1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_compat.h"
45 #include "lpfc_debugfs.h"
46 #include "lpfc_vport.h"
48 /* There are only four IOCB completion types. */
49 typedef enum _lpfc_iocb_type
{
57 /* Provide function prototypes local to this module. */
58 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
60 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
61 uint8_t *, uint32_t *);
64 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
70 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
71 * @q: The Work Queue to operate on.
72 * @wqe: The work Queue Entry to put on the Work queue.
74 * This routine will copy the contents of @wqe to the next available entry on
75 * the @q. This function will then ring the Work Queue Doorbell to signal the
76 * HBA to start processing the Work Queue Entry. This function returns 0 if
77 * successful. If no entries are available on @q then this function will return
79 * The caller is expected to hold the hbalock when calling this routine.
82 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
84 union lpfc_wqe
*temp_wqe
= q
->qe
[q
->host_index
].wqe
;
85 struct lpfc_register doorbell
;
88 /* If the host has not yet processed the next entry then we are done */
89 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
91 /* set consumption flag every once in a while */
92 if (!((q
->host_index
+ 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL
))
93 bf_set(lpfc_wqe_gen_wqec
, &wqe
->generic
, 1);
95 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
97 /* Update the host index before invoking device */
98 host_index
= q
->host_index
;
99 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
103 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
104 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
105 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
106 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
107 readl(q
->phba
->sli4_hba
.WQDBregaddr
); /* Flush */
113 * lpfc_sli4_wq_release - Updates internal hba index for WQ
114 * @q: The Work Queue to operate on.
115 * @index: The index to advance the hba index to.
117 * This routine will update the HBA index of a queue to reflect consumption of
118 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
119 * an entry the host calls this function to update the queue's internal
120 * pointers. This routine returns the number of entries that were consumed by
124 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
126 uint32_t released
= 0;
128 if (q
->hba_index
== index
)
131 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
133 } while (q
->hba_index
!= index
);
138 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
139 * @q: The Mailbox Queue to operate on.
140 * @wqe: The Mailbox Queue Entry to put on the Work queue.
142 * This routine will copy the contents of @mqe to the next available entry on
143 * the @q. This function will then ring the Work Queue Doorbell to signal the
144 * HBA to start processing the Work Queue Entry. This function returns 0 if
145 * successful. If no entries are available on @q then this function will return
147 * The caller is expected to hold the hbalock when calling this routine.
150 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
152 struct lpfc_mqe
*temp_mqe
= q
->qe
[q
->host_index
].mqe
;
153 struct lpfc_register doorbell
;
156 /* If the host has not yet processed the next entry then we are done */
157 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
159 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
160 /* Save off the mailbox pointer for completion */
161 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
163 /* Update the host index before invoking device */
164 host_index
= q
->host_index
;
165 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
169 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
170 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
171 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
172 readl(q
->phba
->sli4_hba
.MQDBregaddr
); /* Flush */
177 * lpfc_sli4_mq_release - Updates internal hba index for MQ
178 * @q: The Mailbox Queue to operate on.
180 * This routine will update the HBA index of a queue to reflect consumption of
181 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
182 * an entry the host calls this function to update the queue's internal
183 * pointers. This routine returns the number of entries that were consumed by
187 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
189 /* Clear the mailbox pointer for completion */
190 q
->phba
->mbox
= NULL
;
191 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
196 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
197 * @q: The Event Queue to get the first valid EQE from
199 * This routine will get the first valid Event Queue Entry from @q, update
200 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
201 * the Queue (no more work to do), or the Queue is full of EQEs that have been
202 * processed, but not popped back to the HBA then this routine will return NULL.
204 static struct lpfc_eqe
*
205 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
207 struct lpfc_eqe
*eqe
= q
->qe
[q
->hba_index
].eqe
;
209 /* If the next EQE is not valid then we are done */
210 if (!bf_get(lpfc_eqe_valid
, eqe
))
212 /* If the host has not yet processed the next entry then we are done */
213 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
216 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
221 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
222 * @q: The Event Queue that the host has completed processing for.
223 * @arm: Indicates whether the host wants to arms this CQ.
225 * This routine will mark all Event Queue Entries on @q, from the last
226 * known completed entry to the last entry that was processed, as completed
227 * by clearing the valid bit for each completion queue entry. Then it will
228 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
229 * The internal host index in the @q will be updated by this routine to indicate
230 * that the host has finished processing the entries. The @arm parameter
231 * indicates that the queue should be rearmed when ringing the doorbell.
233 * This function will return the number of EQEs that were popped.
236 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
238 uint32_t released
= 0;
239 struct lpfc_eqe
*temp_eqe
;
240 struct lpfc_register doorbell
;
242 /* while there are valid entries */
243 while (q
->hba_index
!= q
->host_index
) {
244 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
245 bf_set(lpfc_eqe_valid
, temp_eqe
, 0);
247 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
249 if (unlikely(released
== 0 && !arm
))
252 /* ring doorbell for number popped */
255 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
256 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
258 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
259 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
260 bf_set(lpfc_eqcq_doorbell_eqid
, &doorbell
, q
->queue_id
);
261 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
266 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
267 * @q: The Completion Queue to get the first valid CQE from
269 * This routine will get the first valid Completion Queue Entry from @q, update
270 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
271 * the Queue (no more work to do), or the Queue is full of CQEs that have been
272 * processed, but not popped back to the HBA then this routine will return NULL.
274 static struct lpfc_cqe
*
275 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
277 struct lpfc_cqe
*cqe
;
279 /* If the next CQE is not valid then we are done */
280 if (!bf_get(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
282 /* If the host has not yet processed the next entry then we are done */
283 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
286 cqe
= q
->qe
[q
->hba_index
].cqe
;
287 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
292 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
293 * @q: The Completion Queue that the host has completed processing for.
294 * @arm: Indicates whether the host wants to arms this CQ.
296 * This routine will mark all Completion queue entries on @q, from the last
297 * known completed entry to the last entry that was processed, as completed
298 * by clearing the valid bit for each completion queue entry. Then it will
299 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
300 * The internal host index in the @q will be updated by this routine to indicate
301 * that the host has finished processing the entries. The @arm parameter
302 * indicates that the queue should be rearmed when ringing the doorbell.
304 * This function will return the number of CQEs that were released.
307 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
309 uint32_t released
= 0;
310 struct lpfc_cqe
*temp_qe
;
311 struct lpfc_register doorbell
;
313 /* while there are valid entries */
314 while (q
->hba_index
!= q
->host_index
) {
315 temp_qe
= q
->qe
[q
->host_index
].cqe
;
316 bf_set(lpfc_cqe_valid
, temp_qe
, 0);
318 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
320 if (unlikely(released
== 0 && !arm
))
323 /* ring doorbell for number popped */
326 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
327 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
328 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
329 bf_set(lpfc_eqcq_doorbell_cqid
, &doorbell
, q
->queue_id
);
330 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
335 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
336 * @q: The Header Receive Queue to operate on.
337 * @wqe: The Receive Queue Entry to put on the Receive queue.
339 * This routine will copy the contents of @wqe to the next available entry on
340 * the @q. This function will then ring the Receive Queue Doorbell to signal the
341 * HBA to start processing the Receive Queue Entry. This function returns the
342 * index that the rqe was copied to if successful. If no entries are available
343 * on @q then this function will return -ENOMEM.
344 * The caller is expected to hold the hbalock when calling this routine.
347 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
348 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
350 struct lpfc_rqe
*temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
351 struct lpfc_rqe
*temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
352 struct lpfc_register doorbell
;
353 int put_index
= hq
->host_index
;
355 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
357 if (hq
->host_index
!= dq
->host_index
)
359 /* If the host has not yet processed the next entry then we are done */
360 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
362 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
363 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
365 /* Update the host index to point to the next slot */
366 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
367 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
369 /* Ring The Header Receive Queue Doorbell */
370 if (!(hq
->host_index
% LPFC_RQ_POST_BATCH
)) {
372 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
374 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
375 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
381 * lpfc_sli4_rq_release - Updates internal hba index for RQ
382 * @q: The Header Receive Queue to operate on.
384 * This routine will update the HBA index of a queue to reflect consumption of
385 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
386 * consumed an entry the host calls this function to update the queue's
387 * internal pointers. This routine returns the number of entries that were
388 * consumed by the HBA.
391 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
393 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
395 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
396 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
401 * lpfc_cmd_iocb - Get next command iocb entry in the ring
402 * @phba: Pointer to HBA context object.
403 * @pring: Pointer to driver SLI ring object.
405 * This function returns pointer to next command iocb entry
406 * in the command ring. The caller must hold hbalock to prevent
407 * other threads consume the next command iocb.
408 * SLI-2/SLI-3 provide different sized iocbs.
410 static inline IOCB_t
*
411 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
413 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
414 pring
->cmdidx
* phba
->iocb_cmd_size
);
418 * lpfc_resp_iocb - Get next response iocb entry in the ring
419 * @phba: Pointer to HBA context object.
420 * @pring: Pointer to driver SLI ring object.
422 * This function returns pointer to next response iocb entry
423 * in the response ring. The caller must hold hbalock to make sure
424 * that no other thread consume the next response iocb.
425 * SLI-2/SLI-3 provide different sized iocbs.
427 static inline IOCB_t
*
428 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
430 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
431 pring
->rspidx
* phba
->iocb_rsp_size
);
435 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
436 * @phba: Pointer to HBA context object.
438 * This function is called with hbalock held. This function
439 * allocates a new driver iocb object from the iocb pool. If the
440 * allocation is successful, it returns pointer to the newly
441 * allocated iocb object else it returns NULL.
443 static struct lpfc_iocbq
*
444 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
446 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
447 struct lpfc_iocbq
* iocbq
= NULL
;
449 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
454 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
455 * @phba: Pointer to HBA context object.
456 * @xritag: XRI value.
458 * This function clears the sglq pointer from the array of acive
459 * sglq's. The xritag that is passed in is used to index into the
460 * array. Before the xritag can be used it needs to be adjusted
461 * by subtracting the xribase.
463 * Returns sglq ponter = success, NULL = Failure.
465 static struct lpfc_sglq
*
466 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
469 struct lpfc_sglq
*sglq
;
470 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
471 if (adj_xri
> phba
->sli4_hba
.max_cfg_param
.max_xri
)
473 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
];
474 phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
] = NULL
;
479 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
480 * @phba: Pointer to HBA context object.
481 * @xritag: XRI value.
483 * This function returns the sglq pointer from the array of acive
484 * sglq's. The xritag that is passed in is used to index into the
485 * array. Before the xritag can be used it needs to be adjusted
486 * by subtracting the xribase.
488 * Returns sglq ponter = success, NULL = Failure.
490 static struct lpfc_sglq
*
491 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
494 struct lpfc_sglq
*sglq
;
495 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
496 if (adj_xri
> phba
->sli4_hba
.max_cfg_param
.max_xri
)
498 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
];
503 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
504 * @phba: Pointer to HBA context object.
506 * This function is called with hbalock held. This function
507 * Gets a new driver sglq object from the sglq list. If the
508 * list is not empty then it is successful, it returns pointer to the newly
509 * allocated sglq object else it returns NULL.
511 static struct lpfc_sglq
*
512 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
)
514 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
515 struct lpfc_sglq
*sglq
= NULL
;
517 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
518 adj_xri
= sglq
->sli4_xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
519 phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
] = sglq
;
524 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
525 * @phba: Pointer to HBA context object.
527 * This function is called with no lock held. This function
528 * allocates a new driver iocb object from the iocb pool. If the
529 * allocation is successful, it returns pointer to the newly
530 * allocated iocb object else it returns NULL.
533 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
535 struct lpfc_iocbq
* iocbq
= NULL
;
536 unsigned long iflags
;
538 spin_lock_irqsave(&phba
->hbalock
, iflags
);
539 iocbq
= __lpfc_sli_get_iocbq(phba
);
540 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
545 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
546 * @phba: Pointer to HBA context object.
547 * @iocbq: Pointer to driver iocb object.
549 * This function is called with hbalock held to release driver
550 * iocb object to the iocb pool. The iotag in the iocb object
551 * does not change for each use of the iocb object. This function
552 * clears all other fields of the iocb object when it is freed.
553 * The sqlq structure that holds the xritag and phys and virtual
554 * mappings for the scatter gather list is retrieved from the
555 * active array of sglq. The get of the sglq pointer also clears
556 * the entry in the array. If the status of the IO indiactes that
557 * this IO was aborted then the sglq entry it put on the
558 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
559 * IO has good status or fails for any other reason then the sglq
560 * entry is added to the free list (lpfc_sgl_list).
563 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
565 struct lpfc_sglq
*sglq
;
566 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
569 if (iocbq
->sli4_xritag
== NO_XRI
)
572 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_xritag
);
574 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
575 || ((iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
576 && (iocbq
->iocb
.un
.ulpWord
[4]
577 == IOERR_SLI_ABORTED
))) {
578 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
580 list_add(&sglq
->list
,
581 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
582 spin_unlock_irqrestore(
583 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
585 list_add(&sglq
->list
, &phba
->sli4_hba
.lpfc_sgl_list
);
590 * Clean all volatile data fields, preserve iotag and node struct.
592 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
593 iocbq
->sli4_xritag
= NO_XRI
;
594 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
598 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
599 * @phba: Pointer to HBA context object.
600 * @iocbq: Pointer to driver iocb object.
602 * This function is called with hbalock held to release driver
603 * iocb object to the iocb pool. The iotag in the iocb object
604 * does not change for each use of the iocb object. This function
605 * clears all other fields of the iocb object when it is freed.
608 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
610 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
613 * Clean all volatile data fields, preserve iotag and node struct.
615 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
616 iocbq
->sli4_xritag
= NO_XRI
;
617 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
621 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
622 * @phba: Pointer to HBA context object.
623 * @iocbq: Pointer to driver iocb object.
625 * This function is called with hbalock held to release driver
626 * iocb object to the iocb pool. The iotag in the iocb object
627 * does not change for each use of the iocb object. This function
628 * clears all other fields of the iocb object when it is freed.
631 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
633 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
637 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
638 * @phba: Pointer to HBA context object.
639 * @iocbq: Pointer to driver iocb object.
641 * This function is called with no lock held to release the iocb to
645 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
647 unsigned long iflags
;
650 * Clean all volatile data fields, preserve iotag and node struct.
652 spin_lock_irqsave(&phba
->hbalock
, iflags
);
653 __lpfc_sli_release_iocbq(phba
, iocbq
);
654 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
658 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
659 * @phba: Pointer to HBA context object.
660 * @iocblist: List of IOCBs.
661 * @ulpstatus: ULP status in IOCB command field.
662 * @ulpWord4: ULP word-4 in IOCB command field.
664 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
665 * on the list by invoking the complete callback function associated with the
666 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
670 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
671 uint32_t ulpstatus
, uint32_t ulpWord4
)
673 struct lpfc_iocbq
*piocb
;
675 while (!list_empty(iocblist
)) {
676 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
678 if (!piocb
->iocb_cmpl
)
679 lpfc_sli_release_iocbq(phba
, piocb
);
681 piocb
->iocb
.ulpStatus
= ulpstatus
;
682 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
683 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
690 * lpfc_sli_iocb_cmd_type - Get the iocb type
691 * @iocb_cmnd: iocb command code.
693 * This function is called by ring event handler function to get the iocb type.
694 * This function translates the iocb command to an iocb command type used to
695 * decide the final disposition of each completed IOCB.
696 * The function returns
697 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
698 * LPFC_SOL_IOCB if it is a solicited iocb completion
699 * LPFC_ABORT_IOCB if it is an abort iocb
700 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
702 * The caller is not required to hold any lock.
704 static lpfc_iocb_type
705 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
707 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
709 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
713 case CMD_XMIT_SEQUENCE_CR
:
714 case CMD_XMIT_SEQUENCE_CX
:
715 case CMD_XMIT_BCAST_CN
:
716 case CMD_XMIT_BCAST_CX
:
717 case CMD_ELS_REQUEST_CR
:
718 case CMD_ELS_REQUEST_CX
:
719 case CMD_CREATE_XRI_CR
:
720 case CMD_CREATE_XRI_CX
:
722 case CMD_XMIT_ELS_RSP_CX
:
724 case CMD_FCP_IWRITE_CR
:
725 case CMD_FCP_IWRITE_CX
:
726 case CMD_FCP_IREAD_CR
:
727 case CMD_FCP_IREAD_CX
:
728 case CMD_FCP_ICMND_CR
:
729 case CMD_FCP_ICMND_CX
:
730 case CMD_FCP_TSEND_CX
:
731 case CMD_FCP_TRSP_CX
:
732 case CMD_FCP_TRECEIVE_CX
:
733 case CMD_FCP_AUTO_TRSP_CX
:
734 case CMD_ADAPTER_MSG
:
735 case CMD_ADAPTER_DUMP
:
736 case CMD_XMIT_SEQUENCE64_CR
:
737 case CMD_XMIT_SEQUENCE64_CX
:
738 case CMD_XMIT_BCAST64_CN
:
739 case CMD_XMIT_BCAST64_CX
:
740 case CMD_ELS_REQUEST64_CR
:
741 case CMD_ELS_REQUEST64_CX
:
742 case CMD_FCP_IWRITE64_CR
:
743 case CMD_FCP_IWRITE64_CX
:
744 case CMD_FCP_IREAD64_CR
:
745 case CMD_FCP_IREAD64_CX
:
746 case CMD_FCP_ICMND64_CR
:
747 case CMD_FCP_ICMND64_CX
:
748 case CMD_FCP_TSEND64_CX
:
749 case CMD_FCP_TRSP64_CX
:
750 case CMD_FCP_TRECEIVE64_CX
:
751 case CMD_GEN_REQUEST64_CR
:
752 case CMD_GEN_REQUEST64_CX
:
753 case CMD_XMIT_ELS_RSP64_CX
:
754 case DSSCMD_IWRITE64_CR
:
755 case DSSCMD_IWRITE64_CX
:
756 case DSSCMD_IREAD64_CR
:
757 case DSSCMD_IREAD64_CX
:
758 case DSSCMD_INVALIDATE_DEK
:
760 case DSSCMD_GET_KEK_ID
:
761 case DSSCMD_GEN_XFER
:
762 type
= LPFC_SOL_IOCB
;
764 case CMD_ABORT_XRI_CN
:
765 case CMD_ABORT_XRI_CX
:
766 case CMD_CLOSE_XRI_CN
:
767 case CMD_CLOSE_XRI_CX
:
768 case CMD_XRI_ABORTED_CX
:
769 case CMD_ABORT_MXRI64_CN
:
770 type
= LPFC_ABORT_IOCB
;
772 case CMD_RCV_SEQUENCE_CX
:
773 case CMD_RCV_ELS_REQ_CX
:
774 case CMD_RCV_SEQUENCE64_CX
:
775 case CMD_RCV_ELS_REQ64_CX
:
776 case CMD_ASYNC_STATUS
:
777 case CMD_IOCB_RCV_SEQ64_CX
:
778 case CMD_IOCB_RCV_ELS64_CX
:
779 case CMD_IOCB_RCV_CONT64_CX
:
780 case CMD_IOCB_RET_XRI64_CX
:
781 type
= LPFC_UNSOL_IOCB
;
783 case CMD_IOCB_XMIT_MSEQ64_CR
:
784 case CMD_IOCB_XMIT_MSEQ64_CX
:
785 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
786 case CMD_IOCB_RCV_ELS_LIST64_CX
:
787 case CMD_IOCB_CLOSE_EXTENDED_CN
:
788 case CMD_IOCB_ABORT_EXTENDED_CN
:
789 case CMD_IOCB_RET_HBQE64_CN
:
790 case CMD_IOCB_FCP_IBIDIR64_CR
:
791 case CMD_IOCB_FCP_IBIDIR64_CX
:
792 case CMD_IOCB_FCP_ITASKMGT64_CX
:
793 case CMD_IOCB_LOGENTRY_CN
:
794 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
795 printk("%s - Unhandled SLI-3 Command x%x\n",
796 __func__
, iocb_cmnd
);
797 type
= LPFC_UNKNOWN_IOCB
;
800 type
= LPFC_UNKNOWN_IOCB
;
808 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
809 * @phba: Pointer to HBA context object.
811 * This function is called from SLI initialization code
812 * to configure every ring of the HBA's SLI interface. The
813 * caller is not required to hold any lock. This function issues
814 * a config_ring mailbox command for each ring.
815 * This function returns zero if successful else returns a negative
819 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
821 struct lpfc_sli
*psli
= &phba
->sli
;
826 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
830 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
831 for (i
= 0; i
< psli
->num_rings
; i
++) {
832 lpfc_config_ring(phba
, i
, pmb
);
833 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
834 if (rc
!= MBX_SUCCESS
) {
835 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
836 "0446 Adapter failed to init (%d), "
837 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
839 rc
, pmbox
->mbxCommand
,
840 pmbox
->mbxStatus
, i
);
841 phba
->link_state
= LPFC_HBA_ERROR
;
846 mempool_free(pmb
, phba
->mbox_mem_pool
);
851 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
852 * @phba: Pointer to HBA context object.
853 * @pring: Pointer to driver SLI ring object.
854 * @piocb: Pointer to the driver iocb object.
856 * This function is called with hbalock held. The function adds the
857 * new iocb to txcmplq of the given ring. This function always returns
858 * 0. If this function is called for ELS ring, this function checks if
859 * there is a vport associated with the ELS command. This function also
860 * starts els_tmofunc timer if this is an ELS command.
863 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
864 struct lpfc_iocbq
*piocb
)
866 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
867 pring
->txcmplq_cnt
++;
868 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
869 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
870 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
874 mod_timer(&piocb
->vport
->els_tmofunc
,
875 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
883 * lpfc_sli_ringtx_get - Get first element of the txq
884 * @phba: Pointer to HBA context object.
885 * @pring: Pointer to driver SLI ring object.
887 * This function is called with hbalock held to get next
888 * iocb in txq of the given ring. If there is any iocb in
889 * the txq, the function returns first iocb in the list after
890 * removing the iocb from the list, else it returns NULL.
892 static struct lpfc_iocbq
*
893 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
895 struct lpfc_iocbq
*cmd_iocb
;
897 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
898 if (cmd_iocb
!= NULL
)
904 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
905 * @phba: Pointer to HBA context object.
906 * @pring: Pointer to driver SLI ring object.
908 * This function is called with hbalock held and the caller must post the
909 * iocb without releasing the lock. If the caller releases the lock,
910 * iocb slot returned by the function is not guaranteed to be available.
911 * The function returns pointer to the next available iocb slot if there
912 * is available slot in the ring, else it returns NULL.
913 * If the get index of the ring is ahead of the put index, the function
914 * will post an error attention event to the worker thread to take the
915 * HBA to offline state.
918 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
920 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
921 uint32_t max_cmd_idx
= pring
->numCiocb
;
922 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
923 (++pring
->next_cmdidx
>= max_cmd_idx
))
924 pring
->next_cmdidx
= 0;
926 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
928 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
930 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
931 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
932 "0315 Ring %d issue: portCmdGet %d "
933 "is bigger than cmd ring %d\n",
935 pring
->local_getidx
, max_cmd_idx
);
937 phba
->link_state
= LPFC_HBA_ERROR
;
939 * All error attention handlers are posted to
942 phba
->work_ha
|= HA_ERATT
;
943 phba
->work_hs
= HS_FFER3
;
945 lpfc_worker_wake_up(phba
);
950 if (pring
->local_getidx
== pring
->next_cmdidx
)
954 return lpfc_cmd_iocb(phba
, pring
);
958 * lpfc_sli_next_iotag - Get an iotag for the iocb
959 * @phba: Pointer to HBA context object.
960 * @iocbq: Pointer to driver iocb object.
962 * This function gets an iotag for the iocb. If there is no unused iotag and
963 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
964 * array and assigns a new iotag.
965 * The function returns the allocated iotag if successful, else returns zero.
966 * Zero is not a valid iotag.
967 * The caller is not required to hold any lock.
970 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
972 struct lpfc_iocbq
**new_arr
;
973 struct lpfc_iocbq
**old_arr
;
975 struct lpfc_sli
*psli
= &phba
->sli
;
978 spin_lock_irq(&phba
->hbalock
);
979 iotag
= psli
->last_iotag
;
980 if(++iotag
< psli
->iocbq_lookup_len
) {
981 psli
->last_iotag
= iotag
;
982 psli
->iocbq_lookup
[iotag
] = iocbq
;
983 spin_unlock_irq(&phba
->hbalock
);
984 iocbq
->iotag
= iotag
;
986 } else if (psli
->iocbq_lookup_len
< (0xffff
987 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
988 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
989 spin_unlock_irq(&phba
->hbalock
);
990 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
993 spin_lock_irq(&phba
->hbalock
);
994 old_arr
= psli
->iocbq_lookup
;
995 if (new_len
<= psli
->iocbq_lookup_len
) {
996 /* highly unprobable case */
998 iotag
= psli
->last_iotag
;
999 if(++iotag
< psli
->iocbq_lookup_len
) {
1000 psli
->last_iotag
= iotag
;
1001 psli
->iocbq_lookup
[iotag
] = iocbq
;
1002 spin_unlock_irq(&phba
->hbalock
);
1003 iocbq
->iotag
= iotag
;
1006 spin_unlock_irq(&phba
->hbalock
);
1009 if (psli
->iocbq_lookup
)
1010 memcpy(new_arr
, old_arr
,
1011 ((psli
->last_iotag
+ 1) *
1012 sizeof (struct lpfc_iocbq
*)));
1013 psli
->iocbq_lookup
= new_arr
;
1014 psli
->iocbq_lookup_len
= new_len
;
1015 psli
->last_iotag
= iotag
;
1016 psli
->iocbq_lookup
[iotag
] = iocbq
;
1017 spin_unlock_irq(&phba
->hbalock
);
1018 iocbq
->iotag
= iotag
;
1023 spin_unlock_irq(&phba
->hbalock
);
1025 lpfc_printf_log(phba
, KERN_ERR
,LOG_SLI
,
1026 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1033 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1034 * @phba: Pointer to HBA context object.
1035 * @pring: Pointer to driver SLI ring object.
1036 * @iocb: Pointer to iocb slot in the ring.
1037 * @nextiocb: Pointer to driver iocb object which need to be
1038 * posted to firmware.
1040 * This function is called with hbalock held to post a new iocb to
1041 * the firmware. This function copies the new iocb to ring iocb slot and
1042 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1043 * a completion call back for this iocb else the function will free the
1047 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1048 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1053 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1056 if (pring
->ringno
== LPFC_ELS_RING
) {
1057 lpfc_debugfs_slow_ring_trc(phba
,
1058 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1059 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1060 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1061 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1065 * Issue iocb command to adapter
1067 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1069 pring
->stats
.iocb_cmd
++;
1072 * If there is no completion routine to call, we can release the
1073 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1074 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1076 if (nextiocb
->iocb_cmpl
)
1077 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1079 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1082 * Let the HBA know what IOCB slot will be the next one the
1083 * driver will put a command into.
1085 pring
->cmdidx
= pring
->next_cmdidx
;
1086 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1090 * lpfc_sli_update_full_ring - Update the chip attention register
1091 * @phba: Pointer to HBA context object.
1092 * @pring: Pointer to driver SLI ring object.
1094 * The caller is not required to hold any lock for calling this function.
1095 * This function updates the chip attention bits for the ring to inform firmware
1096 * that there are pending work to be done for this ring and requests an
1097 * interrupt when there is space available in the ring. This function is
1098 * called when the driver is unable to post more iocbs to the ring due
1099 * to unavailability of space in the ring.
1102 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1104 int ringno
= pring
->ringno
;
1106 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1111 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1112 * The HBA will tell us when an IOCB entry is available.
1114 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1115 readl(phba
->CAregaddr
); /* flush */
1117 pring
->stats
.iocb_cmd_full
++;
1121 * lpfc_sli_update_ring - Update chip attention register
1122 * @phba: Pointer to HBA context object.
1123 * @pring: Pointer to driver SLI ring object.
1125 * This function updates the chip attention register bit for the
1126 * given ring to inform HBA that there is more work to be done
1127 * in this ring. The caller is not required to hold any lock.
1130 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1132 int ringno
= pring
->ringno
;
1135 * Tell the HBA that there is work to do in this ring.
1137 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1139 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1140 readl(phba
->CAregaddr
); /* flush */
1145 * lpfc_sli_resume_iocb - Process iocbs in the txq
1146 * @phba: Pointer to HBA context object.
1147 * @pring: Pointer to driver SLI ring object.
1149 * This function is called with hbalock held to post pending iocbs
1150 * in the txq to the firmware. This function is called when driver
1151 * detects space available in the ring.
1154 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1157 struct lpfc_iocbq
*nextiocb
;
1161 * (a) there is anything on the txq to send
1163 * (c) link attention events can be processed (fcp ring only)
1164 * (d) IOCB processing is not blocked by the outstanding mbox command.
1166 if (pring
->txq_cnt
&&
1167 lpfc_is_link_up(phba
) &&
1168 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1169 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1171 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1172 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1173 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1176 lpfc_sli_update_ring(phba
, pring
);
1178 lpfc_sli_update_full_ring(phba
, pring
);
1185 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1186 * @phba: Pointer to HBA context object.
1187 * @hbqno: HBQ number.
1189 * This function is called with hbalock held to get the next
1190 * available slot for the given HBQ. If there is free slot
1191 * available for the HBQ it will return pointer to the next available
1192 * HBQ entry else it will return NULL.
1194 static struct lpfc_hbq_entry
*
1195 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1197 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1199 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1200 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1201 hbqp
->next_hbqPutIdx
= 0;
1203 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1204 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1205 uint32_t getidx
= le32_to_cpu(raw_index
);
1207 hbqp
->local_hbqGetIdx
= getidx
;
1209 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1210 lpfc_printf_log(phba
, KERN_ERR
,
1211 LOG_SLI
| LOG_VPORT
,
1212 "1802 HBQ %d: local_hbqGetIdx "
1213 "%u is > than hbqp->entry_count %u\n",
1214 hbqno
, hbqp
->local_hbqGetIdx
,
1217 phba
->link_state
= LPFC_HBA_ERROR
;
1221 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1225 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1230 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1231 * @phba: Pointer to HBA context object.
1233 * This function is called with no lock held to free all the
1234 * hbq buffers while uninitializing the SLI interface. It also
1235 * frees the HBQ buffers returned by the firmware but not yet
1236 * processed by the upper layers.
1239 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1241 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1242 struct hbq_dmabuf
*hbq_buf
;
1243 unsigned long flags
;
1247 hbq_count
= lpfc_sli_hbq_count();
1248 /* Return all memory used by all HBQs */
1249 spin_lock_irqsave(&phba
->hbalock
, flags
);
1250 for (i
= 0; i
< hbq_count
; ++i
) {
1251 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1252 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1253 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1254 list_del(&hbq_buf
->dbuf
.list
);
1255 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1257 phba
->hbqs
[i
].buffer_count
= 0;
1259 /* Return all HBQ buffer that are in-fly */
1260 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1262 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1263 list_del(&hbq_buf
->dbuf
.list
);
1264 if (hbq_buf
->tag
== -1) {
1265 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1268 hbqno
= hbq_buf
->tag
>> 16;
1269 if (hbqno
>= LPFC_MAX_HBQS
)
1270 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1273 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1278 /* Mark the HBQs not in use */
1279 phba
->hbq_in_use
= 0;
1280 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1284 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1285 * @phba: Pointer to HBA context object.
1286 * @hbqno: HBQ number.
1287 * @hbq_buf: Pointer to HBQ buffer.
1289 * This function is called with the hbalock held to post a
1290 * hbq buffer to the firmware. If the function finds an empty
1291 * slot in the HBQ, it will post the buffer. The function will return
1292 * pointer to the hbq entry if it successfully post the buffer
1293 * else it will return NULL.
1296 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1297 struct hbq_dmabuf
*hbq_buf
)
1299 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1303 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1304 * @phba: Pointer to HBA context object.
1305 * @hbqno: HBQ number.
1306 * @hbq_buf: Pointer to HBQ buffer.
1308 * This function is called with the hbalock held to post a hbq buffer to the
1309 * firmware. If the function finds an empty slot in the HBQ, it will post the
1310 * buffer and place it on the hbq_buffer_list. The function will return zero if
1311 * it successfully post the buffer else it will return an error.
1314 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1315 struct hbq_dmabuf
*hbq_buf
)
1317 struct lpfc_hbq_entry
*hbqe
;
1318 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1320 /* Get next HBQ entry slot to use */
1321 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1323 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1325 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1326 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1327 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1328 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1329 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1330 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1332 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1333 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1335 readl(phba
->hbq_put
+ hbqno
);
1336 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1343 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1344 * @phba: Pointer to HBA context object.
1345 * @hbqno: HBQ number.
1346 * @hbq_buf: Pointer to HBQ buffer.
1348 * This function is called with the hbalock held to post an RQE to the SLI4
1349 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1350 * the hbq_buffer_list and return zero, otherwise it will return an error.
1353 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1354 struct hbq_dmabuf
*hbq_buf
)
1357 struct lpfc_rqe hrqe
;
1358 struct lpfc_rqe drqe
;
1360 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1361 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1362 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1363 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1364 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1369 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1373 /* HBQ for ELS and CT traffic. */
1374 static struct lpfc_hbq_init lpfc_els_hbq
= {
1379 .ring_mask
= (1 << LPFC_ELS_RING
),
1385 /* HBQ for the extra ring if needed */
1386 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1391 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1398 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1404 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1405 * @phba: Pointer to HBA context object.
1406 * @hbqno: HBQ number.
1407 * @count: Number of HBQ buffers to be posted.
1409 * This function is called with no lock held to post more hbq buffers to the
1410 * given HBQ. The function returns the number of HBQ buffers successfully
1414 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1416 uint32_t i
, posted
= 0;
1417 unsigned long flags
;
1418 struct hbq_dmabuf
*hbq_buffer
;
1419 LIST_HEAD(hbq_buf_list
);
1420 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1423 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1424 lpfc_hbq_defs
[hbqno
]->entry_count
)
1425 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1426 phba
->hbqs
[hbqno
].buffer_count
;
1429 /* Allocate HBQ entries */
1430 for (i
= 0; i
< count
; i
++) {
1431 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1434 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1436 /* Check whether HBQ is still in use */
1437 spin_lock_irqsave(&phba
->hbalock
, flags
);
1438 if (!phba
->hbq_in_use
)
1440 while (!list_empty(&hbq_buf_list
)) {
1441 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1443 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1445 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1446 phba
->hbqs
[hbqno
].buffer_count
++;
1449 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1451 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1454 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1455 while (!list_empty(&hbq_buf_list
)) {
1456 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1458 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1464 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1465 * @phba: Pointer to HBA context object.
1468 * This function posts more buffers to the HBQ. This function
1469 * is called with no lock held. The function returns the number of HBQ entries
1470 * successfully allocated.
1473 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1475 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1476 lpfc_hbq_defs
[qno
]->add_count
));
1480 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1481 * @phba: Pointer to HBA context object.
1482 * @qno: HBQ queue number.
1484 * This function is called from SLI initialization code path with
1485 * no lock held to post initial HBQ buffers to firmware. The
1486 * function returns the number of HBQ entries successfully allocated.
1489 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1491 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1492 lpfc_hbq_defs
[qno
]->init_count
));
1496 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1497 * @phba: Pointer to HBA context object.
1498 * @hbqno: HBQ number.
1500 * This function removes the first hbq buffer on an hbq list and returns a
1501 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1503 static struct hbq_dmabuf
*
1504 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1506 struct lpfc_dmabuf
*d_buf
;
1508 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1511 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1515 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1516 * @phba: Pointer to HBA context object.
1517 * @tag: Tag of the hbq buffer.
1519 * This function is called with hbalock held. This function searches
1520 * for the hbq buffer associated with the given tag in the hbq buffer
1521 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1524 static struct hbq_dmabuf
*
1525 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1527 struct lpfc_dmabuf
*d_buf
;
1528 struct hbq_dmabuf
*hbq_buf
;
1532 if (hbqno
>= LPFC_MAX_HBQS
)
1535 spin_lock_irq(&phba
->hbalock
);
1536 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1537 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1538 if (hbq_buf
->tag
== tag
) {
1539 spin_unlock_irq(&phba
->hbalock
);
1543 spin_unlock_irq(&phba
->hbalock
);
1544 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1545 "1803 Bad hbq tag. Data: x%x x%x\n",
1546 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1551 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1552 * @phba: Pointer to HBA context object.
1553 * @hbq_buffer: Pointer to HBQ buffer.
1555 * This function is called with hbalock. This function gives back
1556 * the hbq buffer to firmware. If the HBQ does not have space to
1557 * post the buffer, it will free the buffer.
1560 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1565 hbqno
= hbq_buffer
->tag
>> 16;
1566 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1567 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1572 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1573 * @mbxCommand: mailbox command code.
1575 * This function is called by the mailbox event handler function to verify
1576 * that the completed mailbox command is a legitimate mailbox command. If the
1577 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1578 * and the mailbox event handler will take the HBA offline.
1581 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
1585 switch (mbxCommand
) {
1589 case MBX_WRITE_VPARMS
:
1590 case MBX_RUN_BIU_DIAG
:
1593 case MBX_CONFIG_LINK
:
1594 case MBX_CONFIG_RING
:
1595 case MBX_RESET_RING
:
1596 case MBX_READ_CONFIG
:
1597 case MBX_READ_RCONFIG
:
1598 case MBX_READ_SPARM
:
1599 case MBX_READ_STATUS
:
1603 case MBX_READ_LNK_STAT
:
1605 case MBX_UNREG_LOGIN
:
1608 case MBX_DUMP_MEMORY
:
1609 case MBX_DUMP_CONTEXT
:
1612 case MBX_UPDATE_CFG
:
1614 case MBX_DEL_LD_ENTRY
:
1615 case MBX_RUN_PROGRAM
:
1617 case MBX_SET_VARIABLE
:
1618 case MBX_UNREG_D_ID
:
1619 case MBX_KILL_BOARD
:
1620 case MBX_CONFIG_FARP
:
1623 case MBX_RUN_BIU_DIAG64
:
1624 case MBX_CONFIG_PORT
:
1625 case MBX_READ_SPARM64
:
1626 case MBX_READ_RPI64
:
1627 case MBX_REG_LOGIN64
:
1631 case MBX_LOAD_EXP_ROM
:
1632 case MBX_ASYNCEVT_ENABLE
:
1636 case MBX_PORT_CAPABILITIES
:
1637 case MBX_PORT_IOV_CONTROL
:
1638 case MBX_SLI4_CONFIG
:
1639 case MBX_SLI4_REQ_FTRS
:
1641 case MBX_UNREG_FCFI
:
1646 case MBX_RESUME_RPI
:
1657 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
1658 * @phba: Pointer to HBA context object.
1659 * @pmboxq: Pointer to mailbox command.
1661 * This is completion handler function for mailbox commands issued from
1662 * lpfc_sli_issue_mbox_wait function. This function is called by the
1663 * mailbox event handler function with no lock held. This function
1664 * will wake up thread waiting on the wait queue pointed by context1
1668 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
1670 wait_queue_head_t
*pdone_q
;
1671 unsigned long drvr_flag
;
1674 * If pdone_q is empty, the driver thread gave up waiting and
1675 * continued running.
1677 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
1678 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1679 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
1681 wake_up_interruptible(pdone_q
);
1682 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1688 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
1689 * @phba: Pointer to HBA context object.
1690 * @pmb: Pointer to mailbox object.
1692 * This function is the default mailbox completion handler. It
1693 * frees the memory resources associated with the completed mailbox
1694 * command. If the completed command is a REG_LOGIN mailbox command,
1695 * this function will issue a UREG_LOGIN to re-claim the RPI.
1698 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1700 struct lpfc_dmabuf
*mp
;
1704 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1707 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1711 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
1712 (phba
->sli_rev
== LPFC_SLI_REV4
))
1713 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
1716 * If a REG_LOGIN succeeded after node is destroyed or node
1717 * is in re-discovery driver need to cleanup the RPI.
1719 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1720 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
1721 !pmb
->u
.mb
.mbxStatus
) {
1722 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1723 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
- phba
->vpi_base
;
1724 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
1725 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1726 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1727 if (rc
!= MBX_NOT_FINISHED
)
1731 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
1732 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
1734 mempool_free(pmb
, phba
->mbox_mem_pool
);
1738 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
1739 * @phba: Pointer to HBA context object.
1741 * This function is called with no lock held. This function processes all
1742 * the completed mailbox commands and gives it to upper layers. The interrupt
1743 * service routine processes mailbox completion interrupt and adds completed
1744 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1745 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1746 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1747 * function returns the mailbox commands to the upper layer by calling the
1748 * completion handler function of each mailbox.
1751 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
1758 phba
->sli
.slistat
.mbox_event
++;
1760 /* Get all completed mailboxe buffers into the cmplq */
1761 spin_lock_irq(&phba
->hbalock
);
1762 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
1763 spin_unlock_irq(&phba
->hbalock
);
1765 /* Get a Mailbox buffer to setup mailbox commands for callback */
1767 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
1773 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
1775 lpfc_debugfs_disc_trc(pmb
->vport
,
1776 LPFC_DISC_TRC_MBOX_VPORT
,
1777 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1778 (uint32_t)pmbox
->mbxCommand
,
1779 pmbox
->un
.varWords
[0],
1780 pmbox
->un
.varWords
[1]);
1783 lpfc_debugfs_disc_trc(phba
->pport
,
1785 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1786 (uint32_t)pmbox
->mbxCommand
,
1787 pmbox
->un
.varWords
[0],
1788 pmbox
->un
.varWords
[1]);
1793 * It is a fatal error if unknown mbox command completion.
1795 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
1797 /* Unknow mailbox command compl */
1798 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
1799 "(%d):0323 Unknown Mailbox command "
1801 pmb
->vport
? pmb
->vport
->vpi
: 0,
1803 lpfc_sli4_mbox_opcode_get(phba
, pmb
));
1804 phba
->link_state
= LPFC_HBA_ERROR
;
1805 phba
->work_hs
= HS_FFER3
;
1806 lpfc_handle_eratt(phba
);
1810 if (pmbox
->mbxStatus
) {
1811 phba
->sli
.slistat
.mbox_stat_err
++;
1812 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
1813 /* Mbox cmd cmpl error - RETRYing */
1814 lpfc_printf_log(phba
, KERN_INFO
,
1816 "(%d):0305 Mbox cmd cmpl "
1817 "error - RETRYing Data: x%x "
1818 "(x%x) x%x x%x x%x\n",
1819 pmb
->vport
? pmb
->vport
->vpi
:0,
1821 lpfc_sli4_mbox_opcode_get(phba
,
1824 pmbox
->un
.varWords
[0],
1825 pmb
->vport
->port_state
);
1826 pmbox
->mbxStatus
= 0;
1827 pmbox
->mbxOwner
= OWN_HOST
;
1828 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1829 if (rc
!= MBX_NOT_FINISHED
)
1834 /* Mailbox cmd <cmd> Cmpl <cmpl> */
1835 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
1836 "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
1837 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1838 pmb
->vport
? pmb
->vport
->vpi
: 0,
1840 lpfc_sli4_mbox_opcode_get(phba
, pmb
),
1842 *((uint32_t *) pmbox
),
1843 pmbox
->un
.varWords
[0],
1844 pmbox
->un
.varWords
[1],
1845 pmbox
->un
.varWords
[2],
1846 pmbox
->un
.varWords
[3],
1847 pmbox
->un
.varWords
[4],
1848 pmbox
->un
.varWords
[5],
1849 pmbox
->un
.varWords
[6],
1850 pmbox
->un
.varWords
[7]);
1853 pmb
->mbox_cmpl(phba
,pmb
);
1859 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
1860 * @phba: Pointer to HBA context object.
1861 * @pring: Pointer to driver SLI ring object.
1864 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1865 * is set in the tag the buffer is posted for a particular exchange,
1866 * the function will return the buffer without replacing the buffer.
1867 * If the buffer is for unsolicited ELS or CT traffic, this function
1868 * returns the buffer and also posts another buffer to the firmware.
1870 static struct lpfc_dmabuf
*
1871 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
1872 struct lpfc_sli_ring
*pring
,
1875 struct hbq_dmabuf
*hbq_entry
;
1877 if (tag
& QUE_BUFTAG_BIT
)
1878 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
1879 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
1882 return &hbq_entry
->dbuf
;
1886 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
1887 * @phba: Pointer to HBA context object.
1888 * @pring: Pointer to driver SLI ring object.
1889 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
1890 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
1891 * @fch_type: the type for the first frame of the sequence.
1893 * This function is called with no lock held. This function uses the r_ctl and
1894 * type of the received sequence to find the correct callback function to call
1895 * to process the sequence.
1898 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1899 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
1904 /* unSolicited Responses */
1905 if (pring
->prt
[0].profile
) {
1906 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
1907 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
1911 /* We must search, based on rctl / type
1912 for the right routine */
1913 for (i
= 0; i
< pring
->num_mask
; i
++) {
1914 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
1915 (pring
->prt
[i
].type
== fch_type
)) {
1916 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1917 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1918 (phba
, pring
, saveq
);
1926 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
1927 * @phba: Pointer to HBA context object.
1928 * @pring: Pointer to driver SLI ring object.
1929 * @saveq: Pointer to the unsolicited iocb.
1931 * This function is called with no lock held by the ring event handler
1932 * when there is an unsolicited iocb posted to the response ring by the
1933 * firmware. This function gets the buffer associated with the iocbs
1934 * and calls the event handler for the ring. This function handles both
1935 * qring buffers and hbq buffers.
1936 * When the function returns 1 the caller can free the iocb object otherwise
1937 * upper layer functions will free the iocb objects.
1940 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1941 struct lpfc_iocbq
*saveq
)
1945 uint32_t Rctl
, Type
;
1947 struct lpfc_iocbq
*iocbq
;
1948 struct lpfc_dmabuf
*dmzbuf
;
1951 irsp
= &(saveq
->iocb
);
1953 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
1954 if (pring
->lpfc_sli_rcv_async_status
)
1955 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
1957 lpfc_printf_log(phba
,
1960 "0316 Ring %d handler: unexpected "
1961 "ASYNC_STATUS iocb received evt_code "
1964 irsp
->un
.asyncstat
.evt_code
);
1968 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
1969 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
1970 if (irsp
->ulpBdeCount
> 0) {
1971 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
1972 irsp
->un
.ulpWord
[3]);
1973 lpfc_in_buf_free(phba
, dmzbuf
);
1976 if (irsp
->ulpBdeCount
> 1) {
1977 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
1978 irsp
->unsli3
.sli3Words
[3]);
1979 lpfc_in_buf_free(phba
, dmzbuf
);
1982 if (irsp
->ulpBdeCount
> 2) {
1983 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
1984 irsp
->unsli3
.sli3Words
[7]);
1985 lpfc_in_buf_free(phba
, dmzbuf
);
1991 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
1992 if (irsp
->ulpBdeCount
!= 0) {
1993 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
1994 irsp
->un
.ulpWord
[3]);
1995 if (!saveq
->context2
)
1996 lpfc_printf_log(phba
,
1999 "0341 Ring %d Cannot find buffer for "
2000 "an unsolicited iocb. tag 0x%x\n",
2002 irsp
->un
.ulpWord
[3]);
2004 if (irsp
->ulpBdeCount
== 2) {
2005 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2006 irsp
->unsli3
.sli3Words
[7]);
2007 if (!saveq
->context3
)
2008 lpfc_printf_log(phba
,
2011 "0342 Ring %d Cannot find buffer for an"
2012 " unsolicited iocb. tag 0x%x\n",
2014 irsp
->unsli3
.sli3Words
[7]);
2016 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2017 irsp
= &(iocbq
->iocb
);
2018 if (irsp
->ulpBdeCount
!= 0) {
2019 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2020 irsp
->un
.ulpWord
[3]);
2021 if (!iocbq
->context2
)
2022 lpfc_printf_log(phba
,
2025 "0343 Ring %d Cannot find "
2026 "buffer for an unsolicited iocb"
2027 ". tag 0x%x\n", pring
->ringno
,
2028 irsp
->un
.ulpWord
[3]);
2030 if (irsp
->ulpBdeCount
== 2) {
2031 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2032 irsp
->unsli3
.sli3Words
[7]);
2033 if (!iocbq
->context3
)
2034 lpfc_printf_log(phba
,
2037 "0344 Ring %d Cannot find "
2038 "buffer for an unsolicited "
2041 irsp
->unsli3
.sli3Words
[7]);
2045 if (irsp
->ulpBdeCount
!= 0 &&
2046 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2047 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2050 /* search continue save q for same XRI */
2051 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2052 if (iocbq
->iocb
.ulpContext
== saveq
->iocb
.ulpContext
) {
2053 list_add_tail(&saveq
->list
, &iocbq
->list
);
2059 list_add_tail(&saveq
->clist
,
2060 &pring
->iocb_continue_saveq
);
2061 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2062 list_del_init(&iocbq
->clist
);
2064 irsp
= &(saveq
->iocb
);
2068 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2069 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2070 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2074 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2075 Rctl
= w5p
->hcsw
.Rctl
;
2076 Type
= w5p
->hcsw
.Type
;
2078 /* Firmware Workaround */
2079 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2080 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2081 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2084 w5p
->hcsw
.Rctl
= Rctl
;
2085 w5p
->hcsw
.Type
= Type
;
2089 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2090 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2091 "0313 Ring %d handler: unexpected Rctl x%x "
2092 "Type x%x received\n",
2093 pring
->ringno
, Rctl
, Type
);
2099 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2100 * @phba: Pointer to HBA context object.
2101 * @pring: Pointer to driver SLI ring object.
2102 * @prspiocb: Pointer to response iocb object.
2104 * This function looks up the iocb_lookup table to get the command iocb
2105 * corresponding to the given response iocb using the iotag of the
2106 * response iocb. This function is called with the hbalock held.
2107 * This function returns the command iocb object if it finds the command
2108 * iocb else returns NULL.
2110 static struct lpfc_iocbq
*
2111 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2112 struct lpfc_sli_ring
*pring
,
2113 struct lpfc_iocbq
*prspiocb
)
2115 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2118 iotag
= prspiocb
->iocb
.ulpIoTag
;
2120 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2121 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2122 list_del_init(&cmd_iocb
->list
);
2123 pring
->txcmplq_cnt
--;
2127 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2128 "0317 iotag x%x is out off "
2129 "range: max iotag x%x wd0 x%x\n",
2130 iotag
, phba
->sli
.last_iotag
,
2131 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2136 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2137 * @phba: Pointer to HBA context object.
2138 * @pring: Pointer to driver SLI ring object.
2141 * This function looks up the iocb_lookup table to get the command iocb
2142 * corresponding to the given iotag. This function is called with the
2144 * This function returns the command iocb object if it finds the command
2145 * iocb else returns NULL.
2147 static struct lpfc_iocbq
*
2148 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2149 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2151 struct lpfc_iocbq
*cmd_iocb
;
2153 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2154 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2155 list_del_init(&cmd_iocb
->list
);
2156 pring
->txcmplq_cnt
--;
2160 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2161 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2162 iotag
, phba
->sli
.last_iotag
);
2167 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2168 * @phba: Pointer to HBA context object.
2169 * @pring: Pointer to driver SLI ring object.
2170 * @saveq: Pointer to the response iocb to be processed.
2172 * This function is called by the ring event handler for non-fcp
2173 * rings when there is a new response iocb in the response ring.
2174 * The caller is not required to hold any locks. This function
2175 * gets the command iocb associated with the response iocb and
2176 * calls the completion handler for the command iocb. If there
2177 * is no completion handler, the function will free the resources
2178 * associated with command iocb. If the response iocb is for
2179 * an already aborted command iocb, the status of the completion
2180 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2181 * This function always returns 1.
2184 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2185 struct lpfc_iocbq
*saveq
)
2187 struct lpfc_iocbq
*cmdiocbp
;
2189 unsigned long iflag
;
2191 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2192 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2193 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2194 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2197 if (cmdiocbp
->iocb_cmpl
) {
2199 * If an ELS command failed send an event to mgmt
2202 if (saveq
->iocb
.ulpStatus
&&
2203 (pring
->ringno
== LPFC_ELS_RING
) &&
2204 (cmdiocbp
->iocb
.ulpCommand
==
2205 CMD_ELS_REQUEST64_CR
))
2206 lpfc_send_els_failure_event(phba
,
2210 * Post all ELS completions to the worker thread.
2211 * All other are passed to the completion callback.
2213 if (pring
->ringno
== LPFC_ELS_RING
) {
2214 if (cmdiocbp
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
2215 cmdiocbp
->iocb_flag
&=
2216 ~LPFC_DRIVER_ABORTED
;
2217 saveq
->iocb
.ulpStatus
=
2218 IOSTAT_LOCAL_REJECT
;
2219 saveq
->iocb
.un
.ulpWord
[4] =
2222 /* Firmware could still be in progress
2223 * of DMAing payload, so don't free data
2224 * buffer till after a hbeat.
2226 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2229 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2231 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2234 * Unknown initiating command based on the response iotag.
2235 * This could be the case on the ELS ring because of
2238 if (pring
->ringno
!= LPFC_ELS_RING
) {
2240 * Ring <ringno> handler: unexpected completion IoTag
2243 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2244 "0322 Ring %d handler: "
2245 "unexpected completion IoTag x%x "
2246 "Data: x%x x%x x%x x%x\n",
2248 saveq
->iocb
.ulpIoTag
,
2249 saveq
->iocb
.ulpStatus
,
2250 saveq
->iocb
.un
.ulpWord
[4],
2251 saveq
->iocb
.ulpCommand
,
2252 saveq
->iocb
.ulpContext
);
2260 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2261 * @phba: Pointer to HBA context object.
2262 * @pring: Pointer to driver SLI ring object.
2264 * This function is called from the iocb ring event handlers when
2265 * put pointer is ahead of the get pointer for a ring. This function signal
2266 * an error attention condition to the worker thread and the worker
2267 * thread will transition the HBA to offline state.
2270 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2272 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2274 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2275 * rsp ring <portRspMax>
2277 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2278 "0312 Ring %d handler: portRspPut %d "
2279 "is bigger than rsp ring %d\n",
2280 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2283 phba
->link_state
= LPFC_HBA_ERROR
;
2286 * All error attention handlers are posted to
2289 phba
->work_ha
|= HA_ERATT
;
2290 phba
->work_hs
= HS_FFER3
;
2292 lpfc_worker_wake_up(phba
);
2298 * lpfc_poll_eratt - Error attention polling timer timeout handler
2299 * @ptr: Pointer to address of HBA context object.
2301 * This function is invoked by the Error Attention polling timer when the
2302 * timer times out. It will check the SLI Error Attention register for
2303 * possible attention events. If so, it will post an Error Attention event
2304 * and wake up worker thread to process it. Otherwise, it will set up the
2305 * Error Attention polling timer for the next poll.
2307 void lpfc_poll_eratt(unsigned long ptr
)
2309 struct lpfc_hba
*phba
;
2312 phba
= (struct lpfc_hba
*)ptr
;
2314 /* Check chip HA register for error event */
2315 eratt
= lpfc_sli_check_eratt(phba
);
2318 /* Tell the worker thread there is work to do */
2319 lpfc_worker_wake_up(phba
);
2321 /* Restart the timer for next eratt poll */
2322 mod_timer(&phba
->eratt_poll
, jiffies
+
2323 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2328 * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
2329 * @phba: Pointer to HBA context object.
2331 * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
2332 * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
2335 * The caller does not hold any lock.
2336 * The function processes each response iocb in the response ring until it
2337 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2338 * LE bit set. The function will call the completion handler of the command iocb
2339 * if the response iocb indicates a completion for a command iocb or it is
2340 * an abort completion.
2342 void lpfc_sli_poll_fcp_ring(struct lpfc_hba
*phba
)
2344 struct lpfc_sli
*psli
= &phba
->sli
;
2345 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_FCP_RING
];
2346 IOCB_t
*irsp
= NULL
;
2347 IOCB_t
*entry
= NULL
;
2348 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2349 struct lpfc_iocbq rspiocbq
;
2350 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2352 uint32_t portRspPut
, portRspMax
;
2354 uint32_t rsp_cmpl
= 0;
2356 unsigned long iflags
;
2358 pring
->stats
.iocb_event
++;
2361 * The next available response entry should never exceed the maximum
2362 * entries. If it does, treat it as an adapter hardware error.
2364 portRspMax
= pring
->numRiocb
;
2365 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2366 if (unlikely(portRspPut
>= portRspMax
)) {
2367 lpfc_sli_rsp_pointers_error(phba
, pring
);
2372 while (pring
->rspidx
!= portRspPut
) {
2373 entry
= lpfc_resp_iocb(phba
, pring
);
2374 if (++pring
->rspidx
>= portRspMax
)
2377 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2378 (uint32_t *) &rspiocbq
.iocb
,
2379 phba
->iocb_rsp_size
);
2380 irsp
= &rspiocbq
.iocb
;
2381 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2382 pring
->stats
.iocb_rsp
++;
2385 if (unlikely(irsp
->ulpStatus
)) {
2386 /* Rsp ring <ringno> error: IOCB */
2387 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2388 "0326 Rsp Ring %d error: IOCB Data: "
2389 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2391 irsp
->un
.ulpWord
[0],
2392 irsp
->un
.ulpWord
[1],
2393 irsp
->un
.ulpWord
[2],
2394 irsp
->un
.ulpWord
[3],
2395 irsp
->un
.ulpWord
[4],
2396 irsp
->un
.ulpWord
[5],
2397 *(uint32_t *)&irsp
->un1
,
2398 *((uint32_t *)&irsp
->un1
+ 1));
2402 case LPFC_ABORT_IOCB
:
2405 * Idle exchange closed via ABTS from port. No iocb
2406 * resources need to be recovered.
2408 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2409 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2410 "0314 IOCB cmd 0x%x "
2411 "processed. Skipping "
2417 spin_lock_irqsave(&phba
->hbalock
, iflags
);
2418 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2420 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
2421 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
2422 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2427 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2428 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2429 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2430 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2432 dev_warn(&((phba
->pcidev
)->dev
),
2434 phba
->brd_no
, adaptermsg
);
2436 /* Unknown IOCB command */
2437 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2438 "0321 Unknown IOCB command "
2439 "Data: x%x, x%x x%x x%x x%x\n",
2440 type
, irsp
->ulpCommand
,
2449 * The response IOCB has been processed. Update the ring
2450 * pointer in SLIM. If the port response put pointer has not
2451 * been updated, sync the pgp->rspPutInx and fetch the new port
2452 * response put pointer.
2454 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2456 if (pring
->rspidx
== portRspPut
)
2457 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2460 ha_copy
= readl(phba
->HAregaddr
);
2461 ha_copy
>>= (LPFC_FCP_RING
* 4);
2463 if ((rsp_cmpl
> 0) && (ha_copy
& HA_R0RE_REQ
)) {
2464 spin_lock_irqsave(&phba
->hbalock
, iflags
);
2465 pring
->stats
.iocb_rsp_full
++;
2466 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (LPFC_FCP_RING
* 4));
2467 writel(status
, phba
->CAregaddr
);
2468 readl(phba
->CAregaddr
);
2469 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
2471 if ((ha_copy
& HA_R0CE_RSP
) &&
2472 (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
2473 spin_lock_irqsave(&phba
->hbalock
, iflags
);
2474 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
2475 pring
->stats
.iocb_cmd_empty
++;
2477 /* Force update of the local copy of cmdGetInx */
2478 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
2479 lpfc_sli_resume_iocb(phba
, pring
);
2481 if ((pring
->lpfc_sli_cmd_available
))
2482 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
2484 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
2491 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2492 * @phba: Pointer to HBA context object.
2493 * @pring: Pointer to driver SLI ring object.
2494 * @mask: Host attention register mask for this ring.
2496 * This function is called from the interrupt context when there is a ring
2497 * event for the fcp ring. The caller does not hold any lock.
2498 * The function processes each response iocb in the response ring until it
2499 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2500 * LE bit set. The function will call the completion handler of the command iocb
2501 * if the response iocb indicates a completion for a command iocb or it is
2502 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2503 * function if this is an unsolicited iocb.
2504 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2505 * to check it explicitly. This function always returns 1.
2508 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2509 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2511 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2512 IOCB_t
*irsp
= NULL
;
2513 IOCB_t
*entry
= NULL
;
2514 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2515 struct lpfc_iocbq rspiocbq
;
2517 uint32_t portRspPut
, portRspMax
;
2519 lpfc_iocb_type type
;
2520 unsigned long iflag
;
2521 uint32_t rsp_cmpl
= 0;
2523 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2524 pring
->stats
.iocb_event
++;
2527 * The next available response entry should never exceed the maximum
2528 * entries. If it does, treat it as an adapter hardware error.
2530 portRspMax
= pring
->numRiocb
;
2531 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2532 if (unlikely(portRspPut
>= portRspMax
)) {
2533 lpfc_sli_rsp_pointers_error(phba
, pring
);
2534 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2539 while (pring
->rspidx
!= portRspPut
) {
2541 * Fetch an entry off the ring and copy it into a local data
2542 * structure. The copy involves a byte-swap since the
2543 * network byte order and pci byte orders are different.
2545 entry
= lpfc_resp_iocb(phba
, pring
);
2546 phba
->last_completion_time
= jiffies
;
2548 if (++pring
->rspidx
>= portRspMax
)
2551 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2552 (uint32_t *) &rspiocbq
.iocb
,
2553 phba
->iocb_rsp_size
);
2554 INIT_LIST_HEAD(&(rspiocbq
.list
));
2555 irsp
= &rspiocbq
.iocb
;
2557 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2558 pring
->stats
.iocb_rsp
++;
2561 if (unlikely(irsp
->ulpStatus
)) {
2563 * If resource errors reported from HBA, reduce
2564 * queuedepths of the SCSI device.
2566 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2567 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2568 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2569 phba
->lpfc_rampdown_queue_depth(phba
);
2570 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2573 /* Rsp ring <ringno> error: IOCB */
2574 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2575 "0336 Rsp Ring %d error: IOCB Data: "
2576 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2578 irsp
->un
.ulpWord
[0],
2579 irsp
->un
.ulpWord
[1],
2580 irsp
->un
.ulpWord
[2],
2581 irsp
->un
.ulpWord
[3],
2582 irsp
->un
.ulpWord
[4],
2583 irsp
->un
.ulpWord
[5],
2584 *(uint32_t *)&irsp
->un1
,
2585 *((uint32_t *)&irsp
->un1
+ 1));
2589 case LPFC_ABORT_IOCB
:
2592 * Idle exchange closed via ABTS from port. No iocb
2593 * resources need to be recovered.
2595 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2596 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2597 "0333 IOCB cmd 0x%x"
2598 " processed. Skipping"
2604 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2606 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
2607 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
2608 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2611 spin_unlock_irqrestore(&phba
->hbalock
,
2613 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2615 spin_lock_irqsave(&phba
->hbalock
,
2620 case LPFC_UNSOL_IOCB
:
2621 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2622 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2623 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2626 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2627 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2628 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2629 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2631 dev_warn(&((phba
->pcidev
)->dev
),
2633 phba
->brd_no
, adaptermsg
);
2635 /* Unknown IOCB command */
2636 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2637 "0334 Unknown IOCB command "
2638 "Data: x%x, x%x x%x x%x x%x\n",
2639 type
, irsp
->ulpCommand
,
2648 * The response IOCB has been processed. Update the ring
2649 * pointer in SLIM. If the port response put pointer has not
2650 * been updated, sync the pgp->rspPutInx and fetch the new port
2651 * response put pointer.
2653 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2655 if (pring
->rspidx
== portRspPut
)
2656 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2659 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
2660 pring
->stats
.iocb_rsp_full
++;
2661 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
2662 writel(status
, phba
->CAregaddr
);
2663 readl(phba
->CAregaddr
);
2665 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
2666 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
2667 pring
->stats
.iocb_cmd_empty
++;
2669 /* Force update of the local copy of cmdGetInx */
2670 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
2671 lpfc_sli_resume_iocb(phba
, pring
);
2673 if ((pring
->lpfc_sli_cmd_available
))
2674 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
2678 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2683 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
2684 * @phba: Pointer to HBA context object.
2685 * @pring: Pointer to driver SLI ring object.
2686 * @rspiocbp: Pointer to driver response IOCB object.
2688 * This function is called from the worker thread when there is a slow-path
2689 * response IOCB to process. This function chains all the response iocbs until
2690 * seeing the iocb with the LE bit set. The function will call
2691 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
2692 * completion of a command iocb. The function will call the
2693 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
2694 * The function frees the resources or calls the completion handler if this
2695 * iocb is an abort completion. The function returns NULL when the response
2696 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
2697 * this function shall chain the iocb on to the iocb_continueq and return the
2698 * response iocb passed in.
2700 static struct lpfc_iocbq
*
2701 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2702 struct lpfc_iocbq
*rspiocbp
)
2704 struct lpfc_iocbq
*saveq
;
2705 struct lpfc_iocbq
*cmdiocbp
;
2706 struct lpfc_iocbq
*next_iocb
;
2707 IOCB_t
*irsp
= NULL
;
2708 uint32_t free_saveq
;
2709 uint8_t iocb_cmd_type
;
2710 lpfc_iocb_type type
;
2711 unsigned long iflag
;
2714 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2715 /* First add the response iocb to the countinueq list */
2716 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
2717 pring
->iocb_continueq_cnt
++;
2719 /* Now, determine whetehr the list is completed for processing */
2720 irsp
= &rspiocbp
->iocb
;
2723 * By default, the driver expects to free all resources
2724 * associated with this iocb completion.
2727 saveq
= list_get_first(&pring
->iocb_continueq
,
2728 struct lpfc_iocbq
, list
);
2729 irsp
= &(saveq
->iocb
);
2730 list_del_init(&pring
->iocb_continueq
);
2731 pring
->iocb_continueq_cnt
= 0;
2733 pring
->stats
.iocb_rsp
++;
2736 * If resource errors reported from HBA, reduce
2737 * queuedepths of the SCSI device.
2739 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2740 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2741 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2742 phba
->lpfc_rampdown_queue_depth(phba
);
2743 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2746 if (irsp
->ulpStatus
) {
2747 /* Rsp ring <ringno> error: IOCB */
2748 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2749 "0328 Rsp Ring %d error: "
2754 "x%x x%x x%x x%x\n",
2756 irsp
->un
.ulpWord
[0],
2757 irsp
->un
.ulpWord
[1],
2758 irsp
->un
.ulpWord
[2],
2759 irsp
->un
.ulpWord
[3],
2760 irsp
->un
.ulpWord
[4],
2761 irsp
->un
.ulpWord
[5],
2762 *(((uint32_t *) irsp
) + 6),
2763 *(((uint32_t *) irsp
) + 7),
2764 *(((uint32_t *) irsp
) + 8),
2765 *(((uint32_t *) irsp
) + 9),
2766 *(((uint32_t *) irsp
) + 10),
2767 *(((uint32_t *) irsp
) + 11),
2768 *(((uint32_t *) irsp
) + 12),
2769 *(((uint32_t *) irsp
) + 13),
2770 *(((uint32_t *) irsp
) + 14),
2771 *(((uint32_t *) irsp
) + 15));
2775 * Fetch the IOCB command type and call the correct completion
2776 * routine. Solicited and Unsolicited IOCBs on the ELS ring
2777 * get freed back to the lpfc_iocb_list by the discovery
2780 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
2781 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
2784 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2785 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
2786 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2789 case LPFC_UNSOL_IOCB
:
2790 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2791 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
2792 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2797 case LPFC_ABORT_IOCB
:
2799 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
2800 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
2803 /* Call the specified completion routine */
2804 if (cmdiocbp
->iocb_cmpl
) {
2805 spin_unlock_irqrestore(&phba
->hbalock
,
2807 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
2809 spin_lock_irqsave(&phba
->hbalock
,
2812 __lpfc_sli_release_iocbq(phba
,
2817 case LPFC_UNKNOWN_IOCB
:
2818 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2819 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2820 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2821 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
2823 dev_warn(&((phba
->pcidev
)->dev
),
2825 phba
->brd_no
, adaptermsg
);
2827 /* Unknown IOCB command */
2828 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2829 "0335 Unknown IOCB "
2830 "command Data: x%x "
2841 list_for_each_entry_safe(rspiocbp
, next_iocb
,
2842 &saveq
->list
, list
) {
2843 list_del(&rspiocbp
->list
);
2844 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
2846 __lpfc_sli_release_iocbq(phba
, saveq
);
2850 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2855 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
2856 * @phba: Pointer to HBA context object.
2857 * @pring: Pointer to driver SLI ring object.
2858 * @mask: Host attention register mask for this ring.
2860 * This routine wraps the actual slow_ring event process routine from the
2861 * API jump table function pointer from the lpfc_hba struct.
2864 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
2865 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2867 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
2871 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
2872 * @phba: Pointer to HBA context object.
2873 * @pring: Pointer to driver SLI ring object.
2874 * @mask: Host attention register mask for this ring.
2876 * This function is called from the worker thread when there is a ring event
2877 * for non-fcp rings. The caller does not hold any lock. The function will
2878 * remove each response iocb in the response ring and calls the handle
2879 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2882 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
2883 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2885 struct lpfc_pgp
*pgp
;
2887 IOCB_t
*irsp
= NULL
;
2888 struct lpfc_iocbq
*rspiocbp
= NULL
;
2889 uint32_t portRspPut
, portRspMax
;
2890 unsigned long iflag
;
2893 pgp
= &phba
->port_gp
[pring
->ringno
];
2894 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2895 pring
->stats
.iocb_event
++;
2898 * The next available response entry should never exceed the maximum
2899 * entries. If it does, treat it as an adapter hardware error.
2901 portRspMax
= pring
->numRiocb
;
2902 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2903 if (portRspPut
>= portRspMax
) {
2905 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2906 * rsp ring <portRspMax>
2908 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2909 "0303 Ring %d handler: portRspPut %d "
2910 "is bigger than rsp ring %d\n",
2911 pring
->ringno
, portRspPut
, portRspMax
);
2913 phba
->link_state
= LPFC_HBA_ERROR
;
2914 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2916 phba
->work_hs
= HS_FFER3
;
2917 lpfc_handle_eratt(phba
);
2923 while (pring
->rspidx
!= portRspPut
) {
2925 * Build a completion list and call the appropriate handler.
2926 * The process is to get the next available response iocb, get
2927 * a free iocb from the list, copy the response data into the
2928 * free iocb, insert to the continuation list, and update the
2929 * next response index to slim. This process makes response
2930 * iocb's in the ring available to DMA as fast as possible but
2931 * pays a penalty for a copy operation. Since the iocb is
2932 * only 32 bytes, this penalty is considered small relative to
2933 * the PCI reads for register values and a slim write. When
2934 * the ulpLe field is set, the entire Command has been
2937 entry
= lpfc_resp_iocb(phba
, pring
);
2939 phba
->last_completion_time
= jiffies
;
2940 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
2941 if (rspiocbp
== NULL
) {
2942 printk(KERN_ERR
"%s: out of buffers! Failing "
2943 "completion.\n", __func__
);
2947 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
2948 phba
->iocb_rsp_size
);
2949 irsp
= &rspiocbp
->iocb
;
2951 if (++pring
->rspidx
>= portRspMax
)
2954 if (pring
->ringno
== LPFC_ELS_RING
) {
2955 lpfc_debugfs_slow_ring_trc(phba
,
2956 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2957 *(((uint32_t *) irsp
) + 4),
2958 *(((uint32_t *) irsp
) + 6),
2959 *(((uint32_t *) irsp
) + 7));
2962 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2964 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2965 /* Handle the response IOCB */
2966 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
2967 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2970 * If the port response put pointer has not been updated, sync
2971 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
2972 * response put pointer.
2974 if (pring
->rspidx
== portRspPut
) {
2975 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2977 } /* while (pring->rspidx != portRspPut) */
2979 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
2980 /* At least one response entry has been freed */
2981 pring
->stats
.iocb_rsp_full
++;
2982 /* SET RxRE_RSP in Chip Att register */
2983 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
2984 writel(status
, phba
->CAregaddr
);
2985 readl(phba
->CAregaddr
); /* flush */
2987 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
2988 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
2989 pring
->stats
.iocb_cmd_empty
++;
2991 /* Force update of the local copy of cmdGetInx */
2992 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
2993 lpfc_sli_resume_iocb(phba
, pring
);
2995 if ((pring
->lpfc_sli_cmd_available
))
2996 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3000 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3005 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3006 * @phba: Pointer to HBA context object.
3007 * @pring: Pointer to driver SLI ring object.
3008 * @mask: Host attention register mask for this ring.
3010 * This function is called from the worker thread when there is a pending
3011 * ELS response iocb on the driver internal slow-path response iocb worker
3012 * queue. The caller does not hold any lock. The function will remove each
3013 * response iocb from the response worker queue and calls the handle
3014 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3017 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3018 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3020 struct lpfc_iocbq
*irspiocbq
;
3021 unsigned long iflag
;
3023 while (!list_empty(&phba
->sli4_hba
.sp_rspiocb_work_queue
)) {
3024 /* Get the response iocb from the head of work queue */
3025 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3026 list_remove_head(&phba
->sli4_hba
.sp_rspiocb_work_queue
,
3027 irspiocbq
, struct lpfc_iocbq
, list
);
3028 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3029 /* Process the response iocb */
3030 lpfc_sli_sp_handle_rspiocb(phba
, pring
, irspiocbq
);
3035 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3036 * @phba: Pointer to HBA context object.
3037 * @pring: Pointer to driver SLI ring object.
3039 * This function aborts all iocbs in the given ring and frees all the iocb
3040 * objects in txq. This function issues an abort iocb for all the iocb commands
3041 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3042 * the return of this function. The caller is not required to hold any locks.
3045 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3047 LIST_HEAD(completions
);
3048 struct lpfc_iocbq
*iocb
, *next_iocb
;
3050 if (pring
->ringno
== LPFC_ELS_RING
) {
3051 lpfc_fabric_abort_hba(phba
);
3054 /* Error everything on txq and txcmplq
3057 spin_lock_irq(&phba
->hbalock
);
3058 list_splice_init(&pring
->txq
, &completions
);
3061 /* Next issue ABTS for everything on the txcmplq */
3062 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3063 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3065 spin_unlock_irq(&phba
->hbalock
);
3067 /* Cancel all the IOCBs from the completions list */
3068 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3073 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3074 * @phba: Pointer to HBA context object.
3076 * This function flushes all iocbs in the fcp ring and frees all the iocb
3077 * objects in txq and txcmplq. This function will not issue abort iocbs
3078 * for all the iocb commands in txcmplq, they will just be returned with
3079 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3080 * slot has been permanently disabled.
3083 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3087 struct lpfc_sli
*psli
= &phba
->sli
;
3088 struct lpfc_sli_ring
*pring
;
3090 /* Currently, only one fcp ring */
3091 pring
= &psli
->ring
[psli
->fcp_ring
];
3093 spin_lock_irq(&phba
->hbalock
);
3094 /* Retrieve everything on txq */
3095 list_splice_init(&pring
->txq
, &txq
);
3098 /* Retrieve everything on the txcmplq */
3099 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3100 pring
->txcmplq_cnt
= 0;
3101 spin_unlock_irq(&phba
->hbalock
);
3104 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3107 /* Flush the txcmpq */
3108 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3113 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3114 * @phba: Pointer to HBA context object.
3115 * @mask: Bit mask to be checked.
3117 * This function reads the host status register and compares
3118 * with the provided bit mask to check if HBA completed
3119 * the restart. This function will wait in a loop for the
3120 * HBA to complete restart. If the HBA does not restart within
3121 * 15 iterations, the function will reset the HBA again. The
3122 * function returns 1 when HBA fail to restart otherwise returns
3126 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3132 /* Read the HBA Host Status Register */
3133 status
= readl(phba
->HSregaddr
);
3136 * Check status register every 100ms for 5 retries, then every
3137 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3138 * every 2.5 sec for 4.
3139 * Break our of the loop if errors occurred during init.
3141 while (((status
& mask
) != mask
) &&
3142 !(status
& HS_FFERM
) &&
3154 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3155 lpfc_sli_brdrestart(phba
);
3157 /* Read the HBA Host Status Register */
3158 status
= readl(phba
->HSregaddr
);
3161 /* Check to see if any errors occurred during init */
3162 if ((status
& HS_FFERM
) || (i
>= 20)) {
3163 phba
->link_state
= LPFC_HBA_ERROR
;
3171 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3172 * @phba: Pointer to HBA context object.
3173 * @mask: Bit mask to be checked.
3175 * This function checks the host status register to check if HBA is
3176 * ready. This function will wait in a loop for the HBA to be ready
3177 * If the HBA is not ready , the function will will reset the HBA PCI
3178 * function again. The function returns 1 when HBA fail to be ready
3179 * otherwise returns zero.
3182 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3187 /* Read the HBA Host Status Register */
3188 status
= lpfc_sli4_post_status_check(phba
);
3191 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3192 lpfc_sli_brdrestart(phba
);
3193 status
= lpfc_sli4_post_status_check(phba
);
3196 /* Check to see if any errors occurred during init */
3198 phba
->link_state
= LPFC_HBA_ERROR
;
3201 phba
->sli4_hba
.intr_enable
= 0;
3207 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3208 * @phba: Pointer to HBA context object.
3209 * @mask: Bit mask to be checked.
3211 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3212 * from the API jump table function pointer from the lpfc_hba struct.
3215 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3217 return phba
->lpfc_sli_brdready(phba
, mask
);
3220 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3223 * lpfc_reset_barrier - Make HBA ready for HBA reset
3224 * @phba: Pointer to HBA context object.
3226 * This function is called before resetting an HBA. This
3227 * function requests HBA to quiesce DMAs before a reset.
3229 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3231 uint32_t __iomem
*resp_buf
;
3232 uint32_t __iomem
*mbox_buf
;
3233 volatile uint32_t mbox
;
3238 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3239 if (hdrtype
!= 0x80 ||
3240 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3241 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3245 * Tell the other part of the chip to suspend temporarily all
3248 resp_buf
= phba
->MBslimaddr
;
3250 /* Disable the error attention */
3251 hc_copy
= readl(phba
->HCregaddr
);
3252 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3253 readl(phba
->HCregaddr
); /* flush */
3254 phba
->link_flag
|= LS_IGNORE_ERATT
;
3256 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3257 /* Clear Chip error bit */
3258 writel(HA_ERATT
, phba
->HAregaddr
);
3259 phba
->pport
->stopped
= 1;
3263 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3264 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3266 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3267 mbox_buf
= phba
->MBslimaddr
;
3268 writel(mbox
, mbox_buf
);
3271 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
3274 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
3275 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3276 phba
->pport
->stopped
)
3282 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3283 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
3288 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
3291 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3292 writel(HA_ERATT
, phba
->HAregaddr
);
3293 phba
->pport
->stopped
= 1;
3297 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3298 writel(hc_copy
, phba
->HCregaddr
);
3299 readl(phba
->HCregaddr
); /* flush */
3303 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3304 * @phba: Pointer to HBA context object.
3306 * This function issues a kill_board mailbox command and waits for
3307 * the error attention interrupt. This function is called for stopping
3308 * the firmware processing. The caller is not required to hold any
3309 * locks. This function calls lpfc_hba_down_post function to free
3310 * any pending commands after the kill. The function will return 1 when it
3311 * fails to kill the board else will return 0.
3314 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3316 struct lpfc_sli
*psli
;
3326 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3327 "0329 Kill HBA Data: x%x x%x\n",
3328 phba
->pport
->port_state
, psli
->sli_flag
);
3330 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3334 /* Disable the error attention */
3335 spin_lock_irq(&phba
->hbalock
);
3336 status
= readl(phba
->HCregaddr
);
3337 status
&= ~HC_ERINT_ENA
;
3338 writel(status
, phba
->HCregaddr
);
3339 readl(phba
->HCregaddr
); /* flush */
3340 phba
->link_flag
|= LS_IGNORE_ERATT
;
3341 spin_unlock_irq(&phba
->hbalock
);
3343 lpfc_kill_board(phba
, pmb
);
3344 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3345 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3347 if (retval
!= MBX_SUCCESS
) {
3348 if (retval
!= MBX_BUSY
)
3349 mempool_free(pmb
, phba
->mbox_mem_pool
);
3350 spin_lock_irq(&phba
->hbalock
);
3351 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3352 spin_unlock_irq(&phba
->hbalock
);
3356 spin_lock_irq(&phba
->hbalock
);
3357 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3358 spin_unlock_irq(&phba
->hbalock
);
3360 mempool_free(pmb
, phba
->mbox_mem_pool
);
3362 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3363 * attention every 100ms for 3 seconds. If we don't get ERATT after
3364 * 3 seconds we still set HBA_ERROR state because the status of the
3365 * board is now undefined.
3367 ha_copy
= readl(phba
->HAregaddr
);
3369 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3371 ha_copy
= readl(phba
->HAregaddr
);
3374 del_timer_sync(&psli
->mbox_tmo
);
3375 if (ha_copy
& HA_ERATT
) {
3376 writel(HA_ERATT
, phba
->HAregaddr
);
3377 phba
->pport
->stopped
= 1;
3379 spin_lock_irq(&phba
->hbalock
);
3380 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3381 psli
->mbox_active
= NULL
;
3382 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3383 spin_unlock_irq(&phba
->hbalock
);
3385 lpfc_hba_down_post(phba
);
3386 phba
->link_state
= LPFC_HBA_ERROR
;
3388 return ha_copy
& HA_ERATT
? 0 : 1;
3392 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3393 * @phba: Pointer to HBA context object.
3395 * This function resets the HBA by writing HC_INITFF to the control
3396 * register. After the HBA resets, this function resets all the iocb ring
3397 * indices. This function disables PCI layer parity checking during
3399 * This function returns 0 always.
3400 * The caller is not required to hold any locks.
3403 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3405 struct lpfc_sli
*psli
;
3406 struct lpfc_sli_ring
*pring
;
3413 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3414 "0325 Reset HBA Data: x%x x%x\n",
3415 phba
->pport
->port_state
, psli
->sli_flag
);
3417 /* perform board reset */
3418 phba
->fc_eventTag
= 0;
3419 phba
->pport
->fc_myDID
= 0;
3420 phba
->pport
->fc_prevDID
= 0;
3422 /* Turn off parity checking and serr during the physical reset */
3423 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3424 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3426 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3428 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3430 /* Now toggle INITFF bit in the Host Control Register */
3431 writel(HC_INITFF
, phba
->HCregaddr
);
3433 readl(phba
->HCregaddr
); /* flush */
3434 writel(0, phba
->HCregaddr
);
3435 readl(phba
->HCregaddr
); /* flush */
3437 /* Restore PCI cmd register */
3438 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3440 /* Initialize relevant SLI info */
3441 for (i
= 0; i
< psli
->num_rings
; i
++) {
3442 pring
= &psli
->ring
[i
];
3445 pring
->next_cmdidx
= 0;
3446 pring
->local_getidx
= 0;
3448 pring
->missbufcnt
= 0;
3451 phba
->link_state
= LPFC_WARM_START
;
3456 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3457 * @phba: Pointer to HBA context object.
3459 * This function resets a SLI4 HBA. This function disables PCI layer parity
3460 * checking during resets the device. The caller is not required to hold
3463 * This function returns 0 always.
3466 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3468 struct lpfc_sli
*psli
= &phba
->sli
;
3473 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3474 "0295 Reset HBA Data: x%x x%x\n",
3475 phba
->pport
->port_state
, psli
->sli_flag
);
3477 /* perform board reset */
3478 phba
->fc_eventTag
= 0;
3479 phba
->pport
->fc_myDID
= 0;
3480 phba
->pport
->fc_prevDID
= 0;
3482 /* Turn off parity checking and serr during the physical reset */
3483 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3484 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3486 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3488 spin_lock_irq(&phba
->hbalock
);
3489 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3490 phba
->fcf
.fcf_flag
= 0;
3491 /* Clean up the child queue list for the CQs */
3492 list_del_init(&phba
->sli4_hba
.mbx_wq
->list
);
3493 list_del_init(&phba
->sli4_hba
.els_wq
->list
);
3494 list_del_init(&phba
->sli4_hba
.hdr_rq
->list
);
3495 list_del_init(&phba
->sli4_hba
.dat_rq
->list
);
3496 list_del_init(&phba
->sli4_hba
.mbx_cq
->list
);
3497 list_del_init(&phba
->sli4_hba
.els_cq
->list
);
3498 list_del_init(&phba
->sli4_hba
.rxq_cq
->list
);
3499 for (qindx
= 0; qindx
< phba
->cfg_fcp_wq_count
; qindx
++)
3500 list_del_init(&phba
->sli4_hba
.fcp_wq
[qindx
]->list
);
3501 for (qindx
= 0; qindx
< phba
->cfg_fcp_eq_count
; qindx
++)
3502 list_del_init(&phba
->sli4_hba
.fcp_cq
[qindx
]->list
);
3503 spin_unlock_irq(&phba
->hbalock
);
3505 /* Now physically reset the device */
3506 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3507 "0389 Performing PCI function reset!\n");
3508 /* Perform FCoE PCI function reset */
3509 lpfc_pci_function_reset(phba
);
3515 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3516 * @phba: Pointer to HBA context object.
3518 * This function is called in the SLI initialization code path to
3519 * restart the HBA. The caller is not required to hold any lock.
3520 * This function writes MBX_RESTART mailbox command to the SLIM and
3521 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3522 * function to free any pending commands. The function enables
3523 * POST only during the first initialization. The function returns zero.
3524 * The function does not guarantee completion of MBX_RESTART mailbox
3525 * command before the return of this function.
3528 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3531 struct lpfc_sli
*psli
;
3532 volatile uint32_t word0
;
3533 void __iomem
*to_slim
;
3535 spin_lock_irq(&phba
->hbalock
);
3540 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3541 "0337 Restart HBA Data: x%x x%x\n",
3542 phba
->pport
->port_state
, psli
->sli_flag
);
3545 mb
= (MAILBOX_t
*) &word0
;
3546 mb
->mbxCommand
= MBX_RESTART
;
3549 lpfc_reset_barrier(phba
);
3551 to_slim
= phba
->MBslimaddr
;
3552 writel(*(uint32_t *) mb
, to_slim
);
3553 readl(to_slim
); /* flush */
3555 /* Only skip post after fc_ffinit is completed */
3556 if (phba
->pport
->port_state
)
3557 word0
= 1; /* This is really setting up word1 */
3559 word0
= 0; /* This is really setting up word1 */
3560 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
3561 writel(*(uint32_t *) mb
, to_slim
);
3562 readl(to_slim
); /* flush */
3564 lpfc_sli_brdreset(phba
);
3565 phba
->pport
->stopped
= 0;
3566 phba
->link_state
= LPFC_INIT_START
;
3568 spin_unlock_irq(&phba
->hbalock
);
3570 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3571 psli
->stats_start
= get_seconds();
3573 /* Give the INITFF and Post time to settle. */
3576 lpfc_hba_down_post(phba
);
3582 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3583 * @phba: Pointer to HBA context object.
3585 * This function is called in the SLI initialization code path to restart
3586 * a SLI4 HBA. The caller is not required to hold any lock.
3587 * At the end of the function, it calls lpfc_hba_down_post function to
3588 * free any pending commands.
3591 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
3593 struct lpfc_sli
*psli
= &phba
->sli
;
3597 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3598 "0296 Restart HBA Data: x%x x%x\n",
3599 phba
->pport
->port_state
, psli
->sli_flag
);
3601 lpfc_sli4_brdreset(phba
);
3603 spin_lock_irq(&phba
->hbalock
);
3604 phba
->pport
->stopped
= 0;
3605 phba
->link_state
= LPFC_INIT_START
;
3607 spin_unlock_irq(&phba
->hbalock
);
3609 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3610 psli
->stats_start
= get_seconds();
3612 lpfc_hba_down_post(phba
);
3618 * lpfc_sli_brdrestart - Wrapper func for restarting hba
3619 * @phba: Pointer to HBA context object.
3621 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
3622 * API jump table function pointer from the lpfc_hba struct.
3625 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
3627 return phba
->lpfc_sli_brdrestart(phba
);
3631 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
3632 * @phba: Pointer to HBA context object.
3634 * This function is called after a HBA restart to wait for successful
3635 * restart of the HBA. Successful restart of the HBA is indicated by
3636 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
3637 * iteration, the function will restart the HBA again. The function returns
3638 * zero if HBA successfully restarted else returns negative error code.
3641 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
3643 uint32_t status
, i
= 0;
3645 /* Read the HBA Host Status Register */
3646 status
= readl(phba
->HSregaddr
);
3648 /* Check status register to see what current state is */
3650 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
3652 /* Check every 100ms for 5 retries, then every 500ms for 5, then
3653 * every 2.5 sec for 5, then reset board and every 2.5 sec for
3657 /* Adapter failed to init, timeout, status reg
3659 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3660 "0436 Adapter failed to init, "
3661 "timeout, status reg x%x, "
3662 "FW Data: A8 x%x AC x%x\n", status
,
3663 readl(phba
->MBslimaddr
+ 0xa8),
3664 readl(phba
->MBslimaddr
+ 0xac));
3665 phba
->link_state
= LPFC_HBA_ERROR
;
3669 /* Check to see if any errors occurred during init */
3670 if (status
& HS_FFERM
) {
3671 /* ERROR: During chipset initialization */
3672 /* Adapter failed to init, chipset, status reg
3674 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3675 "0437 Adapter failed to init, "
3676 "chipset, status reg x%x, "
3677 "FW Data: A8 x%x AC x%x\n", status
,
3678 readl(phba
->MBslimaddr
+ 0xa8),
3679 readl(phba
->MBslimaddr
+ 0xac));
3680 phba
->link_state
= LPFC_HBA_ERROR
;
3686 } else if (i
<= 10) {
3694 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3695 lpfc_sli_brdrestart(phba
);
3697 /* Read the HBA Host Status Register */
3698 status
= readl(phba
->HSregaddr
);
3701 /* Check to see if any errors occurred during init */
3702 if (status
& HS_FFERM
) {
3703 /* ERROR: During chipset initialization */
3704 /* Adapter failed to init, chipset, status reg <status> */
3705 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3706 "0438 Adapter failed to init, chipset, "
3708 "FW Data: A8 x%x AC x%x\n", status
,
3709 readl(phba
->MBslimaddr
+ 0xa8),
3710 readl(phba
->MBslimaddr
+ 0xac));
3711 phba
->link_state
= LPFC_HBA_ERROR
;
3715 /* Clear all interrupt enable conditions */
3716 writel(0, phba
->HCregaddr
);
3717 readl(phba
->HCregaddr
); /* flush */
3719 /* setup host attn register */
3720 writel(0xffffffff, phba
->HAregaddr
);
3721 readl(phba
->HAregaddr
); /* flush */
3726 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
3728 * This function calculates and returns the number of HBQs required to be
3732 lpfc_sli_hbq_count(void)
3734 return ARRAY_SIZE(lpfc_hbq_defs
);
3738 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
3740 * This function adds the number of hbq entries in every HBQ to get
3741 * the total number of hbq entries required for the HBA and returns
3745 lpfc_sli_hbq_entry_count(void)
3747 int hbq_count
= lpfc_sli_hbq_count();
3751 for (i
= 0; i
< hbq_count
; ++i
)
3752 count
+= lpfc_hbq_defs
[i
]->entry_count
;
3757 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
3759 * This function calculates amount of memory required for all hbq entries
3760 * to be configured and returns the total memory required.
3763 lpfc_sli_hbq_size(void)
3765 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
3769 * lpfc_sli_hbq_setup - configure and initialize HBQs
3770 * @phba: Pointer to HBA context object.
3772 * This function is called during the SLI initialization to configure
3773 * all the HBQs and post buffers to the HBQ. The caller is not
3774 * required to hold any locks. This function will return zero if successful
3775 * else it will return negative error code.
3778 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
3780 int hbq_count
= lpfc_sli_hbq_count();
3784 uint32_t hbq_entry_index
;
3786 /* Get a Mailbox buffer to setup mailbox
3787 * commands for HBA initialization
3789 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3796 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
3797 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
3798 phba
->hbq_in_use
= 1;
3800 hbq_entry_index
= 0;
3801 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
3802 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
3803 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
3804 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
3805 phba
->hbqs
[hbqno
].entry_count
=
3806 lpfc_hbq_defs
[hbqno
]->entry_count
;
3807 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
3808 hbq_entry_index
, pmb
);
3809 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
3811 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
3812 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
3813 mbxStatus <status>, ring <num> */
3815 lpfc_printf_log(phba
, KERN_ERR
,
3816 LOG_SLI
| LOG_VPORT
,
3817 "1805 Adapter failed to init. "
3818 "Data: x%x x%x x%x\n",
3820 pmbox
->mbxStatus
, hbqno
);
3822 phba
->link_state
= LPFC_HBA_ERROR
;
3823 mempool_free(pmb
, phba
->mbox_mem_pool
);
3827 phba
->hbq_count
= hbq_count
;
3829 mempool_free(pmb
, phba
->mbox_mem_pool
);
3831 /* Initially populate or replenish the HBQs */
3832 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
3833 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
3838 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
3839 * @phba: Pointer to HBA context object.
3841 * This function is called during the SLI initialization to configure
3842 * all the HBQs and post buffers to the HBQ. The caller is not
3843 * required to hold any locks. This function will return zero if successful
3844 * else it will return negative error code.
3847 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
3849 phba
->hbq_in_use
= 1;
3850 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
3851 phba
->hbq_count
= 1;
3852 /* Initially populate or replenish the HBQs */
3853 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
3858 * lpfc_sli_config_port - Issue config port mailbox command
3859 * @phba: Pointer to HBA context object.
3860 * @sli_mode: sli mode - 2/3
3862 * This function is called by the sli intialization code path
3863 * to issue config_port mailbox command. This function restarts the
3864 * HBA firmware and issues a config_port mailbox command to configure
3865 * the SLI interface in the sli mode specified by sli_mode
3866 * variable. The caller is not required to hold any locks.
3867 * The function returns 0 if successful, else returns negative error
3871 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
3874 uint32_t resetcount
= 0, rc
= 0, done
= 0;
3876 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3878 phba
->link_state
= LPFC_HBA_ERROR
;
3882 phba
->sli_rev
= sli_mode
;
3883 while (resetcount
< 2 && !done
) {
3884 spin_lock_irq(&phba
->hbalock
);
3885 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
3886 spin_unlock_irq(&phba
->hbalock
);
3887 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3888 lpfc_sli_brdrestart(phba
);
3889 rc
= lpfc_sli_chipset_init(phba
);
3893 spin_lock_irq(&phba
->hbalock
);
3894 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3895 spin_unlock_irq(&phba
->hbalock
);
3898 /* Call pre CONFIG_PORT mailbox command initialization. A
3899 * value of 0 means the call was successful. Any other
3900 * nonzero value is a failure, but if ERESTART is returned,
3901 * the driver may reset the HBA and try again.
3903 rc
= lpfc_config_port_prep(phba
);
3904 if (rc
== -ERESTART
) {
3905 phba
->link_state
= LPFC_LINK_UNKNOWN
;
3909 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
3910 lpfc_config_port(phba
, pmb
);
3911 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
3912 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
3913 LPFC_SLI3_HBQ_ENABLED
|
3914 LPFC_SLI3_CRP_ENABLED
|
3915 LPFC_SLI3_INB_ENABLED
|
3916 LPFC_SLI3_BG_ENABLED
);
3917 if (rc
!= MBX_SUCCESS
) {
3918 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3919 "0442 Adapter failed to init, mbxCmd x%x "
3920 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3921 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
3922 spin_lock_irq(&phba
->hbalock
);
3923 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
3924 spin_unlock_irq(&phba
->hbalock
);
3927 /* Allow asynchronous mailbox command to go through */
3928 spin_lock_irq(&phba
->hbalock
);
3929 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
3930 spin_unlock_irq(&phba
->hbalock
);
3936 goto do_prep_failed
;
3938 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
3939 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
3941 goto do_prep_failed
;
3943 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
3944 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
3945 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
3946 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
3947 phba
->max_vpi
: phba
->max_vports
;
3951 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
)
3952 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
3953 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
3954 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
3955 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
3956 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
3957 if (pmb
->u
.mb
.un
.varCfgPort
.ginb
) {
3958 phba
->sli3_options
|= LPFC_SLI3_INB_ENABLED
;
3959 phba
->hbq_get
= phba
->mbox
->us
.s3_inb_pgp
.hbq_get
;
3960 phba
->port_gp
= phba
->mbox
->us
.s3_inb_pgp
.port
;
3961 phba
->inb_ha_copy
= &phba
->mbox
->us
.s3_inb_pgp
.ha_copy
;
3962 phba
->inb_counter
= &phba
->mbox
->us
.s3_inb_pgp
.counter
;
3963 phba
->inb_last_counter
=
3964 phba
->mbox
->us
.s3_inb_pgp
.counter
;
3966 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
3967 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
3968 phba
->inb_ha_copy
= NULL
;
3969 phba
->inb_counter
= NULL
;
3972 if (phba
->cfg_enable_bg
) {
3973 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
3974 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
3976 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3977 "0443 Adapter did not grant "
3981 phba
->hbq_get
= NULL
;
3982 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
3983 phba
->inb_ha_copy
= NULL
;
3984 phba
->inb_counter
= NULL
;
3988 mempool_free(pmb
, phba
->mbox_mem_pool
);
3994 * lpfc_sli_hba_setup - SLI intialization function
3995 * @phba: Pointer to HBA context object.
3997 * This function is the main SLI intialization function. This function
3998 * is called by the HBA intialization code, HBA reset code and HBA
3999 * error attention handler code. Caller is not required to hold any
4000 * locks. This function issues config_port mailbox command to configure
4001 * the SLI, setup iocb rings and HBQ rings. In the end the function
4002 * calls the config_port_post function to issue init_link mailbox
4003 * command and to start the discovery. The function will return zero
4004 * if successful, else it will return negative error code.
4007 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4012 switch (lpfc_sli_mode
) {
4014 if (phba
->cfg_enable_npiv
) {
4015 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4016 "1824 NPIV enabled: Override lpfc_sli_mode "
4017 "parameter (%d) to auto (0).\n",
4027 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4028 "1819 Unrecognized lpfc_sli_mode "
4029 "parameter: %d.\n", lpfc_sli_mode
);
4034 rc
= lpfc_sli_config_port(phba
, mode
);
4036 if (rc
&& lpfc_sli_mode
== 3)
4037 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4038 "1820 Unable to select SLI-3. "
4039 "Not supported by adapter.\n");
4040 if (rc
&& mode
!= 2)
4041 rc
= lpfc_sli_config_port(phba
, 2);
4043 goto lpfc_sli_hba_setup_error
;
4045 if (phba
->sli_rev
== 3) {
4046 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4047 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4049 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4050 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4051 phba
->sli3_options
= 0;
4054 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4055 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4056 phba
->sli_rev
, phba
->max_vpi
);
4057 rc
= lpfc_sli_ring_map(phba
);
4060 goto lpfc_sli_hba_setup_error
;
4063 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4064 rc
= lpfc_sli_hbq_setup(phba
);
4066 goto lpfc_sli_hba_setup_error
;
4068 spin_lock_irq(&phba
->hbalock
);
4069 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4070 spin_unlock_irq(&phba
->hbalock
);
4072 rc
= lpfc_config_port_post(phba
);
4074 goto lpfc_sli_hba_setup_error
;
4078 lpfc_sli_hba_setup_error
:
4079 phba
->link_state
= LPFC_HBA_ERROR
;
4080 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4081 "0445 Firmware initialization failed\n");
4086 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4087 * @phba: Pointer to HBA context object.
4088 * @mboxq: mailbox pointer.
4089 * This function issue a dump mailbox command to read config region
4090 * 23 and parse the records in the region and populate driver
4094 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
,
4095 LPFC_MBOXQ_t
*mboxq
)
4097 struct lpfc_dmabuf
*mp
;
4098 struct lpfc_mqe
*mqe
;
4099 uint32_t data_length
;
4102 /* Program the default value of vlan_id and fc_map */
4103 phba
->valid_vlan
= 0;
4104 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4105 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4106 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4108 mqe
= &mboxq
->u
.mqe
;
4109 if (lpfc_dump_fcoe_param(phba
, mboxq
))
4112 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4113 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4115 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4116 "(%d):2571 Mailbox cmd x%x Status x%x "
4117 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4118 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4119 "CQ: x%x x%x x%x x%x\n",
4120 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4121 bf_get(lpfc_mqe_command
, mqe
),
4122 bf_get(lpfc_mqe_status
, mqe
),
4123 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4124 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4125 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4126 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4127 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4128 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4129 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4130 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4131 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4133 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4134 mboxq
->mcqe
.trailer
);
4137 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4141 data_length
= mqe
->un
.mb_words
[5];
4142 if (data_length
> DMP_RGN23_SIZE
) {
4143 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4148 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4149 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4155 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4156 * @phba: pointer to lpfc hba data structure.
4157 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4158 * @vpd: pointer to the memory to hold resulting port vpd data.
4159 * @vpd_size: On input, the number of bytes allocated to @vpd.
4160 * On output, the number of data bytes in @vpd.
4162 * This routine executes a READ_REV SLI4 mailbox command. In
4163 * addition, this routine gets the port vpd data.
4167 * ENOMEM - could not allocated memory.
4170 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4171 uint8_t *vpd
, uint32_t *vpd_size
)
4175 struct lpfc_dmabuf
*dmabuf
;
4176 struct lpfc_mqe
*mqe
;
4178 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4183 * Get a DMA buffer for the vpd data resulting from the READ_REV
4186 dma_size
= *vpd_size
;
4187 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4191 if (!dmabuf
->virt
) {
4195 memset(dmabuf
->virt
, 0, dma_size
);
4198 * The SLI4 implementation of READ_REV conflicts at word1,
4199 * bits 31:16 and SLI4 adds vpd functionality not present
4200 * in SLI3. This code corrects the conflicts.
4202 lpfc_read_rev(phba
, mboxq
);
4203 mqe
= &mboxq
->u
.mqe
;
4204 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4205 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4206 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4207 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4208 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4210 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4212 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4213 dmabuf
->virt
, dmabuf
->phys
);
4218 * The available vpd length cannot be bigger than the
4219 * DMA buffer passed to the port. Catch the less than
4220 * case and update the caller's size.
4222 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4223 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4225 lpfc_sli_pcimem_bcopy(dmabuf
->virt
, vpd
, *vpd_size
);
4226 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4227 dmabuf
->virt
, dmabuf
->phys
);
4233 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4234 * @phba: pointer to lpfc hba data structure.
4236 * This routine is called to explicitly arm the SLI4 device's completion and
4240 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4244 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4245 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4246 lpfc_sli4_cq_release(phba
->sli4_hba
.rxq_cq
, LPFC_QUEUE_REARM
);
4247 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4248 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4250 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4251 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4252 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4257 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4258 * @phba: Pointer to HBA context object.
4260 * This function is the main SLI4 device intialization PCI function. This
4261 * function is called by the HBA intialization code, HBA reset code and
4262 * HBA error attention handler code. Caller is not required to hold any
4266 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
4269 LPFC_MBOXQ_t
*mboxq
;
4270 struct lpfc_mqe
*mqe
;
4273 uint32_t ftr_rsp
= 0;
4274 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
4275 struct lpfc_vport
*vport
= phba
->pport
;
4276 struct lpfc_dmabuf
*mp
;
4278 /* Perform a PCI function reset to start from clean */
4279 rc
= lpfc_pci_function_reset(phba
);
4283 /* Check the HBA Host Status Register for readyness */
4284 rc
= lpfc_sli4_post_status_check(phba
);
4288 spin_lock_irq(&phba
->hbalock
);
4289 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
4290 spin_unlock_irq(&phba
->hbalock
);
4294 * Allocate a single mailbox container for initializing the
4297 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4302 * Continue initialization with default values even if driver failed
4303 * to read FCoE param config regions
4305 if (lpfc_sli4_read_fcoe_params(phba
, mboxq
))
4306 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4307 "2570 Failed to read FCoE parameters\n");
4309 /* Issue READ_REV to collect vpd and FW information. */
4310 vpd_size
= PAGE_SIZE
;
4311 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
4317 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
4321 mqe
= &mboxq
->u
.mqe
;
4322 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
4323 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
4324 phba
->hba_flag
|= HBA_FCOE_SUPPORT
;
4325 if (phba
->sli_rev
!= LPFC_SLI_REV4
||
4326 !(phba
->hba_flag
& HBA_FCOE_SUPPORT
)) {
4327 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4328 "0376 READ_REV Error. SLI Level %d "
4329 "FCoE enabled %d\n",
4330 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_SUPPORT
);
4335 * Evaluate the read rev and vpd data. Populate the driver
4336 * state with the results. If this routine fails, the failure
4337 * is not fatal as the driver will use generic values.
4339 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
4340 if (unlikely(!rc
)) {
4341 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4342 "0377 Error %d parsing vpd. "
4343 "Using defaults.\n", rc
);
4347 /* Save information as VPD data */
4348 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
4349 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
4350 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
4351 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
4353 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
4355 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
4357 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
4359 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4360 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
4361 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
4362 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
4363 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4364 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
4365 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4366 "(%d):0380 READ_REV Status x%x "
4367 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
4368 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4369 bf_get(lpfc_mqe_status
, mqe
),
4370 phba
->vpd
.rev
.opFwName
,
4371 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
4372 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
4375 * Discover the port's supported feature set and match it against the
4378 lpfc_request_features(phba
, mboxq
);
4379 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4386 * The port must support FCP initiator mode as this is the
4387 * only mode running in the host.
4389 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
4390 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4391 "0378 No support for fcpi mode.\n");
4396 * If the port cannot support the host's requested features
4397 * then turn off the global config parameters to disable the
4398 * feature in the driver. This is not a fatal error.
4400 if ((phba
->cfg_enable_bg
) &&
4401 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4404 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
4405 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4409 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4410 "0379 Feature Mismatch Data: x%08x %08x "
4411 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
4412 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
4413 phba
->cfg_enable_npiv
, phba
->max_vpi
);
4414 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4415 phba
->cfg_enable_bg
= 0;
4416 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4417 phba
->cfg_enable_npiv
= 0;
4420 /* These SLI3 features are assumed in SLI4 */
4421 spin_lock_irq(&phba
->hbalock
);
4422 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
4423 spin_unlock_irq(&phba
->hbalock
);
4425 /* Read the port's service parameters. */
4426 lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
4427 mboxq
->vport
= vport
;
4428 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4429 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4430 if (rc
== MBX_SUCCESS
) {
4431 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
4436 * This memory was allocated by the lpfc_read_sparam routine. Release
4437 * it to the mbuf pool.
4439 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4441 mboxq
->context1
= NULL
;
4443 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4444 "0382 READ_SPARAM command failed "
4445 "status %d, mbxStatus x%x\n",
4446 rc
, bf_get(lpfc_mqe_status
, mqe
));
4447 phba
->link_state
= LPFC_HBA_ERROR
;
4452 if (phba
->cfg_soft_wwnn
)
4453 u64_to_wwn(phba
->cfg_soft_wwnn
,
4454 vport
->fc_sparam
.nodeName
.u
.wwn
);
4455 if (phba
->cfg_soft_wwpn
)
4456 u64_to_wwn(phba
->cfg_soft_wwpn
,
4457 vport
->fc_sparam
.portName
.u
.wwn
);
4458 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
4459 sizeof(struct lpfc_name
));
4460 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
4461 sizeof(struct lpfc_name
));
4463 /* Update the fc_host data structures with new wwn. */
4464 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
4465 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
4467 /* Register SGL pool to the device using non-embedded mailbox command */
4468 rc
= lpfc_sli4_post_sgl_list(phba
);
4470 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4471 "0582 Error %d during sgl post operation", rc
);
4476 /* Register SCSI SGL pool to the device */
4477 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
4479 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4480 "0383 Error %d during scsi sgl post opeation",
4482 /* Some Scsi buffers were moved to the abort scsi list */
4483 /* A pci function reset will repost them */
4488 /* Post the rpi header region to the device. */
4489 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
4491 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4492 "0393 Error %d during rpi post operation\n",
4497 if (phba
->cfg_enable_fip
)
4498 bf_set(lpfc_fip_flag
, &phba
->sli4_hba
.sli4_flags
, 1);
4500 bf_set(lpfc_fip_flag
, &phba
->sli4_hba
.sli4_flags
, 0);
4502 /* Set up all the queues to the device */
4503 rc
= lpfc_sli4_queue_setup(phba
);
4505 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4506 "0381 Error %d during queue setup.\n ", rc
);
4507 goto out_stop_timers
;
4510 /* Arm the CQs and then EQs on device */
4511 lpfc_sli4_arm_cqeq_intr(phba
);
4513 /* Indicate device interrupt mode */
4514 phba
->sli4_hba
.intr_enable
= 1;
4516 /* Allow asynchronous mailbox command to go through */
4517 spin_lock_irq(&phba
->hbalock
);
4518 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4519 spin_unlock_irq(&phba
->hbalock
);
4521 /* Post receive buffers to the device */
4522 lpfc_sli4_rb_setup(phba
);
4524 /* Start the ELS watchdog timer */
4525 mod_timer(&vport
->els_tmofunc
,
4526 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
4528 /* Start heart beat timer */
4529 mod_timer(&phba
->hb_tmofunc
,
4530 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
4531 phba
->hb_outstanding
= 0;
4532 phba
->last_completion_time
= jiffies
;
4534 /* Start error attention (ERATT) polling timer */
4535 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
4538 * The port is ready, set the host's link state to LINK_DOWN
4539 * in preparation for link interrupts.
4541 lpfc_init_link(phba
, mboxq
, phba
->cfg_topology
, phba
->cfg_link_speed
);
4542 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4543 lpfc_set_loopback_flag(phba
);
4544 /* Change driver state to LPFC_LINK_DOWN right before init link */
4545 spin_lock_irq(&phba
->hbalock
);
4546 phba
->link_state
= LPFC_LINK_DOWN
;
4547 spin_unlock_irq(&phba
->hbalock
);
4548 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
4549 if (unlikely(rc
!= MBX_NOT_FINISHED
)) {
4555 /* Unset all the queues set up in this routine when error out */
4557 lpfc_sli4_queue_unset(phba
);
4561 lpfc_stop_hba_timers(phba
);
4565 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4570 * lpfc_mbox_timeout - Timeout call back function for mbox timer
4571 * @ptr: context object - pointer to hba structure.
4573 * This is the callback function for mailbox timer. The mailbox
4574 * timer is armed when a new mailbox command is issued and the timer
4575 * is deleted when the mailbox complete. The function is called by
4576 * the kernel timer code when a mailbox does not complete within
4577 * expected time. This function wakes up the worker thread to
4578 * process the mailbox timeout and returns. All the processing is
4579 * done by the worker thread function lpfc_mbox_timeout_handler.
4582 lpfc_mbox_timeout(unsigned long ptr
)
4584 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4585 unsigned long iflag
;
4586 uint32_t tmo_posted
;
4588 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
4589 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
4591 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
4592 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
4595 lpfc_worker_wake_up(phba
);
4601 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
4602 * @phba: Pointer to HBA context object.
4604 * This function is called from worker thread when a mailbox command times out.
4605 * The caller is not required to hold any locks. This function will reset the
4606 * HBA and recover all the pending commands.
4609 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
4611 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
4612 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
4613 struct lpfc_sli
*psli
= &phba
->sli
;
4614 struct lpfc_sli_ring
*pring
;
4616 /* Check the pmbox pointer first. There is a race condition
4617 * between the mbox timeout handler getting executed in the
4618 * worklist and the mailbox actually completing. When this
4619 * race condition occurs, the mbox_active will be NULL.
4621 spin_lock_irq(&phba
->hbalock
);
4622 if (pmbox
== NULL
) {
4623 lpfc_printf_log(phba
, KERN_WARNING
,
4625 "0353 Active Mailbox cleared - mailbox timeout "
4627 spin_unlock_irq(&phba
->hbalock
);
4631 /* Mbox cmd <mbxCommand> timeout */
4632 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4633 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
4635 phba
->pport
->port_state
,
4637 phba
->sli
.mbox_active
);
4638 spin_unlock_irq(&phba
->hbalock
);
4640 /* Setting state unknown so lpfc_sli_abort_iocb_ring
4641 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
4642 * it to fail all oustanding SCSI IO.
4644 spin_lock_irq(&phba
->pport
->work_port_lock
);
4645 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
4646 spin_unlock_irq(&phba
->pport
->work_port_lock
);
4647 spin_lock_irq(&phba
->hbalock
);
4648 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4649 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
4650 spin_unlock_irq(&phba
->hbalock
);
4652 pring
= &psli
->ring
[psli
->fcp_ring
];
4653 lpfc_sli_abort_iocb_ring(phba
, pring
);
4655 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4656 "0345 Resetting board due to mailbox timeout\n");
4658 /* Reset the HBA device */
4659 lpfc_reset_hba(phba
);
4663 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
4664 * @phba: Pointer to HBA context object.
4665 * @pmbox: Pointer to mailbox object.
4666 * @flag: Flag indicating how the mailbox need to be processed.
4668 * This function is called by discovery code and HBA management code
4669 * to submit a mailbox command to firmware with SLI-3 interface spec. This
4670 * function gets the hbalock to protect the data structures.
4671 * The mailbox command can be submitted in polling mode, in which case
4672 * this function will wait in a polling loop for the completion of the
4674 * If the mailbox is submitted in no_wait mode (not polling) the
4675 * function will submit the command and returns immediately without waiting
4676 * for the mailbox completion. The no_wait is supported only when HBA
4677 * is in SLI2/SLI3 mode - interrupts are enabled.
4678 * The SLI interface allows only one mailbox pending at a time. If the
4679 * mailbox is issued in polling mode and there is already a mailbox
4680 * pending, then the function will return an error. If the mailbox is issued
4681 * in NO_WAIT mode and there is a mailbox pending already, the function
4682 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
4683 * The sli layer owns the mailbox object until the completion of mailbox
4684 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
4685 * return codes the caller owns the mailbox command after the return of
4689 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
4693 struct lpfc_sli
*psli
= &phba
->sli
;
4694 uint32_t status
, evtctr
;
4697 unsigned long timeout
;
4698 unsigned long drvr_flag
= 0;
4699 uint32_t word0
, ldata
;
4700 void __iomem
*to_slim
;
4701 int processing_queue
= 0;
4703 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
4705 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4706 /* processing mbox queue from intr_handler */
4707 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
4708 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4711 processing_queue
= 1;
4712 pmbox
= lpfc_mbox_get(phba
);
4714 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4719 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
4720 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
4722 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4723 lpfc_printf_log(phba
, KERN_ERR
,
4724 LOG_MBOX
| LOG_VPORT
,
4725 "1806 Mbox x%x failed. No vport\n",
4726 pmbox
->u
.mb
.mbxCommand
);
4728 goto out_not_finished
;
4732 /* If the PCI channel is in offline state, do not post mbox. */
4733 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
4734 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4735 goto out_not_finished
;
4738 /* If HBA has a deferred error attention, fail the iocb. */
4739 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
4740 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4741 goto out_not_finished
;
4747 status
= MBX_SUCCESS
;
4749 if (phba
->link_state
== LPFC_HBA_ERROR
) {
4750 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4752 /* Mbox command <mbxCommand> cannot issue */
4753 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4754 "(%d):0311 Mailbox command x%x cannot "
4755 "issue Data: x%x x%x\n",
4756 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4757 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
4758 goto out_not_finished
;
4761 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
4762 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
4763 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4764 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4765 "(%d):2528 Mailbox command x%x cannot "
4766 "issue Data: x%x x%x\n",
4767 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4768 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
4769 goto out_not_finished
;
4772 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
4773 /* Polling for a mbox command when another one is already active
4774 * is not allowed in SLI. Also, the driver must have established
4775 * SLI2 mode to queue and process multiple mbox commands.
4778 if (flag
& MBX_POLL
) {
4779 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4781 /* Mbox command <mbxCommand> cannot issue */
4782 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4783 "(%d):2529 Mailbox command x%x "
4784 "cannot issue Data: x%x x%x\n",
4785 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4786 pmbox
->u
.mb
.mbxCommand
,
4787 psli
->sli_flag
, flag
);
4788 goto out_not_finished
;
4791 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
4792 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4793 /* Mbox command <mbxCommand> cannot issue */
4794 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4795 "(%d):2530 Mailbox command x%x "
4796 "cannot issue Data: x%x x%x\n",
4797 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4798 pmbox
->u
.mb
.mbxCommand
,
4799 psli
->sli_flag
, flag
);
4800 goto out_not_finished
;
4803 /* Another mailbox command is still being processed, queue this
4804 * command to be processed later.
4806 lpfc_mbox_put(phba
, pmbox
);
4808 /* Mbox cmd issue - BUSY */
4809 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4810 "(%d):0308 Mbox cmd issue - BUSY Data: "
4811 "x%x x%x x%x x%x\n",
4812 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
4813 mb
->mbxCommand
, phba
->pport
->port_state
,
4814 psli
->sli_flag
, flag
);
4816 psli
->slistat
.mbox_busy
++;
4817 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4820 lpfc_debugfs_disc_trc(pmbox
->vport
,
4821 LPFC_DISC_TRC_MBOX_VPORT
,
4822 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
4823 (uint32_t)mb
->mbxCommand
,
4824 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4827 lpfc_debugfs_disc_trc(phba
->pport
,
4829 "MBOX Bsy: cmd:x%x mb:x%x x%x",
4830 (uint32_t)mb
->mbxCommand
,
4831 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4837 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4839 /* If we are not polling, we MUST be in SLI2 mode */
4840 if (flag
!= MBX_POLL
) {
4841 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
4842 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
4843 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4844 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4845 /* Mbox command <mbxCommand> cannot issue */
4846 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4847 "(%d):2531 Mailbox command x%x "
4848 "cannot issue Data: x%x x%x\n",
4849 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4850 pmbox
->u
.mb
.mbxCommand
,
4851 psli
->sli_flag
, flag
);
4852 goto out_not_finished
;
4854 /* timeout active mbox command */
4855 mod_timer(&psli
->mbox_tmo
, (jiffies
+
4856 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
4859 /* Mailbox cmd <cmd> issue */
4860 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4861 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
4863 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4864 mb
->mbxCommand
, phba
->pport
->port_state
,
4865 psli
->sli_flag
, flag
);
4867 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
4869 lpfc_debugfs_disc_trc(pmbox
->vport
,
4870 LPFC_DISC_TRC_MBOX_VPORT
,
4871 "MBOX Send vport: cmd:x%x mb:x%x x%x",
4872 (uint32_t)mb
->mbxCommand
,
4873 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4876 lpfc_debugfs_disc_trc(phba
->pport
,
4878 "MBOX Send: cmd:x%x mb:x%x x%x",
4879 (uint32_t)mb
->mbxCommand
,
4880 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4884 psli
->slistat
.mbox_cmd
++;
4885 evtctr
= psli
->slistat
.mbox_event
;
4887 /* next set own bit for the adapter and copy over command word */
4888 mb
->mbxOwner
= OWN_CHIP
;
4890 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4891 /* First copy command data to host SLIM area */
4892 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
4894 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4895 /* copy command data into host mbox for cmpl */
4896 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
4899 /* First copy mbox command data to HBA SLIM, skip past first
4901 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4902 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
4903 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
4905 /* Next copy over first word, with mbxOwner set */
4906 ldata
= *((uint32_t *)mb
);
4907 to_slim
= phba
->MBslimaddr
;
4908 writel(ldata
, to_slim
);
4909 readl(to_slim
); /* flush */
4911 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4912 /* switch over to host mailbox */
4913 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
4921 /* Set up reference to mailbox command */
4922 psli
->mbox_active
= pmbox
;
4923 /* Interrupt board to do it */
4924 writel(CA_MBATT
, phba
->CAregaddr
);
4925 readl(phba
->CAregaddr
); /* flush */
4926 /* Don't wait for it to finish, just return */
4930 /* Set up null reference to mailbox command */
4931 psli
->mbox_active
= NULL
;
4932 /* Interrupt board to do it */
4933 writel(CA_MBATT
, phba
->CAregaddr
);
4934 readl(phba
->CAregaddr
); /* flush */
4936 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4937 /* First read mbox status word */
4938 word0
= *((uint32_t *)phba
->mbox
);
4939 word0
= le32_to_cpu(word0
);
4941 /* First read mbox status word */
4942 word0
= readl(phba
->MBslimaddr
);
4945 /* Read the HBA Host Attention Register */
4946 ha_copy
= readl(phba
->HAregaddr
);
4947 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
4951 /* Wait for command to complete */
4952 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
4953 (!(ha_copy
& HA_MBATT
) &&
4954 (phba
->link_state
> LPFC_WARM_START
))) {
4955 if (time_after(jiffies
, timeout
)) {
4956 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4957 spin_unlock_irqrestore(&phba
->hbalock
,
4959 goto out_not_finished
;
4962 /* Check if we took a mbox interrupt while we were
4964 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
4965 && (evtctr
!= psli
->slistat
.mbox_event
))
4969 spin_unlock_irqrestore(&phba
->hbalock
,
4972 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
4975 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4976 /* First copy command data */
4977 word0
= *((uint32_t *)phba
->mbox
);
4978 word0
= le32_to_cpu(word0
);
4979 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4982 /* Check real SLIM for any errors */
4983 slimword0
= readl(phba
->MBslimaddr
);
4984 slimmb
= (MAILBOX_t
*) & slimword0
;
4985 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
4986 && slimmb
->mbxStatus
) {
4993 /* First copy command data */
4994 word0
= readl(phba
->MBslimaddr
);
4996 /* Read the HBA Host Attention Register */
4997 ha_copy
= readl(phba
->HAregaddr
);
5000 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5001 /* copy results back to user */
5002 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
5004 /* First copy command data */
5005 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
5007 if ((mb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
5009 lpfc_memcpy_from_slim((void *)pmbox
->context2
,
5010 phba
->MBslimaddr
+ DMP_RSP_OFFSET
,
5011 mb
->un
.varDmp
.word_cnt
);
5015 writel(HA_MBATT
, phba
->HAregaddr
);
5016 readl(phba
->HAregaddr
); /* flush */
5018 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5019 status
= mb
->mbxStatus
;
5022 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5026 if (processing_queue
) {
5027 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5028 lpfc_mbox_cmpl_put(phba
, pmbox
);
5030 return MBX_NOT_FINISHED
;
5034 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
5035 * @phba: Pointer to HBA context object.
5037 * The function blocks the posting of SLI4 asynchronous mailbox commands from
5038 * the driver internal pending mailbox queue. It will then try to wait out the
5039 * possible outstanding mailbox command before return.
5042 * 0 - the outstanding mailbox command completed; otherwise, the wait for
5043 * the outstanding mailbox command timed out.
5046 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
5048 struct lpfc_sli
*psli
= &phba
->sli
;
5049 uint8_t actcmd
= MBX_HEARTBEAT
;
5051 unsigned long timeout
;
5053 /* Mark the asynchronous mailbox command posting as blocked */
5054 spin_lock_irq(&phba
->hbalock
);
5055 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
5056 if (phba
->sli
.mbox_active
)
5057 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
5058 spin_unlock_irq(&phba
->hbalock
);
5059 /* Determine how long we might wait for the active mailbox
5060 * command to be gracefully completed by firmware.
5062 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) * 1000) +
5064 /* Wait for the outstnading mailbox command to complete */
5065 while (phba
->sli
.mbox_active
) {
5066 /* Check active mailbox complete status every 2ms */
5068 if (time_after(jiffies
, timeout
)) {
5069 /* Timeout, marked the outstanding cmd not complete */
5075 /* Can not cleanly block async mailbox command, fails it */
5077 spin_lock_irq(&phba
->hbalock
);
5078 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5079 spin_unlock_irq(&phba
->hbalock
);
5085 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
5086 * @phba: Pointer to HBA context object.
5088 * The function unblocks and resume posting of SLI4 asynchronous mailbox
5089 * commands from the driver internal pending mailbox queue. It makes sure
5090 * that there is no outstanding mailbox command before resuming posting
5091 * asynchronous mailbox commands. If, for any reason, there is outstanding
5092 * mailbox command, it will try to wait it out before resuming asynchronous
5093 * mailbox command posting.
5096 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
5098 struct lpfc_sli
*psli
= &phba
->sli
;
5100 spin_lock_irq(&phba
->hbalock
);
5101 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5102 /* Asynchronous mailbox posting is not blocked, do nothing */
5103 spin_unlock_irq(&phba
->hbalock
);
5107 /* Outstanding synchronous mailbox command is guaranteed to be done,
5108 * successful or timeout, after timing-out the outstanding mailbox
5109 * command shall always be removed, so just unblock posting async
5110 * mailbox command and resume
5112 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5113 spin_unlock_irq(&phba
->hbalock
);
5115 /* wake up worker thread to post asynchronlous mailbox command */
5116 lpfc_worker_wake_up(phba
);
5120 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5121 * @phba: Pointer to HBA context object.
5122 * @mboxq: Pointer to mailbox object.
5124 * The function posts a mailbox to the port. The mailbox is expected
5125 * to be comletely filled in and ready for the port to operate on it.
5126 * This routine executes a synchronous completion operation on the
5127 * mailbox by polling for its completion.
5129 * The caller must not be holding any locks when calling this routine.
5132 * MBX_SUCCESS - mailbox posted successfully
5133 * Any of the MBX error values.
5136 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
5138 int rc
= MBX_SUCCESS
;
5139 unsigned long iflag
;
5141 uint32_t mcqe_status
;
5143 unsigned long timeout
;
5144 struct lpfc_sli
*psli
= &phba
->sli
;
5145 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
5146 struct lpfc_bmbx_create
*mbox_rgn
;
5147 struct dma_address
*dma_address
;
5148 struct lpfc_register bmbx_reg
;
5151 * Only one mailbox can be active to the bootstrap mailbox region
5152 * at a time and there is no queueing provided.
5154 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5155 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5156 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5157 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5158 "(%d):2532 Mailbox command x%x (x%x) "
5159 "cannot issue Data: x%x x%x\n",
5160 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5161 mboxq
->u
.mb
.mbxCommand
,
5162 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5163 psli
->sli_flag
, MBX_POLL
);
5164 return MBXERR_ERROR
;
5166 /* The server grabs the token and owns it until release */
5167 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5168 phba
->sli
.mbox_active
= mboxq
;
5169 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5172 * Initialize the bootstrap memory region to avoid stale data areas
5173 * in the mailbox post. Then copy the caller's mailbox contents to
5174 * the bmbx mailbox region.
5176 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
5177 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
5178 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
5179 sizeof(struct lpfc_mqe
));
5181 /* Post the high mailbox dma address to the port and wait for ready. */
5182 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
5183 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
5185 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5188 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5189 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5193 if (time_after(jiffies
, timeout
)) {
5197 } while (!db_ready
);
5199 /* Post the low mailbox dma address to the port. */
5200 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
5201 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5204 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5205 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5209 if (time_after(jiffies
, timeout
)) {
5213 } while (!db_ready
);
5216 * Read the CQ to ensure the mailbox has completed.
5217 * If so, update the mailbox status so that the upper layers
5218 * can complete the request normally.
5220 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
5221 sizeof(struct lpfc_mqe
));
5222 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
5223 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
5224 sizeof(struct lpfc_mcqe
));
5225 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
5227 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5228 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
5229 bf_set(lpfc_mqe_status
, mb
, LPFC_MBX_ERROR_RANGE
| mcqe_status
);
5233 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5234 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5235 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5236 " x%x x%x CQ: x%x x%x x%x x%x\n",
5237 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5238 mbx_cmnd
, lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5239 bf_get(lpfc_mqe_status
, mb
),
5240 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
5241 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
5242 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
5243 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
5244 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
5245 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
5246 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
5247 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5248 mboxq
->mcqe
.trailer
);
5250 /* We are holding the token, no needed for lock when release */
5251 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5252 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5253 phba
->sli
.mbox_active
= NULL
;
5254 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5259 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5260 * @phba: Pointer to HBA context object.
5261 * @pmbox: Pointer to mailbox object.
5262 * @flag: Flag indicating how the mailbox need to be processed.
5264 * This function is called by discovery code and HBA management code to submit
5265 * a mailbox command to firmware with SLI-4 interface spec.
5267 * Return codes the caller owns the mailbox command after the return of the
5271 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5274 struct lpfc_sli
*psli
= &phba
->sli
;
5275 unsigned long iflags
;
5278 rc
= lpfc_mbox_dev_check(phba
);
5280 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5281 "(%d):2544 Mailbox command x%x (x%x) "
5282 "cannot issue Data: x%x x%x\n",
5283 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5284 mboxq
->u
.mb
.mbxCommand
,
5285 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5286 psli
->sli_flag
, flag
);
5287 goto out_not_finished
;
5290 /* Detect polling mode and jump to a handler */
5291 if (!phba
->sli4_hba
.intr_enable
) {
5292 if (flag
== MBX_POLL
)
5293 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5296 if (rc
!= MBX_SUCCESS
)
5297 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5298 "(%d):2541 Mailbox command x%x "
5299 "(x%x) cannot issue Data: x%x x%x\n",
5300 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5301 mboxq
->u
.mb
.mbxCommand
,
5302 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5303 psli
->sli_flag
, flag
);
5305 } else if (flag
== MBX_POLL
) {
5306 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
5307 "(%d):2542 Try to issue mailbox command "
5308 "x%x (x%x) synchronously ahead of async"
5309 "mailbox command queue: x%x x%x\n",
5310 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5311 mboxq
->u
.mb
.mbxCommand
,
5312 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5313 psli
->sli_flag
, flag
);
5314 /* Try to block the asynchronous mailbox posting */
5315 rc
= lpfc_sli4_async_mbox_block(phba
);
5317 /* Successfully blocked, now issue sync mbox cmd */
5318 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5319 if (rc
!= MBX_SUCCESS
)
5320 lpfc_printf_log(phba
, KERN_ERR
,
5322 "(%d):2597 Mailbox command "
5323 "x%x (x%x) cannot issue "
5326 mboxq
->vport
->vpi
: 0,
5327 mboxq
->u
.mb
.mbxCommand
,
5328 lpfc_sli4_mbox_opcode_get(phba
,
5330 psli
->sli_flag
, flag
);
5331 /* Unblock the async mailbox posting afterward */
5332 lpfc_sli4_async_mbox_unblock(phba
);
5337 /* Now, interrupt mode asynchrous mailbox command */
5338 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
5340 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5341 "(%d):2543 Mailbox command x%x (x%x) "
5342 "cannot issue Data: x%x x%x\n",
5343 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5344 mboxq
->u
.mb
.mbxCommand
,
5345 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5346 psli
->sli_flag
, flag
);
5347 goto out_not_finished
;
5350 /* Put the mailbox command to the driver internal FIFO */
5351 psli
->slistat
.mbox_busy
++;
5352 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5353 lpfc_mbox_put(phba
, mboxq
);
5354 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5355 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5356 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5357 "x%x (x%x) x%x x%x x%x\n",
5358 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
5359 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5360 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5361 phba
->pport
->port_state
,
5362 psli
->sli_flag
, MBX_NOWAIT
);
5363 /* Wake up worker thread to transport mailbox command from head */
5364 lpfc_worker_wake_up(phba
);
5369 return MBX_NOT_FINISHED
;
5373 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5374 * @phba: Pointer to HBA context object.
5376 * This function is called by worker thread to send a mailbox command to
5377 * SLI4 HBA firmware.
5381 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
5383 struct lpfc_sli
*psli
= &phba
->sli
;
5384 LPFC_MBOXQ_t
*mboxq
;
5385 int rc
= MBX_SUCCESS
;
5386 unsigned long iflags
;
5387 struct lpfc_mqe
*mqe
;
5390 /* Check interrupt mode before post async mailbox command */
5391 if (unlikely(!phba
->sli4_hba
.intr_enable
))
5392 return MBX_NOT_FINISHED
;
5394 /* Check for mailbox command service token */
5395 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5396 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5397 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5398 return MBX_NOT_FINISHED
;
5400 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5401 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5402 return MBX_NOT_FINISHED
;
5404 if (unlikely(phba
->sli
.mbox_active
)) {
5405 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5406 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5407 "0384 There is pending active mailbox cmd\n");
5408 return MBX_NOT_FINISHED
;
5410 /* Take the mailbox command service token */
5411 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5413 /* Get the next mailbox command from head of queue */
5414 mboxq
= lpfc_mbox_get(phba
);
5416 /* If no more mailbox command waiting for post, we're done */
5418 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5419 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5422 phba
->sli
.mbox_active
= mboxq
;
5423 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5425 /* Check device readiness for posting mailbox command */
5426 rc
= lpfc_mbox_dev_check(phba
);
5428 /* Driver clean routine will clean up pending mailbox */
5429 goto out_not_finished
;
5431 /* Prepare the mbox command to be posted */
5432 mqe
= &mboxq
->u
.mqe
;
5433 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
5435 /* Start timer for the mbox_tmo and log some mailbox post messages */
5436 mod_timer(&psli
->mbox_tmo
, (jiffies
+
5437 (HZ
* lpfc_mbox_tmo_val(phba
, mbx_cmnd
))));
5439 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5440 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5442 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
5443 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5444 phba
->pport
->port_state
, psli
->sli_flag
);
5446 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
5448 lpfc_debugfs_disc_trc(mboxq
->vport
,
5449 LPFC_DISC_TRC_MBOX_VPORT
,
5450 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5451 mbx_cmnd
, mqe
->un
.mb_words
[0],
5452 mqe
->un
.mb_words
[1]);
5454 lpfc_debugfs_disc_trc(phba
->pport
,
5456 "MBOX Send: cmd:x%x mb:x%x x%x",
5457 mbx_cmnd
, mqe
->un
.mb_words
[0],
5458 mqe
->un
.mb_words
[1]);
5461 psli
->slistat
.mbox_cmd
++;
5463 /* Post the mailbox command to the port */
5464 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
5465 if (rc
!= MBX_SUCCESS
) {
5466 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5467 "(%d):2533 Mailbox command x%x (x%x) "
5468 "cannot issue Data: x%x x%x\n",
5469 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5470 mboxq
->u
.mb
.mbxCommand
,
5471 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5472 psli
->sli_flag
, MBX_NOWAIT
);
5473 goto out_not_finished
;
5479 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5480 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5481 __lpfc_mbox_cmpl_put(phba
, mboxq
);
5482 /* Release the token */
5483 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5484 phba
->sli
.mbox_active
= NULL
;
5485 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5487 return MBX_NOT_FINISHED
;
5491 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5492 * @phba: Pointer to HBA context object.
5493 * @pmbox: Pointer to mailbox object.
5494 * @flag: Flag indicating how the mailbox need to be processed.
5496 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5497 * the API jump table function pointer from the lpfc_hba struct.
5499 * Return codes the caller owns the mailbox command after the return of the
5503 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
5505 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
5509 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5510 * @phba: The hba struct for which this call is being executed.
5511 * @dev_grp: The HBA PCI-Device group number.
5513 * This routine sets up the mbox interface API function jump table in @phba
5515 * Returns: 0 - success, -ENODEV - failure.
5518 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5522 case LPFC_PCI_DEV_LP
:
5523 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
5524 phba
->lpfc_sli_handle_slow_ring_event
=
5525 lpfc_sli_handle_slow_ring_event_s3
;
5526 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
5527 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
5528 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
5530 case LPFC_PCI_DEV_OC
:
5531 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
5532 phba
->lpfc_sli_handle_slow_ring_event
=
5533 lpfc_sli_handle_slow_ring_event_s4
;
5534 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
5535 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
5536 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
5539 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5540 "1420 Invalid HBA PCI-device group: 0x%x\n",
5549 * __lpfc_sli_ringtx_put - Add an iocb to the txq
5550 * @phba: Pointer to HBA context object.
5551 * @pring: Pointer to driver SLI ring object.
5552 * @piocb: Pointer to address of newly added command iocb.
5554 * This function is called with hbalock held to add a command
5555 * iocb to the txq when SLI layer cannot submit the command iocb
5559 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5560 struct lpfc_iocbq
*piocb
)
5562 /* Insert the caller's iocb in the txq tail for later processing. */
5563 list_add_tail(&piocb
->list
, &pring
->txq
);
5568 * lpfc_sli_next_iocb - Get the next iocb in the txq
5569 * @phba: Pointer to HBA context object.
5570 * @pring: Pointer to driver SLI ring object.
5571 * @piocb: Pointer to address of newly added command iocb.
5573 * This function is called with hbalock held before a new
5574 * iocb is submitted to the firmware. This function checks
5575 * txq to flush the iocbs in txq to Firmware before
5576 * submitting new iocbs to the Firmware.
5577 * If there are iocbs in the txq which need to be submitted
5578 * to firmware, lpfc_sli_next_iocb returns the first element
5579 * of the txq after dequeuing it from txq.
5580 * If there is no iocb in the txq then the function will return
5581 * *piocb and *piocb is set to NULL. Caller needs to check
5582 * *piocb to find if there are more commands in the txq.
5584 static struct lpfc_iocbq
*
5585 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5586 struct lpfc_iocbq
**piocb
)
5588 struct lpfc_iocbq
* nextiocb
;
5590 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
5600 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
5601 * @phba: Pointer to HBA context object.
5602 * @ring_number: SLI ring number to issue iocb on.
5603 * @piocb: Pointer to command iocb.
5604 * @flag: Flag indicating if this command can be put into txq.
5606 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
5607 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
5608 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
5609 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
5610 * this function allows only iocbs for posting buffers. This function finds
5611 * next available slot in the command ring and posts the command to the
5612 * available slot and writes the port attention register to request HBA start
5613 * processing new iocb. If there is no slot available in the ring and
5614 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
5615 * the function returns IOCB_BUSY.
5617 * This function is called with hbalock held. The function will return success
5618 * after it successfully submit the iocb to firmware or after adding to the
5622 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
5623 struct lpfc_iocbq
*piocb
, uint32_t flag
)
5625 struct lpfc_iocbq
*nextiocb
;
5627 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
5629 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
5630 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
5631 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
5632 lpfc_printf_log(phba
, KERN_ERR
,
5633 LOG_SLI
| LOG_VPORT
,
5634 "1807 IOCB x%x failed. No vport\n",
5635 piocb
->iocb
.ulpCommand
);
5641 /* If the PCI channel is in offline state, do not post iocbs. */
5642 if (unlikely(pci_channel_offline(phba
->pcidev
)))
5645 /* If HBA has a deferred error attention, fail the iocb. */
5646 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
5650 * We should never get an IOCB if we are in a < LINK_DOWN state
5652 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
5656 * Check to see if we are blocking IOCB processing because of a
5657 * outstanding event.
5659 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
5662 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
5664 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
5665 * can be issued if the link is not up.
5667 switch (piocb
->iocb
.ulpCommand
) {
5668 case CMD_GEN_REQUEST64_CR
:
5669 case CMD_GEN_REQUEST64_CX
:
5670 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
5671 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
5673 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
5674 MENLO_TRANSPORT_TYPE
))
5678 case CMD_QUE_RING_BUF_CN
:
5679 case CMD_QUE_RING_BUF64_CN
:
5681 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
5682 * completion, iocb_cmpl MUST be 0.
5684 if (piocb
->iocb_cmpl
)
5685 piocb
->iocb_cmpl
= NULL
;
5687 case CMD_CREATE_XRI_CR
:
5688 case CMD_CLOSE_XRI_CN
:
5689 case CMD_CLOSE_XRI_CX
:
5696 * For FCP commands, we must be in a state where we can process link
5699 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
5700 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
5704 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
5705 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
5706 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
5709 lpfc_sli_update_ring(phba
, pring
);
5711 lpfc_sli_update_full_ring(phba
, pring
);
5714 return IOCB_SUCCESS
;
5719 pring
->stats
.iocb_cmd_delay
++;
5723 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
5724 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
5725 return IOCB_SUCCESS
;
5732 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
5733 * @phba: Pointer to HBA context object.
5734 * @piocb: Pointer to command iocb.
5735 * @sglq: Pointer to the scatter gather queue object.
5737 * This routine converts the bpl or bde that is in the IOCB
5738 * to a sgl list for the sli4 hardware. The physical address
5739 * of the bpl/bde is converted back to a virtual address.
5740 * If the IOCB contains a BPL then the list of BDE's is
5741 * converted to sli4_sge's. If the IOCB contains a single
5742 * BDE then it is converted to a single sli_sge.
5743 * The IOCB is still in cpu endianess so the contents of
5744 * the bpl can be used without byte swapping.
5746 * Returns valid XRI = Success, NO_XRI = Failure.
5749 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
5750 struct lpfc_sglq
*sglq
)
5752 uint16_t xritag
= NO_XRI
;
5753 struct ulp_bde64
*bpl
= NULL
;
5754 struct ulp_bde64 bde
;
5755 struct sli4_sge
*sgl
= NULL
;
5760 if (!piocbq
|| !sglq
)
5763 sgl
= (struct sli4_sge
*)sglq
->sgl
;
5764 icmd
= &piocbq
->iocb
;
5765 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
5766 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
5767 sizeof(struct ulp_bde64
);
5768 /* The addrHigh and addrLow fields within the IOCB
5769 * have not been byteswapped yet so there is no
5770 * need to swap them back.
5772 bpl
= (struct ulp_bde64
*)
5773 ((struct lpfc_dmabuf
*)piocbq
->context3
)->virt
;
5778 for (i
= 0; i
< numBdes
; i
++) {
5779 /* Should already be byte swapped. */
5780 sgl
->addr_hi
= bpl
->addrHigh
;
5781 sgl
->addr_lo
= bpl
->addrLow
;
5782 /* swap the size field back to the cpu so we
5783 * can assign it to the sgl.
5785 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5786 bf_set(lpfc_sli4_sge_len
, sgl
, bde
.tus
.f
.bdeSize
);
5787 if ((i
+1) == numBdes
)
5788 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
5790 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
5791 sgl
->word2
= cpu_to_le32(sgl
->word2
);
5792 sgl
->word3
= cpu_to_le32(sgl
->word3
);
5796 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
5797 /* The addrHigh and addrLow fields of the BDE have not
5798 * been byteswapped yet so they need to be swapped
5799 * before putting them in the sgl.
5802 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
5804 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
5805 bf_set(lpfc_sli4_sge_len
, sgl
,
5806 icmd
->un
.genreq64
.bdl
.bdeSize
);
5807 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
5808 sgl
->word2
= cpu_to_le32(sgl
->word2
);
5809 sgl
->word3
= cpu_to_le32(sgl
->word3
);
5811 return sglq
->sli4_xritag
;
5815 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5816 * @phba: Pointer to HBA context object.
5818 * This routine performs a round robin SCSI command to SLI4 FCP WQ index
5819 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
5822 * Return: index into SLI4 fast-path FCP queue index.
5825 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
5828 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
5831 return phba
->fcp_qidx
;
5835 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
5836 * @phba: Pointer to HBA context object.
5837 * @piocb: Pointer to command iocb.
5838 * @wqe: Pointer to the work queue entry.
5840 * This routine converts the iocb command to its Work Queue Entry
5841 * equivalent. The wqe pointer should not have any fields set when
5842 * this routine is called because it will memcpy over them.
5843 * This routine does not set the CQ_ID or the WQEC bits in the
5846 * Returns: 0 = Success, IOCB_ERROR = Failure.
5849 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
5850 union lpfc_wqe
*wqe
)
5852 uint32_t payload_len
= 0;
5856 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
5859 struct ulp_bde64
*bpl
= NULL
;
5861 fip
= bf_get(lpfc_fip_flag
, &phba
->sli4_hba
.sli4_flags
);
5862 /* The fcp commands will set command type */
5863 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
5864 command_type
= FCP_COMMAND
;
5865 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS
))
5866 command_type
= ELS_COMMAND_FIP
;
5868 command_type
= ELS_COMMAND_NON_FIP
;
5870 /* Some of the fields are in the right position already */
5871 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
5872 abort_tag
= (uint32_t) iocbq
->iotag
;
5873 xritag
= iocbq
->sli4_xritag
;
5874 wqe
->words
[7] = 0; /* The ct field has moved so reset */
5875 /* words0-2 bpl convert bde */
5876 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
5877 bpl
= (struct ulp_bde64
*)
5878 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
5882 /* Should already be byte swapped. */
5883 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
5884 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
5885 /* swap the size field back to the cpu so we
5886 * can assign it to the sgl.
5888 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5889 payload_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
5891 payload_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
5893 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
5894 cmnd
= iocbq
->iocb
.ulpCommand
;
5896 switch (iocbq
->iocb
.ulpCommand
) {
5897 case CMD_ELS_REQUEST64_CR
:
5898 if (!iocbq
->iocb
.ulpLe
) {
5899 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5900 "2007 Only Limited Edition cmd Format"
5901 " supported 0x%x\n",
5902 iocbq
->iocb
.ulpCommand
);
5905 wqe
->els_req
.payload_len
= payload_len
;
5906 /* Els_reguest64 has a TMO */
5907 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
5908 iocbq
->iocb
.ulpTimeout
);
5909 /* Need a VF for word 4 set the vf bit*/
5910 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
5911 /* And a VFID for word 12 */
5912 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
5914 * Set ct field to 3, indicates that the context_tag field
5915 * contains the FCFI and remote N_Port_ID is
5919 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
5920 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
5921 iocbq
->iocb
.ulpContext
);
5923 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
, ct
);
5924 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5925 /* CCP CCPE PV PRI in word10 were set in the memcpy */
5927 case CMD_XMIT_SEQUENCE64_CR
:
5928 /* word3 iocb=io_tag32 wqe=payload_offset */
5929 /* payload offset used for multilpe outstanding
5930 * sequences on the same exchange
5933 /* word4 relative_offset memcpy */
5934 /* word5 r_ctl/df_ctl memcpy */
5935 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5936 wqe
->xmit_sequence
.xmit_len
= payload_len
;
5938 case CMD_XMIT_BCAST64_CN
:
5939 /* word3 iocb=iotag32 wqe=payload_len */
5940 wqe
->words
[3] = 0; /* no definition for this in wqe */
5941 /* word4 iocb=rsvd wqe=rsvd */
5942 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
5943 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
5944 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
5945 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
5947 case CMD_FCP_IWRITE64_CR
:
5948 command_type
= FCP_COMMAND_DATA_OUT
;
5949 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
5951 * word3 is payload_len: byte offset to the sgl entry for the
5953 * word4 is total xfer len, same as the IOCB->ulpParameter.
5954 * word5 is initial xfer len 0 = wait for xfer-ready
5957 /* Always wait for xfer-ready before sending data */
5958 wqe
->fcp_iwrite
.initial_xfer_len
= 0;
5959 /* word 4 (xfer length) should have been set on the memcpy */
5961 /* allow write to fall through to read */
5962 case CMD_FCP_IREAD64_CR
:
5963 /* FCP_CMD is always the 1st sgl entry */
5964 wqe
->fcp_iread
.payload_len
=
5965 payload_len
+ sizeof(struct fcp_rsp
);
5967 /* word 4 (xfer length) should have been set on the memcpy */
5969 bf_set(lpfc_wqe_gen_erp
, &wqe
->generic
,
5970 iocbq
->iocb
.ulpFCP2Rcvy
);
5971 bf_set(lpfc_wqe_gen_lnk
, &wqe
->generic
, iocbq
->iocb
.ulpXS
);
5972 /* The XC bit and the XS bit are similar. The driver never
5973 * tracked whether or not the exchange was previouslly open.
5974 * XC = Exchange create, 0 is create. 1 is already open.
5975 * XS = link cmd: 1 do not close the exchange after command.
5976 * XS = 0 close exchange when command completes.
5977 * The only time we would not set the XC bit is when the XS bit
5978 * is set and we are sending our 2nd or greater command on
5981 /* Always open the exchange */
5982 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
5984 wqe
->words
[10] &= 0xffff0000; /* zero out ebde count */
5985 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
5987 case CMD_FCP_ICMND64_CR
:
5988 /* Always open the exchange */
5989 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
5992 wqe
->words
[10] &= 0xffff0000; /* zero out ebde count */
5993 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5995 case CMD_GEN_REQUEST64_CR
:
5996 /* word3 command length is described as byte offset to the
5997 * rsp_data. Would always be 16, sizeof(struct sli4_sge)
6002 wqe
->gen_req
.command_len
= payload_len
;
6003 /* Word4 parameter copied in the memcpy */
6004 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
6005 /* word6 context tag copied in memcpy */
6006 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
6007 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
6008 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6009 "2015 Invalid CT %x command 0x%x\n",
6010 ct
, iocbq
->iocb
.ulpCommand
);
6013 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
, 0);
6014 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
,
6015 iocbq
->iocb
.ulpTimeout
);
6017 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6018 command_type
= OTHER_COMMAND
;
6020 case CMD_XMIT_ELS_RSP64_CX
:
6021 /* words0-2 BDE memcpy */
6022 /* word3 iocb=iotag32 wqe=rsvd */
6024 /* word4 iocb=did wge=rsvd. */
6026 /* word5 iocb=rsvd wge=did */
6027 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
6028 iocbq
->iocb
.un
.elsreq64
.remoteID
);
6030 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6031 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6033 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6034 bf_set(wqe_rcvoxid
, &wqe
->generic
, iocbq
->iocb
.ulpContext
);
6035 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
6036 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
6037 iocbq
->vport
->vpi
+ phba
->vpi_base
);
6038 command_type
= OTHER_COMMAND
;
6040 case CMD_CLOSE_XRI_CN
:
6041 case CMD_ABORT_XRI_CN
:
6042 case CMD_ABORT_XRI_CX
:
6043 /* words 0-2 memcpy should be 0 rserved */
6044 /* port will send abts */
6045 if (iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6047 * The link is down so the fw does not need to send abts
6050 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
6052 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
6053 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
6054 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
6056 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6057 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6058 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
6059 wqe
->generic
.abort_tag
= abort_tag
;
6061 * The abort handler will send us CMD_ABORT_XRI_CN or
6062 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6064 bf_set(lpfc_wqe_gen_command
, &wqe
->generic
, CMD_ABORT_XRI_CX
);
6065 cmnd
= CMD_ABORT_XRI_CX
;
6066 command_type
= OTHER_COMMAND
;
6069 case CMD_XRI_ABORTED_CX
:
6070 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
6071 /* words0-2 are all 0's no bde */
6072 /* word3 and word4 are rsvrd */
6075 /* word5 iocb=rsvd wge=did */
6076 /* There is no remote port id in the IOCB? */
6077 /* Let this fall through and fail */
6078 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
6079 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
6080 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
6081 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
6083 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6084 "2014 Invalid command 0x%x\n",
6085 iocbq
->iocb
.ulpCommand
);
6090 bf_set(lpfc_wqe_gen_xri
, &wqe
->generic
, xritag
);
6091 bf_set(lpfc_wqe_gen_request_tag
, &wqe
->generic
, iocbq
->iotag
);
6092 wqe
->generic
.abort_tag
= abort_tag
;
6093 bf_set(lpfc_wqe_gen_cmd_type
, &wqe
->generic
, command_type
);
6094 bf_set(lpfc_wqe_gen_command
, &wqe
->generic
, cmnd
);
6095 bf_set(lpfc_wqe_gen_class
, &wqe
->generic
, iocbq
->iocb
.ulpClass
);
6096 bf_set(lpfc_wqe_gen_cq_id
, &wqe
->generic
, LPFC_WQE_CQ_ID_DEFAULT
);
6102 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
6103 * @phba: Pointer to HBA context object.
6104 * @ring_number: SLI ring number to issue iocb on.
6105 * @piocb: Pointer to command iocb.
6106 * @flag: Flag indicating if this command can be put into txq.
6108 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
6109 * an iocb command to an HBA with SLI-4 interface spec.
6111 * This function is called with hbalock held. The function will return success
6112 * after it successfully submit the iocb to firmware or after adding to the
6116 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
6117 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6119 struct lpfc_sglq
*sglq
;
6122 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
6125 if (piocb
->sli4_xritag
== NO_XRI
) {
6126 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
6127 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6130 sglq
= __lpfc_sli_get_sglq(phba
);
6133 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
6135 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
6136 sglq
= NULL
; /* These IO's already have an XRI and
6140 /* This is a continuation of a commandi,(CX) so this
6141 * sglq is on the active list
6143 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
6149 xritag
= lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
);
6150 if (xritag
!= sglq
->sli4_xritag
)
6154 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
6157 if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
6158 fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
6159 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[fcp_wqidx
], &wqe
))
6162 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
6165 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
6171 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6173 * This routine wraps the actual lockless version for issusing IOCB function
6174 * pointer from the lpfc_hba struct.
6177 * IOCB_ERROR - Error
6178 * IOCB_SUCCESS - Success
6182 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6183 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6185 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6189 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6190 * @phba: The hba struct for which this call is being executed.
6191 * @dev_grp: The HBA PCI-Device group number.
6193 * This routine sets up the SLI interface API function jump table in @phba
6195 * Returns: 0 - success, -ENODEV - failure.
6198 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6202 case LPFC_PCI_DEV_LP
:
6203 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
6204 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
6206 case LPFC_PCI_DEV_OC
:
6207 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
6208 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
6211 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6212 "1419 Invalid HBA PCI-device group: 0x%x\n",
6217 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
6222 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6223 * @phba: Pointer to HBA context object.
6224 * @pring: Pointer to driver SLI ring object.
6225 * @piocb: Pointer to command iocb.
6226 * @flag: Flag indicating if this command can be put into txq.
6228 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6229 * function. This function gets the hbalock and calls
6230 * __lpfc_sli_issue_iocb function and will return the error returned
6231 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6232 * functions which do not hold hbalock.
6235 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6236 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6238 unsigned long iflags
;
6241 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6242 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6243 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6249 * lpfc_extra_ring_setup - Extra ring setup function
6250 * @phba: Pointer to HBA context object.
6252 * This function is called while driver attaches with the
6253 * HBA to setup the extra ring. The extra ring is used
6254 * only when driver needs to support target mode functionality
6255 * or IP over FC functionalities.
6257 * This function is called with no lock held.
6260 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
6262 struct lpfc_sli
*psli
;
6263 struct lpfc_sli_ring
*pring
;
6267 /* Adjust cmd/rsp ring iocb entries more evenly */
6269 /* Take some away from the FCP ring */
6270 pring
= &psli
->ring
[psli
->fcp_ring
];
6271 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6272 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6273 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6274 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6276 /* and give them to the extra ring */
6277 pring
= &psli
->ring
[psli
->extra_ring
];
6279 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6280 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6281 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6282 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6284 /* Setup default profile for this ring */
6285 pring
->iotag_max
= 4096;
6286 pring
->num_mask
= 1;
6287 pring
->prt
[0].profile
= 0; /* Mask 0 */
6288 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
6289 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
6290 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
6295 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6296 * @phba: Pointer to HBA context object.
6297 * @pring: Pointer to driver SLI ring object.
6298 * @iocbq: Pointer to iocb object.
6300 * This function is called by the slow ring event handler
6301 * function when there is an ASYNC event iocb in the ring.
6302 * This function is called with no lock held.
6303 * Currently this function handles only temperature related
6304 * ASYNC events. The function decodes the temperature sensor
6305 * event message and posts events for the management applications.
6308 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
6309 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
6314 struct temp_event temp_event_data
;
6315 struct Scsi_Host
*shost
;
6318 icmd
= &iocbq
->iocb
;
6319 evt_code
= icmd
->un
.asyncstat
.evt_code
;
6320 temp
= icmd
->ulpContext
;
6322 if ((evt_code
!= ASYNC_TEMP_WARN
) &&
6323 (evt_code
!= ASYNC_TEMP_SAFE
)) {
6324 iocb_w
= (uint32_t *) icmd
;
6325 lpfc_printf_log(phba
,
6328 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6330 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6331 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6332 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6333 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6335 icmd
->un
.asyncstat
.evt_code
,
6336 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
6337 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
6338 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
6339 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
6343 temp_event_data
.data
= (uint32_t)temp
;
6344 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
6345 if (evt_code
== ASYNC_TEMP_WARN
) {
6346 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
6347 lpfc_printf_log(phba
,
6350 "0347 Adapter is very hot, please take "
6351 "corrective action. temperature : %d Celsius\n",
6354 if (evt_code
== ASYNC_TEMP_SAFE
) {
6355 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
6356 lpfc_printf_log(phba
,
6359 "0340 Adapter temperature is OK now. "
6360 "temperature : %d Celsius\n",
6364 /* Send temperature change event to applications */
6365 shost
= lpfc_shost_from_vport(phba
->pport
);
6366 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6367 sizeof(temp_event_data
), (char *) &temp_event_data
,
6374 * lpfc_sli_setup - SLI ring setup function
6375 * @phba: Pointer to HBA context object.
6377 * lpfc_sli_setup sets up rings of the SLI interface with
6378 * number of iocbs per ring and iotags. This function is
6379 * called while driver attach to the HBA and before the
6380 * interrupts are enabled. So there is no need for locking.
6382 * This function always returns 0.
6385 lpfc_sli_setup(struct lpfc_hba
*phba
)
6387 int i
, totiocbsize
= 0;
6388 struct lpfc_sli
*psli
= &phba
->sli
;
6389 struct lpfc_sli_ring
*pring
;
6391 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
6393 psli
->fcp_ring
= LPFC_FCP_RING
;
6394 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
6395 psli
->extra_ring
= LPFC_EXTRA_RING
;
6397 psli
->iocbq_lookup
= NULL
;
6398 psli
->iocbq_lookup_len
= 0;
6399 psli
->last_iotag
= 0;
6401 for (i
= 0; i
< psli
->num_rings
; i
++) {
6402 pring
= &psli
->ring
[i
];
6404 case LPFC_FCP_RING
: /* ring 0 - FCP */
6405 /* numCiocb and numRiocb are used in config_port */
6406 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
6407 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
6408 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6409 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6410 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6411 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6412 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6413 SLI3_IOCB_CMD_SIZE
:
6415 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6416 SLI3_IOCB_RSP_SIZE
:
6418 pring
->iotag_ctr
= 0;
6420 (phba
->cfg_hba_queue_depth
* 2);
6421 pring
->fast_iotag
= pring
->iotag_max
;
6422 pring
->num_mask
= 0;
6424 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
6425 /* numCiocb and numRiocb are used in config_port */
6426 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
6427 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
6428 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6429 SLI3_IOCB_CMD_SIZE
:
6431 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6432 SLI3_IOCB_RSP_SIZE
:
6434 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
6435 pring
->num_mask
= 0;
6437 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
6438 /* numCiocb and numRiocb are used in config_port */
6439 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
6440 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
6441 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6442 SLI3_IOCB_CMD_SIZE
:
6444 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6445 SLI3_IOCB_RSP_SIZE
:
6447 pring
->fast_iotag
= 0;
6448 pring
->iotag_ctr
= 0;
6449 pring
->iotag_max
= 4096;
6450 pring
->lpfc_sli_rcv_async_status
=
6451 lpfc_sli_async_event_handler
;
6452 pring
->num_mask
= 4;
6453 pring
->prt
[0].profile
= 0; /* Mask 0 */
6454 pring
->prt
[0].rctl
= FC_ELS_REQ
;
6455 pring
->prt
[0].type
= FC_ELS_DATA
;
6456 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
6457 lpfc_els_unsol_event
;
6458 pring
->prt
[1].profile
= 0; /* Mask 1 */
6459 pring
->prt
[1].rctl
= FC_ELS_RSP
;
6460 pring
->prt
[1].type
= FC_ELS_DATA
;
6461 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
6462 lpfc_els_unsol_event
;
6463 pring
->prt
[2].profile
= 0; /* Mask 2 */
6464 /* NameServer Inquiry */
6465 pring
->prt
[2].rctl
= FC_UNSOL_CTL
;
6467 pring
->prt
[2].type
= FC_COMMON_TRANSPORT_ULP
;
6468 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
6469 lpfc_ct_unsol_event
;
6470 pring
->prt
[3].profile
= 0; /* Mask 3 */
6471 /* NameServer response */
6472 pring
->prt
[3].rctl
= FC_SOL_CTL
;
6474 pring
->prt
[3].type
= FC_COMMON_TRANSPORT_ULP
;
6475 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
6476 lpfc_ct_unsol_event
;
6479 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
6480 (pring
->numRiocb
* pring
->sizeRiocb
);
6482 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
6483 /* Too many cmd / rsp ring entries in SLI2 SLIM */
6484 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
6485 "SLI2 SLIM Data: x%x x%lx\n",
6486 phba
->brd_no
, totiocbsize
,
6487 (unsigned long) MAX_SLIM_IOCB_SIZE
);
6489 if (phba
->cfg_multi_ring_support
== 2)
6490 lpfc_extra_ring_setup(phba
);
6496 * lpfc_sli_queue_setup - Queue initialization function
6497 * @phba: Pointer to HBA context object.
6499 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
6500 * ring. This function also initializes ring indices of each ring.
6501 * This function is called during the initialization of the SLI
6502 * interface of an HBA.
6503 * This function is called with no lock held and always returns
6507 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
6509 struct lpfc_sli
*psli
;
6510 struct lpfc_sli_ring
*pring
;
6514 spin_lock_irq(&phba
->hbalock
);
6515 INIT_LIST_HEAD(&psli
->mboxq
);
6516 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
6517 /* Initialize list headers for txq and txcmplq as double linked lists */
6518 for (i
= 0; i
< psli
->num_rings
; i
++) {
6519 pring
= &psli
->ring
[i
];
6521 pring
->next_cmdidx
= 0;
6522 pring
->local_getidx
= 0;
6524 INIT_LIST_HEAD(&pring
->txq
);
6525 INIT_LIST_HEAD(&pring
->txcmplq
);
6526 INIT_LIST_HEAD(&pring
->iocb_continueq
);
6527 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
6528 INIT_LIST_HEAD(&pring
->postbufq
);
6530 spin_unlock_irq(&phba
->hbalock
);
6535 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
6536 * @phba: Pointer to HBA context object.
6538 * This routine flushes the mailbox command subsystem. It will unconditionally
6539 * flush all the mailbox commands in the three possible stages in the mailbox
6540 * command sub-system: pending mailbox command queue; the outstanding mailbox
6541 * command; and completed mailbox command queue. It is caller's responsibility
6542 * to make sure that the driver is in the proper state to flush the mailbox
6543 * command sub-system. Namely, the posting of mailbox commands into the
6544 * pending mailbox command queue from the various clients must be stopped;
6545 * either the HBA is in a state that it will never works on the outstanding
6546 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
6547 * mailbox command has been completed.
6550 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
6552 LIST_HEAD(completions
);
6553 struct lpfc_sli
*psli
= &phba
->sli
;
6555 unsigned long iflag
;
6557 /* Flush all the mailbox commands in the mbox system */
6558 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6559 /* The pending mailbox command queue */
6560 list_splice_init(&phba
->sli
.mboxq
, &completions
);
6561 /* The outstanding active mailbox command */
6562 if (psli
->mbox_active
) {
6563 list_add_tail(&psli
->mbox_active
->list
, &completions
);
6564 psli
->mbox_active
= NULL
;
6565 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6567 /* The completed mailbox command queue */
6568 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
6569 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6571 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
6572 while (!list_empty(&completions
)) {
6573 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
6574 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6576 pmb
->mbox_cmpl(phba
, pmb
);
6581 * lpfc_sli_host_down - Vport cleanup function
6582 * @vport: Pointer to virtual port object.
6584 * lpfc_sli_host_down is called to clean up the resources
6585 * associated with a vport before destroying virtual
6586 * port data structures.
6587 * This function does following operations:
6588 * - Free discovery resources associated with this virtual
6590 * - Free iocbs associated with this virtual port in
6592 * - Send abort for all iocb commands associated with this
6595 * This function is called with no lock held and always returns 1.
6598 lpfc_sli_host_down(struct lpfc_vport
*vport
)
6600 LIST_HEAD(completions
);
6601 struct lpfc_hba
*phba
= vport
->phba
;
6602 struct lpfc_sli
*psli
= &phba
->sli
;
6603 struct lpfc_sli_ring
*pring
;
6604 struct lpfc_iocbq
*iocb
, *next_iocb
;
6606 unsigned long flags
= 0;
6607 uint16_t prev_pring_flag
;
6609 lpfc_cleanup_discovery_resources(vport
);
6611 spin_lock_irqsave(&phba
->hbalock
, flags
);
6612 for (i
= 0; i
< psli
->num_rings
; i
++) {
6613 pring
= &psli
->ring
[i
];
6614 prev_pring_flag
= pring
->flag
;
6615 /* Only slow rings */
6616 if (pring
->ringno
== LPFC_ELS_RING
) {
6617 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
6618 /* Set the lpfc data pending flag */
6619 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
6622 * Error everything on the txq since these iocbs have not been
6623 * given to the FW yet.
6625 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
6626 if (iocb
->vport
!= vport
)
6628 list_move_tail(&iocb
->list
, &completions
);
6632 /* Next issue ABTS for everything on the txcmplq */
6633 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
6635 if (iocb
->vport
!= vport
)
6637 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
6640 pring
->flag
= prev_pring_flag
;
6643 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6645 /* Cancel all the IOCBs from the completions list */
6646 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6652 * lpfc_sli_hba_down - Resource cleanup function for the HBA
6653 * @phba: Pointer to HBA context object.
6655 * This function cleans up all iocb, buffers, mailbox commands
6656 * while shutting down the HBA. This function is called with no
6657 * lock held and always returns 1.
6658 * This function does the following to cleanup driver resources:
6659 * - Free discovery resources for each virtual port
6660 * - Cleanup any pending fabric iocbs
6661 * - Iterate through the iocb txq and free each entry
6663 * - Free up any buffer posted to the HBA
6664 * - Free mailbox commands in the mailbox queue.
6667 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
6669 LIST_HEAD(completions
);
6670 struct lpfc_sli
*psli
= &phba
->sli
;
6671 struct lpfc_sli_ring
*pring
;
6672 struct lpfc_dmabuf
*buf_ptr
;
6673 unsigned long flags
= 0;
6676 /* Shutdown the mailbox command sub-system */
6677 lpfc_sli_mbox_sys_shutdown(phba
);
6679 lpfc_hba_down_prep(phba
);
6681 lpfc_fabric_abort_hba(phba
);
6683 spin_lock_irqsave(&phba
->hbalock
, flags
);
6684 for (i
= 0; i
< psli
->num_rings
; i
++) {
6685 pring
= &psli
->ring
[i
];
6686 /* Only slow rings */
6687 if (pring
->ringno
== LPFC_ELS_RING
) {
6688 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
6689 /* Set the lpfc data pending flag */
6690 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
6694 * Error everything on the txq since these iocbs have not been
6695 * given to the FW yet.
6697 list_splice_init(&pring
->txq
, &completions
);
6701 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6703 /* Cancel all the IOCBs from the completions list */
6704 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6707 spin_lock_irqsave(&phba
->hbalock
, flags
);
6708 list_splice_init(&phba
->elsbuf
, &completions
);
6709 phba
->elsbuf_cnt
= 0;
6710 phba
->elsbuf_prev_cnt
= 0;
6711 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6713 while (!list_empty(&completions
)) {
6714 list_remove_head(&completions
, buf_ptr
,
6715 struct lpfc_dmabuf
, list
);
6716 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
6720 /* Return any active mbox cmds */
6721 del_timer_sync(&psli
->mbox_tmo
);
6723 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
6724 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6725 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
6731 * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
6732 * @phba: Pointer to HBA context object.
6734 * This function cleans up all queues, iocb, buffers, mailbox commands while
6735 * shutting down the SLI4 HBA FCoE function. This function is called with no
6736 * lock held and always returns 1.
6738 * This function does the following to cleanup driver FCoE function resources:
6739 * - Free discovery resources for each virtual port
6740 * - Cleanup any pending fabric iocbs
6741 * - Iterate through the iocb txq and free each entry in the list.
6742 * - Free up any buffer posted to the HBA.
6743 * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
6744 * - Free mailbox commands in the mailbox queue.
6747 lpfc_sli4_hba_down(struct lpfc_hba
*phba
)
6749 /* Stop the SLI4 device port */
6750 lpfc_stop_port(phba
);
6752 /* Tear down the queues in the HBA */
6753 lpfc_sli4_queue_unset(phba
);
6755 /* unregister default FCFI from the HBA */
6756 lpfc_sli4_fcfi_unreg(phba
, phba
->fcf
.fcfi
);
6762 * lpfc_sli_pcimem_bcopy - SLI memory copy function
6763 * @srcp: Source memory pointer.
6764 * @destp: Destination memory pointer.
6765 * @cnt: Number of words required to be copied.
6767 * This function is used for copying data between driver memory
6768 * and the SLI memory. This function also changes the endianness
6769 * of each word if native endianness is different from SLI
6770 * endianness. This function can be called with or without
6774 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
6776 uint32_t *src
= srcp
;
6777 uint32_t *dest
= destp
;
6781 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
6783 ldata
= le32_to_cpu(ldata
);
6792 * lpfc_sli_bemem_bcopy - SLI memory copy function
6793 * @srcp: Source memory pointer.
6794 * @destp: Destination memory pointer.
6795 * @cnt: Number of words required to be copied.
6797 * This function is used for copying data between a data structure
6798 * with big endian representation to local endianness.
6799 * This function can be called with or without lock.
6802 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
6804 uint32_t *src
= srcp
;
6805 uint32_t *dest
= destp
;
6809 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
6811 ldata
= be32_to_cpu(ldata
);
6819 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
6820 * @phba: Pointer to HBA context object.
6821 * @pring: Pointer to driver SLI ring object.
6822 * @mp: Pointer to driver buffer object.
6824 * This function is called with no lock held.
6825 * It always return zero after adding the buffer to the postbufq
6829 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6830 struct lpfc_dmabuf
*mp
)
6832 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
6834 spin_lock_irq(&phba
->hbalock
);
6835 list_add_tail(&mp
->list
, &pring
->postbufq
);
6836 pring
->postbufq_cnt
++;
6837 spin_unlock_irq(&phba
->hbalock
);
6842 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
6843 * @phba: Pointer to HBA context object.
6845 * When HBQ is enabled, buffers are searched based on tags. This function
6846 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
6847 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
6848 * does not conflict with tags of buffer posted for unsolicited events.
6849 * The function returns the allocated tag. The function is called with
6853 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
6855 spin_lock_irq(&phba
->hbalock
);
6856 phba
->buffer_tag_count
++;
6858 * Always set the QUE_BUFTAG_BIT to distiguish between
6859 * a tag assigned by HBQ.
6861 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
6862 spin_unlock_irq(&phba
->hbalock
);
6863 return phba
->buffer_tag_count
;
6867 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
6868 * @phba: Pointer to HBA context object.
6869 * @pring: Pointer to driver SLI ring object.
6872 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
6873 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
6874 * iocb is posted to the response ring with the tag of the buffer.
6875 * This function searches the pring->postbufq list using the tag
6876 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
6877 * iocb. If the buffer is found then lpfc_dmabuf object of the
6878 * buffer is returned to the caller else NULL is returned.
6879 * This function is called with no lock held.
6881 struct lpfc_dmabuf
*
6882 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6885 struct lpfc_dmabuf
*mp
, *next_mp
;
6886 struct list_head
*slp
= &pring
->postbufq
;
6888 /* Search postbufq, from the begining, looking for a match on tag */
6889 spin_lock_irq(&phba
->hbalock
);
6890 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
6891 if (mp
->buffer_tag
== tag
) {
6892 list_del_init(&mp
->list
);
6893 pring
->postbufq_cnt
--;
6894 spin_unlock_irq(&phba
->hbalock
);
6899 spin_unlock_irq(&phba
->hbalock
);
6900 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6901 "0402 Cannot find virtual addr for buffer tag on "
6902 "ring %d Data x%lx x%p x%p x%x\n",
6903 pring
->ringno
, (unsigned long) tag
,
6904 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
6910 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
6911 * @phba: Pointer to HBA context object.
6912 * @pring: Pointer to driver SLI ring object.
6913 * @phys: DMA address of the buffer.
6915 * This function searches the buffer list using the dma_address
6916 * of unsolicited event to find the driver's lpfc_dmabuf object
6917 * corresponding to the dma_address. The function returns the
6918 * lpfc_dmabuf object if a buffer is found else it returns NULL.
6919 * This function is called by the ct and els unsolicited event
6920 * handlers to get the buffer associated with the unsolicited
6923 * This function is called with no lock held.
6925 struct lpfc_dmabuf
*
6926 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6929 struct lpfc_dmabuf
*mp
, *next_mp
;
6930 struct list_head
*slp
= &pring
->postbufq
;
6932 /* Search postbufq, from the begining, looking for a match on phys */
6933 spin_lock_irq(&phba
->hbalock
);
6934 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
6935 if (mp
->phys
== phys
) {
6936 list_del_init(&mp
->list
);
6937 pring
->postbufq_cnt
--;
6938 spin_unlock_irq(&phba
->hbalock
);
6943 spin_unlock_irq(&phba
->hbalock
);
6944 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6945 "0410 Cannot find virtual addr for mapped buf on "
6946 "ring %d Data x%llx x%p x%p x%x\n",
6947 pring
->ringno
, (unsigned long long)phys
,
6948 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
6953 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
6954 * @phba: Pointer to HBA context object.
6955 * @cmdiocb: Pointer to driver command iocb object.
6956 * @rspiocb: Pointer to driver response iocb object.
6958 * This function is the completion handler for the abort iocbs for
6959 * ELS commands. This function is called from the ELS ring event
6960 * handler with no lock held. This function frees memory resources
6961 * associated with the abort iocb.
6964 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6965 struct lpfc_iocbq
*rspiocb
)
6967 IOCB_t
*irsp
= &rspiocb
->iocb
;
6968 uint16_t abort_iotag
, abort_context
;
6969 struct lpfc_iocbq
*abort_iocb
;
6970 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6974 if (irsp
->ulpStatus
) {
6975 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
6976 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
6978 spin_lock_irq(&phba
->hbalock
);
6979 if (abort_iotag
!= 0 && abort_iotag
<= phba
->sli
.last_iotag
)
6980 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_iotag
];
6982 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_SLI
,
6983 "0327 Cannot abort els iocb %p "
6984 "with tag %x context %x, abort status %x, "
6986 abort_iocb
, abort_iotag
, abort_context
,
6987 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
6990 * If the iocb is not found in Firmware queue the iocb
6991 * might have completed already. Do not free it again.
6993 if (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
6994 spin_unlock_irq(&phba
->hbalock
);
6995 lpfc_sli_release_iocbq(phba
, cmdiocb
);
6999 * make sure we have the right iocbq before taking it
7000 * off the txcmplq and try to call completion routine.
7003 abort_iocb
->iocb
.ulpContext
!= abort_context
||
7004 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
7005 spin_unlock_irq(&phba
->hbalock
);
7007 list_del_init(&abort_iocb
->list
);
7008 pring
->txcmplq_cnt
--;
7009 spin_unlock_irq(&phba
->hbalock
);
7011 /* Firmware could still be in progress of DMAing
7012 * payload, so don't free data buffer till after
7015 abort_iocb
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
7017 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
7018 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
7019 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
7020 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
7024 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7029 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
7030 * @phba: Pointer to HBA context object.
7031 * @cmdiocb: Pointer to driver command iocb object.
7032 * @rspiocb: Pointer to driver response iocb object.
7034 * The function is called from SLI ring event handler with no
7035 * lock held. This function is the completion handler for ELS commands
7036 * which are aborted. The function frees memory resources used for
7037 * the aborted ELS commands.
7040 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7041 struct lpfc_iocbq
*rspiocb
)
7043 IOCB_t
*irsp
= &rspiocb
->iocb
;
7045 /* ELS cmd tag <ulpIoTag> completes */
7046 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
7047 "0139 Ignoring ELS cmd tag x%x completion Data: "
7049 irsp
->ulpIoTag
, irsp
->ulpStatus
,
7050 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
7051 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
7052 lpfc_ct_free_iocb(phba
, cmdiocb
);
7054 lpfc_els_free_iocb(phba
, cmdiocb
);
7059 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7060 * @phba: Pointer to HBA context object.
7061 * @pring: Pointer to driver SLI ring object.
7062 * @cmdiocb: Pointer to driver command iocb object.
7064 * This function issues an abort iocb for the provided command
7065 * iocb. This function is called with hbalock held.
7066 * The function returns 0 when it fails due to memory allocation
7067 * failure or when the command iocb is an abort request.
7070 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7071 struct lpfc_iocbq
*cmdiocb
)
7073 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7074 struct lpfc_iocbq
*abtsiocbp
;
7075 IOCB_t
*icmd
= NULL
;
7076 IOCB_t
*iabt
= NULL
;
7077 int retval
= IOCB_ERROR
;
7080 * There are certain command types we don't want to abort. And we
7081 * don't want to abort commands that are already in the process of
7084 icmd
= &cmdiocb
->iocb
;
7085 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
7086 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7087 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
7090 /* If we're unloading, don't abort iocb on the ELS ring, but change the
7091 * callback so that nothing happens when it finishes.
7093 if ((vport
->load_flag
& FC_UNLOADING
) &&
7094 (pring
->ringno
== LPFC_ELS_RING
)) {
7095 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
7096 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
7098 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
7099 goto abort_iotag_exit
;
7102 /* issue ABTS for this IOCB based on iotag */
7103 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
7104 if (abtsiocbp
== NULL
)
7107 /* This signals the response to set the correct status
7108 * before calling the completion handler.
7110 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
7112 iabt
= &abtsiocbp
->iocb
;
7113 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7114 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
7115 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7116 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
7118 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
7120 iabt
->ulpClass
= icmd
->ulpClass
;
7122 if (phba
->link_state
>= LPFC_LINK_UP
)
7123 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
7125 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
7127 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
7129 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
7130 "0339 Abort xri x%x, original iotag x%x, "
7131 "abort cmd iotag x%x\n",
7132 iabt
->un
.acxri
.abortContextTag
,
7133 iabt
->un
.acxri
.abortIoTag
, abtsiocbp
->iotag
);
7134 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
7137 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
7140 * Caller to this routine should check for IOCB_ERROR
7141 * and handle it properly. This routine no longer removes
7142 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7148 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7149 * @iocbq: Pointer to driver iocb object.
7150 * @vport: Pointer to driver virtual port object.
7151 * @tgt_id: SCSI ID of the target.
7152 * @lun_id: LUN ID of the scsi device.
7153 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
7155 * This function acts as an iocb filter for functions which abort or count
7156 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
7157 * 0 if the filtering criteria is met for the given iocb and will return
7158 * 1 if the filtering criteria is not met.
7159 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
7160 * given iocb is for the SCSI device specified by vport, tgt_id and
7162 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
7163 * given iocb is for the SCSI target specified by vport and tgt_id
7165 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
7166 * given iocb is for the SCSI host associated with the given vport.
7167 * This function is called with no locks held.
7170 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
7171 uint16_t tgt_id
, uint64_t lun_id
,
7172 lpfc_ctx_cmd ctx_cmd
)
7174 struct lpfc_scsi_buf
*lpfc_cmd
;
7177 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
7180 if (iocbq
->vport
!= vport
)
7183 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
7185 if (lpfc_cmd
->pCmd
== NULL
)
7190 if ((lpfc_cmd
->rdata
->pnode
) &&
7191 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
7192 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
7196 if ((lpfc_cmd
->rdata
->pnode
) &&
7197 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
7204 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
7213 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7214 * @vport: Pointer to virtual port.
7215 * @tgt_id: SCSI ID of the target.
7216 * @lun_id: LUN ID of the scsi device.
7217 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7219 * This function returns number of FCP commands pending for the vport.
7220 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7221 * commands pending on the vport associated with SCSI device specified
7222 * by tgt_id and lun_id parameters.
7223 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7224 * commands pending on the vport associated with SCSI target specified
7225 * by tgt_id parameter.
7226 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7227 * commands pending on the vport.
7228 * This function returns the number of iocbs which satisfy the filter.
7229 * This function is called without any lock held.
7232 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
7233 lpfc_ctx_cmd ctx_cmd
)
7235 struct lpfc_hba
*phba
= vport
->phba
;
7236 struct lpfc_iocbq
*iocbq
;
7239 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
7240 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7242 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
7251 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7252 * @phba: Pointer to HBA context object
7253 * @cmdiocb: Pointer to command iocb object.
7254 * @rspiocb: Pointer to response iocb object.
7256 * This function is called when an aborted FCP iocb completes. This
7257 * function is called by the ring event handler with no lock held.
7258 * This function frees the iocb.
7261 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7262 struct lpfc_iocbq
*rspiocb
)
7264 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7269 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
7270 * @vport: Pointer to virtual port.
7271 * @pring: Pointer to driver SLI ring object.
7272 * @tgt_id: SCSI ID of the target.
7273 * @lun_id: LUN ID of the scsi device.
7274 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7276 * This function sends an abort command for every SCSI command
7277 * associated with the given virtual port pending on the ring
7278 * filtered by lpfc_sli_validate_fcp_iocb function.
7279 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
7280 * FCP iocbs associated with lun specified by tgt_id and lun_id
7282 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
7283 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
7284 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
7285 * FCP iocbs associated with virtual port.
7286 * This function returns number of iocbs it failed to abort.
7287 * This function is called with no locks held.
7290 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
7291 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
7293 struct lpfc_hba
*phba
= vport
->phba
;
7294 struct lpfc_iocbq
*iocbq
;
7295 struct lpfc_iocbq
*abtsiocb
;
7297 int errcnt
= 0, ret_val
= 0;
7300 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
7301 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7303 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
7307 /* issue ABTS for this IOCB based on iotag */
7308 abtsiocb
= lpfc_sli_get_iocbq(phba
);
7309 if (abtsiocb
== NULL
) {
7315 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7316 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
7317 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7318 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
7320 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
7321 abtsiocb
->iocb
.ulpLe
= 1;
7322 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
7323 abtsiocb
->vport
= phba
->pport
;
7325 if (lpfc_is_link_up(phba
))
7326 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
7328 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
7330 /* Setup callback routine and issue the command. */
7331 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
7332 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
7334 if (ret_val
== IOCB_ERROR
) {
7335 lpfc_sli_release_iocbq(phba
, abtsiocb
);
7345 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
7346 * @phba: Pointer to HBA context object.
7347 * @cmdiocbq: Pointer to command iocb.
7348 * @rspiocbq: Pointer to response iocb.
7350 * This function is the completion handler for iocbs issued using
7351 * lpfc_sli_issue_iocb_wait function. This function is called by the
7352 * ring event handler function without any lock held. This function
7353 * can be called from both worker thread context and interrupt
7354 * context. This function also can be called from other thread which
7355 * cleans up the SLI layer objects.
7356 * This function copy the contents of the response iocb to the
7357 * response iocb memory object provided by the caller of
7358 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
7359 * sleeps for the iocb completion.
7362 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
7363 struct lpfc_iocbq
*cmdiocbq
,
7364 struct lpfc_iocbq
*rspiocbq
)
7366 wait_queue_head_t
*pdone_q
;
7367 unsigned long iflags
;
7369 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7370 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
7371 if (cmdiocbq
->context2
&& rspiocbq
)
7372 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
7373 &rspiocbq
->iocb
, sizeof(IOCB_t
));
7375 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
7378 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7383 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
7384 * @phba: Pointer to HBA context object..
7385 * @piocbq: Pointer to command iocb.
7386 * @flag: Flag to test.
7388 * This routine grabs the hbalock and then test the iocb_flag to
7389 * see if the passed in flag is set.
7392 * 0 if flag is not set.
7395 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
7396 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
7398 unsigned long iflags
;
7401 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7402 ret
= piocbq
->iocb_flag
& flag
;
7403 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7409 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
7410 * @phba: Pointer to HBA context object..
7411 * @pring: Pointer to sli ring.
7412 * @piocb: Pointer to command iocb.
7413 * @prspiocbq: Pointer to response iocb.
7414 * @timeout: Timeout in number of seconds.
7416 * This function issues the iocb to firmware and waits for the
7417 * iocb to complete. If the iocb command is not
7418 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
7419 * Caller should not free the iocb resources if this function
7420 * returns IOCB_TIMEDOUT.
7421 * The function waits for the iocb completion using an
7422 * non-interruptible wait.
7423 * This function will sleep while waiting for iocb completion.
7424 * So, this function should not be called from any context which
7425 * does not allow sleeping. Due to the same reason, this function
7426 * cannot be called with interrupt disabled.
7427 * This function assumes that the iocb completions occur while
7428 * this function sleep. So, this function cannot be called from
7429 * the thread which process iocb completion for this ring.
7430 * This function clears the iocb_flag of the iocb object before
7431 * issuing the iocb and the iocb completion handler sets this
7432 * flag and wakes this thread when the iocb completes.
7433 * The contents of the response iocb will be copied to prspiocbq
7434 * by the completion handler when the command completes.
7435 * This function returns IOCB_SUCCESS when success.
7436 * This function is called with no lock held.
7439 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
7440 uint32_t ring_number
,
7441 struct lpfc_iocbq
*piocb
,
7442 struct lpfc_iocbq
*prspiocbq
,
7445 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
7446 long timeleft
, timeout_req
= 0;
7447 int retval
= IOCB_SUCCESS
;
7451 * If the caller has provided a response iocbq buffer, then context2
7452 * is NULL or its an error.
7455 if (piocb
->context2
)
7457 piocb
->context2
= prspiocbq
;
7460 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
7461 piocb
->context_un
.wait_queue
= &done_q
;
7462 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
7464 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7465 creg_val
= readl(phba
->HCregaddr
);
7466 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
7467 writel(creg_val
, phba
->HCregaddr
);
7468 readl(phba
->HCregaddr
); /* flush */
7471 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, 0);
7472 if (retval
== IOCB_SUCCESS
) {
7473 timeout_req
= timeout
* HZ
;
7474 timeleft
= wait_event_timeout(done_q
,
7475 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
7478 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
7479 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7480 "0331 IOCB wake signaled\n");
7481 } else if (timeleft
== 0) {
7482 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7483 "0338 IOCB wait timeout error - no "
7484 "wake response Data x%x\n", timeout
);
7485 retval
= IOCB_TIMEDOUT
;
7487 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7488 "0330 IOCB wake NOT set, "
7490 timeout
, (timeleft
/ jiffies
));
7491 retval
= IOCB_TIMEDOUT
;
7494 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7495 "0332 IOCB wait issue failed, Data x%x\n",
7497 retval
= IOCB_ERROR
;
7500 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7501 creg_val
= readl(phba
->HCregaddr
);
7502 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
7503 writel(creg_val
, phba
->HCregaddr
);
7504 readl(phba
->HCregaddr
); /* flush */
7508 piocb
->context2
= NULL
;
7510 piocb
->context_un
.wait_queue
= NULL
;
7511 piocb
->iocb_cmpl
= NULL
;
7516 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
7517 * @phba: Pointer to HBA context object.
7518 * @pmboxq: Pointer to driver mailbox object.
7519 * @timeout: Timeout in number of seconds.
7521 * This function issues the mailbox to firmware and waits for the
7522 * mailbox command to complete. If the mailbox command is not
7523 * completed within timeout seconds, it returns MBX_TIMEOUT.
7524 * The function waits for the mailbox completion using an
7525 * interruptible wait. If the thread is woken up due to a
7526 * signal, MBX_TIMEOUT error is returned to the caller. Caller
7527 * should not free the mailbox resources, if this function returns
7529 * This function will sleep while waiting for mailbox completion.
7530 * So, this function should not be called from any context which
7531 * does not allow sleeping. Due to the same reason, this function
7532 * cannot be called with interrupt disabled.
7533 * This function assumes that the mailbox completion occurs while
7534 * this function sleep. So, this function cannot be called from
7535 * the worker thread which processes mailbox completion.
7536 * This function is called in the context of HBA management
7538 * This function returns MBX_SUCCESS when successful.
7539 * This function is called with no lock held.
7542 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
7545 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
7549 /* The caller must leave context1 empty. */
7550 if (pmboxq
->context1
)
7551 return MBX_NOT_FINISHED
;
7553 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
7554 /* setup wake call as IOCB callback */
7555 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
7556 /* setup context field to pass wait_queue pointer to wake function */
7557 pmboxq
->context1
= &done_q
;
7559 /* now issue the command */
7560 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
7562 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
7563 wait_event_interruptible_timeout(done_q
,
7564 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
7567 spin_lock_irqsave(&phba
->hbalock
, flag
);
7568 pmboxq
->context1
= NULL
;
7570 * if LPFC_MBX_WAKE flag is set the mailbox is completed
7571 * else do not free the resources.
7573 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
)
7574 retval
= MBX_SUCCESS
;
7576 retval
= MBX_TIMEOUT
;
7577 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
7579 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
7586 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
7587 * @phba: Pointer to HBA context.
7589 * This function is called to shutdown the driver's mailbox sub-system.
7590 * It first marks the mailbox sub-system is in a block state to prevent
7591 * the asynchronous mailbox command from issued off the pending mailbox
7592 * command queue. If the mailbox command sub-system shutdown is due to
7593 * HBA error conditions such as EEH or ERATT, this routine shall invoke
7594 * the mailbox sub-system flush routine to forcefully bring down the
7595 * mailbox sub-system. Otherwise, if it is due to normal condition (such
7596 * as with offline or HBA function reset), this routine will wait for the
7597 * outstanding mailbox command to complete before invoking the mailbox
7598 * sub-system flush routine to gracefully bring down mailbox sub-system.
7601 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
7603 struct lpfc_sli
*psli
= &phba
->sli
;
7604 uint8_t actcmd
= MBX_HEARTBEAT
;
7605 unsigned long timeout
;
7607 spin_lock_irq(&phba
->hbalock
);
7608 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7609 spin_unlock_irq(&phba
->hbalock
);
7611 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7612 spin_lock_irq(&phba
->hbalock
);
7613 if (phba
->sli
.mbox_active
)
7614 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
7615 spin_unlock_irq(&phba
->hbalock
);
7616 /* Determine how long we might wait for the active mailbox
7617 * command to be gracefully completed by firmware.
7619 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) *
7621 while (phba
->sli
.mbox_active
) {
7622 /* Check active mailbox complete status every 2ms */
7624 if (time_after(jiffies
, timeout
))
7625 /* Timeout, let the mailbox flush routine to
7626 * forcefully release active mailbox command
7631 lpfc_sli_mbox_sys_flush(phba
);
7635 * lpfc_sli_eratt_read - read sli-3 error attention events
7636 * @phba: Pointer to HBA context.
7638 * This function is called to read the SLI3 device error attention registers
7639 * for possible error attention events. The caller must hold the hostlock
7640 * with spin_lock_irq().
7642 * This fucntion returns 1 when there is Error Attention in the Host Attention
7643 * Register and returns 0 otherwise.
7646 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
7650 /* Read chip Host Attention (HA) register */
7651 ha_copy
= readl(phba
->HAregaddr
);
7652 if (ha_copy
& HA_ERATT
) {
7653 /* Read host status register to retrieve error event */
7654 lpfc_sli_read_hs(phba
);
7656 /* Check if there is a deferred error condition is active */
7657 if ((HS_FFER1
& phba
->work_hs
) &&
7658 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
7659 HS_FFER6
| HS_FFER7
) & phba
->work_hs
)) {
7660 phba
->hba_flag
|= DEFER_ERATT
;
7661 /* Clear all interrupt enable conditions */
7662 writel(0, phba
->HCregaddr
);
7663 readl(phba
->HCregaddr
);
7666 /* Set the driver HA work bitmap */
7667 phba
->work_ha
|= HA_ERATT
;
7668 /* Indicate polling handles this ERATT */
7669 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7676 * lpfc_sli4_eratt_read - read sli-4 error attention events
7677 * @phba: Pointer to HBA context.
7679 * This function is called to read the SLI4 device error attention registers
7680 * for possible error attention events. The caller must hold the hostlock
7681 * with spin_lock_irq().
7683 * This fucntion returns 1 when there is Error Attention in the Host Attention
7684 * Register and returns 0 otherwise.
7687 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
7689 uint32_t uerr_sta_hi
, uerr_sta_lo
;
7690 uint32_t onlnreg0
, onlnreg1
;
7692 /* For now, use the SLI4 device internal unrecoverable error
7693 * registers for error attention. This can be changed later.
7695 onlnreg0
= readl(phba
->sli4_hba
.ONLINE0regaddr
);
7696 onlnreg1
= readl(phba
->sli4_hba
.ONLINE1regaddr
);
7697 if ((onlnreg0
!= LPFC_ONLINE_NERR
) || (onlnreg1
!= LPFC_ONLINE_NERR
)) {
7698 uerr_sta_lo
= readl(phba
->sli4_hba
.UERRLOregaddr
);
7699 uerr_sta_hi
= readl(phba
->sli4_hba
.UERRHIregaddr
);
7700 if (uerr_sta_lo
|| uerr_sta_hi
) {
7701 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7702 "1423 HBA Unrecoverable error: "
7703 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
7704 "online0_reg=0x%x, online1_reg=0x%x\n",
7705 uerr_sta_lo
, uerr_sta_hi
,
7706 onlnreg0
, onlnreg1
);
7707 phba
->work_status
[0] = uerr_sta_lo
;
7708 phba
->work_status
[1] = uerr_sta_hi
;
7709 /* Set the driver HA work bitmap */
7710 phba
->work_ha
|= HA_ERATT
;
7711 /* Indicate polling handles this ERATT */
7712 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7720 * lpfc_sli_check_eratt - check error attention events
7721 * @phba: Pointer to HBA context.
7723 * This function is called from timer soft interrupt context to check HBA's
7724 * error attention register bit for error attention events.
7726 * This fucntion returns 1 when there is Error Attention in the Host Attention
7727 * Register and returns 0 otherwise.
7730 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
7734 /* If somebody is waiting to handle an eratt, don't process it
7735 * here. The brdkill function will do this.
7737 if (phba
->link_flag
& LS_IGNORE_ERATT
)
7740 /* Check if interrupt handler handles this ERATT */
7741 spin_lock_irq(&phba
->hbalock
);
7742 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
7743 /* Interrupt handler has handled ERATT */
7744 spin_unlock_irq(&phba
->hbalock
);
7749 * If there is deferred error attention, do not check for error
7752 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7753 spin_unlock_irq(&phba
->hbalock
);
7757 /* If PCI channel is offline, don't process it */
7758 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7759 spin_unlock_irq(&phba
->hbalock
);
7763 switch (phba
->sli_rev
) {
7766 /* Read chip Host Attention (HA) register */
7767 ha_copy
= lpfc_sli_eratt_read(phba
);
7770 /* Read devcie Uncoverable Error (UERR) registers */
7771 ha_copy
= lpfc_sli4_eratt_read(phba
);
7774 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7775 "0299 Invalid SLI revision (%d)\n",
7780 spin_unlock_irq(&phba
->hbalock
);
7786 * lpfc_intr_state_check - Check device state for interrupt handling
7787 * @phba: Pointer to HBA context.
7789 * This inline routine checks whether a device or its PCI slot is in a state
7790 * that the interrupt should be handled.
7792 * This function returns 0 if the device or the PCI slot is in a state that
7793 * interrupt should be handled, otherwise -EIO.
7796 lpfc_intr_state_check(struct lpfc_hba
*phba
)
7798 /* If the pci channel is offline, ignore all the interrupts */
7799 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7802 /* Update device level interrupt statistics */
7803 phba
->sli
.slistat
.sli_intr
++;
7805 /* Ignore all interrupts during initialization. */
7806 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7813 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
7814 * @irq: Interrupt number.
7815 * @dev_id: The device context pointer.
7817 * This function is directly called from the PCI layer as an interrupt
7818 * service routine when device with SLI-3 interface spec is enabled with
7819 * MSI-X multi-message interrupt mode and there are slow-path events in
7820 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
7821 * interrupt mode, this function is called as part of the device-level
7822 * interrupt handler. When the PCI slot is in error recovery or the HBA
7823 * is undergoing initialization, the interrupt handler will not process
7824 * the interrupt. The link attention and ELS ring attention events are
7825 * handled by the worker thread. The interrupt handler signals the worker
7826 * thread and returns for these events. This function is called without
7827 * any lock held. It gets the hbalock to access and update SLI data
7830 * This function returns IRQ_HANDLED when interrupt is handled else it
7834 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
7836 struct lpfc_hba
*phba
;
7838 uint32_t work_ha_copy
;
7839 unsigned long status
;
7840 unsigned long iflag
;
7843 MAILBOX_t
*mbox
, *pmbox
;
7844 struct lpfc_vport
*vport
;
7845 struct lpfc_nodelist
*ndlp
;
7846 struct lpfc_dmabuf
*mp
;
7851 * Get the driver's phba structure from the dev_id and
7852 * assume the HBA is not interrupting.
7854 phba
= (struct lpfc_hba
*)dev_id
;
7856 if (unlikely(!phba
))
7860 * Stuff needs to be attented to when this function is invoked as an
7861 * individual interrupt handler in MSI-X multi-message interrupt mode
7863 if (phba
->intr_type
== MSIX
) {
7864 /* Check device state for handling interrupt */
7865 if (lpfc_intr_state_check(phba
))
7867 /* Need to read HA REG for slow-path events */
7868 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7869 ha_copy
= readl(phba
->HAregaddr
);
7870 /* If somebody is waiting to handle an eratt don't process it
7871 * here. The brdkill function will do this.
7873 if (phba
->link_flag
& LS_IGNORE_ERATT
)
7874 ha_copy
&= ~HA_ERATT
;
7875 /* Check the need for handling ERATT in interrupt handler */
7876 if (ha_copy
& HA_ERATT
) {
7877 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
7878 /* ERATT polling has handled ERATT */
7879 ha_copy
&= ~HA_ERATT
;
7881 /* Indicate interrupt handler handles ERATT */
7882 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7886 * If there is deferred error attention, do not check for any
7889 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7890 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7894 /* Clear up only attention source related to slow-path */
7895 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
7897 readl(phba
->HAregaddr
); /* flush */
7898 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7900 ha_copy
= phba
->ha_copy
;
7902 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
7905 if (work_ha_copy
& HA_LATT
) {
7906 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
7908 * Turn off Link Attention interrupts
7909 * until CLEAR_LA done
7911 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7912 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
7913 control
= readl(phba
->HCregaddr
);
7914 control
&= ~HC_LAINT_ENA
;
7915 writel(control
, phba
->HCregaddr
);
7916 readl(phba
->HCregaddr
); /* flush */
7917 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7920 work_ha_copy
&= ~HA_LATT
;
7923 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
7925 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
7926 * the only slow ring.
7928 status
= (work_ha_copy
&
7929 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
7930 status
>>= (4*LPFC_ELS_RING
);
7931 if (status
& HA_RXMASK
) {
7932 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7933 control
= readl(phba
->HCregaddr
);
7935 lpfc_debugfs_slow_ring_trc(phba
,
7936 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
7938 (uint32_t)phba
->sli
.slistat
.sli_intr
);
7940 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
7941 lpfc_debugfs_slow_ring_trc(phba
,
7943 "pwork:x%x hawork:x%x wait:x%x",
7944 phba
->work_ha
, work_ha_copy
,
7945 (uint32_t)((unsigned long)
7946 &phba
->work_waitq
));
7949 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
7950 writel(control
, phba
->HCregaddr
);
7951 readl(phba
->HCregaddr
); /* flush */
7954 lpfc_debugfs_slow_ring_trc(phba
,
7955 "ISR slow ring: pwork:"
7956 "x%x hawork:x%x wait:x%x",
7957 phba
->work_ha
, work_ha_copy
,
7958 (uint32_t)((unsigned long)
7959 &phba
->work_waitq
));
7961 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7964 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7965 if (work_ha_copy
& HA_ERATT
) {
7966 lpfc_sli_read_hs(phba
);
7968 * Check if there is a deferred error condition
7971 if ((HS_FFER1
& phba
->work_hs
) &&
7972 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
7973 HS_FFER6
| HS_FFER7
) & phba
->work_hs
)) {
7974 phba
->hba_flag
|= DEFER_ERATT
;
7975 /* Clear all interrupt enable conditions */
7976 writel(0, phba
->HCregaddr
);
7977 readl(phba
->HCregaddr
);
7981 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
7982 pmb
= phba
->sli
.mbox_active
;
7987 /* First check out the status word */
7988 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
7989 if (pmbox
->mbxOwner
!= OWN_HOST
) {
7990 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7992 * Stray Mailbox Interrupt, mbxCommand <cmd>
7993 * mbxStatus <status>
7995 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
7997 "(%d):0304 Stray Mailbox "
7998 "Interrupt mbxCommand x%x "
8000 (vport
? vport
->vpi
: 0),
8003 /* clear mailbox attention bit */
8004 work_ha_copy
&= ~HA_MBATT
;
8006 phba
->sli
.mbox_active
= NULL
;
8007 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8008 phba
->last_completion_time
= jiffies
;
8009 del_timer(&phba
->sli
.mbox_tmo
);
8010 if (pmb
->mbox_cmpl
) {
8011 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
8014 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8015 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8017 lpfc_debugfs_disc_trc(vport
,
8018 LPFC_DISC_TRC_MBOX_VPORT
,
8020 "status:x%x rpi:x%x",
8021 (uint32_t)pmbox
->mbxStatus
,
8022 pmbox
->un
.varWords
[0], 0);
8024 if (!pmbox
->mbxStatus
) {
8025 mp
= (struct lpfc_dmabuf
*)
8027 ndlp
= (struct lpfc_nodelist
*)
8030 /* Reg_LOGIN of dflt RPI was
8031 * successful. new lets get
8032 * rid of the RPI using the
8035 lpfc_unreg_login(phba
,
8037 pmbox
->un
.varWords
[0],
8040 lpfc_mbx_cmpl_dflt_rpi
;
8042 pmb
->context2
= ndlp
;
8044 rc
= lpfc_sli_issue_mbox(phba
,
8048 lpfc_printf_log(phba
,
8051 "0350 rc should have"
8053 if (rc
!= MBX_NOT_FINISHED
)
8054 goto send_current_mbox
;
8058 &phba
->pport
->work_port_lock
,
8060 phba
->pport
->work_port_events
&=
8062 spin_unlock_irqrestore(
8063 &phba
->pport
->work_port_lock
,
8065 lpfc_mbox_cmpl_put(phba
, pmb
);
8068 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8070 if ((work_ha_copy
& HA_MBATT
) &&
8071 (phba
->sli
.mbox_active
== NULL
)) {
8073 /* Process next mailbox command if there is one */
8075 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
8077 } while (rc
== MBX_NOT_FINISHED
);
8078 if (rc
!= MBX_SUCCESS
)
8079 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8080 LOG_SLI
, "0349 rc should be "
8084 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8085 phba
->work_ha
|= work_ha_copy
;
8086 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8087 lpfc_worker_wake_up(phba
);
8091 } /* lpfc_sli_sp_intr_handler */
8094 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
8095 * @irq: Interrupt number.
8096 * @dev_id: The device context pointer.
8098 * This function is directly called from the PCI layer as an interrupt
8099 * service routine when device with SLI-3 interface spec is enabled with
8100 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8101 * ring event in the HBA. However, when the device is enabled with either
8102 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8103 * device-level interrupt handler. When the PCI slot is in error recovery
8104 * or the HBA is undergoing initialization, the interrupt handler will not
8105 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8106 * the intrrupt context. This function is called without any lock held.
8107 * It gets the hbalock to access and update SLI data structures.
8109 * This function returns IRQ_HANDLED when interrupt is handled else it
8113 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
8115 struct lpfc_hba
*phba
;
8117 unsigned long status
;
8118 unsigned long iflag
;
8120 /* Get the driver's phba structure from the dev_id and
8121 * assume the HBA is not interrupting.
8123 phba
= (struct lpfc_hba
*) dev_id
;
8125 if (unlikely(!phba
))
8129 * Stuff needs to be attented to when this function is invoked as an
8130 * individual interrupt handler in MSI-X multi-message interrupt mode
8132 if (phba
->intr_type
== MSIX
) {
8133 /* Check device state for handling interrupt */
8134 if (lpfc_intr_state_check(phba
))
8136 /* Need to read HA REG for FCP ring and other ring events */
8137 ha_copy
= readl(phba
->HAregaddr
);
8138 /* Clear up only attention source related to fast-path */
8139 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8141 * If there is deferred error attention, do not check for
8144 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8145 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8148 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
8150 readl(phba
->HAregaddr
); /* flush */
8151 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8153 ha_copy
= phba
->ha_copy
;
8156 * Process all events on FCP ring. Take the optimized path for FCP IO.
8158 ha_copy
&= ~(phba
->work_ha_mask
);
8160 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8161 status
>>= (4*LPFC_FCP_RING
);
8162 if (status
& HA_RXMASK
)
8163 lpfc_sli_handle_fast_ring_event(phba
,
8164 &phba
->sli
.ring
[LPFC_FCP_RING
],
8167 if (phba
->cfg_multi_ring_support
== 2) {
8169 * Process all events on extra ring. Take the optimized path
8170 * for extra ring IO.
8172 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8173 status
>>= (4*LPFC_EXTRA_RING
);
8174 if (status
& HA_RXMASK
) {
8175 lpfc_sli_handle_fast_ring_event(phba
,
8176 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
8181 } /* lpfc_sli_fp_intr_handler */
8184 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
8185 * @irq: Interrupt number.
8186 * @dev_id: The device context pointer.
8188 * This function is the HBA device-level interrupt handler to device with
8189 * SLI-3 interface spec, called from the PCI layer when either MSI or
8190 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
8191 * requires driver attention. This function invokes the slow-path interrupt
8192 * attention handling function and fast-path interrupt attention handling
8193 * function in turn to process the relevant HBA attention events. This
8194 * function is called without any lock held. It gets the hbalock to access
8195 * and update SLI data structures.
8197 * This function returns IRQ_HANDLED when interrupt is handled, else it
8201 lpfc_sli_intr_handler(int irq
, void *dev_id
)
8203 struct lpfc_hba
*phba
;
8204 irqreturn_t sp_irq_rc
, fp_irq_rc
;
8205 unsigned long status1
, status2
;
8208 * Get the driver's phba structure from the dev_id and
8209 * assume the HBA is not interrupting.
8211 phba
= (struct lpfc_hba
*) dev_id
;
8213 if (unlikely(!phba
))
8216 /* Check device state for handling interrupt */
8217 if (lpfc_intr_state_check(phba
))
8220 spin_lock(&phba
->hbalock
);
8221 phba
->ha_copy
= readl(phba
->HAregaddr
);
8222 if (unlikely(!phba
->ha_copy
)) {
8223 spin_unlock(&phba
->hbalock
);
8225 } else if (phba
->ha_copy
& HA_ERATT
) {
8226 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
8227 /* ERATT polling has handled ERATT */
8228 phba
->ha_copy
&= ~HA_ERATT
;
8230 /* Indicate interrupt handler handles ERATT */
8231 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8235 * If there is deferred error attention, do not check for any interrupt.
8237 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8238 spin_unlock_irq(&phba
->hbalock
);
8242 /* Clear attention sources except link and error attentions */
8243 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
8244 readl(phba
->HAregaddr
); /* flush */
8245 spin_unlock(&phba
->hbalock
);
8248 * Invokes slow-path host attention interrupt handling as appropriate.
8251 /* status of events with mailbox and link attention */
8252 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
8254 /* status of events with ELS ring */
8255 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
8256 status2
>>= (4*LPFC_ELS_RING
);
8258 if (status1
|| (status2
& HA_RXMASK
))
8259 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
8261 sp_irq_rc
= IRQ_NONE
;
8264 * Invoke fast-path host attention interrupt handling as appropriate.
8267 /* status of events with FCP ring */
8268 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8269 status1
>>= (4*LPFC_FCP_RING
);
8271 /* status of events with extra ring */
8272 if (phba
->cfg_multi_ring_support
== 2) {
8273 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8274 status2
>>= (4*LPFC_EXTRA_RING
);
8278 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
8279 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
8281 fp_irq_rc
= IRQ_NONE
;
8283 /* Return device-level interrupt handling status */
8284 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
8285 } /* lpfc_sli_intr_handler */
8288 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
8289 * @phba: pointer to lpfc hba data structure.
8291 * This routine is invoked by the worker thread to process all the pending
8292 * SLI4 FCP abort XRI events.
8294 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
8296 struct lpfc_cq_event
*cq_event
;
8298 /* First, declare the fcp xri abort event has been handled */
8299 spin_lock_irq(&phba
->hbalock
);
8300 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
8301 spin_unlock_irq(&phba
->hbalock
);
8302 /* Now, handle all the fcp xri abort events */
8303 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
8304 /* Get the first event from the head of the event queue */
8305 spin_lock_irq(&phba
->hbalock
);
8306 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
8307 cq_event
, struct lpfc_cq_event
, list
);
8308 spin_unlock_irq(&phba
->hbalock
);
8309 /* Notify aborted XRI for FCP work queue */
8310 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
8311 /* Free the event processed back to the free pool */
8312 lpfc_sli4_cq_event_release(phba
, cq_event
);
8317 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
8318 * @phba: pointer to lpfc hba data structure.
8320 * This routine is invoked by the worker thread to process all the pending
8321 * SLI4 els abort xri events.
8323 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
8325 struct lpfc_cq_event
*cq_event
;
8327 /* First, declare the els xri abort event has been handled */
8328 spin_lock_irq(&phba
->hbalock
);
8329 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
8330 spin_unlock_irq(&phba
->hbalock
);
8331 /* Now, handle all the els xri abort events */
8332 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
8333 /* Get the first event from the head of the event queue */
8334 spin_lock_irq(&phba
->hbalock
);
8335 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
8336 cq_event
, struct lpfc_cq_event
, list
);
8337 spin_unlock_irq(&phba
->hbalock
);
8338 /* Notify aborted XRI for ELS work queue */
8339 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
8340 /* Free the event processed back to the free pool */
8341 lpfc_sli4_cq_event_release(phba
, cq_event
);
8346 lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq
*pIocbIn
,
8347 struct lpfc_iocbq
*pIocbOut
,
8348 struct lpfc_wcqe_complete
*wcqe
)
8350 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
8352 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
8353 sizeof(struct lpfc_iocbq
) - offset
);
8354 memset(&pIocbIn
->sli4_info
, 0,
8355 sizeof(struct lpfc_sli4_rspiocb_info
));
8356 /* Map WCQE parameters into irspiocb parameters */
8357 pIocbIn
->iocb
.ulpStatus
= bf_get(lpfc_wcqe_c_status
, wcqe
);
8358 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
8359 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
8360 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
8361 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
8362 wcqe
->total_data_placed
;
8364 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
8366 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
8367 /* Load in additional WCQE parameters */
8368 pIocbIn
->sli4_info
.hw_status
= bf_get(lpfc_wcqe_c_hw_status
, wcqe
);
8369 pIocbIn
->sli4_info
.bfield
= 0;
8370 if (bf_get(lpfc_wcqe_c_xb
, wcqe
))
8371 pIocbIn
->sli4_info
.bfield
|= LPFC_XB
;
8372 if (bf_get(lpfc_wcqe_c_pv
, wcqe
)) {
8373 pIocbIn
->sli4_info
.bfield
|= LPFC_PV
;
8374 pIocbIn
->sli4_info
.priority
=
8375 bf_get(lpfc_wcqe_c_priority
, wcqe
);
8380 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
8381 * @phba: Pointer to HBA context object.
8382 * @cqe: Pointer to mailbox completion queue entry.
8384 * This routine process a mailbox completion queue entry with asynchrous
8387 * Return: true if work posted to worker thread, otherwise false.
8390 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
8392 struct lpfc_cq_event
*cq_event
;
8393 unsigned long iflags
;
8395 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8396 "0392 Async Event: word0:x%x, word1:x%x, "
8397 "word2:x%x, word3:x%x\n", mcqe
->word0
,
8398 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
8400 /* Allocate a new internal CQ_EVENT entry */
8401 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
8403 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8404 "0394 Failed to allocate CQ_EVENT entry\n");
8408 /* Move the CQE into an asynchronous event entry */
8409 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
8410 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8411 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
8412 /* Set the async event flag */
8413 phba
->hba_flag
|= ASYNC_EVENT
;
8414 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8420 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
8421 * @phba: Pointer to HBA context object.
8422 * @cqe: Pointer to mailbox completion queue entry.
8424 * This routine process a mailbox completion queue entry with mailbox
8427 * Return: true if work posted to worker thread, otherwise false.
8430 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
8432 uint32_t mcqe_status
;
8433 MAILBOX_t
*mbox
, *pmbox
;
8434 struct lpfc_mqe
*mqe
;
8435 struct lpfc_vport
*vport
;
8436 struct lpfc_nodelist
*ndlp
;
8437 struct lpfc_dmabuf
*mp
;
8438 unsigned long iflags
;
8440 bool workposted
= false;
8443 /* If not a mailbox complete MCQE, out by checking mailbox consume */
8444 if (!bf_get(lpfc_trailer_completed
, mcqe
))
8445 goto out_no_mqe_complete
;
8447 /* Get the reference to the active mbox command */
8448 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8449 pmb
= phba
->sli
.mbox_active
;
8450 if (unlikely(!pmb
)) {
8451 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
8452 "1832 No pending MBOX command to handle\n");
8453 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8454 goto out_no_mqe_complete
;
8456 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8458 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
8462 /* Reset heartbeat timer */
8463 phba
->last_completion_time
= jiffies
;
8464 del_timer(&phba
->sli
.mbox_tmo
);
8466 /* Move mbox data to caller's mailbox region, do endian swapping */
8467 if (pmb
->mbox_cmpl
&& mbox
)
8468 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
8469 /* Set the mailbox status with SLI4 range 0x4000 */
8470 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
8471 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
)
8472 bf_set(lpfc_mqe_status
, mqe
,
8473 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
8475 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8476 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8477 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
8478 "MBOX dflt rpi: status:x%x rpi:x%x",
8480 pmbox
->un
.varWords
[0], 0);
8481 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
8482 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
8483 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
8484 /* Reg_LOGIN of dflt RPI was successful. Now lets get
8485 * RID of the PPI using the same mbox buffer.
8487 lpfc_unreg_login(phba
, vport
->vpi
,
8488 pmbox
->un
.varWords
[0], pmb
);
8489 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
8491 pmb
->context2
= ndlp
;
8493 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
8495 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8496 LOG_SLI
, "0385 rc should "
8497 "have been MBX_BUSY\n");
8498 if (rc
!= MBX_NOT_FINISHED
)
8499 goto send_current_mbox
;
8502 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
8503 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
8504 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
8506 /* There is mailbox completion work to do */
8507 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8508 __lpfc_mbox_cmpl_put(phba
, pmb
);
8509 phba
->work_ha
|= HA_MBATT
;
8510 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8514 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8515 /* Release the mailbox command posting token */
8516 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8517 /* Setting active mailbox pointer need to be in sync to flag clear */
8518 phba
->sli
.mbox_active
= NULL
;
8519 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8520 /* Wake up worker thread to post the next pending mailbox command */
8521 lpfc_worker_wake_up(phba
);
8522 out_no_mqe_complete
:
8523 if (bf_get(lpfc_trailer_consumed
, mcqe
))
8524 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
8529 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
8530 * @phba: Pointer to HBA context object.
8531 * @cqe: Pointer to mailbox completion queue entry.
8533 * This routine process a mailbox completion queue entry, it invokes the
8534 * proper mailbox complete handling or asynchrous event handling routine
8535 * according to the MCQE's async bit.
8537 * Return: true if work posted to worker thread, otherwise false.
8540 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
8542 struct lpfc_mcqe mcqe
;
8545 /* Copy the mailbox MCQE and convert endian order as needed */
8546 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
8548 /* Invoke the proper event handling routine */
8549 if (!bf_get(lpfc_trailer_async
, &mcqe
))
8550 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
8552 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
8557 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
8558 * @phba: Pointer to HBA context object.
8559 * @wcqe: Pointer to work-queue completion queue entry.
8561 * This routine handles an ELS work-queue completion event.
8563 * Return: true if work posted to worker thread, otherwise false.
8566 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
8567 struct lpfc_wcqe_complete
*wcqe
)
8569 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8570 struct lpfc_iocbq
*cmdiocbq
;
8571 struct lpfc_iocbq
*irspiocbq
;
8572 unsigned long iflags
;
8573 bool workposted
= false;
8575 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8576 pring
->stats
.iocb_event
++;
8577 /* Look up the ELS command IOCB and create pseudo response IOCB */
8578 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
8579 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8580 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8582 if (unlikely(!cmdiocbq
)) {
8583 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8584 "0386 ELS complete with no corresponding "
8585 "cmdiocb: iotag (%d)\n",
8586 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8590 /* Fake the irspiocbq and copy necessary response information */
8591 irspiocbq
= lpfc_sli_get_iocbq(phba
);
8593 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8594 "0387 Failed to allocate an iocbq\n");
8597 lpfc_sli4_iocb_param_transfer(irspiocbq
, cmdiocbq
, wcqe
);
8599 /* Add the irspiocb to the response IOCB work list */
8600 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8601 list_add_tail(&irspiocbq
->list
, &phba
->sli4_hba
.sp_rspiocb_work_queue
);
8602 /* Indicate ELS ring attention */
8603 phba
->work_ha
|= (HA_R0ATT
<< (4*LPFC_ELS_RING
));
8604 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8611 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
8612 * @phba: Pointer to HBA context object.
8613 * @wcqe: Pointer to work-queue completion queue entry.
8615 * This routine handles slow-path WQ entry comsumed event by invoking the
8616 * proper WQ release routine to the slow-path WQ.
8619 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
8620 struct lpfc_wcqe_release
*wcqe
)
8622 /* Check for the slow-path ELS work queue */
8623 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
8624 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
8625 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
8627 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8628 "2579 Slow-path wqe consume event carries "
8629 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
8630 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
8631 phba
->sli4_hba
.els_wq
->queue_id
);
8635 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
8636 * @phba: Pointer to HBA context object.
8637 * @cq: Pointer to a WQ completion queue.
8638 * @wcqe: Pointer to work-queue completion queue entry.
8640 * This routine handles an XRI abort event.
8642 * Return: true if work posted to worker thread, otherwise false.
8645 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
8646 struct lpfc_queue
*cq
,
8647 struct sli4_wcqe_xri_aborted
*wcqe
)
8649 bool workposted
= false;
8650 struct lpfc_cq_event
*cq_event
;
8651 unsigned long iflags
;
8653 /* Allocate a new internal CQ_EVENT entry */
8654 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
8656 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8657 "0602 Failed to allocate CQ_EVENT entry\n");
8661 /* Move the CQE into the proper xri abort event list */
8662 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
8663 switch (cq
->subtype
) {
8665 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8666 list_add_tail(&cq_event
->list
,
8667 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
8668 /* Set the fcp xri abort event flag */
8669 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
8670 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8674 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8675 list_add_tail(&cq_event
->list
,
8676 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
8677 /* Set the els xri abort event flag */
8678 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
8679 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8683 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8684 "0603 Invalid work queue CQE subtype (x%x)\n",
8693 * lpfc_sli4_sp_handle_wcqe - Process a work-queue completion queue entry
8694 * @phba: Pointer to HBA context object.
8695 * @cq: Pointer to the completion queue.
8696 * @wcqe: Pointer to a completion queue entry.
8698 * This routine process a slow-path work-queue completion queue entry.
8700 * Return: true if work posted to worker thread, otherwise false.
8703 lpfc_sli4_sp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
8704 struct lpfc_cqe
*cqe
)
8706 struct lpfc_wcqe_complete wcqe
;
8707 bool workposted
= false;
8709 /* Copy the work queue CQE and convert endian order if needed */
8710 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
8712 /* Check and process for different type of WCQE and dispatch */
8713 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
8714 case CQE_CODE_COMPL_WQE
:
8715 /* Process the WQ complete event */
8716 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
8717 (struct lpfc_wcqe_complete
*)&wcqe
);
8719 case CQE_CODE_RELEASE_WQE
:
8720 /* Process the WQ release event */
8721 lpfc_sli4_sp_handle_rel_wcqe(phba
,
8722 (struct lpfc_wcqe_release
*)&wcqe
);
8724 case CQE_CODE_XRI_ABORTED
:
8725 /* Process the WQ XRI abort event */
8726 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
8727 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
8730 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8731 "0388 Not a valid WCQE code: x%x\n",
8732 bf_get(lpfc_wcqe_c_code
, &wcqe
));
8739 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
8740 * @phba: Pointer to HBA context object.
8741 * @rcqe: Pointer to receive-queue completion queue entry.
8743 * This routine process a receive-queue completion queue entry.
8745 * Return: true if work posted to worker thread, otherwise false.
8748 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
8750 struct lpfc_rcqe rcqe
;
8751 bool workposted
= false;
8752 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
8753 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
8754 struct hbq_dmabuf
*dma_buf
;
8756 unsigned long iflags
;
8758 /* Copy the receive queue CQE and convert endian order if needed */
8759 lpfc_sli_pcimem_bcopy(cqe
, &rcqe
, sizeof(struct lpfc_rcqe
));
8760 lpfc_sli4_rq_release(hrq
, drq
);
8761 if (bf_get(lpfc_rcqe_code
, &rcqe
) != CQE_CODE_RECEIVE
)
8763 if (bf_get(lpfc_rcqe_rq_id
, &rcqe
) != hrq
->queue_id
)
8766 status
= bf_get(lpfc_rcqe_status
, &rcqe
);
8768 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
8769 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8770 "2537 Receive Frame Truncated!!\n");
8771 case FC_STATUS_RQ_SUCCESS
:
8772 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8773 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
8775 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8778 memcpy(&dma_buf
->rcqe
, &rcqe
, sizeof(rcqe
));
8779 /* save off the frame for the word thread to process */
8780 list_add_tail(&dma_buf
->dbuf
.list
, &phba
->rb_pend_list
);
8781 /* Frame received */
8782 phba
->hba_flag
|= HBA_RECEIVE_BUFFER
;
8783 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8786 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
8787 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
8788 /* Post more buffers if possible */
8789 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8790 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
8791 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8801 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
8802 * @phba: Pointer to HBA context object.
8803 * @eqe: Pointer to fast-path event queue entry.
8805 * This routine process a event queue entry from the slow-path event queue.
8806 * It will check the MajorCode and MinorCode to determine this is for a
8807 * completion event on a completion queue, if not, an error shall be logged
8808 * and just return. Otherwise, it will get to the corresponding completion
8809 * queue and process all the entries on that completion queue, rearm the
8810 * completion queue, and then return.
8814 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
8816 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
8817 struct lpfc_cqe
*cqe
;
8818 bool workposted
= false;
8822 if (bf_get(lpfc_eqe_major_code
, eqe
) != 0 ||
8823 bf_get(lpfc_eqe_minor_code
, eqe
) != 0) {
8824 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8825 "0359 Not a valid slow-path completion "
8826 "event: majorcode=x%x, minorcode=x%x\n",
8827 bf_get(lpfc_eqe_major_code
, eqe
),
8828 bf_get(lpfc_eqe_minor_code
, eqe
));
8832 /* Get the reference to the corresponding CQ */
8833 cqid
= bf_get(lpfc_eqe_resource_id
, eqe
);
8835 /* Search for completion queue pointer matching this cqid */
8836 speq
= phba
->sli4_hba
.sp_eq
;
8837 list_for_each_entry(childq
, &speq
->child_list
, list
) {
8838 if (childq
->queue_id
== cqid
) {
8843 if (unlikely(!cq
)) {
8844 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8845 "0365 Slow-path CQ identifier (%d) does "
8846 "not exist\n", cqid
);
8850 /* Process all the entries to the CQ */
8853 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
8854 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
8855 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
8856 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
8860 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
8861 workposted
|= lpfc_sli4_sp_handle_wcqe(phba
, cq
, cqe
);
8862 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
8863 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
8867 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
8868 workposted
|= lpfc_sli4_sp_handle_rcqe(phba
, cqe
);
8869 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
8870 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
8874 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8875 "0370 Invalid completion queue type (%d)\n",
8880 /* Catch the no cq entry condition, log an error */
8881 if (unlikely(ecount
== 0))
8882 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8883 "0371 No entry from the CQ: identifier "
8884 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
8886 /* In any case, flash and re-arm the RCQ */
8887 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
8889 /* wake up worker thread if there are works to be done */
8891 lpfc_worker_wake_up(phba
);
8895 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
8896 * @eqe: Pointer to fast-path completion queue entry.
8898 * This routine process a fast-path work queue completion entry from fast-path
8899 * event queue for FCP command response completion.
8902 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
8903 struct lpfc_wcqe_complete
*wcqe
)
8905 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
8906 struct lpfc_iocbq
*cmdiocbq
;
8907 struct lpfc_iocbq irspiocbq
;
8908 unsigned long iflags
;
8910 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8911 pring
->stats
.iocb_event
++;
8912 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8914 /* Check for response status */
8915 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
8916 /* If resource errors reported from HBA, reduce queue
8917 * depth of the SCSI device.
8919 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
8920 IOSTAT_LOCAL_REJECT
) &&
8921 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
8922 phba
->lpfc_rampdown_queue_depth(phba
);
8924 /* Log the error status */
8925 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8926 "0373 FCP complete error: status=x%x, "
8927 "hw_status=x%x, total_data_specified=%d, "
8928 "parameter=x%x, word3=x%x\n",
8929 bf_get(lpfc_wcqe_c_status
, wcqe
),
8930 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
8931 wcqe
->total_data_placed
, wcqe
->parameter
,
8935 /* Look up the FCP command IOCB and create pseudo response IOCB */
8936 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8937 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
8938 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8939 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8940 if (unlikely(!cmdiocbq
)) {
8941 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8942 "0374 FCP complete with no corresponding "
8943 "cmdiocb: iotag (%d)\n",
8944 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8947 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
8948 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8949 "0375 FCP cmdiocb not callback function "
8951 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8955 /* Fake the irspiocb and copy necessary response information */
8956 lpfc_sli4_iocb_param_transfer(&irspiocbq
, cmdiocbq
, wcqe
);
8958 /* Pass the cmd_iocb and the rsp state to the upper layer */
8959 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
8963 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
8964 * @phba: Pointer to HBA context object.
8965 * @cq: Pointer to completion queue.
8966 * @wcqe: Pointer to work-queue completion queue entry.
8968 * This routine handles an fast-path WQ entry comsumed event by invoking the
8969 * proper WQ release routine to the slow-path WQ.
8972 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
8973 struct lpfc_wcqe_release
*wcqe
)
8975 struct lpfc_queue
*childwq
;
8976 bool wqid_matched
= false;
8979 /* Check for fast-path FCP work queue release */
8980 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
8981 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
8982 if (childwq
->queue_id
== fcp_wqid
) {
8983 lpfc_sli4_wq_release(childwq
,
8984 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
8985 wqid_matched
= true;
8989 /* Report warning log message if no match found */
8990 if (wqid_matched
!= true)
8991 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8992 "2580 Fast-path wqe consume event carries "
8993 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
8997 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
8998 * @cq: Pointer to the completion queue.
8999 * @eqe: Pointer to fast-path completion queue entry.
9001 * This routine process a fast-path work queue completion entry from fast-path
9002 * event queue for FCP command response completion.
9005 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9006 struct lpfc_cqe
*cqe
)
9008 struct lpfc_wcqe_release wcqe
;
9009 bool workposted
= false;
9011 /* Copy the work queue CQE and convert endian order if needed */
9012 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
9014 /* Check and process for different type of WCQE and dispatch */
9015 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
9016 case CQE_CODE_COMPL_WQE
:
9017 /* Process the WQ complete event */
9018 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
9019 (struct lpfc_wcqe_complete
*)&wcqe
);
9021 case CQE_CODE_RELEASE_WQE
:
9022 /* Process the WQ release event */
9023 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
9024 (struct lpfc_wcqe_release
*)&wcqe
);
9026 case CQE_CODE_XRI_ABORTED
:
9027 /* Process the WQ XRI abort event */
9028 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
9029 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
9032 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9033 "0144 Not a valid WCQE code: x%x\n",
9034 bf_get(lpfc_wcqe_c_code
, &wcqe
));
9041 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
9042 * @phba: Pointer to HBA context object.
9043 * @eqe: Pointer to fast-path event queue entry.
9045 * This routine process a event queue entry from the fast-path event queue.
9046 * It will check the MajorCode and MinorCode to determine this is for a
9047 * completion event on a completion queue, if not, an error shall be logged
9048 * and just return. Otherwise, it will get to the corresponding completion
9049 * queue and process all the entries on the completion queue, rearm the
9050 * completion queue, and then return.
9053 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
9056 struct lpfc_queue
*cq
;
9057 struct lpfc_cqe
*cqe
;
9058 bool workposted
= false;
9062 if (unlikely(bf_get(lpfc_eqe_major_code
, eqe
) != 0) ||
9063 unlikely(bf_get(lpfc_eqe_minor_code
, eqe
) != 0)) {
9064 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9065 "0366 Not a valid fast-path completion "
9066 "event: majorcode=x%x, minorcode=x%x\n",
9067 bf_get(lpfc_eqe_major_code
, eqe
),
9068 bf_get(lpfc_eqe_minor_code
, eqe
));
9072 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
9073 if (unlikely(!cq
)) {
9074 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9075 "0367 Fast-path completion queue does not "
9080 /* Get the reference to the corresponding CQ */
9081 cqid
= bf_get(lpfc_eqe_resource_id
, eqe
);
9082 if (unlikely(cqid
!= cq
->queue_id
)) {
9083 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9084 "0368 Miss-matched fast-path completion "
9085 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
9086 cqid
, cq
->queue_id
);
9090 /* Process all the entries to the CQ */
9091 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9092 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
9093 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9094 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9097 /* Catch the no cq entry condition */
9098 if (unlikely(ecount
== 0))
9099 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9100 "0369 No entry from fast-path completion "
9101 "queue fcpcqid=%d\n", cq
->queue_id
);
9103 /* In any case, flash and re-arm the CQ */
9104 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9106 /* wake up worker thread if there are works to be done */
9108 lpfc_worker_wake_up(phba
);
9112 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
9114 struct lpfc_eqe
*eqe
;
9116 /* walk all the EQ entries and drop on the floor */
9117 while ((eqe
= lpfc_sli4_eq_get(eq
)))
9120 /* Clear and re-arm the EQ */
9121 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
9125 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
9126 * @irq: Interrupt number.
9127 * @dev_id: The device context pointer.
9129 * This function is directly called from the PCI layer as an interrupt
9130 * service routine when device with SLI-4 interface spec is enabled with
9131 * MSI-X multi-message interrupt mode and there are slow-path events in
9132 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9133 * interrupt mode, this function is called as part of the device-level
9134 * interrupt handler. When the PCI slot is in error recovery or the HBA is
9135 * undergoing initialization, the interrupt handler will not process the
9136 * interrupt. The link attention and ELS ring attention events are handled
9137 * by the worker thread. The interrupt handler signals the worker thread
9138 * and returns for these events. This function is called without any lock
9139 * held. It gets the hbalock to access and update SLI data structures.
9141 * This function returns IRQ_HANDLED when interrupt is handled else it
9145 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
9147 struct lpfc_hba
*phba
;
9148 struct lpfc_queue
*speq
;
9149 struct lpfc_eqe
*eqe
;
9150 unsigned long iflag
;
9154 * Get the driver's phba structure from the dev_id
9156 phba
= (struct lpfc_hba
*)dev_id
;
9158 if (unlikely(!phba
))
9161 /* Get to the EQ struct associated with this vector */
9162 speq
= phba
->sli4_hba
.sp_eq
;
9164 /* Check device state for handling interrupt */
9165 if (unlikely(lpfc_intr_state_check(phba
))) {
9166 /* Check again for link_state with lock held */
9167 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9168 if (phba
->link_state
< LPFC_LINK_DOWN
)
9169 /* Flush, clear interrupt, and rearm the EQ */
9170 lpfc_sli4_eq_flush(phba
, speq
);
9171 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9176 * Process all the event on FCP slow-path EQ
9178 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
9179 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
9180 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9181 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
9184 /* Always clear and re-arm the slow-path EQ */
9185 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
9187 /* Catch the no cq entry condition */
9188 if (unlikely(ecount
== 0)) {
9189 if (phba
->intr_type
== MSIX
)
9190 /* MSI-X treated interrupt served as no EQ share INT */
9191 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9192 "0357 MSI-X interrupt with no EQE\n");
9194 /* Non MSI-X treated on interrupt as EQ share INT */
9199 } /* lpfc_sli4_sp_intr_handler */
9202 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
9203 * @irq: Interrupt number.
9204 * @dev_id: The device context pointer.
9206 * This function is directly called from the PCI layer as an interrupt
9207 * service routine when device with SLI-4 interface spec is enabled with
9208 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
9209 * ring event in the HBA. However, when the device is enabled with either
9210 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
9211 * device-level interrupt handler. When the PCI slot is in error recovery
9212 * or the HBA is undergoing initialization, the interrupt handler will not
9213 * process the interrupt. The SCSI FCP fast-path ring event are handled in
9214 * the intrrupt context. This function is called without any lock held.
9215 * It gets the hbalock to access and update SLI data structures. Note that,
9216 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
9217 * equal to that of FCP CQ index.
9219 * This function returns IRQ_HANDLED when interrupt is handled else it
9223 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
9225 struct lpfc_hba
*phba
;
9226 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
9227 struct lpfc_queue
*fpeq
;
9228 struct lpfc_eqe
*eqe
;
9229 unsigned long iflag
;
9233 /* Get the driver's phba structure from the dev_id */
9234 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
9235 phba
= fcp_eq_hdl
->phba
;
9236 fcp_eqidx
= fcp_eq_hdl
->idx
;
9238 if (unlikely(!phba
))
9241 /* Get to the EQ struct associated with this vector */
9242 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
9244 /* Check device state for handling interrupt */
9245 if (unlikely(lpfc_intr_state_check(phba
))) {
9246 /* Check again for link_state with lock held */
9247 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9248 if (phba
->link_state
< LPFC_LINK_DOWN
)
9249 /* Flush, clear interrupt, and rearm the EQ */
9250 lpfc_sli4_eq_flush(phba
, fpeq
);
9251 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9256 * Process all the event on FCP fast-path EQ
9258 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9259 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
9260 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9261 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
9264 /* Always clear and re-arm the fast-path EQ */
9265 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
9267 if (unlikely(ecount
== 0)) {
9268 if (phba
->intr_type
== MSIX
)
9269 /* MSI-X treated interrupt served as no EQ share INT */
9270 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9271 "0358 MSI-X interrupt with no EQE\n");
9273 /* Non MSI-X treated on interrupt as EQ share INT */
9278 } /* lpfc_sli4_fp_intr_handler */
9281 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
9282 * @irq: Interrupt number.
9283 * @dev_id: The device context pointer.
9285 * This function is the device-level interrupt handler to device with SLI-4
9286 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
9287 * interrupt mode is enabled and there is an event in the HBA which requires
9288 * driver attention. This function invokes the slow-path interrupt attention
9289 * handling function and fast-path interrupt attention handling function in
9290 * turn to process the relevant HBA attention events. This function is called
9291 * without any lock held. It gets the hbalock to access and update SLI data
9294 * This function returns IRQ_HANDLED when interrupt is handled, else it
9298 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
9300 struct lpfc_hba
*phba
;
9301 irqreturn_t sp_irq_rc
, fp_irq_rc
;
9302 bool fp_handled
= false;
9305 /* Get the driver's phba structure from the dev_id */
9306 phba
= (struct lpfc_hba
*)dev_id
;
9308 if (unlikely(!phba
))
9312 * Invokes slow-path host attention interrupt handling as appropriate.
9314 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
9317 * Invoke fast-path host attention interrupt handling as appropriate.
9319 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
9320 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
9321 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
9322 if (fp_irq_rc
== IRQ_HANDLED
)
9326 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
9327 } /* lpfc_sli4_intr_handler */
9330 * lpfc_sli4_queue_free - free a queue structure and associated memory
9331 * @queue: The queue structure to free.
9333 * This function frees a queue structure and the DMAable memeory used for
9334 * the host resident queue. This function must be called after destroying the
9338 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
9340 struct lpfc_dmabuf
*dmabuf
;
9345 while (!list_empty(&queue
->page_list
)) {
9346 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
9348 dma_free_coherent(&queue
->phba
->pcidev
->dev
, PAGE_SIZE
,
9349 dmabuf
->virt
, dmabuf
->phys
);
9357 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
9358 * @phba: The HBA that this queue is being created on.
9359 * @entry_size: The size of each queue entry for this queue.
9360 * @entry count: The number of entries that this queue will handle.
9362 * This function allocates a queue structure and the DMAable memory used for
9363 * the host resident queue. This function must be called before creating the
9367 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
9368 uint32_t entry_count
)
9370 struct lpfc_queue
*queue
;
9371 struct lpfc_dmabuf
*dmabuf
;
9372 int x
, total_qe_count
;
9376 queue
= kzalloc(sizeof(struct lpfc_queue
) +
9377 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
9380 queue
->page_count
= (PAGE_ALIGN(entry_size
* entry_count
))/PAGE_SIZE
;
9381 INIT_LIST_HEAD(&queue
->list
);
9382 INIT_LIST_HEAD(&queue
->page_list
);
9383 INIT_LIST_HEAD(&queue
->child_list
);
9384 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
9385 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
9388 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
9389 PAGE_SIZE
, &dmabuf
->phys
,
9391 if (!dmabuf
->virt
) {
9395 memset(dmabuf
->virt
, 0, PAGE_SIZE
);
9396 dmabuf
->buffer_tag
= x
;
9397 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
9398 /* initialize queue's entry array */
9399 dma_pointer
= dmabuf
->virt
;
9400 for (; total_qe_count
< entry_count
&&
9401 dma_pointer
< (PAGE_SIZE
+ dmabuf
->virt
);
9402 total_qe_count
++, dma_pointer
+= entry_size
) {
9403 queue
->qe
[total_qe_count
].address
= dma_pointer
;
9406 queue
->entry_size
= entry_size
;
9407 queue
->entry_count
= entry_count
;
9412 lpfc_sli4_queue_free(queue
);
9417 * lpfc_eq_create - Create an Event Queue on the HBA
9418 * @phba: HBA structure that indicates port to create a queue on.
9419 * @eq: The queue structure to use to create the event queue.
9420 * @imax: The maximum interrupt per second limit.
9422 * This function creates an event queue, as detailed in @eq, on a port,
9423 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
9425 * The @phba struct is used to send mailbox command to HBA. The @eq struct
9426 * is used to get the entry count and entry size that are necessary to
9427 * determine the number of pages to allocate and use for this queue. This
9428 * function will send the EQ_CREATE mailbox command to the HBA to setup the
9429 * event queue. This function is asynchronous and will wait for the mailbox
9430 * command to finish before continuing.
9432 * On success this function will return a zero. If unable to allocate enough
9433 * memory this function will return ENOMEM. If the queue create mailbox command
9434 * fails this function will return ENXIO.
9437 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
9439 struct lpfc_mbx_eq_create
*eq_create
;
9441 int rc
, length
, status
= 0;
9442 struct lpfc_dmabuf
*dmabuf
;
9443 uint32_t shdr_status
, shdr_add_status
;
9444 union lpfc_sli4_cfg_shdr
*shdr
;
9447 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9450 length
= (sizeof(struct lpfc_mbx_eq_create
) -
9451 sizeof(struct lpfc_sli4_cfg_mhdr
));
9452 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9453 LPFC_MBOX_OPCODE_EQ_CREATE
,
9454 length
, LPFC_SLI4_MBX_EMBED
);
9455 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
9456 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
9458 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
9460 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
9461 /* Calculate delay multiper from maximum interrupt per second */
9462 dmult
= LPFC_DMULT_CONST
/imax
- 1;
9463 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
9465 switch (eq
->entry_count
) {
9467 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9468 "0360 Unsupported EQ count. (%d)\n",
9470 if (eq
->entry_count
< 256)
9472 /* otherwise default to smallest count (drop through) */
9474 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9478 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9482 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9486 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9490 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9494 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
9495 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9496 putPaddrLow(dmabuf
->phys
);
9497 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9498 putPaddrHigh(dmabuf
->phys
);
9500 mbox
->vport
= phba
->pport
;
9501 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
9502 mbox
->context1
= NULL
;
9503 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9504 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
9505 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9506 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9507 if (shdr_status
|| shdr_add_status
|| rc
) {
9508 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9509 "2500 EQ_CREATE mailbox failed with "
9510 "status x%x add_status x%x, mbx status x%x\n",
9511 shdr_status
, shdr_add_status
, rc
);
9515 eq
->subtype
= LPFC_NONE
;
9516 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
9517 if (eq
->queue_id
== 0xFFFF)
9522 mempool_free(mbox
, phba
->mbox_mem_pool
);
9527 * lpfc_cq_create - Create a Completion Queue on the HBA
9528 * @phba: HBA structure that indicates port to create a queue on.
9529 * @cq: The queue structure to use to create the completion queue.
9530 * @eq: The event queue to bind this completion queue to.
9532 * This function creates a completion queue, as detailed in @wq, on a port,
9533 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
9535 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9536 * is used to get the entry count and entry size that are necessary to
9537 * determine the number of pages to allocate and use for this queue. The @eq
9538 * is used to indicate which event queue to bind this completion queue to. This
9539 * function will send the CQ_CREATE mailbox command to the HBA to setup the
9540 * completion queue. This function is asynchronous and will wait for the mailbox
9541 * command to finish before continuing.
9543 * On success this function will return a zero. If unable to allocate enough
9544 * memory this function will return ENOMEM. If the queue create mailbox command
9545 * fails this function will return ENXIO.
9548 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9549 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
9551 struct lpfc_mbx_cq_create
*cq_create
;
9552 struct lpfc_dmabuf
*dmabuf
;
9554 int rc
, length
, status
= 0;
9555 uint32_t shdr_status
, shdr_add_status
;
9556 union lpfc_sli4_cfg_shdr
*shdr
;
9558 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9561 length
= (sizeof(struct lpfc_mbx_cq_create
) -
9562 sizeof(struct lpfc_sli4_cfg_mhdr
));
9563 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9564 LPFC_MBOX_OPCODE_CQ_CREATE
,
9565 length
, LPFC_SLI4_MBX_EMBED
);
9566 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
9567 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
9569 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
9570 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
9571 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
, eq
->queue_id
);
9572 switch (cq
->entry_count
) {
9574 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9575 "0361 Unsupported CQ count. (%d)\n",
9577 if (cq
->entry_count
< 256)
9579 /* otherwise default to smallest count (drop through) */
9581 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9585 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9589 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9593 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
9594 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9595 putPaddrLow(dmabuf
->phys
);
9596 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9597 putPaddrHigh(dmabuf
->phys
);
9599 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9601 /* The IOCTL status is embedded in the mailbox subheader. */
9602 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
9603 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9604 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9605 if (shdr_status
|| shdr_add_status
|| rc
) {
9606 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9607 "2501 CQ_CREATE mailbox failed with "
9608 "status x%x add_status x%x, mbx status x%x\n",
9609 shdr_status
, shdr_add_status
, rc
);
9613 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
9614 if (cq
->queue_id
== 0xFFFF) {
9618 /* link the cq onto the parent eq child list */
9619 list_add_tail(&cq
->list
, &eq
->child_list
);
9620 /* Set up completion queue's type and subtype */
9622 cq
->subtype
= subtype
;
9623 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
9628 mempool_free(mbox
, phba
->mbox_mem_pool
);
9633 * lpfc_mq_create - Create a mailbox Queue on the HBA
9634 * @phba: HBA structure that indicates port to create a queue on.
9635 * @mq: The queue structure to use to create the mailbox queue.
9637 * This function creates a mailbox queue, as detailed in @mq, on a port,
9638 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
9640 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9641 * is used to get the entry count and entry size that are necessary to
9642 * determine the number of pages to allocate and use for this queue. This
9643 * function will send the MQ_CREATE mailbox command to the HBA to setup the
9644 * mailbox queue. This function is asynchronous and will wait for the mailbox
9645 * command to finish before continuing.
9647 * On success this function will return a zero. If unable to allocate enough
9648 * memory this function will return ENOMEM. If the queue create mailbox command
9649 * fails this function will return ENXIO.
9652 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
9653 struct lpfc_queue
*cq
, uint32_t subtype
)
9655 struct lpfc_mbx_mq_create
*mq_create
;
9656 struct lpfc_dmabuf
*dmabuf
;
9658 int rc
, length
, status
= 0;
9659 uint32_t shdr_status
, shdr_add_status
;
9660 union lpfc_sli4_cfg_shdr
*shdr
;
9662 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9665 length
= (sizeof(struct lpfc_mbx_mq_create
) -
9666 sizeof(struct lpfc_sli4_cfg_mhdr
));
9667 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9668 LPFC_MBOX_OPCODE_MQ_CREATE
,
9669 length
, LPFC_SLI4_MBX_EMBED
);
9670 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
9671 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
9673 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
9675 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
9676 switch (mq
->entry_count
) {
9678 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9679 "0362 Unsupported MQ count. (%d)\n",
9681 if (mq
->entry_count
< 16)
9683 /* otherwise default to smallest count (drop through) */
9685 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9689 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9693 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9697 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9701 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
9702 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9703 putPaddrLow(dmabuf
->phys
);
9704 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9705 putPaddrHigh(dmabuf
->phys
);
9707 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9708 /* The IOCTL status is embedded in the mailbox subheader. */
9709 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
9710 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9711 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9712 if (shdr_status
|| shdr_add_status
|| rc
) {
9713 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9714 "2502 MQ_CREATE mailbox failed with "
9715 "status x%x add_status x%x, mbx status x%x\n",
9716 shdr_status
, shdr_add_status
, rc
);
9720 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
, &mq_create
->u
.response
);
9721 if (mq
->queue_id
== 0xFFFF) {
9726 mq
->subtype
= subtype
;
9730 /* link the mq onto the parent cq child list */
9731 list_add_tail(&mq
->list
, &cq
->child_list
);
9733 mempool_free(mbox
, phba
->mbox_mem_pool
);
9738 * lpfc_wq_create - Create a Work Queue on the HBA
9739 * @phba: HBA structure that indicates port to create a queue on.
9740 * @wq: The queue structure to use to create the work queue.
9741 * @cq: The completion queue to bind this work queue to.
9742 * @subtype: The subtype of the work queue indicating its functionality.
9744 * This function creates a work queue, as detailed in @wq, on a port, described
9745 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
9747 * The @phba struct is used to send mailbox command to HBA. The @wq struct
9748 * is used to get the entry count and entry size that are necessary to
9749 * determine the number of pages to allocate and use for this queue. The @cq
9750 * is used to indicate which completion queue to bind this work queue to. This
9751 * function will send the WQ_CREATE mailbox command to the HBA to setup the
9752 * work queue. This function is asynchronous and will wait for the mailbox
9753 * command to finish before continuing.
9755 * On success this function will return a zero. If unable to allocate enough
9756 * memory this function will return ENOMEM. If the queue create mailbox command
9757 * fails this function will return ENXIO.
9760 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
9761 struct lpfc_queue
*cq
, uint32_t subtype
)
9763 struct lpfc_mbx_wq_create
*wq_create
;
9764 struct lpfc_dmabuf
*dmabuf
;
9766 int rc
, length
, status
= 0;
9767 uint32_t shdr_status
, shdr_add_status
;
9768 union lpfc_sli4_cfg_shdr
*shdr
;
9770 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9773 length
= (sizeof(struct lpfc_mbx_wq_create
) -
9774 sizeof(struct lpfc_sli4_cfg_mhdr
));
9775 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
9776 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
9777 length
, LPFC_SLI4_MBX_EMBED
);
9778 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
9779 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
9781 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
9783 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
9784 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9785 putPaddrLow(dmabuf
->phys
);
9786 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9787 putPaddrHigh(dmabuf
->phys
);
9789 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9790 /* The IOCTL status is embedded in the mailbox subheader. */
9791 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
9792 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9793 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9794 if (shdr_status
|| shdr_add_status
|| rc
) {
9795 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9796 "2503 WQ_CREATE mailbox failed with "
9797 "status x%x add_status x%x, mbx status x%x\n",
9798 shdr_status
, shdr_add_status
, rc
);
9802 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
9803 if (wq
->queue_id
== 0xFFFF) {
9808 wq
->subtype
= subtype
;
9812 /* link the wq onto the parent cq child list */
9813 list_add_tail(&wq
->list
, &cq
->child_list
);
9815 mempool_free(mbox
, phba
->mbox_mem_pool
);
9820 * lpfc_rq_create - Create a Receive Queue on the HBA
9821 * @phba: HBA structure that indicates port to create a queue on.
9822 * @hrq: The queue structure to use to create the header receive queue.
9823 * @drq: The queue structure to use to create the data receive queue.
9824 * @cq: The completion queue to bind this work queue to.
9826 * This function creates a receive buffer queue pair , as detailed in @hrq and
9827 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
9830 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
9831 * struct is used to get the entry count that is necessary to determine the
9832 * number of pages to use for this queue. The @cq is used to indicate which
9833 * completion queue to bind received buffers that are posted to these queues to.
9834 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
9835 * receive queue pair. This function is asynchronous and will wait for the
9836 * mailbox command to finish before continuing.
9838 * On success this function will return a zero. If unable to allocate enough
9839 * memory this function will return ENOMEM. If the queue create mailbox command
9840 * fails this function will return ENXIO.
9843 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
9844 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
9846 struct lpfc_mbx_rq_create
*rq_create
;
9847 struct lpfc_dmabuf
*dmabuf
;
9849 int rc
, length
, status
= 0;
9850 uint32_t shdr_status
, shdr_add_status
;
9851 union lpfc_sli4_cfg_shdr
*shdr
;
9853 if (hrq
->entry_count
!= drq
->entry_count
)
9855 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9858 length
= (sizeof(struct lpfc_mbx_rq_create
) -
9859 sizeof(struct lpfc_sli4_cfg_mhdr
));
9860 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
9861 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
9862 length
, LPFC_SLI4_MBX_EMBED
);
9863 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
9864 switch (hrq
->entry_count
) {
9866 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9867 "2535 Unsupported RQ count. (%d)\n",
9869 if (hrq
->entry_count
< 512)
9871 /* otherwise default to smallest count (drop through) */
9873 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9874 LPFC_RQ_RING_SIZE_512
);
9877 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9878 LPFC_RQ_RING_SIZE_1024
);
9881 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9882 LPFC_RQ_RING_SIZE_2048
);
9885 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9886 LPFC_RQ_RING_SIZE_4096
);
9889 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
9891 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
9893 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
9895 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
9896 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9897 putPaddrLow(dmabuf
->phys
);
9898 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9899 putPaddrHigh(dmabuf
->phys
);
9901 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9902 /* The IOCTL status is embedded in the mailbox subheader. */
9903 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
9904 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9905 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9906 if (shdr_status
|| shdr_add_status
|| rc
) {
9907 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9908 "2504 RQ_CREATE mailbox failed with "
9909 "status x%x add_status x%x, mbx status x%x\n",
9910 shdr_status
, shdr_add_status
, rc
);
9914 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
9915 if (hrq
->queue_id
== 0xFFFF) {
9919 hrq
->type
= LPFC_HRQ
;
9920 hrq
->subtype
= subtype
;
9921 hrq
->host_index
= 0;
9924 /* now create the data queue */
9925 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
9926 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
9927 length
, LPFC_SLI4_MBX_EMBED
);
9928 switch (drq
->entry_count
) {
9930 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9931 "2536 Unsupported RQ count. (%d)\n",
9933 if (drq
->entry_count
< 512)
9935 /* otherwise default to smallest count (drop through) */
9937 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9938 LPFC_RQ_RING_SIZE_512
);
9941 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9942 LPFC_RQ_RING_SIZE_1024
);
9945 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9946 LPFC_RQ_RING_SIZE_2048
);
9949 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
9950 LPFC_RQ_RING_SIZE_4096
);
9953 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
9955 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
9957 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
9958 LPFC_DATA_BUF_SIZE
);
9959 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
9960 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9961 putPaddrLow(dmabuf
->phys
);
9962 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9963 putPaddrHigh(dmabuf
->phys
);
9965 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9966 /* The IOCTL status is embedded in the mailbox subheader. */
9967 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
9968 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9969 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9970 if (shdr_status
|| shdr_add_status
|| rc
) {
9974 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
9975 if (drq
->queue_id
== 0xFFFF) {
9979 drq
->type
= LPFC_DRQ
;
9980 drq
->subtype
= subtype
;
9981 drq
->host_index
= 0;
9984 /* link the header and data RQs onto the parent cq child list */
9985 list_add_tail(&hrq
->list
, &cq
->child_list
);
9986 list_add_tail(&drq
->list
, &cq
->child_list
);
9989 mempool_free(mbox
, phba
->mbox_mem_pool
);
9994 * lpfc_eq_destroy - Destroy an event Queue on the HBA
9995 * @eq: The queue structure associated with the queue to destroy.
9997 * This function destroys a queue, as detailed in @eq by sending an mailbox
9998 * command, specific to the type of queue, to the HBA.
10000 * The @eq struct is used to get the queue ID of the queue to destroy.
10002 * On success this function will return a zero. If the queue destroy mailbox
10003 * command fails this function will return ENXIO.
10006 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
10008 LPFC_MBOXQ_t
*mbox
;
10009 int rc
, length
, status
= 0;
10010 uint32_t shdr_status
, shdr_add_status
;
10011 union lpfc_sli4_cfg_shdr
*shdr
;
10015 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10018 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
10019 sizeof(struct lpfc_sli4_cfg_mhdr
));
10020 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10021 LPFC_MBOX_OPCODE_EQ_DESTROY
,
10022 length
, LPFC_SLI4_MBX_EMBED
);
10023 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
10025 mbox
->vport
= eq
->phba
->pport
;
10026 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10028 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
10029 /* The IOCTL status is embedded in the mailbox subheader. */
10030 shdr
= (union lpfc_sli4_cfg_shdr
*)
10031 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
10032 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10033 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10034 if (shdr_status
|| shdr_add_status
|| rc
) {
10035 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10036 "2505 EQ_DESTROY mailbox failed with "
10037 "status x%x add_status x%x, mbx status x%x\n",
10038 shdr_status
, shdr_add_status
, rc
);
10042 /* Remove eq from any list */
10043 list_del_init(&eq
->list
);
10044 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
10049 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
10050 * @cq: The queue structure associated with the queue to destroy.
10052 * This function destroys a queue, as detailed in @cq by sending an mailbox
10053 * command, specific to the type of queue, to the HBA.
10055 * The @cq struct is used to get the queue ID of the queue to destroy.
10057 * On success this function will return a zero. If the queue destroy mailbox
10058 * command fails this function will return ENXIO.
10061 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
10063 LPFC_MBOXQ_t
*mbox
;
10064 int rc
, length
, status
= 0;
10065 uint32_t shdr_status
, shdr_add_status
;
10066 union lpfc_sli4_cfg_shdr
*shdr
;
10070 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10073 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
10074 sizeof(struct lpfc_sli4_cfg_mhdr
));
10075 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10076 LPFC_MBOX_OPCODE_CQ_DESTROY
,
10077 length
, LPFC_SLI4_MBX_EMBED
);
10078 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
10080 mbox
->vport
= cq
->phba
->pport
;
10081 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10082 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
10083 /* The IOCTL status is embedded in the mailbox subheader. */
10084 shdr
= (union lpfc_sli4_cfg_shdr
*)
10085 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
10086 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10087 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10088 if (shdr_status
|| shdr_add_status
|| rc
) {
10089 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10090 "2506 CQ_DESTROY mailbox failed with "
10091 "status x%x add_status x%x, mbx status x%x\n",
10092 shdr_status
, shdr_add_status
, rc
);
10095 /* Remove cq from any list */
10096 list_del_init(&cq
->list
);
10097 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
10102 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
10103 * @qm: The queue structure associated with the queue to destroy.
10105 * This function destroys a queue, as detailed in @mq by sending an mailbox
10106 * command, specific to the type of queue, to the HBA.
10108 * The @mq struct is used to get the queue ID of the queue to destroy.
10110 * On success this function will return a zero. If the queue destroy mailbox
10111 * command fails this function will return ENXIO.
10114 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
10116 LPFC_MBOXQ_t
*mbox
;
10117 int rc
, length
, status
= 0;
10118 uint32_t shdr_status
, shdr_add_status
;
10119 union lpfc_sli4_cfg_shdr
*shdr
;
10123 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10126 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
10127 sizeof(struct lpfc_sli4_cfg_mhdr
));
10128 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10129 LPFC_MBOX_OPCODE_MQ_DESTROY
,
10130 length
, LPFC_SLI4_MBX_EMBED
);
10131 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
10133 mbox
->vport
= mq
->phba
->pport
;
10134 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10135 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
10136 /* The IOCTL status is embedded in the mailbox subheader. */
10137 shdr
= (union lpfc_sli4_cfg_shdr
*)
10138 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
10139 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10140 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10141 if (shdr_status
|| shdr_add_status
|| rc
) {
10142 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10143 "2507 MQ_DESTROY mailbox failed with "
10144 "status x%x add_status x%x, mbx status x%x\n",
10145 shdr_status
, shdr_add_status
, rc
);
10148 /* Remove mq from any list */
10149 list_del_init(&mq
->list
);
10150 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
10155 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
10156 * @wq: The queue structure associated with the queue to destroy.
10158 * This function destroys a queue, as detailed in @wq by sending an mailbox
10159 * command, specific to the type of queue, to the HBA.
10161 * The @wq struct is used to get the queue ID of the queue to destroy.
10163 * On success this function will return a zero. If the queue destroy mailbox
10164 * command fails this function will return ENXIO.
10167 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
10169 LPFC_MBOXQ_t
*mbox
;
10170 int rc
, length
, status
= 0;
10171 uint32_t shdr_status
, shdr_add_status
;
10172 union lpfc_sli4_cfg_shdr
*shdr
;
10176 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10179 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
10180 sizeof(struct lpfc_sli4_cfg_mhdr
));
10181 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10182 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
10183 length
, LPFC_SLI4_MBX_EMBED
);
10184 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
10186 mbox
->vport
= wq
->phba
->pport
;
10187 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10188 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
10189 shdr
= (union lpfc_sli4_cfg_shdr
*)
10190 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
10191 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10192 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10193 if (shdr_status
|| shdr_add_status
|| rc
) {
10194 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10195 "2508 WQ_DESTROY mailbox failed with "
10196 "status x%x add_status x%x, mbx status x%x\n",
10197 shdr_status
, shdr_add_status
, rc
);
10200 /* Remove wq from any list */
10201 list_del_init(&wq
->list
);
10202 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
10207 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
10208 * @rq: The queue structure associated with the queue to destroy.
10210 * This function destroys a queue, as detailed in @rq by sending an mailbox
10211 * command, specific to the type of queue, to the HBA.
10213 * The @rq struct is used to get the queue ID of the queue to destroy.
10215 * On success this function will return a zero. If the queue destroy mailbox
10216 * command fails this function will return ENXIO.
10219 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
10220 struct lpfc_queue
*drq
)
10222 LPFC_MBOXQ_t
*mbox
;
10223 int rc
, length
, status
= 0;
10224 uint32_t shdr_status
, shdr_add_status
;
10225 union lpfc_sli4_cfg_shdr
*shdr
;
10229 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10232 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
10233 sizeof(struct mbox_header
));
10234 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10235 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
10236 length
, LPFC_SLI4_MBX_EMBED
);
10237 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
10239 mbox
->vport
= hrq
->phba
->pport
;
10240 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10241 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
10242 /* The IOCTL status is embedded in the mailbox subheader. */
10243 shdr
= (union lpfc_sli4_cfg_shdr
*)
10244 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
10245 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10246 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10247 if (shdr_status
|| shdr_add_status
|| rc
) {
10248 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10249 "2509 RQ_DESTROY mailbox failed with "
10250 "status x%x add_status x%x, mbx status x%x\n",
10251 shdr_status
, shdr_add_status
, rc
);
10252 if (rc
!= MBX_TIMEOUT
)
10253 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
10256 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
10258 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
10259 shdr
= (union lpfc_sli4_cfg_shdr
*)
10260 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
10261 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10262 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10263 if (shdr_status
|| shdr_add_status
|| rc
) {
10264 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10265 "2510 RQ_DESTROY mailbox failed with "
10266 "status x%x add_status x%x, mbx status x%x\n",
10267 shdr_status
, shdr_add_status
, rc
);
10270 list_del_init(&hrq
->list
);
10271 list_del_init(&drq
->list
);
10272 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
10277 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
10278 * @phba: The virtual port for which this call being executed.
10279 * @pdma_phys_addr0: Physical address of the 1st SGL page.
10280 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
10281 * @xritag: the xritag that ties this io to the SGL pages.
10283 * This routine will post the sgl pages for the IO that has the xritag
10284 * that is in the iocbq structure. The xritag is assigned during iocbq
10285 * creation and persists for as long as the driver is loaded.
10286 * if the caller has fewer than 256 scatter gather segments to map then
10287 * pdma_phys_addr1 should be 0.
10288 * If the caller needs to map more than 256 scatter gather segment then
10289 * pdma_phys_addr1 should be a valid physical address.
10290 * physical address for SGLs must be 64 byte aligned.
10291 * If you are going to map 2 SGL's then the first one must have 256 entries
10292 * the second sgl can have between 1 and 256 entries.
10296 * -ENXIO, -ENOMEM - Failure
10299 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
10300 dma_addr_t pdma_phys_addr0
,
10301 dma_addr_t pdma_phys_addr1
,
10304 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
10305 LPFC_MBOXQ_t
*mbox
;
10307 uint32_t shdr_status
, shdr_add_status
;
10308 union lpfc_sli4_cfg_shdr
*shdr
;
10310 if (xritag
== NO_XRI
) {
10311 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10312 "0364 Invalid param:\n");
10316 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10320 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10321 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
10322 sizeof(struct lpfc_mbx_post_sgl_pages
) -
10323 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
10325 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
10326 &mbox
->u
.mqe
.un
.post_sgl_pages
;
10327 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
10328 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
10330 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
10331 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
10332 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
10333 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
10335 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
10336 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
10337 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
10338 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
10339 if (!phba
->sli4_hba
.intr_enable
)
10340 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10342 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
10343 /* The IOCTL status is embedded in the mailbox subheader. */
10344 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
10345 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10346 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10347 if (rc
!= MBX_TIMEOUT
)
10348 mempool_free(mbox
, phba
->mbox_mem_pool
);
10349 if (shdr_status
|| shdr_add_status
|| rc
) {
10350 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10351 "2511 POST_SGL mailbox failed with "
10352 "status x%x add_status x%x, mbx status x%x\n",
10353 shdr_status
, shdr_add_status
, rc
);
10359 * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
10360 * @phba: The virtual port for which this call being executed.
10362 * This routine will remove all of the sgl pages registered with the hba.
10366 * -ENXIO, -ENOMEM - Failure
10369 lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba
*phba
)
10371 LPFC_MBOXQ_t
*mbox
;
10373 uint32_t shdr_status
, shdr_add_status
;
10374 union lpfc_sli4_cfg_shdr
*shdr
;
10376 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10380 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10381 LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES
, 0,
10382 LPFC_SLI4_MBX_EMBED
);
10383 if (!phba
->sli4_hba
.intr_enable
)
10384 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10386 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
10387 /* The IOCTL status is embedded in the mailbox subheader. */
10388 shdr
= (union lpfc_sli4_cfg_shdr
*)
10389 &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
10390 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10391 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10392 if (rc
!= MBX_TIMEOUT
)
10393 mempool_free(mbox
, phba
->mbox_mem_pool
);
10394 if (shdr_status
|| shdr_add_status
|| rc
) {
10395 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10396 "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
10397 "status x%x add_status x%x, mbx status x%x\n",
10398 shdr_status
, shdr_add_status
, rc
);
10405 * lpfc_sli4_next_xritag - Get an xritag for the io
10406 * @phba: Pointer to HBA context object.
10408 * This function gets an xritag for the iocb. If there is no unused xritag
10409 * it will return 0xffff.
10410 * The function returns the allocated xritag if successful, else returns zero.
10411 * Zero is not a valid xritag.
10412 * The caller is not required to hold any lock.
10415 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
10419 spin_lock_irq(&phba
->hbalock
);
10420 xritag
= phba
->sli4_hba
.next_xri
;
10421 if ((xritag
!= (uint16_t) -1) && xritag
<
10422 (phba
->sli4_hba
.max_cfg_param
.max_xri
10423 + phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
10424 phba
->sli4_hba
.next_xri
++;
10425 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
10426 spin_unlock_irq(&phba
->hbalock
);
10429 spin_unlock_irq(&phba
->hbalock
);
10431 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10432 "2004 Failed to allocate XRI.last XRITAG is %d"
10433 " Max XRI is %d, Used XRI is %d\n",
10434 phba
->sli4_hba
.next_xri
,
10435 phba
->sli4_hba
.max_cfg_param
.max_xri
,
10436 phba
->sli4_hba
.max_cfg_param
.xri_used
);
10441 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
10442 * @phba: pointer to lpfc hba data structure.
10444 * This routine is invoked to post a block of driver's sgl pages to the
10445 * HBA using non-embedded mailbox command. No Lock is held. This routine
10446 * is only called when the driver is loading and after all IO has been
10450 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
)
10452 struct lpfc_sglq
*sglq_entry
;
10453 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
10454 struct sgl_page_pairs
*sgl_pg_pairs
;
10456 LPFC_MBOXQ_t
*mbox
;
10457 uint32_t reqlen
, alloclen
, pg_pairs
;
10459 uint16_t xritag_start
= 0;
10460 int els_xri_cnt
, rc
= 0;
10461 uint32_t shdr_status
, shdr_add_status
;
10462 union lpfc_sli4_cfg_shdr
*shdr
;
10464 /* The number of sgls to be posted */
10465 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
10467 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
10468 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
10469 if (reqlen
> PAGE_SIZE
) {
10470 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10471 "2559 Block sgl registration required DMA "
10472 "size (%d) great than a page\n", reqlen
);
10475 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10477 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10478 "2560 Failed to allocate mbox cmd memory\n");
10482 /* Allocate DMA memory and set up the non-embedded mailbox command */
10483 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10484 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
10485 LPFC_SLI4_MBX_NEMBED
);
10487 if (alloclen
< reqlen
) {
10488 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10489 "0285 Allocated DMA memory size (%d) is "
10490 "less than the requested DMA memory "
10491 "size (%d)\n", alloclen
, reqlen
);
10492 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10496 /* Get the first SGE entry from the non-embedded DMA memory */
10497 if (unlikely(!mbox
->sge_array
)) {
10498 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
10499 "2525 Failed to get the non-embedded SGE "
10500 "virtual address\n");
10501 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10504 viraddr
= mbox
->sge_array
->addr
[0];
10506 /* Set up the SGL pages in the non-embedded DMA pages */
10507 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
10508 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
10510 for (pg_pairs
= 0; pg_pairs
< els_xri_cnt
; pg_pairs
++) {
10511 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[pg_pairs
];
10512 /* Set up the sge entry */
10513 sgl_pg_pairs
->sgl_pg0_addr_lo
=
10514 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
10515 sgl_pg_pairs
->sgl_pg0_addr_hi
=
10516 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
10517 sgl_pg_pairs
->sgl_pg1_addr_lo
=
10518 cpu_to_le32(putPaddrLow(0));
10519 sgl_pg_pairs
->sgl_pg1_addr_hi
=
10520 cpu_to_le32(putPaddrHigh(0));
10521 /* Keep the first xritag on the list */
10523 xritag_start
= sglq_entry
->sli4_xritag
;
10526 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
10527 pg_pairs
= (pg_pairs
> 0) ? (pg_pairs
- 1) : pg_pairs
;
10528 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
10529 /* Perform endian conversion if necessary */
10530 sgl
->word0
= cpu_to_le32(sgl
->word0
);
10532 if (!phba
->sli4_hba
.intr_enable
)
10533 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10535 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
10536 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
10538 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
10539 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10540 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10541 if (rc
!= MBX_TIMEOUT
)
10542 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10543 if (shdr_status
|| shdr_add_status
|| rc
) {
10544 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10545 "2513 POST_SGL_BLOCK mailbox command failed "
10546 "status x%x add_status x%x mbx status x%x\n",
10547 shdr_status
, shdr_add_status
, rc
);
10554 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
10555 * @phba: pointer to lpfc hba data structure.
10556 * @sblist: pointer to scsi buffer list.
10557 * @count: number of scsi buffers on the list.
10559 * This routine is invoked to post a block of @count scsi sgl pages from a
10560 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
10565 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
, struct list_head
*sblist
,
10568 struct lpfc_scsi_buf
*psb
;
10569 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
10570 struct sgl_page_pairs
*sgl_pg_pairs
;
10572 LPFC_MBOXQ_t
*mbox
;
10573 uint32_t reqlen
, alloclen
, pg_pairs
;
10575 uint16_t xritag_start
= 0;
10577 uint32_t shdr_status
, shdr_add_status
;
10578 dma_addr_t pdma_phys_bpl1
;
10579 union lpfc_sli4_cfg_shdr
*shdr
;
10581 /* Calculate the requested length of the dma memory */
10582 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
10583 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
10584 if (reqlen
> PAGE_SIZE
) {
10585 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10586 "0217 Block sgl registration required DMA "
10587 "size (%d) great than a page\n", reqlen
);
10590 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10592 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10593 "0283 Failed to allocate mbox cmd memory\n");
10597 /* Allocate DMA memory and set up the non-embedded mailbox command */
10598 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10599 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
10600 LPFC_SLI4_MBX_NEMBED
);
10602 if (alloclen
< reqlen
) {
10603 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10604 "2561 Allocated DMA memory size (%d) is "
10605 "less than the requested DMA memory "
10606 "size (%d)\n", alloclen
, reqlen
);
10607 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10611 /* Get the first SGE entry from the non-embedded DMA memory */
10612 if (unlikely(!mbox
->sge_array
)) {
10613 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
10614 "2565 Failed to get the non-embedded SGE "
10615 "virtual address\n");
10616 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10619 viraddr
= mbox
->sge_array
->addr
[0];
10621 /* Set up the SGL pages in the non-embedded DMA pages */
10622 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
10623 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
10626 list_for_each_entry(psb
, sblist
, list
) {
10627 /* Set up the sge entry */
10628 sgl_pg_pairs
->sgl_pg0_addr_lo
=
10629 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
10630 sgl_pg_pairs
->sgl_pg0_addr_hi
=
10631 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
10632 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
10633 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
10635 pdma_phys_bpl1
= 0;
10636 sgl_pg_pairs
->sgl_pg1_addr_lo
=
10637 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
10638 sgl_pg_pairs
->sgl_pg1_addr_hi
=
10639 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
10640 /* Keep the first xritag on the list */
10642 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
10646 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
10647 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
10648 /* Perform endian conversion if necessary */
10649 sgl
->word0
= cpu_to_le32(sgl
->word0
);
10651 if (!phba
->sli4_hba
.intr_enable
)
10652 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10654 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
10655 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
10657 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
10658 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10659 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10660 if (rc
!= MBX_TIMEOUT
)
10661 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10662 if (shdr_status
|| shdr_add_status
|| rc
) {
10663 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10664 "2564 POST_SGL_BLOCK mailbox command failed "
10665 "status x%x add_status x%x mbx status x%x\n",
10666 shdr_status
, shdr_add_status
, rc
);
10673 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
10674 * @phba: pointer to lpfc_hba struct that the frame was received on
10675 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10677 * This function checks the fields in the @fc_hdr to see if the FC frame is a
10678 * valid type of frame that the LPFC driver will handle. This function will
10679 * return a zero if the frame is a valid frame or a non zero value when the
10680 * frame does not pass the check.
10683 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
10685 char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
10686 char *type_names
[] = FC_TYPE_NAMES_INIT
;
10687 struct fc_vft_header
*fc_vft_hdr
;
10689 switch (fc_hdr
->fh_r_ctl
) {
10690 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
10691 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
10692 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
10693 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
10694 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
10695 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
10696 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
10697 case FC_RCTL_DD_CMD_STATUS
: /* command status */
10698 case FC_RCTL_ELS_REQ
: /* extended link services request */
10699 case FC_RCTL_ELS_REP
: /* extended link services reply */
10700 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
10701 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
10702 case FC_RCTL_BA_NOP
: /* basic link service NOP */
10703 case FC_RCTL_BA_ABTS
: /* basic link service abort */
10704 case FC_RCTL_BA_RMC
: /* remove connection */
10705 case FC_RCTL_BA_ACC
: /* basic accept */
10706 case FC_RCTL_BA_RJT
: /* basic reject */
10707 case FC_RCTL_BA_PRMT
:
10708 case FC_RCTL_ACK_1
: /* acknowledge_1 */
10709 case FC_RCTL_ACK_0
: /* acknowledge_0 */
10710 case FC_RCTL_P_RJT
: /* port reject */
10711 case FC_RCTL_F_RJT
: /* fabric reject */
10712 case FC_RCTL_P_BSY
: /* port busy */
10713 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
10714 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
10715 case FC_RCTL_LCR
: /* link credit reset */
10716 case FC_RCTL_END
: /* end */
10718 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
10719 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
10720 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
10721 return lpfc_fc_frame_check(phba
, fc_hdr
);
10725 switch (fc_hdr
->fh_type
) {
10736 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
10737 "2538 Received frame rctl:%s type:%s\n",
10738 rctl_names
[fc_hdr
->fh_r_ctl
],
10739 type_names
[fc_hdr
->fh_type
]);
10742 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
10743 "2539 Dropped frame rctl:%s type:%s\n",
10744 rctl_names
[fc_hdr
->fh_r_ctl
],
10745 type_names
[fc_hdr
->fh_type
]);
10750 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
10751 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10753 * This function processes the FC header to retrieve the VFI from the VF
10754 * header, if one exists. This function will return the VFI if one exists
10755 * or 0 if no VSAN Header exists.
10758 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
10760 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
10762 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
10764 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
10768 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
10769 * @phba: Pointer to the HBA structure to search for the vport on
10770 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10771 * @fcfi: The FC Fabric ID that the frame came from
10773 * This function searches the @phba for a vport that matches the content of the
10774 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
10775 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
10776 * returns the matching vport pointer or NULL if unable to match frame to a
10779 static struct lpfc_vport
*
10780 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
10783 struct lpfc_vport
**vports
;
10784 struct lpfc_vport
*vport
= NULL
;
10786 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
10787 fc_hdr
->fh_d_id
[1] << 8 |
10788 fc_hdr
->fh_d_id
[2]);
10790 vports
= lpfc_create_vport_work_array(phba
);
10791 if (vports
!= NULL
)
10792 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
10793 if (phba
->fcf
.fcfi
== fcfi
&&
10794 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
10795 vports
[i
]->fc_myDID
== did
) {
10800 lpfc_destroy_vport_work_array(phba
, vports
);
10805 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
10806 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
10808 * This function searches through the existing incomplete sequences that have
10809 * been sent to this @vport. If the frame matches one of the incomplete
10810 * sequences then the dbuf in the @dmabuf is added to the list of frames that
10811 * make up that sequence. If no sequence is found that matches this frame then
10812 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
10813 * This function returns a pointer to the first dmabuf in the sequence list that
10814 * the frame was linked to.
10816 static struct hbq_dmabuf
*
10817 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
10819 struct fc_frame_header
*new_hdr
;
10820 struct fc_frame_header
*temp_hdr
;
10821 struct lpfc_dmabuf
*d_buf
;
10822 struct lpfc_dmabuf
*h_buf
;
10823 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
10824 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
10826 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
10827 /* Use the hdr_buf to find the sequence that this frame belongs to */
10828 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
10829 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
10830 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
10831 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
10832 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
10834 /* found a pending sequence that matches this frame */
10835 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
10840 * This indicates first frame received for this sequence.
10841 * Queue the buffer on the vport's rcv_buffer_list.
10843 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
10846 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
10847 if (new_hdr
->fh_seq_cnt
< temp_hdr
->fh_seq_cnt
) {
10848 list_add(&seq_dmabuf
->dbuf
.list
, &dmabuf
->dbuf
.list
);
10851 /* find the correct place in the sequence to insert this frame */
10852 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
10853 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
10854 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
10856 * If the frame's sequence count is greater than the frame on
10857 * the list then insert the frame right after this frame
10859 if (new_hdr
->fh_seq_cnt
> temp_hdr
->fh_seq_cnt
) {
10860 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
10868 * lpfc_seq_complete - Indicates if a sequence is complete
10869 * @dmabuf: pointer to a dmabuf that describes the FC sequence
10871 * This function checks the sequence, starting with the frame described by
10872 * @dmabuf, to see if all the frames associated with this sequence are present.
10873 * the frames associated with this sequence are linked to the @dmabuf using the
10874 * dbuf list. This function looks for two major things. 1) That the first frame
10875 * has a sequence count of zero. 2) There is a frame with last frame of sequence
10876 * set. 3) That there are no holes in the sequence count. The function will
10877 * return 1 when the sequence is complete, otherwise it will return 0.
10880 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
10882 struct fc_frame_header
*hdr
;
10883 struct lpfc_dmabuf
*d_buf
;
10884 struct hbq_dmabuf
*seq_dmabuf
;
10888 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
10889 /* make sure first fame of sequence has a sequence count of zero */
10890 if (hdr
->fh_seq_cnt
!= seq_count
)
10892 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
10893 hdr
->fh_f_ctl
[1] << 8 |
10895 /* If last frame of sequence we can return success. */
10896 if (fctl
& FC_FC_END_SEQ
)
10898 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
10899 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
10900 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
10901 /* If there is a hole in the sequence count then fail. */
10902 if (++seq_count
!= hdr
->fh_seq_cnt
)
10904 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
10905 hdr
->fh_f_ctl
[1] << 8 |
10907 /* If last frame of sequence we can return success. */
10908 if (fctl
& FC_FC_END_SEQ
)
10915 * lpfc_prep_seq - Prep sequence for ULP processing
10916 * @vport: Pointer to the vport on which this sequence was received
10917 * @dmabuf: pointer to a dmabuf that describes the FC sequence
10919 * This function takes a sequence, described by a list of frames, and creates
10920 * a list of iocbq structures to describe the sequence. This iocbq list will be
10921 * used to issue to the generic unsolicited sequence handler. This routine
10922 * returns a pointer to the first iocbq in the list. If the function is unable
10923 * to allocate an iocbq then it throw out the received frames that were not
10924 * able to be described and return a pointer to the first iocbq. If unable to
10925 * allocate any iocbqs (including the first) this function will return NULL.
10927 static struct lpfc_iocbq
*
10928 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
10930 struct lpfc_dmabuf
*d_buf
, *n_buf
;
10931 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
10932 struct fc_frame_header
*fc_hdr
;
10935 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
10936 /* remove from receive buffer list */
10937 list_del_init(&seq_dmabuf
->hbuf
.list
);
10938 /* get the Remote Port's SID */
10939 sid
= (fc_hdr
->fh_s_id
[0] << 16 |
10940 fc_hdr
->fh_s_id
[1] << 8 |
10941 fc_hdr
->fh_s_id
[2]);
10942 /* Get an iocbq struct to fill in. */
10943 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
10945 /* Initialize the first IOCB. */
10946 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
10947 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
10948 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
10949 first_iocbq
->iocb
.ulpContext
= be16_to_cpu(fc_hdr
->fh_ox_id
);
10950 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
10951 vport
->vpi
+ vport
->phba
->vpi_base
;
10952 /* put the first buffer into the first IOCBq */
10953 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
10954 first_iocbq
->context3
= NULL
;
10955 first_iocbq
->iocb
.ulpBdeCount
= 1;
10956 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
10957 LPFC_DATA_BUF_SIZE
;
10958 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
10959 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
10960 bf_get(lpfc_rcqe_length
, &seq_dmabuf
->rcqe
);
10962 iocbq
= first_iocbq
;
10964 * Each IOCBq can have two Buffers assigned, so go through the list
10965 * of buffers for this sequence and save two buffers in each IOCBq
10967 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
10969 lpfc_in_buf_free(vport
->phba
, d_buf
);
10972 if (!iocbq
->context3
) {
10973 iocbq
->context3
= d_buf
;
10974 iocbq
->iocb
.ulpBdeCount
++;
10975 iocbq
->iocb
.unsli3
.rcvsli3
.bde2
.tus
.f
.bdeSize
=
10976 LPFC_DATA_BUF_SIZE
;
10977 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
10978 bf_get(lpfc_rcqe_length
, &seq_dmabuf
->rcqe
);
10980 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
10983 first_iocbq
->iocb
.ulpStatus
=
10984 IOSTAT_FCP_RSP_ERROR
;
10985 first_iocbq
->iocb
.un
.ulpWord
[4] =
10986 IOERR_NO_RESOURCES
;
10988 lpfc_in_buf_free(vport
->phba
, d_buf
);
10991 iocbq
->context2
= d_buf
;
10992 iocbq
->context3
= NULL
;
10993 iocbq
->iocb
.ulpBdeCount
= 1;
10994 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
10995 LPFC_DATA_BUF_SIZE
;
10996 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
10997 bf_get(lpfc_rcqe_length
, &seq_dmabuf
->rcqe
);
10998 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
10999 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
11002 return first_iocbq
;
11006 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
11007 * @phba: Pointer to HBA context object.
11009 * This function is called with no lock held. This function processes all
11010 * the received buffers and gives it to upper layers when a received buffer
11011 * indicates that it is the final frame in the sequence. The interrupt
11012 * service routine processes received buffers at interrupt contexts and adds
11013 * received dma buffers to the rb_pend_list queue and signals the worker thread.
11014 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
11015 * appropriate receive function when the final frame in a sequence is received.
11018 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
)
11021 struct hbq_dmabuf
*dmabuf
, *seq_dmabuf
;
11022 struct fc_frame_header
*fc_hdr
;
11023 struct lpfc_vport
*vport
;
11025 struct lpfc_iocbq
*iocbq
;
11027 /* Clear hba flag and get all received buffers into the cmplq */
11028 spin_lock_irq(&phba
->hbalock
);
11029 phba
->hba_flag
&= ~HBA_RECEIVE_BUFFER
;
11030 list_splice_init(&phba
->rb_pend_list
, &cmplq
);
11031 spin_unlock_irq(&phba
->hbalock
);
11033 /* Process each received buffer */
11034 while ((dmabuf
= lpfc_sli_hbqbuf_get(&cmplq
)) != NULL
) {
11035 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11036 /* check to see if this a valid type of frame */
11037 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
11038 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11041 fcfi
= bf_get(lpfc_rcqe_fcf_id
, &dmabuf
->rcqe
);
11042 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
11044 /* throw out the frame */
11045 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11048 /* Link this frame */
11049 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
11051 /* unable to add frame to vport - throw it out */
11052 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11055 /* If not last frame in sequence continue processing frames. */
11056 if (!lpfc_seq_complete(seq_dmabuf
)) {
11058 * When saving off frames post a new one and mark this
11059 * frame to be freed when it is finished.
11061 lpfc_sli_hbqbuf_fill_hbqs(phba
, LPFC_ELS_HBQ
, 1);
11065 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11066 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
11067 if (!lpfc_complete_unsol_iocb(phba
,
11068 &phba
->sli
.ring
[LPFC_ELS_RING
],
11069 iocbq
, fc_hdr
->fh_r_ctl
,
11071 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11072 "2540 Ring %d handler: unexpected Rctl "
11073 "x%x Type x%x received\n",
11075 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
11081 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
11082 * @phba: pointer to lpfc hba data structure.
11084 * This routine is invoked to post rpi header templates to the
11085 * HBA consistent with the SLI-4 interface spec. This routine
11086 * posts a PAGE_SIZE memory region to the port to hold up to
11087 * PAGE_SIZE modulo 64 rpi context headers.
11089 * This routine does not require any locks. It's usage is expected
11090 * to be driver load or reset recovery when the driver is
11095 * EIO - The mailbox failed to complete successfully.
11096 * When this error occurs, the driver is not guaranteed
11097 * to have any rpi regions posted to the device and
11098 * must either attempt to repost the regions or take a
11102 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
11104 struct lpfc_rpi_hdr
*rpi_page
;
11107 /* Post all rpi memory regions to the port. */
11108 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
11109 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
11110 if (rc
!= MBX_SUCCESS
) {
11111 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11112 "2008 Error %d posting all rpi "
11123 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
11124 * @phba: pointer to lpfc hba data structure.
11125 * @rpi_page: pointer to the rpi memory region.
11127 * This routine is invoked to post a single rpi header to the
11128 * HBA consistent with the SLI-4 interface spec. This memory region
11129 * maps up to 64 rpi context regions.
11133 * ENOMEM - No available memory
11134 * EIO - The mailbox failed to complete successfully.
11137 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
11139 LPFC_MBOXQ_t
*mboxq
;
11140 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
11143 uint32_t shdr_status
, shdr_add_status
;
11144 union lpfc_sli4_cfg_shdr
*shdr
;
11146 /* The port is notified of the header region via a mailbox command. */
11147 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11149 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11150 "2001 Unable to allocate memory for issuing "
11151 "SLI_CONFIG_SPECIAL mailbox command\n");
11155 /* Post all rpi memory regions to the port. */
11156 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
11157 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
11158 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11159 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
11160 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
11161 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
11162 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
11163 hdr_tmpl
, rpi_page
->page_count
);
11164 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
11165 rpi_page
->start_rpi
);
11166 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
11167 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
11168 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
11169 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
11170 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11171 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11172 if (rc
!= MBX_TIMEOUT
)
11173 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11174 if (shdr_status
|| shdr_add_status
|| rc
) {
11175 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11176 "2514 POST_RPI_HDR mailbox failed with "
11177 "status x%x add_status x%x, mbx status x%x\n",
11178 shdr_status
, shdr_add_status
, rc
);
11185 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
11186 * @phba: pointer to lpfc hba data structure.
11188 * This routine is invoked to post rpi header templates to the
11189 * HBA consistent with the SLI-4 interface spec. This routine
11190 * posts a PAGE_SIZE memory region to the port to hold up to
11191 * PAGE_SIZE modulo 64 rpi context headers.
11194 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
11195 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
11198 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
11201 uint16_t max_rpi
, rpi_base
, rpi_limit
;
11202 uint16_t rpi_remaining
;
11203 struct lpfc_rpi_hdr
*rpi_hdr
;
11205 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
11206 rpi_base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
11207 rpi_limit
= phba
->sli4_hba
.next_rpi
;
11210 * The valid rpi range is not guaranteed to be zero-based. Start
11211 * the search at the rpi_base as reported by the port.
11213 spin_lock_irq(&phba
->hbalock
);
11214 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, rpi_base
);
11215 if (rpi
>= rpi_limit
|| rpi
< rpi_base
)
11216 rpi
= LPFC_RPI_ALLOC_ERROR
;
11218 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
11219 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
11220 phba
->sli4_hba
.rpi_count
++;
11224 * Don't try to allocate more rpi header regions if the device limit
11225 * on available rpis max has been exhausted.
11227 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
11228 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
11229 spin_unlock_irq(&phba
->hbalock
);
11234 * If the driver is running low on rpi resources, allocate another
11235 * page now. Note that the next_rpi value is used because
11236 * it represents how many are actually in use whereas max_rpi notes
11237 * how many are supported max by the device.
11239 rpi_remaining
= phba
->sli4_hba
.next_rpi
- rpi_base
-
11240 phba
->sli4_hba
.rpi_count
;
11241 spin_unlock_irq(&phba
->hbalock
);
11242 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
11243 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
11245 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11246 "2002 Error Could not grow rpi "
11249 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
11257 * lpfc_sli4_free_rpi - Release an rpi for reuse.
11258 * @phba: pointer to lpfc hba data structure.
11260 * This routine is invoked to release an rpi to the pool of
11261 * available rpis maintained by the driver.
11264 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
11266 spin_lock_irq(&phba
->hbalock
);
11267 clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
11268 phba
->sli4_hba
.rpi_count
--;
11269 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
11270 spin_unlock_irq(&phba
->hbalock
);
11274 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
11275 * @phba: pointer to lpfc hba data structure.
11277 * This routine is invoked to remove the memory region that
11278 * provided rpi via a bitmask.
11281 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
11283 kfree(phba
->sli4_hba
.rpi_bmask
);
11287 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
11288 * @phba: pointer to lpfc hba data structure.
11290 * This routine is invoked to remove the memory region that
11291 * provided rpi via a bitmask.
11294 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
)
11296 LPFC_MBOXQ_t
*mboxq
;
11297 struct lpfc_hba
*phba
= ndlp
->phba
;
11300 /* The port is notified of the header region via a mailbox command. */
11301 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11305 /* Post all rpi memory regions to the port. */
11306 lpfc_resume_rpi(mboxq
, ndlp
);
11307 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
11308 if (rc
== MBX_NOT_FINISHED
) {
11309 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11310 "2010 Resume RPI Mailbox failed "
11311 "status %d, mbxStatus x%x\n", rc
,
11312 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
11313 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11320 * lpfc_sli4_init_vpi - Initialize a vpi with the port
11321 * @phba: pointer to lpfc hba data structure.
11322 * @vpi: vpi value to activate with the port.
11324 * This routine is invoked to activate a vpi with the
11325 * port when the host intends to use vports with a
11330 * -Evalue otherwise
11333 lpfc_sli4_init_vpi(struct lpfc_hba
*phba
, uint16_t vpi
)
11335 LPFC_MBOXQ_t
*mboxq
;
11341 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11344 lpfc_init_vpi(phba
, mboxq
, vpi
);
11345 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_INIT_VPI
);
11346 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
11347 if (rc
!= MBX_TIMEOUT
)
11348 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11349 if (rc
!= MBX_SUCCESS
) {
11350 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11351 "2022 INIT VPI Mailbox failed "
11352 "status %d, mbxStatus x%x\n", rc
,
11353 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
11360 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
11361 * @phba: pointer to lpfc hba data structure.
11362 * @mboxq: Pointer to mailbox object.
11364 * This routine is invoked to manually add a single FCF record. The caller
11365 * must pass a completely initialized FCF_Record. This routine takes
11366 * care of the nonembedded mailbox operations.
11369 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
11372 union lpfc_sli4_cfg_shdr
*shdr
;
11373 uint32_t shdr_status
, shdr_add_status
;
11375 virt_addr
= mboxq
->sge_array
->addr
[0];
11376 /* The IOCTL status is embedded in the mailbox subheader. */
11377 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
11378 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11379 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11381 if ((shdr_status
|| shdr_add_status
) &&
11382 (shdr_status
!= STATUS_FCF_IN_USE
))
11383 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11384 "2558 ADD_FCF_RECORD mailbox failed with "
11385 "status x%x add_status x%x\n",
11386 shdr_status
, shdr_add_status
);
11388 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11392 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
11393 * @phba: pointer to lpfc hba data structure.
11394 * @fcf_record: pointer to the initialized fcf record to add.
11396 * This routine is invoked to manually add a single FCF record. The caller
11397 * must pass a completely initialized FCF_Record. This routine takes
11398 * care of the nonembedded mailbox operations.
11401 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
11404 LPFC_MBOXQ_t
*mboxq
;
11407 dma_addr_t phys_addr
;
11408 struct lpfc_mbx_sge sge
;
11409 uint32_t alloc_len
, req_len
;
11412 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11414 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11415 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
11419 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
11422 /* Allocate DMA memory and set up the non-embedded mailbox command */
11423 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11424 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
11425 req_len
, LPFC_SLI4_MBX_NEMBED
);
11426 if (alloc_len
< req_len
) {
11427 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11428 "2523 Allocated DMA memory size (x%x) is "
11429 "less than the requested DMA memory "
11430 "size (x%x)\n", alloc_len
, req_len
);
11431 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11436 * Get the first SGE entry from the non-embedded DMA memory. This
11437 * routine only uses a single SGE.
11439 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
11440 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
11441 if (unlikely(!mboxq
->sge_array
)) {
11442 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11443 "2526 Failed to get the non-embedded SGE "
11444 "virtual address\n");
11445 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11448 virt_addr
= mboxq
->sge_array
->addr
[0];
11450 * Configure the FCF record for FCFI 0. This is the driver's
11451 * hardcoded default and gets used in nonFIP mode.
11453 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
11454 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
11455 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
11458 * Copy the fcf_index and the FCF Record Data. The data starts after
11459 * the FCoE header plus word10. The data copy needs to be endian
11462 bytep
+= sizeof(uint32_t);
11463 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
11464 mboxq
->vport
= phba
->pport
;
11465 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
11466 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
11467 if (rc
== MBX_NOT_FINISHED
) {
11468 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11469 "2515 ADD_FCF_RECORD mailbox failed with "
11470 "status 0x%x\n", rc
);
11471 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11480 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
11481 * @phba: pointer to lpfc hba data structure.
11482 * @fcf_record: pointer to the fcf record to write the default data.
11483 * @fcf_index: FCF table entry index.
11485 * This routine is invoked to build the driver's default FCF record. The
11486 * values used are hardcoded. This routine handles memory initialization.
11490 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
11491 struct fcf_record
*fcf_record
,
11492 uint16_t fcf_index
)
11494 memset(fcf_record
, 0, sizeof(struct fcf_record
));
11495 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
11496 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
11497 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
11498 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
11499 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
11500 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
11501 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
11502 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
11503 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
11504 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
11505 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
11506 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
11507 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
11508 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
11509 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
11510 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
11511 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
11512 /* Set the VLAN bit map */
11513 if (phba
->valid_vlan
) {
11514 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
11515 = 1 << (phba
->vlan_id
% 8);
11520 * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
11521 * @phba: pointer to lpfc hba data structure.
11522 * @fcf_index: FCF table entry offset.
11524 * This routine is invoked to read up to @fcf_num of FCF record from the
11525 * device starting with the given @fcf_index.
11528 lpfc_sli4_read_fcf_record(struct lpfc_hba
*phba
, uint16_t fcf_index
)
11531 LPFC_MBOXQ_t
*mboxq
;
11533 dma_addr_t phys_addr
;
11535 struct lpfc_mbx_sge sge
;
11536 uint32_t alloc_len
, req_len
;
11537 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
11539 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
11540 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11542 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11543 "2000 Failed to allocate mbox for "
11548 req_len
= sizeof(struct fcf_record
) +
11549 sizeof(union lpfc_sli4_cfg_shdr
) + 2 * sizeof(uint32_t);
11551 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
11552 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11553 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE
, req_len
,
11554 LPFC_SLI4_MBX_NEMBED
);
11556 if (alloc_len
< req_len
) {
11557 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11558 "0291 Allocated DMA memory size (x%x) is "
11559 "less than the requested DMA memory "
11560 "size (x%x)\n", alloc_len
, req_len
);
11561 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11565 /* Get the first SGE entry from the non-embedded DMA memory. This
11566 * routine only uses a single SGE.
11568 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
11569 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
11570 if (unlikely(!mboxq
->sge_array
)) {
11571 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11572 "2527 Failed to get the non-embedded SGE "
11573 "virtual address\n");
11574 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11577 virt_addr
= mboxq
->sge_array
->addr
[0];
11578 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
11580 /* Set up command fields */
11581 bf_set(lpfc_mbx_read_fcf_tbl_indx
, &read_fcf
->u
.request
, fcf_index
);
11582 /* Perform necessary endian conversion */
11583 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
11584 lpfc_sli_pcimem_bcopy(bytep
, bytep
, sizeof(uint32_t));
11585 mboxq
->vport
= phba
->pport
;
11586 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_record
;
11587 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
11588 if (rc
== MBX_NOT_FINISHED
) {
11589 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
11592 spin_lock_irq(&phba
->hbalock
);
11593 phba
->hba_flag
|= FCF_DISC_INPROGRESS
;
11594 spin_unlock_irq(&phba
->hbalock
);
11601 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
11602 * @phba: pointer to lpfc hba data structure.
11604 * This function read region 23 and parse TLV for port status to
11605 * decide if the user disaled the port. If the TLV indicates the
11606 * port is disabled, the hba_flag is set accordingly.
11609 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
11611 LPFC_MBOXQ_t
*pmb
= NULL
;
11613 uint8_t *rgn23_data
= NULL
;
11614 uint32_t offset
= 0, data_size
, sub_tlv_len
, tlv_offset
;
11617 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11619 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11620 "2600 lpfc_sli_read_serdes_param failed to"
11621 " allocate mailbox memory\n");
11626 /* Get adapter Region 23 data */
11627 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
11632 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
11633 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
11635 if (rc
!= MBX_SUCCESS
) {
11636 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11637 "2601 lpfc_sli_read_link_ste failed to"
11638 " read config region 23 rc 0x%x Status 0x%x\n",
11639 rc
, mb
->mbxStatus
);
11640 mb
->un
.varDmp
.word_cnt
= 0;
11643 * dump mem may return a zero when finished or we got a
11644 * mailbox error, either way we are done.
11646 if (mb
->un
.varDmp
.word_cnt
== 0)
11648 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
11649 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
11651 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
11652 rgn23_data
+ offset
,
11653 mb
->un
.varDmp
.word_cnt
);
11654 offset
+= mb
->un
.varDmp
.word_cnt
;
11655 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
11657 data_size
= offset
;
11663 /* Check the region signature first */
11664 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
11665 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11666 "2619 Config region 23 has bad signature\n");
11671 /* Check the data structure version */
11672 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
11673 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11674 "2620 Config region 23 has bad version\n");
11679 /* Parse TLV entries in the region */
11680 while (offset
< data_size
) {
11681 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
11684 * If the TLV is not driver specific TLV or driver id is
11685 * not linux driver id, skip the record.
11687 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
11688 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
11689 (rgn23_data
[offset
+ 3] != 0)) {
11690 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
11694 /* Driver found a driver specific TLV in the config region */
11695 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
11700 * Search for configured port state sub-TLV.
11702 while ((offset
< data_size
) &&
11703 (tlv_offset
< sub_tlv_len
)) {
11704 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
11709 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
11710 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
11711 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
11715 /* This HBA contains PORT_STE configured */
11716 if (!rgn23_data
[offset
+ 2])
11717 phba
->hba_flag
|= LINK_DISABLED
;
11724 mempool_free(pmb
, phba
->mbox_mem_pool
);