1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 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>
27 #include <linux/lockdep.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_cmnd.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/fc/fc_fs.h>
35 #include <linux/aer.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_debugfs.h"
49 #include "lpfc_vport.h"
50 #include "lpfc_version.h"
52 /* There are only four IOCB completion types. */
53 typedef enum _lpfc_iocb_type
{
61 /* Provide function prototypes local to this module. */
62 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
64 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
65 uint8_t *, uint32_t *);
66 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
68 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
70 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*, struct lpfc_queue
*,
72 static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*, struct list_head
*,
74 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*, struct lpfc_eqe
*,
76 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
);
77 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
);
80 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
86 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
87 * @q: The Work Queue to operate on.
88 * @wqe: The work Queue Entry to put on the Work queue.
90 * This routine will copy the contents of @wqe to the next available entry on
91 * the @q. This function will then ring the Work Queue Doorbell to signal the
92 * HBA to start processing the Work Queue Entry. This function returns 0 if
93 * successful. If no entries are available on @q then this function will return
95 * The caller is expected to hold the hbalock when calling this routine.
98 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
100 union lpfc_wqe
*temp_wqe
;
101 struct lpfc_register doorbell
;
105 /* sanity check on queue memory */
108 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
110 /* If the host has not yet processed the next entry then we are done */
111 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
112 if (idx
== q
->hba_index
) {
117 /* set consumption flag every once in a while */
118 if (!((q
->host_index
+ 1) % q
->entry_repost
))
119 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
120 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
121 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
122 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
123 /* ensure WQE bcopy flushed before doorbell write */
126 /* Update the host index before invoking device */
127 host_index
= q
->host_index
;
133 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
134 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
135 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
, host_index
);
136 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
137 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
138 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
139 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
143 writel(doorbell
.word0
, q
->db_regaddr
);
149 * lpfc_sli4_wq_release - Updates internal hba index for WQ
150 * @q: The Work Queue to operate on.
151 * @index: The index to advance the hba index to.
153 * This routine will update the HBA index of a queue to reflect consumption of
154 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
155 * an entry the host calls this function to update the queue's internal
156 * pointers. This routine returns the number of entries that were consumed by
160 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
162 uint32_t released
= 0;
164 /* sanity check on queue memory */
168 if (q
->hba_index
== index
)
171 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
173 } while (q
->hba_index
!= index
);
178 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
179 * @q: The Mailbox Queue to operate on.
180 * @wqe: The Mailbox Queue Entry to put on the Work queue.
182 * This routine will copy the contents of @mqe to the next available entry on
183 * the @q. This function will then ring the Work Queue Doorbell to signal the
184 * HBA to start processing the Work Queue Entry. This function returns 0 if
185 * successful. If no entries are available on @q then this function will return
187 * The caller is expected to hold the hbalock when calling this routine.
190 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
192 struct lpfc_mqe
*temp_mqe
;
193 struct lpfc_register doorbell
;
195 /* sanity check on queue memory */
198 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
200 /* If the host has not yet processed the next entry then we are done */
201 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
203 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
204 /* Save off the mailbox pointer for completion */
205 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
207 /* Update the host index before invoking device */
208 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
212 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
213 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
214 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
219 * lpfc_sli4_mq_release - Updates internal hba index for MQ
220 * @q: The Mailbox Queue to operate on.
222 * This routine will update the HBA index of a queue to reflect consumption of
223 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
224 * an entry the host calls this function to update the queue's internal
225 * pointers. This routine returns the number of entries that were consumed by
229 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
231 /* sanity check on queue memory */
235 /* Clear the mailbox pointer for completion */
236 q
->phba
->mbox
= NULL
;
237 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
242 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
243 * @q: The Event Queue to get the first valid EQE from
245 * This routine will get the first valid Event Queue Entry from @q, update
246 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
247 * the Queue (no more work to do), or the Queue is full of EQEs that have been
248 * processed, but not popped back to the HBA then this routine will return NULL.
250 static struct lpfc_eqe
*
251 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
253 struct lpfc_eqe
*eqe
;
256 /* sanity check on queue memory */
259 eqe
= q
->qe
[q
->hba_index
].eqe
;
261 /* If the next EQE is not valid then we are done */
262 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
264 /* If the host has not yet processed the next entry then we are done */
265 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
266 if (idx
== q
->host_index
)
272 * insert barrier for instruction interlock : data from the hardware
273 * must have the valid bit checked before it can be copied and acted
274 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
275 * instructions allowing action on content before valid bit checked,
276 * add barrier here as well. May not be needed as "content" is a
277 * single 32-bit entity here (vs multi word structure for cq's).
284 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
285 * @q: The Event Queue to disable interrupts
289 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
291 struct lpfc_register doorbell
;
294 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
295 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
296 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
297 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
298 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
299 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
303 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
304 * @q: The Event Queue that the host has completed processing for.
305 * @arm: Indicates whether the host wants to arms this CQ.
307 * This routine will mark all Event Queue Entries on @q, from the last
308 * known completed entry to the last entry that was processed, as completed
309 * by clearing the valid bit for each completion queue entry. Then it will
310 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
311 * The internal host index in the @q will be updated by this routine to indicate
312 * that the host has finished processing the entries. The @arm parameter
313 * indicates that the queue should be rearmed when ringing the doorbell.
315 * This function will return the number of EQEs that were popped.
318 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
320 uint32_t released
= 0;
321 struct lpfc_eqe
*temp_eqe
;
322 struct lpfc_register doorbell
;
324 /* sanity check on queue memory */
328 /* while there are valid entries */
329 while (q
->hba_index
!= q
->host_index
) {
330 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
331 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
333 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
335 if (unlikely(released
== 0 && !arm
))
338 /* ring doorbell for number popped */
341 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
342 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
344 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
345 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
346 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
347 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
348 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
349 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
350 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
351 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
352 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
357 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
358 * @q: The Completion Queue to get the first valid CQE from
360 * This routine will get the first valid Completion Queue Entry from @q, update
361 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
362 * the Queue (no more work to do), or the Queue is full of CQEs that have been
363 * processed, but not popped back to the HBA then this routine will return NULL.
365 static struct lpfc_cqe
*
366 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
368 struct lpfc_cqe
*cqe
;
371 /* sanity check on queue memory */
375 /* If the next CQE is not valid then we are done */
376 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
378 /* If the host has not yet processed the next entry then we are done */
379 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
380 if (idx
== q
->host_index
)
383 cqe
= q
->qe
[q
->hba_index
].cqe
;
387 * insert barrier for instruction interlock : data from the hardware
388 * must have the valid bit checked before it can be copied and acted
389 * upon. Speculative instructions were allowing a bcopy at the start
390 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
391 * after our return, to copy data before the valid bit check above
392 * was done. As such, some of the copied data was stale. The barrier
393 * ensures the check is before any data is copied.
400 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
401 * @q: The Completion Queue that the host has completed processing for.
402 * @arm: Indicates whether the host wants to arms this CQ.
404 * This routine will mark all Completion queue entries on @q, from the last
405 * known completed entry to the last entry that was processed, as completed
406 * by clearing the valid bit for each completion queue entry. Then it will
407 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
408 * The internal host index in the @q will be updated by this routine to indicate
409 * that the host has finished processing the entries. The @arm parameter
410 * indicates that the queue should be rearmed when ringing the doorbell.
412 * This function will return the number of CQEs that were released.
415 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
417 uint32_t released
= 0;
418 struct lpfc_cqe
*temp_qe
;
419 struct lpfc_register doorbell
;
421 /* sanity check on queue memory */
424 /* while there are valid entries */
425 while (q
->hba_index
!= q
->host_index
) {
426 temp_qe
= q
->qe
[q
->host_index
].cqe
;
427 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
429 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
431 if (unlikely(released
== 0 && !arm
))
434 /* ring doorbell for number popped */
437 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
438 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
439 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
440 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
441 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
442 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
443 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
448 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
449 * @q: The Header Receive Queue to operate on.
450 * @wqe: The Receive Queue Entry to put on the Receive queue.
452 * This routine will copy the contents of @wqe to the next available entry on
453 * the @q. This function will then ring the Receive Queue Doorbell to signal the
454 * HBA to start processing the Receive Queue Entry. This function returns the
455 * index that the rqe was copied to if successful. If no entries are available
456 * on @q then this function will return -ENOMEM.
457 * The caller is expected to hold the hbalock when calling this routine.
460 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
461 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
463 struct lpfc_rqe
*temp_hrqe
;
464 struct lpfc_rqe
*temp_drqe
;
465 struct lpfc_register doorbell
;
468 /* sanity check on queue memory */
469 if (unlikely(!hq
) || unlikely(!dq
))
471 put_index
= hq
->host_index
;
472 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
473 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
475 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
477 if (hq
->host_index
!= dq
->host_index
)
479 /* If the host has not yet processed the next entry then we are done */
480 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
482 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
483 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
485 /* Update the host index to point to the next slot */
486 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
487 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
489 /* Ring The Header Receive Queue Doorbell */
490 if (!(hq
->host_index
% hq
->entry_repost
)) {
492 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
493 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
495 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
496 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
497 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
499 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
501 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
505 writel(doorbell
.word0
, hq
->db_regaddr
);
511 * lpfc_sli4_rq_release - Updates internal hba index for RQ
512 * @q: The Header Receive Queue to operate on.
514 * This routine will update the HBA index of a queue to reflect consumption of
515 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
516 * consumed an entry the host calls this function to update the queue's
517 * internal pointers. This routine returns the number of entries that were
518 * consumed by the HBA.
521 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
523 /* sanity check on queue memory */
524 if (unlikely(!hq
) || unlikely(!dq
))
527 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
529 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
530 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
535 * lpfc_cmd_iocb - Get next command iocb entry in the ring
536 * @phba: Pointer to HBA context object.
537 * @pring: Pointer to driver SLI ring object.
539 * This function returns pointer to next command iocb entry
540 * in the command ring. The caller must hold hbalock to prevent
541 * other threads consume the next command iocb.
542 * SLI-2/SLI-3 provide different sized iocbs.
544 static inline IOCB_t
*
545 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
547 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
548 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
552 * lpfc_resp_iocb - Get next response iocb entry in the ring
553 * @phba: Pointer to HBA context object.
554 * @pring: Pointer to driver SLI ring object.
556 * This function returns pointer to next response iocb entry
557 * in the response ring. The caller must hold hbalock to make sure
558 * that no other thread consume the next response iocb.
559 * SLI-2/SLI-3 provide different sized iocbs.
561 static inline IOCB_t
*
562 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
564 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
565 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
569 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
570 * @phba: Pointer to HBA context object.
572 * This function is called with hbalock held. This function
573 * allocates a new driver iocb object from the iocb pool. If the
574 * allocation is successful, it returns pointer to the newly
575 * allocated iocb object else it returns NULL.
578 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
580 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
581 struct lpfc_iocbq
* iocbq
= NULL
;
583 lockdep_assert_held(&phba
->hbalock
);
585 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
588 if (phba
->iocb_cnt
> phba
->iocb_max
)
589 phba
->iocb_max
= phba
->iocb_cnt
;
594 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
595 * @phba: Pointer to HBA context object.
596 * @xritag: XRI value.
598 * This function clears the sglq pointer from the array of acive
599 * sglq's. The xritag that is passed in is used to index into the
600 * array. Before the xritag can be used it needs to be adjusted
601 * by subtracting the xribase.
603 * Returns sglq ponter = success, NULL = Failure.
605 static struct lpfc_sglq
*
606 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
608 struct lpfc_sglq
*sglq
;
610 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
611 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
616 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
617 * @phba: Pointer to HBA context object.
618 * @xritag: XRI value.
620 * This function returns the sglq pointer from the array of acive
621 * sglq's. The xritag that is passed in is used to index into the
622 * array. Before the xritag can be used it needs to be adjusted
623 * by subtracting the xribase.
625 * Returns sglq ponter = success, NULL = Failure.
628 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
630 struct lpfc_sglq
*sglq
;
632 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
637 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
638 * @phba: Pointer to HBA context object.
639 * @xritag: xri used in this exchange.
640 * @rrq: The RRQ to be cleared.
644 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
646 struct lpfc_node_rrq
*rrq
)
648 struct lpfc_nodelist
*ndlp
= NULL
;
650 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
651 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
653 /* The target DID could have been swapped (cable swap)
654 * we should use the ndlp from the findnode if it is
657 if ((!ndlp
) && rrq
->ndlp
)
663 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
)) {
666 rrq
->rrq_stop_time
= 0;
669 mempool_free(rrq
, phba
->rrq_pool
);
673 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
674 * @phba: Pointer to HBA context object.
676 * This function is called with hbalock held. This function
677 * Checks if stop_time (ratov from setting rrq active) has
678 * been reached, if it has and the send_rrq flag is set then
679 * it will call lpfc_send_rrq. If the send_rrq flag is not set
680 * then it will just call the routine to clear the rrq and
681 * free the rrq resource.
682 * The timer is set to the next rrq that is going to expire before
683 * leaving the routine.
687 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
689 struct lpfc_node_rrq
*rrq
;
690 struct lpfc_node_rrq
*nextrrq
;
691 unsigned long next_time
;
692 unsigned long iflags
;
695 spin_lock_irqsave(&phba
->hbalock
, iflags
);
696 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
697 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
698 list_for_each_entry_safe(rrq
, nextrrq
,
699 &phba
->active_rrq_list
, list
) {
700 if (time_after(jiffies
, rrq
->rrq_stop_time
))
701 list_move(&rrq
->list
, &send_rrq
);
702 else if (time_before(rrq
->rrq_stop_time
, next_time
))
703 next_time
= rrq
->rrq_stop_time
;
705 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
706 if ((!list_empty(&phba
->active_rrq_list
)) &&
707 (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
708 mod_timer(&phba
->rrq_tmr
, next_time
);
709 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
710 list_del(&rrq
->list
);
712 /* this call will free the rrq */
713 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
714 else if (lpfc_send_rrq(phba
, rrq
)) {
715 /* if we send the rrq then the completion handler
716 * will clear the bit in the xribitmap.
718 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
725 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
726 * @vport: Pointer to vport context object.
727 * @xri: The xri used in the exchange.
728 * @did: The targets DID for this exchange.
730 * returns NULL = rrq not found in the phba->active_rrq_list.
731 * rrq = rrq for this xri and target.
733 struct lpfc_node_rrq
*
734 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
736 struct lpfc_hba
*phba
= vport
->phba
;
737 struct lpfc_node_rrq
*rrq
;
738 struct lpfc_node_rrq
*nextrrq
;
739 unsigned long iflags
;
741 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
743 spin_lock_irqsave(&phba
->hbalock
, iflags
);
744 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
745 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
746 rrq
->nlp_DID
== did
){
747 list_del(&rrq
->list
);
748 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
752 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
757 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
758 * @vport: Pointer to vport context object.
759 * @ndlp: Pointer to the lpfc_node_list structure.
760 * If ndlp is NULL Remove all active RRQs for this vport from the
761 * phba->active_rrq_list and clear the rrq.
762 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
765 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
768 struct lpfc_hba
*phba
= vport
->phba
;
769 struct lpfc_node_rrq
*rrq
;
770 struct lpfc_node_rrq
*nextrrq
;
771 unsigned long iflags
;
774 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
777 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
778 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
780 spin_lock_irqsave(&phba
->hbalock
, iflags
);
781 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
782 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
783 list_move(&rrq
->list
, &rrq_list
);
784 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
786 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
787 list_del(&rrq
->list
);
788 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
793 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
794 * @phba: Pointer to HBA context object.
795 * @ndlp: Targets nodelist pointer for this exchange.
796 * @xritag the xri in the bitmap to test.
798 * This function is called with hbalock held. This function
799 * returns 0 = rrq not active for this xri
800 * 1 = rrq is valid for this xri.
803 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
806 lockdep_assert_held(&phba
->hbalock
);
809 if (!ndlp
->active_rrqs_xri_bitmap
)
811 if (test_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
818 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
819 * @phba: Pointer to HBA context object.
820 * @ndlp: nodelist pointer for this target.
821 * @xritag: xri used in this exchange.
822 * @rxid: Remote Exchange ID.
823 * @send_rrq: Flag used to determine if we should send rrq els cmd.
825 * This function takes the hbalock.
826 * The active bit is always set in the active rrq xri_bitmap even
827 * if there is no slot avaiable for the other rrq information.
829 * returns 0 rrq actived for this xri
830 * < 0 No memory or invalid ndlp.
833 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
834 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
836 unsigned long iflags
;
837 struct lpfc_node_rrq
*rrq
;
843 if (!phba
->cfg_enable_rrq
)
846 spin_lock_irqsave(&phba
->hbalock
, iflags
);
847 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
848 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
853 * set the active bit even if there is no mem available.
855 if (NLP_CHK_FREE_REQ(ndlp
))
858 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
861 if (!ndlp
->active_rrqs_xri_bitmap
)
864 if (test_and_set_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
867 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
868 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
870 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
871 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
872 " DID:0x%x Send:%d\n",
873 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
876 if (phba
->cfg_enable_rrq
== 1)
877 rrq
->send_rrq
= send_rrq
;
880 rrq
->xritag
= xritag
;
881 rrq
->rrq_stop_time
= jiffies
+
882 msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
884 rrq
->nlp_DID
= ndlp
->nlp_DID
;
885 rrq
->vport
= ndlp
->vport
;
887 spin_lock_irqsave(&phba
->hbalock
, iflags
);
888 empty
= list_empty(&phba
->active_rrq_list
);
889 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
890 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
892 lpfc_worker_wake_up(phba
);
893 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
896 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
897 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
898 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
899 " DID:0x%x Send:%d\n",
900 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
905 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
906 * @phba: Pointer to HBA context object.
907 * @piocb: Pointer to the iocbq.
909 * This function is called with the ring lock held. This function
910 * gets a new driver sglq object from the sglq list. If the
911 * list is not empty then it is successful, it returns pointer to the newly
912 * allocated sglq object else it returns NULL.
914 static struct lpfc_sglq
*
915 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
917 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
918 struct lpfc_sglq
*sglq
= NULL
;
919 struct lpfc_sglq
*start_sglq
= NULL
;
920 struct lpfc_scsi_buf
*lpfc_cmd
;
921 struct lpfc_nodelist
*ndlp
;
924 lockdep_assert_held(&phba
->hbalock
);
926 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
927 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
928 ndlp
= lpfc_cmd
->rdata
->pnode
;
929 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
930 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
931 ndlp
= piocbq
->context_un
.ndlp
;
932 } else if (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
933 if (piocbq
->iocb_flag
& LPFC_IO_LOOPBACK
)
936 ndlp
= piocbq
->context_un
.ndlp
;
938 ndlp
= piocbq
->context1
;
941 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
946 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_lxritag
)) {
947 /* This xri has an rrq outstanding for this DID.
948 * put it back in the list and get another xri.
950 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
952 list_remove_head(lpfc_sgl_list
, sglq
,
953 struct lpfc_sglq
, list
);
954 if (sglq
== start_sglq
) {
962 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
963 sglq
->state
= SGL_ALLOCATED
;
969 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
970 * @phba: Pointer to HBA context object.
972 * This function is called with no lock held. This function
973 * allocates a new driver iocb object from the iocb pool. If the
974 * allocation is successful, it returns pointer to the newly
975 * allocated iocb object else it returns NULL.
978 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
980 struct lpfc_iocbq
* iocbq
= NULL
;
981 unsigned long iflags
;
983 spin_lock_irqsave(&phba
->hbalock
, iflags
);
984 iocbq
= __lpfc_sli_get_iocbq(phba
);
985 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
990 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
991 * @phba: Pointer to HBA context object.
992 * @iocbq: Pointer to driver iocb object.
994 * This function is called with hbalock held to release driver
995 * iocb object to the iocb pool. The iotag in the iocb object
996 * does not change for each use of the iocb object. This function
997 * clears all other fields of the iocb object when it is freed.
998 * The sqlq structure that holds the xritag and phys and virtual
999 * mappings for the scatter gather list is retrieved from the
1000 * active array of sglq. The get of the sglq pointer also clears
1001 * the entry in the array. If the status of the IO indiactes that
1002 * this IO was aborted then the sglq entry it put on the
1003 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1004 * IO has good status or fails for any other reason then the sglq
1005 * entry is added to the free list (lpfc_sgl_list).
1008 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1010 struct lpfc_sglq
*sglq
;
1011 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1012 unsigned long iflag
= 0;
1013 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1015 lockdep_assert_held(&phba
->hbalock
);
1017 if (iocbq
->sli4_xritag
== NO_XRI
)
1020 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1024 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1025 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1026 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
1028 list_add(&sglq
->list
,
1029 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1030 spin_unlock_irqrestore(
1031 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
1033 spin_lock_irqsave(&pring
->ring_lock
, iflag
);
1034 sglq
->state
= SGL_FREED
;
1036 list_add_tail(&sglq
->list
,
1037 &phba
->sli4_hba
.lpfc_sgl_list
);
1038 spin_unlock_irqrestore(&pring
->ring_lock
, iflag
);
1040 /* Check if TXQ queue needs to be serviced */
1041 if (!list_empty(&pring
->txq
))
1042 lpfc_worker_wake_up(phba
);
1048 * Clean all volatile data fields, preserve iotag and node struct.
1050 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1051 iocbq
->sli4_lxritag
= NO_XRI
;
1052 iocbq
->sli4_xritag
= NO_XRI
;
1053 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1058 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1059 * @phba: Pointer to HBA context object.
1060 * @iocbq: Pointer to driver iocb object.
1062 * This function is called with hbalock held to release driver
1063 * iocb object to the iocb pool. The iotag in the iocb object
1064 * does not change for each use of the iocb object. This function
1065 * clears all other fields of the iocb object when it is freed.
1068 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1070 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1072 lockdep_assert_held(&phba
->hbalock
);
1075 * Clean all volatile data fields, preserve iotag and node struct.
1077 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1078 iocbq
->sli4_xritag
= NO_XRI
;
1079 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1083 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1084 * @phba: Pointer to HBA context object.
1085 * @iocbq: Pointer to driver iocb object.
1087 * This function is called with hbalock held to release driver
1088 * iocb object to the iocb pool. The iotag in the iocb object
1089 * does not change for each use of the iocb object. This function
1090 * clears all other fields of the iocb object when it is freed.
1093 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1095 lockdep_assert_held(&phba
->hbalock
);
1097 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1102 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1103 * @phba: Pointer to HBA context object.
1104 * @iocbq: Pointer to driver iocb object.
1106 * This function is called with no lock held to release the iocb to
1110 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1112 unsigned long iflags
;
1115 * Clean all volatile data fields, preserve iotag and node struct.
1117 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1118 __lpfc_sli_release_iocbq(phba
, iocbq
);
1119 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1123 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1124 * @phba: Pointer to HBA context object.
1125 * @iocblist: List of IOCBs.
1126 * @ulpstatus: ULP status in IOCB command field.
1127 * @ulpWord4: ULP word-4 in IOCB command field.
1129 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1130 * on the list by invoking the complete callback function associated with the
1131 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1135 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1136 uint32_t ulpstatus
, uint32_t ulpWord4
)
1138 struct lpfc_iocbq
*piocb
;
1140 while (!list_empty(iocblist
)) {
1141 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1142 if (!piocb
->iocb_cmpl
)
1143 lpfc_sli_release_iocbq(phba
, piocb
);
1145 piocb
->iocb
.ulpStatus
= ulpstatus
;
1146 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1147 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1154 * lpfc_sli_iocb_cmd_type - Get the iocb type
1155 * @iocb_cmnd: iocb command code.
1157 * This function is called by ring event handler function to get the iocb type.
1158 * This function translates the iocb command to an iocb command type used to
1159 * decide the final disposition of each completed IOCB.
1160 * The function returns
1161 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1162 * LPFC_SOL_IOCB if it is a solicited iocb completion
1163 * LPFC_ABORT_IOCB if it is an abort iocb
1164 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1166 * The caller is not required to hold any lock.
1168 static lpfc_iocb_type
1169 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1171 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1173 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1176 switch (iocb_cmnd
) {
1177 case CMD_XMIT_SEQUENCE_CR
:
1178 case CMD_XMIT_SEQUENCE_CX
:
1179 case CMD_XMIT_BCAST_CN
:
1180 case CMD_XMIT_BCAST_CX
:
1181 case CMD_ELS_REQUEST_CR
:
1182 case CMD_ELS_REQUEST_CX
:
1183 case CMD_CREATE_XRI_CR
:
1184 case CMD_CREATE_XRI_CX
:
1185 case CMD_GET_RPI_CN
:
1186 case CMD_XMIT_ELS_RSP_CX
:
1187 case CMD_GET_RPI_CR
:
1188 case CMD_FCP_IWRITE_CR
:
1189 case CMD_FCP_IWRITE_CX
:
1190 case CMD_FCP_IREAD_CR
:
1191 case CMD_FCP_IREAD_CX
:
1192 case CMD_FCP_ICMND_CR
:
1193 case CMD_FCP_ICMND_CX
:
1194 case CMD_FCP_TSEND_CX
:
1195 case CMD_FCP_TRSP_CX
:
1196 case CMD_FCP_TRECEIVE_CX
:
1197 case CMD_FCP_AUTO_TRSP_CX
:
1198 case CMD_ADAPTER_MSG
:
1199 case CMD_ADAPTER_DUMP
:
1200 case CMD_XMIT_SEQUENCE64_CR
:
1201 case CMD_XMIT_SEQUENCE64_CX
:
1202 case CMD_XMIT_BCAST64_CN
:
1203 case CMD_XMIT_BCAST64_CX
:
1204 case CMD_ELS_REQUEST64_CR
:
1205 case CMD_ELS_REQUEST64_CX
:
1206 case CMD_FCP_IWRITE64_CR
:
1207 case CMD_FCP_IWRITE64_CX
:
1208 case CMD_FCP_IREAD64_CR
:
1209 case CMD_FCP_IREAD64_CX
:
1210 case CMD_FCP_ICMND64_CR
:
1211 case CMD_FCP_ICMND64_CX
:
1212 case CMD_FCP_TSEND64_CX
:
1213 case CMD_FCP_TRSP64_CX
:
1214 case CMD_FCP_TRECEIVE64_CX
:
1215 case CMD_GEN_REQUEST64_CR
:
1216 case CMD_GEN_REQUEST64_CX
:
1217 case CMD_XMIT_ELS_RSP64_CX
:
1218 case DSSCMD_IWRITE64_CR
:
1219 case DSSCMD_IWRITE64_CX
:
1220 case DSSCMD_IREAD64_CR
:
1221 case DSSCMD_IREAD64_CX
:
1222 type
= LPFC_SOL_IOCB
;
1224 case CMD_ABORT_XRI_CN
:
1225 case CMD_ABORT_XRI_CX
:
1226 case CMD_CLOSE_XRI_CN
:
1227 case CMD_CLOSE_XRI_CX
:
1228 case CMD_XRI_ABORTED_CX
:
1229 case CMD_ABORT_MXRI64_CN
:
1230 case CMD_XMIT_BLS_RSP64_CX
:
1231 type
= LPFC_ABORT_IOCB
;
1233 case CMD_RCV_SEQUENCE_CX
:
1234 case CMD_RCV_ELS_REQ_CX
:
1235 case CMD_RCV_SEQUENCE64_CX
:
1236 case CMD_RCV_ELS_REQ64_CX
:
1237 case CMD_ASYNC_STATUS
:
1238 case CMD_IOCB_RCV_SEQ64_CX
:
1239 case CMD_IOCB_RCV_ELS64_CX
:
1240 case CMD_IOCB_RCV_CONT64_CX
:
1241 case CMD_IOCB_RET_XRI64_CX
:
1242 type
= LPFC_UNSOL_IOCB
;
1244 case CMD_IOCB_XMIT_MSEQ64_CR
:
1245 case CMD_IOCB_XMIT_MSEQ64_CX
:
1246 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1247 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1248 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1249 case CMD_IOCB_ABORT_EXTENDED_CN
:
1250 case CMD_IOCB_RET_HBQE64_CN
:
1251 case CMD_IOCB_FCP_IBIDIR64_CR
:
1252 case CMD_IOCB_FCP_IBIDIR64_CX
:
1253 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1254 case CMD_IOCB_LOGENTRY_CN
:
1255 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1256 printk("%s - Unhandled SLI-3 Command x%x\n",
1257 __func__
, iocb_cmnd
);
1258 type
= LPFC_UNKNOWN_IOCB
;
1261 type
= LPFC_UNKNOWN_IOCB
;
1269 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1270 * @phba: Pointer to HBA context object.
1272 * This function is called from SLI initialization code
1273 * to configure every ring of the HBA's SLI interface. The
1274 * caller is not required to hold any lock. This function issues
1275 * a config_ring mailbox command for each ring.
1276 * This function returns zero if successful else returns a negative
1280 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1282 struct lpfc_sli
*psli
= &phba
->sli
;
1287 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1291 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1292 for (i
= 0; i
< psli
->num_rings
; i
++) {
1293 lpfc_config_ring(phba
, i
, pmb
);
1294 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1295 if (rc
!= MBX_SUCCESS
) {
1296 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1297 "0446 Adapter failed to init (%d), "
1298 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1300 rc
, pmbox
->mbxCommand
,
1301 pmbox
->mbxStatus
, i
);
1302 phba
->link_state
= LPFC_HBA_ERROR
;
1307 mempool_free(pmb
, phba
->mbox_mem_pool
);
1312 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1313 * @phba: Pointer to HBA context object.
1314 * @pring: Pointer to driver SLI ring object.
1315 * @piocb: Pointer to the driver iocb object.
1317 * This function is called with hbalock held. The function adds the
1318 * new iocb to txcmplq of the given ring. This function always returns
1319 * 0. If this function is called for ELS ring, this function checks if
1320 * there is a vport associated with the ELS command. This function also
1321 * starts els_tmofunc timer if this is an ELS command.
1324 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1325 struct lpfc_iocbq
*piocb
)
1327 lockdep_assert_held(&phba
->hbalock
);
1331 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1332 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1334 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1335 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1336 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1337 BUG_ON(!piocb
->vport
);
1338 if (!(piocb
->vport
->load_flag
& FC_UNLOADING
))
1339 mod_timer(&piocb
->vport
->els_tmofunc
,
1341 msecs_to_jiffies(1000 * (phba
->fc_ratov
<< 1)));
1348 * lpfc_sli_ringtx_get - Get first element of the txq
1349 * @phba: Pointer to HBA context object.
1350 * @pring: Pointer to driver SLI ring object.
1352 * This function is called with hbalock held to get next
1353 * iocb in txq of the given ring. If there is any iocb in
1354 * the txq, the function returns first iocb in the list after
1355 * removing the iocb from the list, else it returns NULL.
1358 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1360 struct lpfc_iocbq
*cmd_iocb
;
1362 lockdep_assert_held(&phba
->hbalock
);
1364 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1369 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1370 * @phba: Pointer to HBA context object.
1371 * @pring: Pointer to driver SLI ring object.
1373 * This function is called with hbalock held and the caller must post the
1374 * iocb without releasing the lock. If the caller releases the lock,
1375 * iocb slot returned by the function is not guaranteed to be available.
1376 * The function returns pointer to the next available iocb slot if there
1377 * is available slot in the ring, else it returns NULL.
1378 * If the get index of the ring is ahead of the put index, the function
1379 * will post an error attention event to the worker thread to take the
1380 * HBA to offline state.
1383 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1385 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1386 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1388 lockdep_assert_held(&phba
->hbalock
);
1390 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1391 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1392 pring
->sli
.sli3
.next_cmdidx
= 0;
1394 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1395 pring
->sli
.sli3
.next_cmdidx
)) {
1397 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1399 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1400 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1401 "0315 Ring %d issue: portCmdGet %d "
1402 "is bigger than cmd ring %d\n",
1404 pring
->sli
.sli3
.local_getidx
,
1407 phba
->link_state
= LPFC_HBA_ERROR
;
1409 * All error attention handlers are posted to
1412 phba
->work_ha
|= HA_ERATT
;
1413 phba
->work_hs
= HS_FFER3
;
1415 lpfc_worker_wake_up(phba
);
1420 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1424 return lpfc_cmd_iocb(phba
, pring
);
1428 * lpfc_sli_next_iotag - Get an iotag for the iocb
1429 * @phba: Pointer to HBA context object.
1430 * @iocbq: Pointer to driver iocb object.
1432 * This function gets an iotag for the iocb. If there is no unused iotag and
1433 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1434 * array and assigns a new iotag.
1435 * The function returns the allocated iotag if successful, else returns zero.
1436 * Zero is not a valid iotag.
1437 * The caller is not required to hold any lock.
1440 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1442 struct lpfc_iocbq
**new_arr
;
1443 struct lpfc_iocbq
**old_arr
;
1445 struct lpfc_sli
*psli
= &phba
->sli
;
1448 spin_lock_irq(&phba
->hbalock
);
1449 iotag
= psli
->last_iotag
;
1450 if(++iotag
< psli
->iocbq_lookup_len
) {
1451 psli
->last_iotag
= iotag
;
1452 psli
->iocbq_lookup
[iotag
] = iocbq
;
1453 spin_unlock_irq(&phba
->hbalock
);
1454 iocbq
->iotag
= iotag
;
1456 } else if (psli
->iocbq_lookup_len
< (0xffff
1457 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1458 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1459 spin_unlock_irq(&phba
->hbalock
);
1460 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1463 spin_lock_irq(&phba
->hbalock
);
1464 old_arr
= psli
->iocbq_lookup
;
1465 if (new_len
<= psli
->iocbq_lookup_len
) {
1466 /* highly unprobable case */
1468 iotag
= psli
->last_iotag
;
1469 if(++iotag
< psli
->iocbq_lookup_len
) {
1470 psli
->last_iotag
= iotag
;
1471 psli
->iocbq_lookup
[iotag
] = iocbq
;
1472 spin_unlock_irq(&phba
->hbalock
);
1473 iocbq
->iotag
= iotag
;
1476 spin_unlock_irq(&phba
->hbalock
);
1479 if (psli
->iocbq_lookup
)
1480 memcpy(new_arr
, old_arr
,
1481 ((psli
->last_iotag
+ 1) *
1482 sizeof (struct lpfc_iocbq
*)));
1483 psli
->iocbq_lookup
= new_arr
;
1484 psli
->iocbq_lookup_len
= new_len
;
1485 psli
->last_iotag
= iotag
;
1486 psli
->iocbq_lookup
[iotag
] = iocbq
;
1487 spin_unlock_irq(&phba
->hbalock
);
1488 iocbq
->iotag
= iotag
;
1493 spin_unlock_irq(&phba
->hbalock
);
1495 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1496 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1503 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1504 * @phba: Pointer to HBA context object.
1505 * @pring: Pointer to driver SLI ring object.
1506 * @iocb: Pointer to iocb slot in the ring.
1507 * @nextiocb: Pointer to driver iocb object which need to be
1508 * posted to firmware.
1510 * This function is called with hbalock held to post a new iocb to
1511 * the firmware. This function copies the new iocb to ring iocb slot and
1512 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1513 * a completion call back for this iocb else the function will free the
1517 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1518 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1520 lockdep_assert_held(&phba
->hbalock
);
1524 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1527 if (pring
->ringno
== LPFC_ELS_RING
) {
1528 lpfc_debugfs_slow_ring_trc(phba
,
1529 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1530 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1531 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1532 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1536 * Issue iocb command to adapter
1538 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1540 pring
->stats
.iocb_cmd
++;
1543 * If there is no completion routine to call, we can release the
1544 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1545 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1547 if (nextiocb
->iocb_cmpl
)
1548 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1550 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1553 * Let the HBA know what IOCB slot will be the next one the
1554 * driver will put a command into.
1556 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1557 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1561 * lpfc_sli_update_full_ring - Update the chip attention register
1562 * @phba: Pointer to HBA context object.
1563 * @pring: Pointer to driver SLI ring object.
1565 * The caller is not required to hold any lock for calling this function.
1566 * This function updates the chip attention bits for the ring to inform firmware
1567 * that there are pending work to be done for this ring and requests an
1568 * interrupt when there is space available in the ring. This function is
1569 * called when the driver is unable to post more iocbs to the ring due
1570 * to unavailability of space in the ring.
1573 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1575 int ringno
= pring
->ringno
;
1577 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1582 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1583 * The HBA will tell us when an IOCB entry is available.
1585 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1586 readl(phba
->CAregaddr
); /* flush */
1588 pring
->stats
.iocb_cmd_full
++;
1592 * lpfc_sli_update_ring - Update chip attention register
1593 * @phba: Pointer to HBA context object.
1594 * @pring: Pointer to driver SLI ring object.
1596 * This function updates the chip attention register bit for the
1597 * given ring to inform HBA that there is more work to be done
1598 * in this ring. The caller is not required to hold any lock.
1601 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1603 int ringno
= pring
->ringno
;
1606 * Tell the HBA that there is work to do in this ring.
1608 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1610 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1611 readl(phba
->CAregaddr
); /* flush */
1616 * lpfc_sli_resume_iocb - Process iocbs in the txq
1617 * @phba: Pointer to HBA context object.
1618 * @pring: Pointer to driver SLI ring object.
1620 * This function is called with hbalock held to post pending iocbs
1621 * in the txq to the firmware. This function is called when driver
1622 * detects space available in the ring.
1625 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1628 struct lpfc_iocbq
*nextiocb
;
1630 lockdep_assert_held(&phba
->hbalock
);
1634 * (a) there is anything on the txq to send
1636 * (c) link attention events can be processed (fcp ring only)
1637 * (d) IOCB processing is not blocked by the outstanding mbox command.
1640 if (lpfc_is_link_up(phba
) &&
1641 (!list_empty(&pring
->txq
)) &&
1642 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1643 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1645 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1646 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1647 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1650 lpfc_sli_update_ring(phba
, pring
);
1652 lpfc_sli_update_full_ring(phba
, pring
);
1659 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1660 * @phba: Pointer to HBA context object.
1661 * @hbqno: HBQ number.
1663 * This function is called with hbalock held to get the next
1664 * available slot for the given HBQ. If there is free slot
1665 * available for the HBQ it will return pointer to the next available
1666 * HBQ entry else it will return NULL.
1668 static struct lpfc_hbq_entry
*
1669 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1671 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1673 lockdep_assert_held(&phba
->hbalock
);
1675 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1676 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1677 hbqp
->next_hbqPutIdx
= 0;
1679 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1680 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1681 uint32_t getidx
= le32_to_cpu(raw_index
);
1683 hbqp
->local_hbqGetIdx
= getidx
;
1685 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1686 lpfc_printf_log(phba
, KERN_ERR
,
1687 LOG_SLI
| LOG_VPORT
,
1688 "1802 HBQ %d: local_hbqGetIdx "
1689 "%u is > than hbqp->entry_count %u\n",
1690 hbqno
, hbqp
->local_hbqGetIdx
,
1693 phba
->link_state
= LPFC_HBA_ERROR
;
1697 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1701 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1706 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1707 * @phba: Pointer to HBA context object.
1709 * This function is called with no lock held to free all the
1710 * hbq buffers while uninitializing the SLI interface. It also
1711 * frees the HBQ buffers returned by the firmware but not yet
1712 * processed by the upper layers.
1715 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1717 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1718 struct hbq_dmabuf
*hbq_buf
;
1719 unsigned long flags
;
1723 hbq_count
= lpfc_sli_hbq_count();
1724 /* Return all memory used by all HBQs */
1725 spin_lock_irqsave(&phba
->hbalock
, flags
);
1726 for (i
= 0; i
< hbq_count
; ++i
) {
1727 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1728 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1729 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1730 list_del(&hbq_buf
->dbuf
.list
);
1731 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1733 phba
->hbqs
[i
].buffer_count
= 0;
1735 /* Return all HBQ buffer that are in-fly */
1736 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1738 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1739 list_del(&hbq_buf
->dbuf
.list
);
1740 if (hbq_buf
->tag
== -1) {
1741 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1744 hbqno
= hbq_buf
->tag
>> 16;
1745 if (hbqno
>= LPFC_MAX_HBQS
)
1746 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1749 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1754 /* Mark the HBQs not in use */
1755 phba
->hbq_in_use
= 0;
1756 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1760 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1761 * @phba: Pointer to HBA context object.
1762 * @hbqno: HBQ number.
1763 * @hbq_buf: Pointer to HBQ buffer.
1765 * This function is called with the hbalock held to post a
1766 * hbq buffer to the firmware. If the function finds an empty
1767 * slot in the HBQ, it will post the buffer. The function will return
1768 * pointer to the hbq entry if it successfully post the buffer
1769 * else it will return NULL.
1772 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1773 struct hbq_dmabuf
*hbq_buf
)
1775 lockdep_assert_held(&phba
->hbalock
);
1776 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1780 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1781 * @phba: Pointer to HBA context object.
1782 * @hbqno: HBQ number.
1783 * @hbq_buf: Pointer to HBQ buffer.
1785 * This function is called with the hbalock held to post a hbq buffer to the
1786 * firmware. If the function finds an empty slot in the HBQ, it will post the
1787 * buffer and place it on the hbq_buffer_list. The function will return zero if
1788 * it successfully post the buffer else it will return an error.
1791 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1792 struct hbq_dmabuf
*hbq_buf
)
1794 struct lpfc_hbq_entry
*hbqe
;
1795 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1797 lockdep_assert_held(&phba
->hbalock
);
1798 /* Get next HBQ entry slot to use */
1799 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1801 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1803 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1804 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1805 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1806 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1807 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1808 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1810 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1811 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1813 readl(phba
->hbq_put
+ hbqno
);
1814 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1821 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1822 * @phba: Pointer to HBA context object.
1823 * @hbqno: HBQ number.
1824 * @hbq_buf: Pointer to HBQ buffer.
1826 * This function is called with the hbalock held to post an RQE to the SLI4
1827 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1828 * the hbq_buffer_list and return zero, otherwise it will return an error.
1831 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1832 struct hbq_dmabuf
*hbq_buf
)
1835 struct lpfc_rqe hrqe
;
1836 struct lpfc_rqe drqe
;
1838 lockdep_assert_held(&phba
->hbalock
);
1839 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1840 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1841 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1842 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1843 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1848 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1852 /* HBQ for ELS and CT traffic. */
1853 static struct lpfc_hbq_init lpfc_els_hbq
= {
1858 .ring_mask
= (1 << LPFC_ELS_RING
),
1864 /* HBQ for the extra ring if needed */
1865 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1870 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1877 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1883 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1884 * @phba: Pointer to HBA context object.
1885 * @hbqno: HBQ number.
1886 * @count: Number of HBQ buffers to be posted.
1888 * This function is called with no lock held to post more hbq buffers to the
1889 * given HBQ. The function returns the number of HBQ buffers successfully
1893 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1895 uint32_t i
, posted
= 0;
1896 unsigned long flags
;
1897 struct hbq_dmabuf
*hbq_buffer
;
1898 LIST_HEAD(hbq_buf_list
);
1899 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1902 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1903 lpfc_hbq_defs
[hbqno
]->entry_count
)
1904 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1905 phba
->hbqs
[hbqno
].buffer_count
;
1908 /* Allocate HBQ entries */
1909 for (i
= 0; i
< count
; i
++) {
1910 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1913 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1915 /* Check whether HBQ is still in use */
1916 spin_lock_irqsave(&phba
->hbalock
, flags
);
1917 if (!phba
->hbq_in_use
)
1919 while (!list_empty(&hbq_buf_list
)) {
1920 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1922 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1924 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1925 phba
->hbqs
[hbqno
].buffer_count
++;
1928 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1930 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1933 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1934 while (!list_empty(&hbq_buf_list
)) {
1935 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1937 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1943 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1944 * @phba: Pointer to HBA context object.
1947 * This function posts more buffers to the HBQ. This function
1948 * is called with no lock held. The function returns the number of HBQ entries
1949 * successfully allocated.
1952 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1954 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1957 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1958 lpfc_hbq_defs
[qno
]->add_count
);
1962 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1963 * @phba: Pointer to HBA context object.
1964 * @qno: HBQ queue number.
1966 * This function is called from SLI initialization code path with
1967 * no lock held to post initial HBQ buffers to firmware. The
1968 * function returns the number of HBQ entries successfully allocated.
1971 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1973 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1974 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1975 lpfc_hbq_defs
[qno
]->entry_count
);
1977 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1978 lpfc_hbq_defs
[qno
]->init_count
);
1982 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1983 * @phba: Pointer to HBA context object.
1984 * @hbqno: HBQ number.
1986 * This function removes the first hbq buffer on an hbq list and returns a
1987 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1989 static struct hbq_dmabuf
*
1990 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1992 struct lpfc_dmabuf
*d_buf
;
1994 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1997 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2001 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2002 * @phba: Pointer to HBA context object.
2003 * @tag: Tag of the hbq buffer.
2005 * This function searches for the hbq buffer associated with the given tag in
2006 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2007 * otherwise it returns NULL.
2009 static struct hbq_dmabuf
*
2010 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
2012 struct lpfc_dmabuf
*d_buf
;
2013 struct hbq_dmabuf
*hbq_buf
;
2017 if (hbqno
>= LPFC_MAX_HBQS
)
2020 spin_lock_irq(&phba
->hbalock
);
2021 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2022 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2023 if (hbq_buf
->tag
== tag
) {
2024 spin_unlock_irq(&phba
->hbalock
);
2028 spin_unlock_irq(&phba
->hbalock
);
2029 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2030 "1803 Bad hbq tag. Data: x%x x%x\n",
2031 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2036 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2037 * @phba: Pointer to HBA context object.
2038 * @hbq_buffer: Pointer to HBQ buffer.
2040 * This function is called with hbalock. This function gives back
2041 * the hbq buffer to firmware. If the HBQ does not have space to
2042 * post the buffer, it will free the buffer.
2045 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2050 hbqno
= hbq_buffer
->tag
>> 16;
2051 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2052 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2057 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2058 * @mbxCommand: mailbox command code.
2060 * This function is called by the mailbox event handler function to verify
2061 * that the completed mailbox command is a legitimate mailbox command. If the
2062 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2063 * and the mailbox event handler will take the HBA offline.
2066 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2070 switch (mbxCommand
) {
2074 case MBX_WRITE_VPARMS
:
2075 case MBX_RUN_BIU_DIAG
:
2078 case MBX_CONFIG_LINK
:
2079 case MBX_CONFIG_RING
:
2080 case MBX_RESET_RING
:
2081 case MBX_READ_CONFIG
:
2082 case MBX_READ_RCONFIG
:
2083 case MBX_READ_SPARM
:
2084 case MBX_READ_STATUS
:
2088 case MBX_READ_LNK_STAT
:
2090 case MBX_UNREG_LOGIN
:
2092 case MBX_DUMP_MEMORY
:
2093 case MBX_DUMP_CONTEXT
:
2096 case MBX_UPDATE_CFG
:
2098 case MBX_DEL_LD_ENTRY
:
2099 case MBX_RUN_PROGRAM
:
2101 case MBX_SET_VARIABLE
:
2102 case MBX_UNREG_D_ID
:
2103 case MBX_KILL_BOARD
:
2104 case MBX_CONFIG_FARP
:
2107 case MBX_RUN_BIU_DIAG64
:
2108 case MBX_CONFIG_PORT
:
2109 case MBX_READ_SPARM64
:
2110 case MBX_READ_RPI64
:
2111 case MBX_REG_LOGIN64
:
2112 case MBX_READ_TOPOLOGY
:
2115 case MBX_LOAD_EXP_ROM
:
2116 case MBX_ASYNCEVT_ENABLE
:
2120 case MBX_PORT_CAPABILITIES
:
2121 case MBX_PORT_IOV_CONTROL
:
2122 case MBX_SLI4_CONFIG
:
2123 case MBX_SLI4_REQ_FTRS
:
2125 case MBX_UNREG_FCFI
:
2130 case MBX_RESUME_RPI
:
2131 case MBX_READ_EVENT_LOG_STATUS
:
2132 case MBX_READ_EVENT_LOG
:
2133 case MBX_SECURITY_MGMT
:
2135 case MBX_ACCESS_VDATA
:
2146 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2147 * @phba: Pointer to HBA context object.
2148 * @pmboxq: Pointer to mailbox command.
2150 * This is completion handler function for mailbox commands issued from
2151 * lpfc_sli_issue_mbox_wait function. This function is called by the
2152 * mailbox event handler function with no lock held. This function
2153 * will wake up thread waiting on the wait queue pointed by context1
2157 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2159 wait_queue_head_t
*pdone_q
;
2160 unsigned long drvr_flag
;
2163 * If pdone_q is empty, the driver thread gave up waiting and
2164 * continued running.
2166 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2167 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2168 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2170 wake_up_interruptible(pdone_q
);
2171 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2177 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2178 * @phba: Pointer to HBA context object.
2179 * @pmb: Pointer to mailbox object.
2181 * This function is the default mailbox completion handler. It
2182 * frees the memory resources associated with the completed mailbox
2183 * command. If the completed command is a REG_LOGIN mailbox command,
2184 * this function will issue a UREG_LOGIN to re-claim the RPI.
2187 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2189 struct lpfc_vport
*vport
= pmb
->vport
;
2190 struct lpfc_dmabuf
*mp
;
2191 struct lpfc_nodelist
*ndlp
;
2192 struct Scsi_Host
*shost
;
2196 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2199 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2204 * If a REG_LOGIN succeeded after node is destroyed or node
2205 * is in re-discovery driver need to cleanup the RPI.
2207 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2208 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2209 !pmb
->u
.mb
.mbxStatus
) {
2210 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2211 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2212 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2214 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2215 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2216 if (rc
!= MBX_NOT_FINISHED
)
2220 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2221 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2222 !pmb
->u
.mb
.mbxStatus
) {
2223 shost
= lpfc_shost_from_vport(vport
);
2224 spin_lock_irq(shost
->host_lock
);
2225 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2226 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2227 spin_unlock_irq(shost
->host_lock
);
2230 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2231 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2233 pmb
->context2
= NULL
;
2236 /* Check security permission status on INIT_LINK mailbox command */
2237 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2238 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2239 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2240 "2860 SLI authentication is required "
2241 "for INIT_LINK but has not done yet\n");
2243 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2244 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2246 mempool_free(pmb
, phba
->mbox_mem_pool
);
2249 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2250 * @phba: Pointer to HBA context object.
2251 * @pmb: Pointer to mailbox object.
2253 * This function is the unreg rpi mailbox completion handler. It
2254 * frees the memory resources associated with the completed mailbox
2255 * command. An additional refrenece is put on the ndlp to prevent
2256 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2257 * the unreg mailbox command completes, this routine puts the
2262 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2264 struct lpfc_vport
*vport
= pmb
->vport
;
2265 struct lpfc_nodelist
*ndlp
;
2267 ndlp
= pmb
->context1
;
2268 if (pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) {
2269 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2270 (bf_get(lpfc_sli_intf_if_type
,
2271 &phba
->sli4_hba
.sli_intf
) ==
2272 LPFC_SLI_INTF_IF_TYPE_2
)) {
2274 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
2275 "0010 UNREG_LOGIN vpi:%x "
2276 "rpi:%x DID:%x map:%x %p\n",
2277 vport
->vpi
, ndlp
->nlp_rpi
,
2279 ndlp
->nlp_usg_map
, ndlp
);
2280 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2286 mempool_free(pmb
, phba
->mbox_mem_pool
);
2290 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2291 * @phba: Pointer to HBA context object.
2293 * This function is called with no lock held. This function processes all
2294 * the completed mailbox commands and gives it to upper layers. The interrupt
2295 * service routine processes mailbox completion interrupt and adds completed
2296 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2297 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2298 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2299 * function returns the mailbox commands to the upper layer by calling the
2300 * completion handler function of each mailbox.
2303 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2310 phba
->sli
.slistat
.mbox_event
++;
2312 /* Get all completed mailboxe buffers into the cmplq */
2313 spin_lock_irq(&phba
->hbalock
);
2314 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2315 spin_unlock_irq(&phba
->hbalock
);
2317 /* Get a Mailbox buffer to setup mailbox commands for callback */
2319 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2325 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2327 lpfc_debugfs_disc_trc(pmb
->vport
,
2328 LPFC_DISC_TRC_MBOX_VPORT
,
2329 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2330 (uint32_t)pmbox
->mbxCommand
,
2331 pmbox
->un
.varWords
[0],
2332 pmbox
->un
.varWords
[1]);
2335 lpfc_debugfs_disc_trc(phba
->pport
,
2337 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2338 (uint32_t)pmbox
->mbxCommand
,
2339 pmbox
->un
.varWords
[0],
2340 pmbox
->un
.varWords
[1]);
2345 * It is a fatal error if unknown mbox command completion.
2347 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2349 /* Unknown mailbox command compl */
2350 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2351 "(%d):0323 Unknown Mailbox command "
2352 "x%x (x%x/x%x) Cmpl\n",
2353 pmb
->vport
? pmb
->vport
->vpi
: 0,
2355 lpfc_sli_config_mbox_subsys_get(phba
,
2357 lpfc_sli_config_mbox_opcode_get(phba
,
2359 phba
->link_state
= LPFC_HBA_ERROR
;
2360 phba
->work_hs
= HS_FFER3
;
2361 lpfc_handle_eratt(phba
);
2365 if (pmbox
->mbxStatus
) {
2366 phba
->sli
.slistat
.mbox_stat_err
++;
2367 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2368 /* Mbox cmd cmpl error - RETRYing */
2369 lpfc_printf_log(phba
, KERN_INFO
,
2371 "(%d):0305 Mbox cmd cmpl "
2372 "error - RETRYing Data: x%x "
2373 "(x%x/x%x) x%x x%x x%x\n",
2374 pmb
->vport
? pmb
->vport
->vpi
: 0,
2376 lpfc_sli_config_mbox_subsys_get(phba
,
2378 lpfc_sli_config_mbox_opcode_get(phba
,
2381 pmbox
->un
.varWords
[0],
2382 pmb
->vport
->port_state
);
2383 pmbox
->mbxStatus
= 0;
2384 pmbox
->mbxOwner
= OWN_HOST
;
2385 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2386 if (rc
!= MBX_NOT_FINISHED
)
2391 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2392 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2393 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2394 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2396 pmb
->vport
? pmb
->vport
->vpi
: 0,
2398 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2399 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2401 *((uint32_t *) pmbox
),
2402 pmbox
->un
.varWords
[0],
2403 pmbox
->un
.varWords
[1],
2404 pmbox
->un
.varWords
[2],
2405 pmbox
->un
.varWords
[3],
2406 pmbox
->un
.varWords
[4],
2407 pmbox
->un
.varWords
[5],
2408 pmbox
->un
.varWords
[6],
2409 pmbox
->un
.varWords
[7],
2410 pmbox
->un
.varWords
[8],
2411 pmbox
->un
.varWords
[9],
2412 pmbox
->un
.varWords
[10]);
2415 pmb
->mbox_cmpl(phba
,pmb
);
2421 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2422 * @phba: Pointer to HBA context object.
2423 * @pring: Pointer to driver SLI ring object.
2426 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2427 * is set in the tag the buffer is posted for a particular exchange,
2428 * the function will return the buffer without replacing the buffer.
2429 * If the buffer is for unsolicited ELS or CT traffic, this function
2430 * returns the buffer and also posts another buffer to the firmware.
2432 static struct lpfc_dmabuf
*
2433 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2434 struct lpfc_sli_ring
*pring
,
2437 struct hbq_dmabuf
*hbq_entry
;
2439 if (tag
& QUE_BUFTAG_BIT
)
2440 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2441 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2444 return &hbq_entry
->dbuf
;
2448 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2449 * @phba: Pointer to HBA context object.
2450 * @pring: Pointer to driver SLI ring object.
2451 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2452 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2453 * @fch_type: the type for the first frame of the sequence.
2455 * This function is called with no lock held. This function uses the r_ctl and
2456 * type of the received sequence to find the correct callback function to call
2457 * to process the sequence.
2460 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2461 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2466 /* unSolicited Responses */
2467 if (pring
->prt
[0].profile
) {
2468 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2469 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2473 /* We must search, based on rctl / type
2474 for the right routine */
2475 for (i
= 0; i
< pring
->num_mask
; i
++) {
2476 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2477 (pring
->prt
[i
].type
== fch_type
)) {
2478 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2479 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2480 (phba
, pring
, saveq
);
2488 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2489 * @phba: Pointer to HBA context object.
2490 * @pring: Pointer to driver SLI ring object.
2491 * @saveq: Pointer to the unsolicited iocb.
2493 * This function is called with no lock held by the ring event handler
2494 * when there is an unsolicited iocb posted to the response ring by the
2495 * firmware. This function gets the buffer associated with the iocbs
2496 * and calls the event handler for the ring. This function handles both
2497 * qring buffers and hbq buffers.
2498 * When the function returns 1 the caller can free the iocb object otherwise
2499 * upper layer functions will free the iocb objects.
2502 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2503 struct lpfc_iocbq
*saveq
)
2507 uint32_t Rctl
, Type
;
2508 struct lpfc_iocbq
*iocbq
;
2509 struct lpfc_dmabuf
*dmzbuf
;
2511 irsp
= &(saveq
->iocb
);
2513 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2514 if (pring
->lpfc_sli_rcv_async_status
)
2515 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2517 lpfc_printf_log(phba
,
2520 "0316 Ring %d handler: unexpected "
2521 "ASYNC_STATUS iocb received evt_code "
2524 irsp
->un
.asyncstat
.evt_code
);
2528 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2529 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2530 if (irsp
->ulpBdeCount
> 0) {
2531 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2532 irsp
->un
.ulpWord
[3]);
2533 lpfc_in_buf_free(phba
, dmzbuf
);
2536 if (irsp
->ulpBdeCount
> 1) {
2537 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2538 irsp
->unsli3
.sli3Words
[3]);
2539 lpfc_in_buf_free(phba
, dmzbuf
);
2542 if (irsp
->ulpBdeCount
> 2) {
2543 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2544 irsp
->unsli3
.sli3Words
[7]);
2545 lpfc_in_buf_free(phba
, dmzbuf
);
2551 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2552 if (irsp
->ulpBdeCount
!= 0) {
2553 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2554 irsp
->un
.ulpWord
[3]);
2555 if (!saveq
->context2
)
2556 lpfc_printf_log(phba
,
2559 "0341 Ring %d Cannot find buffer for "
2560 "an unsolicited iocb. tag 0x%x\n",
2562 irsp
->un
.ulpWord
[3]);
2564 if (irsp
->ulpBdeCount
== 2) {
2565 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2566 irsp
->unsli3
.sli3Words
[7]);
2567 if (!saveq
->context3
)
2568 lpfc_printf_log(phba
,
2571 "0342 Ring %d Cannot find buffer for an"
2572 " unsolicited iocb. tag 0x%x\n",
2574 irsp
->unsli3
.sli3Words
[7]);
2576 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2577 irsp
= &(iocbq
->iocb
);
2578 if (irsp
->ulpBdeCount
!= 0) {
2579 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2580 irsp
->un
.ulpWord
[3]);
2581 if (!iocbq
->context2
)
2582 lpfc_printf_log(phba
,
2585 "0343 Ring %d Cannot find "
2586 "buffer for an unsolicited iocb"
2587 ". tag 0x%x\n", pring
->ringno
,
2588 irsp
->un
.ulpWord
[3]);
2590 if (irsp
->ulpBdeCount
== 2) {
2591 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2592 irsp
->unsli3
.sli3Words
[7]);
2593 if (!iocbq
->context3
)
2594 lpfc_printf_log(phba
,
2597 "0344 Ring %d Cannot find "
2598 "buffer for an unsolicited "
2601 irsp
->unsli3
.sli3Words
[7]);
2605 if (irsp
->ulpBdeCount
!= 0 &&
2606 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2607 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2610 /* search continue save q for same XRI */
2611 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2612 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2613 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2614 list_add_tail(&saveq
->list
, &iocbq
->list
);
2620 list_add_tail(&saveq
->clist
,
2621 &pring
->iocb_continue_saveq
);
2622 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2623 list_del_init(&iocbq
->clist
);
2625 irsp
= &(saveq
->iocb
);
2629 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2630 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2631 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2632 Rctl
= FC_RCTL_ELS_REQ
;
2635 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2636 Rctl
= w5p
->hcsw
.Rctl
;
2637 Type
= w5p
->hcsw
.Type
;
2639 /* Firmware Workaround */
2640 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2641 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2642 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2643 Rctl
= FC_RCTL_ELS_REQ
;
2645 w5p
->hcsw
.Rctl
= Rctl
;
2646 w5p
->hcsw
.Type
= Type
;
2650 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2651 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2652 "0313 Ring %d handler: unexpected Rctl x%x "
2653 "Type x%x received\n",
2654 pring
->ringno
, Rctl
, Type
);
2660 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2661 * @phba: Pointer to HBA context object.
2662 * @pring: Pointer to driver SLI ring object.
2663 * @prspiocb: Pointer to response iocb object.
2665 * This function looks up the iocb_lookup table to get the command iocb
2666 * corresponding to the given response iocb using the iotag of the
2667 * response iocb. This function is called with the hbalock held.
2668 * This function returns the command iocb object if it finds the command
2669 * iocb else returns NULL.
2671 static struct lpfc_iocbq
*
2672 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2673 struct lpfc_sli_ring
*pring
,
2674 struct lpfc_iocbq
*prspiocb
)
2676 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2678 lockdep_assert_held(&phba
->hbalock
);
2680 iotag
= prspiocb
->iocb
.ulpIoTag
;
2682 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2683 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2684 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2685 /* remove from txcmpl queue list */
2686 list_del_init(&cmd_iocb
->list
);
2687 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2692 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2693 "0317 iotag x%x is out of "
2694 "range: max iotag x%x wd0 x%x\n",
2695 iotag
, phba
->sli
.last_iotag
,
2696 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2701 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2702 * @phba: Pointer to HBA context object.
2703 * @pring: Pointer to driver SLI ring object.
2706 * This function looks up the iocb_lookup table to get the command iocb
2707 * corresponding to the given iotag. This function is called with the
2709 * This function returns the command iocb object if it finds the command
2710 * iocb else returns NULL.
2712 static struct lpfc_iocbq
*
2713 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2714 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2716 struct lpfc_iocbq
*cmd_iocb
;
2718 lockdep_assert_held(&phba
->hbalock
);
2719 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2720 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2721 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2722 /* remove from txcmpl queue list */
2723 list_del_init(&cmd_iocb
->list
);
2724 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2729 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2730 "0372 iotag x%x is out of range: max iotag (x%x)\n",
2731 iotag
, phba
->sli
.last_iotag
);
2736 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2737 * @phba: Pointer to HBA context object.
2738 * @pring: Pointer to driver SLI ring object.
2739 * @saveq: Pointer to the response iocb to be processed.
2741 * This function is called by the ring event handler for non-fcp
2742 * rings when there is a new response iocb in the response ring.
2743 * The caller is not required to hold any locks. This function
2744 * gets the command iocb associated with the response iocb and
2745 * calls the completion handler for the command iocb. If there
2746 * is no completion handler, the function will free the resources
2747 * associated with command iocb. If the response iocb is for
2748 * an already aborted command iocb, the status of the completion
2749 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2750 * This function always returns 1.
2753 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2754 struct lpfc_iocbq
*saveq
)
2756 struct lpfc_iocbq
*cmdiocbp
;
2758 unsigned long iflag
;
2760 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2761 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2762 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2763 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2766 if (cmdiocbp
->iocb_cmpl
) {
2768 * If an ELS command failed send an event to mgmt
2771 if (saveq
->iocb
.ulpStatus
&&
2772 (pring
->ringno
== LPFC_ELS_RING
) &&
2773 (cmdiocbp
->iocb
.ulpCommand
==
2774 CMD_ELS_REQUEST64_CR
))
2775 lpfc_send_els_failure_event(phba
,
2779 * Post all ELS completions to the worker thread.
2780 * All other are passed to the completion callback.
2782 if (pring
->ringno
== LPFC_ELS_RING
) {
2783 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2784 (cmdiocbp
->iocb_flag
&
2785 LPFC_DRIVER_ABORTED
)) {
2786 spin_lock_irqsave(&phba
->hbalock
,
2788 cmdiocbp
->iocb_flag
&=
2789 ~LPFC_DRIVER_ABORTED
;
2790 spin_unlock_irqrestore(&phba
->hbalock
,
2792 saveq
->iocb
.ulpStatus
=
2793 IOSTAT_LOCAL_REJECT
;
2794 saveq
->iocb
.un
.ulpWord
[4] =
2797 /* Firmware could still be in progress
2798 * of DMAing payload, so don't free data
2799 * buffer till after a hbeat.
2801 spin_lock_irqsave(&phba
->hbalock
,
2803 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2804 spin_unlock_irqrestore(&phba
->hbalock
,
2807 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2808 if (saveq
->iocb_flag
&
2809 LPFC_EXCHANGE_BUSY
) {
2810 /* Set cmdiocb flag for the
2811 * exchange busy so sgl (xri)
2812 * will not be released until
2813 * the abort xri is received
2817 &phba
->hbalock
, iflag
);
2818 cmdiocbp
->iocb_flag
|=
2820 spin_unlock_irqrestore(
2821 &phba
->hbalock
, iflag
);
2823 if (cmdiocbp
->iocb_flag
&
2824 LPFC_DRIVER_ABORTED
) {
2826 * Clear LPFC_DRIVER_ABORTED
2827 * bit in case it was driver
2831 &phba
->hbalock
, iflag
);
2832 cmdiocbp
->iocb_flag
&=
2833 ~LPFC_DRIVER_ABORTED
;
2834 spin_unlock_irqrestore(
2835 &phba
->hbalock
, iflag
);
2836 cmdiocbp
->iocb
.ulpStatus
=
2837 IOSTAT_LOCAL_REJECT
;
2838 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2839 IOERR_ABORT_REQUESTED
;
2841 * For SLI4, irsiocb contains
2842 * NO_XRI in sli_xritag, it
2843 * shall not affect releasing
2844 * sgl (xri) process.
2846 saveq
->iocb
.ulpStatus
=
2847 IOSTAT_LOCAL_REJECT
;
2848 saveq
->iocb
.un
.ulpWord
[4] =
2851 &phba
->hbalock
, iflag
);
2853 LPFC_DELAY_MEM_FREE
;
2854 spin_unlock_irqrestore(
2855 &phba
->hbalock
, iflag
);
2859 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2861 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2864 * Unknown initiating command based on the response iotag.
2865 * This could be the case on the ELS ring because of
2868 if (pring
->ringno
!= LPFC_ELS_RING
) {
2870 * Ring <ringno> handler: unexpected completion IoTag
2873 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2874 "0322 Ring %d handler: "
2875 "unexpected completion IoTag x%x "
2876 "Data: x%x x%x x%x x%x\n",
2878 saveq
->iocb
.ulpIoTag
,
2879 saveq
->iocb
.ulpStatus
,
2880 saveq
->iocb
.un
.ulpWord
[4],
2881 saveq
->iocb
.ulpCommand
,
2882 saveq
->iocb
.ulpContext
);
2890 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2891 * @phba: Pointer to HBA context object.
2892 * @pring: Pointer to driver SLI ring object.
2894 * This function is called from the iocb ring event handlers when
2895 * put pointer is ahead of the get pointer for a ring. This function signal
2896 * an error attention condition to the worker thread and the worker
2897 * thread will transition the HBA to offline state.
2900 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2902 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2904 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2905 * rsp ring <portRspMax>
2907 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2908 "0312 Ring %d handler: portRspPut %d "
2909 "is bigger than rsp ring %d\n",
2910 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2911 pring
->sli
.sli3
.numRiocb
);
2913 phba
->link_state
= LPFC_HBA_ERROR
;
2916 * All error attention handlers are posted to
2919 phba
->work_ha
|= HA_ERATT
;
2920 phba
->work_hs
= HS_FFER3
;
2922 lpfc_worker_wake_up(phba
);
2928 * lpfc_poll_eratt - Error attention polling timer timeout handler
2929 * @ptr: Pointer to address of HBA context object.
2931 * This function is invoked by the Error Attention polling timer when the
2932 * timer times out. It will check the SLI Error Attention register for
2933 * possible attention events. If so, it will post an Error Attention event
2934 * and wake up worker thread to process it. Otherwise, it will set up the
2935 * Error Attention polling timer for the next poll.
2937 void lpfc_poll_eratt(unsigned long ptr
)
2939 struct lpfc_hba
*phba
;
2941 uint64_t sli_intr
, cnt
;
2943 phba
= (struct lpfc_hba
*)ptr
;
2945 /* Here we will also keep track of interrupts per sec of the hba */
2946 sli_intr
= phba
->sli
.slistat
.sli_intr
;
2948 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
2949 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
2952 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
2954 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
2955 do_div(cnt
, phba
->eratt_poll_interval
);
2956 phba
->sli
.slistat
.sli_ips
= cnt
;
2958 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
2960 /* Check chip HA register for error event */
2961 eratt
= lpfc_sli_check_eratt(phba
);
2964 /* Tell the worker thread there is work to do */
2965 lpfc_worker_wake_up(phba
);
2967 /* Restart the timer for next eratt poll */
2968 mod_timer(&phba
->eratt_poll
,
2970 msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
2976 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2977 * @phba: Pointer to HBA context object.
2978 * @pring: Pointer to driver SLI ring object.
2979 * @mask: Host attention register mask for this ring.
2981 * This function is called from the interrupt context when there is a ring
2982 * event for the fcp ring. The caller does not hold any lock.
2983 * The function processes each response iocb in the response ring until it
2984 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2985 * LE bit set. The function will call the completion handler of the command iocb
2986 * if the response iocb indicates a completion for a command iocb or it is
2987 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2988 * function if this is an unsolicited iocb.
2989 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2990 * to check it explicitly.
2993 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2994 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2996 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2997 IOCB_t
*irsp
= NULL
;
2998 IOCB_t
*entry
= NULL
;
2999 struct lpfc_iocbq
*cmdiocbq
= NULL
;
3000 struct lpfc_iocbq rspiocbq
;
3002 uint32_t portRspPut
, portRspMax
;
3004 lpfc_iocb_type type
;
3005 unsigned long iflag
;
3006 uint32_t rsp_cmpl
= 0;
3008 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3009 pring
->stats
.iocb_event
++;
3012 * The next available response entry should never exceed the maximum
3013 * entries. If it does, treat it as an adapter hardware error.
3015 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3016 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3017 if (unlikely(portRspPut
>= portRspMax
)) {
3018 lpfc_sli_rsp_pointers_error(phba
, pring
);
3019 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3022 if (phba
->fcp_ring_in_use
) {
3023 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3026 phba
->fcp_ring_in_use
= 1;
3029 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3031 * Fetch an entry off the ring and copy it into a local data
3032 * structure. The copy involves a byte-swap since the
3033 * network byte order and pci byte orders are different.
3035 entry
= lpfc_resp_iocb(phba
, pring
);
3036 phba
->last_completion_time
= jiffies
;
3038 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3039 pring
->sli
.sli3
.rspidx
= 0;
3041 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
3042 (uint32_t *) &rspiocbq
.iocb
,
3043 phba
->iocb_rsp_size
);
3044 INIT_LIST_HEAD(&(rspiocbq
.list
));
3045 irsp
= &rspiocbq
.iocb
;
3047 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
3048 pring
->stats
.iocb_rsp
++;
3051 if (unlikely(irsp
->ulpStatus
)) {
3053 * If resource errors reported from HBA, reduce
3054 * queuedepths of the SCSI device.
3056 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3057 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3058 IOERR_NO_RESOURCES
)) {
3059 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3060 phba
->lpfc_rampdown_queue_depth(phba
);
3061 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3064 /* Rsp ring <ringno> error: IOCB */
3065 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3066 "0336 Rsp Ring %d error: IOCB Data: "
3067 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3069 irsp
->un
.ulpWord
[0],
3070 irsp
->un
.ulpWord
[1],
3071 irsp
->un
.ulpWord
[2],
3072 irsp
->un
.ulpWord
[3],
3073 irsp
->un
.ulpWord
[4],
3074 irsp
->un
.ulpWord
[5],
3075 *(uint32_t *)&irsp
->un1
,
3076 *((uint32_t *)&irsp
->un1
+ 1));
3080 case LPFC_ABORT_IOCB
:
3083 * Idle exchange closed via ABTS from port. No iocb
3084 * resources need to be recovered.
3086 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3087 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3088 "0333 IOCB cmd 0x%x"
3089 " processed. Skipping"
3095 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3097 if (unlikely(!cmdiocbq
))
3099 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3100 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3101 if (cmdiocbq
->iocb_cmpl
) {
3102 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3103 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3105 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3108 case LPFC_UNSOL_IOCB
:
3109 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3110 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3111 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3114 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3115 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3116 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3117 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3119 dev_warn(&((phba
->pcidev
)->dev
),
3121 phba
->brd_no
, adaptermsg
);
3123 /* Unknown IOCB command */
3124 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3125 "0334 Unknown IOCB command "
3126 "Data: x%x, x%x x%x x%x x%x\n",
3127 type
, irsp
->ulpCommand
,
3136 * The response IOCB has been processed. Update the ring
3137 * pointer in SLIM. If the port response put pointer has not
3138 * been updated, sync the pgp->rspPutInx and fetch the new port
3139 * response put pointer.
3141 writel(pring
->sli
.sli3
.rspidx
,
3142 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3144 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3145 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3148 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3149 pring
->stats
.iocb_rsp_full
++;
3150 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3151 writel(status
, phba
->CAregaddr
);
3152 readl(phba
->CAregaddr
);
3154 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3155 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3156 pring
->stats
.iocb_cmd_empty
++;
3158 /* Force update of the local copy of cmdGetInx */
3159 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3160 lpfc_sli_resume_iocb(phba
, pring
);
3162 if ((pring
->lpfc_sli_cmd_available
))
3163 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3167 phba
->fcp_ring_in_use
= 0;
3168 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3173 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3174 * @phba: Pointer to HBA context object.
3175 * @pring: Pointer to driver SLI ring object.
3176 * @rspiocbp: Pointer to driver response IOCB object.
3178 * This function is called from the worker thread when there is a slow-path
3179 * response IOCB to process. This function chains all the response iocbs until
3180 * seeing the iocb with the LE bit set. The function will call
3181 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3182 * completion of a command iocb. The function will call the
3183 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3184 * The function frees the resources or calls the completion handler if this
3185 * iocb is an abort completion. The function returns NULL when the response
3186 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3187 * this function shall chain the iocb on to the iocb_continueq and return the
3188 * response iocb passed in.
3190 static struct lpfc_iocbq
*
3191 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3192 struct lpfc_iocbq
*rspiocbp
)
3194 struct lpfc_iocbq
*saveq
;
3195 struct lpfc_iocbq
*cmdiocbp
;
3196 struct lpfc_iocbq
*next_iocb
;
3197 IOCB_t
*irsp
= NULL
;
3198 uint32_t free_saveq
;
3199 uint8_t iocb_cmd_type
;
3200 lpfc_iocb_type type
;
3201 unsigned long iflag
;
3204 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3205 /* First add the response iocb to the countinueq list */
3206 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3207 pring
->iocb_continueq_cnt
++;
3209 /* Now, determine whether the list is completed for processing */
3210 irsp
= &rspiocbp
->iocb
;
3213 * By default, the driver expects to free all resources
3214 * associated with this iocb completion.
3217 saveq
= list_get_first(&pring
->iocb_continueq
,
3218 struct lpfc_iocbq
, list
);
3219 irsp
= &(saveq
->iocb
);
3220 list_del_init(&pring
->iocb_continueq
);
3221 pring
->iocb_continueq_cnt
= 0;
3223 pring
->stats
.iocb_rsp
++;
3226 * If resource errors reported from HBA, reduce
3227 * queuedepths of the SCSI device.
3229 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3230 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3231 IOERR_NO_RESOURCES
)) {
3232 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3233 phba
->lpfc_rampdown_queue_depth(phba
);
3234 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3237 if (irsp
->ulpStatus
) {
3238 /* Rsp ring <ringno> error: IOCB */
3239 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3240 "0328 Rsp Ring %d error: "
3245 "x%x x%x x%x x%x\n",
3247 irsp
->un
.ulpWord
[0],
3248 irsp
->un
.ulpWord
[1],
3249 irsp
->un
.ulpWord
[2],
3250 irsp
->un
.ulpWord
[3],
3251 irsp
->un
.ulpWord
[4],
3252 irsp
->un
.ulpWord
[5],
3253 *(((uint32_t *) irsp
) + 6),
3254 *(((uint32_t *) irsp
) + 7),
3255 *(((uint32_t *) irsp
) + 8),
3256 *(((uint32_t *) irsp
) + 9),
3257 *(((uint32_t *) irsp
) + 10),
3258 *(((uint32_t *) irsp
) + 11),
3259 *(((uint32_t *) irsp
) + 12),
3260 *(((uint32_t *) irsp
) + 13),
3261 *(((uint32_t *) irsp
) + 14),
3262 *(((uint32_t *) irsp
) + 15));
3266 * Fetch the IOCB command type and call the correct completion
3267 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3268 * get freed back to the lpfc_iocb_list by the discovery
3271 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3272 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3275 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3276 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3277 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3280 case LPFC_UNSOL_IOCB
:
3281 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3282 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3283 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3288 case LPFC_ABORT_IOCB
:
3290 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3291 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3294 /* Call the specified completion routine */
3295 if (cmdiocbp
->iocb_cmpl
) {
3296 spin_unlock_irqrestore(&phba
->hbalock
,
3298 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3300 spin_lock_irqsave(&phba
->hbalock
,
3303 __lpfc_sli_release_iocbq(phba
,
3308 case LPFC_UNKNOWN_IOCB
:
3309 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3310 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3311 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3312 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3314 dev_warn(&((phba
->pcidev
)->dev
),
3316 phba
->brd_no
, adaptermsg
);
3318 /* Unknown IOCB command */
3319 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3320 "0335 Unknown IOCB "
3321 "command Data: x%x "
3332 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3333 &saveq
->list
, list
) {
3334 list_del_init(&rspiocbp
->list
);
3335 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3337 __lpfc_sli_release_iocbq(phba
, saveq
);
3341 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3346 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3347 * @phba: Pointer to HBA context object.
3348 * @pring: Pointer to driver SLI ring object.
3349 * @mask: Host attention register mask for this ring.
3351 * This routine wraps the actual slow_ring event process routine from the
3352 * API jump table function pointer from the lpfc_hba struct.
3355 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3356 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3358 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3362 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3363 * @phba: Pointer to HBA context object.
3364 * @pring: Pointer to driver SLI ring object.
3365 * @mask: Host attention register mask for this ring.
3367 * This function is called from the worker thread when there is a ring event
3368 * for non-fcp rings. The caller does not hold any lock. The function will
3369 * remove each response iocb in the response ring and calls the handle
3370 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3373 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3374 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3376 struct lpfc_pgp
*pgp
;
3378 IOCB_t
*irsp
= NULL
;
3379 struct lpfc_iocbq
*rspiocbp
= NULL
;
3380 uint32_t portRspPut
, portRspMax
;
3381 unsigned long iflag
;
3384 pgp
= &phba
->port_gp
[pring
->ringno
];
3385 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3386 pring
->stats
.iocb_event
++;
3389 * The next available response entry should never exceed the maximum
3390 * entries. If it does, treat it as an adapter hardware error.
3392 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3393 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3394 if (portRspPut
>= portRspMax
) {
3396 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3397 * rsp ring <portRspMax>
3399 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3400 "0303 Ring %d handler: portRspPut %d "
3401 "is bigger than rsp ring %d\n",
3402 pring
->ringno
, portRspPut
, portRspMax
);
3404 phba
->link_state
= LPFC_HBA_ERROR
;
3405 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3407 phba
->work_hs
= HS_FFER3
;
3408 lpfc_handle_eratt(phba
);
3414 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3416 * Build a completion list and call the appropriate handler.
3417 * The process is to get the next available response iocb, get
3418 * a free iocb from the list, copy the response data into the
3419 * free iocb, insert to the continuation list, and update the
3420 * next response index to slim. This process makes response
3421 * iocb's in the ring available to DMA as fast as possible but
3422 * pays a penalty for a copy operation. Since the iocb is
3423 * only 32 bytes, this penalty is considered small relative to
3424 * the PCI reads for register values and a slim write. When
3425 * the ulpLe field is set, the entire Command has been
3428 entry
= lpfc_resp_iocb(phba
, pring
);
3430 phba
->last_completion_time
= jiffies
;
3431 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3432 if (rspiocbp
== NULL
) {
3433 printk(KERN_ERR
"%s: out of buffers! Failing "
3434 "completion.\n", __func__
);
3438 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3439 phba
->iocb_rsp_size
);
3440 irsp
= &rspiocbp
->iocb
;
3442 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3443 pring
->sli
.sli3
.rspidx
= 0;
3445 if (pring
->ringno
== LPFC_ELS_RING
) {
3446 lpfc_debugfs_slow_ring_trc(phba
,
3447 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3448 *(((uint32_t *) irsp
) + 4),
3449 *(((uint32_t *) irsp
) + 6),
3450 *(((uint32_t *) irsp
) + 7));
3453 writel(pring
->sli
.sli3
.rspidx
,
3454 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3456 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3457 /* Handle the response IOCB */
3458 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3459 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3462 * If the port response put pointer has not been updated, sync
3463 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3464 * response put pointer.
3466 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3467 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3469 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3471 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3472 /* At least one response entry has been freed */
3473 pring
->stats
.iocb_rsp_full
++;
3474 /* SET RxRE_RSP in Chip Att register */
3475 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3476 writel(status
, phba
->CAregaddr
);
3477 readl(phba
->CAregaddr
); /* flush */
3479 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3480 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3481 pring
->stats
.iocb_cmd_empty
++;
3483 /* Force update of the local copy of cmdGetInx */
3484 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3485 lpfc_sli_resume_iocb(phba
, pring
);
3487 if ((pring
->lpfc_sli_cmd_available
))
3488 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3492 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3497 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3498 * @phba: Pointer to HBA context object.
3499 * @pring: Pointer to driver SLI ring object.
3500 * @mask: Host attention register mask for this ring.
3502 * This function is called from the worker thread when there is a pending
3503 * ELS response iocb on the driver internal slow-path response iocb worker
3504 * queue. The caller does not hold any lock. The function will remove each
3505 * response iocb from the response worker queue and calls the handle
3506 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3509 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3510 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3512 struct lpfc_iocbq
*irspiocbq
;
3513 struct hbq_dmabuf
*dmabuf
;
3514 struct lpfc_cq_event
*cq_event
;
3515 unsigned long iflag
;
3517 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3518 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3519 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3520 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3521 /* Get the response iocb from the head of work queue */
3522 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3523 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3524 cq_event
, struct lpfc_cq_event
, list
);
3525 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3527 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3528 case CQE_CODE_COMPL_WQE
:
3529 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3531 /* Translate ELS WCQE to response IOCBQ */
3532 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3535 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3538 case CQE_CODE_RECEIVE
:
3539 case CQE_CODE_RECEIVE_V1
:
3540 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3542 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3551 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3552 * @phba: Pointer to HBA context object.
3553 * @pring: Pointer to driver SLI ring object.
3555 * This function aborts all iocbs in the given ring and frees all the iocb
3556 * objects in txq. This function issues an abort iocb for all the iocb commands
3557 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3558 * the return of this function. The caller is not required to hold any locks.
3561 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3563 LIST_HEAD(completions
);
3564 struct lpfc_iocbq
*iocb
, *next_iocb
;
3566 if (pring
->ringno
== LPFC_ELS_RING
) {
3567 lpfc_fabric_abort_hba(phba
);
3570 /* Error everything on txq and txcmplq
3573 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3574 spin_lock_irq(&pring
->ring_lock
);
3575 list_splice_init(&pring
->txq
, &completions
);
3577 spin_unlock_irq(&pring
->ring_lock
);
3579 spin_lock_irq(&phba
->hbalock
);
3580 /* Next issue ABTS for everything on the txcmplq */
3581 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3582 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3583 spin_unlock_irq(&phba
->hbalock
);
3585 spin_lock_irq(&phba
->hbalock
);
3586 list_splice_init(&pring
->txq
, &completions
);
3589 /* Next issue ABTS for everything on the txcmplq */
3590 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3591 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3592 spin_unlock_irq(&phba
->hbalock
);
3595 /* Cancel all the IOCBs from the completions list */
3596 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3601 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3602 * @phba: Pointer to HBA context object.
3603 * @pring: Pointer to driver SLI ring object.
3605 * This function aborts all iocbs in FCP rings and frees all the iocb
3606 * objects in txq. This function issues an abort iocb for all the iocb commands
3607 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3608 * the return of this function. The caller is not required to hold any locks.
3611 lpfc_sli_abort_fcp_rings(struct lpfc_hba
*phba
)
3613 struct lpfc_sli
*psli
= &phba
->sli
;
3614 struct lpfc_sli_ring
*pring
;
3617 /* Look on all the FCP Rings for the iotag */
3618 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3619 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3620 pring
= &psli
->ring
[i
+ MAX_SLI3_CONFIGURED_RINGS
];
3621 lpfc_sli_abort_iocb_ring(phba
, pring
);
3624 pring
= &psli
->ring
[psli
->fcp_ring
];
3625 lpfc_sli_abort_iocb_ring(phba
, pring
);
3631 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3632 * @phba: Pointer to HBA context object.
3634 * This function flushes all iocbs in the fcp ring and frees all the iocb
3635 * objects in txq and txcmplq. This function will not issue abort iocbs
3636 * for all the iocb commands in txcmplq, they will just be returned with
3637 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3638 * slot has been permanently disabled.
3641 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3645 struct lpfc_sli
*psli
= &phba
->sli
;
3646 struct lpfc_sli_ring
*pring
;
3649 spin_lock_irq(&phba
->hbalock
);
3650 /* Indicate the I/O queues are flushed */
3651 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3652 spin_unlock_irq(&phba
->hbalock
);
3654 /* Look on all the FCP Rings for the iotag */
3655 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3656 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3657 pring
= &psli
->ring
[i
+ MAX_SLI3_CONFIGURED_RINGS
];
3659 spin_lock_irq(&pring
->ring_lock
);
3660 /* Retrieve everything on txq */
3661 list_splice_init(&pring
->txq
, &txq
);
3662 /* Retrieve everything on the txcmplq */
3663 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3665 pring
->txcmplq_cnt
= 0;
3666 spin_unlock_irq(&pring
->ring_lock
);
3669 lpfc_sli_cancel_iocbs(phba
, &txq
,
3670 IOSTAT_LOCAL_REJECT
,
3672 /* Flush the txcmpq */
3673 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
3674 IOSTAT_LOCAL_REJECT
,
3678 pring
= &psli
->ring
[psli
->fcp_ring
];
3680 spin_lock_irq(&phba
->hbalock
);
3681 /* Retrieve everything on txq */
3682 list_splice_init(&pring
->txq
, &txq
);
3683 /* Retrieve everything on the txcmplq */
3684 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3686 pring
->txcmplq_cnt
= 0;
3687 spin_unlock_irq(&phba
->hbalock
);
3690 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3692 /* Flush the txcmpq */
3693 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3699 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3700 * @phba: Pointer to HBA context object.
3701 * @mask: Bit mask to be checked.
3703 * This function reads the host status register and compares
3704 * with the provided bit mask to check if HBA completed
3705 * the restart. This function will wait in a loop for the
3706 * HBA to complete restart. If the HBA does not restart within
3707 * 15 iterations, the function will reset the HBA again. The
3708 * function returns 1 when HBA fail to restart otherwise returns
3712 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3718 /* Read the HBA Host Status Register */
3719 if (lpfc_readl(phba
->HSregaddr
, &status
))
3723 * Check status register every 100ms for 5 retries, then every
3724 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3725 * every 2.5 sec for 4.
3726 * Break our of the loop if errors occurred during init.
3728 while (((status
& mask
) != mask
) &&
3729 !(status
& HS_FFERM
) &&
3741 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3742 lpfc_sli_brdrestart(phba
);
3744 /* Read the HBA Host Status Register */
3745 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3751 /* Check to see if any errors occurred during init */
3752 if ((status
& HS_FFERM
) || (i
>= 20)) {
3753 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3754 "2751 Adapter failed to restart, "
3755 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3757 readl(phba
->MBslimaddr
+ 0xa8),
3758 readl(phba
->MBslimaddr
+ 0xac));
3759 phba
->link_state
= LPFC_HBA_ERROR
;
3767 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3768 * @phba: Pointer to HBA context object.
3769 * @mask: Bit mask to be checked.
3771 * This function checks the host status register to check if HBA is
3772 * ready. This function will wait in a loop for the HBA to be ready
3773 * If the HBA is not ready , the function will will reset the HBA PCI
3774 * function again. The function returns 1 when HBA fail to be ready
3775 * otherwise returns zero.
3778 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3783 /* Read the HBA Host Status Register */
3784 status
= lpfc_sli4_post_status_check(phba
);
3787 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3788 lpfc_sli_brdrestart(phba
);
3789 status
= lpfc_sli4_post_status_check(phba
);
3792 /* Check to see if any errors occurred during init */
3794 phba
->link_state
= LPFC_HBA_ERROR
;
3797 phba
->sli4_hba
.intr_enable
= 0;
3803 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3804 * @phba: Pointer to HBA context object.
3805 * @mask: Bit mask to be checked.
3807 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3808 * from the API jump table function pointer from the lpfc_hba struct.
3811 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3813 return phba
->lpfc_sli_brdready(phba
, mask
);
3816 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3819 * lpfc_reset_barrier - Make HBA ready for HBA reset
3820 * @phba: Pointer to HBA context object.
3822 * This function is called before resetting an HBA. This function is called
3823 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3825 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3827 uint32_t __iomem
*resp_buf
;
3828 uint32_t __iomem
*mbox_buf
;
3829 volatile uint32_t mbox
;
3830 uint32_t hc_copy
, ha_copy
, resp_data
;
3834 lockdep_assert_held(&phba
->hbalock
);
3836 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3837 if (hdrtype
!= 0x80 ||
3838 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3839 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3843 * Tell the other part of the chip to suspend temporarily all
3846 resp_buf
= phba
->MBslimaddr
;
3848 /* Disable the error attention */
3849 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3851 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3852 readl(phba
->HCregaddr
); /* flush */
3853 phba
->link_flag
|= LS_IGNORE_ERATT
;
3855 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3857 if (ha_copy
& HA_ERATT
) {
3858 /* Clear Chip error bit */
3859 writel(HA_ERATT
, phba
->HAregaddr
);
3860 phba
->pport
->stopped
= 1;
3864 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3865 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3867 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3868 mbox_buf
= phba
->MBslimaddr
;
3869 writel(mbox
, mbox_buf
);
3871 for (i
= 0; i
< 50; i
++) {
3872 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3874 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3880 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3882 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3883 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3884 phba
->pport
->stopped
)
3890 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3892 for (i
= 0; i
< 500; i
++) {
3893 if (lpfc_readl(resp_buf
, &resp_data
))
3895 if (resp_data
!= mbox
)
3904 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3906 if (!(ha_copy
& HA_ERATT
))
3912 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3913 writel(HA_ERATT
, phba
->HAregaddr
);
3914 phba
->pport
->stopped
= 1;
3918 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3919 writel(hc_copy
, phba
->HCregaddr
);
3920 readl(phba
->HCregaddr
); /* flush */
3924 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3925 * @phba: Pointer to HBA context object.
3927 * This function issues a kill_board mailbox command and waits for
3928 * the error attention interrupt. This function is called for stopping
3929 * the firmware processing. The caller is not required to hold any
3930 * locks. This function calls lpfc_hba_down_post function to free
3931 * any pending commands after the kill. The function will return 1 when it
3932 * fails to kill the board else will return 0.
3935 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3937 struct lpfc_sli
*psli
;
3947 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3948 "0329 Kill HBA Data: x%x x%x\n",
3949 phba
->pport
->port_state
, psli
->sli_flag
);
3951 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3955 /* Disable the error attention */
3956 spin_lock_irq(&phba
->hbalock
);
3957 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3958 spin_unlock_irq(&phba
->hbalock
);
3959 mempool_free(pmb
, phba
->mbox_mem_pool
);
3962 status
&= ~HC_ERINT_ENA
;
3963 writel(status
, phba
->HCregaddr
);
3964 readl(phba
->HCregaddr
); /* flush */
3965 phba
->link_flag
|= LS_IGNORE_ERATT
;
3966 spin_unlock_irq(&phba
->hbalock
);
3968 lpfc_kill_board(phba
, pmb
);
3969 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3970 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3972 if (retval
!= MBX_SUCCESS
) {
3973 if (retval
!= MBX_BUSY
)
3974 mempool_free(pmb
, phba
->mbox_mem_pool
);
3975 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3976 "2752 KILL_BOARD command failed retval %d\n",
3978 spin_lock_irq(&phba
->hbalock
);
3979 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3980 spin_unlock_irq(&phba
->hbalock
);
3984 spin_lock_irq(&phba
->hbalock
);
3985 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3986 spin_unlock_irq(&phba
->hbalock
);
3988 mempool_free(pmb
, phba
->mbox_mem_pool
);
3990 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3991 * attention every 100ms for 3 seconds. If we don't get ERATT after
3992 * 3 seconds we still set HBA_ERROR state because the status of the
3993 * board is now undefined.
3995 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3997 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3999 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4003 del_timer_sync(&psli
->mbox_tmo
);
4004 if (ha_copy
& HA_ERATT
) {
4005 writel(HA_ERATT
, phba
->HAregaddr
);
4006 phba
->pport
->stopped
= 1;
4008 spin_lock_irq(&phba
->hbalock
);
4009 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4010 psli
->mbox_active
= NULL
;
4011 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4012 spin_unlock_irq(&phba
->hbalock
);
4014 lpfc_hba_down_post(phba
);
4015 phba
->link_state
= LPFC_HBA_ERROR
;
4017 return ha_copy
& HA_ERATT
? 0 : 1;
4021 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4022 * @phba: Pointer to HBA context object.
4024 * This function resets the HBA by writing HC_INITFF to the control
4025 * register. After the HBA resets, this function resets all the iocb ring
4026 * indices. This function disables PCI layer parity checking during
4028 * This function returns 0 always.
4029 * The caller is not required to hold any locks.
4032 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
4034 struct lpfc_sli
*psli
;
4035 struct lpfc_sli_ring
*pring
;
4042 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4043 "0325 Reset HBA Data: x%x x%x\n",
4044 phba
->pport
->port_state
, psli
->sli_flag
);
4046 /* perform board reset */
4047 phba
->fc_eventTag
= 0;
4048 phba
->link_events
= 0;
4049 phba
->pport
->fc_myDID
= 0;
4050 phba
->pport
->fc_prevDID
= 0;
4052 /* Turn off parity checking and serr during the physical reset */
4053 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4054 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
4056 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4058 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
4060 /* Now toggle INITFF bit in the Host Control Register */
4061 writel(HC_INITFF
, phba
->HCregaddr
);
4063 readl(phba
->HCregaddr
); /* flush */
4064 writel(0, phba
->HCregaddr
);
4065 readl(phba
->HCregaddr
); /* flush */
4067 /* Restore PCI cmd register */
4068 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4070 /* Initialize relevant SLI info */
4071 for (i
= 0; i
< psli
->num_rings
; i
++) {
4072 pring
= &psli
->ring
[i
];
4074 pring
->sli
.sli3
.rspidx
= 0;
4075 pring
->sli
.sli3
.next_cmdidx
= 0;
4076 pring
->sli
.sli3
.local_getidx
= 0;
4077 pring
->sli
.sli3
.cmdidx
= 0;
4078 pring
->missbufcnt
= 0;
4081 phba
->link_state
= LPFC_WARM_START
;
4086 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4087 * @phba: Pointer to HBA context object.
4089 * This function resets a SLI4 HBA. This function disables PCI layer parity
4090 * checking during resets the device. The caller is not required to hold
4093 * This function returns 0 always.
4096 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
4098 struct lpfc_sli
*psli
= &phba
->sli
;
4103 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4104 "0295 Reset HBA Data: x%x x%x x%x\n",
4105 phba
->pport
->port_state
, psli
->sli_flag
,
4108 /* perform board reset */
4109 phba
->fc_eventTag
= 0;
4110 phba
->link_events
= 0;
4111 phba
->pport
->fc_myDID
= 0;
4112 phba
->pport
->fc_prevDID
= 0;
4114 spin_lock_irq(&phba
->hbalock
);
4115 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
4116 phba
->fcf
.fcf_flag
= 0;
4117 spin_unlock_irq(&phba
->hbalock
);
4119 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4120 if (phba
->hba_flag
& HBA_FW_DUMP_OP
) {
4121 phba
->hba_flag
&= ~HBA_FW_DUMP_OP
;
4125 /* Now physically reset the device */
4126 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4127 "0389 Performing PCI function reset!\n");
4129 /* Turn off parity checking and serr during the physical reset */
4130 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4131 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
4132 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4134 /* Perform FCoE PCI function reset before freeing queue memory */
4135 rc
= lpfc_pci_function_reset(phba
);
4136 lpfc_sli4_queue_destroy(phba
);
4138 /* Restore PCI cmd register */
4139 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4145 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4146 * @phba: Pointer to HBA context object.
4148 * This function is called in the SLI initialization code path to
4149 * restart the HBA. The caller is not required to hold any lock.
4150 * This function writes MBX_RESTART mailbox command to the SLIM and
4151 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4152 * function to free any pending commands. The function enables
4153 * POST only during the first initialization. The function returns zero.
4154 * The function does not guarantee completion of MBX_RESTART mailbox
4155 * command before the return of this function.
4158 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4161 struct lpfc_sli
*psli
;
4162 volatile uint32_t word0
;
4163 void __iomem
*to_slim
;
4164 uint32_t hba_aer_enabled
;
4166 spin_lock_irq(&phba
->hbalock
);
4168 /* Take PCIe device Advanced Error Reporting (AER) state */
4169 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4174 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4175 "0337 Restart HBA Data: x%x x%x\n",
4176 phba
->pport
->port_state
, psli
->sli_flag
);
4179 mb
= (MAILBOX_t
*) &word0
;
4180 mb
->mbxCommand
= MBX_RESTART
;
4183 lpfc_reset_barrier(phba
);
4185 to_slim
= phba
->MBslimaddr
;
4186 writel(*(uint32_t *) mb
, to_slim
);
4187 readl(to_slim
); /* flush */
4189 /* Only skip post after fc_ffinit is completed */
4190 if (phba
->pport
->port_state
)
4191 word0
= 1; /* This is really setting up word1 */
4193 word0
= 0; /* This is really setting up word1 */
4194 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4195 writel(*(uint32_t *) mb
, to_slim
);
4196 readl(to_slim
); /* flush */
4198 lpfc_sli_brdreset(phba
);
4199 phba
->pport
->stopped
= 0;
4200 phba
->link_state
= LPFC_INIT_START
;
4202 spin_unlock_irq(&phba
->hbalock
);
4204 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4205 psli
->stats_start
= get_seconds();
4207 /* Give the INITFF and Post time to settle. */
4210 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4211 if (hba_aer_enabled
)
4212 pci_disable_pcie_error_reporting(phba
->pcidev
);
4214 lpfc_hba_down_post(phba
);
4220 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4221 * @phba: Pointer to HBA context object.
4223 * This function is called in the SLI initialization code path to restart
4224 * a SLI4 HBA. The caller is not required to hold any lock.
4225 * At the end of the function, it calls lpfc_hba_down_post function to
4226 * free any pending commands.
4229 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4231 struct lpfc_sli
*psli
= &phba
->sli
;
4232 uint32_t hba_aer_enabled
;
4236 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4237 "0296 Restart HBA Data: x%x x%x\n",
4238 phba
->pport
->port_state
, psli
->sli_flag
);
4240 /* Take PCIe device Advanced Error Reporting (AER) state */
4241 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4243 rc
= lpfc_sli4_brdreset(phba
);
4245 spin_lock_irq(&phba
->hbalock
);
4246 phba
->pport
->stopped
= 0;
4247 phba
->link_state
= LPFC_INIT_START
;
4249 spin_unlock_irq(&phba
->hbalock
);
4251 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4252 psli
->stats_start
= get_seconds();
4254 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4255 if (hba_aer_enabled
)
4256 pci_disable_pcie_error_reporting(phba
->pcidev
);
4258 lpfc_hba_down_post(phba
);
4264 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4265 * @phba: Pointer to HBA context object.
4267 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4268 * API jump table function pointer from the lpfc_hba struct.
4271 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4273 return phba
->lpfc_sli_brdrestart(phba
);
4277 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4278 * @phba: Pointer to HBA context object.
4280 * This function is called after a HBA restart to wait for successful
4281 * restart of the HBA. Successful restart of the HBA is indicated by
4282 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4283 * iteration, the function will restart the HBA again. The function returns
4284 * zero if HBA successfully restarted else returns negative error code.
4287 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4289 uint32_t status
, i
= 0;
4291 /* Read the HBA Host Status Register */
4292 if (lpfc_readl(phba
->HSregaddr
, &status
))
4295 /* Check status register to see what current state is */
4297 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4299 /* Check every 10ms for 10 retries, then every 100ms for 90
4300 * retries, then every 1 sec for 50 retires for a total of
4301 * ~60 seconds before reset the board again and check every
4302 * 1 sec for 50 retries. The up to 60 seconds before the
4303 * board ready is required by the Falcon FIPS zeroization
4304 * complete, and any reset the board in between shall cause
4305 * restart of zeroization, further delay the board ready.
4308 /* Adapter failed to init, timeout, status reg
4310 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4311 "0436 Adapter failed to init, "
4312 "timeout, status reg x%x, "
4313 "FW Data: A8 x%x AC x%x\n", status
,
4314 readl(phba
->MBslimaddr
+ 0xa8),
4315 readl(phba
->MBslimaddr
+ 0xac));
4316 phba
->link_state
= LPFC_HBA_ERROR
;
4320 /* Check to see if any errors occurred during init */
4321 if (status
& HS_FFERM
) {
4322 /* ERROR: During chipset initialization */
4323 /* Adapter failed to init, chipset, status reg
4325 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4326 "0437 Adapter failed to init, "
4327 "chipset, status reg x%x, "
4328 "FW Data: A8 x%x AC x%x\n", status
,
4329 readl(phba
->MBslimaddr
+ 0xa8),
4330 readl(phba
->MBslimaddr
+ 0xac));
4331 phba
->link_state
= LPFC_HBA_ERROR
;
4344 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4345 lpfc_sli_brdrestart(phba
);
4347 /* Read the HBA Host Status Register */
4348 if (lpfc_readl(phba
->HSregaddr
, &status
))
4352 /* Check to see if any errors occurred during init */
4353 if (status
& HS_FFERM
) {
4354 /* ERROR: During chipset initialization */
4355 /* Adapter failed to init, chipset, status reg <status> */
4356 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4357 "0438 Adapter failed to init, chipset, "
4359 "FW Data: A8 x%x AC x%x\n", status
,
4360 readl(phba
->MBslimaddr
+ 0xa8),
4361 readl(phba
->MBslimaddr
+ 0xac));
4362 phba
->link_state
= LPFC_HBA_ERROR
;
4366 /* Clear all interrupt enable conditions */
4367 writel(0, phba
->HCregaddr
);
4368 readl(phba
->HCregaddr
); /* flush */
4370 /* setup host attn register */
4371 writel(0xffffffff, phba
->HAregaddr
);
4372 readl(phba
->HAregaddr
); /* flush */
4377 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4379 * This function calculates and returns the number of HBQs required to be
4383 lpfc_sli_hbq_count(void)
4385 return ARRAY_SIZE(lpfc_hbq_defs
);
4389 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4391 * This function adds the number of hbq entries in every HBQ to get
4392 * the total number of hbq entries required for the HBA and returns
4396 lpfc_sli_hbq_entry_count(void)
4398 int hbq_count
= lpfc_sli_hbq_count();
4402 for (i
= 0; i
< hbq_count
; ++i
)
4403 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4408 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4410 * This function calculates amount of memory required for all hbq entries
4411 * to be configured and returns the total memory required.
4414 lpfc_sli_hbq_size(void)
4416 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4420 * lpfc_sli_hbq_setup - configure and initialize HBQs
4421 * @phba: Pointer to HBA context object.
4423 * This function is called during the SLI initialization to configure
4424 * all the HBQs and post buffers to the HBQ. The caller is not
4425 * required to hold any locks. This function will return zero if successful
4426 * else it will return negative error code.
4429 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4431 int hbq_count
= lpfc_sli_hbq_count();
4435 uint32_t hbq_entry_index
;
4437 /* Get a Mailbox buffer to setup mailbox
4438 * commands for HBA initialization
4440 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4447 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4448 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4449 phba
->hbq_in_use
= 1;
4451 hbq_entry_index
= 0;
4452 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4453 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4454 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4455 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4456 phba
->hbqs
[hbqno
].entry_count
=
4457 lpfc_hbq_defs
[hbqno
]->entry_count
;
4458 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4459 hbq_entry_index
, pmb
);
4460 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4462 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4463 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4464 mbxStatus <status>, ring <num> */
4466 lpfc_printf_log(phba
, KERN_ERR
,
4467 LOG_SLI
| LOG_VPORT
,
4468 "1805 Adapter failed to init. "
4469 "Data: x%x x%x x%x\n",
4471 pmbox
->mbxStatus
, hbqno
);
4473 phba
->link_state
= LPFC_HBA_ERROR
;
4474 mempool_free(pmb
, phba
->mbox_mem_pool
);
4478 phba
->hbq_count
= hbq_count
;
4480 mempool_free(pmb
, phba
->mbox_mem_pool
);
4482 /* Initially populate or replenish the HBQs */
4483 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4484 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4489 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4490 * @phba: Pointer to HBA context object.
4492 * This function is called during the SLI initialization to configure
4493 * all the HBQs and post buffers to the HBQ. The caller is not
4494 * required to hold any locks. This function will return zero if successful
4495 * else it will return negative error code.
4498 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4500 phba
->hbq_in_use
= 1;
4501 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4502 phba
->hbq_count
= 1;
4503 /* Initially populate or replenish the HBQs */
4504 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4509 * lpfc_sli_config_port - Issue config port mailbox command
4510 * @phba: Pointer to HBA context object.
4511 * @sli_mode: sli mode - 2/3
4513 * This function is called by the sli intialization code path
4514 * to issue config_port mailbox command. This function restarts the
4515 * HBA firmware and issues a config_port mailbox command to configure
4516 * the SLI interface in the sli mode specified by sli_mode
4517 * variable. The caller is not required to hold any locks.
4518 * The function returns 0 if successful, else returns negative error
4522 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4525 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4527 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4529 phba
->link_state
= LPFC_HBA_ERROR
;
4533 phba
->sli_rev
= sli_mode
;
4534 while (resetcount
< 2 && !done
) {
4535 spin_lock_irq(&phba
->hbalock
);
4536 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4537 spin_unlock_irq(&phba
->hbalock
);
4538 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4539 lpfc_sli_brdrestart(phba
);
4540 rc
= lpfc_sli_chipset_init(phba
);
4544 spin_lock_irq(&phba
->hbalock
);
4545 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4546 spin_unlock_irq(&phba
->hbalock
);
4549 /* Call pre CONFIG_PORT mailbox command initialization. A
4550 * value of 0 means the call was successful. Any other
4551 * nonzero value is a failure, but if ERESTART is returned,
4552 * the driver may reset the HBA and try again.
4554 rc
= lpfc_config_port_prep(phba
);
4555 if (rc
== -ERESTART
) {
4556 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4561 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4562 lpfc_config_port(phba
, pmb
);
4563 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4564 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4565 LPFC_SLI3_HBQ_ENABLED
|
4566 LPFC_SLI3_CRP_ENABLED
|
4567 LPFC_SLI3_BG_ENABLED
|
4568 LPFC_SLI3_DSS_ENABLED
);
4569 if (rc
!= MBX_SUCCESS
) {
4570 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4571 "0442 Adapter failed to init, mbxCmd x%x "
4572 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4573 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4574 spin_lock_irq(&phba
->hbalock
);
4575 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4576 spin_unlock_irq(&phba
->hbalock
);
4579 /* Allow asynchronous mailbox command to go through */
4580 spin_lock_irq(&phba
->hbalock
);
4581 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4582 spin_unlock_irq(&phba
->hbalock
);
4585 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4586 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4587 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4588 "3110 Port did not grant ASABT\n");
4593 goto do_prep_failed
;
4595 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4596 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4598 goto do_prep_failed
;
4600 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4601 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4602 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4603 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4604 phba
->max_vpi
: phba
->max_vports
;
4608 phba
->fips_level
= 0;
4609 phba
->fips_spec_rev
= 0;
4610 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4611 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4612 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4613 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4614 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4615 "2850 Security Crypto Active. FIPS x%d "
4617 phba
->fips_level
, phba
->fips_spec_rev
);
4619 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4620 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4621 "2856 Config Port Security Crypto "
4623 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4625 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4626 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4627 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4628 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4630 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4631 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4633 if (phba
->cfg_enable_bg
) {
4634 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4635 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4637 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4638 "0443 Adapter did not grant "
4642 phba
->hbq_get
= NULL
;
4643 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4647 mempool_free(pmb
, phba
->mbox_mem_pool
);
4653 * lpfc_sli_hba_setup - SLI intialization function
4654 * @phba: Pointer to HBA context object.
4656 * This function is the main SLI intialization function. This function
4657 * is called by the HBA intialization code, HBA reset code and HBA
4658 * error attention handler code. Caller is not required to hold any
4659 * locks. This function issues config_port mailbox command to configure
4660 * the SLI, setup iocb rings and HBQ rings. In the end the function
4661 * calls the config_port_post function to issue init_link mailbox
4662 * command and to start the discovery. The function will return zero
4663 * if successful, else it will return negative error code.
4666 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4672 switch (phba
->cfg_sli_mode
) {
4674 if (phba
->cfg_enable_npiv
) {
4675 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4676 "1824 NPIV enabled: Override sli_mode "
4677 "parameter (%d) to auto (0).\n",
4678 phba
->cfg_sli_mode
);
4687 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4688 "1819 Unrecognized sli_mode parameter: %d.\n",
4689 phba
->cfg_sli_mode
);
4693 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
4695 rc
= lpfc_sli_config_port(phba
, mode
);
4697 if (rc
&& phba
->cfg_sli_mode
== 3)
4698 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4699 "1820 Unable to select SLI-3. "
4700 "Not supported by adapter.\n");
4701 if (rc
&& mode
!= 2)
4702 rc
= lpfc_sli_config_port(phba
, 2);
4703 else if (rc
&& mode
== 2)
4704 rc
= lpfc_sli_config_port(phba
, 3);
4706 goto lpfc_sli_hba_setup_error
;
4708 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4709 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4710 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4712 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4713 "2709 This device supports "
4714 "Advanced Error Reporting (AER)\n");
4715 spin_lock_irq(&phba
->hbalock
);
4716 phba
->hba_flag
|= HBA_AER_ENABLED
;
4717 spin_unlock_irq(&phba
->hbalock
);
4719 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4720 "2708 This device does not support "
4721 "Advanced Error Reporting (AER): %d\n",
4723 phba
->cfg_aer_support
= 0;
4727 if (phba
->sli_rev
== 3) {
4728 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4729 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4731 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4732 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4733 phba
->sli3_options
= 0;
4736 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4737 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4738 phba
->sli_rev
, phba
->max_vpi
);
4739 rc
= lpfc_sli_ring_map(phba
);
4742 goto lpfc_sli_hba_setup_error
;
4744 /* Initialize VPIs. */
4745 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4747 * The VPI bitmask and physical ID array are allocated
4748 * and initialized once only - at driver load. A port
4749 * reset doesn't need to reinitialize this memory.
4751 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4752 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4753 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4755 if (!phba
->vpi_bmask
) {
4757 goto lpfc_sli_hba_setup_error
;
4760 phba
->vpi_ids
= kzalloc(
4761 (phba
->max_vpi
+1) * sizeof(uint16_t),
4763 if (!phba
->vpi_ids
) {
4764 kfree(phba
->vpi_bmask
);
4766 goto lpfc_sli_hba_setup_error
;
4768 for (i
= 0; i
< phba
->max_vpi
; i
++)
4769 phba
->vpi_ids
[i
] = i
;
4774 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4775 rc
= lpfc_sli_hbq_setup(phba
);
4777 goto lpfc_sli_hba_setup_error
;
4779 spin_lock_irq(&phba
->hbalock
);
4780 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4781 spin_unlock_irq(&phba
->hbalock
);
4783 rc
= lpfc_config_port_post(phba
);
4785 goto lpfc_sli_hba_setup_error
;
4789 lpfc_sli_hba_setup_error
:
4790 phba
->link_state
= LPFC_HBA_ERROR
;
4791 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4792 "0445 Firmware initialization failed\n");
4797 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4798 * @phba: Pointer to HBA context object.
4799 * @mboxq: mailbox pointer.
4800 * This function issue a dump mailbox command to read config region
4801 * 23 and parse the records in the region and populate driver
4805 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4807 LPFC_MBOXQ_t
*mboxq
;
4808 struct lpfc_dmabuf
*mp
;
4809 struct lpfc_mqe
*mqe
;
4810 uint32_t data_length
;
4813 /* Program the default value of vlan_id and fc_map */
4814 phba
->valid_vlan
= 0;
4815 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4816 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4817 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4819 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4823 mqe
= &mboxq
->u
.mqe
;
4824 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4826 goto out_free_mboxq
;
4829 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4830 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4832 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4833 "(%d):2571 Mailbox cmd x%x Status x%x "
4834 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4835 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4836 "CQ: x%x x%x x%x x%x\n",
4837 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4838 bf_get(lpfc_mqe_command
, mqe
),
4839 bf_get(lpfc_mqe_status
, mqe
),
4840 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4841 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4842 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4843 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4844 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4845 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4846 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4847 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4848 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4850 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4851 mboxq
->mcqe
.trailer
);
4854 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4857 goto out_free_mboxq
;
4859 data_length
= mqe
->un
.mb_words
[5];
4860 if (data_length
> DMP_RGN23_SIZE
) {
4861 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4864 goto out_free_mboxq
;
4867 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4868 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4873 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4878 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4879 * @phba: pointer to lpfc hba data structure.
4880 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4881 * @vpd: pointer to the memory to hold resulting port vpd data.
4882 * @vpd_size: On input, the number of bytes allocated to @vpd.
4883 * On output, the number of data bytes in @vpd.
4885 * This routine executes a READ_REV SLI4 mailbox command. In
4886 * addition, this routine gets the port vpd data.
4890 * -ENOMEM - could not allocated memory.
4893 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4894 uint8_t *vpd
, uint32_t *vpd_size
)
4898 struct lpfc_dmabuf
*dmabuf
;
4899 struct lpfc_mqe
*mqe
;
4901 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4906 * Get a DMA buffer for the vpd data resulting from the READ_REV
4909 dma_size
= *vpd_size
;
4910 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, dma_size
,
4911 &dmabuf
->phys
, GFP_KERNEL
);
4912 if (!dmabuf
->virt
) {
4918 * The SLI4 implementation of READ_REV conflicts at word1,
4919 * bits 31:16 and SLI4 adds vpd functionality not present
4920 * in SLI3. This code corrects the conflicts.
4922 lpfc_read_rev(phba
, mboxq
);
4923 mqe
= &mboxq
->u
.mqe
;
4924 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4925 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4926 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4927 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4928 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4930 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4932 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4933 dmabuf
->virt
, dmabuf
->phys
);
4939 * The available vpd length cannot be bigger than the
4940 * DMA buffer passed to the port. Catch the less than
4941 * case and update the caller's size.
4943 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4944 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4946 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4948 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4949 dmabuf
->virt
, dmabuf
->phys
);
4955 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4956 * @phba: pointer to lpfc hba data structure.
4958 * This routine retrieves SLI4 device physical port name this PCI function
4963 * otherwise - failed to retrieve physical port name
4966 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4968 LPFC_MBOXQ_t
*mboxq
;
4969 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4970 struct lpfc_controller_attribute
*cntl_attr
;
4971 struct lpfc_mbx_get_port_name
*get_port_name
;
4972 void *virtaddr
= NULL
;
4973 uint32_t alloclen
, reqlen
;
4974 uint32_t shdr_status
, shdr_add_status
;
4975 union lpfc_sli4_cfg_shdr
*shdr
;
4976 char cport_name
= 0;
4979 /* We assume nothing at this point */
4980 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4981 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4983 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4986 /* obtain link type and link number via READ_CONFIG */
4987 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4988 lpfc_sli4_read_config(phba
);
4989 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4990 goto retrieve_ppname
;
4992 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4993 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4994 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4995 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4996 LPFC_SLI4_MBX_NEMBED
);
4997 if (alloclen
< reqlen
) {
4998 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4999 "3084 Allocated DMA memory size (%d) is "
5000 "less than the requested DMA memory size "
5001 "(%d)\n", alloclen
, reqlen
);
5003 goto out_free_mboxq
;
5005 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5006 virtaddr
= mboxq
->sge_array
->addr
[0];
5007 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
5008 shdr
= &mbx_cntl_attr
->cfg_shdr
;
5009 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5010 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5011 if (shdr_status
|| shdr_add_status
|| rc
) {
5012 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5013 "3085 Mailbox x%x (x%x/x%x) failed, "
5014 "rc:x%x, status:x%x, add_status:x%x\n",
5015 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5016 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5017 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5018 rc
, shdr_status
, shdr_add_status
);
5020 goto out_free_mboxq
;
5022 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
5023 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
5024 phba
->sli4_hba
.lnk_info
.lnk_tp
=
5025 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
5026 phba
->sli4_hba
.lnk_info
.lnk_no
=
5027 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
5028 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5029 "3086 lnk_type:%d, lnk_numb:%d\n",
5030 phba
->sli4_hba
.lnk_info
.lnk_tp
,
5031 phba
->sli4_hba
.lnk_info
.lnk_no
);
5034 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5035 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
5036 sizeof(struct lpfc_mbx_get_port_name
) -
5037 sizeof(struct lpfc_sli4_cfg_mhdr
),
5038 LPFC_SLI4_MBX_EMBED
);
5039 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
5040 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
5041 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
5042 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
5043 phba
->sli4_hba
.lnk_info
.lnk_tp
);
5044 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5045 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5046 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5047 if (shdr_status
|| shdr_add_status
|| rc
) {
5048 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5049 "3087 Mailbox x%x (x%x/x%x) failed: "
5050 "rc:x%x, status:x%x, add_status:x%x\n",
5051 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5052 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5053 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5054 rc
, shdr_status
, shdr_add_status
);
5056 goto out_free_mboxq
;
5058 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
5059 case LPFC_LINK_NUMBER_0
:
5060 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
5061 &get_port_name
->u
.response
);
5062 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5064 case LPFC_LINK_NUMBER_1
:
5065 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
5066 &get_port_name
->u
.response
);
5067 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5069 case LPFC_LINK_NUMBER_2
:
5070 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
5071 &get_port_name
->u
.response
);
5072 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5074 case LPFC_LINK_NUMBER_3
:
5075 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
5076 &get_port_name
->u
.response
);
5077 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5083 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
5084 phba
->Port
[0] = cport_name
;
5085 phba
->Port
[1] = '\0';
5086 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5087 "3091 SLI get port name: %s\n", phba
->Port
);
5091 if (rc
!= MBX_TIMEOUT
) {
5092 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
5093 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
5095 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5101 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5102 * @phba: pointer to lpfc hba data structure.
5104 * This routine is called to explicitly arm the SLI4 device's completion and
5108 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
5112 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
5113 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
5115 if (phba
->sli4_hba
.fcp_cq
) {
5117 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
5119 } while (++fcp_eqidx
< phba
->cfg_fcp_io_channel
);
5123 lpfc_sli4_cq_release(phba
->sli4_hba
.oas_cq
, LPFC_QUEUE_REARM
);
5125 if (phba
->sli4_hba
.hba_eq
) {
5126 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
5128 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
5133 lpfc_sli4_eq_release(phba
->sli4_hba
.fof_eq
, LPFC_QUEUE_REARM
);
5137 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5138 * @phba: Pointer to HBA context object.
5139 * @type: The resource extent type.
5140 * @extnt_count: buffer to hold port available extent count.
5141 * @extnt_size: buffer to hold element count per extent.
5143 * This function calls the port and retrievs the number of available
5144 * extents and their size for a particular extent type.
5146 * Returns: 0 if successful. Nonzero otherwise.
5149 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5150 uint16_t *extnt_count
, uint16_t *extnt_size
)
5155 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5158 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5162 /* Find out how many extents are available for this resource type */
5163 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5164 sizeof(struct lpfc_sli4_cfg_mhdr
));
5165 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5166 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5167 length
, LPFC_SLI4_MBX_EMBED
);
5169 /* Send an extents count of 0 - the GET doesn't use it. */
5170 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5171 LPFC_SLI4_MBX_EMBED
);
5177 if (!phba
->sli4_hba
.intr_enable
)
5178 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5180 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5181 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5188 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5189 if (bf_get(lpfc_mbox_hdr_status
,
5190 &rsrc_info
->header
.cfg_shdr
.response
)) {
5191 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5192 "2930 Failed to get resource extents "
5193 "Status 0x%x Add'l Status 0x%x\n",
5194 bf_get(lpfc_mbox_hdr_status
,
5195 &rsrc_info
->header
.cfg_shdr
.response
),
5196 bf_get(lpfc_mbox_hdr_add_status
,
5197 &rsrc_info
->header
.cfg_shdr
.response
));
5202 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5204 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5207 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5208 "3162 Retrieved extents type-%d from port: count:%d, "
5209 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5212 mempool_free(mbox
, phba
->mbox_mem_pool
);
5217 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5218 * @phba: Pointer to HBA context object.
5219 * @type: The extent type to check.
5221 * This function reads the current available extents from the port and checks
5222 * if the extent count or extent size has changed since the last access.
5223 * Callers use this routine post port reset to understand if there is a
5224 * extent reprovisioning requirement.
5227 * -Error: error indicates problem.
5228 * 1: Extent count or size has changed.
5232 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5234 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5235 uint16_t size_diff
, rsrc_ext_size
;
5237 struct lpfc_rsrc_blks
*rsrc_entry
;
5238 struct list_head
*rsrc_blk_list
= NULL
;
5242 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5249 case LPFC_RSC_TYPE_FCOE_RPI
:
5250 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5252 case LPFC_RSC_TYPE_FCOE_VPI
:
5253 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5255 case LPFC_RSC_TYPE_FCOE_XRI
:
5256 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5258 case LPFC_RSC_TYPE_FCOE_VFI
:
5259 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5265 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5267 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5271 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5278 * lpfc_sli4_cfg_post_extnts -
5279 * @phba: Pointer to HBA context object.
5280 * @extnt_cnt - number of available extents.
5281 * @type - the extent type (rpi, xri, vfi, vpi).
5282 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5283 * @mbox - pointer to the caller's allocated mailbox structure.
5285 * This function executes the extents allocation request. It also
5286 * takes care of the amount of memory needed to allocate or get the
5287 * allocated extents. It is the caller's responsibility to evaluate
5291 * -Error: Error value describes the condition found.
5295 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5296 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5301 uint32_t alloc_len
, mbox_tmo
;
5303 /* Calculate the total requested length of the dma memory */
5304 req_len
= extnt_cnt
* sizeof(uint16_t);
5307 * Calculate the size of an embedded mailbox. The uint32_t
5308 * accounts for extents-specific word.
5310 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5314 * Presume the allocation and response will fit into an embedded
5315 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5317 *emb
= LPFC_SLI4_MBX_EMBED
;
5318 if (req_len
> emb_len
) {
5319 req_len
= extnt_cnt
* sizeof(uint16_t) +
5320 sizeof(union lpfc_sli4_cfg_shdr
) +
5322 *emb
= LPFC_SLI4_MBX_NEMBED
;
5325 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5326 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5328 if (alloc_len
< req_len
) {
5329 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5330 "2982 Allocated DMA memory size (x%x) is "
5331 "less than the requested DMA memory "
5332 "size (x%x)\n", alloc_len
, req_len
);
5335 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5339 if (!phba
->sli4_hba
.intr_enable
)
5340 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5342 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5343 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5352 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5353 * @phba: Pointer to HBA context object.
5354 * @type: The resource extent type to allocate.
5356 * This function allocates the number of elements for the specified
5360 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5363 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5364 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5367 unsigned long longs
;
5368 unsigned long *bmask
;
5369 struct lpfc_rsrc_blks
*rsrc_blks
;
5372 struct lpfc_id_range
*id_array
= NULL
;
5373 void *virtaddr
= NULL
;
5374 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5375 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5376 struct list_head
*ext_blk_list
;
5378 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5384 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5385 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5386 "3009 No available Resource Extents "
5387 "for resource type 0x%x: Count: 0x%x, "
5388 "Size 0x%x\n", type
, rsrc_cnt
,
5393 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5394 "2903 Post resource extents type-0x%x: "
5395 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5397 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5401 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5408 * Figure out where the response is located. Then get local pointers
5409 * to the response data. The port does not guarantee to respond to
5410 * all extents counts request so update the local variable with the
5411 * allocated count from the port.
5413 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5414 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5415 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5416 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5418 virtaddr
= mbox
->sge_array
->addr
[0];
5419 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5420 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5421 id_array
= &n_rsrc
->id
;
5424 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5425 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5428 * Based on the resource size and count, correct the base and max
5431 length
= sizeof(struct lpfc_rsrc_blks
);
5433 case LPFC_RSC_TYPE_FCOE_RPI
:
5434 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5435 sizeof(unsigned long),
5437 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5441 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5444 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5445 kfree(phba
->sli4_hba
.rpi_bmask
);
5451 * The next_rpi was initialized with the maximum available
5452 * count but the port may allocate a smaller number. Catch
5453 * that case and update the next_rpi.
5455 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5457 /* Initialize local ptrs for common extent processing later. */
5458 bmask
= phba
->sli4_hba
.rpi_bmask
;
5459 ids
= phba
->sli4_hba
.rpi_ids
;
5460 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5462 case LPFC_RSC_TYPE_FCOE_VPI
:
5463 phba
->vpi_bmask
= kzalloc(longs
*
5464 sizeof(unsigned long),
5466 if (unlikely(!phba
->vpi_bmask
)) {
5470 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5473 if (unlikely(!phba
->vpi_ids
)) {
5474 kfree(phba
->vpi_bmask
);
5479 /* Initialize local ptrs for common extent processing later. */
5480 bmask
= phba
->vpi_bmask
;
5481 ids
= phba
->vpi_ids
;
5482 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5484 case LPFC_RSC_TYPE_FCOE_XRI
:
5485 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5486 sizeof(unsigned long),
5488 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5492 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5493 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5496 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5497 kfree(phba
->sli4_hba
.xri_bmask
);
5502 /* Initialize local ptrs for common extent processing later. */
5503 bmask
= phba
->sli4_hba
.xri_bmask
;
5504 ids
= phba
->sli4_hba
.xri_ids
;
5505 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5507 case LPFC_RSC_TYPE_FCOE_VFI
:
5508 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5509 sizeof(unsigned long),
5511 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5515 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5518 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5519 kfree(phba
->sli4_hba
.vfi_bmask
);
5524 /* Initialize local ptrs for common extent processing later. */
5525 bmask
= phba
->sli4_hba
.vfi_bmask
;
5526 ids
= phba
->sli4_hba
.vfi_ids
;
5527 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5530 /* Unsupported Opcode. Fail call. */
5534 ext_blk_list
= NULL
;
5539 * Complete initializing the extent configuration with the
5540 * allocated ids assigned to this function. The bitmask serves
5541 * as an index into the array and manages the available ids. The
5542 * array just stores the ids communicated to the port via the wqes.
5544 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5546 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5549 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5552 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5553 if (unlikely(!rsrc_blks
)) {
5559 rsrc_blks
->rsrc_start
= rsrc_id
;
5560 rsrc_blks
->rsrc_size
= rsrc_size
;
5561 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5562 rsrc_start
= rsrc_id
;
5563 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5564 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5565 lpfc_sli4_get_els_iocb_cnt(phba
);
5567 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5572 /* Entire word processed. Get next word.*/
5577 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5582 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5583 * @phba: Pointer to HBA context object.
5584 * @type: the extent's type.
5586 * This function deallocates all extents of a particular resource type.
5587 * SLI4 does not allow for deallocating a particular extent range. It
5588 * is the caller's responsibility to release all kernel memory resources.
5591 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5594 uint32_t length
, mbox_tmo
= 0;
5596 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5597 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5599 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5604 * This function sends an embedded mailbox because it only sends the
5605 * the resource type. All extents of this type are released by the
5608 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5609 sizeof(struct lpfc_sli4_cfg_mhdr
));
5610 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5611 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5612 length
, LPFC_SLI4_MBX_EMBED
);
5614 /* Send an extents count of 0 - the dealloc doesn't use it. */
5615 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5616 LPFC_SLI4_MBX_EMBED
);
5621 if (!phba
->sli4_hba
.intr_enable
)
5622 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5624 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5625 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5632 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5633 if (bf_get(lpfc_mbox_hdr_status
,
5634 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5635 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5636 "2919 Failed to release resource extents "
5637 "for type %d - Status 0x%x Add'l Status 0x%x. "
5638 "Resource memory not released.\n",
5640 bf_get(lpfc_mbox_hdr_status
,
5641 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5642 bf_get(lpfc_mbox_hdr_add_status
,
5643 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5648 /* Release kernel memory resources for the specific type. */
5650 case LPFC_RSC_TYPE_FCOE_VPI
:
5651 kfree(phba
->vpi_bmask
);
5652 kfree(phba
->vpi_ids
);
5653 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5654 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5655 &phba
->lpfc_vpi_blk_list
, list
) {
5656 list_del_init(&rsrc_blk
->list
);
5659 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5661 case LPFC_RSC_TYPE_FCOE_XRI
:
5662 kfree(phba
->sli4_hba
.xri_bmask
);
5663 kfree(phba
->sli4_hba
.xri_ids
);
5664 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5665 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5666 list_del_init(&rsrc_blk
->list
);
5670 case LPFC_RSC_TYPE_FCOE_VFI
:
5671 kfree(phba
->sli4_hba
.vfi_bmask
);
5672 kfree(phba
->sli4_hba
.vfi_ids
);
5673 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5674 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5675 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5676 list_del_init(&rsrc_blk
->list
);
5680 case LPFC_RSC_TYPE_FCOE_RPI
:
5681 /* RPI bitmask and physical id array are cleaned up earlier. */
5682 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5683 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5684 list_del_init(&rsrc_blk
->list
);
5692 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5695 mempool_free(mbox
, phba
->mbox_mem_pool
);
5700 lpfc_set_features(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
,
5705 len
= sizeof(struct lpfc_mbx_set_feature
) -
5706 sizeof(struct lpfc_sli4_cfg_mhdr
);
5707 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5708 LPFC_MBOX_OPCODE_SET_FEATURES
, len
,
5709 LPFC_SLI4_MBX_EMBED
);
5712 case LPFC_SET_UE_RECOVERY
:
5713 bf_set(lpfc_mbx_set_feature_UER
,
5714 &mbox
->u
.mqe
.un
.set_feature
, 1);
5715 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_UE_RECOVERY
;
5716 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5718 case LPFC_SET_MDS_DIAGS
:
5719 bf_set(lpfc_mbx_set_feature_mds
,
5720 &mbox
->u
.mqe
.un
.set_feature
, 1);
5721 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk
,
5722 &mbox
->u
.mqe
.un
.set_feature
, 0);
5723 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_MDS_DIAGS
;
5724 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5732 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5733 * @phba: Pointer to HBA context object.
5735 * This function allocates all SLI4 resource identifiers.
5738 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5740 int i
, rc
, error
= 0;
5741 uint16_t count
, base
;
5742 unsigned long longs
;
5744 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5745 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5746 if (phba
->sli4_hba
.extents_in_use
) {
5748 * The port supports resource extents. The XRI, VPI, VFI, RPI
5749 * resource extent count must be read and allocated before
5750 * provisioning the resource id arrays.
5752 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5753 LPFC_IDX_RSRC_RDY
) {
5755 * Extent-based resources are set - the driver could
5756 * be in a port reset. Figure out if any corrective
5757 * actions need to be taken.
5759 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5760 LPFC_RSC_TYPE_FCOE_VFI
);
5763 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5764 LPFC_RSC_TYPE_FCOE_VPI
);
5767 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5768 LPFC_RSC_TYPE_FCOE_XRI
);
5771 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5772 LPFC_RSC_TYPE_FCOE_RPI
);
5777 * It's possible that the number of resources
5778 * provided to this port instance changed between
5779 * resets. Detect this condition and reallocate
5780 * resources. Otherwise, there is no action.
5783 lpfc_printf_log(phba
, KERN_INFO
,
5784 LOG_MBOX
| LOG_INIT
,
5785 "2931 Detected extent resource "
5786 "change. Reallocating all "
5788 rc
= lpfc_sli4_dealloc_extent(phba
,
5789 LPFC_RSC_TYPE_FCOE_VFI
);
5790 rc
= lpfc_sli4_dealloc_extent(phba
,
5791 LPFC_RSC_TYPE_FCOE_VPI
);
5792 rc
= lpfc_sli4_dealloc_extent(phba
,
5793 LPFC_RSC_TYPE_FCOE_XRI
);
5794 rc
= lpfc_sli4_dealloc_extent(phba
,
5795 LPFC_RSC_TYPE_FCOE_RPI
);
5800 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5804 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5808 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5812 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5815 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5820 * The port does not support resource extents. The XRI, VPI,
5821 * VFI, RPI resource ids were determined from READ_CONFIG.
5822 * Just allocate the bitmasks and provision the resource id
5823 * arrays. If a port reset is active, the resources don't
5824 * need any action - just exit.
5826 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5827 LPFC_IDX_RSRC_RDY
) {
5828 lpfc_sli4_dealloc_resource_identifiers(phba
);
5829 lpfc_sli4_remove_rpis(phba
);
5832 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5834 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5835 "3279 Invalid provisioning of "
5840 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5841 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5842 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5843 sizeof(unsigned long),
5845 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5849 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5852 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5854 goto free_rpi_bmask
;
5857 for (i
= 0; i
< count
; i
++)
5858 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5861 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5863 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5864 "3280 Invalid provisioning of "
5869 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5870 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5871 phba
->vpi_bmask
= kzalloc(longs
*
5872 sizeof(unsigned long),
5874 if (unlikely(!phba
->vpi_bmask
)) {
5878 phba
->vpi_ids
= kzalloc(count
*
5881 if (unlikely(!phba
->vpi_ids
)) {
5883 goto free_vpi_bmask
;
5886 for (i
= 0; i
< count
; i
++)
5887 phba
->vpi_ids
[i
] = base
+ i
;
5890 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5892 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5893 "3281 Invalid provisioning of "
5898 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5899 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5900 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5901 sizeof(unsigned long),
5903 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5907 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5908 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5911 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5913 goto free_xri_bmask
;
5916 for (i
= 0; i
< count
; i
++)
5917 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5920 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5922 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5923 "3282 Invalid provisioning of "
5928 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5929 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5930 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5931 sizeof(unsigned long),
5933 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5937 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5940 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5942 goto free_vfi_bmask
;
5945 for (i
= 0; i
< count
; i
++)
5946 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5949 * Mark all resources ready. An HBA reset doesn't need
5950 * to reset the initialization.
5952 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5958 kfree(phba
->sli4_hba
.vfi_bmask
);
5959 phba
->sli4_hba
.vfi_bmask
= NULL
;
5961 kfree(phba
->sli4_hba
.xri_ids
);
5962 phba
->sli4_hba
.xri_ids
= NULL
;
5964 kfree(phba
->sli4_hba
.xri_bmask
);
5965 phba
->sli4_hba
.xri_bmask
= NULL
;
5967 kfree(phba
->vpi_ids
);
5968 phba
->vpi_ids
= NULL
;
5970 kfree(phba
->vpi_bmask
);
5971 phba
->vpi_bmask
= NULL
;
5973 kfree(phba
->sli4_hba
.rpi_ids
);
5974 phba
->sli4_hba
.rpi_ids
= NULL
;
5976 kfree(phba
->sli4_hba
.rpi_bmask
);
5977 phba
->sli4_hba
.rpi_bmask
= NULL
;
5983 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5984 * @phba: Pointer to HBA context object.
5986 * This function allocates the number of elements for the specified
5990 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5992 if (phba
->sli4_hba
.extents_in_use
) {
5993 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5994 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5995 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5996 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5998 kfree(phba
->vpi_bmask
);
5999 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
6000 kfree(phba
->vpi_ids
);
6001 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6002 kfree(phba
->sli4_hba
.xri_bmask
);
6003 kfree(phba
->sli4_hba
.xri_ids
);
6004 kfree(phba
->sli4_hba
.vfi_bmask
);
6005 kfree(phba
->sli4_hba
.vfi_ids
);
6006 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6007 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6014 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6015 * @phba: Pointer to HBA context object.
6016 * @type: The resource extent type.
6017 * @extnt_count: buffer to hold port extent count response
6018 * @extnt_size: buffer to hold port extent size response.
6020 * This function calls the port to read the host allocated extents
6021 * for a particular type.
6024 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
6025 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
6029 uint16_t curr_blks
= 0;
6030 uint32_t req_len
, emb_len
;
6031 uint32_t alloc_len
, mbox_tmo
;
6032 struct list_head
*blk_list_head
;
6033 struct lpfc_rsrc_blks
*rsrc_blk
;
6035 void *virtaddr
= NULL
;
6036 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
6037 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
6038 union lpfc_sli4_cfg_shdr
*shdr
;
6041 case LPFC_RSC_TYPE_FCOE_VPI
:
6042 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
6044 case LPFC_RSC_TYPE_FCOE_XRI
:
6045 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
6047 case LPFC_RSC_TYPE_FCOE_VFI
:
6048 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
6050 case LPFC_RSC_TYPE_FCOE_RPI
:
6051 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
6057 /* Count the number of extents currently allocatd for this type. */
6058 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
6059 if (curr_blks
== 0) {
6061 * The GET_ALLOCATED mailbox does not return the size,
6062 * just the count. The size should be just the size
6063 * stored in the current allocated block and all sizes
6064 * for an extent type are the same so set the return
6067 *extnt_size
= rsrc_blk
->rsrc_size
;
6073 * Calculate the size of an embedded mailbox. The uint32_t
6074 * accounts for extents-specific word.
6076 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
6080 * Presume the allocation and response will fit into an embedded
6081 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6083 emb
= LPFC_SLI4_MBX_EMBED
;
6085 if (req_len
> emb_len
) {
6086 req_len
= curr_blks
* sizeof(uint16_t) +
6087 sizeof(union lpfc_sli4_cfg_shdr
) +
6089 emb
= LPFC_SLI4_MBX_NEMBED
;
6092 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6095 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
6097 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6098 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
6100 if (alloc_len
< req_len
) {
6101 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6102 "2983 Allocated DMA memory size (x%x) is "
6103 "less than the requested DMA memory "
6104 "size (x%x)\n", alloc_len
, req_len
);
6108 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
6114 if (!phba
->sli4_hba
.intr_enable
)
6115 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6117 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
6118 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6127 * Figure out where the response is located. Then get local pointers
6128 * to the response data. The port does not guarantee to respond to
6129 * all extents counts request so update the local variable with the
6130 * allocated count from the port.
6132 if (emb
== LPFC_SLI4_MBX_EMBED
) {
6133 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
6134 shdr
= &rsrc_ext
->header
.cfg_shdr
;
6135 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
6137 virtaddr
= mbox
->sge_array
->addr
[0];
6138 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
6139 shdr
= &n_rsrc
->cfg_shdr
;
6140 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
6143 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
6144 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
6145 "2984 Failed to read allocated resources "
6146 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6148 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
6149 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
6154 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
6159 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
6160 * @phba: pointer to lpfc hba data structure.
6162 * This routine walks the list of els buffers that have been allocated and
6163 * repost them to the port by using SGL block post. This is needed after a
6164 * pci_function_reset/warm_start or start. It attempts to construct blocks
6165 * of els buffer sgls which contains contiguous xris and uses the non-embedded
6166 * SGL block post mailbox commands to post them to the port. For single els
6167 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6168 * mailbox command for posting.
6170 * Returns: 0 = success, non-zero failure.
6173 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
6175 struct lpfc_sglq
*sglq_entry
= NULL
;
6176 struct lpfc_sglq
*sglq_entry_next
= NULL
;
6177 struct lpfc_sglq
*sglq_entry_first
= NULL
;
6178 int status
, total_cnt
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
6179 int last_xritag
= NO_XRI
;
6180 struct lpfc_sli_ring
*pring
;
6181 LIST_HEAD(prep_sgl_list
);
6182 LIST_HEAD(blck_sgl_list
);
6183 LIST_HEAD(allc_sgl_list
);
6184 LIST_HEAD(post_sgl_list
);
6185 LIST_HEAD(free_sgl_list
);
6187 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6188 spin_lock_irq(&phba
->hbalock
);
6189 spin_lock(&pring
->ring_lock
);
6190 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
6191 spin_unlock(&pring
->ring_lock
);
6192 spin_unlock_irq(&phba
->hbalock
);
6194 total_cnt
= phba
->sli4_hba
.els_xri_cnt
;
6195 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6196 &allc_sgl_list
, list
) {
6197 list_del_init(&sglq_entry
->list
);
6199 if ((last_xritag
!= NO_XRI
) &&
6200 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6201 /* a hole in xri block, form a sgl posting block */
6202 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6203 post_cnt
= block_cnt
- 1;
6204 /* prepare list for next posting block */
6205 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6208 /* prepare list for next posting block */
6209 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6210 /* enough sgls for non-embed sgl mbox command */
6211 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6212 list_splice_init(&prep_sgl_list
,
6214 post_cnt
= block_cnt
;
6220 /* keep track of last sgl's xritag */
6221 last_xritag
= sglq_entry
->sli4_xritag
;
6223 /* end of repost sgl list condition for els buffers */
6224 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
6225 if (post_cnt
== 0) {
6226 list_splice_init(&prep_sgl_list
,
6228 post_cnt
= block_cnt
;
6229 } else if (block_cnt
== 1) {
6230 status
= lpfc_sli4_post_sgl(phba
,
6231 sglq_entry
->phys
, 0,
6232 sglq_entry
->sli4_xritag
);
6234 /* successful, put sgl to posted list */
6235 list_add_tail(&sglq_entry
->list
,
6238 /* Failure, put sgl to free list */
6239 lpfc_printf_log(phba
, KERN_WARNING
,
6241 "3159 Failed to post els "
6242 "sgl, xritag:x%x\n",
6243 sglq_entry
->sli4_xritag
);
6244 list_add_tail(&sglq_entry
->list
,
6251 /* continue until a nembed page worth of sgls */
6255 /* post the els buffer list sgls as a block */
6256 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
6260 /* success, put sgl list to posted sgl list */
6261 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6263 /* Failure, put sgl list to free sgl list */
6264 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6267 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6268 "3160 Failed to post els sgl-list, "
6270 sglq_entry_first
->sli4_xritag
,
6271 (sglq_entry_first
->sli4_xritag
+
6273 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6274 total_cnt
-= post_cnt
;
6277 /* don't reset xirtag due to hole in xri block */
6279 last_xritag
= NO_XRI
;
6281 /* reset els sgl post count for next round of posting */
6284 /* update the number of XRIs posted for ELS */
6285 phba
->sli4_hba
.els_xri_cnt
= total_cnt
;
6287 /* free the els sgls failed to post */
6288 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6290 /* push els sgls posted to the availble list */
6291 if (!list_empty(&post_sgl_list
)) {
6292 spin_lock_irq(&phba
->hbalock
);
6293 spin_lock(&pring
->ring_lock
);
6294 list_splice_init(&post_sgl_list
,
6295 &phba
->sli4_hba
.lpfc_sgl_list
);
6296 spin_unlock(&pring
->ring_lock
);
6297 spin_unlock_irq(&phba
->hbalock
);
6299 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6300 "3161 Failure to post els sgl to port.\n");
6307 lpfc_set_host_data(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
6311 len
= sizeof(struct lpfc_mbx_set_host_data
) -
6312 sizeof(struct lpfc_sli4_cfg_mhdr
);
6313 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6314 LPFC_MBOX_OPCODE_SET_HOST_DATA
, len
,
6315 LPFC_SLI4_MBX_EMBED
);
6317 mbox
->u
.mqe
.un
.set_host_data
.param_id
= LPFC_SET_HOST_OS_DRIVER_VERSION
;
6318 mbox
->u
.mqe
.un
.set_host_data
.param_len
=
6319 LPFC_HOST_OS_DRIVER_VERSION_SIZE
;
6320 snprintf(mbox
->u
.mqe
.un
.set_host_data
.data
,
6321 LPFC_HOST_OS_DRIVER_VERSION_SIZE
,
6322 "Linux %s v"LPFC_DRIVER_VERSION
,
6323 (phba
->hba_flag
& HBA_FCOE_MODE
) ? "FCoE" : "FC");
6327 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6328 * @phba: Pointer to HBA context object.
6330 * This function is the main SLI4 device intialization PCI function. This
6331 * function is called by the HBA intialization code, HBA reset code and
6332 * HBA error attention handler code. Caller is not required to hold any
6336 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6339 LPFC_MBOXQ_t
*mboxq
;
6340 struct lpfc_mqe
*mqe
;
6343 uint32_t ftr_rsp
= 0;
6344 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6345 struct lpfc_vport
*vport
= phba
->pport
;
6346 struct lpfc_dmabuf
*mp
;
6348 /* Perform a PCI function reset to start from clean */
6349 rc
= lpfc_pci_function_reset(phba
);
6353 /* Check the HBA Host Status Register for readyness */
6354 rc
= lpfc_sli4_post_status_check(phba
);
6358 spin_lock_irq(&phba
->hbalock
);
6359 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6360 spin_unlock_irq(&phba
->hbalock
);
6364 * Allocate a single mailbox container for initializing the
6367 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6371 /* Issue READ_REV to collect vpd and FW information. */
6372 vpd_size
= SLI4_PAGE_SIZE
;
6373 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6379 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6385 mqe
= &mboxq
->u
.mqe
;
6386 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6387 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
)) {
6388 phba
->hba_flag
|= HBA_FCOE_MODE
;
6389 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
6391 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6394 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6396 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6398 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6400 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6402 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6403 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6404 "0376 READ_REV Error. SLI Level %d "
6405 "FCoE enabled %d\n",
6406 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6413 * Continue initialization with default values even if driver failed
6414 * to read FCoE param config regions, only read parameters if the
6417 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6418 lpfc_sli4_read_fcoe_params(phba
))
6419 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6420 "2570 Failed to read FCoE parameters\n");
6423 * Retrieve sli4 device physical port name, failure of doing it
6424 * is considered as non-fatal.
6426 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6428 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6429 "3080 Successful retrieving SLI4 device "
6430 "physical port name: %s.\n", phba
->Port
);
6433 * Evaluate the read rev and vpd data. Populate the driver
6434 * state with the results. If this routine fails, the failure
6435 * is not fatal as the driver will use generic values.
6437 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6438 if (unlikely(!rc
)) {
6439 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6440 "0377 Error %d parsing vpd. "
6441 "Using defaults.\n", rc
);
6446 /* Save information as VPD data */
6447 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6448 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6449 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6450 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6452 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6454 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6456 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6458 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6459 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6460 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6461 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6462 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6463 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6464 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6465 "(%d):0380 READ_REV Status x%x "
6466 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6467 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6468 bf_get(lpfc_mqe_status
, mqe
),
6469 phba
->vpd
.rev
.opFwName
,
6470 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6471 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6473 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6474 rc
= (phba
->sli4_hba
.max_cfg_param
.max_xri
>> 3);
6475 if (phba
->pport
->cfg_lun_queue_depth
> rc
) {
6476 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6477 "3362 LUN queue depth changed from %d to %d\n",
6478 phba
->pport
->cfg_lun_queue_depth
, rc
);
6479 phba
->pport
->cfg_lun_queue_depth
= rc
;
6482 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6483 LPFC_SLI_INTF_IF_TYPE_0
) {
6484 lpfc_set_features(phba
, mboxq
, LPFC_SET_UE_RECOVERY
);
6485 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6486 if (rc
== MBX_SUCCESS
) {
6487 phba
->hba_flag
|= HBA_RECOVERABLE_UE
;
6488 /* Set 1Sec interval to detect UE */
6489 phba
->eratt_poll_interval
= 1;
6490 phba
->sli4_hba
.ue_to_sr
= bf_get(
6491 lpfc_mbx_set_feature_UESR
,
6492 &mboxq
->u
.mqe
.un
.set_feature
);
6493 phba
->sli4_hba
.ue_to_rp
= bf_get(
6494 lpfc_mbx_set_feature_UERP
,
6495 &mboxq
->u
.mqe
.un
.set_feature
);
6499 if (phba
->cfg_enable_mds_diags
&& phba
->mds_diags_support
) {
6500 /* Enable MDS Diagnostics only if the SLI Port supports it */
6501 lpfc_set_features(phba
, mboxq
, LPFC_SET_MDS_DIAGS
);
6502 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6503 if (rc
!= MBX_SUCCESS
)
6504 phba
->mds_diags_support
= 0;
6508 * Discover the port's supported feature set and match it against the
6511 lpfc_request_features(phba
, mboxq
);
6512 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6519 * The port must support FCP initiator mode as this is the
6520 * only mode running in the host.
6522 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6523 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6524 "0378 No support for fcpi mode.\n");
6527 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6528 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6530 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6532 * If the port cannot support the host's requested features
6533 * then turn off the global config parameters to disable the
6534 * feature in the driver. This is not a fatal error.
6536 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6537 if (phba
->cfg_enable_bg
) {
6538 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6539 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6544 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6545 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6549 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6550 "0379 Feature Mismatch Data: x%08x %08x "
6551 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6552 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6553 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6554 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6555 phba
->cfg_enable_bg
= 0;
6556 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6557 phba
->cfg_enable_npiv
= 0;
6560 /* These SLI3 features are assumed in SLI4 */
6561 spin_lock_irq(&phba
->hbalock
);
6562 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6563 spin_unlock_irq(&phba
->hbalock
);
6566 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6567 * calls depends on these resources to complete port setup.
6569 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6571 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6572 "2920 Failed to alloc Resource IDs "
6577 lpfc_set_host_data(phba
, mboxq
);
6579 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6581 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6582 "2134 Failed to set host os driver version %x",
6586 /* Read the port's service parameters. */
6587 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6589 phba
->link_state
= LPFC_HBA_ERROR
;
6594 mboxq
->vport
= vport
;
6595 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6596 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6597 if (rc
== MBX_SUCCESS
) {
6598 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6603 * This memory was allocated by the lpfc_read_sparam routine. Release
6604 * it to the mbuf pool.
6606 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6608 mboxq
->context1
= NULL
;
6610 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6611 "0382 READ_SPARAM command failed "
6612 "status %d, mbxStatus x%x\n",
6613 rc
, bf_get(lpfc_mqe_status
, mqe
));
6614 phba
->link_state
= LPFC_HBA_ERROR
;
6619 lpfc_update_vport_wwn(vport
);
6621 /* Update the fc_host data structures with new wwn. */
6622 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6623 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6625 /* update host els and scsi xri-sgl sizes and mappings */
6626 rc
= lpfc_sli4_xri_sgl_update(phba
);
6628 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6629 "1400 Failed to update xri-sgl size and "
6630 "mapping: %d\n", rc
);
6634 /* register the els sgl pool to the port */
6635 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6637 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6638 "0582 Error %d during els sgl post "
6644 /* register the allocated scsi sgl pool to the port */
6645 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6647 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6648 "0383 Error %d during scsi sgl post "
6650 /* Some Scsi buffers were moved to the abort scsi list */
6651 /* A pci function reset will repost them */
6656 /* Post the rpi header region to the device. */
6657 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6659 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6660 "0393 Error %d during rpi post operation\n",
6665 lpfc_sli4_node_prep(phba
);
6667 /* Create all the SLI4 queues */
6668 rc
= lpfc_sli4_queue_create(phba
);
6670 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6671 "3089 Failed to allocate queues\n");
6673 goto out_stop_timers
;
6675 /* Set up all the queues to the device */
6676 rc
= lpfc_sli4_queue_setup(phba
);
6678 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6679 "0381 Error %d during queue setup.\n ", rc
);
6680 goto out_destroy_queue
;
6683 /* Arm the CQs and then EQs on device */
6684 lpfc_sli4_arm_cqeq_intr(phba
);
6686 /* Indicate device interrupt mode */
6687 phba
->sli4_hba
.intr_enable
= 1;
6689 /* Allow asynchronous mailbox command to go through */
6690 spin_lock_irq(&phba
->hbalock
);
6691 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6692 spin_unlock_irq(&phba
->hbalock
);
6694 /* Post receive buffers to the device */
6695 lpfc_sli4_rb_setup(phba
);
6697 /* Reset HBA FCF states after HBA reset */
6698 phba
->fcf
.fcf_flag
= 0;
6699 phba
->fcf
.current_rec
.flag
= 0;
6701 /* Start the ELS watchdog timer */
6702 mod_timer(&vport
->els_tmofunc
,
6703 jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2)));
6705 /* Start heart beat timer */
6706 mod_timer(&phba
->hb_tmofunc
,
6707 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
6708 phba
->hb_outstanding
= 0;
6709 phba
->last_completion_time
= jiffies
;
6711 /* Start error attention (ERATT) polling timer */
6712 mod_timer(&phba
->eratt_poll
,
6713 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
6715 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6716 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6717 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6719 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6720 "2829 This device supports "
6721 "Advanced Error Reporting (AER)\n");
6722 spin_lock_irq(&phba
->hbalock
);
6723 phba
->hba_flag
|= HBA_AER_ENABLED
;
6724 spin_unlock_irq(&phba
->hbalock
);
6726 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6727 "2830 This device does not support "
6728 "Advanced Error Reporting (AER)\n");
6729 phba
->cfg_aer_support
= 0;
6734 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6736 * The FC Port needs to register FCFI (index 0)
6738 lpfc_reg_fcfi(phba
, mboxq
);
6739 mboxq
->vport
= phba
->pport
;
6740 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6741 if (rc
!= MBX_SUCCESS
)
6742 goto out_unset_queue
;
6744 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6745 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6747 /* Check if the port is configured to be disabled */
6748 lpfc_sli_read_link_ste(phba
);
6752 * The port is ready, set the host's link state to LINK_DOWN
6753 * in preparation for link interrupts.
6755 spin_lock_irq(&phba
->hbalock
);
6756 phba
->link_state
= LPFC_LINK_DOWN
;
6757 spin_unlock_irq(&phba
->hbalock
);
6758 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6759 (phba
->hba_flag
& LINK_DISABLED
)) {
6760 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6761 "3103 Adapter Link is disabled.\n");
6762 lpfc_down_link(phba
, mboxq
);
6763 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6764 if (rc
!= MBX_SUCCESS
) {
6765 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6766 "3104 Adapter failed to issue "
6767 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6768 goto out_unset_queue
;
6770 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6771 /* don't perform init_link on SLI4 FC port loopback test */
6772 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6773 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6775 goto out_unset_queue
;
6778 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6781 /* Unset all the queues set up in this routine when error out */
6782 lpfc_sli4_queue_unset(phba
);
6784 lpfc_sli4_queue_destroy(phba
);
6786 lpfc_stop_hba_timers(phba
);
6788 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6793 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6794 * @ptr: context object - pointer to hba structure.
6796 * This is the callback function for mailbox timer. The mailbox
6797 * timer is armed when a new mailbox command is issued and the timer
6798 * is deleted when the mailbox complete. The function is called by
6799 * the kernel timer code when a mailbox does not complete within
6800 * expected time. This function wakes up the worker thread to
6801 * process the mailbox timeout and returns. All the processing is
6802 * done by the worker thread function lpfc_mbox_timeout_handler.
6805 lpfc_mbox_timeout(unsigned long ptr
)
6807 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6808 unsigned long iflag
;
6809 uint32_t tmo_posted
;
6811 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6812 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6814 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6815 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6818 lpfc_worker_wake_up(phba
);
6823 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
6825 * @phba: Pointer to HBA context object.
6827 * This function checks if any mailbox completions are present on the mailbox
6831 lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
)
6835 struct lpfc_queue
*mcq
;
6836 struct lpfc_mcqe
*mcqe
;
6837 bool pending_completions
= false;
6839 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
6842 /* Check for completions on mailbox completion queue */
6844 mcq
= phba
->sli4_hba
.mbx_cq
;
6845 idx
= mcq
->hba_index
;
6846 while (bf_get_le32(lpfc_cqe_valid
, mcq
->qe
[idx
].cqe
)) {
6847 mcqe
= (struct lpfc_mcqe
*)mcq
->qe
[idx
].cqe
;
6848 if (bf_get_le32(lpfc_trailer_completed
, mcqe
) &&
6849 (!bf_get_le32(lpfc_trailer_async
, mcqe
))) {
6850 pending_completions
= true;
6853 idx
= (idx
+ 1) % mcq
->entry_count
;
6854 if (mcq
->hba_index
== idx
)
6857 return pending_completions
;
6862 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
6864 * @phba: Pointer to HBA context object.
6866 * For sli4, it is possible to miss an interrupt. As such mbox completions
6867 * maybe missed causing erroneous mailbox timeouts to occur. This function
6868 * checks to see if mbox completions are on the mailbox completion queue
6869 * and will process all the completions associated with the eq for the
6870 * mailbox completion queue.
6873 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
)
6877 struct lpfc_queue
*fpeq
= NULL
;
6878 struct lpfc_eqe
*eqe
;
6881 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
6884 /* Find the eq associated with the mcq */
6886 if (phba
->sli4_hba
.hba_eq
)
6887 for (eqidx
= 0; eqidx
< phba
->cfg_fcp_io_channel
; eqidx
++)
6888 if (phba
->sli4_hba
.hba_eq
[eqidx
]->queue_id
==
6889 phba
->sli4_hba
.mbx_cq
->assoc_qid
) {
6890 fpeq
= phba
->sli4_hba
.hba_eq
[eqidx
];
6896 /* Turn off interrupts from this EQ */
6898 lpfc_sli4_eq_clr_intr(fpeq
);
6900 /* Check to see if a mbox completion is pending */
6902 mbox_pending
= lpfc_sli4_mbox_completions_pending(phba
);
6905 * If a mbox completion is pending, process all the events on EQ
6906 * associated with the mbox completion queue (this could include
6907 * mailbox commands, async events, els commands, receive queue data
6912 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
6913 lpfc_sli4_hba_handle_eqe(phba
, eqe
, eqidx
);
6914 fpeq
->EQ_processed
++;
6917 /* Always clear and re-arm the EQ */
6919 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
6921 return mbox_pending
;
6926 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6927 * @phba: Pointer to HBA context object.
6929 * This function is called from worker thread when a mailbox command times out.
6930 * The caller is not required to hold any locks. This function will reset the
6931 * HBA and recover all the pending commands.
6934 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6936 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6937 MAILBOX_t
*mb
= NULL
;
6939 struct lpfc_sli
*psli
= &phba
->sli
;
6941 /* If the mailbox completed, process the completion and return */
6942 if (lpfc_sli4_process_missed_mbox_completions(phba
))
6947 /* Check the pmbox pointer first. There is a race condition
6948 * between the mbox timeout handler getting executed in the
6949 * worklist and the mailbox actually completing. When this
6950 * race condition occurs, the mbox_active will be NULL.
6952 spin_lock_irq(&phba
->hbalock
);
6953 if (pmbox
== NULL
) {
6954 lpfc_printf_log(phba
, KERN_WARNING
,
6956 "0353 Active Mailbox cleared - mailbox timeout "
6958 spin_unlock_irq(&phba
->hbalock
);
6962 /* Mbox cmd <mbxCommand> timeout */
6963 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6964 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6966 phba
->pport
->port_state
,
6968 phba
->sli
.mbox_active
);
6969 spin_unlock_irq(&phba
->hbalock
);
6971 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6972 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6973 * it to fail all outstanding SCSI IO.
6975 spin_lock_irq(&phba
->pport
->work_port_lock
);
6976 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6977 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6978 spin_lock_irq(&phba
->hbalock
);
6979 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6980 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6981 spin_unlock_irq(&phba
->hbalock
);
6983 lpfc_sli_abort_fcp_rings(phba
);
6985 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6986 "0345 Resetting board due to mailbox timeout\n");
6988 /* Reset the HBA device */
6989 lpfc_reset_hba(phba
);
6993 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6994 * @phba: Pointer to HBA context object.
6995 * @pmbox: Pointer to mailbox object.
6996 * @flag: Flag indicating how the mailbox need to be processed.
6998 * This function is called by discovery code and HBA management code
6999 * to submit a mailbox command to firmware with SLI-3 interface spec. This
7000 * function gets the hbalock to protect the data structures.
7001 * The mailbox command can be submitted in polling mode, in which case
7002 * this function will wait in a polling loop for the completion of the
7004 * If the mailbox is submitted in no_wait mode (not polling) the
7005 * function will submit the command and returns immediately without waiting
7006 * for the mailbox completion. The no_wait is supported only when HBA
7007 * is in SLI2/SLI3 mode - interrupts are enabled.
7008 * The SLI interface allows only one mailbox pending at a time. If the
7009 * mailbox is issued in polling mode and there is already a mailbox
7010 * pending, then the function will return an error. If the mailbox is issued
7011 * in NO_WAIT mode and there is a mailbox pending already, the function
7012 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
7013 * The sli layer owns the mailbox object until the completion of mailbox
7014 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
7015 * return codes the caller owns the mailbox command after the return of
7019 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
7023 struct lpfc_sli
*psli
= &phba
->sli
;
7024 uint32_t status
, evtctr
;
7025 uint32_t ha_copy
, hc_copy
;
7027 unsigned long timeout
;
7028 unsigned long drvr_flag
= 0;
7029 uint32_t word0
, ldata
;
7030 void __iomem
*to_slim
;
7031 int processing_queue
= 0;
7033 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7035 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7036 /* processing mbox queue from intr_handler */
7037 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7038 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7041 processing_queue
= 1;
7042 pmbox
= lpfc_mbox_get(phba
);
7044 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7049 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
7050 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
7052 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7053 lpfc_printf_log(phba
, KERN_ERR
,
7054 LOG_MBOX
| LOG_VPORT
,
7055 "1806 Mbox x%x failed. No vport\n",
7056 pmbox
->u
.mb
.mbxCommand
);
7058 goto out_not_finished
;
7062 /* If the PCI channel is in offline state, do not post mbox. */
7063 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7064 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7065 goto out_not_finished
;
7068 /* If HBA has a deferred error attention, fail the iocb. */
7069 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7070 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7071 goto out_not_finished
;
7077 status
= MBX_SUCCESS
;
7079 if (phba
->link_state
== LPFC_HBA_ERROR
) {
7080 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7082 /* Mbox command <mbxCommand> cannot issue */
7083 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7084 "(%d):0311 Mailbox command x%x cannot "
7085 "issue Data: x%x x%x\n",
7086 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7087 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7088 goto out_not_finished
;
7091 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
7092 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
7093 !(hc_copy
& HC_MBINT_ENA
)) {
7094 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7095 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7096 "(%d):2528 Mailbox command x%x cannot "
7097 "issue Data: x%x x%x\n",
7098 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7099 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7100 goto out_not_finished
;
7104 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7105 /* Polling for a mbox command when another one is already active
7106 * is not allowed in SLI. Also, the driver must have established
7107 * SLI2 mode to queue and process multiple mbox commands.
7110 if (flag
& MBX_POLL
) {
7111 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7113 /* Mbox command <mbxCommand> cannot issue */
7114 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7115 "(%d):2529 Mailbox command x%x "
7116 "cannot issue Data: x%x x%x\n",
7117 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7118 pmbox
->u
.mb
.mbxCommand
,
7119 psli
->sli_flag
, flag
);
7120 goto out_not_finished
;
7123 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
7124 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7125 /* Mbox command <mbxCommand> cannot issue */
7126 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7127 "(%d):2530 Mailbox command x%x "
7128 "cannot issue Data: x%x x%x\n",
7129 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7130 pmbox
->u
.mb
.mbxCommand
,
7131 psli
->sli_flag
, flag
);
7132 goto out_not_finished
;
7135 /* Another mailbox command is still being processed, queue this
7136 * command to be processed later.
7138 lpfc_mbox_put(phba
, pmbox
);
7140 /* Mbox cmd issue - BUSY */
7141 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7142 "(%d):0308 Mbox cmd issue - BUSY Data: "
7143 "x%x x%x x%x x%x\n",
7144 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
7145 mbx
->mbxCommand
, phba
->pport
->port_state
,
7146 psli
->sli_flag
, flag
);
7148 psli
->slistat
.mbox_busy
++;
7149 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7152 lpfc_debugfs_disc_trc(pmbox
->vport
,
7153 LPFC_DISC_TRC_MBOX_VPORT
,
7154 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
7155 (uint32_t)mbx
->mbxCommand
,
7156 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7159 lpfc_debugfs_disc_trc(phba
->pport
,
7161 "MBOX Bsy: cmd:x%x mb:x%x x%x",
7162 (uint32_t)mbx
->mbxCommand
,
7163 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7169 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7171 /* If we are not polling, we MUST be in SLI2 mode */
7172 if (flag
!= MBX_POLL
) {
7173 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
7174 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
7175 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7176 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7177 /* Mbox command <mbxCommand> cannot issue */
7178 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7179 "(%d):2531 Mailbox command x%x "
7180 "cannot issue Data: x%x x%x\n",
7181 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7182 pmbox
->u
.mb
.mbxCommand
,
7183 psli
->sli_flag
, flag
);
7184 goto out_not_finished
;
7186 /* timeout active mbox command */
7187 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7189 mod_timer(&psli
->mbox_tmo
, jiffies
+ timeout
);
7192 /* Mailbox cmd <cmd> issue */
7193 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7194 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
7196 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7197 mbx
->mbxCommand
, phba
->pport
->port_state
,
7198 psli
->sli_flag
, flag
);
7200 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
7202 lpfc_debugfs_disc_trc(pmbox
->vport
,
7203 LPFC_DISC_TRC_MBOX_VPORT
,
7204 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7205 (uint32_t)mbx
->mbxCommand
,
7206 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7209 lpfc_debugfs_disc_trc(phba
->pport
,
7211 "MBOX Send: cmd:x%x mb:x%x x%x",
7212 (uint32_t)mbx
->mbxCommand
,
7213 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7217 psli
->slistat
.mbox_cmd
++;
7218 evtctr
= psli
->slistat
.mbox_event
;
7220 /* next set own bit for the adapter and copy over command word */
7221 mbx
->mbxOwner
= OWN_CHIP
;
7223 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7224 /* Populate mbox extension offset word. */
7225 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
7226 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7227 = (uint8_t *)phba
->mbox_ext
7228 - (uint8_t *)phba
->mbox
;
7231 /* Copy the mailbox extension data */
7232 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7233 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
7234 (uint8_t *)phba
->mbox_ext
,
7235 pmbox
->in_ext_byte_len
);
7237 /* Copy command data to host SLIM area */
7238 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7240 /* Populate mbox extension offset word. */
7241 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
7242 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7243 = MAILBOX_HBA_EXT_OFFSET
;
7245 /* Copy the mailbox extension data */
7246 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7247 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
7248 MAILBOX_HBA_EXT_OFFSET
,
7249 pmbox
->context2
, pmbox
->in_ext_byte_len
);
7252 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7253 /* copy command data into host mbox for cmpl */
7254 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7257 /* First copy mbox command data to HBA SLIM, skip past first
7259 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
7260 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
7261 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
7263 /* Next copy over first word, with mbxOwner set */
7264 ldata
= *((uint32_t *)mbx
);
7265 to_slim
= phba
->MBslimaddr
;
7266 writel(ldata
, to_slim
);
7267 readl(to_slim
); /* flush */
7269 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7270 /* switch over to host mailbox */
7271 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
7279 /* Set up reference to mailbox command */
7280 psli
->mbox_active
= pmbox
;
7281 /* Interrupt board to do it */
7282 writel(CA_MBATT
, phba
->CAregaddr
);
7283 readl(phba
->CAregaddr
); /* flush */
7284 /* Don't wait for it to finish, just return */
7288 /* Set up null reference to mailbox command */
7289 psli
->mbox_active
= NULL
;
7290 /* Interrupt board to do it */
7291 writel(CA_MBATT
, phba
->CAregaddr
);
7292 readl(phba
->CAregaddr
); /* flush */
7294 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7295 /* First read mbox status word */
7296 word0
= *((uint32_t *)phba
->mbox
);
7297 word0
= le32_to_cpu(word0
);
7299 /* First read mbox status word */
7300 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
7301 spin_unlock_irqrestore(&phba
->hbalock
,
7303 goto out_not_finished
;
7307 /* Read the HBA Host Attention Register */
7308 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7309 spin_unlock_irqrestore(&phba
->hbalock
,
7311 goto out_not_finished
;
7313 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7316 /* Wait for command to complete */
7317 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
7318 (!(ha_copy
& HA_MBATT
) &&
7319 (phba
->link_state
> LPFC_WARM_START
))) {
7320 if (time_after(jiffies
, timeout
)) {
7321 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7322 spin_unlock_irqrestore(&phba
->hbalock
,
7324 goto out_not_finished
;
7327 /* Check if we took a mbox interrupt while we were
7329 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
7330 && (evtctr
!= psli
->slistat
.mbox_event
))
7334 spin_unlock_irqrestore(&phba
->hbalock
,
7337 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7340 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7341 /* First copy command data */
7342 word0
= *((uint32_t *)phba
->mbox
);
7343 word0
= le32_to_cpu(word0
);
7344 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7347 /* Check real SLIM for any errors */
7348 slimword0
= readl(phba
->MBslimaddr
);
7349 slimmb
= (MAILBOX_t
*) & slimword0
;
7350 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
7351 && slimmb
->mbxStatus
) {
7358 /* First copy command data */
7359 word0
= readl(phba
->MBslimaddr
);
7361 /* Read the HBA Host Attention Register */
7362 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7363 spin_unlock_irqrestore(&phba
->hbalock
,
7365 goto out_not_finished
;
7369 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7370 /* copy results back to user */
7371 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
, MAILBOX_CMD_SIZE
);
7372 /* Copy the mailbox extension data */
7373 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7374 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7376 pmbox
->out_ext_byte_len
);
7379 /* First copy command data */
7380 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
7382 /* Copy the mailbox extension data */
7383 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7384 lpfc_memcpy_from_slim(pmbox
->context2
,
7386 MAILBOX_HBA_EXT_OFFSET
,
7387 pmbox
->out_ext_byte_len
);
7391 writel(HA_MBATT
, phba
->HAregaddr
);
7392 readl(phba
->HAregaddr
); /* flush */
7394 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7395 status
= mbx
->mbxStatus
;
7398 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7402 if (processing_queue
) {
7403 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7404 lpfc_mbox_cmpl_put(phba
, pmbox
);
7406 return MBX_NOT_FINISHED
;
7410 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7411 * @phba: Pointer to HBA context object.
7413 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7414 * the driver internal pending mailbox queue. It will then try to wait out the
7415 * possible outstanding mailbox command before return.
7418 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7419 * the outstanding mailbox command timed out.
7422 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7424 struct lpfc_sli
*psli
= &phba
->sli
;
7426 unsigned long timeout
= 0;
7428 /* Mark the asynchronous mailbox command posting as blocked */
7429 spin_lock_irq(&phba
->hbalock
);
7430 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7431 /* Determine how long we might wait for the active mailbox
7432 * command to be gracefully completed by firmware.
7434 if (phba
->sli
.mbox_active
)
7435 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7436 phba
->sli
.mbox_active
) *
7438 spin_unlock_irq(&phba
->hbalock
);
7440 /* Make sure the mailbox is really active */
7442 lpfc_sli4_process_missed_mbox_completions(phba
);
7444 /* Wait for the outstnading mailbox command to complete */
7445 while (phba
->sli
.mbox_active
) {
7446 /* Check active mailbox complete status every 2ms */
7448 if (time_after(jiffies
, timeout
)) {
7449 /* Timeout, marked the outstanding cmd not complete */
7455 /* Can not cleanly block async mailbox command, fails it */
7457 spin_lock_irq(&phba
->hbalock
);
7458 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7459 spin_unlock_irq(&phba
->hbalock
);
7465 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7466 * @phba: Pointer to HBA context object.
7468 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7469 * commands from the driver internal pending mailbox queue. It makes sure
7470 * that there is no outstanding mailbox command before resuming posting
7471 * asynchronous mailbox commands. If, for any reason, there is outstanding
7472 * mailbox command, it will try to wait it out before resuming asynchronous
7473 * mailbox command posting.
7476 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7478 struct lpfc_sli
*psli
= &phba
->sli
;
7480 spin_lock_irq(&phba
->hbalock
);
7481 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7482 /* Asynchronous mailbox posting is not blocked, do nothing */
7483 spin_unlock_irq(&phba
->hbalock
);
7487 /* Outstanding synchronous mailbox command is guaranteed to be done,
7488 * successful or timeout, after timing-out the outstanding mailbox
7489 * command shall always be removed, so just unblock posting async
7490 * mailbox command and resume
7492 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7493 spin_unlock_irq(&phba
->hbalock
);
7495 /* wake up worker thread to post asynchronlous mailbox command */
7496 lpfc_worker_wake_up(phba
);
7500 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7501 * @phba: Pointer to HBA context object.
7502 * @mboxq: Pointer to mailbox object.
7504 * The function waits for the bootstrap mailbox register ready bit from
7505 * port for twice the regular mailbox command timeout value.
7507 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7508 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7511 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7514 unsigned long timeout
;
7515 struct lpfc_register bmbx_reg
;
7517 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7521 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7522 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7526 if (time_after(jiffies
, timeout
))
7527 return MBXERR_ERROR
;
7528 } while (!db_ready
);
7534 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7535 * @phba: Pointer to HBA context object.
7536 * @mboxq: Pointer to mailbox object.
7538 * The function posts a mailbox to the port. The mailbox is expected
7539 * to be comletely filled in and ready for the port to operate on it.
7540 * This routine executes a synchronous completion operation on the
7541 * mailbox by polling for its completion.
7543 * The caller must not be holding any locks when calling this routine.
7546 * MBX_SUCCESS - mailbox posted successfully
7547 * Any of the MBX error values.
7550 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7552 int rc
= MBX_SUCCESS
;
7553 unsigned long iflag
;
7554 uint32_t mcqe_status
;
7556 struct lpfc_sli
*psli
= &phba
->sli
;
7557 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7558 struct lpfc_bmbx_create
*mbox_rgn
;
7559 struct dma_address
*dma_address
;
7562 * Only one mailbox can be active to the bootstrap mailbox region
7563 * at a time and there is no queueing provided.
7565 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7566 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7567 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7568 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7569 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7570 "cannot issue Data: x%x x%x\n",
7571 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7572 mboxq
->u
.mb
.mbxCommand
,
7573 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7574 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7575 psli
->sli_flag
, MBX_POLL
);
7576 return MBXERR_ERROR
;
7578 /* The server grabs the token and owns it until release */
7579 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7580 phba
->sli
.mbox_active
= mboxq
;
7581 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7583 /* wait for bootstrap mbox register for readyness */
7584 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7589 * Initialize the bootstrap memory region to avoid stale data areas
7590 * in the mailbox post. Then copy the caller's mailbox contents to
7591 * the bmbx mailbox region.
7593 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7594 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7595 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7596 sizeof(struct lpfc_mqe
));
7598 /* Post the high mailbox dma address to the port and wait for ready. */
7599 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7600 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7602 /* wait for bootstrap mbox register for hi-address write done */
7603 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7607 /* Post the low mailbox dma address to the port. */
7608 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7610 /* wait for bootstrap mbox register for low address write done */
7611 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7616 * Read the CQ to ensure the mailbox has completed.
7617 * If so, update the mailbox status so that the upper layers
7618 * can complete the request normally.
7620 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7621 sizeof(struct lpfc_mqe
));
7622 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7623 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7624 sizeof(struct lpfc_mcqe
));
7625 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7627 * When the CQE status indicates a failure and the mailbox status
7628 * indicates success then copy the CQE status into the mailbox status
7629 * (and prefix it with x4000).
7631 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7632 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7633 bf_set(lpfc_mqe_status
, mb
,
7634 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7637 lpfc_sli4_swap_str(phba
, mboxq
);
7639 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7640 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7641 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7642 " x%x x%x CQ: x%x x%x x%x x%x\n",
7643 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7644 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7645 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7646 bf_get(lpfc_mqe_status
, mb
),
7647 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7648 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7649 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7650 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7651 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7652 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7653 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7654 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7655 mboxq
->mcqe
.trailer
);
7657 /* We are holding the token, no needed for lock when release */
7658 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7659 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7660 phba
->sli
.mbox_active
= NULL
;
7661 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7666 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7667 * @phba: Pointer to HBA context object.
7668 * @pmbox: Pointer to mailbox object.
7669 * @flag: Flag indicating how the mailbox need to be processed.
7671 * This function is called by discovery code and HBA management code to submit
7672 * a mailbox command to firmware with SLI-4 interface spec.
7674 * Return codes the caller owns the mailbox command after the return of the
7678 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7681 struct lpfc_sli
*psli
= &phba
->sli
;
7682 unsigned long iflags
;
7685 /* dump from issue mailbox command if setup */
7686 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7688 rc
= lpfc_mbox_dev_check(phba
);
7690 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7691 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7692 "cannot issue Data: x%x x%x\n",
7693 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7694 mboxq
->u
.mb
.mbxCommand
,
7695 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7696 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7697 psli
->sli_flag
, flag
);
7698 goto out_not_finished
;
7701 /* Detect polling mode and jump to a handler */
7702 if (!phba
->sli4_hba
.intr_enable
) {
7703 if (flag
== MBX_POLL
)
7704 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7707 if (rc
!= MBX_SUCCESS
)
7708 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7709 "(%d):2541 Mailbox command x%x "
7710 "(x%x/x%x) failure: "
7711 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7713 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7714 mboxq
->u
.mb
.mbxCommand
,
7715 lpfc_sli_config_mbox_subsys_get(phba
,
7717 lpfc_sli_config_mbox_opcode_get(phba
,
7719 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7720 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7721 bf_get(lpfc_mcqe_ext_status
,
7723 psli
->sli_flag
, flag
);
7725 } else if (flag
== MBX_POLL
) {
7726 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7727 "(%d):2542 Try to issue mailbox command "
7728 "x%x (x%x/x%x) synchronously ahead of async"
7729 "mailbox command queue: x%x x%x\n",
7730 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7731 mboxq
->u
.mb
.mbxCommand
,
7732 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7733 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7734 psli
->sli_flag
, flag
);
7735 /* Try to block the asynchronous mailbox posting */
7736 rc
= lpfc_sli4_async_mbox_block(phba
);
7738 /* Successfully blocked, now issue sync mbox cmd */
7739 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7740 if (rc
!= MBX_SUCCESS
)
7741 lpfc_printf_log(phba
, KERN_WARNING
,
7743 "(%d):2597 Sync Mailbox command "
7744 "x%x (x%x/x%x) failure: "
7745 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7747 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7748 mboxq
->u
.mb
.mbxCommand
,
7749 lpfc_sli_config_mbox_subsys_get(phba
,
7751 lpfc_sli_config_mbox_opcode_get(phba
,
7753 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7754 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7755 bf_get(lpfc_mcqe_ext_status
,
7757 psli
->sli_flag
, flag
);
7758 /* Unblock the async mailbox posting afterward */
7759 lpfc_sli4_async_mbox_unblock(phba
);
7764 /* Now, interrupt mode asynchrous mailbox command */
7765 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7767 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7768 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7769 "cannot issue Data: x%x x%x\n",
7770 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7771 mboxq
->u
.mb
.mbxCommand
,
7772 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7773 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7774 psli
->sli_flag
, flag
);
7775 goto out_not_finished
;
7778 /* Put the mailbox command to the driver internal FIFO */
7779 psli
->slistat
.mbox_busy
++;
7780 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7781 lpfc_mbox_put(phba
, mboxq
);
7782 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7783 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7784 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7785 "x%x (x%x/x%x) x%x x%x x%x\n",
7786 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7787 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7788 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7789 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7790 phba
->pport
->port_state
,
7791 psli
->sli_flag
, MBX_NOWAIT
);
7792 /* Wake up worker thread to transport mailbox command from head */
7793 lpfc_worker_wake_up(phba
);
7798 return MBX_NOT_FINISHED
;
7802 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7803 * @phba: Pointer to HBA context object.
7805 * This function is called by worker thread to send a mailbox command to
7806 * SLI4 HBA firmware.
7810 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7812 struct lpfc_sli
*psli
= &phba
->sli
;
7813 LPFC_MBOXQ_t
*mboxq
;
7814 int rc
= MBX_SUCCESS
;
7815 unsigned long iflags
;
7816 struct lpfc_mqe
*mqe
;
7819 /* Check interrupt mode before post async mailbox command */
7820 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7821 return MBX_NOT_FINISHED
;
7823 /* Check for mailbox command service token */
7824 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7825 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7826 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7827 return MBX_NOT_FINISHED
;
7829 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7830 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7831 return MBX_NOT_FINISHED
;
7833 if (unlikely(phba
->sli
.mbox_active
)) {
7834 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7835 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7836 "0384 There is pending active mailbox cmd\n");
7837 return MBX_NOT_FINISHED
;
7839 /* Take the mailbox command service token */
7840 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7842 /* Get the next mailbox command from head of queue */
7843 mboxq
= lpfc_mbox_get(phba
);
7845 /* If no more mailbox command waiting for post, we're done */
7847 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7848 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7851 phba
->sli
.mbox_active
= mboxq
;
7852 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7854 /* Check device readiness for posting mailbox command */
7855 rc
= lpfc_mbox_dev_check(phba
);
7857 /* Driver clean routine will clean up pending mailbox */
7858 goto out_not_finished
;
7860 /* Prepare the mbox command to be posted */
7861 mqe
= &mboxq
->u
.mqe
;
7862 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7864 /* Start timer for the mbox_tmo and log some mailbox post messages */
7865 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7866 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba
, mboxq
))));
7868 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7869 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7871 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7872 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7873 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7874 phba
->pport
->port_state
, psli
->sli_flag
);
7876 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7878 lpfc_debugfs_disc_trc(mboxq
->vport
,
7879 LPFC_DISC_TRC_MBOX_VPORT
,
7880 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7881 mbx_cmnd
, mqe
->un
.mb_words
[0],
7882 mqe
->un
.mb_words
[1]);
7884 lpfc_debugfs_disc_trc(phba
->pport
,
7886 "MBOX Send: cmd:x%x mb:x%x x%x",
7887 mbx_cmnd
, mqe
->un
.mb_words
[0],
7888 mqe
->un
.mb_words
[1]);
7891 psli
->slistat
.mbox_cmd
++;
7893 /* Post the mailbox command to the port */
7894 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7895 if (rc
!= MBX_SUCCESS
) {
7896 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7897 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7898 "cannot issue Data: x%x x%x\n",
7899 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7900 mboxq
->u
.mb
.mbxCommand
,
7901 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7902 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7903 psli
->sli_flag
, MBX_NOWAIT
);
7904 goto out_not_finished
;
7910 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7911 if (phba
->sli
.mbox_active
) {
7912 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7913 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7914 /* Release the token */
7915 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7916 phba
->sli
.mbox_active
= NULL
;
7918 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7920 return MBX_NOT_FINISHED
;
7924 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7925 * @phba: Pointer to HBA context object.
7926 * @pmbox: Pointer to mailbox object.
7927 * @flag: Flag indicating how the mailbox need to be processed.
7929 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7930 * the API jump table function pointer from the lpfc_hba struct.
7932 * Return codes the caller owns the mailbox command after the return of the
7936 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7938 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7942 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7943 * @phba: The hba struct for which this call is being executed.
7944 * @dev_grp: The HBA PCI-Device group number.
7946 * This routine sets up the mbox interface API function jump table in @phba
7948 * Returns: 0 - success, -ENODEV - failure.
7951 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7955 case LPFC_PCI_DEV_LP
:
7956 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7957 phba
->lpfc_sli_handle_slow_ring_event
=
7958 lpfc_sli_handle_slow_ring_event_s3
;
7959 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7960 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7961 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7963 case LPFC_PCI_DEV_OC
:
7964 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7965 phba
->lpfc_sli_handle_slow_ring_event
=
7966 lpfc_sli_handle_slow_ring_event_s4
;
7967 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7968 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7969 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7972 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7973 "1420 Invalid HBA PCI-device group: 0x%x\n",
7982 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7983 * @phba: Pointer to HBA context object.
7984 * @pring: Pointer to driver SLI ring object.
7985 * @piocb: Pointer to address of newly added command iocb.
7987 * This function is called with hbalock held to add a command
7988 * iocb to the txq when SLI layer cannot submit the command iocb
7992 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7993 struct lpfc_iocbq
*piocb
)
7995 lockdep_assert_held(&phba
->hbalock
);
7996 /* Insert the caller's iocb in the txq tail for later processing. */
7997 list_add_tail(&piocb
->list
, &pring
->txq
);
8001 * lpfc_sli_next_iocb - Get the next iocb in the txq
8002 * @phba: Pointer to HBA context object.
8003 * @pring: Pointer to driver SLI ring object.
8004 * @piocb: Pointer to address of newly added command iocb.
8006 * This function is called with hbalock held before a new
8007 * iocb is submitted to the firmware. This function checks
8008 * txq to flush the iocbs in txq to Firmware before
8009 * submitting new iocbs to the Firmware.
8010 * If there are iocbs in the txq which need to be submitted
8011 * to firmware, lpfc_sli_next_iocb returns the first element
8012 * of the txq after dequeuing it from txq.
8013 * If there is no iocb in the txq then the function will return
8014 * *piocb and *piocb is set to NULL. Caller needs to check
8015 * *piocb to find if there are more commands in the txq.
8017 static struct lpfc_iocbq
*
8018 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8019 struct lpfc_iocbq
**piocb
)
8021 struct lpfc_iocbq
* nextiocb
;
8023 lockdep_assert_held(&phba
->hbalock
);
8025 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
8035 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
8036 * @phba: Pointer to HBA context object.
8037 * @ring_number: SLI ring number to issue iocb on.
8038 * @piocb: Pointer to command iocb.
8039 * @flag: Flag indicating if this command can be put into txq.
8041 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
8042 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
8043 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
8044 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
8045 * this function allows only iocbs for posting buffers. This function finds
8046 * next available slot in the command ring and posts the command to the
8047 * available slot and writes the port attention register to request HBA start
8048 * processing new iocb. If there is no slot available in the ring and
8049 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
8050 * the function returns IOCB_BUSY.
8052 * This function is called with hbalock held. The function will return success
8053 * after it successfully submit the iocb to firmware or after adding to the
8057 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
8058 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8060 struct lpfc_iocbq
*nextiocb
;
8062 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8064 lockdep_assert_held(&phba
->hbalock
);
8066 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
8067 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
8068 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
8069 lpfc_printf_log(phba
, KERN_ERR
,
8070 LOG_SLI
| LOG_VPORT
,
8071 "1807 IOCB x%x failed. No vport\n",
8072 piocb
->iocb
.ulpCommand
);
8078 /* If the PCI channel is in offline state, do not post iocbs. */
8079 if (unlikely(pci_channel_offline(phba
->pcidev
)))
8082 /* If HBA has a deferred error attention, fail the iocb. */
8083 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
8087 * We should never get an IOCB if we are in a < LINK_DOWN state
8089 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
8093 * Check to see if we are blocking IOCB processing because of a
8094 * outstanding event.
8096 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
8099 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
8101 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
8102 * can be issued if the link is not up.
8104 switch (piocb
->iocb
.ulpCommand
) {
8105 case CMD_GEN_REQUEST64_CR
:
8106 case CMD_GEN_REQUEST64_CX
:
8107 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
8108 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
8109 FC_RCTL_DD_UNSOL_CMD
) ||
8110 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
8111 MENLO_TRANSPORT_TYPE
))
8115 case CMD_QUE_RING_BUF_CN
:
8116 case CMD_QUE_RING_BUF64_CN
:
8118 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
8119 * completion, iocb_cmpl MUST be 0.
8121 if (piocb
->iocb_cmpl
)
8122 piocb
->iocb_cmpl
= NULL
;
8124 case CMD_CREATE_XRI_CR
:
8125 case CMD_CLOSE_XRI_CN
:
8126 case CMD_CLOSE_XRI_CX
:
8133 * For FCP commands, we must be in a state where we can process link
8136 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
8137 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
8141 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
8142 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
8143 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
8146 lpfc_sli_update_ring(phba
, pring
);
8148 lpfc_sli_update_full_ring(phba
, pring
);
8151 return IOCB_SUCCESS
;
8156 pring
->stats
.iocb_cmd_delay
++;
8160 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8161 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
8162 return IOCB_SUCCESS
;
8169 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
8170 * @phba: Pointer to HBA context object.
8171 * @piocb: Pointer to command iocb.
8172 * @sglq: Pointer to the scatter gather queue object.
8174 * This routine converts the bpl or bde that is in the IOCB
8175 * to a sgl list for the sli4 hardware. The physical address
8176 * of the bpl/bde is converted back to a virtual address.
8177 * If the IOCB contains a BPL then the list of BDE's is
8178 * converted to sli4_sge's. If the IOCB contains a single
8179 * BDE then it is converted to a single sli_sge.
8180 * The IOCB is still in cpu endianess so the contents of
8181 * the bpl can be used without byte swapping.
8183 * Returns valid XRI = Success, NO_XRI = Failure.
8186 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
8187 struct lpfc_sglq
*sglq
)
8189 uint16_t xritag
= NO_XRI
;
8190 struct ulp_bde64
*bpl
= NULL
;
8191 struct ulp_bde64 bde
;
8192 struct sli4_sge
*sgl
= NULL
;
8193 struct lpfc_dmabuf
*dmabuf
;
8197 uint32_t offset
= 0; /* accumulated offset in the sg request list */
8198 int inbound
= 0; /* number of sg reply entries inbound from firmware */
8200 if (!piocbq
|| !sglq
)
8203 sgl
= (struct sli4_sge
*)sglq
->sgl
;
8204 icmd
= &piocbq
->iocb
;
8205 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
8206 return sglq
->sli4_xritag
;
8207 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8208 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
8209 sizeof(struct ulp_bde64
);
8210 /* The addrHigh and addrLow fields within the IOCB
8211 * have not been byteswapped yet so there is no
8212 * need to swap them back.
8214 if (piocbq
->context3
)
8215 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
8219 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
8223 for (i
= 0; i
< numBdes
; i
++) {
8224 /* Should already be byte swapped. */
8225 sgl
->addr_hi
= bpl
->addrHigh
;
8226 sgl
->addr_lo
= bpl
->addrLow
;
8228 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8229 if ((i
+1) == numBdes
)
8230 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8232 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
8233 /* swap the size field back to the cpu so we
8234 * can assign it to the sgl.
8236 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8237 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
8238 /* The offsets in the sgl need to be accumulated
8239 * separately for the request and reply lists.
8240 * The request is always first, the reply follows.
8242 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
8243 /* add up the reply sg entries */
8244 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
8246 /* first inbound? reset the offset */
8249 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
8250 bf_set(lpfc_sli4_sge_type
, sgl
,
8251 LPFC_SGE_TYPE_DATA
);
8252 offset
+= bde
.tus
.f
.bdeSize
;
8254 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8258 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
8259 /* The addrHigh and addrLow fields of the BDE have not
8260 * been byteswapped yet so they need to be swapped
8261 * before putting them in the sgl.
8264 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
8266 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
8267 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8268 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8269 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8271 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
8273 return sglq
->sli4_xritag
;
8277 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8278 * @phba: Pointer to HBA context object.
8279 * @piocb: Pointer to command iocb.
8280 * @wqe: Pointer to the work queue entry.
8282 * This routine converts the iocb command to its Work Queue Entry
8283 * equivalent. The wqe pointer should not have any fields set when
8284 * this routine is called because it will memcpy over them.
8285 * This routine does not set the CQ_ID or the WQEC bits in the
8288 * Returns: 0 = Success, IOCB_ERROR = Failure.
8291 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
8292 union lpfc_wqe
*wqe
)
8294 uint32_t xmit_len
= 0, total_len
= 0;
8298 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
8301 uint16_t abrt_iotag
;
8302 struct lpfc_iocbq
*abrtiocbq
;
8303 struct ulp_bde64
*bpl
= NULL
;
8304 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
8306 struct ulp_bde64 bde
;
8307 struct lpfc_nodelist
*ndlp
;
8311 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
8312 /* The fcp commands will set command type */
8313 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8314 command_type
= FCP_COMMAND
;
8315 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
8316 command_type
= ELS_COMMAND_FIP
;
8318 command_type
= ELS_COMMAND_NON_FIP
;
8320 if (phba
->fcp_embed_io
)
8321 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
8322 /* Some of the fields are in the right position already */
8323 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
8324 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
8325 wqe
->generic
.wqe_com
.word10
= 0;
8327 abort_tag
= (uint32_t) iocbq
->iotag
;
8328 xritag
= iocbq
->sli4_xritag
;
8329 /* words0-2 bpl convert bde */
8330 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8331 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8332 sizeof(struct ulp_bde64
);
8333 bpl
= (struct ulp_bde64
*)
8334 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
8338 /* Should already be byte swapped. */
8339 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
8340 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
8341 /* swap the size field back to the cpu so we
8342 * can assign it to the sgl.
8344 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8345 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
8347 for (i
= 0; i
< numBdes
; i
++) {
8348 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8349 total_len
+= bde
.tus
.f
.bdeSize
;
8352 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8354 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8355 cmnd
= iocbq
->iocb
.ulpCommand
;
8357 switch (iocbq
->iocb
.ulpCommand
) {
8358 case CMD_ELS_REQUEST64_CR
:
8359 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8360 ndlp
= iocbq
->context_un
.ndlp
;
8362 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8363 if (!iocbq
->iocb
.ulpLe
) {
8364 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8365 "2007 Only Limited Edition cmd Format"
8366 " supported 0x%x\n",
8367 iocbq
->iocb
.ulpCommand
);
8371 wqe
->els_req
.payload_len
= xmit_len
;
8372 /* Els_reguest64 has a TMO */
8373 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8374 iocbq
->iocb
.ulpTimeout
);
8375 /* Need a VF for word 4 set the vf bit*/
8376 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
8377 /* And a VFID for word 12 */
8378 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
8379 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8380 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8381 iocbq
->iocb
.ulpContext
);
8382 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
8383 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
8384 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8385 if (command_type
== ELS_COMMAND_FIP
)
8386 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
8387 >> LPFC_FIP_ELS_ID_SHIFT
);
8388 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8389 iocbq
->context2
)->virt
);
8390 if_type
= bf_get(lpfc_sli_intf_if_type
,
8391 &phba
->sli4_hba
.sli_intf
);
8392 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8393 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
8394 *pcmd
== ELS_CMD_SCR
||
8395 *pcmd
== ELS_CMD_FDISC
||
8396 *pcmd
== ELS_CMD_LOGO
||
8397 *pcmd
== ELS_CMD_PLOGI
)) {
8398 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8399 bf_set(els_req64_sid
, &wqe
->els_req
,
8400 iocbq
->vport
->fc_myDID
);
8401 if ((*pcmd
== ELS_CMD_FLOGI
) &&
8402 !(phba
->fc_topology
==
8403 LPFC_TOPOLOGY_LOOP
))
8404 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
8405 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8406 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8407 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8408 } else if (pcmd
&& iocbq
->context1
) {
8409 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
8410 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8411 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8414 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
8415 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8416 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
8417 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
8418 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8419 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
8420 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8421 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
8422 wqe
->els_req
.max_response_payload_len
= total_len
- xmit_len
;
8424 case CMD_XMIT_SEQUENCE64_CX
:
8425 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
8426 iocbq
->iocb
.un
.ulpWord
[3]);
8427 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
8428 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8429 /* The entire sequence is transmitted for this IOCB */
8430 xmit_len
= total_len
;
8431 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8432 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8433 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8434 case CMD_XMIT_SEQUENCE64_CR
:
8435 /* word3 iocb=io_tag32 wqe=reserved */
8436 wqe
->xmit_sequence
.rsvd3
= 0;
8437 /* word4 relative_offset memcpy */
8438 /* word5 r_ctl/df_ctl memcpy */
8439 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8440 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8441 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8442 LPFC_WQE_IOD_WRITE
);
8443 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8444 LPFC_WQE_LENLOC_WORD12
);
8445 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8446 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8447 command_type
= OTHER_COMMAND
;
8449 case CMD_XMIT_BCAST64_CN
:
8450 /* word3 iocb=iotag32 wqe=seq_payload_len */
8451 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8452 /* word4 iocb=rsvd wqe=rsvd */
8453 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8454 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8455 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8456 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8457 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8458 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8459 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8460 LPFC_WQE_LENLOC_WORD3
);
8461 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8463 case CMD_FCP_IWRITE64_CR
:
8464 command_type
= FCP_COMMAND_DATA_OUT
;
8465 /* word3 iocb=iotag wqe=payload_offset_len */
8466 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8467 bf_set(payload_offset_len
, &wqe
->fcp_iwrite
,
8468 xmit_len
+ sizeof(struct fcp_rsp
));
8469 bf_set(cmd_buff_len
, &wqe
->fcp_iwrite
,
8471 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8472 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8473 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8474 iocbq
->iocb
.ulpFCP2Rcvy
);
8475 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8476 /* Always open the exchange */
8477 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8478 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8479 LPFC_WQE_LENLOC_WORD4
);
8480 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8481 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8482 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8483 bf_set(wqe_oas
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8484 bf_set(wqe_ccpe
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8485 if (iocbq
->priority
) {
8486 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8487 (iocbq
->priority
<< 1));
8489 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8490 (phba
->cfg_XLanePriority
<< 1));
8493 /* Note, word 10 is already initialized to 0 */
8495 if (phba
->fcp_embed_io
) {
8496 struct lpfc_scsi_buf
*lpfc_cmd
;
8497 struct sli4_sge
*sgl
;
8498 union lpfc_wqe128
*wqe128
;
8499 struct fcp_cmnd
*fcp_cmnd
;
8502 /* 128 byte wqe support here */
8503 wqe128
= (union lpfc_wqe128
*)wqe
;
8505 lpfc_cmd
= iocbq
->context1
;
8506 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8507 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8509 /* Word 0-2 - FCP_CMND */
8510 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8511 BUFF_TYPE_BDE_IMMED
;
8512 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8513 wqe128
->generic
.bde
.addrHigh
= 0;
8514 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8516 bf_set(wqe_wqes
, &wqe128
->fcp_iwrite
.wqe_com
, 1);
8518 /* Word 22-29 FCP CMND Payload */
8519 ptr
= &wqe128
->words
[22];
8520 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8523 case CMD_FCP_IREAD64_CR
:
8524 /* word3 iocb=iotag wqe=payload_offset_len */
8525 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8526 bf_set(payload_offset_len
, &wqe
->fcp_iread
,
8527 xmit_len
+ sizeof(struct fcp_rsp
));
8528 bf_set(cmd_buff_len
, &wqe
->fcp_iread
,
8530 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8531 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8532 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8533 iocbq
->iocb
.ulpFCP2Rcvy
);
8534 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8535 /* Always open the exchange */
8536 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8537 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8538 LPFC_WQE_LENLOC_WORD4
);
8539 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8540 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8541 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8542 bf_set(wqe_oas
, &wqe
->fcp_iread
.wqe_com
, 1);
8543 bf_set(wqe_ccpe
, &wqe
->fcp_iread
.wqe_com
, 1);
8544 if (iocbq
->priority
) {
8545 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8546 (iocbq
->priority
<< 1));
8548 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8549 (phba
->cfg_XLanePriority
<< 1));
8552 /* Note, word 10 is already initialized to 0 */
8554 if (phba
->fcp_embed_io
) {
8555 struct lpfc_scsi_buf
*lpfc_cmd
;
8556 struct sli4_sge
*sgl
;
8557 union lpfc_wqe128
*wqe128
;
8558 struct fcp_cmnd
*fcp_cmnd
;
8561 /* 128 byte wqe support here */
8562 wqe128
= (union lpfc_wqe128
*)wqe
;
8564 lpfc_cmd
= iocbq
->context1
;
8565 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8566 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8568 /* Word 0-2 - FCP_CMND */
8569 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8570 BUFF_TYPE_BDE_IMMED
;
8571 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8572 wqe128
->generic
.bde
.addrHigh
= 0;
8573 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8575 bf_set(wqe_wqes
, &wqe128
->fcp_iread
.wqe_com
, 1);
8577 /* Word 22-29 FCP CMND Payload */
8578 ptr
= &wqe128
->words
[22];
8579 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8582 case CMD_FCP_ICMND64_CR
:
8583 /* word3 iocb=iotag wqe=payload_offset_len */
8584 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8585 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
8586 xmit_len
+ sizeof(struct fcp_rsp
));
8587 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
,
8589 /* word3 iocb=IO_TAG wqe=reserved */
8590 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8591 /* Always open the exchange */
8592 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8593 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8594 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8595 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8596 LPFC_WQE_LENLOC_NONE
);
8597 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
8598 iocbq
->iocb
.ulpFCP2Rcvy
);
8599 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8600 bf_set(wqe_oas
, &wqe
->fcp_icmd
.wqe_com
, 1);
8601 bf_set(wqe_ccpe
, &wqe
->fcp_icmd
.wqe_com
, 1);
8602 if (iocbq
->priority
) {
8603 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8604 (iocbq
->priority
<< 1));
8606 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8607 (phba
->cfg_XLanePriority
<< 1));
8610 /* Note, word 10 is already initialized to 0 */
8612 if (phba
->fcp_embed_io
) {
8613 struct lpfc_scsi_buf
*lpfc_cmd
;
8614 struct sli4_sge
*sgl
;
8615 union lpfc_wqe128
*wqe128
;
8616 struct fcp_cmnd
*fcp_cmnd
;
8619 /* 128 byte wqe support here */
8620 wqe128
= (union lpfc_wqe128
*)wqe
;
8622 lpfc_cmd
= iocbq
->context1
;
8623 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8624 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8626 /* Word 0-2 - FCP_CMND */
8627 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8628 BUFF_TYPE_BDE_IMMED
;
8629 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8630 wqe128
->generic
.bde
.addrHigh
= 0;
8631 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8633 bf_set(wqe_wqes
, &wqe128
->fcp_icmd
.wqe_com
, 1);
8635 /* Word 22-29 FCP CMND Payload */
8636 ptr
= &wqe128
->words
[22];
8637 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8640 case CMD_GEN_REQUEST64_CR
:
8641 /* For this command calculate the xmit length of the
8645 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8646 sizeof(struct ulp_bde64
);
8647 for (i
= 0; i
< numBdes
; i
++) {
8648 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8649 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8651 xmit_len
+= bde
.tus
.f
.bdeSize
;
8653 /* word3 iocb=IO_TAG wqe=request_payload_len */
8654 wqe
->gen_req
.request_payload_len
= xmit_len
;
8655 /* word4 iocb=parameter wqe=relative_offset memcpy */
8656 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8657 /* word6 context tag copied in memcpy */
8658 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8659 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8660 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8661 "2015 Invalid CT %x command 0x%x\n",
8662 ct
, iocbq
->iocb
.ulpCommand
);
8665 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8666 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8667 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8668 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8669 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8670 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8671 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8672 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8673 wqe
->gen_req
.max_response_payload_len
= total_len
- xmit_len
;
8674 command_type
= OTHER_COMMAND
;
8676 case CMD_XMIT_ELS_RSP64_CX
:
8677 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8678 /* words0-2 BDE memcpy */
8679 /* word3 iocb=iotag32 wqe=response_payload_len */
8680 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8682 wqe
->xmit_els_rsp
.word4
= 0;
8683 /* word5 iocb=rsvd wge=did */
8684 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8685 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
8687 if_type
= bf_get(lpfc_sli_intf_if_type
,
8688 &phba
->sli4_hba
.sli_intf
);
8689 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8690 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
8691 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8692 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8693 iocbq
->vport
->fc_myDID
);
8694 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
8696 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
8700 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8701 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8702 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8703 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8704 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8705 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8706 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8707 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8708 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8709 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8710 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8711 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8712 LPFC_WQE_LENLOC_WORD3
);
8713 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8714 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8715 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8716 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8717 iocbq
->context2
)->virt
);
8718 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8719 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8720 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8721 iocbq
->vport
->fc_myDID
);
8722 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8723 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8724 phba
->vpi_ids
[phba
->pport
->vpi
]);
8726 command_type
= OTHER_COMMAND
;
8728 case CMD_CLOSE_XRI_CN
:
8729 case CMD_ABORT_XRI_CN
:
8730 case CMD_ABORT_XRI_CX
:
8731 /* words 0-2 memcpy should be 0 rserved */
8732 /* port will send abts */
8733 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8734 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8735 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8736 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8740 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8742 * The link is down, or the command was ELS_FIP
8743 * so the fw does not need to send abts
8746 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8748 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8749 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8750 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8751 wqe
->abort_cmd
.rsrvd5
= 0;
8752 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8753 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8754 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8756 * The abort handler will send us CMD_ABORT_XRI_CN or
8757 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8759 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8760 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8761 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8762 LPFC_WQE_LENLOC_NONE
);
8763 cmnd
= CMD_ABORT_XRI_CX
;
8764 command_type
= OTHER_COMMAND
;
8767 case CMD_XMIT_BLS_RSP64_CX
:
8768 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8769 /* As BLS ABTS RSP WQE is very different from other WQEs,
8770 * we re-construct this WQE here based on information in
8771 * iocbq from scratch.
8773 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8774 /* OX_ID is invariable to who sent ABTS to CT exchange */
8775 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8776 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8777 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8778 LPFC_ABTS_UNSOL_INT
) {
8779 /* ABTS sent by initiator to CT exchange, the
8780 * RX_ID field will be filled with the newly
8781 * allocated responder XRI.
8783 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8784 iocbq
->sli4_xritag
);
8786 /* ABTS sent by responder to CT exchange, the
8787 * RX_ID field will be filled with the responder
8790 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8791 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8793 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8794 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8797 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8799 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8800 iocbq
->iocb
.ulpContext
);
8801 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8802 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8803 phba
->vpi_ids
[phba
->pport
->vpi
]);
8804 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8805 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8806 LPFC_WQE_LENLOC_NONE
);
8807 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8808 command_type
= OTHER_COMMAND
;
8809 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8810 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8811 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8812 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8813 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8814 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8815 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8819 case CMD_XRI_ABORTED_CX
:
8820 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8821 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8822 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8823 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8824 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8826 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8827 "2014 Invalid command 0x%x\n",
8828 iocbq
->iocb
.ulpCommand
);
8833 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
8834 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
8835 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
8836 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
8837 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
8838 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
8839 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
8840 LPFC_IO_DIF_INSERT
);
8841 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8842 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8843 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8844 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8845 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8846 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8847 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8852 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8853 * @phba: Pointer to HBA context object.
8854 * @ring_number: SLI ring number to issue iocb on.
8855 * @piocb: Pointer to command iocb.
8856 * @flag: Flag indicating if this command can be put into txq.
8858 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8859 * an iocb command to an HBA with SLI-4 interface spec.
8861 * This function is called with hbalock held. The function will return success
8862 * after it successfully submit the iocb to firmware or after adding to the
8866 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8867 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8869 struct lpfc_sglq
*sglq
;
8870 union lpfc_wqe
*wqe
;
8871 union lpfc_wqe128 wqe128
;
8872 struct lpfc_queue
*wq
;
8873 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8875 lockdep_assert_held(&phba
->hbalock
);
8878 * The WQE can be either 64 or 128 bytes,
8879 * so allocate space on the stack assuming the largest.
8881 wqe
= (union lpfc_wqe
*)&wqe128
;
8883 if (piocb
->sli4_xritag
== NO_XRI
) {
8884 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8885 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8888 if (!list_empty(&pring
->txq
)) {
8889 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8890 __lpfc_sli_ringtx_put(phba
,
8892 return IOCB_SUCCESS
;
8897 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8899 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8900 __lpfc_sli_ringtx_put(phba
,
8903 return IOCB_SUCCESS
;
8909 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8910 /* These IO's already have an XRI and a mapped sgl. */
8914 * This is a continuation of a commandi,(CX) so this
8915 * sglq is on the active list
8917 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
8923 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8924 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8925 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8929 if (lpfc_sli4_iocb2wqe(phba
, piocb
, wqe
))
8932 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8933 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8934 if (!phba
->cfg_fof
|| (!(piocb
->iocb_flag
& LPFC_IO_OAS
))) {
8935 wq
= phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
];
8937 wq
= phba
->sli4_hba
.oas_wq
;
8939 if (lpfc_sli4_wq_put(wq
, wqe
))
8942 if (unlikely(!phba
->sli4_hba
.els_wq
))
8944 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, wqe
))
8947 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8953 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8955 * This routine wraps the actual lockless version for issusing IOCB function
8956 * pointer from the lpfc_hba struct.
8959 * IOCB_ERROR - Error
8960 * IOCB_SUCCESS - Success
8964 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8965 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8967 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8971 * lpfc_sli_api_table_setup - Set up sli api function jump table
8972 * @phba: The hba struct for which this call is being executed.
8973 * @dev_grp: The HBA PCI-Device group number.
8975 * This routine sets up the SLI interface API function jump table in @phba
8977 * Returns: 0 - success, -ENODEV - failure.
8980 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8984 case LPFC_PCI_DEV_LP
:
8985 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8986 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8988 case LPFC_PCI_DEV_OC
:
8989 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8990 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8993 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8994 "1419 Invalid HBA PCI-device group: 0x%x\n",
8999 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
9004 * lpfc_sli_calc_ring - Calculates which ring to use
9005 * @phba: Pointer to HBA context object.
9006 * @ring_number: Initial ring
9007 * @piocb: Pointer to command iocb.
9009 * For SLI4, FCP IO can deferred to one fo many WQs, based on
9010 * fcp_wqidx, thus we need to calculate the corresponding ring.
9011 * Since ABORTS must go on the same WQ of the command they are
9012 * aborting, we use command's fcp_wqidx.
9015 lpfc_sli_calc_ring(struct lpfc_hba
*phba
, uint32_t ring_number
,
9016 struct lpfc_iocbq
*piocb
)
9018 if (phba
->sli_rev
< LPFC_SLI_REV4
)
9021 if (piocb
->iocb_flag
& (LPFC_IO_FCP
| LPFC_USE_FCPWQIDX
)) {
9022 if (!(phba
->cfg_fof
) ||
9023 (!(piocb
->iocb_flag
& LPFC_IO_FOF
))) {
9024 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
9025 return LPFC_HBA_ERROR
;
9027 * for abort iocb fcp_wqidx should already
9028 * be setup based on what work queue we used.
9030 if (!(piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
))
9032 lpfc_sli4_scmd_to_wqidx_distr(phba
,
9034 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+
9037 if (unlikely(!phba
->sli4_hba
.oas_wq
))
9038 return LPFC_HBA_ERROR
;
9039 piocb
->fcp_wqidx
= 0;
9040 ring_number
= LPFC_FCP_OAS_RING
;
9047 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
9048 * @phba: Pointer to HBA context object.
9049 * @pring: Pointer to driver SLI ring object.
9050 * @piocb: Pointer to command iocb.
9051 * @flag: Flag indicating if this command can be put into txq.
9053 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
9054 * function. This function gets the hbalock and calls
9055 * __lpfc_sli_issue_iocb function and will return the error returned
9056 * by __lpfc_sli_issue_iocb function. This wrapper is used by
9057 * functions which do not hold hbalock.
9060 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9061 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9063 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
9064 struct lpfc_sli_ring
*pring
;
9065 struct lpfc_queue
*fpeq
;
9066 struct lpfc_eqe
*eqe
;
9067 unsigned long iflags
;
9070 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9071 ring_number
= lpfc_sli_calc_ring(phba
, ring_number
, piocb
);
9072 if (unlikely(ring_number
== LPFC_HBA_ERROR
))
9074 idx
= piocb
->fcp_wqidx
;
9076 pring
= &phba
->sli
.ring
[ring_number
];
9077 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9078 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9079 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9081 if (lpfc_fcp_look_ahead
&& (piocb
->iocb_flag
& LPFC_IO_FCP
)) {
9082 fcp_eq_hdl
= &phba
->sli4_hba
.fcp_eq_hdl
[idx
];
9084 if (atomic_dec_and_test(&fcp_eq_hdl
->
9087 /* Get associated EQ with this index */
9088 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
9090 /* Turn off interrupts from this EQ */
9091 lpfc_sli4_eq_clr_intr(fpeq
);
9094 * Process all the events on FCP EQ
9096 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9097 lpfc_sli4_hba_handle_eqe(phba
,
9099 fpeq
->EQ_processed
++;
9102 /* Always clear and re-arm the EQ */
9103 lpfc_sli4_eq_release(fpeq
,
9106 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
9109 /* For now, SLI2/3 will still use hbalock */
9110 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9111 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9112 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9118 * lpfc_extra_ring_setup - Extra ring setup function
9119 * @phba: Pointer to HBA context object.
9121 * This function is called while driver attaches with the
9122 * HBA to setup the extra ring. The extra ring is used
9123 * only when driver needs to support target mode functionality
9124 * or IP over FC functionalities.
9126 * This function is called with no lock held.
9129 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
9131 struct lpfc_sli
*psli
;
9132 struct lpfc_sli_ring
*pring
;
9136 /* Adjust cmd/rsp ring iocb entries more evenly */
9138 /* Take some away from the FCP ring */
9139 pring
= &psli
->ring
[psli
->fcp_ring
];
9140 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9141 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9142 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9143 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9145 /* and give them to the extra ring */
9146 pring
= &psli
->ring
[psli
->extra_ring
];
9148 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9149 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9150 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9151 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9153 /* Setup default profile for this ring */
9154 pring
->iotag_max
= 4096;
9155 pring
->num_mask
= 1;
9156 pring
->prt
[0].profile
= 0; /* Mask 0 */
9157 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
9158 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
9159 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
9163 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
9164 * @phba: Pointer to HBA context object.
9165 * @iocbq: Pointer to iocb object.
9167 * The async_event handler calls this routine when it receives
9168 * an ASYNC_STATUS_CN event from the port. The port generates
9169 * this event when an Abort Sequence request to an rport fails
9170 * twice in succession. The abort could be originated by the
9171 * driver or by the port. The ABTS could have been for an ELS
9172 * or FCP IO. The port only generates this event when an ABTS
9173 * fails to complete after one retry.
9176 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
9177 struct lpfc_iocbq
*iocbq
)
9179 struct lpfc_nodelist
*ndlp
= NULL
;
9180 uint16_t rpi
= 0, vpi
= 0;
9181 struct lpfc_vport
*vport
= NULL
;
9183 /* The rpi in the ulpContext is vport-sensitive. */
9184 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
9185 rpi
= iocbq
->iocb
.ulpContext
;
9187 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9188 "3092 Port generated ABTS async event "
9189 "on vpi %d rpi %d status 0x%x\n",
9190 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
9192 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
9195 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
9196 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
9199 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
9200 lpfc_sli_abts_recover_port(vport
, ndlp
);
9204 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9205 "3095 Event Context not found, no "
9206 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
9207 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
9211 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
9212 * @phba: pointer to HBA context object.
9213 * @ndlp: nodelist pointer for the impacted rport.
9214 * @axri: pointer to the wcqe containing the failed exchange.
9216 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
9217 * port. The port generates this event when an abort exchange request to an
9218 * rport fails twice in succession with no reply. The abort could be originated
9219 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
9222 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
9223 struct lpfc_nodelist
*ndlp
,
9224 struct sli4_wcqe_xri_aborted
*axri
)
9226 struct lpfc_vport
*vport
;
9227 uint32_t ext_status
= 0;
9229 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
9230 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9231 "3115 Node Context not found, driver "
9232 "ignoring abts err event\n");
9236 vport
= ndlp
->vport
;
9237 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9238 "3116 Port generated FCP XRI ABORT event on "
9239 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
9240 ndlp
->vport
->vpi
, phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
],
9241 bf_get(lpfc_wcqe_xa_xri
, axri
),
9242 bf_get(lpfc_wcqe_xa_status
, axri
),
9246 * Catch the ABTS protocol failure case. Older OCe FW releases returned
9247 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
9248 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
9250 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
9251 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
9252 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
9253 lpfc_sli_abts_recover_port(vport
, ndlp
);
9257 * lpfc_sli_async_event_handler - ASYNC iocb handler function
9258 * @phba: Pointer to HBA context object.
9259 * @pring: Pointer to driver SLI ring object.
9260 * @iocbq: Pointer to iocb object.
9262 * This function is called by the slow ring event handler
9263 * function when there is an ASYNC event iocb in the ring.
9264 * This function is called with no lock held.
9265 * Currently this function handles only temperature related
9266 * ASYNC events. The function decodes the temperature sensor
9267 * event message and posts events for the management applications.
9270 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
9271 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
9275 struct temp_event temp_event_data
;
9276 struct Scsi_Host
*shost
;
9279 icmd
= &iocbq
->iocb
;
9280 evt_code
= icmd
->un
.asyncstat
.evt_code
;
9283 case ASYNC_TEMP_WARN
:
9284 case ASYNC_TEMP_SAFE
:
9285 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
9286 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
9287 if (evt_code
== ASYNC_TEMP_WARN
) {
9288 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
9289 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9290 "0347 Adapter is very hot, please take "
9291 "corrective action. temperature : %d Celsius\n",
9292 (uint32_t) icmd
->ulpContext
);
9294 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
9295 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9296 "0340 Adapter temperature is OK now. "
9297 "temperature : %d Celsius\n",
9298 (uint32_t) icmd
->ulpContext
);
9301 /* Send temperature change event to applications */
9302 shost
= lpfc_shost_from_vport(phba
->pport
);
9303 fc_host_post_vendor_event(shost
, fc_get_event_number(),
9304 sizeof(temp_event_data
), (char *) &temp_event_data
,
9307 case ASYNC_STATUS_CN
:
9308 lpfc_sli_abts_err_handler(phba
, iocbq
);
9311 iocb_w
= (uint32_t *) icmd
;
9312 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9313 "0346 Ring %d handler: unexpected ASYNC_STATUS"
9315 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9316 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9317 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9318 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
9319 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
9320 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
9321 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
9322 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
9323 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
9331 * lpfc_sli_setup - SLI ring setup function
9332 * @phba: Pointer to HBA context object.
9334 * lpfc_sli_setup sets up rings of the SLI interface with
9335 * number of iocbs per ring and iotags. This function is
9336 * called while driver attach to the HBA and before the
9337 * interrupts are enabled. So there is no need for locking.
9339 * This function always returns 0.
9342 lpfc_sli_setup(struct lpfc_hba
*phba
)
9344 int i
, totiocbsize
= 0;
9345 struct lpfc_sli
*psli
= &phba
->sli
;
9346 struct lpfc_sli_ring
*pring
;
9348 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
9349 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9350 psli
->num_rings
+= phba
->cfg_fcp_io_channel
;
9352 psli
->fcp_ring
= LPFC_FCP_RING
;
9353 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
9354 psli
->extra_ring
= LPFC_EXTRA_RING
;
9356 psli
->iocbq_lookup
= NULL
;
9357 psli
->iocbq_lookup_len
= 0;
9358 psli
->last_iotag
= 0;
9360 for (i
= 0; i
< psli
->num_rings
; i
++) {
9361 pring
= &psli
->ring
[i
];
9363 case LPFC_FCP_RING
: /* ring 0 - FCP */
9364 /* numCiocb and numRiocb are used in config_port */
9365 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
9366 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
9367 pring
->sli
.sli3
.numCiocb
+=
9368 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9369 pring
->sli
.sli3
.numRiocb
+=
9370 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9371 pring
->sli
.sli3
.numCiocb
+=
9372 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9373 pring
->sli
.sli3
.numRiocb
+=
9374 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9375 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9376 SLI3_IOCB_CMD_SIZE
:
9378 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9379 SLI3_IOCB_RSP_SIZE
:
9381 pring
->iotag_ctr
= 0;
9383 (phba
->cfg_hba_queue_depth
* 2);
9384 pring
->fast_iotag
= pring
->iotag_max
;
9385 pring
->num_mask
= 0;
9387 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
9388 /* numCiocb and numRiocb are used in config_port */
9389 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
9390 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
9391 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9392 SLI3_IOCB_CMD_SIZE
:
9394 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9395 SLI3_IOCB_RSP_SIZE
:
9397 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
9398 pring
->num_mask
= 0;
9400 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
9401 /* numCiocb and numRiocb are used in config_port */
9402 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
9403 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
9404 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9405 SLI3_IOCB_CMD_SIZE
:
9407 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9408 SLI3_IOCB_RSP_SIZE
:
9410 pring
->fast_iotag
= 0;
9411 pring
->iotag_ctr
= 0;
9412 pring
->iotag_max
= 4096;
9413 pring
->lpfc_sli_rcv_async_status
=
9414 lpfc_sli_async_event_handler
;
9415 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9416 pring
->prt
[0].profile
= 0; /* Mask 0 */
9417 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9418 pring
->prt
[0].type
= FC_TYPE_ELS
;
9419 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9420 lpfc_els_unsol_event
;
9421 pring
->prt
[1].profile
= 0; /* Mask 1 */
9422 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9423 pring
->prt
[1].type
= FC_TYPE_ELS
;
9424 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9425 lpfc_els_unsol_event
;
9426 pring
->prt
[2].profile
= 0; /* Mask 2 */
9427 /* NameServer Inquiry */
9428 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9430 pring
->prt
[2].type
= FC_TYPE_CT
;
9431 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9432 lpfc_ct_unsol_event
;
9433 pring
->prt
[3].profile
= 0; /* Mask 3 */
9434 /* NameServer response */
9435 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9437 pring
->prt
[3].type
= FC_TYPE_CT
;
9438 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9439 lpfc_ct_unsol_event
;
9442 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
9443 pring
->sli
.sli3
.sizeCiocb
) +
9444 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
9446 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
9447 /* Too many cmd / rsp ring entries in SLI2 SLIM */
9448 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
9449 "SLI2 SLIM Data: x%x x%lx\n",
9450 phba
->brd_no
, totiocbsize
,
9451 (unsigned long) MAX_SLIM_IOCB_SIZE
);
9453 if (phba
->cfg_multi_ring_support
== 2)
9454 lpfc_extra_ring_setup(phba
);
9460 * lpfc_sli_queue_setup - Queue initialization function
9461 * @phba: Pointer to HBA context object.
9463 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
9464 * ring. This function also initializes ring indices of each ring.
9465 * This function is called during the initialization of the SLI
9466 * interface of an HBA.
9467 * This function is called with no lock held and always returns
9471 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
9473 struct lpfc_sli
*psli
;
9474 struct lpfc_sli_ring
*pring
;
9478 spin_lock_irq(&phba
->hbalock
);
9479 INIT_LIST_HEAD(&psli
->mboxq
);
9480 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9481 /* Initialize list headers for txq and txcmplq as double linked lists */
9482 for (i
= 0; i
< psli
->num_rings
; i
++) {
9483 pring
= &psli
->ring
[i
];
9485 pring
->sli
.sli3
.next_cmdidx
= 0;
9486 pring
->sli
.sli3
.local_getidx
= 0;
9487 pring
->sli
.sli3
.cmdidx
= 0;
9489 INIT_LIST_HEAD(&pring
->txq
);
9490 INIT_LIST_HEAD(&pring
->txcmplq
);
9491 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9492 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
9493 INIT_LIST_HEAD(&pring
->postbufq
);
9494 spin_lock_init(&pring
->ring_lock
);
9496 spin_unlock_irq(&phba
->hbalock
);
9501 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9502 * @phba: Pointer to HBA context object.
9504 * This routine flushes the mailbox command subsystem. It will unconditionally
9505 * flush all the mailbox commands in the three possible stages in the mailbox
9506 * command sub-system: pending mailbox command queue; the outstanding mailbox
9507 * command; and completed mailbox command queue. It is caller's responsibility
9508 * to make sure that the driver is in the proper state to flush the mailbox
9509 * command sub-system. Namely, the posting of mailbox commands into the
9510 * pending mailbox command queue from the various clients must be stopped;
9511 * either the HBA is in a state that it will never works on the outstanding
9512 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
9513 * mailbox command has been completed.
9516 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
9518 LIST_HEAD(completions
);
9519 struct lpfc_sli
*psli
= &phba
->sli
;
9521 unsigned long iflag
;
9523 /* Flush all the mailbox commands in the mbox system */
9524 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9525 /* The pending mailbox command queue */
9526 list_splice_init(&phba
->sli
.mboxq
, &completions
);
9527 /* The outstanding active mailbox command */
9528 if (psli
->mbox_active
) {
9529 list_add_tail(&psli
->mbox_active
->list
, &completions
);
9530 psli
->mbox_active
= NULL
;
9531 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9533 /* The completed mailbox command queue */
9534 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
9535 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9537 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
9538 while (!list_empty(&completions
)) {
9539 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
9540 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
9542 pmb
->mbox_cmpl(phba
, pmb
);
9547 * lpfc_sli_host_down - Vport cleanup function
9548 * @vport: Pointer to virtual port object.
9550 * lpfc_sli_host_down is called to clean up the resources
9551 * associated with a vport before destroying virtual
9552 * port data structures.
9553 * This function does following operations:
9554 * - Free discovery resources associated with this virtual
9556 * - Free iocbs associated with this virtual port in
9558 * - Send abort for all iocb commands associated with this
9561 * This function is called with no lock held and always returns 1.
9564 lpfc_sli_host_down(struct lpfc_vport
*vport
)
9566 LIST_HEAD(completions
);
9567 struct lpfc_hba
*phba
= vport
->phba
;
9568 struct lpfc_sli
*psli
= &phba
->sli
;
9569 struct lpfc_sli_ring
*pring
;
9570 struct lpfc_iocbq
*iocb
, *next_iocb
;
9572 unsigned long flags
= 0;
9573 uint16_t prev_pring_flag
;
9575 lpfc_cleanup_discovery_resources(vport
);
9577 spin_lock_irqsave(&phba
->hbalock
, flags
);
9578 for (i
= 0; i
< psli
->num_rings
; i
++) {
9579 pring
= &psli
->ring
[i
];
9580 prev_pring_flag
= pring
->flag
;
9581 /* Only slow rings */
9582 if (pring
->ringno
== LPFC_ELS_RING
) {
9583 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9584 /* Set the lpfc data pending flag */
9585 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9588 * Error everything on the txq since these iocbs have not been
9589 * given to the FW yet.
9591 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
9592 if (iocb
->vport
!= vport
)
9594 list_move_tail(&iocb
->list
, &completions
);
9597 /* Next issue ABTS for everything on the txcmplq */
9598 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
9600 if (iocb
->vport
!= vport
)
9602 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
9605 pring
->flag
= prev_pring_flag
;
9608 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9610 /* Cancel all the IOCBs from the completions list */
9611 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9617 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9618 * @phba: Pointer to HBA context object.
9620 * This function cleans up all iocb, buffers, mailbox commands
9621 * while shutting down the HBA. This function is called with no
9622 * lock held and always returns 1.
9623 * This function does the following to cleanup driver resources:
9624 * - Free discovery resources for each virtual port
9625 * - Cleanup any pending fabric iocbs
9626 * - Iterate through the iocb txq and free each entry
9628 * - Free up any buffer posted to the HBA
9629 * - Free mailbox commands in the mailbox queue.
9632 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
9634 LIST_HEAD(completions
);
9635 struct lpfc_sli
*psli
= &phba
->sli
;
9636 struct lpfc_sli_ring
*pring
;
9637 struct lpfc_dmabuf
*buf_ptr
;
9638 unsigned long flags
= 0;
9641 /* Shutdown the mailbox command sub-system */
9642 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
9644 lpfc_hba_down_prep(phba
);
9646 lpfc_fabric_abort_hba(phba
);
9648 spin_lock_irqsave(&phba
->hbalock
, flags
);
9649 for (i
= 0; i
< psli
->num_rings
; i
++) {
9650 pring
= &psli
->ring
[i
];
9651 /* Only slow rings */
9652 if (pring
->ringno
== LPFC_ELS_RING
) {
9653 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9654 /* Set the lpfc data pending flag */
9655 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9659 * Error everything on the txq since these iocbs have not been
9660 * given to the FW yet.
9662 list_splice_init(&pring
->txq
, &completions
);
9664 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9666 /* Cancel all the IOCBs from the completions list */
9667 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9670 spin_lock_irqsave(&phba
->hbalock
, flags
);
9671 list_splice_init(&phba
->elsbuf
, &completions
);
9672 phba
->elsbuf_cnt
= 0;
9673 phba
->elsbuf_prev_cnt
= 0;
9674 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9676 while (!list_empty(&completions
)) {
9677 list_remove_head(&completions
, buf_ptr
,
9678 struct lpfc_dmabuf
, list
);
9679 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
9683 /* Return any active mbox cmds */
9684 del_timer_sync(&psli
->mbox_tmo
);
9686 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
9687 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9688 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9694 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9695 * @srcp: Source memory pointer.
9696 * @destp: Destination memory pointer.
9697 * @cnt: Number of words required to be copied.
9699 * This function is used for copying data between driver memory
9700 * and the SLI memory. This function also changes the endianness
9701 * of each word if native endianness is different from SLI
9702 * endianness. This function can be called with or without
9706 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9708 uint32_t *src
= srcp
;
9709 uint32_t *dest
= destp
;
9713 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9715 ldata
= le32_to_cpu(ldata
);
9724 * lpfc_sli_bemem_bcopy - SLI memory copy function
9725 * @srcp: Source memory pointer.
9726 * @destp: Destination memory pointer.
9727 * @cnt: Number of words required to be copied.
9729 * This function is used for copying data between a data structure
9730 * with big endian representation to local endianness.
9731 * This function can be called with or without lock.
9734 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9736 uint32_t *src
= srcp
;
9737 uint32_t *dest
= destp
;
9741 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9743 ldata
= be32_to_cpu(ldata
);
9751 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9752 * @phba: Pointer to HBA context object.
9753 * @pring: Pointer to driver SLI ring object.
9754 * @mp: Pointer to driver buffer object.
9756 * This function is called with no lock held.
9757 * It always return zero after adding the buffer to the postbufq
9761 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9762 struct lpfc_dmabuf
*mp
)
9764 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9766 spin_lock_irq(&phba
->hbalock
);
9767 list_add_tail(&mp
->list
, &pring
->postbufq
);
9768 pring
->postbufq_cnt
++;
9769 spin_unlock_irq(&phba
->hbalock
);
9774 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9775 * @phba: Pointer to HBA context object.
9777 * When HBQ is enabled, buffers are searched based on tags. This function
9778 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9779 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9780 * does not conflict with tags of buffer posted for unsolicited events.
9781 * The function returns the allocated tag. The function is called with
9785 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9787 spin_lock_irq(&phba
->hbalock
);
9788 phba
->buffer_tag_count
++;
9790 * Always set the QUE_BUFTAG_BIT to distiguish between
9791 * a tag assigned by HBQ.
9793 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9794 spin_unlock_irq(&phba
->hbalock
);
9795 return phba
->buffer_tag_count
;
9799 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9800 * @phba: Pointer to HBA context object.
9801 * @pring: Pointer to driver SLI ring object.
9804 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9805 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9806 * iocb is posted to the response ring with the tag of the buffer.
9807 * This function searches the pring->postbufq list using the tag
9808 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9809 * iocb. If the buffer is found then lpfc_dmabuf object of the
9810 * buffer is returned to the caller else NULL is returned.
9811 * This function is called with no lock held.
9813 struct lpfc_dmabuf
*
9814 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9817 struct lpfc_dmabuf
*mp
, *next_mp
;
9818 struct list_head
*slp
= &pring
->postbufq
;
9820 /* Search postbufq, from the beginning, looking for a match on tag */
9821 spin_lock_irq(&phba
->hbalock
);
9822 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9823 if (mp
->buffer_tag
== tag
) {
9824 list_del_init(&mp
->list
);
9825 pring
->postbufq_cnt
--;
9826 spin_unlock_irq(&phba
->hbalock
);
9831 spin_unlock_irq(&phba
->hbalock
);
9832 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9833 "0402 Cannot find virtual addr for buffer tag on "
9834 "ring %d Data x%lx x%p x%p x%x\n",
9835 pring
->ringno
, (unsigned long) tag
,
9836 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9842 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9843 * @phba: Pointer to HBA context object.
9844 * @pring: Pointer to driver SLI ring object.
9845 * @phys: DMA address of the buffer.
9847 * This function searches the buffer list using the dma_address
9848 * of unsolicited event to find the driver's lpfc_dmabuf object
9849 * corresponding to the dma_address. The function returns the
9850 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9851 * This function is called by the ct and els unsolicited event
9852 * handlers to get the buffer associated with the unsolicited
9855 * This function is called with no lock held.
9857 struct lpfc_dmabuf
*
9858 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9861 struct lpfc_dmabuf
*mp
, *next_mp
;
9862 struct list_head
*slp
= &pring
->postbufq
;
9864 /* Search postbufq, from the beginning, looking for a match on phys */
9865 spin_lock_irq(&phba
->hbalock
);
9866 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9867 if (mp
->phys
== phys
) {
9868 list_del_init(&mp
->list
);
9869 pring
->postbufq_cnt
--;
9870 spin_unlock_irq(&phba
->hbalock
);
9875 spin_unlock_irq(&phba
->hbalock
);
9876 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9877 "0410 Cannot find virtual addr for mapped buf on "
9878 "ring %d Data x%llx x%p x%p x%x\n",
9879 pring
->ringno
, (unsigned long long)phys
,
9880 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9885 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9886 * @phba: Pointer to HBA context object.
9887 * @cmdiocb: Pointer to driver command iocb object.
9888 * @rspiocb: Pointer to driver response iocb object.
9890 * This function is the completion handler for the abort iocbs for
9891 * ELS commands. This function is called from the ELS ring event
9892 * handler with no lock held. This function frees memory resources
9893 * associated with the abort iocb.
9896 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9897 struct lpfc_iocbq
*rspiocb
)
9899 IOCB_t
*irsp
= &rspiocb
->iocb
;
9900 uint16_t abort_iotag
, abort_context
;
9901 struct lpfc_iocbq
*abort_iocb
= NULL
;
9903 if (irsp
->ulpStatus
) {
9906 * Assume that the port already completed and returned, or
9907 * will return the iocb. Just Log the message.
9909 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9910 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9912 spin_lock_irq(&phba
->hbalock
);
9913 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9914 if (abort_iotag
!= 0 &&
9915 abort_iotag
<= phba
->sli
.last_iotag
)
9917 phba
->sli
.iocbq_lookup
[abort_iotag
];
9919 /* For sli4 the abort_tag is the XRI,
9920 * so the abort routine puts the iotag of the iocb
9921 * being aborted in the context field of the abort
9924 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9926 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9927 "0327 Cannot abort els iocb %p "
9928 "with tag %x context %x, abort status %x, "
9930 abort_iocb
, abort_iotag
, abort_context
,
9931 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9933 spin_unlock_irq(&phba
->hbalock
);
9935 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9940 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9941 * @phba: Pointer to HBA context object.
9942 * @cmdiocb: Pointer to driver command iocb object.
9943 * @rspiocb: Pointer to driver response iocb object.
9945 * The function is called from SLI ring event handler with no
9946 * lock held. This function is the completion handler for ELS commands
9947 * which are aborted. The function frees memory resources used for
9948 * the aborted ELS commands.
9951 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9952 struct lpfc_iocbq
*rspiocb
)
9954 IOCB_t
*irsp
= &rspiocb
->iocb
;
9956 /* ELS cmd tag <ulpIoTag> completes */
9957 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9958 "0139 Ignoring ELS cmd tag x%x completion Data: "
9960 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9961 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9962 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9963 lpfc_ct_free_iocb(phba
, cmdiocb
);
9965 lpfc_els_free_iocb(phba
, cmdiocb
);
9970 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9971 * @phba: Pointer to HBA context object.
9972 * @pring: Pointer to driver SLI ring object.
9973 * @cmdiocb: Pointer to driver command iocb object.
9975 * This function issues an abort iocb for the provided command iocb down to
9976 * the port. Other than the case the outstanding command iocb is an abort
9977 * request, this function issues abort out unconditionally. This function is
9978 * called with hbalock held. The function returns 0 when it fails due to
9979 * memory allocation failure or when the command iocb is an abort request.
9982 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9983 struct lpfc_iocbq
*cmdiocb
)
9985 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9986 struct lpfc_iocbq
*abtsiocbp
;
9987 IOCB_t
*icmd
= NULL
;
9988 IOCB_t
*iabt
= NULL
;
9991 unsigned long iflags
;
9993 lockdep_assert_held(&phba
->hbalock
);
9996 * There are certain command types we don't want to abort. And we
9997 * don't want to abort commands that are already in the process of
10000 icmd
= &cmdiocb
->iocb
;
10001 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10002 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10003 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10006 /* issue ABTS for this IOCB based on iotag */
10007 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10008 if (abtsiocbp
== NULL
)
10011 /* This signals the response to set the correct status
10012 * before calling the completion handler
10014 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10016 iabt
= &abtsiocbp
->iocb
;
10017 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10018 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
10019 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10020 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
10021 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
10024 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
10026 iabt
->ulpClass
= icmd
->ulpClass
;
10028 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10029 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
10030 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
10031 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10032 if (cmdiocb
->iocb_flag
& LPFC_IO_FOF
)
10033 abtsiocbp
->iocb_flag
|= LPFC_IO_FOF
;
10035 if (phba
->link_state
>= LPFC_LINK_UP
)
10036 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
10038 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
10040 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
10041 abtsiocbp
->vport
= vport
;
10043 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
10044 "0339 Abort xri x%x, original iotag x%x, "
10045 "abort cmd iotag x%x\n",
10046 iabt
->un
.acxri
.abortIoTag
,
10047 iabt
->un
.acxri
.abortContextTag
,
10050 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10052 lpfc_sli_calc_ring(phba
, pring
->ringno
, abtsiocbp
);
10053 if (unlikely(ring_number
== LPFC_HBA_ERROR
))
10055 pring
= &phba
->sli
.ring
[ring_number
];
10056 /* Note: both hbalock and ring_lock need to be set here */
10057 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
10058 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10060 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
10062 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10067 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10070 * Caller to this routine should check for IOCB_ERROR
10071 * and handle it properly. This routine no longer removes
10072 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10078 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
10079 * @phba: Pointer to HBA context object.
10080 * @pring: Pointer to driver SLI ring object.
10081 * @cmdiocb: Pointer to driver command iocb object.
10083 * This function issues an abort iocb for the provided command iocb. In case
10084 * of unloading, the abort iocb will not be issued to commands on the ELS
10085 * ring. Instead, the callback function shall be changed to those commands
10086 * so that nothing happens when them finishes. This function is called with
10087 * hbalock held. The function returns 0 when the command iocb is an abort
10091 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10092 struct lpfc_iocbq
*cmdiocb
)
10094 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10095 int retval
= IOCB_ERROR
;
10096 IOCB_t
*icmd
= NULL
;
10098 lockdep_assert_held(&phba
->hbalock
);
10101 * There are certain command types we don't want to abort. And we
10102 * don't want to abort commands that are already in the process of
10105 icmd
= &cmdiocb
->iocb
;
10106 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10107 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10108 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10112 * If we're unloading, don't abort iocb on the ELS ring, but change
10113 * the callback so that nothing happens when it finishes.
10115 if ((vport
->load_flag
& FC_UNLOADING
) &&
10116 (pring
->ringno
== LPFC_ELS_RING
)) {
10117 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10118 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10120 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10121 goto abort_iotag_exit
;
10124 /* Now, we try to issue the abort to the cmdiocb out */
10125 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
10129 * Caller to this routine should check for IOCB_ERROR
10130 * and handle it properly. This routine no longer removes
10131 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10137 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
10138 * @phba: pointer to lpfc HBA data structure.
10140 * This routine will abort all pending and outstanding iocbs to an HBA.
10143 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
10145 struct lpfc_sli
*psli
= &phba
->sli
;
10146 struct lpfc_sli_ring
*pring
;
10149 for (i
= 0; i
< psli
->num_rings
; i
++) {
10150 pring
= &psli
->ring
[i
];
10151 lpfc_sli_abort_iocb_ring(phba
, pring
);
10156 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
10157 * @iocbq: Pointer to driver iocb object.
10158 * @vport: Pointer to driver virtual port object.
10159 * @tgt_id: SCSI ID of the target.
10160 * @lun_id: LUN ID of the scsi device.
10161 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
10163 * This function acts as an iocb filter for functions which abort or count
10164 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
10165 * 0 if the filtering criteria is met for the given iocb and will return
10166 * 1 if the filtering criteria is not met.
10167 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
10168 * given iocb is for the SCSI device specified by vport, tgt_id and
10169 * lun_id parameter.
10170 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
10171 * given iocb is for the SCSI target specified by vport and tgt_id
10173 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
10174 * given iocb is for the SCSI host associated with the given vport.
10175 * This function is called with no locks held.
10178 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
10179 uint16_t tgt_id
, uint64_t lun_id
,
10180 lpfc_ctx_cmd ctx_cmd
)
10182 struct lpfc_scsi_buf
*lpfc_cmd
;
10185 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
10188 if (iocbq
->vport
!= vport
)
10191 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
10193 if (lpfc_cmd
->pCmd
== NULL
)
10198 if ((lpfc_cmd
->rdata
->pnode
) &&
10199 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
10200 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
10204 if ((lpfc_cmd
->rdata
->pnode
) &&
10205 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
10208 case LPFC_CTX_HOST
:
10212 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
10213 __func__
, ctx_cmd
);
10221 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
10222 * @vport: Pointer to virtual port.
10223 * @tgt_id: SCSI ID of the target.
10224 * @lun_id: LUN ID of the scsi device.
10225 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10227 * This function returns number of FCP commands pending for the vport.
10228 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
10229 * commands pending on the vport associated with SCSI device specified
10230 * by tgt_id and lun_id parameters.
10231 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
10232 * commands pending on the vport associated with SCSI target specified
10233 * by tgt_id parameter.
10234 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
10235 * commands pending on the vport.
10236 * This function returns the number of iocbs which satisfy the filter.
10237 * This function is called without any lock held.
10240 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
10241 lpfc_ctx_cmd ctx_cmd
)
10243 struct lpfc_hba
*phba
= vport
->phba
;
10244 struct lpfc_iocbq
*iocbq
;
10247 spin_lock_irq(&phba
->hbalock
);
10248 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
10249 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10251 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
10255 spin_unlock_irq(&phba
->hbalock
);
10261 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
10262 * @phba: Pointer to HBA context object
10263 * @cmdiocb: Pointer to command iocb object.
10264 * @rspiocb: Pointer to response iocb object.
10266 * This function is called when an aborted FCP iocb completes. This
10267 * function is called by the ring event handler with no lock held.
10268 * This function frees the iocb.
10271 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10272 struct lpfc_iocbq
*rspiocb
)
10274 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10275 "3096 ABORT_XRI_CN completing on rpi x%x "
10276 "original iotag x%x, abort cmd iotag x%x "
10277 "status 0x%x, reason 0x%x\n",
10278 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
10279 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
10280 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
10281 rspiocb
->iocb
.un
.ulpWord
[4]);
10282 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10287 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
10288 * @vport: Pointer to virtual port.
10289 * @pring: Pointer to driver SLI ring object.
10290 * @tgt_id: SCSI ID of the target.
10291 * @lun_id: LUN ID of the scsi device.
10292 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10294 * This function sends an abort command for every SCSI command
10295 * associated with the given virtual port pending on the ring
10296 * filtered by lpfc_sli_validate_fcp_iocb function.
10297 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
10298 * FCP iocbs associated with lun specified by tgt_id and lun_id
10300 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
10301 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10302 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
10303 * FCP iocbs associated with virtual port.
10304 * This function returns number of iocbs it failed to abort.
10305 * This function is called with no locks held.
10308 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
10309 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
10311 struct lpfc_hba
*phba
= vport
->phba
;
10312 struct lpfc_iocbq
*iocbq
;
10313 struct lpfc_iocbq
*abtsiocb
;
10314 IOCB_t
*cmd
= NULL
;
10315 int errcnt
= 0, ret_val
= 0;
10318 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
10319 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10321 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
10326 * If the iocbq is already being aborted, don't take a second
10327 * action, but do count it.
10329 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
10332 /* issue ABTS for this IOCB based on iotag */
10333 abtsiocb
= lpfc_sli_get_iocbq(phba
);
10334 if (abtsiocb
== NULL
) {
10339 /* indicate the IO is being aborted by the driver. */
10340 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10342 cmd
= &iocbq
->iocb
;
10343 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10344 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
10345 if (phba
->sli_rev
== LPFC_SLI_REV4
)
10346 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
10348 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
10349 abtsiocb
->iocb
.ulpLe
= 1;
10350 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
10351 abtsiocb
->vport
= vport
;
10353 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10354 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
10355 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
10356 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10357 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
10358 abtsiocb
->iocb_flag
|= LPFC_IO_FOF
;
10360 if (lpfc_is_link_up(phba
))
10361 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
10363 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
10365 /* Setup callback routine and issue the command. */
10366 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
10367 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10369 if (ret_val
== IOCB_ERROR
) {
10370 lpfc_sli_release_iocbq(phba
, abtsiocb
);
10380 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
10381 * @vport: Pointer to virtual port.
10382 * @pring: Pointer to driver SLI ring object.
10383 * @tgt_id: SCSI ID of the target.
10384 * @lun_id: LUN ID of the scsi device.
10385 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10387 * This function sends an abort command for every SCSI command
10388 * associated with the given virtual port pending on the ring
10389 * filtered by lpfc_sli_validate_fcp_iocb function.
10390 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
10391 * FCP iocbs associated with lun specified by tgt_id and lun_id
10393 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
10394 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10395 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
10396 * FCP iocbs associated with virtual port.
10397 * This function returns number of iocbs it aborted .
10398 * This function is called with no locks held right after a taskmgmt
10402 lpfc_sli_abort_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
10403 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd cmd
)
10405 struct lpfc_hba
*phba
= vport
->phba
;
10406 struct lpfc_scsi_buf
*lpfc_cmd
;
10407 struct lpfc_iocbq
*abtsiocbq
;
10408 struct lpfc_nodelist
*ndlp
;
10409 struct lpfc_iocbq
*iocbq
;
10411 int sum
, i
, ret_val
;
10412 unsigned long iflags
;
10413 struct lpfc_sli_ring
*pring_s4
;
10414 uint32_t ring_number
;
10416 spin_lock_irq(&phba
->hbalock
);
10418 /* all I/Os are in process of being flushed */
10419 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
10420 spin_unlock_irq(&phba
->hbalock
);
10425 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
10426 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10428 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
10433 * If the iocbq is already being aborted, don't take a second
10434 * action, but do count it.
10436 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
10439 /* issue ABTS for this IOCB based on iotag */
10440 abtsiocbq
= __lpfc_sli_get_iocbq(phba
);
10441 if (abtsiocbq
== NULL
)
10444 icmd
= &iocbq
->iocb
;
10445 abtsiocbq
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10446 abtsiocbq
->iocb
.un
.acxri
.abortContextTag
= icmd
->ulpContext
;
10447 if (phba
->sli_rev
== LPFC_SLI_REV4
)
10448 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
=
10449 iocbq
->sli4_xritag
;
10451 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
10452 abtsiocbq
->iocb
.ulpLe
= 1;
10453 abtsiocbq
->iocb
.ulpClass
= icmd
->ulpClass
;
10454 abtsiocbq
->vport
= vport
;
10456 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10457 abtsiocbq
->fcp_wqidx
= iocbq
->fcp_wqidx
;
10458 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
10459 abtsiocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10460 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
10461 abtsiocbq
->iocb_flag
|= LPFC_IO_FOF
;
10463 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
10464 ndlp
= lpfc_cmd
->rdata
->pnode
;
10466 if (lpfc_is_link_up(phba
) &&
10467 (ndlp
&& ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
10468 abtsiocbq
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
10470 abtsiocbq
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
10472 /* Setup callback routine and issue the command. */
10473 abtsiocbq
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
10476 * Indicate the IO is being aborted by the driver and set
10477 * the caller's flag into the aborted IO.
10479 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10481 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10482 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+
10484 pring_s4
= &phba
->sli
.ring
[ring_number
];
10485 /* Note: both hbalock and ring_lock must be set here */
10486 spin_lock_irqsave(&pring_s4
->ring_lock
, iflags
);
10487 ret_val
= __lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
10489 spin_unlock_irqrestore(&pring_s4
->ring_lock
, iflags
);
10491 ret_val
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10496 if (ret_val
== IOCB_ERROR
)
10497 __lpfc_sli_release_iocbq(phba
, abtsiocbq
);
10501 spin_unlock_irq(&phba
->hbalock
);
10506 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
10507 * @phba: Pointer to HBA context object.
10508 * @cmdiocbq: Pointer to command iocb.
10509 * @rspiocbq: Pointer to response iocb.
10511 * This function is the completion handler for iocbs issued using
10512 * lpfc_sli_issue_iocb_wait function. This function is called by the
10513 * ring event handler function without any lock held. This function
10514 * can be called from both worker thread context and interrupt
10515 * context. This function also can be called from other thread which
10516 * cleans up the SLI layer objects.
10517 * This function copy the contents of the response iocb to the
10518 * response iocb memory object provided by the caller of
10519 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
10520 * sleeps for the iocb completion.
10523 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
10524 struct lpfc_iocbq
*cmdiocbq
,
10525 struct lpfc_iocbq
*rspiocbq
)
10527 wait_queue_head_t
*pdone_q
;
10528 unsigned long iflags
;
10529 struct lpfc_scsi_buf
*lpfc_cmd
;
10531 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10532 if (cmdiocbq
->iocb_flag
& LPFC_IO_WAKE_TMO
) {
10535 * A time out has occurred for the iocb. If a time out
10536 * completion handler has been supplied, call it. Otherwise,
10537 * just free the iocbq.
10540 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10541 cmdiocbq
->iocb_cmpl
= cmdiocbq
->wait_iocb_cmpl
;
10542 cmdiocbq
->wait_iocb_cmpl
= NULL
;
10543 if (cmdiocbq
->iocb_cmpl
)
10544 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, NULL
);
10546 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
10550 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
10551 if (cmdiocbq
->context2
&& rspiocbq
)
10552 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
10553 &rspiocbq
->iocb
, sizeof(IOCB_t
));
10555 /* Set the exchange busy flag for task management commands */
10556 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
10557 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
10558 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
10560 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
10563 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
10566 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10571 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
10572 * @phba: Pointer to HBA context object..
10573 * @piocbq: Pointer to command iocb.
10574 * @flag: Flag to test.
10576 * This routine grabs the hbalock and then test the iocb_flag to
10577 * see if the passed in flag is set.
10579 * 1 if flag is set.
10580 * 0 if flag is not set.
10583 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
10584 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
10586 unsigned long iflags
;
10589 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10590 ret
= piocbq
->iocb_flag
& flag
;
10591 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10597 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
10598 * @phba: Pointer to HBA context object..
10599 * @pring: Pointer to sli ring.
10600 * @piocb: Pointer to command iocb.
10601 * @prspiocbq: Pointer to response iocb.
10602 * @timeout: Timeout in number of seconds.
10604 * This function issues the iocb to firmware and waits for the
10605 * iocb to complete. The iocb_cmpl field of the shall be used
10606 * to handle iocbs which time out. If the field is NULL, the
10607 * function shall free the iocbq structure. If more clean up is
10608 * needed, the caller is expected to provide a completion function
10609 * that will provide the needed clean up. If the iocb command is
10610 * not completed within timeout seconds, the function will either
10611 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
10612 * completion function set in the iocb_cmpl field and then return
10613 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
10614 * resources if this function returns IOCB_TIMEDOUT.
10615 * The function waits for the iocb completion using an
10616 * non-interruptible wait.
10617 * This function will sleep while waiting for iocb completion.
10618 * So, this function should not be called from any context which
10619 * does not allow sleeping. Due to the same reason, this function
10620 * cannot be called with interrupt disabled.
10621 * This function assumes that the iocb completions occur while
10622 * this function sleep. So, this function cannot be called from
10623 * the thread which process iocb completion for this ring.
10624 * This function clears the iocb_flag of the iocb object before
10625 * issuing the iocb and the iocb completion handler sets this
10626 * flag and wakes this thread when the iocb completes.
10627 * The contents of the response iocb will be copied to prspiocbq
10628 * by the completion handler when the command completes.
10629 * This function returns IOCB_SUCCESS when success.
10630 * This function is called with no lock held.
10633 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
10634 uint32_t ring_number
,
10635 struct lpfc_iocbq
*piocb
,
10636 struct lpfc_iocbq
*prspiocbq
,
10639 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10640 long timeleft
, timeout_req
= 0;
10641 int retval
= IOCB_SUCCESS
;
10643 struct lpfc_iocbq
*iocb
;
10645 int txcmplq_cnt
= 0;
10646 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10647 unsigned long iflags
;
10648 bool iocb_completed
= true;
10651 * If the caller has provided a response iocbq buffer, then context2
10652 * is NULL or its an error.
10655 if (piocb
->context2
)
10657 piocb
->context2
= prspiocbq
;
10660 piocb
->wait_iocb_cmpl
= piocb
->iocb_cmpl
;
10661 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
10662 piocb
->context_un
.wait_queue
= &done_q
;
10663 piocb
->iocb_flag
&= ~(LPFC_IO_WAKE
| LPFC_IO_WAKE_TMO
);
10665 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10666 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10668 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
10669 writel(creg_val
, phba
->HCregaddr
);
10670 readl(phba
->HCregaddr
); /* flush */
10673 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
10674 SLI_IOCB_RET_IOCB
);
10675 if (retval
== IOCB_SUCCESS
) {
10676 timeout_req
= msecs_to_jiffies(timeout
* 1000);
10677 timeleft
= wait_event_timeout(done_q
,
10678 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
10680 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10681 if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
10684 * IOCB timed out. Inform the wake iocb wait
10685 * completion function and set local status
10688 iocb_completed
= false;
10689 piocb
->iocb_flag
|= LPFC_IO_WAKE_TMO
;
10691 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10692 if (iocb_completed
) {
10693 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10694 "0331 IOCB wake signaled\n");
10695 /* Note: we are not indicating if the IOCB has a success
10696 * status or not - that's for the caller to check.
10697 * IOCB_SUCCESS means just that the command was sent and
10698 * completed. Not that it completed successfully.
10700 } else if (timeleft
== 0) {
10701 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10702 "0338 IOCB wait timeout error - no "
10703 "wake response Data x%x\n", timeout
);
10704 retval
= IOCB_TIMEDOUT
;
10706 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10707 "0330 IOCB wake NOT set, "
10709 timeout
, (timeleft
/ jiffies
));
10710 retval
= IOCB_TIMEDOUT
;
10712 } else if (retval
== IOCB_BUSY
) {
10713 if (phba
->cfg_log_verbose
& LOG_SLI
) {
10714 list_for_each_entry(iocb
, &pring
->txq
, list
) {
10717 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
10720 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10721 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
10722 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
10726 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10727 "0332 IOCB wait issue failed, Data x%x\n",
10729 retval
= IOCB_ERROR
;
10732 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10733 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10735 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
10736 writel(creg_val
, phba
->HCregaddr
);
10737 readl(phba
->HCregaddr
); /* flush */
10741 piocb
->context2
= NULL
;
10743 piocb
->context_un
.wait_queue
= NULL
;
10744 piocb
->iocb_cmpl
= NULL
;
10749 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
10750 * @phba: Pointer to HBA context object.
10751 * @pmboxq: Pointer to driver mailbox object.
10752 * @timeout: Timeout in number of seconds.
10754 * This function issues the mailbox to firmware and waits for the
10755 * mailbox command to complete. If the mailbox command is not
10756 * completed within timeout seconds, it returns MBX_TIMEOUT.
10757 * The function waits for the mailbox completion using an
10758 * interruptible wait. If the thread is woken up due to a
10759 * signal, MBX_TIMEOUT error is returned to the caller. Caller
10760 * should not free the mailbox resources, if this function returns
10762 * This function will sleep while waiting for mailbox completion.
10763 * So, this function should not be called from any context which
10764 * does not allow sleeping. Due to the same reason, this function
10765 * cannot be called with interrupt disabled.
10766 * This function assumes that the mailbox completion occurs while
10767 * this function sleep. So, this function cannot be called from
10768 * the worker thread which processes mailbox completion.
10769 * This function is called in the context of HBA management
10771 * This function returns MBX_SUCCESS when successful.
10772 * This function is called with no lock held.
10775 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
10778 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10779 MAILBOX_t
*mb
= NULL
;
10781 unsigned long flag
;
10783 /* The caller might set context1 for extended buffer */
10784 if (pmboxq
->context1
)
10785 mb
= (MAILBOX_t
*)pmboxq
->context1
;
10787 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
10788 /* setup wake call as IOCB callback */
10789 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
10790 /* setup context field to pass wait_queue pointer to wake function */
10791 pmboxq
->context1
= &done_q
;
10793 /* now issue the command */
10794 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
10795 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
10796 wait_event_interruptible_timeout(done_q
,
10797 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
10798 msecs_to_jiffies(timeout
* 1000));
10800 spin_lock_irqsave(&phba
->hbalock
, flag
);
10801 /* restore the possible extended buffer for free resource */
10802 pmboxq
->context1
= (uint8_t *)mb
;
10804 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10805 * else do not free the resources.
10807 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
10808 retval
= MBX_SUCCESS
;
10810 retval
= MBX_TIMEOUT
;
10811 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10813 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
10815 /* restore the possible extended buffer for free resource */
10816 pmboxq
->context1
= (uint8_t *)mb
;
10823 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10824 * @phba: Pointer to HBA context.
10826 * This function is called to shutdown the driver's mailbox sub-system.
10827 * It first marks the mailbox sub-system is in a block state to prevent
10828 * the asynchronous mailbox command from issued off the pending mailbox
10829 * command queue. If the mailbox command sub-system shutdown is due to
10830 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10831 * the mailbox sub-system flush routine to forcefully bring down the
10832 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10833 * as with offline or HBA function reset), this routine will wait for the
10834 * outstanding mailbox command to complete before invoking the mailbox
10835 * sub-system flush routine to gracefully bring down mailbox sub-system.
10838 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
10840 struct lpfc_sli
*psli
= &phba
->sli
;
10841 unsigned long timeout
;
10843 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
10844 /* delay 100ms for port state */
10846 lpfc_sli_mbox_sys_flush(phba
);
10849 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
10851 spin_lock_irq(&phba
->hbalock
);
10852 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10854 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
10855 /* Determine how long we might wait for the active mailbox
10856 * command to be gracefully completed by firmware.
10858 if (phba
->sli
.mbox_active
)
10859 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
10860 phba
->sli
.mbox_active
) *
10862 spin_unlock_irq(&phba
->hbalock
);
10864 while (phba
->sli
.mbox_active
) {
10865 /* Check active mailbox complete status every 2ms */
10867 if (time_after(jiffies
, timeout
))
10868 /* Timeout, let the mailbox flush routine to
10869 * forcefully release active mailbox command
10874 spin_unlock_irq(&phba
->hbalock
);
10876 lpfc_sli_mbox_sys_flush(phba
);
10880 * lpfc_sli_eratt_read - read sli-3 error attention events
10881 * @phba: Pointer to HBA context.
10883 * This function is called to read the SLI3 device error attention registers
10884 * for possible error attention events. The caller must hold the hostlock
10885 * with spin_lock_irq().
10887 * This function returns 1 when there is Error Attention in the Host Attention
10888 * Register and returns 0 otherwise.
10891 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10895 /* Read chip Host Attention (HA) register */
10896 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10899 if (ha_copy
& HA_ERATT
) {
10900 /* Read host status register to retrieve error event */
10901 if (lpfc_sli_read_hs(phba
))
10904 /* Check if there is a deferred error condition is active */
10905 if ((HS_FFER1
& phba
->work_hs
) &&
10906 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10907 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10908 phba
->hba_flag
|= DEFER_ERATT
;
10909 /* Clear all interrupt enable conditions */
10910 writel(0, phba
->HCregaddr
);
10911 readl(phba
->HCregaddr
);
10914 /* Set the driver HA work bitmap */
10915 phba
->work_ha
|= HA_ERATT
;
10916 /* Indicate polling handles this ERATT */
10917 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10923 /* Set the driver HS work bitmap */
10924 phba
->work_hs
|= UNPLUG_ERR
;
10925 /* Set the driver HA work bitmap */
10926 phba
->work_ha
|= HA_ERATT
;
10927 /* Indicate polling handles this ERATT */
10928 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10933 * lpfc_sli4_eratt_read - read sli-4 error attention events
10934 * @phba: Pointer to HBA context.
10936 * This function is called to read the SLI4 device error attention registers
10937 * for possible error attention events. The caller must hold the hostlock
10938 * with spin_lock_irq().
10940 * This function returns 1 when there is Error Attention in the Host Attention
10941 * Register and returns 0 otherwise.
10944 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10946 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10947 uint32_t if_type
, portsmphr
;
10948 struct lpfc_register portstat_reg
;
10951 * For now, use the SLI4 device internal unrecoverable error
10952 * registers for error attention. This can be changed later.
10954 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10956 case LPFC_SLI_INTF_IF_TYPE_0
:
10957 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10959 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10961 phba
->work_hs
|= UNPLUG_ERR
;
10962 phba
->work_ha
|= HA_ERATT
;
10963 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10966 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10967 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10968 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10969 "1423 HBA Unrecoverable error: "
10970 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10971 "ue_mask_lo_reg=0x%x, "
10972 "ue_mask_hi_reg=0x%x\n",
10973 uerr_sta_lo
, uerr_sta_hi
,
10974 phba
->sli4_hba
.ue_mask_lo
,
10975 phba
->sli4_hba
.ue_mask_hi
);
10976 phba
->work_status
[0] = uerr_sta_lo
;
10977 phba
->work_status
[1] = uerr_sta_hi
;
10978 phba
->work_ha
|= HA_ERATT
;
10979 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10983 case LPFC_SLI_INTF_IF_TYPE_2
:
10984 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10985 &portstat_reg
.word0
) ||
10986 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10988 phba
->work_hs
|= UNPLUG_ERR
;
10989 phba
->work_ha
|= HA_ERATT
;
10990 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10993 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10994 phba
->work_status
[0] =
10995 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10996 phba
->work_status
[1] =
10997 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10998 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10999 "2885 Port Status Event: "
11000 "port status reg 0x%x, "
11001 "port smphr reg 0x%x, "
11002 "error 1=0x%x, error 2=0x%x\n",
11003 portstat_reg
.word0
,
11005 phba
->work_status
[0],
11006 phba
->work_status
[1]);
11007 phba
->work_ha
|= HA_ERATT
;
11008 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11012 case LPFC_SLI_INTF_IF_TYPE_1
:
11014 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11015 "2886 HBA Error Attention on unsupported "
11016 "if type %d.", if_type
);
11024 * lpfc_sli_check_eratt - check error attention events
11025 * @phba: Pointer to HBA context.
11027 * This function is called from timer soft interrupt context to check HBA's
11028 * error attention register bit for error attention events.
11030 * This function returns 1 when there is Error Attention in the Host Attention
11031 * Register and returns 0 otherwise.
11034 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
11038 /* If somebody is waiting to handle an eratt, don't process it
11039 * here. The brdkill function will do this.
11041 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11044 /* Check if interrupt handler handles this ERATT */
11045 spin_lock_irq(&phba
->hbalock
);
11046 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
11047 /* Interrupt handler has handled ERATT */
11048 spin_unlock_irq(&phba
->hbalock
);
11053 * If there is deferred error attention, do not check for error
11056 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11057 spin_unlock_irq(&phba
->hbalock
);
11061 /* If PCI channel is offline, don't process it */
11062 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
11063 spin_unlock_irq(&phba
->hbalock
);
11067 switch (phba
->sli_rev
) {
11068 case LPFC_SLI_REV2
:
11069 case LPFC_SLI_REV3
:
11070 /* Read chip Host Attention (HA) register */
11071 ha_copy
= lpfc_sli_eratt_read(phba
);
11073 case LPFC_SLI_REV4
:
11074 /* Read device Uncoverable Error (UERR) registers */
11075 ha_copy
= lpfc_sli4_eratt_read(phba
);
11078 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11079 "0299 Invalid SLI revision (%d)\n",
11084 spin_unlock_irq(&phba
->hbalock
);
11090 * lpfc_intr_state_check - Check device state for interrupt handling
11091 * @phba: Pointer to HBA context.
11093 * This inline routine checks whether a device or its PCI slot is in a state
11094 * that the interrupt should be handled.
11096 * This function returns 0 if the device or the PCI slot is in a state that
11097 * interrupt should be handled, otherwise -EIO.
11100 lpfc_intr_state_check(struct lpfc_hba
*phba
)
11102 /* If the pci channel is offline, ignore all the interrupts */
11103 if (unlikely(pci_channel_offline(phba
->pcidev
)))
11106 /* Update device level interrupt statistics */
11107 phba
->sli
.slistat
.sli_intr
++;
11109 /* Ignore all interrupts during initialization. */
11110 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
11117 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
11118 * @irq: Interrupt number.
11119 * @dev_id: The device context pointer.
11121 * This function is directly called from the PCI layer as an interrupt
11122 * service routine when device with SLI-3 interface spec is enabled with
11123 * MSI-X multi-message interrupt mode and there are slow-path events in
11124 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11125 * interrupt mode, this function is called as part of the device-level
11126 * interrupt handler. When the PCI slot is in error recovery or the HBA
11127 * is undergoing initialization, the interrupt handler will not process
11128 * the interrupt. The link attention and ELS ring attention events are
11129 * handled by the worker thread. The interrupt handler signals the worker
11130 * thread and returns for these events. This function is called without
11131 * any lock held. It gets the hbalock to access and update SLI data
11134 * This function returns IRQ_HANDLED when interrupt is handled else it
11135 * returns IRQ_NONE.
11138 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
11140 struct lpfc_hba
*phba
;
11141 uint32_t ha_copy
, hc_copy
;
11142 uint32_t work_ha_copy
;
11143 unsigned long status
;
11144 unsigned long iflag
;
11147 MAILBOX_t
*mbox
, *pmbox
;
11148 struct lpfc_vport
*vport
;
11149 struct lpfc_nodelist
*ndlp
;
11150 struct lpfc_dmabuf
*mp
;
11155 * Get the driver's phba structure from the dev_id and
11156 * assume the HBA is not interrupting.
11158 phba
= (struct lpfc_hba
*)dev_id
;
11160 if (unlikely(!phba
))
11164 * Stuff needs to be attented to when this function is invoked as an
11165 * individual interrupt handler in MSI-X multi-message interrupt mode
11167 if (phba
->intr_type
== MSIX
) {
11168 /* Check device state for handling interrupt */
11169 if (lpfc_intr_state_check(phba
))
11171 /* Need to read HA REG for slow-path events */
11172 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11173 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11175 /* If somebody is waiting to handle an eratt don't process it
11176 * here. The brdkill function will do this.
11178 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11179 ha_copy
&= ~HA_ERATT
;
11180 /* Check the need for handling ERATT in interrupt handler */
11181 if (ha_copy
& HA_ERATT
) {
11182 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11183 /* ERATT polling has handled ERATT */
11184 ha_copy
&= ~HA_ERATT
;
11186 /* Indicate interrupt handler handles ERATT */
11187 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11191 * If there is deferred error attention, do not check for any
11194 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11195 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11199 /* Clear up only attention source related to slow-path */
11200 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
11203 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
11204 HC_LAINT_ENA
| HC_ERINT_ENA
),
11206 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
11208 writel(hc_copy
, phba
->HCregaddr
);
11209 readl(phba
->HAregaddr
); /* flush */
11210 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11212 ha_copy
= phba
->ha_copy
;
11214 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
11216 if (work_ha_copy
) {
11217 if (work_ha_copy
& HA_LATT
) {
11218 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
11220 * Turn off Link Attention interrupts
11221 * until CLEAR_LA done
11223 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11224 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
11225 if (lpfc_readl(phba
->HCregaddr
, &control
))
11227 control
&= ~HC_LAINT_ENA
;
11228 writel(control
, phba
->HCregaddr
);
11229 readl(phba
->HCregaddr
); /* flush */
11230 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11233 work_ha_copy
&= ~HA_LATT
;
11236 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
11238 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
11239 * the only slow ring.
11241 status
= (work_ha_copy
&
11242 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11243 status
>>= (4*LPFC_ELS_RING
);
11244 if (status
& HA_RXMASK
) {
11245 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11246 if (lpfc_readl(phba
->HCregaddr
, &control
))
11249 lpfc_debugfs_slow_ring_trc(phba
,
11250 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
11252 (uint32_t)phba
->sli
.slistat
.sli_intr
);
11254 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
11255 lpfc_debugfs_slow_ring_trc(phba
,
11256 "ISR Disable ring:"
11257 "pwork:x%x hawork:x%x wait:x%x",
11258 phba
->work_ha
, work_ha_copy
,
11259 (uint32_t)((unsigned long)
11260 &phba
->work_waitq
));
11263 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
11264 writel(control
, phba
->HCregaddr
);
11265 readl(phba
->HCregaddr
); /* flush */
11268 lpfc_debugfs_slow_ring_trc(phba
,
11269 "ISR slow ring: pwork:"
11270 "x%x hawork:x%x wait:x%x",
11271 phba
->work_ha
, work_ha_copy
,
11272 (uint32_t)((unsigned long)
11273 &phba
->work_waitq
));
11275 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11278 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11279 if (work_ha_copy
& HA_ERATT
) {
11280 if (lpfc_sli_read_hs(phba
))
11283 * Check if there is a deferred error condition
11286 if ((HS_FFER1
& phba
->work_hs
) &&
11287 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11288 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
11290 phba
->hba_flag
|= DEFER_ERATT
;
11291 /* Clear all interrupt enable conditions */
11292 writel(0, phba
->HCregaddr
);
11293 readl(phba
->HCregaddr
);
11297 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
11298 pmb
= phba
->sli
.mbox_active
;
11299 pmbox
= &pmb
->u
.mb
;
11301 vport
= pmb
->vport
;
11303 /* First check out the status word */
11304 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
11305 if (pmbox
->mbxOwner
!= OWN_HOST
) {
11306 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11308 * Stray Mailbox Interrupt, mbxCommand <cmd>
11309 * mbxStatus <status>
11311 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11313 "(%d):0304 Stray Mailbox "
11314 "Interrupt mbxCommand x%x "
11316 (vport
? vport
->vpi
: 0),
11319 /* clear mailbox attention bit */
11320 work_ha_copy
&= ~HA_MBATT
;
11322 phba
->sli
.mbox_active
= NULL
;
11323 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11324 phba
->last_completion_time
= jiffies
;
11325 del_timer(&phba
->sli
.mbox_tmo
);
11326 if (pmb
->mbox_cmpl
) {
11327 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
11329 if (pmb
->out_ext_byte_len
&&
11331 lpfc_sli_pcimem_bcopy(
11334 pmb
->out_ext_byte_len
);
11336 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11337 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11339 lpfc_debugfs_disc_trc(vport
,
11340 LPFC_DISC_TRC_MBOX_VPORT
,
11341 "MBOX dflt rpi: : "
11342 "status:x%x rpi:x%x",
11343 (uint32_t)pmbox
->mbxStatus
,
11344 pmbox
->un
.varWords
[0], 0);
11346 if (!pmbox
->mbxStatus
) {
11347 mp
= (struct lpfc_dmabuf
*)
11349 ndlp
= (struct lpfc_nodelist
*)
11352 /* Reg_LOGIN of dflt RPI was
11353 * successful. new lets get
11354 * rid of the RPI using the
11355 * same mbox buffer.
11357 lpfc_unreg_login(phba
,
11359 pmbox
->un
.varWords
[0],
11362 lpfc_mbx_cmpl_dflt_rpi
;
11363 pmb
->context1
= mp
;
11364 pmb
->context2
= ndlp
;
11365 pmb
->vport
= vport
;
11366 rc
= lpfc_sli_issue_mbox(phba
,
11369 if (rc
!= MBX_BUSY
)
11370 lpfc_printf_log(phba
,
11372 LOG_MBOX
| LOG_SLI
,
11373 "0350 rc should have"
11374 "been MBX_BUSY\n");
11375 if (rc
!= MBX_NOT_FINISHED
)
11376 goto send_current_mbox
;
11380 &phba
->pport
->work_port_lock
,
11382 phba
->pport
->work_port_events
&=
11384 spin_unlock_irqrestore(
11385 &phba
->pport
->work_port_lock
,
11387 lpfc_mbox_cmpl_put(phba
, pmb
);
11390 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11392 if ((work_ha_copy
& HA_MBATT
) &&
11393 (phba
->sli
.mbox_active
== NULL
)) {
11395 /* Process next mailbox command if there is one */
11397 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
11399 } while (rc
== MBX_NOT_FINISHED
);
11400 if (rc
!= MBX_SUCCESS
)
11401 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11402 LOG_SLI
, "0349 rc should be "
11406 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11407 phba
->work_ha
|= work_ha_copy
;
11408 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11409 lpfc_worker_wake_up(phba
);
11411 return IRQ_HANDLED
;
11413 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11414 return IRQ_HANDLED
;
11416 } /* lpfc_sli_sp_intr_handler */
11419 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
11420 * @irq: Interrupt number.
11421 * @dev_id: The device context pointer.
11423 * This function is directly called from the PCI layer as an interrupt
11424 * service routine when device with SLI-3 interface spec is enabled with
11425 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11426 * ring event in the HBA. However, when the device is enabled with either
11427 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11428 * device-level interrupt handler. When the PCI slot is in error recovery
11429 * or the HBA is undergoing initialization, the interrupt handler will not
11430 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11431 * the intrrupt context. This function is called without any lock held.
11432 * It gets the hbalock to access and update SLI data structures.
11434 * This function returns IRQ_HANDLED when interrupt is handled else it
11435 * returns IRQ_NONE.
11438 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
11440 struct lpfc_hba
*phba
;
11442 unsigned long status
;
11443 unsigned long iflag
;
11445 /* Get the driver's phba structure from the dev_id and
11446 * assume the HBA is not interrupting.
11448 phba
= (struct lpfc_hba
*) dev_id
;
11450 if (unlikely(!phba
))
11454 * Stuff needs to be attented to when this function is invoked as an
11455 * individual interrupt handler in MSI-X multi-message interrupt mode
11457 if (phba
->intr_type
== MSIX
) {
11458 /* Check device state for handling interrupt */
11459 if (lpfc_intr_state_check(phba
))
11461 /* Need to read HA REG for FCP ring and other ring events */
11462 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11463 return IRQ_HANDLED
;
11464 /* Clear up only attention source related to fast-path */
11465 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11467 * If there is deferred error attention, do not check for
11470 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11471 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11474 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
11476 readl(phba
->HAregaddr
); /* flush */
11477 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11479 ha_copy
= phba
->ha_copy
;
11482 * Process all events on FCP ring. Take the optimized path for FCP IO.
11484 ha_copy
&= ~(phba
->work_ha_mask
);
11486 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
11487 status
>>= (4*LPFC_FCP_RING
);
11488 if (status
& HA_RXMASK
)
11489 lpfc_sli_handle_fast_ring_event(phba
,
11490 &phba
->sli
.ring
[LPFC_FCP_RING
],
11493 if (phba
->cfg_multi_ring_support
== 2) {
11495 * Process all events on extra ring. Take the optimized path
11496 * for extra ring IO.
11498 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
11499 status
>>= (4*LPFC_EXTRA_RING
);
11500 if (status
& HA_RXMASK
) {
11501 lpfc_sli_handle_fast_ring_event(phba
,
11502 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
11506 return IRQ_HANDLED
;
11507 } /* lpfc_sli_fp_intr_handler */
11510 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
11511 * @irq: Interrupt number.
11512 * @dev_id: The device context pointer.
11514 * This function is the HBA device-level interrupt handler to device with
11515 * SLI-3 interface spec, called from the PCI layer when either MSI or
11516 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
11517 * requires driver attention. This function invokes the slow-path interrupt
11518 * attention handling function and fast-path interrupt attention handling
11519 * function in turn to process the relevant HBA attention events. This
11520 * function is called without any lock held. It gets the hbalock to access
11521 * and update SLI data structures.
11523 * This function returns IRQ_HANDLED when interrupt is handled, else it
11524 * returns IRQ_NONE.
11527 lpfc_sli_intr_handler(int irq
, void *dev_id
)
11529 struct lpfc_hba
*phba
;
11530 irqreturn_t sp_irq_rc
, fp_irq_rc
;
11531 unsigned long status1
, status2
;
11535 * Get the driver's phba structure from the dev_id and
11536 * assume the HBA is not interrupting.
11538 phba
= (struct lpfc_hba
*) dev_id
;
11540 if (unlikely(!phba
))
11543 /* Check device state for handling interrupt */
11544 if (lpfc_intr_state_check(phba
))
11547 spin_lock(&phba
->hbalock
);
11548 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
11549 spin_unlock(&phba
->hbalock
);
11550 return IRQ_HANDLED
;
11553 if (unlikely(!phba
->ha_copy
)) {
11554 spin_unlock(&phba
->hbalock
);
11556 } else if (phba
->ha_copy
& HA_ERATT
) {
11557 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11558 /* ERATT polling has handled ERATT */
11559 phba
->ha_copy
&= ~HA_ERATT
;
11561 /* Indicate interrupt handler handles ERATT */
11562 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11566 * If there is deferred error attention, do not check for any interrupt.
11568 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11569 spin_unlock(&phba
->hbalock
);
11573 /* Clear attention sources except link and error attentions */
11574 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
11575 spin_unlock(&phba
->hbalock
);
11576 return IRQ_HANDLED
;
11578 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
11579 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
11581 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
11582 writel(hc_copy
, phba
->HCregaddr
);
11583 readl(phba
->HAregaddr
); /* flush */
11584 spin_unlock(&phba
->hbalock
);
11587 * Invokes slow-path host attention interrupt handling as appropriate.
11590 /* status of events with mailbox and link attention */
11591 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
11593 /* status of events with ELS ring */
11594 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11595 status2
>>= (4*LPFC_ELS_RING
);
11597 if (status1
|| (status2
& HA_RXMASK
))
11598 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
11600 sp_irq_rc
= IRQ_NONE
;
11603 * Invoke fast-path host attention interrupt handling as appropriate.
11606 /* status of events with FCP ring */
11607 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
11608 status1
>>= (4*LPFC_FCP_RING
);
11610 /* status of events with extra ring */
11611 if (phba
->cfg_multi_ring_support
== 2) {
11612 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
11613 status2
>>= (4*LPFC_EXTRA_RING
);
11617 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
11618 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
11620 fp_irq_rc
= IRQ_NONE
;
11622 /* Return device-level interrupt handling status */
11623 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
11624 } /* lpfc_sli_intr_handler */
11627 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
11628 * @phba: pointer to lpfc hba data structure.
11630 * This routine is invoked by the worker thread to process all the pending
11631 * SLI4 FCP abort XRI events.
11633 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
11635 struct lpfc_cq_event
*cq_event
;
11637 /* First, declare the fcp xri abort event has been handled */
11638 spin_lock_irq(&phba
->hbalock
);
11639 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
11640 spin_unlock_irq(&phba
->hbalock
);
11641 /* Now, handle all the fcp xri abort events */
11642 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
11643 /* Get the first event from the head of the event queue */
11644 spin_lock_irq(&phba
->hbalock
);
11645 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
11646 cq_event
, struct lpfc_cq_event
, list
);
11647 spin_unlock_irq(&phba
->hbalock
);
11648 /* Notify aborted XRI for FCP work queue */
11649 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
11650 /* Free the event processed back to the free pool */
11651 lpfc_sli4_cq_event_release(phba
, cq_event
);
11656 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
11657 * @phba: pointer to lpfc hba data structure.
11659 * This routine is invoked by the worker thread to process all the pending
11660 * SLI4 els abort xri events.
11662 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
11664 struct lpfc_cq_event
*cq_event
;
11666 /* First, declare the els xri abort event has been handled */
11667 spin_lock_irq(&phba
->hbalock
);
11668 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
11669 spin_unlock_irq(&phba
->hbalock
);
11670 /* Now, handle all the els xri abort events */
11671 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
11672 /* Get the first event from the head of the event queue */
11673 spin_lock_irq(&phba
->hbalock
);
11674 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
11675 cq_event
, struct lpfc_cq_event
, list
);
11676 spin_unlock_irq(&phba
->hbalock
);
11677 /* Notify aborted XRI for ELS work queue */
11678 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
11679 /* Free the event processed back to the free pool */
11680 lpfc_sli4_cq_event_release(phba
, cq_event
);
11685 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
11686 * @phba: pointer to lpfc hba data structure
11687 * @pIocbIn: pointer to the rspiocbq
11688 * @pIocbOut: pointer to the cmdiocbq
11689 * @wcqe: pointer to the complete wcqe
11691 * This routine transfers the fields of a command iocbq to a response iocbq
11692 * by copying all the IOCB fields from command iocbq and transferring the
11693 * completion status information from the complete wcqe.
11696 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
11697 struct lpfc_iocbq
*pIocbIn
,
11698 struct lpfc_iocbq
*pIocbOut
,
11699 struct lpfc_wcqe_complete
*wcqe
)
11702 unsigned long iflags
;
11703 uint32_t status
, max_response
;
11704 struct lpfc_dmabuf
*dmabuf
;
11705 struct ulp_bde64
*bpl
, bde
;
11706 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
11708 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
11709 sizeof(struct lpfc_iocbq
) - offset
);
11710 /* Map WCQE parameters into irspiocb parameters */
11711 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
11712 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
11713 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
11714 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
11715 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
11716 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
11717 wcqe
->total_data_placed
;
11719 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11721 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11722 switch (pIocbOut
->iocb
.ulpCommand
) {
11723 case CMD_ELS_REQUEST64_CR
:
11724 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
11725 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
11726 bde
.tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
11727 max_response
= bde
.tus
.f
.bdeSize
;
11729 case CMD_GEN_REQUEST64_CR
:
11731 if (!pIocbOut
->context3
)
11733 numBdes
= pIocbOut
->iocb
.un
.genreq64
.bdl
.bdeSize
/
11734 sizeof(struct ulp_bde64
);
11735 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
11736 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
11737 for (i
= 0; i
< numBdes
; i
++) {
11738 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
11739 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
11740 max_response
+= bde
.tus
.f
.bdeSize
;
11744 max_response
= wcqe
->total_data_placed
;
11747 if (max_response
< wcqe
->total_data_placed
)
11748 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= max_response
;
11750 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
=
11751 wcqe
->total_data_placed
;
11754 /* Convert BG errors for completion status */
11755 if (status
== CQE_STATUS_DI_ERROR
) {
11756 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
11758 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
11759 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
11761 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
11763 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
11764 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
11765 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11766 BGS_GUARD_ERR_MASK
;
11767 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
11768 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11769 BGS_APPTAG_ERR_MASK
;
11770 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
11771 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11772 BGS_REFTAG_ERR_MASK
;
11774 /* Check to see if there was any good data before the error */
11775 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
11776 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11777 BGS_HI_WATER_MARK_PRESENT_MASK
;
11778 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
11779 wcqe
->total_data_placed
;
11783 * Set ALL the error bits to indicate we don't know what
11784 * type of error it is.
11786 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
11787 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11788 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
11789 BGS_GUARD_ERR_MASK
);
11792 /* Pick up HBA exchange busy condition */
11793 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
11794 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11795 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
11796 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11801 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11802 * @phba: Pointer to HBA context object.
11803 * @wcqe: Pointer to work-queue completion queue entry.
11805 * This routine handles an ELS work-queue completion event and construct
11806 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11807 * discovery engine to handle.
11809 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11811 static struct lpfc_iocbq
*
11812 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
11813 struct lpfc_iocbq
*irspiocbq
)
11815 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
11816 struct lpfc_iocbq
*cmdiocbq
;
11817 struct lpfc_wcqe_complete
*wcqe
;
11818 unsigned long iflags
;
11820 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
11821 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11822 pring
->stats
.iocb_event
++;
11823 /* Look up the ELS command IOCB and create pseudo response IOCB */
11824 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11825 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11826 /* Put the iocb back on the txcmplq */
11827 lpfc_sli_ringtxcmpl_put(phba
, pring
, cmdiocbq
);
11828 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11830 if (unlikely(!cmdiocbq
)) {
11831 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11832 "0386 ELS complete with no corresponding "
11833 "cmdiocb: iotag (%d)\n",
11834 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11835 lpfc_sli_release_iocbq(phba
, irspiocbq
);
11839 /* Fake the irspiocbq and copy necessary response information */
11840 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
11846 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11847 * @phba: Pointer to HBA context object.
11848 * @cqe: Pointer to mailbox completion queue entry.
11850 * This routine process a mailbox completion queue entry with asynchrous
11853 * Return: true if work posted to worker thread, otherwise false.
11856 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11858 struct lpfc_cq_event
*cq_event
;
11859 unsigned long iflags
;
11861 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11862 "0392 Async Event: word0:x%x, word1:x%x, "
11863 "word2:x%x, word3:x%x\n", mcqe
->word0
,
11864 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
11866 /* Allocate a new internal CQ_EVENT entry */
11867 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11869 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11870 "0394 Failed to allocate CQ_EVENT entry\n");
11874 /* Move the CQE into an asynchronous event entry */
11875 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
11876 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11877 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
11878 /* Set the async event flag */
11879 phba
->hba_flag
|= ASYNC_EVENT
;
11880 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11886 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11887 * @phba: Pointer to HBA context object.
11888 * @cqe: Pointer to mailbox completion queue entry.
11890 * This routine process a mailbox completion queue entry with mailbox
11891 * completion event.
11893 * Return: true if work posted to worker thread, otherwise false.
11896 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11898 uint32_t mcqe_status
;
11899 MAILBOX_t
*mbox
, *pmbox
;
11900 struct lpfc_mqe
*mqe
;
11901 struct lpfc_vport
*vport
;
11902 struct lpfc_nodelist
*ndlp
;
11903 struct lpfc_dmabuf
*mp
;
11904 unsigned long iflags
;
11906 bool workposted
= false;
11909 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11910 if (!bf_get(lpfc_trailer_completed
, mcqe
))
11911 goto out_no_mqe_complete
;
11913 /* Get the reference to the active mbox command */
11914 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11915 pmb
= phba
->sli
.mbox_active
;
11916 if (unlikely(!pmb
)) {
11917 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11918 "1832 No pending MBOX command to handle\n");
11919 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11920 goto out_no_mqe_complete
;
11922 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11924 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11926 vport
= pmb
->vport
;
11928 /* Reset heartbeat timer */
11929 phba
->last_completion_time
= jiffies
;
11930 del_timer(&phba
->sli
.mbox_tmo
);
11932 /* Move mbox data to caller's mailbox region, do endian swapping */
11933 if (pmb
->mbox_cmpl
&& mbox
)
11934 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11937 * For mcqe errors, conditionally move a modified error code to
11938 * the mbox so that the error will not be missed.
11940 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11941 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11942 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11943 bf_set(lpfc_mqe_status
, mqe
,
11944 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11946 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11947 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11948 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11949 "MBOX dflt rpi: status:x%x rpi:x%x",
11951 pmbox
->un
.varWords
[0], 0);
11952 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11953 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11954 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11955 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11956 * RID of the PPI using the same mbox buffer.
11958 lpfc_unreg_login(phba
, vport
->vpi
,
11959 pmbox
->un
.varWords
[0], pmb
);
11960 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11961 pmb
->context1
= mp
;
11962 pmb
->context2
= ndlp
;
11963 pmb
->vport
= vport
;
11964 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11965 if (rc
!= MBX_BUSY
)
11966 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11967 LOG_SLI
, "0385 rc should "
11968 "have been MBX_BUSY\n");
11969 if (rc
!= MBX_NOT_FINISHED
)
11970 goto send_current_mbox
;
11973 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11974 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11975 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11977 /* There is mailbox completion work to do */
11978 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11979 __lpfc_mbox_cmpl_put(phba
, pmb
);
11980 phba
->work_ha
|= HA_MBATT
;
11981 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11985 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11986 /* Release the mailbox command posting token */
11987 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11988 /* Setting active mailbox pointer need to be in sync to flag clear */
11989 phba
->sli
.mbox_active
= NULL
;
11990 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11991 /* Wake up worker thread to post the next pending mailbox command */
11992 lpfc_worker_wake_up(phba
);
11993 out_no_mqe_complete
:
11994 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11995 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
12000 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
12001 * @phba: Pointer to HBA context object.
12002 * @cqe: Pointer to mailbox completion queue entry.
12004 * This routine process a mailbox completion queue entry, it invokes the
12005 * proper mailbox complete handling or asynchrous event handling routine
12006 * according to the MCQE's async bit.
12008 * Return: true if work posted to worker thread, otherwise false.
12011 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
12013 struct lpfc_mcqe mcqe
;
12016 /* Copy the mailbox MCQE and convert endian order as needed */
12017 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
12019 /* Invoke the proper event handling routine */
12020 if (!bf_get(lpfc_trailer_async
, &mcqe
))
12021 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
12023 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
12028 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
12029 * @phba: Pointer to HBA context object.
12030 * @cq: Pointer to associated CQ
12031 * @wcqe: Pointer to work-queue completion queue entry.
12033 * This routine handles an ELS work-queue completion event.
12035 * Return: true if work posted to worker thread, otherwise false.
12038 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12039 struct lpfc_wcqe_complete
*wcqe
)
12041 struct lpfc_iocbq
*irspiocbq
;
12042 unsigned long iflags
;
12043 struct lpfc_sli_ring
*pring
= cq
->pring
;
12045 int txcmplq_cnt
= 0;
12046 int fcp_txcmplq_cnt
= 0;
12048 /* Get an irspiocbq for later ELS response processing use */
12049 irspiocbq
= lpfc_sli_get_iocbq(phba
);
12051 if (!list_empty(&pring
->txq
))
12053 if (!list_empty(&pring
->txcmplq
))
12055 if (!list_empty(&phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq
))
12057 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12058 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
12059 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
12060 txq_cnt
, phba
->iocb_cnt
,
12066 /* Save off the slow-path queue event for work thread to process */
12067 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
12068 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12069 list_add_tail(&irspiocbq
->cq_event
.list
,
12070 &phba
->sli4_hba
.sp_queue_event
);
12071 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12072 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12078 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
12079 * @phba: Pointer to HBA context object.
12080 * @wcqe: Pointer to work-queue completion queue entry.
12082 * This routine handles slow-path WQ entry comsumed event by invoking the
12083 * proper WQ release routine to the slow-path WQ.
12086 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
12087 struct lpfc_wcqe_release
*wcqe
)
12089 /* sanity check on queue memory */
12090 if (unlikely(!phba
->sli4_hba
.els_wq
))
12092 /* Check for the slow-path ELS work queue */
12093 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
12094 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
12095 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
12097 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12098 "2579 Slow-path wqe consume event carries "
12099 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
12100 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
12101 phba
->sli4_hba
.els_wq
->queue_id
);
12105 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
12106 * @phba: Pointer to HBA context object.
12107 * @cq: Pointer to a WQ completion queue.
12108 * @wcqe: Pointer to work-queue completion queue entry.
12110 * This routine handles an XRI abort event.
12112 * Return: true if work posted to worker thread, otherwise false.
12115 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
12116 struct lpfc_queue
*cq
,
12117 struct sli4_wcqe_xri_aborted
*wcqe
)
12119 bool workposted
= false;
12120 struct lpfc_cq_event
*cq_event
;
12121 unsigned long iflags
;
12123 /* Allocate a new internal CQ_EVENT entry */
12124 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
12126 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12127 "0602 Failed to allocate CQ_EVENT entry\n");
12131 /* Move the CQE into the proper xri abort event list */
12132 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
12133 switch (cq
->subtype
) {
12135 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12136 list_add_tail(&cq_event
->list
,
12137 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
12138 /* Set the fcp xri abort event flag */
12139 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
12140 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12144 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12145 list_add_tail(&cq_event
->list
,
12146 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
12147 /* Set the els xri abort event flag */
12148 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
12149 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12153 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12154 "0603 Invalid work queue CQE subtype (x%x)\n",
12156 workposted
= false;
12163 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
12164 * @phba: Pointer to HBA context object.
12165 * @rcqe: Pointer to receive-queue completion queue entry.
12167 * This routine process a receive-queue completion queue entry.
12169 * Return: true if work posted to worker thread, otherwise false.
12172 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
12174 bool workposted
= false;
12175 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
12176 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
12177 struct hbq_dmabuf
*dma_buf
;
12178 uint32_t status
, rq_id
;
12179 unsigned long iflags
;
12181 /* sanity check on queue memory */
12182 if (unlikely(!hrq
) || unlikely(!drq
))
12185 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
12186 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
12188 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
12189 if (rq_id
!= hrq
->queue_id
)
12192 status
= bf_get(lpfc_rcqe_status
, rcqe
);
12194 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
12195 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12196 "2537 Receive Frame Truncated!!\n");
12197 hrq
->RQ_buf_trunc
++;
12198 case FC_STATUS_RQ_SUCCESS
:
12199 lpfc_sli4_rq_release(hrq
, drq
);
12200 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12201 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
12203 hrq
->RQ_no_buf_found
++;
12204 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12208 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
12209 /* save off the frame for the word thread to process */
12210 list_add_tail(&dma_buf
->cq_event
.list
,
12211 &phba
->sli4_hba
.sp_queue_event
);
12212 /* Frame received */
12213 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12214 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12217 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
12218 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
12219 hrq
->RQ_no_posted_buf
++;
12220 /* Post more buffers if possible */
12221 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12222 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
12223 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12232 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
12233 * @phba: Pointer to HBA context object.
12234 * @cq: Pointer to the completion queue.
12235 * @wcqe: Pointer to a completion queue entry.
12237 * This routine process a slow-path work-queue or receive queue completion queue
12240 * Return: true if work posted to worker thread, otherwise false.
12243 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12244 struct lpfc_cqe
*cqe
)
12246 struct lpfc_cqe cqevt
;
12247 bool workposted
= false;
12249 /* Copy the work queue CQE and convert endian order if needed */
12250 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
12252 /* Check and process for different type of WCQE and dispatch */
12253 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
12254 case CQE_CODE_COMPL_WQE
:
12255 /* Process the WQ/RQ complete event */
12256 phba
->last_completion_time
= jiffies
;
12257 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
12258 (struct lpfc_wcqe_complete
*)&cqevt
);
12260 case CQE_CODE_RELEASE_WQE
:
12261 /* Process the WQ release event */
12262 lpfc_sli4_sp_handle_rel_wcqe(phba
,
12263 (struct lpfc_wcqe_release
*)&cqevt
);
12265 case CQE_CODE_XRI_ABORTED
:
12266 /* Process the WQ XRI abort event */
12267 phba
->last_completion_time
= jiffies
;
12268 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
12269 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
12271 case CQE_CODE_RECEIVE
:
12272 case CQE_CODE_RECEIVE_V1
:
12273 /* Process the RQ event */
12274 phba
->last_completion_time
= jiffies
;
12275 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
12276 (struct lpfc_rcqe
*)&cqevt
);
12279 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12280 "0388 Not a valid WCQE code: x%x\n",
12281 bf_get(lpfc_cqe_code
, &cqevt
));
12288 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
12289 * @phba: Pointer to HBA context object.
12290 * @eqe: Pointer to fast-path event queue entry.
12292 * This routine process a event queue entry from the slow-path event queue.
12293 * It will check the MajorCode and MinorCode to determine this is for a
12294 * completion event on a completion queue, if not, an error shall be logged
12295 * and just return. Otherwise, it will get to the corresponding completion
12296 * queue and process all the entries on that completion queue, rearm the
12297 * completion queue, and then return.
12301 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
12302 struct lpfc_queue
*speq
)
12304 struct lpfc_queue
*cq
= NULL
, *childq
;
12305 struct lpfc_cqe
*cqe
;
12306 bool workposted
= false;
12310 /* Get the reference to the corresponding CQ */
12311 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12313 list_for_each_entry(childq
, &speq
->child_list
, list
) {
12314 if (childq
->queue_id
== cqid
) {
12319 if (unlikely(!cq
)) {
12320 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12321 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12322 "0365 Slow-path CQ identifier "
12323 "(%d) does not exist\n", cqid
);
12327 /* Process all the entries to the CQ */
12328 switch (cq
->type
) {
12330 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12331 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
12332 if (!(++ecount
% cq
->entry_repost
))
12333 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12338 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12339 if (cq
->subtype
== LPFC_FCP
)
12340 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
12343 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
12345 if (!(++ecount
% cq
->entry_repost
))
12346 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12349 /* Track the max number of CQEs processed in 1 EQ */
12350 if (ecount
> cq
->CQ_max_cqe
)
12351 cq
->CQ_max_cqe
= ecount
;
12354 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12355 "0370 Invalid completion queue type (%d)\n",
12360 /* Catch the no cq entry condition, log an error */
12361 if (unlikely(ecount
== 0))
12362 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12363 "0371 No entry from the CQ: identifier "
12364 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
12366 /* In any case, flash and re-arm the RCQ */
12367 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12369 /* wake up worker thread if there are works to be done */
12371 lpfc_worker_wake_up(phba
);
12375 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
12376 * @phba: Pointer to HBA context object.
12377 * @cq: Pointer to associated CQ
12378 * @wcqe: Pointer to work-queue completion queue entry.
12380 * This routine process a fast-path work queue completion entry from fast-path
12381 * event queue for FCP command response completion.
12384 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12385 struct lpfc_wcqe_complete
*wcqe
)
12387 struct lpfc_sli_ring
*pring
= cq
->pring
;
12388 struct lpfc_iocbq
*cmdiocbq
;
12389 struct lpfc_iocbq irspiocbq
;
12390 unsigned long iflags
;
12392 /* Check for response status */
12393 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
12394 /* If resource errors reported from HBA, reduce queue
12395 * depth of the SCSI device.
12397 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
12398 IOSTAT_LOCAL_REJECT
)) &&
12399 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
12400 IOERR_NO_RESOURCES
))
12401 phba
->lpfc_rampdown_queue_depth(phba
);
12403 /* Log the error status */
12404 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12405 "0373 FCP complete error: status=x%x, "
12406 "hw_status=x%x, total_data_specified=%d, "
12407 "parameter=x%x, word3=x%x\n",
12408 bf_get(lpfc_wcqe_c_status
, wcqe
),
12409 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
12410 wcqe
->total_data_placed
, wcqe
->parameter
,
12414 /* Look up the FCP command IOCB and create pseudo response IOCB */
12415 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
12416 pring
->stats
.iocb_event
++;
12417 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
12418 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12419 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12420 if (unlikely(!cmdiocbq
)) {
12421 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12422 "0374 FCP complete with no corresponding "
12423 "cmdiocb: iotag (%d)\n",
12424 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12427 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
12428 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12429 "0375 FCP cmdiocb not callback function "
12431 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12435 /* Fake the irspiocb and copy necessary response information */
12436 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
12438 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
12439 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12440 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
12441 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12444 /* Pass the cmd_iocb and the rsp state to the upper layer */
12445 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
12449 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
12450 * @phba: Pointer to HBA context object.
12451 * @cq: Pointer to completion queue.
12452 * @wcqe: Pointer to work-queue completion queue entry.
12454 * This routine handles an fast-path WQ entry comsumed event by invoking the
12455 * proper WQ release routine to the slow-path WQ.
12458 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12459 struct lpfc_wcqe_release
*wcqe
)
12461 struct lpfc_queue
*childwq
;
12462 bool wqid_matched
= false;
12465 /* Check for fast-path FCP work queue release */
12466 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
12467 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
12468 if (childwq
->queue_id
== fcp_wqid
) {
12469 lpfc_sli4_wq_release(childwq
,
12470 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
12471 wqid_matched
= true;
12475 /* Report warning log message if no match found */
12476 if (wqid_matched
!= true)
12477 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12478 "2580 Fast-path wqe consume event carries "
12479 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
12483 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
12484 * @cq: Pointer to the completion queue.
12485 * @eqe: Pointer to fast-path completion queue entry.
12487 * This routine process a fast-path work queue completion entry from fast-path
12488 * event queue for FCP command response completion.
12491 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12492 struct lpfc_cqe
*cqe
)
12494 struct lpfc_wcqe_release wcqe
;
12495 bool workposted
= false;
12497 /* Copy the work queue CQE and convert endian order if needed */
12498 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
12500 /* Check and process for different type of WCQE and dispatch */
12501 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
12502 case CQE_CODE_COMPL_WQE
:
12504 /* Process the WQ complete event */
12505 phba
->last_completion_time
= jiffies
;
12506 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
12507 (struct lpfc_wcqe_complete
*)&wcqe
);
12509 case CQE_CODE_RELEASE_WQE
:
12510 cq
->CQ_release_wqe
++;
12511 /* Process the WQ release event */
12512 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
12513 (struct lpfc_wcqe_release
*)&wcqe
);
12515 case CQE_CODE_XRI_ABORTED
:
12516 cq
->CQ_xri_aborted
++;
12517 /* Process the WQ XRI abort event */
12518 phba
->last_completion_time
= jiffies
;
12519 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
12520 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
12523 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12524 "0144 Not a valid WCQE code: x%x\n",
12525 bf_get(lpfc_wcqe_c_code
, &wcqe
));
12532 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
12533 * @phba: Pointer to HBA context object.
12534 * @eqe: Pointer to fast-path event queue entry.
12536 * This routine process a event queue entry from the fast-path event queue.
12537 * It will check the MajorCode and MinorCode to determine this is for a
12538 * completion event on a completion queue, if not, an error shall be logged
12539 * and just return. Otherwise, it will get to the corresponding completion
12540 * queue and process all the entries on the completion queue, rearm the
12541 * completion queue, and then return.
12544 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
12547 struct lpfc_queue
*cq
;
12548 struct lpfc_cqe
*cqe
;
12549 bool workposted
= false;
12553 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
12554 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12555 "0366 Not a valid completion "
12556 "event: majorcode=x%x, minorcode=x%x\n",
12557 bf_get_le32(lpfc_eqe_major_code
, eqe
),
12558 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
12562 /* Get the reference to the corresponding CQ */
12563 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12565 /* Check if this is a Slow path event */
12566 if (unlikely(cqid
!= phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
12567 lpfc_sli4_sp_handle_eqe(phba
, eqe
,
12568 phba
->sli4_hba
.hba_eq
[qidx
]);
12572 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
12573 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12574 "3146 Fast-path completion queues "
12575 "does not exist\n");
12578 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
12579 if (unlikely(!cq
)) {
12580 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12581 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12582 "0367 Fast-path completion queue "
12583 "(%d) does not exist\n", qidx
);
12587 if (unlikely(cqid
!= cq
->queue_id
)) {
12588 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12589 "0368 Miss-matched fast-path completion "
12590 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
12591 cqid
, cq
->queue_id
);
12595 /* Process all the entries to the CQ */
12596 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12597 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
12598 if (!(++ecount
% cq
->entry_repost
))
12599 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12602 /* Track the max number of CQEs processed in 1 EQ */
12603 if (ecount
> cq
->CQ_max_cqe
)
12604 cq
->CQ_max_cqe
= ecount
;
12606 /* Catch the no cq entry condition */
12607 if (unlikely(ecount
== 0))
12608 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12609 "0369 No entry from fast-path completion "
12610 "queue fcpcqid=%d\n", cq
->queue_id
);
12612 /* In any case, flash and re-arm the CQ */
12613 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12615 /* wake up worker thread if there are works to be done */
12617 lpfc_worker_wake_up(phba
);
12621 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12623 struct lpfc_eqe
*eqe
;
12625 /* walk all the EQ entries and drop on the floor */
12626 while ((eqe
= lpfc_sli4_eq_get(eq
)))
12629 /* Clear and re-arm the EQ */
12630 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
12635 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
12637 * @phba: Pointer to HBA context object.
12638 * @eqe: Pointer to fast-path event queue entry.
12640 * This routine process a event queue entry from the Flash Optimized Fabric
12641 * event queue. It will check the MajorCode and MinorCode to determine this
12642 * is for a completion event on a completion queue, if not, an error shall be
12643 * logged and just return. Otherwise, it will get to the corresponding
12644 * completion queue and process all the entries on the completion queue, rearm
12645 * the completion queue, and then return.
12648 lpfc_sli4_fof_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
12650 struct lpfc_queue
*cq
;
12651 struct lpfc_cqe
*cqe
;
12652 bool workposted
= false;
12656 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
12657 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12658 "9147 Not a valid completion "
12659 "event: majorcode=x%x, minorcode=x%x\n",
12660 bf_get_le32(lpfc_eqe_major_code
, eqe
),
12661 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
12665 /* Get the reference to the corresponding CQ */
12666 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12668 /* Next check for OAS */
12669 cq
= phba
->sli4_hba
.oas_cq
;
12670 if (unlikely(!cq
)) {
12671 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12672 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12673 "9148 OAS completion queue "
12674 "does not exist\n");
12678 if (unlikely(cqid
!= cq
->queue_id
)) {
12679 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12680 "9149 Miss-matched fast-path compl "
12681 "queue id: eqcqid=%d, fcpcqid=%d\n",
12682 cqid
, cq
->queue_id
);
12686 /* Process all the entries to the OAS CQ */
12687 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12688 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
12689 if (!(++ecount
% cq
->entry_repost
))
12690 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12693 /* Track the max number of CQEs processed in 1 EQ */
12694 if (ecount
> cq
->CQ_max_cqe
)
12695 cq
->CQ_max_cqe
= ecount
;
12697 /* Catch the no cq entry condition */
12698 if (unlikely(ecount
== 0))
12699 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12700 "9153 No entry from fast-path completion "
12701 "queue fcpcqid=%d\n", cq
->queue_id
);
12703 /* In any case, flash and re-arm the CQ */
12704 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12706 /* wake up worker thread if there are works to be done */
12708 lpfc_worker_wake_up(phba
);
12712 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
12713 * @irq: Interrupt number.
12714 * @dev_id: The device context pointer.
12716 * This function is directly called from the PCI layer as an interrupt
12717 * service routine when device with SLI-4 interface spec is enabled with
12718 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
12719 * IOCB ring event in the HBA. However, when the device is enabled with either
12720 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12721 * device-level interrupt handler. When the PCI slot is in error recovery
12722 * or the HBA is undergoing initialization, the interrupt handler will not
12723 * process the interrupt. The Flash Optimized Fabric ring event are handled in
12724 * the intrrupt context. This function is called without any lock held.
12725 * It gets the hbalock to access and update SLI data structures. Note that,
12726 * the EQ to CQ are one-to-one map such that the EQ index is
12727 * equal to that of CQ index.
12729 * This function returns IRQ_HANDLED when interrupt is handled else it
12730 * returns IRQ_NONE.
12733 lpfc_sli4_fof_intr_handler(int irq
, void *dev_id
)
12735 struct lpfc_hba
*phba
;
12736 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
12737 struct lpfc_queue
*eq
;
12738 struct lpfc_eqe
*eqe
;
12739 unsigned long iflag
;
12742 /* Get the driver's phba structure from the dev_id */
12743 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
12744 phba
= fcp_eq_hdl
->phba
;
12746 if (unlikely(!phba
))
12749 /* Get to the EQ struct associated with this vector */
12750 eq
= phba
->sli4_hba
.fof_eq
;
12754 /* Check device state for handling interrupt */
12755 if (unlikely(lpfc_intr_state_check(phba
))) {
12757 /* Check again for link_state with lock held */
12758 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12759 if (phba
->link_state
< LPFC_LINK_DOWN
)
12760 /* Flush, clear interrupt, and rearm the EQ */
12761 lpfc_sli4_eq_flush(phba
, eq
);
12762 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12767 * Process all the event on FCP fast-path EQ
12769 while ((eqe
= lpfc_sli4_eq_get(eq
))) {
12770 lpfc_sli4_fof_handle_eqe(phba
, eqe
);
12771 if (!(++ecount
% eq
->entry_repost
))
12772 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_NOARM
);
12773 eq
->EQ_processed
++;
12776 /* Track the max number of EQEs processed in 1 intr */
12777 if (ecount
> eq
->EQ_max_eqe
)
12778 eq
->EQ_max_eqe
= ecount
;
12781 if (unlikely(ecount
== 0)) {
12784 if (phba
->intr_type
== MSIX
)
12785 /* MSI-X treated interrupt served as no EQ share INT */
12786 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12787 "9145 MSI-X interrupt with no EQE\n");
12789 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12790 "9146 ISR interrupt with no EQE\n");
12791 /* Non MSI-X treated on interrupt as EQ share INT */
12795 /* Always clear and re-arm the fast-path EQ */
12796 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
12797 return IRQ_HANDLED
;
12801 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
12802 * @irq: Interrupt number.
12803 * @dev_id: The device context pointer.
12805 * This function is directly called from the PCI layer as an interrupt
12806 * service routine when device with SLI-4 interface spec is enabled with
12807 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12808 * ring event in the HBA. However, when the device is enabled with either
12809 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12810 * device-level interrupt handler. When the PCI slot is in error recovery
12811 * or the HBA is undergoing initialization, the interrupt handler will not
12812 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12813 * the intrrupt context. This function is called without any lock held.
12814 * It gets the hbalock to access and update SLI data structures. Note that,
12815 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
12816 * equal to that of FCP CQ index.
12818 * The link attention and ELS ring attention events are handled
12819 * by the worker thread. The interrupt handler signals the worker thread
12820 * and returns for these events. This function is called without any lock
12821 * held. It gets the hbalock to access and update SLI data structures.
12823 * This function returns IRQ_HANDLED when interrupt is handled else it
12824 * returns IRQ_NONE.
12827 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
12829 struct lpfc_hba
*phba
;
12830 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
12831 struct lpfc_queue
*fpeq
;
12832 struct lpfc_eqe
*eqe
;
12833 unsigned long iflag
;
12837 /* Get the driver's phba structure from the dev_id */
12838 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
12839 phba
= fcp_eq_hdl
->phba
;
12840 fcp_eqidx
= fcp_eq_hdl
->idx
;
12842 if (unlikely(!phba
))
12844 if (unlikely(!phba
->sli4_hba
.hba_eq
))
12847 /* Get to the EQ struct associated with this vector */
12848 fpeq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12849 if (unlikely(!fpeq
))
12852 if (lpfc_fcp_look_ahead
) {
12853 if (atomic_dec_and_test(&fcp_eq_hdl
->fcp_eq_in_use
))
12854 lpfc_sli4_eq_clr_intr(fpeq
);
12856 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12861 /* Check device state for handling interrupt */
12862 if (unlikely(lpfc_intr_state_check(phba
))) {
12863 fpeq
->EQ_badstate
++;
12864 /* Check again for link_state with lock held */
12865 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12866 if (phba
->link_state
< LPFC_LINK_DOWN
)
12867 /* Flush, clear interrupt, and rearm the EQ */
12868 lpfc_sli4_eq_flush(phba
, fpeq
);
12869 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12870 if (lpfc_fcp_look_ahead
)
12871 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12876 * Process all the event on FCP fast-path EQ
12878 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
12882 lpfc_sli4_hba_handle_eqe(phba
, eqe
, fcp_eqidx
);
12883 if (!(++ecount
% fpeq
->entry_repost
))
12884 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
12885 fpeq
->EQ_processed
++;
12888 /* Track the max number of EQEs processed in 1 intr */
12889 if (ecount
> fpeq
->EQ_max_eqe
)
12890 fpeq
->EQ_max_eqe
= ecount
;
12892 /* Always clear and re-arm the fast-path EQ */
12893 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
12895 if (unlikely(ecount
== 0)) {
12896 fpeq
->EQ_no_entry
++;
12898 if (lpfc_fcp_look_ahead
) {
12899 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12903 if (phba
->intr_type
== MSIX
)
12904 /* MSI-X treated interrupt served as no EQ share INT */
12905 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12906 "0358 MSI-X interrupt with no EQE\n");
12908 /* Non MSI-X treated on interrupt as EQ share INT */
12912 if (lpfc_fcp_look_ahead
)
12913 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12914 return IRQ_HANDLED
;
12915 } /* lpfc_sli4_fp_intr_handler */
12918 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
12919 * @irq: Interrupt number.
12920 * @dev_id: The device context pointer.
12922 * This function is the device-level interrupt handler to device with SLI-4
12923 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
12924 * interrupt mode is enabled and there is an event in the HBA which requires
12925 * driver attention. This function invokes the slow-path interrupt attention
12926 * handling function and fast-path interrupt attention handling function in
12927 * turn to process the relevant HBA attention events. This function is called
12928 * without any lock held. It gets the hbalock to access and update SLI data
12931 * This function returns IRQ_HANDLED when interrupt is handled, else it
12932 * returns IRQ_NONE.
12935 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
12937 struct lpfc_hba
*phba
;
12938 irqreturn_t hba_irq_rc
;
12939 bool hba_handled
= false;
12942 /* Get the driver's phba structure from the dev_id */
12943 phba
= (struct lpfc_hba
*)dev_id
;
12945 if (unlikely(!phba
))
12949 * Invoke fast-path host attention interrupt handling as appropriate.
12951 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
12952 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
12953 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
12954 if (hba_irq_rc
== IRQ_HANDLED
)
12955 hba_handled
|= true;
12958 if (phba
->cfg_fof
) {
12959 hba_irq_rc
= lpfc_sli4_fof_intr_handler(irq
,
12960 &phba
->sli4_hba
.fcp_eq_hdl
[0]);
12961 if (hba_irq_rc
== IRQ_HANDLED
)
12962 hba_handled
|= true;
12965 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
12966 } /* lpfc_sli4_intr_handler */
12969 * lpfc_sli4_queue_free - free a queue structure and associated memory
12970 * @queue: The queue structure to free.
12972 * This function frees a queue structure and the DMAable memory used for
12973 * the host resident queue. This function must be called after destroying the
12974 * queue on the HBA.
12977 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
12979 struct lpfc_dmabuf
*dmabuf
;
12984 while (!list_empty(&queue
->page_list
)) {
12985 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
12987 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
12988 dmabuf
->virt
, dmabuf
->phys
);
12996 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12997 * @phba: The HBA that this queue is being created on.
12998 * @entry_size: The size of each queue entry for this queue.
12999 * @entry count: The number of entries that this queue will handle.
13001 * This function allocates a queue structure and the DMAable memory used for
13002 * the host resident queue. This function must be called before creating the
13003 * queue on the HBA.
13005 struct lpfc_queue
*
13006 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
13007 uint32_t entry_count
)
13009 struct lpfc_queue
*queue
;
13010 struct lpfc_dmabuf
*dmabuf
;
13011 int x
, total_qe_count
;
13013 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13015 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13016 hw_page_size
= SLI4_PAGE_SIZE
;
13018 queue
= kzalloc(sizeof(struct lpfc_queue
) +
13019 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
13022 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
13023 hw_page_size
))/hw_page_size
;
13024 INIT_LIST_HEAD(&queue
->list
);
13025 INIT_LIST_HEAD(&queue
->page_list
);
13026 INIT_LIST_HEAD(&queue
->child_list
);
13027 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
13028 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
13031 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
13032 hw_page_size
, &dmabuf
->phys
,
13034 if (!dmabuf
->virt
) {
13038 dmabuf
->buffer_tag
= x
;
13039 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
13040 /* initialize queue's entry array */
13041 dma_pointer
= dmabuf
->virt
;
13042 for (; total_qe_count
< entry_count
&&
13043 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
13044 total_qe_count
++, dma_pointer
+= entry_size
) {
13045 queue
->qe
[total_qe_count
].address
= dma_pointer
;
13048 queue
->entry_size
= entry_size
;
13049 queue
->entry_count
= entry_count
;
13052 * entry_repost is calculated based on the number of entries in the
13053 * queue. This works out except for RQs. If buffers are NOT initially
13054 * posted for every RQE, entry_repost should be adjusted accordingly.
13056 queue
->entry_repost
= (entry_count
>> 3);
13057 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
13058 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
13059 queue
->phba
= phba
;
13063 lpfc_sli4_queue_free(queue
);
13068 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
13069 * @phba: HBA structure that indicates port to create a queue on.
13070 * @pci_barset: PCI BAR set flag.
13072 * This function shall perform iomap of the specified PCI BAR address to host
13073 * memory address if not already done so and return it. The returned host
13074 * memory address can be NULL.
13076 static void __iomem
*
13077 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
13082 switch (pci_barset
) {
13083 case WQ_PCI_BAR_0_AND_1
:
13084 return phba
->pci_bar0_memmap_p
;
13085 case WQ_PCI_BAR_2_AND_3
:
13086 return phba
->pci_bar2_memmap_p
;
13087 case WQ_PCI_BAR_4_AND_5
:
13088 return phba
->pci_bar4_memmap_p
;
13096 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
13097 * @phba: HBA structure that indicates port to create a queue on.
13098 * @startq: The starting FCP EQ to modify
13100 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
13102 * The @phba struct is used to send mailbox command to HBA. The @startq
13103 * is used to get the starting FCP EQ to change.
13104 * This function is asynchronous and will wait for the mailbox
13105 * command to finish before continuing.
13107 * On success this function will return a zero. If unable to allocate enough
13108 * memory this function will return -ENOMEM. If the queue create mailbox command
13109 * fails this function will return -ENXIO.
13112 lpfc_modify_fcp_eq_delay(struct lpfc_hba
*phba
, uint32_t startq
)
13114 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
13115 LPFC_MBOXQ_t
*mbox
;
13116 struct lpfc_queue
*eq
;
13117 int cnt
, rc
, length
, status
= 0;
13118 uint32_t shdr_status
, shdr_add_status
;
13121 union lpfc_sli4_cfg_shdr
*shdr
;
13124 if (startq
>= phba
->cfg_fcp_io_channel
)
13127 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13130 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
13131 sizeof(struct lpfc_sli4_cfg_mhdr
));
13132 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13133 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
13134 length
, LPFC_SLI4_MBX_EMBED
);
13135 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
13137 /* Calculate delay multiper from maximum interrupt per second */
13138 result
= phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
;
13139 if (result
> LPFC_DMULT_CONST
)
13142 dmult
= LPFC_DMULT_CONST
/result
- 1;
13145 for (fcp_eqidx
= startq
; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
13147 eq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
13150 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
13151 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
13152 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
13154 if (cnt
>= LPFC_MAX_EQ_DELAY
)
13157 eq_delay
->u
.request
.num_eq
= cnt
;
13159 mbox
->vport
= phba
->pport
;
13160 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13161 mbox
->context1
= NULL
;
13162 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13163 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
13164 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13165 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13166 if (shdr_status
|| shdr_add_status
|| rc
) {
13167 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13168 "2512 MODIFY_EQ_DELAY mailbox failed with "
13169 "status x%x add_status x%x, mbx status x%x\n",
13170 shdr_status
, shdr_add_status
, rc
);
13173 mempool_free(mbox
, phba
->mbox_mem_pool
);
13178 * lpfc_eq_create - Create an Event Queue on the HBA
13179 * @phba: HBA structure that indicates port to create a queue on.
13180 * @eq: The queue structure to use to create the event queue.
13181 * @imax: The maximum interrupt per second limit.
13183 * This function creates an event queue, as detailed in @eq, on a port,
13184 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
13186 * The @phba struct is used to send mailbox command to HBA. The @eq struct
13187 * is used to get the entry count and entry size that are necessary to
13188 * determine the number of pages to allocate and use for this queue. This
13189 * function will send the EQ_CREATE mailbox command to the HBA to setup the
13190 * event queue. This function is asynchronous and will wait for the mailbox
13191 * command to finish before continuing.
13193 * On success this function will return a zero. If unable to allocate enough
13194 * memory this function will return -ENOMEM. If the queue create mailbox command
13195 * fails this function will return -ENXIO.
13198 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
13200 struct lpfc_mbx_eq_create
*eq_create
;
13201 LPFC_MBOXQ_t
*mbox
;
13202 int rc
, length
, status
= 0;
13203 struct lpfc_dmabuf
*dmabuf
;
13204 uint32_t shdr_status
, shdr_add_status
;
13205 union lpfc_sli4_cfg_shdr
*shdr
;
13207 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13209 /* sanity check on queue memory */
13212 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13213 hw_page_size
= SLI4_PAGE_SIZE
;
13215 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13218 length
= (sizeof(struct lpfc_mbx_eq_create
) -
13219 sizeof(struct lpfc_sli4_cfg_mhdr
));
13220 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13221 LPFC_MBOX_OPCODE_EQ_CREATE
,
13222 length
, LPFC_SLI4_MBX_EMBED
);
13223 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
13224 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
13226 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
13228 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
13229 /* don't setup delay multiplier using EQ_CREATE */
13231 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
13233 switch (eq
->entry_count
) {
13235 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13236 "0360 Unsupported EQ count. (%d)\n",
13238 if (eq
->entry_count
< 256)
13240 /* otherwise default to smallest count (drop through) */
13242 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13246 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13250 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13254 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13258 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13262 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
13263 memset(dmabuf
->virt
, 0, hw_page_size
);
13264 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13265 putPaddrLow(dmabuf
->phys
);
13266 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13267 putPaddrHigh(dmabuf
->phys
);
13269 mbox
->vport
= phba
->pport
;
13270 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13271 mbox
->context1
= NULL
;
13272 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13273 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
13274 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13275 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13276 if (shdr_status
|| shdr_add_status
|| rc
) {
13277 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13278 "2500 EQ_CREATE mailbox failed with "
13279 "status x%x add_status x%x, mbx status x%x\n",
13280 shdr_status
, shdr_add_status
, rc
);
13283 eq
->type
= LPFC_EQ
;
13284 eq
->subtype
= LPFC_NONE
;
13285 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
13286 if (eq
->queue_id
== 0xFFFF)
13288 eq
->host_index
= 0;
13291 mempool_free(mbox
, phba
->mbox_mem_pool
);
13296 * lpfc_cq_create - Create a Completion Queue on the HBA
13297 * @phba: HBA structure that indicates port to create a queue on.
13298 * @cq: The queue structure to use to create the completion queue.
13299 * @eq: The event queue to bind this completion queue to.
13301 * This function creates a completion queue, as detailed in @wq, on a port,
13302 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
13304 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13305 * is used to get the entry count and entry size that are necessary to
13306 * determine the number of pages to allocate and use for this queue. The @eq
13307 * is used to indicate which event queue to bind this completion queue to. This
13308 * function will send the CQ_CREATE mailbox command to the HBA to setup the
13309 * completion queue. This function is asynchronous and will wait for the mailbox
13310 * command to finish before continuing.
13312 * On success this function will return a zero. If unable to allocate enough
13313 * memory this function will return -ENOMEM. If the queue create mailbox command
13314 * fails this function will return -ENXIO.
13317 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13318 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
13320 struct lpfc_mbx_cq_create
*cq_create
;
13321 struct lpfc_dmabuf
*dmabuf
;
13322 LPFC_MBOXQ_t
*mbox
;
13323 int rc
, length
, status
= 0;
13324 uint32_t shdr_status
, shdr_add_status
;
13325 union lpfc_sli4_cfg_shdr
*shdr
;
13326 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13328 /* sanity check on queue memory */
13331 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13332 hw_page_size
= SLI4_PAGE_SIZE
;
13334 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13337 length
= (sizeof(struct lpfc_mbx_cq_create
) -
13338 sizeof(struct lpfc_sli4_cfg_mhdr
));
13339 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13340 LPFC_MBOX_OPCODE_CQ_CREATE
,
13341 length
, LPFC_SLI4_MBX_EMBED
);
13342 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
13343 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
13344 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
13346 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
13347 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
13348 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13349 phba
->sli4_hba
.pc_sli4_params
.cqv
);
13350 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
13351 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
13352 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
13353 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
13356 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
13359 switch (cq
->entry_count
) {
13361 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13362 "0361 Unsupported CQ count. (%d)\n",
13364 if (cq
->entry_count
< 256) {
13368 /* otherwise default to smallest count (drop through) */
13370 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
13374 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
13378 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
13382 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
13383 memset(dmabuf
->virt
, 0, hw_page_size
);
13384 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13385 putPaddrLow(dmabuf
->phys
);
13386 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13387 putPaddrHigh(dmabuf
->phys
);
13389 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13391 /* The IOCTL status is embedded in the mailbox subheader. */
13392 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13393 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13394 if (shdr_status
|| shdr_add_status
|| rc
) {
13395 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13396 "2501 CQ_CREATE mailbox failed with "
13397 "status x%x add_status x%x, mbx status x%x\n",
13398 shdr_status
, shdr_add_status
, rc
);
13402 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
13403 if (cq
->queue_id
== 0xFFFF) {
13407 /* link the cq onto the parent eq child list */
13408 list_add_tail(&cq
->list
, &eq
->child_list
);
13409 /* Set up completion queue's type and subtype */
13411 cq
->subtype
= subtype
;
13412 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
13413 cq
->assoc_qid
= eq
->queue_id
;
13414 cq
->host_index
= 0;
13418 mempool_free(mbox
, phba
->mbox_mem_pool
);
13423 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
13424 * @phba: HBA structure that indicates port to create a queue on.
13425 * @mq: The queue structure to use to create the mailbox queue.
13426 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
13427 * @cq: The completion queue to associate with this cq.
13429 * This function provides failback (fb) functionality when the
13430 * mq_create_ext fails on older FW generations. It's purpose is identical
13431 * to mq_create_ext otherwise.
13433 * This routine cannot fail as all attributes were previously accessed and
13434 * initialized in mq_create_ext.
13437 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
13438 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
13440 struct lpfc_mbx_mq_create
*mq_create
;
13441 struct lpfc_dmabuf
*dmabuf
;
13444 length
= (sizeof(struct lpfc_mbx_mq_create
) -
13445 sizeof(struct lpfc_sli4_cfg_mhdr
));
13446 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13447 LPFC_MBOX_OPCODE_MQ_CREATE
,
13448 length
, LPFC_SLI4_MBX_EMBED
);
13449 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
13450 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
13452 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
13454 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
13455 switch (mq
->entry_count
) {
13457 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13458 LPFC_MQ_RING_SIZE_16
);
13461 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13462 LPFC_MQ_RING_SIZE_32
);
13465 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13466 LPFC_MQ_RING_SIZE_64
);
13469 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13470 LPFC_MQ_RING_SIZE_128
);
13473 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
13474 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13475 putPaddrLow(dmabuf
->phys
);
13476 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13477 putPaddrHigh(dmabuf
->phys
);
13482 * lpfc_mq_create - Create a mailbox Queue on the HBA
13483 * @phba: HBA structure that indicates port to create a queue on.
13484 * @mq: The queue structure to use to create the mailbox queue.
13485 * @cq: The completion queue to associate with this cq.
13486 * @subtype: The queue's subtype.
13488 * This function creates a mailbox queue, as detailed in @mq, on a port,
13489 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
13491 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13492 * is used to get the entry count and entry size that are necessary to
13493 * determine the number of pages to allocate and use for this queue. This
13494 * function will send the MQ_CREATE mailbox command to the HBA to setup the
13495 * mailbox queue. This function is asynchronous and will wait for the mailbox
13496 * command to finish before continuing.
13498 * On success this function will return a zero. If unable to allocate enough
13499 * memory this function will return -ENOMEM. If the queue create mailbox command
13500 * fails this function will return -ENXIO.
13503 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
13504 struct lpfc_queue
*cq
, uint32_t subtype
)
13506 struct lpfc_mbx_mq_create
*mq_create
;
13507 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
13508 struct lpfc_dmabuf
*dmabuf
;
13509 LPFC_MBOXQ_t
*mbox
;
13510 int rc
, length
, status
= 0;
13511 uint32_t shdr_status
, shdr_add_status
;
13512 union lpfc_sli4_cfg_shdr
*shdr
;
13513 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13515 /* sanity check on queue memory */
13518 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13519 hw_page_size
= SLI4_PAGE_SIZE
;
13521 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13524 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
13525 sizeof(struct lpfc_sli4_cfg_mhdr
));
13526 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13527 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
13528 length
, LPFC_SLI4_MBX_EMBED
);
13530 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
13531 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
13532 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
13533 &mq_create_ext
->u
.request
, mq
->page_count
);
13534 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
13535 &mq_create_ext
->u
.request
, 1);
13536 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
13537 &mq_create_ext
->u
.request
, 1);
13538 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
13539 &mq_create_ext
->u
.request
, 1);
13540 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
13541 &mq_create_ext
->u
.request
, 1);
13542 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
13543 &mq_create_ext
->u
.request
, 1);
13544 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
13545 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13546 phba
->sli4_hba
.pc_sli4_params
.mqv
);
13547 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
13548 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
13551 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
13553 switch (mq
->entry_count
) {
13555 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13556 "0362 Unsupported MQ count. (%d)\n",
13558 if (mq
->entry_count
< 16) {
13562 /* otherwise default to smallest count (drop through) */
13564 bf_set(lpfc_mq_context_ring_size
,
13565 &mq_create_ext
->u
.request
.context
,
13566 LPFC_MQ_RING_SIZE_16
);
13569 bf_set(lpfc_mq_context_ring_size
,
13570 &mq_create_ext
->u
.request
.context
,
13571 LPFC_MQ_RING_SIZE_32
);
13574 bf_set(lpfc_mq_context_ring_size
,
13575 &mq_create_ext
->u
.request
.context
,
13576 LPFC_MQ_RING_SIZE_64
);
13579 bf_set(lpfc_mq_context_ring_size
,
13580 &mq_create_ext
->u
.request
.context
,
13581 LPFC_MQ_RING_SIZE_128
);
13584 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
13585 memset(dmabuf
->virt
, 0, hw_page_size
);
13586 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13587 putPaddrLow(dmabuf
->phys
);
13588 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13589 putPaddrHigh(dmabuf
->phys
);
13591 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13592 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
13593 &mq_create_ext
->u
.response
);
13594 if (rc
!= MBX_SUCCESS
) {
13595 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13596 "2795 MQ_CREATE_EXT failed with "
13597 "status x%x. Failback to MQ_CREATE.\n",
13599 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
13600 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
13601 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13602 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
13603 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
13604 &mq_create
->u
.response
);
13607 /* The IOCTL status is embedded in the mailbox subheader. */
13608 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13609 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13610 if (shdr_status
|| shdr_add_status
|| rc
) {
13611 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13612 "2502 MQ_CREATE mailbox failed with "
13613 "status x%x add_status x%x, mbx status x%x\n",
13614 shdr_status
, shdr_add_status
, rc
);
13618 if (mq
->queue_id
== 0xFFFF) {
13622 mq
->type
= LPFC_MQ
;
13623 mq
->assoc_qid
= cq
->queue_id
;
13624 mq
->subtype
= subtype
;
13625 mq
->host_index
= 0;
13628 /* link the mq onto the parent cq child list */
13629 list_add_tail(&mq
->list
, &cq
->child_list
);
13631 mempool_free(mbox
, phba
->mbox_mem_pool
);
13636 * lpfc_wq_create - Create a Work Queue on the HBA
13637 * @phba: HBA structure that indicates port to create a queue on.
13638 * @wq: The queue structure to use to create the work queue.
13639 * @cq: The completion queue to bind this work queue to.
13640 * @subtype: The subtype of the work queue indicating its functionality.
13642 * This function creates a work queue, as detailed in @wq, on a port, described
13643 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
13645 * The @phba struct is used to send mailbox command to HBA. The @wq struct
13646 * is used to get the entry count and entry size that are necessary to
13647 * determine the number of pages to allocate and use for this queue. The @cq
13648 * is used to indicate which completion queue to bind this work queue to. This
13649 * function will send the WQ_CREATE mailbox command to the HBA to setup the
13650 * work queue. This function is asynchronous and will wait for the mailbox
13651 * command to finish before continuing.
13653 * On success this function will return a zero. If unable to allocate enough
13654 * memory this function will return -ENOMEM. If the queue create mailbox command
13655 * fails this function will return -ENXIO.
13658 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
13659 struct lpfc_queue
*cq
, uint32_t subtype
)
13661 struct lpfc_mbx_wq_create
*wq_create
;
13662 struct lpfc_dmabuf
*dmabuf
;
13663 LPFC_MBOXQ_t
*mbox
;
13664 int rc
, length
, status
= 0;
13665 uint32_t shdr_status
, shdr_add_status
;
13666 union lpfc_sli4_cfg_shdr
*shdr
;
13667 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13668 struct dma_address
*page
;
13669 void __iomem
*bar_memmap_p
;
13670 uint32_t db_offset
;
13671 uint16_t pci_barset
;
13673 /* sanity check on queue memory */
13676 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13677 hw_page_size
= SLI4_PAGE_SIZE
;
13679 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13682 length
= (sizeof(struct lpfc_mbx_wq_create
) -
13683 sizeof(struct lpfc_sli4_cfg_mhdr
));
13684 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13685 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
13686 length
, LPFC_SLI4_MBX_EMBED
);
13687 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
13688 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
13689 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
13691 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
13694 /* wqv is the earliest version supported, NOT the latest */
13695 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13696 phba
->sli4_hba
.pc_sli4_params
.wqv
);
13698 switch (phba
->sli4_hba
.pc_sli4_params
.wqv
) {
13699 case LPFC_Q_CREATE_VERSION_0
:
13700 switch (wq
->entry_size
) {
13703 /* Nothing to do, version 0 ONLY supports 64 byte */
13704 page
= wq_create
->u
.request
.page
;
13707 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
13708 LPFC_WQ_SZ128_SUPPORT
)) {
13712 /* If we get here the HBA MUST also support V1 and
13715 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13716 LPFC_Q_CREATE_VERSION_1
);
13718 bf_set(lpfc_mbx_wq_create_wqe_count
,
13719 &wq_create
->u
.request_1
, wq
->entry_count
);
13720 bf_set(lpfc_mbx_wq_create_wqe_size
,
13721 &wq_create
->u
.request_1
,
13722 LPFC_WQ_WQE_SIZE_128
);
13723 bf_set(lpfc_mbx_wq_create_page_size
,
13724 &wq_create
->u
.request_1
,
13725 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13726 page
= wq_create
->u
.request_1
.page
;
13730 case LPFC_Q_CREATE_VERSION_1
:
13731 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
13733 switch (wq
->entry_size
) {
13736 bf_set(lpfc_mbx_wq_create_wqe_size
,
13737 &wq_create
->u
.request_1
,
13738 LPFC_WQ_WQE_SIZE_64
);
13741 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
13742 LPFC_WQ_SZ128_SUPPORT
)) {
13746 bf_set(lpfc_mbx_wq_create_wqe_size
,
13747 &wq_create
->u
.request_1
,
13748 LPFC_WQ_WQE_SIZE_128
);
13751 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
13752 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13753 page
= wq_create
->u
.request_1
.page
;
13760 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
13761 memset(dmabuf
->virt
, 0, hw_page_size
);
13762 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
13763 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
13766 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13767 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
13769 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13770 /* The IOCTL status is embedded in the mailbox subheader. */
13771 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13772 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13773 if (shdr_status
|| shdr_add_status
|| rc
) {
13774 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13775 "2503 WQ_CREATE mailbox failed with "
13776 "status x%x add_status x%x, mbx status x%x\n",
13777 shdr_status
, shdr_add_status
, rc
);
13781 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
13782 if (wq
->queue_id
== 0xFFFF) {
13786 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
13787 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
13788 &wq_create
->u
.response
);
13789 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
13790 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
13791 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13792 "3265 WQ[%d] doorbell format not "
13793 "supported: x%x\n", wq
->queue_id
,
13798 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
13799 &wq_create
->u
.response
);
13800 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
13801 if (!bar_memmap_p
) {
13802 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13803 "3263 WQ[%d] failed to memmap pci "
13804 "barset:x%x\n", wq
->queue_id
,
13809 db_offset
= wq_create
->u
.response
.doorbell_offset
;
13810 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
13811 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
13812 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13813 "3252 WQ[%d] doorbell offset not "
13814 "supported: x%x\n", wq
->queue_id
,
13819 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
13820 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13821 "3264 WQ[%d]: barset:x%x, offset:x%x, "
13822 "format:x%x\n", wq
->queue_id
, pci_barset
,
13823 db_offset
, wq
->db_format
);
13825 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
13826 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
13828 wq
->type
= LPFC_WQ
;
13829 wq
->assoc_qid
= cq
->queue_id
;
13830 wq
->subtype
= subtype
;
13831 wq
->host_index
= 0;
13833 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
13835 /* link the wq onto the parent cq child list */
13836 list_add_tail(&wq
->list
, &cq
->child_list
);
13838 mempool_free(mbox
, phba
->mbox_mem_pool
);
13843 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
13844 * @phba: HBA structure that indicates port to create a queue on.
13845 * @rq: The queue structure to use for the receive queue.
13846 * @qno: The associated HBQ number
13849 * For SLI4 we need to adjust the RQ repost value based on
13850 * the number of buffers that are initially posted to the RQ.
13853 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
13857 /* sanity check on queue memory */
13860 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
13862 /* Recalc repost for RQs based on buffers initially posted */
13864 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
13865 cnt
= LPFC_QUEUE_MIN_REPOST
;
13867 rq
->entry_repost
= cnt
;
13871 * lpfc_rq_create - Create a Receive Queue on the HBA
13872 * @phba: HBA structure that indicates port to create a queue on.
13873 * @hrq: The queue structure to use to create the header receive queue.
13874 * @drq: The queue structure to use to create the data receive queue.
13875 * @cq: The completion queue to bind this work queue to.
13877 * This function creates a receive buffer queue pair , as detailed in @hrq and
13878 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
13881 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
13882 * struct is used to get the entry count that is necessary to determine the
13883 * number of pages to use for this queue. The @cq is used to indicate which
13884 * completion queue to bind received buffers that are posted to these queues to.
13885 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
13886 * receive queue pair. This function is asynchronous and will wait for the
13887 * mailbox command to finish before continuing.
13889 * On success this function will return a zero. If unable to allocate enough
13890 * memory this function will return -ENOMEM. If the queue create mailbox command
13891 * fails this function will return -ENXIO.
13894 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13895 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
13897 struct lpfc_mbx_rq_create
*rq_create
;
13898 struct lpfc_dmabuf
*dmabuf
;
13899 LPFC_MBOXQ_t
*mbox
;
13900 int rc
, length
, status
= 0;
13901 uint32_t shdr_status
, shdr_add_status
;
13902 union lpfc_sli4_cfg_shdr
*shdr
;
13903 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13904 void __iomem
*bar_memmap_p
;
13905 uint32_t db_offset
;
13906 uint16_t pci_barset
;
13908 /* sanity check on queue memory */
13909 if (!hrq
|| !drq
|| !cq
)
13911 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13912 hw_page_size
= SLI4_PAGE_SIZE
;
13914 if (hrq
->entry_count
!= drq
->entry_count
)
13916 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13919 length
= (sizeof(struct lpfc_mbx_rq_create
) -
13920 sizeof(struct lpfc_sli4_cfg_mhdr
));
13921 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13922 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
13923 length
, LPFC_SLI4_MBX_EMBED
);
13924 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
13925 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13926 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13927 phba
->sli4_hba
.pc_sli4_params
.rqv
);
13928 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
13929 bf_set(lpfc_rq_context_rqe_count_1
,
13930 &rq_create
->u
.request
.context
,
13932 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
13933 bf_set(lpfc_rq_context_rqe_size
,
13934 &rq_create
->u
.request
.context
,
13936 bf_set(lpfc_rq_context_page_size
,
13937 &rq_create
->u
.request
.context
,
13938 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13940 switch (hrq
->entry_count
) {
13942 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13943 "2535 Unsupported RQ count. (%d)\n",
13945 if (hrq
->entry_count
< 512) {
13949 /* otherwise default to smallest count (drop through) */
13951 bf_set(lpfc_rq_context_rqe_count
,
13952 &rq_create
->u
.request
.context
,
13953 LPFC_RQ_RING_SIZE_512
);
13956 bf_set(lpfc_rq_context_rqe_count
,
13957 &rq_create
->u
.request
.context
,
13958 LPFC_RQ_RING_SIZE_1024
);
13961 bf_set(lpfc_rq_context_rqe_count
,
13962 &rq_create
->u
.request
.context
,
13963 LPFC_RQ_RING_SIZE_2048
);
13966 bf_set(lpfc_rq_context_rqe_count
,
13967 &rq_create
->u
.request
.context
,
13968 LPFC_RQ_RING_SIZE_4096
);
13971 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
13972 LPFC_HDR_BUF_SIZE
);
13974 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
13976 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
13978 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
13979 memset(dmabuf
->virt
, 0, hw_page_size
);
13980 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13981 putPaddrLow(dmabuf
->phys
);
13982 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13983 putPaddrHigh(dmabuf
->phys
);
13985 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13986 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
13988 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13989 /* The IOCTL status is embedded in the mailbox subheader. */
13990 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13991 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13992 if (shdr_status
|| shdr_add_status
|| rc
) {
13993 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13994 "2504 RQ_CREATE mailbox failed with "
13995 "status x%x add_status x%x, mbx status x%x\n",
13996 shdr_status
, shdr_add_status
, rc
);
14000 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
14001 if (hrq
->queue_id
== 0xFFFF) {
14006 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
14007 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
14008 &rq_create
->u
.response
);
14009 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
14010 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
14011 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14012 "3262 RQ [%d] doorbell format not "
14013 "supported: x%x\n", hrq
->queue_id
,
14019 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
14020 &rq_create
->u
.response
);
14021 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
14022 if (!bar_memmap_p
) {
14023 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14024 "3269 RQ[%d] failed to memmap pci "
14025 "barset:x%x\n", hrq
->queue_id
,
14031 db_offset
= rq_create
->u
.response
.doorbell_offset
;
14032 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
14033 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
14034 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14035 "3270 RQ[%d] doorbell offset not "
14036 "supported: x%x\n", hrq
->queue_id
,
14041 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
14042 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
14043 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
14044 "format:x%x\n", hrq
->queue_id
, pci_barset
,
14045 db_offset
, hrq
->db_format
);
14047 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
14048 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
14050 hrq
->type
= LPFC_HRQ
;
14051 hrq
->assoc_qid
= cq
->queue_id
;
14052 hrq
->subtype
= subtype
;
14053 hrq
->host_index
= 0;
14054 hrq
->hba_index
= 0;
14056 /* now create the data queue */
14057 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14058 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
14059 length
, LPFC_SLI4_MBX_EMBED
);
14060 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14061 phba
->sli4_hba
.pc_sli4_params
.rqv
);
14062 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
14063 bf_set(lpfc_rq_context_rqe_count_1
,
14064 &rq_create
->u
.request
.context
, hrq
->entry_count
);
14065 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
14066 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
14068 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
14069 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
14071 switch (drq
->entry_count
) {
14073 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14074 "2536 Unsupported RQ count. (%d)\n",
14076 if (drq
->entry_count
< 512) {
14080 /* otherwise default to smallest count (drop through) */
14082 bf_set(lpfc_rq_context_rqe_count
,
14083 &rq_create
->u
.request
.context
,
14084 LPFC_RQ_RING_SIZE_512
);
14087 bf_set(lpfc_rq_context_rqe_count
,
14088 &rq_create
->u
.request
.context
,
14089 LPFC_RQ_RING_SIZE_1024
);
14092 bf_set(lpfc_rq_context_rqe_count
,
14093 &rq_create
->u
.request
.context
,
14094 LPFC_RQ_RING_SIZE_2048
);
14097 bf_set(lpfc_rq_context_rqe_count
,
14098 &rq_create
->u
.request
.context
,
14099 LPFC_RQ_RING_SIZE_4096
);
14102 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
14103 LPFC_DATA_BUF_SIZE
);
14105 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
14107 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
14109 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
14110 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14111 putPaddrLow(dmabuf
->phys
);
14112 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14113 putPaddrHigh(dmabuf
->phys
);
14115 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
14116 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
14117 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14118 /* The IOCTL status is embedded in the mailbox subheader. */
14119 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
14120 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14121 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14122 if (shdr_status
|| shdr_add_status
|| rc
) {
14126 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
14127 if (drq
->queue_id
== 0xFFFF) {
14131 drq
->type
= LPFC_DRQ
;
14132 drq
->assoc_qid
= cq
->queue_id
;
14133 drq
->subtype
= subtype
;
14134 drq
->host_index
= 0;
14135 drq
->hba_index
= 0;
14137 /* link the header and data RQs onto the parent cq child list */
14138 list_add_tail(&hrq
->list
, &cq
->child_list
);
14139 list_add_tail(&drq
->list
, &cq
->child_list
);
14142 mempool_free(mbox
, phba
->mbox_mem_pool
);
14147 * lpfc_eq_destroy - Destroy an event Queue on the HBA
14148 * @eq: The queue structure associated with the queue to destroy.
14150 * This function destroys a queue, as detailed in @eq by sending an mailbox
14151 * command, specific to the type of queue, to the HBA.
14153 * The @eq struct is used to get the queue ID of the queue to destroy.
14155 * On success this function will return a zero. If the queue destroy mailbox
14156 * command fails this function will return -ENXIO.
14159 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
14161 LPFC_MBOXQ_t
*mbox
;
14162 int rc
, length
, status
= 0;
14163 uint32_t shdr_status
, shdr_add_status
;
14164 union lpfc_sli4_cfg_shdr
*shdr
;
14166 /* sanity check on queue memory */
14169 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14172 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
14173 sizeof(struct lpfc_sli4_cfg_mhdr
));
14174 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14175 LPFC_MBOX_OPCODE_EQ_DESTROY
,
14176 length
, LPFC_SLI4_MBX_EMBED
);
14177 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
14179 mbox
->vport
= eq
->phba
->pport
;
14180 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14182 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
14183 /* The IOCTL status is embedded in the mailbox subheader. */
14184 shdr
= (union lpfc_sli4_cfg_shdr
*)
14185 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
14186 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14187 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14188 if (shdr_status
|| shdr_add_status
|| rc
) {
14189 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14190 "2505 EQ_DESTROY mailbox failed with "
14191 "status x%x add_status x%x, mbx status x%x\n",
14192 shdr_status
, shdr_add_status
, rc
);
14196 /* Remove eq from any list */
14197 list_del_init(&eq
->list
);
14198 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
14203 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
14204 * @cq: The queue structure associated with the queue to destroy.
14206 * This function destroys a queue, as detailed in @cq by sending an mailbox
14207 * command, specific to the type of queue, to the HBA.
14209 * The @cq struct is used to get the queue ID of the queue to destroy.
14211 * On success this function will return a zero. If the queue destroy mailbox
14212 * command fails this function will return -ENXIO.
14215 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
14217 LPFC_MBOXQ_t
*mbox
;
14218 int rc
, length
, status
= 0;
14219 uint32_t shdr_status
, shdr_add_status
;
14220 union lpfc_sli4_cfg_shdr
*shdr
;
14222 /* sanity check on queue memory */
14225 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14228 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
14229 sizeof(struct lpfc_sli4_cfg_mhdr
));
14230 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14231 LPFC_MBOX_OPCODE_CQ_DESTROY
,
14232 length
, LPFC_SLI4_MBX_EMBED
);
14233 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
14235 mbox
->vport
= cq
->phba
->pport
;
14236 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14237 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
14238 /* The IOCTL status is embedded in the mailbox subheader. */
14239 shdr
= (union lpfc_sli4_cfg_shdr
*)
14240 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
14241 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14242 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14243 if (shdr_status
|| shdr_add_status
|| rc
) {
14244 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14245 "2506 CQ_DESTROY mailbox failed with "
14246 "status x%x add_status x%x, mbx status x%x\n",
14247 shdr_status
, shdr_add_status
, rc
);
14250 /* Remove cq from any list */
14251 list_del_init(&cq
->list
);
14252 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
14257 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
14258 * @qm: The queue structure associated with the queue to destroy.
14260 * This function destroys a queue, as detailed in @mq by sending an mailbox
14261 * command, specific to the type of queue, to the HBA.
14263 * The @mq struct is used to get the queue ID of the queue to destroy.
14265 * On success this function will return a zero. If the queue destroy mailbox
14266 * command fails this function will return -ENXIO.
14269 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
14271 LPFC_MBOXQ_t
*mbox
;
14272 int rc
, length
, status
= 0;
14273 uint32_t shdr_status
, shdr_add_status
;
14274 union lpfc_sli4_cfg_shdr
*shdr
;
14276 /* sanity check on queue memory */
14279 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14282 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
14283 sizeof(struct lpfc_sli4_cfg_mhdr
));
14284 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14285 LPFC_MBOX_OPCODE_MQ_DESTROY
,
14286 length
, LPFC_SLI4_MBX_EMBED
);
14287 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
14289 mbox
->vport
= mq
->phba
->pport
;
14290 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14291 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
14292 /* The IOCTL status is embedded in the mailbox subheader. */
14293 shdr
= (union lpfc_sli4_cfg_shdr
*)
14294 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
14295 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14296 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14297 if (shdr_status
|| shdr_add_status
|| rc
) {
14298 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14299 "2507 MQ_DESTROY mailbox failed with "
14300 "status x%x add_status x%x, mbx status x%x\n",
14301 shdr_status
, shdr_add_status
, rc
);
14304 /* Remove mq from any list */
14305 list_del_init(&mq
->list
);
14306 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
14311 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
14312 * @wq: The queue structure associated with the queue to destroy.
14314 * This function destroys a queue, as detailed in @wq by sending an mailbox
14315 * command, specific to the type of queue, to the HBA.
14317 * The @wq struct is used to get the queue ID of the queue to destroy.
14319 * On success this function will return a zero. If the queue destroy mailbox
14320 * command fails this function will return -ENXIO.
14323 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
14325 LPFC_MBOXQ_t
*mbox
;
14326 int rc
, length
, status
= 0;
14327 uint32_t shdr_status
, shdr_add_status
;
14328 union lpfc_sli4_cfg_shdr
*shdr
;
14330 /* sanity check on queue memory */
14333 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14336 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
14337 sizeof(struct lpfc_sli4_cfg_mhdr
));
14338 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14339 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
14340 length
, LPFC_SLI4_MBX_EMBED
);
14341 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
14343 mbox
->vport
= wq
->phba
->pport
;
14344 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14345 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
14346 shdr
= (union lpfc_sli4_cfg_shdr
*)
14347 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
14348 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14349 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14350 if (shdr_status
|| shdr_add_status
|| rc
) {
14351 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14352 "2508 WQ_DESTROY mailbox failed with "
14353 "status x%x add_status x%x, mbx status x%x\n",
14354 shdr_status
, shdr_add_status
, rc
);
14357 /* Remove wq from any list */
14358 list_del_init(&wq
->list
);
14359 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
14364 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
14365 * @rq: The queue structure associated with the queue to destroy.
14367 * This function destroys a queue, as detailed in @rq by sending an mailbox
14368 * command, specific to the type of queue, to the HBA.
14370 * The @rq struct is used to get the queue ID of the queue to destroy.
14372 * On success this function will return a zero. If the queue destroy mailbox
14373 * command fails this function will return -ENXIO.
14376 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
14377 struct lpfc_queue
*drq
)
14379 LPFC_MBOXQ_t
*mbox
;
14380 int rc
, length
, status
= 0;
14381 uint32_t shdr_status
, shdr_add_status
;
14382 union lpfc_sli4_cfg_shdr
*shdr
;
14384 /* sanity check on queue memory */
14387 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14390 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
14391 sizeof(struct lpfc_sli4_cfg_mhdr
));
14392 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14393 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
14394 length
, LPFC_SLI4_MBX_EMBED
);
14395 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
14397 mbox
->vport
= hrq
->phba
->pport
;
14398 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14399 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
14400 /* The IOCTL status is embedded in the mailbox subheader. */
14401 shdr
= (union lpfc_sli4_cfg_shdr
*)
14402 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
14403 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14404 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14405 if (shdr_status
|| shdr_add_status
|| rc
) {
14406 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14407 "2509 RQ_DESTROY mailbox failed with "
14408 "status x%x add_status x%x, mbx status x%x\n",
14409 shdr_status
, shdr_add_status
, rc
);
14410 if (rc
!= MBX_TIMEOUT
)
14411 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
14414 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
14416 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
14417 shdr
= (union lpfc_sli4_cfg_shdr
*)
14418 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
14419 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14420 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14421 if (shdr_status
|| shdr_add_status
|| rc
) {
14422 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14423 "2510 RQ_DESTROY mailbox failed with "
14424 "status x%x add_status x%x, mbx status x%x\n",
14425 shdr_status
, shdr_add_status
, rc
);
14428 list_del_init(&hrq
->list
);
14429 list_del_init(&drq
->list
);
14430 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
14435 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
14436 * @phba: The virtual port for which this call being executed.
14437 * @pdma_phys_addr0: Physical address of the 1st SGL page.
14438 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
14439 * @xritag: the xritag that ties this io to the SGL pages.
14441 * This routine will post the sgl pages for the IO that has the xritag
14442 * that is in the iocbq structure. The xritag is assigned during iocbq
14443 * creation and persists for as long as the driver is loaded.
14444 * if the caller has fewer than 256 scatter gather segments to map then
14445 * pdma_phys_addr1 should be 0.
14446 * If the caller needs to map more than 256 scatter gather segment then
14447 * pdma_phys_addr1 should be a valid physical address.
14448 * physical address for SGLs must be 64 byte aligned.
14449 * If you are going to map 2 SGL's then the first one must have 256 entries
14450 * the second sgl can have between 1 and 256 entries.
14454 * -ENXIO, -ENOMEM - Failure
14457 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
14458 dma_addr_t pdma_phys_addr0
,
14459 dma_addr_t pdma_phys_addr1
,
14462 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
14463 LPFC_MBOXQ_t
*mbox
;
14465 uint32_t shdr_status
, shdr_add_status
;
14467 union lpfc_sli4_cfg_shdr
*shdr
;
14469 if (xritag
== NO_XRI
) {
14470 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14471 "0364 Invalid param:\n");
14475 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14479 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14480 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
14481 sizeof(struct lpfc_mbx_post_sgl_pages
) -
14482 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
14484 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
14485 &mbox
->u
.mqe
.un
.post_sgl_pages
;
14486 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
14487 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
14489 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
14490 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
14491 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
14492 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
14494 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
14495 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
14496 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
14497 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
14498 if (!phba
->sli4_hba
.intr_enable
)
14499 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14501 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14502 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14504 /* The IOCTL status is embedded in the mailbox subheader. */
14505 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
14506 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14507 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14508 if (rc
!= MBX_TIMEOUT
)
14509 mempool_free(mbox
, phba
->mbox_mem_pool
);
14510 if (shdr_status
|| shdr_add_status
|| rc
) {
14511 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14512 "2511 POST_SGL mailbox failed with "
14513 "status x%x add_status x%x, mbx status x%x\n",
14514 shdr_status
, shdr_add_status
, rc
);
14520 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
14521 * @phba: pointer to lpfc hba data structure.
14523 * This routine is invoked to post rpi header templates to the
14524 * HBA consistent with the SLI-4 interface spec. This routine
14525 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14526 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14529 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14530 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14533 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
14538 * Fetch the next logical xri. Because this index is logical,
14539 * the driver starts at 0 each time.
14541 spin_lock_irq(&phba
->hbalock
);
14542 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
14543 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
14544 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
14545 spin_unlock_irq(&phba
->hbalock
);
14548 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
14549 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
14551 spin_unlock_irq(&phba
->hbalock
);
14556 * lpfc_sli4_free_xri - Release an xri for reuse.
14557 * @phba: pointer to lpfc hba data structure.
14559 * This routine is invoked to release an xri to the pool of
14560 * available rpis maintained by the driver.
14563 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
14565 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
14566 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
14571 * lpfc_sli4_free_xri - Release an xri for reuse.
14572 * @phba: pointer to lpfc hba data structure.
14574 * This routine is invoked to release an xri to the pool of
14575 * available rpis maintained by the driver.
14578 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
14580 spin_lock_irq(&phba
->hbalock
);
14581 __lpfc_sli4_free_xri(phba
, xri
);
14582 spin_unlock_irq(&phba
->hbalock
);
14586 * lpfc_sli4_next_xritag - Get an xritag for the io
14587 * @phba: Pointer to HBA context object.
14589 * This function gets an xritag for the iocb. If there is no unused xritag
14590 * it will return 0xffff.
14591 * The function returns the allocated xritag if successful, else returns zero.
14592 * Zero is not a valid xritag.
14593 * The caller is not required to hold any lock.
14596 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
14598 uint16_t xri_index
;
14600 xri_index
= lpfc_sli4_alloc_xri(phba
);
14601 if (xri_index
== NO_XRI
)
14602 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
14603 "2004 Failed to allocate XRI.last XRITAG is %d"
14604 " Max XRI is %d, Used XRI is %d\n",
14606 phba
->sli4_hba
.max_cfg_param
.max_xri
,
14607 phba
->sli4_hba
.max_cfg_param
.xri_used
);
14612 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
14613 * @phba: pointer to lpfc hba data structure.
14614 * @post_sgl_list: pointer to els sgl entry list.
14615 * @count: number of els sgl entries on the list.
14617 * This routine is invoked to post a block of driver's sgl pages to the
14618 * HBA using non-embedded mailbox command. No Lock is held. This routine
14619 * is only called when the driver is loading and after all IO has been
14623 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
14624 struct list_head
*post_sgl_list
,
14627 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
14628 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
14629 struct sgl_page_pairs
*sgl_pg_pairs
;
14631 LPFC_MBOXQ_t
*mbox
;
14632 uint32_t reqlen
, alloclen
, pg_pairs
;
14634 uint16_t xritag_start
= 0;
14636 uint32_t shdr_status
, shdr_add_status
;
14637 union lpfc_sli4_cfg_shdr
*shdr
;
14639 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
14640 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
14641 if (reqlen
> SLI4_PAGE_SIZE
) {
14642 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
14643 "2559 Block sgl registration required DMA "
14644 "size (%d) great than a page\n", reqlen
);
14647 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14651 /* Allocate DMA memory and set up the non-embedded mailbox command */
14652 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14653 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
14654 LPFC_SLI4_MBX_NEMBED
);
14656 if (alloclen
< reqlen
) {
14657 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14658 "0285 Allocated DMA memory size (%d) is "
14659 "less than the requested DMA memory "
14660 "size (%d)\n", alloclen
, reqlen
);
14661 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14664 /* Set up the SGL pages in the non-embedded DMA pages */
14665 viraddr
= mbox
->sge_array
->addr
[0];
14666 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
14667 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
14670 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
14671 /* Set up the sge entry */
14672 sgl_pg_pairs
->sgl_pg0_addr_lo
=
14673 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
14674 sgl_pg_pairs
->sgl_pg0_addr_hi
=
14675 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
14676 sgl_pg_pairs
->sgl_pg1_addr_lo
=
14677 cpu_to_le32(putPaddrLow(0));
14678 sgl_pg_pairs
->sgl_pg1_addr_hi
=
14679 cpu_to_le32(putPaddrHigh(0));
14681 /* Keep the first xritag on the list */
14683 xritag_start
= sglq_entry
->sli4_xritag
;
14688 /* Complete initialization and perform endian conversion. */
14689 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
14690 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
14691 sgl
->word0
= cpu_to_le32(sgl
->word0
);
14692 if (!phba
->sli4_hba
.intr_enable
)
14693 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14695 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14696 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14698 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
14699 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14700 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14701 if (rc
!= MBX_TIMEOUT
)
14702 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14703 if (shdr_status
|| shdr_add_status
|| rc
) {
14704 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14705 "2513 POST_SGL_BLOCK mailbox command failed "
14706 "status x%x add_status x%x mbx status x%x\n",
14707 shdr_status
, shdr_add_status
, rc
);
14714 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
14715 * @phba: pointer to lpfc hba data structure.
14716 * @sblist: pointer to scsi buffer list.
14717 * @count: number of scsi buffers on the list.
14719 * This routine is invoked to post a block of @count scsi sgl pages from a
14720 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
14725 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
14726 struct list_head
*sblist
,
14729 struct lpfc_scsi_buf
*psb
;
14730 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
14731 struct sgl_page_pairs
*sgl_pg_pairs
;
14733 LPFC_MBOXQ_t
*mbox
;
14734 uint32_t reqlen
, alloclen
, pg_pairs
;
14736 uint16_t xritag_start
= 0;
14738 uint32_t shdr_status
, shdr_add_status
;
14739 dma_addr_t pdma_phys_bpl1
;
14740 union lpfc_sli4_cfg_shdr
*shdr
;
14742 /* Calculate the requested length of the dma memory */
14743 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
14744 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
14745 if (reqlen
> SLI4_PAGE_SIZE
) {
14746 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
14747 "0217 Block sgl registration required DMA "
14748 "size (%d) great than a page\n", reqlen
);
14751 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14753 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14754 "0283 Failed to allocate mbox cmd memory\n");
14758 /* Allocate DMA memory and set up the non-embedded mailbox command */
14759 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14760 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
14761 LPFC_SLI4_MBX_NEMBED
);
14763 if (alloclen
< reqlen
) {
14764 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14765 "2561 Allocated DMA memory size (%d) is "
14766 "less than the requested DMA memory "
14767 "size (%d)\n", alloclen
, reqlen
);
14768 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14772 /* Get the first SGE entry from the non-embedded DMA memory */
14773 viraddr
= mbox
->sge_array
->addr
[0];
14775 /* Set up the SGL pages in the non-embedded DMA pages */
14776 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
14777 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
14780 list_for_each_entry(psb
, sblist
, list
) {
14781 /* Set up the sge entry */
14782 sgl_pg_pairs
->sgl_pg0_addr_lo
=
14783 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
14784 sgl_pg_pairs
->sgl_pg0_addr_hi
=
14785 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
14786 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
14787 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
14789 pdma_phys_bpl1
= 0;
14790 sgl_pg_pairs
->sgl_pg1_addr_lo
=
14791 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
14792 sgl_pg_pairs
->sgl_pg1_addr_hi
=
14793 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
14794 /* Keep the first xritag on the list */
14796 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
14800 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
14801 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
14802 /* Perform endian conversion if necessary */
14803 sgl
->word0
= cpu_to_le32(sgl
->word0
);
14805 if (!phba
->sli4_hba
.intr_enable
)
14806 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14808 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14809 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14811 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
14812 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14813 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14814 if (rc
!= MBX_TIMEOUT
)
14815 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14816 if (shdr_status
|| shdr_add_status
|| rc
) {
14817 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14818 "2564 POST_SGL_BLOCK mailbox command failed "
14819 "status x%x add_status x%x mbx status x%x\n",
14820 shdr_status
, shdr_add_status
, rc
);
14827 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
14828 * @phba: pointer to lpfc_hba struct that the frame was received on
14829 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14831 * This function checks the fields in the @fc_hdr to see if the FC frame is a
14832 * valid type of frame that the LPFC driver will handle. This function will
14833 * return a zero if the frame is a valid frame or a non zero value when the
14834 * frame does not pass the check.
14837 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
14839 /* make rctl_names static to save stack space */
14840 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
14841 char *type_names
[] = FC_TYPE_NAMES_INIT
;
14842 struct fc_vft_header
*fc_vft_hdr
;
14843 uint32_t *header
= (uint32_t *) fc_hdr
;
14845 switch (fc_hdr
->fh_r_ctl
) {
14846 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
14847 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
14848 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
14849 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
14850 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
14851 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
14852 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
14853 case FC_RCTL_DD_CMD_STATUS
: /* command status */
14854 case FC_RCTL_ELS_REQ
: /* extended link services request */
14855 case FC_RCTL_ELS_REP
: /* extended link services reply */
14856 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
14857 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
14858 case FC_RCTL_BA_NOP
: /* basic link service NOP */
14859 case FC_RCTL_BA_ABTS
: /* basic link service abort */
14860 case FC_RCTL_BA_RMC
: /* remove connection */
14861 case FC_RCTL_BA_ACC
: /* basic accept */
14862 case FC_RCTL_BA_RJT
: /* basic reject */
14863 case FC_RCTL_BA_PRMT
:
14864 case FC_RCTL_ACK_1
: /* acknowledge_1 */
14865 case FC_RCTL_ACK_0
: /* acknowledge_0 */
14866 case FC_RCTL_P_RJT
: /* port reject */
14867 case FC_RCTL_F_RJT
: /* fabric reject */
14868 case FC_RCTL_P_BSY
: /* port busy */
14869 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
14870 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
14871 case FC_RCTL_LCR
: /* link credit reset */
14872 case FC_RCTL_END
: /* end */
14874 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
14875 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14876 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
14877 return lpfc_fc_frame_check(phba
, fc_hdr
);
14881 switch (fc_hdr
->fh_type
) {
14893 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14894 "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
14895 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
14896 rctl_names
[fc_hdr
->fh_r_ctl
], fc_hdr
->fh_r_ctl
,
14897 type_names
[fc_hdr
->fh_type
], fc_hdr
->fh_type
,
14898 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
14899 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
14900 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]),
14901 be32_to_cpu(header
[6]));
14904 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14905 "2539 Dropped frame rctl:%s type:%s\n",
14906 rctl_names
[fc_hdr
->fh_r_ctl
],
14907 type_names
[fc_hdr
->fh_type
]);
14912 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
14913 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14915 * This function processes the FC header to retrieve the VFI from the VF
14916 * header, if one exists. This function will return the VFI if one exists
14917 * or 0 if no VSAN Header exists.
14920 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
14922 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14924 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
14926 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
14930 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
14931 * @phba: Pointer to the HBA structure to search for the vport on
14932 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14933 * @fcfi: The FC Fabric ID that the frame came from
14935 * This function searches the @phba for a vport that matches the content of the
14936 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
14937 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
14938 * returns the matching vport pointer or NULL if unable to match frame to a
14941 static struct lpfc_vport
*
14942 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
14945 struct lpfc_vport
**vports
;
14946 struct lpfc_vport
*vport
= NULL
;
14948 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
14949 fc_hdr
->fh_d_id
[1] << 8 |
14950 fc_hdr
->fh_d_id
[2]);
14952 if (did
== Fabric_DID
)
14953 return phba
->pport
;
14954 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
14955 !(phba
->link_state
== LPFC_HBA_READY
))
14956 return phba
->pport
;
14958 vports
= lpfc_create_vport_work_array(phba
);
14959 if (vports
!= NULL
)
14960 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
14961 if (phba
->fcf
.fcfi
== fcfi
&&
14962 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
14963 vports
[i
]->fc_myDID
== did
) {
14968 lpfc_destroy_vport_work_array(phba
, vports
);
14973 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
14974 * @vport: The vport to work on.
14976 * This function updates the receive sequence time stamp for this vport. The
14977 * receive sequence time stamp indicates the time that the last frame of the
14978 * the sequence that has been idle for the longest amount of time was received.
14979 * the driver uses this time stamp to indicate if any received sequences have
14983 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
14985 struct lpfc_dmabuf
*h_buf
;
14986 struct hbq_dmabuf
*dmabuf
= NULL
;
14988 /* get the oldest sequence on the rcv list */
14989 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
14990 struct lpfc_dmabuf
, list
);
14993 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14994 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
14998 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
14999 * @vport: The vport that the received sequences were sent to.
15001 * This function cleans up all outstanding received sequences. This is called
15002 * by the driver when a link event or user action invalidates all the received
15006 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
15008 struct lpfc_dmabuf
*h_buf
, *hnext
;
15009 struct lpfc_dmabuf
*d_buf
, *dnext
;
15010 struct hbq_dmabuf
*dmabuf
= NULL
;
15012 /* start with the oldest sequence on the rcv list */
15013 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
15014 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15015 list_del_init(&dmabuf
->hbuf
.list
);
15016 list_for_each_entry_safe(d_buf
, dnext
,
15017 &dmabuf
->dbuf
.list
, list
) {
15018 list_del_init(&d_buf
->list
);
15019 lpfc_in_buf_free(vport
->phba
, d_buf
);
15021 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
15026 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
15027 * @vport: The vport that the received sequences were sent to.
15029 * This function determines whether any received sequences have timed out by
15030 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
15031 * indicates that there is at least one timed out sequence this routine will
15032 * go through the received sequences one at a time from most inactive to most
15033 * active to determine which ones need to be cleaned up. Once it has determined
15034 * that a sequence needs to be cleaned up it will simply free up the resources
15035 * without sending an abort.
15038 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
15040 struct lpfc_dmabuf
*h_buf
, *hnext
;
15041 struct lpfc_dmabuf
*d_buf
, *dnext
;
15042 struct hbq_dmabuf
*dmabuf
= NULL
;
15043 unsigned long timeout
;
15044 int abort_count
= 0;
15046 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
15047 vport
->rcv_buffer_time_stamp
);
15048 if (list_empty(&vport
->rcv_buffer_list
) ||
15049 time_before(jiffies
, timeout
))
15051 /* start with the oldest sequence on the rcv list */
15052 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
15053 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15054 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
15055 dmabuf
->time_stamp
);
15056 if (time_before(jiffies
, timeout
))
15059 list_del_init(&dmabuf
->hbuf
.list
);
15060 list_for_each_entry_safe(d_buf
, dnext
,
15061 &dmabuf
->dbuf
.list
, list
) {
15062 list_del_init(&d_buf
->list
);
15063 lpfc_in_buf_free(vport
->phba
, d_buf
);
15065 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
15068 lpfc_update_rcv_time_stamp(vport
);
15072 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
15073 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
15075 * This function searches through the existing incomplete sequences that have
15076 * been sent to this @vport. If the frame matches one of the incomplete
15077 * sequences then the dbuf in the @dmabuf is added to the list of frames that
15078 * make up that sequence. If no sequence is found that matches this frame then
15079 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
15080 * This function returns a pointer to the first dmabuf in the sequence list that
15081 * the frame was linked to.
15083 static struct hbq_dmabuf
*
15084 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
15086 struct fc_frame_header
*new_hdr
;
15087 struct fc_frame_header
*temp_hdr
;
15088 struct lpfc_dmabuf
*d_buf
;
15089 struct lpfc_dmabuf
*h_buf
;
15090 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
15091 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
15094 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
15095 dmabuf
->time_stamp
= jiffies
;
15096 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15098 /* Use the hdr_buf to find the sequence that this frame belongs to */
15099 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
15100 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
15101 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
15102 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
15103 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
15105 /* found a pending sequence that matches this frame */
15106 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15111 * This indicates first frame received for this sequence.
15112 * Queue the buffer on the vport's rcv_buffer_list.
15114 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
15115 lpfc_update_rcv_time_stamp(vport
);
15118 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
15119 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
15120 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
15121 list_del_init(&seq_dmabuf
->hbuf
.list
);
15122 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
15123 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
15124 lpfc_update_rcv_time_stamp(vport
);
15127 /* move this sequence to the tail to indicate a young sequence */
15128 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
15129 seq_dmabuf
->time_stamp
= jiffies
;
15130 lpfc_update_rcv_time_stamp(vport
);
15131 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
15132 temp_hdr
= dmabuf
->hbuf
.virt
;
15133 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
15136 /* find the correct place in the sequence to insert this frame */
15137 d_buf
= list_entry(seq_dmabuf
->dbuf
.list
.prev
, typeof(*d_buf
), list
);
15139 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15140 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
15142 * If the frame's sequence count is greater than the frame on
15143 * the list then insert the frame right after this frame
15145 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
15146 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
15147 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
15152 if (&d_buf
->list
== &seq_dmabuf
->dbuf
.list
)
15154 d_buf
= list_entry(d_buf
->list
.prev
, typeof(*d_buf
), list
);
15163 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
15164 * @vport: pointer to a vitural port
15165 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15167 * This function tries to abort from the partially assembed sequence, described
15168 * by the information from basic abbort @dmabuf. It checks to see whether such
15169 * partially assembled sequence held by the driver. If so, it shall free up all
15170 * the frames from the partially assembled sequence.
15173 * true -- if there is matching partially assembled sequence present and all
15174 * the frames freed with the sequence;
15175 * false -- if there is no matching partially assembled sequence present so
15176 * nothing got aborted in the lower layer driver
15179 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
15180 struct hbq_dmabuf
*dmabuf
)
15182 struct fc_frame_header
*new_hdr
;
15183 struct fc_frame_header
*temp_hdr
;
15184 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
15185 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
15187 /* Use the hdr_buf to find the sequence that matches this frame */
15188 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
15189 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
15190 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15191 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
15192 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
15193 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
15194 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
15195 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
15197 /* found a pending sequence that matches this frame */
15198 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15202 /* Free up all the frames from the partially assembled sequence */
15204 list_for_each_entry_safe(d_buf
, n_buf
,
15205 &seq_dmabuf
->dbuf
.list
, list
) {
15206 list_del_init(&d_buf
->list
);
15207 lpfc_in_buf_free(vport
->phba
, d_buf
);
15215 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
15216 * @vport: pointer to a vitural port
15217 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15219 * This function tries to abort from the assembed sequence from upper level
15220 * protocol, described by the information from basic abbort @dmabuf. It
15221 * checks to see whether such pending context exists at upper level protocol.
15222 * If so, it shall clean up the pending context.
15225 * true -- if there is matching pending context of the sequence cleaned
15227 * false -- if there is no matching pending context of the sequence present
15231 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
15233 struct lpfc_hba
*phba
= vport
->phba
;
15236 /* Accepting abort at ulp with SLI4 only */
15237 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15240 /* Register all caring upper level protocols to attend abort */
15241 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
15249 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
15250 * @phba: Pointer to HBA context object.
15251 * @cmd_iocbq: pointer to the command iocbq structure.
15252 * @rsp_iocbq: pointer to the response iocbq structure.
15254 * This function handles the sequence abort response iocb command complete
15255 * event. It properly releases the memory allocated to the sequence abort
15259 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
15260 struct lpfc_iocbq
*cmd_iocbq
,
15261 struct lpfc_iocbq
*rsp_iocbq
)
15263 struct lpfc_nodelist
*ndlp
;
15266 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
15267 lpfc_nlp_put(ndlp
);
15268 lpfc_nlp_not_used(ndlp
);
15269 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
15272 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
15273 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
15274 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15275 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
15276 rsp_iocbq
->iocb
.ulpStatus
,
15277 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
15281 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
15282 * @phba: Pointer to HBA context object.
15283 * @xri: xri id in transaction.
15285 * This function validates the xri maps to the known range of XRIs allocated an
15286 * used by the driver.
15289 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
15294 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
15295 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
15302 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
15303 * @phba: Pointer to HBA context object.
15304 * @fc_hdr: pointer to a FC frame header.
15306 * This function sends a basic response to a previous unsol sequence abort
15307 * event after aborting the sequence handling.
15310 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
15311 struct fc_frame_header
*fc_hdr
, bool aborted
)
15313 struct lpfc_hba
*phba
= vport
->phba
;
15314 struct lpfc_iocbq
*ctiocb
= NULL
;
15315 struct lpfc_nodelist
*ndlp
;
15316 uint16_t oxid
, rxid
, xri
, lxri
;
15317 uint32_t sid
, fctl
;
15321 if (!lpfc_is_link_up(phba
))
15324 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
15325 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
15326 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
15328 ndlp
= lpfc_findnode_did(vport
, sid
);
15330 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
15332 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
15333 "1268 Failed to allocate ndlp for "
15334 "oxid:x%x SID:x%x\n", oxid
, sid
);
15337 lpfc_nlp_init(vport
, ndlp
, sid
);
15338 /* Put ndlp onto pport node list */
15339 lpfc_enqueue_node(vport
, ndlp
);
15340 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
15341 /* re-setup ndlp without removing from node list */
15342 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
15344 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
15345 "3275 Failed to active ndlp found "
15346 "for oxid:x%x SID:x%x\n", oxid
, sid
);
15351 /* Allocate buffer for rsp iocb */
15352 ctiocb
= lpfc_sli_get_iocbq(phba
);
15356 /* Extract the F_CTL field from FC_HDR */
15357 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
15359 icmd
= &ctiocb
->iocb
;
15360 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
15361 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
15362 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
15363 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
15364 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
15366 /* Fill in the rest of iocb fields */
15367 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
15368 icmd
->ulpBdeCount
= 0;
15370 icmd
->ulpClass
= CLASS3
;
15371 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
15372 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
15374 ctiocb
->iocb_cmpl
= NULL
;
15375 ctiocb
->vport
= phba
->pport
;
15376 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
15377 ctiocb
->sli4_lxritag
= NO_XRI
;
15378 ctiocb
->sli4_xritag
= NO_XRI
;
15380 if (fctl
& FC_FC_EX_CTX
)
15381 /* Exchange responder sent the abort so we
15387 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
15388 if (lxri
!= NO_XRI
)
15389 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
15390 (xri
== oxid
) ? rxid
: oxid
, 0);
15391 /* For BA_ABTS from exchange responder, if the logical xri with
15392 * the oxid maps to the FCP XRI range, the port no longer has
15393 * that exchange context, send a BLS_RJT. Override the IOCB for
15396 if ((fctl
& FC_FC_EX_CTX
) &&
15397 (lxri
> lpfc_sli4_get_els_iocb_cnt(phba
))) {
15398 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
15399 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
15400 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
15401 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
15404 /* If BA_ABTS failed to abort a partially assembled receive sequence,
15405 * the driver no longer has that exchange, send a BLS_RJT. Override
15406 * the IOCB for a BA_RJT.
15408 if (aborted
== false) {
15409 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
15410 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
15411 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
15412 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
15415 if (fctl
& FC_FC_EX_CTX
) {
15416 /* ABTS sent by responder to CT exchange, construction
15417 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
15418 * field and RX_ID from ABTS for RX_ID field.
15420 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
15422 /* ABTS sent by initiator to CT exchange, construction
15423 * of BA_ACC will need to allocate a new XRI as for the
15426 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
15428 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
15429 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
15431 /* Xmit CT abts response on exchange <xid> */
15432 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
15433 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
15434 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
15436 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
15437 if (rc
== IOCB_ERROR
) {
15438 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
15439 "2925 Failed to issue CT ABTS RSP x%x on "
15440 "xri x%x, Data x%x\n",
15441 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
15443 lpfc_nlp_put(ndlp
);
15444 ctiocb
->context1
= NULL
;
15445 lpfc_sli_release_iocbq(phba
, ctiocb
);
15450 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
15451 * @vport: Pointer to the vport on which this sequence was received
15452 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15454 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
15455 * receive sequence is only partially assembed by the driver, it shall abort
15456 * the partially assembled frames for the sequence. Otherwise, if the
15457 * unsolicited receive sequence has been completely assembled and passed to
15458 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
15459 * unsolicited sequence has been aborted. After that, it will issue a basic
15460 * accept to accept the abort.
15463 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
15464 struct hbq_dmabuf
*dmabuf
)
15466 struct lpfc_hba
*phba
= vport
->phba
;
15467 struct fc_frame_header fc_hdr
;
15471 /* Make a copy of fc_hdr before the dmabuf being released */
15472 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
15473 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
15475 if (fctl
& FC_FC_EX_CTX
) {
15476 /* ABTS by responder to exchange, no cleanup needed */
15479 /* ABTS by initiator to exchange, need to do cleanup */
15480 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
15481 if (aborted
== false)
15482 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
15484 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15486 /* Respond with BA_ACC or BA_RJT accordingly */
15487 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
15491 * lpfc_seq_complete - Indicates if a sequence is complete
15492 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15494 * This function checks the sequence, starting with the frame described by
15495 * @dmabuf, to see if all the frames associated with this sequence are present.
15496 * the frames associated with this sequence are linked to the @dmabuf using the
15497 * dbuf list. This function looks for two major things. 1) That the first frame
15498 * has a sequence count of zero. 2) There is a frame with last frame of sequence
15499 * set. 3) That there are no holes in the sequence count. The function will
15500 * return 1 when the sequence is complete, otherwise it will return 0.
15503 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
15505 struct fc_frame_header
*hdr
;
15506 struct lpfc_dmabuf
*d_buf
;
15507 struct hbq_dmabuf
*seq_dmabuf
;
15511 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15512 /* make sure first fame of sequence has a sequence count of zero */
15513 if (hdr
->fh_seq_cnt
!= seq_count
)
15515 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
15516 hdr
->fh_f_ctl
[1] << 8 |
15518 /* If last frame of sequence we can return success. */
15519 if (fctl
& FC_FC_END_SEQ
)
15521 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
15522 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15523 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15524 /* If there is a hole in the sequence count then fail. */
15525 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
15527 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
15528 hdr
->fh_f_ctl
[1] << 8 |
15530 /* If last frame of sequence we can return success. */
15531 if (fctl
& FC_FC_END_SEQ
)
15538 * lpfc_prep_seq - Prep sequence for ULP processing
15539 * @vport: Pointer to the vport on which this sequence was received
15540 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15542 * This function takes a sequence, described by a list of frames, and creates
15543 * a list of iocbq structures to describe the sequence. This iocbq list will be
15544 * used to issue to the generic unsolicited sequence handler. This routine
15545 * returns a pointer to the first iocbq in the list. If the function is unable
15546 * to allocate an iocbq then it throw out the received frames that were not
15547 * able to be described and return a pointer to the first iocbq. If unable to
15548 * allocate any iocbqs (including the first) this function will return NULL.
15550 static struct lpfc_iocbq
*
15551 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
15553 struct hbq_dmabuf
*hbq_buf
;
15554 struct lpfc_dmabuf
*d_buf
, *n_buf
;
15555 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
15556 struct fc_frame_header
*fc_hdr
;
15558 uint32_t len
, tot_len
;
15559 struct ulp_bde64
*pbde
;
15561 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15562 /* remove from receive buffer list */
15563 list_del_init(&seq_dmabuf
->hbuf
.list
);
15564 lpfc_update_rcv_time_stamp(vport
);
15565 /* get the Remote Port's SID */
15566 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
15568 /* Get an iocbq struct to fill in. */
15569 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
15571 /* Initialize the first IOCB. */
15572 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
15573 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
15575 /* Check FC Header to see what TYPE of frame we are rcv'ing */
15576 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
15577 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
15578 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
15579 sli4_did_from_fc_hdr(fc_hdr
);
15580 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
15582 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
15583 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
15584 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
15585 be16_to_cpu(fc_hdr
->fh_ox_id
);
15586 /* iocbq is prepped for internal consumption. Physical vpi. */
15587 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
15588 vport
->phba
->vpi_ids
[vport
->vpi
];
15589 /* put the first buffer into the first IOCBq */
15590 tot_len
= bf_get(lpfc_rcqe_length
,
15591 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15593 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
15594 first_iocbq
->context3
= NULL
;
15595 first_iocbq
->iocb
.ulpBdeCount
= 1;
15596 if (tot_len
> LPFC_DATA_BUF_SIZE
)
15597 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
15598 LPFC_DATA_BUF_SIZE
;
15600 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= tot_len
;
15602 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
15604 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
15606 iocbq
= first_iocbq
;
15608 * Each IOCBq can have two Buffers assigned, so go through the list
15609 * of buffers for this sequence and save two buffers in each IOCBq
15611 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
15613 lpfc_in_buf_free(vport
->phba
, d_buf
);
15616 if (!iocbq
->context3
) {
15617 iocbq
->context3
= d_buf
;
15618 iocbq
->iocb
.ulpBdeCount
++;
15619 /* We need to get the size out of the right CQE */
15620 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15621 len
= bf_get(lpfc_rcqe_length
,
15622 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
15623 pbde
= (struct ulp_bde64
*)
15624 &iocbq
->iocb
.unsli3
.sli3Words
[4];
15625 if (len
> LPFC_DATA_BUF_SIZE
)
15626 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
15628 pbde
->tus
.f
.bdeSize
= len
;
15630 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
15633 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
15636 first_iocbq
->iocb
.ulpStatus
=
15637 IOSTAT_FCP_RSP_ERROR
;
15638 first_iocbq
->iocb
.un
.ulpWord
[4] =
15639 IOERR_NO_RESOURCES
;
15641 lpfc_in_buf_free(vport
->phba
, d_buf
);
15644 /* We need to get the size out of the right CQE */
15645 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15646 len
= bf_get(lpfc_rcqe_length
,
15647 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
15648 iocbq
->context2
= d_buf
;
15649 iocbq
->context3
= NULL
;
15650 iocbq
->iocb
.ulpBdeCount
= 1;
15651 if (len
> LPFC_DATA_BUF_SIZE
)
15652 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
15653 LPFC_DATA_BUF_SIZE
;
15655 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= len
;
15658 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
15660 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
15661 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
15664 return first_iocbq
;
15668 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
15669 struct hbq_dmabuf
*seq_dmabuf
)
15671 struct fc_frame_header
*fc_hdr
;
15672 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
15673 struct lpfc_hba
*phba
= vport
->phba
;
15675 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15676 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
15678 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15679 "2707 Ring %d handler: Failed to allocate "
15680 "iocb Rctl x%x Type x%x received\n",
15682 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
15685 if (!lpfc_complete_unsol_iocb(phba
,
15686 &phba
->sli
.ring
[LPFC_ELS_RING
],
15687 iocbq
, fc_hdr
->fh_r_ctl
,
15689 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15690 "2540 Ring %d handler: unexpected Rctl "
15691 "x%x Type x%x received\n",
15693 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
15695 /* Free iocb created in lpfc_prep_seq */
15696 list_for_each_entry_safe(curr_iocb
, next_iocb
,
15697 &iocbq
->list
, list
) {
15698 list_del_init(&curr_iocb
->list
);
15699 lpfc_sli_release_iocbq(phba
, curr_iocb
);
15701 lpfc_sli_release_iocbq(phba
, iocbq
);
15705 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
15706 * @phba: Pointer to HBA context object.
15708 * This function is called with no lock held. This function processes all
15709 * the received buffers and gives it to upper layers when a received buffer
15710 * indicates that it is the final frame in the sequence. The interrupt
15711 * service routine processes received buffers at interrupt contexts and adds
15712 * received dma buffers to the rb_pend_list queue and signals the worker thread.
15713 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
15714 * appropriate receive function when the final frame in a sequence is received.
15717 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
15718 struct hbq_dmabuf
*dmabuf
)
15720 struct hbq_dmabuf
*seq_dmabuf
;
15721 struct fc_frame_header
*fc_hdr
;
15722 struct lpfc_vport
*vport
;
15726 /* Process each received buffer */
15727 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15728 /* check to see if this a valid type of frame */
15729 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
15730 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15733 if ((bf_get(lpfc_cqe_code
,
15734 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
15735 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
15736 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15738 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
15739 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15741 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
15743 /* throw out the frame */
15744 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15748 /* d_id this frame is directed to */
15749 did
= sli4_did_from_fc_hdr(fc_hdr
);
15751 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
15752 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
15753 (did
!= Fabric_DID
)) {
15755 * Throw out the frame if we are not pt2pt.
15756 * The pt2pt protocol allows for discovery frames
15757 * to be received without a registered VPI.
15759 if (!(vport
->fc_flag
& FC_PT2PT
) ||
15760 (phba
->link_state
== LPFC_HBA_READY
)) {
15761 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15766 /* Handle the basic abort sequence (BA_ABTS) event */
15767 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
15768 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
15772 /* Link this frame */
15773 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
15775 /* unable to add frame to vport - throw it out */
15776 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15779 /* If not last frame in sequence continue processing frames. */
15780 if (!lpfc_seq_complete(seq_dmabuf
))
15783 /* Send the complete sequence to the upper layer protocol */
15784 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
15788 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
15789 * @phba: pointer to lpfc hba data structure.
15791 * This routine is invoked to post rpi header templates to the
15792 * HBA consistent with the SLI-4 interface spec. This routine
15793 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15794 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15796 * This routine does not require any locks. It's usage is expected
15797 * to be driver load or reset recovery when the driver is
15802 * -EIO - The mailbox failed to complete successfully.
15803 * When this error occurs, the driver is not guaranteed
15804 * to have any rpi regions posted to the device and
15805 * must either attempt to repost the regions or take a
15809 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
15811 struct lpfc_rpi_hdr
*rpi_page
;
15815 /* SLI4 ports that support extents do not require RPI headers. */
15816 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
15818 if (phba
->sli4_hba
.extents_in_use
)
15821 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
15823 * Assign the rpi headers a physical rpi only if the driver
15824 * has not initialized those resources. A port reset only
15825 * needs the headers posted.
15827 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
15829 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15831 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
15832 if (rc
!= MBX_SUCCESS
) {
15833 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15834 "2008 Error %d posting all rpi "
15842 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
15843 LPFC_RPI_RSRC_RDY
);
15848 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
15849 * @phba: pointer to lpfc hba data structure.
15850 * @rpi_page: pointer to the rpi memory region.
15852 * This routine is invoked to post a single rpi header to the
15853 * HBA consistent with the SLI-4 interface spec. This memory region
15854 * maps up to 64 rpi context regions.
15858 * -ENOMEM - No available memory
15859 * -EIO - The mailbox failed to complete successfully.
15862 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
15864 LPFC_MBOXQ_t
*mboxq
;
15865 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
15867 uint32_t shdr_status
, shdr_add_status
;
15868 union lpfc_sli4_cfg_shdr
*shdr
;
15870 /* SLI4 ports that support extents do not require RPI headers. */
15871 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
15873 if (phba
->sli4_hba
.extents_in_use
)
15876 /* The port is notified of the header region via a mailbox command. */
15877 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15879 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15880 "2001 Unable to allocate memory for issuing "
15881 "SLI_CONFIG_SPECIAL mailbox command\n");
15885 /* Post all rpi memory regions to the port. */
15886 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
15887 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15888 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
15889 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
15890 sizeof(struct lpfc_sli4_cfg_mhdr
),
15891 LPFC_SLI4_MBX_EMBED
);
15894 /* Post the physical rpi to the port for this rpi header. */
15895 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
15896 rpi_page
->start_rpi
);
15897 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
15898 hdr_tmpl
, rpi_page
->page_count
);
15900 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
15901 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
15902 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15903 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
15904 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15905 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15906 if (rc
!= MBX_TIMEOUT
)
15907 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15908 if (shdr_status
|| shdr_add_status
|| rc
) {
15909 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15910 "2514 POST_RPI_HDR mailbox failed with "
15911 "status x%x add_status x%x, mbx status x%x\n",
15912 shdr_status
, shdr_add_status
, rc
);
15919 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
15920 * @phba: pointer to lpfc hba data structure.
15922 * This routine is invoked to post rpi header templates to the
15923 * HBA consistent with the SLI-4 interface spec. This routine
15924 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15925 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15928 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
15929 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15932 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
15935 uint16_t max_rpi
, rpi_limit
;
15936 uint16_t rpi_remaining
, lrpi
= 0;
15937 struct lpfc_rpi_hdr
*rpi_hdr
;
15938 unsigned long iflag
;
15941 * Fetch the next logical rpi. Because this index is logical,
15942 * the driver starts at 0 each time.
15944 spin_lock_irqsave(&phba
->hbalock
, iflag
);
15945 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
15946 rpi_limit
= phba
->sli4_hba
.next_rpi
;
15948 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
15949 if (rpi
>= rpi_limit
)
15950 rpi
= LPFC_RPI_ALLOC_ERROR
;
15952 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
15953 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
15954 phba
->sli4_hba
.rpi_count
++;
15956 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
15957 "0001 rpi:%x max:%x lim:%x\n",
15958 (int) rpi
, max_rpi
, rpi_limit
);
15961 * Don't try to allocate more rpi header regions if the device limit
15962 * has been exhausted.
15964 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
15965 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
15966 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15971 * RPI header postings are not required for SLI4 ports capable of
15974 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
15975 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15980 * If the driver is running low on rpi resources, allocate another
15981 * page now. Note that the next_rpi value is used because
15982 * it represents how many are actually in use whereas max_rpi notes
15983 * how many are supported max by the device.
15985 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
15986 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15987 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
15988 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
15990 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15991 "2002 Error Could not grow rpi "
15994 lrpi
= rpi_hdr
->start_rpi
;
15995 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15996 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
16004 * lpfc_sli4_free_rpi - Release an rpi for reuse.
16005 * @phba: pointer to lpfc hba data structure.
16007 * This routine is invoked to release an rpi to the pool of
16008 * available rpis maintained by the driver.
16011 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
16013 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
16014 phba
->sli4_hba
.rpi_count
--;
16015 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
16020 * lpfc_sli4_free_rpi - Release an rpi for reuse.
16021 * @phba: pointer to lpfc hba data structure.
16023 * This routine is invoked to release an rpi to the pool of
16024 * available rpis maintained by the driver.
16027 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
16029 spin_lock_irq(&phba
->hbalock
);
16030 __lpfc_sli4_free_rpi(phba
, rpi
);
16031 spin_unlock_irq(&phba
->hbalock
);
16035 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
16036 * @phba: pointer to lpfc hba data structure.
16038 * This routine is invoked to remove the memory region that
16039 * provided rpi via a bitmask.
16042 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
16044 kfree(phba
->sli4_hba
.rpi_bmask
);
16045 kfree(phba
->sli4_hba
.rpi_ids
);
16046 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
16050 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
16051 * @phba: pointer to lpfc hba data structure.
16053 * This routine is invoked to remove the memory region that
16054 * provided rpi via a bitmask.
16057 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
16058 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
16060 LPFC_MBOXQ_t
*mboxq
;
16061 struct lpfc_hba
*phba
= ndlp
->phba
;
16064 /* The port is notified of the header region via a mailbox command. */
16065 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16069 /* Post all rpi memory regions to the port. */
16070 lpfc_resume_rpi(mboxq
, ndlp
);
16072 mboxq
->mbox_cmpl
= cmpl
;
16073 mboxq
->context1
= arg
;
16074 mboxq
->context2
= ndlp
;
16076 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16077 mboxq
->vport
= ndlp
->vport
;
16078 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16079 if (rc
== MBX_NOT_FINISHED
) {
16080 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16081 "2010 Resume RPI Mailbox failed "
16082 "status %d, mbxStatus x%x\n", rc
,
16083 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
16084 mempool_free(mboxq
, phba
->mbox_mem_pool
);
16091 * lpfc_sli4_init_vpi - Initialize a vpi with the port
16092 * @vport: Pointer to the vport for which the vpi is being initialized
16094 * This routine is invoked to activate a vpi with the port.
16098 * -Evalue otherwise
16101 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
16103 LPFC_MBOXQ_t
*mboxq
;
16105 int retval
= MBX_SUCCESS
;
16107 struct lpfc_hba
*phba
= vport
->phba
;
16108 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16111 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
16112 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
16113 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
16114 if (rc
!= MBX_SUCCESS
) {
16115 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
16116 "2022 INIT VPI Mailbox failed "
16117 "status %d, mbxStatus x%x\n", rc
,
16118 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
16121 if (rc
!= MBX_TIMEOUT
)
16122 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
16128 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
16129 * @phba: pointer to lpfc hba data structure.
16130 * @mboxq: Pointer to mailbox object.
16132 * This routine is invoked to manually add a single FCF record. The caller
16133 * must pass a completely initialized FCF_Record. This routine takes
16134 * care of the nonembedded mailbox operations.
16137 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
16140 union lpfc_sli4_cfg_shdr
*shdr
;
16141 uint32_t shdr_status
, shdr_add_status
;
16143 virt_addr
= mboxq
->sge_array
->addr
[0];
16144 /* The IOCTL status is embedded in the mailbox subheader. */
16145 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
16146 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16147 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16149 if ((shdr_status
|| shdr_add_status
) &&
16150 (shdr_status
!= STATUS_FCF_IN_USE
))
16151 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16152 "2558 ADD_FCF_RECORD mailbox failed with "
16153 "status x%x add_status x%x\n",
16154 shdr_status
, shdr_add_status
);
16156 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16160 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
16161 * @phba: pointer to lpfc hba data structure.
16162 * @fcf_record: pointer to the initialized fcf record to add.
16164 * This routine is invoked to manually add a single FCF record. The caller
16165 * must pass a completely initialized FCF_Record. This routine takes
16166 * care of the nonembedded mailbox operations.
16169 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
16172 LPFC_MBOXQ_t
*mboxq
;
16175 struct lpfc_mbx_sge sge
;
16176 uint32_t alloc_len
, req_len
;
16179 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16181 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16182 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
16186 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
16189 /* Allocate DMA memory and set up the non-embedded mailbox command */
16190 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16191 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
16192 req_len
, LPFC_SLI4_MBX_NEMBED
);
16193 if (alloc_len
< req_len
) {
16194 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16195 "2523 Allocated DMA memory size (x%x) is "
16196 "less than the requested DMA memory "
16197 "size (x%x)\n", alloc_len
, req_len
);
16198 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16203 * Get the first SGE entry from the non-embedded DMA memory. This
16204 * routine only uses a single SGE.
16206 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
16207 virt_addr
= mboxq
->sge_array
->addr
[0];
16209 * Configure the FCF record for FCFI 0. This is the driver's
16210 * hardcoded default and gets used in nonFIP mode.
16212 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
16213 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
16214 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
16217 * Copy the fcf_index and the FCF Record Data. The data starts after
16218 * the FCoE header plus word10. The data copy needs to be endian
16221 bytep
+= sizeof(uint32_t);
16222 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
16223 mboxq
->vport
= phba
->pport
;
16224 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
16225 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16226 if (rc
== MBX_NOT_FINISHED
) {
16227 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16228 "2515 ADD_FCF_RECORD mailbox failed with "
16229 "status 0x%x\n", rc
);
16230 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16239 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
16240 * @phba: pointer to lpfc hba data structure.
16241 * @fcf_record: pointer to the fcf record to write the default data.
16242 * @fcf_index: FCF table entry index.
16244 * This routine is invoked to build the driver's default FCF record. The
16245 * values used are hardcoded. This routine handles memory initialization.
16249 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
16250 struct fcf_record
*fcf_record
,
16251 uint16_t fcf_index
)
16253 memset(fcf_record
, 0, sizeof(struct fcf_record
));
16254 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
16255 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
16256 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
16257 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
16258 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
16259 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
16260 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
16261 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
16262 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
16263 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
16264 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
16265 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
16266 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
16267 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
16268 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
16269 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
16270 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
16271 /* Set the VLAN bit map */
16272 if (phba
->valid_vlan
) {
16273 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
16274 = 1 << (phba
->vlan_id
% 8);
16279 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
16280 * @phba: pointer to lpfc hba data structure.
16281 * @fcf_index: FCF table entry offset.
16283 * This routine is invoked to scan the entire FCF table by reading FCF
16284 * record and processing it one at a time starting from the @fcf_index
16285 * for initial FCF discovery or fast FCF failover rediscovery.
16287 * Return 0 if the mailbox command is submitted successfully, none 0
16291 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16294 LPFC_MBOXQ_t
*mboxq
;
16296 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
16297 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
16298 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16300 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16301 "2000 Failed to allocate mbox for "
16304 goto fail_fcf_scan
;
16306 /* Construct the read FCF record mailbox command */
16307 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
16310 goto fail_fcf_scan
;
16312 /* Issue the mailbox command asynchronously */
16313 mboxq
->vport
= phba
->pport
;
16314 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
16316 spin_lock_irq(&phba
->hbalock
);
16317 phba
->hba_flag
|= FCF_TS_INPROG
;
16318 spin_unlock_irq(&phba
->hbalock
);
16320 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16321 if (rc
== MBX_NOT_FINISHED
)
16324 /* Reset eligible FCF count for new scan */
16325 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
16326 phba
->fcf
.eligible_fcf_cnt
= 0;
16332 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16333 /* FCF scan failed, clear FCF_TS_INPROG flag */
16334 spin_lock_irq(&phba
->hbalock
);
16335 phba
->hba_flag
&= ~FCF_TS_INPROG
;
16336 spin_unlock_irq(&phba
->hbalock
);
16342 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
16343 * @phba: pointer to lpfc hba data structure.
16344 * @fcf_index: FCF table entry offset.
16346 * This routine is invoked to read an FCF record indicated by @fcf_index
16347 * and to use it for FLOGI roundrobin FCF failover.
16349 * Return 0 if the mailbox command is submitted successfully, none 0
16353 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16356 LPFC_MBOXQ_t
*mboxq
;
16358 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16360 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
16361 "2763 Failed to allocate mbox for "
16364 goto fail_fcf_read
;
16366 /* Construct the read FCF record mailbox command */
16367 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
16370 goto fail_fcf_read
;
16372 /* Issue the mailbox command asynchronously */
16373 mboxq
->vport
= phba
->pport
;
16374 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
16375 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16376 if (rc
== MBX_NOT_FINISHED
)
16382 if (error
&& mboxq
)
16383 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16388 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
16389 * @phba: pointer to lpfc hba data structure.
16390 * @fcf_index: FCF table entry offset.
16392 * This routine is invoked to read an FCF record indicated by @fcf_index to
16393 * determine whether it's eligible for FLOGI roundrobin failover list.
16395 * Return 0 if the mailbox command is submitted successfully, none 0
16399 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16402 LPFC_MBOXQ_t
*mboxq
;
16404 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16406 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
16407 "2758 Failed to allocate mbox for "
16410 goto fail_fcf_read
;
16412 /* Construct the read FCF record mailbox command */
16413 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
16416 goto fail_fcf_read
;
16418 /* Issue the mailbox command asynchronously */
16419 mboxq
->vport
= phba
->pport
;
16420 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
16421 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16422 if (rc
== MBX_NOT_FINISHED
)
16428 if (error
&& mboxq
)
16429 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16434 * lpfc_check_next_fcf_pri_level
16435 * phba pointer to the lpfc_hba struct for this port.
16436 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
16437 * routine when the rr_bmask is empty. The FCF indecies are put into the
16438 * rr_bmask based on their priority level. Starting from the highest priority
16439 * to the lowest. The most likely FCF candidate will be in the highest
16440 * priority group. When this routine is called it searches the fcf_pri list for
16441 * next lowest priority group and repopulates the rr_bmask with only those
16444 * 1=success 0=failure
16447 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
16449 uint16_t next_fcf_pri
;
16450 uint16_t last_index
;
16451 struct lpfc_fcf_pri
*fcf_pri
;
16455 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
16456 LPFC_SLI4_FCF_TBL_INDX_MAX
);
16457 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16458 "3060 Last IDX %d\n", last_index
);
16460 /* Verify the priority list has 2 or more entries */
16461 spin_lock_irq(&phba
->hbalock
);
16462 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
16463 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
16464 spin_unlock_irq(&phba
->hbalock
);
16465 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16466 "3061 Last IDX %d\n", last_index
);
16467 return 0; /* Empty rr list */
16469 spin_unlock_irq(&phba
->hbalock
);
16473 * Clear the rr_bmask and set all of the bits that are at this
16476 memset(phba
->fcf
.fcf_rr_bmask
, 0,
16477 sizeof(*phba
->fcf
.fcf_rr_bmask
));
16478 spin_lock_irq(&phba
->hbalock
);
16479 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
16480 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
16483 * the 1st priority that has not FLOGI failed
16484 * will be the highest.
16487 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
16488 spin_unlock_irq(&phba
->hbalock
);
16489 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
16490 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
16491 fcf_pri
->fcf_rec
.fcf_index
);
16495 spin_lock_irq(&phba
->hbalock
);
16498 * if next_fcf_pri was not set above and the list is not empty then
16499 * we have failed flogis on all of them. So reset flogi failed
16500 * and start at the beginning.
16502 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
16503 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
16504 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
16506 * the 1st priority that has not FLOGI failed
16507 * will be the highest.
16510 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
16511 spin_unlock_irq(&phba
->hbalock
);
16512 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
16513 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
16514 fcf_pri
->fcf_rec
.fcf_index
);
16518 spin_lock_irq(&phba
->hbalock
);
16522 spin_unlock_irq(&phba
->hbalock
);
16527 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
16528 * @phba: pointer to lpfc hba data structure.
16530 * This routine is to get the next eligible FCF record index in a round
16531 * robin fashion. If the next eligible FCF record index equals to the
16532 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
16533 * shall be returned, otherwise, the next eligible FCF record's index
16534 * shall be returned.
16537 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
16539 uint16_t next_fcf_index
;
16542 /* Search start from next bit of currently registered FCF index */
16543 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
16546 /* Determine the next fcf index to check */
16547 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
16548 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
16549 LPFC_SLI4_FCF_TBL_INDX_MAX
,
16552 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
16553 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
16555 * If we have wrapped then we need to clear the bits that
16556 * have been tested so that we can detect when we should
16557 * change the priority level.
16559 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
16560 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
16564 /* Check roundrobin failover list empty condition */
16565 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
16566 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
16568 * If next fcf index is not found check if there are lower
16569 * Priority level fcf's in the fcf_priority list.
16570 * Set up the rr_bmask with all of the avaiable fcf bits
16571 * at that level and continue the selection process.
16573 if (lpfc_check_next_fcf_pri_level(phba
))
16574 goto initial_priority
;
16575 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
16576 "2844 No roundrobin failover FCF available\n");
16577 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
16578 return LPFC_FCOE_FCF_NEXT_NONE
;
16580 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
16581 "3063 Only FCF available idx %d, flag %x\n",
16583 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
16584 return next_fcf_index
;
16588 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
16589 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
16590 LPFC_FCF_FLOGI_FAILED
) {
16591 if (list_is_singular(&phba
->fcf
.fcf_pri_list
))
16592 return LPFC_FCOE_FCF_NEXT_NONE
;
16594 goto next_priority
;
16597 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16598 "2845 Get next roundrobin failover FCF (x%x)\n",
16601 return next_fcf_index
;
16605 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
16606 * @phba: pointer to lpfc hba data structure.
16608 * This routine sets the FCF record index in to the eligible bmask for
16609 * roundrobin failover search. It checks to make sure that the index
16610 * does not go beyond the range of the driver allocated bmask dimension
16611 * before setting the bit.
16613 * Returns 0 if the index bit successfully set, otherwise, it returns
16617 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16619 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
16620 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16621 "2610 FCF (x%x) reached driver's book "
16622 "keeping dimension:x%x\n",
16623 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
16626 /* Set the eligible FCF record index bmask */
16627 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
16629 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16630 "2790 Set FCF (x%x) to roundrobin FCF failover "
16631 "bmask\n", fcf_index
);
16637 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
16638 * @phba: pointer to lpfc hba data structure.
16640 * This routine clears the FCF record index from the eligible bmask for
16641 * roundrobin failover search. It checks to make sure that the index
16642 * does not go beyond the range of the driver allocated bmask dimension
16643 * before clearing the bit.
16646 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16648 struct lpfc_fcf_pri
*fcf_pri
, *fcf_pri_next
;
16649 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
16650 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16651 "2762 FCF (x%x) reached driver's book "
16652 "keeping dimension:x%x\n",
16653 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
16656 /* Clear the eligible FCF record index bmask */
16657 spin_lock_irq(&phba
->hbalock
);
16658 list_for_each_entry_safe(fcf_pri
, fcf_pri_next
, &phba
->fcf
.fcf_pri_list
,
16660 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
16661 list_del_init(&fcf_pri
->list
);
16665 spin_unlock_irq(&phba
->hbalock
);
16666 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
16668 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16669 "2791 Clear FCF (x%x) from roundrobin failover "
16670 "bmask\n", fcf_index
);
16674 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
16675 * @phba: pointer to lpfc hba data structure.
16677 * This routine is the completion routine for the rediscover FCF table mailbox
16678 * command. If the mailbox command returned failure, it will try to stop the
16679 * FCF rediscover wait timer.
16682 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
16684 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
16685 uint32_t shdr_status
, shdr_add_status
;
16687 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
16689 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
16690 &redisc_fcf
->header
.cfg_shdr
.response
);
16691 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
16692 &redisc_fcf
->header
.cfg_shdr
.response
);
16693 if (shdr_status
|| shdr_add_status
) {
16694 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16695 "2746 Requesting for FCF rediscovery failed "
16696 "status x%x add_status x%x\n",
16697 shdr_status
, shdr_add_status
);
16698 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
16699 spin_lock_irq(&phba
->hbalock
);
16700 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
16701 spin_unlock_irq(&phba
->hbalock
);
16703 * CVL event triggered FCF rediscover request failed,
16704 * last resort to re-try current registered FCF entry.
16706 lpfc_retry_pport_discovery(phba
);
16708 spin_lock_irq(&phba
->hbalock
);
16709 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
16710 spin_unlock_irq(&phba
->hbalock
);
16712 * DEAD FCF event triggered FCF rediscover request
16713 * failed, last resort to fail over as a link down
16714 * to FCF registration.
16716 lpfc_sli4_fcf_dead_failthrough(phba
);
16719 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16720 "2775 Start FCF rediscover quiescent timer\n");
16722 * Start FCF rediscovery wait timer for pending FCF
16723 * before rescan FCF record table.
16725 lpfc_fcf_redisc_wait_start_timer(phba
);
16728 mempool_free(mbox
, phba
->mbox_mem_pool
);
16732 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
16733 * @phba: pointer to lpfc hba data structure.
16735 * This routine is invoked to request for rediscovery of the entire FCF table
16739 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
16741 LPFC_MBOXQ_t
*mbox
;
16742 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
16745 /* Cancel retry delay timers to all vports before FCF rediscover */
16746 lpfc_cancel_all_vport_retry_delay_timer(phba
);
16748 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16750 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16751 "2745 Failed to allocate mbox for "
16752 "requesting FCF rediscover.\n");
16756 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
16757 sizeof(struct lpfc_sli4_cfg_mhdr
));
16758 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16759 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
16760 length
, LPFC_SLI4_MBX_EMBED
);
16762 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
16763 /* Set count to 0 for invalidating the entire FCF database */
16764 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
16766 /* Issue the mailbox command asynchronously */
16767 mbox
->vport
= phba
->pport
;
16768 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
16769 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
16771 if (rc
== MBX_NOT_FINISHED
) {
16772 mempool_free(mbox
, phba
->mbox_mem_pool
);
16779 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
16780 * @phba: pointer to lpfc hba data structure.
16782 * This function is the failover routine as a last resort to the FCF DEAD
16783 * event when driver failed to perform fast FCF failover.
16786 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
16788 uint32_t link_state
;
16791 * Last resort as FCF DEAD event failover will treat this as
16792 * a link down, but save the link state because we don't want
16793 * it to be changed to Link Down unless it is already down.
16795 link_state
= phba
->link_state
;
16796 lpfc_linkdown(phba
);
16797 phba
->link_state
= link_state
;
16799 /* Unregister FCF if no devices connected to it */
16800 lpfc_unregister_unused_fcf(phba
);
16804 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
16805 * @phba: pointer to lpfc hba data structure.
16806 * @rgn23_data: pointer to configure region 23 data.
16808 * This function gets SLI3 port configure region 23 data through memory dump
16809 * mailbox command. When it successfully retrieves data, the size of the data
16810 * will be returned, otherwise, 0 will be returned.
16813 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
16815 LPFC_MBOXQ_t
*pmb
= NULL
;
16817 uint32_t offset
= 0;
16823 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16825 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16826 "2600 failed to allocate mailbox memory\n");
16832 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
16833 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
16835 if (rc
!= MBX_SUCCESS
) {
16836 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
16837 "2601 failed to read config "
16838 "region 23, rc 0x%x Status 0x%x\n",
16839 rc
, mb
->mbxStatus
);
16840 mb
->un
.varDmp
.word_cnt
= 0;
16843 * dump mem may return a zero when finished or we got a
16844 * mailbox error, either way we are done.
16846 if (mb
->un
.varDmp
.word_cnt
== 0)
16848 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
16849 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
16851 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
16852 rgn23_data
+ offset
,
16853 mb
->un
.varDmp
.word_cnt
);
16854 offset
+= mb
->un
.varDmp
.word_cnt
;
16855 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
16857 mempool_free(pmb
, phba
->mbox_mem_pool
);
16862 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
16863 * @phba: pointer to lpfc hba data structure.
16864 * @rgn23_data: pointer to configure region 23 data.
16866 * This function gets SLI4 port configure region 23 data through memory dump
16867 * mailbox command. When it successfully retrieves data, the size of the data
16868 * will be returned, otherwise, 0 will be returned.
16871 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
16873 LPFC_MBOXQ_t
*mboxq
= NULL
;
16874 struct lpfc_dmabuf
*mp
= NULL
;
16875 struct lpfc_mqe
*mqe
;
16876 uint32_t data_length
= 0;
16882 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16884 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16885 "3105 failed to allocate mailbox memory\n");
16889 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
16891 mqe
= &mboxq
->u
.mqe
;
16892 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
16893 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
16896 data_length
= mqe
->un
.mb_words
[5];
16897 if (data_length
== 0)
16899 if (data_length
> DMP_RGN23_SIZE
) {
16903 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
16905 mempool_free(mboxq
, phba
->mbox_mem_pool
);
16907 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
16910 return data_length
;
16914 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
16915 * @phba: pointer to lpfc hba data structure.
16917 * This function read region 23 and parse TLV for port status to
16918 * decide if the user disaled the port. If the TLV indicates the
16919 * port is disabled, the hba_flag is set accordingly.
16922 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
16924 uint8_t *rgn23_data
= NULL
;
16925 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
16926 uint32_t offset
= 0;
16928 /* Get adapter Region 23 data */
16929 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
16933 if (phba
->sli_rev
< LPFC_SLI_REV4
)
16934 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
16936 if_type
= bf_get(lpfc_sli_intf_if_type
,
16937 &phba
->sli4_hba
.sli_intf
);
16938 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
16940 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
16946 /* Check the region signature first */
16947 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
16948 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16949 "2619 Config region 23 has bad signature\n");
16954 /* Check the data structure version */
16955 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
16956 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16957 "2620 Config region 23 has bad version\n");
16962 /* Parse TLV entries in the region */
16963 while (offset
< data_size
) {
16964 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
16967 * If the TLV is not driver specific TLV or driver id is
16968 * not linux driver id, skip the record.
16970 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
16971 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
16972 (rgn23_data
[offset
+ 3] != 0)) {
16973 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16977 /* Driver found a driver specific TLV in the config region */
16978 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
16983 * Search for configured port state sub-TLV.
16985 while ((offset
< data_size
) &&
16986 (tlv_offset
< sub_tlv_len
)) {
16987 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
16992 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
16993 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16994 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16998 /* This HBA contains PORT_STE configured */
16999 if (!rgn23_data
[offset
+ 2])
17000 phba
->hba_flag
|= LINK_DISABLED
;
17012 * lpfc_wr_object - write an object to the firmware
17013 * @phba: HBA structure that indicates port to create a queue on.
17014 * @dmabuf_list: list of dmabufs to write to the port.
17015 * @size: the total byte value of the objects to write to the port.
17016 * @offset: the current offset to be used to start the transfer.
17018 * This routine will create a wr_object mailbox command to send to the port.
17019 * the mailbox command will be constructed using the dma buffers described in
17020 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
17021 * BDEs that the imbedded mailbox can support. The @offset variable will be
17022 * used to indicate the starting offset of the transfer and will also return
17023 * the offset after the write object mailbox has completed. @size is used to
17024 * determine the end of the object and whether the eof bit should be set.
17026 * Return 0 is successful and offset will contain the the new offset to use
17027 * for the next write.
17028 * Return negative value for error cases.
17031 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
17032 uint32_t size
, uint32_t *offset
)
17034 struct lpfc_mbx_wr_object
*wr_object
;
17035 LPFC_MBOXQ_t
*mbox
;
17037 uint32_t shdr_status
, shdr_add_status
;
17039 union lpfc_sli4_cfg_shdr
*shdr
;
17040 struct lpfc_dmabuf
*dmabuf
;
17041 uint32_t written
= 0;
17043 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17047 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
17048 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
17049 sizeof(struct lpfc_mbx_wr_object
) -
17050 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
17052 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
17053 wr_object
->u
.request
.write_offset
= *offset
;
17054 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
17055 wr_object
->u
.request
.object_name
[0] =
17056 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
17057 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
17058 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
17059 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
17061 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
17062 wr_object
->u
.request
.bde
[i
].addrHigh
=
17063 putPaddrHigh(dmabuf
->phys
);
17064 if (written
+ SLI4_PAGE_SIZE
>= size
) {
17065 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
17067 written
+= (size
- written
);
17068 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
17070 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
17072 written
+= SLI4_PAGE_SIZE
;
17076 wr_object
->u
.request
.bde_count
= i
;
17077 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
17078 if (!phba
->sli4_hba
.intr_enable
)
17079 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
17081 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
17082 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
17084 /* The IOCTL status is embedded in the mailbox subheader. */
17085 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
17086 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17087 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17088 if (rc
!= MBX_TIMEOUT
)
17089 mempool_free(mbox
, phba
->mbox_mem_pool
);
17090 if (shdr_status
|| shdr_add_status
|| rc
) {
17091 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17092 "3025 Write Object mailbox failed with "
17093 "status x%x add_status x%x, mbx status x%x\n",
17094 shdr_status
, shdr_add_status
, rc
);
17097 *offset
+= wr_object
->u
.response
.actual_write_length
;
17102 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
17103 * @vport: pointer to vport data structure.
17105 * This function iterate through the mailboxq and clean up all REG_LOGIN
17106 * and REG_VPI mailbox commands associated with the vport. This function
17107 * is called when driver want to restart discovery of the vport due to
17108 * a Clear Virtual Link event.
17111 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
17113 struct lpfc_hba
*phba
= vport
->phba
;
17114 LPFC_MBOXQ_t
*mb
, *nextmb
;
17115 struct lpfc_dmabuf
*mp
;
17116 struct lpfc_nodelist
*ndlp
;
17117 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
17118 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
17119 LIST_HEAD(mbox_cmd_list
);
17120 uint8_t restart_loop
;
17122 /* Clean up internally queued mailbox commands with the vport */
17123 spin_lock_irq(&phba
->hbalock
);
17124 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
17125 if (mb
->vport
!= vport
)
17128 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
17129 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
17132 list_del(&mb
->list
);
17133 list_add_tail(&mb
->list
, &mbox_cmd_list
);
17135 /* Clean up active mailbox command with the vport */
17136 mb
= phba
->sli
.mbox_active
;
17137 if (mb
&& (mb
->vport
== vport
)) {
17138 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
17139 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
17140 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17141 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
17142 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
17143 /* Put reference count for delayed processing */
17144 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
17145 /* Unregister the RPI when mailbox complete */
17146 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
17149 /* Cleanup any mailbox completions which are not yet processed */
17152 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
17154 * If this mailox is already processed or it is
17155 * for another vport ignore it.
17157 if ((mb
->vport
!= vport
) ||
17158 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
17161 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
17162 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
17165 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17166 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
17167 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
17168 /* Unregister the RPI when mailbox complete */
17169 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
17171 spin_unlock_irq(&phba
->hbalock
);
17172 spin_lock(shost
->host_lock
);
17173 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
17174 spin_unlock(shost
->host_lock
);
17175 spin_lock_irq(&phba
->hbalock
);
17179 } while (restart_loop
);
17181 spin_unlock_irq(&phba
->hbalock
);
17183 /* Release the cleaned-up mailbox commands */
17184 while (!list_empty(&mbox_cmd_list
)) {
17185 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
17186 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
17187 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
17189 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
17192 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
17193 mb
->context2
= NULL
;
17195 spin_lock(shost
->host_lock
);
17196 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
17197 spin_unlock(shost
->host_lock
);
17198 lpfc_nlp_put(ndlp
);
17201 mempool_free(mb
, phba
->mbox_mem_pool
);
17204 /* Release the ndlp with the cleaned-up active mailbox command */
17205 if (act_mbx_ndlp
) {
17206 spin_lock(shost
->host_lock
);
17207 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
17208 spin_unlock(shost
->host_lock
);
17209 lpfc_nlp_put(act_mbx_ndlp
);
17214 * lpfc_drain_txq - Drain the txq
17215 * @phba: Pointer to HBA context object.
17217 * This function attempt to submit IOCBs on the txq
17218 * to the adapter. For SLI4 adapters, the txq contains
17219 * ELS IOCBs that have been deferred because the there
17220 * are no SGLs. This congestion can occur with large
17221 * vport counts during node discovery.
17225 lpfc_drain_txq(struct lpfc_hba
*phba
)
17227 LIST_HEAD(completions
);
17228 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
17229 struct lpfc_iocbq
*piocbq
= NULL
;
17230 unsigned long iflags
= 0;
17231 char *fail_msg
= NULL
;
17232 struct lpfc_sglq
*sglq
;
17233 union lpfc_wqe128 wqe128
;
17234 union lpfc_wqe
*wqe
= (union lpfc_wqe
*) &wqe128
;
17235 uint32_t txq_cnt
= 0;
17237 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
17238 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
17242 if (txq_cnt
> pring
->txq_max
)
17243 pring
->txq_max
= txq_cnt
;
17245 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17247 while (!list_empty(&pring
->txq
)) {
17248 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
17250 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
17252 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17253 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17254 "2823 txq empty and txq_cnt is %d\n ",
17258 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
17260 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
17261 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17266 /* The xri and iocb resources secured,
17267 * attempt to issue request
17269 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
17270 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
17271 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
17272 fail_msg
= "to convert bpl to sgl";
17273 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, wqe
))
17274 fail_msg
= "to convert iocb to wqe";
17275 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, wqe
))
17276 fail_msg
= " - Wq is full";
17278 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
17281 /* Failed means we can't issue and need to cancel */
17282 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17283 "2822 IOCB failed %s iotag 0x%x "
17286 piocbq
->iotag
, piocbq
->sli4_xritag
);
17287 list_add_tail(&piocbq
->list
, &completions
);
17289 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17292 /* Cancel all the IOCBs that cannot be issued */
17293 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
17294 IOERR_SLI_ABORTED
);