1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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"
48 * Define macro to log: Mailbox command x%x cannot issue Data
49 * This allows multiple uses of lpfc_msgBlk0311
50 * w/o perturbing log msg utility.
52 #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
53 lpfc_printf_log(phba, \
56 "(%d):0311 Mailbox command x%x cannot " \
57 "issue Data: x%x x%x x%x\n", \
58 pmbox->vport ? pmbox->vport->vpi : 0, \
59 pmbox->mb.mbxCommand, \
60 phba->pport->port_state, \
65 /* There are only four IOCB completion types. */
66 typedef enum _lpfc_iocb_type {
74 /* Provide function prototypes local to this module. */
75 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
77 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
78 uint8_t *, uint32_t *);
81 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
87 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
88 * @q: The Work Queue to operate on.
89 * @wqe: The work Queue Entry to put on the Work queue.
91 * This routine will copy the contents of @wqe to the next available entry on
92 * the @q. This function will then ring the Work Queue Doorbell to signal the
93 * HBA to start processing the Work Queue Entry. This function returns 0 if
94 * successful. If no entries are available on @q then this function will return
96 * The caller is expected to hold the hbalock when calling this routine.
99 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
101 union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
102 struct lpfc_register doorbell;
105 /* If the host has not yet processed the next entry then we are done */
106 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
108 /* set consumption flag every once in a while */
109 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
110 bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
112 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
114 /* Update the host index before invoking device */
115 host_index = q->host_index;
116 q->host_index = ((q->host_index + 1) % q->entry_count);
120 bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
121 bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
122 bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
123 writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
124 readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
130 * lpfc_sli4_wq_release - Updates internal hba index for WQ
131 * @q: The Work Queue to operate on.
132 * @index: The index to advance the hba index to.
134 * This routine will update the HBA index of a queue to reflect consumption of
135 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
136 * an entry the host calls this function to update the queue's internal
137 * pointers. This routine returns the number of entries that were consumed by
141 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
143 uint32_t released = 0;
145 if (q->hba_index == index)
148 q->hba_index = ((q->hba_index + 1) % q->entry_count);
150 } while (q->hba_index != index);
155 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
156 * @q: The Mailbox Queue to operate on.
157 * @wqe: The Mailbox Queue Entry to put on the Work queue.
159 * This routine will copy the contents of @mqe to the next available entry on
160 * the @q. This function will then ring the Work Queue Doorbell to signal the
161 * HBA to start processing the Work Queue Entry. This function returns 0 if
162 * successful. If no entries are available on @q then this function will return
164 * The caller is expected to hold the hbalock when calling this routine.
167 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
169 struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
170 struct lpfc_register doorbell;
173 /* If the host has not yet processed the next entry then we are done */
174 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
176 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
177 /* Save off the mailbox pointer for completion */
178 q->phba->mbox = (MAILBOX_t *)temp_mqe;
180 /* Update the host index before invoking device */
181 host_index = q->host_index;
182 q->host_index = ((q->host_index + 1) % q->entry_count);
186 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
187 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
188 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
189 readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
194 * lpfc_sli4_mq_release - Updates internal hba index for MQ
195 * @q: The Mailbox Queue to operate on.
197 * This routine will update the HBA index of a queue to reflect consumption of
198 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
199 * an entry the host calls this function to update the queue's internal
200 * pointers. This routine returns the number of entries that were consumed by
204 lpfc_sli4_mq_release(struct lpfc_queue *q)
206 /* Clear the mailbox pointer for completion */
207 q->phba->mbox = NULL;
208 q->hba_index = ((q->hba_index + 1) % q->entry_count);
213 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
214 * @q: The Event Queue to get the first valid EQE from
216 * This routine will get the first valid Event Queue Entry from @q, update
217 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
218 * the Queue (no more work to do), or the Queue is full of EQEs that have been
219 * processed, but not popped back to the HBA then this routine will return NULL.
221 static struct lpfc_eqe *
222 lpfc_sli4_eq_get(struct lpfc_queue *q)
224 struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
226 /* If the next EQE is not valid then we are done */
227 if (!bf_get(lpfc_eqe_valid, eqe))
229 /* If the host has not yet processed the next entry then we are done */
230 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
233 q->hba_index = ((q->hba_index + 1) % q->entry_count);
238 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
239 * @q: The Event Queue that the host has completed processing for.
240 * @arm: Indicates whether the host wants to arms this CQ.
242 * This routine will mark all Event Queue Entries on @q, from the last
243 * known completed entry to the last entry that was processed, as completed
244 * by clearing the valid bit for each completion queue entry. Then it will
245 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
246 * The internal host index in the @q will be updated by this routine to indicate
247 * that the host has finished processing the entries. The @arm parameter
248 * indicates that the queue should be rearmed when ringing the doorbell.
250 * This function will return the number of EQEs that were popped.
253 lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
255 uint32_t released = 0;
256 struct lpfc_eqe *temp_eqe;
257 struct lpfc_register doorbell;
259 /* while there are valid entries */
260 while (q->hba_index != q->host_index) {
261 temp_eqe = q->qe[q->host_index].eqe;
262 bf_set(lpfc_eqe_valid, temp_eqe, 0);
264 q->host_index = ((q->host_index + 1) % q->entry_count);
266 if (unlikely(released == 0 && !arm))
269 /* ring doorbell for number popped */
272 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
273 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
275 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
276 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
277 bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
278 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
283 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
284 * @q: The Completion Queue to get the first valid CQE from
286 * This routine will get the first valid Completion Queue Entry from @q, update
287 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
288 * the Queue (no more work to do), or the Queue is full of CQEs that have been
289 * processed, but not popped back to the HBA then this routine will return NULL.
291 static struct lpfc_cqe *
292 lpfc_sli4_cq_get(struct lpfc_queue *q)
294 struct lpfc_cqe *cqe;
296 /* If the next CQE is not valid then we are done */
297 if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
299 /* If the host has not yet processed the next entry then we are done */
300 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
303 cqe = q->qe[q->hba_index].cqe;
304 q->hba_index = ((q->hba_index + 1) % q->entry_count);
309 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
310 * @q: The Completion Queue that the host has completed processing for.
311 * @arm: Indicates whether the host wants to arms this CQ.
313 * This routine will mark all Completion queue entries on @q, from the last
314 * known completed entry to the last entry that was processed, as completed
315 * by clearing the valid bit for each completion queue entry. Then it will
316 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
317 * The internal host index in the @q will be updated by this routine to indicate
318 * that the host has finished processing the entries. The @arm parameter
319 * indicates that the queue should be rearmed when ringing the doorbell.
321 * This function will return the number of CQEs that were released.
324 lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
326 uint32_t released = 0;
327 struct lpfc_cqe *temp_qe;
328 struct lpfc_register doorbell;
330 /* while there are valid entries */
331 while (q->hba_index != q->host_index) {
332 temp_qe = q->qe[q->host_index].cqe;
333 bf_set(lpfc_cqe_valid, temp_qe, 0);
335 q->host_index = ((q->host_index + 1) % q->entry_count);
337 if (unlikely(released == 0 && !arm))
340 /* ring doorbell for number popped */
343 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
344 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
345 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
346 bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
347 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
352 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
353 * @q: The Header Receive Queue to operate on.
354 * @wqe: The Receive Queue Entry to put on the Receive queue.
356 * This routine will copy the contents of @wqe to the next available entry on
357 * the @q. This function will then ring the Receive Queue Doorbell to signal the
358 * HBA to start processing the Receive Queue Entry. This function returns the
359 * index that the rqe was copied to if successful. If no entries are available
360 * on @q then this function will return -ENOMEM.
361 * The caller is expected to hold the hbalock when calling this routine.
364 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
365 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
367 struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
368 struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
369 struct lpfc_register doorbell;
370 int put_index = hq->host_index;
372 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
374 if (hq->host_index != dq->host_index)
376 /* If the host has not yet processed the next entry then we are done */
377 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
379 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
380 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
382 /* Update the host index to point to the next slot */
383 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
384 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
386 /* Ring The Header Receive Queue Doorbell */
387 if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
389 bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
391 bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
392 writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
398 * lpfc_sli4_rq_release - Updates internal hba index for RQ
399 * @q: The Header Receive Queue to operate on.
401 * This routine will update the HBA index of a queue to reflect consumption of
402 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
403 * consumed an entry the host calls this function to update the queue's
404 * internal pointers. This routine returns the number of entries that were
405 * consumed by the HBA.
408 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
410 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
412 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
413 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
418 * lpfc_cmd_iocb - Get next command 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 command iocb entry
423 * in the command ring. The caller must hold hbalock to prevent
424 * other threads consume the next command iocb.
425 * SLI-2/SLI-3 provide different sized iocbs.
427 static inline IOCB_t *
428 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
430 return (IOCB_t *) (((char *) pring->cmdringaddr) +
431 pring->cmdidx * phba->iocb_cmd_size);
435 * lpfc_resp_iocb - Get next response iocb entry in the ring
436 * @phba: Pointer to HBA context object.
437 * @pring: Pointer to driver SLI ring object.
439 * This function returns pointer to next response iocb entry
440 * in the response ring. The caller must hold hbalock to make sure
441 * that no other thread consume the next response iocb.
442 * SLI-2/SLI-3 provide different sized iocbs.
444 static inline IOCB_t *
445 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
447 return (IOCB_t *) (((char *) pring->rspringaddr) +
448 pring->rspidx * phba->iocb_rsp_size);
452 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
453 * @phba: Pointer to HBA context object.
455 * This function is called with hbalock held. This function
456 * allocates a new driver iocb object from the iocb pool. If the
457 * allocation is successful, it returns pointer to the newly
458 * allocated iocb object else it returns NULL.
460 static struct lpfc_iocbq *
461 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
463 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
464 struct lpfc_iocbq * iocbq = NULL;
466 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
471 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
472 * @phba: Pointer to HBA context object.
473 * @xritag: XRI value.
475 * This function clears the sglq pointer from the array of acive
476 * sglq's. The xritag that is passed in is used to index into the
477 * array. Before the xritag can be used it needs to be adjusted
478 * by subtracting the xribase.
480 * Returns sglq ponter = success, NULL = Failure.
482 static struct lpfc_sglq *
483 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
486 struct lpfc_sglq *sglq;
487 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
488 if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
490 sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
491 phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
496 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
497 * @phba: Pointer to HBA context object.
498 * @xritag: XRI value.
500 * This function returns the sglq pointer from the array of acive
501 * sglq's. The xritag that is passed in is used to index into the
502 * array. Before the xritag can be used it needs to be adjusted
503 * by subtracting the xribase.
505 * Returns sglq ponter = success, NULL = Failure.
507 static struct lpfc_sglq *
508 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
511 struct lpfc_sglq *sglq;
512 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
513 if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
515 sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
520 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
521 * @phba: Pointer to HBA context object.
523 * This function is called with hbalock held. This function
524 * Gets a new driver sglq object from the sglq list. If the
525 * list is not empty then it is successful, it returns pointer to the newly
526 * allocated sglq object else it returns NULL.
528 static struct lpfc_sglq *
529 __lpfc_sli_get_sglq(struct lpfc_hba *phba)
531 struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
532 struct lpfc_sglq *sglq = NULL;
534 list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
535 adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
536 phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
541 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
542 * @phba: Pointer to HBA context object.
544 * This function is called with no lock held. This function
545 * allocates a new driver iocb object from the iocb pool. If the
546 * allocation is successful, it returns pointer to the newly
547 * allocated iocb object else it returns NULL.
550 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
552 struct lpfc_iocbq * iocbq = NULL;
553 unsigned long iflags;
555 spin_lock_irqsave(&phba->hbalock, iflags);
556 iocbq = __lpfc_sli_get_iocbq(phba);
557 spin_unlock_irqrestore(&phba->hbalock, iflags);
562 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
563 * @phba: Pointer to HBA context object.
564 * @iocbq: Pointer to driver iocb object.
566 * This function is called with hbalock held to release driver
567 * iocb object to the iocb pool. The iotag in the iocb object
568 * does not change for each use of the iocb object. This function
569 * clears all other fields of the iocb object when it is freed.
570 * The sqlq structure that holds the xritag and phys and virtual
571 * mappings for the scatter gather list is retrieved from the
572 * active array of sglq. The get of the sglq pointer also clears
573 * the entry in the array. If the status of the IO indiactes that
574 * this IO was aborted then the sglq entry it put on the
575 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
576 * IO has good status or fails for any other reason then the sglq
577 * entry is added to the free list (lpfc_sgl_list).
580 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
582 struct lpfc_sglq *sglq;
583 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
586 if (iocbq->sli4_xritag == NO_XRI)
589 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
591 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
592 || ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
593 && (iocbq->iocb.un.ulpWord[4]
594 == IOERR_SLI_ABORTED))) {
595 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
597 list_add(&sglq->list,
598 &phba->sli4_hba.lpfc_abts_els_sgl_list);
599 spin_unlock_irqrestore(
600 &phba->sli4_hba.abts_sgl_list_lock, iflag);
602 list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
607 * Clean all volatile data fields, preserve iotag and node struct.
609 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
610 iocbq->sli4_xritag = NO_XRI;
611 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
615 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
616 * @phba: Pointer to HBA context object.
617 * @iocbq: Pointer to driver iocb object.
619 * This function is called with hbalock held to release driver
620 * iocb object to the iocb pool. The iotag in the iocb object
621 * does not change for each use of the iocb object. This function
622 * clears all other fields of the iocb object when it is freed.
625 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
627 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
630 * Clean all volatile data fields, preserve iotag and node struct.
632 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
633 iocbq->sli4_xritag = NO_XRI;
634 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
638 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
639 * @phba: Pointer to HBA context object.
640 * @iocbq: Pointer to driver iocb object.
642 * This function is called with hbalock held to release driver
643 * iocb object to the iocb pool. The iotag in the iocb object
644 * does not change for each use of the iocb object. This function
645 * clears all other fields of the iocb object when it is freed.
648 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
650 phba->__lpfc_sli_release_iocbq(phba, iocbq);
654 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
655 * @phba: Pointer to HBA context object.
656 * @iocbq: Pointer to driver iocb object.
658 * This function is called with no lock held to release the iocb to
662 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
664 unsigned long iflags;
667 * Clean all volatile data fields, preserve iotag and node struct.
669 spin_lock_irqsave(&phba->hbalock, iflags);
670 __lpfc_sli_release_iocbq(phba, iocbq);
671 spin_unlock_irqrestore(&phba->hbalock, iflags);
675 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
676 * @phba: Pointer to HBA context object.
677 * @iocblist: List of IOCBs.
678 * @ulpstatus: ULP status in IOCB command field.
679 * @ulpWord4: ULP word-4 in IOCB command field.
681 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
682 * on the list by invoking the complete callback function associated with the
683 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
687 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
688 uint32_t ulpstatus, uint32_t ulpWord4)
690 struct lpfc_iocbq *piocb;
692 while (!list_empty(iocblist)) {
693 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
695 if (!piocb->iocb_cmpl)
696 lpfc_sli_release_iocbq(phba, piocb);
698 piocb->iocb.ulpStatus = ulpstatus;
699 piocb->iocb.un.ulpWord[4] = ulpWord4;
700 (piocb->iocb_cmpl) (phba, piocb, piocb);
707 * lpfc_sli_iocb_cmd_type - Get the iocb type
708 * @iocb_cmnd: iocb command code.
710 * This function is called by ring event handler function to get the iocb type.
711 * This function translates the iocb command to an iocb command type used to
712 * decide the final disposition of each completed IOCB.
713 * The function returns
714 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
715 * LPFC_SOL_IOCB if it is a solicited iocb completion
716 * LPFC_ABORT_IOCB if it is an abort iocb
717 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
719 * The caller is not required to hold any lock.
721 static lpfc_iocb_type
722 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
724 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
726 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
730 case CMD_XMIT_SEQUENCE_CR:
731 case CMD_XMIT_SEQUENCE_CX:
732 case CMD_XMIT_BCAST_CN:
733 case CMD_XMIT_BCAST_CX:
734 case CMD_ELS_REQUEST_CR:
735 case CMD_ELS_REQUEST_CX:
736 case CMD_CREATE_XRI_CR:
737 case CMD_CREATE_XRI_CX:
739 case CMD_XMIT_ELS_RSP_CX:
741 case CMD_FCP_IWRITE_CR:
742 case CMD_FCP_IWRITE_CX:
743 case CMD_FCP_IREAD_CR:
744 case CMD_FCP_IREAD_CX:
745 case CMD_FCP_ICMND_CR:
746 case CMD_FCP_ICMND_CX:
747 case CMD_FCP_TSEND_CX:
748 case CMD_FCP_TRSP_CX:
749 case CMD_FCP_TRECEIVE_CX:
750 case CMD_FCP_AUTO_TRSP_CX:
751 case CMD_ADAPTER_MSG:
752 case CMD_ADAPTER_DUMP:
753 case CMD_XMIT_SEQUENCE64_CR:
754 case CMD_XMIT_SEQUENCE64_CX:
755 case CMD_XMIT_BCAST64_CN:
756 case CMD_XMIT_BCAST64_CX:
757 case CMD_ELS_REQUEST64_CR:
758 case CMD_ELS_REQUEST64_CX:
759 case CMD_FCP_IWRITE64_CR:
760 case CMD_FCP_IWRITE64_CX:
761 case CMD_FCP_IREAD64_CR:
762 case CMD_FCP_IREAD64_CX:
763 case CMD_FCP_ICMND64_CR:
764 case CMD_FCP_ICMND64_CX:
765 case CMD_FCP_TSEND64_CX:
766 case CMD_FCP_TRSP64_CX:
767 case CMD_FCP_TRECEIVE64_CX:
768 case CMD_GEN_REQUEST64_CR:
769 case CMD_GEN_REQUEST64_CX:
770 case CMD_XMIT_ELS_RSP64_CX:
771 case DSSCMD_IWRITE64_CR:
772 case DSSCMD_IWRITE64_CX:
773 case DSSCMD_IREAD64_CR:
774 case DSSCMD_IREAD64_CX:
775 case DSSCMD_INVALIDATE_DEK:
777 case DSSCMD_GET_KEK_ID:
778 case DSSCMD_GEN_XFER:
779 type = LPFC_SOL_IOCB;
781 case CMD_ABORT_XRI_CN:
782 case CMD_ABORT_XRI_CX:
783 case CMD_CLOSE_XRI_CN:
784 case CMD_CLOSE_XRI_CX:
785 case CMD_XRI_ABORTED_CX:
786 case CMD_ABORT_MXRI64_CN:
787 type = LPFC_ABORT_IOCB;
789 case CMD_RCV_SEQUENCE_CX:
790 case CMD_RCV_ELS_REQ_CX:
791 case CMD_RCV_SEQUENCE64_CX:
792 case CMD_RCV_ELS_REQ64_CX:
793 case CMD_ASYNC_STATUS:
794 case CMD_IOCB_RCV_SEQ64_CX:
795 case CMD_IOCB_RCV_ELS64_CX:
796 case CMD_IOCB_RCV_CONT64_CX:
797 case CMD_IOCB_RET_XRI64_CX:
798 type = LPFC_UNSOL_IOCB;
800 case CMD_IOCB_XMIT_MSEQ64_CR:
801 case CMD_IOCB_XMIT_MSEQ64_CX:
802 case CMD_IOCB_RCV_SEQ_LIST64_CX:
803 case CMD_IOCB_RCV_ELS_LIST64_CX:
804 case CMD_IOCB_CLOSE_EXTENDED_CN:
805 case CMD_IOCB_ABORT_EXTENDED_CN:
806 case CMD_IOCB_RET_HBQE64_CN:
807 case CMD_IOCB_FCP_IBIDIR64_CR:
808 case CMD_IOCB_FCP_IBIDIR64_CX:
809 case CMD_IOCB_FCP_ITASKMGT64_CX:
810 case CMD_IOCB_LOGENTRY_CN:
811 case CMD_IOCB_LOGENTRY_ASYNC_CN:
812 printk("%s - Unhandled SLI-3 Command x%x\n",
813 __func__, iocb_cmnd);
814 type = LPFC_UNKNOWN_IOCB;
817 type = LPFC_UNKNOWN_IOCB;
825 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
826 * @phba: Pointer to HBA context object.
828 * This function is called from SLI initialization code
829 * to configure every ring of the HBA's SLI interface. The
830 * caller is not required to hold any lock. This function issues
831 * a config_ring mailbox command for each ring.
832 * This function returns zero if successful else returns a negative
836 lpfc_sli_ring_map(struct lpfc_hba *phba)
838 struct lpfc_sli *psli = &phba->sli;
843 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
847 phba->link_state = LPFC_INIT_MBX_CMDS;
848 for (i = 0; i < psli->num_rings; i++) {
849 lpfc_config_ring(phba, i, pmb);
850 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
851 if (rc != MBX_SUCCESS) {
852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
853 "0446 Adapter failed to init (%d), "
854 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
856 rc, pmbox->mbxCommand,
857 pmbox->mbxStatus, i);
858 phba->link_state = LPFC_HBA_ERROR;
863 mempool_free(pmb, phba->mbox_mem_pool);
868 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
869 * @phba: Pointer to HBA context object.
870 * @pring: Pointer to driver SLI ring object.
871 * @piocb: Pointer to the driver iocb object.
873 * This function is called with hbalock held. The function adds the
874 * new iocb to txcmplq of the given ring. This function always returns
875 * 0. If this function is called for ELS ring, this function checks if
876 * there is a vport associated with the ELS command. This function also
877 * starts els_tmofunc timer if this is an ELS command.
880 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
881 struct lpfc_iocbq *piocb)
883 list_add_tail(&piocb->list, &pring->txcmplq);
884 pring->txcmplq_cnt++;
885 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
886 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
887 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
891 mod_timer(&piocb->vport->els_tmofunc,
892 jiffies + HZ * (phba->fc_ratov << 1));
900 * lpfc_sli_ringtx_get - Get first element of the txq
901 * @phba: Pointer to HBA context object.
902 * @pring: Pointer to driver SLI ring object.
904 * This function is called with hbalock held to get next
905 * iocb in txq of the given ring. If there is any iocb in
906 * the txq, the function returns first iocb in the list after
907 * removing the iocb from the list, else it returns NULL.
909 static struct lpfc_iocbq *
910 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
912 struct lpfc_iocbq *cmd_iocb;
914 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
915 if (cmd_iocb != NULL)
921 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
922 * @phba: Pointer to HBA context object.
923 * @pring: Pointer to driver SLI ring object.
925 * This function is called with hbalock held and the caller must post the
926 * iocb without releasing the lock. If the caller releases the lock,
927 * iocb slot returned by the function is not guaranteed to be available.
928 * The function returns pointer to the next available iocb slot if there
929 * is available slot in the ring, else it returns NULL.
930 * If the get index of the ring is ahead of the put index, the function
931 * will post an error attention event to the worker thread to take the
932 * HBA to offline state.
935 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
937 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
938 uint32_t max_cmd_idx = pring->numCiocb;
939 if ((pring->next_cmdidx == pring->cmdidx) &&
940 (++pring->next_cmdidx >= max_cmd_idx))
941 pring->next_cmdidx = 0;
943 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
945 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
947 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
948 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
949 "0315 Ring %d issue: portCmdGet %d "
950 "is bigger than cmd ring %d\n",
952 pring->local_getidx, max_cmd_idx);
954 phba->link_state = LPFC_HBA_ERROR;
956 * All error attention handlers are posted to
959 phba->work_ha |= HA_ERATT;
960 phba->work_hs = HS_FFER3;
962 lpfc_worker_wake_up(phba);
967 if (pring->local_getidx == pring->next_cmdidx)
971 return lpfc_cmd_iocb(phba, pring);
975 * lpfc_sli_next_iotag - Get an iotag for the iocb
976 * @phba: Pointer to HBA context object.
977 * @iocbq: Pointer to driver iocb object.
979 * This function gets an iotag for the iocb. If there is no unused iotag and
980 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
981 * array and assigns a new iotag.
982 * The function returns the allocated iotag if successful, else returns zero.
983 * Zero is not a valid iotag.
984 * The caller is not required to hold any lock.
987 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
989 struct lpfc_iocbq **new_arr;
990 struct lpfc_iocbq **old_arr;
992 struct lpfc_sli *psli = &phba->sli;
995 spin_lock_irq(&phba->hbalock);
996 iotag = psli->last_iotag;
997 if(++iotag < psli->iocbq_lookup_len) {
998 psli->last_iotag = iotag;
999 psli->iocbq_lookup[iotag] = iocbq;
1000 spin_unlock_irq(&phba->hbalock);
1001 iocbq->iotag = iotag;
1003 } else if (psli->iocbq_lookup_len < (0xffff
1004 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1005 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1006 spin_unlock_irq(&phba->hbalock);
1007 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
1010 spin_lock_irq(&phba->hbalock);
1011 old_arr = psli->iocbq_lookup;
1012 if (new_len <= psli->iocbq_lookup_len) {
1013 /* highly unprobable case */
1015 iotag = psli->last_iotag;
1016 if(++iotag < psli->iocbq_lookup_len) {
1017 psli->last_iotag = iotag;
1018 psli->iocbq_lookup[iotag] = iocbq;
1019 spin_unlock_irq(&phba->hbalock);
1020 iocbq->iotag = iotag;
1023 spin_unlock_irq(&phba->hbalock);
1026 if (psli->iocbq_lookup)
1027 memcpy(new_arr, old_arr,
1028 ((psli->last_iotag + 1) *
1029 sizeof (struct lpfc_iocbq *)));
1030 psli->iocbq_lookup = new_arr;
1031 psli->iocbq_lookup_len = new_len;
1032 psli->last_iotag = iotag;
1033 psli->iocbq_lookup[iotag] = iocbq;
1034 spin_unlock_irq(&phba->hbalock);
1035 iocbq->iotag = iotag;
1040 spin_unlock_irq(&phba->hbalock);
1042 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
1043 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1050 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1051 * @phba: Pointer to HBA context object.
1052 * @pring: Pointer to driver SLI ring object.
1053 * @iocb: Pointer to iocb slot in the ring.
1054 * @nextiocb: Pointer to driver iocb object which need to be
1055 * posted to firmware.
1057 * This function is called with hbalock held to post a new iocb to
1058 * the firmware. This function copies the new iocb to ring iocb slot and
1059 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1060 * a completion call back for this iocb else the function will free the
1064 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1065 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1070 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1073 if (pring->ringno == LPFC_ELS_RING) {
1074 lpfc_debugfs_slow_ring_trc(phba,
1075 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1076 *(((uint32_t *) &nextiocb->iocb) + 4),
1077 *(((uint32_t *) &nextiocb->iocb) + 6),
1078 *(((uint32_t *) &nextiocb->iocb) + 7));
1082 * Issue iocb command to adapter
1084 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1086 pring->stats.iocb_cmd++;
1089 * If there is no completion routine to call, we can release the
1090 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1091 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1093 if (nextiocb->iocb_cmpl)
1094 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1096 __lpfc_sli_release_iocbq(phba, nextiocb);
1099 * Let the HBA know what IOCB slot will be the next one the
1100 * driver will put a command into.
1102 pring->cmdidx = pring->next_cmdidx;
1103 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1107 * lpfc_sli_update_full_ring - Update the chip attention register
1108 * @phba: Pointer to HBA context object.
1109 * @pring: Pointer to driver SLI ring object.
1111 * The caller is not required to hold any lock for calling this function.
1112 * This function updates the chip attention bits for the ring to inform firmware
1113 * that there are pending work to be done for this ring and requests an
1114 * interrupt when there is space available in the ring. This function is
1115 * called when the driver is unable to post more iocbs to the ring due
1116 * to unavailability of space in the ring.
1119 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1121 int ringno = pring->ringno;
1123 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1128 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1129 * The HBA will tell us when an IOCB entry is available.
1131 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1132 readl(phba->CAregaddr); /* flush */
1134 pring->stats.iocb_cmd_full++;
1138 * lpfc_sli_update_ring - Update chip attention register
1139 * @phba: Pointer to HBA context object.
1140 * @pring: Pointer to driver SLI ring object.
1142 * This function updates the chip attention register bit for the
1143 * given ring to inform HBA that there is more work to be done
1144 * in this ring. The caller is not required to hold any lock.
1147 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1149 int ringno = pring->ringno;
1152 * Tell the HBA that there is work to do in this ring.
1154 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1156 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1157 readl(phba->CAregaddr); /* flush */
1162 * lpfc_sli_resume_iocb - Process iocbs in the txq
1163 * @phba: Pointer to HBA context object.
1164 * @pring: Pointer to driver SLI ring object.
1166 * This function is called with hbalock held to post pending iocbs
1167 * in the txq to the firmware. This function is called when driver
1168 * detects space available in the ring.
1171 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1174 struct lpfc_iocbq *nextiocb;
1178 * (a) there is anything on the txq to send
1180 * (c) link attention events can be processed (fcp ring only)
1181 * (d) IOCB processing is not blocked by the outstanding mbox command.
1183 if (pring->txq_cnt &&
1184 lpfc_is_link_up(phba) &&
1185 (pring->ringno != phba->sli.fcp_ring ||
1186 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1188 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1189 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1190 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1193 lpfc_sli_update_ring(phba, pring);
1195 lpfc_sli_update_full_ring(phba, pring);
1202 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1203 * @phba: Pointer to HBA context object.
1204 * @hbqno: HBQ number.
1206 * This function is called with hbalock held to get the next
1207 * available slot for the given HBQ. If there is free slot
1208 * available for the HBQ it will return pointer to the next available
1209 * HBQ entry else it will return NULL.
1211 static struct lpfc_hbq_entry *
1212 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1214 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1216 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1217 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1218 hbqp->next_hbqPutIdx = 0;
1220 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1221 uint32_t raw_index = phba->hbq_get[hbqno];
1222 uint32_t getidx = le32_to_cpu(raw_index);
1224 hbqp->local_hbqGetIdx = getidx;
1226 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1227 lpfc_printf_log(phba, KERN_ERR,
1228 LOG_SLI | LOG_VPORT,
1229 "1802 HBQ %d: local_hbqGetIdx "
1230 "%u is > than hbqp->entry_count %u\n",
1231 hbqno, hbqp->local_hbqGetIdx,
1234 phba->link_state = LPFC_HBA_ERROR;
1238 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1242 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1247 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1248 * @phba: Pointer to HBA context object.
1250 * This function is called with no lock held to free all the
1251 * hbq buffers while uninitializing the SLI interface. It also
1252 * frees the HBQ buffers returned by the firmware but not yet
1253 * processed by the upper layers.
1256 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1258 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1259 struct hbq_dmabuf *hbq_buf;
1260 unsigned long flags;
1264 hbq_count = lpfc_sli_hbq_count();
1265 /* Return all memory used by all HBQs */
1266 spin_lock_irqsave(&phba->hbalock, flags);
1267 for (i = 0; i < hbq_count; ++i) {
1268 list_for_each_entry_safe(dmabuf, next_dmabuf,
1269 &phba->hbqs[i].hbq_buffer_list, list) {
1270 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1271 list_del(&hbq_buf->dbuf.list);
1272 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1274 phba->hbqs[i].buffer_count = 0;
1276 /* Return all HBQ buffer that are in-fly */
1277 list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
1279 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1280 list_del(&hbq_buf->dbuf.list);
1281 if (hbq_buf->tag == -1) {
1282 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1285 hbqno = hbq_buf->tag >> 16;
1286 if (hbqno >= LPFC_MAX_HBQS)
1287 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1290 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1295 /* Mark the HBQs not in use */
1296 phba->hbq_in_use = 0;
1297 spin_unlock_irqrestore(&phba->hbalock, flags);
1301 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1302 * @phba: Pointer to HBA context object.
1303 * @hbqno: HBQ number.
1304 * @hbq_buf: Pointer to HBQ buffer.
1306 * This function is called with the hbalock held to post a
1307 * hbq buffer to the firmware. If the function finds an empty
1308 * slot in the HBQ, it will post the buffer. The function will return
1309 * pointer to the hbq entry if it successfully post the buffer
1310 * else it will return NULL.
1313 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
1314 struct hbq_dmabuf *hbq_buf)
1316 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1320 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1321 * @phba: Pointer to HBA context object.
1322 * @hbqno: HBQ number.
1323 * @hbq_buf: Pointer to HBQ buffer.
1325 * This function is called with the hbalock held to post a hbq buffer to the
1326 * firmware. If the function finds an empty slot in the HBQ, it will post the
1327 * buffer and place it on the hbq_buffer_list. The function will return zero if
1328 * it successfully post the buffer else it will return an error.
1331 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1332 struct hbq_dmabuf *hbq_buf)
1334 struct lpfc_hbq_entry *hbqe;
1335 dma_addr_t physaddr = hbq_buf->dbuf.phys;
1337 /* Get next HBQ entry slot to use */
1338 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1340 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1342 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1343 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
1344 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
1345 hbqe->bde.tus.f.bdeFlags = 0;
1346 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1347 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1349 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1350 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
1352 readl(phba->hbq_put + hbqno);
1353 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
1360 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1361 * @phba: Pointer to HBA context object.
1362 * @hbqno: HBQ number.
1363 * @hbq_buf: Pointer to HBQ buffer.
1365 * This function is called with the hbalock held to post an RQE to the SLI4
1366 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1367 * the hbq_buffer_list and return zero, otherwise it will return an error.
1370 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1371 struct hbq_dmabuf *hbq_buf)
1374 struct lpfc_rqe hrqe;
1375 struct lpfc_rqe drqe;
1377 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1378 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1379 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1380 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1381 rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
1386 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1390 /* HBQ for ELS and CT traffic. */
1391 static struct lpfc_hbq_init lpfc_els_hbq = {
1396 .ring_mask = (1 << LPFC_ELS_RING),
1402 /* HBQ for the extra ring if needed */
1403 static struct lpfc_hbq_init lpfc_extra_hbq = {
1408 .ring_mask = (1 << LPFC_EXTRA_RING),
1415 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
1421 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1422 * @phba: Pointer to HBA context object.
1423 * @hbqno: HBQ number.
1424 * @count: Number of HBQ buffers to be posted.
1426 * This function is called with no lock held to post more hbq buffers to the
1427 * given HBQ. The function returns the number of HBQ buffers successfully
1431 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1433 uint32_t i, posted = 0;
1434 unsigned long flags;
1435 struct hbq_dmabuf *hbq_buffer;
1436 LIST_HEAD(hbq_buf_list);
1437 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
1440 if ((phba->hbqs[hbqno].buffer_count + count) >
1441 lpfc_hbq_defs[hbqno]->entry_count)
1442 count = lpfc_hbq_defs[hbqno]->entry_count -
1443 phba->hbqs[hbqno].buffer_count;
1446 /* Allocate HBQ entries */
1447 for (i = 0; i < count; i++) {
1448 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1451 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1453 /* Check whether HBQ is still in use */
1454 spin_lock_irqsave(&phba->hbalock, flags);
1455 if (!phba->hbq_in_use)
1457 while (!list_empty(&hbq_buf_list)) {
1458 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1460 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1462 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
1463 phba->hbqs[hbqno].buffer_count++;
1466 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1468 spin_unlock_irqrestore(&phba->hbalock, flags);
1471 spin_unlock_irqrestore(&phba->hbalock, flags);
1472 while (!list_empty(&hbq_buf_list)) {
1473 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1475 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1481 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1482 * @phba: Pointer to HBA context object.
1485 * This function posts more buffers to the HBQ. This function
1486 * is called with no lock held. The function returns the number of HBQ entries
1487 * successfully allocated.
1490 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
1492 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1493 lpfc_hbq_defs[qno]->add_count));
1497 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1498 * @phba: Pointer to HBA context object.
1499 * @qno: HBQ queue number.
1501 * This function is called from SLI initialization code path with
1502 * no lock held to post initial HBQ buffers to firmware. The
1503 * function returns the number of HBQ entries successfully allocated.
1506 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
1508 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1509 lpfc_hbq_defs[qno]->init_count));
1513 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1514 * @phba: Pointer to HBA context object.
1515 * @hbqno: HBQ number.
1517 * This function removes the first hbq buffer on an hbq list and returns a
1518 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1520 static struct hbq_dmabuf *
1521 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
1523 struct lpfc_dmabuf *d_buf;
1525 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
1528 return container_of(d_buf, struct hbq_dmabuf, dbuf);
1532 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1533 * @phba: Pointer to HBA context object.
1534 * @tag: Tag of the hbq buffer.
1536 * This function is called with hbalock held. This function searches
1537 * for the hbq buffer associated with the given tag in the hbq buffer
1538 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1541 static struct hbq_dmabuf *
1542 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
1544 struct lpfc_dmabuf *d_buf;
1545 struct hbq_dmabuf *hbq_buf;
1549 if (hbqno >= LPFC_MAX_HBQS)
1552 spin_lock_irq(&phba->hbalock);
1553 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
1554 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
1555 if (hbq_buf->tag == tag) {
1556 spin_unlock_irq(&phba->hbalock);
1560 spin_unlock_irq(&phba->hbalock);
1561 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
1562 "1803 Bad hbq tag. Data: x%x x%x\n",
1563 tag, phba->hbqs[tag >> 16].buffer_count);
1568 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1569 * @phba: Pointer to HBA context object.
1570 * @hbq_buffer: Pointer to HBQ buffer.
1572 * This function is called with hbalock. This function gives back
1573 * the hbq buffer to firmware. If the HBQ does not have space to
1574 * post the buffer, it will free the buffer.
1577 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
1582 hbqno = hbq_buffer->tag >> 16;
1583 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
1584 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1589 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1590 * @mbxCommand: mailbox command code.
1592 * This function is called by the mailbox event handler function to verify
1593 * that the completed mailbox command is a legitimate mailbox command. If the
1594 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1595 * and the mailbox event handler will take the HBA offline.
1598 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
1602 switch (mbxCommand) {
1606 case MBX_WRITE_VPARMS:
1607 case MBX_RUN_BIU_DIAG:
1610 case MBX_CONFIG_LINK:
1611 case MBX_CONFIG_RING:
1612 case MBX_RESET_RING:
1613 case MBX_READ_CONFIG:
1614 case MBX_READ_RCONFIG:
1615 case MBX_READ_SPARM:
1616 case MBX_READ_STATUS:
1620 case MBX_READ_LNK_STAT:
1622 case MBX_UNREG_LOGIN:
1625 case MBX_DUMP_MEMORY:
1626 case MBX_DUMP_CONTEXT:
1629 case MBX_UPDATE_CFG:
1631 case MBX_DEL_LD_ENTRY:
1632 case MBX_RUN_PROGRAM:
1634 case MBX_SET_VARIABLE:
1635 case MBX_UNREG_D_ID:
1636 case MBX_KILL_BOARD:
1637 case MBX_CONFIG_FARP:
1640 case MBX_RUN_BIU_DIAG64:
1641 case MBX_CONFIG_PORT:
1642 case MBX_READ_SPARM64:
1643 case MBX_READ_RPI64:
1644 case MBX_REG_LOGIN64:
1648 case MBX_LOAD_EXP_ROM:
1649 case MBX_ASYNCEVT_ENABLE:
1653 case MBX_PORT_CAPABILITIES:
1654 case MBX_PORT_IOV_CONTROL:
1665 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
1666 * @phba: Pointer to HBA context object.
1667 * @pmboxq: Pointer to mailbox command.
1669 * This is completion handler function for mailbox commands issued from
1670 * lpfc_sli_issue_mbox_wait function. This function is called by the
1671 * mailbox event handler function with no lock held. This function
1672 * will wake up thread waiting on the wait queue pointed by context1
1676 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
1678 wait_queue_head_t *pdone_q;
1679 unsigned long drvr_flag;
1682 * If pdone_q is empty, the driver thread gave up waiting and
1683 * continued running.
1685 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
1686 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1687 pdone_q = (wait_queue_head_t *) pmboxq->context1;
1689 wake_up_interruptible(pdone_q);
1690 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1696 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
1697 * @phba: Pointer to HBA context object.
1698 * @pmb: Pointer to mailbox object.
1700 * This function is the default mailbox completion handler. It
1701 * frees the memory resources associated with the completed mailbox
1702 * command. If the completed command is a REG_LOGIN mailbox command,
1703 * this function will issue a UREG_LOGIN to re-claim the RPI.
1706 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1708 struct lpfc_dmabuf *mp;
1712 mp = (struct lpfc_dmabuf *) (pmb->context1);
1715 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1720 * If a REG_LOGIN succeeded after node is destroyed or node
1721 * is in re-discovery driver need to cleanup the RPI.
1723 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1724 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
1725 !pmb->mb.mbxStatus) {
1727 rpi = pmb->mb.un.varWords[0];
1728 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
1729 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1730 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1731 if (rc != MBX_NOT_FINISHED)
1735 mempool_free(pmb, phba->mbox_mem_pool);
1740 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
1741 * @phba: Pointer to HBA context object.
1743 * This function is called with no lock held. This function processes all
1744 * the completed mailbox commands and gives it to upper layers. The interrupt
1745 * service routine processes mailbox completion interrupt and adds completed
1746 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1747 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1748 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1749 * function returns the mailbox commands to the upper layer by calling the
1750 * completion handler function of each mailbox.
1753 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
1760 phba->sli.slistat.mbox_event++;
1762 /* Get all completed mailboxe buffers into the cmplq */
1763 spin_lock_irq(&phba->hbalock);
1764 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
1765 spin_unlock_irq(&phba->hbalock);
1767 /* Get a Mailbox buffer to setup mailbox commands for callback */
1769 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
1775 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
1777 lpfc_debugfs_disc_trc(pmb->vport,
1778 LPFC_DISC_TRC_MBOX_VPORT,
1779 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1780 (uint32_t)pmbox->mbxCommand,
1781 pmbox->un.varWords[0],
1782 pmbox->un.varWords[1]);
1785 lpfc_debugfs_disc_trc(phba->pport,
1787 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1788 (uint32_t)pmbox->mbxCommand,
1789 pmbox->un.varWords[0],
1790 pmbox->un.varWords[1]);
1795 * It is a fatal error if unknown mbox command completion.
1797 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
1799 /* Unknow mailbox command compl */
1800 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1801 "(%d):0323 Unknown Mailbox command "
1803 pmb->vport ? pmb->vport->vpi : 0,
1805 phba->link_state = LPFC_HBA_ERROR;
1806 phba->work_hs = HS_FFER3;
1807 lpfc_handle_eratt(phba);
1811 if (pmbox->mbxStatus) {
1812 phba->sli.slistat.mbox_stat_err++;
1813 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
1814 /* Mbox cmd cmpl error - RETRYing */
1815 lpfc_printf_log(phba, KERN_INFO,
1817 "(%d):0305 Mbox cmd cmpl "
1818 "error - RETRYing Data: x%x "
1820 pmb->vport ? pmb->vport->vpi :0,
1823 pmbox->un.varWords[0],
1824 pmb->vport->port_state);
1825 pmbox->mbxStatus = 0;
1826 pmbox->mbxOwner = OWN_HOST;
1827 spin_lock_irq(&phba->hbalock);
1828 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1829 spin_unlock_irq(&phba->hbalock);
1830 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1831 if (rc == MBX_SUCCESS)
1836 /* Mailbox cmd <cmd> Cmpl <cmpl> */
1837 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
1838 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
1839 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1840 pmb->vport ? pmb->vport->vpi : 0,
1843 *((uint32_t *) pmbox),
1844 pmbox->un.varWords[0],
1845 pmbox->un.varWords[1],
1846 pmbox->un.varWords[2],
1847 pmbox->un.varWords[3],
1848 pmbox->un.varWords[4],
1849 pmbox->un.varWords[5],
1850 pmbox->un.varWords[6],
1851 pmbox->un.varWords[7]);
1854 pmb->mbox_cmpl(phba,pmb);
1860 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
1861 * @phba: Pointer to HBA context object.
1862 * @pring: Pointer to driver SLI ring object.
1865 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1866 * is set in the tag the buffer is posted for a particular exchange,
1867 * the function will return the buffer without replacing the buffer.
1868 * If the buffer is for unsolicited ELS or CT traffic, this function
1869 * returns the buffer and also posts another buffer to the firmware.
1871 static struct lpfc_dmabuf *
1872 lpfc_sli_get_buff(struct lpfc_hba *phba,
1873 struct lpfc_sli_ring *pring,
1876 struct hbq_dmabuf *hbq_entry;
1878 if (tag & QUE_BUFTAG_BIT)
1879 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
1880 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
1883 return &hbq_entry->dbuf;
1887 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
1888 * @phba: Pointer to HBA context object.
1889 * @pring: Pointer to driver SLI ring object.
1890 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
1891 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
1892 * @fch_type: the type for the first frame of the sequence.
1894 * This function is called with no lock held. This function uses the r_ctl and
1895 * type of the received sequence to find the correct callback function to call
1896 * to process the sequence.
1899 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1900 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
1905 /* unSolicited Responses */
1906 if (pring->prt[0].profile) {
1907 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1908 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1912 /* We must search, based on rctl / type
1913 for the right routine */
1914 for (i = 0; i < pring->num_mask; i++) {
1915 if ((pring->prt[i].rctl == fch_r_ctl) &&
1916 (pring->prt[i].type == fch_type)) {
1917 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1918 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1919 (phba, pring, saveq);
1927 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
1928 * @phba: Pointer to HBA context object.
1929 * @pring: Pointer to driver SLI ring object.
1930 * @saveq: Pointer to the unsolicited iocb.
1932 * This function is called with no lock held by the ring event handler
1933 * when there is an unsolicited iocb posted to the response ring by the
1934 * firmware. This function gets the buffer associated with the iocbs
1935 * and calls the event handler for the ring. This function handles both
1936 * qring buffers and hbq buffers.
1937 * When the function returns 1 the caller can free the iocb object otherwise
1938 * upper layer functions will free the iocb objects.
1941 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1942 struct lpfc_iocbq *saveq)
1946 uint32_t Rctl, Type;
1948 struct lpfc_iocbq *iocbq;
1949 struct lpfc_dmabuf *dmzbuf;
1952 irsp = &(saveq->iocb);
1954 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
1955 if (pring->lpfc_sli_rcv_async_status)
1956 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
1958 lpfc_printf_log(phba,
1961 "0316 Ring %d handler: unexpected "
1962 "ASYNC_STATUS iocb received evt_code "
1965 irsp->un.asyncstat.evt_code);
1969 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
1970 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
1971 if (irsp->ulpBdeCount > 0) {
1972 dmzbuf = lpfc_sli_get_buff(phba, pring,
1973 irsp->un.ulpWord[3]);
1974 lpfc_in_buf_free(phba, dmzbuf);
1977 if (irsp->ulpBdeCount > 1) {
1978 dmzbuf = lpfc_sli_get_buff(phba, pring,
1979 irsp->unsli3.sli3Words[3]);
1980 lpfc_in_buf_free(phba, dmzbuf);
1983 if (irsp->ulpBdeCount > 2) {
1984 dmzbuf = lpfc_sli_get_buff(phba, pring,
1985 irsp->unsli3.sli3Words[7]);
1986 lpfc_in_buf_free(phba, dmzbuf);
1992 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1993 if (irsp->ulpBdeCount != 0) {
1994 saveq->context2 = lpfc_sli_get_buff(phba, pring,
1995 irsp->un.ulpWord[3]);
1996 if (!saveq->context2)
1997 lpfc_printf_log(phba,
2000 "0341 Ring %d Cannot find buffer for "
2001 "an unsolicited iocb. tag 0x%x\n",
2003 irsp->un.ulpWord[3]);
2005 if (irsp->ulpBdeCount == 2) {
2006 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2007 irsp->unsli3.sli3Words[7]);
2008 if (!saveq->context3)
2009 lpfc_printf_log(phba,
2012 "0342 Ring %d Cannot find buffer for an"
2013 " unsolicited iocb. tag 0x%x\n",
2015 irsp->unsli3.sli3Words[7]);
2017 list_for_each_entry(iocbq, &saveq->list, list) {
2018 irsp = &(iocbq->iocb);
2019 if (irsp->ulpBdeCount != 0) {
2020 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2021 irsp->un.ulpWord[3]);
2022 if (!iocbq->context2)
2023 lpfc_printf_log(phba,
2026 "0343 Ring %d Cannot find "
2027 "buffer for an unsolicited iocb"
2028 ". tag 0x%x\n", pring->ringno,
2029 irsp->un.ulpWord[3]);
2031 if (irsp->ulpBdeCount == 2) {
2032 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2033 irsp->unsli3.sli3Words[7]);
2034 if (!iocbq->context3)
2035 lpfc_printf_log(phba,
2038 "0344 Ring %d Cannot find "
2039 "buffer for an unsolicited "
2042 irsp->unsli3.sli3Words[7]);
2046 if (irsp->ulpBdeCount != 0 &&
2047 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2048 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2051 /* search continue save q for same XRI */
2052 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2053 if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
2054 list_add_tail(&saveq->list, &iocbq->list);
2060 list_add_tail(&saveq->clist,
2061 &pring->iocb_continue_saveq);
2062 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2063 list_del_init(&iocbq->clist);
2065 irsp = &(saveq->iocb);
2069 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2070 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2071 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2075 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2076 Rctl = w5p->hcsw.Rctl;
2077 Type = w5p->hcsw.Type;
2079 /* Firmware Workaround */
2080 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2081 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2082 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2085 w5p->hcsw.Rctl = Rctl;
2086 w5p->hcsw.Type = Type;
2090 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2091 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2092 "0313 Ring %d handler: unexpected Rctl x%x "
2093 "Type x%x received\n",
2094 pring->ringno, Rctl, Type);
2100 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2101 * @phba: Pointer to HBA context object.
2102 * @pring: Pointer to driver SLI ring object.
2103 * @prspiocb: Pointer to response iocb object.
2105 * This function looks up the iocb_lookup table to get the command iocb
2106 * corresponding to the given response iocb using the iotag of the
2107 * response iocb. This function is called with the hbalock held.
2108 * This function returns the command iocb object if it finds the command
2109 * iocb else returns NULL.
2111 static struct lpfc_iocbq *
2112 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2113 struct lpfc_sli_ring *pring,
2114 struct lpfc_iocbq *prspiocb)
2116 struct lpfc_iocbq *cmd_iocb = NULL;
2119 iotag = prspiocb->iocb.ulpIoTag;
2121 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2122 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2123 list_del_init(&cmd_iocb->list);
2124 pring->txcmplq_cnt--;
2128 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2129 "0317 iotag x%x is out off "
2130 "range: max iotag x%x wd0 x%x\n",
2131 iotag, phba->sli.last_iotag,
2132 *(((uint32_t *) &prspiocb->iocb) + 7));
2137 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2138 * @phba: Pointer to HBA context object.
2139 * @pring: Pointer to driver SLI ring object.
2142 * This function looks up the iocb_lookup table to get the command iocb
2143 * corresponding to the given iotag. This function is called with the
2145 * This function returns the command iocb object if it finds the command
2146 * iocb else returns NULL.
2148 static struct lpfc_iocbq *
2149 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2150 struct lpfc_sli_ring *pring, uint16_t iotag)
2152 struct lpfc_iocbq *cmd_iocb;
2154 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2155 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2156 list_del_init(&cmd_iocb->list);
2157 pring->txcmplq_cnt--;
2161 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2162 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2163 iotag, phba->sli.last_iotag);
2168 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2169 * @phba: Pointer to HBA context object.
2170 * @pring: Pointer to driver SLI ring object.
2171 * @saveq: Pointer to the response iocb to be processed.
2173 * This function is called by the ring event handler for non-fcp
2174 * rings when there is a new response iocb in the response ring.
2175 * The caller is not required to hold any locks. This function
2176 * gets the command iocb associated with the response iocb and
2177 * calls the completion handler for the command iocb. If there
2178 * is no completion handler, the function will free the resources
2179 * associated with command iocb. If the response iocb is for
2180 * an already aborted command iocb, the status of the completion
2181 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2182 * This function always returns 1.
2185 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2186 struct lpfc_iocbq *saveq)
2188 struct lpfc_iocbq *cmdiocbp;
2190 unsigned long iflag;
2192 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2193 spin_lock_irqsave(&phba->hbalock, iflag);
2194 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
2195 spin_unlock_irqrestore(&phba->hbalock, iflag);
2198 if (cmdiocbp->iocb_cmpl) {
2200 * If an ELS command failed send an event to mgmt
2203 if (saveq->iocb.ulpStatus &&
2204 (pring->ringno == LPFC_ELS_RING) &&
2205 (cmdiocbp->iocb.ulpCommand ==
2206 CMD_ELS_REQUEST64_CR))
2207 lpfc_send_els_failure_event(phba,
2211 * Post all ELS completions to the worker thread.
2212 * All other are passed to the completion callback.
2214 if (pring->ringno == LPFC_ELS_RING) {
2215 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
2216 cmdiocbp->iocb_flag &=
2217 ~LPFC_DRIVER_ABORTED;
2218 saveq->iocb.ulpStatus =
2219 IOSTAT_LOCAL_REJECT;
2220 saveq->iocb.un.ulpWord[4] =
2223 /* Firmware could still be in progress
2224 * of DMAing payload, so don't free data
2225 * buffer till after a hbeat.
2227 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2230 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
2232 lpfc_sli_release_iocbq(phba, cmdiocbp);
2235 * Unknown initiating command based on the response iotag.
2236 * This could be the case on the ELS ring because of
2239 if (pring->ringno != LPFC_ELS_RING) {
2241 * Ring <ringno> handler: unexpected completion IoTag
2244 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2245 "0322 Ring %d handler: "
2246 "unexpected completion IoTag x%x "
2247 "Data: x%x x%x x%x x%x\n",
2249 saveq->iocb.ulpIoTag,
2250 saveq->iocb.ulpStatus,
2251 saveq->iocb.un.ulpWord[4],
2252 saveq->iocb.ulpCommand,
2253 saveq->iocb.ulpContext);
2261 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2262 * @phba: Pointer to HBA context object.
2263 * @pring: Pointer to driver SLI ring object.
2265 * This function is called from the iocb ring event handlers when
2266 * put pointer is ahead of the get pointer for a ring. This function signal
2267 * an error attention condition to the worker thread and the worker
2268 * thread will transition the HBA to offline state.
2271 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2273 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2275 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2276 * rsp ring <portRspMax>
2278 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2279 "0312 Ring %d handler: portRspPut %d "
2280 "is bigger than rsp ring %d\n",
2281 pring->ringno, le32_to_cpu(pgp->rspPutInx),
2284 phba->link_state = LPFC_HBA_ERROR;
2287 * All error attention handlers are posted to
2290 phba->work_ha |= HA_ERATT;
2291 phba->work_hs = HS_FFER3;
2293 lpfc_worker_wake_up(phba);
2299 * lpfc_poll_eratt - Error attention polling timer timeout handler
2300 * @ptr: Pointer to address of HBA context object.
2302 * This function is invoked by the Error Attention polling timer when the
2303 * timer times out. It will check the SLI Error Attention register for
2304 * possible attention events. If so, it will post an Error Attention event
2305 * and wake up worker thread to process it. Otherwise, it will set up the
2306 * Error Attention polling timer for the next poll.
2308 void lpfc_poll_eratt(unsigned long ptr)
2310 struct lpfc_hba *phba;
2313 phba = (struct lpfc_hba *)ptr;
2315 /* Check chip HA register for error event */
2316 eratt = lpfc_sli_check_eratt(phba);
2319 /* Tell the worker thread there is work to do */
2320 lpfc_worker_wake_up(phba);
2322 /* Restart the timer for next eratt poll */
2323 mod_timer(&phba->eratt_poll, jiffies +
2324 HZ * LPFC_ERATT_POLL_INTERVAL);
2329 * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
2330 * @phba: Pointer to HBA context object.
2332 * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
2333 * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
2336 * The caller does not hold any lock.
2337 * The function processes each response iocb in the response ring until it
2338 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2339 * LE bit set. The function will call the completion handler of the command iocb
2340 * if the response iocb indicates a completion for a command iocb or it is
2341 * an abort completion.
2343 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
2345 struct lpfc_sli *psli = &phba->sli;
2346 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
2347 IOCB_t *irsp = NULL;
2348 IOCB_t *entry = NULL;
2349 struct lpfc_iocbq *cmdiocbq = NULL;
2350 struct lpfc_iocbq rspiocbq;
2351 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2353 uint32_t portRspPut, portRspMax;
2355 uint32_t rsp_cmpl = 0;
2357 unsigned long iflags;
2359 pring->stats.iocb_event++;
2362 * The next available response entry should never exceed the maximum
2363 * entries. If it does, treat it as an adapter hardware error.
2365 portRspMax = pring->numRiocb;
2366 portRspPut = le32_to_cpu(pgp->rspPutInx);
2367 if (unlikely(portRspPut >= portRspMax)) {
2368 lpfc_sli_rsp_pointers_error(phba, pring);
2373 while (pring->rspidx != portRspPut) {
2374 entry = lpfc_resp_iocb(phba, pring);
2375 if (++pring->rspidx >= portRspMax)
2378 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2379 (uint32_t *) &rspiocbq.iocb,
2380 phba->iocb_rsp_size);
2381 irsp = &rspiocbq.iocb;
2382 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2383 pring->stats.iocb_rsp++;
2386 if (unlikely(irsp->ulpStatus)) {
2387 /* Rsp ring <ringno> error: IOCB */
2388 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2389 "0326 Rsp Ring %d error: IOCB Data: "
2390 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2392 irsp->un.ulpWord[0],
2393 irsp->un.ulpWord[1],
2394 irsp->un.ulpWord[2],
2395 irsp->un.ulpWord[3],
2396 irsp->un.ulpWord[4],
2397 irsp->un.ulpWord[5],
2398 *(uint32_t *)&irsp->un1,
2399 *((uint32_t *)&irsp->un1 + 1));
2403 case LPFC_ABORT_IOCB:
2406 * Idle exchange closed via ABTS from port. No iocb
2407 * resources need to be recovered.
2409 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2410 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2411 "0314 IOCB cmd 0x%x "
2412 "processed. Skipping "
2418 spin_lock_irqsave(&phba->hbalock, iflags);
2419 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2421 spin_unlock_irqrestore(&phba->hbalock, iflags);
2422 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
2423 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2428 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2429 char adaptermsg[LPFC_MAX_ADPTMSG];
2430 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2431 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2433 dev_warn(&((phba->pcidev)->dev),
2435 phba->brd_no, adaptermsg);
2437 /* Unknown IOCB command */
2438 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2439 "0321 Unknown IOCB command "
2440 "Data: x%x, x%x x%x x%x x%x\n",
2441 type, irsp->ulpCommand,
2450 * The response IOCB has been processed. Update the ring
2451 * pointer in SLIM. If the port response put pointer has not
2452 * been updated, sync the pgp->rspPutInx and fetch the new port
2453 * response put pointer.
2455 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2457 if (pring->rspidx == portRspPut)
2458 portRspPut = le32_to_cpu(pgp->rspPutInx);
2461 ha_copy = readl(phba->HAregaddr);
2462 ha_copy >>= (LPFC_FCP_RING * 4);
2464 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
2465 spin_lock_irqsave(&phba->hbalock, iflags);
2466 pring->stats.iocb_rsp_full++;
2467 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
2468 writel(status, phba->CAregaddr);
2469 readl(phba->CAregaddr);
2470 spin_unlock_irqrestore(&phba->hbalock, iflags);
2472 if ((ha_copy & HA_R0CE_RSP) &&
2473 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2474 spin_lock_irqsave(&phba->hbalock, iflags);
2475 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2476 pring->stats.iocb_cmd_empty++;
2478 /* Force update of the local copy of cmdGetInx */
2479 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2480 lpfc_sli_resume_iocb(phba, pring);
2482 if ((pring->lpfc_sli_cmd_available))
2483 (pring->lpfc_sli_cmd_available) (phba, pring);
2485 spin_unlock_irqrestore(&phba->hbalock, iflags);
2492 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2493 * @phba: Pointer to HBA context object.
2494 * @pring: Pointer to driver SLI ring object.
2495 * @mask: Host attention register mask for this ring.
2497 * This function is called from the interrupt context when there is a ring
2498 * event for the fcp ring. The caller does not hold any lock.
2499 * The function processes each response iocb in the response ring until it
2500 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2501 * LE bit set. The function will call the completion handler of the command iocb
2502 * if the response iocb indicates a completion for a command iocb or it is
2503 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2504 * function if this is an unsolicited iocb.
2505 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2506 * to check it explicitly. This function always returns 1.
2509 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
2510 struct lpfc_sli_ring *pring, uint32_t mask)
2512 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2513 IOCB_t *irsp = NULL;
2514 IOCB_t *entry = NULL;
2515 struct lpfc_iocbq *cmdiocbq = NULL;
2516 struct lpfc_iocbq rspiocbq;
2518 uint32_t portRspPut, portRspMax;
2520 lpfc_iocb_type type;
2521 unsigned long iflag;
2522 uint32_t rsp_cmpl = 0;
2524 spin_lock_irqsave(&phba->hbalock, iflag);
2525 pring->stats.iocb_event++;
2528 * The next available response entry should never exceed the maximum
2529 * entries. If it does, treat it as an adapter hardware error.
2531 portRspMax = pring->numRiocb;
2532 portRspPut = le32_to_cpu(pgp->rspPutInx);
2533 if (unlikely(portRspPut >= portRspMax)) {
2534 lpfc_sli_rsp_pointers_error(phba, pring);
2535 spin_unlock_irqrestore(&phba->hbalock, iflag);
2540 while (pring->rspidx != portRspPut) {
2542 * Fetch an entry off the ring and copy it into a local data
2543 * structure. The copy involves a byte-swap since the
2544 * network byte order and pci byte orders are different.
2546 entry = lpfc_resp_iocb(phba, pring);
2547 phba->last_completion_time = jiffies;
2549 if (++pring->rspidx >= portRspMax)
2552 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2553 (uint32_t *) &rspiocbq.iocb,
2554 phba->iocb_rsp_size);
2555 INIT_LIST_HEAD(&(rspiocbq.list));
2556 irsp = &rspiocbq.iocb;
2558 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2559 pring->stats.iocb_rsp++;
2562 if (unlikely(irsp->ulpStatus)) {
2564 * If resource errors reported from HBA, reduce
2565 * queuedepths of the SCSI device.
2567 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2568 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2569 spin_unlock_irqrestore(&phba->hbalock, iflag);
2570 phba->lpfc_rampdown_queue_depth(phba);
2571 spin_lock_irqsave(&phba->hbalock, iflag);
2574 /* Rsp ring <ringno> error: IOCB */
2575 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2576 "0336 Rsp Ring %d error: IOCB Data: "
2577 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2579 irsp->un.ulpWord[0],
2580 irsp->un.ulpWord[1],
2581 irsp->un.ulpWord[2],
2582 irsp->un.ulpWord[3],
2583 irsp->un.ulpWord[4],
2584 irsp->un.ulpWord[5],
2585 *(uint32_t *)&irsp->un1,
2586 *((uint32_t *)&irsp->un1 + 1));
2590 case LPFC_ABORT_IOCB:
2593 * Idle exchange closed via ABTS from port. No iocb
2594 * resources need to be recovered.
2596 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2597 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2598 "0333 IOCB cmd 0x%x"
2599 " processed. Skipping"
2605 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2607 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
2608 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
2609 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2612 spin_unlock_irqrestore(&phba->hbalock,
2614 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2616 spin_lock_irqsave(&phba->hbalock,
2621 case LPFC_UNSOL_IOCB:
2622 spin_unlock_irqrestore(&phba->hbalock, iflag);
2623 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
2624 spin_lock_irqsave(&phba->hbalock, iflag);
2627 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2628 char adaptermsg[LPFC_MAX_ADPTMSG];
2629 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2630 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2632 dev_warn(&((phba->pcidev)->dev),
2634 phba->brd_no, adaptermsg);
2636 /* Unknown IOCB command */
2637 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2638 "0334 Unknown IOCB command "
2639 "Data: x%x, x%x x%x x%x x%x\n",
2640 type, irsp->ulpCommand,
2649 * The response IOCB has been processed. Update the ring
2650 * pointer in SLIM. If the port response put pointer has not
2651 * been updated, sync the pgp->rspPutInx and fetch the new port
2652 * response put pointer.
2654 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2656 if (pring->rspidx == portRspPut)
2657 portRspPut = le32_to_cpu(pgp->rspPutInx);
2660 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
2661 pring->stats.iocb_rsp_full++;
2662 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2663 writel(status, phba->CAregaddr);
2664 readl(phba->CAregaddr);
2666 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2667 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2668 pring->stats.iocb_cmd_empty++;
2670 /* Force update of the local copy of cmdGetInx */
2671 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2672 lpfc_sli_resume_iocb(phba, pring);
2674 if ((pring->lpfc_sli_cmd_available))
2675 (pring->lpfc_sli_cmd_available) (phba, pring);
2679 spin_unlock_irqrestore(&phba->hbalock, iflag);
2684 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
2685 * @phba: Pointer to HBA context object.
2686 * @pring: Pointer to driver SLI ring object.
2687 * @rspiocbp: Pointer to driver response IOCB object.
2689 * This function is called from the worker thread when there is a slow-path
2690 * response IOCB to process. This function chains all the response iocbs until
2691 * seeing the iocb with the LE bit set. The function will call
2692 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
2693 * completion of a command iocb. The function will call the
2694 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
2695 * The function frees the resources or calls the completion handler if this
2696 * iocb is an abort completion. The function returns NULL when the response
2697 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
2698 * this function shall chain the iocb on to the iocb_continueq and return the
2699 * response iocb passed in.
2701 static struct lpfc_iocbq *
2702 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2703 struct lpfc_iocbq *rspiocbp)
2705 struct lpfc_iocbq *saveq;
2706 struct lpfc_iocbq *cmdiocbp;
2707 struct lpfc_iocbq *next_iocb;
2708 IOCB_t *irsp = NULL;
2709 uint32_t free_saveq;
2710 uint8_t iocb_cmd_type;
2711 lpfc_iocb_type type;
2712 unsigned long iflag;
2715 spin_lock_irqsave(&phba->hbalock, iflag);
2716 /* First add the response iocb to the countinueq list */
2717 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
2718 pring->iocb_continueq_cnt++;
2720 /* Now, determine whetehr the list is completed for processing */
2721 irsp = &rspiocbp->iocb;
2724 * By default, the driver expects to free all resources
2725 * associated with this iocb completion.
2728 saveq = list_get_first(&pring->iocb_continueq,
2729 struct lpfc_iocbq, list);
2730 irsp = &(saveq->iocb);
2731 list_del_init(&pring->iocb_continueq);
2732 pring->iocb_continueq_cnt = 0;
2734 pring->stats.iocb_rsp++;
2737 * If resource errors reported from HBA, reduce
2738 * queuedepths of the SCSI device.
2740 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2741 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2742 spin_unlock_irqrestore(&phba->hbalock, iflag);
2743 phba->lpfc_rampdown_queue_depth(phba);
2744 spin_lock_irqsave(&phba->hbalock, iflag);
2747 if (irsp->ulpStatus) {
2748 /* Rsp ring <ringno> error: IOCB */
2749 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2750 "0328 Rsp Ring %d error: "
2755 "x%x x%x x%x x%x\n",
2757 irsp->un.ulpWord[0],
2758 irsp->un.ulpWord[1],
2759 irsp->un.ulpWord[2],
2760 irsp->un.ulpWord[3],
2761 irsp->un.ulpWord[4],
2762 irsp->un.ulpWord[5],
2763 *(((uint32_t *) irsp) + 6),
2764 *(((uint32_t *) irsp) + 7),
2765 *(((uint32_t *) irsp) + 8),
2766 *(((uint32_t *) irsp) + 9),
2767 *(((uint32_t *) irsp) + 10),
2768 *(((uint32_t *) irsp) + 11),
2769 *(((uint32_t *) irsp) + 12),
2770 *(((uint32_t *) irsp) + 13),
2771 *(((uint32_t *) irsp) + 14),
2772 *(((uint32_t *) irsp) + 15));
2776 * Fetch the IOCB command type and call the correct completion
2777 * routine. Solicited and Unsolicited IOCBs on the ELS ring
2778 * get freed back to the lpfc_iocb_list by the discovery
2781 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
2782 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
2785 spin_unlock_irqrestore(&phba->hbalock, iflag);
2786 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
2787 spin_lock_irqsave(&phba->hbalock, iflag);
2790 case LPFC_UNSOL_IOCB:
2791 spin_unlock_irqrestore(&phba->hbalock, iflag);
2792 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
2793 spin_lock_irqsave(&phba->hbalock, iflag);
2798 case LPFC_ABORT_IOCB:
2800 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
2801 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
2804 /* Call the specified completion routine */
2805 if (cmdiocbp->iocb_cmpl) {
2806 spin_unlock_irqrestore(&phba->hbalock,
2808 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
2810 spin_lock_irqsave(&phba->hbalock,
2813 __lpfc_sli_release_iocbq(phba,
2818 case LPFC_UNKNOWN_IOCB:
2819 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2820 char adaptermsg[LPFC_MAX_ADPTMSG];
2821 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2822 memcpy(&adaptermsg[0], (uint8_t *)irsp,
2824 dev_warn(&((phba->pcidev)->dev),
2826 phba->brd_no, adaptermsg);
2828 /* Unknown IOCB command */
2829 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2830 "0335 Unknown IOCB "
2831 "command Data: x%x "
2842 list_for_each_entry_safe(rspiocbp, next_iocb,
2843 &saveq->list, list) {
2844 list_del(&rspiocbp->list);
2845 __lpfc_sli_release_iocbq(phba, rspiocbp);
2847 __lpfc_sli_release_iocbq(phba, saveq);
2851 spin_unlock_irqrestore(&phba->hbalock, iflag);
2856 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
2857 * @phba: Pointer to HBA context object.
2858 * @pring: Pointer to driver SLI ring object.
2859 * @mask: Host attention register mask for this ring.
2861 * This routine wraps the actual slow_ring event process routine from the
2862 * API jump table function pointer from the lpfc_hba struct.
2865 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
2866 struct lpfc_sli_ring *pring, uint32_t mask)
2868 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
2872 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
2873 * @phba: Pointer to HBA context object.
2874 * @pring: Pointer to driver SLI ring object.
2875 * @mask: Host attention register mask for this ring.
2877 * This function is called from the worker thread when there is a ring event
2878 * for non-fcp rings. The caller does not hold any lock. The function will
2879 * remove each response iocb in the response ring and calls the handle
2880 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2883 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
2884 struct lpfc_sli_ring *pring, uint32_t mask)
2886 struct lpfc_pgp *pgp;
2888 IOCB_t *irsp = NULL;
2889 struct lpfc_iocbq *rspiocbp = NULL;
2890 uint32_t portRspPut, portRspMax;
2891 unsigned long iflag;
2894 pgp = &phba->port_gp[pring->ringno];
2895 spin_lock_irqsave(&phba->hbalock, iflag);
2896 pring->stats.iocb_event++;
2899 * The next available response entry should never exceed the maximum
2900 * entries. If it does, treat it as an adapter hardware error.
2902 portRspMax = pring->numRiocb;
2903 portRspPut = le32_to_cpu(pgp->rspPutInx);
2904 if (portRspPut >= portRspMax) {
2906 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2907 * rsp ring <portRspMax>
2909 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2910 "0303 Ring %d handler: portRspPut %d "
2911 "is bigger than rsp ring %d\n",
2912 pring->ringno, portRspPut, portRspMax);
2914 phba->link_state = LPFC_HBA_ERROR;
2915 spin_unlock_irqrestore(&phba->hbalock, iflag);
2917 phba->work_hs = HS_FFER3;
2918 lpfc_handle_eratt(phba);
2924 while (pring->rspidx != portRspPut) {
2926 * Build a completion list and call the appropriate handler.
2927 * The process is to get the next available response iocb, get
2928 * a free iocb from the list, copy the response data into the
2929 * free iocb, insert to the continuation list, and update the
2930 * next response index to slim. This process makes response
2931 * iocb's in the ring available to DMA as fast as possible but
2932 * pays a penalty for a copy operation. Since the iocb is
2933 * only 32 bytes, this penalty is considered small relative to
2934 * the PCI reads for register values and a slim write. When
2935 * the ulpLe field is set, the entire Command has been
2938 entry = lpfc_resp_iocb(phba, pring);
2940 phba->last_completion_time = jiffies;
2941 rspiocbp = __lpfc_sli_get_iocbq(phba);
2942 if (rspiocbp == NULL) {
2943 printk(KERN_ERR "%s: out of buffers! Failing "
2944 "completion.\n", __func__);
2948 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
2949 phba->iocb_rsp_size);
2950 irsp = &rspiocbp->iocb;
2952 if (++pring->rspidx >= portRspMax)
2955 if (pring->ringno == LPFC_ELS_RING) {
2956 lpfc_debugfs_slow_ring_trc(phba,
2957 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2958 *(((uint32_t *) irsp) + 4),
2959 *(((uint32_t *) irsp) + 6),
2960 *(((uint32_t *) irsp) + 7));
2963 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2965 spin_unlock_irqrestore(&phba->hbalock, iflag);
2966 /* Handle the response IOCB */
2967 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
2968 spin_lock_irqsave(&phba->hbalock, iflag);
2971 * If the port response put pointer has not been updated, sync
2972 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
2973 * response put pointer.
2975 if (pring->rspidx == portRspPut) {
2976 portRspPut = le32_to_cpu(pgp->rspPutInx);
2978 } /* while (pring->rspidx != portRspPut) */
2980 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
2981 /* At least one response entry has been freed */
2982 pring->stats.iocb_rsp_full++;
2983 /* SET RxRE_RSP in Chip Att register */
2984 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2985 writel(status, phba->CAregaddr);
2986 readl(phba->CAregaddr); /* flush */
2988 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2989 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2990 pring->stats.iocb_cmd_empty++;
2992 /* Force update of the local copy of cmdGetInx */
2993 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2994 lpfc_sli_resume_iocb(phba, pring);
2996 if ((pring->lpfc_sli_cmd_available))
2997 (pring->lpfc_sli_cmd_available) (phba, pring);
3001 spin_unlock_irqrestore(&phba->hbalock, iflag);
3006 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3007 * @phba: Pointer to HBA context object.
3008 * @pring: Pointer to driver SLI ring object.
3009 * @mask: Host attention register mask for this ring.
3011 * This function is called from the worker thread when there is a pending
3012 * ELS response iocb on the driver internal slow-path response iocb worker
3013 * queue. The caller does not hold any lock. The function will remove each
3014 * response iocb from the response worker queue and calls the handle
3015 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3018 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3019 struct lpfc_sli_ring *pring, uint32_t mask)
3021 struct lpfc_iocbq *irspiocbq;
3022 unsigned long iflag;
3024 while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) {
3025 /* Get the response iocb from the head of work queue */
3026 spin_lock_irqsave(&phba->hbalock, iflag);
3027 list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue,
3028 irspiocbq, struct lpfc_iocbq, list);
3029 spin_unlock_irqrestore(&phba->hbalock, iflag);
3030 /* Process the response iocb */
3031 lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq);
3036 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3037 * @phba: Pointer to HBA context object.
3038 * @pring: Pointer to driver SLI ring object.
3040 * This function aborts all iocbs in the given ring and frees all the iocb
3041 * objects in txq. This function issues an abort iocb for all the iocb commands
3042 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3043 * the return of this function. The caller is not required to hold any locks.
3046 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3048 LIST_HEAD(completions);
3049 struct lpfc_iocbq *iocb, *next_iocb;
3051 if (pring->ringno == LPFC_ELS_RING) {
3052 lpfc_fabric_abort_hba(phba);
3055 /* Error everything on txq and txcmplq
3058 spin_lock_irq(&phba->hbalock);
3059 list_splice_init(&pring->txq, &completions);
3062 /* Next issue ABTS for everything on the txcmplq */
3063 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3064 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3066 spin_unlock_irq(&phba->hbalock);
3068 /* Cancel all the IOCBs from the completions list */
3069 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3074 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3075 * @phba: Pointer to HBA context object.
3077 * This function flushes all iocbs in the fcp ring and frees all the iocb
3078 * objects in txq and txcmplq. This function will not issue abort iocbs
3079 * for all the iocb commands in txcmplq, they will just be returned with
3080 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3081 * slot has been permanently disabled.
3084 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3088 struct lpfc_sli *psli = &phba->sli;
3089 struct lpfc_sli_ring *pring;
3091 /* Currently, only one fcp ring */
3092 pring = &psli->ring[psli->fcp_ring];
3094 spin_lock_irq(&phba->hbalock);
3095 /* Retrieve everything on txq */
3096 list_splice_init(&pring->txq, &txq);
3099 /* Retrieve everything on the txcmplq */
3100 list_splice_init(&pring->txcmplq, &txcmplq);
3101 pring->txcmplq_cnt = 0;
3102 spin_unlock_irq(&phba->hbalock);
3105 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3108 /* Flush the txcmpq */
3109 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3114 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3115 * @phba: Pointer to HBA context object.
3116 * @mask: Bit mask to be checked.
3118 * This function reads the host status register and compares
3119 * with the provided bit mask to check if HBA completed
3120 * the restart. This function will wait in a loop for the
3121 * HBA to complete restart. If the HBA does not restart within
3122 * 15 iterations, the function will reset the HBA again. The
3123 * function returns 1 when HBA fail to restart otherwise returns
3127 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
3133 /* Read the HBA Host Status Register */
3134 status = readl(phba->HSregaddr);
3137 * Check status register every 100ms for 5 retries, then every
3138 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3139 * every 2.5 sec for 4.
3140 * Break our of the loop if errors occurred during init.
3142 while (((status & mask) != mask) &&
3143 !(status & HS_FFERM) &&
3155 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3156 lpfc_sli_brdrestart(phba);
3158 /* Read the HBA Host Status Register */
3159 status = readl(phba->HSregaddr);
3162 /* Check to see if any errors occurred during init */
3163 if ((status & HS_FFERM) || (i >= 20)) {
3164 phba->link_state = LPFC_HBA_ERROR;
3172 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3173 * @phba: Pointer to HBA context object.
3174 * @mask: Bit mask to be checked.
3176 * This function checks the host status register to check if HBA is
3177 * ready. This function will wait in a loop for the HBA to be ready
3178 * If the HBA is not ready , the function will will reset the HBA PCI
3179 * function again. The function returns 1 when HBA fail to be ready
3180 * otherwise returns zero.
3183 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3188 /* Read the HBA Host Status Register */
3189 status = lpfc_sli4_post_status_check(phba);
3192 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3193 lpfc_sli_brdrestart(phba);
3194 status = lpfc_sli4_post_status_check(phba);
3197 /* Check to see if any errors occurred during init */
3199 phba->link_state = LPFC_HBA_ERROR;
3202 phba->sli4_hba.intr_enable = 0;
3208 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3209 * @phba: Pointer to HBA context object.
3210 * @mask: Bit mask to be checked.
3212 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3213 * from the API jump table function pointer from the lpfc_hba struct.
3216 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3218 return phba->lpfc_sli_brdready(phba, mask);
3221 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3224 * lpfc_reset_barrier - Make HBA ready for HBA reset
3225 * @phba: Pointer to HBA context object.
3227 * This function is called before resetting an HBA. This
3228 * function requests HBA to quiesce DMAs before a reset.
3230 void lpfc_reset_barrier(struct lpfc_hba *phba)
3232 uint32_t __iomem *resp_buf;
3233 uint32_t __iomem *mbox_buf;
3234 volatile uint32_t mbox;
3239 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3240 if (hdrtype != 0x80 ||
3241 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3242 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3246 * Tell the other part of the chip to suspend temporarily all
3249 resp_buf = phba->MBslimaddr;
3251 /* Disable the error attention */
3252 hc_copy = readl(phba->HCregaddr);
3253 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3254 readl(phba->HCregaddr); /* flush */
3255 phba->link_flag |= LS_IGNORE_ERATT;
3257 if (readl(phba->HAregaddr) & HA_ERATT) {
3258 /* Clear Chip error bit */
3259 writel(HA_ERATT, phba->HAregaddr);
3260 phba->pport->stopped = 1;
3264 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
3265 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
3267 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
3268 mbox_buf = phba->MBslimaddr;
3269 writel(mbox, mbox_buf);
3272 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
3275 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
3276 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
3277 phba->pport->stopped)
3283 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
3284 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
3289 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
3292 if (readl(phba->HAregaddr) & HA_ERATT) {
3293 writel(HA_ERATT, phba->HAregaddr);
3294 phba->pport->stopped = 1;
3298 phba->link_flag &= ~LS_IGNORE_ERATT;
3299 writel(hc_copy, phba->HCregaddr);
3300 readl(phba->HCregaddr); /* flush */
3304 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3305 * @phba: Pointer to HBA context object.
3307 * This function issues a kill_board mailbox command and waits for
3308 * the error attention interrupt. This function is called for stopping
3309 * the firmware processing. The caller is not required to hold any
3310 * locks. This function calls lpfc_hba_down_post function to free
3311 * any pending commands after the kill. The function will return 1 when it
3312 * fails to kill the board else will return 0.
3315 lpfc_sli_brdkill(struct lpfc_hba *phba)
3317 struct lpfc_sli *psli;
3327 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3328 "0329 Kill HBA Data: x%x x%x\n",
3329 phba->pport->port_state, psli->sli_flag);
3331 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3335 /* Disable the error attention */
3336 spin_lock_irq(&phba->hbalock);
3337 status = readl(phba->HCregaddr);
3338 status &= ~HC_ERINT_ENA;
3339 writel(status, phba->HCregaddr);
3340 readl(phba->HCregaddr); /* flush */
3341 phba->link_flag |= LS_IGNORE_ERATT;
3342 spin_unlock_irq(&phba->hbalock);
3344 lpfc_kill_board(phba, pmb);
3345 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3346 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3348 if (retval != MBX_SUCCESS) {
3349 if (retval != MBX_BUSY)
3350 mempool_free(pmb, phba->mbox_mem_pool);
3351 spin_lock_irq(&phba->hbalock);
3352 phba->link_flag &= ~LS_IGNORE_ERATT;
3353 spin_unlock_irq(&phba->hbalock);
3357 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
3359 mempool_free(pmb, phba->mbox_mem_pool);
3361 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3362 * attention every 100ms for 3 seconds. If we don't get ERATT after
3363 * 3 seconds we still set HBA_ERROR state because the status of the
3364 * board is now undefined.
3366 ha_copy = readl(phba->HAregaddr);
3368 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
3370 ha_copy = readl(phba->HAregaddr);
3373 del_timer_sync(&psli->mbox_tmo);
3374 if (ha_copy & HA_ERATT) {
3375 writel(HA_ERATT, phba->HAregaddr);
3376 phba->pport->stopped = 1;
3378 spin_lock_irq(&phba->hbalock);
3379 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3380 phba->link_flag &= ~LS_IGNORE_ERATT;
3381 spin_unlock_irq(&phba->hbalock);
3383 psli->mbox_active = NULL;
3384 lpfc_hba_down_post(phba);
3385 phba->link_state = LPFC_HBA_ERROR;
3387 return ha_copy & HA_ERATT ? 0 : 1;
3391 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3392 * @phba: Pointer to HBA context object.
3394 * This function resets the HBA by writing HC_INITFF to the control
3395 * register. After the HBA resets, this function resets all the iocb ring
3396 * indices. This function disables PCI layer parity checking during
3398 * This function returns 0 always.
3399 * The caller is not required to hold any locks.
3402 lpfc_sli_brdreset(struct lpfc_hba *phba)
3404 struct lpfc_sli *psli;
3405 struct lpfc_sli_ring *pring;
3412 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3413 "0325 Reset HBA Data: x%x x%x\n",
3414 phba->pport->port_state, psli->sli_flag);
3416 /* perform board reset */
3417 phba->fc_eventTag = 0;
3418 phba->pport->fc_myDID = 0;
3419 phba->pport->fc_prevDID = 0;
3421 /* Turn off parity checking and serr during the physical reset */
3422 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3423 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3425 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3427 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
3429 /* Now toggle INITFF bit in the Host Control Register */
3430 writel(HC_INITFF, phba->HCregaddr);
3432 readl(phba->HCregaddr); /* flush */
3433 writel(0, phba->HCregaddr);
3434 readl(phba->HCregaddr); /* flush */
3436 /* Restore PCI cmd register */
3437 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3439 /* Initialize relevant SLI info */
3440 for (i = 0; i < psli->num_rings; i++) {
3441 pring = &psli->ring[i];
3444 pring->next_cmdidx = 0;
3445 pring->local_getidx = 0;
3447 pring->missbufcnt = 0;
3450 phba->link_state = LPFC_WARM_START;
3455 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3456 * @phba: Pointer to HBA context object.
3458 * This function resets a SLI4 HBA. This function disables PCI layer parity
3459 * checking during resets the device. The caller is not required to hold
3462 * This function returns 0 always.
3465 lpfc_sli4_brdreset(struct lpfc_hba *phba)
3467 struct lpfc_sli *psli = &phba->sli;
3472 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3473 "0295 Reset HBA Data: x%x x%x\n",
3474 phba->pport->port_state, psli->sli_flag);
3476 /* perform board reset */
3477 phba->fc_eventTag = 0;
3478 phba->pport->fc_myDID = 0;
3479 phba->pport->fc_prevDID = 0;
3481 /* Turn off parity checking and serr during the physical reset */
3482 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3483 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3485 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3487 spin_lock_irq(&phba->hbalock);
3488 psli->sli_flag &= ~(LPFC_PROCESS_LA);
3489 phba->fcf.fcf_flag = 0;
3490 /* Clean up the child queue list for the CQs */
3491 list_del_init(&phba->sli4_hba.mbx_wq->list);
3492 list_del_init(&phba->sli4_hba.els_wq->list);
3493 list_del_init(&phba->sli4_hba.hdr_rq->list);
3494 list_del_init(&phba->sli4_hba.dat_rq->list);
3495 list_del_init(&phba->sli4_hba.mbx_cq->list);
3496 list_del_init(&phba->sli4_hba.els_cq->list);
3497 list_del_init(&phba->sli4_hba.rxq_cq->list);
3498 for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
3499 list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
3500 for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
3501 list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
3502 spin_unlock_irq(&phba->hbalock);
3504 /* Now physically reset the device */
3505 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3506 "0389 Performing PCI function reset!\n");
3507 /* Perform FCoE PCI function reset */
3508 lpfc_pci_function_reset(phba);
3514 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3515 * @phba: Pointer to HBA context object.
3517 * This function is called in the SLI initialization code path to
3518 * restart the HBA. The caller is not required to hold any lock.
3519 * This function writes MBX_RESTART mailbox command to the SLIM and
3520 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3521 * function to free any pending commands. The function enables
3522 * POST only during the first initialization. The function returns zero.
3523 * The function does not guarantee completion of MBX_RESTART mailbox
3524 * command before the return of this function.
3527 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
3530 struct lpfc_sli *psli;
3531 volatile uint32_t word0;
3532 void __iomem *to_slim;
3534 spin_lock_irq(&phba->hbalock);
3539 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3540 "0337 Restart HBA Data: x%x x%x\n",
3541 phba->pport->port_state, psli->sli_flag);
3544 mb = (MAILBOX_t *) &word0;
3545 mb->mbxCommand = MBX_RESTART;
3548 lpfc_reset_barrier(phba);
3550 to_slim = phba->MBslimaddr;
3551 writel(*(uint32_t *) mb, to_slim);
3552 readl(to_slim); /* flush */
3554 /* Only skip post after fc_ffinit is completed */
3555 if (phba->pport->port_state)
3556 word0 = 1; /* This is really setting up word1 */
3558 word0 = 0; /* This is really setting up word1 */
3559 to_slim = phba->MBslimaddr + sizeof (uint32_t);
3560 writel(*(uint32_t *) mb, to_slim);
3561 readl(to_slim); /* flush */
3563 lpfc_sli_brdreset(phba);
3564 phba->pport->stopped = 0;
3565 phba->link_state = LPFC_INIT_START;
3567 spin_unlock_irq(&phba->hbalock);
3569 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3570 psli->stats_start = get_seconds();
3572 /* Give the INITFF and Post time to settle. */
3575 lpfc_hba_down_post(phba);
3581 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3582 * @phba: Pointer to HBA context object.
3584 * This function is called in the SLI initialization code path to restart
3585 * a SLI4 HBA. The caller is not required to hold any lock.
3586 * At the end of the function, it calls lpfc_hba_down_post function to
3587 * free any pending commands.
3590 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
3592 struct lpfc_sli *psli = &phba->sli;
3596 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3597 "0296 Restart HBA Data: x%x x%x\n",
3598 phba->pport->port_state, psli->sli_flag);
3600 lpfc_sli4_brdreset(phba);
3602 spin_lock_irq(&phba->hbalock);
3603 phba->pport->stopped = 0;
3604 phba->link_state = LPFC_INIT_START;
3606 spin_unlock_irq(&phba->hbalock);
3608 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3609 psli->stats_start = get_seconds();
3611 lpfc_hba_down_post(phba);
3617 * lpfc_sli_brdrestart - Wrapper func for restarting hba
3618 * @phba: Pointer to HBA context object.
3620 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
3621 * API jump table function pointer from the lpfc_hba struct.
3624 lpfc_sli_brdrestart(struct lpfc_hba *phba)
3626 return phba->lpfc_sli_brdrestart(phba);
3630 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
3631 * @phba: Pointer to HBA context object.
3633 * This function is called after a HBA restart to wait for successful
3634 * restart of the HBA. Successful restart of the HBA is indicated by
3635 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
3636 * iteration, the function will restart the HBA again. The function returns
3637 * zero if HBA successfully restarted else returns negative error code.
3640 lpfc_sli_chipset_init(struct lpfc_hba *phba)
3642 uint32_t status, i = 0;
3644 /* Read the HBA Host Status Register */
3645 status = readl(phba->HSregaddr);
3647 /* Check status register to see what current state is */
3649 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
3651 /* Check every 100ms for 5 retries, then every 500ms for 5, then
3652 * every 2.5 sec for 5, then reset board and every 2.5 sec for
3656 /* Adapter failed to init, timeout, status reg
3658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3659 "0436 Adapter failed to init, "
3660 "timeout, status reg x%x, "
3661 "FW Data: A8 x%x AC x%x\n", status,
3662 readl(phba->MBslimaddr + 0xa8),
3663 readl(phba->MBslimaddr + 0xac));
3664 phba->link_state = LPFC_HBA_ERROR;
3668 /* Check to see if any errors occurred during init */
3669 if (status & HS_FFERM) {
3670 /* ERROR: During chipset initialization */
3671 /* Adapter failed to init, chipset, status reg
3673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3674 "0437 Adapter failed to init, "
3675 "chipset, status reg x%x, "
3676 "FW Data: A8 x%x AC x%x\n", status,
3677 readl(phba->MBslimaddr + 0xa8),
3678 readl(phba->MBslimaddr + 0xac));
3679 phba->link_state = LPFC_HBA_ERROR;
3685 } else if (i <= 10) {
3693 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3694 lpfc_sli_brdrestart(phba);
3696 /* Read the HBA Host Status Register */
3697 status = readl(phba->HSregaddr);
3700 /* Check to see if any errors occurred during init */
3701 if (status & HS_FFERM) {
3702 /* ERROR: During chipset initialization */
3703 /* Adapter failed to init, chipset, status reg <status> */
3704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3705 "0438 Adapter failed to init, chipset, "
3707 "FW Data: A8 x%x AC x%x\n", status,
3708 readl(phba->MBslimaddr + 0xa8),
3709 readl(phba->MBslimaddr + 0xac));
3710 phba->link_state = LPFC_HBA_ERROR;
3714 /* Clear all interrupt enable conditions */
3715 writel(0, phba->HCregaddr);
3716 readl(phba->HCregaddr); /* flush */
3718 /* setup host attn register */
3719 writel(0xffffffff, phba->HAregaddr);
3720 readl(phba->HAregaddr); /* flush */
3725 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
3727 * This function calculates and returns the number of HBQs required to be
3731 lpfc_sli_hbq_count(void)
3733 return ARRAY_SIZE(lpfc_hbq_defs);
3737 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
3739 * This function adds the number of hbq entries in every HBQ to get
3740 * the total number of hbq entries required for the HBA and returns
3744 lpfc_sli_hbq_entry_count(void)
3746 int hbq_count = lpfc_sli_hbq_count();
3750 for (i = 0; i < hbq_count; ++i)
3751 count += lpfc_hbq_defs[i]->entry_count;
3756 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
3758 * This function calculates amount of memory required for all hbq entries
3759 * to be configured and returns the total memory required.
3762 lpfc_sli_hbq_size(void)
3764 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
3768 * lpfc_sli_hbq_setup - configure and initialize HBQs
3769 * @phba: Pointer to HBA context object.
3771 * This function is called during the SLI initialization to configure
3772 * all the HBQs and post buffers to the HBQ. The caller is not
3773 * required to hold any locks. This function will return zero if successful
3774 * else it will return negative error code.
3777 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
3779 int hbq_count = lpfc_sli_hbq_count();
3783 uint32_t hbq_entry_index;
3785 /* Get a Mailbox buffer to setup mailbox
3786 * commands for HBA initialization
3788 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3795 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
3796 phba->link_state = LPFC_INIT_MBX_CMDS;
3797 phba->hbq_in_use = 1;
3799 hbq_entry_index = 0;
3800 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
3801 phba->hbqs[hbqno].next_hbqPutIdx = 0;
3802 phba->hbqs[hbqno].hbqPutIdx = 0;
3803 phba->hbqs[hbqno].local_hbqGetIdx = 0;
3804 phba->hbqs[hbqno].entry_count =
3805 lpfc_hbq_defs[hbqno]->entry_count;
3806 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
3807 hbq_entry_index, pmb);
3808 hbq_entry_index += phba->hbqs[hbqno].entry_count;
3810 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
3811 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
3812 mbxStatus <status>, ring <num> */
3814 lpfc_printf_log(phba, KERN_ERR,
3815 LOG_SLI | LOG_VPORT,
3816 "1805 Adapter failed to init. "
3817 "Data: x%x x%x x%x\n",
3819 pmbox->mbxStatus, hbqno);
3821 phba->link_state = LPFC_HBA_ERROR;
3822 mempool_free(pmb, phba->mbox_mem_pool);
3826 phba->hbq_count = hbq_count;
3828 mempool_free(pmb, phba->mbox_mem_pool);
3830 /* Initially populate or replenish the HBQs */
3831 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
3832 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
3837 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
3838 * @phba: Pointer to HBA context object.
3840 * This function is called during the SLI initialization to configure
3841 * all the HBQs and post buffers to the HBQ. The caller is not
3842 * required to hold any locks. This function will return zero if successful
3843 * else it will return negative error code.
3846 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
3848 phba->hbq_in_use = 1;
3849 phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
3850 phba->hbq_count = 1;
3851 /* Initially populate or replenish the HBQs */
3852 lpfc_sli_hbqbuf_init_hbqs(phba, 0);
3857 * lpfc_sli_config_port - Issue config port mailbox command
3858 * @phba: Pointer to HBA context object.
3859 * @sli_mode: sli mode - 2/3
3861 * This function is called by the sli intialization code path
3862 * to issue config_port mailbox command. This function restarts the
3863 * HBA firmware and issues a config_port mailbox command to configure
3864 * the SLI interface in the sli mode specified by sli_mode
3865 * variable. The caller is not required to hold any locks.
3866 * The function returns 0 if successful, else returns negative error
3870 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
3873 uint32_t resetcount = 0, rc = 0, done = 0;
3875 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3877 phba->link_state = LPFC_HBA_ERROR;
3881 phba->sli_rev = sli_mode;
3882 while (resetcount < 2 && !done) {
3883 spin_lock_irq(&phba->hbalock);
3884 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
3885 spin_unlock_irq(&phba->hbalock);
3886 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3887 lpfc_sli_brdrestart(phba);
3888 rc = lpfc_sli_chipset_init(phba);
3892 spin_lock_irq(&phba->hbalock);
3893 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3894 spin_unlock_irq(&phba->hbalock);
3897 /* Call pre CONFIG_PORT mailbox command initialization. A
3898 * value of 0 means the call was successful. Any other
3899 * nonzero value is a failure, but if ERESTART is returned,
3900 * the driver may reset the HBA and try again.
3902 rc = lpfc_config_port_prep(phba);
3903 if (rc == -ERESTART) {
3904 phba->link_state = LPFC_LINK_UNKNOWN;
3908 phba->link_state = LPFC_INIT_MBX_CMDS;
3909 lpfc_config_port(phba, pmb);
3910 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
3911 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
3912 LPFC_SLI3_HBQ_ENABLED |
3913 LPFC_SLI3_CRP_ENABLED |
3914 LPFC_SLI3_INB_ENABLED |
3915 LPFC_SLI3_BG_ENABLED);
3916 if (rc != MBX_SUCCESS) {
3917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3918 "0442 Adapter failed to init, mbxCmd x%x "
3919 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3920 pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
3921 spin_lock_irq(&phba->hbalock);
3922 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
3923 spin_unlock_irq(&phba->hbalock);
3930 goto do_prep_failed;
3932 if (pmb->mb.un.varCfgPort.sli_mode == 3) {
3933 if (!pmb->mb.un.varCfgPort.cMA) {
3935 goto do_prep_failed;
3937 if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) {
3938 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3939 phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi;
3942 if (pmb->mb.un.varCfgPort.gerbm)
3943 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
3944 if (pmb->mb.un.varCfgPort.gcrp)
3945 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
3946 if (pmb->mb.un.varCfgPort.ginb) {
3947 phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
3948 phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
3949 phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
3950 phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
3951 phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
3952 phba->inb_last_counter =
3953 phba->mbox->us.s3_inb_pgp.counter;
3955 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
3956 phba->port_gp = phba->mbox->us.s3_pgp.port;
3957 phba->inb_ha_copy = NULL;
3958 phba->inb_counter = NULL;
3961 if (phba->cfg_enable_bg) {
3962 if (pmb->mb.un.varCfgPort.gbg)
3963 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
3965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3966 "0443 Adapter did not grant "
3970 phba->hbq_get = NULL;
3971 phba->port_gp = phba->mbox->us.s2.port;
3972 phba->inb_ha_copy = NULL;
3973 phba->inb_counter = NULL;
3977 mempool_free(pmb, phba->mbox_mem_pool);
3983 * lpfc_sli_hba_setup - SLI intialization function
3984 * @phba: Pointer to HBA context object.
3986 * This function is the main SLI intialization function. This function
3987 * is called by the HBA intialization code, HBA reset code and HBA
3988 * error attention handler code. Caller is not required to hold any
3989 * locks. This function issues config_port mailbox command to configure
3990 * the SLI, setup iocb rings and HBQ rings. In the end the function
3991 * calls the config_port_post function to issue init_link mailbox
3992 * command and to start the discovery. The function will return zero
3993 * if successful, else it will return negative error code.
3996 lpfc_sli_hba_setup(struct lpfc_hba *phba)
4001 switch (lpfc_sli_mode) {
4003 if (phba->cfg_enable_npiv) {
4004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4005 "1824 NPIV enabled: Override lpfc_sli_mode "
4006 "parameter (%d) to auto (0).\n",
4016 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4017 "1819 Unrecognized lpfc_sli_mode "
4018 "parameter: %d.\n", lpfc_sli_mode);
4023 rc = lpfc_sli_config_port(phba, mode);
4025 if (rc && lpfc_sli_mode == 3)
4026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4027 "1820 Unable to select SLI-3. "
4028 "Not supported by adapter.\n");
4029 if (rc && mode != 2)
4030 rc = lpfc_sli_config_port(phba, 2);
4032 goto lpfc_sli_hba_setup_error;
4034 if (phba->sli_rev == 3) {
4035 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4036 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
4038 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4039 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
4040 phba->sli3_options = 0;
4043 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4044 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4045 phba->sli_rev, phba->max_vpi);
4046 rc = lpfc_sli_ring_map(phba);
4049 goto lpfc_sli_hba_setup_error;
4052 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4053 rc = lpfc_sli_hbq_setup(phba);
4055 goto lpfc_sli_hba_setup_error;
4058 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4060 rc = lpfc_config_port_post(phba);
4062 goto lpfc_sli_hba_setup_error;
4066 lpfc_sli_hba_setup_error:
4067 phba->link_state = LPFC_HBA_ERROR;
4068 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4069 "0445 Firmware initialization failed\n");
4074 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4075 * @phba: Pointer to HBA context object.
4076 * @mboxq: mailbox pointer.
4077 * This function issue a dump mailbox command to read config region
4078 * 23 and parse the records in the region and populate driver
4082 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
4083 LPFC_MBOXQ_t *mboxq)
4085 struct lpfc_dmabuf *mp;
4086 struct lpfc_mqe *mqe;
4087 uint32_t data_length;
4090 /* Program the default value of vlan_id and fc_map */
4091 phba->valid_vlan = 0;
4092 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4093 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4094 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4096 mqe = &mboxq->u.mqe;
4097 if (lpfc_dump_fcoe_param(phba, mboxq))
4100 mp = (struct lpfc_dmabuf *) mboxq->context1;
4101 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4103 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4104 "(%d):2571 Mailbox cmd x%x Status x%x "
4105 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4106 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4107 "CQ: x%x x%x x%x x%x\n",
4108 mboxq->vport ? mboxq->vport->vpi : 0,
4109 bf_get(lpfc_mqe_command, mqe),
4110 bf_get(lpfc_mqe_status, mqe),
4111 mqe->un.mb_words[0], mqe->un.mb_words[1],
4112 mqe->un.mb_words[2], mqe->un.mb_words[3],
4113 mqe->un.mb_words[4], mqe->un.mb_words[5],
4114 mqe->un.mb_words[6], mqe->un.mb_words[7],
4115 mqe->un.mb_words[8], mqe->un.mb_words[9],
4116 mqe->un.mb_words[10], mqe->un.mb_words[11],
4117 mqe->un.mb_words[12], mqe->un.mb_words[13],
4118 mqe->un.mb_words[14], mqe->un.mb_words[15],
4119 mqe->un.mb_words[16], mqe->un.mb_words[50],
4121 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4122 mboxq->mcqe.trailer);
4125 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4129 data_length = mqe->un.mb_words[5];
4130 if (data_length > DMP_FCOEPARAM_RGN_SIZE)
4133 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
4134 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4140 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4141 * @phba: pointer to lpfc hba data structure.
4142 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4143 * @vpd: pointer to the memory to hold resulting port vpd data.
4144 * @vpd_size: On input, the number of bytes allocated to @vpd.
4145 * On output, the number of data bytes in @vpd.
4147 * This routine executes a READ_REV SLI4 mailbox command. In
4148 * addition, this routine gets the port vpd data.
4152 * ENOMEM - could not allocated memory.
4155 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4156 uint8_t *vpd, uint32_t *vpd_size)
4160 struct lpfc_dmabuf *dmabuf;
4161 struct lpfc_mqe *mqe;
4163 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4168 * Get a DMA buffer for the vpd data resulting from the READ_REV
4171 dma_size = *vpd_size;
4172 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4176 if (!dmabuf->virt) {
4180 memset(dmabuf->virt, 0, dma_size);
4183 * The SLI4 implementation of READ_REV conflicts at word1,
4184 * bits 31:16 and SLI4 adds vpd functionality not present
4185 * in SLI3. This code corrects the conflicts.
4187 lpfc_read_rev(phba, mboxq);
4188 mqe = &mboxq->u.mqe;
4189 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
4190 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
4191 mqe->un.read_rev.word1 &= 0x0000FFFF;
4192 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
4193 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
4195 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4197 dma_free_coherent(&phba->pcidev->dev, dma_size,
4198 dmabuf->virt, dmabuf->phys);
4202 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4203 "(%d):0380 Mailbox cmd x%x Status x%x "
4204 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4205 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4206 "CQ: x%x x%x x%x x%x\n",
4207 mboxq->vport ? mboxq->vport->vpi : 0,
4208 bf_get(lpfc_mqe_command, mqe),
4209 bf_get(lpfc_mqe_status, mqe),
4210 mqe->un.mb_words[0], mqe->un.mb_words[1],
4211 mqe->un.mb_words[2], mqe->un.mb_words[3],
4212 mqe->un.mb_words[4], mqe->un.mb_words[5],
4213 mqe->un.mb_words[6], mqe->un.mb_words[7],
4214 mqe->un.mb_words[8], mqe->un.mb_words[9],
4215 mqe->un.mb_words[10], mqe->un.mb_words[11],
4216 mqe->un.mb_words[12], mqe->un.mb_words[13],
4217 mqe->un.mb_words[14], mqe->un.mb_words[15],
4218 mqe->un.mb_words[16], mqe->un.mb_words[50],
4220 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4221 mboxq->mcqe.trailer);
4224 * The available vpd length cannot be bigger than the
4225 * DMA buffer passed to the port. Catch the less than
4226 * case and update the caller's size.
4228 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
4229 *vpd_size = mqe->un.read_rev.avail_vpd_len;
4231 lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
4232 dma_free_coherent(&phba->pcidev->dev, dma_size,
4233 dmabuf->virt, dmabuf->phys);
4239 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4240 * @phba: pointer to lpfc hba data structure.
4242 * This routine is called to explicitly arm the SLI4 device's completion and
4246 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
4250 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
4251 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
4252 lpfc_sli4_cq_release(phba->sli4_hba.rxq_cq, LPFC_QUEUE_REARM);
4253 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4254 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
4256 lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
4257 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4258 lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
4263 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4264 * @phba: Pointer to HBA context object.
4266 * This function is the main SLI4 device intialization PCI function. This
4267 * function is called by the HBA intialization code, HBA reset code and
4268 * HBA error attention handler code. Caller is not required to hold any
4272 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
4275 LPFC_MBOXQ_t *mboxq;
4276 struct lpfc_mqe *mqe;
4279 uint32_t ftr_rsp = 0;
4280 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
4281 struct lpfc_vport *vport = phba->pport;
4282 struct lpfc_dmabuf *mp;
4284 /* Perform a PCI function reset to start from clean */
4285 rc = lpfc_pci_function_reset(phba);
4289 /* Check the HBA Host Status Register for readyness */
4290 rc = lpfc_sli4_post_status_check(phba);
4294 spin_lock_irq(&phba->hbalock);
4295 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
4296 spin_unlock_irq(&phba->hbalock);
4300 * Allocate a single mailbox container for initializing the
4303 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4308 * Continue initialization with default values even if driver failed
4309 * to read FCoE param config regions
4311 if (lpfc_sli4_read_fcoe_params(phba, mboxq))
4312 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
4313 "2570 Failed to read FCoE parameters \n");
4315 /* Issue READ_REV to collect vpd and FW information. */
4316 vpd_size = PAGE_SIZE;
4317 vpd = kzalloc(vpd_size, GFP_KERNEL);
4323 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
4327 mqe = &mboxq->u.mqe;
4328 if ((bf_get(lpfc_mbx_rd_rev_sli_lvl,
4329 &mqe->un.read_rev) != LPFC_SLI_REV4) ||
4330 (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev) == 0)) {
4331 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4332 "0376 READ_REV Error. SLI Level %d "
4333 "FCoE enabled %d\n",
4334 bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev),
4335 bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev));
4339 /* Single threaded at this point, no need for lock */
4340 spin_lock_irq(&phba->hbalock);
4341 phba->hba_flag |= HBA_FCOE_SUPPORT;
4342 spin_unlock_irq(&phba->hbalock);
4344 * Evaluate the read rev and vpd data. Populate the driver
4345 * state with the results. If this routine fails, the failure
4346 * is not fatal as the driver will use generic values.
4348 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
4349 if (unlikely(!rc)) {
4350 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4351 "0377 Error %d parsing vpd. "
4352 "Using defaults.\n", rc);
4356 /* By now, we should determine the SLI revision, hard code for now */
4357 phba->sli_rev = LPFC_SLI_REV4;
4360 * Discover the port's supported feature set and match it against the
4363 lpfc_request_features(phba, mboxq);
4364 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4371 * The port must support FCP initiator mode as this is the
4372 * only mode running in the host.
4374 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
4375 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4376 "0378 No support for fcpi mode.\n");
4381 * If the port cannot support the host's requested features
4382 * then turn off the global config parameters to disable the
4383 * feature in the driver. This is not a fatal error.
4385 if ((phba->cfg_enable_bg) &&
4386 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
4389 if (phba->max_vpi && phba->cfg_enable_npiv &&
4390 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
4394 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4395 "0379 Feature Mismatch Data: x%08x %08x "
4396 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
4397 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
4398 phba->cfg_enable_npiv, phba->max_vpi);
4399 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
4400 phba->cfg_enable_bg = 0;
4401 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
4402 phba->cfg_enable_npiv = 0;
4405 /* These SLI3 features are assumed in SLI4 */
4406 spin_lock_irq(&phba->hbalock);
4407 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
4408 spin_unlock_irq(&phba->hbalock);
4410 /* Read the port's service parameters. */
4411 lpfc_read_sparam(phba, mboxq, vport->vpi);
4412 mboxq->vport = vport;
4413 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4414 mp = (struct lpfc_dmabuf *) mboxq->context1;
4415 if (rc == MBX_SUCCESS) {
4416 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
4421 * This memory was allocated by the lpfc_read_sparam routine. Release
4422 * it to the mbuf pool.
4424 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4426 mboxq->context1 = NULL;
4428 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4429 "0382 READ_SPARAM command failed "
4430 "status %d, mbxStatus x%x\n",
4431 rc, bf_get(lpfc_mqe_status, mqe));
4432 phba->link_state = LPFC_HBA_ERROR;
4437 if (phba->cfg_soft_wwnn)
4438 u64_to_wwn(phba->cfg_soft_wwnn,
4439 vport->fc_sparam.nodeName.u.wwn);
4440 if (phba->cfg_soft_wwpn)
4441 u64_to_wwn(phba->cfg_soft_wwpn,
4442 vport->fc_sparam.portName.u.wwn);
4443 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
4444 sizeof(struct lpfc_name));
4445 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
4446 sizeof(struct lpfc_name));
4448 /* Update the fc_host data structures with new wwn. */
4449 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4450 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4452 /* Register SGL pool to the device using non-embedded mailbox command */
4453 rc = lpfc_sli4_post_sgl_list(phba);
4455 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4456 "0582 Error %d during sgl post operation", rc);
4461 /* Register SCSI SGL pool to the device */
4462 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
4464 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4465 "0383 Error %d during scsi sgl post opeation",
4467 /* Some Scsi buffers were moved to the abort scsi list */
4468 /* A pci function reset will repost them */
4473 /* Post the rpi header region to the device. */
4474 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
4476 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4477 "0393 Error %d during rpi post operation\n",
4482 /* Temporary initialization of lpfc_fip_flag to non-fip */
4483 bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
4485 /* Set up all the queues to the device */
4486 rc = lpfc_sli4_queue_setup(phba);
4488 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4489 "0381 Error %d during queue setup.\n ", rc);
4490 goto out_stop_timers;
4493 /* Arm the CQs and then EQs on device */
4494 lpfc_sli4_arm_cqeq_intr(phba);
4496 /* Indicate device interrupt mode */
4497 phba->sli4_hba.intr_enable = 1;
4499 /* Allow asynchronous mailbox command to go through */
4500 spin_lock_irq(&phba->hbalock);
4501 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4502 spin_unlock_irq(&phba->hbalock);
4504 /* Post receive buffers to the device */
4505 lpfc_sli4_rb_setup(phba);
4507 /* Start the ELS watchdog timer */
4509 * The driver for SLI4 is not yet ready to process timeouts
4510 * or interrupts. Once it is, the comment bars can be removed.
4512 /* mod_timer(&vport->els_tmofunc,
4513 * jiffies + HZ * (phba->fc_ratov*2)); */
4515 /* Start heart beat timer */
4516 mod_timer(&phba->hb_tmofunc,
4517 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
4518 phba->hb_outstanding = 0;
4519 phba->last_completion_time = jiffies;
4521 /* Start error attention (ERATT) polling timer */
4522 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
4525 * The port is ready, set the host's link state to LINK_DOWN
4526 * in preparation for link interrupts.
4528 lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
4529 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4530 lpfc_set_loopback_flag(phba);
4531 /* Change driver state to LPFC_LINK_DOWN right before init link */
4532 spin_lock_irq(&phba->hbalock);
4533 phba->link_state = LPFC_LINK_DOWN;
4534 spin_unlock_irq(&phba->hbalock);
4535 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
4536 if (unlikely(rc != MBX_NOT_FINISHED)) {
4542 /* Unset all the queues set up in this routine when error out */
4544 lpfc_sli4_queue_unset(phba);
4548 lpfc_stop_hba_timers(phba);
4552 mempool_free(mboxq, phba->mbox_mem_pool);
4557 * lpfc_mbox_timeout - Timeout call back function for mbox timer
4558 * @ptr: context object - pointer to hba structure.
4560 * This is the callback function for mailbox timer. The mailbox
4561 * timer is armed when a new mailbox command is issued and the timer
4562 * is deleted when the mailbox complete. The function is called by
4563 * the kernel timer code when a mailbox does not complete within
4564 * expected time. This function wakes up the worker thread to
4565 * process the mailbox timeout and returns. All the processing is
4566 * done by the worker thread function lpfc_mbox_timeout_handler.
4569 lpfc_mbox_timeout(unsigned long ptr)
4571 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4572 unsigned long iflag;
4573 uint32_t tmo_posted;
4575 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
4576 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
4578 phba->pport->work_port_events |= WORKER_MBOX_TMO;
4579 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
4582 lpfc_worker_wake_up(phba);
4588 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
4589 * @phba: Pointer to HBA context object.
4591 * This function is called from worker thread when a mailbox command times out.
4592 * The caller is not required to hold any locks. This function will reset the
4593 * HBA and recover all the pending commands.
4596 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
4598 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
4599 MAILBOX_t *mb = &pmbox->mb;
4600 struct lpfc_sli *psli = &phba->sli;
4601 struct lpfc_sli_ring *pring;
4603 /* Check the pmbox pointer first. There is a race condition
4604 * between the mbox timeout handler getting executed in the
4605 * worklist and the mailbox actually completing. When this
4606 * race condition occurs, the mbox_active will be NULL.
4608 spin_lock_irq(&phba->hbalock);
4609 if (pmbox == NULL) {
4610 lpfc_printf_log(phba, KERN_WARNING,
4612 "0353 Active Mailbox cleared - mailbox timeout "
4614 spin_unlock_irq(&phba->hbalock);
4618 /* Mbox cmd <mbxCommand> timeout */
4619 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4620 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
4622 phba->pport->port_state,
4624 phba->sli.mbox_active);
4625 spin_unlock_irq(&phba->hbalock);
4627 /* Setting state unknown so lpfc_sli_abort_iocb_ring
4628 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
4629 * it to fail all oustanding SCSI IO.
4631 spin_lock_irq(&phba->pport->work_port_lock);
4632 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
4633 spin_unlock_irq(&phba->pport->work_port_lock);
4634 spin_lock_irq(&phba->hbalock);
4635 phba->link_state = LPFC_LINK_UNKNOWN;
4636 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
4637 spin_unlock_irq(&phba->hbalock);
4639 pring = &psli->ring[psli->fcp_ring];
4640 lpfc_sli_abort_iocb_ring(phba, pring);
4642 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4643 "0345 Resetting board due to mailbox timeout\n");
4645 /* Reset the HBA device */
4646 lpfc_reset_hba(phba);
4650 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
4651 * @phba: Pointer to HBA context object.
4652 * @pmbox: Pointer to mailbox object.
4653 * @flag: Flag indicating how the mailbox need to be processed.
4655 * This function is called by discovery code and HBA management code
4656 * to submit a mailbox command to firmware with SLI-3 interface spec. This
4657 * function gets the hbalock to protect the data structures.
4658 * The mailbox command can be submitted in polling mode, in which case
4659 * this function will wait in a polling loop for the completion of the
4661 * If the mailbox is submitted in no_wait mode (not polling) the
4662 * function will submit the command and returns immediately without waiting
4663 * for the mailbox completion. The no_wait is supported only when HBA
4664 * is in SLI2/SLI3 mode - interrupts are enabled.
4665 * The SLI interface allows only one mailbox pending at a time. If the
4666 * mailbox is issued in polling mode and there is already a mailbox
4667 * pending, then the function will return an error. If the mailbox is issued
4668 * in NO_WAIT mode and there is a mailbox pending already, the function
4669 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
4670 * The sli layer owns the mailbox object until the completion of mailbox
4671 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
4672 * return codes the caller owns the mailbox command after the return of
4676 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
4680 struct lpfc_sli *psli = &phba->sli;
4681 uint32_t status, evtctr;
4684 unsigned long timeout;
4685 unsigned long drvr_flag = 0;
4686 uint32_t word0, ldata;
4687 void __iomem *to_slim;
4688 int processing_queue = 0;
4690 spin_lock_irqsave(&phba->hbalock, drvr_flag);
4692 /* processing mbox queue from intr_handler */
4693 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
4694 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4697 processing_queue = 1;
4698 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4699 pmbox = lpfc_mbox_get(phba);
4701 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4706 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
4707 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
4709 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4710 lpfc_printf_log(phba, KERN_ERR,
4711 LOG_MBOX | LOG_VPORT,
4712 "1806 Mbox x%x failed. No vport\n",
4713 pmbox->u.mb.mbxCommand);
4715 goto out_not_finished;
4719 /* If the PCI channel is in offline state, do not post mbox. */
4720 if (unlikely(pci_channel_offline(phba->pcidev))) {
4721 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4722 goto out_not_finished;
4725 /* If HBA has a deferred error attention, fail the iocb. */
4726 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
4727 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4728 goto out_not_finished;
4734 status = MBX_SUCCESS;
4736 if (phba->link_state == LPFC_HBA_ERROR) {
4737 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4739 /* Mbox command <mbxCommand> cannot issue */
4740 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4741 "(%d):0311 Mailbox command x%x cannot "
4742 "issue Data: x%x x%x\n",
4743 pmbox->vport ? pmbox->vport->vpi : 0,
4744 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
4745 goto out_not_finished;
4748 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
4749 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
4750 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4751 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4752 "(%d):2528 Mailbox command x%x cannot "
4753 "issue Data: x%x x%x\n",
4754 pmbox->vport ? pmbox->vport->vpi : 0,
4755 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
4756 goto out_not_finished;
4759 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
4760 /* Polling for a mbox command when another one is already active
4761 * is not allowed in SLI. Also, the driver must have established
4762 * SLI2 mode to queue and process multiple mbox commands.
4765 if (flag & MBX_POLL) {
4766 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4768 /* Mbox command <mbxCommand> cannot issue */
4769 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4770 "(%d):2529 Mailbox command x%x "
4771 "cannot issue Data: x%x x%x\n",
4772 pmbox->vport ? pmbox->vport->vpi : 0,
4773 pmbox->u.mb.mbxCommand,
4774 psli->sli_flag, flag);
4775 goto out_not_finished;
4778 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
4779 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4780 /* Mbox command <mbxCommand> cannot issue */
4781 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4782 "(%d):2530 Mailbox command x%x "
4783 "cannot issue Data: x%x x%x\n",
4784 pmbox->vport ? pmbox->vport->vpi : 0,
4785 pmbox->u.mb.mbxCommand,
4786 psli->sli_flag, flag);
4787 goto out_not_finished;
4790 /* Another mailbox command is still being processed, queue this
4791 * command to be processed later.
4793 lpfc_mbox_put(phba, pmbox);
4795 /* Mbox cmd issue - BUSY */
4796 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4797 "(%d):0308 Mbox cmd issue - BUSY Data: "
4798 "x%x x%x x%x x%x\n",
4799 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
4800 mb->mbxCommand, phba->pport->port_state,
4801 psli->sli_flag, flag);
4803 psli->slistat.mbox_busy++;
4804 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4807 lpfc_debugfs_disc_trc(pmbox->vport,
4808 LPFC_DISC_TRC_MBOX_VPORT,
4809 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
4810 (uint32_t)mb->mbxCommand,
4811 mb->un.varWords[0], mb->un.varWords[1]);
4814 lpfc_debugfs_disc_trc(phba->pport,
4816 "MBOX Bsy: cmd:x%x mb:x%x x%x",
4817 (uint32_t)mb->mbxCommand,
4818 mb->un.varWords[0], mb->un.varWords[1]);
4824 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4826 /* If we are not polling, we MUST be in SLI2 mode */
4827 if (flag != MBX_POLL) {
4828 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
4829 (mb->mbxCommand != MBX_KILL_BOARD)) {
4830 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4831 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4832 /* Mbox command <mbxCommand> cannot issue */
4833 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4834 "(%d):2531 Mailbox command x%x "
4835 "cannot issue Data: x%x x%x\n",
4836 pmbox->vport ? pmbox->vport->vpi : 0,
4837 pmbox->u.mb.mbxCommand,
4838 psli->sli_flag, flag);
4839 goto out_not_finished;
4841 /* timeout active mbox command */
4842 mod_timer(&psli->mbox_tmo, (jiffies +
4843 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
4846 /* Mailbox cmd <cmd> issue */
4847 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4848 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
4850 pmbox->vport ? pmbox->vport->vpi : 0,
4851 mb->mbxCommand, phba->pport->port_state,
4852 psli->sli_flag, flag);
4854 if (mb->mbxCommand != MBX_HEARTBEAT) {
4856 lpfc_debugfs_disc_trc(pmbox->vport,
4857 LPFC_DISC_TRC_MBOX_VPORT,
4858 "MBOX Send vport: cmd:x%x mb:x%x x%x",
4859 (uint32_t)mb->mbxCommand,
4860 mb->un.varWords[0], mb->un.varWords[1]);
4863 lpfc_debugfs_disc_trc(phba->pport,
4865 "MBOX Send: cmd:x%x mb:x%x x%x",
4866 (uint32_t)mb->mbxCommand,
4867 mb->un.varWords[0], mb->un.varWords[1]);
4871 psli->slistat.mbox_cmd++;
4872 evtctr = psli->slistat.mbox_event;
4874 /* next set own bit for the adapter and copy over command word */
4875 mb->mbxOwner = OWN_CHIP;
4877 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4878 /* First copy command data to host SLIM area */
4879 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
4881 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4882 /* copy command data into host mbox for cmpl */
4883 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
4886 /* First copy mbox command data to HBA SLIM, skip past first
4888 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4889 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
4890 MAILBOX_CMD_SIZE - sizeof (uint32_t));
4892 /* Next copy over first word, with mbxOwner set */
4893 ldata = *((uint32_t *)mb);
4894 to_slim = phba->MBslimaddr;
4895 writel(ldata, to_slim);
4896 readl(to_slim); /* flush */
4898 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4899 /* switch over to host mailbox */
4900 psli->sli_flag |= LPFC_SLI_ACTIVE;
4908 /* Set up reference to mailbox command */
4909 psli->mbox_active = pmbox;
4910 /* Interrupt board to do it */
4911 writel(CA_MBATT, phba->CAregaddr);
4912 readl(phba->CAregaddr); /* flush */
4913 /* Don't wait for it to finish, just return */
4917 /* Set up null reference to mailbox command */
4918 psli->mbox_active = NULL;
4919 /* Interrupt board to do it */
4920 writel(CA_MBATT, phba->CAregaddr);
4921 readl(phba->CAregaddr); /* flush */
4923 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4924 /* First read mbox status word */
4925 word0 = *((uint32_t *)phba->mbox);
4926 word0 = le32_to_cpu(word0);
4928 /* First read mbox status word */
4929 word0 = readl(phba->MBslimaddr);
4932 /* Read the HBA Host Attention Register */
4933 ha_copy = readl(phba->HAregaddr);
4934 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
4938 /* Wait for command to complete */
4939 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
4940 (!(ha_copy & HA_MBATT) &&
4941 (phba->link_state > LPFC_WARM_START))) {
4942 if (time_after(jiffies, timeout)) {
4943 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4944 spin_unlock_irqrestore(&phba->hbalock,
4946 goto out_not_finished;
4949 /* Check if we took a mbox interrupt while we were
4951 if (((word0 & OWN_CHIP) != OWN_CHIP)
4952 && (evtctr != psli->slistat.mbox_event))
4956 spin_unlock_irqrestore(&phba->hbalock,
4959 spin_lock_irqsave(&phba->hbalock, drvr_flag);
4962 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4963 /* First copy command data */
4964 word0 = *((uint32_t *)phba->mbox);
4965 word0 = le32_to_cpu(word0);
4966 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4969 /* Check real SLIM for any errors */
4970 slimword0 = readl(phba->MBslimaddr);
4971 slimmb = (MAILBOX_t *) & slimword0;
4972 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
4973 && slimmb->mbxStatus) {
4980 /* First copy command data */
4981 word0 = readl(phba->MBslimaddr);
4983 /* Read the HBA Host Attention Register */
4984 ha_copy = readl(phba->HAregaddr);
4987 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4988 /* copy results back to user */
4989 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
4991 /* First copy command data */
4992 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
4994 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
4996 lpfc_memcpy_from_slim((void *)pmbox->context2,
4997 phba->MBslimaddr + DMP_RSP_OFFSET,
4998 mb->un.varDmp.word_cnt);
5002 writel(HA_MBATT, phba->HAregaddr);
5003 readl(phba->HAregaddr); /* flush */
5005 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5006 status = mb->mbxStatus;
5009 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
5013 if (processing_queue) {
5014 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
5015 lpfc_mbox_cmpl_put(phba, pmbox);
5017 return MBX_NOT_FINISHED;
5021 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5022 * @phba: Pointer to HBA context object.
5023 * @mboxq: Pointer to mailbox object.
5025 * The function posts a mailbox to the port. The mailbox is expected
5026 * to be comletely filled in and ready for the port to operate on it.
5027 * This routine executes a synchronous completion operation on the
5028 * mailbox by polling for its completion.
5030 * The caller must not be holding any locks when calling this routine.
5033 * MBX_SUCCESS - mailbox posted successfully
5034 * Any of the MBX error values.
5037 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5039 int rc = MBX_SUCCESS;
5040 unsigned long iflag;
5042 uint32_t mcqe_status;
5044 unsigned long timeout;
5045 struct lpfc_sli *psli = &phba->sli;
5046 struct lpfc_mqe *mb = &mboxq->u.mqe;
5047 struct lpfc_bmbx_create *mbox_rgn;
5048 struct dma_address *dma_address;
5049 struct lpfc_register bmbx_reg;
5052 * Only one mailbox can be active to the bootstrap mailbox region
5053 * at a time and there is no queueing provided.
5055 spin_lock_irqsave(&phba->hbalock, iflag);
5056 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
5057 spin_unlock_irqrestore(&phba->hbalock, iflag);
5058 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5059 "(%d):2532 Mailbox command x%x (x%x) "
5060 "cannot issue Data: x%x x%x\n",
5061 mboxq->vport ? mboxq->vport->vpi : 0,
5062 mboxq->u.mb.mbxCommand,
5063 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5064 psli->sli_flag, MBX_POLL);
5065 return MBXERR_ERROR;
5067 /* The server grabs the token and owns it until release */
5068 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5069 phba->sli.mbox_active = mboxq;
5070 spin_unlock_irqrestore(&phba->hbalock, iflag);
5073 * Initialize the bootstrap memory region to avoid stale data areas
5074 * in the mailbox post. Then copy the caller's mailbox contents to
5075 * the bmbx mailbox region.
5077 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
5078 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
5079 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
5080 sizeof(struct lpfc_mqe));
5082 /* Post the high mailbox dma address to the port and wait for ready. */
5083 dma_address = &phba->sli4_hba.bmbx.dma_address;
5084 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
5086 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
5089 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
5090 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
5094 if (time_after(jiffies, timeout)) {
5098 } while (!db_ready);
5100 /* Post the low mailbox dma address to the port. */
5101 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
5102 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
5105 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
5106 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
5110 if (time_after(jiffies, timeout)) {
5114 } while (!db_ready);
5117 * Read the CQ to ensure the mailbox has completed.
5118 * If so, update the mailbox status so that the upper layers
5119 * can complete the request normally.
5121 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
5122 sizeof(struct lpfc_mqe));
5123 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
5124 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
5125 sizeof(struct lpfc_mcqe));
5126 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
5128 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5129 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
5130 bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
5134 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5135 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5136 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5137 " x%x x%x CQ: x%x x%x x%x x%x\n",
5138 mboxq->vport ? mboxq->vport->vpi : 0,
5139 mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
5140 bf_get(lpfc_mqe_status, mb),
5141 mb->un.mb_words[0], mb->un.mb_words[1],
5142 mb->un.mb_words[2], mb->un.mb_words[3],
5143 mb->un.mb_words[4], mb->un.mb_words[5],
5144 mb->un.mb_words[6], mb->un.mb_words[7],
5145 mb->un.mb_words[8], mb->un.mb_words[9],
5146 mb->un.mb_words[10], mb->un.mb_words[11],
5147 mb->un.mb_words[12], mboxq->mcqe.word0,
5148 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5149 mboxq->mcqe.trailer);
5151 /* We are holding the token, no needed for lock when release */
5152 spin_lock_irqsave(&phba->hbalock, iflag);
5153 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5154 phba->sli.mbox_active = NULL;
5155 spin_unlock_irqrestore(&phba->hbalock, iflag);
5160 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5161 * @phba: Pointer to HBA context object.
5162 * @pmbox: Pointer to mailbox object.
5163 * @flag: Flag indicating how the mailbox need to be processed.
5165 * This function is called by discovery code and HBA management code to submit
5166 * a mailbox command to firmware with SLI-4 interface spec.
5168 * Return codes the caller owns the mailbox command after the return of the
5172 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5175 struct lpfc_sli *psli = &phba->sli;
5176 unsigned long iflags;
5179 /* Detect polling mode and jump to a handler */
5180 if (!phba->sli4_hba.intr_enable) {
5181 if (flag == MBX_POLL)
5182 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
5185 if (rc != MBX_SUCCESS)
5186 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5187 "(%d):2541 Mailbox command x%x "
5188 "(x%x) cannot issue Data: x%x x%x\n",
5189 mboxq->vport ? mboxq->vport->vpi : 0,
5190 mboxq->u.mb.mbxCommand,
5191 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5192 psli->sli_flag, flag);
5194 } else if (flag == MBX_POLL) {
5195 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5196 "(%d):2542 Mailbox command x%x (x%x) "
5197 "cannot issue Data: x%x x%x\n",
5198 mboxq->vport ? mboxq->vport->vpi : 0,
5199 mboxq->u.mb.mbxCommand,
5200 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5201 psli->sli_flag, flag);
5205 /* Now, interrupt mode asynchrous mailbox command */
5206 rc = lpfc_mbox_cmd_check(phba, mboxq);
5208 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5209 "(%d):2543 Mailbox command x%x (x%x) "
5210 "cannot issue Data: x%x x%x\n",
5211 mboxq->vport ? mboxq->vport->vpi : 0,
5212 mboxq->u.mb.mbxCommand,
5213 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5214 psli->sli_flag, flag);
5215 goto out_not_finished;
5217 rc = lpfc_mbox_dev_check(phba);
5219 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5220 "(%d):2544 Mailbox command x%x (x%x) "
5221 "cannot issue Data: x%x x%x\n",
5222 mboxq->vport ? mboxq->vport->vpi : 0,
5223 mboxq->u.mb.mbxCommand,
5224 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5225 psli->sli_flag, flag);
5226 goto out_not_finished;
5229 /* Put the mailbox command to the driver internal FIFO */
5230 psli->slistat.mbox_busy++;
5231 spin_lock_irqsave(&phba->hbalock, iflags);
5232 lpfc_mbox_put(phba, mboxq);
5233 spin_unlock_irqrestore(&phba->hbalock, iflags);
5234 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5235 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5236 "x%x (x%x) x%x x%x x%x\n",
5237 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
5238 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5239 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5240 phba->pport->port_state,
5241 psli->sli_flag, MBX_NOWAIT);
5242 /* Wake up worker thread to transport mailbox command from head */
5243 lpfc_worker_wake_up(phba);
5248 return MBX_NOT_FINISHED;
5252 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5253 * @phba: Pointer to HBA context object.
5255 * This function is called by worker thread to send a mailbox command to
5256 * SLI4 HBA firmware.
5260 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
5262 struct lpfc_sli *psli = &phba->sli;
5263 LPFC_MBOXQ_t *mboxq;
5264 int rc = MBX_SUCCESS;
5265 unsigned long iflags;
5266 struct lpfc_mqe *mqe;
5269 /* Check interrupt mode before post async mailbox command */
5270 if (unlikely(!phba->sli4_hba.intr_enable))
5271 return MBX_NOT_FINISHED;
5273 /* Check for mailbox command service token */
5274 spin_lock_irqsave(&phba->hbalock, iflags);
5275 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
5276 spin_unlock_irqrestore(&phba->hbalock, iflags);
5277 return MBX_NOT_FINISHED;
5279 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
5280 spin_unlock_irqrestore(&phba->hbalock, iflags);
5281 return MBX_NOT_FINISHED;
5283 if (unlikely(phba->sli.mbox_active)) {
5284 spin_unlock_irqrestore(&phba->hbalock, iflags);
5285 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5286 "0384 There is pending active mailbox cmd\n");
5287 return MBX_NOT_FINISHED;
5289 /* Take the mailbox command service token */
5290 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5292 /* Get the next mailbox command from head of queue */
5293 mboxq = lpfc_mbox_get(phba);
5295 /* If no more mailbox command waiting for post, we're done */
5297 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5298 spin_unlock_irqrestore(&phba->hbalock, iflags);
5301 phba->sli.mbox_active = mboxq;
5302 spin_unlock_irqrestore(&phba->hbalock, iflags);
5304 /* Check device readiness for posting mailbox command */
5305 rc = lpfc_mbox_dev_check(phba);
5307 /* Driver clean routine will clean up pending mailbox */
5308 goto out_not_finished;
5310 /* Prepare the mbox command to be posted */
5311 mqe = &mboxq->u.mqe;
5312 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
5314 /* Start timer for the mbox_tmo and log some mailbox post messages */
5315 mod_timer(&psli->mbox_tmo, (jiffies +
5316 (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
5318 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5319 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5321 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
5322 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5323 phba->pport->port_state, psli->sli_flag);
5325 if (mbx_cmnd != MBX_HEARTBEAT) {
5327 lpfc_debugfs_disc_trc(mboxq->vport,
5328 LPFC_DISC_TRC_MBOX_VPORT,
5329 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5330 mbx_cmnd, mqe->un.mb_words[0],
5331 mqe->un.mb_words[1]);
5333 lpfc_debugfs_disc_trc(phba->pport,
5335 "MBOX Send: cmd:x%x mb:x%x x%x",
5336 mbx_cmnd, mqe->un.mb_words[0],
5337 mqe->un.mb_words[1]);
5340 psli->slistat.mbox_cmd++;
5342 /* Post the mailbox command to the port */
5343 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
5344 if (rc != MBX_SUCCESS) {
5345 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5346 "(%d):2533 Mailbox command x%x (x%x) "
5347 "cannot issue Data: x%x x%x\n",
5348 mboxq->vport ? mboxq->vport->vpi : 0,
5349 mboxq->u.mb.mbxCommand,
5350 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5351 psli->sli_flag, MBX_NOWAIT);
5352 goto out_not_finished;
5358 spin_lock_irqsave(&phba->hbalock, iflags);
5359 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
5360 __lpfc_mbox_cmpl_put(phba, mboxq);
5361 /* Release the token */
5362 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5363 phba->sli.mbox_active = NULL;
5364 spin_unlock_irqrestore(&phba->hbalock, iflags);
5366 return MBX_NOT_FINISHED;
5370 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5371 * @phba: Pointer to HBA context object.
5372 * @pmbox: Pointer to mailbox object.
5373 * @flag: Flag indicating how the mailbox need to be processed.
5375 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5376 * the API jump table function pointer from the lpfc_hba struct.
5378 * Return codes the caller owns the mailbox command after the return of the
5382 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
5384 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
5388 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5389 * @phba: The hba struct for which this call is being executed.
5390 * @dev_grp: The HBA PCI-Device group number.
5392 * This routine sets up the mbox interface API function jump table in @phba
5394 * Returns: 0 - success, -ENODEV - failure.
5397 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5401 case LPFC_PCI_DEV_LP:
5402 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
5403 phba->lpfc_sli_handle_slow_ring_event =
5404 lpfc_sli_handle_slow_ring_event_s3;
5405 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
5406 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
5407 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
5409 case LPFC_PCI_DEV_OC:
5410 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
5411 phba->lpfc_sli_handle_slow_ring_event =
5412 lpfc_sli_handle_slow_ring_event_s4;
5413 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
5414 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
5415 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
5418 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5419 "1420 Invalid HBA PCI-device group: 0x%x\n",
5428 * __lpfc_sli_ringtx_put - Add an iocb to the txq
5429 * @phba: Pointer to HBA context object.
5430 * @pring: Pointer to driver SLI ring object.
5431 * @piocb: Pointer to address of newly added command iocb.
5433 * This function is called with hbalock held to add a command
5434 * iocb to the txq when SLI layer cannot submit the command iocb
5438 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5439 struct lpfc_iocbq *piocb)
5441 /* Insert the caller's iocb in the txq tail for later processing. */
5442 list_add_tail(&piocb->list, &pring->txq);
5447 * lpfc_sli_next_iocb - Get the next iocb in the txq
5448 * @phba: Pointer to HBA context object.
5449 * @pring: Pointer to driver SLI ring object.
5450 * @piocb: Pointer to address of newly added command iocb.
5452 * This function is called with hbalock held before a new
5453 * iocb is submitted to the firmware. This function checks
5454 * txq to flush the iocbs in txq to Firmware before
5455 * submitting new iocbs to the Firmware.
5456 * If there are iocbs in the txq which need to be submitted
5457 * to firmware, lpfc_sli_next_iocb returns the first element
5458 * of the txq after dequeuing it from txq.
5459 * If there is no iocb in the txq then the function will return
5460 * *piocb and *piocb is set to NULL. Caller needs to check
5461 * *piocb to find if there are more commands in the txq.
5463 static struct lpfc_iocbq *
5464 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5465 struct lpfc_iocbq **piocb)
5467 struct lpfc_iocbq * nextiocb;
5469 nextiocb = lpfc_sli_ringtx_get(phba, pring);
5479 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
5480 * @phba: Pointer to HBA context object.
5481 * @ring_number: SLI ring number to issue iocb on.
5482 * @piocb: Pointer to command iocb.
5483 * @flag: Flag indicating if this command can be put into txq.
5485 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
5486 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
5487 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
5488 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
5489 * this function allows only iocbs for posting buffers. This function finds
5490 * next available slot in the command ring and posts the command to the
5491 * available slot and writes the port attention register to request HBA start
5492 * processing new iocb. If there is no slot available in the ring and
5493 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
5494 * the function returns IOCB_BUSY.
5496 * This function is called with hbalock held. The function will return success
5497 * after it successfully submit the iocb to firmware or after adding to the
5501 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
5502 struct lpfc_iocbq *piocb, uint32_t flag)
5504 struct lpfc_iocbq *nextiocb;
5506 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
5508 if (piocb->iocb_cmpl && (!piocb->vport) &&
5509 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
5510 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
5511 lpfc_printf_log(phba, KERN_ERR,
5512 LOG_SLI | LOG_VPORT,
5513 "1807 IOCB x%x failed. No vport\n",
5514 piocb->iocb.ulpCommand);
5520 /* If the PCI channel is in offline state, do not post iocbs. */
5521 if (unlikely(pci_channel_offline(phba->pcidev)))
5524 /* If HBA has a deferred error attention, fail the iocb. */
5525 if (unlikely(phba->hba_flag & DEFER_ERATT))
5529 * We should never get an IOCB if we are in a < LINK_DOWN state
5531 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5535 * Check to see if we are blocking IOCB processing because of a
5536 * outstanding event.
5538 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
5541 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
5543 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
5544 * can be issued if the link is not up.
5546 switch (piocb->iocb.ulpCommand) {
5547 case CMD_GEN_REQUEST64_CR:
5548 case CMD_GEN_REQUEST64_CX:
5549 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
5550 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
5552 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
5553 MENLO_TRANSPORT_TYPE))
5557 case CMD_QUE_RING_BUF_CN:
5558 case CMD_QUE_RING_BUF64_CN:
5560 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
5561 * completion, iocb_cmpl MUST be 0.
5563 if (piocb->iocb_cmpl)
5564 piocb->iocb_cmpl = NULL;
5566 case CMD_CREATE_XRI_CR:
5567 case CMD_CLOSE_XRI_CN:
5568 case CMD_CLOSE_XRI_CX:
5575 * For FCP commands, we must be in a state where we can process link
5578 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
5579 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
5583 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
5584 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
5585 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
5588 lpfc_sli_update_ring(phba, pring);
5590 lpfc_sli_update_full_ring(phba, pring);
5593 return IOCB_SUCCESS;
5598 pring->stats.iocb_cmd_delay++;
5602 if (!(flag & SLI_IOCB_RET_IOCB)) {
5603 __lpfc_sli_ringtx_put(phba, pring, piocb);
5604 return IOCB_SUCCESS;
5611 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
5612 * @phba: Pointer to HBA context object.
5613 * @piocb: Pointer to command iocb.
5614 * @sglq: Pointer to the scatter gather queue object.
5616 * This routine converts the bpl or bde that is in the IOCB
5617 * to a sgl list for the sli4 hardware. The physical address
5618 * of the bpl/bde is converted back to a virtual address.
5619 * If the IOCB contains a BPL then the list of BDE's is
5620 * converted to sli4_sge's. If the IOCB contains a single
5621 * BDE then it is converted to a single sli_sge.
5622 * The IOCB is still in cpu endianess so the contents of
5623 * the bpl can be used without byte swapping.
5625 * Returns valid XRI = Success, NO_XRI = Failure.
5628 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
5629 struct lpfc_sglq *sglq)
5631 uint16_t xritag = NO_XRI;
5632 struct ulp_bde64 *bpl = NULL;
5633 struct ulp_bde64 bde;
5634 struct sli4_sge *sgl = NULL;
5639 if (!piocbq || !sglq)
5642 sgl = (struct sli4_sge *)sglq->sgl;
5643 icmd = &piocbq->iocb;
5644 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5645 numBdes = icmd->un.genreq64.bdl.bdeSize /
5646 sizeof(struct ulp_bde64);
5647 /* The addrHigh and addrLow fields within the IOCB
5648 * have not been byteswapped yet so there is no
5649 * need to swap them back.
5651 bpl = (struct ulp_bde64 *)
5652 ((struct lpfc_dmabuf *)piocbq->context3)->virt;
5657 for (i = 0; i < numBdes; i++) {
5658 /* Should already be byte swapped. */
5659 sgl->addr_hi = bpl->addrHigh;
5660 sgl->addr_lo = bpl->addrLow;
5661 /* swap the size field back to the cpu so we
5662 * can assign it to the sgl.
5664 bde.tus.w = le32_to_cpu(bpl->tus.w);
5665 bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
5666 if ((i+1) == numBdes)
5667 bf_set(lpfc_sli4_sge_last, sgl, 1);
5669 bf_set(lpfc_sli4_sge_last, sgl, 0);
5670 sgl->word2 = cpu_to_le32(sgl->word2);
5671 sgl->word3 = cpu_to_le32(sgl->word3);
5675 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
5676 /* The addrHigh and addrLow fields of the BDE have not
5677 * been byteswapped yet so they need to be swapped
5678 * before putting them in the sgl.
5681 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
5683 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
5684 bf_set(lpfc_sli4_sge_len, sgl,
5685 icmd->un.genreq64.bdl.bdeSize);
5686 bf_set(lpfc_sli4_sge_last, sgl, 1);
5687 sgl->word2 = cpu_to_le32(sgl->word2);
5688 sgl->word3 = cpu_to_le32(sgl->word3);
5690 return sglq->sli4_xritag;
5694 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5695 * @phba: Pointer to HBA context object.
5696 * @piocb: Pointer to command iocb.
5698 * This routine performs a round robin SCSI command to SLI4 FCP WQ index
5701 * Return: index into SLI4 fast-path FCP queue index.
5704 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
5706 static uint32_t fcp_qidx;
5708 return fcp_qidx++ % phba->cfg_fcp_wq_count;
5712 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
5713 * @phba: Pointer to HBA context object.
5714 * @piocb: Pointer to command iocb.
5715 * @wqe: Pointer to the work queue entry.
5717 * This routine converts the iocb command to its Work Queue Entry
5718 * equivalent. The wqe pointer should not have any fields set when
5719 * this routine is called because it will memcpy over them.
5720 * This routine does not set the CQ_ID or the WQEC bits in the
5723 * Returns: 0 = Success, IOCB_ERROR = Failure.
5726 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
5727 union lpfc_wqe *wqe)
5729 uint32_t payload_len = 0;
5733 uint8_t command_type = ELS_COMMAND_NON_FIP;
5736 struct ulp_bde64 *bpl = NULL;
5738 fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
5739 /* The fcp commands will set command type */
5740 if ((!(iocbq->iocb_flag & LPFC_IO_FCP)) && (!fip))
5741 command_type = ELS_COMMAND_NON_FIP;
5742 else if (!(iocbq->iocb_flag & LPFC_IO_FCP))
5743 command_type = ELS_COMMAND_FIP;
5744 else if (iocbq->iocb_flag & LPFC_IO_FCP)
5745 command_type = FCP_COMMAND;
5747 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5748 "2019 Invalid cmd 0x%x\n",
5749 iocbq->iocb.ulpCommand);
5752 /* Some of the fields are in the right position already */
5753 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
5754 abort_tag = (uint32_t) iocbq->iotag;
5755 xritag = iocbq->sli4_xritag;
5756 wqe->words[7] = 0; /* The ct field has moved so reset */
5757 /* words0-2 bpl convert bde */
5758 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5759 bpl = (struct ulp_bde64 *)
5760 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
5764 /* Should already be byte swapped. */
5765 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
5766 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
5767 /* swap the size field back to the cpu so we
5768 * can assign it to the sgl.
5770 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
5771 payload_len = wqe->generic.bde.tus.f.bdeSize;
5773 payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
5775 iocbq->iocb.ulpIoTag = iocbq->iotag;
5776 cmnd = iocbq->iocb.ulpCommand;
5778 switch (iocbq->iocb.ulpCommand) {
5779 case CMD_ELS_REQUEST64_CR:
5780 if (!iocbq->iocb.ulpLe) {
5781 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5782 "2007 Only Limited Edition cmd Format"
5783 " supported 0x%x\n",
5784 iocbq->iocb.ulpCommand);
5787 wqe->els_req.payload_len = payload_len;
5788 /* Els_reguest64 has a TMO */
5789 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
5790 iocbq->iocb.ulpTimeout);
5791 /* Need a VF for word 4 set the vf bit*/
5792 bf_set(els_req64_vf, &wqe->els_req, 0);
5793 /* And a VFID for word 12 */
5794 bf_set(els_req64_vfid, &wqe->els_req, 0);
5796 * Set ct field to 3, indicates that the context_tag field
5797 * contains the FCFI and remote N_Port_ID is
5801 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
5802 bf_set(lpfc_wqe_gen_context, &wqe->generic,
5803 iocbq->iocb.ulpContext);
5805 if (iocbq->vport->fc_myDID != 0) {
5806 bf_set(els_req64_sid, &wqe->els_req,
5807 iocbq->vport->fc_myDID);
5808 bf_set(els_req64_sp, &wqe->els_req, 1);
5810 bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
5811 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
5812 /* CCP CCPE PV PRI in word10 were set in the memcpy */
5814 case CMD_XMIT_SEQUENCE64_CR:
5815 /* word3 iocb=io_tag32 wqe=payload_offset */
5816 /* payload offset used for multilpe outstanding
5817 * sequences on the same exchange
5820 /* word4 relative_offset memcpy */
5821 /* word5 r_ctl/df_ctl memcpy */
5822 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
5823 wqe->xmit_sequence.xmit_len = payload_len;
5825 case CMD_XMIT_BCAST64_CN:
5826 /* word3 iocb=iotag32 wqe=payload_len */
5827 wqe->words[3] = 0; /* no definition for this in wqe */
5828 /* word4 iocb=rsvd wqe=rsvd */
5829 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
5830 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
5831 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
5832 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
5834 case CMD_FCP_IWRITE64_CR:
5835 command_type = FCP_COMMAND_DATA_OUT;
5836 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
5838 * word3 is payload_len: byte offset to the sgl entry for the
5840 * word4 is total xfer len, same as the IOCB->ulpParameter.
5841 * word5 is initial xfer len 0 = wait for xfer-ready
5844 /* Always wait for xfer-ready before sending data */
5845 wqe->fcp_iwrite.initial_xfer_len = 0;
5846 /* word 4 (xfer length) should have been set on the memcpy */
5848 /* allow write to fall through to read */
5849 case CMD_FCP_IREAD64_CR:
5850 /* FCP_CMD is always the 1st sgl entry */
5851 wqe->fcp_iread.payload_len =
5852 payload_len + sizeof(struct fcp_rsp);
5854 /* word 4 (xfer length) should have been set on the memcpy */
5856 bf_set(lpfc_wqe_gen_erp, &wqe->generic,
5857 iocbq->iocb.ulpFCP2Rcvy);
5858 bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
5859 /* The XC bit and the XS bit are similar. The driver never
5860 * tracked whether or not the exchange was previouslly open.
5861 * XC = Exchange create, 0 is create. 1 is already open.
5862 * XS = link cmd: 1 do not close the exchange after command.
5863 * XS = 0 close exchange when command completes.
5864 * The only time we would not set the XC bit is when the XS bit
5865 * is set and we are sending our 2nd or greater command on
5869 /* ALLOW read & write to fall through to ICMD64 */
5870 case CMD_FCP_ICMND64_CR:
5871 /* Always open the exchange */
5872 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
5874 wqe->words[10] &= 0xffff0000; /* zero out ebde count */
5875 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
5877 case CMD_GEN_REQUEST64_CR:
5878 /* word3 command length is described as byte offset to the
5879 * rsp_data. Would always be 16, sizeof(struct sli4_sge)
5884 wqe->gen_req.command_len = payload_len;
5885 /* Word4 parameter copied in the memcpy */
5886 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
5887 /* word6 context tag copied in memcpy */
5888 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
5889 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
5890 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5891 "2015 Invalid CT %x command 0x%x\n",
5892 ct, iocbq->iocb.ulpCommand);
5895 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
5896 bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
5897 iocbq->iocb.ulpTimeout);
5899 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
5900 command_type = OTHER_COMMAND;
5902 case CMD_XMIT_ELS_RSP64_CX:
5903 /* words0-2 BDE memcpy */
5904 /* word3 iocb=iotag32 wqe=rsvd */
5906 /* word4 iocb=did wge=rsvd. */
5908 /* word5 iocb=rsvd wge=did */
5909 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
5910 iocbq->iocb.un.elsreq64.remoteID);
5912 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
5913 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
5915 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
5916 bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
5917 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
5918 bf_set(lpfc_wqe_gen_context, &wqe->generic,
5919 iocbq->vport->vpi + phba->vpi_base);
5920 command_type = OTHER_COMMAND;
5922 case CMD_CLOSE_XRI_CN:
5923 case CMD_ABORT_XRI_CN:
5924 case CMD_ABORT_XRI_CX:
5925 /* words 0-2 memcpy should be 0 rserved */
5926 /* port will send abts */
5927 if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
5929 * The link is down so the fw does not need to send abts
5932 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
5934 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
5935 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
5936 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
5938 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
5939 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
5940 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
5941 wqe->generic.abort_tag = abort_tag;
5943 * The abort handler will send us CMD_ABORT_XRI_CN or
5944 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
5946 bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
5947 cmnd = CMD_ABORT_XRI_CX;
5948 command_type = OTHER_COMMAND;
5951 case CMD_XRI_ABORTED_CX:
5952 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
5953 /* words0-2 are all 0's no bde */
5954 /* word3 and word4 are rsvrd */
5957 /* word5 iocb=rsvd wge=did */
5958 /* There is no remote port id in the IOCB? */
5959 /* Let this fall through and fail */
5960 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
5961 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
5962 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
5963 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
5965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5966 "2014 Invalid command 0x%x\n",
5967 iocbq->iocb.ulpCommand);
5972 bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
5973 bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
5974 wqe->generic.abort_tag = abort_tag;
5975 bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
5976 bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
5977 bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
5978 bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
5984 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
5985 * @phba: Pointer to HBA context object.
5986 * @ring_number: SLI ring number to issue iocb on.
5987 * @piocb: Pointer to command iocb.
5988 * @flag: Flag indicating if this command can be put into txq.
5990 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
5991 * an iocb command to an HBA with SLI-4 interface spec.
5993 * This function is called with hbalock held. The function will return success
5994 * after it successfully submit the iocb to firmware or after adding to the
5998 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
5999 struct lpfc_iocbq *piocb, uint32_t flag)
6001 struct lpfc_sglq *sglq;
6004 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
6007 if (piocb->sli4_xritag == NO_XRI) {
6008 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6009 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6012 sglq = __lpfc_sli_get_sglq(phba);
6015 piocb->sli4_xritag = sglq->sli4_xritag;
6017 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
6018 sglq = NULL; /* These IO's already have an XRI and
6022 /* This is a continuation of a commandi,(CX) so this
6023 * sglq is on the active list
6025 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
6031 xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
6032 if (xritag != sglq->sli4_xritag)
6036 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
6039 if (piocb->iocb_flag & LPFC_IO_FCP) {
6040 fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba, piocb);
6041 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
6044 if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
6047 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
6053 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6055 * This routine wraps the actual lockless version for issusing IOCB function
6056 * pointer from the lpfc_hba struct.
6059 * IOCB_ERROR - Error
6060 * IOCB_SUCCESS - Success
6064 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
6065 struct lpfc_iocbq *piocb, uint32_t flag)
6067 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
6071 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6072 * @phba: The hba struct for which this call is being executed.
6073 * @dev_grp: The HBA PCI-Device group number.
6075 * This routine sets up the SLI interface API function jump table in @phba
6077 * Returns: 0 - success, -ENODEV - failure.
6080 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6084 case LPFC_PCI_DEV_LP:
6085 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
6086 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
6088 case LPFC_PCI_DEV_OC:
6089 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
6090 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
6093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6094 "1419 Invalid HBA PCI-device group: 0x%x\n",
6099 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
6104 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6105 * @phba: Pointer to HBA context object.
6106 * @pring: Pointer to driver SLI ring object.
6107 * @piocb: Pointer to command iocb.
6108 * @flag: Flag indicating if this command can be put into txq.
6110 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6111 * function. This function gets the hbalock and calls
6112 * __lpfc_sli_issue_iocb function and will return the error returned
6113 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6114 * functions which do not hold hbalock.
6117 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
6118 struct lpfc_iocbq *piocb, uint32_t flag)
6120 unsigned long iflags;
6123 spin_lock_irqsave(&phba->hbalock, iflags);
6124 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
6125 spin_unlock_irqrestore(&phba->hbalock, iflags);
6131 * lpfc_extra_ring_setup - Extra ring setup function
6132 * @phba: Pointer to HBA context object.
6134 * This function is called while driver attaches with the
6135 * HBA to setup the extra ring. The extra ring is used
6136 * only when driver needs to support target mode functionality
6137 * or IP over FC functionalities.
6139 * This function is called with no lock held.
6142 lpfc_extra_ring_setup( struct lpfc_hba *phba)
6144 struct lpfc_sli *psli;
6145 struct lpfc_sli_ring *pring;
6149 /* Adjust cmd/rsp ring iocb entries more evenly */
6151 /* Take some away from the FCP ring */
6152 pring = &psli->ring[psli->fcp_ring];
6153 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6154 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6155 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6156 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6158 /* and give them to the extra ring */
6159 pring = &psli->ring[psli->extra_ring];
6161 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6162 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6163 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6164 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6166 /* Setup default profile for this ring */
6167 pring->iotag_max = 4096;
6168 pring->num_mask = 1;
6169 pring->prt[0].profile = 0; /* Mask 0 */
6170 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
6171 pring->prt[0].type = phba->cfg_multi_ring_type;
6172 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
6177 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6178 * @phba: Pointer to HBA context object.
6179 * @pring: Pointer to driver SLI ring object.
6180 * @iocbq: Pointer to iocb object.
6182 * This function is called by the slow ring event handler
6183 * function when there is an ASYNC event iocb in the ring.
6184 * This function is called with no lock held.
6185 * Currently this function handles only temperature related
6186 * ASYNC events. The function decodes the temperature sensor
6187 * event message and posts events for the management applications.
6190 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
6191 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
6196 struct temp_event temp_event_data;
6197 struct Scsi_Host *shost;
6200 icmd = &iocbq->iocb;
6201 evt_code = icmd->un.asyncstat.evt_code;
6202 temp = icmd->ulpContext;
6204 if ((evt_code != ASYNC_TEMP_WARN) &&
6205 (evt_code != ASYNC_TEMP_SAFE)) {
6206 iocb_w = (uint32_t *) icmd;
6207 lpfc_printf_log(phba,
6210 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6212 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6213 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6214 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6215 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6217 icmd->un.asyncstat.evt_code,
6218 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
6219 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
6220 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
6221 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
6225 temp_event_data.data = (uint32_t)temp;
6226 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6227 if (evt_code == ASYNC_TEMP_WARN) {
6228 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6229 lpfc_printf_log(phba,
6232 "0347 Adapter is very hot, please take "
6233 "corrective action. temperature : %d Celsius\n",
6236 if (evt_code == ASYNC_TEMP_SAFE) {
6237 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6238 lpfc_printf_log(phba,
6241 "0340 Adapter temperature is OK now. "
6242 "temperature : %d Celsius\n",
6246 /* Send temperature change event to applications */
6247 shost = lpfc_shost_from_vport(phba->pport);
6248 fc_host_post_vendor_event(shost, fc_get_event_number(),
6249 sizeof(temp_event_data), (char *) &temp_event_data,
6256 * lpfc_sli_setup - SLI ring setup function
6257 * @phba: Pointer to HBA context object.
6259 * lpfc_sli_setup sets up rings of the SLI interface with
6260 * number of iocbs per ring and iotags. This function is
6261 * called while driver attach to the HBA and before the
6262 * interrupts are enabled. So there is no need for locking.
6264 * This function always returns 0.
6267 lpfc_sli_setup(struct lpfc_hba *phba)
6269 int i, totiocbsize = 0;
6270 struct lpfc_sli *psli = &phba->sli;
6271 struct lpfc_sli_ring *pring;
6273 psli->num_rings = MAX_CONFIGURED_RINGS;
6275 psli->fcp_ring = LPFC_FCP_RING;
6276 psli->next_ring = LPFC_FCP_NEXT_RING;
6277 psli->extra_ring = LPFC_EXTRA_RING;
6279 psli->iocbq_lookup = NULL;
6280 psli->iocbq_lookup_len = 0;
6281 psli->last_iotag = 0;
6283 for (i = 0; i < psli->num_rings; i++) {
6284 pring = &psli->ring[i];
6286 case LPFC_FCP_RING: /* ring 0 - FCP */
6287 /* numCiocb and numRiocb are used in config_port */
6288 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
6289 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
6290 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6291 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6292 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6293 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6294 pring->sizeCiocb = (phba->sli_rev == 3) ?
6295 SLI3_IOCB_CMD_SIZE :
6297 pring->sizeRiocb = (phba->sli_rev == 3) ?
6298 SLI3_IOCB_RSP_SIZE :
6300 pring->iotag_ctr = 0;
6302 (phba->cfg_hba_queue_depth * 2);
6303 pring->fast_iotag = pring->iotag_max;
6304 pring->num_mask = 0;
6306 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
6307 /* numCiocb and numRiocb are used in config_port */
6308 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
6309 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
6310 pring->sizeCiocb = (phba->sli_rev == 3) ?
6311 SLI3_IOCB_CMD_SIZE :
6313 pring->sizeRiocb = (phba->sli_rev == 3) ?
6314 SLI3_IOCB_RSP_SIZE :
6316 pring->iotag_max = phba->cfg_hba_queue_depth;
6317 pring->num_mask = 0;
6319 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
6320 /* numCiocb and numRiocb are used in config_port */
6321 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
6322 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
6323 pring->sizeCiocb = (phba->sli_rev == 3) ?
6324 SLI3_IOCB_CMD_SIZE :
6326 pring->sizeRiocb = (phba->sli_rev == 3) ?
6327 SLI3_IOCB_RSP_SIZE :
6329 pring->fast_iotag = 0;
6330 pring->iotag_ctr = 0;
6331 pring->iotag_max = 4096;
6332 pring->lpfc_sli_rcv_async_status =
6333 lpfc_sli_async_event_handler;
6334 pring->num_mask = 4;
6335 pring->prt[0].profile = 0; /* Mask 0 */
6336 pring->prt[0].rctl = FC_ELS_REQ;
6337 pring->prt[0].type = FC_ELS_DATA;
6338 pring->prt[0].lpfc_sli_rcv_unsol_event =
6339 lpfc_els_unsol_event;
6340 pring->prt[1].profile = 0; /* Mask 1 */
6341 pring->prt[1].rctl = FC_ELS_RSP;
6342 pring->prt[1].type = FC_ELS_DATA;
6343 pring->prt[1].lpfc_sli_rcv_unsol_event =
6344 lpfc_els_unsol_event;
6345 pring->prt[2].profile = 0; /* Mask 2 */
6346 /* NameServer Inquiry */
6347 pring->prt[2].rctl = FC_UNSOL_CTL;
6349 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
6350 pring->prt[2].lpfc_sli_rcv_unsol_event =
6351 lpfc_ct_unsol_event;
6352 pring->prt[3].profile = 0; /* Mask 3 */
6353 /* NameServer response */
6354 pring->prt[3].rctl = FC_SOL_CTL;
6356 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
6357 pring->prt[3].lpfc_sli_rcv_unsol_event =
6358 lpfc_ct_unsol_event;
6361 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
6362 (pring->numRiocb * pring->sizeRiocb);
6364 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
6365 /* Too many cmd / rsp ring entries in SLI2 SLIM */
6366 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
6367 "SLI2 SLIM Data: x%x x%lx\n",
6368 phba->brd_no, totiocbsize,
6369 (unsigned long) MAX_SLIM_IOCB_SIZE);
6371 if (phba->cfg_multi_ring_support == 2)
6372 lpfc_extra_ring_setup(phba);
6378 * lpfc_sli_queue_setup - Queue initialization function
6379 * @phba: Pointer to HBA context object.
6381 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
6382 * ring. This function also initializes ring indices of each ring.
6383 * This function is called during the initialization of the SLI
6384 * interface of an HBA.
6385 * This function is called with no lock held and always returns
6389 lpfc_sli_queue_setup(struct lpfc_hba *phba)
6391 struct lpfc_sli *psli;
6392 struct lpfc_sli_ring *pring;
6396 spin_lock_irq(&phba->hbalock);
6397 INIT_LIST_HEAD(&psli->mboxq);
6398 INIT_LIST_HEAD(&psli->mboxq_cmpl);
6399 /* Initialize list headers for txq and txcmplq as double linked lists */
6400 for (i = 0; i < psli->num_rings; i++) {
6401 pring = &psli->ring[i];
6403 pring->next_cmdidx = 0;
6404 pring->local_getidx = 0;
6406 INIT_LIST_HEAD(&pring->txq);
6407 INIT_LIST_HEAD(&pring->txcmplq);
6408 INIT_LIST_HEAD(&pring->iocb_continueq);
6409 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
6410 INIT_LIST_HEAD(&pring->postbufq);
6412 spin_unlock_irq(&phba->hbalock);
6417 * lpfc_sli_host_down - Vport cleanup function
6418 * @vport: Pointer to virtual port object.
6420 * lpfc_sli_host_down is called to clean up the resources
6421 * associated with a vport before destroying virtual
6422 * port data structures.
6423 * This function does following operations:
6424 * - Free discovery resources associated with this virtual
6426 * - Free iocbs associated with this virtual port in
6428 * - Send abort for all iocb commands associated with this
6431 * This function is called with no lock held and always returns 1.
6434 lpfc_sli_host_down(struct lpfc_vport *vport)
6436 LIST_HEAD(completions);
6437 struct lpfc_hba *phba = vport->phba;
6438 struct lpfc_sli *psli = &phba->sli;
6439 struct lpfc_sli_ring *pring;
6440 struct lpfc_iocbq *iocb, *next_iocb;
6442 unsigned long flags = 0;
6443 uint16_t prev_pring_flag;
6445 lpfc_cleanup_discovery_resources(vport);
6447 spin_lock_irqsave(&phba->hbalock, flags);
6448 for (i = 0; i < psli->num_rings; i++) {
6449 pring = &psli->ring[i];
6450 prev_pring_flag = pring->flag;
6451 /* Only slow rings */
6452 if (pring->ringno == LPFC_ELS_RING) {
6453 pring->flag |= LPFC_DEFERRED_RING_EVENT;
6454 /* Set the lpfc data pending flag */
6455 set_bit(LPFC_DATA_READY, &phba->data_flags);
6458 * Error everything on the txq since these iocbs have not been
6459 * given to the FW yet.
6461 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6462 if (iocb->vport != vport)
6464 list_move_tail(&iocb->list, &completions);
6468 /* Next issue ABTS for everything on the txcmplq */
6469 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
6471 if (iocb->vport != vport)
6473 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
6476 pring->flag = prev_pring_flag;
6479 spin_unlock_irqrestore(&phba->hbalock, flags);
6481 /* Cancel all the IOCBs from the completions list */
6482 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6488 * lpfc_sli_hba_down - Resource cleanup function for the HBA
6489 * @phba: Pointer to HBA context object.
6491 * This function cleans up all iocb, buffers, mailbox commands
6492 * while shutting down the HBA. This function is called with no
6493 * lock held and always returns 1.
6494 * This function does the following to cleanup driver resources:
6495 * - Free discovery resources for each virtual port
6496 * - Cleanup any pending fabric iocbs
6497 * - Iterate through the iocb txq and free each entry
6499 * - Free up any buffer posted to the HBA
6500 * - Free mailbox commands in the mailbox queue.
6503 lpfc_sli_hba_down(struct lpfc_hba *phba)
6505 LIST_HEAD(completions);
6506 struct lpfc_sli *psli = &phba->sli;
6507 struct lpfc_sli_ring *pring;
6508 struct lpfc_dmabuf *buf_ptr;
6511 unsigned long flags = 0;
6513 lpfc_hba_down_prep(phba);
6515 lpfc_fabric_abort_hba(phba);
6517 spin_lock_irqsave(&phba->hbalock, flags);
6518 for (i = 0; i < psli->num_rings; i++) {
6519 pring = &psli->ring[i];
6520 /* Only slow rings */
6521 if (pring->ringno == LPFC_ELS_RING) {
6522 pring->flag |= LPFC_DEFERRED_RING_EVENT;
6523 /* Set the lpfc data pending flag */
6524 set_bit(LPFC_DATA_READY, &phba->data_flags);
6528 * Error everything on the txq since these iocbs have not been
6529 * given to the FW yet.
6531 list_splice_init(&pring->txq, &completions);
6535 spin_unlock_irqrestore(&phba->hbalock, flags);
6537 /* Cancel all the IOCBs from the completions list */
6538 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6541 spin_lock_irqsave(&phba->hbalock, flags);
6542 list_splice_init(&phba->elsbuf, &completions);
6543 phba->elsbuf_cnt = 0;
6544 phba->elsbuf_prev_cnt = 0;
6545 spin_unlock_irqrestore(&phba->hbalock, flags);
6547 while (!list_empty(&completions)) {
6548 list_remove_head(&completions, buf_ptr,
6549 struct lpfc_dmabuf, list);
6550 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
6554 /* Return any active mbox cmds */
6555 del_timer_sync(&psli->mbox_tmo);
6557 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
6558 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
6559 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
6565 * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
6566 * @phba: Pointer to HBA context object.
6568 * This function cleans up all queues, iocb, buffers, mailbox commands while
6569 * shutting down the SLI4 HBA FCoE function. This function is called with no
6570 * lock held and always returns 1.
6572 * This function does the following to cleanup driver FCoE function resources:
6573 * - Free discovery resources for each virtual port
6574 * - Cleanup any pending fabric iocbs
6575 * - Iterate through the iocb txq and free each entry in the list.
6576 * - Free up any buffer posted to the HBA.
6577 * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
6578 * - Free mailbox commands in the mailbox queue.
6581 lpfc_sli4_hba_down(struct lpfc_hba *phba)
6583 /* Stop the SLI4 device port */
6584 lpfc_stop_port(phba);
6586 /* Tear down the queues in the HBA */
6587 lpfc_sli4_queue_unset(phba);
6589 /* unregister default FCFI from the HBA */
6590 lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
6596 * lpfc_sli_pcimem_bcopy - SLI memory copy function
6597 * @srcp: Source memory pointer.
6598 * @destp: Destination memory pointer.
6599 * @cnt: Number of words required to be copied.
6601 * This function is used for copying data between driver memory
6602 * and the SLI memory. This function also changes the endianness
6603 * of each word if native endianness is different from SLI
6604 * endianness. This function can be called with or without
6608 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
6610 uint32_t *src = srcp;
6611 uint32_t *dest = destp;
6615 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
6617 ldata = le32_to_cpu(ldata);
6626 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
6627 * @phba: Pointer to HBA context object.
6628 * @pring: Pointer to driver SLI ring object.
6629 * @mp: Pointer to driver buffer object.
6631 * This function is called with no lock held.
6632 * It always return zero after adding the buffer to the postbufq
6636 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6637 struct lpfc_dmabuf *mp)
6639 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
6641 spin_lock_irq(&phba->hbalock);
6642 list_add_tail(&mp->list, &pring->postbufq);
6643 pring->postbufq_cnt++;
6644 spin_unlock_irq(&phba->hbalock);
6649 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
6650 * @phba: Pointer to HBA context object.
6652 * When HBQ is enabled, buffers are searched based on tags. This function
6653 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
6654 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
6655 * does not conflict with tags of buffer posted for unsolicited events.
6656 * The function returns the allocated tag. The function is called with
6660 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
6662 spin_lock_irq(&phba->hbalock);
6663 phba->buffer_tag_count++;
6665 * Always set the QUE_BUFTAG_BIT to distiguish between
6666 * a tag assigned by HBQ.
6668 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
6669 spin_unlock_irq(&phba->hbalock);
6670 return phba->buffer_tag_count;
6674 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
6675 * @phba: Pointer to HBA context object.
6676 * @pring: Pointer to driver SLI ring object.
6679 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
6680 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
6681 * iocb is posted to the response ring with the tag of the buffer.
6682 * This function searches the pring->postbufq list using the tag
6683 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
6684 * iocb. If the buffer is found then lpfc_dmabuf object of the
6685 * buffer is returned to the caller else NULL is returned.
6686 * This function is called with no lock held.
6688 struct lpfc_dmabuf *
6689 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6692 struct lpfc_dmabuf *mp, *next_mp;
6693 struct list_head *slp = &pring->postbufq;
6695 /* Search postbufq, from the begining, looking for a match on tag */
6696 spin_lock_irq(&phba->hbalock);
6697 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
6698 if (mp->buffer_tag == tag) {
6699 list_del_init(&mp->list);
6700 pring->postbufq_cnt--;
6701 spin_unlock_irq(&phba->hbalock);
6706 spin_unlock_irq(&phba->hbalock);
6707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6708 "0402 Cannot find virtual addr for buffer tag on "
6709 "ring %d Data x%lx x%p x%p x%x\n",
6710 pring->ringno, (unsigned long) tag,
6711 slp->next, slp->prev, pring->postbufq_cnt);
6717 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
6718 * @phba: Pointer to HBA context object.
6719 * @pring: Pointer to driver SLI ring object.
6720 * @phys: DMA address of the buffer.
6722 * This function searches the buffer list using the dma_address
6723 * of unsolicited event to find the driver's lpfc_dmabuf object
6724 * corresponding to the dma_address. The function returns the
6725 * lpfc_dmabuf object if a buffer is found else it returns NULL.
6726 * This function is called by the ct and els unsolicited event
6727 * handlers to get the buffer associated with the unsolicited
6730 * This function is called with no lock held.
6732 struct lpfc_dmabuf *
6733 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6736 struct lpfc_dmabuf *mp, *next_mp;
6737 struct list_head *slp = &pring->postbufq;
6739 /* Search postbufq, from the begining, looking for a match on phys */
6740 spin_lock_irq(&phba->hbalock);
6741 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
6742 if (mp->phys == phys) {
6743 list_del_init(&mp->list);
6744 pring->postbufq_cnt--;
6745 spin_unlock_irq(&phba->hbalock);
6750 spin_unlock_irq(&phba->hbalock);
6751 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6752 "0410 Cannot find virtual addr for mapped buf on "
6753 "ring %d Data x%llx x%p x%p x%x\n",
6754 pring->ringno, (unsigned long long)phys,
6755 slp->next, slp->prev, pring->postbufq_cnt);
6760 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
6761 * @phba: Pointer to HBA context object.
6762 * @cmdiocb: Pointer to driver command iocb object.
6763 * @rspiocb: Pointer to driver response iocb object.
6765 * This function is the completion handler for the abort iocbs for
6766 * ELS commands. This function is called from the ELS ring event
6767 * handler with no lock held. This function frees memory resources
6768 * associated with the abort iocb.
6771 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6772 struct lpfc_iocbq *rspiocb)
6774 IOCB_t *irsp = &rspiocb->iocb;
6775 uint16_t abort_iotag, abort_context;
6776 struct lpfc_iocbq *abort_iocb;
6777 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6781 if (irsp->ulpStatus) {
6782 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
6783 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
6785 spin_lock_irq(&phba->hbalock);
6786 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
6787 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
6789 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
6790 "0327 Cannot abort els iocb %p "
6791 "with tag %x context %x, abort status %x, "
6793 abort_iocb, abort_iotag, abort_context,
6794 irsp->ulpStatus, irsp->un.ulpWord[4]);
6797 * If the iocb is not found in Firmware queue the iocb
6798 * might have completed already. Do not free it again.
6800 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
6801 spin_unlock_irq(&phba->hbalock);
6802 lpfc_sli_release_iocbq(phba, cmdiocb);
6806 * make sure we have the right iocbq before taking it
6807 * off the txcmplq and try to call completion routine.
6810 abort_iocb->iocb.ulpContext != abort_context ||
6811 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
6812 spin_unlock_irq(&phba->hbalock);
6814 list_del_init(&abort_iocb->list);
6815 pring->txcmplq_cnt--;
6816 spin_unlock_irq(&phba->hbalock);
6818 /* Firmware could still be in progress of DMAing
6819 * payload, so don't free data buffer till after
6822 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
6824 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
6825 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
6826 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
6827 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
6831 lpfc_sli_release_iocbq(phba, cmdiocb);
6836 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
6837 * @phba: Pointer to HBA context object.
6838 * @cmdiocb: Pointer to driver command iocb object.
6839 * @rspiocb: Pointer to driver response iocb object.
6841 * The function is called from SLI ring event handler with no
6842 * lock held. This function is the completion handler for ELS commands
6843 * which are aborted. The function frees memory resources used for
6844 * the aborted ELS commands.
6847 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6848 struct lpfc_iocbq *rspiocb)
6850 IOCB_t *irsp = &rspiocb->iocb;
6852 /* ELS cmd tag <ulpIoTag> completes */
6853 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
6854 "0139 Ignoring ELS cmd tag x%x completion Data: "
6856 irsp->ulpIoTag, irsp->ulpStatus,
6857 irsp->un.ulpWord[4], irsp->ulpTimeout);
6858 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
6859 lpfc_ct_free_iocb(phba, cmdiocb);
6861 lpfc_els_free_iocb(phba, cmdiocb);
6866 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
6867 * @phba: Pointer to HBA context object.
6868 * @pring: Pointer to driver SLI ring object.
6869 * @cmdiocb: Pointer to driver command iocb object.
6871 * This function issues an abort iocb for the provided command
6872 * iocb. This function is called with hbalock held.
6873 * The function returns 0 when it fails due to memory allocation
6874 * failure or when the command iocb is an abort request.
6877 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6878 struct lpfc_iocbq *cmdiocb)
6880 struct lpfc_vport *vport = cmdiocb->vport;
6881 struct lpfc_iocbq *abtsiocbp;
6882 IOCB_t *icmd = NULL;
6883 IOCB_t *iabt = NULL;
6884 int retval = IOCB_ERROR;
6887 * There are certain command types we don't want to abort. And we
6888 * don't want to abort commands that are already in the process of
6891 icmd = &cmdiocb->iocb;
6892 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
6893 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6894 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
6897 /* If we're unloading, don't abort iocb on the ELS ring, but change the
6898 * callback so that nothing happens when it finishes.
6900 if ((vport->load_flag & FC_UNLOADING) &&
6901 (pring->ringno == LPFC_ELS_RING)) {
6902 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
6903 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
6905 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
6906 goto abort_iotag_exit;
6909 /* issue ABTS for this IOCB based on iotag */
6910 abtsiocbp = __lpfc_sli_get_iocbq(phba);
6911 if (abtsiocbp == NULL)
6914 /* This signals the response to set the correct status
6915 * before calling the completion handler.
6917 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
6919 iabt = &abtsiocbp->iocb;
6920 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
6921 iabt->un.acxri.abortContextTag = icmd->ulpContext;
6922 if (phba->sli_rev == LPFC_SLI_REV4)
6923 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
6925 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
6927 iabt->ulpClass = icmd->ulpClass;
6929 if (phba->link_state >= LPFC_LINK_UP)
6930 iabt->ulpCommand = CMD_ABORT_XRI_CN;
6932 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
6934 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
6936 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
6937 "0339 Abort xri x%x, original iotag x%x, "
6938 "abort cmd iotag x%x\n",
6939 iabt->un.acxri.abortContextTag,
6940 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
6941 retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
6944 __lpfc_sli_release_iocbq(phba, abtsiocbp);
6947 * Caller to this routine should check for IOCB_ERROR
6948 * and handle it properly. This routine no longer removes
6949 * iocb off txcmplq and call compl in case of IOCB_ERROR.
6955 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
6956 * @iocbq: Pointer to driver iocb object.
6957 * @vport: Pointer to driver virtual port object.
6958 * @tgt_id: SCSI ID of the target.
6959 * @lun_id: LUN ID of the scsi device.
6960 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
6962 * This function acts as an iocb filter for functions which abort or count
6963 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
6964 * 0 if the filtering criteria is met for the given iocb and will return
6965 * 1 if the filtering criteria is not met.
6966 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
6967 * given iocb is for the SCSI device specified by vport, tgt_id and
6969 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
6970 * given iocb is for the SCSI target specified by vport and tgt_id
6972 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
6973 * given iocb is for the SCSI host associated with the given vport.
6974 * This function is called with no locks held.
6977 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
6978 uint16_t tgt_id, uint64_t lun_id,
6979 lpfc_ctx_cmd ctx_cmd)
6981 struct lpfc_scsi_buf *lpfc_cmd;
6984 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
6987 if (iocbq->vport != vport)
6990 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
6992 if (lpfc_cmd->pCmd == NULL)
6997 if ((lpfc_cmd->rdata->pnode) &&
6998 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
6999 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
7003 if ((lpfc_cmd->rdata->pnode) &&
7004 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
7011 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
7020 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7021 * @vport: Pointer to virtual port.
7022 * @tgt_id: SCSI ID of the target.
7023 * @lun_id: LUN ID of the scsi device.
7024 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7026 * This function returns number of FCP commands pending for the vport.
7027 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7028 * commands pending on the vport associated with SCSI device specified
7029 * by tgt_id and lun_id parameters.
7030 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7031 * commands pending on the vport associated with SCSI target specified
7032 * by tgt_id parameter.
7033 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7034 * commands pending on the vport.
7035 * This function returns the number of iocbs which satisfy the filter.
7036 * This function is called without any lock held.
7039 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
7040 lpfc_ctx_cmd ctx_cmd)
7042 struct lpfc_hba *phba = vport->phba;
7043 struct lpfc_iocbq *iocbq;
7046 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
7047 iocbq = phba->sli.iocbq_lookup[i];
7049 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
7058 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7059 * @phba: Pointer to HBA context object
7060 * @cmdiocb: Pointer to command iocb object.
7061 * @rspiocb: Pointer to response iocb object.
7063 * This function is called when an aborted FCP iocb completes. This
7064 * function is called by the ring event handler with no lock held.
7065 * This function frees the iocb.
7068 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7069 struct lpfc_iocbq *rspiocb)
7071 lpfc_sli_release_iocbq(phba, cmdiocb);
7076 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
7077 * @vport: Pointer to virtual port.
7078 * @pring: Pointer to driver SLI ring object.
7079 * @tgt_id: SCSI ID of the target.
7080 * @lun_id: LUN ID of the scsi device.
7081 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7083 * This function sends an abort command for every SCSI command
7084 * associated with the given virtual port pending on the ring
7085 * filtered by lpfc_sli_validate_fcp_iocb function.
7086 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
7087 * FCP iocbs associated with lun specified by tgt_id and lun_id
7089 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
7090 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
7091 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
7092 * FCP iocbs associated with virtual port.
7093 * This function returns number of iocbs it failed to abort.
7094 * This function is called with no locks held.
7097 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
7098 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
7100 struct lpfc_hba *phba = vport->phba;
7101 struct lpfc_iocbq *iocbq;
7102 struct lpfc_iocbq *abtsiocb;
7104 int errcnt = 0, ret_val = 0;
7107 for (i = 1; i <= phba->sli.last_iotag; i++) {
7108 iocbq = phba->sli.iocbq_lookup[i];
7110 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
7114 /* issue ABTS for this IOCB based on iotag */
7115 abtsiocb = lpfc_sli_get_iocbq(phba);
7116 if (abtsiocb == NULL) {
7122 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
7123 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
7124 if (phba->sli_rev == LPFC_SLI_REV4)
7125 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
7127 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
7128 abtsiocb->iocb.ulpLe = 1;
7129 abtsiocb->iocb.ulpClass = cmd->ulpClass;
7130 abtsiocb->vport = phba->pport;
7132 if (lpfc_is_link_up(phba))
7133 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
7135 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
7137 /* Setup callback routine and issue the command. */
7138 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
7139 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
7141 if (ret_val == IOCB_ERROR) {
7142 lpfc_sli_release_iocbq(phba, abtsiocb);
7152 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
7153 * @phba: Pointer to HBA context object.
7154 * @cmdiocbq: Pointer to command iocb.
7155 * @rspiocbq: Pointer to response iocb.
7157 * This function is the completion handler for iocbs issued using
7158 * lpfc_sli_issue_iocb_wait function. This function is called by the
7159 * ring event handler function without any lock held. This function
7160 * can be called from both worker thread context and interrupt
7161 * context. This function also can be called from other thread which
7162 * cleans up the SLI layer objects.
7163 * This function copy the contents of the response iocb to the
7164 * response iocb memory object provided by the caller of
7165 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
7166 * sleeps for the iocb completion.
7169 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
7170 struct lpfc_iocbq *cmdiocbq,
7171 struct lpfc_iocbq *rspiocbq)
7173 wait_queue_head_t *pdone_q;
7174 unsigned long iflags;
7176 spin_lock_irqsave(&phba->hbalock, iflags);
7177 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
7178 if (cmdiocbq->context2 && rspiocbq)
7179 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
7180 &rspiocbq->iocb, sizeof(IOCB_t));
7182 pdone_q = cmdiocbq->context_un.wait_queue;
7185 spin_unlock_irqrestore(&phba->hbalock, iflags);
7190 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
7191 * @phba: Pointer to HBA context object..
7192 * @pring: Pointer to sli ring.
7193 * @piocb: Pointer to command iocb.
7194 * @prspiocbq: Pointer to response iocb.
7195 * @timeout: Timeout in number of seconds.
7197 * This function issues the iocb to firmware and waits for the
7198 * iocb to complete. If the iocb command is not
7199 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
7200 * Caller should not free the iocb resources if this function
7201 * returns IOCB_TIMEDOUT.
7202 * The function waits for the iocb completion using an
7203 * non-interruptible wait.
7204 * This function will sleep while waiting for iocb completion.
7205 * So, this function should not be called from any context which
7206 * does not allow sleeping. Due to the same reason, this function
7207 * cannot be called with interrupt disabled.
7208 * This function assumes that the iocb completions occur while
7209 * this function sleep. So, this function cannot be called from
7210 * the thread which process iocb completion for this ring.
7211 * This function clears the iocb_flag of the iocb object before
7212 * issuing the iocb and the iocb completion handler sets this
7213 * flag and wakes this thread when the iocb completes.
7214 * The contents of the response iocb will be copied to prspiocbq
7215 * by the completion handler when the command completes.
7216 * This function returns IOCB_SUCCESS when success.
7217 * This function is called with no lock held.
7220 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
7221 uint32_t ring_number,
7222 struct lpfc_iocbq *piocb,
7223 struct lpfc_iocbq *prspiocbq,
7226 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
7227 long timeleft, timeout_req = 0;
7228 int retval = IOCB_SUCCESS;
7232 * If the caller has provided a response iocbq buffer, then context2
7233 * is NULL or its an error.
7236 if (piocb->context2)
7238 piocb->context2 = prspiocbq;
7241 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
7242 piocb->context_un.wait_queue = &done_q;
7243 piocb->iocb_flag &= ~LPFC_IO_WAKE;
7245 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7246 creg_val = readl(phba->HCregaddr);
7247 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
7248 writel(creg_val, phba->HCregaddr);
7249 readl(phba->HCregaddr); /* flush */
7252 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
7253 if (retval == IOCB_SUCCESS) {
7254 timeout_req = timeout * HZ;
7255 timeleft = wait_event_timeout(done_q,
7256 piocb->iocb_flag & LPFC_IO_WAKE,
7259 if (piocb->iocb_flag & LPFC_IO_WAKE) {
7260 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7261 "0331 IOCB wake signaled\n");
7262 } else if (timeleft == 0) {
7263 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7264 "0338 IOCB wait timeout error - no "
7265 "wake response Data x%x\n", timeout);
7266 retval = IOCB_TIMEDOUT;
7268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7269 "0330 IOCB wake NOT set, "
7271 timeout, (timeleft / jiffies));
7272 retval = IOCB_TIMEDOUT;
7275 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7276 "0332 IOCB wait issue failed, Data x%x\n",
7278 retval = IOCB_ERROR;
7281 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7282 creg_val = readl(phba->HCregaddr);
7283 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
7284 writel(creg_val, phba->HCregaddr);
7285 readl(phba->HCregaddr); /* flush */
7289 piocb->context2 = NULL;
7291 piocb->context_un.wait_queue = NULL;
7292 piocb->iocb_cmpl = NULL;
7297 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
7298 * @phba: Pointer to HBA context object.
7299 * @pmboxq: Pointer to driver mailbox object.
7300 * @timeout: Timeout in number of seconds.
7302 * This function issues the mailbox to firmware and waits for the
7303 * mailbox command to complete. If the mailbox command is not
7304 * completed within timeout seconds, it returns MBX_TIMEOUT.
7305 * The function waits for the mailbox completion using an
7306 * interruptible wait. If the thread is woken up due to a
7307 * signal, MBX_TIMEOUT error is returned to the caller. Caller
7308 * should not free the mailbox resources, if this function returns
7310 * This function will sleep while waiting for mailbox completion.
7311 * So, this function should not be called from any context which
7312 * does not allow sleeping. Due to the same reason, this function
7313 * cannot be called with interrupt disabled.
7314 * This function assumes that the mailbox completion occurs while
7315 * this function sleep. So, this function cannot be called from
7316 * the worker thread which processes mailbox completion.
7317 * This function is called in the context of HBA management
7319 * This function returns MBX_SUCCESS when successful.
7320 * This function is called with no lock held.
7323 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
7326 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
7330 /* The caller must leave context1 empty. */
7331 if (pmboxq->context1)
7332 return MBX_NOT_FINISHED;
7334 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
7335 /* setup wake call as IOCB callback */
7336 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
7337 /* setup context field to pass wait_queue pointer to wake function */
7338 pmboxq->context1 = &done_q;
7340 /* now issue the command */
7341 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
7343 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
7344 wait_event_interruptible_timeout(done_q,
7345 pmboxq->mbox_flag & LPFC_MBX_WAKE,
7348 spin_lock_irqsave(&phba->hbalock, flag);
7349 pmboxq->context1 = NULL;
7351 * if LPFC_MBX_WAKE flag is set the mailbox is completed
7352 * else do not free the resources.
7354 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
7355 retval = MBX_SUCCESS;
7357 retval = MBX_TIMEOUT;
7358 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7360 spin_unlock_irqrestore(&phba->hbalock, flag);
7367 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
7368 * @phba: Pointer to HBA context.
7370 * This function is called to shutdown the driver's mailbox sub-system.
7371 * It first marks the mailbox sub-system is in a block state to prevent
7372 * the asynchronous mailbox command from issued off the pending mailbox
7373 * command queue. If the mailbox command sub-system shutdown is due to
7374 * HBA error conditions such as EEH or ERATT, this routine shall invoke
7375 * the mailbox sub-system flush routine to forcefully bring down the
7376 * mailbox sub-system. Otherwise, if it is due to normal condition (such
7377 * as with offline or HBA function reset), this routine will wait for the
7378 * outstanding mailbox command to complete before invoking the mailbox
7379 * sub-system flush routine to gracefully bring down mailbox sub-system.
7382 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
7384 struct lpfc_sli *psli = &phba->sli;
7385 uint8_t actcmd = MBX_HEARTBEAT;
7386 unsigned long timeout;
7388 spin_lock_irq(&phba->hbalock);
7389 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
7390 spin_unlock_irq(&phba->hbalock);
7392 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7393 spin_lock_irq(&phba->hbalock);
7394 if (phba->sli.mbox_active)
7395 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
7396 spin_unlock_irq(&phba->hbalock);
7397 /* Determine how long we might wait for the active mailbox
7398 * command to be gracefully completed by firmware.
7400 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
7402 while (phba->sli.mbox_active) {
7403 /* Check active mailbox complete status every 2ms */
7405 if (time_after(jiffies, timeout))
7406 /* Timeout, let the mailbox flush routine to
7407 * forcefully release active mailbox command
7412 lpfc_sli_mbox_sys_flush(phba);
7416 * lpfc_sli_eratt_read - read sli-3 error attention events
7417 * @phba: Pointer to HBA context.
7419 * This function is called to read the SLI3 device error attention registers
7420 * for possible error attention events. The caller must hold the hostlock
7421 * with spin_lock_irq().
7423 * This fucntion returns 1 when there is Error Attention in the Host Attention
7424 * Register and returns 0 otherwise.
7427 lpfc_sli_eratt_read(struct lpfc_hba *phba)
7431 /* Read chip Host Attention (HA) register */
7432 ha_copy = readl(phba->HAregaddr);
7433 if (ha_copy & HA_ERATT) {
7434 /* Read host status register to retrieve error event */
7435 lpfc_sli_read_hs(phba);
7437 /* Check if there is a deferred error condition is active */
7438 if ((HS_FFER1 & phba->work_hs) &&
7439 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
7440 HS_FFER6 | HS_FFER7) & phba->work_hs)) {
7441 spin_lock_irq(&phba->hbalock);
7442 phba->hba_flag |= DEFER_ERATT;
7443 spin_unlock_irq(&phba->hbalock);
7444 /* Clear all interrupt enable conditions */
7445 writel(0, phba->HCregaddr);
7446 readl(phba->HCregaddr);
7449 /* Set the driver HA work bitmap */
7450 spin_lock_irq(&phba->hbalock);
7451 phba->work_ha |= HA_ERATT;
7452 /* Indicate polling handles this ERATT */
7453 phba->hba_flag |= HBA_ERATT_HANDLED;
7454 spin_unlock_irq(&phba->hbalock);
7461 * lpfc_sli4_eratt_read - read sli-4 error attention events
7462 * @phba: Pointer to HBA context.
7464 * This function is called to read the SLI4 device error attention registers
7465 * for possible error attention events. The caller must hold the hostlock
7466 * with spin_lock_irq().
7468 * This fucntion returns 1 when there is Error Attention in the Host Attention
7469 * Register and returns 0 otherwise.
7472 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
7474 uint32_t uerr_sta_hi, uerr_sta_lo;
7475 uint32_t onlnreg0, onlnreg1;
7477 /* For now, use the SLI4 device internal unrecoverable error
7478 * registers for error attention. This can be changed later.
7480 onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
7481 onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
7482 if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
7483 uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
7484 uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
7485 if (uerr_sta_lo || uerr_sta_hi) {
7486 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7487 "1423 HBA Unrecoverable error: "
7488 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
7489 "online0_reg=0x%x, online1_reg=0x%x\n",
7490 uerr_sta_lo, uerr_sta_hi,
7491 onlnreg0, onlnreg1);
7492 /* TEMP: as the driver error recover logic is not
7493 * fully developed, we just log the error message
7494 * and the device error attention action is now
7495 * temporarily disabled.
7498 phba->work_status[0] = uerr_sta_lo;
7499 phba->work_status[1] = uerr_sta_hi;
7500 spin_lock_irq(&phba->hbalock);
7501 /* Set the driver HA work bitmap */
7502 phba->work_ha |= HA_ERATT;
7503 /* Indicate polling handles this ERATT */
7504 phba->hba_flag |= HBA_ERATT_HANDLED;
7505 spin_unlock_irq(&phba->hbalock);
7513 * lpfc_sli_check_eratt - check error attention events
7514 * @phba: Pointer to HBA context.
7516 * This function is called from timer soft interrupt context to check HBA's
7517 * error attention register bit for error attention events.
7519 * This fucntion returns 1 when there is Error Attention in the Host Attention
7520 * Register and returns 0 otherwise.
7523 lpfc_sli_check_eratt(struct lpfc_hba *phba)
7527 /* If somebody is waiting to handle an eratt, don't process it
7528 * here. The brdkill function will do this.
7530 if (phba->link_flag & LS_IGNORE_ERATT)
7533 /* Check if interrupt handler handles this ERATT */
7534 spin_lock_irq(&phba->hbalock);
7535 if (phba->hba_flag & HBA_ERATT_HANDLED) {
7536 /* Interrupt handler has handled ERATT */
7537 spin_unlock_irq(&phba->hbalock);
7542 * If there is deferred error attention, do not check for error
7545 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7546 spin_unlock_irq(&phba->hbalock);
7550 /* If PCI channel is offline, don't process it */
7551 if (unlikely(pci_channel_offline(phba->pcidev))) {
7552 spin_unlock_irq(&phba->hbalock);
7556 switch (phba->sli_rev) {
7559 /* Read chip Host Attention (HA) register */
7560 ha_copy = lpfc_sli_eratt_read(phba);
7563 /* Read devcie Uncoverable Error (UERR) registers */
7564 ha_copy = lpfc_sli4_eratt_read(phba);
7567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7568 "0299 Invalid SLI revision (%d)\n",
7573 spin_unlock_irq(&phba->hbalock);
7579 * lpfc_intr_state_check - Check device state for interrupt handling
7580 * @phba: Pointer to HBA context.
7582 * This inline routine checks whether a device or its PCI slot is in a state
7583 * that the interrupt should be handled.
7585 * This function returns 0 if the device or the PCI slot is in a state that
7586 * interrupt should be handled, otherwise -EIO.
7589 lpfc_intr_state_check(struct lpfc_hba *phba)
7591 /* If the pci channel is offline, ignore all the interrupts */
7592 if (unlikely(pci_channel_offline(phba->pcidev)))
7595 /* Update device level interrupt statistics */
7596 phba->sli.slistat.sli_intr++;
7598 /* Ignore all interrupts during initialization. */
7599 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
7606 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
7607 * @irq: Interrupt number.
7608 * @dev_id: The device context pointer.
7610 * This function is directly called from the PCI layer as an interrupt
7611 * service routine when device with SLI-3 interface spec is enabled with
7612 * MSI-X multi-message interrupt mode and there are slow-path events in
7613 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
7614 * interrupt mode, this function is called as part of the device-level
7615 * interrupt handler. When the PCI slot is in error recovery or the HBA
7616 * is undergoing initialization, the interrupt handler will not process
7617 * the interrupt. The link attention and ELS ring attention events are
7618 * handled by the worker thread. The interrupt handler signals the worker
7619 * thread and returns for these events. This function is called without
7620 * any lock held. It gets the hbalock to access and update SLI data
7623 * This function returns IRQ_HANDLED when interrupt is handled else it
7627 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
7629 struct lpfc_hba *phba;
7631 uint32_t work_ha_copy;
7632 unsigned long status;
7633 unsigned long iflag;
7636 MAILBOX_t *mbox, *pmbox;
7637 struct lpfc_vport *vport;
7638 struct lpfc_nodelist *ndlp;
7639 struct lpfc_dmabuf *mp;
7644 * Get the driver's phba structure from the dev_id and
7645 * assume the HBA is not interrupting.
7647 phba = (struct lpfc_hba *)dev_id;
7649 if (unlikely(!phba))
7653 * Stuff needs to be attented to when this function is invoked as an
7654 * individual interrupt handler in MSI-X multi-message interrupt mode
7656 if (phba->intr_type == MSIX) {
7657 /* Check device state for handling interrupt */
7658 if (lpfc_intr_state_check(phba))
7660 /* Need to read HA REG for slow-path events */
7661 spin_lock_irqsave(&phba->hbalock, iflag);
7662 ha_copy = readl(phba->HAregaddr);
7663 /* If somebody is waiting to handle an eratt don't process it
7664 * here. The brdkill function will do this.
7666 if (phba->link_flag & LS_IGNORE_ERATT)
7667 ha_copy &= ~HA_ERATT;
7668 /* Check the need for handling ERATT in interrupt handler */
7669 if (ha_copy & HA_ERATT) {
7670 if (phba->hba_flag & HBA_ERATT_HANDLED)
7671 /* ERATT polling has handled ERATT */
7672 ha_copy &= ~HA_ERATT;
7674 /* Indicate interrupt handler handles ERATT */
7675 phba->hba_flag |= HBA_ERATT_HANDLED;
7679 * If there is deferred error attention, do not check for any
7682 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7683 spin_unlock_irqrestore(&phba->hbalock, iflag);
7687 /* Clear up only attention source related to slow-path */
7688 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
7690 readl(phba->HAregaddr); /* flush */
7691 spin_unlock_irqrestore(&phba->hbalock, iflag);
7693 ha_copy = phba->ha_copy;
7695 work_ha_copy = ha_copy & phba->work_ha_mask;
7698 if (work_ha_copy & HA_LATT) {
7699 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
7701 * Turn off Link Attention interrupts
7702 * until CLEAR_LA done
7704 spin_lock_irqsave(&phba->hbalock, iflag);
7705 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
7706 control = readl(phba->HCregaddr);
7707 control &= ~HC_LAINT_ENA;
7708 writel(control, phba->HCregaddr);
7709 readl(phba->HCregaddr); /* flush */
7710 spin_unlock_irqrestore(&phba->hbalock, iflag);
7713 work_ha_copy &= ~HA_LATT;
7716 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
7718 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
7719 * the only slow ring.
7721 status = (work_ha_copy &
7722 (HA_RXMASK << (4*LPFC_ELS_RING)));
7723 status >>= (4*LPFC_ELS_RING);
7724 if (status & HA_RXMASK) {
7725 spin_lock_irqsave(&phba->hbalock, iflag);
7726 control = readl(phba->HCregaddr);
7728 lpfc_debugfs_slow_ring_trc(phba,
7729 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
7731 (uint32_t)phba->sli.slistat.sli_intr);
7733 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
7734 lpfc_debugfs_slow_ring_trc(phba,
7736 "pwork:x%x hawork:x%x wait:x%x",
7737 phba->work_ha, work_ha_copy,
7738 (uint32_t)((unsigned long)
7739 &phba->work_waitq));
7742 ~(HC_R0INT_ENA << LPFC_ELS_RING);
7743 writel(control, phba->HCregaddr);
7744 readl(phba->HCregaddr); /* flush */
7747 lpfc_debugfs_slow_ring_trc(phba,
7748 "ISR slow ring: pwork:"
7749 "x%x hawork:x%x wait:x%x",
7750 phba->work_ha, work_ha_copy,
7751 (uint32_t)((unsigned long)
7752 &phba->work_waitq));
7754 spin_unlock_irqrestore(&phba->hbalock, iflag);
7757 spin_lock_irqsave(&phba->hbalock, iflag);
7758 if (work_ha_copy & HA_ERATT) {
7759 lpfc_sli_read_hs(phba);
7761 * Check if there is a deferred error condition
7764 if ((HS_FFER1 & phba->work_hs) &&
7765 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
7766 HS_FFER6 | HS_FFER7) & phba->work_hs)) {
7767 phba->hba_flag |= DEFER_ERATT;
7768 /* Clear all interrupt enable conditions */
7769 writel(0, phba->HCregaddr);
7770 readl(phba->HCregaddr);
7774 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
7775 pmb = phba->sli.mbox_active;
7780 /* First check out the status word */
7781 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
7782 if (pmbox->mbxOwner != OWN_HOST) {
7783 spin_unlock_irqrestore(&phba->hbalock, iflag);
7785 * Stray Mailbox Interrupt, mbxCommand <cmd>
7786 * mbxStatus <status>
7788 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
7790 "(%d):0304 Stray Mailbox "
7791 "Interrupt mbxCommand x%x "
7793 (vport ? vport->vpi : 0),
7796 /* clear mailbox attention bit */
7797 work_ha_copy &= ~HA_MBATT;
7799 phba->sli.mbox_active = NULL;
7800 spin_unlock_irqrestore(&phba->hbalock, iflag);
7801 phba->last_completion_time = jiffies;
7802 del_timer(&phba->sli.mbox_tmo);
7803 if (pmb->mbox_cmpl) {
7804 lpfc_sli_pcimem_bcopy(mbox, pmbox,
7807 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
7808 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
7810 lpfc_debugfs_disc_trc(vport,
7811 LPFC_DISC_TRC_MBOX_VPORT,
7813 "status:x%x rpi:x%x",
7814 (uint32_t)pmbox->mbxStatus,
7815 pmbox->un.varWords[0], 0);
7817 if (!pmbox->mbxStatus) {
7818 mp = (struct lpfc_dmabuf *)
7820 ndlp = (struct lpfc_nodelist *)
7823 /* Reg_LOGIN of dflt RPI was
7824 * successful. new lets get
7825 * rid of the RPI using the
7828 lpfc_unreg_login(phba,
7830 pmbox->un.varWords[0],
7833 lpfc_mbx_cmpl_dflt_rpi;
7835 pmb->context2 = ndlp;
7837 rc = lpfc_sli_issue_mbox(phba,
7841 lpfc_printf_log(phba,
7844 "0350 rc should have"
7846 if (rc != MBX_NOT_FINISHED)
7847 goto send_current_mbox;
7851 &phba->pport->work_port_lock,
7853 phba->pport->work_port_events &=
7855 spin_unlock_irqrestore(
7856 &phba->pport->work_port_lock,
7858 lpfc_mbox_cmpl_put(phba, pmb);
7861 spin_unlock_irqrestore(&phba->hbalock, iflag);
7863 if ((work_ha_copy & HA_MBATT) &&
7864 (phba->sli.mbox_active == NULL)) {
7866 /* Process next mailbox command if there is one */
7868 rc = lpfc_sli_issue_mbox(phba, NULL,
7870 } while (rc == MBX_NOT_FINISHED);
7871 if (rc != MBX_SUCCESS)
7872 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
7873 LOG_SLI, "0349 rc should be "
7877 spin_lock_irqsave(&phba->hbalock, iflag);
7878 phba->work_ha |= work_ha_copy;
7879 spin_unlock_irqrestore(&phba->hbalock, iflag);
7880 lpfc_worker_wake_up(phba);
7884 } /* lpfc_sli_sp_intr_handler */
7887 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
7888 * @irq: Interrupt number.
7889 * @dev_id: The device context pointer.
7891 * This function is directly called from the PCI layer as an interrupt
7892 * service routine when device with SLI-3 interface spec is enabled with
7893 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
7894 * ring event in the HBA. However, when the device is enabled with either
7895 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
7896 * device-level interrupt handler. When the PCI slot is in error recovery
7897 * or the HBA is undergoing initialization, the interrupt handler will not
7898 * process the interrupt. The SCSI FCP fast-path ring event are handled in
7899 * the intrrupt context. This function is called without any lock held.
7900 * It gets the hbalock to access and update SLI data structures.
7902 * This function returns IRQ_HANDLED when interrupt is handled else it
7906 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
7908 struct lpfc_hba *phba;
7910 unsigned long status;
7911 unsigned long iflag;
7913 /* Get the driver's phba structure from the dev_id and
7914 * assume the HBA is not interrupting.
7916 phba = (struct lpfc_hba *) dev_id;
7918 if (unlikely(!phba))
7922 * Stuff needs to be attented to when this function is invoked as an
7923 * individual interrupt handler in MSI-X multi-message interrupt mode
7925 if (phba->intr_type == MSIX) {
7926 /* Check device state for handling interrupt */
7927 if (lpfc_intr_state_check(phba))
7929 /* Need to read HA REG for FCP ring and other ring events */
7930 ha_copy = readl(phba->HAregaddr);
7931 /* Clear up only attention source related to fast-path */
7932 spin_lock_irqsave(&phba->hbalock, iflag);
7934 * If there is deferred error attention, do not check for
7937 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7938 spin_unlock_irqrestore(&phba->hbalock, iflag);
7941 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
7943 readl(phba->HAregaddr); /* flush */
7944 spin_unlock_irqrestore(&phba->hbalock, iflag);
7946 ha_copy = phba->ha_copy;
7949 * Process all events on FCP ring. Take the optimized path for FCP IO.
7951 ha_copy &= ~(phba->work_ha_mask);
7953 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
7954 status >>= (4*LPFC_FCP_RING);
7955 if (status & HA_RXMASK)
7956 lpfc_sli_handle_fast_ring_event(phba,
7957 &phba->sli.ring[LPFC_FCP_RING],
7960 if (phba->cfg_multi_ring_support == 2) {
7962 * Process all events on extra ring. Take the optimized path
7963 * for extra ring IO.
7965 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
7966 status >>= (4*LPFC_EXTRA_RING);
7967 if (status & HA_RXMASK) {
7968 lpfc_sli_handle_fast_ring_event(phba,
7969 &phba->sli.ring[LPFC_EXTRA_RING],
7974 } /* lpfc_sli_fp_intr_handler */
7977 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
7978 * @irq: Interrupt number.
7979 * @dev_id: The device context pointer.
7981 * This function is the HBA device-level interrupt handler to device with
7982 * SLI-3 interface spec, called from the PCI layer when either MSI or
7983 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
7984 * requires driver attention. This function invokes the slow-path interrupt
7985 * attention handling function and fast-path interrupt attention handling
7986 * function in turn to process the relevant HBA attention events. This
7987 * function is called without any lock held. It gets the hbalock to access
7988 * and update SLI data structures.
7990 * This function returns IRQ_HANDLED when interrupt is handled, else it
7994 lpfc_sli_intr_handler(int irq, void *dev_id)
7996 struct lpfc_hba *phba;
7997 irqreturn_t sp_irq_rc, fp_irq_rc;
7998 unsigned long status1, status2;
8001 * Get the driver's phba structure from the dev_id and
8002 * assume the HBA is not interrupting.
8004 phba = (struct lpfc_hba *) dev_id;
8006 if (unlikely(!phba))
8009 /* Check device state for handling interrupt */
8010 if (lpfc_intr_state_check(phba))
8013 spin_lock(&phba->hbalock);
8014 phba->ha_copy = readl(phba->HAregaddr);
8015 if (unlikely(!phba->ha_copy)) {
8016 spin_unlock(&phba->hbalock);
8018 } else if (phba->ha_copy & HA_ERATT) {
8019 if (phba->hba_flag & HBA_ERATT_HANDLED)
8020 /* ERATT polling has handled ERATT */
8021 phba->ha_copy &= ~HA_ERATT;
8023 /* Indicate interrupt handler handles ERATT */
8024 phba->hba_flag |= HBA_ERATT_HANDLED;
8028 * If there is deferred error attention, do not check for any interrupt.
8030 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8031 spin_unlock_irq(&phba->hbalock);
8035 /* Clear attention sources except link and error attentions */
8036 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
8037 readl(phba->HAregaddr); /* flush */
8038 spin_unlock(&phba->hbalock);
8041 * Invokes slow-path host attention interrupt handling as appropriate.
8044 /* status of events with mailbox and link attention */
8045 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
8047 /* status of events with ELS ring */
8048 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
8049 status2 >>= (4*LPFC_ELS_RING);
8051 if (status1 || (status2 & HA_RXMASK))
8052 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
8054 sp_irq_rc = IRQ_NONE;
8057 * Invoke fast-path host attention interrupt handling as appropriate.
8060 /* status of events with FCP ring */
8061 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
8062 status1 >>= (4*LPFC_FCP_RING);
8064 /* status of events with extra ring */
8065 if (phba->cfg_multi_ring_support == 2) {
8066 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
8067 status2 >>= (4*LPFC_EXTRA_RING);
8071 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
8072 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
8074 fp_irq_rc = IRQ_NONE;
8076 /* Return device-level interrupt handling status */
8077 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
8078 } /* lpfc_sli_intr_handler */
8081 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
8082 * @phba: pointer to lpfc hba data structure.
8084 * This routine is invoked by the worker thread to process all the pending
8085 * SLI4 FCP abort XRI events.
8087 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
8089 struct lpfc_cq_event *cq_event;
8091 /* First, declare the fcp xri abort event has been handled */
8092 spin_lock_irq(&phba->hbalock);
8093 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
8094 spin_unlock_irq(&phba->hbalock);
8095 /* Now, handle all the fcp xri abort events */
8096 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
8097 /* Get the first event from the head of the event queue */
8098 spin_lock_irq(&phba->hbalock);
8099 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8100 cq_event, struct lpfc_cq_event, list);
8101 spin_unlock_irq(&phba->hbalock);
8102 /* Notify aborted XRI for FCP work queue */
8103 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
8104 /* Free the event processed back to the free pool */
8105 lpfc_sli4_cq_event_release(phba, cq_event);
8110 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
8111 * @phba: pointer to lpfc hba data structure.
8113 * This routine is invoked by the worker thread to process all the pending
8114 * SLI4 els abort xri events.
8116 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
8118 struct lpfc_cq_event *cq_event;
8120 /* First, declare the els xri abort event has been handled */
8121 spin_lock_irq(&phba->hbalock);
8122 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
8123 spin_unlock_irq(&phba->hbalock);
8124 /* Now, handle all the els xri abort events */
8125 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
8126 /* Get the first event from the head of the event queue */
8127 spin_lock_irq(&phba->hbalock);
8128 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8129 cq_event, struct lpfc_cq_event, list);
8130 spin_unlock_irq(&phba->hbalock);
8131 /* Notify aborted XRI for ELS work queue */
8132 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
8133 /* Free the event processed back to the free pool */
8134 lpfc_sli4_cq_event_release(phba, cq_event);
8139 lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
8140 struct lpfc_iocbq *pIocbOut,
8141 struct lpfc_wcqe_complete *wcqe)
8143 size_t offset = offsetof(struct lpfc_iocbq, iocb);
8145 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
8146 sizeof(struct lpfc_iocbq) - offset);
8147 memset(&pIocbIn->sli4_info, 0,
8148 sizeof(struct lpfc_sli4_rspiocb_info));
8149 /* Map WCQE parameters into irspiocb parameters */
8150 pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
8151 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
8152 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
8153 pIocbIn->iocb.un.fcpi.fcpi_parm =
8154 pIocbOut->iocb.un.fcpi.fcpi_parm -
8155 wcqe->total_data_placed;
8157 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8159 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8160 /* Load in additional WCQE parameters */
8161 pIocbIn->sli4_info.hw_status = bf_get(lpfc_wcqe_c_hw_status, wcqe);
8162 pIocbIn->sli4_info.bfield = 0;
8163 if (bf_get(lpfc_wcqe_c_xb, wcqe))
8164 pIocbIn->sli4_info.bfield |= LPFC_XB;
8165 if (bf_get(lpfc_wcqe_c_pv, wcqe)) {
8166 pIocbIn->sli4_info.bfield |= LPFC_PV;
8167 pIocbIn->sli4_info.priority =
8168 bf_get(lpfc_wcqe_c_priority, wcqe);
8173 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
8174 * @phba: Pointer to HBA context object.
8175 * @wcqe: Pointer to work-queue completion queue entry.
8177 * This routine handles an ELS work-queue completion event.
8179 * Return: true if work posted to worker thread, otherwise false.
8182 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
8183 struct lpfc_wcqe_complete *wcqe)
8185 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8186 struct lpfc_iocbq *cmdiocbq;
8187 struct lpfc_iocbq *irspiocbq;
8188 unsigned long iflags;
8189 bool workposted = false;
8191 spin_lock_irqsave(&phba->hbalock, iflags);
8192 pring->stats.iocb_event++;
8193 /* Look up the ELS command IOCB and create pseudo response IOCB */
8194 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
8195 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8196 spin_unlock_irqrestore(&phba->hbalock, iflags);
8198 if (unlikely(!cmdiocbq)) {
8199 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8200 "0386 ELS complete with no corresponding "
8201 "cmdiocb: iotag (%d)\n",
8202 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8206 /* Fake the irspiocbq and copy necessary response information */
8207 irspiocbq = lpfc_sli_get_iocbq(phba);
8209 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8210 "0387 Failed to allocate an iocbq\n");
8213 lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
8215 /* Add the irspiocb to the response IOCB work list */
8216 spin_lock_irqsave(&phba->hbalock, iflags);
8217 list_add_tail(&irspiocbq->list, &phba->sli4_hba.sp_rspiocb_work_queue);
8218 /* Indicate ELS ring attention */
8219 phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
8220 spin_unlock_irqrestore(&phba->hbalock, iflags);
8227 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
8228 * @phba: Pointer to HBA context object.
8229 * @wcqe: Pointer to work-queue completion queue entry.
8231 * This routine handles slow-path WQ entry comsumed event by invoking the
8232 * proper WQ release routine to the slow-path WQ.
8235 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
8236 struct lpfc_wcqe_release *wcqe)
8238 /* Check for the slow-path ELS work queue */
8239 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
8240 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
8241 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
8243 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8244 "2579 Slow-path wqe consume event carries "
8245 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
8246 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
8247 phba->sli4_hba.els_wq->queue_id);
8251 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
8252 * @phba: Pointer to HBA context object.
8253 * @cq: Pointer to a WQ completion queue.
8254 * @wcqe: Pointer to work-queue completion queue entry.
8256 * This routine handles an XRI abort event.
8258 * Return: true if work posted to worker thread, otherwise false.
8261 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
8262 struct lpfc_queue *cq,
8263 struct sli4_wcqe_xri_aborted *wcqe)
8265 bool workposted = false;
8266 struct lpfc_cq_event *cq_event;
8267 unsigned long iflags;
8269 /* Allocate a new internal CQ_EVENT entry */
8270 cq_event = lpfc_sli4_cq_event_alloc(phba);
8272 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8273 "0602 Failed to allocate CQ_EVENT entry\n");
8277 /* Move the CQE into the proper xri abort event list */
8278 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
8279 switch (cq->subtype) {
8281 spin_lock_irqsave(&phba->hbalock, iflags);
8282 list_add_tail(&cq_event->list,
8283 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
8284 /* Set the fcp xri abort event flag */
8285 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
8286 spin_unlock_irqrestore(&phba->hbalock, iflags);
8290 spin_lock_irqsave(&phba->hbalock, iflags);
8291 list_add_tail(&cq_event->list,
8292 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
8293 /* Set the els xri abort event flag */
8294 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
8295 spin_unlock_irqrestore(&phba->hbalock, iflags);
8299 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8300 "0603 Invalid work queue CQE subtype (x%x)\n",
8309 * lpfc_sli4_sp_handle_wcqe - Process a work-queue completion queue entry
8310 * @phba: Pointer to HBA context object.
8311 * @cq: Pointer to the completion queue.
8312 * @wcqe: Pointer to a completion queue entry.
8314 * This routine process a slow-path work-queue completion queue entry.
8316 * Return: true if work posted to worker thread, otherwise false.
8319 lpfc_sli4_sp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
8320 struct lpfc_cqe *cqe)
8322 struct lpfc_wcqe_complete wcqe;
8323 bool workposted = false;
8325 /* Copy the work queue CQE and convert endian order if needed */
8326 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
8328 /* Check and process for different type of WCQE and dispatch */
8329 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
8330 case CQE_CODE_COMPL_WQE:
8331 /* Process the WQ complete event */
8332 workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
8333 (struct lpfc_wcqe_complete *)&wcqe);
8335 case CQE_CODE_RELEASE_WQE:
8336 /* Process the WQ release event */
8337 lpfc_sli4_sp_handle_rel_wcqe(phba,
8338 (struct lpfc_wcqe_release *)&wcqe);
8340 case CQE_CODE_XRI_ABORTED:
8341 /* Process the WQ XRI abort event */
8342 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
8343 (struct sli4_wcqe_xri_aborted *)&wcqe);
8346 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8347 "0388 Not a valid WCQE code: x%x\n",
8348 bf_get(lpfc_wcqe_c_code, &wcqe));
8355 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
8356 * @phba: Pointer to HBA context object.
8357 * @rcqe: Pointer to receive-queue completion queue entry.
8359 * This routine process a receive-queue completion queue entry.
8361 * Return: true if work posted to worker thread, otherwise false.
8364 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
8366 struct lpfc_rcqe rcqe;
8367 bool workposted = false;
8368 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
8369 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
8370 struct hbq_dmabuf *dma_buf;
8372 unsigned long iflags;
8374 /* Copy the receive queue CQE and convert endian order if needed */
8375 lpfc_sli_pcimem_bcopy(cqe, &rcqe, sizeof(struct lpfc_rcqe));
8376 lpfc_sli4_rq_release(hrq, drq);
8377 if (bf_get(lpfc_rcqe_code, &rcqe) != CQE_CODE_RECEIVE)
8379 if (bf_get(lpfc_rcqe_rq_id, &rcqe) != hrq->queue_id)
8382 status = bf_get(lpfc_rcqe_status, &rcqe);
8384 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
8385 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8386 "2537 Receive Frame Truncated!!\n");
8387 case FC_STATUS_RQ_SUCCESS:
8388 spin_lock_irqsave(&phba->hbalock, iflags);
8389 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
8391 spin_unlock_irqrestore(&phba->hbalock, iflags);
8394 memcpy(&dma_buf->rcqe, &rcqe, sizeof(rcqe));
8395 /* save off the frame for the word thread to process */
8396 list_add_tail(&dma_buf->dbuf.list, &phba->rb_pend_list);
8397 /* Frame received */
8398 phba->hba_flag |= HBA_RECEIVE_BUFFER;
8399 spin_unlock_irqrestore(&phba->hbalock, iflags);
8402 case FC_STATUS_INSUFF_BUF_NEED_BUF:
8403 case FC_STATUS_INSUFF_BUF_FRM_DISC:
8404 /* Post more buffers if possible */
8405 spin_lock_irqsave(&phba->hbalock, iflags);
8406 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
8407 spin_unlock_irqrestore(&phba->hbalock, iflags);
8417 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
8418 * @phba: Pointer to HBA context object.
8419 * @eqe: Pointer to fast-path event queue entry.
8421 * This routine process a event queue entry from the slow-path event queue.
8422 * It will check the MajorCode and MinorCode to determine this is for a
8423 * completion event on a completion queue, if not, an error shall be logged
8424 * and just return. Otherwise, it will get to the corresponding completion
8425 * queue and process all the entries on that completion queue, rearm the
8426 * completion queue, and then return.
8430 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
8432 struct lpfc_queue *cq = NULL, *childq, *speq;
8433 struct lpfc_cqe *cqe;
8434 bool workposted = false;
8438 if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
8439 bf_get(lpfc_eqe_minor_code, eqe) != 0) {
8440 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8441 "0359 Not a valid slow-path completion "
8442 "event: majorcode=x%x, minorcode=x%x\n",
8443 bf_get(lpfc_eqe_major_code, eqe),
8444 bf_get(lpfc_eqe_minor_code, eqe));
8448 /* Get the reference to the corresponding CQ */
8449 cqid = bf_get(lpfc_eqe_resource_id, eqe);
8451 /* Search for completion queue pointer matching this cqid */
8452 speq = phba->sli4_hba.sp_eq;
8453 list_for_each_entry(childq, &speq->child_list, list) {
8454 if (childq->queue_id == cqid) {
8459 if (unlikely(!cq)) {
8460 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8461 "0365 Slow-path CQ identifier (%d) does "
8462 "not exist\n", cqid);
8466 /* Process all the entries to the CQ */
8469 while ((cqe = lpfc_sli4_cq_get(cq))) {
8470 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
8471 if (!(++ecount % LPFC_GET_QE_REL_INT))
8472 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
8476 while ((cqe = lpfc_sli4_cq_get(cq))) {
8477 workposted |= lpfc_sli4_sp_handle_wcqe(phba, cq, cqe);
8478 if (!(++ecount % LPFC_GET_QE_REL_INT))
8479 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
8483 while ((cqe = lpfc_sli4_cq_get(cq))) {
8484 workposted |= lpfc_sli4_sp_handle_rcqe(phba, cqe);
8485 if (!(++ecount % LPFC_GET_QE_REL_INT))
8486 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
8490 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8491 "0370 Invalid completion queue type (%d)\n",
8496 /* Catch the no cq entry condition, log an error */
8497 if (unlikely(ecount == 0))
8498 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8499 "0371 No entry from the CQ: identifier "
8500 "(x%x), type (%d)\n", cq->queue_id, cq->type);
8502 /* In any case, flash and re-arm the RCQ */
8503 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
8505 /* wake up worker thread if there are works to be done */
8507 lpfc_worker_wake_up(phba);
8511 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
8512 * @eqe: Pointer to fast-path completion queue entry.
8514 * This routine process a fast-path work queue completion entry from fast-path
8515 * event queue for FCP command response completion.
8518 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
8519 struct lpfc_wcqe_complete *wcqe)
8521 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
8522 struct lpfc_iocbq *cmdiocbq;
8523 struct lpfc_iocbq irspiocbq;
8524 unsigned long iflags;
8526 spin_lock_irqsave(&phba->hbalock, iflags);
8527 pring->stats.iocb_event++;
8528 spin_unlock_irqrestore(&phba->hbalock, iflags);
8530 /* Check for response status */
8531 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
8532 /* If resource errors reported from HBA, reduce queue
8533 * depth of the SCSI device.
8535 if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
8536 IOSTAT_LOCAL_REJECT) &&
8537 (wcqe->parameter == IOERR_NO_RESOURCES)) {
8538 phba->lpfc_rampdown_queue_depth(phba);
8540 /* Log the error status */
8541 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8542 "0373 FCP complete error: status=x%x, "
8543 "hw_status=x%x, total_data_specified=%d, "
8544 "parameter=x%x, word3=x%x\n",
8545 bf_get(lpfc_wcqe_c_status, wcqe),
8546 bf_get(lpfc_wcqe_c_hw_status, wcqe),
8547 wcqe->total_data_placed, wcqe->parameter,
8551 /* Look up the FCP command IOCB and create pseudo response IOCB */
8552 spin_lock_irqsave(&phba->hbalock, iflags);
8553 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
8554 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8555 spin_unlock_irqrestore(&phba->hbalock, iflags);
8556 if (unlikely(!cmdiocbq)) {
8557 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8558 "0374 FCP complete with no corresponding "
8559 "cmdiocb: iotag (%d)\n",
8560 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8563 if (unlikely(!cmdiocbq->iocb_cmpl)) {
8564 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8565 "0375 FCP cmdiocb not callback function "
8567 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8571 /* Fake the irspiocb and copy necessary response information */
8572 lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
8574 /* Pass the cmd_iocb and the rsp state to the upper layer */
8575 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
8579 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
8580 * @phba: Pointer to HBA context object.
8581 * @cq: Pointer to completion queue.
8582 * @wcqe: Pointer to work-queue completion queue entry.
8584 * This routine handles an fast-path WQ entry comsumed event by invoking the
8585 * proper WQ release routine to the slow-path WQ.
8588 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
8589 struct lpfc_wcqe_release *wcqe)
8591 struct lpfc_queue *childwq;
8592 bool wqid_matched = false;
8595 /* Check for fast-path FCP work queue release */
8596 fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
8597 list_for_each_entry(childwq, &cq->child_list, list) {
8598 if (childwq->queue_id == fcp_wqid) {
8599 lpfc_sli4_wq_release(childwq,
8600 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
8601 wqid_matched = true;
8605 /* Report warning log message if no match found */
8606 if (wqid_matched != true)
8607 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8608 "2580 Fast-path wqe consume event carries "
8609 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
8613 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
8614 * @cq: Pointer to the completion queue.
8615 * @eqe: Pointer to fast-path completion queue entry.
8617 * This routine process a fast-path work queue completion entry from fast-path
8618 * event queue for FCP command response completion.
8621 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
8622 struct lpfc_cqe *cqe)
8624 struct lpfc_wcqe_release wcqe;
8625 bool workposted = false;
8627 /* Copy the work queue CQE and convert endian order if needed */
8628 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
8630 /* Check and process for different type of WCQE and dispatch */
8631 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
8632 case CQE_CODE_COMPL_WQE:
8633 /* Process the WQ complete event */
8634 lpfc_sli4_fp_handle_fcp_wcqe(phba,
8635 (struct lpfc_wcqe_complete *)&wcqe);
8637 case CQE_CODE_RELEASE_WQE:
8638 /* Process the WQ release event */
8639 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
8640 (struct lpfc_wcqe_release *)&wcqe);
8642 case CQE_CODE_XRI_ABORTED:
8643 /* Process the WQ XRI abort event */
8644 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
8645 (struct sli4_wcqe_xri_aborted *)&wcqe);
8648 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8649 "0144 Not a valid WCQE code: x%x\n",
8650 bf_get(lpfc_wcqe_c_code, &wcqe));
8657 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
8658 * @phba: Pointer to HBA context object.
8659 * @eqe: Pointer to fast-path event queue entry.
8661 * This routine process a event queue entry from the fast-path event queue.
8662 * It will check the MajorCode and MinorCode to determine this is for a
8663 * completion event on a completion queue, if not, an error shall be logged
8664 * and just return. Otherwise, it will get to the corresponding completion
8665 * queue and process all the entries on the completion queue, rearm the
8666 * completion queue, and then return.
8669 lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
8672 struct lpfc_queue *cq;
8673 struct lpfc_cqe *cqe;
8674 bool workposted = false;
8678 if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
8679 unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
8680 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8681 "0366 Not a valid fast-path completion "
8682 "event: majorcode=x%x, minorcode=x%x\n",
8683 bf_get(lpfc_eqe_major_code, eqe),
8684 bf_get(lpfc_eqe_minor_code, eqe));
8688 cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
8689 if (unlikely(!cq)) {
8690 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8691 "0367 Fast-path completion queue does not "
8696 /* Get the reference to the corresponding CQ */
8697 cqid = bf_get(lpfc_eqe_resource_id, eqe);
8698 if (unlikely(cqid != cq->queue_id)) {
8699 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8700 "0368 Miss-matched fast-path completion "
8701 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
8702 cqid, cq->queue_id);
8706 /* Process all the entries to the CQ */
8707 while ((cqe = lpfc_sli4_cq_get(cq))) {
8708 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
8709 if (!(++ecount % LPFC_GET_QE_REL_INT))
8710 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
8713 /* Catch the no cq entry condition */
8714 if (unlikely(ecount == 0))
8715 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8716 "0369 No entry from fast-path completion "
8717 "queue fcpcqid=%d\n", cq->queue_id);
8719 /* In any case, flash and re-arm the CQ */
8720 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
8722 /* wake up worker thread if there are works to be done */
8724 lpfc_worker_wake_up(phba);
8728 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
8730 struct lpfc_eqe *eqe;
8732 /* walk all the EQ entries and drop on the floor */
8733 while ((eqe = lpfc_sli4_eq_get(eq)))
8736 /* Clear and re-arm the EQ */
8737 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
8741 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
8742 * @irq: Interrupt number.
8743 * @dev_id: The device context pointer.
8745 * This function is directly called from the PCI layer as an interrupt
8746 * service routine when device with SLI-4 interface spec is enabled with
8747 * MSI-X multi-message interrupt mode and there are slow-path events in
8748 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
8749 * interrupt mode, this function is called as part of the device-level
8750 * interrupt handler. When the PCI slot is in error recovery or the HBA is
8751 * undergoing initialization, the interrupt handler will not process the
8752 * interrupt. The link attention and ELS ring attention events are handled
8753 * by the worker thread. The interrupt handler signals the worker thread
8754 * and returns for these events. This function is called without any lock
8755 * held. It gets the hbalock to access and update SLI data structures.
8757 * This function returns IRQ_HANDLED when interrupt is handled else it
8761 lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
8763 struct lpfc_hba *phba;
8764 struct lpfc_queue *speq;
8765 struct lpfc_eqe *eqe;
8766 unsigned long iflag;
8770 * Get the driver's phba structure from the dev_id
8772 phba = (struct lpfc_hba *)dev_id;
8774 if (unlikely(!phba))
8777 /* Get to the EQ struct associated with this vector */
8778 speq = phba->sli4_hba.sp_eq;
8780 /* Check device state for handling interrupt */
8781 if (unlikely(lpfc_intr_state_check(phba))) {
8782 /* Check again for link_state with lock held */
8783 spin_lock_irqsave(&phba->hbalock, iflag);
8784 if (phba->link_state < LPFC_LINK_DOWN)
8785 /* Flush, clear interrupt, and rearm the EQ */
8786 lpfc_sli4_eq_flush(phba, speq);
8787 spin_unlock_irqrestore(&phba->hbalock, iflag);
8792 * Process all the event on FCP slow-path EQ
8794 while ((eqe = lpfc_sli4_eq_get(speq))) {
8795 lpfc_sli4_sp_handle_eqe(phba, eqe);
8796 if (!(++ecount % LPFC_GET_QE_REL_INT))
8797 lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
8800 /* Always clear and re-arm the slow-path EQ */
8801 lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
8803 /* Catch the no cq entry condition */
8804 if (unlikely(ecount == 0)) {
8805 if (phba->intr_type == MSIX)
8806 /* MSI-X treated interrupt served as no EQ share INT */
8807 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8808 "0357 MSI-X interrupt with no EQE\n");
8810 /* Non MSI-X treated on interrupt as EQ share INT */
8815 } /* lpfc_sli4_sp_intr_handler */
8818 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
8819 * @irq: Interrupt number.
8820 * @dev_id: The device context pointer.
8822 * This function is directly called from the PCI layer as an interrupt
8823 * service routine when device with SLI-4 interface spec is enabled with
8824 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8825 * ring event in the HBA. However, when the device is enabled with either
8826 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8827 * device-level interrupt handler. When the PCI slot is in error recovery
8828 * or the HBA is undergoing initialization, the interrupt handler will not
8829 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8830 * the intrrupt context. This function is called without any lock held.
8831 * It gets the hbalock to access and update SLI data structures. Note that,
8832 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
8833 * equal to that of FCP CQ index.
8835 * This function returns IRQ_HANDLED when interrupt is handled else it
8839 lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
8841 struct lpfc_hba *phba;
8842 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
8843 struct lpfc_queue *fpeq;
8844 struct lpfc_eqe *eqe;
8845 unsigned long iflag;
8849 /* Get the driver's phba structure from the dev_id */
8850 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
8851 phba = fcp_eq_hdl->phba;
8852 fcp_eqidx = fcp_eq_hdl->idx;
8854 if (unlikely(!phba))
8857 /* Get to the EQ struct associated with this vector */
8858 fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
8860 /* Check device state for handling interrupt */
8861 if (unlikely(lpfc_intr_state_check(phba))) {
8862 /* Check again for link_state with lock held */
8863 spin_lock_irqsave(&phba->hbalock, iflag);
8864 if (phba->link_state < LPFC_LINK_DOWN)
8865 /* Flush, clear interrupt, and rearm the EQ */
8866 lpfc_sli4_eq_flush(phba, fpeq);
8867 spin_unlock_irqrestore(&phba->hbalock, iflag);
8872 * Process all the event on FCP fast-path EQ
8874 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
8875 lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
8876 if (!(++ecount % LPFC_GET_QE_REL_INT))
8877 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
8880 /* Always clear and re-arm the fast-path EQ */
8881 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
8883 if (unlikely(ecount == 0)) {
8884 if (phba->intr_type == MSIX)
8885 /* MSI-X treated interrupt served as no EQ share INT */
8886 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8887 "0358 MSI-X interrupt with no EQE\n");
8889 /* Non MSI-X treated on interrupt as EQ share INT */
8894 } /* lpfc_sli4_fp_intr_handler */
8897 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
8898 * @irq: Interrupt number.
8899 * @dev_id: The device context pointer.
8901 * This function is the device-level interrupt handler to device with SLI-4
8902 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
8903 * interrupt mode is enabled and there is an event in the HBA which requires
8904 * driver attention. This function invokes the slow-path interrupt attention
8905 * handling function and fast-path interrupt attention handling function in
8906 * turn to process the relevant HBA attention events. This function is called
8907 * without any lock held. It gets the hbalock to access and update SLI data
8910 * This function returns IRQ_HANDLED when interrupt is handled, else it
8914 lpfc_sli4_intr_handler(int irq, void *dev_id)
8916 struct lpfc_hba *phba;
8917 irqreturn_t sp_irq_rc, fp_irq_rc;
8918 bool fp_handled = false;
8921 /* Get the driver's phba structure from the dev_id */
8922 phba = (struct lpfc_hba *)dev_id;
8924 if (unlikely(!phba))
8928 * Invokes slow-path host attention interrupt handling as appropriate.
8930 sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
8933 * Invoke fast-path host attention interrupt handling as appropriate.
8935 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
8936 fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
8937 &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
8938 if (fp_irq_rc == IRQ_HANDLED)
8942 return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
8943 } /* lpfc_sli4_intr_handler */
8946 * lpfc_sli4_queue_free - free a queue structure and associated memory
8947 * @queue: The queue structure to free.
8949 * This function frees a queue structure and the DMAable memeory used for
8950 * the host resident queue. This function must be called after destroying the
8954 lpfc_sli4_queue_free(struct lpfc_queue *queue)
8956 struct lpfc_dmabuf *dmabuf;
8961 while (!list_empty(&queue->page_list)) {
8962 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
8964 dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
8965 dmabuf->virt, dmabuf->phys);
8973 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
8974 * @phba: The HBA that this queue is being created on.
8975 * @entry_size: The size of each queue entry for this queue.
8976 * @entry count: The number of entries that this queue will handle.
8978 * This function allocates a queue structure and the DMAable memory used for
8979 * the host resident queue. This function must be called before creating the
8983 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
8984 uint32_t entry_count)
8986 struct lpfc_queue *queue;
8987 struct lpfc_dmabuf *dmabuf;
8988 int x, total_qe_count;
8992 queue = kzalloc(sizeof(struct lpfc_queue) +
8993 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
8996 queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
8997 INIT_LIST_HEAD(&queue->list);
8998 INIT_LIST_HEAD(&queue->page_list);
8999 INIT_LIST_HEAD(&queue->child_list);
9000 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
9001 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9004 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9005 PAGE_SIZE, &dmabuf->phys,
9007 if (!dmabuf->virt) {
9011 dmabuf->buffer_tag = x;
9012 list_add_tail(&dmabuf->list, &queue->page_list);
9013 /* initialize queue's entry array */
9014 dma_pointer = dmabuf->virt;
9015 for (; total_qe_count < entry_count &&
9016 dma_pointer < (PAGE_SIZE + dmabuf->virt);
9017 total_qe_count++, dma_pointer += entry_size) {
9018 queue->qe[total_qe_count].address = dma_pointer;
9021 queue->entry_size = entry_size;
9022 queue->entry_count = entry_count;
9027 lpfc_sli4_queue_free(queue);
9032 * lpfc_eq_create - Create an Event Queue on the HBA
9033 * @phba: HBA structure that indicates port to create a queue on.
9034 * @eq: The queue structure to use to create the event queue.
9035 * @imax: The maximum interrupt per second limit.
9037 * This function creates an event queue, as detailed in @eq, on a port,
9038 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
9040 * The @phba struct is used to send mailbox command to HBA. The @eq struct
9041 * is used to get the entry count and entry size that are necessary to
9042 * determine the number of pages to allocate and use for this queue. This
9043 * function will send the EQ_CREATE mailbox command to the HBA to setup the
9044 * event queue. This function is asynchronous and will wait for the mailbox
9045 * command to finish before continuing.
9047 * On success this function will return a zero. If unable to allocate enough
9048 * memory this function will return ENOMEM. If the queue create mailbox command
9049 * fails this function will return ENXIO.
9052 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
9054 struct lpfc_mbx_eq_create *eq_create;
9056 int rc, length, status = 0;
9057 struct lpfc_dmabuf *dmabuf;
9058 uint32_t shdr_status, shdr_add_status;
9059 union lpfc_sli4_cfg_shdr *shdr;
9062 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9065 length = (sizeof(struct lpfc_mbx_eq_create) -
9066 sizeof(struct lpfc_sli4_cfg_mhdr));
9067 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9068 LPFC_MBOX_OPCODE_EQ_CREATE,
9069 length, LPFC_SLI4_MBX_EMBED);
9070 eq_create = &mbox->u.mqe.un.eq_create;
9071 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
9073 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
9075 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
9076 /* Calculate delay multiper from maximum interrupt per second */
9077 dmult = LPFC_DMULT_CONST/imax - 1;
9078 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
9080 switch (eq->entry_count) {
9082 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9083 "0360 Unsupported EQ count. (%d)\n",
9085 if (eq->entry_count < 256)
9087 /* otherwise default to smallest count (drop through) */
9089 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9093 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9097 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9101 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9105 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9109 list_for_each_entry(dmabuf, &eq->page_list, list) {
9110 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9111 putPaddrLow(dmabuf->phys);
9112 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9113 putPaddrHigh(dmabuf->phys);
9115 mbox->vport = phba->pport;
9116 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9117 mbox->context1 = NULL;
9118 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9119 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
9120 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9121 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9122 if (shdr_status || shdr_add_status || rc) {
9123 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9124 "2500 EQ_CREATE mailbox failed with "
9125 "status x%x add_status x%x, mbx status x%x\n",
9126 shdr_status, shdr_add_status, rc);
9130 eq->subtype = LPFC_NONE;
9131 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
9132 if (eq->queue_id == 0xFFFF)
9137 if (rc != MBX_TIMEOUT)
9138 mempool_free(mbox, phba->mbox_mem_pool);
9143 * lpfc_cq_create - Create a Completion Queue on the HBA
9144 * @phba: HBA structure that indicates port to create a queue on.
9145 * @cq: The queue structure to use to create the completion queue.
9146 * @eq: The event queue to bind this completion queue to.
9148 * This function creates a completion queue, as detailed in @wq, on a port,
9149 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
9151 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9152 * is used to get the entry count and entry size that are necessary to
9153 * determine the number of pages to allocate and use for this queue. The @eq
9154 * is used to indicate which event queue to bind this completion queue to. This
9155 * function will send the CQ_CREATE mailbox command to the HBA to setup the
9156 * completion queue. This function is asynchronous and will wait for the mailbox
9157 * command to finish before continuing.
9159 * On success this function will return a zero. If unable to allocate enough
9160 * memory this function will return ENOMEM. If the queue create mailbox command
9161 * fails this function will return ENXIO.
9164 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
9165 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
9167 struct lpfc_mbx_cq_create *cq_create;
9168 struct lpfc_dmabuf *dmabuf;
9170 int rc, length, status = 0;
9171 uint32_t shdr_status, shdr_add_status;
9172 union lpfc_sli4_cfg_shdr *shdr;
9174 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9177 length = (sizeof(struct lpfc_mbx_cq_create) -
9178 sizeof(struct lpfc_sli4_cfg_mhdr));
9179 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9180 LPFC_MBOX_OPCODE_CQ_CREATE,
9181 length, LPFC_SLI4_MBX_EMBED);
9182 cq_create = &mbox->u.mqe.un.cq_create;
9183 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
9185 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
9186 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
9187 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
9188 switch (cq->entry_count) {
9190 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9191 "0361 Unsupported CQ count. (%d)\n",
9193 if (cq->entry_count < 256)
9195 /* otherwise default to smallest count (drop through) */
9197 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9201 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9205 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9209 list_for_each_entry(dmabuf, &cq->page_list, list) {
9210 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9211 putPaddrLow(dmabuf->phys);
9212 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9213 putPaddrHigh(dmabuf->phys);
9215 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9217 /* The IOCTL status is embedded in the mailbox subheader. */
9218 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
9219 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9220 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9221 if (shdr_status || shdr_add_status || rc) {
9222 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9223 "2501 CQ_CREATE mailbox failed with "
9224 "status x%x add_status x%x, mbx status x%x\n",
9225 shdr_status, shdr_add_status, rc);
9229 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
9230 if (cq->queue_id == 0xFFFF) {
9234 /* link the cq onto the parent eq child list */
9235 list_add_tail(&cq->list, &eq->child_list);
9236 /* Set up completion queue's type and subtype */
9238 cq->subtype = subtype;
9239 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
9244 if (rc != MBX_TIMEOUT)
9245 mempool_free(mbox, phba->mbox_mem_pool);
9250 * lpfc_wq_create - Create a Work Queue on the HBA
9251 * @phba: HBA structure that indicates port to create a queue on.
9252 * @wq: The queue structure to use to create the work queue.
9253 * @cq: The completion queue to bind this work queue to.
9254 * @subtype: The subtype of the work queue indicating its functionality.
9256 * This function creates a work queue, as detailed in @wq, on a port, described
9257 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
9259 * The @phba struct is used to send mailbox command to HBA. The @wq struct
9260 * is used to get the entry count and entry size that are necessary to
9261 * determine the number of pages to allocate and use for this queue. The @cq
9262 * is used to indicate which completion queue to bind this work queue to. This
9263 * function will send the WQ_CREATE mailbox command to the HBA to setup the
9264 * work queue. This function is asynchronous and will wait for the mailbox
9265 * command to finish before continuing.
9267 * On success this function will return a zero. If unable to allocate enough
9268 * memory this function will return ENOMEM. If the queue create mailbox command
9269 * fails this function will return ENXIO.
9272 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
9273 struct lpfc_queue *cq, uint32_t subtype)
9275 struct lpfc_mbx_wq_create *wq_create;
9276 struct lpfc_dmabuf *dmabuf;
9278 int rc, length, status = 0;
9279 uint32_t shdr_status, shdr_add_status;
9280 union lpfc_sli4_cfg_shdr *shdr;
9282 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9285 length = (sizeof(struct lpfc_mbx_wq_create) -
9286 sizeof(struct lpfc_sli4_cfg_mhdr));
9287 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9288 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
9289 length, LPFC_SLI4_MBX_EMBED);
9290 wq_create = &mbox->u.mqe.un.wq_create;
9291 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
9293 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
9295 list_for_each_entry(dmabuf, &wq->page_list, list) {
9296 wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9297 putPaddrLow(dmabuf->phys);
9298 wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9299 putPaddrHigh(dmabuf->phys);
9301 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9302 /* The IOCTL status is embedded in the mailbox subheader. */
9303 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
9304 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9305 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9306 if (shdr_status || shdr_add_status || rc) {
9307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9308 "2503 WQ_CREATE mailbox failed with "
9309 "status x%x add_status x%x, mbx status x%x\n",
9310 shdr_status, shdr_add_status, rc);
9314 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
9315 if (wq->queue_id == 0xFFFF) {
9320 wq->subtype = subtype;
9324 /* link the wq onto the parent cq child list */
9325 list_add_tail(&wq->list, &cq->child_list);
9327 if (rc == MBX_TIMEOUT)
9328 mempool_free(mbox, phba->mbox_mem_pool);
9333 * lpfc_rq_create - Create a Receive Queue on the HBA
9334 * @phba: HBA structure that indicates port to create a queue on.
9335 * @hrq: The queue structure to use to create the header receive queue.
9336 * @drq: The queue structure to use to create the data receive queue.
9337 * @cq: The completion queue to bind this work queue to.
9339 * This function creates a receive buffer queue pair , as detailed in @hrq and
9340 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
9343 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
9344 * struct is used to get the entry count that is necessary to determine the
9345 * number of pages to use for this queue. The @cq is used to indicate which
9346 * completion queue to bind received buffers that are posted to these queues to.
9347 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
9348 * receive queue pair. This function is asynchronous and will wait for the
9349 * mailbox command to finish before continuing.
9351 * On success this function will return a zero. If unable to allocate enough
9352 * memory this function will return ENOMEM. If the queue create mailbox command
9353 * fails this function will return ENXIO.
9356 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
9357 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
9359 struct lpfc_mbx_rq_create *rq_create;
9360 struct lpfc_dmabuf *dmabuf;
9362 int rc, length, status = 0;
9363 uint32_t shdr_status, shdr_add_status;
9364 union lpfc_sli4_cfg_shdr *shdr;
9366 if (hrq->entry_count != drq->entry_count)
9368 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9371 length = (sizeof(struct lpfc_mbx_rq_create) -
9372 sizeof(struct lpfc_sli4_cfg_mhdr));
9373 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9374 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
9375 length, LPFC_SLI4_MBX_EMBED);
9376 rq_create = &mbox->u.mqe.un.rq_create;
9377 switch (hrq->entry_count) {
9379 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9380 "2535 Unsupported RQ count. (%d)\n",
9382 if (hrq->entry_count < 512)
9384 /* otherwise default to smallest count (drop through) */
9386 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9387 LPFC_RQ_RING_SIZE_512);
9390 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9391 LPFC_RQ_RING_SIZE_1024);
9394 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9395 LPFC_RQ_RING_SIZE_2048);
9398 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9399 LPFC_RQ_RING_SIZE_4096);
9402 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
9404 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
9406 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
9408 list_for_each_entry(dmabuf, &hrq->page_list, list) {
9409 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9410 putPaddrLow(dmabuf->phys);
9411 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9412 putPaddrHigh(dmabuf->phys);
9414 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9415 /* The IOCTL status is embedded in the mailbox subheader. */
9416 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
9417 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9418 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9419 if (shdr_status || shdr_add_status || rc) {
9420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9421 "2504 RQ_CREATE mailbox failed with "
9422 "status x%x add_status x%x, mbx status x%x\n",
9423 shdr_status, shdr_add_status, rc);
9427 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
9428 if (hrq->queue_id == 0xFFFF) {
9432 hrq->type = LPFC_HRQ;
9433 hrq->subtype = subtype;
9434 hrq->host_index = 0;
9437 /* now create the data queue */
9438 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9439 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
9440 length, LPFC_SLI4_MBX_EMBED);
9441 switch (drq->entry_count) {
9443 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9444 "2536 Unsupported RQ count. (%d)\n",
9446 if (drq->entry_count < 512)
9448 /* otherwise default to smallest count (drop through) */
9450 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9451 LPFC_RQ_RING_SIZE_512);
9454 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9455 LPFC_RQ_RING_SIZE_1024);
9458 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9459 LPFC_RQ_RING_SIZE_2048);
9462 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9463 LPFC_RQ_RING_SIZE_4096);
9466 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
9468 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
9470 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
9471 LPFC_DATA_BUF_SIZE);
9472 list_for_each_entry(dmabuf, &drq->page_list, list) {
9473 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9474 putPaddrLow(dmabuf->phys);
9475 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9476 putPaddrHigh(dmabuf->phys);
9478 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9479 /* The IOCTL status is embedded in the mailbox subheader. */
9480 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
9481 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9482 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9483 if (shdr_status || shdr_add_status || rc) {
9487 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
9488 if (drq->queue_id == 0xFFFF) {
9492 drq->type = LPFC_DRQ;
9493 drq->subtype = subtype;
9494 drq->host_index = 0;
9497 /* link the header and data RQs onto the parent cq child list */
9498 list_add_tail(&hrq->list, &cq->child_list);
9499 list_add_tail(&drq->list, &cq->child_list);
9502 if (rc != MBX_TIMEOUT)
9503 mempool_free(mbox, phba->mbox_mem_pool);
9508 * lpfc_eq_destroy - Destroy an event Queue on the HBA
9509 * @eq: The queue structure associated with the queue to destroy.
9511 * This function destroys a queue, as detailed in @eq by sending an mailbox
9512 * command, specific to the type of queue, to the HBA.
9514 * The @eq struct is used to get the queue ID of the queue to destroy.
9516 * On success this function will return a zero. If the queue destroy mailbox
9517 * command fails this function will return ENXIO.
9520 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
9523 int rc, length, status = 0;
9524 uint32_t shdr_status, shdr_add_status;
9525 union lpfc_sli4_cfg_shdr *shdr;
9529 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
9532 length = (sizeof(struct lpfc_mbx_eq_destroy) -
9533 sizeof(struct lpfc_sli4_cfg_mhdr));
9534 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9535 LPFC_MBOX_OPCODE_EQ_DESTROY,
9536 length, LPFC_SLI4_MBX_EMBED);
9537 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
9539 mbox->vport = eq->phba->pport;
9540 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9542 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
9543 /* The IOCTL status is embedded in the mailbox subheader. */
9544 shdr = (union lpfc_sli4_cfg_shdr *)
9545 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
9546 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9547 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9548 if (shdr_status || shdr_add_status || rc) {
9549 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9550 "2505 EQ_DESTROY mailbox failed with "
9551 "status x%x add_status x%x, mbx status x%x\n",
9552 shdr_status, shdr_add_status, rc);
9556 /* Remove eq from any list */
9557 list_del_init(&eq->list);
9558 if (rc != MBX_TIMEOUT)
9559 mempool_free(mbox, eq->phba->mbox_mem_pool);
9564 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
9565 * @cq: The queue structure associated with the queue to destroy.
9567 * This function destroys a queue, as detailed in @cq by sending an mailbox
9568 * command, specific to the type of queue, to the HBA.
9570 * The @cq struct is used to get the queue ID of the queue to destroy.
9572 * On success this function will return a zero. If the queue destroy mailbox
9573 * command fails this function will return ENXIO.
9576 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
9579 int rc, length, status = 0;
9580 uint32_t shdr_status, shdr_add_status;
9581 union lpfc_sli4_cfg_shdr *shdr;
9585 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
9588 length = (sizeof(struct lpfc_mbx_cq_destroy) -
9589 sizeof(struct lpfc_sli4_cfg_mhdr));
9590 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9591 LPFC_MBOX_OPCODE_CQ_DESTROY,
9592 length, LPFC_SLI4_MBX_EMBED);
9593 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
9595 mbox->vport = cq->phba->pport;
9596 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9597 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
9598 /* The IOCTL status is embedded in the mailbox subheader. */
9599 shdr = (union lpfc_sli4_cfg_shdr *)
9600 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
9601 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9602 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9603 if (shdr_status || shdr_add_status || rc) {
9604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9605 "2506 CQ_DESTROY mailbox failed with "
9606 "status x%x add_status x%x, mbx status x%x\n",
9607 shdr_status, shdr_add_status, rc);
9610 /* Remove cq from any list */
9611 list_del_init(&cq->list);
9612 if (rc != MBX_TIMEOUT)
9613 mempool_free(mbox, cq->phba->mbox_mem_pool);
9618 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
9619 * @wq: The queue structure associated with the queue to destroy.
9621 * This function destroys a queue, as detailed in @wq by sending an mailbox
9622 * command, specific to the type of queue, to the HBA.
9624 * The @wq struct is used to get the queue ID of the queue to destroy.
9626 * On success this function will return a zero. If the queue destroy mailbox
9627 * command fails this function will return ENXIO.
9630 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
9633 int rc, length, status = 0;
9634 uint32_t shdr_status, shdr_add_status;
9635 union lpfc_sli4_cfg_shdr *shdr;
9639 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
9642 length = (sizeof(struct lpfc_mbx_wq_destroy) -
9643 sizeof(struct lpfc_sli4_cfg_mhdr));
9644 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9645 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
9646 length, LPFC_SLI4_MBX_EMBED);
9647 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
9649 mbox->vport = wq->phba->pport;
9650 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9651 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
9652 shdr = (union lpfc_sli4_cfg_shdr *)
9653 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
9654 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9655 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9656 if (shdr_status || shdr_add_status || rc) {
9657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9658 "2508 WQ_DESTROY mailbox failed with "
9659 "status x%x add_status x%x, mbx status x%x\n",
9660 shdr_status, shdr_add_status, rc);
9663 /* Remove wq from any list */
9664 list_del_init(&wq->list);
9665 if (rc != MBX_TIMEOUT)
9666 mempool_free(mbox, wq->phba->mbox_mem_pool);
9671 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
9672 * @rq: The queue structure associated with the queue to destroy.
9674 * This function destroys a queue, as detailed in @rq by sending an mailbox
9675 * command, specific to the type of queue, to the HBA.
9677 * The @rq struct is used to get the queue ID of the queue to destroy.
9679 * On success this function will return a zero. If the queue destroy mailbox
9680 * command fails this function will return ENXIO.
9683 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
9684 struct lpfc_queue *drq)
9687 int rc, length, status = 0;
9688 uint32_t shdr_status, shdr_add_status;
9689 union lpfc_sli4_cfg_shdr *shdr;
9693 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
9696 length = (sizeof(struct lpfc_mbx_rq_destroy) -
9697 sizeof(struct mbox_header));
9698 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9699 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
9700 length, LPFC_SLI4_MBX_EMBED);
9701 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
9703 mbox->vport = hrq->phba->pport;
9704 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9705 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
9706 /* The IOCTL status is embedded in the mailbox subheader. */
9707 shdr = (union lpfc_sli4_cfg_shdr *)
9708 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
9709 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9710 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9711 if (shdr_status || shdr_add_status || rc) {
9712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9713 "2509 RQ_DESTROY mailbox failed with "
9714 "status x%x add_status x%x, mbx status x%x\n",
9715 shdr_status, shdr_add_status, rc);
9716 if (rc != MBX_TIMEOUT)
9717 mempool_free(mbox, hrq->phba->mbox_mem_pool);
9720 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
9722 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
9723 shdr = (union lpfc_sli4_cfg_shdr *)
9724 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
9725 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9726 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9727 if (shdr_status || shdr_add_status || rc) {
9728 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9729 "2510 RQ_DESTROY mailbox failed with "
9730 "status x%x add_status x%x, mbx status x%x\n",
9731 shdr_status, shdr_add_status, rc);
9734 list_del_init(&hrq->list);
9735 list_del_init(&drq->list);
9736 if (rc != MBX_TIMEOUT)
9737 mempool_free(mbox, hrq->phba->mbox_mem_pool);
9742 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
9743 * @phba: The virtual port for which this call being executed.
9744 * @pdma_phys_addr0: Physical address of the 1st SGL page.
9745 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
9746 * @xritag: the xritag that ties this io to the SGL pages.
9748 * This routine will post the sgl pages for the IO that has the xritag
9749 * that is in the iocbq structure. The xritag is assigned during iocbq
9750 * creation and persists for as long as the driver is loaded.
9751 * if the caller has fewer than 256 scatter gather segments to map then
9752 * pdma_phys_addr1 should be 0.
9753 * If the caller needs to map more than 256 scatter gather segment then
9754 * pdma_phys_addr1 should be a valid physical address.
9755 * physical address for SGLs must be 64 byte aligned.
9756 * If you are going to map 2 SGL's then the first one must have 256 entries
9757 * the second sgl can have between 1 and 256 entries.
9761 * -ENXIO, -ENOMEM - Failure
9764 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
9765 dma_addr_t pdma_phys_addr0,
9766 dma_addr_t pdma_phys_addr1,
9769 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
9772 uint32_t shdr_status, shdr_add_status;
9773 union lpfc_sli4_cfg_shdr *shdr;
9775 if (xritag == NO_XRI) {
9776 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9777 "0364 Invalid param:\n");
9781 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9785 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9786 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
9787 sizeof(struct lpfc_mbx_post_sgl_pages) -
9788 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
9790 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
9791 &mbox->u.mqe.un.post_sgl_pages;
9792 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
9793 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
9795 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
9796 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
9797 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
9798 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
9800 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
9801 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
9802 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
9803 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
9804 if (!phba->sli4_hba.intr_enable)
9805 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9807 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
9808 /* The IOCTL status is embedded in the mailbox subheader. */
9809 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
9810 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9811 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9812 if (rc != MBX_TIMEOUT)
9813 mempool_free(mbox, phba->mbox_mem_pool);
9814 if (shdr_status || shdr_add_status || rc) {
9815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9816 "2511 POST_SGL mailbox failed with "
9817 "status x%x add_status x%x, mbx status x%x\n",
9818 shdr_status, shdr_add_status, rc);
9824 * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
9825 * @phba: The virtual port for which this call being executed.
9827 * This routine will remove all of the sgl pages registered with the hba.
9831 * -ENXIO, -ENOMEM - Failure
9834 lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
9838 uint32_t shdr_status, shdr_add_status;
9839 union lpfc_sli4_cfg_shdr *shdr;
9841 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9845 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9846 LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
9847 LPFC_SLI4_MBX_EMBED);
9848 if (!phba->sli4_hba.intr_enable)
9849 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9851 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
9852 /* The IOCTL status is embedded in the mailbox subheader. */
9853 shdr = (union lpfc_sli4_cfg_shdr *)
9854 &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
9855 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9856 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9857 if (rc != MBX_TIMEOUT)
9858 mempool_free(mbox, phba->mbox_mem_pool);
9859 if (shdr_status || shdr_add_status || rc) {
9860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9861 "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
9862 "status x%x add_status x%x, mbx status x%x\n",
9863 shdr_status, shdr_add_status, rc);
9870 * lpfc_sli4_next_xritag - Get an xritag for the io
9871 * @phba: Pointer to HBA context object.
9873 * This function gets an xritag for the iocb. If there is no unused xritag
9874 * it will return 0xffff.
9875 * The function returns the allocated xritag if successful, else returns zero.
9876 * Zero is not a valid xritag.
9877 * The caller is not required to hold any lock.
9880 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
9884 spin_lock_irq(&phba->hbalock);
9885 xritag = phba->sli4_hba.next_xri;
9886 if ((xritag != (uint16_t) -1) && xritag <
9887 (phba->sli4_hba.max_cfg_param.max_xri
9888 + phba->sli4_hba.max_cfg_param.xri_base)) {
9889 phba->sli4_hba.next_xri++;
9890 phba->sli4_hba.max_cfg_param.xri_used++;
9891 spin_unlock_irq(&phba->hbalock);
9894 spin_unlock_irq(&phba->hbalock);
9896 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9897 "2004 Failed to allocate XRI.last XRITAG is %d"
9898 " Max XRI is %d, Used XRI is %d\n",
9899 phba->sli4_hba.next_xri,
9900 phba->sli4_hba.max_cfg_param.max_xri,
9901 phba->sli4_hba.max_cfg_param.xri_used);
9906 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
9907 * @phba: pointer to lpfc hba data structure.
9909 * This routine is invoked to post a block of driver's sgl pages to the
9910 * HBA using non-embedded mailbox command. No Lock is held. This routine
9911 * is only called when the driver is loading and after all IO has been
9915 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
9917 struct lpfc_sglq *sglq_entry;
9918 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
9919 struct sgl_page_pairs *sgl_pg_pairs;
9922 uint32_t reqlen, alloclen, pg_pairs;
9924 uint16_t xritag_start = 0;
9925 int els_xri_cnt, rc = 0;
9926 uint32_t shdr_status, shdr_add_status;
9927 union lpfc_sli4_cfg_shdr *shdr;
9929 /* The number of sgls to be posted */
9930 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
9932 reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
9933 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
9934 if (reqlen > PAGE_SIZE) {
9935 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9936 "2559 Block sgl registration required DMA "
9937 "size (%d) great than a page\n", reqlen);
9940 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9942 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9943 "2560 Failed to allocate mbox cmd memory\n");
9947 /* Allocate DMA memory and set up the non-embedded mailbox command */
9948 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9949 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
9950 LPFC_SLI4_MBX_NEMBED);
9952 if (alloclen < reqlen) {
9953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9954 "0285 Allocated DMA memory size (%d) is "
9955 "less than the requested DMA memory "
9956 "size (%d)\n", alloclen, reqlen);
9957 lpfc_sli4_mbox_cmd_free(phba, mbox);
9961 /* Get the first SGE entry from the non-embedded DMA memory */
9962 if (unlikely(!mbox->sge_array)) {
9963 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
9964 "2525 Failed to get the non-embedded SGE "
9965 "virtual address\n");
9966 lpfc_sli4_mbox_cmd_free(phba, mbox);
9969 viraddr = mbox->sge_array->addr[0];
9971 /* Set up the SGL pages in the non-embedded DMA pages */
9972 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
9973 sgl_pg_pairs = &sgl->sgl_pg_pairs;
9975 for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
9976 sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
9977 /* Set up the sge entry */
9978 sgl_pg_pairs->sgl_pg0_addr_lo =
9979 cpu_to_le32(putPaddrLow(sglq_entry->phys));
9980 sgl_pg_pairs->sgl_pg0_addr_hi =
9981 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
9982 sgl_pg_pairs->sgl_pg1_addr_lo =
9983 cpu_to_le32(putPaddrLow(0));
9984 sgl_pg_pairs->sgl_pg1_addr_hi =
9985 cpu_to_le32(putPaddrHigh(0));
9986 /* Keep the first xritag on the list */
9988 xritag_start = sglq_entry->sli4_xritag;
9991 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
9992 pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
9993 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
9994 /* Perform endian conversion if necessary */
9995 sgl->word0 = cpu_to_le32(sgl->word0);
9997 if (!phba->sli4_hba.intr_enable)
9998 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10000 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
10001 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
10003 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
10004 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10005 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10006 if (rc != MBX_TIMEOUT)
10007 lpfc_sli4_mbox_cmd_free(phba, mbox);
10008 if (shdr_status || shdr_add_status || rc) {
10009 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10010 "2513 POST_SGL_BLOCK mailbox command failed "
10011 "status x%x add_status x%x mbx status x%x\n",
10012 shdr_status, shdr_add_status, rc);
10019 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
10020 * @phba: pointer to lpfc hba data structure.
10021 * @sblist: pointer to scsi buffer list.
10022 * @count: number of scsi buffers on the list.
10024 * This routine is invoked to post a block of @count scsi sgl pages from a
10025 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
10030 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
10033 struct lpfc_scsi_buf *psb;
10034 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
10035 struct sgl_page_pairs *sgl_pg_pairs;
10037 LPFC_MBOXQ_t *mbox;
10038 uint32_t reqlen, alloclen, pg_pairs;
10040 uint16_t xritag_start = 0;
10042 uint32_t shdr_status, shdr_add_status;
10043 dma_addr_t pdma_phys_bpl1;
10044 union lpfc_sli4_cfg_shdr *shdr;
10046 /* Calculate the requested length of the dma memory */
10047 reqlen = cnt * sizeof(struct sgl_page_pairs) +
10048 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
10049 if (reqlen > PAGE_SIZE) {
10050 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10051 "0217 Block sgl registration required DMA "
10052 "size (%d) great than a page\n", reqlen);
10055 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10057 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10058 "0283 Failed to allocate mbox cmd memory\n");
10062 /* Allocate DMA memory and set up the non-embedded mailbox command */
10063 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10064 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
10065 LPFC_SLI4_MBX_NEMBED);
10067 if (alloclen < reqlen) {
10068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10069 "2561 Allocated DMA memory size (%d) is "
10070 "less than the requested DMA memory "
10071 "size (%d)\n", alloclen, reqlen);
10072 lpfc_sli4_mbox_cmd_free(phba, mbox);
10076 /* Get the first SGE entry from the non-embedded DMA memory */
10077 if (unlikely(!mbox->sge_array)) {
10078 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
10079 "2565 Failed to get the non-embedded SGE "
10080 "virtual address\n");
10081 lpfc_sli4_mbox_cmd_free(phba, mbox);
10084 viraddr = mbox->sge_array->addr[0];
10086 /* Set up the SGL pages in the non-embedded DMA pages */
10087 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
10088 sgl_pg_pairs = &sgl->sgl_pg_pairs;
10091 list_for_each_entry(psb, sblist, list) {
10092 /* Set up the sge entry */
10093 sgl_pg_pairs->sgl_pg0_addr_lo =
10094 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
10095 sgl_pg_pairs->sgl_pg0_addr_hi =
10096 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
10097 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
10098 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
10100 pdma_phys_bpl1 = 0;
10101 sgl_pg_pairs->sgl_pg1_addr_lo =
10102 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
10103 sgl_pg_pairs->sgl_pg1_addr_hi =
10104 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
10105 /* Keep the first xritag on the list */
10107 xritag_start = psb->cur_iocbq.sli4_xritag;
10111 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
10112 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
10113 /* Perform endian conversion if necessary */
10114 sgl->word0 = cpu_to_le32(sgl->word0);
10116 if (!phba->sli4_hba.intr_enable)
10117 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10119 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
10120 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
10122 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
10123 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10124 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10125 if (rc != MBX_TIMEOUT)
10126 lpfc_sli4_mbox_cmd_free(phba, mbox);
10127 if (shdr_status || shdr_add_status || rc) {
10128 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10129 "2564 POST_SGL_BLOCK mailbox command failed "
10130 "status x%x add_status x%x mbx status x%x\n",
10131 shdr_status, shdr_add_status, rc);
10138 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
10139 * @phba: pointer to lpfc_hba struct that the frame was received on
10140 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10142 * This function checks the fields in the @fc_hdr to see if the FC frame is a
10143 * valid type of frame that the LPFC driver will handle. This function will
10144 * return a zero if the frame is a valid frame or a non zero value when the
10145 * frame does not pass the check.
10148 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
10150 char *rctl_names[] = FC_RCTL_NAMES_INIT;
10151 char *type_names[] = FC_TYPE_NAMES_INIT;
10152 struct fc_vft_header *fc_vft_hdr;
10154 switch (fc_hdr->fh_r_ctl) {
10155 case FC_RCTL_DD_UNCAT: /* uncategorized information */
10156 case FC_RCTL_DD_SOL_DATA: /* solicited data */
10157 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
10158 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
10159 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
10160 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
10161 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
10162 case FC_RCTL_DD_CMD_STATUS: /* command status */
10163 case FC_RCTL_ELS_REQ: /* extended link services request */
10164 case FC_RCTL_ELS_REP: /* extended link services reply */
10165 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
10166 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
10167 case FC_RCTL_BA_NOP: /* basic link service NOP */
10168 case FC_RCTL_BA_ABTS: /* basic link service abort */
10169 case FC_RCTL_BA_RMC: /* remove connection */
10170 case FC_RCTL_BA_ACC: /* basic accept */
10171 case FC_RCTL_BA_RJT: /* basic reject */
10172 case FC_RCTL_BA_PRMT:
10173 case FC_RCTL_ACK_1: /* acknowledge_1 */
10174 case FC_RCTL_ACK_0: /* acknowledge_0 */
10175 case FC_RCTL_P_RJT: /* port reject */
10176 case FC_RCTL_F_RJT: /* fabric reject */
10177 case FC_RCTL_P_BSY: /* port busy */
10178 case FC_RCTL_F_BSY: /* fabric busy to data frame */
10179 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
10180 case FC_RCTL_LCR: /* link credit reset */
10181 case FC_RCTL_END: /* end */
10183 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
10184 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
10185 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
10186 return lpfc_fc_frame_check(phba, fc_hdr);
10190 switch (fc_hdr->fh_type) {
10201 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10202 "2538 Received frame rctl:%s type:%s\n",
10203 rctl_names[fc_hdr->fh_r_ctl],
10204 type_names[fc_hdr->fh_type]);
10207 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
10208 "2539 Dropped frame rctl:%s type:%s\n",
10209 rctl_names[fc_hdr->fh_r_ctl],
10210 type_names[fc_hdr->fh_type]);
10215 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
10216 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10218 * This function processes the FC header to retrieve the VFI from the VF
10219 * header, if one exists. This function will return the VFI if one exists
10220 * or 0 if no VSAN Header exists.
10223 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
10225 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
10227 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
10229 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
10233 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
10234 * @phba: Pointer to the HBA structure to search for the vport on
10235 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10236 * @fcfi: The FC Fabric ID that the frame came from
10238 * This function searches the @phba for a vport that matches the content of the
10239 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
10240 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
10241 * returns the matching vport pointer or NULL if unable to match frame to a
10244 static struct lpfc_vport *
10245 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
10248 struct lpfc_vport **vports;
10249 struct lpfc_vport *vport = NULL;
10251 uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
10252 fc_hdr->fh_d_id[1] << 8 |
10253 fc_hdr->fh_d_id[2]);
10255 vports = lpfc_create_vport_work_array(phba);
10256 if (vports != NULL)
10257 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
10258 if (phba->fcf.fcfi == fcfi &&
10259 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
10260 vports[i]->fc_myDID == did) {
10265 lpfc_destroy_vport_work_array(phba, vports);
10270 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
10271 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
10273 * This function searches through the existing incomplete sequences that have
10274 * been sent to this @vport. If the frame matches one of the incomplete
10275 * sequences then the dbuf in the @dmabuf is added to the list of frames that
10276 * make up that sequence. If no sequence is found that matches this frame then
10277 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
10278 * This function returns a pointer to the first dmabuf in the sequence list that
10279 * the frame was linked to.
10281 static struct hbq_dmabuf *
10282 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
10284 struct fc_frame_header *new_hdr;
10285 struct fc_frame_header *temp_hdr;
10286 struct lpfc_dmabuf *d_buf;
10287 struct lpfc_dmabuf *h_buf;
10288 struct hbq_dmabuf *seq_dmabuf = NULL;
10289 struct hbq_dmabuf *temp_dmabuf = NULL;
10291 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
10292 /* Use the hdr_buf to find the sequence that this frame belongs to */
10293 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
10294 temp_hdr = (struct fc_frame_header *)h_buf->virt;
10295 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
10296 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
10297 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
10299 /* found a pending sequence that matches this frame */
10300 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
10305 * This indicates first frame received for this sequence.
10306 * Queue the buffer on the vport's rcv_buffer_list.
10308 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
10311 temp_hdr = seq_dmabuf->hbuf.virt;
10312 if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
10313 list_add(&seq_dmabuf->dbuf.list, &dmabuf->dbuf.list);
10316 /* find the correct place in the sequence to insert this frame */
10317 list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
10318 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
10319 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
10321 * If the frame's sequence count is greater than the frame on
10322 * the list then insert the frame right after this frame
10324 if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
10325 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
10333 * lpfc_seq_complete - Indicates if a sequence is complete
10334 * @dmabuf: pointer to a dmabuf that describes the FC sequence
10336 * This function checks the sequence, starting with the frame described by
10337 * @dmabuf, to see if all the frames associated with this sequence are present.
10338 * the frames associated with this sequence are linked to the @dmabuf using the
10339 * dbuf list. This function looks for two major things. 1) That the first frame
10340 * has a sequence count of zero. 2) There is a frame with last frame of sequence
10341 * set. 3) That there are no holes in the sequence count. The function will
10342 * return 1 when the sequence is complete, otherwise it will return 0.
10345 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
10347 struct fc_frame_header *hdr;
10348 struct lpfc_dmabuf *d_buf;
10349 struct hbq_dmabuf *seq_dmabuf;
10353 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
10354 /* make sure first fame of sequence has a sequence count of zero */
10355 if (hdr->fh_seq_cnt != seq_count)
10357 fctl = (hdr->fh_f_ctl[0] << 16 |
10358 hdr->fh_f_ctl[1] << 8 |
10360 /* If last frame of sequence we can return success. */
10361 if (fctl & FC_FC_END_SEQ)
10363 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
10364 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
10365 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
10366 /* If there is a hole in the sequence count then fail. */
10367 if (++seq_count != hdr->fh_seq_cnt)
10369 fctl = (hdr->fh_f_ctl[0] << 16 |
10370 hdr->fh_f_ctl[1] << 8 |
10372 /* If last frame of sequence we can return success. */
10373 if (fctl & FC_FC_END_SEQ)
10380 * lpfc_prep_seq - Prep sequence for ULP processing
10381 * @vport: Pointer to the vport on which this sequence was received
10382 * @dmabuf: pointer to a dmabuf that describes the FC sequence
10384 * This function takes a sequence, described by a list of frames, and creates
10385 * a list of iocbq structures to describe the sequence. This iocbq list will be
10386 * used to issue to the generic unsolicited sequence handler. This routine
10387 * returns a pointer to the first iocbq in the list. If the function is unable
10388 * to allocate an iocbq then it throw out the received frames that were not
10389 * able to be described and return a pointer to the first iocbq. If unable to
10390 * allocate any iocbqs (including the first) this function will return NULL.
10392 static struct lpfc_iocbq *
10393 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
10395 struct lpfc_dmabuf *d_buf, *n_buf;
10396 struct lpfc_iocbq *first_iocbq, *iocbq;
10397 struct fc_frame_header *fc_hdr;
10400 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
10401 /* remove from receive buffer list */
10402 list_del_init(&seq_dmabuf->hbuf.list);
10403 /* get the Remote Port's SID */
10404 sid = (fc_hdr->fh_s_id[0] << 16 |
10405 fc_hdr->fh_s_id[1] << 8 |
10406 fc_hdr->fh_s_id[2]);
10407 /* Get an iocbq struct to fill in. */
10408 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
10410 /* Initialize the first IOCB. */
10411 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
10412 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
10413 first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
10414 first_iocbq->iocb.unsli3.rcvsli3.vpi =
10415 vport->vpi + vport->phba->vpi_base;
10416 /* put the first buffer into the first IOCBq */
10417 first_iocbq->context2 = &seq_dmabuf->dbuf;
10418 first_iocbq->context3 = NULL;
10419 first_iocbq->iocb.ulpBdeCount = 1;
10420 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
10421 LPFC_DATA_BUF_SIZE;
10422 first_iocbq->iocb.un.rcvels.remoteID = sid;
10424 iocbq = first_iocbq;
10426 * Each IOCBq can have two Buffers assigned, so go through the list
10427 * of buffers for this sequence and save two buffers in each IOCBq
10429 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
10431 lpfc_in_buf_free(vport->phba, d_buf);
10434 if (!iocbq->context3) {
10435 iocbq->context3 = d_buf;
10436 iocbq->iocb.ulpBdeCount++;
10437 iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
10438 LPFC_DATA_BUF_SIZE;
10440 iocbq = lpfc_sli_get_iocbq(vport->phba);
10443 first_iocbq->iocb.ulpStatus =
10444 IOSTAT_FCP_RSP_ERROR;
10445 first_iocbq->iocb.un.ulpWord[4] =
10446 IOERR_NO_RESOURCES;
10448 lpfc_in_buf_free(vport->phba, d_buf);
10451 iocbq->context2 = d_buf;
10452 iocbq->context3 = NULL;
10453 iocbq->iocb.ulpBdeCount = 1;
10454 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
10455 LPFC_DATA_BUF_SIZE;
10456 iocbq->iocb.un.rcvels.remoteID = sid;
10457 list_add_tail(&iocbq->list, &first_iocbq->list);
10460 return first_iocbq;
10464 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
10465 * @phba: Pointer to HBA context object.
10467 * This function is called with no lock held. This function processes all
10468 * the received buffers and gives it to upper layers when a received buffer
10469 * indicates that it is the final frame in the sequence. The interrupt
10470 * service routine processes received buffers at interrupt contexts and adds
10471 * received dma buffers to the rb_pend_list queue and signals the worker thread.
10472 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
10473 * appropriate receive function when the final frame in a sequence is received.
10476 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba)
10479 struct hbq_dmabuf *dmabuf, *seq_dmabuf;
10480 struct fc_frame_header *fc_hdr;
10481 struct lpfc_vport *vport;
10483 struct lpfc_iocbq *iocbq;
10485 /* Clear hba flag and get all received buffers into the cmplq */
10486 spin_lock_irq(&phba->hbalock);
10487 phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
10488 list_splice_init(&phba->rb_pend_list, &cmplq);
10489 spin_unlock_irq(&phba->hbalock);
10491 /* Process each received buffer */
10492 while ((dmabuf = lpfc_sli_hbqbuf_get(&cmplq)) != NULL) {
10493 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
10494 /* check to see if this a valid type of frame */
10495 if (lpfc_fc_frame_check(phba, fc_hdr)) {
10496 lpfc_in_buf_free(phba, &dmabuf->dbuf);
10499 fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->rcqe);
10500 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
10502 /* throw out the frame */
10503 lpfc_in_buf_free(phba, &dmabuf->dbuf);
10506 /* Link this frame */
10507 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
10509 /* unable to add frame to vport - throw it out */
10510 lpfc_in_buf_free(phba, &dmabuf->dbuf);
10513 /* If not last frame in sequence continue processing frames. */
10514 if (!lpfc_seq_complete(seq_dmabuf)) {
10516 * When saving off frames post a new one and mark this
10517 * frame to be freed when it is finished.
10519 lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
10523 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
10524 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
10525 if (!lpfc_complete_unsol_iocb(phba,
10526 &phba->sli.ring[LPFC_ELS_RING],
10527 iocbq, fc_hdr->fh_r_ctl,
10529 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10530 "2540 Ring %d handler: unexpected Rctl "
10531 "x%x Type x%x received\n",
10533 fc_hdr->fh_r_ctl, fc_hdr->fh_type);