1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <linux/aer.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
48 #include "lpfc_vport.h"
50 /* There are only four IOCB completion types. */
51 typedef enum _lpfc_iocb_type
{
59 /* Provide function prototypes local to this module. */
60 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
62 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
63 uint8_t *, uint32_t *);
64 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
66 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*, struct lpfc_queue
*,
70 static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*, struct list_head
*,
74 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
80 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
81 * @q: The Work Queue to operate on.
82 * @wqe: The work Queue Entry to put on the Work queue.
84 * This routine will copy the contents of @wqe to the next available entry on
85 * the @q. This function will then ring the Work Queue Doorbell to signal the
86 * HBA to start processing the Work Queue Entry. This function returns 0 if
87 * successful. If no entries are available on @q then this function will return
89 * The caller is expected to hold the hbalock when calling this routine.
92 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
94 union lpfc_wqe
*temp_wqe
;
95 struct lpfc_register doorbell
;
99 /* sanity check on queue memory */
102 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
104 /* If the host has not yet processed the next entry then we are done */
105 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
106 if (idx
== q
->hba_index
) {
111 /* set consumption flag every once in a while */
112 if (!((q
->host_index
+ 1) % q
->entry_repost
))
113 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
114 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
115 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
116 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
118 /* Update the host index before invoking device */
119 host_index
= q
->host_index
;
125 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
126 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
127 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
128 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
134 * lpfc_sli4_wq_release - Updates internal hba index for WQ
135 * @q: The Work Queue to operate on.
136 * @index: The index to advance the hba index to.
138 * This routine will update the HBA index of a queue to reflect consumption of
139 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
140 * an entry the host calls this function to update the queue's internal
141 * pointers. This routine returns the number of entries that were consumed by
145 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
147 uint32_t released
= 0;
149 /* sanity check on queue memory */
153 if (q
->hba_index
== index
)
156 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
158 } while (q
->hba_index
!= index
);
163 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
164 * @q: The Mailbox Queue to operate on.
165 * @wqe: The Mailbox Queue Entry to put on the Work queue.
167 * This routine will copy the contents of @mqe to the next available entry on
168 * the @q. This function will then ring the Work Queue Doorbell to signal the
169 * HBA to start processing the Work Queue Entry. This function returns 0 if
170 * successful. If no entries are available on @q then this function will return
172 * The caller is expected to hold the hbalock when calling this routine.
175 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
177 struct lpfc_mqe
*temp_mqe
;
178 struct lpfc_register doorbell
;
181 /* sanity check on queue memory */
184 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
186 /* If the host has not yet processed the next entry then we are done */
187 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
189 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
190 /* Save off the mailbox pointer for completion */
191 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
193 /* Update the host index before invoking device */
194 host_index
= q
->host_index
;
195 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
199 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
200 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
201 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
206 * lpfc_sli4_mq_release - Updates internal hba index for MQ
207 * @q: The Mailbox Queue to operate on.
209 * This routine will update the HBA index of a queue to reflect consumption of
210 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
211 * an entry the host calls this function to update the queue's internal
212 * pointers. This routine returns the number of entries that were consumed by
216 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
218 /* sanity check on queue memory */
222 /* Clear the mailbox pointer for completion */
223 q
->phba
->mbox
= NULL
;
224 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
229 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
230 * @q: The Event Queue to get the first valid EQE from
232 * This routine will get the first valid Event Queue Entry from @q, update
233 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
234 * the Queue (no more work to do), or the Queue is full of EQEs that have been
235 * processed, but not popped back to the HBA then this routine will return NULL.
237 static struct lpfc_eqe
*
238 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
240 struct lpfc_eqe
*eqe
;
243 /* sanity check on queue memory */
246 eqe
= q
->qe
[q
->hba_index
].eqe
;
248 /* If the next EQE is not valid then we are done */
249 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
251 /* If the host has not yet processed the next entry then we are done */
252 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
253 if (idx
== q
->host_index
)
261 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
262 * @q: The Event Queue that the host has completed processing for.
263 * @arm: Indicates whether the host wants to arms this CQ.
265 * This routine will mark all Event Queue Entries on @q, from the last
266 * known completed entry to the last entry that was processed, as completed
267 * by clearing the valid bit for each completion queue entry. Then it will
268 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
269 * The internal host index in the @q will be updated by this routine to indicate
270 * that the host has finished processing the entries. The @arm parameter
271 * indicates that the queue should be rearmed when ringing the doorbell.
273 * This function will return the number of EQEs that were popped.
276 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
278 uint32_t released
= 0;
279 struct lpfc_eqe
*temp_eqe
;
280 struct lpfc_register doorbell
;
282 /* sanity check on queue memory */
286 /* while there are valid entries */
287 while (q
->hba_index
!= q
->host_index
) {
288 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
289 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
291 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
293 if (unlikely(released
== 0 && !arm
))
296 /* ring doorbell for number popped */
299 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
300 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
302 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
303 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
304 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
305 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
306 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
307 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
308 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
309 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
310 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
315 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
316 * @q: The Completion Queue to get the first valid CQE from
318 * This routine will get the first valid Completion Queue Entry from @q, update
319 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
320 * the Queue (no more work to do), or the Queue is full of CQEs that have been
321 * processed, but not popped back to the HBA then this routine will return NULL.
323 static struct lpfc_cqe
*
324 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
326 struct lpfc_cqe
*cqe
;
329 /* sanity check on queue memory */
333 /* If the next CQE is not valid then we are done */
334 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
336 /* If the host has not yet processed the next entry then we are done */
337 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
338 if (idx
== q
->host_index
)
341 cqe
= q
->qe
[q
->hba_index
].cqe
;
347 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
348 * @q: The Completion Queue that the host has completed processing for.
349 * @arm: Indicates whether the host wants to arms this CQ.
351 * This routine will mark all Completion queue entries on @q, from the last
352 * known completed entry to the last entry that was processed, as completed
353 * by clearing the valid bit for each completion queue entry. Then it will
354 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
355 * The internal host index in the @q will be updated by this routine to indicate
356 * that the host has finished processing the entries. The @arm parameter
357 * indicates that the queue should be rearmed when ringing the doorbell.
359 * This function will return the number of CQEs that were released.
362 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
364 uint32_t released
= 0;
365 struct lpfc_cqe
*temp_qe
;
366 struct lpfc_register doorbell
;
368 /* sanity check on queue memory */
371 /* while there are valid entries */
372 while (q
->hba_index
!= q
->host_index
) {
373 temp_qe
= q
->qe
[q
->host_index
].cqe
;
374 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
376 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
378 if (unlikely(released
== 0 && !arm
))
381 /* ring doorbell for number popped */
384 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
385 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
386 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
387 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
388 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
389 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
390 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
395 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
396 * @q: The Header Receive Queue to operate on.
397 * @wqe: The Receive Queue Entry to put on the Receive queue.
399 * This routine will copy the contents of @wqe to the next available entry on
400 * the @q. This function will then ring the Receive Queue Doorbell to signal the
401 * HBA to start processing the Receive Queue Entry. This function returns the
402 * index that the rqe was copied to if successful. If no entries are available
403 * on @q then this function will return -ENOMEM.
404 * The caller is expected to hold the hbalock when calling this routine.
407 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
408 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
410 struct lpfc_rqe
*temp_hrqe
;
411 struct lpfc_rqe
*temp_drqe
;
412 struct lpfc_register doorbell
;
413 int put_index
= hq
->host_index
;
415 /* sanity check on queue memory */
416 if (unlikely(!hq
) || unlikely(!dq
))
418 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
419 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
421 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
423 if (hq
->host_index
!= dq
->host_index
)
425 /* If the host has not yet processed the next entry then we are done */
426 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
428 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
429 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
431 /* Update the host index to point to the next slot */
432 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
433 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
435 /* Ring The Header Receive Queue Doorbell */
436 if (!(hq
->host_index
% hq
->entry_repost
)) {
438 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
440 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
441 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
447 * lpfc_sli4_rq_release - Updates internal hba index for RQ
448 * @q: The Header Receive Queue to operate on.
450 * This routine will update the HBA index of a queue to reflect consumption of
451 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
452 * consumed an entry the host calls this function to update the queue's
453 * internal pointers. This routine returns the number of entries that were
454 * consumed by the HBA.
457 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
459 /* sanity check on queue memory */
460 if (unlikely(!hq
) || unlikely(!dq
))
463 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
465 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
466 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
471 * lpfc_cmd_iocb - Get next command iocb entry in the ring
472 * @phba: Pointer to HBA context object.
473 * @pring: Pointer to driver SLI ring object.
475 * This function returns pointer to next command iocb entry
476 * in the command ring. The caller must hold hbalock to prevent
477 * other threads consume the next command iocb.
478 * SLI-2/SLI-3 provide different sized iocbs.
480 static inline IOCB_t
*
481 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
483 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
484 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
488 * lpfc_resp_iocb - Get next response iocb entry in the ring
489 * @phba: Pointer to HBA context object.
490 * @pring: Pointer to driver SLI ring object.
492 * This function returns pointer to next response iocb entry
493 * in the response ring. The caller must hold hbalock to make sure
494 * that no other thread consume the next response iocb.
495 * SLI-2/SLI-3 provide different sized iocbs.
497 static inline IOCB_t
*
498 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
500 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
501 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
505 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
506 * @phba: Pointer to HBA context object.
508 * This function is called with hbalock held. This function
509 * allocates a new driver iocb object from the iocb pool. If the
510 * allocation is successful, it returns pointer to the newly
511 * allocated iocb object else it returns NULL.
514 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
516 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
517 struct lpfc_iocbq
* iocbq
= NULL
;
519 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
522 if (phba
->iocb_cnt
> phba
->iocb_max
)
523 phba
->iocb_max
= phba
->iocb_cnt
;
528 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
529 * @phba: Pointer to HBA context object.
530 * @xritag: XRI value.
532 * This function clears the sglq pointer from the array of acive
533 * sglq's. The xritag that is passed in is used to index into the
534 * array. Before the xritag can be used it needs to be adjusted
535 * by subtracting the xribase.
537 * Returns sglq ponter = success, NULL = Failure.
539 static struct lpfc_sglq
*
540 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
542 struct lpfc_sglq
*sglq
;
544 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
545 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
550 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
551 * @phba: Pointer to HBA context object.
552 * @xritag: XRI value.
554 * This function returns the sglq pointer from the array of acive
555 * sglq's. The xritag that is passed in is used to index into the
556 * array. Before the xritag can be used it needs to be adjusted
557 * by subtracting the xribase.
559 * Returns sglq ponter = success, NULL = Failure.
562 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
564 struct lpfc_sglq
*sglq
;
566 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
571 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
572 * @phba: Pointer to HBA context object.
573 * @xritag: xri used in this exchange.
574 * @rrq: The RRQ to be cleared.
578 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
580 struct lpfc_node_rrq
*rrq
)
582 struct lpfc_nodelist
*ndlp
= NULL
;
584 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
585 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
587 /* The target DID could have been swapped (cable swap)
588 * we should use the ndlp from the findnode if it is
591 if ((!ndlp
) && rrq
->ndlp
)
597 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
)) {
600 rrq
->rrq_stop_time
= 0;
603 mempool_free(rrq
, phba
->rrq_pool
);
607 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
608 * @phba: Pointer to HBA context object.
610 * This function is called with hbalock held. This function
611 * Checks if stop_time (ratov from setting rrq active) has
612 * been reached, if it has and the send_rrq flag is set then
613 * it will call lpfc_send_rrq. If the send_rrq flag is not set
614 * then it will just call the routine to clear the rrq and
615 * free the rrq resource.
616 * The timer is set to the next rrq that is going to expire before
617 * leaving the routine.
621 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
623 struct lpfc_node_rrq
*rrq
;
624 struct lpfc_node_rrq
*nextrrq
;
625 unsigned long next_time
;
626 unsigned long iflags
;
629 spin_lock_irqsave(&phba
->hbalock
, iflags
);
630 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
631 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
632 list_for_each_entry_safe(rrq
, nextrrq
,
633 &phba
->active_rrq_list
, list
) {
634 if (time_after(jiffies
, rrq
->rrq_stop_time
))
635 list_move(&rrq
->list
, &send_rrq
);
636 else if (time_before(rrq
->rrq_stop_time
, next_time
))
637 next_time
= rrq
->rrq_stop_time
;
639 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
640 if (!list_empty(&phba
->active_rrq_list
))
641 mod_timer(&phba
->rrq_tmr
, next_time
);
642 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
643 list_del(&rrq
->list
);
645 /* this call will free the rrq */
646 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
647 else if (lpfc_send_rrq(phba
, rrq
)) {
648 /* if we send the rrq then the completion handler
649 * will clear the bit in the xribitmap.
651 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
658 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
659 * @vport: Pointer to vport context object.
660 * @xri: The xri used in the exchange.
661 * @did: The targets DID for this exchange.
663 * returns NULL = rrq not found in the phba->active_rrq_list.
664 * rrq = rrq for this xri and target.
666 struct lpfc_node_rrq
*
667 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
669 struct lpfc_hba
*phba
= vport
->phba
;
670 struct lpfc_node_rrq
*rrq
;
671 struct lpfc_node_rrq
*nextrrq
;
672 unsigned long iflags
;
674 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
676 spin_lock_irqsave(&phba
->hbalock
, iflags
);
677 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
678 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
679 rrq
->nlp_DID
== did
){
680 list_del(&rrq
->list
);
681 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
685 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
690 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
691 * @vport: Pointer to vport context object.
692 * @ndlp: Pointer to the lpfc_node_list structure.
693 * If ndlp is NULL Remove all active RRQs for this vport from the
694 * phba->active_rrq_list and clear the rrq.
695 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
698 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
701 struct lpfc_hba
*phba
= vport
->phba
;
702 struct lpfc_node_rrq
*rrq
;
703 struct lpfc_node_rrq
*nextrrq
;
704 unsigned long iflags
;
707 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
710 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
711 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
713 spin_lock_irqsave(&phba
->hbalock
, iflags
);
714 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
715 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
716 list_move(&rrq
->list
, &rrq_list
);
717 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
719 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
720 list_del(&rrq
->list
);
721 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
726 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
727 * @phba: Pointer to HBA context object.
729 * Remove all rrqs from the phba->active_rrq_list and free them by
730 * calling __lpfc_clr_active_rrq
734 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
736 struct lpfc_node_rrq
*rrq
;
737 struct lpfc_node_rrq
*nextrrq
;
738 unsigned long next_time
;
739 unsigned long iflags
;
742 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
744 spin_lock_irqsave(&phba
->hbalock
, iflags
);
745 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
746 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
747 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
748 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
750 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
751 list_del(&rrq
->list
);
752 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
754 if (!list_empty(&phba
->active_rrq_list
))
755 mod_timer(&phba
->rrq_tmr
, next_time
);
760 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
761 * @phba: Pointer to HBA context object.
762 * @ndlp: Targets nodelist pointer for this exchange.
763 * @xritag the xri in the bitmap to test.
765 * This function is called with hbalock held. This function
766 * returns 0 = rrq not active for this xri
767 * 1 = rrq is valid for this xri.
770 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
775 if (test_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
782 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
783 * @phba: Pointer to HBA context object.
784 * @ndlp: nodelist pointer for this target.
785 * @xritag: xri used in this exchange.
786 * @rxid: Remote Exchange ID.
787 * @send_rrq: Flag used to determine if we should send rrq els cmd.
789 * This function takes the hbalock.
790 * The active bit is always set in the active rrq xri_bitmap even
791 * if there is no slot avaiable for the other rrq information.
793 * returns 0 rrq actived for this xri
794 * < 0 No memory or invalid ndlp.
797 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
798 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
800 unsigned long iflags
;
801 struct lpfc_node_rrq
*rrq
;
807 if (!phba
->cfg_enable_rrq
)
810 spin_lock_irqsave(&phba
->hbalock
, iflags
);
811 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
812 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
817 * set the active bit even if there is no mem available.
819 if (NLP_CHK_FREE_REQ(ndlp
))
822 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
825 if (test_and_set_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
828 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
829 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
831 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
832 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
833 " DID:0x%x Send:%d\n",
834 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
837 rrq
->send_rrq
= send_rrq
;
838 rrq
->xritag
= xritag
;
839 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
841 rrq
->nlp_DID
= ndlp
->nlp_DID
;
842 rrq
->vport
= ndlp
->vport
;
844 rrq
->send_rrq
= send_rrq
;
845 spin_lock_irqsave(&phba
->hbalock
, iflags
);
846 empty
= list_empty(&phba
->active_rrq_list
);
847 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
848 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
850 lpfc_worker_wake_up(phba
);
851 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
854 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
855 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
856 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
857 " DID:0x%x Send:%d\n",
858 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
863 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
864 * @phba: Pointer to HBA context object.
865 * @piocb: Pointer to the iocbq.
867 * This function is called with hbalock held. This function
868 * gets a new driver sglq object from the sglq list. If the
869 * list is not empty then it is successful, it returns pointer to the newly
870 * allocated sglq object else it returns NULL.
872 static struct lpfc_sglq
*
873 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
875 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
876 struct lpfc_sglq
*sglq
= NULL
;
877 struct lpfc_sglq
*start_sglq
= NULL
;
878 struct lpfc_scsi_buf
*lpfc_cmd
;
879 struct lpfc_nodelist
*ndlp
;
882 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
883 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
884 ndlp
= lpfc_cmd
->rdata
->pnode
;
885 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
886 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
887 ndlp
= piocbq
->context_un
.ndlp
;
888 else if ((piocbq
->iocb
.ulpCommand
== CMD_ELS_REQUEST64_CR
) &&
889 (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
890 ndlp
= piocbq
->context_un
.ndlp
;
892 ndlp
= piocbq
->context1
;
894 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
899 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_lxritag
)) {
900 /* This xri has an rrq outstanding for this DID.
901 * put it back in the list and get another xri.
903 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
905 list_remove_head(lpfc_sgl_list
, sglq
,
906 struct lpfc_sglq
, list
);
907 if (sglq
== start_sglq
) {
915 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
916 sglq
->state
= SGL_ALLOCATED
;
922 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
923 * @phba: Pointer to HBA context object.
925 * This function is called with no lock held. This function
926 * allocates a new driver iocb object from the iocb pool. If the
927 * allocation is successful, it returns pointer to the newly
928 * allocated iocb object else it returns NULL.
931 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
933 struct lpfc_iocbq
* iocbq
= NULL
;
934 unsigned long iflags
;
936 spin_lock_irqsave(&phba
->hbalock
, iflags
);
937 iocbq
= __lpfc_sli_get_iocbq(phba
);
938 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
943 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
944 * @phba: Pointer to HBA context object.
945 * @iocbq: Pointer to driver iocb object.
947 * This function is called with hbalock held to release driver
948 * iocb object to the iocb pool. The iotag in the iocb object
949 * does not change for each use of the iocb object. This function
950 * clears all other fields of the iocb object when it is freed.
951 * The sqlq structure that holds the xritag and phys and virtual
952 * mappings for the scatter gather list is retrieved from the
953 * active array of sglq. The get of the sglq pointer also clears
954 * the entry in the array. If the status of the IO indiactes that
955 * this IO was aborted then the sglq entry it put on the
956 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
957 * IO has good status or fails for any other reason then the sglq
958 * entry is added to the free list (lpfc_sgl_list).
961 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
963 struct lpfc_sglq
*sglq
;
964 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
965 unsigned long iflag
= 0;
966 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
968 if (iocbq
->sli4_xritag
== NO_XRI
)
971 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
974 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
975 (sglq
->state
!= SGL_XRI_ABORTED
)) {
976 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
978 list_add(&sglq
->list
,
979 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
980 spin_unlock_irqrestore(
981 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
983 sglq
->state
= SGL_FREED
;
985 list_add_tail(&sglq
->list
,
986 &phba
->sli4_hba
.lpfc_sgl_list
);
988 /* Check if TXQ queue needs to be serviced */
990 lpfc_worker_wake_up(phba
);
996 * Clean all volatile data fields, preserve iotag and node struct.
998 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
999 iocbq
->sli4_lxritag
= NO_XRI
;
1000 iocbq
->sli4_xritag
= NO_XRI
;
1001 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1006 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1007 * @phba: Pointer to HBA context object.
1008 * @iocbq: Pointer to driver iocb object.
1010 * This function is called with hbalock held to release driver
1011 * iocb object to the iocb pool. The iotag in the iocb object
1012 * does not change for each use of the iocb object. This function
1013 * clears all other fields of the iocb object when it is freed.
1016 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1018 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1021 * Clean all volatile data fields, preserve iotag and node struct.
1023 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1024 iocbq
->sli4_xritag
= NO_XRI
;
1025 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1029 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1030 * @phba: Pointer to HBA context object.
1031 * @iocbq: Pointer to driver iocb object.
1033 * This function is called with hbalock held to release driver
1034 * iocb object to the iocb pool. The iotag in the iocb object
1035 * does not change for each use of the iocb object. This function
1036 * clears all other fields of the iocb object when it is freed.
1039 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1041 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1046 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1047 * @phba: Pointer to HBA context object.
1048 * @iocbq: Pointer to driver iocb object.
1050 * This function is called with no lock held to release the iocb to
1054 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1056 unsigned long iflags
;
1059 * Clean all volatile data fields, preserve iotag and node struct.
1061 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1062 __lpfc_sli_release_iocbq(phba
, iocbq
);
1063 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1067 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1068 * @phba: Pointer to HBA context object.
1069 * @iocblist: List of IOCBs.
1070 * @ulpstatus: ULP status in IOCB command field.
1071 * @ulpWord4: ULP word-4 in IOCB command field.
1073 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1074 * on the list by invoking the complete callback function associated with the
1075 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1079 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1080 uint32_t ulpstatus
, uint32_t ulpWord4
)
1082 struct lpfc_iocbq
*piocb
;
1084 while (!list_empty(iocblist
)) {
1085 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1087 if (!piocb
->iocb_cmpl
)
1088 lpfc_sli_release_iocbq(phba
, piocb
);
1090 piocb
->iocb
.ulpStatus
= ulpstatus
;
1091 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1092 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1099 * lpfc_sli_iocb_cmd_type - Get the iocb type
1100 * @iocb_cmnd: iocb command code.
1102 * This function is called by ring event handler function to get the iocb type.
1103 * This function translates the iocb command to an iocb command type used to
1104 * decide the final disposition of each completed IOCB.
1105 * The function returns
1106 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1107 * LPFC_SOL_IOCB if it is a solicited iocb completion
1108 * LPFC_ABORT_IOCB if it is an abort iocb
1109 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1111 * The caller is not required to hold any lock.
1113 static lpfc_iocb_type
1114 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1116 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1118 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1121 switch (iocb_cmnd
) {
1122 case CMD_XMIT_SEQUENCE_CR
:
1123 case CMD_XMIT_SEQUENCE_CX
:
1124 case CMD_XMIT_BCAST_CN
:
1125 case CMD_XMIT_BCAST_CX
:
1126 case CMD_ELS_REQUEST_CR
:
1127 case CMD_ELS_REQUEST_CX
:
1128 case CMD_CREATE_XRI_CR
:
1129 case CMD_CREATE_XRI_CX
:
1130 case CMD_GET_RPI_CN
:
1131 case CMD_XMIT_ELS_RSP_CX
:
1132 case CMD_GET_RPI_CR
:
1133 case CMD_FCP_IWRITE_CR
:
1134 case CMD_FCP_IWRITE_CX
:
1135 case CMD_FCP_IREAD_CR
:
1136 case CMD_FCP_IREAD_CX
:
1137 case CMD_FCP_ICMND_CR
:
1138 case CMD_FCP_ICMND_CX
:
1139 case CMD_FCP_TSEND_CX
:
1140 case CMD_FCP_TRSP_CX
:
1141 case CMD_FCP_TRECEIVE_CX
:
1142 case CMD_FCP_AUTO_TRSP_CX
:
1143 case CMD_ADAPTER_MSG
:
1144 case CMD_ADAPTER_DUMP
:
1145 case CMD_XMIT_SEQUENCE64_CR
:
1146 case CMD_XMIT_SEQUENCE64_CX
:
1147 case CMD_XMIT_BCAST64_CN
:
1148 case CMD_XMIT_BCAST64_CX
:
1149 case CMD_ELS_REQUEST64_CR
:
1150 case CMD_ELS_REQUEST64_CX
:
1151 case CMD_FCP_IWRITE64_CR
:
1152 case CMD_FCP_IWRITE64_CX
:
1153 case CMD_FCP_IREAD64_CR
:
1154 case CMD_FCP_IREAD64_CX
:
1155 case CMD_FCP_ICMND64_CR
:
1156 case CMD_FCP_ICMND64_CX
:
1157 case CMD_FCP_TSEND64_CX
:
1158 case CMD_FCP_TRSP64_CX
:
1159 case CMD_FCP_TRECEIVE64_CX
:
1160 case CMD_GEN_REQUEST64_CR
:
1161 case CMD_GEN_REQUEST64_CX
:
1162 case CMD_XMIT_ELS_RSP64_CX
:
1163 case DSSCMD_IWRITE64_CR
:
1164 case DSSCMD_IWRITE64_CX
:
1165 case DSSCMD_IREAD64_CR
:
1166 case DSSCMD_IREAD64_CX
:
1167 type
= LPFC_SOL_IOCB
;
1169 case CMD_ABORT_XRI_CN
:
1170 case CMD_ABORT_XRI_CX
:
1171 case CMD_CLOSE_XRI_CN
:
1172 case CMD_CLOSE_XRI_CX
:
1173 case CMD_XRI_ABORTED_CX
:
1174 case CMD_ABORT_MXRI64_CN
:
1175 case CMD_XMIT_BLS_RSP64_CX
:
1176 type
= LPFC_ABORT_IOCB
;
1178 case CMD_RCV_SEQUENCE_CX
:
1179 case CMD_RCV_ELS_REQ_CX
:
1180 case CMD_RCV_SEQUENCE64_CX
:
1181 case CMD_RCV_ELS_REQ64_CX
:
1182 case CMD_ASYNC_STATUS
:
1183 case CMD_IOCB_RCV_SEQ64_CX
:
1184 case CMD_IOCB_RCV_ELS64_CX
:
1185 case CMD_IOCB_RCV_CONT64_CX
:
1186 case CMD_IOCB_RET_XRI64_CX
:
1187 type
= LPFC_UNSOL_IOCB
;
1189 case CMD_IOCB_XMIT_MSEQ64_CR
:
1190 case CMD_IOCB_XMIT_MSEQ64_CX
:
1191 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1192 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1193 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1194 case CMD_IOCB_ABORT_EXTENDED_CN
:
1195 case CMD_IOCB_RET_HBQE64_CN
:
1196 case CMD_IOCB_FCP_IBIDIR64_CR
:
1197 case CMD_IOCB_FCP_IBIDIR64_CX
:
1198 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1199 case CMD_IOCB_LOGENTRY_CN
:
1200 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1201 printk("%s - Unhandled SLI-3 Command x%x\n",
1202 __func__
, iocb_cmnd
);
1203 type
= LPFC_UNKNOWN_IOCB
;
1206 type
= LPFC_UNKNOWN_IOCB
;
1214 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1215 * @phba: Pointer to HBA context object.
1217 * This function is called from SLI initialization code
1218 * to configure every ring of the HBA's SLI interface. The
1219 * caller is not required to hold any lock. This function issues
1220 * a config_ring mailbox command for each ring.
1221 * This function returns zero if successful else returns a negative
1225 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1227 struct lpfc_sli
*psli
= &phba
->sli
;
1232 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1236 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1237 for (i
= 0; i
< psli
->num_rings
; i
++) {
1238 lpfc_config_ring(phba
, i
, pmb
);
1239 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1240 if (rc
!= MBX_SUCCESS
) {
1241 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1242 "0446 Adapter failed to init (%d), "
1243 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1245 rc
, pmbox
->mbxCommand
,
1246 pmbox
->mbxStatus
, i
);
1247 phba
->link_state
= LPFC_HBA_ERROR
;
1252 mempool_free(pmb
, phba
->mbox_mem_pool
);
1257 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1258 * @phba: Pointer to HBA context object.
1259 * @pring: Pointer to driver SLI ring object.
1260 * @piocb: Pointer to the driver iocb object.
1262 * This function is called with hbalock held. The function adds the
1263 * new iocb to txcmplq of the given ring. This function always returns
1264 * 0. If this function is called for ELS ring, this function checks if
1265 * there is a vport associated with the ELS command. This function also
1266 * starts els_tmofunc timer if this is an ELS command.
1269 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1270 struct lpfc_iocbq
*piocb
)
1272 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1273 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1274 pring
->txcmplq_cnt
++;
1275 if (pring
->txcmplq_cnt
> pring
->txcmplq_max
)
1276 pring
->txcmplq_max
= pring
->txcmplq_cnt
;
1278 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1279 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1280 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1284 mod_timer(&piocb
->vport
->els_tmofunc
,
1285 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1293 * lpfc_sli_ringtx_get - Get first element of the txq
1294 * @phba: Pointer to HBA context object.
1295 * @pring: Pointer to driver SLI ring object.
1297 * This function is called with hbalock held to get next
1298 * iocb in txq of the given ring. If there is any iocb in
1299 * the txq, the function returns first iocb in the list after
1300 * removing the iocb from the list, else it returns NULL.
1303 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1305 struct lpfc_iocbq
*cmd_iocb
;
1307 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1308 if (cmd_iocb
!= NULL
)
1314 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1315 * @phba: Pointer to HBA context object.
1316 * @pring: Pointer to driver SLI ring object.
1318 * This function is called with hbalock held and the caller must post the
1319 * iocb without releasing the lock. If the caller releases the lock,
1320 * iocb slot returned by the function is not guaranteed to be available.
1321 * The function returns pointer to the next available iocb slot if there
1322 * is available slot in the ring, else it returns NULL.
1323 * If the get index of the ring is ahead of the put index, the function
1324 * will post an error attention event to the worker thread to take the
1325 * HBA to offline state.
1328 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1330 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1331 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1332 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1333 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1334 pring
->sli
.sli3
.next_cmdidx
= 0;
1336 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1337 pring
->sli
.sli3
.next_cmdidx
)) {
1339 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1341 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1342 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1343 "0315 Ring %d issue: portCmdGet %d "
1344 "is bigger than cmd ring %d\n",
1346 pring
->sli
.sli3
.local_getidx
,
1349 phba
->link_state
= LPFC_HBA_ERROR
;
1351 * All error attention handlers are posted to
1354 phba
->work_ha
|= HA_ERATT
;
1355 phba
->work_hs
= HS_FFER3
;
1357 lpfc_worker_wake_up(phba
);
1362 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1366 return lpfc_cmd_iocb(phba
, pring
);
1370 * lpfc_sli_next_iotag - Get an iotag for the iocb
1371 * @phba: Pointer to HBA context object.
1372 * @iocbq: Pointer to driver iocb object.
1374 * This function gets an iotag for the iocb. If there is no unused iotag and
1375 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1376 * array and assigns a new iotag.
1377 * The function returns the allocated iotag if successful, else returns zero.
1378 * Zero is not a valid iotag.
1379 * The caller is not required to hold any lock.
1382 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1384 struct lpfc_iocbq
**new_arr
;
1385 struct lpfc_iocbq
**old_arr
;
1387 struct lpfc_sli
*psli
= &phba
->sli
;
1390 spin_lock_irq(&phba
->hbalock
);
1391 iotag
= psli
->last_iotag
;
1392 if(++iotag
< psli
->iocbq_lookup_len
) {
1393 psli
->last_iotag
= iotag
;
1394 psli
->iocbq_lookup
[iotag
] = iocbq
;
1395 spin_unlock_irq(&phba
->hbalock
);
1396 iocbq
->iotag
= iotag
;
1398 } else if (psli
->iocbq_lookup_len
< (0xffff
1399 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1400 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1401 spin_unlock_irq(&phba
->hbalock
);
1402 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1405 spin_lock_irq(&phba
->hbalock
);
1406 old_arr
= psli
->iocbq_lookup
;
1407 if (new_len
<= psli
->iocbq_lookup_len
) {
1408 /* highly unprobable case */
1410 iotag
= psli
->last_iotag
;
1411 if(++iotag
< psli
->iocbq_lookup_len
) {
1412 psli
->last_iotag
= iotag
;
1413 psli
->iocbq_lookup
[iotag
] = iocbq
;
1414 spin_unlock_irq(&phba
->hbalock
);
1415 iocbq
->iotag
= iotag
;
1418 spin_unlock_irq(&phba
->hbalock
);
1421 if (psli
->iocbq_lookup
)
1422 memcpy(new_arr
, old_arr
,
1423 ((psli
->last_iotag
+ 1) *
1424 sizeof (struct lpfc_iocbq
*)));
1425 psli
->iocbq_lookup
= new_arr
;
1426 psli
->iocbq_lookup_len
= new_len
;
1427 psli
->last_iotag
= iotag
;
1428 psli
->iocbq_lookup
[iotag
] = iocbq
;
1429 spin_unlock_irq(&phba
->hbalock
);
1430 iocbq
->iotag
= iotag
;
1435 spin_unlock_irq(&phba
->hbalock
);
1437 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1438 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1445 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1446 * @phba: Pointer to HBA context object.
1447 * @pring: Pointer to driver SLI ring object.
1448 * @iocb: Pointer to iocb slot in the ring.
1449 * @nextiocb: Pointer to driver iocb object which need to be
1450 * posted to firmware.
1452 * This function is called with hbalock held to post a new iocb to
1453 * the firmware. This function copies the new iocb to ring iocb slot and
1454 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1455 * a completion call back for this iocb else the function will free the
1459 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1460 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1465 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1468 if (pring
->ringno
== LPFC_ELS_RING
) {
1469 lpfc_debugfs_slow_ring_trc(phba
,
1470 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1471 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1472 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1473 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1477 * Issue iocb command to adapter
1479 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1481 pring
->stats
.iocb_cmd
++;
1484 * If there is no completion routine to call, we can release the
1485 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1486 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1488 if (nextiocb
->iocb_cmpl
)
1489 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1491 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1494 * Let the HBA know what IOCB slot will be the next one the
1495 * driver will put a command into.
1497 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1498 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1502 * lpfc_sli_update_full_ring - Update the chip attention register
1503 * @phba: Pointer to HBA context object.
1504 * @pring: Pointer to driver SLI ring object.
1506 * The caller is not required to hold any lock for calling this function.
1507 * This function updates the chip attention bits for the ring to inform firmware
1508 * that there are pending work to be done for this ring and requests an
1509 * interrupt when there is space available in the ring. This function is
1510 * called when the driver is unable to post more iocbs to the ring due
1511 * to unavailability of space in the ring.
1514 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1516 int ringno
= pring
->ringno
;
1518 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1523 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1524 * The HBA will tell us when an IOCB entry is available.
1526 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1527 readl(phba
->CAregaddr
); /* flush */
1529 pring
->stats
.iocb_cmd_full
++;
1533 * lpfc_sli_update_ring - Update chip attention register
1534 * @phba: Pointer to HBA context object.
1535 * @pring: Pointer to driver SLI ring object.
1537 * This function updates the chip attention register bit for the
1538 * given ring to inform HBA that there is more work to be done
1539 * in this ring. The caller is not required to hold any lock.
1542 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1544 int ringno
= pring
->ringno
;
1547 * Tell the HBA that there is work to do in this ring.
1549 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1551 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1552 readl(phba
->CAregaddr
); /* flush */
1557 * lpfc_sli_resume_iocb - Process iocbs in the txq
1558 * @phba: Pointer to HBA context object.
1559 * @pring: Pointer to driver SLI ring object.
1561 * This function is called with hbalock held to post pending iocbs
1562 * in the txq to the firmware. This function is called when driver
1563 * detects space available in the ring.
1566 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1569 struct lpfc_iocbq
*nextiocb
;
1573 * (a) there is anything on the txq to send
1575 * (c) link attention events can be processed (fcp ring only)
1576 * (d) IOCB processing is not blocked by the outstanding mbox command.
1578 if (pring
->txq_cnt
&&
1579 lpfc_is_link_up(phba
) &&
1580 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1581 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1583 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1584 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1585 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1588 lpfc_sli_update_ring(phba
, pring
);
1590 lpfc_sli_update_full_ring(phba
, pring
);
1597 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1598 * @phba: Pointer to HBA context object.
1599 * @hbqno: HBQ number.
1601 * This function is called with hbalock held to get the next
1602 * available slot for the given HBQ. If there is free slot
1603 * available for the HBQ it will return pointer to the next available
1604 * HBQ entry else it will return NULL.
1606 static struct lpfc_hbq_entry
*
1607 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1609 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1611 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1612 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1613 hbqp
->next_hbqPutIdx
= 0;
1615 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1616 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1617 uint32_t getidx
= le32_to_cpu(raw_index
);
1619 hbqp
->local_hbqGetIdx
= getidx
;
1621 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1622 lpfc_printf_log(phba
, KERN_ERR
,
1623 LOG_SLI
| LOG_VPORT
,
1624 "1802 HBQ %d: local_hbqGetIdx "
1625 "%u is > than hbqp->entry_count %u\n",
1626 hbqno
, hbqp
->local_hbqGetIdx
,
1629 phba
->link_state
= LPFC_HBA_ERROR
;
1633 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1637 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1642 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1643 * @phba: Pointer to HBA context object.
1645 * This function is called with no lock held to free all the
1646 * hbq buffers while uninitializing the SLI interface. It also
1647 * frees the HBQ buffers returned by the firmware but not yet
1648 * processed by the upper layers.
1651 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1653 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1654 struct hbq_dmabuf
*hbq_buf
;
1655 unsigned long flags
;
1659 hbq_count
= lpfc_sli_hbq_count();
1660 /* Return all memory used by all HBQs */
1661 spin_lock_irqsave(&phba
->hbalock
, flags
);
1662 for (i
= 0; i
< hbq_count
; ++i
) {
1663 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1664 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1665 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1666 list_del(&hbq_buf
->dbuf
.list
);
1667 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1669 phba
->hbqs
[i
].buffer_count
= 0;
1671 /* Return all HBQ buffer that are in-fly */
1672 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1674 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1675 list_del(&hbq_buf
->dbuf
.list
);
1676 if (hbq_buf
->tag
== -1) {
1677 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1680 hbqno
= hbq_buf
->tag
>> 16;
1681 if (hbqno
>= LPFC_MAX_HBQS
)
1682 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1685 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1690 /* Mark the HBQs not in use */
1691 phba
->hbq_in_use
= 0;
1692 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1696 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1697 * @phba: Pointer to HBA context object.
1698 * @hbqno: HBQ number.
1699 * @hbq_buf: Pointer to HBQ buffer.
1701 * This function is called with the hbalock held to post a
1702 * hbq buffer to the firmware. If the function finds an empty
1703 * slot in the HBQ, it will post the buffer. The function will return
1704 * pointer to the hbq entry if it successfully post the buffer
1705 * else it will return NULL.
1708 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1709 struct hbq_dmabuf
*hbq_buf
)
1711 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1715 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1716 * @phba: Pointer to HBA context object.
1717 * @hbqno: HBQ number.
1718 * @hbq_buf: Pointer to HBQ buffer.
1720 * This function is called with the hbalock held to post a hbq buffer to the
1721 * firmware. If the function finds an empty slot in the HBQ, it will post the
1722 * buffer and place it on the hbq_buffer_list. The function will return zero if
1723 * it successfully post the buffer else it will return an error.
1726 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1727 struct hbq_dmabuf
*hbq_buf
)
1729 struct lpfc_hbq_entry
*hbqe
;
1730 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1732 /* Get next HBQ entry slot to use */
1733 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1735 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1737 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1738 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1739 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1740 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1741 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1742 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1744 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1745 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1747 readl(phba
->hbq_put
+ hbqno
);
1748 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1755 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1756 * @phba: Pointer to HBA context object.
1757 * @hbqno: HBQ number.
1758 * @hbq_buf: Pointer to HBQ buffer.
1760 * This function is called with the hbalock held to post an RQE to the SLI4
1761 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1762 * the hbq_buffer_list and return zero, otherwise it will return an error.
1765 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1766 struct hbq_dmabuf
*hbq_buf
)
1769 struct lpfc_rqe hrqe
;
1770 struct lpfc_rqe drqe
;
1772 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1773 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1774 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1775 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1776 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1781 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1785 /* HBQ for ELS and CT traffic. */
1786 static struct lpfc_hbq_init lpfc_els_hbq
= {
1791 .ring_mask
= (1 << LPFC_ELS_RING
),
1797 /* HBQ for the extra ring if needed */
1798 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1803 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1810 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1816 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1817 * @phba: Pointer to HBA context object.
1818 * @hbqno: HBQ number.
1819 * @count: Number of HBQ buffers to be posted.
1821 * This function is called with no lock held to post more hbq buffers to the
1822 * given HBQ. The function returns the number of HBQ buffers successfully
1826 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1828 uint32_t i
, posted
= 0;
1829 unsigned long flags
;
1830 struct hbq_dmabuf
*hbq_buffer
;
1831 LIST_HEAD(hbq_buf_list
);
1832 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1835 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1836 lpfc_hbq_defs
[hbqno
]->entry_count
)
1837 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1838 phba
->hbqs
[hbqno
].buffer_count
;
1841 /* Allocate HBQ entries */
1842 for (i
= 0; i
< count
; i
++) {
1843 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1846 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1848 /* Check whether HBQ is still in use */
1849 spin_lock_irqsave(&phba
->hbalock
, flags
);
1850 if (!phba
->hbq_in_use
)
1852 while (!list_empty(&hbq_buf_list
)) {
1853 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1855 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1857 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1858 phba
->hbqs
[hbqno
].buffer_count
++;
1861 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1863 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1866 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1867 while (!list_empty(&hbq_buf_list
)) {
1868 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1870 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1876 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1877 * @phba: Pointer to HBA context object.
1880 * This function posts more buffers to the HBQ. This function
1881 * is called with no lock held. The function returns the number of HBQ entries
1882 * successfully allocated.
1885 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1887 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1890 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1891 lpfc_hbq_defs
[qno
]->add_count
);
1895 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1896 * @phba: Pointer to HBA context object.
1897 * @qno: HBQ queue number.
1899 * This function is called from SLI initialization code path with
1900 * no lock held to post initial HBQ buffers to firmware. The
1901 * function returns the number of HBQ entries successfully allocated.
1904 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1906 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1907 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1908 lpfc_hbq_defs
[qno
]->entry_count
);
1910 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1911 lpfc_hbq_defs
[qno
]->init_count
);
1915 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1916 * @phba: Pointer to HBA context object.
1917 * @hbqno: HBQ number.
1919 * This function removes the first hbq buffer on an hbq list and returns a
1920 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1922 static struct hbq_dmabuf
*
1923 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1925 struct lpfc_dmabuf
*d_buf
;
1927 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1930 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1934 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1935 * @phba: Pointer to HBA context object.
1936 * @tag: Tag of the hbq buffer.
1938 * This function is called with hbalock held. This function searches
1939 * for the hbq buffer associated with the given tag in the hbq buffer
1940 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1943 static struct hbq_dmabuf
*
1944 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1946 struct lpfc_dmabuf
*d_buf
;
1947 struct hbq_dmabuf
*hbq_buf
;
1951 if (hbqno
>= LPFC_MAX_HBQS
)
1954 spin_lock_irq(&phba
->hbalock
);
1955 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1956 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1957 if (hbq_buf
->tag
== tag
) {
1958 spin_unlock_irq(&phba
->hbalock
);
1962 spin_unlock_irq(&phba
->hbalock
);
1963 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1964 "1803 Bad hbq tag. Data: x%x x%x\n",
1965 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1970 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1971 * @phba: Pointer to HBA context object.
1972 * @hbq_buffer: Pointer to HBQ buffer.
1974 * This function is called with hbalock. This function gives back
1975 * the hbq buffer to firmware. If the HBQ does not have space to
1976 * post the buffer, it will free the buffer.
1979 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1984 hbqno
= hbq_buffer
->tag
>> 16;
1985 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1986 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1991 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1992 * @mbxCommand: mailbox command code.
1994 * This function is called by the mailbox event handler function to verify
1995 * that the completed mailbox command is a legitimate mailbox command. If the
1996 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1997 * and the mailbox event handler will take the HBA offline.
2000 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2004 switch (mbxCommand
) {
2008 case MBX_WRITE_VPARMS
:
2009 case MBX_RUN_BIU_DIAG
:
2012 case MBX_CONFIG_LINK
:
2013 case MBX_CONFIG_RING
:
2014 case MBX_RESET_RING
:
2015 case MBX_READ_CONFIG
:
2016 case MBX_READ_RCONFIG
:
2017 case MBX_READ_SPARM
:
2018 case MBX_READ_STATUS
:
2022 case MBX_READ_LNK_STAT
:
2024 case MBX_UNREG_LOGIN
:
2026 case MBX_DUMP_MEMORY
:
2027 case MBX_DUMP_CONTEXT
:
2030 case MBX_UPDATE_CFG
:
2032 case MBX_DEL_LD_ENTRY
:
2033 case MBX_RUN_PROGRAM
:
2035 case MBX_SET_VARIABLE
:
2036 case MBX_UNREG_D_ID
:
2037 case MBX_KILL_BOARD
:
2038 case MBX_CONFIG_FARP
:
2041 case MBX_RUN_BIU_DIAG64
:
2042 case MBX_CONFIG_PORT
:
2043 case MBX_READ_SPARM64
:
2044 case MBX_READ_RPI64
:
2045 case MBX_REG_LOGIN64
:
2046 case MBX_READ_TOPOLOGY
:
2049 case MBX_LOAD_EXP_ROM
:
2050 case MBX_ASYNCEVT_ENABLE
:
2054 case MBX_PORT_CAPABILITIES
:
2055 case MBX_PORT_IOV_CONTROL
:
2056 case MBX_SLI4_CONFIG
:
2057 case MBX_SLI4_REQ_FTRS
:
2059 case MBX_UNREG_FCFI
:
2064 case MBX_RESUME_RPI
:
2065 case MBX_READ_EVENT_LOG_STATUS
:
2066 case MBX_READ_EVENT_LOG
:
2067 case MBX_SECURITY_MGMT
:
2079 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2080 * @phba: Pointer to HBA context object.
2081 * @pmboxq: Pointer to mailbox command.
2083 * This is completion handler function for mailbox commands issued from
2084 * lpfc_sli_issue_mbox_wait function. This function is called by the
2085 * mailbox event handler function with no lock held. This function
2086 * will wake up thread waiting on the wait queue pointed by context1
2090 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2092 wait_queue_head_t
*pdone_q
;
2093 unsigned long drvr_flag
;
2096 * If pdone_q is empty, the driver thread gave up waiting and
2097 * continued running.
2099 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2100 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2101 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2103 wake_up_interruptible(pdone_q
);
2104 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2110 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2111 * @phba: Pointer to HBA context object.
2112 * @pmb: Pointer to mailbox object.
2114 * This function is the default mailbox completion handler. It
2115 * frees the memory resources associated with the completed mailbox
2116 * command. If the completed command is a REG_LOGIN mailbox command,
2117 * this function will issue a UREG_LOGIN to re-claim the RPI.
2120 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2122 struct lpfc_vport
*vport
= pmb
->vport
;
2123 struct lpfc_dmabuf
*mp
;
2124 struct lpfc_nodelist
*ndlp
;
2125 struct Scsi_Host
*shost
;
2129 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2132 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2137 * If a REG_LOGIN succeeded after node is destroyed or node
2138 * is in re-discovery driver need to cleanup the RPI.
2140 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2141 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2142 !pmb
->u
.mb
.mbxStatus
) {
2143 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2144 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2145 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2146 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2147 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2148 if (rc
!= MBX_NOT_FINISHED
)
2152 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2153 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2154 !pmb
->u
.mb
.mbxStatus
) {
2155 shost
= lpfc_shost_from_vport(vport
);
2156 spin_lock_irq(shost
->host_lock
);
2157 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2158 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2159 spin_unlock_irq(shost
->host_lock
);
2162 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2163 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2165 pmb
->context2
= NULL
;
2168 /* Check security permission status on INIT_LINK mailbox command */
2169 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2170 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2171 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2172 "2860 SLI authentication is required "
2173 "for INIT_LINK but has not done yet\n");
2175 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2176 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2178 mempool_free(pmb
, phba
->mbox_mem_pool
);
2182 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2183 * @phba: Pointer to HBA context object.
2185 * This function is called with no lock held. This function processes all
2186 * the completed mailbox commands and gives it to upper layers. The interrupt
2187 * service routine processes mailbox completion interrupt and adds completed
2188 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2189 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2190 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2191 * function returns the mailbox commands to the upper layer by calling the
2192 * completion handler function of each mailbox.
2195 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2202 phba
->sli
.slistat
.mbox_event
++;
2204 /* Get all completed mailboxe buffers into the cmplq */
2205 spin_lock_irq(&phba
->hbalock
);
2206 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2207 spin_unlock_irq(&phba
->hbalock
);
2209 /* Get a Mailbox buffer to setup mailbox commands for callback */
2211 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2217 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2219 lpfc_debugfs_disc_trc(pmb
->vport
,
2220 LPFC_DISC_TRC_MBOX_VPORT
,
2221 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2222 (uint32_t)pmbox
->mbxCommand
,
2223 pmbox
->un
.varWords
[0],
2224 pmbox
->un
.varWords
[1]);
2227 lpfc_debugfs_disc_trc(phba
->pport
,
2229 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2230 (uint32_t)pmbox
->mbxCommand
,
2231 pmbox
->un
.varWords
[0],
2232 pmbox
->un
.varWords
[1]);
2237 * It is a fatal error if unknown mbox command completion.
2239 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2241 /* Unknown mailbox command compl */
2242 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2243 "(%d):0323 Unknown Mailbox command "
2244 "x%x (x%x/x%x) Cmpl\n",
2245 pmb
->vport
? pmb
->vport
->vpi
: 0,
2247 lpfc_sli_config_mbox_subsys_get(phba
,
2249 lpfc_sli_config_mbox_opcode_get(phba
,
2251 phba
->link_state
= LPFC_HBA_ERROR
;
2252 phba
->work_hs
= HS_FFER3
;
2253 lpfc_handle_eratt(phba
);
2257 if (pmbox
->mbxStatus
) {
2258 phba
->sli
.slistat
.mbox_stat_err
++;
2259 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2260 /* Mbox cmd cmpl error - RETRYing */
2261 lpfc_printf_log(phba
, KERN_INFO
,
2263 "(%d):0305 Mbox cmd cmpl "
2264 "error - RETRYing Data: x%x "
2265 "(x%x/x%x) x%x x%x x%x\n",
2266 pmb
->vport
? pmb
->vport
->vpi
: 0,
2268 lpfc_sli_config_mbox_subsys_get(phba
,
2270 lpfc_sli_config_mbox_opcode_get(phba
,
2273 pmbox
->un
.varWords
[0],
2274 pmb
->vport
->port_state
);
2275 pmbox
->mbxStatus
= 0;
2276 pmbox
->mbxOwner
= OWN_HOST
;
2277 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2278 if (rc
!= MBX_NOT_FINISHED
)
2283 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2284 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2285 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2286 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2287 pmb
->vport
? pmb
->vport
->vpi
: 0,
2289 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2290 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2292 *((uint32_t *) pmbox
),
2293 pmbox
->un
.varWords
[0],
2294 pmbox
->un
.varWords
[1],
2295 pmbox
->un
.varWords
[2],
2296 pmbox
->un
.varWords
[3],
2297 pmbox
->un
.varWords
[4],
2298 pmbox
->un
.varWords
[5],
2299 pmbox
->un
.varWords
[6],
2300 pmbox
->un
.varWords
[7]);
2303 pmb
->mbox_cmpl(phba
,pmb
);
2309 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2310 * @phba: Pointer to HBA context object.
2311 * @pring: Pointer to driver SLI ring object.
2314 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2315 * is set in the tag the buffer is posted for a particular exchange,
2316 * the function will return the buffer without replacing the buffer.
2317 * If the buffer is for unsolicited ELS or CT traffic, this function
2318 * returns the buffer and also posts another buffer to the firmware.
2320 static struct lpfc_dmabuf
*
2321 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2322 struct lpfc_sli_ring
*pring
,
2325 struct hbq_dmabuf
*hbq_entry
;
2327 if (tag
& QUE_BUFTAG_BIT
)
2328 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2329 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2332 return &hbq_entry
->dbuf
;
2336 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2337 * @phba: Pointer to HBA context object.
2338 * @pring: Pointer to driver SLI ring object.
2339 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2340 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2341 * @fch_type: the type for the first frame of the sequence.
2343 * This function is called with no lock held. This function uses the r_ctl and
2344 * type of the received sequence to find the correct callback function to call
2345 * to process the sequence.
2348 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2349 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2354 /* unSolicited Responses */
2355 if (pring
->prt
[0].profile
) {
2356 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2357 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2361 /* We must search, based on rctl / type
2362 for the right routine */
2363 for (i
= 0; i
< pring
->num_mask
; i
++) {
2364 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2365 (pring
->prt
[i
].type
== fch_type
)) {
2366 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2367 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2368 (phba
, pring
, saveq
);
2376 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2377 * @phba: Pointer to HBA context object.
2378 * @pring: Pointer to driver SLI ring object.
2379 * @saveq: Pointer to the unsolicited iocb.
2381 * This function is called with no lock held by the ring event handler
2382 * when there is an unsolicited iocb posted to the response ring by the
2383 * firmware. This function gets the buffer associated with the iocbs
2384 * and calls the event handler for the ring. This function handles both
2385 * qring buffers and hbq buffers.
2386 * When the function returns 1 the caller can free the iocb object otherwise
2387 * upper layer functions will free the iocb objects.
2390 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2391 struct lpfc_iocbq
*saveq
)
2395 uint32_t Rctl
, Type
;
2397 struct lpfc_iocbq
*iocbq
;
2398 struct lpfc_dmabuf
*dmzbuf
;
2401 irsp
= &(saveq
->iocb
);
2403 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2404 if (pring
->lpfc_sli_rcv_async_status
)
2405 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2407 lpfc_printf_log(phba
,
2410 "0316 Ring %d handler: unexpected "
2411 "ASYNC_STATUS iocb received evt_code "
2414 irsp
->un
.asyncstat
.evt_code
);
2418 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2419 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2420 if (irsp
->ulpBdeCount
> 0) {
2421 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2422 irsp
->un
.ulpWord
[3]);
2423 lpfc_in_buf_free(phba
, dmzbuf
);
2426 if (irsp
->ulpBdeCount
> 1) {
2427 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2428 irsp
->unsli3
.sli3Words
[3]);
2429 lpfc_in_buf_free(phba
, dmzbuf
);
2432 if (irsp
->ulpBdeCount
> 2) {
2433 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2434 irsp
->unsli3
.sli3Words
[7]);
2435 lpfc_in_buf_free(phba
, dmzbuf
);
2441 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2442 if (irsp
->ulpBdeCount
!= 0) {
2443 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2444 irsp
->un
.ulpWord
[3]);
2445 if (!saveq
->context2
)
2446 lpfc_printf_log(phba
,
2449 "0341 Ring %d Cannot find buffer for "
2450 "an unsolicited iocb. tag 0x%x\n",
2452 irsp
->un
.ulpWord
[3]);
2454 if (irsp
->ulpBdeCount
== 2) {
2455 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2456 irsp
->unsli3
.sli3Words
[7]);
2457 if (!saveq
->context3
)
2458 lpfc_printf_log(phba
,
2461 "0342 Ring %d Cannot find buffer for an"
2462 " unsolicited iocb. tag 0x%x\n",
2464 irsp
->unsli3
.sli3Words
[7]);
2466 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2467 irsp
= &(iocbq
->iocb
);
2468 if (irsp
->ulpBdeCount
!= 0) {
2469 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2470 irsp
->un
.ulpWord
[3]);
2471 if (!iocbq
->context2
)
2472 lpfc_printf_log(phba
,
2475 "0343 Ring %d Cannot find "
2476 "buffer for an unsolicited iocb"
2477 ". tag 0x%x\n", pring
->ringno
,
2478 irsp
->un
.ulpWord
[3]);
2480 if (irsp
->ulpBdeCount
== 2) {
2481 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2482 irsp
->unsli3
.sli3Words
[7]);
2483 if (!iocbq
->context3
)
2484 lpfc_printf_log(phba
,
2487 "0344 Ring %d Cannot find "
2488 "buffer for an unsolicited "
2491 irsp
->unsli3
.sli3Words
[7]);
2495 if (irsp
->ulpBdeCount
!= 0 &&
2496 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2497 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2500 /* search continue save q for same XRI */
2501 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2502 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2503 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2504 list_add_tail(&saveq
->list
, &iocbq
->list
);
2510 list_add_tail(&saveq
->clist
,
2511 &pring
->iocb_continue_saveq
);
2512 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2513 list_del_init(&iocbq
->clist
);
2515 irsp
= &(saveq
->iocb
);
2519 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2520 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2521 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2522 Rctl
= FC_RCTL_ELS_REQ
;
2525 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2526 Rctl
= w5p
->hcsw
.Rctl
;
2527 Type
= w5p
->hcsw
.Type
;
2529 /* Firmware Workaround */
2530 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2531 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2532 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2533 Rctl
= FC_RCTL_ELS_REQ
;
2535 w5p
->hcsw
.Rctl
= Rctl
;
2536 w5p
->hcsw
.Type
= Type
;
2540 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2541 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2542 "0313 Ring %d handler: unexpected Rctl x%x "
2543 "Type x%x received\n",
2544 pring
->ringno
, Rctl
, Type
);
2550 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2551 * @phba: Pointer to HBA context object.
2552 * @pring: Pointer to driver SLI ring object.
2553 * @prspiocb: Pointer to response iocb object.
2555 * This function looks up the iocb_lookup table to get the command iocb
2556 * corresponding to the given response iocb using the iotag of the
2557 * response iocb. This function is called with the hbalock held.
2558 * This function returns the command iocb object if it finds the command
2559 * iocb else returns NULL.
2561 static struct lpfc_iocbq
*
2562 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2563 struct lpfc_sli_ring
*pring
,
2564 struct lpfc_iocbq
*prspiocb
)
2566 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2569 iotag
= prspiocb
->iocb
.ulpIoTag
;
2571 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2572 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2573 list_del_init(&cmd_iocb
->list
);
2574 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2575 pring
->txcmplq_cnt
--;
2576 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2581 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2582 "0317 iotag x%x is out off "
2583 "range: max iotag x%x wd0 x%x\n",
2584 iotag
, phba
->sli
.last_iotag
,
2585 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2590 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2591 * @phba: Pointer to HBA context object.
2592 * @pring: Pointer to driver SLI ring object.
2595 * This function looks up the iocb_lookup table to get the command iocb
2596 * corresponding to the given iotag. This function is called with the
2598 * This function returns the command iocb object if it finds the command
2599 * iocb else returns NULL.
2601 static struct lpfc_iocbq
*
2602 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2603 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2605 struct lpfc_iocbq
*cmd_iocb
;
2607 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2608 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2609 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2610 /* remove from txcmpl queue list */
2611 list_del_init(&cmd_iocb
->list
);
2612 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2613 pring
->txcmplq_cnt
--;
2617 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2618 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2619 iotag
, phba
->sli
.last_iotag
);
2624 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2625 * @phba: Pointer to HBA context object.
2626 * @pring: Pointer to driver SLI ring object.
2627 * @saveq: Pointer to the response iocb to be processed.
2629 * This function is called by the ring event handler for non-fcp
2630 * rings when there is a new response iocb in the response ring.
2631 * The caller is not required to hold any locks. This function
2632 * gets the command iocb associated with the response iocb and
2633 * calls the completion handler for the command iocb. If there
2634 * is no completion handler, the function will free the resources
2635 * associated with command iocb. If the response iocb is for
2636 * an already aborted command iocb, the status of the completion
2637 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2638 * This function always returns 1.
2641 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2642 struct lpfc_iocbq
*saveq
)
2644 struct lpfc_iocbq
*cmdiocbp
;
2646 unsigned long iflag
;
2648 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2649 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2650 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2651 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2654 if (cmdiocbp
->iocb_cmpl
) {
2656 * If an ELS command failed send an event to mgmt
2659 if (saveq
->iocb
.ulpStatus
&&
2660 (pring
->ringno
== LPFC_ELS_RING
) &&
2661 (cmdiocbp
->iocb
.ulpCommand
==
2662 CMD_ELS_REQUEST64_CR
))
2663 lpfc_send_els_failure_event(phba
,
2667 * Post all ELS completions to the worker thread.
2668 * All other are passed to the completion callback.
2670 if (pring
->ringno
== LPFC_ELS_RING
) {
2671 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2672 (cmdiocbp
->iocb_flag
&
2673 LPFC_DRIVER_ABORTED
)) {
2674 spin_lock_irqsave(&phba
->hbalock
,
2676 cmdiocbp
->iocb_flag
&=
2677 ~LPFC_DRIVER_ABORTED
;
2678 spin_unlock_irqrestore(&phba
->hbalock
,
2680 saveq
->iocb
.ulpStatus
=
2681 IOSTAT_LOCAL_REJECT
;
2682 saveq
->iocb
.un
.ulpWord
[4] =
2685 /* Firmware could still be in progress
2686 * of DMAing payload, so don't free data
2687 * buffer till after a hbeat.
2689 spin_lock_irqsave(&phba
->hbalock
,
2691 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2692 spin_unlock_irqrestore(&phba
->hbalock
,
2695 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2696 if (saveq
->iocb_flag
&
2697 LPFC_EXCHANGE_BUSY
) {
2698 /* Set cmdiocb flag for the
2699 * exchange busy so sgl (xri)
2700 * will not be released until
2701 * the abort xri is received
2705 &phba
->hbalock
, iflag
);
2706 cmdiocbp
->iocb_flag
|=
2708 spin_unlock_irqrestore(
2709 &phba
->hbalock
, iflag
);
2711 if (cmdiocbp
->iocb_flag
&
2712 LPFC_DRIVER_ABORTED
) {
2714 * Clear LPFC_DRIVER_ABORTED
2715 * bit in case it was driver
2719 &phba
->hbalock
, iflag
);
2720 cmdiocbp
->iocb_flag
&=
2721 ~LPFC_DRIVER_ABORTED
;
2722 spin_unlock_irqrestore(
2723 &phba
->hbalock
, iflag
);
2724 cmdiocbp
->iocb
.ulpStatus
=
2725 IOSTAT_LOCAL_REJECT
;
2726 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2727 IOERR_ABORT_REQUESTED
;
2729 * For SLI4, irsiocb contains
2730 * NO_XRI in sli_xritag, it
2731 * shall not affect releasing
2732 * sgl (xri) process.
2734 saveq
->iocb
.ulpStatus
=
2735 IOSTAT_LOCAL_REJECT
;
2736 saveq
->iocb
.un
.ulpWord
[4] =
2739 &phba
->hbalock
, iflag
);
2741 LPFC_DELAY_MEM_FREE
;
2742 spin_unlock_irqrestore(
2743 &phba
->hbalock
, iflag
);
2747 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2749 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2752 * Unknown initiating command based on the response iotag.
2753 * This could be the case on the ELS ring because of
2756 if (pring
->ringno
!= LPFC_ELS_RING
) {
2758 * Ring <ringno> handler: unexpected completion IoTag
2761 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2762 "0322 Ring %d handler: "
2763 "unexpected completion IoTag x%x "
2764 "Data: x%x x%x x%x x%x\n",
2766 saveq
->iocb
.ulpIoTag
,
2767 saveq
->iocb
.ulpStatus
,
2768 saveq
->iocb
.un
.ulpWord
[4],
2769 saveq
->iocb
.ulpCommand
,
2770 saveq
->iocb
.ulpContext
);
2778 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2779 * @phba: Pointer to HBA context object.
2780 * @pring: Pointer to driver SLI ring object.
2782 * This function is called from the iocb ring event handlers when
2783 * put pointer is ahead of the get pointer for a ring. This function signal
2784 * an error attention condition to the worker thread and the worker
2785 * thread will transition the HBA to offline state.
2788 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2790 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2792 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2793 * rsp ring <portRspMax>
2795 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2796 "0312 Ring %d handler: portRspPut %d "
2797 "is bigger than rsp ring %d\n",
2798 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2799 pring
->sli
.sli3
.numRiocb
);
2801 phba
->link_state
= LPFC_HBA_ERROR
;
2804 * All error attention handlers are posted to
2807 phba
->work_ha
|= HA_ERATT
;
2808 phba
->work_hs
= HS_FFER3
;
2810 lpfc_worker_wake_up(phba
);
2816 * lpfc_poll_eratt - Error attention polling timer timeout handler
2817 * @ptr: Pointer to address of HBA context object.
2819 * This function is invoked by the Error Attention polling timer when the
2820 * timer times out. It will check the SLI Error Attention register for
2821 * possible attention events. If so, it will post an Error Attention event
2822 * and wake up worker thread to process it. Otherwise, it will set up the
2823 * Error Attention polling timer for the next poll.
2825 void lpfc_poll_eratt(unsigned long ptr
)
2827 struct lpfc_hba
*phba
;
2828 uint32_t eratt
= 0, rem
;
2829 uint64_t sli_intr
, cnt
;
2831 phba
= (struct lpfc_hba
*)ptr
;
2833 /* Here we will also keep track of interrupts per sec of the hba */
2834 sli_intr
= phba
->sli
.slistat
.sli_intr
;
2836 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
2837 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
2840 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
2842 /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
2843 rem
= do_div(cnt
, LPFC_ERATT_POLL_INTERVAL
);
2844 phba
->sli
.slistat
.sli_ips
= cnt
;
2846 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
2848 /* Check chip HA register for error event */
2849 eratt
= lpfc_sli_check_eratt(phba
);
2852 /* Tell the worker thread there is work to do */
2853 lpfc_worker_wake_up(phba
);
2855 /* Restart the timer for next eratt poll */
2856 mod_timer(&phba
->eratt_poll
, jiffies
+
2857 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2863 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2864 * @phba: Pointer to HBA context object.
2865 * @pring: Pointer to driver SLI ring object.
2866 * @mask: Host attention register mask for this ring.
2868 * This function is called from the interrupt context when there is a ring
2869 * event for the fcp ring. The caller does not hold any lock.
2870 * The function processes each response iocb in the response ring until it
2871 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2872 * LE bit set. The function will call the completion handler of the command iocb
2873 * if the response iocb indicates a completion for a command iocb or it is
2874 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2875 * function if this is an unsolicited iocb.
2876 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2877 * to check it explicitly.
2880 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2881 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2883 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2884 IOCB_t
*irsp
= NULL
;
2885 IOCB_t
*entry
= NULL
;
2886 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2887 struct lpfc_iocbq rspiocbq
;
2889 uint32_t portRspPut
, portRspMax
;
2891 lpfc_iocb_type type
;
2892 unsigned long iflag
;
2893 uint32_t rsp_cmpl
= 0;
2895 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2896 pring
->stats
.iocb_event
++;
2899 * The next available response entry should never exceed the maximum
2900 * entries. If it does, treat it as an adapter hardware error.
2902 portRspMax
= pring
->sli
.sli3
.numRiocb
;
2903 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2904 if (unlikely(portRspPut
>= portRspMax
)) {
2905 lpfc_sli_rsp_pointers_error(phba
, pring
);
2906 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2909 if (phba
->fcp_ring_in_use
) {
2910 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2913 phba
->fcp_ring_in_use
= 1;
2916 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
2918 * Fetch an entry off the ring and copy it into a local data
2919 * structure. The copy involves a byte-swap since the
2920 * network byte order and pci byte orders are different.
2922 entry
= lpfc_resp_iocb(phba
, pring
);
2923 phba
->last_completion_time
= jiffies
;
2925 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
2926 pring
->sli
.sli3
.rspidx
= 0;
2928 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2929 (uint32_t *) &rspiocbq
.iocb
,
2930 phba
->iocb_rsp_size
);
2931 INIT_LIST_HEAD(&(rspiocbq
.list
));
2932 irsp
= &rspiocbq
.iocb
;
2934 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2935 pring
->stats
.iocb_rsp
++;
2938 if (unlikely(irsp
->ulpStatus
)) {
2940 * If resource errors reported from HBA, reduce
2941 * queuedepths of the SCSI device.
2943 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2944 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2945 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2946 phba
->lpfc_rampdown_queue_depth(phba
);
2947 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2950 /* Rsp ring <ringno> error: IOCB */
2951 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2952 "0336 Rsp Ring %d error: IOCB Data: "
2953 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2955 irsp
->un
.ulpWord
[0],
2956 irsp
->un
.ulpWord
[1],
2957 irsp
->un
.ulpWord
[2],
2958 irsp
->un
.ulpWord
[3],
2959 irsp
->un
.ulpWord
[4],
2960 irsp
->un
.ulpWord
[5],
2961 *(uint32_t *)&irsp
->un1
,
2962 *((uint32_t *)&irsp
->un1
+ 1));
2966 case LPFC_ABORT_IOCB
:
2969 * Idle exchange closed via ABTS from port. No iocb
2970 * resources need to be recovered.
2972 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2973 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2974 "0333 IOCB cmd 0x%x"
2975 " processed. Skipping"
2981 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2983 if (unlikely(!cmdiocbq
))
2985 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
2986 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
2987 if (cmdiocbq
->iocb_cmpl
) {
2988 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2989 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2991 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2994 case LPFC_UNSOL_IOCB
:
2995 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2996 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2997 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3000 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3001 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3002 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3003 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3005 dev_warn(&((phba
->pcidev
)->dev
),
3007 phba
->brd_no
, adaptermsg
);
3009 /* Unknown IOCB command */
3010 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3011 "0334 Unknown IOCB command "
3012 "Data: x%x, x%x x%x x%x x%x\n",
3013 type
, irsp
->ulpCommand
,
3022 * The response IOCB has been processed. Update the ring
3023 * pointer in SLIM. If the port response put pointer has not
3024 * been updated, sync the pgp->rspPutInx and fetch the new port
3025 * response put pointer.
3027 writel(pring
->sli
.sli3
.rspidx
,
3028 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3030 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3031 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3034 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3035 pring
->stats
.iocb_rsp_full
++;
3036 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3037 writel(status
, phba
->CAregaddr
);
3038 readl(phba
->CAregaddr
);
3040 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3041 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3042 pring
->stats
.iocb_cmd_empty
++;
3044 /* Force update of the local copy of cmdGetInx */
3045 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3046 lpfc_sli_resume_iocb(phba
, pring
);
3048 if ((pring
->lpfc_sli_cmd_available
))
3049 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3053 phba
->fcp_ring_in_use
= 0;
3054 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3059 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3060 * @phba: Pointer to HBA context object.
3061 * @pring: Pointer to driver SLI ring object.
3062 * @rspiocbp: Pointer to driver response IOCB object.
3064 * This function is called from the worker thread when there is a slow-path
3065 * response IOCB to process. This function chains all the response iocbs until
3066 * seeing the iocb with the LE bit set. The function will call
3067 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3068 * completion of a command iocb. The function will call the
3069 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3070 * The function frees the resources or calls the completion handler if this
3071 * iocb is an abort completion. The function returns NULL when the response
3072 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3073 * this function shall chain the iocb on to the iocb_continueq and return the
3074 * response iocb passed in.
3076 static struct lpfc_iocbq
*
3077 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3078 struct lpfc_iocbq
*rspiocbp
)
3080 struct lpfc_iocbq
*saveq
;
3081 struct lpfc_iocbq
*cmdiocbp
;
3082 struct lpfc_iocbq
*next_iocb
;
3083 IOCB_t
*irsp
= NULL
;
3084 uint32_t free_saveq
;
3085 uint8_t iocb_cmd_type
;
3086 lpfc_iocb_type type
;
3087 unsigned long iflag
;
3090 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3091 /* First add the response iocb to the countinueq list */
3092 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3093 pring
->iocb_continueq_cnt
++;
3095 /* Now, determine whether the list is completed for processing */
3096 irsp
= &rspiocbp
->iocb
;
3099 * By default, the driver expects to free all resources
3100 * associated with this iocb completion.
3103 saveq
= list_get_first(&pring
->iocb_continueq
,
3104 struct lpfc_iocbq
, list
);
3105 irsp
= &(saveq
->iocb
);
3106 list_del_init(&pring
->iocb_continueq
);
3107 pring
->iocb_continueq_cnt
= 0;
3109 pring
->stats
.iocb_rsp
++;
3112 * If resource errors reported from HBA, reduce
3113 * queuedepths of the SCSI device.
3115 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3116 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
3117 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3118 phba
->lpfc_rampdown_queue_depth(phba
);
3119 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3122 if (irsp
->ulpStatus
) {
3123 /* Rsp ring <ringno> error: IOCB */
3124 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3125 "0328 Rsp Ring %d error: "
3130 "x%x x%x x%x x%x\n",
3132 irsp
->un
.ulpWord
[0],
3133 irsp
->un
.ulpWord
[1],
3134 irsp
->un
.ulpWord
[2],
3135 irsp
->un
.ulpWord
[3],
3136 irsp
->un
.ulpWord
[4],
3137 irsp
->un
.ulpWord
[5],
3138 *(((uint32_t *) irsp
) + 6),
3139 *(((uint32_t *) irsp
) + 7),
3140 *(((uint32_t *) irsp
) + 8),
3141 *(((uint32_t *) irsp
) + 9),
3142 *(((uint32_t *) irsp
) + 10),
3143 *(((uint32_t *) irsp
) + 11),
3144 *(((uint32_t *) irsp
) + 12),
3145 *(((uint32_t *) irsp
) + 13),
3146 *(((uint32_t *) irsp
) + 14),
3147 *(((uint32_t *) irsp
) + 15));
3151 * Fetch the IOCB command type and call the correct completion
3152 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3153 * get freed back to the lpfc_iocb_list by the discovery
3156 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3157 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3160 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3161 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3162 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3165 case LPFC_UNSOL_IOCB
:
3166 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3167 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3168 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3173 case LPFC_ABORT_IOCB
:
3175 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3176 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3179 /* Call the specified completion routine */
3180 if (cmdiocbp
->iocb_cmpl
) {
3181 spin_unlock_irqrestore(&phba
->hbalock
,
3183 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3185 spin_lock_irqsave(&phba
->hbalock
,
3188 __lpfc_sli_release_iocbq(phba
,
3193 case LPFC_UNKNOWN_IOCB
:
3194 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3195 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3196 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3197 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3199 dev_warn(&((phba
->pcidev
)->dev
),
3201 phba
->brd_no
, adaptermsg
);
3203 /* Unknown IOCB command */
3204 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3205 "0335 Unknown IOCB "
3206 "command Data: x%x "
3217 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3218 &saveq
->list
, list
) {
3219 list_del(&rspiocbp
->list
);
3220 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3222 __lpfc_sli_release_iocbq(phba
, saveq
);
3226 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3231 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3232 * @phba: Pointer to HBA context object.
3233 * @pring: Pointer to driver SLI ring object.
3234 * @mask: Host attention register mask for this ring.
3236 * This routine wraps the actual slow_ring event process routine from the
3237 * API jump table function pointer from the lpfc_hba struct.
3240 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3241 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3243 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3247 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3248 * @phba: Pointer to HBA context object.
3249 * @pring: Pointer to driver SLI ring object.
3250 * @mask: Host attention register mask for this ring.
3252 * This function is called from the worker thread when there is a ring event
3253 * for non-fcp rings. The caller does not hold any lock. The function will
3254 * remove each response iocb in the response ring and calls the handle
3255 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3258 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3259 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3261 struct lpfc_pgp
*pgp
;
3263 IOCB_t
*irsp
= NULL
;
3264 struct lpfc_iocbq
*rspiocbp
= NULL
;
3265 uint32_t portRspPut
, portRspMax
;
3266 unsigned long iflag
;
3269 pgp
= &phba
->port_gp
[pring
->ringno
];
3270 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3271 pring
->stats
.iocb_event
++;
3274 * The next available response entry should never exceed the maximum
3275 * entries. If it does, treat it as an adapter hardware error.
3277 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3278 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3279 if (portRspPut
>= portRspMax
) {
3281 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3282 * rsp ring <portRspMax>
3284 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3285 "0303 Ring %d handler: portRspPut %d "
3286 "is bigger than rsp ring %d\n",
3287 pring
->ringno
, portRspPut
, portRspMax
);
3289 phba
->link_state
= LPFC_HBA_ERROR
;
3290 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3292 phba
->work_hs
= HS_FFER3
;
3293 lpfc_handle_eratt(phba
);
3299 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3301 * Build a completion list and call the appropriate handler.
3302 * The process is to get the next available response iocb, get
3303 * a free iocb from the list, copy the response data into the
3304 * free iocb, insert to the continuation list, and update the
3305 * next response index to slim. This process makes response
3306 * iocb's in the ring available to DMA as fast as possible but
3307 * pays a penalty for a copy operation. Since the iocb is
3308 * only 32 bytes, this penalty is considered small relative to
3309 * the PCI reads for register values and a slim write. When
3310 * the ulpLe field is set, the entire Command has been
3313 entry
= lpfc_resp_iocb(phba
, pring
);
3315 phba
->last_completion_time
= jiffies
;
3316 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3317 if (rspiocbp
== NULL
) {
3318 printk(KERN_ERR
"%s: out of buffers! Failing "
3319 "completion.\n", __func__
);
3323 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3324 phba
->iocb_rsp_size
);
3325 irsp
= &rspiocbp
->iocb
;
3327 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3328 pring
->sli
.sli3
.rspidx
= 0;
3330 if (pring
->ringno
== LPFC_ELS_RING
) {
3331 lpfc_debugfs_slow_ring_trc(phba
,
3332 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3333 *(((uint32_t *) irsp
) + 4),
3334 *(((uint32_t *) irsp
) + 6),
3335 *(((uint32_t *) irsp
) + 7));
3338 writel(pring
->sli
.sli3
.rspidx
,
3339 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3341 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3342 /* Handle the response IOCB */
3343 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3344 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3347 * If the port response put pointer has not been updated, sync
3348 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3349 * response put pointer.
3351 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3352 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3354 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3356 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3357 /* At least one response entry has been freed */
3358 pring
->stats
.iocb_rsp_full
++;
3359 /* SET RxRE_RSP in Chip Att register */
3360 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3361 writel(status
, phba
->CAregaddr
);
3362 readl(phba
->CAregaddr
); /* flush */
3364 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3365 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3366 pring
->stats
.iocb_cmd_empty
++;
3368 /* Force update of the local copy of cmdGetInx */
3369 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3370 lpfc_sli_resume_iocb(phba
, pring
);
3372 if ((pring
->lpfc_sli_cmd_available
))
3373 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3377 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3382 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3383 * @phba: Pointer to HBA context object.
3384 * @pring: Pointer to driver SLI ring object.
3385 * @mask: Host attention register mask for this ring.
3387 * This function is called from the worker thread when there is a pending
3388 * ELS response iocb on the driver internal slow-path response iocb worker
3389 * queue. The caller does not hold any lock. The function will remove each
3390 * response iocb from the response worker queue and calls the handle
3391 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3394 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3395 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3397 struct lpfc_iocbq
*irspiocbq
;
3398 struct hbq_dmabuf
*dmabuf
;
3399 struct lpfc_cq_event
*cq_event
;
3400 unsigned long iflag
;
3402 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3403 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3404 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3405 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3406 /* Get the response iocb from the head of work queue */
3407 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3408 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3409 cq_event
, struct lpfc_cq_event
, list
);
3410 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3412 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3413 case CQE_CODE_COMPL_WQE
:
3414 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3416 /* Translate ELS WCQE to response IOCBQ */
3417 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3420 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3423 case CQE_CODE_RECEIVE
:
3424 case CQE_CODE_RECEIVE_V1
:
3425 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3427 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3436 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3437 * @phba: Pointer to HBA context object.
3438 * @pring: Pointer to driver SLI ring object.
3440 * This function aborts all iocbs in the given ring and frees all the iocb
3441 * objects in txq. This function issues an abort iocb for all the iocb commands
3442 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3443 * the return of this function. The caller is not required to hold any locks.
3446 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3448 LIST_HEAD(completions
);
3449 struct lpfc_iocbq
*iocb
, *next_iocb
;
3451 if (pring
->ringno
== LPFC_ELS_RING
) {
3452 lpfc_fabric_abort_hba(phba
);
3455 /* Error everything on txq and txcmplq
3458 spin_lock_irq(&phba
->hbalock
);
3459 list_splice_init(&pring
->txq
, &completions
);
3462 /* Next issue ABTS for everything on the txcmplq */
3463 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3464 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3466 spin_unlock_irq(&phba
->hbalock
);
3468 /* Cancel all the IOCBs from the completions list */
3469 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3474 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3475 * @phba: Pointer to HBA context object.
3477 * This function flushes all iocbs in the fcp ring and frees all the iocb
3478 * objects in txq and txcmplq. This function will not issue abort iocbs
3479 * for all the iocb commands in txcmplq, they will just be returned with
3480 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3481 * slot has been permanently disabled.
3484 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3488 struct lpfc_sli
*psli
= &phba
->sli
;
3489 struct lpfc_sli_ring
*pring
;
3491 /* Currently, only one fcp ring */
3492 pring
= &psli
->ring
[psli
->fcp_ring
];
3494 spin_lock_irq(&phba
->hbalock
);
3495 /* Retrieve everything on txq */
3496 list_splice_init(&pring
->txq
, &txq
);
3499 /* Retrieve everything on the txcmplq */
3500 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3501 pring
->txcmplq_cnt
= 0;
3503 /* Indicate the I/O queues are flushed */
3504 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3505 spin_unlock_irq(&phba
->hbalock
);
3508 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3511 /* Flush the txcmpq */
3512 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3517 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3518 * @phba: Pointer to HBA context object.
3519 * @mask: Bit mask to be checked.
3521 * This function reads the host status register and compares
3522 * with the provided bit mask to check if HBA completed
3523 * the restart. This function will wait in a loop for the
3524 * HBA to complete restart. If the HBA does not restart within
3525 * 15 iterations, the function will reset the HBA again. The
3526 * function returns 1 when HBA fail to restart otherwise returns
3530 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3536 /* Read the HBA Host Status Register */
3537 if (lpfc_readl(phba
->HSregaddr
, &status
))
3541 * Check status register every 100ms for 5 retries, then every
3542 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3543 * every 2.5 sec for 4.
3544 * Break our of the loop if errors occurred during init.
3546 while (((status
& mask
) != mask
) &&
3547 !(status
& HS_FFERM
) &&
3559 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3560 lpfc_sli_brdrestart(phba
);
3562 /* Read the HBA Host Status Register */
3563 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3569 /* Check to see if any errors occurred during init */
3570 if ((status
& HS_FFERM
) || (i
>= 20)) {
3571 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3572 "2751 Adapter failed to restart, "
3573 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3575 readl(phba
->MBslimaddr
+ 0xa8),
3576 readl(phba
->MBslimaddr
+ 0xac));
3577 phba
->link_state
= LPFC_HBA_ERROR
;
3585 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3586 * @phba: Pointer to HBA context object.
3587 * @mask: Bit mask to be checked.
3589 * This function checks the host status register to check if HBA is
3590 * ready. This function will wait in a loop for the HBA to be ready
3591 * If the HBA is not ready , the function will will reset the HBA PCI
3592 * function again. The function returns 1 when HBA fail to be ready
3593 * otherwise returns zero.
3596 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3601 /* Read the HBA Host Status Register */
3602 status
= lpfc_sli4_post_status_check(phba
);
3605 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3606 lpfc_sli_brdrestart(phba
);
3607 status
= lpfc_sli4_post_status_check(phba
);
3610 /* Check to see if any errors occurred during init */
3612 phba
->link_state
= LPFC_HBA_ERROR
;
3615 phba
->sli4_hba
.intr_enable
= 0;
3621 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3622 * @phba: Pointer to HBA context object.
3623 * @mask: Bit mask to be checked.
3625 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3626 * from the API jump table function pointer from the lpfc_hba struct.
3629 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3631 return phba
->lpfc_sli_brdready(phba
, mask
);
3634 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3637 * lpfc_reset_barrier - Make HBA ready for HBA reset
3638 * @phba: Pointer to HBA context object.
3640 * This function is called before resetting an HBA. This function is called
3641 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3643 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3645 uint32_t __iomem
*resp_buf
;
3646 uint32_t __iomem
*mbox_buf
;
3647 volatile uint32_t mbox
;
3648 uint32_t hc_copy
, ha_copy
, resp_data
;
3652 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3653 if (hdrtype
!= 0x80 ||
3654 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3655 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3659 * Tell the other part of the chip to suspend temporarily all
3662 resp_buf
= phba
->MBslimaddr
;
3664 /* Disable the error attention */
3665 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3667 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3668 readl(phba
->HCregaddr
); /* flush */
3669 phba
->link_flag
|= LS_IGNORE_ERATT
;
3671 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3673 if (ha_copy
& HA_ERATT
) {
3674 /* Clear Chip error bit */
3675 writel(HA_ERATT
, phba
->HAregaddr
);
3676 phba
->pport
->stopped
= 1;
3680 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3681 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3683 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3684 mbox_buf
= phba
->MBslimaddr
;
3685 writel(mbox
, mbox_buf
);
3687 for (i
= 0; i
< 50; i
++) {
3688 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3690 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3696 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3698 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3699 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3700 phba
->pport
->stopped
)
3706 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3708 for (i
= 0; i
< 500; i
++) {
3709 if (lpfc_readl(resp_buf
, &resp_data
))
3711 if (resp_data
!= mbox
)
3720 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3722 if (!(ha_copy
& HA_ERATT
))
3728 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3729 writel(HA_ERATT
, phba
->HAregaddr
);
3730 phba
->pport
->stopped
= 1;
3734 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3735 writel(hc_copy
, phba
->HCregaddr
);
3736 readl(phba
->HCregaddr
); /* flush */
3740 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3741 * @phba: Pointer to HBA context object.
3743 * This function issues a kill_board mailbox command and waits for
3744 * the error attention interrupt. This function is called for stopping
3745 * the firmware processing. The caller is not required to hold any
3746 * locks. This function calls lpfc_hba_down_post function to free
3747 * any pending commands after the kill. The function will return 1 when it
3748 * fails to kill the board else will return 0.
3751 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3753 struct lpfc_sli
*psli
;
3763 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3764 "0329 Kill HBA Data: x%x x%x\n",
3765 phba
->pport
->port_state
, psli
->sli_flag
);
3767 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3771 /* Disable the error attention */
3772 spin_lock_irq(&phba
->hbalock
);
3773 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3774 spin_unlock_irq(&phba
->hbalock
);
3775 mempool_free(pmb
, phba
->mbox_mem_pool
);
3778 status
&= ~HC_ERINT_ENA
;
3779 writel(status
, phba
->HCregaddr
);
3780 readl(phba
->HCregaddr
); /* flush */
3781 phba
->link_flag
|= LS_IGNORE_ERATT
;
3782 spin_unlock_irq(&phba
->hbalock
);
3784 lpfc_kill_board(phba
, pmb
);
3785 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3786 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3788 if (retval
!= MBX_SUCCESS
) {
3789 if (retval
!= MBX_BUSY
)
3790 mempool_free(pmb
, phba
->mbox_mem_pool
);
3791 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3792 "2752 KILL_BOARD command failed retval %d\n",
3794 spin_lock_irq(&phba
->hbalock
);
3795 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3796 spin_unlock_irq(&phba
->hbalock
);
3800 spin_lock_irq(&phba
->hbalock
);
3801 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3802 spin_unlock_irq(&phba
->hbalock
);
3804 mempool_free(pmb
, phba
->mbox_mem_pool
);
3806 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3807 * attention every 100ms for 3 seconds. If we don't get ERATT after
3808 * 3 seconds we still set HBA_ERROR state because the status of the
3809 * board is now undefined.
3811 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3813 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3815 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3819 del_timer_sync(&psli
->mbox_tmo
);
3820 if (ha_copy
& HA_ERATT
) {
3821 writel(HA_ERATT
, phba
->HAregaddr
);
3822 phba
->pport
->stopped
= 1;
3824 spin_lock_irq(&phba
->hbalock
);
3825 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3826 psli
->mbox_active
= NULL
;
3827 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3828 spin_unlock_irq(&phba
->hbalock
);
3830 lpfc_hba_down_post(phba
);
3831 phba
->link_state
= LPFC_HBA_ERROR
;
3833 return ha_copy
& HA_ERATT
? 0 : 1;
3837 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3838 * @phba: Pointer to HBA context object.
3840 * This function resets the HBA by writing HC_INITFF to the control
3841 * register. After the HBA resets, this function resets all the iocb ring
3842 * indices. This function disables PCI layer parity checking during
3844 * This function returns 0 always.
3845 * The caller is not required to hold any locks.
3848 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3850 struct lpfc_sli
*psli
;
3851 struct lpfc_sli_ring
*pring
;
3858 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3859 "0325 Reset HBA Data: x%x x%x\n",
3860 phba
->pport
->port_state
, psli
->sli_flag
);
3862 /* perform board reset */
3863 phba
->fc_eventTag
= 0;
3864 phba
->link_events
= 0;
3865 phba
->pport
->fc_myDID
= 0;
3866 phba
->pport
->fc_prevDID
= 0;
3868 /* Turn off parity checking and serr during the physical reset */
3869 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3870 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3872 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3874 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3876 /* Now toggle INITFF bit in the Host Control Register */
3877 writel(HC_INITFF
, phba
->HCregaddr
);
3879 readl(phba
->HCregaddr
); /* flush */
3880 writel(0, phba
->HCregaddr
);
3881 readl(phba
->HCregaddr
); /* flush */
3883 /* Restore PCI cmd register */
3884 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3886 /* Initialize relevant SLI info */
3887 for (i
= 0; i
< psli
->num_rings
; i
++) {
3888 pring
= &psli
->ring
[i
];
3890 pring
->sli
.sli3
.rspidx
= 0;
3891 pring
->sli
.sli3
.next_cmdidx
= 0;
3892 pring
->sli
.sli3
.local_getidx
= 0;
3893 pring
->sli
.sli3
.cmdidx
= 0;
3894 pring
->missbufcnt
= 0;
3897 phba
->link_state
= LPFC_WARM_START
;
3902 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3903 * @phba: Pointer to HBA context object.
3905 * This function resets a SLI4 HBA. This function disables PCI layer parity
3906 * checking during resets the device. The caller is not required to hold
3909 * This function returns 0 always.
3912 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3914 struct lpfc_sli
*psli
= &phba
->sli
;
3919 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3920 "0295 Reset HBA Data: x%x x%x\n",
3921 phba
->pport
->port_state
, psli
->sli_flag
);
3923 /* perform board reset */
3924 phba
->fc_eventTag
= 0;
3925 phba
->link_events
= 0;
3926 phba
->pport
->fc_myDID
= 0;
3927 phba
->pport
->fc_prevDID
= 0;
3929 spin_lock_irq(&phba
->hbalock
);
3930 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3931 phba
->fcf
.fcf_flag
= 0;
3932 spin_unlock_irq(&phba
->hbalock
);
3934 /* Now physically reset the device */
3935 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3936 "0389 Performing PCI function reset!\n");
3938 /* Turn off parity checking and serr during the physical reset */
3939 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3940 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3941 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3943 /* Perform FCoE PCI function reset */
3944 lpfc_sli4_queue_destroy(phba
);
3945 rc
= lpfc_pci_function_reset(phba
);
3947 /* Restore PCI cmd register */
3948 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3954 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3955 * @phba: Pointer to HBA context object.
3957 * This function is called in the SLI initialization code path to
3958 * restart the HBA. The caller is not required to hold any lock.
3959 * This function writes MBX_RESTART mailbox command to the SLIM and
3960 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3961 * function to free any pending commands. The function enables
3962 * POST only during the first initialization. The function returns zero.
3963 * The function does not guarantee completion of MBX_RESTART mailbox
3964 * command before the return of this function.
3967 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3970 struct lpfc_sli
*psli
;
3971 volatile uint32_t word0
;
3972 void __iomem
*to_slim
;
3973 uint32_t hba_aer_enabled
;
3975 spin_lock_irq(&phba
->hbalock
);
3977 /* Take PCIe device Advanced Error Reporting (AER) state */
3978 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3983 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3984 "0337 Restart HBA Data: x%x x%x\n",
3985 phba
->pport
->port_state
, psli
->sli_flag
);
3988 mb
= (MAILBOX_t
*) &word0
;
3989 mb
->mbxCommand
= MBX_RESTART
;
3992 lpfc_reset_barrier(phba
);
3994 to_slim
= phba
->MBslimaddr
;
3995 writel(*(uint32_t *) mb
, to_slim
);
3996 readl(to_slim
); /* flush */
3998 /* Only skip post after fc_ffinit is completed */
3999 if (phba
->pport
->port_state
)
4000 word0
= 1; /* This is really setting up word1 */
4002 word0
= 0; /* This is really setting up word1 */
4003 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4004 writel(*(uint32_t *) mb
, to_slim
);
4005 readl(to_slim
); /* flush */
4007 lpfc_sli_brdreset(phba
);
4008 phba
->pport
->stopped
= 0;
4009 phba
->link_state
= LPFC_INIT_START
;
4011 spin_unlock_irq(&phba
->hbalock
);
4013 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4014 psli
->stats_start
= get_seconds();
4016 /* Give the INITFF and Post time to settle. */
4019 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4020 if (hba_aer_enabled
)
4021 pci_disable_pcie_error_reporting(phba
->pcidev
);
4023 lpfc_hba_down_post(phba
);
4029 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4030 * @phba: Pointer to HBA context object.
4032 * This function is called in the SLI initialization code path to restart
4033 * a SLI4 HBA. The caller is not required to hold any lock.
4034 * At the end of the function, it calls lpfc_hba_down_post function to
4035 * free any pending commands.
4038 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4040 struct lpfc_sli
*psli
= &phba
->sli
;
4041 uint32_t hba_aer_enabled
;
4045 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4046 "0296 Restart HBA Data: x%x x%x\n",
4047 phba
->pport
->port_state
, psli
->sli_flag
);
4049 /* Take PCIe device Advanced Error Reporting (AER) state */
4050 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4052 rc
= lpfc_sli4_brdreset(phba
);
4054 spin_lock_irq(&phba
->hbalock
);
4055 phba
->pport
->stopped
= 0;
4056 phba
->link_state
= LPFC_INIT_START
;
4058 spin_unlock_irq(&phba
->hbalock
);
4060 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4061 psli
->stats_start
= get_seconds();
4063 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4064 if (hba_aer_enabled
)
4065 pci_disable_pcie_error_reporting(phba
->pcidev
);
4067 lpfc_hba_down_post(phba
);
4073 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4074 * @phba: Pointer to HBA context object.
4076 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4077 * API jump table function pointer from the lpfc_hba struct.
4080 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4082 return phba
->lpfc_sli_brdrestart(phba
);
4086 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4087 * @phba: Pointer to HBA context object.
4089 * This function is called after a HBA restart to wait for successful
4090 * restart of the HBA. Successful restart of the HBA is indicated by
4091 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4092 * iteration, the function will restart the HBA again. The function returns
4093 * zero if HBA successfully restarted else returns negative error code.
4096 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4098 uint32_t status
, i
= 0;
4100 /* Read the HBA Host Status Register */
4101 if (lpfc_readl(phba
->HSregaddr
, &status
))
4104 /* Check status register to see what current state is */
4106 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4108 /* Check every 10ms for 10 retries, then every 100ms for 90
4109 * retries, then every 1 sec for 50 retires for a total of
4110 * ~60 seconds before reset the board again and check every
4111 * 1 sec for 50 retries. The up to 60 seconds before the
4112 * board ready is required by the Falcon FIPS zeroization
4113 * complete, and any reset the board in between shall cause
4114 * restart of zeroization, further delay the board ready.
4117 /* Adapter failed to init, timeout, status reg
4119 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4120 "0436 Adapter failed to init, "
4121 "timeout, status reg x%x, "
4122 "FW Data: A8 x%x AC x%x\n", status
,
4123 readl(phba
->MBslimaddr
+ 0xa8),
4124 readl(phba
->MBslimaddr
+ 0xac));
4125 phba
->link_state
= LPFC_HBA_ERROR
;
4129 /* Check to see if any errors occurred during init */
4130 if (status
& HS_FFERM
) {
4131 /* ERROR: During chipset initialization */
4132 /* Adapter failed to init, chipset, status reg
4134 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4135 "0437 Adapter failed to init, "
4136 "chipset, status reg x%x, "
4137 "FW Data: A8 x%x AC x%x\n", status
,
4138 readl(phba
->MBslimaddr
+ 0xa8),
4139 readl(phba
->MBslimaddr
+ 0xac));
4140 phba
->link_state
= LPFC_HBA_ERROR
;
4153 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4154 lpfc_sli_brdrestart(phba
);
4156 /* Read the HBA Host Status Register */
4157 if (lpfc_readl(phba
->HSregaddr
, &status
))
4161 /* Check to see if any errors occurred during init */
4162 if (status
& HS_FFERM
) {
4163 /* ERROR: During chipset initialization */
4164 /* Adapter failed to init, chipset, status reg <status> */
4165 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4166 "0438 Adapter failed to init, chipset, "
4168 "FW Data: A8 x%x AC x%x\n", status
,
4169 readl(phba
->MBslimaddr
+ 0xa8),
4170 readl(phba
->MBslimaddr
+ 0xac));
4171 phba
->link_state
= LPFC_HBA_ERROR
;
4175 /* Clear all interrupt enable conditions */
4176 writel(0, phba
->HCregaddr
);
4177 readl(phba
->HCregaddr
); /* flush */
4179 /* setup host attn register */
4180 writel(0xffffffff, phba
->HAregaddr
);
4181 readl(phba
->HAregaddr
); /* flush */
4186 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4188 * This function calculates and returns the number of HBQs required to be
4192 lpfc_sli_hbq_count(void)
4194 return ARRAY_SIZE(lpfc_hbq_defs
);
4198 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4200 * This function adds the number of hbq entries in every HBQ to get
4201 * the total number of hbq entries required for the HBA and returns
4205 lpfc_sli_hbq_entry_count(void)
4207 int hbq_count
= lpfc_sli_hbq_count();
4211 for (i
= 0; i
< hbq_count
; ++i
)
4212 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4217 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4219 * This function calculates amount of memory required for all hbq entries
4220 * to be configured and returns the total memory required.
4223 lpfc_sli_hbq_size(void)
4225 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4229 * lpfc_sli_hbq_setup - configure and initialize HBQs
4230 * @phba: Pointer to HBA context object.
4232 * This function is called during the SLI initialization to configure
4233 * all the HBQs and post buffers to the HBQ. The caller is not
4234 * required to hold any locks. This function will return zero if successful
4235 * else it will return negative error code.
4238 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4240 int hbq_count
= lpfc_sli_hbq_count();
4244 uint32_t hbq_entry_index
;
4246 /* Get a Mailbox buffer to setup mailbox
4247 * commands for HBA initialization
4249 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4256 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4257 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4258 phba
->hbq_in_use
= 1;
4260 hbq_entry_index
= 0;
4261 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4262 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4263 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4264 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4265 phba
->hbqs
[hbqno
].entry_count
=
4266 lpfc_hbq_defs
[hbqno
]->entry_count
;
4267 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4268 hbq_entry_index
, pmb
);
4269 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4271 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4272 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4273 mbxStatus <status>, ring <num> */
4275 lpfc_printf_log(phba
, KERN_ERR
,
4276 LOG_SLI
| LOG_VPORT
,
4277 "1805 Adapter failed to init. "
4278 "Data: x%x x%x x%x\n",
4280 pmbox
->mbxStatus
, hbqno
);
4282 phba
->link_state
= LPFC_HBA_ERROR
;
4283 mempool_free(pmb
, phba
->mbox_mem_pool
);
4287 phba
->hbq_count
= hbq_count
;
4289 mempool_free(pmb
, phba
->mbox_mem_pool
);
4291 /* Initially populate or replenish the HBQs */
4292 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4293 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4298 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4299 * @phba: Pointer to HBA context object.
4301 * This function is called during the SLI initialization to configure
4302 * all the HBQs and post buffers to the HBQ. The caller is not
4303 * required to hold any locks. This function will return zero if successful
4304 * else it will return negative error code.
4307 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4309 phba
->hbq_in_use
= 1;
4310 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4311 phba
->hbq_count
= 1;
4312 /* Initially populate or replenish the HBQs */
4313 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4318 * lpfc_sli_config_port - Issue config port mailbox command
4319 * @phba: Pointer to HBA context object.
4320 * @sli_mode: sli mode - 2/3
4322 * This function is called by the sli intialization code path
4323 * to issue config_port mailbox command. This function restarts the
4324 * HBA firmware and issues a config_port mailbox command to configure
4325 * the SLI interface in the sli mode specified by sli_mode
4326 * variable. The caller is not required to hold any locks.
4327 * The function returns 0 if successful, else returns negative error
4331 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4334 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4336 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4338 phba
->link_state
= LPFC_HBA_ERROR
;
4342 phba
->sli_rev
= sli_mode
;
4343 while (resetcount
< 2 && !done
) {
4344 spin_lock_irq(&phba
->hbalock
);
4345 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4346 spin_unlock_irq(&phba
->hbalock
);
4347 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4348 lpfc_sli_brdrestart(phba
);
4349 rc
= lpfc_sli_chipset_init(phba
);
4353 spin_lock_irq(&phba
->hbalock
);
4354 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4355 spin_unlock_irq(&phba
->hbalock
);
4358 /* Call pre CONFIG_PORT mailbox command initialization. A
4359 * value of 0 means the call was successful. Any other
4360 * nonzero value is a failure, but if ERESTART is returned,
4361 * the driver may reset the HBA and try again.
4363 rc
= lpfc_config_port_prep(phba
);
4364 if (rc
== -ERESTART
) {
4365 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4370 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4371 lpfc_config_port(phba
, pmb
);
4372 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4373 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4374 LPFC_SLI3_HBQ_ENABLED
|
4375 LPFC_SLI3_CRP_ENABLED
|
4376 LPFC_SLI3_BG_ENABLED
|
4377 LPFC_SLI3_DSS_ENABLED
);
4378 if (rc
!= MBX_SUCCESS
) {
4379 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4380 "0442 Adapter failed to init, mbxCmd x%x "
4381 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4382 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4383 spin_lock_irq(&phba
->hbalock
);
4384 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4385 spin_unlock_irq(&phba
->hbalock
);
4388 /* Allow asynchronous mailbox command to go through */
4389 spin_lock_irq(&phba
->hbalock
);
4390 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4391 spin_unlock_irq(&phba
->hbalock
);
4394 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4395 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4396 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4397 "3110 Port did not grant ASABT\n");
4402 goto do_prep_failed
;
4404 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4405 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4407 goto do_prep_failed
;
4409 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4410 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4411 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4412 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4413 phba
->max_vpi
: phba
->max_vports
;
4417 phba
->fips_level
= 0;
4418 phba
->fips_spec_rev
= 0;
4419 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4420 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4421 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4422 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4423 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4424 "2850 Security Crypto Active. FIPS x%d "
4426 phba
->fips_level
, phba
->fips_spec_rev
);
4428 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4429 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4430 "2856 Config Port Security Crypto "
4432 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4434 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4435 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4436 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4437 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4439 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4440 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4442 if (phba
->cfg_enable_bg
) {
4443 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4444 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4446 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4447 "0443 Adapter did not grant "
4451 phba
->hbq_get
= NULL
;
4452 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4456 mempool_free(pmb
, phba
->mbox_mem_pool
);
4462 * lpfc_sli_hba_setup - SLI intialization function
4463 * @phba: Pointer to HBA context object.
4465 * This function is the main SLI intialization function. This function
4466 * is called by the HBA intialization code, HBA reset code and HBA
4467 * error attention handler code. Caller is not required to hold any
4468 * locks. This function issues config_port mailbox command to configure
4469 * the SLI, setup iocb rings and HBQ rings. In the end the function
4470 * calls the config_port_post function to issue init_link mailbox
4471 * command and to start the discovery. The function will return zero
4472 * if successful, else it will return negative error code.
4475 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4481 switch (lpfc_sli_mode
) {
4483 if (phba
->cfg_enable_npiv
) {
4484 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4485 "1824 NPIV enabled: Override lpfc_sli_mode "
4486 "parameter (%d) to auto (0).\n",
4496 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4497 "1819 Unrecognized lpfc_sli_mode "
4498 "parameter: %d.\n", lpfc_sli_mode
);
4503 rc
= lpfc_sli_config_port(phba
, mode
);
4505 if (rc
&& lpfc_sli_mode
== 3)
4506 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4507 "1820 Unable to select SLI-3. "
4508 "Not supported by adapter.\n");
4509 if (rc
&& mode
!= 2)
4510 rc
= lpfc_sli_config_port(phba
, 2);
4512 goto lpfc_sli_hba_setup_error
;
4514 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4515 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4516 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4518 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4519 "2709 This device supports "
4520 "Advanced Error Reporting (AER)\n");
4521 spin_lock_irq(&phba
->hbalock
);
4522 phba
->hba_flag
|= HBA_AER_ENABLED
;
4523 spin_unlock_irq(&phba
->hbalock
);
4525 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4526 "2708 This device does not support "
4527 "Advanced Error Reporting (AER)\n");
4528 phba
->cfg_aer_support
= 0;
4532 if (phba
->sli_rev
== 3) {
4533 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4534 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4536 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4537 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4538 phba
->sli3_options
= 0;
4541 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4542 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4543 phba
->sli_rev
, phba
->max_vpi
);
4544 rc
= lpfc_sli_ring_map(phba
);
4547 goto lpfc_sli_hba_setup_error
;
4549 /* Initialize VPIs. */
4550 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4552 * The VPI bitmask and physical ID array are allocated
4553 * and initialized once only - at driver load. A port
4554 * reset doesn't need to reinitialize this memory.
4556 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4557 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4558 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4560 if (!phba
->vpi_bmask
) {
4562 goto lpfc_sli_hba_setup_error
;
4565 phba
->vpi_ids
= kzalloc(
4566 (phba
->max_vpi
+1) * sizeof(uint16_t),
4568 if (!phba
->vpi_ids
) {
4569 kfree(phba
->vpi_bmask
);
4571 goto lpfc_sli_hba_setup_error
;
4573 for (i
= 0; i
< phba
->max_vpi
; i
++)
4574 phba
->vpi_ids
[i
] = i
;
4579 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4580 rc
= lpfc_sli_hbq_setup(phba
);
4582 goto lpfc_sli_hba_setup_error
;
4584 spin_lock_irq(&phba
->hbalock
);
4585 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4586 spin_unlock_irq(&phba
->hbalock
);
4588 rc
= lpfc_config_port_post(phba
);
4590 goto lpfc_sli_hba_setup_error
;
4594 lpfc_sli_hba_setup_error
:
4595 phba
->link_state
= LPFC_HBA_ERROR
;
4596 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4597 "0445 Firmware initialization failed\n");
4602 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4603 * @phba: Pointer to HBA context object.
4604 * @mboxq: mailbox pointer.
4605 * This function issue a dump mailbox command to read config region
4606 * 23 and parse the records in the region and populate driver
4610 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4612 LPFC_MBOXQ_t
*mboxq
;
4613 struct lpfc_dmabuf
*mp
;
4614 struct lpfc_mqe
*mqe
;
4615 uint32_t data_length
;
4618 /* Program the default value of vlan_id and fc_map */
4619 phba
->valid_vlan
= 0;
4620 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4621 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4622 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4624 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4628 mqe
= &mboxq
->u
.mqe
;
4629 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4631 goto out_free_mboxq
;
4634 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4635 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4637 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4638 "(%d):2571 Mailbox cmd x%x Status x%x "
4639 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4640 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4641 "CQ: x%x x%x x%x x%x\n",
4642 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4643 bf_get(lpfc_mqe_command
, mqe
),
4644 bf_get(lpfc_mqe_status
, mqe
),
4645 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4646 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4647 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4648 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4649 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4650 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4651 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4652 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4653 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4655 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4656 mboxq
->mcqe
.trailer
);
4659 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4662 goto out_free_mboxq
;
4664 data_length
= mqe
->un
.mb_words
[5];
4665 if (data_length
> DMP_RGN23_SIZE
) {
4666 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4669 goto out_free_mboxq
;
4672 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4673 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4678 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4683 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4684 * @phba: pointer to lpfc hba data structure.
4685 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4686 * @vpd: pointer to the memory to hold resulting port vpd data.
4687 * @vpd_size: On input, the number of bytes allocated to @vpd.
4688 * On output, the number of data bytes in @vpd.
4690 * This routine executes a READ_REV SLI4 mailbox command. In
4691 * addition, this routine gets the port vpd data.
4695 * -ENOMEM - could not allocated memory.
4698 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4699 uint8_t *vpd
, uint32_t *vpd_size
)
4703 struct lpfc_dmabuf
*dmabuf
;
4704 struct lpfc_mqe
*mqe
;
4706 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4711 * Get a DMA buffer for the vpd data resulting from the READ_REV
4714 dma_size
= *vpd_size
;
4715 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4719 if (!dmabuf
->virt
) {
4723 memset(dmabuf
->virt
, 0, dma_size
);
4726 * The SLI4 implementation of READ_REV conflicts at word1,
4727 * bits 31:16 and SLI4 adds vpd functionality not present
4728 * in SLI3. This code corrects the conflicts.
4730 lpfc_read_rev(phba
, mboxq
);
4731 mqe
= &mboxq
->u
.mqe
;
4732 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4733 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4734 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4735 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4736 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4738 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4740 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4741 dmabuf
->virt
, dmabuf
->phys
);
4747 * The available vpd length cannot be bigger than the
4748 * DMA buffer passed to the port. Catch the less than
4749 * case and update the caller's size.
4751 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4752 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4754 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4756 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4757 dmabuf
->virt
, dmabuf
->phys
);
4763 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4764 * @phba: pointer to lpfc hba data structure.
4766 * This routine retrieves SLI4 device physical port name this PCI function
4771 * otherwise - failed to retrieve physical port name
4774 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4776 LPFC_MBOXQ_t
*mboxq
;
4777 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4778 struct lpfc_controller_attribute
*cntl_attr
;
4779 struct lpfc_mbx_get_port_name
*get_port_name
;
4780 void *virtaddr
= NULL
;
4781 uint32_t alloclen
, reqlen
;
4782 uint32_t shdr_status
, shdr_add_status
;
4783 union lpfc_sli4_cfg_shdr
*shdr
;
4784 char cport_name
= 0;
4787 /* We assume nothing at this point */
4788 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4789 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4791 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4794 /* obtain link type and link number via READ_CONFIG */
4795 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4796 lpfc_sli4_read_config(phba
);
4797 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4798 goto retrieve_ppname
;
4800 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4801 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4802 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4803 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4804 LPFC_SLI4_MBX_NEMBED
);
4805 if (alloclen
< reqlen
) {
4806 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4807 "3084 Allocated DMA memory size (%d) is "
4808 "less than the requested DMA memory size "
4809 "(%d)\n", alloclen
, reqlen
);
4811 goto out_free_mboxq
;
4813 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4814 virtaddr
= mboxq
->sge_array
->addr
[0];
4815 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4816 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4817 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4818 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4819 if (shdr_status
|| shdr_add_status
|| rc
) {
4820 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4821 "3085 Mailbox x%x (x%x/x%x) failed, "
4822 "rc:x%x, status:x%x, add_status:x%x\n",
4823 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4824 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4825 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4826 rc
, shdr_status
, shdr_add_status
);
4828 goto out_free_mboxq
;
4830 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4831 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4832 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4833 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4834 phba
->sli4_hba
.lnk_info
.lnk_no
=
4835 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4836 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4837 "3086 lnk_type:%d, lnk_numb:%d\n",
4838 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4839 phba
->sli4_hba
.lnk_info
.lnk_no
);
4842 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4843 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4844 sizeof(struct lpfc_mbx_get_port_name
) -
4845 sizeof(struct lpfc_sli4_cfg_mhdr
),
4846 LPFC_SLI4_MBX_EMBED
);
4847 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4848 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4849 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4850 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4851 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4852 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4853 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4854 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4855 if (shdr_status
|| shdr_add_status
|| rc
) {
4856 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4857 "3087 Mailbox x%x (x%x/x%x) failed: "
4858 "rc:x%x, status:x%x, add_status:x%x\n",
4859 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4860 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4861 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4862 rc
, shdr_status
, shdr_add_status
);
4864 goto out_free_mboxq
;
4866 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4867 case LPFC_LINK_NUMBER_0
:
4868 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4869 &get_port_name
->u
.response
);
4870 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4872 case LPFC_LINK_NUMBER_1
:
4873 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4874 &get_port_name
->u
.response
);
4875 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4877 case LPFC_LINK_NUMBER_2
:
4878 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4879 &get_port_name
->u
.response
);
4880 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4882 case LPFC_LINK_NUMBER_3
:
4883 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4884 &get_port_name
->u
.response
);
4885 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4891 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4892 phba
->Port
[0] = cport_name
;
4893 phba
->Port
[1] = '\0';
4894 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4895 "3091 SLI get port name: %s\n", phba
->Port
);
4899 if (rc
!= MBX_TIMEOUT
) {
4900 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4901 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4903 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4909 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4910 * @phba: pointer to lpfc hba data structure.
4912 * This routine is called to explicitly arm the SLI4 device's completion and
4916 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4920 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4921 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4923 if (phba
->sli4_hba
.fcp_cq
) {
4925 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4927 } while (++fcp_eqidx
< phba
->cfg_fcp_io_channel
);
4929 if (phba
->sli4_hba
.hba_eq
) {
4930 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
4932 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
4938 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4939 * @phba: Pointer to HBA context object.
4940 * @type: The resource extent type.
4941 * @extnt_count: buffer to hold port available extent count.
4942 * @extnt_size: buffer to hold element count per extent.
4944 * This function calls the port and retrievs the number of available
4945 * extents and their size for a particular extent type.
4947 * Returns: 0 if successful. Nonzero otherwise.
4950 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
4951 uint16_t *extnt_count
, uint16_t *extnt_size
)
4956 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
4959 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4963 /* Find out how many extents are available for this resource type */
4964 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
4965 sizeof(struct lpfc_sli4_cfg_mhdr
));
4966 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4967 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
4968 length
, LPFC_SLI4_MBX_EMBED
);
4970 /* Send an extents count of 0 - the GET doesn't use it. */
4971 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
4972 LPFC_SLI4_MBX_EMBED
);
4978 if (!phba
->sli4_hba
.intr_enable
)
4979 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
4981 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
4982 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
4989 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
4990 if (bf_get(lpfc_mbox_hdr_status
,
4991 &rsrc_info
->header
.cfg_shdr
.response
)) {
4992 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4993 "2930 Failed to get resource extents "
4994 "Status 0x%x Add'l Status 0x%x\n",
4995 bf_get(lpfc_mbox_hdr_status
,
4996 &rsrc_info
->header
.cfg_shdr
.response
),
4997 bf_get(lpfc_mbox_hdr_add_status
,
4998 &rsrc_info
->header
.cfg_shdr
.response
));
5003 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5005 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5008 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5009 "3162 Retrieved extents type-%d from port: count:%d, "
5010 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5013 mempool_free(mbox
, phba
->mbox_mem_pool
);
5018 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5019 * @phba: Pointer to HBA context object.
5020 * @type: The extent type to check.
5022 * This function reads the current available extents from the port and checks
5023 * if the extent count or extent size has changed since the last access.
5024 * Callers use this routine post port reset to understand if there is a
5025 * extent reprovisioning requirement.
5028 * -Error: error indicates problem.
5029 * 1: Extent count or size has changed.
5033 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5035 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5036 uint16_t size_diff
, rsrc_ext_size
;
5038 struct lpfc_rsrc_blks
*rsrc_entry
;
5039 struct list_head
*rsrc_blk_list
= NULL
;
5043 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5050 case LPFC_RSC_TYPE_FCOE_RPI
:
5051 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5053 case LPFC_RSC_TYPE_FCOE_VPI
:
5054 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5056 case LPFC_RSC_TYPE_FCOE_XRI
:
5057 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5059 case LPFC_RSC_TYPE_FCOE_VFI
:
5060 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5066 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5068 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5072 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5079 * lpfc_sli4_cfg_post_extnts -
5080 * @phba: Pointer to HBA context object.
5081 * @extnt_cnt - number of available extents.
5082 * @type - the extent type (rpi, xri, vfi, vpi).
5083 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5084 * @mbox - pointer to the caller's allocated mailbox structure.
5086 * This function executes the extents allocation request. It also
5087 * takes care of the amount of memory needed to allocate or get the
5088 * allocated extents. It is the caller's responsibility to evaluate
5092 * -Error: Error value describes the condition found.
5096 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5097 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5102 uint32_t alloc_len
, mbox_tmo
;
5104 /* Calculate the total requested length of the dma memory */
5105 req_len
= extnt_cnt
* sizeof(uint16_t);
5108 * Calculate the size of an embedded mailbox. The uint32_t
5109 * accounts for extents-specific word.
5111 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5115 * Presume the allocation and response will fit into an embedded
5116 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5118 *emb
= LPFC_SLI4_MBX_EMBED
;
5119 if (req_len
> emb_len
) {
5120 req_len
= extnt_cnt
* sizeof(uint16_t) +
5121 sizeof(union lpfc_sli4_cfg_shdr
) +
5123 *emb
= LPFC_SLI4_MBX_NEMBED
;
5126 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5127 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5129 if (alloc_len
< req_len
) {
5130 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5131 "2982 Allocated DMA memory size (x%x) is "
5132 "less than the requested DMA memory "
5133 "size (x%x)\n", alloc_len
, req_len
);
5136 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5140 if (!phba
->sli4_hba
.intr_enable
)
5141 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5143 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5144 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5153 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5154 * @phba: Pointer to HBA context object.
5155 * @type: The resource extent type to allocate.
5157 * This function allocates the number of elements for the specified
5161 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5164 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5165 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5168 unsigned long longs
;
5169 unsigned long *bmask
;
5170 struct lpfc_rsrc_blks
*rsrc_blks
;
5173 struct lpfc_id_range
*id_array
= NULL
;
5174 void *virtaddr
= NULL
;
5175 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5176 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5177 struct list_head
*ext_blk_list
;
5179 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5185 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5186 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5187 "3009 No available Resource Extents "
5188 "for resource type 0x%x: Count: 0x%x, "
5189 "Size 0x%x\n", type
, rsrc_cnt
,
5194 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5195 "2903 Post resource extents type-0x%x: "
5196 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5198 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5202 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5209 * Figure out where the response is located. Then get local pointers
5210 * to the response data. The port does not guarantee to respond to
5211 * all extents counts request so update the local variable with the
5212 * allocated count from the port.
5214 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5215 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5216 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5217 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5219 virtaddr
= mbox
->sge_array
->addr
[0];
5220 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5221 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5222 id_array
= &n_rsrc
->id
;
5225 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5226 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5229 * Based on the resource size and count, correct the base and max
5232 length
= sizeof(struct lpfc_rsrc_blks
);
5234 case LPFC_RSC_TYPE_FCOE_RPI
:
5235 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5236 sizeof(unsigned long),
5238 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5242 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5245 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5246 kfree(phba
->sli4_hba
.rpi_bmask
);
5252 * The next_rpi was initialized with the maximum available
5253 * count but the port may allocate a smaller number. Catch
5254 * that case and update the next_rpi.
5256 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5258 /* Initialize local ptrs for common extent processing later. */
5259 bmask
= phba
->sli4_hba
.rpi_bmask
;
5260 ids
= phba
->sli4_hba
.rpi_ids
;
5261 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5263 case LPFC_RSC_TYPE_FCOE_VPI
:
5264 phba
->vpi_bmask
= kzalloc(longs
*
5265 sizeof(unsigned long),
5267 if (unlikely(!phba
->vpi_bmask
)) {
5271 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5274 if (unlikely(!phba
->vpi_ids
)) {
5275 kfree(phba
->vpi_bmask
);
5280 /* Initialize local ptrs for common extent processing later. */
5281 bmask
= phba
->vpi_bmask
;
5282 ids
= phba
->vpi_ids
;
5283 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5285 case LPFC_RSC_TYPE_FCOE_XRI
:
5286 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5287 sizeof(unsigned long),
5289 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5293 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5294 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5297 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5298 kfree(phba
->sli4_hba
.xri_bmask
);
5303 /* Initialize local ptrs for common extent processing later. */
5304 bmask
= phba
->sli4_hba
.xri_bmask
;
5305 ids
= phba
->sli4_hba
.xri_ids
;
5306 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5308 case LPFC_RSC_TYPE_FCOE_VFI
:
5309 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5310 sizeof(unsigned long),
5312 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5316 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5319 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5320 kfree(phba
->sli4_hba
.vfi_bmask
);
5325 /* Initialize local ptrs for common extent processing later. */
5326 bmask
= phba
->sli4_hba
.vfi_bmask
;
5327 ids
= phba
->sli4_hba
.vfi_ids
;
5328 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5331 /* Unsupported Opcode. Fail call. */
5335 ext_blk_list
= NULL
;
5340 * Complete initializing the extent configuration with the
5341 * allocated ids assigned to this function. The bitmask serves
5342 * as an index into the array and manages the available ids. The
5343 * array just stores the ids communicated to the port via the wqes.
5345 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5347 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5350 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5353 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5354 if (unlikely(!rsrc_blks
)) {
5360 rsrc_blks
->rsrc_start
= rsrc_id
;
5361 rsrc_blks
->rsrc_size
= rsrc_size
;
5362 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5363 rsrc_start
= rsrc_id
;
5364 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5365 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5366 lpfc_sli4_get_els_iocb_cnt(phba
);
5368 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5373 /* Entire word processed. Get next word.*/
5378 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5383 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5384 * @phba: Pointer to HBA context object.
5385 * @type: the extent's type.
5387 * This function deallocates all extents of a particular resource type.
5388 * SLI4 does not allow for deallocating a particular extent range. It
5389 * is the caller's responsibility to release all kernel memory resources.
5392 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5395 uint32_t length
, mbox_tmo
= 0;
5397 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5398 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5400 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5405 * This function sends an embedded mailbox because it only sends the
5406 * the resource type. All extents of this type are released by the
5409 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5410 sizeof(struct lpfc_sli4_cfg_mhdr
));
5411 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5412 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5413 length
, LPFC_SLI4_MBX_EMBED
);
5415 /* Send an extents count of 0 - the dealloc doesn't use it. */
5416 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5417 LPFC_SLI4_MBX_EMBED
);
5422 if (!phba
->sli4_hba
.intr_enable
)
5423 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5425 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5426 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5433 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5434 if (bf_get(lpfc_mbox_hdr_status
,
5435 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5436 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5437 "2919 Failed to release resource extents "
5438 "for type %d - Status 0x%x Add'l Status 0x%x. "
5439 "Resource memory not released.\n",
5441 bf_get(lpfc_mbox_hdr_status
,
5442 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5443 bf_get(lpfc_mbox_hdr_add_status
,
5444 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5449 /* Release kernel memory resources for the specific type. */
5451 case LPFC_RSC_TYPE_FCOE_VPI
:
5452 kfree(phba
->vpi_bmask
);
5453 kfree(phba
->vpi_ids
);
5454 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5455 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5456 &phba
->lpfc_vpi_blk_list
, list
) {
5457 list_del_init(&rsrc_blk
->list
);
5461 case LPFC_RSC_TYPE_FCOE_XRI
:
5462 kfree(phba
->sli4_hba
.xri_bmask
);
5463 kfree(phba
->sli4_hba
.xri_ids
);
5464 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5465 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5466 list_del_init(&rsrc_blk
->list
);
5470 case LPFC_RSC_TYPE_FCOE_VFI
:
5471 kfree(phba
->sli4_hba
.vfi_bmask
);
5472 kfree(phba
->sli4_hba
.vfi_ids
);
5473 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5474 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5475 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5476 list_del_init(&rsrc_blk
->list
);
5480 case LPFC_RSC_TYPE_FCOE_RPI
:
5481 /* RPI bitmask and physical id array are cleaned up earlier. */
5482 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5483 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5484 list_del_init(&rsrc_blk
->list
);
5492 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5495 mempool_free(mbox
, phba
->mbox_mem_pool
);
5500 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5501 * @phba: Pointer to HBA context object.
5503 * This function allocates all SLI4 resource identifiers.
5506 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5508 int i
, rc
, error
= 0;
5509 uint16_t count
, base
;
5510 unsigned long longs
;
5512 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5513 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5514 if (phba
->sli4_hba
.extents_in_use
) {
5516 * The port supports resource extents. The XRI, VPI, VFI, RPI
5517 * resource extent count must be read and allocated before
5518 * provisioning the resource id arrays.
5520 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5521 LPFC_IDX_RSRC_RDY
) {
5523 * Extent-based resources are set - the driver could
5524 * be in a port reset. Figure out if any corrective
5525 * actions need to be taken.
5527 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5528 LPFC_RSC_TYPE_FCOE_VFI
);
5531 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5532 LPFC_RSC_TYPE_FCOE_VPI
);
5535 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5536 LPFC_RSC_TYPE_FCOE_XRI
);
5539 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5540 LPFC_RSC_TYPE_FCOE_RPI
);
5545 * It's possible that the number of resources
5546 * provided to this port instance changed between
5547 * resets. Detect this condition and reallocate
5548 * resources. Otherwise, there is no action.
5551 lpfc_printf_log(phba
, KERN_INFO
,
5552 LOG_MBOX
| LOG_INIT
,
5553 "2931 Detected extent resource "
5554 "change. Reallocating all "
5556 rc
= lpfc_sli4_dealloc_extent(phba
,
5557 LPFC_RSC_TYPE_FCOE_VFI
);
5558 rc
= lpfc_sli4_dealloc_extent(phba
,
5559 LPFC_RSC_TYPE_FCOE_VPI
);
5560 rc
= lpfc_sli4_dealloc_extent(phba
,
5561 LPFC_RSC_TYPE_FCOE_XRI
);
5562 rc
= lpfc_sli4_dealloc_extent(phba
,
5563 LPFC_RSC_TYPE_FCOE_RPI
);
5568 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5572 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5576 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5580 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5583 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5588 * The port does not support resource extents. The XRI, VPI,
5589 * VFI, RPI resource ids were determined from READ_CONFIG.
5590 * Just allocate the bitmasks and provision the resource id
5591 * arrays. If a port reset is active, the resources don't
5592 * need any action - just exit.
5594 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5595 LPFC_IDX_RSRC_RDY
) {
5596 lpfc_sli4_dealloc_resource_identifiers(phba
);
5597 lpfc_sli4_remove_rpis(phba
);
5600 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5601 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5602 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5603 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5604 sizeof(unsigned long),
5606 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5610 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5613 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5615 goto free_rpi_bmask
;
5618 for (i
= 0; i
< count
; i
++)
5619 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5622 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5623 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5624 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5625 phba
->vpi_bmask
= kzalloc(longs
*
5626 sizeof(unsigned long),
5628 if (unlikely(!phba
->vpi_bmask
)) {
5632 phba
->vpi_ids
= kzalloc(count
*
5635 if (unlikely(!phba
->vpi_ids
)) {
5637 goto free_vpi_bmask
;
5640 for (i
= 0; i
< count
; i
++)
5641 phba
->vpi_ids
[i
] = base
+ i
;
5644 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5645 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5646 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5647 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5648 sizeof(unsigned long),
5650 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5654 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5655 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5658 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5660 goto free_xri_bmask
;
5663 for (i
= 0; i
< count
; i
++)
5664 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5667 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5668 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5669 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5670 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5671 sizeof(unsigned long),
5673 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5677 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5680 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5682 goto free_vfi_bmask
;
5685 for (i
= 0; i
< count
; i
++)
5686 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5689 * Mark all resources ready. An HBA reset doesn't need
5690 * to reset the initialization.
5692 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5698 kfree(phba
->sli4_hba
.vfi_bmask
);
5700 kfree(phba
->sli4_hba
.xri_ids
);
5702 kfree(phba
->sli4_hba
.xri_bmask
);
5704 kfree(phba
->vpi_ids
);
5706 kfree(phba
->vpi_bmask
);
5708 kfree(phba
->sli4_hba
.rpi_ids
);
5710 kfree(phba
->sli4_hba
.rpi_bmask
);
5716 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5717 * @phba: Pointer to HBA context object.
5719 * This function allocates the number of elements for the specified
5723 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5725 if (phba
->sli4_hba
.extents_in_use
) {
5726 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5727 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5728 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5729 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5731 kfree(phba
->vpi_bmask
);
5732 kfree(phba
->vpi_ids
);
5733 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5734 kfree(phba
->sli4_hba
.xri_bmask
);
5735 kfree(phba
->sli4_hba
.xri_ids
);
5736 kfree(phba
->sli4_hba
.vfi_bmask
);
5737 kfree(phba
->sli4_hba
.vfi_ids
);
5738 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5739 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5746 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5747 * @phba: Pointer to HBA context object.
5748 * @type: The resource extent type.
5749 * @extnt_count: buffer to hold port extent count response
5750 * @extnt_size: buffer to hold port extent size response.
5752 * This function calls the port to read the host allocated extents
5753 * for a particular type.
5756 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5757 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5761 uint16_t curr_blks
= 0;
5762 uint32_t req_len
, emb_len
;
5763 uint32_t alloc_len
, mbox_tmo
;
5764 struct list_head
*blk_list_head
;
5765 struct lpfc_rsrc_blks
*rsrc_blk
;
5767 void *virtaddr
= NULL
;
5768 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5769 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5770 union lpfc_sli4_cfg_shdr
*shdr
;
5773 case LPFC_RSC_TYPE_FCOE_VPI
:
5774 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5776 case LPFC_RSC_TYPE_FCOE_XRI
:
5777 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5779 case LPFC_RSC_TYPE_FCOE_VFI
:
5780 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5782 case LPFC_RSC_TYPE_FCOE_RPI
:
5783 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5789 /* Count the number of extents currently allocatd for this type. */
5790 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5791 if (curr_blks
== 0) {
5793 * The GET_ALLOCATED mailbox does not return the size,
5794 * just the count. The size should be just the size
5795 * stored in the current allocated block and all sizes
5796 * for an extent type are the same so set the return
5799 *extnt_size
= rsrc_blk
->rsrc_size
;
5804 /* Calculate the total requested length of the dma memory. */
5805 req_len
= curr_blks
* sizeof(uint16_t);
5808 * Calculate the size of an embedded mailbox. The uint32_t
5809 * accounts for extents-specific word.
5811 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5815 * Presume the allocation and response will fit into an embedded
5816 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5818 emb
= LPFC_SLI4_MBX_EMBED
;
5820 if (req_len
> emb_len
) {
5821 req_len
= curr_blks
* sizeof(uint16_t) +
5822 sizeof(union lpfc_sli4_cfg_shdr
) +
5824 emb
= LPFC_SLI4_MBX_NEMBED
;
5827 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5830 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5832 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5833 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5835 if (alloc_len
< req_len
) {
5836 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5837 "2983 Allocated DMA memory size (x%x) is "
5838 "less than the requested DMA memory "
5839 "size (x%x)\n", alloc_len
, req_len
);
5843 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5849 if (!phba
->sli4_hba
.intr_enable
)
5850 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5852 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5853 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5862 * Figure out where the response is located. Then get local pointers
5863 * to the response data. The port does not guarantee to respond to
5864 * all extents counts request so update the local variable with the
5865 * allocated count from the port.
5867 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5868 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5869 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5870 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5872 virtaddr
= mbox
->sge_array
->addr
[0];
5873 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5874 shdr
= &n_rsrc
->cfg_shdr
;
5875 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5878 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5879 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5880 "2984 Failed to read allocated resources "
5881 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5883 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5884 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5889 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5894 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
5895 * @phba: pointer to lpfc hba data structure.
5897 * This routine walks the list of els buffers that have been allocated and
5898 * repost them to the port by using SGL block post. This is needed after a
5899 * pci_function_reset/warm_start or start. It attempts to construct blocks
5900 * of els buffer sgls which contains contiguous xris and uses the non-embedded
5901 * SGL block post mailbox commands to post them to the port. For single els
5902 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
5903 * mailbox command for posting.
5905 * Returns: 0 = success, non-zero failure.
5908 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
5910 struct lpfc_sglq
*sglq_entry
= NULL
;
5911 struct lpfc_sglq
*sglq_entry_next
= NULL
;
5912 struct lpfc_sglq
*sglq_entry_first
= NULL
;
5913 int status
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
5914 int last_xritag
= NO_XRI
;
5915 LIST_HEAD(prep_sgl_list
);
5916 LIST_HEAD(blck_sgl_list
);
5917 LIST_HEAD(allc_sgl_list
);
5918 LIST_HEAD(post_sgl_list
);
5919 LIST_HEAD(free_sgl_list
);
5921 spin_lock(&phba
->hbalock
);
5922 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
5923 spin_unlock(&phba
->hbalock
);
5925 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
5926 &allc_sgl_list
, list
) {
5927 list_del_init(&sglq_entry
->list
);
5929 if ((last_xritag
!= NO_XRI
) &&
5930 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
5931 /* a hole in xri block, form a sgl posting block */
5932 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
5933 post_cnt
= block_cnt
- 1;
5934 /* prepare list for next posting block */
5935 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
5938 /* prepare list for next posting block */
5939 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
5940 /* enough sgls for non-embed sgl mbox command */
5941 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
5942 list_splice_init(&prep_sgl_list
,
5944 post_cnt
= block_cnt
;
5950 /* keep track of last sgl's xritag */
5951 last_xritag
= sglq_entry
->sli4_xritag
;
5953 /* end of repost sgl list condition for els buffers */
5954 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
5955 if (post_cnt
== 0) {
5956 list_splice_init(&prep_sgl_list
,
5958 post_cnt
= block_cnt
;
5959 } else if (block_cnt
== 1) {
5960 status
= lpfc_sli4_post_sgl(phba
,
5961 sglq_entry
->phys
, 0,
5962 sglq_entry
->sli4_xritag
);
5964 /* successful, put sgl to posted list */
5965 list_add_tail(&sglq_entry
->list
,
5968 /* Failure, put sgl to free list */
5969 lpfc_printf_log(phba
, KERN_WARNING
,
5971 "3159 Failed to post els "
5972 "sgl, xritag:x%x\n",
5973 sglq_entry
->sli4_xritag
);
5974 list_add_tail(&sglq_entry
->list
,
5976 spin_lock_irq(&phba
->hbalock
);
5977 phba
->sli4_hba
.els_xri_cnt
--;
5978 spin_unlock_irq(&phba
->hbalock
);
5983 /* continue until a nembed page worth of sgls */
5987 /* post the els buffer list sgls as a block */
5988 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
5992 /* success, put sgl list to posted sgl list */
5993 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
5995 /* Failure, put sgl list to free sgl list */
5996 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
5999 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6000 "3160 Failed to post els sgl-list, "
6002 sglq_entry_first
->sli4_xritag
,
6003 (sglq_entry_first
->sli4_xritag
+
6005 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6006 spin_lock_irq(&phba
->hbalock
);
6007 phba
->sli4_hba
.els_xri_cnt
-= post_cnt
;
6008 spin_unlock_irq(&phba
->hbalock
);
6011 /* don't reset xirtag due to hole in xri block */
6013 last_xritag
= NO_XRI
;
6015 /* reset els sgl post count for next round of posting */
6019 /* free the els sgls failed to post */
6020 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6022 /* push els sgls posted to the availble list */
6023 if (!list_empty(&post_sgl_list
)) {
6024 spin_lock(&phba
->hbalock
);
6025 list_splice_init(&post_sgl_list
,
6026 &phba
->sli4_hba
.lpfc_sgl_list
);
6027 spin_unlock(&phba
->hbalock
);
6029 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6030 "3161 Failure to post els sgl to port.\n");
6037 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6038 * @phba: Pointer to HBA context object.
6040 * This function is the main SLI4 device intialization PCI function. This
6041 * function is called by the HBA intialization code, HBA reset code and
6042 * HBA error attention handler code. Caller is not required to hold any
6046 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6049 LPFC_MBOXQ_t
*mboxq
;
6050 struct lpfc_mqe
*mqe
;
6053 uint32_t ftr_rsp
= 0;
6054 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6055 struct lpfc_vport
*vport
= phba
->pport
;
6056 struct lpfc_dmabuf
*mp
;
6058 /* Perform a PCI function reset to start from clean */
6059 rc
= lpfc_pci_function_reset(phba
);
6063 /* Check the HBA Host Status Register for readyness */
6064 rc
= lpfc_sli4_post_status_check(phba
);
6068 spin_lock_irq(&phba
->hbalock
);
6069 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6070 spin_unlock_irq(&phba
->hbalock
);
6074 * Allocate a single mailbox container for initializing the
6077 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6081 /* Issue READ_REV to collect vpd and FW information. */
6082 vpd_size
= SLI4_PAGE_SIZE
;
6083 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6089 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6094 mqe
= &mboxq
->u
.mqe
;
6095 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6096 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
6097 phba
->hba_flag
|= HBA_FCOE_MODE
;
6099 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6101 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6103 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6105 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6107 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6109 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6110 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6111 "0376 READ_REV Error. SLI Level %d "
6112 "FCoE enabled %d\n",
6113 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6120 * Continue initialization with default values even if driver failed
6121 * to read FCoE param config regions, only read parameters if the
6124 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6125 lpfc_sli4_read_fcoe_params(phba
))
6126 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6127 "2570 Failed to read FCoE parameters\n");
6130 * Retrieve sli4 device physical port name, failure of doing it
6131 * is considered as non-fatal.
6133 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6135 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6136 "3080 Successful retrieving SLI4 device "
6137 "physical port name: %s.\n", phba
->Port
);
6140 * Evaluate the read rev and vpd data. Populate the driver
6141 * state with the results. If this routine fails, the failure
6142 * is not fatal as the driver will use generic values.
6144 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6145 if (unlikely(!rc
)) {
6146 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6147 "0377 Error %d parsing vpd. "
6148 "Using defaults.\n", rc
);
6153 /* Save information as VPD data */
6154 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6155 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6156 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6157 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6159 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6161 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6163 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6165 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6166 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6167 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6168 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6169 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6170 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6171 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6172 "(%d):0380 READ_REV Status x%x "
6173 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6174 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6175 bf_get(lpfc_mqe_status
, mqe
),
6176 phba
->vpd
.rev
.opFwName
,
6177 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6178 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6181 * Discover the port's supported feature set and match it against the
6184 lpfc_request_features(phba
, mboxq
);
6185 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6192 * The port must support FCP initiator mode as this is the
6193 * only mode running in the host.
6195 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6196 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6197 "0378 No support for fcpi mode.\n");
6200 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6201 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6203 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6205 * If the port cannot support the host's requested features
6206 * then turn off the global config parameters to disable the
6207 * feature in the driver. This is not a fatal error.
6209 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6210 if (phba
->cfg_enable_bg
) {
6211 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6212 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6217 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6218 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6222 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6223 "0379 Feature Mismatch Data: x%08x %08x "
6224 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6225 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6226 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6227 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6228 phba
->cfg_enable_bg
= 0;
6229 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6230 phba
->cfg_enable_npiv
= 0;
6233 /* These SLI3 features are assumed in SLI4 */
6234 spin_lock_irq(&phba
->hbalock
);
6235 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6236 spin_unlock_irq(&phba
->hbalock
);
6239 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6240 * calls depends on these resources to complete port setup.
6242 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6244 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6245 "2920 Failed to alloc Resource IDs "
6250 /* Read the port's service parameters. */
6251 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6253 phba
->link_state
= LPFC_HBA_ERROR
;
6258 mboxq
->vport
= vport
;
6259 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6260 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6261 if (rc
== MBX_SUCCESS
) {
6262 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6267 * This memory was allocated by the lpfc_read_sparam routine. Release
6268 * it to the mbuf pool.
6270 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6272 mboxq
->context1
= NULL
;
6274 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6275 "0382 READ_SPARAM command failed "
6276 "status %d, mbxStatus x%x\n",
6277 rc
, bf_get(lpfc_mqe_status
, mqe
));
6278 phba
->link_state
= LPFC_HBA_ERROR
;
6283 lpfc_update_vport_wwn(vport
);
6285 /* Update the fc_host data structures with new wwn. */
6286 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6287 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6289 /* update host els and scsi xri-sgl sizes and mappings */
6290 rc
= lpfc_sli4_xri_sgl_update(phba
);
6292 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6293 "1400 Failed to update xri-sgl size and "
6294 "mapping: %d\n", rc
);
6298 /* register the els sgl pool to the port */
6299 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6301 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6302 "0582 Error %d during els sgl post "
6308 /* register the allocated scsi sgl pool to the port */
6309 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6311 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6312 "0383 Error %d during scsi sgl post "
6314 /* Some Scsi buffers were moved to the abort scsi list */
6315 /* A pci function reset will repost them */
6320 /* Post the rpi header region to the device. */
6321 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6323 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6324 "0393 Error %d during rpi post operation\n",
6329 lpfc_sli4_node_prep(phba
);
6331 /* Create all the SLI4 queues */
6332 rc
= lpfc_sli4_queue_create(phba
);
6334 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6335 "3089 Failed to allocate queues\n");
6337 goto out_stop_timers
;
6339 /* Set up all the queues to the device */
6340 rc
= lpfc_sli4_queue_setup(phba
);
6342 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6343 "0381 Error %d during queue setup.\n ", rc
);
6344 goto out_destroy_queue
;
6347 /* Arm the CQs and then EQs on device */
6348 lpfc_sli4_arm_cqeq_intr(phba
);
6350 /* Indicate device interrupt mode */
6351 phba
->sli4_hba
.intr_enable
= 1;
6353 /* Allow asynchronous mailbox command to go through */
6354 spin_lock_irq(&phba
->hbalock
);
6355 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6356 spin_unlock_irq(&phba
->hbalock
);
6358 /* Post receive buffers to the device */
6359 lpfc_sli4_rb_setup(phba
);
6361 /* Reset HBA FCF states after HBA reset */
6362 phba
->fcf
.fcf_flag
= 0;
6363 phba
->fcf
.current_rec
.flag
= 0;
6365 /* Start the ELS watchdog timer */
6366 mod_timer(&vport
->els_tmofunc
,
6367 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
6369 /* Start heart beat timer */
6370 mod_timer(&phba
->hb_tmofunc
,
6371 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
6372 phba
->hb_outstanding
= 0;
6373 phba
->last_completion_time
= jiffies
;
6375 /* Start error attention (ERATT) polling timer */
6376 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
6378 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6379 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6380 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6382 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6383 "2829 This device supports "
6384 "Advanced Error Reporting (AER)\n");
6385 spin_lock_irq(&phba
->hbalock
);
6386 phba
->hba_flag
|= HBA_AER_ENABLED
;
6387 spin_unlock_irq(&phba
->hbalock
);
6389 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6390 "2830 This device does not support "
6391 "Advanced Error Reporting (AER)\n");
6392 phba
->cfg_aer_support
= 0;
6397 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6399 * The FC Port needs to register FCFI (index 0)
6401 lpfc_reg_fcfi(phba
, mboxq
);
6402 mboxq
->vport
= phba
->pport
;
6403 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6404 if (rc
!= MBX_SUCCESS
)
6405 goto out_unset_queue
;
6407 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6408 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6410 /* Check if the port is configured to be disabled */
6411 lpfc_sli_read_link_ste(phba
);
6415 * The port is ready, set the host's link state to LINK_DOWN
6416 * in preparation for link interrupts.
6418 spin_lock_irq(&phba
->hbalock
);
6419 phba
->link_state
= LPFC_LINK_DOWN
;
6420 spin_unlock_irq(&phba
->hbalock
);
6421 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6422 (phba
->hba_flag
& LINK_DISABLED
)) {
6423 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6424 "3103 Adapter Link is disabled.\n");
6425 lpfc_down_link(phba
, mboxq
);
6426 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6427 if (rc
!= MBX_SUCCESS
) {
6428 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6429 "3104 Adapter failed to issue "
6430 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6431 goto out_unset_queue
;
6433 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6434 /* don't perform init_link on SLI4 FC port loopback test */
6435 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6436 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6438 goto out_unset_queue
;
6441 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6444 /* Unset all the queues set up in this routine when error out */
6445 lpfc_sli4_queue_unset(phba
);
6447 lpfc_sli4_queue_destroy(phba
);
6449 lpfc_stop_hba_timers(phba
);
6451 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6456 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6457 * @ptr: context object - pointer to hba structure.
6459 * This is the callback function for mailbox timer. The mailbox
6460 * timer is armed when a new mailbox command is issued and the timer
6461 * is deleted when the mailbox complete. The function is called by
6462 * the kernel timer code when a mailbox does not complete within
6463 * expected time. This function wakes up the worker thread to
6464 * process the mailbox timeout and returns. All the processing is
6465 * done by the worker thread function lpfc_mbox_timeout_handler.
6468 lpfc_mbox_timeout(unsigned long ptr
)
6470 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6471 unsigned long iflag
;
6472 uint32_t tmo_posted
;
6474 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6475 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6477 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6478 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6481 lpfc_worker_wake_up(phba
);
6487 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6488 * @phba: Pointer to HBA context object.
6490 * This function is called from worker thread when a mailbox command times out.
6491 * The caller is not required to hold any locks. This function will reset the
6492 * HBA and recover all the pending commands.
6495 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6497 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6498 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6499 struct lpfc_sli
*psli
= &phba
->sli
;
6500 struct lpfc_sli_ring
*pring
;
6502 /* Check the pmbox pointer first. There is a race condition
6503 * between the mbox timeout handler getting executed in the
6504 * worklist and the mailbox actually completing. When this
6505 * race condition occurs, the mbox_active will be NULL.
6507 spin_lock_irq(&phba
->hbalock
);
6508 if (pmbox
== NULL
) {
6509 lpfc_printf_log(phba
, KERN_WARNING
,
6511 "0353 Active Mailbox cleared - mailbox timeout "
6513 spin_unlock_irq(&phba
->hbalock
);
6517 /* Mbox cmd <mbxCommand> timeout */
6518 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6519 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6521 phba
->pport
->port_state
,
6523 phba
->sli
.mbox_active
);
6524 spin_unlock_irq(&phba
->hbalock
);
6526 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6527 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6528 * it to fail all outstanding SCSI IO.
6530 spin_lock_irq(&phba
->pport
->work_port_lock
);
6531 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6532 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6533 spin_lock_irq(&phba
->hbalock
);
6534 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6535 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6536 spin_unlock_irq(&phba
->hbalock
);
6538 pring
= &psli
->ring
[psli
->fcp_ring
];
6539 lpfc_sli_abort_iocb_ring(phba
, pring
);
6541 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6542 "0345 Resetting board due to mailbox timeout\n");
6544 /* Reset the HBA device */
6545 lpfc_reset_hba(phba
);
6549 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6550 * @phba: Pointer to HBA context object.
6551 * @pmbox: Pointer to mailbox object.
6552 * @flag: Flag indicating how the mailbox need to be processed.
6554 * This function is called by discovery code and HBA management code
6555 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6556 * function gets the hbalock to protect the data structures.
6557 * The mailbox command can be submitted in polling mode, in which case
6558 * this function will wait in a polling loop for the completion of the
6560 * If the mailbox is submitted in no_wait mode (not polling) the
6561 * function will submit the command and returns immediately without waiting
6562 * for the mailbox completion. The no_wait is supported only when HBA
6563 * is in SLI2/SLI3 mode - interrupts are enabled.
6564 * The SLI interface allows only one mailbox pending at a time. If the
6565 * mailbox is issued in polling mode and there is already a mailbox
6566 * pending, then the function will return an error. If the mailbox is issued
6567 * in NO_WAIT mode and there is a mailbox pending already, the function
6568 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6569 * The sli layer owns the mailbox object until the completion of mailbox
6570 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6571 * return codes the caller owns the mailbox command after the return of
6575 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6579 struct lpfc_sli
*psli
= &phba
->sli
;
6580 uint32_t status
, evtctr
;
6581 uint32_t ha_copy
, hc_copy
;
6583 unsigned long timeout
;
6584 unsigned long drvr_flag
= 0;
6585 uint32_t word0
, ldata
;
6586 void __iomem
*to_slim
;
6587 int processing_queue
= 0;
6589 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6591 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6592 /* processing mbox queue from intr_handler */
6593 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6594 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6597 processing_queue
= 1;
6598 pmbox
= lpfc_mbox_get(phba
);
6600 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6605 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6606 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6608 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6609 lpfc_printf_log(phba
, KERN_ERR
,
6610 LOG_MBOX
| LOG_VPORT
,
6611 "1806 Mbox x%x failed. No vport\n",
6612 pmbox
->u
.mb
.mbxCommand
);
6614 goto out_not_finished
;
6618 /* If the PCI channel is in offline state, do not post mbox. */
6619 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6620 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6621 goto out_not_finished
;
6624 /* If HBA has a deferred error attention, fail the iocb. */
6625 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6626 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6627 goto out_not_finished
;
6633 status
= MBX_SUCCESS
;
6635 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6636 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6638 /* Mbox command <mbxCommand> cannot issue */
6639 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6640 "(%d):0311 Mailbox command x%x cannot "
6641 "issue Data: x%x x%x\n",
6642 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6643 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6644 goto out_not_finished
;
6647 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6648 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6649 !(hc_copy
& HC_MBINT_ENA
)) {
6650 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6651 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6652 "(%d):2528 Mailbox command x%x cannot "
6653 "issue Data: x%x x%x\n",
6654 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6655 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6656 goto out_not_finished
;
6660 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6661 /* Polling for a mbox command when another one is already active
6662 * is not allowed in SLI. Also, the driver must have established
6663 * SLI2 mode to queue and process multiple mbox commands.
6666 if (flag
& MBX_POLL
) {
6667 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6669 /* Mbox command <mbxCommand> cannot issue */
6670 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6671 "(%d):2529 Mailbox command x%x "
6672 "cannot issue Data: x%x x%x\n",
6673 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6674 pmbox
->u
.mb
.mbxCommand
,
6675 psli
->sli_flag
, flag
);
6676 goto out_not_finished
;
6679 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6680 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6681 /* Mbox command <mbxCommand> cannot issue */
6682 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6683 "(%d):2530 Mailbox command x%x "
6684 "cannot issue Data: x%x x%x\n",
6685 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6686 pmbox
->u
.mb
.mbxCommand
,
6687 psli
->sli_flag
, flag
);
6688 goto out_not_finished
;
6691 /* Another mailbox command is still being processed, queue this
6692 * command to be processed later.
6694 lpfc_mbox_put(phba
, pmbox
);
6696 /* Mbox cmd issue - BUSY */
6697 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6698 "(%d):0308 Mbox cmd issue - BUSY Data: "
6699 "x%x x%x x%x x%x\n",
6700 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6701 mb
->mbxCommand
, phba
->pport
->port_state
,
6702 psli
->sli_flag
, flag
);
6704 psli
->slistat
.mbox_busy
++;
6705 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6708 lpfc_debugfs_disc_trc(pmbox
->vport
,
6709 LPFC_DISC_TRC_MBOX_VPORT
,
6710 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6711 (uint32_t)mb
->mbxCommand
,
6712 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6715 lpfc_debugfs_disc_trc(phba
->pport
,
6717 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6718 (uint32_t)mb
->mbxCommand
,
6719 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6725 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6727 /* If we are not polling, we MUST be in SLI2 mode */
6728 if (flag
!= MBX_POLL
) {
6729 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6730 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
6731 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6732 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6733 /* Mbox command <mbxCommand> cannot issue */
6734 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6735 "(%d):2531 Mailbox command x%x "
6736 "cannot issue Data: x%x x%x\n",
6737 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6738 pmbox
->u
.mb
.mbxCommand
,
6739 psli
->sli_flag
, flag
);
6740 goto out_not_finished
;
6742 /* timeout active mbox command */
6743 mod_timer(&psli
->mbox_tmo
, (jiffies
+
6744 (HZ
* lpfc_mbox_tmo_val(phba
, pmbox
))));
6747 /* Mailbox cmd <cmd> issue */
6748 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6749 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6751 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6752 mb
->mbxCommand
, phba
->pport
->port_state
,
6753 psli
->sli_flag
, flag
);
6755 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
6757 lpfc_debugfs_disc_trc(pmbox
->vport
,
6758 LPFC_DISC_TRC_MBOX_VPORT
,
6759 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6760 (uint32_t)mb
->mbxCommand
,
6761 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6764 lpfc_debugfs_disc_trc(phba
->pport
,
6766 "MBOX Send: cmd:x%x mb:x%x x%x",
6767 (uint32_t)mb
->mbxCommand
,
6768 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6772 psli
->slistat
.mbox_cmd
++;
6773 evtctr
= psli
->slistat
.mbox_event
;
6775 /* next set own bit for the adapter and copy over command word */
6776 mb
->mbxOwner
= OWN_CHIP
;
6778 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6779 /* Populate mbox extension offset word. */
6780 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6781 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6782 = (uint8_t *)phba
->mbox_ext
6783 - (uint8_t *)phba
->mbox
;
6786 /* Copy the mailbox extension data */
6787 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6788 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6789 (uint8_t *)phba
->mbox_ext
,
6790 pmbox
->in_ext_byte_len
);
6792 /* Copy command data to host SLIM area */
6793 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6795 /* Populate mbox extension offset word. */
6796 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6797 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6798 = MAILBOX_HBA_EXT_OFFSET
;
6800 /* Copy the mailbox extension data */
6801 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6802 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
6803 MAILBOX_HBA_EXT_OFFSET
,
6804 pmbox
->context2
, pmbox
->in_ext_byte_len
);
6807 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6808 /* copy command data into host mbox for cmpl */
6809 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6812 /* First copy mbox command data to HBA SLIM, skip past first
6814 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
6815 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
6816 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
6818 /* Next copy over first word, with mbxOwner set */
6819 ldata
= *((uint32_t *)mb
);
6820 to_slim
= phba
->MBslimaddr
;
6821 writel(ldata
, to_slim
);
6822 readl(to_slim
); /* flush */
6824 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6825 /* switch over to host mailbox */
6826 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
6834 /* Set up reference to mailbox command */
6835 psli
->mbox_active
= pmbox
;
6836 /* Interrupt board to do it */
6837 writel(CA_MBATT
, phba
->CAregaddr
);
6838 readl(phba
->CAregaddr
); /* flush */
6839 /* Don't wait for it to finish, just return */
6843 /* Set up null reference to mailbox command */
6844 psli
->mbox_active
= NULL
;
6845 /* Interrupt board to do it */
6846 writel(CA_MBATT
, phba
->CAregaddr
);
6847 readl(phba
->CAregaddr
); /* flush */
6849 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6850 /* First read mbox status word */
6851 word0
= *((uint32_t *)phba
->mbox
);
6852 word0
= le32_to_cpu(word0
);
6854 /* First read mbox status word */
6855 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
6856 spin_unlock_irqrestore(&phba
->hbalock
,
6858 goto out_not_finished
;
6862 /* Read the HBA Host Attention Register */
6863 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6864 spin_unlock_irqrestore(&phba
->hbalock
,
6866 goto out_not_finished
;
6868 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6871 /* Wait for command to complete */
6872 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
6873 (!(ha_copy
& HA_MBATT
) &&
6874 (phba
->link_state
> LPFC_WARM_START
))) {
6875 if (time_after(jiffies
, timeout
)) {
6876 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6877 spin_unlock_irqrestore(&phba
->hbalock
,
6879 goto out_not_finished
;
6882 /* Check if we took a mbox interrupt while we were
6884 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
6885 && (evtctr
!= psli
->slistat
.mbox_event
))
6889 spin_unlock_irqrestore(&phba
->hbalock
,
6892 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6895 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6896 /* First copy command data */
6897 word0
= *((uint32_t *)phba
->mbox
);
6898 word0
= le32_to_cpu(word0
);
6899 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6902 /* Check real SLIM for any errors */
6903 slimword0
= readl(phba
->MBslimaddr
);
6904 slimmb
= (MAILBOX_t
*) & slimword0
;
6905 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
6906 && slimmb
->mbxStatus
) {
6913 /* First copy command data */
6914 word0
= readl(phba
->MBslimaddr
);
6916 /* Read the HBA Host Attention Register */
6917 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6918 spin_unlock_irqrestore(&phba
->hbalock
,
6920 goto out_not_finished
;
6924 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6925 /* copy results back to user */
6926 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
6927 /* Copy the mailbox extension data */
6928 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6929 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
6931 pmbox
->out_ext_byte_len
);
6934 /* First copy command data */
6935 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
6937 /* Copy the mailbox extension data */
6938 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6939 lpfc_memcpy_from_slim(pmbox
->context2
,
6941 MAILBOX_HBA_EXT_OFFSET
,
6942 pmbox
->out_ext_byte_len
);
6946 writel(HA_MBATT
, phba
->HAregaddr
);
6947 readl(phba
->HAregaddr
); /* flush */
6949 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6950 status
= mb
->mbxStatus
;
6953 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6957 if (processing_queue
) {
6958 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6959 lpfc_mbox_cmpl_put(phba
, pmbox
);
6961 return MBX_NOT_FINISHED
;
6965 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6966 * @phba: Pointer to HBA context object.
6968 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6969 * the driver internal pending mailbox queue. It will then try to wait out the
6970 * possible outstanding mailbox command before return.
6973 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6974 * the outstanding mailbox command timed out.
6977 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
6979 struct lpfc_sli
*psli
= &phba
->sli
;
6981 unsigned long timeout
= 0;
6983 /* Mark the asynchronous mailbox command posting as blocked */
6984 spin_lock_irq(&phba
->hbalock
);
6985 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
6986 /* Determine how long we might wait for the active mailbox
6987 * command to be gracefully completed by firmware.
6989 if (phba
->sli
.mbox_active
)
6990 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
6991 phba
->sli
.mbox_active
) *
6993 spin_unlock_irq(&phba
->hbalock
);
6995 /* Wait for the outstnading mailbox command to complete */
6996 while (phba
->sli
.mbox_active
) {
6997 /* Check active mailbox complete status every 2ms */
6999 if (time_after(jiffies
, timeout
)) {
7000 /* Timeout, marked the outstanding cmd not complete */
7006 /* Can not cleanly block async mailbox command, fails it */
7008 spin_lock_irq(&phba
->hbalock
);
7009 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7010 spin_unlock_irq(&phba
->hbalock
);
7016 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7017 * @phba: Pointer to HBA context object.
7019 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7020 * commands from the driver internal pending mailbox queue. It makes sure
7021 * that there is no outstanding mailbox command before resuming posting
7022 * asynchronous mailbox commands. If, for any reason, there is outstanding
7023 * mailbox command, it will try to wait it out before resuming asynchronous
7024 * mailbox command posting.
7027 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7029 struct lpfc_sli
*psli
= &phba
->sli
;
7031 spin_lock_irq(&phba
->hbalock
);
7032 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7033 /* Asynchronous mailbox posting is not blocked, do nothing */
7034 spin_unlock_irq(&phba
->hbalock
);
7038 /* Outstanding synchronous mailbox command is guaranteed to be done,
7039 * successful or timeout, after timing-out the outstanding mailbox
7040 * command shall always be removed, so just unblock posting async
7041 * mailbox command and resume
7043 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7044 spin_unlock_irq(&phba
->hbalock
);
7046 /* wake up worker thread to post asynchronlous mailbox command */
7047 lpfc_worker_wake_up(phba
);
7051 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7052 * @phba: Pointer to HBA context object.
7053 * @mboxq: Pointer to mailbox object.
7055 * The function posts a mailbox to the port. The mailbox is expected
7056 * to be comletely filled in and ready for the port to operate on it.
7057 * This routine executes a synchronous completion operation on the
7058 * mailbox by polling for its completion.
7060 * The caller must not be holding any locks when calling this routine.
7063 * MBX_SUCCESS - mailbox posted successfully
7064 * Any of the MBX error values.
7067 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7069 int rc
= MBX_SUCCESS
;
7070 unsigned long iflag
;
7072 uint32_t mcqe_status
;
7074 unsigned long timeout
;
7075 struct lpfc_sli
*psli
= &phba
->sli
;
7076 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7077 struct lpfc_bmbx_create
*mbox_rgn
;
7078 struct dma_address
*dma_address
;
7079 struct lpfc_register bmbx_reg
;
7082 * Only one mailbox can be active to the bootstrap mailbox region
7083 * at a time and there is no queueing provided.
7085 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7086 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7087 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7088 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7089 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7090 "cannot issue Data: x%x x%x\n",
7091 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7092 mboxq
->u
.mb
.mbxCommand
,
7093 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7094 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7095 psli
->sli_flag
, MBX_POLL
);
7096 return MBXERR_ERROR
;
7098 /* The server grabs the token and owns it until release */
7099 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7100 phba
->sli
.mbox_active
= mboxq
;
7101 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7104 * Initialize the bootstrap memory region to avoid stale data areas
7105 * in the mailbox post. Then copy the caller's mailbox contents to
7106 * the bmbx mailbox region.
7108 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7109 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7110 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7111 sizeof(struct lpfc_mqe
));
7113 /* Post the high mailbox dma address to the port and wait for ready. */
7114 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7115 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7117 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7120 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7121 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7125 if (time_after(jiffies
, timeout
)) {
7129 } while (!db_ready
);
7131 /* Post the low mailbox dma address to the port. */
7132 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7133 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7136 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7137 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7141 if (time_after(jiffies
, timeout
)) {
7145 } while (!db_ready
);
7148 * Read the CQ to ensure the mailbox has completed.
7149 * If so, update the mailbox status so that the upper layers
7150 * can complete the request normally.
7152 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7153 sizeof(struct lpfc_mqe
));
7154 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7155 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7156 sizeof(struct lpfc_mcqe
));
7157 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7159 * When the CQE status indicates a failure and the mailbox status
7160 * indicates success then copy the CQE status into the mailbox status
7161 * (and prefix it with x4000).
7163 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7164 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7165 bf_set(lpfc_mqe_status
, mb
,
7166 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7169 lpfc_sli4_swap_str(phba
, mboxq
);
7171 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7172 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7173 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7174 " x%x x%x CQ: x%x x%x x%x x%x\n",
7175 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7176 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7177 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7178 bf_get(lpfc_mqe_status
, mb
),
7179 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7180 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7181 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7182 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7183 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7184 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7185 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7186 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7187 mboxq
->mcqe
.trailer
);
7189 /* We are holding the token, no needed for lock when release */
7190 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7191 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7192 phba
->sli
.mbox_active
= NULL
;
7193 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7198 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7199 * @phba: Pointer to HBA context object.
7200 * @pmbox: Pointer to mailbox object.
7201 * @flag: Flag indicating how the mailbox need to be processed.
7203 * This function is called by discovery code and HBA management code to submit
7204 * a mailbox command to firmware with SLI-4 interface spec.
7206 * Return codes the caller owns the mailbox command after the return of the
7210 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7213 struct lpfc_sli
*psli
= &phba
->sli
;
7214 unsigned long iflags
;
7217 /* dump from issue mailbox command if setup */
7218 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7220 rc
= lpfc_mbox_dev_check(phba
);
7222 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7223 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7224 "cannot issue Data: x%x x%x\n",
7225 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7226 mboxq
->u
.mb
.mbxCommand
,
7227 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7228 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7229 psli
->sli_flag
, flag
);
7230 goto out_not_finished
;
7233 /* Detect polling mode and jump to a handler */
7234 if (!phba
->sli4_hba
.intr_enable
) {
7235 if (flag
== MBX_POLL
)
7236 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7239 if (rc
!= MBX_SUCCESS
)
7240 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7241 "(%d):2541 Mailbox command x%x "
7242 "(x%x/x%x) failure: "
7243 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7245 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7246 mboxq
->u
.mb
.mbxCommand
,
7247 lpfc_sli_config_mbox_subsys_get(phba
,
7249 lpfc_sli_config_mbox_opcode_get(phba
,
7251 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7252 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7253 bf_get(lpfc_mcqe_ext_status
,
7255 psli
->sli_flag
, flag
);
7257 } else if (flag
== MBX_POLL
) {
7258 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7259 "(%d):2542 Try to issue mailbox command "
7260 "x%x (x%x/x%x) synchronously ahead of async"
7261 "mailbox command queue: x%x x%x\n",
7262 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7263 mboxq
->u
.mb
.mbxCommand
,
7264 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7265 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7266 psli
->sli_flag
, flag
);
7267 /* Try to block the asynchronous mailbox posting */
7268 rc
= lpfc_sli4_async_mbox_block(phba
);
7270 /* Successfully blocked, now issue sync mbox cmd */
7271 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7272 if (rc
!= MBX_SUCCESS
)
7273 lpfc_printf_log(phba
, KERN_WARNING
,
7275 "(%d):2597 Sync Mailbox command "
7276 "x%x (x%x/x%x) failure: "
7277 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7279 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7280 mboxq
->u
.mb
.mbxCommand
,
7281 lpfc_sli_config_mbox_subsys_get(phba
,
7283 lpfc_sli_config_mbox_opcode_get(phba
,
7285 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7286 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7287 bf_get(lpfc_mcqe_ext_status
,
7289 psli
->sli_flag
, flag
);
7290 /* Unblock the async mailbox posting afterward */
7291 lpfc_sli4_async_mbox_unblock(phba
);
7296 /* Now, interrupt mode asynchrous mailbox command */
7297 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7299 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7300 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7301 "cannot issue Data: x%x x%x\n",
7302 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7303 mboxq
->u
.mb
.mbxCommand
,
7304 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7305 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7306 psli
->sli_flag
, flag
);
7307 goto out_not_finished
;
7310 /* Put the mailbox command to the driver internal FIFO */
7311 psli
->slistat
.mbox_busy
++;
7312 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7313 lpfc_mbox_put(phba
, mboxq
);
7314 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7315 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7316 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7317 "x%x (x%x/x%x) x%x x%x x%x\n",
7318 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7319 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7320 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7321 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7322 phba
->pport
->port_state
,
7323 psli
->sli_flag
, MBX_NOWAIT
);
7324 /* Wake up worker thread to transport mailbox command from head */
7325 lpfc_worker_wake_up(phba
);
7330 return MBX_NOT_FINISHED
;
7334 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7335 * @phba: Pointer to HBA context object.
7337 * This function is called by worker thread to send a mailbox command to
7338 * SLI4 HBA firmware.
7342 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7344 struct lpfc_sli
*psli
= &phba
->sli
;
7345 LPFC_MBOXQ_t
*mboxq
;
7346 int rc
= MBX_SUCCESS
;
7347 unsigned long iflags
;
7348 struct lpfc_mqe
*mqe
;
7351 /* Check interrupt mode before post async mailbox command */
7352 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7353 return MBX_NOT_FINISHED
;
7355 /* Check for mailbox command service token */
7356 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7357 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7358 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7359 return MBX_NOT_FINISHED
;
7361 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7362 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7363 return MBX_NOT_FINISHED
;
7365 if (unlikely(phba
->sli
.mbox_active
)) {
7366 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7367 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7368 "0384 There is pending active mailbox cmd\n");
7369 return MBX_NOT_FINISHED
;
7371 /* Take the mailbox command service token */
7372 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7374 /* Get the next mailbox command from head of queue */
7375 mboxq
= lpfc_mbox_get(phba
);
7377 /* If no more mailbox command waiting for post, we're done */
7379 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7380 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7383 phba
->sli
.mbox_active
= mboxq
;
7384 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7386 /* Check device readiness for posting mailbox command */
7387 rc
= lpfc_mbox_dev_check(phba
);
7389 /* Driver clean routine will clean up pending mailbox */
7390 goto out_not_finished
;
7392 /* Prepare the mbox command to be posted */
7393 mqe
= &mboxq
->u
.mqe
;
7394 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7396 /* Start timer for the mbox_tmo and log some mailbox post messages */
7397 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7398 (HZ
* lpfc_mbox_tmo_val(phba
, mboxq
))));
7400 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7401 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7403 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7404 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7405 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7406 phba
->pport
->port_state
, psli
->sli_flag
);
7408 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7410 lpfc_debugfs_disc_trc(mboxq
->vport
,
7411 LPFC_DISC_TRC_MBOX_VPORT
,
7412 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7413 mbx_cmnd
, mqe
->un
.mb_words
[0],
7414 mqe
->un
.mb_words
[1]);
7416 lpfc_debugfs_disc_trc(phba
->pport
,
7418 "MBOX Send: cmd:x%x mb:x%x x%x",
7419 mbx_cmnd
, mqe
->un
.mb_words
[0],
7420 mqe
->un
.mb_words
[1]);
7423 psli
->slistat
.mbox_cmd
++;
7425 /* Post the mailbox command to the port */
7426 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7427 if (rc
!= MBX_SUCCESS
) {
7428 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7429 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7430 "cannot issue Data: x%x x%x\n",
7431 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7432 mboxq
->u
.mb
.mbxCommand
,
7433 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7434 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7435 psli
->sli_flag
, MBX_NOWAIT
);
7436 goto out_not_finished
;
7442 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7443 if (phba
->sli
.mbox_active
) {
7444 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7445 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7446 /* Release the token */
7447 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7448 phba
->sli
.mbox_active
= NULL
;
7450 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7452 return MBX_NOT_FINISHED
;
7456 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7457 * @phba: Pointer to HBA context object.
7458 * @pmbox: Pointer to mailbox object.
7459 * @flag: Flag indicating how the mailbox need to be processed.
7461 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7462 * the API jump table function pointer from the lpfc_hba struct.
7464 * Return codes the caller owns the mailbox command after the return of the
7468 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7470 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7474 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7475 * @phba: The hba struct for which this call is being executed.
7476 * @dev_grp: The HBA PCI-Device group number.
7478 * This routine sets up the mbox interface API function jump table in @phba
7480 * Returns: 0 - success, -ENODEV - failure.
7483 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7487 case LPFC_PCI_DEV_LP
:
7488 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7489 phba
->lpfc_sli_handle_slow_ring_event
=
7490 lpfc_sli_handle_slow_ring_event_s3
;
7491 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7492 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7493 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7495 case LPFC_PCI_DEV_OC
:
7496 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7497 phba
->lpfc_sli_handle_slow_ring_event
=
7498 lpfc_sli_handle_slow_ring_event_s4
;
7499 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7500 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7501 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7504 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7505 "1420 Invalid HBA PCI-device group: 0x%x\n",
7514 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7515 * @phba: Pointer to HBA context object.
7516 * @pring: Pointer to driver SLI ring object.
7517 * @piocb: Pointer to address of newly added command iocb.
7519 * This function is called with hbalock held to add a command
7520 * iocb to the txq when SLI layer cannot submit the command iocb
7524 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7525 struct lpfc_iocbq
*piocb
)
7527 /* Insert the caller's iocb in the txq tail for later processing. */
7528 list_add_tail(&piocb
->list
, &pring
->txq
);
7533 * lpfc_sli_next_iocb - Get the next iocb in the txq
7534 * @phba: Pointer to HBA context object.
7535 * @pring: Pointer to driver SLI ring object.
7536 * @piocb: Pointer to address of newly added command iocb.
7538 * This function is called with hbalock held before a new
7539 * iocb is submitted to the firmware. This function checks
7540 * txq to flush the iocbs in txq to Firmware before
7541 * submitting new iocbs to the Firmware.
7542 * If there are iocbs in the txq which need to be submitted
7543 * to firmware, lpfc_sli_next_iocb returns the first element
7544 * of the txq after dequeuing it from txq.
7545 * If there is no iocb in the txq then the function will return
7546 * *piocb and *piocb is set to NULL. Caller needs to check
7547 * *piocb to find if there are more commands in the txq.
7549 static struct lpfc_iocbq
*
7550 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7551 struct lpfc_iocbq
**piocb
)
7553 struct lpfc_iocbq
* nextiocb
;
7555 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7565 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7566 * @phba: Pointer to HBA context object.
7567 * @ring_number: SLI ring number to issue iocb on.
7568 * @piocb: Pointer to command iocb.
7569 * @flag: Flag indicating if this command can be put into txq.
7571 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7572 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7573 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7574 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7575 * this function allows only iocbs for posting buffers. This function finds
7576 * next available slot in the command ring and posts the command to the
7577 * available slot and writes the port attention register to request HBA start
7578 * processing new iocb. If there is no slot available in the ring and
7579 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7580 * the function returns IOCB_BUSY.
7582 * This function is called with hbalock held. The function will return success
7583 * after it successfully submit the iocb to firmware or after adding to the
7587 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7588 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7590 struct lpfc_iocbq
*nextiocb
;
7592 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7594 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7595 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7596 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7597 lpfc_printf_log(phba
, KERN_ERR
,
7598 LOG_SLI
| LOG_VPORT
,
7599 "1807 IOCB x%x failed. No vport\n",
7600 piocb
->iocb
.ulpCommand
);
7606 /* If the PCI channel is in offline state, do not post iocbs. */
7607 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7610 /* If HBA has a deferred error attention, fail the iocb. */
7611 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7615 * We should never get an IOCB if we are in a < LINK_DOWN state
7617 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7621 * Check to see if we are blocking IOCB processing because of a
7622 * outstanding event.
7624 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7627 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7629 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7630 * can be issued if the link is not up.
7632 switch (piocb
->iocb
.ulpCommand
) {
7633 case CMD_GEN_REQUEST64_CR
:
7634 case CMD_GEN_REQUEST64_CX
:
7635 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7636 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7637 FC_RCTL_DD_UNSOL_CMD
) ||
7638 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7639 MENLO_TRANSPORT_TYPE
))
7643 case CMD_QUE_RING_BUF_CN
:
7644 case CMD_QUE_RING_BUF64_CN
:
7646 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7647 * completion, iocb_cmpl MUST be 0.
7649 if (piocb
->iocb_cmpl
)
7650 piocb
->iocb_cmpl
= NULL
;
7652 case CMD_CREATE_XRI_CR
:
7653 case CMD_CLOSE_XRI_CN
:
7654 case CMD_CLOSE_XRI_CX
:
7661 * For FCP commands, we must be in a state where we can process link
7664 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7665 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7669 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7670 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7671 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7674 lpfc_sli_update_ring(phba
, pring
);
7676 lpfc_sli_update_full_ring(phba
, pring
);
7679 return IOCB_SUCCESS
;
7684 pring
->stats
.iocb_cmd_delay
++;
7688 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7689 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7690 return IOCB_SUCCESS
;
7697 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7698 * @phba: Pointer to HBA context object.
7699 * @piocb: Pointer to command iocb.
7700 * @sglq: Pointer to the scatter gather queue object.
7702 * This routine converts the bpl or bde that is in the IOCB
7703 * to a sgl list for the sli4 hardware. The physical address
7704 * of the bpl/bde is converted back to a virtual address.
7705 * If the IOCB contains a BPL then the list of BDE's is
7706 * converted to sli4_sge's. If the IOCB contains a single
7707 * BDE then it is converted to a single sli_sge.
7708 * The IOCB is still in cpu endianess so the contents of
7709 * the bpl can be used without byte swapping.
7711 * Returns valid XRI = Success, NO_XRI = Failure.
7714 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7715 struct lpfc_sglq
*sglq
)
7717 uint16_t xritag
= NO_XRI
;
7718 struct ulp_bde64
*bpl
= NULL
;
7719 struct ulp_bde64 bde
;
7720 struct sli4_sge
*sgl
= NULL
;
7721 struct lpfc_dmabuf
*dmabuf
;
7725 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7726 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7728 if (!piocbq
|| !sglq
)
7731 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7732 icmd
= &piocbq
->iocb
;
7733 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
7734 return sglq
->sli4_xritag
;
7735 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7736 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7737 sizeof(struct ulp_bde64
);
7738 /* The addrHigh and addrLow fields within the IOCB
7739 * have not been byteswapped yet so there is no
7740 * need to swap them back.
7742 if (piocbq
->context3
)
7743 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7747 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7751 for (i
= 0; i
< numBdes
; i
++) {
7752 /* Should already be byte swapped. */
7753 sgl
->addr_hi
= bpl
->addrHigh
;
7754 sgl
->addr_lo
= bpl
->addrLow
;
7756 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7757 if ((i
+1) == numBdes
)
7758 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7760 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7761 /* swap the size field back to the cpu so we
7762 * can assign it to the sgl.
7764 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7765 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7766 /* The offsets in the sgl need to be accumulated
7767 * separately for the request and reply lists.
7768 * The request is always first, the reply follows.
7770 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7771 /* add up the reply sg entries */
7772 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7774 /* first inbound? reset the offset */
7777 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7778 bf_set(lpfc_sli4_sge_type
, sgl
,
7779 LPFC_SGE_TYPE_DATA
);
7780 offset
+= bde
.tus
.f
.bdeSize
;
7782 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7786 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
7787 /* The addrHigh and addrLow fields of the BDE have not
7788 * been byteswapped yet so they need to be swapped
7789 * before putting them in the sgl.
7792 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
7794 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
7795 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7796 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7797 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7799 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
7801 return sglq
->sli4_xritag
;
7805 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7806 * @phba: Pointer to HBA context object.
7808 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7809 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7812 * Return: index into SLI4 fast-path FCP queue index.
7814 static inline uint32_t
7815 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
7819 i
= atomic_add_return(1, &phba
->fcp_qidx
);
7820 i
= (i
% phba
->cfg_fcp_io_channel
);
7825 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7826 * @phba: Pointer to HBA context object.
7827 * @piocb: Pointer to command iocb.
7828 * @wqe: Pointer to the work queue entry.
7830 * This routine converts the iocb command to its Work Queue Entry
7831 * equivalent. The wqe pointer should not have any fields set when
7832 * this routine is called because it will memcpy over them.
7833 * This routine does not set the CQ_ID or the WQEC bits in the
7836 * Returns: 0 = Success, IOCB_ERROR = Failure.
7839 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
7840 union lpfc_wqe
*wqe
)
7842 uint32_t xmit_len
= 0, total_len
= 0;
7846 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
7849 uint16_t abrt_iotag
;
7850 struct lpfc_iocbq
*abrtiocbq
;
7851 struct ulp_bde64
*bpl
= NULL
;
7852 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
7854 struct ulp_bde64 bde
;
7855 struct lpfc_nodelist
*ndlp
;
7859 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
7860 /* The fcp commands will set command type */
7861 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7862 command_type
= FCP_COMMAND
;
7863 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
7864 command_type
= ELS_COMMAND_FIP
;
7866 command_type
= ELS_COMMAND_NON_FIP
;
7868 /* Some of the fields are in the right position already */
7869 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
7870 abort_tag
= (uint32_t) iocbq
->iotag
;
7871 xritag
= iocbq
->sli4_xritag
;
7872 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
7873 /* words0-2 bpl convert bde */
7874 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7875 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7876 sizeof(struct ulp_bde64
);
7877 bpl
= (struct ulp_bde64
*)
7878 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
7882 /* Should already be byte swapped. */
7883 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
7884 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
7885 /* swap the size field back to the cpu so we
7886 * can assign it to the sgl.
7888 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7889 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
7891 for (i
= 0; i
< numBdes
; i
++) {
7892 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7893 total_len
+= bde
.tus
.f
.bdeSize
;
7896 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
7898 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
7899 cmnd
= iocbq
->iocb
.ulpCommand
;
7901 switch (iocbq
->iocb
.ulpCommand
) {
7902 case CMD_ELS_REQUEST64_CR
:
7903 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
7904 ndlp
= iocbq
->context_un
.ndlp
;
7906 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7907 if (!iocbq
->iocb
.ulpLe
) {
7908 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7909 "2007 Only Limited Edition cmd Format"
7910 " supported 0x%x\n",
7911 iocbq
->iocb
.ulpCommand
);
7915 wqe
->els_req
.payload_len
= xmit_len
;
7916 /* Els_reguest64 has a TMO */
7917 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
7918 iocbq
->iocb
.ulpTimeout
);
7919 /* Need a VF for word 4 set the vf bit*/
7920 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
7921 /* And a VFID for word 12 */
7922 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
7923 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7924 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7925 iocbq
->iocb
.ulpContext
);
7926 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
7927 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
7928 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7929 if (command_type
== ELS_COMMAND_FIP
)
7930 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
7931 >> LPFC_FIP_ELS_ID_SHIFT
);
7932 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7933 iocbq
->context2
)->virt
);
7934 if_type
= bf_get(lpfc_sli_intf_if_type
,
7935 &phba
->sli4_hba
.sli_intf
);
7936 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7937 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
7938 *pcmd
== ELS_CMD_SCR
||
7939 *pcmd
== ELS_CMD_FDISC
||
7940 *pcmd
== ELS_CMD_LOGO
||
7941 *pcmd
== ELS_CMD_PLOGI
)) {
7942 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7943 bf_set(els_req64_sid
, &wqe
->els_req
,
7944 iocbq
->vport
->fc_myDID
);
7945 if ((*pcmd
== ELS_CMD_FLOGI
) &&
7946 !(phba
->fc_topology
==
7947 LPFC_TOPOLOGY_LOOP
))
7948 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
7949 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7950 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7951 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
7952 } else if (pcmd
&& iocbq
->context1
) {
7953 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
7954 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7955 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7958 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
7959 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7960 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
7961 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
7962 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7963 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
7964 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7965 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
7967 case CMD_XMIT_SEQUENCE64_CX
:
7968 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
7969 iocbq
->iocb
.un
.ulpWord
[3]);
7970 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
7971 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7972 /* The entire sequence is transmitted for this IOCB */
7973 xmit_len
= total_len
;
7974 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
7975 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
7976 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
7977 case CMD_XMIT_SEQUENCE64_CR
:
7978 /* word3 iocb=io_tag32 wqe=reserved */
7979 wqe
->xmit_sequence
.rsvd3
= 0;
7980 /* word4 relative_offset memcpy */
7981 /* word5 r_ctl/df_ctl memcpy */
7982 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
7983 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
7984 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
7985 LPFC_WQE_IOD_WRITE
);
7986 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
7987 LPFC_WQE_LENLOC_WORD12
);
7988 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
7989 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
7990 command_type
= OTHER_COMMAND
;
7992 case CMD_XMIT_BCAST64_CN
:
7993 /* word3 iocb=iotag32 wqe=seq_payload_len */
7994 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
7995 /* word4 iocb=rsvd wqe=rsvd */
7996 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
7997 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
7998 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
7999 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8000 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8001 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8002 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8003 LPFC_WQE_LENLOC_WORD3
);
8004 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8006 case CMD_FCP_IWRITE64_CR
:
8007 command_type
= FCP_COMMAND_DATA_OUT
;
8008 /* word3 iocb=iotag wqe=payload_offset_len */
8009 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8010 wqe
->fcp_iwrite
.payload_offset_len
=
8011 xmit_len
+ sizeof(struct fcp_rsp
);
8012 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8013 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8014 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8015 iocbq
->iocb
.ulpFCP2Rcvy
);
8016 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8017 /* Always open the exchange */
8018 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8019 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8020 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8021 LPFC_WQE_LENLOC_WORD4
);
8022 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8023 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8024 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
8025 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
8026 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
8028 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8030 case CMD_FCP_IREAD64_CR
:
8031 /* word3 iocb=iotag wqe=payload_offset_len */
8032 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8033 wqe
->fcp_iread
.payload_offset_len
=
8034 xmit_len
+ sizeof(struct fcp_rsp
);
8035 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8036 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8037 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8038 iocbq
->iocb
.ulpFCP2Rcvy
);
8039 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8040 /* Always open the exchange */
8041 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
8042 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8043 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8044 LPFC_WQE_LENLOC_WORD4
);
8045 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
8046 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8047 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
8048 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
8049 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
8051 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8053 case CMD_FCP_ICMND64_CR
:
8054 /* word3 iocb=IO_TAG wqe=reserved */
8055 wqe
->fcp_icmd
.rsrvd3
= 0;
8056 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8057 /* Always open the exchange */
8058 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
8059 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8060 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8061 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8062 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8063 LPFC_WQE_LENLOC_NONE
);
8064 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
8066 case CMD_GEN_REQUEST64_CR
:
8067 /* For this command calculate the xmit length of the
8071 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8072 sizeof(struct ulp_bde64
);
8073 for (i
= 0; i
< numBdes
; i
++) {
8074 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8075 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8077 xmit_len
+= bde
.tus
.f
.bdeSize
;
8079 /* word3 iocb=IO_TAG wqe=request_payload_len */
8080 wqe
->gen_req
.request_payload_len
= xmit_len
;
8081 /* word4 iocb=parameter wqe=relative_offset memcpy */
8082 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8083 /* word6 context tag copied in memcpy */
8084 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8085 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8086 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8087 "2015 Invalid CT %x command 0x%x\n",
8088 ct
, iocbq
->iocb
.ulpCommand
);
8091 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8092 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8093 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8094 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8095 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8096 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8097 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8098 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8099 command_type
= OTHER_COMMAND
;
8101 case CMD_XMIT_ELS_RSP64_CX
:
8102 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8103 /* words0-2 BDE memcpy */
8104 /* word3 iocb=iotag32 wqe=response_payload_len */
8105 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8107 wqe
->xmit_els_rsp
.word4
= 0;
8108 /* word5 iocb=rsvd wge=did */
8109 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8110 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
8112 if_type
= bf_get(lpfc_sli_intf_if_type
,
8113 &phba
->sli4_hba
.sli_intf
);
8114 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8115 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
8116 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8117 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8118 iocbq
->vport
->fc_myDID
);
8119 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
8121 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
8125 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8126 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8127 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8128 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8129 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8130 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8131 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8132 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8133 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8134 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8135 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8136 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8137 LPFC_WQE_LENLOC_WORD3
);
8138 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8139 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8140 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8141 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8142 iocbq
->context2
)->virt
);
8143 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8144 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8145 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8146 iocbq
->vport
->fc_myDID
);
8147 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8148 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8149 phba
->vpi_ids
[phba
->pport
->vpi
]);
8151 command_type
= OTHER_COMMAND
;
8153 case CMD_CLOSE_XRI_CN
:
8154 case CMD_ABORT_XRI_CN
:
8155 case CMD_ABORT_XRI_CX
:
8156 /* words 0-2 memcpy should be 0 rserved */
8157 /* port will send abts */
8158 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8159 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8160 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8161 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8165 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8167 * The link is down, or the command was ELS_FIP
8168 * so the fw does not need to send abts
8171 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8173 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8174 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8175 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8176 wqe
->abort_cmd
.rsrvd5
= 0;
8177 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8178 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8179 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8181 * The abort handler will send us CMD_ABORT_XRI_CN or
8182 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8184 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8185 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8186 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8187 LPFC_WQE_LENLOC_NONE
);
8188 cmnd
= CMD_ABORT_XRI_CX
;
8189 command_type
= OTHER_COMMAND
;
8192 case CMD_XMIT_BLS_RSP64_CX
:
8193 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8194 /* As BLS ABTS RSP WQE is very different from other WQEs,
8195 * we re-construct this WQE here based on information in
8196 * iocbq from scratch.
8198 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8199 /* OX_ID is invariable to who sent ABTS to CT exchange */
8200 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8201 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8202 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8203 LPFC_ABTS_UNSOL_INT
) {
8204 /* ABTS sent by initiator to CT exchange, the
8205 * RX_ID field will be filled with the newly
8206 * allocated responder XRI.
8208 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8209 iocbq
->sli4_xritag
);
8211 /* ABTS sent by responder to CT exchange, the
8212 * RX_ID field will be filled with the responder
8215 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8216 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8218 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8219 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8222 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8224 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8225 iocbq
->iocb
.ulpContext
);
8226 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8227 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8228 phba
->vpi_ids
[phba
->pport
->vpi
]);
8229 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8230 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8231 LPFC_WQE_LENLOC_NONE
);
8232 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8233 command_type
= OTHER_COMMAND
;
8234 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8235 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8236 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8237 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8238 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8239 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8240 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8244 case CMD_XRI_ABORTED_CX
:
8245 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8246 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8247 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8248 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8249 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8251 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8252 "2014 Invalid command 0x%x\n",
8253 iocbq
->iocb
.ulpCommand
);
8258 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8259 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8260 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8261 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8262 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8263 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8264 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8269 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8270 * @phba: Pointer to HBA context object.
8271 * @ring_number: SLI ring number to issue iocb on.
8272 * @piocb: Pointer to command iocb.
8273 * @flag: Flag indicating if this command can be put into txq.
8275 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8276 * an iocb command to an HBA with SLI-4 interface spec.
8278 * This function is called with hbalock held. The function will return success
8279 * after it successfully submit the iocb to firmware or after adding to the
8283 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8284 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8286 struct lpfc_sglq
*sglq
;
8288 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8290 if (piocb
->sli4_xritag
== NO_XRI
) {
8291 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8292 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8295 if (pring
->txq_cnt
) {
8296 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8297 __lpfc_sli_ringtx_put(phba
,
8299 return IOCB_SUCCESS
;
8304 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8306 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8307 __lpfc_sli_ringtx_put(phba
,
8310 return IOCB_SUCCESS
;
8316 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8317 /* These IO's already have an XRI and a mapped sgl. */
8321 * This is a continuation of a commandi,(CX) so this
8322 * sglq is on the active list
8324 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
8330 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8331 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8332 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8336 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8339 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8340 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8341 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8345 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8348 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8354 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8356 * This routine wraps the actual lockless version for issusing IOCB function
8357 * pointer from the lpfc_hba struct.
8360 * IOCB_ERROR - Error
8361 * IOCB_SUCCESS - Success
8365 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8366 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8368 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8372 * lpfc_sli_api_table_setup - Set up sli api function jump table
8373 * @phba: The hba struct for which this call is being executed.
8374 * @dev_grp: The HBA PCI-Device group number.
8376 * This routine sets up the SLI interface API function jump table in @phba
8378 * Returns: 0 - success, -ENODEV - failure.
8381 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8385 case LPFC_PCI_DEV_LP
:
8386 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8387 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8389 case LPFC_PCI_DEV_OC
:
8390 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8391 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8394 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8395 "1419 Invalid HBA PCI-device group: 0x%x\n",
8400 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8405 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8406 * @phba: Pointer to HBA context object.
8407 * @pring: Pointer to driver SLI ring object.
8408 * @piocb: Pointer to command iocb.
8409 * @flag: Flag indicating if this command can be put into txq.
8411 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8412 * function. This function gets the hbalock and calls
8413 * __lpfc_sli_issue_iocb function and will return the error returned
8414 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8415 * functions which do not hold hbalock.
8418 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8419 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8421 struct lpfc_sli_ring
*pring
;
8422 unsigned long iflags
;
8425 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8426 if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8427 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8429 idx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8430 piocb
->fcp_wqidx
= idx
;
8431 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+ idx
;
8433 pring
= &phba
->sli
.ring
[ring_number
];
8434 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8435 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8436 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8438 /* For now, SLI2/3 will still use hbalock */
8439 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8440 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8441 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8447 * lpfc_extra_ring_setup - Extra ring setup function
8448 * @phba: Pointer to HBA context object.
8450 * This function is called while driver attaches with the
8451 * HBA to setup the extra ring. The extra ring is used
8452 * only when driver needs to support target mode functionality
8453 * or IP over FC functionalities.
8455 * This function is called with no lock held.
8458 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8460 struct lpfc_sli
*psli
;
8461 struct lpfc_sli_ring
*pring
;
8465 /* Adjust cmd/rsp ring iocb entries more evenly */
8467 /* Take some away from the FCP ring */
8468 pring
= &psli
->ring
[psli
->fcp_ring
];
8469 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8470 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8471 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8472 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8474 /* and give them to the extra ring */
8475 pring
= &psli
->ring
[psli
->extra_ring
];
8477 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8478 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8479 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8480 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8482 /* Setup default profile for this ring */
8483 pring
->iotag_max
= 4096;
8484 pring
->num_mask
= 1;
8485 pring
->prt
[0].profile
= 0; /* Mask 0 */
8486 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8487 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8488 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8492 /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
8493 * @vport: pointer to virtual port object.
8494 * @ndlp: nodelist pointer for the impacted rport.
8496 * The driver calls this routine in response to a XRI ABORT CQE
8497 * event from the port. In this event, the driver is required to
8498 * recover its login to the rport even though its login may be valid
8499 * from the driver's perspective. The failed ABTS notice from the
8500 * port indicates the rport is not responding.
8503 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8504 struct lpfc_nodelist
*ndlp
)
8506 struct Scsi_Host
*shost
;
8507 struct lpfc_hba
*phba
;
8508 unsigned long flags
= 0;
8510 shost
= lpfc_shost_from_vport(vport
);
8512 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8513 lpfc_printf_log(phba
, KERN_INFO
,
8514 LOG_SLI
, "3093 No rport recovery needed. "
8515 "rport in state 0x%x\n",
8519 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8520 "3094 Start rport recovery on shost id 0x%x "
8521 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8523 shost
->host_no
, ndlp
->nlp_DID
,
8524 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8527 * The rport is not responding. Don't attempt ADISC recovery.
8528 * Remove the FCP-2 flag to force a PLOGI.
8530 spin_lock_irqsave(shost
->host_lock
, flags
);
8531 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8532 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8533 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
8534 NLP_EVT_DEVICE_RECOVERY
);
8535 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
8536 spin_lock_irqsave(shost
->host_lock
, flags
);
8537 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
8538 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8539 lpfc_disc_start(vport
);
8542 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8543 * @phba: Pointer to HBA context object.
8544 * @iocbq: Pointer to iocb object.
8546 * The async_event handler calls this routine when it receives
8547 * an ASYNC_STATUS_CN event from the port. The port generates
8548 * this event when an Abort Sequence request to an rport fails
8549 * twice in succession. The abort could be originated by the
8550 * driver or by the port. The ABTS could have been for an ELS
8551 * or FCP IO. The port only generates this event when an ABTS
8552 * fails to complete after one retry.
8555 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8556 struct lpfc_iocbq
*iocbq
)
8558 struct lpfc_nodelist
*ndlp
= NULL
;
8559 uint16_t rpi
= 0, vpi
= 0;
8560 struct lpfc_vport
*vport
= NULL
;
8562 /* The rpi in the ulpContext is vport-sensitive. */
8563 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8564 rpi
= iocbq
->iocb
.ulpContext
;
8566 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8567 "3092 Port generated ABTS async event "
8568 "on vpi %d rpi %d status 0x%x\n",
8569 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8571 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8574 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8575 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8578 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8579 lpfc_sli_abts_recover_port(vport
, ndlp
);
8583 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8584 "3095 Event Context not found, no "
8585 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8586 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8590 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8591 * @phba: pointer to HBA context object.
8592 * @ndlp: nodelist pointer for the impacted rport.
8593 * @axri: pointer to the wcqe containing the failed exchange.
8595 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8596 * port. The port generates this event when an abort exchange request to an
8597 * rport fails twice in succession with no reply. The abort could be originated
8598 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8601 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8602 struct lpfc_nodelist
*ndlp
,
8603 struct sli4_wcqe_xri_aborted
*axri
)
8605 struct lpfc_vport
*vport
;
8606 uint32_t ext_status
= 0;
8608 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
8609 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8610 "3115 Node Context not found, driver "
8611 "ignoring abts err event\n");
8615 vport
= ndlp
->vport
;
8616 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8617 "3116 Port generated FCP XRI ABORT event on "
8618 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8619 ndlp
->vport
->vpi
, ndlp
->nlp_rpi
,
8620 bf_get(lpfc_wcqe_xa_xri
, axri
),
8621 bf_get(lpfc_wcqe_xa_status
, axri
),
8625 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8626 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8627 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8629 ext_status
= axri
->parameter
& WCQE_PARAM_MASK
;
8630 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
8631 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
8632 lpfc_sli_abts_recover_port(vport
, ndlp
);
8636 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8637 * @phba: Pointer to HBA context object.
8638 * @pring: Pointer to driver SLI ring object.
8639 * @iocbq: Pointer to iocb object.
8641 * This function is called by the slow ring event handler
8642 * function when there is an ASYNC event iocb in the ring.
8643 * This function is called with no lock held.
8644 * Currently this function handles only temperature related
8645 * ASYNC events. The function decodes the temperature sensor
8646 * event message and posts events for the management applications.
8649 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8650 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8654 struct temp_event temp_event_data
;
8655 struct Scsi_Host
*shost
;
8658 icmd
= &iocbq
->iocb
;
8659 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8662 case ASYNC_TEMP_WARN
:
8663 case ASYNC_TEMP_SAFE
:
8664 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8665 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8666 if (evt_code
== ASYNC_TEMP_WARN
) {
8667 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8668 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8669 "0347 Adapter is very hot, please take "
8670 "corrective action. temperature : %d Celsius\n",
8671 (uint32_t) icmd
->ulpContext
);
8673 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8674 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8675 "0340 Adapter temperature is OK now. "
8676 "temperature : %d Celsius\n",
8677 (uint32_t) icmd
->ulpContext
);
8680 /* Send temperature change event to applications */
8681 shost
= lpfc_shost_from_vport(phba
->pport
);
8682 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8683 sizeof(temp_event_data
), (char *) &temp_event_data
,
8686 case ASYNC_STATUS_CN
:
8687 lpfc_sli_abts_err_handler(phba
, iocbq
);
8690 iocb_w
= (uint32_t *) icmd
;
8691 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8692 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8694 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8695 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8696 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8697 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8698 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8699 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8700 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8701 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8702 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8710 * lpfc_sli_setup - SLI ring setup function
8711 * @phba: Pointer to HBA context object.
8713 * lpfc_sli_setup sets up rings of the SLI interface with
8714 * number of iocbs per ring and iotags. This function is
8715 * called while driver attach to the HBA and before the
8716 * interrupts are enabled. So there is no need for locking.
8718 * This function always returns 0.
8721 lpfc_sli_setup(struct lpfc_hba
*phba
)
8723 int i
, totiocbsize
= 0;
8724 struct lpfc_sli
*psli
= &phba
->sli
;
8725 struct lpfc_sli_ring
*pring
;
8727 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
8728 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8729 psli
->num_rings
+= phba
->cfg_fcp_io_channel
;
8731 psli
->fcp_ring
= LPFC_FCP_RING
;
8732 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8733 psli
->extra_ring
= LPFC_EXTRA_RING
;
8735 psli
->iocbq_lookup
= NULL
;
8736 psli
->iocbq_lookup_len
= 0;
8737 psli
->last_iotag
= 0;
8739 for (i
= 0; i
< psli
->num_rings
; i
++) {
8740 pring
= &psli
->ring
[i
];
8742 case LPFC_FCP_RING
: /* ring 0 - FCP */
8743 /* numCiocb and numRiocb are used in config_port */
8744 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8745 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8746 pring
->sli
.sli3
.numCiocb
+=
8747 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8748 pring
->sli
.sli3
.numRiocb
+=
8749 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8750 pring
->sli
.sli3
.numCiocb
+=
8751 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8752 pring
->sli
.sli3
.numRiocb
+=
8753 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8754 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8755 SLI3_IOCB_CMD_SIZE
:
8757 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8758 SLI3_IOCB_RSP_SIZE
:
8760 pring
->iotag_ctr
= 0;
8762 (phba
->cfg_hba_queue_depth
* 2);
8763 pring
->fast_iotag
= pring
->iotag_max
;
8764 pring
->num_mask
= 0;
8766 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
8767 /* numCiocb and numRiocb are used in config_port */
8768 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
8769 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
8770 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8771 SLI3_IOCB_CMD_SIZE
:
8773 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8774 SLI3_IOCB_RSP_SIZE
:
8776 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
8777 pring
->num_mask
= 0;
8779 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
8780 /* numCiocb and numRiocb are used in config_port */
8781 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
8782 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
8783 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8784 SLI3_IOCB_CMD_SIZE
:
8786 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8787 SLI3_IOCB_RSP_SIZE
:
8789 pring
->fast_iotag
= 0;
8790 pring
->iotag_ctr
= 0;
8791 pring
->iotag_max
= 4096;
8792 pring
->lpfc_sli_rcv_async_status
=
8793 lpfc_sli_async_event_handler
;
8794 pring
->num_mask
= LPFC_MAX_RING_MASK
;
8795 pring
->prt
[0].profile
= 0; /* Mask 0 */
8796 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
8797 pring
->prt
[0].type
= FC_TYPE_ELS
;
8798 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
8799 lpfc_els_unsol_event
;
8800 pring
->prt
[1].profile
= 0; /* Mask 1 */
8801 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
8802 pring
->prt
[1].type
= FC_TYPE_ELS
;
8803 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
8804 lpfc_els_unsol_event
;
8805 pring
->prt
[2].profile
= 0; /* Mask 2 */
8806 /* NameServer Inquiry */
8807 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
8809 pring
->prt
[2].type
= FC_TYPE_CT
;
8810 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
8811 lpfc_ct_unsol_event
;
8812 pring
->prt
[3].profile
= 0; /* Mask 3 */
8813 /* NameServer response */
8814 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
8816 pring
->prt
[3].type
= FC_TYPE_CT
;
8817 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
8818 lpfc_ct_unsol_event
;
8819 /* abort unsolicited sequence */
8820 pring
->prt
[4].profile
= 0; /* Mask 4 */
8821 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
8822 pring
->prt
[4].type
= FC_TYPE_BLS
;
8823 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
8824 lpfc_sli4_ct_abort_unsol_event
;
8827 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
8828 pring
->sli
.sli3
.sizeCiocb
) +
8829 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
8831 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
8832 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8833 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
8834 "SLI2 SLIM Data: x%x x%lx\n",
8835 phba
->brd_no
, totiocbsize
,
8836 (unsigned long) MAX_SLIM_IOCB_SIZE
);
8838 if (phba
->cfg_multi_ring_support
== 2)
8839 lpfc_extra_ring_setup(phba
);
8845 * lpfc_sli_queue_setup - Queue initialization function
8846 * @phba: Pointer to HBA context object.
8848 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8849 * ring. This function also initializes ring indices of each ring.
8850 * This function is called during the initialization of the SLI
8851 * interface of an HBA.
8852 * This function is called with no lock held and always returns
8856 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
8858 struct lpfc_sli
*psli
;
8859 struct lpfc_sli_ring
*pring
;
8863 spin_lock_irq(&phba
->hbalock
);
8864 INIT_LIST_HEAD(&psli
->mboxq
);
8865 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
8866 /* Initialize list headers for txq and txcmplq as double linked lists */
8867 for (i
= 0; i
< psli
->num_rings
; i
++) {
8868 pring
= &psli
->ring
[i
];
8870 pring
->sli
.sli3
.next_cmdidx
= 0;
8871 pring
->sli
.sli3
.local_getidx
= 0;
8872 pring
->sli
.sli3
.cmdidx
= 0;
8873 INIT_LIST_HEAD(&pring
->txq
);
8874 INIT_LIST_HEAD(&pring
->txcmplq
);
8875 INIT_LIST_HEAD(&pring
->iocb_continueq
);
8876 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
8877 INIT_LIST_HEAD(&pring
->postbufq
);
8878 spin_lock_init(&pring
->ring_lock
);
8880 spin_unlock_irq(&phba
->hbalock
);
8885 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8886 * @phba: Pointer to HBA context object.
8888 * This routine flushes the mailbox command subsystem. It will unconditionally
8889 * flush all the mailbox commands in the three possible stages in the mailbox
8890 * command sub-system: pending mailbox command queue; the outstanding mailbox
8891 * command; and completed mailbox command queue. It is caller's responsibility
8892 * to make sure that the driver is in the proper state to flush the mailbox
8893 * command sub-system. Namely, the posting of mailbox commands into the
8894 * pending mailbox command queue from the various clients must be stopped;
8895 * either the HBA is in a state that it will never works on the outstanding
8896 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8897 * mailbox command has been completed.
8900 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
8902 LIST_HEAD(completions
);
8903 struct lpfc_sli
*psli
= &phba
->sli
;
8905 unsigned long iflag
;
8907 /* Flush all the mailbox commands in the mbox system */
8908 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8909 /* The pending mailbox command queue */
8910 list_splice_init(&phba
->sli
.mboxq
, &completions
);
8911 /* The outstanding active mailbox command */
8912 if (psli
->mbox_active
) {
8913 list_add_tail(&psli
->mbox_active
->list
, &completions
);
8914 psli
->mbox_active
= NULL
;
8915 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8917 /* The completed mailbox command queue */
8918 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
8919 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8921 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8922 while (!list_empty(&completions
)) {
8923 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
8924 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8926 pmb
->mbox_cmpl(phba
, pmb
);
8931 * lpfc_sli_host_down - Vport cleanup function
8932 * @vport: Pointer to virtual port object.
8934 * lpfc_sli_host_down is called to clean up the resources
8935 * associated with a vport before destroying virtual
8936 * port data structures.
8937 * This function does following operations:
8938 * - Free discovery resources associated with this virtual
8940 * - Free iocbs associated with this virtual port in
8942 * - Send abort for all iocb commands associated with this
8945 * This function is called with no lock held and always returns 1.
8948 lpfc_sli_host_down(struct lpfc_vport
*vport
)
8950 LIST_HEAD(completions
);
8951 struct lpfc_hba
*phba
= vport
->phba
;
8952 struct lpfc_sli
*psli
= &phba
->sli
;
8953 struct lpfc_sli_ring
*pring
;
8954 struct lpfc_iocbq
*iocb
, *next_iocb
;
8956 unsigned long flags
= 0;
8957 uint16_t prev_pring_flag
;
8959 lpfc_cleanup_discovery_resources(vport
);
8961 spin_lock_irqsave(&phba
->hbalock
, flags
);
8962 for (i
= 0; i
< psli
->num_rings
; i
++) {
8963 pring
= &psli
->ring
[i
];
8964 prev_pring_flag
= pring
->flag
;
8965 /* Only slow rings */
8966 if (pring
->ringno
== LPFC_ELS_RING
) {
8967 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8968 /* Set the lpfc data pending flag */
8969 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8972 * Error everything on the txq since these iocbs have not been
8973 * given to the FW yet.
8975 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
8976 if (iocb
->vport
!= vport
)
8978 list_move_tail(&iocb
->list
, &completions
);
8982 /* Next issue ABTS for everything on the txcmplq */
8983 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
8985 if (iocb
->vport
!= vport
)
8987 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
8990 pring
->flag
= prev_pring_flag
;
8993 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8995 /* Cancel all the IOCBs from the completions list */
8996 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9002 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9003 * @phba: Pointer to HBA context object.
9005 * This function cleans up all iocb, buffers, mailbox commands
9006 * while shutting down the HBA. This function is called with no
9007 * lock held and always returns 1.
9008 * This function does the following to cleanup driver resources:
9009 * - Free discovery resources for each virtual port
9010 * - Cleanup any pending fabric iocbs
9011 * - Iterate through the iocb txq and free each entry
9013 * - Free up any buffer posted to the HBA
9014 * - Free mailbox commands in the mailbox queue.
9017 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
9019 LIST_HEAD(completions
);
9020 struct lpfc_sli
*psli
= &phba
->sli
;
9021 struct lpfc_sli_ring
*pring
;
9022 struct lpfc_dmabuf
*buf_ptr
;
9023 unsigned long flags
= 0;
9026 /* Shutdown the mailbox command sub-system */
9027 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
9029 lpfc_hba_down_prep(phba
);
9031 lpfc_fabric_abort_hba(phba
);
9033 spin_lock_irqsave(&phba
->hbalock
, flags
);
9034 for (i
= 0; i
< psli
->num_rings
; i
++) {
9035 pring
= &psli
->ring
[i
];
9036 /* Only slow rings */
9037 if (pring
->ringno
== LPFC_ELS_RING
) {
9038 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9039 /* Set the lpfc data pending flag */
9040 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9044 * Error everything on the txq since these iocbs have not been
9045 * given to the FW yet.
9047 list_splice_init(&pring
->txq
, &completions
);
9051 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9053 /* Cancel all the IOCBs from the completions list */
9054 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9057 spin_lock_irqsave(&phba
->hbalock
, flags
);
9058 list_splice_init(&phba
->elsbuf
, &completions
);
9059 phba
->elsbuf_cnt
= 0;
9060 phba
->elsbuf_prev_cnt
= 0;
9061 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9063 while (!list_empty(&completions
)) {
9064 list_remove_head(&completions
, buf_ptr
,
9065 struct lpfc_dmabuf
, list
);
9066 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
9070 /* Return any active mbox cmds */
9071 del_timer_sync(&psli
->mbox_tmo
);
9073 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
9074 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9075 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9081 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9082 * @srcp: Source memory pointer.
9083 * @destp: Destination memory pointer.
9084 * @cnt: Number of words required to be copied.
9086 * This function is used for copying data between driver memory
9087 * and the SLI memory. This function also changes the endianness
9088 * of each word if native endianness is different from SLI
9089 * endianness. This function can be called with or without
9093 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9095 uint32_t *src
= srcp
;
9096 uint32_t *dest
= destp
;
9100 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9102 ldata
= le32_to_cpu(ldata
);
9111 * lpfc_sli_bemem_bcopy - SLI memory copy function
9112 * @srcp: Source memory pointer.
9113 * @destp: Destination memory pointer.
9114 * @cnt: Number of words required to be copied.
9116 * This function is used for copying data between a data structure
9117 * with big endian representation to local endianness.
9118 * This function can be called with or without lock.
9121 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9123 uint32_t *src
= srcp
;
9124 uint32_t *dest
= destp
;
9128 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9130 ldata
= be32_to_cpu(ldata
);
9138 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9139 * @phba: Pointer to HBA context object.
9140 * @pring: Pointer to driver SLI ring object.
9141 * @mp: Pointer to driver buffer object.
9143 * This function is called with no lock held.
9144 * It always return zero after adding the buffer to the postbufq
9148 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9149 struct lpfc_dmabuf
*mp
)
9151 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9153 spin_lock_irq(&phba
->hbalock
);
9154 list_add_tail(&mp
->list
, &pring
->postbufq
);
9155 pring
->postbufq_cnt
++;
9156 spin_unlock_irq(&phba
->hbalock
);
9161 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9162 * @phba: Pointer to HBA context object.
9164 * When HBQ is enabled, buffers are searched based on tags. This function
9165 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9166 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9167 * does not conflict with tags of buffer posted for unsolicited events.
9168 * The function returns the allocated tag. The function is called with
9172 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9174 spin_lock_irq(&phba
->hbalock
);
9175 phba
->buffer_tag_count
++;
9177 * Always set the QUE_BUFTAG_BIT to distiguish between
9178 * a tag assigned by HBQ.
9180 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9181 spin_unlock_irq(&phba
->hbalock
);
9182 return phba
->buffer_tag_count
;
9186 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9187 * @phba: Pointer to HBA context object.
9188 * @pring: Pointer to driver SLI ring object.
9191 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9192 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9193 * iocb is posted to the response ring with the tag of the buffer.
9194 * This function searches the pring->postbufq list using the tag
9195 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9196 * iocb. If the buffer is found then lpfc_dmabuf object of the
9197 * buffer is returned to the caller else NULL is returned.
9198 * This function is called with no lock held.
9200 struct lpfc_dmabuf
*
9201 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9204 struct lpfc_dmabuf
*mp
, *next_mp
;
9205 struct list_head
*slp
= &pring
->postbufq
;
9207 /* Search postbufq, from the beginning, looking for a match on tag */
9208 spin_lock_irq(&phba
->hbalock
);
9209 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9210 if (mp
->buffer_tag
== tag
) {
9211 list_del_init(&mp
->list
);
9212 pring
->postbufq_cnt
--;
9213 spin_unlock_irq(&phba
->hbalock
);
9218 spin_unlock_irq(&phba
->hbalock
);
9219 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9220 "0402 Cannot find virtual addr for buffer tag on "
9221 "ring %d Data x%lx x%p x%p x%x\n",
9222 pring
->ringno
, (unsigned long) tag
,
9223 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9229 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9230 * @phba: Pointer to HBA context object.
9231 * @pring: Pointer to driver SLI ring object.
9232 * @phys: DMA address of the buffer.
9234 * This function searches the buffer list using the dma_address
9235 * of unsolicited event to find the driver's lpfc_dmabuf object
9236 * corresponding to the dma_address. The function returns the
9237 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9238 * This function is called by the ct and els unsolicited event
9239 * handlers to get the buffer associated with the unsolicited
9242 * This function is called with no lock held.
9244 struct lpfc_dmabuf
*
9245 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9248 struct lpfc_dmabuf
*mp
, *next_mp
;
9249 struct list_head
*slp
= &pring
->postbufq
;
9251 /* Search postbufq, from the beginning, looking for a match on phys */
9252 spin_lock_irq(&phba
->hbalock
);
9253 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9254 if (mp
->phys
== phys
) {
9255 list_del_init(&mp
->list
);
9256 pring
->postbufq_cnt
--;
9257 spin_unlock_irq(&phba
->hbalock
);
9262 spin_unlock_irq(&phba
->hbalock
);
9263 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9264 "0410 Cannot find virtual addr for mapped buf on "
9265 "ring %d Data x%llx x%p x%p x%x\n",
9266 pring
->ringno
, (unsigned long long)phys
,
9267 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9272 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9273 * @phba: Pointer to HBA context object.
9274 * @cmdiocb: Pointer to driver command iocb object.
9275 * @rspiocb: Pointer to driver response iocb object.
9277 * This function is the completion handler for the abort iocbs for
9278 * ELS commands. This function is called from the ELS ring event
9279 * handler with no lock held. This function frees memory resources
9280 * associated with the abort iocb.
9283 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9284 struct lpfc_iocbq
*rspiocb
)
9286 IOCB_t
*irsp
= &rspiocb
->iocb
;
9287 uint16_t abort_iotag
, abort_context
;
9288 struct lpfc_iocbq
*abort_iocb
= NULL
;
9290 if (irsp
->ulpStatus
) {
9293 * Assume that the port already completed and returned, or
9294 * will return the iocb. Just Log the message.
9296 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9297 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9299 spin_lock_irq(&phba
->hbalock
);
9300 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9301 if (abort_iotag
!= 0 &&
9302 abort_iotag
<= phba
->sli
.last_iotag
)
9304 phba
->sli
.iocbq_lookup
[abort_iotag
];
9306 /* For sli4 the abort_tag is the XRI,
9307 * so the abort routine puts the iotag of the iocb
9308 * being aborted in the context field of the abort
9311 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9313 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9314 "0327 Cannot abort els iocb %p "
9315 "with tag %x context %x, abort status %x, "
9317 abort_iocb
, abort_iotag
, abort_context
,
9318 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9320 spin_unlock_irq(&phba
->hbalock
);
9322 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9327 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9328 * @phba: Pointer to HBA context object.
9329 * @cmdiocb: Pointer to driver command iocb object.
9330 * @rspiocb: Pointer to driver response iocb object.
9332 * The function is called from SLI ring event handler with no
9333 * lock held. This function is the completion handler for ELS commands
9334 * which are aborted. The function frees memory resources used for
9335 * the aborted ELS commands.
9338 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9339 struct lpfc_iocbq
*rspiocb
)
9341 IOCB_t
*irsp
= &rspiocb
->iocb
;
9343 /* ELS cmd tag <ulpIoTag> completes */
9344 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9345 "0139 Ignoring ELS cmd tag x%x completion Data: "
9347 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9348 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9349 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9350 lpfc_ct_free_iocb(phba
, cmdiocb
);
9352 lpfc_els_free_iocb(phba
, cmdiocb
);
9357 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9358 * @phba: Pointer to HBA context object.
9359 * @pring: Pointer to driver SLI ring object.
9360 * @cmdiocb: Pointer to driver command iocb object.
9362 * This function issues an abort iocb for the provided command iocb down to
9363 * the port. Other than the case the outstanding command iocb is an abort
9364 * request, this function issues abort out unconditionally. This function is
9365 * called with hbalock held. The function returns 0 when it fails due to
9366 * memory allocation failure or when the command iocb is an abort request.
9369 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9370 struct lpfc_iocbq
*cmdiocb
)
9372 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9373 struct lpfc_iocbq
*abtsiocbp
;
9374 IOCB_t
*icmd
= NULL
;
9375 IOCB_t
*iabt
= NULL
;
9377 unsigned long iflags
;
9380 * There are certain command types we don't want to abort. And we
9381 * don't want to abort commands that are already in the process of
9384 icmd
= &cmdiocb
->iocb
;
9385 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9386 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9387 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9390 /* issue ABTS for this IOCB based on iotag */
9391 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9392 if (abtsiocbp
== NULL
)
9395 /* This signals the response to set the correct status
9396 * before calling the completion handler
9398 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9400 iabt
= &abtsiocbp
->iocb
;
9401 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9402 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9403 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9404 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9405 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9408 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9410 iabt
->ulpClass
= icmd
->ulpClass
;
9412 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9413 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9414 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9415 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9417 if (phba
->link_state
>= LPFC_LINK_UP
)
9418 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9420 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9422 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9424 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9425 "0339 Abort xri x%x, original iotag x%x, "
9426 "abort cmd iotag x%x\n",
9427 iabt
->un
.acxri
.abortIoTag
,
9428 iabt
->un
.acxri
.abortContextTag
,
9431 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9432 /* Note: both hbalock and ring_lock need to be set here */
9433 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9434 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9436 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9438 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9443 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9446 * Caller to this routine should check for IOCB_ERROR
9447 * and handle it properly. This routine no longer removes
9448 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9454 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9455 * @phba: Pointer to HBA context object.
9456 * @pring: Pointer to driver SLI ring object.
9457 * @cmdiocb: Pointer to driver command iocb object.
9459 * This function issues an abort iocb for the provided command iocb. In case
9460 * of unloading, the abort iocb will not be issued to commands on the ELS
9461 * ring. Instead, the callback function shall be changed to those commands
9462 * so that nothing happens when them finishes. This function is called with
9463 * hbalock held. The function returns 0 when the command iocb is an abort
9467 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9468 struct lpfc_iocbq
*cmdiocb
)
9470 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9471 int retval
= IOCB_ERROR
;
9472 IOCB_t
*icmd
= NULL
;
9475 * There are certain command types we don't want to abort. And we
9476 * don't want to abort commands that are already in the process of
9479 icmd
= &cmdiocb
->iocb
;
9480 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9481 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9482 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9486 * If we're unloading, don't abort iocb on the ELS ring, but change
9487 * the callback so that nothing happens when it finishes.
9489 if ((vport
->load_flag
& FC_UNLOADING
) &&
9490 (pring
->ringno
== LPFC_ELS_RING
)) {
9491 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9492 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9494 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9495 goto abort_iotag_exit
;
9498 /* Now, we try to issue the abort to the cmdiocb out */
9499 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9503 * Caller to this routine should check for IOCB_ERROR
9504 * and handle it properly. This routine no longer removes
9505 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9511 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9512 * @phba: Pointer to HBA context object.
9513 * @pring: Pointer to driver SLI ring object.
9515 * This function aborts all iocbs in the given ring and frees all the iocb
9516 * objects in txq. This function issues abort iocbs unconditionally for all
9517 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9518 * to complete before the return of this function. The caller is not required
9519 * to hold any locks.
9522 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9524 LIST_HEAD(completions
);
9525 struct lpfc_iocbq
*iocb
, *next_iocb
;
9527 if (pring
->ringno
== LPFC_ELS_RING
)
9528 lpfc_fabric_abort_hba(phba
);
9530 spin_lock_irq(&phba
->hbalock
);
9532 /* Take off all the iocbs on txq for cancelling */
9533 list_splice_init(&pring
->txq
, &completions
);
9536 /* Next issue ABTS for everything on the txcmplq */
9537 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9538 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9540 spin_unlock_irq(&phba
->hbalock
);
9542 /* Cancel all the IOCBs from the completions list */
9543 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9548 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9549 * @phba: pointer to lpfc HBA data structure.
9551 * This routine will abort all pending and outstanding iocbs to an HBA.
9554 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9556 struct lpfc_sli
*psli
= &phba
->sli
;
9557 struct lpfc_sli_ring
*pring
;
9560 for (i
= 0; i
< psli
->num_rings
; i
++) {
9561 pring
= &psli
->ring
[i
];
9562 lpfc_sli_iocb_ring_abort(phba
, pring
);
9567 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9568 * @iocbq: Pointer to driver iocb object.
9569 * @vport: Pointer to driver virtual port object.
9570 * @tgt_id: SCSI ID of the target.
9571 * @lun_id: LUN ID of the scsi device.
9572 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9574 * This function acts as an iocb filter for functions which abort or count
9575 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9576 * 0 if the filtering criteria is met for the given iocb and will return
9577 * 1 if the filtering criteria is not met.
9578 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9579 * given iocb is for the SCSI device specified by vport, tgt_id and
9581 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9582 * given iocb is for the SCSI target specified by vport and tgt_id
9584 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9585 * given iocb is for the SCSI host associated with the given vport.
9586 * This function is called with no locks held.
9589 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9590 uint16_t tgt_id
, uint64_t lun_id
,
9591 lpfc_ctx_cmd ctx_cmd
)
9593 struct lpfc_scsi_buf
*lpfc_cmd
;
9596 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9599 if (iocbq
->vport
!= vport
)
9602 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9604 if (lpfc_cmd
->pCmd
== NULL
)
9609 if ((lpfc_cmd
->rdata
->pnode
) &&
9610 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9611 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9615 if ((lpfc_cmd
->rdata
->pnode
) &&
9616 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9623 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9632 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9633 * @vport: Pointer to virtual port.
9634 * @tgt_id: SCSI ID of the target.
9635 * @lun_id: LUN ID of the scsi device.
9636 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9638 * This function returns number of FCP commands pending for the vport.
9639 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9640 * commands pending on the vport associated with SCSI device specified
9641 * by tgt_id and lun_id parameters.
9642 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9643 * commands pending on the vport associated with SCSI target specified
9644 * by tgt_id parameter.
9645 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9646 * commands pending on the vport.
9647 * This function returns the number of iocbs which satisfy the filter.
9648 * This function is called without any lock held.
9651 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9652 lpfc_ctx_cmd ctx_cmd
)
9654 struct lpfc_hba
*phba
= vport
->phba
;
9655 struct lpfc_iocbq
*iocbq
;
9658 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9659 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9661 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9670 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9671 * @phba: Pointer to HBA context object
9672 * @cmdiocb: Pointer to command iocb object.
9673 * @rspiocb: Pointer to response iocb object.
9675 * This function is called when an aborted FCP iocb completes. This
9676 * function is called by the ring event handler with no lock held.
9677 * This function frees the iocb.
9680 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9681 struct lpfc_iocbq
*rspiocb
)
9683 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9684 "3096 ABORT_XRI_CN completing on xri x%x "
9685 "original iotag x%x, abort cmd iotag x%x "
9686 "status 0x%x, reason 0x%x\n",
9687 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9688 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9689 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9690 rspiocb
->iocb
.un
.ulpWord
[4]);
9691 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9696 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9697 * @vport: Pointer to virtual port.
9698 * @pring: Pointer to driver SLI ring object.
9699 * @tgt_id: SCSI ID of the target.
9700 * @lun_id: LUN ID of the scsi device.
9701 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9703 * This function sends an abort command for every SCSI command
9704 * associated with the given virtual port pending on the ring
9705 * filtered by lpfc_sli_validate_fcp_iocb function.
9706 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9707 * FCP iocbs associated with lun specified by tgt_id and lun_id
9709 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9710 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9711 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9712 * FCP iocbs associated with virtual port.
9713 * This function returns number of iocbs it failed to abort.
9714 * This function is called with no locks held.
9717 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9718 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9720 struct lpfc_hba
*phba
= vport
->phba
;
9721 struct lpfc_iocbq
*iocbq
;
9722 struct lpfc_iocbq
*abtsiocb
;
9724 int errcnt
= 0, ret_val
= 0;
9727 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9728 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9730 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9734 /* issue ABTS for this IOCB based on iotag */
9735 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9736 if (abtsiocb
== NULL
) {
9742 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9743 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9744 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9745 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9747 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9748 abtsiocb
->iocb
.ulpLe
= 1;
9749 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9750 abtsiocb
->vport
= phba
->pport
;
9752 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9753 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9754 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9755 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9757 if (lpfc_is_link_up(phba
))
9758 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9760 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
9762 /* Setup callback routine and issue the command. */
9763 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
9764 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9766 if (ret_val
== IOCB_ERROR
) {
9767 lpfc_sli_release_iocbq(phba
, abtsiocb
);
9777 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9778 * @phba: Pointer to HBA context object.
9779 * @cmdiocbq: Pointer to command iocb.
9780 * @rspiocbq: Pointer to response iocb.
9782 * This function is the completion handler for iocbs issued using
9783 * lpfc_sli_issue_iocb_wait function. This function is called by the
9784 * ring event handler function without any lock held. This function
9785 * can be called from both worker thread context and interrupt
9786 * context. This function also can be called from other thread which
9787 * cleans up the SLI layer objects.
9788 * This function copy the contents of the response iocb to the
9789 * response iocb memory object provided by the caller of
9790 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9791 * sleeps for the iocb completion.
9794 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
9795 struct lpfc_iocbq
*cmdiocbq
,
9796 struct lpfc_iocbq
*rspiocbq
)
9798 wait_queue_head_t
*pdone_q
;
9799 unsigned long iflags
;
9800 struct lpfc_scsi_buf
*lpfc_cmd
;
9802 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9803 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
9804 if (cmdiocbq
->context2
&& rspiocbq
)
9805 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
9806 &rspiocbq
->iocb
, sizeof(IOCB_t
));
9808 /* Set the exchange busy flag for task management commands */
9809 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
9810 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
9811 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
9813 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
9816 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
9819 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9824 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9825 * @phba: Pointer to HBA context object..
9826 * @piocbq: Pointer to command iocb.
9827 * @flag: Flag to test.
9829 * This routine grabs the hbalock and then test the iocb_flag to
9830 * see if the passed in flag is set.
9833 * 0 if flag is not set.
9836 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
9837 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
9839 unsigned long iflags
;
9842 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9843 ret
= piocbq
->iocb_flag
& flag
;
9844 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9850 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9851 * @phba: Pointer to HBA context object..
9852 * @pring: Pointer to sli ring.
9853 * @piocb: Pointer to command iocb.
9854 * @prspiocbq: Pointer to response iocb.
9855 * @timeout: Timeout in number of seconds.
9857 * This function issues the iocb to firmware and waits for the
9858 * iocb to complete. If the iocb command is not
9859 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9860 * Caller should not free the iocb resources if this function
9861 * returns IOCB_TIMEDOUT.
9862 * The function waits for the iocb completion using an
9863 * non-interruptible wait.
9864 * This function will sleep while waiting for iocb completion.
9865 * So, this function should not be called from any context which
9866 * does not allow sleeping. Due to the same reason, this function
9867 * cannot be called with interrupt disabled.
9868 * This function assumes that the iocb completions occur while
9869 * this function sleep. So, this function cannot be called from
9870 * the thread which process iocb completion for this ring.
9871 * This function clears the iocb_flag of the iocb object before
9872 * issuing the iocb and the iocb completion handler sets this
9873 * flag and wakes this thread when the iocb completes.
9874 * The contents of the response iocb will be copied to prspiocbq
9875 * by the completion handler when the command completes.
9876 * This function returns IOCB_SUCCESS when success.
9877 * This function is called with no lock held.
9880 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
9881 uint32_t ring_number
,
9882 struct lpfc_iocbq
*piocb
,
9883 struct lpfc_iocbq
*prspiocbq
,
9886 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9887 long timeleft
, timeout_req
= 0;
9888 int retval
= IOCB_SUCCESS
;
9890 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9892 * If the caller has provided a response iocbq buffer, then context2
9893 * is NULL or its an error.
9896 if (piocb
->context2
)
9898 piocb
->context2
= prspiocbq
;
9901 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
9902 piocb
->context_un
.wait_queue
= &done_q
;
9903 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
9905 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9906 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9908 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
9909 writel(creg_val
, phba
->HCregaddr
);
9910 readl(phba
->HCregaddr
); /* flush */
9913 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
9915 if (retval
== IOCB_SUCCESS
) {
9916 timeout_req
= timeout
* HZ
;
9917 timeleft
= wait_event_timeout(done_q
,
9918 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
9921 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
9922 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9923 "0331 IOCB wake signaled\n");
9924 } else if (timeleft
== 0) {
9925 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9926 "0338 IOCB wait timeout error - no "
9927 "wake response Data x%x\n", timeout
);
9928 retval
= IOCB_TIMEDOUT
;
9930 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9931 "0330 IOCB wake NOT set, "
9933 timeout
, (timeleft
/ jiffies
));
9934 retval
= IOCB_TIMEDOUT
;
9936 } else if (retval
== IOCB_BUSY
) {
9937 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9938 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
9939 phba
->iocb_cnt
, pring
->txq_cnt
, pring
->txcmplq_cnt
);
9942 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9943 "0332 IOCB wait issue failed, Data x%x\n",
9945 retval
= IOCB_ERROR
;
9948 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9949 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9951 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
9952 writel(creg_val
, phba
->HCregaddr
);
9953 readl(phba
->HCregaddr
); /* flush */
9957 piocb
->context2
= NULL
;
9959 piocb
->context_un
.wait_queue
= NULL
;
9960 piocb
->iocb_cmpl
= NULL
;
9965 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
9966 * @phba: Pointer to HBA context object.
9967 * @pmboxq: Pointer to driver mailbox object.
9968 * @timeout: Timeout in number of seconds.
9970 * This function issues the mailbox to firmware and waits for the
9971 * mailbox command to complete. If the mailbox command is not
9972 * completed within timeout seconds, it returns MBX_TIMEOUT.
9973 * The function waits for the mailbox completion using an
9974 * interruptible wait. If the thread is woken up due to a
9975 * signal, MBX_TIMEOUT error is returned to the caller. Caller
9976 * should not free the mailbox resources, if this function returns
9978 * This function will sleep while waiting for mailbox completion.
9979 * So, this function should not be called from any context which
9980 * does not allow sleeping. Due to the same reason, this function
9981 * cannot be called with interrupt disabled.
9982 * This function assumes that the mailbox completion occurs while
9983 * this function sleep. So, this function cannot be called from
9984 * the worker thread which processes mailbox completion.
9985 * This function is called in the context of HBA management
9987 * This function returns MBX_SUCCESS when successful.
9988 * This function is called with no lock held.
9991 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
9994 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9998 /* The caller must leave context1 empty. */
9999 if (pmboxq
->context1
)
10000 return MBX_NOT_FINISHED
;
10002 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
10003 /* setup wake call as IOCB callback */
10004 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
10005 /* setup context field to pass wait_queue pointer to wake function */
10006 pmboxq
->context1
= &done_q
;
10008 /* now issue the command */
10009 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
10010 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
10011 wait_event_interruptible_timeout(done_q
,
10012 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
10015 spin_lock_irqsave(&phba
->hbalock
, flag
);
10016 pmboxq
->context1
= NULL
;
10018 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10019 * else do not free the resources.
10021 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
10022 retval
= MBX_SUCCESS
;
10023 lpfc_sli4_swap_str(phba
, pmboxq
);
10025 retval
= MBX_TIMEOUT
;
10026 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10028 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
10035 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10036 * @phba: Pointer to HBA context.
10038 * This function is called to shutdown the driver's mailbox sub-system.
10039 * It first marks the mailbox sub-system is in a block state to prevent
10040 * the asynchronous mailbox command from issued off the pending mailbox
10041 * command queue. If the mailbox command sub-system shutdown is due to
10042 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10043 * the mailbox sub-system flush routine to forcefully bring down the
10044 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10045 * as with offline or HBA function reset), this routine will wait for the
10046 * outstanding mailbox command to complete before invoking the mailbox
10047 * sub-system flush routine to gracefully bring down mailbox sub-system.
10050 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
10052 struct lpfc_sli
*psli
= &phba
->sli
;
10053 unsigned long timeout
;
10055 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
10056 /* delay 100ms for port state */
10058 lpfc_sli_mbox_sys_flush(phba
);
10061 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
10063 spin_lock_irq(&phba
->hbalock
);
10064 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10066 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
10067 /* Determine how long we might wait for the active mailbox
10068 * command to be gracefully completed by firmware.
10070 if (phba
->sli
.mbox_active
)
10071 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
10072 phba
->sli
.mbox_active
) *
10074 spin_unlock_irq(&phba
->hbalock
);
10076 while (phba
->sli
.mbox_active
) {
10077 /* Check active mailbox complete status every 2ms */
10079 if (time_after(jiffies
, timeout
))
10080 /* Timeout, let the mailbox flush routine to
10081 * forcefully release active mailbox command
10086 spin_unlock_irq(&phba
->hbalock
);
10088 lpfc_sli_mbox_sys_flush(phba
);
10092 * lpfc_sli_eratt_read - read sli-3 error attention events
10093 * @phba: Pointer to HBA context.
10095 * This function is called to read the SLI3 device error attention registers
10096 * for possible error attention events. The caller must hold the hostlock
10097 * with spin_lock_irq().
10099 * This function returns 1 when there is Error Attention in the Host Attention
10100 * Register and returns 0 otherwise.
10103 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10107 /* Read chip Host Attention (HA) register */
10108 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10111 if (ha_copy
& HA_ERATT
) {
10112 /* Read host status register to retrieve error event */
10113 if (lpfc_sli_read_hs(phba
))
10116 /* Check if there is a deferred error condition is active */
10117 if ((HS_FFER1
& phba
->work_hs
) &&
10118 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10119 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10120 phba
->hba_flag
|= DEFER_ERATT
;
10121 /* Clear all interrupt enable conditions */
10122 writel(0, phba
->HCregaddr
);
10123 readl(phba
->HCregaddr
);
10126 /* Set the driver HA work bitmap */
10127 phba
->work_ha
|= HA_ERATT
;
10128 /* Indicate polling handles this ERATT */
10129 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10135 /* Set the driver HS work bitmap */
10136 phba
->work_hs
|= UNPLUG_ERR
;
10137 /* Set the driver HA work bitmap */
10138 phba
->work_ha
|= HA_ERATT
;
10139 /* Indicate polling handles this ERATT */
10140 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10145 * lpfc_sli4_eratt_read - read sli-4 error attention events
10146 * @phba: Pointer to HBA context.
10148 * This function is called to read the SLI4 device error attention registers
10149 * for possible error attention events. The caller must hold the hostlock
10150 * with spin_lock_irq().
10152 * This function returns 1 when there is Error Attention in the Host Attention
10153 * Register and returns 0 otherwise.
10156 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10158 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10159 uint32_t if_type
, portsmphr
;
10160 struct lpfc_register portstat_reg
;
10163 * For now, use the SLI4 device internal unrecoverable error
10164 * registers for error attention. This can be changed later.
10166 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10168 case LPFC_SLI_INTF_IF_TYPE_0
:
10169 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10171 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10173 phba
->work_hs
|= UNPLUG_ERR
;
10174 phba
->work_ha
|= HA_ERATT
;
10175 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10178 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10179 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10180 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10181 "1423 HBA Unrecoverable error: "
10182 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10183 "ue_mask_lo_reg=0x%x, "
10184 "ue_mask_hi_reg=0x%x\n",
10185 uerr_sta_lo
, uerr_sta_hi
,
10186 phba
->sli4_hba
.ue_mask_lo
,
10187 phba
->sli4_hba
.ue_mask_hi
);
10188 phba
->work_status
[0] = uerr_sta_lo
;
10189 phba
->work_status
[1] = uerr_sta_hi
;
10190 phba
->work_ha
|= HA_ERATT
;
10191 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10195 case LPFC_SLI_INTF_IF_TYPE_2
:
10196 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10197 &portstat_reg
.word0
) ||
10198 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10200 phba
->work_hs
|= UNPLUG_ERR
;
10201 phba
->work_ha
|= HA_ERATT
;
10202 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10205 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10206 phba
->work_status
[0] =
10207 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10208 phba
->work_status
[1] =
10209 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10210 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10211 "2885 Port Status Event: "
10212 "port status reg 0x%x, "
10213 "port smphr reg 0x%x, "
10214 "error 1=0x%x, error 2=0x%x\n",
10215 portstat_reg
.word0
,
10217 phba
->work_status
[0],
10218 phba
->work_status
[1]);
10219 phba
->work_ha
|= HA_ERATT
;
10220 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10224 case LPFC_SLI_INTF_IF_TYPE_1
:
10226 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10227 "2886 HBA Error Attention on unsupported "
10228 "if type %d.", if_type
);
10236 * lpfc_sli_check_eratt - check error attention events
10237 * @phba: Pointer to HBA context.
10239 * This function is called from timer soft interrupt context to check HBA's
10240 * error attention register bit for error attention events.
10242 * This function returns 1 when there is Error Attention in the Host Attention
10243 * Register and returns 0 otherwise.
10246 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10250 /* If somebody is waiting to handle an eratt, don't process it
10251 * here. The brdkill function will do this.
10253 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10256 /* Check if interrupt handler handles this ERATT */
10257 spin_lock_irq(&phba
->hbalock
);
10258 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10259 /* Interrupt handler has handled ERATT */
10260 spin_unlock_irq(&phba
->hbalock
);
10265 * If there is deferred error attention, do not check for error
10268 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10269 spin_unlock_irq(&phba
->hbalock
);
10273 /* If PCI channel is offline, don't process it */
10274 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10275 spin_unlock_irq(&phba
->hbalock
);
10279 switch (phba
->sli_rev
) {
10280 case LPFC_SLI_REV2
:
10281 case LPFC_SLI_REV3
:
10282 /* Read chip Host Attention (HA) register */
10283 ha_copy
= lpfc_sli_eratt_read(phba
);
10285 case LPFC_SLI_REV4
:
10286 /* Read device Uncoverable Error (UERR) registers */
10287 ha_copy
= lpfc_sli4_eratt_read(phba
);
10290 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10291 "0299 Invalid SLI revision (%d)\n",
10296 spin_unlock_irq(&phba
->hbalock
);
10302 * lpfc_intr_state_check - Check device state for interrupt handling
10303 * @phba: Pointer to HBA context.
10305 * This inline routine checks whether a device or its PCI slot is in a state
10306 * that the interrupt should be handled.
10308 * This function returns 0 if the device or the PCI slot is in a state that
10309 * interrupt should be handled, otherwise -EIO.
10312 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10314 /* If the pci channel is offline, ignore all the interrupts */
10315 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10318 /* Update device level interrupt statistics */
10319 phba
->sli
.slistat
.sli_intr
++;
10321 /* Ignore all interrupts during initialization. */
10322 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10329 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10330 * @irq: Interrupt number.
10331 * @dev_id: The device context pointer.
10333 * This function is directly called from the PCI layer as an interrupt
10334 * service routine when device with SLI-3 interface spec is enabled with
10335 * MSI-X multi-message interrupt mode and there are slow-path events in
10336 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10337 * interrupt mode, this function is called as part of the device-level
10338 * interrupt handler. When the PCI slot is in error recovery or the HBA
10339 * is undergoing initialization, the interrupt handler will not process
10340 * the interrupt. The link attention and ELS ring attention events are
10341 * handled by the worker thread. The interrupt handler signals the worker
10342 * thread and returns for these events. This function is called without
10343 * any lock held. It gets the hbalock to access and update SLI data
10346 * This function returns IRQ_HANDLED when interrupt is handled else it
10347 * returns IRQ_NONE.
10350 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10352 struct lpfc_hba
*phba
;
10353 uint32_t ha_copy
, hc_copy
;
10354 uint32_t work_ha_copy
;
10355 unsigned long status
;
10356 unsigned long iflag
;
10359 MAILBOX_t
*mbox
, *pmbox
;
10360 struct lpfc_vport
*vport
;
10361 struct lpfc_nodelist
*ndlp
;
10362 struct lpfc_dmabuf
*mp
;
10367 * Get the driver's phba structure from the dev_id and
10368 * assume the HBA is not interrupting.
10370 phba
= (struct lpfc_hba
*)dev_id
;
10372 if (unlikely(!phba
))
10376 * Stuff needs to be attented to when this function is invoked as an
10377 * individual interrupt handler in MSI-X multi-message interrupt mode
10379 if (phba
->intr_type
== MSIX
) {
10380 /* Check device state for handling interrupt */
10381 if (lpfc_intr_state_check(phba
))
10383 /* Need to read HA REG for slow-path events */
10384 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10385 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10387 /* If somebody is waiting to handle an eratt don't process it
10388 * here. The brdkill function will do this.
10390 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10391 ha_copy
&= ~HA_ERATT
;
10392 /* Check the need for handling ERATT in interrupt handler */
10393 if (ha_copy
& HA_ERATT
) {
10394 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10395 /* ERATT polling has handled ERATT */
10396 ha_copy
&= ~HA_ERATT
;
10398 /* Indicate interrupt handler handles ERATT */
10399 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10403 * If there is deferred error attention, do not check for any
10406 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10407 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10411 /* Clear up only attention source related to slow-path */
10412 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10415 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10416 HC_LAINT_ENA
| HC_ERINT_ENA
),
10418 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10420 writel(hc_copy
, phba
->HCregaddr
);
10421 readl(phba
->HAregaddr
); /* flush */
10422 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10424 ha_copy
= phba
->ha_copy
;
10426 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10428 if (work_ha_copy
) {
10429 if (work_ha_copy
& HA_LATT
) {
10430 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10432 * Turn off Link Attention interrupts
10433 * until CLEAR_LA done
10435 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10436 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10437 if (lpfc_readl(phba
->HCregaddr
, &control
))
10439 control
&= ~HC_LAINT_ENA
;
10440 writel(control
, phba
->HCregaddr
);
10441 readl(phba
->HCregaddr
); /* flush */
10442 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10445 work_ha_copy
&= ~HA_LATT
;
10448 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10450 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10451 * the only slow ring.
10453 status
= (work_ha_copy
&
10454 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10455 status
>>= (4*LPFC_ELS_RING
);
10456 if (status
& HA_RXMASK
) {
10457 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10458 if (lpfc_readl(phba
->HCregaddr
, &control
))
10461 lpfc_debugfs_slow_ring_trc(phba
,
10462 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10464 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10466 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10467 lpfc_debugfs_slow_ring_trc(phba
,
10468 "ISR Disable ring:"
10469 "pwork:x%x hawork:x%x wait:x%x",
10470 phba
->work_ha
, work_ha_copy
,
10471 (uint32_t)((unsigned long)
10472 &phba
->work_waitq
));
10475 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10476 writel(control
, phba
->HCregaddr
);
10477 readl(phba
->HCregaddr
); /* flush */
10480 lpfc_debugfs_slow_ring_trc(phba
,
10481 "ISR slow ring: pwork:"
10482 "x%x hawork:x%x wait:x%x",
10483 phba
->work_ha
, work_ha_copy
,
10484 (uint32_t)((unsigned long)
10485 &phba
->work_waitq
));
10487 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10490 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10491 if (work_ha_copy
& HA_ERATT
) {
10492 if (lpfc_sli_read_hs(phba
))
10495 * Check if there is a deferred error condition
10498 if ((HS_FFER1
& phba
->work_hs
) &&
10499 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10500 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10502 phba
->hba_flag
|= DEFER_ERATT
;
10503 /* Clear all interrupt enable conditions */
10504 writel(0, phba
->HCregaddr
);
10505 readl(phba
->HCregaddr
);
10509 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10510 pmb
= phba
->sli
.mbox_active
;
10511 pmbox
= &pmb
->u
.mb
;
10513 vport
= pmb
->vport
;
10515 /* First check out the status word */
10516 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10517 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10518 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10520 * Stray Mailbox Interrupt, mbxCommand <cmd>
10521 * mbxStatus <status>
10523 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10525 "(%d):0304 Stray Mailbox "
10526 "Interrupt mbxCommand x%x "
10528 (vport
? vport
->vpi
: 0),
10531 /* clear mailbox attention bit */
10532 work_ha_copy
&= ~HA_MBATT
;
10534 phba
->sli
.mbox_active
= NULL
;
10535 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10536 phba
->last_completion_time
= jiffies
;
10537 del_timer(&phba
->sli
.mbox_tmo
);
10538 if (pmb
->mbox_cmpl
) {
10539 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10541 if (pmb
->out_ext_byte_len
&&
10543 lpfc_sli_pcimem_bcopy(
10546 pmb
->out_ext_byte_len
);
10548 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10549 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10551 lpfc_debugfs_disc_trc(vport
,
10552 LPFC_DISC_TRC_MBOX_VPORT
,
10553 "MBOX dflt rpi: : "
10554 "status:x%x rpi:x%x",
10555 (uint32_t)pmbox
->mbxStatus
,
10556 pmbox
->un
.varWords
[0], 0);
10558 if (!pmbox
->mbxStatus
) {
10559 mp
= (struct lpfc_dmabuf
*)
10561 ndlp
= (struct lpfc_nodelist
*)
10564 /* Reg_LOGIN of dflt RPI was
10565 * successful. new lets get
10566 * rid of the RPI using the
10567 * same mbox buffer.
10569 lpfc_unreg_login(phba
,
10571 pmbox
->un
.varWords
[0],
10574 lpfc_mbx_cmpl_dflt_rpi
;
10575 pmb
->context1
= mp
;
10576 pmb
->context2
= ndlp
;
10577 pmb
->vport
= vport
;
10578 rc
= lpfc_sli_issue_mbox(phba
,
10581 if (rc
!= MBX_BUSY
)
10582 lpfc_printf_log(phba
,
10584 LOG_MBOX
| LOG_SLI
,
10585 "0350 rc should have"
10586 "been MBX_BUSY\n");
10587 if (rc
!= MBX_NOT_FINISHED
)
10588 goto send_current_mbox
;
10592 &phba
->pport
->work_port_lock
,
10594 phba
->pport
->work_port_events
&=
10596 spin_unlock_irqrestore(
10597 &phba
->pport
->work_port_lock
,
10599 lpfc_mbox_cmpl_put(phba
, pmb
);
10602 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10604 if ((work_ha_copy
& HA_MBATT
) &&
10605 (phba
->sli
.mbox_active
== NULL
)) {
10607 /* Process next mailbox command if there is one */
10609 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10611 } while (rc
== MBX_NOT_FINISHED
);
10612 if (rc
!= MBX_SUCCESS
)
10613 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10614 LOG_SLI
, "0349 rc should be "
10618 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10619 phba
->work_ha
|= work_ha_copy
;
10620 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10621 lpfc_worker_wake_up(phba
);
10623 return IRQ_HANDLED
;
10625 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10626 return IRQ_HANDLED
;
10628 } /* lpfc_sli_sp_intr_handler */
10631 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10632 * @irq: Interrupt number.
10633 * @dev_id: The device context pointer.
10635 * This function is directly called from the PCI layer as an interrupt
10636 * service routine when device with SLI-3 interface spec is enabled with
10637 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10638 * ring event in the HBA. However, when the device is enabled with either
10639 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10640 * device-level interrupt handler. When the PCI slot is in error recovery
10641 * or the HBA is undergoing initialization, the interrupt handler will not
10642 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10643 * the intrrupt context. This function is called without any lock held.
10644 * It gets the hbalock to access and update SLI data structures.
10646 * This function returns IRQ_HANDLED when interrupt is handled else it
10647 * returns IRQ_NONE.
10650 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10652 struct lpfc_hba
*phba
;
10654 unsigned long status
;
10655 unsigned long iflag
;
10657 /* Get the driver's phba structure from the dev_id and
10658 * assume the HBA is not interrupting.
10660 phba
= (struct lpfc_hba
*) dev_id
;
10662 if (unlikely(!phba
))
10666 * Stuff needs to be attented to when this function is invoked as an
10667 * individual interrupt handler in MSI-X multi-message interrupt mode
10669 if (phba
->intr_type
== MSIX
) {
10670 /* Check device state for handling interrupt */
10671 if (lpfc_intr_state_check(phba
))
10673 /* Need to read HA REG for FCP ring and other ring events */
10674 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10675 return IRQ_HANDLED
;
10676 /* Clear up only attention source related to fast-path */
10677 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10679 * If there is deferred error attention, do not check for
10682 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10683 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10686 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10688 readl(phba
->HAregaddr
); /* flush */
10689 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10691 ha_copy
= phba
->ha_copy
;
10694 * Process all events on FCP ring. Take the optimized path for FCP IO.
10696 ha_copy
&= ~(phba
->work_ha_mask
);
10698 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10699 status
>>= (4*LPFC_FCP_RING
);
10700 if (status
& HA_RXMASK
)
10701 lpfc_sli_handle_fast_ring_event(phba
,
10702 &phba
->sli
.ring
[LPFC_FCP_RING
],
10705 if (phba
->cfg_multi_ring_support
== 2) {
10707 * Process all events on extra ring. Take the optimized path
10708 * for extra ring IO.
10710 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10711 status
>>= (4*LPFC_EXTRA_RING
);
10712 if (status
& HA_RXMASK
) {
10713 lpfc_sli_handle_fast_ring_event(phba
,
10714 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
10718 return IRQ_HANDLED
;
10719 } /* lpfc_sli_fp_intr_handler */
10722 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10723 * @irq: Interrupt number.
10724 * @dev_id: The device context pointer.
10726 * This function is the HBA device-level interrupt handler to device with
10727 * SLI-3 interface spec, called from the PCI layer when either MSI or
10728 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10729 * requires driver attention. This function invokes the slow-path interrupt
10730 * attention handling function and fast-path interrupt attention handling
10731 * function in turn to process the relevant HBA attention events. This
10732 * function is called without any lock held. It gets the hbalock to access
10733 * and update SLI data structures.
10735 * This function returns IRQ_HANDLED when interrupt is handled, else it
10736 * returns IRQ_NONE.
10739 lpfc_sli_intr_handler(int irq
, void *dev_id
)
10741 struct lpfc_hba
*phba
;
10742 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10743 unsigned long status1
, status2
;
10747 * Get the driver's phba structure from the dev_id and
10748 * assume the HBA is not interrupting.
10750 phba
= (struct lpfc_hba
*) dev_id
;
10752 if (unlikely(!phba
))
10755 /* Check device state for handling interrupt */
10756 if (lpfc_intr_state_check(phba
))
10759 spin_lock(&phba
->hbalock
);
10760 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
10761 spin_unlock(&phba
->hbalock
);
10762 return IRQ_HANDLED
;
10765 if (unlikely(!phba
->ha_copy
)) {
10766 spin_unlock(&phba
->hbalock
);
10768 } else if (phba
->ha_copy
& HA_ERATT
) {
10769 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10770 /* ERATT polling has handled ERATT */
10771 phba
->ha_copy
&= ~HA_ERATT
;
10773 /* Indicate interrupt handler handles ERATT */
10774 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10778 * If there is deferred error attention, do not check for any interrupt.
10780 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10781 spin_unlock(&phba
->hbalock
);
10785 /* Clear attention sources except link and error attentions */
10786 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
10787 spin_unlock(&phba
->hbalock
);
10788 return IRQ_HANDLED
;
10790 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
10791 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
10793 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
10794 writel(hc_copy
, phba
->HCregaddr
);
10795 readl(phba
->HAregaddr
); /* flush */
10796 spin_unlock(&phba
->hbalock
);
10799 * Invokes slow-path host attention interrupt handling as appropriate.
10802 /* status of events with mailbox and link attention */
10803 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
10805 /* status of events with ELS ring */
10806 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10807 status2
>>= (4*LPFC_ELS_RING
);
10809 if (status1
|| (status2
& HA_RXMASK
))
10810 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
10812 sp_irq_rc
= IRQ_NONE
;
10815 * Invoke fast-path host attention interrupt handling as appropriate.
10818 /* status of events with FCP ring */
10819 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10820 status1
>>= (4*LPFC_FCP_RING
);
10822 /* status of events with extra ring */
10823 if (phba
->cfg_multi_ring_support
== 2) {
10824 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10825 status2
>>= (4*LPFC_EXTRA_RING
);
10829 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
10830 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
10832 fp_irq_rc
= IRQ_NONE
;
10834 /* Return device-level interrupt handling status */
10835 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
10836 } /* lpfc_sli_intr_handler */
10839 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10840 * @phba: pointer to lpfc hba data structure.
10842 * This routine is invoked by the worker thread to process all the pending
10843 * SLI4 FCP abort XRI events.
10845 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
10847 struct lpfc_cq_event
*cq_event
;
10849 /* First, declare the fcp xri abort event has been handled */
10850 spin_lock_irq(&phba
->hbalock
);
10851 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
10852 spin_unlock_irq(&phba
->hbalock
);
10853 /* Now, handle all the fcp xri abort events */
10854 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
10855 /* Get the first event from the head of the event queue */
10856 spin_lock_irq(&phba
->hbalock
);
10857 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10858 cq_event
, struct lpfc_cq_event
, list
);
10859 spin_unlock_irq(&phba
->hbalock
);
10860 /* Notify aborted XRI for FCP work queue */
10861 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10862 /* Free the event processed back to the free pool */
10863 lpfc_sli4_cq_event_release(phba
, cq_event
);
10868 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10869 * @phba: pointer to lpfc hba data structure.
10871 * This routine is invoked by the worker thread to process all the pending
10872 * SLI4 els abort xri events.
10874 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
10876 struct lpfc_cq_event
*cq_event
;
10878 /* First, declare the els xri abort event has been handled */
10879 spin_lock_irq(&phba
->hbalock
);
10880 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
10881 spin_unlock_irq(&phba
->hbalock
);
10882 /* Now, handle all the els xri abort events */
10883 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
10884 /* Get the first event from the head of the event queue */
10885 spin_lock_irq(&phba
->hbalock
);
10886 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10887 cq_event
, struct lpfc_cq_event
, list
);
10888 spin_unlock_irq(&phba
->hbalock
);
10889 /* Notify aborted XRI for ELS work queue */
10890 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10891 /* Free the event processed back to the free pool */
10892 lpfc_sli4_cq_event_release(phba
, cq_event
);
10897 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10898 * @phba: pointer to lpfc hba data structure
10899 * @pIocbIn: pointer to the rspiocbq
10900 * @pIocbOut: pointer to the cmdiocbq
10901 * @wcqe: pointer to the complete wcqe
10903 * This routine transfers the fields of a command iocbq to a response iocbq
10904 * by copying all the IOCB fields from command iocbq and transferring the
10905 * completion status information from the complete wcqe.
10908 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
10909 struct lpfc_iocbq
*pIocbIn
,
10910 struct lpfc_iocbq
*pIocbOut
,
10911 struct lpfc_wcqe_complete
*wcqe
)
10913 unsigned long iflags
;
10915 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
10917 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
10918 sizeof(struct lpfc_iocbq
) - offset
);
10919 /* Map WCQE parameters into irspiocb parameters */
10920 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
10921 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
10922 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
10923 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
10924 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
10925 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
10926 wcqe
->total_data_placed
;
10928 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10930 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10931 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
10934 /* Convert BG errors for completion status */
10935 if (status
== CQE_STATUS_DI_ERROR
) {
10936 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
10938 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
10939 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
10941 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
10943 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
10944 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
10945 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10946 BGS_GUARD_ERR_MASK
;
10947 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
10948 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10949 BGS_APPTAG_ERR_MASK
;
10950 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
10951 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10952 BGS_REFTAG_ERR_MASK
;
10954 /* Check to see if there was any good data before the error */
10955 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
10956 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10957 BGS_HI_WATER_MARK_PRESENT_MASK
;
10958 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
10959 wcqe
->total_data_placed
;
10963 * Set ALL the error bits to indicate we don't know what
10964 * type of error it is.
10966 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
10967 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10968 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
10969 BGS_GUARD_ERR_MASK
);
10972 /* Pick up HBA exchange busy condition */
10973 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
10974 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10975 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
10976 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10981 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
10982 * @phba: Pointer to HBA context object.
10983 * @wcqe: Pointer to work-queue completion queue entry.
10985 * This routine handles an ELS work-queue completion event and construct
10986 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
10987 * discovery engine to handle.
10989 * Return: Pointer to the receive IOCBQ, NULL otherwise.
10991 static struct lpfc_iocbq
*
10992 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
10993 struct lpfc_iocbq
*irspiocbq
)
10995 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10996 struct lpfc_iocbq
*cmdiocbq
;
10997 struct lpfc_wcqe_complete
*wcqe
;
10998 unsigned long iflags
;
11000 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
11001 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11002 pring
->stats
.iocb_event
++;
11003 /* Look up the ELS command IOCB and create pseudo response IOCB */
11004 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11005 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11006 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11008 if (unlikely(!cmdiocbq
)) {
11009 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11010 "0386 ELS complete with no corresponding "
11011 "cmdiocb: iotag (%d)\n",
11012 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11013 lpfc_sli_release_iocbq(phba
, irspiocbq
);
11017 /* Fake the irspiocbq and copy necessary response information */
11018 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
11024 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11025 * @phba: Pointer to HBA context object.
11026 * @cqe: Pointer to mailbox completion queue entry.
11028 * This routine process a mailbox completion queue entry with asynchrous
11031 * Return: true if work posted to worker thread, otherwise false.
11034 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11036 struct lpfc_cq_event
*cq_event
;
11037 unsigned long iflags
;
11039 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11040 "0392 Async Event: word0:x%x, word1:x%x, "
11041 "word2:x%x, word3:x%x\n", mcqe
->word0
,
11042 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
11044 /* Allocate a new internal CQ_EVENT entry */
11045 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11047 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11048 "0394 Failed to allocate CQ_EVENT entry\n");
11052 /* Move the CQE into an asynchronous event entry */
11053 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
11054 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11055 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
11056 /* Set the async event flag */
11057 phba
->hba_flag
|= ASYNC_EVENT
;
11058 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11064 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11065 * @phba: Pointer to HBA context object.
11066 * @cqe: Pointer to mailbox completion queue entry.
11068 * This routine process a mailbox completion queue entry with mailbox
11069 * completion event.
11071 * Return: true if work posted to worker thread, otherwise false.
11074 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11076 uint32_t mcqe_status
;
11077 MAILBOX_t
*mbox
, *pmbox
;
11078 struct lpfc_mqe
*mqe
;
11079 struct lpfc_vport
*vport
;
11080 struct lpfc_nodelist
*ndlp
;
11081 struct lpfc_dmabuf
*mp
;
11082 unsigned long iflags
;
11084 bool workposted
= false;
11087 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11088 if (!bf_get(lpfc_trailer_completed
, mcqe
))
11089 goto out_no_mqe_complete
;
11091 /* Get the reference to the active mbox command */
11092 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11093 pmb
= phba
->sli
.mbox_active
;
11094 if (unlikely(!pmb
)) {
11095 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11096 "1832 No pending MBOX command to handle\n");
11097 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11098 goto out_no_mqe_complete
;
11100 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11102 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11104 vport
= pmb
->vport
;
11106 /* Reset heartbeat timer */
11107 phba
->last_completion_time
= jiffies
;
11108 del_timer(&phba
->sli
.mbox_tmo
);
11110 /* Move mbox data to caller's mailbox region, do endian swapping */
11111 if (pmb
->mbox_cmpl
&& mbox
)
11112 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11115 * For mcqe errors, conditionally move a modified error code to
11116 * the mbox so that the error will not be missed.
11118 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11119 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11120 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11121 bf_set(lpfc_mqe_status
, mqe
,
11122 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11124 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11125 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11126 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11127 "MBOX dflt rpi: status:x%x rpi:x%x",
11129 pmbox
->un
.varWords
[0], 0);
11130 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11131 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11132 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11133 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11134 * RID of the PPI using the same mbox buffer.
11136 lpfc_unreg_login(phba
, vport
->vpi
,
11137 pmbox
->un
.varWords
[0], pmb
);
11138 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11139 pmb
->context1
= mp
;
11140 pmb
->context2
= ndlp
;
11141 pmb
->vport
= vport
;
11142 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11143 if (rc
!= MBX_BUSY
)
11144 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11145 LOG_SLI
, "0385 rc should "
11146 "have been MBX_BUSY\n");
11147 if (rc
!= MBX_NOT_FINISHED
)
11148 goto send_current_mbox
;
11151 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11152 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11153 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11155 /* There is mailbox completion work to do */
11156 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11157 __lpfc_mbox_cmpl_put(phba
, pmb
);
11158 phba
->work_ha
|= HA_MBATT
;
11159 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11163 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11164 /* Release the mailbox command posting token */
11165 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11166 /* Setting active mailbox pointer need to be in sync to flag clear */
11167 phba
->sli
.mbox_active
= NULL
;
11168 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11169 /* Wake up worker thread to post the next pending mailbox command */
11170 lpfc_worker_wake_up(phba
);
11171 out_no_mqe_complete
:
11172 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11173 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
11178 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11179 * @phba: Pointer to HBA context object.
11180 * @cqe: Pointer to mailbox completion queue entry.
11182 * This routine process a mailbox completion queue entry, it invokes the
11183 * proper mailbox complete handling or asynchrous event handling routine
11184 * according to the MCQE's async bit.
11186 * Return: true if work posted to worker thread, otherwise false.
11189 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
11191 struct lpfc_mcqe mcqe
;
11194 /* Copy the mailbox MCQE and convert endian order as needed */
11195 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
11197 /* Invoke the proper event handling routine */
11198 if (!bf_get(lpfc_trailer_async
, &mcqe
))
11199 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
11201 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
11206 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11207 * @phba: Pointer to HBA context object.
11208 * @cq: Pointer to associated CQ
11209 * @wcqe: Pointer to work-queue completion queue entry.
11211 * This routine handles an ELS work-queue completion event.
11213 * Return: true if work posted to worker thread, otherwise false.
11216 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11217 struct lpfc_wcqe_complete
*wcqe
)
11219 struct lpfc_iocbq
*irspiocbq
;
11220 unsigned long iflags
;
11221 struct lpfc_sli_ring
*pring
= cq
->pring
;
11223 /* Get an irspiocbq for later ELS response processing use */
11224 irspiocbq
= lpfc_sli_get_iocbq(phba
);
11226 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11227 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11228 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
11229 pring
->txq_cnt
, phba
->iocb_cnt
,
11230 phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
,
11231 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
);
11235 /* Save off the slow-path queue event for work thread to process */
11236 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
11237 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11238 list_add_tail(&irspiocbq
->cq_event
.list
,
11239 &phba
->sli4_hba
.sp_queue_event
);
11240 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11241 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11247 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11248 * @phba: Pointer to HBA context object.
11249 * @wcqe: Pointer to work-queue completion queue entry.
11251 * This routine handles slow-path WQ entry comsumed event by invoking the
11252 * proper WQ release routine to the slow-path WQ.
11255 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
11256 struct lpfc_wcqe_release
*wcqe
)
11258 /* sanity check on queue memory */
11259 if (unlikely(!phba
->sli4_hba
.els_wq
))
11261 /* Check for the slow-path ELS work queue */
11262 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
11263 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
11264 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11266 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11267 "2579 Slow-path wqe consume event carries "
11268 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11269 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
11270 phba
->sli4_hba
.els_wq
->queue_id
);
11274 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11275 * @phba: Pointer to HBA context object.
11276 * @cq: Pointer to a WQ completion queue.
11277 * @wcqe: Pointer to work-queue completion queue entry.
11279 * This routine handles an XRI abort event.
11281 * Return: true if work posted to worker thread, otherwise false.
11284 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
11285 struct lpfc_queue
*cq
,
11286 struct sli4_wcqe_xri_aborted
*wcqe
)
11288 bool workposted
= false;
11289 struct lpfc_cq_event
*cq_event
;
11290 unsigned long iflags
;
11292 /* Allocate a new internal CQ_EVENT entry */
11293 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11295 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11296 "0602 Failed to allocate CQ_EVENT entry\n");
11300 /* Move the CQE into the proper xri abort event list */
11301 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11302 switch (cq
->subtype
) {
11304 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11305 list_add_tail(&cq_event
->list
,
11306 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11307 /* Set the fcp xri abort event flag */
11308 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11309 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11313 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11314 list_add_tail(&cq_event
->list
,
11315 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11316 /* Set the els xri abort event flag */
11317 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11318 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11322 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11323 "0603 Invalid work queue CQE subtype (x%x)\n",
11325 workposted
= false;
11332 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11333 * @phba: Pointer to HBA context object.
11334 * @rcqe: Pointer to receive-queue completion queue entry.
11336 * This routine process a receive-queue completion queue entry.
11338 * Return: true if work posted to worker thread, otherwise false.
11341 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11343 bool workposted
= false;
11344 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11345 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11346 struct hbq_dmabuf
*dma_buf
;
11347 uint32_t status
, rq_id
;
11348 unsigned long iflags
;
11350 /* sanity check on queue memory */
11351 if (unlikely(!hrq
) || unlikely(!drq
))
11354 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11355 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11357 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11358 if (rq_id
!= hrq
->queue_id
)
11361 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11363 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11364 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11365 "2537 Receive Frame Truncated!!\n");
11366 hrq
->RQ_buf_trunc
++;
11367 case FC_STATUS_RQ_SUCCESS
:
11368 lpfc_sli4_rq_release(hrq
, drq
);
11369 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11370 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11372 hrq
->RQ_no_buf_found
++;
11373 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11377 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11378 /* save off the frame for the word thread to process */
11379 list_add_tail(&dma_buf
->cq_event
.list
,
11380 &phba
->sli4_hba
.sp_queue_event
);
11381 /* Frame received */
11382 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11383 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11386 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11387 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11388 hrq
->RQ_no_posted_buf
++;
11389 /* Post more buffers if possible */
11390 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11391 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11392 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11401 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11402 * @phba: Pointer to HBA context object.
11403 * @cq: Pointer to the completion queue.
11404 * @wcqe: Pointer to a completion queue entry.
11406 * This routine process a slow-path work-queue or receive queue completion queue
11409 * Return: true if work posted to worker thread, otherwise false.
11412 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11413 struct lpfc_cqe
*cqe
)
11415 struct lpfc_cqe cqevt
;
11416 bool workposted
= false;
11418 /* Copy the work queue CQE and convert endian order if needed */
11419 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11421 /* Check and process for different type of WCQE and dispatch */
11422 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11423 case CQE_CODE_COMPL_WQE
:
11424 /* Process the WQ/RQ complete event */
11425 phba
->last_completion_time
= jiffies
;
11426 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
11427 (struct lpfc_wcqe_complete
*)&cqevt
);
11429 case CQE_CODE_RELEASE_WQE
:
11430 /* Process the WQ release event */
11431 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11432 (struct lpfc_wcqe_release
*)&cqevt
);
11434 case CQE_CODE_XRI_ABORTED
:
11435 /* Process the WQ XRI abort event */
11436 phba
->last_completion_time
= jiffies
;
11437 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11438 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11440 case CQE_CODE_RECEIVE
:
11441 case CQE_CODE_RECEIVE_V1
:
11442 /* Process the RQ event */
11443 phba
->last_completion_time
= jiffies
;
11444 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11445 (struct lpfc_rcqe
*)&cqevt
);
11448 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11449 "0388 Not a valid WCQE code: x%x\n",
11450 bf_get(lpfc_cqe_code
, &cqevt
));
11457 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11458 * @phba: Pointer to HBA context object.
11459 * @eqe: Pointer to fast-path event queue entry.
11461 * This routine process a event queue entry from the slow-path event queue.
11462 * It will check the MajorCode and MinorCode to determine this is for a
11463 * completion event on a completion queue, if not, an error shall be logged
11464 * and just return. Otherwise, it will get to the corresponding completion
11465 * queue and process all the entries on that completion queue, rearm the
11466 * completion queue, and then return.
11470 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11471 struct lpfc_queue
*speq
)
11473 struct lpfc_queue
*cq
= NULL
, *childq
;
11474 struct lpfc_cqe
*cqe
;
11475 bool workposted
= false;
11479 /* Get the reference to the corresponding CQ */
11480 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11482 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11483 if (childq
->queue_id
== cqid
) {
11488 if (unlikely(!cq
)) {
11489 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11490 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11491 "0365 Slow-path CQ identifier "
11492 "(%d) does not exist\n", cqid
);
11496 /* Process all the entries to the CQ */
11497 switch (cq
->type
) {
11499 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11500 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11501 if (!(++ecount
% cq
->entry_repost
))
11502 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11507 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11508 if (cq
->subtype
== LPFC_FCP
)
11509 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11512 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11514 if (!(++ecount
% cq
->entry_repost
))
11515 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11518 /* Track the max number of CQEs processed in 1 EQ */
11519 if (ecount
> cq
->CQ_max_cqe
)
11520 cq
->CQ_max_cqe
= ecount
;
11523 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11524 "0370 Invalid completion queue type (%d)\n",
11529 /* Catch the no cq entry condition, log an error */
11530 if (unlikely(ecount
== 0))
11531 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11532 "0371 No entry from the CQ: identifier "
11533 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11535 /* In any case, flash and re-arm the RCQ */
11536 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11538 /* wake up worker thread if there are works to be done */
11540 lpfc_worker_wake_up(phba
);
11544 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11545 * @phba: Pointer to HBA context object.
11546 * @cq: Pointer to associated CQ
11547 * @wcqe: Pointer to work-queue completion queue entry.
11549 * This routine process a fast-path work queue completion entry from fast-path
11550 * event queue for FCP command response completion.
11553 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11554 struct lpfc_wcqe_complete
*wcqe
)
11556 struct lpfc_sli_ring
*pring
= cq
->pring
;
11557 struct lpfc_iocbq
*cmdiocbq
;
11558 struct lpfc_iocbq irspiocbq
;
11559 unsigned long iflags
;
11561 /* Check for response status */
11562 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11563 /* If resource errors reported from HBA, reduce queue
11564 * depth of the SCSI device.
11566 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11567 IOSTAT_LOCAL_REJECT
) &&
11568 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
11569 phba
->lpfc_rampdown_queue_depth(phba
);
11571 /* Log the error status */
11572 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11573 "0373 FCP complete error: status=x%x, "
11574 "hw_status=x%x, total_data_specified=%d, "
11575 "parameter=x%x, word3=x%x\n",
11576 bf_get(lpfc_wcqe_c_status
, wcqe
),
11577 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11578 wcqe
->total_data_placed
, wcqe
->parameter
,
11582 /* Look up the FCP command IOCB and create pseudo response IOCB */
11583 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11584 pring
->stats
.iocb_event
++;
11585 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11586 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11587 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11588 if (unlikely(!cmdiocbq
)) {
11589 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11590 "0374 FCP complete with no corresponding "
11591 "cmdiocb: iotag (%d)\n",
11592 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11595 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11596 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11597 "0375 FCP cmdiocb not callback function "
11599 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11603 /* Fake the irspiocb and copy necessary response information */
11604 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11606 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11607 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11608 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11609 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11612 /* Pass the cmd_iocb and the rsp state to the upper layer */
11613 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11617 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11618 * @phba: Pointer to HBA context object.
11619 * @cq: Pointer to completion queue.
11620 * @wcqe: Pointer to work-queue completion queue entry.
11622 * This routine handles an fast-path WQ entry comsumed event by invoking the
11623 * proper WQ release routine to the slow-path WQ.
11626 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11627 struct lpfc_wcqe_release
*wcqe
)
11629 struct lpfc_queue
*childwq
;
11630 bool wqid_matched
= false;
11633 /* Check for fast-path FCP work queue release */
11634 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11635 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11636 if (childwq
->queue_id
== fcp_wqid
) {
11637 lpfc_sli4_wq_release(childwq
,
11638 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11639 wqid_matched
= true;
11643 /* Report warning log message if no match found */
11644 if (wqid_matched
!= true)
11645 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11646 "2580 Fast-path wqe consume event carries "
11647 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11651 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11652 * @cq: Pointer to the completion queue.
11653 * @eqe: Pointer to fast-path completion queue entry.
11655 * This routine process a fast-path work queue completion entry from fast-path
11656 * event queue for FCP command response completion.
11659 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11660 struct lpfc_cqe
*cqe
)
11662 struct lpfc_wcqe_release wcqe
;
11663 bool workposted
= false;
11665 /* Copy the work queue CQE and convert endian order if needed */
11666 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
11668 /* Check and process for different type of WCQE and dispatch */
11669 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
11670 case CQE_CODE_COMPL_WQE
:
11672 /* Process the WQ complete event */
11673 phba
->last_completion_time
= jiffies
;
11674 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
11675 (struct lpfc_wcqe_complete
*)&wcqe
);
11677 case CQE_CODE_RELEASE_WQE
:
11678 cq
->CQ_release_wqe
++;
11679 /* Process the WQ release event */
11680 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
11681 (struct lpfc_wcqe_release
*)&wcqe
);
11683 case CQE_CODE_XRI_ABORTED
:
11684 cq
->CQ_xri_aborted
++;
11685 /* Process the WQ XRI abort event */
11686 phba
->last_completion_time
= jiffies
;
11687 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11688 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
11691 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11692 "0144 Not a valid WCQE code: x%x\n",
11693 bf_get(lpfc_wcqe_c_code
, &wcqe
));
11700 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
11701 * @phba: Pointer to HBA context object.
11702 * @eqe: Pointer to fast-path event queue entry.
11704 * This routine process a event queue entry from the fast-path event queue.
11705 * It will check the MajorCode and MinorCode to determine this is for a
11706 * completion event on a completion queue, if not, an error shall be logged
11707 * and just return. Otherwise, it will get to the corresponding completion
11708 * queue and process all the entries on the completion queue, rearm the
11709 * completion queue, and then return.
11712 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11715 struct lpfc_queue
*cq
;
11716 struct lpfc_cqe
*cqe
;
11717 bool workposted
= false;
11721 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
11722 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11723 "0366 Not a valid completion "
11724 "event: majorcode=x%x, minorcode=x%x\n",
11725 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11726 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11730 /* Get the reference to the corresponding CQ */
11731 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11733 /* Check if this is a Slow path event */
11734 if (unlikely(cqid
!= phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
11735 lpfc_sli4_sp_handle_eqe(phba
, eqe
,
11736 phba
->sli4_hba
.hba_eq
[qidx
]);
11740 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
11741 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11742 "3146 Fast-path completion queues "
11743 "does not exist\n");
11746 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
11747 if (unlikely(!cq
)) {
11748 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11749 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11750 "0367 Fast-path completion queue "
11751 "(%d) does not exist\n", qidx
);
11755 if (unlikely(cqid
!= cq
->queue_id
)) {
11756 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11757 "0368 Miss-matched fast-path completion "
11758 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11759 cqid
, cq
->queue_id
);
11763 /* Process all the entries to the CQ */
11764 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11765 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
11766 if (!(++ecount
% cq
->entry_repost
))
11767 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11770 /* Track the max number of CQEs processed in 1 EQ */
11771 if (ecount
> cq
->CQ_max_cqe
)
11772 cq
->CQ_max_cqe
= ecount
;
11774 /* Catch the no cq entry condition */
11775 if (unlikely(ecount
== 0))
11776 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11777 "0369 No entry from fast-path completion "
11778 "queue fcpcqid=%d\n", cq
->queue_id
);
11780 /* In any case, flash and re-arm the CQ */
11781 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11783 /* wake up worker thread if there are works to be done */
11785 lpfc_worker_wake_up(phba
);
11789 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
11791 struct lpfc_eqe
*eqe
;
11793 /* walk all the EQ entries and drop on the floor */
11794 while ((eqe
= lpfc_sli4_eq_get(eq
)))
11797 /* Clear and re-arm the EQ */
11798 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
11802 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
11803 * @irq: Interrupt number.
11804 * @dev_id: The device context pointer.
11806 * This function is directly called from the PCI layer as an interrupt
11807 * service routine when device with SLI-4 interface spec is enabled with
11808 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11809 * ring event in the HBA. However, when the device is enabled with either
11810 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11811 * device-level interrupt handler. When the PCI slot is in error recovery
11812 * or the HBA is undergoing initialization, the interrupt handler will not
11813 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11814 * the intrrupt context. This function is called without any lock held.
11815 * It gets the hbalock to access and update SLI data structures. Note that,
11816 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11817 * equal to that of FCP CQ index.
11819 * The link attention and ELS ring attention events are handled
11820 * by the worker thread. The interrupt handler signals the worker thread
11821 * and returns for these events. This function is called without any lock
11822 * held. It gets the hbalock to access and update SLI data structures.
11824 * This function returns IRQ_HANDLED when interrupt is handled else it
11825 * returns IRQ_NONE.
11828 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
11830 struct lpfc_hba
*phba
;
11831 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
11832 struct lpfc_queue
*fpeq
;
11833 struct lpfc_eqe
*eqe
;
11834 unsigned long iflag
;
11836 uint32_t fcp_eqidx
;
11838 /* Get the driver's phba structure from the dev_id */
11839 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
11840 phba
= fcp_eq_hdl
->phba
;
11841 fcp_eqidx
= fcp_eq_hdl
->idx
;
11843 if (unlikely(!phba
))
11845 if (unlikely(!phba
->sli4_hba
.hba_eq
))
11848 /* Get to the EQ struct associated with this vector */
11849 fpeq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
11850 if (unlikely(!fpeq
))
11853 /* Check device state for handling interrupt */
11854 if (unlikely(lpfc_intr_state_check(phba
))) {
11855 fpeq
->EQ_badstate
++;
11856 /* Check again for link_state with lock held */
11857 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11858 if (phba
->link_state
< LPFC_LINK_DOWN
)
11859 /* Flush, clear interrupt, and rearm the EQ */
11860 lpfc_sli4_eq_flush(phba
, fpeq
);
11861 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11866 * Process all the event on FCP fast-path EQ
11868 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
11869 lpfc_sli4_hba_handle_eqe(phba
, eqe
, fcp_eqidx
);
11870 if (!(++ecount
% fpeq
->entry_repost
))
11871 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
11872 fpeq
->EQ_processed
++;
11875 /* Track the max number of EQEs processed in 1 intr */
11876 if (ecount
> fpeq
->EQ_max_eqe
)
11877 fpeq
->EQ_max_eqe
= ecount
;
11879 /* Always clear and re-arm the fast-path EQ */
11880 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
11882 if (unlikely(ecount
== 0)) {
11883 fpeq
->EQ_no_entry
++;
11884 if (phba
->intr_type
== MSIX
)
11885 /* MSI-X treated interrupt served as no EQ share INT */
11886 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11887 "0358 MSI-X interrupt with no EQE\n");
11889 /* Non MSI-X treated on interrupt as EQ share INT */
11893 return IRQ_HANDLED
;
11894 } /* lpfc_sli4_fp_intr_handler */
11897 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11898 * @irq: Interrupt number.
11899 * @dev_id: The device context pointer.
11901 * This function is the device-level interrupt handler to device with SLI-4
11902 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11903 * interrupt mode is enabled and there is an event in the HBA which requires
11904 * driver attention. This function invokes the slow-path interrupt attention
11905 * handling function and fast-path interrupt attention handling function in
11906 * turn to process the relevant HBA attention events. This function is called
11907 * without any lock held. It gets the hbalock to access and update SLI data
11910 * This function returns IRQ_HANDLED when interrupt is handled, else it
11911 * returns IRQ_NONE.
11914 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
11916 struct lpfc_hba
*phba
;
11917 irqreturn_t hba_irq_rc
;
11918 bool hba_handled
= false;
11919 uint32_t fcp_eqidx
;
11921 /* Get the driver's phba structure from the dev_id */
11922 phba
= (struct lpfc_hba
*)dev_id
;
11924 if (unlikely(!phba
))
11928 * Invoke fast-path host attention interrupt handling as appropriate.
11930 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
11931 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
11932 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
11933 if (hba_irq_rc
== IRQ_HANDLED
)
11934 hba_handled
|= true;
11937 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
11938 } /* lpfc_sli4_intr_handler */
11941 * lpfc_sli4_queue_free - free a queue structure and associated memory
11942 * @queue: The queue structure to free.
11944 * This function frees a queue structure and the DMAable memory used for
11945 * the host resident queue. This function must be called after destroying the
11946 * queue on the HBA.
11949 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
11951 struct lpfc_dmabuf
*dmabuf
;
11956 while (!list_empty(&queue
->page_list
)) {
11957 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
11959 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
11960 dmabuf
->virt
, dmabuf
->phys
);
11968 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
11969 * @phba: The HBA that this queue is being created on.
11970 * @entry_size: The size of each queue entry for this queue.
11971 * @entry count: The number of entries that this queue will handle.
11973 * This function allocates a queue structure and the DMAable memory used for
11974 * the host resident queue. This function must be called before creating the
11975 * queue on the HBA.
11977 struct lpfc_queue
*
11978 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
11979 uint32_t entry_count
)
11981 struct lpfc_queue
*queue
;
11982 struct lpfc_dmabuf
*dmabuf
;
11983 int x
, total_qe_count
;
11985 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11987 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11988 hw_page_size
= SLI4_PAGE_SIZE
;
11990 queue
= kzalloc(sizeof(struct lpfc_queue
) +
11991 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
11994 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
11995 hw_page_size
))/hw_page_size
;
11996 INIT_LIST_HEAD(&queue
->list
);
11997 INIT_LIST_HEAD(&queue
->page_list
);
11998 INIT_LIST_HEAD(&queue
->child_list
);
11999 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
12000 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
12003 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
12004 hw_page_size
, &dmabuf
->phys
,
12006 if (!dmabuf
->virt
) {
12010 memset(dmabuf
->virt
, 0, hw_page_size
);
12011 dmabuf
->buffer_tag
= x
;
12012 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
12013 /* initialize queue's entry array */
12014 dma_pointer
= dmabuf
->virt
;
12015 for (; total_qe_count
< entry_count
&&
12016 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
12017 total_qe_count
++, dma_pointer
+= entry_size
) {
12018 queue
->qe
[total_qe_count
].address
= dma_pointer
;
12021 queue
->entry_size
= entry_size
;
12022 queue
->entry_count
= entry_count
;
12025 * entry_repost is calculated based on the number of entries in the
12026 * queue. This works out except for RQs. If buffers are NOT initially
12027 * posted for every RQE, entry_repost should be adjusted accordingly.
12029 queue
->entry_repost
= (entry_count
>> 3);
12030 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
12031 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
12032 queue
->phba
= phba
;
12036 lpfc_sli4_queue_free(queue
);
12041 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
12042 * @phba: HBA structure that indicates port to create a queue on.
12043 * @startq: The starting FCP EQ to modify
12045 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
12047 * The @phba struct is used to send mailbox command to HBA. The @startq
12048 * is used to get the starting FCP EQ to change.
12049 * This function is asynchronous and will wait for the mailbox
12050 * command to finish before continuing.
12052 * On success this function will return a zero. If unable to allocate enough
12053 * memory this function will return -ENOMEM. If the queue create mailbox command
12054 * fails this function will return -ENXIO.
12057 lpfc_modify_fcp_eq_delay(struct lpfc_hba
*phba
, uint16_t startq
)
12059 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
12060 LPFC_MBOXQ_t
*mbox
;
12061 struct lpfc_queue
*eq
;
12062 int cnt
, rc
, length
, status
= 0;
12063 uint32_t shdr_status
, shdr_add_status
;
12065 union lpfc_sli4_cfg_shdr
*shdr
;
12068 if (startq
>= phba
->cfg_fcp_io_channel
)
12071 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12074 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
12075 sizeof(struct lpfc_sli4_cfg_mhdr
));
12076 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12077 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
12078 length
, LPFC_SLI4_MBX_EMBED
);
12079 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
12081 /* Calculate delay multiper from maximum interrupt per second */
12082 dmult
= phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
;
12083 dmult
= LPFC_DMULT_CONST
/dmult
- 1;
12086 for (fcp_eqidx
= startq
; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
12088 eq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12091 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
12092 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
12093 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
12095 if (cnt
>= LPFC_MAX_EQ_DELAY
)
12098 eq_delay
->u
.request
.num_eq
= cnt
;
12100 mbox
->vport
= phba
->pport
;
12101 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12102 mbox
->context1
= NULL
;
12103 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12104 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
12105 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12106 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12107 if (shdr_status
|| shdr_add_status
|| rc
) {
12108 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12109 "2512 MODIFY_EQ_DELAY mailbox failed with "
12110 "status x%x add_status x%x, mbx status x%x\n",
12111 shdr_status
, shdr_add_status
, rc
);
12114 mempool_free(mbox
, phba
->mbox_mem_pool
);
12119 * lpfc_eq_create - Create an Event Queue on the HBA
12120 * @phba: HBA structure that indicates port to create a queue on.
12121 * @eq: The queue structure to use to create the event queue.
12122 * @imax: The maximum interrupt per second limit.
12124 * This function creates an event queue, as detailed in @eq, on a port,
12125 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12127 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12128 * is used to get the entry count and entry size that are necessary to
12129 * determine the number of pages to allocate and use for this queue. This
12130 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12131 * event queue. This function is asynchronous and will wait for the mailbox
12132 * command to finish before continuing.
12134 * On success this function will return a zero. If unable to allocate enough
12135 * memory this function will return -ENOMEM. If the queue create mailbox command
12136 * fails this function will return -ENXIO.
12139 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
12141 struct lpfc_mbx_eq_create
*eq_create
;
12142 LPFC_MBOXQ_t
*mbox
;
12143 int rc
, length
, status
= 0;
12144 struct lpfc_dmabuf
*dmabuf
;
12145 uint32_t shdr_status
, shdr_add_status
;
12146 union lpfc_sli4_cfg_shdr
*shdr
;
12148 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12150 /* sanity check on queue memory */
12153 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12154 hw_page_size
= SLI4_PAGE_SIZE
;
12156 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12159 length
= (sizeof(struct lpfc_mbx_eq_create
) -
12160 sizeof(struct lpfc_sli4_cfg_mhdr
));
12161 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12162 LPFC_MBOX_OPCODE_EQ_CREATE
,
12163 length
, LPFC_SLI4_MBX_EMBED
);
12164 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
12165 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
12167 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
12169 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
12170 /* Calculate delay multiper from maximum interrupt per second */
12171 dmult
= LPFC_DMULT_CONST
/imax
- 1;
12172 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
12174 switch (eq
->entry_count
) {
12176 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12177 "0360 Unsupported EQ count. (%d)\n",
12179 if (eq
->entry_count
< 256)
12181 /* otherwise default to smallest count (drop through) */
12183 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12187 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12191 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12195 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12199 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12203 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
12204 memset(dmabuf
->virt
, 0, hw_page_size
);
12205 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12206 putPaddrLow(dmabuf
->phys
);
12207 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12208 putPaddrHigh(dmabuf
->phys
);
12210 mbox
->vport
= phba
->pport
;
12211 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12212 mbox
->context1
= NULL
;
12213 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12214 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
12215 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12216 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12217 if (shdr_status
|| shdr_add_status
|| rc
) {
12218 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12219 "2500 EQ_CREATE mailbox failed with "
12220 "status x%x add_status x%x, mbx status x%x\n",
12221 shdr_status
, shdr_add_status
, rc
);
12224 eq
->type
= LPFC_EQ
;
12225 eq
->subtype
= LPFC_NONE
;
12226 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
12227 if (eq
->queue_id
== 0xFFFF)
12229 eq
->host_index
= 0;
12232 mempool_free(mbox
, phba
->mbox_mem_pool
);
12237 * lpfc_cq_create - Create a Completion Queue on the HBA
12238 * @phba: HBA structure that indicates port to create a queue on.
12239 * @cq: The queue structure to use to create the completion queue.
12240 * @eq: The event queue to bind this completion queue to.
12242 * This function creates a completion queue, as detailed in @wq, on a port,
12243 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
12245 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12246 * is used to get the entry count and entry size that are necessary to
12247 * determine the number of pages to allocate and use for this queue. The @eq
12248 * is used to indicate which event queue to bind this completion queue to. This
12249 * function will send the CQ_CREATE mailbox command to the HBA to setup the
12250 * completion queue. This function is asynchronous and will wait for the mailbox
12251 * command to finish before continuing.
12253 * On success this function will return a zero. If unable to allocate enough
12254 * memory this function will return -ENOMEM. If the queue create mailbox command
12255 * fails this function will return -ENXIO.
12258 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12259 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
12261 struct lpfc_mbx_cq_create
*cq_create
;
12262 struct lpfc_dmabuf
*dmabuf
;
12263 LPFC_MBOXQ_t
*mbox
;
12264 int rc
, length
, status
= 0;
12265 uint32_t shdr_status
, shdr_add_status
;
12266 union lpfc_sli4_cfg_shdr
*shdr
;
12267 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12269 /* sanity check on queue memory */
12272 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12273 hw_page_size
= SLI4_PAGE_SIZE
;
12275 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12278 length
= (sizeof(struct lpfc_mbx_cq_create
) -
12279 sizeof(struct lpfc_sli4_cfg_mhdr
));
12280 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12281 LPFC_MBOX_OPCODE_CQ_CREATE
,
12282 length
, LPFC_SLI4_MBX_EMBED
);
12283 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
12284 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
12285 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
12287 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
12288 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
12289 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12290 phba
->sli4_hba
.pc_sli4_params
.cqv
);
12291 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
12292 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12293 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
12294 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
12297 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
12300 switch (cq
->entry_count
) {
12302 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12303 "0361 Unsupported CQ count. (%d)\n",
12305 if (cq
->entry_count
< 256) {
12309 /* otherwise default to smallest count (drop through) */
12311 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12315 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12319 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12323 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12324 memset(dmabuf
->virt
, 0, hw_page_size
);
12325 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12326 putPaddrLow(dmabuf
->phys
);
12327 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12328 putPaddrHigh(dmabuf
->phys
);
12330 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12332 /* The IOCTL status is embedded in the mailbox subheader. */
12333 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12334 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12335 if (shdr_status
|| shdr_add_status
|| rc
) {
12336 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12337 "2501 CQ_CREATE mailbox failed with "
12338 "status x%x add_status x%x, mbx status x%x\n",
12339 shdr_status
, shdr_add_status
, rc
);
12343 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12344 if (cq
->queue_id
== 0xFFFF) {
12348 /* link the cq onto the parent eq child list */
12349 list_add_tail(&cq
->list
, &eq
->child_list
);
12350 /* Set up completion queue's type and subtype */
12352 cq
->subtype
= subtype
;
12353 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12354 cq
->assoc_qid
= eq
->queue_id
;
12355 cq
->host_index
= 0;
12359 mempool_free(mbox
, phba
->mbox_mem_pool
);
12364 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12365 * @phba: HBA structure that indicates port to create a queue on.
12366 * @mq: The queue structure to use to create the mailbox queue.
12367 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12368 * @cq: The completion queue to associate with this cq.
12370 * This function provides failback (fb) functionality when the
12371 * mq_create_ext fails on older FW generations. It's purpose is identical
12372 * to mq_create_ext otherwise.
12374 * This routine cannot fail as all attributes were previously accessed and
12375 * initialized in mq_create_ext.
12378 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12379 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12381 struct lpfc_mbx_mq_create
*mq_create
;
12382 struct lpfc_dmabuf
*dmabuf
;
12385 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12386 sizeof(struct lpfc_sli4_cfg_mhdr
));
12387 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12388 LPFC_MBOX_OPCODE_MQ_CREATE
,
12389 length
, LPFC_SLI4_MBX_EMBED
);
12390 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12391 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12393 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12395 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12396 switch (mq
->entry_count
) {
12398 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12399 LPFC_MQ_RING_SIZE_16
);
12402 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12403 LPFC_MQ_RING_SIZE_32
);
12406 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12407 LPFC_MQ_RING_SIZE_64
);
12410 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12411 LPFC_MQ_RING_SIZE_128
);
12414 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12415 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12416 putPaddrLow(dmabuf
->phys
);
12417 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12418 putPaddrHigh(dmabuf
->phys
);
12423 * lpfc_mq_create - Create a mailbox Queue on the HBA
12424 * @phba: HBA structure that indicates port to create a queue on.
12425 * @mq: The queue structure to use to create the mailbox queue.
12426 * @cq: The completion queue to associate with this cq.
12427 * @subtype: The queue's subtype.
12429 * This function creates a mailbox queue, as detailed in @mq, on a port,
12430 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12432 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12433 * is used to get the entry count and entry size that are necessary to
12434 * determine the number of pages to allocate and use for this queue. This
12435 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12436 * mailbox queue. This function is asynchronous and will wait for the mailbox
12437 * command to finish before continuing.
12439 * On success this function will return a zero. If unable to allocate enough
12440 * memory this function will return -ENOMEM. If the queue create mailbox command
12441 * fails this function will return -ENXIO.
12444 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12445 struct lpfc_queue
*cq
, uint32_t subtype
)
12447 struct lpfc_mbx_mq_create
*mq_create
;
12448 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12449 struct lpfc_dmabuf
*dmabuf
;
12450 LPFC_MBOXQ_t
*mbox
;
12451 int rc
, length
, status
= 0;
12452 uint32_t shdr_status
, shdr_add_status
;
12453 union lpfc_sli4_cfg_shdr
*shdr
;
12454 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12456 /* sanity check on queue memory */
12459 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12460 hw_page_size
= SLI4_PAGE_SIZE
;
12462 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12465 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12466 sizeof(struct lpfc_sli4_cfg_mhdr
));
12467 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12468 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12469 length
, LPFC_SLI4_MBX_EMBED
);
12471 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12472 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12473 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12474 &mq_create_ext
->u
.request
, mq
->page_count
);
12475 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12476 &mq_create_ext
->u
.request
, 1);
12477 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12478 &mq_create_ext
->u
.request
, 1);
12479 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12480 &mq_create_ext
->u
.request
, 1);
12481 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12482 &mq_create_ext
->u
.request
, 1);
12483 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12484 &mq_create_ext
->u
.request
, 1);
12485 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12486 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12487 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12488 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12489 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12492 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12494 switch (mq
->entry_count
) {
12496 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12497 "0362 Unsupported MQ count. (%d)\n",
12499 if (mq
->entry_count
< 16) {
12503 /* otherwise default to smallest count (drop through) */
12505 bf_set(lpfc_mq_context_ring_size
,
12506 &mq_create_ext
->u
.request
.context
,
12507 LPFC_MQ_RING_SIZE_16
);
12510 bf_set(lpfc_mq_context_ring_size
,
12511 &mq_create_ext
->u
.request
.context
,
12512 LPFC_MQ_RING_SIZE_32
);
12515 bf_set(lpfc_mq_context_ring_size
,
12516 &mq_create_ext
->u
.request
.context
,
12517 LPFC_MQ_RING_SIZE_64
);
12520 bf_set(lpfc_mq_context_ring_size
,
12521 &mq_create_ext
->u
.request
.context
,
12522 LPFC_MQ_RING_SIZE_128
);
12525 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12526 memset(dmabuf
->virt
, 0, hw_page_size
);
12527 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12528 putPaddrLow(dmabuf
->phys
);
12529 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12530 putPaddrHigh(dmabuf
->phys
);
12532 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12533 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12534 &mq_create_ext
->u
.response
);
12535 if (rc
!= MBX_SUCCESS
) {
12536 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12537 "2795 MQ_CREATE_EXT failed with "
12538 "status x%x. Failback to MQ_CREATE.\n",
12540 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12541 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12542 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12543 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12544 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12545 &mq_create
->u
.response
);
12548 /* The IOCTL status is embedded in the mailbox subheader. */
12549 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12550 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12551 if (shdr_status
|| shdr_add_status
|| rc
) {
12552 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12553 "2502 MQ_CREATE mailbox failed with "
12554 "status x%x add_status x%x, mbx status x%x\n",
12555 shdr_status
, shdr_add_status
, rc
);
12559 if (mq
->queue_id
== 0xFFFF) {
12563 mq
->type
= LPFC_MQ
;
12564 mq
->assoc_qid
= cq
->queue_id
;
12565 mq
->subtype
= subtype
;
12566 mq
->host_index
= 0;
12569 /* link the mq onto the parent cq child list */
12570 list_add_tail(&mq
->list
, &cq
->child_list
);
12572 mempool_free(mbox
, phba
->mbox_mem_pool
);
12577 * lpfc_wq_create - Create a Work Queue on the HBA
12578 * @phba: HBA structure that indicates port to create a queue on.
12579 * @wq: The queue structure to use to create the work queue.
12580 * @cq: The completion queue to bind this work queue to.
12581 * @subtype: The subtype of the work queue indicating its functionality.
12583 * This function creates a work queue, as detailed in @wq, on a port, described
12584 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12586 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12587 * is used to get the entry count and entry size that are necessary to
12588 * determine the number of pages to allocate and use for this queue. The @cq
12589 * is used to indicate which completion queue to bind this work queue to. This
12590 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12591 * work queue. This function is asynchronous and will wait for the mailbox
12592 * command to finish before continuing.
12594 * On success this function will return a zero. If unable to allocate enough
12595 * memory this function will return -ENOMEM. If the queue create mailbox command
12596 * fails this function will return -ENXIO.
12599 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12600 struct lpfc_queue
*cq
, uint32_t subtype
)
12602 struct lpfc_mbx_wq_create
*wq_create
;
12603 struct lpfc_dmabuf
*dmabuf
;
12604 LPFC_MBOXQ_t
*mbox
;
12605 int rc
, length
, status
= 0;
12606 uint32_t shdr_status
, shdr_add_status
;
12607 union lpfc_sli4_cfg_shdr
*shdr
;
12608 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12609 struct dma_address
*page
;
12611 /* sanity check on queue memory */
12614 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12615 hw_page_size
= SLI4_PAGE_SIZE
;
12617 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12620 length
= (sizeof(struct lpfc_mbx_wq_create
) -
12621 sizeof(struct lpfc_sli4_cfg_mhdr
));
12622 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12623 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
12624 length
, LPFC_SLI4_MBX_EMBED
);
12625 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
12626 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
12627 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
12629 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
12631 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12632 phba
->sli4_hba
.pc_sli4_params
.wqv
);
12633 if (phba
->sli4_hba
.pc_sli4_params
.wqv
== LPFC_Q_CREATE_VERSION_1
) {
12634 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
12636 switch (wq
->entry_size
) {
12639 bf_set(lpfc_mbx_wq_create_wqe_size
,
12640 &wq_create
->u
.request_1
,
12641 LPFC_WQ_WQE_SIZE_64
);
12644 bf_set(lpfc_mbx_wq_create_wqe_size
,
12645 &wq_create
->u
.request_1
,
12646 LPFC_WQ_WQE_SIZE_128
);
12649 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
12650 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12651 page
= wq_create
->u
.request_1
.page
;
12653 page
= wq_create
->u
.request
.page
;
12655 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
12656 memset(dmabuf
->virt
, 0, hw_page_size
);
12657 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
12658 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
12660 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12661 /* The IOCTL status is embedded in the mailbox subheader. */
12662 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12663 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12664 if (shdr_status
|| shdr_add_status
|| rc
) {
12665 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12666 "2503 WQ_CREATE mailbox failed with "
12667 "status x%x add_status x%x, mbx status x%x\n",
12668 shdr_status
, shdr_add_status
, rc
);
12672 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
12673 if (wq
->queue_id
== 0xFFFF) {
12677 wq
->type
= LPFC_WQ
;
12678 wq
->assoc_qid
= cq
->queue_id
;
12679 wq
->subtype
= subtype
;
12680 wq
->host_index
= 0;
12682 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
12684 /* link the wq onto the parent cq child list */
12685 list_add_tail(&wq
->list
, &cq
->child_list
);
12687 mempool_free(mbox
, phba
->mbox_mem_pool
);
12692 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12693 * @phba: HBA structure that indicates port to create a queue on.
12694 * @rq: The queue structure to use for the receive queue.
12695 * @qno: The associated HBQ number
12698 * For SLI4 we need to adjust the RQ repost value based on
12699 * the number of buffers that are initially posted to the RQ.
12702 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
12706 /* sanity check on queue memory */
12709 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
12711 /* Recalc repost for RQs based on buffers initially posted */
12713 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
12714 cnt
= LPFC_QUEUE_MIN_REPOST
;
12716 rq
->entry_repost
= cnt
;
12720 * lpfc_rq_create - Create a Receive Queue on the HBA
12721 * @phba: HBA structure that indicates port to create a queue on.
12722 * @hrq: The queue structure to use to create the header receive queue.
12723 * @drq: The queue structure to use to create the data receive queue.
12724 * @cq: The completion queue to bind this work queue to.
12726 * This function creates a receive buffer queue pair , as detailed in @hrq and
12727 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12730 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12731 * struct is used to get the entry count that is necessary to determine the
12732 * number of pages to use for this queue. The @cq is used to indicate which
12733 * completion queue to bind received buffers that are posted to these queues to.
12734 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12735 * receive queue pair. This function is asynchronous and will wait for the
12736 * mailbox command to finish before continuing.
12738 * On success this function will return a zero. If unable to allocate enough
12739 * memory this function will return -ENOMEM. If the queue create mailbox command
12740 * fails this function will return -ENXIO.
12743 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12744 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
12746 struct lpfc_mbx_rq_create
*rq_create
;
12747 struct lpfc_dmabuf
*dmabuf
;
12748 LPFC_MBOXQ_t
*mbox
;
12749 int rc
, length
, status
= 0;
12750 uint32_t shdr_status
, shdr_add_status
;
12751 union lpfc_sli4_cfg_shdr
*shdr
;
12752 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12754 /* sanity check on queue memory */
12755 if (!hrq
|| !drq
|| !cq
)
12757 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12758 hw_page_size
= SLI4_PAGE_SIZE
;
12760 if (hrq
->entry_count
!= drq
->entry_count
)
12762 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12765 length
= (sizeof(struct lpfc_mbx_rq_create
) -
12766 sizeof(struct lpfc_sli4_cfg_mhdr
));
12767 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12768 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12769 length
, LPFC_SLI4_MBX_EMBED
);
12770 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
12771 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12772 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12773 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12774 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12775 bf_set(lpfc_rq_context_rqe_count_1
,
12776 &rq_create
->u
.request
.context
,
12778 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
12779 bf_set(lpfc_rq_context_rqe_size
,
12780 &rq_create
->u
.request
.context
,
12782 bf_set(lpfc_rq_context_page_size
,
12783 &rq_create
->u
.request
.context
,
12784 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12786 switch (hrq
->entry_count
) {
12788 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12789 "2535 Unsupported RQ count. (%d)\n",
12791 if (hrq
->entry_count
< 512) {
12795 /* otherwise default to smallest count (drop through) */
12797 bf_set(lpfc_rq_context_rqe_count
,
12798 &rq_create
->u
.request
.context
,
12799 LPFC_RQ_RING_SIZE_512
);
12802 bf_set(lpfc_rq_context_rqe_count
,
12803 &rq_create
->u
.request
.context
,
12804 LPFC_RQ_RING_SIZE_1024
);
12807 bf_set(lpfc_rq_context_rqe_count
,
12808 &rq_create
->u
.request
.context
,
12809 LPFC_RQ_RING_SIZE_2048
);
12812 bf_set(lpfc_rq_context_rqe_count
,
12813 &rq_create
->u
.request
.context
,
12814 LPFC_RQ_RING_SIZE_4096
);
12817 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12818 LPFC_HDR_BUF_SIZE
);
12820 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12822 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12824 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
12825 memset(dmabuf
->virt
, 0, hw_page_size
);
12826 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12827 putPaddrLow(dmabuf
->phys
);
12828 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12829 putPaddrHigh(dmabuf
->phys
);
12831 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12832 /* The IOCTL status is embedded in the mailbox subheader. */
12833 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12834 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12835 if (shdr_status
|| shdr_add_status
|| rc
) {
12836 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12837 "2504 RQ_CREATE mailbox failed with "
12838 "status x%x add_status x%x, mbx status x%x\n",
12839 shdr_status
, shdr_add_status
, rc
);
12843 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12844 if (hrq
->queue_id
== 0xFFFF) {
12848 hrq
->type
= LPFC_HRQ
;
12849 hrq
->assoc_qid
= cq
->queue_id
;
12850 hrq
->subtype
= subtype
;
12851 hrq
->host_index
= 0;
12852 hrq
->hba_index
= 0;
12854 /* now create the data queue */
12855 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12856 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12857 length
, LPFC_SLI4_MBX_EMBED
);
12858 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12859 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12860 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12861 bf_set(lpfc_rq_context_rqe_count_1
,
12862 &rq_create
->u
.request
.context
, hrq
->entry_count
);
12863 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
12864 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
12866 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
12867 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12869 switch (drq
->entry_count
) {
12871 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12872 "2536 Unsupported RQ count. (%d)\n",
12874 if (drq
->entry_count
< 512) {
12878 /* otherwise default to smallest count (drop through) */
12880 bf_set(lpfc_rq_context_rqe_count
,
12881 &rq_create
->u
.request
.context
,
12882 LPFC_RQ_RING_SIZE_512
);
12885 bf_set(lpfc_rq_context_rqe_count
,
12886 &rq_create
->u
.request
.context
,
12887 LPFC_RQ_RING_SIZE_1024
);
12890 bf_set(lpfc_rq_context_rqe_count
,
12891 &rq_create
->u
.request
.context
,
12892 LPFC_RQ_RING_SIZE_2048
);
12895 bf_set(lpfc_rq_context_rqe_count
,
12896 &rq_create
->u
.request
.context
,
12897 LPFC_RQ_RING_SIZE_4096
);
12900 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12901 LPFC_DATA_BUF_SIZE
);
12903 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12905 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12907 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
12908 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12909 putPaddrLow(dmabuf
->phys
);
12910 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12911 putPaddrHigh(dmabuf
->phys
);
12913 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12914 /* The IOCTL status is embedded in the mailbox subheader. */
12915 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12916 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12917 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12918 if (shdr_status
|| shdr_add_status
|| rc
) {
12922 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12923 if (drq
->queue_id
== 0xFFFF) {
12927 drq
->type
= LPFC_DRQ
;
12928 drq
->assoc_qid
= cq
->queue_id
;
12929 drq
->subtype
= subtype
;
12930 drq
->host_index
= 0;
12931 drq
->hba_index
= 0;
12933 /* link the header and data RQs onto the parent cq child list */
12934 list_add_tail(&hrq
->list
, &cq
->child_list
);
12935 list_add_tail(&drq
->list
, &cq
->child_list
);
12938 mempool_free(mbox
, phba
->mbox_mem_pool
);
12943 * lpfc_eq_destroy - Destroy an event Queue on the HBA
12944 * @eq: The queue structure associated with the queue to destroy.
12946 * This function destroys a queue, as detailed in @eq by sending an mailbox
12947 * command, specific to the type of queue, to the HBA.
12949 * The @eq struct is used to get the queue ID of the queue to destroy.
12951 * On success this function will return a zero. If the queue destroy mailbox
12952 * command fails this function will return -ENXIO.
12955 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12957 LPFC_MBOXQ_t
*mbox
;
12958 int rc
, length
, status
= 0;
12959 uint32_t shdr_status
, shdr_add_status
;
12960 union lpfc_sli4_cfg_shdr
*shdr
;
12962 /* sanity check on queue memory */
12965 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12968 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
12969 sizeof(struct lpfc_sli4_cfg_mhdr
));
12970 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12971 LPFC_MBOX_OPCODE_EQ_DESTROY
,
12972 length
, LPFC_SLI4_MBX_EMBED
);
12973 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
12975 mbox
->vport
= eq
->phba
->pport
;
12976 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12978 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
12979 /* The IOCTL status is embedded in the mailbox subheader. */
12980 shdr
= (union lpfc_sli4_cfg_shdr
*)
12981 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
12982 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12983 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12984 if (shdr_status
|| shdr_add_status
|| rc
) {
12985 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12986 "2505 EQ_DESTROY mailbox failed with "
12987 "status x%x add_status x%x, mbx status x%x\n",
12988 shdr_status
, shdr_add_status
, rc
);
12992 /* Remove eq from any list */
12993 list_del_init(&eq
->list
);
12994 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
12999 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
13000 * @cq: The queue structure associated with the queue to destroy.
13002 * This function destroys a queue, as detailed in @cq by sending an mailbox
13003 * command, specific to the type of queue, to the HBA.
13005 * The @cq struct is used to get the queue ID of the queue to destroy.
13007 * On success this function will return a zero. If the queue destroy mailbox
13008 * command fails this function will return -ENXIO.
13011 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
13013 LPFC_MBOXQ_t
*mbox
;
13014 int rc
, length
, status
= 0;
13015 uint32_t shdr_status
, shdr_add_status
;
13016 union lpfc_sli4_cfg_shdr
*shdr
;
13018 /* sanity check on queue memory */
13021 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13024 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
13025 sizeof(struct lpfc_sli4_cfg_mhdr
));
13026 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13027 LPFC_MBOX_OPCODE_CQ_DESTROY
,
13028 length
, LPFC_SLI4_MBX_EMBED
);
13029 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
13031 mbox
->vport
= cq
->phba
->pport
;
13032 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13033 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
13034 /* The IOCTL status is embedded in the mailbox subheader. */
13035 shdr
= (union lpfc_sli4_cfg_shdr
*)
13036 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
13037 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13038 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13039 if (shdr_status
|| shdr_add_status
|| rc
) {
13040 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13041 "2506 CQ_DESTROY mailbox failed with "
13042 "status x%x add_status x%x, mbx status x%x\n",
13043 shdr_status
, shdr_add_status
, rc
);
13046 /* Remove cq from any list */
13047 list_del_init(&cq
->list
);
13048 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
13053 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
13054 * @qm: The queue structure associated with the queue to destroy.
13056 * This function destroys a queue, as detailed in @mq by sending an mailbox
13057 * command, specific to the type of queue, to the HBA.
13059 * The @mq struct is used to get the queue ID of the queue to destroy.
13061 * On success this function will return a zero. If the queue destroy mailbox
13062 * command fails this function will return -ENXIO.
13065 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
13067 LPFC_MBOXQ_t
*mbox
;
13068 int rc
, length
, status
= 0;
13069 uint32_t shdr_status
, shdr_add_status
;
13070 union lpfc_sli4_cfg_shdr
*shdr
;
13072 /* sanity check on queue memory */
13075 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13078 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
13079 sizeof(struct lpfc_sli4_cfg_mhdr
));
13080 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13081 LPFC_MBOX_OPCODE_MQ_DESTROY
,
13082 length
, LPFC_SLI4_MBX_EMBED
);
13083 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
13085 mbox
->vport
= mq
->phba
->pport
;
13086 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13087 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
13088 /* The IOCTL status is embedded in the mailbox subheader. */
13089 shdr
= (union lpfc_sli4_cfg_shdr
*)
13090 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
13091 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13092 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13093 if (shdr_status
|| shdr_add_status
|| rc
) {
13094 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13095 "2507 MQ_DESTROY mailbox failed with "
13096 "status x%x add_status x%x, mbx status x%x\n",
13097 shdr_status
, shdr_add_status
, rc
);
13100 /* Remove mq from any list */
13101 list_del_init(&mq
->list
);
13102 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
13107 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
13108 * @wq: The queue structure associated with the queue to destroy.
13110 * This function destroys a queue, as detailed in @wq by sending an mailbox
13111 * command, specific to the type of queue, to the HBA.
13113 * The @wq struct is used to get the queue ID of the queue to destroy.
13115 * On success this function will return a zero. If the queue destroy mailbox
13116 * command fails this function will return -ENXIO.
13119 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
13121 LPFC_MBOXQ_t
*mbox
;
13122 int rc
, length
, status
= 0;
13123 uint32_t shdr_status
, shdr_add_status
;
13124 union lpfc_sli4_cfg_shdr
*shdr
;
13126 /* sanity check on queue memory */
13129 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13132 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
13133 sizeof(struct lpfc_sli4_cfg_mhdr
));
13134 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13135 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
13136 length
, LPFC_SLI4_MBX_EMBED
);
13137 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
13139 mbox
->vport
= wq
->phba
->pport
;
13140 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13141 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
13142 shdr
= (union lpfc_sli4_cfg_shdr
*)
13143 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
13144 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13145 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13146 if (shdr_status
|| shdr_add_status
|| rc
) {
13147 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13148 "2508 WQ_DESTROY mailbox failed with "
13149 "status x%x add_status x%x, mbx status x%x\n",
13150 shdr_status
, shdr_add_status
, rc
);
13153 /* Remove wq from any list */
13154 list_del_init(&wq
->list
);
13155 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
13160 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
13161 * @rq: The queue structure associated with the queue to destroy.
13163 * This function destroys a queue, as detailed in @rq by sending an mailbox
13164 * command, specific to the type of queue, to the HBA.
13166 * The @rq struct is used to get the queue ID of the queue to destroy.
13168 * On success this function will return a zero. If the queue destroy mailbox
13169 * command fails this function will return -ENXIO.
13172 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13173 struct lpfc_queue
*drq
)
13175 LPFC_MBOXQ_t
*mbox
;
13176 int rc
, length
, status
= 0;
13177 uint32_t shdr_status
, shdr_add_status
;
13178 union lpfc_sli4_cfg_shdr
*shdr
;
13180 /* sanity check on queue memory */
13183 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13186 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
13187 sizeof(struct lpfc_sli4_cfg_mhdr
));
13188 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13189 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
13190 length
, LPFC_SLI4_MBX_EMBED
);
13191 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13193 mbox
->vport
= hrq
->phba
->pport
;
13194 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13195 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
13196 /* The IOCTL status is embedded in the mailbox subheader. */
13197 shdr
= (union lpfc_sli4_cfg_shdr
*)
13198 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13199 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13200 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13201 if (shdr_status
|| shdr_add_status
|| rc
) {
13202 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13203 "2509 RQ_DESTROY mailbox failed with "
13204 "status x%x add_status x%x, mbx status x%x\n",
13205 shdr_status
, shdr_add_status
, rc
);
13206 if (rc
!= MBX_TIMEOUT
)
13207 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13210 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13212 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
13213 shdr
= (union lpfc_sli4_cfg_shdr
*)
13214 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13215 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13216 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13217 if (shdr_status
|| shdr_add_status
|| rc
) {
13218 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13219 "2510 RQ_DESTROY mailbox failed with "
13220 "status x%x add_status x%x, mbx status x%x\n",
13221 shdr_status
, shdr_add_status
, rc
);
13224 list_del_init(&hrq
->list
);
13225 list_del_init(&drq
->list
);
13226 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13231 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
13232 * @phba: The virtual port for which this call being executed.
13233 * @pdma_phys_addr0: Physical address of the 1st SGL page.
13234 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
13235 * @xritag: the xritag that ties this io to the SGL pages.
13237 * This routine will post the sgl pages for the IO that has the xritag
13238 * that is in the iocbq structure. The xritag is assigned during iocbq
13239 * creation and persists for as long as the driver is loaded.
13240 * if the caller has fewer than 256 scatter gather segments to map then
13241 * pdma_phys_addr1 should be 0.
13242 * If the caller needs to map more than 256 scatter gather segment then
13243 * pdma_phys_addr1 should be a valid physical address.
13244 * physical address for SGLs must be 64 byte aligned.
13245 * If you are going to map 2 SGL's then the first one must have 256 entries
13246 * the second sgl can have between 1 and 256 entries.
13250 * -ENXIO, -ENOMEM - Failure
13253 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
13254 dma_addr_t pdma_phys_addr0
,
13255 dma_addr_t pdma_phys_addr1
,
13258 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
13259 LPFC_MBOXQ_t
*mbox
;
13261 uint32_t shdr_status
, shdr_add_status
;
13263 union lpfc_sli4_cfg_shdr
*shdr
;
13265 if (xritag
== NO_XRI
) {
13266 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13267 "0364 Invalid param:\n");
13271 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13275 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13276 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13277 sizeof(struct lpfc_mbx_post_sgl_pages
) -
13278 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
13280 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
13281 &mbox
->u
.mqe
.un
.post_sgl_pages
;
13282 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
13283 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
13285 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
13286 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
13287 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
13288 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
13290 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
13291 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
13292 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
13293 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
13294 if (!phba
->sli4_hba
.intr_enable
)
13295 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13297 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13298 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13300 /* The IOCTL status is embedded in the mailbox subheader. */
13301 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
13302 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13303 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13304 if (rc
!= MBX_TIMEOUT
)
13305 mempool_free(mbox
, phba
->mbox_mem_pool
);
13306 if (shdr_status
|| shdr_add_status
|| rc
) {
13307 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13308 "2511 POST_SGL mailbox failed with "
13309 "status x%x add_status x%x, mbx status x%x\n",
13310 shdr_status
, shdr_add_status
, rc
);
13317 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13318 * @phba: pointer to lpfc hba data structure.
13320 * This routine is invoked to post rpi header templates to the
13321 * HBA consistent with the SLI-4 interface spec. This routine
13322 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13323 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13326 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13327 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13330 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13335 * Fetch the next logical xri. Because this index is logical,
13336 * the driver starts at 0 each time.
13338 spin_lock_irq(&phba
->hbalock
);
13339 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13340 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13341 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13342 spin_unlock_irq(&phba
->hbalock
);
13345 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13346 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13348 spin_unlock_irq(&phba
->hbalock
);
13353 * lpfc_sli4_free_xri - Release an xri for reuse.
13354 * @phba: pointer to lpfc hba data structure.
13356 * This routine is invoked to release an xri to the pool of
13357 * available rpis maintained by the driver.
13360 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13362 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13363 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13368 * lpfc_sli4_free_xri - Release an xri for reuse.
13369 * @phba: pointer to lpfc hba data structure.
13371 * This routine is invoked to release an xri to the pool of
13372 * available rpis maintained by the driver.
13375 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13377 spin_lock_irq(&phba
->hbalock
);
13378 __lpfc_sli4_free_xri(phba
, xri
);
13379 spin_unlock_irq(&phba
->hbalock
);
13383 * lpfc_sli4_next_xritag - Get an xritag for the io
13384 * @phba: Pointer to HBA context object.
13386 * This function gets an xritag for the iocb. If there is no unused xritag
13387 * it will return 0xffff.
13388 * The function returns the allocated xritag if successful, else returns zero.
13389 * Zero is not a valid xritag.
13390 * The caller is not required to hold any lock.
13393 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13395 uint16_t xri_index
;
13397 xri_index
= lpfc_sli4_alloc_xri(phba
);
13398 if (xri_index
== NO_XRI
)
13399 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13400 "2004 Failed to allocate XRI.last XRITAG is %d"
13401 " Max XRI is %d, Used XRI is %d\n",
13403 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13404 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13409 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13410 * @phba: pointer to lpfc hba data structure.
13411 * @post_sgl_list: pointer to els sgl entry list.
13412 * @count: number of els sgl entries on the list.
13414 * This routine is invoked to post a block of driver's sgl pages to the
13415 * HBA using non-embedded mailbox command. No Lock is held. This routine
13416 * is only called when the driver is loading and after all IO has been
13420 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
13421 struct list_head
*post_sgl_list
,
13424 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
13425 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13426 struct sgl_page_pairs
*sgl_pg_pairs
;
13428 LPFC_MBOXQ_t
*mbox
;
13429 uint32_t reqlen
, alloclen
, pg_pairs
;
13431 uint16_t xritag_start
= 0;
13433 uint32_t shdr_status
, shdr_add_status
;
13434 union lpfc_sli4_cfg_shdr
*shdr
;
13436 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13437 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13438 if (reqlen
> SLI4_PAGE_SIZE
) {
13439 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13440 "2559 Block sgl registration required DMA "
13441 "size (%d) great than a page\n", reqlen
);
13444 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13448 /* Allocate DMA memory and set up the non-embedded mailbox command */
13449 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13450 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13451 LPFC_SLI4_MBX_NEMBED
);
13453 if (alloclen
< reqlen
) {
13454 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13455 "0285 Allocated DMA memory size (%d) is "
13456 "less than the requested DMA memory "
13457 "size (%d)\n", alloclen
, reqlen
);
13458 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13461 /* Set up the SGL pages in the non-embedded DMA pages */
13462 viraddr
= mbox
->sge_array
->addr
[0];
13463 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13464 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13467 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
13468 /* Set up the sge entry */
13469 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13470 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13471 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13472 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13473 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13474 cpu_to_le32(putPaddrLow(0));
13475 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13476 cpu_to_le32(putPaddrHigh(0));
13478 /* Keep the first xritag on the list */
13480 xritag_start
= sglq_entry
->sli4_xritag
;
13485 /* Complete initialization and perform endian conversion. */
13486 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13487 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
13488 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13489 if (!phba
->sli4_hba
.intr_enable
)
13490 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13492 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13493 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13495 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13496 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13497 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13498 if (rc
!= MBX_TIMEOUT
)
13499 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13500 if (shdr_status
|| shdr_add_status
|| rc
) {
13501 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13502 "2513 POST_SGL_BLOCK mailbox command failed "
13503 "status x%x add_status x%x mbx status x%x\n",
13504 shdr_status
, shdr_add_status
, rc
);
13511 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13512 * @phba: pointer to lpfc hba data structure.
13513 * @sblist: pointer to scsi buffer list.
13514 * @count: number of scsi buffers on the list.
13516 * This routine is invoked to post a block of @count scsi sgl pages from a
13517 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13522 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
13523 struct list_head
*sblist
,
13526 struct lpfc_scsi_buf
*psb
;
13527 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13528 struct sgl_page_pairs
*sgl_pg_pairs
;
13530 LPFC_MBOXQ_t
*mbox
;
13531 uint32_t reqlen
, alloclen
, pg_pairs
;
13533 uint16_t xritag_start
= 0;
13535 uint32_t shdr_status
, shdr_add_status
;
13536 dma_addr_t pdma_phys_bpl1
;
13537 union lpfc_sli4_cfg_shdr
*shdr
;
13539 /* Calculate the requested length of the dma memory */
13540 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
13541 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13542 if (reqlen
> SLI4_PAGE_SIZE
) {
13543 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13544 "0217 Block sgl registration required DMA "
13545 "size (%d) great than a page\n", reqlen
);
13548 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13550 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13551 "0283 Failed to allocate mbox cmd memory\n");
13555 /* Allocate DMA memory and set up the non-embedded mailbox command */
13556 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13557 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13558 LPFC_SLI4_MBX_NEMBED
);
13560 if (alloclen
< reqlen
) {
13561 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13562 "2561 Allocated DMA memory size (%d) is "
13563 "less than the requested DMA memory "
13564 "size (%d)\n", alloclen
, reqlen
);
13565 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13569 /* Get the first SGE entry from the non-embedded DMA memory */
13570 viraddr
= mbox
->sge_array
->addr
[0];
13572 /* Set up the SGL pages in the non-embedded DMA pages */
13573 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13574 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13577 list_for_each_entry(psb
, sblist
, list
) {
13578 /* Set up the sge entry */
13579 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13580 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13581 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13582 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13583 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13584 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
13586 pdma_phys_bpl1
= 0;
13587 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13588 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13589 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13590 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13591 /* Keep the first xritag on the list */
13593 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
13597 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13598 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13599 /* Perform endian conversion if necessary */
13600 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13602 if (!phba
->sli4_hba
.intr_enable
)
13603 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13605 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13606 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13608 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13609 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13610 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13611 if (rc
!= MBX_TIMEOUT
)
13612 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13613 if (shdr_status
|| shdr_add_status
|| rc
) {
13614 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13615 "2564 POST_SGL_BLOCK mailbox command failed "
13616 "status x%x add_status x%x mbx status x%x\n",
13617 shdr_status
, shdr_add_status
, rc
);
13624 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13625 * @phba: pointer to lpfc_hba struct that the frame was received on
13626 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13628 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13629 * valid type of frame that the LPFC driver will handle. This function will
13630 * return a zero if the frame is a valid frame or a non zero value when the
13631 * frame does not pass the check.
13634 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
13636 /* make rctl_names static to save stack space */
13637 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
13638 char *type_names
[] = FC_TYPE_NAMES_INIT
;
13639 struct fc_vft_header
*fc_vft_hdr
;
13640 uint32_t *header
= (uint32_t *) fc_hdr
;
13642 switch (fc_hdr
->fh_r_ctl
) {
13643 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
13644 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
13645 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
13646 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
13647 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
13648 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
13649 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
13650 case FC_RCTL_DD_CMD_STATUS
: /* command status */
13651 case FC_RCTL_ELS_REQ
: /* extended link services request */
13652 case FC_RCTL_ELS_REP
: /* extended link services reply */
13653 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
13654 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
13655 case FC_RCTL_BA_NOP
: /* basic link service NOP */
13656 case FC_RCTL_BA_ABTS
: /* basic link service abort */
13657 case FC_RCTL_BA_RMC
: /* remove connection */
13658 case FC_RCTL_BA_ACC
: /* basic accept */
13659 case FC_RCTL_BA_RJT
: /* basic reject */
13660 case FC_RCTL_BA_PRMT
:
13661 case FC_RCTL_ACK_1
: /* acknowledge_1 */
13662 case FC_RCTL_ACK_0
: /* acknowledge_0 */
13663 case FC_RCTL_P_RJT
: /* port reject */
13664 case FC_RCTL_F_RJT
: /* fabric reject */
13665 case FC_RCTL_P_BSY
: /* port busy */
13666 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
13667 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
13668 case FC_RCTL_LCR
: /* link credit reset */
13669 case FC_RCTL_END
: /* end */
13671 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
13672 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13673 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
13674 return lpfc_fc_frame_check(phba
, fc_hdr
);
13678 switch (fc_hdr
->fh_type
) {
13690 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
13691 "2538 Received frame rctl:%s type:%s "
13692 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13693 rctl_names
[fc_hdr
->fh_r_ctl
],
13694 type_names
[fc_hdr
->fh_type
],
13695 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
13696 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
13697 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]));
13700 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13701 "2539 Dropped frame rctl:%s type:%s\n",
13702 rctl_names
[fc_hdr
->fh_r_ctl
],
13703 type_names
[fc_hdr
->fh_type
]);
13708 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13709 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13711 * This function processes the FC header to retrieve the VFI from the VF
13712 * header, if one exists. This function will return the VFI if one exists
13713 * or 0 if no VSAN Header exists.
13716 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
13718 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13720 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
13722 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
13726 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13727 * @phba: Pointer to the HBA structure to search for the vport on
13728 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13729 * @fcfi: The FC Fabric ID that the frame came from
13731 * This function searches the @phba for a vport that matches the content of the
13732 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13733 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13734 * returns the matching vport pointer or NULL if unable to match frame to a
13737 static struct lpfc_vport
*
13738 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
13741 struct lpfc_vport
**vports
;
13742 struct lpfc_vport
*vport
= NULL
;
13744 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
13745 fc_hdr
->fh_d_id
[1] << 8 |
13746 fc_hdr
->fh_d_id
[2]);
13748 if (did
== Fabric_DID
)
13749 return phba
->pport
;
13750 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
13751 !(phba
->link_state
== LPFC_HBA_READY
))
13752 return phba
->pport
;
13754 vports
= lpfc_create_vport_work_array(phba
);
13755 if (vports
!= NULL
)
13756 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
13757 if (phba
->fcf
.fcfi
== fcfi
&&
13758 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
13759 vports
[i
]->fc_myDID
== did
) {
13764 lpfc_destroy_vport_work_array(phba
, vports
);
13769 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13770 * @vport: The vport to work on.
13772 * This function updates the receive sequence time stamp for this vport. The
13773 * receive sequence time stamp indicates the time that the last frame of the
13774 * the sequence that has been idle for the longest amount of time was received.
13775 * the driver uses this time stamp to indicate if any received sequences have
13779 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
13781 struct lpfc_dmabuf
*h_buf
;
13782 struct hbq_dmabuf
*dmabuf
= NULL
;
13784 /* get the oldest sequence on the rcv list */
13785 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
13786 struct lpfc_dmabuf
, list
);
13789 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13790 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
13794 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13795 * @vport: The vport that the received sequences were sent to.
13797 * This function cleans up all outstanding received sequences. This is called
13798 * by the driver when a link event or user action invalidates all the received
13802 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
13804 struct lpfc_dmabuf
*h_buf
, *hnext
;
13805 struct lpfc_dmabuf
*d_buf
, *dnext
;
13806 struct hbq_dmabuf
*dmabuf
= NULL
;
13808 /* start with the oldest sequence on the rcv list */
13809 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13810 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13811 list_del_init(&dmabuf
->hbuf
.list
);
13812 list_for_each_entry_safe(d_buf
, dnext
,
13813 &dmabuf
->dbuf
.list
, list
) {
13814 list_del_init(&d_buf
->list
);
13815 lpfc_in_buf_free(vport
->phba
, d_buf
);
13817 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13822 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13823 * @vport: The vport that the received sequences were sent to.
13825 * This function determines whether any received sequences have timed out by
13826 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13827 * indicates that there is at least one timed out sequence this routine will
13828 * go through the received sequences one at a time from most inactive to most
13829 * active to determine which ones need to be cleaned up. Once it has determined
13830 * that a sequence needs to be cleaned up it will simply free up the resources
13831 * without sending an abort.
13834 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
13836 struct lpfc_dmabuf
*h_buf
, *hnext
;
13837 struct lpfc_dmabuf
*d_buf
, *dnext
;
13838 struct hbq_dmabuf
*dmabuf
= NULL
;
13839 unsigned long timeout
;
13840 int abort_count
= 0;
13842 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13843 vport
->rcv_buffer_time_stamp
);
13844 if (list_empty(&vport
->rcv_buffer_list
) ||
13845 time_before(jiffies
, timeout
))
13847 /* start with the oldest sequence on the rcv list */
13848 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13849 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13850 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13851 dmabuf
->time_stamp
);
13852 if (time_before(jiffies
, timeout
))
13855 list_del_init(&dmabuf
->hbuf
.list
);
13856 list_for_each_entry_safe(d_buf
, dnext
,
13857 &dmabuf
->dbuf
.list
, list
) {
13858 list_del_init(&d_buf
->list
);
13859 lpfc_in_buf_free(vport
->phba
, d_buf
);
13861 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13864 lpfc_update_rcv_time_stamp(vport
);
13868 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13869 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13871 * This function searches through the existing incomplete sequences that have
13872 * been sent to this @vport. If the frame matches one of the incomplete
13873 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13874 * make up that sequence. If no sequence is found that matches this frame then
13875 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13876 * This function returns a pointer to the first dmabuf in the sequence list that
13877 * the frame was linked to.
13879 static struct hbq_dmabuf
*
13880 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
13882 struct fc_frame_header
*new_hdr
;
13883 struct fc_frame_header
*temp_hdr
;
13884 struct lpfc_dmabuf
*d_buf
;
13885 struct lpfc_dmabuf
*h_buf
;
13886 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13887 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
13889 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13890 dmabuf
->time_stamp
= jiffies
;
13891 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13892 /* Use the hdr_buf to find the sequence that this frame belongs to */
13893 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13894 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13895 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13896 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13897 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13899 /* found a pending sequence that matches this frame */
13900 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13905 * This indicates first frame received for this sequence.
13906 * Queue the buffer on the vport's rcv_buffer_list.
13908 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13909 lpfc_update_rcv_time_stamp(vport
);
13912 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
13913 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
13914 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13915 list_del_init(&seq_dmabuf
->hbuf
.list
);
13916 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13917 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
13918 lpfc_update_rcv_time_stamp(vport
);
13921 /* move this sequence to the tail to indicate a young sequence */
13922 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13923 seq_dmabuf
->time_stamp
= jiffies
;
13924 lpfc_update_rcv_time_stamp(vport
);
13925 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
13926 temp_hdr
= dmabuf
->hbuf
.virt
;
13927 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
13930 /* find the correct place in the sequence to insert this frame */
13931 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
13932 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
13933 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
13935 * If the frame's sequence count is greater than the frame on
13936 * the list then insert the frame right after this frame
13938 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
13939 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13940 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
13948 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
13949 * @vport: pointer to a vitural port
13950 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13952 * This function tries to abort from the partially assembed sequence, described
13953 * by the information from basic abbort @dmabuf. It checks to see whether such
13954 * partially assembled sequence held by the driver. If so, it shall free up all
13955 * the frames from the partially assembled sequence.
13958 * true -- if there is matching partially assembled sequence present and all
13959 * the frames freed with the sequence;
13960 * false -- if there is no matching partially assembled sequence present so
13961 * nothing got aborted in the lower layer driver
13964 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
13965 struct hbq_dmabuf
*dmabuf
)
13967 struct fc_frame_header
*new_hdr
;
13968 struct fc_frame_header
*temp_hdr
;
13969 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
13970 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13972 /* Use the hdr_buf to find the sequence that matches this frame */
13973 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13974 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
13975 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13976 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13977 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13978 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13979 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13980 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13982 /* found a pending sequence that matches this frame */
13983 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13987 /* Free up all the frames from the partially assembled sequence */
13989 list_for_each_entry_safe(d_buf
, n_buf
,
13990 &seq_dmabuf
->dbuf
.list
, list
) {
13991 list_del_init(&d_buf
->list
);
13992 lpfc_in_buf_free(vport
->phba
, d_buf
);
14000 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14001 * @phba: Pointer to HBA context object.
14002 * @cmd_iocbq: pointer to the command iocbq structure.
14003 * @rsp_iocbq: pointer to the response iocbq structure.
14005 * This function handles the sequence abort response iocb command complete
14006 * event. It properly releases the memory allocated to the sequence abort
14010 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
14011 struct lpfc_iocbq
*cmd_iocbq
,
14012 struct lpfc_iocbq
*rsp_iocbq
)
14015 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
14017 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14018 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
14019 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14020 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14021 rsp_iocbq
->iocb
.ulpStatus
,
14022 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
14026 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14027 * @phba: Pointer to HBA context object.
14028 * @xri: xri id in transaction.
14030 * This function validates the xri maps to the known range of XRIs allocated an
14031 * used by the driver.
14034 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
14039 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
14040 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
14047 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14048 * @phba: Pointer to HBA context object.
14049 * @fc_hdr: pointer to a FC frame header.
14051 * This function sends a basic response to a previous unsol sequence abort
14052 * event after aborting the sequence handling.
14055 lpfc_sli4_seq_abort_rsp(struct lpfc_hba
*phba
,
14056 struct fc_frame_header
*fc_hdr
)
14058 struct lpfc_iocbq
*ctiocb
= NULL
;
14059 struct lpfc_nodelist
*ndlp
;
14060 uint16_t oxid
, rxid
, xri
, lxri
;
14061 uint32_t sid
, fctl
;
14065 if (!lpfc_is_link_up(phba
))
14068 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14069 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
14070 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
14072 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
14074 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14075 "1268 Find ndlp returned NULL for oxid:x%x "
14076 "SID:x%x\n", oxid
, sid
);
14080 /* Allocate buffer for rsp iocb */
14081 ctiocb
= lpfc_sli_get_iocbq(phba
);
14085 /* Extract the F_CTL field from FC_HDR */
14086 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
14088 icmd
= &ctiocb
->iocb
;
14089 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
14090 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
14091 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
14092 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
14093 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
14095 /* Fill in the rest of iocb fields */
14096 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
14097 icmd
->ulpBdeCount
= 0;
14099 icmd
->ulpClass
= CLASS3
;
14100 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
14101 ctiocb
->context1
= ndlp
;
14103 ctiocb
->iocb_cmpl
= NULL
;
14104 ctiocb
->vport
= phba
->pport
;
14105 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
14106 ctiocb
->sli4_lxritag
= NO_XRI
;
14107 ctiocb
->sli4_xritag
= NO_XRI
;
14109 if (fctl
& FC_FC_EX_CTX
)
14110 /* Exchange responder sent the abort so we
14116 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
14117 if (lxri
!= NO_XRI
)
14118 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
14119 (xri
== oxid
) ? rxid
: oxid
, 0);
14120 /* If the oxid maps to the FCP XRI range or if it is out of range,
14121 * send a BLS_RJT. The driver no longer has that exchange.
14122 * Override the IOCB for a BA_RJT.
14124 if (xri
> (phba
->sli4_hba
.max_cfg_param
.max_xri
+
14125 phba
->sli4_hba
.max_cfg_param
.xri_base
) ||
14126 xri
> (lpfc_sli4_get_els_iocb_cnt(phba
) +
14127 phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
14128 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14129 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14130 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14131 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14134 if (fctl
& FC_FC_EX_CTX
) {
14135 /* ABTS sent by responder to CT exchange, construction
14136 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14137 * field and RX_ID from ABTS for RX_ID field.
14139 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14141 /* ABTS sent by initiator to CT exchange, construction
14142 * of BA_ACC will need to allocate a new XRI as for the
14145 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14147 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14148 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14150 /* Xmit CT abts response on exchange <xid> */
14151 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14152 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14153 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14155 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14156 if (rc
== IOCB_ERROR
) {
14157 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
14158 "2925 Failed to issue CT ABTS RSP x%x on "
14159 "xri x%x, Data x%x\n",
14160 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14162 lpfc_sli_release_iocbq(phba
, ctiocb
);
14167 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14168 * @vport: Pointer to the vport on which this sequence was received
14169 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14171 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14172 * receive sequence is only partially assembed by the driver, it shall abort
14173 * the partially assembled frames for the sequence. Otherwise, if the
14174 * unsolicited receive sequence has been completely assembled and passed to
14175 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14176 * unsolicited sequence has been aborted. After that, it will issue a basic
14177 * accept to accept the abort.
14180 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14181 struct hbq_dmabuf
*dmabuf
)
14183 struct lpfc_hba
*phba
= vport
->phba
;
14184 struct fc_frame_header fc_hdr
;
14188 /* Make a copy of fc_hdr before the dmabuf being released */
14189 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14190 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14192 if (fctl
& FC_FC_EX_CTX
) {
14194 * ABTS sent by responder to exchange, just free the buffer
14196 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14199 * ABTS sent by initiator to exchange, need to do cleanup
14201 /* Try to abort partially assembled seq */
14202 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14204 /* Send abort to ULP if partially seq abort failed */
14205 if (abts_par
== false)
14206 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
14208 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14210 /* Send basic accept (BA_ACC) to the abort requester */
14211 lpfc_sli4_seq_abort_rsp(phba
, &fc_hdr
);
14215 * lpfc_seq_complete - Indicates if a sequence is complete
14216 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14218 * This function checks the sequence, starting with the frame described by
14219 * @dmabuf, to see if all the frames associated with this sequence are present.
14220 * the frames associated with this sequence are linked to the @dmabuf using the
14221 * dbuf list. This function looks for two major things. 1) That the first frame
14222 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14223 * set. 3) That there are no holes in the sequence count. The function will
14224 * return 1 when the sequence is complete, otherwise it will return 0.
14227 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14229 struct fc_frame_header
*hdr
;
14230 struct lpfc_dmabuf
*d_buf
;
14231 struct hbq_dmabuf
*seq_dmabuf
;
14235 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14236 /* make sure first fame of sequence has a sequence count of zero */
14237 if (hdr
->fh_seq_cnt
!= seq_count
)
14239 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14240 hdr
->fh_f_ctl
[1] << 8 |
14242 /* If last frame of sequence we can return success. */
14243 if (fctl
& FC_FC_END_SEQ
)
14245 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14246 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14247 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14248 /* If there is a hole in the sequence count then fail. */
14249 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14251 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14252 hdr
->fh_f_ctl
[1] << 8 |
14254 /* If last frame of sequence we can return success. */
14255 if (fctl
& FC_FC_END_SEQ
)
14262 * lpfc_prep_seq - Prep sequence for ULP processing
14263 * @vport: Pointer to the vport on which this sequence was received
14264 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14266 * This function takes a sequence, described by a list of frames, and creates
14267 * a list of iocbq structures to describe the sequence. This iocbq list will be
14268 * used to issue to the generic unsolicited sequence handler. This routine
14269 * returns a pointer to the first iocbq in the list. If the function is unable
14270 * to allocate an iocbq then it throw out the received frames that were not
14271 * able to be described and return a pointer to the first iocbq. If unable to
14272 * allocate any iocbqs (including the first) this function will return NULL.
14274 static struct lpfc_iocbq
*
14275 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14277 struct hbq_dmabuf
*hbq_buf
;
14278 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14279 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14280 struct fc_frame_header
*fc_hdr
;
14282 uint32_t len
, tot_len
;
14283 struct ulp_bde64
*pbde
;
14285 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14286 /* remove from receive buffer list */
14287 list_del_init(&seq_dmabuf
->hbuf
.list
);
14288 lpfc_update_rcv_time_stamp(vport
);
14289 /* get the Remote Port's SID */
14290 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14292 /* Get an iocbq struct to fill in. */
14293 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14295 /* Initialize the first IOCB. */
14296 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14297 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14299 /* Check FC Header to see what TYPE of frame we are rcv'ing */
14300 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
14301 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
14302 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
14303 sli4_did_from_fc_hdr(fc_hdr
);
14304 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
14306 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14307 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14308 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14309 be16_to_cpu(fc_hdr
->fh_ox_id
);
14310 /* iocbq is prepped for internal consumption. Physical vpi. */
14311 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14312 vport
->phba
->vpi_ids
[vport
->vpi
];
14313 /* put the first buffer into the first IOCBq */
14314 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14315 first_iocbq
->context3
= NULL
;
14316 first_iocbq
->iocb
.ulpBdeCount
= 1;
14317 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14318 LPFC_DATA_BUF_SIZE
;
14319 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14320 tot_len
= bf_get(lpfc_rcqe_length
,
14321 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14322 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14324 iocbq
= first_iocbq
;
14326 * Each IOCBq can have two Buffers assigned, so go through the list
14327 * of buffers for this sequence and save two buffers in each IOCBq
14329 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14331 lpfc_in_buf_free(vport
->phba
, d_buf
);
14334 if (!iocbq
->context3
) {
14335 iocbq
->context3
= d_buf
;
14336 iocbq
->iocb
.ulpBdeCount
++;
14337 pbde
= (struct ulp_bde64
*)
14338 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14339 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14341 /* We need to get the size out of the right CQE */
14342 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14343 len
= bf_get(lpfc_rcqe_length
,
14344 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14345 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14348 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14351 first_iocbq
->iocb
.ulpStatus
=
14352 IOSTAT_FCP_RSP_ERROR
;
14353 first_iocbq
->iocb
.un
.ulpWord
[4] =
14354 IOERR_NO_RESOURCES
;
14356 lpfc_in_buf_free(vport
->phba
, d_buf
);
14359 iocbq
->context2
= d_buf
;
14360 iocbq
->context3
= NULL
;
14361 iocbq
->iocb
.ulpBdeCount
= 1;
14362 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14363 LPFC_DATA_BUF_SIZE
;
14365 /* We need to get the size out of the right CQE */
14366 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14367 len
= bf_get(lpfc_rcqe_length
,
14368 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14370 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14372 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14373 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14376 return first_iocbq
;
14380 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14381 struct hbq_dmabuf
*seq_dmabuf
)
14383 struct fc_frame_header
*fc_hdr
;
14384 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
14385 struct lpfc_hba
*phba
= vport
->phba
;
14387 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14388 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
14390 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14391 "2707 Ring %d handler: Failed to allocate "
14392 "iocb Rctl x%x Type x%x received\n",
14394 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14397 if (!lpfc_complete_unsol_iocb(phba
,
14398 &phba
->sli
.ring
[LPFC_ELS_RING
],
14399 iocbq
, fc_hdr
->fh_r_ctl
,
14401 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14402 "2540 Ring %d handler: unexpected Rctl "
14403 "x%x Type x%x received\n",
14405 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14407 /* Free iocb created in lpfc_prep_seq */
14408 list_for_each_entry_safe(curr_iocb
, next_iocb
,
14409 &iocbq
->list
, list
) {
14410 list_del_init(&curr_iocb
->list
);
14411 lpfc_sli_release_iocbq(phba
, curr_iocb
);
14413 lpfc_sli_release_iocbq(phba
, iocbq
);
14417 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14418 * @phba: Pointer to HBA context object.
14420 * This function is called with no lock held. This function processes all
14421 * the received buffers and gives it to upper layers when a received buffer
14422 * indicates that it is the final frame in the sequence. The interrupt
14423 * service routine processes received buffers at interrupt contexts and adds
14424 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14425 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14426 * appropriate receive function when the final frame in a sequence is received.
14429 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
14430 struct hbq_dmabuf
*dmabuf
)
14432 struct hbq_dmabuf
*seq_dmabuf
;
14433 struct fc_frame_header
*fc_hdr
;
14434 struct lpfc_vport
*vport
;
14438 /* Process each received buffer */
14439 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14440 /* check to see if this a valid type of frame */
14441 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
14442 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14445 if ((bf_get(lpfc_cqe_code
,
14446 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
14447 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
14448 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14450 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
14451 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14453 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
14455 /* throw out the frame */
14456 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14460 /* d_id this frame is directed to */
14461 did
= sli4_did_from_fc_hdr(fc_hdr
);
14463 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
14464 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
14465 (did
!= Fabric_DID
)) {
14467 * Throw out the frame if we are not pt2pt.
14468 * The pt2pt protocol allows for discovery frames
14469 * to be received without a registered VPI.
14471 if (!(vport
->fc_flag
& FC_PT2PT
) ||
14472 (phba
->link_state
== LPFC_HBA_READY
)) {
14473 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14478 /* Handle the basic abort sequence (BA_ABTS) event */
14479 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
14480 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
14484 /* Link this frame */
14485 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
14487 /* unable to add frame to vport - throw it out */
14488 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14491 /* If not last frame in sequence continue processing frames. */
14492 if (!lpfc_seq_complete(seq_dmabuf
))
14495 /* Send the complete sequence to the upper layer protocol */
14496 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
14500 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14501 * @phba: pointer to lpfc hba data structure.
14503 * This routine is invoked to post rpi header templates to the
14504 * HBA consistent with the SLI-4 interface spec. This routine
14505 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14506 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14508 * This routine does not require any locks. It's usage is expected
14509 * to be driver load or reset recovery when the driver is
14514 * -EIO - The mailbox failed to complete successfully.
14515 * When this error occurs, the driver is not guaranteed
14516 * to have any rpi regions posted to the device and
14517 * must either attempt to repost the regions or take a
14521 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
14523 struct lpfc_rpi_hdr
*rpi_page
;
14527 /* SLI4 ports that support extents do not require RPI headers. */
14528 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14530 if (phba
->sli4_hba
.extents_in_use
)
14533 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
14535 * Assign the rpi headers a physical rpi only if the driver
14536 * has not initialized those resources. A port reset only
14537 * needs the headers posted.
14539 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
14541 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14543 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
14544 if (rc
!= MBX_SUCCESS
) {
14545 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14546 "2008 Error %d posting all rpi "
14554 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
14555 LPFC_RPI_RSRC_RDY
);
14560 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14561 * @phba: pointer to lpfc hba data structure.
14562 * @rpi_page: pointer to the rpi memory region.
14564 * This routine is invoked to post a single rpi header to the
14565 * HBA consistent with the SLI-4 interface spec. This memory region
14566 * maps up to 64 rpi context regions.
14570 * -ENOMEM - No available memory
14571 * -EIO - The mailbox failed to complete successfully.
14574 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
14576 LPFC_MBOXQ_t
*mboxq
;
14577 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
14579 uint32_t shdr_status
, shdr_add_status
;
14580 union lpfc_sli4_cfg_shdr
*shdr
;
14582 /* SLI4 ports that support extents do not require RPI headers. */
14583 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14585 if (phba
->sli4_hba
.extents_in_use
)
14588 /* The port is notified of the header region via a mailbox command. */
14589 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14591 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14592 "2001 Unable to allocate memory for issuing "
14593 "SLI_CONFIG_SPECIAL mailbox command\n");
14597 /* Post all rpi memory regions to the port. */
14598 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
14599 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14600 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
14601 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
14602 sizeof(struct lpfc_sli4_cfg_mhdr
),
14603 LPFC_SLI4_MBX_EMBED
);
14606 /* Post the physical rpi to the port for this rpi header. */
14607 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
14608 rpi_page
->start_rpi
);
14609 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
14610 hdr_tmpl
, rpi_page
->page_count
);
14612 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
14613 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
14614 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
14615 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
14616 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14617 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14618 if (rc
!= MBX_TIMEOUT
)
14619 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14620 if (shdr_status
|| shdr_add_status
|| rc
) {
14621 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14622 "2514 POST_RPI_HDR mailbox failed with "
14623 "status x%x add_status x%x, mbx status x%x\n",
14624 shdr_status
, shdr_add_status
, rc
);
14631 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14632 * @phba: pointer to lpfc hba data structure.
14634 * This routine is invoked to post rpi header templates to the
14635 * HBA consistent with the SLI-4 interface spec. This routine
14636 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14637 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14640 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14641 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14644 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
14647 uint16_t max_rpi
, rpi_limit
;
14648 uint16_t rpi_remaining
, lrpi
= 0;
14649 struct lpfc_rpi_hdr
*rpi_hdr
;
14651 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
14652 rpi_limit
= phba
->sli4_hba
.next_rpi
;
14655 * Fetch the next logical rpi. Because this index is logical,
14656 * the driver starts at 0 each time.
14658 spin_lock_irq(&phba
->hbalock
);
14659 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
14660 if (rpi
>= rpi_limit
)
14661 rpi
= LPFC_RPI_ALLOC_ERROR
;
14663 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
14664 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
14665 phba
->sli4_hba
.rpi_count
++;
14669 * Don't try to allocate more rpi header regions if the device limit
14670 * has been exhausted.
14672 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
14673 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
14674 spin_unlock_irq(&phba
->hbalock
);
14679 * RPI header postings are not required for SLI4 ports capable of
14682 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
14683 spin_unlock_irq(&phba
->hbalock
);
14688 * If the driver is running low on rpi resources, allocate another
14689 * page now. Note that the next_rpi value is used because
14690 * it represents how many are actually in use whereas max_rpi notes
14691 * how many are supported max by the device.
14693 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
14694 spin_unlock_irq(&phba
->hbalock
);
14695 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
14696 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
14698 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14699 "2002 Error Could not grow rpi "
14702 lrpi
= rpi_hdr
->start_rpi
;
14703 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14704 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
14712 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14713 * @phba: pointer to lpfc hba data structure.
14715 * This routine is invoked to release an rpi to the pool of
14716 * available rpis maintained by the driver.
14719 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14721 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
14722 phba
->sli4_hba
.rpi_count
--;
14723 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
14728 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14729 * @phba: pointer to lpfc hba data structure.
14731 * This routine is invoked to release an rpi to the pool of
14732 * available rpis maintained by the driver.
14735 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14737 spin_lock_irq(&phba
->hbalock
);
14738 __lpfc_sli4_free_rpi(phba
, rpi
);
14739 spin_unlock_irq(&phba
->hbalock
);
14743 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14744 * @phba: pointer to lpfc hba data structure.
14746 * This routine is invoked to remove the memory region that
14747 * provided rpi via a bitmask.
14750 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
14752 kfree(phba
->sli4_hba
.rpi_bmask
);
14753 kfree(phba
->sli4_hba
.rpi_ids
);
14754 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
14758 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14759 * @phba: pointer to lpfc hba data structure.
14761 * This routine is invoked to remove the memory region that
14762 * provided rpi via a bitmask.
14765 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
14766 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
14768 LPFC_MBOXQ_t
*mboxq
;
14769 struct lpfc_hba
*phba
= ndlp
->phba
;
14772 /* The port is notified of the header region via a mailbox command. */
14773 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14777 /* Post all rpi memory regions to the port. */
14778 lpfc_resume_rpi(mboxq
, ndlp
);
14780 mboxq
->mbox_cmpl
= cmpl
;
14781 mboxq
->context1
= arg
;
14782 mboxq
->context2
= ndlp
;
14784 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14785 mboxq
->vport
= ndlp
->vport
;
14786 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14787 if (rc
== MBX_NOT_FINISHED
) {
14788 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14789 "2010 Resume RPI Mailbox failed "
14790 "status %d, mbxStatus x%x\n", rc
,
14791 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14792 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14799 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14800 * @vport: Pointer to the vport for which the vpi is being initialized
14802 * This routine is invoked to activate a vpi with the port.
14806 * -Evalue otherwise
14809 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
14811 LPFC_MBOXQ_t
*mboxq
;
14813 int retval
= MBX_SUCCESS
;
14815 struct lpfc_hba
*phba
= vport
->phba
;
14816 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14819 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
14820 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
14821 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
14822 if (rc
!= MBX_SUCCESS
) {
14823 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
14824 "2022 INIT VPI Mailbox failed "
14825 "status %d, mbxStatus x%x\n", rc
,
14826 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14829 if (rc
!= MBX_TIMEOUT
)
14830 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
14836 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14837 * @phba: pointer to lpfc hba data structure.
14838 * @mboxq: Pointer to mailbox object.
14840 * This routine is invoked to manually add a single FCF record. The caller
14841 * must pass a completely initialized FCF_Record. This routine takes
14842 * care of the nonembedded mailbox operations.
14845 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
14848 union lpfc_sli4_cfg_shdr
*shdr
;
14849 uint32_t shdr_status
, shdr_add_status
;
14851 virt_addr
= mboxq
->sge_array
->addr
[0];
14852 /* The IOCTL status is embedded in the mailbox subheader. */
14853 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
14854 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14855 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14857 if ((shdr_status
|| shdr_add_status
) &&
14858 (shdr_status
!= STATUS_FCF_IN_USE
))
14859 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14860 "2558 ADD_FCF_RECORD mailbox failed with "
14861 "status x%x add_status x%x\n",
14862 shdr_status
, shdr_add_status
);
14864 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14868 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14869 * @phba: pointer to lpfc hba data structure.
14870 * @fcf_record: pointer to the initialized fcf record to add.
14872 * This routine is invoked to manually add a single FCF record. The caller
14873 * must pass a completely initialized FCF_Record. This routine takes
14874 * care of the nonembedded mailbox operations.
14877 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
14880 LPFC_MBOXQ_t
*mboxq
;
14883 dma_addr_t phys_addr
;
14884 struct lpfc_mbx_sge sge
;
14885 uint32_t alloc_len
, req_len
;
14888 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14890 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14891 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14895 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
14898 /* Allocate DMA memory and set up the non-embedded mailbox command */
14899 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14900 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
14901 req_len
, LPFC_SLI4_MBX_NEMBED
);
14902 if (alloc_len
< req_len
) {
14903 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14904 "2523 Allocated DMA memory size (x%x) is "
14905 "less than the requested DMA memory "
14906 "size (x%x)\n", alloc_len
, req_len
);
14907 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14912 * Get the first SGE entry from the non-embedded DMA memory. This
14913 * routine only uses a single SGE.
14915 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
14916 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
14917 virt_addr
= mboxq
->sge_array
->addr
[0];
14919 * Configure the FCF record for FCFI 0. This is the driver's
14920 * hardcoded default and gets used in nonFIP mode.
14922 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
14923 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
14924 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
14927 * Copy the fcf_index and the FCF Record Data. The data starts after
14928 * the FCoE header plus word10. The data copy needs to be endian
14931 bytep
+= sizeof(uint32_t);
14932 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
14933 mboxq
->vport
= phba
->pport
;
14934 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
14935 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14936 if (rc
== MBX_NOT_FINISHED
) {
14937 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14938 "2515 ADD_FCF_RECORD mailbox failed with "
14939 "status 0x%x\n", rc
);
14940 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14949 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
14950 * @phba: pointer to lpfc hba data structure.
14951 * @fcf_record: pointer to the fcf record to write the default data.
14952 * @fcf_index: FCF table entry index.
14954 * This routine is invoked to build the driver's default FCF record. The
14955 * values used are hardcoded. This routine handles memory initialization.
14959 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
14960 struct fcf_record
*fcf_record
,
14961 uint16_t fcf_index
)
14963 memset(fcf_record
, 0, sizeof(struct fcf_record
));
14964 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
14965 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
14966 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
14967 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
14968 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
14969 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
14970 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
14971 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
14972 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
14973 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
14974 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
14975 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
14976 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
14977 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
14978 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
14979 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
14980 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
14981 /* Set the VLAN bit map */
14982 if (phba
->valid_vlan
) {
14983 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
14984 = 1 << (phba
->vlan_id
% 8);
14989 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
14990 * @phba: pointer to lpfc hba data structure.
14991 * @fcf_index: FCF table entry offset.
14993 * This routine is invoked to scan the entire FCF table by reading FCF
14994 * record and processing it one at a time starting from the @fcf_index
14995 * for initial FCF discovery or fast FCF failover rediscovery.
14997 * Return 0 if the mailbox command is submitted successfully, none 0
15001 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15004 LPFC_MBOXQ_t
*mboxq
;
15006 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
15007 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
15008 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15010 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15011 "2000 Failed to allocate mbox for "
15014 goto fail_fcf_scan
;
15016 /* Construct the read FCF record mailbox command */
15017 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15020 goto fail_fcf_scan
;
15022 /* Issue the mailbox command asynchronously */
15023 mboxq
->vport
= phba
->pport
;
15024 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
15026 spin_lock_irq(&phba
->hbalock
);
15027 phba
->hba_flag
|= FCF_TS_INPROG
;
15028 spin_unlock_irq(&phba
->hbalock
);
15030 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15031 if (rc
== MBX_NOT_FINISHED
)
15034 /* Reset eligible FCF count for new scan */
15035 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
15036 phba
->fcf
.eligible_fcf_cnt
= 0;
15042 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15043 /* FCF scan failed, clear FCF_TS_INPROG flag */
15044 spin_lock_irq(&phba
->hbalock
);
15045 phba
->hba_flag
&= ~FCF_TS_INPROG
;
15046 spin_unlock_irq(&phba
->hbalock
);
15052 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15053 * @phba: pointer to lpfc hba data structure.
15054 * @fcf_index: FCF table entry offset.
15056 * This routine is invoked to read an FCF record indicated by @fcf_index
15057 * and to use it for FLOGI roundrobin FCF failover.
15059 * Return 0 if the mailbox command is submitted successfully, none 0
15063 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15066 LPFC_MBOXQ_t
*mboxq
;
15068 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15070 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15071 "2763 Failed to allocate mbox for "
15074 goto fail_fcf_read
;
15076 /* Construct the read FCF record mailbox command */
15077 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15080 goto fail_fcf_read
;
15082 /* Issue the mailbox command asynchronously */
15083 mboxq
->vport
= phba
->pport
;
15084 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
15085 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15086 if (rc
== MBX_NOT_FINISHED
)
15092 if (error
&& mboxq
)
15093 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15098 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15099 * @phba: pointer to lpfc hba data structure.
15100 * @fcf_index: FCF table entry offset.
15102 * This routine is invoked to read an FCF record indicated by @fcf_index to
15103 * determine whether it's eligible for FLOGI roundrobin failover list.
15105 * Return 0 if the mailbox command is submitted successfully, none 0
15109 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15112 LPFC_MBOXQ_t
*mboxq
;
15114 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15116 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15117 "2758 Failed to allocate mbox for "
15120 goto fail_fcf_read
;
15122 /* Construct the read FCF record mailbox command */
15123 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15126 goto fail_fcf_read
;
15128 /* Issue the mailbox command asynchronously */
15129 mboxq
->vport
= phba
->pport
;
15130 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
15131 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15132 if (rc
== MBX_NOT_FINISHED
)
15138 if (error
&& mboxq
)
15139 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15144 * lpfc_check_next_fcf_pri
15145 * phba pointer to the lpfc_hba struct for this port.
15146 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15147 * routine when the rr_bmask is empty. The FCF indecies are put into the
15148 * rr_bmask based on their priority level. Starting from the highest priority
15149 * to the lowest. The most likely FCF candidate will be in the highest
15150 * priority group. When this routine is called it searches the fcf_pri list for
15151 * next lowest priority group and repopulates the rr_bmask with only those
15154 * 1=success 0=failure
15157 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15159 uint16_t next_fcf_pri
;
15160 uint16_t last_index
;
15161 struct lpfc_fcf_pri
*fcf_pri
;
15165 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15166 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15167 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15168 "3060 Last IDX %d\n", last_index
);
15169 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
15170 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15171 "3061 Last IDX %d\n", last_index
);
15172 return 0; /* Empty rr list */
15176 * Clear the rr_bmask and set all of the bits that are at this
15179 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15180 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15181 spin_lock_irq(&phba
->hbalock
);
15182 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15183 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15186 * the 1st priority that has not FLOGI failed
15187 * will be the highest.
15190 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15191 spin_unlock_irq(&phba
->hbalock
);
15192 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15193 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15194 fcf_pri
->fcf_rec
.fcf_index
);
15198 spin_lock_irq(&phba
->hbalock
);
15201 * if next_fcf_pri was not set above and the list is not empty then
15202 * we have failed flogis on all of them. So reset flogi failed
15203 * and start at the begining.
15205 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15206 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15207 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15209 * the 1st priority that has not FLOGI failed
15210 * will be the highest.
15213 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15214 spin_unlock_irq(&phba
->hbalock
);
15215 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15216 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15217 fcf_pri
->fcf_rec
.fcf_index
);
15221 spin_lock_irq(&phba
->hbalock
);
15225 spin_unlock_irq(&phba
->hbalock
);
15230 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15231 * @phba: pointer to lpfc hba data structure.
15233 * This routine is to get the next eligible FCF record index in a round
15234 * robin fashion. If the next eligible FCF record index equals to the
15235 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15236 * shall be returned, otherwise, the next eligible FCF record's index
15237 * shall be returned.
15240 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15242 uint16_t next_fcf_index
;
15244 /* Search start from next bit of currently registered FCF index */
15246 next_fcf_index
= (phba
->fcf
.current_rec
.fcf_indx
+ 1) %
15247 LPFC_SLI4_FCF_TBL_INDX_MAX
;
15248 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15249 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15252 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15253 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15255 * If we have wrapped then we need to clear the bits that
15256 * have been tested so that we can detect when we should
15257 * change the priority level.
15259 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15260 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15264 /* Check roundrobin failover list empty condition */
15265 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15266 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15268 * If next fcf index is not found check if there are lower
15269 * Priority level fcf's in the fcf_priority list.
15270 * Set up the rr_bmask with all of the avaiable fcf bits
15271 * at that level and continue the selection process.
15273 if (lpfc_check_next_fcf_pri_level(phba
))
15274 goto next_priority
;
15275 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15276 "2844 No roundrobin failover FCF available\n");
15277 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15278 return LPFC_FCOE_FCF_NEXT_NONE
;
15280 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15281 "3063 Only FCF available idx %d, flag %x\n",
15283 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15284 return next_fcf_index
;
15288 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15289 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15290 LPFC_FCF_FLOGI_FAILED
)
15291 goto next_priority
;
15293 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15294 "2845 Get next roundrobin failover FCF (x%x)\n",
15297 return next_fcf_index
;
15301 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15302 * @phba: pointer to lpfc hba data structure.
15304 * This routine sets the FCF record index in to the eligible bmask for
15305 * roundrobin failover search. It checks to make sure that the index
15306 * does not go beyond the range of the driver allocated bmask dimension
15307 * before setting the bit.
15309 * Returns 0 if the index bit successfully set, otherwise, it returns
15313 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15315 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15316 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15317 "2610 FCF (x%x) reached driver's book "
15318 "keeping dimension:x%x\n",
15319 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15322 /* Set the eligible FCF record index bmask */
15323 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15325 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15326 "2790 Set FCF (x%x) to roundrobin FCF failover "
15327 "bmask\n", fcf_index
);
15333 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15334 * @phba: pointer to lpfc hba data structure.
15336 * This routine clears the FCF record index from the eligible bmask for
15337 * roundrobin failover search. It checks to make sure that the index
15338 * does not go beyond the range of the driver allocated bmask dimension
15339 * before clearing the bit.
15342 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15344 struct lpfc_fcf_pri
*fcf_pri
;
15345 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15346 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15347 "2762 FCF (x%x) reached driver's book "
15348 "keeping dimension:x%x\n",
15349 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15352 /* Clear the eligible FCF record index bmask */
15353 spin_lock_irq(&phba
->hbalock
);
15354 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15355 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15356 list_del_init(&fcf_pri
->list
);
15360 spin_unlock_irq(&phba
->hbalock
);
15361 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15363 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15364 "2791 Clear FCF (x%x) from roundrobin failover "
15365 "bmask\n", fcf_index
);
15369 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15370 * @phba: pointer to lpfc hba data structure.
15372 * This routine is the completion routine for the rediscover FCF table mailbox
15373 * command. If the mailbox command returned failure, it will try to stop the
15374 * FCF rediscover wait timer.
15377 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
15379 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15380 uint32_t shdr_status
, shdr_add_status
;
15382 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15384 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
15385 &redisc_fcf
->header
.cfg_shdr
.response
);
15386 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
15387 &redisc_fcf
->header
.cfg_shdr
.response
);
15388 if (shdr_status
|| shdr_add_status
) {
15389 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15390 "2746 Requesting for FCF rediscovery failed "
15391 "status x%x add_status x%x\n",
15392 shdr_status
, shdr_add_status
);
15393 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
15394 spin_lock_irq(&phba
->hbalock
);
15395 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
15396 spin_unlock_irq(&phba
->hbalock
);
15398 * CVL event triggered FCF rediscover request failed,
15399 * last resort to re-try current registered FCF entry.
15401 lpfc_retry_pport_discovery(phba
);
15403 spin_lock_irq(&phba
->hbalock
);
15404 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
15405 spin_unlock_irq(&phba
->hbalock
);
15407 * DEAD FCF event triggered FCF rediscover request
15408 * failed, last resort to fail over as a link down
15409 * to FCF registration.
15411 lpfc_sli4_fcf_dead_failthrough(phba
);
15414 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15415 "2775 Start FCF rediscover quiescent timer\n");
15417 * Start FCF rediscovery wait timer for pending FCF
15418 * before rescan FCF record table.
15420 lpfc_fcf_redisc_wait_start_timer(phba
);
15423 mempool_free(mbox
, phba
->mbox_mem_pool
);
15427 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15428 * @phba: pointer to lpfc hba data structure.
15430 * This routine is invoked to request for rediscovery of the entire FCF table
15434 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
15436 LPFC_MBOXQ_t
*mbox
;
15437 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15440 /* Cancel retry delay timers to all vports before FCF rediscover */
15441 lpfc_cancel_all_vport_retry_delay_timer(phba
);
15443 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15445 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15446 "2745 Failed to allocate mbox for "
15447 "requesting FCF rediscover.\n");
15451 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
15452 sizeof(struct lpfc_sli4_cfg_mhdr
));
15453 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15454 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
15455 length
, LPFC_SLI4_MBX_EMBED
);
15457 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15458 /* Set count to 0 for invalidating the entire FCF database */
15459 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
15461 /* Issue the mailbox command asynchronously */
15462 mbox
->vport
= phba
->pport
;
15463 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
15464 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
15466 if (rc
== MBX_NOT_FINISHED
) {
15467 mempool_free(mbox
, phba
->mbox_mem_pool
);
15474 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15475 * @phba: pointer to lpfc hba data structure.
15477 * This function is the failover routine as a last resort to the FCF DEAD
15478 * event when driver failed to perform fast FCF failover.
15481 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
15483 uint32_t link_state
;
15486 * Last resort as FCF DEAD event failover will treat this as
15487 * a link down, but save the link state because we don't want
15488 * it to be changed to Link Down unless it is already down.
15490 link_state
= phba
->link_state
;
15491 lpfc_linkdown(phba
);
15492 phba
->link_state
= link_state
;
15494 /* Unregister FCF if no devices connected to it */
15495 lpfc_unregister_unused_fcf(phba
);
15499 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15500 * @phba: pointer to lpfc hba data structure.
15501 * @rgn23_data: pointer to configure region 23 data.
15503 * This function gets SLI3 port configure region 23 data through memory dump
15504 * mailbox command. When it successfully retrieves data, the size of the data
15505 * will be returned, otherwise, 0 will be returned.
15508 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15510 LPFC_MBOXQ_t
*pmb
= NULL
;
15512 uint32_t offset
= 0;
15518 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15520 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15521 "2600 failed to allocate mailbox memory\n");
15527 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
15528 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
15530 if (rc
!= MBX_SUCCESS
) {
15531 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15532 "2601 failed to read config "
15533 "region 23, rc 0x%x Status 0x%x\n",
15534 rc
, mb
->mbxStatus
);
15535 mb
->un
.varDmp
.word_cnt
= 0;
15538 * dump mem may return a zero when finished or we got a
15539 * mailbox error, either way we are done.
15541 if (mb
->un
.varDmp
.word_cnt
== 0)
15543 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
15544 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
15546 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
15547 rgn23_data
+ offset
,
15548 mb
->un
.varDmp
.word_cnt
);
15549 offset
+= mb
->un
.varDmp
.word_cnt
;
15550 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
15552 mempool_free(pmb
, phba
->mbox_mem_pool
);
15557 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15558 * @phba: pointer to lpfc hba data structure.
15559 * @rgn23_data: pointer to configure region 23 data.
15561 * This function gets SLI4 port configure region 23 data through memory dump
15562 * mailbox command. When it successfully retrieves data, the size of the data
15563 * will be returned, otherwise, 0 will be returned.
15566 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15568 LPFC_MBOXQ_t
*mboxq
= NULL
;
15569 struct lpfc_dmabuf
*mp
= NULL
;
15570 struct lpfc_mqe
*mqe
;
15571 uint32_t data_length
= 0;
15577 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15579 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15580 "3105 failed to allocate mailbox memory\n");
15584 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
15586 mqe
= &mboxq
->u
.mqe
;
15587 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
15588 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15591 data_length
= mqe
->un
.mb_words
[5];
15592 if (data_length
== 0)
15594 if (data_length
> DMP_RGN23_SIZE
) {
15598 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
15600 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15602 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15605 return data_length
;
15609 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15610 * @phba: pointer to lpfc hba data structure.
15612 * This function read region 23 and parse TLV for port status to
15613 * decide if the user disaled the port. If the TLV indicates the
15614 * port is disabled, the hba_flag is set accordingly.
15617 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
15619 uint8_t *rgn23_data
= NULL
;
15620 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
15621 uint32_t offset
= 0;
15623 /* Get adapter Region 23 data */
15624 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
15628 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15629 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
15631 if_type
= bf_get(lpfc_sli_intf_if_type
,
15632 &phba
->sli4_hba
.sli_intf
);
15633 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
15635 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
15641 /* Check the region signature first */
15642 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
15643 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15644 "2619 Config region 23 has bad signature\n");
15649 /* Check the data structure version */
15650 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
15651 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15652 "2620 Config region 23 has bad version\n");
15657 /* Parse TLV entries in the region */
15658 while (offset
< data_size
) {
15659 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
15662 * If the TLV is not driver specific TLV or driver id is
15663 * not linux driver id, skip the record.
15665 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
15666 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
15667 (rgn23_data
[offset
+ 3] != 0)) {
15668 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15672 /* Driver found a driver specific TLV in the config region */
15673 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
15678 * Search for configured port state sub-TLV.
15680 while ((offset
< data_size
) &&
15681 (tlv_offset
< sub_tlv_len
)) {
15682 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
15687 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
15688 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15689 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15693 /* This HBA contains PORT_STE configured */
15694 if (!rgn23_data
[offset
+ 2])
15695 phba
->hba_flag
|= LINK_DISABLED
;
15707 * lpfc_wr_object - write an object to the firmware
15708 * @phba: HBA structure that indicates port to create a queue on.
15709 * @dmabuf_list: list of dmabufs to write to the port.
15710 * @size: the total byte value of the objects to write to the port.
15711 * @offset: the current offset to be used to start the transfer.
15713 * This routine will create a wr_object mailbox command to send to the port.
15714 * the mailbox command will be constructed using the dma buffers described in
15715 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
15716 * BDEs that the imbedded mailbox can support. The @offset variable will be
15717 * used to indicate the starting offset of the transfer and will also return
15718 * the offset after the write object mailbox has completed. @size is used to
15719 * determine the end of the object and whether the eof bit should be set.
15721 * Return 0 is successful and offset will contain the the new offset to use
15722 * for the next write.
15723 * Return negative value for error cases.
15726 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
15727 uint32_t size
, uint32_t *offset
)
15729 struct lpfc_mbx_wr_object
*wr_object
;
15730 LPFC_MBOXQ_t
*mbox
;
15732 uint32_t shdr_status
, shdr_add_status
;
15734 union lpfc_sli4_cfg_shdr
*shdr
;
15735 struct lpfc_dmabuf
*dmabuf
;
15736 uint32_t written
= 0;
15738 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15742 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15743 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
15744 sizeof(struct lpfc_mbx_wr_object
) -
15745 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15747 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
15748 wr_object
->u
.request
.write_offset
= *offset
;
15749 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
15750 wr_object
->u
.request
.object_name
[0] =
15751 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
15752 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
15753 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
15754 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
15756 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
15757 wr_object
->u
.request
.bde
[i
].addrHigh
=
15758 putPaddrHigh(dmabuf
->phys
);
15759 if (written
+ SLI4_PAGE_SIZE
>= size
) {
15760 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15762 written
+= (size
- written
);
15763 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
15765 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15767 written
+= SLI4_PAGE_SIZE
;
15771 wr_object
->u
.request
.bde_count
= i
;
15772 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
15773 if (!phba
->sli4_hba
.intr_enable
)
15774 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15776 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15777 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15779 /* The IOCTL status is embedded in the mailbox subheader. */
15780 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
15781 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15782 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15783 if (rc
!= MBX_TIMEOUT
)
15784 mempool_free(mbox
, phba
->mbox_mem_pool
);
15785 if (shdr_status
|| shdr_add_status
|| rc
) {
15786 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15787 "3025 Write Object mailbox failed with "
15788 "status x%x add_status x%x, mbx status x%x\n",
15789 shdr_status
, shdr_add_status
, rc
);
15792 *offset
+= wr_object
->u
.response
.actual_write_length
;
15797 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
15798 * @vport: pointer to vport data structure.
15800 * This function iterate through the mailboxq and clean up all REG_LOGIN
15801 * and REG_VPI mailbox commands associated with the vport. This function
15802 * is called when driver want to restart discovery of the vport due to
15803 * a Clear Virtual Link event.
15806 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
15808 struct lpfc_hba
*phba
= vport
->phba
;
15809 LPFC_MBOXQ_t
*mb
, *nextmb
;
15810 struct lpfc_dmabuf
*mp
;
15811 struct lpfc_nodelist
*ndlp
;
15812 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
15813 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
15814 LIST_HEAD(mbox_cmd_list
);
15815 uint8_t restart_loop
;
15817 /* Clean up internally queued mailbox commands with the vport */
15818 spin_lock_irq(&phba
->hbalock
);
15819 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
15820 if (mb
->vport
!= vport
)
15823 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15824 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15827 list_del(&mb
->list
);
15828 list_add_tail(&mb
->list
, &mbox_cmd_list
);
15830 /* Clean up active mailbox command with the vport */
15831 mb
= phba
->sli
.mbox_active
;
15832 if (mb
&& (mb
->vport
== vport
)) {
15833 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
15834 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
15835 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15836 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15837 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15838 /* Put reference count for delayed processing */
15839 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
15840 /* Unregister the RPI when mailbox complete */
15841 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15844 /* Cleanup any mailbox completions which are not yet processed */
15847 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
15849 * If this mailox is already processed or it is
15850 * for another vport ignore it.
15852 if ((mb
->vport
!= vport
) ||
15853 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
15856 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15857 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15860 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15861 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15862 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15863 /* Unregister the RPI when mailbox complete */
15864 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15866 spin_unlock_irq(&phba
->hbalock
);
15867 spin_lock(shost
->host_lock
);
15868 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15869 spin_unlock(shost
->host_lock
);
15870 spin_lock_irq(&phba
->hbalock
);
15874 } while (restart_loop
);
15876 spin_unlock_irq(&phba
->hbalock
);
15878 /* Release the cleaned-up mailbox commands */
15879 while (!list_empty(&mbox_cmd_list
)) {
15880 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
15881 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15882 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
15884 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15887 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
15888 mb
->context2
= NULL
;
15890 spin_lock(shost
->host_lock
);
15891 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15892 spin_unlock(shost
->host_lock
);
15893 lpfc_nlp_put(ndlp
);
15896 mempool_free(mb
, phba
->mbox_mem_pool
);
15899 /* Release the ndlp with the cleaned-up active mailbox command */
15900 if (act_mbx_ndlp
) {
15901 spin_lock(shost
->host_lock
);
15902 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15903 spin_unlock(shost
->host_lock
);
15904 lpfc_nlp_put(act_mbx_ndlp
);
15909 * lpfc_drain_txq - Drain the txq
15910 * @phba: Pointer to HBA context object.
15912 * This function attempt to submit IOCBs on the txq
15913 * to the adapter. For SLI4 adapters, the txq contains
15914 * ELS IOCBs that have been deferred because the there
15915 * are no SGLs. This congestion can occur with large
15916 * vport counts during node discovery.
15920 lpfc_drain_txq(struct lpfc_hba
*phba
)
15922 LIST_HEAD(completions
);
15923 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
15924 struct lpfc_iocbq
*piocbq
= 0;
15925 unsigned long iflags
= 0;
15926 char *fail_msg
= NULL
;
15927 struct lpfc_sglq
*sglq
;
15928 union lpfc_wqe wqe
;
15930 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15931 if (pring
->txq_cnt
> pring
->txq_max
)
15932 pring
->txq_max
= pring
->txq_cnt
;
15934 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15936 while (pring
->txq_cnt
) {
15937 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15939 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
15941 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15942 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15943 "2823 txq empty and txq_cnt is %d\n ",
15947 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
15949 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
15950 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15954 /* The xri and iocb resources secured,
15955 * attempt to issue request
15957 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
15958 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
15959 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
15960 fail_msg
= "to convert bpl to sgl";
15961 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
15962 fail_msg
= "to convert iocb to wqe";
15963 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
15964 fail_msg
= " - Wq is full";
15966 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
15969 /* Failed means we can't issue and need to cancel */
15970 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15971 "2822 IOCB failed %s iotag 0x%x "
15974 piocbq
->iotag
, piocbq
->sli4_xritag
);
15975 list_add_tail(&piocbq
->list
, &completions
);
15977 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15980 /* Cancel all the IOCBs that cannot be issued */
15981 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
15982 IOERR_SLI_ABORTED
);
15984 return pring
->txq_cnt
;