1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <linux/aer.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
48 #include "lpfc_vport.h"
50 /* There are only four IOCB completion types. */
51 typedef enum _lpfc_iocb_type
{
59 /* Provide function prototypes local to this module. */
60 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
62 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
63 uint8_t *, uint32_t *);
64 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
66 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*, struct lpfc_queue
*,
70 static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*, struct list_head
*,
72 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*, struct lpfc_eqe
*,
76 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
82 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
83 * @q: The Work Queue to operate on.
84 * @wqe: The work Queue Entry to put on the Work queue.
86 * This routine will copy the contents of @wqe to the next available entry on
87 * the @q. This function will then ring the Work Queue Doorbell to signal the
88 * HBA to start processing the Work Queue Entry. This function returns 0 if
89 * successful. If no entries are available on @q then this function will return
91 * The caller is expected to hold the hbalock when calling this routine.
94 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
96 union lpfc_wqe
*temp_wqe
;
97 struct lpfc_register doorbell
;
101 /* sanity check on queue memory */
104 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
106 /* If the host has not yet processed the next entry then we are done */
107 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
108 if (idx
== q
->hba_index
) {
113 /* set consumption flag every once in a while */
114 if (!((q
->host_index
+ 1) % q
->entry_repost
))
115 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
116 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
117 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
118 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
120 /* Update the host index before invoking device */
121 host_index
= q
->host_index
;
127 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
128 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
129 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
130 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
136 * lpfc_sli4_wq_release - Updates internal hba index for WQ
137 * @q: The Work Queue to operate on.
138 * @index: The index to advance the hba index to.
140 * This routine will update the HBA index of a queue to reflect consumption of
141 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
142 * an entry the host calls this function to update the queue's internal
143 * pointers. This routine returns the number of entries that were consumed by
147 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
149 uint32_t released
= 0;
151 /* sanity check on queue memory */
155 if (q
->hba_index
== index
)
158 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
160 } while (q
->hba_index
!= index
);
165 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
166 * @q: The Mailbox Queue to operate on.
167 * @wqe: The Mailbox Queue Entry to put on the Work queue.
169 * This routine will copy the contents of @mqe to the next available entry on
170 * the @q. This function will then ring the Work Queue Doorbell to signal the
171 * HBA to start processing the Work Queue Entry. This function returns 0 if
172 * successful. If no entries are available on @q then this function will return
174 * The caller is expected to hold the hbalock when calling this routine.
177 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
179 struct lpfc_mqe
*temp_mqe
;
180 struct lpfc_register doorbell
;
183 /* sanity check on queue memory */
186 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
188 /* If the host has not yet processed the next entry then we are done */
189 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
191 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
192 /* Save off the mailbox pointer for completion */
193 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
195 /* Update the host index before invoking device */
196 host_index
= q
->host_index
;
197 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
201 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
202 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
203 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
208 * lpfc_sli4_mq_release - Updates internal hba index for MQ
209 * @q: The Mailbox Queue to operate on.
211 * This routine will update the HBA index of a queue to reflect consumption of
212 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
213 * an entry the host calls this function to update the queue's internal
214 * pointers. This routine returns the number of entries that were consumed by
218 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
220 /* sanity check on queue memory */
224 /* Clear the mailbox pointer for completion */
225 q
->phba
->mbox
= NULL
;
226 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
231 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
232 * @q: The Event Queue to get the first valid EQE from
234 * This routine will get the first valid Event Queue Entry from @q, update
235 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
236 * the Queue (no more work to do), or the Queue is full of EQEs that have been
237 * processed, but not popped back to the HBA then this routine will return NULL.
239 static struct lpfc_eqe
*
240 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
242 struct lpfc_eqe
*eqe
;
245 /* sanity check on queue memory */
248 eqe
= q
->qe
[q
->hba_index
].eqe
;
250 /* If the next EQE is not valid then we are done */
251 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
253 /* If the host has not yet processed the next entry then we are done */
254 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
255 if (idx
== q
->host_index
)
263 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
264 * @q: The Event Queue to disable interrupts
268 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
270 struct lpfc_register doorbell
;
273 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
274 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
275 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
276 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
277 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
278 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
282 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
283 * @q: The Event Queue that the host has completed processing for.
284 * @arm: Indicates whether the host wants to arms this CQ.
286 * This routine will mark all Event Queue Entries on @q, from the last
287 * known completed entry to the last entry that was processed, as completed
288 * by clearing the valid bit for each completion queue entry. Then it will
289 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
290 * The internal host index in the @q will be updated by this routine to indicate
291 * that the host has finished processing the entries. The @arm parameter
292 * indicates that the queue should be rearmed when ringing the doorbell.
294 * This function will return the number of EQEs that were popped.
297 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
299 uint32_t released
= 0;
300 struct lpfc_eqe
*temp_eqe
;
301 struct lpfc_register doorbell
;
303 /* sanity check on queue memory */
307 /* while there are valid entries */
308 while (q
->hba_index
!= q
->host_index
) {
309 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
310 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
312 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
314 if (unlikely(released
== 0 && !arm
))
317 /* ring doorbell for number popped */
320 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
321 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
323 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
324 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
325 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
326 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
327 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
328 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
329 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
330 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
331 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
336 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
337 * @q: The Completion Queue to get the first valid CQE from
339 * This routine will get the first valid Completion Queue Entry from @q, update
340 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
341 * the Queue (no more work to do), or the Queue is full of CQEs that have been
342 * processed, but not popped back to the HBA then this routine will return NULL.
344 static struct lpfc_cqe
*
345 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
347 struct lpfc_cqe
*cqe
;
350 /* sanity check on queue memory */
354 /* If the next CQE is not valid then we are done */
355 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
357 /* If the host has not yet processed the next entry then we are done */
358 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
359 if (idx
== q
->host_index
)
362 cqe
= q
->qe
[q
->hba_index
].cqe
;
368 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
369 * @q: The Completion Queue that the host has completed processing for.
370 * @arm: Indicates whether the host wants to arms this CQ.
372 * This routine will mark all Completion queue entries on @q, from the last
373 * known completed entry to the last entry that was processed, as completed
374 * by clearing the valid bit for each completion queue entry. Then it will
375 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
376 * The internal host index in the @q will be updated by this routine to indicate
377 * that the host has finished processing the entries. The @arm parameter
378 * indicates that the queue should be rearmed when ringing the doorbell.
380 * This function will return the number of CQEs that were released.
383 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
385 uint32_t released
= 0;
386 struct lpfc_cqe
*temp_qe
;
387 struct lpfc_register doorbell
;
389 /* sanity check on queue memory */
392 /* while there are valid entries */
393 while (q
->hba_index
!= q
->host_index
) {
394 temp_qe
= q
->qe
[q
->host_index
].cqe
;
395 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
397 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
399 if (unlikely(released
== 0 && !arm
))
402 /* ring doorbell for number popped */
405 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
406 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
407 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
408 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
409 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
410 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
411 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
416 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
417 * @q: The Header Receive Queue to operate on.
418 * @wqe: The Receive Queue Entry to put on the Receive queue.
420 * This routine will copy the contents of @wqe to the next available entry on
421 * the @q. This function will then ring the Receive Queue Doorbell to signal the
422 * HBA to start processing the Receive Queue Entry. This function returns the
423 * index that the rqe was copied to if successful. If no entries are available
424 * on @q then this function will return -ENOMEM.
425 * The caller is expected to hold the hbalock when calling this routine.
428 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
429 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
431 struct lpfc_rqe
*temp_hrqe
;
432 struct lpfc_rqe
*temp_drqe
;
433 struct lpfc_register doorbell
;
434 int put_index
= hq
->host_index
;
436 /* sanity check on queue memory */
437 if (unlikely(!hq
) || unlikely(!dq
))
439 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
440 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
442 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
444 if (hq
->host_index
!= dq
->host_index
)
446 /* If the host has not yet processed the next entry then we are done */
447 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
449 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
450 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
452 /* Update the host index to point to the next slot */
453 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
454 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
456 /* Ring The Header Receive Queue Doorbell */
457 if (!(hq
->host_index
% hq
->entry_repost
)) {
459 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
461 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
462 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
468 * lpfc_sli4_rq_release - Updates internal hba index for RQ
469 * @q: The Header Receive Queue to operate on.
471 * This routine will update the HBA index of a queue to reflect consumption of
472 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
473 * consumed an entry the host calls this function to update the queue's
474 * internal pointers. This routine returns the number of entries that were
475 * consumed by the HBA.
478 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
480 /* sanity check on queue memory */
481 if (unlikely(!hq
) || unlikely(!dq
))
484 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
486 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
487 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
492 * lpfc_cmd_iocb - Get next command iocb entry in the ring
493 * @phba: Pointer to HBA context object.
494 * @pring: Pointer to driver SLI ring object.
496 * This function returns pointer to next command iocb entry
497 * in the command ring. The caller must hold hbalock to prevent
498 * other threads consume the next command iocb.
499 * SLI-2/SLI-3 provide different sized iocbs.
501 static inline IOCB_t
*
502 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
504 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
505 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
509 * lpfc_resp_iocb - Get next response iocb entry in the ring
510 * @phba: Pointer to HBA context object.
511 * @pring: Pointer to driver SLI ring object.
513 * This function returns pointer to next response iocb entry
514 * in the response ring. The caller must hold hbalock to make sure
515 * that no other thread consume the next response iocb.
516 * SLI-2/SLI-3 provide different sized iocbs.
518 static inline IOCB_t
*
519 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
521 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
522 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
526 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
527 * @phba: Pointer to HBA context object.
529 * This function is called with hbalock held. This function
530 * allocates a new driver iocb object from the iocb pool. If the
531 * allocation is successful, it returns pointer to the newly
532 * allocated iocb object else it returns NULL.
535 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
537 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
538 struct lpfc_iocbq
* iocbq
= NULL
;
540 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
543 if (phba
->iocb_cnt
> phba
->iocb_max
)
544 phba
->iocb_max
= phba
->iocb_cnt
;
549 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
550 * @phba: Pointer to HBA context object.
551 * @xritag: XRI value.
553 * This function clears the sglq pointer from the array of acive
554 * sglq's. The xritag that is passed in is used to index into the
555 * array. Before the xritag can be used it needs to be adjusted
556 * by subtracting the xribase.
558 * Returns sglq ponter = success, NULL = Failure.
560 static struct lpfc_sglq
*
561 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
563 struct lpfc_sglq
*sglq
;
565 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
566 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
571 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
572 * @phba: Pointer to HBA context object.
573 * @xritag: XRI value.
575 * This function returns the sglq pointer from the array of acive
576 * sglq's. The xritag that is passed in is used to index into the
577 * array. Before the xritag can be used it needs to be adjusted
578 * by subtracting the xribase.
580 * Returns sglq ponter = success, NULL = Failure.
583 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
585 struct lpfc_sglq
*sglq
;
587 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
592 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
593 * @phba: Pointer to HBA context object.
594 * @xritag: xri used in this exchange.
595 * @rrq: The RRQ to be cleared.
599 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
601 struct lpfc_node_rrq
*rrq
)
603 struct lpfc_nodelist
*ndlp
= NULL
;
605 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
606 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
608 /* The target DID could have been swapped (cable swap)
609 * we should use the ndlp from the findnode if it is
612 if ((!ndlp
) && rrq
->ndlp
)
618 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
)) {
621 rrq
->rrq_stop_time
= 0;
624 mempool_free(rrq
, phba
->rrq_pool
);
628 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
629 * @phba: Pointer to HBA context object.
631 * This function is called with hbalock held. This function
632 * Checks if stop_time (ratov from setting rrq active) has
633 * been reached, if it has and the send_rrq flag is set then
634 * it will call lpfc_send_rrq. If the send_rrq flag is not set
635 * then it will just call the routine to clear the rrq and
636 * free the rrq resource.
637 * The timer is set to the next rrq that is going to expire before
638 * leaving the routine.
642 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
644 struct lpfc_node_rrq
*rrq
;
645 struct lpfc_node_rrq
*nextrrq
;
646 unsigned long next_time
;
647 unsigned long iflags
;
650 spin_lock_irqsave(&phba
->hbalock
, iflags
);
651 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
652 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
653 list_for_each_entry_safe(rrq
, nextrrq
,
654 &phba
->active_rrq_list
, list
) {
655 if (time_after(jiffies
, rrq
->rrq_stop_time
))
656 list_move(&rrq
->list
, &send_rrq
);
657 else if (time_before(rrq
->rrq_stop_time
, next_time
))
658 next_time
= rrq
->rrq_stop_time
;
660 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
661 if (!list_empty(&phba
->active_rrq_list
))
662 mod_timer(&phba
->rrq_tmr
, next_time
);
663 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
664 list_del(&rrq
->list
);
666 /* this call will free the rrq */
667 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
668 else if (lpfc_send_rrq(phba
, rrq
)) {
669 /* if we send the rrq then the completion handler
670 * will clear the bit in the xribitmap.
672 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
679 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
680 * @vport: Pointer to vport context object.
681 * @xri: The xri used in the exchange.
682 * @did: The targets DID for this exchange.
684 * returns NULL = rrq not found in the phba->active_rrq_list.
685 * rrq = rrq for this xri and target.
687 struct lpfc_node_rrq
*
688 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
690 struct lpfc_hba
*phba
= vport
->phba
;
691 struct lpfc_node_rrq
*rrq
;
692 struct lpfc_node_rrq
*nextrrq
;
693 unsigned long iflags
;
695 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
697 spin_lock_irqsave(&phba
->hbalock
, iflags
);
698 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
699 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
700 rrq
->nlp_DID
== did
){
701 list_del(&rrq
->list
);
702 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
706 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
711 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
712 * @vport: Pointer to vport context object.
713 * @ndlp: Pointer to the lpfc_node_list structure.
714 * If ndlp is NULL Remove all active RRQs for this vport from the
715 * phba->active_rrq_list and clear the rrq.
716 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
719 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
722 struct lpfc_hba
*phba
= vport
->phba
;
723 struct lpfc_node_rrq
*rrq
;
724 struct lpfc_node_rrq
*nextrrq
;
725 unsigned long iflags
;
728 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
731 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
732 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
734 spin_lock_irqsave(&phba
->hbalock
, iflags
);
735 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
736 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
737 list_move(&rrq
->list
, &rrq_list
);
738 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
740 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
741 list_del(&rrq
->list
);
742 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
747 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
748 * @phba: Pointer to HBA context object.
750 * Remove all rrqs from the phba->active_rrq_list and free them by
751 * calling __lpfc_clr_active_rrq
755 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
757 struct lpfc_node_rrq
*rrq
;
758 struct lpfc_node_rrq
*nextrrq
;
759 unsigned long next_time
;
760 unsigned long iflags
;
763 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
765 spin_lock_irqsave(&phba
->hbalock
, iflags
);
766 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
767 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
768 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
769 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
771 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
772 list_del(&rrq
->list
);
773 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
775 if (!list_empty(&phba
->active_rrq_list
))
776 mod_timer(&phba
->rrq_tmr
, next_time
);
781 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
782 * @phba: Pointer to HBA context object.
783 * @ndlp: Targets nodelist pointer for this exchange.
784 * @xritag the xri in the bitmap to test.
786 * This function is called with hbalock held. This function
787 * returns 0 = rrq not active for this xri
788 * 1 = rrq is valid for this xri.
791 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
796 if (test_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
803 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
804 * @phba: Pointer to HBA context object.
805 * @ndlp: nodelist pointer for this target.
806 * @xritag: xri used in this exchange.
807 * @rxid: Remote Exchange ID.
808 * @send_rrq: Flag used to determine if we should send rrq els cmd.
810 * This function takes the hbalock.
811 * The active bit is always set in the active rrq xri_bitmap even
812 * if there is no slot avaiable for the other rrq information.
814 * returns 0 rrq actived for this xri
815 * < 0 No memory or invalid ndlp.
818 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
819 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
821 unsigned long iflags
;
822 struct lpfc_node_rrq
*rrq
;
828 if (!phba
->cfg_enable_rrq
)
831 spin_lock_irqsave(&phba
->hbalock
, iflags
);
832 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
833 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
838 * set the active bit even if there is no mem available.
840 if (NLP_CHK_FREE_REQ(ndlp
))
843 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
846 if (test_and_set_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
849 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
850 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
852 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
853 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
854 " DID:0x%x Send:%d\n",
855 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
858 rrq
->send_rrq
= send_rrq
;
859 rrq
->xritag
= xritag
;
860 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
862 rrq
->nlp_DID
= ndlp
->nlp_DID
;
863 rrq
->vport
= ndlp
->vport
;
865 rrq
->send_rrq
= send_rrq
;
866 spin_lock_irqsave(&phba
->hbalock
, iflags
);
867 empty
= list_empty(&phba
->active_rrq_list
);
868 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
869 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
871 lpfc_worker_wake_up(phba
);
872 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
875 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
876 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
877 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
878 " DID:0x%x Send:%d\n",
879 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
884 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
885 * @phba: Pointer to HBA context object.
886 * @piocb: Pointer to the iocbq.
888 * This function is called with hbalock held. This function
889 * gets a new driver sglq object from the sglq list. If the
890 * list is not empty then it is successful, it returns pointer to the newly
891 * allocated sglq object else it returns NULL.
893 static struct lpfc_sglq
*
894 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
896 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
897 struct lpfc_sglq
*sglq
= NULL
;
898 struct lpfc_sglq
*start_sglq
= NULL
;
899 struct lpfc_scsi_buf
*lpfc_cmd
;
900 struct lpfc_nodelist
*ndlp
;
903 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
904 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
905 ndlp
= lpfc_cmd
->rdata
->pnode
;
906 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
907 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
908 ndlp
= piocbq
->context_un
.ndlp
;
909 else if ((piocbq
->iocb
.ulpCommand
== CMD_ELS_REQUEST64_CR
) &&
910 (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
911 ndlp
= piocbq
->context_un
.ndlp
;
913 ndlp
= piocbq
->context1
;
915 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
920 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_lxritag
)) {
921 /* This xri has an rrq outstanding for this DID.
922 * put it back in the list and get another xri.
924 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
926 list_remove_head(lpfc_sgl_list
, sglq
,
927 struct lpfc_sglq
, list
);
928 if (sglq
== start_sglq
) {
936 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
937 sglq
->state
= SGL_ALLOCATED
;
943 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
944 * @phba: Pointer to HBA context object.
946 * This function is called with no lock held. This function
947 * allocates a new driver iocb object from the iocb pool. If the
948 * allocation is successful, it returns pointer to the newly
949 * allocated iocb object else it returns NULL.
952 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
954 struct lpfc_iocbq
* iocbq
= NULL
;
955 unsigned long iflags
;
957 spin_lock_irqsave(&phba
->hbalock
, iflags
);
958 iocbq
= __lpfc_sli_get_iocbq(phba
);
959 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
964 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
965 * @phba: Pointer to HBA context object.
966 * @iocbq: Pointer to driver iocb object.
968 * This function is called with hbalock held to release driver
969 * iocb object to the iocb pool. The iotag in the iocb object
970 * does not change for each use of the iocb object. This function
971 * clears all other fields of the iocb object when it is freed.
972 * The sqlq structure that holds the xritag and phys and virtual
973 * mappings for the scatter gather list is retrieved from the
974 * active array of sglq. The get of the sglq pointer also clears
975 * the entry in the array. If the status of the IO indiactes that
976 * this IO was aborted then the sglq entry it put on the
977 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
978 * IO has good status or fails for any other reason then the sglq
979 * entry is added to the free list (lpfc_sgl_list).
982 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
984 struct lpfc_sglq
*sglq
;
985 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
986 unsigned long iflag
= 0;
987 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
989 if (iocbq
->sli4_xritag
== NO_XRI
)
992 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
995 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
996 (sglq
->state
!= SGL_XRI_ABORTED
)) {
997 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
999 list_add(&sglq
->list
,
1000 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1001 spin_unlock_irqrestore(
1002 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
1004 sglq
->state
= SGL_FREED
;
1006 list_add_tail(&sglq
->list
,
1007 &phba
->sli4_hba
.lpfc_sgl_list
);
1009 /* Check if TXQ queue needs to be serviced */
1011 lpfc_worker_wake_up(phba
);
1017 * Clean all volatile data fields, preserve iotag and node struct.
1019 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1020 iocbq
->sli4_lxritag
= NO_XRI
;
1021 iocbq
->sli4_xritag
= NO_XRI
;
1022 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1027 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1028 * @phba: Pointer to HBA context object.
1029 * @iocbq: Pointer to driver iocb object.
1031 * This function is called with hbalock held to release driver
1032 * iocb object to the iocb pool. The iotag in the iocb object
1033 * does not change for each use of the iocb object. This function
1034 * clears all other fields of the iocb object when it is freed.
1037 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1039 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1042 * Clean all volatile data fields, preserve iotag and node struct.
1044 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1045 iocbq
->sli4_xritag
= NO_XRI
;
1046 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1050 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1051 * @phba: Pointer to HBA context object.
1052 * @iocbq: Pointer to driver iocb object.
1054 * This function is called with hbalock held to release driver
1055 * iocb object to the iocb pool. The iotag in the iocb object
1056 * does not change for each use of the iocb object. This function
1057 * clears all other fields of the iocb object when it is freed.
1060 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1062 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1067 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1068 * @phba: Pointer to HBA context object.
1069 * @iocbq: Pointer to driver iocb object.
1071 * This function is called with no lock held to release the iocb to
1075 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1077 unsigned long iflags
;
1080 * Clean all volatile data fields, preserve iotag and node struct.
1082 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1083 __lpfc_sli_release_iocbq(phba
, iocbq
);
1084 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1088 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1089 * @phba: Pointer to HBA context object.
1090 * @iocblist: List of IOCBs.
1091 * @ulpstatus: ULP status in IOCB command field.
1092 * @ulpWord4: ULP word-4 in IOCB command field.
1094 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1095 * on the list by invoking the complete callback function associated with the
1096 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1100 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1101 uint32_t ulpstatus
, uint32_t ulpWord4
)
1103 struct lpfc_iocbq
*piocb
;
1105 while (!list_empty(iocblist
)) {
1106 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1108 if (!piocb
->iocb_cmpl
)
1109 lpfc_sli_release_iocbq(phba
, piocb
);
1111 piocb
->iocb
.ulpStatus
= ulpstatus
;
1112 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1113 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1120 * lpfc_sli_iocb_cmd_type - Get the iocb type
1121 * @iocb_cmnd: iocb command code.
1123 * This function is called by ring event handler function to get the iocb type.
1124 * This function translates the iocb command to an iocb command type used to
1125 * decide the final disposition of each completed IOCB.
1126 * The function returns
1127 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1128 * LPFC_SOL_IOCB if it is a solicited iocb completion
1129 * LPFC_ABORT_IOCB if it is an abort iocb
1130 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1132 * The caller is not required to hold any lock.
1134 static lpfc_iocb_type
1135 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1137 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1139 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1142 switch (iocb_cmnd
) {
1143 case CMD_XMIT_SEQUENCE_CR
:
1144 case CMD_XMIT_SEQUENCE_CX
:
1145 case CMD_XMIT_BCAST_CN
:
1146 case CMD_XMIT_BCAST_CX
:
1147 case CMD_ELS_REQUEST_CR
:
1148 case CMD_ELS_REQUEST_CX
:
1149 case CMD_CREATE_XRI_CR
:
1150 case CMD_CREATE_XRI_CX
:
1151 case CMD_GET_RPI_CN
:
1152 case CMD_XMIT_ELS_RSP_CX
:
1153 case CMD_GET_RPI_CR
:
1154 case CMD_FCP_IWRITE_CR
:
1155 case CMD_FCP_IWRITE_CX
:
1156 case CMD_FCP_IREAD_CR
:
1157 case CMD_FCP_IREAD_CX
:
1158 case CMD_FCP_ICMND_CR
:
1159 case CMD_FCP_ICMND_CX
:
1160 case CMD_FCP_TSEND_CX
:
1161 case CMD_FCP_TRSP_CX
:
1162 case CMD_FCP_TRECEIVE_CX
:
1163 case CMD_FCP_AUTO_TRSP_CX
:
1164 case CMD_ADAPTER_MSG
:
1165 case CMD_ADAPTER_DUMP
:
1166 case CMD_XMIT_SEQUENCE64_CR
:
1167 case CMD_XMIT_SEQUENCE64_CX
:
1168 case CMD_XMIT_BCAST64_CN
:
1169 case CMD_XMIT_BCAST64_CX
:
1170 case CMD_ELS_REQUEST64_CR
:
1171 case CMD_ELS_REQUEST64_CX
:
1172 case CMD_FCP_IWRITE64_CR
:
1173 case CMD_FCP_IWRITE64_CX
:
1174 case CMD_FCP_IREAD64_CR
:
1175 case CMD_FCP_IREAD64_CX
:
1176 case CMD_FCP_ICMND64_CR
:
1177 case CMD_FCP_ICMND64_CX
:
1178 case CMD_FCP_TSEND64_CX
:
1179 case CMD_FCP_TRSP64_CX
:
1180 case CMD_FCP_TRECEIVE64_CX
:
1181 case CMD_GEN_REQUEST64_CR
:
1182 case CMD_GEN_REQUEST64_CX
:
1183 case CMD_XMIT_ELS_RSP64_CX
:
1184 case DSSCMD_IWRITE64_CR
:
1185 case DSSCMD_IWRITE64_CX
:
1186 case DSSCMD_IREAD64_CR
:
1187 case DSSCMD_IREAD64_CX
:
1188 type
= LPFC_SOL_IOCB
;
1190 case CMD_ABORT_XRI_CN
:
1191 case CMD_ABORT_XRI_CX
:
1192 case CMD_CLOSE_XRI_CN
:
1193 case CMD_CLOSE_XRI_CX
:
1194 case CMD_XRI_ABORTED_CX
:
1195 case CMD_ABORT_MXRI64_CN
:
1196 case CMD_XMIT_BLS_RSP64_CX
:
1197 type
= LPFC_ABORT_IOCB
;
1199 case CMD_RCV_SEQUENCE_CX
:
1200 case CMD_RCV_ELS_REQ_CX
:
1201 case CMD_RCV_SEQUENCE64_CX
:
1202 case CMD_RCV_ELS_REQ64_CX
:
1203 case CMD_ASYNC_STATUS
:
1204 case CMD_IOCB_RCV_SEQ64_CX
:
1205 case CMD_IOCB_RCV_ELS64_CX
:
1206 case CMD_IOCB_RCV_CONT64_CX
:
1207 case CMD_IOCB_RET_XRI64_CX
:
1208 type
= LPFC_UNSOL_IOCB
;
1210 case CMD_IOCB_XMIT_MSEQ64_CR
:
1211 case CMD_IOCB_XMIT_MSEQ64_CX
:
1212 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1213 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1214 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1215 case CMD_IOCB_ABORT_EXTENDED_CN
:
1216 case CMD_IOCB_RET_HBQE64_CN
:
1217 case CMD_IOCB_FCP_IBIDIR64_CR
:
1218 case CMD_IOCB_FCP_IBIDIR64_CX
:
1219 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1220 case CMD_IOCB_LOGENTRY_CN
:
1221 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1222 printk("%s - Unhandled SLI-3 Command x%x\n",
1223 __func__
, iocb_cmnd
);
1224 type
= LPFC_UNKNOWN_IOCB
;
1227 type
= LPFC_UNKNOWN_IOCB
;
1235 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1236 * @phba: Pointer to HBA context object.
1238 * This function is called from SLI initialization code
1239 * to configure every ring of the HBA's SLI interface. The
1240 * caller is not required to hold any lock. This function issues
1241 * a config_ring mailbox command for each ring.
1242 * This function returns zero if successful else returns a negative
1246 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1248 struct lpfc_sli
*psli
= &phba
->sli
;
1253 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1257 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1258 for (i
= 0; i
< psli
->num_rings
; i
++) {
1259 lpfc_config_ring(phba
, i
, pmb
);
1260 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1261 if (rc
!= MBX_SUCCESS
) {
1262 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1263 "0446 Adapter failed to init (%d), "
1264 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1266 rc
, pmbox
->mbxCommand
,
1267 pmbox
->mbxStatus
, i
);
1268 phba
->link_state
= LPFC_HBA_ERROR
;
1273 mempool_free(pmb
, phba
->mbox_mem_pool
);
1278 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1279 * @phba: Pointer to HBA context object.
1280 * @pring: Pointer to driver SLI ring object.
1281 * @piocb: Pointer to the driver iocb object.
1283 * This function is called with hbalock held. The function adds the
1284 * new iocb to txcmplq of the given ring. This function always returns
1285 * 0. If this function is called for ELS ring, this function checks if
1286 * there is a vport associated with the ELS command. This function also
1287 * starts els_tmofunc timer if this is an ELS command.
1290 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1291 struct lpfc_iocbq
*piocb
)
1293 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1294 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1295 pring
->txcmplq_cnt
++;
1296 if (pring
->txcmplq_cnt
> pring
->txcmplq_max
)
1297 pring
->txcmplq_max
= pring
->txcmplq_cnt
;
1299 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1300 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1301 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1305 mod_timer(&piocb
->vport
->els_tmofunc
,
1306 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1314 * lpfc_sli_ringtx_get - Get first element of the txq
1315 * @phba: Pointer to HBA context object.
1316 * @pring: Pointer to driver SLI ring object.
1318 * This function is called with hbalock held to get next
1319 * iocb in txq of the given ring. If there is any iocb in
1320 * the txq, the function returns first iocb in the list after
1321 * removing the iocb from the list, else it returns NULL.
1324 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1326 struct lpfc_iocbq
*cmd_iocb
;
1328 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1329 if (cmd_iocb
!= NULL
)
1335 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1336 * @phba: Pointer to HBA context object.
1337 * @pring: Pointer to driver SLI ring object.
1339 * This function is called with hbalock held and the caller must post the
1340 * iocb without releasing the lock. If the caller releases the lock,
1341 * iocb slot returned by the function is not guaranteed to be available.
1342 * The function returns pointer to the next available iocb slot if there
1343 * is available slot in the ring, else it returns NULL.
1344 * If the get index of the ring is ahead of the put index, the function
1345 * will post an error attention event to the worker thread to take the
1346 * HBA to offline state.
1349 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1351 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1352 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1353 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1354 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1355 pring
->sli
.sli3
.next_cmdidx
= 0;
1357 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1358 pring
->sli
.sli3
.next_cmdidx
)) {
1360 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1362 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1363 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1364 "0315 Ring %d issue: portCmdGet %d "
1365 "is bigger than cmd ring %d\n",
1367 pring
->sli
.sli3
.local_getidx
,
1370 phba
->link_state
= LPFC_HBA_ERROR
;
1372 * All error attention handlers are posted to
1375 phba
->work_ha
|= HA_ERATT
;
1376 phba
->work_hs
= HS_FFER3
;
1378 lpfc_worker_wake_up(phba
);
1383 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1387 return lpfc_cmd_iocb(phba
, pring
);
1391 * lpfc_sli_next_iotag - Get an iotag for the iocb
1392 * @phba: Pointer to HBA context object.
1393 * @iocbq: Pointer to driver iocb object.
1395 * This function gets an iotag for the iocb. If there is no unused iotag and
1396 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1397 * array and assigns a new iotag.
1398 * The function returns the allocated iotag if successful, else returns zero.
1399 * Zero is not a valid iotag.
1400 * The caller is not required to hold any lock.
1403 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1405 struct lpfc_iocbq
**new_arr
;
1406 struct lpfc_iocbq
**old_arr
;
1408 struct lpfc_sli
*psli
= &phba
->sli
;
1411 spin_lock_irq(&phba
->hbalock
);
1412 iotag
= psli
->last_iotag
;
1413 if(++iotag
< psli
->iocbq_lookup_len
) {
1414 psli
->last_iotag
= iotag
;
1415 psli
->iocbq_lookup
[iotag
] = iocbq
;
1416 spin_unlock_irq(&phba
->hbalock
);
1417 iocbq
->iotag
= iotag
;
1419 } else if (psli
->iocbq_lookup_len
< (0xffff
1420 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1421 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1422 spin_unlock_irq(&phba
->hbalock
);
1423 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1426 spin_lock_irq(&phba
->hbalock
);
1427 old_arr
= psli
->iocbq_lookup
;
1428 if (new_len
<= psli
->iocbq_lookup_len
) {
1429 /* highly unprobable case */
1431 iotag
= psli
->last_iotag
;
1432 if(++iotag
< psli
->iocbq_lookup_len
) {
1433 psli
->last_iotag
= iotag
;
1434 psli
->iocbq_lookup
[iotag
] = iocbq
;
1435 spin_unlock_irq(&phba
->hbalock
);
1436 iocbq
->iotag
= iotag
;
1439 spin_unlock_irq(&phba
->hbalock
);
1442 if (psli
->iocbq_lookup
)
1443 memcpy(new_arr
, old_arr
,
1444 ((psli
->last_iotag
+ 1) *
1445 sizeof (struct lpfc_iocbq
*)));
1446 psli
->iocbq_lookup
= new_arr
;
1447 psli
->iocbq_lookup_len
= new_len
;
1448 psli
->last_iotag
= iotag
;
1449 psli
->iocbq_lookup
[iotag
] = iocbq
;
1450 spin_unlock_irq(&phba
->hbalock
);
1451 iocbq
->iotag
= iotag
;
1456 spin_unlock_irq(&phba
->hbalock
);
1458 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1459 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1466 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1467 * @phba: Pointer to HBA context object.
1468 * @pring: Pointer to driver SLI ring object.
1469 * @iocb: Pointer to iocb slot in the ring.
1470 * @nextiocb: Pointer to driver iocb object which need to be
1471 * posted to firmware.
1473 * This function is called with hbalock held to post a new iocb to
1474 * the firmware. This function copies the new iocb to ring iocb slot and
1475 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1476 * a completion call back for this iocb else the function will free the
1480 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1481 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1486 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1489 if (pring
->ringno
== LPFC_ELS_RING
) {
1490 lpfc_debugfs_slow_ring_trc(phba
,
1491 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1492 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1493 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1494 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1498 * Issue iocb command to adapter
1500 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1502 pring
->stats
.iocb_cmd
++;
1505 * If there is no completion routine to call, we can release the
1506 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1507 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1509 if (nextiocb
->iocb_cmpl
)
1510 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1512 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1515 * Let the HBA know what IOCB slot will be the next one the
1516 * driver will put a command into.
1518 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1519 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1523 * lpfc_sli_update_full_ring - Update the chip attention register
1524 * @phba: Pointer to HBA context object.
1525 * @pring: Pointer to driver SLI ring object.
1527 * The caller is not required to hold any lock for calling this function.
1528 * This function updates the chip attention bits for the ring to inform firmware
1529 * that there are pending work to be done for this ring and requests an
1530 * interrupt when there is space available in the ring. This function is
1531 * called when the driver is unable to post more iocbs to the ring due
1532 * to unavailability of space in the ring.
1535 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1537 int ringno
= pring
->ringno
;
1539 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1544 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1545 * The HBA will tell us when an IOCB entry is available.
1547 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1548 readl(phba
->CAregaddr
); /* flush */
1550 pring
->stats
.iocb_cmd_full
++;
1554 * lpfc_sli_update_ring - Update chip attention register
1555 * @phba: Pointer to HBA context object.
1556 * @pring: Pointer to driver SLI ring object.
1558 * This function updates the chip attention register bit for the
1559 * given ring to inform HBA that there is more work to be done
1560 * in this ring. The caller is not required to hold any lock.
1563 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1565 int ringno
= pring
->ringno
;
1568 * Tell the HBA that there is work to do in this ring.
1570 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1572 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1573 readl(phba
->CAregaddr
); /* flush */
1578 * lpfc_sli_resume_iocb - Process iocbs in the txq
1579 * @phba: Pointer to HBA context object.
1580 * @pring: Pointer to driver SLI ring object.
1582 * This function is called with hbalock held to post pending iocbs
1583 * in the txq to the firmware. This function is called when driver
1584 * detects space available in the ring.
1587 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1590 struct lpfc_iocbq
*nextiocb
;
1594 * (a) there is anything on the txq to send
1596 * (c) link attention events can be processed (fcp ring only)
1597 * (d) IOCB processing is not blocked by the outstanding mbox command.
1599 if (pring
->txq_cnt
&&
1600 lpfc_is_link_up(phba
) &&
1601 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1602 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1604 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1605 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1606 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1609 lpfc_sli_update_ring(phba
, pring
);
1611 lpfc_sli_update_full_ring(phba
, pring
);
1618 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1619 * @phba: Pointer to HBA context object.
1620 * @hbqno: HBQ number.
1622 * This function is called with hbalock held to get the next
1623 * available slot for the given HBQ. If there is free slot
1624 * available for the HBQ it will return pointer to the next available
1625 * HBQ entry else it will return NULL.
1627 static struct lpfc_hbq_entry
*
1628 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1630 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1632 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1633 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1634 hbqp
->next_hbqPutIdx
= 0;
1636 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1637 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1638 uint32_t getidx
= le32_to_cpu(raw_index
);
1640 hbqp
->local_hbqGetIdx
= getidx
;
1642 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1643 lpfc_printf_log(phba
, KERN_ERR
,
1644 LOG_SLI
| LOG_VPORT
,
1645 "1802 HBQ %d: local_hbqGetIdx "
1646 "%u is > than hbqp->entry_count %u\n",
1647 hbqno
, hbqp
->local_hbqGetIdx
,
1650 phba
->link_state
= LPFC_HBA_ERROR
;
1654 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1658 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1663 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1664 * @phba: Pointer to HBA context object.
1666 * This function is called with no lock held to free all the
1667 * hbq buffers while uninitializing the SLI interface. It also
1668 * frees the HBQ buffers returned by the firmware but not yet
1669 * processed by the upper layers.
1672 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1674 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1675 struct hbq_dmabuf
*hbq_buf
;
1676 unsigned long flags
;
1680 hbq_count
= lpfc_sli_hbq_count();
1681 /* Return all memory used by all HBQs */
1682 spin_lock_irqsave(&phba
->hbalock
, flags
);
1683 for (i
= 0; i
< hbq_count
; ++i
) {
1684 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1685 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1686 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1687 list_del(&hbq_buf
->dbuf
.list
);
1688 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1690 phba
->hbqs
[i
].buffer_count
= 0;
1692 /* Return all HBQ buffer that are in-fly */
1693 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1695 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1696 list_del(&hbq_buf
->dbuf
.list
);
1697 if (hbq_buf
->tag
== -1) {
1698 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1701 hbqno
= hbq_buf
->tag
>> 16;
1702 if (hbqno
>= LPFC_MAX_HBQS
)
1703 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1706 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1711 /* Mark the HBQs not in use */
1712 phba
->hbq_in_use
= 0;
1713 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1717 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1718 * @phba: Pointer to HBA context object.
1719 * @hbqno: HBQ number.
1720 * @hbq_buf: Pointer to HBQ buffer.
1722 * This function is called with the hbalock held to post a
1723 * hbq buffer to the firmware. If the function finds an empty
1724 * slot in the HBQ, it will post the buffer. The function will return
1725 * pointer to the hbq entry if it successfully post the buffer
1726 * else it will return NULL.
1729 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1730 struct hbq_dmabuf
*hbq_buf
)
1732 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1736 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1737 * @phba: Pointer to HBA context object.
1738 * @hbqno: HBQ number.
1739 * @hbq_buf: Pointer to HBQ buffer.
1741 * This function is called with the hbalock held to post a hbq buffer to the
1742 * firmware. If the function finds an empty slot in the HBQ, it will post the
1743 * buffer and place it on the hbq_buffer_list. The function will return zero if
1744 * it successfully post the buffer else it will return an error.
1747 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1748 struct hbq_dmabuf
*hbq_buf
)
1750 struct lpfc_hbq_entry
*hbqe
;
1751 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1753 /* Get next HBQ entry slot to use */
1754 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1756 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1758 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1759 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1760 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1761 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1762 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1763 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1765 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1766 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1768 readl(phba
->hbq_put
+ hbqno
);
1769 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1776 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1777 * @phba: Pointer to HBA context object.
1778 * @hbqno: HBQ number.
1779 * @hbq_buf: Pointer to HBQ buffer.
1781 * This function is called with the hbalock held to post an RQE to the SLI4
1782 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1783 * the hbq_buffer_list and return zero, otherwise it will return an error.
1786 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1787 struct hbq_dmabuf
*hbq_buf
)
1790 struct lpfc_rqe hrqe
;
1791 struct lpfc_rqe drqe
;
1793 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1794 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1795 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1796 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1797 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1802 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1806 /* HBQ for ELS and CT traffic. */
1807 static struct lpfc_hbq_init lpfc_els_hbq
= {
1812 .ring_mask
= (1 << LPFC_ELS_RING
),
1818 /* HBQ for the extra ring if needed */
1819 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1824 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1831 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1837 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1838 * @phba: Pointer to HBA context object.
1839 * @hbqno: HBQ number.
1840 * @count: Number of HBQ buffers to be posted.
1842 * This function is called with no lock held to post more hbq buffers to the
1843 * given HBQ. The function returns the number of HBQ buffers successfully
1847 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1849 uint32_t i
, posted
= 0;
1850 unsigned long flags
;
1851 struct hbq_dmabuf
*hbq_buffer
;
1852 LIST_HEAD(hbq_buf_list
);
1853 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1856 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1857 lpfc_hbq_defs
[hbqno
]->entry_count
)
1858 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1859 phba
->hbqs
[hbqno
].buffer_count
;
1862 /* Allocate HBQ entries */
1863 for (i
= 0; i
< count
; i
++) {
1864 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1867 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1869 /* Check whether HBQ is still in use */
1870 spin_lock_irqsave(&phba
->hbalock
, flags
);
1871 if (!phba
->hbq_in_use
)
1873 while (!list_empty(&hbq_buf_list
)) {
1874 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1876 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1878 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1879 phba
->hbqs
[hbqno
].buffer_count
++;
1882 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1884 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1887 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1888 while (!list_empty(&hbq_buf_list
)) {
1889 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1891 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1897 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1898 * @phba: Pointer to HBA context object.
1901 * This function posts more buffers to the HBQ. This function
1902 * is called with no lock held. The function returns the number of HBQ entries
1903 * successfully allocated.
1906 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1908 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1911 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1912 lpfc_hbq_defs
[qno
]->add_count
);
1916 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1917 * @phba: Pointer to HBA context object.
1918 * @qno: HBQ queue number.
1920 * This function is called from SLI initialization code path with
1921 * no lock held to post initial HBQ buffers to firmware. The
1922 * function returns the number of HBQ entries successfully allocated.
1925 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1927 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1928 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1929 lpfc_hbq_defs
[qno
]->entry_count
);
1931 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1932 lpfc_hbq_defs
[qno
]->init_count
);
1936 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1937 * @phba: Pointer to HBA context object.
1938 * @hbqno: HBQ number.
1940 * This function removes the first hbq buffer on an hbq list and returns a
1941 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1943 static struct hbq_dmabuf
*
1944 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1946 struct lpfc_dmabuf
*d_buf
;
1948 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1951 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1955 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1956 * @phba: Pointer to HBA context object.
1957 * @tag: Tag of the hbq buffer.
1959 * This function is called with hbalock held. This function searches
1960 * for the hbq buffer associated with the given tag in the hbq buffer
1961 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1964 static struct hbq_dmabuf
*
1965 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1967 struct lpfc_dmabuf
*d_buf
;
1968 struct hbq_dmabuf
*hbq_buf
;
1972 if (hbqno
>= LPFC_MAX_HBQS
)
1975 spin_lock_irq(&phba
->hbalock
);
1976 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1977 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1978 if (hbq_buf
->tag
== tag
) {
1979 spin_unlock_irq(&phba
->hbalock
);
1983 spin_unlock_irq(&phba
->hbalock
);
1984 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1985 "1803 Bad hbq tag. Data: x%x x%x\n",
1986 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1991 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1992 * @phba: Pointer to HBA context object.
1993 * @hbq_buffer: Pointer to HBQ buffer.
1995 * This function is called with hbalock. This function gives back
1996 * the hbq buffer to firmware. If the HBQ does not have space to
1997 * post the buffer, it will free the buffer.
2000 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2005 hbqno
= hbq_buffer
->tag
>> 16;
2006 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2007 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2012 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2013 * @mbxCommand: mailbox command code.
2015 * This function is called by the mailbox event handler function to verify
2016 * that the completed mailbox command is a legitimate mailbox command. If the
2017 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2018 * and the mailbox event handler will take the HBA offline.
2021 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2025 switch (mbxCommand
) {
2029 case MBX_WRITE_VPARMS
:
2030 case MBX_RUN_BIU_DIAG
:
2033 case MBX_CONFIG_LINK
:
2034 case MBX_CONFIG_RING
:
2035 case MBX_RESET_RING
:
2036 case MBX_READ_CONFIG
:
2037 case MBX_READ_RCONFIG
:
2038 case MBX_READ_SPARM
:
2039 case MBX_READ_STATUS
:
2043 case MBX_READ_LNK_STAT
:
2045 case MBX_UNREG_LOGIN
:
2047 case MBX_DUMP_MEMORY
:
2048 case MBX_DUMP_CONTEXT
:
2051 case MBX_UPDATE_CFG
:
2053 case MBX_DEL_LD_ENTRY
:
2054 case MBX_RUN_PROGRAM
:
2056 case MBX_SET_VARIABLE
:
2057 case MBX_UNREG_D_ID
:
2058 case MBX_KILL_BOARD
:
2059 case MBX_CONFIG_FARP
:
2062 case MBX_RUN_BIU_DIAG64
:
2063 case MBX_CONFIG_PORT
:
2064 case MBX_READ_SPARM64
:
2065 case MBX_READ_RPI64
:
2066 case MBX_REG_LOGIN64
:
2067 case MBX_READ_TOPOLOGY
:
2070 case MBX_LOAD_EXP_ROM
:
2071 case MBX_ASYNCEVT_ENABLE
:
2075 case MBX_PORT_CAPABILITIES
:
2076 case MBX_PORT_IOV_CONTROL
:
2077 case MBX_SLI4_CONFIG
:
2078 case MBX_SLI4_REQ_FTRS
:
2080 case MBX_UNREG_FCFI
:
2085 case MBX_RESUME_RPI
:
2086 case MBX_READ_EVENT_LOG_STATUS
:
2087 case MBX_READ_EVENT_LOG
:
2088 case MBX_SECURITY_MGMT
:
2100 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2101 * @phba: Pointer to HBA context object.
2102 * @pmboxq: Pointer to mailbox command.
2104 * This is completion handler function for mailbox commands issued from
2105 * lpfc_sli_issue_mbox_wait function. This function is called by the
2106 * mailbox event handler function with no lock held. This function
2107 * will wake up thread waiting on the wait queue pointed by context1
2111 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2113 wait_queue_head_t
*pdone_q
;
2114 unsigned long drvr_flag
;
2117 * If pdone_q is empty, the driver thread gave up waiting and
2118 * continued running.
2120 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2121 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2122 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2124 wake_up_interruptible(pdone_q
);
2125 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2131 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2132 * @phba: Pointer to HBA context object.
2133 * @pmb: Pointer to mailbox object.
2135 * This function is the default mailbox completion handler. It
2136 * frees the memory resources associated with the completed mailbox
2137 * command. If the completed command is a REG_LOGIN mailbox command,
2138 * this function will issue a UREG_LOGIN to re-claim the RPI.
2141 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2143 struct lpfc_vport
*vport
= pmb
->vport
;
2144 struct lpfc_dmabuf
*mp
;
2145 struct lpfc_nodelist
*ndlp
;
2146 struct Scsi_Host
*shost
;
2150 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2153 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2158 * If a REG_LOGIN succeeded after node is destroyed or node
2159 * is in re-discovery driver need to cleanup the RPI.
2161 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2162 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2163 !pmb
->u
.mb
.mbxStatus
) {
2164 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2165 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2166 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2167 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2168 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2169 if (rc
!= MBX_NOT_FINISHED
)
2173 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2174 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2175 !pmb
->u
.mb
.mbxStatus
) {
2176 shost
= lpfc_shost_from_vport(vport
);
2177 spin_lock_irq(shost
->host_lock
);
2178 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2179 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2180 spin_unlock_irq(shost
->host_lock
);
2183 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2184 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2186 pmb
->context2
= NULL
;
2189 /* Check security permission status on INIT_LINK mailbox command */
2190 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2191 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2192 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2193 "2860 SLI authentication is required "
2194 "for INIT_LINK but has not done yet\n");
2196 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2197 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2199 mempool_free(pmb
, phba
->mbox_mem_pool
);
2203 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2204 * @phba: Pointer to HBA context object.
2206 * This function is called with no lock held. This function processes all
2207 * the completed mailbox commands and gives it to upper layers. The interrupt
2208 * service routine processes mailbox completion interrupt and adds completed
2209 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2210 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2211 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2212 * function returns the mailbox commands to the upper layer by calling the
2213 * completion handler function of each mailbox.
2216 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2223 phba
->sli
.slistat
.mbox_event
++;
2225 /* Get all completed mailboxe buffers into the cmplq */
2226 spin_lock_irq(&phba
->hbalock
);
2227 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2228 spin_unlock_irq(&phba
->hbalock
);
2230 /* Get a Mailbox buffer to setup mailbox commands for callback */
2232 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2238 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2240 lpfc_debugfs_disc_trc(pmb
->vport
,
2241 LPFC_DISC_TRC_MBOX_VPORT
,
2242 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2243 (uint32_t)pmbox
->mbxCommand
,
2244 pmbox
->un
.varWords
[0],
2245 pmbox
->un
.varWords
[1]);
2248 lpfc_debugfs_disc_trc(phba
->pport
,
2250 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2251 (uint32_t)pmbox
->mbxCommand
,
2252 pmbox
->un
.varWords
[0],
2253 pmbox
->un
.varWords
[1]);
2258 * It is a fatal error if unknown mbox command completion.
2260 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2262 /* Unknown mailbox command compl */
2263 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2264 "(%d):0323 Unknown Mailbox command "
2265 "x%x (x%x/x%x) Cmpl\n",
2266 pmb
->vport
? pmb
->vport
->vpi
: 0,
2268 lpfc_sli_config_mbox_subsys_get(phba
,
2270 lpfc_sli_config_mbox_opcode_get(phba
,
2272 phba
->link_state
= LPFC_HBA_ERROR
;
2273 phba
->work_hs
= HS_FFER3
;
2274 lpfc_handle_eratt(phba
);
2278 if (pmbox
->mbxStatus
) {
2279 phba
->sli
.slistat
.mbox_stat_err
++;
2280 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2281 /* Mbox cmd cmpl error - RETRYing */
2282 lpfc_printf_log(phba
, KERN_INFO
,
2284 "(%d):0305 Mbox cmd cmpl "
2285 "error - RETRYing Data: x%x "
2286 "(x%x/x%x) x%x x%x x%x\n",
2287 pmb
->vport
? pmb
->vport
->vpi
: 0,
2289 lpfc_sli_config_mbox_subsys_get(phba
,
2291 lpfc_sli_config_mbox_opcode_get(phba
,
2294 pmbox
->un
.varWords
[0],
2295 pmb
->vport
->port_state
);
2296 pmbox
->mbxStatus
= 0;
2297 pmbox
->mbxOwner
= OWN_HOST
;
2298 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2299 if (rc
!= MBX_NOT_FINISHED
)
2304 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2305 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2306 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2307 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2308 pmb
->vport
? pmb
->vport
->vpi
: 0,
2310 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2311 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2313 *((uint32_t *) pmbox
),
2314 pmbox
->un
.varWords
[0],
2315 pmbox
->un
.varWords
[1],
2316 pmbox
->un
.varWords
[2],
2317 pmbox
->un
.varWords
[3],
2318 pmbox
->un
.varWords
[4],
2319 pmbox
->un
.varWords
[5],
2320 pmbox
->un
.varWords
[6],
2321 pmbox
->un
.varWords
[7]);
2324 pmb
->mbox_cmpl(phba
,pmb
);
2330 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2331 * @phba: Pointer to HBA context object.
2332 * @pring: Pointer to driver SLI ring object.
2335 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2336 * is set in the tag the buffer is posted for a particular exchange,
2337 * the function will return the buffer without replacing the buffer.
2338 * If the buffer is for unsolicited ELS or CT traffic, this function
2339 * returns the buffer and also posts another buffer to the firmware.
2341 static struct lpfc_dmabuf
*
2342 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2343 struct lpfc_sli_ring
*pring
,
2346 struct hbq_dmabuf
*hbq_entry
;
2348 if (tag
& QUE_BUFTAG_BIT
)
2349 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2350 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2353 return &hbq_entry
->dbuf
;
2357 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2358 * @phba: Pointer to HBA context object.
2359 * @pring: Pointer to driver SLI ring object.
2360 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2361 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2362 * @fch_type: the type for the first frame of the sequence.
2364 * This function is called with no lock held. This function uses the r_ctl and
2365 * type of the received sequence to find the correct callback function to call
2366 * to process the sequence.
2369 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2370 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2375 /* unSolicited Responses */
2376 if (pring
->prt
[0].profile
) {
2377 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2378 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2382 /* We must search, based on rctl / type
2383 for the right routine */
2384 for (i
= 0; i
< pring
->num_mask
; i
++) {
2385 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2386 (pring
->prt
[i
].type
== fch_type
)) {
2387 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2388 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2389 (phba
, pring
, saveq
);
2397 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2398 * @phba: Pointer to HBA context object.
2399 * @pring: Pointer to driver SLI ring object.
2400 * @saveq: Pointer to the unsolicited iocb.
2402 * This function is called with no lock held by the ring event handler
2403 * when there is an unsolicited iocb posted to the response ring by the
2404 * firmware. This function gets the buffer associated with the iocbs
2405 * and calls the event handler for the ring. This function handles both
2406 * qring buffers and hbq buffers.
2407 * When the function returns 1 the caller can free the iocb object otherwise
2408 * upper layer functions will free the iocb objects.
2411 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2412 struct lpfc_iocbq
*saveq
)
2416 uint32_t Rctl
, Type
;
2418 struct lpfc_iocbq
*iocbq
;
2419 struct lpfc_dmabuf
*dmzbuf
;
2422 irsp
= &(saveq
->iocb
);
2424 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2425 if (pring
->lpfc_sli_rcv_async_status
)
2426 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2428 lpfc_printf_log(phba
,
2431 "0316 Ring %d handler: unexpected "
2432 "ASYNC_STATUS iocb received evt_code "
2435 irsp
->un
.asyncstat
.evt_code
);
2439 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2440 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2441 if (irsp
->ulpBdeCount
> 0) {
2442 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2443 irsp
->un
.ulpWord
[3]);
2444 lpfc_in_buf_free(phba
, dmzbuf
);
2447 if (irsp
->ulpBdeCount
> 1) {
2448 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2449 irsp
->unsli3
.sli3Words
[3]);
2450 lpfc_in_buf_free(phba
, dmzbuf
);
2453 if (irsp
->ulpBdeCount
> 2) {
2454 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2455 irsp
->unsli3
.sli3Words
[7]);
2456 lpfc_in_buf_free(phba
, dmzbuf
);
2462 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2463 if (irsp
->ulpBdeCount
!= 0) {
2464 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2465 irsp
->un
.ulpWord
[3]);
2466 if (!saveq
->context2
)
2467 lpfc_printf_log(phba
,
2470 "0341 Ring %d Cannot find buffer for "
2471 "an unsolicited iocb. tag 0x%x\n",
2473 irsp
->un
.ulpWord
[3]);
2475 if (irsp
->ulpBdeCount
== 2) {
2476 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2477 irsp
->unsli3
.sli3Words
[7]);
2478 if (!saveq
->context3
)
2479 lpfc_printf_log(phba
,
2482 "0342 Ring %d Cannot find buffer for an"
2483 " unsolicited iocb. tag 0x%x\n",
2485 irsp
->unsli3
.sli3Words
[7]);
2487 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2488 irsp
= &(iocbq
->iocb
);
2489 if (irsp
->ulpBdeCount
!= 0) {
2490 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2491 irsp
->un
.ulpWord
[3]);
2492 if (!iocbq
->context2
)
2493 lpfc_printf_log(phba
,
2496 "0343 Ring %d Cannot find "
2497 "buffer for an unsolicited iocb"
2498 ". tag 0x%x\n", pring
->ringno
,
2499 irsp
->un
.ulpWord
[3]);
2501 if (irsp
->ulpBdeCount
== 2) {
2502 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2503 irsp
->unsli3
.sli3Words
[7]);
2504 if (!iocbq
->context3
)
2505 lpfc_printf_log(phba
,
2508 "0344 Ring %d Cannot find "
2509 "buffer for an unsolicited "
2512 irsp
->unsli3
.sli3Words
[7]);
2516 if (irsp
->ulpBdeCount
!= 0 &&
2517 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2518 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2521 /* search continue save q for same XRI */
2522 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2523 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2524 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2525 list_add_tail(&saveq
->list
, &iocbq
->list
);
2531 list_add_tail(&saveq
->clist
,
2532 &pring
->iocb_continue_saveq
);
2533 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2534 list_del_init(&iocbq
->clist
);
2536 irsp
= &(saveq
->iocb
);
2540 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2541 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2542 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2543 Rctl
= FC_RCTL_ELS_REQ
;
2546 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2547 Rctl
= w5p
->hcsw
.Rctl
;
2548 Type
= w5p
->hcsw
.Type
;
2550 /* Firmware Workaround */
2551 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2552 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2553 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2554 Rctl
= FC_RCTL_ELS_REQ
;
2556 w5p
->hcsw
.Rctl
= Rctl
;
2557 w5p
->hcsw
.Type
= Type
;
2561 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2562 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2563 "0313 Ring %d handler: unexpected Rctl x%x "
2564 "Type x%x received\n",
2565 pring
->ringno
, Rctl
, Type
);
2571 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2572 * @phba: Pointer to HBA context object.
2573 * @pring: Pointer to driver SLI ring object.
2574 * @prspiocb: Pointer to response iocb object.
2576 * This function looks up the iocb_lookup table to get the command iocb
2577 * corresponding to the given response iocb using the iotag of the
2578 * response iocb. This function is called with the hbalock held.
2579 * This function returns the command iocb object if it finds the command
2580 * iocb else returns NULL.
2582 static struct lpfc_iocbq
*
2583 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2584 struct lpfc_sli_ring
*pring
,
2585 struct lpfc_iocbq
*prspiocb
)
2587 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2590 iotag
= prspiocb
->iocb
.ulpIoTag
;
2592 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2593 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2594 list_del_init(&cmd_iocb
->list
);
2595 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2596 pring
->txcmplq_cnt
--;
2597 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2602 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2603 "0317 iotag x%x is out off "
2604 "range: max iotag x%x wd0 x%x\n",
2605 iotag
, phba
->sli
.last_iotag
,
2606 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2611 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2612 * @phba: Pointer to HBA context object.
2613 * @pring: Pointer to driver SLI ring object.
2616 * This function looks up the iocb_lookup table to get the command iocb
2617 * corresponding to the given iotag. This function is called with the
2619 * This function returns the command iocb object if it finds the command
2620 * iocb else returns NULL.
2622 static struct lpfc_iocbq
*
2623 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2624 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2626 struct lpfc_iocbq
*cmd_iocb
;
2628 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2629 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2630 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2631 /* remove from txcmpl queue list */
2632 list_del_init(&cmd_iocb
->list
);
2633 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2634 pring
->txcmplq_cnt
--;
2638 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2639 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2640 iotag
, phba
->sli
.last_iotag
);
2645 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2646 * @phba: Pointer to HBA context object.
2647 * @pring: Pointer to driver SLI ring object.
2648 * @saveq: Pointer to the response iocb to be processed.
2650 * This function is called by the ring event handler for non-fcp
2651 * rings when there is a new response iocb in the response ring.
2652 * The caller is not required to hold any locks. This function
2653 * gets the command iocb associated with the response iocb and
2654 * calls the completion handler for the command iocb. If there
2655 * is no completion handler, the function will free the resources
2656 * associated with command iocb. If the response iocb is for
2657 * an already aborted command iocb, the status of the completion
2658 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2659 * This function always returns 1.
2662 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2663 struct lpfc_iocbq
*saveq
)
2665 struct lpfc_iocbq
*cmdiocbp
;
2667 unsigned long iflag
;
2669 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2670 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2671 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2672 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2675 if (cmdiocbp
->iocb_cmpl
) {
2677 * If an ELS command failed send an event to mgmt
2680 if (saveq
->iocb
.ulpStatus
&&
2681 (pring
->ringno
== LPFC_ELS_RING
) &&
2682 (cmdiocbp
->iocb
.ulpCommand
==
2683 CMD_ELS_REQUEST64_CR
))
2684 lpfc_send_els_failure_event(phba
,
2688 * Post all ELS completions to the worker thread.
2689 * All other are passed to the completion callback.
2691 if (pring
->ringno
== LPFC_ELS_RING
) {
2692 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2693 (cmdiocbp
->iocb_flag
&
2694 LPFC_DRIVER_ABORTED
)) {
2695 spin_lock_irqsave(&phba
->hbalock
,
2697 cmdiocbp
->iocb_flag
&=
2698 ~LPFC_DRIVER_ABORTED
;
2699 spin_unlock_irqrestore(&phba
->hbalock
,
2701 saveq
->iocb
.ulpStatus
=
2702 IOSTAT_LOCAL_REJECT
;
2703 saveq
->iocb
.un
.ulpWord
[4] =
2706 /* Firmware could still be in progress
2707 * of DMAing payload, so don't free data
2708 * buffer till after a hbeat.
2710 spin_lock_irqsave(&phba
->hbalock
,
2712 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2713 spin_unlock_irqrestore(&phba
->hbalock
,
2716 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2717 if (saveq
->iocb_flag
&
2718 LPFC_EXCHANGE_BUSY
) {
2719 /* Set cmdiocb flag for the
2720 * exchange busy so sgl (xri)
2721 * will not be released until
2722 * the abort xri is received
2726 &phba
->hbalock
, iflag
);
2727 cmdiocbp
->iocb_flag
|=
2729 spin_unlock_irqrestore(
2730 &phba
->hbalock
, iflag
);
2732 if (cmdiocbp
->iocb_flag
&
2733 LPFC_DRIVER_ABORTED
) {
2735 * Clear LPFC_DRIVER_ABORTED
2736 * bit in case it was driver
2740 &phba
->hbalock
, iflag
);
2741 cmdiocbp
->iocb_flag
&=
2742 ~LPFC_DRIVER_ABORTED
;
2743 spin_unlock_irqrestore(
2744 &phba
->hbalock
, iflag
);
2745 cmdiocbp
->iocb
.ulpStatus
=
2746 IOSTAT_LOCAL_REJECT
;
2747 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2748 IOERR_ABORT_REQUESTED
;
2750 * For SLI4, irsiocb contains
2751 * NO_XRI in sli_xritag, it
2752 * shall not affect releasing
2753 * sgl (xri) process.
2755 saveq
->iocb
.ulpStatus
=
2756 IOSTAT_LOCAL_REJECT
;
2757 saveq
->iocb
.un
.ulpWord
[4] =
2760 &phba
->hbalock
, iflag
);
2762 LPFC_DELAY_MEM_FREE
;
2763 spin_unlock_irqrestore(
2764 &phba
->hbalock
, iflag
);
2768 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2770 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2773 * Unknown initiating command based on the response iotag.
2774 * This could be the case on the ELS ring because of
2777 if (pring
->ringno
!= LPFC_ELS_RING
) {
2779 * Ring <ringno> handler: unexpected completion IoTag
2782 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2783 "0322 Ring %d handler: "
2784 "unexpected completion IoTag x%x "
2785 "Data: x%x x%x x%x x%x\n",
2787 saveq
->iocb
.ulpIoTag
,
2788 saveq
->iocb
.ulpStatus
,
2789 saveq
->iocb
.un
.ulpWord
[4],
2790 saveq
->iocb
.ulpCommand
,
2791 saveq
->iocb
.ulpContext
);
2799 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2800 * @phba: Pointer to HBA context object.
2801 * @pring: Pointer to driver SLI ring object.
2803 * This function is called from the iocb ring event handlers when
2804 * put pointer is ahead of the get pointer for a ring. This function signal
2805 * an error attention condition to the worker thread and the worker
2806 * thread will transition the HBA to offline state.
2809 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2811 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2813 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2814 * rsp ring <portRspMax>
2816 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2817 "0312 Ring %d handler: portRspPut %d "
2818 "is bigger than rsp ring %d\n",
2819 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2820 pring
->sli
.sli3
.numRiocb
);
2822 phba
->link_state
= LPFC_HBA_ERROR
;
2825 * All error attention handlers are posted to
2828 phba
->work_ha
|= HA_ERATT
;
2829 phba
->work_hs
= HS_FFER3
;
2831 lpfc_worker_wake_up(phba
);
2837 * lpfc_poll_eratt - Error attention polling timer timeout handler
2838 * @ptr: Pointer to address of HBA context object.
2840 * This function is invoked by the Error Attention polling timer when the
2841 * timer times out. It will check the SLI Error Attention register for
2842 * possible attention events. If so, it will post an Error Attention event
2843 * and wake up worker thread to process it. Otherwise, it will set up the
2844 * Error Attention polling timer for the next poll.
2846 void lpfc_poll_eratt(unsigned long ptr
)
2848 struct lpfc_hba
*phba
;
2849 uint32_t eratt
= 0, rem
;
2850 uint64_t sli_intr
, cnt
;
2852 phba
= (struct lpfc_hba
*)ptr
;
2854 /* Here we will also keep track of interrupts per sec of the hba */
2855 sli_intr
= phba
->sli
.slistat
.sli_intr
;
2857 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
2858 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
2861 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
2863 /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
2864 rem
= do_div(cnt
, LPFC_ERATT_POLL_INTERVAL
);
2865 phba
->sli
.slistat
.sli_ips
= cnt
;
2867 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
2869 /* Check chip HA register for error event */
2870 eratt
= lpfc_sli_check_eratt(phba
);
2873 /* Tell the worker thread there is work to do */
2874 lpfc_worker_wake_up(phba
);
2876 /* Restart the timer for next eratt poll */
2877 mod_timer(&phba
->eratt_poll
, jiffies
+
2878 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2884 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2885 * @phba: Pointer to HBA context object.
2886 * @pring: Pointer to driver SLI ring object.
2887 * @mask: Host attention register mask for this ring.
2889 * This function is called from the interrupt context when there is a ring
2890 * event for the fcp ring. The caller does not hold any lock.
2891 * The function processes each response iocb in the response ring until it
2892 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2893 * LE bit set. The function will call the completion handler of the command iocb
2894 * if the response iocb indicates a completion for a command iocb or it is
2895 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2896 * function if this is an unsolicited iocb.
2897 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2898 * to check it explicitly.
2901 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2902 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2904 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2905 IOCB_t
*irsp
= NULL
;
2906 IOCB_t
*entry
= NULL
;
2907 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2908 struct lpfc_iocbq rspiocbq
;
2910 uint32_t portRspPut
, portRspMax
;
2912 lpfc_iocb_type type
;
2913 unsigned long iflag
;
2914 uint32_t rsp_cmpl
= 0;
2916 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2917 pring
->stats
.iocb_event
++;
2920 * The next available response entry should never exceed the maximum
2921 * entries. If it does, treat it as an adapter hardware error.
2923 portRspMax
= pring
->sli
.sli3
.numRiocb
;
2924 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2925 if (unlikely(portRspPut
>= portRspMax
)) {
2926 lpfc_sli_rsp_pointers_error(phba
, pring
);
2927 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2930 if (phba
->fcp_ring_in_use
) {
2931 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2934 phba
->fcp_ring_in_use
= 1;
2937 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
2939 * Fetch an entry off the ring and copy it into a local data
2940 * structure. The copy involves a byte-swap since the
2941 * network byte order and pci byte orders are different.
2943 entry
= lpfc_resp_iocb(phba
, pring
);
2944 phba
->last_completion_time
= jiffies
;
2946 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
2947 pring
->sli
.sli3
.rspidx
= 0;
2949 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2950 (uint32_t *) &rspiocbq
.iocb
,
2951 phba
->iocb_rsp_size
);
2952 INIT_LIST_HEAD(&(rspiocbq
.list
));
2953 irsp
= &rspiocbq
.iocb
;
2955 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2956 pring
->stats
.iocb_rsp
++;
2959 if (unlikely(irsp
->ulpStatus
)) {
2961 * If resource errors reported from HBA, reduce
2962 * queuedepths of the SCSI device.
2964 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2965 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2966 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2967 phba
->lpfc_rampdown_queue_depth(phba
);
2968 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2971 /* Rsp ring <ringno> error: IOCB */
2972 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2973 "0336 Rsp Ring %d error: IOCB Data: "
2974 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2976 irsp
->un
.ulpWord
[0],
2977 irsp
->un
.ulpWord
[1],
2978 irsp
->un
.ulpWord
[2],
2979 irsp
->un
.ulpWord
[3],
2980 irsp
->un
.ulpWord
[4],
2981 irsp
->un
.ulpWord
[5],
2982 *(uint32_t *)&irsp
->un1
,
2983 *((uint32_t *)&irsp
->un1
+ 1));
2987 case LPFC_ABORT_IOCB
:
2990 * Idle exchange closed via ABTS from port. No iocb
2991 * resources need to be recovered.
2993 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2994 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2995 "0333 IOCB cmd 0x%x"
2996 " processed. Skipping"
3002 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3004 if (unlikely(!cmdiocbq
))
3006 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3007 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3008 if (cmdiocbq
->iocb_cmpl
) {
3009 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3010 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3012 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3015 case LPFC_UNSOL_IOCB
:
3016 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3017 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3018 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3021 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3022 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3023 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3024 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3026 dev_warn(&((phba
->pcidev
)->dev
),
3028 phba
->brd_no
, adaptermsg
);
3030 /* Unknown IOCB command */
3031 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3032 "0334 Unknown IOCB command "
3033 "Data: x%x, x%x x%x x%x x%x\n",
3034 type
, irsp
->ulpCommand
,
3043 * The response IOCB has been processed. Update the ring
3044 * pointer in SLIM. If the port response put pointer has not
3045 * been updated, sync the pgp->rspPutInx and fetch the new port
3046 * response put pointer.
3048 writel(pring
->sli
.sli3
.rspidx
,
3049 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3051 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3052 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3055 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3056 pring
->stats
.iocb_rsp_full
++;
3057 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3058 writel(status
, phba
->CAregaddr
);
3059 readl(phba
->CAregaddr
);
3061 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3062 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3063 pring
->stats
.iocb_cmd_empty
++;
3065 /* Force update of the local copy of cmdGetInx */
3066 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3067 lpfc_sli_resume_iocb(phba
, pring
);
3069 if ((pring
->lpfc_sli_cmd_available
))
3070 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3074 phba
->fcp_ring_in_use
= 0;
3075 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3080 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3081 * @phba: Pointer to HBA context object.
3082 * @pring: Pointer to driver SLI ring object.
3083 * @rspiocbp: Pointer to driver response IOCB object.
3085 * This function is called from the worker thread when there is a slow-path
3086 * response IOCB to process. This function chains all the response iocbs until
3087 * seeing the iocb with the LE bit set. The function will call
3088 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3089 * completion of a command iocb. The function will call the
3090 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3091 * The function frees the resources or calls the completion handler if this
3092 * iocb is an abort completion. The function returns NULL when the response
3093 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3094 * this function shall chain the iocb on to the iocb_continueq and return the
3095 * response iocb passed in.
3097 static struct lpfc_iocbq
*
3098 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3099 struct lpfc_iocbq
*rspiocbp
)
3101 struct lpfc_iocbq
*saveq
;
3102 struct lpfc_iocbq
*cmdiocbp
;
3103 struct lpfc_iocbq
*next_iocb
;
3104 IOCB_t
*irsp
= NULL
;
3105 uint32_t free_saveq
;
3106 uint8_t iocb_cmd_type
;
3107 lpfc_iocb_type type
;
3108 unsigned long iflag
;
3111 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3112 /* First add the response iocb to the countinueq list */
3113 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3114 pring
->iocb_continueq_cnt
++;
3116 /* Now, determine whether the list is completed for processing */
3117 irsp
= &rspiocbp
->iocb
;
3120 * By default, the driver expects to free all resources
3121 * associated with this iocb completion.
3124 saveq
= list_get_first(&pring
->iocb_continueq
,
3125 struct lpfc_iocbq
, list
);
3126 irsp
= &(saveq
->iocb
);
3127 list_del_init(&pring
->iocb_continueq
);
3128 pring
->iocb_continueq_cnt
= 0;
3130 pring
->stats
.iocb_rsp
++;
3133 * If resource errors reported from HBA, reduce
3134 * queuedepths of the SCSI device.
3136 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3137 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
3138 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3139 phba
->lpfc_rampdown_queue_depth(phba
);
3140 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3143 if (irsp
->ulpStatus
) {
3144 /* Rsp ring <ringno> error: IOCB */
3145 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3146 "0328 Rsp Ring %d error: "
3151 "x%x x%x x%x x%x\n",
3153 irsp
->un
.ulpWord
[0],
3154 irsp
->un
.ulpWord
[1],
3155 irsp
->un
.ulpWord
[2],
3156 irsp
->un
.ulpWord
[3],
3157 irsp
->un
.ulpWord
[4],
3158 irsp
->un
.ulpWord
[5],
3159 *(((uint32_t *) irsp
) + 6),
3160 *(((uint32_t *) irsp
) + 7),
3161 *(((uint32_t *) irsp
) + 8),
3162 *(((uint32_t *) irsp
) + 9),
3163 *(((uint32_t *) irsp
) + 10),
3164 *(((uint32_t *) irsp
) + 11),
3165 *(((uint32_t *) irsp
) + 12),
3166 *(((uint32_t *) irsp
) + 13),
3167 *(((uint32_t *) irsp
) + 14),
3168 *(((uint32_t *) irsp
) + 15));
3172 * Fetch the IOCB command type and call the correct completion
3173 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3174 * get freed back to the lpfc_iocb_list by the discovery
3177 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3178 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3181 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3182 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3183 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3186 case LPFC_UNSOL_IOCB
:
3187 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3188 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3189 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3194 case LPFC_ABORT_IOCB
:
3196 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3197 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3200 /* Call the specified completion routine */
3201 if (cmdiocbp
->iocb_cmpl
) {
3202 spin_unlock_irqrestore(&phba
->hbalock
,
3204 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3206 spin_lock_irqsave(&phba
->hbalock
,
3209 __lpfc_sli_release_iocbq(phba
,
3214 case LPFC_UNKNOWN_IOCB
:
3215 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3216 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3217 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3218 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3220 dev_warn(&((phba
->pcidev
)->dev
),
3222 phba
->brd_no
, adaptermsg
);
3224 /* Unknown IOCB command */
3225 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3226 "0335 Unknown IOCB "
3227 "command Data: x%x "
3238 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3239 &saveq
->list
, list
) {
3240 list_del(&rspiocbp
->list
);
3241 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3243 __lpfc_sli_release_iocbq(phba
, saveq
);
3247 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3252 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3253 * @phba: Pointer to HBA context object.
3254 * @pring: Pointer to driver SLI ring object.
3255 * @mask: Host attention register mask for this ring.
3257 * This routine wraps the actual slow_ring event process routine from the
3258 * API jump table function pointer from the lpfc_hba struct.
3261 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3262 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3264 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3268 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3269 * @phba: Pointer to HBA context object.
3270 * @pring: Pointer to driver SLI ring object.
3271 * @mask: Host attention register mask for this ring.
3273 * This function is called from the worker thread when there is a ring event
3274 * for non-fcp rings. The caller does not hold any lock. The function will
3275 * remove each response iocb in the response ring and calls the handle
3276 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3279 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3280 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3282 struct lpfc_pgp
*pgp
;
3284 IOCB_t
*irsp
= NULL
;
3285 struct lpfc_iocbq
*rspiocbp
= NULL
;
3286 uint32_t portRspPut
, portRspMax
;
3287 unsigned long iflag
;
3290 pgp
= &phba
->port_gp
[pring
->ringno
];
3291 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3292 pring
->stats
.iocb_event
++;
3295 * The next available response entry should never exceed the maximum
3296 * entries. If it does, treat it as an adapter hardware error.
3298 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3299 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3300 if (portRspPut
>= portRspMax
) {
3302 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3303 * rsp ring <portRspMax>
3305 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3306 "0303 Ring %d handler: portRspPut %d "
3307 "is bigger than rsp ring %d\n",
3308 pring
->ringno
, portRspPut
, portRspMax
);
3310 phba
->link_state
= LPFC_HBA_ERROR
;
3311 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3313 phba
->work_hs
= HS_FFER3
;
3314 lpfc_handle_eratt(phba
);
3320 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3322 * Build a completion list and call the appropriate handler.
3323 * The process is to get the next available response iocb, get
3324 * a free iocb from the list, copy the response data into the
3325 * free iocb, insert to the continuation list, and update the
3326 * next response index to slim. This process makes response
3327 * iocb's in the ring available to DMA as fast as possible but
3328 * pays a penalty for a copy operation. Since the iocb is
3329 * only 32 bytes, this penalty is considered small relative to
3330 * the PCI reads for register values and a slim write. When
3331 * the ulpLe field is set, the entire Command has been
3334 entry
= lpfc_resp_iocb(phba
, pring
);
3336 phba
->last_completion_time
= jiffies
;
3337 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3338 if (rspiocbp
== NULL
) {
3339 printk(KERN_ERR
"%s: out of buffers! Failing "
3340 "completion.\n", __func__
);
3344 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3345 phba
->iocb_rsp_size
);
3346 irsp
= &rspiocbp
->iocb
;
3348 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3349 pring
->sli
.sli3
.rspidx
= 0;
3351 if (pring
->ringno
== LPFC_ELS_RING
) {
3352 lpfc_debugfs_slow_ring_trc(phba
,
3353 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3354 *(((uint32_t *) irsp
) + 4),
3355 *(((uint32_t *) irsp
) + 6),
3356 *(((uint32_t *) irsp
) + 7));
3359 writel(pring
->sli
.sli3
.rspidx
,
3360 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3362 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3363 /* Handle the response IOCB */
3364 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3365 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3368 * If the port response put pointer has not been updated, sync
3369 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3370 * response put pointer.
3372 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3373 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3375 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3377 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3378 /* At least one response entry has been freed */
3379 pring
->stats
.iocb_rsp_full
++;
3380 /* SET RxRE_RSP in Chip Att register */
3381 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3382 writel(status
, phba
->CAregaddr
);
3383 readl(phba
->CAregaddr
); /* flush */
3385 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3386 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3387 pring
->stats
.iocb_cmd_empty
++;
3389 /* Force update of the local copy of cmdGetInx */
3390 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3391 lpfc_sli_resume_iocb(phba
, pring
);
3393 if ((pring
->lpfc_sli_cmd_available
))
3394 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3398 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3403 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3404 * @phba: Pointer to HBA context object.
3405 * @pring: Pointer to driver SLI ring object.
3406 * @mask: Host attention register mask for this ring.
3408 * This function is called from the worker thread when there is a pending
3409 * ELS response iocb on the driver internal slow-path response iocb worker
3410 * queue. The caller does not hold any lock. The function will remove each
3411 * response iocb from the response worker queue and calls the handle
3412 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3415 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3416 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3418 struct lpfc_iocbq
*irspiocbq
;
3419 struct hbq_dmabuf
*dmabuf
;
3420 struct lpfc_cq_event
*cq_event
;
3421 unsigned long iflag
;
3423 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3424 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3425 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3426 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3427 /* Get the response iocb from the head of work queue */
3428 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3429 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3430 cq_event
, struct lpfc_cq_event
, list
);
3431 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3433 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3434 case CQE_CODE_COMPL_WQE
:
3435 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3437 /* Translate ELS WCQE to response IOCBQ */
3438 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3441 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3444 case CQE_CODE_RECEIVE
:
3445 case CQE_CODE_RECEIVE_V1
:
3446 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3448 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3457 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3458 * @phba: Pointer to HBA context object.
3459 * @pring: Pointer to driver SLI ring object.
3461 * This function aborts all iocbs in the given ring and frees all the iocb
3462 * objects in txq. This function issues an abort iocb for all the iocb commands
3463 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3464 * the return of this function. The caller is not required to hold any locks.
3467 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3469 LIST_HEAD(completions
);
3470 struct lpfc_iocbq
*iocb
, *next_iocb
;
3472 if (pring
->ringno
== LPFC_ELS_RING
) {
3473 lpfc_fabric_abort_hba(phba
);
3476 /* Error everything on txq and txcmplq
3479 spin_lock_irq(&phba
->hbalock
);
3480 list_splice_init(&pring
->txq
, &completions
);
3483 /* Next issue ABTS for everything on the txcmplq */
3484 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3485 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3487 spin_unlock_irq(&phba
->hbalock
);
3489 /* Cancel all the IOCBs from the completions list */
3490 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3495 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3496 * @phba: Pointer to HBA context object.
3498 * This function flushes all iocbs in the fcp ring and frees all the iocb
3499 * objects in txq and txcmplq. This function will not issue abort iocbs
3500 * for all the iocb commands in txcmplq, they will just be returned with
3501 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3502 * slot has been permanently disabled.
3505 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3509 struct lpfc_sli
*psli
= &phba
->sli
;
3510 struct lpfc_sli_ring
*pring
;
3512 /* Currently, only one fcp ring */
3513 pring
= &psli
->ring
[psli
->fcp_ring
];
3515 spin_lock_irq(&phba
->hbalock
);
3516 /* Retrieve everything on txq */
3517 list_splice_init(&pring
->txq
, &txq
);
3520 /* Retrieve everything on the txcmplq */
3521 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3522 pring
->txcmplq_cnt
= 0;
3524 /* Indicate the I/O queues are flushed */
3525 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3526 spin_unlock_irq(&phba
->hbalock
);
3529 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3532 /* Flush the txcmpq */
3533 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3538 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3539 * @phba: Pointer to HBA context object.
3540 * @mask: Bit mask to be checked.
3542 * This function reads the host status register and compares
3543 * with the provided bit mask to check if HBA completed
3544 * the restart. This function will wait in a loop for the
3545 * HBA to complete restart. If the HBA does not restart within
3546 * 15 iterations, the function will reset the HBA again. The
3547 * function returns 1 when HBA fail to restart otherwise returns
3551 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3557 /* Read the HBA Host Status Register */
3558 if (lpfc_readl(phba
->HSregaddr
, &status
))
3562 * Check status register every 100ms for 5 retries, then every
3563 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3564 * every 2.5 sec for 4.
3565 * Break our of the loop if errors occurred during init.
3567 while (((status
& mask
) != mask
) &&
3568 !(status
& HS_FFERM
) &&
3580 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3581 lpfc_sli_brdrestart(phba
);
3583 /* Read the HBA Host Status Register */
3584 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3590 /* Check to see if any errors occurred during init */
3591 if ((status
& HS_FFERM
) || (i
>= 20)) {
3592 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3593 "2751 Adapter failed to restart, "
3594 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3596 readl(phba
->MBslimaddr
+ 0xa8),
3597 readl(phba
->MBslimaddr
+ 0xac));
3598 phba
->link_state
= LPFC_HBA_ERROR
;
3606 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3607 * @phba: Pointer to HBA context object.
3608 * @mask: Bit mask to be checked.
3610 * This function checks the host status register to check if HBA is
3611 * ready. This function will wait in a loop for the HBA to be ready
3612 * If the HBA is not ready , the function will will reset the HBA PCI
3613 * function again. The function returns 1 when HBA fail to be ready
3614 * otherwise returns zero.
3617 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3622 /* Read the HBA Host Status Register */
3623 status
= lpfc_sli4_post_status_check(phba
);
3626 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3627 lpfc_sli_brdrestart(phba
);
3628 status
= lpfc_sli4_post_status_check(phba
);
3631 /* Check to see if any errors occurred during init */
3633 phba
->link_state
= LPFC_HBA_ERROR
;
3636 phba
->sli4_hba
.intr_enable
= 0;
3642 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3643 * @phba: Pointer to HBA context object.
3644 * @mask: Bit mask to be checked.
3646 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3647 * from the API jump table function pointer from the lpfc_hba struct.
3650 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3652 return phba
->lpfc_sli_brdready(phba
, mask
);
3655 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3658 * lpfc_reset_barrier - Make HBA ready for HBA reset
3659 * @phba: Pointer to HBA context object.
3661 * This function is called before resetting an HBA. This function is called
3662 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3664 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3666 uint32_t __iomem
*resp_buf
;
3667 uint32_t __iomem
*mbox_buf
;
3668 volatile uint32_t mbox
;
3669 uint32_t hc_copy
, ha_copy
, resp_data
;
3673 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3674 if (hdrtype
!= 0x80 ||
3675 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3676 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3680 * Tell the other part of the chip to suspend temporarily all
3683 resp_buf
= phba
->MBslimaddr
;
3685 /* Disable the error attention */
3686 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3688 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3689 readl(phba
->HCregaddr
); /* flush */
3690 phba
->link_flag
|= LS_IGNORE_ERATT
;
3692 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3694 if (ha_copy
& HA_ERATT
) {
3695 /* Clear Chip error bit */
3696 writel(HA_ERATT
, phba
->HAregaddr
);
3697 phba
->pport
->stopped
= 1;
3701 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3702 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3704 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3705 mbox_buf
= phba
->MBslimaddr
;
3706 writel(mbox
, mbox_buf
);
3708 for (i
= 0; i
< 50; i
++) {
3709 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3711 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3717 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3719 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3720 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3721 phba
->pport
->stopped
)
3727 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3729 for (i
= 0; i
< 500; i
++) {
3730 if (lpfc_readl(resp_buf
, &resp_data
))
3732 if (resp_data
!= mbox
)
3741 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3743 if (!(ha_copy
& HA_ERATT
))
3749 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3750 writel(HA_ERATT
, phba
->HAregaddr
);
3751 phba
->pport
->stopped
= 1;
3755 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3756 writel(hc_copy
, phba
->HCregaddr
);
3757 readl(phba
->HCregaddr
); /* flush */
3761 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3762 * @phba: Pointer to HBA context object.
3764 * This function issues a kill_board mailbox command and waits for
3765 * the error attention interrupt. This function is called for stopping
3766 * the firmware processing. The caller is not required to hold any
3767 * locks. This function calls lpfc_hba_down_post function to free
3768 * any pending commands after the kill. The function will return 1 when it
3769 * fails to kill the board else will return 0.
3772 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3774 struct lpfc_sli
*psli
;
3784 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3785 "0329 Kill HBA Data: x%x x%x\n",
3786 phba
->pport
->port_state
, psli
->sli_flag
);
3788 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3792 /* Disable the error attention */
3793 spin_lock_irq(&phba
->hbalock
);
3794 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3795 spin_unlock_irq(&phba
->hbalock
);
3796 mempool_free(pmb
, phba
->mbox_mem_pool
);
3799 status
&= ~HC_ERINT_ENA
;
3800 writel(status
, phba
->HCregaddr
);
3801 readl(phba
->HCregaddr
); /* flush */
3802 phba
->link_flag
|= LS_IGNORE_ERATT
;
3803 spin_unlock_irq(&phba
->hbalock
);
3805 lpfc_kill_board(phba
, pmb
);
3806 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3807 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3809 if (retval
!= MBX_SUCCESS
) {
3810 if (retval
!= MBX_BUSY
)
3811 mempool_free(pmb
, phba
->mbox_mem_pool
);
3812 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3813 "2752 KILL_BOARD command failed retval %d\n",
3815 spin_lock_irq(&phba
->hbalock
);
3816 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3817 spin_unlock_irq(&phba
->hbalock
);
3821 spin_lock_irq(&phba
->hbalock
);
3822 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3823 spin_unlock_irq(&phba
->hbalock
);
3825 mempool_free(pmb
, phba
->mbox_mem_pool
);
3827 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3828 * attention every 100ms for 3 seconds. If we don't get ERATT after
3829 * 3 seconds we still set HBA_ERROR state because the status of the
3830 * board is now undefined.
3832 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3834 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3836 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3840 del_timer_sync(&psli
->mbox_tmo
);
3841 if (ha_copy
& HA_ERATT
) {
3842 writel(HA_ERATT
, phba
->HAregaddr
);
3843 phba
->pport
->stopped
= 1;
3845 spin_lock_irq(&phba
->hbalock
);
3846 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3847 psli
->mbox_active
= NULL
;
3848 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3849 spin_unlock_irq(&phba
->hbalock
);
3851 lpfc_hba_down_post(phba
);
3852 phba
->link_state
= LPFC_HBA_ERROR
;
3854 return ha_copy
& HA_ERATT
? 0 : 1;
3858 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3859 * @phba: Pointer to HBA context object.
3861 * This function resets the HBA by writing HC_INITFF to the control
3862 * register. After the HBA resets, this function resets all the iocb ring
3863 * indices. This function disables PCI layer parity checking during
3865 * This function returns 0 always.
3866 * The caller is not required to hold any locks.
3869 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3871 struct lpfc_sli
*psli
;
3872 struct lpfc_sli_ring
*pring
;
3879 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3880 "0325 Reset HBA Data: x%x x%x\n",
3881 phba
->pport
->port_state
, psli
->sli_flag
);
3883 /* perform board reset */
3884 phba
->fc_eventTag
= 0;
3885 phba
->link_events
= 0;
3886 phba
->pport
->fc_myDID
= 0;
3887 phba
->pport
->fc_prevDID
= 0;
3889 /* Turn off parity checking and serr during the physical reset */
3890 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3891 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3893 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3895 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3897 /* Now toggle INITFF bit in the Host Control Register */
3898 writel(HC_INITFF
, phba
->HCregaddr
);
3900 readl(phba
->HCregaddr
); /* flush */
3901 writel(0, phba
->HCregaddr
);
3902 readl(phba
->HCregaddr
); /* flush */
3904 /* Restore PCI cmd register */
3905 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3907 /* Initialize relevant SLI info */
3908 for (i
= 0; i
< psli
->num_rings
; i
++) {
3909 pring
= &psli
->ring
[i
];
3911 pring
->sli
.sli3
.rspidx
= 0;
3912 pring
->sli
.sli3
.next_cmdidx
= 0;
3913 pring
->sli
.sli3
.local_getidx
= 0;
3914 pring
->sli
.sli3
.cmdidx
= 0;
3915 pring
->missbufcnt
= 0;
3918 phba
->link_state
= LPFC_WARM_START
;
3923 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3924 * @phba: Pointer to HBA context object.
3926 * This function resets a SLI4 HBA. This function disables PCI layer parity
3927 * checking during resets the device. The caller is not required to hold
3930 * This function returns 0 always.
3933 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3935 struct lpfc_sli
*psli
= &phba
->sli
;
3940 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3941 "0295 Reset HBA Data: x%x x%x\n",
3942 phba
->pport
->port_state
, psli
->sli_flag
);
3944 /* perform board reset */
3945 phba
->fc_eventTag
= 0;
3946 phba
->link_events
= 0;
3947 phba
->pport
->fc_myDID
= 0;
3948 phba
->pport
->fc_prevDID
= 0;
3950 spin_lock_irq(&phba
->hbalock
);
3951 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3952 phba
->fcf
.fcf_flag
= 0;
3953 spin_unlock_irq(&phba
->hbalock
);
3955 /* Now physically reset the device */
3956 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3957 "0389 Performing PCI function reset!\n");
3959 /* Turn off parity checking and serr during the physical reset */
3960 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3961 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3962 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3964 /* Perform FCoE PCI function reset */
3965 lpfc_sli4_queue_destroy(phba
);
3966 rc
= lpfc_pci_function_reset(phba
);
3968 /* Restore PCI cmd register */
3969 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3975 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3976 * @phba: Pointer to HBA context object.
3978 * This function is called in the SLI initialization code path to
3979 * restart the HBA. The caller is not required to hold any lock.
3980 * This function writes MBX_RESTART mailbox command to the SLIM and
3981 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3982 * function to free any pending commands. The function enables
3983 * POST only during the first initialization. The function returns zero.
3984 * The function does not guarantee completion of MBX_RESTART mailbox
3985 * command before the return of this function.
3988 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3991 struct lpfc_sli
*psli
;
3992 volatile uint32_t word0
;
3993 void __iomem
*to_slim
;
3994 uint32_t hba_aer_enabled
;
3996 spin_lock_irq(&phba
->hbalock
);
3998 /* Take PCIe device Advanced Error Reporting (AER) state */
3999 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4004 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4005 "0337 Restart HBA Data: x%x x%x\n",
4006 phba
->pport
->port_state
, psli
->sli_flag
);
4009 mb
= (MAILBOX_t
*) &word0
;
4010 mb
->mbxCommand
= MBX_RESTART
;
4013 lpfc_reset_barrier(phba
);
4015 to_slim
= phba
->MBslimaddr
;
4016 writel(*(uint32_t *) mb
, to_slim
);
4017 readl(to_slim
); /* flush */
4019 /* Only skip post after fc_ffinit is completed */
4020 if (phba
->pport
->port_state
)
4021 word0
= 1; /* This is really setting up word1 */
4023 word0
= 0; /* This is really setting up word1 */
4024 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4025 writel(*(uint32_t *) mb
, to_slim
);
4026 readl(to_slim
); /* flush */
4028 lpfc_sli_brdreset(phba
);
4029 phba
->pport
->stopped
= 0;
4030 phba
->link_state
= LPFC_INIT_START
;
4032 spin_unlock_irq(&phba
->hbalock
);
4034 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4035 psli
->stats_start
= get_seconds();
4037 /* Give the INITFF and Post time to settle. */
4040 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4041 if (hba_aer_enabled
)
4042 pci_disable_pcie_error_reporting(phba
->pcidev
);
4044 lpfc_hba_down_post(phba
);
4050 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4051 * @phba: Pointer to HBA context object.
4053 * This function is called in the SLI initialization code path to restart
4054 * a SLI4 HBA. The caller is not required to hold any lock.
4055 * At the end of the function, it calls lpfc_hba_down_post function to
4056 * free any pending commands.
4059 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4061 struct lpfc_sli
*psli
= &phba
->sli
;
4062 uint32_t hba_aer_enabled
;
4066 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4067 "0296 Restart HBA Data: x%x x%x\n",
4068 phba
->pport
->port_state
, psli
->sli_flag
);
4070 /* Take PCIe device Advanced Error Reporting (AER) state */
4071 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4073 rc
= lpfc_sli4_brdreset(phba
);
4075 spin_lock_irq(&phba
->hbalock
);
4076 phba
->pport
->stopped
= 0;
4077 phba
->link_state
= LPFC_INIT_START
;
4079 spin_unlock_irq(&phba
->hbalock
);
4081 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4082 psli
->stats_start
= get_seconds();
4084 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4085 if (hba_aer_enabled
)
4086 pci_disable_pcie_error_reporting(phba
->pcidev
);
4088 lpfc_hba_down_post(phba
);
4094 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4095 * @phba: Pointer to HBA context object.
4097 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4098 * API jump table function pointer from the lpfc_hba struct.
4101 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4103 return phba
->lpfc_sli_brdrestart(phba
);
4107 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4108 * @phba: Pointer to HBA context object.
4110 * This function is called after a HBA restart to wait for successful
4111 * restart of the HBA. Successful restart of the HBA is indicated by
4112 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4113 * iteration, the function will restart the HBA again. The function returns
4114 * zero if HBA successfully restarted else returns negative error code.
4117 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4119 uint32_t status
, i
= 0;
4121 /* Read the HBA Host Status Register */
4122 if (lpfc_readl(phba
->HSregaddr
, &status
))
4125 /* Check status register to see what current state is */
4127 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4129 /* Check every 10ms for 10 retries, then every 100ms for 90
4130 * retries, then every 1 sec for 50 retires for a total of
4131 * ~60 seconds before reset the board again and check every
4132 * 1 sec for 50 retries. The up to 60 seconds before the
4133 * board ready is required by the Falcon FIPS zeroization
4134 * complete, and any reset the board in between shall cause
4135 * restart of zeroization, further delay the board ready.
4138 /* Adapter failed to init, timeout, status reg
4140 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4141 "0436 Adapter failed to init, "
4142 "timeout, status reg x%x, "
4143 "FW Data: A8 x%x AC x%x\n", status
,
4144 readl(phba
->MBslimaddr
+ 0xa8),
4145 readl(phba
->MBslimaddr
+ 0xac));
4146 phba
->link_state
= LPFC_HBA_ERROR
;
4150 /* Check to see if any errors occurred during init */
4151 if (status
& HS_FFERM
) {
4152 /* ERROR: During chipset initialization */
4153 /* Adapter failed to init, chipset, status reg
4155 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4156 "0437 Adapter failed to init, "
4157 "chipset, status reg x%x, "
4158 "FW Data: A8 x%x AC x%x\n", status
,
4159 readl(phba
->MBslimaddr
+ 0xa8),
4160 readl(phba
->MBslimaddr
+ 0xac));
4161 phba
->link_state
= LPFC_HBA_ERROR
;
4174 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4175 lpfc_sli_brdrestart(phba
);
4177 /* Read the HBA Host Status Register */
4178 if (lpfc_readl(phba
->HSregaddr
, &status
))
4182 /* Check to see if any errors occurred during init */
4183 if (status
& HS_FFERM
) {
4184 /* ERROR: During chipset initialization */
4185 /* Adapter failed to init, chipset, status reg <status> */
4186 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4187 "0438 Adapter failed to init, chipset, "
4189 "FW Data: A8 x%x AC x%x\n", status
,
4190 readl(phba
->MBslimaddr
+ 0xa8),
4191 readl(phba
->MBslimaddr
+ 0xac));
4192 phba
->link_state
= LPFC_HBA_ERROR
;
4196 /* Clear all interrupt enable conditions */
4197 writel(0, phba
->HCregaddr
);
4198 readl(phba
->HCregaddr
); /* flush */
4200 /* setup host attn register */
4201 writel(0xffffffff, phba
->HAregaddr
);
4202 readl(phba
->HAregaddr
); /* flush */
4207 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4209 * This function calculates and returns the number of HBQs required to be
4213 lpfc_sli_hbq_count(void)
4215 return ARRAY_SIZE(lpfc_hbq_defs
);
4219 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4221 * This function adds the number of hbq entries in every HBQ to get
4222 * the total number of hbq entries required for the HBA and returns
4226 lpfc_sli_hbq_entry_count(void)
4228 int hbq_count
= lpfc_sli_hbq_count();
4232 for (i
= 0; i
< hbq_count
; ++i
)
4233 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4238 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4240 * This function calculates amount of memory required for all hbq entries
4241 * to be configured and returns the total memory required.
4244 lpfc_sli_hbq_size(void)
4246 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4250 * lpfc_sli_hbq_setup - configure and initialize HBQs
4251 * @phba: Pointer to HBA context object.
4253 * This function is called during the SLI initialization to configure
4254 * all the HBQs and post buffers to the HBQ. The caller is not
4255 * required to hold any locks. This function will return zero if successful
4256 * else it will return negative error code.
4259 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4261 int hbq_count
= lpfc_sli_hbq_count();
4265 uint32_t hbq_entry_index
;
4267 /* Get a Mailbox buffer to setup mailbox
4268 * commands for HBA initialization
4270 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4277 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4278 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4279 phba
->hbq_in_use
= 1;
4281 hbq_entry_index
= 0;
4282 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4283 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4284 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4285 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4286 phba
->hbqs
[hbqno
].entry_count
=
4287 lpfc_hbq_defs
[hbqno
]->entry_count
;
4288 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4289 hbq_entry_index
, pmb
);
4290 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4292 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4293 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4294 mbxStatus <status>, ring <num> */
4296 lpfc_printf_log(phba
, KERN_ERR
,
4297 LOG_SLI
| LOG_VPORT
,
4298 "1805 Adapter failed to init. "
4299 "Data: x%x x%x x%x\n",
4301 pmbox
->mbxStatus
, hbqno
);
4303 phba
->link_state
= LPFC_HBA_ERROR
;
4304 mempool_free(pmb
, phba
->mbox_mem_pool
);
4308 phba
->hbq_count
= hbq_count
;
4310 mempool_free(pmb
, phba
->mbox_mem_pool
);
4312 /* Initially populate or replenish the HBQs */
4313 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4314 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4319 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4320 * @phba: Pointer to HBA context object.
4322 * This function is called during the SLI initialization to configure
4323 * all the HBQs and post buffers to the HBQ. The caller is not
4324 * required to hold any locks. This function will return zero if successful
4325 * else it will return negative error code.
4328 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4330 phba
->hbq_in_use
= 1;
4331 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4332 phba
->hbq_count
= 1;
4333 /* Initially populate or replenish the HBQs */
4334 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4339 * lpfc_sli_config_port - Issue config port mailbox command
4340 * @phba: Pointer to HBA context object.
4341 * @sli_mode: sli mode - 2/3
4343 * This function is called by the sli intialization code path
4344 * to issue config_port mailbox command. This function restarts the
4345 * HBA firmware and issues a config_port mailbox command to configure
4346 * the SLI interface in the sli mode specified by sli_mode
4347 * variable. The caller is not required to hold any locks.
4348 * The function returns 0 if successful, else returns negative error
4352 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4355 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4357 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4359 phba
->link_state
= LPFC_HBA_ERROR
;
4363 phba
->sli_rev
= sli_mode
;
4364 while (resetcount
< 2 && !done
) {
4365 spin_lock_irq(&phba
->hbalock
);
4366 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4367 spin_unlock_irq(&phba
->hbalock
);
4368 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4369 lpfc_sli_brdrestart(phba
);
4370 rc
= lpfc_sli_chipset_init(phba
);
4374 spin_lock_irq(&phba
->hbalock
);
4375 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4376 spin_unlock_irq(&phba
->hbalock
);
4379 /* Call pre CONFIG_PORT mailbox command initialization. A
4380 * value of 0 means the call was successful. Any other
4381 * nonzero value is a failure, but if ERESTART is returned,
4382 * the driver may reset the HBA and try again.
4384 rc
= lpfc_config_port_prep(phba
);
4385 if (rc
== -ERESTART
) {
4386 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4391 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4392 lpfc_config_port(phba
, pmb
);
4393 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4394 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4395 LPFC_SLI3_HBQ_ENABLED
|
4396 LPFC_SLI3_CRP_ENABLED
|
4397 LPFC_SLI3_BG_ENABLED
|
4398 LPFC_SLI3_DSS_ENABLED
);
4399 if (rc
!= MBX_SUCCESS
) {
4400 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4401 "0442 Adapter failed to init, mbxCmd x%x "
4402 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4403 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4404 spin_lock_irq(&phba
->hbalock
);
4405 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4406 spin_unlock_irq(&phba
->hbalock
);
4409 /* Allow asynchronous mailbox command to go through */
4410 spin_lock_irq(&phba
->hbalock
);
4411 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4412 spin_unlock_irq(&phba
->hbalock
);
4415 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4416 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4417 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4418 "3110 Port did not grant ASABT\n");
4423 goto do_prep_failed
;
4425 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4426 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4428 goto do_prep_failed
;
4430 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4431 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4432 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4433 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4434 phba
->max_vpi
: phba
->max_vports
;
4438 phba
->fips_level
= 0;
4439 phba
->fips_spec_rev
= 0;
4440 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4441 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4442 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4443 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4444 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4445 "2850 Security Crypto Active. FIPS x%d "
4447 phba
->fips_level
, phba
->fips_spec_rev
);
4449 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4450 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4451 "2856 Config Port Security Crypto "
4453 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4455 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4456 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4457 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4458 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4460 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4461 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4463 if (phba
->cfg_enable_bg
) {
4464 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4465 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4467 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4468 "0443 Adapter did not grant "
4472 phba
->hbq_get
= NULL
;
4473 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4477 mempool_free(pmb
, phba
->mbox_mem_pool
);
4483 * lpfc_sli_hba_setup - SLI intialization function
4484 * @phba: Pointer to HBA context object.
4486 * This function is the main SLI intialization function. This function
4487 * is called by the HBA intialization code, HBA reset code and HBA
4488 * error attention handler code. Caller is not required to hold any
4489 * locks. This function issues config_port mailbox command to configure
4490 * the SLI, setup iocb rings and HBQ rings. In the end the function
4491 * calls the config_port_post function to issue init_link mailbox
4492 * command and to start the discovery. The function will return zero
4493 * if successful, else it will return negative error code.
4496 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4502 switch (lpfc_sli_mode
) {
4504 if (phba
->cfg_enable_npiv
) {
4505 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4506 "1824 NPIV enabled: Override lpfc_sli_mode "
4507 "parameter (%d) to auto (0).\n",
4517 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4518 "1819 Unrecognized lpfc_sli_mode "
4519 "parameter: %d.\n", lpfc_sli_mode
);
4524 rc
= lpfc_sli_config_port(phba
, mode
);
4526 if (rc
&& lpfc_sli_mode
== 3)
4527 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4528 "1820 Unable to select SLI-3. "
4529 "Not supported by adapter.\n");
4530 if (rc
&& mode
!= 2)
4531 rc
= lpfc_sli_config_port(phba
, 2);
4533 goto lpfc_sli_hba_setup_error
;
4535 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4536 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4537 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4539 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4540 "2709 This device supports "
4541 "Advanced Error Reporting (AER)\n");
4542 spin_lock_irq(&phba
->hbalock
);
4543 phba
->hba_flag
|= HBA_AER_ENABLED
;
4544 spin_unlock_irq(&phba
->hbalock
);
4546 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4547 "2708 This device does not support "
4548 "Advanced Error Reporting (AER)\n");
4549 phba
->cfg_aer_support
= 0;
4553 if (phba
->sli_rev
== 3) {
4554 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4555 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4557 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4558 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4559 phba
->sli3_options
= 0;
4562 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4563 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4564 phba
->sli_rev
, phba
->max_vpi
);
4565 rc
= lpfc_sli_ring_map(phba
);
4568 goto lpfc_sli_hba_setup_error
;
4570 /* Initialize VPIs. */
4571 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4573 * The VPI bitmask and physical ID array are allocated
4574 * and initialized once only - at driver load. A port
4575 * reset doesn't need to reinitialize this memory.
4577 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4578 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4579 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4581 if (!phba
->vpi_bmask
) {
4583 goto lpfc_sli_hba_setup_error
;
4586 phba
->vpi_ids
= kzalloc(
4587 (phba
->max_vpi
+1) * sizeof(uint16_t),
4589 if (!phba
->vpi_ids
) {
4590 kfree(phba
->vpi_bmask
);
4592 goto lpfc_sli_hba_setup_error
;
4594 for (i
= 0; i
< phba
->max_vpi
; i
++)
4595 phba
->vpi_ids
[i
] = i
;
4600 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4601 rc
= lpfc_sli_hbq_setup(phba
);
4603 goto lpfc_sli_hba_setup_error
;
4605 spin_lock_irq(&phba
->hbalock
);
4606 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4607 spin_unlock_irq(&phba
->hbalock
);
4609 rc
= lpfc_config_port_post(phba
);
4611 goto lpfc_sli_hba_setup_error
;
4615 lpfc_sli_hba_setup_error
:
4616 phba
->link_state
= LPFC_HBA_ERROR
;
4617 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4618 "0445 Firmware initialization failed\n");
4623 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4624 * @phba: Pointer to HBA context object.
4625 * @mboxq: mailbox pointer.
4626 * This function issue a dump mailbox command to read config region
4627 * 23 and parse the records in the region and populate driver
4631 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4633 LPFC_MBOXQ_t
*mboxq
;
4634 struct lpfc_dmabuf
*mp
;
4635 struct lpfc_mqe
*mqe
;
4636 uint32_t data_length
;
4639 /* Program the default value of vlan_id and fc_map */
4640 phba
->valid_vlan
= 0;
4641 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4642 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4643 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4645 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4649 mqe
= &mboxq
->u
.mqe
;
4650 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4652 goto out_free_mboxq
;
4655 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4656 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4658 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4659 "(%d):2571 Mailbox cmd x%x Status x%x "
4660 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4661 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4662 "CQ: x%x x%x x%x x%x\n",
4663 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4664 bf_get(lpfc_mqe_command
, mqe
),
4665 bf_get(lpfc_mqe_status
, mqe
),
4666 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4667 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4668 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4669 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4670 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4671 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4672 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4673 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4674 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4676 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4677 mboxq
->mcqe
.trailer
);
4680 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4683 goto out_free_mboxq
;
4685 data_length
= mqe
->un
.mb_words
[5];
4686 if (data_length
> DMP_RGN23_SIZE
) {
4687 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4690 goto out_free_mboxq
;
4693 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4694 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4699 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4704 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4705 * @phba: pointer to lpfc hba data structure.
4706 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4707 * @vpd: pointer to the memory to hold resulting port vpd data.
4708 * @vpd_size: On input, the number of bytes allocated to @vpd.
4709 * On output, the number of data bytes in @vpd.
4711 * This routine executes a READ_REV SLI4 mailbox command. In
4712 * addition, this routine gets the port vpd data.
4716 * -ENOMEM - could not allocated memory.
4719 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4720 uint8_t *vpd
, uint32_t *vpd_size
)
4724 struct lpfc_dmabuf
*dmabuf
;
4725 struct lpfc_mqe
*mqe
;
4727 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4732 * Get a DMA buffer for the vpd data resulting from the READ_REV
4735 dma_size
= *vpd_size
;
4736 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4740 if (!dmabuf
->virt
) {
4744 memset(dmabuf
->virt
, 0, dma_size
);
4747 * The SLI4 implementation of READ_REV conflicts at word1,
4748 * bits 31:16 and SLI4 adds vpd functionality not present
4749 * in SLI3. This code corrects the conflicts.
4751 lpfc_read_rev(phba
, mboxq
);
4752 mqe
= &mboxq
->u
.mqe
;
4753 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4754 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4755 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4756 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4757 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4759 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4761 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4762 dmabuf
->virt
, dmabuf
->phys
);
4768 * The available vpd length cannot be bigger than the
4769 * DMA buffer passed to the port. Catch the less than
4770 * case and update the caller's size.
4772 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4773 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4775 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4777 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4778 dmabuf
->virt
, dmabuf
->phys
);
4784 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4785 * @phba: pointer to lpfc hba data structure.
4787 * This routine retrieves SLI4 device physical port name this PCI function
4792 * otherwise - failed to retrieve physical port name
4795 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4797 LPFC_MBOXQ_t
*mboxq
;
4798 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4799 struct lpfc_controller_attribute
*cntl_attr
;
4800 struct lpfc_mbx_get_port_name
*get_port_name
;
4801 void *virtaddr
= NULL
;
4802 uint32_t alloclen
, reqlen
;
4803 uint32_t shdr_status
, shdr_add_status
;
4804 union lpfc_sli4_cfg_shdr
*shdr
;
4805 char cport_name
= 0;
4808 /* We assume nothing at this point */
4809 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4810 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4812 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4815 /* obtain link type and link number via READ_CONFIG */
4816 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4817 lpfc_sli4_read_config(phba
);
4818 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4819 goto retrieve_ppname
;
4821 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4822 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4823 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4824 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4825 LPFC_SLI4_MBX_NEMBED
);
4826 if (alloclen
< reqlen
) {
4827 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4828 "3084 Allocated DMA memory size (%d) is "
4829 "less than the requested DMA memory size "
4830 "(%d)\n", alloclen
, reqlen
);
4832 goto out_free_mboxq
;
4834 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4835 virtaddr
= mboxq
->sge_array
->addr
[0];
4836 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4837 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4838 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4839 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4840 if (shdr_status
|| shdr_add_status
|| rc
) {
4841 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4842 "3085 Mailbox x%x (x%x/x%x) failed, "
4843 "rc:x%x, status:x%x, add_status:x%x\n",
4844 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4845 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4846 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4847 rc
, shdr_status
, shdr_add_status
);
4849 goto out_free_mboxq
;
4851 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4852 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4853 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4854 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4855 phba
->sli4_hba
.lnk_info
.lnk_no
=
4856 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4857 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4858 "3086 lnk_type:%d, lnk_numb:%d\n",
4859 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4860 phba
->sli4_hba
.lnk_info
.lnk_no
);
4863 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4864 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4865 sizeof(struct lpfc_mbx_get_port_name
) -
4866 sizeof(struct lpfc_sli4_cfg_mhdr
),
4867 LPFC_SLI4_MBX_EMBED
);
4868 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4869 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4870 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4871 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4872 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4873 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4874 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4875 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4876 if (shdr_status
|| shdr_add_status
|| rc
) {
4877 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4878 "3087 Mailbox x%x (x%x/x%x) failed: "
4879 "rc:x%x, status:x%x, add_status:x%x\n",
4880 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4881 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4882 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4883 rc
, shdr_status
, shdr_add_status
);
4885 goto out_free_mboxq
;
4887 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4888 case LPFC_LINK_NUMBER_0
:
4889 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4890 &get_port_name
->u
.response
);
4891 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4893 case LPFC_LINK_NUMBER_1
:
4894 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4895 &get_port_name
->u
.response
);
4896 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4898 case LPFC_LINK_NUMBER_2
:
4899 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4900 &get_port_name
->u
.response
);
4901 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4903 case LPFC_LINK_NUMBER_3
:
4904 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4905 &get_port_name
->u
.response
);
4906 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4912 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4913 phba
->Port
[0] = cport_name
;
4914 phba
->Port
[1] = '\0';
4915 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4916 "3091 SLI get port name: %s\n", phba
->Port
);
4920 if (rc
!= MBX_TIMEOUT
) {
4921 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4922 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4924 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4930 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4931 * @phba: pointer to lpfc hba data structure.
4933 * This routine is called to explicitly arm the SLI4 device's completion and
4937 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4941 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4942 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4944 if (phba
->sli4_hba
.fcp_cq
) {
4946 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4948 } while (++fcp_eqidx
< phba
->cfg_fcp_io_channel
);
4950 if (phba
->sli4_hba
.hba_eq
) {
4951 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
4953 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
4959 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4960 * @phba: Pointer to HBA context object.
4961 * @type: The resource extent type.
4962 * @extnt_count: buffer to hold port available extent count.
4963 * @extnt_size: buffer to hold element count per extent.
4965 * This function calls the port and retrievs the number of available
4966 * extents and their size for a particular extent type.
4968 * Returns: 0 if successful. Nonzero otherwise.
4971 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
4972 uint16_t *extnt_count
, uint16_t *extnt_size
)
4977 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
4980 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4984 /* Find out how many extents are available for this resource type */
4985 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
4986 sizeof(struct lpfc_sli4_cfg_mhdr
));
4987 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4988 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
4989 length
, LPFC_SLI4_MBX_EMBED
);
4991 /* Send an extents count of 0 - the GET doesn't use it. */
4992 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
4993 LPFC_SLI4_MBX_EMBED
);
4999 if (!phba
->sli4_hba
.intr_enable
)
5000 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5002 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5003 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5010 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5011 if (bf_get(lpfc_mbox_hdr_status
,
5012 &rsrc_info
->header
.cfg_shdr
.response
)) {
5013 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5014 "2930 Failed to get resource extents "
5015 "Status 0x%x Add'l Status 0x%x\n",
5016 bf_get(lpfc_mbox_hdr_status
,
5017 &rsrc_info
->header
.cfg_shdr
.response
),
5018 bf_get(lpfc_mbox_hdr_add_status
,
5019 &rsrc_info
->header
.cfg_shdr
.response
));
5024 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5026 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5029 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5030 "3162 Retrieved extents type-%d from port: count:%d, "
5031 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5034 mempool_free(mbox
, phba
->mbox_mem_pool
);
5039 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5040 * @phba: Pointer to HBA context object.
5041 * @type: The extent type to check.
5043 * This function reads the current available extents from the port and checks
5044 * if the extent count or extent size has changed since the last access.
5045 * Callers use this routine post port reset to understand if there is a
5046 * extent reprovisioning requirement.
5049 * -Error: error indicates problem.
5050 * 1: Extent count or size has changed.
5054 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5056 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5057 uint16_t size_diff
, rsrc_ext_size
;
5059 struct lpfc_rsrc_blks
*rsrc_entry
;
5060 struct list_head
*rsrc_blk_list
= NULL
;
5064 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5071 case LPFC_RSC_TYPE_FCOE_RPI
:
5072 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5074 case LPFC_RSC_TYPE_FCOE_VPI
:
5075 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5077 case LPFC_RSC_TYPE_FCOE_XRI
:
5078 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5080 case LPFC_RSC_TYPE_FCOE_VFI
:
5081 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5087 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5089 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5093 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5100 * lpfc_sli4_cfg_post_extnts -
5101 * @phba: Pointer to HBA context object.
5102 * @extnt_cnt - number of available extents.
5103 * @type - the extent type (rpi, xri, vfi, vpi).
5104 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5105 * @mbox - pointer to the caller's allocated mailbox structure.
5107 * This function executes the extents allocation request. It also
5108 * takes care of the amount of memory needed to allocate or get the
5109 * allocated extents. It is the caller's responsibility to evaluate
5113 * -Error: Error value describes the condition found.
5117 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5118 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5123 uint32_t alloc_len
, mbox_tmo
;
5125 /* Calculate the total requested length of the dma memory */
5126 req_len
= extnt_cnt
* sizeof(uint16_t);
5129 * Calculate the size of an embedded mailbox. The uint32_t
5130 * accounts for extents-specific word.
5132 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5136 * Presume the allocation and response will fit into an embedded
5137 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5139 *emb
= LPFC_SLI4_MBX_EMBED
;
5140 if (req_len
> emb_len
) {
5141 req_len
= extnt_cnt
* sizeof(uint16_t) +
5142 sizeof(union lpfc_sli4_cfg_shdr
) +
5144 *emb
= LPFC_SLI4_MBX_NEMBED
;
5147 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5148 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5150 if (alloc_len
< req_len
) {
5151 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5152 "2982 Allocated DMA memory size (x%x) is "
5153 "less than the requested DMA memory "
5154 "size (x%x)\n", alloc_len
, req_len
);
5157 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5161 if (!phba
->sli4_hba
.intr_enable
)
5162 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5164 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5165 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5174 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5175 * @phba: Pointer to HBA context object.
5176 * @type: The resource extent type to allocate.
5178 * This function allocates the number of elements for the specified
5182 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5185 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5186 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5189 unsigned long longs
;
5190 unsigned long *bmask
;
5191 struct lpfc_rsrc_blks
*rsrc_blks
;
5194 struct lpfc_id_range
*id_array
= NULL
;
5195 void *virtaddr
= NULL
;
5196 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5197 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5198 struct list_head
*ext_blk_list
;
5200 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5206 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5207 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5208 "3009 No available Resource Extents "
5209 "for resource type 0x%x: Count: 0x%x, "
5210 "Size 0x%x\n", type
, rsrc_cnt
,
5215 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5216 "2903 Post resource extents type-0x%x: "
5217 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5219 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5223 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5230 * Figure out where the response is located. Then get local pointers
5231 * to the response data. The port does not guarantee to respond to
5232 * all extents counts request so update the local variable with the
5233 * allocated count from the port.
5235 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5236 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5237 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5238 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5240 virtaddr
= mbox
->sge_array
->addr
[0];
5241 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5242 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5243 id_array
= &n_rsrc
->id
;
5246 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5247 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5250 * Based on the resource size and count, correct the base and max
5253 length
= sizeof(struct lpfc_rsrc_blks
);
5255 case LPFC_RSC_TYPE_FCOE_RPI
:
5256 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5257 sizeof(unsigned long),
5259 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5263 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5266 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5267 kfree(phba
->sli4_hba
.rpi_bmask
);
5273 * The next_rpi was initialized with the maximum available
5274 * count but the port may allocate a smaller number. Catch
5275 * that case and update the next_rpi.
5277 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5279 /* Initialize local ptrs for common extent processing later. */
5280 bmask
= phba
->sli4_hba
.rpi_bmask
;
5281 ids
= phba
->sli4_hba
.rpi_ids
;
5282 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5284 case LPFC_RSC_TYPE_FCOE_VPI
:
5285 phba
->vpi_bmask
= kzalloc(longs
*
5286 sizeof(unsigned long),
5288 if (unlikely(!phba
->vpi_bmask
)) {
5292 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5295 if (unlikely(!phba
->vpi_ids
)) {
5296 kfree(phba
->vpi_bmask
);
5301 /* Initialize local ptrs for common extent processing later. */
5302 bmask
= phba
->vpi_bmask
;
5303 ids
= phba
->vpi_ids
;
5304 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5306 case LPFC_RSC_TYPE_FCOE_XRI
:
5307 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5308 sizeof(unsigned long),
5310 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5314 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5315 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5318 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5319 kfree(phba
->sli4_hba
.xri_bmask
);
5324 /* Initialize local ptrs for common extent processing later. */
5325 bmask
= phba
->sli4_hba
.xri_bmask
;
5326 ids
= phba
->sli4_hba
.xri_ids
;
5327 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5329 case LPFC_RSC_TYPE_FCOE_VFI
:
5330 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5331 sizeof(unsigned long),
5333 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5337 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5340 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5341 kfree(phba
->sli4_hba
.vfi_bmask
);
5346 /* Initialize local ptrs for common extent processing later. */
5347 bmask
= phba
->sli4_hba
.vfi_bmask
;
5348 ids
= phba
->sli4_hba
.vfi_ids
;
5349 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5352 /* Unsupported Opcode. Fail call. */
5356 ext_blk_list
= NULL
;
5361 * Complete initializing the extent configuration with the
5362 * allocated ids assigned to this function. The bitmask serves
5363 * as an index into the array and manages the available ids. The
5364 * array just stores the ids communicated to the port via the wqes.
5366 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5368 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5371 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5374 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5375 if (unlikely(!rsrc_blks
)) {
5381 rsrc_blks
->rsrc_start
= rsrc_id
;
5382 rsrc_blks
->rsrc_size
= rsrc_size
;
5383 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5384 rsrc_start
= rsrc_id
;
5385 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5386 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5387 lpfc_sli4_get_els_iocb_cnt(phba
);
5389 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5394 /* Entire word processed. Get next word.*/
5399 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5404 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5405 * @phba: Pointer to HBA context object.
5406 * @type: the extent's type.
5408 * This function deallocates all extents of a particular resource type.
5409 * SLI4 does not allow for deallocating a particular extent range. It
5410 * is the caller's responsibility to release all kernel memory resources.
5413 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5416 uint32_t length
, mbox_tmo
= 0;
5418 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5419 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5421 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5426 * This function sends an embedded mailbox because it only sends the
5427 * the resource type. All extents of this type are released by the
5430 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5431 sizeof(struct lpfc_sli4_cfg_mhdr
));
5432 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5433 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5434 length
, LPFC_SLI4_MBX_EMBED
);
5436 /* Send an extents count of 0 - the dealloc doesn't use it. */
5437 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5438 LPFC_SLI4_MBX_EMBED
);
5443 if (!phba
->sli4_hba
.intr_enable
)
5444 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5446 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5447 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5454 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5455 if (bf_get(lpfc_mbox_hdr_status
,
5456 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5457 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5458 "2919 Failed to release resource extents "
5459 "for type %d - Status 0x%x Add'l Status 0x%x. "
5460 "Resource memory not released.\n",
5462 bf_get(lpfc_mbox_hdr_status
,
5463 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5464 bf_get(lpfc_mbox_hdr_add_status
,
5465 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5470 /* Release kernel memory resources for the specific type. */
5472 case LPFC_RSC_TYPE_FCOE_VPI
:
5473 kfree(phba
->vpi_bmask
);
5474 kfree(phba
->vpi_ids
);
5475 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5476 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5477 &phba
->lpfc_vpi_blk_list
, list
) {
5478 list_del_init(&rsrc_blk
->list
);
5482 case LPFC_RSC_TYPE_FCOE_XRI
:
5483 kfree(phba
->sli4_hba
.xri_bmask
);
5484 kfree(phba
->sli4_hba
.xri_ids
);
5485 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5486 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5487 list_del_init(&rsrc_blk
->list
);
5491 case LPFC_RSC_TYPE_FCOE_VFI
:
5492 kfree(phba
->sli4_hba
.vfi_bmask
);
5493 kfree(phba
->sli4_hba
.vfi_ids
);
5494 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5495 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5496 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5497 list_del_init(&rsrc_blk
->list
);
5501 case LPFC_RSC_TYPE_FCOE_RPI
:
5502 /* RPI bitmask and physical id array are cleaned up earlier. */
5503 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5504 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5505 list_del_init(&rsrc_blk
->list
);
5513 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5516 mempool_free(mbox
, phba
->mbox_mem_pool
);
5521 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5522 * @phba: Pointer to HBA context object.
5524 * This function allocates all SLI4 resource identifiers.
5527 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5529 int i
, rc
, error
= 0;
5530 uint16_t count
, base
;
5531 unsigned long longs
;
5533 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5534 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5535 if (phba
->sli4_hba
.extents_in_use
) {
5537 * The port supports resource extents. The XRI, VPI, VFI, RPI
5538 * resource extent count must be read and allocated before
5539 * provisioning the resource id arrays.
5541 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5542 LPFC_IDX_RSRC_RDY
) {
5544 * Extent-based resources are set - the driver could
5545 * be in a port reset. Figure out if any corrective
5546 * actions need to be taken.
5548 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5549 LPFC_RSC_TYPE_FCOE_VFI
);
5552 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5553 LPFC_RSC_TYPE_FCOE_VPI
);
5556 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5557 LPFC_RSC_TYPE_FCOE_XRI
);
5560 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5561 LPFC_RSC_TYPE_FCOE_RPI
);
5566 * It's possible that the number of resources
5567 * provided to this port instance changed between
5568 * resets. Detect this condition and reallocate
5569 * resources. Otherwise, there is no action.
5572 lpfc_printf_log(phba
, KERN_INFO
,
5573 LOG_MBOX
| LOG_INIT
,
5574 "2931 Detected extent resource "
5575 "change. Reallocating all "
5577 rc
= lpfc_sli4_dealloc_extent(phba
,
5578 LPFC_RSC_TYPE_FCOE_VFI
);
5579 rc
= lpfc_sli4_dealloc_extent(phba
,
5580 LPFC_RSC_TYPE_FCOE_VPI
);
5581 rc
= lpfc_sli4_dealloc_extent(phba
,
5582 LPFC_RSC_TYPE_FCOE_XRI
);
5583 rc
= lpfc_sli4_dealloc_extent(phba
,
5584 LPFC_RSC_TYPE_FCOE_RPI
);
5589 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5593 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5597 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5601 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5604 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5609 * The port does not support resource extents. The XRI, VPI,
5610 * VFI, RPI resource ids were determined from READ_CONFIG.
5611 * Just allocate the bitmasks and provision the resource id
5612 * arrays. If a port reset is active, the resources don't
5613 * need any action - just exit.
5615 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5616 LPFC_IDX_RSRC_RDY
) {
5617 lpfc_sli4_dealloc_resource_identifiers(phba
);
5618 lpfc_sli4_remove_rpis(phba
);
5621 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5622 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5623 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5624 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5625 sizeof(unsigned long),
5627 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5631 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5634 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5636 goto free_rpi_bmask
;
5639 for (i
= 0; i
< count
; i
++)
5640 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5643 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5644 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5645 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5646 phba
->vpi_bmask
= kzalloc(longs
*
5647 sizeof(unsigned long),
5649 if (unlikely(!phba
->vpi_bmask
)) {
5653 phba
->vpi_ids
= kzalloc(count
*
5656 if (unlikely(!phba
->vpi_ids
)) {
5658 goto free_vpi_bmask
;
5661 for (i
= 0; i
< count
; i
++)
5662 phba
->vpi_ids
[i
] = base
+ i
;
5665 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5666 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5667 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5668 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5669 sizeof(unsigned long),
5671 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5675 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5676 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5679 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5681 goto free_xri_bmask
;
5684 for (i
= 0; i
< count
; i
++)
5685 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5688 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5689 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5690 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5691 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5692 sizeof(unsigned long),
5694 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5698 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5701 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5703 goto free_vfi_bmask
;
5706 for (i
= 0; i
< count
; i
++)
5707 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5710 * Mark all resources ready. An HBA reset doesn't need
5711 * to reset the initialization.
5713 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5719 kfree(phba
->sli4_hba
.vfi_bmask
);
5721 kfree(phba
->sli4_hba
.xri_ids
);
5723 kfree(phba
->sli4_hba
.xri_bmask
);
5725 kfree(phba
->vpi_ids
);
5727 kfree(phba
->vpi_bmask
);
5729 kfree(phba
->sli4_hba
.rpi_ids
);
5731 kfree(phba
->sli4_hba
.rpi_bmask
);
5737 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5738 * @phba: Pointer to HBA context object.
5740 * This function allocates the number of elements for the specified
5744 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5746 if (phba
->sli4_hba
.extents_in_use
) {
5747 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5748 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5749 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5750 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5752 kfree(phba
->vpi_bmask
);
5753 kfree(phba
->vpi_ids
);
5754 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5755 kfree(phba
->sli4_hba
.xri_bmask
);
5756 kfree(phba
->sli4_hba
.xri_ids
);
5757 kfree(phba
->sli4_hba
.vfi_bmask
);
5758 kfree(phba
->sli4_hba
.vfi_ids
);
5759 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5760 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5767 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5768 * @phba: Pointer to HBA context object.
5769 * @type: The resource extent type.
5770 * @extnt_count: buffer to hold port extent count response
5771 * @extnt_size: buffer to hold port extent size response.
5773 * This function calls the port to read the host allocated extents
5774 * for a particular type.
5777 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5778 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5782 uint16_t curr_blks
= 0;
5783 uint32_t req_len
, emb_len
;
5784 uint32_t alloc_len
, mbox_tmo
;
5785 struct list_head
*blk_list_head
;
5786 struct lpfc_rsrc_blks
*rsrc_blk
;
5788 void *virtaddr
= NULL
;
5789 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5790 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5791 union lpfc_sli4_cfg_shdr
*shdr
;
5794 case LPFC_RSC_TYPE_FCOE_VPI
:
5795 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5797 case LPFC_RSC_TYPE_FCOE_XRI
:
5798 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5800 case LPFC_RSC_TYPE_FCOE_VFI
:
5801 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5803 case LPFC_RSC_TYPE_FCOE_RPI
:
5804 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5810 /* Count the number of extents currently allocatd for this type. */
5811 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5812 if (curr_blks
== 0) {
5814 * The GET_ALLOCATED mailbox does not return the size,
5815 * just the count. The size should be just the size
5816 * stored in the current allocated block and all sizes
5817 * for an extent type are the same so set the return
5820 *extnt_size
= rsrc_blk
->rsrc_size
;
5825 /* Calculate the total requested length of the dma memory. */
5826 req_len
= curr_blks
* sizeof(uint16_t);
5829 * Calculate the size of an embedded mailbox. The uint32_t
5830 * accounts for extents-specific word.
5832 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5836 * Presume the allocation and response will fit into an embedded
5837 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5839 emb
= LPFC_SLI4_MBX_EMBED
;
5841 if (req_len
> emb_len
) {
5842 req_len
= curr_blks
* sizeof(uint16_t) +
5843 sizeof(union lpfc_sli4_cfg_shdr
) +
5845 emb
= LPFC_SLI4_MBX_NEMBED
;
5848 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5851 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5853 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5854 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5856 if (alloc_len
< req_len
) {
5857 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5858 "2983 Allocated DMA memory size (x%x) is "
5859 "less than the requested DMA memory "
5860 "size (x%x)\n", alloc_len
, req_len
);
5864 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5870 if (!phba
->sli4_hba
.intr_enable
)
5871 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5873 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5874 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5883 * Figure out where the response is located. Then get local pointers
5884 * to the response data. The port does not guarantee to respond to
5885 * all extents counts request so update the local variable with the
5886 * allocated count from the port.
5888 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5889 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5890 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5891 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5893 virtaddr
= mbox
->sge_array
->addr
[0];
5894 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5895 shdr
= &n_rsrc
->cfg_shdr
;
5896 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5899 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5900 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5901 "2984 Failed to read allocated resources "
5902 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5904 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5905 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5910 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5915 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
5916 * @phba: pointer to lpfc hba data structure.
5918 * This routine walks the list of els buffers that have been allocated and
5919 * repost them to the port by using SGL block post. This is needed after a
5920 * pci_function_reset/warm_start or start. It attempts to construct blocks
5921 * of els buffer sgls which contains contiguous xris and uses the non-embedded
5922 * SGL block post mailbox commands to post them to the port. For single els
5923 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
5924 * mailbox command for posting.
5926 * Returns: 0 = success, non-zero failure.
5929 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
5931 struct lpfc_sglq
*sglq_entry
= NULL
;
5932 struct lpfc_sglq
*sglq_entry_next
= NULL
;
5933 struct lpfc_sglq
*sglq_entry_first
= NULL
;
5934 int status
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
5935 int last_xritag
= NO_XRI
;
5936 LIST_HEAD(prep_sgl_list
);
5937 LIST_HEAD(blck_sgl_list
);
5938 LIST_HEAD(allc_sgl_list
);
5939 LIST_HEAD(post_sgl_list
);
5940 LIST_HEAD(free_sgl_list
);
5942 spin_lock(&phba
->hbalock
);
5943 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
5944 spin_unlock(&phba
->hbalock
);
5946 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
5947 &allc_sgl_list
, list
) {
5948 list_del_init(&sglq_entry
->list
);
5950 if ((last_xritag
!= NO_XRI
) &&
5951 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
5952 /* a hole in xri block, form a sgl posting block */
5953 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
5954 post_cnt
= block_cnt
- 1;
5955 /* prepare list for next posting block */
5956 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
5959 /* prepare list for next posting block */
5960 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
5961 /* enough sgls for non-embed sgl mbox command */
5962 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
5963 list_splice_init(&prep_sgl_list
,
5965 post_cnt
= block_cnt
;
5971 /* keep track of last sgl's xritag */
5972 last_xritag
= sglq_entry
->sli4_xritag
;
5974 /* end of repost sgl list condition for els buffers */
5975 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
5976 if (post_cnt
== 0) {
5977 list_splice_init(&prep_sgl_list
,
5979 post_cnt
= block_cnt
;
5980 } else if (block_cnt
== 1) {
5981 status
= lpfc_sli4_post_sgl(phba
,
5982 sglq_entry
->phys
, 0,
5983 sglq_entry
->sli4_xritag
);
5985 /* successful, put sgl to posted list */
5986 list_add_tail(&sglq_entry
->list
,
5989 /* Failure, put sgl to free list */
5990 lpfc_printf_log(phba
, KERN_WARNING
,
5992 "3159 Failed to post els "
5993 "sgl, xritag:x%x\n",
5994 sglq_entry
->sli4_xritag
);
5995 list_add_tail(&sglq_entry
->list
,
5997 spin_lock_irq(&phba
->hbalock
);
5998 phba
->sli4_hba
.els_xri_cnt
--;
5999 spin_unlock_irq(&phba
->hbalock
);
6004 /* continue until a nembed page worth of sgls */
6008 /* post the els buffer list sgls as a block */
6009 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
6013 /* success, put sgl list to posted sgl list */
6014 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6016 /* Failure, put sgl list to free sgl list */
6017 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6020 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6021 "3160 Failed to post els sgl-list, "
6023 sglq_entry_first
->sli4_xritag
,
6024 (sglq_entry_first
->sli4_xritag
+
6026 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6027 spin_lock_irq(&phba
->hbalock
);
6028 phba
->sli4_hba
.els_xri_cnt
-= post_cnt
;
6029 spin_unlock_irq(&phba
->hbalock
);
6032 /* don't reset xirtag due to hole in xri block */
6034 last_xritag
= NO_XRI
;
6036 /* reset els sgl post count for next round of posting */
6040 /* free the els sgls failed to post */
6041 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6043 /* push els sgls posted to the availble list */
6044 if (!list_empty(&post_sgl_list
)) {
6045 spin_lock(&phba
->hbalock
);
6046 list_splice_init(&post_sgl_list
,
6047 &phba
->sli4_hba
.lpfc_sgl_list
);
6048 spin_unlock(&phba
->hbalock
);
6050 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6051 "3161 Failure to post els sgl to port.\n");
6058 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6059 * @phba: Pointer to HBA context object.
6061 * This function is the main SLI4 device intialization PCI function. This
6062 * function is called by the HBA intialization code, HBA reset code and
6063 * HBA error attention handler code. Caller is not required to hold any
6067 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6070 LPFC_MBOXQ_t
*mboxq
;
6071 struct lpfc_mqe
*mqe
;
6074 uint32_t ftr_rsp
= 0;
6075 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6076 struct lpfc_vport
*vport
= phba
->pport
;
6077 struct lpfc_dmabuf
*mp
;
6079 /* Perform a PCI function reset to start from clean */
6080 rc
= lpfc_pci_function_reset(phba
);
6084 /* Check the HBA Host Status Register for readyness */
6085 rc
= lpfc_sli4_post_status_check(phba
);
6089 spin_lock_irq(&phba
->hbalock
);
6090 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6091 spin_unlock_irq(&phba
->hbalock
);
6095 * Allocate a single mailbox container for initializing the
6098 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6102 /* Issue READ_REV to collect vpd and FW information. */
6103 vpd_size
= SLI4_PAGE_SIZE
;
6104 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6110 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6115 mqe
= &mboxq
->u
.mqe
;
6116 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6117 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
6118 phba
->hba_flag
|= HBA_FCOE_MODE
;
6120 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6122 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6124 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6126 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6128 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6130 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6131 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6132 "0376 READ_REV Error. SLI Level %d "
6133 "FCoE enabled %d\n",
6134 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6141 * Continue initialization with default values even if driver failed
6142 * to read FCoE param config regions, only read parameters if the
6145 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6146 lpfc_sli4_read_fcoe_params(phba
))
6147 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6148 "2570 Failed to read FCoE parameters\n");
6151 * Retrieve sli4 device physical port name, failure of doing it
6152 * is considered as non-fatal.
6154 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6156 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6157 "3080 Successful retrieving SLI4 device "
6158 "physical port name: %s.\n", phba
->Port
);
6161 * Evaluate the read rev and vpd data. Populate the driver
6162 * state with the results. If this routine fails, the failure
6163 * is not fatal as the driver will use generic values.
6165 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6166 if (unlikely(!rc
)) {
6167 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6168 "0377 Error %d parsing vpd. "
6169 "Using defaults.\n", rc
);
6174 /* Save information as VPD data */
6175 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6176 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6177 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6178 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6180 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6182 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6184 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6186 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6187 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6188 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6189 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6190 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6191 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6192 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6193 "(%d):0380 READ_REV Status x%x "
6194 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6195 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6196 bf_get(lpfc_mqe_status
, mqe
),
6197 phba
->vpd
.rev
.opFwName
,
6198 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6199 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6202 * Discover the port's supported feature set and match it against the
6205 lpfc_request_features(phba
, mboxq
);
6206 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6213 * The port must support FCP initiator mode as this is the
6214 * only mode running in the host.
6216 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6217 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6218 "0378 No support for fcpi mode.\n");
6221 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6222 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6224 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6226 * If the port cannot support the host's requested features
6227 * then turn off the global config parameters to disable the
6228 * feature in the driver. This is not a fatal error.
6230 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6231 if (phba
->cfg_enable_bg
) {
6232 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6233 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6238 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6239 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6243 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6244 "0379 Feature Mismatch Data: x%08x %08x "
6245 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6246 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6247 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6248 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6249 phba
->cfg_enable_bg
= 0;
6250 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6251 phba
->cfg_enable_npiv
= 0;
6254 /* These SLI3 features are assumed in SLI4 */
6255 spin_lock_irq(&phba
->hbalock
);
6256 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6257 spin_unlock_irq(&phba
->hbalock
);
6260 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6261 * calls depends on these resources to complete port setup.
6263 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6265 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6266 "2920 Failed to alloc Resource IDs "
6271 /* Read the port's service parameters. */
6272 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6274 phba
->link_state
= LPFC_HBA_ERROR
;
6279 mboxq
->vport
= vport
;
6280 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6281 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6282 if (rc
== MBX_SUCCESS
) {
6283 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6288 * This memory was allocated by the lpfc_read_sparam routine. Release
6289 * it to the mbuf pool.
6291 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6293 mboxq
->context1
= NULL
;
6295 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6296 "0382 READ_SPARAM command failed "
6297 "status %d, mbxStatus x%x\n",
6298 rc
, bf_get(lpfc_mqe_status
, mqe
));
6299 phba
->link_state
= LPFC_HBA_ERROR
;
6304 lpfc_update_vport_wwn(vport
);
6306 /* Update the fc_host data structures with new wwn. */
6307 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6308 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6310 /* update host els and scsi xri-sgl sizes and mappings */
6311 rc
= lpfc_sli4_xri_sgl_update(phba
);
6313 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6314 "1400 Failed to update xri-sgl size and "
6315 "mapping: %d\n", rc
);
6319 /* register the els sgl pool to the port */
6320 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6322 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6323 "0582 Error %d during els sgl post "
6329 /* register the allocated scsi sgl pool to the port */
6330 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6332 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6333 "0383 Error %d during scsi sgl post "
6335 /* Some Scsi buffers were moved to the abort scsi list */
6336 /* A pci function reset will repost them */
6341 /* Post the rpi header region to the device. */
6342 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6344 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6345 "0393 Error %d during rpi post operation\n",
6350 lpfc_sli4_node_prep(phba
);
6352 /* Create all the SLI4 queues */
6353 rc
= lpfc_sli4_queue_create(phba
);
6355 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6356 "3089 Failed to allocate queues\n");
6358 goto out_stop_timers
;
6360 /* Set up all the queues to the device */
6361 rc
= lpfc_sli4_queue_setup(phba
);
6363 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6364 "0381 Error %d during queue setup.\n ", rc
);
6365 goto out_destroy_queue
;
6368 /* Arm the CQs and then EQs on device */
6369 lpfc_sli4_arm_cqeq_intr(phba
);
6371 /* Indicate device interrupt mode */
6372 phba
->sli4_hba
.intr_enable
= 1;
6374 /* Allow asynchronous mailbox command to go through */
6375 spin_lock_irq(&phba
->hbalock
);
6376 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6377 spin_unlock_irq(&phba
->hbalock
);
6379 /* Post receive buffers to the device */
6380 lpfc_sli4_rb_setup(phba
);
6382 /* Reset HBA FCF states after HBA reset */
6383 phba
->fcf
.fcf_flag
= 0;
6384 phba
->fcf
.current_rec
.flag
= 0;
6386 /* Start the ELS watchdog timer */
6387 mod_timer(&vport
->els_tmofunc
,
6388 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
6390 /* Start heart beat timer */
6391 mod_timer(&phba
->hb_tmofunc
,
6392 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
6393 phba
->hb_outstanding
= 0;
6394 phba
->last_completion_time
= jiffies
;
6396 /* Start error attention (ERATT) polling timer */
6397 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
6399 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6400 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6401 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6403 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6404 "2829 This device supports "
6405 "Advanced Error Reporting (AER)\n");
6406 spin_lock_irq(&phba
->hbalock
);
6407 phba
->hba_flag
|= HBA_AER_ENABLED
;
6408 spin_unlock_irq(&phba
->hbalock
);
6410 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6411 "2830 This device does not support "
6412 "Advanced Error Reporting (AER)\n");
6413 phba
->cfg_aer_support
= 0;
6418 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6420 * The FC Port needs to register FCFI (index 0)
6422 lpfc_reg_fcfi(phba
, mboxq
);
6423 mboxq
->vport
= phba
->pport
;
6424 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6425 if (rc
!= MBX_SUCCESS
)
6426 goto out_unset_queue
;
6428 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6429 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6431 /* Check if the port is configured to be disabled */
6432 lpfc_sli_read_link_ste(phba
);
6436 * The port is ready, set the host's link state to LINK_DOWN
6437 * in preparation for link interrupts.
6439 spin_lock_irq(&phba
->hbalock
);
6440 phba
->link_state
= LPFC_LINK_DOWN
;
6441 spin_unlock_irq(&phba
->hbalock
);
6442 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6443 (phba
->hba_flag
& LINK_DISABLED
)) {
6444 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6445 "3103 Adapter Link is disabled.\n");
6446 lpfc_down_link(phba
, mboxq
);
6447 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6448 if (rc
!= MBX_SUCCESS
) {
6449 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6450 "3104 Adapter failed to issue "
6451 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6452 goto out_unset_queue
;
6454 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6455 /* don't perform init_link on SLI4 FC port loopback test */
6456 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6457 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6459 goto out_unset_queue
;
6462 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6465 /* Unset all the queues set up in this routine when error out */
6466 lpfc_sli4_queue_unset(phba
);
6468 lpfc_sli4_queue_destroy(phba
);
6470 lpfc_stop_hba_timers(phba
);
6472 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6477 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6478 * @ptr: context object - pointer to hba structure.
6480 * This is the callback function for mailbox timer. The mailbox
6481 * timer is armed when a new mailbox command is issued and the timer
6482 * is deleted when the mailbox complete. The function is called by
6483 * the kernel timer code when a mailbox does not complete within
6484 * expected time. This function wakes up the worker thread to
6485 * process the mailbox timeout and returns. All the processing is
6486 * done by the worker thread function lpfc_mbox_timeout_handler.
6489 lpfc_mbox_timeout(unsigned long ptr
)
6491 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6492 unsigned long iflag
;
6493 uint32_t tmo_posted
;
6495 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6496 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6498 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6499 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6502 lpfc_worker_wake_up(phba
);
6508 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6509 * @phba: Pointer to HBA context object.
6511 * This function is called from worker thread when a mailbox command times out.
6512 * The caller is not required to hold any locks. This function will reset the
6513 * HBA and recover all the pending commands.
6516 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6518 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6519 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6520 struct lpfc_sli
*psli
= &phba
->sli
;
6521 struct lpfc_sli_ring
*pring
;
6523 /* Check the pmbox pointer first. There is a race condition
6524 * between the mbox timeout handler getting executed in the
6525 * worklist and the mailbox actually completing. When this
6526 * race condition occurs, the mbox_active will be NULL.
6528 spin_lock_irq(&phba
->hbalock
);
6529 if (pmbox
== NULL
) {
6530 lpfc_printf_log(phba
, KERN_WARNING
,
6532 "0353 Active Mailbox cleared - mailbox timeout "
6534 spin_unlock_irq(&phba
->hbalock
);
6538 /* Mbox cmd <mbxCommand> timeout */
6539 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6540 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6542 phba
->pport
->port_state
,
6544 phba
->sli
.mbox_active
);
6545 spin_unlock_irq(&phba
->hbalock
);
6547 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6548 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6549 * it to fail all outstanding SCSI IO.
6551 spin_lock_irq(&phba
->pport
->work_port_lock
);
6552 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6553 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6554 spin_lock_irq(&phba
->hbalock
);
6555 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6556 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6557 spin_unlock_irq(&phba
->hbalock
);
6559 pring
= &psli
->ring
[psli
->fcp_ring
];
6560 lpfc_sli_abort_iocb_ring(phba
, pring
);
6562 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6563 "0345 Resetting board due to mailbox timeout\n");
6565 /* Reset the HBA device */
6566 lpfc_reset_hba(phba
);
6570 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6571 * @phba: Pointer to HBA context object.
6572 * @pmbox: Pointer to mailbox object.
6573 * @flag: Flag indicating how the mailbox need to be processed.
6575 * This function is called by discovery code and HBA management code
6576 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6577 * function gets the hbalock to protect the data structures.
6578 * The mailbox command can be submitted in polling mode, in which case
6579 * this function will wait in a polling loop for the completion of the
6581 * If the mailbox is submitted in no_wait mode (not polling) the
6582 * function will submit the command and returns immediately without waiting
6583 * for the mailbox completion. The no_wait is supported only when HBA
6584 * is in SLI2/SLI3 mode - interrupts are enabled.
6585 * The SLI interface allows only one mailbox pending at a time. If the
6586 * mailbox is issued in polling mode and there is already a mailbox
6587 * pending, then the function will return an error. If the mailbox is issued
6588 * in NO_WAIT mode and there is a mailbox pending already, the function
6589 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6590 * The sli layer owns the mailbox object until the completion of mailbox
6591 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6592 * return codes the caller owns the mailbox command after the return of
6596 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6600 struct lpfc_sli
*psli
= &phba
->sli
;
6601 uint32_t status
, evtctr
;
6602 uint32_t ha_copy
, hc_copy
;
6604 unsigned long timeout
;
6605 unsigned long drvr_flag
= 0;
6606 uint32_t word0
, ldata
;
6607 void __iomem
*to_slim
;
6608 int processing_queue
= 0;
6610 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6612 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6613 /* processing mbox queue from intr_handler */
6614 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6615 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6618 processing_queue
= 1;
6619 pmbox
= lpfc_mbox_get(phba
);
6621 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6626 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6627 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6629 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6630 lpfc_printf_log(phba
, KERN_ERR
,
6631 LOG_MBOX
| LOG_VPORT
,
6632 "1806 Mbox x%x failed. No vport\n",
6633 pmbox
->u
.mb
.mbxCommand
);
6635 goto out_not_finished
;
6639 /* If the PCI channel is in offline state, do not post mbox. */
6640 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6641 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6642 goto out_not_finished
;
6645 /* If HBA has a deferred error attention, fail the iocb. */
6646 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6647 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6648 goto out_not_finished
;
6654 status
= MBX_SUCCESS
;
6656 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6657 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6659 /* Mbox command <mbxCommand> cannot issue */
6660 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6661 "(%d):0311 Mailbox command x%x cannot "
6662 "issue Data: x%x x%x\n",
6663 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6664 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6665 goto out_not_finished
;
6668 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6669 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6670 !(hc_copy
& HC_MBINT_ENA
)) {
6671 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6672 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6673 "(%d):2528 Mailbox command x%x cannot "
6674 "issue Data: x%x x%x\n",
6675 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6676 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6677 goto out_not_finished
;
6681 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6682 /* Polling for a mbox command when another one is already active
6683 * is not allowed in SLI. Also, the driver must have established
6684 * SLI2 mode to queue and process multiple mbox commands.
6687 if (flag
& MBX_POLL
) {
6688 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6690 /* Mbox command <mbxCommand> cannot issue */
6691 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6692 "(%d):2529 Mailbox command x%x "
6693 "cannot issue Data: x%x x%x\n",
6694 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6695 pmbox
->u
.mb
.mbxCommand
,
6696 psli
->sli_flag
, flag
);
6697 goto out_not_finished
;
6700 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6701 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6702 /* Mbox command <mbxCommand> cannot issue */
6703 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6704 "(%d):2530 Mailbox command x%x "
6705 "cannot issue Data: x%x x%x\n",
6706 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6707 pmbox
->u
.mb
.mbxCommand
,
6708 psli
->sli_flag
, flag
);
6709 goto out_not_finished
;
6712 /* Another mailbox command is still being processed, queue this
6713 * command to be processed later.
6715 lpfc_mbox_put(phba
, pmbox
);
6717 /* Mbox cmd issue - BUSY */
6718 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6719 "(%d):0308 Mbox cmd issue - BUSY Data: "
6720 "x%x x%x x%x x%x\n",
6721 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6722 mb
->mbxCommand
, phba
->pport
->port_state
,
6723 psli
->sli_flag
, flag
);
6725 psli
->slistat
.mbox_busy
++;
6726 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6729 lpfc_debugfs_disc_trc(pmbox
->vport
,
6730 LPFC_DISC_TRC_MBOX_VPORT
,
6731 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6732 (uint32_t)mb
->mbxCommand
,
6733 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6736 lpfc_debugfs_disc_trc(phba
->pport
,
6738 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6739 (uint32_t)mb
->mbxCommand
,
6740 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6746 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6748 /* If we are not polling, we MUST be in SLI2 mode */
6749 if (flag
!= MBX_POLL
) {
6750 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6751 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
6752 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6753 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6754 /* Mbox command <mbxCommand> cannot issue */
6755 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6756 "(%d):2531 Mailbox command x%x "
6757 "cannot issue Data: x%x x%x\n",
6758 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6759 pmbox
->u
.mb
.mbxCommand
,
6760 psli
->sli_flag
, flag
);
6761 goto out_not_finished
;
6763 /* timeout active mbox command */
6764 mod_timer(&psli
->mbox_tmo
, (jiffies
+
6765 (HZ
* lpfc_mbox_tmo_val(phba
, pmbox
))));
6768 /* Mailbox cmd <cmd> issue */
6769 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6770 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6772 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6773 mb
->mbxCommand
, phba
->pport
->port_state
,
6774 psli
->sli_flag
, flag
);
6776 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
6778 lpfc_debugfs_disc_trc(pmbox
->vport
,
6779 LPFC_DISC_TRC_MBOX_VPORT
,
6780 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6781 (uint32_t)mb
->mbxCommand
,
6782 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6785 lpfc_debugfs_disc_trc(phba
->pport
,
6787 "MBOX Send: cmd:x%x mb:x%x x%x",
6788 (uint32_t)mb
->mbxCommand
,
6789 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6793 psli
->slistat
.mbox_cmd
++;
6794 evtctr
= psli
->slistat
.mbox_event
;
6796 /* next set own bit for the adapter and copy over command word */
6797 mb
->mbxOwner
= OWN_CHIP
;
6799 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6800 /* Populate mbox extension offset word. */
6801 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6802 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6803 = (uint8_t *)phba
->mbox_ext
6804 - (uint8_t *)phba
->mbox
;
6807 /* Copy the mailbox extension data */
6808 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6809 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6810 (uint8_t *)phba
->mbox_ext
,
6811 pmbox
->in_ext_byte_len
);
6813 /* Copy command data to host SLIM area */
6814 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6816 /* Populate mbox extension offset word. */
6817 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6818 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6819 = MAILBOX_HBA_EXT_OFFSET
;
6821 /* Copy the mailbox extension data */
6822 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6823 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
6824 MAILBOX_HBA_EXT_OFFSET
,
6825 pmbox
->context2
, pmbox
->in_ext_byte_len
);
6828 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6829 /* copy command data into host mbox for cmpl */
6830 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6833 /* First copy mbox command data to HBA SLIM, skip past first
6835 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
6836 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
6837 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
6839 /* Next copy over first word, with mbxOwner set */
6840 ldata
= *((uint32_t *)mb
);
6841 to_slim
= phba
->MBslimaddr
;
6842 writel(ldata
, to_slim
);
6843 readl(to_slim
); /* flush */
6845 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6846 /* switch over to host mailbox */
6847 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
6855 /* Set up reference to mailbox command */
6856 psli
->mbox_active
= pmbox
;
6857 /* Interrupt board to do it */
6858 writel(CA_MBATT
, phba
->CAregaddr
);
6859 readl(phba
->CAregaddr
); /* flush */
6860 /* Don't wait for it to finish, just return */
6864 /* Set up null reference to mailbox command */
6865 psli
->mbox_active
= NULL
;
6866 /* Interrupt board to do it */
6867 writel(CA_MBATT
, phba
->CAregaddr
);
6868 readl(phba
->CAregaddr
); /* flush */
6870 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6871 /* First read mbox status word */
6872 word0
= *((uint32_t *)phba
->mbox
);
6873 word0
= le32_to_cpu(word0
);
6875 /* First read mbox status word */
6876 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
6877 spin_unlock_irqrestore(&phba
->hbalock
,
6879 goto out_not_finished
;
6883 /* Read the HBA Host Attention Register */
6884 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6885 spin_unlock_irqrestore(&phba
->hbalock
,
6887 goto out_not_finished
;
6889 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6892 /* Wait for command to complete */
6893 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
6894 (!(ha_copy
& HA_MBATT
) &&
6895 (phba
->link_state
> LPFC_WARM_START
))) {
6896 if (time_after(jiffies
, timeout
)) {
6897 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6898 spin_unlock_irqrestore(&phba
->hbalock
,
6900 goto out_not_finished
;
6903 /* Check if we took a mbox interrupt while we were
6905 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
6906 && (evtctr
!= psli
->slistat
.mbox_event
))
6910 spin_unlock_irqrestore(&phba
->hbalock
,
6913 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6916 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6917 /* First copy command data */
6918 word0
= *((uint32_t *)phba
->mbox
);
6919 word0
= le32_to_cpu(word0
);
6920 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6923 /* Check real SLIM for any errors */
6924 slimword0
= readl(phba
->MBslimaddr
);
6925 slimmb
= (MAILBOX_t
*) & slimword0
;
6926 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
6927 && slimmb
->mbxStatus
) {
6934 /* First copy command data */
6935 word0
= readl(phba
->MBslimaddr
);
6937 /* Read the HBA Host Attention Register */
6938 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6939 spin_unlock_irqrestore(&phba
->hbalock
,
6941 goto out_not_finished
;
6945 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6946 /* copy results back to user */
6947 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
6948 /* Copy the mailbox extension data */
6949 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6950 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
6952 pmbox
->out_ext_byte_len
);
6955 /* First copy command data */
6956 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
6958 /* Copy the mailbox extension data */
6959 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6960 lpfc_memcpy_from_slim(pmbox
->context2
,
6962 MAILBOX_HBA_EXT_OFFSET
,
6963 pmbox
->out_ext_byte_len
);
6967 writel(HA_MBATT
, phba
->HAregaddr
);
6968 readl(phba
->HAregaddr
); /* flush */
6970 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6971 status
= mb
->mbxStatus
;
6974 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6978 if (processing_queue
) {
6979 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6980 lpfc_mbox_cmpl_put(phba
, pmbox
);
6982 return MBX_NOT_FINISHED
;
6986 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6987 * @phba: Pointer to HBA context object.
6989 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6990 * the driver internal pending mailbox queue. It will then try to wait out the
6991 * possible outstanding mailbox command before return.
6994 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6995 * the outstanding mailbox command timed out.
6998 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7000 struct lpfc_sli
*psli
= &phba
->sli
;
7002 unsigned long timeout
= 0;
7004 /* Mark the asynchronous mailbox command posting as blocked */
7005 spin_lock_irq(&phba
->hbalock
);
7006 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7007 /* Determine how long we might wait for the active mailbox
7008 * command to be gracefully completed by firmware.
7010 if (phba
->sli
.mbox_active
)
7011 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7012 phba
->sli
.mbox_active
) *
7014 spin_unlock_irq(&phba
->hbalock
);
7016 /* Wait for the outstnading mailbox command to complete */
7017 while (phba
->sli
.mbox_active
) {
7018 /* Check active mailbox complete status every 2ms */
7020 if (time_after(jiffies
, timeout
)) {
7021 /* Timeout, marked the outstanding cmd not complete */
7027 /* Can not cleanly block async mailbox command, fails it */
7029 spin_lock_irq(&phba
->hbalock
);
7030 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7031 spin_unlock_irq(&phba
->hbalock
);
7037 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7038 * @phba: Pointer to HBA context object.
7040 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7041 * commands from the driver internal pending mailbox queue. It makes sure
7042 * that there is no outstanding mailbox command before resuming posting
7043 * asynchronous mailbox commands. If, for any reason, there is outstanding
7044 * mailbox command, it will try to wait it out before resuming asynchronous
7045 * mailbox command posting.
7048 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7050 struct lpfc_sli
*psli
= &phba
->sli
;
7052 spin_lock_irq(&phba
->hbalock
);
7053 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7054 /* Asynchronous mailbox posting is not blocked, do nothing */
7055 spin_unlock_irq(&phba
->hbalock
);
7059 /* Outstanding synchronous mailbox command is guaranteed to be done,
7060 * successful or timeout, after timing-out the outstanding mailbox
7061 * command shall always be removed, so just unblock posting async
7062 * mailbox command and resume
7064 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7065 spin_unlock_irq(&phba
->hbalock
);
7067 /* wake up worker thread to post asynchronlous mailbox command */
7068 lpfc_worker_wake_up(phba
);
7072 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7073 * @phba: Pointer to HBA context object.
7074 * @mboxq: Pointer to mailbox object.
7076 * The function posts a mailbox to the port. The mailbox is expected
7077 * to be comletely filled in and ready for the port to operate on it.
7078 * This routine executes a synchronous completion operation on the
7079 * mailbox by polling for its completion.
7081 * The caller must not be holding any locks when calling this routine.
7084 * MBX_SUCCESS - mailbox posted successfully
7085 * Any of the MBX error values.
7088 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7090 int rc
= MBX_SUCCESS
;
7091 unsigned long iflag
;
7093 uint32_t mcqe_status
;
7095 unsigned long timeout
;
7096 struct lpfc_sli
*psli
= &phba
->sli
;
7097 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7098 struct lpfc_bmbx_create
*mbox_rgn
;
7099 struct dma_address
*dma_address
;
7100 struct lpfc_register bmbx_reg
;
7103 * Only one mailbox can be active to the bootstrap mailbox region
7104 * at a time and there is no queueing provided.
7106 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7107 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7108 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7109 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7110 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7111 "cannot issue Data: x%x x%x\n",
7112 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7113 mboxq
->u
.mb
.mbxCommand
,
7114 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7115 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7116 psli
->sli_flag
, MBX_POLL
);
7117 return MBXERR_ERROR
;
7119 /* The server grabs the token and owns it until release */
7120 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7121 phba
->sli
.mbox_active
= mboxq
;
7122 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7125 * Initialize the bootstrap memory region to avoid stale data areas
7126 * in the mailbox post. Then copy the caller's mailbox contents to
7127 * the bmbx mailbox region.
7129 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7130 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7131 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7132 sizeof(struct lpfc_mqe
));
7134 /* Post the high mailbox dma address to the port and wait for ready. */
7135 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7136 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7138 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7141 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7142 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7146 if (time_after(jiffies
, timeout
)) {
7150 } while (!db_ready
);
7152 /* Post the low mailbox dma address to the port. */
7153 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7154 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7157 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7158 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7162 if (time_after(jiffies
, timeout
)) {
7166 } while (!db_ready
);
7169 * Read the CQ to ensure the mailbox has completed.
7170 * If so, update the mailbox status so that the upper layers
7171 * can complete the request normally.
7173 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7174 sizeof(struct lpfc_mqe
));
7175 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7176 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7177 sizeof(struct lpfc_mcqe
));
7178 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7180 * When the CQE status indicates a failure and the mailbox status
7181 * indicates success then copy the CQE status into the mailbox status
7182 * (and prefix it with x4000).
7184 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7185 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7186 bf_set(lpfc_mqe_status
, mb
,
7187 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7190 lpfc_sli4_swap_str(phba
, mboxq
);
7192 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7193 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7194 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7195 " x%x x%x CQ: x%x x%x x%x x%x\n",
7196 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7197 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7198 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7199 bf_get(lpfc_mqe_status
, mb
),
7200 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7201 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7202 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7203 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7204 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7205 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7206 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7207 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7208 mboxq
->mcqe
.trailer
);
7210 /* We are holding the token, no needed for lock when release */
7211 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7212 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7213 phba
->sli
.mbox_active
= NULL
;
7214 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7219 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7220 * @phba: Pointer to HBA context object.
7221 * @pmbox: Pointer to mailbox object.
7222 * @flag: Flag indicating how the mailbox need to be processed.
7224 * This function is called by discovery code and HBA management code to submit
7225 * a mailbox command to firmware with SLI-4 interface spec.
7227 * Return codes the caller owns the mailbox command after the return of the
7231 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7234 struct lpfc_sli
*psli
= &phba
->sli
;
7235 unsigned long iflags
;
7238 /* dump from issue mailbox command if setup */
7239 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7241 rc
= lpfc_mbox_dev_check(phba
);
7243 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7244 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7245 "cannot issue Data: x%x x%x\n",
7246 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7247 mboxq
->u
.mb
.mbxCommand
,
7248 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7249 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7250 psli
->sli_flag
, flag
);
7251 goto out_not_finished
;
7254 /* Detect polling mode and jump to a handler */
7255 if (!phba
->sli4_hba
.intr_enable
) {
7256 if (flag
== MBX_POLL
)
7257 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7260 if (rc
!= MBX_SUCCESS
)
7261 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7262 "(%d):2541 Mailbox command x%x "
7263 "(x%x/x%x) failure: "
7264 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7266 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7267 mboxq
->u
.mb
.mbxCommand
,
7268 lpfc_sli_config_mbox_subsys_get(phba
,
7270 lpfc_sli_config_mbox_opcode_get(phba
,
7272 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7273 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7274 bf_get(lpfc_mcqe_ext_status
,
7276 psli
->sli_flag
, flag
);
7278 } else if (flag
== MBX_POLL
) {
7279 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7280 "(%d):2542 Try to issue mailbox command "
7281 "x%x (x%x/x%x) synchronously ahead of async"
7282 "mailbox command queue: x%x x%x\n",
7283 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7284 mboxq
->u
.mb
.mbxCommand
,
7285 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7286 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7287 psli
->sli_flag
, flag
);
7288 /* Try to block the asynchronous mailbox posting */
7289 rc
= lpfc_sli4_async_mbox_block(phba
);
7291 /* Successfully blocked, now issue sync mbox cmd */
7292 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7293 if (rc
!= MBX_SUCCESS
)
7294 lpfc_printf_log(phba
, KERN_WARNING
,
7296 "(%d):2597 Sync Mailbox command "
7297 "x%x (x%x/x%x) failure: "
7298 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7300 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7301 mboxq
->u
.mb
.mbxCommand
,
7302 lpfc_sli_config_mbox_subsys_get(phba
,
7304 lpfc_sli_config_mbox_opcode_get(phba
,
7306 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7307 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7308 bf_get(lpfc_mcqe_ext_status
,
7310 psli
->sli_flag
, flag
);
7311 /* Unblock the async mailbox posting afterward */
7312 lpfc_sli4_async_mbox_unblock(phba
);
7317 /* Now, interrupt mode asynchrous mailbox command */
7318 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7320 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7321 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7322 "cannot issue Data: x%x x%x\n",
7323 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7324 mboxq
->u
.mb
.mbxCommand
,
7325 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7326 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7327 psli
->sli_flag
, flag
);
7328 goto out_not_finished
;
7331 /* Put the mailbox command to the driver internal FIFO */
7332 psli
->slistat
.mbox_busy
++;
7333 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7334 lpfc_mbox_put(phba
, mboxq
);
7335 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7336 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7337 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7338 "x%x (x%x/x%x) x%x x%x x%x\n",
7339 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7340 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7341 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7342 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7343 phba
->pport
->port_state
,
7344 psli
->sli_flag
, MBX_NOWAIT
);
7345 /* Wake up worker thread to transport mailbox command from head */
7346 lpfc_worker_wake_up(phba
);
7351 return MBX_NOT_FINISHED
;
7355 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7356 * @phba: Pointer to HBA context object.
7358 * This function is called by worker thread to send a mailbox command to
7359 * SLI4 HBA firmware.
7363 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7365 struct lpfc_sli
*psli
= &phba
->sli
;
7366 LPFC_MBOXQ_t
*mboxq
;
7367 int rc
= MBX_SUCCESS
;
7368 unsigned long iflags
;
7369 struct lpfc_mqe
*mqe
;
7372 /* Check interrupt mode before post async mailbox command */
7373 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7374 return MBX_NOT_FINISHED
;
7376 /* Check for mailbox command service token */
7377 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7378 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7379 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7380 return MBX_NOT_FINISHED
;
7382 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7383 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7384 return MBX_NOT_FINISHED
;
7386 if (unlikely(phba
->sli
.mbox_active
)) {
7387 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7388 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7389 "0384 There is pending active mailbox cmd\n");
7390 return MBX_NOT_FINISHED
;
7392 /* Take the mailbox command service token */
7393 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7395 /* Get the next mailbox command from head of queue */
7396 mboxq
= lpfc_mbox_get(phba
);
7398 /* If no more mailbox command waiting for post, we're done */
7400 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7401 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7404 phba
->sli
.mbox_active
= mboxq
;
7405 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7407 /* Check device readiness for posting mailbox command */
7408 rc
= lpfc_mbox_dev_check(phba
);
7410 /* Driver clean routine will clean up pending mailbox */
7411 goto out_not_finished
;
7413 /* Prepare the mbox command to be posted */
7414 mqe
= &mboxq
->u
.mqe
;
7415 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7417 /* Start timer for the mbox_tmo and log some mailbox post messages */
7418 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7419 (HZ
* lpfc_mbox_tmo_val(phba
, mboxq
))));
7421 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7422 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7424 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7425 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7426 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7427 phba
->pport
->port_state
, psli
->sli_flag
);
7429 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7431 lpfc_debugfs_disc_trc(mboxq
->vport
,
7432 LPFC_DISC_TRC_MBOX_VPORT
,
7433 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7434 mbx_cmnd
, mqe
->un
.mb_words
[0],
7435 mqe
->un
.mb_words
[1]);
7437 lpfc_debugfs_disc_trc(phba
->pport
,
7439 "MBOX Send: cmd:x%x mb:x%x x%x",
7440 mbx_cmnd
, mqe
->un
.mb_words
[0],
7441 mqe
->un
.mb_words
[1]);
7444 psli
->slistat
.mbox_cmd
++;
7446 /* Post the mailbox command to the port */
7447 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7448 if (rc
!= MBX_SUCCESS
) {
7449 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7450 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7451 "cannot issue Data: x%x x%x\n",
7452 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7453 mboxq
->u
.mb
.mbxCommand
,
7454 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7455 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7456 psli
->sli_flag
, MBX_NOWAIT
);
7457 goto out_not_finished
;
7463 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7464 if (phba
->sli
.mbox_active
) {
7465 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7466 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7467 /* Release the token */
7468 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7469 phba
->sli
.mbox_active
= NULL
;
7471 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7473 return MBX_NOT_FINISHED
;
7477 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7478 * @phba: Pointer to HBA context object.
7479 * @pmbox: Pointer to mailbox object.
7480 * @flag: Flag indicating how the mailbox need to be processed.
7482 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7483 * the API jump table function pointer from the lpfc_hba struct.
7485 * Return codes the caller owns the mailbox command after the return of the
7489 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7491 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7495 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7496 * @phba: The hba struct for which this call is being executed.
7497 * @dev_grp: The HBA PCI-Device group number.
7499 * This routine sets up the mbox interface API function jump table in @phba
7501 * Returns: 0 - success, -ENODEV - failure.
7504 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7508 case LPFC_PCI_DEV_LP
:
7509 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7510 phba
->lpfc_sli_handle_slow_ring_event
=
7511 lpfc_sli_handle_slow_ring_event_s3
;
7512 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7513 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7514 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7516 case LPFC_PCI_DEV_OC
:
7517 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7518 phba
->lpfc_sli_handle_slow_ring_event
=
7519 lpfc_sli_handle_slow_ring_event_s4
;
7520 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7521 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7522 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7525 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7526 "1420 Invalid HBA PCI-device group: 0x%x\n",
7535 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7536 * @phba: Pointer to HBA context object.
7537 * @pring: Pointer to driver SLI ring object.
7538 * @piocb: Pointer to address of newly added command iocb.
7540 * This function is called with hbalock held to add a command
7541 * iocb to the txq when SLI layer cannot submit the command iocb
7545 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7546 struct lpfc_iocbq
*piocb
)
7548 /* Insert the caller's iocb in the txq tail for later processing. */
7549 list_add_tail(&piocb
->list
, &pring
->txq
);
7554 * lpfc_sli_next_iocb - Get the next iocb in the txq
7555 * @phba: Pointer to HBA context object.
7556 * @pring: Pointer to driver SLI ring object.
7557 * @piocb: Pointer to address of newly added command iocb.
7559 * This function is called with hbalock held before a new
7560 * iocb is submitted to the firmware. This function checks
7561 * txq to flush the iocbs in txq to Firmware before
7562 * submitting new iocbs to the Firmware.
7563 * If there are iocbs in the txq which need to be submitted
7564 * to firmware, lpfc_sli_next_iocb returns the first element
7565 * of the txq after dequeuing it from txq.
7566 * If there is no iocb in the txq then the function will return
7567 * *piocb and *piocb is set to NULL. Caller needs to check
7568 * *piocb to find if there are more commands in the txq.
7570 static struct lpfc_iocbq
*
7571 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7572 struct lpfc_iocbq
**piocb
)
7574 struct lpfc_iocbq
* nextiocb
;
7576 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7586 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7587 * @phba: Pointer to HBA context object.
7588 * @ring_number: SLI ring number to issue iocb on.
7589 * @piocb: Pointer to command iocb.
7590 * @flag: Flag indicating if this command can be put into txq.
7592 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7593 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7594 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7595 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7596 * this function allows only iocbs for posting buffers. This function finds
7597 * next available slot in the command ring and posts the command to the
7598 * available slot and writes the port attention register to request HBA start
7599 * processing new iocb. If there is no slot available in the ring and
7600 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7601 * the function returns IOCB_BUSY.
7603 * This function is called with hbalock held. The function will return success
7604 * after it successfully submit the iocb to firmware or after adding to the
7608 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7609 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7611 struct lpfc_iocbq
*nextiocb
;
7613 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7615 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7616 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7617 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7618 lpfc_printf_log(phba
, KERN_ERR
,
7619 LOG_SLI
| LOG_VPORT
,
7620 "1807 IOCB x%x failed. No vport\n",
7621 piocb
->iocb
.ulpCommand
);
7627 /* If the PCI channel is in offline state, do not post iocbs. */
7628 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7631 /* If HBA has a deferred error attention, fail the iocb. */
7632 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7636 * We should never get an IOCB if we are in a < LINK_DOWN state
7638 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7642 * Check to see if we are blocking IOCB processing because of a
7643 * outstanding event.
7645 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7648 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7650 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7651 * can be issued if the link is not up.
7653 switch (piocb
->iocb
.ulpCommand
) {
7654 case CMD_GEN_REQUEST64_CR
:
7655 case CMD_GEN_REQUEST64_CX
:
7656 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7657 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7658 FC_RCTL_DD_UNSOL_CMD
) ||
7659 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7660 MENLO_TRANSPORT_TYPE
))
7664 case CMD_QUE_RING_BUF_CN
:
7665 case CMD_QUE_RING_BUF64_CN
:
7667 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7668 * completion, iocb_cmpl MUST be 0.
7670 if (piocb
->iocb_cmpl
)
7671 piocb
->iocb_cmpl
= NULL
;
7673 case CMD_CREATE_XRI_CR
:
7674 case CMD_CLOSE_XRI_CN
:
7675 case CMD_CLOSE_XRI_CX
:
7682 * For FCP commands, we must be in a state where we can process link
7685 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7686 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7690 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7691 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7692 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7695 lpfc_sli_update_ring(phba
, pring
);
7697 lpfc_sli_update_full_ring(phba
, pring
);
7700 return IOCB_SUCCESS
;
7705 pring
->stats
.iocb_cmd_delay
++;
7709 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7710 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7711 return IOCB_SUCCESS
;
7718 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7719 * @phba: Pointer to HBA context object.
7720 * @piocb: Pointer to command iocb.
7721 * @sglq: Pointer to the scatter gather queue object.
7723 * This routine converts the bpl or bde that is in the IOCB
7724 * to a sgl list for the sli4 hardware. The physical address
7725 * of the bpl/bde is converted back to a virtual address.
7726 * If the IOCB contains a BPL then the list of BDE's is
7727 * converted to sli4_sge's. If the IOCB contains a single
7728 * BDE then it is converted to a single sli_sge.
7729 * The IOCB is still in cpu endianess so the contents of
7730 * the bpl can be used without byte swapping.
7732 * Returns valid XRI = Success, NO_XRI = Failure.
7735 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7736 struct lpfc_sglq
*sglq
)
7738 uint16_t xritag
= NO_XRI
;
7739 struct ulp_bde64
*bpl
= NULL
;
7740 struct ulp_bde64 bde
;
7741 struct sli4_sge
*sgl
= NULL
;
7742 struct lpfc_dmabuf
*dmabuf
;
7746 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7747 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7749 if (!piocbq
|| !sglq
)
7752 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7753 icmd
= &piocbq
->iocb
;
7754 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
7755 return sglq
->sli4_xritag
;
7756 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7757 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7758 sizeof(struct ulp_bde64
);
7759 /* The addrHigh and addrLow fields within the IOCB
7760 * have not been byteswapped yet so there is no
7761 * need to swap them back.
7763 if (piocbq
->context3
)
7764 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7768 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7772 for (i
= 0; i
< numBdes
; i
++) {
7773 /* Should already be byte swapped. */
7774 sgl
->addr_hi
= bpl
->addrHigh
;
7775 sgl
->addr_lo
= bpl
->addrLow
;
7777 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7778 if ((i
+1) == numBdes
)
7779 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7781 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7782 /* swap the size field back to the cpu so we
7783 * can assign it to the sgl.
7785 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7786 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7787 /* The offsets in the sgl need to be accumulated
7788 * separately for the request and reply lists.
7789 * The request is always first, the reply follows.
7791 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7792 /* add up the reply sg entries */
7793 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7795 /* first inbound? reset the offset */
7798 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7799 bf_set(lpfc_sli4_sge_type
, sgl
,
7800 LPFC_SGE_TYPE_DATA
);
7801 offset
+= bde
.tus
.f
.bdeSize
;
7803 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7807 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
7808 /* The addrHigh and addrLow fields of the BDE have not
7809 * been byteswapped yet so they need to be swapped
7810 * before putting them in the sgl.
7813 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
7815 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
7816 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7817 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7818 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7820 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
7822 return sglq
->sli4_xritag
;
7826 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7827 * @phba: Pointer to HBA context object.
7829 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7830 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7833 * Return: index into SLI4 fast-path FCP queue index.
7835 static inline uint32_t
7836 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
7840 if (phba
->cfg_fcp_io_sched
== LPFC_FCP_SCHED_BY_CPU
)
7841 i
= smp_processor_id();
7843 i
= atomic_add_return(1, &phba
->fcp_qidx
);
7845 i
= (i
% phba
->cfg_fcp_io_channel
);
7850 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7851 * @phba: Pointer to HBA context object.
7852 * @piocb: Pointer to command iocb.
7853 * @wqe: Pointer to the work queue entry.
7855 * This routine converts the iocb command to its Work Queue Entry
7856 * equivalent. The wqe pointer should not have any fields set when
7857 * this routine is called because it will memcpy over them.
7858 * This routine does not set the CQ_ID or the WQEC bits in the
7861 * Returns: 0 = Success, IOCB_ERROR = Failure.
7864 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
7865 union lpfc_wqe
*wqe
)
7867 uint32_t xmit_len
= 0, total_len
= 0;
7871 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
7874 uint16_t abrt_iotag
;
7875 struct lpfc_iocbq
*abrtiocbq
;
7876 struct ulp_bde64
*bpl
= NULL
;
7877 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
7879 struct ulp_bde64 bde
;
7880 struct lpfc_nodelist
*ndlp
;
7884 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
7885 /* The fcp commands will set command type */
7886 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7887 command_type
= FCP_COMMAND
;
7888 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
7889 command_type
= ELS_COMMAND_FIP
;
7891 command_type
= ELS_COMMAND_NON_FIP
;
7893 /* Some of the fields are in the right position already */
7894 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
7895 abort_tag
= (uint32_t) iocbq
->iotag
;
7896 xritag
= iocbq
->sli4_xritag
;
7897 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
7898 /* words0-2 bpl convert bde */
7899 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7900 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7901 sizeof(struct ulp_bde64
);
7902 bpl
= (struct ulp_bde64
*)
7903 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
7907 /* Should already be byte swapped. */
7908 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
7909 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
7910 /* swap the size field back to the cpu so we
7911 * can assign it to the sgl.
7913 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7914 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
7916 for (i
= 0; i
< numBdes
; i
++) {
7917 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7918 total_len
+= bde
.tus
.f
.bdeSize
;
7921 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
7923 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
7924 cmnd
= iocbq
->iocb
.ulpCommand
;
7926 switch (iocbq
->iocb
.ulpCommand
) {
7927 case CMD_ELS_REQUEST64_CR
:
7928 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
7929 ndlp
= iocbq
->context_un
.ndlp
;
7931 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7932 if (!iocbq
->iocb
.ulpLe
) {
7933 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7934 "2007 Only Limited Edition cmd Format"
7935 " supported 0x%x\n",
7936 iocbq
->iocb
.ulpCommand
);
7940 wqe
->els_req
.payload_len
= xmit_len
;
7941 /* Els_reguest64 has a TMO */
7942 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
7943 iocbq
->iocb
.ulpTimeout
);
7944 /* Need a VF for word 4 set the vf bit*/
7945 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
7946 /* And a VFID for word 12 */
7947 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
7948 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7949 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7950 iocbq
->iocb
.ulpContext
);
7951 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
7952 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
7953 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7954 if (command_type
== ELS_COMMAND_FIP
)
7955 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
7956 >> LPFC_FIP_ELS_ID_SHIFT
);
7957 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7958 iocbq
->context2
)->virt
);
7959 if_type
= bf_get(lpfc_sli_intf_if_type
,
7960 &phba
->sli4_hba
.sli_intf
);
7961 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7962 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
7963 *pcmd
== ELS_CMD_SCR
||
7964 *pcmd
== ELS_CMD_FDISC
||
7965 *pcmd
== ELS_CMD_LOGO
||
7966 *pcmd
== ELS_CMD_PLOGI
)) {
7967 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7968 bf_set(els_req64_sid
, &wqe
->els_req
,
7969 iocbq
->vport
->fc_myDID
);
7970 if ((*pcmd
== ELS_CMD_FLOGI
) &&
7971 !(phba
->fc_topology
==
7972 LPFC_TOPOLOGY_LOOP
))
7973 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
7974 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7975 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7976 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
7977 } else if (pcmd
&& iocbq
->context1
) {
7978 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
7979 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7980 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7983 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
7984 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7985 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
7986 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
7987 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7988 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
7989 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7990 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
7992 case CMD_XMIT_SEQUENCE64_CX
:
7993 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
7994 iocbq
->iocb
.un
.ulpWord
[3]);
7995 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
7996 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7997 /* The entire sequence is transmitted for this IOCB */
7998 xmit_len
= total_len
;
7999 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8000 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8001 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8002 case CMD_XMIT_SEQUENCE64_CR
:
8003 /* word3 iocb=io_tag32 wqe=reserved */
8004 wqe
->xmit_sequence
.rsvd3
= 0;
8005 /* word4 relative_offset memcpy */
8006 /* word5 r_ctl/df_ctl memcpy */
8007 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8008 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8009 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8010 LPFC_WQE_IOD_WRITE
);
8011 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8012 LPFC_WQE_LENLOC_WORD12
);
8013 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8014 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8015 command_type
= OTHER_COMMAND
;
8017 case CMD_XMIT_BCAST64_CN
:
8018 /* word3 iocb=iotag32 wqe=seq_payload_len */
8019 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8020 /* word4 iocb=rsvd wqe=rsvd */
8021 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8022 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8023 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8024 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8025 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8026 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8027 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8028 LPFC_WQE_LENLOC_WORD3
);
8029 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8031 case CMD_FCP_IWRITE64_CR
:
8032 command_type
= FCP_COMMAND_DATA_OUT
;
8033 /* word3 iocb=iotag wqe=payload_offset_len */
8034 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8035 wqe
->fcp_iwrite
.payload_offset_len
=
8036 xmit_len
+ sizeof(struct fcp_rsp
);
8037 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8038 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8039 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8040 iocbq
->iocb
.ulpFCP2Rcvy
);
8041 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8042 /* Always open the exchange */
8043 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8044 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8045 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8046 LPFC_WQE_LENLOC_WORD4
);
8047 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8048 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8049 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
8050 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
8051 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
8053 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8055 case CMD_FCP_IREAD64_CR
:
8056 /* word3 iocb=iotag wqe=payload_offset_len */
8057 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8058 wqe
->fcp_iread
.payload_offset_len
=
8059 xmit_len
+ sizeof(struct fcp_rsp
);
8060 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8061 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8062 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8063 iocbq
->iocb
.ulpFCP2Rcvy
);
8064 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8065 /* Always open the exchange */
8066 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
8067 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8068 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8069 LPFC_WQE_LENLOC_WORD4
);
8070 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
8071 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8072 if (iocbq
->iocb_flag
& LPFC_IO_DIF
) {
8073 iocbq
->iocb_flag
&= ~LPFC_IO_DIF
;
8074 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, 1);
8076 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8078 case CMD_FCP_ICMND64_CR
:
8079 /* word3 iocb=IO_TAG wqe=reserved */
8080 wqe
->fcp_icmd
.rsrvd3
= 0;
8081 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8082 /* Always open the exchange */
8083 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
8084 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8085 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8086 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8087 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8088 LPFC_WQE_LENLOC_NONE
);
8089 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
8091 case CMD_GEN_REQUEST64_CR
:
8092 /* For this command calculate the xmit length of the
8096 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8097 sizeof(struct ulp_bde64
);
8098 for (i
= 0; i
< numBdes
; i
++) {
8099 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8100 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8102 xmit_len
+= bde
.tus
.f
.bdeSize
;
8104 /* word3 iocb=IO_TAG wqe=request_payload_len */
8105 wqe
->gen_req
.request_payload_len
= xmit_len
;
8106 /* word4 iocb=parameter wqe=relative_offset memcpy */
8107 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8108 /* word6 context tag copied in memcpy */
8109 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8110 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8111 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8112 "2015 Invalid CT %x command 0x%x\n",
8113 ct
, iocbq
->iocb
.ulpCommand
);
8116 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8117 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8118 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8119 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8120 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8121 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8122 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8123 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8124 command_type
= OTHER_COMMAND
;
8126 case CMD_XMIT_ELS_RSP64_CX
:
8127 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8128 /* words0-2 BDE memcpy */
8129 /* word3 iocb=iotag32 wqe=response_payload_len */
8130 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8132 wqe
->xmit_els_rsp
.word4
= 0;
8133 /* word5 iocb=rsvd wge=did */
8134 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8135 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
8137 if_type
= bf_get(lpfc_sli_intf_if_type
,
8138 &phba
->sli4_hba
.sli_intf
);
8139 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8140 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
8141 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8142 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8143 iocbq
->vport
->fc_myDID
);
8144 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
8146 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
8150 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8151 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8152 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8153 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8154 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8155 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8156 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8157 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8158 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8159 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8160 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8161 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8162 LPFC_WQE_LENLOC_WORD3
);
8163 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8164 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8165 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8166 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8167 iocbq
->context2
)->virt
);
8168 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8169 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8170 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8171 iocbq
->vport
->fc_myDID
);
8172 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8173 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8174 phba
->vpi_ids
[phba
->pport
->vpi
]);
8176 command_type
= OTHER_COMMAND
;
8178 case CMD_CLOSE_XRI_CN
:
8179 case CMD_ABORT_XRI_CN
:
8180 case CMD_ABORT_XRI_CX
:
8181 /* words 0-2 memcpy should be 0 rserved */
8182 /* port will send abts */
8183 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8184 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8185 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8186 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8190 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8192 * The link is down, or the command was ELS_FIP
8193 * so the fw does not need to send abts
8196 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8198 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8199 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8200 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8201 wqe
->abort_cmd
.rsrvd5
= 0;
8202 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8203 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8204 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8206 * The abort handler will send us CMD_ABORT_XRI_CN or
8207 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8209 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8210 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8211 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8212 LPFC_WQE_LENLOC_NONE
);
8213 cmnd
= CMD_ABORT_XRI_CX
;
8214 command_type
= OTHER_COMMAND
;
8217 case CMD_XMIT_BLS_RSP64_CX
:
8218 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8219 /* As BLS ABTS RSP WQE is very different from other WQEs,
8220 * we re-construct this WQE here based on information in
8221 * iocbq from scratch.
8223 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8224 /* OX_ID is invariable to who sent ABTS to CT exchange */
8225 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8226 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8227 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8228 LPFC_ABTS_UNSOL_INT
) {
8229 /* ABTS sent by initiator to CT exchange, the
8230 * RX_ID field will be filled with the newly
8231 * allocated responder XRI.
8233 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8234 iocbq
->sli4_xritag
);
8236 /* ABTS sent by responder to CT exchange, the
8237 * RX_ID field will be filled with the responder
8240 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8241 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8243 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8244 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8247 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8249 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8250 iocbq
->iocb
.ulpContext
);
8251 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8252 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8253 phba
->vpi_ids
[phba
->pport
->vpi
]);
8254 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8255 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8256 LPFC_WQE_LENLOC_NONE
);
8257 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8258 command_type
= OTHER_COMMAND
;
8259 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8260 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8261 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8262 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8263 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8264 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8265 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8269 case CMD_XRI_ABORTED_CX
:
8270 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8271 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8272 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8273 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8274 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8276 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8277 "2014 Invalid command 0x%x\n",
8278 iocbq
->iocb
.ulpCommand
);
8283 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8284 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8285 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8286 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8287 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8288 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8289 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8294 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8295 * @phba: Pointer to HBA context object.
8296 * @ring_number: SLI ring number to issue iocb on.
8297 * @piocb: Pointer to command iocb.
8298 * @flag: Flag indicating if this command can be put into txq.
8300 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8301 * an iocb command to an HBA with SLI-4 interface spec.
8303 * This function is called with hbalock held. The function will return success
8304 * after it successfully submit the iocb to firmware or after adding to the
8308 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8309 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8311 struct lpfc_sglq
*sglq
;
8313 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8315 if (piocb
->sli4_xritag
== NO_XRI
) {
8316 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8317 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8320 if (pring
->txq_cnt
) {
8321 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8322 __lpfc_sli_ringtx_put(phba
,
8324 return IOCB_SUCCESS
;
8329 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8331 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8332 __lpfc_sli_ringtx_put(phba
,
8335 return IOCB_SUCCESS
;
8341 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8342 /* These IO's already have an XRI and a mapped sgl. */
8346 * This is a continuation of a commandi,(CX) so this
8347 * sglq is on the active list
8349 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
8355 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8356 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8357 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8361 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8364 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8365 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8366 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8370 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8373 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8379 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8381 * This routine wraps the actual lockless version for issusing IOCB function
8382 * pointer from the lpfc_hba struct.
8385 * IOCB_ERROR - Error
8386 * IOCB_SUCCESS - Success
8390 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8391 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8393 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8397 * lpfc_sli_api_table_setup - Set up sli api function jump table
8398 * @phba: The hba struct for which this call is being executed.
8399 * @dev_grp: The HBA PCI-Device group number.
8401 * This routine sets up the SLI interface API function jump table in @phba
8403 * Returns: 0 - success, -ENODEV - failure.
8406 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8410 case LPFC_PCI_DEV_LP
:
8411 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8412 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8414 case LPFC_PCI_DEV_OC
:
8415 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8416 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8419 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8420 "1419 Invalid HBA PCI-device group: 0x%x\n",
8425 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8430 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8431 * @phba: Pointer to HBA context object.
8432 * @pring: Pointer to driver SLI ring object.
8433 * @piocb: Pointer to command iocb.
8434 * @flag: Flag indicating if this command can be put into txq.
8436 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8437 * function. This function gets the hbalock and calls
8438 * __lpfc_sli_issue_iocb function and will return the error returned
8439 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8440 * functions which do not hold hbalock.
8443 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8444 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8446 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
8447 struct lpfc_sli_ring
*pring
;
8448 struct lpfc_queue
*fpeq
;
8449 struct lpfc_eqe
*eqe
;
8450 unsigned long iflags
;
8453 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8454 if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8455 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8457 idx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8458 piocb
->fcp_wqidx
= idx
;
8459 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+ idx
;
8461 pring
= &phba
->sli
.ring
[ring_number
];
8462 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8463 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8465 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8467 if (lpfc_fcp_look_ahead
) {
8468 fcp_eq_hdl
= &phba
->sli4_hba
.fcp_eq_hdl
[idx
];
8470 if (atomic_dec_and_test(&fcp_eq_hdl
->
8473 /* Get associated EQ with this index */
8474 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
8476 /* Turn off interrupts from this EQ */
8477 lpfc_sli4_eq_clr_intr(fpeq
);
8480 * Process all the events on FCP EQ
8482 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
8483 lpfc_sli4_hba_handle_eqe(phba
,
8485 fpeq
->EQ_processed
++;
8488 /* Always clear and re-arm the EQ */
8489 lpfc_sli4_eq_release(fpeq
,
8492 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
8495 pring
= &phba
->sli
.ring
[ring_number
];
8496 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8497 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8499 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8503 /* For now, SLI2/3 will still use hbalock */
8504 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8505 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8506 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8512 * lpfc_extra_ring_setup - Extra ring setup function
8513 * @phba: Pointer to HBA context object.
8515 * This function is called while driver attaches with the
8516 * HBA to setup the extra ring. The extra ring is used
8517 * only when driver needs to support target mode functionality
8518 * or IP over FC functionalities.
8520 * This function is called with no lock held.
8523 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8525 struct lpfc_sli
*psli
;
8526 struct lpfc_sli_ring
*pring
;
8530 /* Adjust cmd/rsp ring iocb entries more evenly */
8532 /* Take some away from the FCP ring */
8533 pring
= &psli
->ring
[psli
->fcp_ring
];
8534 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8535 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8536 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8537 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8539 /* and give them to the extra ring */
8540 pring
= &psli
->ring
[psli
->extra_ring
];
8542 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8543 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8544 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8545 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8547 /* Setup default profile for this ring */
8548 pring
->iotag_max
= 4096;
8549 pring
->num_mask
= 1;
8550 pring
->prt
[0].profile
= 0; /* Mask 0 */
8551 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8552 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8553 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8557 /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
8558 * @vport: pointer to virtual port object.
8559 * @ndlp: nodelist pointer for the impacted rport.
8561 * The driver calls this routine in response to a XRI ABORT CQE
8562 * event from the port. In this event, the driver is required to
8563 * recover its login to the rport even though its login may be valid
8564 * from the driver's perspective. The failed ABTS notice from the
8565 * port indicates the rport is not responding.
8568 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8569 struct lpfc_nodelist
*ndlp
)
8571 struct Scsi_Host
*shost
;
8572 struct lpfc_hba
*phba
;
8573 unsigned long flags
= 0;
8575 shost
= lpfc_shost_from_vport(vport
);
8577 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8578 lpfc_printf_log(phba
, KERN_INFO
,
8579 LOG_SLI
, "3093 No rport recovery needed. "
8580 "rport in state 0x%x\n",
8584 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8585 "3094 Start rport recovery on shost id 0x%x "
8586 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8588 shost
->host_no
, ndlp
->nlp_DID
,
8589 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8592 * The rport is not responding. Don't attempt ADISC recovery.
8593 * Remove the FCP-2 flag to force a PLOGI.
8595 spin_lock_irqsave(shost
->host_lock
, flags
);
8596 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8597 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8598 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
8599 NLP_EVT_DEVICE_RECOVERY
);
8600 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
8601 spin_lock_irqsave(shost
->host_lock
, flags
);
8602 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
8603 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8604 lpfc_disc_start(vport
);
8607 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8608 * @phba: Pointer to HBA context object.
8609 * @iocbq: Pointer to iocb object.
8611 * The async_event handler calls this routine when it receives
8612 * an ASYNC_STATUS_CN event from the port. The port generates
8613 * this event when an Abort Sequence request to an rport fails
8614 * twice in succession. The abort could be originated by the
8615 * driver or by the port. The ABTS could have been for an ELS
8616 * or FCP IO. The port only generates this event when an ABTS
8617 * fails to complete after one retry.
8620 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8621 struct lpfc_iocbq
*iocbq
)
8623 struct lpfc_nodelist
*ndlp
= NULL
;
8624 uint16_t rpi
= 0, vpi
= 0;
8625 struct lpfc_vport
*vport
= NULL
;
8627 /* The rpi in the ulpContext is vport-sensitive. */
8628 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8629 rpi
= iocbq
->iocb
.ulpContext
;
8631 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8632 "3092 Port generated ABTS async event "
8633 "on vpi %d rpi %d status 0x%x\n",
8634 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8636 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8639 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8640 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8643 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8644 lpfc_sli_abts_recover_port(vport
, ndlp
);
8648 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8649 "3095 Event Context not found, no "
8650 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8651 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8655 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8656 * @phba: pointer to HBA context object.
8657 * @ndlp: nodelist pointer for the impacted rport.
8658 * @axri: pointer to the wcqe containing the failed exchange.
8660 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8661 * port. The port generates this event when an abort exchange request to an
8662 * rport fails twice in succession with no reply. The abort could be originated
8663 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8666 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8667 struct lpfc_nodelist
*ndlp
,
8668 struct sli4_wcqe_xri_aborted
*axri
)
8670 struct lpfc_vport
*vport
;
8671 uint32_t ext_status
= 0;
8673 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
8674 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8675 "3115 Node Context not found, driver "
8676 "ignoring abts err event\n");
8680 vport
= ndlp
->vport
;
8681 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8682 "3116 Port generated FCP XRI ABORT event on "
8683 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8684 ndlp
->vport
->vpi
, ndlp
->nlp_rpi
,
8685 bf_get(lpfc_wcqe_xa_xri
, axri
),
8686 bf_get(lpfc_wcqe_xa_status
, axri
),
8690 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8691 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8692 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8694 ext_status
= axri
->parameter
& WCQE_PARAM_MASK
;
8695 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
8696 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
8697 lpfc_sli_abts_recover_port(vport
, ndlp
);
8701 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8702 * @phba: Pointer to HBA context object.
8703 * @pring: Pointer to driver SLI ring object.
8704 * @iocbq: Pointer to iocb object.
8706 * This function is called by the slow ring event handler
8707 * function when there is an ASYNC event iocb in the ring.
8708 * This function is called with no lock held.
8709 * Currently this function handles only temperature related
8710 * ASYNC events. The function decodes the temperature sensor
8711 * event message and posts events for the management applications.
8714 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8715 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8719 struct temp_event temp_event_data
;
8720 struct Scsi_Host
*shost
;
8723 icmd
= &iocbq
->iocb
;
8724 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8727 case ASYNC_TEMP_WARN
:
8728 case ASYNC_TEMP_SAFE
:
8729 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8730 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8731 if (evt_code
== ASYNC_TEMP_WARN
) {
8732 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8733 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8734 "0347 Adapter is very hot, please take "
8735 "corrective action. temperature : %d Celsius\n",
8736 (uint32_t) icmd
->ulpContext
);
8738 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8739 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8740 "0340 Adapter temperature is OK now. "
8741 "temperature : %d Celsius\n",
8742 (uint32_t) icmd
->ulpContext
);
8745 /* Send temperature change event to applications */
8746 shost
= lpfc_shost_from_vport(phba
->pport
);
8747 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8748 sizeof(temp_event_data
), (char *) &temp_event_data
,
8751 case ASYNC_STATUS_CN
:
8752 lpfc_sli_abts_err_handler(phba
, iocbq
);
8755 iocb_w
= (uint32_t *) icmd
;
8756 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8757 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8759 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8760 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8761 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8762 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8763 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8764 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8765 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8766 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8767 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8775 * lpfc_sli_setup - SLI ring setup function
8776 * @phba: Pointer to HBA context object.
8778 * lpfc_sli_setup sets up rings of the SLI interface with
8779 * number of iocbs per ring and iotags. This function is
8780 * called while driver attach to the HBA and before the
8781 * interrupts are enabled. So there is no need for locking.
8783 * This function always returns 0.
8786 lpfc_sli_setup(struct lpfc_hba
*phba
)
8788 int i
, totiocbsize
= 0;
8789 struct lpfc_sli
*psli
= &phba
->sli
;
8790 struct lpfc_sli_ring
*pring
;
8792 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
8793 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8794 psli
->num_rings
+= phba
->cfg_fcp_io_channel
;
8796 psli
->fcp_ring
= LPFC_FCP_RING
;
8797 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8798 psli
->extra_ring
= LPFC_EXTRA_RING
;
8800 psli
->iocbq_lookup
= NULL
;
8801 psli
->iocbq_lookup_len
= 0;
8802 psli
->last_iotag
= 0;
8804 for (i
= 0; i
< psli
->num_rings
; i
++) {
8805 pring
= &psli
->ring
[i
];
8807 case LPFC_FCP_RING
: /* ring 0 - FCP */
8808 /* numCiocb and numRiocb are used in config_port */
8809 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8810 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8811 pring
->sli
.sli3
.numCiocb
+=
8812 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8813 pring
->sli
.sli3
.numRiocb
+=
8814 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8815 pring
->sli
.sli3
.numCiocb
+=
8816 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8817 pring
->sli
.sli3
.numRiocb
+=
8818 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8819 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8820 SLI3_IOCB_CMD_SIZE
:
8822 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8823 SLI3_IOCB_RSP_SIZE
:
8825 pring
->iotag_ctr
= 0;
8827 (phba
->cfg_hba_queue_depth
* 2);
8828 pring
->fast_iotag
= pring
->iotag_max
;
8829 pring
->num_mask
= 0;
8831 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
8832 /* numCiocb and numRiocb are used in config_port */
8833 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
8834 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
8835 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8836 SLI3_IOCB_CMD_SIZE
:
8838 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8839 SLI3_IOCB_RSP_SIZE
:
8841 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
8842 pring
->num_mask
= 0;
8844 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
8845 /* numCiocb and numRiocb are used in config_port */
8846 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
8847 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
8848 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8849 SLI3_IOCB_CMD_SIZE
:
8851 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8852 SLI3_IOCB_RSP_SIZE
:
8854 pring
->fast_iotag
= 0;
8855 pring
->iotag_ctr
= 0;
8856 pring
->iotag_max
= 4096;
8857 pring
->lpfc_sli_rcv_async_status
=
8858 lpfc_sli_async_event_handler
;
8859 pring
->num_mask
= LPFC_MAX_RING_MASK
;
8860 pring
->prt
[0].profile
= 0; /* Mask 0 */
8861 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
8862 pring
->prt
[0].type
= FC_TYPE_ELS
;
8863 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
8864 lpfc_els_unsol_event
;
8865 pring
->prt
[1].profile
= 0; /* Mask 1 */
8866 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
8867 pring
->prt
[1].type
= FC_TYPE_ELS
;
8868 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
8869 lpfc_els_unsol_event
;
8870 pring
->prt
[2].profile
= 0; /* Mask 2 */
8871 /* NameServer Inquiry */
8872 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
8874 pring
->prt
[2].type
= FC_TYPE_CT
;
8875 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
8876 lpfc_ct_unsol_event
;
8877 pring
->prt
[3].profile
= 0; /* Mask 3 */
8878 /* NameServer response */
8879 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
8881 pring
->prt
[3].type
= FC_TYPE_CT
;
8882 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
8883 lpfc_ct_unsol_event
;
8884 /* abort unsolicited sequence */
8885 pring
->prt
[4].profile
= 0; /* Mask 4 */
8886 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
8887 pring
->prt
[4].type
= FC_TYPE_BLS
;
8888 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
8889 lpfc_sli4_ct_abort_unsol_event
;
8892 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
8893 pring
->sli
.sli3
.sizeCiocb
) +
8894 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
8896 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
8897 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8898 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
8899 "SLI2 SLIM Data: x%x x%lx\n",
8900 phba
->brd_no
, totiocbsize
,
8901 (unsigned long) MAX_SLIM_IOCB_SIZE
);
8903 if (phba
->cfg_multi_ring_support
== 2)
8904 lpfc_extra_ring_setup(phba
);
8910 * lpfc_sli_queue_setup - Queue initialization function
8911 * @phba: Pointer to HBA context object.
8913 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8914 * ring. This function also initializes ring indices of each ring.
8915 * This function is called during the initialization of the SLI
8916 * interface of an HBA.
8917 * This function is called with no lock held and always returns
8921 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
8923 struct lpfc_sli
*psli
;
8924 struct lpfc_sli_ring
*pring
;
8928 spin_lock_irq(&phba
->hbalock
);
8929 INIT_LIST_HEAD(&psli
->mboxq
);
8930 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
8931 /* Initialize list headers for txq and txcmplq as double linked lists */
8932 for (i
= 0; i
< psli
->num_rings
; i
++) {
8933 pring
= &psli
->ring
[i
];
8935 pring
->sli
.sli3
.next_cmdidx
= 0;
8936 pring
->sli
.sli3
.local_getidx
= 0;
8937 pring
->sli
.sli3
.cmdidx
= 0;
8938 INIT_LIST_HEAD(&pring
->txq
);
8939 INIT_LIST_HEAD(&pring
->txcmplq
);
8940 INIT_LIST_HEAD(&pring
->iocb_continueq
);
8941 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
8942 INIT_LIST_HEAD(&pring
->postbufq
);
8943 spin_lock_init(&pring
->ring_lock
);
8945 spin_unlock_irq(&phba
->hbalock
);
8950 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8951 * @phba: Pointer to HBA context object.
8953 * This routine flushes the mailbox command subsystem. It will unconditionally
8954 * flush all the mailbox commands in the three possible stages in the mailbox
8955 * command sub-system: pending mailbox command queue; the outstanding mailbox
8956 * command; and completed mailbox command queue. It is caller's responsibility
8957 * to make sure that the driver is in the proper state to flush the mailbox
8958 * command sub-system. Namely, the posting of mailbox commands into the
8959 * pending mailbox command queue from the various clients must be stopped;
8960 * either the HBA is in a state that it will never works on the outstanding
8961 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8962 * mailbox command has been completed.
8965 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
8967 LIST_HEAD(completions
);
8968 struct lpfc_sli
*psli
= &phba
->sli
;
8970 unsigned long iflag
;
8972 /* Flush all the mailbox commands in the mbox system */
8973 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8974 /* The pending mailbox command queue */
8975 list_splice_init(&phba
->sli
.mboxq
, &completions
);
8976 /* The outstanding active mailbox command */
8977 if (psli
->mbox_active
) {
8978 list_add_tail(&psli
->mbox_active
->list
, &completions
);
8979 psli
->mbox_active
= NULL
;
8980 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8982 /* The completed mailbox command queue */
8983 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
8984 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8986 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8987 while (!list_empty(&completions
)) {
8988 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
8989 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8991 pmb
->mbox_cmpl(phba
, pmb
);
8996 * lpfc_sli_host_down - Vport cleanup function
8997 * @vport: Pointer to virtual port object.
8999 * lpfc_sli_host_down is called to clean up the resources
9000 * associated with a vport before destroying virtual
9001 * port data structures.
9002 * This function does following operations:
9003 * - Free discovery resources associated with this virtual
9005 * - Free iocbs associated with this virtual port in
9007 * - Send abort for all iocb commands associated with this
9010 * This function is called with no lock held and always returns 1.
9013 lpfc_sli_host_down(struct lpfc_vport
*vport
)
9015 LIST_HEAD(completions
);
9016 struct lpfc_hba
*phba
= vport
->phba
;
9017 struct lpfc_sli
*psli
= &phba
->sli
;
9018 struct lpfc_sli_ring
*pring
;
9019 struct lpfc_iocbq
*iocb
, *next_iocb
;
9021 unsigned long flags
= 0;
9022 uint16_t prev_pring_flag
;
9024 lpfc_cleanup_discovery_resources(vport
);
9026 spin_lock_irqsave(&phba
->hbalock
, flags
);
9027 for (i
= 0; i
< psli
->num_rings
; i
++) {
9028 pring
= &psli
->ring
[i
];
9029 prev_pring_flag
= pring
->flag
;
9030 /* Only slow rings */
9031 if (pring
->ringno
== LPFC_ELS_RING
) {
9032 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9033 /* Set the lpfc data pending flag */
9034 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9037 * Error everything on the txq since these iocbs have not been
9038 * given to the FW yet.
9040 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
9041 if (iocb
->vport
!= vport
)
9043 list_move_tail(&iocb
->list
, &completions
);
9047 /* Next issue ABTS for everything on the txcmplq */
9048 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
9050 if (iocb
->vport
!= vport
)
9052 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
9055 pring
->flag
= prev_pring_flag
;
9058 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9060 /* Cancel all the IOCBs from the completions list */
9061 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9067 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9068 * @phba: Pointer to HBA context object.
9070 * This function cleans up all iocb, buffers, mailbox commands
9071 * while shutting down the HBA. This function is called with no
9072 * lock held and always returns 1.
9073 * This function does the following to cleanup driver resources:
9074 * - Free discovery resources for each virtual port
9075 * - Cleanup any pending fabric iocbs
9076 * - Iterate through the iocb txq and free each entry
9078 * - Free up any buffer posted to the HBA
9079 * - Free mailbox commands in the mailbox queue.
9082 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
9084 LIST_HEAD(completions
);
9085 struct lpfc_sli
*psli
= &phba
->sli
;
9086 struct lpfc_sli_ring
*pring
;
9087 struct lpfc_dmabuf
*buf_ptr
;
9088 unsigned long flags
= 0;
9091 /* Shutdown the mailbox command sub-system */
9092 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
9094 lpfc_hba_down_prep(phba
);
9096 lpfc_fabric_abort_hba(phba
);
9098 spin_lock_irqsave(&phba
->hbalock
, flags
);
9099 for (i
= 0; i
< psli
->num_rings
; i
++) {
9100 pring
= &psli
->ring
[i
];
9101 /* Only slow rings */
9102 if (pring
->ringno
== LPFC_ELS_RING
) {
9103 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9104 /* Set the lpfc data pending flag */
9105 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9109 * Error everything on the txq since these iocbs have not been
9110 * given to the FW yet.
9112 list_splice_init(&pring
->txq
, &completions
);
9116 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9118 /* Cancel all the IOCBs from the completions list */
9119 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9122 spin_lock_irqsave(&phba
->hbalock
, flags
);
9123 list_splice_init(&phba
->elsbuf
, &completions
);
9124 phba
->elsbuf_cnt
= 0;
9125 phba
->elsbuf_prev_cnt
= 0;
9126 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9128 while (!list_empty(&completions
)) {
9129 list_remove_head(&completions
, buf_ptr
,
9130 struct lpfc_dmabuf
, list
);
9131 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
9135 /* Return any active mbox cmds */
9136 del_timer_sync(&psli
->mbox_tmo
);
9138 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
9139 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9140 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9146 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9147 * @srcp: Source memory pointer.
9148 * @destp: Destination memory pointer.
9149 * @cnt: Number of words required to be copied.
9151 * This function is used for copying data between driver memory
9152 * and the SLI memory. This function also changes the endianness
9153 * of each word if native endianness is different from SLI
9154 * endianness. This function can be called with or without
9158 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9160 uint32_t *src
= srcp
;
9161 uint32_t *dest
= destp
;
9165 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9167 ldata
= le32_to_cpu(ldata
);
9176 * lpfc_sli_bemem_bcopy - SLI memory copy function
9177 * @srcp: Source memory pointer.
9178 * @destp: Destination memory pointer.
9179 * @cnt: Number of words required to be copied.
9181 * This function is used for copying data between a data structure
9182 * with big endian representation to local endianness.
9183 * This function can be called with or without lock.
9186 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9188 uint32_t *src
= srcp
;
9189 uint32_t *dest
= destp
;
9193 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9195 ldata
= be32_to_cpu(ldata
);
9203 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9204 * @phba: Pointer to HBA context object.
9205 * @pring: Pointer to driver SLI ring object.
9206 * @mp: Pointer to driver buffer object.
9208 * This function is called with no lock held.
9209 * It always return zero after adding the buffer to the postbufq
9213 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9214 struct lpfc_dmabuf
*mp
)
9216 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9218 spin_lock_irq(&phba
->hbalock
);
9219 list_add_tail(&mp
->list
, &pring
->postbufq
);
9220 pring
->postbufq_cnt
++;
9221 spin_unlock_irq(&phba
->hbalock
);
9226 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9227 * @phba: Pointer to HBA context object.
9229 * When HBQ is enabled, buffers are searched based on tags. This function
9230 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9231 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9232 * does not conflict with tags of buffer posted for unsolicited events.
9233 * The function returns the allocated tag. The function is called with
9237 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9239 spin_lock_irq(&phba
->hbalock
);
9240 phba
->buffer_tag_count
++;
9242 * Always set the QUE_BUFTAG_BIT to distiguish between
9243 * a tag assigned by HBQ.
9245 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9246 spin_unlock_irq(&phba
->hbalock
);
9247 return phba
->buffer_tag_count
;
9251 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9252 * @phba: Pointer to HBA context object.
9253 * @pring: Pointer to driver SLI ring object.
9256 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9257 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9258 * iocb is posted to the response ring with the tag of the buffer.
9259 * This function searches the pring->postbufq list using the tag
9260 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9261 * iocb. If the buffer is found then lpfc_dmabuf object of the
9262 * buffer is returned to the caller else NULL is returned.
9263 * This function is called with no lock held.
9265 struct lpfc_dmabuf
*
9266 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9269 struct lpfc_dmabuf
*mp
, *next_mp
;
9270 struct list_head
*slp
= &pring
->postbufq
;
9272 /* Search postbufq, from the beginning, looking for a match on tag */
9273 spin_lock_irq(&phba
->hbalock
);
9274 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9275 if (mp
->buffer_tag
== tag
) {
9276 list_del_init(&mp
->list
);
9277 pring
->postbufq_cnt
--;
9278 spin_unlock_irq(&phba
->hbalock
);
9283 spin_unlock_irq(&phba
->hbalock
);
9284 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9285 "0402 Cannot find virtual addr for buffer tag on "
9286 "ring %d Data x%lx x%p x%p x%x\n",
9287 pring
->ringno
, (unsigned long) tag
,
9288 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9294 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9295 * @phba: Pointer to HBA context object.
9296 * @pring: Pointer to driver SLI ring object.
9297 * @phys: DMA address of the buffer.
9299 * This function searches the buffer list using the dma_address
9300 * of unsolicited event to find the driver's lpfc_dmabuf object
9301 * corresponding to the dma_address. The function returns the
9302 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9303 * This function is called by the ct and els unsolicited event
9304 * handlers to get the buffer associated with the unsolicited
9307 * This function is called with no lock held.
9309 struct lpfc_dmabuf
*
9310 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9313 struct lpfc_dmabuf
*mp
, *next_mp
;
9314 struct list_head
*slp
= &pring
->postbufq
;
9316 /* Search postbufq, from the beginning, looking for a match on phys */
9317 spin_lock_irq(&phba
->hbalock
);
9318 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9319 if (mp
->phys
== phys
) {
9320 list_del_init(&mp
->list
);
9321 pring
->postbufq_cnt
--;
9322 spin_unlock_irq(&phba
->hbalock
);
9327 spin_unlock_irq(&phba
->hbalock
);
9328 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9329 "0410 Cannot find virtual addr for mapped buf on "
9330 "ring %d Data x%llx x%p x%p x%x\n",
9331 pring
->ringno
, (unsigned long long)phys
,
9332 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9337 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9338 * @phba: Pointer to HBA context object.
9339 * @cmdiocb: Pointer to driver command iocb object.
9340 * @rspiocb: Pointer to driver response iocb object.
9342 * This function is the completion handler for the abort iocbs for
9343 * ELS commands. This function is called from the ELS ring event
9344 * handler with no lock held. This function frees memory resources
9345 * associated with the abort iocb.
9348 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9349 struct lpfc_iocbq
*rspiocb
)
9351 IOCB_t
*irsp
= &rspiocb
->iocb
;
9352 uint16_t abort_iotag
, abort_context
;
9353 struct lpfc_iocbq
*abort_iocb
= NULL
;
9355 if (irsp
->ulpStatus
) {
9358 * Assume that the port already completed and returned, or
9359 * will return the iocb. Just Log the message.
9361 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9362 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9364 spin_lock_irq(&phba
->hbalock
);
9365 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9366 if (abort_iotag
!= 0 &&
9367 abort_iotag
<= phba
->sli
.last_iotag
)
9369 phba
->sli
.iocbq_lookup
[abort_iotag
];
9371 /* For sli4 the abort_tag is the XRI,
9372 * so the abort routine puts the iotag of the iocb
9373 * being aborted in the context field of the abort
9376 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9378 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9379 "0327 Cannot abort els iocb %p "
9380 "with tag %x context %x, abort status %x, "
9382 abort_iocb
, abort_iotag
, abort_context
,
9383 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9385 spin_unlock_irq(&phba
->hbalock
);
9387 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9392 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9393 * @phba: Pointer to HBA context object.
9394 * @cmdiocb: Pointer to driver command iocb object.
9395 * @rspiocb: Pointer to driver response iocb object.
9397 * The function is called from SLI ring event handler with no
9398 * lock held. This function is the completion handler for ELS commands
9399 * which are aborted. The function frees memory resources used for
9400 * the aborted ELS commands.
9403 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9404 struct lpfc_iocbq
*rspiocb
)
9406 IOCB_t
*irsp
= &rspiocb
->iocb
;
9408 /* ELS cmd tag <ulpIoTag> completes */
9409 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9410 "0139 Ignoring ELS cmd tag x%x completion Data: "
9412 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9413 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9414 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9415 lpfc_ct_free_iocb(phba
, cmdiocb
);
9417 lpfc_els_free_iocb(phba
, cmdiocb
);
9422 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9423 * @phba: Pointer to HBA context object.
9424 * @pring: Pointer to driver SLI ring object.
9425 * @cmdiocb: Pointer to driver command iocb object.
9427 * This function issues an abort iocb for the provided command iocb down to
9428 * the port. Other than the case the outstanding command iocb is an abort
9429 * request, this function issues abort out unconditionally. This function is
9430 * called with hbalock held. The function returns 0 when it fails due to
9431 * memory allocation failure or when the command iocb is an abort request.
9434 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9435 struct lpfc_iocbq
*cmdiocb
)
9437 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9438 struct lpfc_iocbq
*abtsiocbp
;
9439 IOCB_t
*icmd
= NULL
;
9440 IOCB_t
*iabt
= NULL
;
9442 unsigned long iflags
;
9445 * There are certain command types we don't want to abort. And we
9446 * don't want to abort commands that are already in the process of
9449 icmd
= &cmdiocb
->iocb
;
9450 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9451 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9452 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9455 /* issue ABTS for this IOCB based on iotag */
9456 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9457 if (abtsiocbp
== NULL
)
9460 /* This signals the response to set the correct status
9461 * before calling the completion handler
9463 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9465 iabt
= &abtsiocbp
->iocb
;
9466 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9467 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9468 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9469 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9470 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9473 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9475 iabt
->ulpClass
= icmd
->ulpClass
;
9477 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9478 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9479 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9480 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9482 if (phba
->link_state
>= LPFC_LINK_UP
)
9483 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9485 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9487 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9489 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9490 "0339 Abort xri x%x, original iotag x%x, "
9491 "abort cmd iotag x%x\n",
9492 iabt
->un
.acxri
.abortIoTag
,
9493 iabt
->un
.acxri
.abortContextTag
,
9496 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9497 /* Note: both hbalock and ring_lock need to be set here */
9498 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9499 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9501 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9503 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9508 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9511 * Caller to this routine should check for IOCB_ERROR
9512 * and handle it properly. This routine no longer removes
9513 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9519 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9520 * @phba: Pointer to HBA context object.
9521 * @pring: Pointer to driver SLI ring object.
9522 * @cmdiocb: Pointer to driver command iocb object.
9524 * This function issues an abort iocb for the provided command iocb. In case
9525 * of unloading, the abort iocb will not be issued to commands on the ELS
9526 * ring. Instead, the callback function shall be changed to those commands
9527 * so that nothing happens when them finishes. This function is called with
9528 * hbalock held. The function returns 0 when the command iocb is an abort
9532 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9533 struct lpfc_iocbq
*cmdiocb
)
9535 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9536 int retval
= IOCB_ERROR
;
9537 IOCB_t
*icmd
= NULL
;
9540 * There are certain command types we don't want to abort. And we
9541 * don't want to abort commands that are already in the process of
9544 icmd
= &cmdiocb
->iocb
;
9545 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9546 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9547 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9551 * If we're unloading, don't abort iocb on the ELS ring, but change
9552 * the callback so that nothing happens when it finishes.
9554 if ((vport
->load_flag
& FC_UNLOADING
) &&
9555 (pring
->ringno
== LPFC_ELS_RING
)) {
9556 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9557 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9559 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9560 goto abort_iotag_exit
;
9563 /* Now, we try to issue the abort to the cmdiocb out */
9564 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9568 * Caller to this routine should check for IOCB_ERROR
9569 * and handle it properly. This routine no longer removes
9570 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9576 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9577 * @phba: Pointer to HBA context object.
9578 * @pring: Pointer to driver SLI ring object.
9580 * This function aborts all iocbs in the given ring and frees all the iocb
9581 * objects in txq. This function issues abort iocbs unconditionally for all
9582 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9583 * to complete before the return of this function. The caller is not required
9584 * to hold any locks.
9587 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9589 LIST_HEAD(completions
);
9590 struct lpfc_iocbq
*iocb
, *next_iocb
;
9592 if (pring
->ringno
== LPFC_ELS_RING
)
9593 lpfc_fabric_abort_hba(phba
);
9595 spin_lock_irq(&phba
->hbalock
);
9597 /* Take off all the iocbs on txq for cancelling */
9598 list_splice_init(&pring
->txq
, &completions
);
9601 /* Next issue ABTS for everything on the txcmplq */
9602 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9603 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9605 spin_unlock_irq(&phba
->hbalock
);
9607 /* Cancel all the IOCBs from the completions list */
9608 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9613 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9614 * @phba: pointer to lpfc HBA data structure.
9616 * This routine will abort all pending and outstanding iocbs to an HBA.
9619 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9621 struct lpfc_sli
*psli
= &phba
->sli
;
9622 struct lpfc_sli_ring
*pring
;
9625 for (i
= 0; i
< psli
->num_rings
; i
++) {
9626 pring
= &psli
->ring
[i
];
9627 lpfc_sli_iocb_ring_abort(phba
, pring
);
9632 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9633 * @iocbq: Pointer to driver iocb object.
9634 * @vport: Pointer to driver virtual port object.
9635 * @tgt_id: SCSI ID of the target.
9636 * @lun_id: LUN ID of the scsi device.
9637 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9639 * This function acts as an iocb filter for functions which abort or count
9640 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9641 * 0 if the filtering criteria is met for the given iocb and will return
9642 * 1 if the filtering criteria is not met.
9643 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9644 * given iocb is for the SCSI device specified by vport, tgt_id and
9646 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9647 * given iocb is for the SCSI target specified by vport and tgt_id
9649 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9650 * given iocb is for the SCSI host associated with the given vport.
9651 * This function is called with no locks held.
9654 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9655 uint16_t tgt_id
, uint64_t lun_id
,
9656 lpfc_ctx_cmd ctx_cmd
)
9658 struct lpfc_scsi_buf
*lpfc_cmd
;
9661 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9664 if (iocbq
->vport
!= vport
)
9667 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9669 if (lpfc_cmd
->pCmd
== NULL
)
9674 if ((lpfc_cmd
->rdata
->pnode
) &&
9675 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9676 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9680 if ((lpfc_cmd
->rdata
->pnode
) &&
9681 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9688 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9697 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9698 * @vport: Pointer to virtual port.
9699 * @tgt_id: SCSI ID of the target.
9700 * @lun_id: LUN ID of the scsi device.
9701 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9703 * This function returns number of FCP commands pending for the vport.
9704 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9705 * commands pending on the vport associated with SCSI device specified
9706 * by tgt_id and lun_id parameters.
9707 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9708 * commands pending on the vport associated with SCSI target specified
9709 * by tgt_id parameter.
9710 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9711 * commands pending on the vport.
9712 * This function returns the number of iocbs which satisfy the filter.
9713 * This function is called without any lock held.
9716 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9717 lpfc_ctx_cmd ctx_cmd
)
9719 struct lpfc_hba
*phba
= vport
->phba
;
9720 struct lpfc_iocbq
*iocbq
;
9723 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9724 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9726 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9735 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9736 * @phba: Pointer to HBA context object
9737 * @cmdiocb: Pointer to command iocb object.
9738 * @rspiocb: Pointer to response iocb object.
9740 * This function is called when an aborted FCP iocb completes. This
9741 * function is called by the ring event handler with no lock held.
9742 * This function frees the iocb.
9745 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9746 struct lpfc_iocbq
*rspiocb
)
9748 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9749 "3096 ABORT_XRI_CN completing on xri x%x "
9750 "original iotag x%x, abort cmd iotag x%x "
9751 "status 0x%x, reason 0x%x\n",
9752 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9753 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9754 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9755 rspiocb
->iocb
.un
.ulpWord
[4]);
9756 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9761 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9762 * @vport: Pointer to virtual port.
9763 * @pring: Pointer to driver SLI ring object.
9764 * @tgt_id: SCSI ID of the target.
9765 * @lun_id: LUN ID of the scsi device.
9766 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9768 * This function sends an abort command for every SCSI command
9769 * associated with the given virtual port pending on the ring
9770 * filtered by lpfc_sli_validate_fcp_iocb function.
9771 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9772 * FCP iocbs associated with lun specified by tgt_id and lun_id
9774 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9775 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9776 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9777 * FCP iocbs associated with virtual port.
9778 * This function returns number of iocbs it failed to abort.
9779 * This function is called with no locks held.
9782 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9783 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9785 struct lpfc_hba
*phba
= vport
->phba
;
9786 struct lpfc_iocbq
*iocbq
;
9787 struct lpfc_iocbq
*abtsiocb
;
9789 int errcnt
= 0, ret_val
= 0;
9792 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9793 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9795 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9799 /* issue ABTS for this IOCB based on iotag */
9800 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9801 if (abtsiocb
== NULL
) {
9807 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9808 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9809 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9810 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9812 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9813 abtsiocb
->iocb
.ulpLe
= 1;
9814 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9815 abtsiocb
->vport
= phba
->pport
;
9817 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9818 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9819 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9820 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9822 if (lpfc_is_link_up(phba
))
9823 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9825 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
9827 /* Setup callback routine and issue the command. */
9828 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
9829 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9831 if (ret_val
== IOCB_ERROR
) {
9832 lpfc_sli_release_iocbq(phba
, abtsiocb
);
9842 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9843 * @phba: Pointer to HBA context object.
9844 * @cmdiocbq: Pointer to command iocb.
9845 * @rspiocbq: Pointer to response iocb.
9847 * This function is the completion handler for iocbs issued using
9848 * lpfc_sli_issue_iocb_wait function. This function is called by the
9849 * ring event handler function without any lock held. This function
9850 * can be called from both worker thread context and interrupt
9851 * context. This function also can be called from other thread which
9852 * cleans up the SLI layer objects.
9853 * This function copy the contents of the response iocb to the
9854 * response iocb memory object provided by the caller of
9855 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9856 * sleeps for the iocb completion.
9859 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
9860 struct lpfc_iocbq
*cmdiocbq
,
9861 struct lpfc_iocbq
*rspiocbq
)
9863 wait_queue_head_t
*pdone_q
;
9864 unsigned long iflags
;
9865 struct lpfc_scsi_buf
*lpfc_cmd
;
9867 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9868 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
9869 if (cmdiocbq
->context2
&& rspiocbq
)
9870 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
9871 &rspiocbq
->iocb
, sizeof(IOCB_t
));
9873 /* Set the exchange busy flag for task management commands */
9874 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
9875 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
9876 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
9878 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
9881 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
9884 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9889 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9890 * @phba: Pointer to HBA context object..
9891 * @piocbq: Pointer to command iocb.
9892 * @flag: Flag to test.
9894 * This routine grabs the hbalock and then test the iocb_flag to
9895 * see if the passed in flag is set.
9898 * 0 if flag is not set.
9901 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
9902 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
9904 unsigned long iflags
;
9907 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9908 ret
= piocbq
->iocb_flag
& flag
;
9909 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9915 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9916 * @phba: Pointer to HBA context object..
9917 * @pring: Pointer to sli ring.
9918 * @piocb: Pointer to command iocb.
9919 * @prspiocbq: Pointer to response iocb.
9920 * @timeout: Timeout in number of seconds.
9922 * This function issues the iocb to firmware and waits for the
9923 * iocb to complete. If the iocb command is not
9924 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9925 * Caller should not free the iocb resources if this function
9926 * returns IOCB_TIMEDOUT.
9927 * The function waits for the iocb completion using an
9928 * non-interruptible wait.
9929 * This function will sleep while waiting for iocb completion.
9930 * So, this function should not be called from any context which
9931 * does not allow sleeping. Due to the same reason, this function
9932 * cannot be called with interrupt disabled.
9933 * This function assumes that the iocb completions occur while
9934 * this function sleep. So, this function cannot be called from
9935 * the thread which process iocb completion for this ring.
9936 * This function clears the iocb_flag of the iocb object before
9937 * issuing the iocb and the iocb completion handler sets this
9938 * flag and wakes this thread when the iocb completes.
9939 * The contents of the response iocb will be copied to prspiocbq
9940 * by the completion handler when the command completes.
9941 * This function returns IOCB_SUCCESS when success.
9942 * This function is called with no lock held.
9945 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
9946 uint32_t ring_number
,
9947 struct lpfc_iocbq
*piocb
,
9948 struct lpfc_iocbq
*prspiocbq
,
9951 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9952 long timeleft
, timeout_req
= 0;
9953 int retval
= IOCB_SUCCESS
;
9955 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9957 * If the caller has provided a response iocbq buffer, then context2
9958 * is NULL or its an error.
9961 if (piocb
->context2
)
9963 piocb
->context2
= prspiocbq
;
9966 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
9967 piocb
->context_un
.wait_queue
= &done_q
;
9968 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
9970 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9971 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9973 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
9974 writel(creg_val
, phba
->HCregaddr
);
9975 readl(phba
->HCregaddr
); /* flush */
9978 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
9980 if (retval
== IOCB_SUCCESS
) {
9981 timeout_req
= timeout
* HZ
;
9982 timeleft
= wait_event_timeout(done_q
,
9983 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
9986 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
9987 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9988 "0331 IOCB wake signaled\n");
9989 } else if (timeleft
== 0) {
9990 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9991 "0338 IOCB wait timeout error - no "
9992 "wake response Data x%x\n", timeout
);
9993 retval
= IOCB_TIMEDOUT
;
9995 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9996 "0330 IOCB wake NOT set, "
9998 timeout
, (timeleft
/ jiffies
));
9999 retval
= IOCB_TIMEDOUT
;
10001 } else if (retval
== IOCB_BUSY
) {
10002 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10003 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
10004 phba
->iocb_cnt
, pring
->txq_cnt
, pring
->txcmplq_cnt
);
10007 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10008 "0332 IOCB wait issue failed, Data x%x\n",
10010 retval
= IOCB_ERROR
;
10013 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10014 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10016 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
10017 writel(creg_val
, phba
->HCregaddr
);
10018 readl(phba
->HCregaddr
); /* flush */
10022 piocb
->context2
= NULL
;
10024 piocb
->context_un
.wait_queue
= NULL
;
10025 piocb
->iocb_cmpl
= NULL
;
10030 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
10031 * @phba: Pointer to HBA context object.
10032 * @pmboxq: Pointer to driver mailbox object.
10033 * @timeout: Timeout in number of seconds.
10035 * This function issues the mailbox to firmware and waits for the
10036 * mailbox command to complete. If the mailbox command is not
10037 * completed within timeout seconds, it returns MBX_TIMEOUT.
10038 * The function waits for the mailbox completion using an
10039 * interruptible wait. If the thread is woken up due to a
10040 * signal, MBX_TIMEOUT error is returned to the caller. Caller
10041 * should not free the mailbox resources, if this function returns
10043 * This function will sleep while waiting for mailbox completion.
10044 * So, this function should not be called from any context which
10045 * does not allow sleeping. Due to the same reason, this function
10046 * cannot be called with interrupt disabled.
10047 * This function assumes that the mailbox completion occurs while
10048 * this function sleep. So, this function cannot be called from
10049 * the worker thread which processes mailbox completion.
10050 * This function is called in the context of HBA management
10052 * This function returns MBX_SUCCESS when successful.
10053 * This function is called with no lock held.
10056 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
10059 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10061 unsigned long flag
;
10063 /* The caller must leave context1 empty. */
10064 if (pmboxq
->context1
)
10065 return MBX_NOT_FINISHED
;
10067 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
10068 /* setup wake call as IOCB callback */
10069 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
10070 /* setup context field to pass wait_queue pointer to wake function */
10071 pmboxq
->context1
= &done_q
;
10073 /* now issue the command */
10074 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
10075 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
10076 wait_event_interruptible_timeout(done_q
,
10077 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
10080 spin_lock_irqsave(&phba
->hbalock
, flag
);
10081 pmboxq
->context1
= NULL
;
10083 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10084 * else do not free the resources.
10086 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
10087 retval
= MBX_SUCCESS
;
10088 lpfc_sli4_swap_str(phba
, pmboxq
);
10090 retval
= MBX_TIMEOUT
;
10091 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10093 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
10100 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10101 * @phba: Pointer to HBA context.
10103 * This function is called to shutdown the driver's mailbox sub-system.
10104 * It first marks the mailbox sub-system is in a block state to prevent
10105 * the asynchronous mailbox command from issued off the pending mailbox
10106 * command queue. If the mailbox command sub-system shutdown is due to
10107 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10108 * the mailbox sub-system flush routine to forcefully bring down the
10109 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10110 * as with offline or HBA function reset), this routine will wait for the
10111 * outstanding mailbox command to complete before invoking the mailbox
10112 * sub-system flush routine to gracefully bring down mailbox sub-system.
10115 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
10117 struct lpfc_sli
*psli
= &phba
->sli
;
10118 unsigned long timeout
;
10120 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
10121 /* delay 100ms for port state */
10123 lpfc_sli_mbox_sys_flush(phba
);
10126 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
10128 spin_lock_irq(&phba
->hbalock
);
10129 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10131 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
10132 /* Determine how long we might wait for the active mailbox
10133 * command to be gracefully completed by firmware.
10135 if (phba
->sli
.mbox_active
)
10136 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
10137 phba
->sli
.mbox_active
) *
10139 spin_unlock_irq(&phba
->hbalock
);
10141 while (phba
->sli
.mbox_active
) {
10142 /* Check active mailbox complete status every 2ms */
10144 if (time_after(jiffies
, timeout
))
10145 /* Timeout, let the mailbox flush routine to
10146 * forcefully release active mailbox command
10151 spin_unlock_irq(&phba
->hbalock
);
10153 lpfc_sli_mbox_sys_flush(phba
);
10157 * lpfc_sli_eratt_read - read sli-3 error attention events
10158 * @phba: Pointer to HBA context.
10160 * This function is called to read the SLI3 device error attention registers
10161 * for possible error attention events. The caller must hold the hostlock
10162 * with spin_lock_irq().
10164 * This function returns 1 when there is Error Attention in the Host Attention
10165 * Register and returns 0 otherwise.
10168 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10172 /* Read chip Host Attention (HA) register */
10173 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10176 if (ha_copy
& HA_ERATT
) {
10177 /* Read host status register to retrieve error event */
10178 if (lpfc_sli_read_hs(phba
))
10181 /* Check if there is a deferred error condition is active */
10182 if ((HS_FFER1
& phba
->work_hs
) &&
10183 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10184 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10185 phba
->hba_flag
|= DEFER_ERATT
;
10186 /* Clear all interrupt enable conditions */
10187 writel(0, phba
->HCregaddr
);
10188 readl(phba
->HCregaddr
);
10191 /* Set the driver HA work bitmap */
10192 phba
->work_ha
|= HA_ERATT
;
10193 /* Indicate polling handles this ERATT */
10194 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10200 /* Set the driver HS work bitmap */
10201 phba
->work_hs
|= UNPLUG_ERR
;
10202 /* Set the driver HA work bitmap */
10203 phba
->work_ha
|= HA_ERATT
;
10204 /* Indicate polling handles this ERATT */
10205 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10210 * lpfc_sli4_eratt_read - read sli-4 error attention events
10211 * @phba: Pointer to HBA context.
10213 * This function is called to read the SLI4 device error attention registers
10214 * for possible error attention events. The caller must hold the hostlock
10215 * with spin_lock_irq().
10217 * This function returns 1 when there is Error Attention in the Host Attention
10218 * Register and returns 0 otherwise.
10221 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10223 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10224 uint32_t if_type
, portsmphr
;
10225 struct lpfc_register portstat_reg
;
10228 * For now, use the SLI4 device internal unrecoverable error
10229 * registers for error attention. This can be changed later.
10231 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10233 case LPFC_SLI_INTF_IF_TYPE_0
:
10234 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10236 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10238 phba
->work_hs
|= UNPLUG_ERR
;
10239 phba
->work_ha
|= HA_ERATT
;
10240 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10243 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10244 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10245 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10246 "1423 HBA Unrecoverable error: "
10247 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10248 "ue_mask_lo_reg=0x%x, "
10249 "ue_mask_hi_reg=0x%x\n",
10250 uerr_sta_lo
, uerr_sta_hi
,
10251 phba
->sli4_hba
.ue_mask_lo
,
10252 phba
->sli4_hba
.ue_mask_hi
);
10253 phba
->work_status
[0] = uerr_sta_lo
;
10254 phba
->work_status
[1] = uerr_sta_hi
;
10255 phba
->work_ha
|= HA_ERATT
;
10256 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10260 case LPFC_SLI_INTF_IF_TYPE_2
:
10261 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10262 &portstat_reg
.word0
) ||
10263 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10265 phba
->work_hs
|= UNPLUG_ERR
;
10266 phba
->work_ha
|= HA_ERATT
;
10267 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10270 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10271 phba
->work_status
[0] =
10272 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10273 phba
->work_status
[1] =
10274 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10275 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10276 "2885 Port Status Event: "
10277 "port status reg 0x%x, "
10278 "port smphr reg 0x%x, "
10279 "error 1=0x%x, error 2=0x%x\n",
10280 portstat_reg
.word0
,
10282 phba
->work_status
[0],
10283 phba
->work_status
[1]);
10284 phba
->work_ha
|= HA_ERATT
;
10285 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10289 case LPFC_SLI_INTF_IF_TYPE_1
:
10291 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10292 "2886 HBA Error Attention on unsupported "
10293 "if type %d.", if_type
);
10301 * lpfc_sli_check_eratt - check error attention events
10302 * @phba: Pointer to HBA context.
10304 * This function is called from timer soft interrupt context to check HBA's
10305 * error attention register bit for error attention events.
10307 * This function returns 1 when there is Error Attention in the Host Attention
10308 * Register and returns 0 otherwise.
10311 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10315 /* If somebody is waiting to handle an eratt, don't process it
10316 * here. The brdkill function will do this.
10318 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10321 /* Check if interrupt handler handles this ERATT */
10322 spin_lock_irq(&phba
->hbalock
);
10323 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10324 /* Interrupt handler has handled ERATT */
10325 spin_unlock_irq(&phba
->hbalock
);
10330 * If there is deferred error attention, do not check for error
10333 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10334 spin_unlock_irq(&phba
->hbalock
);
10338 /* If PCI channel is offline, don't process it */
10339 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10340 spin_unlock_irq(&phba
->hbalock
);
10344 switch (phba
->sli_rev
) {
10345 case LPFC_SLI_REV2
:
10346 case LPFC_SLI_REV3
:
10347 /* Read chip Host Attention (HA) register */
10348 ha_copy
= lpfc_sli_eratt_read(phba
);
10350 case LPFC_SLI_REV4
:
10351 /* Read device Uncoverable Error (UERR) registers */
10352 ha_copy
= lpfc_sli4_eratt_read(phba
);
10355 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10356 "0299 Invalid SLI revision (%d)\n",
10361 spin_unlock_irq(&phba
->hbalock
);
10367 * lpfc_intr_state_check - Check device state for interrupt handling
10368 * @phba: Pointer to HBA context.
10370 * This inline routine checks whether a device or its PCI slot is in a state
10371 * that the interrupt should be handled.
10373 * This function returns 0 if the device or the PCI slot is in a state that
10374 * interrupt should be handled, otherwise -EIO.
10377 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10379 /* If the pci channel is offline, ignore all the interrupts */
10380 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10383 /* Update device level interrupt statistics */
10384 phba
->sli
.slistat
.sli_intr
++;
10386 /* Ignore all interrupts during initialization. */
10387 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10394 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10395 * @irq: Interrupt number.
10396 * @dev_id: The device context pointer.
10398 * This function is directly called from the PCI layer as an interrupt
10399 * service routine when device with SLI-3 interface spec is enabled with
10400 * MSI-X multi-message interrupt mode and there are slow-path events in
10401 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10402 * interrupt mode, this function is called as part of the device-level
10403 * interrupt handler. When the PCI slot is in error recovery or the HBA
10404 * is undergoing initialization, the interrupt handler will not process
10405 * the interrupt. The link attention and ELS ring attention events are
10406 * handled by the worker thread. The interrupt handler signals the worker
10407 * thread and returns for these events. This function is called without
10408 * any lock held. It gets the hbalock to access and update SLI data
10411 * This function returns IRQ_HANDLED when interrupt is handled else it
10412 * returns IRQ_NONE.
10415 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10417 struct lpfc_hba
*phba
;
10418 uint32_t ha_copy
, hc_copy
;
10419 uint32_t work_ha_copy
;
10420 unsigned long status
;
10421 unsigned long iflag
;
10424 MAILBOX_t
*mbox
, *pmbox
;
10425 struct lpfc_vport
*vport
;
10426 struct lpfc_nodelist
*ndlp
;
10427 struct lpfc_dmabuf
*mp
;
10432 * Get the driver's phba structure from the dev_id and
10433 * assume the HBA is not interrupting.
10435 phba
= (struct lpfc_hba
*)dev_id
;
10437 if (unlikely(!phba
))
10441 * Stuff needs to be attented to when this function is invoked as an
10442 * individual interrupt handler in MSI-X multi-message interrupt mode
10444 if (phba
->intr_type
== MSIX
) {
10445 /* Check device state for handling interrupt */
10446 if (lpfc_intr_state_check(phba
))
10448 /* Need to read HA REG for slow-path events */
10449 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10450 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10452 /* If somebody is waiting to handle an eratt don't process it
10453 * here. The brdkill function will do this.
10455 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10456 ha_copy
&= ~HA_ERATT
;
10457 /* Check the need for handling ERATT in interrupt handler */
10458 if (ha_copy
& HA_ERATT
) {
10459 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10460 /* ERATT polling has handled ERATT */
10461 ha_copy
&= ~HA_ERATT
;
10463 /* Indicate interrupt handler handles ERATT */
10464 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10468 * If there is deferred error attention, do not check for any
10471 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10472 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10476 /* Clear up only attention source related to slow-path */
10477 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10480 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10481 HC_LAINT_ENA
| HC_ERINT_ENA
),
10483 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10485 writel(hc_copy
, phba
->HCregaddr
);
10486 readl(phba
->HAregaddr
); /* flush */
10487 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10489 ha_copy
= phba
->ha_copy
;
10491 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10493 if (work_ha_copy
) {
10494 if (work_ha_copy
& HA_LATT
) {
10495 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10497 * Turn off Link Attention interrupts
10498 * until CLEAR_LA done
10500 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10501 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10502 if (lpfc_readl(phba
->HCregaddr
, &control
))
10504 control
&= ~HC_LAINT_ENA
;
10505 writel(control
, phba
->HCregaddr
);
10506 readl(phba
->HCregaddr
); /* flush */
10507 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10510 work_ha_copy
&= ~HA_LATT
;
10513 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10515 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10516 * the only slow ring.
10518 status
= (work_ha_copy
&
10519 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10520 status
>>= (4*LPFC_ELS_RING
);
10521 if (status
& HA_RXMASK
) {
10522 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10523 if (lpfc_readl(phba
->HCregaddr
, &control
))
10526 lpfc_debugfs_slow_ring_trc(phba
,
10527 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10529 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10531 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10532 lpfc_debugfs_slow_ring_trc(phba
,
10533 "ISR Disable ring:"
10534 "pwork:x%x hawork:x%x wait:x%x",
10535 phba
->work_ha
, work_ha_copy
,
10536 (uint32_t)((unsigned long)
10537 &phba
->work_waitq
));
10540 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10541 writel(control
, phba
->HCregaddr
);
10542 readl(phba
->HCregaddr
); /* flush */
10545 lpfc_debugfs_slow_ring_trc(phba
,
10546 "ISR slow ring: pwork:"
10547 "x%x hawork:x%x wait:x%x",
10548 phba
->work_ha
, work_ha_copy
,
10549 (uint32_t)((unsigned long)
10550 &phba
->work_waitq
));
10552 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10555 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10556 if (work_ha_copy
& HA_ERATT
) {
10557 if (lpfc_sli_read_hs(phba
))
10560 * Check if there is a deferred error condition
10563 if ((HS_FFER1
& phba
->work_hs
) &&
10564 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10565 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10567 phba
->hba_flag
|= DEFER_ERATT
;
10568 /* Clear all interrupt enable conditions */
10569 writel(0, phba
->HCregaddr
);
10570 readl(phba
->HCregaddr
);
10574 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10575 pmb
= phba
->sli
.mbox_active
;
10576 pmbox
= &pmb
->u
.mb
;
10578 vport
= pmb
->vport
;
10580 /* First check out the status word */
10581 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10582 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10583 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10585 * Stray Mailbox Interrupt, mbxCommand <cmd>
10586 * mbxStatus <status>
10588 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10590 "(%d):0304 Stray Mailbox "
10591 "Interrupt mbxCommand x%x "
10593 (vport
? vport
->vpi
: 0),
10596 /* clear mailbox attention bit */
10597 work_ha_copy
&= ~HA_MBATT
;
10599 phba
->sli
.mbox_active
= NULL
;
10600 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10601 phba
->last_completion_time
= jiffies
;
10602 del_timer(&phba
->sli
.mbox_tmo
);
10603 if (pmb
->mbox_cmpl
) {
10604 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10606 if (pmb
->out_ext_byte_len
&&
10608 lpfc_sli_pcimem_bcopy(
10611 pmb
->out_ext_byte_len
);
10613 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10614 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10616 lpfc_debugfs_disc_trc(vport
,
10617 LPFC_DISC_TRC_MBOX_VPORT
,
10618 "MBOX dflt rpi: : "
10619 "status:x%x rpi:x%x",
10620 (uint32_t)pmbox
->mbxStatus
,
10621 pmbox
->un
.varWords
[0], 0);
10623 if (!pmbox
->mbxStatus
) {
10624 mp
= (struct lpfc_dmabuf
*)
10626 ndlp
= (struct lpfc_nodelist
*)
10629 /* Reg_LOGIN of dflt RPI was
10630 * successful. new lets get
10631 * rid of the RPI using the
10632 * same mbox buffer.
10634 lpfc_unreg_login(phba
,
10636 pmbox
->un
.varWords
[0],
10639 lpfc_mbx_cmpl_dflt_rpi
;
10640 pmb
->context1
= mp
;
10641 pmb
->context2
= ndlp
;
10642 pmb
->vport
= vport
;
10643 rc
= lpfc_sli_issue_mbox(phba
,
10646 if (rc
!= MBX_BUSY
)
10647 lpfc_printf_log(phba
,
10649 LOG_MBOX
| LOG_SLI
,
10650 "0350 rc should have"
10651 "been MBX_BUSY\n");
10652 if (rc
!= MBX_NOT_FINISHED
)
10653 goto send_current_mbox
;
10657 &phba
->pport
->work_port_lock
,
10659 phba
->pport
->work_port_events
&=
10661 spin_unlock_irqrestore(
10662 &phba
->pport
->work_port_lock
,
10664 lpfc_mbox_cmpl_put(phba
, pmb
);
10667 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10669 if ((work_ha_copy
& HA_MBATT
) &&
10670 (phba
->sli
.mbox_active
== NULL
)) {
10672 /* Process next mailbox command if there is one */
10674 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10676 } while (rc
== MBX_NOT_FINISHED
);
10677 if (rc
!= MBX_SUCCESS
)
10678 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10679 LOG_SLI
, "0349 rc should be "
10683 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10684 phba
->work_ha
|= work_ha_copy
;
10685 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10686 lpfc_worker_wake_up(phba
);
10688 return IRQ_HANDLED
;
10690 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10691 return IRQ_HANDLED
;
10693 } /* lpfc_sli_sp_intr_handler */
10696 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10697 * @irq: Interrupt number.
10698 * @dev_id: The device context pointer.
10700 * This function is directly called from the PCI layer as an interrupt
10701 * service routine when device with SLI-3 interface spec is enabled with
10702 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10703 * ring event in the HBA. However, when the device is enabled with either
10704 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10705 * device-level interrupt handler. When the PCI slot is in error recovery
10706 * or the HBA is undergoing initialization, the interrupt handler will not
10707 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10708 * the intrrupt context. This function is called without any lock held.
10709 * It gets the hbalock to access and update SLI data structures.
10711 * This function returns IRQ_HANDLED when interrupt is handled else it
10712 * returns IRQ_NONE.
10715 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10717 struct lpfc_hba
*phba
;
10719 unsigned long status
;
10720 unsigned long iflag
;
10722 /* Get the driver's phba structure from the dev_id and
10723 * assume the HBA is not interrupting.
10725 phba
= (struct lpfc_hba
*) dev_id
;
10727 if (unlikely(!phba
))
10731 * Stuff needs to be attented to when this function is invoked as an
10732 * individual interrupt handler in MSI-X multi-message interrupt mode
10734 if (phba
->intr_type
== MSIX
) {
10735 /* Check device state for handling interrupt */
10736 if (lpfc_intr_state_check(phba
))
10738 /* Need to read HA REG for FCP ring and other ring events */
10739 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10740 return IRQ_HANDLED
;
10741 /* Clear up only attention source related to fast-path */
10742 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10744 * If there is deferred error attention, do not check for
10747 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10748 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10751 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10753 readl(phba
->HAregaddr
); /* flush */
10754 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10756 ha_copy
= phba
->ha_copy
;
10759 * Process all events on FCP ring. Take the optimized path for FCP IO.
10761 ha_copy
&= ~(phba
->work_ha_mask
);
10763 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10764 status
>>= (4*LPFC_FCP_RING
);
10765 if (status
& HA_RXMASK
)
10766 lpfc_sli_handle_fast_ring_event(phba
,
10767 &phba
->sli
.ring
[LPFC_FCP_RING
],
10770 if (phba
->cfg_multi_ring_support
== 2) {
10772 * Process all events on extra ring. Take the optimized path
10773 * for extra ring IO.
10775 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10776 status
>>= (4*LPFC_EXTRA_RING
);
10777 if (status
& HA_RXMASK
) {
10778 lpfc_sli_handle_fast_ring_event(phba
,
10779 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
10783 return IRQ_HANDLED
;
10784 } /* lpfc_sli_fp_intr_handler */
10787 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10788 * @irq: Interrupt number.
10789 * @dev_id: The device context pointer.
10791 * This function is the HBA device-level interrupt handler to device with
10792 * SLI-3 interface spec, called from the PCI layer when either MSI or
10793 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10794 * requires driver attention. This function invokes the slow-path interrupt
10795 * attention handling function and fast-path interrupt attention handling
10796 * function in turn to process the relevant HBA attention events. This
10797 * function is called without any lock held. It gets the hbalock to access
10798 * and update SLI data structures.
10800 * This function returns IRQ_HANDLED when interrupt is handled, else it
10801 * returns IRQ_NONE.
10804 lpfc_sli_intr_handler(int irq
, void *dev_id
)
10806 struct lpfc_hba
*phba
;
10807 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10808 unsigned long status1
, status2
;
10812 * Get the driver's phba structure from the dev_id and
10813 * assume the HBA is not interrupting.
10815 phba
= (struct lpfc_hba
*) dev_id
;
10817 if (unlikely(!phba
))
10820 /* Check device state for handling interrupt */
10821 if (lpfc_intr_state_check(phba
))
10824 spin_lock(&phba
->hbalock
);
10825 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
10826 spin_unlock(&phba
->hbalock
);
10827 return IRQ_HANDLED
;
10830 if (unlikely(!phba
->ha_copy
)) {
10831 spin_unlock(&phba
->hbalock
);
10833 } else if (phba
->ha_copy
& HA_ERATT
) {
10834 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10835 /* ERATT polling has handled ERATT */
10836 phba
->ha_copy
&= ~HA_ERATT
;
10838 /* Indicate interrupt handler handles ERATT */
10839 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10843 * If there is deferred error attention, do not check for any interrupt.
10845 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10846 spin_unlock(&phba
->hbalock
);
10850 /* Clear attention sources except link and error attentions */
10851 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
10852 spin_unlock(&phba
->hbalock
);
10853 return IRQ_HANDLED
;
10855 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
10856 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
10858 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
10859 writel(hc_copy
, phba
->HCregaddr
);
10860 readl(phba
->HAregaddr
); /* flush */
10861 spin_unlock(&phba
->hbalock
);
10864 * Invokes slow-path host attention interrupt handling as appropriate.
10867 /* status of events with mailbox and link attention */
10868 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
10870 /* status of events with ELS ring */
10871 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10872 status2
>>= (4*LPFC_ELS_RING
);
10874 if (status1
|| (status2
& HA_RXMASK
))
10875 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
10877 sp_irq_rc
= IRQ_NONE
;
10880 * Invoke fast-path host attention interrupt handling as appropriate.
10883 /* status of events with FCP ring */
10884 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10885 status1
>>= (4*LPFC_FCP_RING
);
10887 /* status of events with extra ring */
10888 if (phba
->cfg_multi_ring_support
== 2) {
10889 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10890 status2
>>= (4*LPFC_EXTRA_RING
);
10894 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
10895 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
10897 fp_irq_rc
= IRQ_NONE
;
10899 /* Return device-level interrupt handling status */
10900 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
10901 } /* lpfc_sli_intr_handler */
10904 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10905 * @phba: pointer to lpfc hba data structure.
10907 * This routine is invoked by the worker thread to process all the pending
10908 * SLI4 FCP abort XRI events.
10910 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
10912 struct lpfc_cq_event
*cq_event
;
10914 /* First, declare the fcp xri abort event has been handled */
10915 spin_lock_irq(&phba
->hbalock
);
10916 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
10917 spin_unlock_irq(&phba
->hbalock
);
10918 /* Now, handle all the fcp xri abort events */
10919 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
10920 /* Get the first event from the head of the event queue */
10921 spin_lock_irq(&phba
->hbalock
);
10922 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10923 cq_event
, struct lpfc_cq_event
, list
);
10924 spin_unlock_irq(&phba
->hbalock
);
10925 /* Notify aborted XRI for FCP work queue */
10926 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10927 /* Free the event processed back to the free pool */
10928 lpfc_sli4_cq_event_release(phba
, cq_event
);
10933 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10934 * @phba: pointer to lpfc hba data structure.
10936 * This routine is invoked by the worker thread to process all the pending
10937 * SLI4 els abort xri events.
10939 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
10941 struct lpfc_cq_event
*cq_event
;
10943 /* First, declare the els xri abort event has been handled */
10944 spin_lock_irq(&phba
->hbalock
);
10945 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
10946 spin_unlock_irq(&phba
->hbalock
);
10947 /* Now, handle all the els xri abort events */
10948 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
10949 /* Get the first event from the head of the event queue */
10950 spin_lock_irq(&phba
->hbalock
);
10951 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10952 cq_event
, struct lpfc_cq_event
, list
);
10953 spin_unlock_irq(&phba
->hbalock
);
10954 /* Notify aborted XRI for ELS work queue */
10955 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10956 /* Free the event processed back to the free pool */
10957 lpfc_sli4_cq_event_release(phba
, cq_event
);
10962 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10963 * @phba: pointer to lpfc hba data structure
10964 * @pIocbIn: pointer to the rspiocbq
10965 * @pIocbOut: pointer to the cmdiocbq
10966 * @wcqe: pointer to the complete wcqe
10968 * This routine transfers the fields of a command iocbq to a response iocbq
10969 * by copying all the IOCB fields from command iocbq and transferring the
10970 * completion status information from the complete wcqe.
10973 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
10974 struct lpfc_iocbq
*pIocbIn
,
10975 struct lpfc_iocbq
*pIocbOut
,
10976 struct lpfc_wcqe_complete
*wcqe
)
10978 unsigned long iflags
;
10980 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
10982 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
10983 sizeof(struct lpfc_iocbq
) - offset
);
10984 /* Map WCQE parameters into irspiocb parameters */
10985 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
10986 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
10987 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
10988 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
10989 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
10990 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
10991 wcqe
->total_data_placed
;
10993 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10995 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10996 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
10999 /* Convert BG errors for completion status */
11000 if (status
== CQE_STATUS_DI_ERROR
) {
11001 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
11003 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
11004 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
11006 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
11008 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
11009 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
11010 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11011 BGS_GUARD_ERR_MASK
;
11012 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
11013 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11014 BGS_APPTAG_ERR_MASK
;
11015 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
11016 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11017 BGS_REFTAG_ERR_MASK
;
11019 /* Check to see if there was any good data before the error */
11020 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
11021 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11022 BGS_HI_WATER_MARK_PRESENT_MASK
;
11023 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
11024 wcqe
->total_data_placed
;
11028 * Set ALL the error bits to indicate we don't know what
11029 * type of error it is.
11031 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
11032 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11033 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
11034 BGS_GUARD_ERR_MASK
);
11037 /* Pick up HBA exchange busy condition */
11038 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
11039 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11040 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
11041 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11046 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11047 * @phba: Pointer to HBA context object.
11048 * @wcqe: Pointer to work-queue completion queue entry.
11050 * This routine handles an ELS work-queue completion event and construct
11051 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11052 * discovery engine to handle.
11054 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11056 static struct lpfc_iocbq
*
11057 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
11058 struct lpfc_iocbq
*irspiocbq
)
11060 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
11061 struct lpfc_iocbq
*cmdiocbq
;
11062 struct lpfc_wcqe_complete
*wcqe
;
11063 unsigned long iflags
;
11065 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
11066 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11067 pring
->stats
.iocb_event
++;
11068 /* Look up the ELS command IOCB and create pseudo response IOCB */
11069 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11070 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11071 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11073 if (unlikely(!cmdiocbq
)) {
11074 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11075 "0386 ELS complete with no corresponding "
11076 "cmdiocb: iotag (%d)\n",
11077 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11078 lpfc_sli_release_iocbq(phba
, irspiocbq
);
11082 /* Fake the irspiocbq and copy necessary response information */
11083 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
11089 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11090 * @phba: Pointer to HBA context object.
11091 * @cqe: Pointer to mailbox completion queue entry.
11093 * This routine process a mailbox completion queue entry with asynchrous
11096 * Return: true if work posted to worker thread, otherwise false.
11099 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11101 struct lpfc_cq_event
*cq_event
;
11102 unsigned long iflags
;
11104 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11105 "0392 Async Event: word0:x%x, word1:x%x, "
11106 "word2:x%x, word3:x%x\n", mcqe
->word0
,
11107 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
11109 /* Allocate a new internal CQ_EVENT entry */
11110 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11112 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11113 "0394 Failed to allocate CQ_EVENT entry\n");
11117 /* Move the CQE into an asynchronous event entry */
11118 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
11119 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11120 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
11121 /* Set the async event flag */
11122 phba
->hba_flag
|= ASYNC_EVENT
;
11123 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11129 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11130 * @phba: Pointer to HBA context object.
11131 * @cqe: Pointer to mailbox completion queue entry.
11133 * This routine process a mailbox completion queue entry with mailbox
11134 * completion event.
11136 * Return: true if work posted to worker thread, otherwise false.
11139 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11141 uint32_t mcqe_status
;
11142 MAILBOX_t
*mbox
, *pmbox
;
11143 struct lpfc_mqe
*mqe
;
11144 struct lpfc_vport
*vport
;
11145 struct lpfc_nodelist
*ndlp
;
11146 struct lpfc_dmabuf
*mp
;
11147 unsigned long iflags
;
11149 bool workposted
= false;
11152 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11153 if (!bf_get(lpfc_trailer_completed
, mcqe
))
11154 goto out_no_mqe_complete
;
11156 /* Get the reference to the active mbox command */
11157 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11158 pmb
= phba
->sli
.mbox_active
;
11159 if (unlikely(!pmb
)) {
11160 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11161 "1832 No pending MBOX command to handle\n");
11162 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11163 goto out_no_mqe_complete
;
11165 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11167 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11169 vport
= pmb
->vport
;
11171 /* Reset heartbeat timer */
11172 phba
->last_completion_time
= jiffies
;
11173 del_timer(&phba
->sli
.mbox_tmo
);
11175 /* Move mbox data to caller's mailbox region, do endian swapping */
11176 if (pmb
->mbox_cmpl
&& mbox
)
11177 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11180 * For mcqe errors, conditionally move a modified error code to
11181 * the mbox so that the error will not be missed.
11183 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11184 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11185 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11186 bf_set(lpfc_mqe_status
, mqe
,
11187 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11189 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11190 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11191 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11192 "MBOX dflt rpi: status:x%x rpi:x%x",
11194 pmbox
->un
.varWords
[0], 0);
11195 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11196 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11197 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11198 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11199 * RID of the PPI using the same mbox buffer.
11201 lpfc_unreg_login(phba
, vport
->vpi
,
11202 pmbox
->un
.varWords
[0], pmb
);
11203 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11204 pmb
->context1
= mp
;
11205 pmb
->context2
= ndlp
;
11206 pmb
->vport
= vport
;
11207 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11208 if (rc
!= MBX_BUSY
)
11209 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11210 LOG_SLI
, "0385 rc should "
11211 "have been MBX_BUSY\n");
11212 if (rc
!= MBX_NOT_FINISHED
)
11213 goto send_current_mbox
;
11216 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11217 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11218 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11220 /* There is mailbox completion work to do */
11221 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11222 __lpfc_mbox_cmpl_put(phba
, pmb
);
11223 phba
->work_ha
|= HA_MBATT
;
11224 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11228 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11229 /* Release the mailbox command posting token */
11230 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11231 /* Setting active mailbox pointer need to be in sync to flag clear */
11232 phba
->sli
.mbox_active
= NULL
;
11233 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11234 /* Wake up worker thread to post the next pending mailbox command */
11235 lpfc_worker_wake_up(phba
);
11236 out_no_mqe_complete
:
11237 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11238 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
11243 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11244 * @phba: Pointer to HBA context object.
11245 * @cqe: Pointer to mailbox completion queue entry.
11247 * This routine process a mailbox completion queue entry, it invokes the
11248 * proper mailbox complete handling or asynchrous event handling routine
11249 * according to the MCQE's async bit.
11251 * Return: true if work posted to worker thread, otherwise false.
11254 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
11256 struct lpfc_mcqe mcqe
;
11259 /* Copy the mailbox MCQE and convert endian order as needed */
11260 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
11262 /* Invoke the proper event handling routine */
11263 if (!bf_get(lpfc_trailer_async
, &mcqe
))
11264 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
11266 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
11271 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11272 * @phba: Pointer to HBA context object.
11273 * @cq: Pointer to associated CQ
11274 * @wcqe: Pointer to work-queue completion queue entry.
11276 * This routine handles an ELS work-queue completion event.
11278 * Return: true if work posted to worker thread, otherwise false.
11281 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11282 struct lpfc_wcqe_complete
*wcqe
)
11284 struct lpfc_iocbq
*irspiocbq
;
11285 unsigned long iflags
;
11286 struct lpfc_sli_ring
*pring
= cq
->pring
;
11288 /* Get an irspiocbq for later ELS response processing use */
11289 irspiocbq
= lpfc_sli_get_iocbq(phba
);
11291 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11292 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11293 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
11294 pring
->txq_cnt
, phba
->iocb_cnt
,
11295 phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
,
11296 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
);
11300 /* Save off the slow-path queue event for work thread to process */
11301 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
11302 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11303 list_add_tail(&irspiocbq
->cq_event
.list
,
11304 &phba
->sli4_hba
.sp_queue_event
);
11305 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11306 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11312 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11313 * @phba: Pointer to HBA context object.
11314 * @wcqe: Pointer to work-queue completion queue entry.
11316 * This routine handles slow-path WQ entry comsumed event by invoking the
11317 * proper WQ release routine to the slow-path WQ.
11320 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
11321 struct lpfc_wcqe_release
*wcqe
)
11323 /* sanity check on queue memory */
11324 if (unlikely(!phba
->sli4_hba
.els_wq
))
11326 /* Check for the slow-path ELS work queue */
11327 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
11328 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
11329 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11331 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11332 "2579 Slow-path wqe consume event carries "
11333 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11334 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
11335 phba
->sli4_hba
.els_wq
->queue_id
);
11339 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11340 * @phba: Pointer to HBA context object.
11341 * @cq: Pointer to a WQ completion queue.
11342 * @wcqe: Pointer to work-queue completion queue entry.
11344 * This routine handles an XRI abort event.
11346 * Return: true if work posted to worker thread, otherwise false.
11349 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
11350 struct lpfc_queue
*cq
,
11351 struct sli4_wcqe_xri_aborted
*wcqe
)
11353 bool workposted
= false;
11354 struct lpfc_cq_event
*cq_event
;
11355 unsigned long iflags
;
11357 /* Allocate a new internal CQ_EVENT entry */
11358 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11360 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11361 "0602 Failed to allocate CQ_EVENT entry\n");
11365 /* Move the CQE into the proper xri abort event list */
11366 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11367 switch (cq
->subtype
) {
11369 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11370 list_add_tail(&cq_event
->list
,
11371 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11372 /* Set the fcp xri abort event flag */
11373 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11374 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11378 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11379 list_add_tail(&cq_event
->list
,
11380 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11381 /* Set the els xri abort event flag */
11382 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11383 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11387 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11388 "0603 Invalid work queue CQE subtype (x%x)\n",
11390 workposted
= false;
11397 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11398 * @phba: Pointer to HBA context object.
11399 * @rcqe: Pointer to receive-queue completion queue entry.
11401 * This routine process a receive-queue completion queue entry.
11403 * Return: true if work posted to worker thread, otherwise false.
11406 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11408 bool workposted
= false;
11409 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11410 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11411 struct hbq_dmabuf
*dma_buf
;
11412 uint32_t status
, rq_id
;
11413 unsigned long iflags
;
11415 /* sanity check on queue memory */
11416 if (unlikely(!hrq
) || unlikely(!drq
))
11419 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11420 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11422 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11423 if (rq_id
!= hrq
->queue_id
)
11426 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11428 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11429 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11430 "2537 Receive Frame Truncated!!\n");
11431 hrq
->RQ_buf_trunc
++;
11432 case FC_STATUS_RQ_SUCCESS
:
11433 lpfc_sli4_rq_release(hrq
, drq
);
11434 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11435 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11437 hrq
->RQ_no_buf_found
++;
11438 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11442 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11443 /* save off the frame for the word thread to process */
11444 list_add_tail(&dma_buf
->cq_event
.list
,
11445 &phba
->sli4_hba
.sp_queue_event
);
11446 /* Frame received */
11447 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11448 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11451 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11452 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11453 hrq
->RQ_no_posted_buf
++;
11454 /* Post more buffers if possible */
11455 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11456 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11457 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11466 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11467 * @phba: Pointer to HBA context object.
11468 * @cq: Pointer to the completion queue.
11469 * @wcqe: Pointer to a completion queue entry.
11471 * This routine process a slow-path work-queue or receive queue completion queue
11474 * Return: true if work posted to worker thread, otherwise false.
11477 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11478 struct lpfc_cqe
*cqe
)
11480 struct lpfc_cqe cqevt
;
11481 bool workposted
= false;
11483 /* Copy the work queue CQE and convert endian order if needed */
11484 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11486 /* Check and process for different type of WCQE and dispatch */
11487 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11488 case CQE_CODE_COMPL_WQE
:
11489 /* Process the WQ/RQ complete event */
11490 phba
->last_completion_time
= jiffies
;
11491 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
11492 (struct lpfc_wcqe_complete
*)&cqevt
);
11494 case CQE_CODE_RELEASE_WQE
:
11495 /* Process the WQ release event */
11496 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11497 (struct lpfc_wcqe_release
*)&cqevt
);
11499 case CQE_CODE_XRI_ABORTED
:
11500 /* Process the WQ XRI abort event */
11501 phba
->last_completion_time
= jiffies
;
11502 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11503 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11505 case CQE_CODE_RECEIVE
:
11506 case CQE_CODE_RECEIVE_V1
:
11507 /* Process the RQ event */
11508 phba
->last_completion_time
= jiffies
;
11509 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11510 (struct lpfc_rcqe
*)&cqevt
);
11513 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11514 "0388 Not a valid WCQE code: x%x\n",
11515 bf_get(lpfc_cqe_code
, &cqevt
));
11522 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11523 * @phba: Pointer to HBA context object.
11524 * @eqe: Pointer to fast-path event queue entry.
11526 * This routine process a event queue entry from the slow-path event queue.
11527 * It will check the MajorCode and MinorCode to determine this is for a
11528 * completion event on a completion queue, if not, an error shall be logged
11529 * and just return. Otherwise, it will get to the corresponding completion
11530 * queue and process all the entries on that completion queue, rearm the
11531 * completion queue, and then return.
11535 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11536 struct lpfc_queue
*speq
)
11538 struct lpfc_queue
*cq
= NULL
, *childq
;
11539 struct lpfc_cqe
*cqe
;
11540 bool workposted
= false;
11544 /* Get the reference to the corresponding CQ */
11545 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11547 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11548 if (childq
->queue_id
== cqid
) {
11553 if (unlikely(!cq
)) {
11554 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11555 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11556 "0365 Slow-path CQ identifier "
11557 "(%d) does not exist\n", cqid
);
11561 /* Process all the entries to the CQ */
11562 switch (cq
->type
) {
11564 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11565 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11566 if (!(++ecount
% cq
->entry_repost
))
11567 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11572 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11573 if (cq
->subtype
== LPFC_FCP
)
11574 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11577 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11579 if (!(++ecount
% cq
->entry_repost
))
11580 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11583 /* Track the max number of CQEs processed in 1 EQ */
11584 if (ecount
> cq
->CQ_max_cqe
)
11585 cq
->CQ_max_cqe
= ecount
;
11588 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11589 "0370 Invalid completion queue type (%d)\n",
11594 /* Catch the no cq entry condition, log an error */
11595 if (unlikely(ecount
== 0))
11596 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11597 "0371 No entry from the CQ: identifier "
11598 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11600 /* In any case, flash and re-arm the RCQ */
11601 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11603 /* wake up worker thread if there are works to be done */
11605 lpfc_worker_wake_up(phba
);
11609 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11610 * @phba: Pointer to HBA context object.
11611 * @cq: Pointer to associated CQ
11612 * @wcqe: Pointer to work-queue completion queue entry.
11614 * This routine process a fast-path work queue completion entry from fast-path
11615 * event queue for FCP command response completion.
11618 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11619 struct lpfc_wcqe_complete
*wcqe
)
11621 struct lpfc_sli_ring
*pring
= cq
->pring
;
11622 struct lpfc_iocbq
*cmdiocbq
;
11623 struct lpfc_iocbq irspiocbq
;
11624 unsigned long iflags
;
11626 /* Check for response status */
11627 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11628 /* If resource errors reported from HBA, reduce queue
11629 * depth of the SCSI device.
11631 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11632 IOSTAT_LOCAL_REJECT
) &&
11633 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
11634 phba
->lpfc_rampdown_queue_depth(phba
);
11636 /* Log the error status */
11637 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11638 "0373 FCP complete error: status=x%x, "
11639 "hw_status=x%x, total_data_specified=%d, "
11640 "parameter=x%x, word3=x%x\n",
11641 bf_get(lpfc_wcqe_c_status
, wcqe
),
11642 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11643 wcqe
->total_data_placed
, wcqe
->parameter
,
11647 /* Look up the FCP command IOCB and create pseudo response IOCB */
11648 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11649 pring
->stats
.iocb_event
++;
11650 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11651 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11652 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11653 if (unlikely(!cmdiocbq
)) {
11654 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11655 "0374 FCP complete with no corresponding "
11656 "cmdiocb: iotag (%d)\n",
11657 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11660 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11661 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11662 "0375 FCP cmdiocb not callback function "
11664 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11668 /* Fake the irspiocb and copy necessary response information */
11669 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11671 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11672 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11673 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11674 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11677 /* Pass the cmd_iocb and the rsp state to the upper layer */
11678 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11682 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11683 * @phba: Pointer to HBA context object.
11684 * @cq: Pointer to completion queue.
11685 * @wcqe: Pointer to work-queue completion queue entry.
11687 * This routine handles an fast-path WQ entry comsumed event by invoking the
11688 * proper WQ release routine to the slow-path WQ.
11691 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11692 struct lpfc_wcqe_release
*wcqe
)
11694 struct lpfc_queue
*childwq
;
11695 bool wqid_matched
= false;
11698 /* Check for fast-path FCP work queue release */
11699 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11700 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11701 if (childwq
->queue_id
== fcp_wqid
) {
11702 lpfc_sli4_wq_release(childwq
,
11703 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11704 wqid_matched
= true;
11708 /* Report warning log message if no match found */
11709 if (wqid_matched
!= true)
11710 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11711 "2580 Fast-path wqe consume event carries "
11712 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11716 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11717 * @cq: Pointer to the completion queue.
11718 * @eqe: Pointer to fast-path completion queue entry.
11720 * This routine process a fast-path work queue completion entry from fast-path
11721 * event queue for FCP command response completion.
11724 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11725 struct lpfc_cqe
*cqe
)
11727 struct lpfc_wcqe_release wcqe
;
11728 bool workposted
= false;
11730 /* Copy the work queue CQE and convert endian order if needed */
11731 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
11733 /* Check and process for different type of WCQE and dispatch */
11734 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
11735 case CQE_CODE_COMPL_WQE
:
11737 /* Process the WQ complete event */
11738 phba
->last_completion_time
= jiffies
;
11739 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
11740 (struct lpfc_wcqe_complete
*)&wcqe
);
11742 case CQE_CODE_RELEASE_WQE
:
11743 cq
->CQ_release_wqe
++;
11744 /* Process the WQ release event */
11745 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
11746 (struct lpfc_wcqe_release
*)&wcqe
);
11748 case CQE_CODE_XRI_ABORTED
:
11749 cq
->CQ_xri_aborted
++;
11750 /* Process the WQ XRI abort event */
11751 phba
->last_completion_time
= jiffies
;
11752 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11753 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
11756 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11757 "0144 Not a valid WCQE code: x%x\n",
11758 bf_get(lpfc_wcqe_c_code
, &wcqe
));
11765 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
11766 * @phba: Pointer to HBA context object.
11767 * @eqe: Pointer to fast-path event queue entry.
11769 * This routine process a event queue entry from the fast-path event queue.
11770 * It will check the MajorCode and MinorCode to determine this is for a
11771 * completion event on a completion queue, if not, an error shall be logged
11772 * and just return. Otherwise, it will get to the corresponding completion
11773 * queue and process all the entries on the completion queue, rearm the
11774 * completion queue, and then return.
11777 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11780 struct lpfc_queue
*cq
;
11781 struct lpfc_cqe
*cqe
;
11782 bool workposted
= false;
11786 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
11787 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11788 "0366 Not a valid completion "
11789 "event: majorcode=x%x, minorcode=x%x\n",
11790 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11791 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11795 /* Get the reference to the corresponding CQ */
11796 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11798 /* Check if this is a Slow path event */
11799 if (unlikely(cqid
!= phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
11800 lpfc_sli4_sp_handle_eqe(phba
, eqe
,
11801 phba
->sli4_hba
.hba_eq
[qidx
]);
11805 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
11806 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11807 "3146 Fast-path completion queues "
11808 "does not exist\n");
11811 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
11812 if (unlikely(!cq
)) {
11813 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11814 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11815 "0367 Fast-path completion queue "
11816 "(%d) does not exist\n", qidx
);
11820 if (unlikely(cqid
!= cq
->queue_id
)) {
11821 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11822 "0368 Miss-matched fast-path completion "
11823 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11824 cqid
, cq
->queue_id
);
11828 /* Process all the entries to the CQ */
11829 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11830 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
11831 if (!(++ecount
% cq
->entry_repost
))
11832 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11835 /* Track the max number of CQEs processed in 1 EQ */
11836 if (ecount
> cq
->CQ_max_cqe
)
11837 cq
->CQ_max_cqe
= ecount
;
11839 /* Catch the no cq entry condition */
11840 if (unlikely(ecount
== 0))
11841 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11842 "0369 No entry from fast-path completion "
11843 "queue fcpcqid=%d\n", cq
->queue_id
);
11845 /* In any case, flash and re-arm the CQ */
11846 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11848 /* wake up worker thread if there are works to be done */
11850 lpfc_worker_wake_up(phba
);
11854 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
11856 struct lpfc_eqe
*eqe
;
11858 /* walk all the EQ entries and drop on the floor */
11859 while ((eqe
= lpfc_sli4_eq_get(eq
)))
11862 /* Clear and re-arm the EQ */
11863 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
11867 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
11868 * @irq: Interrupt number.
11869 * @dev_id: The device context pointer.
11871 * This function is directly called from the PCI layer as an interrupt
11872 * service routine when device with SLI-4 interface spec is enabled with
11873 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11874 * ring event in the HBA. However, when the device is enabled with either
11875 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11876 * device-level interrupt handler. When the PCI slot is in error recovery
11877 * or the HBA is undergoing initialization, the interrupt handler will not
11878 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11879 * the intrrupt context. This function is called without any lock held.
11880 * It gets the hbalock to access and update SLI data structures. Note that,
11881 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11882 * equal to that of FCP CQ index.
11884 * The link attention and ELS ring attention events are handled
11885 * by the worker thread. The interrupt handler signals the worker thread
11886 * and returns for these events. This function is called without any lock
11887 * held. It gets the hbalock to access and update SLI data structures.
11889 * This function returns IRQ_HANDLED when interrupt is handled else it
11890 * returns IRQ_NONE.
11893 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
11895 struct lpfc_hba
*phba
;
11896 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
11897 struct lpfc_queue
*fpeq
;
11898 struct lpfc_eqe
*eqe
;
11899 unsigned long iflag
;
11901 uint32_t fcp_eqidx
;
11903 /* Get the driver's phba structure from the dev_id */
11904 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
11905 phba
= fcp_eq_hdl
->phba
;
11906 fcp_eqidx
= fcp_eq_hdl
->idx
;
11908 if (unlikely(!phba
))
11910 if (unlikely(!phba
->sli4_hba
.hba_eq
))
11913 /* Get to the EQ struct associated with this vector */
11914 fpeq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
11915 if (unlikely(!fpeq
))
11918 if (lpfc_fcp_look_ahead
) {
11919 if (atomic_dec_and_test(&fcp_eq_hdl
->fcp_eq_in_use
))
11920 lpfc_sli4_eq_clr_intr(fpeq
);
11922 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
11927 /* Check device state for handling interrupt */
11928 if (unlikely(lpfc_intr_state_check(phba
))) {
11929 fpeq
->EQ_badstate
++;
11930 /* Check again for link_state with lock held */
11931 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11932 if (phba
->link_state
< LPFC_LINK_DOWN
)
11933 /* Flush, clear interrupt, and rearm the EQ */
11934 lpfc_sli4_eq_flush(phba
, fpeq
);
11935 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11936 if (lpfc_fcp_look_ahead
)
11937 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
11942 * Process all the event on FCP fast-path EQ
11944 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
11945 lpfc_sli4_hba_handle_eqe(phba
, eqe
, fcp_eqidx
);
11946 if (!(++ecount
% fpeq
->entry_repost
))
11947 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
11948 fpeq
->EQ_processed
++;
11951 /* Track the max number of EQEs processed in 1 intr */
11952 if (ecount
> fpeq
->EQ_max_eqe
)
11953 fpeq
->EQ_max_eqe
= ecount
;
11955 /* Always clear and re-arm the fast-path EQ */
11956 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
11958 if (unlikely(ecount
== 0)) {
11959 fpeq
->EQ_no_entry
++;
11961 if (lpfc_fcp_look_ahead
) {
11962 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
11966 if (phba
->intr_type
== MSIX
)
11967 /* MSI-X treated interrupt served as no EQ share INT */
11968 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11969 "0358 MSI-X interrupt with no EQE\n");
11971 /* Non MSI-X treated on interrupt as EQ share INT */
11975 if (lpfc_fcp_look_ahead
)
11976 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
11977 return IRQ_HANDLED
;
11978 } /* lpfc_sli4_fp_intr_handler */
11981 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11982 * @irq: Interrupt number.
11983 * @dev_id: The device context pointer.
11985 * This function is the device-level interrupt handler to device with SLI-4
11986 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11987 * interrupt mode is enabled and there is an event in the HBA which requires
11988 * driver attention. This function invokes the slow-path interrupt attention
11989 * handling function and fast-path interrupt attention handling function in
11990 * turn to process the relevant HBA attention events. This function is called
11991 * without any lock held. It gets the hbalock to access and update SLI data
11994 * This function returns IRQ_HANDLED when interrupt is handled, else it
11995 * returns IRQ_NONE.
11998 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
12000 struct lpfc_hba
*phba
;
12001 irqreturn_t hba_irq_rc
;
12002 bool hba_handled
= false;
12003 uint32_t fcp_eqidx
;
12005 /* Get the driver's phba structure from the dev_id */
12006 phba
= (struct lpfc_hba
*)dev_id
;
12008 if (unlikely(!phba
))
12012 * Invoke fast-path host attention interrupt handling as appropriate.
12014 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
12015 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
12016 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
12017 if (hba_irq_rc
== IRQ_HANDLED
)
12018 hba_handled
|= true;
12021 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
12022 } /* lpfc_sli4_intr_handler */
12025 * lpfc_sli4_queue_free - free a queue structure and associated memory
12026 * @queue: The queue structure to free.
12028 * This function frees a queue structure and the DMAable memory used for
12029 * the host resident queue. This function must be called after destroying the
12030 * queue on the HBA.
12033 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
12035 struct lpfc_dmabuf
*dmabuf
;
12040 while (!list_empty(&queue
->page_list
)) {
12041 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
12043 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
12044 dmabuf
->virt
, dmabuf
->phys
);
12052 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12053 * @phba: The HBA that this queue is being created on.
12054 * @entry_size: The size of each queue entry for this queue.
12055 * @entry count: The number of entries that this queue will handle.
12057 * This function allocates a queue structure and the DMAable memory used for
12058 * the host resident queue. This function must be called before creating the
12059 * queue on the HBA.
12061 struct lpfc_queue
*
12062 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
12063 uint32_t entry_count
)
12065 struct lpfc_queue
*queue
;
12066 struct lpfc_dmabuf
*dmabuf
;
12067 int x
, total_qe_count
;
12069 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12071 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12072 hw_page_size
= SLI4_PAGE_SIZE
;
12074 queue
= kzalloc(sizeof(struct lpfc_queue
) +
12075 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
12078 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
12079 hw_page_size
))/hw_page_size
;
12080 INIT_LIST_HEAD(&queue
->list
);
12081 INIT_LIST_HEAD(&queue
->page_list
);
12082 INIT_LIST_HEAD(&queue
->child_list
);
12083 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
12084 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
12087 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
12088 hw_page_size
, &dmabuf
->phys
,
12090 if (!dmabuf
->virt
) {
12094 memset(dmabuf
->virt
, 0, hw_page_size
);
12095 dmabuf
->buffer_tag
= x
;
12096 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
12097 /* initialize queue's entry array */
12098 dma_pointer
= dmabuf
->virt
;
12099 for (; total_qe_count
< entry_count
&&
12100 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
12101 total_qe_count
++, dma_pointer
+= entry_size
) {
12102 queue
->qe
[total_qe_count
].address
= dma_pointer
;
12105 queue
->entry_size
= entry_size
;
12106 queue
->entry_count
= entry_count
;
12109 * entry_repost is calculated based on the number of entries in the
12110 * queue. This works out except for RQs. If buffers are NOT initially
12111 * posted for every RQE, entry_repost should be adjusted accordingly.
12113 queue
->entry_repost
= (entry_count
>> 3);
12114 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
12115 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
12116 queue
->phba
= phba
;
12120 lpfc_sli4_queue_free(queue
);
12125 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
12126 * @phba: HBA structure that indicates port to create a queue on.
12127 * @startq: The starting FCP EQ to modify
12129 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
12131 * The @phba struct is used to send mailbox command to HBA. The @startq
12132 * is used to get the starting FCP EQ to change.
12133 * This function is asynchronous and will wait for the mailbox
12134 * command to finish before continuing.
12136 * On success this function will return a zero. If unable to allocate enough
12137 * memory this function will return -ENOMEM. If the queue create mailbox command
12138 * fails this function will return -ENXIO.
12141 lpfc_modify_fcp_eq_delay(struct lpfc_hba
*phba
, uint16_t startq
)
12143 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
12144 LPFC_MBOXQ_t
*mbox
;
12145 struct lpfc_queue
*eq
;
12146 int cnt
, rc
, length
, status
= 0;
12147 uint32_t shdr_status
, shdr_add_status
;
12149 union lpfc_sli4_cfg_shdr
*shdr
;
12152 if (startq
>= phba
->cfg_fcp_io_channel
)
12155 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12158 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
12159 sizeof(struct lpfc_sli4_cfg_mhdr
));
12160 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12161 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
12162 length
, LPFC_SLI4_MBX_EMBED
);
12163 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
12165 /* Calculate delay multiper from maximum interrupt per second */
12166 dmult
= phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
;
12167 dmult
= LPFC_DMULT_CONST
/dmult
- 1;
12170 for (fcp_eqidx
= startq
; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
12172 eq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12175 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
12176 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
12177 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
12179 if (cnt
>= LPFC_MAX_EQ_DELAY
)
12182 eq_delay
->u
.request
.num_eq
= cnt
;
12184 mbox
->vport
= phba
->pport
;
12185 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12186 mbox
->context1
= NULL
;
12187 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12188 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
12189 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12190 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12191 if (shdr_status
|| shdr_add_status
|| rc
) {
12192 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12193 "2512 MODIFY_EQ_DELAY mailbox failed with "
12194 "status x%x add_status x%x, mbx status x%x\n",
12195 shdr_status
, shdr_add_status
, rc
);
12198 mempool_free(mbox
, phba
->mbox_mem_pool
);
12203 * lpfc_eq_create - Create an Event Queue on the HBA
12204 * @phba: HBA structure that indicates port to create a queue on.
12205 * @eq: The queue structure to use to create the event queue.
12206 * @imax: The maximum interrupt per second limit.
12208 * This function creates an event queue, as detailed in @eq, on a port,
12209 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12211 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12212 * is used to get the entry count and entry size that are necessary to
12213 * determine the number of pages to allocate and use for this queue. This
12214 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12215 * event queue. This function is asynchronous and will wait for the mailbox
12216 * command to finish before continuing.
12218 * On success this function will return a zero. If unable to allocate enough
12219 * memory this function will return -ENOMEM. If the queue create mailbox command
12220 * fails this function will return -ENXIO.
12223 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
12225 struct lpfc_mbx_eq_create
*eq_create
;
12226 LPFC_MBOXQ_t
*mbox
;
12227 int rc
, length
, status
= 0;
12228 struct lpfc_dmabuf
*dmabuf
;
12229 uint32_t shdr_status
, shdr_add_status
;
12230 union lpfc_sli4_cfg_shdr
*shdr
;
12232 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12234 /* sanity check on queue memory */
12237 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12238 hw_page_size
= SLI4_PAGE_SIZE
;
12240 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12243 length
= (sizeof(struct lpfc_mbx_eq_create
) -
12244 sizeof(struct lpfc_sli4_cfg_mhdr
));
12245 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12246 LPFC_MBOX_OPCODE_EQ_CREATE
,
12247 length
, LPFC_SLI4_MBX_EMBED
);
12248 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
12249 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
12251 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
12253 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
12254 /* Calculate delay multiper from maximum interrupt per second */
12255 dmult
= LPFC_DMULT_CONST
/imax
- 1;
12256 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
12258 switch (eq
->entry_count
) {
12260 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12261 "0360 Unsupported EQ count. (%d)\n",
12263 if (eq
->entry_count
< 256)
12265 /* otherwise default to smallest count (drop through) */
12267 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12271 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12275 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12279 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12283 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12287 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
12288 memset(dmabuf
->virt
, 0, hw_page_size
);
12289 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12290 putPaddrLow(dmabuf
->phys
);
12291 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12292 putPaddrHigh(dmabuf
->phys
);
12294 mbox
->vport
= phba
->pport
;
12295 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12296 mbox
->context1
= NULL
;
12297 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12298 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
12299 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12300 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12301 if (shdr_status
|| shdr_add_status
|| rc
) {
12302 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12303 "2500 EQ_CREATE mailbox failed with "
12304 "status x%x add_status x%x, mbx status x%x\n",
12305 shdr_status
, shdr_add_status
, rc
);
12308 eq
->type
= LPFC_EQ
;
12309 eq
->subtype
= LPFC_NONE
;
12310 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
12311 if (eq
->queue_id
== 0xFFFF)
12313 eq
->host_index
= 0;
12316 mempool_free(mbox
, phba
->mbox_mem_pool
);
12321 * lpfc_cq_create - Create a Completion Queue on the HBA
12322 * @phba: HBA structure that indicates port to create a queue on.
12323 * @cq: The queue structure to use to create the completion queue.
12324 * @eq: The event queue to bind this completion queue to.
12326 * This function creates a completion queue, as detailed in @wq, on a port,
12327 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
12329 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12330 * is used to get the entry count and entry size that are necessary to
12331 * determine the number of pages to allocate and use for this queue. The @eq
12332 * is used to indicate which event queue to bind this completion queue to. This
12333 * function will send the CQ_CREATE mailbox command to the HBA to setup the
12334 * completion queue. This function is asynchronous and will wait for the mailbox
12335 * command to finish before continuing.
12337 * On success this function will return a zero. If unable to allocate enough
12338 * memory this function will return -ENOMEM. If the queue create mailbox command
12339 * fails this function will return -ENXIO.
12342 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12343 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
12345 struct lpfc_mbx_cq_create
*cq_create
;
12346 struct lpfc_dmabuf
*dmabuf
;
12347 LPFC_MBOXQ_t
*mbox
;
12348 int rc
, length
, status
= 0;
12349 uint32_t shdr_status
, shdr_add_status
;
12350 union lpfc_sli4_cfg_shdr
*shdr
;
12351 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12353 /* sanity check on queue memory */
12356 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12357 hw_page_size
= SLI4_PAGE_SIZE
;
12359 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12362 length
= (sizeof(struct lpfc_mbx_cq_create
) -
12363 sizeof(struct lpfc_sli4_cfg_mhdr
));
12364 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12365 LPFC_MBOX_OPCODE_CQ_CREATE
,
12366 length
, LPFC_SLI4_MBX_EMBED
);
12367 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
12368 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
12369 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
12371 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
12372 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
12373 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12374 phba
->sli4_hba
.pc_sli4_params
.cqv
);
12375 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
12376 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12377 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
12378 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
12381 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
12384 switch (cq
->entry_count
) {
12386 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12387 "0361 Unsupported CQ count. (%d)\n",
12389 if (cq
->entry_count
< 256) {
12393 /* otherwise default to smallest count (drop through) */
12395 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12399 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12403 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12407 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12408 memset(dmabuf
->virt
, 0, hw_page_size
);
12409 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12410 putPaddrLow(dmabuf
->phys
);
12411 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12412 putPaddrHigh(dmabuf
->phys
);
12414 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12416 /* The IOCTL status is embedded in the mailbox subheader. */
12417 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12418 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12419 if (shdr_status
|| shdr_add_status
|| rc
) {
12420 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12421 "2501 CQ_CREATE mailbox failed with "
12422 "status x%x add_status x%x, mbx status x%x\n",
12423 shdr_status
, shdr_add_status
, rc
);
12427 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12428 if (cq
->queue_id
== 0xFFFF) {
12432 /* link the cq onto the parent eq child list */
12433 list_add_tail(&cq
->list
, &eq
->child_list
);
12434 /* Set up completion queue's type and subtype */
12436 cq
->subtype
= subtype
;
12437 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12438 cq
->assoc_qid
= eq
->queue_id
;
12439 cq
->host_index
= 0;
12443 mempool_free(mbox
, phba
->mbox_mem_pool
);
12448 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12449 * @phba: HBA structure that indicates port to create a queue on.
12450 * @mq: The queue structure to use to create the mailbox queue.
12451 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12452 * @cq: The completion queue to associate with this cq.
12454 * This function provides failback (fb) functionality when the
12455 * mq_create_ext fails on older FW generations. It's purpose is identical
12456 * to mq_create_ext otherwise.
12458 * This routine cannot fail as all attributes were previously accessed and
12459 * initialized in mq_create_ext.
12462 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12463 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12465 struct lpfc_mbx_mq_create
*mq_create
;
12466 struct lpfc_dmabuf
*dmabuf
;
12469 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12470 sizeof(struct lpfc_sli4_cfg_mhdr
));
12471 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12472 LPFC_MBOX_OPCODE_MQ_CREATE
,
12473 length
, LPFC_SLI4_MBX_EMBED
);
12474 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12475 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12477 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12479 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12480 switch (mq
->entry_count
) {
12482 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12483 LPFC_MQ_RING_SIZE_16
);
12486 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12487 LPFC_MQ_RING_SIZE_32
);
12490 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12491 LPFC_MQ_RING_SIZE_64
);
12494 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12495 LPFC_MQ_RING_SIZE_128
);
12498 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12499 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12500 putPaddrLow(dmabuf
->phys
);
12501 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12502 putPaddrHigh(dmabuf
->phys
);
12507 * lpfc_mq_create - Create a mailbox Queue on the HBA
12508 * @phba: HBA structure that indicates port to create a queue on.
12509 * @mq: The queue structure to use to create the mailbox queue.
12510 * @cq: The completion queue to associate with this cq.
12511 * @subtype: The queue's subtype.
12513 * This function creates a mailbox queue, as detailed in @mq, on a port,
12514 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12516 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12517 * is used to get the entry count and entry size that are necessary to
12518 * determine the number of pages to allocate and use for this queue. This
12519 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12520 * mailbox queue. This function is asynchronous and will wait for the mailbox
12521 * command to finish before continuing.
12523 * On success this function will return a zero. If unable to allocate enough
12524 * memory this function will return -ENOMEM. If the queue create mailbox command
12525 * fails this function will return -ENXIO.
12528 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12529 struct lpfc_queue
*cq
, uint32_t subtype
)
12531 struct lpfc_mbx_mq_create
*mq_create
;
12532 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12533 struct lpfc_dmabuf
*dmabuf
;
12534 LPFC_MBOXQ_t
*mbox
;
12535 int rc
, length
, status
= 0;
12536 uint32_t shdr_status
, shdr_add_status
;
12537 union lpfc_sli4_cfg_shdr
*shdr
;
12538 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12540 /* sanity check on queue memory */
12543 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12544 hw_page_size
= SLI4_PAGE_SIZE
;
12546 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12549 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12550 sizeof(struct lpfc_sli4_cfg_mhdr
));
12551 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12552 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12553 length
, LPFC_SLI4_MBX_EMBED
);
12555 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12556 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12557 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12558 &mq_create_ext
->u
.request
, mq
->page_count
);
12559 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12560 &mq_create_ext
->u
.request
, 1);
12561 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12562 &mq_create_ext
->u
.request
, 1);
12563 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12564 &mq_create_ext
->u
.request
, 1);
12565 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12566 &mq_create_ext
->u
.request
, 1);
12567 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12568 &mq_create_ext
->u
.request
, 1);
12569 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12570 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12571 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12572 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12573 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12576 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12578 switch (mq
->entry_count
) {
12580 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12581 "0362 Unsupported MQ count. (%d)\n",
12583 if (mq
->entry_count
< 16) {
12587 /* otherwise default to smallest count (drop through) */
12589 bf_set(lpfc_mq_context_ring_size
,
12590 &mq_create_ext
->u
.request
.context
,
12591 LPFC_MQ_RING_SIZE_16
);
12594 bf_set(lpfc_mq_context_ring_size
,
12595 &mq_create_ext
->u
.request
.context
,
12596 LPFC_MQ_RING_SIZE_32
);
12599 bf_set(lpfc_mq_context_ring_size
,
12600 &mq_create_ext
->u
.request
.context
,
12601 LPFC_MQ_RING_SIZE_64
);
12604 bf_set(lpfc_mq_context_ring_size
,
12605 &mq_create_ext
->u
.request
.context
,
12606 LPFC_MQ_RING_SIZE_128
);
12609 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12610 memset(dmabuf
->virt
, 0, hw_page_size
);
12611 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12612 putPaddrLow(dmabuf
->phys
);
12613 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12614 putPaddrHigh(dmabuf
->phys
);
12616 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12617 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12618 &mq_create_ext
->u
.response
);
12619 if (rc
!= MBX_SUCCESS
) {
12620 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12621 "2795 MQ_CREATE_EXT failed with "
12622 "status x%x. Failback to MQ_CREATE.\n",
12624 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12625 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12626 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12627 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12628 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12629 &mq_create
->u
.response
);
12632 /* The IOCTL status is embedded in the mailbox subheader. */
12633 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12634 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12635 if (shdr_status
|| shdr_add_status
|| rc
) {
12636 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12637 "2502 MQ_CREATE mailbox failed with "
12638 "status x%x add_status x%x, mbx status x%x\n",
12639 shdr_status
, shdr_add_status
, rc
);
12643 if (mq
->queue_id
== 0xFFFF) {
12647 mq
->type
= LPFC_MQ
;
12648 mq
->assoc_qid
= cq
->queue_id
;
12649 mq
->subtype
= subtype
;
12650 mq
->host_index
= 0;
12653 /* link the mq onto the parent cq child list */
12654 list_add_tail(&mq
->list
, &cq
->child_list
);
12656 mempool_free(mbox
, phba
->mbox_mem_pool
);
12661 * lpfc_wq_create - Create a Work Queue on the HBA
12662 * @phba: HBA structure that indicates port to create a queue on.
12663 * @wq: The queue structure to use to create the work queue.
12664 * @cq: The completion queue to bind this work queue to.
12665 * @subtype: The subtype of the work queue indicating its functionality.
12667 * This function creates a work queue, as detailed in @wq, on a port, described
12668 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12670 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12671 * is used to get the entry count and entry size that are necessary to
12672 * determine the number of pages to allocate and use for this queue. The @cq
12673 * is used to indicate which completion queue to bind this work queue to. This
12674 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12675 * work queue. This function is asynchronous and will wait for the mailbox
12676 * command to finish before continuing.
12678 * On success this function will return a zero. If unable to allocate enough
12679 * memory this function will return -ENOMEM. If the queue create mailbox command
12680 * fails this function will return -ENXIO.
12683 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12684 struct lpfc_queue
*cq
, uint32_t subtype
)
12686 struct lpfc_mbx_wq_create
*wq_create
;
12687 struct lpfc_dmabuf
*dmabuf
;
12688 LPFC_MBOXQ_t
*mbox
;
12689 int rc
, length
, status
= 0;
12690 uint32_t shdr_status
, shdr_add_status
;
12691 union lpfc_sli4_cfg_shdr
*shdr
;
12692 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12693 struct dma_address
*page
;
12695 /* sanity check on queue memory */
12698 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12699 hw_page_size
= SLI4_PAGE_SIZE
;
12701 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12704 length
= (sizeof(struct lpfc_mbx_wq_create
) -
12705 sizeof(struct lpfc_sli4_cfg_mhdr
));
12706 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12707 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
12708 length
, LPFC_SLI4_MBX_EMBED
);
12709 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
12710 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
12711 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
12713 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
12715 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12716 phba
->sli4_hba
.pc_sli4_params
.wqv
);
12717 if (phba
->sli4_hba
.pc_sli4_params
.wqv
== LPFC_Q_CREATE_VERSION_1
) {
12718 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
12720 switch (wq
->entry_size
) {
12723 bf_set(lpfc_mbx_wq_create_wqe_size
,
12724 &wq_create
->u
.request_1
,
12725 LPFC_WQ_WQE_SIZE_64
);
12728 bf_set(lpfc_mbx_wq_create_wqe_size
,
12729 &wq_create
->u
.request_1
,
12730 LPFC_WQ_WQE_SIZE_128
);
12733 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
12734 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12735 page
= wq_create
->u
.request_1
.page
;
12737 page
= wq_create
->u
.request
.page
;
12739 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
12740 memset(dmabuf
->virt
, 0, hw_page_size
);
12741 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
12742 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
12744 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12745 /* The IOCTL status is embedded in the mailbox subheader. */
12746 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12747 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12748 if (shdr_status
|| shdr_add_status
|| rc
) {
12749 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12750 "2503 WQ_CREATE mailbox failed with "
12751 "status x%x add_status x%x, mbx status x%x\n",
12752 shdr_status
, shdr_add_status
, rc
);
12756 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
12757 if (wq
->queue_id
== 0xFFFF) {
12761 wq
->type
= LPFC_WQ
;
12762 wq
->assoc_qid
= cq
->queue_id
;
12763 wq
->subtype
= subtype
;
12764 wq
->host_index
= 0;
12766 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
12768 /* link the wq onto the parent cq child list */
12769 list_add_tail(&wq
->list
, &cq
->child_list
);
12771 mempool_free(mbox
, phba
->mbox_mem_pool
);
12776 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12777 * @phba: HBA structure that indicates port to create a queue on.
12778 * @rq: The queue structure to use for the receive queue.
12779 * @qno: The associated HBQ number
12782 * For SLI4 we need to adjust the RQ repost value based on
12783 * the number of buffers that are initially posted to the RQ.
12786 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
12790 /* sanity check on queue memory */
12793 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
12795 /* Recalc repost for RQs based on buffers initially posted */
12797 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
12798 cnt
= LPFC_QUEUE_MIN_REPOST
;
12800 rq
->entry_repost
= cnt
;
12804 * lpfc_rq_create - Create a Receive Queue on the HBA
12805 * @phba: HBA structure that indicates port to create a queue on.
12806 * @hrq: The queue structure to use to create the header receive queue.
12807 * @drq: The queue structure to use to create the data receive queue.
12808 * @cq: The completion queue to bind this work queue to.
12810 * This function creates a receive buffer queue pair , as detailed in @hrq and
12811 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12814 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12815 * struct is used to get the entry count that is necessary to determine the
12816 * number of pages to use for this queue. The @cq is used to indicate which
12817 * completion queue to bind received buffers that are posted to these queues to.
12818 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12819 * receive queue pair. This function is asynchronous and will wait for the
12820 * mailbox command to finish before continuing.
12822 * On success this function will return a zero. If unable to allocate enough
12823 * memory this function will return -ENOMEM. If the queue create mailbox command
12824 * fails this function will return -ENXIO.
12827 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12828 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
12830 struct lpfc_mbx_rq_create
*rq_create
;
12831 struct lpfc_dmabuf
*dmabuf
;
12832 LPFC_MBOXQ_t
*mbox
;
12833 int rc
, length
, status
= 0;
12834 uint32_t shdr_status
, shdr_add_status
;
12835 union lpfc_sli4_cfg_shdr
*shdr
;
12836 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12838 /* sanity check on queue memory */
12839 if (!hrq
|| !drq
|| !cq
)
12841 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12842 hw_page_size
= SLI4_PAGE_SIZE
;
12844 if (hrq
->entry_count
!= drq
->entry_count
)
12846 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12849 length
= (sizeof(struct lpfc_mbx_rq_create
) -
12850 sizeof(struct lpfc_sli4_cfg_mhdr
));
12851 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12852 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12853 length
, LPFC_SLI4_MBX_EMBED
);
12854 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
12855 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12856 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12857 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12858 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12859 bf_set(lpfc_rq_context_rqe_count_1
,
12860 &rq_create
->u
.request
.context
,
12862 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
12863 bf_set(lpfc_rq_context_rqe_size
,
12864 &rq_create
->u
.request
.context
,
12866 bf_set(lpfc_rq_context_page_size
,
12867 &rq_create
->u
.request
.context
,
12868 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12870 switch (hrq
->entry_count
) {
12872 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12873 "2535 Unsupported RQ count. (%d)\n",
12875 if (hrq
->entry_count
< 512) {
12879 /* otherwise default to smallest count (drop through) */
12881 bf_set(lpfc_rq_context_rqe_count
,
12882 &rq_create
->u
.request
.context
,
12883 LPFC_RQ_RING_SIZE_512
);
12886 bf_set(lpfc_rq_context_rqe_count
,
12887 &rq_create
->u
.request
.context
,
12888 LPFC_RQ_RING_SIZE_1024
);
12891 bf_set(lpfc_rq_context_rqe_count
,
12892 &rq_create
->u
.request
.context
,
12893 LPFC_RQ_RING_SIZE_2048
);
12896 bf_set(lpfc_rq_context_rqe_count
,
12897 &rq_create
->u
.request
.context
,
12898 LPFC_RQ_RING_SIZE_4096
);
12901 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12902 LPFC_HDR_BUF_SIZE
);
12904 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12906 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12908 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
12909 memset(dmabuf
->virt
, 0, hw_page_size
);
12910 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12911 putPaddrLow(dmabuf
->phys
);
12912 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12913 putPaddrHigh(dmabuf
->phys
);
12915 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12916 /* The IOCTL status is embedded in the mailbox subheader. */
12917 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12918 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12919 if (shdr_status
|| shdr_add_status
|| rc
) {
12920 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12921 "2504 RQ_CREATE mailbox failed with "
12922 "status x%x add_status x%x, mbx status x%x\n",
12923 shdr_status
, shdr_add_status
, rc
);
12927 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12928 if (hrq
->queue_id
== 0xFFFF) {
12932 hrq
->type
= LPFC_HRQ
;
12933 hrq
->assoc_qid
= cq
->queue_id
;
12934 hrq
->subtype
= subtype
;
12935 hrq
->host_index
= 0;
12936 hrq
->hba_index
= 0;
12938 /* now create the data queue */
12939 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12940 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12941 length
, LPFC_SLI4_MBX_EMBED
);
12942 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12943 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12944 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12945 bf_set(lpfc_rq_context_rqe_count_1
,
12946 &rq_create
->u
.request
.context
, hrq
->entry_count
);
12947 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
12948 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
12950 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
12951 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12953 switch (drq
->entry_count
) {
12955 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12956 "2536 Unsupported RQ count. (%d)\n",
12958 if (drq
->entry_count
< 512) {
12962 /* otherwise default to smallest count (drop through) */
12964 bf_set(lpfc_rq_context_rqe_count
,
12965 &rq_create
->u
.request
.context
,
12966 LPFC_RQ_RING_SIZE_512
);
12969 bf_set(lpfc_rq_context_rqe_count
,
12970 &rq_create
->u
.request
.context
,
12971 LPFC_RQ_RING_SIZE_1024
);
12974 bf_set(lpfc_rq_context_rqe_count
,
12975 &rq_create
->u
.request
.context
,
12976 LPFC_RQ_RING_SIZE_2048
);
12979 bf_set(lpfc_rq_context_rqe_count
,
12980 &rq_create
->u
.request
.context
,
12981 LPFC_RQ_RING_SIZE_4096
);
12984 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12985 LPFC_DATA_BUF_SIZE
);
12987 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12989 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12991 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
12992 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12993 putPaddrLow(dmabuf
->phys
);
12994 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12995 putPaddrHigh(dmabuf
->phys
);
12997 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12998 /* The IOCTL status is embedded in the mailbox subheader. */
12999 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13000 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13001 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13002 if (shdr_status
|| shdr_add_status
|| rc
) {
13006 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
13007 if (drq
->queue_id
== 0xFFFF) {
13011 drq
->type
= LPFC_DRQ
;
13012 drq
->assoc_qid
= cq
->queue_id
;
13013 drq
->subtype
= subtype
;
13014 drq
->host_index
= 0;
13015 drq
->hba_index
= 0;
13017 /* link the header and data RQs onto the parent cq child list */
13018 list_add_tail(&hrq
->list
, &cq
->child_list
);
13019 list_add_tail(&drq
->list
, &cq
->child_list
);
13022 mempool_free(mbox
, phba
->mbox_mem_pool
);
13027 * lpfc_eq_destroy - Destroy an event Queue on the HBA
13028 * @eq: The queue structure associated with the queue to destroy.
13030 * This function destroys a queue, as detailed in @eq by sending an mailbox
13031 * command, specific to the type of queue, to the HBA.
13033 * The @eq struct is used to get the queue ID of the queue to destroy.
13035 * On success this function will return a zero. If the queue destroy mailbox
13036 * command fails this function will return -ENXIO.
13039 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
13041 LPFC_MBOXQ_t
*mbox
;
13042 int rc
, length
, status
= 0;
13043 uint32_t shdr_status
, shdr_add_status
;
13044 union lpfc_sli4_cfg_shdr
*shdr
;
13046 /* sanity check on queue memory */
13049 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13052 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
13053 sizeof(struct lpfc_sli4_cfg_mhdr
));
13054 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13055 LPFC_MBOX_OPCODE_EQ_DESTROY
,
13056 length
, LPFC_SLI4_MBX_EMBED
);
13057 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
13059 mbox
->vport
= eq
->phba
->pport
;
13060 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13062 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
13063 /* The IOCTL status is embedded in the mailbox subheader. */
13064 shdr
= (union lpfc_sli4_cfg_shdr
*)
13065 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
13066 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13067 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13068 if (shdr_status
|| shdr_add_status
|| rc
) {
13069 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13070 "2505 EQ_DESTROY mailbox failed with "
13071 "status x%x add_status x%x, mbx status x%x\n",
13072 shdr_status
, shdr_add_status
, rc
);
13076 /* Remove eq from any list */
13077 list_del_init(&eq
->list
);
13078 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
13083 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
13084 * @cq: The queue structure associated with the queue to destroy.
13086 * This function destroys a queue, as detailed in @cq by sending an mailbox
13087 * command, specific to the type of queue, to the HBA.
13089 * The @cq struct is used to get the queue ID of the queue to destroy.
13091 * On success this function will return a zero. If the queue destroy mailbox
13092 * command fails this function will return -ENXIO.
13095 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
13097 LPFC_MBOXQ_t
*mbox
;
13098 int rc
, length
, status
= 0;
13099 uint32_t shdr_status
, shdr_add_status
;
13100 union lpfc_sli4_cfg_shdr
*shdr
;
13102 /* sanity check on queue memory */
13105 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13108 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
13109 sizeof(struct lpfc_sli4_cfg_mhdr
));
13110 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13111 LPFC_MBOX_OPCODE_CQ_DESTROY
,
13112 length
, LPFC_SLI4_MBX_EMBED
);
13113 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
13115 mbox
->vport
= cq
->phba
->pport
;
13116 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13117 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
13118 /* The IOCTL status is embedded in the mailbox subheader. */
13119 shdr
= (union lpfc_sli4_cfg_shdr
*)
13120 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
13121 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13122 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13123 if (shdr_status
|| shdr_add_status
|| rc
) {
13124 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13125 "2506 CQ_DESTROY mailbox failed with "
13126 "status x%x add_status x%x, mbx status x%x\n",
13127 shdr_status
, shdr_add_status
, rc
);
13130 /* Remove cq from any list */
13131 list_del_init(&cq
->list
);
13132 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
13137 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
13138 * @qm: The queue structure associated with the queue to destroy.
13140 * This function destroys a queue, as detailed in @mq by sending an mailbox
13141 * command, specific to the type of queue, to the HBA.
13143 * The @mq struct is used to get the queue ID of the queue to destroy.
13145 * On success this function will return a zero. If the queue destroy mailbox
13146 * command fails this function will return -ENXIO.
13149 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
13151 LPFC_MBOXQ_t
*mbox
;
13152 int rc
, length
, status
= 0;
13153 uint32_t shdr_status
, shdr_add_status
;
13154 union lpfc_sli4_cfg_shdr
*shdr
;
13156 /* sanity check on queue memory */
13159 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13162 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
13163 sizeof(struct lpfc_sli4_cfg_mhdr
));
13164 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13165 LPFC_MBOX_OPCODE_MQ_DESTROY
,
13166 length
, LPFC_SLI4_MBX_EMBED
);
13167 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
13169 mbox
->vport
= mq
->phba
->pport
;
13170 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13171 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
13172 /* The IOCTL status is embedded in the mailbox subheader. */
13173 shdr
= (union lpfc_sli4_cfg_shdr
*)
13174 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
13175 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13176 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13177 if (shdr_status
|| shdr_add_status
|| rc
) {
13178 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13179 "2507 MQ_DESTROY mailbox failed with "
13180 "status x%x add_status x%x, mbx status x%x\n",
13181 shdr_status
, shdr_add_status
, rc
);
13184 /* Remove mq from any list */
13185 list_del_init(&mq
->list
);
13186 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
13191 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
13192 * @wq: The queue structure associated with the queue to destroy.
13194 * This function destroys a queue, as detailed in @wq by sending an mailbox
13195 * command, specific to the type of queue, to the HBA.
13197 * The @wq struct is used to get the queue ID of the queue to destroy.
13199 * On success this function will return a zero. If the queue destroy mailbox
13200 * command fails this function will return -ENXIO.
13203 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
13205 LPFC_MBOXQ_t
*mbox
;
13206 int rc
, length
, status
= 0;
13207 uint32_t shdr_status
, shdr_add_status
;
13208 union lpfc_sli4_cfg_shdr
*shdr
;
13210 /* sanity check on queue memory */
13213 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13216 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
13217 sizeof(struct lpfc_sli4_cfg_mhdr
));
13218 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13219 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
13220 length
, LPFC_SLI4_MBX_EMBED
);
13221 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
13223 mbox
->vport
= wq
->phba
->pport
;
13224 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13225 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
13226 shdr
= (union lpfc_sli4_cfg_shdr
*)
13227 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
13228 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13229 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13230 if (shdr_status
|| shdr_add_status
|| rc
) {
13231 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13232 "2508 WQ_DESTROY mailbox failed with "
13233 "status x%x add_status x%x, mbx status x%x\n",
13234 shdr_status
, shdr_add_status
, rc
);
13237 /* Remove wq from any list */
13238 list_del_init(&wq
->list
);
13239 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
13244 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
13245 * @rq: The queue structure associated with the queue to destroy.
13247 * This function destroys a queue, as detailed in @rq by sending an mailbox
13248 * command, specific to the type of queue, to the HBA.
13250 * The @rq struct is used to get the queue ID of the queue to destroy.
13252 * On success this function will return a zero. If the queue destroy mailbox
13253 * command fails this function will return -ENXIO.
13256 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13257 struct lpfc_queue
*drq
)
13259 LPFC_MBOXQ_t
*mbox
;
13260 int rc
, length
, status
= 0;
13261 uint32_t shdr_status
, shdr_add_status
;
13262 union lpfc_sli4_cfg_shdr
*shdr
;
13264 /* sanity check on queue memory */
13267 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13270 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
13271 sizeof(struct lpfc_sli4_cfg_mhdr
));
13272 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13273 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
13274 length
, LPFC_SLI4_MBX_EMBED
);
13275 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13277 mbox
->vport
= hrq
->phba
->pport
;
13278 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13279 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
13280 /* The IOCTL status is embedded in the mailbox subheader. */
13281 shdr
= (union lpfc_sli4_cfg_shdr
*)
13282 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13283 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13284 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13285 if (shdr_status
|| shdr_add_status
|| rc
) {
13286 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13287 "2509 RQ_DESTROY mailbox failed with "
13288 "status x%x add_status x%x, mbx status x%x\n",
13289 shdr_status
, shdr_add_status
, rc
);
13290 if (rc
!= MBX_TIMEOUT
)
13291 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13294 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13296 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
13297 shdr
= (union lpfc_sli4_cfg_shdr
*)
13298 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13299 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13300 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13301 if (shdr_status
|| shdr_add_status
|| rc
) {
13302 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13303 "2510 RQ_DESTROY mailbox failed with "
13304 "status x%x add_status x%x, mbx status x%x\n",
13305 shdr_status
, shdr_add_status
, rc
);
13308 list_del_init(&hrq
->list
);
13309 list_del_init(&drq
->list
);
13310 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13315 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
13316 * @phba: The virtual port for which this call being executed.
13317 * @pdma_phys_addr0: Physical address of the 1st SGL page.
13318 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
13319 * @xritag: the xritag that ties this io to the SGL pages.
13321 * This routine will post the sgl pages for the IO that has the xritag
13322 * that is in the iocbq structure. The xritag is assigned during iocbq
13323 * creation and persists for as long as the driver is loaded.
13324 * if the caller has fewer than 256 scatter gather segments to map then
13325 * pdma_phys_addr1 should be 0.
13326 * If the caller needs to map more than 256 scatter gather segment then
13327 * pdma_phys_addr1 should be a valid physical address.
13328 * physical address for SGLs must be 64 byte aligned.
13329 * If you are going to map 2 SGL's then the first one must have 256 entries
13330 * the second sgl can have between 1 and 256 entries.
13334 * -ENXIO, -ENOMEM - Failure
13337 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
13338 dma_addr_t pdma_phys_addr0
,
13339 dma_addr_t pdma_phys_addr1
,
13342 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
13343 LPFC_MBOXQ_t
*mbox
;
13345 uint32_t shdr_status
, shdr_add_status
;
13347 union lpfc_sli4_cfg_shdr
*shdr
;
13349 if (xritag
== NO_XRI
) {
13350 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13351 "0364 Invalid param:\n");
13355 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13359 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13360 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13361 sizeof(struct lpfc_mbx_post_sgl_pages
) -
13362 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
13364 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
13365 &mbox
->u
.mqe
.un
.post_sgl_pages
;
13366 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
13367 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
13369 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
13370 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
13371 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
13372 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
13374 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
13375 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
13376 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
13377 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
13378 if (!phba
->sli4_hba
.intr_enable
)
13379 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13381 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13382 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13384 /* The IOCTL status is embedded in the mailbox subheader. */
13385 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
13386 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13387 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13388 if (rc
!= MBX_TIMEOUT
)
13389 mempool_free(mbox
, phba
->mbox_mem_pool
);
13390 if (shdr_status
|| shdr_add_status
|| rc
) {
13391 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13392 "2511 POST_SGL mailbox failed with "
13393 "status x%x add_status x%x, mbx status x%x\n",
13394 shdr_status
, shdr_add_status
, rc
);
13401 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13402 * @phba: pointer to lpfc hba data structure.
13404 * This routine is invoked to post rpi header templates to the
13405 * HBA consistent with the SLI-4 interface spec. This routine
13406 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13407 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13410 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13411 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13414 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13419 * Fetch the next logical xri. Because this index is logical,
13420 * the driver starts at 0 each time.
13422 spin_lock_irq(&phba
->hbalock
);
13423 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13424 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13425 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13426 spin_unlock_irq(&phba
->hbalock
);
13429 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13430 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13432 spin_unlock_irq(&phba
->hbalock
);
13437 * lpfc_sli4_free_xri - Release an xri for reuse.
13438 * @phba: pointer to lpfc hba data structure.
13440 * This routine is invoked to release an xri to the pool of
13441 * available rpis maintained by the driver.
13444 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13446 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13447 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13452 * lpfc_sli4_free_xri - Release an xri for reuse.
13453 * @phba: pointer to lpfc hba data structure.
13455 * This routine is invoked to release an xri to the pool of
13456 * available rpis maintained by the driver.
13459 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13461 spin_lock_irq(&phba
->hbalock
);
13462 __lpfc_sli4_free_xri(phba
, xri
);
13463 spin_unlock_irq(&phba
->hbalock
);
13467 * lpfc_sli4_next_xritag - Get an xritag for the io
13468 * @phba: Pointer to HBA context object.
13470 * This function gets an xritag for the iocb. If there is no unused xritag
13471 * it will return 0xffff.
13472 * The function returns the allocated xritag if successful, else returns zero.
13473 * Zero is not a valid xritag.
13474 * The caller is not required to hold any lock.
13477 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13479 uint16_t xri_index
;
13481 xri_index
= lpfc_sli4_alloc_xri(phba
);
13482 if (xri_index
== NO_XRI
)
13483 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13484 "2004 Failed to allocate XRI.last XRITAG is %d"
13485 " Max XRI is %d, Used XRI is %d\n",
13487 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13488 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13493 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13494 * @phba: pointer to lpfc hba data structure.
13495 * @post_sgl_list: pointer to els sgl entry list.
13496 * @count: number of els sgl entries on the list.
13498 * This routine is invoked to post a block of driver's sgl pages to the
13499 * HBA using non-embedded mailbox command. No Lock is held. This routine
13500 * is only called when the driver is loading and after all IO has been
13504 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
13505 struct list_head
*post_sgl_list
,
13508 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
13509 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13510 struct sgl_page_pairs
*sgl_pg_pairs
;
13512 LPFC_MBOXQ_t
*mbox
;
13513 uint32_t reqlen
, alloclen
, pg_pairs
;
13515 uint16_t xritag_start
= 0;
13517 uint32_t shdr_status
, shdr_add_status
;
13518 union lpfc_sli4_cfg_shdr
*shdr
;
13520 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13521 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13522 if (reqlen
> SLI4_PAGE_SIZE
) {
13523 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13524 "2559 Block sgl registration required DMA "
13525 "size (%d) great than a page\n", reqlen
);
13528 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13532 /* Allocate DMA memory and set up the non-embedded mailbox command */
13533 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13534 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13535 LPFC_SLI4_MBX_NEMBED
);
13537 if (alloclen
< reqlen
) {
13538 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13539 "0285 Allocated DMA memory size (%d) is "
13540 "less than the requested DMA memory "
13541 "size (%d)\n", alloclen
, reqlen
);
13542 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13545 /* Set up the SGL pages in the non-embedded DMA pages */
13546 viraddr
= mbox
->sge_array
->addr
[0];
13547 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13548 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13551 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
13552 /* Set up the sge entry */
13553 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13554 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13555 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13556 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13557 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13558 cpu_to_le32(putPaddrLow(0));
13559 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13560 cpu_to_le32(putPaddrHigh(0));
13562 /* Keep the first xritag on the list */
13564 xritag_start
= sglq_entry
->sli4_xritag
;
13569 /* Complete initialization and perform endian conversion. */
13570 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13571 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
13572 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13573 if (!phba
->sli4_hba
.intr_enable
)
13574 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13576 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13577 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13579 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13580 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13581 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13582 if (rc
!= MBX_TIMEOUT
)
13583 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13584 if (shdr_status
|| shdr_add_status
|| rc
) {
13585 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13586 "2513 POST_SGL_BLOCK mailbox command failed "
13587 "status x%x add_status x%x mbx status x%x\n",
13588 shdr_status
, shdr_add_status
, rc
);
13595 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13596 * @phba: pointer to lpfc hba data structure.
13597 * @sblist: pointer to scsi buffer list.
13598 * @count: number of scsi buffers on the list.
13600 * This routine is invoked to post a block of @count scsi sgl pages from a
13601 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13606 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
13607 struct list_head
*sblist
,
13610 struct lpfc_scsi_buf
*psb
;
13611 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13612 struct sgl_page_pairs
*sgl_pg_pairs
;
13614 LPFC_MBOXQ_t
*mbox
;
13615 uint32_t reqlen
, alloclen
, pg_pairs
;
13617 uint16_t xritag_start
= 0;
13619 uint32_t shdr_status
, shdr_add_status
;
13620 dma_addr_t pdma_phys_bpl1
;
13621 union lpfc_sli4_cfg_shdr
*shdr
;
13623 /* Calculate the requested length of the dma memory */
13624 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
13625 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13626 if (reqlen
> SLI4_PAGE_SIZE
) {
13627 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13628 "0217 Block sgl registration required DMA "
13629 "size (%d) great than a page\n", reqlen
);
13632 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13634 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13635 "0283 Failed to allocate mbox cmd memory\n");
13639 /* Allocate DMA memory and set up the non-embedded mailbox command */
13640 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13641 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13642 LPFC_SLI4_MBX_NEMBED
);
13644 if (alloclen
< reqlen
) {
13645 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13646 "2561 Allocated DMA memory size (%d) is "
13647 "less than the requested DMA memory "
13648 "size (%d)\n", alloclen
, reqlen
);
13649 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13653 /* Get the first SGE entry from the non-embedded DMA memory */
13654 viraddr
= mbox
->sge_array
->addr
[0];
13656 /* Set up the SGL pages in the non-embedded DMA pages */
13657 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13658 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13661 list_for_each_entry(psb
, sblist
, list
) {
13662 /* Set up the sge entry */
13663 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13664 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13665 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13666 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13667 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13668 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
13670 pdma_phys_bpl1
= 0;
13671 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13672 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13673 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13674 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13675 /* Keep the first xritag on the list */
13677 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
13681 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13682 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13683 /* Perform endian conversion if necessary */
13684 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13686 if (!phba
->sli4_hba
.intr_enable
)
13687 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13689 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13690 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13692 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13693 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13694 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13695 if (rc
!= MBX_TIMEOUT
)
13696 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13697 if (shdr_status
|| shdr_add_status
|| rc
) {
13698 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13699 "2564 POST_SGL_BLOCK mailbox command failed "
13700 "status x%x add_status x%x mbx status x%x\n",
13701 shdr_status
, shdr_add_status
, rc
);
13708 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13709 * @phba: pointer to lpfc_hba struct that the frame was received on
13710 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13712 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13713 * valid type of frame that the LPFC driver will handle. This function will
13714 * return a zero if the frame is a valid frame or a non zero value when the
13715 * frame does not pass the check.
13718 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
13720 /* make rctl_names static to save stack space */
13721 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
13722 char *type_names
[] = FC_TYPE_NAMES_INIT
;
13723 struct fc_vft_header
*fc_vft_hdr
;
13724 uint32_t *header
= (uint32_t *) fc_hdr
;
13726 switch (fc_hdr
->fh_r_ctl
) {
13727 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
13728 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
13729 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
13730 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
13731 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
13732 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
13733 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
13734 case FC_RCTL_DD_CMD_STATUS
: /* command status */
13735 case FC_RCTL_ELS_REQ
: /* extended link services request */
13736 case FC_RCTL_ELS_REP
: /* extended link services reply */
13737 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
13738 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
13739 case FC_RCTL_BA_NOP
: /* basic link service NOP */
13740 case FC_RCTL_BA_ABTS
: /* basic link service abort */
13741 case FC_RCTL_BA_RMC
: /* remove connection */
13742 case FC_RCTL_BA_ACC
: /* basic accept */
13743 case FC_RCTL_BA_RJT
: /* basic reject */
13744 case FC_RCTL_BA_PRMT
:
13745 case FC_RCTL_ACK_1
: /* acknowledge_1 */
13746 case FC_RCTL_ACK_0
: /* acknowledge_0 */
13747 case FC_RCTL_P_RJT
: /* port reject */
13748 case FC_RCTL_F_RJT
: /* fabric reject */
13749 case FC_RCTL_P_BSY
: /* port busy */
13750 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
13751 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
13752 case FC_RCTL_LCR
: /* link credit reset */
13753 case FC_RCTL_END
: /* end */
13755 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
13756 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13757 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
13758 return lpfc_fc_frame_check(phba
, fc_hdr
);
13762 switch (fc_hdr
->fh_type
) {
13774 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
13775 "2538 Received frame rctl:%s type:%s "
13776 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13777 rctl_names
[fc_hdr
->fh_r_ctl
],
13778 type_names
[fc_hdr
->fh_type
],
13779 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
13780 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
13781 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]));
13784 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13785 "2539 Dropped frame rctl:%s type:%s\n",
13786 rctl_names
[fc_hdr
->fh_r_ctl
],
13787 type_names
[fc_hdr
->fh_type
]);
13792 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13793 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13795 * This function processes the FC header to retrieve the VFI from the VF
13796 * header, if one exists. This function will return the VFI if one exists
13797 * or 0 if no VSAN Header exists.
13800 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
13802 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13804 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
13806 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
13810 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13811 * @phba: Pointer to the HBA structure to search for the vport on
13812 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13813 * @fcfi: The FC Fabric ID that the frame came from
13815 * This function searches the @phba for a vport that matches the content of the
13816 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13817 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13818 * returns the matching vport pointer or NULL if unable to match frame to a
13821 static struct lpfc_vport
*
13822 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
13825 struct lpfc_vport
**vports
;
13826 struct lpfc_vport
*vport
= NULL
;
13828 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
13829 fc_hdr
->fh_d_id
[1] << 8 |
13830 fc_hdr
->fh_d_id
[2]);
13832 if (did
== Fabric_DID
)
13833 return phba
->pport
;
13834 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
13835 !(phba
->link_state
== LPFC_HBA_READY
))
13836 return phba
->pport
;
13838 vports
= lpfc_create_vport_work_array(phba
);
13839 if (vports
!= NULL
)
13840 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
13841 if (phba
->fcf
.fcfi
== fcfi
&&
13842 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
13843 vports
[i
]->fc_myDID
== did
) {
13848 lpfc_destroy_vport_work_array(phba
, vports
);
13853 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13854 * @vport: The vport to work on.
13856 * This function updates the receive sequence time stamp for this vport. The
13857 * receive sequence time stamp indicates the time that the last frame of the
13858 * the sequence that has been idle for the longest amount of time was received.
13859 * the driver uses this time stamp to indicate if any received sequences have
13863 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
13865 struct lpfc_dmabuf
*h_buf
;
13866 struct hbq_dmabuf
*dmabuf
= NULL
;
13868 /* get the oldest sequence on the rcv list */
13869 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
13870 struct lpfc_dmabuf
, list
);
13873 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13874 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
13878 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13879 * @vport: The vport that the received sequences were sent to.
13881 * This function cleans up all outstanding received sequences. This is called
13882 * by the driver when a link event or user action invalidates all the received
13886 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
13888 struct lpfc_dmabuf
*h_buf
, *hnext
;
13889 struct lpfc_dmabuf
*d_buf
, *dnext
;
13890 struct hbq_dmabuf
*dmabuf
= NULL
;
13892 /* start with the oldest sequence on the rcv list */
13893 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13894 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13895 list_del_init(&dmabuf
->hbuf
.list
);
13896 list_for_each_entry_safe(d_buf
, dnext
,
13897 &dmabuf
->dbuf
.list
, list
) {
13898 list_del_init(&d_buf
->list
);
13899 lpfc_in_buf_free(vport
->phba
, d_buf
);
13901 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13906 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13907 * @vport: The vport that the received sequences were sent to.
13909 * This function determines whether any received sequences have timed out by
13910 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13911 * indicates that there is at least one timed out sequence this routine will
13912 * go through the received sequences one at a time from most inactive to most
13913 * active to determine which ones need to be cleaned up. Once it has determined
13914 * that a sequence needs to be cleaned up it will simply free up the resources
13915 * without sending an abort.
13918 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
13920 struct lpfc_dmabuf
*h_buf
, *hnext
;
13921 struct lpfc_dmabuf
*d_buf
, *dnext
;
13922 struct hbq_dmabuf
*dmabuf
= NULL
;
13923 unsigned long timeout
;
13924 int abort_count
= 0;
13926 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13927 vport
->rcv_buffer_time_stamp
);
13928 if (list_empty(&vport
->rcv_buffer_list
) ||
13929 time_before(jiffies
, timeout
))
13931 /* start with the oldest sequence on the rcv list */
13932 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13933 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13934 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13935 dmabuf
->time_stamp
);
13936 if (time_before(jiffies
, timeout
))
13939 list_del_init(&dmabuf
->hbuf
.list
);
13940 list_for_each_entry_safe(d_buf
, dnext
,
13941 &dmabuf
->dbuf
.list
, list
) {
13942 list_del_init(&d_buf
->list
);
13943 lpfc_in_buf_free(vport
->phba
, d_buf
);
13945 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13948 lpfc_update_rcv_time_stamp(vport
);
13952 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13953 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13955 * This function searches through the existing incomplete sequences that have
13956 * been sent to this @vport. If the frame matches one of the incomplete
13957 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13958 * make up that sequence. If no sequence is found that matches this frame then
13959 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13960 * This function returns a pointer to the first dmabuf in the sequence list that
13961 * the frame was linked to.
13963 static struct hbq_dmabuf
*
13964 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
13966 struct fc_frame_header
*new_hdr
;
13967 struct fc_frame_header
*temp_hdr
;
13968 struct lpfc_dmabuf
*d_buf
;
13969 struct lpfc_dmabuf
*h_buf
;
13970 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13971 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
13973 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13974 dmabuf
->time_stamp
= jiffies
;
13975 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13976 /* Use the hdr_buf to find the sequence that this frame belongs to */
13977 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13978 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13979 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13980 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13981 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13983 /* found a pending sequence that matches this frame */
13984 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13989 * This indicates first frame received for this sequence.
13990 * Queue the buffer on the vport's rcv_buffer_list.
13992 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13993 lpfc_update_rcv_time_stamp(vport
);
13996 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
13997 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
13998 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13999 list_del_init(&seq_dmabuf
->hbuf
.list
);
14000 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14001 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14002 lpfc_update_rcv_time_stamp(vport
);
14005 /* move this sequence to the tail to indicate a young sequence */
14006 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14007 seq_dmabuf
->time_stamp
= jiffies
;
14008 lpfc_update_rcv_time_stamp(vport
);
14009 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
14010 temp_hdr
= dmabuf
->hbuf
.virt
;
14011 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14014 /* find the correct place in the sequence to insert this frame */
14015 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14016 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14017 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
14019 * If the frame's sequence count is greater than the frame on
14020 * the list then insert the frame right after this frame
14022 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
14023 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14024 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
14032 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
14033 * @vport: pointer to a vitural port
14034 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14036 * This function tries to abort from the partially assembed sequence, described
14037 * by the information from basic abbort @dmabuf. It checks to see whether such
14038 * partially assembled sequence held by the driver. If so, it shall free up all
14039 * the frames from the partially assembled sequence.
14042 * true -- if there is matching partially assembled sequence present and all
14043 * the frames freed with the sequence;
14044 * false -- if there is no matching partially assembled sequence present so
14045 * nothing got aborted in the lower layer driver
14048 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
14049 struct hbq_dmabuf
*dmabuf
)
14051 struct fc_frame_header
*new_hdr
;
14052 struct fc_frame_header
*temp_hdr
;
14053 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
14054 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14056 /* Use the hdr_buf to find the sequence that matches this frame */
14057 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14058 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
14059 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14060 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14061 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14062 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14063 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14064 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14066 /* found a pending sequence that matches this frame */
14067 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14071 /* Free up all the frames from the partially assembled sequence */
14073 list_for_each_entry_safe(d_buf
, n_buf
,
14074 &seq_dmabuf
->dbuf
.list
, list
) {
14075 list_del_init(&d_buf
->list
);
14076 lpfc_in_buf_free(vport
->phba
, d_buf
);
14084 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14085 * @phba: Pointer to HBA context object.
14086 * @cmd_iocbq: pointer to the command iocbq structure.
14087 * @rsp_iocbq: pointer to the response iocbq structure.
14089 * This function handles the sequence abort response iocb command complete
14090 * event. It properly releases the memory allocated to the sequence abort
14094 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
14095 struct lpfc_iocbq
*cmd_iocbq
,
14096 struct lpfc_iocbq
*rsp_iocbq
)
14099 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
14101 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14102 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
14103 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14104 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14105 rsp_iocbq
->iocb
.ulpStatus
,
14106 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
14110 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14111 * @phba: Pointer to HBA context object.
14112 * @xri: xri id in transaction.
14114 * This function validates the xri maps to the known range of XRIs allocated an
14115 * used by the driver.
14118 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
14123 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
14124 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
14131 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14132 * @phba: Pointer to HBA context object.
14133 * @fc_hdr: pointer to a FC frame header.
14135 * This function sends a basic response to a previous unsol sequence abort
14136 * event after aborting the sequence handling.
14139 lpfc_sli4_seq_abort_rsp(struct lpfc_hba
*phba
,
14140 struct fc_frame_header
*fc_hdr
)
14142 struct lpfc_iocbq
*ctiocb
= NULL
;
14143 struct lpfc_nodelist
*ndlp
;
14144 uint16_t oxid
, rxid
, xri
, lxri
;
14145 uint32_t sid
, fctl
;
14149 if (!lpfc_is_link_up(phba
))
14152 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14153 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
14154 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
14156 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
14158 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14159 "1268 Find ndlp returned NULL for oxid:x%x "
14160 "SID:x%x\n", oxid
, sid
);
14164 /* Allocate buffer for rsp iocb */
14165 ctiocb
= lpfc_sli_get_iocbq(phba
);
14169 /* Extract the F_CTL field from FC_HDR */
14170 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
14172 icmd
= &ctiocb
->iocb
;
14173 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
14174 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
14175 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
14176 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
14177 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
14179 /* Fill in the rest of iocb fields */
14180 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
14181 icmd
->ulpBdeCount
= 0;
14183 icmd
->ulpClass
= CLASS3
;
14184 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
14185 ctiocb
->context1
= ndlp
;
14187 ctiocb
->iocb_cmpl
= NULL
;
14188 ctiocb
->vport
= phba
->pport
;
14189 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
14190 ctiocb
->sli4_lxritag
= NO_XRI
;
14191 ctiocb
->sli4_xritag
= NO_XRI
;
14193 if (fctl
& FC_FC_EX_CTX
)
14194 /* Exchange responder sent the abort so we
14200 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
14201 if (lxri
!= NO_XRI
)
14202 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
14203 (xri
== oxid
) ? rxid
: oxid
, 0);
14204 /* If the oxid maps to the FCP XRI range or if it is out of range,
14205 * send a BLS_RJT. The driver no longer has that exchange.
14206 * Override the IOCB for a BA_RJT.
14208 if (xri
> (phba
->sli4_hba
.max_cfg_param
.max_xri
+
14209 phba
->sli4_hba
.max_cfg_param
.xri_base
) ||
14210 xri
> (lpfc_sli4_get_els_iocb_cnt(phba
) +
14211 phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
14212 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14213 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14214 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14215 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14218 if (fctl
& FC_FC_EX_CTX
) {
14219 /* ABTS sent by responder to CT exchange, construction
14220 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14221 * field and RX_ID from ABTS for RX_ID field.
14223 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14225 /* ABTS sent by initiator to CT exchange, construction
14226 * of BA_ACC will need to allocate a new XRI as for the
14229 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14231 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14232 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14234 /* Xmit CT abts response on exchange <xid> */
14235 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14236 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14237 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14239 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14240 if (rc
== IOCB_ERROR
) {
14241 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
14242 "2925 Failed to issue CT ABTS RSP x%x on "
14243 "xri x%x, Data x%x\n",
14244 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14246 lpfc_sli_release_iocbq(phba
, ctiocb
);
14251 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14252 * @vport: Pointer to the vport on which this sequence was received
14253 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14255 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14256 * receive sequence is only partially assembed by the driver, it shall abort
14257 * the partially assembled frames for the sequence. Otherwise, if the
14258 * unsolicited receive sequence has been completely assembled and passed to
14259 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14260 * unsolicited sequence has been aborted. After that, it will issue a basic
14261 * accept to accept the abort.
14264 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14265 struct hbq_dmabuf
*dmabuf
)
14267 struct lpfc_hba
*phba
= vport
->phba
;
14268 struct fc_frame_header fc_hdr
;
14272 /* Make a copy of fc_hdr before the dmabuf being released */
14273 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14274 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14276 if (fctl
& FC_FC_EX_CTX
) {
14278 * ABTS sent by responder to exchange, just free the buffer
14280 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14283 * ABTS sent by initiator to exchange, need to do cleanup
14285 /* Try to abort partially assembled seq */
14286 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14288 /* Send abort to ULP if partially seq abort failed */
14289 if (abts_par
== false)
14290 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
14292 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14294 /* Send basic accept (BA_ACC) to the abort requester */
14295 lpfc_sli4_seq_abort_rsp(phba
, &fc_hdr
);
14299 * lpfc_seq_complete - Indicates if a sequence is complete
14300 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14302 * This function checks the sequence, starting with the frame described by
14303 * @dmabuf, to see if all the frames associated with this sequence are present.
14304 * the frames associated with this sequence are linked to the @dmabuf using the
14305 * dbuf list. This function looks for two major things. 1) That the first frame
14306 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14307 * set. 3) That there are no holes in the sequence count. The function will
14308 * return 1 when the sequence is complete, otherwise it will return 0.
14311 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14313 struct fc_frame_header
*hdr
;
14314 struct lpfc_dmabuf
*d_buf
;
14315 struct hbq_dmabuf
*seq_dmabuf
;
14319 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14320 /* make sure first fame of sequence has a sequence count of zero */
14321 if (hdr
->fh_seq_cnt
!= seq_count
)
14323 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14324 hdr
->fh_f_ctl
[1] << 8 |
14326 /* If last frame of sequence we can return success. */
14327 if (fctl
& FC_FC_END_SEQ
)
14329 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14330 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14331 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14332 /* If there is a hole in the sequence count then fail. */
14333 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14335 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14336 hdr
->fh_f_ctl
[1] << 8 |
14338 /* If last frame of sequence we can return success. */
14339 if (fctl
& FC_FC_END_SEQ
)
14346 * lpfc_prep_seq - Prep sequence for ULP processing
14347 * @vport: Pointer to the vport on which this sequence was received
14348 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14350 * This function takes a sequence, described by a list of frames, and creates
14351 * a list of iocbq structures to describe the sequence. This iocbq list will be
14352 * used to issue to the generic unsolicited sequence handler. This routine
14353 * returns a pointer to the first iocbq in the list. If the function is unable
14354 * to allocate an iocbq then it throw out the received frames that were not
14355 * able to be described and return a pointer to the first iocbq. If unable to
14356 * allocate any iocbqs (including the first) this function will return NULL.
14358 static struct lpfc_iocbq
*
14359 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14361 struct hbq_dmabuf
*hbq_buf
;
14362 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14363 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14364 struct fc_frame_header
*fc_hdr
;
14366 uint32_t len
, tot_len
;
14367 struct ulp_bde64
*pbde
;
14369 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14370 /* remove from receive buffer list */
14371 list_del_init(&seq_dmabuf
->hbuf
.list
);
14372 lpfc_update_rcv_time_stamp(vport
);
14373 /* get the Remote Port's SID */
14374 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14376 /* Get an iocbq struct to fill in. */
14377 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14379 /* Initialize the first IOCB. */
14380 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14381 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14383 /* Check FC Header to see what TYPE of frame we are rcv'ing */
14384 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
14385 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
14386 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
14387 sli4_did_from_fc_hdr(fc_hdr
);
14388 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
14390 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14391 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14392 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14393 be16_to_cpu(fc_hdr
->fh_ox_id
);
14394 /* iocbq is prepped for internal consumption. Physical vpi. */
14395 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14396 vport
->phba
->vpi_ids
[vport
->vpi
];
14397 /* put the first buffer into the first IOCBq */
14398 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14399 first_iocbq
->context3
= NULL
;
14400 first_iocbq
->iocb
.ulpBdeCount
= 1;
14401 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14402 LPFC_DATA_BUF_SIZE
;
14403 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14404 tot_len
= bf_get(lpfc_rcqe_length
,
14405 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14406 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14408 iocbq
= first_iocbq
;
14410 * Each IOCBq can have two Buffers assigned, so go through the list
14411 * of buffers for this sequence and save two buffers in each IOCBq
14413 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14415 lpfc_in_buf_free(vport
->phba
, d_buf
);
14418 if (!iocbq
->context3
) {
14419 iocbq
->context3
= d_buf
;
14420 iocbq
->iocb
.ulpBdeCount
++;
14421 pbde
= (struct ulp_bde64
*)
14422 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14423 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14425 /* We need to get the size out of the right CQE */
14426 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14427 len
= bf_get(lpfc_rcqe_length
,
14428 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14429 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14432 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14435 first_iocbq
->iocb
.ulpStatus
=
14436 IOSTAT_FCP_RSP_ERROR
;
14437 first_iocbq
->iocb
.un
.ulpWord
[4] =
14438 IOERR_NO_RESOURCES
;
14440 lpfc_in_buf_free(vport
->phba
, d_buf
);
14443 iocbq
->context2
= d_buf
;
14444 iocbq
->context3
= NULL
;
14445 iocbq
->iocb
.ulpBdeCount
= 1;
14446 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14447 LPFC_DATA_BUF_SIZE
;
14449 /* We need to get the size out of the right CQE */
14450 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14451 len
= bf_get(lpfc_rcqe_length
,
14452 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14454 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14456 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14457 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14460 return first_iocbq
;
14464 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14465 struct hbq_dmabuf
*seq_dmabuf
)
14467 struct fc_frame_header
*fc_hdr
;
14468 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
14469 struct lpfc_hba
*phba
= vport
->phba
;
14471 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14472 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
14474 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14475 "2707 Ring %d handler: Failed to allocate "
14476 "iocb Rctl x%x Type x%x received\n",
14478 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14481 if (!lpfc_complete_unsol_iocb(phba
,
14482 &phba
->sli
.ring
[LPFC_ELS_RING
],
14483 iocbq
, fc_hdr
->fh_r_ctl
,
14485 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14486 "2540 Ring %d handler: unexpected Rctl "
14487 "x%x Type x%x received\n",
14489 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14491 /* Free iocb created in lpfc_prep_seq */
14492 list_for_each_entry_safe(curr_iocb
, next_iocb
,
14493 &iocbq
->list
, list
) {
14494 list_del_init(&curr_iocb
->list
);
14495 lpfc_sli_release_iocbq(phba
, curr_iocb
);
14497 lpfc_sli_release_iocbq(phba
, iocbq
);
14501 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14502 * @phba: Pointer to HBA context object.
14504 * This function is called with no lock held. This function processes all
14505 * the received buffers and gives it to upper layers when a received buffer
14506 * indicates that it is the final frame in the sequence. The interrupt
14507 * service routine processes received buffers at interrupt contexts and adds
14508 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14509 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14510 * appropriate receive function when the final frame in a sequence is received.
14513 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
14514 struct hbq_dmabuf
*dmabuf
)
14516 struct hbq_dmabuf
*seq_dmabuf
;
14517 struct fc_frame_header
*fc_hdr
;
14518 struct lpfc_vport
*vport
;
14522 /* Process each received buffer */
14523 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14524 /* check to see if this a valid type of frame */
14525 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
14526 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14529 if ((bf_get(lpfc_cqe_code
,
14530 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
14531 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
14532 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14534 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
14535 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14537 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
14539 /* throw out the frame */
14540 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14544 /* d_id this frame is directed to */
14545 did
= sli4_did_from_fc_hdr(fc_hdr
);
14547 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
14548 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
14549 (did
!= Fabric_DID
)) {
14551 * Throw out the frame if we are not pt2pt.
14552 * The pt2pt protocol allows for discovery frames
14553 * to be received without a registered VPI.
14555 if (!(vport
->fc_flag
& FC_PT2PT
) ||
14556 (phba
->link_state
== LPFC_HBA_READY
)) {
14557 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14562 /* Handle the basic abort sequence (BA_ABTS) event */
14563 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
14564 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
14568 /* Link this frame */
14569 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
14571 /* unable to add frame to vport - throw it out */
14572 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14575 /* If not last frame in sequence continue processing frames. */
14576 if (!lpfc_seq_complete(seq_dmabuf
))
14579 /* Send the complete sequence to the upper layer protocol */
14580 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
14584 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14585 * @phba: pointer to lpfc hba data structure.
14587 * This routine is invoked to post rpi header templates to the
14588 * HBA consistent with the SLI-4 interface spec. This routine
14589 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14590 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14592 * This routine does not require any locks. It's usage is expected
14593 * to be driver load or reset recovery when the driver is
14598 * -EIO - The mailbox failed to complete successfully.
14599 * When this error occurs, the driver is not guaranteed
14600 * to have any rpi regions posted to the device and
14601 * must either attempt to repost the regions or take a
14605 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
14607 struct lpfc_rpi_hdr
*rpi_page
;
14611 /* SLI4 ports that support extents do not require RPI headers. */
14612 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14614 if (phba
->sli4_hba
.extents_in_use
)
14617 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
14619 * Assign the rpi headers a physical rpi only if the driver
14620 * has not initialized those resources. A port reset only
14621 * needs the headers posted.
14623 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
14625 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14627 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
14628 if (rc
!= MBX_SUCCESS
) {
14629 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14630 "2008 Error %d posting all rpi "
14638 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
14639 LPFC_RPI_RSRC_RDY
);
14644 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14645 * @phba: pointer to lpfc hba data structure.
14646 * @rpi_page: pointer to the rpi memory region.
14648 * This routine is invoked to post a single rpi header to the
14649 * HBA consistent with the SLI-4 interface spec. This memory region
14650 * maps up to 64 rpi context regions.
14654 * -ENOMEM - No available memory
14655 * -EIO - The mailbox failed to complete successfully.
14658 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
14660 LPFC_MBOXQ_t
*mboxq
;
14661 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
14663 uint32_t shdr_status
, shdr_add_status
;
14664 union lpfc_sli4_cfg_shdr
*shdr
;
14666 /* SLI4 ports that support extents do not require RPI headers. */
14667 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14669 if (phba
->sli4_hba
.extents_in_use
)
14672 /* The port is notified of the header region via a mailbox command. */
14673 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14675 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14676 "2001 Unable to allocate memory for issuing "
14677 "SLI_CONFIG_SPECIAL mailbox command\n");
14681 /* Post all rpi memory regions to the port. */
14682 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
14683 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14684 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
14685 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
14686 sizeof(struct lpfc_sli4_cfg_mhdr
),
14687 LPFC_SLI4_MBX_EMBED
);
14690 /* Post the physical rpi to the port for this rpi header. */
14691 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
14692 rpi_page
->start_rpi
);
14693 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
14694 hdr_tmpl
, rpi_page
->page_count
);
14696 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
14697 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
14698 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
14699 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
14700 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14701 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14702 if (rc
!= MBX_TIMEOUT
)
14703 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14704 if (shdr_status
|| shdr_add_status
|| rc
) {
14705 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14706 "2514 POST_RPI_HDR mailbox failed with "
14707 "status x%x add_status x%x, mbx status x%x\n",
14708 shdr_status
, shdr_add_status
, rc
);
14715 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14716 * @phba: pointer to lpfc hba data structure.
14718 * This routine is invoked to post rpi header templates to the
14719 * HBA consistent with the SLI-4 interface spec. This routine
14720 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14721 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14724 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14725 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14728 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
14731 uint16_t max_rpi
, rpi_limit
;
14732 uint16_t rpi_remaining
, lrpi
= 0;
14733 struct lpfc_rpi_hdr
*rpi_hdr
;
14735 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
14736 rpi_limit
= phba
->sli4_hba
.next_rpi
;
14739 * Fetch the next logical rpi. Because this index is logical,
14740 * the driver starts at 0 each time.
14742 spin_lock_irq(&phba
->hbalock
);
14743 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
14744 if (rpi
>= rpi_limit
)
14745 rpi
= LPFC_RPI_ALLOC_ERROR
;
14747 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
14748 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
14749 phba
->sli4_hba
.rpi_count
++;
14753 * Don't try to allocate more rpi header regions if the device limit
14754 * has been exhausted.
14756 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
14757 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
14758 spin_unlock_irq(&phba
->hbalock
);
14763 * RPI header postings are not required for SLI4 ports capable of
14766 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
14767 spin_unlock_irq(&phba
->hbalock
);
14772 * If the driver is running low on rpi resources, allocate another
14773 * page now. Note that the next_rpi value is used because
14774 * it represents how many are actually in use whereas max_rpi notes
14775 * how many are supported max by the device.
14777 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
14778 spin_unlock_irq(&phba
->hbalock
);
14779 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
14780 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
14782 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14783 "2002 Error Could not grow rpi "
14786 lrpi
= rpi_hdr
->start_rpi
;
14787 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14788 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
14796 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14797 * @phba: pointer to lpfc hba data structure.
14799 * This routine is invoked to release an rpi to the pool of
14800 * available rpis maintained by the driver.
14803 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14805 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
14806 phba
->sli4_hba
.rpi_count
--;
14807 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
14812 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14813 * @phba: pointer to lpfc hba data structure.
14815 * This routine is invoked to release an rpi to the pool of
14816 * available rpis maintained by the driver.
14819 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14821 spin_lock_irq(&phba
->hbalock
);
14822 __lpfc_sli4_free_rpi(phba
, rpi
);
14823 spin_unlock_irq(&phba
->hbalock
);
14827 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14828 * @phba: pointer to lpfc hba data structure.
14830 * This routine is invoked to remove the memory region that
14831 * provided rpi via a bitmask.
14834 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
14836 kfree(phba
->sli4_hba
.rpi_bmask
);
14837 kfree(phba
->sli4_hba
.rpi_ids
);
14838 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
14842 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14843 * @phba: pointer to lpfc hba data structure.
14845 * This routine is invoked to remove the memory region that
14846 * provided rpi via a bitmask.
14849 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
14850 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
14852 LPFC_MBOXQ_t
*mboxq
;
14853 struct lpfc_hba
*phba
= ndlp
->phba
;
14856 /* The port is notified of the header region via a mailbox command. */
14857 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14861 /* Post all rpi memory regions to the port. */
14862 lpfc_resume_rpi(mboxq
, ndlp
);
14864 mboxq
->mbox_cmpl
= cmpl
;
14865 mboxq
->context1
= arg
;
14866 mboxq
->context2
= ndlp
;
14868 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14869 mboxq
->vport
= ndlp
->vport
;
14870 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14871 if (rc
== MBX_NOT_FINISHED
) {
14872 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14873 "2010 Resume RPI Mailbox failed "
14874 "status %d, mbxStatus x%x\n", rc
,
14875 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14876 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14883 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14884 * @vport: Pointer to the vport for which the vpi is being initialized
14886 * This routine is invoked to activate a vpi with the port.
14890 * -Evalue otherwise
14893 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
14895 LPFC_MBOXQ_t
*mboxq
;
14897 int retval
= MBX_SUCCESS
;
14899 struct lpfc_hba
*phba
= vport
->phba
;
14900 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14903 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
14904 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
14905 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
14906 if (rc
!= MBX_SUCCESS
) {
14907 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
14908 "2022 INIT VPI Mailbox failed "
14909 "status %d, mbxStatus x%x\n", rc
,
14910 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14913 if (rc
!= MBX_TIMEOUT
)
14914 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
14920 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14921 * @phba: pointer to lpfc hba data structure.
14922 * @mboxq: Pointer to mailbox object.
14924 * This routine is invoked to manually add a single FCF record. The caller
14925 * must pass a completely initialized FCF_Record. This routine takes
14926 * care of the nonembedded mailbox operations.
14929 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
14932 union lpfc_sli4_cfg_shdr
*shdr
;
14933 uint32_t shdr_status
, shdr_add_status
;
14935 virt_addr
= mboxq
->sge_array
->addr
[0];
14936 /* The IOCTL status is embedded in the mailbox subheader. */
14937 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
14938 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14939 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14941 if ((shdr_status
|| shdr_add_status
) &&
14942 (shdr_status
!= STATUS_FCF_IN_USE
))
14943 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14944 "2558 ADD_FCF_RECORD mailbox failed with "
14945 "status x%x add_status x%x\n",
14946 shdr_status
, shdr_add_status
);
14948 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14952 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14953 * @phba: pointer to lpfc hba data structure.
14954 * @fcf_record: pointer to the initialized fcf record to add.
14956 * This routine is invoked to manually add a single FCF record. The caller
14957 * must pass a completely initialized FCF_Record. This routine takes
14958 * care of the nonembedded mailbox operations.
14961 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
14964 LPFC_MBOXQ_t
*mboxq
;
14967 dma_addr_t phys_addr
;
14968 struct lpfc_mbx_sge sge
;
14969 uint32_t alloc_len
, req_len
;
14972 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14974 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14975 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14979 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
14982 /* Allocate DMA memory and set up the non-embedded mailbox command */
14983 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14984 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
14985 req_len
, LPFC_SLI4_MBX_NEMBED
);
14986 if (alloc_len
< req_len
) {
14987 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14988 "2523 Allocated DMA memory size (x%x) is "
14989 "less than the requested DMA memory "
14990 "size (x%x)\n", alloc_len
, req_len
);
14991 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14996 * Get the first SGE entry from the non-embedded DMA memory. This
14997 * routine only uses a single SGE.
14999 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
15000 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
15001 virt_addr
= mboxq
->sge_array
->addr
[0];
15003 * Configure the FCF record for FCFI 0. This is the driver's
15004 * hardcoded default and gets used in nonFIP mode.
15006 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
15007 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
15008 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
15011 * Copy the fcf_index and the FCF Record Data. The data starts after
15012 * the FCoE header plus word10. The data copy needs to be endian
15015 bytep
+= sizeof(uint32_t);
15016 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
15017 mboxq
->vport
= phba
->pport
;
15018 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
15019 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15020 if (rc
== MBX_NOT_FINISHED
) {
15021 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15022 "2515 ADD_FCF_RECORD mailbox failed with "
15023 "status 0x%x\n", rc
);
15024 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15033 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
15034 * @phba: pointer to lpfc hba data structure.
15035 * @fcf_record: pointer to the fcf record to write the default data.
15036 * @fcf_index: FCF table entry index.
15038 * This routine is invoked to build the driver's default FCF record. The
15039 * values used are hardcoded. This routine handles memory initialization.
15043 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
15044 struct fcf_record
*fcf_record
,
15045 uint16_t fcf_index
)
15047 memset(fcf_record
, 0, sizeof(struct fcf_record
));
15048 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
15049 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
15050 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
15051 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
15052 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
15053 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
15054 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
15055 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
15056 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
15057 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
15058 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
15059 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
15060 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
15061 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
15062 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
15063 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
15064 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
15065 /* Set the VLAN bit map */
15066 if (phba
->valid_vlan
) {
15067 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
15068 = 1 << (phba
->vlan_id
% 8);
15073 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
15074 * @phba: pointer to lpfc hba data structure.
15075 * @fcf_index: FCF table entry offset.
15077 * This routine is invoked to scan the entire FCF table by reading FCF
15078 * record and processing it one at a time starting from the @fcf_index
15079 * for initial FCF discovery or fast FCF failover rediscovery.
15081 * Return 0 if the mailbox command is submitted successfully, none 0
15085 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15088 LPFC_MBOXQ_t
*mboxq
;
15090 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
15091 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
15092 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15094 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15095 "2000 Failed to allocate mbox for "
15098 goto fail_fcf_scan
;
15100 /* Construct the read FCF record mailbox command */
15101 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15104 goto fail_fcf_scan
;
15106 /* Issue the mailbox command asynchronously */
15107 mboxq
->vport
= phba
->pport
;
15108 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
15110 spin_lock_irq(&phba
->hbalock
);
15111 phba
->hba_flag
|= FCF_TS_INPROG
;
15112 spin_unlock_irq(&phba
->hbalock
);
15114 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15115 if (rc
== MBX_NOT_FINISHED
)
15118 /* Reset eligible FCF count for new scan */
15119 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
15120 phba
->fcf
.eligible_fcf_cnt
= 0;
15126 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15127 /* FCF scan failed, clear FCF_TS_INPROG flag */
15128 spin_lock_irq(&phba
->hbalock
);
15129 phba
->hba_flag
&= ~FCF_TS_INPROG
;
15130 spin_unlock_irq(&phba
->hbalock
);
15136 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15137 * @phba: pointer to lpfc hba data structure.
15138 * @fcf_index: FCF table entry offset.
15140 * This routine is invoked to read an FCF record indicated by @fcf_index
15141 * and to use it for FLOGI roundrobin FCF failover.
15143 * Return 0 if the mailbox command is submitted successfully, none 0
15147 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15150 LPFC_MBOXQ_t
*mboxq
;
15152 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15154 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15155 "2763 Failed to allocate mbox for "
15158 goto fail_fcf_read
;
15160 /* Construct the read FCF record mailbox command */
15161 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15164 goto fail_fcf_read
;
15166 /* Issue the mailbox command asynchronously */
15167 mboxq
->vport
= phba
->pport
;
15168 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
15169 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15170 if (rc
== MBX_NOT_FINISHED
)
15176 if (error
&& mboxq
)
15177 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15182 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15183 * @phba: pointer to lpfc hba data structure.
15184 * @fcf_index: FCF table entry offset.
15186 * This routine is invoked to read an FCF record indicated by @fcf_index to
15187 * determine whether it's eligible for FLOGI roundrobin failover list.
15189 * Return 0 if the mailbox command is submitted successfully, none 0
15193 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15196 LPFC_MBOXQ_t
*mboxq
;
15198 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15200 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15201 "2758 Failed to allocate mbox for "
15204 goto fail_fcf_read
;
15206 /* Construct the read FCF record mailbox command */
15207 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15210 goto fail_fcf_read
;
15212 /* Issue the mailbox command asynchronously */
15213 mboxq
->vport
= phba
->pport
;
15214 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
15215 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15216 if (rc
== MBX_NOT_FINISHED
)
15222 if (error
&& mboxq
)
15223 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15228 * lpfc_check_next_fcf_pri
15229 * phba pointer to the lpfc_hba struct for this port.
15230 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15231 * routine when the rr_bmask is empty. The FCF indecies are put into the
15232 * rr_bmask based on their priority level. Starting from the highest priority
15233 * to the lowest. The most likely FCF candidate will be in the highest
15234 * priority group. When this routine is called it searches the fcf_pri list for
15235 * next lowest priority group and repopulates the rr_bmask with only those
15238 * 1=success 0=failure
15241 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15243 uint16_t next_fcf_pri
;
15244 uint16_t last_index
;
15245 struct lpfc_fcf_pri
*fcf_pri
;
15249 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15250 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15251 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15252 "3060 Last IDX %d\n", last_index
);
15253 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
15254 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15255 "3061 Last IDX %d\n", last_index
);
15256 return 0; /* Empty rr list */
15260 * Clear the rr_bmask and set all of the bits that are at this
15263 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15264 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15265 spin_lock_irq(&phba
->hbalock
);
15266 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15267 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15270 * the 1st priority that has not FLOGI failed
15271 * will be the highest.
15274 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15275 spin_unlock_irq(&phba
->hbalock
);
15276 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15277 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15278 fcf_pri
->fcf_rec
.fcf_index
);
15282 spin_lock_irq(&phba
->hbalock
);
15285 * if next_fcf_pri was not set above and the list is not empty then
15286 * we have failed flogis on all of them. So reset flogi failed
15287 * and start at the begining.
15289 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15290 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15291 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15293 * the 1st priority that has not FLOGI failed
15294 * will be the highest.
15297 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15298 spin_unlock_irq(&phba
->hbalock
);
15299 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15300 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15301 fcf_pri
->fcf_rec
.fcf_index
);
15305 spin_lock_irq(&phba
->hbalock
);
15309 spin_unlock_irq(&phba
->hbalock
);
15314 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15315 * @phba: pointer to lpfc hba data structure.
15317 * This routine is to get the next eligible FCF record index in a round
15318 * robin fashion. If the next eligible FCF record index equals to the
15319 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15320 * shall be returned, otherwise, the next eligible FCF record's index
15321 * shall be returned.
15324 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15326 uint16_t next_fcf_index
;
15328 /* Search start from next bit of currently registered FCF index */
15330 next_fcf_index
= (phba
->fcf
.current_rec
.fcf_indx
+ 1) %
15331 LPFC_SLI4_FCF_TBL_INDX_MAX
;
15332 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15333 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15336 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15337 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15339 * If we have wrapped then we need to clear the bits that
15340 * have been tested so that we can detect when we should
15341 * change the priority level.
15343 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15344 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15348 /* Check roundrobin failover list empty condition */
15349 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15350 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15352 * If next fcf index is not found check if there are lower
15353 * Priority level fcf's in the fcf_priority list.
15354 * Set up the rr_bmask with all of the avaiable fcf bits
15355 * at that level and continue the selection process.
15357 if (lpfc_check_next_fcf_pri_level(phba
))
15358 goto next_priority
;
15359 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15360 "2844 No roundrobin failover FCF available\n");
15361 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15362 return LPFC_FCOE_FCF_NEXT_NONE
;
15364 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15365 "3063 Only FCF available idx %d, flag %x\n",
15367 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15368 return next_fcf_index
;
15372 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15373 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15374 LPFC_FCF_FLOGI_FAILED
)
15375 goto next_priority
;
15377 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15378 "2845 Get next roundrobin failover FCF (x%x)\n",
15381 return next_fcf_index
;
15385 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15386 * @phba: pointer to lpfc hba data structure.
15388 * This routine sets the FCF record index in to the eligible bmask for
15389 * roundrobin failover search. It checks to make sure that the index
15390 * does not go beyond the range of the driver allocated bmask dimension
15391 * before setting the bit.
15393 * Returns 0 if the index bit successfully set, otherwise, it returns
15397 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15399 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15400 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15401 "2610 FCF (x%x) reached driver's book "
15402 "keeping dimension:x%x\n",
15403 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15406 /* Set the eligible FCF record index bmask */
15407 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15409 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15410 "2790 Set FCF (x%x) to roundrobin FCF failover "
15411 "bmask\n", fcf_index
);
15417 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15418 * @phba: pointer to lpfc hba data structure.
15420 * This routine clears the FCF record index from the eligible bmask for
15421 * roundrobin failover search. It checks to make sure that the index
15422 * does not go beyond the range of the driver allocated bmask dimension
15423 * before clearing the bit.
15426 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15428 struct lpfc_fcf_pri
*fcf_pri
;
15429 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15430 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15431 "2762 FCF (x%x) reached driver's book "
15432 "keeping dimension:x%x\n",
15433 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15436 /* Clear the eligible FCF record index bmask */
15437 spin_lock_irq(&phba
->hbalock
);
15438 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15439 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15440 list_del_init(&fcf_pri
->list
);
15444 spin_unlock_irq(&phba
->hbalock
);
15445 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15447 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15448 "2791 Clear FCF (x%x) from roundrobin failover "
15449 "bmask\n", fcf_index
);
15453 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15454 * @phba: pointer to lpfc hba data structure.
15456 * This routine is the completion routine for the rediscover FCF table mailbox
15457 * command. If the mailbox command returned failure, it will try to stop the
15458 * FCF rediscover wait timer.
15461 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
15463 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15464 uint32_t shdr_status
, shdr_add_status
;
15466 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15468 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
15469 &redisc_fcf
->header
.cfg_shdr
.response
);
15470 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
15471 &redisc_fcf
->header
.cfg_shdr
.response
);
15472 if (shdr_status
|| shdr_add_status
) {
15473 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15474 "2746 Requesting for FCF rediscovery failed "
15475 "status x%x add_status x%x\n",
15476 shdr_status
, shdr_add_status
);
15477 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
15478 spin_lock_irq(&phba
->hbalock
);
15479 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
15480 spin_unlock_irq(&phba
->hbalock
);
15482 * CVL event triggered FCF rediscover request failed,
15483 * last resort to re-try current registered FCF entry.
15485 lpfc_retry_pport_discovery(phba
);
15487 spin_lock_irq(&phba
->hbalock
);
15488 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
15489 spin_unlock_irq(&phba
->hbalock
);
15491 * DEAD FCF event triggered FCF rediscover request
15492 * failed, last resort to fail over as a link down
15493 * to FCF registration.
15495 lpfc_sli4_fcf_dead_failthrough(phba
);
15498 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15499 "2775 Start FCF rediscover quiescent timer\n");
15501 * Start FCF rediscovery wait timer for pending FCF
15502 * before rescan FCF record table.
15504 lpfc_fcf_redisc_wait_start_timer(phba
);
15507 mempool_free(mbox
, phba
->mbox_mem_pool
);
15511 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15512 * @phba: pointer to lpfc hba data structure.
15514 * This routine is invoked to request for rediscovery of the entire FCF table
15518 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
15520 LPFC_MBOXQ_t
*mbox
;
15521 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15524 /* Cancel retry delay timers to all vports before FCF rediscover */
15525 lpfc_cancel_all_vport_retry_delay_timer(phba
);
15527 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15529 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15530 "2745 Failed to allocate mbox for "
15531 "requesting FCF rediscover.\n");
15535 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
15536 sizeof(struct lpfc_sli4_cfg_mhdr
));
15537 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15538 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
15539 length
, LPFC_SLI4_MBX_EMBED
);
15541 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15542 /* Set count to 0 for invalidating the entire FCF database */
15543 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
15545 /* Issue the mailbox command asynchronously */
15546 mbox
->vport
= phba
->pport
;
15547 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
15548 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
15550 if (rc
== MBX_NOT_FINISHED
) {
15551 mempool_free(mbox
, phba
->mbox_mem_pool
);
15558 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15559 * @phba: pointer to lpfc hba data structure.
15561 * This function is the failover routine as a last resort to the FCF DEAD
15562 * event when driver failed to perform fast FCF failover.
15565 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
15567 uint32_t link_state
;
15570 * Last resort as FCF DEAD event failover will treat this as
15571 * a link down, but save the link state because we don't want
15572 * it to be changed to Link Down unless it is already down.
15574 link_state
= phba
->link_state
;
15575 lpfc_linkdown(phba
);
15576 phba
->link_state
= link_state
;
15578 /* Unregister FCF if no devices connected to it */
15579 lpfc_unregister_unused_fcf(phba
);
15583 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15584 * @phba: pointer to lpfc hba data structure.
15585 * @rgn23_data: pointer to configure region 23 data.
15587 * This function gets SLI3 port configure region 23 data through memory dump
15588 * mailbox command. When it successfully retrieves data, the size of the data
15589 * will be returned, otherwise, 0 will be returned.
15592 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15594 LPFC_MBOXQ_t
*pmb
= NULL
;
15596 uint32_t offset
= 0;
15602 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15604 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15605 "2600 failed to allocate mailbox memory\n");
15611 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
15612 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
15614 if (rc
!= MBX_SUCCESS
) {
15615 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15616 "2601 failed to read config "
15617 "region 23, rc 0x%x Status 0x%x\n",
15618 rc
, mb
->mbxStatus
);
15619 mb
->un
.varDmp
.word_cnt
= 0;
15622 * dump mem may return a zero when finished or we got a
15623 * mailbox error, either way we are done.
15625 if (mb
->un
.varDmp
.word_cnt
== 0)
15627 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
15628 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
15630 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
15631 rgn23_data
+ offset
,
15632 mb
->un
.varDmp
.word_cnt
);
15633 offset
+= mb
->un
.varDmp
.word_cnt
;
15634 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
15636 mempool_free(pmb
, phba
->mbox_mem_pool
);
15641 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15642 * @phba: pointer to lpfc hba data structure.
15643 * @rgn23_data: pointer to configure region 23 data.
15645 * This function gets SLI4 port configure region 23 data through memory dump
15646 * mailbox command. When it successfully retrieves data, the size of the data
15647 * will be returned, otherwise, 0 will be returned.
15650 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15652 LPFC_MBOXQ_t
*mboxq
= NULL
;
15653 struct lpfc_dmabuf
*mp
= NULL
;
15654 struct lpfc_mqe
*mqe
;
15655 uint32_t data_length
= 0;
15661 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15663 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15664 "3105 failed to allocate mailbox memory\n");
15668 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
15670 mqe
= &mboxq
->u
.mqe
;
15671 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
15672 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15675 data_length
= mqe
->un
.mb_words
[5];
15676 if (data_length
== 0)
15678 if (data_length
> DMP_RGN23_SIZE
) {
15682 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
15684 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15686 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15689 return data_length
;
15693 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15694 * @phba: pointer to lpfc hba data structure.
15696 * This function read region 23 and parse TLV for port status to
15697 * decide if the user disaled the port. If the TLV indicates the
15698 * port is disabled, the hba_flag is set accordingly.
15701 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
15703 uint8_t *rgn23_data
= NULL
;
15704 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
15705 uint32_t offset
= 0;
15707 /* Get adapter Region 23 data */
15708 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
15712 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15713 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
15715 if_type
= bf_get(lpfc_sli_intf_if_type
,
15716 &phba
->sli4_hba
.sli_intf
);
15717 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
15719 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
15725 /* Check the region signature first */
15726 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
15727 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15728 "2619 Config region 23 has bad signature\n");
15733 /* Check the data structure version */
15734 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
15735 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15736 "2620 Config region 23 has bad version\n");
15741 /* Parse TLV entries in the region */
15742 while (offset
< data_size
) {
15743 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
15746 * If the TLV is not driver specific TLV or driver id is
15747 * not linux driver id, skip the record.
15749 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
15750 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
15751 (rgn23_data
[offset
+ 3] != 0)) {
15752 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15756 /* Driver found a driver specific TLV in the config region */
15757 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
15762 * Search for configured port state sub-TLV.
15764 while ((offset
< data_size
) &&
15765 (tlv_offset
< sub_tlv_len
)) {
15766 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
15771 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
15772 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15773 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15777 /* This HBA contains PORT_STE configured */
15778 if (!rgn23_data
[offset
+ 2])
15779 phba
->hba_flag
|= LINK_DISABLED
;
15791 * lpfc_wr_object - write an object to the firmware
15792 * @phba: HBA structure that indicates port to create a queue on.
15793 * @dmabuf_list: list of dmabufs to write to the port.
15794 * @size: the total byte value of the objects to write to the port.
15795 * @offset: the current offset to be used to start the transfer.
15797 * This routine will create a wr_object mailbox command to send to the port.
15798 * the mailbox command will be constructed using the dma buffers described in
15799 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
15800 * BDEs that the imbedded mailbox can support. The @offset variable will be
15801 * used to indicate the starting offset of the transfer and will also return
15802 * the offset after the write object mailbox has completed. @size is used to
15803 * determine the end of the object and whether the eof bit should be set.
15805 * Return 0 is successful and offset will contain the the new offset to use
15806 * for the next write.
15807 * Return negative value for error cases.
15810 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
15811 uint32_t size
, uint32_t *offset
)
15813 struct lpfc_mbx_wr_object
*wr_object
;
15814 LPFC_MBOXQ_t
*mbox
;
15816 uint32_t shdr_status
, shdr_add_status
;
15818 union lpfc_sli4_cfg_shdr
*shdr
;
15819 struct lpfc_dmabuf
*dmabuf
;
15820 uint32_t written
= 0;
15822 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15826 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15827 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
15828 sizeof(struct lpfc_mbx_wr_object
) -
15829 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15831 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
15832 wr_object
->u
.request
.write_offset
= *offset
;
15833 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
15834 wr_object
->u
.request
.object_name
[0] =
15835 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
15836 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
15837 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
15838 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
15840 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
15841 wr_object
->u
.request
.bde
[i
].addrHigh
=
15842 putPaddrHigh(dmabuf
->phys
);
15843 if (written
+ SLI4_PAGE_SIZE
>= size
) {
15844 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15846 written
+= (size
- written
);
15847 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
15849 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15851 written
+= SLI4_PAGE_SIZE
;
15855 wr_object
->u
.request
.bde_count
= i
;
15856 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
15857 if (!phba
->sli4_hba
.intr_enable
)
15858 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15860 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15861 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15863 /* The IOCTL status is embedded in the mailbox subheader. */
15864 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
15865 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15866 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15867 if (rc
!= MBX_TIMEOUT
)
15868 mempool_free(mbox
, phba
->mbox_mem_pool
);
15869 if (shdr_status
|| shdr_add_status
|| rc
) {
15870 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15871 "3025 Write Object mailbox failed with "
15872 "status x%x add_status x%x, mbx status x%x\n",
15873 shdr_status
, shdr_add_status
, rc
);
15876 *offset
+= wr_object
->u
.response
.actual_write_length
;
15881 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
15882 * @vport: pointer to vport data structure.
15884 * This function iterate through the mailboxq and clean up all REG_LOGIN
15885 * and REG_VPI mailbox commands associated with the vport. This function
15886 * is called when driver want to restart discovery of the vport due to
15887 * a Clear Virtual Link event.
15890 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
15892 struct lpfc_hba
*phba
= vport
->phba
;
15893 LPFC_MBOXQ_t
*mb
, *nextmb
;
15894 struct lpfc_dmabuf
*mp
;
15895 struct lpfc_nodelist
*ndlp
;
15896 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
15897 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
15898 LIST_HEAD(mbox_cmd_list
);
15899 uint8_t restart_loop
;
15901 /* Clean up internally queued mailbox commands with the vport */
15902 spin_lock_irq(&phba
->hbalock
);
15903 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
15904 if (mb
->vport
!= vport
)
15907 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15908 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15911 list_del(&mb
->list
);
15912 list_add_tail(&mb
->list
, &mbox_cmd_list
);
15914 /* Clean up active mailbox command with the vport */
15915 mb
= phba
->sli
.mbox_active
;
15916 if (mb
&& (mb
->vport
== vport
)) {
15917 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
15918 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
15919 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15920 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15921 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15922 /* Put reference count for delayed processing */
15923 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
15924 /* Unregister the RPI when mailbox complete */
15925 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15928 /* Cleanup any mailbox completions which are not yet processed */
15931 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
15933 * If this mailox is already processed or it is
15934 * for another vport ignore it.
15936 if ((mb
->vport
!= vport
) ||
15937 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
15940 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15941 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15944 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15945 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15946 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15947 /* Unregister the RPI when mailbox complete */
15948 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15950 spin_unlock_irq(&phba
->hbalock
);
15951 spin_lock(shost
->host_lock
);
15952 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15953 spin_unlock(shost
->host_lock
);
15954 spin_lock_irq(&phba
->hbalock
);
15958 } while (restart_loop
);
15960 spin_unlock_irq(&phba
->hbalock
);
15962 /* Release the cleaned-up mailbox commands */
15963 while (!list_empty(&mbox_cmd_list
)) {
15964 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
15965 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15966 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
15968 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15971 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
15972 mb
->context2
= NULL
;
15974 spin_lock(shost
->host_lock
);
15975 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15976 spin_unlock(shost
->host_lock
);
15977 lpfc_nlp_put(ndlp
);
15980 mempool_free(mb
, phba
->mbox_mem_pool
);
15983 /* Release the ndlp with the cleaned-up active mailbox command */
15984 if (act_mbx_ndlp
) {
15985 spin_lock(shost
->host_lock
);
15986 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15987 spin_unlock(shost
->host_lock
);
15988 lpfc_nlp_put(act_mbx_ndlp
);
15993 * lpfc_drain_txq - Drain the txq
15994 * @phba: Pointer to HBA context object.
15996 * This function attempt to submit IOCBs on the txq
15997 * to the adapter. For SLI4 adapters, the txq contains
15998 * ELS IOCBs that have been deferred because the there
15999 * are no SGLs. This congestion can occur with large
16000 * vport counts during node discovery.
16004 lpfc_drain_txq(struct lpfc_hba
*phba
)
16006 LIST_HEAD(completions
);
16007 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
16008 struct lpfc_iocbq
*piocbq
= 0;
16009 unsigned long iflags
= 0;
16010 char *fail_msg
= NULL
;
16011 struct lpfc_sglq
*sglq
;
16012 union lpfc_wqe wqe
;
16014 spin_lock_irqsave(&phba
->hbalock
, iflags
);
16015 if (pring
->txq_cnt
> pring
->txq_max
)
16016 pring
->txq_max
= pring
->txq_cnt
;
16018 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16020 while (pring
->txq_cnt
) {
16021 spin_lock_irqsave(&phba
->hbalock
, iflags
);
16023 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
16025 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16026 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16027 "2823 txq empty and txq_cnt is %d\n ",
16031 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
16033 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
16034 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16038 /* The xri and iocb resources secured,
16039 * attempt to issue request
16041 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
16042 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
16043 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
16044 fail_msg
= "to convert bpl to sgl";
16045 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
16046 fail_msg
= "to convert iocb to wqe";
16047 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
16048 fail_msg
= " - Wq is full";
16050 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
16053 /* Failed means we can't issue and need to cancel */
16054 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16055 "2822 IOCB failed %s iotag 0x%x "
16058 piocbq
->iotag
, piocbq
->sli4_xritag
);
16059 list_add_tail(&piocbq
->list
, &completions
);
16061 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16064 /* Cancel all the IOCBs that cannot be issued */
16065 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
16066 IOERR_SLI_ABORTED
);
16068 return pring
->txq_cnt
;