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
;
98 /* sanity check on queue memory */
101 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
103 /* If the host has not yet processed the next entry then we are done */
104 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
106 /* set consumption flag every once in a while */
107 if (!((q
->host_index
+ 1) % q
->entry_repost
))
108 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
109 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
110 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
111 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
113 /* Update the host index before invoking device */
114 host_index
= q
->host_index
;
115 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
119 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
120 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
121 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
122 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
123 readl(q
->phba
->sli4_hba
.WQDBregaddr
); /* Flush */
129 * lpfc_sli4_wq_release - Updates internal hba index for WQ
130 * @q: The Work Queue to operate on.
131 * @index: The index to advance the hba index to.
133 * This routine will update the HBA index of a queue to reflect consumption of
134 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
135 * an entry the host calls this function to update the queue's internal
136 * pointers. This routine returns the number of entries that were consumed by
140 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
142 uint32_t released
= 0;
144 /* sanity check on queue memory */
148 if (q
->hba_index
== index
)
151 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
153 } while (q
->hba_index
!= index
);
158 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
159 * @q: The Mailbox Queue to operate on.
160 * @wqe: The Mailbox Queue Entry to put on the Work queue.
162 * This routine will copy the contents of @mqe to the next available entry on
163 * the @q. This function will then ring the Work Queue Doorbell to signal the
164 * HBA to start processing the Work Queue Entry. This function returns 0 if
165 * successful. If no entries are available on @q then this function will return
167 * The caller is expected to hold the hbalock when calling this routine.
170 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
172 struct lpfc_mqe
*temp_mqe
;
173 struct lpfc_register doorbell
;
176 /* sanity check on queue memory */
179 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
181 /* If the host has not yet processed the next entry then we are done */
182 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
184 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
185 /* Save off the mailbox pointer for completion */
186 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
188 /* Update the host index before invoking device */
189 host_index
= q
->host_index
;
190 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
194 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
195 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
196 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
197 readl(q
->phba
->sli4_hba
.MQDBregaddr
); /* Flush */
202 * lpfc_sli4_mq_release - Updates internal hba index for MQ
203 * @q: The Mailbox Queue to operate on.
205 * This routine will update the HBA index of a queue to reflect consumption of
206 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
207 * an entry the host calls this function to update the queue's internal
208 * pointers. This routine returns the number of entries that were consumed by
212 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
214 /* sanity check on queue memory */
218 /* Clear the mailbox pointer for completion */
219 q
->phba
->mbox
= NULL
;
220 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
225 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
226 * @q: The Event Queue to get the first valid EQE from
228 * This routine will get the first valid Event Queue Entry from @q, update
229 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
230 * the Queue (no more work to do), or the Queue is full of EQEs that have been
231 * processed, but not popped back to the HBA then this routine will return NULL.
233 static struct lpfc_eqe
*
234 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
236 struct lpfc_eqe
*eqe
;
238 /* sanity check on queue memory */
241 eqe
= q
->qe
[q
->hba_index
].eqe
;
243 /* If the next EQE is not valid then we are done */
244 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
246 /* If the host has not yet processed the next entry then we are done */
247 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
250 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
255 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
256 * @q: The Event Queue that the host has completed processing for.
257 * @arm: Indicates whether the host wants to arms this CQ.
259 * This routine will mark all Event Queue Entries on @q, from the last
260 * known completed entry to the last entry that was processed, as completed
261 * by clearing the valid bit for each completion queue entry. Then it will
262 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
263 * The internal host index in the @q will be updated by this routine to indicate
264 * that the host has finished processing the entries. The @arm parameter
265 * indicates that the queue should be rearmed when ringing the doorbell.
267 * This function will return the number of EQEs that were popped.
270 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
272 uint32_t released
= 0;
273 struct lpfc_eqe
*temp_eqe
;
274 struct lpfc_register doorbell
;
276 /* sanity check on queue memory */
280 /* while there are valid entries */
281 while (q
->hba_index
!= q
->host_index
) {
282 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
283 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
285 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
287 if (unlikely(released
== 0 && !arm
))
290 /* ring doorbell for number popped */
293 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
294 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
296 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
297 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
298 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
299 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
300 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
301 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
302 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
303 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
304 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
309 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
310 * @q: The Completion Queue to get the first valid CQE from
312 * This routine will get the first valid Completion Queue Entry from @q, update
313 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
314 * the Queue (no more work to do), or the Queue is full of CQEs that have been
315 * processed, but not popped back to the HBA then this routine will return NULL.
317 static struct lpfc_cqe
*
318 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
320 struct lpfc_cqe
*cqe
;
322 /* sanity check on queue memory */
326 /* If the next CQE is not valid then we are done */
327 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
329 /* If the host has not yet processed the next entry then we are done */
330 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
333 cqe
= q
->qe
[q
->hba_index
].cqe
;
334 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
339 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
340 * @q: The Completion Queue that the host has completed processing for.
341 * @arm: Indicates whether the host wants to arms this CQ.
343 * This routine will mark all Completion queue entries on @q, from the last
344 * known completed entry to the last entry that was processed, as completed
345 * by clearing the valid bit for each completion queue entry. Then it will
346 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
347 * The internal host index in the @q will be updated by this routine to indicate
348 * that the host has finished processing the entries. The @arm parameter
349 * indicates that the queue should be rearmed when ringing the doorbell.
351 * This function will return the number of CQEs that were released.
354 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
356 uint32_t released
= 0;
357 struct lpfc_cqe
*temp_qe
;
358 struct lpfc_register doorbell
;
360 /* sanity check on queue memory */
363 /* while there are valid entries */
364 while (q
->hba_index
!= q
->host_index
) {
365 temp_qe
= q
->qe
[q
->host_index
].cqe
;
366 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
368 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
370 if (unlikely(released
== 0 && !arm
))
373 /* ring doorbell for number popped */
376 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
377 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
378 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
379 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
380 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
381 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
382 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
387 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
388 * @q: The Header Receive Queue to operate on.
389 * @wqe: The Receive Queue Entry to put on the Receive queue.
391 * This routine will copy the contents of @wqe to the next available entry on
392 * the @q. This function will then ring the Receive Queue Doorbell to signal the
393 * HBA to start processing the Receive Queue Entry. This function returns the
394 * index that the rqe was copied to if successful. If no entries are available
395 * on @q then this function will return -ENOMEM.
396 * The caller is expected to hold the hbalock when calling this routine.
399 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
400 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
402 struct lpfc_rqe
*temp_hrqe
;
403 struct lpfc_rqe
*temp_drqe
;
404 struct lpfc_register doorbell
;
405 int put_index
= hq
->host_index
;
407 /* sanity check on queue memory */
408 if (unlikely(!hq
) || unlikely(!dq
))
410 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
411 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
413 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
415 if (hq
->host_index
!= dq
->host_index
)
417 /* If the host has not yet processed the next entry then we are done */
418 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
420 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
421 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
423 /* Update the host index to point to the next slot */
424 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
425 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
427 /* Ring The Header Receive Queue Doorbell */
428 if (!(hq
->host_index
% hq
->entry_repost
)) {
430 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
432 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
433 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
439 * lpfc_sli4_rq_release - Updates internal hba index for RQ
440 * @q: The Header Receive Queue to operate on.
442 * This routine will update the HBA index of a queue to reflect consumption of
443 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
444 * consumed an entry the host calls this function to update the queue's
445 * internal pointers. This routine returns the number of entries that were
446 * consumed by the HBA.
449 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
451 /* sanity check on queue memory */
452 if (unlikely(!hq
) || unlikely(!dq
))
455 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
457 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
458 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
463 * lpfc_cmd_iocb - Get next command iocb entry in the ring
464 * @phba: Pointer to HBA context object.
465 * @pring: Pointer to driver SLI ring object.
467 * This function returns pointer to next command iocb entry
468 * in the command ring. The caller must hold hbalock to prevent
469 * other threads consume the next command iocb.
470 * SLI-2/SLI-3 provide different sized iocbs.
472 static inline IOCB_t
*
473 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
475 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
476 pring
->cmdidx
* phba
->iocb_cmd_size
);
480 * lpfc_resp_iocb - Get next response iocb entry in the ring
481 * @phba: Pointer to HBA context object.
482 * @pring: Pointer to driver SLI ring object.
484 * This function returns pointer to next response iocb entry
485 * in the response ring. The caller must hold hbalock to make sure
486 * that no other thread consume the next response iocb.
487 * SLI-2/SLI-3 provide different sized iocbs.
489 static inline IOCB_t
*
490 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
492 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
493 pring
->rspidx
* phba
->iocb_rsp_size
);
497 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
498 * @phba: Pointer to HBA context object.
500 * This function is called with hbalock held. This function
501 * allocates a new driver iocb object from the iocb pool. If the
502 * allocation is successful, it returns pointer to the newly
503 * allocated iocb object else it returns NULL.
506 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
508 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
509 struct lpfc_iocbq
* iocbq
= NULL
;
511 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
514 if (phba
->iocb_cnt
> phba
->iocb_max
)
515 phba
->iocb_max
= phba
->iocb_cnt
;
520 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
521 * @phba: Pointer to HBA context object.
522 * @xritag: XRI value.
524 * This function clears the sglq pointer from the array of acive
525 * sglq's. The xritag that is passed in is used to index into the
526 * array. Before the xritag can be used it needs to be adjusted
527 * by subtracting the xribase.
529 * Returns sglq ponter = success, NULL = Failure.
531 static struct lpfc_sglq
*
532 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
534 struct lpfc_sglq
*sglq
;
536 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
537 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
542 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
543 * @phba: Pointer to HBA context object.
544 * @xritag: XRI value.
546 * This function returns the sglq pointer from the array of acive
547 * sglq's. The xritag that is passed in is used to index into the
548 * array. Before the xritag can be used it needs to be adjusted
549 * by subtracting the xribase.
551 * Returns sglq ponter = success, NULL = Failure.
554 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
556 struct lpfc_sglq
*sglq
;
558 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
563 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
564 * @phba: Pointer to HBA context object.
565 * @xritag: xri used in this exchange.
566 * @rrq: The RRQ to be cleared.
570 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
572 struct lpfc_node_rrq
*rrq
)
574 struct lpfc_nodelist
*ndlp
= NULL
;
576 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
577 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
579 /* The target DID could have been swapped (cable swap)
580 * we should use the ndlp from the findnode if it is
583 if ((!ndlp
) && rrq
->ndlp
)
589 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
)) {
592 rrq
->rrq_stop_time
= 0;
595 mempool_free(rrq
, phba
->rrq_pool
);
599 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
600 * @phba: Pointer to HBA context object.
602 * This function is called with hbalock held. This function
603 * Checks if stop_time (ratov from setting rrq active) has
604 * been reached, if it has and the send_rrq flag is set then
605 * it will call lpfc_send_rrq. If the send_rrq flag is not set
606 * then it will just call the routine to clear the rrq and
607 * free the rrq resource.
608 * The timer is set to the next rrq that is going to expire before
609 * leaving the routine.
613 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
615 struct lpfc_node_rrq
*rrq
;
616 struct lpfc_node_rrq
*nextrrq
;
617 unsigned long next_time
;
618 unsigned long iflags
;
621 spin_lock_irqsave(&phba
->hbalock
, iflags
);
622 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
623 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
624 list_for_each_entry_safe(rrq
, nextrrq
,
625 &phba
->active_rrq_list
, list
) {
626 if (time_after(jiffies
, rrq
->rrq_stop_time
))
627 list_move(&rrq
->list
, &send_rrq
);
628 else if (time_before(rrq
->rrq_stop_time
, next_time
))
629 next_time
= rrq
->rrq_stop_time
;
631 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
632 if (!list_empty(&phba
->active_rrq_list
))
633 mod_timer(&phba
->rrq_tmr
, next_time
);
634 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
635 list_del(&rrq
->list
);
637 /* this call will free the rrq */
638 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
639 else if (lpfc_send_rrq(phba
, rrq
)) {
640 /* if we send the rrq then the completion handler
641 * will clear the bit in the xribitmap.
643 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
650 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
651 * @vport: Pointer to vport context object.
652 * @xri: The xri used in the exchange.
653 * @did: The targets DID for this exchange.
655 * returns NULL = rrq not found in the phba->active_rrq_list.
656 * rrq = rrq for this xri and target.
658 struct lpfc_node_rrq
*
659 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
661 struct lpfc_hba
*phba
= vport
->phba
;
662 struct lpfc_node_rrq
*rrq
;
663 struct lpfc_node_rrq
*nextrrq
;
664 unsigned long iflags
;
666 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
668 spin_lock_irqsave(&phba
->hbalock
, iflags
);
669 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
670 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
671 rrq
->nlp_DID
== did
){
672 list_del(&rrq
->list
);
673 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
677 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
682 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
683 * @vport: Pointer to vport context object.
684 * @ndlp: Pointer to the lpfc_node_list structure.
685 * If ndlp is NULL Remove all active RRQs for this vport from the
686 * phba->active_rrq_list and clear the rrq.
687 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
690 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
693 struct lpfc_hba
*phba
= vport
->phba
;
694 struct lpfc_node_rrq
*rrq
;
695 struct lpfc_node_rrq
*nextrrq
;
696 unsigned long iflags
;
699 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
702 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
703 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
705 spin_lock_irqsave(&phba
->hbalock
, iflags
);
706 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
707 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
708 list_move(&rrq
->list
, &rrq_list
);
709 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
711 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
712 list_del(&rrq
->list
);
713 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
718 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
719 * @phba: Pointer to HBA context object.
721 * Remove all rrqs from the phba->active_rrq_list and free them by
722 * calling __lpfc_clr_active_rrq
726 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
728 struct lpfc_node_rrq
*rrq
;
729 struct lpfc_node_rrq
*nextrrq
;
730 unsigned long next_time
;
731 unsigned long iflags
;
734 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
736 spin_lock_irqsave(&phba
->hbalock
, iflags
);
737 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
738 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
739 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
740 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
742 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
743 list_del(&rrq
->list
);
744 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
746 if (!list_empty(&phba
->active_rrq_list
))
747 mod_timer(&phba
->rrq_tmr
, next_time
);
752 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
753 * @phba: Pointer to HBA context object.
754 * @ndlp: Targets nodelist pointer for this exchange.
755 * @xritag the xri in the bitmap to test.
757 * This function is called with hbalock held. This function
758 * returns 0 = rrq not active for this xri
759 * 1 = rrq is valid for this xri.
762 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
767 if (test_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
774 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
775 * @phba: Pointer to HBA context object.
776 * @ndlp: nodelist pointer for this target.
777 * @xritag: xri used in this exchange.
778 * @rxid: Remote Exchange ID.
779 * @send_rrq: Flag used to determine if we should send rrq els cmd.
781 * This function takes the hbalock.
782 * The active bit is always set in the active rrq xri_bitmap even
783 * if there is no slot avaiable for the other rrq information.
785 * returns 0 rrq actived for this xri
786 * < 0 No memory or invalid ndlp.
789 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
790 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
792 unsigned long iflags
;
793 struct lpfc_node_rrq
*rrq
;
799 if (!phba
->cfg_enable_rrq
)
802 spin_lock_irqsave(&phba
->hbalock
, iflags
);
803 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
804 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
809 * set the active bit even if there is no mem available.
811 if (NLP_CHK_FREE_REQ(ndlp
))
814 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
817 if (test_and_set_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
820 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
821 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
823 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
824 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
825 " DID:0x%x Send:%d\n",
826 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
829 rrq
->send_rrq
= send_rrq
;
830 rrq
->xritag
= xritag
;
831 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
833 rrq
->nlp_DID
= ndlp
->nlp_DID
;
834 rrq
->vport
= ndlp
->vport
;
836 rrq
->send_rrq
= send_rrq
;
837 spin_lock_irqsave(&phba
->hbalock
, iflags
);
838 empty
= list_empty(&phba
->active_rrq_list
);
839 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
840 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
842 lpfc_worker_wake_up(phba
);
843 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
846 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
847 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
848 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
849 " DID:0x%x Send:%d\n",
850 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
855 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
856 * @phba: Pointer to HBA context object.
857 * @piocb: Pointer to the iocbq.
859 * This function is called with hbalock held. This function
860 * gets a new driver sglq object from the sglq list. If the
861 * list is not empty then it is successful, it returns pointer to the newly
862 * allocated sglq object else it returns NULL.
864 static struct lpfc_sglq
*
865 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
867 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
868 struct lpfc_sglq
*sglq
= NULL
;
869 struct lpfc_sglq
*start_sglq
= NULL
;
870 struct lpfc_scsi_buf
*lpfc_cmd
;
871 struct lpfc_nodelist
*ndlp
;
874 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
875 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
876 ndlp
= lpfc_cmd
->rdata
->pnode
;
877 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
878 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
879 ndlp
= piocbq
->context_un
.ndlp
;
881 ndlp
= piocbq
->context1
;
883 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
888 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_xritag
)) {
889 /* This xri has an rrq outstanding for this DID.
890 * put it back in the list and get another xri.
892 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
894 list_remove_head(lpfc_sgl_list
, sglq
,
895 struct lpfc_sglq
, list
);
896 if (sglq
== start_sglq
) {
904 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
905 sglq
->state
= SGL_ALLOCATED
;
911 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
912 * @phba: Pointer to HBA context object.
914 * This function is called with no lock held. This function
915 * allocates a new driver iocb object from the iocb pool. If the
916 * allocation is successful, it returns pointer to the newly
917 * allocated iocb object else it returns NULL.
920 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
922 struct lpfc_iocbq
* iocbq
= NULL
;
923 unsigned long iflags
;
925 spin_lock_irqsave(&phba
->hbalock
, iflags
);
926 iocbq
= __lpfc_sli_get_iocbq(phba
);
927 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
932 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
933 * @phba: Pointer to HBA context object.
934 * @iocbq: Pointer to driver iocb object.
936 * This function is called with hbalock held to release driver
937 * iocb object to the iocb pool. The iotag in the iocb object
938 * does not change for each use of the iocb object. This function
939 * clears all other fields of the iocb object when it is freed.
940 * The sqlq structure that holds the xritag and phys and virtual
941 * mappings for the scatter gather list is retrieved from the
942 * active array of sglq. The get of the sglq pointer also clears
943 * the entry in the array. If the status of the IO indiactes that
944 * this IO was aborted then the sglq entry it put on the
945 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
946 * IO has good status or fails for any other reason then the sglq
947 * entry is added to the free list (lpfc_sgl_list).
950 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
952 struct lpfc_sglq
*sglq
;
953 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
954 unsigned long iflag
= 0;
955 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
957 if (iocbq
->sli4_xritag
== NO_XRI
)
960 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
963 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
964 (sglq
->state
!= SGL_XRI_ABORTED
)) {
965 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
967 list_add(&sglq
->list
,
968 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
969 spin_unlock_irqrestore(
970 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
972 sglq
->state
= SGL_FREED
;
974 list_add_tail(&sglq
->list
,
975 &phba
->sli4_hba
.lpfc_sgl_list
);
977 /* Check if TXQ queue needs to be serviced */
979 lpfc_worker_wake_up(phba
);
985 * Clean all volatile data fields, preserve iotag and node struct.
987 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
988 iocbq
->sli4_lxritag
= NO_XRI
;
989 iocbq
->sli4_xritag
= NO_XRI
;
990 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
995 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
996 * @phba: Pointer to HBA context object.
997 * @iocbq: Pointer to driver iocb object.
999 * This function is called with hbalock held to release driver
1000 * iocb object to the iocb pool. The iotag in the iocb object
1001 * does not change for each use of the iocb object. This function
1002 * clears all other fields of the iocb object when it is freed.
1005 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1007 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1010 * Clean all volatile data fields, preserve iotag and node struct.
1012 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1013 iocbq
->sli4_xritag
= NO_XRI
;
1014 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1018 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1019 * @phba: Pointer to HBA context object.
1020 * @iocbq: Pointer to driver iocb object.
1022 * This function is called with hbalock held to release driver
1023 * iocb object to the iocb pool. The iotag in the iocb object
1024 * does not change for each use of the iocb object. This function
1025 * clears all other fields of the iocb object when it is freed.
1028 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1030 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1035 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1036 * @phba: Pointer to HBA context object.
1037 * @iocbq: Pointer to driver iocb object.
1039 * This function is called with no lock held to release the iocb to
1043 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1045 unsigned long iflags
;
1048 * Clean all volatile data fields, preserve iotag and node struct.
1050 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1051 __lpfc_sli_release_iocbq(phba
, iocbq
);
1052 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1056 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1057 * @phba: Pointer to HBA context object.
1058 * @iocblist: List of IOCBs.
1059 * @ulpstatus: ULP status in IOCB command field.
1060 * @ulpWord4: ULP word-4 in IOCB command field.
1062 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1063 * on the list by invoking the complete callback function associated with the
1064 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1068 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1069 uint32_t ulpstatus
, uint32_t ulpWord4
)
1071 struct lpfc_iocbq
*piocb
;
1073 while (!list_empty(iocblist
)) {
1074 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1076 if (!piocb
->iocb_cmpl
)
1077 lpfc_sli_release_iocbq(phba
, piocb
);
1079 piocb
->iocb
.ulpStatus
= ulpstatus
;
1080 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1081 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1088 * lpfc_sli_iocb_cmd_type - Get the iocb type
1089 * @iocb_cmnd: iocb command code.
1091 * This function is called by ring event handler function to get the iocb type.
1092 * This function translates the iocb command to an iocb command type used to
1093 * decide the final disposition of each completed IOCB.
1094 * The function returns
1095 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1096 * LPFC_SOL_IOCB if it is a solicited iocb completion
1097 * LPFC_ABORT_IOCB if it is an abort iocb
1098 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1100 * The caller is not required to hold any lock.
1102 static lpfc_iocb_type
1103 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1105 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1107 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1110 switch (iocb_cmnd
) {
1111 case CMD_XMIT_SEQUENCE_CR
:
1112 case CMD_XMIT_SEQUENCE_CX
:
1113 case CMD_XMIT_BCAST_CN
:
1114 case CMD_XMIT_BCAST_CX
:
1115 case CMD_ELS_REQUEST_CR
:
1116 case CMD_ELS_REQUEST_CX
:
1117 case CMD_CREATE_XRI_CR
:
1118 case CMD_CREATE_XRI_CX
:
1119 case CMD_GET_RPI_CN
:
1120 case CMD_XMIT_ELS_RSP_CX
:
1121 case CMD_GET_RPI_CR
:
1122 case CMD_FCP_IWRITE_CR
:
1123 case CMD_FCP_IWRITE_CX
:
1124 case CMD_FCP_IREAD_CR
:
1125 case CMD_FCP_IREAD_CX
:
1126 case CMD_FCP_ICMND_CR
:
1127 case CMD_FCP_ICMND_CX
:
1128 case CMD_FCP_TSEND_CX
:
1129 case CMD_FCP_TRSP_CX
:
1130 case CMD_FCP_TRECEIVE_CX
:
1131 case CMD_FCP_AUTO_TRSP_CX
:
1132 case CMD_ADAPTER_MSG
:
1133 case CMD_ADAPTER_DUMP
:
1134 case CMD_XMIT_SEQUENCE64_CR
:
1135 case CMD_XMIT_SEQUENCE64_CX
:
1136 case CMD_XMIT_BCAST64_CN
:
1137 case CMD_XMIT_BCAST64_CX
:
1138 case CMD_ELS_REQUEST64_CR
:
1139 case CMD_ELS_REQUEST64_CX
:
1140 case CMD_FCP_IWRITE64_CR
:
1141 case CMD_FCP_IWRITE64_CX
:
1142 case CMD_FCP_IREAD64_CR
:
1143 case CMD_FCP_IREAD64_CX
:
1144 case CMD_FCP_ICMND64_CR
:
1145 case CMD_FCP_ICMND64_CX
:
1146 case CMD_FCP_TSEND64_CX
:
1147 case CMD_FCP_TRSP64_CX
:
1148 case CMD_FCP_TRECEIVE64_CX
:
1149 case CMD_GEN_REQUEST64_CR
:
1150 case CMD_GEN_REQUEST64_CX
:
1151 case CMD_XMIT_ELS_RSP64_CX
:
1152 case DSSCMD_IWRITE64_CR
:
1153 case DSSCMD_IWRITE64_CX
:
1154 case DSSCMD_IREAD64_CR
:
1155 case DSSCMD_IREAD64_CX
:
1156 type
= LPFC_SOL_IOCB
;
1158 case CMD_ABORT_XRI_CN
:
1159 case CMD_ABORT_XRI_CX
:
1160 case CMD_CLOSE_XRI_CN
:
1161 case CMD_CLOSE_XRI_CX
:
1162 case CMD_XRI_ABORTED_CX
:
1163 case CMD_ABORT_MXRI64_CN
:
1164 case CMD_XMIT_BLS_RSP64_CX
:
1165 type
= LPFC_ABORT_IOCB
;
1167 case CMD_RCV_SEQUENCE_CX
:
1168 case CMD_RCV_ELS_REQ_CX
:
1169 case CMD_RCV_SEQUENCE64_CX
:
1170 case CMD_RCV_ELS_REQ64_CX
:
1171 case CMD_ASYNC_STATUS
:
1172 case CMD_IOCB_RCV_SEQ64_CX
:
1173 case CMD_IOCB_RCV_ELS64_CX
:
1174 case CMD_IOCB_RCV_CONT64_CX
:
1175 case CMD_IOCB_RET_XRI64_CX
:
1176 type
= LPFC_UNSOL_IOCB
;
1178 case CMD_IOCB_XMIT_MSEQ64_CR
:
1179 case CMD_IOCB_XMIT_MSEQ64_CX
:
1180 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1181 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1182 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1183 case CMD_IOCB_ABORT_EXTENDED_CN
:
1184 case CMD_IOCB_RET_HBQE64_CN
:
1185 case CMD_IOCB_FCP_IBIDIR64_CR
:
1186 case CMD_IOCB_FCP_IBIDIR64_CX
:
1187 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1188 case CMD_IOCB_LOGENTRY_CN
:
1189 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1190 printk("%s - Unhandled SLI-3 Command x%x\n",
1191 __func__
, iocb_cmnd
);
1192 type
= LPFC_UNKNOWN_IOCB
;
1195 type
= LPFC_UNKNOWN_IOCB
;
1203 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1204 * @phba: Pointer to HBA context object.
1206 * This function is called from SLI initialization code
1207 * to configure every ring of the HBA's SLI interface. The
1208 * caller is not required to hold any lock. This function issues
1209 * a config_ring mailbox command for each ring.
1210 * This function returns zero if successful else returns a negative
1214 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1216 struct lpfc_sli
*psli
= &phba
->sli
;
1221 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1225 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1226 for (i
= 0; i
< psli
->num_rings
; i
++) {
1227 lpfc_config_ring(phba
, i
, pmb
);
1228 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1229 if (rc
!= MBX_SUCCESS
) {
1230 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1231 "0446 Adapter failed to init (%d), "
1232 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1234 rc
, pmbox
->mbxCommand
,
1235 pmbox
->mbxStatus
, i
);
1236 phba
->link_state
= LPFC_HBA_ERROR
;
1241 mempool_free(pmb
, phba
->mbox_mem_pool
);
1246 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1247 * @phba: Pointer to HBA context object.
1248 * @pring: Pointer to driver SLI ring object.
1249 * @piocb: Pointer to the driver iocb object.
1251 * This function is called with hbalock held. The function adds the
1252 * new iocb to txcmplq of the given ring. This function always returns
1253 * 0. If this function is called for ELS ring, this function checks if
1254 * there is a vport associated with the ELS command. This function also
1255 * starts els_tmofunc timer if this is an ELS command.
1258 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1259 struct lpfc_iocbq
*piocb
)
1261 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1262 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1263 pring
->txcmplq_cnt
++;
1264 if (pring
->txcmplq_cnt
> pring
->txcmplq_max
)
1265 pring
->txcmplq_max
= pring
->txcmplq_cnt
;
1267 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1268 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1269 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1273 mod_timer(&piocb
->vport
->els_tmofunc
,
1274 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1282 * lpfc_sli_ringtx_get - Get first element of the txq
1283 * @phba: Pointer to HBA context object.
1284 * @pring: Pointer to driver SLI ring object.
1286 * This function is called with hbalock held to get next
1287 * iocb in txq of the given ring. If there is any iocb in
1288 * the txq, the function returns first iocb in the list after
1289 * removing the iocb from the list, else it returns NULL.
1292 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1294 struct lpfc_iocbq
*cmd_iocb
;
1296 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1297 if (cmd_iocb
!= NULL
)
1303 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1304 * @phba: Pointer to HBA context object.
1305 * @pring: Pointer to driver SLI ring object.
1307 * This function is called with hbalock held and the caller must post the
1308 * iocb without releasing the lock. If the caller releases the lock,
1309 * iocb slot returned by the function is not guaranteed to be available.
1310 * The function returns pointer to the next available iocb slot if there
1311 * is available slot in the ring, else it returns NULL.
1312 * If the get index of the ring is ahead of the put index, the function
1313 * will post an error attention event to the worker thread to take the
1314 * HBA to offline state.
1317 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1319 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1320 uint32_t max_cmd_idx
= pring
->numCiocb
;
1321 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
1322 (++pring
->next_cmdidx
>= max_cmd_idx
))
1323 pring
->next_cmdidx
= 0;
1325 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
1327 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1329 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
1330 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1331 "0315 Ring %d issue: portCmdGet %d "
1332 "is bigger than cmd ring %d\n",
1334 pring
->local_getidx
, max_cmd_idx
);
1336 phba
->link_state
= LPFC_HBA_ERROR
;
1338 * All error attention handlers are posted to
1341 phba
->work_ha
|= HA_ERATT
;
1342 phba
->work_hs
= HS_FFER3
;
1344 lpfc_worker_wake_up(phba
);
1349 if (pring
->local_getidx
== pring
->next_cmdidx
)
1353 return lpfc_cmd_iocb(phba
, pring
);
1357 * lpfc_sli_next_iotag - Get an iotag for the iocb
1358 * @phba: Pointer to HBA context object.
1359 * @iocbq: Pointer to driver iocb object.
1361 * This function gets an iotag for the iocb. If there is no unused iotag and
1362 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1363 * array and assigns a new iotag.
1364 * The function returns the allocated iotag if successful, else returns zero.
1365 * Zero is not a valid iotag.
1366 * The caller is not required to hold any lock.
1369 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1371 struct lpfc_iocbq
**new_arr
;
1372 struct lpfc_iocbq
**old_arr
;
1374 struct lpfc_sli
*psli
= &phba
->sli
;
1377 spin_lock_irq(&phba
->hbalock
);
1378 iotag
= psli
->last_iotag
;
1379 if(++iotag
< psli
->iocbq_lookup_len
) {
1380 psli
->last_iotag
= iotag
;
1381 psli
->iocbq_lookup
[iotag
] = iocbq
;
1382 spin_unlock_irq(&phba
->hbalock
);
1383 iocbq
->iotag
= iotag
;
1385 } else if (psli
->iocbq_lookup_len
< (0xffff
1386 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1387 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1388 spin_unlock_irq(&phba
->hbalock
);
1389 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1392 spin_lock_irq(&phba
->hbalock
);
1393 old_arr
= psli
->iocbq_lookup
;
1394 if (new_len
<= psli
->iocbq_lookup_len
) {
1395 /* highly unprobable case */
1397 iotag
= psli
->last_iotag
;
1398 if(++iotag
< psli
->iocbq_lookup_len
) {
1399 psli
->last_iotag
= iotag
;
1400 psli
->iocbq_lookup
[iotag
] = iocbq
;
1401 spin_unlock_irq(&phba
->hbalock
);
1402 iocbq
->iotag
= iotag
;
1405 spin_unlock_irq(&phba
->hbalock
);
1408 if (psli
->iocbq_lookup
)
1409 memcpy(new_arr
, old_arr
,
1410 ((psli
->last_iotag
+ 1) *
1411 sizeof (struct lpfc_iocbq
*)));
1412 psli
->iocbq_lookup
= new_arr
;
1413 psli
->iocbq_lookup_len
= new_len
;
1414 psli
->last_iotag
= iotag
;
1415 psli
->iocbq_lookup
[iotag
] = iocbq
;
1416 spin_unlock_irq(&phba
->hbalock
);
1417 iocbq
->iotag
= iotag
;
1422 spin_unlock_irq(&phba
->hbalock
);
1424 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1425 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1432 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1433 * @phba: Pointer to HBA context object.
1434 * @pring: Pointer to driver SLI ring object.
1435 * @iocb: Pointer to iocb slot in the ring.
1436 * @nextiocb: Pointer to driver iocb object which need to be
1437 * posted to firmware.
1439 * This function is called with hbalock held to post a new iocb to
1440 * the firmware. This function copies the new iocb to ring iocb slot and
1441 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1442 * a completion call back for this iocb else the function will free the
1446 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1447 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1452 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1455 if (pring
->ringno
== LPFC_ELS_RING
) {
1456 lpfc_debugfs_slow_ring_trc(phba
,
1457 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1458 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1459 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1460 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1464 * Issue iocb command to adapter
1466 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1468 pring
->stats
.iocb_cmd
++;
1471 * If there is no completion routine to call, we can release the
1472 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1473 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1475 if (nextiocb
->iocb_cmpl
)
1476 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1478 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1481 * Let the HBA know what IOCB slot will be the next one the
1482 * driver will put a command into.
1484 pring
->cmdidx
= pring
->next_cmdidx
;
1485 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1489 * lpfc_sli_update_full_ring - Update the chip attention register
1490 * @phba: Pointer to HBA context object.
1491 * @pring: Pointer to driver SLI ring object.
1493 * The caller is not required to hold any lock for calling this function.
1494 * This function updates the chip attention bits for the ring to inform firmware
1495 * that there are pending work to be done for this ring and requests an
1496 * interrupt when there is space available in the ring. This function is
1497 * called when the driver is unable to post more iocbs to the ring due
1498 * to unavailability of space in the ring.
1501 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1503 int ringno
= pring
->ringno
;
1505 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1510 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1511 * The HBA will tell us when an IOCB entry is available.
1513 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1514 readl(phba
->CAregaddr
); /* flush */
1516 pring
->stats
.iocb_cmd_full
++;
1520 * lpfc_sli_update_ring - Update chip attention register
1521 * @phba: Pointer to HBA context object.
1522 * @pring: Pointer to driver SLI ring object.
1524 * This function updates the chip attention register bit for the
1525 * given ring to inform HBA that there is more work to be done
1526 * in this ring. The caller is not required to hold any lock.
1529 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1531 int ringno
= pring
->ringno
;
1534 * Tell the HBA that there is work to do in this ring.
1536 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1538 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1539 readl(phba
->CAregaddr
); /* flush */
1544 * lpfc_sli_resume_iocb - Process iocbs in the txq
1545 * @phba: Pointer to HBA context object.
1546 * @pring: Pointer to driver SLI ring object.
1548 * This function is called with hbalock held to post pending iocbs
1549 * in the txq to the firmware. This function is called when driver
1550 * detects space available in the ring.
1553 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1556 struct lpfc_iocbq
*nextiocb
;
1560 * (a) there is anything on the txq to send
1562 * (c) link attention events can be processed (fcp ring only)
1563 * (d) IOCB processing is not blocked by the outstanding mbox command.
1565 if (pring
->txq_cnt
&&
1566 lpfc_is_link_up(phba
) &&
1567 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1568 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1570 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1571 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1572 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1575 lpfc_sli_update_ring(phba
, pring
);
1577 lpfc_sli_update_full_ring(phba
, pring
);
1584 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1585 * @phba: Pointer to HBA context object.
1586 * @hbqno: HBQ number.
1588 * This function is called with hbalock held to get the next
1589 * available slot for the given HBQ. If there is free slot
1590 * available for the HBQ it will return pointer to the next available
1591 * HBQ entry else it will return NULL.
1593 static struct lpfc_hbq_entry
*
1594 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1596 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1598 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1599 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1600 hbqp
->next_hbqPutIdx
= 0;
1602 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1603 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1604 uint32_t getidx
= le32_to_cpu(raw_index
);
1606 hbqp
->local_hbqGetIdx
= getidx
;
1608 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1609 lpfc_printf_log(phba
, KERN_ERR
,
1610 LOG_SLI
| LOG_VPORT
,
1611 "1802 HBQ %d: local_hbqGetIdx "
1612 "%u is > than hbqp->entry_count %u\n",
1613 hbqno
, hbqp
->local_hbqGetIdx
,
1616 phba
->link_state
= LPFC_HBA_ERROR
;
1620 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1624 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1629 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1630 * @phba: Pointer to HBA context object.
1632 * This function is called with no lock held to free all the
1633 * hbq buffers while uninitializing the SLI interface. It also
1634 * frees the HBQ buffers returned by the firmware but not yet
1635 * processed by the upper layers.
1638 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1640 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1641 struct hbq_dmabuf
*hbq_buf
;
1642 unsigned long flags
;
1646 hbq_count
= lpfc_sli_hbq_count();
1647 /* Return all memory used by all HBQs */
1648 spin_lock_irqsave(&phba
->hbalock
, flags
);
1649 for (i
= 0; i
< hbq_count
; ++i
) {
1650 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1651 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1652 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1653 list_del(&hbq_buf
->dbuf
.list
);
1654 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1656 phba
->hbqs
[i
].buffer_count
= 0;
1658 /* Return all HBQ buffer that are in-fly */
1659 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1661 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1662 list_del(&hbq_buf
->dbuf
.list
);
1663 if (hbq_buf
->tag
== -1) {
1664 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1667 hbqno
= hbq_buf
->tag
>> 16;
1668 if (hbqno
>= LPFC_MAX_HBQS
)
1669 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1672 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1677 /* Mark the HBQs not in use */
1678 phba
->hbq_in_use
= 0;
1679 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1683 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1684 * @phba: Pointer to HBA context object.
1685 * @hbqno: HBQ number.
1686 * @hbq_buf: Pointer to HBQ buffer.
1688 * This function is called with the hbalock held to post a
1689 * hbq buffer to the firmware. If the function finds an empty
1690 * slot in the HBQ, it will post the buffer. The function will return
1691 * pointer to the hbq entry if it successfully post the buffer
1692 * else it will return NULL.
1695 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1696 struct hbq_dmabuf
*hbq_buf
)
1698 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1702 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1703 * @phba: Pointer to HBA context object.
1704 * @hbqno: HBQ number.
1705 * @hbq_buf: Pointer to HBQ buffer.
1707 * This function is called with the hbalock held to post a hbq buffer to the
1708 * firmware. If the function finds an empty slot in the HBQ, it will post the
1709 * buffer and place it on the hbq_buffer_list. The function will return zero if
1710 * it successfully post the buffer else it will return an error.
1713 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1714 struct hbq_dmabuf
*hbq_buf
)
1716 struct lpfc_hbq_entry
*hbqe
;
1717 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1719 /* Get next HBQ entry slot to use */
1720 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1722 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1724 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1725 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1726 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1727 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1728 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1729 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1731 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1732 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1734 readl(phba
->hbq_put
+ hbqno
);
1735 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1742 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1743 * @phba: Pointer to HBA context object.
1744 * @hbqno: HBQ number.
1745 * @hbq_buf: Pointer to HBQ buffer.
1747 * This function is called with the hbalock held to post an RQE to the SLI4
1748 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1749 * the hbq_buffer_list and return zero, otherwise it will return an error.
1752 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1753 struct hbq_dmabuf
*hbq_buf
)
1756 struct lpfc_rqe hrqe
;
1757 struct lpfc_rqe drqe
;
1759 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1760 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1761 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1762 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1763 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1768 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1772 /* HBQ for ELS and CT traffic. */
1773 static struct lpfc_hbq_init lpfc_els_hbq
= {
1778 .ring_mask
= (1 << LPFC_ELS_RING
),
1784 /* HBQ for the extra ring if needed */
1785 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1790 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1797 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1803 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1804 * @phba: Pointer to HBA context object.
1805 * @hbqno: HBQ number.
1806 * @count: Number of HBQ buffers to be posted.
1808 * This function is called with no lock held to post more hbq buffers to the
1809 * given HBQ. The function returns the number of HBQ buffers successfully
1813 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1815 uint32_t i
, posted
= 0;
1816 unsigned long flags
;
1817 struct hbq_dmabuf
*hbq_buffer
;
1818 LIST_HEAD(hbq_buf_list
);
1819 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1822 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1823 lpfc_hbq_defs
[hbqno
]->entry_count
)
1824 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1825 phba
->hbqs
[hbqno
].buffer_count
;
1828 /* Allocate HBQ entries */
1829 for (i
= 0; i
< count
; i
++) {
1830 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1833 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1835 /* Check whether HBQ is still in use */
1836 spin_lock_irqsave(&phba
->hbalock
, flags
);
1837 if (!phba
->hbq_in_use
)
1839 while (!list_empty(&hbq_buf_list
)) {
1840 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1842 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1844 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1845 phba
->hbqs
[hbqno
].buffer_count
++;
1848 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1850 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1853 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1854 while (!list_empty(&hbq_buf_list
)) {
1855 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1857 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1863 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1864 * @phba: Pointer to HBA context object.
1867 * This function posts more buffers to the HBQ. This function
1868 * is called with no lock held. The function returns the number of HBQ entries
1869 * successfully allocated.
1872 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1874 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1877 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1878 lpfc_hbq_defs
[qno
]->add_count
);
1882 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1883 * @phba: Pointer to HBA context object.
1884 * @qno: HBQ queue number.
1886 * This function is called from SLI initialization code path with
1887 * no lock held to post initial HBQ buffers to firmware. The
1888 * function returns the number of HBQ entries successfully allocated.
1891 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1893 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1894 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1895 lpfc_hbq_defs
[qno
]->entry_count
);
1897 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1898 lpfc_hbq_defs
[qno
]->init_count
);
1902 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1903 * @phba: Pointer to HBA context object.
1904 * @hbqno: HBQ number.
1906 * This function removes the first hbq buffer on an hbq list and returns a
1907 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1909 static struct hbq_dmabuf
*
1910 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1912 struct lpfc_dmabuf
*d_buf
;
1914 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1917 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1921 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1922 * @phba: Pointer to HBA context object.
1923 * @tag: Tag of the hbq buffer.
1925 * This function is called with hbalock held. This function searches
1926 * for the hbq buffer associated with the given tag in the hbq buffer
1927 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1930 static struct hbq_dmabuf
*
1931 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1933 struct lpfc_dmabuf
*d_buf
;
1934 struct hbq_dmabuf
*hbq_buf
;
1938 if (hbqno
>= LPFC_MAX_HBQS
)
1941 spin_lock_irq(&phba
->hbalock
);
1942 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1943 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1944 if (hbq_buf
->tag
== tag
) {
1945 spin_unlock_irq(&phba
->hbalock
);
1949 spin_unlock_irq(&phba
->hbalock
);
1950 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1951 "1803 Bad hbq tag. Data: x%x x%x\n",
1952 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1957 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1958 * @phba: Pointer to HBA context object.
1959 * @hbq_buffer: Pointer to HBQ buffer.
1961 * This function is called with hbalock. This function gives back
1962 * the hbq buffer to firmware. If the HBQ does not have space to
1963 * post the buffer, it will free the buffer.
1966 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1971 hbqno
= hbq_buffer
->tag
>> 16;
1972 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1973 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1978 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1979 * @mbxCommand: mailbox command code.
1981 * This function is called by the mailbox event handler function to verify
1982 * that the completed mailbox command is a legitimate mailbox command. If the
1983 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1984 * and the mailbox event handler will take the HBA offline.
1987 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
1991 switch (mbxCommand
) {
1995 case MBX_WRITE_VPARMS
:
1996 case MBX_RUN_BIU_DIAG
:
1999 case MBX_CONFIG_LINK
:
2000 case MBX_CONFIG_RING
:
2001 case MBX_RESET_RING
:
2002 case MBX_READ_CONFIG
:
2003 case MBX_READ_RCONFIG
:
2004 case MBX_READ_SPARM
:
2005 case MBX_READ_STATUS
:
2009 case MBX_READ_LNK_STAT
:
2011 case MBX_UNREG_LOGIN
:
2013 case MBX_DUMP_MEMORY
:
2014 case MBX_DUMP_CONTEXT
:
2017 case MBX_UPDATE_CFG
:
2019 case MBX_DEL_LD_ENTRY
:
2020 case MBX_RUN_PROGRAM
:
2022 case MBX_SET_VARIABLE
:
2023 case MBX_UNREG_D_ID
:
2024 case MBX_KILL_BOARD
:
2025 case MBX_CONFIG_FARP
:
2028 case MBX_RUN_BIU_DIAG64
:
2029 case MBX_CONFIG_PORT
:
2030 case MBX_READ_SPARM64
:
2031 case MBX_READ_RPI64
:
2032 case MBX_REG_LOGIN64
:
2033 case MBX_READ_TOPOLOGY
:
2036 case MBX_LOAD_EXP_ROM
:
2037 case MBX_ASYNCEVT_ENABLE
:
2041 case MBX_PORT_CAPABILITIES
:
2042 case MBX_PORT_IOV_CONTROL
:
2043 case MBX_SLI4_CONFIG
:
2044 case MBX_SLI4_REQ_FTRS
:
2046 case MBX_UNREG_FCFI
:
2051 case MBX_RESUME_RPI
:
2052 case MBX_READ_EVENT_LOG_STATUS
:
2053 case MBX_READ_EVENT_LOG
:
2054 case MBX_SECURITY_MGMT
:
2066 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2067 * @phba: Pointer to HBA context object.
2068 * @pmboxq: Pointer to mailbox command.
2070 * This is completion handler function for mailbox commands issued from
2071 * lpfc_sli_issue_mbox_wait function. This function is called by the
2072 * mailbox event handler function with no lock held. This function
2073 * will wake up thread waiting on the wait queue pointed by context1
2077 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2079 wait_queue_head_t
*pdone_q
;
2080 unsigned long drvr_flag
;
2083 * If pdone_q is empty, the driver thread gave up waiting and
2084 * continued running.
2086 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2087 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2088 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2090 wake_up_interruptible(pdone_q
);
2091 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2097 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2098 * @phba: Pointer to HBA context object.
2099 * @pmb: Pointer to mailbox object.
2101 * This function is the default mailbox completion handler. It
2102 * frees the memory resources associated with the completed mailbox
2103 * command. If the completed command is a REG_LOGIN mailbox command,
2104 * this function will issue a UREG_LOGIN to re-claim the RPI.
2107 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2109 struct lpfc_vport
*vport
= pmb
->vport
;
2110 struct lpfc_dmabuf
*mp
;
2111 struct lpfc_nodelist
*ndlp
;
2112 struct Scsi_Host
*shost
;
2116 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2119 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2124 * If a REG_LOGIN succeeded after node is destroyed or node
2125 * is in re-discovery driver need to cleanup the RPI.
2127 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2128 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2129 !pmb
->u
.mb
.mbxStatus
) {
2130 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2131 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2132 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2133 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2134 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2135 if (rc
!= MBX_NOT_FINISHED
)
2139 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2140 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2141 !pmb
->u
.mb
.mbxStatus
) {
2142 shost
= lpfc_shost_from_vport(vport
);
2143 spin_lock_irq(shost
->host_lock
);
2144 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2145 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2146 spin_unlock_irq(shost
->host_lock
);
2149 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2150 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2152 pmb
->context2
= NULL
;
2155 /* Check security permission status on INIT_LINK mailbox command */
2156 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2157 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2158 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2159 "2860 SLI authentication is required "
2160 "for INIT_LINK but has not done yet\n");
2162 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2163 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2165 mempool_free(pmb
, phba
->mbox_mem_pool
);
2169 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2170 * @phba: Pointer to HBA context object.
2172 * This function is called with no lock held. This function processes all
2173 * the completed mailbox commands and gives it to upper layers. The interrupt
2174 * service routine processes mailbox completion interrupt and adds completed
2175 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2176 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2177 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2178 * function returns the mailbox commands to the upper layer by calling the
2179 * completion handler function of each mailbox.
2182 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2189 phba
->sli
.slistat
.mbox_event
++;
2191 /* Get all completed mailboxe buffers into the cmplq */
2192 spin_lock_irq(&phba
->hbalock
);
2193 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2194 spin_unlock_irq(&phba
->hbalock
);
2196 /* Get a Mailbox buffer to setup mailbox commands for callback */
2198 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2204 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2206 lpfc_debugfs_disc_trc(pmb
->vport
,
2207 LPFC_DISC_TRC_MBOX_VPORT
,
2208 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2209 (uint32_t)pmbox
->mbxCommand
,
2210 pmbox
->un
.varWords
[0],
2211 pmbox
->un
.varWords
[1]);
2214 lpfc_debugfs_disc_trc(phba
->pport
,
2216 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2217 (uint32_t)pmbox
->mbxCommand
,
2218 pmbox
->un
.varWords
[0],
2219 pmbox
->un
.varWords
[1]);
2224 * It is a fatal error if unknown mbox command completion.
2226 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2228 /* Unknown mailbox command compl */
2229 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2230 "(%d):0323 Unknown Mailbox command "
2231 "x%x (x%x/x%x) Cmpl\n",
2232 pmb
->vport
? pmb
->vport
->vpi
: 0,
2234 lpfc_sli_config_mbox_subsys_get(phba
,
2236 lpfc_sli_config_mbox_opcode_get(phba
,
2238 phba
->link_state
= LPFC_HBA_ERROR
;
2239 phba
->work_hs
= HS_FFER3
;
2240 lpfc_handle_eratt(phba
);
2244 if (pmbox
->mbxStatus
) {
2245 phba
->sli
.slistat
.mbox_stat_err
++;
2246 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2247 /* Mbox cmd cmpl error - RETRYing */
2248 lpfc_printf_log(phba
, KERN_INFO
,
2250 "(%d):0305 Mbox cmd cmpl "
2251 "error - RETRYing Data: x%x "
2252 "(x%x/x%x) x%x x%x x%x\n",
2253 pmb
->vport
? pmb
->vport
->vpi
: 0,
2255 lpfc_sli_config_mbox_subsys_get(phba
,
2257 lpfc_sli_config_mbox_opcode_get(phba
,
2260 pmbox
->un
.varWords
[0],
2261 pmb
->vport
->port_state
);
2262 pmbox
->mbxStatus
= 0;
2263 pmbox
->mbxOwner
= OWN_HOST
;
2264 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2265 if (rc
!= MBX_NOT_FINISHED
)
2270 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2271 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2272 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2273 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2274 pmb
->vport
? pmb
->vport
->vpi
: 0,
2276 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2277 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2279 *((uint32_t *) pmbox
),
2280 pmbox
->un
.varWords
[0],
2281 pmbox
->un
.varWords
[1],
2282 pmbox
->un
.varWords
[2],
2283 pmbox
->un
.varWords
[3],
2284 pmbox
->un
.varWords
[4],
2285 pmbox
->un
.varWords
[5],
2286 pmbox
->un
.varWords
[6],
2287 pmbox
->un
.varWords
[7]);
2290 pmb
->mbox_cmpl(phba
,pmb
);
2296 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2297 * @phba: Pointer to HBA context object.
2298 * @pring: Pointer to driver SLI ring object.
2301 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2302 * is set in the tag the buffer is posted for a particular exchange,
2303 * the function will return the buffer without replacing the buffer.
2304 * If the buffer is for unsolicited ELS or CT traffic, this function
2305 * returns the buffer and also posts another buffer to the firmware.
2307 static struct lpfc_dmabuf
*
2308 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2309 struct lpfc_sli_ring
*pring
,
2312 struct hbq_dmabuf
*hbq_entry
;
2314 if (tag
& QUE_BUFTAG_BIT
)
2315 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2316 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2319 return &hbq_entry
->dbuf
;
2323 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2324 * @phba: Pointer to HBA context object.
2325 * @pring: Pointer to driver SLI ring object.
2326 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2327 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2328 * @fch_type: the type for the first frame of the sequence.
2330 * This function is called with no lock held. This function uses the r_ctl and
2331 * type of the received sequence to find the correct callback function to call
2332 * to process the sequence.
2335 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2336 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2341 /* unSolicited Responses */
2342 if (pring
->prt
[0].profile
) {
2343 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2344 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2348 /* We must search, based on rctl / type
2349 for the right routine */
2350 for (i
= 0; i
< pring
->num_mask
; i
++) {
2351 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2352 (pring
->prt
[i
].type
== fch_type
)) {
2353 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2354 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2355 (phba
, pring
, saveq
);
2363 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2364 * @phba: Pointer to HBA context object.
2365 * @pring: Pointer to driver SLI ring object.
2366 * @saveq: Pointer to the unsolicited iocb.
2368 * This function is called with no lock held by the ring event handler
2369 * when there is an unsolicited iocb posted to the response ring by the
2370 * firmware. This function gets the buffer associated with the iocbs
2371 * and calls the event handler for the ring. This function handles both
2372 * qring buffers and hbq buffers.
2373 * When the function returns 1 the caller can free the iocb object otherwise
2374 * upper layer functions will free the iocb objects.
2377 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2378 struct lpfc_iocbq
*saveq
)
2382 uint32_t Rctl
, Type
;
2384 struct lpfc_iocbq
*iocbq
;
2385 struct lpfc_dmabuf
*dmzbuf
;
2388 irsp
= &(saveq
->iocb
);
2390 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2391 if (pring
->lpfc_sli_rcv_async_status
)
2392 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2394 lpfc_printf_log(phba
,
2397 "0316 Ring %d handler: unexpected "
2398 "ASYNC_STATUS iocb received evt_code "
2401 irsp
->un
.asyncstat
.evt_code
);
2405 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2406 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2407 if (irsp
->ulpBdeCount
> 0) {
2408 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2409 irsp
->un
.ulpWord
[3]);
2410 lpfc_in_buf_free(phba
, dmzbuf
);
2413 if (irsp
->ulpBdeCount
> 1) {
2414 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2415 irsp
->unsli3
.sli3Words
[3]);
2416 lpfc_in_buf_free(phba
, dmzbuf
);
2419 if (irsp
->ulpBdeCount
> 2) {
2420 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2421 irsp
->unsli3
.sli3Words
[7]);
2422 lpfc_in_buf_free(phba
, dmzbuf
);
2428 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2429 if (irsp
->ulpBdeCount
!= 0) {
2430 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2431 irsp
->un
.ulpWord
[3]);
2432 if (!saveq
->context2
)
2433 lpfc_printf_log(phba
,
2436 "0341 Ring %d Cannot find buffer for "
2437 "an unsolicited iocb. tag 0x%x\n",
2439 irsp
->un
.ulpWord
[3]);
2441 if (irsp
->ulpBdeCount
== 2) {
2442 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2443 irsp
->unsli3
.sli3Words
[7]);
2444 if (!saveq
->context3
)
2445 lpfc_printf_log(phba
,
2448 "0342 Ring %d Cannot find buffer for an"
2449 " unsolicited iocb. tag 0x%x\n",
2451 irsp
->unsli3
.sli3Words
[7]);
2453 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2454 irsp
= &(iocbq
->iocb
);
2455 if (irsp
->ulpBdeCount
!= 0) {
2456 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2457 irsp
->un
.ulpWord
[3]);
2458 if (!iocbq
->context2
)
2459 lpfc_printf_log(phba
,
2462 "0343 Ring %d Cannot find "
2463 "buffer for an unsolicited iocb"
2464 ". tag 0x%x\n", pring
->ringno
,
2465 irsp
->un
.ulpWord
[3]);
2467 if (irsp
->ulpBdeCount
== 2) {
2468 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2469 irsp
->unsli3
.sli3Words
[7]);
2470 if (!iocbq
->context3
)
2471 lpfc_printf_log(phba
,
2474 "0344 Ring %d Cannot find "
2475 "buffer for an unsolicited "
2478 irsp
->unsli3
.sli3Words
[7]);
2482 if (irsp
->ulpBdeCount
!= 0 &&
2483 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2484 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2487 /* search continue save q for same XRI */
2488 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2489 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2490 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2491 list_add_tail(&saveq
->list
, &iocbq
->list
);
2497 list_add_tail(&saveq
->clist
,
2498 &pring
->iocb_continue_saveq
);
2499 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2500 list_del_init(&iocbq
->clist
);
2502 irsp
= &(saveq
->iocb
);
2506 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2507 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2508 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2509 Rctl
= FC_RCTL_ELS_REQ
;
2512 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2513 Rctl
= w5p
->hcsw
.Rctl
;
2514 Type
= w5p
->hcsw
.Type
;
2516 /* Firmware Workaround */
2517 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2518 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2519 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2520 Rctl
= FC_RCTL_ELS_REQ
;
2522 w5p
->hcsw
.Rctl
= Rctl
;
2523 w5p
->hcsw
.Type
= Type
;
2527 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2528 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2529 "0313 Ring %d handler: unexpected Rctl x%x "
2530 "Type x%x received\n",
2531 pring
->ringno
, Rctl
, Type
);
2537 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2538 * @phba: Pointer to HBA context object.
2539 * @pring: Pointer to driver SLI ring object.
2540 * @prspiocb: Pointer to response iocb object.
2542 * This function looks up the iocb_lookup table to get the command iocb
2543 * corresponding to the given response iocb using the iotag of the
2544 * response iocb. This function is called with the hbalock held.
2545 * This function returns the command iocb object if it finds the command
2546 * iocb else returns NULL.
2548 static struct lpfc_iocbq
*
2549 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2550 struct lpfc_sli_ring
*pring
,
2551 struct lpfc_iocbq
*prspiocb
)
2553 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2556 iotag
= prspiocb
->iocb
.ulpIoTag
;
2558 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2559 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2560 list_del_init(&cmd_iocb
->list
);
2561 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2562 pring
->txcmplq_cnt
--;
2563 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2568 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2569 "0317 iotag x%x is out off "
2570 "range: max iotag x%x wd0 x%x\n",
2571 iotag
, phba
->sli
.last_iotag
,
2572 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2577 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2578 * @phba: Pointer to HBA context object.
2579 * @pring: Pointer to driver SLI ring object.
2582 * This function looks up the iocb_lookup table to get the command iocb
2583 * corresponding to the given iotag. This function is called with the
2585 * This function returns the command iocb object if it finds the command
2586 * iocb else returns NULL.
2588 static struct lpfc_iocbq
*
2589 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2590 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2592 struct lpfc_iocbq
*cmd_iocb
;
2594 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2595 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2596 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2597 /* remove from txcmpl queue list */
2598 list_del_init(&cmd_iocb
->list
);
2599 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2600 pring
->txcmplq_cnt
--;
2604 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2605 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2606 iotag
, phba
->sli
.last_iotag
);
2611 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2612 * @phba: Pointer to HBA context object.
2613 * @pring: Pointer to driver SLI ring object.
2614 * @saveq: Pointer to the response iocb to be processed.
2616 * This function is called by the ring event handler for non-fcp
2617 * rings when there is a new response iocb in the response ring.
2618 * The caller is not required to hold any locks. This function
2619 * gets the command iocb associated with the response iocb and
2620 * calls the completion handler for the command iocb. If there
2621 * is no completion handler, the function will free the resources
2622 * associated with command iocb. If the response iocb is for
2623 * an already aborted command iocb, the status of the completion
2624 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2625 * This function always returns 1.
2628 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2629 struct lpfc_iocbq
*saveq
)
2631 struct lpfc_iocbq
*cmdiocbp
;
2633 unsigned long iflag
;
2635 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2636 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2637 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2638 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2641 if (cmdiocbp
->iocb_cmpl
) {
2643 * If an ELS command failed send an event to mgmt
2646 if (saveq
->iocb
.ulpStatus
&&
2647 (pring
->ringno
== LPFC_ELS_RING
) &&
2648 (cmdiocbp
->iocb
.ulpCommand
==
2649 CMD_ELS_REQUEST64_CR
))
2650 lpfc_send_els_failure_event(phba
,
2654 * Post all ELS completions to the worker thread.
2655 * All other are passed to the completion callback.
2657 if (pring
->ringno
== LPFC_ELS_RING
) {
2658 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2659 (cmdiocbp
->iocb_flag
&
2660 LPFC_DRIVER_ABORTED
)) {
2661 spin_lock_irqsave(&phba
->hbalock
,
2663 cmdiocbp
->iocb_flag
&=
2664 ~LPFC_DRIVER_ABORTED
;
2665 spin_unlock_irqrestore(&phba
->hbalock
,
2667 saveq
->iocb
.ulpStatus
=
2668 IOSTAT_LOCAL_REJECT
;
2669 saveq
->iocb
.un
.ulpWord
[4] =
2672 /* Firmware could still be in progress
2673 * of DMAing payload, so don't free data
2674 * buffer till after a hbeat.
2676 spin_lock_irqsave(&phba
->hbalock
,
2678 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2679 spin_unlock_irqrestore(&phba
->hbalock
,
2682 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2683 if (saveq
->iocb_flag
&
2684 LPFC_EXCHANGE_BUSY
) {
2685 /* Set cmdiocb flag for the
2686 * exchange busy so sgl (xri)
2687 * will not be released until
2688 * the abort xri is received
2692 &phba
->hbalock
, iflag
);
2693 cmdiocbp
->iocb_flag
|=
2695 spin_unlock_irqrestore(
2696 &phba
->hbalock
, iflag
);
2698 if (cmdiocbp
->iocb_flag
&
2699 LPFC_DRIVER_ABORTED
) {
2701 * Clear LPFC_DRIVER_ABORTED
2702 * bit in case it was driver
2706 &phba
->hbalock
, iflag
);
2707 cmdiocbp
->iocb_flag
&=
2708 ~LPFC_DRIVER_ABORTED
;
2709 spin_unlock_irqrestore(
2710 &phba
->hbalock
, iflag
);
2711 cmdiocbp
->iocb
.ulpStatus
=
2712 IOSTAT_LOCAL_REJECT
;
2713 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2714 IOERR_ABORT_REQUESTED
;
2716 * For SLI4, irsiocb contains
2717 * NO_XRI in sli_xritag, it
2718 * shall not affect releasing
2719 * sgl (xri) process.
2721 saveq
->iocb
.ulpStatus
=
2722 IOSTAT_LOCAL_REJECT
;
2723 saveq
->iocb
.un
.ulpWord
[4] =
2726 &phba
->hbalock
, iflag
);
2728 LPFC_DELAY_MEM_FREE
;
2729 spin_unlock_irqrestore(
2730 &phba
->hbalock
, iflag
);
2734 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2736 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2739 * Unknown initiating command based on the response iotag.
2740 * This could be the case on the ELS ring because of
2743 if (pring
->ringno
!= LPFC_ELS_RING
) {
2745 * Ring <ringno> handler: unexpected completion IoTag
2748 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2749 "0322 Ring %d handler: "
2750 "unexpected completion IoTag x%x "
2751 "Data: x%x x%x x%x x%x\n",
2753 saveq
->iocb
.ulpIoTag
,
2754 saveq
->iocb
.ulpStatus
,
2755 saveq
->iocb
.un
.ulpWord
[4],
2756 saveq
->iocb
.ulpCommand
,
2757 saveq
->iocb
.ulpContext
);
2765 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2766 * @phba: Pointer to HBA context object.
2767 * @pring: Pointer to driver SLI ring object.
2769 * This function is called from the iocb ring event handlers when
2770 * put pointer is ahead of the get pointer for a ring. This function signal
2771 * an error attention condition to the worker thread and the worker
2772 * thread will transition the HBA to offline state.
2775 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2777 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2779 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2780 * rsp ring <portRspMax>
2782 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2783 "0312 Ring %d handler: portRspPut %d "
2784 "is bigger than rsp ring %d\n",
2785 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2788 phba
->link_state
= LPFC_HBA_ERROR
;
2791 * All error attention handlers are posted to
2794 phba
->work_ha
|= HA_ERATT
;
2795 phba
->work_hs
= HS_FFER3
;
2797 lpfc_worker_wake_up(phba
);
2803 * lpfc_poll_eratt - Error attention polling timer timeout handler
2804 * @ptr: Pointer to address of HBA context object.
2806 * This function is invoked by the Error Attention polling timer when the
2807 * timer times out. It will check the SLI Error Attention register for
2808 * possible attention events. If so, it will post an Error Attention event
2809 * and wake up worker thread to process it. Otherwise, it will set up the
2810 * Error Attention polling timer for the next poll.
2812 void lpfc_poll_eratt(unsigned long ptr
)
2814 struct lpfc_hba
*phba
;
2817 phba
= (struct lpfc_hba
*)ptr
;
2819 /* Check chip HA register for error event */
2820 eratt
= lpfc_sli_check_eratt(phba
);
2823 /* Tell the worker thread there is work to do */
2824 lpfc_worker_wake_up(phba
);
2826 /* Restart the timer for next eratt poll */
2827 mod_timer(&phba
->eratt_poll
, jiffies
+
2828 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2834 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2835 * @phba: Pointer to HBA context object.
2836 * @pring: Pointer to driver SLI ring object.
2837 * @mask: Host attention register mask for this ring.
2839 * This function is called from the interrupt context when there is a ring
2840 * event for the fcp ring. The caller does not hold any lock.
2841 * The function processes each response iocb in the response ring until it
2842 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2843 * LE bit set. The function will call the completion handler of the command iocb
2844 * if the response iocb indicates a completion for a command iocb or it is
2845 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2846 * function if this is an unsolicited iocb.
2847 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2848 * to check it explicitly.
2851 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2852 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2854 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2855 IOCB_t
*irsp
= NULL
;
2856 IOCB_t
*entry
= NULL
;
2857 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2858 struct lpfc_iocbq rspiocbq
;
2860 uint32_t portRspPut
, portRspMax
;
2862 lpfc_iocb_type type
;
2863 unsigned long iflag
;
2864 uint32_t rsp_cmpl
= 0;
2866 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2867 pring
->stats
.iocb_event
++;
2870 * The next available response entry should never exceed the maximum
2871 * entries. If it does, treat it as an adapter hardware error.
2873 portRspMax
= pring
->numRiocb
;
2874 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2875 if (unlikely(portRspPut
>= portRspMax
)) {
2876 lpfc_sli_rsp_pointers_error(phba
, pring
);
2877 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2880 if (phba
->fcp_ring_in_use
) {
2881 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2884 phba
->fcp_ring_in_use
= 1;
2887 while (pring
->rspidx
!= portRspPut
) {
2889 * Fetch an entry off the ring and copy it into a local data
2890 * structure. The copy involves a byte-swap since the
2891 * network byte order and pci byte orders are different.
2893 entry
= lpfc_resp_iocb(phba
, pring
);
2894 phba
->last_completion_time
= jiffies
;
2896 if (++pring
->rspidx
>= portRspMax
)
2899 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2900 (uint32_t *) &rspiocbq
.iocb
,
2901 phba
->iocb_rsp_size
);
2902 INIT_LIST_HEAD(&(rspiocbq
.list
));
2903 irsp
= &rspiocbq
.iocb
;
2905 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2906 pring
->stats
.iocb_rsp
++;
2909 if (unlikely(irsp
->ulpStatus
)) {
2911 * If resource errors reported from HBA, reduce
2912 * queuedepths of the SCSI device.
2914 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2915 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2916 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2917 phba
->lpfc_rampdown_queue_depth(phba
);
2918 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2921 /* Rsp ring <ringno> error: IOCB */
2922 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2923 "0336 Rsp Ring %d error: IOCB Data: "
2924 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2926 irsp
->un
.ulpWord
[0],
2927 irsp
->un
.ulpWord
[1],
2928 irsp
->un
.ulpWord
[2],
2929 irsp
->un
.ulpWord
[3],
2930 irsp
->un
.ulpWord
[4],
2931 irsp
->un
.ulpWord
[5],
2932 *(uint32_t *)&irsp
->un1
,
2933 *((uint32_t *)&irsp
->un1
+ 1));
2937 case LPFC_ABORT_IOCB
:
2940 * Idle exchange closed via ABTS from port. No iocb
2941 * resources need to be recovered.
2943 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2944 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2945 "0333 IOCB cmd 0x%x"
2946 " processed. Skipping"
2952 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2954 if (unlikely(!cmdiocbq
))
2956 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
2957 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
2958 if (cmdiocbq
->iocb_cmpl
) {
2959 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2960 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2962 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2965 case LPFC_UNSOL_IOCB
:
2966 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2967 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2968 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2971 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2972 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2973 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2974 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2976 dev_warn(&((phba
->pcidev
)->dev
),
2978 phba
->brd_no
, adaptermsg
);
2980 /* Unknown IOCB command */
2981 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2982 "0334 Unknown IOCB command "
2983 "Data: x%x, x%x x%x x%x x%x\n",
2984 type
, irsp
->ulpCommand
,
2993 * The response IOCB has been processed. Update the ring
2994 * pointer in SLIM. If the port response put pointer has not
2995 * been updated, sync the pgp->rspPutInx and fetch the new port
2996 * response put pointer.
2998 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3000 if (pring
->rspidx
== portRspPut
)
3001 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3004 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3005 pring
->stats
.iocb_rsp_full
++;
3006 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3007 writel(status
, phba
->CAregaddr
);
3008 readl(phba
->CAregaddr
);
3010 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3011 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3012 pring
->stats
.iocb_cmd_empty
++;
3014 /* Force update of the local copy of cmdGetInx */
3015 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3016 lpfc_sli_resume_iocb(phba
, pring
);
3018 if ((pring
->lpfc_sli_cmd_available
))
3019 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3023 phba
->fcp_ring_in_use
= 0;
3024 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3029 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3030 * @phba: Pointer to HBA context object.
3031 * @pring: Pointer to driver SLI ring object.
3032 * @rspiocbp: Pointer to driver response IOCB object.
3034 * This function is called from the worker thread when there is a slow-path
3035 * response IOCB to process. This function chains all the response iocbs until
3036 * seeing the iocb with the LE bit set. The function will call
3037 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3038 * completion of a command iocb. The function will call the
3039 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3040 * The function frees the resources or calls the completion handler if this
3041 * iocb is an abort completion. The function returns NULL when the response
3042 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3043 * this function shall chain the iocb on to the iocb_continueq and return the
3044 * response iocb passed in.
3046 static struct lpfc_iocbq
*
3047 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3048 struct lpfc_iocbq
*rspiocbp
)
3050 struct lpfc_iocbq
*saveq
;
3051 struct lpfc_iocbq
*cmdiocbp
;
3052 struct lpfc_iocbq
*next_iocb
;
3053 IOCB_t
*irsp
= NULL
;
3054 uint32_t free_saveq
;
3055 uint8_t iocb_cmd_type
;
3056 lpfc_iocb_type type
;
3057 unsigned long iflag
;
3060 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3061 /* First add the response iocb to the countinueq list */
3062 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3063 pring
->iocb_continueq_cnt
++;
3065 /* Now, determine whether the list is completed for processing */
3066 irsp
= &rspiocbp
->iocb
;
3069 * By default, the driver expects to free all resources
3070 * associated with this iocb completion.
3073 saveq
= list_get_first(&pring
->iocb_continueq
,
3074 struct lpfc_iocbq
, list
);
3075 irsp
= &(saveq
->iocb
);
3076 list_del_init(&pring
->iocb_continueq
);
3077 pring
->iocb_continueq_cnt
= 0;
3079 pring
->stats
.iocb_rsp
++;
3082 * If resource errors reported from HBA, reduce
3083 * queuedepths of the SCSI device.
3085 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3086 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
3087 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3088 phba
->lpfc_rampdown_queue_depth(phba
);
3089 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3092 if (irsp
->ulpStatus
) {
3093 /* Rsp ring <ringno> error: IOCB */
3094 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3095 "0328 Rsp Ring %d error: "
3100 "x%x x%x x%x x%x\n",
3102 irsp
->un
.ulpWord
[0],
3103 irsp
->un
.ulpWord
[1],
3104 irsp
->un
.ulpWord
[2],
3105 irsp
->un
.ulpWord
[3],
3106 irsp
->un
.ulpWord
[4],
3107 irsp
->un
.ulpWord
[5],
3108 *(((uint32_t *) irsp
) + 6),
3109 *(((uint32_t *) irsp
) + 7),
3110 *(((uint32_t *) irsp
) + 8),
3111 *(((uint32_t *) irsp
) + 9),
3112 *(((uint32_t *) irsp
) + 10),
3113 *(((uint32_t *) irsp
) + 11),
3114 *(((uint32_t *) irsp
) + 12),
3115 *(((uint32_t *) irsp
) + 13),
3116 *(((uint32_t *) irsp
) + 14),
3117 *(((uint32_t *) irsp
) + 15));
3121 * Fetch the IOCB command type and call the correct completion
3122 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3123 * get freed back to the lpfc_iocb_list by the discovery
3126 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3127 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3130 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3131 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3132 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3135 case LPFC_UNSOL_IOCB
:
3136 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3137 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3138 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3143 case LPFC_ABORT_IOCB
:
3145 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3146 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3149 /* Call the specified completion routine */
3150 if (cmdiocbp
->iocb_cmpl
) {
3151 spin_unlock_irqrestore(&phba
->hbalock
,
3153 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3155 spin_lock_irqsave(&phba
->hbalock
,
3158 __lpfc_sli_release_iocbq(phba
,
3163 case LPFC_UNKNOWN_IOCB
:
3164 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3165 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3166 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3167 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3169 dev_warn(&((phba
->pcidev
)->dev
),
3171 phba
->brd_no
, adaptermsg
);
3173 /* Unknown IOCB command */
3174 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3175 "0335 Unknown IOCB "
3176 "command Data: x%x "
3187 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3188 &saveq
->list
, list
) {
3189 list_del(&rspiocbp
->list
);
3190 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3192 __lpfc_sli_release_iocbq(phba
, saveq
);
3196 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3201 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3202 * @phba: Pointer to HBA context object.
3203 * @pring: Pointer to driver SLI ring object.
3204 * @mask: Host attention register mask for this ring.
3206 * This routine wraps the actual slow_ring event process routine from the
3207 * API jump table function pointer from the lpfc_hba struct.
3210 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3211 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3213 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3217 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3218 * @phba: Pointer to HBA context object.
3219 * @pring: Pointer to driver SLI ring object.
3220 * @mask: Host attention register mask for this ring.
3222 * This function is called from the worker thread when there is a ring event
3223 * for non-fcp rings. The caller does not hold any lock. The function will
3224 * remove each response iocb in the response ring and calls the handle
3225 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3228 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3229 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3231 struct lpfc_pgp
*pgp
;
3233 IOCB_t
*irsp
= NULL
;
3234 struct lpfc_iocbq
*rspiocbp
= NULL
;
3235 uint32_t portRspPut
, portRspMax
;
3236 unsigned long iflag
;
3239 pgp
= &phba
->port_gp
[pring
->ringno
];
3240 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3241 pring
->stats
.iocb_event
++;
3244 * The next available response entry should never exceed the maximum
3245 * entries. If it does, treat it as an adapter hardware error.
3247 portRspMax
= pring
->numRiocb
;
3248 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3249 if (portRspPut
>= portRspMax
) {
3251 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3252 * rsp ring <portRspMax>
3254 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3255 "0303 Ring %d handler: portRspPut %d "
3256 "is bigger than rsp ring %d\n",
3257 pring
->ringno
, portRspPut
, portRspMax
);
3259 phba
->link_state
= LPFC_HBA_ERROR
;
3260 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3262 phba
->work_hs
= HS_FFER3
;
3263 lpfc_handle_eratt(phba
);
3269 while (pring
->rspidx
!= portRspPut
) {
3271 * Build a completion list and call the appropriate handler.
3272 * The process is to get the next available response iocb, get
3273 * a free iocb from the list, copy the response data into the
3274 * free iocb, insert to the continuation list, and update the
3275 * next response index to slim. This process makes response
3276 * iocb's in the ring available to DMA as fast as possible but
3277 * pays a penalty for a copy operation. Since the iocb is
3278 * only 32 bytes, this penalty is considered small relative to
3279 * the PCI reads for register values and a slim write. When
3280 * the ulpLe field is set, the entire Command has been
3283 entry
= lpfc_resp_iocb(phba
, pring
);
3285 phba
->last_completion_time
= jiffies
;
3286 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3287 if (rspiocbp
== NULL
) {
3288 printk(KERN_ERR
"%s: out of buffers! Failing "
3289 "completion.\n", __func__
);
3293 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3294 phba
->iocb_rsp_size
);
3295 irsp
= &rspiocbp
->iocb
;
3297 if (++pring
->rspidx
>= portRspMax
)
3300 if (pring
->ringno
== LPFC_ELS_RING
) {
3301 lpfc_debugfs_slow_ring_trc(phba
,
3302 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3303 *(((uint32_t *) irsp
) + 4),
3304 *(((uint32_t *) irsp
) + 6),
3305 *(((uint32_t *) irsp
) + 7));
3308 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3310 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3311 /* Handle the response IOCB */
3312 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3313 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3316 * If the port response put pointer has not been updated, sync
3317 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3318 * response put pointer.
3320 if (pring
->rspidx
== portRspPut
) {
3321 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3323 } /* while (pring->rspidx != portRspPut) */
3325 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3326 /* At least one response entry has been freed */
3327 pring
->stats
.iocb_rsp_full
++;
3328 /* SET RxRE_RSP in Chip Att register */
3329 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3330 writel(status
, phba
->CAregaddr
);
3331 readl(phba
->CAregaddr
); /* flush */
3333 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3334 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3335 pring
->stats
.iocb_cmd_empty
++;
3337 /* Force update of the local copy of cmdGetInx */
3338 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3339 lpfc_sli_resume_iocb(phba
, pring
);
3341 if ((pring
->lpfc_sli_cmd_available
))
3342 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3346 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3351 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3352 * @phba: Pointer to HBA context object.
3353 * @pring: Pointer to driver SLI ring object.
3354 * @mask: Host attention register mask for this ring.
3356 * This function is called from the worker thread when there is a pending
3357 * ELS response iocb on the driver internal slow-path response iocb worker
3358 * queue. The caller does not hold any lock. The function will remove each
3359 * response iocb from the response worker queue and calls the handle
3360 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3363 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3364 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3366 struct lpfc_iocbq
*irspiocbq
;
3367 struct hbq_dmabuf
*dmabuf
;
3368 struct lpfc_cq_event
*cq_event
;
3369 unsigned long iflag
;
3371 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3372 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3373 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3374 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3375 /* Get the response iocb from the head of work queue */
3376 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3377 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3378 cq_event
, struct lpfc_cq_event
, list
);
3379 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3381 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3382 case CQE_CODE_COMPL_WQE
:
3383 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3385 /* Translate ELS WCQE to response IOCBQ */
3386 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3389 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3392 case CQE_CODE_RECEIVE
:
3393 case CQE_CODE_RECEIVE_V1
:
3394 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3396 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3405 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3406 * @phba: Pointer to HBA context object.
3407 * @pring: Pointer to driver SLI ring object.
3409 * This function aborts all iocbs in the given ring and frees all the iocb
3410 * objects in txq. This function issues an abort iocb for all the iocb commands
3411 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3412 * the return of this function. The caller is not required to hold any locks.
3415 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3417 LIST_HEAD(completions
);
3418 struct lpfc_iocbq
*iocb
, *next_iocb
;
3420 if (pring
->ringno
== LPFC_ELS_RING
) {
3421 lpfc_fabric_abort_hba(phba
);
3424 /* Error everything on txq and txcmplq
3427 spin_lock_irq(&phba
->hbalock
);
3428 list_splice_init(&pring
->txq
, &completions
);
3431 /* Next issue ABTS for everything on the txcmplq */
3432 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3433 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3435 spin_unlock_irq(&phba
->hbalock
);
3437 /* Cancel all the IOCBs from the completions list */
3438 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3443 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3444 * @phba: Pointer to HBA context object.
3446 * This function flushes all iocbs in the fcp ring and frees all the iocb
3447 * objects in txq and txcmplq. This function will not issue abort iocbs
3448 * for all the iocb commands in txcmplq, they will just be returned with
3449 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3450 * slot has been permanently disabled.
3453 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3457 struct lpfc_sli
*psli
= &phba
->sli
;
3458 struct lpfc_sli_ring
*pring
;
3460 /* Currently, only one fcp ring */
3461 pring
= &psli
->ring
[psli
->fcp_ring
];
3463 spin_lock_irq(&phba
->hbalock
);
3464 /* Retrieve everything on txq */
3465 list_splice_init(&pring
->txq
, &txq
);
3468 /* Retrieve everything on the txcmplq */
3469 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3470 pring
->txcmplq_cnt
= 0;
3472 /* Indicate the I/O queues are flushed */
3473 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3474 spin_unlock_irq(&phba
->hbalock
);
3477 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3480 /* Flush the txcmpq */
3481 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3486 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3487 * @phba: Pointer to HBA context object.
3488 * @mask: Bit mask to be checked.
3490 * This function reads the host status register and compares
3491 * with the provided bit mask to check if HBA completed
3492 * the restart. This function will wait in a loop for the
3493 * HBA to complete restart. If the HBA does not restart within
3494 * 15 iterations, the function will reset the HBA again. The
3495 * function returns 1 when HBA fail to restart otherwise returns
3499 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3505 /* Read the HBA Host Status Register */
3506 if (lpfc_readl(phba
->HSregaddr
, &status
))
3510 * Check status register every 100ms for 5 retries, then every
3511 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3512 * every 2.5 sec for 4.
3513 * Break our of the loop if errors occurred during init.
3515 while (((status
& mask
) != mask
) &&
3516 !(status
& HS_FFERM
) &&
3528 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3529 lpfc_sli_brdrestart(phba
);
3531 /* Read the HBA Host Status Register */
3532 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3538 /* Check to see if any errors occurred during init */
3539 if ((status
& HS_FFERM
) || (i
>= 20)) {
3540 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3541 "2751 Adapter failed to restart, "
3542 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3544 readl(phba
->MBslimaddr
+ 0xa8),
3545 readl(phba
->MBslimaddr
+ 0xac));
3546 phba
->link_state
= LPFC_HBA_ERROR
;
3554 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3555 * @phba: Pointer to HBA context object.
3556 * @mask: Bit mask to be checked.
3558 * This function checks the host status register to check if HBA is
3559 * ready. This function will wait in a loop for the HBA to be ready
3560 * If the HBA is not ready , the function will will reset the HBA PCI
3561 * function again. The function returns 1 when HBA fail to be ready
3562 * otherwise returns zero.
3565 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3570 /* Read the HBA Host Status Register */
3571 status
= lpfc_sli4_post_status_check(phba
);
3574 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3575 lpfc_sli_brdrestart(phba
);
3576 status
= lpfc_sli4_post_status_check(phba
);
3579 /* Check to see if any errors occurred during init */
3581 phba
->link_state
= LPFC_HBA_ERROR
;
3584 phba
->sli4_hba
.intr_enable
= 0;
3590 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3591 * @phba: Pointer to HBA context object.
3592 * @mask: Bit mask to be checked.
3594 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3595 * from the API jump table function pointer from the lpfc_hba struct.
3598 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3600 return phba
->lpfc_sli_brdready(phba
, mask
);
3603 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3606 * lpfc_reset_barrier - Make HBA ready for HBA reset
3607 * @phba: Pointer to HBA context object.
3609 * This function is called before resetting an HBA. This function is called
3610 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3612 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3614 uint32_t __iomem
*resp_buf
;
3615 uint32_t __iomem
*mbox_buf
;
3616 volatile uint32_t mbox
;
3617 uint32_t hc_copy
, ha_copy
, resp_data
;
3621 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3622 if (hdrtype
!= 0x80 ||
3623 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3624 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3628 * Tell the other part of the chip to suspend temporarily all
3631 resp_buf
= phba
->MBslimaddr
;
3633 /* Disable the error attention */
3634 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3636 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3637 readl(phba
->HCregaddr
); /* flush */
3638 phba
->link_flag
|= LS_IGNORE_ERATT
;
3640 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3642 if (ha_copy
& HA_ERATT
) {
3643 /* Clear Chip error bit */
3644 writel(HA_ERATT
, phba
->HAregaddr
);
3645 phba
->pport
->stopped
= 1;
3649 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3650 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3652 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3653 mbox_buf
= phba
->MBslimaddr
;
3654 writel(mbox
, mbox_buf
);
3656 for (i
= 0; i
< 50; i
++) {
3657 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3659 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3665 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3667 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3668 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3669 phba
->pport
->stopped
)
3675 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3677 for (i
= 0; i
< 500; i
++) {
3678 if (lpfc_readl(resp_buf
, &resp_data
))
3680 if (resp_data
!= mbox
)
3689 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3691 if (!(ha_copy
& HA_ERATT
))
3697 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3698 writel(HA_ERATT
, phba
->HAregaddr
);
3699 phba
->pport
->stopped
= 1;
3703 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3704 writel(hc_copy
, phba
->HCregaddr
);
3705 readl(phba
->HCregaddr
); /* flush */
3709 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3710 * @phba: Pointer to HBA context object.
3712 * This function issues a kill_board mailbox command and waits for
3713 * the error attention interrupt. This function is called for stopping
3714 * the firmware processing. The caller is not required to hold any
3715 * locks. This function calls lpfc_hba_down_post function to free
3716 * any pending commands after the kill. The function will return 1 when it
3717 * fails to kill the board else will return 0.
3720 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3722 struct lpfc_sli
*psli
;
3732 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3733 "0329 Kill HBA Data: x%x x%x\n",
3734 phba
->pport
->port_state
, psli
->sli_flag
);
3736 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3740 /* Disable the error attention */
3741 spin_lock_irq(&phba
->hbalock
);
3742 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3743 spin_unlock_irq(&phba
->hbalock
);
3744 mempool_free(pmb
, phba
->mbox_mem_pool
);
3747 status
&= ~HC_ERINT_ENA
;
3748 writel(status
, phba
->HCregaddr
);
3749 readl(phba
->HCregaddr
); /* flush */
3750 phba
->link_flag
|= LS_IGNORE_ERATT
;
3751 spin_unlock_irq(&phba
->hbalock
);
3753 lpfc_kill_board(phba
, pmb
);
3754 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3755 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3757 if (retval
!= MBX_SUCCESS
) {
3758 if (retval
!= MBX_BUSY
)
3759 mempool_free(pmb
, phba
->mbox_mem_pool
);
3760 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3761 "2752 KILL_BOARD command failed retval %d\n",
3763 spin_lock_irq(&phba
->hbalock
);
3764 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3765 spin_unlock_irq(&phba
->hbalock
);
3769 spin_lock_irq(&phba
->hbalock
);
3770 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3771 spin_unlock_irq(&phba
->hbalock
);
3773 mempool_free(pmb
, phba
->mbox_mem_pool
);
3775 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3776 * attention every 100ms for 3 seconds. If we don't get ERATT after
3777 * 3 seconds we still set HBA_ERROR state because the status of the
3778 * board is now undefined.
3780 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3782 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3784 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3788 del_timer_sync(&psli
->mbox_tmo
);
3789 if (ha_copy
& HA_ERATT
) {
3790 writel(HA_ERATT
, phba
->HAregaddr
);
3791 phba
->pport
->stopped
= 1;
3793 spin_lock_irq(&phba
->hbalock
);
3794 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3795 psli
->mbox_active
= NULL
;
3796 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3797 spin_unlock_irq(&phba
->hbalock
);
3799 lpfc_hba_down_post(phba
);
3800 phba
->link_state
= LPFC_HBA_ERROR
;
3802 return ha_copy
& HA_ERATT
? 0 : 1;
3806 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3807 * @phba: Pointer to HBA context object.
3809 * This function resets the HBA by writing HC_INITFF to the control
3810 * register. After the HBA resets, this function resets all the iocb ring
3811 * indices. This function disables PCI layer parity checking during
3813 * This function returns 0 always.
3814 * The caller is not required to hold any locks.
3817 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3819 struct lpfc_sli
*psli
;
3820 struct lpfc_sli_ring
*pring
;
3827 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3828 "0325 Reset HBA Data: x%x x%x\n",
3829 phba
->pport
->port_state
, psli
->sli_flag
);
3831 /* perform board reset */
3832 phba
->fc_eventTag
= 0;
3833 phba
->link_events
= 0;
3834 phba
->pport
->fc_myDID
= 0;
3835 phba
->pport
->fc_prevDID
= 0;
3837 /* Turn off parity checking and serr during the physical reset */
3838 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3839 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3841 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3843 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3845 /* Now toggle INITFF bit in the Host Control Register */
3846 writel(HC_INITFF
, phba
->HCregaddr
);
3848 readl(phba
->HCregaddr
); /* flush */
3849 writel(0, phba
->HCregaddr
);
3850 readl(phba
->HCregaddr
); /* flush */
3852 /* Restore PCI cmd register */
3853 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3855 /* Initialize relevant SLI info */
3856 for (i
= 0; i
< psli
->num_rings
; i
++) {
3857 pring
= &psli
->ring
[i
];
3860 pring
->next_cmdidx
= 0;
3861 pring
->local_getidx
= 0;
3863 pring
->missbufcnt
= 0;
3866 phba
->link_state
= LPFC_WARM_START
;
3871 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3872 * @phba: Pointer to HBA context object.
3874 * This function resets a SLI4 HBA. This function disables PCI layer parity
3875 * checking during resets the device. The caller is not required to hold
3878 * This function returns 0 always.
3881 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3883 struct lpfc_sli
*psli
= &phba
->sli
;
3887 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3888 "0295 Reset HBA Data: x%x x%x\n",
3889 phba
->pport
->port_state
, psli
->sli_flag
);
3891 /* perform board reset */
3892 phba
->fc_eventTag
= 0;
3893 phba
->link_events
= 0;
3894 phba
->pport
->fc_myDID
= 0;
3895 phba
->pport
->fc_prevDID
= 0;
3897 spin_lock_irq(&phba
->hbalock
);
3898 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3899 phba
->fcf
.fcf_flag
= 0;
3900 spin_unlock_irq(&phba
->hbalock
);
3902 /* Now physically reset the device */
3903 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3904 "0389 Performing PCI function reset!\n");
3906 /* Turn off parity checking and serr during the physical reset */
3907 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3908 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3909 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3911 /* Perform FCoE PCI function reset */
3912 lpfc_sli4_queue_destroy(phba
);
3913 lpfc_pci_function_reset(phba
);
3915 /* Restore PCI cmd register */
3916 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3922 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3923 * @phba: Pointer to HBA context object.
3925 * This function is called in the SLI initialization code path to
3926 * restart the HBA. The caller is not required to hold any lock.
3927 * This function writes MBX_RESTART mailbox command to the SLIM and
3928 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3929 * function to free any pending commands. The function enables
3930 * POST only during the first initialization. The function returns zero.
3931 * The function does not guarantee completion of MBX_RESTART mailbox
3932 * command before the return of this function.
3935 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3938 struct lpfc_sli
*psli
;
3939 volatile uint32_t word0
;
3940 void __iomem
*to_slim
;
3941 uint32_t hba_aer_enabled
;
3943 spin_lock_irq(&phba
->hbalock
);
3945 /* Take PCIe device Advanced Error Reporting (AER) state */
3946 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3951 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3952 "0337 Restart HBA Data: x%x x%x\n",
3953 phba
->pport
->port_state
, psli
->sli_flag
);
3956 mb
= (MAILBOX_t
*) &word0
;
3957 mb
->mbxCommand
= MBX_RESTART
;
3960 lpfc_reset_barrier(phba
);
3962 to_slim
= phba
->MBslimaddr
;
3963 writel(*(uint32_t *) mb
, to_slim
);
3964 readl(to_slim
); /* flush */
3966 /* Only skip post after fc_ffinit is completed */
3967 if (phba
->pport
->port_state
)
3968 word0
= 1; /* This is really setting up word1 */
3970 word0
= 0; /* This is really setting up word1 */
3971 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
3972 writel(*(uint32_t *) mb
, to_slim
);
3973 readl(to_slim
); /* flush */
3975 lpfc_sli_brdreset(phba
);
3976 phba
->pport
->stopped
= 0;
3977 phba
->link_state
= LPFC_INIT_START
;
3979 spin_unlock_irq(&phba
->hbalock
);
3981 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3982 psli
->stats_start
= get_seconds();
3984 /* Give the INITFF and Post time to settle. */
3987 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
3988 if (hba_aer_enabled
)
3989 pci_disable_pcie_error_reporting(phba
->pcidev
);
3991 lpfc_hba_down_post(phba
);
3997 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3998 * @phba: Pointer to HBA context object.
4000 * This function is called in the SLI initialization code path to restart
4001 * a SLI4 HBA. The caller is not required to hold any lock.
4002 * At the end of the function, it calls lpfc_hba_down_post function to
4003 * free any pending commands.
4006 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4008 struct lpfc_sli
*psli
= &phba
->sli
;
4009 uint32_t hba_aer_enabled
;
4012 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4013 "0296 Restart HBA Data: x%x x%x\n",
4014 phba
->pport
->port_state
, psli
->sli_flag
);
4016 /* Take PCIe device Advanced Error Reporting (AER) state */
4017 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4019 lpfc_sli4_brdreset(phba
);
4021 spin_lock_irq(&phba
->hbalock
);
4022 phba
->pport
->stopped
= 0;
4023 phba
->link_state
= LPFC_INIT_START
;
4025 spin_unlock_irq(&phba
->hbalock
);
4027 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4028 psli
->stats_start
= get_seconds();
4030 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4031 if (hba_aer_enabled
)
4032 pci_disable_pcie_error_reporting(phba
->pcidev
);
4034 lpfc_hba_down_post(phba
);
4040 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4041 * @phba: Pointer to HBA context object.
4043 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4044 * API jump table function pointer from the lpfc_hba struct.
4047 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4049 return phba
->lpfc_sli_brdrestart(phba
);
4053 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4054 * @phba: Pointer to HBA context object.
4056 * This function is called after a HBA restart to wait for successful
4057 * restart of the HBA. Successful restart of the HBA is indicated by
4058 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4059 * iteration, the function will restart the HBA again. The function returns
4060 * zero if HBA successfully restarted else returns negative error code.
4063 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4065 uint32_t status
, i
= 0;
4067 /* Read the HBA Host Status Register */
4068 if (lpfc_readl(phba
->HSregaddr
, &status
))
4071 /* Check status register to see what current state is */
4073 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4075 /* Check every 10ms for 10 retries, then every 100ms for 90
4076 * retries, then every 1 sec for 50 retires for a total of
4077 * ~60 seconds before reset the board again and check every
4078 * 1 sec for 50 retries. The up to 60 seconds before the
4079 * board ready is required by the Falcon FIPS zeroization
4080 * complete, and any reset the board in between shall cause
4081 * restart of zeroization, further delay the board ready.
4084 /* Adapter failed to init, timeout, status reg
4086 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4087 "0436 Adapter failed to init, "
4088 "timeout, status reg x%x, "
4089 "FW Data: A8 x%x AC x%x\n", status
,
4090 readl(phba
->MBslimaddr
+ 0xa8),
4091 readl(phba
->MBslimaddr
+ 0xac));
4092 phba
->link_state
= LPFC_HBA_ERROR
;
4096 /* Check to see if any errors occurred during init */
4097 if (status
& HS_FFERM
) {
4098 /* ERROR: During chipset initialization */
4099 /* Adapter failed to init, chipset, status reg
4101 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4102 "0437 Adapter failed to init, "
4103 "chipset, status reg x%x, "
4104 "FW Data: A8 x%x AC x%x\n", status
,
4105 readl(phba
->MBslimaddr
+ 0xa8),
4106 readl(phba
->MBslimaddr
+ 0xac));
4107 phba
->link_state
= LPFC_HBA_ERROR
;
4120 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4121 lpfc_sli_brdrestart(phba
);
4123 /* Read the HBA Host Status Register */
4124 if (lpfc_readl(phba
->HSregaddr
, &status
))
4128 /* Check to see if any errors occurred during init */
4129 if (status
& HS_FFERM
) {
4130 /* ERROR: During chipset initialization */
4131 /* Adapter failed to init, chipset, status reg <status> */
4132 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4133 "0438 Adapter failed to init, chipset, "
4135 "FW Data: A8 x%x AC x%x\n", status
,
4136 readl(phba
->MBslimaddr
+ 0xa8),
4137 readl(phba
->MBslimaddr
+ 0xac));
4138 phba
->link_state
= LPFC_HBA_ERROR
;
4142 /* Clear all interrupt enable conditions */
4143 writel(0, phba
->HCregaddr
);
4144 readl(phba
->HCregaddr
); /* flush */
4146 /* setup host attn register */
4147 writel(0xffffffff, phba
->HAregaddr
);
4148 readl(phba
->HAregaddr
); /* flush */
4153 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4155 * This function calculates and returns the number of HBQs required to be
4159 lpfc_sli_hbq_count(void)
4161 return ARRAY_SIZE(lpfc_hbq_defs
);
4165 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4167 * This function adds the number of hbq entries in every HBQ to get
4168 * the total number of hbq entries required for the HBA and returns
4172 lpfc_sli_hbq_entry_count(void)
4174 int hbq_count
= lpfc_sli_hbq_count();
4178 for (i
= 0; i
< hbq_count
; ++i
)
4179 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4184 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4186 * This function calculates amount of memory required for all hbq entries
4187 * to be configured and returns the total memory required.
4190 lpfc_sli_hbq_size(void)
4192 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4196 * lpfc_sli_hbq_setup - configure and initialize HBQs
4197 * @phba: Pointer to HBA context object.
4199 * This function is called during the SLI initialization to configure
4200 * all the HBQs and post buffers to the HBQ. The caller is not
4201 * required to hold any locks. This function will return zero if successful
4202 * else it will return negative error code.
4205 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4207 int hbq_count
= lpfc_sli_hbq_count();
4211 uint32_t hbq_entry_index
;
4213 /* Get a Mailbox buffer to setup mailbox
4214 * commands for HBA initialization
4216 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4223 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4224 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4225 phba
->hbq_in_use
= 1;
4227 hbq_entry_index
= 0;
4228 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4229 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4230 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4231 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4232 phba
->hbqs
[hbqno
].entry_count
=
4233 lpfc_hbq_defs
[hbqno
]->entry_count
;
4234 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4235 hbq_entry_index
, pmb
);
4236 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4238 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4239 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4240 mbxStatus <status>, ring <num> */
4242 lpfc_printf_log(phba
, KERN_ERR
,
4243 LOG_SLI
| LOG_VPORT
,
4244 "1805 Adapter failed to init. "
4245 "Data: x%x x%x x%x\n",
4247 pmbox
->mbxStatus
, hbqno
);
4249 phba
->link_state
= LPFC_HBA_ERROR
;
4250 mempool_free(pmb
, phba
->mbox_mem_pool
);
4254 phba
->hbq_count
= hbq_count
;
4256 mempool_free(pmb
, phba
->mbox_mem_pool
);
4258 /* Initially populate or replenish the HBQs */
4259 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4260 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4265 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4266 * @phba: Pointer to HBA context object.
4268 * This function is called during the SLI initialization to configure
4269 * all the HBQs and post buffers to the HBQ. The caller is not
4270 * required to hold any locks. This function will return zero if successful
4271 * else it will return negative error code.
4274 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4276 phba
->hbq_in_use
= 1;
4277 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4278 phba
->hbq_count
= 1;
4279 /* Initially populate or replenish the HBQs */
4280 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4285 * lpfc_sli_config_port - Issue config port mailbox command
4286 * @phba: Pointer to HBA context object.
4287 * @sli_mode: sli mode - 2/3
4289 * This function is called by the sli intialization code path
4290 * to issue config_port mailbox command. This function restarts the
4291 * HBA firmware and issues a config_port mailbox command to configure
4292 * the SLI interface in the sli mode specified by sli_mode
4293 * variable. The caller is not required to hold any locks.
4294 * The function returns 0 if successful, else returns negative error
4298 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4301 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4303 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4305 phba
->link_state
= LPFC_HBA_ERROR
;
4309 phba
->sli_rev
= sli_mode
;
4310 while (resetcount
< 2 && !done
) {
4311 spin_lock_irq(&phba
->hbalock
);
4312 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4313 spin_unlock_irq(&phba
->hbalock
);
4314 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4315 lpfc_sli_brdrestart(phba
);
4316 rc
= lpfc_sli_chipset_init(phba
);
4320 spin_lock_irq(&phba
->hbalock
);
4321 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4322 spin_unlock_irq(&phba
->hbalock
);
4325 /* Call pre CONFIG_PORT mailbox command initialization. A
4326 * value of 0 means the call was successful. Any other
4327 * nonzero value is a failure, but if ERESTART is returned,
4328 * the driver may reset the HBA and try again.
4330 rc
= lpfc_config_port_prep(phba
);
4331 if (rc
== -ERESTART
) {
4332 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4337 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4338 lpfc_config_port(phba
, pmb
);
4339 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4340 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4341 LPFC_SLI3_HBQ_ENABLED
|
4342 LPFC_SLI3_CRP_ENABLED
|
4343 LPFC_SLI3_BG_ENABLED
|
4344 LPFC_SLI3_DSS_ENABLED
);
4345 if (rc
!= MBX_SUCCESS
) {
4346 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4347 "0442 Adapter failed to init, mbxCmd x%x "
4348 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4349 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4350 spin_lock_irq(&phba
->hbalock
);
4351 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4352 spin_unlock_irq(&phba
->hbalock
);
4355 /* Allow asynchronous mailbox command to go through */
4356 spin_lock_irq(&phba
->hbalock
);
4357 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4358 spin_unlock_irq(&phba
->hbalock
);
4361 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4362 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4363 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4364 "3110 Port did not grant ASABT\n");
4369 goto do_prep_failed
;
4371 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4372 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4374 goto do_prep_failed
;
4376 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4377 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4378 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4379 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4380 phba
->max_vpi
: phba
->max_vports
;
4384 phba
->fips_level
= 0;
4385 phba
->fips_spec_rev
= 0;
4386 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4387 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4388 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4389 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4390 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4391 "2850 Security Crypto Active. FIPS x%d "
4393 phba
->fips_level
, phba
->fips_spec_rev
);
4395 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4396 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4397 "2856 Config Port Security Crypto "
4399 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4401 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4402 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4403 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4404 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4406 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4407 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4409 if (phba
->cfg_enable_bg
) {
4410 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4411 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4413 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4414 "0443 Adapter did not grant "
4418 phba
->hbq_get
= NULL
;
4419 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4423 mempool_free(pmb
, phba
->mbox_mem_pool
);
4429 * lpfc_sli_hba_setup - SLI intialization function
4430 * @phba: Pointer to HBA context object.
4432 * This function is the main SLI intialization function. This function
4433 * is called by the HBA intialization code, HBA reset code and HBA
4434 * error attention handler code. Caller is not required to hold any
4435 * locks. This function issues config_port mailbox command to configure
4436 * the SLI, setup iocb rings and HBQ rings. In the end the function
4437 * calls the config_port_post function to issue init_link mailbox
4438 * command and to start the discovery. The function will return zero
4439 * if successful, else it will return negative error code.
4442 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4448 switch (lpfc_sli_mode
) {
4450 if (phba
->cfg_enable_npiv
) {
4451 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4452 "1824 NPIV enabled: Override lpfc_sli_mode "
4453 "parameter (%d) to auto (0).\n",
4463 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4464 "1819 Unrecognized lpfc_sli_mode "
4465 "parameter: %d.\n", lpfc_sli_mode
);
4470 rc
= lpfc_sli_config_port(phba
, mode
);
4472 if (rc
&& lpfc_sli_mode
== 3)
4473 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4474 "1820 Unable to select SLI-3. "
4475 "Not supported by adapter.\n");
4476 if (rc
&& mode
!= 2)
4477 rc
= lpfc_sli_config_port(phba
, 2);
4479 goto lpfc_sli_hba_setup_error
;
4481 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4482 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4483 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4485 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4486 "2709 This device supports "
4487 "Advanced Error Reporting (AER)\n");
4488 spin_lock_irq(&phba
->hbalock
);
4489 phba
->hba_flag
|= HBA_AER_ENABLED
;
4490 spin_unlock_irq(&phba
->hbalock
);
4492 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4493 "2708 This device does not support "
4494 "Advanced Error Reporting (AER)\n");
4495 phba
->cfg_aer_support
= 0;
4499 if (phba
->sli_rev
== 3) {
4500 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4501 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4503 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4504 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4505 phba
->sli3_options
= 0;
4508 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4509 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4510 phba
->sli_rev
, phba
->max_vpi
);
4511 rc
= lpfc_sli_ring_map(phba
);
4514 goto lpfc_sli_hba_setup_error
;
4516 /* Initialize VPIs. */
4517 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4519 * The VPI bitmask and physical ID array are allocated
4520 * and initialized once only - at driver load. A port
4521 * reset doesn't need to reinitialize this memory.
4523 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4524 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4525 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4527 if (!phba
->vpi_bmask
) {
4529 goto lpfc_sli_hba_setup_error
;
4532 phba
->vpi_ids
= kzalloc(
4533 (phba
->max_vpi
+1) * sizeof(uint16_t),
4535 if (!phba
->vpi_ids
) {
4536 kfree(phba
->vpi_bmask
);
4538 goto lpfc_sli_hba_setup_error
;
4540 for (i
= 0; i
< phba
->max_vpi
; i
++)
4541 phba
->vpi_ids
[i
] = i
;
4546 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4547 rc
= lpfc_sli_hbq_setup(phba
);
4549 goto lpfc_sli_hba_setup_error
;
4551 spin_lock_irq(&phba
->hbalock
);
4552 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4553 spin_unlock_irq(&phba
->hbalock
);
4555 rc
= lpfc_config_port_post(phba
);
4557 goto lpfc_sli_hba_setup_error
;
4561 lpfc_sli_hba_setup_error
:
4562 phba
->link_state
= LPFC_HBA_ERROR
;
4563 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4564 "0445 Firmware initialization failed\n");
4569 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4570 * @phba: Pointer to HBA context object.
4571 * @mboxq: mailbox pointer.
4572 * This function issue a dump mailbox command to read config region
4573 * 23 and parse the records in the region and populate driver
4577 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4579 LPFC_MBOXQ_t
*mboxq
;
4580 struct lpfc_dmabuf
*mp
;
4581 struct lpfc_mqe
*mqe
;
4582 uint32_t data_length
;
4585 /* Program the default value of vlan_id and fc_map */
4586 phba
->valid_vlan
= 0;
4587 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4588 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4589 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4591 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4595 mqe
= &mboxq
->u
.mqe
;
4596 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4598 goto out_free_mboxq
;
4601 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4602 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4604 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4605 "(%d):2571 Mailbox cmd x%x Status x%x "
4606 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4607 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4608 "CQ: x%x x%x x%x x%x\n",
4609 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4610 bf_get(lpfc_mqe_command
, mqe
),
4611 bf_get(lpfc_mqe_status
, mqe
),
4612 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4613 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4614 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4615 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4616 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4617 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4618 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4619 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4620 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4622 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4623 mboxq
->mcqe
.trailer
);
4626 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4629 goto out_free_mboxq
;
4631 data_length
= mqe
->un
.mb_words
[5];
4632 if (data_length
> DMP_RGN23_SIZE
) {
4633 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4636 goto out_free_mboxq
;
4639 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4640 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4645 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4650 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4651 * @phba: pointer to lpfc hba data structure.
4652 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4653 * @vpd: pointer to the memory to hold resulting port vpd data.
4654 * @vpd_size: On input, the number of bytes allocated to @vpd.
4655 * On output, the number of data bytes in @vpd.
4657 * This routine executes a READ_REV SLI4 mailbox command. In
4658 * addition, this routine gets the port vpd data.
4662 * -ENOMEM - could not allocated memory.
4665 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4666 uint8_t *vpd
, uint32_t *vpd_size
)
4670 struct lpfc_dmabuf
*dmabuf
;
4671 struct lpfc_mqe
*mqe
;
4673 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4678 * Get a DMA buffer for the vpd data resulting from the READ_REV
4681 dma_size
= *vpd_size
;
4682 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4686 if (!dmabuf
->virt
) {
4690 memset(dmabuf
->virt
, 0, dma_size
);
4693 * The SLI4 implementation of READ_REV conflicts at word1,
4694 * bits 31:16 and SLI4 adds vpd functionality not present
4695 * in SLI3. This code corrects the conflicts.
4697 lpfc_read_rev(phba
, mboxq
);
4698 mqe
= &mboxq
->u
.mqe
;
4699 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4700 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4701 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4702 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4703 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4705 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4707 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4708 dmabuf
->virt
, dmabuf
->phys
);
4714 * The available vpd length cannot be bigger than the
4715 * DMA buffer passed to the port. Catch the less than
4716 * case and update the caller's size.
4718 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4719 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4721 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4723 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4724 dmabuf
->virt
, dmabuf
->phys
);
4730 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4731 * @phba: pointer to lpfc hba data structure.
4733 * This routine retrieves SLI4 device physical port name this PCI function
4738 * otherwise - failed to retrieve physical port name
4741 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4743 LPFC_MBOXQ_t
*mboxq
;
4744 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4745 struct lpfc_controller_attribute
*cntl_attr
;
4746 struct lpfc_mbx_get_port_name
*get_port_name
;
4747 void *virtaddr
= NULL
;
4748 uint32_t alloclen
, reqlen
;
4749 uint32_t shdr_status
, shdr_add_status
;
4750 union lpfc_sli4_cfg_shdr
*shdr
;
4751 char cport_name
= 0;
4754 /* We assume nothing at this point */
4755 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4756 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4758 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4761 /* obtain link type and link number via READ_CONFIG */
4762 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4763 lpfc_sli4_read_config(phba
);
4764 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4765 goto retrieve_ppname
;
4767 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4768 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4769 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4770 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4771 LPFC_SLI4_MBX_NEMBED
);
4772 if (alloclen
< reqlen
) {
4773 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4774 "3084 Allocated DMA memory size (%d) is "
4775 "less than the requested DMA memory size "
4776 "(%d)\n", alloclen
, reqlen
);
4778 goto out_free_mboxq
;
4780 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4781 virtaddr
= mboxq
->sge_array
->addr
[0];
4782 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4783 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4784 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4785 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4786 if (shdr_status
|| shdr_add_status
|| rc
) {
4787 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4788 "3085 Mailbox x%x (x%x/x%x) failed, "
4789 "rc:x%x, status:x%x, add_status:x%x\n",
4790 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4791 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4792 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4793 rc
, shdr_status
, shdr_add_status
);
4795 goto out_free_mboxq
;
4797 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4798 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4799 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4800 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4801 phba
->sli4_hba
.lnk_info
.lnk_no
=
4802 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4803 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4804 "3086 lnk_type:%d, lnk_numb:%d\n",
4805 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4806 phba
->sli4_hba
.lnk_info
.lnk_no
);
4809 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4810 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4811 sizeof(struct lpfc_mbx_get_port_name
) -
4812 sizeof(struct lpfc_sli4_cfg_mhdr
),
4813 LPFC_SLI4_MBX_EMBED
);
4814 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4815 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4816 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4817 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4818 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4819 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4820 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4821 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4822 if (shdr_status
|| shdr_add_status
|| rc
) {
4823 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4824 "3087 Mailbox x%x (x%x/x%x) failed: "
4825 "rc:x%x, status:x%x, add_status:x%x\n",
4826 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4827 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4828 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4829 rc
, shdr_status
, shdr_add_status
);
4831 goto out_free_mboxq
;
4833 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4834 case LPFC_LINK_NUMBER_0
:
4835 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4836 &get_port_name
->u
.response
);
4837 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4839 case LPFC_LINK_NUMBER_1
:
4840 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4841 &get_port_name
->u
.response
);
4842 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4844 case LPFC_LINK_NUMBER_2
:
4845 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4846 &get_port_name
->u
.response
);
4847 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4849 case LPFC_LINK_NUMBER_3
:
4850 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4851 &get_port_name
->u
.response
);
4852 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4858 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4859 phba
->Port
[0] = cport_name
;
4860 phba
->Port
[1] = '\0';
4861 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4862 "3091 SLI get port name: %s\n", phba
->Port
);
4866 if (rc
!= MBX_TIMEOUT
) {
4867 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4868 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4870 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4876 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4877 * @phba: pointer to lpfc hba data structure.
4879 * This routine is called to explicitly arm the SLI4 device's completion and
4883 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4887 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4888 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4890 if (phba
->sli4_hba
.fcp_cq
) {
4892 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4894 while (++fcp_eqidx
< phba
->cfg_fcp_eq_count
);
4896 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4897 if (phba
->sli4_hba
.fp_eq
) {
4898 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
;
4900 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4906 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4907 * @phba: Pointer to HBA context object.
4908 * @type: The resource extent type.
4909 * @extnt_count: buffer to hold port available extent count.
4910 * @extnt_size: buffer to hold element count per extent.
4912 * This function calls the port and retrievs the number of available
4913 * extents and their size for a particular extent type.
4915 * Returns: 0 if successful. Nonzero otherwise.
4918 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
4919 uint16_t *extnt_count
, uint16_t *extnt_size
)
4924 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
4927 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4931 /* Find out how many extents are available for this resource type */
4932 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
4933 sizeof(struct lpfc_sli4_cfg_mhdr
));
4934 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4935 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
4936 length
, LPFC_SLI4_MBX_EMBED
);
4938 /* Send an extents count of 0 - the GET doesn't use it. */
4939 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
4940 LPFC_SLI4_MBX_EMBED
);
4946 if (!phba
->sli4_hba
.intr_enable
)
4947 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
4949 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
4950 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
4957 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
4958 if (bf_get(lpfc_mbox_hdr_status
,
4959 &rsrc_info
->header
.cfg_shdr
.response
)) {
4960 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4961 "2930 Failed to get resource extents "
4962 "Status 0x%x Add'l Status 0x%x\n",
4963 bf_get(lpfc_mbox_hdr_status
,
4964 &rsrc_info
->header
.cfg_shdr
.response
),
4965 bf_get(lpfc_mbox_hdr_add_status
,
4966 &rsrc_info
->header
.cfg_shdr
.response
));
4971 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
4973 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
4976 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4977 "3162 Retrieved extents type-%d from port: count:%d, "
4978 "size:%d\n", type
, *extnt_count
, *extnt_size
);
4981 mempool_free(mbox
, phba
->mbox_mem_pool
);
4986 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
4987 * @phba: Pointer to HBA context object.
4988 * @type: The extent type to check.
4990 * This function reads the current available extents from the port and checks
4991 * if the extent count or extent size has changed since the last access.
4992 * Callers use this routine post port reset to understand if there is a
4993 * extent reprovisioning requirement.
4996 * -Error: error indicates problem.
4997 * 1: Extent count or size has changed.
5001 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5003 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5004 uint16_t size_diff
, rsrc_ext_size
;
5006 struct lpfc_rsrc_blks
*rsrc_entry
;
5007 struct list_head
*rsrc_blk_list
= NULL
;
5011 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5018 case LPFC_RSC_TYPE_FCOE_RPI
:
5019 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5021 case LPFC_RSC_TYPE_FCOE_VPI
:
5022 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5024 case LPFC_RSC_TYPE_FCOE_XRI
:
5025 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5027 case LPFC_RSC_TYPE_FCOE_VFI
:
5028 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5034 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5036 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5040 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5047 * lpfc_sli4_cfg_post_extnts -
5048 * @phba: Pointer to HBA context object.
5049 * @extnt_cnt - number of available extents.
5050 * @type - the extent type (rpi, xri, vfi, vpi).
5051 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5052 * @mbox - pointer to the caller's allocated mailbox structure.
5054 * This function executes the extents allocation request. It also
5055 * takes care of the amount of memory needed to allocate or get the
5056 * allocated extents. It is the caller's responsibility to evaluate
5060 * -Error: Error value describes the condition found.
5064 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5065 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5070 uint32_t alloc_len
, mbox_tmo
;
5072 /* Calculate the total requested length of the dma memory */
5073 req_len
= extnt_cnt
* sizeof(uint16_t);
5076 * Calculate the size of an embedded mailbox. The uint32_t
5077 * accounts for extents-specific word.
5079 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5083 * Presume the allocation and response will fit into an embedded
5084 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5086 *emb
= LPFC_SLI4_MBX_EMBED
;
5087 if (req_len
> emb_len
) {
5088 req_len
= extnt_cnt
* sizeof(uint16_t) +
5089 sizeof(union lpfc_sli4_cfg_shdr
) +
5091 *emb
= LPFC_SLI4_MBX_NEMBED
;
5094 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5095 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5097 if (alloc_len
< req_len
) {
5098 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5099 "2982 Allocated DMA memory size (x%x) is "
5100 "less than the requested DMA memory "
5101 "size (x%x)\n", alloc_len
, req_len
);
5104 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5108 if (!phba
->sli4_hba
.intr_enable
)
5109 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5111 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5112 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5121 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5122 * @phba: Pointer to HBA context object.
5123 * @type: The resource extent type to allocate.
5125 * This function allocates the number of elements for the specified
5129 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5132 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5133 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5136 unsigned long longs
;
5137 unsigned long *bmask
;
5138 struct lpfc_rsrc_blks
*rsrc_blks
;
5141 struct lpfc_id_range
*id_array
= NULL
;
5142 void *virtaddr
= NULL
;
5143 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5144 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5145 struct list_head
*ext_blk_list
;
5147 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5153 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5154 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5155 "3009 No available Resource Extents "
5156 "for resource type 0x%x: Count: 0x%x, "
5157 "Size 0x%x\n", type
, rsrc_cnt
,
5162 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5163 "2903 Post resource extents type-0x%x: "
5164 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5166 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5170 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5177 * Figure out where the response is located. Then get local pointers
5178 * to the response data. The port does not guarantee to respond to
5179 * all extents counts request so update the local variable with the
5180 * allocated count from the port.
5182 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5183 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5184 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5185 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5187 virtaddr
= mbox
->sge_array
->addr
[0];
5188 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5189 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5190 id_array
= &n_rsrc
->id
;
5193 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5194 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5197 * Based on the resource size and count, correct the base and max
5200 length
= sizeof(struct lpfc_rsrc_blks
);
5202 case LPFC_RSC_TYPE_FCOE_RPI
:
5203 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5204 sizeof(unsigned long),
5206 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5210 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5213 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5214 kfree(phba
->sli4_hba
.rpi_bmask
);
5220 * The next_rpi was initialized with the maximum available
5221 * count but the port may allocate a smaller number. Catch
5222 * that case and update the next_rpi.
5224 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5226 /* Initialize local ptrs for common extent processing later. */
5227 bmask
= phba
->sli4_hba
.rpi_bmask
;
5228 ids
= phba
->sli4_hba
.rpi_ids
;
5229 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5231 case LPFC_RSC_TYPE_FCOE_VPI
:
5232 phba
->vpi_bmask
= kzalloc(longs
*
5233 sizeof(unsigned long),
5235 if (unlikely(!phba
->vpi_bmask
)) {
5239 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5242 if (unlikely(!phba
->vpi_ids
)) {
5243 kfree(phba
->vpi_bmask
);
5248 /* Initialize local ptrs for common extent processing later. */
5249 bmask
= phba
->vpi_bmask
;
5250 ids
= phba
->vpi_ids
;
5251 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5253 case LPFC_RSC_TYPE_FCOE_XRI
:
5254 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5255 sizeof(unsigned long),
5257 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5261 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5262 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5265 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5266 kfree(phba
->sli4_hba
.xri_bmask
);
5271 /* Initialize local ptrs for common extent processing later. */
5272 bmask
= phba
->sli4_hba
.xri_bmask
;
5273 ids
= phba
->sli4_hba
.xri_ids
;
5274 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5276 case LPFC_RSC_TYPE_FCOE_VFI
:
5277 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5278 sizeof(unsigned long),
5280 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5284 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5287 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5288 kfree(phba
->sli4_hba
.vfi_bmask
);
5293 /* Initialize local ptrs for common extent processing later. */
5294 bmask
= phba
->sli4_hba
.vfi_bmask
;
5295 ids
= phba
->sli4_hba
.vfi_ids
;
5296 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5299 /* Unsupported Opcode. Fail call. */
5303 ext_blk_list
= NULL
;
5308 * Complete initializing the extent configuration with the
5309 * allocated ids assigned to this function. The bitmask serves
5310 * as an index into the array and manages the available ids. The
5311 * array just stores the ids communicated to the port via the wqes.
5313 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5315 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5318 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5321 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5322 if (unlikely(!rsrc_blks
)) {
5328 rsrc_blks
->rsrc_start
= rsrc_id
;
5329 rsrc_blks
->rsrc_size
= rsrc_size
;
5330 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5331 rsrc_start
= rsrc_id
;
5332 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5333 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5334 lpfc_sli4_get_els_iocb_cnt(phba
);
5336 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5341 /* Entire word processed. Get next word.*/
5346 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5351 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5352 * @phba: Pointer to HBA context object.
5353 * @type: the extent's type.
5355 * This function deallocates all extents of a particular resource type.
5356 * SLI4 does not allow for deallocating a particular extent range. It
5357 * is the caller's responsibility to release all kernel memory resources.
5360 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5363 uint32_t length
, mbox_tmo
= 0;
5365 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5366 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5368 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5373 * This function sends an embedded mailbox because it only sends the
5374 * the resource type. All extents of this type are released by the
5377 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5378 sizeof(struct lpfc_sli4_cfg_mhdr
));
5379 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5380 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5381 length
, LPFC_SLI4_MBX_EMBED
);
5383 /* Send an extents count of 0 - the dealloc doesn't use it. */
5384 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5385 LPFC_SLI4_MBX_EMBED
);
5390 if (!phba
->sli4_hba
.intr_enable
)
5391 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5393 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5394 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5401 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5402 if (bf_get(lpfc_mbox_hdr_status
,
5403 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5404 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5405 "2919 Failed to release resource extents "
5406 "for type %d - Status 0x%x Add'l Status 0x%x. "
5407 "Resource memory not released.\n",
5409 bf_get(lpfc_mbox_hdr_status
,
5410 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5411 bf_get(lpfc_mbox_hdr_add_status
,
5412 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5417 /* Release kernel memory resources for the specific type. */
5419 case LPFC_RSC_TYPE_FCOE_VPI
:
5420 kfree(phba
->vpi_bmask
);
5421 kfree(phba
->vpi_ids
);
5422 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5423 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5424 &phba
->lpfc_vpi_blk_list
, list
) {
5425 list_del_init(&rsrc_blk
->list
);
5429 case LPFC_RSC_TYPE_FCOE_XRI
:
5430 kfree(phba
->sli4_hba
.xri_bmask
);
5431 kfree(phba
->sli4_hba
.xri_ids
);
5432 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5433 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5434 list_del_init(&rsrc_blk
->list
);
5438 case LPFC_RSC_TYPE_FCOE_VFI
:
5439 kfree(phba
->sli4_hba
.vfi_bmask
);
5440 kfree(phba
->sli4_hba
.vfi_ids
);
5441 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5442 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5443 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5444 list_del_init(&rsrc_blk
->list
);
5448 case LPFC_RSC_TYPE_FCOE_RPI
:
5449 /* RPI bitmask and physical id array are cleaned up earlier. */
5450 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5451 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5452 list_del_init(&rsrc_blk
->list
);
5460 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5463 mempool_free(mbox
, phba
->mbox_mem_pool
);
5468 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5469 * @phba: Pointer to HBA context object.
5471 * This function allocates all SLI4 resource identifiers.
5474 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5476 int i
, rc
, error
= 0;
5477 uint16_t count
, base
;
5478 unsigned long longs
;
5480 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5481 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5482 if (phba
->sli4_hba
.extents_in_use
) {
5484 * The port supports resource extents. The XRI, VPI, VFI, RPI
5485 * resource extent count must be read and allocated before
5486 * provisioning the resource id arrays.
5488 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5489 LPFC_IDX_RSRC_RDY
) {
5491 * Extent-based resources are set - the driver could
5492 * be in a port reset. Figure out if any corrective
5493 * actions need to be taken.
5495 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5496 LPFC_RSC_TYPE_FCOE_VFI
);
5499 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5500 LPFC_RSC_TYPE_FCOE_VPI
);
5503 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5504 LPFC_RSC_TYPE_FCOE_XRI
);
5507 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5508 LPFC_RSC_TYPE_FCOE_RPI
);
5513 * It's possible that the number of resources
5514 * provided to this port instance changed between
5515 * resets. Detect this condition and reallocate
5516 * resources. Otherwise, there is no action.
5519 lpfc_printf_log(phba
, KERN_INFO
,
5520 LOG_MBOX
| LOG_INIT
,
5521 "2931 Detected extent resource "
5522 "change. Reallocating all "
5524 rc
= lpfc_sli4_dealloc_extent(phba
,
5525 LPFC_RSC_TYPE_FCOE_VFI
);
5526 rc
= lpfc_sli4_dealloc_extent(phba
,
5527 LPFC_RSC_TYPE_FCOE_VPI
);
5528 rc
= lpfc_sli4_dealloc_extent(phba
,
5529 LPFC_RSC_TYPE_FCOE_XRI
);
5530 rc
= lpfc_sli4_dealloc_extent(phba
,
5531 LPFC_RSC_TYPE_FCOE_RPI
);
5536 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5540 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5544 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5548 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5551 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5556 * The port does not support resource extents. The XRI, VPI,
5557 * VFI, RPI resource ids were determined from READ_CONFIG.
5558 * Just allocate the bitmasks and provision the resource id
5559 * arrays. If a port reset is active, the resources don't
5560 * need any action - just exit.
5562 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5563 LPFC_IDX_RSRC_RDY
) {
5564 lpfc_sli4_dealloc_resource_identifiers(phba
);
5565 lpfc_sli4_remove_rpis(phba
);
5568 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5569 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5570 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5571 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5572 sizeof(unsigned long),
5574 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5578 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5581 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5583 goto free_rpi_bmask
;
5586 for (i
= 0; i
< count
; i
++)
5587 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5590 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5591 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5592 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5593 phba
->vpi_bmask
= kzalloc(longs
*
5594 sizeof(unsigned long),
5596 if (unlikely(!phba
->vpi_bmask
)) {
5600 phba
->vpi_ids
= kzalloc(count
*
5603 if (unlikely(!phba
->vpi_ids
)) {
5605 goto free_vpi_bmask
;
5608 for (i
= 0; i
< count
; i
++)
5609 phba
->vpi_ids
[i
] = base
+ i
;
5612 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5613 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5614 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5615 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5616 sizeof(unsigned long),
5618 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5622 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5623 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5626 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5628 goto free_xri_bmask
;
5631 for (i
= 0; i
< count
; i
++)
5632 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5635 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5636 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5637 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5638 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5639 sizeof(unsigned long),
5641 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5645 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5648 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5650 goto free_vfi_bmask
;
5653 for (i
= 0; i
< count
; i
++)
5654 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5657 * Mark all resources ready. An HBA reset doesn't need
5658 * to reset the initialization.
5660 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5666 kfree(phba
->sli4_hba
.vfi_bmask
);
5668 kfree(phba
->sli4_hba
.xri_ids
);
5670 kfree(phba
->sli4_hba
.xri_bmask
);
5672 kfree(phba
->vpi_ids
);
5674 kfree(phba
->vpi_bmask
);
5676 kfree(phba
->sli4_hba
.rpi_ids
);
5678 kfree(phba
->sli4_hba
.rpi_bmask
);
5684 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5685 * @phba: Pointer to HBA context object.
5687 * This function allocates the number of elements for the specified
5691 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5693 if (phba
->sli4_hba
.extents_in_use
) {
5694 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5695 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5696 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5697 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5699 kfree(phba
->vpi_bmask
);
5700 kfree(phba
->vpi_ids
);
5701 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5702 kfree(phba
->sli4_hba
.xri_bmask
);
5703 kfree(phba
->sli4_hba
.xri_ids
);
5704 kfree(phba
->sli4_hba
.vfi_bmask
);
5705 kfree(phba
->sli4_hba
.vfi_ids
);
5706 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5707 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5714 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5715 * @phba: Pointer to HBA context object.
5716 * @type: The resource extent type.
5717 * @extnt_count: buffer to hold port extent count response
5718 * @extnt_size: buffer to hold port extent size response.
5720 * This function calls the port to read the host allocated extents
5721 * for a particular type.
5724 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5725 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5729 uint16_t curr_blks
= 0;
5730 uint32_t req_len
, emb_len
;
5731 uint32_t alloc_len
, mbox_tmo
;
5732 struct list_head
*blk_list_head
;
5733 struct lpfc_rsrc_blks
*rsrc_blk
;
5735 void *virtaddr
= NULL
;
5736 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5737 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5738 union lpfc_sli4_cfg_shdr
*shdr
;
5741 case LPFC_RSC_TYPE_FCOE_VPI
:
5742 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5744 case LPFC_RSC_TYPE_FCOE_XRI
:
5745 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5747 case LPFC_RSC_TYPE_FCOE_VFI
:
5748 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5750 case LPFC_RSC_TYPE_FCOE_RPI
:
5751 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5757 /* Count the number of extents currently allocatd for this type. */
5758 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5759 if (curr_blks
== 0) {
5761 * The GET_ALLOCATED mailbox does not return the size,
5762 * just the count. The size should be just the size
5763 * stored in the current allocated block and all sizes
5764 * for an extent type are the same so set the return
5767 *extnt_size
= rsrc_blk
->rsrc_size
;
5772 /* Calculate the total requested length of the dma memory. */
5773 req_len
= curr_blks
* sizeof(uint16_t);
5776 * Calculate the size of an embedded mailbox. The uint32_t
5777 * accounts for extents-specific word.
5779 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5783 * Presume the allocation and response will fit into an embedded
5784 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5786 emb
= LPFC_SLI4_MBX_EMBED
;
5788 if (req_len
> emb_len
) {
5789 req_len
= curr_blks
* sizeof(uint16_t) +
5790 sizeof(union lpfc_sli4_cfg_shdr
) +
5792 emb
= LPFC_SLI4_MBX_NEMBED
;
5795 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5798 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5800 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5801 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5803 if (alloc_len
< req_len
) {
5804 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5805 "2983 Allocated DMA memory size (x%x) is "
5806 "less than the requested DMA memory "
5807 "size (x%x)\n", alloc_len
, req_len
);
5811 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5817 if (!phba
->sli4_hba
.intr_enable
)
5818 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5820 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5821 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5830 * Figure out where the response is located. Then get local pointers
5831 * to the response data. The port does not guarantee to respond to
5832 * all extents counts request so update the local variable with the
5833 * allocated count from the port.
5835 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5836 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5837 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5838 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5840 virtaddr
= mbox
->sge_array
->addr
[0];
5841 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5842 shdr
= &n_rsrc
->cfg_shdr
;
5843 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5846 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5847 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5848 "2984 Failed to read allocated resources "
5849 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5851 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5852 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5857 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5862 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
5863 * @phba: pointer to lpfc hba data structure.
5865 * This routine walks the list of els buffers that have been allocated and
5866 * repost them to the port by using SGL block post. This is needed after a
5867 * pci_function_reset/warm_start or start. It attempts to construct blocks
5868 * of els buffer sgls which contains contiguous xris and uses the non-embedded
5869 * SGL block post mailbox commands to post them to the port. For single els
5870 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
5871 * mailbox command for posting.
5873 * Returns: 0 = success, non-zero failure.
5876 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
5878 struct lpfc_sglq
*sglq_entry
= NULL
;
5879 struct lpfc_sglq
*sglq_entry_next
= NULL
;
5880 struct lpfc_sglq
*sglq_entry_first
= NULL
;
5881 int status
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
5882 int last_xritag
= NO_XRI
;
5883 LIST_HEAD(prep_sgl_list
);
5884 LIST_HEAD(blck_sgl_list
);
5885 LIST_HEAD(allc_sgl_list
);
5886 LIST_HEAD(post_sgl_list
);
5887 LIST_HEAD(free_sgl_list
);
5889 spin_lock(&phba
->hbalock
);
5890 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
5891 spin_unlock(&phba
->hbalock
);
5893 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
5894 &allc_sgl_list
, list
) {
5895 list_del_init(&sglq_entry
->list
);
5897 if ((last_xritag
!= NO_XRI
) &&
5898 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
5899 /* a hole in xri block, form a sgl posting block */
5900 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
5901 post_cnt
= block_cnt
- 1;
5902 /* prepare list for next posting block */
5903 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
5906 /* prepare list for next posting block */
5907 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
5908 /* enough sgls for non-embed sgl mbox command */
5909 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
5910 list_splice_init(&prep_sgl_list
,
5912 post_cnt
= block_cnt
;
5918 /* keep track of last sgl's xritag */
5919 last_xritag
= sglq_entry
->sli4_xritag
;
5921 /* end of repost sgl list condition for els buffers */
5922 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
5923 if (post_cnt
== 0) {
5924 list_splice_init(&prep_sgl_list
,
5926 post_cnt
= block_cnt
;
5927 } else if (block_cnt
== 1) {
5928 status
= lpfc_sli4_post_sgl(phba
,
5929 sglq_entry
->phys
, 0,
5930 sglq_entry
->sli4_xritag
);
5932 /* successful, put sgl to posted list */
5933 list_add_tail(&sglq_entry
->list
,
5936 /* Failure, put sgl to free list */
5937 lpfc_printf_log(phba
, KERN_WARNING
,
5939 "3159 Failed to post els "
5940 "sgl, xritag:x%x\n",
5941 sglq_entry
->sli4_xritag
);
5942 list_add_tail(&sglq_entry
->list
,
5944 spin_lock_irq(&phba
->hbalock
);
5945 phba
->sli4_hba
.els_xri_cnt
--;
5946 spin_unlock_irq(&phba
->hbalock
);
5951 /* continue until a nembed page worth of sgls */
5955 /* post the els buffer list sgls as a block */
5956 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
5960 /* success, put sgl list to posted sgl list */
5961 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
5963 /* Failure, put sgl list to free sgl list */
5964 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
5967 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5968 "3160 Failed to post els sgl-list, "
5970 sglq_entry_first
->sli4_xritag
,
5971 (sglq_entry_first
->sli4_xritag
+
5973 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
5974 spin_lock_irq(&phba
->hbalock
);
5975 phba
->sli4_hba
.els_xri_cnt
-= post_cnt
;
5976 spin_unlock_irq(&phba
->hbalock
);
5979 /* don't reset xirtag due to hole in xri block */
5981 last_xritag
= NO_XRI
;
5983 /* reset els sgl post count for next round of posting */
5987 /* free the els sgls failed to post */
5988 lpfc_free_sgl_list(phba
, &free_sgl_list
);
5990 /* push els sgls posted to the availble list */
5991 if (!list_empty(&post_sgl_list
)) {
5992 spin_lock(&phba
->hbalock
);
5993 list_splice_init(&post_sgl_list
,
5994 &phba
->sli4_hba
.lpfc_sgl_list
);
5995 spin_unlock(&phba
->hbalock
);
5997 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5998 "3161 Failure to post els sgl to port.\n");
6005 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6006 * @phba: Pointer to HBA context object.
6008 * This function is the main SLI4 device intialization PCI function. This
6009 * function is called by the HBA intialization code, HBA reset code and
6010 * HBA error attention handler code. Caller is not required to hold any
6014 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6017 LPFC_MBOXQ_t
*mboxq
;
6018 struct lpfc_mqe
*mqe
;
6021 uint32_t ftr_rsp
= 0;
6022 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6023 struct lpfc_vport
*vport
= phba
->pport
;
6024 struct lpfc_dmabuf
*mp
;
6026 /* Perform a PCI function reset to start from clean */
6027 rc
= lpfc_pci_function_reset(phba
);
6031 /* Check the HBA Host Status Register for readyness */
6032 rc
= lpfc_sli4_post_status_check(phba
);
6036 spin_lock_irq(&phba
->hbalock
);
6037 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6038 spin_unlock_irq(&phba
->hbalock
);
6042 * Allocate a single mailbox container for initializing the
6045 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6049 /* Issue READ_REV to collect vpd and FW information. */
6050 vpd_size
= SLI4_PAGE_SIZE
;
6051 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6057 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6062 mqe
= &mboxq
->u
.mqe
;
6063 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6064 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
6065 phba
->hba_flag
|= HBA_FCOE_MODE
;
6067 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6069 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6071 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6073 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6075 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6077 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6078 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6079 "0376 READ_REV Error. SLI Level %d "
6080 "FCoE enabled %d\n",
6081 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6088 * Continue initialization with default values even if driver failed
6089 * to read FCoE param config regions, only read parameters if the
6092 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6093 lpfc_sli4_read_fcoe_params(phba
))
6094 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6095 "2570 Failed to read FCoE parameters\n");
6098 * Retrieve sli4 device physical port name, failure of doing it
6099 * is considered as non-fatal.
6101 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6103 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6104 "3080 Successful retrieving SLI4 device "
6105 "physical port name: %s.\n", phba
->Port
);
6108 * Evaluate the read rev and vpd data. Populate the driver
6109 * state with the results. If this routine fails, the failure
6110 * is not fatal as the driver will use generic values.
6112 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6113 if (unlikely(!rc
)) {
6114 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6115 "0377 Error %d parsing vpd. "
6116 "Using defaults.\n", rc
);
6121 /* Save information as VPD data */
6122 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6123 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6124 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6125 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6127 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6129 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6131 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6133 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6134 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6135 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6136 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6137 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6138 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6139 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6140 "(%d):0380 READ_REV Status x%x "
6141 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6142 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6143 bf_get(lpfc_mqe_status
, mqe
),
6144 phba
->vpd
.rev
.opFwName
,
6145 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6146 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6149 * Discover the port's supported feature set and match it against the
6152 lpfc_request_features(phba
, mboxq
);
6153 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6160 * The port must support FCP initiator mode as this is the
6161 * only mode running in the host.
6163 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6164 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6165 "0378 No support for fcpi mode.\n");
6168 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6169 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6171 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6173 * If the port cannot support the host's requested features
6174 * then turn off the global config parameters to disable the
6175 * feature in the driver. This is not a fatal error.
6177 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6178 if (phba
->cfg_enable_bg
) {
6179 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6180 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6185 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6186 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6190 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6191 "0379 Feature Mismatch Data: x%08x %08x "
6192 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6193 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6194 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6195 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6196 phba
->cfg_enable_bg
= 0;
6197 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6198 phba
->cfg_enable_npiv
= 0;
6201 /* These SLI3 features are assumed in SLI4 */
6202 spin_lock_irq(&phba
->hbalock
);
6203 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6204 spin_unlock_irq(&phba
->hbalock
);
6207 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6208 * calls depends on these resources to complete port setup.
6210 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6212 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6213 "2920 Failed to alloc Resource IDs "
6218 /* Read the port's service parameters. */
6219 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6221 phba
->link_state
= LPFC_HBA_ERROR
;
6226 mboxq
->vport
= vport
;
6227 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6228 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6229 if (rc
== MBX_SUCCESS
) {
6230 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6235 * This memory was allocated by the lpfc_read_sparam routine. Release
6236 * it to the mbuf pool.
6238 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6240 mboxq
->context1
= NULL
;
6242 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6243 "0382 READ_SPARAM command failed "
6244 "status %d, mbxStatus x%x\n",
6245 rc
, bf_get(lpfc_mqe_status
, mqe
));
6246 phba
->link_state
= LPFC_HBA_ERROR
;
6251 lpfc_update_vport_wwn(vport
);
6253 /* Update the fc_host data structures with new wwn. */
6254 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6255 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6257 /* update host els and scsi xri-sgl sizes and mappings */
6258 rc
= lpfc_sli4_xri_sgl_update(phba
);
6260 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6261 "1400 Failed to update xri-sgl size and "
6262 "mapping: %d\n", rc
);
6266 /* register the els sgl pool to the port */
6267 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6269 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6270 "0582 Error %d during els sgl post "
6276 /* register the allocated scsi sgl pool to the port */
6277 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6279 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6280 "0383 Error %d during scsi sgl post "
6282 /* Some Scsi buffers were moved to the abort scsi list */
6283 /* A pci function reset will repost them */
6288 /* Post the rpi header region to the device. */
6289 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6291 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6292 "0393 Error %d during rpi post operation\n",
6297 lpfc_sli4_node_prep(phba
);
6299 /* Create all the SLI4 queues */
6300 rc
= lpfc_sli4_queue_create(phba
);
6302 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6303 "3089 Failed to allocate queues\n");
6305 goto out_stop_timers
;
6307 /* Set up all the queues to the device */
6308 rc
= lpfc_sli4_queue_setup(phba
);
6310 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6311 "0381 Error %d during queue setup.\n ", rc
);
6312 goto out_destroy_queue
;
6315 /* Arm the CQs and then EQs on device */
6316 lpfc_sli4_arm_cqeq_intr(phba
);
6318 /* Indicate device interrupt mode */
6319 phba
->sli4_hba
.intr_enable
= 1;
6321 /* Allow asynchronous mailbox command to go through */
6322 spin_lock_irq(&phba
->hbalock
);
6323 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6324 spin_unlock_irq(&phba
->hbalock
);
6326 /* Post receive buffers to the device */
6327 lpfc_sli4_rb_setup(phba
);
6329 /* Reset HBA FCF states after HBA reset */
6330 phba
->fcf
.fcf_flag
= 0;
6331 phba
->fcf
.current_rec
.flag
= 0;
6333 /* Start the ELS watchdog timer */
6334 mod_timer(&vport
->els_tmofunc
,
6335 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
6337 /* Start heart beat timer */
6338 mod_timer(&phba
->hb_tmofunc
,
6339 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
6340 phba
->hb_outstanding
= 0;
6341 phba
->last_completion_time
= jiffies
;
6343 /* Start error attention (ERATT) polling timer */
6344 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
6346 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6347 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6348 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6350 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6351 "2829 This device supports "
6352 "Advanced Error Reporting (AER)\n");
6353 spin_lock_irq(&phba
->hbalock
);
6354 phba
->hba_flag
|= HBA_AER_ENABLED
;
6355 spin_unlock_irq(&phba
->hbalock
);
6357 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6358 "2830 This device does not support "
6359 "Advanced Error Reporting (AER)\n");
6360 phba
->cfg_aer_support
= 0;
6365 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6367 * The FC Port needs to register FCFI (index 0)
6369 lpfc_reg_fcfi(phba
, mboxq
);
6370 mboxq
->vport
= phba
->pport
;
6371 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6372 if (rc
!= MBX_SUCCESS
)
6373 goto out_unset_queue
;
6375 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6376 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6378 /* Check if the port is configured to be disabled */
6379 lpfc_sli_read_link_ste(phba
);
6383 * The port is ready, set the host's link state to LINK_DOWN
6384 * in preparation for link interrupts.
6386 spin_lock_irq(&phba
->hbalock
);
6387 phba
->link_state
= LPFC_LINK_DOWN
;
6388 spin_unlock_irq(&phba
->hbalock
);
6389 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6390 (phba
->hba_flag
& LINK_DISABLED
)) {
6391 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6392 "3103 Adapter Link is disabled.\n");
6393 lpfc_down_link(phba
, mboxq
);
6394 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6395 if (rc
!= MBX_SUCCESS
) {
6396 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6397 "3104 Adapter failed to issue "
6398 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6399 goto out_unset_queue
;
6401 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6402 /* don't perform init_link on SLI4 FC port loopback test */
6403 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6404 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6406 goto out_unset_queue
;
6409 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6412 /* Unset all the queues set up in this routine when error out */
6413 lpfc_sli4_queue_unset(phba
);
6415 lpfc_sli4_queue_destroy(phba
);
6417 lpfc_stop_hba_timers(phba
);
6419 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6424 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6425 * @ptr: context object - pointer to hba structure.
6427 * This is the callback function for mailbox timer. The mailbox
6428 * timer is armed when a new mailbox command is issued and the timer
6429 * is deleted when the mailbox complete. The function is called by
6430 * the kernel timer code when a mailbox does not complete within
6431 * expected time. This function wakes up the worker thread to
6432 * process the mailbox timeout and returns. All the processing is
6433 * done by the worker thread function lpfc_mbox_timeout_handler.
6436 lpfc_mbox_timeout(unsigned long ptr
)
6438 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6439 unsigned long iflag
;
6440 uint32_t tmo_posted
;
6442 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6443 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6445 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6446 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6449 lpfc_worker_wake_up(phba
);
6455 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6456 * @phba: Pointer to HBA context object.
6458 * This function is called from worker thread when a mailbox command times out.
6459 * The caller is not required to hold any locks. This function will reset the
6460 * HBA and recover all the pending commands.
6463 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6465 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6466 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6467 struct lpfc_sli
*psli
= &phba
->sli
;
6468 struct lpfc_sli_ring
*pring
;
6470 /* Check the pmbox pointer first. There is a race condition
6471 * between the mbox timeout handler getting executed in the
6472 * worklist and the mailbox actually completing. When this
6473 * race condition occurs, the mbox_active will be NULL.
6475 spin_lock_irq(&phba
->hbalock
);
6476 if (pmbox
== NULL
) {
6477 lpfc_printf_log(phba
, KERN_WARNING
,
6479 "0353 Active Mailbox cleared - mailbox timeout "
6481 spin_unlock_irq(&phba
->hbalock
);
6485 /* Mbox cmd <mbxCommand> timeout */
6486 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6487 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6489 phba
->pport
->port_state
,
6491 phba
->sli
.mbox_active
);
6492 spin_unlock_irq(&phba
->hbalock
);
6494 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6495 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6496 * it to fail all outstanding SCSI IO.
6498 spin_lock_irq(&phba
->pport
->work_port_lock
);
6499 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6500 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6501 spin_lock_irq(&phba
->hbalock
);
6502 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6503 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6504 spin_unlock_irq(&phba
->hbalock
);
6506 pring
= &psli
->ring
[psli
->fcp_ring
];
6507 lpfc_sli_abort_iocb_ring(phba
, pring
);
6509 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6510 "0345 Resetting board due to mailbox timeout\n");
6512 /* Reset the HBA device */
6513 lpfc_reset_hba(phba
);
6517 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6518 * @phba: Pointer to HBA context object.
6519 * @pmbox: Pointer to mailbox object.
6520 * @flag: Flag indicating how the mailbox need to be processed.
6522 * This function is called by discovery code and HBA management code
6523 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6524 * function gets the hbalock to protect the data structures.
6525 * The mailbox command can be submitted in polling mode, in which case
6526 * this function will wait in a polling loop for the completion of the
6528 * If the mailbox is submitted in no_wait mode (not polling) the
6529 * function will submit the command and returns immediately without waiting
6530 * for the mailbox completion. The no_wait is supported only when HBA
6531 * is in SLI2/SLI3 mode - interrupts are enabled.
6532 * The SLI interface allows only one mailbox pending at a time. If the
6533 * mailbox is issued in polling mode and there is already a mailbox
6534 * pending, then the function will return an error. If the mailbox is issued
6535 * in NO_WAIT mode and there is a mailbox pending already, the function
6536 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6537 * The sli layer owns the mailbox object until the completion of mailbox
6538 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6539 * return codes the caller owns the mailbox command after the return of
6543 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6547 struct lpfc_sli
*psli
= &phba
->sli
;
6548 uint32_t status
, evtctr
;
6549 uint32_t ha_copy
, hc_copy
;
6551 unsigned long timeout
;
6552 unsigned long drvr_flag
= 0;
6553 uint32_t word0
, ldata
;
6554 void __iomem
*to_slim
;
6555 int processing_queue
= 0;
6557 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6559 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6560 /* processing mbox queue from intr_handler */
6561 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6562 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6565 processing_queue
= 1;
6566 pmbox
= lpfc_mbox_get(phba
);
6568 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6573 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6574 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6576 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6577 lpfc_printf_log(phba
, KERN_ERR
,
6578 LOG_MBOX
| LOG_VPORT
,
6579 "1806 Mbox x%x failed. No vport\n",
6580 pmbox
->u
.mb
.mbxCommand
);
6582 goto out_not_finished
;
6586 /* If the PCI channel is in offline state, do not post mbox. */
6587 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6588 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6589 goto out_not_finished
;
6592 /* If HBA has a deferred error attention, fail the iocb. */
6593 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6594 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6595 goto out_not_finished
;
6601 status
= MBX_SUCCESS
;
6603 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6604 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6606 /* Mbox command <mbxCommand> cannot issue */
6607 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6608 "(%d):0311 Mailbox command x%x cannot "
6609 "issue Data: x%x x%x\n",
6610 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6611 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6612 goto out_not_finished
;
6615 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6616 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6617 !(hc_copy
& HC_MBINT_ENA
)) {
6618 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6619 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6620 "(%d):2528 Mailbox command x%x cannot "
6621 "issue Data: x%x x%x\n",
6622 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6623 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6624 goto out_not_finished
;
6628 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6629 /* Polling for a mbox command when another one is already active
6630 * is not allowed in SLI. Also, the driver must have established
6631 * SLI2 mode to queue and process multiple mbox commands.
6634 if (flag
& MBX_POLL
) {
6635 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6637 /* Mbox command <mbxCommand> cannot issue */
6638 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6639 "(%d):2529 Mailbox command x%x "
6640 "cannot issue Data: x%x x%x\n",
6641 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6642 pmbox
->u
.mb
.mbxCommand
,
6643 psli
->sli_flag
, flag
);
6644 goto out_not_finished
;
6647 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6648 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6649 /* Mbox command <mbxCommand> cannot issue */
6650 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6651 "(%d):2530 Mailbox command x%x "
6652 "cannot issue Data: x%x x%x\n",
6653 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6654 pmbox
->u
.mb
.mbxCommand
,
6655 psli
->sli_flag
, flag
);
6656 goto out_not_finished
;
6659 /* Another mailbox command is still being processed, queue this
6660 * command to be processed later.
6662 lpfc_mbox_put(phba
, pmbox
);
6664 /* Mbox cmd issue - BUSY */
6665 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6666 "(%d):0308 Mbox cmd issue - BUSY Data: "
6667 "x%x x%x x%x x%x\n",
6668 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6669 mb
->mbxCommand
, phba
->pport
->port_state
,
6670 psli
->sli_flag
, flag
);
6672 psli
->slistat
.mbox_busy
++;
6673 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6676 lpfc_debugfs_disc_trc(pmbox
->vport
,
6677 LPFC_DISC_TRC_MBOX_VPORT
,
6678 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6679 (uint32_t)mb
->mbxCommand
,
6680 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6683 lpfc_debugfs_disc_trc(phba
->pport
,
6685 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6686 (uint32_t)mb
->mbxCommand
,
6687 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6693 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6695 /* If we are not polling, we MUST be in SLI2 mode */
6696 if (flag
!= MBX_POLL
) {
6697 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6698 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
6699 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6700 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6701 /* Mbox command <mbxCommand> cannot issue */
6702 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6703 "(%d):2531 Mailbox command x%x "
6704 "cannot issue Data: x%x x%x\n",
6705 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6706 pmbox
->u
.mb
.mbxCommand
,
6707 psli
->sli_flag
, flag
);
6708 goto out_not_finished
;
6710 /* timeout active mbox command */
6711 mod_timer(&psli
->mbox_tmo
, (jiffies
+
6712 (HZ
* lpfc_mbox_tmo_val(phba
, pmbox
))));
6715 /* Mailbox cmd <cmd> issue */
6716 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6717 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6719 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6720 mb
->mbxCommand
, phba
->pport
->port_state
,
6721 psli
->sli_flag
, flag
);
6723 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
6725 lpfc_debugfs_disc_trc(pmbox
->vport
,
6726 LPFC_DISC_TRC_MBOX_VPORT
,
6727 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6728 (uint32_t)mb
->mbxCommand
,
6729 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6732 lpfc_debugfs_disc_trc(phba
->pport
,
6734 "MBOX Send: cmd:x%x mb:x%x x%x",
6735 (uint32_t)mb
->mbxCommand
,
6736 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6740 psli
->slistat
.mbox_cmd
++;
6741 evtctr
= psli
->slistat
.mbox_event
;
6743 /* next set own bit for the adapter and copy over command word */
6744 mb
->mbxOwner
= OWN_CHIP
;
6746 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6747 /* Populate mbox extension offset word. */
6748 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6749 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6750 = (uint8_t *)phba
->mbox_ext
6751 - (uint8_t *)phba
->mbox
;
6754 /* Copy the mailbox extension data */
6755 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6756 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6757 (uint8_t *)phba
->mbox_ext
,
6758 pmbox
->in_ext_byte_len
);
6760 /* Copy command data to host SLIM area */
6761 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6763 /* Populate mbox extension offset word. */
6764 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6765 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6766 = MAILBOX_HBA_EXT_OFFSET
;
6768 /* Copy the mailbox extension data */
6769 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6770 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
6771 MAILBOX_HBA_EXT_OFFSET
,
6772 pmbox
->context2
, pmbox
->in_ext_byte_len
);
6775 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6776 /* copy command data into host mbox for cmpl */
6777 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6780 /* First copy mbox command data to HBA SLIM, skip past first
6782 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
6783 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
6784 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
6786 /* Next copy over first word, with mbxOwner set */
6787 ldata
= *((uint32_t *)mb
);
6788 to_slim
= phba
->MBslimaddr
;
6789 writel(ldata
, to_slim
);
6790 readl(to_slim
); /* flush */
6792 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6793 /* switch over to host mailbox */
6794 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
6802 /* Set up reference to mailbox command */
6803 psli
->mbox_active
= pmbox
;
6804 /* Interrupt board to do it */
6805 writel(CA_MBATT
, phba
->CAregaddr
);
6806 readl(phba
->CAregaddr
); /* flush */
6807 /* Don't wait for it to finish, just return */
6811 /* Set up null reference to mailbox command */
6812 psli
->mbox_active
= NULL
;
6813 /* Interrupt board to do it */
6814 writel(CA_MBATT
, phba
->CAregaddr
);
6815 readl(phba
->CAregaddr
); /* flush */
6817 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6818 /* First read mbox status word */
6819 word0
= *((uint32_t *)phba
->mbox
);
6820 word0
= le32_to_cpu(word0
);
6822 /* First read mbox status word */
6823 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
6824 spin_unlock_irqrestore(&phba
->hbalock
,
6826 goto out_not_finished
;
6830 /* Read the HBA Host Attention Register */
6831 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6832 spin_unlock_irqrestore(&phba
->hbalock
,
6834 goto out_not_finished
;
6836 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6839 /* Wait for command to complete */
6840 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
6841 (!(ha_copy
& HA_MBATT
) &&
6842 (phba
->link_state
> LPFC_WARM_START
))) {
6843 if (time_after(jiffies
, timeout
)) {
6844 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6845 spin_unlock_irqrestore(&phba
->hbalock
,
6847 goto out_not_finished
;
6850 /* Check if we took a mbox interrupt while we were
6852 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
6853 && (evtctr
!= psli
->slistat
.mbox_event
))
6857 spin_unlock_irqrestore(&phba
->hbalock
,
6860 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6863 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6864 /* First copy command data */
6865 word0
= *((uint32_t *)phba
->mbox
);
6866 word0
= le32_to_cpu(word0
);
6867 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6870 /* Check real SLIM for any errors */
6871 slimword0
= readl(phba
->MBslimaddr
);
6872 slimmb
= (MAILBOX_t
*) & slimword0
;
6873 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
6874 && slimmb
->mbxStatus
) {
6881 /* First copy command data */
6882 word0
= readl(phba
->MBslimaddr
);
6884 /* Read the HBA Host Attention Register */
6885 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6886 spin_unlock_irqrestore(&phba
->hbalock
,
6888 goto out_not_finished
;
6892 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6893 /* copy results back to user */
6894 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
6895 /* Copy the mailbox extension data */
6896 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6897 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
6899 pmbox
->out_ext_byte_len
);
6902 /* First copy command data */
6903 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
6905 /* Copy the mailbox extension data */
6906 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6907 lpfc_memcpy_from_slim(pmbox
->context2
,
6909 MAILBOX_HBA_EXT_OFFSET
,
6910 pmbox
->out_ext_byte_len
);
6914 writel(HA_MBATT
, phba
->HAregaddr
);
6915 readl(phba
->HAregaddr
); /* flush */
6917 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6918 status
= mb
->mbxStatus
;
6921 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6925 if (processing_queue
) {
6926 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6927 lpfc_mbox_cmpl_put(phba
, pmbox
);
6929 return MBX_NOT_FINISHED
;
6933 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6934 * @phba: Pointer to HBA context object.
6936 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6937 * the driver internal pending mailbox queue. It will then try to wait out the
6938 * possible outstanding mailbox command before return.
6941 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6942 * the outstanding mailbox command timed out.
6945 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
6947 struct lpfc_sli
*psli
= &phba
->sli
;
6949 unsigned long timeout
= 0;
6951 /* Mark the asynchronous mailbox command posting as blocked */
6952 spin_lock_irq(&phba
->hbalock
);
6953 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
6954 /* Determine how long we might wait for the active mailbox
6955 * command to be gracefully completed by firmware.
6957 if (phba
->sli
.mbox_active
)
6958 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
6959 phba
->sli
.mbox_active
) *
6961 spin_unlock_irq(&phba
->hbalock
);
6963 /* Wait for the outstnading mailbox command to complete */
6964 while (phba
->sli
.mbox_active
) {
6965 /* Check active mailbox complete status every 2ms */
6967 if (time_after(jiffies
, timeout
)) {
6968 /* Timeout, marked the outstanding cmd not complete */
6974 /* Can not cleanly block async mailbox command, fails it */
6976 spin_lock_irq(&phba
->hbalock
);
6977 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6978 spin_unlock_irq(&phba
->hbalock
);
6984 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
6985 * @phba: Pointer to HBA context object.
6987 * The function unblocks and resume posting of SLI4 asynchronous mailbox
6988 * commands from the driver internal pending mailbox queue. It makes sure
6989 * that there is no outstanding mailbox command before resuming posting
6990 * asynchronous mailbox commands. If, for any reason, there is outstanding
6991 * mailbox command, it will try to wait it out before resuming asynchronous
6992 * mailbox command posting.
6995 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
6997 struct lpfc_sli
*psli
= &phba
->sli
;
6999 spin_lock_irq(&phba
->hbalock
);
7000 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7001 /* Asynchronous mailbox posting is not blocked, do nothing */
7002 spin_unlock_irq(&phba
->hbalock
);
7006 /* Outstanding synchronous mailbox command is guaranteed to be done,
7007 * successful or timeout, after timing-out the outstanding mailbox
7008 * command shall always be removed, so just unblock posting async
7009 * mailbox command and resume
7011 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7012 spin_unlock_irq(&phba
->hbalock
);
7014 /* wake up worker thread to post asynchronlous mailbox command */
7015 lpfc_worker_wake_up(phba
);
7019 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7020 * @phba: Pointer to HBA context object.
7021 * @mboxq: Pointer to mailbox object.
7023 * The function posts a mailbox to the port. The mailbox is expected
7024 * to be comletely filled in and ready for the port to operate on it.
7025 * This routine executes a synchronous completion operation on the
7026 * mailbox by polling for its completion.
7028 * The caller must not be holding any locks when calling this routine.
7031 * MBX_SUCCESS - mailbox posted successfully
7032 * Any of the MBX error values.
7035 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7037 int rc
= MBX_SUCCESS
;
7038 unsigned long iflag
;
7040 uint32_t mcqe_status
;
7042 unsigned long timeout
;
7043 struct lpfc_sli
*psli
= &phba
->sli
;
7044 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7045 struct lpfc_bmbx_create
*mbox_rgn
;
7046 struct dma_address
*dma_address
;
7047 struct lpfc_register bmbx_reg
;
7050 * Only one mailbox can be active to the bootstrap mailbox region
7051 * at a time and there is no queueing provided.
7053 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7054 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7055 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7056 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7057 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7058 "cannot issue Data: x%x x%x\n",
7059 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7060 mboxq
->u
.mb
.mbxCommand
,
7061 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7062 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7063 psli
->sli_flag
, MBX_POLL
);
7064 return MBXERR_ERROR
;
7066 /* The server grabs the token and owns it until release */
7067 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7068 phba
->sli
.mbox_active
= mboxq
;
7069 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7072 * Initialize the bootstrap memory region to avoid stale data areas
7073 * in the mailbox post. Then copy the caller's mailbox contents to
7074 * the bmbx mailbox region.
7076 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7077 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7078 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7079 sizeof(struct lpfc_mqe
));
7081 /* Post the high mailbox dma address to the port and wait for ready. */
7082 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7083 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7085 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7088 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7089 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7093 if (time_after(jiffies
, timeout
)) {
7097 } while (!db_ready
);
7099 /* Post the low mailbox dma address to the port. */
7100 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7101 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7104 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7105 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7109 if (time_after(jiffies
, timeout
)) {
7113 } while (!db_ready
);
7116 * Read the CQ to ensure the mailbox has completed.
7117 * If so, update the mailbox status so that the upper layers
7118 * can complete the request normally.
7120 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7121 sizeof(struct lpfc_mqe
));
7122 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7123 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7124 sizeof(struct lpfc_mcqe
));
7125 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7127 * When the CQE status indicates a failure and the mailbox status
7128 * indicates success then copy the CQE status into the mailbox status
7129 * (and prefix it with x4000).
7131 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7132 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7133 bf_set(lpfc_mqe_status
, mb
,
7134 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7137 lpfc_sli4_swap_str(phba
, mboxq
);
7139 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7140 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7141 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7142 " x%x x%x CQ: x%x x%x x%x x%x\n",
7143 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7144 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7145 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7146 bf_get(lpfc_mqe_status
, mb
),
7147 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7148 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7149 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7150 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7151 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7152 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7153 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7154 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7155 mboxq
->mcqe
.trailer
);
7157 /* We are holding the token, no needed for lock when release */
7158 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7159 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7160 phba
->sli
.mbox_active
= NULL
;
7161 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7166 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7167 * @phba: Pointer to HBA context object.
7168 * @pmbox: Pointer to mailbox object.
7169 * @flag: Flag indicating how the mailbox need to be processed.
7171 * This function is called by discovery code and HBA management code to submit
7172 * a mailbox command to firmware with SLI-4 interface spec.
7174 * Return codes the caller owns the mailbox command after the return of the
7178 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7181 struct lpfc_sli
*psli
= &phba
->sli
;
7182 unsigned long iflags
;
7185 /* dump from issue mailbox command if setup */
7186 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7188 rc
= lpfc_mbox_dev_check(phba
);
7190 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7191 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7192 "cannot issue Data: x%x x%x\n",
7193 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7194 mboxq
->u
.mb
.mbxCommand
,
7195 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7196 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7197 psli
->sli_flag
, flag
);
7198 goto out_not_finished
;
7201 /* Detect polling mode and jump to a handler */
7202 if (!phba
->sli4_hba
.intr_enable
) {
7203 if (flag
== MBX_POLL
)
7204 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7207 if (rc
!= MBX_SUCCESS
)
7208 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7209 "(%d):2541 Mailbox command x%x "
7210 "(x%x/x%x) cannot issue Data: "
7212 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7213 mboxq
->u
.mb
.mbxCommand
,
7214 lpfc_sli_config_mbox_subsys_get(phba
,
7216 lpfc_sli_config_mbox_opcode_get(phba
,
7218 psli
->sli_flag
, flag
);
7220 } else if (flag
== MBX_POLL
) {
7221 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7222 "(%d):2542 Try to issue mailbox command "
7223 "x%x (x%x/x%x) synchronously ahead of async"
7224 "mailbox command queue: 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 /* Try to block the asynchronous mailbox posting */
7231 rc
= lpfc_sli4_async_mbox_block(phba
);
7233 /* Successfully blocked, now issue sync mbox cmd */
7234 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7235 if (rc
!= MBX_SUCCESS
)
7236 lpfc_printf_log(phba
, KERN_ERR
,
7238 "(%d):2597 Mailbox command "
7239 "x%x (x%x/x%x) cannot issue "
7242 mboxq
->vport
->vpi
: 0,
7243 mboxq
->u
.mb
.mbxCommand
,
7244 lpfc_sli_config_mbox_subsys_get(phba
,
7246 lpfc_sli_config_mbox_opcode_get(phba
,
7248 psli
->sli_flag
, flag
);
7249 /* Unblock the async mailbox posting afterward */
7250 lpfc_sli4_async_mbox_unblock(phba
);
7255 /* Now, interrupt mode asynchrous mailbox command */
7256 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7258 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7259 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7260 "cannot issue Data: x%x x%x\n",
7261 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7262 mboxq
->u
.mb
.mbxCommand
,
7263 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7264 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7265 psli
->sli_flag
, flag
);
7266 goto out_not_finished
;
7269 /* Put the mailbox command to the driver internal FIFO */
7270 psli
->slistat
.mbox_busy
++;
7271 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7272 lpfc_mbox_put(phba
, mboxq
);
7273 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7274 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7275 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7276 "x%x (x%x/x%x) x%x x%x x%x\n",
7277 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7278 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7279 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7280 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7281 phba
->pport
->port_state
,
7282 psli
->sli_flag
, MBX_NOWAIT
);
7283 /* Wake up worker thread to transport mailbox command from head */
7284 lpfc_worker_wake_up(phba
);
7289 return MBX_NOT_FINISHED
;
7293 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7294 * @phba: Pointer to HBA context object.
7296 * This function is called by worker thread to send a mailbox command to
7297 * SLI4 HBA firmware.
7301 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7303 struct lpfc_sli
*psli
= &phba
->sli
;
7304 LPFC_MBOXQ_t
*mboxq
;
7305 int rc
= MBX_SUCCESS
;
7306 unsigned long iflags
;
7307 struct lpfc_mqe
*mqe
;
7310 /* Check interrupt mode before post async mailbox command */
7311 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7312 return MBX_NOT_FINISHED
;
7314 /* Check for mailbox command service token */
7315 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7316 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7317 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7318 return MBX_NOT_FINISHED
;
7320 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7321 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7322 return MBX_NOT_FINISHED
;
7324 if (unlikely(phba
->sli
.mbox_active
)) {
7325 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7326 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7327 "0384 There is pending active mailbox cmd\n");
7328 return MBX_NOT_FINISHED
;
7330 /* Take the mailbox command service token */
7331 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7333 /* Get the next mailbox command from head of queue */
7334 mboxq
= lpfc_mbox_get(phba
);
7336 /* If no more mailbox command waiting for post, we're done */
7338 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7339 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7342 phba
->sli
.mbox_active
= mboxq
;
7343 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7345 /* Check device readiness for posting mailbox command */
7346 rc
= lpfc_mbox_dev_check(phba
);
7348 /* Driver clean routine will clean up pending mailbox */
7349 goto out_not_finished
;
7351 /* Prepare the mbox command to be posted */
7352 mqe
= &mboxq
->u
.mqe
;
7353 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7355 /* Start timer for the mbox_tmo and log some mailbox post messages */
7356 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7357 (HZ
* lpfc_mbox_tmo_val(phba
, mboxq
))));
7359 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7360 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7362 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7363 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7364 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7365 phba
->pport
->port_state
, psli
->sli_flag
);
7367 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7369 lpfc_debugfs_disc_trc(mboxq
->vport
,
7370 LPFC_DISC_TRC_MBOX_VPORT
,
7371 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7372 mbx_cmnd
, mqe
->un
.mb_words
[0],
7373 mqe
->un
.mb_words
[1]);
7375 lpfc_debugfs_disc_trc(phba
->pport
,
7377 "MBOX Send: cmd:x%x mb:x%x x%x",
7378 mbx_cmnd
, mqe
->un
.mb_words
[0],
7379 mqe
->un
.mb_words
[1]);
7382 psli
->slistat
.mbox_cmd
++;
7384 /* Post the mailbox command to the port */
7385 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7386 if (rc
!= MBX_SUCCESS
) {
7387 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7388 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7389 "cannot issue Data: x%x x%x\n",
7390 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7391 mboxq
->u
.mb
.mbxCommand
,
7392 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7393 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7394 psli
->sli_flag
, MBX_NOWAIT
);
7395 goto out_not_finished
;
7401 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7402 if (phba
->sli
.mbox_active
) {
7403 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7404 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7405 /* Release the token */
7406 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7407 phba
->sli
.mbox_active
= NULL
;
7409 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7411 return MBX_NOT_FINISHED
;
7415 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7416 * @phba: Pointer to HBA context object.
7417 * @pmbox: Pointer to mailbox object.
7418 * @flag: Flag indicating how the mailbox need to be processed.
7420 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7421 * the API jump table function pointer from the lpfc_hba struct.
7423 * Return codes the caller owns the mailbox command after the return of the
7427 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7429 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7433 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7434 * @phba: The hba struct for which this call is being executed.
7435 * @dev_grp: The HBA PCI-Device group number.
7437 * This routine sets up the mbox interface API function jump table in @phba
7439 * Returns: 0 - success, -ENODEV - failure.
7442 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7446 case LPFC_PCI_DEV_LP
:
7447 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7448 phba
->lpfc_sli_handle_slow_ring_event
=
7449 lpfc_sli_handle_slow_ring_event_s3
;
7450 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7451 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7452 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7454 case LPFC_PCI_DEV_OC
:
7455 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7456 phba
->lpfc_sli_handle_slow_ring_event
=
7457 lpfc_sli_handle_slow_ring_event_s4
;
7458 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7459 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7460 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7463 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7464 "1420 Invalid HBA PCI-device group: 0x%x\n",
7473 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7474 * @phba: Pointer to HBA context object.
7475 * @pring: Pointer to driver SLI ring object.
7476 * @piocb: Pointer to address of newly added command iocb.
7478 * This function is called with hbalock held to add a command
7479 * iocb to the txq when SLI layer cannot submit the command iocb
7483 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7484 struct lpfc_iocbq
*piocb
)
7486 /* Insert the caller's iocb in the txq tail for later processing. */
7487 list_add_tail(&piocb
->list
, &pring
->txq
);
7492 * lpfc_sli_next_iocb - Get the next iocb in the txq
7493 * @phba: Pointer to HBA context object.
7494 * @pring: Pointer to driver SLI ring object.
7495 * @piocb: Pointer to address of newly added command iocb.
7497 * This function is called with hbalock held before a new
7498 * iocb is submitted to the firmware. This function checks
7499 * txq to flush the iocbs in txq to Firmware before
7500 * submitting new iocbs to the Firmware.
7501 * If there are iocbs in the txq which need to be submitted
7502 * to firmware, lpfc_sli_next_iocb returns the first element
7503 * of the txq after dequeuing it from txq.
7504 * If there is no iocb in the txq then the function will return
7505 * *piocb and *piocb is set to NULL. Caller needs to check
7506 * *piocb to find if there are more commands in the txq.
7508 static struct lpfc_iocbq
*
7509 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7510 struct lpfc_iocbq
**piocb
)
7512 struct lpfc_iocbq
* nextiocb
;
7514 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7524 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7525 * @phba: Pointer to HBA context object.
7526 * @ring_number: SLI ring number to issue iocb on.
7527 * @piocb: Pointer to command iocb.
7528 * @flag: Flag indicating if this command can be put into txq.
7530 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7531 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7532 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7533 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7534 * this function allows only iocbs for posting buffers. This function finds
7535 * next available slot in the command ring and posts the command to the
7536 * available slot and writes the port attention register to request HBA start
7537 * processing new iocb. If there is no slot available in the ring and
7538 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7539 * the function returns IOCB_BUSY.
7541 * This function is called with hbalock held. The function will return success
7542 * after it successfully submit the iocb to firmware or after adding to the
7546 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7547 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7549 struct lpfc_iocbq
*nextiocb
;
7551 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7553 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7554 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7555 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7556 lpfc_printf_log(phba
, KERN_ERR
,
7557 LOG_SLI
| LOG_VPORT
,
7558 "1807 IOCB x%x failed. No vport\n",
7559 piocb
->iocb
.ulpCommand
);
7565 /* If the PCI channel is in offline state, do not post iocbs. */
7566 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7569 /* If HBA has a deferred error attention, fail the iocb. */
7570 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7574 * We should never get an IOCB if we are in a < LINK_DOWN state
7576 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7580 * Check to see if we are blocking IOCB processing because of a
7581 * outstanding event.
7583 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7586 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7588 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7589 * can be issued if the link is not up.
7591 switch (piocb
->iocb
.ulpCommand
) {
7592 case CMD_GEN_REQUEST64_CR
:
7593 case CMD_GEN_REQUEST64_CX
:
7594 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7595 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7596 FC_RCTL_DD_UNSOL_CMD
) ||
7597 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7598 MENLO_TRANSPORT_TYPE
))
7602 case CMD_QUE_RING_BUF_CN
:
7603 case CMD_QUE_RING_BUF64_CN
:
7605 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7606 * completion, iocb_cmpl MUST be 0.
7608 if (piocb
->iocb_cmpl
)
7609 piocb
->iocb_cmpl
= NULL
;
7611 case CMD_CREATE_XRI_CR
:
7612 case CMD_CLOSE_XRI_CN
:
7613 case CMD_CLOSE_XRI_CX
:
7620 * For FCP commands, we must be in a state where we can process link
7623 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7624 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7628 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7629 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7630 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7633 lpfc_sli_update_ring(phba
, pring
);
7635 lpfc_sli_update_full_ring(phba
, pring
);
7638 return IOCB_SUCCESS
;
7643 pring
->stats
.iocb_cmd_delay
++;
7647 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7648 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7649 return IOCB_SUCCESS
;
7656 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7657 * @phba: Pointer to HBA context object.
7658 * @piocb: Pointer to command iocb.
7659 * @sglq: Pointer to the scatter gather queue object.
7661 * This routine converts the bpl or bde that is in the IOCB
7662 * to a sgl list for the sli4 hardware. The physical address
7663 * of the bpl/bde is converted back to a virtual address.
7664 * If the IOCB contains a BPL then the list of BDE's is
7665 * converted to sli4_sge's. If the IOCB contains a single
7666 * BDE then it is converted to a single sli_sge.
7667 * The IOCB is still in cpu endianess so the contents of
7668 * the bpl can be used without byte swapping.
7670 * Returns valid XRI = Success, NO_XRI = Failure.
7673 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7674 struct lpfc_sglq
*sglq
)
7676 uint16_t xritag
= NO_XRI
;
7677 struct ulp_bde64
*bpl
= NULL
;
7678 struct ulp_bde64 bde
;
7679 struct sli4_sge
*sgl
= NULL
;
7680 struct lpfc_dmabuf
*dmabuf
;
7684 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7685 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7687 if (!piocbq
|| !sglq
)
7690 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7691 icmd
= &piocbq
->iocb
;
7692 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
7693 return sglq
->sli4_xritag
;
7694 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7695 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7696 sizeof(struct ulp_bde64
);
7697 /* The addrHigh and addrLow fields within the IOCB
7698 * have not been byteswapped yet so there is no
7699 * need to swap them back.
7701 if (piocbq
->context3
)
7702 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7706 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7710 for (i
= 0; i
< numBdes
; i
++) {
7711 /* Should already be byte swapped. */
7712 sgl
->addr_hi
= bpl
->addrHigh
;
7713 sgl
->addr_lo
= bpl
->addrLow
;
7715 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7716 if ((i
+1) == numBdes
)
7717 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7719 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7720 /* swap the size field back to the cpu so we
7721 * can assign it to the sgl.
7723 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7724 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7725 /* The offsets in the sgl need to be accumulated
7726 * separately for the request and reply lists.
7727 * The request is always first, the reply follows.
7729 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7730 /* add up the reply sg entries */
7731 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7733 /* first inbound? reset the offset */
7736 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7737 bf_set(lpfc_sli4_sge_type
, sgl
,
7738 LPFC_SGE_TYPE_DATA
);
7739 offset
+= bde
.tus
.f
.bdeSize
;
7741 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7745 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
7746 /* The addrHigh and addrLow fields of the BDE have not
7747 * been byteswapped yet so they need to be swapped
7748 * before putting them in the sgl.
7751 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
7753 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
7754 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7755 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7756 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7758 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
7760 return sglq
->sli4_xritag
;
7764 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7765 * @phba: Pointer to HBA context object.
7767 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7768 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7771 * Return: index into SLI4 fast-path FCP queue index.
7774 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
7777 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
7780 return phba
->fcp_qidx
;
7784 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7785 * @phba: Pointer to HBA context object.
7786 * @piocb: Pointer to command iocb.
7787 * @wqe: Pointer to the work queue entry.
7789 * This routine converts the iocb command to its Work Queue Entry
7790 * equivalent. The wqe pointer should not have any fields set when
7791 * this routine is called because it will memcpy over them.
7792 * This routine does not set the CQ_ID or the WQEC bits in the
7795 * Returns: 0 = Success, IOCB_ERROR = Failure.
7798 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
7799 union lpfc_wqe
*wqe
)
7801 uint32_t xmit_len
= 0, total_len
= 0;
7805 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
7808 uint16_t abrt_iotag
;
7809 struct lpfc_iocbq
*abrtiocbq
;
7810 struct ulp_bde64
*bpl
= NULL
;
7811 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
7813 struct ulp_bde64 bde
;
7814 struct lpfc_nodelist
*ndlp
;
7818 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
7819 /* The fcp commands will set command type */
7820 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7821 command_type
= FCP_COMMAND
;
7822 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
7823 command_type
= ELS_COMMAND_FIP
;
7825 command_type
= ELS_COMMAND_NON_FIP
;
7827 /* Some of the fields are in the right position already */
7828 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
7829 abort_tag
= (uint32_t) iocbq
->iotag
;
7830 xritag
= iocbq
->sli4_xritag
;
7831 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
7832 /* words0-2 bpl convert bde */
7833 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7834 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7835 sizeof(struct ulp_bde64
);
7836 bpl
= (struct ulp_bde64
*)
7837 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
7841 /* Should already be byte swapped. */
7842 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
7843 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
7844 /* swap the size field back to the cpu so we
7845 * can assign it to the sgl.
7847 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7848 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
7850 for (i
= 0; i
< numBdes
; i
++) {
7851 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7852 total_len
+= bde
.tus
.f
.bdeSize
;
7855 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
7857 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
7858 cmnd
= iocbq
->iocb
.ulpCommand
;
7860 switch (iocbq
->iocb
.ulpCommand
) {
7861 case CMD_ELS_REQUEST64_CR
:
7862 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7863 if (!iocbq
->iocb
.ulpLe
) {
7864 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7865 "2007 Only Limited Edition cmd Format"
7866 " supported 0x%x\n",
7867 iocbq
->iocb
.ulpCommand
);
7871 wqe
->els_req
.payload_len
= xmit_len
;
7872 /* Els_reguest64 has a TMO */
7873 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
7874 iocbq
->iocb
.ulpTimeout
);
7875 /* Need a VF for word 4 set the vf bit*/
7876 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
7877 /* And a VFID for word 12 */
7878 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
7879 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7880 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7881 iocbq
->iocb
.ulpContext
);
7882 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
7883 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
7884 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7885 if (command_type
== ELS_COMMAND_FIP
)
7886 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
7887 >> LPFC_FIP_ELS_ID_SHIFT
);
7888 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7889 iocbq
->context2
)->virt
);
7890 if_type
= bf_get(lpfc_sli_intf_if_type
,
7891 &phba
->sli4_hba
.sli_intf
);
7892 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7893 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
7894 *pcmd
== ELS_CMD_SCR
||
7895 *pcmd
== ELS_CMD_FDISC
||
7896 *pcmd
== ELS_CMD_LOGO
||
7897 *pcmd
== ELS_CMD_PLOGI
)) {
7898 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7899 bf_set(els_req64_sid
, &wqe
->els_req
,
7900 iocbq
->vport
->fc_myDID
);
7901 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7902 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7903 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
7904 } else if (pcmd
&& iocbq
->context1
) {
7905 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
7906 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7907 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7910 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
7911 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7912 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
7913 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
7914 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7915 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
7916 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7917 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
7919 case CMD_XMIT_SEQUENCE64_CX
:
7920 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
7921 iocbq
->iocb
.un
.ulpWord
[3]);
7922 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
7923 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7924 /* The entire sequence is transmitted for this IOCB */
7925 xmit_len
= total_len
;
7926 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
7927 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
7928 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
7929 case CMD_XMIT_SEQUENCE64_CR
:
7930 /* word3 iocb=io_tag32 wqe=reserved */
7931 wqe
->xmit_sequence
.rsvd3
= 0;
7932 /* word4 relative_offset memcpy */
7933 /* word5 r_ctl/df_ctl memcpy */
7934 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
7935 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
7936 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
7937 LPFC_WQE_IOD_WRITE
);
7938 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
7939 LPFC_WQE_LENLOC_WORD12
);
7940 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
7941 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
7942 command_type
= OTHER_COMMAND
;
7944 case CMD_XMIT_BCAST64_CN
:
7945 /* word3 iocb=iotag32 wqe=seq_payload_len */
7946 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
7947 /* word4 iocb=rsvd wqe=rsvd */
7948 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
7949 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
7950 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
7951 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7952 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
7953 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7954 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
7955 LPFC_WQE_LENLOC_WORD3
);
7956 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
7958 case CMD_FCP_IWRITE64_CR
:
7959 command_type
= FCP_COMMAND_DATA_OUT
;
7960 /* word3 iocb=iotag wqe=payload_offset_len */
7961 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7962 wqe
->fcp_iwrite
.payload_offset_len
=
7963 xmit_len
+ sizeof(struct fcp_rsp
);
7964 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7965 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7966 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
7967 iocbq
->iocb
.ulpFCP2Rcvy
);
7968 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
7969 /* Always open the exchange */
7970 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
7971 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7972 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
7973 LPFC_WQE_LENLOC_WORD4
);
7974 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
7975 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
7976 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
7977 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
7978 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
7980 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
7982 case CMD_FCP_IREAD64_CR
:
7983 /* word3 iocb=iotag wqe=payload_offset_len */
7984 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7985 wqe
->fcp_iread
.payload_offset_len
=
7986 xmit_len
+ sizeof(struct fcp_rsp
);
7987 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7988 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7989 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
7990 iocbq
->iocb
.ulpFCP2Rcvy
);
7991 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
7992 /* Always open the exchange */
7993 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
7994 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
7995 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
7996 LPFC_WQE_LENLOC_WORD4
);
7997 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
7998 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
7999 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
8000 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
8001 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
8003 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8005 case CMD_FCP_ICMND64_CR
:
8006 /* word3 iocb=IO_TAG wqe=reserved */
8007 wqe
->fcp_icmd
.rsrvd3
= 0;
8008 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8009 /* Always open the exchange */
8010 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
8011 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8012 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8013 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8014 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8015 LPFC_WQE_LENLOC_NONE
);
8016 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
8018 case CMD_GEN_REQUEST64_CR
:
8019 /* For this command calculate the xmit length of the
8023 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8024 sizeof(struct ulp_bde64
);
8025 for (i
= 0; i
< numBdes
; i
++) {
8026 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8027 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8029 xmit_len
+= bde
.tus
.f
.bdeSize
;
8031 /* word3 iocb=IO_TAG wqe=request_payload_len */
8032 wqe
->gen_req
.request_payload_len
= xmit_len
;
8033 /* word4 iocb=parameter wqe=relative_offset memcpy */
8034 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8035 /* word6 context tag copied in memcpy */
8036 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8037 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8038 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8039 "2015 Invalid CT %x command 0x%x\n",
8040 ct
, iocbq
->iocb
.ulpCommand
);
8043 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8044 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8045 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8046 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8047 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8048 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8049 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8050 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8051 command_type
= OTHER_COMMAND
;
8053 case CMD_XMIT_ELS_RSP64_CX
:
8054 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8055 /* words0-2 BDE memcpy */
8056 /* word3 iocb=iotag32 wqe=response_payload_len */
8057 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8058 /* word4 iocb=did wge=rsvd. */
8059 wqe
->xmit_els_rsp
.rsvd4
= 0;
8060 /* word5 iocb=rsvd wge=did */
8061 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8062 iocbq
->iocb
.un
.elsreq64
.remoteID
);
8063 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8064 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8065 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8066 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8067 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8068 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8069 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8070 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8071 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8072 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8073 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8074 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8075 LPFC_WQE_LENLOC_WORD3
);
8076 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8077 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8078 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8079 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8080 iocbq
->context2
)->virt
);
8081 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8082 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8083 bf_set(els_req64_sid
, &wqe
->els_req
,
8084 iocbq
->vport
->fc_myDID
);
8085 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8086 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8087 phba
->vpi_ids
[phba
->pport
->vpi
]);
8089 command_type
= OTHER_COMMAND
;
8091 case CMD_CLOSE_XRI_CN
:
8092 case CMD_ABORT_XRI_CN
:
8093 case CMD_ABORT_XRI_CX
:
8094 /* words 0-2 memcpy should be 0 rserved */
8095 /* port will send abts */
8096 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8097 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8098 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8099 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8103 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8105 * The link is down, or the command was ELS_FIP
8106 * so the fw does not need to send abts
8109 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8111 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8112 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8113 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8114 wqe
->abort_cmd
.rsrvd5
= 0;
8115 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8116 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8117 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8119 * The abort handler will send us CMD_ABORT_XRI_CN or
8120 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8122 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8123 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8124 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8125 LPFC_WQE_LENLOC_NONE
);
8126 cmnd
= CMD_ABORT_XRI_CX
;
8127 command_type
= OTHER_COMMAND
;
8130 case CMD_XMIT_BLS_RSP64_CX
:
8131 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8132 /* As BLS ABTS RSP WQE is very different from other WQEs,
8133 * we re-construct this WQE here based on information in
8134 * iocbq from scratch.
8136 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8137 /* OX_ID is invariable to who sent ABTS to CT exchange */
8138 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8139 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8140 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8141 LPFC_ABTS_UNSOL_INT
) {
8142 /* ABTS sent by initiator to CT exchange, the
8143 * RX_ID field will be filled with the newly
8144 * allocated responder XRI.
8146 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8147 iocbq
->sli4_xritag
);
8149 /* ABTS sent by responder to CT exchange, the
8150 * RX_ID field will be filled with the responder
8153 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8154 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8156 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8157 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8160 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8162 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8163 iocbq
->iocb
.ulpContext
);
8164 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8165 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8166 phba
->vpi_ids
[phba
->pport
->vpi
]);
8167 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8168 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8169 LPFC_WQE_LENLOC_NONE
);
8170 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8171 command_type
= OTHER_COMMAND
;
8172 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8173 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8174 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8175 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8176 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8177 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8178 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8182 case CMD_XRI_ABORTED_CX
:
8183 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8184 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8185 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8186 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8187 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8189 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8190 "2014 Invalid command 0x%x\n",
8191 iocbq
->iocb
.ulpCommand
);
8196 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8197 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8198 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8199 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8200 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8201 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8202 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8207 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8208 * @phba: Pointer to HBA context object.
8209 * @ring_number: SLI ring number to issue iocb on.
8210 * @piocb: Pointer to command iocb.
8211 * @flag: Flag indicating if this command can be put into txq.
8213 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8214 * an iocb command to an HBA with SLI-4 interface spec.
8216 * This function is called with hbalock held. The function will return success
8217 * after it successfully submit the iocb to firmware or after adding to the
8221 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8222 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8224 struct lpfc_sglq
*sglq
;
8226 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8228 if (piocb
->sli4_xritag
== NO_XRI
) {
8229 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8230 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8233 if (pring
->txq_cnt
) {
8234 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8235 __lpfc_sli_ringtx_put(phba
,
8237 return IOCB_SUCCESS
;
8242 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8244 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8245 __lpfc_sli_ringtx_put(phba
,
8248 return IOCB_SUCCESS
;
8254 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8255 /* These IO's already have an XRI and a mapped sgl. */
8259 * This is a continuation of a commandi,(CX) so this
8260 * sglq is on the active list
8262 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
8268 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8269 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8270 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8274 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8277 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8278 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8280 * For FCP command IOCB, get a new WQ index to distribute
8281 * WQE across the WQsr. On the other hand, for abort IOCB,
8282 * it carries the same WQ index to the original command
8285 if (piocb
->iocb_flag
& LPFC_IO_FCP
)
8286 piocb
->fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8287 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8289 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8293 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8296 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8302 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8304 * This routine wraps the actual lockless version for issusing IOCB function
8305 * pointer from the lpfc_hba struct.
8308 * IOCB_ERROR - Error
8309 * IOCB_SUCCESS - Success
8313 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8314 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8316 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8320 * lpfc_sli_api_table_setup - Set up sli api function jump table
8321 * @phba: The hba struct for which this call is being executed.
8322 * @dev_grp: The HBA PCI-Device group number.
8324 * This routine sets up the SLI interface API function jump table in @phba
8326 * Returns: 0 - success, -ENODEV - failure.
8329 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8333 case LPFC_PCI_DEV_LP
:
8334 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8335 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8337 case LPFC_PCI_DEV_OC
:
8338 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8339 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8342 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8343 "1419 Invalid HBA PCI-device group: 0x%x\n",
8348 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8353 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8354 * @phba: Pointer to HBA context object.
8355 * @pring: Pointer to driver SLI ring object.
8356 * @piocb: Pointer to command iocb.
8357 * @flag: Flag indicating if this command can be put into txq.
8359 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8360 * function. This function gets the hbalock and calls
8361 * __lpfc_sli_issue_iocb function and will return the error returned
8362 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8363 * functions which do not hold hbalock.
8366 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8367 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8369 unsigned long iflags
;
8372 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8373 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8374 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8380 * lpfc_extra_ring_setup - Extra ring setup function
8381 * @phba: Pointer to HBA context object.
8383 * This function is called while driver attaches with the
8384 * HBA to setup the extra ring. The extra ring is used
8385 * only when driver needs to support target mode functionality
8386 * or IP over FC functionalities.
8388 * This function is called with no lock held.
8391 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8393 struct lpfc_sli
*psli
;
8394 struct lpfc_sli_ring
*pring
;
8398 /* Adjust cmd/rsp ring iocb entries more evenly */
8400 /* Take some away from the FCP ring */
8401 pring
= &psli
->ring
[psli
->fcp_ring
];
8402 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8403 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8404 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8405 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8407 /* and give them to the extra ring */
8408 pring
= &psli
->ring
[psli
->extra_ring
];
8410 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8411 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8412 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8413 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8415 /* Setup default profile for this ring */
8416 pring
->iotag_max
= 4096;
8417 pring
->num_mask
= 1;
8418 pring
->prt
[0].profile
= 0; /* Mask 0 */
8419 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8420 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8421 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8425 /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
8426 * @vport: pointer to virtual port object.
8427 * @ndlp: nodelist pointer for the impacted rport.
8429 * The driver calls this routine in response to a XRI ABORT CQE
8430 * event from the port. In this event, the driver is required to
8431 * recover its login to the rport even though its login may be valid
8432 * from the driver's perspective. The failed ABTS notice from the
8433 * port indicates the rport is not responding.
8436 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8437 struct lpfc_nodelist
*ndlp
)
8439 struct Scsi_Host
*shost
;
8440 struct lpfc_hba
*phba
;
8441 unsigned long flags
= 0;
8443 shost
= lpfc_shost_from_vport(vport
);
8445 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8446 lpfc_printf_log(phba
, KERN_INFO
,
8447 LOG_SLI
, "3093 No rport recovery needed. "
8448 "rport in state 0x%x\n",
8452 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8453 "3094 Start rport recovery on shost id 0x%x "
8454 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8456 shost
->host_no
, ndlp
->nlp_DID
,
8457 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8460 * The rport is not responding. Don't attempt ADISC recovery.
8461 * Remove the FCP-2 flag to force a PLOGI.
8463 spin_lock_irqsave(shost
->host_lock
, flags
);
8464 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8465 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8466 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
8467 NLP_EVT_DEVICE_RECOVERY
);
8468 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
8469 spin_lock_irqsave(shost
->host_lock
, flags
);
8470 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
8471 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8472 lpfc_disc_start(vport
);
8475 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8476 * @phba: Pointer to HBA context object.
8477 * @iocbq: Pointer to iocb object.
8479 * The async_event handler calls this routine when it receives
8480 * an ASYNC_STATUS_CN event from the port. The port generates
8481 * this event when an Abort Sequence request to an rport fails
8482 * twice in succession. The abort could be originated by the
8483 * driver or by the port. The ABTS could have been for an ELS
8484 * or FCP IO. The port only generates this event when an ABTS
8485 * fails to complete after one retry.
8488 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8489 struct lpfc_iocbq
*iocbq
)
8491 struct lpfc_nodelist
*ndlp
= NULL
;
8492 uint16_t rpi
= 0, vpi
= 0;
8493 struct lpfc_vport
*vport
= NULL
;
8495 /* The rpi in the ulpContext is vport-sensitive. */
8496 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8497 rpi
= iocbq
->iocb
.ulpContext
;
8499 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8500 "3092 Port generated ABTS async event "
8501 "on vpi %d rpi %d status 0x%x\n",
8502 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8504 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8507 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8508 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8511 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8512 lpfc_sli_abts_recover_port(vport
, ndlp
);
8516 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8517 "3095 Event Context not found, no "
8518 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8519 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8523 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8524 * @phba: pointer to HBA context object.
8525 * @ndlp: nodelist pointer for the impacted rport.
8526 * @axri: pointer to the wcqe containing the failed exchange.
8528 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8529 * port. The port generates this event when an abort exchange request to an
8530 * rport fails twice in succession with no reply. The abort could be originated
8531 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8534 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8535 struct lpfc_nodelist
*ndlp
,
8536 struct sli4_wcqe_xri_aborted
*axri
)
8538 struct lpfc_vport
*vport
;
8539 uint32_t ext_status
= 0;
8541 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
8542 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8543 "3115 Node Context not found, driver "
8544 "ignoring abts err event\n");
8548 vport
= ndlp
->vport
;
8549 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8550 "3116 Port generated FCP XRI ABORT event on "
8551 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8552 ndlp
->vport
->vpi
, ndlp
->nlp_rpi
,
8553 bf_get(lpfc_wcqe_xa_xri
, axri
),
8554 bf_get(lpfc_wcqe_xa_status
, axri
),
8558 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8559 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8560 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8562 ext_status
= axri
->parameter
& WCQE_PARAM_MASK
;
8563 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
8564 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
8565 lpfc_sli_abts_recover_port(vport
, ndlp
);
8569 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8570 * @phba: Pointer to HBA context object.
8571 * @pring: Pointer to driver SLI ring object.
8572 * @iocbq: Pointer to iocb object.
8574 * This function is called by the slow ring event handler
8575 * function when there is an ASYNC event iocb in the ring.
8576 * This function is called with no lock held.
8577 * Currently this function handles only temperature related
8578 * ASYNC events. The function decodes the temperature sensor
8579 * event message and posts events for the management applications.
8582 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8583 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8587 struct temp_event temp_event_data
;
8588 struct Scsi_Host
*shost
;
8591 icmd
= &iocbq
->iocb
;
8592 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8595 case ASYNC_TEMP_WARN
:
8596 case ASYNC_TEMP_SAFE
:
8597 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8598 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8599 if (evt_code
== ASYNC_TEMP_WARN
) {
8600 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8601 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8602 "0347 Adapter is very hot, please take "
8603 "corrective action. temperature : %d Celsius\n",
8604 (uint32_t) icmd
->ulpContext
);
8606 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8607 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8608 "0340 Adapter temperature is OK now. "
8609 "temperature : %d Celsius\n",
8610 (uint32_t) icmd
->ulpContext
);
8613 /* Send temperature change event to applications */
8614 shost
= lpfc_shost_from_vport(phba
->pport
);
8615 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8616 sizeof(temp_event_data
), (char *) &temp_event_data
,
8619 case ASYNC_STATUS_CN
:
8620 lpfc_sli_abts_err_handler(phba
, iocbq
);
8623 iocb_w
= (uint32_t *) icmd
;
8624 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8625 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8627 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8628 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8629 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8630 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8631 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8632 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8633 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8634 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8635 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8643 * lpfc_sli_setup - SLI ring setup function
8644 * @phba: Pointer to HBA context object.
8646 * lpfc_sli_setup sets up rings of the SLI interface with
8647 * number of iocbs per ring and iotags. This function is
8648 * called while driver attach to the HBA and before the
8649 * interrupts are enabled. So there is no need for locking.
8651 * This function always returns 0.
8654 lpfc_sli_setup(struct lpfc_hba
*phba
)
8656 int i
, totiocbsize
= 0;
8657 struct lpfc_sli
*psli
= &phba
->sli
;
8658 struct lpfc_sli_ring
*pring
;
8660 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
8662 psli
->fcp_ring
= LPFC_FCP_RING
;
8663 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8664 psli
->extra_ring
= LPFC_EXTRA_RING
;
8666 psli
->iocbq_lookup
= NULL
;
8667 psli
->iocbq_lookup_len
= 0;
8668 psli
->last_iotag
= 0;
8670 for (i
= 0; i
< psli
->num_rings
; i
++) {
8671 pring
= &psli
->ring
[i
];
8673 case LPFC_FCP_RING
: /* ring 0 - FCP */
8674 /* numCiocb and numRiocb are used in config_port */
8675 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8676 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8677 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8678 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8679 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8680 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8681 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8682 SLI3_IOCB_CMD_SIZE
:
8684 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8685 SLI3_IOCB_RSP_SIZE
:
8687 pring
->iotag_ctr
= 0;
8689 (phba
->cfg_hba_queue_depth
* 2);
8690 pring
->fast_iotag
= pring
->iotag_max
;
8691 pring
->num_mask
= 0;
8693 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
8694 /* numCiocb and numRiocb are used in config_port */
8695 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
8696 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
8697 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8698 SLI3_IOCB_CMD_SIZE
:
8700 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8701 SLI3_IOCB_RSP_SIZE
:
8703 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
8704 pring
->num_mask
= 0;
8706 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
8707 /* numCiocb and numRiocb are used in config_port */
8708 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
8709 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
8710 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8711 SLI3_IOCB_CMD_SIZE
:
8713 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8714 SLI3_IOCB_RSP_SIZE
:
8716 pring
->fast_iotag
= 0;
8717 pring
->iotag_ctr
= 0;
8718 pring
->iotag_max
= 4096;
8719 pring
->lpfc_sli_rcv_async_status
=
8720 lpfc_sli_async_event_handler
;
8721 pring
->num_mask
= LPFC_MAX_RING_MASK
;
8722 pring
->prt
[0].profile
= 0; /* Mask 0 */
8723 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
8724 pring
->prt
[0].type
= FC_TYPE_ELS
;
8725 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
8726 lpfc_els_unsol_event
;
8727 pring
->prt
[1].profile
= 0; /* Mask 1 */
8728 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
8729 pring
->prt
[1].type
= FC_TYPE_ELS
;
8730 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
8731 lpfc_els_unsol_event
;
8732 pring
->prt
[2].profile
= 0; /* Mask 2 */
8733 /* NameServer Inquiry */
8734 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
8736 pring
->prt
[2].type
= FC_TYPE_CT
;
8737 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
8738 lpfc_ct_unsol_event
;
8739 pring
->prt
[3].profile
= 0; /* Mask 3 */
8740 /* NameServer response */
8741 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
8743 pring
->prt
[3].type
= FC_TYPE_CT
;
8744 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
8745 lpfc_ct_unsol_event
;
8746 /* abort unsolicited sequence */
8747 pring
->prt
[4].profile
= 0; /* Mask 4 */
8748 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
8749 pring
->prt
[4].type
= FC_TYPE_BLS
;
8750 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
8751 lpfc_sli4_ct_abort_unsol_event
;
8754 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
8755 (pring
->numRiocb
* pring
->sizeRiocb
);
8757 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
8758 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8759 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
8760 "SLI2 SLIM Data: x%x x%lx\n",
8761 phba
->brd_no
, totiocbsize
,
8762 (unsigned long) MAX_SLIM_IOCB_SIZE
);
8764 if (phba
->cfg_multi_ring_support
== 2)
8765 lpfc_extra_ring_setup(phba
);
8771 * lpfc_sli_queue_setup - Queue initialization function
8772 * @phba: Pointer to HBA context object.
8774 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8775 * ring. This function also initializes ring indices of each ring.
8776 * This function is called during the initialization of the SLI
8777 * interface of an HBA.
8778 * This function is called with no lock held and always returns
8782 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
8784 struct lpfc_sli
*psli
;
8785 struct lpfc_sli_ring
*pring
;
8789 spin_lock_irq(&phba
->hbalock
);
8790 INIT_LIST_HEAD(&psli
->mboxq
);
8791 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
8792 /* Initialize list headers for txq and txcmplq as double linked lists */
8793 for (i
= 0; i
< psli
->num_rings
; i
++) {
8794 pring
= &psli
->ring
[i
];
8796 pring
->next_cmdidx
= 0;
8797 pring
->local_getidx
= 0;
8799 INIT_LIST_HEAD(&pring
->txq
);
8800 INIT_LIST_HEAD(&pring
->txcmplq
);
8801 INIT_LIST_HEAD(&pring
->iocb_continueq
);
8802 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
8803 INIT_LIST_HEAD(&pring
->postbufq
);
8805 spin_unlock_irq(&phba
->hbalock
);
8810 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8811 * @phba: Pointer to HBA context object.
8813 * This routine flushes the mailbox command subsystem. It will unconditionally
8814 * flush all the mailbox commands in the three possible stages in the mailbox
8815 * command sub-system: pending mailbox command queue; the outstanding mailbox
8816 * command; and completed mailbox command queue. It is caller's responsibility
8817 * to make sure that the driver is in the proper state to flush the mailbox
8818 * command sub-system. Namely, the posting of mailbox commands into the
8819 * pending mailbox command queue from the various clients must be stopped;
8820 * either the HBA is in a state that it will never works on the outstanding
8821 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8822 * mailbox command has been completed.
8825 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
8827 LIST_HEAD(completions
);
8828 struct lpfc_sli
*psli
= &phba
->sli
;
8830 unsigned long iflag
;
8832 /* Flush all the mailbox commands in the mbox system */
8833 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8834 /* The pending mailbox command queue */
8835 list_splice_init(&phba
->sli
.mboxq
, &completions
);
8836 /* The outstanding active mailbox command */
8837 if (psli
->mbox_active
) {
8838 list_add_tail(&psli
->mbox_active
->list
, &completions
);
8839 psli
->mbox_active
= NULL
;
8840 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8842 /* The completed mailbox command queue */
8843 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
8844 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8846 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8847 while (!list_empty(&completions
)) {
8848 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
8849 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8851 pmb
->mbox_cmpl(phba
, pmb
);
8856 * lpfc_sli_host_down - Vport cleanup function
8857 * @vport: Pointer to virtual port object.
8859 * lpfc_sli_host_down is called to clean up the resources
8860 * associated with a vport before destroying virtual
8861 * port data structures.
8862 * This function does following operations:
8863 * - Free discovery resources associated with this virtual
8865 * - Free iocbs associated with this virtual port in
8867 * - Send abort for all iocb commands associated with this
8870 * This function is called with no lock held and always returns 1.
8873 lpfc_sli_host_down(struct lpfc_vport
*vport
)
8875 LIST_HEAD(completions
);
8876 struct lpfc_hba
*phba
= vport
->phba
;
8877 struct lpfc_sli
*psli
= &phba
->sli
;
8878 struct lpfc_sli_ring
*pring
;
8879 struct lpfc_iocbq
*iocb
, *next_iocb
;
8881 unsigned long flags
= 0;
8882 uint16_t prev_pring_flag
;
8884 lpfc_cleanup_discovery_resources(vport
);
8886 spin_lock_irqsave(&phba
->hbalock
, flags
);
8887 for (i
= 0; i
< psli
->num_rings
; i
++) {
8888 pring
= &psli
->ring
[i
];
8889 prev_pring_flag
= pring
->flag
;
8890 /* Only slow rings */
8891 if (pring
->ringno
== LPFC_ELS_RING
) {
8892 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8893 /* Set the lpfc data pending flag */
8894 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8897 * Error everything on the txq since these iocbs have not been
8898 * given to the FW yet.
8900 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
8901 if (iocb
->vport
!= vport
)
8903 list_move_tail(&iocb
->list
, &completions
);
8907 /* Next issue ABTS for everything on the txcmplq */
8908 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
8910 if (iocb
->vport
!= vport
)
8912 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
8915 pring
->flag
= prev_pring_flag
;
8918 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8920 /* Cancel all the IOCBs from the completions list */
8921 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8927 * lpfc_sli_hba_down - Resource cleanup function for the HBA
8928 * @phba: Pointer to HBA context object.
8930 * This function cleans up all iocb, buffers, mailbox commands
8931 * while shutting down the HBA. This function is called with no
8932 * lock held and always returns 1.
8933 * This function does the following to cleanup driver resources:
8934 * - Free discovery resources for each virtual port
8935 * - Cleanup any pending fabric iocbs
8936 * - Iterate through the iocb txq and free each entry
8938 * - Free up any buffer posted to the HBA
8939 * - Free mailbox commands in the mailbox queue.
8942 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
8944 LIST_HEAD(completions
);
8945 struct lpfc_sli
*psli
= &phba
->sli
;
8946 struct lpfc_sli_ring
*pring
;
8947 struct lpfc_dmabuf
*buf_ptr
;
8948 unsigned long flags
= 0;
8951 /* Shutdown the mailbox command sub-system */
8952 lpfc_sli_mbox_sys_shutdown(phba
);
8954 lpfc_hba_down_prep(phba
);
8956 lpfc_fabric_abort_hba(phba
);
8958 spin_lock_irqsave(&phba
->hbalock
, flags
);
8959 for (i
= 0; i
< psli
->num_rings
; i
++) {
8960 pring
= &psli
->ring
[i
];
8961 /* Only slow rings */
8962 if (pring
->ringno
== LPFC_ELS_RING
) {
8963 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8964 /* Set the lpfc data pending flag */
8965 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8969 * Error everything on the txq since these iocbs have not been
8970 * given to the FW yet.
8972 list_splice_init(&pring
->txq
, &completions
);
8976 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8978 /* Cancel all the IOCBs from the completions list */
8979 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8982 spin_lock_irqsave(&phba
->hbalock
, flags
);
8983 list_splice_init(&phba
->elsbuf
, &completions
);
8984 phba
->elsbuf_cnt
= 0;
8985 phba
->elsbuf_prev_cnt
= 0;
8986 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8988 while (!list_empty(&completions
)) {
8989 list_remove_head(&completions
, buf_ptr
,
8990 struct lpfc_dmabuf
, list
);
8991 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
8995 /* Return any active mbox cmds */
8996 del_timer_sync(&psli
->mbox_tmo
);
8998 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
8999 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9000 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9006 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9007 * @srcp: Source memory pointer.
9008 * @destp: Destination memory pointer.
9009 * @cnt: Number of words required to be copied.
9011 * This function is used for copying data between driver memory
9012 * and the SLI memory. This function also changes the endianness
9013 * of each word if native endianness is different from SLI
9014 * endianness. This function can be called with or without
9018 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9020 uint32_t *src
= srcp
;
9021 uint32_t *dest
= destp
;
9025 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9027 ldata
= le32_to_cpu(ldata
);
9036 * lpfc_sli_bemem_bcopy - SLI memory copy function
9037 * @srcp: Source memory pointer.
9038 * @destp: Destination memory pointer.
9039 * @cnt: Number of words required to be copied.
9041 * This function is used for copying data between a data structure
9042 * with big endian representation to local endianness.
9043 * This function can be called with or without lock.
9046 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9048 uint32_t *src
= srcp
;
9049 uint32_t *dest
= destp
;
9053 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9055 ldata
= be32_to_cpu(ldata
);
9063 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9064 * @phba: Pointer to HBA context object.
9065 * @pring: Pointer to driver SLI ring object.
9066 * @mp: Pointer to driver buffer object.
9068 * This function is called with no lock held.
9069 * It always return zero after adding the buffer to the postbufq
9073 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9074 struct lpfc_dmabuf
*mp
)
9076 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9078 spin_lock_irq(&phba
->hbalock
);
9079 list_add_tail(&mp
->list
, &pring
->postbufq
);
9080 pring
->postbufq_cnt
++;
9081 spin_unlock_irq(&phba
->hbalock
);
9086 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9087 * @phba: Pointer to HBA context object.
9089 * When HBQ is enabled, buffers are searched based on tags. This function
9090 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9091 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9092 * does not conflict with tags of buffer posted for unsolicited events.
9093 * The function returns the allocated tag. The function is called with
9097 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9099 spin_lock_irq(&phba
->hbalock
);
9100 phba
->buffer_tag_count
++;
9102 * Always set the QUE_BUFTAG_BIT to distiguish between
9103 * a tag assigned by HBQ.
9105 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9106 spin_unlock_irq(&phba
->hbalock
);
9107 return phba
->buffer_tag_count
;
9111 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9112 * @phba: Pointer to HBA context object.
9113 * @pring: Pointer to driver SLI ring object.
9116 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9117 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9118 * iocb is posted to the response ring with the tag of the buffer.
9119 * This function searches the pring->postbufq list using the tag
9120 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9121 * iocb. If the buffer is found then lpfc_dmabuf object of the
9122 * buffer is returned to the caller else NULL is returned.
9123 * This function is called with no lock held.
9125 struct lpfc_dmabuf
*
9126 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9129 struct lpfc_dmabuf
*mp
, *next_mp
;
9130 struct list_head
*slp
= &pring
->postbufq
;
9132 /* Search postbufq, from the beginning, looking for a match on tag */
9133 spin_lock_irq(&phba
->hbalock
);
9134 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9135 if (mp
->buffer_tag
== tag
) {
9136 list_del_init(&mp
->list
);
9137 pring
->postbufq_cnt
--;
9138 spin_unlock_irq(&phba
->hbalock
);
9143 spin_unlock_irq(&phba
->hbalock
);
9144 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9145 "0402 Cannot find virtual addr for buffer tag on "
9146 "ring %d Data x%lx x%p x%p x%x\n",
9147 pring
->ringno
, (unsigned long) tag
,
9148 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9154 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9155 * @phba: Pointer to HBA context object.
9156 * @pring: Pointer to driver SLI ring object.
9157 * @phys: DMA address of the buffer.
9159 * This function searches the buffer list using the dma_address
9160 * of unsolicited event to find the driver's lpfc_dmabuf object
9161 * corresponding to the dma_address. The function returns the
9162 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9163 * This function is called by the ct and els unsolicited event
9164 * handlers to get the buffer associated with the unsolicited
9167 * This function is called with no lock held.
9169 struct lpfc_dmabuf
*
9170 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9173 struct lpfc_dmabuf
*mp
, *next_mp
;
9174 struct list_head
*slp
= &pring
->postbufq
;
9176 /* Search postbufq, from the beginning, looking for a match on phys */
9177 spin_lock_irq(&phba
->hbalock
);
9178 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9179 if (mp
->phys
== phys
) {
9180 list_del_init(&mp
->list
);
9181 pring
->postbufq_cnt
--;
9182 spin_unlock_irq(&phba
->hbalock
);
9187 spin_unlock_irq(&phba
->hbalock
);
9188 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9189 "0410 Cannot find virtual addr for mapped buf on "
9190 "ring %d Data x%llx x%p x%p x%x\n",
9191 pring
->ringno
, (unsigned long long)phys
,
9192 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9197 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9198 * @phba: Pointer to HBA context object.
9199 * @cmdiocb: Pointer to driver command iocb object.
9200 * @rspiocb: Pointer to driver response iocb object.
9202 * This function is the completion handler for the abort iocbs for
9203 * ELS commands. This function is called from the ELS ring event
9204 * handler with no lock held. This function frees memory resources
9205 * associated with the abort iocb.
9208 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9209 struct lpfc_iocbq
*rspiocb
)
9211 IOCB_t
*irsp
= &rspiocb
->iocb
;
9212 uint16_t abort_iotag
, abort_context
;
9213 struct lpfc_iocbq
*abort_iocb
= NULL
;
9215 if (irsp
->ulpStatus
) {
9218 * Assume that the port already completed and returned, or
9219 * will return the iocb. Just Log the message.
9221 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9222 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9224 spin_lock_irq(&phba
->hbalock
);
9225 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9226 if (abort_iotag
!= 0 &&
9227 abort_iotag
<= phba
->sli
.last_iotag
)
9229 phba
->sli
.iocbq_lookup
[abort_iotag
];
9231 /* For sli4 the abort_tag is the XRI,
9232 * so the abort routine puts the iotag of the iocb
9233 * being aborted in the context field of the abort
9236 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9238 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9239 "0327 Cannot abort els iocb %p "
9240 "with tag %x context %x, abort status %x, "
9242 abort_iocb
, abort_iotag
, abort_context
,
9243 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9245 spin_unlock_irq(&phba
->hbalock
);
9247 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9252 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9253 * @phba: Pointer to HBA context object.
9254 * @cmdiocb: Pointer to driver command iocb object.
9255 * @rspiocb: Pointer to driver response iocb object.
9257 * The function is called from SLI ring event handler with no
9258 * lock held. This function is the completion handler for ELS commands
9259 * which are aborted. The function frees memory resources used for
9260 * the aborted ELS commands.
9263 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9264 struct lpfc_iocbq
*rspiocb
)
9266 IOCB_t
*irsp
= &rspiocb
->iocb
;
9268 /* ELS cmd tag <ulpIoTag> completes */
9269 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9270 "0139 Ignoring ELS cmd tag x%x completion Data: "
9272 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9273 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9274 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9275 lpfc_ct_free_iocb(phba
, cmdiocb
);
9277 lpfc_els_free_iocb(phba
, cmdiocb
);
9282 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9283 * @phba: Pointer to HBA context object.
9284 * @pring: Pointer to driver SLI ring object.
9285 * @cmdiocb: Pointer to driver command iocb object.
9287 * This function issues an abort iocb for the provided command iocb down to
9288 * the port. Other than the case the outstanding command iocb is an abort
9289 * request, this function issues abort out unconditionally. This function is
9290 * called with hbalock held. The function returns 0 when it fails due to
9291 * memory allocation failure or when the command iocb is an abort request.
9294 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9295 struct lpfc_iocbq
*cmdiocb
)
9297 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9298 struct lpfc_iocbq
*abtsiocbp
;
9299 IOCB_t
*icmd
= NULL
;
9300 IOCB_t
*iabt
= NULL
;
9304 * There are certain command types we don't want to abort. And we
9305 * don't want to abort commands that are already in the process of
9308 icmd
= &cmdiocb
->iocb
;
9309 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9310 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9311 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9314 /* issue ABTS for this IOCB based on iotag */
9315 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9316 if (abtsiocbp
== NULL
)
9319 /* This signals the response to set the correct status
9320 * before calling the completion handler
9322 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9324 iabt
= &abtsiocbp
->iocb
;
9325 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9326 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9327 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9328 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9329 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9332 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9334 iabt
->ulpClass
= icmd
->ulpClass
;
9336 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9337 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9338 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9339 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9341 if (phba
->link_state
>= LPFC_LINK_UP
)
9342 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9344 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9346 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9348 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9349 "0339 Abort xri x%x, original iotag x%x, "
9350 "abort cmd iotag x%x\n",
9351 iabt
->un
.acxri
.abortIoTag
,
9352 iabt
->un
.acxri
.abortContextTag
,
9354 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
9357 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9360 * Caller to this routine should check for IOCB_ERROR
9361 * and handle it properly. This routine no longer removes
9362 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9368 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9369 * @phba: Pointer to HBA context object.
9370 * @pring: Pointer to driver SLI ring object.
9371 * @cmdiocb: Pointer to driver command iocb object.
9373 * This function issues an abort iocb for the provided command iocb. In case
9374 * of unloading, the abort iocb will not be issued to commands on the ELS
9375 * ring. Instead, the callback function shall be changed to those commands
9376 * so that nothing happens when them finishes. This function is called with
9377 * hbalock held. The function returns 0 when the command iocb is an abort
9381 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9382 struct lpfc_iocbq
*cmdiocb
)
9384 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9385 int retval
= IOCB_ERROR
;
9386 IOCB_t
*icmd
= NULL
;
9389 * There are certain command types we don't want to abort. And we
9390 * don't want to abort commands that are already in the process of
9393 icmd
= &cmdiocb
->iocb
;
9394 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9395 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9396 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9400 * If we're unloading, don't abort iocb on the ELS ring, but change
9401 * the callback so that nothing happens when it finishes.
9403 if ((vport
->load_flag
& FC_UNLOADING
) &&
9404 (pring
->ringno
== LPFC_ELS_RING
)) {
9405 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9406 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9408 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9409 goto abort_iotag_exit
;
9412 /* Now, we try to issue the abort to the cmdiocb out */
9413 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9417 * Caller to this routine should check for IOCB_ERROR
9418 * and handle it properly. This routine no longer removes
9419 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9425 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9426 * @phba: Pointer to HBA context object.
9427 * @pring: Pointer to driver SLI ring object.
9429 * This function aborts all iocbs in the given ring and frees all the iocb
9430 * objects in txq. This function issues abort iocbs unconditionally for all
9431 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9432 * to complete before the return of this function. The caller is not required
9433 * to hold any locks.
9436 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9438 LIST_HEAD(completions
);
9439 struct lpfc_iocbq
*iocb
, *next_iocb
;
9441 if (pring
->ringno
== LPFC_ELS_RING
)
9442 lpfc_fabric_abort_hba(phba
);
9444 spin_lock_irq(&phba
->hbalock
);
9446 /* Take off all the iocbs on txq for cancelling */
9447 list_splice_init(&pring
->txq
, &completions
);
9450 /* Next issue ABTS for everything on the txcmplq */
9451 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9452 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9454 spin_unlock_irq(&phba
->hbalock
);
9456 /* Cancel all the IOCBs from the completions list */
9457 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9462 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9463 * @phba: pointer to lpfc HBA data structure.
9465 * This routine will abort all pending and outstanding iocbs to an HBA.
9468 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9470 struct lpfc_sli
*psli
= &phba
->sli
;
9471 struct lpfc_sli_ring
*pring
;
9474 for (i
= 0; i
< psli
->num_rings
; i
++) {
9475 pring
= &psli
->ring
[i
];
9476 lpfc_sli_iocb_ring_abort(phba
, pring
);
9481 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9482 * @iocbq: Pointer to driver iocb object.
9483 * @vport: Pointer to driver virtual port object.
9484 * @tgt_id: SCSI ID of the target.
9485 * @lun_id: LUN ID of the scsi device.
9486 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9488 * This function acts as an iocb filter for functions which abort or count
9489 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9490 * 0 if the filtering criteria is met for the given iocb and will return
9491 * 1 if the filtering criteria is not met.
9492 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9493 * given iocb is for the SCSI device specified by vport, tgt_id and
9495 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9496 * given iocb is for the SCSI target specified by vport and tgt_id
9498 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9499 * given iocb is for the SCSI host associated with the given vport.
9500 * This function is called with no locks held.
9503 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9504 uint16_t tgt_id
, uint64_t lun_id
,
9505 lpfc_ctx_cmd ctx_cmd
)
9507 struct lpfc_scsi_buf
*lpfc_cmd
;
9510 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9513 if (iocbq
->vport
!= vport
)
9516 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9518 if (lpfc_cmd
->pCmd
== NULL
)
9523 if ((lpfc_cmd
->rdata
->pnode
) &&
9524 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9525 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9529 if ((lpfc_cmd
->rdata
->pnode
) &&
9530 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9537 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9546 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9547 * @vport: Pointer to virtual port.
9548 * @tgt_id: SCSI ID of the target.
9549 * @lun_id: LUN ID of the scsi device.
9550 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9552 * This function returns number of FCP commands pending for the vport.
9553 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9554 * commands pending on the vport associated with SCSI device specified
9555 * by tgt_id and lun_id parameters.
9556 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9557 * commands pending on the vport associated with SCSI target specified
9558 * by tgt_id parameter.
9559 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9560 * commands pending on the vport.
9561 * This function returns the number of iocbs which satisfy the filter.
9562 * This function is called without any lock held.
9565 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9566 lpfc_ctx_cmd ctx_cmd
)
9568 struct lpfc_hba
*phba
= vport
->phba
;
9569 struct lpfc_iocbq
*iocbq
;
9572 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9573 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9575 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9584 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9585 * @phba: Pointer to HBA context object
9586 * @cmdiocb: Pointer to command iocb object.
9587 * @rspiocb: Pointer to response iocb object.
9589 * This function is called when an aborted FCP iocb completes. This
9590 * function is called by the ring event handler with no lock held.
9591 * This function frees the iocb.
9594 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9595 struct lpfc_iocbq
*rspiocb
)
9597 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9598 "3096 ABORT_XRI_CN completing on xri x%x "
9599 "original iotag x%x, abort cmd iotag x%x "
9600 "status 0x%x, reason 0x%x\n",
9601 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9602 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9603 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9604 rspiocb
->iocb
.un
.ulpWord
[4]);
9605 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9610 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9611 * @vport: Pointer to virtual port.
9612 * @pring: Pointer to driver SLI ring object.
9613 * @tgt_id: SCSI ID of the target.
9614 * @lun_id: LUN ID of the scsi device.
9615 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9617 * This function sends an abort command for every SCSI command
9618 * associated with the given virtual port pending on the ring
9619 * filtered by lpfc_sli_validate_fcp_iocb function.
9620 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9621 * FCP iocbs associated with lun specified by tgt_id and lun_id
9623 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9624 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9625 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9626 * FCP iocbs associated with virtual port.
9627 * This function returns number of iocbs it failed to abort.
9628 * This function is called with no locks held.
9631 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9632 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9634 struct lpfc_hba
*phba
= vport
->phba
;
9635 struct lpfc_iocbq
*iocbq
;
9636 struct lpfc_iocbq
*abtsiocb
;
9638 int errcnt
= 0, ret_val
= 0;
9641 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9642 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9644 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9648 /* issue ABTS for this IOCB based on iotag */
9649 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9650 if (abtsiocb
== NULL
) {
9656 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9657 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9658 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9659 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9661 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9662 abtsiocb
->iocb
.ulpLe
= 1;
9663 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9664 abtsiocb
->vport
= phba
->pport
;
9666 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9667 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9668 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9669 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9671 if (lpfc_is_link_up(phba
))
9672 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9674 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
9676 /* Setup callback routine and issue the command. */
9677 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
9678 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9680 if (ret_val
== IOCB_ERROR
) {
9681 lpfc_sli_release_iocbq(phba
, abtsiocb
);
9691 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9692 * @phba: Pointer to HBA context object.
9693 * @cmdiocbq: Pointer to command iocb.
9694 * @rspiocbq: Pointer to response iocb.
9696 * This function is the completion handler for iocbs issued using
9697 * lpfc_sli_issue_iocb_wait function. This function is called by the
9698 * ring event handler function without any lock held. This function
9699 * can be called from both worker thread context and interrupt
9700 * context. This function also can be called from other thread which
9701 * cleans up the SLI layer objects.
9702 * This function copy the contents of the response iocb to the
9703 * response iocb memory object provided by the caller of
9704 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9705 * sleeps for the iocb completion.
9708 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
9709 struct lpfc_iocbq
*cmdiocbq
,
9710 struct lpfc_iocbq
*rspiocbq
)
9712 wait_queue_head_t
*pdone_q
;
9713 unsigned long iflags
;
9714 struct lpfc_scsi_buf
*lpfc_cmd
;
9716 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9717 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
9718 if (cmdiocbq
->context2
&& rspiocbq
)
9719 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
9720 &rspiocbq
->iocb
, sizeof(IOCB_t
));
9722 /* Set the exchange busy flag for task management commands */
9723 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
9724 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
9725 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
9727 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
9730 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
9733 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9738 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9739 * @phba: Pointer to HBA context object..
9740 * @piocbq: Pointer to command iocb.
9741 * @flag: Flag to test.
9743 * This routine grabs the hbalock and then test the iocb_flag to
9744 * see if the passed in flag is set.
9747 * 0 if flag is not set.
9750 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
9751 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
9753 unsigned long iflags
;
9756 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9757 ret
= piocbq
->iocb_flag
& flag
;
9758 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9764 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9765 * @phba: Pointer to HBA context object..
9766 * @pring: Pointer to sli ring.
9767 * @piocb: Pointer to command iocb.
9768 * @prspiocbq: Pointer to response iocb.
9769 * @timeout: Timeout in number of seconds.
9771 * This function issues the iocb to firmware and waits for the
9772 * iocb to complete. If the iocb command is not
9773 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9774 * Caller should not free the iocb resources if this function
9775 * returns IOCB_TIMEDOUT.
9776 * The function waits for the iocb completion using an
9777 * non-interruptible wait.
9778 * This function will sleep while waiting for iocb completion.
9779 * So, this function should not be called from any context which
9780 * does not allow sleeping. Due to the same reason, this function
9781 * cannot be called with interrupt disabled.
9782 * This function assumes that the iocb completions occur while
9783 * this function sleep. So, this function cannot be called from
9784 * the thread which process iocb completion for this ring.
9785 * This function clears the iocb_flag of the iocb object before
9786 * issuing the iocb and the iocb completion handler sets this
9787 * flag and wakes this thread when the iocb completes.
9788 * The contents of the response iocb will be copied to prspiocbq
9789 * by the completion handler when the command completes.
9790 * This function returns IOCB_SUCCESS when success.
9791 * This function is called with no lock held.
9794 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
9795 uint32_t ring_number
,
9796 struct lpfc_iocbq
*piocb
,
9797 struct lpfc_iocbq
*prspiocbq
,
9800 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9801 long timeleft
, timeout_req
= 0;
9802 int retval
= IOCB_SUCCESS
;
9804 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9806 * If the caller has provided a response iocbq buffer, then context2
9807 * is NULL or its an error.
9810 if (piocb
->context2
)
9812 piocb
->context2
= prspiocbq
;
9815 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
9816 piocb
->context_un
.wait_queue
= &done_q
;
9817 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
9819 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9820 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9822 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
9823 writel(creg_val
, phba
->HCregaddr
);
9824 readl(phba
->HCregaddr
); /* flush */
9827 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
9829 if (retval
== IOCB_SUCCESS
) {
9830 timeout_req
= timeout
* HZ
;
9831 timeleft
= wait_event_timeout(done_q
,
9832 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
9835 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
9836 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9837 "0331 IOCB wake signaled\n");
9838 } else if (timeleft
== 0) {
9839 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9840 "0338 IOCB wait timeout error - no "
9841 "wake response Data x%x\n", timeout
);
9842 retval
= IOCB_TIMEDOUT
;
9844 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9845 "0330 IOCB wake NOT set, "
9847 timeout
, (timeleft
/ jiffies
));
9848 retval
= IOCB_TIMEDOUT
;
9850 } else if (retval
== IOCB_BUSY
) {
9851 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9852 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
9853 phba
->iocb_cnt
, pring
->txq_cnt
, pring
->txcmplq_cnt
);
9856 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9857 "0332 IOCB wait issue failed, Data x%x\n",
9859 retval
= IOCB_ERROR
;
9862 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9863 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9865 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
9866 writel(creg_val
, phba
->HCregaddr
);
9867 readl(phba
->HCregaddr
); /* flush */
9871 piocb
->context2
= NULL
;
9873 piocb
->context_un
.wait_queue
= NULL
;
9874 piocb
->iocb_cmpl
= NULL
;
9879 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
9880 * @phba: Pointer to HBA context object.
9881 * @pmboxq: Pointer to driver mailbox object.
9882 * @timeout: Timeout in number of seconds.
9884 * This function issues the mailbox to firmware and waits for the
9885 * mailbox command to complete. If the mailbox command is not
9886 * completed within timeout seconds, it returns MBX_TIMEOUT.
9887 * The function waits for the mailbox completion using an
9888 * interruptible wait. If the thread is woken up due to a
9889 * signal, MBX_TIMEOUT error is returned to the caller. Caller
9890 * should not free the mailbox resources, if this function returns
9892 * This function will sleep while waiting for mailbox completion.
9893 * So, this function should not be called from any context which
9894 * does not allow sleeping. Due to the same reason, this function
9895 * cannot be called with interrupt disabled.
9896 * This function assumes that the mailbox completion occurs while
9897 * this function sleep. So, this function cannot be called from
9898 * the worker thread which processes mailbox completion.
9899 * This function is called in the context of HBA management
9901 * This function returns MBX_SUCCESS when successful.
9902 * This function is called with no lock held.
9905 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
9908 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9912 /* The caller must leave context1 empty. */
9913 if (pmboxq
->context1
)
9914 return MBX_NOT_FINISHED
;
9916 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
9917 /* setup wake call as IOCB callback */
9918 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
9919 /* setup context field to pass wait_queue pointer to wake function */
9920 pmboxq
->context1
= &done_q
;
9922 /* now issue the command */
9923 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
9924 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
9925 wait_event_interruptible_timeout(done_q
,
9926 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
9929 spin_lock_irqsave(&phba
->hbalock
, flag
);
9930 pmboxq
->context1
= NULL
;
9932 * if LPFC_MBX_WAKE flag is set the mailbox is completed
9933 * else do not free the resources.
9935 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
9936 retval
= MBX_SUCCESS
;
9937 lpfc_sli4_swap_str(phba
, pmboxq
);
9939 retval
= MBX_TIMEOUT
;
9940 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
9942 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
9949 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
9950 * @phba: Pointer to HBA context.
9952 * This function is called to shutdown the driver's mailbox sub-system.
9953 * It first marks the mailbox sub-system is in a block state to prevent
9954 * the asynchronous mailbox command from issued off the pending mailbox
9955 * command queue. If the mailbox command sub-system shutdown is due to
9956 * HBA error conditions such as EEH or ERATT, this routine shall invoke
9957 * the mailbox sub-system flush routine to forcefully bring down the
9958 * mailbox sub-system. Otherwise, if it is due to normal condition (such
9959 * as with offline or HBA function reset), this routine will wait for the
9960 * outstanding mailbox command to complete before invoking the mailbox
9961 * sub-system flush routine to gracefully bring down mailbox sub-system.
9964 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
9966 struct lpfc_sli
*psli
= &phba
->sli
;
9967 unsigned long timeout
;
9969 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
9971 spin_lock_irq(&phba
->hbalock
);
9972 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
9974 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
9975 /* Determine how long we might wait for the active mailbox
9976 * command to be gracefully completed by firmware.
9978 if (phba
->sli
.mbox_active
)
9979 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
9980 phba
->sli
.mbox_active
) *
9982 spin_unlock_irq(&phba
->hbalock
);
9984 while (phba
->sli
.mbox_active
) {
9985 /* Check active mailbox complete status every 2ms */
9987 if (time_after(jiffies
, timeout
))
9988 /* Timeout, let the mailbox flush routine to
9989 * forcefully release active mailbox command
9994 spin_unlock_irq(&phba
->hbalock
);
9996 lpfc_sli_mbox_sys_flush(phba
);
10000 * lpfc_sli_eratt_read - read sli-3 error attention events
10001 * @phba: Pointer to HBA context.
10003 * This function is called to read the SLI3 device error attention registers
10004 * for possible error attention events. The caller must hold the hostlock
10005 * with spin_lock_irq().
10007 * This function returns 1 when there is Error Attention in the Host Attention
10008 * Register and returns 0 otherwise.
10011 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10015 /* Read chip Host Attention (HA) register */
10016 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10019 if (ha_copy
& HA_ERATT
) {
10020 /* Read host status register to retrieve error event */
10021 if (lpfc_sli_read_hs(phba
))
10024 /* Check if there is a deferred error condition is active */
10025 if ((HS_FFER1
& phba
->work_hs
) &&
10026 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10027 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10028 phba
->hba_flag
|= DEFER_ERATT
;
10029 /* Clear all interrupt enable conditions */
10030 writel(0, phba
->HCregaddr
);
10031 readl(phba
->HCregaddr
);
10034 /* Set the driver HA work bitmap */
10035 phba
->work_ha
|= HA_ERATT
;
10036 /* Indicate polling handles this ERATT */
10037 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10043 /* Set the driver HS work bitmap */
10044 phba
->work_hs
|= UNPLUG_ERR
;
10045 /* Set the driver HA work bitmap */
10046 phba
->work_ha
|= HA_ERATT
;
10047 /* Indicate polling handles this ERATT */
10048 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10053 * lpfc_sli4_eratt_read - read sli-4 error attention events
10054 * @phba: Pointer to HBA context.
10056 * This function is called to read the SLI4 device error attention registers
10057 * for possible error attention events. The caller must hold the hostlock
10058 * with spin_lock_irq().
10060 * This function returns 1 when there is Error Attention in the Host Attention
10061 * Register and returns 0 otherwise.
10064 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10066 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10067 uint32_t if_type
, portsmphr
;
10068 struct lpfc_register portstat_reg
;
10071 * For now, use the SLI4 device internal unrecoverable error
10072 * registers for error attention. This can be changed later.
10074 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10076 case LPFC_SLI_INTF_IF_TYPE_0
:
10077 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10079 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10081 phba
->work_hs
|= UNPLUG_ERR
;
10082 phba
->work_ha
|= HA_ERATT
;
10083 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10086 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10087 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10088 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10089 "1423 HBA Unrecoverable error: "
10090 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10091 "ue_mask_lo_reg=0x%x, "
10092 "ue_mask_hi_reg=0x%x\n",
10093 uerr_sta_lo
, uerr_sta_hi
,
10094 phba
->sli4_hba
.ue_mask_lo
,
10095 phba
->sli4_hba
.ue_mask_hi
);
10096 phba
->work_status
[0] = uerr_sta_lo
;
10097 phba
->work_status
[1] = uerr_sta_hi
;
10098 phba
->work_ha
|= HA_ERATT
;
10099 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10103 case LPFC_SLI_INTF_IF_TYPE_2
:
10104 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10105 &portstat_reg
.word0
) ||
10106 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10108 phba
->work_hs
|= UNPLUG_ERR
;
10109 phba
->work_ha
|= HA_ERATT
;
10110 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10113 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10114 phba
->work_status
[0] =
10115 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10116 phba
->work_status
[1] =
10117 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10118 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10119 "2885 Port Status Event: "
10120 "port status reg 0x%x, "
10121 "port smphr reg 0x%x, "
10122 "error 1=0x%x, error 2=0x%x\n",
10123 portstat_reg
.word0
,
10125 phba
->work_status
[0],
10126 phba
->work_status
[1]);
10127 phba
->work_ha
|= HA_ERATT
;
10128 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10132 case LPFC_SLI_INTF_IF_TYPE_1
:
10134 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10135 "2886 HBA Error Attention on unsupported "
10136 "if type %d.", if_type
);
10144 * lpfc_sli_check_eratt - check error attention events
10145 * @phba: Pointer to HBA context.
10147 * This function is called from timer soft interrupt context to check HBA's
10148 * error attention register bit for error attention events.
10150 * This function returns 1 when there is Error Attention in the Host Attention
10151 * Register and returns 0 otherwise.
10154 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10158 /* If somebody is waiting to handle an eratt, don't process it
10159 * here. The brdkill function will do this.
10161 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10164 /* Check if interrupt handler handles this ERATT */
10165 spin_lock_irq(&phba
->hbalock
);
10166 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10167 /* Interrupt handler has handled ERATT */
10168 spin_unlock_irq(&phba
->hbalock
);
10173 * If there is deferred error attention, do not check for error
10176 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10177 spin_unlock_irq(&phba
->hbalock
);
10181 /* If PCI channel is offline, don't process it */
10182 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10183 spin_unlock_irq(&phba
->hbalock
);
10187 switch (phba
->sli_rev
) {
10188 case LPFC_SLI_REV2
:
10189 case LPFC_SLI_REV3
:
10190 /* Read chip Host Attention (HA) register */
10191 ha_copy
= lpfc_sli_eratt_read(phba
);
10193 case LPFC_SLI_REV4
:
10194 /* Read device Uncoverable Error (UERR) registers */
10195 ha_copy
= lpfc_sli4_eratt_read(phba
);
10198 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10199 "0299 Invalid SLI revision (%d)\n",
10204 spin_unlock_irq(&phba
->hbalock
);
10210 * lpfc_intr_state_check - Check device state for interrupt handling
10211 * @phba: Pointer to HBA context.
10213 * This inline routine checks whether a device or its PCI slot is in a state
10214 * that the interrupt should be handled.
10216 * This function returns 0 if the device or the PCI slot is in a state that
10217 * interrupt should be handled, otherwise -EIO.
10220 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10222 /* If the pci channel is offline, ignore all the interrupts */
10223 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10226 /* Update device level interrupt statistics */
10227 phba
->sli
.slistat
.sli_intr
++;
10229 /* Ignore all interrupts during initialization. */
10230 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10237 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10238 * @irq: Interrupt number.
10239 * @dev_id: The device context pointer.
10241 * This function is directly called from the PCI layer as an interrupt
10242 * service routine when device with SLI-3 interface spec is enabled with
10243 * MSI-X multi-message interrupt mode and there are slow-path events in
10244 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10245 * interrupt mode, this function is called as part of the device-level
10246 * interrupt handler. When the PCI slot is in error recovery or the HBA
10247 * is undergoing initialization, the interrupt handler will not process
10248 * the interrupt. The link attention and ELS ring attention events are
10249 * handled by the worker thread. The interrupt handler signals the worker
10250 * thread and returns for these events. This function is called without
10251 * any lock held. It gets the hbalock to access and update SLI data
10254 * This function returns IRQ_HANDLED when interrupt is handled else it
10255 * returns IRQ_NONE.
10258 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10260 struct lpfc_hba
*phba
;
10261 uint32_t ha_copy
, hc_copy
;
10262 uint32_t work_ha_copy
;
10263 unsigned long status
;
10264 unsigned long iflag
;
10267 MAILBOX_t
*mbox
, *pmbox
;
10268 struct lpfc_vport
*vport
;
10269 struct lpfc_nodelist
*ndlp
;
10270 struct lpfc_dmabuf
*mp
;
10275 * Get the driver's phba structure from the dev_id and
10276 * assume the HBA is not interrupting.
10278 phba
= (struct lpfc_hba
*)dev_id
;
10280 if (unlikely(!phba
))
10284 * Stuff needs to be attented to when this function is invoked as an
10285 * individual interrupt handler in MSI-X multi-message interrupt mode
10287 if (phba
->intr_type
== MSIX
) {
10288 /* Check device state for handling interrupt */
10289 if (lpfc_intr_state_check(phba
))
10291 /* Need to read HA REG for slow-path events */
10292 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10293 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10295 /* If somebody is waiting to handle an eratt don't process it
10296 * here. The brdkill function will do this.
10298 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10299 ha_copy
&= ~HA_ERATT
;
10300 /* Check the need for handling ERATT in interrupt handler */
10301 if (ha_copy
& HA_ERATT
) {
10302 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10303 /* ERATT polling has handled ERATT */
10304 ha_copy
&= ~HA_ERATT
;
10306 /* Indicate interrupt handler handles ERATT */
10307 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10311 * If there is deferred error attention, do not check for any
10314 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10315 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10319 /* Clear up only attention source related to slow-path */
10320 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10323 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10324 HC_LAINT_ENA
| HC_ERINT_ENA
),
10326 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10328 writel(hc_copy
, phba
->HCregaddr
);
10329 readl(phba
->HAregaddr
); /* flush */
10330 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10332 ha_copy
= phba
->ha_copy
;
10334 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10336 if (work_ha_copy
) {
10337 if (work_ha_copy
& HA_LATT
) {
10338 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10340 * Turn off Link Attention interrupts
10341 * until CLEAR_LA done
10343 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10344 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10345 if (lpfc_readl(phba
->HCregaddr
, &control
))
10347 control
&= ~HC_LAINT_ENA
;
10348 writel(control
, phba
->HCregaddr
);
10349 readl(phba
->HCregaddr
); /* flush */
10350 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10353 work_ha_copy
&= ~HA_LATT
;
10356 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10358 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10359 * the only slow ring.
10361 status
= (work_ha_copy
&
10362 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10363 status
>>= (4*LPFC_ELS_RING
);
10364 if (status
& HA_RXMASK
) {
10365 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10366 if (lpfc_readl(phba
->HCregaddr
, &control
))
10369 lpfc_debugfs_slow_ring_trc(phba
,
10370 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10372 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10374 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10375 lpfc_debugfs_slow_ring_trc(phba
,
10376 "ISR Disable ring:"
10377 "pwork:x%x hawork:x%x wait:x%x",
10378 phba
->work_ha
, work_ha_copy
,
10379 (uint32_t)((unsigned long)
10380 &phba
->work_waitq
));
10383 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10384 writel(control
, phba
->HCregaddr
);
10385 readl(phba
->HCregaddr
); /* flush */
10388 lpfc_debugfs_slow_ring_trc(phba
,
10389 "ISR slow ring: pwork:"
10390 "x%x hawork:x%x wait:x%x",
10391 phba
->work_ha
, work_ha_copy
,
10392 (uint32_t)((unsigned long)
10393 &phba
->work_waitq
));
10395 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10398 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10399 if (work_ha_copy
& HA_ERATT
) {
10400 if (lpfc_sli_read_hs(phba
))
10403 * Check if there is a deferred error condition
10406 if ((HS_FFER1
& phba
->work_hs
) &&
10407 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10408 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10410 phba
->hba_flag
|= DEFER_ERATT
;
10411 /* Clear all interrupt enable conditions */
10412 writel(0, phba
->HCregaddr
);
10413 readl(phba
->HCregaddr
);
10417 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10418 pmb
= phba
->sli
.mbox_active
;
10419 pmbox
= &pmb
->u
.mb
;
10421 vport
= pmb
->vport
;
10423 /* First check out the status word */
10424 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10425 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10426 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10428 * Stray Mailbox Interrupt, mbxCommand <cmd>
10429 * mbxStatus <status>
10431 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10433 "(%d):0304 Stray Mailbox "
10434 "Interrupt mbxCommand x%x "
10436 (vport
? vport
->vpi
: 0),
10439 /* clear mailbox attention bit */
10440 work_ha_copy
&= ~HA_MBATT
;
10442 phba
->sli
.mbox_active
= NULL
;
10443 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10444 phba
->last_completion_time
= jiffies
;
10445 del_timer(&phba
->sli
.mbox_tmo
);
10446 if (pmb
->mbox_cmpl
) {
10447 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10449 if (pmb
->out_ext_byte_len
&&
10451 lpfc_sli_pcimem_bcopy(
10454 pmb
->out_ext_byte_len
);
10456 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10457 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10459 lpfc_debugfs_disc_trc(vport
,
10460 LPFC_DISC_TRC_MBOX_VPORT
,
10461 "MBOX dflt rpi: : "
10462 "status:x%x rpi:x%x",
10463 (uint32_t)pmbox
->mbxStatus
,
10464 pmbox
->un
.varWords
[0], 0);
10466 if (!pmbox
->mbxStatus
) {
10467 mp
= (struct lpfc_dmabuf
*)
10469 ndlp
= (struct lpfc_nodelist
*)
10472 /* Reg_LOGIN of dflt RPI was
10473 * successful. new lets get
10474 * rid of the RPI using the
10475 * same mbox buffer.
10477 lpfc_unreg_login(phba
,
10479 pmbox
->un
.varWords
[0],
10482 lpfc_mbx_cmpl_dflt_rpi
;
10483 pmb
->context1
= mp
;
10484 pmb
->context2
= ndlp
;
10485 pmb
->vport
= vport
;
10486 rc
= lpfc_sli_issue_mbox(phba
,
10489 if (rc
!= MBX_BUSY
)
10490 lpfc_printf_log(phba
,
10492 LOG_MBOX
| LOG_SLI
,
10493 "0350 rc should have"
10494 "been MBX_BUSY\n");
10495 if (rc
!= MBX_NOT_FINISHED
)
10496 goto send_current_mbox
;
10500 &phba
->pport
->work_port_lock
,
10502 phba
->pport
->work_port_events
&=
10504 spin_unlock_irqrestore(
10505 &phba
->pport
->work_port_lock
,
10507 lpfc_mbox_cmpl_put(phba
, pmb
);
10510 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10512 if ((work_ha_copy
& HA_MBATT
) &&
10513 (phba
->sli
.mbox_active
== NULL
)) {
10515 /* Process next mailbox command if there is one */
10517 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10519 } while (rc
== MBX_NOT_FINISHED
);
10520 if (rc
!= MBX_SUCCESS
)
10521 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10522 LOG_SLI
, "0349 rc should be "
10526 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10527 phba
->work_ha
|= work_ha_copy
;
10528 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10529 lpfc_worker_wake_up(phba
);
10531 return IRQ_HANDLED
;
10533 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10534 return IRQ_HANDLED
;
10536 } /* lpfc_sli_sp_intr_handler */
10539 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10540 * @irq: Interrupt number.
10541 * @dev_id: The device context pointer.
10543 * This function is directly called from the PCI layer as an interrupt
10544 * service routine when device with SLI-3 interface spec is enabled with
10545 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10546 * ring event in the HBA. However, when the device is enabled with either
10547 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10548 * device-level interrupt handler. When the PCI slot is in error recovery
10549 * or the HBA is undergoing initialization, the interrupt handler will not
10550 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10551 * the intrrupt context. This function is called without any lock held.
10552 * It gets the hbalock to access and update SLI data structures.
10554 * This function returns IRQ_HANDLED when interrupt is handled else it
10555 * returns IRQ_NONE.
10558 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10560 struct lpfc_hba
*phba
;
10562 unsigned long status
;
10563 unsigned long iflag
;
10565 /* Get the driver's phba structure from the dev_id and
10566 * assume the HBA is not interrupting.
10568 phba
= (struct lpfc_hba
*) dev_id
;
10570 if (unlikely(!phba
))
10574 * Stuff needs to be attented to when this function is invoked as an
10575 * individual interrupt handler in MSI-X multi-message interrupt mode
10577 if (phba
->intr_type
== MSIX
) {
10578 /* Check device state for handling interrupt */
10579 if (lpfc_intr_state_check(phba
))
10581 /* Need to read HA REG for FCP ring and other ring events */
10582 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10583 return IRQ_HANDLED
;
10584 /* Clear up only attention source related to fast-path */
10585 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10587 * If there is deferred error attention, do not check for
10590 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10591 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10594 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10596 readl(phba
->HAregaddr
); /* flush */
10597 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10599 ha_copy
= phba
->ha_copy
;
10602 * Process all events on FCP ring. Take the optimized path for FCP IO.
10604 ha_copy
&= ~(phba
->work_ha_mask
);
10606 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10607 status
>>= (4*LPFC_FCP_RING
);
10608 if (status
& HA_RXMASK
)
10609 lpfc_sli_handle_fast_ring_event(phba
,
10610 &phba
->sli
.ring
[LPFC_FCP_RING
],
10613 if (phba
->cfg_multi_ring_support
== 2) {
10615 * Process all events on extra ring. Take the optimized path
10616 * for extra ring IO.
10618 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10619 status
>>= (4*LPFC_EXTRA_RING
);
10620 if (status
& HA_RXMASK
) {
10621 lpfc_sli_handle_fast_ring_event(phba
,
10622 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
10626 return IRQ_HANDLED
;
10627 } /* lpfc_sli_fp_intr_handler */
10630 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10631 * @irq: Interrupt number.
10632 * @dev_id: The device context pointer.
10634 * This function is the HBA device-level interrupt handler to device with
10635 * SLI-3 interface spec, called from the PCI layer when either MSI or
10636 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10637 * requires driver attention. This function invokes the slow-path interrupt
10638 * attention handling function and fast-path interrupt attention handling
10639 * function in turn to process the relevant HBA attention events. This
10640 * function is called without any lock held. It gets the hbalock to access
10641 * and update SLI data structures.
10643 * This function returns IRQ_HANDLED when interrupt is handled, else it
10644 * returns IRQ_NONE.
10647 lpfc_sli_intr_handler(int irq
, void *dev_id
)
10649 struct lpfc_hba
*phba
;
10650 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10651 unsigned long status1
, status2
;
10655 * Get the driver's phba structure from the dev_id and
10656 * assume the HBA is not interrupting.
10658 phba
= (struct lpfc_hba
*) dev_id
;
10660 if (unlikely(!phba
))
10663 /* Check device state for handling interrupt */
10664 if (lpfc_intr_state_check(phba
))
10667 spin_lock(&phba
->hbalock
);
10668 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
10669 spin_unlock(&phba
->hbalock
);
10670 return IRQ_HANDLED
;
10673 if (unlikely(!phba
->ha_copy
)) {
10674 spin_unlock(&phba
->hbalock
);
10676 } else if (phba
->ha_copy
& HA_ERATT
) {
10677 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10678 /* ERATT polling has handled ERATT */
10679 phba
->ha_copy
&= ~HA_ERATT
;
10681 /* Indicate interrupt handler handles ERATT */
10682 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10686 * If there is deferred error attention, do not check for any interrupt.
10688 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10689 spin_unlock(&phba
->hbalock
);
10693 /* Clear attention sources except link and error attentions */
10694 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
10695 spin_unlock(&phba
->hbalock
);
10696 return IRQ_HANDLED
;
10698 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
10699 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
10701 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
10702 writel(hc_copy
, phba
->HCregaddr
);
10703 readl(phba
->HAregaddr
); /* flush */
10704 spin_unlock(&phba
->hbalock
);
10707 * Invokes slow-path host attention interrupt handling as appropriate.
10710 /* status of events with mailbox and link attention */
10711 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
10713 /* status of events with ELS ring */
10714 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10715 status2
>>= (4*LPFC_ELS_RING
);
10717 if (status1
|| (status2
& HA_RXMASK
))
10718 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
10720 sp_irq_rc
= IRQ_NONE
;
10723 * Invoke fast-path host attention interrupt handling as appropriate.
10726 /* status of events with FCP ring */
10727 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10728 status1
>>= (4*LPFC_FCP_RING
);
10730 /* status of events with extra ring */
10731 if (phba
->cfg_multi_ring_support
== 2) {
10732 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10733 status2
>>= (4*LPFC_EXTRA_RING
);
10737 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
10738 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
10740 fp_irq_rc
= IRQ_NONE
;
10742 /* Return device-level interrupt handling status */
10743 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
10744 } /* lpfc_sli_intr_handler */
10747 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10748 * @phba: pointer to lpfc hba data structure.
10750 * This routine is invoked by the worker thread to process all the pending
10751 * SLI4 FCP abort XRI events.
10753 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
10755 struct lpfc_cq_event
*cq_event
;
10757 /* First, declare the fcp xri abort event has been handled */
10758 spin_lock_irq(&phba
->hbalock
);
10759 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
10760 spin_unlock_irq(&phba
->hbalock
);
10761 /* Now, handle all the fcp xri abort events */
10762 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
10763 /* Get the first event from the head of the event queue */
10764 spin_lock_irq(&phba
->hbalock
);
10765 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10766 cq_event
, struct lpfc_cq_event
, list
);
10767 spin_unlock_irq(&phba
->hbalock
);
10768 /* Notify aborted XRI for FCP work queue */
10769 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10770 /* Free the event processed back to the free pool */
10771 lpfc_sli4_cq_event_release(phba
, cq_event
);
10776 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10777 * @phba: pointer to lpfc hba data structure.
10779 * This routine is invoked by the worker thread to process all the pending
10780 * SLI4 els abort xri events.
10782 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
10784 struct lpfc_cq_event
*cq_event
;
10786 /* First, declare the els xri abort event has been handled */
10787 spin_lock_irq(&phba
->hbalock
);
10788 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
10789 spin_unlock_irq(&phba
->hbalock
);
10790 /* Now, handle all the els xri abort events */
10791 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
10792 /* Get the first event from the head of the event queue */
10793 spin_lock_irq(&phba
->hbalock
);
10794 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10795 cq_event
, struct lpfc_cq_event
, list
);
10796 spin_unlock_irq(&phba
->hbalock
);
10797 /* Notify aborted XRI for ELS work queue */
10798 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10799 /* Free the event processed back to the free pool */
10800 lpfc_sli4_cq_event_release(phba
, cq_event
);
10805 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10806 * @phba: pointer to lpfc hba data structure
10807 * @pIocbIn: pointer to the rspiocbq
10808 * @pIocbOut: pointer to the cmdiocbq
10809 * @wcqe: pointer to the complete wcqe
10811 * This routine transfers the fields of a command iocbq to a response iocbq
10812 * by copying all the IOCB fields from command iocbq and transferring the
10813 * completion status information from the complete wcqe.
10816 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
10817 struct lpfc_iocbq
*pIocbIn
,
10818 struct lpfc_iocbq
*pIocbOut
,
10819 struct lpfc_wcqe_complete
*wcqe
)
10821 unsigned long iflags
;
10823 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
10825 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
10826 sizeof(struct lpfc_iocbq
) - offset
);
10827 /* Map WCQE parameters into irspiocb parameters */
10828 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
10829 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
10830 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
10831 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
10832 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
10833 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
10834 wcqe
->total_data_placed
;
10836 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10838 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10839 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
10842 /* Convert BG errors for completion status */
10843 if (status
== CQE_STATUS_DI_ERROR
) {
10844 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
10846 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
10847 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
10849 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
10851 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
10852 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
10853 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10854 BGS_GUARD_ERR_MASK
;
10855 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
10856 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10857 BGS_APPTAG_ERR_MASK
;
10858 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
10859 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10860 BGS_REFTAG_ERR_MASK
;
10862 /* Check to see if there was any good data before the error */
10863 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
10864 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10865 BGS_HI_WATER_MARK_PRESENT_MASK
;
10866 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
10867 wcqe
->total_data_placed
;
10871 * Set ALL the error bits to indicate we don't know what
10872 * type of error it is.
10874 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
10875 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
10876 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
10877 BGS_GUARD_ERR_MASK
);
10880 /* Pick up HBA exchange busy condition */
10881 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
10882 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10883 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
10884 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10889 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
10890 * @phba: Pointer to HBA context object.
10891 * @wcqe: Pointer to work-queue completion queue entry.
10893 * This routine handles an ELS work-queue completion event and construct
10894 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
10895 * discovery engine to handle.
10897 * Return: Pointer to the receive IOCBQ, NULL otherwise.
10899 static struct lpfc_iocbq
*
10900 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
10901 struct lpfc_iocbq
*irspiocbq
)
10903 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10904 struct lpfc_iocbq
*cmdiocbq
;
10905 struct lpfc_wcqe_complete
*wcqe
;
10906 unsigned long iflags
;
10908 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
10909 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10910 pring
->stats
.iocb_event
++;
10911 /* Look up the ELS command IOCB and create pseudo response IOCB */
10912 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
10913 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
10914 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10916 if (unlikely(!cmdiocbq
)) {
10917 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10918 "0386 ELS complete with no corresponding "
10919 "cmdiocb: iotag (%d)\n",
10920 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
10921 lpfc_sli_release_iocbq(phba
, irspiocbq
);
10925 /* Fake the irspiocbq and copy necessary response information */
10926 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
10932 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
10933 * @phba: Pointer to HBA context object.
10934 * @cqe: Pointer to mailbox completion queue entry.
10936 * This routine process a mailbox completion queue entry with asynchrous
10939 * Return: true if work posted to worker thread, otherwise false.
10942 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
10944 struct lpfc_cq_event
*cq_event
;
10945 unsigned long iflags
;
10947 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10948 "0392 Async Event: word0:x%x, word1:x%x, "
10949 "word2:x%x, word3:x%x\n", mcqe
->word0
,
10950 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
10952 /* Allocate a new internal CQ_EVENT entry */
10953 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
10955 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10956 "0394 Failed to allocate CQ_EVENT entry\n");
10960 /* Move the CQE into an asynchronous event entry */
10961 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
10962 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10963 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
10964 /* Set the async event flag */
10965 phba
->hba_flag
|= ASYNC_EVENT
;
10966 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10972 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
10973 * @phba: Pointer to HBA context object.
10974 * @cqe: Pointer to mailbox completion queue entry.
10976 * This routine process a mailbox completion queue entry with mailbox
10977 * completion event.
10979 * Return: true if work posted to worker thread, otherwise false.
10982 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
10984 uint32_t mcqe_status
;
10985 MAILBOX_t
*mbox
, *pmbox
;
10986 struct lpfc_mqe
*mqe
;
10987 struct lpfc_vport
*vport
;
10988 struct lpfc_nodelist
*ndlp
;
10989 struct lpfc_dmabuf
*mp
;
10990 unsigned long iflags
;
10992 bool workposted
= false;
10995 /* If not a mailbox complete MCQE, out by checking mailbox consume */
10996 if (!bf_get(lpfc_trailer_completed
, mcqe
))
10997 goto out_no_mqe_complete
;
10999 /* Get the reference to the active mbox command */
11000 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11001 pmb
= phba
->sli
.mbox_active
;
11002 if (unlikely(!pmb
)) {
11003 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11004 "1832 No pending MBOX command to handle\n");
11005 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11006 goto out_no_mqe_complete
;
11008 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11010 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11012 vport
= pmb
->vport
;
11014 /* Reset heartbeat timer */
11015 phba
->last_completion_time
= jiffies
;
11016 del_timer(&phba
->sli
.mbox_tmo
);
11018 /* Move mbox data to caller's mailbox region, do endian swapping */
11019 if (pmb
->mbox_cmpl
&& mbox
)
11020 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11023 * For mcqe errors, conditionally move a modified error code to
11024 * the mbox so that the error will not be missed.
11026 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11027 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11028 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11029 bf_set(lpfc_mqe_status
, mqe
,
11030 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11032 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11033 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11034 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11035 "MBOX dflt rpi: status:x%x rpi:x%x",
11037 pmbox
->un
.varWords
[0], 0);
11038 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11039 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11040 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11041 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11042 * RID of the PPI using the same mbox buffer.
11044 lpfc_unreg_login(phba
, vport
->vpi
,
11045 pmbox
->un
.varWords
[0], pmb
);
11046 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11047 pmb
->context1
= mp
;
11048 pmb
->context2
= ndlp
;
11049 pmb
->vport
= vport
;
11050 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11051 if (rc
!= MBX_BUSY
)
11052 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11053 LOG_SLI
, "0385 rc should "
11054 "have been MBX_BUSY\n");
11055 if (rc
!= MBX_NOT_FINISHED
)
11056 goto send_current_mbox
;
11059 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11060 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11061 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11063 /* There is mailbox completion work to do */
11064 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11065 __lpfc_mbox_cmpl_put(phba
, pmb
);
11066 phba
->work_ha
|= HA_MBATT
;
11067 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11071 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11072 /* Release the mailbox command posting token */
11073 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11074 /* Setting active mailbox pointer need to be in sync to flag clear */
11075 phba
->sli
.mbox_active
= NULL
;
11076 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11077 /* Wake up worker thread to post the next pending mailbox command */
11078 lpfc_worker_wake_up(phba
);
11079 out_no_mqe_complete
:
11080 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11081 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
11086 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11087 * @phba: Pointer to HBA context object.
11088 * @cqe: Pointer to mailbox completion queue entry.
11090 * This routine process a mailbox completion queue entry, it invokes the
11091 * proper mailbox complete handling or asynchrous event handling routine
11092 * according to the MCQE's async bit.
11094 * Return: true if work posted to worker thread, otherwise false.
11097 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
11099 struct lpfc_mcqe mcqe
;
11102 /* Copy the mailbox MCQE and convert endian order as needed */
11103 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
11105 /* Invoke the proper event handling routine */
11106 if (!bf_get(lpfc_trailer_async
, &mcqe
))
11107 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
11109 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
11114 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11115 * @phba: Pointer to HBA context object.
11116 * @wcqe: Pointer to work-queue completion queue entry.
11118 * This routine handles an ELS work-queue completion event.
11120 * Return: true if work posted to worker thread, otherwise false.
11123 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
11124 struct lpfc_wcqe_complete
*wcqe
)
11126 struct lpfc_iocbq
*irspiocbq
;
11127 unsigned long iflags
;
11128 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
11130 /* Get an irspiocbq for later ELS response processing use */
11131 irspiocbq
= lpfc_sli_get_iocbq(phba
);
11133 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11134 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11135 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
11136 pring
->txq_cnt
, phba
->iocb_cnt
,
11137 phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
,
11138 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
);
11142 /* Save off the slow-path queue event for work thread to process */
11143 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
11144 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11145 list_add_tail(&irspiocbq
->cq_event
.list
,
11146 &phba
->sli4_hba
.sp_queue_event
);
11147 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11148 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11154 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11155 * @phba: Pointer to HBA context object.
11156 * @wcqe: Pointer to work-queue completion queue entry.
11158 * This routine handles slow-path WQ entry comsumed event by invoking the
11159 * proper WQ release routine to the slow-path WQ.
11162 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
11163 struct lpfc_wcqe_release
*wcqe
)
11165 /* sanity check on queue memory */
11166 if (unlikely(!phba
->sli4_hba
.els_wq
))
11168 /* Check for the slow-path ELS work queue */
11169 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
11170 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
11171 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11173 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11174 "2579 Slow-path wqe consume event carries "
11175 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11176 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
11177 phba
->sli4_hba
.els_wq
->queue_id
);
11181 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11182 * @phba: Pointer to HBA context object.
11183 * @cq: Pointer to a WQ completion queue.
11184 * @wcqe: Pointer to work-queue completion queue entry.
11186 * This routine handles an XRI abort event.
11188 * Return: true if work posted to worker thread, otherwise false.
11191 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
11192 struct lpfc_queue
*cq
,
11193 struct sli4_wcqe_xri_aborted
*wcqe
)
11195 bool workposted
= false;
11196 struct lpfc_cq_event
*cq_event
;
11197 unsigned long iflags
;
11199 /* Allocate a new internal CQ_EVENT entry */
11200 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11202 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11203 "0602 Failed to allocate CQ_EVENT entry\n");
11207 /* Move the CQE into the proper xri abort event list */
11208 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11209 switch (cq
->subtype
) {
11211 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11212 list_add_tail(&cq_event
->list
,
11213 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11214 /* Set the fcp xri abort event flag */
11215 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11216 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11220 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11221 list_add_tail(&cq_event
->list
,
11222 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11223 /* Set the els xri abort event flag */
11224 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11225 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11229 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11230 "0603 Invalid work queue CQE subtype (x%x)\n",
11232 workposted
= false;
11239 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11240 * @phba: Pointer to HBA context object.
11241 * @rcqe: Pointer to receive-queue completion queue entry.
11243 * This routine process a receive-queue completion queue entry.
11245 * Return: true if work posted to worker thread, otherwise false.
11248 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11250 bool workposted
= false;
11251 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11252 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11253 struct hbq_dmabuf
*dma_buf
;
11254 uint32_t status
, rq_id
;
11255 unsigned long iflags
;
11257 /* sanity check on queue memory */
11258 if (unlikely(!hrq
) || unlikely(!drq
))
11261 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11262 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11264 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11265 if (rq_id
!= hrq
->queue_id
)
11268 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11270 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11271 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11272 "2537 Receive Frame Truncated!!\n");
11273 case FC_STATUS_RQ_SUCCESS
:
11274 lpfc_sli4_rq_release(hrq
, drq
);
11275 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11276 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11278 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11281 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11282 /* save off the frame for the word thread to process */
11283 list_add_tail(&dma_buf
->cq_event
.list
,
11284 &phba
->sli4_hba
.sp_queue_event
);
11285 /* Frame received */
11286 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11287 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11290 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11291 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11292 /* Post more buffers if possible */
11293 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11294 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11295 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11304 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11305 * @phba: Pointer to HBA context object.
11306 * @cq: Pointer to the completion queue.
11307 * @wcqe: Pointer to a completion queue entry.
11309 * This routine process a slow-path work-queue or receive queue completion queue
11312 * Return: true if work posted to worker thread, otherwise false.
11315 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11316 struct lpfc_cqe
*cqe
)
11318 struct lpfc_cqe cqevt
;
11319 bool workposted
= false;
11321 /* Copy the work queue CQE and convert endian order if needed */
11322 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11324 /* Check and process for different type of WCQE and dispatch */
11325 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11326 case CQE_CODE_COMPL_WQE
:
11327 /* Process the WQ/RQ complete event */
11328 phba
->last_completion_time
= jiffies
;
11329 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
11330 (struct lpfc_wcqe_complete
*)&cqevt
);
11332 case CQE_CODE_RELEASE_WQE
:
11333 /* Process the WQ release event */
11334 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11335 (struct lpfc_wcqe_release
*)&cqevt
);
11337 case CQE_CODE_XRI_ABORTED
:
11338 /* Process the WQ XRI abort event */
11339 phba
->last_completion_time
= jiffies
;
11340 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11341 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11343 case CQE_CODE_RECEIVE
:
11344 case CQE_CODE_RECEIVE_V1
:
11345 /* Process the RQ event */
11346 phba
->last_completion_time
= jiffies
;
11347 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11348 (struct lpfc_rcqe
*)&cqevt
);
11351 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11352 "0388 Not a valid WCQE code: x%x\n",
11353 bf_get(lpfc_cqe_code
, &cqevt
));
11360 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11361 * @phba: Pointer to HBA context object.
11362 * @eqe: Pointer to fast-path event queue entry.
11364 * This routine process a event queue entry from the slow-path event queue.
11365 * It will check the MajorCode and MinorCode to determine this is for a
11366 * completion event on a completion queue, if not, an error shall be logged
11367 * and just return. Otherwise, it will get to the corresponding completion
11368 * queue and process all the entries on that completion queue, rearm the
11369 * completion queue, and then return.
11373 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
11375 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
11376 struct lpfc_cqe
*cqe
;
11377 bool workposted
= false;
11381 if (bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0) {
11382 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11383 "0359 Not a valid slow-path completion "
11384 "event: majorcode=x%x, minorcode=x%x\n",
11385 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11386 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11390 /* Get the reference to the corresponding CQ */
11391 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11393 /* Search for completion queue pointer matching this cqid */
11394 speq
= phba
->sli4_hba
.sp_eq
;
11395 /* sanity check on queue memory */
11396 if (unlikely(!speq
))
11398 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11399 if (childq
->queue_id
== cqid
) {
11404 if (unlikely(!cq
)) {
11405 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11406 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11407 "0365 Slow-path CQ identifier "
11408 "(%d) does not exist\n", cqid
);
11412 /* Process all the entries to the CQ */
11413 switch (cq
->type
) {
11415 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11416 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11417 if (!(++ecount
% cq
->entry_repost
))
11418 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11422 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11423 if (cq
->subtype
== LPFC_FCP
)
11424 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11427 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11429 if (!(++ecount
% cq
->entry_repost
))
11430 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11434 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11435 "0370 Invalid completion queue type (%d)\n",
11440 /* Catch the no cq entry condition, log an error */
11441 if (unlikely(ecount
== 0))
11442 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11443 "0371 No entry from the CQ: identifier "
11444 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11446 /* In any case, flash and re-arm the RCQ */
11447 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11449 /* wake up worker thread if there are works to be done */
11451 lpfc_worker_wake_up(phba
);
11455 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11456 * @eqe: Pointer to fast-path completion queue entry.
11458 * This routine process a fast-path work queue completion entry from fast-path
11459 * event queue for FCP command response completion.
11462 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
11463 struct lpfc_wcqe_complete
*wcqe
)
11465 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
11466 struct lpfc_iocbq
*cmdiocbq
;
11467 struct lpfc_iocbq irspiocbq
;
11468 unsigned long iflags
;
11470 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11471 pring
->stats
.iocb_event
++;
11472 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11474 /* Check for response status */
11475 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11476 /* If resource errors reported from HBA, reduce queue
11477 * depth of the SCSI device.
11479 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11480 IOSTAT_LOCAL_REJECT
) &&
11481 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
11482 phba
->lpfc_rampdown_queue_depth(phba
);
11484 /* Log the error status */
11485 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11486 "0373 FCP complete error: status=x%x, "
11487 "hw_status=x%x, total_data_specified=%d, "
11488 "parameter=x%x, word3=x%x\n",
11489 bf_get(lpfc_wcqe_c_status
, wcqe
),
11490 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11491 wcqe
->total_data_placed
, wcqe
->parameter
,
11495 /* Look up the FCP command IOCB and create pseudo response IOCB */
11496 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11497 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11498 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11499 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11500 if (unlikely(!cmdiocbq
)) {
11501 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11502 "0374 FCP complete with no corresponding "
11503 "cmdiocb: iotag (%d)\n",
11504 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11507 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11508 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11509 "0375 FCP cmdiocb not callback function "
11511 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11515 /* Fake the irspiocb and copy necessary response information */
11516 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11518 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11519 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11520 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11521 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11524 /* Pass the cmd_iocb and the rsp state to the upper layer */
11525 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11529 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11530 * @phba: Pointer to HBA context object.
11531 * @cq: Pointer to completion queue.
11532 * @wcqe: Pointer to work-queue completion queue entry.
11534 * This routine handles an fast-path WQ entry comsumed event by invoking the
11535 * proper WQ release routine to the slow-path WQ.
11538 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11539 struct lpfc_wcqe_release
*wcqe
)
11541 struct lpfc_queue
*childwq
;
11542 bool wqid_matched
= false;
11545 /* Check for fast-path FCP work queue release */
11546 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11547 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11548 if (childwq
->queue_id
== fcp_wqid
) {
11549 lpfc_sli4_wq_release(childwq
,
11550 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11551 wqid_matched
= true;
11555 /* Report warning log message if no match found */
11556 if (wqid_matched
!= true)
11557 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11558 "2580 Fast-path wqe consume event carries "
11559 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11563 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11564 * @cq: Pointer to the completion queue.
11565 * @eqe: Pointer to fast-path completion queue entry.
11567 * This routine process a fast-path work queue completion entry from fast-path
11568 * event queue for FCP command response completion.
11571 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11572 struct lpfc_cqe
*cqe
)
11574 struct lpfc_wcqe_release wcqe
;
11575 bool workposted
= false;
11577 /* Copy the work queue CQE and convert endian order if needed */
11578 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
11580 /* Check and process for different type of WCQE and dispatch */
11581 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
11582 case CQE_CODE_COMPL_WQE
:
11583 /* Process the WQ complete event */
11584 phba
->last_completion_time
= jiffies
;
11585 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
11586 (struct lpfc_wcqe_complete
*)&wcqe
);
11588 case CQE_CODE_RELEASE_WQE
:
11589 /* Process the WQ release event */
11590 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
11591 (struct lpfc_wcqe_release
*)&wcqe
);
11593 case CQE_CODE_XRI_ABORTED
:
11594 /* Process the WQ XRI abort event */
11595 phba
->last_completion_time
= jiffies
;
11596 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11597 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
11600 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11601 "0144 Not a valid WCQE code: x%x\n",
11602 bf_get(lpfc_wcqe_c_code
, &wcqe
));
11609 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
11610 * @phba: Pointer to HBA context object.
11611 * @eqe: Pointer to fast-path event queue entry.
11613 * This routine process a event queue entry from the fast-path event queue.
11614 * It will check the MajorCode and MinorCode to determine this is for a
11615 * completion event on a completion queue, if not, an error shall be logged
11616 * and just return. Otherwise, it will get to the corresponding completion
11617 * queue and process all the entries on the completion queue, rearm the
11618 * completion queue, and then return.
11621 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11622 uint32_t fcp_cqidx
)
11624 struct lpfc_queue
*cq
;
11625 struct lpfc_cqe
*cqe
;
11626 bool workposted
= false;
11630 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
11631 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11632 "0366 Not a valid fast-path completion "
11633 "event: majorcode=x%x, minorcode=x%x\n",
11634 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11635 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11639 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
11640 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11641 "3146 Fast-path completion queues "
11642 "does not exist\n");
11645 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
11646 if (unlikely(!cq
)) {
11647 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11648 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11649 "0367 Fast-path completion queue "
11650 "(%d) does not exist\n", fcp_cqidx
);
11654 /* Get the reference to the corresponding CQ */
11655 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11656 if (unlikely(cqid
!= cq
->queue_id
)) {
11657 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11658 "0368 Miss-matched fast-path completion "
11659 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11660 cqid
, cq
->queue_id
);
11664 /* Process all the entries to the CQ */
11665 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11666 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
11667 if (!(++ecount
% cq
->entry_repost
))
11668 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11671 /* Catch the no cq entry condition */
11672 if (unlikely(ecount
== 0))
11673 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11674 "0369 No entry from fast-path completion "
11675 "queue fcpcqid=%d\n", cq
->queue_id
);
11677 /* In any case, flash and re-arm the CQ */
11678 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11680 /* wake up worker thread if there are works to be done */
11682 lpfc_worker_wake_up(phba
);
11686 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
11688 struct lpfc_eqe
*eqe
;
11690 /* walk all the EQ entries and drop on the floor */
11691 while ((eqe
= lpfc_sli4_eq_get(eq
)))
11694 /* Clear and re-arm the EQ */
11695 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
11699 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
11700 * @irq: Interrupt number.
11701 * @dev_id: The device context pointer.
11703 * This function is directly called from the PCI layer as an interrupt
11704 * service routine when device with SLI-4 interface spec is enabled with
11705 * MSI-X multi-message interrupt mode and there are slow-path events in
11706 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11707 * interrupt mode, this function is called as part of the device-level
11708 * interrupt handler. When the PCI slot is in error recovery or the HBA is
11709 * undergoing initialization, the interrupt handler will not process the
11710 * interrupt. The link attention and ELS ring attention events are handled
11711 * by the worker thread. The interrupt handler signals the worker thread
11712 * and returns for these events. This function is called without any lock
11713 * held. It gets the hbalock to access and update SLI data structures.
11715 * This function returns IRQ_HANDLED when interrupt is handled else it
11716 * returns IRQ_NONE.
11719 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
11721 struct lpfc_hba
*phba
;
11722 struct lpfc_queue
*speq
;
11723 struct lpfc_eqe
*eqe
;
11724 unsigned long iflag
;
11728 * Get the driver's phba structure from the dev_id
11730 phba
= (struct lpfc_hba
*)dev_id
;
11732 if (unlikely(!phba
))
11735 /* Get to the EQ struct associated with this vector */
11736 speq
= phba
->sli4_hba
.sp_eq
;
11737 if (unlikely(!speq
))
11740 /* Check device state for handling interrupt */
11741 if (unlikely(lpfc_intr_state_check(phba
))) {
11742 /* Check again for link_state with lock held */
11743 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11744 if (phba
->link_state
< LPFC_LINK_DOWN
)
11745 /* Flush, clear interrupt, and rearm the EQ */
11746 lpfc_sli4_eq_flush(phba
, speq
);
11747 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11752 * Process all the event on FCP slow-path EQ
11754 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
11755 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
11756 if (!(++ecount
% speq
->entry_repost
))
11757 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
11760 /* Always clear and re-arm the slow-path EQ */
11761 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
11763 /* Catch the no cq entry condition */
11764 if (unlikely(ecount
== 0)) {
11765 if (phba
->intr_type
== MSIX
)
11766 /* MSI-X treated interrupt served as no EQ share INT */
11767 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11768 "0357 MSI-X interrupt with no EQE\n");
11770 /* Non MSI-X treated on interrupt as EQ share INT */
11774 return IRQ_HANDLED
;
11775 } /* lpfc_sli4_sp_intr_handler */
11778 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
11779 * @irq: Interrupt number.
11780 * @dev_id: The device context pointer.
11782 * This function is directly called from the PCI layer as an interrupt
11783 * service routine when device with SLI-4 interface spec is enabled with
11784 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11785 * ring event in the HBA. However, when the device is enabled with either
11786 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11787 * device-level interrupt handler. When the PCI slot is in error recovery
11788 * or the HBA is undergoing initialization, the interrupt handler will not
11789 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11790 * the intrrupt context. This function is called without any lock held.
11791 * It gets the hbalock to access and update SLI data structures. Note that,
11792 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11793 * equal to that of FCP CQ index.
11795 * This function returns IRQ_HANDLED when interrupt is handled else it
11796 * returns IRQ_NONE.
11799 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
11801 struct lpfc_hba
*phba
;
11802 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
11803 struct lpfc_queue
*fpeq
;
11804 struct lpfc_eqe
*eqe
;
11805 unsigned long iflag
;
11807 uint32_t fcp_eqidx
;
11809 /* Get the driver's phba structure from the dev_id */
11810 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
11811 phba
= fcp_eq_hdl
->phba
;
11812 fcp_eqidx
= fcp_eq_hdl
->idx
;
11814 if (unlikely(!phba
))
11816 if (unlikely(!phba
->sli4_hba
.fp_eq
))
11819 /* Get to the EQ struct associated with this vector */
11820 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
11821 if (unlikely(!fpeq
))
11824 /* Check device state for handling interrupt */
11825 if (unlikely(lpfc_intr_state_check(phba
))) {
11826 /* Check again for link_state with lock held */
11827 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11828 if (phba
->link_state
< LPFC_LINK_DOWN
)
11829 /* Flush, clear interrupt, and rearm the EQ */
11830 lpfc_sli4_eq_flush(phba
, fpeq
);
11831 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11836 * Process all the event on FCP fast-path EQ
11838 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
11839 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
11840 if (!(++ecount
% fpeq
->entry_repost
))
11841 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
11844 /* Always clear and re-arm the fast-path EQ */
11845 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
11847 if (unlikely(ecount
== 0)) {
11848 if (phba
->intr_type
== MSIX
)
11849 /* MSI-X treated interrupt served as no EQ share INT */
11850 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11851 "0358 MSI-X interrupt with no EQE\n");
11853 /* Non MSI-X treated on interrupt as EQ share INT */
11857 return IRQ_HANDLED
;
11858 } /* lpfc_sli4_fp_intr_handler */
11861 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11862 * @irq: Interrupt number.
11863 * @dev_id: The device context pointer.
11865 * This function is the device-level interrupt handler to device with SLI-4
11866 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11867 * interrupt mode is enabled and there is an event in the HBA which requires
11868 * driver attention. This function invokes the slow-path interrupt attention
11869 * handling function and fast-path interrupt attention handling function in
11870 * turn to process the relevant HBA attention events. This function is called
11871 * without any lock held. It gets the hbalock to access and update SLI data
11874 * This function returns IRQ_HANDLED when interrupt is handled, else it
11875 * returns IRQ_NONE.
11878 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
11880 struct lpfc_hba
*phba
;
11881 irqreturn_t sp_irq_rc
, fp_irq_rc
;
11882 bool fp_handled
= false;
11883 uint32_t fcp_eqidx
;
11885 /* Get the driver's phba structure from the dev_id */
11886 phba
= (struct lpfc_hba
*)dev_id
;
11888 if (unlikely(!phba
))
11892 * Invokes slow-path host attention interrupt handling as appropriate.
11894 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
11897 * Invoke fast-path host attention interrupt handling as appropriate.
11899 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
11900 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
11901 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
11902 if (fp_irq_rc
== IRQ_HANDLED
)
11903 fp_handled
|= true;
11906 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
11907 } /* lpfc_sli4_intr_handler */
11910 * lpfc_sli4_queue_free - free a queue structure and associated memory
11911 * @queue: The queue structure to free.
11913 * This function frees a queue structure and the DMAable memory used for
11914 * the host resident queue. This function must be called after destroying the
11915 * queue on the HBA.
11918 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
11920 struct lpfc_dmabuf
*dmabuf
;
11925 while (!list_empty(&queue
->page_list
)) {
11926 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
11928 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
11929 dmabuf
->virt
, dmabuf
->phys
);
11937 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
11938 * @phba: The HBA that this queue is being created on.
11939 * @entry_size: The size of each queue entry for this queue.
11940 * @entry count: The number of entries that this queue will handle.
11942 * This function allocates a queue structure and the DMAable memory used for
11943 * the host resident queue. This function must be called before creating the
11944 * queue on the HBA.
11946 struct lpfc_queue
*
11947 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
11948 uint32_t entry_count
)
11950 struct lpfc_queue
*queue
;
11951 struct lpfc_dmabuf
*dmabuf
;
11952 int x
, total_qe_count
;
11954 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11956 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11957 hw_page_size
= SLI4_PAGE_SIZE
;
11959 queue
= kzalloc(sizeof(struct lpfc_queue
) +
11960 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
11963 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
11964 hw_page_size
))/hw_page_size
;
11965 INIT_LIST_HEAD(&queue
->list
);
11966 INIT_LIST_HEAD(&queue
->page_list
);
11967 INIT_LIST_HEAD(&queue
->child_list
);
11968 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
11969 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
11972 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
11973 hw_page_size
, &dmabuf
->phys
,
11975 if (!dmabuf
->virt
) {
11979 memset(dmabuf
->virt
, 0, hw_page_size
);
11980 dmabuf
->buffer_tag
= x
;
11981 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
11982 /* initialize queue's entry array */
11983 dma_pointer
= dmabuf
->virt
;
11984 for (; total_qe_count
< entry_count
&&
11985 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
11986 total_qe_count
++, dma_pointer
+= entry_size
) {
11987 queue
->qe
[total_qe_count
].address
= dma_pointer
;
11990 queue
->entry_size
= entry_size
;
11991 queue
->entry_count
= entry_count
;
11994 * entry_repost is calculated based on the number of entries in the
11995 * queue. This works out except for RQs. If buffers are NOT initially
11996 * posted for every RQE, entry_repost should be adjusted accordingly.
11998 queue
->entry_repost
= (entry_count
>> 3);
11999 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
12000 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
12001 queue
->phba
= phba
;
12005 lpfc_sli4_queue_free(queue
);
12010 * lpfc_eq_create - Create an Event Queue on the HBA
12011 * @phba: HBA structure that indicates port to create a queue on.
12012 * @eq: The queue structure to use to create the event queue.
12013 * @imax: The maximum interrupt per second limit.
12015 * This function creates an event queue, as detailed in @eq, on a port,
12016 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12018 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12019 * is used to get the entry count and entry size that are necessary to
12020 * determine the number of pages to allocate and use for this queue. This
12021 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12022 * event queue. This function is asynchronous and will wait for the mailbox
12023 * command to finish before continuing.
12025 * On success this function will return a zero. If unable to allocate enough
12026 * memory this function will return -ENOMEM. If the queue create mailbox command
12027 * fails this function will return -ENXIO.
12030 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
12032 struct lpfc_mbx_eq_create
*eq_create
;
12033 LPFC_MBOXQ_t
*mbox
;
12034 int rc
, length
, status
= 0;
12035 struct lpfc_dmabuf
*dmabuf
;
12036 uint32_t shdr_status
, shdr_add_status
;
12037 union lpfc_sli4_cfg_shdr
*shdr
;
12039 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12041 /* sanity check on queue memory */
12044 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12045 hw_page_size
= SLI4_PAGE_SIZE
;
12047 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12050 length
= (sizeof(struct lpfc_mbx_eq_create
) -
12051 sizeof(struct lpfc_sli4_cfg_mhdr
));
12052 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12053 LPFC_MBOX_OPCODE_EQ_CREATE
,
12054 length
, LPFC_SLI4_MBX_EMBED
);
12055 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
12056 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
12058 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
12060 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
12061 /* Calculate delay multiper from maximum interrupt per second */
12062 dmult
= LPFC_DMULT_CONST
/imax
- 1;
12063 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
12065 switch (eq
->entry_count
) {
12067 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12068 "0360 Unsupported EQ count. (%d)\n",
12070 if (eq
->entry_count
< 256)
12072 /* otherwise default to smallest count (drop through) */
12074 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12078 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12082 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12086 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12090 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12094 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
12095 memset(dmabuf
->virt
, 0, hw_page_size
);
12096 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12097 putPaddrLow(dmabuf
->phys
);
12098 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12099 putPaddrHigh(dmabuf
->phys
);
12101 mbox
->vport
= phba
->pport
;
12102 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12103 mbox
->context1
= NULL
;
12104 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12105 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
12106 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12107 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12108 if (shdr_status
|| shdr_add_status
|| rc
) {
12109 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12110 "2500 EQ_CREATE mailbox failed with "
12111 "status x%x add_status x%x, mbx status x%x\n",
12112 shdr_status
, shdr_add_status
, rc
);
12115 eq
->type
= LPFC_EQ
;
12116 eq
->subtype
= LPFC_NONE
;
12117 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
12118 if (eq
->queue_id
== 0xFFFF)
12120 eq
->host_index
= 0;
12123 mempool_free(mbox
, phba
->mbox_mem_pool
);
12128 * lpfc_cq_create - Create a Completion Queue on the HBA
12129 * @phba: HBA structure that indicates port to create a queue on.
12130 * @cq: The queue structure to use to create the completion queue.
12131 * @eq: The event queue to bind this completion queue to.
12133 * This function creates a completion queue, as detailed in @wq, on a port,
12134 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
12136 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12137 * is used to get the entry count and entry size that are necessary to
12138 * determine the number of pages to allocate and use for this queue. The @eq
12139 * is used to indicate which event queue to bind this completion queue to. This
12140 * function will send the CQ_CREATE mailbox command to the HBA to setup the
12141 * completion queue. This function is asynchronous and will wait for the mailbox
12142 * command to finish before continuing.
12144 * On success this function will return a zero. If unable to allocate enough
12145 * memory this function will return -ENOMEM. If the queue create mailbox command
12146 * fails this function will return -ENXIO.
12149 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12150 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
12152 struct lpfc_mbx_cq_create
*cq_create
;
12153 struct lpfc_dmabuf
*dmabuf
;
12154 LPFC_MBOXQ_t
*mbox
;
12155 int rc
, length
, status
= 0;
12156 uint32_t shdr_status
, shdr_add_status
;
12157 union lpfc_sli4_cfg_shdr
*shdr
;
12158 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12160 /* sanity check on queue memory */
12163 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12164 hw_page_size
= SLI4_PAGE_SIZE
;
12166 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12169 length
= (sizeof(struct lpfc_mbx_cq_create
) -
12170 sizeof(struct lpfc_sli4_cfg_mhdr
));
12171 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12172 LPFC_MBOX_OPCODE_CQ_CREATE
,
12173 length
, LPFC_SLI4_MBX_EMBED
);
12174 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
12175 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
12176 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
12178 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
12179 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
12180 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12181 phba
->sli4_hba
.pc_sli4_params
.cqv
);
12182 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
12183 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12184 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
12185 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
12188 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
12191 switch (cq
->entry_count
) {
12193 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12194 "0361 Unsupported CQ count. (%d)\n",
12196 if (cq
->entry_count
< 256)
12198 /* otherwise default to smallest count (drop through) */
12200 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12204 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12208 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12212 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12213 memset(dmabuf
->virt
, 0, hw_page_size
);
12214 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12215 putPaddrLow(dmabuf
->phys
);
12216 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12217 putPaddrHigh(dmabuf
->phys
);
12219 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12221 /* The IOCTL status is embedded in the mailbox subheader. */
12222 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12223 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12224 if (shdr_status
|| shdr_add_status
|| rc
) {
12225 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12226 "2501 CQ_CREATE mailbox failed with "
12227 "status x%x add_status x%x, mbx status x%x\n",
12228 shdr_status
, shdr_add_status
, rc
);
12232 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12233 if (cq
->queue_id
== 0xFFFF) {
12237 /* link the cq onto the parent eq child list */
12238 list_add_tail(&cq
->list
, &eq
->child_list
);
12239 /* Set up completion queue's type and subtype */
12241 cq
->subtype
= subtype
;
12242 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12243 cq
->assoc_qid
= eq
->queue_id
;
12244 cq
->host_index
= 0;
12248 mempool_free(mbox
, phba
->mbox_mem_pool
);
12253 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12254 * @phba: HBA structure that indicates port to create a queue on.
12255 * @mq: The queue structure to use to create the mailbox queue.
12256 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12257 * @cq: The completion queue to associate with this cq.
12259 * This function provides failback (fb) functionality when the
12260 * mq_create_ext fails on older FW generations. It's purpose is identical
12261 * to mq_create_ext otherwise.
12263 * This routine cannot fail as all attributes were previously accessed and
12264 * initialized in mq_create_ext.
12267 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12268 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12270 struct lpfc_mbx_mq_create
*mq_create
;
12271 struct lpfc_dmabuf
*dmabuf
;
12274 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12275 sizeof(struct lpfc_sli4_cfg_mhdr
));
12276 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12277 LPFC_MBOX_OPCODE_MQ_CREATE
,
12278 length
, LPFC_SLI4_MBX_EMBED
);
12279 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12280 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12282 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12284 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12285 switch (mq
->entry_count
) {
12287 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12288 LPFC_MQ_RING_SIZE_16
);
12291 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12292 LPFC_MQ_RING_SIZE_32
);
12295 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12296 LPFC_MQ_RING_SIZE_64
);
12299 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12300 LPFC_MQ_RING_SIZE_128
);
12303 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12304 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12305 putPaddrLow(dmabuf
->phys
);
12306 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12307 putPaddrHigh(dmabuf
->phys
);
12312 * lpfc_mq_create - Create a mailbox Queue on the HBA
12313 * @phba: HBA structure that indicates port to create a queue on.
12314 * @mq: The queue structure to use to create the mailbox queue.
12315 * @cq: The completion queue to associate with this cq.
12316 * @subtype: The queue's subtype.
12318 * This function creates a mailbox queue, as detailed in @mq, on a port,
12319 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12321 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12322 * is used to get the entry count and entry size that are necessary to
12323 * determine the number of pages to allocate and use for this queue. This
12324 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12325 * mailbox queue. This function is asynchronous and will wait for the mailbox
12326 * command to finish before continuing.
12328 * On success this function will return a zero. If unable to allocate enough
12329 * memory this function will return -ENOMEM. If the queue create mailbox command
12330 * fails this function will return -ENXIO.
12333 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12334 struct lpfc_queue
*cq
, uint32_t subtype
)
12336 struct lpfc_mbx_mq_create
*mq_create
;
12337 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12338 struct lpfc_dmabuf
*dmabuf
;
12339 LPFC_MBOXQ_t
*mbox
;
12340 int rc
, length
, status
= 0;
12341 uint32_t shdr_status
, shdr_add_status
;
12342 union lpfc_sli4_cfg_shdr
*shdr
;
12343 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12345 /* sanity check on queue memory */
12348 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12349 hw_page_size
= SLI4_PAGE_SIZE
;
12351 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12354 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12355 sizeof(struct lpfc_sli4_cfg_mhdr
));
12356 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12357 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12358 length
, LPFC_SLI4_MBX_EMBED
);
12360 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12361 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12362 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12363 &mq_create_ext
->u
.request
, mq
->page_count
);
12364 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12365 &mq_create_ext
->u
.request
, 1);
12366 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12367 &mq_create_ext
->u
.request
, 1);
12368 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12369 &mq_create_ext
->u
.request
, 1);
12370 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12371 &mq_create_ext
->u
.request
, 1);
12372 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12373 &mq_create_ext
->u
.request
, 1);
12374 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12375 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12376 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12377 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12378 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12381 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12383 switch (mq
->entry_count
) {
12385 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12386 "0362 Unsupported MQ count. (%d)\n",
12388 if (mq
->entry_count
< 16)
12390 /* otherwise default to smallest count (drop through) */
12392 bf_set(lpfc_mq_context_ring_size
,
12393 &mq_create_ext
->u
.request
.context
,
12394 LPFC_MQ_RING_SIZE_16
);
12397 bf_set(lpfc_mq_context_ring_size
,
12398 &mq_create_ext
->u
.request
.context
,
12399 LPFC_MQ_RING_SIZE_32
);
12402 bf_set(lpfc_mq_context_ring_size
,
12403 &mq_create_ext
->u
.request
.context
,
12404 LPFC_MQ_RING_SIZE_64
);
12407 bf_set(lpfc_mq_context_ring_size
,
12408 &mq_create_ext
->u
.request
.context
,
12409 LPFC_MQ_RING_SIZE_128
);
12412 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12413 memset(dmabuf
->virt
, 0, hw_page_size
);
12414 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12415 putPaddrLow(dmabuf
->phys
);
12416 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12417 putPaddrHigh(dmabuf
->phys
);
12419 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12420 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12421 &mq_create_ext
->u
.response
);
12422 if (rc
!= MBX_SUCCESS
) {
12423 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12424 "2795 MQ_CREATE_EXT failed with "
12425 "status x%x. Failback to MQ_CREATE.\n",
12427 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12428 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12429 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12430 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12431 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12432 &mq_create
->u
.response
);
12435 /* The IOCTL status is embedded in the mailbox subheader. */
12436 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12437 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12438 if (shdr_status
|| shdr_add_status
|| rc
) {
12439 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12440 "2502 MQ_CREATE mailbox failed with "
12441 "status x%x add_status x%x, mbx status x%x\n",
12442 shdr_status
, shdr_add_status
, rc
);
12446 if (mq
->queue_id
== 0xFFFF) {
12450 mq
->type
= LPFC_MQ
;
12451 mq
->assoc_qid
= cq
->queue_id
;
12452 mq
->subtype
= subtype
;
12453 mq
->host_index
= 0;
12456 /* link the mq onto the parent cq child list */
12457 list_add_tail(&mq
->list
, &cq
->child_list
);
12459 mempool_free(mbox
, phba
->mbox_mem_pool
);
12464 * lpfc_wq_create - Create a Work Queue on the HBA
12465 * @phba: HBA structure that indicates port to create a queue on.
12466 * @wq: The queue structure to use to create the work queue.
12467 * @cq: The completion queue to bind this work queue to.
12468 * @subtype: The subtype of the work queue indicating its functionality.
12470 * This function creates a work queue, as detailed in @wq, on a port, described
12471 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12473 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12474 * is used to get the entry count and entry size that are necessary to
12475 * determine the number of pages to allocate and use for this queue. The @cq
12476 * is used to indicate which completion queue to bind this work queue to. This
12477 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12478 * work queue. This function is asynchronous and will wait for the mailbox
12479 * command to finish before continuing.
12481 * On success this function will return a zero. If unable to allocate enough
12482 * memory this function will return -ENOMEM. If the queue create mailbox command
12483 * fails this function will return -ENXIO.
12486 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12487 struct lpfc_queue
*cq
, uint32_t subtype
)
12489 struct lpfc_mbx_wq_create
*wq_create
;
12490 struct lpfc_dmabuf
*dmabuf
;
12491 LPFC_MBOXQ_t
*mbox
;
12492 int rc
, length
, status
= 0;
12493 uint32_t shdr_status
, shdr_add_status
;
12494 union lpfc_sli4_cfg_shdr
*shdr
;
12495 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12496 struct dma_address
*page
;
12498 /* sanity check on queue memory */
12501 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12502 hw_page_size
= SLI4_PAGE_SIZE
;
12504 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12507 length
= (sizeof(struct lpfc_mbx_wq_create
) -
12508 sizeof(struct lpfc_sli4_cfg_mhdr
));
12509 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12510 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
12511 length
, LPFC_SLI4_MBX_EMBED
);
12512 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
12513 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
12514 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
12516 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
12518 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12519 phba
->sli4_hba
.pc_sli4_params
.wqv
);
12520 if (phba
->sli4_hba
.pc_sli4_params
.wqv
== LPFC_Q_CREATE_VERSION_1
) {
12521 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
12523 switch (wq
->entry_size
) {
12526 bf_set(lpfc_mbx_wq_create_wqe_size
,
12527 &wq_create
->u
.request_1
,
12528 LPFC_WQ_WQE_SIZE_64
);
12531 bf_set(lpfc_mbx_wq_create_wqe_size
,
12532 &wq_create
->u
.request_1
,
12533 LPFC_WQ_WQE_SIZE_128
);
12536 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
12537 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12538 page
= wq_create
->u
.request_1
.page
;
12540 page
= wq_create
->u
.request
.page
;
12542 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
12543 memset(dmabuf
->virt
, 0, hw_page_size
);
12544 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
12545 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
12547 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
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 "2503 WQ_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 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
12560 if (wq
->queue_id
== 0xFFFF) {
12564 wq
->type
= LPFC_WQ
;
12565 wq
->assoc_qid
= cq
->queue_id
;
12566 wq
->subtype
= subtype
;
12567 wq
->host_index
= 0;
12569 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
12571 /* link the wq onto the parent cq child list */
12572 list_add_tail(&wq
->list
, &cq
->child_list
);
12574 mempool_free(mbox
, phba
->mbox_mem_pool
);
12579 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12580 * @phba: HBA structure that indicates port to create a queue on.
12581 * @rq: The queue structure to use for the receive queue.
12582 * @qno: The associated HBQ number
12585 * For SLI4 we need to adjust the RQ repost value based on
12586 * the number of buffers that are initially posted to the RQ.
12589 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
12593 /* sanity check on queue memory */
12596 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
12598 /* Recalc repost for RQs based on buffers initially posted */
12600 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
12601 cnt
= LPFC_QUEUE_MIN_REPOST
;
12603 rq
->entry_repost
= cnt
;
12607 * lpfc_rq_create - Create a Receive Queue on the HBA
12608 * @phba: HBA structure that indicates port to create a queue on.
12609 * @hrq: The queue structure to use to create the header receive queue.
12610 * @drq: The queue structure to use to create the data receive queue.
12611 * @cq: The completion queue to bind this work queue to.
12613 * This function creates a receive buffer queue pair , as detailed in @hrq and
12614 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12617 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12618 * struct is used to get the entry count that is necessary to determine the
12619 * number of pages to use for this queue. The @cq is used to indicate which
12620 * completion queue to bind received buffers that are posted to these queues to.
12621 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12622 * receive queue pair. This function is asynchronous and will wait for the
12623 * mailbox command to finish before continuing.
12625 * On success this function will return a zero. If unable to allocate enough
12626 * memory this function will return -ENOMEM. If the queue create mailbox command
12627 * fails this function will return -ENXIO.
12630 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12631 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
12633 struct lpfc_mbx_rq_create
*rq_create
;
12634 struct lpfc_dmabuf
*dmabuf
;
12635 LPFC_MBOXQ_t
*mbox
;
12636 int rc
, length
, status
= 0;
12637 uint32_t shdr_status
, shdr_add_status
;
12638 union lpfc_sli4_cfg_shdr
*shdr
;
12639 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12641 /* sanity check on queue memory */
12642 if (!hrq
|| !drq
|| !cq
)
12644 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12645 hw_page_size
= SLI4_PAGE_SIZE
;
12647 if (hrq
->entry_count
!= drq
->entry_count
)
12649 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12652 length
= (sizeof(struct lpfc_mbx_rq_create
) -
12653 sizeof(struct lpfc_sli4_cfg_mhdr
));
12654 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12655 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12656 length
, LPFC_SLI4_MBX_EMBED
);
12657 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
12658 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12659 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12660 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12661 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12662 bf_set(lpfc_rq_context_rqe_count_1
,
12663 &rq_create
->u
.request
.context
,
12665 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
12666 bf_set(lpfc_rq_context_rqe_size
,
12667 &rq_create
->u
.request
.context
,
12669 bf_set(lpfc_rq_context_page_size
,
12670 &rq_create
->u
.request
.context
,
12671 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12673 switch (hrq
->entry_count
) {
12675 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12676 "2535 Unsupported RQ count. (%d)\n",
12678 if (hrq
->entry_count
< 512)
12680 /* otherwise default to smallest count (drop through) */
12682 bf_set(lpfc_rq_context_rqe_count
,
12683 &rq_create
->u
.request
.context
,
12684 LPFC_RQ_RING_SIZE_512
);
12687 bf_set(lpfc_rq_context_rqe_count
,
12688 &rq_create
->u
.request
.context
,
12689 LPFC_RQ_RING_SIZE_1024
);
12692 bf_set(lpfc_rq_context_rqe_count
,
12693 &rq_create
->u
.request
.context
,
12694 LPFC_RQ_RING_SIZE_2048
);
12697 bf_set(lpfc_rq_context_rqe_count
,
12698 &rq_create
->u
.request
.context
,
12699 LPFC_RQ_RING_SIZE_4096
);
12702 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12703 LPFC_HDR_BUF_SIZE
);
12705 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12707 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12709 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
12710 memset(dmabuf
->virt
, 0, hw_page_size
);
12711 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12712 putPaddrLow(dmabuf
->phys
);
12713 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12714 putPaddrHigh(dmabuf
->phys
);
12716 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12717 /* The IOCTL status is embedded in the mailbox subheader. */
12718 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12719 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12720 if (shdr_status
|| shdr_add_status
|| rc
) {
12721 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12722 "2504 RQ_CREATE mailbox failed with "
12723 "status x%x add_status x%x, mbx status x%x\n",
12724 shdr_status
, shdr_add_status
, rc
);
12728 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12729 if (hrq
->queue_id
== 0xFFFF) {
12733 hrq
->type
= LPFC_HRQ
;
12734 hrq
->assoc_qid
= cq
->queue_id
;
12735 hrq
->subtype
= subtype
;
12736 hrq
->host_index
= 0;
12737 hrq
->hba_index
= 0;
12739 /* now create the data queue */
12740 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12741 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12742 length
, LPFC_SLI4_MBX_EMBED
);
12743 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12744 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12745 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12746 bf_set(lpfc_rq_context_rqe_count_1
,
12747 &rq_create
->u
.request
.context
, hrq
->entry_count
);
12748 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
12749 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
12751 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
12752 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12754 switch (drq
->entry_count
) {
12756 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12757 "2536 Unsupported RQ count. (%d)\n",
12759 if (drq
->entry_count
< 512)
12761 /* otherwise default to smallest count (drop through) */
12763 bf_set(lpfc_rq_context_rqe_count
,
12764 &rq_create
->u
.request
.context
,
12765 LPFC_RQ_RING_SIZE_512
);
12768 bf_set(lpfc_rq_context_rqe_count
,
12769 &rq_create
->u
.request
.context
,
12770 LPFC_RQ_RING_SIZE_1024
);
12773 bf_set(lpfc_rq_context_rqe_count
,
12774 &rq_create
->u
.request
.context
,
12775 LPFC_RQ_RING_SIZE_2048
);
12778 bf_set(lpfc_rq_context_rqe_count
,
12779 &rq_create
->u
.request
.context
,
12780 LPFC_RQ_RING_SIZE_4096
);
12783 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12784 LPFC_DATA_BUF_SIZE
);
12786 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12788 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12790 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
12791 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12792 putPaddrLow(dmabuf
->phys
);
12793 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12794 putPaddrHigh(dmabuf
->phys
);
12796 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12797 /* The IOCTL status is embedded in the mailbox subheader. */
12798 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12799 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12800 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12801 if (shdr_status
|| shdr_add_status
|| rc
) {
12805 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12806 if (drq
->queue_id
== 0xFFFF) {
12810 drq
->type
= LPFC_DRQ
;
12811 drq
->assoc_qid
= cq
->queue_id
;
12812 drq
->subtype
= subtype
;
12813 drq
->host_index
= 0;
12814 drq
->hba_index
= 0;
12816 /* link the header and data RQs onto the parent cq child list */
12817 list_add_tail(&hrq
->list
, &cq
->child_list
);
12818 list_add_tail(&drq
->list
, &cq
->child_list
);
12821 mempool_free(mbox
, phba
->mbox_mem_pool
);
12826 * lpfc_eq_destroy - Destroy an event Queue on the HBA
12827 * @eq: The queue structure associated with the queue to destroy.
12829 * This function destroys a queue, as detailed in @eq by sending an mailbox
12830 * command, specific to the type of queue, to the HBA.
12832 * The @eq struct is used to get the queue ID of the queue to destroy.
12834 * On success this function will return a zero. If the queue destroy mailbox
12835 * command fails this function will return -ENXIO.
12838 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12840 LPFC_MBOXQ_t
*mbox
;
12841 int rc
, length
, status
= 0;
12842 uint32_t shdr_status
, shdr_add_status
;
12843 union lpfc_sli4_cfg_shdr
*shdr
;
12845 /* sanity check on queue memory */
12848 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12851 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
12852 sizeof(struct lpfc_sli4_cfg_mhdr
));
12853 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12854 LPFC_MBOX_OPCODE_EQ_DESTROY
,
12855 length
, LPFC_SLI4_MBX_EMBED
);
12856 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
12858 mbox
->vport
= eq
->phba
->pport
;
12859 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12861 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
12862 /* The IOCTL status is embedded in the mailbox subheader. */
12863 shdr
= (union lpfc_sli4_cfg_shdr
*)
12864 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
12865 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12866 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12867 if (shdr_status
|| shdr_add_status
|| rc
) {
12868 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12869 "2505 EQ_DESTROY mailbox failed with "
12870 "status x%x add_status x%x, mbx status x%x\n",
12871 shdr_status
, shdr_add_status
, rc
);
12875 /* Remove eq from any list */
12876 list_del_init(&eq
->list
);
12877 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
12882 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
12883 * @cq: The queue structure associated with the queue to destroy.
12885 * This function destroys a queue, as detailed in @cq by sending an mailbox
12886 * command, specific to the type of queue, to the HBA.
12888 * The @cq struct is used to get the queue ID of the queue to destroy.
12890 * On success this function will return a zero. If the queue destroy mailbox
12891 * command fails this function will return -ENXIO.
12894 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
12896 LPFC_MBOXQ_t
*mbox
;
12897 int rc
, length
, status
= 0;
12898 uint32_t shdr_status
, shdr_add_status
;
12899 union lpfc_sli4_cfg_shdr
*shdr
;
12901 /* sanity check on queue memory */
12904 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12907 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
12908 sizeof(struct lpfc_sli4_cfg_mhdr
));
12909 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12910 LPFC_MBOX_OPCODE_CQ_DESTROY
,
12911 length
, LPFC_SLI4_MBX_EMBED
);
12912 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
12914 mbox
->vport
= cq
->phba
->pport
;
12915 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12916 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
12917 /* The IOCTL status is embedded in the mailbox subheader. */
12918 shdr
= (union lpfc_sli4_cfg_shdr
*)
12919 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
12920 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12921 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12922 if (shdr_status
|| shdr_add_status
|| rc
) {
12923 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12924 "2506 CQ_DESTROY mailbox failed with "
12925 "status x%x add_status x%x, mbx status x%x\n",
12926 shdr_status
, shdr_add_status
, rc
);
12929 /* Remove cq from any list */
12930 list_del_init(&cq
->list
);
12931 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
12936 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
12937 * @qm: The queue structure associated with the queue to destroy.
12939 * This function destroys a queue, as detailed in @mq by sending an mailbox
12940 * command, specific to the type of queue, to the HBA.
12942 * The @mq struct is used to get the queue ID of the queue to destroy.
12944 * On success this function will return a zero. If the queue destroy mailbox
12945 * command fails this function will return -ENXIO.
12948 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
12950 LPFC_MBOXQ_t
*mbox
;
12951 int rc
, length
, status
= 0;
12952 uint32_t shdr_status
, shdr_add_status
;
12953 union lpfc_sli4_cfg_shdr
*shdr
;
12955 /* sanity check on queue memory */
12958 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12961 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
12962 sizeof(struct lpfc_sli4_cfg_mhdr
));
12963 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12964 LPFC_MBOX_OPCODE_MQ_DESTROY
,
12965 length
, LPFC_SLI4_MBX_EMBED
);
12966 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
12968 mbox
->vport
= mq
->phba
->pport
;
12969 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12970 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
12971 /* The IOCTL status is embedded in the mailbox subheader. */
12972 shdr
= (union lpfc_sli4_cfg_shdr
*)
12973 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
12974 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12975 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12976 if (shdr_status
|| shdr_add_status
|| rc
) {
12977 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12978 "2507 MQ_DESTROY mailbox failed with "
12979 "status x%x add_status x%x, mbx status x%x\n",
12980 shdr_status
, shdr_add_status
, rc
);
12983 /* Remove mq from any list */
12984 list_del_init(&mq
->list
);
12985 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
12990 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
12991 * @wq: The queue structure associated with the queue to destroy.
12993 * This function destroys a queue, as detailed in @wq by sending an mailbox
12994 * command, specific to the type of queue, to the HBA.
12996 * The @wq struct is used to get the queue ID of the queue to destroy.
12998 * On success this function will return a zero. If the queue destroy mailbox
12999 * command fails this function will return -ENXIO.
13002 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
13004 LPFC_MBOXQ_t
*mbox
;
13005 int rc
, length
, status
= 0;
13006 uint32_t shdr_status
, shdr_add_status
;
13007 union lpfc_sli4_cfg_shdr
*shdr
;
13009 /* sanity check on queue memory */
13012 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13015 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
13016 sizeof(struct lpfc_sli4_cfg_mhdr
));
13017 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13018 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
13019 length
, LPFC_SLI4_MBX_EMBED
);
13020 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
13022 mbox
->vport
= wq
->phba
->pport
;
13023 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13024 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
13025 shdr
= (union lpfc_sli4_cfg_shdr
*)
13026 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
13027 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13028 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13029 if (shdr_status
|| shdr_add_status
|| rc
) {
13030 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13031 "2508 WQ_DESTROY mailbox failed with "
13032 "status x%x add_status x%x, mbx status x%x\n",
13033 shdr_status
, shdr_add_status
, rc
);
13036 /* Remove wq from any list */
13037 list_del_init(&wq
->list
);
13038 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
13043 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
13044 * @rq: The queue structure associated with the queue to destroy.
13046 * This function destroys a queue, as detailed in @rq by sending an mailbox
13047 * command, specific to the type of queue, to the HBA.
13049 * The @rq struct is used to get the queue ID of the queue to destroy.
13051 * On success this function will return a zero. If the queue destroy mailbox
13052 * command fails this function will return -ENXIO.
13055 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13056 struct lpfc_queue
*drq
)
13058 LPFC_MBOXQ_t
*mbox
;
13059 int rc
, length
, status
= 0;
13060 uint32_t shdr_status
, shdr_add_status
;
13061 union lpfc_sli4_cfg_shdr
*shdr
;
13063 /* sanity check on queue memory */
13066 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13069 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
13070 sizeof(struct lpfc_sli4_cfg_mhdr
));
13071 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13072 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
13073 length
, LPFC_SLI4_MBX_EMBED
);
13074 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13076 mbox
->vport
= hrq
->phba
->pport
;
13077 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13078 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
13079 /* The IOCTL status is embedded in the mailbox subheader. */
13080 shdr
= (union lpfc_sli4_cfg_shdr
*)
13081 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13082 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13083 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13084 if (shdr_status
|| shdr_add_status
|| rc
) {
13085 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13086 "2509 RQ_DESTROY mailbox failed with "
13087 "status x%x add_status x%x, mbx status x%x\n",
13088 shdr_status
, shdr_add_status
, rc
);
13089 if (rc
!= MBX_TIMEOUT
)
13090 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13093 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13095 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
13096 shdr
= (union lpfc_sli4_cfg_shdr
*)
13097 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13098 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13099 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13100 if (shdr_status
|| shdr_add_status
|| rc
) {
13101 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13102 "2510 RQ_DESTROY mailbox failed with "
13103 "status x%x add_status x%x, mbx status x%x\n",
13104 shdr_status
, shdr_add_status
, rc
);
13107 list_del_init(&hrq
->list
);
13108 list_del_init(&drq
->list
);
13109 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13114 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
13115 * @phba: The virtual port for which this call being executed.
13116 * @pdma_phys_addr0: Physical address of the 1st SGL page.
13117 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
13118 * @xritag: the xritag that ties this io to the SGL pages.
13120 * This routine will post the sgl pages for the IO that has the xritag
13121 * that is in the iocbq structure. The xritag is assigned during iocbq
13122 * creation and persists for as long as the driver is loaded.
13123 * if the caller has fewer than 256 scatter gather segments to map then
13124 * pdma_phys_addr1 should be 0.
13125 * If the caller needs to map more than 256 scatter gather segment then
13126 * pdma_phys_addr1 should be a valid physical address.
13127 * physical address for SGLs must be 64 byte aligned.
13128 * If you are going to map 2 SGL's then the first one must have 256 entries
13129 * the second sgl can have between 1 and 256 entries.
13133 * -ENXIO, -ENOMEM - Failure
13136 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
13137 dma_addr_t pdma_phys_addr0
,
13138 dma_addr_t pdma_phys_addr1
,
13141 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
13142 LPFC_MBOXQ_t
*mbox
;
13144 uint32_t shdr_status
, shdr_add_status
;
13146 union lpfc_sli4_cfg_shdr
*shdr
;
13148 if (xritag
== NO_XRI
) {
13149 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13150 "0364 Invalid param:\n");
13154 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13158 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13159 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13160 sizeof(struct lpfc_mbx_post_sgl_pages
) -
13161 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
13163 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
13164 &mbox
->u
.mqe
.un
.post_sgl_pages
;
13165 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
13166 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
13168 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
13169 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
13170 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
13171 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
13173 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
13174 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
13175 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
13176 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
13177 if (!phba
->sli4_hba
.intr_enable
)
13178 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13180 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13181 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13183 /* The IOCTL status is embedded in the mailbox subheader. */
13184 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
13185 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13186 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13187 if (rc
!= MBX_TIMEOUT
)
13188 mempool_free(mbox
, phba
->mbox_mem_pool
);
13189 if (shdr_status
|| shdr_add_status
|| rc
) {
13190 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13191 "2511 POST_SGL mailbox failed with "
13192 "status x%x add_status x%x, mbx status x%x\n",
13193 shdr_status
, shdr_add_status
, rc
);
13200 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13201 * @phba: pointer to lpfc hba data structure.
13203 * This routine is invoked to post rpi header templates to the
13204 * HBA consistent with the SLI-4 interface spec. This routine
13205 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13206 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13209 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13210 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13213 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13218 * Fetch the next logical xri. Because this index is logical,
13219 * the driver starts at 0 each time.
13221 spin_lock_irq(&phba
->hbalock
);
13222 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13223 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13224 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13225 spin_unlock_irq(&phba
->hbalock
);
13228 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13229 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13231 spin_unlock_irq(&phba
->hbalock
);
13236 * lpfc_sli4_free_xri - Release an xri for reuse.
13237 * @phba: pointer to lpfc hba data structure.
13239 * This routine is invoked to release an xri to the pool of
13240 * available rpis maintained by the driver.
13243 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13245 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13246 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13251 * lpfc_sli4_free_xri - Release an xri for reuse.
13252 * @phba: pointer to lpfc hba data structure.
13254 * This routine is invoked to release an xri to the pool of
13255 * available rpis maintained by the driver.
13258 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13260 spin_lock_irq(&phba
->hbalock
);
13261 __lpfc_sli4_free_xri(phba
, xri
);
13262 spin_unlock_irq(&phba
->hbalock
);
13266 * lpfc_sli4_next_xritag - Get an xritag for the io
13267 * @phba: Pointer to HBA context object.
13269 * This function gets an xritag for the iocb. If there is no unused xritag
13270 * it will return 0xffff.
13271 * The function returns the allocated xritag if successful, else returns zero.
13272 * Zero is not a valid xritag.
13273 * The caller is not required to hold any lock.
13276 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13278 uint16_t xri_index
;
13280 xri_index
= lpfc_sli4_alloc_xri(phba
);
13281 if (xri_index
== NO_XRI
)
13282 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13283 "2004 Failed to allocate XRI.last XRITAG is %d"
13284 " Max XRI is %d, Used XRI is %d\n",
13286 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13287 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13292 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13293 * @phba: pointer to lpfc hba data structure.
13294 * @post_sgl_list: pointer to els sgl entry list.
13295 * @count: number of els sgl entries on the list.
13297 * This routine is invoked to post a block of driver's sgl pages to the
13298 * HBA using non-embedded mailbox command. No Lock is held. This routine
13299 * is only called when the driver is loading and after all IO has been
13303 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
13304 struct list_head
*post_sgl_list
,
13307 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
13308 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13309 struct sgl_page_pairs
*sgl_pg_pairs
;
13311 LPFC_MBOXQ_t
*mbox
;
13312 uint32_t reqlen
, alloclen
, pg_pairs
;
13314 uint16_t xritag_start
= 0;
13316 uint32_t shdr_status
, shdr_add_status
;
13317 union lpfc_sli4_cfg_shdr
*shdr
;
13319 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13320 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13321 if (reqlen
> SLI4_PAGE_SIZE
) {
13322 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13323 "2559 Block sgl registration required DMA "
13324 "size (%d) great than a page\n", reqlen
);
13327 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13331 /* Allocate DMA memory and set up the non-embedded mailbox command */
13332 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13333 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13334 LPFC_SLI4_MBX_NEMBED
);
13336 if (alloclen
< reqlen
) {
13337 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13338 "0285 Allocated DMA memory size (%d) is "
13339 "less than the requested DMA memory "
13340 "size (%d)\n", alloclen
, reqlen
);
13341 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13344 /* Set up the SGL pages in the non-embedded DMA pages */
13345 viraddr
= mbox
->sge_array
->addr
[0];
13346 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13347 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13350 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
13351 /* Set up the sge entry */
13352 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13353 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13354 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13355 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13356 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13357 cpu_to_le32(putPaddrLow(0));
13358 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13359 cpu_to_le32(putPaddrHigh(0));
13361 /* Keep the first xritag on the list */
13363 xritag_start
= sglq_entry
->sli4_xritag
;
13368 /* Complete initialization and perform endian conversion. */
13369 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13370 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
13371 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13372 if (!phba
->sli4_hba
.intr_enable
)
13373 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13375 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13376 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13378 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13379 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13380 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13381 if (rc
!= MBX_TIMEOUT
)
13382 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13383 if (shdr_status
|| shdr_add_status
|| rc
) {
13384 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13385 "2513 POST_SGL_BLOCK mailbox command failed "
13386 "status x%x add_status x%x mbx status x%x\n",
13387 shdr_status
, shdr_add_status
, rc
);
13394 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13395 * @phba: pointer to lpfc hba data structure.
13396 * @sblist: pointer to scsi buffer list.
13397 * @count: number of scsi buffers on the list.
13399 * This routine is invoked to post a block of @count scsi sgl pages from a
13400 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13405 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
13406 struct list_head
*sblist
,
13409 struct lpfc_scsi_buf
*psb
;
13410 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13411 struct sgl_page_pairs
*sgl_pg_pairs
;
13413 LPFC_MBOXQ_t
*mbox
;
13414 uint32_t reqlen
, alloclen
, pg_pairs
;
13416 uint16_t xritag_start
= 0;
13418 uint32_t shdr_status
, shdr_add_status
;
13419 dma_addr_t pdma_phys_bpl1
;
13420 union lpfc_sli4_cfg_shdr
*shdr
;
13422 /* Calculate the requested length of the dma memory */
13423 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
13424 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13425 if (reqlen
> SLI4_PAGE_SIZE
) {
13426 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13427 "0217 Block sgl registration required DMA "
13428 "size (%d) great than a page\n", reqlen
);
13431 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13433 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13434 "0283 Failed to allocate mbox cmd memory\n");
13438 /* Allocate DMA memory and set up the non-embedded mailbox command */
13439 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13440 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13441 LPFC_SLI4_MBX_NEMBED
);
13443 if (alloclen
< reqlen
) {
13444 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13445 "2561 Allocated DMA memory size (%d) is "
13446 "less than the requested DMA memory "
13447 "size (%d)\n", alloclen
, reqlen
);
13448 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13452 /* Get the first SGE entry from the non-embedded DMA memory */
13453 viraddr
= mbox
->sge_array
->addr
[0];
13455 /* Set up the SGL pages in the non-embedded DMA pages */
13456 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13457 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13460 list_for_each_entry(psb
, sblist
, list
) {
13461 /* Set up the sge entry */
13462 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13463 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13464 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13465 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13466 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13467 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
13469 pdma_phys_bpl1
= 0;
13470 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13471 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13472 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13473 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13474 /* Keep the first xritag on the list */
13476 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
13480 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13481 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13482 /* Perform endian conversion if necessary */
13483 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13485 if (!phba
->sli4_hba
.intr_enable
)
13486 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13488 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13489 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13491 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13492 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13493 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13494 if (rc
!= MBX_TIMEOUT
)
13495 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13496 if (shdr_status
|| shdr_add_status
|| rc
) {
13497 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13498 "2564 POST_SGL_BLOCK mailbox command failed "
13499 "status x%x add_status x%x mbx status x%x\n",
13500 shdr_status
, shdr_add_status
, rc
);
13507 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13508 * @phba: pointer to lpfc_hba struct that the frame was received on
13509 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13511 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13512 * valid type of frame that the LPFC driver will handle. This function will
13513 * return a zero if the frame is a valid frame or a non zero value when the
13514 * frame does not pass the check.
13517 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
13519 /* make rctl_names static to save stack space */
13520 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
13521 char *type_names
[] = FC_TYPE_NAMES_INIT
;
13522 struct fc_vft_header
*fc_vft_hdr
;
13523 uint32_t *header
= (uint32_t *) fc_hdr
;
13525 switch (fc_hdr
->fh_r_ctl
) {
13526 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
13527 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
13528 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
13529 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
13530 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
13531 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
13532 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
13533 case FC_RCTL_DD_CMD_STATUS
: /* command status */
13534 case FC_RCTL_ELS_REQ
: /* extended link services request */
13535 case FC_RCTL_ELS_REP
: /* extended link services reply */
13536 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
13537 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
13538 case FC_RCTL_BA_NOP
: /* basic link service NOP */
13539 case FC_RCTL_BA_ABTS
: /* basic link service abort */
13540 case FC_RCTL_BA_RMC
: /* remove connection */
13541 case FC_RCTL_BA_ACC
: /* basic accept */
13542 case FC_RCTL_BA_RJT
: /* basic reject */
13543 case FC_RCTL_BA_PRMT
:
13544 case FC_RCTL_ACK_1
: /* acknowledge_1 */
13545 case FC_RCTL_ACK_0
: /* acknowledge_0 */
13546 case FC_RCTL_P_RJT
: /* port reject */
13547 case FC_RCTL_F_RJT
: /* fabric reject */
13548 case FC_RCTL_P_BSY
: /* port busy */
13549 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
13550 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
13551 case FC_RCTL_LCR
: /* link credit reset */
13552 case FC_RCTL_END
: /* end */
13554 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
13555 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13556 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
13557 return lpfc_fc_frame_check(phba
, fc_hdr
);
13561 switch (fc_hdr
->fh_type
) {
13573 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
13574 "2538 Received frame rctl:%s type:%s "
13575 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13576 rctl_names
[fc_hdr
->fh_r_ctl
],
13577 type_names
[fc_hdr
->fh_type
],
13578 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
13579 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
13580 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]));
13583 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13584 "2539 Dropped frame rctl:%s type:%s\n",
13585 rctl_names
[fc_hdr
->fh_r_ctl
],
13586 type_names
[fc_hdr
->fh_type
]);
13591 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13592 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13594 * This function processes the FC header to retrieve the VFI from the VF
13595 * header, if one exists. This function will return the VFI if one exists
13596 * or 0 if no VSAN Header exists.
13599 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
13601 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13603 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
13605 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
13609 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13610 * @phba: Pointer to the HBA structure to search for the vport on
13611 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13612 * @fcfi: The FC Fabric ID that the frame came from
13614 * This function searches the @phba for a vport that matches the content of the
13615 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13616 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13617 * returns the matching vport pointer or NULL if unable to match frame to a
13620 static struct lpfc_vport
*
13621 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
13624 struct lpfc_vport
**vports
;
13625 struct lpfc_vport
*vport
= NULL
;
13627 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
13628 fc_hdr
->fh_d_id
[1] << 8 |
13629 fc_hdr
->fh_d_id
[2]);
13630 if (did
== Fabric_DID
)
13631 return phba
->pport
;
13632 vports
= lpfc_create_vport_work_array(phba
);
13633 if (vports
!= NULL
)
13634 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
13635 if (phba
->fcf
.fcfi
== fcfi
&&
13636 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
13637 vports
[i
]->fc_myDID
== did
) {
13642 lpfc_destroy_vport_work_array(phba
, vports
);
13647 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13648 * @vport: The vport to work on.
13650 * This function updates the receive sequence time stamp for this vport. The
13651 * receive sequence time stamp indicates the time that the last frame of the
13652 * the sequence that has been idle for the longest amount of time was received.
13653 * the driver uses this time stamp to indicate if any received sequences have
13657 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
13659 struct lpfc_dmabuf
*h_buf
;
13660 struct hbq_dmabuf
*dmabuf
= NULL
;
13662 /* get the oldest sequence on the rcv list */
13663 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
13664 struct lpfc_dmabuf
, list
);
13667 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13668 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
13672 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13673 * @vport: The vport that the received sequences were sent to.
13675 * This function cleans up all outstanding received sequences. This is called
13676 * by the driver when a link event or user action invalidates all the received
13680 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
13682 struct lpfc_dmabuf
*h_buf
, *hnext
;
13683 struct lpfc_dmabuf
*d_buf
, *dnext
;
13684 struct hbq_dmabuf
*dmabuf
= NULL
;
13686 /* start with the oldest sequence on the rcv list */
13687 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13688 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13689 list_del_init(&dmabuf
->hbuf
.list
);
13690 list_for_each_entry_safe(d_buf
, dnext
,
13691 &dmabuf
->dbuf
.list
, list
) {
13692 list_del_init(&d_buf
->list
);
13693 lpfc_in_buf_free(vport
->phba
, d_buf
);
13695 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13700 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13701 * @vport: The vport that the received sequences were sent to.
13703 * This function determines whether any received sequences have timed out by
13704 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13705 * indicates that there is at least one timed out sequence this routine will
13706 * go through the received sequences one at a time from most inactive to most
13707 * active to determine which ones need to be cleaned up. Once it has determined
13708 * that a sequence needs to be cleaned up it will simply free up the resources
13709 * without sending an abort.
13712 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
13714 struct lpfc_dmabuf
*h_buf
, *hnext
;
13715 struct lpfc_dmabuf
*d_buf
, *dnext
;
13716 struct hbq_dmabuf
*dmabuf
= NULL
;
13717 unsigned long timeout
;
13718 int abort_count
= 0;
13720 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13721 vport
->rcv_buffer_time_stamp
);
13722 if (list_empty(&vport
->rcv_buffer_list
) ||
13723 time_before(jiffies
, timeout
))
13725 /* start with the oldest sequence on the rcv list */
13726 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13727 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13728 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13729 dmabuf
->time_stamp
);
13730 if (time_before(jiffies
, timeout
))
13733 list_del_init(&dmabuf
->hbuf
.list
);
13734 list_for_each_entry_safe(d_buf
, dnext
,
13735 &dmabuf
->dbuf
.list
, list
) {
13736 list_del_init(&d_buf
->list
);
13737 lpfc_in_buf_free(vport
->phba
, d_buf
);
13739 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13742 lpfc_update_rcv_time_stamp(vport
);
13746 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13747 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13749 * This function searches through the existing incomplete sequences that have
13750 * been sent to this @vport. If the frame matches one of the incomplete
13751 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13752 * make up that sequence. If no sequence is found that matches this frame then
13753 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13754 * This function returns a pointer to the first dmabuf in the sequence list that
13755 * the frame was linked to.
13757 static struct hbq_dmabuf
*
13758 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
13760 struct fc_frame_header
*new_hdr
;
13761 struct fc_frame_header
*temp_hdr
;
13762 struct lpfc_dmabuf
*d_buf
;
13763 struct lpfc_dmabuf
*h_buf
;
13764 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13765 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
13767 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13768 dmabuf
->time_stamp
= jiffies
;
13769 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13770 /* Use the hdr_buf to find the sequence that this frame belongs to */
13771 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13772 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13773 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13774 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13775 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13777 /* found a pending sequence that matches this frame */
13778 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13783 * This indicates first frame received for this sequence.
13784 * Queue the buffer on the vport's rcv_buffer_list.
13786 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13787 lpfc_update_rcv_time_stamp(vport
);
13790 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
13791 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
13792 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13793 list_del_init(&seq_dmabuf
->hbuf
.list
);
13794 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13795 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
13796 lpfc_update_rcv_time_stamp(vport
);
13799 /* move this sequence to the tail to indicate a young sequence */
13800 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13801 seq_dmabuf
->time_stamp
= jiffies
;
13802 lpfc_update_rcv_time_stamp(vport
);
13803 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
13804 temp_hdr
= dmabuf
->hbuf
.virt
;
13805 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
13808 /* find the correct place in the sequence to insert this frame */
13809 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
13810 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
13811 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
13813 * If the frame's sequence count is greater than the frame on
13814 * the list then insert the frame right after this frame
13816 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
13817 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13818 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
13826 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
13827 * @vport: pointer to a vitural port
13828 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13830 * This function tries to abort from the partially assembed sequence, described
13831 * by the information from basic abbort @dmabuf. It checks to see whether such
13832 * partially assembled sequence held by the driver. If so, it shall free up all
13833 * the frames from the partially assembled sequence.
13836 * true -- if there is matching partially assembled sequence present and all
13837 * the frames freed with the sequence;
13838 * false -- if there is no matching partially assembled sequence present so
13839 * nothing got aborted in the lower layer driver
13842 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
13843 struct hbq_dmabuf
*dmabuf
)
13845 struct fc_frame_header
*new_hdr
;
13846 struct fc_frame_header
*temp_hdr
;
13847 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
13848 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13850 /* Use the hdr_buf to find the sequence that matches this frame */
13851 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13852 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
13853 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13854 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13855 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13856 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13857 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13858 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13860 /* found a pending sequence that matches this frame */
13861 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13865 /* Free up all the frames from the partially assembled sequence */
13867 list_for_each_entry_safe(d_buf
, n_buf
,
13868 &seq_dmabuf
->dbuf
.list
, list
) {
13869 list_del_init(&d_buf
->list
);
13870 lpfc_in_buf_free(vport
->phba
, d_buf
);
13878 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
13879 * @phba: Pointer to HBA context object.
13880 * @cmd_iocbq: pointer to the command iocbq structure.
13881 * @rsp_iocbq: pointer to the response iocbq structure.
13883 * This function handles the sequence abort response iocb command complete
13884 * event. It properly releases the memory allocated to the sequence abort
13888 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
13889 struct lpfc_iocbq
*cmd_iocbq
,
13890 struct lpfc_iocbq
*rsp_iocbq
)
13893 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
13895 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
13896 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
13897 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13898 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
13899 rsp_iocbq
->iocb
.ulpStatus
,
13900 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
13904 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
13905 * @phba: Pointer to HBA context object.
13906 * @xri: xri id in transaction.
13908 * This function validates the xri maps to the known range of XRIs allocated an
13909 * used by the driver.
13912 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
13917 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
13918 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
13926 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
13927 * @phba: Pointer to HBA context object.
13928 * @fc_hdr: pointer to a FC frame header.
13930 * This function sends a basic response to a previous unsol sequence abort
13931 * event after aborting the sequence handling.
13934 lpfc_sli4_seq_abort_rsp(struct lpfc_hba
*phba
,
13935 struct fc_frame_header
*fc_hdr
)
13937 struct lpfc_iocbq
*ctiocb
= NULL
;
13938 struct lpfc_nodelist
*ndlp
;
13939 uint16_t oxid
, rxid
;
13940 uint32_t sid
, fctl
;
13944 if (!lpfc_is_link_up(phba
))
13947 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
13948 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
13949 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
13951 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
13953 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13954 "1268 Find ndlp returned NULL for oxid:x%x "
13955 "SID:x%x\n", oxid
, sid
);
13958 if (lpfc_sli4_xri_inrange(phba
, rxid
))
13959 lpfc_set_rrq_active(phba
, ndlp
, rxid
, oxid
, 0);
13961 /* Allocate buffer for rsp iocb */
13962 ctiocb
= lpfc_sli_get_iocbq(phba
);
13966 /* Extract the F_CTL field from FC_HDR */
13967 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
13969 icmd
= &ctiocb
->iocb
;
13970 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
13971 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
13972 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
13973 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
13974 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
13976 /* Fill in the rest of iocb fields */
13977 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
13978 icmd
->ulpBdeCount
= 0;
13980 icmd
->ulpClass
= CLASS3
;
13981 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
13982 ctiocb
->context1
= ndlp
;
13984 ctiocb
->iocb_cmpl
= NULL
;
13985 ctiocb
->vport
= phba
->pport
;
13986 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
13987 ctiocb
->sli4_lxritag
= NO_XRI
;
13988 ctiocb
->sli4_xritag
= NO_XRI
;
13990 /* If the oxid maps to the FCP XRI range or if it is out of range,
13991 * send a BLS_RJT. The driver no longer has that exchange.
13992 * Override the IOCB for a BA_RJT.
13994 if (oxid
> (phba
->sli4_hba
.max_cfg_param
.max_xri
+
13995 phba
->sli4_hba
.max_cfg_param
.xri_base
) ||
13996 oxid
> (lpfc_sli4_get_els_iocb_cnt(phba
) +
13997 phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
13998 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
13999 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14000 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14001 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14004 if (fctl
& FC_FC_EX_CTX
) {
14005 /* ABTS sent by responder to CT exchange, construction
14006 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14007 * field and RX_ID from ABTS for RX_ID field.
14009 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14011 /* ABTS sent by initiator to CT exchange, construction
14012 * of BA_ACC will need to allocate a new XRI as for the
14015 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14017 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14018 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14020 /* Xmit CT abts response on exchange <xid> */
14021 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14022 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14023 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14025 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14026 if (rc
== IOCB_ERROR
) {
14027 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
14028 "2925 Failed to issue CT ABTS RSP x%x on "
14029 "xri x%x, Data x%x\n",
14030 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14032 lpfc_sli_release_iocbq(phba
, ctiocb
);
14037 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14038 * @vport: Pointer to the vport on which this sequence was received
14039 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14041 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14042 * receive sequence is only partially assembed by the driver, it shall abort
14043 * the partially assembled frames for the sequence. Otherwise, if the
14044 * unsolicited receive sequence has been completely assembled and passed to
14045 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14046 * unsolicited sequence has been aborted. After that, it will issue a basic
14047 * accept to accept the abort.
14050 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14051 struct hbq_dmabuf
*dmabuf
)
14053 struct lpfc_hba
*phba
= vport
->phba
;
14054 struct fc_frame_header fc_hdr
;
14058 /* Make a copy of fc_hdr before the dmabuf being released */
14059 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14060 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14062 if (fctl
& FC_FC_EX_CTX
) {
14064 * ABTS sent by responder to exchange, just free the buffer
14066 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14069 * ABTS sent by initiator to exchange, need to do cleanup
14071 /* Try to abort partially assembled seq */
14072 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14074 /* Send abort to ULP if partially seq abort failed */
14075 if (abts_par
== false)
14076 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
14078 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14080 /* Send basic accept (BA_ACC) to the abort requester */
14081 lpfc_sli4_seq_abort_rsp(phba
, &fc_hdr
);
14085 * lpfc_seq_complete - Indicates if a sequence is complete
14086 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14088 * This function checks the sequence, starting with the frame described by
14089 * @dmabuf, to see if all the frames associated with this sequence are present.
14090 * the frames associated with this sequence are linked to the @dmabuf using the
14091 * dbuf list. This function looks for two major things. 1) That the first frame
14092 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14093 * set. 3) That there are no holes in the sequence count. The function will
14094 * return 1 when the sequence is complete, otherwise it will return 0.
14097 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14099 struct fc_frame_header
*hdr
;
14100 struct lpfc_dmabuf
*d_buf
;
14101 struct hbq_dmabuf
*seq_dmabuf
;
14105 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14106 /* make sure first fame of sequence has a sequence count of zero */
14107 if (hdr
->fh_seq_cnt
!= seq_count
)
14109 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14110 hdr
->fh_f_ctl
[1] << 8 |
14112 /* If last frame of sequence we can return success. */
14113 if (fctl
& FC_FC_END_SEQ
)
14115 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14116 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14117 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14118 /* If there is a hole in the sequence count then fail. */
14119 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14121 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14122 hdr
->fh_f_ctl
[1] << 8 |
14124 /* If last frame of sequence we can return success. */
14125 if (fctl
& FC_FC_END_SEQ
)
14132 * lpfc_prep_seq - Prep sequence for ULP processing
14133 * @vport: Pointer to the vport on which this sequence was received
14134 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14136 * This function takes a sequence, described by a list of frames, and creates
14137 * a list of iocbq structures to describe the sequence. This iocbq list will be
14138 * used to issue to the generic unsolicited sequence handler. This routine
14139 * returns a pointer to the first iocbq in the list. If the function is unable
14140 * to allocate an iocbq then it throw out the received frames that were not
14141 * able to be described and return a pointer to the first iocbq. If unable to
14142 * allocate any iocbqs (including the first) this function will return NULL.
14144 static struct lpfc_iocbq
*
14145 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14147 struct hbq_dmabuf
*hbq_buf
;
14148 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14149 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14150 struct fc_frame_header
*fc_hdr
;
14152 uint32_t len
, tot_len
;
14153 struct ulp_bde64
*pbde
;
14155 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14156 /* remove from receive buffer list */
14157 list_del_init(&seq_dmabuf
->hbuf
.list
);
14158 lpfc_update_rcv_time_stamp(vport
);
14159 /* get the Remote Port's SID */
14160 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14162 /* Get an iocbq struct to fill in. */
14163 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14165 /* Initialize the first IOCB. */
14166 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14167 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14168 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14169 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14170 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14171 be16_to_cpu(fc_hdr
->fh_ox_id
);
14172 /* iocbq is prepped for internal consumption. Physical vpi. */
14173 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14174 vport
->phba
->vpi_ids
[vport
->vpi
];
14175 /* put the first buffer into the first IOCBq */
14176 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14177 first_iocbq
->context3
= NULL
;
14178 first_iocbq
->iocb
.ulpBdeCount
= 1;
14179 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14180 LPFC_DATA_BUF_SIZE
;
14181 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14182 tot_len
= bf_get(lpfc_rcqe_length
,
14183 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14184 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14186 iocbq
= first_iocbq
;
14188 * Each IOCBq can have two Buffers assigned, so go through the list
14189 * of buffers for this sequence and save two buffers in each IOCBq
14191 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14193 lpfc_in_buf_free(vport
->phba
, d_buf
);
14196 if (!iocbq
->context3
) {
14197 iocbq
->context3
= d_buf
;
14198 iocbq
->iocb
.ulpBdeCount
++;
14199 pbde
= (struct ulp_bde64
*)
14200 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14201 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14203 /* We need to get the size out of the right CQE */
14204 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14205 len
= bf_get(lpfc_rcqe_length
,
14206 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14207 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14210 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14213 first_iocbq
->iocb
.ulpStatus
=
14214 IOSTAT_FCP_RSP_ERROR
;
14215 first_iocbq
->iocb
.un
.ulpWord
[4] =
14216 IOERR_NO_RESOURCES
;
14218 lpfc_in_buf_free(vport
->phba
, d_buf
);
14221 iocbq
->context2
= d_buf
;
14222 iocbq
->context3
= NULL
;
14223 iocbq
->iocb
.ulpBdeCount
= 1;
14224 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14225 LPFC_DATA_BUF_SIZE
;
14227 /* We need to get the size out of the right CQE */
14228 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14229 len
= bf_get(lpfc_rcqe_length
,
14230 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14232 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14234 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14235 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14238 return first_iocbq
;
14242 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14243 struct hbq_dmabuf
*seq_dmabuf
)
14245 struct fc_frame_header
*fc_hdr
;
14246 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
14247 struct lpfc_hba
*phba
= vport
->phba
;
14249 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14250 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
14252 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14253 "2707 Ring %d handler: Failed to allocate "
14254 "iocb Rctl x%x Type x%x received\n",
14256 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14259 if (!lpfc_complete_unsol_iocb(phba
,
14260 &phba
->sli
.ring
[LPFC_ELS_RING
],
14261 iocbq
, fc_hdr
->fh_r_ctl
,
14263 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14264 "2540 Ring %d handler: unexpected Rctl "
14265 "x%x Type x%x received\n",
14267 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14269 /* Free iocb created in lpfc_prep_seq */
14270 list_for_each_entry_safe(curr_iocb
, next_iocb
,
14271 &iocbq
->list
, list
) {
14272 list_del_init(&curr_iocb
->list
);
14273 lpfc_sli_release_iocbq(phba
, curr_iocb
);
14275 lpfc_sli_release_iocbq(phba
, iocbq
);
14279 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14280 * @phba: Pointer to HBA context object.
14282 * This function is called with no lock held. This function processes all
14283 * the received buffers and gives it to upper layers when a received buffer
14284 * indicates that it is the final frame in the sequence. The interrupt
14285 * service routine processes received buffers at interrupt contexts and adds
14286 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14287 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14288 * appropriate receive function when the final frame in a sequence is received.
14291 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
14292 struct hbq_dmabuf
*dmabuf
)
14294 struct hbq_dmabuf
*seq_dmabuf
;
14295 struct fc_frame_header
*fc_hdr
;
14296 struct lpfc_vport
*vport
;
14299 /* Process each received buffer */
14300 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14301 /* check to see if this a valid type of frame */
14302 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
14303 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14306 if ((bf_get(lpfc_cqe_code
,
14307 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
14308 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
14309 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14311 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
14312 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14313 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
14314 if (!vport
|| !(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
14315 /* throw out the frame */
14316 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14319 /* Handle the basic abort sequence (BA_ABTS) event */
14320 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
14321 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
14325 /* Link this frame */
14326 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
14328 /* unable to add frame to vport - throw it out */
14329 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14332 /* If not last frame in sequence continue processing frames. */
14333 if (!lpfc_seq_complete(seq_dmabuf
))
14336 /* Send the complete sequence to the upper layer protocol */
14337 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
14341 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14342 * @phba: pointer to lpfc hba data structure.
14344 * This routine is invoked to post rpi header templates to the
14345 * HBA consistent with the SLI-4 interface spec. This routine
14346 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14347 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14349 * This routine does not require any locks. It's usage is expected
14350 * to be driver load or reset recovery when the driver is
14355 * -EIO - The mailbox failed to complete successfully.
14356 * When this error occurs, the driver is not guaranteed
14357 * to have any rpi regions posted to the device and
14358 * must either attempt to repost the regions or take a
14362 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
14364 struct lpfc_rpi_hdr
*rpi_page
;
14368 /* SLI4 ports that support extents do not require RPI headers. */
14369 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14371 if (phba
->sli4_hba
.extents_in_use
)
14374 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
14376 * Assign the rpi headers a physical rpi only if the driver
14377 * has not initialized those resources. A port reset only
14378 * needs the headers posted.
14380 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
14382 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14384 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
14385 if (rc
!= MBX_SUCCESS
) {
14386 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14387 "2008 Error %d posting all rpi "
14395 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
14396 LPFC_RPI_RSRC_RDY
);
14401 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14402 * @phba: pointer to lpfc hba data structure.
14403 * @rpi_page: pointer to the rpi memory region.
14405 * This routine is invoked to post a single rpi header to the
14406 * HBA consistent with the SLI-4 interface spec. This memory region
14407 * maps up to 64 rpi context regions.
14411 * -ENOMEM - No available memory
14412 * -EIO - The mailbox failed to complete successfully.
14415 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
14417 LPFC_MBOXQ_t
*mboxq
;
14418 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
14420 uint32_t shdr_status
, shdr_add_status
;
14421 union lpfc_sli4_cfg_shdr
*shdr
;
14423 /* SLI4 ports that support extents do not require RPI headers. */
14424 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14426 if (phba
->sli4_hba
.extents_in_use
)
14429 /* The port is notified of the header region via a mailbox command. */
14430 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14432 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14433 "2001 Unable to allocate memory for issuing "
14434 "SLI_CONFIG_SPECIAL mailbox command\n");
14438 /* Post all rpi memory regions to the port. */
14439 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
14440 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14441 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
14442 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
14443 sizeof(struct lpfc_sli4_cfg_mhdr
),
14444 LPFC_SLI4_MBX_EMBED
);
14447 /* Post the physical rpi to the port for this rpi header. */
14448 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
14449 rpi_page
->start_rpi
);
14450 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
14451 hdr_tmpl
, rpi_page
->page_count
);
14453 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
14454 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
14455 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
14456 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
14457 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14458 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14459 if (rc
!= MBX_TIMEOUT
)
14460 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14461 if (shdr_status
|| shdr_add_status
|| rc
) {
14462 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14463 "2514 POST_RPI_HDR mailbox failed with "
14464 "status x%x add_status x%x, mbx status x%x\n",
14465 shdr_status
, shdr_add_status
, rc
);
14472 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14473 * @phba: pointer to lpfc hba data structure.
14475 * This routine is invoked to post rpi header templates to the
14476 * HBA consistent with the SLI-4 interface spec. This routine
14477 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14478 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14481 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14482 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14485 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
14488 uint16_t max_rpi
, rpi_limit
;
14489 uint16_t rpi_remaining
, lrpi
= 0;
14490 struct lpfc_rpi_hdr
*rpi_hdr
;
14492 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
14493 rpi_limit
= phba
->sli4_hba
.next_rpi
;
14496 * Fetch the next logical rpi. Because this index is logical,
14497 * the driver starts at 0 each time.
14499 spin_lock_irq(&phba
->hbalock
);
14500 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
14501 if (rpi
>= rpi_limit
)
14502 rpi
= LPFC_RPI_ALLOC_ERROR
;
14504 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
14505 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
14506 phba
->sli4_hba
.rpi_count
++;
14510 * Don't try to allocate more rpi header regions if the device limit
14511 * has been exhausted.
14513 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
14514 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
14515 spin_unlock_irq(&phba
->hbalock
);
14520 * RPI header postings are not required for SLI4 ports capable of
14523 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
14524 spin_unlock_irq(&phba
->hbalock
);
14529 * If the driver is running low on rpi resources, allocate another
14530 * page now. Note that the next_rpi value is used because
14531 * it represents how many are actually in use whereas max_rpi notes
14532 * how many are supported max by the device.
14534 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
14535 spin_unlock_irq(&phba
->hbalock
);
14536 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
14537 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
14539 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14540 "2002 Error Could not grow rpi "
14543 lrpi
= rpi_hdr
->start_rpi
;
14544 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14545 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
14553 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14554 * @phba: pointer to lpfc hba data structure.
14556 * This routine is invoked to release an rpi to the pool of
14557 * available rpis maintained by the driver.
14560 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14562 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
14563 phba
->sli4_hba
.rpi_count
--;
14564 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
14569 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14570 * @phba: pointer to lpfc hba data structure.
14572 * This routine is invoked to release an rpi to the pool of
14573 * available rpis maintained by the driver.
14576 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14578 spin_lock_irq(&phba
->hbalock
);
14579 __lpfc_sli4_free_rpi(phba
, rpi
);
14580 spin_unlock_irq(&phba
->hbalock
);
14584 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14585 * @phba: pointer to lpfc hba data structure.
14587 * This routine is invoked to remove the memory region that
14588 * provided rpi via a bitmask.
14591 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
14593 kfree(phba
->sli4_hba
.rpi_bmask
);
14594 kfree(phba
->sli4_hba
.rpi_ids
);
14595 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
14599 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14600 * @phba: pointer to lpfc hba data structure.
14602 * This routine is invoked to remove the memory region that
14603 * provided rpi via a bitmask.
14606 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
14607 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
14609 LPFC_MBOXQ_t
*mboxq
;
14610 struct lpfc_hba
*phba
= ndlp
->phba
;
14613 /* The port is notified of the header region via a mailbox command. */
14614 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14618 /* Post all rpi memory regions to the port. */
14619 lpfc_resume_rpi(mboxq
, ndlp
);
14621 mboxq
->mbox_cmpl
= cmpl
;
14622 mboxq
->context1
= arg
;
14623 mboxq
->context2
= ndlp
;
14625 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14626 mboxq
->vport
= ndlp
->vport
;
14627 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14628 if (rc
== MBX_NOT_FINISHED
) {
14629 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14630 "2010 Resume RPI Mailbox failed "
14631 "status %d, mbxStatus x%x\n", rc
,
14632 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14633 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14640 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14641 * @vport: Pointer to the vport for which the vpi is being initialized
14643 * This routine is invoked to activate a vpi with the port.
14647 * -Evalue otherwise
14650 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
14652 LPFC_MBOXQ_t
*mboxq
;
14654 int retval
= MBX_SUCCESS
;
14656 struct lpfc_hba
*phba
= vport
->phba
;
14657 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14660 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
14661 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
14662 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
14663 if (rc
!= MBX_SUCCESS
) {
14664 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
14665 "2022 INIT VPI Mailbox failed "
14666 "status %d, mbxStatus x%x\n", rc
,
14667 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14670 if (rc
!= MBX_TIMEOUT
)
14671 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
14677 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14678 * @phba: pointer to lpfc hba data structure.
14679 * @mboxq: Pointer to mailbox object.
14681 * This routine is invoked to manually add a single FCF record. The caller
14682 * must pass a completely initialized FCF_Record. This routine takes
14683 * care of the nonembedded mailbox operations.
14686 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
14689 union lpfc_sli4_cfg_shdr
*shdr
;
14690 uint32_t shdr_status
, shdr_add_status
;
14692 virt_addr
= mboxq
->sge_array
->addr
[0];
14693 /* The IOCTL status is embedded in the mailbox subheader. */
14694 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
14695 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14696 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14698 if ((shdr_status
|| shdr_add_status
) &&
14699 (shdr_status
!= STATUS_FCF_IN_USE
))
14700 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14701 "2558 ADD_FCF_RECORD mailbox failed with "
14702 "status x%x add_status x%x\n",
14703 shdr_status
, shdr_add_status
);
14705 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14709 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14710 * @phba: pointer to lpfc hba data structure.
14711 * @fcf_record: pointer to the initialized fcf record to add.
14713 * This routine is invoked to manually add a single FCF record. The caller
14714 * must pass a completely initialized FCF_Record. This routine takes
14715 * care of the nonembedded mailbox operations.
14718 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
14721 LPFC_MBOXQ_t
*mboxq
;
14724 dma_addr_t phys_addr
;
14725 struct lpfc_mbx_sge sge
;
14726 uint32_t alloc_len
, req_len
;
14729 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14731 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14732 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14736 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
14739 /* Allocate DMA memory and set up the non-embedded mailbox command */
14740 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14741 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
14742 req_len
, LPFC_SLI4_MBX_NEMBED
);
14743 if (alloc_len
< req_len
) {
14744 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14745 "2523 Allocated DMA memory size (x%x) is "
14746 "less than the requested DMA memory "
14747 "size (x%x)\n", alloc_len
, req_len
);
14748 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14753 * Get the first SGE entry from the non-embedded DMA memory. This
14754 * routine only uses a single SGE.
14756 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
14757 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
14758 virt_addr
= mboxq
->sge_array
->addr
[0];
14760 * Configure the FCF record for FCFI 0. This is the driver's
14761 * hardcoded default and gets used in nonFIP mode.
14763 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
14764 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
14765 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
14768 * Copy the fcf_index and the FCF Record Data. The data starts after
14769 * the FCoE header plus word10. The data copy needs to be endian
14772 bytep
+= sizeof(uint32_t);
14773 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
14774 mboxq
->vport
= phba
->pport
;
14775 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
14776 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14777 if (rc
== MBX_NOT_FINISHED
) {
14778 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14779 "2515 ADD_FCF_RECORD mailbox failed with "
14780 "status 0x%x\n", rc
);
14781 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14790 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
14791 * @phba: pointer to lpfc hba data structure.
14792 * @fcf_record: pointer to the fcf record to write the default data.
14793 * @fcf_index: FCF table entry index.
14795 * This routine is invoked to build the driver's default FCF record. The
14796 * values used are hardcoded. This routine handles memory initialization.
14800 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
14801 struct fcf_record
*fcf_record
,
14802 uint16_t fcf_index
)
14804 memset(fcf_record
, 0, sizeof(struct fcf_record
));
14805 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
14806 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
14807 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
14808 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
14809 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
14810 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
14811 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
14812 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
14813 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
14814 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
14815 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
14816 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
14817 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
14818 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
14819 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
14820 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
14821 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
14822 /* Set the VLAN bit map */
14823 if (phba
->valid_vlan
) {
14824 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
14825 = 1 << (phba
->vlan_id
% 8);
14830 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
14831 * @phba: pointer to lpfc hba data structure.
14832 * @fcf_index: FCF table entry offset.
14834 * This routine is invoked to scan the entire FCF table by reading FCF
14835 * record and processing it one at a time starting from the @fcf_index
14836 * for initial FCF discovery or fast FCF failover rediscovery.
14838 * Return 0 if the mailbox command is submitted successfully, none 0
14842 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
14845 LPFC_MBOXQ_t
*mboxq
;
14847 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
14848 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
14849 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14851 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14852 "2000 Failed to allocate mbox for "
14855 goto fail_fcf_scan
;
14857 /* Construct the read FCF record mailbox command */
14858 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
14861 goto fail_fcf_scan
;
14863 /* Issue the mailbox command asynchronously */
14864 mboxq
->vport
= phba
->pport
;
14865 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
14867 spin_lock_irq(&phba
->hbalock
);
14868 phba
->hba_flag
|= FCF_TS_INPROG
;
14869 spin_unlock_irq(&phba
->hbalock
);
14871 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14872 if (rc
== MBX_NOT_FINISHED
)
14875 /* Reset eligible FCF count for new scan */
14876 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
14877 phba
->fcf
.eligible_fcf_cnt
= 0;
14883 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14884 /* FCF scan failed, clear FCF_TS_INPROG flag */
14885 spin_lock_irq(&phba
->hbalock
);
14886 phba
->hba_flag
&= ~FCF_TS_INPROG
;
14887 spin_unlock_irq(&phba
->hbalock
);
14893 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
14894 * @phba: pointer to lpfc hba data structure.
14895 * @fcf_index: FCF table entry offset.
14897 * This routine is invoked to read an FCF record indicated by @fcf_index
14898 * and to use it for FLOGI roundrobin FCF failover.
14900 * Return 0 if the mailbox command is submitted successfully, none 0
14904 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
14907 LPFC_MBOXQ_t
*mboxq
;
14909 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14911 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
14912 "2763 Failed to allocate mbox for "
14915 goto fail_fcf_read
;
14917 /* Construct the read FCF record mailbox command */
14918 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
14921 goto fail_fcf_read
;
14923 /* Issue the mailbox command asynchronously */
14924 mboxq
->vport
= phba
->pport
;
14925 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
14926 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14927 if (rc
== MBX_NOT_FINISHED
)
14933 if (error
&& mboxq
)
14934 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14939 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
14940 * @phba: pointer to lpfc hba data structure.
14941 * @fcf_index: FCF table entry offset.
14943 * This routine is invoked to read an FCF record indicated by @fcf_index to
14944 * determine whether it's eligible for FLOGI roundrobin failover list.
14946 * Return 0 if the mailbox command is submitted successfully, none 0
14950 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
14953 LPFC_MBOXQ_t
*mboxq
;
14955 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14957 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
14958 "2758 Failed to allocate mbox for "
14961 goto fail_fcf_read
;
14963 /* Construct the read FCF record mailbox command */
14964 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
14967 goto fail_fcf_read
;
14969 /* Issue the mailbox command asynchronously */
14970 mboxq
->vport
= phba
->pport
;
14971 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
14972 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14973 if (rc
== MBX_NOT_FINISHED
)
14979 if (error
&& mboxq
)
14980 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14985 * lpfc_check_next_fcf_pri
14986 * phba pointer to the lpfc_hba struct for this port.
14987 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
14988 * routine when the rr_bmask is empty. The FCF indecies are put into the
14989 * rr_bmask based on their priority level. Starting from the highest priority
14990 * to the lowest. The most likely FCF candidate will be in the highest
14991 * priority group. When this routine is called it searches the fcf_pri list for
14992 * next lowest priority group and repopulates the rr_bmask with only those
14995 * 1=success 0=failure
14998 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15000 uint16_t next_fcf_pri
;
15001 uint16_t last_index
;
15002 struct lpfc_fcf_pri
*fcf_pri
;
15006 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15007 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15008 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15009 "3060 Last IDX %d\n", last_index
);
15010 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
15011 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15012 "3061 Last IDX %d\n", last_index
);
15013 return 0; /* Empty rr list */
15017 * Clear the rr_bmask and set all of the bits that are at this
15020 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15021 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15022 spin_lock_irq(&phba
->hbalock
);
15023 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15024 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15027 * the 1st priority that has not FLOGI failed
15028 * will be the highest.
15031 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15032 spin_unlock_irq(&phba
->hbalock
);
15033 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15034 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15035 fcf_pri
->fcf_rec
.fcf_index
);
15039 spin_lock_irq(&phba
->hbalock
);
15042 * if next_fcf_pri was not set above and the list is not empty then
15043 * we have failed flogis on all of them. So reset flogi failed
15044 * and start at the begining.
15046 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15047 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15048 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15050 * the 1st priority that has not FLOGI failed
15051 * will be the highest.
15054 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15055 spin_unlock_irq(&phba
->hbalock
);
15056 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15057 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15058 fcf_pri
->fcf_rec
.fcf_index
);
15062 spin_lock_irq(&phba
->hbalock
);
15066 spin_unlock_irq(&phba
->hbalock
);
15071 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15072 * @phba: pointer to lpfc hba data structure.
15074 * This routine is to get the next eligible FCF record index in a round
15075 * robin fashion. If the next eligible FCF record index equals to the
15076 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15077 * shall be returned, otherwise, the next eligible FCF record's index
15078 * shall be returned.
15081 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15083 uint16_t next_fcf_index
;
15085 /* Search start from next bit of currently registered FCF index */
15087 next_fcf_index
= (phba
->fcf
.current_rec
.fcf_indx
+ 1) %
15088 LPFC_SLI4_FCF_TBL_INDX_MAX
;
15089 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15090 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15093 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15094 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15096 * If we have wrapped then we need to clear the bits that
15097 * have been tested so that we can detect when we should
15098 * change the priority level.
15100 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15101 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15105 /* Check roundrobin failover list empty condition */
15106 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15107 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15109 * If next fcf index is not found check if there are lower
15110 * Priority level fcf's in the fcf_priority list.
15111 * Set up the rr_bmask with all of the avaiable fcf bits
15112 * at that level and continue the selection process.
15114 if (lpfc_check_next_fcf_pri_level(phba
))
15115 goto next_priority
;
15116 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15117 "2844 No roundrobin failover FCF available\n");
15118 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15119 return LPFC_FCOE_FCF_NEXT_NONE
;
15121 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15122 "3063 Only FCF available idx %d, flag %x\n",
15124 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15125 return next_fcf_index
;
15129 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15130 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15131 LPFC_FCF_FLOGI_FAILED
)
15132 goto next_priority
;
15134 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15135 "2845 Get next roundrobin failover FCF (x%x)\n",
15138 return next_fcf_index
;
15142 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15143 * @phba: pointer to lpfc hba data structure.
15145 * This routine sets the FCF record index in to the eligible bmask for
15146 * roundrobin failover search. It checks to make sure that the index
15147 * does not go beyond the range of the driver allocated bmask dimension
15148 * before setting the bit.
15150 * Returns 0 if the index bit successfully set, otherwise, it returns
15154 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15156 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15157 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15158 "2610 FCF (x%x) reached driver's book "
15159 "keeping dimension:x%x\n",
15160 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15163 /* Set the eligible FCF record index bmask */
15164 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15166 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15167 "2790 Set FCF (x%x) to roundrobin FCF failover "
15168 "bmask\n", fcf_index
);
15174 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15175 * @phba: pointer to lpfc hba data structure.
15177 * This routine clears the FCF record index from the eligible bmask for
15178 * roundrobin failover search. It checks to make sure that the index
15179 * does not go beyond the range of the driver allocated bmask dimension
15180 * before clearing the bit.
15183 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15185 struct lpfc_fcf_pri
*fcf_pri
;
15186 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15187 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15188 "2762 FCF (x%x) reached driver's book "
15189 "keeping dimension:x%x\n",
15190 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15193 /* Clear the eligible FCF record index bmask */
15194 spin_lock_irq(&phba
->hbalock
);
15195 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15196 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15197 list_del_init(&fcf_pri
->list
);
15201 spin_unlock_irq(&phba
->hbalock
);
15202 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15204 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15205 "2791 Clear FCF (x%x) from roundrobin failover "
15206 "bmask\n", fcf_index
);
15210 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15211 * @phba: pointer to lpfc hba data structure.
15213 * This routine is the completion routine for the rediscover FCF table mailbox
15214 * command. If the mailbox command returned failure, it will try to stop the
15215 * FCF rediscover wait timer.
15218 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
15220 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15221 uint32_t shdr_status
, shdr_add_status
;
15223 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15225 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
15226 &redisc_fcf
->header
.cfg_shdr
.response
);
15227 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
15228 &redisc_fcf
->header
.cfg_shdr
.response
);
15229 if (shdr_status
|| shdr_add_status
) {
15230 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15231 "2746 Requesting for FCF rediscovery failed "
15232 "status x%x add_status x%x\n",
15233 shdr_status
, shdr_add_status
);
15234 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
15235 spin_lock_irq(&phba
->hbalock
);
15236 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
15237 spin_unlock_irq(&phba
->hbalock
);
15239 * CVL event triggered FCF rediscover request failed,
15240 * last resort to re-try current registered FCF entry.
15242 lpfc_retry_pport_discovery(phba
);
15244 spin_lock_irq(&phba
->hbalock
);
15245 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
15246 spin_unlock_irq(&phba
->hbalock
);
15248 * DEAD FCF event triggered FCF rediscover request
15249 * failed, last resort to fail over as a link down
15250 * to FCF registration.
15252 lpfc_sli4_fcf_dead_failthrough(phba
);
15255 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15256 "2775 Start FCF rediscover quiescent timer\n");
15258 * Start FCF rediscovery wait timer for pending FCF
15259 * before rescan FCF record table.
15261 lpfc_fcf_redisc_wait_start_timer(phba
);
15264 mempool_free(mbox
, phba
->mbox_mem_pool
);
15268 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15269 * @phba: pointer to lpfc hba data structure.
15271 * This routine is invoked to request for rediscovery of the entire FCF table
15275 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
15277 LPFC_MBOXQ_t
*mbox
;
15278 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15281 /* Cancel retry delay timers to all vports before FCF rediscover */
15282 lpfc_cancel_all_vport_retry_delay_timer(phba
);
15284 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15286 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15287 "2745 Failed to allocate mbox for "
15288 "requesting FCF rediscover.\n");
15292 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
15293 sizeof(struct lpfc_sli4_cfg_mhdr
));
15294 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15295 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
15296 length
, LPFC_SLI4_MBX_EMBED
);
15298 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15299 /* Set count to 0 for invalidating the entire FCF database */
15300 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
15302 /* Issue the mailbox command asynchronously */
15303 mbox
->vport
= phba
->pport
;
15304 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
15305 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
15307 if (rc
== MBX_NOT_FINISHED
) {
15308 mempool_free(mbox
, phba
->mbox_mem_pool
);
15315 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15316 * @phba: pointer to lpfc hba data structure.
15318 * This function is the failover routine as a last resort to the FCF DEAD
15319 * event when driver failed to perform fast FCF failover.
15322 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
15324 uint32_t link_state
;
15327 * Last resort as FCF DEAD event failover will treat this as
15328 * a link down, but save the link state because we don't want
15329 * it to be changed to Link Down unless it is already down.
15331 link_state
= phba
->link_state
;
15332 lpfc_linkdown(phba
);
15333 phba
->link_state
= link_state
;
15335 /* Unregister FCF if no devices connected to it */
15336 lpfc_unregister_unused_fcf(phba
);
15340 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15341 * @phba: pointer to lpfc hba data structure.
15342 * @rgn23_data: pointer to configure region 23 data.
15344 * This function gets SLI3 port configure region 23 data through memory dump
15345 * mailbox command. When it successfully retrieves data, the size of the data
15346 * will be returned, otherwise, 0 will be returned.
15349 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15351 LPFC_MBOXQ_t
*pmb
= NULL
;
15353 uint32_t offset
= 0;
15359 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15361 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15362 "2600 failed to allocate mailbox memory\n");
15368 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
15369 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
15371 if (rc
!= MBX_SUCCESS
) {
15372 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15373 "2601 failed to read config "
15374 "region 23, rc 0x%x Status 0x%x\n",
15375 rc
, mb
->mbxStatus
);
15376 mb
->un
.varDmp
.word_cnt
= 0;
15379 * dump mem may return a zero when finished or we got a
15380 * mailbox error, either way we are done.
15382 if (mb
->un
.varDmp
.word_cnt
== 0)
15384 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
15385 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
15387 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
15388 rgn23_data
+ offset
,
15389 mb
->un
.varDmp
.word_cnt
);
15390 offset
+= mb
->un
.varDmp
.word_cnt
;
15391 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
15393 mempool_free(pmb
, phba
->mbox_mem_pool
);
15398 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15399 * @phba: pointer to lpfc hba data structure.
15400 * @rgn23_data: pointer to configure region 23 data.
15402 * This function gets SLI4 port configure region 23 data through memory dump
15403 * mailbox command. When it successfully retrieves data, the size of the data
15404 * will be returned, otherwise, 0 will be returned.
15407 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15409 LPFC_MBOXQ_t
*mboxq
= NULL
;
15410 struct lpfc_dmabuf
*mp
= NULL
;
15411 struct lpfc_mqe
*mqe
;
15412 uint32_t data_length
= 0;
15418 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15420 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15421 "3105 failed to allocate mailbox memory\n");
15425 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
15427 mqe
= &mboxq
->u
.mqe
;
15428 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
15429 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15432 data_length
= mqe
->un
.mb_words
[5];
15433 if (data_length
== 0)
15435 if (data_length
> DMP_RGN23_SIZE
) {
15439 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
15441 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15443 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15446 return data_length
;
15450 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15451 * @phba: pointer to lpfc hba data structure.
15453 * This function read region 23 and parse TLV for port status to
15454 * decide if the user disaled the port. If the TLV indicates the
15455 * port is disabled, the hba_flag is set accordingly.
15458 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
15460 uint8_t *rgn23_data
= NULL
;
15461 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
15462 uint32_t offset
= 0;
15464 /* Get adapter Region 23 data */
15465 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
15469 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15470 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
15472 if_type
= bf_get(lpfc_sli_intf_if_type
,
15473 &phba
->sli4_hba
.sli_intf
);
15474 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
15476 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
15482 /* Check the region signature first */
15483 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
15484 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15485 "2619 Config region 23 has bad signature\n");
15490 /* Check the data structure version */
15491 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
15492 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15493 "2620 Config region 23 has bad version\n");
15498 /* Parse TLV entries in the region */
15499 while (offset
< data_size
) {
15500 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
15503 * If the TLV is not driver specific TLV or driver id is
15504 * not linux driver id, skip the record.
15506 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
15507 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
15508 (rgn23_data
[offset
+ 3] != 0)) {
15509 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15513 /* Driver found a driver specific TLV in the config region */
15514 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
15519 * Search for configured port state sub-TLV.
15521 while ((offset
< data_size
) &&
15522 (tlv_offset
< sub_tlv_len
)) {
15523 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
15528 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
15529 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15530 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15534 /* This HBA contains PORT_STE configured */
15535 if (!rgn23_data
[offset
+ 2])
15536 phba
->hba_flag
|= LINK_DISABLED
;
15548 * lpfc_wr_object - write an object to the firmware
15549 * @phba: HBA structure that indicates port to create a queue on.
15550 * @dmabuf_list: list of dmabufs to write to the port.
15551 * @size: the total byte value of the objects to write to the port.
15552 * @offset: the current offset to be used to start the transfer.
15554 * This routine will create a wr_object mailbox command to send to the port.
15555 * the mailbox command will be constructed using the dma buffers described in
15556 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
15557 * BDEs that the imbedded mailbox can support. The @offset variable will be
15558 * used to indicate the starting offset of the transfer and will also return
15559 * the offset after the write object mailbox has completed. @size is used to
15560 * determine the end of the object and whether the eof bit should be set.
15562 * Return 0 is successful and offset will contain the the new offset to use
15563 * for the next write.
15564 * Return negative value for error cases.
15567 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
15568 uint32_t size
, uint32_t *offset
)
15570 struct lpfc_mbx_wr_object
*wr_object
;
15571 LPFC_MBOXQ_t
*mbox
;
15573 uint32_t shdr_status
, shdr_add_status
;
15575 union lpfc_sli4_cfg_shdr
*shdr
;
15576 struct lpfc_dmabuf
*dmabuf
;
15577 uint32_t written
= 0;
15579 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15583 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15584 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
15585 sizeof(struct lpfc_mbx_wr_object
) -
15586 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15588 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
15589 wr_object
->u
.request
.write_offset
= *offset
;
15590 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
15591 wr_object
->u
.request
.object_name
[0] =
15592 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
15593 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
15594 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
15595 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
15597 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
15598 wr_object
->u
.request
.bde
[i
].addrHigh
=
15599 putPaddrHigh(dmabuf
->phys
);
15600 if (written
+ SLI4_PAGE_SIZE
>= size
) {
15601 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15603 written
+= (size
- written
);
15604 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
15606 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15608 written
+= SLI4_PAGE_SIZE
;
15612 wr_object
->u
.request
.bde_count
= i
;
15613 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
15614 if (!phba
->sli4_hba
.intr_enable
)
15615 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15617 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15618 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15620 /* The IOCTL status is embedded in the mailbox subheader. */
15621 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
15622 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15623 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15624 if (rc
!= MBX_TIMEOUT
)
15625 mempool_free(mbox
, phba
->mbox_mem_pool
);
15626 if (shdr_status
|| shdr_add_status
|| rc
) {
15627 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15628 "3025 Write Object mailbox failed with "
15629 "status x%x add_status x%x, mbx status x%x\n",
15630 shdr_status
, shdr_add_status
, rc
);
15633 *offset
+= wr_object
->u
.response
.actual_write_length
;
15638 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
15639 * @vport: pointer to vport data structure.
15641 * This function iterate through the mailboxq and clean up all REG_LOGIN
15642 * and REG_VPI mailbox commands associated with the vport. This function
15643 * is called when driver want to restart discovery of the vport due to
15644 * a Clear Virtual Link event.
15647 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
15649 struct lpfc_hba
*phba
= vport
->phba
;
15650 LPFC_MBOXQ_t
*mb
, *nextmb
;
15651 struct lpfc_dmabuf
*mp
;
15652 struct lpfc_nodelist
*ndlp
;
15653 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
15654 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
15655 LIST_HEAD(mbox_cmd_list
);
15656 uint8_t restart_loop
;
15658 /* Clean up internally queued mailbox commands with the vport */
15659 spin_lock_irq(&phba
->hbalock
);
15660 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
15661 if (mb
->vport
!= vport
)
15664 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15665 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15668 list_del(&mb
->list
);
15669 list_add_tail(&mb
->list
, &mbox_cmd_list
);
15671 /* Clean up active mailbox command with the vport */
15672 mb
= phba
->sli
.mbox_active
;
15673 if (mb
&& (mb
->vport
== vport
)) {
15674 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
15675 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
15676 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15677 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15678 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15679 /* Put reference count for delayed processing */
15680 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
15681 /* Unregister the RPI when mailbox complete */
15682 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15685 /* Cleanup any mailbox completions which are not yet processed */
15688 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
15690 * If this mailox is already processed or it is
15691 * for another vport ignore it.
15693 if ((mb
->vport
!= vport
) ||
15694 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
15697 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15698 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15701 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15702 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15703 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15704 /* Unregister the RPI when mailbox complete */
15705 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15707 spin_unlock_irq(&phba
->hbalock
);
15708 spin_lock(shost
->host_lock
);
15709 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15710 spin_unlock(shost
->host_lock
);
15711 spin_lock_irq(&phba
->hbalock
);
15715 } while (restart_loop
);
15717 spin_unlock_irq(&phba
->hbalock
);
15719 /* Release the cleaned-up mailbox commands */
15720 while (!list_empty(&mbox_cmd_list
)) {
15721 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
15722 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15723 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
15725 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15728 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
15729 mb
->context2
= NULL
;
15731 spin_lock(shost
->host_lock
);
15732 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15733 spin_unlock(shost
->host_lock
);
15734 lpfc_nlp_put(ndlp
);
15737 mempool_free(mb
, phba
->mbox_mem_pool
);
15740 /* Release the ndlp with the cleaned-up active mailbox command */
15741 if (act_mbx_ndlp
) {
15742 spin_lock(shost
->host_lock
);
15743 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15744 spin_unlock(shost
->host_lock
);
15745 lpfc_nlp_put(act_mbx_ndlp
);
15750 * lpfc_drain_txq - Drain the txq
15751 * @phba: Pointer to HBA context object.
15753 * This function attempt to submit IOCBs on the txq
15754 * to the adapter. For SLI4 adapters, the txq contains
15755 * ELS IOCBs that have been deferred because the there
15756 * are no SGLs. This congestion can occur with large
15757 * vport counts during node discovery.
15761 lpfc_drain_txq(struct lpfc_hba
*phba
)
15763 LIST_HEAD(completions
);
15764 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
15765 struct lpfc_iocbq
*piocbq
= 0;
15766 unsigned long iflags
= 0;
15767 char *fail_msg
= NULL
;
15768 struct lpfc_sglq
*sglq
;
15769 union lpfc_wqe wqe
;
15771 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15772 if (pring
->txq_cnt
> pring
->txq_max
)
15773 pring
->txq_max
= pring
->txq_cnt
;
15775 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15777 while (pring
->txq_cnt
) {
15778 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15780 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
15781 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
15783 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
15784 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15788 /* The txq_cnt out of sync. This should
15791 sglq
= __lpfc_clear_active_sglq(phba
,
15792 sglq
->sli4_lxritag
);
15793 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15794 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15795 "2823 txq empty and txq_cnt is %d\n ",
15801 /* The xri and iocb resources secured,
15802 * attempt to issue request
15804 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
15805 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
15806 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
15807 fail_msg
= "to convert bpl to sgl";
15808 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
15809 fail_msg
= "to convert iocb to wqe";
15810 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
15811 fail_msg
= " - Wq is full";
15813 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
15816 /* Failed means we can't issue and need to cancel */
15817 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15818 "2822 IOCB failed %s iotag 0x%x "
15821 piocbq
->iotag
, piocbq
->sli4_xritag
);
15822 list_add_tail(&piocbq
->list
, &completions
);
15824 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15827 /* Cancel all the IOCBs that cannot be issued */
15828 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
15829 IOERR_SLI_ABORTED
);
15831 return pring
->txq_cnt
;