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
*,
72 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
78 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
79 * @q: The Work Queue to operate on.
80 * @wqe: The work Queue Entry to put on the Work queue.
82 * This routine will copy the contents of @wqe to the next available entry on
83 * the @q. This function will then ring the Work Queue Doorbell to signal the
84 * HBA to start processing the Work Queue Entry. This function returns 0 if
85 * successful. If no entries are available on @q then this function will return
87 * The caller is expected to hold the hbalock when calling this routine.
90 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
92 union lpfc_wqe
*temp_wqe
;
93 struct lpfc_register doorbell
;
96 /* sanity check on queue memory */
99 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
101 /* If the host has not yet processed the next entry then we are done */
102 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
104 /* set consumption flag every once in a while */
105 if (!((q
->host_index
+ 1) % q
->entry_repost
))
106 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
107 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
108 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
109 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
111 /* Update the host index before invoking device */
112 host_index
= q
->host_index
;
113 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
117 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
118 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
119 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
120 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
121 readl(q
->phba
->sli4_hba
.WQDBregaddr
); /* Flush */
127 * lpfc_sli4_wq_release - Updates internal hba index for WQ
128 * @q: The Work Queue to operate on.
129 * @index: The index to advance the hba index to.
131 * This routine will update the HBA index of a queue to reflect consumption of
132 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
133 * an entry the host calls this function to update the queue's internal
134 * pointers. This routine returns the number of entries that were consumed by
138 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
140 uint32_t released
= 0;
142 /* sanity check on queue memory */
146 if (q
->hba_index
== index
)
149 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
151 } while (q
->hba_index
!= index
);
156 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
157 * @q: The Mailbox Queue to operate on.
158 * @wqe: The Mailbox Queue Entry to put on the Work queue.
160 * This routine will copy the contents of @mqe to the next available entry on
161 * the @q. This function will then ring the Work Queue Doorbell to signal the
162 * HBA to start processing the Work Queue Entry. This function returns 0 if
163 * successful. If no entries are available on @q then this function will return
165 * The caller is expected to hold the hbalock when calling this routine.
168 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
170 struct lpfc_mqe
*temp_mqe
;
171 struct lpfc_register doorbell
;
174 /* sanity check on queue memory */
177 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
179 /* If the host has not yet processed the next entry then we are done */
180 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
182 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
183 /* Save off the mailbox pointer for completion */
184 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
186 /* Update the host index before invoking device */
187 host_index
= q
->host_index
;
188 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
192 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
193 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
194 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
195 readl(q
->phba
->sli4_hba
.MQDBregaddr
); /* Flush */
200 * lpfc_sli4_mq_release - Updates internal hba index for MQ
201 * @q: The Mailbox Queue to operate on.
203 * This routine will update the HBA index of a queue to reflect consumption of
204 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
205 * an entry the host calls this function to update the queue's internal
206 * pointers. This routine returns the number of entries that were consumed by
210 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
212 /* sanity check on queue memory */
216 /* Clear the mailbox pointer for completion */
217 q
->phba
->mbox
= NULL
;
218 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
223 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
224 * @q: The Event Queue to get the first valid EQE from
226 * This routine will get the first valid Event Queue Entry from @q, update
227 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
228 * the Queue (no more work to do), or the Queue is full of EQEs that have been
229 * processed, but not popped back to the HBA then this routine will return NULL.
231 static struct lpfc_eqe
*
232 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
234 struct lpfc_eqe
*eqe
;
236 /* sanity check on queue memory */
239 eqe
= q
->qe
[q
->hba_index
].eqe
;
241 /* If the next EQE is not valid then we are done */
242 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
244 /* If the host has not yet processed the next entry then we are done */
245 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
248 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
253 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
254 * @q: The Event Queue that the host has completed processing for.
255 * @arm: Indicates whether the host wants to arms this CQ.
257 * This routine will mark all Event Queue Entries on @q, from the last
258 * known completed entry to the last entry that was processed, as completed
259 * by clearing the valid bit for each completion queue entry. Then it will
260 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
261 * The internal host index in the @q will be updated by this routine to indicate
262 * that the host has finished processing the entries. The @arm parameter
263 * indicates that the queue should be rearmed when ringing the doorbell.
265 * This function will return the number of EQEs that were popped.
268 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
270 uint32_t released
= 0;
271 struct lpfc_eqe
*temp_eqe
;
272 struct lpfc_register doorbell
;
274 /* sanity check on queue memory */
278 /* while there are valid entries */
279 while (q
->hba_index
!= q
->host_index
) {
280 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
281 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
283 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
285 if (unlikely(released
== 0 && !arm
))
288 /* ring doorbell for number popped */
291 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
292 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
294 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
295 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
296 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
297 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
298 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
299 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
300 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
301 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
302 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
307 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
308 * @q: The Completion Queue to get the first valid CQE from
310 * This routine will get the first valid Completion Queue Entry from @q, update
311 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
312 * the Queue (no more work to do), or the Queue is full of CQEs that have been
313 * processed, but not popped back to the HBA then this routine will return NULL.
315 static struct lpfc_cqe
*
316 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
318 struct lpfc_cqe
*cqe
;
320 /* sanity check on queue memory */
324 /* If the next CQE is not valid then we are done */
325 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
327 /* If the host has not yet processed the next entry then we are done */
328 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
331 cqe
= q
->qe
[q
->hba_index
].cqe
;
332 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
337 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
338 * @q: The Completion Queue that the host has completed processing for.
339 * @arm: Indicates whether the host wants to arms this CQ.
341 * This routine will mark all Completion queue entries on @q, from the last
342 * known completed entry to the last entry that was processed, as completed
343 * by clearing the valid bit for each completion queue entry. Then it will
344 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
345 * The internal host index in the @q will be updated by this routine to indicate
346 * that the host has finished processing the entries. The @arm parameter
347 * indicates that the queue should be rearmed when ringing the doorbell.
349 * This function will return the number of CQEs that were released.
352 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
354 uint32_t released
= 0;
355 struct lpfc_cqe
*temp_qe
;
356 struct lpfc_register doorbell
;
358 /* sanity check on queue memory */
361 /* while there are valid entries */
362 while (q
->hba_index
!= q
->host_index
) {
363 temp_qe
= q
->qe
[q
->host_index
].cqe
;
364 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
366 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
368 if (unlikely(released
== 0 && !arm
))
371 /* ring doorbell for number popped */
374 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
375 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
376 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
377 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
378 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
379 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
380 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
385 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
386 * @q: The Header Receive Queue to operate on.
387 * @wqe: The Receive Queue Entry to put on the Receive queue.
389 * This routine will copy the contents of @wqe to the next available entry on
390 * the @q. This function will then ring the Receive Queue Doorbell to signal the
391 * HBA to start processing the Receive Queue Entry. This function returns the
392 * index that the rqe was copied to if successful. If no entries are available
393 * on @q then this function will return -ENOMEM.
394 * The caller is expected to hold the hbalock when calling this routine.
397 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
398 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
400 struct lpfc_rqe
*temp_hrqe
;
401 struct lpfc_rqe
*temp_drqe
;
402 struct lpfc_register doorbell
;
403 int put_index
= hq
->host_index
;
405 /* sanity check on queue memory */
406 if (unlikely(!hq
) || unlikely(!dq
))
408 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
409 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
411 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
413 if (hq
->host_index
!= dq
->host_index
)
415 /* If the host has not yet processed the next entry then we are done */
416 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
418 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
419 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
421 /* Update the host index to point to the next slot */
422 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
423 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
425 /* Ring The Header Receive Queue Doorbell */
426 if (!(hq
->host_index
% hq
->entry_repost
)) {
428 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
430 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
431 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
437 * lpfc_sli4_rq_release - Updates internal hba index for RQ
438 * @q: The Header Receive Queue to operate on.
440 * This routine will update the HBA index of a queue to reflect consumption of
441 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
442 * consumed an entry the host calls this function to update the queue's
443 * internal pointers. This routine returns the number of entries that were
444 * consumed by the HBA.
447 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
449 /* sanity check on queue memory */
450 if (unlikely(!hq
) || unlikely(!dq
))
453 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
455 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
456 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
461 * lpfc_cmd_iocb - Get next command iocb entry in the ring
462 * @phba: Pointer to HBA context object.
463 * @pring: Pointer to driver SLI ring object.
465 * This function returns pointer to next command iocb entry
466 * in the command ring. The caller must hold hbalock to prevent
467 * other threads consume the next command iocb.
468 * SLI-2/SLI-3 provide different sized iocbs.
470 static inline IOCB_t
*
471 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
473 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
474 pring
->cmdidx
* phba
->iocb_cmd_size
);
478 * lpfc_resp_iocb - Get next response iocb entry in the ring
479 * @phba: Pointer to HBA context object.
480 * @pring: Pointer to driver SLI ring object.
482 * This function returns pointer to next response iocb entry
483 * in the response ring. The caller must hold hbalock to make sure
484 * that no other thread consume the next response iocb.
485 * SLI-2/SLI-3 provide different sized iocbs.
487 static inline IOCB_t
*
488 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
490 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
491 pring
->rspidx
* phba
->iocb_rsp_size
);
495 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
496 * @phba: Pointer to HBA context object.
498 * This function is called with hbalock held. This function
499 * allocates a new driver iocb object from the iocb pool. If the
500 * allocation is successful, it returns pointer to the newly
501 * allocated iocb object else it returns NULL.
503 static struct lpfc_iocbq
*
504 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
506 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
507 struct lpfc_iocbq
* iocbq
= NULL
;
509 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
512 if (phba
->iocb_cnt
> phba
->iocb_max
)
513 phba
->iocb_max
= phba
->iocb_cnt
;
518 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
519 * @phba: Pointer to HBA context object.
520 * @xritag: XRI value.
522 * This function clears the sglq pointer from the array of acive
523 * sglq's. The xritag that is passed in is used to index into the
524 * array. Before the xritag can be used it needs to be adjusted
525 * by subtracting the xribase.
527 * Returns sglq ponter = success, NULL = Failure.
529 static struct lpfc_sglq
*
530 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
532 struct lpfc_sglq
*sglq
;
534 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
535 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
540 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
541 * @phba: Pointer to HBA context object.
542 * @xritag: XRI value.
544 * This function returns the sglq pointer from the array of acive
545 * sglq's. The xritag that is passed in is used to index into the
546 * array. Before the xritag can be used it needs to be adjusted
547 * by subtracting the xribase.
549 * Returns sglq ponter = success, NULL = Failure.
552 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
554 struct lpfc_sglq
*sglq
;
556 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
561 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
562 * @phba: Pointer to HBA context object.
563 * @xritag: xri used in this exchange.
564 * @rrq: The RRQ to be cleared.
568 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
570 struct lpfc_node_rrq
*rrq
)
572 struct lpfc_nodelist
*ndlp
= NULL
;
574 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
575 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
577 /* The target DID could have been swapped (cable swap)
578 * we should use the ndlp from the findnode if it is
581 if ((!ndlp
) && rrq
->ndlp
)
587 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
)) {
590 rrq
->rrq_stop_time
= 0;
593 mempool_free(rrq
, phba
->rrq_pool
);
597 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
598 * @phba: Pointer to HBA context object.
600 * This function is called with hbalock held. This function
601 * Checks if stop_time (ratov from setting rrq active) has
602 * been reached, if it has and the send_rrq flag is set then
603 * it will call lpfc_send_rrq. If the send_rrq flag is not set
604 * then it will just call the routine to clear the rrq and
605 * free the rrq resource.
606 * The timer is set to the next rrq that is going to expire before
607 * leaving the routine.
611 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
613 struct lpfc_node_rrq
*rrq
;
614 struct lpfc_node_rrq
*nextrrq
;
615 unsigned long next_time
;
616 unsigned long iflags
;
619 spin_lock_irqsave(&phba
->hbalock
, iflags
);
620 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
621 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
622 list_for_each_entry_safe(rrq
, nextrrq
,
623 &phba
->active_rrq_list
, list
) {
624 if (time_after(jiffies
, rrq
->rrq_stop_time
))
625 list_move(&rrq
->list
, &send_rrq
);
626 else if (time_before(rrq
->rrq_stop_time
, next_time
))
627 next_time
= rrq
->rrq_stop_time
;
629 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
630 if (!list_empty(&phba
->active_rrq_list
))
631 mod_timer(&phba
->rrq_tmr
, next_time
);
632 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
633 list_del(&rrq
->list
);
635 /* this call will free the rrq */
636 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
637 else if (lpfc_send_rrq(phba
, rrq
)) {
638 /* if we send the rrq then the completion handler
639 * will clear the bit in the xribitmap.
641 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
648 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
649 * @vport: Pointer to vport context object.
650 * @xri: The xri used in the exchange.
651 * @did: The targets DID for this exchange.
653 * returns NULL = rrq not found in the phba->active_rrq_list.
654 * rrq = rrq for this xri and target.
656 struct lpfc_node_rrq
*
657 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
659 struct lpfc_hba
*phba
= vport
->phba
;
660 struct lpfc_node_rrq
*rrq
;
661 struct lpfc_node_rrq
*nextrrq
;
662 unsigned long iflags
;
664 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
666 spin_lock_irqsave(&phba
->hbalock
, iflags
);
667 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
668 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
669 rrq
->nlp_DID
== did
){
670 list_del(&rrq
->list
);
671 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
675 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
680 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
681 * @vport: Pointer to vport context object.
682 * @ndlp: Pointer to the lpfc_node_list structure.
683 * If ndlp is NULL Remove all active RRQs for this vport from the
684 * phba->active_rrq_list and clear the rrq.
685 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
688 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
691 struct lpfc_hba
*phba
= vport
->phba
;
692 struct lpfc_node_rrq
*rrq
;
693 struct lpfc_node_rrq
*nextrrq
;
694 unsigned long iflags
;
697 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
700 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
701 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
703 spin_lock_irqsave(&phba
->hbalock
, iflags
);
704 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
705 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
706 list_move(&rrq
->list
, &rrq_list
);
707 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
709 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
710 list_del(&rrq
->list
);
711 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
716 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
717 * @phba: Pointer to HBA context object.
719 * Remove all rrqs from the phba->active_rrq_list and free them by
720 * calling __lpfc_clr_active_rrq
724 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
726 struct lpfc_node_rrq
*rrq
;
727 struct lpfc_node_rrq
*nextrrq
;
728 unsigned long next_time
;
729 unsigned long iflags
;
732 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
734 spin_lock_irqsave(&phba
->hbalock
, iflags
);
735 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
736 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
737 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
738 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
740 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
741 list_del(&rrq
->list
);
742 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
744 if (!list_empty(&phba
->active_rrq_list
))
745 mod_timer(&phba
->rrq_tmr
, next_time
);
750 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
751 * @phba: Pointer to HBA context object.
752 * @ndlp: Targets nodelist pointer for this exchange.
753 * @xritag the xri in the bitmap to test.
755 * This function is called with hbalock held. This function
756 * returns 0 = rrq not active for this xri
757 * 1 = rrq is valid for this xri.
760 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
765 if (test_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
772 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
773 * @phba: Pointer to HBA context object.
774 * @ndlp: nodelist pointer for this target.
775 * @xritag: xri used in this exchange.
776 * @rxid: Remote Exchange ID.
777 * @send_rrq: Flag used to determine if we should send rrq els cmd.
779 * This function takes the hbalock.
780 * The active bit is always set in the active rrq xri_bitmap even
781 * if there is no slot avaiable for the other rrq information.
783 * returns 0 rrq actived for this xri
784 * < 0 No memory or invalid ndlp.
787 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
788 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
790 unsigned long iflags
;
791 struct lpfc_node_rrq
*rrq
;
797 if (!phba
->cfg_enable_rrq
)
800 spin_lock_irqsave(&phba
->hbalock
, iflags
);
801 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
802 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
807 * set the active bit even if there is no mem available.
809 if (NLP_CHK_FREE_REQ(ndlp
))
812 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
815 if (test_and_set_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
818 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
819 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
821 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
822 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
823 " DID:0x%x Send:%d\n",
824 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
827 rrq
->send_rrq
= send_rrq
;
828 rrq
->xritag
= xritag
;
829 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
831 rrq
->nlp_DID
= ndlp
->nlp_DID
;
832 rrq
->vport
= ndlp
->vport
;
834 rrq
->send_rrq
= send_rrq
;
835 spin_lock_irqsave(&phba
->hbalock
, iflags
);
836 empty
= list_empty(&phba
->active_rrq_list
);
837 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
838 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
840 lpfc_worker_wake_up(phba
);
841 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
844 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
845 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
846 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
847 " DID:0x%x Send:%d\n",
848 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
853 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
854 * @phba: Pointer to HBA context object.
855 * @piocb: Pointer to the iocbq.
857 * This function is called with hbalock held. This function
858 * gets a new driver sglq object from the sglq list. If the
859 * list is not empty then it is successful, it returns pointer to the newly
860 * allocated sglq object else it returns NULL.
862 static struct lpfc_sglq
*
863 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
865 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
866 struct lpfc_sglq
*sglq
= NULL
;
867 struct lpfc_sglq
*start_sglq
= NULL
;
868 struct lpfc_scsi_buf
*lpfc_cmd
;
869 struct lpfc_nodelist
*ndlp
;
872 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
873 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
874 ndlp
= lpfc_cmd
->rdata
->pnode
;
875 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
876 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
877 ndlp
= piocbq
->context_un
.ndlp
;
879 ndlp
= piocbq
->context1
;
881 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
886 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_xritag
)) {
887 /* This xri has an rrq outstanding for this DID.
888 * put it back in the list and get another xri.
890 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
892 list_remove_head(lpfc_sgl_list
, sglq
,
893 struct lpfc_sglq
, list
);
894 if (sglq
== start_sglq
) {
902 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
903 sglq
->state
= SGL_ALLOCATED
;
909 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
910 * @phba: Pointer to HBA context object.
912 * This function is called with no lock held. This function
913 * allocates a new driver iocb object from the iocb pool. If the
914 * allocation is successful, it returns pointer to the newly
915 * allocated iocb object else it returns NULL.
918 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
920 struct lpfc_iocbq
* iocbq
= NULL
;
921 unsigned long iflags
;
923 spin_lock_irqsave(&phba
->hbalock
, iflags
);
924 iocbq
= __lpfc_sli_get_iocbq(phba
);
925 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
930 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
931 * @phba: Pointer to HBA context object.
932 * @iocbq: Pointer to driver iocb object.
934 * This function is called with hbalock held to release driver
935 * iocb object to the iocb pool. The iotag in the iocb object
936 * does not change for each use of the iocb object. This function
937 * clears all other fields of the iocb object when it is freed.
938 * The sqlq structure that holds the xritag and phys and virtual
939 * mappings for the scatter gather list is retrieved from the
940 * active array of sglq. The get of the sglq pointer also clears
941 * the entry in the array. If the status of the IO indiactes that
942 * this IO was aborted then the sglq entry it put on the
943 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
944 * IO has good status or fails for any other reason then the sglq
945 * entry is added to the free list (lpfc_sgl_list).
948 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
950 struct lpfc_sglq
*sglq
;
951 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
952 unsigned long iflag
= 0;
953 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
955 if (iocbq
->sli4_xritag
== NO_XRI
)
958 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
961 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
962 (sglq
->state
!= SGL_XRI_ABORTED
)) {
963 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
965 list_add(&sglq
->list
,
966 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
967 spin_unlock_irqrestore(
968 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
970 sglq
->state
= SGL_FREED
;
972 list_add_tail(&sglq
->list
,
973 &phba
->sli4_hba
.lpfc_sgl_list
);
975 /* Check if TXQ queue needs to be serviced */
977 lpfc_worker_wake_up(phba
);
983 * Clean all volatile data fields, preserve iotag and node struct.
985 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
986 iocbq
->sli4_lxritag
= NO_XRI
;
987 iocbq
->sli4_xritag
= NO_XRI
;
988 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
993 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
994 * @phba: Pointer to HBA context object.
995 * @iocbq: Pointer to driver iocb object.
997 * This function is called with hbalock held to release driver
998 * iocb object to the iocb pool. The iotag in the iocb object
999 * does not change for each use of the iocb object. This function
1000 * clears all other fields of the iocb object when it is freed.
1003 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1005 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1008 * Clean all volatile data fields, preserve iotag and node struct.
1010 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1011 iocbq
->sli4_xritag
= NO_XRI
;
1012 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1016 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1017 * @phba: Pointer to HBA context object.
1018 * @iocbq: Pointer to driver iocb object.
1020 * This function is called with hbalock held to release driver
1021 * iocb object to the iocb pool. The iotag in the iocb object
1022 * does not change for each use of the iocb object. This function
1023 * clears all other fields of the iocb object when it is freed.
1026 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1028 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1033 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1034 * @phba: Pointer to HBA context object.
1035 * @iocbq: Pointer to driver iocb object.
1037 * This function is called with no lock held to release the iocb to
1041 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1043 unsigned long iflags
;
1046 * Clean all volatile data fields, preserve iotag and node struct.
1048 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1049 __lpfc_sli_release_iocbq(phba
, iocbq
);
1050 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1054 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1055 * @phba: Pointer to HBA context object.
1056 * @iocblist: List of IOCBs.
1057 * @ulpstatus: ULP status in IOCB command field.
1058 * @ulpWord4: ULP word-4 in IOCB command field.
1060 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1061 * on the list by invoking the complete callback function associated with the
1062 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1066 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1067 uint32_t ulpstatus
, uint32_t ulpWord4
)
1069 struct lpfc_iocbq
*piocb
;
1071 while (!list_empty(iocblist
)) {
1072 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1074 if (!piocb
->iocb_cmpl
)
1075 lpfc_sli_release_iocbq(phba
, piocb
);
1077 piocb
->iocb
.ulpStatus
= ulpstatus
;
1078 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1079 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1086 * lpfc_sli_iocb_cmd_type - Get the iocb type
1087 * @iocb_cmnd: iocb command code.
1089 * This function is called by ring event handler function to get the iocb type.
1090 * This function translates the iocb command to an iocb command type used to
1091 * decide the final disposition of each completed IOCB.
1092 * The function returns
1093 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1094 * LPFC_SOL_IOCB if it is a solicited iocb completion
1095 * LPFC_ABORT_IOCB if it is an abort iocb
1096 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1098 * The caller is not required to hold any lock.
1100 static lpfc_iocb_type
1101 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1103 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1105 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1108 switch (iocb_cmnd
) {
1109 case CMD_XMIT_SEQUENCE_CR
:
1110 case CMD_XMIT_SEQUENCE_CX
:
1111 case CMD_XMIT_BCAST_CN
:
1112 case CMD_XMIT_BCAST_CX
:
1113 case CMD_ELS_REQUEST_CR
:
1114 case CMD_ELS_REQUEST_CX
:
1115 case CMD_CREATE_XRI_CR
:
1116 case CMD_CREATE_XRI_CX
:
1117 case CMD_GET_RPI_CN
:
1118 case CMD_XMIT_ELS_RSP_CX
:
1119 case CMD_GET_RPI_CR
:
1120 case CMD_FCP_IWRITE_CR
:
1121 case CMD_FCP_IWRITE_CX
:
1122 case CMD_FCP_IREAD_CR
:
1123 case CMD_FCP_IREAD_CX
:
1124 case CMD_FCP_ICMND_CR
:
1125 case CMD_FCP_ICMND_CX
:
1126 case CMD_FCP_TSEND_CX
:
1127 case CMD_FCP_TRSP_CX
:
1128 case CMD_FCP_TRECEIVE_CX
:
1129 case CMD_FCP_AUTO_TRSP_CX
:
1130 case CMD_ADAPTER_MSG
:
1131 case CMD_ADAPTER_DUMP
:
1132 case CMD_XMIT_SEQUENCE64_CR
:
1133 case CMD_XMIT_SEQUENCE64_CX
:
1134 case CMD_XMIT_BCAST64_CN
:
1135 case CMD_XMIT_BCAST64_CX
:
1136 case CMD_ELS_REQUEST64_CR
:
1137 case CMD_ELS_REQUEST64_CX
:
1138 case CMD_FCP_IWRITE64_CR
:
1139 case CMD_FCP_IWRITE64_CX
:
1140 case CMD_FCP_IREAD64_CR
:
1141 case CMD_FCP_IREAD64_CX
:
1142 case CMD_FCP_ICMND64_CR
:
1143 case CMD_FCP_ICMND64_CX
:
1144 case CMD_FCP_TSEND64_CX
:
1145 case CMD_FCP_TRSP64_CX
:
1146 case CMD_FCP_TRECEIVE64_CX
:
1147 case CMD_GEN_REQUEST64_CR
:
1148 case CMD_GEN_REQUEST64_CX
:
1149 case CMD_XMIT_ELS_RSP64_CX
:
1150 case DSSCMD_IWRITE64_CR
:
1151 case DSSCMD_IWRITE64_CX
:
1152 case DSSCMD_IREAD64_CR
:
1153 case DSSCMD_IREAD64_CX
:
1154 type
= LPFC_SOL_IOCB
;
1156 case CMD_ABORT_XRI_CN
:
1157 case CMD_ABORT_XRI_CX
:
1158 case CMD_CLOSE_XRI_CN
:
1159 case CMD_CLOSE_XRI_CX
:
1160 case CMD_XRI_ABORTED_CX
:
1161 case CMD_ABORT_MXRI64_CN
:
1162 case CMD_XMIT_BLS_RSP64_CX
:
1163 type
= LPFC_ABORT_IOCB
;
1165 case CMD_RCV_SEQUENCE_CX
:
1166 case CMD_RCV_ELS_REQ_CX
:
1167 case CMD_RCV_SEQUENCE64_CX
:
1168 case CMD_RCV_ELS_REQ64_CX
:
1169 case CMD_ASYNC_STATUS
:
1170 case CMD_IOCB_RCV_SEQ64_CX
:
1171 case CMD_IOCB_RCV_ELS64_CX
:
1172 case CMD_IOCB_RCV_CONT64_CX
:
1173 case CMD_IOCB_RET_XRI64_CX
:
1174 type
= LPFC_UNSOL_IOCB
;
1176 case CMD_IOCB_XMIT_MSEQ64_CR
:
1177 case CMD_IOCB_XMIT_MSEQ64_CX
:
1178 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1179 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1180 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1181 case CMD_IOCB_ABORT_EXTENDED_CN
:
1182 case CMD_IOCB_RET_HBQE64_CN
:
1183 case CMD_IOCB_FCP_IBIDIR64_CR
:
1184 case CMD_IOCB_FCP_IBIDIR64_CX
:
1185 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1186 case CMD_IOCB_LOGENTRY_CN
:
1187 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1188 printk("%s - Unhandled SLI-3 Command x%x\n",
1189 __func__
, iocb_cmnd
);
1190 type
= LPFC_UNKNOWN_IOCB
;
1193 type
= LPFC_UNKNOWN_IOCB
;
1201 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1202 * @phba: Pointer to HBA context object.
1204 * This function is called from SLI initialization code
1205 * to configure every ring of the HBA's SLI interface. The
1206 * caller is not required to hold any lock. This function issues
1207 * a config_ring mailbox command for each ring.
1208 * This function returns zero if successful else returns a negative
1212 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1214 struct lpfc_sli
*psli
= &phba
->sli
;
1219 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1223 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1224 for (i
= 0; i
< psli
->num_rings
; i
++) {
1225 lpfc_config_ring(phba
, i
, pmb
);
1226 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1227 if (rc
!= MBX_SUCCESS
) {
1228 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1229 "0446 Adapter failed to init (%d), "
1230 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1232 rc
, pmbox
->mbxCommand
,
1233 pmbox
->mbxStatus
, i
);
1234 phba
->link_state
= LPFC_HBA_ERROR
;
1239 mempool_free(pmb
, phba
->mbox_mem_pool
);
1244 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1245 * @phba: Pointer to HBA context object.
1246 * @pring: Pointer to driver SLI ring object.
1247 * @piocb: Pointer to the driver iocb object.
1249 * This function is called with hbalock held. The function adds the
1250 * new iocb to txcmplq of the given ring. This function always returns
1251 * 0. If this function is called for ELS ring, this function checks if
1252 * there is a vport associated with the ELS command. This function also
1253 * starts els_tmofunc timer if this is an ELS command.
1256 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1257 struct lpfc_iocbq
*piocb
)
1259 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1260 piocb
->iocb_flag
|= LPFC_IO_ON_Q
;
1261 pring
->txcmplq_cnt
++;
1262 if (pring
->txcmplq_cnt
> pring
->txcmplq_max
)
1263 pring
->txcmplq_max
= pring
->txcmplq_cnt
;
1265 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1266 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1267 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1271 mod_timer(&piocb
->vport
->els_tmofunc
,
1272 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1280 * lpfc_sli_ringtx_get - Get first element of the txq
1281 * @phba: Pointer to HBA context object.
1282 * @pring: Pointer to driver SLI ring object.
1284 * This function is called with hbalock held to get next
1285 * iocb in txq of the given ring. If there is any iocb in
1286 * the txq, the function returns first iocb in the list after
1287 * removing the iocb from the list, else it returns NULL.
1290 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1292 struct lpfc_iocbq
*cmd_iocb
;
1294 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1295 if (cmd_iocb
!= NULL
)
1301 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1302 * @phba: Pointer to HBA context object.
1303 * @pring: Pointer to driver SLI ring object.
1305 * This function is called with hbalock held and the caller must post the
1306 * iocb without releasing the lock. If the caller releases the lock,
1307 * iocb slot returned by the function is not guaranteed to be available.
1308 * The function returns pointer to the next available iocb slot if there
1309 * is available slot in the ring, else it returns NULL.
1310 * If the get index of the ring is ahead of the put index, the function
1311 * will post an error attention event to the worker thread to take the
1312 * HBA to offline state.
1315 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1317 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1318 uint32_t max_cmd_idx
= pring
->numCiocb
;
1319 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
1320 (++pring
->next_cmdidx
>= max_cmd_idx
))
1321 pring
->next_cmdidx
= 0;
1323 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
1325 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1327 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
1328 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1329 "0315 Ring %d issue: portCmdGet %d "
1330 "is bigger than cmd ring %d\n",
1332 pring
->local_getidx
, max_cmd_idx
);
1334 phba
->link_state
= LPFC_HBA_ERROR
;
1336 * All error attention handlers are posted to
1339 phba
->work_ha
|= HA_ERATT
;
1340 phba
->work_hs
= HS_FFER3
;
1342 lpfc_worker_wake_up(phba
);
1347 if (pring
->local_getidx
== pring
->next_cmdidx
)
1351 return lpfc_cmd_iocb(phba
, pring
);
1355 * lpfc_sli_next_iotag - Get an iotag for the iocb
1356 * @phba: Pointer to HBA context object.
1357 * @iocbq: Pointer to driver iocb object.
1359 * This function gets an iotag for the iocb. If there is no unused iotag and
1360 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1361 * array and assigns a new iotag.
1362 * The function returns the allocated iotag if successful, else returns zero.
1363 * Zero is not a valid iotag.
1364 * The caller is not required to hold any lock.
1367 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1369 struct lpfc_iocbq
**new_arr
;
1370 struct lpfc_iocbq
**old_arr
;
1372 struct lpfc_sli
*psli
= &phba
->sli
;
1375 spin_lock_irq(&phba
->hbalock
);
1376 iotag
= psli
->last_iotag
;
1377 if(++iotag
< psli
->iocbq_lookup_len
) {
1378 psli
->last_iotag
= iotag
;
1379 psli
->iocbq_lookup
[iotag
] = iocbq
;
1380 spin_unlock_irq(&phba
->hbalock
);
1381 iocbq
->iotag
= iotag
;
1383 } else if (psli
->iocbq_lookup_len
< (0xffff
1384 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1385 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1386 spin_unlock_irq(&phba
->hbalock
);
1387 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1390 spin_lock_irq(&phba
->hbalock
);
1391 old_arr
= psli
->iocbq_lookup
;
1392 if (new_len
<= psli
->iocbq_lookup_len
) {
1393 /* highly unprobable case */
1395 iotag
= psli
->last_iotag
;
1396 if(++iotag
< psli
->iocbq_lookup_len
) {
1397 psli
->last_iotag
= iotag
;
1398 psli
->iocbq_lookup
[iotag
] = iocbq
;
1399 spin_unlock_irq(&phba
->hbalock
);
1400 iocbq
->iotag
= iotag
;
1403 spin_unlock_irq(&phba
->hbalock
);
1406 if (psli
->iocbq_lookup
)
1407 memcpy(new_arr
, old_arr
,
1408 ((psli
->last_iotag
+ 1) *
1409 sizeof (struct lpfc_iocbq
*)));
1410 psli
->iocbq_lookup
= new_arr
;
1411 psli
->iocbq_lookup_len
= new_len
;
1412 psli
->last_iotag
= iotag
;
1413 psli
->iocbq_lookup
[iotag
] = iocbq
;
1414 spin_unlock_irq(&phba
->hbalock
);
1415 iocbq
->iotag
= iotag
;
1420 spin_unlock_irq(&phba
->hbalock
);
1422 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1423 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1430 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1431 * @phba: Pointer to HBA context object.
1432 * @pring: Pointer to driver SLI ring object.
1433 * @iocb: Pointer to iocb slot in the ring.
1434 * @nextiocb: Pointer to driver iocb object which need to be
1435 * posted to firmware.
1437 * This function is called with hbalock held to post a new iocb to
1438 * the firmware. This function copies the new iocb to ring iocb slot and
1439 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1440 * a completion call back for this iocb else the function will free the
1444 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1445 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1450 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1453 if (pring
->ringno
== LPFC_ELS_RING
) {
1454 lpfc_debugfs_slow_ring_trc(phba
,
1455 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1456 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1457 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1458 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1462 * Issue iocb command to adapter
1464 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1466 pring
->stats
.iocb_cmd
++;
1469 * If there is no completion routine to call, we can release the
1470 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1471 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1473 if (nextiocb
->iocb_cmpl
)
1474 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1476 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1479 * Let the HBA know what IOCB slot will be the next one the
1480 * driver will put a command into.
1482 pring
->cmdidx
= pring
->next_cmdidx
;
1483 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1487 * lpfc_sli_update_full_ring - Update the chip attention register
1488 * @phba: Pointer to HBA context object.
1489 * @pring: Pointer to driver SLI ring object.
1491 * The caller is not required to hold any lock for calling this function.
1492 * This function updates the chip attention bits for the ring to inform firmware
1493 * that there are pending work to be done for this ring and requests an
1494 * interrupt when there is space available in the ring. This function is
1495 * called when the driver is unable to post more iocbs to the ring due
1496 * to unavailability of space in the ring.
1499 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1501 int ringno
= pring
->ringno
;
1503 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1508 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1509 * The HBA will tell us when an IOCB entry is available.
1511 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1512 readl(phba
->CAregaddr
); /* flush */
1514 pring
->stats
.iocb_cmd_full
++;
1518 * lpfc_sli_update_ring - Update chip attention register
1519 * @phba: Pointer to HBA context object.
1520 * @pring: Pointer to driver SLI ring object.
1522 * This function updates the chip attention register bit for the
1523 * given ring to inform HBA that there is more work to be done
1524 * in this ring. The caller is not required to hold any lock.
1527 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1529 int ringno
= pring
->ringno
;
1532 * Tell the HBA that there is work to do in this ring.
1534 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1536 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1537 readl(phba
->CAregaddr
); /* flush */
1542 * lpfc_sli_resume_iocb - Process iocbs in the txq
1543 * @phba: Pointer to HBA context object.
1544 * @pring: Pointer to driver SLI ring object.
1546 * This function is called with hbalock held to post pending iocbs
1547 * in the txq to the firmware. This function is called when driver
1548 * detects space available in the ring.
1551 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1554 struct lpfc_iocbq
*nextiocb
;
1558 * (a) there is anything on the txq to send
1560 * (c) link attention events can be processed (fcp ring only)
1561 * (d) IOCB processing is not blocked by the outstanding mbox command.
1563 if (pring
->txq_cnt
&&
1564 lpfc_is_link_up(phba
) &&
1565 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1566 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1568 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1569 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1570 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1573 lpfc_sli_update_ring(phba
, pring
);
1575 lpfc_sli_update_full_ring(phba
, pring
);
1582 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1583 * @phba: Pointer to HBA context object.
1584 * @hbqno: HBQ number.
1586 * This function is called with hbalock held to get the next
1587 * available slot for the given HBQ. If there is free slot
1588 * available for the HBQ it will return pointer to the next available
1589 * HBQ entry else it will return NULL.
1591 static struct lpfc_hbq_entry
*
1592 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1594 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1596 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1597 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1598 hbqp
->next_hbqPutIdx
= 0;
1600 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1601 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1602 uint32_t getidx
= le32_to_cpu(raw_index
);
1604 hbqp
->local_hbqGetIdx
= getidx
;
1606 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1607 lpfc_printf_log(phba
, KERN_ERR
,
1608 LOG_SLI
| LOG_VPORT
,
1609 "1802 HBQ %d: local_hbqGetIdx "
1610 "%u is > than hbqp->entry_count %u\n",
1611 hbqno
, hbqp
->local_hbqGetIdx
,
1614 phba
->link_state
= LPFC_HBA_ERROR
;
1618 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1622 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1627 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1628 * @phba: Pointer to HBA context object.
1630 * This function is called with no lock held to free all the
1631 * hbq buffers while uninitializing the SLI interface. It also
1632 * frees the HBQ buffers returned by the firmware but not yet
1633 * processed by the upper layers.
1636 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1638 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1639 struct hbq_dmabuf
*hbq_buf
;
1640 unsigned long flags
;
1644 hbq_count
= lpfc_sli_hbq_count();
1645 /* Return all memory used by all HBQs */
1646 spin_lock_irqsave(&phba
->hbalock
, flags
);
1647 for (i
= 0; i
< hbq_count
; ++i
) {
1648 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1649 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1650 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1651 list_del(&hbq_buf
->dbuf
.list
);
1652 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1654 phba
->hbqs
[i
].buffer_count
= 0;
1656 /* Return all HBQ buffer that are in-fly */
1657 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1659 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1660 list_del(&hbq_buf
->dbuf
.list
);
1661 if (hbq_buf
->tag
== -1) {
1662 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1665 hbqno
= hbq_buf
->tag
>> 16;
1666 if (hbqno
>= LPFC_MAX_HBQS
)
1667 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1670 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1675 /* Mark the HBQs not in use */
1676 phba
->hbq_in_use
= 0;
1677 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1681 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1682 * @phba: Pointer to HBA context object.
1683 * @hbqno: HBQ number.
1684 * @hbq_buf: Pointer to HBQ buffer.
1686 * This function is called with the hbalock held to post a
1687 * hbq buffer to the firmware. If the function finds an empty
1688 * slot in the HBQ, it will post the buffer. The function will return
1689 * pointer to the hbq entry if it successfully post the buffer
1690 * else it will return NULL.
1693 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1694 struct hbq_dmabuf
*hbq_buf
)
1696 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1700 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1701 * @phba: Pointer to HBA context object.
1702 * @hbqno: HBQ number.
1703 * @hbq_buf: Pointer to HBQ buffer.
1705 * This function is called with the hbalock held to post a hbq buffer to the
1706 * firmware. If the function finds an empty slot in the HBQ, it will post the
1707 * buffer and place it on the hbq_buffer_list. The function will return zero if
1708 * it successfully post the buffer else it will return an error.
1711 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1712 struct hbq_dmabuf
*hbq_buf
)
1714 struct lpfc_hbq_entry
*hbqe
;
1715 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1717 /* Get next HBQ entry slot to use */
1718 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1720 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1722 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1723 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1724 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1725 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1726 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1727 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1729 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1730 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1732 readl(phba
->hbq_put
+ hbqno
);
1733 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1740 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1741 * @phba: Pointer to HBA context object.
1742 * @hbqno: HBQ number.
1743 * @hbq_buf: Pointer to HBQ buffer.
1745 * This function is called with the hbalock held to post an RQE to the SLI4
1746 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1747 * the hbq_buffer_list and return zero, otherwise it will return an error.
1750 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1751 struct hbq_dmabuf
*hbq_buf
)
1754 struct lpfc_rqe hrqe
;
1755 struct lpfc_rqe drqe
;
1757 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1758 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1759 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1760 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1761 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1766 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1770 /* HBQ for ELS and CT traffic. */
1771 static struct lpfc_hbq_init lpfc_els_hbq
= {
1776 .ring_mask
= (1 << LPFC_ELS_RING
),
1782 /* HBQ for the extra ring if needed */
1783 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1788 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1795 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1801 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1802 * @phba: Pointer to HBA context object.
1803 * @hbqno: HBQ number.
1804 * @count: Number of HBQ buffers to be posted.
1806 * This function is called with no lock held to post more hbq buffers to the
1807 * given HBQ. The function returns the number of HBQ buffers successfully
1811 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1813 uint32_t i
, posted
= 0;
1814 unsigned long flags
;
1815 struct hbq_dmabuf
*hbq_buffer
;
1816 LIST_HEAD(hbq_buf_list
);
1817 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1820 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1821 lpfc_hbq_defs
[hbqno
]->entry_count
)
1822 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1823 phba
->hbqs
[hbqno
].buffer_count
;
1826 /* Allocate HBQ entries */
1827 for (i
= 0; i
< count
; i
++) {
1828 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1831 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1833 /* Check whether HBQ is still in use */
1834 spin_lock_irqsave(&phba
->hbalock
, flags
);
1835 if (!phba
->hbq_in_use
)
1837 while (!list_empty(&hbq_buf_list
)) {
1838 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1840 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1842 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1843 phba
->hbqs
[hbqno
].buffer_count
++;
1846 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1848 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1851 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1852 while (!list_empty(&hbq_buf_list
)) {
1853 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1855 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1861 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1862 * @phba: Pointer to HBA context object.
1865 * This function posts more buffers to the HBQ. This function
1866 * is called with no lock held. The function returns the number of HBQ entries
1867 * successfully allocated.
1870 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1872 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1875 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1876 lpfc_hbq_defs
[qno
]->add_count
);
1880 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1881 * @phba: Pointer to HBA context object.
1882 * @qno: HBQ queue number.
1884 * This function is called from SLI initialization code path with
1885 * no lock held to post initial HBQ buffers to firmware. The
1886 * function returns the number of HBQ entries successfully allocated.
1889 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1891 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1892 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1893 lpfc_hbq_defs
[qno
]->entry_count
);
1895 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1896 lpfc_hbq_defs
[qno
]->init_count
);
1900 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1901 * @phba: Pointer to HBA context object.
1902 * @hbqno: HBQ number.
1904 * This function removes the first hbq buffer on an hbq list and returns a
1905 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1907 static struct hbq_dmabuf
*
1908 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1910 struct lpfc_dmabuf
*d_buf
;
1912 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1915 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1919 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1920 * @phba: Pointer to HBA context object.
1921 * @tag: Tag of the hbq buffer.
1923 * This function is called with hbalock held. This function searches
1924 * for the hbq buffer associated with the given tag in the hbq buffer
1925 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1928 static struct hbq_dmabuf
*
1929 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1931 struct lpfc_dmabuf
*d_buf
;
1932 struct hbq_dmabuf
*hbq_buf
;
1936 if (hbqno
>= LPFC_MAX_HBQS
)
1939 spin_lock_irq(&phba
->hbalock
);
1940 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1941 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1942 if (hbq_buf
->tag
== tag
) {
1943 spin_unlock_irq(&phba
->hbalock
);
1947 spin_unlock_irq(&phba
->hbalock
);
1948 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1949 "1803 Bad hbq tag. Data: x%x x%x\n",
1950 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1955 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1956 * @phba: Pointer to HBA context object.
1957 * @hbq_buffer: Pointer to HBQ buffer.
1959 * This function is called with hbalock. This function gives back
1960 * the hbq buffer to firmware. If the HBQ does not have space to
1961 * post the buffer, it will free the buffer.
1964 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1969 hbqno
= hbq_buffer
->tag
>> 16;
1970 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1971 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1976 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1977 * @mbxCommand: mailbox command code.
1979 * This function is called by the mailbox event handler function to verify
1980 * that the completed mailbox command is a legitimate mailbox command. If the
1981 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1982 * and the mailbox event handler will take the HBA offline.
1985 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
1989 switch (mbxCommand
) {
1993 case MBX_WRITE_VPARMS
:
1994 case MBX_RUN_BIU_DIAG
:
1997 case MBX_CONFIG_LINK
:
1998 case MBX_CONFIG_RING
:
1999 case MBX_RESET_RING
:
2000 case MBX_READ_CONFIG
:
2001 case MBX_READ_RCONFIG
:
2002 case MBX_READ_SPARM
:
2003 case MBX_READ_STATUS
:
2007 case MBX_READ_LNK_STAT
:
2009 case MBX_UNREG_LOGIN
:
2011 case MBX_DUMP_MEMORY
:
2012 case MBX_DUMP_CONTEXT
:
2015 case MBX_UPDATE_CFG
:
2017 case MBX_DEL_LD_ENTRY
:
2018 case MBX_RUN_PROGRAM
:
2020 case MBX_SET_VARIABLE
:
2021 case MBX_UNREG_D_ID
:
2022 case MBX_KILL_BOARD
:
2023 case MBX_CONFIG_FARP
:
2026 case MBX_RUN_BIU_DIAG64
:
2027 case MBX_CONFIG_PORT
:
2028 case MBX_READ_SPARM64
:
2029 case MBX_READ_RPI64
:
2030 case MBX_REG_LOGIN64
:
2031 case MBX_READ_TOPOLOGY
:
2034 case MBX_LOAD_EXP_ROM
:
2035 case MBX_ASYNCEVT_ENABLE
:
2039 case MBX_PORT_CAPABILITIES
:
2040 case MBX_PORT_IOV_CONTROL
:
2041 case MBX_SLI4_CONFIG
:
2042 case MBX_SLI4_REQ_FTRS
:
2044 case MBX_UNREG_FCFI
:
2049 case MBX_RESUME_RPI
:
2050 case MBX_READ_EVENT_LOG_STATUS
:
2051 case MBX_READ_EVENT_LOG
:
2052 case MBX_SECURITY_MGMT
:
2064 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2065 * @phba: Pointer to HBA context object.
2066 * @pmboxq: Pointer to mailbox command.
2068 * This is completion handler function for mailbox commands issued from
2069 * lpfc_sli_issue_mbox_wait function. This function is called by the
2070 * mailbox event handler function with no lock held. This function
2071 * will wake up thread waiting on the wait queue pointed by context1
2075 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2077 wait_queue_head_t
*pdone_q
;
2078 unsigned long drvr_flag
;
2081 * If pdone_q is empty, the driver thread gave up waiting and
2082 * continued running.
2084 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2085 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2086 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2088 wake_up_interruptible(pdone_q
);
2089 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2095 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2096 * @phba: Pointer to HBA context object.
2097 * @pmb: Pointer to mailbox object.
2099 * This function is the default mailbox completion handler. It
2100 * frees the memory resources associated with the completed mailbox
2101 * command. If the completed command is a REG_LOGIN mailbox command,
2102 * this function will issue a UREG_LOGIN to re-claim the RPI.
2105 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2107 struct lpfc_vport
*vport
= pmb
->vport
;
2108 struct lpfc_dmabuf
*mp
;
2109 struct lpfc_nodelist
*ndlp
;
2110 struct Scsi_Host
*shost
;
2114 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2117 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2122 * If a REG_LOGIN succeeded after node is destroyed or node
2123 * is in re-discovery driver need to cleanup the RPI.
2125 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2126 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2127 !pmb
->u
.mb
.mbxStatus
) {
2128 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2129 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2130 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2131 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2132 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2133 if (rc
!= MBX_NOT_FINISHED
)
2137 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2138 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2139 !pmb
->u
.mb
.mbxStatus
) {
2140 shost
= lpfc_shost_from_vport(vport
);
2141 spin_lock_irq(shost
->host_lock
);
2142 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2143 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2144 spin_unlock_irq(shost
->host_lock
);
2147 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2148 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2150 pmb
->context2
= NULL
;
2153 /* Check security permission status on INIT_LINK mailbox command */
2154 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2155 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2156 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2157 "2860 SLI authentication is required "
2158 "for INIT_LINK but has not done yet\n");
2160 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2161 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2163 mempool_free(pmb
, phba
->mbox_mem_pool
);
2167 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2168 * @phba: Pointer to HBA context object.
2170 * This function is called with no lock held. This function processes all
2171 * the completed mailbox commands and gives it to upper layers. The interrupt
2172 * service routine processes mailbox completion interrupt and adds completed
2173 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2174 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2175 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2176 * function returns the mailbox commands to the upper layer by calling the
2177 * completion handler function of each mailbox.
2180 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2187 phba
->sli
.slistat
.mbox_event
++;
2189 /* Get all completed mailboxe buffers into the cmplq */
2190 spin_lock_irq(&phba
->hbalock
);
2191 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2192 spin_unlock_irq(&phba
->hbalock
);
2194 /* Get a Mailbox buffer to setup mailbox commands for callback */
2196 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2202 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2204 lpfc_debugfs_disc_trc(pmb
->vport
,
2205 LPFC_DISC_TRC_MBOX_VPORT
,
2206 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2207 (uint32_t)pmbox
->mbxCommand
,
2208 pmbox
->un
.varWords
[0],
2209 pmbox
->un
.varWords
[1]);
2212 lpfc_debugfs_disc_trc(phba
->pport
,
2214 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2215 (uint32_t)pmbox
->mbxCommand
,
2216 pmbox
->un
.varWords
[0],
2217 pmbox
->un
.varWords
[1]);
2222 * It is a fatal error if unknown mbox command completion.
2224 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2226 /* Unknown mailbox command compl */
2227 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2228 "(%d):0323 Unknown Mailbox command "
2229 "x%x (x%x/x%x) Cmpl\n",
2230 pmb
->vport
? pmb
->vport
->vpi
: 0,
2232 lpfc_sli_config_mbox_subsys_get(phba
,
2234 lpfc_sli_config_mbox_opcode_get(phba
,
2236 phba
->link_state
= LPFC_HBA_ERROR
;
2237 phba
->work_hs
= HS_FFER3
;
2238 lpfc_handle_eratt(phba
);
2242 if (pmbox
->mbxStatus
) {
2243 phba
->sli
.slistat
.mbox_stat_err
++;
2244 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2245 /* Mbox cmd cmpl error - RETRYing */
2246 lpfc_printf_log(phba
, KERN_INFO
,
2248 "(%d):0305 Mbox cmd cmpl "
2249 "error - RETRYing Data: x%x "
2250 "(x%x/x%x) x%x x%x x%x\n",
2251 pmb
->vport
? pmb
->vport
->vpi
: 0,
2253 lpfc_sli_config_mbox_subsys_get(phba
,
2255 lpfc_sli_config_mbox_opcode_get(phba
,
2258 pmbox
->un
.varWords
[0],
2259 pmb
->vport
->port_state
);
2260 pmbox
->mbxStatus
= 0;
2261 pmbox
->mbxOwner
= OWN_HOST
;
2262 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2263 if (rc
!= MBX_NOT_FINISHED
)
2268 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2269 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2270 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2271 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2272 pmb
->vport
? pmb
->vport
->vpi
: 0,
2274 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2275 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2277 *((uint32_t *) pmbox
),
2278 pmbox
->un
.varWords
[0],
2279 pmbox
->un
.varWords
[1],
2280 pmbox
->un
.varWords
[2],
2281 pmbox
->un
.varWords
[3],
2282 pmbox
->un
.varWords
[4],
2283 pmbox
->un
.varWords
[5],
2284 pmbox
->un
.varWords
[6],
2285 pmbox
->un
.varWords
[7]);
2288 pmb
->mbox_cmpl(phba
,pmb
);
2294 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2295 * @phba: Pointer to HBA context object.
2296 * @pring: Pointer to driver SLI ring object.
2299 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2300 * is set in the tag the buffer is posted for a particular exchange,
2301 * the function will return the buffer without replacing the buffer.
2302 * If the buffer is for unsolicited ELS or CT traffic, this function
2303 * returns the buffer and also posts another buffer to the firmware.
2305 static struct lpfc_dmabuf
*
2306 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2307 struct lpfc_sli_ring
*pring
,
2310 struct hbq_dmabuf
*hbq_entry
;
2312 if (tag
& QUE_BUFTAG_BIT
)
2313 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2314 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2317 return &hbq_entry
->dbuf
;
2321 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2322 * @phba: Pointer to HBA context object.
2323 * @pring: Pointer to driver SLI ring object.
2324 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2325 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2326 * @fch_type: the type for the first frame of the sequence.
2328 * This function is called with no lock held. This function uses the r_ctl and
2329 * type of the received sequence to find the correct callback function to call
2330 * to process the sequence.
2333 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2334 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2339 /* unSolicited Responses */
2340 if (pring
->prt
[0].profile
) {
2341 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2342 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2346 /* We must search, based on rctl / type
2347 for the right routine */
2348 for (i
= 0; i
< pring
->num_mask
; i
++) {
2349 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2350 (pring
->prt
[i
].type
== fch_type
)) {
2351 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2352 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2353 (phba
, pring
, saveq
);
2361 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2362 * @phba: Pointer to HBA context object.
2363 * @pring: Pointer to driver SLI ring object.
2364 * @saveq: Pointer to the unsolicited iocb.
2366 * This function is called with no lock held by the ring event handler
2367 * when there is an unsolicited iocb posted to the response ring by the
2368 * firmware. This function gets the buffer associated with the iocbs
2369 * and calls the event handler for the ring. This function handles both
2370 * qring buffers and hbq buffers.
2371 * When the function returns 1 the caller can free the iocb object otherwise
2372 * upper layer functions will free the iocb objects.
2375 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2376 struct lpfc_iocbq
*saveq
)
2380 uint32_t Rctl
, Type
;
2382 struct lpfc_iocbq
*iocbq
;
2383 struct lpfc_dmabuf
*dmzbuf
;
2386 irsp
= &(saveq
->iocb
);
2388 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2389 if (pring
->lpfc_sli_rcv_async_status
)
2390 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2392 lpfc_printf_log(phba
,
2395 "0316 Ring %d handler: unexpected "
2396 "ASYNC_STATUS iocb received evt_code "
2399 irsp
->un
.asyncstat
.evt_code
);
2403 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2404 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2405 if (irsp
->ulpBdeCount
> 0) {
2406 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2407 irsp
->un
.ulpWord
[3]);
2408 lpfc_in_buf_free(phba
, dmzbuf
);
2411 if (irsp
->ulpBdeCount
> 1) {
2412 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2413 irsp
->unsli3
.sli3Words
[3]);
2414 lpfc_in_buf_free(phba
, dmzbuf
);
2417 if (irsp
->ulpBdeCount
> 2) {
2418 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2419 irsp
->unsli3
.sli3Words
[7]);
2420 lpfc_in_buf_free(phba
, dmzbuf
);
2426 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2427 if (irsp
->ulpBdeCount
!= 0) {
2428 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2429 irsp
->un
.ulpWord
[3]);
2430 if (!saveq
->context2
)
2431 lpfc_printf_log(phba
,
2434 "0341 Ring %d Cannot find buffer for "
2435 "an unsolicited iocb. tag 0x%x\n",
2437 irsp
->un
.ulpWord
[3]);
2439 if (irsp
->ulpBdeCount
== 2) {
2440 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2441 irsp
->unsli3
.sli3Words
[7]);
2442 if (!saveq
->context3
)
2443 lpfc_printf_log(phba
,
2446 "0342 Ring %d Cannot find buffer for an"
2447 " unsolicited iocb. tag 0x%x\n",
2449 irsp
->unsli3
.sli3Words
[7]);
2451 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2452 irsp
= &(iocbq
->iocb
);
2453 if (irsp
->ulpBdeCount
!= 0) {
2454 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2455 irsp
->un
.ulpWord
[3]);
2456 if (!iocbq
->context2
)
2457 lpfc_printf_log(phba
,
2460 "0343 Ring %d Cannot find "
2461 "buffer for an unsolicited iocb"
2462 ". tag 0x%x\n", pring
->ringno
,
2463 irsp
->un
.ulpWord
[3]);
2465 if (irsp
->ulpBdeCount
== 2) {
2466 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2467 irsp
->unsli3
.sli3Words
[7]);
2468 if (!iocbq
->context3
)
2469 lpfc_printf_log(phba
,
2472 "0344 Ring %d Cannot find "
2473 "buffer for an unsolicited "
2476 irsp
->unsli3
.sli3Words
[7]);
2480 if (irsp
->ulpBdeCount
!= 0 &&
2481 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2482 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2485 /* search continue save q for same XRI */
2486 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2487 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2488 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2489 list_add_tail(&saveq
->list
, &iocbq
->list
);
2495 list_add_tail(&saveq
->clist
,
2496 &pring
->iocb_continue_saveq
);
2497 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2498 list_del_init(&iocbq
->clist
);
2500 irsp
= &(saveq
->iocb
);
2504 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2505 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2506 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2507 Rctl
= FC_RCTL_ELS_REQ
;
2510 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2511 Rctl
= w5p
->hcsw
.Rctl
;
2512 Type
= w5p
->hcsw
.Type
;
2514 /* Firmware Workaround */
2515 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2516 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2517 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2518 Rctl
= FC_RCTL_ELS_REQ
;
2520 w5p
->hcsw
.Rctl
= Rctl
;
2521 w5p
->hcsw
.Type
= Type
;
2525 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2526 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2527 "0313 Ring %d handler: unexpected Rctl x%x "
2528 "Type x%x received\n",
2529 pring
->ringno
, Rctl
, Type
);
2535 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2536 * @phba: Pointer to HBA context object.
2537 * @pring: Pointer to driver SLI ring object.
2538 * @prspiocb: Pointer to response iocb object.
2540 * This function looks up the iocb_lookup table to get the command iocb
2541 * corresponding to the given response iocb using the iotag of the
2542 * response iocb. This function is called with the hbalock held.
2543 * This function returns the command iocb object if it finds the command
2544 * iocb else returns NULL.
2546 static struct lpfc_iocbq
*
2547 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2548 struct lpfc_sli_ring
*pring
,
2549 struct lpfc_iocbq
*prspiocb
)
2551 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2554 iotag
= prspiocb
->iocb
.ulpIoTag
;
2556 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2557 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2558 list_del_init(&cmd_iocb
->list
);
2559 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
2560 pring
->txcmplq_cnt
--;
2561 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
2566 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2567 "0317 iotag x%x is out off "
2568 "range: max iotag x%x wd0 x%x\n",
2569 iotag
, phba
->sli
.last_iotag
,
2570 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2575 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2576 * @phba: Pointer to HBA context object.
2577 * @pring: Pointer to driver SLI ring object.
2580 * This function looks up the iocb_lookup table to get the command iocb
2581 * corresponding to the given iotag. This function is called with the
2583 * This function returns the command iocb object if it finds the command
2584 * iocb else returns NULL.
2586 static struct lpfc_iocbq
*
2587 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2588 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2590 struct lpfc_iocbq
*cmd_iocb
;
2592 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2593 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2594 list_del_init(&cmd_iocb
->list
);
2595 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
2596 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
2597 pring
->txcmplq_cnt
--;
2602 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2603 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2604 iotag
, phba
->sli
.last_iotag
);
2609 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2610 * @phba: Pointer to HBA context object.
2611 * @pring: Pointer to driver SLI ring object.
2612 * @saveq: Pointer to the response iocb to be processed.
2614 * This function is called by the ring event handler for non-fcp
2615 * rings when there is a new response iocb in the response ring.
2616 * The caller is not required to hold any locks. This function
2617 * gets the command iocb associated with the response iocb and
2618 * calls the completion handler for the command iocb. If there
2619 * is no completion handler, the function will free the resources
2620 * associated with command iocb. If the response iocb is for
2621 * an already aborted command iocb, the status of the completion
2622 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2623 * This function always returns 1.
2626 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2627 struct lpfc_iocbq
*saveq
)
2629 struct lpfc_iocbq
*cmdiocbp
;
2631 unsigned long iflag
;
2633 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2634 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2635 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2636 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2639 if (cmdiocbp
->iocb_cmpl
) {
2641 * If an ELS command failed send an event to mgmt
2644 if (saveq
->iocb
.ulpStatus
&&
2645 (pring
->ringno
== LPFC_ELS_RING
) &&
2646 (cmdiocbp
->iocb
.ulpCommand
==
2647 CMD_ELS_REQUEST64_CR
))
2648 lpfc_send_els_failure_event(phba
,
2652 * Post all ELS completions to the worker thread.
2653 * All other are passed to the completion callback.
2655 if (pring
->ringno
== LPFC_ELS_RING
) {
2656 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2657 (cmdiocbp
->iocb_flag
&
2658 LPFC_DRIVER_ABORTED
)) {
2659 spin_lock_irqsave(&phba
->hbalock
,
2661 cmdiocbp
->iocb_flag
&=
2662 ~LPFC_DRIVER_ABORTED
;
2663 spin_unlock_irqrestore(&phba
->hbalock
,
2665 saveq
->iocb
.ulpStatus
=
2666 IOSTAT_LOCAL_REJECT
;
2667 saveq
->iocb
.un
.ulpWord
[4] =
2670 /* Firmware could still be in progress
2671 * of DMAing payload, so don't free data
2672 * buffer till after a hbeat.
2674 spin_lock_irqsave(&phba
->hbalock
,
2676 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2677 spin_unlock_irqrestore(&phba
->hbalock
,
2680 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2681 if (saveq
->iocb_flag
&
2682 LPFC_EXCHANGE_BUSY
) {
2683 /* Set cmdiocb flag for the
2684 * exchange busy so sgl (xri)
2685 * will not be released until
2686 * the abort xri is received
2690 &phba
->hbalock
, iflag
);
2691 cmdiocbp
->iocb_flag
|=
2693 spin_unlock_irqrestore(
2694 &phba
->hbalock
, iflag
);
2696 if (cmdiocbp
->iocb_flag
&
2697 LPFC_DRIVER_ABORTED
) {
2699 * Clear LPFC_DRIVER_ABORTED
2700 * bit in case it was driver
2704 &phba
->hbalock
, iflag
);
2705 cmdiocbp
->iocb_flag
&=
2706 ~LPFC_DRIVER_ABORTED
;
2707 spin_unlock_irqrestore(
2708 &phba
->hbalock
, iflag
);
2709 cmdiocbp
->iocb
.ulpStatus
=
2710 IOSTAT_LOCAL_REJECT
;
2711 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2712 IOERR_ABORT_REQUESTED
;
2714 * For SLI4, irsiocb contains
2715 * NO_XRI in sli_xritag, it
2716 * shall not affect releasing
2717 * sgl (xri) process.
2719 saveq
->iocb
.ulpStatus
=
2720 IOSTAT_LOCAL_REJECT
;
2721 saveq
->iocb
.un
.ulpWord
[4] =
2724 &phba
->hbalock
, iflag
);
2726 LPFC_DELAY_MEM_FREE
;
2727 spin_unlock_irqrestore(
2728 &phba
->hbalock
, iflag
);
2732 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2734 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2737 * Unknown initiating command based on the response iotag.
2738 * This could be the case on the ELS ring because of
2741 if (pring
->ringno
!= LPFC_ELS_RING
) {
2743 * Ring <ringno> handler: unexpected completion IoTag
2746 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2747 "0322 Ring %d handler: "
2748 "unexpected completion IoTag x%x "
2749 "Data: x%x x%x x%x x%x\n",
2751 saveq
->iocb
.ulpIoTag
,
2752 saveq
->iocb
.ulpStatus
,
2753 saveq
->iocb
.un
.ulpWord
[4],
2754 saveq
->iocb
.ulpCommand
,
2755 saveq
->iocb
.ulpContext
);
2763 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2764 * @phba: Pointer to HBA context object.
2765 * @pring: Pointer to driver SLI ring object.
2767 * This function is called from the iocb ring event handlers when
2768 * put pointer is ahead of the get pointer for a ring. This function signal
2769 * an error attention condition to the worker thread and the worker
2770 * thread will transition the HBA to offline state.
2773 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2775 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2777 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2778 * rsp ring <portRspMax>
2780 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2781 "0312 Ring %d handler: portRspPut %d "
2782 "is bigger than rsp ring %d\n",
2783 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2786 phba
->link_state
= LPFC_HBA_ERROR
;
2789 * All error attention handlers are posted to
2792 phba
->work_ha
|= HA_ERATT
;
2793 phba
->work_hs
= HS_FFER3
;
2795 lpfc_worker_wake_up(phba
);
2801 * lpfc_poll_eratt - Error attention polling timer timeout handler
2802 * @ptr: Pointer to address of HBA context object.
2804 * This function is invoked by the Error Attention polling timer when the
2805 * timer times out. It will check the SLI Error Attention register for
2806 * possible attention events. If so, it will post an Error Attention event
2807 * and wake up worker thread to process it. Otherwise, it will set up the
2808 * Error Attention polling timer for the next poll.
2810 void lpfc_poll_eratt(unsigned long ptr
)
2812 struct lpfc_hba
*phba
;
2815 phba
= (struct lpfc_hba
*)ptr
;
2817 /* Check chip HA register for error event */
2818 eratt
= lpfc_sli_check_eratt(phba
);
2821 /* Tell the worker thread there is work to do */
2822 lpfc_worker_wake_up(phba
);
2824 /* Restart the timer for next eratt poll */
2825 mod_timer(&phba
->eratt_poll
, jiffies
+
2826 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2832 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2833 * @phba: Pointer to HBA context object.
2834 * @pring: Pointer to driver SLI ring object.
2835 * @mask: Host attention register mask for this ring.
2837 * This function is called from the interrupt context when there is a ring
2838 * event for the fcp ring. The caller does not hold any lock.
2839 * The function processes each response iocb in the response ring until it
2840 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2841 * LE bit set. The function will call the completion handler of the command iocb
2842 * if the response iocb indicates a completion for a command iocb or it is
2843 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2844 * function if this is an unsolicited iocb.
2845 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2846 * to check it explicitly.
2849 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2850 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2852 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2853 IOCB_t
*irsp
= NULL
;
2854 IOCB_t
*entry
= NULL
;
2855 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2856 struct lpfc_iocbq rspiocbq
;
2858 uint32_t portRspPut
, portRspMax
;
2860 lpfc_iocb_type type
;
2861 unsigned long iflag
;
2862 uint32_t rsp_cmpl
= 0;
2864 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2865 pring
->stats
.iocb_event
++;
2868 * The next available response entry should never exceed the maximum
2869 * entries. If it does, treat it as an adapter hardware error.
2871 portRspMax
= pring
->numRiocb
;
2872 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2873 if (unlikely(portRspPut
>= portRspMax
)) {
2874 lpfc_sli_rsp_pointers_error(phba
, pring
);
2875 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2878 if (phba
->fcp_ring_in_use
) {
2879 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2882 phba
->fcp_ring_in_use
= 1;
2885 while (pring
->rspidx
!= portRspPut
) {
2887 * Fetch an entry off the ring and copy it into a local data
2888 * structure. The copy involves a byte-swap since the
2889 * network byte order and pci byte orders are different.
2891 entry
= lpfc_resp_iocb(phba
, pring
);
2892 phba
->last_completion_time
= jiffies
;
2894 if (++pring
->rspidx
>= portRspMax
)
2897 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2898 (uint32_t *) &rspiocbq
.iocb
,
2899 phba
->iocb_rsp_size
);
2900 INIT_LIST_HEAD(&(rspiocbq
.list
));
2901 irsp
= &rspiocbq
.iocb
;
2903 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2904 pring
->stats
.iocb_rsp
++;
2907 if (unlikely(irsp
->ulpStatus
)) {
2909 * If resource errors reported from HBA, reduce
2910 * queuedepths of the SCSI device.
2912 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2913 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2914 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2915 phba
->lpfc_rampdown_queue_depth(phba
);
2916 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2919 /* Rsp ring <ringno> error: IOCB */
2920 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2921 "0336 Rsp Ring %d error: IOCB Data: "
2922 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2924 irsp
->un
.ulpWord
[0],
2925 irsp
->un
.ulpWord
[1],
2926 irsp
->un
.ulpWord
[2],
2927 irsp
->un
.ulpWord
[3],
2928 irsp
->un
.ulpWord
[4],
2929 irsp
->un
.ulpWord
[5],
2930 *(uint32_t *)&irsp
->un1
,
2931 *((uint32_t *)&irsp
->un1
+ 1));
2935 case LPFC_ABORT_IOCB
:
2938 * Idle exchange closed via ABTS from port. No iocb
2939 * resources need to be recovered.
2941 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2942 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2943 "0333 IOCB cmd 0x%x"
2944 " processed. Skipping"
2950 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2952 if (unlikely(!cmdiocbq
))
2954 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
2955 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
2956 if (cmdiocbq
->iocb_cmpl
) {
2957 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2958 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2960 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2963 case LPFC_UNSOL_IOCB
:
2964 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2965 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2966 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2969 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2970 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2971 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2972 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2974 dev_warn(&((phba
->pcidev
)->dev
),
2976 phba
->brd_no
, adaptermsg
);
2978 /* Unknown IOCB command */
2979 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2980 "0334 Unknown IOCB command "
2981 "Data: x%x, x%x x%x x%x x%x\n",
2982 type
, irsp
->ulpCommand
,
2991 * The response IOCB has been processed. Update the ring
2992 * pointer in SLIM. If the port response put pointer has not
2993 * been updated, sync the pgp->rspPutInx and fetch the new port
2994 * response put pointer.
2996 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2998 if (pring
->rspidx
== portRspPut
)
2999 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3002 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3003 pring
->stats
.iocb_rsp_full
++;
3004 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3005 writel(status
, phba
->CAregaddr
);
3006 readl(phba
->CAregaddr
);
3008 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3009 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3010 pring
->stats
.iocb_cmd_empty
++;
3012 /* Force update of the local copy of cmdGetInx */
3013 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3014 lpfc_sli_resume_iocb(phba
, pring
);
3016 if ((pring
->lpfc_sli_cmd_available
))
3017 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3021 phba
->fcp_ring_in_use
= 0;
3022 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3027 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3028 * @phba: Pointer to HBA context object.
3029 * @pring: Pointer to driver SLI ring object.
3030 * @rspiocbp: Pointer to driver response IOCB object.
3032 * This function is called from the worker thread when there is a slow-path
3033 * response IOCB to process. This function chains all the response iocbs until
3034 * seeing the iocb with the LE bit set. The function will call
3035 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3036 * completion of a command iocb. The function will call the
3037 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3038 * The function frees the resources or calls the completion handler if this
3039 * iocb is an abort completion. The function returns NULL when the response
3040 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3041 * this function shall chain the iocb on to the iocb_continueq and return the
3042 * response iocb passed in.
3044 static struct lpfc_iocbq
*
3045 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3046 struct lpfc_iocbq
*rspiocbp
)
3048 struct lpfc_iocbq
*saveq
;
3049 struct lpfc_iocbq
*cmdiocbp
;
3050 struct lpfc_iocbq
*next_iocb
;
3051 IOCB_t
*irsp
= NULL
;
3052 uint32_t free_saveq
;
3053 uint8_t iocb_cmd_type
;
3054 lpfc_iocb_type type
;
3055 unsigned long iflag
;
3058 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3059 /* First add the response iocb to the countinueq list */
3060 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3061 pring
->iocb_continueq_cnt
++;
3063 /* Now, determine whether the list is completed for processing */
3064 irsp
= &rspiocbp
->iocb
;
3067 * By default, the driver expects to free all resources
3068 * associated with this iocb completion.
3071 saveq
= list_get_first(&pring
->iocb_continueq
,
3072 struct lpfc_iocbq
, list
);
3073 irsp
= &(saveq
->iocb
);
3074 list_del_init(&pring
->iocb_continueq
);
3075 pring
->iocb_continueq_cnt
= 0;
3077 pring
->stats
.iocb_rsp
++;
3080 * If resource errors reported from HBA, reduce
3081 * queuedepths of the SCSI device.
3083 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3084 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
3085 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3086 phba
->lpfc_rampdown_queue_depth(phba
);
3087 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3090 if (irsp
->ulpStatus
) {
3091 /* Rsp ring <ringno> error: IOCB */
3092 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3093 "0328 Rsp Ring %d error: "
3098 "x%x x%x x%x x%x\n",
3100 irsp
->un
.ulpWord
[0],
3101 irsp
->un
.ulpWord
[1],
3102 irsp
->un
.ulpWord
[2],
3103 irsp
->un
.ulpWord
[3],
3104 irsp
->un
.ulpWord
[4],
3105 irsp
->un
.ulpWord
[5],
3106 *(((uint32_t *) irsp
) + 6),
3107 *(((uint32_t *) irsp
) + 7),
3108 *(((uint32_t *) irsp
) + 8),
3109 *(((uint32_t *) irsp
) + 9),
3110 *(((uint32_t *) irsp
) + 10),
3111 *(((uint32_t *) irsp
) + 11),
3112 *(((uint32_t *) irsp
) + 12),
3113 *(((uint32_t *) irsp
) + 13),
3114 *(((uint32_t *) irsp
) + 14),
3115 *(((uint32_t *) irsp
) + 15));
3119 * Fetch the IOCB command type and call the correct completion
3120 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3121 * get freed back to the lpfc_iocb_list by the discovery
3124 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3125 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3128 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3129 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3130 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3133 case LPFC_UNSOL_IOCB
:
3134 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3135 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3136 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3141 case LPFC_ABORT_IOCB
:
3143 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3144 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3147 /* Call the specified completion routine */
3148 if (cmdiocbp
->iocb_cmpl
) {
3149 spin_unlock_irqrestore(&phba
->hbalock
,
3151 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3153 spin_lock_irqsave(&phba
->hbalock
,
3156 __lpfc_sli_release_iocbq(phba
,
3161 case LPFC_UNKNOWN_IOCB
:
3162 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3163 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3164 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3165 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3167 dev_warn(&((phba
->pcidev
)->dev
),
3169 phba
->brd_no
, adaptermsg
);
3171 /* Unknown IOCB command */
3172 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3173 "0335 Unknown IOCB "
3174 "command Data: x%x "
3185 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3186 &saveq
->list
, list
) {
3187 list_del(&rspiocbp
->list
);
3188 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3190 __lpfc_sli_release_iocbq(phba
, saveq
);
3194 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3199 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3200 * @phba: Pointer to HBA context object.
3201 * @pring: Pointer to driver SLI ring object.
3202 * @mask: Host attention register mask for this ring.
3204 * This routine wraps the actual slow_ring event process routine from the
3205 * API jump table function pointer from the lpfc_hba struct.
3208 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3209 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3211 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3215 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3216 * @phba: Pointer to HBA context object.
3217 * @pring: Pointer to driver SLI ring object.
3218 * @mask: Host attention register mask for this ring.
3220 * This function is called from the worker thread when there is a ring event
3221 * for non-fcp rings. The caller does not hold any lock. The function will
3222 * remove each response iocb in the response ring and calls the handle
3223 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3226 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3227 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3229 struct lpfc_pgp
*pgp
;
3231 IOCB_t
*irsp
= NULL
;
3232 struct lpfc_iocbq
*rspiocbp
= NULL
;
3233 uint32_t portRspPut
, portRspMax
;
3234 unsigned long iflag
;
3237 pgp
= &phba
->port_gp
[pring
->ringno
];
3238 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3239 pring
->stats
.iocb_event
++;
3242 * The next available response entry should never exceed the maximum
3243 * entries. If it does, treat it as an adapter hardware error.
3245 portRspMax
= pring
->numRiocb
;
3246 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3247 if (portRspPut
>= portRspMax
) {
3249 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3250 * rsp ring <portRspMax>
3252 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3253 "0303 Ring %d handler: portRspPut %d "
3254 "is bigger than rsp ring %d\n",
3255 pring
->ringno
, portRspPut
, portRspMax
);
3257 phba
->link_state
= LPFC_HBA_ERROR
;
3258 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3260 phba
->work_hs
= HS_FFER3
;
3261 lpfc_handle_eratt(phba
);
3267 while (pring
->rspidx
!= portRspPut
) {
3269 * Build a completion list and call the appropriate handler.
3270 * The process is to get the next available response iocb, get
3271 * a free iocb from the list, copy the response data into the
3272 * free iocb, insert to the continuation list, and update the
3273 * next response index to slim. This process makes response
3274 * iocb's in the ring available to DMA as fast as possible but
3275 * pays a penalty for a copy operation. Since the iocb is
3276 * only 32 bytes, this penalty is considered small relative to
3277 * the PCI reads for register values and a slim write. When
3278 * the ulpLe field is set, the entire Command has been
3281 entry
= lpfc_resp_iocb(phba
, pring
);
3283 phba
->last_completion_time
= jiffies
;
3284 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3285 if (rspiocbp
== NULL
) {
3286 printk(KERN_ERR
"%s: out of buffers! Failing "
3287 "completion.\n", __func__
);
3291 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3292 phba
->iocb_rsp_size
);
3293 irsp
= &rspiocbp
->iocb
;
3295 if (++pring
->rspidx
>= portRspMax
)
3298 if (pring
->ringno
== LPFC_ELS_RING
) {
3299 lpfc_debugfs_slow_ring_trc(phba
,
3300 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3301 *(((uint32_t *) irsp
) + 4),
3302 *(((uint32_t *) irsp
) + 6),
3303 *(((uint32_t *) irsp
) + 7));
3306 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3308 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3309 /* Handle the response IOCB */
3310 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3311 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3314 * If the port response put pointer has not been updated, sync
3315 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3316 * response put pointer.
3318 if (pring
->rspidx
== portRspPut
) {
3319 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3321 } /* while (pring->rspidx != portRspPut) */
3323 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3324 /* At least one response entry has been freed */
3325 pring
->stats
.iocb_rsp_full
++;
3326 /* SET RxRE_RSP in Chip Att register */
3327 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3328 writel(status
, phba
->CAregaddr
);
3329 readl(phba
->CAregaddr
); /* flush */
3331 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3332 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3333 pring
->stats
.iocb_cmd_empty
++;
3335 /* Force update of the local copy of cmdGetInx */
3336 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3337 lpfc_sli_resume_iocb(phba
, pring
);
3339 if ((pring
->lpfc_sli_cmd_available
))
3340 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3344 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3349 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3350 * @phba: Pointer to HBA context object.
3351 * @pring: Pointer to driver SLI ring object.
3352 * @mask: Host attention register mask for this ring.
3354 * This function is called from the worker thread when there is a pending
3355 * ELS response iocb on the driver internal slow-path response iocb worker
3356 * queue. The caller does not hold any lock. The function will remove each
3357 * response iocb from the response worker queue and calls the handle
3358 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3361 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3362 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3364 struct lpfc_iocbq
*irspiocbq
;
3365 struct hbq_dmabuf
*dmabuf
;
3366 struct lpfc_cq_event
*cq_event
;
3367 unsigned long iflag
;
3369 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3370 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3371 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3372 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3373 /* Get the response iocb from the head of work queue */
3374 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3375 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3376 cq_event
, struct lpfc_cq_event
, list
);
3377 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3379 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3380 case CQE_CODE_COMPL_WQE
:
3381 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3383 /* Translate ELS WCQE to response IOCBQ */
3384 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3387 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3390 case CQE_CODE_RECEIVE
:
3391 case CQE_CODE_RECEIVE_V1
:
3392 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3394 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3403 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3404 * @phba: Pointer to HBA context object.
3405 * @pring: Pointer to driver SLI ring object.
3407 * This function aborts all iocbs in the given ring and frees all the iocb
3408 * objects in txq. This function issues an abort iocb for all the iocb commands
3409 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3410 * the return of this function. The caller is not required to hold any locks.
3413 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3415 LIST_HEAD(completions
);
3416 struct lpfc_iocbq
*iocb
, *next_iocb
;
3418 if (pring
->ringno
== LPFC_ELS_RING
) {
3419 lpfc_fabric_abort_hba(phba
);
3422 /* Error everything on txq and txcmplq
3425 spin_lock_irq(&phba
->hbalock
);
3426 list_splice_init(&pring
->txq
, &completions
);
3429 /* Next issue ABTS for everything on the txcmplq */
3430 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3431 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3433 spin_unlock_irq(&phba
->hbalock
);
3435 /* Cancel all the IOCBs from the completions list */
3436 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3441 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3442 * @phba: Pointer to HBA context object.
3444 * This function flushes all iocbs in the fcp ring and frees all the iocb
3445 * objects in txq and txcmplq. This function will not issue abort iocbs
3446 * for all the iocb commands in txcmplq, they will just be returned with
3447 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3448 * slot has been permanently disabled.
3451 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3455 struct lpfc_sli
*psli
= &phba
->sli
;
3456 struct lpfc_sli_ring
*pring
;
3458 /* Currently, only one fcp ring */
3459 pring
= &psli
->ring
[psli
->fcp_ring
];
3461 spin_lock_irq(&phba
->hbalock
);
3462 /* Retrieve everything on txq */
3463 list_splice_init(&pring
->txq
, &txq
);
3466 /* Retrieve everything on the txcmplq */
3467 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3468 pring
->txcmplq_cnt
= 0;
3469 spin_unlock_irq(&phba
->hbalock
);
3472 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3475 /* Flush the txcmpq */
3476 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3481 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3482 * @phba: Pointer to HBA context object.
3483 * @mask: Bit mask to be checked.
3485 * This function reads the host status register and compares
3486 * with the provided bit mask to check if HBA completed
3487 * the restart. This function will wait in a loop for the
3488 * HBA to complete restart. If the HBA does not restart within
3489 * 15 iterations, the function will reset the HBA again. The
3490 * function returns 1 when HBA fail to restart otherwise returns
3494 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3500 /* Read the HBA Host Status Register */
3501 if (lpfc_readl(phba
->HSregaddr
, &status
))
3505 * Check status register every 100ms for 5 retries, then every
3506 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3507 * every 2.5 sec for 4.
3508 * Break our of the loop if errors occurred during init.
3510 while (((status
& mask
) != mask
) &&
3511 !(status
& HS_FFERM
) &&
3523 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3524 lpfc_sli_brdrestart(phba
);
3526 /* Read the HBA Host Status Register */
3527 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3533 /* Check to see if any errors occurred during init */
3534 if ((status
& HS_FFERM
) || (i
>= 20)) {
3535 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3536 "2751 Adapter failed to restart, "
3537 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3539 readl(phba
->MBslimaddr
+ 0xa8),
3540 readl(phba
->MBslimaddr
+ 0xac));
3541 phba
->link_state
= LPFC_HBA_ERROR
;
3549 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3550 * @phba: Pointer to HBA context object.
3551 * @mask: Bit mask to be checked.
3553 * This function checks the host status register to check if HBA is
3554 * ready. This function will wait in a loop for the HBA to be ready
3555 * If the HBA is not ready , the function will will reset the HBA PCI
3556 * function again. The function returns 1 when HBA fail to be ready
3557 * otherwise returns zero.
3560 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3565 /* Read the HBA Host Status Register */
3566 status
= lpfc_sli4_post_status_check(phba
);
3569 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3570 lpfc_sli_brdrestart(phba
);
3571 status
= lpfc_sli4_post_status_check(phba
);
3574 /* Check to see if any errors occurred during init */
3576 phba
->link_state
= LPFC_HBA_ERROR
;
3579 phba
->sli4_hba
.intr_enable
= 0;
3585 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3586 * @phba: Pointer to HBA context object.
3587 * @mask: Bit mask to be checked.
3589 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3590 * from the API jump table function pointer from the lpfc_hba struct.
3593 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3595 return phba
->lpfc_sli_brdready(phba
, mask
);
3598 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3601 * lpfc_reset_barrier - Make HBA ready for HBA reset
3602 * @phba: Pointer to HBA context object.
3604 * This function is called before resetting an HBA. This function is called
3605 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3607 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3609 uint32_t __iomem
*resp_buf
;
3610 uint32_t __iomem
*mbox_buf
;
3611 volatile uint32_t mbox
;
3612 uint32_t hc_copy
, ha_copy
, resp_data
;
3616 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3617 if (hdrtype
!= 0x80 ||
3618 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3619 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3623 * Tell the other part of the chip to suspend temporarily all
3626 resp_buf
= phba
->MBslimaddr
;
3628 /* Disable the error attention */
3629 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3631 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3632 readl(phba
->HCregaddr
); /* flush */
3633 phba
->link_flag
|= LS_IGNORE_ERATT
;
3635 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3637 if (ha_copy
& HA_ERATT
) {
3638 /* Clear Chip error bit */
3639 writel(HA_ERATT
, phba
->HAregaddr
);
3640 phba
->pport
->stopped
= 1;
3644 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3645 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3647 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3648 mbox_buf
= phba
->MBslimaddr
;
3649 writel(mbox
, mbox_buf
);
3651 for (i
= 0; i
< 50; i
++) {
3652 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3654 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3660 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3662 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3663 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3664 phba
->pport
->stopped
)
3670 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3672 for (i
= 0; i
< 500; i
++) {
3673 if (lpfc_readl(resp_buf
, &resp_data
))
3675 if (resp_data
!= mbox
)
3684 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3686 if (!(ha_copy
& HA_ERATT
))
3692 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3693 writel(HA_ERATT
, phba
->HAregaddr
);
3694 phba
->pport
->stopped
= 1;
3698 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3699 writel(hc_copy
, phba
->HCregaddr
);
3700 readl(phba
->HCregaddr
); /* flush */
3704 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3705 * @phba: Pointer to HBA context object.
3707 * This function issues a kill_board mailbox command and waits for
3708 * the error attention interrupt. This function is called for stopping
3709 * the firmware processing. The caller is not required to hold any
3710 * locks. This function calls lpfc_hba_down_post function to free
3711 * any pending commands after the kill. The function will return 1 when it
3712 * fails to kill the board else will return 0.
3715 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3717 struct lpfc_sli
*psli
;
3727 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3728 "0329 Kill HBA Data: x%x x%x\n",
3729 phba
->pport
->port_state
, psli
->sli_flag
);
3731 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3735 /* Disable the error attention */
3736 spin_lock_irq(&phba
->hbalock
);
3737 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3738 spin_unlock_irq(&phba
->hbalock
);
3739 mempool_free(pmb
, phba
->mbox_mem_pool
);
3742 status
&= ~HC_ERINT_ENA
;
3743 writel(status
, phba
->HCregaddr
);
3744 readl(phba
->HCregaddr
); /* flush */
3745 phba
->link_flag
|= LS_IGNORE_ERATT
;
3746 spin_unlock_irq(&phba
->hbalock
);
3748 lpfc_kill_board(phba
, pmb
);
3749 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3750 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3752 if (retval
!= MBX_SUCCESS
) {
3753 if (retval
!= MBX_BUSY
)
3754 mempool_free(pmb
, phba
->mbox_mem_pool
);
3755 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3756 "2752 KILL_BOARD command failed retval %d\n",
3758 spin_lock_irq(&phba
->hbalock
);
3759 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3760 spin_unlock_irq(&phba
->hbalock
);
3764 spin_lock_irq(&phba
->hbalock
);
3765 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3766 spin_unlock_irq(&phba
->hbalock
);
3768 mempool_free(pmb
, phba
->mbox_mem_pool
);
3770 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3771 * attention every 100ms for 3 seconds. If we don't get ERATT after
3772 * 3 seconds we still set HBA_ERROR state because the status of the
3773 * board is now undefined.
3775 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3777 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3779 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3783 del_timer_sync(&psli
->mbox_tmo
);
3784 if (ha_copy
& HA_ERATT
) {
3785 writel(HA_ERATT
, phba
->HAregaddr
);
3786 phba
->pport
->stopped
= 1;
3788 spin_lock_irq(&phba
->hbalock
);
3789 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3790 psli
->mbox_active
= NULL
;
3791 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3792 spin_unlock_irq(&phba
->hbalock
);
3794 lpfc_hba_down_post(phba
);
3795 phba
->link_state
= LPFC_HBA_ERROR
;
3797 return ha_copy
& HA_ERATT
? 0 : 1;
3801 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3802 * @phba: Pointer to HBA context object.
3804 * This function resets the HBA by writing HC_INITFF to the control
3805 * register. After the HBA resets, this function resets all the iocb ring
3806 * indices. This function disables PCI layer parity checking during
3808 * This function returns 0 always.
3809 * The caller is not required to hold any locks.
3812 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3814 struct lpfc_sli
*psli
;
3815 struct lpfc_sli_ring
*pring
;
3822 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3823 "0325 Reset HBA Data: x%x x%x\n",
3824 phba
->pport
->port_state
, psli
->sli_flag
);
3826 /* perform board reset */
3827 phba
->fc_eventTag
= 0;
3828 phba
->link_events
= 0;
3829 phba
->pport
->fc_myDID
= 0;
3830 phba
->pport
->fc_prevDID
= 0;
3832 /* Turn off parity checking and serr during the physical reset */
3833 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3834 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3836 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3838 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3840 /* Now toggle INITFF bit in the Host Control Register */
3841 writel(HC_INITFF
, phba
->HCregaddr
);
3843 readl(phba
->HCregaddr
); /* flush */
3844 writel(0, phba
->HCregaddr
);
3845 readl(phba
->HCregaddr
); /* flush */
3847 /* Restore PCI cmd register */
3848 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3850 /* Initialize relevant SLI info */
3851 for (i
= 0; i
< psli
->num_rings
; i
++) {
3852 pring
= &psli
->ring
[i
];
3855 pring
->next_cmdidx
= 0;
3856 pring
->local_getidx
= 0;
3858 pring
->missbufcnt
= 0;
3861 phba
->link_state
= LPFC_WARM_START
;
3866 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3867 * @phba: Pointer to HBA context object.
3869 * This function resets a SLI4 HBA. This function disables PCI layer parity
3870 * checking during resets the device. The caller is not required to hold
3873 * This function returns 0 always.
3876 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3878 struct lpfc_sli
*psli
= &phba
->sli
;
3882 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3883 "0295 Reset HBA Data: x%x x%x\n",
3884 phba
->pport
->port_state
, psli
->sli_flag
);
3886 /* perform board reset */
3887 phba
->fc_eventTag
= 0;
3888 phba
->link_events
= 0;
3889 phba
->pport
->fc_myDID
= 0;
3890 phba
->pport
->fc_prevDID
= 0;
3892 spin_lock_irq(&phba
->hbalock
);
3893 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3894 phba
->fcf
.fcf_flag
= 0;
3895 spin_unlock_irq(&phba
->hbalock
);
3897 /* Now physically reset the device */
3898 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3899 "0389 Performing PCI function reset!\n");
3901 /* Turn off parity checking and serr during the physical reset */
3902 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3903 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3904 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3906 /* Perform FCoE PCI function reset */
3907 lpfc_sli4_queue_destroy(phba
);
3908 lpfc_pci_function_reset(phba
);
3910 /* Restore PCI cmd register */
3911 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3917 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3918 * @phba: Pointer to HBA context object.
3920 * This function is called in the SLI initialization code path to
3921 * restart the HBA. The caller is not required to hold any lock.
3922 * This function writes MBX_RESTART mailbox command to the SLIM and
3923 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3924 * function to free any pending commands. The function enables
3925 * POST only during the first initialization. The function returns zero.
3926 * The function does not guarantee completion of MBX_RESTART mailbox
3927 * command before the return of this function.
3930 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3933 struct lpfc_sli
*psli
;
3934 volatile uint32_t word0
;
3935 void __iomem
*to_slim
;
3936 uint32_t hba_aer_enabled
;
3938 spin_lock_irq(&phba
->hbalock
);
3940 /* Take PCIe device Advanced Error Reporting (AER) state */
3941 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3946 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3947 "0337 Restart HBA Data: x%x x%x\n",
3948 phba
->pport
->port_state
, psli
->sli_flag
);
3951 mb
= (MAILBOX_t
*) &word0
;
3952 mb
->mbxCommand
= MBX_RESTART
;
3955 lpfc_reset_barrier(phba
);
3957 to_slim
= phba
->MBslimaddr
;
3958 writel(*(uint32_t *) mb
, to_slim
);
3959 readl(to_slim
); /* flush */
3961 /* Only skip post after fc_ffinit is completed */
3962 if (phba
->pport
->port_state
)
3963 word0
= 1; /* This is really setting up word1 */
3965 word0
= 0; /* This is really setting up word1 */
3966 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
3967 writel(*(uint32_t *) mb
, to_slim
);
3968 readl(to_slim
); /* flush */
3970 lpfc_sli_brdreset(phba
);
3971 phba
->pport
->stopped
= 0;
3972 phba
->link_state
= LPFC_INIT_START
;
3974 spin_unlock_irq(&phba
->hbalock
);
3976 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3977 psli
->stats_start
= get_seconds();
3979 /* Give the INITFF and Post time to settle. */
3982 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
3983 if (hba_aer_enabled
)
3984 pci_disable_pcie_error_reporting(phba
->pcidev
);
3986 lpfc_hba_down_post(phba
);
3992 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3993 * @phba: Pointer to HBA context object.
3995 * This function is called in the SLI initialization code path to restart
3996 * a SLI4 HBA. The caller is not required to hold any lock.
3997 * At the end of the function, it calls lpfc_hba_down_post function to
3998 * free any pending commands.
4001 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4003 struct lpfc_sli
*psli
= &phba
->sli
;
4004 uint32_t hba_aer_enabled
;
4007 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4008 "0296 Restart HBA Data: x%x x%x\n",
4009 phba
->pport
->port_state
, psli
->sli_flag
);
4011 /* Take PCIe device Advanced Error Reporting (AER) state */
4012 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4014 lpfc_sli4_brdreset(phba
);
4016 spin_lock_irq(&phba
->hbalock
);
4017 phba
->pport
->stopped
= 0;
4018 phba
->link_state
= LPFC_INIT_START
;
4020 spin_unlock_irq(&phba
->hbalock
);
4022 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4023 psli
->stats_start
= get_seconds();
4025 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4026 if (hba_aer_enabled
)
4027 pci_disable_pcie_error_reporting(phba
->pcidev
);
4029 lpfc_hba_down_post(phba
);
4035 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4036 * @phba: Pointer to HBA context object.
4038 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4039 * API jump table function pointer from the lpfc_hba struct.
4042 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4044 return phba
->lpfc_sli_brdrestart(phba
);
4048 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4049 * @phba: Pointer to HBA context object.
4051 * This function is called after a HBA restart to wait for successful
4052 * restart of the HBA. Successful restart of the HBA is indicated by
4053 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4054 * iteration, the function will restart the HBA again. The function returns
4055 * zero if HBA successfully restarted else returns negative error code.
4058 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4060 uint32_t status
, i
= 0;
4062 /* Read the HBA Host Status Register */
4063 if (lpfc_readl(phba
->HSregaddr
, &status
))
4066 /* Check status register to see what current state is */
4068 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4070 /* Check every 10ms for 10 retries, then every 100ms for 90
4071 * retries, then every 1 sec for 50 retires for a total of
4072 * ~60 seconds before reset the board again and check every
4073 * 1 sec for 50 retries. The up to 60 seconds before the
4074 * board ready is required by the Falcon FIPS zeroization
4075 * complete, and any reset the board in between shall cause
4076 * restart of zeroization, further delay the board ready.
4079 /* Adapter failed to init, timeout, status reg
4081 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4082 "0436 Adapter failed to init, "
4083 "timeout, status reg x%x, "
4084 "FW Data: A8 x%x AC x%x\n", status
,
4085 readl(phba
->MBslimaddr
+ 0xa8),
4086 readl(phba
->MBslimaddr
+ 0xac));
4087 phba
->link_state
= LPFC_HBA_ERROR
;
4091 /* Check to see if any errors occurred during init */
4092 if (status
& HS_FFERM
) {
4093 /* ERROR: During chipset initialization */
4094 /* Adapter failed to init, chipset, status reg
4096 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4097 "0437 Adapter failed to init, "
4098 "chipset, status reg x%x, "
4099 "FW Data: A8 x%x AC x%x\n", status
,
4100 readl(phba
->MBslimaddr
+ 0xa8),
4101 readl(phba
->MBslimaddr
+ 0xac));
4102 phba
->link_state
= LPFC_HBA_ERROR
;
4115 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4116 lpfc_sli_brdrestart(phba
);
4118 /* Read the HBA Host Status Register */
4119 if (lpfc_readl(phba
->HSregaddr
, &status
))
4123 /* Check to see if any errors occurred during init */
4124 if (status
& HS_FFERM
) {
4125 /* ERROR: During chipset initialization */
4126 /* Adapter failed to init, chipset, status reg <status> */
4127 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4128 "0438 Adapter failed to init, chipset, "
4130 "FW Data: A8 x%x AC x%x\n", status
,
4131 readl(phba
->MBslimaddr
+ 0xa8),
4132 readl(phba
->MBslimaddr
+ 0xac));
4133 phba
->link_state
= LPFC_HBA_ERROR
;
4137 /* Clear all interrupt enable conditions */
4138 writel(0, phba
->HCregaddr
);
4139 readl(phba
->HCregaddr
); /* flush */
4141 /* setup host attn register */
4142 writel(0xffffffff, phba
->HAregaddr
);
4143 readl(phba
->HAregaddr
); /* flush */
4148 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4150 * This function calculates and returns the number of HBQs required to be
4154 lpfc_sli_hbq_count(void)
4156 return ARRAY_SIZE(lpfc_hbq_defs
);
4160 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4162 * This function adds the number of hbq entries in every HBQ to get
4163 * the total number of hbq entries required for the HBA and returns
4167 lpfc_sli_hbq_entry_count(void)
4169 int hbq_count
= lpfc_sli_hbq_count();
4173 for (i
= 0; i
< hbq_count
; ++i
)
4174 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4179 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4181 * This function calculates amount of memory required for all hbq entries
4182 * to be configured and returns the total memory required.
4185 lpfc_sli_hbq_size(void)
4187 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4191 * lpfc_sli_hbq_setup - configure and initialize HBQs
4192 * @phba: Pointer to HBA context object.
4194 * This function is called during the SLI initialization to configure
4195 * all the HBQs and post buffers to the HBQ. The caller is not
4196 * required to hold any locks. This function will return zero if successful
4197 * else it will return negative error code.
4200 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4202 int hbq_count
= lpfc_sli_hbq_count();
4206 uint32_t hbq_entry_index
;
4208 /* Get a Mailbox buffer to setup mailbox
4209 * commands for HBA initialization
4211 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4218 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4219 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4220 phba
->hbq_in_use
= 1;
4222 hbq_entry_index
= 0;
4223 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4224 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4225 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4226 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4227 phba
->hbqs
[hbqno
].entry_count
=
4228 lpfc_hbq_defs
[hbqno
]->entry_count
;
4229 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4230 hbq_entry_index
, pmb
);
4231 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4233 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4234 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4235 mbxStatus <status>, ring <num> */
4237 lpfc_printf_log(phba
, KERN_ERR
,
4238 LOG_SLI
| LOG_VPORT
,
4239 "1805 Adapter failed to init. "
4240 "Data: x%x x%x x%x\n",
4242 pmbox
->mbxStatus
, hbqno
);
4244 phba
->link_state
= LPFC_HBA_ERROR
;
4245 mempool_free(pmb
, phba
->mbox_mem_pool
);
4249 phba
->hbq_count
= hbq_count
;
4251 mempool_free(pmb
, phba
->mbox_mem_pool
);
4253 /* Initially populate or replenish the HBQs */
4254 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4255 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4260 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4261 * @phba: Pointer to HBA context object.
4263 * This function is called during the SLI initialization to configure
4264 * all the HBQs and post buffers to the HBQ. The caller is not
4265 * required to hold any locks. This function will return zero if successful
4266 * else it will return negative error code.
4269 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4271 phba
->hbq_in_use
= 1;
4272 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4273 phba
->hbq_count
= 1;
4274 /* Initially populate or replenish the HBQs */
4275 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4280 * lpfc_sli_config_port - Issue config port mailbox command
4281 * @phba: Pointer to HBA context object.
4282 * @sli_mode: sli mode - 2/3
4284 * This function is called by the sli intialization code path
4285 * to issue config_port mailbox command. This function restarts the
4286 * HBA firmware and issues a config_port mailbox command to configure
4287 * the SLI interface in the sli mode specified by sli_mode
4288 * variable. The caller is not required to hold any locks.
4289 * The function returns 0 if successful, else returns negative error
4293 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4296 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4298 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4300 phba
->link_state
= LPFC_HBA_ERROR
;
4304 phba
->sli_rev
= sli_mode
;
4305 while (resetcount
< 2 && !done
) {
4306 spin_lock_irq(&phba
->hbalock
);
4307 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4308 spin_unlock_irq(&phba
->hbalock
);
4309 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4310 lpfc_sli_brdrestart(phba
);
4311 rc
= lpfc_sli_chipset_init(phba
);
4315 spin_lock_irq(&phba
->hbalock
);
4316 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4317 spin_unlock_irq(&phba
->hbalock
);
4320 /* Call pre CONFIG_PORT mailbox command initialization. A
4321 * value of 0 means the call was successful. Any other
4322 * nonzero value is a failure, but if ERESTART is returned,
4323 * the driver may reset the HBA and try again.
4325 rc
= lpfc_config_port_prep(phba
);
4326 if (rc
== -ERESTART
) {
4327 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4332 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4333 lpfc_config_port(phba
, pmb
);
4334 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4335 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4336 LPFC_SLI3_HBQ_ENABLED
|
4337 LPFC_SLI3_CRP_ENABLED
|
4338 LPFC_SLI3_BG_ENABLED
|
4339 LPFC_SLI3_DSS_ENABLED
);
4340 if (rc
!= MBX_SUCCESS
) {
4341 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4342 "0442 Adapter failed to init, mbxCmd x%x "
4343 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4344 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4345 spin_lock_irq(&phba
->hbalock
);
4346 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4347 spin_unlock_irq(&phba
->hbalock
);
4350 /* Allow asynchronous mailbox command to go through */
4351 spin_lock_irq(&phba
->hbalock
);
4352 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4353 spin_unlock_irq(&phba
->hbalock
);
4356 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4357 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4358 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4359 "3110 Port did not grant ASABT\n");
4364 goto do_prep_failed
;
4366 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4367 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4369 goto do_prep_failed
;
4371 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4372 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4373 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4374 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4375 phba
->max_vpi
: phba
->max_vports
;
4379 phba
->fips_level
= 0;
4380 phba
->fips_spec_rev
= 0;
4381 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4382 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4383 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4384 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4385 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4386 "2850 Security Crypto Active. FIPS x%d "
4388 phba
->fips_level
, phba
->fips_spec_rev
);
4390 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4391 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4392 "2856 Config Port Security Crypto "
4394 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4396 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4397 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4398 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4399 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4401 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4402 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4404 if (phba
->cfg_enable_bg
) {
4405 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4406 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4408 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4409 "0443 Adapter did not grant "
4413 phba
->hbq_get
= NULL
;
4414 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4418 mempool_free(pmb
, phba
->mbox_mem_pool
);
4424 * lpfc_sli_hba_setup - SLI intialization function
4425 * @phba: Pointer to HBA context object.
4427 * This function is the main SLI intialization function. This function
4428 * is called by the HBA intialization code, HBA reset code and HBA
4429 * error attention handler code. Caller is not required to hold any
4430 * locks. This function issues config_port mailbox command to configure
4431 * the SLI, setup iocb rings and HBQ rings. In the end the function
4432 * calls the config_port_post function to issue init_link mailbox
4433 * command and to start the discovery. The function will return zero
4434 * if successful, else it will return negative error code.
4437 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4443 switch (lpfc_sli_mode
) {
4445 if (phba
->cfg_enable_npiv
) {
4446 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4447 "1824 NPIV enabled: Override lpfc_sli_mode "
4448 "parameter (%d) to auto (0).\n",
4458 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4459 "1819 Unrecognized lpfc_sli_mode "
4460 "parameter: %d.\n", lpfc_sli_mode
);
4465 rc
= lpfc_sli_config_port(phba
, mode
);
4467 if (rc
&& lpfc_sli_mode
== 3)
4468 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4469 "1820 Unable to select SLI-3. "
4470 "Not supported by adapter.\n");
4471 if (rc
&& mode
!= 2)
4472 rc
= lpfc_sli_config_port(phba
, 2);
4474 goto lpfc_sli_hba_setup_error
;
4476 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4477 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4478 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4480 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4481 "2709 This device supports "
4482 "Advanced Error Reporting (AER)\n");
4483 spin_lock_irq(&phba
->hbalock
);
4484 phba
->hba_flag
|= HBA_AER_ENABLED
;
4485 spin_unlock_irq(&phba
->hbalock
);
4487 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4488 "2708 This device does not support "
4489 "Advanced Error Reporting (AER)\n");
4490 phba
->cfg_aer_support
= 0;
4494 if (phba
->sli_rev
== 3) {
4495 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4496 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4498 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4499 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4500 phba
->sli3_options
= 0;
4503 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4504 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4505 phba
->sli_rev
, phba
->max_vpi
);
4506 rc
= lpfc_sli_ring_map(phba
);
4509 goto lpfc_sli_hba_setup_error
;
4511 /* Initialize VPIs. */
4512 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4514 * The VPI bitmask and physical ID array are allocated
4515 * and initialized once only - at driver load. A port
4516 * reset doesn't need to reinitialize this memory.
4518 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4519 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4520 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4522 if (!phba
->vpi_bmask
) {
4524 goto lpfc_sli_hba_setup_error
;
4527 phba
->vpi_ids
= kzalloc(
4528 (phba
->max_vpi
+1) * sizeof(uint16_t),
4530 if (!phba
->vpi_ids
) {
4531 kfree(phba
->vpi_bmask
);
4533 goto lpfc_sli_hba_setup_error
;
4535 for (i
= 0; i
< phba
->max_vpi
; i
++)
4536 phba
->vpi_ids
[i
] = i
;
4541 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4542 rc
= lpfc_sli_hbq_setup(phba
);
4544 goto lpfc_sli_hba_setup_error
;
4546 spin_lock_irq(&phba
->hbalock
);
4547 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4548 spin_unlock_irq(&phba
->hbalock
);
4550 rc
= lpfc_config_port_post(phba
);
4552 goto lpfc_sli_hba_setup_error
;
4556 lpfc_sli_hba_setup_error
:
4557 phba
->link_state
= LPFC_HBA_ERROR
;
4558 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4559 "0445 Firmware initialization failed\n");
4564 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4565 * @phba: Pointer to HBA context object.
4566 * @mboxq: mailbox pointer.
4567 * This function issue a dump mailbox command to read config region
4568 * 23 and parse the records in the region and populate driver
4572 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4574 LPFC_MBOXQ_t
*mboxq
;
4575 struct lpfc_dmabuf
*mp
;
4576 struct lpfc_mqe
*mqe
;
4577 uint32_t data_length
;
4580 /* Program the default value of vlan_id and fc_map */
4581 phba
->valid_vlan
= 0;
4582 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4583 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4584 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4586 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4590 mqe
= &mboxq
->u
.mqe
;
4591 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4593 goto out_free_mboxq
;
4596 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4597 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4599 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4600 "(%d):2571 Mailbox cmd x%x Status x%x "
4601 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4602 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4603 "CQ: x%x x%x x%x x%x\n",
4604 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4605 bf_get(lpfc_mqe_command
, mqe
),
4606 bf_get(lpfc_mqe_status
, mqe
),
4607 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4608 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4609 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4610 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4611 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4612 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4613 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4614 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4615 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4617 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4618 mboxq
->mcqe
.trailer
);
4621 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4624 goto out_free_mboxq
;
4626 data_length
= mqe
->un
.mb_words
[5];
4627 if (data_length
> DMP_RGN23_SIZE
) {
4628 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4631 goto out_free_mboxq
;
4634 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4635 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4640 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4645 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4646 * @phba: pointer to lpfc hba data structure.
4647 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4648 * @vpd: pointer to the memory to hold resulting port vpd data.
4649 * @vpd_size: On input, the number of bytes allocated to @vpd.
4650 * On output, the number of data bytes in @vpd.
4652 * This routine executes a READ_REV SLI4 mailbox command. In
4653 * addition, this routine gets the port vpd data.
4657 * -ENOMEM - could not allocated memory.
4660 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4661 uint8_t *vpd
, uint32_t *vpd_size
)
4665 struct lpfc_dmabuf
*dmabuf
;
4666 struct lpfc_mqe
*mqe
;
4668 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4673 * Get a DMA buffer for the vpd data resulting from the READ_REV
4676 dma_size
= *vpd_size
;
4677 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4681 if (!dmabuf
->virt
) {
4685 memset(dmabuf
->virt
, 0, dma_size
);
4688 * The SLI4 implementation of READ_REV conflicts at word1,
4689 * bits 31:16 and SLI4 adds vpd functionality not present
4690 * in SLI3. This code corrects the conflicts.
4692 lpfc_read_rev(phba
, mboxq
);
4693 mqe
= &mboxq
->u
.mqe
;
4694 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4695 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4696 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4697 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4698 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4700 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4702 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4703 dmabuf
->virt
, dmabuf
->phys
);
4709 * The available vpd length cannot be bigger than the
4710 * DMA buffer passed to the port. Catch the less than
4711 * case and update the caller's size.
4713 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4714 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4716 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4718 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4719 dmabuf
->virt
, dmabuf
->phys
);
4725 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4726 * @phba: pointer to lpfc hba data structure.
4728 * This routine retrieves SLI4 device physical port name this PCI function
4733 * otherwise - failed to retrieve physical port name
4736 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4738 LPFC_MBOXQ_t
*mboxq
;
4739 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4740 struct lpfc_controller_attribute
*cntl_attr
;
4741 struct lpfc_mbx_get_port_name
*get_port_name
;
4742 void *virtaddr
= NULL
;
4743 uint32_t alloclen
, reqlen
;
4744 uint32_t shdr_status
, shdr_add_status
;
4745 union lpfc_sli4_cfg_shdr
*shdr
;
4746 char cport_name
= 0;
4749 /* We assume nothing at this point */
4750 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4751 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4753 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4756 /* obtain link type and link number via READ_CONFIG */
4757 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4758 lpfc_sli4_read_config(phba
);
4759 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4760 goto retrieve_ppname
;
4762 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4763 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4764 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4765 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4766 LPFC_SLI4_MBX_NEMBED
);
4767 if (alloclen
< reqlen
) {
4768 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4769 "3084 Allocated DMA memory size (%d) is "
4770 "less than the requested DMA memory size "
4771 "(%d)\n", alloclen
, reqlen
);
4773 goto out_free_mboxq
;
4775 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4776 virtaddr
= mboxq
->sge_array
->addr
[0];
4777 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4778 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4779 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4780 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4781 if (shdr_status
|| shdr_add_status
|| rc
) {
4782 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4783 "3085 Mailbox x%x (x%x/x%x) failed, "
4784 "rc:x%x, status:x%x, add_status:x%x\n",
4785 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4786 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4787 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4788 rc
, shdr_status
, shdr_add_status
);
4790 goto out_free_mboxq
;
4792 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4793 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4794 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4795 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4796 phba
->sli4_hba
.lnk_info
.lnk_no
=
4797 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4798 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4799 "3086 lnk_type:%d, lnk_numb:%d\n",
4800 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4801 phba
->sli4_hba
.lnk_info
.lnk_no
);
4804 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4805 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4806 sizeof(struct lpfc_mbx_get_port_name
) -
4807 sizeof(struct lpfc_sli4_cfg_mhdr
),
4808 LPFC_SLI4_MBX_EMBED
);
4809 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4810 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4811 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4812 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4813 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4814 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4815 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4816 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4817 if (shdr_status
|| shdr_add_status
|| rc
) {
4818 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4819 "3087 Mailbox x%x (x%x/x%x) failed: "
4820 "rc:x%x, status:x%x, add_status:x%x\n",
4821 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4822 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4823 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4824 rc
, shdr_status
, shdr_add_status
);
4826 goto out_free_mboxq
;
4828 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4829 case LPFC_LINK_NUMBER_0
:
4830 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4831 &get_port_name
->u
.response
);
4832 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4834 case LPFC_LINK_NUMBER_1
:
4835 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4836 &get_port_name
->u
.response
);
4837 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4839 case LPFC_LINK_NUMBER_2
:
4840 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4841 &get_port_name
->u
.response
);
4842 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4844 case LPFC_LINK_NUMBER_3
:
4845 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4846 &get_port_name
->u
.response
);
4847 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4853 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4854 phba
->Port
[0] = cport_name
;
4855 phba
->Port
[1] = '\0';
4856 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4857 "3091 SLI get port name: %s\n", phba
->Port
);
4861 if (rc
!= MBX_TIMEOUT
) {
4862 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4863 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4865 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4871 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4872 * @phba: pointer to lpfc hba data structure.
4874 * This routine is called to explicitly arm the SLI4 device's completion and
4878 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4882 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4883 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4885 if (phba
->sli4_hba
.fcp_cq
) {
4887 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4889 while (++fcp_eqidx
< phba
->cfg_fcp_eq_count
);
4891 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4892 if (phba
->sli4_hba
.fp_eq
) {
4893 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
;
4895 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4901 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4902 * @phba: Pointer to HBA context object.
4903 * @type: The resource extent type.
4904 * @extnt_count: buffer to hold port available extent count.
4905 * @extnt_size: buffer to hold element count per extent.
4907 * This function calls the port and retrievs the number of available
4908 * extents and their size for a particular extent type.
4910 * Returns: 0 if successful. Nonzero otherwise.
4913 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
4914 uint16_t *extnt_count
, uint16_t *extnt_size
)
4919 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
4922 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4926 /* Find out how many extents are available for this resource type */
4927 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
4928 sizeof(struct lpfc_sli4_cfg_mhdr
));
4929 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4930 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
4931 length
, LPFC_SLI4_MBX_EMBED
);
4933 /* Send an extents count of 0 - the GET doesn't use it. */
4934 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
4935 LPFC_SLI4_MBX_EMBED
);
4941 if (!phba
->sli4_hba
.intr_enable
)
4942 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
4944 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
4945 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
4952 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
4953 if (bf_get(lpfc_mbox_hdr_status
,
4954 &rsrc_info
->header
.cfg_shdr
.response
)) {
4955 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4956 "2930 Failed to get resource extents "
4957 "Status 0x%x Add'l Status 0x%x\n",
4958 bf_get(lpfc_mbox_hdr_status
,
4959 &rsrc_info
->header
.cfg_shdr
.response
),
4960 bf_get(lpfc_mbox_hdr_add_status
,
4961 &rsrc_info
->header
.cfg_shdr
.response
));
4966 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
4968 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
4971 mempool_free(mbox
, phba
->mbox_mem_pool
);
4976 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
4977 * @phba: Pointer to HBA context object.
4978 * @type: The extent type to check.
4980 * This function reads the current available extents from the port and checks
4981 * if the extent count or extent size has changed since the last access.
4982 * Callers use this routine post port reset to understand if there is a
4983 * extent reprovisioning requirement.
4986 * -Error: error indicates problem.
4987 * 1: Extent count or size has changed.
4991 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
4993 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
4994 uint16_t size_diff
, rsrc_ext_size
;
4996 struct lpfc_rsrc_blks
*rsrc_entry
;
4997 struct list_head
*rsrc_blk_list
= NULL
;
5001 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5008 case LPFC_RSC_TYPE_FCOE_RPI
:
5009 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5011 case LPFC_RSC_TYPE_FCOE_VPI
:
5012 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5014 case LPFC_RSC_TYPE_FCOE_XRI
:
5015 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5017 case LPFC_RSC_TYPE_FCOE_VFI
:
5018 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5024 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5026 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5030 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5037 * lpfc_sli4_cfg_post_extnts -
5038 * @phba: Pointer to HBA context object.
5039 * @extnt_cnt - number of available extents.
5040 * @type - the extent type (rpi, xri, vfi, vpi).
5041 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5042 * @mbox - pointer to the caller's allocated mailbox structure.
5044 * This function executes the extents allocation request. It also
5045 * takes care of the amount of memory needed to allocate or get the
5046 * allocated extents. It is the caller's responsibility to evaluate
5050 * -Error: Error value describes the condition found.
5054 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t *extnt_cnt
,
5055 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5060 uint32_t alloc_len
, mbox_tmo
;
5062 /* Calculate the total requested length of the dma memory */
5063 req_len
= *extnt_cnt
* sizeof(uint16_t);
5066 * Calculate the size of an embedded mailbox. The uint32_t
5067 * accounts for extents-specific word.
5069 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5073 * Presume the allocation and response will fit into an embedded
5074 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5076 *emb
= LPFC_SLI4_MBX_EMBED
;
5077 if (req_len
> emb_len
) {
5078 req_len
= *extnt_cnt
* sizeof(uint16_t) +
5079 sizeof(union lpfc_sli4_cfg_shdr
) +
5081 *emb
= LPFC_SLI4_MBX_NEMBED
;
5084 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5085 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5087 if (alloc_len
< req_len
) {
5088 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5089 "2982 Allocated DMA memory size (x%x) is "
5090 "less than the requested DMA memory "
5091 "size (x%x)\n", alloc_len
, req_len
);
5094 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, *extnt_cnt
, type
, *emb
);
5098 if (!phba
->sli4_hba
.intr_enable
)
5099 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5101 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5102 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5111 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5112 * @phba: Pointer to HBA context object.
5113 * @type: The resource extent type to allocate.
5115 * This function allocates the number of elements for the specified
5119 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5122 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5123 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5126 unsigned long longs
;
5127 unsigned long *bmask
;
5128 struct lpfc_rsrc_blks
*rsrc_blks
;
5131 struct lpfc_id_range
*id_array
= NULL
;
5132 void *virtaddr
= NULL
;
5133 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5134 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5135 struct list_head
*ext_blk_list
;
5137 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5143 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5144 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5145 "3009 No available Resource Extents "
5146 "for resource type 0x%x: Count: 0x%x, "
5147 "Size 0x%x\n", type
, rsrc_cnt
,
5152 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
,
5153 "2903 Available Resource Extents "
5154 "for resource type 0x%x: Count: 0x%x, "
5155 "Size 0x%x\n", type
, rsrc_cnt
,
5158 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5162 rc
= lpfc_sli4_cfg_post_extnts(phba
, &rsrc_cnt
, type
, &emb
, mbox
);
5169 * Figure out where the response is located. Then get local pointers
5170 * to the response data. The port does not guarantee to respond to
5171 * all extents counts request so update the local variable with the
5172 * allocated count from the port.
5174 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5175 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5176 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5177 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5179 virtaddr
= mbox
->sge_array
->addr
[0];
5180 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5181 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5182 id_array
= &n_rsrc
->id
;
5185 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5186 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5189 * Based on the resource size and count, correct the base and max
5192 length
= sizeof(struct lpfc_rsrc_blks
);
5194 case LPFC_RSC_TYPE_FCOE_RPI
:
5195 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5196 sizeof(unsigned long),
5198 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5202 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5205 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5206 kfree(phba
->sli4_hba
.rpi_bmask
);
5212 * The next_rpi was initialized with the maximum available
5213 * count but the port may allocate a smaller number. Catch
5214 * that case and update the next_rpi.
5216 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5218 /* Initialize local ptrs for common extent processing later. */
5219 bmask
= phba
->sli4_hba
.rpi_bmask
;
5220 ids
= phba
->sli4_hba
.rpi_ids
;
5221 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5223 case LPFC_RSC_TYPE_FCOE_VPI
:
5224 phba
->vpi_bmask
= kzalloc(longs
*
5225 sizeof(unsigned long),
5227 if (unlikely(!phba
->vpi_bmask
)) {
5231 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5234 if (unlikely(!phba
->vpi_ids
)) {
5235 kfree(phba
->vpi_bmask
);
5240 /* Initialize local ptrs for common extent processing later. */
5241 bmask
= phba
->vpi_bmask
;
5242 ids
= phba
->vpi_ids
;
5243 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5245 case LPFC_RSC_TYPE_FCOE_XRI
:
5246 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5247 sizeof(unsigned long),
5249 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5253 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5256 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5257 kfree(phba
->sli4_hba
.xri_bmask
);
5262 /* Initialize local ptrs for common extent processing later. */
5263 bmask
= phba
->sli4_hba
.xri_bmask
;
5264 ids
= phba
->sli4_hba
.xri_ids
;
5265 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5267 case LPFC_RSC_TYPE_FCOE_VFI
:
5268 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5269 sizeof(unsigned long),
5271 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5275 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5278 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5279 kfree(phba
->sli4_hba
.vfi_bmask
);
5284 /* Initialize local ptrs for common extent processing later. */
5285 bmask
= phba
->sli4_hba
.vfi_bmask
;
5286 ids
= phba
->sli4_hba
.vfi_ids
;
5287 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5290 /* Unsupported Opcode. Fail call. */
5294 ext_blk_list
= NULL
;
5299 * Complete initializing the extent configuration with the
5300 * allocated ids assigned to this function. The bitmask serves
5301 * as an index into the array and manages the available ids. The
5302 * array just stores the ids communicated to the port via the wqes.
5304 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5306 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5309 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5312 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5313 if (unlikely(!rsrc_blks
)) {
5319 rsrc_blks
->rsrc_start
= rsrc_id
;
5320 rsrc_blks
->rsrc_size
= rsrc_size
;
5321 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5322 rsrc_start
= rsrc_id
;
5323 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5324 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5325 lpfc_sli4_get_els_iocb_cnt(phba
);
5327 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5332 /* Entire word processed. Get next word.*/
5337 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5342 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5343 * @phba: Pointer to HBA context object.
5344 * @type: the extent's type.
5346 * This function deallocates all extents of a particular resource type.
5347 * SLI4 does not allow for deallocating a particular extent range. It
5348 * is the caller's responsibility to release all kernel memory resources.
5351 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5354 uint32_t length
, mbox_tmo
= 0;
5356 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5357 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5359 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5364 * This function sends an embedded mailbox because it only sends the
5365 * the resource type. All extents of this type are released by the
5368 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5369 sizeof(struct lpfc_sli4_cfg_mhdr
));
5370 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5371 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5372 length
, LPFC_SLI4_MBX_EMBED
);
5374 /* Send an extents count of 0 - the dealloc doesn't use it. */
5375 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5376 LPFC_SLI4_MBX_EMBED
);
5381 if (!phba
->sli4_hba
.intr_enable
)
5382 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5384 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5385 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5392 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5393 if (bf_get(lpfc_mbox_hdr_status
,
5394 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5395 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5396 "2919 Failed to release resource extents "
5397 "for type %d - Status 0x%x Add'l Status 0x%x. "
5398 "Resource memory not released.\n",
5400 bf_get(lpfc_mbox_hdr_status
,
5401 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5402 bf_get(lpfc_mbox_hdr_add_status
,
5403 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5408 /* Release kernel memory resources for the specific type. */
5410 case LPFC_RSC_TYPE_FCOE_VPI
:
5411 kfree(phba
->vpi_bmask
);
5412 kfree(phba
->vpi_ids
);
5413 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5414 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5415 &phba
->lpfc_vpi_blk_list
, list
) {
5416 list_del_init(&rsrc_blk
->list
);
5420 case LPFC_RSC_TYPE_FCOE_XRI
:
5421 kfree(phba
->sli4_hba
.xri_bmask
);
5422 kfree(phba
->sli4_hba
.xri_ids
);
5423 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5424 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5425 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5426 list_del_init(&rsrc_blk
->list
);
5430 case LPFC_RSC_TYPE_FCOE_VFI
:
5431 kfree(phba
->sli4_hba
.vfi_bmask
);
5432 kfree(phba
->sli4_hba
.vfi_ids
);
5433 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5434 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5435 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5436 list_del_init(&rsrc_blk
->list
);
5440 case LPFC_RSC_TYPE_FCOE_RPI
:
5441 /* RPI bitmask and physical id array are cleaned up earlier. */
5442 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5443 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5444 list_del_init(&rsrc_blk
->list
);
5452 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5455 mempool_free(mbox
, phba
->mbox_mem_pool
);
5460 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5461 * @phba: Pointer to HBA context object.
5463 * This function allocates all SLI4 resource identifiers.
5466 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5468 int i
, rc
, error
= 0;
5469 uint16_t count
, base
;
5470 unsigned long longs
;
5472 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5473 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5474 if (phba
->sli4_hba
.extents_in_use
) {
5476 * The port supports resource extents. The XRI, VPI, VFI, RPI
5477 * resource extent count must be read and allocated before
5478 * provisioning the resource id arrays.
5480 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5481 LPFC_IDX_RSRC_RDY
) {
5483 * Extent-based resources are set - the driver could
5484 * be in a port reset. Figure out if any corrective
5485 * actions need to be taken.
5487 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5488 LPFC_RSC_TYPE_FCOE_VFI
);
5491 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5492 LPFC_RSC_TYPE_FCOE_VPI
);
5495 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5496 LPFC_RSC_TYPE_FCOE_XRI
);
5499 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5500 LPFC_RSC_TYPE_FCOE_RPI
);
5505 * It's possible that the number of resources
5506 * provided to this port instance changed between
5507 * resets. Detect this condition and reallocate
5508 * resources. Otherwise, there is no action.
5511 lpfc_printf_log(phba
, KERN_INFO
,
5512 LOG_MBOX
| LOG_INIT
,
5513 "2931 Detected extent resource "
5514 "change. Reallocating all "
5516 rc
= lpfc_sli4_dealloc_extent(phba
,
5517 LPFC_RSC_TYPE_FCOE_VFI
);
5518 rc
= lpfc_sli4_dealloc_extent(phba
,
5519 LPFC_RSC_TYPE_FCOE_VPI
);
5520 rc
= lpfc_sli4_dealloc_extent(phba
,
5521 LPFC_RSC_TYPE_FCOE_XRI
);
5522 rc
= lpfc_sli4_dealloc_extent(phba
,
5523 LPFC_RSC_TYPE_FCOE_RPI
);
5528 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5532 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5536 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5540 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5543 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5548 * The port does not support resource extents. The XRI, VPI,
5549 * VFI, RPI resource ids were determined from READ_CONFIG.
5550 * Just allocate the bitmasks and provision the resource id
5551 * arrays. If a port reset is active, the resources don't
5552 * need any action - just exit.
5554 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5555 LPFC_IDX_RSRC_RDY
) {
5556 lpfc_sli4_dealloc_resource_identifiers(phba
);
5557 lpfc_sli4_remove_rpis(phba
);
5560 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5561 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5562 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5563 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5564 sizeof(unsigned long),
5566 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5570 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5573 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5575 goto free_rpi_bmask
;
5578 for (i
= 0; i
< count
; i
++)
5579 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5582 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5583 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5584 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5585 phba
->vpi_bmask
= kzalloc(longs
*
5586 sizeof(unsigned long),
5588 if (unlikely(!phba
->vpi_bmask
)) {
5592 phba
->vpi_ids
= kzalloc(count
*
5595 if (unlikely(!phba
->vpi_ids
)) {
5597 goto free_vpi_bmask
;
5600 for (i
= 0; i
< count
; i
++)
5601 phba
->vpi_ids
[i
] = base
+ i
;
5604 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5605 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5606 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5607 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5608 sizeof(unsigned long),
5610 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5614 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5615 phba
->sli4_hba
.xri_count
= 0;
5616 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5619 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5621 goto free_xri_bmask
;
5624 for (i
= 0; i
< count
; i
++)
5625 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5628 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5629 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5630 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5631 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5632 sizeof(unsigned long),
5634 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5638 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5641 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5643 goto free_vfi_bmask
;
5646 for (i
= 0; i
< count
; i
++)
5647 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5650 * Mark all resources ready. An HBA reset doesn't need
5651 * to reset the initialization.
5653 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5659 kfree(phba
->sli4_hba
.vfi_bmask
);
5661 kfree(phba
->sli4_hba
.xri_ids
);
5663 kfree(phba
->sli4_hba
.xri_bmask
);
5665 kfree(phba
->vpi_ids
);
5667 kfree(phba
->vpi_bmask
);
5669 kfree(phba
->sli4_hba
.rpi_ids
);
5671 kfree(phba
->sli4_hba
.rpi_bmask
);
5677 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5678 * @phba: Pointer to HBA context object.
5680 * This function allocates the number of elements for the specified
5684 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5686 if (phba
->sli4_hba
.extents_in_use
) {
5687 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5688 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5689 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5690 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5692 kfree(phba
->vpi_bmask
);
5693 kfree(phba
->vpi_ids
);
5694 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5695 kfree(phba
->sli4_hba
.xri_bmask
);
5696 kfree(phba
->sli4_hba
.xri_ids
);
5697 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5698 kfree(phba
->sli4_hba
.vfi_bmask
);
5699 kfree(phba
->sli4_hba
.vfi_ids
);
5700 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5701 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5708 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5709 * @phba: Pointer to HBA context object.
5710 * @type: The resource extent type.
5711 * @extnt_count: buffer to hold port extent count response
5712 * @extnt_size: buffer to hold port extent size response.
5714 * This function calls the port to read the host allocated extents
5715 * for a particular type.
5718 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5719 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5723 uint16_t curr_blks
= 0;
5724 uint32_t req_len
, emb_len
;
5725 uint32_t alloc_len
, mbox_tmo
;
5726 struct list_head
*blk_list_head
;
5727 struct lpfc_rsrc_blks
*rsrc_blk
;
5729 void *virtaddr
= NULL
;
5730 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5731 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5732 union lpfc_sli4_cfg_shdr
*shdr
;
5735 case LPFC_RSC_TYPE_FCOE_VPI
:
5736 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5738 case LPFC_RSC_TYPE_FCOE_XRI
:
5739 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5741 case LPFC_RSC_TYPE_FCOE_VFI
:
5742 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5744 case LPFC_RSC_TYPE_FCOE_RPI
:
5745 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5751 /* Count the number of extents currently allocatd for this type. */
5752 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5753 if (curr_blks
== 0) {
5755 * The GET_ALLOCATED mailbox does not return the size,
5756 * just the count. The size should be just the size
5757 * stored in the current allocated block and all sizes
5758 * for an extent type are the same so set the return
5761 *extnt_size
= rsrc_blk
->rsrc_size
;
5766 /* Calculate the total requested length of the dma memory. */
5767 req_len
= curr_blks
* sizeof(uint16_t);
5770 * Calculate the size of an embedded mailbox. The uint32_t
5771 * accounts for extents-specific word.
5773 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5777 * Presume the allocation and response will fit into an embedded
5778 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5780 emb
= LPFC_SLI4_MBX_EMBED
;
5782 if (req_len
> emb_len
) {
5783 req_len
= curr_blks
* sizeof(uint16_t) +
5784 sizeof(union lpfc_sli4_cfg_shdr
) +
5786 emb
= LPFC_SLI4_MBX_NEMBED
;
5789 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5792 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5794 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5795 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5797 if (alloc_len
< req_len
) {
5798 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5799 "2983 Allocated DMA memory size (x%x) is "
5800 "less than the requested DMA memory "
5801 "size (x%x)\n", alloc_len
, req_len
);
5805 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5811 if (!phba
->sli4_hba
.intr_enable
)
5812 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5814 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5815 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5824 * Figure out where the response is located. Then get local pointers
5825 * to the response data. The port does not guarantee to respond to
5826 * all extents counts request so update the local variable with the
5827 * allocated count from the port.
5829 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5830 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5831 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5832 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5834 virtaddr
= mbox
->sge_array
->addr
[0];
5835 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5836 shdr
= &n_rsrc
->cfg_shdr
;
5837 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5840 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5841 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5842 "2984 Failed to read allocated resources "
5843 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5845 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5846 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5851 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5856 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
5857 * @phba: Pointer to HBA context object.
5859 * This function is the main SLI4 device intialization PCI function. This
5860 * function is called by the HBA intialization code, HBA reset code and
5861 * HBA error attention handler code. Caller is not required to hold any
5865 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
5868 LPFC_MBOXQ_t
*mboxq
;
5869 struct lpfc_mqe
*mqe
;
5872 uint32_t ftr_rsp
= 0;
5873 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
5874 struct lpfc_vport
*vport
= phba
->pport
;
5875 struct lpfc_dmabuf
*mp
;
5877 /* Perform a PCI function reset to start from clean */
5878 rc
= lpfc_pci_function_reset(phba
);
5882 /* Check the HBA Host Status Register for readyness */
5883 rc
= lpfc_sli4_post_status_check(phba
);
5887 spin_lock_irq(&phba
->hbalock
);
5888 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
5889 spin_unlock_irq(&phba
->hbalock
);
5893 * Allocate a single mailbox container for initializing the
5896 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5900 /* Issue READ_REV to collect vpd and FW information. */
5901 vpd_size
= SLI4_PAGE_SIZE
;
5902 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
5908 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
5913 mqe
= &mboxq
->u
.mqe
;
5914 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
5915 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
5916 phba
->hba_flag
|= HBA_FCOE_MODE
;
5918 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
5920 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
5922 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
5924 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
5926 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5927 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5928 "0376 READ_REV Error. SLI Level %d "
5929 "FCoE enabled %d\n",
5930 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
5937 * Continue initialization with default values even if driver failed
5938 * to read FCoE param config regions, only read parameters if the
5941 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
5942 lpfc_sli4_read_fcoe_params(phba
))
5943 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
5944 "2570 Failed to read FCoE parameters\n");
5947 * Retrieve sli4 device physical port name, failure of doing it
5948 * is considered as non-fatal.
5950 rc
= lpfc_sli4_retrieve_pport_name(phba
);
5952 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5953 "3080 Successful retrieving SLI4 device "
5954 "physical port name: %s.\n", phba
->Port
);
5957 * Evaluate the read rev and vpd data. Populate the driver
5958 * state with the results. If this routine fails, the failure
5959 * is not fatal as the driver will use generic values.
5961 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
5962 if (unlikely(!rc
)) {
5963 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5964 "0377 Error %d parsing vpd. "
5965 "Using defaults.\n", rc
);
5970 /* Save information as VPD data */
5971 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
5972 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
5973 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
5974 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
5976 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
5978 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
5980 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
5982 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
5983 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
5984 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
5985 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
5986 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
5987 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
5988 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5989 "(%d):0380 READ_REV Status x%x "
5990 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
5991 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5992 bf_get(lpfc_mqe_status
, mqe
),
5993 phba
->vpd
.rev
.opFwName
,
5994 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
5995 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
5998 * Discover the port's supported feature set and match it against the
6001 lpfc_request_features(phba
, mboxq
);
6002 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6009 * The port must support FCP initiator mode as this is the
6010 * only mode running in the host.
6012 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6013 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6014 "0378 No support for fcpi mode.\n");
6017 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6018 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6020 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6022 * If the port cannot support the host's requested features
6023 * then turn off the global config parameters to disable the
6024 * feature in the driver. This is not a fatal error.
6026 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6027 if (phba
->cfg_enable_bg
) {
6028 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6029 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6034 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6035 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6039 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6040 "0379 Feature Mismatch Data: x%08x %08x "
6041 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6042 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6043 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6044 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6045 phba
->cfg_enable_bg
= 0;
6046 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6047 phba
->cfg_enable_npiv
= 0;
6050 /* These SLI3 features are assumed in SLI4 */
6051 spin_lock_irq(&phba
->hbalock
);
6052 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6053 spin_unlock_irq(&phba
->hbalock
);
6056 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6057 * calls depends on these resources to complete port setup.
6059 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6061 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6062 "2920 Failed to alloc Resource IDs "
6066 /* update physical xri mappings in the scsi buffers */
6067 lpfc_scsi_buf_update(phba
);
6069 /* Read the port's service parameters. */
6070 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6072 phba
->link_state
= LPFC_HBA_ERROR
;
6077 mboxq
->vport
= vport
;
6078 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6079 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6080 if (rc
== MBX_SUCCESS
) {
6081 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6086 * This memory was allocated by the lpfc_read_sparam routine. Release
6087 * it to the mbuf pool.
6089 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6091 mboxq
->context1
= NULL
;
6093 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6094 "0382 READ_SPARAM command failed "
6095 "status %d, mbxStatus x%x\n",
6096 rc
, bf_get(lpfc_mqe_status
, mqe
));
6097 phba
->link_state
= LPFC_HBA_ERROR
;
6102 lpfc_update_vport_wwn(vport
);
6104 /* Update the fc_host data structures with new wwn. */
6105 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6106 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6108 /* Register SGL pool to the device using non-embedded mailbox command */
6109 if (!phba
->sli4_hba
.extents_in_use
) {
6110 rc
= lpfc_sli4_post_els_sgl_list(phba
);
6112 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6113 "0582 Error %d during els sgl post "
6119 rc
= lpfc_sli4_post_els_sgl_list_ext(phba
);
6121 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6122 "2560 Error %d during els sgl post "
6129 /* Register SCSI SGL pool to the device */
6130 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6132 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6133 "0383 Error %d during scsi sgl post "
6135 /* Some Scsi buffers were moved to the abort scsi list */
6136 /* A pci function reset will repost them */
6141 /* Post the rpi header region to the device. */
6142 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6144 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6145 "0393 Error %d during rpi post operation\n",
6150 lpfc_sli4_node_prep(phba
);
6152 /* Create all the SLI4 queues */
6153 rc
= lpfc_sli4_queue_create(phba
);
6155 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6156 "3089 Failed to allocate queues\n");
6158 goto out_stop_timers
;
6160 /* Set up all the queues to the device */
6161 rc
= lpfc_sli4_queue_setup(phba
);
6163 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6164 "0381 Error %d during queue setup.\n ", rc
);
6165 goto out_destroy_queue
;
6168 /* Arm the CQs and then EQs on device */
6169 lpfc_sli4_arm_cqeq_intr(phba
);
6171 /* Indicate device interrupt mode */
6172 phba
->sli4_hba
.intr_enable
= 1;
6174 /* Allow asynchronous mailbox command to go through */
6175 spin_lock_irq(&phba
->hbalock
);
6176 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6177 spin_unlock_irq(&phba
->hbalock
);
6179 /* Post receive buffers to the device */
6180 lpfc_sli4_rb_setup(phba
);
6182 /* Reset HBA FCF states after HBA reset */
6183 phba
->fcf
.fcf_flag
= 0;
6184 phba
->fcf
.current_rec
.flag
= 0;
6186 /* Start the ELS watchdog timer */
6187 mod_timer(&vport
->els_tmofunc
,
6188 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
6190 /* Start heart beat timer */
6191 mod_timer(&phba
->hb_tmofunc
,
6192 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
6193 phba
->hb_outstanding
= 0;
6194 phba
->last_completion_time
= jiffies
;
6196 /* Start error attention (ERATT) polling timer */
6197 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
6199 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6200 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6201 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6203 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6204 "2829 This device supports "
6205 "Advanced Error Reporting (AER)\n");
6206 spin_lock_irq(&phba
->hbalock
);
6207 phba
->hba_flag
|= HBA_AER_ENABLED
;
6208 spin_unlock_irq(&phba
->hbalock
);
6210 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6211 "2830 This device does not support "
6212 "Advanced Error Reporting (AER)\n");
6213 phba
->cfg_aer_support
= 0;
6218 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6220 * The FC Port needs to register FCFI (index 0)
6222 lpfc_reg_fcfi(phba
, mboxq
);
6223 mboxq
->vport
= phba
->pport
;
6224 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6225 if (rc
!= MBX_SUCCESS
)
6226 goto out_unset_queue
;
6228 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6229 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6231 /* Check if the port is configured to be disabled */
6232 lpfc_sli_read_link_ste(phba
);
6236 * The port is ready, set the host's link state to LINK_DOWN
6237 * in preparation for link interrupts.
6239 spin_lock_irq(&phba
->hbalock
);
6240 phba
->link_state
= LPFC_LINK_DOWN
;
6241 spin_unlock_irq(&phba
->hbalock
);
6242 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6243 (phba
->hba_flag
& LINK_DISABLED
)) {
6244 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6245 "3103 Adapter Link is disabled.\n");
6246 lpfc_down_link(phba
, mboxq
);
6247 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6248 if (rc
!= MBX_SUCCESS
) {
6249 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6250 "3104 Adapter failed to issue "
6251 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6252 goto out_unset_queue
;
6254 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6255 /* don't perform init_link on SLI4 FC port loopback test */
6256 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6257 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6259 goto out_unset_queue
;
6262 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6265 /* Unset all the queues set up in this routine when error out */
6266 lpfc_sli4_queue_unset(phba
);
6268 lpfc_sli4_queue_destroy(phba
);
6270 lpfc_stop_hba_timers(phba
);
6272 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6277 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6278 * @ptr: context object - pointer to hba structure.
6280 * This is the callback function for mailbox timer. The mailbox
6281 * timer is armed when a new mailbox command is issued and the timer
6282 * is deleted when the mailbox complete. The function is called by
6283 * the kernel timer code when a mailbox does not complete within
6284 * expected time. This function wakes up the worker thread to
6285 * process the mailbox timeout and returns. All the processing is
6286 * done by the worker thread function lpfc_mbox_timeout_handler.
6289 lpfc_mbox_timeout(unsigned long ptr
)
6291 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6292 unsigned long iflag
;
6293 uint32_t tmo_posted
;
6295 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6296 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6298 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6299 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6302 lpfc_worker_wake_up(phba
);
6308 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6309 * @phba: Pointer to HBA context object.
6311 * This function is called from worker thread when a mailbox command times out.
6312 * The caller is not required to hold any locks. This function will reset the
6313 * HBA and recover all the pending commands.
6316 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6318 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6319 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6320 struct lpfc_sli
*psli
= &phba
->sli
;
6321 struct lpfc_sli_ring
*pring
;
6323 /* Check the pmbox pointer first. There is a race condition
6324 * between the mbox timeout handler getting executed in the
6325 * worklist and the mailbox actually completing. When this
6326 * race condition occurs, the mbox_active will be NULL.
6328 spin_lock_irq(&phba
->hbalock
);
6329 if (pmbox
== NULL
) {
6330 lpfc_printf_log(phba
, KERN_WARNING
,
6332 "0353 Active Mailbox cleared - mailbox timeout "
6334 spin_unlock_irq(&phba
->hbalock
);
6338 /* Mbox cmd <mbxCommand> timeout */
6339 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6340 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6342 phba
->pport
->port_state
,
6344 phba
->sli
.mbox_active
);
6345 spin_unlock_irq(&phba
->hbalock
);
6347 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6348 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6349 * it to fail all outstanding SCSI IO.
6351 spin_lock_irq(&phba
->pport
->work_port_lock
);
6352 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6353 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6354 spin_lock_irq(&phba
->hbalock
);
6355 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6356 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6357 spin_unlock_irq(&phba
->hbalock
);
6359 pring
= &psli
->ring
[psli
->fcp_ring
];
6360 lpfc_sli_abort_iocb_ring(phba
, pring
);
6362 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6363 "0345 Resetting board due to mailbox timeout\n");
6365 /* Reset the HBA device */
6366 lpfc_reset_hba(phba
);
6370 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6371 * @phba: Pointer to HBA context object.
6372 * @pmbox: Pointer to mailbox object.
6373 * @flag: Flag indicating how the mailbox need to be processed.
6375 * This function is called by discovery code and HBA management code
6376 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6377 * function gets the hbalock to protect the data structures.
6378 * The mailbox command can be submitted in polling mode, in which case
6379 * this function will wait in a polling loop for the completion of the
6381 * If the mailbox is submitted in no_wait mode (not polling) the
6382 * function will submit the command and returns immediately without waiting
6383 * for the mailbox completion. The no_wait is supported only when HBA
6384 * is in SLI2/SLI3 mode - interrupts are enabled.
6385 * The SLI interface allows only one mailbox pending at a time. If the
6386 * mailbox is issued in polling mode and there is already a mailbox
6387 * pending, then the function will return an error. If the mailbox is issued
6388 * in NO_WAIT mode and there is a mailbox pending already, the function
6389 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6390 * The sli layer owns the mailbox object until the completion of mailbox
6391 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6392 * return codes the caller owns the mailbox command after the return of
6396 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6400 struct lpfc_sli
*psli
= &phba
->sli
;
6401 uint32_t status
, evtctr
;
6402 uint32_t ha_copy
, hc_copy
;
6404 unsigned long timeout
;
6405 unsigned long drvr_flag
= 0;
6406 uint32_t word0
, ldata
;
6407 void __iomem
*to_slim
;
6408 int processing_queue
= 0;
6410 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6412 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6413 /* processing mbox queue from intr_handler */
6414 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6415 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6418 processing_queue
= 1;
6419 pmbox
= lpfc_mbox_get(phba
);
6421 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6426 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6427 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6429 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6430 lpfc_printf_log(phba
, KERN_ERR
,
6431 LOG_MBOX
| LOG_VPORT
,
6432 "1806 Mbox x%x failed. No vport\n",
6433 pmbox
->u
.mb
.mbxCommand
);
6435 goto out_not_finished
;
6439 /* If the PCI channel is in offline state, do not post mbox. */
6440 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6441 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6442 goto out_not_finished
;
6445 /* If HBA has a deferred error attention, fail the iocb. */
6446 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6447 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6448 goto out_not_finished
;
6454 status
= MBX_SUCCESS
;
6456 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6457 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6459 /* Mbox command <mbxCommand> cannot issue */
6460 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6461 "(%d):0311 Mailbox command x%x cannot "
6462 "issue Data: x%x x%x\n",
6463 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6464 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6465 goto out_not_finished
;
6468 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6469 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6470 !(hc_copy
& HC_MBINT_ENA
)) {
6471 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6472 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6473 "(%d):2528 Mailbox command x%x cannot "
6474 "issue Data: x%x x%x\n",
6475 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6476 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6477 goto out_not_finished
;
6481 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6482 /* Polling for a mbox command when another one is already active
6483 * is not allowed in SLI. Also, the driver must have established
6484 * SLI2 mode to queue and process multiple mbox commands.
6487 if (flag
& MBX_POLL
) {
6488 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6490 /* Mbox command <mbxCommand> cannot issue */
6491 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6492 "(%d):2529 Mailbox command x%x "
6493 "cannot issue Data: x%x x%x\n",
6494 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6495 pmbox
->u
.mb
.mbxCommand
,
6496 psli
->sli_flag
, flag
);
6497 goto out_not_finished
;
6500 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6501 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6502 /* Mbox command <mbxCommand> cannot issue */
6503 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6504 "(%d):2530 Mailbox command x%x "
6505 "cannot issue Data: x%x x%x\n",
6506 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6507 pmbox
->u
.mb
.mbxCommand
,
6508 psli
->sli_flag
, flag
);
6509 goto out_not_finished
;
6512 /* Another mailbox command is still being processed, queue this
6513 * command to be processed later.
6515 lpfc_mbox_put(phba
, pmbox
);
6517 /* Mbox cmd issue - BUSY */
6518 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6519 "(%d):0308 Mbox cmd issue - BUSY Data: "
6520 "x%x x%x x%x x%x\n",
6521 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6522 mb
->mbxCommand
, phba
->pport
->port_state
,
6523 psli
->sli_flag
, flag
);
6525 psli
->slistat
.mbox_busy
++;
6526 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6529 lpfc_debugfs_disc_trc(pmbox
->vport
,
6530 LPFC_DISC_TRC_MBOX_VPORT
,
6531 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6532 (uint32_t)mb
->mbxCommand
,
6533 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6536 lpfc_debugfs_disc_trc(phba
->pport
,
6538 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6539 (uint32_t)mb
->mbxCommand
,
6540 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6546 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6548 /* If we are not polling, we MUST be in SLI2 mode */
6549 if (flag
!= MBX_POLL
) {
6550 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6551 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
6552 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6553 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6554 /* Mbox command <mbxCommand> cannot issue */
6555 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6556 "(%d):2531 Mailbox command x%x "
6557 "cannot issue Data: x%x x%x\n",
6558 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6559 pmbox
->u
.mb
.mbxCommand
,
6560 psli
->sli_flag
, flag
);
6561 goto out_not_finished
;
6563 /* timeout active mbox command */
6564 mod_timer(&psli
->mbox_tmo
, (jiffies
+
6565 (HZ
* lpfc_mbox_tmo_val(phba
, pmbox
))));
6568 /* Mailbox cmd <cmd> issue */
6569 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6570 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6572 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6573 mb
->mbxCommand
, phba
->pport
->port_state
,
6574 psli
->sli_flag
, flag
);
6576 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
6578 lpfc_debugfs_disc_trc(pmbox
->vport
,
6579 LPFC_DISC_TRC_MBOX_VPORT
,
6580 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6581 (uint32_t)mb
->mbxCommand
,
6582 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6585 lpfc_debugfs_disc_trc(phba
->pport
,
6587 "MBOX Send: cmd:x%x mb:x%x x%x",
6588 (uint32_t)mb
->mbxCommand
,
6589 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6593 psli
->slistat
.mbox_cmd
++;
6594 evtctr
= psli
->slistat
.mbox_event
;
6596 /* next set own bit for the adapter and copy over command word */
6597 mb
->mbxOwner
= OWN_CHIP
;
6599 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6600 /* Populate mbox extension offset word. */
6601 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6602 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6603 = (uint8_t *)phba
->mbox_ext
6604 - (uint8_t *)phba
->mbox
;
6607 /* Copy the mailbox extension data */
6608 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6609 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6610 (uint8_t *)phba
->mbox_ext
,
6611 pmbox
->in_ext_byte_len
);
6613 /* Copy command data to host SLIM area */
6614 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6616 /* Populate mbox extension offset word. */
6617 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6618 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6619 = MAILBOX_HBA_EXT_OFFSET
;
6621 /* Copy the mailbox extension data */
6622 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6623 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
6624 MAILBOX_HBA_EXT_OFFSET
,
6625 pmbox
->context2
, pmbox
->in_ext_byte_len
);
6628 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6629 /* copy command data into host mbox for cmpl */
6630 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6633 /* First copy mbox command data to HBA SLIM, skip past first
6635 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
6636 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
6637 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
6639 /* Next copy over first word, with mbxOwner set */
6640 ldata
= *((uint32_t *)mb
);
6641 to_slim
= phba
->MBslimaddr
;
6642 writel(ldata
, to_slim
);
6643 readl(to_slim
); /* flush */
6645 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6646 /* switch over to host mailbox */
6647 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
6655 /* Set up reference to mailbox command */
6656 psli
->mbox_active
= pmbox
;
6657 /* Interrupt board to do it */
6658 writel(CA_MBATT
, phba
->CAregaddr
);
6659 readl(phba
->CAregaddr
); /* flush */
6660 /* Don't wait for it to finish, just return */
6664 /* Set up null reference to mailbox command */
6665 psli
->mbox_active
= NULL
;
6666 /* Interrupt board to do it */
6667 writel(CA_MBATT
, phba
->CAregaddr
);
6668 readl(phba
->CAregaddr
); /* flush */
6670 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6671 /* First read mbox status word */
6672 word0
= *((uint32_t *)phba
->mbox
);
6673 word0
= le32_to_cpu(word0
);
6675 /* First read mbox status word */
6676 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
6677 spin_unlock_irqrestore(&phba
->hbalock
,
6679 goto out_not_finished
;
6683 /* Read the HBA Host Attention Register */
6684 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6685 spin_unlock_irqrestore(&phba
->hbalock
,
6687 goto out_not_finished
;
6689 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6692 /* Wait for command to complete */
6693 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
6694 (!(ha_copy
& HA_MBATT
) &&
6695 (phba
->link_state
> LPFC_WARM_START
))) {
6696 if (time_after(jiffies
, timeout
)) {
6697 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6698 spin_unlock_irqrestore(&phba
->hbalock
,
6700 goto out_not_finished
;
6703 /* Check if we took a mbox interrupt while we were
6705 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
6706 && (evtctr
!= psli
->slistat
.mbox_event
))
6710 spin_unlock_irqrestore(&phba
->hbalock
,
6713 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6716 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6717 /* First copy command data */
6718 word0
= *((uint32_t *)phba
->mbox
);
6719 word0
= le32_to_cpu(word0
);
6720 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6723 /* Check real SLIM for any errors */
6724 slimword0
= readl(phba
->MBslimaddr
);
6725 slimmb
= (MAILBOX_t
*) & slimword0
;
6726 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
6727 && slimmb
->mbxStatus
) {
6734 /* First copy command data */
6735 word0
= readl(phba
->MBslimaddr
);
6737 /* Read the HBA Host Attention Register */
6738 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6739 spin_unlock_irqrestore(&phba
->hbalock
,
6741 goto out_not_finished
;
6745 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6746 /* copy results back to user */
6747 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
6748 /* Copy the mailbox extension data */
6749 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6750 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
6752 pmbox
->out_ext_byte_len
);
6755 /* First copy command data */
6756 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
6758 /* Copy the mailbox extension data */
6759 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6760 lpfc_memcpy_from_slim(pmbox
->context2
,
6762 MAILBOX_HBA_EXT_OFFSET
,
6763 pmbox
->out_ext_byte_len
);
6767 writel(HA_MBATT
, phba
->HAregaddr
);
6768 readl(phba
->HAregaddr
); /* flush */
6770 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6771 status
= mb
->mbxStatus
;
6774 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6778 if (processing_queue
) {
6779 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6780 lpfc_mbox_cmpl_put(phba
, pmbox
);
6782 return MBX_NOT_FINISHED
;
6786 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6787 * @phba: Pointer to HBA context object.
6789 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6790 * the driver internal pending mailbox queue. It will then try to wait out the
6791 * possible outstanding mailbox command before return.
6794 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6795 * the outstanding mailbox command timed out.
6798 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
6800 struct lpfc_sli
*psli
= &phba
->sli
;
6802 unsigned long timeout
= 0;
6804 /* Mark the asynchronous mailbox command posting as blocked */
6805 spin_lock_irq(&phba
->hbalock
);
6806 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
6807 /* Determine how long we might wait for the active mailbox
6808 * command to be gracefully completed by firmware.
6810 if (phba
->sli
.mbox_active
)
6811 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
6812 phba
->sli
.mbox_active
) *
6814 spin_unlock_irq(&phba
->hbalock
);
6816 /* Wait for the outstnading mailbox command to complete */
6817 while (phba
->sli
.mbox_active
) {
6818 /* Check active mailbox complete status every 2ms */
6820 if (time_after(jiffies
, timeout
)) {
6821 /* Timeout, marked the outstanding cmd not complete */
6827 /* Can not cleanly block async mailbox command, fails it */
6829 spin_lock_irq(&phba
->hbalock
);
6830 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6831 spin_unlock_irq(&phba
->hbalock
);
6837 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
6838 * @phba: Pointer to HBA context object.
6840 * The function unblocks and resume posting of SLI4 asynchronous mailbox
6841 * commands from the driver internal pending mailbox queue. It makes sure
6842 * that there is no outstanding mailbox command before resuming posting
6843 * asynchronous mailbox commands. If, for any reason, there is outstanding
6844 * mailbox command, it will try to wait it out before resuming asynchronous
6845 * mailbox command posting.
6848 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
6850 struct lpfc_sli
*psli
= &phba
->sli
;
6852 spin_lock_irq(&phba
->hbalock
);
6853 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6854 /* Asynchronous mailbox posting is not blocked, do nothing */
6855 spin_unlock_irq(&phba
->hbalock
);
6859 /* Outstanding synchronous mailbox command is guaranteed to be done,
6860 * successful or timeout, after timing-out the outstanding mailbox
6861 * command shall always be removed, so just unblock posting async
6862 * mailbox command and resume
6864 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6865 spin_unlock_irq(&phba
->hbalock
);
6867 /* wake up worker thread to post asynchronlous mailbox command */
6868 lpfc_worker_wake_up(phba
);
6872 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
6873 * @phba: Pointer to HBA context object.
6874 * @mboxq: Pointer to mailbox object.
6876 * The function posts a mailbox to the port. The mailbox is expected
6877 * to be comletely filled in and ready for the port to operate on it.
6878 * This routine executes a synchronous completion operation on the
6879 * mailbox by polling for its completion.
6881 * The caller must not be holding any locks when calling this routine.
6884 * MBX_SUCCESS - mailbox posted successfully
6885 * Any of the MBX error values.
6888 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6890 int rc
= MBX_SUCCESS
;
6891 unsigned long iflag
;
6893 uint32_t mcqe_status
;
6895 unsigned long timeout
;
6896 struct lpfc_sli
*psli
= &phba
->sli
;
6897 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
6898 struct lpfc_bmbx_create
*mbox_rgn
;
6899 struct dma_address
*dma_address
;
6900 struct lpfc_register bmbx_reg
;
6903 * Only one mailbox can be active to the bootstrap mailbox region
6904 * at a time and there is no queueing provided.
6906 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6907 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6908 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6909 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6910 "(%d):2532 Mailbox command x%x (x%x/x%x) "
6911 "cannot issue Data: x%x x%x\n",
6912 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6913 mboxq
->u
.mb
.mbxCommand
,
6914 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
6915 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
6916 psli
->sli_flag
, MBX_POLL
);
6917 return MBXERR_ERROR
;
6919 /* The server grabs the token and owns it until release */
6920 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6921 phba
->sli
.mbox_active
= mboxq
;
6922 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6925 * Initialize the bootstrap memory region to avoid stale data areas
6926 * in the mailbox post. Then copy the caller's mailbox contents to
6927 * the bmbx mailbox region.
6929 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
6930 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
6931 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
6932 sizeof(struct lpfc_mqe
));
6934 /* Post the high mailbox dma address to the port and wait for ready. */
6935 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
6936 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
6938 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
6941 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
6942 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
6946 if (time_after(jiffies
, timeout
)) {
6950 } while (!db_ready
);
6952 /* Post the low mailbox dma address to the port. */
6953 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
6954 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
6957 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
6958 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
6962 if (time_after(jiffies
, timeout
)) {
6966 } while (!db_ready
);
6969 * Read the CQ to ensure the mailbox has completed.
6970 * If so, update the mailbox status so that the upper layers
6971 * can complete the request normally.
6973 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
6974 sizeof(struct lpfc_mqe
));
6975 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
6976 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
6977 sizeof(struct lpfc_mcqe
));
6978 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
6980 * When the CQE status indicates a failure and the mailbox status
6981 * indicates success then copy the CQE status into the mailbox status
6982 * (and prefix it with x4000).
6984 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
6985 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
6986 bf_set(lpfc_mqe_status
, mb
,
6987 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
6990 lpfc_sli4_swap_str(phba
, mboxq
);
6992 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6993 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
6994 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
6995 " x%x x%x CQ: x%x x%x x%x x%x\n",
6996 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
6997 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
6998 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
6999 bf_get(lpfc_mqe_status
, mb
),
7000 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7001 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7002 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7003 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7004 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7005 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7006 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7007 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7008 mboxq
->mcqe
.trailer
);
7010 /* We are holding the token, no needed for lock when release */
7011 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7012 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7013 phba
->sli
.mbox_active
= NULL
;
7014 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7019 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7020 * @phba: Pointer to HBA context object.
7021 * @pmbox: Pointer to mailbox object.
7022 * @flag: Flag indicating how the mailbox need to be processed.
7024 * This function is called by discovery code and HBA management code to submit
7025 * a mailbox command to firmware with SLI-4 interface spec.
7027 * Return codes the caller owns the mailbox command after the return of the
7031 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7034 struct lpfc_sli
*psli
= &phba
->sli
;
7035 unsigned long iflags
;
7038 /* dump from issue mailbox command if setup */
7039 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7041 rc
= lpfc_mbox_dev_check(phba
);
7043 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7044 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7045 "cannot issue Data: x%x x%x\n",
7046 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7047 mboxq
->u
.mb
.mbxCommand
,
7048 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7049 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7050 psli
->sli_flag
, flag
);
7051 goto out_not_finished
;
7054 /* Detect polling mode and jump to a handler */
7055 if (!phba
->sli4_hba
.intr_enable
) {
7056 if (flag
== MBX_POLL
)
7057 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7060 if (rc
!= MBX_SUCCESS
)
7061 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7062 "(%d):2541 Mailbox command x%x "
7063 "(x%x/x%x) cannot issue Data: "
7065 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7066 mboxq
->u
.mb
.mbxCommand
,
7067 lpfc_sli_config_mbox_subsys_get(phba
,
7069 lpfc_sli_config_mbox_opcode_get(phba
,
7071 psli
->sli_flag
, flag
);
7073 } else if (flag
== MBX_POLL
) {
7074 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7075 "(%d):2542 Try to issue mailbox command "
7076 "x%x (x%x/x%x) synchronously ahead of async"
7077 "mailbox command queue: x%x x%x\n",
7078 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7079 mboxq
->u
.mb
.mbxCommand
,
7080 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7081 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7082 psli
->sli_flag
, flag
);
7083 /* Try to block the asynchronous mailbox posting */
7084 rc
= lpfc_sli4_async_mbox_block(phba
);
7086 /* Successfully blocked, now issue sync mbox cmd */
7087 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7088 if (rc
!= MBX_SUCCESS
)
7089 lpfc_printf_log(phba
, KERN_ERR
,
7091 "(%d):2597 Mailbox command "
7092 "x%x (x%x/x%x) cannot issue "
7095 mboxq
->vport
->vpi
: 0,
7096 mboxq
->u
.mb
.mbxCommand
,
7097 lpfc_sli_config_mbox_subsys_get(phba
,
7099 lpfc_sli_config_mbox_opcode_get(phba
,
7101 psli
->sli_flag
, flag
);
7102 /* Unblock the async mailbox posting afterward */
7103 lpfc_sli4_async_mbox_unblock(phba
);
7108 /* Now, interrupt mode asynchrous mailbox command */
7109 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7111 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7112 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7113 "cannot issue Data: x%x x%x\n",
7114 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7115 mboxq
->u
.mb
.mbxCommand
,
7116 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7117 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7118 psli
->sli_flag
, flag
);
7119 goto out_not_finished
;
7122 /* Put the mailbox command to the driver internal FIFO */
7123 psli
->slistat
.mbox_busy
++;
7124 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7125 lpfc_mbox_put(phba
, mboxq
);
7126 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7127 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7128 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7129 "x%x (x%x/x%x) x%x x%x x%x\n",
7130 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7131 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7132 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7133 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7134 phba
->pport
->port_state
,
7135 psli
->sli_flag
, MBX_NOWAIT
);
7136 /* Wake up worker thread to transport mailbox command from head */
7137 lpfc_worker_wake_up(phba
);
7142 return MBX_NOT_FINISHED
;
7146 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7147 * @phba: Pointer to HBA context object.
7149 * This function is called by worker thread to send a mailbox command to
7150 * SLI4 HBA firmware.
7154 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7156 struct lpfc_sli
*psli
= &phba
->sli
;
7157 LPFC_MBOXQ_t
*mboxq
;
7158 int rc
= MBX_SUCCESS
;
7159 unsigned long iflags
;
7160 struct lpfc_mqe
*mqe
;
7163 /* Check interrupt mode before post async mailbox command */
7164 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7165 return MBX_NOT_FINISHED
;
7167 /* Check for mailbox command service token */
7168 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7169 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7170 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7171 return MBX_NOT_FINISHED
;
7173 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7174 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7175 return MBX_NOT_FINISHED
;
7177 if (unlikely(phba
->sli
.mbox_active
)) {
7178 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7179 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7180 "0384 There is pending active mailbox cmd\n");
7181 return MBX_NOT_FINISHED
;
7183 /* Take the mailbox command service token */
7184 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7186 /* Get the next mailbox command from head of queue */
7187 mboxq
= lpfc_mbox_get(phba
);
7189 /* If no more mailbox command waiting for post, we're done */
7191 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7192 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7195 phba
->sli
.mbox_active
= mboxq
;
7196 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7198 /* Check device readiness for posting mailbox command */
7199 rc
= lpfc_mbox_dev_check(phba
);
7201 /* Driver clean routine will clean up pending mailbox */
7202 goto out_not_finished
;
7204 /* Prepare the mbox command to be posted */
7205 mqe
= &mboxq
->u
.mqe
;
7206 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7208 /* Start timer for the mbox_tmo and log some mailbox post messages */
7209 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7210 (HZ
* lpfc_mbox_tmo_val(phba
, mboxq
))));
7212 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7213 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7215 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7216 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7217 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7218 phba
->pport
->port_state
, psli
->sli_flag
);
7220 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7222 lpfc_debugfs_disc_trc(mboxq
->vport
,
7223 LPFC_DISC_TRC_MBOX_VPORT
,
7224 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7225 mbx_cmnd
, mqe
->un
.mb_words
[0],
7226 mqe
->un
.mb_words
[1]);
7228 lpfc_debugfs_disc_trc(phba
->pport
,
7230 "MBOX Send: cmd:x%x mb:x%x x%x",
7231 mbx_cmnd
, mqe
->un
.mb_words
[0],
7232 mqe
->un
.mb_words
[1]);
7235 psli
->slistat
.mbox_cmd
++;
7237 /* Post the mailbox command to the port */
7238 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7239 if (rc
!= MBX_SUCCESS
) {
7240 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7241 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7242 "cannot issue Data: x%x x%x\n",
7243 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7244 mboxq
->u
.mb
.mbxCommand
,
7245 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7246 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7247 psli
->sli_flag
, MBX_NOWAIT
);
7248 goto out_not_finished
;
7254 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7255 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7256 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7257 /* Release the token */
7258 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7259 phba
->sli
.mbox_active
= NULL
;
7260 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7262 return MBX_NOT_FINISHED
;
7266 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7267 * @phba: Pointer to HBA context object.
7268 * @pmbox: Pointer to mailbox object.
7269 * @flag: Flag indicating how the mailbox need to be processed.
7271 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7272 * the API jump table function pointer from the lpfc_hba struct.
7274 * Return codes the caller owns the mailbox command after the return of the
7278 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7280 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7284 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7285 * @phba: The hba struct for which this call is being executed.
7286 * @dev_grp: The HBA PCI-Device group number.
7288 * This routine sets up the mbox interface API function jump table in @phba
7290 * Returns: 0 - success, -ENODEV - failure.
7293 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7297 case LPFC_PCI_DEV_LP
:
7298 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7299 phba
->lpfc_sli_handle_slow_ring_event
=
7300 lpfc_sli_handle_slow_ring_event_s3
;
7301 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7302 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7303 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7305 case LPFC_PCI_DEV_OC
:
7306 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7307 phba
->lpfc_sli_handle_slow_ring_event
=
7308 lpfc_sli_handle_slow_ring_event_s4
;
7309 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7310 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7311 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7314 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7315 "1420 Invalid HBA PCI-device group: 0x%x\n",
7324 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7325 * @phba: Pointer to HBA context object.
7326 * @pring: Pointer to driver SLI ring object.
7327 * @piocb: Pointer to address of newly added command iocb.
7329 * This function is called with hbalock held to add a command
7330 * iocb to the txq when SLI layer cannot submit the command iocb
7334 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7335 struct lpfc_iocbq
*piocb
)
7337 /* Insert the caller's iocb in the txq tail for later processing. */
7338 list_add_tail(&piocb
->list
, &pring
->txq
);
7343 * lpfc_sli_next_iocb - Get the next iocb in the txq
7344 * @phba: Pointer to HBA context object.
7345 * @pring: Pointer to driver SLI ring object.
7346 * @piocb: Pointer to address of newly added command iocb.
7348 * This function is called with hbalock held before a new
7349 * iocb is submitted to the firmware. This function checks
7350 * txq to flush the iocbs in txq to Firmware before
7351 * submitting new iocbs to the Firmware.
7352 * If there are iocbs in the txq which need to be submitted
7353 * to firmware, lpfc_sli_next_iocb returns the first element
7354 * of the txq after dequeuing it from txq.
7355 * If there is no iocb in the txq then the function will return
7356 * *piocb and *piocb is set to NULL. Caller needs to check
7357 * *piocb to find if there are more commands in the txq.
7359 static struct lpfc_iocbq
*
7360 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7361 struct lpfc_iocbq
**piocb
)
7363 struct lpfc_iocbq
* nextiocb
;
7365 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7375 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7376 * @phba: Pointer to HBA context object.
7377 * @ring_number: SLI ring number to issue iocb on.
7378 * @piocb: Pointer to command iocb.
7379 * @flag: Flag indicating if this command can be put into txq.
7381 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7382 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7383 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7384 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7385 * this function allows only iocbs for posting buffers. This function finds
7386 * next available slot in the command ring and posts the command to the
7387 * available slot and writes the port attention register to request HBA start
7388 * processing new iocb. If there is no slot available in the ring and
7389 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7390 * the function returns IOCB_BUSY.
7392 * This function is called with hbalock held. The function will return success
7393 * after it successfully submit the iocb to firmware or after adding to the
7397 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7398 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7400 struct lpfc_iocbq
*nextiocb
;
7402 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7404 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7405 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7406 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7407 lpfc_printf_log(phba
, KERN_ERR
,
7408 LOG_SLI
| LOG_VPORT
,
7409 "1807 IOCB x%x failed. No vport\n",
7410 piocb
->iocb
.ulpCommand
);
7416 /* If the PCI channel is in offline state, do not post iocbs. */
7417 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7420 /* If HBA has a deferred error attention, fail the iocb. */
7421 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7425 * We should never get an IOCB if we are in a < LINK_DOWN state
7427 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7431 * Check to see if we are blocking IOCB processing because of a
7432 * outstanding event.
7434 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7437 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7439 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7440 * can be issued if the link is not up.
7442 switch (piocb
->iocb
.ulpCommand
) {
7443 case CMD_GEN_REQUEST64_CR
:
7444 case CMD_GEN_REQUEST64_CX
:
7445 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7446 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7447 FC_RCTL_DD_UNSOL_CMD
) ||
7448 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7449 MENLO_TRANSPORT_TYPE
))
7453 case CMD_QUE_RING_BUF_CN
:
7454 case CMD_QUE_RING_BUF64_CN
:
7456 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7457 * completion, iocb_cmpl MUST be 0.
7459 if (piocb
->iocb_cmpl
)
7460 piocb
->iocb_cmpl
= NULL
;
7462 case CMD_CREATE_XRI_CR
:
7463 case CMD_CLOSE_XRI_CN
:
7464 case CMD_CLOSE_XRI_CX
:
7471 * For FCP commands, we must be in a state where we can process link
7474 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7475 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7479 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7480 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7481 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7484 lpfc_sli_update_ring(phba
, pring
);
7486 lpfc_sli_update_full_ring(phba
, pring
);
7489 return IOCB_SUCCESS
;
7494 pring
->stats
.iocb_cmd_delay
++;
7498 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7499 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7500 return IOCB_SUCCESS
;
7507 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7508 * @phba: Pointer to HBA context object.
7509 * @piocb: Pointer to command iocb.
7510 * @sglq: Pointer to the scatter gather queue object.
7512 * This routine converts the bpl or bde that is in the IOCB
7513 * to a sgl list for the sli4 hardware. The physical address
7514 * of the bpl/bde is converted back to a virtual address.
7515 * If the IOCB contains a BPL then the list of BDE's is
7516 * converted to sli4_sge's. If the IOCB contains a single
7517 * BDE then it is converted to a single sli_sge.
7518 * The IOCB is still in cpu endianess so the contents of
7519 * the bpl can be used without byte swapping.
7521 * Returns valid XRI = Success, NO_XRI = Failure.
7524 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7525 struct lpfc_sglq
*sglq
)
7527 uint16_t xritag
= NO_XRI
;
7528 struct ulp_bde64
*bpl
= NULL
;
7529 struct ulp_bde64 bde
;
7530 struct sli4_sge
*sgl
= NULL
;
7531 struct lpfc_dmabuf
*dmabuf
;
7535 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7536 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7538 if (!piocbq
|| !sglq
)
7541 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7542 icmd
= &piocbq
->iocb
;
7543 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
7544 return sglq
->sli4_xritag
;
7545 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7546 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7547 sizeof(struct ulp_bde64
);
7548 /* The addrHigh and addrLow fields within the IOCB
7549 * have not been byteswapped yet so there is no
7550 * need to swap them back.
7552 if (piocbq
->context3
)
7553 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7557 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7561 for (i
= 0; i
< numBdes
; i
++) {
7562 /* Should already be byte swapped. */
7563 sgl
->addr_hi
= bpl
->addrHigh
;
7564 sgl
->addr_lo
= bpl
->addrLow
;
7566 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7567 if ((i
+1) == numBdes
)
7568 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7570 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7571 /* swap the size field back to the cpu so we
7572 * can assign it to the sgl.
7574 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7575 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7576 /* The offsets in the sgl need to be accumulated
7577 * separately for the request and reply lists.
7578 * The request is always first, the reply follows.
7580 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7581 /* add up the reply sg entries */
7582 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7584 /* first inbound? reset the offset */
7587 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7588 bf_set(lpfc_sli4_sge_type
, sgl
,
7589 LPFC_SGE_TYPE_DATA
);
7590 offset
+= bde
.tus
.f
.bdeSize
;
7592 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7596 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
7597 /* The addrHigh and addrLow fields of the BDE have not
7598 * been byteswapped yet so they need to be swapped
7599 * before putting them in the sgl.
7602 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
7604 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
7605 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7606 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7607 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7609 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
7611 return sglq
->sli4_xritag
;
7615 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7616 * @phba: Pointer to HBA context object.
7618 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7619 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7622 * Return: index into SLI4 fast-path FCP queue index.
7625 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
7628 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
7631 return phba
->fcp_qidx
;
7635 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7636 * @phba: Pointer to HBA context object.
7637 * @piocb: Pointer to command iocb.
7638 * @wqe: Pointer to the work queue entry.
7640 * This routine converts the iocb command to its Work Queue Entry
7641 * equivalent. The wqe pointer should not have any fields set when
7642 * this routine is called because it will memcpy over them.
7643 * This routine does not set the CQ_ID or the WQEC bits in the
7646 * Returns: 0 = Success, IOCB_ERROR = Failure.
7649 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
7650 union lpfc_wqe
*wqe
)
7652 uint32_t xmit_len
= 0, total_len
= 0;
7656 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
7659 uint16_t abrt_iotag
;
7660 struct lpfc_iocbq
*abrtiocbq
;
7661 struct ulp_bde64
*bpl
= NULL
;
7662 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
7664 struct ulp_bde64 bde
;
7665 struct lpfc_nodelist
*ndlp
;
7669 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
7670 /* The fcp commands will set command type */
7671 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7672 command_type
= FCP_COMMAND
;
7673 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
7674 command_type
= ELS_COMMAND_FIP
;
7676 command_type
= ELS_COMMAND_NON_FIP
;
7678 /* Some of the fields are in the right position already */
7679 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
7680 abort_tag
= (uint32_t) iocbq
->iotag
;
7681 xritag
= iocbq
->sli4_xritag
;
7682 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
7683 /* words0-2 bpl convert bde */
7684 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7685 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7686 sizeof(struct ulp_bde64
);
7687 bpl
= (struct ulp_bde64
*)
7688 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
7692 /* Should already be byte swapped. */
7693 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
7694 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
7695 /* swap the size field back to the cpu so we
7696 * can assign it to the sgl.
7698 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7699 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
7701 for (i
= 0; i
< numBdes
; i
++) {
7702 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7703 total_len
+= bde
.tus
.f
.bdeSize
;
7706 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
7708 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
7709 cmnd
= iocbq
->iocb
.ulpCommand
;
7711 switch (iocbq
->iocb
.ulpCommand
) {
7712 case CMD_ELS_REQUEST64_CR
:
7713 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7714 if (!iocbq
->iocb
.ulpLe
) {
7715 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7716 "2007 Only Limited Edition cmd Format"
7717 " supported 0x%x\n",
7718 iocbq
->iocb
.ulpCommand
);
7722 wqe
->els_req
.payload_len
= xmit_len
;
7723 /* Els_reguest64 has a TMO */
7724 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
7725 iocbq
->iocb
.ulpTimeout
);
7726 /* Need a VF for word 4 set the vf bit*/
7727 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
7728 /* And a VFID for word 12 */
7729 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
7730 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7731 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7732 iocbq
->iocb
.ulpContext
);
7733 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
7734 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
7735 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7736 if (command_type
== ELS_COMMAND_FIP
)
7737 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
7738 >> LPFC_FIP_ELS_ID_SHIFT
);
7739 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7740 iocbq
->context2
)->virt
);
7741 if_type
= bf_get(lpfc_sli_intf_if_type
,
7742 &phba
->sli4_hba
.sli_intf
);
7743 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7744 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
7745 *pcmd
== ELS_CMD_SCR
||
7746 *pcmd
== ELS_CMD_FDISC
||
7747 *pcmd
== ELS_CMD_LOGO
||
7748 *pcmd
== ELS_CMD_PLOGI
)) {
7749 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7750 bf_set(els_req64_sid
, &wqe
->els_req
,
7751 iocbq
->vport
->fc_myDID
);
7752 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7753 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7754 phba
->vpi_ids
[phba
->pport
->vpi
]);
7755 } else if (pcmd
&& iocbq
->context1
) {
7756 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
7757 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7758 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7761 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
7762 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7763 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
7764 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
7765 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7766 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
7767 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7768 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
7770 case CMD_XMIT_SEQUENCE64_CX
:
7771 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
7772 iocbq
->iocb
.un
.ulpWord
[3]);
7773 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
7774 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7775 /* The entire sequence is transmitted for this IOCB */
7776 xmit_len
= total_len
;
7777 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
7778 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
7779 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
7780 case CMD_XMIT_SEQUENCE64_CR
:
7781 /* word3 iocb=io_tag32 wqe=reserved */
7782 wqe
->xmit_sequence
.rsvd3
= 0;
7783 /* word4 relative_offset memcpy */
7784 /* word5 r_ctl/df_ctl memcpy */
7785 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
7786 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
7787 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
7788 LPFC_WQE_IOD_WRITE
);
7789 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
7790 LPFC_WQE_LENLOC_WORD12
);
7791 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
7792 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
7793 command_type
= OTHER_COMMAND
;
7795 case CMD_XMIT_BCAST64_CN
:
7796 /* word3 iocb=iotag32 wqe=seq_payload_len */
7797 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
7798 /* word4 iocb=rsvd wqe=rsvd */
7799 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
7800 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
7801 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
7802 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7803 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
7804 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7805 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
7806 LPFC_WQE_LENLOC_WORD3
);
7807 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
7809 case CMD_FCP_IWRITE64_CR
:
7810 command_type
= FCP_COMMAND_DATA_OUT
;
7811 /* word3 iocb=iotag wqe=payload_offset_len */
7812 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7813 wqe
->fcp_iwrite
.payload_offset_len
=
7814 xmit_len
+ sizeof(struct fcp_rsp
);
7815 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7816 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7817 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
7818 iocbq
->iocb
.ulpFCP2Rcvy
);
7819 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
7820 /* Always open the exchange */
7821 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
7822 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7823 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
7824 LPFC_WQE_LENLOC_WORD4
);
7825 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
7826 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
7827 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
7828 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
7829 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
7831 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
7833 case CMD_FCP_IREAD64_CR
:
7834 /* word3 iocb=iotag wqe=payload_offset_len */
7835 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7836 wqe
->fcp_iread
.payload_offset_len
=
7837 xmit_len
+ sizeof(struct fcp_rsp
);
7838 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7839 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7840 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
7841 iocbq
->iocb
.ulpFCP2Rcvy
);
7842 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
7843 /* Always open the exchange */
7844 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
7845 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
7846 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
7847 LPFC_WQE_LENLOC_WORD4
);
7848 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
7849 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
7850 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
7851 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
7852 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
7854 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
7856 case CMD_FCP_ICMND64_CR
:
7857 /* word3 iocb=IO_TAG wqe=reserved */
7858 wqe
->fcp_icmd
.rsrvd3
= 0;
7859 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
7860 /* Always open the exchange */
7861 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
7862 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
7863 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7864 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
7865 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
7866 LPFC_WQE_LENLOC_NONE
);
7867 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
7869 case CMD_GEN_REQUEST64_CR
:
7870 /* For this command calculate the xmit length of the
7874 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7875 sizeof(struct ulp_bde64
);
7876 for (i
= 0; i
< numBdes
; i
++) {
7877 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7878 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
7880 xmit_len
+= bde
.tus
.f
.bdeSize
;
7882 /* word3 iocb=IO_TAG wqe=request_payload_len */
7883 wqe
->gen_req
.request_payload_len
= xmit_len
;
7884 /* word4 iocb=parameter wqe=relative_offset memcpy */
7885 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
7886 /* word6 context tag copied in memcpy */
7887 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
7888 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7889 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7890 "2015 Invalid CT %x command 0x%x\n",
7891 ct
, iocbq
->iocb
.ulpCommand
);
7894 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
7895 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
7896 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
7897 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
7898 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7899 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
7900 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7901 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
7902 command_type
= OTHER_COMMAND
;
7904 case CMD_XMIT_ELS_RSP64_CX
:
7905 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7906 /* words0-2 BDE memcpy */
7907 /* word3 iocb=iotag32 wqe=response_payload_len */
7908 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
7909 /* word4 iocb=did wge=rsvd. */
7910 wqe
->xmit_els_rsp
.rsvd4
= 0;
7911 /* word5 iocb=rsvd wge=did */
7912 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
7913 iocbq
->iocb
.un
.elsreq64
.remoteID
);
7914 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
7915 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7916 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
7917 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
7918 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7919 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
7920 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
7921 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
7922 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
7923 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7924 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
7925 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
7926 LPFC_WQE_LENLOC_WORD3
);
7927 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
7928 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
7929 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7930 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7931 iocbq
->context2
)->virt
);
7932 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
7933 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7934 bf_set(els_req64_sid
, &wqe
->els_req
,
7935 iocbq
->vport
->fc_myDID
);
7936 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7937 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7938 phba
->vpi_ids
[phba
->pport
->vpi
]);
7940 command_type
= OTHER_COMMAND
;
7942 case CMD_CLOSE_XRI_CN
:
7943 case CMD_ABORT_XRI_CN
:
7944 case CMD_ABORT_XRI_CX
:
7945 /* words 0-2 memcpy should be 0 rserved */
7946 /* port will send abts */
7947 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
7948 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
7949 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
7950 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
7954 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
7956 * The link is down, or the command was ELS_FIP
7957 * so the fw does not need to send abts
7960 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
7962 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
7963 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
7964 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
7965 wqe
->abort_cmd
.rsrvd5
= 0;
7966 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
7967 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7968 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
7970 * The abort handler will send us CMD_ABORT_XRI_CN or
7971 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
7973 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
7974 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
7975 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
7976 LPFC_WQE_LENLOC_NONE
);
7977 cmnd
= CMD_ABORT_XRI_CX
;
7978 command_type
= OTHER_COMMAND
;
7981 case CMD_XMIT_BLS_RSP64_CX
:
7982 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7983 /* As BLS ABTS RSP WQE is very different from other WQEs,
7984 * we re-construct this WQE here based on information in
7985 * iocbq from scratch.
7987 memset(wqe
, 0, sizeof(union lpfc_wqe
));
7988 /* OX_ID is invariable to who sent ABTS to CT exchange */
7989 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
7990 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
7991 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
7992 LPFC_ABTS_UNSOL_INT
) {
7993 /* ABTS sent by initiator to CT exchange, the
7994 * RX_ID field will be filled with the newly
7995 * allocated responder XRI.
7997 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
7998 iocbq
->sli4_xritag
);
8000 /* ABTS sent by responder to CT exchange, the
8001 * RX_ID field will be filled with the responder
8004 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8005 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8007 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8008 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8011 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8013 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8014 iocbq
->iocb
.ulpContext
);
8015 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8016 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8017 phba
->vpi_ids
[phba
->pport
->vpi
]);
8018 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8019 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8020 LPFC_WQE_LENLOC_NONE
);
8021 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8022 command_type
= OTHER_COMMAND
;
8023 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8024 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8025 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8026 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8027 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8028 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8029 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8033 case CMD_XRI_ABORTED_CX
:
8034 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8035 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8036 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8037 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8038 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8040 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8041 "2014 Invalid command 0x%x\n",
8042 iocbq
->iocb
.ulpCommand
);
8047 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8048 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8049 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8050 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8051 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8052 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8053 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8058 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8059 * @phba: Pointer to HBA context object.
8060 * @ring_number: SLI ring number to issue iocb on.
8061 * @piocb: Pointer to command iocb.
8062 * @flag: Flag indicating if this command can be put into txq.
8064 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8065 * an iocb command to an HBA with SLI-4 interface spec.
8067 * This function is called with hbalock held. The function will return success
8068 * after it successfully submit the iocb to firmware or after adding to the
8072 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8073 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8075 struct lpfc_sglq
*sglq
;
8077 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8079 if (piocb
->sli4_xritag
== NO_XRI
) {
8080 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8081 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8084 if (pring
->txq_cnt
) {
8085 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8086 __lpfc_sli_ringtx_put(phba
,
8088 return IOCB_SUCCESS
;
8093 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8095 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8096 __lpfc_sli_ringtx_put(phba
,
8099 return IOCB_SUCCESS
;
8105 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8106 /* These IO's already have an XRI and a mapped sgl. */
8110 * This is a continuation of a commandi,(CX) so this
8111 * sglq is on the active list
8113 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
8119 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8120 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8121 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8125 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8128 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8129 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8131 * For FCP command IOCB, get a new WQ index to distribute
8132 * WQE across the WQsr. On the other hand, for abort IOCB,
8133 * it carries the same WQ index to the original command
8136 if (piocb
->iocb_flag
& LPFC_IO_FCP
)
8137 piocb
->fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8138 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8140 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8144 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8147 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8153 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8155 * This routine wraps the actual lockless version for issusing IOCB function
8156 * pointer from the lpfc_hba struct.
8159 * IOCB_ERROR - Error
8160 * IOCB_SUCCESS - Success
8164 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8165 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8167 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8171 * lpfc_sli_api_table_setup - Set up sli api function jump table
8172 * @phba: The hba struct for which this call is being executed.
8173 * @dev_grp: The HBA PCI-Device group number.
8175 * This routine sets up the SLI interface API function jump table in @phba
8177 * Returns: 0 - success, -ENODEV - failure.
8180 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8184 case LPFC_PCI_DEV_LP
:
8185 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8186 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8188 case LPFC_PCI_DEV_OC
:
8189 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8190 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8193 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8194 "1419 Invalid HBA PCI-device group: 0x%x\n",
8199 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8204 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8205 * @phba: Pointer to HBA context object.
8206 * @pring: Pointer to driver SLI ring object.
8207 * @piocb: Pointer to command iocb.
8208 * @flag: Flag indicating if this command can be put into txq.
8210 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8211 * function. This function gets the hbalock and calls
8212 * __lpfc_sli_issue_iocb function and will return the error returned
8213 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8214 * functions which do not hold hbalock.
8217 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8218 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8220 unsigned long iflags
;
8223 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8224 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8225 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8231 * lpfc_extra_ring_setup - Extra ring setup function
8232 * @phba: Pointer to HBA context object.
8234 * This function is called while driver attaches with the
8235 * HBA to setup the extra ring. The extra ring is used
8236 * only when driver needs to support target mode functionality
8237 * or IP over FC functionalities.
8239 * This function is called with no lock held.
8242 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8244 struct lpfc_sli
*psli
;
8245 struct lpfc_sli_ring
*pring
;
8249 /* Adjust cmd/rsp ring iocb entries more evenly */
8251 /* Take some away from the FCP ring */
8252 pring
= &psli
->ring
[psli
->fcp_ring
];
8253 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8254 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8255 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8256 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8258 /* and give them to the extra ring */
8259 pring
= &psli
->ring
[psli
->extra_ring
];
8261 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8262 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8263 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8264 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8266 /* Setup default profile for this ring */
8267 pring
->iotag_max
= 4096;
8268 pring
->num_mask
= 1;
8269 pring
->prt
[0].profile
= 0; /* Mask 0 */
8270 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8271 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8272 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8276 /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
8277 * @vport: pointer to virtual port object.
8278 * @ndlp: nodelist pointer for the impacted rport.
8280 * The driver calls this routine in response to a XRI ABORT CQE
8281 * event from the port. In this event, the driver is required to
8282 * recover its login to the rport even though its login may be valid
8283 * from the driver's perspective. The failed ABTS notice from the
8284 * port indicates the rport is not responding.
8287 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8288 struct lpfc_nodelist
*ndlp
)
8290 struct Scsi_Host
*shost
;
8291 struct lpfc_hba
*phba
;
8292 unsigned long flags
= 0;
8294 shost
= lpfc_shost_from_vport(vport
);
8296 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8297 lpfc_printf_log(phba
, KERN_INFO
,
8298 LOG_SLI
, "3093 No rport recovery needed. "
8299 "rport in state 0x%x\n",
8303 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8304 "3094 Start rport recovery on shost id 0x%x "
8305 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8307 shost
->host_no
, ndlp
->nlp_DID
,
8308 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8311 * The rport is not responding. Don't attempt ADISC recovery.
8312 * Remove the FCP-2 flag to force a PLOGI.
8314 spin_lock_irqsave(shost
->host_lock
, flags
);
8315 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8316 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8317 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
8318 NLP_EVT_DEVICE_RECOVERY
);
8319 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
8320 spin_lock_irqsave(shost
->host_lock
, flags
);
8321 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
8322 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8323 lpfc_disc_start(vport
);
8326 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8327 * @phba: Pointer to HBA context object.
8328 * @iocbq: Pointer to iocb object.
8330 * The async_event handler calls this routine when it receives
8331 * an ASYNC_STATUS_CN event from the port. The port generates
8332 * this event when an Abort Sequence request to an rport fails
8333 * twice in succession. The abort could be originated by the
8334 * driver or by the port. The ABTS could have been for an ELS
8335 * or FCP IO. The port only generates this event when an ABTS
8336 * fails to complete after one retry.
8339 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8340 struct lpfc_iocbq
*iocbq
)
8342 struct lpfc_nodelist
*ndlp
= NULL
;
8343 uint16_t rpi
= 0, vpi
= 0;
8344 struct lpfc_vport
*vport
= NULL
;
8346 /* The rpi in the ulpContext is vport-sensitive. */
8347 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8348 rpi
= iocbq
->iocb
.ulpContext
;
8350 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8351 "3092 Port generated ABTS async event "
8352 "on vpi %d rpi %d status 0x%x\n",
8353 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8355 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8358 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8359 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8362 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8363 lpfc_sli_abts_recover_port(vport
, ndlp
);
8367 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8368 "3095 Event Context not found, no "
8369 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8370 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8374 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8375 * @phba: pointer to HBA context object.
8376 * @ndlp: nodelist pointer for the impacted rport.
8377 * @axri: pointer to the wcqe containing the failed exchange.
8379 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8380 * port. The port generates this event when an abort exchange request to an
8381 * rport fails twice in succession with no reply. The abort could be originated
8382 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8385 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8386 struct lpfc_nodelist
*ndlp
,
8387 struct sli4_wcqe_xri_aborted
*axri
)
8389 struct lpfc_vport
*vport
;
8390 uint32_t ext_status
= 0;
8392 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
8393 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8394 "3115 Node Context not found, driver "
8395 "ignoring abts err event\n");
8399 vport
= ndlp
->vport
;
8400 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8401 "3116 Port generated FCP XRI ABORT event on "
8402 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8403 ndlp
->vport
->vpi
, ndlp
->nlp_rpi
,
8404 bf_get(lpfc_wcqe_xa_xri
, axri
),
8405 bf_get(lpfc_wcqe_xa_status
, axri
),
8409 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8410 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8411 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8413 ext_status
= axri
->parameter
& WCQE_PARAM_MASK
;
8414 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
8415 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
8416 lpfc_sli_abts_recover_port(vport
, ndlp
);
8420 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8421 * @phba: Pointer to HBA context object.
8422 * @pring: Pointer to driver SLI ring object.
8423 * @iocbq: Pointer to iocb object.
8425 * This function is called by the slow ring event handler
8426 * function when there is an ASYNC event iocb in the ring.
8427 * This function is called with no lock held.
8428 * Currently this function handles only temperature related
8429 * ASYNC events. The function decodes the temperature sensor
8430 * event message and posts events for the management applications.
8433 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8434 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8438 struct temp_event temp_event_data
;
8439 struct Scsi_Host
*shost
;
8442 icmd
= &iocbq
->iocb
;
8443 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8446 case ASYNC_TEMP_WARN
:
8447 case ASYNC_TEMP_SAFE
:
8448 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8449 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8450 if (evt_code
== ASYNC_TEMP_WARN
) {
8451 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8452 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8453 "0347 Adapter is very hot, please take "
8454 "corrective action. temperature : %d Celsius\n",
8455 (uint32_t) icmd
->ulpContext
);
8457 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8458 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8459 "0340 Adapter temperature is OK now. "
8460 "temperature : %d Celsius\n",
8461 (uint32_t) icmd
->ulpContext
);
8464 /* Send temperature change event to applications */
8465 shost
= lpfc_shost_from_vport(phba
->pport
);
8466 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8467 sizeof(temp_event_data
), (char *) &temp_event_data
,
8470 case ASYNC_STATUS_CN
:
8471 lpfc_sli_abts_err_handler(phba
, iocbq
);
8474 iocb_w
= (uint32_t *) icmd
;
8475 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8476 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8478 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8479 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8480 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8481 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8482 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8483 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8484 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8485 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8486 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8494 * lpfc_sli_setup - SLI ring setup function
8495 * @phba: Pointer to HBA context object.
8497 * lpfc_sli_setup sets up rings of the SLI interface with
8498 * number of iocbs per ring and iotags. This function is
8499 * called while driver attach to the HBA and before the
8500 * interrupts are enabled. So there is no need for locking.
8502 * This function always returns 0.
8505 lpfc_sli_setup(struct lpfc_hba
*phba
)
8507 int i
, totiocbsize
= 0;
8508 struct lpfc_sli
*psli
= &phba
->sli
;
8509 struct lpfc_sli_ring
*pring
;
8511 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
8513 psli
->fcp_ring
= LPFC_FCP_RING
;
8514 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8515 psli
->extra_ring
= LPFC_EXTRA_RING
;
8517 psli
->iocbq_lookup
= NULL
;
8518 psli
->iocbq_lookup_len
= 0;
8519 psli
->last_iotag
= 0;
8521 for (i
= 0; i
< psli
->num_rings
; i
++) {
8522 pring
= &psli
->ring
[i
];
8524 case LPFC_FCP_RING
: /* ring 0 - FCP */
8525 /* numCiocb and numRiocb are used in config_port */
8526 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8527 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8528 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8529 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8530 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8531 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8532 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8533 SLI3_IOCB_CMD_SIZE
:
8535 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8536 SLI3_IOCB_RSP_SIZE
:
8538 pring
->iotag_ctr
= 0;
8540 (phba
->cfg_hba_queue_depth
* 2);
8541 pring
->fast_iotag
= pring
->iotag_max
;
8542 pring
->num_mask
= 0;
8544 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
8545 /* numCiocb and numRiocb are used in config_port */
8546 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
8547 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
8548 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8549 SLI3_IOCB_CMD_SIZE
:
8551 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8552 SLI3_IOCB_RSP_SIZE
:
8554 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
8555 pring
->num_mask
= 0;
8557 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
8558 /* numCiocb and numRiocb are used in config_port */
8559 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
8560 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
8561 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8562 SLI3_IOCB_CMD_SIZE
:
8564 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8565 SLI3_IOCB_RSP_SIZE
:
8567 pring
->fast_iotag
= 0;
8568 pring
->iotag_ctr
= 0;
8569 pring
->iotag_max
= 4096;
8570 pring
->lpfc_sli_rcv_async_status
=
8571 lpfc_sli_async_event_handler
;
8572 pring
->num_mask
= LPFC_MAX_RING_MASK
;
8573 pring
->prt
[0].profile
= 0; /* Mask 0 */
8574 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
8575 pring
->prt
[0].type
= FC_TYPE_ELS
;
8576 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
8577 lpfc_els_unsol_event
;
8578 pring
->prt
[1].profile
= 0; /* Mask 1 */
8579 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
8580 pring
->prt
[1].type
= FC_TYPE_ELS
;
8581 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
8582 lpfc_els_unsol_event
;
8583 pring
->prt
[2].profile
= 0; /* Mask 2 */
8584 /* NameServer Inquiry */
8585 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
8587 pring
->prt
[2].type
= FC_TYPE_CT
;
8588 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
8589 lpfc_ct_unsol_event
;
8590 pring
->prt
[3].profile
= 0; /* Mask 3 */
8591 /* NameServer response */
8592 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
8594 pring
->prt
[3].type
= FC_TYPE_CT
;
8595 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
8596 lpfc_ct_unsol_event
;
8597 /* abort unsolicited sequence */
8598 pring
->prt
[4].profile
= 0; /* Mask 4 */
8599 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
8600 pring
->prt
[4].type
= FC_TYPE_BLS
;
8601 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
8602 lpfc_sli4_ct_abort_unsol_event
;
8605 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
8606 (pring
->numRiocb
* pring
->sizeRiocb
);
8608 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
8609 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8610 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
8611 "SLI2 SLIM Data: x%x x%lx\n",
8612 phba
->brd_no
, totiocbsize
,
8613 (unsigned long) MAX_SLIM_IOCB_SIZE
);
8615 if (phba
->cfg_multi_ring_support
== 2)
8616 lpfc_extra_ring_setup(phba
);
8622 * lpfc_sli_queue_setup - Queue initialization function
8623 * @phba: Pointer to HBA context object.
8625 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8626 * ring. This function also initializes ring indices of each ring.
8627 * This function is called during the initialization of the SLI
8628 * interface of an HBA.
8629 * This function is called with no lock held and always returns
8633 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
8635 struct lpfc_sli
*psli
;
8636 struct lpfc_sli_ring
*pring
;
8640 spin_lock_irq(&phba
->hbalock
);
8641 INIT_LIST_HEAD(&psli
->mboxq
);
8642 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
8643 /* Initialize list headers for txq and txcmplq as double linked lists */
8644 for (i
= 0; i
< psli
->num_rings
; i
++) {
8645 pring
= &psli
->ring
[i
];
8647 pring
->next_cmdidx
= 0;
8648 pring
->local_getidx
= 0;
8650 INIT_LIST_HEAD(&pring
->txq
);
8651 INIT_LIST_HEAD(&pring
->txcmplq
);
8652 INIT_LIST_HEAD(&pring
->iocb_continueq
);
8653 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
8654 INIT_LIST_HEAD(&pring
->postbufq
);
8656 spin_unlock_irq(&phba
->hbalock
);
8661 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8662 * @phba: Pointer to HBA context object.
8664 * This routine flushes the mailbox command subsystem. It will unconditionally
8665 * flush all the mailbox commands in the three possible stages in the mailbox
8666 * command sub-system: pending mailbox command queue; the outstanding mailbox
8667 * command; and completed mailbox command queue. It is caller's responsibility
8668 * to make sure that the driver is in the proper state to flush the mailbox
8669 * command sub-system. Namely, the posting of mailbox commands into the
8670 * pending mailbox command queue from the various clients must be stopped;
8671 * either the HBA is in a state that it will never works on the outstanding
8672 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8673 * mailbox command has been completed.
8676 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
8678 LIST_HEAD(completions
);
8679 struct lpfc_sli
*psli
= &phba
->sli
;
8681 unsigned long iflag
;
8683 /* Flush all the mailbox commands in the mbox system */
8684 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8685 /* The pending mailbox command queue */
8686 list_splice_init(&phba
->sli
.mboxq
, &completions
);
8687 /* The outstanding active mailbox command */
8688 if (psli
->mbox_active
) {
8689 list_add_tail(&psli
->mbox_active
->list
, &completions
);
8690 psli
->mbox_active
= NULL
;
8691 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8693 /* The completed mailbox command queue */
8694 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
8695 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8697 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8698 while (!list_empty(&completions
)) {
8699 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
8700 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8702 pmb
->mbox_cmpl(phba
, pmb
);
8707 * lpfc_sli_host_down - Vport cleanup function
8708 * @vport: Pointer to virtual port object.
8710 * lpfc_sli_host_down is called to clean up the resources
8711 * associated with a vport before destroying virtual
8712 * port data structures.
8713 * This function does following operations:
8714 * - Free discovery resources associated with this virtual
8716 * - Free iocbs associated with this virtual port in
8718 * - Send abort for all iocb commands associated with this
8721 * This function is called with no lock held and always returns 1.
8724 lpfc_sli_host_down(struct lpfc_vport
*vport
)
8726 LIST_HEAD(completions
);
8727 struct lpfc_hba
*phba
= vport
->phba
;
8728 struct lpfc_sli
*psli
= &phba
->sli
;
8729 struct lpfc_sli_ring
*pring
;
8730 struct lpfc_iocbq
*iocb
, *next_iocb
;
8732 unsigned long flags
= 0;
8733 uint16_t prev_pring_flag
;
8735 lpfc_cleanup_discovery_resources(vport
);
8737 spin_lock_irqsave(&phba
->hbalock
, flags
);
8738 for (i
= 0; i
< psli
->num_rings
; i
++) {
8739 pring
= &psli
->ring
[i
];
8740 prev_pring_flag
= pring
->flag
;
8741 /* Only slow rings */
8742 if (pring
->ringno
== LPFC_ELS_RING
) {
8743 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8744 /* Set the lpfc data pending flag */
8745 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8748 * Error everything on the txq since these iocbs have not been
8749 * given to the FW yet.
8751 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
8752 if (iocb
->vport
!= vport
)
8754 list_move_tail(&iocb
->list
, &completions
);
8758 /* Next issue ABTS for everything on the txcmplq */
8759 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
8761 if (iocb
->vport
!= vport
)
8763 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
8766 pring
->flag
= prev_pring_flag
;
8769 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8771 /* Cancel all the IOCBs from the completions list */
8772 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8778 * lpfc_sli_hba_down - Resource cleanup function for the HBA
8779 * @phba: Pointer to HBA context object.
8781 * This function cleans up all iocb, buffers, mailbox commands
8782 * while shutting down the HBA. This function is called with no
8783 * lock held and always returns 1.
8784 * This function does the following to cleanup driver resources:
8785 * - Free discovery resources for each virtual port
8786 * - Cleanup any pending fabric iocbs
8787 * - Iterate through the iocb txq and free each entry
8789 * - Free up any buffer posted to the HBA
8790 * - Free mailbox commands in the mailbox queue.
8793 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
8795 LIST_HEAD(completions
);
8796 struct lpfc_sli
*psli
= &phba
->sli
;
8797 struct lpfc_sli_ring
*pring
;
8798 struct lpfc_dmabuf
*buf_ptr
;
8799 unsigned long flags
= 0;
8802 /* Shutdown the mailbox command sub-system */
8803 lpfc_sli_mbox_sys_shutdown(phba
);
8805 lpfc_hba_down_prep(phba
);
8807 lpfc_fabric_abort_hba(phba
);
8809 spin_lock_irqsave(&phba
->hbalock
, flags
);
8810 for (i
= 0; i
< psli
->num_rings
; i
++) {
8811 pring
= &psli
->ring
[i
];
8812 /* Only slow rings */
8813 if (pring
->ringno
== LPFC_ELS_RING
) {
8814 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8815 /* Set the lpfc data pending flag */
8816 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8820 * Error everything on the txq since these iocbs have not been
8821 * given to the FW yet.
8823 list_splice_init(&pring
->txq
, &completions
);
8827 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8829 /* Cancel all the IOCBs from the completions list */
8830 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8833 spin_lock_irqsave(&phba
->hbalock
, flags
);
8834 list_splice_init(&phba
->elsbuf
, &completions
);
8835 phba
->elsbuf_cnt
= 0;
8836 phba
->elsbuf_prev_cnt
= 0;
8837 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8839 while (!list_empty(&completions
)) {
8840 list_remove_head(&completions
, buf_ptr
,
8841 struct lpfc_dmabuf
, list
);
8842 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
8846 /* Return any active mbox cmds */
8847 del_timer_sync(&psli
->mbox_tmo
);
8849 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
8850 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
8851 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
8857 * lpfc_sli_pcimem_bcopy - SLI memory copy function
8858 * @srcp: Source memory pointer.
8859 * @destp: Destination memory pointer.
8860 * @cnt: Number of words required to be copied.
8862 * This function is used for copying data between driver memory
8863 * and the SLI memory. This function also changes the endianness
8864 * of each word if native endianness is different from SLI
8865 * endianness. This function can be called with or without
8869 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
8871 uint32_t *src
= srcp
;
8872 uint32_t *dest
= destp
;
8876 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
8878 ldata
= le32_to_cpu(ldata
);
8887 * lpfc_sli_bemem_bcopy - SLI memory copy function
8888 * @srcp: Source memory pointer.
8889 * @destp: Destination memory pointer.
8890 * @cnt: Number of words required to be copied.
8892 * This function is used for copying data between a data structure
8893 * with big endian representation to local endianness.
8894 * This function can be called with or without lock.
8897 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
8899 uint32_t *src
= srcp
;
8900 uint32_t *dest
= destp
;
8904 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
8906 ldata
= be32_to_cpu(ldata
);
8914 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
8915 * @phba: Pointer to HBA context object.
8916 * @pring: Pointer to driver SLI ring object.
8917 * @mp: Pointer to driver buffer object.
8919 * This function is called with no lock held.
8920 * It always return zero after adding the buffer to the postbufq
8924 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8925 struct lpfc_dmabuf
*mp
)
8927 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
8929 spin_lock_irq(&phba
->hbalock
);
8930 list_add_tail(&mp
->list
, &pring
->postbufq
);
8931 pring
->postbufq_cnt
++;
8932 spin_unlock_irq(&phba
->hbalock
);
8937 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
8938 * @phba: Pointer to HBA context object.
8940 * When HBQ is enabled, buffers are searched based on tags. This function
8941 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
8942 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
8943 * does not conflict with tags of buffer posted for unsolicited events.
8944 * The function returns the allocated tag. The function is called with
8948 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
8950 spin_lock_irq(&phba
->hbalock
);
8951 phba
->buffer_tag_count
++;
8953 * Always set the QUE_BUFTAG_BIT to distiguish between
8954 * a tag assigned by HBQ.
8956 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
8957 spin_unlock_irq(&phba
->hbalock
);
8958 return phba
->buffer_tag_count
;
8962 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
8963 * @phba: Pointer to HBA context object.
8964 * @pring: Pointer to driver SLI ring object.
8967 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
8968 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
8969 * iocb is posted to the response ring with the tag of the buffer.
8970 * This function searches the pring->postbufq list using the tag
8971 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
8972 * iocb. If the buffer is found then lpfc_dmabuf object of the
8973 * buffer is returned to the caller else NULL is returned.
8974 * This function is called with no lock held.
8976 struct lpfc_dmabuf
*
8977 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8980 struct lpfc_dmabuf
*mp
, *next_mp
;
8981 struct list_head
*slp
= &pring
->postbufq
;
8983 /* Search postbufq, from the beginning, looking for a match on tag */
8984 spin_lock_irq(&phba
->hbalock
);
8985 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
8986 if (mp
->buffer_tag
== tag
) {
8987 list_del_init(&mp
->list
);
8988 pring
->postbufq_cnt
--;
8989 spin_unlock_irq(&phba
->hbalock
);
8994 spin_unlock_irq(&phba
->hbalock
);
8995 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8996 "0402 Cannot find virtual addr for buffer tag on "
8997 "ring %d Data x%lx x%p x%p x%x\n",
8998 pring
->ringno
, (unsigned long) tag
,
8999 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9005 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9006 * @phba: Pointer to HBA context object.
9007 * @pring: Pointer to driver SLI ring object.
9008 * @phys: DMA address of the buffer.
9010 * This function searches the buffer list using the dma_address
9011 * of unsolicited event to find the driver's lpfc_dmabuf object
9012 * corresponding to the dma_address. The function returns the
9013 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9014 * This function is called by the ct and els unsolicited event
9015 * handlers to get the buffer associated with the unsolicited
9018 * This function is called with no lock held.
9020 struct lpfc_dmabuf
*
9021 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9024 struct lpfc_dmabuf
*mp
, *next_mp
;
9025 struct list_head
*slp
= &pring
->postbufq
;
9027 /* Search postbufq, from the beginning, looking for a match on phys */
9028 spin_lock_irq(&phba
->hbalock
);
9029 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9030 if (mp
->phys
== phys
) {
9031 list_del_init(&mp
->list
);
9032 pring
->postbufq_cnt
--;
9033 spin_unlock_irq(&phba
->hbalock
);
9038 spin_unlock_irq(&phba
->hbalock
);
9039 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9040 "0410 Cannot find virtual addr for mapped buf on "
9041 "ring %d Data x%llx x%p x%p x%x\n",
9042 pring
->ringno
, (unsigned long long)phys
,
9043 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9048 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9049 * @phba: Pointer to HBA context object.
9050 * @cmdiocb: Pointer to driver command iocb object.
9051 * @rspiocb: Pointer to driver response iocb object.
9053 * This function is the completion handler for the abort iocbs for
9054 * ELS commands. This function is called from the ELS ring event
9055 * handler with no lock held. This function frees memory resources
9056 * associated with the abort iocb.
9059 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9060 struct lpfc_iocbq
*rspiocb
)
9062 IOCB_t
*irsp
= &rspiocb
->iocb
;
9063 uint16_t abort_iotag
, abort_context
;
9064 struct lpfc_iocbq
*abort_iocb
= NULL
;
9066 if (irsp
->ulpStatus
) {
9069 * Assume that the port already completed and returned, or
9070 * will return the iocb. Just Log the message.
9072 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9073 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9075 spin_lock_irq(&phba
->hbalock
);
9076 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9077 if (abort_iotag
!= 0 &&
9078 abort_iotag
<= phba
->sli
.last_iotag
)
9080 phba
->sli
.iocbq_lookup
[abort_iotag
];
9082 /* For sli4 the abort_tag is the XRI,
9083 * so the abort routine puts the iotag of the iocb
9084 * being aborted in the context field of the abort
9087 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9089 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9090 "0327 Cannot abort els iocb %p "
9091 "with tag %x context %x, abort status %x, "
9093 abort_iocb
, abort_iotag
, abort_context
,
9094 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9096 spin_unlock_irq(&phba
->hbalock
);
9098 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9103 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9104 * @phba: Pointer to HBA context object.
9105 * @cmdiocb: Pointer to driver command iocb object.
9106 * @rspiocb: Pointer to driver response iocb object.
9108 * The function is called from SLI ring event handler with no
9109 * lock held. This function is the completion handler for ELS commands
9110 * which are aborted. The function frees memory resources used for
9111 * the aborted ELS commands.
9114 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9115 struct lpfc_iocbq
*rspiocb
)
9117 IOCB_t
*irsp
= &rspiocb
->iocb
;
9119 /* ELS cmd tag <ulpIoTag> completes */
9120 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9121 "0139 Ignoring ELS cmd tag x%x completion Data: "
9123 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9124 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9125 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9126 lpfc_ct_free_iocb(phba
, cmdiocb
);
9128 lpfc_els_free_iocb(phba
, cmdiocb
);
9133 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9134 * @phba: Pointer to HBA context object.
9135 * @pring: Pointer to driver SLI ring object.
9136 * @cmdiocb: Pointer to driver command iocb object.
9138 * This function issues an abort iocb for the provided command iocb down to
9139 * the port. Other than the case the outstanding command iocb is an abort
9140 * request, this function issues abort out unconditionally. This function is
9141 * called with hbalock held. The function returns 0 when it fails due to
9142 * memory allocation failure or when the command iocb is an abort request.
9145 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9146 struct lpfc_iocbq
*cmdiocb
)
9148 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9149 struct lpfc_iocbq
*abtsiocbp
;
9150 IOCB_t
*icmd
= NULL
;
9151 IOCB_t
*iabt
= NULL
;
9155 * There are certain command types we don't want to abort. And we
9156 * don't want to abort commands that are already in the process of
9159 icmd
= &cmdiocb
->iocb
;
9160 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9161 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9162 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9165 /* issue ABTS for this IOCB based on iotag */
9166 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9167 if (abtsiocbp
== NULL
)
9170 /* This signals the response to set the correct status
9171 * before calling the completion handler
9173 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9175 iabt
= &abtsiocbp
->iocb
;
9176 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9177 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9178 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9179 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9180 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9183 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9185 iabt
->ulpClass
= icmd
->ulpClass
;
9187 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9188 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9189 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9190 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9192 if (phba
->link_state
>= LPFC_LINK_UP
)
9193 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9195 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9197 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9199 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9200 "0339 Abort xri x%x, original iotag x%x, "
9201 "abort cmd iotag x%x\n",
9202 iabt
->un
.acxri
.abortIoTag
,
9203 iabt
->un
.acxri
.abortContextTag
,
9205 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
9208 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9211 * Caller to this routine should check for IOCB_ERROR
9212 * and handle it properly. This routine no longer removes
9213 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9219 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9220 * @phba: Pointer to HBA context object.
9221 * @pring: Pointer to driver SLI ring object.
9222 * @cmdiocb: Pointer to driver command iocb object.
9224 * This function issues an abort iocb for the provided command iocb. In case
9225 * of unloading, the abort iocb will not be issued to commands on the ELS
9226 * ring. Instead, the callback function shall be changed to those commands
9227 * so that nothing happens when them finishes. This function is called with
9228 * hbalock held. The function returns 0 when the command iocb is an abort
9232 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9233 struct lpfc_iocbq
*cmdiocb
)
9235 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9236 int retval
= IOCB_ERROR
;
9237 IOCB_t
*icmd
= NULL
;
9240 * There are certain command types we don't want to abort. And we
9241 * don't want to abort commands that are already in the process of
9244 icmd
= &cmdiocb
->iocb
;
9245 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9246 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9247 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9251 * If we're unloading, don't abort iocb on the ELS ring, but change
9252 * the callback so that nothing happens when it finishes.
9254 if ((vport
->load_flag
& FC_UNLOADING
) &&
9255 (pring
->ringno
== LPFC_ELS_RING
)) {
9256 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9257 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9259 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9260 goto abort_iotag_exit
;
9263 /* Now, we try to issue the abort to the cmdiocb out */
9264 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9268 * Caller to this routine should check for IOCB_ERROR
9269 * and handle it properly. This routine no longer removes
9270 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9276 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9277 * @phba: Pointer to HBA context object.
9278 * @pring: Pointer to driver SLI ring object.
9280 * This function aborts all iocbs in the given ring and frees all the iocb
9281 * objects in txq. This function issues abort iocbs unconditionally for all
9282 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9283 * to complete before the return of this function. The caller is not required
9284 * to hold any locks.
9287 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9289 LIST_HEAD(completions
);
9290 struct lpfc_iocbq
*iocb
, *next_iocb
;
9292 if (pring
->ringno
== LPFC_ELS_RING
)
9293 lpfc_fabric_abort_hba(phba
);
9295 spin_lock_irq(&phba
->hbalock
);
9297 /* Take off all the iocbs on txq for cancelling */
9298 list_splice_init(&pring
->txq
, &completions
);
9301 /* Next issue ABTS for everything on the txcmplq */
9302 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9303 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9305 spin_unlock_irq(&phba
->hbalock
);
9307 /* Cancel all the IOCBs from the completions list */
9308 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9313 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9314 * @phba: pointer to lpfc HBA data structure.
9316 * This routine will abort all pending and outstanding iocbs to an HBA.
9319 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9321 struct lpfc_sli
*psli
= &phba
->sli
;
9322 struct lpfc_sli_ring
*pring
;
9325 for (i
= 0; i
< psli
->num_rings
; i
++) {
9326 pring
= &psli
->ring
[i
];
9327 lpfc_sli_iocb_ring_abort(phba
, pring
);
9332 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9333 * @iocbq: Pointer to driver iocb object.
9334 * @vport: Pointer to driver virtual port object.
9335 * @tgt_id: SCSI ID of the target.
9336 * @lun_id: LUN ID of the scsi device.
9337 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9339 * This function acts as an iocb filter for functions which abort or count
9340 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9341 * 0 if the filtering criteria is met for the given iocb and will return
9342 * 1 if the filtering criteria is not met.
9343 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9344 * given iocb is for the SCSI device specified by vport, tgt_id and
9346 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9347 * given iocb is for the SCSI target specified by vport and tgt_id
9349 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9350 * given iocb is for the SCSI host associated with the given vport.
9351 * This function is called with no locks held.
9354 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9355 uint16_t tgt_id
, uint64_t lun_id
,
9356 lpfc_ctx_cmd ctx_cmd
)
9358 struct lpfc_scsi_buf
*lpfc_cmd
;
9361 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9364 if (iocbq
->vport
!= vport
)
9367 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9369 if (lpfc_cmd
->pCmd
== NULL
)
9374 if ((lpfc_cmd
->rdata
->pnode
) &&
9375 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9376 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9380 if ((lpfc_cmd
->rdata
->pnode
) &&
9381 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9388 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9397 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9398 * @vport: Pointer to virtual port.
9399 * @tgt_id: SCSI ID of the target.
9400 * @lun_id: LUN ID of the scsi device.
9401 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9403 * This function returns number of FCP commands pending for the vport.
9404 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9405 * commands pending on the vport associated with SCSI device specified
9406 * by tgt_id and lun_id parameters.
9407 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9408 * commands pending on the vport associated with SCSI target specified
9409 * by tgt_id parameter.
9410 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9411 * commands pending on the vport.
9412 * This function returns the number of iocbs which satisfy the filter.
9413 * This function is called without any lock held.
9416 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9417 lpfc_ctx_cmd ctx_cmd
)
9419 struct lpfc_hba
*phba
= vport
->phba
;
9420 struct lpfc_iocbq
*iocbq
;
9423 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9424 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9426 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9435 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9436 * @phba: Pointer to HBA context object
9437 * @cmdiocb: Pointer to command iocb object.
9438 * @rspiocb: Pointer to response iocb object.
9440 * This function is called when an aborted FCP iocb completes. This
9441 * function is called by the ring event handler with no lock held.
9442 * This function frees the iocb.
9445 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9446 struct lpfc_iocbq
*rspiocb
)
9448 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9449 "3096 ABORT_XRI_CN completing on xri x%x "
9450 "original iotag x%x, abort cmd iotag x%x "
9451 "status 0x%x, reason 0x%x\n",
9452 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9453 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9454 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9455 rspiocb
->iocb
.un
.ulpWord
[4]);
9456 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9461 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9462 * @vport: Pointer to virtual port.
9463 * @pring: Pointer to driver SLI ring object.
9464 * @tgt_id: SCSI ID of the target.
9465 * @lun_id: LUN ID of the scsi device.
9466 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9468 * This function sends an abort command for every SCSI command
9469 * associated with the given virtual port pending on the ring
9470 * filtered by lpfc_sli_validate_fcp_iocb function.
9471 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9472 * FCP iocbs associated with lun specified by tgt_id and lun_id
9474 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9475 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9476 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9477 * FCP iocbs associated with virtual port.
9478 * This function returns number of iocbs it failed to abort.
9479 * This function is called with no locks held.
9482 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9483 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9485 struct lpfc_hba
*phba
= vport
->phba
;
9486 struct lpfc_iocbq
*iocbq
;
9487 struct lpfc_iocbq
*abtsiocb
;
9489 int errcnt
= 0, ret_val
= 0;
9492 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9493 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9495 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9499 /* issue ABTS for this IOCB based on iotag */
9500 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9501 if (abtsiocb
== NULL
) {
9507 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9508 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9509 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9510 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9512 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9513 abtsiocb
->iocb
.ulpLe
= 1;
9514 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9515 abtsiocb
->vport
= phba
->pport
;
9517 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9518 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9519 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9520 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9522 if (lpfc_is_link_up(phba
))
9523 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9525 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
9527 /* Setup callback routine and issue the command. */
9528 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
9529 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9531 if (ret_val
== IOCB_ERROR
) {
9532 lpfc_sli_release_iocbq(phba
, abtsiocb
);
9542 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9543 * @phba: Pointer to HBA context object.
9544 * @cmdiocbq: Pointer to command iocb.
9545 * @rspiocbq: Pointer to response iocb.
9547 * This function is the completion handler for iocbs issued using
9548 * lpfc_sli_issue_iocb_wait function. This function is called by the
9549 * ring event handler function without any lock held. This function
9550 * can be called from both worker thread context and interrupt
9551 * context. This function also can be called from other thread which
9552 * cleans up the SLI layer objects.
9553 * This function copy the contents of the response iocb to the
9554 * response iocb memory object provided by the caller of
9555 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9556 * sleeps for the iocb completion.
9559 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
9560 struct lpfc_iocbq
*cmdiocbq
,
9561 struct lpfc_iocbq
*rspiocbq
)
9563 wait_queue_head_t
*pdone_q
;
9564 unsigned long iflags
;
9565 struct lpfc_scsi_buf
*lpfc_cmd
;
9567 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9568 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
9569 if (cmdiocbq
->context2
&& rspiocbq
)
9570 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
9571 &rspiocbq
->iocb
, sizeof(IOCB_t
));
9573 /* Set the exchange busy flag for task management commands */
9574 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
9575 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
9576 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
9578 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
9581 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
9584 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9589 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9590 * @phba: Pointer to HBA context object..
9591 * @piocbq: Pointer to command iocb.
9592 * @flag: Flag to test.
9594 * This routine grabs the hbalock and then test the iocb_flag to
9595 * see if the passed in flag is set.
9598 * 0 if flag is not set.
9601 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
9602 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
9604 unsigned long iflags
;
9607 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9608 ret
= piocbq
->iocb_flag
& flag
;
9609 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9615 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9616 * @phba: Pointer to HBA context object..
9617 * @pring: Pointer to sli ring.
9618 * @piocb: Pointer to command iocb.
9619 * @prspiocbq: Pointer to response iocb.
9620 * @timeout: Timeout in number of seconds.
9622 * This function issues the iocb to firmware and waits for the
9623 * iocb to complete. If the iocb command is not
9624 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9625 * Caller should not free the iocb resources if this function
9626 * returns IOCB_TIMEDOUT.
9627 * The function waits for the iocb completion using an
9628 * non-interruptible wait.
9629 * This function will sleep while waiting for iocb completion.
9630 * So, this function should not be called from any context which
9631 * does not allow sleeping. Due to the same reason, this function
9632 * cannot be called with interrupt disabled.
9633 * This function assumes that the iocb completions occur while
9634 * this function sleep. So, this function cannot be called from
9635 * the thread which process iocb completion for this ring.
9636 * This function clears the iocb_flag of the iocb object before
9637 * issuing the iocb and the iocb completion handler sets this
9638 * flag and wakes this thread when the iocb completes.
9639 * The contents of the response iocb will be copied to prspiocbq
9640 * by the completion handler when the command completes.
9641 * This function returns IOCB_SUCCESS when success.
9642 * This function is called with no lock held.
9645 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
9646 uint32_t ring_number
,
9647 struct lpfc_iocbq
*piocb
,
9648 struct lpfc_iocbq
*prspiocbq
,
9651 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9652 long timeleft
, timeout_req
= 0;
9653 int retval
= IOCB_SUCCESS
;
9655 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9657 * If the caller has provided a response iocbq buffer, then context2
9658 * is NULL or its an error.
9661 if (piocb
->context2
)
9663 piocb
->context2
= prspiocbq
;
9666 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
9667 piocb
->context_un
.wait_queue
= &done_q
;
9668 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
9670 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9671 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9673 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
9674 writel(creg_val
, phba
->HCregaddr
);
9675 readl(phba
->HCregaddr
); /* flush */
9678 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
9680 if (retval
== IOCB_SUCCESS
) {
9681 timeout_req
= timeout
* HZ
;
9682 timeleft
= wait_event_timeout(done_q
,
9683 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
9686 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
9687 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9688 "0331 IOCB wake signaled\n");
9689 } else if (timeleft
== 0) {
9690 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9691 "0338 IOCB wait timeout error - no "
9692 "wake response Data x%x\n", timeout
);
9693 retval
= IOCB_TIMEDOUT
;
9695 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9696 "0330 IOCB wake NOT set, "
9698 timeout
, (timeleft
/ jiffies
));
9699 retval
= IOCB_TIMEDOUT
;
9701 } else if (retval
== IOCB_BUSY
) {
9702 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9703 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
9704 phba
->iocb_cnt
, pring
->txq_cnt
, pring
->txcmplq_cnt
);
9707 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9708 "0332 IOCB wait issue failed, Data x%x\n",
9710 retval
= IOCB_ERROR
;
9713 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9714 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9716 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
9717 writel(creg_val
, phba
->HCregaddr
);
9718 readl(phba
->HCregaddr
); /* flush */
9722 piocb
->context2
= NULL
;
9724 piocb
->context_un
.wait_queue
= NULL
;
9725 piocb
->iocb_cmpl
= NULL
;
9730 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
9731 * @phba: Pointer to HBA context object.
9732 * @pmboxq: Pointer to driver mailbox object.
9733 * @timeout: Timeout in number of seconds.
9735 * This function issues the mailbox to firmware and waits for the
9736 * mailbox command to complete. If the mailbox command is not
9737 * completed within timeout seconds, it returns MBX_TIMEOUT.
9738 * The function waits for the mailbox completion using an
9739 * interruptible wait. If the thread is woken up due to a
9740 * signal, MBX_TIMEOUT error is returned to the caller. Caller
9741 * should not free the mailbox resources, if this function returns
9743 * This function will sleep while waiting for mailbox completion.
9744 * So, this function should not be called from any context which
9745 * does not allow sleeping. Due to the same reason, this function
9746 * cannot be called with interrupt disabled.
9747 * This function assumes that the mailbox completion occurs while
9748 * this function sleep. So, this function cannot be called from
9749 * the worker thread which processes mailbox completion.
9750 * This function is called in the context of HBA management
9752 * This function returns MBX_SUCCESS when successful.
9753 * This function is called with no lock held.
9756 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
9759 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9763 /* The caller must leave context1 empty. */
9764 if (pmboxq
->context1
)
9765 return MBX_NOT_FINISHED
;
9767 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
9768 /* setup wake call as IOCB callback */
9769 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
9770 /* setup context field to pass wait_queue pointer to wake function */
9771 pmboxq
->context1
= &done_q
;
9773 /* now issue the command */
9774 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
9775 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
9776 wait_event_interruptible_timeout(done_q
,
9777 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
9780 spin_lock_irqsave(&phba
->hbalock
, flag
);
9781 pmboxq
->context1
= NULL
;
9783 * if LPFC_MBX_WAKE flag is set the mailbox is completed
9784 * else do not free the resources.
9786 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
9787 retval
= MBX_SUCCESS
;
9788 lpfc_sli4_swap_str(phba
, pmboxq
);
9790 retval
= MBX_TIMEOUT
;
9791 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
9793 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
9800 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
9801 * @phba: Pointer to HBA context.
9803 * This function is called to shutdown the driver's mailbox sub-system.
9804 * It first marks the mailbox sub-system is in a block state to prevent
9805 * the asynchronous mailbox command from issued off the pending mailbox
9806 * command queue. If the mailbox command sub-system shutdown is due to
9807 * HBA error conditions such as EEH or ERATT, this routine shall invoke
9808 * the mailbox sub-system flush routine to forcefully bring down the
9809 * mailbox sub-system. Otherwise, if it is due to normal condition (such
9810 * as with offline or HBA function reset), this routine will wait for the
9811 * outstanding mailbox command to complete before invoking the mailbox
9812 * sub-system flush routine to gracefully bring down mailbox sub-system.
9815 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
9817 struct lpfc_sli
*psli
= &phba
->sli
;
9818 unsigned long timeout
;
9820 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
9821 spin_lock_irq(&phba
->hbalock
);
9822 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
9823 spin_unlock_irq(&phba
->hbalock
);
9825 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
9826 spin_lock_irq(&phba
->hbalock
);
9827 /* Determine how long we might wait for the active mailbox
9828 * command to be gracefully completed by firmware.
9830 if (phba
->sli
.mbox_active
)
9831 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
9832 phba
->sli
.mbox_active
) *
9834 spin_unlock_irq(&phba
->hbalock
);
9836 while (phba
->sli
.mbox_active
) {
9837 /* Check active mailbox complete status every 2ms */
9839 if (time_after(jiffies
, timeout
))
9840 /* Timeout, let the mailbox flush routine to
9841 * forcefully release active mailbox command
9846 lpfc_sli_mbox_sys_flush(phba
);
9850 * lpfc_sli_eratt_read - read sli-3 error attention events
9851 * @phba: Pointer to HBA context.
9853 * This function is called to read the SLI3 device error attention registers
9854 * for possible error attention events. The caller must hold the hostlock
9855 * with spin_lock_irq().
9857 * This function returns 1 when there is Error Attention in the Host Attention
9858 * Register and returns 0 otherwise.
9861 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
9865 /* Read chip Host Attention (HA) register */
9866 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
9869 if (ha_copy
& HA_ERATT
) {
9870 /* Read host status register to retrieve error event */
9871 if (lpfc_sli_read_hs(phba
))
9874 /* Check if there is a deferred error condition is active */
9875 if ((HS_FFER1
& phba
->work_hs
) &&
9876 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
9877 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
9878 phba
->hba_flag
|= DEFER_ERATT
;
9879 /* Clear all interrupt enable conditions */
9880 writel(0, phba
->HCregaddr
);
9881 readl(phba
->HCregaddr
);
9884 /* Set the driver HA work bitmap */
9885 phba
->work_ha
|= HA_ERATT
;
9886 /* Indicate polling handles this ERATT */
9887 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9893 /* Set the driver HS work bitmap */
9894 phba
->work_hs
|= UNPLUG_ERR
;
9895 /* Set the driver HA work bitmap */
9896 phba
->work_ha
|= HA_ERATT
;
9897 /* Indicate polling handles this ERATT */
9898 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9903 * lpfc_sli4_eratt_read - read sli-4 error attention events
9904 * @phba: Pointer to HBA context.
9906 * This function is called to read the SLI4 device error attention registers
9907 * for possible error attention events. The caller must hold the hostlock
9908 * with spin_lock_irq().
9910 * This function returns 1 when there is Error Attention in the Host Attention
9911 * Register and returns 0 otherwise.
9914 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
9916 uint32_t uerr_sta_hi
, uerr_sta_lo
;
9917 uint32_t if_type
, portsmphr
;
9918 struct lpfc_register portstat_reg
;
9921 * For now, use the SLI4 device internal unrecoverable error
9922 * registers for error attention. This can be changed later.
9924 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
9926 case LPFC_SLI_INTF_IF_TYPE_0
:
9927 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
9929 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
9931 phba
->work_hs
|= UNPLUG_ERR
;
9932 phba
->work_ha
|= HA_ERATT
;
9933 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9936 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
9937 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
9938 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9939 "1423 HBA Unrecoverable error: "
9940 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
9941 "ue_mask_lo_reg=0x%x, "
9942 "ue_mask_hi_reg=0x%x\n",
9943 uerr_sta_lo
, uerr_sta_hi
,
9944 phba
->sli4_hba
.ue_mask_lo
,
9945 phba
->sli4_hba
.ue_mask_hi
);
9946 phba
->work_status
[0] = uerr_sta_lo
;
9947 phba
->work_status
[1] = uerr_sta_hi
;
9948 phba
->work_ha
|= HA_ERATT
;
9949 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9953 case LPFC_SLI_INTF_IF_TYPE_2
:
9954 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
9955 &portstat_reg
.word0
) ||
9956 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
9958 phba
->work_hs
|= UNPLUG_ERR
;
9959 phba
->work_ha
|= HA_ERATT
;
9960 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9963 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
9964 phba
->work_status
[0] =
9965 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
9966 phba
->work_status
[1] =
9967 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
9968 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9969 "2885 Port Status Event: "
9970 "port status reg 0x%x, "
9971 "port smphr reg 0x%x, "
9972 "error 1=0x%x, error 2=0x%x\n",
9975 phba
->work_status
[0],
9976 phba
->work_status
[1]);
9977 phba
->work_ha
|= HA_ERATT
;
9978 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9982 case LPFC_SLI_INTF_IF_TYPE_1
:
9984 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9985 "2886 HBA Error Attention on unsupported "
9986 "if type %d.", if_type
);
9994 * lpfc_sli_check_eratt - check error attention events
9995 * @phba: Pointer to HBA context.
9997 * This function is called from timer soft interrupt context to check HBA's
9998 * error attention register bit for error attention events.
10000 * This function returns 1 when there is Error Attention in the Host Attention
10001 * Register and returns 0 otherwise.
10004 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10008 /* If somebody is waiting to handle an eratt, don't process it
10009 * here. The brdkill function will do this.
10011 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10014 /* Check if interrupt handler handles this ERATT */
10015 spin_lock_irq(&phba
->hbalock
);
10016 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10017 /* Interrupt handler has handled ERATT */
10018 spin_unlock_irq(&phba
->hbalock
);
10023 * If there is deferred error attention, do not check for error
10026 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10027 spin_unlock_irq(&phba
->hbalock
);
10031 /* If PCI channel is offline, don't process it */
10032 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10033 spin_unlock_irq(&phba
->hbalock
);
10037 switch (phba
->sli_rev
) {
10038 case LPFC_SLI_REV2
:
10039 case LPFC_SLI_REV3
:
10040 /* Read chip Host Attention (HA) register */
10041 ha_copy
= lpfc_sli_eratt_read(phba
);
10043 case LPFC_SLI_REV4
:
10044 /* Read device Uncoverable Error (UERR) registers */
10045 ha_copy
= lpfc_sli4_eratt_read(phba
);
10048 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10049 "0299 Invalid SLI revision (%d)\n",
10054 spin_unlock_irq(&phba
->hbalock
);
10060 * lpfc_intr_state_check - Check device state for interrupt handling
10061 * @phba: Pointer to HBA context.
10063 * This inline routine checks whether a device or its PCI slot is in a state
10064 * that the interrupt should be handled.
10066 * This function returns 0 if the device or the PCI slot is in a state that
10067 * interrupt should be handled, otherwise -EIO.
10070 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10072 /* If the pci channel is offline, ignore all the interrupts */
10073 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10076 /* Update device level interrupt statistics */
10077 phba
->sli
.slistat
.sli_intr
++;
10079 /* Ignore all interrupts during initialization. */
10080 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10087 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10088 * @irq: Interrupt number.
10089 * @dev_id: The device context pointer.
10091 * This function is directly called from the PCI layer as an interrupt
10092 * service routine when device with SLI-3 interface spec is enabled with
10093 * MSI-X multi-message interrupt mode and there are slow-path events in
10094 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10095 * interrupt mode, this function is called as part of the device-level
10096 * interrupt handler. When the PCI slot is in error recovery or the HBA
10097 * is undergoing initialization, the interrupt handler will not process
10098 * the interrupt. The link attention and ELS ring attention events are
10099 * handled by the worker thread. The interrupt handler signals the worker
10100 * thread and returns for these events. This function is called without
10101 * any lock held. It gets the hbalock to access and update SLI data
10104 * This function returns IRQ_HANDLED when interrupt is handled else it
10105 * returns IRQ_NONE.
10108 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10110 struct lpfc_hba
*phba
;
10111 uint32_t ha_copy
, hc_copy
;
10112 uint32_t work_ha_copy
;
10113 unsigned long status
;
10114 unsigned long iflag
;
10117 MAILBOX_t
*mbox
, *pmbox
;
10118 struct lpfc_vport
*vport
;
10119 struct lpfc_nodelist
*ndlp
;
10120 struct lpfc_dmabuf
*mp
;
10125 * Get the driver's phba structure from the dev_id and
10126 * assume the HBA is not interrupting.
10128 phba
= (struct lpfc_hba
*)dev_id
;
10130 if (unlikely(!phba
))
10134 * Stuff needs to be attented to when this function is invoked as an
10135 * individual interrupt handler in MSI-X multi-message interrupt mode
10137 if (phba
->intr_type
== MSIX
) {
10138 /* Check device state for handling interrupt */
10139 if (lpfc_intr_state_check(phba
))
10141 /* Need to read HA REG for slow-path events */
10142 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10143 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10145 /* If somebody is waiting to handle an eratt don't process it
10146 * here. The brdkill function will do this.
10148 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10149 ha_copy
&= ~HA_ERATT
;
10150 /* Check the need for handling ERATT in interrupt handler */
10151 if (ha_copy
& HA_ERATT
) {
10152 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10153 /* ERATT polling has handled ERATT */
10154 ha_copy
&= ~HA_ERATT
;
10156 /* Indicate interrupt handler handles ERATT */
10157 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10161 * If there is deferred error attention, do not check for any
10164 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10165 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10169 /* Clear up only attention source related to slow-path */
10170 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10173 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10174 HC_LAINT_ENA
| HC_ERINT_ENA
),
10176 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10178 writel(hc_copy
, phba
->HCregaddr
);
10179 readl(phba
->HAregaddr
); /* flush */
10180 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10182 ha_copy
= phba
->ha_copy
;
10184 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10186 if (work_ha_copy
) {
10187 if (work_ha_copy
& HA_LATT
) {
10188 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10190 * Turn off Link Attention interrupts
10191 * until CLEAR_LA done
10193 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10194 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10195 if (lpfc_readl(phba
->HCregaddr
, &control
))
10197 control
&= ~HC_LAINT_ENA
;
10198 writel(control
, phba
->HCregaddr
);
10199 readl(phba
->HCregaddr
); /* flush */
10200 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10203 work_ha_copy
&= ~HA_LATT
;
10206 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10208 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10209 * the only slow ring.
10211 status
= (work_ha_copy
&
10212 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10213 status
>>= (4*LPFC_ELS_RING
);
10214 if (status
& HA_RXMASK
) {
10215 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10216 if (lpfc_readl(phba
->HCregaddr
, &control
))
10219 lpfc_debugfs_slow_ring_trc(phba
,
10220 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10222 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10224 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10225 lpfc_debugfs_slow_ring_trc(phba
,
10226 "ISR Disable ring:"
10227 "pwork:x%x hawork:x%x wait:x%x",
10228 phba
->work_ha
, work_ha_copy
,
10229 (uint32_t)((unsigned long)
10230 &phba
->work_waitq
));
10233 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10234 writel(control
, phba
->HCregaddr
);
10235 readl(phba
->HCregaddr
); /* flush */
10238 lpfc_debugfs_slow_ring_trc(phba
,
10239 "ISR slow ring: pwork:"
10240 "x%x hawork:x%x wait:x%x",
10241 phba
->work_ha
, work_ha_copy
,
10242 (uint32_t)((unsigned long)
10243 &phba
->work_waitq
));
10245 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10248 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10249 if (work_ha_copy
& HA_ERATT
) {
10250 if (lpfc_sli_read_hs(phba
))
10253 * Check if there is a deferred error condition
10256 if ((HS_FFER1
& phba
->work_hs
) &&
10257 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10258 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10260 phba
->hba_flag
|= DEFER_ERATT
;
10261 /* Clear all interrupt enable conditions */
10262 writel(0, phba
->HCregaddr
);
10263 readl(phba
->HCregaddr
);
10267 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10268 pmb
= phba
->sli
.mbox_active
;
10269 pmbox
= &pmb
->u
.mb
;
10271 vport
= pmb
->vport
;
10273 /* First check out the status word */
10274 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10275 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10276 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10278 * Stray Mailbox Interrupt, mbxCommand <cmd>
10279 * mbxStatus <status>
10281 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10283 "(%d):0304 Stray Mailbox "
10284 "Interrupt mbxCommand x%x "
10286 (vport
? vport
->vpi
: 0),
10289 /* clear mailbox attention bit */
10290 work_ha_copy
&= ~HA_MBATT
;
10292 phba
->sli
.mbox_active
= NULL
;
10293 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10294 phba
->last_completion_time
= jiffies
;
10295 del_timer(&phba
->sli
.mbox_tmo
);
10296 if (pmb
->mbox_cmpl
) {
10297 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10299 if (pmb
->out_ext_byte_len
&&
10301 lpfc_sli_pcimem_bcopy(
10304 pmb
->out_ext_byte_len
);
10306 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10307 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10309 lpfc_debugfs_disc_trc(vport
,
10310 LPFC_DISC_TRC_MBOX_VPORT
,
10311 "MBOX dflt rpi: : "
10312 "status:x%x rpi:x%x",
10313 (uint32_t)pmbox
->mbxStatus
,
10314 pmbox
->un
.varWords
[0], 0);
10316 if (!pmbox
->mbxStatus
) {
10317 mp
= (struct lpfc_dmabuf
*)
10319 ndlp
= (struct lpfc_nodelist
*)
10322 /* Reg_LOGIN of dflt RPI was
10323 * successful. new lets get
10324 * rid of the RPI using the
10325 * same mbox buffer.
10327 lpfc_unreg_login(phba
,
10329 pmbox
->un
.varWords
[0],
10332 lpfc_mbx_cmpl_dflt_rpi
;
10333 pmb
->context1
= mp
;
10334 pmb
->context2
= ndlp
;
10335 pmb
->vport
= vport
;
10336 rc
= lpfc_sli_issue_mbox(phba
,
10339 if (rc
!= MBX_BUSY
)
10340 lpfc_printf_log(phba
,
10342 LOG_MBOX
| LOG_SLI
,
10343 "0350 rc should have"
10344 "been MBX_BUSY\n");
10345 if (rc
!= MBX_NOT_FINISHED
)
10346 goto send_current_mbox
;
10350 &phba
->pport
->work_port_lock
,
10352 phba
->pport
->work_port_events
&=
10354 spin_unlock_irqrestore(
10355 &phba
->pport
->work_port_lock
,
10357 lpfc_mbox_cmpl_put(phba
, pmb
);
10360 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10362 if ((work_ha_copy
& HA_MBATT
) &&
10363 (phba
->sli
.mbox_active
== NULL
)) {
10365 /* Process next mailbox command if there is one */
10367 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10369 } while (rc
== MBX_NOT_FINISHED
);
10370 if (rc
!= MBX_SUCCESS
)
10371 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10372 LOG_SLI
, "0349 rc should be "
10376 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10377 phba
->work_ha
|= work_ha_copy
;
10378 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10379 lpfc_worker_wake_up(phba
);
10381 return IRQ_HANDLED
;
10383 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10384 return IRQ_HANDLED
;
10386 } /* lpfc_sli_sp_intr_handler */
10389 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10390 * @irq: Interrupt number.
10391 * @dev_id: The device context pointer.
10393 * This function is directly called from the PCI layer as an interrupt
10394 * service routine when device with SLI-3 interface spec is enabled with
10395 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10396 * ring event in the HBA. However, when the device is enabled with either
10397 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10398 * device-level interrupt handler. When the PCI slot is in error recovery
10399 * or the HBA is undergoing initialization, the interrupt handler will not
10400 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10401 * the intrrupt context. This function is called without any lock held.
10402 * It gets the hbalock to access and update SLI data structures.
10404 * This function returns IRQ_HANDLED when interrupt is handled else it
10405 * returns IRQ_NONE.
10408 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10410 struct lpfc_hba
*phba
;
10412 unsigned long status
;
10413 unsigned long iflag
;
10415 /* Get the driver's phba structure from the dev_id and
10416 * assume the HBA is not interrupting.
10418 phba
= (struct lpfc_hba
*) dev_id
;
10420 if (unlikely(!phba
))
10424 * Stuff needs to be attented to when this function is invoked as an
10425 * individual interrupt handler in MSI-X multi-message interrupt mode
10427 if (phba
->intr_type
== MSIX
) {
10428 /* Check device state for handling interrupt */
10429 if (lpfc_intr_state_check(phba
))
10431 /* Need to read HA REG for FCP ring and other ring events */
10432 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10433 return IRQ_HANDLED
;
10434 /* Clear up only attention source related to fast-path */
10435 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10437 * If there is deferred error attention, do not check for
10440 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10441 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10444 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10446 readl(phba
->HAregaddr
); /* flush */
10447 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10449 ha_copy
= phba
->ha_copy
;
10452 * Process all events on FCP ring. Take the optimized path for FCP IO.
10454 ha_copy
&= ~(phba
->work_ha_mask
);
10456 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10457 status
>>= (4*LPFC_FCP_RING
);
10458 if (status
& HA_RXMASK
)
10459 lpfc_sli_handle_fast_ring_event(phba
,
10460 &phba
->sli
.ring
[LPFC_FCP_RING
],
10463 if (phba
->cfg_multi_ring_support
== 2) {
10465 * Process all events on extra ring. Take the optimized path
10466 * for extra ring IO.
10468 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10469 status
>>= (4*LPFC_EXTRA_RING
);
10470 if (status
& HA_RXMASK
) {
10471 lpfc_sli_handle_fast_ring_event(phba
,
10472 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
10476 return IRQ_HANDLED
;
10477 } /* lpfc_sli_fp_intr_handler */
10480 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10481 * @irq: Interrupt number.
10482 * @dev_id: The device context pointer.
10484 * This function is the HBA device-level interrupt handler to device with
10485 * SLI-3 interface spec, called from the PCI layer when either MSI or
10486 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10487 * requires driver attention. This function invokes the slow-path interrupt
10488 * attention handling function and fast-path interrupt attention handling
10489 * function in turn to process the relevant HBA attention events. This
10490 * function is called without any lock held. It gets the hbalock to access
10491 * and update SLI data structures.
10493 * This function returns IRQ_HANDLED when interrupt is handled, else it
10494 * returns IRQ_NONE.
10497 lpfc_sli_intr_handler(int irq
, void *dev_id
)
10499 struct lpfc_hba
*phba
;
10500 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10501 unsigned long status1
, status2
;
10505 * Get the driver's phba structure from the dev_id and
10506 * assume the HBA is not interrupting.
10508 phba
= (struct lpfc_hba
*) dev_id
;
10510 if (unlikely(!phba
))
10513 /* Check device state for handling interrupt */
10514 if (lpfc_intr_state_check(phba
))
10517 spin_lock(&phba
->hbalock
);
10518 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
10519 spin_unlock(&phba
->hbalock
);
10520 return IRQ_HANDLED
;
10523 if (unlikely(!phba
->ha_copy
)) {
10524 spin_unlock(&phba
->hbalock
);
10526 } else if (phba
->ha_copy
& HA_ERATT
) {
10527 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10528 /* ERATT polling has handled ERATT */
10529 phba
->ha_copy
&= ~HA_ERATT
;
10531 /* Indicate interrupt handler handles ERATT */
10532 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10536 * If there is deferred error attention, do not check for any interrupt.
10538 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10539 spin_unlock(&phba
->hbalock
);
10543 /* Clear attention sources except link and error attentions */
10544 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
10545 spin_unlock(&phba
->hbalock
);
10546 return IRQ_HANDLED
;
10548 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
10549 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
10551 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
10552 writel(hc_copy
, phba
->HCregaddr
);
10553 readl(phba
->HAregaddr
); /* flush */
10554 spin_unlock(&phba
->hbalock
);
10557 * Invokes slow-path host attention interrupt handling as appropriate.
10560 /* status of events with mailbox and link attention */
10561 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
10563 /* status of events with ELS ring */
10564 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10565 status2
>>= (4*LPFC_ELS_RING
);
10567 if (status1
|| (status2
& HA_RXMASK
))
10568 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
10570 sp_irq_rc
= IRQ_NONE
;
10573 * Invoke fast-path host attention interrupt handling as appropriate.
10576 /* status of events with FCP ring */
10577 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10578 status1
>>= (4*LPFC_FCP_RING
);
10580 /* status of events with extra ring */
10581 if (phba
->cfg_multi_ring_support
== 2) {
10582 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10583 status2
>>= (4*LPFC_EXTRA_RING
);
10587 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
10588 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
10590 fp_irq_rc
= IRQ_NONE
;
10592 /* Return device-level interrupt handling status */
10593 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
10594 } /* lpfc_sli_intr_handler */
10597 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10598 * @phba: pointer to lpfc hba data structure.
10600 * This routine is invoked by the worker thread to process all the pending
10601 * SLI4 FCP abort XRI events.
10603 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
10605 struct lpfc_cq_event
*cq_event
;
10607 /* First, declare the fcp xri abort event has been handled */
10608 spin_lock_irq(&phba
->hbalock
);
10609 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
10610 spin_unlock_irq(&phba
->hbalock
);
10611 /* Now, handle all the fcp xri abort events */
10612 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
10613 /* Get the first event from the head of the event queue */
10614 spin_lock_irq(&phba
->hbalock
);
10615 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10616 cq_event
, struct lpfc_cq_event
, list
);
10617 spin_unlock_irq(&phba
->hbalock
);
10618 /* Notify aborted XRI for FCP work queue */
10619 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10620 /* Free the event processed back to the free pool */
10621 lpfc_sli4_cq_event_release(phba
, cq_event
);
10626 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10627 * @phba: pointer to lpfc hba data structure.
10629 * This routine is invoked by the worker thread to process all the pending
10630 * SLI4 els abort xri events.
10632 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
10634 struct lpfc_cq_event
*cq_event
;
10636 /* First, declare the els xri abort event has been handled */
10637 spin_lock_irq(&phba
->hbalock
);
10638 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
10639 spin_unlock_irq(&phba
->hbalock
);
10640 /* Now, handle all the els xri abort events */
10641 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
10642 /* Get the first event from the head of the event queue */
10643 spin_lock_irq(&phba
->hbalock
);
10644 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10645 cq_event
, struct lpfc_cq_event
, list
);
10646 spin_unlock_irq(&phba
->hbalock
);
10647 /* Notify aborted XRI for ELS work queue */
10648 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10649 /* Free the event processed back to the free pool */
10650 lpfc_sli4_cq_event_release(phba
, cq_event
);
10655 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10656 * @phba: pointer to lpfc hba data structure
10657 * @pIocbIn: pointer to the rspiocbq
10658 * @pIocbOut: pointer to the cmdiocbq
10659 * @wcqe: pointer to the complete wcqe
10661 * This routine transfers the fields of a command iocbq to a response iocbq
10662 * by copying all the IOCB fields from command iocbq and transferring the
10663 * completion status information from the complete wcqe.
10666 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
10667 struct lpfc_iocbq
*pIocbIn
,
10668 struct lpfc_iocbq
*pIocbOut
,
10669 struct lpfc_wcqe_complete
*wcqe
)
10671 unsigned long iflags
;
10673 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
10675 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
10676 sizeof(struct lpfc_iocbq
) - offset
);
10677 /* Map WCQE parameters into irspiocb parameters */
10678 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
10679 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
10680 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
10681 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
10682 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
10683 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
10684 wcqe
->total_data_placed
;
10686 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10688 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10689 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
10692 /* Convert BG errors for completion status */
10693 if (status
== CQE_STATUS_DI_ERROR
) {
10694 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
10696 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
10697 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
10699 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
10701 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
10702 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
10703 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10704 BGS_GUARD_ERR_MASK
;
10705 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
10706 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10707 BGS_APPTAG_ERR_MASK
;
10708 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
10709 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10710 BGS_REFTAG_ERR_MASK
;
10712 /* Check to see if there was any good data before the error */
10713 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
10714 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10715 BGS_HI_WATER_MARK_PRESENT_MASK
;
10716 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
10717 wcqe
->total_data_placed
;
10721 * Set ALL the error bits to indicate we don't know what
10722 * type of error it is.
10724 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
10725 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10726 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
10727 BGS_GUARD_ERR_MASK
);
10730 /* Pick up HBA exchange busy condition */
10731 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
10732 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10733 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
10734 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10739 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
10740 * @phba: Pointer to HBA context object.
10741 * @wcqe: Pointer to work-queue completion queue entry.
10743 * This routine handles an ELS work-queue completion event and construct
10744 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
10745 * discovery engine to handle.
10747 * Return: Pointer to the receive IOCBQ, NULL otherwise.
10749 static struct lpfc_iocbq
*
10750 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
10751 struct lpfc_iocbq
*irspiocbq
)
10753 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10754 struct lpfc_iocbq
*cmdiocbq
;
10755 struct lpfc_wcqe_complete
*wcqe
;
10756 unsigned long iflags
;
10758 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
10759 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10760 pring
->stats
.iocb_event
++;
10761 /* Look up the ELS command IOCB and create pseudo response IOCB */
10762 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
10763 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
10764 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10766 if (unlikely(!cmdiocbq
)) {
10767 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10768 "0386 ELS complete with no corresponding "
10769 "cmdiocb: iotag (%d)\n",
10770 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
10771 lpfc_sli_release_iocbq(phba
, irspiocbq
);
10775 /* Fake the irspiocbq and copy necessary response information */
10776 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
10782 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
10783 * @phba: Pointer to HBA context object.
10784 * @cqe: Pointer to mailbox completion queue entry.
10786 * This routine process a mailbox completion queue entry with asynchrous
10789 * Return: true if work posted to worker thread, otherwise false.
10792 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
10794 struct lpfc_cq_event
*cq_event
;
10795 unsigned long iflags
;
10797 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10798 "0392 Async Event: word0:x%x, word1:x%x, "
10799 "word2:x%x, word3:x%x\n", mcqe
->word0
,
10800 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
10802 /* Allocate a new internal CQ_EVENT entry */
10803 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
10805 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10806 "0394 Failed to allocate CQ_EVENT entry\n");
10810 /* Move the CQE into an asynchronous event entry */
10811 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
10812 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10813 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
10814 /* Set the async event flag */
10815 phba
->hba_flag
|= ASYNC_EVENT
;
10816 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10822 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
10823 * @phba: Pointer to HBA context object.
10824 * @cqe: Pointer to mailbox completion queue entry.
10826 * This routine process a mailbox completion queue entry with mailbox
10827 * completion event.
10829 * Return: true if work posted to worker thread, otherwise false.
10832 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
10834 uint32_t mcqe_status
;
10835 MAILBOX_t
*mbox
, *pmbox
;
10836 struct lpfc_mqe
*mqe
;
10837 struct lpfc_vport
*vport
;
10838 struct lpfc_nodelist
*ndlp
;
10839 struct lpfc_dmabuf
*mp
;
10840 unsigned long iflags
;
10842 bool workposted
= false;
10845 /* If not a mailbox complete MCQE, out by checking mailbox consume */
10846 if (!bf_get(lpfc_trailer_completed
, mcqe
))
10847 goto out_no_mqe_complete
;
10849 /* Get the reference to the active mbox command */
10850 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10851 pmb
= phba
->sli
.mbox_active
;
10852 if (unlikely(!pmb
)) {
10853 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
10854 "1832 No pending MBOX command to handle\n");
10855 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10856 goto out_no_mqe_complete
;
10858 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10860 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
10862 vport
= pmb
->vport
;
10864 /* Reset heartbeat timer */
10865 phba
->last_completion_time
= jiffies
;
10866 del_timer(&phba
->sli
.mbox_tmo
);
10868 /* Move mbox data to caller's mailbox region, do endian swapping */
10869 if (pmb
->mbox_cmpl
&& mbox
)
10870 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
10873 * For mcqe errors, conditionally move a modified error code to
10874 * the mbox so that the error will not be missed.
10876 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
10877 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
10878 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
10879 bf_set(lpfc_mqe_status
, mqe
,
10880 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
10882 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10883 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10884 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
10885 "MBOX dflt rpi: status:x%x rpi:x%x",
10887 pmbox
->un
.varWords
[0], 0);
10888 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
10889 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
10890 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
10891 /* Reg_LOGIN of dflt RPI was successful. Now lets get
10892 * RID of the PPI using the same mbox buffer.
10894 lpfc_unreg_login(phba
, vport
->vpi
,
10895 pmbox
->un
.varWords
[0], pmb
);
10896 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
10897 pmb
->context1
= mp
;
10898 pmb
->context2
= ndlp
;
10899 pmb
->vport
= vport
;
10900 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
10901 if (rc
!= MBX_BUSY
)
10902 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10903 LOG_SLI
, "0385 rc should "
10904 "have been MBX_BUSY\n");
10905 if (rc
!= MBX_NOT_FINISHED
)
10906 goto send_current_mbox
;
10909 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
10910 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
10911 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
10913 /* There is mailbox completion work to do */
10914 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10915 __lpfc_mbox_cmpl_put(phba
, pmb
);
10916 phba
->work_ha
|= HA_MBATT
;
10917 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10921 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10922 /* Release the mailbox command posting token */
10923 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
10924 /* Setting active mailbox pointer need to be in sync to flag clear */
10925 phba
->sli
.mbox_active
= NULL
;
10926 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10927 /* Wake up worker thread to post the next pending mailbox command */
10928 lpfc_worker_wake_up(phba
);
10929 out_no_mqe_complete
:
10930 if (bf_get(lpfc_trailer_consumed
, mcqe
))
10931 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
10936 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
10937 * @phba: Pointer to HBA context object.
10938 * @cqe: Pointer to mailbox completion queue entry.
10940 * This routine process a mailbox completion queue entry, it invokes the
10941 * proper mailbox complete handling or asynchrous event handling routine
10942 * according to the MCQE's async bit.
10944 * Return: true if work posted to worker thread, otherwise false.
10947 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
10949 struct lpfc_mcqe mcqe
;
10952 /* Copy the mailbox MCQE and convert endian order as needed */
10953 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
10955 /* Invoke the proper event handling routine */
10956 if (!bf_get(lpfc_trailer_async
, &mcqe
))
10957 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
10959 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
10964 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
10965 * @phba: Pointer to HBA context object.
10966 * @wcqe: Pointer to work-queue completion queue entry.
10968 * This routine handles an ELS work-queue completion event.
10970 * Return: true if work posted to worker thread, otherwise false.
10973 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
10974 struct lpfc_wcqe_complete
*wcqe
)
10976 struct lpfc_iocbq
*irspiocbq
;
10977 unsigned long iflags
;
10978 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
10980 /* Get an irspiocbq for later ELS response processing use */
10981 irspiocbq
= lpfc_sli_get_iocbq(phba
);
10983 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10984 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
10985 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
10986 pring
->txq_cnt
, phba
->iocb_cnt
,
10987 phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
,
10988 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
);
10992 /* Save off the slow-path queue event for work thread to process */
10993 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
10994 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10995 list_add_tail(&irspiocbq
->cq_event
.list
,
10996 &phba
->sli4_hba
.sp_queue_event
);
10997 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
10998 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11004 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11005 * @phba: Pointer to HBA context object.
11006 * @wcqe: Pointer to work-queue completion queue entry.
11008 * This routine handles slow-path WQ entry comsumed event by invoking the
11009 * proper WQ release routine to the slow-path WQ.
11012 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
11013 struct lpfc_wcqe_release
*wcqe
)
11015 /* sanity check on queue memory */
11016 if (unlikely(!phba
->sli4_hba
.els_wq
))
11018 /* Check for the slow-path ELS work queue */
11019 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
11020 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
11021 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11023 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11024 "2579 Slow-path wqe consume event carries "
11025 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11026 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
11027 phba
->sli4_hba
.els_wq
->queue_id
);
11031 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11032 * @phba: Pointer to HBA context object.
11033 * @cq: Pointer to a WQ completion queue.
11034 * @wcqe: Pointer to work-queue completion queue entry.
11036 * This routine handles an XRI abort event.
11038 * Return: true if work posted to worker thread, otherwise false.
11041 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
11042 struct lpfc_queue
*cq
,
11043 struct sli4_wcqe_xri_aborted
*wcqe
)
11045 bool workposted
= false;
11046 struct lpfc_cq_event
*cq_event
;
11047 unsigned long iflags
;
11049 /* Allocate a new internal CQ_EVENT entry */
11050 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11052 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11053 "0602 Failed to allocate CQ_EVENT entry\n");
11057 /* Move the CQE into the proper xri abort event list */
11058 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11059 switch (cq
->subtype
) {
11061 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11062 list_add_tail(&cq_event
->list
,
11063 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11064 /* Set the fcp xri abort event flag */
11065 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11066 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11070 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11071 list_add_tail(&cq_event
->list
,
11072 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11073 /* Set the els xri abort event flag */
11074 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11075 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11079 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11080 "0603 Invalid work queue CQE subtype (x%x)\n",
11082 workposted
= false;
11089 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11090 * @phba: Pointer to HBA context object.
11091 * @rcqe: Pointer to receive-queue completion queue entry.
11093 * This routine process a receive-queue completion queue entry.
11095 * Return: true if work posted to worker thread, otherwise false.
11098 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11100 bool workposted
= false;
11101 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11102 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11103 struct hbq_dmabuf
*dma_buf
;
11104 uint32_t status
, rq_id
;
11105 unsigned long iflags
;
11107 /* sanity check on queue memory */
11108 if (unlikely(!hrq
) || unlikely(!drq
))
11111 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11112 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11114 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11115 if (rq_id
!= hrq
->queue_id
)
11118 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11120 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11121 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11122 "2537 Receive Frame Truncated!!\n");
11123 case FC_STATUS_RQ_SUCCESS
:
11124 lpfc_sli4_rq_release(hrq
, drq
);
11125 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11126 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11128 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11131 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11132 /* save off the frame for the word thread to process */
11133 list_add_tail(&dma_buf
->cq_event
.list
,
11134 &phba
->sli4_hba
.sp_queue_event
);
11135 /* Frame received */
11136 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11137 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11140 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11141 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11142 /* Post more buffers if possible */
11143 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11144 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11145 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11154 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11155 * @phba: Pointer to HBA context object.
11156 * @cq: Pointer to the completion queue.
11157 * @wcqe: Pointer to a completion queue entry.
11159 * This routine process a slow-path work-queue or receive queue completion queue
11162 * Return: true if work posted to worker thread, otherwise false.
11165 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11166 struct lpfc_cqe
*cqe
)
11168 struct lpfc_cqe cqevt
;
11169 bool workposted
= false;
11171 /* Copy the work queue CQE and convert endian order if needed */
11172 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11174 /* Check and process for different type of WCQE and dispatch */
11175 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11176 case CQE_CODE_COMPL_WQE
:
11177 /* Process the WQ/RQ complete event */
11178 phba
->last_completion_time
= jiffies
;
11179 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
11180 (struct lpfc_wcqe_complete
*)&cqevt
);
11182 case CQE_CODE_RELEASE_WQE
:
11183 /* Process the WQ release event */
11184 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11185 (struct lpfc_wcqe_release
*)&cqevt
);
11187 case CQE_CODE_XRI_ABORTED
:
11188 /* Process the WQ XRI abort event */
11189 phba
->last_completion_time
= jiffies
;
11190 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11191 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11193 case CQE_CODE_RECEIVE
:
11194 case CQE_CODE_RECEIVE_V1
:
11195 /* Process the RQ event */
11196 phba
->last_completion_time
= jiffies
;
11197 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11198 (struct lpfc_rcqe
*)&cqevt
);
11201 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11202 "0388 Not a valid WCQE code: x%x\n",
11203 bf_get(lpfc_cqe_code
, &cqevt
));
11210 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11211 * @phba: Pointer to HBA context object.
11212 * @eqe: Pointer to fast-path event queue entry.
11214 * This routine process a event queue entry from the slow-path event queue.
11215 * It will check the MajorCode and MinorCode to determine this is for a
11216 * completion event on a completion queue, if not, an error shall be logged
11217 * and just return. Otherwise, it will get to the corresponding completion
11218 * queue and process all the entries on that completion queue, rearm the
11219 * completion queue, and then return.
11223 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
11225 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
11226 struct lpfc_cqe
*cqe
;
11227 bool workposted
= false;
11231 if (bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0) {
11232 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11233 "0359 Not a valid slow-path completion "
11234 "event: majorcode=x%x, minorcode=x%x\n",
11235 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11236 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11240 /* Get the reference to the corresponding CQ */
11241 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11243 /* Search for completion queue pointer matching this cqid */
11244 speq
= phba
->sli4_hba
.sp_eq
;
11245 /* sanity check on queue memory */
11246 if (unlikely(!speq
))
11248 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11249 if (childq
->queue_id
== cqid
) {
11254 if (unlikely(!cq
)) {
11255 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11256 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11257 "0365 Slow-path CQ identifier "
11258 "(%d) does not exist\n", cqid
);
11262 /* Process all the entries to the CQ */
11263 switch (cq
->type
) {
11265 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11266 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11267 if (!(++ecount
% cq
->entry_repost
))
11268 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11272 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11273 if (cq
->subtype
== LPFC_FCP
)
11274 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11277 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11279 if (!(++ecount
% cq
->entry_repost
))
11280 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11284 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11285 "0370 Invalid completion queue type (%d)\n",
11290 /* Catch the no cq entry condition, log an error */
11291 if (unlikely(ecount
== 0))
11292 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11293 "0371 No entry from the CQ: identifier "
11294 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11296 /* In any case, flash and re-arm the RCQ */
11297 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11299 /* wake up worker thread if there are works to be done */
11301 lpfc_worker_wake_up(phba
);
11305 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11306 * @eqe: Pointer to fast-path completion queue entry.
11308 * This routine process a fast-path work queue completion entry from fast-path
11309 * event queue for FCP command response completion.
11312 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
11313 struct lpfc_wcqe_complete
*wcqe
)
11315 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
11316 struct lpfc_iocbq
*cmdiocbq
;
11317 struct lpfc_iocbq irspiocbq
;
11318 unsigned long iflags
;
11320 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11321 pring
->stats
.iocb_event
++;
11322 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11324 /* Check for response status */
11325 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11326 /* If resource errors reported from HBA, reduce queue
11327 * depth of the SCSI device.
11329 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11330 IOSTAT_LOCAL_REJECT
) &&
11331 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
11332 phba
->lpfc_rampdown_queue_depth(phba
);
11334 /* Log the error status */
11335 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11336 "0373 FCP complete error: status=x%x, "
11337 "hw_status=x%x, total_data_specified=%d, "
11338 "parameter=x%x, word3=x%x\n",
11339 bf_get(lpfc_wcqe_c_status
, wcqe
),
11340 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11341 wcqe
->total_data_placed
, wcqe
->parameter
,
11345 /* Look up the FCP command IOCB and create pseudo response IOCB */
11346 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11347 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11348 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11349 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11350 if (unlikely(!cmdiocbq
)) {
11351 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11352 "0374 FCP complete with no corresponding "
11353 "cmdiocb: iotag (%d)\n",
11354 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11357 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11358 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11359 "0375 FCP cmdiocb not callback function "
11361 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11365 /* Fake the irspiocb and copy necessary response information */
11366 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11368 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11369 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11370 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11371 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11374 /* Pass the cmd_iocb and the rsp state to the upper layer */
11375 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11379 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11380 * @phba: Pointer to HBA context object.
11381 * @cq: Pointer to completion queue.
11382 * @wcqe: Pointer to work-queue completion queue entry.
11384 * This routine handles an fast-path WQ entry comsumed event by invoking the
11385 * proper WQ release routine to the slow-path WQ.
11388 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11389 struct lpfc_wcqe_release
*wcqe
)
11391 struct lpfc_queue
*childwq
;
11392 bool wqid_matched
= false;
11395 /* Check for fast-path FCP work queue release */
11396 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11397 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11398 if (childwq
->queue_id
== fcp_wqid
) {
11399 lpfc_sli4_wq_release(childwq
,
11400 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11401 wqid_matched
= true;
11405 /* Report warning log message if no match found */
11406 if (wqid_matched
!= true)
11407 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11408 "2580 Fast-path wqe consume event carries "
11409 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11413 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11414 * @cq: Pointer to the completion queue.
11415 * @eqe: Pointer to fast-path completion queue entry.
11417 * This routine process a fast-path work queue completion entry from fast-path
11418 * event queue for FCP command response completion.
11421 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11422 struct lpfc_cqe
*cqe
)
11424 struct lpfc_wcqe_release wcqe
;
11425 bool workposted
= false;
11427 /* Copy the work queue CQE and convert endian order if needed */
11428 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
11430 /* Check and process for different type of WCQE and dispatch */
11431 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
11432 case CQE_CODE_COMPL_WQE
:
11433 /* Process the WQ complete event */
11434 phba
->last_completion_time
= jiffies
;
11435 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
11436 (struct lpfc_wcqe_complete
*)&wcqe
);
11438 case CQE_CODE_RELEASE_WQE
:
11439 /* Process the WQ release event */
11440 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
11441 (struct lpfc_wcqe_release
*)&wcqe
);
11443 case CQE_CODE_XRI_ABORTED
:
11444 /* Process the WQ XRI abort event */
11445 phba
->last_completion_time
= jiffies
;
11446 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11447 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
11450 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11451 "0144 Not a valid WCQE code: x%x\n",
11452 bf_get(lpfc_wcqe_c_code
, &wcqe
));
11459 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
11460 * @phba: Pointer to HBA context object.
11461 * @eqe: Pointer to fast-path event queue entry.
11463 * This routine process a event queue entry from the fast-path event queue.
11464 * It will check the MajorCode and MinorCode to determine this is for a
11465 * completion event on a completion queue, if not, an error shall be logged
11466 * and just return. Otherwise, it will get to the corresponding completion
11467 * queue and process all the entries on the completion queue, rearm the
11468 * completion queue, and then return.
11471 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11472 uint32_t fcp_cqidx
)
11474 struct lpfc_queue
*cq
;
11475 struct lpfc_cqe
*cqe
;
11476 bool workposted
= false;
11480 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
11481 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11482 "0366 Not a valid fast-path completion "
11483 "event: majorcode=x%x, minorcode=x%x\n",
11484 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11485 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11489 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
11490 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11491 "3146 Fast-path completion queues "
11492 "does not exist\n");
11495 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
11496 if (unlikely(!cq
)) {
11497 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11498 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11499 "0367 Fast-path completion queue "
11500 "(%d) does not exist\n", fcp_cqidx
);
11504 /* Get the reference to the corresponding CQ */
11505 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11506 if (unlikely(cqid
!= cq
->queue_id
)) {
11507 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11508 "0368 Miss-matched fast-path completion "
11509 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11510 cqid
, cq
->queue_id
);
11514 /* Process all the entries to the CQ */
11515 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11516 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
11517 if (!(++ecount
% cq
->entry_repost
))
11518 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11521 /* Catch the no cq entry condition */
11522 if (unlikely(ecount
== 0))
11523 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11524 "0369 No entry from fast-path completion "
11525 "queue fcpcqid=%d\n", cq
->queue_id
);
11527 /* In any case, flash and re-arm the CQ */
11528 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11530 /* wake up worker thread if there are works to be done */
11532 lpfc_worker_wake_up(phba
);
11536 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
11538 struct lpfc_eqe
*eqe
;
11540 /* walk all the EQ entries and drop on the floor */
11541 while ((eqe
= lpfc_sli4_eq_get(eq
)))
11544 /* Clear and re-arm the EQ */
11545 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
11549 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
11550 * @irq: Interrupt number.
11551 * @dev_id: The device context pointer.
11553 * This function is directly called from the PCI layer as an interrupt
11554 * service routine when device with SLI-4 interface spec is enabled with
11555 * MSI-X multi-message interrupt mode and there are slow-path events in
11556 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11557 * interrupt mode, this function is called as part of the device-level
11558 * interrupt handler. When the PCI slot is in error recovery or the HBA is
11559 * undergoing initialization, the interrupt handler will not process the
11560 * interrupt. The link attention and ELS ring attention events are handled
11561 * by the worker thread. The interrupt handler signals the worker thread
11562 * and returns for these events. This function is called without any lock
11563 * held. It gets the hbalock to access and update SLI data structures.
11565 * This function returns IRQ_HANDLED when interrupt is handled else it
11566 * returns IRQ_NONE.
11569 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
11571 struct lpfc_hba
*phba
;
11572 struct lpfc_queue
*speq
;
11573 struct lpfc_eqe
*eqe
;
11574 unsigned long iflag
;
11578 * Get the driver's phba structure from the dev_id
11580 phba
= (struct lpfc_hba
*)dev_id
;
11582 if (unlikely(!phba
))
11585 /* Get to the EQ struct associated with this vector */
11586 speq
= phba
->sli4_hba
.sp_eq
;
11587 if (unlikely(!speq
))
11590 /* Check device state for handling interrupt */
11591 if (unlikely(lpfc_intr_state_check(phba
))) {
11592 /* Check again for link_state with lock held */
11593 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11594 if (phba
->link_state
< LPFC_LINK_DOWN
)
11595 /* Flush, clear interrupt, and rearm the EQ */
11596 lpfc_sli4_eq_flush(phba
, speq
);
11597 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11602 * Process all the event on FCP slow-path EQ
11604 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
11605 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
11606 if (!(++ecount
% speq
->entry_repost
))
11607 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
11610 /* Always clear and re-arm the slow-path EQ */
11611 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
11613 /* Catch the no cq entry condition */
11614 if (unlikely(ecount
== 0)) {
11615 if (phba
->intr_type
== MSIX
)
11616 /* MSI-X treated interrupt served as no EQ share INT */
11617 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11618 "0357 MSI-X interrupt with no EQE\n");
11620 /* Non MSI-X treated on interrupt as EQ share INT */
11624 return IRQ_HANDLED
;
11625 } /* lpfc_sli4_sp_intr_handler */
11628 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
11629 * @irq: Interrupt number.
11630 * @dev_id: The device context pointer.
11632 * This function is directly called from the PCI layer as an interrupt
11633 * service routine when device with SLI-4 interface spec is enabled with
11634 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11635 * ring event in the HBA. However, when the device is enabled with either
11636 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11637 * device-level interrupt handler. When the PCI slot is in error recovery
11638 * or the HBA is undergoing initialization, the interrupt handler will not
11639 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11640 * the intrrupt context. This function is called without any lock held.
11641 * It gets the hbalock to access and update SLI data structures. Note that,
11642 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11643 * equal to that of FCP CQ index.
11645 * This function returns IRQ_HANDLED when interrupt is handled else it
11646 * returns IRQ_NONE.
11649 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
11651 struct lpfc_hba
*phba
;
11652 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
11653 struct lpfc_queue
*fpeq
;
11654 struct lpfc_eqe
*eqe
;
11655 unsigned long iflag
;
11657 uint32_t fcp_eqidx
;
11659 /* Get the driver's phba structure from the dev_id */
11660 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
11661 phba
= fcp_eq_hdl
->phba
;
11662 fcp_eqidx
= fcp_eq_hdl
->idx
;
11664 if (unlikely(!phba
))
11666 if (unlikely(!phba
->sli4_hba
.fp_eq
))
11669 /* Get to the EQ struct associated with this vector */
11670 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
11671 if (unlikely(!fpeq
))
11674 /* Check device state for handling interrupt */
11675 if (unlikely(lpfc_intr_state_check(phba
))) {
11676 /* Check again for link_state with lock held */
11677 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11678 if (phba
->link_state
< LPFC_LINK_DOWN
)
11679 /* Flush, clear interrupt, and rearm the EQ */
11680 lpfc_sli4_eq_flush(phba
, fpeq
);
11681 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11686 * Process all the event on FCP fast-path EQ
11688 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
11689 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
11690 if (!(++ecount
% fpeq
->entry_repost
))
11691 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
11694 /* Always clear and re-arm the fast-path EQ */
11695 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
11697 if (unlikely(ecount
== 0)) {
11698 if (phba
->intr_type
== MSIX
)
11699 /* MSI-X treated interrupt served as no EQ share INT */
11700 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11701 "0358 MSI-X interrupt with no EQE\n");
11703 /* Non MSI-X treated on interrupt as EQ share INT */
11707 return IRQ_HANDLED
;
11708 } /* lpfc_sli4_fp_intr_handler */
11711 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11712 * @irq: Interrupt number.
11713 * @dev_id: The device context pointer.
11715 * This function is the device-level interrupt handler to device with SLI-4
11716 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11717 * interrupt mode is enabled and there is an event in the HBA which requires
11718 * driver attention. This function invokes the slow-path interrupt attention
11719 * handling function and fast-path interrupt attention handling function in
11720 * turn to process the relevant HBA attention events. This function is called
11721 * without any lock held. It gets the hbalock to access and update SLI data
11724 * This function returns IRQ_HANDLED when interrupt is handled, else it
11725 * returns IRQ_NONE.
11728 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
11730 struct lpfc_hba
*phba
;
11731 irqreturn_t sp_irq_rc
, fp_irq_rc
;
11732 bool fp_handled
= false;
11733 uint32_t fcp_eqidx
;
11735 /* Get the driver's phba structure from the dev_id */
11736 phba
= (struct lpfc_hba
*)dev_id
;
11738 if (unlikely(!phba
))
11742 * Invokes slow-path host attention interrupt handling as appropriate.
11744 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
11747 * Invoke fast-path host attention interrupt handling as appropriate.
11749 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
11750 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
11751 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
11752 if (fp_irq_rc
== IRQ_HANDLED
)
11753 fp_handled
|= true;
11756 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
11757 } /* lpfc_sli4_intr_handler */
11760 * lpfc_sli4_queue_free - free a queue structure and associated memory
11761 * @queue: The queue structure to free.
11763 * This function frees a queue structure and the DMAable memory used for
11764 * the host resident queue. This function must be called after destroying the
11765 * queue on the HBA.
11768 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
11770 struct lpfc_dmabuf
*dmabuf
;
11775 while (!list_empty(&queue
->page_list
)) {
11776 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
11778 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
11779 dmabuf
->virt
, dmabuf
->phys
);
11787 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
11788 * @phba: The HBA that this queue is being created on.
11789 * @entry_size: The size of each queue entry for this queue.
11790 * @entry count: The number of entries that this queue will handle.
11792 * This function allocates a queue structure and the DMAable memory used for
11793 * the host resident queue. This function must be called before creating the
11794 * queue on the HBA.
11796 struct lpfc_queue
*
11797 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
11798 uint32_t entry_count
)
11800 struct lpfc_queue
*queue
;
11801 struct lpfc_dmabuf
*dmabuf
;
11802 int x
, total_qe_count
;
11804 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11806 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11807 hw_page_size
= SLI4_PAGE_SIZE
;
11809 queue
= kzalloc(sizeof(struct lpfc_queue
) +
11810 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
11813 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
11814 hw_page_size
))/hw_page_size
;
11815 INIT_LIST_HEAD(&queue
->list
);
11816 INIT_LIST_HEAD(&queue
->page_list
);
11817 INIT_LIST_HEAD(&queue
->child_list
);
11818 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
11819 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
11822 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
11823 hw_page_size
, &dmabuf
->phys
,
11825 if (!dmabuf
->virt
) {
11829 memset(dmabuf
->virt
, 0, hw_page_size
);
11830 dmabuf
->buffer_tag
= x
;
11831 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
11832 /* initialize queue's entry array */
11833 dma_pointer
= dmabuf
->virt
;
11834 for (; total_qe_count
< entry_count
&&
11835 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
11836 total_qe_count
++, dma_pointer
+= entry_size
) {
11837 queue
->qe
[total_qe_count
].address
= dma_pointer
;
11840 queue
->entry_size
= entry_size
;
11841 queue
->entry_count
= entry_count
;
11844 * entry_repost is calculated based on the number of entries in the
11845 * queue. This works out except for RQs. If buffers are NOT initially
11846 * posted for every RQE, entry_repost should be adjusted accordingly.
11848 queue
->entry_repost
= (entry_count
>> 3);
11849 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
11850 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
11851 queue
->phba
= phba
;
11855 lpfc_sli4_queue_free(queue
);
11860 * lpfc_eq_create - Create an Event Queue on the HBA
11861 * @phba: HBA structure that indicates port to create a queue on.
11862 * @eq: The queue structure to use to create the event queue.
11863 * @imax: The maximum interrupt per second limit.
11865 * This function creates an event queue, as detailed in @eq, on a port,
11866 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
11868 * The @phba struct is used to send mailbox command to HBA. The @eq struct
11869 * is used to get the entry count and entry size that are necessary to
11870 * determine the number of pages to allocate and use for this queue. This
11871 * function will send the EQ_CREATE mailbox command to the HBA to setup the
11872 * event queue. This function is asynchronous and will wait for the mailbox
11873 * command to finish before continuing.
11875 * On success this function will return a zero. If unable to allocate enough
11876 * memory this function will return -ENOMEM. If the queue create mailbox command
11877 * fails this function will return -ENXIO.
11880 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
11882 struct lpfc_mbx_eq_create
*eq_create
;
11883 LPFC_MBOXQ_t
*mbox
;
11884 int rc
, length
, status
= 0;
11885 struct lpfc_dmabuf
*dmabuf
;
11886 uint32_t shdr_status
, shdr_add_status
;
11887 union lpfc_sli4_cfg_shdr
*shdr
;
11889 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11891 /* sanity check on queue memory */
11894 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11895 hw_page_size
= SLI4_PAGE_SIZE
;
11897 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11900 length
= (sizeof(struct lpfc_mbx_eq_create
) -
11901 sizeof(struct lpfc_sli4_cfg_mhdr
));
11902 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
11903 LPFC_MBOX_OPCODE_EQ_CREATE
,
11904 length
, LPFC_SLI4_MBX_EMBED
);
11905 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
11906 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
11908 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
11910 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
11911 /* Calculate delay multiper from maximum interrupt per second */
11912 dmult
= LPFC_DMULT_CONST
/imax
- 1;
11913 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
11915 switch (eq
->entry_count
) {
11917 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11918 "0360 Unsupported EQ count. (%d)\n",
11920 if (eq
->entry_count
< 256)
11922 /* otherwise default to smallest count (drop through) */
11924 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11928 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11932 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11936 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11940 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11944 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
11945 memset(dmabuf
->virt
, 0, hw_page_size
);
11946 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
11947 putPaddrLow(dmabuf
->phys
);
11948 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
11949 putPaddrHigh(dmabuf
->phys
);
11951 mbox
->vport
= phba
->pport
;
11952 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11953 mbox
->context1
= NULL
;
11954 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
11955 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
11956 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11957 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11958 if (shdr_status
|| shdr_add_status
|| rc
) {
11959 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11960 "2500 EQ_CREATE mailbox failed with "
11961 "status x%x add_status x%x, mbx status x%x\n",
11962 shdr_status
, shdr_add_status
, rc
);
11965 eq
->type
= LPFC_EQ
;
11966 eq
->subtype
= LPFC_NONE
;
11967 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
11968 if (eq
->queue_id
== 0xFFFF)
11970 eq
->host_index
= 0;
11973 mempool_free(mbox
, phba
->mbox_mem_pool
);
11978 * lpfc_cq_create - Create a Completion Queue on the HBA
11979 * @phba: HBA structure that indicates port to create a queue on.
11980 * @cq: The queue structure to use to create the completion queue.
11981 * @eq: The event queue to bind this completion queue to.
11983 * This function creates a completion queue, as detailed in @wq, on a port,
11984 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
11986 * The @phba struct is used to send mailbox command to HBA. The @cq struct
11987 * is used to get the entry count and entry size that are necessary to
11988 * determine the number of pages to allocate and use for this queue. The @eq
11989 * is used to indicate which event queue to bind this completion queue to. This
11990 * function will send the CQ_CREATE mailbox command to the HBA to setup the
11991 * completion queue. This function is asynchronous and will wait for the mailbox
11992 * command to finish before continuing.
11994 * On success this function will return a zero. If unable to allocate enough
11995 * memory this function will return -ENOMEM. If the queue create mailbox command
11996 * fails this function will return -ENXIO.
11999 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12000 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
12002 struct lpfc_mbx_cq_create
*cq_create
;
12003 struct lpfc_dmabuf
*dmabuf
;
12004 LPFC_MBOXQ_t
*mbox
;
12005 int rc
, length
, status
= 0;
12006 uint32_t shdr_status
, shdr_add_status
;
12007 union lpfc_sli4_cfg_shdr
*shdr
;
12008 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12010 /* sanity check on queue memory */
12013 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12014 hw_page_size
= SLI4_PAGE_SIZE
;
12016 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12019 length
= (sizeof(struct lpfc_mbx_cq_create
) -
12020 sizeof(struct lpfc_sli4_cfg_mhdr
));
12021 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12022 LPFC_MBOX_OPCODE_CQ_CREATE
,
12023 length
, LPFC_SLI4_MBX_EMBED
);
12024 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
12025 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
12026 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
12028 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
12029 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
12030 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12031 phba
->sli4_hba
.pc_sli4_params
.cqv
);
12032 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
12033 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12034 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
12035 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
12038 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
12041 switch (cq
->entry_count
) {
12043 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12044 "0361 Unsupported CQ count. (%d)\n",
12046 if (cq
->entry_count
< 256)
12048 /* otherwise default to smallest count (drop through) */
12050 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12054 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12058 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12062 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12063 memset(dmabuf
->virt
, 0, hw_page_size
);
12064 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12065 putPaddrLow(dmabuf
->phys
);
12066 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12067 putPaddrHigh(dmabuf
->phys
);
12069 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12071 /* The IOCTL status is embedded in the mailbox subheader. */
12072 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12073 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12074 if (shdr_status
|| shdr_add_status
|| rc
) {
12075 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12076 "2501 CQ_CREATE mailbox failed with "
12077 "status x%x add_status x%x, mbx status x%x\n",
12078 shdr_status
, shdr_add_status
, rc
);
12082 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12083 if (cq
->queue_id
== 0xFFFF) {
12087 /* link the cq onto the parent eq child list */
12088 list_add_tail(&cq
->list
, &eq
->child_list
);
12089 /* Set up completion queue's type and subtype */
12091 cq
->subtype
= subtype
;
12092 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12093 cq
->assoc_qid
= eq
->queue_id
;
12094 cq
->host_index
= 0;
12098 mempool_free(mbox
, phba
->mbox_mem_pool
);
12103 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12104 * @phba: HBA structure that indicates port to create a queue on.
12105 * @mq: The queue structure to use to create the mailbox queue.
12106 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12107 * @cq: The completion queue to associate with this cq.
12109 * This function provides failback (fb) functionality when the
12110 * mq_create_ext fails on older FW generations. It's purpose is identical
12111 * to mq_create_ext otherwise.
12113 * This routine cannot fail as all attributes were previously accessed and
12114 * initialized in mq_create_ext.
12117 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12118 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12120 struct lpfc_mbx_mq_create
*mq_create
;
12121 struct lpfc_dmabuf
*dmabuf
;
12124 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12125 sizeof(struct lpfc_sli4_cfg_mhdr
));
12126 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12127 LPFC_MBOX_OPCODE_MQ_CREATE
,
12128 length
, LPFC_SLI4_MBX_EMBED
);
12129 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12130 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12132 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12134 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12135 switch (mq
->entry_count
) {
12137 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12138 LPFC_MQ_RING_SIZE_16
);
12141 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12142 LPFC_MQ_RING_SIZE_32
);
12145 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12146 LPFC_MQ_RING_SIZE_64
);
12149 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12150 LPFC_MQ_RING_SIZE_128
);
12153 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12154 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12155 putPaddrLow(dmabuf
->phys
);
12156 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12157 putPaddrHigh(dmabuf
->phys
);
12162 * lpfc_mq_create - Create a mailbox Queue on the HBA
12163 * @phba: HBA structure that indicates port to create a queue on.
12164 * @mq: The queue structure to use to create the mailbox queue.
12165 * @cq: The completion queue to associate with this cq.
12166 * @subtype: The queue's subtype.
12168 * This function creates a mailbox queue, as detailed in @mq, on a port,
12169 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12171 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12172 * is used to get the entry count and entry size that are necessary to
12173 * determine the number of pages to allocate and use for this queue. This
12174 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12175 * mailbox queue. This function is asynchronous and will wait for the mailbox
12176 * command to finish before continuing.
12178 * On success this function will return a zero. If unable to allocate enough
12179 * memory this function will return -ENOMEM. If the queue create mailbox command
12180 * fails this function will return -ENXIO.
12183 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12184 struct lpfc_queue
*cq
, uint32_t subtype
)
12186 struct lpfc_mbx_mq_create
*mq_create
;
12187 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12188 struct lpfc_dmabuf
*dmabuf
;
12189 LPFC_MBOXQ_t
*mbox
;
12190 int rc
, length
, status
= 0;
12191 uint32_t shdr_status
, shdr_add_status
;
12192 union lpfc_sli4_cfg_shdr
*shdr
;
12193 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12195 /* sanity check on queue memory */
12198 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12199 hw_page_size
= SLI4_PAGE_SIZE
;
12201 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12204 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12205 sizeof(struct lpfc_sli4_cfg_mhdr
));
12206 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12207 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12208 length
, LPFC_SLI4_MBX_EMBED
);
12210 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12211 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12212 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12213 &mq_create_ext
->u
.request
, mq
->page_count
);
12214 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12215 &mq_create_ext
->u
.request
, 1);
12216 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12217 &mq_create_ext
->u
.request
, 1);
12218 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12219 &mq_create_ext
->u
.request
, 1);
12220 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12221 &mq_create_ext
->u
.request
, 1);
12222 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12223 &mq_create_ext
->u
.request
, 1);
12224 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12225 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12226 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12227 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12228 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12231 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12233 switch (mq
->entry_count
) {
12235 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12236 "0362 Unsupported MQ count. (%d)\n",
12238 if (mq
->entry_count
< 16)
12240 /* otherwise default to smallest count (drop through) */
12242 bf_set(lpfc_mq_context_ring_size
,
12243 &mq_create_ext
->u
.request
.context
,
12244 LPFC_MQ_RING_SIZE_16
);
12247 bf_set(lpfc_mq_context_ring_size
,
12248 &mq_create_ext
->u
.request
.context
,
12249 LPFC_MQ_RING_SIZE_32
);
12252 bf_set(lpfc_mq_context_ring_size
,
12253 &mq_create_ext
->u
.request
.context
,
12254 LPFC_MQ_RING_SIZE_64
);
12257 bf_set(lpfc_mq_context_ring_size
,
12258 &mq_create_ext
->u
.request
.context
,
12259 LPFC_MQ_RING_SIZE_128
);
12262 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12263 memset(dmabuf
->virt
, 0, hw_page_size
);
12264 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12265 putPaddrLow(dmabuf
->phys
);
12266 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12267 putPaddrHigh(dmabuf
->phys
);
12269 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12270 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12271 &mq_create_ext
->u
.response
);
12272 if (rc
!= MBX_SUCCESS
) {
12273 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12274 "2795 MQ_CREATE_EXT failed with "
12275 "status x%x. Failback to MQ_CREATE.\n",
12277 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12278 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12279 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12280 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12281 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12282 &mq_create
->u
.response
);
12285 /* The IOCTL status is embedded in the mailbox subheader. */
12286 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12287 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12288 if (shdr_status
|| shdr_add_status
|| rc
) {
12289 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12290 "2502 MQ_CREATE mailbox failed with "
12291 "status x%x add_status x%x, mbx status x%x\n",
12292 shdr_status
, shdr_add_status
, rc
);
12296 if (mq
->queue_id
== 0xFFFF) {
12300 mq
->type
= LPFC_MQ
;
12301 mq
->assoc_qid
= cq
->queue_id
;
12302 mq
->subtype
= subtype
;
12303 mq
->host_index
= 0;
12306 /* link the mq onto the parent cq child list */
12307 list_add_tail(&mq
->list
, &cq
->child_list
);
12309 mempool_free(mbox
, phba
->mbox_mem_pool
);
12314 * lpfc_wq_create - Create a Work Queue on the HBA
12315 * @phba: HBA structure that indicates port to create a queue on.
12316 * @wq: The queue structure to use to create the work queue.
12317 * @cq: The completion queue to bind this work queue to.
12318 * @subtype: The subtype of the work queue indicating its functionality.
12320 * This function creates a work queue, as detailed in @wq, on a port, described
12321 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12323 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12324 * is used to get the entry count and entry size that are necessary to
12325 * determine the number of pages to allocate and use for this queue. The @cq
12326 * is used to indicate which completion queue to bind this work queue to. This
12327 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12328 * work queue. This function is asynchronous and will wait for the mailbox
12329 * command to finish before continuing.
12331 * On success this function will return a zero. If unable to allocate enough
12332 * memory this function will return -ENOMEM. If the queue create mailbox command
12333 * fails this function will return -ENXIO.
12336 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12337 struct lpfc_queue
*cq
, uint32_t subtype
)
12339 struct lpfc_mbx_wq_create
*wq_create
;
12340 struct lpfc_dmabuf
*dmabuf
;
12341 LPFC_MBOXQ_t
*mbox
;
12342 int rc
, length
, status
= 0;
12343 uint32_t shdr_status
, shdr_add_status
;
12344 union lpfc_sli4_cfg_shdr
*shdr
;
12345 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12346 struct dma_address
*page
;
12348 /* sanity check on queue memory */
12351 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12352 hw_page_size
= SLI4_PAGE_SIZE
;
12354 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12357 length
= (sizeof(struct lpfc_mbx_wq_create
) -
12358 sizeof(struct lpfc_sli4_cfg_mhdr
));
12359 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12360 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
12361 length
, LPFC_SLI4_MBX_EMBED
);
12362 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
12363 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
12364 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
12366 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
12368 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12369 phba
->sli4_hba
.pc_sli4_params
.wqv
);
12370 if (phba
->sli4_hba
.pc_sli4_params
.wqv
== LPFC_Q_CREATE_VERSION_1
) {
12371 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
12373 switch (wq
->entry_size
) {
12376 bf_set(lpfc_mbx_wq_create_wqe_size
,
12377 &wq_create
->u
.request_1
,
12378 LPFC_WQ_WQE_SIZE_64
);
12381 bf_set(lpfc_mbx_wq_create_wqe_size
,
12382 &wq_create
->u
.request_1
,
12383 LPFC_WQ_WQE_SIZE_128
);
12386 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
12387 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12388 page
= wq_create
->u
.request_1
.page
;
12390 page
= wq_create
->u
.request
.page
;
12392 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
12393 memset(dmabuf
->virt
, 0, hw_page_size
);
12394 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
12395 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
12397 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12398 /* The IOCTL status is embedded in the mailbox subheader. */
12399 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12400 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12401 if (shdr_status
|| shdr_add_status
|| rc
) {
12402 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12403 "2503 WQ_CREATE mailbox failed with "
12404 "status x%x add_status x%x, mbx status x%x\n",
12405 shdr_status
, shdr_add_status
, rc
);
12409 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
12410 if (wq
->queue_id
== 0xFFFF) {
12414 wq
->type
= LPFC_WQ
;
12415 wq
->assoc_qid
= cq
->queue_id
;
12416 wq
->subtype
= subtype
;
12417 wq
->host_index
= 0;
12419 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
12421 /* link the wq onto the parent cq child list */
12422 list_add_tail(&wq
->list
, &cq
->child_list
);
12424 mempool_free(mbox
, phba
->mbox_mem_pool
);
12429 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12430 * @phba: HBA structure that indicates port to create a queue on.
12431 * @rq: The queue structure to use for the receive queue.
12432 * @qno: The associated HBQ number
12435 * For SLI4 we need to adjust the RQ repost value based on
12436 * the number of buffers that are initially posted to the RQ.
12439 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
12443 /* sanity check on queue memory */
12446 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
12448 /* Recalc repost for RQs based on buffers initially posted */
12450 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
12451 cnt
= LPFC_QUEUE_MIN_REPOST
;
12453 rq
->entry_repost
= cnt
;
12457 * lpfc_rq_create - Create a Receive Queue on the HBA
12458 * @phba: HBA structure that indicates port to create a queue on.
12459 * @hrq: The queue structure to use to create the header receive queue.
12460 * @drq: The queue structure to use to create the data receive queue.
12461 * @cq: The completion queue to bind this work queue to.
12463 * This function creates a receive buffer queue pair , as detailed in @hrq and
12464 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12467 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12468 * struct is used to get the entry count that is necessary to determine the
12469 * number of pages to use for this queue. The @cq is used to indicate which
12470 * completion queue to bind received buffers that are posted to these queues to.
12471 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12472 * receive queue pair. This function is asynchronous and will wait for the
12473 * mailbox command to finish before continuing.
12475 * On success this function will return a zero. If unable to allocate enough
12476 * memory this function will return -ENOMEM. If the queue create mailbox command
12477 * fails this function will return -ENXIO.
12480 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12481 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
12483 struct lpfc_mbx_rq_create
*rq_create
;
12484 struct lpfc_dmabuf
*dmabuf
;
12485 LPFC_MBOXQ_t
*mbox
;
12486 int rc
, length
, status
= 0;
12487 uint32_t shdr_status
, shdr_add_status
;
12488 union lpfc_sli4_cfg_shdr
*shdr
;
12489 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12491 /* sanity check on queue memory */
12492 if (!hrq
|| !drq
|| !cq
)
12494 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12495 hw_page_size
= SLI4_PAGE_SIZE
;
12497 if (hrq
->entry_count
!= drq
->entry_count
)
12499 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12502 length
= (sizeof(struct lpfc_mbx_rq_create
) -
12503 sizeof(struct lpfc_sli4_cfg_mhdr
));
12504 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12505 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12506 length
, LPFC_SLI4_MBX_EMBED
);
12507 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
12508 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12509 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12510 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12511 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12512 bf_set(lpfc_rq_context_rqe_count_1
,
12513 &rq_create
->u
.request
.context
,
12515 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
12516 bf_set(lpfc_rq_context_rqe_size
,
12517 &rq_create
->u
.request
.context
,
12519 bf_set(lpfc_rq_context_page_size
,
12520 &rq_create
->u
.request
.context
,
12521 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12523 switch (hrq
->entry_count
) {
12525 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12526 "2535 Unsupported RQ count. (%d)\n",
12528 if (hrq
->entry_count
< 512)
12530 /* otherwise default to smallest count (drop through) */
12532 bf_set(lpfc_rq_context_rqe_count
,
12533 &rq_create
->u
.request
.context
,
12534 LPFC_RQ_RING_SIZE_512
);
12537 bf_set(lpfc_rq_context_rqe_count
,
12538 &rq_create
->u
.request
.context
,
12539 LPFC_RQ_RING_SIZE_1024
);
12542 bf_set(lpfc_rq_context_rqe_count
,
12543 &rq_create
->u
.request
.context
,
12544 LPFC_RQ_RING_SIZE_2048
);
12547 bf_set(lpfc_rq_context_rqe_count
,
12548 &rq_create
->u
.request
.context
,
12549 LPFC_RQ_RING_SIZE_4096
);
12552 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12553 LPFC_HDR_BUF_SIZE
);
12555 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12557 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12559 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
12560 memset(dmabuf
->virt
, 0, hw_page_size
);
12561 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12562 putPaddrLow(dmabuf
->phys
);
12563 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12564 putPaddrHigh(dmabuf
->phys
);
12566 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12567 /* The IOCTL status is embedded in the mailbox subheader. */
12568 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12569 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12570 if (shdr_status
|| shdr_add_status
|| rc
) {
12571 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12572 "2504 RQ_CREATE mailbox failed with "
12573 "status x%x add_status x%x, mbx status x%x\n",
12574 shdr_status
, shdr_add_status
, rc
);
12578 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12579 if (hrq
->queue_id
== 0xFFFF) {
12583 hrq
->type
= LPFC_HRQ
;
12584 hrq
->assoc_qid
= cq
->queue_id
;
12585 hrq
->subtype
= subtype
;
12586 hrq
->host_index
= 0;
12587 hrq
->hba_index
= 0;
12589 /* now create the data queue */
12590 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12591 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12592 length
, LPFC_SLI4_MBX_EMBED
);
12593 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12594 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12595 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12596 bf_set(lpfc_rq_context_rqe_count_1
,
12597 &rq_create
->u
.request
.context
, hrq
->entry_count
);
12598 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
12599 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
12601 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
12602 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12604 switch (drq
->entry_count
) {
12606 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12607 "2536 Unsupported RQ count. (%d)\n",
12609 if (drq
->entry_count
< 512)
12611 /* otherwise default to smallest count (drop through) */
12613 bf_set(lpfc_rq_context_rqe_count
,
12614 &rq_create
->u
.request
.context
,
12615 LPFC_RQ_RING_SIZE_512
);
12618 bf_set(lpfc_rq_context_rqe_count
,
12619 &rq_create
->u
.request
.context
,
12620 LPFC_RQ_RING_SIZE_1024
);
12623 bf_set(lpfc_rq_context_rqe_count
,
12624 &rq_create
->u
.request
.context
,
12625 LPFC_RQ_RING_SIZE_2048
);
12628 bf_set(lpfc_rq_context_rqe_count
,
12629 &rq_create
->u
.request
.context
,
12630 LPFC_RQ_RING_SIZE_4096
);
12633 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12634 LPFC_DATA_BUF_SIZE
);
12636 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12638 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12640 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
12641 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12642 putPaddrLow(dmabuf
->phys
);
12643 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12644 putPaddrHigh(dmabuf
->phys
);
12646 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12647 /* The IOCTL status is embedded in the mailbox subheader. */
12648 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12649 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12650 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12651 if (shdr_status
|| shdr_add_status
|| rc
) {
12655 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12656 if (drq
->queue_id
== 0xFFFF) {
12660 drq
->type
= LPFC_DRQ
;
12661 drq
->assoc_qid
= cq
->queue_id
;
12662 drq
->subtype
= subtype
;
12663 drq
->host_index
= 0;
12664 drq
->hba_index
= 0;
12666 /* link the header and data RQs onto the parent cq child list */
12667 list_add_tail(&hrq
->list
, &cq
->child_list
);
12668 list_add_tail(&drq
->list
, &cq
->child_list
);
12671 mempool_free(mbox
, phba
->mbox_mem_pool
);
12676 * lpfc_eq_destroy - Destroy an event Queue on the HBA
12677 * @eq: The queue structure associated with the queue to destroy.
12679 * This function destroys a queue, as detailed in @eq by sending an mailbox
12680 * command, specific to the type of queue, to the HBA.
12682 * The @eq struct is used to get the queue ID of the queue to destroy.
12684 * On success this function will return a zero. If the queue destroy mailbox
12685 * command fails this function will return -ENXIO.
12688 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12690 LPFC_MBOXQ_t
*mbox
;
12691 int rc
, length
, status
= 0;
12692 uint32_t shdr_status
, shdr_add_status
;
12693 union lpfc_sli4_cfg_shdr
*shdr
;
12695 /* sanity check on queue memory */
12698 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12701 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
12702 sizeof(struct lpfc_sli4_cfg_mhdr
));
12703 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12704 LPFC_MBOX_OPCODE_EQ_DESTROY
,
12705 length
, LPFC_SLI4_MBX_EMBED
);
12706 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
12708 mbox
->vport
= eq
->phba
->pport
;
12709 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12711 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
12712 /* The IOCTL status is embedded in the mailbox subheader. */
12713 shdr
= (union lpfc_sli4_cfg_shdr
*)
12714 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
12715 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12716 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12717 if (shdr_status
|| shdr_add_status
|| rc
) {
12718 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12719 "2505 EQ_DESTROY mailbox failed with "
12720 "status x%x add_status x%x, mbx status x%x\n",
12721 shdr_status
, shdr_add_status
, rc
);
12725 /* Remove eq from any list */
12726 list_del_init(&eq
->list
);
12727 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
12732 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
12733 * @cq: The queue structure associated with the queue to destroy.
12735 * This function destroys a queue, as detailed in @cq by sending an mailbox
12736 * command, specific to the type of queue, to the HBA.
12738 * The @cq struct is used to get the queue ID of the queue to destroy.
12740 * On success this function will return a zero. If the queue destroy mailbox
12741 * command fails this function will return -ENXIO.
12744 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
12746 LPFC_MBOXQ_t
*mbox
;
12747 int rc
, length
, status
= 0;
12748 uint32_t shdr_status
, shdr_add_status
;
12749 union lpfc_sli4_cfg_shdr
*shdr
;
12751 /* sanity check on queue memory */
12754 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12757 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
12758 sizeof(struct lpfc_sli4_cfg_mhdr
));
12759 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12760 LPFC_MBOX_OPCODE_CQ_DESTROY
,
12761 length
, LPFC_SLI4_MBX_EMBED
);
12762 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
12764 mbox
->vport
= cq
->phba
->pport
;
12765 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12766 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
12767 /* The IOCTL status is embedded in the mailbox subheader. */
12768 shdr
= (union lpfc_sli4_cfg_shdr
*)
12769 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
12770 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12771 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12772 if (shdr_status
|| shdr_add_status
|| rc
) {
12773 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12774 "2506 CQ_DESTROY mailbox failed with "
12775 "status x%x add_status x%x, mbx status x%x\n",
12776 shdr_status
, shdr_add_status
, rc
);
12779 /* Remove cq from any list */
12780 list_del_init(&cq
->list
);
12781 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
12786 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
12787 * @qm: The queue structure associated with the queue to destroy.
12789 * This function destroys a queue, as detailed in @mq by sending an mailbox
12790 * command, specific to the type of queue, to the HBA.
12792 * The @mq struct is used to get the queue ID of the queue to destroy.
12794 * On success this function will return a zero. If the queue destroy mailbox
12795 * command fails this function will return -ENXIO.
12798 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
12800 LPFC_MBOXQ_t
*mbox
;
12801 int rc
, length
, status
= 0;
12802 uint32_t shdr_status
, shdr_add_status
;
12803 union lpfc_sli4_cfg_shdr
*shdr
;
12805 /* sanity check on queue memory */
12808 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12811 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
12812 sizeof(struct lpfc_sli4_cfg_mhdr
));
12813 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12814 LPFC_MBOX_OPCODE_MQ_DESTROY
,
12815 length
, LPFC_SLI4_MBX_EMBED
);
12816 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
12818 mbox
->vport
= mq
->phba
->pport
;
12819 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12820 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
12821 /* The IOCTL status is embedded in the mailbox subheader. */
12822 shdr
= (union lpfc_sli4_cfg_shdr
*)
12823 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
12824 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12825 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12826 if (shdr_status
|| shdr_add_status
|| rc
) {
12827 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12828 "2507 MQ_DESTROY mailbox failed with "
12829 "status x%x add_status x%x, mbx status x%x\n",
12830 shdr_status
, shdr_add_status
, rc
);
12833 /* Remove mq from any list */
12834 list_del_init(&mq
->list
);
12835 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
12840 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
12841 * @wq: The queue structure associated with the queue to destroy.
12843 * This function destroys a queue, as detailed in @wq by sending an mailbox
12844 * command, specific to the type of queue, to the HBA.
12846 * The @wq struct is used to get the queue ID of the queue to destroy.
12848 * On success this function will return a zero. If the queue destroy mailbox
12849 * command fails this function will return -ENXIO.
12852 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
12854 LPFC_MBOXQ_t
*mbox
;
12855 int rc
, length
, status
= 0;
12856 uint32_t shdr_status
, shdr_add_status
;
12857 union lpfc_sli4_cfg_shdr
*shdr
;
12859 /* sanity check on queue memory */
12862 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12865 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
12866 sizeof(struct lpfc_sli4_cfg_mhdr
));
12867 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12868 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
12869 length
, LPFC_SLI4_MBX_EMBED
);
12870 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
12872 mbox
->vport
= wq
->phba
->pport
;
12873 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12874 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
12875 shdr
= (union lpfc_sli4_cfg_shdr
*)
12876 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
12877 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12878 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12879 if (shdr_status
|| shdr_add_status
|| rc
) {
12880 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12881 "2508 WQ_DESTROY mailbox failed with "
12882 "status x%x add_status x%x, mbx status x%x\n",
12883 shdr_status
, shdr_add_status
, rc
);
12886 /* Remove wq from any list */
12887 list_del_init(&wq
->list
);
12888 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
12893 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
12894 * @rq: The queue structure associated with the queue to destroy.
12896 * This function destroys a queue, as detailed in @rq by sending an mailbox
12897 * command, specific to the type of queue, to the HBA.
12899 * The @rq struct is used to get the queue ID of the queue to destroy.
12901 * On success this function will return a zero. If the queue destroy mailbox
12902 * command fails this function will return -ENXIO.
12905 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12906 struct lpfc_queue
*drq
)
12908 LPFC_MBOXQ_t
*mbox
;
12909 int rc
, length
, status
= 0;
12910 uint32_t shdr_status
, shdr_add_status
;
12911 union lpfc_sli4_cfg_shdr
*shdr
;
12913 /* sanity check on queue memory */
12916 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12919 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
12920 sizeof(struct lpfc_sli4_cfg_mhdr
));
12921 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12922 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
12923 length
, LPFC_SLI4_MBX_EMBED
);
12924 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
12926 mbox
->vport
= hrq
->phba
->pport
;
12927 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12928 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
12929 /* The IOCTL status is embedded in the mailbox subheader. */
12930 shdr
= (union lpfc_sli4_cfg_shdr
*)
12931 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
12932 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12933 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12934 if (shdr_status
|| shdr_add_status
|| rc
) {
12935 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12936 "2509 RQ_DESTROY mailbox failed with "
12937 "status x%x add_status x%x, mbx status x%x\n",
12938 shdr_status
, shdr_add_status
, rc
);
12939 if (rc
!= MBX_TIMEOUT
)
12940 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
12943 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
12945 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
12946 shdr
= (union lpfc_sli4_cfg_shdr
*)
12947 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
12948 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12949 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12950 if (shdr_status
|| shdr_add_status
|| rc
) {
12951 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12952 "2510 RQ_DESTROY mailbox failed with "
12953 "status x%x add_status x%x, mbx status x%x\n",
12954 shdr_status
, shdr_add_status
, rc
);
12957 list_del_init(&hrq
->list
);
12958 list_del_init(&drq
->list
);
12959 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
12964 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
12965 * @phba: The virtual port for which this call being executed.
12966 * @pdma_phys_addr0: Physical address of the 1st SGL page.
12967 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
12968 * @xritag: the xritag that ties this io to the SGL pages.
12970 * This routine will post the sgl pages for the IO that has the xritag
12971 * that is in the iocbq structure. The xritag is assigned during iocbq
12972 * creation and persists for as long as the driver is loaded.
12973 * if the caller has fewer than 256 scatter gather segments to map then
12974 * pdma_phys_addr1 should be 0.
12975 * If the caller needs to map more than 256 scatter gather segment then
12976 * pdma_phys_addr1 should be a valid physical address.
12977 * physical address for SGLs must be 64 byte aligned.
12978 * If you are going to map 2 SGL's then the first one must have 256 entries
12979 * the second sgl can have between 1 and 256 entries.
12983 * -ENXIO, -ENOMEM - Failure
12986 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
12987 dma_addr_t pdma_phys_addr0
,
12988 dma_addr_t pdma_phys_addr1
,
12991 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
12992 LPFC_MBOXQ_t
*mbox
;
12994 uint32_t shdr_status
, shdr_add_status
;
12996 union lpfc_sli4_cfg_shdr
*shdr
;
12998 if (xritag
== NO_XRI
) {
12999 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13000 "0364 Invalid param:\n");
13004 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13008 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13009 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13010 sizeof(struct lpfc_mbx_post_sgl_pages
) -
13011 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
13013 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
13014 &mbox
->u
.mqe
.un
.post_sgl_pages
;
13015 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
13016 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
13018 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
13019 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
13020 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
13021 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
13023 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
13024 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
13025 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
13026 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
13027 if (!phba
->sli4_hba
.intr_enable
)
13028 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13030 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13031 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13033 /* The IOCTL status is embedded in the mailbox subheader. */
13034 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
13035 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13036 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13037 if (rc
!= MBX_TIMEOUT
)
13038 mempool_free(mbox
, phba
->mbox_mem_pool
);
13039 if (shdr_status
|| shdr_add_status
|| rc
) {
13040 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13041 "2511 POST_SGL mailbox failed with "
13042 "status x%x add_status x%x, mbx status x%x\n",
13043 shdr_status
, shdr_add_status
, rc
);
13050 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13051 * @phba: pointer to lpfc hba data structure.
13053 * This routine is invoked to post rpi header templates to the
13054 * HBA consistent with the SLI-4 interface spec. This routine
13055 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13056 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13059 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13060 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13063 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13068 * Fetch the next logical xri. Because this index is logical,
13069 * the driver starts at 0 each time.
13071 spin_lock_irq(&phba
->hbalock
);
13072 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13073 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13074 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13075 spin_unlock_irq(&phba
->hbalock
);
13078 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13079 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13080 phba
->sli4_hba
.xri_count
++;
13083 spin_unlock_irq(&phba
->hbalock
);
13088 * lpfc_sli4_free_xri - Release an xri for reuse.
13089 * @phba: pointer to lpfc hba data structure.
13091 * This routine is invoked to release an xri to the pool of
13092 * available rpis maintained by the driver.
13095 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13097 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13098 phba
->sli4_hba
.xri_count
--;
13099 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13104 * lpfc_sli4_free_xri - Release an xri for reuse.
13105 * @phba: pointer to lpfc hba data structure.
13107 * This routine is invoked to release an xri to the pool of
13108 * available rpis maintained by the driver.
13111 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13113 spin_lock_irq(&phba
->hbalock
);
13114 __lpfc_sli4_free_xri(phba
, xri
);
13115 spin_unlock_irq(&phba
->hbalock
);
13119 * lpfc_sli4_next_xritag - Get an xritag for the io
13120 * @phba: Pointer to HBA context object.
13122 * This function gets an xritag for the iocb. If there is no unused xritag
13123 * it will return 0xffff.
13124 * The function returns the allocated xritag if successful, else returns zero.
13125 * Zero is not a valid xritag.
13126 * The caller is not required to hold any lock.
13129 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13131 uint16_t xri_index
;
13133 xri_index
= lpfc_sli4_alloc_xri(phba
);
13134 if (xri_index
!= NO_XRI
)
13137 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13138 "2004 Failed to allocate XRI.last XRITAG is %d"
13139 " Max XRI is %d, Used XRI is %d\n",
13141 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13142 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13147 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13148 * @phba: pointer to lpfc hba data structure.
13150 * This routine is invoked to post a block of driver's sgl pages to the
13151 * HBA using non-embedded mailbox command. No Lock is held. This routine
13152 * is only called when the driver is loading and after all IO has been
13156 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
)
13158 struct lpfc_sglq
*sglq_entry
;
13159 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13160 struct sgl_page_pairs
*sgl_pg_pairs
;
13162 LPFC_MBOXQ_t
*mbox
;
13163 uint32_t reqlen
, alloclen
, pg_pairs
;
13165 uint16_t xritag_start
= 0, lxri
= 0;
13166 int els_xri_cnt
, rc
= 0;
13167 uint32_t shdr_status
, shdr_add_status
;
13168 union lpfc_sli4_cfg_shdr
*shdr
;
13170 /* The number of sgls to be posted */
13171 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
13173 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13174 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13175 if (reqlen
> SLI4_PAGE_SIZE
) {
13176 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13177 "2559 Block sgl registration required DMA "
13178 "size (%d) great than a page\n", reqlen
);
13181 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13185 /* Allocate DMA memory and set up the non-embedded mailbox command */
13186 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13187 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13188 LPFC_SLI4_MBX_NEMBED
);
13190 if (alloclen
< reqlen
) {
13191 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13192 "0285 Allocated DMA memory size (%d) is "
13193 "less than the requested DMA memory "
13194 "size (%d)\n", alloclen
, reqlen
);
13195 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13198 /* Set up the SGL pages in the non-embedded DMA pages */
13199 viraddr
= mbox
->sge_array
->addr
[0];
13200 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13201 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13203 for (pg_pairs
= 0; pg_pairs
< els_xri_cnt
; pg_pairs
++) {
13204 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[pg_pairs
];
13207 * Assign the sglq a physical xri only if the driver has not
13208 * initialized those resources. A port reset only needs
13209 * the sglq's posted.
13211 if (bf_get(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
13212 LPFC_XRI_RSRC_RDY
) {
13213 lxri
= lpfc_sli4_next_xritag(phba
);
13214 if (lxri
== NO_XRI
) {
13215 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13218 sglq_entry
->sli4_lxritag
= lxri
;
13219 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
13222 /* Set up the sge entry */
13223 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13224 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13225 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13226 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13227 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13228 cpu_to_le32(putPaddrLow(0));
13229 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13230 cpu_to_le32(putPaddrHigh(0));
13232 /* Keep the first xritag on the list */
13234 xritag_start
= sglq_entry
->sli4_xritag
;
13238 /* Complete initialization and perform endian conversion. */
13239 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13240 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, els_xri_cnt
);
13241 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13242 if (!phba
->sli4_hba
.intr_enable
)
13243 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13245 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13246 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13248 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13249 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13250 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13251 if (rc
!= MBX_TIMEOUT
)
13252 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13253 if (shdr_status
|| shdr_add_status
|| rc
) {
13254 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13255 "2513 POST_SGL_BLOCK mailbox command failed "
13256 "status x%x add_status x%x mbx status x%x\n",
13257 shdr_status
, shdr_add_status
, rc
);
13262 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
13263 LPFC_XRI_RSRC_RDY
);
13268 * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port.
13269 * @phba: pointer to lpfc hba data structure.
13271 * This routine is invoked to post a block of driver's sgl pages to the
13272 * HBA using non-embedded mailbox command. No Lock is held. This routine
13273 * is only called when the driver is loading and after all IO has been
13277 lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba
*phba
)
13279 struct lpfc_sglq
*sglq_entry
;
13280 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13281 struct sgl_page_pairs
*sgl_pg_pairs
;
13283 LPFC_MBOXQ_t
*mbox
;
13284 uint32_t reqlen
, alloclen
, index
;
13286 uint16_t rsrc_start
, rsrc_size
, els_xri_cnt
;
13287 uint16_t xritag_start
= 0, lxri
= 0;
13288 struct lpfc_rsrc_blks
*rsrc_blk
;
13289 int cnt
, ttl_cnt
, rc
= 0;
13291 uint32_t shdr_status
, shdr_add_status
;
13292 union lpfc_sli4_cfg_shdr
*shdr
;
13294 /* The number of sgls to be posted */
13295 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
13297 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13298 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13299 if (reqlen
> SLI4_PAGE_SIZE
) {
13300 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13301 "2989 Block sgl registration required DMA "
13302 "size (%d) great than a page\n", reqlen
);
13308 list_for_each_entry(rsrc_blk
, &phba
->sli4_hba
.lpfc_xri_blk_list
,
13310 rsrc_start
= rsrc_blk
->rsrc_start
;
13311 rsrc_size
= rsrc_blk
->rsrc_size
;
13313 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13314 "3014 Working ELS Extent start %d, cnt %d\n",
13315 rsrc_start
, rsrc_size
);
13317 loop_cnt
= min(els_xri_cnt
, rsrc_size
);
13318 if (ttl_cnt
+ loop_cnt
>= els_xri_cnt
) {
13319 loop_cnt
= els_xri_cnt
- ttl_cnt
;
13320 ttl_cnt
= els_xri_cnt
;
13323 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13327 * Allocate DMA memory and set up the non-embedded mailbox
13330 alloclen
= lpfc_sli4_config(phba
, mbox
,
13331 LPFC_MBOX_SUBSYSTEM_FCOE
,
13332 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13333 reqlen
, LPFC_SLI4_MBX_NEMBED
);
13334 if (alloclen
< reqlen
) {
13335 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13336 "2987 Allocated DMA memory size (%d) "
13337 "is less than the requested DMA memory "
13338 "size (%d)\n", alloclen
, reqlen
);
13339 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13343 /* Set up the SGL pages in the non-embedded DMA pages */
13344 viraddr
= mbox
->sge_array
->addr
[0];
13345 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13346 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13349 * The starting resource may not begin at zero. Control
13350 * the loop variants via the block resource parameters,
13351 * but handle the sge pointers with a zero-based index
13352 * that doesn't get reset per loop pass.
13354 for (index
= rsrc_start
;
13355 index
< rsrc_start
+ loop_cnt
;
13357 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[cnt
];
13360 * Assign the sglq a physical xri only if the driver
13361 * has not initialized those resources. A port reset
13362 * only needs the sglq's posted.
13364 if (bf_get(lpfc_xri_rsrc_rdy
,
13365 &phba
->sli4_hba
.sli4_flags
) !=
13366 LPFC_XRI_RSRC_RDY
) {
13367 lxri
= lpfc_sli4_next_xritag(phba
);
13368 if (lxri
== NO_XRI
) {
13369 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13373 sglq_entry
->sli4_lxritag
= lxri
;
13374 sglq_entry
->sli4_xritag
=
13375 phba
->sli4_hba
.xri_ids
[lxri
];
13378 /* Set up the sge entry */
13379 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13380 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13381 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13382 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13383 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13384 cpu_to_le32(putPaddrLow(0));
13385 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13386 cpu_to_le32(putPaddrHigh(0));
13388 /* Track the starting physical XRI for the mailbox. */
13389 if (index
== rsrc_start
)
13390 xritag_start
= sglq_entry
->sli4_xritag
;
13395 /* Complete initialization and perform endian conversion. */
13396 rsrc_blk
->rsrc_used
+= loop_cnt
;
13397 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13398 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, loop_cnt
);
13399 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13401 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13402 "3015 Post ELS Extent SGL, start %d, "
13403 "cnt %d, used %d\n",
13404 xritag_start
, loop_cnt
, rsrc_blk
->rsrc_used
);
13405 if (!phba
->sli4_hba
.intr_enable
)
13406 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13408 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13409 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13411 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13412 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
13414 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
13416 if (rc
!= MBX_TIMEOUT
)
13417 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13418 if (shdr_status
|| shdr_add_status
|| rc
) {
13419 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13420 "2988 POST_SGL_BLOCK mailbox "
13421 "command failed status x%x "
13422 "add_status x%x mbx status x%x\n",
13423 shdr_status
, shdr_add_status
, rc
);
13427 if (ttl_cnt
>= els_xri_cnt
)
13433 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
13434 LPFC_XRI_RSRC_RDY
);
13439 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13440 * @phba: pointer to lpfc hba data structure.
13441 * @sblist: pointer to scsi buffer list.
13442 * @count: number of scsi buffers on the list.
13444 * This routine is invoked to post a block of @count scsi sgl pages from a
13445 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13450 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
, struct list_head
*sblist
,
13453 struct lpfc_scsi_buf
*psb
;
13454 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13455 struct sgl_page_pairs
*sgl_pg_pairs
;
13457 LPFC_MBOXQ_t
*mbox
;
13458 uint32_t reqlen
, alloclen
, pg_pairs
;
13460 uint16_t xritag_start
= 0;
13462 uint32_t shdr_status
, shdr_add_status
;
13463 dma_addr_t pdma_phys_bpl1
;
13464 union lpfc_sli4_cfg_shdr
*shdr
;
13466 /* Calculate the requested length of the dma memory */
13467 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
13468 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13469 if (reqlen
> SLI4_PAGE_SIZE
) {
13470 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13471 "0217 Block sgl registration required DMA "
13472 "size (%d) great than a page\n", reqlen
);
13475 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13477 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13478 "0283 Failed to allocate mbox cmd memory\n");
13482 /* Allocate DMA memory and set up the non-embedded mailbox command */
13483 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13484 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13485 LPFC_SLI4_MBX_NEMBED
);
13487 if (alloclen
< reqlen
) {
13488 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13489 "2561 Allocated DMA memory size (%d) is "
13490 "less than the requested DMA memory "
13491 "size (%d)\n", alloclen
, reqlen
);
13492 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13496 /* Get the first SGE entry from the non-embedded DMA memory */
13497 viraddr
= mbox
->sge_array
->addr
[0];
13499 /* Set up the SGL pages in the non-embedded DMA pages */
13500 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13501 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13504 list_for_each_entry(psb
, sblist
, list
) {
13505 /* Set up the sge entry */
13506 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13507 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13508 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13509 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13510 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13511 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
13513 pdma_phys_bpl1
= 0;
13514 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13515 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13516 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13517 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13518 /* Keep the first xritag on the list */
13520 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
13524 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13525 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13526 /* Perform endian conversion if necessary */
13527 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13529 if (!phba
->sli4_hba
.intr_enable
)
13530 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13532 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13533 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13535 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13536 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13537 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13538 if (rc
!= MBX_TIMEOUT
)
13539 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13540 if (shdr_status
|| shdr_add_status
|| rc
) {
13541 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13542 "2564 POST_SGL_BLOCK mailbox command failed "
13543 "status x%x add_status x%x mbx status x%x\n",
13544 shdr_status
, shdr_add_status
, rc
);
13551 * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port.
13552 * @phba: pointer to lpfc hba data structure.
13553 * @sblist: pointer to scsi buffer list.
13554 * @count: number of scsi buffers on the list.
13556 * This routine is invoked to post a block of @count scsi sgl pages from a
13557 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13562 lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba
*phba
, struct list_head
*sblist
,
13565 struct lpfc_scsi_buf
*psb
= NULL
;
13566 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13567 struct sgl_page_pairs
*sgl_pg_pairs
;
13569 LPFC_MBOXQ_t
*mbox
;
13570 uint32_t reqlen
, alloclen
, pg_pairs
;
13572 uint16_t xri_start
= 0, scsi_xri_start
;
13573 uint16_t rsrc_range
;
13574 int rc
= 0, avail_cnt
;
13575 uint32_t shdr_status
, shdr_add_status
;
13576 dma_addr_t pdma_phys_bpl1
;
13577 union lpfc_sli4_cfg_shdr
*shdr
;
13578 struct lpfc_rsrc_blks
*rsrc_blk
;
13579 uint32_t xri_cnt
= 0;
13581 /* Calculate the total requested length of the dma memory */
13582 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
13583 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13584 if (reqlen
> SLI4_PAGE_SIZE
) {
13585 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13586 "2932 Block sgl registration required DMA "
13587 "size (%d) great than a page\n", reqlen
);
13592 * The use of extents requires the driver to post the sgl headers
13593 * in multiple postings to meet the contiguous resource assignment.
13595 psb
= list_prepare_entry(psb
, sblist
, list
);
13596 scsi_xri_start
= phba
->sli4_hba
.scsi_xri_start
;
13597 list_for_each_entry(rsrc_blk
, &phba
->sli4_hba
.lpfc_xri_blk_list
,
13599 rsrc_range
= rsrc_blk
->rsrc_start
+ rsrc_blk
->rsrc_size
;
13600 if (rsrc_range
< scsi_xri_start
)
13602 else if (rsrc_blk
->rsrc_used
>= rsrc_blk
->rsrc_size
)
13605 avail_cnt
= rsrc_blk
->rsrc_size
- rsrc_blk
->rsrc_used
;
13607 reqlen
= (avail_cnt
* sizeof(struct sgl_page_pairs
)) +
13608 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13610 * Allocate DMA memory and set up the non-embedded mailbox
13611 * command. The mbox is used to post an SGL page per loop
13612 * but the DMA memory has a use-once semantic so the mailbox
13613 * is used and freed per loop pass.
13615 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13617 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13618 "2933 Failed to allocate mbox cmd "
13622 alloclen
= lpfc_sli4_config(phba
, mbox
,
13623 LPFC_MBOX_SUBSYSTEM_FCOE
,
13624 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13626 LPFC_SLI4_MBX_NEMBED
);
13627 if (alloclen
< reqlen
) {
13628 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13629 "2934 Allocated DMA memory size (%d) "
13630 "is less than the requested DMA memory "
13631 "size (%d)\n", alloclen
, reqlen
);
13632 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13636 /* Get the first SGE entry from the non-embedded DMA memory */
13637 viraddr
= mbox
->sge_array
->addr
[0];
13639 /* Set up the SGL pages in the non-embedded DMA pages */
13640 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13641 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13643 /* pg_pairs tracks posted SGEs per loop iteration. */
13645 list_for_each_entry_continue(psb
, sblist
, list
) {
13646 /* Set up the sge entry */
13647 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13648 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13649 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13650 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13651 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13652 pdma_phys_bpl1
= psb
->dma_phys_bpl
+
13655 pdma_phys_bpl1
= 0;
13656 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13657 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13658 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13659 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13660 /* Keep the first xri for this extent. */
13662 xri_start
= psb
->cur_iocbq
.sli4_xritag
;
13668 * Track two exit conditions - the loop has constructed
13669 * all of the caller's SGE pairs or all available
13670 * resource IDs in this extent are consumed.
13672 if ((xri_cnt
== cnt
) || (pg_pairs
>= avail_cnt
))
13675 rsrc_blk
->rsrc_used
+= pg_pairs
;
13676 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xri_start
);
13677 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13679 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13680 "3016 Post SCSI Extent SGL, start %d, cnt %d "
13682 xri_start
, pg_pairs
, rsrc_blk
->rsrc_used
);
13683 /* Perform endian conversion if necessary */
13684 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13685 if (!phba
->sli4_hba
.intr_enable
)
13686 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13688 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13689 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13691 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13692 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13693 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
13695 if (rc
!= MBX_TIMEOUT
)
13696 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13697 if (shdr_status
|| shdr_add_status
|| rc
) {
13698 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13699 "2935 POST_SGL_BLOCK mailbox command "
13700 "failed status x%x add_status x%x "
13701 "mbx status x%x\n",
13702 shdr_status
, shdr_add_status
, rc
);
13706 /* Post only what is requested. */
13707 if (xri_cnt
>= cnt
)
13714 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13715 * @phba: pointer to lpfc_hba struct that the frame was received on
13716 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13718 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13719 * valid type of frame that the LPFC driver will handle. This function will
13720 * return a zero if the frame is a valid frame or a non zero value when the
13721 * frame does not pass the check.
13724 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
13726 /* make rctl_names static to save stack space */
13727 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
13728 char *type_names
[] = FC_TYPE_NAMES_INIT
;
13729 struct fc_vft_header
*fc_vft_hdr
;
13730 uint32_t *header
= (uint32_t *) fc_hdr
;
13732 switch (fc_hdr
->fh_r_ctl
) {
13733 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
13734 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
13735 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
13736 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
13737 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
13738 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
13739 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
13740 case FC_RCTL_DD_CMD_STATUS
: /* command status */
13741 case FC_RCTL_ELS_REQ
: /* extended link services request */
13742 case FC_RCTL_ELS_REP
: /* extended link services reply */
13743 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
13744 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
13745 case FC_RCTL_BA_NOP
: /* basic link service NOP */
13746 case FC_RCTL_BA_ABTS
: /* basic link service abort */
13747 case FC_RCTL_BA_RMC
: /* remove connection */
13748 case FC_RCTL_BA_ACC
: /* basic accept */
13749 case FC_RCTL_BA_RJT
: /* basic reject */
13750 case FC_RCTL_BA_PRMT
:
13751 case FC_RCTL_ACK_1
: /* acknowledge_1 */
13752 case FC_RCTL_ACK_0
: /* acknowledge_0 */
13753 case FC_RCTL_P_RJT
: /* port reject */
13754 case FC_RCTL_F_RJT
: /* fabric reject */
13755 case FC_RCTL_P_BSY
: /* port busy */
13756 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
13757 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
13758 case FC_RCTL_LCR
: /* link credit reset */
13759 case FC_RCTL_END
: /* end */
13761 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
13762 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13763 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
13764 return lpfc_fc_frame_check(phba
, fc_hdr
);
13768 switch (fc_hdr
->fh_type
) {
13780 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
13781 "2538 Received frame rctl:%s type:%s "
13782 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13783 rctl_names
[fc_hdr
->fh_r_ctl
],
13784 type_names
[fc_hdr
->fh_type
],
13785 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
13786 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
13787 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]));
13790 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13791 "2539 Dropped frame rctl:%s type:%s\n",
13792 rctl_names
[fc_hdr
->fh_r_ctl
],
13793 type_names
[fc_hdr
->fh_type
]);
13798 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13799 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13801 * This function processes the FC header to retrieve the VFI from the VF
13802 * header, if one exists. This function will return the VFI if one exists
13803 * or 0 if no VSAN Header exists.
13806 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
13808 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13810 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
13812 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
13816 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13817 * @phba: Pointer to the HBA structure to search for the vport on
13818 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13819 * @fcfi: The FC Fabric ID that the frame came from
13821 * This function searches the @phba for a vport that matches the content of the
13822 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13823 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13824 * returns the matching vport pointer or NULL if unable to match frame to a
13827 static struct lpfc_vport
*
13828 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
13831 struct lpfc_vport
**vports
;
13832 struct lpfc_vport
*vport
= NULL
;
13834 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
13835 fc_hdr
->fh_d_id
[1] << 8 |
13836 fc_hdr
->fh_d_id
[2]);
13837 if (did
== Fabric_DID
)
13838 return phba
->pport
;
13839 vports
= lpfc_create_vport_work_array(phba
);
13840 if (vports
!= NULL
)
13841 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
13842 if (phba
->fcf
.fcfi
== fcfi
&&
13843 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
13844 vports
[i
]->fc_myDID
== did
) {
13849 lpfc_destroy_vport_work_array(phba
, vports
);
13854 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13855 * @vport: The vport to work on.
13857 * This function updates the receive sequence time stamp for this vport. The
13858 * receive sequence time stamp indicates the time that the last frame of the
13859 * the sequence that has been idle for the longest amount of time was received.
13860 * the driver uses this time stamp to indicate if any received sequences have
13864 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
13866 struct lpfc_dmabuf
*h_buf
;
13867 struct hbq_dmabuf
*dmabuf
= NULL
;
13869 /* get the oldest sequence on the rcv list */
13870 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
13871 struct lpfc_dmabuf
, list
);
13874 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13875 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
13879 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13880 * @vport: The vport that the received sequences were sent to.
13882 * This function cleans up all outstanding received sequences. This is called
13883 * by the driver when a link event or user action invalidates all the received
13887 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
13889 struct lpfc_dmabuf
*h_buf
, *hnext
;
13890 struct lpfc_dmabuf
*d_buf
, *dnext
;
13891 struct hbq_dmabuf
*dmabuf
= NULL
;
13893 /* start with the oldest sequence on the rcv list */
13894 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13895 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13896 list_del_init(&dmabuf
->hbuf
.list
);
13897 list_for_each_entry_safe(d_buf
, dnext
,
13898 &dmabuf
->dbuf
.list
, list
) {
13899 list_del_init(&d_buf
->list
);
13900 lpfc_in_buf_free(vport
->phba
, d_buf
);
13902 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13907 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13908 * @vport: The vport that the received sequences were sent to.
13910 * This function determines whether any received sequences have timed out by
13911 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13912 * indicates that there is at least one timed out sequence this routine will
13913 * go through the received sequences one at a time from most inactive to most
13914 * active to determine which ones need to be cleaned up. Once it has determined
13915 * that a sequence needs to be cleaned up it will simply free up the resources
13916 * without sending an abort.
13919 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
13921 struct lpfc_dmabuf
*h_buf
, *hnext
;
13922 struct lpfc_dmabuf
*d_buf
, *dnext
;
13923 struct hbq_dmabuf
*dmabuf
= NULL
;
13924 unsigned long timeout
;
13925 int abort_count
= 0;
13927 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13928 vport
->rcv_buffer_time_stamp
);
13929 if (list_empty(&vport
->rcv_buffer_list
) ||
13930 time_before(jiffies
, timeout
))
13932 /* start with the oldest sequence on the rcv list */
13933 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13934 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13935 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13936 dmabuf
->time_stamp
);
13937 if (time_before(jiffies
, timeout
))
13940 list_del_init(&dmabuf
->hbuf
.list
);
13941 list_for_each_entry_safe(d_buf
, dnext
,
13942 &dmabuf
->dbuf
.list
, list
) {
13943 list_del_init(&d_buf
->list
);
13944 lpfc_in_buf_free(vport
->phba
, d_buf
);
13946 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13949 lpfc_update_rcv_time_stamp(vport
);
13953 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13954 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13956 * This function searches through the existing incomplete sequences that have
13957 * been sent to this @vport. If the frame matches one of the incomplete
13958 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13959 * make up that sequence. If no sequence is found that matches this frame then
13960 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13961 * This function returns a pointer to the first dmabuf in the sequence list that
13962 * the frame was linked to.
13964 static struct hbq_dmabuf
*
13965 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
13967 struct fc_frame_header
*new_hdr
;
13968 struct fc_frame_header
*temp_hdr
;
13969 struct lpfc_dmabuf
*d_buf
;
13970 struct lpfc_dmabuf
*h_buf
;
13971 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13972 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
13974 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13975 dmabuf
->time_stamp
= jiffies
;
13976 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13977 /* Use the hdr_buf to find the sequence that this frame belongs to */
13978 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13979 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13980 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13981 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13982 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13984 /* found a pending sequence that matches this frame */
13985 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13990 * This indicates first frame received for this sequence.
13991 * Queue the buffer on the vport's rcv_buffer_list.
13993 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13994 lpfc_update_rcv_time_stamp(vport
);
13997 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
13998 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
13999 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14000 list_del_init(&seq_dmabuf
->hbuf
.list
);
14001 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14002 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14003 lpfc_update_rcv_time_stamp(vport
);
14006 /* move this sequence to the tail to indicate a young sequence */
14007 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14008 seq_dmabuf
->time_stamp
= jiffies
;
14009 lpfc_update_rcv_time_stamp(vport
);
14010 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
14011 temp_hdr
= dmabuf
->hbuf
.virt
;
14012 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14015 /* find the correct place in the sequence to insert this frame */
14016 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14017 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14018 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
14020 * If the frame's sequence count is greater than the frame on
14021 * the list then insert the frame right after this frame
14023 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
14024 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14025 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
14033 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
14034 * @vport: pointer to a vitural port
14035 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14037 * This function tries to abort from the partially assembed sequence, described
14038 * by the information from basic abbort @dmabuf. It checks to see whether such
14039 * partially assembled sequence held by the driver. If so, it shall free up all
14040 * the frames from the partially assembled sequence.
14043 * true -- if there is matching partially assembled sequence present and all
14044 * the frames freed with the sequence;
14045 * false -- if there is no matching partially assembled sequence present so
14046 * nothing got aborted in the lower layer driver
14049 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
14050 struct hbq_dmabuf
*dmabuf
)
14052 struct fc_frame_header
*new_hdr
;
14053 struct fc_frame_header
*temp_hdr
;
14054 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
14055 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14057 /* Use the hdr_buf to find the sequence that matches this frame */
14058 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14059 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
14060 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14061 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14062 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14063 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14064 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14065 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14067 /* found a pending sequence that matches this frame */
14068 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14072 /* Free up all the frames from the partially assembled sequence */
14074 list_for_each_entry_safe(d_buf
, n_buf
,
14075 &seq_dmabuf
->dbuf
.list
, list
) {
14076 list_del_init(&d_buf
->list
);
14077 lpfc_in_buf_free(vport
->phba
, d_buf
);
14085 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14086 * @phba: Pointer to HBA context object.
14087 * @cmd_iocbq: pointer to the command iocbq structure.
14088 * @rsp_iocbq: pointer to the response iocbq structure.
14090 * This function handles the sequence abort response iocb command complete
14091 * event. It properly releases the memory allocated to the sequence abort
14095 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
14096 struct lpfc_iocbq
*cmd_iocbq
,
14097 struct lpfc_iocbq
*rsp_iocbq
)
14100 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
14102 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14103 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
14104 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14105 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14106 rsp_iocbq
->iocb
.ulpStatus
,
14107 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
14111 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14112 * @phba: Pointer to HBA context object.
14113 * @xri: xri id in transaction.
14115 * This function validates the xri maps to the known range of XRIs allocated an
14116 * used by the driver.
14119 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
14124 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
14125 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
14133 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14134 * @phba: Pointer to HBA context object.
14135 * @fc_hdr: pointer to a FC frame header.
14137 * This function sends a basic response to a previous unsol sequence abort
14138 * event after aborting the sequence handling.
14141 lpfc_sli4_seq_abort_rsp(struct lpfc_hba
*phba
,
14142 struct fc_frame_header
*fc_hdr
)
14144 struct lpfc_iocbq
*ctiocb
= NULL
;
14145 struct lpfc_nodelist
*ndlp
;
14146 uint16_t oxid
, rxid
;
14147 uint32_t sid
, fctl
;
14151 if (!lpfc_is_link_up(phba
))
14154 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14155 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
14156 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
14158 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
14160 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14161 "1268 Find ndlp returned NULL for oxid:x%x "
14162 "SID:x%x\n", oxid
, sid
);
14165 if (lpfc_sli4_xri_inrange(phba
, rxid
))
14166 lpfc_set_rrq_active(phba
, ndlp
, rxid
, oxid
, 0);
14168 /* Allocate buffer for rsp iocb */
14169 ctiocb
= lpfc_sli_get_iocbq(phba
);
14173 /* Extract the F_CTL field from FC_HDR */
14174 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
14176 icmd
= &ctiocb
->iocb
;
14177 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
14178 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
14179 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
14180 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
14181 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
14183 /* Fill in the rest of iocb fields */
14184 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
14185 icmd
->ulpBdeCount
= 0;
14187 icmd
->ulpClass
= CLASS3
;
14188 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
14189 ctiocb
->context1
= ndlp
;
14191 ctiocb
->iocb_cmpl
= NULL
;
14192 ctiocb
->vport
= phba
->pport
;
14193 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
14194 ctiocb
->sli4_lxritag
= NO_XRI
;
14195 ctiocb
->sli4_xritag
= NO_XRI
;
14197 /* If the oxid maps to the FCP XRI range or if it is out of range,
14198 * send a BLS_RJT. The driver no longer has that exchange.
14199 * Override the IOCB for a BA_RJT.
14201 if (oxid
> (phba
->sli4_hba
.max_cfg_param
.max_xri
+
14202 phba
->sli4_hba
.max_cfg_param
.xri_base
) ||
14203 oxid
> (lpfc_sli4_get_els_iocb_cnt(phba
) +
14204 phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
14205 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14206 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14207 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14208 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14211 if (fctl
& FC_FC_EX_CTX
) {
14212 /* ABTS sent by responder to CT exchange, construction
14213 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14214 * field and RX_ID from ABTS for RX_ID field.
14216 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14218 /* ABTS sent by initiator to CT exchange, construction
14219 * of BA_ACC will need to allocate a new XRI as for the
14222 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14224 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14225 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14227 /* Xmit CT abts response on exchange <xid> */
14228 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14229 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14230 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14232 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14233 if (rc
== IOCB_ERROR
) {
14234 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
14235 "2925 Failed to issue CT ABTS RSP x%x on "
14236 "xri x%x, Data x%x\n",
14237 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14239 lpfc_sli_release_iocbq(phba
, ctiocb
);
14244 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14245 * @vport: Pointer to the vport on which this sequence was received
14246 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14248 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14249 * receive sequence is only partially assembed by the driver, it shall abort
14250 * the partially assembled frames for the sequence. Otherwise, if the
14251 * unsolicited receive sequence has been completely assembled and passed to
14252 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14253 * unsolicited sequence has been aborted. After that, it will issue a basic
14254 * accept to accept the abort.
14257 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14258 struct hbq_dmabuf
*dmabuf
)
14260 struct lpfc_hba
*phba
= vport
->phba
;
14261 struct fc_frame_header fc_hdr
;
14265 /* Make a copy of fc_hdr before the dmabuf being released */
14266 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14267 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14269 if (fctl
& FC_FC_EX_CTX
) {
14271 * ABTS sent by responder to exchange, just free the buffer
14273 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14276 * ABTS sent by initiator to exchange, need to do cleanup
14278 /* Try to abort partially assembled seq */
14279 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14281 /* Send abort to ULP if partially seq abort failed */
14282 if (abts_par
== false)
14283 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
14285 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14287 /* Send basic accept (BA_ACC) to the abort requester */
14288 lpfc_sli4_seq_abort_rsp(phba
, &fc_hdr
);
14292 * lpfc_seq_complete - Indicates if a sequence is complete
14293 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14295 * This function checks the sequence, starting with the frame described by
14296 * @dmabuf, to see if all the frames associated with this sequence are present.
14297 * the frames associated with this sequence are linked to the @dmabuf using the
14298 * dbuf list. This function looks for two major things. 1) That the first frame
14299 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14300 * set. 3) That there are no holes in the sequence count. The function will
14301 * return 1 when the sequence is complete, otherwise it will return 0.
14304 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14306 struct fc_frame_header
*hdr
;
14307 struct lpfc_dmabuf
*d_buf
;
14308 struct hbq_dmabuf
*seq_dmabuf
;
14312 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14313 /* make sure first fame of sequence has a sequence count of zero */
14314 if (hdr
->fh_seq_cnt
!= seq_count
)
14316 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14317 hdr
->fh_f_ctl
[1] << 8 |
14319 /* If last frame of sequence we can return success. */
14320 if (fctl
& FC_FC_END_SEQ
)
14322 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14323 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14324 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14325 /* If there is a hole in the sequence count then fail. */
14326 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14328 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14329 hdr
->fh_f_ctl
[1] << 8 |
14331 /* If last frame of sequence we can return success. */
14332 if (fctl
& FC_FC_END_SEQ
)
14339 * lpfc_prep_seq - Prep sequence for ULP processing
14340 * @vport: Pointer to the vport on which this sequence was received
14341 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14343 * This function takes a sequence, described by a list of frames, and creates
14344 * a list of iocbq structures to describe the sequence. This iocbq list will be
14345 * used to issue to the generic unsolicited sequence handler. This routine
14346 * returns a pointer to the first iocbq in the list. If the function is unable
14347 * to allocate an iocbq then it throw out the received frames that were not
14348 * able to be described and return a pointer to the first iocbq. If unable to
14349 * allocate any iocbqs (including the first) this function will return NULL.
14351 static struct lpfc_iocbq
*
14352 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14354 struct hbq_dmabuf
*hbq_buf
;
14355 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14356 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14357 struct fc_frame_header
*fc_hdr
;
14359 uint32_t len
, tot_len
;
14360 struct ulp_bde64
*pbde
;
14362 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14363 /* remove from receive buffer list */
14364 list_del_init(&seq_dmabuf
->hbuf
.list
);
14365 lpfc_update_rcv_time_stamp(vport
);
14366 /* get the Remote Port's SID */
14367 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14369 /* Get an iocbq struct to fill in. */
14370 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14372 /* Initialize the first IOCB. */
14373 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14374 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14375 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14376 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14377 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14378 be16_to_cpu(fc_hdr
->fh_ox_id
);
14379 /* iocbq is prepped for internal consumption. Physical vpi. */
14380 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14381 vport
->phba
->vpi_ids
[vport
->vpi
];
14382 /* put the first buffer into the first IOCBq */
14383 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14384 first_iocbq
->context3
= NULL
;
14385 first_iocbq
->iocb
.ulpBdeCount
= 1;
14386 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14387 LPFC_DATA_BUF_SIZE
;
14388 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14389 tot_len
= bf_get(lpfc_rcqe_length
,
14390 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14391 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14393 iocbq
= first_iocbq
;
14395 * Each IOCBq can have two Buffers assigned, so go through the list
14396 * of buffers for this sequence and save two buffers in each IOCBq
14398 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14400 lpfc_in_buf_free(vport
->phba
, d_buf
);
14403 if (!iocbq
->context3
) {
14404 iocbq
->context3
= d_buf
;
14405 iocbq
->iocb
.ulpBdeCount
++;
14406 pbde
= (struct ulp_bde64
*)
14407 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14408 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14410 /* We need to get the size out of the right CQE */
14411 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14412 len
= bf_get(lpfc_rcqe_length
,
14413 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14414 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14417 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14420 first_iocbq
->iocb
.ulpStatus
=
14421 IOSTAT_FCP_RSP_ERROR
;
14422 first_iocbq
->iocb
.un
.ulpWord
[4] =
14423 IOERR_NO_RESOURCES
;
14425 lpfc_in_buf_free(vport
->phba
, d_buf
);
14428 iocbq
->context2
= d_buf
;
14429 iocbq
->context3
= NULL
;
14430 iocbq
->iocb
.ulpBdeCount
= 1;
14431 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14432 LPFC_DATA_BUF_SIZE
;
14434 /* We need to get the size out of the right CQE */
14435 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14436 len
= bf_get(lpfc_rcqe_length
,
14437 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14439 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14441 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14442 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14445 return first_iocbq
;
14449 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14450 struct hbq_dmabuf
*seq_dmabuf
)
14452 struct fc_frame_header
*fc_hdr
;
14453 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
14454 struct lpfc_hba
*phba
= vport
->phba
;
14456 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14457 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
14459 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14460 "2707 Ring %d handler: Failed to allocate "
14461 "iocb Rctl x%x Type x%x received\n",
14463 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14466 if (!lpfc_complete_unsol_iocb(phba
,
14467 &phba
->sli
.ring
[LPFC_ELS_RING
],
14468 iocbq
, fc_hdr
->fh_r_ctl
,
14470 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14471 "2540 Ring %d handler: unexpected Rctl "
14472 "x%x Type x%x received\n",
14474 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14476 /* Free iocb created in lpfc_prep_seq */
14477 list_for_each_entry_safe(curr_iocb
, next_iocb
,
14478 &iocbq
->list
, list
) {
14479 list_del_init(&curr_iocb
->list
);
14480 lpfc_sli_release_iocbq(phba
, curr_iocb
);
14482 lpfc_sli_release_iocbq(phba
, iocbq
);
14486 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14487 * @phba: Pointer to HBA context object.
14489 * This function is called with no lock held. This function processes all
14490 * the received buffers and gives it to upper layers when a received buffer
14491 * indicates that it is the final frame in the sequence. The interrupt
14492 * service routine processes received buffers at interrupt contexts and adds
14493 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14494 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14495 * appropriate receive function when the final frame in a sequence is received.
14498 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
14499 struct hbq_dmabuf
*dmabuf
)
14501 struct hbq_dmabuf
*seq_dmabuf
;
14502 struct fc_frame_header
*fc_hdr
;
14503 struct lpfc_vport
*vport
;
14506 /* Process each received buffer */
14507 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14508 /* check to see if this a valid type of frame */
14509 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
14510 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14513 if ((bf_get(lpfc_cqe_code
,
14514 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
14515 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
14516 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14518 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
14519 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14520 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
14521 if (!vport
|| !(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
14522 /* throw out the frame */
14523 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14526 /* Handle the basic abort sequence (BA_ABTS) event */
14527 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
14528 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
14532 /* Link this frame */
14533 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
14535 /* unable to add frame to vport - throw it out */
14536 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14539 /* If not last frame in sequence continue processing frames. */
14540 if (!lpfc_seq_complete(seq_dmabuf
))
14543 /* Send the complete sequence to the upper layer protocol */
14544 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
14548 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14549 * @phba: pointer to lpfc hba data structure.
14551 * This routine is invoked to post rpi header templates to the
14552 * HBA consistent with the SLI-4 interface spec. This routine
14553 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14554 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14556 * This routine does not require any locks. It's usage is expected
14557 * to be driver load or reset recovery when the driver is
14562 * -EIO - The mailbox failed to complete successfully.
14563 * When this error occurs, the driver is not guaranteed
14564 * to have any rpi regions posted to the device and
14565 * must either attempt to repost the regions or take a
14569 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
14571 struct lpfc_rpi_hdr
*rpi_page
;
14575 /* SLI4 ports that support extents do not require RPI headers. */
14576 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14578 if (phba
->sli4_hba
.extents_in_use
)
14581 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
14583 * Assign the rpi headers a physical rpi only if the driver
14584 * has not initialized those resources. A port reset only
14585 * needs the headers posted.
14587 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
14589 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14591 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
14592 if (rc
!= MBX_SUCCESS
) {
14593 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14594 "2008 Error %d posting all rpi "
14602 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
14603 LPFC_RPI_RSRC_RDY
);
14608 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14609 * @phba: pointer to lpfc hba data structure.
14610 * @rpi_page: pointer to the rpi memory region.
14612 * This routine is invoked to post a single rpi header to the
14613 * HBA consistent with the SLI-4 interface spec. This memory region
14614 * maps up to 64 rpi context regions.
14618 * -ENOMEM - No available memory
14619 * -EIO - The mailbox failed to complete successfully.
14622 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
14624 LPFC_MBOXQ_t
*mboxq
;
14625 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
14627 uint32_t shdr_status
, shdr_add_status
;
14628 union lpfc_sli4_cfg_shdr
*shdr
;
14630 /* SLI4 ports that support extents do not require RPI headers. */
14631 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14633 if (phba
->sli4_hba
.extents_in_use
)
14636 /* The port is notified of the header region via a mailbox command. */
14637 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14639 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14640 "2001 Unable to allocate memory for issuing "
14641 "SLI_CONFIG_SPECIAL mailbox command\n");
14645 /* Post all rpi memory regions to the port. */
14646 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
14647 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14648 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
14649 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
14650 sizeof(struct lpfc_sli4_cfg_mhdr
),
14651 LPFC_SLI4_MBX_EMBED
);
14654 /* Post the physical rpi to the port for this rpi header. */
14655 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
14656 rpi_page
->start_rpi
);
14657 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
14658 hdr_tmpl
, rpi_page
->page_count
);
14660 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
14661 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
14662 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
14663 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
14664 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14665 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14666 if (rc
!= MBX_TIMEOUT
)
14667 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14668 if (shdr_status
|| shdr_add_status
|| rc
) {
14669 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14670 "2514 POST_RPI_HDR mailbox failed with "
14671 "status x%x add_status x%x, mbx status x%x\n",
14672 shdr_status
, shdr_add_status
, rc
);
14679 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14680 * @phba: pointer to lpfc hba data structure.
14682 * This routine is invoked to post rpi header templates to the
14683 * HBA consistent with the SLI-4 interface spec. This routine
14684 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14685 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14688 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14689 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14692 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
14695 uint16_t max_rpi
, rpi_limit
;
14696 uint16_t rpi_remaining
, lrpi
= 0;
14697 struct lpfc_rpi_hdr
*rpi_hdr
;
14699 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
14700 rpi_limit
= phba
->sli4_hba
.next_rpi
;
14703 * Fetch the next logical rpi. Because this index is logical,
14704 * the driver starts at 0 each time.
14706 spin_lock_irq(&phba
->hbalock
);
14707 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
14708 if (rpi
>= rpi_limit
)
14709 rpi
= LPFC_RPI_ALLOC_ERROR
;
14711 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
14712 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
14713 phba
->sli4_hba
.rpi_count
++;
14717 * Don't try to allocate more rpi header regions if the device limit
14718 * has been exhausted.
14720 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
14721 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
14722 spin_unlock_irq(&phba
->hbalock
);
14727 * RPI header postings are not required for SLI4 ports capable of
14730 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
14731 spin_unlock_irq(&phba
->hbalock
);
14736 * If the driver is running low on rpi resources, allocate another
14737 * page now. Note that the next_rpi value is used because
14738 * it represents how many are actually in use whereas max_rpi notes
14739 * how many are supported max by the device.
14741 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
14742 spin_unlock_irq(&phba
->hbalock
);
14743 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
14744 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
14746 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14747 "2002 Error Could not grow rpi "
14750 lrpi
= rpi_hdr
->start_rpi
;
14751 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14752 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
14760 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14761 * @phba: pointer to lpfc hba data structure.
14763 * This routine is invoked to release an rpi to the pool of
14764 * available rpis maintained by the driver.
14767 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14769 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
14770 phba
->sli4_hba
.rpi_count
--;
14771 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
14776 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14777 * @phba: pointer to lpfc hba data structure.
14779 * This routine is invoked to release an rpi to the pool of
14780 * available rpis maintained by the driver.
14783 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14785 spin_lock_irq(&phba
->hbalock
);
14786 __lpfc_sli4_free_rpi(phba
, rpi
);
14787 spin_unlock_irq(&phba
->hbalock
);
14791 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14792 * @phba: pointer to lpfc hba data structure.
14794 * This routine is invoked to remove the memory region that
14795 * provided rpi via a bitmask.
14798 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
14800 kfree(phba
->sli4_hba
.rpi_bmask
);
14801 kfree(phba
->sli4_hba
.rpi_ids
);
14802 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
14806 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14807 * @phba: pointer to lpfc hba data structure.
14809 * This routine is invoked to remove the memory region that
14810 * provided rpi via a bitmask.
14813 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
14814 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
14816 LPFC_MBOXQ_t
*mboxq
;
14817 struct lpfc_hba
*phba
= ndlp
->phba
;
14820 /* The port is notified of the header region via a mailbox command. */
14821 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14825 /* Post all rpi memory regions to the port. */
14826 lpfc_resume_rpi(mboxq
, ndlp
);
14828 mboxq
->mbox_cmpl
= cmpl
;
14829 mboxq
->context1
= arg
;
14830 mboxq
->context2
= ndlp
;
14832 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14833 mboxq
->vport
= ndlp
->vport
;
14834 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14835 if (rc
== MBX_NOT_FINISHED
) {
14836 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14837 "2010 Resume RPI Mailbox failed "
14838 "status %d, mbxStatus x%x\n", rc
,
14839 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14840 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14847 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14848 * @vport: Pointer to the vport for which the vpi is being initialized
14850 * This routine is invoked to activate a vpi with the port.
14854 * -Evalue otherwise
14857 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
14859 LPFC_MBOXQ_t
*mboxq
;
14861 int retval
= MBX_SUCCESS
;
14863 struct lpfc_hba
*phba
= vport
->phba
;
14864 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14867 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
14868 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
14869 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
14870 if (rc
!= MBX_SUCCESS
) {
14871 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
14872 "2022 INIT VPI Mailbox failed "
14873 "status %d, mbxStatus x%x\n", rc
,
14874 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14877 if (rc
!= MBX_TIMEOUT
)
14878 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
14884 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14885 * @phba: pointer to lpfc hba data structure.
14886 * @mboxq: Pointer to mailbox object.
14888 * This routine is invoked to manually add a single FCF record. The caller
14889 * must pass a completely initialized FCF_Record. This routine takes
14890 * care of the nonembedded mailbox operations.
14893 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
14896 union lpfc_sli4_cfg_shdr
*shdr
;
14897 uint32_t shdr_status
, shdr_add_status
;
14899 virt_addr
= mboxq
->sge_array
->addr
[0];
14900 /* The IOCTL status is embedded in the mailbox subheader. */
14901 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
14902 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14903 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14905 if ((shdr_status
|| shdr_add_status
) &&
14906 (shdr_status
!= STATUS_FCF_IN_USE
))
14907 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14908 "2558 ADD_FCF_RECORD mailbox failed with "
14909 "status x%x add_status x%x\n",
14910 shdr_status
, shdr_add_status
);
14912 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14916 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14917 * @phba: pointer to lpfc hba data structure.
14918 * @fcf_record: pointer to the initialized fcf record to add.
14920 * This routine is invoked to manually add a single FCF record. The caller
14921 * must pass a completely initialized FCF_Record. This routine takes
14922 * care of the nonembedded mailbox operations.
14925 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
14928 LPFC_MBOXQ_t
*mboxq
;
14931 dma_addr_t phys_addr
;
14932 struct lpfc_mbx_sge sge
;
14933 uint32_t alloc_len
, req_len
;
14936 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14938 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14939 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14943 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
14946 /* Allocate DMA memory and set up the non-embedded mailbox command */
14947 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14948 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
14949 req_len
, LPFC_SLI4_MBX_NEMBED
);
14950 if (alloc_len
< req_len
) {
14951 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14952 "2523 Allocated DMA memory size (x%x) is "
14953 "less than the requested DMA memory "
14954 "size (x%x)\n", alloc_len
, req_len
);
14955 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14960 * Get the first SGE entry from the non-embedded DMA memory. This
14961 * routine only uses a single SGE.
14963 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
14964 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
14965 virt_addr
= mboxq
->sge_array
->addr
[0];
14967 * Configure the FCF record for FCFI 0. This is the driver's
14968 * hardcoded default and gets used in nonFIP mode.
14970 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
14971 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
14972 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
14975 * Copy the fcf_index and the FCF Record Data. The data starts after
14976 * the FCoE header plus word10. The data copy needs to be endian
14979 bytep
+= sizeof(uint32_t);
14980 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
14981 mboxq
->vport
= phba
->pport
;
14982 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
14983 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14984 if (rc
== MBX_NOT_FINISHED
) {
14985 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14986 "2515 ADD_FCF_RECORD mailbox failed with "
14987 "status 0x%x\n", rc
);
14988 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14997 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
14998 * @phba: pointer to lpfc hba data structure.
14999 * @fcf_record: pointer to the fcf record to write the default data.
15000 * @fcf_index: FCF table entry index.
15002 * This routine is invoked to build the driver's default FCF record. The
15003 * values used are hardcoded. This routine handles memory initialization.
15007 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
15008 struct fcf_record
*fcf_record
,
15009 uint16_t fcf_index
)
15011 memset(fcf_record
, 0, sizeof(struct fcf_record
));
15012 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
15013 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
15014 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
15015 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
15016 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
15017 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
15018 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
15019 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
15020 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
15021 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
15022 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
15023 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
15024 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
15025 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
15026 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
15027 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
15028 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
15029 /* Set the VLAN bit map */
15030 if (phba
->valid_vlan
) {
15031 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
15032 = 1 << (phba
->vlan_id
% 8);
15037 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
15038 * @phba: pointer to lpfc hba data structure.
15039 * @fcf_index: FCF table entry offset.
15041 * This routine is invoked to scan the entire FCF table by reading FCF
15042 * record and processing it one at a time starting from the @fcf_index
15043 * for initial FCF discovery or fast FCF failover rediscovery.
15045 * Return 0 if the mailbox command is submitted successfully, none 0
15049 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15052 LPFC_MBOXQ_t
*mboxq
;
15054 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
15055 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
15056 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15058 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15059 "2000 Failed to allocate mbox for "
15062 goto fail_fcf_scan
;
15064 /* Construct the read FCF record mailbox command */
15065 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15068 goto fail_fcf_scan
;
15070 /* Issue the mailbox command asynchronously */
15071 mboxq
->vport
= phba
->pport
;
15072 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
15074 spin_lock_irq(&phba
->hbalock
);
15075 phba
->hba_flag
|= FCF_TS_INPROG
;
15076 spin_unlock_irq(&phba
->hbalock
);
15078 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15079 if (rc
== MBX_NOT_FINISHED
)
15082 /* Reset eligible FCF count for new scan */
15083 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
15084 phba
->fcf
.eligible_fcf_cnt
= 0;
15090 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15091 /* FCF scan failed, clear FCF_TS_INPROG flag */
15092 spin_lock_irq(&phba
->hbalock
);
15093 phba
->hba_flag
&= ~FCF_TS_INPROG
;
15094 spin_unlock_irq(&phba
->hbalock
);
15100 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15101 * @phba: pointer to lpfc hba data structure.
15102 * @fcf_index: FCF table entry offset.
15104 * This routine is invoked to read an FCF record indicated by @fcf_index
15105 * and to use it for FLOGI roundrobin FCF failover.
15107 * Return 0 if the mailbox command is submitted successfully, none 0
15111 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15114 LPFC_MBOXQ_t
*mboxq
;
15116 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15118 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15119 "2763 Failed to allocate mbox for "
15122 goto fail_fcf_read
;
15124 /* Construct the read FCF record mailbox command */
15125 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15128 goto fail_fcf_read
;
15130 /* Issue the mailbox command asynchronously */
15131 mboxq
->vport
= phba
->pport
;
15132 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
15133 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15134 if (rc
== MBX_NOT_FINISHED
)
15140 if (error
&& mboxq
)
15141 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15146 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15147 * @phba: pointer to lpfc hba data structure.
15148 * @fcf_index: FCF table entry offset.
15150 * This routine is invoked to read an FCF record indicated by @fcf_index to
15151 * determine whether it's eligible for FLOGI roundrobin failover list.
15153 * Return 0 if the mailbox command is submitted successfully, none 0
15157 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15160 LPFC_MBOXQ_t
*mboxq
;
15162 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15164 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15165 "2758 Failed to allocate mbox for "
15168 goto fail_fcf_read
;
15170 /* Construct the read FCF record mailbox command */
15171 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15174 goto fail_fcf_read
;
15176 /* Issue the mailbox command asynchronously */
15177 mboxq
->vport
= phba
->pport
;
15178 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
15179 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15180 if (rc
== MBX_NOT_FINISHED
)
15186 if (error
&& mboxq
)
15187 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15192 * lpfc_check_next_fcf_pri
15193 * phba pointer to the lpfc_hba struct for this port.
15194 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15195 * routine when the rr_bmask is empty. The FCF indecies are put into the
15196 * rr_bmask based on their priority level. Starting from the highest priority
15197 * to the lowest. The most likely FCF candidate will be in the highest
15198 * priority group. When this routine is called it searches the fcf_pri list for
15199 * next lowest priority group and repopulates the rr_bmask with only those
15202 * 1=success 0=failure
15205 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15207 uint16_t next_fcf_pri
;
15208 uint16_t last_index
;
15209 struct lpfc_fcf_pri
*fcf_pri
;
15213 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15214 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15215 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15216 "3060 Last IDX %d\n", last_index
);
15217 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
15218 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15219 "3061 Last IDX %d\n", last_index
);
15220 return 0; /* Empty rr list */
15224 * Clear the rr_bmask and set all of the bits that are at this
15227 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15228 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15229 spin_lock_irq(&phba
->hbalock
);
15230 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15231 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15234 * the 1st priority that has not FLOGI failed
15235 * will be the highest.
15238 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15239 spin_unlock_irq(&phba
->hbalock
);
15240 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15241 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15242 fcf_pri
->fcf_rec
.fcf_index
);
15246 spin_lock_irq(&phba
->hbalock
);
15249 * if next_fcf_pri was not set above and the list is not empty then
15250 * we have failed flogis on all of them. So reset flogi failed
15251 * and start at the begining.
15253 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15254 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15255 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15257 * the 1st priority that has not FLOGI failed
15258 * will be the highest.
15261 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15262 spin_unlock_irq(&phba
->hbalock
);
15263 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15264 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15265 fcf_pri
->fcf_rec
.fcf_index
);
15269 spin_lock_irq(&phba
->hbalock
);
15273 spin_unlock_irq(&phba
->hbalock
);
15278 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15279 * @phba: pointer to lpfc hba data structure.
15281 * This routine is to get the next eligible FCF record index in a round
15282 * robin fashion. If the next eligible FCF record index equals to the
15283 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15284 * shall be returned, otherwise, the next eligible FCF record's index
15285 * shall be returned.
15288 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15290 uint16_t next_fcf_index
;
15292 /* Search start from next bit of currently registered FCF index */
15294 next_fcf_index
= (phba
->fcf
.current_rec
.fcf_indx
+ 1) %
15295 LPFC_SLI4_FCF_TBL_INDX_MAX
;
15296 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15297 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15300 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15301 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15303 * If we have wrapped then we need to clear the bits that
15304 * have been tested so that we can detect when we should
15305 * change the priority level.
15307 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15308 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15312 /* Check roundrobin failover list empty condition */
15313 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15314 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15316 * If next fcf index is not found check if there are lower
15317 * Priority level fcf's in the fcf_priority list.
15318 * Set up the rr_bmask with all of the avaiable fcf bits
15319 * at that level and continue the selection process.
15321 if (lpfc_check_next_fcf_pri_level(phba
))
15322 goto next_priority
;
15323 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15324 "2844 No roundrobin failover FCF available\n");
15325 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15326 return LPFC_FCOE_FCF_NEXT_NONE
;
15328 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15329 "3063 Only FCF available idx %d, flag %x\n",
15331 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15332 return next_fcf_index
;
15336 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15337 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15338 LPFC_FCF_FLOGI_FAILED
)
15339 goto next_priority
;
15341 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15342 "2845 Get next roundrobin failover FCF (x%x)\n",
15345 return next_fcf_index
;
15349 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15350 * @phba: pointer to lpfc hba data structure.
15352 * This routine sets the FCF record index in to the eligible bmask for
15353 * roundrobin failover search. It checks to make sure that the index
15354 * does not go beyond the range of the driver allocated bmask dimension
15355 * before setting the bit.
15357 * Returns 0 if the index bit successfully set, otherwise, it returns
15361 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15363 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15364 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15365 "2610 FCF (x%x) reached driver's book "
15366 "keeping dimension:x%x\n",
15367 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15370 /* Set the eligible FCF record index bmask */
15371 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15373 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15374 "2790 Set FCF (x%x) to roundrobin FCF failover "
15375 "bmask\n", fcf_index
);
15381 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15382 * @phba: pointer to lpfc hba data structure.
15384 * This routine clears the FCF record index from the eligible bmask for
15385 * roundrobin failover search. It checks to make sure that the index
15386 * does not go beyond the range of the driver allocated bmask dimension
15387 * before clearing the bit.
15390 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15392 struct lpfc_fcf_pri
*fcf_pri
;
15393 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15394 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15395 "2762 FCF (x%x) reached driver's book "
15396 "keeping dimension:x%x\n",
15397 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15400 /* Clear the eligible FCF record index bmask */
15401 spin_lock_irq(&phba
->hbalock
);
15402 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15403 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15404 list_del_init(&fcf_pri
->list
);
15408 spin_unlock_irq(&phba
->hbalock
);
15409 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15411 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15412 "2791 Clear FCF (x%x) from roundrobin failover "
15413 "bmask\n", fcf_index
);
15417 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15418 * @phba: pointer to lpfc hba data structure.
15420 * This routine is the completion routine for the rediscover FCF table mailbox
15421 * command. If the mailbox command returned failure, it will try to stop the
15422 * FCF rediscover wait timer.
15425 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
15427 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15428 uint32_t shdr_status
, shdr_add_status
;
15430 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15432 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
15433 &redisc_fcf
->header
.cfg_shdr
.response
);
15434 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
15435 &redisc_fcf
->header
.cfg_shdr
.response
);
15436 if (shdr_status
|| shdr_add_status
) {
15437 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15438 "2746 Requesting for FCF rediscovery failed "
15439 "status x%x add_status x%x\n",
15440 shdr_status
, shdr_add_status
);
15441 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
15442 spin_lock_irq(&phba
->hbalock
);
15443 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
15444 spin_unlock_irq(&phba
->hbalock
);
15446 * CVL event triggered FCF rediscover request failed,
15447 * last resort to re-try current registered FCF entry.
15449 lpfc_retry_pport_discovery(phba
);
15451 spin_lock_irq(&phba
->hbalock
);
15452 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
15453 spin_unlock_irq(&phba
->hbalock
);
15455 * DEAD FCF event triggered FCF rediscover request
15456 * failed, last resort to fail over as a link down
15457 * to FCF registration.
15459 lpfc_sli4_fcf_dead_failthrough(phba
);
15462 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15463 "2775 Start FCF rediscover quiescent timer\n");
15465 * Start FCF rediscovery wait timer for pending FCF
15466 * before rescan FCF record table.
15468 lpfc_fcf_redisc_wait_start_timer(phba
);
15471 mempool_free(mbox
, phba
->mbox_mem_pool
);
15475 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15476 * @phba: pointer to lpfc hba data structure.
15478 * This routine is invoked to request for rediscovery of the entire FCF table
15482 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
15484 LPFC_MBOXQ_t
*mbox
;
15485 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15488 /* Cancel retry delay timers to all vports before FCF rediscover */
15489 lpfc_cancel_all_vport_retry_delay_timer(phba
);
15491 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15493 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15494 "2745 Failed to allocate mbox for "
15495 "requesting FCF rediscover.\n");
15499 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
15500 sizeof(struct lpfc_sli4_cfg_mhdr
));
15501 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15502 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
15503 length
, LPFC_SLI4_MBX_EMBED
);
15505 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15506 /* Set count to 0 for invalidating the entire FCF database */
15507 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
15509 /* Issue the mailbox command asynchronously */
15510 mbox
->vport
= phba
->pport
;
15511 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
15512 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
15514 if (rc
== MBX_NOT_FINISHED
) {
15515 mempool_free(mbox
, phba
->mbox_mem_pool
);
15522 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15523 * @phba: pointer to lpfc hba data structure.
15525 * This function is the failover routine as a last resort to the FCF DEAD
15526 * event when driver failed to perform fast FCF failover.
15529 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
15531 uint32_t link_state
;
15534 * Last resort as FCF DEAD event failover will treat this as
15535 * a link down, but save the link state because we don't want
15536 * it to be changed to Link Down unless it is already down.
15538 link_state
= phba
->link_state
;
15539 lpfc_linkdown(phba
);
15540 phba
->link_state
= link_state
;
15542 /* Unregister FCF if no devices connected to it */
15543 lpfc_unregister_unused_fcf(phba
);
15547 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15548 * @phba: pointer to lpfc hba data structure.
15549 * @rgn23_data: pointer to configure region 23 data.
15551 * This function gets SLI3 port configure region 23 data through memory dump
15552 * mailbox command. When it successfully retrieves data, the size of the data
15553 * will be returned, otherwise, 0 will be returned.
15556 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15558 LPFC_MBOXQ_t
*pmb
= NULL
;
15560 uint32_t offset
= 0;
15566 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15568 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15569 "2600 failed to allocate mailbox memory\n");
15575 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
15576 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
15578 if (rc
!= MBX_SUCCESS
) {
15579 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15580 "2601 failed to read config "
15581 "region 23, rc 0x%x Status 0x%x\n",
15582 rc
, mb
->mbxStatus
);
15583 mb
->un
.varDmp
.word_cnt
= 0;
15586 * dump mem may return a zero when finished or we got a
15587 * mailbox error, either way we are done.
15589 if (mb
->un
.varDmp
.word_cnt
== 0)
15591 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
15592 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
15594 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
15595 rgn23_data
+ offset
,
15596 mb
->un
.varDmp
.word_cnt
);
15597 offset
+= mb
->un
.varDmp
.word_cnt
;
15598 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
15600 mempool_free(pmb
, phba
->mbox_mem_pool
);
15605 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15606 * @phba: pointer to lpfc hba data structure.
15607 * @rgn23_data: pointer to configure region 23 data.
15609 * This function gets SLI4 port configure region 23 data through memory dump
15610 * mailbox command. When it successfully retrieves data, the size of the data
15611 * will be returned, otherwise, 0 will be returned.
15614 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15616 LPFC_MBOXQ_t
*mboxq
= NULL
;
15617 struct lpfc_dmabuf
*mp
= NULL
;
15618 struct lpfc_mqe
*mqe
;
15619 uint32_t data_length
= 0;
15625 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15627 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15628 "3105 failed to allocate mailbox memory\n");
15632 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
15634 mqe
= &mboxq
->u
.mqe
;
15635 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
15636 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15639 data_length
= mqe
->un
.mb_words
[5];
15640 if (data_length
== 0)
15642 if (data_length
> DMP_RGN23_SIZE
) {
15646 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
15648 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15650 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15653 return data_length
;
15657 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15658 * @phba: pointer to lpfc hba data structure.
15660 * This function read region 23 and parse TLV for port status to
15661 * decide if the user disaled the port. If the TLV indicates the
15662 * port is disabled, the hba_flag is set accordingly.
15665 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
15667 uint8_t *rgn23_data
= NULL
;
15668 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
15669 uint32_t offset
= 0;
15671 /* Get adapter Region 23 data */
15672 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
15676 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15677 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
15679 if_type
= bf_get(lpfc_sli_intf_if_type
,
15680 &phba
->sli4_hba
.sli_intf
);
15681 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
15683 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
15689 /* Check the region signature first */
15690 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
15691 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15692 "2619 Config region 23 has bad signature\n");
15697 /* Check the data structure version */
15698 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
15699 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15700 "2620 Config region 23 has bad version\n");
15705 /* Parse TLV entries in the region */
15706 while (offset
< data_size
) {
15707 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
15710 * If the TLV is not driver specific TLV or driver id is
15711 * not linux driver id, skip the record.
15713 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
15714 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
15715 (rgn23_data
[offset
+ 3] != 0)) {
15716 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15720 /* Driver found a driver specific TLV in the config region */
15721 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
15726 * Search for configured port state sub-TLV.
15728 while ((offset
< data_size
) &&
15729 (tlv_offset
< sub_tlv_len
)) {
15730 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
15735 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
15736 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15737 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15741 /* This HBA contains PORT_STE configured */
15742 if (!rgn23_data
[offset
+ 2])
15743 phba
->hba_flag
|= LINK_DISABLED
;
15755 * lpfc_wr_object - write an object to the firmware
15756 * @phba: HBA structure that indicates port to create a queue on.
15757 * @dmabuf_list: list of dmabufs to write to the port.
15758 * @size: the total byte value of the objects to write to the port.
15759 * @offset: the current offset to be used to start the transfer.
15761 * This routine will create a wr_object mailbox command to send to the port.
15762 * the mailbox command will be constructed using the dma buffers described in
15763 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
15764 * BDEs that the imbedded mailbox can support. The @offset variable will be
15765 * used to indicate the starting offset of the transfer and will also return
15766 * the offset after the write object mailbox has completed. @size is used to
15767 * determine the end of the object and whether the eof bit should be set.
15769 * Return 0 is successful and offset will contain the the new offset to use
15770 * for the next write.
15771 * Return negative value for error cases.
15774 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
15775 uint32_t size
, uint32_t *offset
)
15777 struct lpfc_mbx_wr_object
*wr_object
;
15778 LPFC_MBOXQ_t
*mbox
;
15780 uint32_t shdr_status
, shdr_add_status
;
15782 union lpfc_sli4_cfg_shdr
*shdr
;
15783 struct lpfc_dmabuf
*dmabuf
;
15784 uint32_t written
= 0;
15786 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15790 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15791 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
15792 sizeof(struct lpfc_mbx_wr_object
) -
15793 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15795 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
15796 wr_object
->u
.request
.write_offset
= *offset
;
15797 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
15798 wr_object
->u
.request
.object_name
[0] =
15799 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
15800 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
15801 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
15802 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
15804 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
15805 wr_object
->u
.request
.bde
[i
].addrHigh
=
15806 putPaddrHigh(dmabuf
->phys
);
15807 if (written
+ SLI4_PAGE_SIZE
>= size
) {
15808 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15810 written
+= (size
- written
);
15811 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
15813 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15815 written
+= SLI4_PAGE_SIZE
;
15819 wr_object
->u
.request
.bde_count
= i
;
15820 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
15821 if (!phba
->sli4_hba
.intr_enable
)
15822 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15824 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15825 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15827 /* The IOCTL status is embedded in the mailbox subheader. */
15828 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
15829 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15830 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15831 if (rc
!= MBX_TIMEOUT
)
15832 mempool_free(mbox
, phba
->mbox_mem_pool
);
15833 if (shdr_status
|| shdr_add_status
|| rc
) {
15834 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15835 "3025 Write Object mailbox failed with "
15836 "status x%x add_status x%x, mbx status x%x\n",
15837 shdr_status
, shdr_add_status
, rc
);
15840 *offset
+= wr_object
->u
.response
.actual_write_length
;
15845 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
15846 * @vport: pointer to vport data structure.
15848 * This function iterate through the mailboxq and clean up all REG_LOGIN
15849 * and REG_VPI mailbox commands associated with the vport. This function
15850 * is called when driver want to restart discovery of the vport due to
15851 * a Clear Virtual Link event.
15854 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
15856 struct lpfc_hba
*phba
= vport
->phba
;
15857 LPFC_MBOXQ_t
*mb
, *nextmb
;
15858 struct lpfc_dmabuf
*mp
;
15859 struct lpfc_nodelist
*ndlp
;
15860 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
15861 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
15862 LIST_HEAD(mbox_cmd_list
);
15863 uint8_t restart_loop
;
15865 /* Clean up internally queued mailbox commands with the vport */
15866 spin_lock_irq(&phba
->hbalock
);
15867 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
15868 if (mb
->vport
!= vport
)
15871 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15872 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15875 list_del(&mb
->list
);
15876 list_add_tail(&mb
->list
, &mbox_cmd_list
);
15878 /* Clean up active mailbox command with the vport */
15879 mb
= phba
->sli
.mbox_active
;
15880 if (mb
&& (mb
->vport
== vport
)) {
15881 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
15882 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
15883 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15884 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15885 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15886 /* Put reference count for delayed processing */
15887 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
15888 /* Unregister the RPI when mailbox complete */
15889 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15892 /* Cleanup any mailbox completions which are not yet processed */
15895 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
15897 * If this mailox is already processed or it is
15898 * for another vport ignore it.
15900 if ((mb
->vport
!= vport
) ||
15901 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
15904 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15905 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15908 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15909 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15910 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15911 /* Unregister the RPI when mailbox complete */
15912 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15914 spin_unlock_irq(&phba
->hbalock
);
15915 spin_lock(shost
->host_lock
);
15916 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15917 spin_unlock(shost
->host_lock
);
15918 spin_lock_irq(&phba
->hbalock
);
15922 } while (restart_loop
);
15924 spin_unlock_irq(&phba
->hbalock
);
15926 /* Release the cleaned-up mailbox commands */
15927 while (!list_empty(&mbox_cmd_list
)) {
15928 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
15929 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15930 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
15932 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15935 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
15936 mb
->context2
= NULL
;
15938 spin_lock(shost
->host_lock
);
15939 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15940 spin_unlock(shost
->host_lock
);
15941 lpfc_nlp_put(ndlp
);
15944 mempool_free(mb
, phba
->mbox_mem_pool
);
15947 /* Release the ndlp with the cleaned-up active mailbox command */
15948 if (act_mbx_ndlp
) {
15949 spin_lock(shost
->host_lock
);
15950 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15951 spin_unlock(shost
->host_lock
);
15952 lpfc_nlp_put(act_mbx_ndlp
);
15957 * lpfc_drain_txq - Drain the txq
15958 * @phba: Pointer to HBA context object.
15960 * This function attempt to submit IOCBs on the txq
15961 * to the adapter. For SLI4 adapters, the txq contains
15962 * ELS IOCBs that have been deferred because the there
15963 * are no SGLs. This congestion can occur with large
15964 * vport counts during node discovery.
15968 lpfc_drain_txq(struct lpfc_hba
*phba
)
15970 LIST_HEAD(completions
);
15971 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
15972 struct lpfc_iocbq
*piocbq
= 0;
15973 unsigned long iflags
= 0;
15974 char *fail_msg
= NULL
;
15975 struct lpfc_sglq
*sglq
;
15976 union lpfc_wqe wqe
;
15978 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15979 if (pring
->txq_cnt
> pring
->txq_max
)
15980 pring
->txq_max
= pring
->txq_cnt
;
15982 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15984 while (pring
->txq_cnt
) {
15985 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15987 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
15988 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
15990 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
15991 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15995 /* The txq_cnt out of sync. This should
15998 sglq
= __lpfc_clear_active_sglq(phba
,
15999 sglq
->sli4_lxritag
);
16000 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16001 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16002 "2823 txq empty and txq_cnt is %d\n ",
16008 /* The xri and iocb resources secured,
16009 * attempt to issue request
16011 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
16012 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
16013 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
16014 fail_msg
= "to convert bpl to sgl";
16015 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
16016 fail_msg
= "to convert iocb to wqe";
16017 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
16018 fail_msg
= " - Wq is full";
16020 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
16023 /* Failed means we can't issue and need to cancel */
16024 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16025 "2822 IOCB failed %s iotag 0x%x "
16028 piocbq
->iotag
, piocbq
->sli4_xritag
);
16029 list_add_tail(&piocbq
->list
, &completions
);
16031 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16034 /* Cancel all the IOCBs that cannot be issued */
16035 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
16036 IOERR_SLI_ABORTED
);
16038 return pring
->txq_cnt
;