1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <linux/aer.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
48 #include "lpfc_vport.h"
50 /* There are only four IOCB completion types. */
51 typedef enum _lpfc_iocb_type {
59 /* Provide function prototypes local to this module. */
60 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
62 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
63 uint8_t *, uint32_t *);
64 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
66 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
72 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
78 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
79 * @q: The Work Queue to operate on.
80 * @wqe: The work Queue Entry to put on the Work queue.
82 * This routine will copy the contents of @wqe to the next available entry on
83 * the @q. This function will then ring the Work Queue Doorbell to signal the
84 * HBA to start processing the Work Queue Entry. This function returns 0 if
85 * successful. If no entries are available on @q then this function will return
87 * The caller is expected to hold the hbalock when calling this routine.
90 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
92 union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
93 struct lpfc_register doorbell;
96 /* If the host has not yet processed the next entry then we are done */
97 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
99 /* set consumption flag every once in a while */
100 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
101 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
102 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
103 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
104 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
106 /* Update the host index before invoking device */
107 host_index = q->host_index;
108 q->host_index = ((q->host_index + 1) % q->entry_count);
112 bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
113 bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
114 bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
115 writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
116 readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
122 * lpfc_sli4_wq_release - Updates internal hba index for WQ
123 * @q: The Work Queue to operate on.
124 * @index: The index to advance the hba index to.
126 * This routine will update the HBA index of a queue to reflect consumption of
127 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
128 * an entry the host calls this function to update the queue's internal
129 * pointers. This routine returns the number of entries that were consumed by
133 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
135 uint32_t released = 0;
137 if (q->hba_index == index)
140 q->hba_index = ((q->hba_index + 1) % q->entry_count);
142 } while (q->hba_index != index);
147 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
148 * @q: The Mailbox Queue to operate on.
149 * @wqe: The Mailbox Queue Entry to put on the Work queue.
151 * This routine will copy the contents of @mqe to the next available entry on
152 * the @q. This function will then ring the Work Queue Doorbell to signal the
153 * HBA to start processing the Work Queue Entry. This function returns 0 if
154 * successful. If no entries are available on @q then this function will return
156 * The caller is expected to hold the hbalock when calling this routine.
159 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
161 struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
162 struct lpfc_register doorbell;
165 /* If the host has not yet processed the next entry then we are done */
166 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
168 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
169 /* Save off the mailbox pointer for completion */
170 q->phba->mbox = (MAILBOX_t *)temp_mqe;
172 /* Update the host index before invoking device */
173 host_index = q->host_index;
174 q->host_index = ((q->host_index + 1) % q->entry_count);
178 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
179 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
180 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
181 readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
186 * lpfc_sli4_mq_release - Updates internal hba index for MQ
187 * @q: The Mailbox Queue to operate on.
189 * This routine will update the HBA index of a queue to reflect consumption of
190 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
191 * an entry the host calls this function to update the queue's internal
192 * pointers. This routine returns the number of entries that were consumed by
196 lpfc_sli4_mq_release(struct lpfc_queue *q)
198 /* Clear the mailbox pointer for completion */
199 q->phba->mbox = NULL;
200 q->hba_index = ((q->hba_index + 1) % q->entry_count);
205 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
206 * @q: The Event Queue to get the first valid EQE from
208 * This routine will get the first valid Event Queue Entry from @q, update
209 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
210 * the Queue (no more work to do), or the Queue is full of EQEs that have been
211 * processed, but not popped back to the HBA then this routine will return NULL.
213 static struct lpfc_eqe *
214 lpfc_sli4_eq_get(struct lpfc_queue *q)
216 struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
218 /* If the next EQE is not valid then we are done */
219 if (!bf_get_le32(lpfc_eqe_valid, eqe))
221 /* If the host has not yet processed the next entry then we are done */
222 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
225 q->hba_index = ((q->hba_index + 1) % q->entry_count);
230 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
231 * @q: The Event Queue that the host has completed processing for.
232 * @arm: Indicates whether the host wants to arms this CQ.
234 * This routine will mark all Event Queue Entries on @q, from the last
235 * known completed entry to the last entry that was processed, as completed
236 * by clearing the valid bit for each completion queue entry. Then it will
237 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
238 * The internal host index in the @q will be updated by this routine to indicate
239 * that the host has finished processing the entries. The @arm parameter
240 * indicates that the queue should be rearmed when ringing the doorbell.
242 * This function will return the number of EQEs that were popped.
245 lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
247 uint32_t released = 0;
248 struct lpfc_eqe *temp_eqe;
249 struct lpfc_register doorbell;
251 /* while there are valid entries */
252 while (q->hba_index != q->host_index) {
253 temp_eqe = q->qe[q->host_index].eqe;
254 bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
256 q->host_index = ((q->host_index + 1) % q->entry_count);
258 if (unlikely(released == 0 && !arm))
261 /* ring doorbell for number popped */
264 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
265 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
267 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
268 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
269 bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
270 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
271 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
272 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
273 readl(q->phba->sli4_hba.EQCQDBregaddr);
278 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
279 * @q: The Completion Queue to get the first valid CQE from
281 * This routine will get the first valid Completion Queue Entry from @q, update
282 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
283 * the Queue (no more work to do), or the Queue is full of CQEs that have been
284 * processed, but not popped back to the HBA then this routine will return NULL.
286 static struct lpfc_cqe *
287 lpfc_sli4_cq_get(struct lpfc_queue *q)
289 struct lpfc_cqe *cqe;
291 /* If the next CQE is not valid then we are done */
292 if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
294 /* If the host has not yet processed the next entry then we are done */
295 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
298 cqe = q->qe[q->hba_index].cqe;
299 q->hba_index = ((q->hba_index + 1) % q->entry_count);
304 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
305 * @q: The Completion Queue that the host has completed processing for.
306 * @arm: Indicates whether the host wants to arms this CQ.
308 * This routine will mark all Completion queue entries on @q, from the last
309 * known completed entry to the last entry that was processed, as completed
310 * by clearing the valid bit for each completion queue entry. Then it will
311 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
312 * The internal host index in the @q will be updated by this routine to indicate
313 * that the host has finished processing the entries. The @arm parameter
314 * indicates that the queue should be rearmed when ringing the doorbell.
316 * This function will return the number of CQEs that were released.
319 lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
321 uint32_t released = 0;
322 struct lpfc_cqe *temp_qe;
323 struct lpfc_register doorbell;
325 /* while there are valid entries */
326 while (q->hba_index != q->host_index) {
327 temp_qe = q->qe[q->host_index].cqe;
328 bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
330 q->host_index = ((q->host_index + 1) % q->entry_count);
332 if (unlikely(released == 0 && !arm))
335 /* ring doorbell for number popped */
338 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
339 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
340 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
341 bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
342 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
347 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
348 * @q: The Header Receive Queue to operate on.
349 * @wqe: The Receive Queue Entry to put on the Receive queue.
351 * This routine will copy the contents of @wqe to the next available entry on
352 * the @q. This function will then ring the Receive Queue Doorbell to signal the
353 * HBA to start processing the Receive Queue Entry. This function returns the
354 * index that the rqe was copied to if successful. If no entries are available
355 * on @q then this function will return -ENOMEM.
356 * The caller is expected to hold the hbalock when calling this routine.
359 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
360 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
362 struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
363 struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
364 struct lpfc_register doorbell;
365 int put_index = hq->host_index;
367 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
369 if (hq->host_index != dq->host_index)
371 /* If the host has not yet processed the next entry then we are done */
372 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
374 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
375 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
377 /* Update the host index to point to the next slot */
378 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
379 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
381 /* Ring The Header Receive Queue Doorbell */
382 if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
384 bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
386 bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
387 writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
393 * lpfc_sli4_rq_release - Updates internal hba index for RQ
394 * @q: The Header Receive Queue to operate on.
396 * This routine will update the HBA index of a queue to reflect consumption of
397 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
398 * consumed an entry the host calls this function to update the queue's
399 * internal pointers. This routine returns the number of entries that were
400 * consumed by the HBA.
403 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
405 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
407 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
408 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
413 * lpfc_cmd_iocb - Get next command iocb entry in the ring
414 * @phba: Pointer to HBA context object.
415 * @pring: Pointer to driver SLI ring object.
417 * This function returns pointer to next command iocb entry
418 * in the command ring. The caller must hold hbalock to prevent
419 * other threads consume the next command iocb.
420 * SLI-2/SLI-3 provide different sized iocbs.
422 static inline IOCB_t *
423 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
425 return (IOCB_t *) (((char *) pring->cmdringaddr) +
426 pring->cmdidx * phba->iocb_cmd_size);
430 * lpfc_resp_iocb - Get next response iocb entry in the ring
431 * @phba: Pointer to HBA context object.
432 * @pring: Pointer to driver SLI ring object.
434 * This function returns pointer to next response iocb entry
435 * in the response ring. The caller must hold hbalock to make sure
436 * that no other thread consume the next response iocb.
437 * SLI-2/SLI-3 provide different sized iocbs.
439 static inline IOCB_t *
440 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
442 return (IOCB_t *) (((char *) pring->rspringaddr) +
443 pring->rspidx * phba->iocb_rsp_size);
447 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
448 * @phba: Pointer to HBA context object.
450 * This function is called with hbalock held. This function
451 * allocates a new driver iocb object from the iocb pool. If the
452 * allocation is successful, it returns pointer to the newly
453 * allocated iocb object else it returns NULL.
455 static struct lpfc_iocbq *
456 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
458 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
459 struct lpfc_iocbq * iocbq = NULL;
461 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
464 if (phba->iocb_cnt > phba->iocb_max)
465 phba->iocb_max = phba->iocb_cnt;
470 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
471 * @phba: Pointer to HBA context object.
472 * @xritag: XRI value.
474 * This function clears the sglq pointer from the array of acive
475 * sglq's. The xritag that is passed in is used to index into the
476 * array. Before the xritag can be used it needs to be adjusted
477 * by subtracting the xribase.
479 * Returns sglq ponter = success, NULL = Failure.
481 static struct lpfc_sglq *
482 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
484 struct lpfc_sglq *sglq;
486 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
487 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
492 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
493 * @phba: Pointer to HBA context object.
494 * @xritag: XRI value.
496 * This function returns the sglq pointer from the array of acive
497 * sglq's. The xritag that is passed in is used to index into the
498 * array. Before the xritag can be used it needs to be adjusted
499 * by subtracting the xribase.
501 * Returns sglq ponter = success, NULL = Failure.
504 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
506 struct lpfc_sglq *sglq;
508 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
513 * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
514 * @phba: Pointer to HBA context object.
515 * @ndlp: nodelist pointer for this target.
516 * @xritag: xri used in this exchange.
517 * @rxid: Remote Exchange ID.
518 * @send_rrq: Flag used to determine if we should send rrq els cmd.
520 * This function is called with hbalock held.
521 * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
522 * rrq struct and adds it to the active_rrq_list.
524 * returns 0 for rrq slot for this xri
525 * < 0 Were not able to get rrq mem or invalid parameter.
528 __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
529 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
531 struct lpfc_node_rrq *rrq;
539 if (!phba->cfg_enable_rrq)
542 if (phba->pport->load_flag & FC_UNLOADING) {
543 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
549 * set the active bit even if there is no mem available.
551 if (NLP_CHK_FREE_REQ(ndlp))
554 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
557 if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
560 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
562 rrq->send_rrq = send_rrq;
563 rrq->xritag = xritag;
564 rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
566 rrq->nlp_DID = ndlp->nlp_DID;
567 rrq->vport = ndlp->vport;
569 empty = list_empty(&phba->active_rrq_list);
570 rrq->send_rrq = send_rrq;
571 list_add_tail(&rrq->list, &phba->active_rrq_list);
572 if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
573 phba->hba_flag |= HBA_RRQ_ACTIVE;
575 lpfc_worker_wake_up(phba);
580 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
581 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
582 " DID:0x%x Send:%d\n",
583 xritag, rxid, did, send_rrq);
588 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
589 * @phba: Pointer to HBA context object.
590 * @xritag: xri used in this exchange.
591 * @rrq: The RRQ to be cleared.
595 lpfc_clr_rrq_active(struct lpfc_hba *phba,
597 struct lpfc_node_rrq *rrq)
599 struct lpfc_nodelist *ndlp = NULL;
601 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
602 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
604 /* The target DID could have been swapped (cable swap)
605 * we should use the ndlp from the findnode if it is
608 if ((!ndlp) && rrq->ndlp)
614 if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
617 rrq->rrq_stop_time = 0;
620 mempool_free(rrq, phba->rrq_pool);
624 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
625 * @phba: Pointer to HBA context object.
627 * This function is called with hbalock held. This function
628 * Checks if stop_time (ratov from setting rrq active) has
629 * been reached, if it has and the send_rrq flag is set then
630 * it will call lpfc_send_rrq. If the send_rrq flag is not set
631 * then it will just call the routine to clear the rrq and
632 * free the rrq resource.
633 * The timer is set to the next rrq that is going to expire before
634 * leaving the routine.
638 lpfc_handle_rrq_active(struct lpfc_hba *phba)
640 struct lpfc_node_rrq *rrq;
641 struct lpfc_node_rrq *nextrrq;
642 unsigned long next_time;
643 unsigned long iflags;
646 spin_lock_irqsave(&phba->hbalock, iflags);
647 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
648 next_time = jiffies + HZ * (phba->fc_ratov + 1);
649 list_for_each_entry_safe(rrq, nextrrq,
650 &phba->active_rrq_list, list) {
651 if (time_after(jiffies, rrq->rrq_stop_time))
652 list_move(&rrq->list, &send_rrq);
653 else if (time_before(rrq->rrq_stop_time, next_time))
654 next_time = rrq->rrq_stop_time;
656 spin_unlock_irqrestore(&phba->hbalock, iflags);
657 if (!list_empty(&phba->active_rrq_list))
658 mod_timer(&phba->rrq_tmr, next_time);
659 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
660 list_del(&rrq->list);
662 /* this call will free the rrq */
663 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
664 else if (lpfc_send_rrq(phba, rrq)) {
665 /* if we send the rrq then the completion handler
666 * will clear the bit in the xribitmap.
668 lpfc_clr_rrq_active(phba, rrq->xritag,
675 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
676 * @vport: Pointer to vport context object.
677 * @xri: The xri used in the exchange.
678 * @did: The targets DID for this exchange.
680 * returns NULL = rrq not found in the phba->active_rrq_list.
681 * rrq = rrq for this xri and target.
683 struct lpfc_node_rrq *
684 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
686 struct lpfc_hba *phba = vport->phba;
687 struct lpfc_node_rrq *rrq;
688 struct lpfc_node_rrq *nextrrq;
689 unsigned long iflags;
691 if (phba->sli_rev != LPFC_SLI_REV4)
693 spin_lock_irqsave(&phba->hbalock, iflags);
694 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
695 if (rrq->vport == vport && rrq->xritag == xri &&
696 rrq->nlp_DID == did){
697 list_del(&rrq->list);
698 spin_unlock_irqrestore(&phba->hbalock, iflags);
702 spin_unlock_irqrestore(&phba->hbalock, iflags);
707 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
708 * @vport: Pointer to vport context object.
709 * @ndlp: Pointer to the lpfc_node_list structure.
710 * If ndlp is NULL Remove all active RRQs for this vport from the
711 * phba->active_rrq_list and clear the rrq.
712 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
715 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
718 struct lpfc_hba *phba = vport->phba;
719 struct lpfc_node_rrq *rrq;
720 struct lpfc_node_rrq *nextrrq;
721 unsigned long iflags;
724 if (phba->sli_rev != LPFC_SLI_REV4)
727 lpfc_sli4_vport_delete_els_xri_aborted(vport);
728 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
730 spin_lock_irqsave(&phba->hbalock, iflags);
731 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
732 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
733 list_move(&rrq->list, &rrq_list);
734 spin_unlock_irqrestore(&phba->hbalock, iflags);
736 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
737 list_del(&rrq->list);
738 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
743 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
744 * @phba: Pointer to HBA context object.
746 * Remove all rrqs from the phba->active_rrq_list and free them by
747 * calling __lpfc_clr_active_rrq
751 lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
753 struct lpfc_node_rrq *rrq;
754 struct lpfc_node_rrq *nextrrq;
755 unsigned long next_time;
756 unsigned long iflags;
759 if (phba->sli_rev != LPFC_SLI_REV4)
761 spin_lock_irqsave(&phba->hbalock, iflags);
762 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
763 next_time = jiffies + HZ * (phba->fc_ratov * 2);
764 list_splice_init(&phba->active_rrq_list, &rrq_list);
765 spin_unlock_irqrestore(&phba->hbalock, iflags);
767 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
768 list_del(&rrq->list);
769 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
771 if (!list_empty(&phba->active_rrq_list))
772 mod_timer(&phba->rrq_tmr, next_time);
777 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
778 * @phba: Pointer to HBA context object.
779 * @ndlp: Targets nodelist pointer for this exchange.
780 * @xritag the xri in the bitmap to test.
782 * This function is called with hbalock held. This function
783 * returns 0 = rrq not active for this xri
784 * 1 = rrq is valid for this xri.
787 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
792 if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
799 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
800 * @phba: Pointer to HBA context object.
801 * @ndlp: nodelist pointer for this target.
802 * @xritag: xri used in this exchange.
803 * @rxid: Remote Exchange ID.
804 * @send_rrq: Flag used to determine if we should send rrq els cmd.
806 * This function takes the hbalock.
807 * The active bit is always set in the active rrq xri_bitmap even
808 * if there is no slot avaiable for the other rrq information.
810 * returns 0 rrq actived for this xri
811 * < 0 No memory or invalid ndlp.
814 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
815 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
818 unsigned long iflags;
820 spin_lock_irqsave(&phba->hbalock, iflags);
821 ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
822 spin_unlock_irqrestore(&phba->hbalock, iflags);
827 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
828 * @phba: Pointer to HBA context object.
829 * @piocb: Pointer to the iocbq.
831 * This function is called with hbalock held. This function
832 * gets a new driver sglq object from the sglq list. If the
833 * list is not empty then it is successful, it returns pointer to the newly
834 * allocated sglq object else it returns NULL.
836 static struct lpfc_sglq *
837 __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
839 struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
840 struct lpfc_sglq *sglq = NULL;
841 struct lpfc_sglq *start_sglq = NULL;
842 struct lpfc_scsi_buf *lpfc_cmd;
843 struct lpfc_nodelist *ndlp;
846 if (piocbq->iocb_flag & LPFC_IO_FCP) {
847 lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
848 ndlp = lpfc_cmd->rdata->pnode;
849 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
850 !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
851 ndlp = piocbq->context_un.ndlp;
853 ndlp = piocbq->context1;
855 list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
860 if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
861 /* This xri has an rrq outstanding for this DID.
862 * put it back in the list and get another xri.
864 list_add_tail(&sglq->list, lpfc_sgl_list);
866 list_remove_head(lpfc_sgl_list, sglq,
867 struct lpfc_sglq, list);
868 if (sglq == start_sglq) {
876 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
877 sglq->state = SGL_ALLOCATED;
883 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
884 * @phba: Pointer to HBA context object.
886 * This function is called with no lock held. This function
887 * allocates a new driver iocb object from the iocb pool. If the
888 * allocation is successful, it returns pointer to the newly
889 * allocated iocb object else it returns NULL.
892 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
894 struct lpfc_iocbq * iocbq = NULL;
895 unsigned long iflags;
897 spin_lock_irqsave(&phba->hbalock, iflags);
898 iocbq = __lpfc_sli_get_iocbq(phba);
899 spin_unlock_irqrestore(&phba->hbalock, iflags);
904 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
905 * @phba: Pointer to HBA context object.
906 * @iocbq: Pointer to driver iocb object.
908 * This function is called with hbalock held to release driver
909 * iocb object to the iocb pool. The iotag in the iocb object
910 * does not change for each use of the iocb object. This function
911 * clears all other fields of the iocb object when it is freed.
912 * The sqlq structure that holds the xritag and phys and virtual
913 * mappings for the scatter gather list is retrieved from the
914 * active array of sglq. The get of the sglq pointer also clears
915 * the entry in the array. If the status of the IO indiactes that
916 * this IO was aborted then the sglq entry it put on the
917 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
918 * IO has good status or fails for any other reason then the sglq
919 * entry is added to the free list (lpfc_sgl_list).
922 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
924 struct lpfc_sglq *sglq;
925 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
926 unsigned long iflag = 0;
927 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
929 if (iocbq->sli4_xritag == NO_XRI)
932 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
935 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
936 (sglq->state != SGL_XRI_ABORTED)) {
937 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
939 list_add(&sglq->list,
940 &phba->sli4_hba.lpfc_abts_els_sgl_list);
941 spin_unlock_irqrestore(
942 &phba->sli4_hba.abts_sgl_list_lock, iflag);
944 sglq->state = SGL_FREED;
946 list_add_tail(&sglq->list,
947 &phba->sli4_hba.lpfc_sgl_list);
949 /* Check if TXQ queue needs to be serviced */
951 lpfc_worker_wake_up(phba);
957 * Clean all volatile data fields, preserve iotag and node struct.
959 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
960 iocbq->sli4_lxritag = NO_XRI;
961 iocbq->sli4_xritag = NO_XRI;
962 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
967 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
968 * @phba: Pointer to HBA context object.
969 * @iocbq: Pointer to driver iocb object.
971 * This function is called with hbalock held to release driver
972 * iocb object to the iocb pool. The iotag in the iocb object
973 * does not change for each use of the iocb object. This function
974 * clears all other fields of the iocb object when it is freed.
977 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
979 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
982 * Clean all volatile data fields, preserve iotag and node struct.
984 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
985 iocbq->sli4_xritag = NO_XRI;
986 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
990 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
991 * @phba: Pointer to HBA context object.
992 * @iocbq: Pointer to driver iocb object.
994 * This function is called with hbalock held to release driver
995 * iocb object to the iocb pool. The iotag in the iocb object
996 * does not change for each use of the iocb object. This function
997 * clears all other fields of the iocb object when it is freed.
1000 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1002 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1007 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1008 * @phba: Pointer to HBA context object.
1009 * @iocbq: Pointer to driver iocb object.
1011 * This function is called with no lock held to release the iocb to
1015 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1017 unsigned long iflags;
1020 * Clean all volatile data fields, preserve iotag and node struct.
1022 spin_lock_irqsave(&phba->hbalock, iflags);
1023 __lpfc_sli_release_iocbq(phba, iocbq);
1024 spin_unlock_irqrestore(&phba->hbalock, iflags);
1028 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1029 * @phba: Pointer to HBA context object.
1030 * @iocblist: List of IOCBs.
1031 * @ulpstatus: ULP status in IOCB command field.
1032 * @ulpWord4: ULP word-4 in IOCB command field.
1034 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1035 * on the list by invoking the complete callback function associated with the
1036 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1040 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1041 uint32_t ulpstatus, uint32_t ulpWord4)
1043 struct lpfc_iocbq *piocb;
1045 while (!list_empty(iocblist)) {
1046 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1048 if (!piocb->iocb_cmpl)
1049 lpfc_sli_release_iocbq(phba, piocb);
1051 piocb->iocb.ulpStatus = ulpstatus;
1052 piocb->iocb.un.ulpWord[4] = ulpWord4;
1053 (piocb->iocb_cmpl) (phba, piocb, piocb);
1060 * lpfc_sli_iocb_cmd_type - Get the iocb type
1061 * @iocb_cmnd: iocb command code.
1063 * This function is called by ring event handler function to get the iocb type.
1064 * This function translates the iocb command to an iocb command type used to
1065 * decide the final disposition of each completed IOCB.
1066 * The function returns
1067 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1068 * LPFC_SOL_IOCB if it is a solicited iocb completion
1069 * LPFC_ABORT_IOCB if it is an abort iocb
1070 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1072 * The caller is not required to hold any lock.
1074 static lpfc_iocb_type
1075 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1077 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1079 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1082 switch (iocb_cmnd) {
1083 case CMD_XMIT_SEQUENCE_CR:
1084 case CMD_XMIT_SEQUENCE_CX:
1085 case CMD_XMIT_BCAST_CN:
1086 case CMD_XMIT_BCAST_CX:
1087 case CMD_ELS_REQUEST_CR:
1088 case CMD_ELS_REQUEST_CX:
1089 case CMD_CREATE_XRI_CR:
1090 case CMD_CREATE_XRI_CX:
1091 case CMD_GET_RPI_CN:
1092 case CMD_XMIT_ELS_RSP_CX:
1093 case CMD_GET_RPI_CR:
1094 case CMD_FCP_IWRITE_CR:
1095 case CMD_FCP_IWRITE_CX:
1096 case CMD_FCP_IREAD_CR:
1097 case CMD_FCP_IREAD_CX:
1098 case CMD_FCP_ICMND_CR:
1099 case CMD_FCP_ICMND_CX:
1100 case CMD_FCP_TSEND_CX:
1101 case CMD_FCP_TRSP_CX:
1102 case CMD_FCP_TRECEIVE_CX:
1103 case CMD_FCP_AUTO_TRSP_CX:
1104 case CMD_ADAPTER_MSG:
1105 case CMD_ADAPTER_DUMP:
1106 case CMD_XMIT_SEQUENCE64_CR:
1107 case CMD_XMIT_SEQUENCE64_CX:
1108 case CMD_XMIT_BCAST64_CN:
1109 case CMD_XMIT_BCAST64_CX:
1110 case CMD_ELS_REQUEST64_CR:
1111 case CMD_ELS_REQUEST64_CX:
1112 case CMD_FCP_IWRITE64_CR:
1113 case CMD_FCP_IWRITE64_CX:
1114 case CMD_FCP_IREAD64_CR:
1115 case CMD_FCP_IREAD64_CX:
1116 case CMD_FCP_ICMND64_CR:
1117 case CMD_FCP_ICMND64_CX:
1118 case CMD_FCP_TSEND64_CX:
1119 case CMD_FCP_TRSP64_CX:
1120 case CMD_FCP_TRECEIVE64_CX:
1121 case CMD_GEN_REQUEST64_CR:
1122 case CMD_GEN_REQUEST64_CX:
1123 case CMD_XMIT_ELS_RSP64_CX:
1124 case DSSCMD_IWRITE64_CR:
1125 case DSSCMD_IWRITE64_CX:
1126 case DSSCMD_IREAD64_CR:
1127 case DSSCMD_IREAD64_CX:
1128 type = LPFC_SOL_IOCB;
1130 case CMD_ABORT_XRI_CN:
1131 case CMD_ABORT_XRI_CX:
1132 case CMD_CLOSE_XRI_CN:
1133 case CMD_CLOSE_XRI_CX:
1134 case CMD_XRI_ABORTED_CX:
1135 case CMD_ABORT_MXRI64_CN:
1136 case CMD_XMIT_BLS_RSP64_CX:
1137 type = LPFC_ABORT_IOCB;
1139 case CMD_RCV_SEQUENCE_CX:
1140 case CMD_RCV_ELS_REQ_CX:
1141 case CMD_RCV_SEQUENCE64_CX:
1142 case CMD_RCV_ELS_REQ64_CX:
1143 case CMD_ASYNC_STATUS:
1144 case CMD_IOCB_RCV_SEQ64_CX:
1145 case CMD_IOCB_RCV_ELS64_CX:
1146 case CMD_IOCB_RCV_CONT64_CX:
1147 case CMD_IOCB_RET_XRI64_CX:
1148 type = LPFC_UNSOL_IOCB;
1150 case CMD_IOCB_XMIT_MSEQ64_CR:
1151 case CMD_IOCB_XMIT_MSEQ64_CX:
1152 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1153 case CMD_IOCB_RCV_ELS_LIST64_CX:
1154 case CMD_IOCB_CLOSE_EXTENDED_CN:
1155 case CMD_IOCB_ABORT_EXTENDED_CN:
1156 case CMD_IOCB_RET_HBQE64_CN:
1157 case CMD_IOCB_FCP_IBIDIR64_CR:
1158 case CMD_IOCB_FCP_IBIDIR64_CX:
1159 case CMD_IOCB_FCP_ITASKMGT64_CX:
1160 case CMD_IOCB_LOGENTRY_CN:
1161 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1162 printk("%s - Unhandled SLI-3 Command x%x\n",
1163 __func__, iocb_cmnd);
1164 type = LPFC_UNKNOWN_IOCB;
1167 type = LPFC_UNKNOWN_IOCB;
1175 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1176 * @phba: Pointer to HBA context object.
1178 * This function is called from SLI initialization code
1179 * to configure every ring of the HBA's SLI interface. The
1180 * caller is not required to hold any lock. This function issues
1181 * a config_ring mailbox command for each ring.
1182 * This function returns zero if successful else returns a negative
1186 lpfc_sli_ring_map(struct lpfc_hba *phba)
1188 struct lpfc_sli *psli = &phba->sli;
1193 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1197 phba->link_state = LPFC_INIT_MBX_CMDS;
1198 for (i = 0; i < psli->num_rings; i++) {
1199 lpfc_config_ring(phba, i, pmb);
1200 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1201 if (rc != MBX_SUCCESS) {
1202 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1203 "0446 Adapter failed to init (%d), "
1204 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1206 rc, pmbox->mbxCommand,
1207 pmbox->mbxStatus, i);
1208 phba->link_state = LPFC_HBA_ERROR;
1213 mempool_free(pmb, phba->mbox_mem_pool);
1218 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1219 * @phba: Pointer to HBA context object.
1220 * @pring: Pointer to driver SLI ring object.
1221 * @piocb: Pointer to the driver iocb object.
1223 * This function is called with hbalock held. The function adds the
1224 * new iocb to txcmplq of the given ring. This function always returns
1225 * 0. If this function is called for ELS ring, this function checks if
1226 * there is a vport associated with the ELS command. This function also
1227 * starts els_tmofunc timer if this is an ELS command.
1230 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1231 struct lpfc_iocbq *piocb)
1233 list_add_tail(&piocb->list, &pring->txcmplq);
1234 piocb->iocb_flag |= LPFC_IO_ON_Q;
1235 pring->txcmplq_cnt++;
1236 if (pring->txcmplq_cnt > pring->txcmplq_max)
1237 pring->txcmplq_max = pring->txcmplq_cnt;
1239 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1240 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1241 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1245 mod_timer(&piocb->vport->els_tmofunc,
1246 jiffies + HZ * (phba->fc_ratov << 1));
1254 * lpfc_sli_ringtx_get - Get first element of the txq
1255 * @phba: Pointer to HBA context object.
1256 * @pring: Pointer to driver SLI ring object.
1258 * This function is called with hbalock held to get next
1259 * iocb in txq of the given ring. If there is any iocb in
1260 * the txq, the function returns first iocb in the list after
1261 * removing the iocb from the list, else it returns NULL.
1264 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1266 struct lpfc_iocbq *cmd_iocb;
1268 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1269 if (cmd_iocb != NULL)
1275 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1276 * @phba: Pointer to HBA context object.
1277 * @pring: Pointer to driver SLI ring object.
1279 * This function is called with hbalock held and the caller must post the
1280 * iocb without releasing the lock. If the caller releases the lock,
1281 * iocb slot returned by the function is not guaranteed to be available.
1282 * The function returns pointer to the next available iocb slot if there
1283 * is available slot in the ring, else it returns NULL.
1284 * If the get index of the ring is ahead of the put index, the function
1285 * will post an error attention event to the worker thread to take the
1286 * HBA to offline state.
1289 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1291 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1292 uint32_t max_cmd_idx = pring->numCiocb;
1293 if ((pring->next_cmdidx == pring->cmdidx) &&
1294 (++pring->next_cmdidx >= max_cmd_idx))
1295 pring->next_cmdidx = 0;
1297 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
1299 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1301 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
1302 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1303 "0315 Ring %d issue: portCmdGet %d "
1304 "is bigger than cmd ring %d\n",
1306 pring->local_getidx, max_cmd_idx);
1308 phba->link_state = LPFC_HBA_ERROR;
1310 * All error attention handlers are posted to
1313 phba->work_ha |= HA_ERATT;
1314 phba->work_hs = HS_FFER3;
1316 lpfc_worker_wake_up(phba);
1321 if (pring->local_getidx == pring->next_cmdidx)
1325 return lpfc_cmd_iocb(phba, pring);
1329 * lpfc_sli_next_iotag - Get an iotag for the iocb
1330 * @phba: Pointer to HBA context object.
1331 * @iocbq: Pointer to driver iocb object.
1333 * This function gets an iotag for the iocb. If there is no unused iotag and
1334 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1335 * array and assigns a new iotag.
1336 * The function returns the allocated iotag if successful, else returns zero.
1337 * Zero is not a valid iotag.
1338 * The caller is not required to hold any lock.
1341 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1343 struct lpfc_iocbq **new_arr;
1344 struct lpfc_iocbq **old_arr;
1346 struct lpfc_sli *psli = &phba->sli;
1349 spin_lock_irq(&phba->hbalock);
1350 iotag = psli->last_iotag;
1351 if(++iotag < psli->iocbq_lookup_len) {
1352 psli->last_iotag = iotag;
1353 psli->iocbq_lookup[iotag] = iocbq;
1354 spin_unlock_irq(&phba->hbalock);
1355 iocbq->iotag = iotag;
1357 } else if (psli->iocbq_lookup_len < (0xffff
1358 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1359 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1360 spin_unlock_irq(&phba->hbalock);
1361 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
1364 spin_lock_irq(&phba->hbalock);
1365 old_arr = psli->iocbq_lookup;
1366 if (new_len <= psli->iocbq_lookup_len) {
1367 /* highly unprobable case */
1369 iotag = psli->last_iotag;
1370 if(++iotag < psli->iocbq_lookup_len) {
1371 psli->last_iotag = iotag;
1372 psli->iocbq_lookup[iotag] = iocbq;
1373 spin_unlock_irq(&phba->hbalock);
1374 iocbq->iotag = iotag;
1377 spin_unlock_irq(&phba->hbalock);
1380 if (psli->iocbq_lookup)
1381 memcpy(new_arr, old_arr,
1382 ((psli->last_iotag + 1) *
1383 sizeof (struct lpfc_iocbq *)));
1384 psli->iocbq_lookup = new_arr;
1385 psli->iocbq_lookup_len = new_len;
1386 psli->last_iotag = iotag;
1387 psli->iocbq_lookup[iotag] = iocbq;
1388 spin_unlock_irq(&phba->hbalock);
1389 iocbq->iotag = iotag;
1394 spin_unlock_irq(&phba->hbalock);
1396 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1397 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1404 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1405 * @phba: Pointer to HBA context object.
1406 * @pring: Pointer to driver SLI ring object.
1407 * @iocb: Pointer to iocb slot in the ring.
1408 * @nextiocb: Pointer to driver iocb object which need to be
1409 * posted to firmware.
1411 * This function is called with hbalock held to post a new iocb to
1412 * the firmware. This function copies the new iocb to ring iocb slot and
1413 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1414 * a completion call back for this iocb else the function will free the
1418 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1419 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1424 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1427 if (pring->ringno == LPFC_ELS_RING) {
1428 lpfc_debugfs_slow_ring_trc(phba,
1429 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1430 *(((uint32_t *) &nextiocb->iocb) + 4),
1431 *(((uint32_t *) &nextiocb->iocb) + 6),
1432 *(((uint32_t *) &nextiocb->iocb) + 7));
1436 * Issue iocb command to adapter
1438 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1440 pring->stats.iocb_cmd++;
1443 * If there is no completion routine to call, we can release the
1444 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1445 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1447 if (nextiocb->iocb_cmpl)
1448 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1450 __lpfc_sli_release_iocbq(phba, nextiocb);
1453 * Let the HBA know what IOCB slot will be the next one the
1454 * driver will put a command into.
1456 pring->cmdidx = pring->next_cmdidx;
1457 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1461 * lpfc_sli_update_full_ring - Update the chip attention register
1462 * @phba: Pointer to HBA context object.
1463 * @pring: Pointer to driver SLI ring object.
1465 * The caller is not required to hold any lock for calling this function.
1466 * This function updates the chip attention bits for the ring to inform firmware
1467 * that there are pending work to be done for this ring and requests an
1468 * interrupt when there is space available in the ring. This function is
1469 * called when the driver is unable to post more iocbs to the ring due
1470 * to unavailability of space in the ring.
1473 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1475 int ringno = pring->ringno;
1477 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1482 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1483 * The HBA will tell us when an IOCB entry is available.
1485 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1486 readl(phba->CAregaddr); /* flush */
1488 pring->stats.iocb_cmd_full++;
1492 * lpfc_sli_update_ring - Update chip attention register
1493 * @phba: Pointer to HBA context object.
1494 * @pring: Pointer to driver SLI ring object.
1496 * This function updates the chip attention register bit for the
1497 * given ring to inform HBA that there is more work to be done
1498 * in this ring. The caller is not required to hold any lock.
1501 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1503 int ringno = pring->ringno;
1506 * Tell the HBA that there is work to do in this ring.
1508 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1510 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1511 readl(phba->CAregaddr); /* flush */
1516 * lpfc_sli_resume_iocb - Process iocbs in the txq
1517 * @phba: Pointer to HBA context object.
1518 * @pring: Pointer to driver SLI ring object.
1520 * This function is called with hbalock held to post pending iocbs
1521 * in the txq to the firmware. This function is called when driver
1522 * detects space available in the ring.
1525 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1528 struct lpfc_iocbq *nextiocb;
1532 * (a) there is anything on the txq to send
1534 * (c) link attention events can be processed (fcp ring only)
1535 * (d) IOCB processing is not blocked by the outstanding mbox command.
1537 if (pring->txq_cnt &&
1538 lpfc_is_link_up(phba) &&
1539 (pring->ringno != phba->sli.fcp_ring ||
1540 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1542 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1543 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1544 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1547 lpfc_sli_update_ring(phba, pring);
1549 lpfc_sli_update_full_ring(phba, pring);
1556 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1557 * @phba: Pointer to HBA context object.
1558 * @hbqno: HBQ number.
1560 * This function is called with hbalock held to get the next
1561 * available slot for the given HBQ. If there is free slot
1562 * available for the HBQ it will return pointer to the next available
1563 * HBQ entry else it will return NULL.
1565 static struct lpfc_hbq_entry *
1566 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1568 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1570 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1571 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1572 hbqp->next_hbqPutIdx = 0;
1574 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1575 uint32_t raw_index = phba->hbq_get[hbqno];
1576 uint32_t getidx = le32_to_cpu(raw_index);
1578 hbqp->local_hbqGetIdx = getidx;
1580 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1581 lpfc_printf_log(phba, KERN_ERR,
1582 LOG_SLI | LOG_VPORT,
1583 "1802 HBQ %d: local_hbqGetIdx "
1584 "%u is > than hbqp->entry_count %u\n",
1585 hbqno, hbqp->local_hbqGetIdx,
1588 phba->link_state = LPFC_HBA_ERROR;
1592 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1596 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1601 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1602 * @phba: Pointer to HBA context object.
1604 * This function is called with no lock held to free all the
1605 * hbq buffers while uninitializing the SLI interface. It also
1606 * frees the HBQ buffers returned by the firmware but not yet
1607 * processed by the upper layers.
1610 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1612 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1613 struct hbq_dmabuf *hbq_buf;
1614 unsigned long flags;
1618 hbq_count = lpfc_sli_hbq_count();
1619 /* Return all memory used by all HBQs */
1620 spin_lock_irqsave(&phba->hbalock, flags);
1621 for (i = 0; i < hbq_count; ++i) {
1622 list_for_each_entry_safe(dmabuf, next_dmabuf,
1623 &phba->hbqs[i].hbq_buffer_list, list) {
1624 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1625 list_del(&hbq_buf->dbuf.list);
1626 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1628 phba->hbqs[i].buffer_count = 0;
1630 /* Return all HBQ buffer that are in-fly */
1631 list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
1633 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1634 list_del(&hbq_buf->dbuf.list);
1635 if (hbq_buf->tag == -1) {
1636 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1639 hbqno = hbq_buf->tag >> 16;
1640 if (hbqno >= LPFC_MAX_HBQS)
1641 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1644 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1649 /* Mark the HBQs not in use */
1650 phba->hbq_in_use = 0;
1651 spin_unlock_irqrestore(&phba->hbalock, flags);
1655 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1656 * @phba: Pointer to HBA context object.
1657 * @hbqno: HBQ number.
1658 * @hbq_buf: Pointer to HBQ buffer.
1660 * This function is called with the hbalock held to post a
1661 * hbq buffer to the firmware. If the function finds an empty
1662 * slot in the HBQ, it will post the buffer. The function will return
1663 * pointer to the hbq entry if it successfully post the buffer
1664 * else it will return NULL.
1667 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
1668 struct hbq_dmabuf *hbq_buf)
1670 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1674 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1675 * @phba: Pointer to HBA context object.
1676 * @hbqno: HBQ number.
1677 * @hbq_buf: Pointer to HBQ buffer.
1679 * This function is called with the hbalock held to post a hbq buffer to the
1680 * firmware. If the function finds an empty slot in the HBQ, it will post the
1681 * buffer and place it on the hbq_buffer_list. The function will return zero if
1682 * it successfully post the buffer else it will return an error.
1685 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1686 struct hbq_dmabuf *hbq_buf)
1688 struct lpfc_hbq_entry *hbqe;
1689 dma_addr_t physaddr = hbq_buf->dbuf.phys;
1691 /* Get next HBQ entry slot to use */
1692 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1694 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1696 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1697 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
1698 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
1699 hbqe->bde.tus.f.bdeFlags = 0;
1700 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1701 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1703 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1704 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
1706 readl(phba->hbq_put + hbqno);
1707 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
1714 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1715 * @phba: Pointer to HBA context object.
1716 * @hbqno: HBQ number.
1717 * @hbq_buf: Pointer to HBQ buffer.
1719 * This function is called with the hbalock held to post an RQE to the SLI4
1720 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1721 * the hbq_buffer_list and return zero, otherwise it will return an error.
1724 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1725 struct hbq_dmabuf *hbq_buf)
1728 struct lpfc_rqe hrqe;
1729 struct lpfc_rqe drqe;
1731 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1732 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1733 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1734 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1735 rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
1740 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1744 /* HBQ for ELS and CT traffic. */
1745 static struct lpfc_hbq_init lpfc_els_hbq = {
1750 .ring_mask = (1 << LPFC_ELS_RING),
1756 /* HBQ for the extra ring if needed */
1757 static struct lpfc_hbq_init lpfc_extra_hbq = {
1762 .ring_mask = (1 << LPFC_EXTRA_RING),
1769 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
1775 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1776 * @phba: Pointer to HBA context object.
1777 * @hbqno: HBQ number.
1778 * @count: Number of HBQ buffers to be posted.
1780 * This function is called with no lock held to post more hbq buffers to the
1781 * given HBQ. The function returns the number of HBQ buffers successfully
1785 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1787 uint32_t i, posted = 0;
1788 unsigned long flags;
1789 struct hbq_dmabuf *hbq_buffer;
1790 LIST_HEAD(hbq_buf_list);
1791 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
1794 if ((phba->hbqs[hbqno].buffer_count + count) >
1795 lpfc_hbq_defs[hbqno]->entry_count)
1796 count = lpfc_hbq_defs[hbqno]->entry_count -
1797 phba->hbqs[hbqno].buffer_count;
1800 /* Allocate HBQ entries */
1801 for (i = 0; i < count; i++) {
1802 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1805 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1807 /* Check whether HBQ is still in use */
1808 spin_lock_irqsave(&phba->hbalock, flags);
1809 if (!phba->hbq_in_use)
1811 while (!list_empty(&hbq_buf_list)) {
1812 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1814 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1816 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
1817 phba->hbqs[hbqno].buffer_count++;
1820 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1822 spin_unlock_irqrestore(&phba->hbalock, flags);
1825 spin_unlock_irqrestore(&phba->hbalock, flags);
1826 while (!list_empty(&hbq_buf_list)) {
1827 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1829 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1835 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1836 * @phba: Pointer to HBA context object.
1839 * This function posts more buffers to the HBQ. This function
1840 * is called with no lock held. The function returns the number of HBQ entries
1841 * successfully allocated.
1844 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
1846 if (phba->sli_rev == LPFC_SLI_REV4)
1849 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1850 lpfc_hbq_defs[qno]->add_count);
1854 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1855 * @phba: Pointer to HBA context object.
1856 * @qno: HBQ queue number.
1858 * This function is called from SLI initialization code path with
1859 * no lock held to post initial HBQ buffers to firmware. The
1860 * function returns the number of HBQ entries successfully allocated.
1863 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
1865 if (phba->sli_rev == LPFC_SLI_REV4)
1866 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1867 lpfc_hbq_defs[qno]->entry_count);
1869 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1870 lpfc_hbq_defs[qno]->init_count);
1874 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1875 * @phba: Pointer to HBA context object.
1876 * @hbqno: HBQ number.
1878 * This function removes the first hbq buffer on an hbq list and returns a
1879 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1881 static struct hbq_dmabuf *
1882 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
1884 struct lpfc_dmabuf *d_buf;
1886 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
1889 return container_of(d_buf, struct hbq_dmabuf, dbuf);
1893 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1894 * @phba: Pointer to HBA context object.
1895 * @tag: Tag of the hbq buffer.
1897 * This function is called with hbalock held. This function searches
1898 * for the hbq buffer associated with the given tag in the hbq buffer
1899 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1902 static struct hbq_dmabuf *
1903 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
1905 struct lpfc_dmabuf *d_buf;
1906 struct hbq_dmabuf *hbq_buf;
1910 if (hbqno >= LPFC_MAX_HBQS)
1913 spin_lock_irq(&phba->hbalock);
1914 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
1915 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
1916 if (hbq_buf->tag == tag) {
1917 spin_unlock_irq(&phba->hbalock);
1921 spin_unlock_irq(&phba->hbalock);
1922 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
1923 "1803 Bad hbq tag. Data: x%x x%x\n",
1924 tag, phba->hbqs[tag >> 16].buffer_count);
1929 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1930 * @phba: Pointer to HBA context object.
1931 * @hbq_buffer: Pointer to HBQ buffer.
1933 * This function is called with hbalock. This function gives back
1934 * the hbq buffer to firmware. If the HBQ does not have space to
1935 * post the buffer, it will free the buffer.
1938 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
1943 hbqno = hbq_buffer->tag >> 16;
1944 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
1945 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1950 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1951 * @mbxCommand: mailbox command code.
1953 * This function is called by the mailbox event handler function to verify
1954 * that the completed mailbox command is a legitimate mailbox command. If the
1955 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1956 * and the mailbox event handler will take the HBA offline.
1959 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
1963 switch (mbxCommand) {
1967 case MBX_WRITE_VPARMS:
1968 case MBX_RUN_BIU_DIAG:
1971 case MBX_CONFIG_LINK:
1972 case MBX_CONFIG_RING:
1973 case MBX_RESET_RING:
1974 case MBX_READ_CONFIG:
1975 case MBX_READ_RCONFIG:
1976 case MBX_READ_SPARM:
1977 case MBX_READ_STATUS:
1981 case MBX_READ_LNK_STAT:
1983 case MBX_UNREG_LOGIN:
1985 case MBX_DUMP_MEMORY:
1986 case MBX_DUMP_CONTEXT:
1989 case MBX_UPDATE_CFG:
1991 case MBX_DEL_LD_ENTRY:
1992 case MBX_RUN_PROGRAM:
1994 case MBX_SET_VARIABLE:
1995 case MBX_UNREG_D_ID:
1996 case MBX_KILL_BOARD:
1997 case MBX_CONFIG_FARP:
2000 case MBX_RUN_BIU_DIAG64:
2001 case MBX_CONFIG_PORT:
2002 case MBX_READ_SPARM64:
2003 case MBX_READ_RPI64:
2004 case MBX_REG_LOGIN64:
2005 case MBX_READ_TOPOLOGY:
2008 case MBX_LOAD_EXP_ROM:
2009 case MBX_ASYNCEVT_ENABLE:
2013 case MBX_PORT_CAPABILITIES:
2014 case MBX_PORT_IOV_CONTROL:
2015 case MBX_SLI4_CONFIG:
2016 case MBX_SLI4_REQ_FTRS:
2018 case MBX_UNREG_FCFI:
2023 case MBX_RESUME_RPI:
2024 case MBX_READ_EVENT_LOG_STATUS:
2025 case MBX_READ_EVENT_LOG:
2026 case MBX_SECURITY_MGMT:
2038 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2039 * @phba: Pointer to HBA context object.
2040 * @pmboxq: Pointer to mailbox command.
2042 * This is completion handler function for mailbox commands issued from
2043 * lpfc_sli_issue_mbox_wait function. This function is called by the
2044 * mailbox event handler function with no lock held. This function
2045 * will wake up thread waiting on the wait queue pointed by context1
2049 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2051 wait_queue_head_t *pdone_q;
2052 unsigned long drvr_flag;
2055 * If pdone_q is empty, the driver thread gave up waiting and
2056 * continued running.
2058 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2059 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2060 pdone_q = (wait_queue_head_t *) pmboxq->context1;
2062 wake_up_interruptible(pdone_q);
2063 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2069 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2070 * @phba: Pointer to HBA context object.
2071 * @pmb: Pointer to mailbox object.
2073 * This function is the default mailbox completion handler. It
2074 * frees the memory resources associated with the completed mailbox
2075 * command. If the completed command is a REG_LOGIN mailbox command,
2076 * this function will issue a UREG_LOGIN to re-claim the RPI.
2079 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2081 struct lpfc_vport *vport = pmb->vport;
2082 struct lpfc_dmabuf *mp;
2083 struct lpfc_nodelist *ndlp;
2084 struct Scsi_Host *shost;
2088 mp = (struct lpfc_dmabuf *) (pmb->context1);
2091 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2096 * If a REG_LOGIN succeeded after node is destroyed or node
2097 * is in re-discovery driver need to cleanup the RPI.
2099 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2100 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2101 !pmb->u.mb.mbxStatus) {
2102 rpi = pmb->u.mb.un.varWords[0];
2103 vpi = pmb->u.mb.un.varRegLogin.vpi;
2104 lpfc_unreg_login(phba, vpi, rpi, pmb);
2105 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2106 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2107 if (rc != MBX_NOT_FINISHED)
2111 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2112 !(phba->pport->load_flag & FC_UNLOADING) &&
2113 !pmb->u.mb.mbxStatus) {
2114 shost = lpfc_shost_from_vport(vport);
2115 spin_lock_irq(shost->host_lock);
2116 vport->vpi_state |= LPFC_VPI_REGISTERED;
2117 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2118 spin_unlock_irq(shost->host_lock);
2121 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2122 ndlp = (struct lpfc_nodelist *)pmb->context2;
2124 pmb->context2 = NULL;
2127 /* Check security permission status on INIT_LINK mailbox command */
2128 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2129 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2130 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2131 "2860 SLI authentication is required "
2132 "for INIT_LINK but has not done yet\n");
2134 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2135 lpfc_sli4_mbox_cmd_free(phba, pmb);
2137 mempool_free(pmb, phba->mbox_mem_pool);
2141 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2142 * @phba: Pointer to HBA context object.
2144 * This function is called with no lock held. This function processes all
2145 * the completed mailbox commands and gives it to upper layers. The interrupt
2146 * service routine processes mailbox completion interrupt and adds completed
2147 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2148 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2149 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2150 * function returns the mailbox commands to the upper layer by calling the
2151 * completion handler function of each mailbox.
2154 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
2161 phba->sli.slistat.mbox_event++;
2163 /* Get all completed mailboxe buffers into the cmplq */
2164 spin_lock_irq(&phba->hbalock);
2165 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2166 spin_unlock_irq(&phba->hbalock);
2168 /* Get a Mailbox buffer to setup mailbox commands for callback */
2170 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2176 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2178 lpfc_debugfs_disc_trc(pmb->vport,
2179 LPFC_DISC_TRC_MBOX_VPORT,
2180 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2181 (uint32_t)pmbox->mbxCommand,
2182 pmbox->un.varWords[0],
2183 pmbox->un.varWords[1]);
2186 lpfc_debugfs_disc_trc(phba->pport,
2188 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2189 (uint32_t)pmbox->mbxCommand,
2190 pmbox->un.varWords[0],
2191 pmbox->un.varWords[1]);
2196 * It is a fatal error if unknown mbox command completion.
2198 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2200 /* Unknown mailbox command compl */
2201 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2202 "(%d):0323 Unknown Mailbox command "
2204 pmb->vport ? pmb->vport->vpi : 0,
2206 lpfc_sli4_mbox_opcode_get(phba, pmb));
2207 phba->link_state = LPFC_HBA_ERROR;
2208 phba->work_hs = HS_FFER3;
2209 lpfc_handle_eratt(phba);
2213 if (pmbox->mbxStatus) {
2214 phba->sli.slistat.mbox_stat_err++;
2215 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2216 /* Mbox cmd cmpl error - RETRYing */
2217 lpfc_printf_log(phba, KERN_INFO,
2219 "(%d):0305 Mbox cmd cmpl "
2220 "error - RETRYing Data: x%x "
2221 "(x%x) x%x x%x x%x\n",
2222 pmb->vport ? pmb->vport->vpi :0,
2224 lpfc_sli4_mbox_opcode_get(phba,
2227 pmbox->un.varWords[0],
2228 pmb->vport->port_state);
2229 pmbox->mbxStatus = 0;
2230 pmbox->mbxOwner = OWN_HOST;
2231 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2232 if (rc != MBX_NOT_FINISHED)
2237 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2238 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2239 "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
2240 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2241 pmb->vport ? pmb->vport->vpi : 0,
2243 lpfc_sli4_mbox_opcode_get(phba, pmb),
2245 *((uint32_t *) pmbox),
2246 pmbox->un.varWords[0],
2247 pmbox->un.varWords[1],
2248 pmbox->un.varWords[2],
2249 pmbox->un.varWords[3],
2250 pmbox->un.varWords[4],
2251 pmbox->un.varWords[5],
2252 pmbox->un.varWords[6],
2253 pmbox->un.varWords[7]);
2256 pmb->mbox_cmpl(phba,pmb);
2262 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2263 * @phba: Pointer to HBA context object.
2264 * @pring: Pointer to driver SLI ring object.
2267 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2268 * is set in the tag the buffer is posted for a particular exchange,
2269 * the function will return the buffer without replacing the buffer.
2270 * If the buffer is for unsolicited ELS or CT traffic, this function
2271 * returns the buffer and also posts another buffer to the firmware.
2273 static struct lpfc_dmabuf *
2274 lpfc_sli_get_buff(struct lpfc_hba *phba,
2275 struct lpfc_sli_ring *pring,
2278 struct hbq_dmabuf *hbq_entry;
2280 if (tag & QUE_BUFTAG_BIT)
2281 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
2282 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2285 return &hbq_entry->dbuf;
2289 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2290 * @phba: Pointer to HBA context object.
2291 * @pring: Pointer to driver SLI ring object.
2292 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2293 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2294 * @fch_type: the type for the first frame of the sequence.
2296 * This function is called with no lock held. This function uses the r_ctl and
2297 * type of the received sequence to find the correct callback function to call
2298 * to process the sequence.
2301 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2302 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
2307 /* unSolicited Responses */
2308 if (pring->prt[0].profile) {
2309 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
2310 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
2314 /* We must search, based on rctl / type
2315 for the right routine */
2316 for (i = 0; i < pring->num_mask; i++) {
2317 if ((pring->prt[i].rctl == fch_r_ctl) &&
2318 (pring->prt[i].type == fch_type)) {
2319 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
2320 (pring->prt[i].lpfc_sli_rcv_unsol_event)
2321 (phba, pring, saveq);
2329 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2330 * @phba: Pointer to HBA context object.
2331 * @pring: Pointer to driver SLI ring object.
2332 * @saveq: Pointer to the unsolicited iocb.
2334 * This function is called with no lock held by the ring event handler
2335 * when there is an unsolicited iocb posted to the response ring by the
2336 * firmware. This function gets the buffer associated with the iocbs
2337 * and calls the event handler for the ring. This function handles both
2338 * qring buffers and hbq buffers.
2339 * When the function returns 1 the caller can free the iocb object otherwise
2340 * upper layer functions will free the iocb objects.
2343 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2344 struct lpfc_iocbq *saveq)
2348 uint32_t Rctl, Type;
2350 struct lpfc_iocbq *iocbq;
2351 struct lpfc_dmabuf *dmzbuf;
2354 irsp = &(saveq->iocb);
2356 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
2357 if (pring->lpfc_sli_rcv_async_status)
2358 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
2360 lpfc_printf_log(phba,
2363 "0316 Ring %d handler: unexpected "
2364 "ASYNC_STATUS iocb received evt_code "
2367 irsp->un.asyncstat.evt_code);
2371 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
2372 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
2373 if (irsp->ulpBdeCount > 0) {
2374 dmzbuf = lpfc_sli_get_buff(phba, pring,
2375 irsp->un.ulpWord[3]);
2376 lpfc_in_buf_free(phba, dmzbuf);
2379 if (irsp->ulpBdeCount > 1) {
2380 dmzbuf = lpfc_sli_get_buff(phba, pring,
2381 irsp->unsli3.sli3Words[3]);
2382 lpfc_in_buf_free(phba, dmzbuf);
2385 if (irsp->ulpBdeCount > 2) {
2386 dmzbuf = lpfc_sli_get_buff(phba, pring,
2387 irsp->unsli3.sli3Words[7]);
2388 lpfc_in_buf_free(phba, dmzbuf);
2394 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2395 if (irsp->ulpBdeCount != 0) {
2396 saveq->context2 = lpfc_sli_get_buff(phba, pring,
2397 irsp->un.ulpWord[3]);
2398 if (!saveq->context2)
2399 lpfc_printf_log(phba,
2402 "0341 Ring %d Cannot find buffer for "
2403 "an unsolicited iocb. tag 0x%x\n",
2405 irsp->un.ulpWord[3]);
2407 if (irsp->ulpBdeCount == 2) {
2408 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2409 irsp->unsli3.sli3Words[7]);
2410 if (!saveq->context3)
2411 lpfc_printf_log(phba,
2414 "0342 Ring %d Cannot find buffer for an"
2415 " unsolicited iocb. tag 0x%x\n",
2417 irsp->unsli3.sli3Words[7]);
2419 list_for_each_entry(iocbq, &saveq->list, list) {
2420 irsp = &(iocbq->iocb);
2421 if (irsp->ulpBdeCount != 0) {
2422 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2423 irsp->un.ulpWord[3]);
2424 if (!iocbq->context2)
2425 lpfc_printf_log(phba,
2428 "0343 Ring %d Cannot find "
2429 "buffer for an unsolicited iocb"
2430 ". tag 0x%x\n", pring->ringno,
2431 irsp->un.ulpWord[3]);
2433 if (irsp->ulpBdeCount == 2) {
2434 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2435 irsp->unsli3.sli3Words[7]);
2436 if (!iocbq->context3)
2437 lpfc_printf_log(phba,
2440 "0344 Ring %d Cannot find "
2441 "buffer for an unsolicited "
2444 irsp->unsli3.sli3Words[7]);
2448 if (irsp->ulpBdeCount != 0 &&
2449 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2450 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2453 /* search continue save q for same XRI */
2454 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2455 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
2456 saveq->iocb.unsli3.rcvsli3.ox_id) {
2457 list_add_tail(&saveq->list, &iocbq->list);
2463 list_add_tail(&saveq->clist,
2464 &pring->iocb_continue_saveq);
2465 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2466 list_del_init(&iocbq->clist);
2468 irsp = &(saveq->iocb);
2472 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2473 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2474 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2475 Rctl = FC_RCTL_ELS_REQ;
2478 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2479 Rctl = w5p->hcsw.Rctl;
2480 Type = w5p->hcsw.Type;
2482 /* Firmware Workaround */
2483 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2484 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2485 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2486 Rctl = FC_RCTL_ELS_REQ;
2488 w5p->hcsw.Rctl = Rctl;
2489 w5p->hcsw.Type = Type;
2493 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2494 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2495 "0313 Ring %d handler: unexpected Rctl x%x "
2496 "Type x%x received\n",
2497 pring->ringno, Rctl, Type);
2503 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2504 * @phba: Pointer to HBA context object.
2505 * @pring: Pointer to driver SLI ring object.
2506 * @prspiocb: Pointer to response iocb object.
2508 * This function looks up the iocb_lookup table to get the command iocb
2509 * corresponding to the given response iocb using the iotag of the
2510 * response iocb. This function is called with the hbalock held.
2511 * This function returns the command iocb object if it finds the command
2512 * iocb else returns NULL.
2514 static struct lpfc_iocbq *
2515 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2516 struct lpfc_sli_ring *pring,
2517 struct lpfc_iocbq *prspiocb)
2519 struct lpfc_iocbq *cmd_iocb = NULL;
2522 iotag = prspiocb->iocb.ulpIoTag;
2524 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2525 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2526 list_del_init(&cmd_iocb->list);
2527 if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
2528 pring->txcmplq_cnt--;
2529 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
2534 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2535 "0317 iotag x%x is out off "
2536 "range: max iotag x%x wd0 x%x\n",
2537 iotag, phba->sli.last_iotag,
2538 *(((uint32_t *) &prspiocb->iocb) + 7));
2543 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2544 * @phba: Pointer to HBA context object.
2545 * @pring: Pointer to driver SLI ring object.
2548 * This function looks up the iocb_lookup table to get the command iocb
2549 * corresponding to the given iotag. This function is called with the
2551 * This function returns the command iocb object if it finds the command
2552 * iocb else returns NULL.
2554 static struct lpfc_iocbq *
2555 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2556 struct lpfc_sli_ring *pring, uint16_t iotag)
2558 struct lpfc_iocbq *cmd_iocb;
2560 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2561 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2562 list_del_init(&cmd_iocb->list);
2563 if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
2564 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
2565 pring->txcmplq_cnt--;
2570 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2571 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2572 iotag, phba->sli.last_iotag);
2577 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2578 * @phba: Pointer to HBA context object.
2579 * @pring: Pointer to driver SLI ring object.
2580 * @saveq: Pointer to the response iocb to be processed.
2582 * This function is called by the ring event handler for non-fcp
2583 * rings when there is a new response iocb in the response ring.
2584 * The caller is not required to hold any locks. This function
2585 * gets the command iocb associated with the response iocb and
2586 * calls the completion handler for the command iocb. If there
2587 * is no completion handler, the function will free the resources
2588 * associated with command iocb. If the response iocb is for
2589 * an already aborted command iocb, the status of the completion
2590 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2591 * This function always returns 1.
2594 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2595 struct lpfc_iocbq *saveq)
2597 struct lpfc_iocbq *cmdiocbp;
2599 unsigned long iflag;
2601 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2602 spin_lock_irqsave(&phba->hbalock, iflag);
2603 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
2604 spin_unlock_irqrestore(&phba->hbalock, iflag);
2607 if (cmdiocbp->iocb_cmpl) {
2609 * If an ELS command failed send an event to mgmt
2612 if (saveq->iocb.ulpStatus &&
2613 (pring->ringno == LPFC_ELS_RING) &&
2614 (cmdiocbp->iocb.ulpCommand ==
2615 CMD_ELS_REQUEST64_CR))
2616 lpfc_send_els_failure_event(phba,
2620 * Post all ELS completions to the worker thread.
2621 * All other are passed to the completion callback.
2623 if (pring->ringno == LPFC_ELS_RING) {
2624 if ((phba->sli_rev < LPFC_SLI_REV4) &&
2625 (cmdiocbp->iocb_flag &
2626 LPFC_DRIVER_ABORTED)) {
2627 spin_lock_irqsave(&phba->hbalock,
2629 cmdiocbp->iocb_flag &=
2630 ~LPFC_DRIVER_ABORTED;
2631 spin_unlock_irqrestore(&phba->hbalock,
2633 saveq->iocb.ulpStatus =
2634 IOSTAT_LOCAL_REJECT;
2635 saveq->iocb.un.ulpWord[4] =
2638 /* Firmware could still be in progress
2639 * of DMAing payload, so don't free data
2640 * buffer till after a hbeat.
2642 spin_lock_irqsave(&phba->hbalock,
2644 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2645 spin_unlock_irqrestore(&phba->hbalock,
2648 if (phba->sli_rev == LPFC_SLI_REV4) {
2649 if (saveq->iocb_flag &
2650 LPFC_EXCHANGE_BUSY) {
2651 /* Set cmdiocb flag for the
2652 * exchange busy so sgl (xri)
2653 * will not be released until
2654 * the abort xri is received
2658 &phba->hbalock, iflag);
2659 cmdiocbp->iocb_flag |=
2661 spin_unlock_irqrestore(
2662 &phba->hbalock, iflag);
2664 if (cmdiocbp->iocb_flag &
2665 LPFC_DRIVER_ABORTED) {
2667 * Clear LPFC_DRIVER_ABORTED
2668 * bit in case it was driver
2672 &phba->hbalock, iflag);
2673 cmdiocbp->iocb_flag &=
2674 ~LPFC_DRIVER_ABORTED;
2675 spin_unlock_irqrestore(
2676 &phba->hbalock, iflag);
2677 cmdiocbp->iocb.ulpStatus =
2678 IOSTAT_LOCAL_REJECT;
2679 cmdiocbp->iocb.un.ulpWord[4] =
2680 IOERR_ABORT_REQUESTED;
2682 * For SLI4, irsiocb contains
2683 * NO_XRI in sli_xritag, it
2684 * shall not affect releasing
2685 * sgl (xri) process.
2687 saveq->iocb.ulpStatus =
2688 IOSTAT_LOCAL_REJECT;
2689 saveq->iocb.un.ulpWord[4] =
2692 &phba->hbalock, iflag);
2694 LPFC_DELAY_MEM_FREE;
2695 spin_unlock_irqrestore(
2696 &phba->hbalock, iflag);
2700 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
2702 lpfc_sli_release_iocbq(phba, cmdiocbp);
2705 * Unknown initiating command based on the response iotag.
2706 * This could be the case on the ELS ring because of
2709 if (pring->ringno != LPFC_ELS_RING) {
2711 * Ring <ringno> handler: unexpected completion IoTag
2714 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2715 "0322 Ring %d handler: "
2716 "unexpected completion IoTag x%x "
2717 "Data: x%x x%x x%x x%x\n",
2719 saveq->iocb.ulpIoTag,
2720 saveq->iocb.ulpStatus,
2721 saveq->iocb.un.ulpWord[4],
2722 saveq->iocb.ulpCommand,
2723 saveq->iocb.ulpContext);
2731 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2732 * @phba: Pointer to HBA context object.
2733 * @pring: Pointer to driver SLI ring object.
2735 * This function is called from the iocb ring event handlers when
2736 * put pointer is ahead of the get pointer for a ring. This function signal
2737 * an error attention condition to the worker thread and the worker
2738 * thread will transition the HBA to offline state.
2741 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2743 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2745 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2746 * rsp ring <portRspMax>
2748 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2749 "0312 Ring %d handler: portRspPut %d "
2750 "is bigger than rsp ring %d\n",
2751 pring->ringno, le32_to_cpu(pgp->rspPutInx),
2754 phba->link_state = LPFC_HBA_ERROR;
2757 * All error attention handlers are posted to
2760 phba->work_ha |= HA_ERATT;
2761 phba->work_hs = HS_FFER3;
2763 lpfc_worker_wake_up(phba);
2769 * lpfc_poll_eratt - Error attention polling timer timeout handler
2770 * @ptr: Pointer to address of HBA context object.
2772 * This function is invoked by the Error Attention polling timer when the
2773 * timer times out. It will check the SLI Error Attention register for
2774 * possible attention events. If so, it will post an Error Attention event
2775 * and wake up worker thread to process it. Otherwise, it will set up the
2776 * Error Attention polling timer for the next poll.
2778 void lpfc_poll_eratt(unsigned long ptr)
2780 struct lpfc_hba *phba;
2783 phba = (struct lpfc_hba *)ptr;
2785 /* Check chip HA register for error event */
2786 eratt = lpfc_sli_check_eratt(phba);
2789 /* Tell the worker thread there is work to do */
2790 lpfc_worker_wake_up(phba);
2792 /* Restart the timer for next eratt poll */
2793 mod_timer(&phba->eratt_poll, jiffies +
2794 HZ * LPFC_ERATT_POLL_INTERVAL);
2800 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2801 * @phba: Pointer to HBA context object.
2802 * @pring: Pointer to driver SLI ring object.
2803 * @mask: Host attention register mask for this ring.
2805 * This function is called from the interrupt context when there is a ring
2806 * event for the fcp ring. The caller does not hold any lock.
2807 * The function processes each response iocb in the response ring until it
2808 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2809 * LE bit set. The function will call the completion handler of the command iocb
2810 * if the response iocb indicates a completion for a command iocb or it is
2811 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2812 * function if this is an unsolicited iocb.
2813 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2814 * to check it explicitly.
2817 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
2818 struct lpfc_sli_ring *pring, uint32_t mask)
2820 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2821 IOCB_t *irsp = NULL;
2822 IOCB_t *entry = NULL;
2823 struct lpfc_iocbq *cmdiocbq = NULL;
2824 struct lpfc_iocbq rspiocbq;
2826 uint32_t portRspPut, portRspMax;
2828 lpfc_iocb_type type;
2829 unsigned long iflag;
2830 uint32_t rsp_cmpl = 0;
2832 spin_lock_irqsave(&phba->hbalock, iflag);
2833 pring->stats.iocb_event++;
2836 * The next available response entry should never exceed the maximum
2837 * entries. If it does, treat it as an adapter hardware error.
2839 portRspMax = pring->numRiocb;
2840 portRspPut = le32_to_cpu(pgp->rspPutInx);
2841 if (unlikely(portRspPut >= portRspMax)) {
2842 lpfc_sli_rsp_pointers_error(phba, pring);
2843 spin_unlock_irqrestore(&phba->hbalock, iflag);
2846 if (phba->fcp_ring_in_use) {
2847 spin_unlock_irqrestore(&phba->hbalock, iflag);
2850 phba->fcp_ring_in_use = 1;
2853 while (pring->rspidx != portRspPut) {
2855 * Fetch an entry off the ring and copy it into a local data
2856 * structure. The copy involves a byte-swap since the
2857 * network byte order and pci byte orders are different.
2859 entry = lpfc_resp_iocb(phba, pring);
2860 phba->last_completion_time = jiffies;
2862 if (++pring->rspidx >= portRspMax)
2865 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2866 (uint32_t *) &rspiocbq.iocb,
2867 phba->iocb_rsp_size);
2868 INIT_LIST_HEAD(&(rspiocbq.list));
2869 irsp = &rspiocbq.iocb;
2871 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2872 pring->stats.iocb_rsp++;
2875 if (unlikely(irsp->ulpStatus)) {
2877 * If resource errors reported from HBA, reduce
2878 * queuedepths of the SCSI device.
2880 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2881 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2882 spin_unlock_irqrestore(&phba->hbalock, iflag);
2883 phba->lpfc_rampdown_queue_depth(phba);
2884 spin_lock_irqsave(&phba->hbalock, iflag);
2887 /* Rsp ring <ringno> error: IOCB */
2888 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2889 "0336 Rsp Ring %d error: IOCB Data: "
2890 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2892 irsp->un.ulpWord[0],
2893 irsp->un.ulpWord[1],
2894 irsp->un.ulpWord[2],
2895 irsp->un.ulpWord[3],
2896 irsp->un.ulpWord[4],
2897 irsp->un.ulpWord[5],
2898 *(uint32_t *)&irsp->un1,
2899 *((uint32_t *)&irsp->un1 + 1));
2903 case LPFC_ABORT_IOCB:
2906 * Idle exchange closed via ABTS from port. No iocb
2907 * resources need to be recovered.
2909 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2910 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2911 "0333 IOCB cmd 0x%x"
2912 " processed. Skipping"
2918 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2920 if (unlikely(!cmdiocbq))
2922 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
2923 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
2924 if (cmdiocbq->iocb_cmpl) {
2925 spin_unlock_irqrestore(&phba->hbalock, iflag);
2926 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2928 spin_lock_irqsave(&phba->hbalock, iflag);
2931 case LPFC_UNSOL_IOCB:
2932 spin_unlock_irqrestore(&phba->hbalock, iflag);
2933 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
2934 spin_lock_irqsave(&phba->hbalock, iflag);
2937 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2938 char adaptermsg[LPFC_MAX_ADPTMSG];
2939 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2940 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2942 dev_warn(&((phba->pcidev)->dev),
2944 phba->brd_no, adaptermsg);
2946 /* Unknown IOCB command */
2947 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2948 "0334 Unknown IOCB command "
2949 "Data: x%x, x%x x%x x%x x%x\n",
2950 type, irsp->ulpCommand,
2959 * The response IOCB has been processed. Update the ring
2960 * pointer in SLIM. If the port response put pointer has not
2961 * been updated, sync the pgp->rspPutInx and fetch the new port
2962 * response put pointer.
2964 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2966 if (pring->rspidx == portRspPut)
2967 portRspPut = le32_to_cpu(pgp->rspPutInx);
2970 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
2971 pring->stats.iocb_rsp_full++;
2972 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2973 writel(status, phba->CAregaddr);
2974 readl(phba->CAregaddr);
2976 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2977 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2978 pring->stats.iocb_cmd_empty++;
2980 /* Force update of the local copy of cmdGetInx */
2981 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2982 lpfc_sli_resume_iocb(phba, pring);
2984 if ((pring->lpfc_sli_cmd_available))
2985 (pring->lpfc_sli_cmd_available) (phba, pring);
2989 phba->fcp_ring_in_use = 0;
2990 spin_unlock_irqrestore(&phba->hbalock, iflag);
2995 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
2996 * @phba: Pointer to HBA context object.
2997 * @pring: Pointer to driver SLI ring object.
2998 * @rspiocbp: Pointer to driver response IOCB object.
3000 * This function is called from the worker thread when there is a slow-path
3001 * response IOCB to process. This function chains all the response iocbs until
3002 * seeing the iocb with the LE bit set. The function will call
3003 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3004 * completion of a command iocb. The function will call the
3005 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3006 * The function frees the resources or calls the completion handler if this
3007 * iocb is an abort completion. The function returns NULL when the response
3008 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3009 * this function shall chain the iocb on to the iocb_continueq and return the
3010 * response iocb passed in.
3012 static struct lpfc_iocbq *
3013 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3014 struct lpfc_iocbq *rspiocbp)
3016 struct lpfc_iocbq *saveq;
3017 struct lpfc_iocbq *cmdiocbp;
3018 struct lpfc_iocbq *next_iocb;
3019 IOCB_t *irsp = NULL;
3020 uint32_t free_saveq;
3021 uint8_t iocb_cmd_type;
3022 lpfc_iocb_type type;
3023 unsigned long iflag;
3026 spin_lock_irqsave(&phba->hbalock, iflag);
3027 /* First add the response iocb to the countinueq list */
3028 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3029 pring->iocb_continueq_cnt++;
3031 /* Now, determine whether the list is completed for processing */
3032 irsp = &rspiocbp->iocb;
3035 * By default, the driver expects to free all resources
3036 * associated with this iocb completion.
3039 saveq = list_get_first(&pring->iocb_continueq,
3040 struct lpfc_iocbq, list);
3041 irsp = &(saveq->iocb);
3042 list_del_init(&pring->iocb_continueq);
3043 pring->iocb_continueq_cnt = 0;
3045 pring->stats.iocb_rsp++;
3048 * If resource errors reported from HBA, reduce
3049 * queuedepths of the SCSI device.
3051 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3052 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
3053 spin_unlock_irqrestore(&phba->hbalock, iflag);
3054 phba->lpfc_rampdown_queue_depth(phba);
3055 spin_lock_irqsave(&phba->hbalock, iflag);
3058 if (irsp->ulpStatus) {
3059 /* Rsp ring <ringno> error: IOCB */
3060 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3061 "0328 Rsp Ring %d error: "
3066 "x%x x%x x%x x%x\n",
3068 irsp->un.ulpWord[0],
3069 irsp->un.ulpWord[1],
3070 irsp->un.ulpWord[2],
3071 irsp->un.ulpWord[3],
3072 irsp->un.ulpWord[4],
3073 irsp->un.ulpWord[5],
3074 *(((uint32_t *) irsp) + 6),
3075 *(((uint32_t *) irsp) + 7),
3076 *(((uint32_t *) irsp) + 8),
3077 *(((uint32_t *) irsp) + 9),
3078 *(((uint32_t *) irsp) + 10),
3079 *(((uint32_t *) irsp) + 11),
3080 *(((uint32_t *) irsp) + 12),
3081 *(((uint32_t *) irsp) + 13),
3082 *(((uint32_t *) irsp) + 14),
3083 *(((uint32_t *) irsp) + 15));
3087 * Fetch the IOCB command type and call the correct completion
3088 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3089 * get freed back to the lpfc_iocb_list by the discovery
3092 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3093 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3096 spin_unlock_irqrestore(&phba->hbalock, iflag);
3097 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3098 spin_lock_irqsave(&phba->hbalock, iflag);
3101 case LPFC_UNSOL_IOCB:
3102 spin_unlock_irqrestore(&phba->hbalock, iflag);
3103 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3104 spin_lock_irqsave(&phba->hbalock, iflag);
3109 case LPFC_ABORT_IOCB:
3111 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
3112 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3115 /* Call the specified completion routine */
3116 if (cmdiocbp->iocb_cmpl) {
3117 spin_unlock_irqrestore(&phba->hbalock,
3119 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3121 spin_lock_irqsave(&phba->hbalock,
3124 __lpfc_sli_release_iocbq(phba,
3129 case LPFC_UNKNOWN_IOCB:
3130 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3131 char adaptermsg[LPFC_MAX_ADPTMSG];
3132 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3133 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3135 dev_warn(&((phba->pcidev)->dev),
3137 phba->brd_no, adaptermsg);
3139 /* Unknown IOCB command */
3140 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3141 "0335 Unknown IOCB "
3142 "command Data: x%x "
3153 list_for_each_entry_safe(rspiocbp, next_iocb,
3154 &saveq->list, list) {
3155 list_del(&rspiocbp->list);
3156 __lpfc_sli_release_iocbq(phba, rspiocbp);
3158 __lpfc_sli_release_iocbq(phba, saveq);
3162 spin_unlock_irqrestore(&phba->hbalock, iflag);
3167 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3168 * @phba: Pointer to HBA context object.
3169 * @pring: Pointer to driver SLI ring object.
3170 * @mask: Host attention register mask for this ring.
3172 * This routine wraps the actual slow_ring event process routine from the
3173 * API jump table function pointer from the lpfc_hba struct.
3176 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
3177 struct lpfc_sli_ring *pring, uint32_t mask)
3179 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
3183 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3184 * @phba: Pointer to HBA context object.
3185 * @pring: Pointer to driver SLI ring object.
3186 * @mask: Host attention register mask for this ring.
3188 * This function is called from the worker thread when there is a ring event
3189 * for non-fcp rings. The caller does not hold any lock. The function will
3190 * remove each response iocb in the response ring and calls the handle
3191 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3194 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
3195 struct lpfc_sli_ring *pring, uint32_t mask)
3197 struct lpfc_pgp *pgp;
3199 IOCB_t *irsp = NULL;
3200 struct lpfc_iocbq *rspiocbp = NULL;
3201 uint32_t portRspPut, portRspMax;
3202 unsigned long iflag;
3205 pgp = &phba->port_gp[pring->ringno];
3206 spin_lock_irqsave(&phba->hbalock, iflag);
3207 pring->stats.iocb_event++;
3210 * The next available response entry should never exceed the maximum
3211 * entries. If it does, treat it as an adapter hardware error.
3213 portRspMax = pring->numRiocb;
3214 portRspPut = le32_to_cpu(pgp->rspPutInx);
3215 if (portRspPut >= portRspMax) {
3217 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3218 * rsp ring <portRspMax>
3220 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3221 "0303 Ring %d handler: portRspPut %d "
3222 "is bigger than rsp ring %d\n",
3223 pring->ringno, portRspPut, portRspMax);
3225 phba->link_state = LPFC_HBA_ERROR;
3226 spin_unlock_irqrestore(&phba->hbalock, iflag);
3228 phba->work_hs = HS_FFER3;
3229 lpfc_handle_eratt(phba);
3235 while (pring->rspidx != portRspPut) {
3237 * Build a completion list and call the appropriate handler.
3238 * The process is to get the next available response iocb, get
3239 * a free iocb from the list, copy the response data into the
3240 * free iocb, insert to the continuation list, and update the
3241 * next response index to slim. This process makes response
3242 * iocb's in the ring available to DMA as fast as possible but
3243 * pays a penalty for a copy operation. Since the iocb is
3244 * only 32 bytes, this penalty is considered small relative to
3245 * the PCI reads for register values and a slim write. When
3246 * the ulpLe field is set, the entire Command has been
3249 entry = lpfc_resp_iocb(phba, pring);
3251 phba->last_completion_time = jiffies;
3252 rspiocbp = __lpfc_sli_get_iocbq(phba);
3253 if (rspiocbp == NULL) {
3254 printk(KERN_ERR "%s: out of buffers! Failing "
3255 "completion.\n", __func__);
3259 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
3260 phba->iocb_rsp_size);
3261 irsp = &rspiocbp->iocb;
3263 if (++pring->rspidx >= portRspMax)
3266 if (pring->ringno == LPFC_ELS_RING) {
3267 lpfc_debugfs_slow_ring_trc(phba,
3268 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3269 *(((uint32_t *) irsp) + 4),
3270 *(((uint32_t *) irsp) + 6),
3271 *(((uint32_t *) irsp) + 7));
3274 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
3276 spin_unlock_irqrestore(&phba->hbalock, iflag);
3277 /* Handle the response IOCB */
3278 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
3279 spin_lock_irqsave(&phba->hbalock, iflag);
3282 * If the port response put pointer has not been updated, sync
3283 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3284 * response put pointer.
3286 if (pring->rspidx == portRspPut) {
3287 portRspPut = le32_to_cpu(pgp->rspPutInx);
3289 } /* while (pring->rspidx != portRspPut) */
3291 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
3292 /* At least one response entry has been freed */
3293 pring->stats.iocb_rsp_full++;
3294 /* SET RxRE_RSP in Chip Att register */
3295 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3296 writel(status, phba->CAregaddr);
3297 readl(phba->CAregaddr); /* flush */
3299 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3300 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3301 pring->stats.iocb_cmd_empty++;
3303 /* Force update of the local copy of cmdGetInx */
3304 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
3305 lpfc_sli_resume_iocb(phba, pring);
3307 if ((pring->lpfc_sli_cmd_available))
3308 (pring->lpfc_sli_cmd_available) (phba, pring);
3312 spin_unlock_irqrestore(&phba->hbalock, iflag);
3317 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3318 * @phba: Pointer to HBA context object.
3319 * @pring: Pointer to driver SLI ring object.
3320 * @mask: Host attention register mask for this ring.
3322 * This function is called from the worker thread when there is a pending
3323 * ELS response iocb on the driver internal slow-path response iocb worker
3324 * queue. The caller does not hold any lock. The function will remove each
3325 * response iocb from the response worker queue and calls the handle
3326 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3329 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3330 struct lpfc_sli_ring *pring, uint32_t mask)
3332 struct lpfc_iocbq *irspiocbq;
3333 struct hbq_dmabuf *dmabuf;
3334 struct lpfc_cq_event *cq_event;
3335 unsigned long iflag;
3337 spin_lock_irqsave(&phba->hbalock, iflag);
3338 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
3339 spin_unlock_irqrestore(&phba->hbalock, iflag);
3340 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
3341 /* Get the response iocb from the head of work queue */
3342 spin_lock_irqsave(&phba->hbalock, iflag);
3343 list_remove_head(&phba->sli4_hba.sp_queue_event,
3344 cq_event, struct lpfc_cq_event, list);
3345 spin_unlock_irqrestore(&phba->hbalock, iflag);
3347 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
3348 case CQE_CODE_COMPL_WQE:
3349 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
3351 /* Translate ELS WCQE to response IOCBQ */
3352 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
3355 lpfc_sli_sp_handle_rspiocb(phba, pring,
3358 case CQE_CODE_RECEIVE:
3359 case CQE_CODE_RECEIVE_V1:
3360 dmabuf = container_of(cq_event, struct hbq_dmabuf,
3362 lpfc_sli4_handle_received_buffer(phba, dmabuf);
3371 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3372 * @phba: Pointer to HBA context object.
3373 * @pring: Pointer to driver SLI ring object.
3375 * This function aborts all iocbs in the given ring and frees all the iocb
3376 * objects in txq. This function issues an abort iocb for all the iocb commands
3377 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3378 * the return of this function. The caller is not required to hold any locks.
3381 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3383 LIST_HEAD(completions);
3384 struct lpfc_iocbq *iocb, *next_iocb;
3386 if (pring->ringno == LPFC_ELS_RING) {
3387 lpfc_fabric_abort_hba(phba);
3390 /* Error everything on txq and txcmplq
3393 spin_lock_irq(&phba->hbalock);
3394 list_splice_init(&pring->txq, &completions);
3397 /* Next issue ABTS for everything on the txcmplq */
3398 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3399 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3401 spin_unlock_irq(&phba->hbalock);
3403 /* Cancel all the IOCBs from the completions list */
3404 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3409 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3410 * @phba: Pointer to HBA context object.
3412 * This function flushes all iocbs in the fcp ring and frees all the iocb
3413 * objects in txq and txcmplq. This function will not issue abort iocbs
3414 * for all the iocb commands in txcmplq, they will just be returned with
3415 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3416 * slot has been permanently disabled.
3419 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3423 struct lpfc_sli *psli = &phba->sli;
3424 struct lpfc_sli_ring *pring;
3426 /* Currently, only one fcp ring */
3427 pring = &psli->ring[psli->fcp_ring];
3429 spin_lock_irq(&phba->hbalock);
3430 /* Retrieve everything on txq */
3431 list_splice_init(&pring->txq, &txq);
3434 /* Retrieve everything on the txcmplq */
3435 list_splice_init(&pring->txcmplq, &txcmplq);
3436 pring->txcmplq_cnt = 0;
3437 spin_unlock_irq(&phba->hbalock);
3440 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3443 /* Flush the txcmpq */
3444 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3449 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3450 * @phba: Pointer to HBA context object.
3451 * @mask: Bit mask to be checked.
3453 * This function reads the host status register and compares
3454 * with the provided bit mask to check if HBA completed
3455 * the restart. This function will wait in a loop for the
3456 * HBA to complete restart. If the HBA does not restart within
3457 * 15 iterations, the function will reset the HBA again. The
3458 * function returns 1 when HBA fail to restart otherwise returns
3462 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
3468 /* Read the HBA Host Status Register */
3469 if (lpfc_readl(phba->HSregaddr, &status))
3473 * Check status register every 100ms for 5 retries, then every
3474 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3475 * every 2.5 sec for 4.
3476 * Break our of the loop if errors occurred during init.
3478 while (((status & mask) != mask) &&
3479 !(status & HS_FFERM) &&
3491 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3492 lpfc_sli_brdrestart(phba);
3494 /* Read the HBA Host Status Register */
3495 if (lpfc_readl(phba->HSregaddr, &status)) {
3501 /* Check to see if any errors occurred during init */
3502 if ((status & HS_FFERM) || (i >= 20)) {
3503 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3504 "2751 Adapter failed to restart, "
3505 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3507 readl(phba->MBslimaddr + 0xa8),
3508 readl(phba->MBslimaddr + 0xac));
3509 phba->link_state = LPFC_HBA_ERROR;
3517 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3518 * @phba: Pointer to HBA context object.
3519 * @mask: Bit mask to be checked.
3521 * This function checks the host status register to check if HBA is
3522 * ready. This function will wait in a loop for the HBA to be ready
3523 * If the HBA is not ready , the function will will reset the HBA PCI
3524 * function again. The function returns 1 when HBA fail to be ready
3525 * otherwise returns zero.
3528 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3533 /* Read the HBA Host Status Register */
3534 status = lpfc_sli4_post_status_check(phba);
3537 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3538 lpfc_sli_brdrestart(phba);
3539 status = lpfc_sli4_post_status_check(phba);
3542 /* Check to see if any errors occurred during init */
3544 phba->link_state = LPFC_HBA_ERROR;
3547 phba->sli4_hba.intr_enable = 0;
3553 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3554 * @phba: Pointer to HBA context object.
3555 * @mask: Bit mask to be checked.
3557 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3558 * from the API jump table function pointer from the lpfc_hba struct.
3561 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3563 return phba->lpfc_sli_brdready(phba, mask);
3566 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3569 * lpfc_reset_barrier - Make HBA ready for HBA reset
3570 * @phba: Pointer to HBA context object.
3572 * This function is called before resetting an HBA. This
3573 * function requests HBA to quiesce DMAs before a reset.
3575 void lpfc_reset_barrier(struct lpfc_hba *phba)
3577 uint32_t __iomem *resp_buf;
3578 uint32_t __iomem *mbox_buf;
3579 volatile uint32_t mbox;
3580 uint32_t hc_copy, ha_copy, resp_data;
3584 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3585 if (hdrtype != 0x80 ||
3586 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3587 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3591 * Tell the other part of the chip to suspend temporarily all
3594 resp_buf = phba->MBslimaddr;
3596 /* Disable the error attention */
3597 if (lpfc_readl(phba->HCregaddr, &hc_copy))
3599 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3600 readl(phba->HCregaddr); /* flush */
3601 phba->link_flag |= LS_IGNORE_ERATT;
3603 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3605 if (ha_copy & HA_ERATT) {
3606 /* Clear Chip error bit */
3607 writel(HA_ERATT, phba->HAregaddr);
3608 phba->pport->stopped = 1;
3612 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
3613 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
3615 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
3616 mbox_buf = phba->MBslimaddr;
3617 writel(mbox, mbox_buf);
3619 for (i = 0; i < 50; i++) {
3620 if (lpfc_readl((resp_buf + 1), &resp_data))
3622 if (resp_data != ~(BARRIER_TEST_PATTERN))
3628 if (lpfc_readl((resp_buf + 1), &resp_data))
3630 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
3631 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
3632 phba->pport->stopped)
3638 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
3640 for (i = 0; i < 500; i++) {
3641 if (lpfc_readl(resp_buf, &resp_data))
3643 if (resp_data != mbox)
3652 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3654 if (!(ha_copy & HA_ERATT))
3660 if (readl(phba->HAregaddr) & HA_ERATT) {
3661 writel(HA_ERATT, phba->HAregaddr);
3662 phba->pport->stopped = 1;
3666 phba->link_flag &= ~LS_IGNORE_ERATT;
3667 writel(hc_copy, phba->HCregaddr);
3668 readl(phba->HCregaddr); /* flush */
3672 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3673 * @phba: Pointer to HBA context object.
3675 * This function issues a kill_board mailbox command and waits for
3676 * the error attention interrupt. This function is called for stopping
3677 * the firmware processing. The caller is not required to hold any
3678 * locks. This function calls lpfc_hba_down_post function to free
3679 * any pending commands after the kill. The function will return 1 when it
3680 * fails to kill the board else will return 0.
3683 lpfc_sli_brdkill(struct lpfc_hba *phba)
3685 struct lpfc_sli *psli;
3695 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3696 "0329 Kill HBA Data: x%x x%x\n",
3697 phba->pport->port_state, psli->sli_flag);
3699 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3703 /* Disable the error attention */
3704 spin_lock_irq(&phba->hbalock);
3705 if (lpfc_readl(phba->HCregaddr, &status)) {
3706 spin_unlock_irq(&phba->hbalock);
3707 mempool_free(pmb, phba->mbox_mem_pool);
3710 status &= ~HC_ERINT_ENA;
3711 writel(status, phba->HCregaddr);
3712 readl(phba->HCregaddr); /* flush */
3713 phba->link_flag |= LS_IGNORE_ERATT;
3714 spin_unlock_irq(&phba->hbalock);
3716 lpfc_kill_board(phba, pmb);
3717 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3718 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3720 if (retval != MBX_SUCCESS) {
3721 if (retval != MBX_BUSY)
3722 mempool_free(pmb, phba->mbox_mem_pool);
3723 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3724 "2752 KILL_BOARD command failed retval %d\n",
3726 spin_lock_irq(&phba->hbalock);
3727 phba->link_flag &= ~LS_IGNORE_ERATT;
3728 spin_unlock_irq(&phba->hbalock);
3732 spin_lock_irq(&phba->hbalock);
3733 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
3734 spin_unlock_irq(&phba->hbalock);
3736 mempool_free(pmb, phba->mbox_mem_pool);
3738 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3739 * attention every 100ms for 3 seconds. If we don't get ERATT after
3740 * 3 seconds we still set HBA_ERROR state because the status of the
3741 * board is now undefined.
3743 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3745 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
3747 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3751 del_timer_sync(&psli->mbox_tmo);
3752 if (ha_copy & HA_ERATT) {
3753 writel(HA_ERATT, phba->HAregaddr);
3754 phba->pport->stopped = 1;
3756 spin_lock_irq(&phba->hbalock);
3757 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3758 psli->mbox_active = NULL;
3759 phba->link_flag &= ~LS_IGNORE_ERATT;
3760 spin_unlock_irq(&phba->hbalock);
3762 lpfc_hba_down_post(phba);
3763 phba->link_state = LPFC_HBA_ERROR;
3765 return ha_copy & HA_ERATT ? 0 : 1;
3769 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3770 * @phba: Pointer to HBA context object.
3772 * This function resets the HBA by writing HC_INITFF to the control
3773 * register. After the HBA resets, this function resets all the iocb ring
3774 * indices. This function disables PCI layer parity checking during
3776 * This function returns 0 always.
3777 * The caller is not required to hold any locks.
3780 lpfc_sli_brdreset(struct lpfc_hba *phba)
3782 struct lpfc_sli *psli;
3783 struct lpfc_sli_ring *pring;
3790 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3791 "0325 Reset HBA Data: x%x x%x\n",
3792 phba->pport->port_state, psli->sli_flag);
3794 /* perform board reset */
3795 phba->fc_eventTag = 0;
3796 phba->link_events = 0;
3797 phba->pport->fc_myDID = 0;
3798 phba->pport->fc_prevDID = 0;
3800 /* Turn off parity checking and serr during the physical reset */
3801 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3802 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3804 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3806 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
3808 /* Now toggle INITFF bit in the Host Control Register */
3809 writel(HC_INITFF, phba->HCregaddr);
3811 readl(phba->HCregaddr); /* flush */
3812 writel(0, phba->HCregaddr);
3813 readl(phba->HCregaddr); /* flush */
3815 /* Restore PCI cmd register */
3816 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3818 /* Initialize relevant SLI info */
3819 for (i = 0; i < psli->num_rings; i++) {
3820 pring = &psli->ring[i];
3823 pring->next_cmdidx = 0;
3824 pring->local_getidx = 0;
3826 pring->missbufcnt = 0;
3829 phba->link_state = LPFC_WARM_START;
3834 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3835 * @phba: Pointer to HBA context object.
3837 * This function resets a SLI4 HBA. This function disables PCI layer parity
3838 * checking during resets the device. The caller is not required to hold
3841 * This function returns 0 always.
3844 lpfc_sli4_brdreset(struct lpfc_hba *phba)
3846 struct lpfc_sli *psli = &phba->sli;
3851 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3852 "0295 Reset HBA Data: x%x x%x\n",
3853 phba->pport->port_state, psli->sli_flag);
3855 /* perform board reset */
3856 phba->fc_eventTag = 0;
3857 phba->link_events = 0;
3858 phba->pport->fc_myDID = 0;
3859 phba->pport->fc_prevDID = 0;
3861 spin_lock_irq(&phba->hbalock);
3862 psli->sli_flag &= ~(LPFC_PROCESS_LA);
3863 phba->fcf.fcf_flag = 0;
3864 /* Clean up the child queue list for the CQs */
3865 list_del_init(&phba->sli4_hba.mbx_wq->list);
3866 list_del_init(&phba->sli4_hba.els_wq->list);
3867 list_del_init(&phba->sli4_hba.hdr_rq->list);
3868 list_del_init(&phba->sli4_hba.dat_rq->list);
3869 list_del_init(&phba->sli4_hba.mbx_cq->list);
3870 list_del_init(&phba->sli4_hba.els_cq->list);
3871 for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
3872 list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
3875 list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
3876 while (++qindx < phba->cfg_fcp_eq_count);
3877 spin_unlock_irq(&phba->hbalock);
3879 /* Now physically reset the device */
3880 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3881 "0389 Performing PCI function reset!\n");
3883 /* Turn off parity checking and serr during the physical reset */
3884 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3885 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
3886 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3888 /* Perform FCoE PCI function reset */
3889 lpfc_pci_function_reset(phba);
3891 /* Restore PCI cmd register */
3892 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3898 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3899 * @phba: Pointer to HBA context object.
3901 * This function is called in the SLI initialization code path to
3902 * restart the HBA. The caller is not required to hold any lock.
3903 * This function writes MBX_RESTART mailbox command to the SLIM and
3904 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3905 * function to free any pending commands. The function enables
3906 * POST only during the first initialization. The function returns zero.
3907 * The function does not guarantee completion of MBX_RESTART mailbox
3908 * command before the return of this function.
3911 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
3914 struct lpfc_sli *psli;
3915 volatile uint32_t word0;
3916 void __iomem *to_slim;
3917 uint32_t hba_aer_enabled;
3919 spin_lock_irq(&phba->hbalock);
3921 /* Take PCIe device Advanced Error Reporting (AER) state */
3922 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
3927 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3928 "0337 Restart HBA Data: x%x x%x\n",
3929 phba->pport->port_state, psli->sli_flag);
3932 mb = (MAILBOX_t *) &word0;
3933 mb->mbxCommand = MBX_RESTART;
3936 lpfc_reset_barrier(phba);
3938 to_slim = phba->MBslimaddr;
3939 writel(*(uint32_t *) mb, to_slim);
3940 readl(to_slim); /* flush */
3942 /* Only skip post after fc_ffinit is completed */
3943 if (phba->pport->port_state)
3944 word0 = 1; /* This is really setting up word1 */
3946 word0 = 0; /* This is really setting up word1 */
3947 to_slim = phba->MBslimaddr + sizeof (uint32_t);
3948 writel(*(uint32_t *) mb, to_slim);
3949 readl(to_slim); /* flush */
3951 lpfc_sli_brdreset(phba);
3952 phba->pport->stopped = 0;
3953 phba->link_state = LPFC_INIT_START;
3955 spin_unlock_irq(&phba->hbalock);
3957 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3958 psli->stats_start = get_seconds();
3960 /* Give the INITFF and Post time to settle. */
3963 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
3964 if (hba_aer_enabled)
3965 pci_disable_pcie_error_reporting(phba->pcidev);
3967 lpfc_hba_down_post(phba);
3973 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3974 * @phba: Pointer to HBA context object.
3976 * This function is called in the SLI initialization code path to restart
3977 * a SLI4 HBA. The caller is not required to hold any lock.
3978 * At the end of the function, it calls lpfc_hba_down_post function to
3979 * free any pending commands.
3982 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
3984 struct lpfc_sli *psli = &phba->sli;
3985 uint32_t hba_aer_enabled;
3988 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3989 "0296 Restart HBA Data: x%x x%x\n",
3990 phba->pport->port_state, psli->sli_flag);
3992 /* Take PCIe device Advanced Error Reporting (AER) state */
3993 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
3995 lpfc_sli4_brdreset(phba);
3997 spin_lock_irq(&phba->hbalock);
3998 phba->pport->stopped = 0;
3999 phba->link_state = LPFC_INIT_START;
4001 spin_unlock_irq(&phba->hbalock);
4003 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4004 psli->stats_start = get_seconds();
4006 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4007 if (hba_aer_enabled)
4008 pci_disable_pcie_error_reporting(phba->pcidev);
4010 lpfc_hba_down_post(phba);
4016 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4017 * @phba: Pointer to HBA context object.
4019 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4020 * API jump table function pointer from the lpfc_hba struct.
4023 lpfc_sli_brdrestart(struct lpfc_hba *phba)
4025 return phba->lpfc_sli_brdrestart(phba);
4029 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4030 * @phba: Pointer to HBA context object.
4032 * This function is called after a HBA restart to wait for successful
4033 * restart of the HBA. Successful restart of the HBA is indicated by
4034 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4035 * iteration, the function will restart the HBA again. The function returns
4036 * zero if HBA successfully restarted else returns negative error code.
4039 lpfc_sli_chipset_init(struct lpfc_hba *phba)
4041 uint32_t status, i = 0;
4043 /* Read the HBA Host Status Register */
4044 if (lpfc_readl(phba->HSregaddr, &status))
4047 /* Check status register to see what current state is */
4049 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4051 /* Check every 10ms for 10 retries, then every 100ms for 90
4052 * retries, then every 1 sec for 50 retires for a total of
4053 * ~60 seconds before reset the board again and check every
4054 * 1 sec for 50 retries. The up to 60 seconds before the
4055 * board ready is required by the Falcon FIPS zeroization
4056 * complete, and any reset the board in between shall cause
4057 * restart of zeroization, further delay the board ready.
4060 /* Adapter failed to init, timeout, status reg
4062 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4063 "0436 Adapter failed to init, "
4064 "timeout, status reg x%x, "
4065 "FW Data: A8 x%x AC x%x\n", status,
4066 readl(phba->MBslimaddr + 0xa8),
4067 readl(phba->MBslimaddr + 0xac));
4068 phba->link_state = LPFC_HBA_ERROR;
4072 /* Check to see if any errors occurred during init */
4073 if (status & HS_FFERM) {
4074 /* ERROR: During chipset initialization */
4075 /* Adapter failed to init, chipset, status reg
4077 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4078 "0437 Adapter failed to init, "
4079 "chipset, status reg x%x, "
4080 "FW Data: A8 x%x AC x%x\n", status,
4081 readl(phba->MBslimaddr + 0xa8),
4082 readl(phba->MBslimaddr + 0xac));
4083 phba->link_state = LPFC_HBA_ERROR;
4096 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4097 lpfc_sli_brdrestart(phba);
4099 /* Read the HBA Host Status Register */
4100 if (lpfc_readl(phba->HSregaddr, &status))
4104 /* Check to see if any errors occurred during init */
4105 if (status & HS_FFERM) {
4106 /* ERROR: During chipset initialization */
4107 /* Adapter failed to init, chipset, status reg <status> */
4108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4109 "0438 Adapter failed to init, chipset, "
4111 "FW Data: A8 x%x AC x%x\n", status,
4112 readl(phba->MBslimaddr + 0xa8),
4113 readl(phba->MBslimaddr + 0xac));
4114 phba->link_state = LPFC_HBA_ERROR;
4118 /* Clear all interrupt enable conditions */
4119 writel(0, phba->HCregaddr);
4120 readl(phba->HCregaddr); /* flush */
4122 /* setup host attn register */
4123 writel(0xffffffff, phba->HAregaddr);
4124 readl(phba->HAregaddr); /* flush */
4129 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4131 * This function calculates and returns the number of HBQs required to be
4135 lpfc_sli_hbq_count(void)
4137 return ARRAY_SIZE(lpfc_hbq_defs);
4141 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4143 * This function adds the number of hbq entries in every HBQ to get
4144 * the total number of hbq entries required for the HBA and returns
4148 lpfc_sli_hbq_entry_count(void)
4150 int hbq_count = lpfc_sli_hbq_count();
4154 for (i = 0; i < hbq_count; ++i)
4155 count += lpfc_hbq_defs[i]->entry_count;
4160 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4162 * This function calculates amount of memory required for all hbq entries
4163 * to be configured and returns the total memory required.
4166 lpfc_sli_hbq_size(void)
4168 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
4172 * lpfc_sli_hbq_setup - configure and initialize HBQs
4173 * @phba: Pointer to HBA context object.
4175 * This function is called during the SLI initialization to configure
4176 * all the HBQs and post buffers to the HBQ. The caller is not
4177 * required to hold any locks. This function will return zero if successful
4178 * else it will return negative error code.
4181 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
4183 int hbq_count = lpfc_sli_hbq_count();
4187 uint32_t hbq_entry_index;
4189 /* Get a Mailbox buffer to setup mailbox
4190 * commands for HBA initialization
4192 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4199 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4200 phba->link_state = LPFC_INIT_MBX_CMDS;
4201 phba->hbq_in_use = 1;
4203 hbq_entry_index = 0;
4204 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
4205 phba->hbqs[hbqno].next_hbqPutIdx = 0;
4206 phba->hbqs[hbqno].hbqPutIdx = 0;
4207 phba->hbqs[hbqno].local_hbqGetIdx = 0;
4208 phba->hbqs[hbqno].entry_count =
4209 lpfc_hbq_defs[hbqno]->entry_count;
4210 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
4211 hbq_entry_index, pmb);
4212 hbq_entry_index += phba->hbqs[hbqno].entry_count;
4214 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
4215 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4216 mbxStatus <status>, ring <num> */
4218 lpfc_printf_log(phba, KERN_ERR,
4219 LOG_SLI | LOG_VPORT,
4220 "1805 Adapter failed to init. "
4221 "Data: x%x x%x x%x\n",
4223 pmbox->mbxStatus, hbqno);
4225 phba->link_state = LPFC_HBA_ERROR;
4226 mempool_free(pmb, phba->mbox_mem_pool);
4230 phba->hbq_count = hbq_count;
4232 mempool_free(pmb, phba->mbox_mem_pool);
4234 /* Initially populate or replenish the HBQs */
4235 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
4236 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
4241 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4242 * @phba: Pointer to HBA context object.
4244 * This function is called during the SLI initialization to configure
4245 * all the HBQs and post buffers to the HBQ. The caller is not
4246 * required to hold any locks. This function will return zero if successful
4247 * else it will return negative error code.
4250 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
4252 phba->hbq_in_use = 1;
4253 phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
4254 phba->hbq_count = 1;
4255 /* Initially populate or replenish the HBQs */
4256 lpfc_sli_hbqbuf_init_hbqs(phba, 0);
4261 * lpfc_sli_config_port - Issue config port mailbox command
4262 * @phba: Pointer to HBA context object.
4263 * @sli_mode: sli mode - 2/3
4265 * This function is called by the sli intialization code path
4266 * to issue config_port mailbox command. This function restarts the
4267 * HBA firmware and issues a config_port mailbox command to configure
4268 * the SLI interface in the sli mode specified by sli_mode
4269 * variable. The caller is not required to hold any locks.
4270 * The function returns 0 if successful, else returns negative error
4274 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
4277 uint32_t resetcount = 0, rc = 0, done = 0;
4279 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4281 phba->link_state = LPFC_HBA_ERROR;
4285 phba->sli_rev = sli_mode;
4286 while (resetcount < 2 && !done) {
4287 spin_lock_irq(&phba->hbalock);
4288 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4289 spin_unlock_irq(&phba->hbalock);
4290 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4291 lpfc_sli_brdrestart(phba);
4292 rc = lpfc_sli_chipset_init(phba);
4296 spin_lock_irq(&phba->hbalock);
4297 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4298 spin_unlock_irq(&phba->hbalock);
4301 /* Call pre CONFIG_PORT mailbox command initialization. A
4302 * value of 0 means the call was successful. Any other
4303 * nonzero value is a failure, but if ERESTART is returned,
4304 * the driver may reset the HBA and try again.
4306 rc = lpfc_config_port_prep(phba);
4307 if (rc == -ERESTART) {
4308 phba->link_state = LPFC_LINK_UNKNOWN;
4313 phba->link_state = LPFC_INIT_MBX_CMDS;
4314 lpfc_config_port(phba, pmb);
4315 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4316 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
4317 LPFC_SLI3_HBQ_ENABLED |
4318 LPFC_SLI3_CRP_ENABLED |
4319 LPFC_SLI3_BG_ENABLED |
4320 LPFC_SLI3_DSS_ENABLED);
4321 if (rc != MBX_SUCCESS) {
4322 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4323 "0442 Adapter failed to init, mbxCmd x%x "
4324 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4325 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
4326 spin_lock_irq(&phba->hbalock);
4327 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
4328 spin_unlock_irq(&phba->hbalock);
4331 /* Allow asynchronous mailbox command to go through */
4332 spin_lock_irq(&phba->hbalock);
4333 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4334 spin_unlock_irq(&phba->hbalock);
4340 goto do_prep_failed;
4342 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
4343 if (!pmb->u.mb.un.varCfgPort.cMA) {
4345 goto do_prep_failed;
4347 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
4348 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
4349 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
4350 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
4351 phba->max_vpi : phba->max_vports;
4355 phba->fips_level = 0;
4356 phba->fips_spec_rev = 0;
4357 if (pmb->u.mb.un.varCfgPort.gdss) {
4358 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
4359 phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
4360 phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
4361 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4362 "2850 Security Crypto Active. FIPS x%d "
4364 phba->fips_level, phba->fips_spec_rev);
4366 if (pmb->u.mb.un.varCfgPort.sec_err) {
4367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4368 "2856 Config Port Security Crypto "
4370 pmb->u.mb.un.varCfgPort.sec_err);
4372 if (pmb->u.mb.un.varCfgPort.gerbm)
4373 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
4374 if (pmb->u.mb.un.varCfgPort.gcrp)
4375 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
4377 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
4378 phba->port_gp = phba->mbox->us.s3_pgp.port;
4380 if (phba->cfg_enable_bg) {
4381 if (pmb->u.mb.un.varCfgPort.gbg)
4382 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
4384 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4385 "0443 Adapter did not grant "
4389 phba->hbq_get = NULL;
4390 phba->port_gp = phba->mbox->us.s2.port;
4394 mempool_free(pmb, phba->mbox_mem_pool);
4400 * lpfc_sli_hba_setup - SLI intialization function
4401 * @phba: Pointer to HBA context object.
4403 * This function is the main SLI intialization function. This function
4404 * is called by the HBA intialization code, HBA reset code and HBA
4405 * error attention handler code. Caller is not required to hold any
4406 * locks. This function issues config_port mailbox command to configure
4407 * the SLI, setup iocb rings and HBQ rings. In the end the function
4408 * calls the config_port_post function to issue init_link mailbox
4409 * command and to start the discovery. The function will return zero
4410 * if successful, else it will return negative error code.
4413 lpfc_sli_hba_setup(struct lpfc_hba *phba)
4419 switch (lpfc_sli_mode) {
4421 if (phba->cfg_enable_npiv) {
4422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4423 "1824 NPIV enabled: Override lpfc_sli_mode "
4424 "parameter (%d) to auto (0).\n",
4434 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4435 "1819 Unrecognized lpfc_sli_mode "
4436 "parameter: %d.\n", lpfc_sli_mode);
4441 rc = lpfc_sli_config_port(phba, mode);
4443 if (rc && lpfc_sli_mode == 3)
4444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4445 "1820 Unable to select SLI-3. "
4446 "Not supported by adapter.\n");
4447 if (rc && mode != 2)
4448 rc = lpfc_sli_config_port(phba, 2);
4450 goto lpfc_sli_hba_setup_error;
4452 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4453 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
4454 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4456 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4457 "2709 This device supports "
4458 "Advanced Error Reporting (AER)\n");
4459 spin_lock_irq(&phba->hbalock);
4460 phba->hba_flag |= HBA_AER_ENABLED;
4461 spin_unlock_irq(&phba->hbalock);
4463 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4464 "2708 This device does not support "
4465 "Advanced Error Reporting (AER)\n");
4466 phba->cfg_aer_support = 0;
4470 if (phba->sli_rev == 3) {
4471 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4472 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
4474 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4475 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
4476 phba->sli3_options = 0;
4479 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4480 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4481 phba->sli_rev, phba->max_vpi);
4482 rc = lpfc_sli_ring_map(phba);
4485 goto lpfc_sli_hba_setup_error;
4487 /* Initialize VPIs. */
4488 if (phba->sli_rev == LPFC_SLI_REV3) {
4490 * The VPI bitmask and physical ID array are allocated
4491 * and initialized once only - at driver load. A port
4492 * reset doesn't need to reinitialize this memory.
4494 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
4495 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
4496 phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
4498 if (!phba->vpi_bmask) {
4500 goto lpfc_sli_hba_setup_error;
4503 phba->vpi_ids = kzalloc(
4504 (phba->max_vpi+1) * sizeof(uint16_t),
4506 if (!phba->vpi_ids) {
4507 kfree(phba->vpi_bmask);
4509 goto lpfc_sli_hba_setup_error;
4511 for (i = 0; i < phba->max_vpi; i++)
4512 phba->vpi_ids[i] = i;
4517 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4518 rc = lpfc_sli_hbq_setup(phba);
4520 goto lpfc_sli_hba_setup_error;
4522 spin_lock_irq(&phba->hbalock);
4523 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4524 spin_unlock_irq(&phba->hbalock);
4526 rc = lpfc_config_port_post(phba);
4528 goto lpfc_sli_hba_setup_error;
4532 lpfc_sli_hba_setup_error:
4533 phba->link_state = LPFC_HBA_ERROR;
4534 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4535 "0445 Firmware initialization failed\n");
4540 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4541 * @phba: Pointer to HBA context object.
4542 * @mboxq: mailbox pointer.
4543 * This function issue a dump mailbox command to read config region
4544 * 23 and parse the records in the region and populate driver
4548 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
4549 LPFC_MBOXQ_t *mboxq)
4551 struct lpfc_dmabuf *mp;
4552 struct lpfc_mqe *mqe;
4553 uint32_t data_length;
4556 /* Program the default value of vlan_id and fc_map */
4557 phba->valid_vlan = 0;
4558 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4559 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4560 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4562 mqe = &mboxq->u.mqe;
4563 if (lpfc_dump_fcoe_param(phba, mboxq))
4566 mp = (struct lpfc_dmabuf *) mboxq->context1;
4567 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4569 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4570 "(%d):2571 Mailbox cmd x%x Status x%x "
4571 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4572 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4573 "CQ: x%x x%x x%x x%x\n",
4574 mboxq->vport ? mboxq->vport->vpi : 0,
4575 bf_get(lpfc_mqe_command, mqe),
4576 bf_get(lpfc_mqe_status, mqe),
4577 mqe->un.mb_words[0], mqe->un.mb_words[1],
4578 mqe->un.mb_words[2], mqe->un.mb_words[3],
4579 mqe->un.mb_words[4], mqe->un.mb_words[5],
4580 mqe->un.mb_words[6], mqe->un.mb_words[7],
4581 mqe->un.mb_words[8], mqe->un.mb_words[9],
4582 mqe->un.mb_words[10], mqe->un.mb_words[11],
4583 mqe->un.mb_words[12], mqe->un.mb_words[13],
4584 mqe->un.mb_words[14], mqe->un.mb_words[15],
4585 mqe->un.mb_words[16], mqe->un.mb_words[50],
4587 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4588 mboxq->mcqe.trailer);
4591 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4595 data_length = mqe->un.mb_words[5];
4596 if (data_length > DMP_RGN23_SIZE) {
4597 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4602 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
4603 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4609 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4610 * @phba: pointer to lpfc hba data structure.
4611 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4612 * @vpd: pointer to the memory to hold resulting port vpd data.
4613 * @vpd_size: On input, the number of bytes allocated to @vpd.
4614 * On output, the number of data bytes in @vpd.
4616 * This routine executes a READ_REV SLI4 mailbox command. In
4617 * addition, this routine gets the port vpd data.
4621 * -ENOMEM - could not allocated memory.
4624 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4625 uint8_t *vpd, uint32_t *vpd_size)
4629 struct lpfc_dmabuf *dmabuf;
4630 struct lpfc_mqe *mqe;
4632 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4637 * Get a DMA buffer for the vpd data resulting from the READ_REV
4640 dma_size = *vpd_size;
4641 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4645 if (!dmabuf->virt) {
4649 memset(dmabuf->virt, 0, dma_size);
4652 * The SLI4 implementation of READ_REV conflicts at word1,
4653 * bits 31:16 and SLI4 adds vpd functionality not present
4654 * in SLI3. This code corrects the conflicts.
4656 lpfc_read_rev(phba, mboxq);
4657 mqe = &mboxq->u.mqe;
4658 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
4659 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
4660 mqe->un.read_rev.word1 &= 0x0000FFFF;
4661 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
4662 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
4664 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4666 dma_free_coherent(&phba->pcidev->dev, dma_size,
4667 dmabuf->virt, dmabuf->phys);
4673 * The available vpd length cannot be bigger than the
4674 * DMA buffer passed to the port. Catch the less than
4675 * case and update the caller's size.
4677 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
4678 *vpd_size = mqe->un.read_rev.avail_vpd_len;
4680 memcpy(vpd, dmabuf->virt, *vpd_size);
4682 dma_free_coherent(&phba->pcidev->dev, dma_size,
4683 dmabuf->virt, dmabuf->phys);
4689 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4690 * @phba: pointer to lpfc hba data structure.
4692 * This routine is called to explicitly arm the SLI4 device's completion and
4696 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
4700 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
4701 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
4704 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
4706 while (++fcp_eqidx < phba->cfg_fcp_eq_count);
4707 lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
4708 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4709 lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
4714 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4715 * @phba: Pointer to HBA context object.
4716 * @type: The resource extent type.
4718 * This function allocates all SLI4 resource identifiers.
4721 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
4722 uint16_t *extnt_count, uint16_t *extnt_size)
4727 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
4730 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4734 /* Find out how many extents are available for this resource type */
4735 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
4736 sizeof(struct lpfc_sli4_cfg_mhdr));
4737 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
4738 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
4739 length, LPFC_SLI4_MBX_EMBED);
4741 /* Send an extents count of 0 - the GET doesn't use it. */
4742 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
4743 LPFC_SLI4_MBX_EMBED);
4749 if (!phba->sli4_hba.intr_enable)
4750 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
4752 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
4753 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
4760 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
4761 if (bf_get(lpfc_mbox_hdr_status,
4762 &rsrc_info->header.cfg_shdr.response)) {
4763 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
4764 "2930 Failed to get resource extents "
4765 "Status 0x%x Add'l Status 0x%x\n",
4766 bf_get(lpfc_mbox_hdr_status,
4767 &rsrc_info->header.cfg_shdr.response),
4768 bf_get(lpfc_mbox_hdr_add_status,
4769 &rsrc_info->header.cfg_shdr.response));
4774 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
4776 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
4779 mempool_free(mbox, phba->mbox_mem_pool);
4784 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
4785 * @phba: Pointer to HBA context object.
4786 * @type: The extent type to check.
4788 * This function reads the current available extents from the port and checks
4789 * if the extent count or extent size has changed since the last access.
4790 * Callers use this routine post port reset to understand if there is a
4791 * extent reprovisioning requirement.
4794 * -Error: error indicates problem.
4795 * 1: Extent count or size has changed.
4799 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
4801 uint16_t curr_ext_cnt, rsrc_ext_cnt;
4802 uint16_t size_diff, rsrc_ext_size;
4804 struct lpfc_rsrc_blks *rsrc_entry;
4805 struct list_head *rsrc_blk_list = NULL;
4809 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
4816 case LPFC_RSC_TYPE_FCOE_RPI:
4817 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
4819 case LPFC_RSC_TYPE_FCOE_VPI:
4820 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
4822 case LPFC_RSC_TYPE_FCOE_XRI:
4823 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
4825 case LPFC_RSC_TYPE_FCOE_VFI:
4826 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
4832 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
4834 if (rsrc_entry->rsrc_size != rsrc_ext_size)
4838 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
4845 * lpfc_sli4_cfg_post_extnts -
4846 * @phba: Pointer to HBA context object.
4847 * @extnt_cnt - number of available extents.
4848 * @type - the extent type (rpi, xri, vfi, vpi).
4849 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
4850 * @mbox - pointer to the caller's allocated mailbox structure.
4852 * This function executes the extents allocation request. It also
4853 * takes care of the amount of memory needed to allocate or get the
4854 * allocated extents. It is the caller's responsibility to evaluate
4858 * -Error: Error value describes the condition found.
4862 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt,
4863 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
4868 uint32_t alloc_len, mbox_tmo;
4870 /* Calculate the total requested length of the dma memory */
4871 req_len = *extnt_cnt * sizeof(uint16_t);
4874 * Calculate the size of an embedded mailbox. The uint32_t
4875 * accounts for extents-specific word.
4877 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
4881 * Presume the allocation and response will fit into an embedded
4882 * mailbox. If not true, reconfigure to a non-embedded mailbox.
4884 *emb = LPFC_SLI4_MBX_EMBED;
4885 if (req_len > emb_len) {
4886 req_len = *extnt_cnt * sizeof(uint16_t) +
4887 sizeof(union lpfc_sli4_cfg_shdr) +
4889 *emb = LPFC_SLI4_MBX_NEMBED;
4892 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
4893 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
4895 if (alloc_len < req_len) {
4896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4897 "9000 Allocated DMA memory size (x%x) is "
4898 "less than the requested DMA memory "
4899 "size (x%x)\n", alloc_len, req_len);
4902 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb);
4906 if (!phba->sli4_hba.intr_enable)
4907 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
4909 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
4910 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
4919 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
4920 * @phba: Pointer to HBA context object.
4921 * @type: The resource extent type to allocate.
4923 * This function allocates the number of elements for the specified
4927 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
4930 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
4931 uint16_t rsrc_id, rsrc_start, j, k;
4934 unsigned long longs;
4935 unsigned long *bmask;
4936 struct lpfc_rsrc_blks *rsrc_blks;
4939 struct lpfc_id_range *id_array = NULL;
4940 void *virtaddr = NULL;
4941 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
4942 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
4943 struct list_head *ext_blk_list;
4945 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
4951 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
4952 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
4953 "3009 No available Resource Extents "
4954 "for resource type 0x%x: Count: 0x%x, "
4955 "Size 0x%x\n", type, rsrc_cnt,
4960 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT,
4961 "2903 Available Resource Extents "
4962 "for resource type 0x%x: Count: 0x%x, "
4963 "Size 0x%x\n", type, rsrc_cnt,
4966 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4970 rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox);
4977 * Figure out where the response is located. Then get local pointers
4978 * to the response data. The port does not guarantee to respond to
4979 * all extents counts request so update the local variable with the
4980 * allocated count from the port.
4982 if (emb == LPFC_SLI4_MBX_EMBED) {
4983 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
4984 id_array = &rsrc_ext->u.rsp.id[0];
4985 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
4987 virtaddr = mbox->sge_array->addr[0];
4988 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
4989 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
4990 id_array = &n_rsrc->id;
4993 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
4994 rsrc_id_cnt = rsrc_cnt * rsrc_size;
4997 * Based on the resource size and count, correct the base and max
5000 length = sizeof(struct lpfc_rsrc_blks);
5002 case LPFC_RSC_TYPE_FCOE_RPI:
5003 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5004 sizeof(unsigned long),
5006 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5010 phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
5013 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5014 kfree(phba->sli4_hba.rpi_bmask);
5020 * The next_rpi was initialized with the maximum available
5021 * count but the port may allocate a smaller number. Catch
5022 * that case and update the next_rpi.
5024 phba->sli4_hba.next_rpi = rsrc_id_cnt;
5026 /* Initialize local ptrs for common extent processing later. */
5027 bmask = phba->sli4_hba.rpi_bmask;
5028 ids = phba->sli4_hba.rpi_ids;
5029 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5031 case LPFC_RSC_TYPE_FCOE_VPI:
5032 phba->vpi_bmask = kzalloc(longs *
5033 sizeof(unsigned long),
5035 if (unlikely(!phba->vpi_bmask)) {
5039 phba->vpi_ids = kzalloc(rsrc_id_cnt *
5042 if (unlikely(!phba->vpi_ids)) {
5043 kfree(phba->vpi_bmask);
5048 /* Initialize local ptrs for common extent processing later. */
5049 bmask = phba->vpi_bmask;
5050 ids = phba->vpi_ids;
5051 ext_blk_list = &phba->lpfc_vpi_blk_list;
5053 case LPFC_RSC_TYPE_FCOE_XRI:
5054 phba->sli4_hba.xri_bmask = kzalloc(longs *
5055 sizeof(unsigned long),
5057 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5061 phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
5064 if (unlikely(!phba->sli4_hba.xri_ids)) {
5065 kfree(phba->sli4_hba.xri_bmask);
5070 /* Initialize local ptrs for common extent processing later. */
5071 bmask = phba->sli4_hba.xri_bmask;
5072 ids = phba->sli4_hba.xri_ids;
5073 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5075 case LPFC_RSC_TYPE_FCOE_VFI:
5076 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5077 sizeof(unsigned long),
5079 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5083 phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
5086 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5087 kfree(phba->sli4_hba.vfi_bmask);
5092 /* Initialize local ptrs for common extent processing later. */
5093 bmask = phba->sli4_hba.vfi_bmask;
5094 ids = phba->sli4_hba.vfi_ids;
5095 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5098 /* Unsupported Opcode. Fail call. */
5102 ext_blk_list = NULL;
5107 * Complete initializing the extent configuration with the
5108 * allocated ids assigned to this function. The bitmask serves
5109 * as an index into the array and manages the available ids. The
5110 * array just stores the ids communicated to the port via the wqes.
5112 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
5114 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
5117 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
5120 rsrc_blks = kzalloc(length, GFP_KERNEL);
5121 if (unlikely(!rsrc_blks)) {
5127 rsrc_blks->rsrc_start = rsrc_id;
5128 rsrc_blks->rsrc_size = rsrc_size;
5129 list_add_tail(&rsrc_blks->list, ext_blk_list);
5130 rsrc_start = rsrc_id;
5131 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
5132 phba->sli4_hba.scsi_xri_start = rsrc_start +
5133 lpfc_sli4_get_els_iocb_cnt(phba);
5135 while (rsrc_id < (rsrc_start + rsrc_size)) {
5140 /* Entire word processed. Get next word.*/
5145 lpfc_sli4_mbox_cmd_free(phba, mbox);
5150 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5151 * @phba: Pointer to HBA context object.
5152 * @type: the extent's type.
5154 * This function deallocates all extents of a particular resource type.
5155 * SLI4 does not allow for deallocating a particular extent range. It
5156 * is the caller's responsibility to release all kernel memory resources.
5159 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
5162 uint32_t length, mbox_tmo = 0;
5164 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
5165 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
5167 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5172 * This function sends an embedded mailbox because it only sends the
5173 * the resource type. All extents of this type are released by the
5176 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
5177 sizeof(struct lpfc_sli4_cfg_mhdr));
5178 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5179 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
5180 length, LPFC_SLI4_MBX_EMBED);
5182 /* Send an extents count of 0 - the dealloc doesn't use it. */
5183 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5184 LPFC_SLI4_MBX_EMBED);
5189 if (!phba->sli4_hba.intr_enable)
5190 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5192 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox_tmo);
5193 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5200 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
5201 if (bf_get(lpfc_mbox_hdr_status,
5202 &dealloc_rsrc->header.cfg_shdr.response)) {
5203 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5204 "2919 Failed to release resource extents "
5205 "for type %d - Status 0x%x Add'l Status 0x%x. "
5206 "Resource memory not released.\n",
5208 bf_get(lpfc_mbox_hdr_status,
5209 &dealloc_rsrc->header.cfg_shdr.response),
5210 bf_get(lpfc_mbox_hdr_add_status,
5211 &dealloc_rsrc->header.cfg_shdr.response));
5216 /* Release kernel memory resources for the specific type. */
5218 case LPFC_RSC_TYPE_FCOE_VPI:
5219 kfree(phba->vpi_bmask);
5220 kfree(phba->vpi_ids);
5221 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5222 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5223 &phba->lpfc_vpi_blk_list, list) {
5224 list_del_init(&rsrc_blk->list);
5228 case LPFC_RSC_TYPE_FCOE_XRI:
5229 kfree(phba->sli4_hba.xri_bmask);
5230 kfree(phba->sli4_hba.xri_ids);
5231 bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5232 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5233 &phba->sli4_hba.lpfc_xri_blk_list, list) {
5234 list_del_init(&rsrc_blk->list);
5238 case LPFC_RSC_TYPE_FCOE_VFI:
5239 kfree(phba->sli4_hba.vfi_bmask);
5240 kfree(phba->sli4_hba.vfi_ids);
5241 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5242 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5243 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
5244 list_del_init(&rsrc_blk->list);
5248 case LPFC_RSC_TYPE_FCOE_RPI:
5249 /* RPI bitmask and physical id array are cleaned up earlier. */
5250 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5251 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
5252 list_del_init(&rsrc_blk->list);
5260 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5263 mempool_free(mbox, phba->mbox_mem_pool);
5268 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5269 * @phba: Pointer to HBA context object.
5271 * This function allocates all SLI4 resource identifiers.
5274 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
5276 int i, rc, error = 0;
5277 uint16_t count, base;
5278 unsigned long longs;
5280 if (phba->sli4_hba.extents_in_use) {
5282 * The port supports resource extents. The XRI, VPI, VFI, RPI
5283 * resource extent count must be read and allocated before
5284 * provisioning the resource id arrays.
5286 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5287 LPFC_IDX_RSRC_RDY) {
5289 * Extent-based resources are set - the driver could
5290 * be in a port reset. Figure out if any corrective
5291 * actions need to be taken.
5293 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5294 LPFC_RSC_TYPE_FCOE_VFI);
5297 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5298 LPFC_RSC_TYPE_FCOE_VPI);
5301 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5302 LPFC_RSC_TYPE_FCOE_XRI);
5305 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5306 LPFC_RSC_TYPE_FCOE_RPI);
5311 * It's possible that the number of resources
5312 * provided to this port instance changed between
5313 * resets. Detect this condition and reallocate
5314 * resources. Otherwise, there is no action.
5317 lpfc_printf_log(phba, KERN_INFO,
5318 LOG_MBOX | LOG_INIT,
5319 "2931 Detected extent resource "
5320 "change. Reallocating all "
5322 rc = lpfc_sli4_dealloc_extent(phba,
5323 LPFC_RSC_TYPE_FCOE_VFI);
5324 rc = lpfc_sli4_dealloc_extent(phba,
5325 LPFC_RSC_TYPE_FCOE_VPI);
5326 rc = lpfc_sli4_dealloc_extent(phba,
5327 LPFC_RSC_TYPE_FCOE_XRI);
5328 rc = lpfc_sli4_dealloc_extent(phba,
5329 LPFC_RSC_TYPE_FCOE_RPI);
5334 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5338 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5342 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5346 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5349 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5354 * The port does not support resource extents. The XRI, VPI,
5355 * VFI, RPI resource ids were determined from READ_CONFIG.
5356 * Just allocate the bitmasks and provision the resource id
5357 * arrays. If a port reset is active, the resources don't
5358 * need any action - just exit.
5360 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5365 count = phba->sli4_hba.max_cfg_param.max_rpi;
5366 base = phba->sli4_hba.max_cfg_param.rpi_base;
5367 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5368 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5369 sizeof(unsigned long),
5371 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5375 phba->sli4_hba.rpi_ids = kzalloc(count *
5378 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5380 goto free_rpi_bmask;
5383 for (i = 0; i < count; i++)
5384 phba->sli4_hba.rpi_ids[i] = base + i;
5387 count = phba->sli4_hba.max_cfg_param.max_vpi;
5388 base = phba->sli4_hba.max_cfg_param.vpi_base;
5389 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5390 phba->vpi_bmask = kzalloc(longs *
5391 sizeof(unsigned long),
5393 if (unlikely(!phba->vpi_bmask)) {
5397 phba->vpi_ids = kzalloc(count *
5400 if (unlikely(!phba->vpi_ids)) {
5402 goto free_vpi_bmask;
5405 for (i = 0; i < count; i++)
5406 phba->vpi_ids[i] = base + i;
5409 count = phba->sli4_hba.max_cfg_param.max_xri;
5410 base = phba->sli4_hba.max_cfg_param.xri_base;
5411 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5412 phba->sli4_hba.xri_bmask = kzalloc(longs *
5413 sizeof(unsigned long),
5415 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5419 phba->sli4_hba.xri_ids = kzalloc(count *
5422 if (unlikely(!phba->sli4_hba.xri_ids)) {
5424 goto free_xri_bmask;
5427 for (i = 0; i < count; i++)
5428 phba->sli4_hba.xri_ids[i] = base + i;
5431 count = phba->sli4_hba.max_cfg_param.max_vfi;
5432 base = phba->sli4_hba.max_cfg_param.vfi_base;
5433 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5434 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5435 sizeof(unsigned long),
5437 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5441 phba->sli4_hba.vfi_ids = kzalloc(count *
5444 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5446 goto free_vfi_bmask;
5449 for (i = 0; i < count; i++)
5450 phba->sli4_hba.vfi_ids[i] = base + i;
5453 * Mark all resources ready. An HBA reset doesn't need
5454 * to reset the initialization.
5456 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5462 kfree(phba->sli4_hba.vfi_bmask);
5464 kfree(phba->sli4_hba.xri_ids);
5466 kfree(phba->sli4_hba.xri_bmask);
5468 kfree(phba->vpi_ids);
5470 kfree(phba->vpi_bmask);
5472 kfree(phba->sli4_hba.rpi_ids);
5474 kfree(phba->sli4_hba.rpi_bmask);
5480 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5481 * @phba: Pointer to HBA context object.
5483 * This function allocates the number of elements for the specified
5487 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
5489 if (phba->sli4_hba.extents_in_use) {
5490 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5491 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5492 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5493 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5495 kfree(phba->vpi_bmask);
5496 kfree(phba->vpi_ids);
5497 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5498 kfree(phba->sli4_hba.xri_bmask);
5499 kfree(phba->sli4_hba.xri_ids);
5500 bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5501 kfree(phba->sli4_hba.vfi_bmask);
5502 kfree(phba->sli4_hba.vfi_ids);
5503 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5504 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5511 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
5512 * @phba: Pointer to HBA context object.
5514 * This function is the main SLI4 device intialization PCI function. This
5515 * function is called by the HBA intialization code, HBA reset code and
5516 * HBA error attention handler code. Caller is not required to hold any
5520 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
5523 LPFC_MBOXQ_t *mboxq;
5524 struct lpfc_mqe *mqe;
5527 uint32_t ftr_rsp = 0;
5528 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
5529 struct lpfc_vport *vport = phba->pport;
5530 struct lpfc_dmabuf *mp;
5532 /* Perform a PCI function reset to start from clean */
5533 rc = lpfc_pci_function_reset(phba);
5537 /* Check the HBA Host Status Register for readyness */
5538 rc = lpfc_sli4_post_status_check(phba);
5542 spin_lock_irq(&phba->hbalock);
5543 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
5544 spin_unlock_irq(&phba->hbalock);
5548 * Allocate a single mailbox container for initializing the
5551 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5556 * Continue initialization with default values even if driver failed
5557 * to read FCoE param config regions
5559 if (lpfc_sli4_read_fcoe_params(phba, mboxq))
5560 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
5561 "2570 Failed to read FCoE parameters\n");
5563 /* Issue READ_REV to collect vpd and FW information. */
5564 vpd_size = SLI4_PAGE_SIZE;
5565 vpd = kzalloc(vpd_size, GFP_KERNEL);
5571 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
5576 mqe = &mboxq->u.mqe;
5577 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
5578 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
5579 phba->hba_flag |= HBA_FCOE_MODE;
5581 phba->hba_flag &= ~HBA_FCOE_MODE;
5583 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
5585 phba->hba_flag |= HBA_FIP_SUPPORT;
5587 phba->hba_flag &= ~HBA_FIP_SUPPORT;
5589 if (phba->sli_rev != LPFC_SLI_REV4) {
5590 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5591 "0376 READ_REV Error. SLI Level %d "
5592 "FCoE enabled %d\n",
5593 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
5599 * Evaluate the read rev and vpd data. Populate the driver
5600 * state with the results. If this routine fails, the failure
5601 * is not fatal as the driver will use generic values.
5603 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
5604 if (unlikely(!rc)) {
5605 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5606 "0377 Error %d parsing vpd. "
5607 "Using defaults.\n", rc);
5612 /* Save information as VPD data */
5613 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
5614 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
5615 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
5616 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
5618 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
5620 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
5622 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
5624 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
5625 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
5626 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
5627 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
5628 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
5629 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
5630 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5631 "(%d):0380 READ_REV Status x%x "
5632 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
5633 mboxq->vport ? mboxq->vport->vpi : 0,
5634 bf_get(lpfc_mqe_status, mqe),
5635 phba->vpd.rev.opFwName,
5636 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
5637 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
5640 * Discover the port's supported feature set and match it against the
5643 lpfc_request_features(phba, mboxq);
5644 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5651 * The port must support FCP initiator mode as this is the
5652 * only mode running in the host.
5654 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
5655 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
5656 "0378 No support for fcpi mode.\n");
5659 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
5660 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
5662 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
5664 * If the port cannot support the host's requested features
5665 * then turn off the global config parameters to disable the
5666 * feature in the driver. This is not a fatal error.
5668 if ((phba->cfg_enable_bg) &&
5669 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
5672 if (phba->max_vpi && phba->cfg_enable_npiv &&
5673 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
5677 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
5678 "0379 Feature Mismatch Data: x%08x %08x "
5679 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
5680 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
5681 phba->cfg_enable_npiv, phba->max_vpi);
5682 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
5683 phba->cfg_enable_bg = 0;
5684 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
5685 phba->cfg_enable_npiv = 0;
5688 /* These SLI3 features are assumed in SLI4 */
5689 spin_lock_irq(&phba->hbalock);
5690 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
5691 spin_unlock_irq(&phba->hbalock);
5694 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
5695 * calls depends on these resources to complete port setup.
5697 rc = lpfc_sli4_alloc_resource_identifiers(phba);
5699 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5700 "2920 Failed to alloc Resource IDs "
5705 /* Read the port's service parameters. */
5706 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
5708 phba->link_state = LPFC_HBA_ERROR;
5713 mboxq->vport = vport;
5714 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5715 mp = (struct lpfc_dmabuf *) mboxq->context1;
5716 if (rc == MBX_SUCCESS) {
5717 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
5722 * This memory was allocated by the lpfc_read_sparam routine. Release
5723 * it to the mbuf pool.
5725 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5727 mboxq->context1 = NULL;
5729 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5730 "0382 READ_SPARAM command failed "
5731 "status %d, mbxStatus x%x\n",
5732 rc, bf_get(lpfc_mqe_status, mqe));
5733 phba->link_state = LPFC_HBA_ERROR;
5738 lpfc_update_vport_wwn(vport);
5740 /* Update the fc_host data structures with new wwn. */
5741 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
5742 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
5744 /* Register SGL pool to the device using non-embedded mailbox command */
5745 if (!phba->sli4_hba.extents_in_use) {
5746 rc = lpfc_sli4_post_els_sgl_list(phba);
5748 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5749 "0582 Error %d during els sgl post "
5755 rc = lpfc_sli4_post_els_sgl_list_ext(phba);
5757 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5758 "2560 Error %d during els sgl post "
5765 /* Register SCSI SGL pool to the device */
5766 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
5768 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5769 "0383 Error %d during scsi sgl post "
5771 /* Some Scsi buffers were moved to the abort scsi list */
5772 /* A pci function reset will repost them */
5777 /* Post the rpi header region to the device. */
5778 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
5780 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5781 "0393 Error %d during rpi post operation\n",
5787 /* Set up all the queues to the device */
5788 rc = lpfc_sli4_queue_setup(phba);
5790 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5791 "0381 Error %d during queue setup.\n ", rc);
5792 goto out_stop_timers;
5795 /* Arm the CQs and then EQs on device */
5796 lpfc_sli4_arm_cqeq_intr(phba);
5798 /* Indicate device interrupt mode */
5799 phba->sli4_hba.intr_enable = 1;
5801 /* Allow asynchronous mailbox command to go through */
5802 spin_lock_irq(&phba->hbalock);
5803 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5804 spin_unlock_irq(&phba->hbalock);
5806 /* Post receive buffers to the device */
5807 lpfc_sli4_rb_setup(phba);
5809 /* Reset HBA FCF states after HBA reset */
5810 phba->fcf.fcf_flag = 0;
5811 phba->fcf.current_rec.flag = 0;
5813 /* Start the ELS watchdog timer */
5814 mod_timer(&vport->els_tmofunc,
5815 jiffies + HZ * (phba->fc_ratov * 2));
5817 /* Start heart beat timer */
5818 mod_timer(&phba->hb_tmofunc,
5819 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
5820 phba->hb_outstanding = 0;
5821 phba->last_completion_time = jiffies;
5823 /* Start error attention (ERATT) polling timer */
5824 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
5826 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5827 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
5828 rc = pci_enable_pcie_error_reporting(phba->pcidev);
5830 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5831 "2829 This device supports "
5832 "Advanced Error Reporting (AER)\n");
5833 spin_lock_irq(&phba->hbalock);
5834 phba->hba_flag |= HBA_AER_ENABLED;
5835 spin_unlock_irq(&phba->hbalock);
5837 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5838 "2830 This device does not support "
5839 "Advanced Error Reporting (AER)\n");
5840 phba->cfg_aer_support = 0;
5845 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5847 * The FC Port needs to register FCFI (index 0)
5849 lpfc_reg_fcfi(phba, mboxq);
5850 mboxq->vport = phba->pport;
5851 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5852 if (rc != MBX_SUCCESS)
5853 goto out_unset_queue;
5855 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
5856 &mboxq->u.mqe.un.reg_fcfi);
5859 * The port is ready, set the host's link state to LINK_DOWN
5860 * in preparation for link interrupts.
5862 spin_lock_irq(&phba->hbalock);
5863 phba->link_state = LPFC_LINK_DOWN;
5864 spin_unlock_irq(&phba->hbalock);
5865 if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
5866 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
5868 /* Unset all the queues set up in this routine when error out */
5870 lpfc_sli4_queue_unset(phba);
5873 lpfc_stop_hba_timers(phba);
5875 mempool_free(mboxq, phba->mbox_mem_pool);
5880 * lpfc_mbox_timeout - Timeout call back function for mbox timer
5881 * @ptr: context object - pointer to hba structure.
5883 * This is the callback function for mailbox timer. The mailbox
5884 * timer is armed when a new mailbox command is issued and the timer
5885 * is deleted when the mailbox complete. The function is called by
5886 * the kernel timer code when a mailbox does not complete within
5887 * expected time. This function wakes up the worker thread to
5888 * process the mailbox timeout and returns. All the processing is
5889 * done by the worker thread function lpfc_mbox_timeout_handler.
5892 lpfc_mbox_timeout(unsigned long ptr)
5894 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
5895 unsigned long iflag;
5896 uint32_t tmo_posted;
5898 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
5899 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
5901 phba->pport->work_port_events |= WORKER_MBOX_TMO;
5902 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
5905 lpfc_worker_wake_up(phba);
5911 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
5912 * @phba: Pointer to HBA context object.
5914 * This function is called from worker thread when a mailbox command times out.
5915 * The caller is not required to hold any locks. This function will reset the
5916 * HBA and recover all the pending commands.
5919 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
5921 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
5922 MAILBOX_t *mb = &pmbox->u.mb;
5923 struct lpfc_sli *psli = &phba->sli;
5924 struct lpfc_sli_ring *pring;
5926 /* Check the pmbox pointer first. There is a race condition
5927 * between the mbox timeout handler getting executed in the
5928 * worklist and the mailbox actually completing. When this
5929 * race condition occurs, the mbox_active will be NULL.
5931 spin_lock_irq(&phba->hbalock);
5932 if (pmbox == NULL) {
5933 lpfc_printf_log(phba, KERN_WARNING,
5935 "0353 Active Mailbox cleared - mailbox timeout "
5937 spin_unlock_irq(&phba->hbalock);
5941 /* Mbox cmd <mbxCommand> timeout */
5942 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5943 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
5945 phba->pport->port_state,
5947 phba->sli.mbox_active);
5948 spin_unlock_irq(&phba->hbalock);
5950 /* Setting state unknown so lpfc_sli_abort_iocb_ring
5951 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
5952 * it to fail all outstanding SCSI IO.
5954 spin_lock_irq(&phba->pport->work_port_lock);
5955 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
5956 spin_unlock_irq(&phba->pport->work_port_lock);
5957 spin_lock_irq(&phba->hbalock);
5958 phba->link_state = LPFC_LINK_UNKNOWN;
5959 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
5960 spin_unlock_irq(&phba->hbalock);
5962 pring = &psli->ring[psli->fcp_ring];
5963 lpfc_sli_abort_iocb_ring(phba, pring);
5965 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5966 "0345 Resetting board due to mailbox timeout\n");
5968 /* Reset the HBA device */
5969 lpfc_reset_hba(phba);
5973 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
5974 * @phba: Pointer to HBA context object.
5975 * @pmbox: Pointer to mailbox object.
5976 * @flag: Flag indicating how the mailbox need to be processed.
5978 * This function is called by discovery code and HBA management code
5979 * to submit a mailbox command to firmware with SLI-3 interface spec. This
5980 * function gets the hbalock to protect the data structures.
5981 * The mailbox command can be submitted in polling mode, in which case
5982 * this function will wait in a polling loop for the completion of the
5984 * If the mailbox is submitted in no_wait mode (not polling) the
5985 * function will submit the command and returns immediately without waiting
5986 * for the mailbox completion. The no_wait is supported only when HBA
5987 * is in SLI2/SLI3 mode - interrupts are enabled.
5988 * The SLI interface allows only one mailbox pending at a time. If the
5989 * mailbox is issued in polling mode and there is already a mailbox
5990 * pending, then the function will return an error. If the mailbox is issued
5991 * in NO_WAIT mode and there is a mailbox pending already, the function
5992 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
5993 * The sli layer owns the mailbox object until the completion of mailbox
5994 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
5995 * return codes the caller owns the mailbox command after the return of
5999 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
6003 struct lpfc_sli *psli = &phba->sli;
6004 uint32_t status, evtctr;
6005 uint32_t ha_copy, hc_copy;
6007 unsigned long timeout;
6008 unsigned long drvr_flag = 0;
6009 uint32_t word0, ldata;
6010 void __iomem *to_slim;
6011 int processing_queue = 0;
6013 spin_lock_irqsave(&phba->hbalock, drvr_flag);
6015 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6016 /* processing mbox queue from intr_handler */
6017 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
6018 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6021 processing_queue = 1;
6022 pmbox = lpfc_mbox_get(phba);
6024 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6029 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
6030 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
6032 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6033 lpfc_printf_log(phba, KERN_ERR,
6034 LOG_MBOX | LOG_VPORT,
6035 "1806 Mbox x%x failed. No vport\n",
6036 pmbox->u.mb.mbxCommand);
6038 goto out_not_finished;
6042 /* If the PCI channel is in offline state, do not post mbox. */
6043 if (unlikely(pci_channel_offline(phba->pcidev))) {
6044 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6045 goto out_not_finished;
6048 /* If HBA has a deferred error attention, fail the iocb. */
6049 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
6050 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6051 goto out_not_finished;
6057 status = MBX_SUCCESS;
6059 if (phba->link_state == LPFC_HBA_ERROR) {
6060 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6062 /* Mbox command <mbxCommand> cannot issue */
6063 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6064 "(%d):0311 Mailbox command x%x cannot "
6065 "issue Data: x%x x%x\n",
6066 pmbox->vport ? pmbox->vport->vpi : 0,
6067 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
6068 goto out_not_finished;
6071 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
6072 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
6073 !(hc_copy & HC_MBINT_ENA)) {
6074 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6075 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6076 "(%d):2528 Mailbox command x%x cannot "
6077 "issue Data: x%x x%x\n",
6078 pmbox->vport ? pmbox->vport->vpi : 0,
6079 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
6080 goto out_not_finished;
6084 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6085 /* Polling for a mbox command when another one is already active
6086 * is not allowed in SLI. Also, the driver must have established
6087 * SLI2 mode to queue and process multiple mbox commands.
6090 if (flag & MBX_POLL) {
6091 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6093 /* Mbox command <mbxCommand> cannot issue */
6094 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6095 "(%d):2529 Mailbox command x%x "
6096 "cannot issue Data: x%x x%x\n",
6097 pmbox->vport ? pmbox->vport->vpi : 0,
6098 pmbox->u.mb.mbxCommand,
6099 psli->sli_flag, flag);
6100 goto out_not_finished;
6103 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
6104 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6105 /* Mbox command <mbxCommand> cannot issue */
6106 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6107 "(%d):2530 Mailbox command x%x "
6108 "cannot issue Data: x%x x%x\n",
6109 pmbox->vport ? pmbox->vport->vpi : 0,
6110 pmbox->u.mb.mbxCommand,
6111 psli->sli_flag, flag);
6112 goto out_not_finished;
6115 /* Another mailbox command is still being processed, queue this
6116 * command to be processed later.
6118 lpfc_mbox_put(phba, pmbox);
6120 /* Mbox cmd issue - BUSY */
6121 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6122 "(%d):0308 Mbox cmd issue - BUSY Data: "
6123 "x%x x%x x%x x%x\n",
6124 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
6125 mb->mbxCommand, phba->pport->port_state,
6126 psli->sli_flag, flag);
6128 psli->slistat.mbox_busy++;
6129 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6132 lpfc_debugfs_disc_trc(pmbox->vport,
6133 LPFC_DISC_TRC_MBOX_VPORT,
6134 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6135 (uint32_t)mb->mbxCommand,
6136 mb->un.varWords[0], mb->un.varWords[1]);
6139 lpfc_debugfs_disc_trc(phba->pport,
6141 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6142 (uint32_t)mb->mbxCommand,
6143 mb->un.varWords[0], mb->un.varWords[1]);
6149 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
6151 /* If we are not polling, we MUST be in SLI2 mode */
6152 if (flag != MBX_POLL) {
6153 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
6154 (mb->mbxCommand != MBX_KILL_BOARD)) {
6155 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6156 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6157 /* Mbox command <mbxCommand> cannot issue */
6158 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6159 "(%d):2531 Mailbox command x%x "
6160 "cannot issue Data: x%x x%x\n",
6161 pmbox->vport ? pmbox->vport->vpi : 0,
6162 pmbox->u.mb.mbxCommand,
6163 psli->sli_flag, flag);
6164 goto out_not_finished;
6166 /* timeout active mbox command */
6167 mod_timer(&psli->mbox_tmo, (jiffies +
6168 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
6171 /* Mailbox cmd <cmd> issue */
6172 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6173 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6175 pmbox->vport ? pmbox->vport->vpi : 0,
6176 mb->mbxCommand, phba->pport->port_state,
6177 psli->sli_flag, flag);
6179 if (mb->mbxCommand != MBX_HEARTBEAT) {
6181 lpfc_debugfs_disc_trc(pmbox->vport,
6182 LPFC_DISC_TRC_MBOX_VPORT,
6183 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6184 (uint32_t)mb->mbxCommand,
6185 mb->un.varWords[0], mb->un.varWords[1]);
6188 lpfc_debugfs_disc_trc(phba->pport,
6190 "MBOX Send: cmd:x%x mb:x%x x%x",
6191 (uint32_t)mb->mbxCommand,
6192 mb->un.varWords[0], mb->un.varWords[1]);
6196 psli->slistat.mbox_cmd++;
6197 evtctr = psli->slistat.mbox_event;
6199 /* next set own bit for the adapter and copy over command word */
6200 mb->mbxOwner = OWN_CHIP;
6202 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6203 /* Populate mbox extension offset word. */
6204 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
6205 *(((uint32_t *)mb) + pmbox->mbox_offset_word)
6206 = (uint8_t *)phba->mbox_ext
6207 - (uint8_t *)phba->mbox;
6210 /* Copy the mailbox extension data */
6211 if (pmbox->in_ext_byte_len && pmbox->context2) {
6212 lpfc_sli_pcimem_bcopy(pmbox->context2,
6213 (uint8_t *)phba->mbox_ext,
6214 pmbox->in_ext_byte_len);
6216 /* Copy command data to host SLIM area */
6217 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
6219 /* Populate mbox extension offset word. */
6220 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
6221 *(((uint32_t *)mb) + pmbox->mbox_offset_word)
6222 = MAILBOX_HBA_EXT_OFFSET;
6224 /* Copy the mailbox extension data */
6225 if (pmbox->in_ext_byte_len && pmbox->context2) {
6226 lpfc_memcpy_to_slim(phba->MBslimaddr +
6227 MAILBOX_HBA_EXT_OFFSET,
6228 pmbox->context2, pmbox->in_ext_byte_len);
6231 if (mb->mbxCommand == MBX_CONFIG_PORT) {
6232 /* copy command data into host mbox for cmpl */
6233 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
6236 /* First copy mbox command data to HBA SLIM, skip past first
6238 to_slim = phba->MBslimaddr + sizeof (uint32_t);
6239 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
6240 MAILBOX_CMD_SIZE - sizeof (uint32_t));
6242 /* Next copy over first word, with mbxOwner set */
6243 ldata = *((uint32_t *)mb);
6244 to_slim = phba->MBslimaddr;
6245 writel(ldata, to_slim);
6246 readl(to_slim); /* flush */
6248 if (mb->mbxCommand == MBX_CONFIG_PORT) {
6249 /* switch over to host mailbox */
6250 psli->sli_flag |= LPFC_SLI_ACTIVE;
6258 /* Set up reference to mailbox command */
6259 psli->mbox_active = pmbox;
6260 /* Interrupt board to do it */
6261 writel(CA_MBATT, phba->CAregaddr);
6262 readl(phba->CAregaddr); /* flush */
6263 /* Don't wait for it to finish, just return */
6267 /* Set up null reference to mailbox command */
6268 psli->mbox_active = NULL;
6269 /* Interrupt board to do it */
6270 writel(CA_MBATT, phba->CAregaddr);
6271 readl(phba->CAregaddr); /* flush */
6273 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6274 /* First read mbox status word */
6275 word0 = *((uint32_t *)phba->mbox);
6276 word0 = le32_to_cpu(word0);
6278 /* First read mbox status word */
6279 if (lpfc_readl(phba->MBslimaddr, &word0)) {
6280 spin_unlock_irqrestore(&phba->hbalock,
6282 goto out_not_finished;
6286 /* Read the HBA Host Attention Register */
6287 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
6288 spin_unlock_irqrestore(&phba->hbalock,
6290 goto out_not_finished;
6292 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
6296 /* Wait for command to complete */
6297 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
6298 (!(ha_copy & HA_MBATT) &&
6299 (phba->link_state > LPFC_WARM_START))) {
6300 if (time_after(jiffies, timeout)) {
6301 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6302 spin_unlock_irqrestore(&phba->hbalock,
6304 goto out_not_finished;
6307 /* Check if we took a mbox interrupt while we were
6309 if (((word0 & OWN_CHIP) != OWN_CHIP)
6310 && (evtctr != psli->slistat.mbox_event))
6314 spin_unlock_irqrestore(&phba->hbalock,
6317 spin_lock_irqsave(&phba->hbalock, drvr_flag);
6320 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6321 /* First copy command data */
6322 word0 = *((uint32_t *)phba->mbox);
6323 word0 = le32_to_cpu(word0);
6324 if (mb->mbxCommand == MBX_CONFIG_PORT) {
6327 /* Check real SLIM for any errors */
6328 slimword0 = readl(phba->MBslimaddr);
6329 slimmb = (MAILBOX_t *) & slimword0;
6330 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
6331 && slimmb->mbxStatus) {
6338 /* First copy command data */
6339 word0 = readl(phba->MBslimaddr);
6341 /* Read the HBA Host Attention Register */
6342 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
6343 spin_unlock_irqrestore(&phba->hbalock,
6345 goto out_not_finished;
6349 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6350 /* copy results back to user */
6351 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
6352 /* Copy the mailbox extension data */
6353 if (pmbox->out_ext_byte_len && pmbox->context2) {
6354 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
6356 pmbox->out_ext_byte_len);
6359 /* First copy command data */
6360 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
6362 /* Copy the mailbox extension data */
6363 if (pmbox->out_ext_byte_len && pmbox->context2) {
6364 lpfc_memcpy_from_slim(pmbox->context2,
6366 MAILBOX_HBA_EXT_OFFSET,
6367 pmbox->out_ext_byte_len);
6371 writel(HA_MBATT, phba->HAregaddr);
6372 readl(phba->HAregaddr); /* flush */
6374 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6375 status = mb->mbxStatus;
6378 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6382 if (processing_queue) {
6383 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
6384 lpfc_mbox_cmpl_put(phba, pmbox);
6386 return MBX_NOT_FINISHED;
6390 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6391 * @phba: Pointer to HBA context object.
6393 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6394 * the driver internal pending mailbox queue. It will then try to wait out the
6395 * possible outstanding mailbox command before return.
6398 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6399 * the outstanding mailbox command timed out.
6402 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
6404 struct lpfc_sli *psli = &phba->sli;
6405 uint8_t actcmd = MBX_HEARTBEAT;
6407 unsigned long timeout;
6409 /* Mark the asynchronous mailbox command posting as blocked */
6410 spin_lock_irq(&phba->hbalock);
6411 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
6412 if (phba->sli.mbox_active)
6413 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
6414 spin_unlock_irq(&phba->hbalock);
6415 /* Determine how long we might wait for the active mailbox
6416 * command to be gracefully completed by firmware.
6418 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
6420 /* Wait for the outstnading mailbox command to complete */
6421 while (phba->sli.mbox_active) {
6422 /* Check active mailbox complete status every 2ms */
6424 if (time_after(jiffies, timeout)) {
6425 /* Timeout, marked the outstanding cmd not complete */
6431 /* Can not cleanly block async mailbox command, fails it */
6433 spin_lock_irq(&phba->hbalock);
6434 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
6435 spin_unlock_irq(&phba->hbalock);
6441 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
6442 * @phba: Pointer to HBA context object.
6444 * The function unblocks and resume posting of SLI4 asynchronous mailbox
6445 * commands from the driver internal pending mailbox queue. It makes sure
6446 * that there is no outstanding mailbox command before resuming posting
6447 * asynchronous mailbox commands. If, for any reason, there is outstanding
6448 * mailbox command, it will try to wait it out before resuming asynchronous
6449 * mailbox command posting.
6452 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
6454 struct lpfc_sli *psli = &phba->sli;
6456 spin_lock_irq(&phba->hbalock);
6457 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
6458 /* Asynchronous mailbox posting is not blocked, do nothing */
6459 spin_unlock_irq(&phba->hbalock);
6463 /* Outstanding synchronous mailbox command is guaranteed to be done,
6464 * successful or timeout, after timing-out the outstanding mailbox
6465 * command shall always be removed, so just unblock posting async
6466 * mailbox command and resume
6468 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
6469 spin_unlock_irq(&phba->hbalock);
6471 /* wake up worker thread to post asynchronlous mailbox command */
6472 lpfc_worker_wake_up(phba);
6476 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
6477 * @phba: Pointer to HBA context object.
6478 * @mboxq: Pointer to mailbox object.
6480 * The function posts a mailbox to the port. The mailbox is expected
6481 * to be comletely filled in and ready for the port to operate on it.
6482 * This routine executes a synchronous completion operation on the
6483 * mailbox by polling for its completion.
6485 * The caller must not be holding any locks when calling this routine.
6488 * MBX_SUCCESS - mailbox posted successfully
6489 * Any of the MBX error values.
6492 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6494 int rc = MBX_SUCCESS;
6495 unsigned long iflag;
6497 uint32_t mcqe_status;
6499 unsigned long timeout;
6500 struct lpfc_sli *psli = &phba->sli;
6501 struct lpfc_mqe *mb = &mboxq->u.mqe;
6502 struct lpfc_bmbx_create *mbox_rgn;
6503 struct dma_address *dma_address;
6504 struct lpfc_register bmbx_reg;
6507 * Only one mailbox can be active to the bootstrap mailbox region
6508 * at a time and there is no queueing provided.
6510 spin_lock_irqsave(&phba->hbalock, iflag);
6511 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6512 spin_unlock_irqrestore(&phba->hbalock, iflag);
6513 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6514 "(%d):2532 Mailbox command x%x (x%x) "
6515 "cannot issue Data: x%x x%x\n",
6516 mboxq->vport ? mboxq->vport->vpi : 0,
6517 mboxq->u.mb.mbxCommand,
6518 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6519 psli->sli_flag, MBX_POLL);
6520 return MBXERR_ERROR;
6522 /* The server grabs the token and owns it until release */
6523 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
6524 phba->sli.mbox_active = mboxq;
6525 spin_unlock_irqrestore(&phba->hbalock, iflag);
6528 * Initialize the bootstrap memory region to avoid stale data areas
6529 * in the mailbox post. Then copy the caller's mailbox contents to
6530 * the bmbx mailbox region.
6532 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
6533 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
6534 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
6535 sizeof(struct lpfc_mqe));
6537 /* Post the high mailbox dma address to the port and wait for ready. */
6538 dma_address = &phba->sli4_hba.bmbx.dma_address;
6539 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
6541 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
6544 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
6545 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
6549 if (time_after(jiffies, timeout)) {
6553 } while (!db_ready);
6555 /* Post the low mailbox dma address to the port. */
6556 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
6557 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
6560 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
6561 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
6565 if (time_after(jiffies, timeout)) {
6569 } while (!db_ready);
6572 * Read the CQ to ensure the mailbox has completed.
6573 * If so, update the mailbox status so that the upper layers
6574 * can complete the request normally.
6576 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
6577 sizeof(struct lpfc_mqe));
6578 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
6579 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
6580 sizeof(struct lpfc_mcqe));
6581 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
6583 * When the CQE status indicates a failure and the mailbox status
6584 * indicates success then copy the CQE status into the mailbox status
6585 * (and prefix it with x4000).
6587 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
6588 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
6589 bf_set(lpfc_mqe_status, mb,
6590 (LPFC_MBX_ERROR_RANGE | mcqe_status));
6593 lpfc_sli4_swap_str(phba, mboxq);
6595 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6596 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
6597 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
6598 " x%x x%x CQ: x%x x%x x%x x%x\n",
6599 mboxq->vport ? mboxq->vport->vpi : 0,
6600 mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
6601 bf_get(lpfc_mqe_status, mb),
6602 mb->un.mb_words[0], mb->un.mb_words[1],
6603 mb->un.mb_words[2], mb->un.mb_words[3],
6604 mb->un.mb_words[4], mb->un.mb_words[5],
6605 mb->un.mb_words[6], mb->un.mb_words[7],
6606 mb->un.mb_words[8], mb->un.mb_words[9],
6607 mb->un.mb_words[10], mb->un.mb_words[11],
6608 mb->un.mb_words[12], mboxq->mcqe.word0,
6609 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
6610 mboxq->mcqe.trailer);
6612 /* We are holding the token, no needed for lock when release */
6613 spin_lock_irqsave(&phba->hbalock, iflag);
6614 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6615 phba->sli.mbox_active = NULL;
6616 spin_unlock_irqrestore(&phba->hbalock, iflag);
6621 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
6622 * @phba: Pointer to HBA context object.
6623 * @pmbox: Pointer to mailbox object.
6624 * @flag: Flag indicating how the mailbox need to be processed.
6626 * This function is called by discovery code and HBA management code to submit
6627 * a mailbox command to firmware with SLI-4 interface spec.
6629 * Return codes the caller owns the mailbox command after the return of the
6633 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
6636 struct lpfc_sli *psli = &phba->sli;
6637 unsigned long iflags;
6640 rc = lpfc_mbox_dev_check(phba);
6642 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6643 "(%d):2544 Mailbox command x%x (x%x) "
6644 "cannot issue Data: x%x x%x\n",
6645 mboxq->vport ? mboxq->vport->vpi : 0,
6646 mboxq->u.mb.mbxCommand,
6647 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6648 psli->sli_flag, flag);
6649 goto out_not_finished;
6652 /* Detect polling mode and jump to a handler */
6653 if (!phba->sli4_hba.intr_enable) {
6654 if (flag == MBX_POLL)
6655 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
6658 if (rc != MBX_SUCCESS)
6659 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6660 "(%d):2541 Mailbox command x%x "
6661 "(x%x) cannot issue Data: x%x x%x\n",
6662 mboxq->vport ? mboxq->vport->vpi : 0,
6663 mboxq->u.mb.mbxCommand,
6664 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6665 psli->sli_flag, flag);
6667 } else if (flag == MBX_POLL) {
6668 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6669 "(%d):2542 Try to issue mailbox command "
6670 "x%x (x%x) synchronously ahead of async"
6671 "mailbox command queue: x%x x%x\n",
6672 mboxq->vport ? mboxq->vport->vpi : 0,
6673 mboxq->u.mb.mbxCommand,
6674 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6675 psli->sli_flag, flag);
6676 /* Try to block the asynchronous mailbox posting */
6677 rc = lpfc_sli4_async_mbox_block(phba);
6679 /* Successfully blocked, now issue sync mbox cmd */
6680 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
6681 if (rc != MBX_SUCCESS)
6682 lpfc_printf_log(phba, KERN_ERR,
6684 "(%d):2597 Mailbox command "
6685 "x%x (x%x) cannot issue "
6688 mboxq->vport->vpi : 0,
6689 mboxq->u.mb.mbxCommand,
6690 lpfc_sli4_mbox_opcode_get(phba,
6692 psli->sli_flag, flag);
6693 /* Unblock the async mailbox posting afterward */
6694 lpfc_sli4_async_mbox_unblock(phba);
6699 /* Now, interrupt mode asynchrous mailbox command */
6700 rc = lpfc_mbox_cmd_check(phba, mboxq);
6702 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6703 "(%d):2543 Mailbox command x%x (x%x) "
6704 "cannot issue Data: x%x x%x\n",
6705 mboxq->vport ? mboxq->vport->vpi : 0,
6706 mboxq->u.mb.mbxCommand,
6707 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6708 psli->sli_flag, flag);
6709 goto out_not_finished;
6712 /* Put the mailbox command to the driver internal FIFO */
6713 psli->slistat.mbox_busy++;
6714 spin_lock_irqsave(&phba->hbalock, iflags);
6715 lpfc_mbox_put(phba, mboxq);
6716 spin_unlock_irqrestore(&phba->hbalock, iflags);
6717 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6718 "(%d):0354 Mbox cmd issue - Enqueue Data: "
6719 "x%x (x%x) x%x x%x x%x\n",
6720 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
6721 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6722 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6723 phba->pport->port_state,
6724 psli->sli_flag, MBX_NOWAIT);
6725 /* Wake up worker thread to transport mailbox command from head */
6726 lpfc_worker_wake_up(phba);
6731 return MBX_NOT_FINISHED;
6735 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
6736 * @phba: Pointer to HBA context object.
6738 * This function is called by worker thread to send a mailbox command to
6739 * SLI4 HBA firmware.
6743 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
6745 struct lpfc_sli *psli = &phba->sli;
6746 LPFC_MBOXQ_t *mboxq;
6747 int rc = MBX_SUCCESS;
6748 unsigned long iflags;
6749 struct lpfc_mqe *mqe;
6752 /* Check interrupt mode before post async mailbox command */
6753 if (unlikely(!phba->sli4_hba.intr_enable))
6754 return MBX_NOT_FINISHED;
6756 /* Check for mailbox command service token */
6757 spin_lock_irqsave(&phba->hbalock, iflags);
6758 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
6759 spin_unlock_irqrestore(&phba->hbalock, iflags);
6760 return MBX_NOT_FINISHED;
6762 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6763 spin_unlock_irqrestore(&phba->hbalock, iflags);
6764 return MBX_NOT_FINISHED;
6766 if (unlikely(phba->sli.mbox_active)) {
6767 spin_unlock_irqrestore(&phba->hbalock, iflags);
6768 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6769 "0384 There is pending active mailbox cmd\n");
6770 return MBX_NOT_FINISHED;
6772 /* Take the mailbox command service token */
6773 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
6775 /* Get the next mailbox command from head of queue */
6776 mboxq = lpfc_mbox_get(phba);
6778 /* If no more mailbox command waiting for post, we're done */
6780 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6781 spin_unlock_irqrestore(&phba->hbalock, iflags);
6784 phba->sli.mbox_active = mboxq;
6785 spin_unlock_irqrestore(&phba->hbalock, iflags);
6787 /* Check device readiness for posting mailbox command */
6788 rc = lpfc_mbox_dev_check(phba);
6790 /* Driver clean routine will clean up pending mailbox */
6791 goto out_not_finished;
6793 /* Prepare the mbox command to be posted */
6794 mqe = &mboxq->u.mqe;
6795 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
6797 /* Start timer for the mbox_tmo and log some mailbox post messages */
6798 mod_timer(&psli->mbox_tmo, (jiffies +
6799 (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
6801 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6802 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
6804 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
6805 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6806 phba->pport->port_state, psli->sli_flag);
6808 if (mbx_cmnd != MBX_HEARTBEAT) {
6810 lpfc_debugfs_disc_trc(mboxq->vport,
6811 LPFC_DISC_TRC_MBOX_VPORT,
6812 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6813 mbx_cmnd, mqe->un.mb_words[0],
6814 mqe->un.mb_words[1]);
6816 lpfc_debugfs_disc_trc(phba->pport,
6818 "MBOX Send: cmd:x%x mb:x%x x%x",
6819 mbx_cmnd, mqe->un.mb_words[0],
6820 mqe->un.mb_words[1]);
6823 psli->slistat.mbox_cmd++;
6825 /* Post the mailbox command to the port */
6826 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
6827 if (rc != MBX_SUCCESS) {
6828 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6829 "(%d):2533 Mailbox command x%x (x%x) "
6830 "cannot issue Data: x%x x%x\n",
6831 mboxq->vport ? mboxq->vport->vpi : 0,
6832 mboxq->u.mb.mbxCommand,
6833 lpfc_sli4_mbox_opcode_get(phba, mboxq),
6834 psli->sli_flag, MBX_NOWAIT);
6835 goto out_not_finished;
6841 spin_lock_irqsave(&phba->hbalock, iflags);
6842 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
6843 __lpfc_mbox_cmpl_put(phba, mboxq);
6844 /* Release the token */
6845 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6846 phba->sli.mbox_active = NULL;
6847 spin_unlock_irqrestore(&phba->hbalock, iflags);
6849 return MBX_NOT_FINISHED;
6853 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
6854 * @phba: Pointer to HBA context object.
6855 * @pmbox: Pointer to mailbox object.
6856 * @flag: Flag indicating how the mailbox need to be processed.
6858 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
6859 * the API jump table function pointer from the lpfc_hba struct.
6861 * Return codes the caller owns the mailbox command after the return of the
6865 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
6867 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
6871 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
6872 * @phba: The hba struct for which this call is being executed.
6873 * @dev_grp: The HBA PCI-Device group number.
6875 * This routine sets up the mbox interface API function jump table in @phba
6877 * Returns: 0 - success, -ENODEV - failure.
6880 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6884 case LPFC_PCI_DEV_LP:
6885 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
6886 phba->lpfc_sli_handle_slow_ring_event =
6887 lpfc_sli_handle_slow_ring_event_s3;
6888 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
6889 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
6890 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
6892 case LPFC_PCI_DEV_OC:
6893 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
6894 phba->lpfc_sli_handle_slow_ring_event =
6895 lpfc_sli_handle_slow_ring_event_s4;
6896 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
6897 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
6898 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
6901 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6902 "1420 Invalid HBA PCI-device group: 0x%x\n",
6911 * __lpfc_sli_ringtx_put - Add an iocb to the txq
6912 * @phba: Pointer to HBA context object.
6913 * @pring: Pointer to driver SLI ring object.
6914 * @piocb: Pointer to address of newly added command iocb.
6916 * This function is called with hbalock held to add a command
6917 * iocb to the txq when SLI layer cannot submit the command iocb
6921 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6922 struct lpfc_iocbq *piocb)
6924 /* Insert the caller's iocb in the txq tail for later processing. */
6925 list_add_tail(&piocb->list, &pring->txq);
6930 * lpfc_sli_next_iocb - Get the next iocb in the txq
6931 * @phba: Pointer to HBA context object.
6932 * @pring: Pointer to driver SLI ring object.
6933 * @piocb: Pointer to address of newly added command iocb.
6935 * This function is called with hbalock held before a new
6936 * iocb is submitted to the firmware. This function checks
6937 * txq to flush the iocbs in txq to Firmware before
6938 * submitting new iocbs to the Firmware.
6939 * If there are iocbs in the txq which need to be submitted
6940 * to firmware, lpfc_sli_next_iocb returns the first element
6941 * of the txq after dequeuing it from txq.
6942 * If there is no iocb in the txq then the function will return
6943 * *piocb and *piocb is set to NULL. Caller needs to check
6944 * *piocb to find if there are more commands in the txq.
6946 static struct lpfc_iocbq *
6947 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6948 struct lpfc_iocbq **piocb)
6950 struct lpfc_iocbq * nextiocb;
6952 nextiocb = lpfc_sli_ringtx_get(phba, pring);
6962 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
6963 * @phba: Pointer to HBA context object.
6964 * @ring_number: SLI ring number to issue iocb on.
6965 * @piocb: Pointer to command iocb.
6966 * @flag: Flag indicating if this command can be put into txq.
6968 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
6969 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
6970 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
6971 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
6972 * this function allows only iocbs for posting buffers. This function finds
6973 * next available slot in the command ring and posts the command to the
6974 * available slot and writes the port attention register to request HBA start
6975 * processing new iocb. If there is no slot available in the ring and
6976 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
6977 * the function returns IOCB_BUSY.
6979 * This function is called with hbalock held. The function will return success
6980 * after it successfully submit the iocb to firmware or after adding to the
6984 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
6985 struct lpfc_iocbq *piocb, uint32_t flag)
6987 struct lpfc_iocbq *nextiocb;
6989 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
6991 if (piocb->iocb_cmpl && (!piocb->vport) &&
6992 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
6993 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
6994 lpfc_printf_log(phba, KERN_ERR,
6995 LOG_SLI | LOG_VPORT,
6996 "1807 IOCB x%x failed. No vport\n",
6997 piocb->iocb.ulpCommand);
7003 /* If the PCI channel is in offline state, do not post iocbs. */
7004 if (unlikely(pci_channel_offline(phba->pcidev)))
7007 /* If HBA has a deferred error attention, fail the iocb. */
7008 if (unlikely(phba->hba_flag & DEFER_ERATT))
7012 * We should never get an IOCB if we are in a < LINK_DOWN state
7014 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
7018 * Check to see if we are blocking IOCB processing because of a
7019 * outstanding event.
7021 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
7024 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
7026 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7027 * can be issued if the link is not up.
7029 switch (piocb->iocb.ulpCommand) {
7030 case CMD_GEN_REQUEST64_CR:
7031 case CMD_GEN_REQUEST64_CX:
7032 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
7033 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
7034 FC_RCTL_DD_UNSOL_CMD) ||
7035 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
7036 MENLO_TRANSPORT_TYPE))
7040 case CMD_QUE_RING_BUF_CN:
7041 case CMD_QUE_RING_BUF64_CN:
7043 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7044 * completion, iocb_cmpl MUST be 0.
7046 if (piocb->iocb_cmpl)
7047 piocb->iocb_cmpl = NULL;
7049 case CMD_CREATE_XRI_CR:
7050 case CMD_CLOSE_XRI_CN:
7051 case CMD_CLOSE_XRI_CX:
7058 * For FCP commands, we must be in a state where we can process link
7061 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
7062 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
7066 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
7067 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
7068 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
7071 lpfc_sli_update_ring(phba, pring);
7073 lpfc_sli_update_full_ring(phba, pring);
7076 return IOCB_SUCCESS;
7081 pring->stats.iocb_cmd_delay++;
7085 if (!(flag & SLI_IOCB_RET_IOCB)) {
7086 __lpfc_sli_ringtx_put(phba, pring, piocb);
7087 return IOCB_SUCCESS;
7094 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7095 * @phba: Pointer to HBA context object.
7096 * @piocb: Pointer to command iocb.
7097 * @sglq: Pointer to the scatter gather queue object.
7099 * This routine converts the bpl or bde that is in the IOCB
7100 * to a sgl list for the sli4 hardware. The physical address
7101 * of the bpl/bde is converted back to a virtual address.
7102 * If the IOCB contains a BPL then the list of BDE's is
7103 * converted to sli4_sge's. If the IOCB contains a single
7104 * BDE then it is converted to a single sli_sge.
7105 * The IOCB is still in cpu endianess so the contents of
7106 * the bpl can be used without byte swapping.
7108 * Returns valid XRI = Success, NO_XRI = Failure.
7111 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
7112 struct lpfc_sglq *sglq)
7114 uint16_t xritag = NO_XRI;
7115 struct ulp_bde64 *bpl = NULL;
7116 struct ulp_bde64 bde;
7117 struct sli4_sge *sgl = NULL;
7121 uint32_t offset = 0; /* accumulated offset in the sg request list */
7122 int inbound = 0; /* number of sg reply entries inbound from firmware */
7124 if (!piocbq || !sglq)
7127 sgl = (struct sli4_sge *)sglq->sgl;
7128 icmd = &piocbq->iocb;
7129 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
7130 numBdes = icmd->un.genreq64.bdl.bdeSize /
7131 sizeof(struct ulp_bde64);
7132 /* The addrHigh and addrLow fields within the IOCB
7133 * have not been byteswapped yet so there is no
7134 * need to swap them back.
7136 bpl = (struct ulp_bde64 *)
7137 ((struct lpfc_dmabuf *)piocbq->context3)->virt;
7142 for (i = 0; i < numBdes; i++) {
7143 /* Should already be byte swapped. */
7144 sgl->addr_hi = bpl->addrHigh;
7145 sgl->addr_lo = bpl->addrLow;
7147 sgl->word2 = le32_to_cpu(sgl->word2);
7148 if ((i+1) == numBdes)
7149 bf_set(lpfc_sli4_sge_last, sgl, 1);
7151 bf_set(lpfc_sli4_sge_last, sgl, 0);
7152 /* swap the size field back to the cpu so we
7153 * can assign it to the sgl.
7155 bde.tus.w = le32_to_cpu(bpl->tus.w);
7156 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
7157 /* The offsets in the sgl need to be accumulated
7158 * separately for the request and reply lists.
7159 * The request is always first, the reply follows.
7161 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
7162 /* add up the reply sg entries */
7163 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
7165 /* first inbound? reset the offset */
7168 bf_set(lpfc_sli4_sge_offset, sgl, offset);
7169 offset += bde.tus.f.bdeSize;
7171 sgl->word2 = cpu_to_le32(sgl->word2);
7175 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
7176 /* The addrHigh and addrLow fields of the BDE have not
7177 * been byteswapped yet so they need to be swapped
7178 * before putting them in the sgl.
7181 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
7183 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
7184 sgl->word2 = le32_to_cpu(sgl->word2);
7185 bf_set(lpfc_sli4_sge_last, sgl, 1);
7186 sgl->word2 = cpu_to_le32(sgl->word2);
7188 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
7190 return sglq->sli4_xritag;
7194 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7195 * @phba: Pointer to HBA context object.
7197 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7198 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7201 * Return: index into SLI4 fast-path FCP queue index.
7204 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
7207 if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
7210 return phba->fcp_qidx;
7214 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7215 * @phba: Pointer to HBA context object.
7216 * @piocb: Pointer to command iocb.
7217 * @wqe: Pointer to the work queue entry.
7219 * This routine converts the iocb command to its Work Queue Entry
7220 * equivalent. The wqe pointer should not have any fields set when
7221 * this routine is called because it will memcpy over them.
7222 * This routine does not set the CQ_ID or the WQEC bits in the
7225 * Returns: 0 = Success, IOCB_ERROR = Failure.
7228 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
7229 union lpfc_wqe *wqe)
7231 uint32_t xmit_len = 0, total_len = 0;
7235 uint8_t command_type = ELS_COMMAND_NON_FIP;
7238 uint16_t abrt_iotag;
7239 struct lpfc_iocbq *abrtiocbq;
7240 struct ulp_bde64 *bpl = NULL;
7241 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
7243 struct ulp_bde64 bde;
7244 struct lpfc_nodelist *ndlp;
7246 fip = phba->hba_flag & HBA_FIP_SUPPORT;
7247 /* The fcp commands will set command type */
7248 if (iocbq->iocb_flag & LPFC_IO_FCP)
7249 command_type = FCP_COMMAND;
7250 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
7251 command_type = ELS_COMMAND_FIP;
7253 command_type = ELS_COMMAND_NON_FIP;
7255 /* Some of the fields are in the right position already */
7256 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
7257 abort_tag = (uint32_t) iocbq->iotag;
7258 xritag = iocbq->sli4_xritag;
7259 wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
7260 /* words0-2 bpl convert bde */
7261 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
7262 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
7263 sizeof(struct ulp_bde64);
7264 bpl = (struct ulp_bde64 *)
7265 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
7269 /* Should already be byte swapped. */
7270 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
7271 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
7272 /* swap the size field back to the cpu so we
7273 * can assign it to the sgl.
7275 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
7276 xmit_len = wqe->generic.bde.tus.f.bdeSize;
7278 for (i = 0; i < numBdes; i++) {
7279 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
7280 total_len += bde.tus.f.bdeSize;
7283 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
7285 iocbq->iocb.ulpIoTag = iocbq->iotag;
7286 cmnd = iocbq->iocb.ulpCommand;
7288 switch (iocbq->iocb.ulpCommand) {
7289 case CMD_ELS_REQUEST64_CR:
7290 ndlp = (struct lpfc_nodelist *)iocbq->context1;
7291 if (!iocbq->iocb.ulpLe) {
7292 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7293 "2007 Only Limited Edition cmd Format"
7294 " supported 0x%x\n",
7295 iocbq->iocb.ulpCommand);
7298 wqe->els_req.payload_len = xmit_len;
7299 /* Els_reguest64 has a TMO */
7300 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
7301 iocbq->iocb.ulpTimeout);
7302 /* Need a VF for word 4 set the vf bit*/
7303 bf_set(els_req64_vf, &wqe->els_req, 0);
7304 /* And a VFID for word 12 */
7305 bf_set(els_req64_vfid, &wqe->els_req, 0);
7306 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
7307 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
7308 iocbq->iocb.ulpContext);
7309 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
7310 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
7311 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7312 if (command_type == ELS_COMMAND_FIP) {
7313 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
7314 >> LPFC_FIP_ELS_ID_SHIFT);
7316 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
7317 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
7318 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
7319 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
7320 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
7321 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
7322 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
7323 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
7325 case CMD_XMIT_SEQUENCE64_CX:
7326 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
7327 iocbq->iocb.un.ulpWord[3]);
7328 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
7329 iocbq->iocb.unsli3.rcvsli3.ox_id);
7330 /* The entire sequence is transmitted for this IOCB */
7331 xmit_len = total_len;
7332 cmnd = CMD_XMIT_SEQUENCE64_CR;
7333 case CMD_XMIT_SEQUENCE64_CR:
7334 /* word3 iocb=io_tag32 wqe=reserved */
7335 wqe->xmit_sequence.rsvd3 = 0;
7336 /* word4 relative_offset memcpy */
7337 /* word5 r_ctl/df_ctl memcpy */
7338 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
7339 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
7340 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
7341 LPFC_WQE_IOD_WRITE);
7342 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
7343 LPFC_WQE_LENLOC_WORD12);
7344 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
7345 wqe->xmit_sequence.xmit_len = xmit_len;
7346 command_type = OTHER_COMMAND;
7348 case CMD_XMIT_BCAST64_CN:
7349 /* word3 iocb=iotag32 wqe=seq_payload_len */
7350 wqe->xmit_bcast64.seq_payload_len = xmit_len;
7351 /* word4 iocb=rsvd wqe=rsvd */
7352 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
7353 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
7354 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
7355 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
7356 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
7357 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
7358 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
7359 LPFC_WQE_LENLOC_WORD3);
7360 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
7362 case CMD_FCP_IWRITE64_CR:
7363 command_type = FCP_COMMAND_DATA_OUT;
7364 /* word3 iocb=iotag wqe=payload_offset_len */
7365 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7366 wqe->fcp_iwrite.payload_offset_len =
7367 xmit_len + sizeof(struct fcp_rsp);
7368 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7369 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7370 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
7371 iocbq->iocb.ulpFCP2Rcvy);
7372 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
7373 /* Always open the exchange */
7374 bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
7375 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
7376 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
7377 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
7378 LPFC_WQE_LENLOC_WORD4);
7379 bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
7380 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
7382 case CMD_FCP_IREAD64_CR:
7383 /* word3 iocb=iotag wqe=payload_offset_len */
7384 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7385 wqe->fcp_iread.payload_offset_len =
7386 xmit_len + sizeof(struct fcp_rsp);
7387 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7388 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7389 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
7390 iocbq->iocb.ulpFCP2Rcvy);
7391 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
7392 /* Always open the exchange */
7393 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
7394 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
7395 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
7396 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
7397 LPFC_WQE_LENLOC_WORD4);
7398 bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
7399 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
7401 case CMD_FCP_ICMND64_CR:
7402 /* word3 iocb=IO_TAG wqe=reserved */
7403 wqe->fcp_icmd.rsrvd3 = 0;
7404 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
7405 /* Always open the exchange */
7406 bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
7407 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
7408 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
7409 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
7410 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
7411 LPFC_WQE_LENLOC_NONE);
7412 bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
7414 case CMD_GEN_REQUEST64_CR:
7415 /* For this command calculate the xmit length of the
7419 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
7420 sizeof(struct ulp_bde64);
7421 for (i = 0; i < numBdes; i++) {
7422 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
7423 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
7425 xmit_len += bde.tus.f.bdeSize;
7427 /* word3 iocb=IO_TAG wqe=request_payload_len */
7428 wqe->gen_req.request_payload_len = xmit_len;
7429 /* word4 iocb=parameter wqe=relative_offset memcpy */
7430 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
7431 /* word6 context tag copied in memcpy */
7432 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
7433 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
7434 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7435 "2015 Invalid CT %x command 0x%x\n",
7436 ct, iocbq->iocb.ulpCommand);
7439 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
7440 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
7441 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
7442 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
7443 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
7444 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
7445 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
7446 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
7447 command_type = OTHER_COMMAND;
7449 case CMD_XMIT_ELS_RSP64_CX:
7450 ndlp = (struct lpfc_nodelist *)iocbq->context1;
7451 /* words0-2 BDE memcpy */
7452 /* word3 iocb=iotag32 wqe=response_payload_len */
7453 wqe->xmit_els_rsp.response_payload_len = xmit_len;
7454 /* word4 iocb=did wge=rsvd. */
7455 wqe->xmit_els_rsp.rsvd4 = 0;
7456 /* word5 iocb=rsvd wge=did */
7457 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
7458 iocbq->iocb.un.elsreq64.remoteID);
7459 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
7460 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
7461 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
7462 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7463 iocbq->iocb.unsli3.rcvsli3.ox_id);
7464 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
7465 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
7466 phba->vpi_ids[iocbq->vport->vpi]);
7467 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
7468 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
7469 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
7470 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
7471 LPFC_WQE_LENLOC_WORD3);
7472 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
7473 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
7474 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
7475 command_type = OTHER_COMMAND;
7477 case CMD_CLOSE_XRI_CN:
7478 case CMD_ABORT_XRI_CN:
7479 case CMD_ABORT_XRI_CX:
7480 /* words 0-2 memcpy should be 0 rserved */
7481 /* port will send abts */
7482 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
7483 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
7484 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
7485 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
7489 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
7491 * The link is down, or the command was ELS_FIP
7492 * so the fw does not need to send abts
7495 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
7497 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
7498 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
7499 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
7500 wqe->abort_cmd.rsrvd5 = 0;
7501 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
7502 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
7503 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
7505 * The abort handler will send us CMD_ABORT_XRI_CN or
7506 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
7508 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
7509 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
7510 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
7511 LPFC_WQE_LENLOC_NONE);
7512 cmnd = CMD_ABORT_XRI_CX;
7513 command_type = OTHER_COMMAND;
7516 case CMD_XMIT_BLS_RSP64_CX:
7517 /* As BLS ABTS RSP WQE is very different from other WQEs,
7518 * we re-construct this WQE here based on information in
7519 * iocbq from scratch.
7521 memset(wqe, 0, sizeof(union lpfc_wqe));
7522 /* OX_ID is invariable to who sent ABTS to CT exchange */
7523 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
7524 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
7525 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
7526 LPFC_ABTS_UNSOL_INT) {
7527 /* ABTS sent by initiator to CT exchange, the
7528 * RX_ID field will be filled with the newly
7529 * allocated responder XRI.
7531 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
7532 iocbq->sli4_xritag);
7534 /* ABTS sent by responder to CT exchange, the
7535 * RX_ID field will be filled with the responder
7538 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
7539 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
7541 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
7542 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
7543 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
7544 iocbq->iocb.ulpContext);
7545 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
7546 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
7547 LPFC_WQE_LENLOC_NONE);
7548 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
7549 command_type = OTHER_COMMAND;
7550 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
7551 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
7552 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
7553 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
7554 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
7555 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
7556 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
7560 case CMD_XRI_ABORTED_CX:
7561 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
7562 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
7563 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
7564 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
7565 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
7567 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7568 "2014 Invalid command 0x%x\n",
7569 iocbq->iocb.ulpCommand);
7574 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
7575 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
7576 wqe->generic.wqe_com.abort_tag = abort_tag;
7577 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
7578 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
7579 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
7580 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
7585 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
7586 * @phba: Pointer to HBA context object.
7587 * @ring_number: SLI ring number to issue iocb on.
7588 * @piocb: Pointer to command iocb.
7589 * @flag: Flag indicating if this command can be put into txq.
7591 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
7592 * an iocb command to an HBA with SLI-4 interface spec.
7594 * This function is called with hbalock held. The function will return success
7595 * after it successfully submit the iocb to firmware or after adding to the
7599 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
7600 struct lpfc_iocbq *piocb, uint32_t flag)
7602 struct lpfc_sglq *sglq;
7604 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
7606 if (piocb->sli4_xritag == NO_XRI) {
7607 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7608 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN ||
7609 piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX)
7612 if (pring->txq_cnt) {
7613 if (!(flag & SLI_IOCB_RET_IOCB)) {
7614 __lpfc_sli_ringtx_put(phba,
7616 return IOCB_SUCCESS;
7621 sglq = __lpfc_sli_get_sglq(phba, piocb);
7623 if (!(flag & SLI_IOCB_RET_IOCB)) {
7624 __lpfc_sli_ringtx_put(phba,
7627 return IOCB_SUCCESS;
7633 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
7634 /* These IO's already have an XRI and a mapped sgl. */
7638 * This is a continuation of a commandi,(CX) so this
7639 * sglq is on the active list
7641 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
7647 piocb->sli4_lxritag = sglq->sli4_lxritag;
7648 piocb->sli4_xritag = sglq->sli4_xritag;
7649 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
7653 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
7656 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
7657 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
7659 * For FCP command IOCB, get a new WQ index to distribute
7660 * WQE across the WQsr. On the other hand, for abort IOCB,
7661 * it carries the same WQ index to the original command
7664 if (piocb->iocb_flag & LPFC_IO_FCP)
7665 piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
7666 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
7670 if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
7673 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
7679 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
7681 * This routine wraps the actual lockless version for issusing IOCB function
7682 * pointer from the lpfc_hba struct.
7685 * IOCB_ERROR - Error
7686 * IOCB_SUCCESS - Success
7690 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
7691 struct lpfc_iocbq *piocb, uint32_t flag)
7693 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
7697 * lpfc_sli_api_table_setup - Set up sli api function jump table
7698 * @phba: The hba struct for which this call is being executed.
7699 * @dev_grp: The HBA PCI-Device group number.
7701 * This routine sets up the SLI interface API function jump table in @phba
7703 * Returns: 0 - success, -ENODEV - failure.
7706 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7710 case LPFC_PCI_DEV_LP:
7711 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
7712 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
7714 case LPFC_PCI_DEV_OC:
7715 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
7716 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
7719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7720 "1419 Invalid HBA PCI-device group: 0x%x\n",
7725 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
7730 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
7731 * @phba: Pointer to HBA context object.
7732 * @pring: Pointer to driver SLI ring object.
7733 * @piocb: Pointer to command iocb.
7734 * @flag: Flag indicating if this command can be put into txq.
7736 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
7737 * function. This function gets the hbalock and calls
7738 * __lpfc_sli_issue_iocb function and will return the error returned
7739 * by __lpfc_sli_issue_iocb function. This wrapper is used by
7740 * functions which do not hold hbalock.
7743 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
7744 struct lpfc_iocbq *piocb, uint32_t flag)
7746 unsigned long iflags;
7749 spin_lock_irqsave(&phba->hbalock, iflags);
7750 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
7751 spin_unlock_irqrestore(&phba->hbalock, iflags);
7757 * lpfc_extra_ring_setup - Extra ring setup function
7758 * @phba: Pointer to HBA context object.
7760 * This function is called while driver attaches with the
7761 * HBA to setup the extra ring. The extra ring is used
7762 * only when driver needs to support target mode functionality
7763 * or IP over FC functionalities.
7765 * This function is called with no lock held.
7768 lpfc_extra_ring_setup( struct lpfc_hba *phba)
7770 struct lpfc_sli *psli;
7771 struct lpfc_sli_ring *pring;
7775 /* Adjust cmd/rsp ring iocb entries more evenly */
7777 /* Take some away from the FCP ring */
7778 pring = &psli->ring[psli->fcp_ring];
7779 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
7780 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
7781 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
7782 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
7784 /* and give them to the extra ring */
7785 pring = &psli->ring[psli->extra_ring];
7787 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
7788 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
7789 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
7790 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
7792 /* Setup default profile for this ring */
7793 pring->iotag_max = 4096;
7794 pring->num_mask = 1;
7795 pring->prt[0].profile = 0; /* Mask 0 */
7796 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
7797 pring->prt[0].type = phba->cfg_multi_ring_type;
7798 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
7803 * lpfc_sli_async_event_handler - ASYNC iocb handler function
7804 * @phba: Pointer to HBA context object.
7805 * @pring: Pointer to driver SLI ring object.
7806 * @iocbq: Pointer to iocb object.
7808 * This function is called by the slow ring event handler
7809 * function when there is an ASYNC event iocb in the ring.
7810 * This function is called with no lock held.
7811 * Currently this function handles only temperature related
7812 * ASYNC events. The function decodes the temperature sensor
7813 * event message and posts events for the management applications.
7816 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
7817 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
7822 struct temp_event temp_event_data;
7823 struct Scsi_Host *shost;
7826 icmd = &iocbq->iocb;
7827 evt_code = icmd->un.asyncstat.evt_code;
7828 temp = icmd->ulpContext;
7830 if ((evt_code != ASYNC_TEMP_WARN) &&
7831 (evt_code != ASYNC_TEMP_SAFE)) {
7832 iocb_w = (uint32_t *) icmd;
7833 lpfc_printf_log(phba,
7836 "0346 Ring %d handler: unexpected ASYNC_STATUS"
7838 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
7839 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
7840 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
7841 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
7843 icmd->un.asyncstat.evt_code,
7844 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
7845 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
7846 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
7847 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
7851 temp_event_data.data = (uint32_t)temp;
7852 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
7853 if (evt_code == ASYNC_TEMP_WARN) {
7854 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
7855 lpfc_printf_log(phba,
7858 "0347 Adapter is very hot, please take "
7859 "corrective action. temperature : %d Celsius\n",
7862 if (evt_code == ASYNC_TEMP_SAFE) {
7863 temp_event_data.event_code = LPFC_NORMAL_TEMP;
7864 lpfc_printf_log(phba,
7867 "0340 Adapter temperature is OK now. "
7868 "temperature : %d Celsius\n",
7872 /* Send temperature change event to applications */
7873 shost = lpfc_shost_from_vport(phba->pport);
7874 fc_host_post_vendor_event(shost, fc_get_event_number(),
7875 sizeof(temp_event_data), (char *) &temp_event_data,
7882 * lpfc_sli_setup - SLI ring setup function
7883 * @phba: Pointer to HBA context object.
7885 * lpfc_sli_setup sets up rings of the SLI interface with
7886 * number of iocbs per ring and iotags. This function is
7887 * called while driver attach to the HBA and before the
7888 * interrupts are enabled. So there is no need for locking.
7890 * This function always returns 0.
7893 lpfc_sli_setup(struct lpfc_hba *phba)
7895 int i, totiocbsize = 0;
7896 struct lpfc_sli *psli = &phba->sli;
7897 struct lpfc_sli_ring *pring;
7899 psli->num_rings = MAX_CONFIGURED_RINGS;
7901 psli->fcp_ring = LPFC_FCP_RING;
7902 psli->next_ring = LPFC_FCP_NEXT_RING;
7903 psli->extra_ring = LPFC_EXTRA_RING;
7905 psli->iocbq_lookup = NULL;
7906 psli->iocbq_lookup_len = 0;
7907 psli->last_iotag = 0;
7909 for (i = 0; i < psli->num_rings; i++) {
7910 pring = &psli->ring[i];
7912 case LPFC_FCP_RING: /* ring 0 - FCP */
7913 /* numCiocb and numRiocb are used in config_port */
7914 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
7915 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
7916 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
7917 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
7918 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
7919 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
7920 pring->sizeCiocb = (phba->sli_rev == 3) ?
7921 SLI3_IOCB_CMD_SIZE :
7923 pring->sizeRiocb = (phba->sli_rev == 3) ?
7924 SLI3_IOCB_RSP_SIZE :
7926 pring->iotag_ctr = 0;
7928 (phba->cfg_hba_queue_depth * 2);
7929 pring->fast_iotag = pring->iotag_max;
7930 pring->num_mask = 0;
7932 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
7933 /* numCiocb and numRiocb are used in config_port */
7934 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
7935 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
7936 pring->sizeCiocb = (phba->sli_rev == 3) ?
7937 SLI3_IOCB_CMD_SIZE :
7939 pring->sizeRiocb = (phba->sli_rev == 3) ?
7940 SLI3_IOCB_RSP_SIZE :
7942 pring->iotag_max = phba->cfg_hba_queue_depth;
7943 pring->num_mask = 0;
7945 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
7946 /* numCiocb and numRiocb are used in config_port */
7947 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
7948 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
7949 pring->sizeCiocb = (phba->sli_rev == 3) ?
7950 SLI3_IOCB_CMD_SIZE :
7952 pring->sizeRiocb = (phba->sli_rev == 3) ?
7953 SLI3_IOCB_RSP_SIZE :
7955 pring->fast_iotag = 0;
7956 pring->iotag_ctr = 0;
7957 pring->iotag_max = 4096;
7958 pring->lpfc_sli_rcv_async_status =
7959 lpfc_sli_async_event_handler;
7960 pring->num_mask = LPFC_MAX_RING_MASK;
7961 pring->prt[0].profile = 0; /* Mask 0 */
7962 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
7963 pring->prt[0].type = FC_TYPE_ELS;
7964 pring->prt[0].lpfc_sli_rcv_unsol_event =
7965 lpfc_els_unsol_event;
7966 pring->prt[1].profile = 0; /* Mask 1 */
7967 pring->prt[1].rctl = FC_RCTL_ELS_REP;
7968 pring->prt[1].type = FC_TYPE_ELS;
7969 pring->prt[1].lpfc_sli_rcv_unsol_event =
7970 lpfc_els_unsol_event;
7971 pring->prt[2].profile = 0; /* Mask 2 */
7972 /* NameServer Inquiry */
7973 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
7975 pring->prt[2].type = FC_TYPE_CT;
7976 pring->prt[2].lpfc_sli_rcv_unsol_event =
7977 lpfc_ct_unsol_event;
7978 pring->prt[3].profile = 0; /* Mask 3 */
7979 /* NameServer response */
7980 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
7982 pring->prt[3].type = FC_TYPE_CT;
7983 pring->prt[3].lpfc_sli_rcv_unsol_event =
7984 lpfc_ct_unsol_event;
7985 /* abort unsolicited sequence */
7986 pring->prt[4].profile = 0; /* Mask 4 */
7987 pring->prt[4].rctl = FC_RCTL_BA_ABTS;
7988 pring->prt[4].type = FC_TYPE_BLS;
7989 pring->prt[4].lpfc_sli_rcv_unsol_event =
7990 lpfc_sli4_ct_abort_unsol_event;
7993 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
7994 (pring->numRiocb * pring->sizeRiocb);
7996 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
7997 /* Too many cmd / rsp ring entries in SLI2 SLIM */
7998 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
7999 "SLI2 SLIM Data: x%x x%lx\n",
8000 phba->brd_no, totiocbsize,
8001 (unsigned long) MAX_SLIM_IOCB_SIZE);
8003 if (phba->cfg_multi_ring_support == 2)
8004 lpfc_extra_ring_setup(phba);
8010 * lpfc_sli_queue_setup - Queue initialization function
8011 * @phba: Pointer to HBA context object.
8013 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8014 * ring. This function also initializes ring indices of each ring.
8015 * This function is called during the initialization of the SLI
8016 * interface of an HBA.
8017 * This function is called with no lock held and always returns
8021 lpfc_sli_queue_setup(struct lpfc_hba *phba)
8023 struct lpfc_sli *psli;
8024 struct lpfc_sli_ring *pring;
8028 spin_lock_irq(&phba->hbalock);
8029 INIT_LIST_HEAD(&psli->mboxq);
8030 INIT_LIST_HEAD(&psli->mboxq_cmpl);
8031 /* Initialize list headers for txq and txcmplq as double linked lists */
8032 for (i = 0; i < psli->num_rings; i++) {
8033 pring = &psli->ring[i];
8035 pring->next_cmdidx = 0;
8036 pring->local_getidx = 0;
8038 INIT_LIST_HEAD(&pring->txq);
8039 INIT_LIST_HEAD(&pring->txcmplq);
8040 INIT_LIST_HEAD(&pring->iocb_continueq);
8041 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
8042 INIT_LIST_HEAD(&pring->postbufq);
8044 spin_unlock_irq(&phba->hbalock);
8049 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8050 * @phba: Pointer to HBA context object.
8052 * This routine flushes the mailbox command subsystem. It will unconditionally
8053 * flush all the mailbox commands in the three possible stages in the mailbox
8054 * command sub-system: pending mailbox command queue; the outstanding mailbox
8055 * command; and completed mailbox command queue. It is caller's responsibility
8056 * to make sure that the driver is in the proper state to flush the mailbox
8057 * command sub-system. Namely, the posting of mailbox commands into the
8058 * pending mailbox command queue from the various clients must be stopped;
8059 * either the HBA is in a state that it will never works on the outstanding
8060 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8061 * mailbox command has been completed.
8064 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
8066 LIST_HEAD(completions);
8067 struct lpfc_sli *psli = &phba->sli;
8069 unsigned long iflag;
8071 /* Flush all the mailbox commands in the mbox system */
8072 spin_lock_irqsave(&phba->hbalock, iflag);
8073 /* The pending mailbox command queue */
8074 list_splice_init(&phba->sli.mboxq, &completions);
8075 /* The outstanding active mailbox command */
8076 if (psli->mbox_active) {
8077 list_add_tail(&psli->mbox_active->list, &completions);
8078 psli->mbox_active = NULL;
8079 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8081 /* The completed mailbox command queue */
8082 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
8083 spin_unlock_irqrestore(&phba->hbalock, iflag);
8085 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8086 while (!list_empty(&completions)) {
8087 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
8088 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
8090 pmb->mbox_cmpl(phba, pmb);
8095 * lpfc_sli_host_down - Vport cleanup function
8096 * @vport: Pointer to virtual port object.
8098 * lpfc_sli_host_down is called to clean up the resources
8099 * associated with a vport before destroying virtual
8100 * port data structures.
8101 * This function does following operations:
8102 * - Free discovery resources associated with this virtual
8104 * - Free iocbs associated with this virtual port in
8106 * - Send abort for all iocb commands associated with this
8109 * This function is called with no lock held and always returns 1.
8112 lpfc_sli_host_down(struct lpfc_vport *vport)
8114 LIST_HEAD(completions);
8115 struct lpfc_hba *phba = vport->phba;
8116 struct lpfc_sli *psli = &phba->sli;
8117 struct lpfc_sli_ring *pring;
8118 struct lpfc_iocbq *iocb, *next_iocb;
8120 unsigned long flags = 0;
8121 uint16_t prev_pring_flag;
8123 lpfc_cleanup_discovery_resources(vport);
8125 spin_lock_irqsave(&phba->hbalock, flags);
8126 for (i = 0; i < psli->num_rings; i++) {
8127 pring = &psli->ring[i];
8128 prev_pring_flag = pring->flag;
8129 /* Only slow rings */
8130 if (pring->ringno == LPFC_ELS_RING) {
8131 pring->flag |= LPFC_DEFERRED_RING_EVENT;
8132 /* Set the lpfc data pending flag */
8133 set_bit(LPFC_DATA_READY, &phba->data_flags);
8136 * Error everything on the txq since these iocbs have not been
8137 * given to the FW yet.
8139 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
8140 if (iocb->vport != vport)
8142 list_move_tail(&iocb->list, &completions);
8146 /* Next issue ABTS for everything on the txcmplq */
8147 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
8149 if (iocb->vport != vport)
8151 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
8154 pring->flag = prev_pring_flag;
8157 spin_unlock_irqrestore(&phba->hbalock, flags);
8159 /* Cancel all the IOCBs from the completions list */
8160 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8166 * lpfc_sli_hba_down - Resource cleanup function for the HBA
8167 * @phba: Pointer to HBA context object.
8169 * This function cleans up all iocb, buffers, mailbox commands
8170 * while shutting down the HBA. This function is called with no
8171 * lock held and always returns 1.
8172 * This function does the following to cleanup driver resources:
8173 * - Free discovery resources for each virtual port
8174 * - Cleanup any pending fabric iocbs
8175 * - Iterate through the iocb txq and free each entry
8177 * - Free up any buffer posted to the HBA
8178 * - Free mailbox commands in the mailbox queue.
8181 lpfc_sli_hba_down(struct lpfc_hba *phba)
8183 LIST_HEAD(completions);
8184 struct lpfc_sli *psli = &phba->sli;
8185 struct lpfc_sli_ring *pring;
8186 struct lpfc_dmabuf *buf_ptr;
8187 unsigned long flags = 0;
8190 /* Shutdown the mailbox command sub-system */
8191 lpfc_sli_mbox_sys_shutdown(phba);
8193 lpfc_hba_down_prep(phba);
8195 lpfc_fabric_abort_hba(phba);
8197 spin_lock_irqsave(&phba->hbalock, flags);
8198 for (i = 0; i < psli->num_rings; i++) {
8199 pring = &psli->ring[i];
8200 /* Only slow rings */
8201 if (pring->ringno == LPFC_ELS_RING) {
8202 pring->flag |= LPFC_DEFERRED_RING_EVENT;
8203 /* Set the lpfc data pending flag */
8204 set_bit(LPFC_DATA_READY, &phba->data_flags);
8208 * Error everything on the txq since these iocbs have not been
8209 * given to the FW yet.
8211 list_splice_init(&pring->txq, &completions);
8215 spin_unlock_irqrestore(&phba->hbalock, flags);
8217 /* Cancel all the IOCBs from the completions list */
8218 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8221 spin_lock_irqsave(&phba->hbalock, flags);
8222 list_splice_init(&phba->elsbuf, &completions);
8223 phba->elsbuf_cnt = 0;
8224 phba->elsbuf_prev_cnt = 0;
8225 spin_unlock_irqrestore(&phba->hbalock, flags);
8227 while (!list_empty(&completions)) {
8228 list_remove_head(&completions, buf_ptr,
8229 struct lpfc_dmabuf, list);
8230 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
8234 /* Return any active mbox cmds */
8235 del_timer_sync(&psli->mbox_tmo);
8237 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
8238 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
8239 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
8245 * lpfc_sli_pcimem_bcopy - SLI memory copy function
8246 * @srcp: Source memory pointer.
8247 * @destp: Destination memory pointer.
8248 * @cnt: Number of words required to be copied.
8250 * This function is used for copying data between driver memory
8251 * and the SLI memory. This function also changes the endianness
8252 * of each word if native endianness is different from SLI
8253 * endianness. This function can be called with or without
8257 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
8259 uint32_t *src = srcp;
8260 uint32_t *dest = destp;
8264 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
8266 ldata = le32_to_cpu(ldata);
8275 * lpfc_sli_bemem_bcopy - SLI memory copy function
8276 * @srcp: Source memory pointer.
8277 * @destp: Destination memory pointer.
8278 * @cnt: Number of words required to be copied.
8280 * This function is used for copying data between a data structure
8281 * with big endian representation to local endianness.
8282 * This function can be called with or without lock.
8285 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
8287 uint32_t *src = srcp;
8288 uint32_t *dest = destp;
8292 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
8294 ldata = be32_to_cpu(ldata);
8302 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
8303 * @phba: Pointer to HBA context object.
8304 * @pring: Pointer to driver SLI ring object.
8305 * @mp: Pointer to driver buffer object.
8307 * This function is called with no lock held.
8308 * It always return zero after adding the buffer to the postbufq
8312 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8313 struct lpfc_dmabuf *mp)
8315 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
8317 spin_lock_irq(&phba->hbalock);
8318 list_add_tail(&mp->list, &pring->postbufq);
8319 pring->postbufq_cnt++;
8320 spin_unlock_irq(&phba->hbalock);
8325 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
8326 * @phba: Pointer to HBA context object.
8328 * When HBQ is enabled, buffers are searched based on tags. This function
8329 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
8330 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
8331 * does not conflict with tags of buffer posted for unsolicited events.
8332 * The function returns the allocated tag. The function is called with
8336 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
8338 spin_lock_irq(&phba->hbalock);
8339 phba->buffer_tag_count++;
8341 * Always set the QUE_BUFTAG_BIT to distiguish between
8342 * a tag assigned by HBQ.
8344 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
8345 spin_unlock_irq(&phba->hbalock);
8346 return phba->buffer_tag_count;
8350 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
8351 * @phba: Pointer to HBA context object.
8352 * @pring: Pointer to driver SLI ring object.
8355 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
8356 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
8357 * iocb is posted to the response ring with the tag of the buffer.
8358 * This function searches the pring->postbufq list using the tag
8359 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
8360 * iocb. If the buffer is found then lpfc_dmabuf object of the
8361 * buffer is returned to the caller else NULL is returned.
8362 * This function is called with no lock held.
8364 struct lpfc_dmabuf *
8365 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8368 struct lpfc_dmabuf *mp, *next_mp;
8369 struct list_head *slp = &pring->postbufq;
8371 /* Search postbufq, from the beginning, looking for a match on tag */
8372 spin_lock_irq(&phba->hbalock);
8373 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
8374 if (mp->buffer_tag == tag) {
8375 list_del_init(&mp->list);
8376 pring->postbufq_cnt--;
8377 spin_unlock_irq(&phba->hbalock);
8382 spin_unlock_irq(&phba->hbalock);
8383 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8384 "0402 Cannot find virtual addr for buffer tag on "
8385 "ring %d Data x%lx x%p x%p x%x\n",
8386 pring->ringno, (unsigned long) tag,
8387 slp->next, slp->prev, pring->postbufq_cnt);
8393 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
8394 * @phba: Pointer to HBA context object.
8395 * @pring: Pointer to driver SLI ring object.
8396 * @phys: DMA address of the buffer.
8398 * This function searches the buffer list using the dma_address
8399 * of unsolicited event to find the driver's lpfc_dmabuf object
8400 * corresponding to the dma_address. The function returns the
8401 * lpfc_dmabuf object if a buffer is found else it returns NULL.
8402 * This function is called by the ct and els unsolicited event
8403 * handlers to get the buffer associated with the unsolicited
8406 * This function is called with no lock held.
8408 struct lpfc_dmabuf *
8409 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8412 struct lpfc_dmabuf *mp, *next_mp;
8413 struct list_head *slp = &pring->postbufq;
8415 /* Search postbufq, from the beginning, looking for a match on phys */
8416 spin_lock_irq(&phba->hbalock);
8417 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
8418 if (mp->phys == phys) {
8419 list_del_init(&mp->list);
8420 pring->postbufq_cnt--;
8421 spin_unlock_irq(&phba->hbalock);
8426 spin_unlock_irq(&phba->hbalock);
8427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8428 "0410 Cannot find virtual addr for mapped buf on "
8429 "ring %d Data x%llx x%p x%p x%x\n",
8430 pring->ringno, (unsigned long long)phys,
8431 slp->next, slp->prev, pring->postbufq_cnt);
8436 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
8437 * @phba: Pointer to HBA context object.
8438 * @cmdiocb: Pointer to driver command iocb object.
8439 * @rspiocb: Pointer to driver response iocb object.
8441 * This function is the completion handler for the abort iocbs for
8442 * ELS commands. This function is called from the ELS ring event
8443 * handler with no lock held. This function frees memory resources
8444 * associated with the abort iocb.
8447 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8448 struct lpfc_iocbq *rspiocb)
8450 IOCB_t *irsp = &rspiocb->iocb;
8451 uint16_t abort_iotag, abort_context;
8452 struct lpfc_iocbq *abort_iocb;
8453 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8457 if (irsp->ulpStatus) {
8458 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
8459 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
8461 spin_lock_irq(&phba->hbalock);
8462 if (phba->sli_rev < LPFC_SLI_REV4) {
8463 if (abort_iotag != 0 &&
8464 abort_iotag <= phba->sli.last_iotag)
8466 phba->sli.iocbq_lookup[abort_iotag];
8468 /* For sli4 the abort_tag is the XRI,
8469 * so the abort routine puts the iotag of the iocb
8470 * being aborted in the context field of the abort
8473 abort_iocb = phba->sli.iocbq_lookup[abort_context];
8476 * If the iocb is not found in Firmware queue the iocb
8477 * might have completed already. Do not free it again.
8479 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
8480 if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
8481 spin_unlock_irq(&phba->hbalock);
8482 lpfc_sli_release_iocbq(phba, cmdiocb);
8485 /* For SLI4 the ulpContext field for abort IOCB
8486 * holds the iotag of the IOCB being aborted so
8487 * the local abort_context needs to be reset to
8488 * match the aborted IOCBs ulpContext.
8490 if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
8491 abort_context = abort_iocb->iocb.ulpContext;
8494 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
8495 "0327 Cannot abort els iocb %p "
8496 "with tag %x context %x, abort status %x, "
8498 abort_iocb, abort_iotag, abort_context,
8499 irsp->ulpStatus, irsp->un.ulpWord[4]);
8501 * make sure we have the right iocbq before taking it
8502 * off the txcmplq and try to call completion routine.
8505 abort_iocb->iocb.ulpContext != abort_context ||
8506 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
8507 spin_unlock_irq(&phba->hbalock);
8508 else if (phba->sli_rev < LPFC_SLI_REV4) {
8510 * leave the SLI4 aborted command on the txcmplq
8511 * list and the command complete WCQE's XB bit
8512 * will tell whether the SGL (XRI) can be released
8513 * immediately or to the aborted SGL list for the
8514 * following abort XRI from the HBA.
8516 list_del_init(&abort_iocb->list);
8517 if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
8518 abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
8519 pring->txcmplq_cnt--;
8522 /* Firmware could still be in progress of DMAing
8523 * payload, so don't free data buffer till after
8526 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
8527 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
8528 spin_unlock_irq(&phba->hbalock);
8530 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
8531 abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
8532 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
8534 spin_unlock_irq(&phba->hbalock);
8537 lpfc_sli_release_iocbq(phba, cmdiocb);
8542 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
8543 * @phba: Pointer to HBA context object.
8544 * @cmdiocb: Pointer to driver command iocb object.
8545 * @rspiocb: Pointer to driver response iocb object.
8547 * The function is called from SLI ring event handler with no
8548 * lock held. This function is the completion handler for ELS commands
8549 * which are aborted. The function frees memory resources used for
8550 * the aborted ELS commands.
8553 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8554 struct lpfc_iocbq *rspiocb)
8556 IOCB_t *irsp = &rspiocb->iocb;
8558 /* ELS cmd tag <ulpIoTag> completes */
8559 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
8560 "0139 Ignoring ELS cmd tag x%x completion Data: "
8562 irsp->ulpIoTag, irsp->ulpStatus,
8563 irsp->un.ulpWord[4], irsp->ulpTimeout);
8564 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
8565 lpfc_ct_free_iocb(phba, cmdiocb);
8567 lpfc_els_free_iocb(phba, cmdiocb);
8572 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
8573 * @phba: Pointer to HBA context object.
8574 * @pring: Pointer to driver SLI ring object.
8575 * @cmdiocb: Pointer to driver command iocb object.
8577 * This function issues an abort iocb for the provided command iocb down to
8578 * the port. Other than the case the outstanding command iocb is an abort
8579 * request, this function issues abort out unconditionally. This function is
8580 * called with hbalock held. The function returns 0 when it fails due to
8581 * memory allocation failure or when the command iocb is an abort request.
8584 lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8585 struct lpfc_iocbq *cmdiocb)
8587 struct lpfc_vport *vport = cmdiocb->vport;
8588 struct lpfc_iocbq *abtsiocbp;
8589 IOCB_t *icmd = NULL;
8590 IOCB_t *iabt = NULL;
8594 * There are certain command types we don't want to abort. And we
8595 * don't want to abort commands that are already in the process of
8598 icmd = &cmdiocb->iocb;
8599 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
8600 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8601 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
8604 /* issue ABTS for this IOCB based on iotag */
8605 abtsiocbp = __lpfc_sli_get_iocbq(phba);
8606 if (abtsiocbp == NULL)
8609 /* This signals the response to set the correct status
8610 * before calling the completion handler
8612 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
8614 iabt = &abtsiocbp->iocb;
8615 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
8616 iabt->un.acxri.abortContextTag = icmd->ulpContext;
8617 if (phba->sli_rev == LPFC_SLI_REV4) {
8618 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
8619 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
8622 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
8624 iabt->ulpClass = icmd->ulpClass;
8626 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
8627 abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
8628 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
8629 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
8631 if (phba->link_state >= LPFC_LINK_UP)
8632 iabt->ulpCommand = CMD_ABORT_XRI_CN;
8634 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
8636 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
8638 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
8639 "0339 Abort xri x%x, original iotag x%x, "
8640 "abort cmd iotag x%x\n",
8641 iabt->un.acxri.abortIoTag,
8642 iabt->un.acxri.abortContextTag,
8644 retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
8647 __lpfc_sli_release_iocbq(phba, abtsiocbp);
8650 * Caller to this routine should check for IOCB_ERROR
8651 * and handle it properly. This routine no longer removes
8652 * iocb off txcmplq and call compl in case of IOCB_ERROR.
8658 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
8659 * @phba: Pointer to HBA context object.
8660 * @pring: Pointer to driver SLI ring object.
8661 * @cmdiocb: Pointer to driver command iocb object.
8663 * This function issues an abort iocb for the provided command iocb. In case
8664 * of unloading, the abort iocb will not be issued to commands on the ELS
8665 * ring. Instead, the callback function shall be changed to those commands
8666 * so that nothing happens when them finishes. This function is called with
8667 * hbalock held. The function returns 0 when the command iocb is an abort
8671 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8672 struct lpfc_iocbq *cmdiocb)
8674 struct lpfc_vport *vport = cmdiocb->vport;
8675 int retval = IOCB_ERROR;
8676 IOCB_t *icmd = NULL;
8679 * There are certain command types we don't want to abort. And we
8680 * don't want to abort commands that are already in the process of
8683 icmd = &cmdiocb->iocb;
8684 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
8685 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8686 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
8690 * If we're unloading, don't abort iocb on the ELS ring, but change
8691 * the callback so that nothing happens when it finishes.
8693 if ((vport->load_flag & FC_UNLOADING) &&
8694 (pring->ringno == LPFC_ELS_RING)) {
8695 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
8696 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
8698 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
8699 goto abort_iotag_exit;
8702 /* Now, we try to issue the abort to the cmdiocb out */
8703 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
8707 * Caller to this routine should check for IOCB_ERROR
8708 * and handle it properly. This routine no longer removes
8709 * iocb off txcmplq and call compl in case of IOCB_ERROR.
8715 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
8716 * @phba: Pointer to HBA context object.
8717 * @pring: Pointer to driver SLI ring object.
8719 * This function aborts all iocbs in the given ring and frees all the iocb
8720 * objects in txq. This function issues abort iocbs unconditionally for all
8721 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
8722 * to complete before the return of this function. The caller is not required
8723 * to hold any locks.
8726 lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
8728 LIST_HEAD(completions);
8729 struct lpfc_iocbq *iocb, *next_iocb;
8731 if (pring->ringno == LPFC_ELS_RING)
8732 lpfc_fabric_abort_hba(phba);
8734 spin_lock_irq(&phba->hbalock);
8736 /* Take off all the iocbs on txq for cancelling */
8737 list_splice_init(&pring->txq, &completions);
8740 /* Next issue ABTS for everything on the txcmplq */
8741 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
8742 lpfc_sli_abort_iotag_issue(phba, pring, iocb);
8744 spin_unlock_irq(&phba->hbalock);
8746 /* Cancel all the IOCBs from the completions list */
8747 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8752 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
8753 * @phba: pointer to lpfc HBA data structure.
8755 * This routine will abort all pending and outstanding iocbs to an HBA.
8758 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
8760 struct lpfc_sli *psli = &phba->sli;
8761 struct lpfc_sli_ring *pring;
8764 for (i = 0; i < psli->num_rings; i++) {
8765 pring = &psli->ring[i];
8766 lpfc_sli_iocb_ring_abort(phba, pring);
8771 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
8772 * @iocbq: Pointer to driver iocb object.
8773 * @vport: Pointer to driver virtual port object.
8774 * @tgt_id: SCSI ID of the target.
8775 * @lun_id: LUN ID of the scsi device.
8776 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
8778 * This function acts as an iocb filter for functions which abort or count
8779 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
8780 * 0 if the filtering criteria is met for the given iocb and will return
8781 * 1 if the filtering criteria is not met.
8782 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
8783 * given iocb is for the SCSI device specified by vport, tgt_id and
8785 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
8786 * given iocb is for the SCSI target specified by vport and tgt_id
8788 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
8789 * given iocb is for the SCSI host associated with the given vport.
8790 * This function is called with no locks held.
8793 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
8794 uint16_t tgt_id, uint64_t lun_id,
8795 lpfc_ctx_cmd ctx_cmd)
8797 struct lpfc_scsi_buf *lpfc_cmd;
8800 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
8803 if (iocbq->vport != vport)
8806 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
8808 if (lpfc_cmd->pCmd == NULL)
8813 if ((lpfc_cmd->rdata->pnode) &&
8814 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
8815 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
8819 if ((lpfc_cmd->rdata->pnode) &&
8820 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
8827 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
8836 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
8837 * @vport: Pointer to virtual port.
8838 * @tgt_id: SCSI ID of the target.
8839 * @lun_id: LUN ID of the scsi device.
8840 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
8842 * This function returns number of FCP commands pending for the vport.
8843 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
8844 * commands pending on the vport associated with SCSI device specified
8845 * by tgt_id and lun_id parameters.
8846 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
8847 * commands pending on the vport associated with SCSI target specified
8848 * by tgt_id parameter.
8849 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
8850 * commands pending on the vport.
8851 * This function returns the number of iocbs which satisfy the filter.
8852 * This function is called without any lock held.
8855 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
8856 lpfc_ctx_cmd ctx_cmd)
8858 struct lpfc_hba *phba = vport->phba;
8859 struct lpfc_iocbq *iocbq;
8862 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
8863 iocbq = phba->sli.iocbq_lookup[i];
8865 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
8874 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
8875 * @phba: Pointer to HBA context object
8876 * @cmdiocb: Pointer to command iocb object.
8877 * @rspiocb: Pointer to response iocb object.
8879 * This function is called when an aborted FCP iocb completes. This
8880 * function is called by the ring event handler with no lock held.
8881 * This function frees the iocb.
8884 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8885 struct lpfc_iocbq *rspiocb)
8887 lpfc_sli_release_iocbq(phba, cmdiocb);
8892 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
8893 * @vport: Pointer to virtual port.
8894 * @pring: Pointer to driver SLI ring object.
8895 * @tgt_id: SCSI ID of the target.
8896 * @lun_id: LUN ID of the scsi device.
8897 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
8899 * This function sends an abort command for every SCSI command
8900 * associated with the given virtual port pending on the ring
8901 * filtered by lpfc_sli_validate_fcp_iocb function.
8902 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
8903 * FCP iocbs associated with lun specified by tgt_id and lun_id
8905 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
8906 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
8907 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
8908 * FCP iocbs associated with virtual port.
8909 * This function returns number of iocbs it failed to abort.
8910 * This function is called with no locks held.
8913 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
8914 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
8916 struct lpfc_hba *phba = vport->phba;
8917 struct lpfc_iocbq *iocbq;
8918 struct lpfc_iocbq *abtsiocb;
8920 int errcnt = 0, ret_val = 0;
8923 for (i = 1; i <= phba->sli.last_iotag; i++) {
8924 iocbq = phba->sli.iocbq_lookup[i];
8926 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
8930 /* issue ABTS for this IOCB based on iotag */
8931 abtsiocb = lpfc_sli_get_iocbq(phba);
8932 if (abtsiocb == NULL) {
8938 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
8939 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
8940 if (phba->sli_rev == LPFC_SLI_REV4)
8941 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
8943 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
8944 abtsiocb->iocb.ulpLe = 1;
8945 abtsiocb->iocb.ulpClass = cmd->ulpClass;
8946 abtsiocb->vport = phba->pport;
8948 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
8949 abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
8950 if (iocbq->iocb_flag & LPFC_IO_FCP)
8951 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
8953 if (lpfc_is_link_up(phba))
8954 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
8956 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
8958 /* Setup callback routine and issue the command. */
8959 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
8960 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
8962 if (ret_val == IOCB_ERROR) {
8963 lpfc_sli_release_iocbq(phba, abtsiocb);
8973 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
8974 * @phba: Pointer to HBA context object.
8975 * @cmdiocbq: Pointer to command iocb.
8976 * @rspiocbq: Pointer to response iocb.
8978 * This function is the completion handler for iocbs issued using
8979 * lpfc_sli_issue_iocb_wait function. This function is called by the
8980 * ring event handler function without any lock held. This function
8981 * can be called from both worker thread context and interrupt
8982 * context. This function also can be called from other thread which
8983 * cleans up the SLI layer objects.
8984 * This function copy the contents of the response iocb to the
8985 * response iocb memory object provided by the caller of
8986 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
8987 * sleeps for the iocb completion.
8990 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
8991 struct lpfc_iocbq *cmdiocbq,
8992 struct lpfc_iocbq *rspiocbq)
8994 wait_queue_head_t *pdone_q;
8995 unsigned long iflags;
8996 struct lpfc_scsi_buf *lpfc_cmd;
8998 spin_lock_irqsave(&phba->hbalock, iflags);
8999 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
9000 if (cmdiocbq->context2 && rspiocbq)
9001 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
9002 &rspiocbq->iocb, sizeof(IOCB_t));
9004 /* Set the exchange busy flag for task management commands */
9005 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
9006 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
9007 lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
9009 lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
9012 pdone_q = cmdiocbq->context_un.wait_queue;
9015 spin_unlock_irqrestore(&phba->hbalock, iflags);
9020 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9021 * @phba: Pointer to HBA context object..
9022 * @piocbq: Pointer to command iocb.
9023 * @flag: Flag to test.
9025 * This routine grabs the hbalock and then test the iocb_flag to
9026 * see if the passed in flag is set.
9029 * 0 if flag is not set.
9032 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
9033 struct lpfc_iocbq *piocbq, uint32_t flag)
9035 unsigned long iflags;
9038 spin_lock_irqsave(&phba->hbalock, iflags);
9039 ret = piocbq->iocb_flag & flag;
9040 spin_unlock_irqrestore(&phba->hbalock, iflags);
9046 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9047 * @phba: Pointer to HBA context object..
9048 * @pring: Pointer to sli ring.
9049 * @piocb: Pointer to command iocb.
9050 * @prspiocbq: Pointer to response iocb.
9051 * @timeout: Timeout in number of seconds.
9053 * This function issues the iocb to firmware and waits for the
9054 * iocb to complete. If the iocb command is not
9055 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9056 * Caller should not free the iocb resources if this function
9057 * returns IOCB_TIMEDOUT.
9058 * The function waits for the iocb completion using an
9059 * non-interruptible wait.
9060 * This function will sleep while waiting for iocb completion.
9061 * So, this function should not be called from any context which
9062 * does not allow sleeping. Due to the same reason, this function
9063 * cannot be called with interrupt disabled.
9064 * This function assumes that the iocb completions occur while
9065 * this function sleep. So, this function cannot be called from
9066 * the thread which process iocb completion for this ring.
9067 * This function clears the iocb_flag of the iocb object before
9068 * issuing the iocb and the iocb completion handler sets this
9069 * flag and wakes this thread when the iocb completes.
9070 * The contents of the response iocb will be copied to prspiocbq
9071 * by the completion handler when the command completes.
9072 * This function returns IOCB_SUCCESS when success.
9073 * This function is called with no lock held.
9076 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
9077 uint32_t ring_number,
9078 struct lpfc_iocbq *piocb,
9079 struct lpfc_iocbq *prspiocbq,
9082 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
9083 long timeleft, timeout_req = 0;
9084 int retval = IOCB_SUCCESS;
9086 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
9088 * If the caller has provided a response iocbq buffer, then context2
9089 * is NULL or its an error.
9092 if (piocb->context2)
9094 piocb->context2 = prspiocbq;
9097 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
9098 piocb->context_un.wait_queue = &done_q;
9099 piocb->iocb_flag &= ~LPFC_IO_WAKE;
9101 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9102 if (lpfc_readl(phba->HCregaddr, &creg_val))
9104 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
9105 writel(creg_val, phba->HCregaddr);
9106 readl(phba->HCregaddr); /* flush */
9109 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
9111 if (retval == IOCB_SUCCESS) {
9112 timeout_req = timeout * HZ;
9113 timeleft = wait_event_timeout(done_q,
9114 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
9117 if (piocb->iocb_flag & LPFC_IO_WAKE) {
9118 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9119 "0331 IOCB wake signaled\n");
9120 } else if (timeleft == 0) {
9121 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9122 "0338 IOCB wait timeout error - no "
9123 "wake response Data x%x\n", timeout);
9124 retval = IOCB_TIMEDOUT;
9126 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9127 "0330 IOCB wake NOT set, "
9129 timeout, (timeleft / jiffies));
9130 retval = IOCB_TIMEDOUT;
9132 } else if (retval == IOCB_BUSY) {
9133 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9134 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
9135 phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
9138 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9139 "0332 IOCB wait issue failed, Data x%x\n",
9141 retval = IOCB_ERROR;
9144 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9145 if (lpfc_readl(phba->HCregaddr, &creg_val))
9147 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
9148 writel(creg_val, phba->HCregaddr);
9149 readl(phba->HCregaddr); /* flush */
9153 piocb->context2 = NULL;
9155 piocb->context_un.wait_queue = NULL;
9156 piocb->iocb_cmpl = NULL;
9161 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
9162 * @phba: Pointer to HBA context object.
9163 * @pmboxq: Pointer to driver mailbox object.
9164 * @timeout: Timeout in number of seconds.
9166 * This function issues the mailbox to firmware and waits for the
9167 * mailbox command to complete. If the mailbox command is not
9168 * completed within timeout seconds, it returns MBX_TIMEOUT.
9169 * The function waits for the mailbox completion using an
9170 * interruptible wait. If the thread is woken up due to a
9171 * signal, MBX_TIMEOUT error is returned to the caller. Caller
9172 * should not free the mailbox resources, if this function returns
9174 * This function will sleep while waiting for mailbox completion.
9175 * So, this function should not be called from any context which
9176 * does not allow sleeping. Due to the same reason, this function
9177 * cannot be called with interrupt disabled.
9178 * This function assumes that the mailbox completion occurs while
9179 * this function sleep. So, this function cannot be called from
9180 * the worker thread which processes mailbox completion.
9181 * This function is called in the context of HBA management
9183 * This function returns MBX_SUCCESS when successful.
9184 * This function is called with no lock held.
9187 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
9190 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
9194 /* The caller must leave context1 empty. */
9195 if (pmboxq->context1)
9196 return MBX_NOT_FINISHED;
9198 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
9199 /* setup wake call as IOCB callback */
9200 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
9201 /* setup context field to pass wait_queue pointer to wake function */
9202 pmboxq->context1 = &done_q;
9204 /* now issue the command */
9205 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
9207 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
9208 wait_event_interruptible_timeout(done_q,
9209 pmboxq->mbox_flag & LPFC_MBX_WAKE,
9212 spin_lock_irqsave(&phba->hbalock, flag);
9213 pmboxq->context1 = NULL;
9215 * if LPFC_MBX_WAKE flag is set the mailbox is completed
9216 * else do not free the resources.
9218 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
9219 retval = MBX_SUCCESS;
9220 lpfc_sli4_swap_str(phba, pmboxq);
9222 retval = MBX_TIMEOUT;
9223 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9225 spin_unlock_irqrestore(&phba->hbalock, flag);
9232 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
9233 * @phba: Pointer to HBA context.
9235 * This function is called to shutdown the driver's mailbox sub-system.
9236 * It first marks the mailbox sub-system is in a block state to prevent
9237 * the asynchronous mailbox command from issued off the pending mailbox
9238 * command queue. If the mailbox command sub-system shutdown is due to
9239 * HBA error conditions such as EEH or ERATT, this routine shall invoke
9240 * the mailbox sub-system flush routine to forcefully bring down the
9241 * mailbox sub-system. Otherwise, if it is due to normal condition (such
9242 * as with offline or HBA function reset), this routine will wait for the
9243 * outstanding mailbox command to complete before invoking the mailbox
9244 * sub-system flush routine to gracefully bring down mailbox sub-system.
9247 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
9249 struct lpfc_sli *psli = &phba->sli;
9250 uint8_t actcmd = MBX_HEARTBEAT;
9251 unsigned long timeout;
9253 spin_lock_irq(&phba->hbalock);
9254 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9255 spin_unlock_irq(&phba->hbalock);
9257 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9258 spin_lock_irq(&phba->hbalock);
9259 if (phba->sli.mbox_active)
9260 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
9261 spin_unlock_irq(&phba->hbalock);
9262 /* Determine how long we might wait for the active mailbox
9263 * command to be gracefully completed by firmware.
9265 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
9267 while (phba->sli.mbox_active) {
9268 /* Check active mailbox complete status every 2ms */
9270 if (time_after(jiffies, timeout))
9271 /* Timeout, let the mailbox flush routine to
9272 * forcefully release active mailbox command
9277 lpfc_sli_mbox_sys_flush(phba);
9281 * lpfc_sli_eratt_read - read sli-3 error attention events
9282 * @phba: Pointer to HBA context.
9284 * This function is called to read the SLI3 device error attention registers
9285 * for possible error attention events. The caller must hold the hostlock
9286 * with spin_lock_irq().
9288 * This function returns 1 when there is Error Attention in the Host Attention
9289 * Register and returns 0 otherwise.
9292 lpfc_sli_eratt_read(struct lpfc_hba *phba)
9296 /* Read chip Host Attention (HA) register */
9297 if (lpfc_readl(phba->HAregaddr, &ha_copy))
9300 if (ha_copy & HA_ERATT) {
9301 /* Read host status register to retrieve error event */
9302 if (lpfc_sli_read_hs(phba))
9305 /* Check if there is a deferred error condition is active */
9306 if ((HS_FFER1 & phba->work_hs) &&
9307 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
9308 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
9309 phba->hba_flag |= DEFER_ERATT;
9310 /* Clear all interrupt enable conditions */
9311 writel(0, phba->HCregaddr);
9312 readl(phba->HCregaddr);
9315 /* Set the driver HA work bitmap */
9316 phba->work_ha |= HA_ERATT;
9317 /* Indicate polling handles this ERATT */
9318 phba->hba_flag |= HBA_ERATT_HANDLED;
9324 /* Set the driver HS work bitmap */
9325 phba->work_hs |= UNPLUG_ERR;
9326 /* Set the driver HA work bitmap */
9327 phba->work_ha |= HA_ERATT;
9328 /* Indicate polling handles this ERATT */
9329 phba->hba_flag |= HBA_ERATT_HANDLED;
9334 * lpfc_sli4_eratt_read - read sli-4 error attention events
9335 * @phba: Pointer to HBA context.
9337 * This function is called to read the SLI4 device error attention registers
9338 * for possible error attention events. The caller must hold the hostlock
9339 * with spin_lock_irq().
9341 * This function returns 1 when there is Error Attention in the Host Attention
9342 * Register and returns 0 otherwise.
9345 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
9347 uint32_t uerr_sta_hi, uerr_sta_lo;
9348 uint32_t if_type, portsmphr;
9349 struct lpfc_register portstat_reg;
9352 * For now, use the SLI4 device internal unrecoverable error
9353 * registers for error attention. This can be changed later.
9355 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9357 case LPFC_SLI_INTF_IF_TYPE_0:
9358 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
9360 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
9362 phba->work_hs |= UNPLUG_ERR;
9363 phba->work_ha |= HA_ERATT;
9364 phba->hba_flag |= HBA_ERATT_HANDLED;
9367 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
9368 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
9369 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9370 "1423 HBA Unrecoverable error: "
9371 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
9372 "ue_mask_lo_reg=0x%x, "
9373 "ue_mask_hi_reg=0x%x\n",
9374 uerr_sta_lo, uerr_sta_hi,
9375 phba->sli4_hba.ue_mask_lo,
9376 phba->sli4_hba.ue_mask_hi);
9377 phba->work_status[0] = uerr_sta_lo;
9378 phba->work_status[1] = uerr_sta_hi;
9379 phba->work_ha |= HA_ERATT;
9380 phba->hba_flag |= HBA_ERATT_HANDLED;
9384 case LPFC_SLI_INTF_IF_TYPE_2:
9385 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
9386 &portstat_reg.word0) ||
9387 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
9389 phba->work_hs |= UNPLUG_ERR;
9390 phba->work_ha |= HA_ERATT;
9391 phba->hba_flag |= HBA_ERATT_HANDLED;
9394 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
9395 phba->work_status[0] =
9396 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
9397 phba->work_status[1] =
9398 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
9399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9400 "2885 Port Error Detected: "
9401 "port status reg 0x%x, "
9402 "port smphr reg 0x%x, "
9403 "error 1=0x%x, error 2=0x%x\n",
9406 phba->work_status[0],
9407 phba->work_status[1]);
9408 phba->work_ha |= HA_ERATT;
9409 phba->hba_flag |= HBA_ERATT_HANDLED;
9413 case LPFC_SLI_INTF_IF_TYPE_1:
9415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9416 "2886 HBA Error Attention on unsupported "
9417 "if type %d.", if_type);
9425 * lpfc_sli_check_eratt - check error attention events
9426 * @phba: Pointer to HBA context.
9428 * This function is called from timer soft interrupt context to check HBA's
9429 * error attention register bit for error attention events.
9431 * This function returns 1 when there is Error Attention in the Host Attention
9432 * Register and returns 0 otherwise.
9435 lpfc_sli_check_eratt(struct lpfc_hba *phba)
9439 /* If somebody is waiting to handle an eratt, don't process it
9440 * here. The brdkill function will do this.
9442 if (phba->link_flag & LS_IGNORE_ERATT)
9445 /* Check if interrupt handler handles this ERATT */
9446 spin_lock_irq(&phba->hbalock);
9447 if (phba->hba_flag & HBA_ERATT_HANDLED) {
9448 /* Interrupt handler has handled ERATT */
9449 spin_unlock_irq(&phba->hbalock);
9454 * If there is deferred error attention, do not check for error
9457 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
9458 spin_unlock_irq(&phba->hbalock);
9462 /* If PCI channel is offline, don't process it */
9463 if (unlikely(pci_channel_offline(phba->pcidev))) {
9464 spin_unlock_irq(&phba->hbalock);
9468 switch (phba->sli_rev) {
9471 /* Read chip Host Attention (HA) register */
9472 ha_copy = lpfc_sli_eratt_read(phba);
9475 /* Read device Uncoverable Error (UERR) registers */
9476 ha_copy = lpfc_sli4_eratt_read(phba);
9479 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9480 "0299 Invalid SLI revision (%d)\n",
9485 spin_unlock_irq(&phba->hbalock);
9491 * lpfc_intr_state_check - Check device state for interrupt handling
9492 * @phba: Pointer to HBA context.
9494 * This inline routine checks whether a device or its PCI slot is in a state
9495 * that the interrupt should be handled.
9497 * This function returns 0 if the device or the PCI slot is in a state that
9498 * interrupt should be handled, otherwise -EIO.
9501 lpfc_intr_state_check(struct lpfc_hba *phba)
9503 /* If the pci channel is offline, ignore all the interrupts */
9504 if (unlikely(pci_channel_offline(phba->pcidev)))
9507 /* Update device level interrupt statistics */
9508 phba->sli.slistat.sli_intr++;
9510 /* Ignore all interrupts during initialization. */
9511 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
9518 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
9519 * @irq: Interrupt number.
9520 * @dev_id: The device context pointer.
9522 * This function is directly called from the PCI layer as an interrupt
9523 * service routine when device with SLI-3 interface spec is enabled with
9524 * MSI-X multi-message interrupt mode and there are slow-path events in
9525 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9526 * interrupt mode, this function is called as part of the device-level
9527 * interrupt handler. When the PCI slot is in error recovery or the HBA
9528 * is undergoing initialization, the interrupt handler will not process
9529 * the interrupt. The link attention and ELS ring attention events are
9530 * handled by the worker thread. The interrupt handler signals the worker
9531 * thread and returns for these events. This function is called without
9532 * any lock held. It gets the hbalock to access and update SLI data
9535 * This function returns IRQ_HANDLED when interrupt is handled else it
9539 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
9541 struct lpfc_hba *phba;
9542 uint32_t ha_copy, hc_copy;
9543 uint32_t work_ha_copy;
9544 unsigned long status;
9545 unsigned long iflag;
9548 MAILBOX_t *mbox, *pmbox;
9549 struct lpfc_vport *vport;
9550 struct lpfc_nodelist *ndlp;
9551 struct lpfc_dmabuf *mp;
9556 * Get the driver's phba structure from the dev_id and
9557 * assume the HBA is not interrupting.
9559 phba = (struct lpfc_hba *)dev_id;
9561 if (unlikely(!phba))
9565 * Stuff needs to be attented to when this function is invoked as an
9566 * individual interrupt handler in MSI-X multi-message interrupt mode
9568 if (phba->intr_type == MSIX) {
9569 /* Check device state for handling interrupt */
9570 if (lpfc_intr_state_check(phba))
9572 /* Need to read HA REG for slow-path events */
9573 spin_lock_irqsave(&phba->hbalock, iflag);
9574 if (lpfc_readl(phba->HAregaddr, &ha_copy))
9576 /* If somebody is waiting to handle an eratt don't process it
9577 * here. The brdkill function will do this.
9579 if (phba->link_flag & LS_IGNORE_ERATT)
9580 ha_copy &= ~HA_ERATT;
9581 /* Check the need for handling ERATT in interrupt handler */
9582 if (ha_copy & HA_ERATT) {
9583 if (phba->hba_flag & HBA_ERATT_HANDLED)
9584 /* ERATT polling has handled ERATT */
9585 ha_copy &= ~HA_ERATT;
9587 /* Indicate interrupt handler handles ERATT */
9588 phba->hba_flag |= HBA_ERATT_HANDLED;
9592 * If there is deferred error attention, do not check for any
9595 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
9596 spin_unlock_irqrestore(&phba->hbalock, iflag);
9600 /* Clear up only attention source related to slow-path */
9601 if (lpfc_readl(phba->HCregaddr, &hc_copy))
9604 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
9605 HC_LAINT_ENA | HC_ERINT_ENA),
9607 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
9609 writel(hc_copy, phba->HCregaddr);
9610 readl(phba->HAregaddr); /* flush */
9611 spin_unlock_irqrestore(&phba->hbalock, iflag);
9613 ha_copy = phba->ha_copy;
9615 work_ha_copy = ha_copy & phba->work_ha_mask;
9618 if (work_ha_copy & HA_LATT) {
9619 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
9621 * Turn off Link Attention interrupts
9622 * until CLEAR_LA done
9624 spin_lock_irqsave(&phba->hbalock, iflag);
9625 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
9626 if (lpfc_readl(phba->HCregaddr, &control))
9628 control &= ~HC_LAINT_ENA;
9629 writel(control, phba->HCregaddr);
9630 readl(phba->HCregaddr); /* flush */
9631 spin_unlock_irqrestore(&phba->hbalock, iflag);
9634 work_ha_copy &= ~HA_LATT;
9637 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
9639 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
9640 * the only slow ring.
9642 status = (work_ha_copy &
9643 (HA_RXMASK << (4*LPFC_ELS_RING)));
9644 status >>= (4*LPFC_ELS_RING);
9645 if (status & HA_RXMASK) {
9646 spin_lock_irqsave(&phba->hbalock, iflag);
9647 if (lpfc_readl(phba->HCregaddr, &control))
9650 lpfc_debugfs_slow_ring_trc(phba,
9651 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
9653 (uint32_t)phba->sli.slistat.sli_intr);
9655 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
9656 lpfc_debugfs_slow_ring_trc(phba,
9658 "pwork:x%x hawork:x%x wait:x%x",
9659 phba->work_ha, work_ha_copy,
9660 (uint32_t)((unsigned long)
9661 &phba->work_waitq));
9664 ~(HC_R0INT_ENA << LPFC_ELS_RING);
9665 writel(control, phba->HCregaddr);
9666 readl(phba->HCregaddr); /* flush */
9669 lpfc_debugfs_slow_ring_trc(phba,
9670 "ISR slow ring: pwork:"
9671 "x%x hawork:x%x wait:x%x",
9672 phba->work_ha, work_ha_copy,
9673 (uint32_t)((unsigned long)
9674 &phba->work_waitq));
9676 spin_unlock_irqrestore(&phba->hbalock, iflag);
9679 spin_lock_irqsave(&phba->hbalock, iflag);
9680 if (work_ha_copy & HA_ERATT) {
9681 if (lpfc_sli_read_hs(phba))
9684 * Check if there is a deferred error condition
9687 if ((HS_FFER1 & phba->work_hs) &&
9688 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
9689 HS_FFER6 | HS_FFER7 | HS_FFER8) &
9691 phba->hba_flag |= DEFER_ERATT;
9692 /* Clear all interrupt enable conditions */
9693 writel(0, phba->HCregaddr);
9694 readl(phba->HCregaddr);
9698 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
9699 pmb = phba->sli.mbox_active;
9704 /* First check out the status word */
9705 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
9706 if (pmbox->mbxOwner != OWN_HOST) {
9707 spin_unlock_irqrestore(&phba->hbalock, iflag);
9709 * Stray Mailbox Interrupt, mbxCommand <cmd>
9710 * mbxStatus <status>
9712 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
9714 "(%d):0304 Stray Mailbox "
9715 "Interrupt mbxCommand x%x "
9717 (vport ? vport->vpi : 0),
9720 /* clear mailbox attention bit */
9721 work_ha_copy &= ~HA_MBATT;
9723 phba->sli.mbox_active = NULL;
9724 spin_unlock_irqrestore(&phba->hbalock, iflag);
9725 phba->last_completion_time = jiffies;
9726 del_timer(&phba->sli.mbox_tmo);
9727 if (pmb->mbox_cmpl) {
9728 lpfc_sli_pcimem_bcopy(mbox, pmbox,
9730 if (pmb->out_ext_byte_len &&
9732 lpfc_sli_pcimem_bcopy(
9735 pmb->out_ext_byte_len);
9737 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
9738 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
9740 lpfc_debugfs_disc_trc(vport,
9741 LPFC_DISC_TRC_MBOX_VPORT,
9743 "status:x%x rpi:x%x",
9744 (uint32_t)pmbox->mbxStatus,
9745 pmbox->un.varWords[0], 0);
9747 if (!pmbox->mbxStatus) {
9748 mp = (struct lpfc_dmabuf *)
9750 ndlp = (struct lpfc_nodelist *)
9753 /* Reg_LOGIN of dflt RPI was
9754 * successful. new lets get
9755 * rid of the RPI using the
9758 lpfc_unreg_login(phba,
9760 pmbox->un.varWords[0],
9763 lpfc_mbx_cmpl_dflt_rpi;
9765 pmb->context2 = ndlp;
9767 rc = lpfc_sli_issue_mbox(phba,
9771 lpfc_printf_log(phba,
9774 "0350 rc should have"
9776 if (rc != MBX_NOT_FINISHED)
9777 goto send_current_mbox;
9781 &phba->pport->work_port_lock,
9783 phba->pport->work_port_events &=
9785 spin_unlock_irqrestore(
9786 &phba->pport->work_port_lock,
9788 lpfc_mbox_cmpl_put(phba, pmb);
9791 spin_unlock_irqrestore(&phba->hbalock, iflag);
9793 if ((work_ha_copy & HA_MBATT) &&
9794 (phba->sli.mbox_active == NULL)) {
9796 /* Process next mailbox command if there is one */
9798 rc = lpfc_sli_issue_mbox(phba, NULL,
9800 } while (rc == MBX_NOT_FINISHED);
9801 if (rc != MBX_SUCCESS)
9802 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
9803 LOG_SLI, "0349 rc should be "
9807 spin_lock_irqsave(&phba->hbalock, iflag);
9808 phba->work_ha |= work_ha_copy;
9809 spin_unlock_irqrestore(&phba->hbalock, iflag);
9810 lpfc_worker_wake_up(phba);
9814 spin_unlock_irqrestore(&phba->hbalock, iflag);
9817 } /* lpfc_sli_sp_intr_handler */
9820 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
9821 * @irq: Interrupt number.
9822 * @dev_id: The device context pointer.
9824 * This function is directly called from the PCI layer as an interrupt
9825 * service routine when device with SLI-3 interface spec is enabled with
9826 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
9827 * ring event in the HBA. However, when the device is enabled with either
9828 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
9829 * device-level interrupt handler. When the PCI slot is in error recovery
9830 * or the HBA is undergoing initialization, the interrupt handler will not
9831 * process the interrupt. The SCSI FCP fast-path ring event are handled in
9832 * the intrrupt context. This function is called without any lock held.
9833 * It gets the hbalock to access and update SLI data structures.
9835 * This function returns IRQ_HANDLED when interrupt is handled else it
9839 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
9841 struct lpfc_hba *phba;
9843 unsigned long status;
9844 unsigned long iflag;
9846 /* Get the driver's phba structure from the dev_id and
9847 * assume the HBA is not interrupting.
9849 phba = (struct lpfc_hba *) dev_id;
9851 if (unlikely(!phba))
9855 * Stuff needs to be attented to when this function is invoked as an
9856 * individual interrupt handler in MSI-X multi-message interrupt mode
9858 if (phba->intr_type == MSIX) {
9859 /* Check device state for handling interrupt */
9860 if (lpfc_intr_state_check(phba))
9862 /* Need to read HA REG for FCP ring and other ring events */
9863 if (lpfc_readl(phba->HAregaddr, &ha_copy))
9865 /* Clear up only attention source related to fast-path */
9866 spin_lock_irqsave(&phba->hbalock, iflag);
9868 * If there is deferred error attention, do not check for
9871 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
9872 spin_unlock_irqrestore(&phba->hbalock, iflag);
9875 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
9877 readl(phba->HAregaddr); /* flush */
9878 spin_unlock_irqrestore(&phba->hbalock, iflag);
9880 ha_copy = phba->ha_copy;
9883 * Process all events on FCP ring. Take the optimized path for FCP IO.
9885 ha_copy &= ~(phba->work_ha_mask);
9887 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
9888 status >>= (4*LPFC_FCP_RING);
9889 if (status & HA_RXMASK)
9890 lpfc_sli_handle_fast_ring_event(phba,
9891 &phba->sli.ring[LPFC_FCP_RING],
9894 if (phba->cfg_multi_ring_support == 2) {
9896 * Process all events on extra ring. Take the optimized path
9897 * for extra ring IO.
9899 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
9900 status >>= (4*LPFC_EXTRA_RING);
9901 if (status & HA_RXMASK) {
9902 lpfc_sli_handle_fast_ring_event(phba,
9903 &phba->sli.ring[LPFC_EXTRA_RING],
9908 } /* lpfc_sli_fp_intr_handler */
9911 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
9912 * @irq: Interrupt number.
9913 * @dev_id: The device context pointer.
9915 * This function is the HBA device-level interrupt handler to device with
9916 * SLI-3 interface spec, called from the PCI layer when either MSI or
9917 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
9918 * requires driver attention. This function invokes the slow-path interrupt
9919 * attention handling function and fast-path interrupt attention handling
9920 * function in turn to process the relevant HBA attention events. This
9921 * function is called without any lock held. It gets the hbalock to access
9922 * and update SLI data structures.
9924 * This function returns IRQ_HANDLED when interrupt is handled, else it
9928 lpfc_sli_intr_handler(int irq, void *dev_id)
9930 struct lpfc_hba *phba;
9931 irqreturn_t sp_irq_rc, fp_irq_rc;
9932 unsigned long status1, status2;
9936 * Get the driver's phba structure from the dev_id and
9937 * assume the HBA is not interrupting.
9939 phba = (struct lpfc_hba *) dev_id;
9941 if (unlikely(!phba))
9944 /* Check device state for handling interrupt */
9945 if (lpfc_intr_state_check(phba))
9948 spin_lock(&phba->hbalock);
9949 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
9950 spin_unlock(&phba->hbalock);
9954 if (unlikely(!phba->ha_copy)) {
9955 spin_unlock(&phba->hbalock);
9957 } else if (phba->ha_copy & HA_ERATT) {
9958 if (phba->hba_flag & HBA_ERATT_HANDLED)
9959 /* ERATT polling has handled ERATT */
9960 phba->ha_copy &= ~HA_ERATT;
9962 /* Indicate interrupt handler handles ERATT */
9963 phba->hba_flag |= HBA_ERATT_HANDLED;
9967 * If there is deferred error attention, do not check for any interrupt.
9969 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
9970 spin_unlock(&phba->hbalock);
9974 /* Clear attention sources except link and error attentions */
9975 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
9976 spin_unlock(&phba->hbalock);
9979 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
9980 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
9982 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
9983 writel(hc_copy, phba->HCregaddr);
9984 readl(phba->HAregaddr); /* flush */
9985 spin_unlock(&phba->hbalock);
9988 * Invokes slow-path host attention interrupt handling as appropriate.
9991 /* status of events with mailbox and link attention */
9992 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
9994 /* status of events with ELS ring */
9995 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
9996 status2 >>= (4*LPFC_ELS_RING);
9998 if (status1 || (status2 & HA_RXMASK))
9999 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
10001 sp_irq_rc = IRQ_NONE;
10004 * Invoke fast-path host attention interrupt handling as appropriate.
10007 /* status of events with FCP ring */
10008 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
10009 status1 >>= (4*LPFC_FCP_RING);
10011 /* status of events with extra ring */
10012 if (phba->cfg_multi_ring_support == 2) {
10013 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
10014 status2 >>= (4*LPFC_EXTRA_RING);
10018 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
10019 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
10021 fp_irq_rc = IRQ_NONE;
10023 /* Return device-level interrupt handling status */
10024 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
10025 } /* lpfc_sli_intr_handler */
10028 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10029 * @phba: pointer to lpfc hba data structure.
10031 * This routine is invoked by the worker thread to process all the pending
10032 * SLI4 FCP abort XRI events.
10034 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
10036 struct lpfc_cq_event *cq_event;
10038 /* First, declare the fcp xri abort event has been handled */
10039 spin_lock_irq(&phba->hbalock);
10040 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
10041 spin_unlock_irq(&phba->hbalock);
10042 /* Now, handle all the fcp xri abort events */
10043 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
10044 /* Get the first event from the head of the event queue */
10045 spin_lock_irq(&phba->hbalock);
10046 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
10047 cq_event, struct lpfc_cq_event, list);
10048 spin_unlock_irq(&phba->hbalock);
10049 /* Notify aborted XRI for FCP work queue */
10050 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
10051 /* Free the event processed back to the free pool */
10052 lpfc_sli4_cq_event_release(phba, cq_event);
10057 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10058 * @phba: pointer to lpfc hba data structure.
10060 * This routine is invoked by the worker thread to process all the pending
10061 * SLI4 els abort xri events.
10063 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
10065 struct lpfc_cq_event *cq_event;
10067 /* First, declare the els xri abort event has been handled */
10068 spin_lock_irq(&phba->hbalock);
10069 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
10070 spin_unlock_irq(&phba->hbalock);
10071 /* Now, handle all the els xri abort events */
10072 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
10073 /* Get the first event from the head of the event queue */
10074 spin_lock_irq(&phba->hbalock);
10075 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10076 cq_event, struct lpfc_cq_event, list);
10077 spin_unlock_irq(&phba->hbalock);
10078 /* Notify aborted XRI for ELS work queue */
10079 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
10080 /* Free the event processed back to the free pool */
10081 lpfc_sli4_cq_event_release(phba, cq_event);
10086 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10087 * @phba: pointer to lpfc hba data structure
10088 * @pIocbIn: pointer to the rspiocbq
10089 * @pIocbOut: pointer to the cmdiocbq
10090 * @wcqe: pointer to the complete wcqe
10092 * This routine transfers the fields of a command iocbq to a response iocbq
10093 * by copying all the IOCB fields from command iocbq and transferring the
10094 * completion status information from the complete wcqe.
10097 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
10098 struct lpfc_iocbq *pIocbIn,
10099 struct lpfc_iocbq *pIocbOut,
10100 struct lpfc_wcqe_complete *wcqe)
10102 unsigned long iflags;
10103 size_t offset = offsetof(struct lpfc_iocbq, iocb);
10105 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
10106 sizeof(struct lpfc_iocbq) - offset);
10107 /* Map WCQE parameters into irspiocb parameters */
10108 pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
10109 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
10110 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
10111 pIocbIn->iocb.un.fcpi.fcpi_parm =
10112 pIocbOut->iocb.un.fcpi.fcpi_parm -
10113 wcqe->total_data_placed;
10115 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
10117 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
10118 pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
10121 /* Pick up HBA exchange busy condition */
10122 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
10123 spin_lock_irqsave(&phba->hbalock, iflags);
10124 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
10125 spin_unlock_irqrestore(&phba->hbalock, iflags);
10130 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
10131 * @phba: Pointer to HBA context object.
10132 * @wcqe: Pointer to work-queue completion queue entry.
10134 * This routine handles an ELS work-queue completion event and construct
10135 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
10136 * discovery engine to handle.
10138 * Return: Pointer to the receive IOCBQ, NULL otherwise.
10140 static struct lpfc_iocbq *
10141 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
10142 struct lpfc_iocbq *irspiocbq)
10144 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
10145 struct lpfc_iocbq *cmdiocbq;
10146 struct lpfc_wcqe_complete *wcqe;
10147 unsigned long iflags;
10149 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
10150 spin_lock_irqsave(&phba->hbalock, iflags);
10151 pring->stats.iocb_event++;
10152 /* Look up the ELS command IOCB and create pseudo response IOCB */
10153 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
10154 bf_get(lpfc_wcqe_c_request_tag, wcqe));
10155 spin_unlock_irqrestore(&phba->hbalock, iflags);
10157 if (unlikely(!cmdiocbq)) {
10158 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10159 "0386 ELS complete with no corresponding "
10160 "cmdiocb: iotag (%d)\n",
10161 bf_get(lpfc_wcqe_c_request_tag, wcqe));
10162 lpfc_sli_release_iocbq(phba, irspiocbq);
10166 /* Fake the irspiocbq and copy necessary response information */
10167 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
10173 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
10174 * @phba: Pointer to HBA context object.
10175 * @cqe: Pointer to mailbox completion queue entry.
10177 * This routine process a mailbox completion queue entry with asynchrous
10180 * Return: true if work posted to worker thread, otherwise false.
10183 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
10185 struct lpfc_cq_event *cq_event;
10186 unsigned long iflags;
10188 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10189 "0392 Async Event: word0:x%x, word1:x%x, "
10190 "word2:x%x, word3:x%x\n", mcqe->word0,
10191 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
10193 /* Allocate a new internal CQ_EVENT entry */
10194 cq_event = lpfc_sli4_cq_event_alloc(phba);
10196 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10197 "0394 Failed to allocate CQ_EVENT entry\n");
10201 /* Move the CQE into an asynchronous event entry */
10202 memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
10203 spin_lock_irqsave(&phba->hbalock, iflags);
10204 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
10205 /* Set the async event flag */
10206 phba->hba_flag |= ASYNC_EVENT;
10207 spin_unlock_irqrestore(&phba->hbalock, iflags);
10213 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
10214 * @phba: Pointer to HBA context object.
10215 * @cqe: Pointer to mailbox completion queue entry.
10217 * This routine process a mailbox completion queue entry with mailbox
10218 * completion event.
10220 * Return: true if work posted to worker thread, otherwise false.
10223 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
10225 uint32_t mcqe_status;
10226 MAILBOX_t *mbox, *pmbox;
10227 struct lpfc_mqe *mqe;
10228 struct lpfc_vport *vport;
10229 struct lpfc_nodelist *ndlp;
10230 struct lpfc_dmabuf *mp;
10231 unsigned long iflags;
10233 bool workposted = false;
10236 /* If not a mailbox complete MCQE, out by checking mailbox consume */
10237 if (!bf_get(lpfc_trailer_completed, mcqe))
10238 goto out_no_mqe_complete;
10240 /* Get the reference to the active mbox command */
10241 spin_lock_irqsave(&phba->hbalock, iflags);
10242 pmb = phba->sli.mbox_active;
10243 if (unlikely(!pmb)) {
10244 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
10245 "1832 No pending MBOX command to handle\n");
10246 spin_unlock_irqrestore(&phba->hbalock, iflags);
10247 goto out_no_mqe_complete;
10249 spin_unlock_irqrestore(&phba->hbalock, iflags);
10251 pmbox = (MAILBOX_t *)&pmb->u.mqe;
10253 vport = pmb->vport;
10255 /* Reset heartbeat timer */
10256 phba->last_completion_time = jiffies;
10257 del_timer(&phba->sli.mbox_tmo);
10259 /* Move mbox data to caller's mailbox region, do endian swapping */
10260 if (pmb->mbox_cmpl && mbox)
10261 lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
10262 /* Set the mailbox status with SLI4 range 0x4000 */
10263 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
10264 if (mcqe_status != MB_CQE_STATUS_SUCCESS)
10265 bf_set(lpfc_mqe_status, mqe,
10266 (LPFC_MBX_ERROR_RANGE | mcqe_status));
10268 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
10269 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
10270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
10271 "MBOX dflt rpi: status:x%x rpi:x%x",
10273 pmbox->un.varWords[0], 0);
10274 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
10275 mp = (struct lpfc_dmabuf *)(pmb->context1);
10276 ndlp = (struct lpfc_nodelist *)pmb->context2;
10277 /* Reg_LOGIN of dflt RPI was successful. Now lets get
10278 * RID of the PPI using the same mbox buffer.
10280 lpfc_unreg_login(phba, vport->vpi,
10281 pmbox->un.varWords[0], pmb);
10282 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
10283 pmb->context1 = mp;
10284 pmb->context2 = ndlp;
10285 pmb->vport = vport;
10286 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
10287 if (rc != MBX_BUSY)
10288 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
10289 LOG_SLI, "0385 rc should "
10290 "have been MBX_BUSY\n");
10291 if (rc != MBX_NOT_FINISHED)
10292 goto send_current_mbox;
10295 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
10296 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
10297 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
10299 /* There is mailbox completion work to do */
10300 spin_lock_irqsave(&phba->hbalock, iflags);
10301 __lpfc_mbox_cmpl_put(phba, pmb);
10302 phba->work_ha |= HA_MBATT;
10303 spin_unlock_irqrestore(&phba->hbalock, iflags);
10307 spin_lock_irqsave(&phba->hbalock, iflags);
10308 /* Release the mailbox command posting token */
10309 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10310 /* Setting active mailbox pointer need to be in sync to flag clear */
10311 phba->sli.mbox_active = NULL;
10312 spin_unlock_irqrestore(&phba->hbalock, iflags);
10313 /* Wake up worker thread to post the next pending mailbox command */
10314 lpfc_worker_wake_up(phba);
10315 out_no_mqe_complete:
10316 if (bf_get(lpfc_trailer_consumed, mcqe))
10317 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
10322 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
10323 * @phba: Pointer to HBA context object.
10324 * @cqe: Pointer to mailbox completion queue entry.
10326 * This routine process a mailbox completion queue entry, it invokes the
10327 * proper mailbox complete handling or asynchrous event handling routine
10328 * according to the MCQE's async bit.
10330 * Return: true if work posted to worker thread, otherwise false.
10333 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
10335 struct lpfc_mcqe mcqe;
10338 /* Copy the mailbox MCQE and convert endian order as needed */
10339 lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
10341 /* Invoke the proper event handling routine */
10342 if (!bf_get(lpfc_trailer_async, &mcqe))
10343 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
10345 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
10350 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
10351 * @phba: Pointer to HBA context object.
10352 * @wcqe: Pointer to work-queue completion queue entry.
10354 * This routine handles an ELS work-queue completion event.
10356 * Return: true if work posted to worker thread, otherwise false.
10359 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
10360 struct lpfc_wcqe_complete *wcqe)
10362 struct lpfc_iocbq *irspiocbq;
10363 unsigned long iflags;
10364 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
10366 /* Get an irspiocbq for later ELS response processing use */
10367 irspiocbq = lpfc_sli_get_iocbq(phba);
10369 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10370 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
10371 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
10372 pring->txq_cnt, phba->iocb_cnt,
10373 phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
10374 phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
10378 /* Save off the slow-path queue event for work thread to process */
10379 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
10380 spin_lock_irqsave(&phba->hbalock, iflags);
10381 list_add_tail(&irspiocbq->cq_event.list,
10382 &phba->sli4_hba.sp_queue_event);
10383 phba->hba_flag |= HBA_SP_QUEUE_EVT;
10384 spin_unlock_irqrestore(&phba->hbalock, iflags);
10390 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
10391 * @phba: Pointer to HBA context object.
10392 * @wcqe: Pointer to work-queue completion queue entry.
10394 * This routine handles slow-path WQ entry comsumed event by invoking the
10395 * proper WQ release routine to the slow-path WQ.
10398 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
10399 struct lpfc_wcqe_release *wcqe)
10401 /* Check for the slow-path ELS work queue */
10402 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
10403 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
10404 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
10406 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10407 "2579 Slow-path wqe consume event carries "
10408 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
10409 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
10410 phba->sli4_hba.els_wq->queue_id);
10414 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
10415 * @phba: Pointer to HBA context object.
10416 * @cq: Pointer to a WQ completion queue.
10417 * @wcqe: Pointer to work-queue completion queue entry.
10419 * This routine handles an XRI abort event.
10421 * Return: true if work posted to worker thread, otherwise false.
10424 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
10425 struct lpfc_queue *cq,
10426 struct sli4_wcqe_xri_aborted *wcqe)
10428 bool workposted = false;
10429 struct lpfc_cq_event *cq_event;
10430 unsigned long iflags;
10432 /* Allocate a new internal CQ_EVENT entry */
10433 cq_event = lpfc_sli4_cq_event_alloc(phba);
10435 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10436 "0602 Failed to allocate CQ_EVENT entry\n");
10440 /* Move the CQE into the proper xri abort event list */
10441 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
10442 switch (cq->subtype) {
10444 spin_lock_irqsave(&phba->hbalock, iflags);
10445 list_add_tail(&cq_event->list,
10446 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
10447 /* Set the fcp xri abort event flag */
10448 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
10449 spin_unlock_irqrestore(&phba->hbalock, iflags);
10453 spin_lock_irqsave(&phba->hbalock, iflags);
10454 list_add_tail(&cq_event->list,
10455 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
10456 /* Set the els xri abort event flag */
10457 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
10458 spin_unlock_irqrestore(&phba->hbalock, iflags);
10462 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10463 "0603 Invalid work queue CQE subtype (x%x)\n",
10465 workposted = false;
10472 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
10473 * @phba: Pointer to HBA context object.
10474 * @rcqe: Pointer to receive-queue completion queue entry.
10476 * This routine process a receive-queue completion queue entry.
10478 * Return: true if work posted to worker thread, otherwise false.
10481 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
10483 bool workposted = false;
10484 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
10485 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
10486 struct hbq_dmabuf *dma_buf;
10487 uint32_t status, rq_id;
10488 unsigned long iflags;
10490 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
10491 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
10493 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
10494 if (rq_id != hrq->queue_id)
10497 status = bf_get(lpfc_rcqe_status, rcqe);
10499 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
10500 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10501 "2537 Receive Frame Truncated!!\n");
10502 case FC_STATUS_RQ_SUCCESS:
10503 lpfc_sli4_rq_release(hrq, drq);
10504 spin_lock_irqsave(&phba->hbalock, iflags);
10505 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
10507 spin_unlock_irqrestore(&phba->hbalock, iflags);
10510 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
10511 /* save off the frame for the word thread to process */
10512 list_add_tail(&dma_buf->cq_event.list,
10513 &phba->sli4_hba.sp_queue_event);
10514 /* Frame received */
10515 phba->hba_flag |= HBA_SP_QUEUE_EVT;
10516 spin_unlock_irqrestore(&phba->hbalock, iflags);
10519 case FC_STATUS_INSUFF_BUF_NEED_BUF:
10520 case FC_STATUS_INSUFF_BUF_FRM_DISC:
10521 /* Post more buffers if possible */
10522 spin_lock_irqsave(&phba->hbalock, iflags);
10523 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
10524 spin_unlock_irqrestore(&phba->hbalock, iflags);
10533 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
10534 * @phba: Pointer to HBA context object.
10535 * @cq: Pointer to the completion queue.
10536 * @wcqe: Pointer to a completion queue entry.
10538 * This routine process a slow-path work-queue or receive queue completion queue
10541 * Return: true if work posted to worker thread, otherwise false.
10544 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
10545 struct lpfc_cqe *cqe)
10547 struct lpfc_cqe cqevt;
10548 bool workposted = false;
10550 /* Copy the work queue CQE and convert endian order if needed */
10551 lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
10553 /* Check and process for different type of WCQE and dispatch */
10554 switch (bf_get(lpfc_cqe_code, &cqevt)) {
10555 case CQE_CODE_COMPL_WQE:
10556 /* Process the WQ/RQ complete event */
10557 phba->last_completion_time = jiffies;
10558 workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
10559 (struct lpfc_wcqe_complete *)&cqevt);
10561 case CQE_CODE_RELEASE_WQE:
10562 /* Process the WQ release event */
10563 lpfc_sli4_sp_handle_rel_wcqe(phba,
10564 (struct lpfc_wcqe_release *)&cqevt);
10566 case CQE_CODE_XRI_ABORTED:
10567 /* Process the WQ XRI abort event */
10568 phba->last_completion_time = jiffies;
10569 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
10570 (struct sli4_wcqe_xri_aborted *)&cqevt);
10572 case CQE_CODE_RECEIVE:
10573 case CQE_CODE_RECEIVE_V1:
10574 /* Process the RQ event */
10575 phba->last_completion_time = jiffies;
10576 workposted = lpfc_sli4_sp_handle_rcqe(phba,
10577 (struct lpfc_rcqe *)&cqevt);
10580 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10581 "0388 Not a valid WCQE code: x%x\n",
10582 bf_get(lpfc_cqe_code, &cqevt));
10589 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
10590 * @phba: Pointer to HBA context object.
10591 * @eqe: Pointer to fast-path event queue entry.
10593 * This routine process a event queue entry from the slow-path event queue.
10594 * It will check the MajorCode and MinorCode to determine this is for a
10595 * completion event on a completion queue, if not, an error shall be logged
10596 * and just return. Otherwise, it will get to the corresponding completion
10597 * queue and process all the entries on that completion queue, rearm the
10598 * completion queue, and then return.
10602 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
10604 struct lpfc_queue *cq = NULL, *childq, *speq;
10605 struct lpfc_cqe *cqe;
10606 bool workposted = false;
10610 if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
10611 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10612 "0359 Not a valid slow-path completion "
10613 "event: majorcode=x%x, minorcode=x%x\n",
10614 bf_get_le32(lpfc_eqe_major_code, eqe),
10615 bf_get_le32(lpfc_eqe_minor_code, eqe));
10619 /* Get the reference to the corresponding CQ */
10620 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
10622 /* Search for completion queue pointer matching this cqid */
10623 speq = phba->sli4_hba.sp_eq;
10624 list_for_each_entry(childq, &speq->child_list, list) {
10625 if (childq->queue_id == cqid) {
10630 if (unlikely(!cq)) {
10631 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
10632 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10633 "0365 Slow-path CQ identifier "
10634 "(%d) does not exist\n", cqid);
10638 /* Process all the entries to the CQ */
10639 switch (cq->type) {
10641 while ((cqe = lpfc_sli4_cq_get(cq))) {
10642 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
10643 if (!(++ecount % LPFC_GET_QE_REL_INT))
10644 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
10648 while ((cqe = lpfc_sli4_cq_get(cq))) {
10649 if (cq->subtype == LPFC_FCP)
10650 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
10653 workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
10655 if (!(++ecount % LPFC_GET_QE_REL_INT))
10656 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
10660 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10661 "0370 Invalid completion queue type (%d)\n",
10666 /* Catch the no cq entry condition, log an error */
10667 if (unlikely(ecount == 0))
10668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10669 "0371 No entry from the CQ: identifier "
10670 "(x%x), type (%d)\n", cq->queue_id, cq->type);
10672 /* In any case, flash and re-arm the RCQ */
10673 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
10675 /* wake up worker thread if there are works to be done */
10677 lpfc_worker_wake_up(phba);
10681 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
10682 * @eqe: Pointer to fast-path completion queue entry.
10684 * This routine process a fast-path work queue completion entry from fast-path
10685 * event queue for FCP command response completion.
10688 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
10689 struct lpfc_wcqe_complete *wcqe)
10691 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
10692 struct lpfc_iocbq *cmdiocbq;
10693 struct lpfc_iocbq irspiocbq;
10694 unsigned long iflags;
10696 spin_lock_irqsave(&phba->hbalock, iflags);
10697 pring->stats.iocb_event++;
10698 spin_unlock_irqrestore(&phba->hbalock, iflags);
10700 /* Check for response status */
10701 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
10702 /* If resource errors reported from HBA, reduce queue
10703 * depth of the SCSI device.
10705 if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
10706 IOSTAT_LOCAL_REJECT) &&
10707 (wcqe->parameter == IOERR_NO_RESOURCES)) {
10708 phba->lpfc_rampdown_queue_depth(phba);
10710 /* Log the error status */
10711 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10712 "0373 FCP complete error: status=x%x, "
10713 "hw_status=x%x, total_data_specified=%d, "
10714 "parameter=x%x, word3=x%x\n",
10715 bf_get(lpfc_wcqe_c_status, wcqe),
10716 bf_get(lpfc_wcqe_c_hw_status, wcqe),
10717 wcqe->total_data_placed, wcqe->parameter,
10721 /* Look up the FCP command IOCB and create pseudo response IOCB */
10722 spin_lock_irqsave(&phba->hbalock, iflags);
10723 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
10724 bf_get(lpfc_wcqe_c_request_tag, wcqe));
10725 spin_unlock_irqrestore(&phba->hbalock, iflags);
10726 if (unlikely(!cmdiocbq)) {
10727 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10728 "0374 FCP complete with no corresponding "
10729 "cmdiocb: iotag (%d)\n",
10730 bf_get(lpfc_wcqe_c_request_tag, wcqe));
10733 if (unlikely(!cmdiocbq->iocb_cmpl)) {
10734 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10735 "0375 FCP cmdiocb not callback function "
10737 bf_get(lpfc_wcqe_c_request_tag, wcqe));
10741 /* Fake the irspiocb and copy necessary response information */
10742 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
10744 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
10745 spin_lock_irqsave(&phba->hbalock, iflags);
10746 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
10747 spin_unlock_irqrestore(&phba->hbalock, iflags);
10750 /* Pass the cmd_iocb and the rsp state to the upper layer */
10751 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
10755 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
10756 * @phba: Pointer to HBA context object.
10757 * @cq: Pointer to completion queue.
10758 * @wcqe: Pointer to work-queue completion queue entry.
10760 * This routine handles an fast-path WQ entry comsumed event by invoking the
10761 * proper WQ release routine to the slow-path WQ.
10764 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
10765 struct lpfc_wcqe_release *wcqe)
10767 struct lpfc_queue *childwq;
10768 bool wqid_matched = false;
10771 /* Check for fast-path FCP work queue release */
10772 fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
10773 list_for_each_entry(childwq, &cq->child_list, list) {
10774 if (childwq->queue_id == fcp_wqid) {
10775 lpfc_sli4_wq_release(childwq,
10776 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
10777 wqid_matched = true;
10781 /* Report warning log message if no match found */
10782 if (wqid_matched != true)
10783 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10784 "2580 Fast-path wqe consume event carries "
10785 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
10789 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
10790 * @cq: Pointer to the completion queue.
10791 * @eqe: Pointer to fast-path completion queue entry.
10793 * This routine process a fast-path work queue completion entry from fast-path
10794 * event queue for FCP command response completion.
10797 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
10798 struct lpfc_cqe *cqe)
10800 struct lpfc_wcqe_release wcqe;
10801 bool workposted = false;
10803 /* Copy the work queue CQE and convert endian order if needed */
10804 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
10806 /* Check and process for different type of WCQE and dispatch */
10807 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
10808 case CQE_CODE_COMPL_WQE:
10809 /* Process the WQ complete event */
10810 phba->last_completion_time = jiffies;
10811 lpfc_sli4_fp_handle_fcp_wcqe(phba,
10812 (struct lpfc_wcqe_complete *)&wcqe);
10814 case CQE_CODE_RELEASE_WQE:
10815 /* Process the WQ release event */
10816 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
10817 (struct lpfc_wcqe_release *)&wcqe);
10819 case CQE_CODE_XRI_ABORTED:
10820 /* Process the WQ XRI abort event */
10821 phba->last_completion_time = jiffies;
10822 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
10823 (struct sli4_wcqe_xri_aborted *)&wcqe);
10826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10827 "0144 Not a valid WCQE code: x%x\n",
10828 bf_get(lpfc_wcqe_c_code, &wcqe));
10835 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
10836 * @phba: Pointer to HBA context object.
10837 * @eqe: Pointer to fast-path event queue entry.
10839 * This routine process a event queue entry from the fast-path event queue.
10840 * It will check the MajorCode and MinorCode to determine this is for a
10841 * completion event on a completion queue, if not, an error shall be logged
10842 * and just return. Otherwise, it will get to the corresponding completion
10843 * queue and process all the entries on the completion queue, rearm the
10844 * completion queue, and then return.
10847 lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
10848 uint32_t fcp_cqidx)
10850 struct lpfc_queue *cq;
10851 struct lpfc_cqe *cqe;
10852 bool workposted = false;
10856 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
10857 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10858 "0366 Not a valid fast-path completion "
10859 "event: majorcode=x%x, minorcode=x%x\n",
10860 bf_get_le32(lpfc_eqe_major_code, eqe),
10861 bf_get_le32(lpfc_eqe_minor_code, eqe));
10865 cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
10866 if (unlikely(!cq)) {
10867 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
10868 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10869 "0367 Fast-path completion queue "
10870 "does not exist\n");
10874 /* Get the reference to the corresponding CQ */
10875 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
10876 if (unlikely(cqid != cq->queue_id)) {
10877 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10878 "0368 Miss-matched fast-path completion "
10879 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
10880 cqid, cq->queue_id);
10884 /* Process all the entries to the CQ */
10885 while ((cqe = lpfc_sli4_cq_get(cq))) {
10886 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
10887 if (!(++ecount % LPFC_GET_QE_REL_INT))
10888 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
10891 /* Catch the no cq entry condition */
10892 if (unlikely(ecount == 0))
10893 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10894 "0369 No entry from fast-path completion "
10895 "queue fcpcqid=%d\n", cq->queue_id);
10897 /* In any case, flash and re-arm the CQ */
10898 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
10900 /* wake up worker thread if there are works to be done */
10902 lpfc_worker_wake_up(phba);
10906 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
10908 struct lpfc_eqe *eqe;
10910 /* walk all the EQ entries and drop on the floor */
10911 while ((eqe = lpfc_sli4_eq_get(eq)))
10914 /* Clear and re-arm the EQ */
10915 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
10919 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
10920 * @irq: Interrupt number.
10921 * @dev_id: The device context pointer.
10923 * This function is directly called from the PCI layer as an interrupt
10924 * service routine when device with SLI-4 interface spec is enabled with
10925 * MSI-X multi-message interrupt mode and there are slow-path events in
10926 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10927 * interrupt mode, this function is called as part of the device-level
10928 * interrupt handler. When the PCI slot is in error recovery or the HBA is
10929 * undergoing initialization, the interrupt handler will not process the
10930 * interrupt. The link attention and ELS ring attention events are handled
10931 * by the worker thread. The interrupt handler signals the worker thread
10932 * and returns for these events. This function is called without any lock
10933 * held. It gets the hbalock to access and update SLI data structures.
10935 * This function returns IRQ_HANDLED when interrupt is handled else it
10936 * returns IRQ_NONE.
10939 lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
10941 struct lpfc_hba *phba;
10942 struct lpfc_queue *speq;
10943 struct lpfc_eqe *eqe;
10944 unsigned long iflag;
10948 * Get the driver's phba structure from the dev_id
10950 phba = (struct lpfc_hba *)dev_id;
10952 if (unlikely(!phba))
10955 /* Get to the EQ struct associated with this vector */
10956 speq = phba->sli4_hba.sp_eq;
10958 /* Check device state for handling interrupt */
10959 if (unlikely(lpfc_intr_state_check(phba))) {
10960 /* Check again for link_state with lock held */
10961 spin_lock_irqsave(&phba->hbalock, iflag);
10962 if (phba->link_state < LPFC_LINK_DOWN)
10963 /* Flush, clear interrupt, and rearm the EQ */
10964 lpfc_sli4_eq_flush(phba, speq);
10965 spin_unlock_irqrestore(&phba->hbalock, iflag);
10970 * Process all the event on FCP slow-path EQ
10972 while ((eqe = lpfc_sli4_eq_get(speq))) {
10973 lpfc_sli4_sp_handle_eqe(phba, eqe);
10974 if (!(++ecount % LPFC_GET_QE_REL_INT))
10975 lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
10978 /* Always clear and re-arm the slow-path EQ */
10979 lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
10981 /* Catch the no cq entry condition */
10982 if (unlikely(ecount == 0)) {
10983 if (phba->intr_type == MSIX)
10984 /* MSI-X treated interrupt served as no EQ share INT */
10985 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10986 "0357 MSI-X interrupt with no EQE\n");
10988 /* Non MSI-X treated on interrupt as EQ share INT */
10992 return IRQ_HANDLED;
10993 } /* lpfc_sli4_sp_intr_handler */
10996 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
10997 * @irq: Interrupt number.
10998 * @dev_id: The device context pointer.
11000 * This function is directly called from the PCI layer as an interrupt
11001 * service routine when device with SLI-4 interface spec is enabled with
11002 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11003 * ring event in the HBA. However, when the device is enabled with either
11004 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11005 * device-level interrupt handler. When the PCI slot is in error recovery
11006 * or the HBA is undergoing initialization, the interrupt handler will not
11007 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11008 * the intrrupt context. This function is called without any lock held.
11009 * It gets the hbalock to access and update SLI data structures. Note that,
11010 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11011 * equal to that of FCP CQ index.
11013 * This function returns IRQ_HANDLED when interrupt is handled else it
11014 * returns IRQ_NONE.
11017 lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
11019 struct lpfc_hba *phba;
11020 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
11021 struct lpfc_queue *fpeq;
11022 struct lpfc_eqe *eqe;
11023 unsigned long iflag;
11025 uint32_t fcp_eqidx;
11027 /* Get the driver's phba structure from the dev_id */
11028 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
11029 phba = fcp_eq_hdl->phba;
11030 fcp_eqidx = fcp_eq_hdl->idx;
11032 if (unlikely(!phba))
11035 /* Get to the EQ struct associated with this vector */
11036 fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
11038 /* Check device state for handling interrupt */
11039 if (unlikely(lpfc_intr_state_check(phba))) {
11040 /* Check again for link_state with lock held */
11041 spin_lock_irqsave(&phba->hbalock, iflag);
11042 if (phba->link_state < LPFC_LINK_DOWN)
11043 /* Flush, clear interrupt, and rearm the EQ */
11044 lpfc_sli4_eq_flush(phba, fpeq);
11045 spin_unlock_irqrestore(&phba->hbalock, iflag);
11050 * Process all the event on FCP fast-path EQ
11052 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
11053 lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
11054 if (!(++ecount % LPFC_GET_QE_REL_INT))
11055 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
11058 /* Always clear and re-arm the fast-path EQ */
11059 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
11061 if (unlikely(ecount == 0)) {
11062 if (phba->intr_type == MSIX)
11063 /* MSI-X treated interrupt served as no EQ share INT */
11064 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11065 "0358 MSI-X interrupt with no EQE\n");
11067 /* Non MSI-X treated on interrupt as EQ share INT */
11071 return IRQ_HANDLED;
11072 } /* lpfc_sli4_fp_intr_handler */
11075 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11076 * @irq: Interrupt number.
11077 * @dev_id: The device context pointer.
11079 * This function is the device-level interrupt handler to device with SLI-4
11080 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11081 * interrupt mode is enabled and there is an event in the HBA which requires
11082 * driver attention. This function invokes the slow-path interrupt attention
11083 * handling function and fast-path interrupt attention handling function in
11084 * turn to process the relevant HBA attention events. This function is called
11085 * without any lock held. It gets the hbalock to access and update SLI data
11088 * This function returns IRQ_HANDLED when interrupt is handled, else it
11089 * returns IRQ_NONE.
11092 lpfc_sli4_intr_handler(int irq, void *dev_id)
11094 struct lpfc_hba *phba;
11095 irqreturn_t sp_irq_rc, fp_irq_rc;
11096 bool fp_handled = false;
11097 uint32_t fcp_eqidx;
11099 /* Get the driver's phba structure from the dev_id */
11100 phba = (struct lpfc_hba *)dev_id;
11102 if (unlikely(!phba))
11106 * Invokes slow-path host attention interrupt handling as appropriate.
11108 sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
11111 * Invoke fast-path host attention interrupt handling as appropriate.
11113 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
11114 fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
11115 &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
11116 if (fp_irq_rc == IRQ_HANDLED)
11117 fp_handled |= true;
11120 return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
11121 } /* lpfc_sli4_intr_handler */
11124 * lpfc_sli4_queue_free - free a queue structure and associated memory
11125 * @queue: The queue structure to free.
11127 * This function frees a queue structure and the DMAable memory used for
11128 * the host resident queue. This function must be called after destroying the
11129 * queue on the HBA.
11132 lpfc_sli4_queue_free(struct lpfc_queue *queue)
11134 struct lpfc_dmabuf *dmabuf;
11139 while (!list_empty(&queue->page_list)) {
11140 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
11142 dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
11143 dmabuf->virt, dmabuf->phys);
11151 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
11152 * @phba: The HBA that this queue is being created on.
11153 * @entry_size: The size of each queue entry for this queue.
11154 * @entry count: The number of entries that this queue will handle.
11156 * This function allocates a queue structure and the DMAable memory used for
11157 * the host resident queue. This function must be called before creating the
11158 * queue on the HBA.
11160 struct lpfc_queue *
11161 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
11162 uint32_t entry_count)
11164 struct lpfc_queue *queue;
11165 struct lpfc_dmabuf *dmabuf;
11166 int x, total_qe_count;
11168 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
11170 if (!phba->sli4_hba.pc_sli4_params.supported)
11171 hw_page_size = SLI4_PAGE_SIZE;
11173 queue = kzalloc(sizeof(struct lpfc_queue) +
11174 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
11177 queue->page_count = (ALIGN(entry_size * entry_count,
11178 hw_page_size))/hw_page_size;
11179 INIT_LIST_HEAD(&queue->list);
11180 INIT_LIST_HEAD(&queue->page_list);
11181 INIT_LIST_HEAD(&queue->child_list);
11182 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
11183 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
11186 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11187 hw_page_size, &dmabuf->phys,
11189 if (!dmabuf->virt) {
11193 memset(dmabuf->virt, 0, hw_page_size);
11194 dmabuf->buffer_tag = x;
11195 list_add_tail(&dmabuf->list, &queue->page_list);
11196 /* initialize queue's entry array */
11197 dma_pointer = dmabuf->virt;
11198 for (; total_qe_count < entry_count &&
11199 dma_pointer < (hw_page_size + dmabuf->virt);
11200 total_qe_count++, dma_pointer += entry_size) {
11201 queue->qe[total_qe_count].address = dma_pointer;
11204 queue->entry_size = entry_size;
11205 queue->entry_count = entry_count;
11206 queue->phba = phba;
11210 lpfc_sli4_queue_free(queue);
11215 * lpfc_eq_create - Create an Event Queue on the HBA
11216 * @phba: HBA structure that indicates port to create a queue on.
11217 * @eq: The queue structure to use to create the event queue.
11218 * @imax: The maximum interrupt per second limit.
11220 * This function creates an event queue, as detailed in @eq, on a port,
11221 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
11223 * The @phba struct is used to send mailbox command to HBA. The @eq struct
11224 * is used to get the entry count and entry size that are necessary to
11225 * determine the number of pages to allocate and use for this queue. This
11226 * function will send the EQ_CREATE mailbox command to the HBA to setup the
11227 * event queue. This function is asynchronous and will wait for the mailbox
11228 * command to finish before continuing.
11230 * On success this function will return a zero. If unable to allocate enough
11231 * memory this function will return -ENOMEM. If the queue create mailbox command
11232 * fails this function will return -ENXIO.
11235 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
11237 struct lpfc_mbx_eq_create *eq_create;
11238 LPFC_MBOXQ_t *mbox;
11239 int rc, length, status = 0;
11240 struct lpfc_dmabuf *dmabuf;
11241 uint32_t shdr_status, shdr_add_status;
11242 union lpfc_sli4_cfg_shdr *shdr;
11244 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
11246 if (!phba->sli4_hba.pc_sli4_params.supported)
11247 hw_page_size = SLI4_PAGE_SIZE;
11249 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11252 length = (sizeof(struct lpfc_mbx_eq_create) -
11253 sizeof(struct lpfc_sli4_cfg_mhdr));
11254 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
11255 LPFC_MBOX_OPCODE_EQ_CREATE,
11256 length, LPFC_SLI4_MBX_EMBED);
11257 eq_create = &mbox->u.mqe.un.eq_create;
11258 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
11260 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
11262 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
11263 /* Calculate delay multiper from maximum interrupt per second */
11264 dmult = LPFC_DMULT_CONST/imax - 1;
11265 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
11267 switch (eq->entry_count) {
11269 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11270 "0360 Unsupported EQ count. (%d)\n",
11272 if (eq->entry_count < 256)
11274 /* otherwise default to smallest count (drop through) */
11276 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
11280 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
11284 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
11288 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
11292 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
11296 list_for_each_entry(dmabuf, &eq->page_list, list) {
11297 memset(dmabuf->virt, 0, hw_page_size);
11298 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
11299 putPaddrLow(dmabuf->phys);
11300 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
11301 putPaddrHigh(dmabuf->phys);
11303 mbox->vport = phba->pport;
11304 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
11305 mbox->context1 = NULL;
11306 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11307 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
11308 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11309 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11310 if (shdr_status || shdr_add_status || rc) {
11311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11312 "2500 EQ_CREATE mailbox failed with "
11313 "status x%x add_status x%x, mbx status x%x\n",
11314 shdr_status, shdr_add_status, rc);
11317 eq->type = LPFC_EQ;
11318 eq->subtype = LPFC_NONE;
11319 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
11320 if (eq->queue_id == 0xFFFF)
11322 eq->host_index = 0;
11325 mempool_free(mbox, phba->mbox_mem_pool);
11330 * lpfc_cq_create - Create a Completion Queue on the HBA
11331 * @phba: HBA structure that indicates port to create a queue on.
11332 * @cq: The queue structure to use to create the completion queue.
11333 * @eq: The event queue to bind this completion queue to.
11335 * This function creates a completion queue, as detailed in @wq, on a port,
11336 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
11338 * The @phba struct is used to send mailbox command to HBA. The @cq struct
11339 * is used to get the entry count and entry size that are necessary to
11340 * determine the number of pages to allocate and use for this queue. The @eq
11341 * is used to indicate which event queue to bind this completion queue to. This
11342 * function will send the CQ_CREATE mailbox command to the HBA to setup the
11343 * completion queue. This function is asynchronous and will wait for the mailbox
11344 * command to finish before continuing.
11346 * On success this function will return a zero. If unable to allocate enough
11347 * memory this function will return -ENOMEM. If the queue create mailbox command
11348 * fails this function will return -ENXIO.
11351 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
11352 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
11354 struct lpfc_mbx_cq_create *cq_create;
11355 struct lpfc_dmabuf *dmabuf;
11356 LPFC_MBOXQ_t *mbox;
11357 int rc, length, status = 0;
11358 uint32_t shdr_status, shdr_add_status;
11359 union lpfc_sli4_cfg_shdr *shdr;
11360 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
11362 if (!phba->sli4_hba.pc_sli4_params.supported)
11363 hw_page_size = SLI4_PAGE_SIZE;
11365 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11368 length = (sizeof(struct lpfc_mbx_cq_create) -
11369 sizeof(struct lpfc_sli4_cfg_mhdr));
11370 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
11371 LPFC_MBOX_OPCODE_CQ_CREATE,
11372 length, LPFC_SLI4_MBX_EMBED);
11373 cq_create = &mbox->u.mqe.un.cq_create;
11374 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
11375 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
11377 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
11378 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
11379 bf_set(lpfc_mbox_hdr_version, &shdr->request,
11380 phba->sli4_hba.pc_sli4_params.cqv);
11381 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
11382 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
11383 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
11384 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
11387 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
11390 switch (cq->entry_count) {
11392 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11393 "0361 Unsupported CQ count. (%d)\n",
11395 if (cq->entry_count < 256)
11397 /* otherwise default to smallest count (drop through) */
11399 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
11403 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
11407 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
11411 list_for_each_entry(dmabuf, &cq->page_list, list) {
11412 memset(dmabuf->virt, 0, hw_page_size);
11413 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
11414 putPaddrLow(dmabuf->phys);
11415 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
11416 putPaddrHigh(dmabuf->phys);
11418 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11420 /* The IOCTL status is embedded in the mailbox subheader. */
11421 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11422 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11423 if (shdr_status || shdr_add_status || rc) {
11424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11425 "2501 CQ_CREATE mailbox failed with "
11426 "status x%x add_status x%x, mbx status x%x\n",
11427 shdr_status, shdr_add_status, rc);
11431 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
11432 if (cq->queue_id == 0xFFFF) {
11436 /* link the cq onto the parent eq child list */
11437 list_add_tail(&cq->list, &eq->child_list);
11438 /* Set up completion queue's type and subtype */
11440 cq->subtype = subtype;
11441 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
11442 cq->assoc_qid = eq->queue_id;
11443 cq->host_index = 0;
11447 mempool_free(mbox, phba->mbox_mem_pool);
11452 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
11453 * @phba: HBA structure that indicates port to create a queue on.
11454 * @mq: The queue structure to use to create the mailbox queue.
11455 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
11456 * @cq: The completion queue to associate with this cq.
11458 * This function provides failback (fb) functionality when the
11459 * mq_create_ext fails on older FW generations. It's purpose is identical
11460 * to mq_create_ext otherwise.
11462 * This routine cannot fail as all attributes were previously accessed and
11463 * initialized in mq_create_ext.
11466 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
11467 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
11469 struct lpfc_mbx_mq_create *mq_create;
11470 struct lpfc_dmabuf *dmabuf;
11473 length = (sizeof(struct lpfc_mbx_mq_create) -
11474 sizeof(struct lpfc_sli4_cfg_mhdr));
11475 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
11476 LPFC_MBOX_OPCODE_MQ_CREATE,
11477 length, LPFC_SLI4_MBX_EMBED);
11478 mq_create = &mbox->u.mqe.un.mq_create;
11479 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
11481 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
11483 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
11484 switch (mq->entry_count) {
11486 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
11487 LPFC_MQ_RING_SIZE_16);
11490 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
11491 LPFC_MQ_RING_SIZE_32);
11494 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
11495 LPFC_MQ_RING_SIZE_64);
11498 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
11499 LPFC_MQ_RING_SIZE_128);
11502 list_for_each_entry(dmabuf, &mq->page_list, list) {
11503 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
11504 putPaddrLow(dmabuf->phys);
11505 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
11506 putPaddrHigh(dmabuf->phys);
11511 * lpfc_mq_create - Create a mailbox Queue on the HBA
11512 * @phba: HBA structure that indicates port to create a queue on.
11513 * @mq: The queue structure to use to create the mailbox queue.
11514 * @cq: The completion queue to associate with this cq.
11515 * @subtype: The queue's subtype.
11517 * This function creates a mailbox queue, as detailed in @mq, on a port,
11518 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
11520 * The @phba struct is used to send mailbox command to HBA. The @cq struct
11521 * is used to get the entry count and entry size that are necessary to
11522 * determine the number of pages to allocate and use for this queue. This
11523 * function will send the MQ_CREATE mailbox command to the HBA to setup the
11524 * mailbox queue. This function is asynchronous and will wait for the mailbox
11525 * command to finish before continuing.
11527 * On success this function will return a zero. If unable to allocate enough
11528 * memory this function will return -ENOMEM. If the queue create mailbox command
11529 * fails this function will return -ENXIO.
11532 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
11533 struct lpfc_queue *cq, uint32_t subtype)
11535 struct lpfc_mbx_mq_create *mq_create;
11536 struct lpfc_mbx_mq_create_ext *mq_create_ext;
11537 struct lpfc_dmabuf *dmabuf;
11538 LPFC_MBOXQ_t *mbox;
11539 int rc, length, status = 0;
11540 uint32_t shdr_status, shdr_add_status;
11541 union lpfc_sli4_cfg_shdr *shdr;
11542 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
11544 if (!phba->sli4_hba.pc_sli4_params.supported)
11545 hw_page_size = SLI4_PAGE_SIZE;
11547 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11550 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
11551 sizeof(struct lpfc_sli4_cfg_mhdr));
11552 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
11553 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
11554 length, LPFC_SLI4_MBX_EMBED);
11556 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
11557 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
11558 bf_set(lpfc_mbx_mq_create_ext_num_pages,
11559 &mq_create_ext->u.request, mq->page_count);
11560 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
11561 &mq_create_ext->u.request, 1);
11562 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
11563 &mq_create_ext->u.request, 1);
11564 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
11565 &mq_create_ext->u.request, 1);
11566 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
11567 &mq_create_ext->u.request, 1);
11568 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
11569 &mq_create_ext->u.request, 1);
11570 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
11571 bf_set(lpfc_mbox_hdr_version, &shdr->request,
11572 phba->sli4_hba.pc_sli4_params.mqv);
11573 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
11574 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
11577 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
11579 switch (mq->entry_count) {
11581 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11582 "0362 Unsupported MQ count. (%d)\n",
11584 if (mq->entry_count < 16)
11586 /* otherwise default to smallest count (drop through) */
11588 bf_set(lpfc_mq_context_ring_size,
11589 &mq_create_ext->u.request.context,
11590 LPFC_MQ_RING_SIZE_16);
11593 bf_set(lpfc_mq_context_ring_size,
11594 &mq_create_ext->u.request.context,
11595 LPFC_MQ_RING_SIZE_32);
11598 bf_set(lpfc_mq_context_ring_size,
11599 &mq_create_ext->u.request.context,
11600 LPFC_MQ_RING_SIZE_64);
11603 bf_set(lpfc_mq_context_ring_size,
11604 &mq_create_ext->u.request.context,
11605 LPFC_MQ_RING_SIZE_128);
11608 list_for_each_entry(dmabuf, &mq->page_list, list) {
11609 memset(dmabuf->virt, 0, hw_page_size);
11610 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
11611 putPaddrLow(dmabuf->phys);
11612 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
11613 putPaddrHigh(dmabuf->phys);
11615 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11616 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
11617 &mq_create_ext->u.response);
11618 if (rc != MBX_SUCCESS) {
11619 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11620 "2795 MQ_CREATE_EXT failed with "
11621 "status x%x. Failback to MQ_CREATE.\n",
11623 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
11624 mq_create = &mbox->u.mqe.un.mq_create;
11625 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11626 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
11627 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
11628 &mq_create->u.response);
11631 /* The IOCTL status is embedded in the mailbox subheader. */
11632 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11633 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11634 if (shdr_status || shdr_add_status || rc) {
11635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11636 "2502 MQ_CREATE mailbox failed with "
11637 "status x%x add_status x%x, mbx status x%x\n",
11638 shdr_status, shdr_add_status, rc);
11642 if (mq->queue_id == 0xFFFF) {
11646 mq->type = LPFC_MQ;
11647 mq->assoc_qid = cq->queue_id;
11648 mq->subtype = subtype;
11649 mq->host_index = 0;
11652 /* link the mq onto the parent cq child list */
11653 list_add_tail(&mq->list, &cq->child_list);
11655 mempool_free(mbox, phba->mbox_mem_pool);
11660 * lpfc_wq_create - Create a Work Queue on the HBA
11661 * @phba: HBA structure that indicates port to create a queue on.
11662 * @wq: The queue structure to use to create the work queue.
11663 * @cq: The completion queue to bind this work queue to.
11664 * @subtype: The subtype of the work queue indicating its functionality.
11666 * This function creates a work queue, as detailed in @wq, on a port, described
11667 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
11669 * The @phba struct is used to send mailbox command to HBA. The @wq struct
11670 * is used to get the entry count and entry size that are necessary to
11671 * determine the number of pages to allocate and use for this queue. The @cq
11672 * is used to indicate which completion queue to bind this work queue to. This
11673 * function will send the WQ_CREATE mailbox command to the HBA to setup the
11674 * work queue. This function is asynchronous and will wait for the mailbox
11675 * command to finish before continuing.
11677 * On success this function will return a zero. If unable to allocate enough
11678 * memory this function will return -ENOMEM. If the queue create mailbox command
11679 * fails this function will return -ENXIO.
11682 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
11683 struct lpfc_queue *cq, uint32_t subtype)
11685 struct lpfc_mbx_wq_create *wq_create;
11686 struct lpfc_dmabuf *dmabuf;
11687 LPFC_MBOXQ_t *mbox;
11688 int rc, length, status = 0;
11689 uint32_t shdr_status, shdr_add_status;
11690 union lpfc_sli4_cfg_shdr *shdr;
11691 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
11692 struct dma_address *page;
11694 if (!phba->sli4_hba.pc_sli4_params.supported)
11695 hw_page_size = SLI4_PAGE_SIZE;
11697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11700 length = (sizeof(struct lpfc_mbx_wq_create) -
11701 sizeof(struct lpfc_sli4_cfg_mhdr));
11702 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
11703 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
11704 length, LPFC_SLI4_MBX_EMBED);
11705 wq_create = &mbox->u.mqe.un.wq_create;
11706 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
11707 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
11709 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
11711 bf_set(lpfc_mbox_hdr_version, &shdr->request,
11712 phba->sli4_hba.pc_sli4_params.wqv);
11713 if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
11714 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
11716 switch (wq->entry_size) {
11719 bf_set(lpfc_mbx_wq_create_wqe_size,
11720 &wq_create->u.request_1,
11721 LPFC_WQ_WQE_SIZE_64);
11724 bf_set(lpfc_mbx_wq_create_wqe_size,
11725 &wq_create->u.request_1,
11726 LPFC_WQ_WQE_SIZE_128);
11729 bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
11730 (PAGE_SIZE/SLI4_PAGE_SIZE));
11731 page = wq_create->u.request_1.page;
11733 page = wq_create->u.request.page;
11735 list_for_each_entry(dmabuf, &wq->page_list, list) {
11736 memset(dmabuf->virt, 0, hw_page_size);
11737 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
11738 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
11740 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11741 /* The IOCTL status is embedded in the mailbox subheader. */
11742 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11743 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11744 if (shdr_status || shdr_add_status || rc) {
11745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11746 "2503 WQ_CREATE mailbox failed with "
11747 "status x%x add_status x%x, mbx status x%x\n",
11748 shdr_status, shdr_add_status, rc);
11752 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
11753 if (wq->queue_id == 0xFFFF) {
11757 wq->type = LPFC_WQ;
11758 wq->assoc_qid = cq->queue_id;
11759 wq->subtype = subtype;
11760 wq->host_index = 0;
11763 /* link the wq onto the parent cq child list */
11764 list_add_tail(&wq->list, &cq->child_list);
11766 mempool_free(mbox, phba->mbox_mem_pool);
11771 * lpfc_rq_create - Create a Receive Queue on the HBA
11772 * @phba: HBA structure that indicates port to create a queue on.
11773 * @hrq: The queue structure to use to create the header receive queue.
11774 * @drq: The queue structure to use to create the data receive queue.
11775 * @cq: The completion queue to bind this work queue to.
11777 * This function creates a receive buffer queue pair , as detailed in @hrq and
11778 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
11781 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
11782 * struct is used to get the entry count that is necessary to determine the
11783 * number of pages to use for this queue. The @cq is used to indicate which
11784 * completion queue to bind received buffers that are posted to these queues to.
11785 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
11786 * receive queue pair. This function is asynchronous and will wait for the
11787 * mailbox command to finish before continuing.
11789 * On success this function will return a zero. If unable to allocate enough
11790 * memory this function will return -ENOMEM. If the queue create mailbox command
11791 * fails this function will return -ENXIO.
11794 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
11795 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
11797 struct lpfc_mbx_rq_create *rq_create;
11798 struct lpfc_dmabuf *dmabuf;
11799 LPFC_MBOXQ_t *mbox;
11800 int rc, length, status = 0;
11801 uint32_t shdr_status, shdr_add_status;
11802 union lpfc_sli4_cfg_shdr *shdr;
11803 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
11805 if (!phba->sli4_hba.pc_sli4_params.supported)
11806 hw_page_size = SLI4_PAGE_SIZE;
11808 if (hrq->entry_count != drq->entry_count)
11810 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11813 length = (sizeof(struct lpfc_mbx_rq_create) -
11814 sizeof(struct lpfc_sli4_cfg_mhdr));
11815 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
11816 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
11817 length, LPFC_SLI4_MBX_EMBED);
11818 rq_create = &mbox->u.mqe.un.rq_create;
11819 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
11820 bf_set(lpfc_mbox_hdr_version, &shdr->request,
11821 phba->sli4_hba.pc_sli4_params.rqv);
11822 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
11823 bf_set(lpfc_rq_context_rqe_count_1,
11824 &rq_create->u.request.context,
11826 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
11827 bf_set(lpfc_rq_context_rqe_size,
11828 &rq_create->u.request.context,
11830 bf_set(lpfc_rq_context_page_size,
11831 &rq_create->u.request.context,
11832 (PAGE_SIZE/SLI4_PAGE_SIZE));
11834 switch (hrq->entry_count) {
11836 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11837 "2535 Unsupported RQ count. (%d)\n",
11839 if (hrq->entry_count < 512)
11841 /* otherwise default to smallest count (drop through) */
11843 bf_set(lpfc_rq_context_rqe_count,
11844 &rq_create->u.request.context,
11845 LPFC_RQ_RING_SIZE_512);
11848 bf_set(lpfc_rq_context_rqe_count,
11849 &rq_create->u.request.context,
11850 LPFC_RQ_RING_SIZE_1024);
11853 bf_set(lpfc_rq_context_rqe_count,
11854 &rq_create->u.request.context,
11855 LPFC_RQ_RING_SIZE_2048);
11858 bf_set(lpfc_rq_context_rqe_count,
11859 &rq_create->u.request.context,
11860 LPFC_RQ_RING_SIZE_4096);
11863 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
11864 LPFC_HDR_BUF_SIZE);
11866 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
11868 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
11870 list_for_each_entry(dmabuf, &hrq->page_list, list) {
11871 memset(dmabuf->virt, 0, hw_page_size);
11872 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
11873 putPaddrLow(dmabuf->phys);
11874 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
11875 putPaddrHigh(dmabuf->phys);
11877 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11878 /* The IOCTL status is embedded in the mailbox subheader. */
11879 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11880 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11881 if (shdr_status || shdr_add_status || rc) {
11882 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11883 "2504 RQ_CREATE mailbox failed with "
11884 "status x%x add_status x%x, mbx status x%x\n",
11885 shdr_status, shdr_add_status, rc);
11889 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
11890 if (hrq->queue_id == 0xFFFF) {
11894 hrq->type = LPFC_HRQ;
11895 hrq->assoc_qid = cq->queue_id;
11896 hrq->subtype = subtype;
11897 hrq->host_index = 0;
11898 hrq->hba_index = 0;
11900 /* now create the data queue */
11901 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
11902 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
11903 length, LPFC_SLI4_MBX_EMBED);
11904 bf_set(lpfc_mbox_hdr_version, &shdr->request,
11905 phba->sli4_hba.pc_sli4_params.rqv);
11906 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
11907 bf_set(lpfc_rq_context_rqe_count_1,
11908 &rq_create->u.request.context, hrq->entry_count);
11909 rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
11910 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
11912 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
11913 (PAGE_SIZE/SLI4_PAGE_SIZE));
11915 switch (drq->entry_count) {
11917 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11918 "2536 Unsupported RQ count. (%d)\n",
11920 if (drq->entry_count < 512)
11922 /* otherwise default to smallest count (drop through) */
11924 bf_set(lpfc_rq_context_rqe_count,
11925 &rq_create->u.request.context,
11926 LPFC_RQ_RING_SIZE_512);
11929 bf_set(lpfc_rq_context_rqe_count,
11930 &rq_create->u.request.context,
11931 LPFC_RQ_RING_SIZE_1024);
11934 bf_set(lpfc_rq_context_rqe_count,
11935 &rq_create->u.request.context,
11936 LPFC_RQ_RING_SIZE_2048);
11939 bf_set(lpfc_rq_context_rqe_count,
11940 &rq_create->u.request.context,
11941 LPFC_RQ_RING_SIZE_4096);
11944 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
11945 LPFC_DATA_BUF_SIZE);
11947 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
11949 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
11951 list_for_each_entry(dmabuf, &drq->page_list, list) {
11952 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
11953 putPaddrLow(dmabuf->phys);
11954 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
11955 putPaddrHigh(dmabuf->phys);
11957 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
11958 /* The IOCTL status is embedded in the mailbox subheader. */
11959 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
11960 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11961 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11962 if (shdr_status || shdr_add_status || rc) {
11966 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
11967 if (drq->queue_id == 0xFFFF) {
11971 drq->type = LPFC_DRQ;
11972 drq->assoc_qid = cq->queue_id;
11973 drq->subtype = subtype;
11974 drq->host_index = 0;
11975 drq->hba_index = 0;
11977 /* link the header and data RQs onto the parent cq child list */
11978 list_add_tail(&hrq->list, &cq->child_list);
11979 list_add_tail(&drq->list, &cq->child_list);
11982 mempool_free(mbox, phba->mbox_mem_pool);
11987 * lpfc_eq_destroy - Destroy an event Queue on the HBA
11988 * @eq: The queue structure associated with the queue to destroy.
11990 * This function destroys a queue, as detailed in @eq by sending an mailbox
11991 * command, specific to the type of queue, to the HBA.
11993 * The @eq struct is used to get the queue ID of the queue to destroy.
11995 * On success this function will return a zero. If the queue destroy mailbox
11996 * command fails this function will return -ENXIO.
11999 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
12001 LPFC_MBOXQ_t *mbox;
12002 int rc, length, status = 0;
12003 uint32_t shdr_status, shdr_add_status;
12004 union lpfc_sli4_cfg_shdr *shdr;
12008 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
12011 length = (sizeof(struct lpfc_mbx_eq_destroy) -
12012 sizeof(struct lpfc_sli4_cfg_mhdr));
12013 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12014 LPFC_MBOX_OPCODE_EQ_DESTROY,
12015 length, LPFC_SLI4_MBX_EMBED);
12016 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
12018 mbox->vport = eq->phba->pport;
12019 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12021 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
12022 /* The IOCTL status is embedded in the mailbox subheader. */
12023 shdr = (union lpfc_sli4_cfg_shdr *)
12024 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
12025 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12026 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12027 if (shdr_status || shdr_add_status || rc) {
12028 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12029 "2505 EQ_DESTROY mailbox failed with "
12030 "status x%x add_status x%x, mbx status x%x\n",
12031 shdr_status, shdr_add_status, rc);
12035 /* Remove eq from any list */
12036 list_del_init(&eq->list);
12037 mempool_free(mbox, eq->phba->mbox_mem_pool);
12042 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
12043 * @cq: The queue structure associated with the queue to destroy.
12045 * This function destroys a queue, as detailed in @cq by sending an mailbox
12046 * command, specific to the type of queue, to the HBA.
12048 * The @cq struct is used to get the queue ID of the queue to destroy.
12050 * On success this function will return a zero. If the queue destroy mailbox
12051 * command fails this function will return -ENXIO.
12054 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
12056 LPFC_MBOXQ_t *mbox;
12057 int rc, length, status = 0;
12058 uint32_t shdr_status, shdr_add_status;
12059 union lpfc_sli4_cfg_shdr *shdr;
12063 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
12066 length = (sizeof(struct lpfc_mbx_cq_destroy) -
12067 sizeof(struct lpfc_sli4_cfg_mhdr));
12068 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12069 LPFC_MBOX_OPCODE_CQ_DESTROY,
12070 length, LPFC_SLI4_MBX_EMBED);
12071 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
12073 mbox->vport = cq->phba->pport;
12074 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12075 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
12076 /* The IOCTL status is embedded in the mailbox subheader. */
12077 shdr = (union lpfc_sli4_cfg_shdr *)
12078 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
12079 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12080 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12081 if (shdr_status || shdr_add_status || rc) {
12082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12083 "2506 CQ_DESTROY mailbox failed with "
12084 "status x%x add_status x%x, mbx status x%x\n",
12085 shdr_status, shdr_add_status, rc);
12088 /* Remove cq from any list */
12089 list_del_init(&cq->list);
12090 mempool_free(mbox, cq->phba->mbox_mem_pool);
12095 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
12096 * @qm: The queue structure associated with the queue to destroy.
12098 * This function destroys a queue, as detailed in @mq by sending an mailbox
12099 * command, specific to the type of queue, to the HBA.
12101 * The @mq struct is used to get the queue ID of the queue to destroy.
12103 * On success this function will return a zero. If the queue destroy mailbox
12104 * command fails this function will return -ENXIO.
12107 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
12109 LPFC_MBOXQ_t *mbox;
12110 int rc, length, status = 0;
12111 uint32_t shdr_status, shdr_add_status;
12112 union lpfc_sli4_cfg_shdr *shdr;
12116 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
12119 length = (sizeof(struct lpfc_mbx_mq_destroy) -
12120 sizeof(struct lpfc_sli4_cfg_mhdr));
12121 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12122 LPFC_MBOX_OPCODE_MQ_DESTROY,
12123 length, LPFC_SLI4_MBX_EMBED);
12124 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
12126 mbox->vport = mq->phba->pport;
12127 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12128 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
12129 /* The IOCTL status is embedded in the mailbox subheader. */
12130 shdr = (union lpfc_sli4_cfg_shdr *)
12131 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
12132 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12133 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12134 if (shdr_status || shdr_add_status || rc) {
12135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12136 "2507 MQ_DESTROY mailbox failed with "
12137 "status x%x add_status x%x, mbx status x%x\n",
12138 shdr_status, shdr_add_status, rc);
12141 /* Remove mq from any list */
12142 list_del_init(&mq->list);
12143 mempool_free(mbox, mq->phba->mbox_mem_pool);
12148 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
12149 * @wq: The queue structure associated with the queue to destroy.
12151 * This function destroys a queue, as detailed in @wq by sending an mailbox
12152 * command, specific to the type of queue, to the HBA.
12154 * The @wq struct is used to get the queue ID of the queue to destroy.
12156 * On success this function will return a zero. If the queue destroy mailbox
12157 * command fails this function will return -ENXIO.
12160 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
12162 LPFC_MBOXQ_t *mbox;
12163 int rc, length, status = 0;
12164 uint32_t shdr_status, shdr_add_status;
12165 union lpfc_sli4_cfg_shdr *shdr;
12169 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
12172 length = (sizeof(struct lpfc_mbx_wq_destroy) -
12173 sizeof(struct lpfc_sli4_cfg_mhdr));
12174 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12175 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
12176 length, LPFC_SLI4_MBX_EMBED);
12177 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
12179 mbox->vport = wq->phba->pport;
12180 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12181 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
12182 shdr = (union lpfc_sli4_cfg_shdr *)
12183 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
12184 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12185 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12186 if (shdr_status || shdr_add_status || rc) {
12187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12188 "2508 WQ_DESTROY mailbox failed with "
12189 "status x%x add_status x%x, mbx status x%x\n",
12190 shdr_status, shdr_add_status, rc);
12193 /* Remove wq from any list */
12194 list_del_init(&wq->list);
12195 mempool_free(mbox, wq->phba->mbox_mem_pool);
12200 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
12201 * @rq: The queue structure associated with the queue to destroy.
12203 * This function destroys a queue, as detailed in @rq by sending an mailbox
12204 * command, specific to the type of queue, to the HBA.
12206 * The @rq struct is used to get the queue ID of the queue to destroy.
12208 * On success this function will return a zero. If the queue destroy mailbox
12209 * command fails this function will return -ENXIO.
12212 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
12213 struct lpfc_queue *drq)
12215 LPFC_MBOXQ_t *mbox;
12216 int rc, length, status = 0;
12217 uint32_t shdr_status, shdr_add_status;
12218 union lpfc_sli4_cfg_shdr *shdr;
12222 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
12225 length = (sizeof(struct lpfc_mbx_rq_destroy) -
12226 sizeof(struct lpfc_sli4_cfg_mhdr));
12227 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12228 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
12229 length, LPFC_SLI4_MBX_EMBED);
12230 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
12232 mbox->vport = hrq->phba->pport;
12233 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12234 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
12235 /* The IOCTL status is embedded in the mailbox subheader. */
12236 shdr = (union lpfc_sli4_cfg_shdr *)
12237 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
12238 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12239 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12240 if (shdr_status || shdr_add_status || rc) {
12241 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12242 "2509 RQ_DESTROY mailbox failed with "
12243 "status x%x add_status x%x, mbx status x%x\n",
12244 shdr_status, shdr_add_status, rc);
12245 if (rc != MBX_TIMEOUT)
12246 mempool_free(mbox, hrq->phba->mbox_mem_pool);
12249 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
12251 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
12252 shdr = (union lpfc_sli4_cfg_shdr *)
12253 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
12254 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12255 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12256 if (shdr_status || shdr_add_status || rc) {
12257 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12258 "2510 RQ_DESTROY mailbox failed with "
12259 "status x%x add_status x%x, mbx status x%x\n",
12260 shdr_status, shdr_add_status, rc);
12263 list_del_init(&hrq->list);
12264 list_del_init(&drq->list);
12265 mempool_free(mbox, hrq->phba->mbox_mem_pool);
12270 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
12271 * @phba: The virtual port for which this call being executed.
12272 * @pdma_phys_addr0: Physical address of the 1st SGL page.
12273 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
12274 * @xritag: the xritag that ties this io to the SGL pages.
12276 * This routine will post the sgl pages for the IO that has the xritag
12277 * that is in the iocbq structure. The xritag is assigned during iocbq
12278 * creation and persists for as long as the driver is loaded.
12279 * if the caller has fewer than 256 scatter gather segments to map then
12280 * pdma_phys_addr1 should be 0.
12281 * If the caller needs to map more than 256 scatter gather segment then
12282 * pdma_phys_addr1 should be a valid physical address.
12283 * physical address for SGLs must be 64 byte aligned.
12284 * If you are going to map 2 SGL's then the first one must have 256 entries
12285 * the second sgl can have between 1 and 256 entries.
12289 * -ENXIO, -ENOMEM - Failure
12292 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
12293 dma_addr_t pdma_phys_addr0,
12294 dma_addr_t pdma_phys_addr1,
12297 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
12298 LPFC_MBOXQ_t *mbox;
12300 uint32_t shdr_status, shdr_add_status;
12302 union lpfc_sli4_cfg_shdr *shdr;
12304 if (xritag == NO_XRI) {
12305 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12306 "0364 Invalid param:\n");
12310 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12314 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12315 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
12316 sizeof(struct lpfc_mbx_post_sgl_pages) -
12317 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
12319 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
12320 &mbox->u.mqe.un.post_sgl_pages;
12321 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
12322 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
12324 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
12325 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
12326 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
12327 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
12329 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
12330 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
12331 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
12332 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
12333 if (!phba->sli4_hba.intr_enable)
12334 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12336 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
12337 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
12339 /* The IOCTL status is embedded in the mailbox subheader. */
12340 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
12341 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12342 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12343 if (rc != MBX_TIMEOUT)
12344 mempool_free(mbox, phba->mbox_mem_pool);
12345 if (shdr_status || shdr_add_status || rc) {
12346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12347 "2511 POST_SGL mailbox failed with "
12348 "status x%x add_status x%x, mbx status x%x\n",
12349 shdr_status, shdr_add_status, rc);
12356 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
12357 * @phba: pointer to lpfc hba data structure.
12359 * This routine is invoked to post rpi header templates to the
12360 * HBA consistent with the SLI-4 interface spec. This routine
12361 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
12362 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
12365 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
12366 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
12369 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
12374 * Fetch the next logical xri. Because this index is logical,
12375 * the driver starts at 0 each time.
12377 spin_lock_irq(&phba->hbalock);
12378 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
12379 phba->sli4_hba.max_cfg_param.max_xri, 0);
12380 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
12381 spin_unlock_irq(&phba->hbalock);
12384 set_bit(xri, phba->sli4_hba.xri_bmask);
12385 phba->sli4_hba.max_cfg_param.xri_used++;
12386 phba->sli4_hba.xri_count++;
12389 spin_unlock_irq(&phba->hbalock);
12394 * lpfc_sli4_free_xri - Release an xri for reuse.
12395 * @phba: pointer to lpfc hba data structure.
12397 * This routine is invoked to release an xri to the pool of
12398 * available rpis maintained by the driver.
12401 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
12403 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
12404 phba->sli4_hba.xri_count--;
12405 phba->sli4_hba.max_cfg_param.xri_used--;
12410 * lpfc_sli4_free_xri - Release an xri for reuse.
12411 * @phba: pointer to lpfc hba data structure.
12413 * This routine is invoked to release an xri to the pool of
12414 * available rpis maintained by the driver.
12417 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
12419 spin_lock_irq(&phba->hbalock);
12420 __lpfc_sli4_free_xri(phba, xri);
12421 spin_unlock_irq(&phba->hbalock);
12425 * lpfc_sli4_next_xritag - Get an xritag for the io
12426 * @phba: Pointer to HBA context object.
12428 * This function gets an xritag for the iocb. If there is no unused xritag
12429 * it will return 0xffff.
12430 * The function returns the allocated xritag if successful, else returns zero.
12431 * Zero is not a valid xritag.
12432 * The caller is not required to hold any lock.
12435 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
12437 uint16_t xri_index;
12439 xri_index = lpfc_sli4_alloc_xri(phba);
12440 if (xri_index != NO_XRI)
12443 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12444 "2004 Failed to allocate XRI.last XRITAG is %d"
12445 " Max XRI is %d, Used XRI is %d\n",
12447 phba->sli4_hba.max_cfg_param.max_xri,
12448 phba->sli4_hba.max_cfg_param.xri_used);
12453 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
12454 * @phba: pointer to lpfc hba data structure.
12456 * This routine is invoked to post a block of driver's sgl pages to the
12457 * HBA using non-embedded mailbox command. No Lock is held. This routine
12458 * is only called when the driver is loading and after all IO has been
12462 lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba)
12464 struct lpfc_sglq *sglq_entry;
12465 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
12466 struct sgl_page_pairs *sgl_pg_pairs;
12468 LPFC_MBOXQ_t *mbox;
12469 uint32_t reqlen, alloclen, pg_pairs;
12471 uint16_t xritag_start = 0, lxri = 0;
12472 int els_xri_cnt, rc = 0;
12473 uint32_t shdr_status, shdr_add_status;
12474 union lpfc_sli4_cfg_shdr *shdr;
12476 /* The number of sgls to be posted */
12477 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
12479 reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
12480 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
12481 if (reqlen > SLI4_PAGE_SIZE) {
12482 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12483 "2559 Block sgl registration required DMA "
12484 "size (%d) great than a page\n", reqlen);
12487 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12491 /* Allocate DMA memory and set up the non-embedded mailbox command */
12492 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12493 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
12494 LPFC_SLI4_MBX_NEMBED);
12496 if (alloclen < reqlen) {
12497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12498 "0285 Allocated DMA memory size (%d) is "
12499 "less than the requested DMA memory "
12500 "size (%d)\n", alloclen, reqlen);
12501 lpfc_sli4_mbox_cmd_free(phba, mbox);
12504 /* Set up the SGL pages in the non-embedded DMA pages */
12505 viraddr = mbox->sge_array->addr[0];
12506 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
12507 sgl_pg_pairs = &sgl->sgl_pg_pairs;
12509 for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
12510 sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
12513 * Assign the sglq a physical xri only if the driver has not
12514 * initialized those resources. A port reset only needs
12515 * the sglq's posted.
12517 if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
12518 LPFC_XRI_RSRC_RDY) {
12519 lxri = lpfc_sli4_next_xritag(phba);
12520 if (lxri == NO_XRI) {
12521 lpfc_sli4_mbox_cmd_free(phba, mbox);
12524 sglq_entry->sli4_lxritag = lxri;
12525 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
12528 /* Set up the sge entry */
12529 sgl_pg_pairs->sgl_pg0_addr_lo =
12530 cpu_to_le32(putPaddrLow(sglq_entry->phys));
12531 sgl_pg_pairs->sgl_pg0_addr_hi =
12532 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
12533 sgl_pg_pairs->sgl_pg1_addr_lo =
12534 cpu_to_le32(putPaddrLow(0));
12535 sgl_pg_pairs->sgl_pg1_addr_hi =
12536 cpu_to_le32(putPaddrHigh(0));
12538 /* Keep the first xritag on the list */
12540 xritag_start = sglq_entry->sli4_xritag;
12544 /* Complete initialization and perform endian conversion. */
12545 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
12546 bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
12547 sgl->word0 = cpu_to_le32(sgl->word0);
12548 if (!phba->sli4_hba.intr_enable)
12549 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12551 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
12552 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
12554 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
12555 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12556 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12557 if (rc != MBX_TIMEOUT)
12558 lpfc_sli4_mbox_cmd_free(phba, mbox);
12559 if (shdr_status || shdr_add_status || rc) {
12560 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12561 "2513 POST_SGL_BLOCK mailbox command failed "
12562 "status x%x add_status x%x mbx status x%x\n",
12563 shdr_status, shdr_add_status, rc);
12568 bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags,
12569 LPFC_XRI_RSRC_RDY);
12574 * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port.
12575 * @phba: pointer to lpfc hba data structure.
12577 * This routine is invoked to post a block of driver's sgl pages to the
12578 * HBA using non-embedded mailbox command. No Lock is held. This routine
12579 * is only called when the driver is loading and after all IO has been
12583 lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba)
12585 struct lpfc_sglq *sglq_entry;
12586 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
12587 struct sgl_page_pairs *sgl_pg_pairs;
12589 LPFC_MBOXQ_t *mbox;
12590 uint32_t reqlen, alloclen, index;
12592 uint16_t rsrc_start, rsrc_size, els_xri_cnt;
12593 uint16_t xritag_start = 0, lxri = 0;
12594 struct lpfc_rsrc_blks *rsrc_blk;
12595 int cnt, ttl_cnt, rc = 0;
12597 uint32_t shdr_status, shdr_add_status;
12598 union lpfc_sli4_cfg_shdr *shdr;
12600 /* The number of sgls to be posted */
12601 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
12603 reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
12604 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
12605 if (reqlen > SLI4_PAGE_SIZE) {
12606 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12607 "2989 Block sgl registration required DMA "
12608 "size (%d) great than a page\n", reqlen);
12614 list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
12616 rsrc_start = rsrc_blk->rsrc_start;
12617 rsrc_size = rsrc_blk->rsrc_size;
12619 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12620 "3014 Working ELS Extent start %d, cnt %d\n",
12621 rsrc_start, rsrc_size);
12623 loop_cnt = min(els_xri_cnt, rsrc_size);
12624 if (ttl_cnt + loop_cnt >= els_xri_cnt) {
12625 loop_cnt = els_xri_cnt - ttl_cnt;
12626 ttl_cnt = els_xri_cnt;
12629 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12633 * Allocate DMA memory and set up the non-embedded mailbox
12636 alloclen = lpfc_sli4_config(phba, mbox,
12637 LPFC_MBOX_SUBSYSTEM_FCOE,
12638 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
12639 reqlen, LPFC_SLI4_MBX_NEMBED);
12640 if (alloclen < reqlen) {
12641 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12642 "2987 Allocated DMA memory size (%d) "
12643 "is less than the requested DMA memory "
12644 "size (%d)\n", alloclen, reqlen);
12645 lpfc_sli4_mbox_cmd_free(phba, mbox);
12649 /* Set up the SGL pages in the non-embedded DMA pages */
12650 viraddr = mbox->sge_array->addr[0];
12651 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
12652 sgl_pg_pairs = &sgl->sgl_pg_pairs;
12655 * The starting resource may not begin at zero. Control
12656 * the loop variants via the block resource parameters,
12657 * but handle the sge pointers with a zero-based index
12658 * that doesn't get reset per loop pass.
12660 for (index = rsrc_start;
12661 index < rsrc_start + loop_cnt;
12663 sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt];
12666 * Assign the sglq a physical xri only if the driver
12667 * has not initialized those resources. A port reset
12668 * only needs the sglq's posted.
12670 if (bf_get(lpfc_xri_rsrc_rdy,
12671 &phba->sli4_hba.sli4_flags) !=
12672 LPFC_XRI_RSRC_RDY) {
12673 lxri = lpfc_sli4_next_xritag(phba);
12674 if (lxri == NO_XRI) {
12675 lpfc_sli4_mbox_cmd_free(phba, mbox);
12679 sglq_entry->sli4_lxritag = lxri;
12680 sglq_entry->sli4_xritag =
12681 phba->sli4_hba.xri_ids[lxri];
12684 /* Set up the sge entry */
12685 sgl_pg_pairs->sgl_pg0_addr_lo =
12686 cpu_to_le32(putPaddrLow(sglq_entry->phys));
12687 sgl_pg_pairs->sgl_pg0_addr_hi =
12688 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
12689 sgl_pg_pairs->sgl_pg1_addr_lo =
12690 cpu_to_le32(putPaddrLow(0));
12691 sgl_pg_pairs->sgl_pg1_addr_hi =
12692 cpu_to_le32(putPaddrHigh(0));
12694 /* Track the starting physical XRI for the mailbox. */
12695 if (index == rsrc_start)
12696 xritag_start = sglq_entry->sli4_xritag;
12701 /* Complete initialization and perform endian conversion. */
12702 rsrc_blk->rsrc_used += loop_cnt;
12703 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
12704 bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt);
12705 sgl->word0 = cpu_to_le32(sgl->word0);
12707 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12708 "3015 Post ELS Extent SGL, start %d, "
12709 "cnt %d, used %d\n",
12710 xritag_start, loop_cnt, rsrc_blk->rsrc_used);
12711 if (!phba->sli4_hba.intr_enable)
12712 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12714 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
12715 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
12717 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
12718 shdr_status = bf_get(lpfc_mbox_hdr_status,
12720 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
12722 if (rc != MBX_TIMEOUT)
12723 lpfc_sli4_mbox_cmd_free(phba, mbox);
12724 if (shdr_status || shdr_add_status || rc) {
12725 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12726 "2988 POST_SGL_BLOCK mailbox "
12727 "command failed status x%x "
12728 "add_status x%x mbx status x%x\n",
12729 shdr_status, shdr_add_status, rc);
12733 if (ttl_cnt >= els_xri_cnt)
12739 bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags,
12740 LPFC_XRI_RSRC_RDY);
12745 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
12746 * @phba: pointer to lpfc hba data structure.
12747 * @sblist: pointer to scsi buffer list.
12748 * @count: number of scsi buffers on the list.
12750 * This routine is invoked to post a block of @count scsi sgl pages from a
12751 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
12756 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
12759 struct lpfc_scsi_buf *psb;
12760 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
12761 struct sgl_page_pairs *sgl_pg_pairs;
12763 LPFC_MBOXQ_t *mbox;
12764 uint32_t reqlen, alloclen, pg_pairs;
12766 uint16_t xritag_start = 0;
12768 uint32_t shdr_status, shdr_add_status;
12769 dma_addr_t pdma_phys_bpl1;
12770 union lpfc_sli4_cfg_shdr *shdr;
12772 /* Calculate the requested length of the dma memory */
12773 reqlen = cnt * sizeof(struct sgl_page_pairs) +
12774 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
12775 if (reqlen > SLI4_PAGE_SIZE) {
12776 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12777 "0217 Block sgl registration required DMA "
12778 "size (%d) great than a page\n", reqlen);
12781 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12783 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12784 "0283 Failed to allocate mbox cmd memory\n");
12788 /* Allocate DMA memory and set up the non-embedded mailbox command */
12789 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12790 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
12791 LPFC_SLI4_MBX_NEMBED);
12793 if (alloclen < reqlen) {
12794 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12795 "2561 Allocated DMA memory size (%d) is "
12796 "less than the requested DMA memory "
12797 "size (%d)\n", alloclen, reqlen);
12798 lpfc_sli4_mbox_cmd_free(phba, mbox);
12802 /* Get the first SGE entry from the non-embedded DMA memory */
12803 viraddr = mbox->sge_array->addr[0];
12805 /* Set up the SGL pages in the non-embedded DMA pages */
12806 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
12807 sgl_pg_pairs = &sgl->sgl_pg_pairs;
12810 list_for_each_entry(psb, sblist, list) {
12811 /* Set up the sge entry */
12812 sgl_pg_pairs->sgl_pg0_addr_lo =
12813 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
12814 sgl_pg_pairs->sgl_pg0_addr_hi =
12815 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
12816 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
12817 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
12819 pdma_phys_bpl1 = 0;
12820 sgl_pg_pairs->sgl_pg1_addr_lo =
12821 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
12822 sgl_pg_pairs->sgl_pg1_addr_hi =
12823 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
12824 /* Keep the first xritag on the list */
12826 xritag_start = psb->cur_iocbq.sli4_xritag;
12830 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
12831 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
12832 /* Perform endian conversion if necessary */
12833 sgl->word0 = cpu_to_le32(sgl->word0);
12835 if (!phba->sli4_hba.intr_enable)
12836 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12838 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
12839 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
12841 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
12842 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12843 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12844 if (rc != MBX_TIMEOUT)
12845 lpfc_sli4_mbox_cmd_free(phba, mbox);
12846 if (shdr_status || shdr_add_status || rc) {
12847 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12848 "2564 POST_SGL_BLOCK mailbox command failed "
12849 "status x%x add_status x%x mbx status x%x\n",
12850 shdr_status, shdr_add_status, rc);
12857 * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port.
12858 * @phba: pointer to lpfc hba data structure.
12859 * @sblist: pointer to scsi buffer list.
12860 * @count: number of scsi buffers on the list.
12862 * This routine is invoked to post a block of @count scsi sgl pages from a
12863 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
12868 lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist,
12871 struct lpfc_scsi_buf *psb = NULL;
12872 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
12873 struct sgl_page_pairs *sgl_pg_pairs;
12875 LPFC_MBOXQ_t *mbox;
12876 uint32_t reqlen, alloclen, pg_pairs;
12878 uint16_t xri_start = 0, scsi_xri_start;
12879 uint16_t rsrc_range;
12880 int rc = 0, avail_cnt;
12881 uint32_t shdr_status, shdr_add_status;
12882 dma_addr_t pdma_phys_bpl1;
12883 union lpfc_sli4_cfg_shdr *shdr;
12884 struct lpfc_rsrc_blks *rsrc_blk;
12885 uint32_t xri_cnt = 0;
12887 /* Calculate the total requested length of the dma memory */
12888 reqlen = cnt * sizeof(struct sgl_page_pairs) +
12889 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
12890 if (reqlen > SLI4_PAGE_SIZE) {
12891 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12892 "2932 Block sgl registration required DMA "
12893 "size (%d) great than a page\n", reqlen);
12898 * The use of extents requires the driver to post the sgl headers
12899 * in multiple postings to meet the contiguous resource assignment.
12901 psb = list_prepare_entry(psb, sblist, list);
12902 scsi_xri_start = phba->sli4_hba.scsi_xri_start;
12903 list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
12905 rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size;
12906 if (rsrc_range < scsi_xri_start)
12908 else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size)
12911 avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used;
12913 reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) +
12914 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
12916 * Allocate DMA memory and set up the non-embedded mailbox
12917 * command. The mbox is used to post an SGL page per loop
12918 * but the DMA memory has a use-once semantic so the mailbox
12919 * is used and freed per loop pass.
12921 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12924 "2933 Failed to allocate mbox cmd "
12928 alloclen = lpfc_sli4_config(phba, mbox,
12929 LPFC_MBOX_SUBSYSTEM_FCOE,
12930 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
12932 LPFC_SLI4_MBX_NEMBED);
12933 if (alloclen < reqlen) {
12934 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12935 "2934 Allocated DMA memory size (%d) "
12936 "is less than the requested DMA memory "
12937 "size (%d)\n", alloclen, reqlen);
12938 lpfc_sli4_mbox_cmd_free(phba, mbox);
12942 /* Get the first SGE entry from the non-embedded DMA memory */
12943 viraddr = mbox->sge_array->addr[0];
12945 /* Set up the SGL pages in the non-embedded DMA pages */
12946 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
12947 sgl_pg_pairs = &sgl->sgl_pg_pairs;
12949 /* pg_pairs tracks posted SGEs per loop iteration. */
12951 list_for_each_entry_continue(psb, sblist, list) {
12952 /* Set up the sge entry */
12953 sgl_pg_pairs->sgl_pg0_addr_lo =
12954 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
12955 sgl_pg_pairs->sgl_pg0_addr_hi =
12956 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
12957 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
12958 pdma_phys_bpl1 = psb->dma_phys_bpl +
12961 pdma_phys_bpl1 = 0;
12962 sgl_pg_pairs->sgl_pg1_addr_lo =
12963 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
12964 sgl_pg_pairs->sgl_pg1_addr_hi =
12965 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
12966 /* Keep the first xri for this extent. */
12968 xri_start = psb->cur_iocbq.sli4_xritag;
12974 * Track two exit conditions - the loop has constructed
12975 * all of the caller's SGE pairs or all available
12976 * resource IDs in this extent are consumed.
12978 if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt))
12981 rsrc_blk->rsrc_used += pg_pairs;
12982 bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start);
12983 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
12985 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12986 "3016 Post SCSI Extent SGL, start %d, cnt %d "
12988 xri_start, pg_pairs, rsrc_blk->rsrc_used);
12989 /* Perform endian conversion if necessary */
12990 sgl->word0 = cpu_to_le32(sgl->word0);
12991 if (!phba->sli4_hba.intr_enable)
12992 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12994 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
12995 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
12997 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
12998 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12999 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
13001 if (rc != MBX_TIMEOUT)
13002 lpfc_sli4_mbox_cmd_free(phba, mbox);
13003 if (shdr_status || shdr_add_status || rc) {
13004 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13005 "2935 POST_SGL_BLOCK mailbox command "
13006 "failed status x%x add_status x%x "
13007 "mbx status x%x\n",
13008 shdr_status, shdr_add_status, rc);
13012 /* Post only what is requested. */
13013 if (xri_cnt >= cnt)
13020 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13021 * @phba: pointer to lpfc_hba struct that the frame was received on
13022 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13024 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13025 * valid type of frame that the LPFC driver will handle. This function will
13026 * return a zero if the frame is a valid frame or a non zero value when the
13027 * frame does not pass the check.
13030 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
13032 /* make rctl_names static to save stack space */
13033 static char *rctl_names[] = FC_RCTL_NAMES_INIT;
13034 char *type_names[] = FC_TYPE_NAMES_INIT;
13035 struct fc_vft_header *fc_vft_hdr;
13036 uint32_t *header = (uint32_t *) fc_hdr;
13038 switch (fc_hdr->fh_r_ctl) {
13039 case FC_RCTL_DD_UNCAT: /* uncategorized information */
13040 case FC_RCTL_DD_SOL_DATA: /* solicited data */
13041 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
13042 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
13043 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
13044 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
13045 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
13046 case FC_RCTL_DD_CMD_STATUS: /* command status */
13047 case FC_RCTL_ELS_REQ: /* extended link services request */
13048 case FC_RCTL_ELS_REP: /* extended link services reply */
13049 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
13050 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
13051 case FC_RCTL_BA_NOP: /* basic link service NOP */
13052 case FC_RCTL_BA_ABTS: /* basic link service abort */
13053 case FC_RCTL_BA_RMC: /* remove connection */
13054 case FC_RCTL_BA_ACC: /* basic accept */
13055 case FC_RCTL_BA_RJT: /* basic reject */
13056 case FC_RCTL_BA_PRMT:
13057 case FC_RCTL_ACK_1: /* acknowledge_1 */
13058 case FC_RCTL_ACK_0: /* acknowledge_0 */
13059 case FC_RCTL_P_RJT: /* port reject */
13060 case FC_RCTL_F_RJT: /* fabric reject */
13061 case FC_RCTL_P_BSY: /* port busy */
13062 case FC_RCTL_F_BSY: /* fabric busy to data frame */
13063 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
13064 case FC_RCTL_LCR: /* link credit reset */
13065 case FC_RCTL_END: /* end */
13067 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
13068 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
13069 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
13070 return lpfc_fc_frame_check(phba, fc_hdr);
13074 switch (fc_hdr->fh_type) {
13086 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
13087 "2538 Received frame rctl:%s type:%s "
13088 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13089 rctl_names[fc_hdr->fh_r_ctl],
13090 type_names[fc_hdr->fh_type],
13091 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
13092 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
13093 be32_to_cpu(header[4]), be32_to_cpu(header[5]));
13096 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
13097 "2539 Dropped frame rctl:%s type:%s\n",
13098 rctl_names[fc_hdr->fh_r_ctl],
13099 type_names[fc_hdr->fh_type]);
13104 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13105 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13107 * This function processes the FC header to retrieve the VFI from the VF
13108 * header, if one exists. This function will return the VFI if one exists
13109 * or 0 if no VSAN Header exists.
13112 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
13114 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
13116 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
13118 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
13122 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13123 * @phba: Pointer to the HBA structure to search for the vport on
13124 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13125 * @fcfi: The FC Fabric ID that the frame came from
13127 * This function searches the @phba for a vport that matches the content of the
13128 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13129 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13130 * returns the matching vport pointer or NULL if unable to match frame to a
13133 static struct lpfc_vport *
13134 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
13137 struct lpfc_vport **vports;
13138 struct lpfc_vport *vport = NULL;
13140 uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
13141 fc_hdr->fh_d_id[1] << 8 |
13142 fc_hdr->fh_d_id[2]);
13144 vports = lpfc_create_vport_work_array(phba);
13145 if (vports != NULL)
13146 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
13147 if (phba->fcf.fcfi == fcfi &&
13148 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
13149 vports[i]->fc_myDID == did) {
13154 lpfc_destroy_vport_work_array(phba, vports);
13159 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13160 * @vport: The vport to work on.
13162 * This function updates the receive sequence time stamp for this vport. The
13163 * receive sequence time stamp indicates the time that the last frame of the
13164 * the sequence that has been idle for the longest amount of time was received.
13165 * the driver uses this time stamp to indicate if any received sequences have
13169 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
13171 struct lpfc_dmabuf *h_buf;
13172 struct hbq_dmabuf *dmabuf = NULL;
13174 /* get the oldest sequence on the rcv list */
13175 h_buf = list_get_first(&vport->rcv_buffer_list,
13176 struct lpfc_dmabuf, list);
13179 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13180 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
13184 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13185 * @vport: The vport that the received sequences were sent to.
13187 * This function cleans up all outstanding received sequences. This is called
13188 * by the driver when a link event or user action invalidates all the received
13192 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
13194 struct lpfc_dmabuf *h_buf, *hnext;
13195 struct lpfc_dmabuf *d_buf, *dnext;
13196 struct hbq_dmabuf *dmabuf = NULL;
13198 /* start with the oldest sequence on the rcv list */
13199 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
13200 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13201 list_del_init(&dmabuf->hbuf.list);
13202 list_for_each_entry_safe(d_buf, dnext,
13203 &dmabuf->dbuf.list, list) {
13204 list_del_init(&d_buf->list);
13205 lpfc_in_buf_free(vport->phba, d_buf);
13207 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
13212 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13213 * @vport: The vport that the received sequences were sent to.
13215 * This function determines whether any received sequences have timed out by
13216 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13217 * indicates that there is at least one timed out sequence this routine will
13218 * go through the received sequences one at a time from most inactive to most
13219 * active to determine which ones need to be cleaned up. Once it has determined
13220 * that a sequence needs to be cleaned up it will simply free up the resources
13221 * without sending an abort.
13224 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
13226 struct lpfc_dmabuf *h_buf, *hnext;
13227 struct lpfc_dmabuf *d_buf, *dnext;
13228 struct hbq_dmabuf *dmabuf = NULL;
13229 unsigned long timeout;
13230 int abort_count = 0;
13232 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
13233 vport->rcv_buffer_time_stamp);
13234 if (list_empty(&vport->rcv_buffer_list) ||
13235 time_before(jiffies, timeout))
13237 /* start with the oldest sequence on the rcv list */
13238 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
13239 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13240 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
13241 dmabuf->time_stamp);
13242 if (time_before(jiffies, timeout))
13245 list_del_init(&dmabuf->hbuf.list);
13246 list_for_each_entry_safe(d_buf, dnext,
13247 &dmabuf->dbuf.list, list) {
13248 list_del_init(&d_buf->list);
13249 lpfc_in_buf_free(vport->phba, d_buf);
13251 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
13254 lpfc_update_rcv_time_stamp(vport);
13258 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13259 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13261 * This function searches through the existing incomplete sequences that have
13262 * been sent to this @vport. If the frame matches one of the incomplete
13263 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13264 * make up that sequence. If no sequence is found that matches this frame then
13265 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13266 * This function returns a pointer to the first dmabuf in the sequence list that
13267 * the frame was linked to.
13269 static struct hbq_dmabuf *
13270 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
13272 struct fc_frame_header *new_hdr;
13273 struct fc_frame_header *temp_hdr;
13274 struct lpfc_dmabuf *d_buf;
13275 struct lpfc_dmabuf *h_buf;
13276 struct hbq_dmabuf *seq_dmabuf = NULL;
13277 struct hbq_dmabuf *temp_dmabuf = NULL;
13279 INIT_LIST_HEAD(&dmabuf->dbuf.list);
13280 dmabuf->time_stamp = jiffies;
13281 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
13282 /* Use the hdr_buf to find the sequence that this frame belongs to */
13283 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
13284 temp_hdr = (struct fc_frame_header *)h_buf->virt;
13285 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
13286 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
13287 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
13289 /* found a pending sequence that matches this frame */
13290 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13295 * This indicates first frame received for this sequence.
13296 * Queue the buffer on the vport's rcv_buffer_list.
13298 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
13299 lpfc_update_rcv_time_stamp(vport);
13302 temp_hdr = seq_dmabuf->hbuf.virt;
13303 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
13304 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
13305 list_del_init(&seq_dmabuf->hbuf.list);
13306 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
13307 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
13308 lpfc_update_rcv_time_stamp(vport);
13311 /* move this sequence to the tail to indicate a young sequence */
13312 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
13313 seq_dmabuf->time_stamp = jiffies;
13314 lpfc_update_rcv_time_stamp(vport);
13315 if (list_empty(&seq_dmabuf->dbuf.list)) {
13316 temp_hdr = dmabuf->hbuf.virt;
13317 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
13320 /* find the correct place in the sequence to insert this frame */
13321 list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
13322 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
13323 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
13325 * If the frame's sequence count is greater than the frame on
13326 * the list then insert the frame right after this frame
13328 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
13329 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
13330 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
13338 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
13339 * @vport: pointer to a vitural port
13340 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13342 * This function tries to abort from the partially assembed sequence, described
13343 * by the information from basic abbort @dmabuf. It checks to see whether such
13344 * partially assembled sequence held by the driver. If so, it shall free up all
13345 * the frames from the partially assembled sequence.
13348 * true -- if there is matching partially assembled sequence present and all
13349 * the frames freed with the sequence;
13350 * false -- if there is no matching partially assembled sequence present so
13351 * nothing got aborted in the lower layer driver
13354 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
13355 struct hbq_dmabuf *dmabuf)
13357 struct fc_frame_header *new_hdr;
13358 struct fc_frame_header *temp_hdr;
13359 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
13360 struct hbq_dmabuf *seq_dmabuf = NULL;
13362 /* Use the hdr_buf to find the sequence that matches this frame */
13363 INIT_LIST_HEAD(&dmabuf->dbuf.list);
13364 INIT_LIST_HEAD(&dmabuf->hbuf.list);
13365 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
13366 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
13367 temp_hdr = (struct fc_frame_header *)h_buf->virt;
13368 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
13369 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
13370 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
13372 /* found a pending sequence that matches this frame */
13373 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13377 /* Free up all the frames from the partially assembled sequence */
13379 list_for_each_entry_safe(d_buf, n_buf,
13380 &seq_dmabuf->dbuf.list, list) {
13381 list_del_init(&d_buf->list);
13382 lpfc_in_buf_free(vport->phba, d_buf);
13390 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
13391 * @phba: Pointer to HBA context object.
13392 * @cmd_iocbq: pointer to the command iocbq structure.
13393 * @rsp_iocbq: pointer to the response iocbq structure.
13395 * This function handles the sequence abort response iocb command complete
13396 * event. It properly releases the memory allocated to the sequence abort
13400 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
13401 struct lpfc_iocbq *cmd_iocbq,
13402 struct lpfc_iocbq *rsp_iocbq)
13405 lpfc_sli_release_iocbq(phba, cmd_iocbq);
13409 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
13410 * @phba: Pointer to HBA context object.
13411 * @xri: xri id in transaction.
13413 * This function validates the xri maps to the known range of XRIs allocated an
13414 * used by the driver.
13417 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
13422 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
13423 if (xri == phba->sli4_hba.xri_ids[i])
13431 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
13432 * @phba: Pointer to HBA context object.
13433 * @fc_hdr: pointer to a FC frame header.
13435 * This function sends a basic response to a previous unsol sequence abort
13436 * event after aborting the sequence handling.
13439 lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
13440 struct fc_frame_header *fc_hdr)
13442 struct lpfc_iocbq *ctiocb = NULL;
13443 struct lpfc_nodelist *ndlp;
13444 uint16_t oxid, rxid;
13445 uint32_t sid, fctl;
13449 if (!lpfc_is_link_up(phba))
13452 sid = sli4_sid_from_fc_hdr(fc_hdr);
13453 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
13454 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
13456 ndlp = lpfc_findnode_did(phba->pport, sid);
13458 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
13459 "1268 Find ndlp returned NULL for oxid:x%x "
13460 "SID:x%x\n", oxid, sid);
13463 if (lpfc_sli4_xri_inrange(phba, rxid))
13464 lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
13466 /* Allocate buffer for rsp iocb */
13467 ctiocb = lpfc_sli_get_iocbq(phba);
13471 /* Extract the F_CTL field from FC_HDR */
13472 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
13474 icmd = &ctiocb->iocb;
13475 icmd->un.xseq64.bdl.bdeSize = 0;
13476 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
13477 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
13478 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
13479 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
13481 /* Fill in the rest of iocb fields */
13482 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
13483 icmd->ulpBdeCount = 0;
13485 icmd->ulpClass = CLASS3;
13486 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
13487 ctiocb->context1 = ndlp;
13489 ctiocb->iocb_cmpl = NULL;
13490 ctiocb->vport = phba->pport;
13491 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
13492 ctiocb->sli4_lxritag = NO_XRI;
13493 ctiocb->sli4_xritag = NO_XRI;
13495 /* If the oxid maps to the FCP XRI range or if it is out of range,
13496 * send a BLS_RJT. The driver no longer has that exchange.
13497 * Override the IOCB for a BA_RJT.
13499 if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
13500 phba->sli4_hba.max_cfg_param.xri_base) ||
13501 oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
13502 phba->sli4_hba.max_cfg_param.xri_base)) {
13503 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
13504 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
13505 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
13506 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
13509 if (fctl & FC_FC_EX_CTX) {
13510 /* ABTS sent by responder to CT exchange, construction
13511 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
13512 * field and RX_ID from ABTS for RX_ID field.
13514 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
13515 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
13517 /* ABTS sent by initiator to CT exchange, construction
13518 * of BA_ACC will need to allocate a new XRI as for the
13519 * XRI_TAG and RX_ID fields.
13521 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
13522 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
13524 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
13526 /* Xmit CT abts response on exchange <xid> */
13527 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
13528 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
13529 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
13531 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
13532 if (rc == IOCB_ERROR) {
13533 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
13534 "2925 Failed to issue CT ABTS RSP x%x on "
13535 "xri x%x, Data x%x\n",
13536 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
13538 lpfc_sli_release_iocbq(phba, ctiocb);
13543 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
13544 * @vport: Pointer to the vport on which this sequence was received
13545 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13547 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
13548 * receive sequence is only partially assembed by the driver, it shall abort
13549 * the partially assembled frames for the sequence. Otherwise, if the
13550 * unsolicited receive sequence has been completely assembled and passed to
13551 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
13552 * unsolicited sequence has been aborted. After that, it will issue a basic
13553 * accept to accept the abort.
13556 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
13557 struct hbq_dmabuf *dmabuf)
13559 struct lpfc_hba *phba = vport->phba;
13560 struct fc_frame_header fc_hdr;
13564 /* Make a copy of fc_hdr before the dmabuf being released */
13565 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
13566 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
13568 if (fctl & FC_FC_EX_CTX) {
13570 * ABTS sent by responder to exchange, just free the buffer
13572 lpfc_in_buf_free(phba, &dmabuf->dbuf);
13575 * ABTS sent by initiator to exchange, need to do cleanup
13577 /* Try to abort partially assembled seq */
13578 abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
13580 /* Send abort to ULP if partially seq abort failed */
13581 if (abts_par == false)
13582 lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
13584 lpfc_in_buf_free(phba, &dmabuf->dbuf);
13586 /* Send basic accept (BA_ACC) to the abort requester */
13587 lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
13591 * lpfc_seq_complete - Indicates if a sequence is complete
13592 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13594 * This function checks the sequence, starting with the frame described by
13595 * @dmabuf, to see if all the frames associated with this sequence are present.
13596 * the frames associated with this sequence are linked to the @dmabuf using the
13597 * dbuf list. This function looks for two major things. 1) That the first frame
13598 * has a sequence count of zero. 2) There is a frame with last frame of sequence
13599 * set. 3) That there are no holes in the sequence count. The function will
13600 * return 1 when the sequence is complete, otherwise it will return 0.
13603 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
13605 struct fc_frame_header *hdr;
13606 struct lpfc_dmabuf *d_buf;
13607 struct hbq_dmabuf *seq_dmabuf;
13611 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
13612 /* make sure first fame of sequence has a sequence count of zero */
13613 if (hdr->fh_seq_cnt != seq_count)
13615 fctl = (hdr->fh_f_ctl[0] << 16 |
13616 hdr->fh_f_ctl[1] << 8 |
13618 /* If last frame of sequence we can return success. */
13619 if (fctl & FC_FC_END_SEQ)
13621 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
13622 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
13623 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
13624 /* If there is a hole in the sequence count then fail. */
13625 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
13627 fctl = (hdr->fh_f_ctl[0] << 16 |
13628 hdr->fh_f_ctl[1] << 8 |
13630 /* If last frame of sequence we can return success. */
13631 if (fctl & FC_FC_END_SEQ)
13638 * lpfc_prep_seq - Prep sequence for ULP processing
13639 * @vport: Pointer to the vport on which this sequence was received
13640 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13642 * This function takes a sequence, described by a list of frames, and creates
13643 * a list of iocbq structures to describe the sequence. This iocbq list will be
13644 * used to issue to the generic unsolicited sequence handler. This routine
13645 * returns a pointer to the first iocbq in the list. If the function is unable
13646 * to allocate an iocbq then it throw out the received frames that were not
13647 * able to be described and return a pointer to the first iocbq. If unable to
13648 * allocate any iocbqs (including the first) this function will return NULL.
13650 static struct lpfc_iocbq *
13651 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
13653 struct hbq_dmabuf *hbq_buf;
13654 struct lpfc_dmabuf *d_buf, *n_buf;
13655 struct lpfc_iocbq *first_iocbq, *iocbq;
13656 struct fc_frame_header *fc_hdr;
13658 uint32_t len, tot_len;
13659 struct ulp_bde64 *pbde;
13661 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
13662 /* remove from receive buffer list */
13663 list_del_init(&seq_dmabuf->hbuf.list);
13664 lpfc_update_rcv_time_stamp(vport);
13665 /* get the Remote Port's SID */
13666 sid = sli4_sid_from_fc_hdr(fc_hdr);
13668 /* Get an iocbq struct to fill in. */
13669 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
13671 /* Initialize the first IOCB. */
13672 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
13673 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
13674 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
13675 first_iocbq->iocb.ulpContext = NO_XRI;
13676 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
13677 be16_to_cpu(fc_hdr->fh_ox_id);
13678 /* iocbq is prepped for internal consumption. Physical vpi. */
13679 first_iocbq->iocb.unsli3.rcvsli3.vpi =
13680 vport->phba->vpi_ids[vport->vpi];
13681 /* put the first buffer into the first IOCBq */
13682 first_iocbq->context2 = &seq_dmabuf->dbuf;
13683 first_iocbq->context3 = NULL;
13684 first_iocbq->iocb.ulpBdeCount = 1;
13685 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
13686 LPFC_DATA_BUF_SIZE;
13687 first_iocbq->iocb.un.rcvels.remoteID = sid;
13688 tot_len = bf_get(lpfc_rcqe_length,
13689 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
13690 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
13692 iocbq = first_iocbq;
13694 * Each IOCBq can have two Buffers assigned, so go through the list
13695 * of buffers for this sequence and save two buffers in each IOCBq
13697 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
13699 lpfc_in_buf_free(vport->phba, d_buf);
13702 if (!iocbq->context3) {
13703 iocbq->context3 = d_buf;
13704 iocbq->iocb.ulpBdeCount++;
13705 pbde = (struct ulp_bde64 *)
13706 &iocbq->iocb.unsli3.sli3Words[4];
13707 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
13709 /* We need to get the size out of the right CQE */
13710 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
13711 len = bf_get(lpfc_rcqe_length,
13712 &hbq_buf->cq_event.cqe.rcqe_cmpl);
13713 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
13716 iocbq = lpfc_sli_get_iocbq(vport->phba);
13719 first_iocbq->iocb.ulpStatus =
13720 IOSTAT_FCP_RSP_ERROR;
13721 first_iocbq->iocb.un.ulpWord[4] =
13722 IOERR_NO_RESOURCES;
13724 lpfc_in_buf_free(vport->phba, d_buf);
13727 iocbq->context2 = d_buf;
13728 iocbq->context3 = NULL;
13729 iocbq->iocb.ulpBdeCount = 1;
13730 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
13731 LPFC_DATA_BUF_SIZE;
13733 /* We need to get the size out of the right CQE */
13734 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
13735 len = bf_get(lpfc_rcqe_length,
13736 &hbq_buf->cq_event.cqe.rcqe_cmpl);
13738 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
13740 iocbq->iocb.un.rcvels.remoteID = sid;
13741 list_add_tail(&iocbq->list, &first_iocbq->list);
13744 return first_iocbq;
13748 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
13749 struct hbq_dmabuf *seq_dmabuf)
13751 struct fc_frame_header *fc_hdr;
13752 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
13753 struct lpfc_hba *phba = vport->phba;
13755 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
13756 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
13758 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13759 "2707 Ring %d handler: Failed to allocate "
13760 "iocb Rctl x%x Type x%x received\n",
13762 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
13765 if (!lpfc_complete_unsol_iocb(phba,
13766 &phba->sli.ring[LPFC_ELS_RING],
13767 iocbq, fc_hdr->fh_r_ctl,
13769 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13770 "2540 Ring %d handler: unexpected Rctl "
13771 "x%x Type x%x received\n",
13773 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
13775 /* Free iocb created in lpfc_prep_seq */
13776 list_for_each_entry_safe(curr_iocb, next_iocb,
13777 &iocbq->list, list) {
13778 list_del_init(&curr_iocb->list);
13779 lpfc_sli_release_iocbq(phba, curr_iocb);
13781 lpfc_sli_release_iocbq(phba, iocbq);
13785 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
13786 * @phba: Pointer to HBA context object.
13788 * This function is called with no lock held. This function processes all
13789 * the received buffers and gives it to upper layers when a received buffer
13790 * indicates that it is the final frame in the sequence. The interrupt
13791 * service routine processes received buffers at interrupt contexts and adds
13792 * received dma buffers to the rb_pend_list queue and signals the worker thread.
13793 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
13794 * appropriate receive function when the final frame in a sequence is received.
13797 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
13798 struct hbq_dmabuf *dmabuf)
13800 struct hbq_dmabuf *seq_dmabuf;
13801 struct fc_frame_header *fc_hdr;
13802 struct lpfc_vport *vport;
13805 /* Process each received buffer */
13806 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
13807 /* check to see if this a valid type of frame */
13808 if (lpfc_fc_frame_check(phba, fc_hdr)) {
13809 lpfc_in_buf_free(phba, &dmabuf->dbuf);
13812 if ((bf_get(lpfc_cqe_code,
13813 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
13814 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
13815 &dmabuf->cq_event.cqe.rcqe_cmpl);
13817 fcfi = bf_get(lpfc_rcqe_fcf_id,
13818 &dmabuf->cq_event.cqe.rcqe_cmpl);
13819 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
13820 if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
13821 /* throw out the frame */
13822 lpfc_in_buf_free(phba, &dmabuf->dbuf);
13825 /* Handle the basic abort sequence (BA_ABTS) event */
13826 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
13827 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
13831 /* Link this frame */
13832 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
13834 /* unable to add frame to vport - throw it out */
13835 lpfc_in_buf_free(phba, &dmabuf->dbuf);
13838 /* If not last frame in sequence continue processing frames. */
13839 if (!lpfc_seq_complete(seq_dmabuf))
13842 /* Send the complete sequence to the upper layer protocol */
13843 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
13847 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
13848 * @phba: pointer to lpfc hba data structure.
13850 * This routine is invoked to post rpi header templates to the
13851 * HBA consistent with the SLI-4 interface spec. This routine
13852 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13853 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13855 * This routine does not require any locks. It's usage is expected
13856 * to be driver load or reset recovery when the driver is
13861 * -EIO - The mailbox failed to complete successfully.
13862 * When this error occurs, the driver is not guaranteed
13863 * to have any rpi regions posted to the device and
13864 * must either attempt to repost the regions or take a
13868 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
13870 struct lpfc_rpi_hdr *rpi_page;
13874 /* SLI4 ports that support extents do not require RPI headers. */
13875 if (!phba->sli4_hba.rpi_hdrs_in_use)
13877 if (phba->sli4_hba.extents_in_use)
13880 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
13882 * Assign the rpi headers a physical rpi only if the driver
13883 * has not initialized those resources. A port reset only
13884 * needs the headers posted.
13886 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
13888 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
13890 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
13891 if (rc != MBX_SUCCESS) {
13892 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13893 "2008 Error %d posting all rpi "
13901 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
13902 LPFC_RPI_RSRC_RDY);
13907 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
13908 * @phba: pointer to lpfc hba data structure.
13909 * @rpi_page: pointer to the rpi memory region.
13911 * This routine is invoked to post a single rpi header to the
13912 * HBA consistent with the SLI-4 interface spec. This memory region
13913 * maps up to 64 rpi context regions.
13917 * -ENOMEM - No available memory
13918 * -EIO - The mailbox failed to complete successfully.
13921 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
13923 LPFC_MBOXQ_t *mboxq;
13924 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
13926 uint32_t shdr_status, shdr_add_status;
13927 union lpfc_sli4_cfg_shdr *shdr;
13929 /* SLI4 ports that support extents do not require RPI headers. */
13930 if (!phba->sli4_hba.rpi_hdrs_in_use)
13932 if (phba->sli4_hba.extents_in_use)
13935 /* The port is notified of the header region via a mailbox command. */
13936 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13938 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13939 "2001 Unable to allocate memory for issuing "
13940 "SLI_CONFIG_SPECIAL mailbox command\n");
13944 /* Post all rpi memory regions to the port. */
13945 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
13946 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
13947 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
13948 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
13949 sizeof(struct lpfc_sli4_cfg_mhdr),
13950 LPFC_SLI4_MBX_EMBED);
13953 /* Post the physical rpi to the port for this rpi header. */
13954 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
13955 rpi_page->start_rpi);
13956 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
13957 hdr_tmpl, rpi_page->page_count);
13959 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
13960 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
13961 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13962 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
13963 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13964 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13965 if (rc != MBX_TIMEOUT)
13966 mempool_free(mboxq, phba->mbox_mem_pool);
13967 if (shdr_status || shdr_add_status || rc) {
13968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13969 "2514 POST_RPI_HDR mailbox failed with "
13970 "status x%x add_status x%x, mbx status x%x\n",
13971 shdr_status, shdr_add_status, rc);
13978 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
13979 * @phba: pointer to lpfc hba data structure.
13981 * This routine is invoked to post rpi header templates to the
13982 * HBA consistent with the SLI-4 interface spec. This routine
13983 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13984 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13987 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13988 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13991 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
13994 uint16_t max_rpi, rpi_limit;
13995 uint16_t rpi_remaining, lrpi = 0;
13996 struct lpfc_rpi_hdr *rpi_hdr;
13998 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
13999 rpi_limit = phba->sli4_hba.next_rpi;
14002 * Fetch the next logical rpi. Because this index is logical,
14003 * the driver starts at 0 each time.
14005 spin_lock_irq(&phba->hbalock);
14006 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
14007 if (rpi >= rpi_limit)
14008 rpi = LPFC_RPI_ALLOC_ERROR;
14010 set_bit(rpi, phba->sli4_hba.rpi_bmask);
14011 phba->sli4_hba.max_cfg_param.rpi_used++;
14012 phba->sli4_hba.rpi_count++;
14016 * Don't try to allocate more rpi header regions if the device limit
14017 * has been exhausted.
14019 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
14020 (phba->sli4_hba.rpi_count >= max_rpi)) {
14021 spin_unlock_irq(&phba->hbalock);
14026 * RPI header postings are not required for SLI4 ports capable of
14029 if (!phba->sli4_hba.rpi_hdrs_in_use) {
14030 spin_unlock_irq(&phba->hbalock);
14035 * If the driver is running low on rpi resources, allocate another
14036 * page now. Note that the next_rpi value is used because
14037 * it represents how many are actually in use whereas max_rpi notes
14038 * how many are supported max by the device.
14040 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
14041 spin_unlock_irq(&phba->hbalock);
14042 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
14043 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
14045 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14046 "2002 Error Could not grow rpi "
14049 lrpi = rpi_hdr->start_rpi;
14050 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
14051 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
14059 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14060 * @phba: pointer to lpfc hba data structure.
14062 * This routine is invoked to release an rpi to the pool of
14063 * available rpis maintained by the driver.
14066 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
14068 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
14069 phba->sli4_hba.rpi_count--;
14070 phba->sli4_hba.max_cfg_param.rpi_used--;
14075 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14076 * @phba: pointer to lpfc hba data structure.
14078 * This routine is invoked to release an rpi to the pool of
14079 * available rpis maintained by the driver.
14082 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
14084 spin_lock_irq(&phba->hbalock);
14085 __lpfc_sli4_free_rpi(phba, rpi);
14086 spin_unlock_irq(&phba->hbalock);
14090 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14091 * @phba: pointer to lpfc hba data structure.
14093 * This routine is invoked to remove the memory region that
14094 * provided rpi via a bitmask.
14097 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
14099 kfree(phba->sli4_hba.rpi_bmask);
14100 kfree(phba->sli4_hba.rpi_ids);
14101 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
14105 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14106 * @phba: pointer to lpfc hba data structure.
14108 * This routine is invoked to remove the memory region that
14109 * provided rpi via a bitmask.
14112 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
14114 LPFC_MBOXQ_t *mboxq;
14115 struct lpfc_hba *phba = ndlp->phba;
14118 /* The port is notified of the header region via a mailbox command. */
14119 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14123 /* Post all rpi memory regions to the port. */
14124 lpfc_resume_rpi(mboxq, ndlp);
14125 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14126 if (rc == MBX_NOT_FINISHED) {
14127 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14128 "2010 Resume RPI Mailbox failed "
14129 "status %d, mbxStatus x%x\n", rc,
14130 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
14131 mempool_free(mboxq, phba->mbox_mem_pool);
14138 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14139 * @vport: Pointer to the vport for which the vpi is being initialized
14141 * This routine is invoked to activate a vpi with the port.
14145 * -Evalue otherwise
14148 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
14150 LPFC_MBOXQ_t *mboxq;
14152 int retval = MBX_SUCCESS;
14154 struct lpfc_hba *phba = vport->phba;
14155 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14158 lpfc_init_vpi(phba, mboxq, vport->vpi);
14159 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
14160 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
14161 if (rc != MBX_SUCCESS) {
14162 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
14163 "2022 INIT VPI Mailbox failed "
14164 "status %d, mbxStatus x%x\n", rc,
14165 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
14168 if (rc != MBX_TIMEOUT)
14169 mempool_free(mboxq, vport->phba->mbox_mem_pool);
14175 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14176 * @phba: pointer to lpfc hba data structure.
14177 * @mboxq: Pointer to mailbox object.
14179 * This routine is invoked to manually add a single FCF record. The caller
14180 * must pass a completely initialized FCF_Record. This routine takes
14181 * care of the nonembedded mailbox operations.
14184 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
14187 union lpfc_sli4_cfg_shdr *shdr;
14188 uint32_t shdr_status, shdr_add_status;
14190 virt_addr = mboxq->sge_array->addr[0];
14191 /* The IOCTL status is embedded in the mailbox subheader. */
14192 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
14193 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14194 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14196 if ((shdr_status || shdr_add_status) &&
14197 (shdr_status != STATUS_FCF_IN_USE))
14198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14199 "2558 ADD_FCF_RECORD mailbox failed with "
14200 "status x%x add_status x%x\n",
14201 shdr_status, shdr_add_status);
14203 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14207 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14208 * @phba: pointer to lpfc hba data structure.
14209 * @fcf_record: pointer to the initialized fcf record to add.
14211 * This routine is invoked to manually add a single FCF record. The caller
14212 * must pass a completely initialized FCF_Record. This routine takes
14213 * care of the nonembedded mailbox operations.
14216 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
14219 LPFC_MBOXQ_t *mboxq;
14222 dma_addr_t phys_addr;
14223 struct lpfc_mbx_sge sge;
14224 uint32_t alloc_len, req_len;
14227 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14229 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14230 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14234 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
14237 /* Allocate DMA memory and set up the non-embedded mailbox command */
14238 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
14239 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
14240 req_len, LPFC_SLI4_MBX_NEMBED);
14241 if (alloc_len < req_len) {
14242 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14243 "2523 Allocated DMA memory size (x%x) is "
14244 "less than the requested DMA memory "
14245 "size (x%x)\n", alloc_len, req_len);
14246 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14251 * Get the first SGE entry from the non-embedded DMA memory. This
14252 * routine only uses a single SGE.
14254 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
14255 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
14256 virt_addr = mboxq->sge_array->addr[0];
14258 * Configure the FCF record for FCFI 0. This is the driver's
14259 * hardcoded default and gets used in nonFIP mode.
14261 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
14262 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
14263 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
14266 * Copy the fcf_index and the FCF Record Data. The data starts after
14267 * the FCoE header plus word10. The data copy needs to be endian
14270 bytep += sizeof(uint32_t);
14271 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
14272 mboxq->vport = phba->pport;
14273 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
14274 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14275 if (rc == MBX_NOT_FINISHED) {
14276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14277 "2515 ADD_FCF_RECORD mailbox failed with "
14278 "status 0x%x\n", rc);
14279 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14288 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
14289 * @phba: pointer to lpfc hba data structure.
14290 * @fcf_record: pointer to the fcf record to write the default data.
14291 * @fcf_index: FCF table entry index.
14293 * This routine is invoked to build the driver's default FCF record. The
14294 * values used are hardcoded. This routine handles memory initialization.
14298 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
14299 struct fcf_record *fcf_record,
14300 uint16_t fcf_index)
14302 memset(fcf_record, 0, sizeof(struct fcf_record));
14303 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
14304 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
14305 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
14306 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
14307 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
14308 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
14309 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
14310 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
14311 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
14312 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
14313 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
14314 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
14315 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
14316 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
14317 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
14318 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
14319 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
14320 /* Set the VLAN bit map */
14321 if (phba->valid_vlan) {
14322 fcf_record->vlan_bitmap[phba->vlan_id / 8]
14323 = 1 << (phba->vlan_id % 8);
14328 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
14329 * @phba: pointer to lpfc hba data structure.
14330 * @fcf_index: FCF table entry offset.
14332 * This routine is invoked to scan the entire FCF table by reading FCF
14333 * record and processing it one at a time starting from the @fcf_index
14334 * for initial FCF discovery or fast FCF failover rediscovery.
14336 * Return 0 if the mailbox command is submitted successfully, none 0
14340 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
14343 LPFC_MBOXQ_t *mboxq;
14345 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
14346 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14349 "2000 Failed to allocate mbox for "
14352 goto fail_fcf_scan;
14354 /* Construct the read FCF record mailbox command */
14355 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
14358 goto fail_fcf_scan;
14360 /* Issue the mailbox command asynchronously */
14361 mboxq->vport = phba->pport;
14362 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
14364 spin_lock_irq(&phba->hbalock);
14365 phba->hba_flag |= FCF_TS_INPROG;
14366 spin_unlock_irq(&phba->hbalock);
14368 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14369 if (rc == MBX_NOT_FINISHED)
14372 /* Reset eligible FCF count for new scan */
14373 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
14374 phba->fcf.eligible_fcf_cnt = 0;
14380 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14381 /* FCF scan failed, clear FCF_TS_INPROG flag */
14382 spin_lock_irq(&phba->hbalock);
14383 phba->hba_flag &= ~FCF_TS_INPROG;
14384 spin_unlock_irq(&phba->hbalock);
14390 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
14391 * @phba: pointer to lpfc hba data structure.
14392 * @fcf_index: FCF table entry offset.
14394 * This routine is invoked to read an FCF record indicated by @fcf_index
14395 * and to use it for FLOGI roundrobin FCF failover.
14397 * Return 0 if the mailbox command is submitted successfully, none 0
14401 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
14404 LPFC_MBOXQ_t *mboxq;
14406 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14408 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
14409 "2763 Failed to allocate mbox for "
14412 goto fail_fcf_read;
14414 /* Construct the read FCF record mailbox command */
14415 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
14418 goto fail_fcf_read;
14420 /* Issue the mailbox command asynchronously */
14421 mboxq->vport = phba->pport;
14422 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
14423 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14424 if (rc == MBX_NOT_FINISHED)
14430 if (error && mboxq)
14431 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14436 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
14437 * @phba: pointer to lpfc hba data structure.
14438 * @fcf_index: FCF table entry offset.
14440 * This routine is invoked to read an FCF record indicated by @fcf_index to
14441 * determine whether it's eligible for FLOGI roundrobin failover list.
14443 * Return 0 if the mailbox command is submitted successfully, none 0
14447 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
14450 LPFC_MBOXQ_t *mboxq;
14452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14454 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
14455 "2758 Failed to allocate mbox for "
14458 goto fail_fcf_read;
14460 /* Construct the read FCF record mailbox command */
14461 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
14464 goto fail_fcf_read;
14466 /* Issue the mailbox command asynchronously */
14467 mboxq->vport = phba->pport;
14468 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
14469 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14470 if (rc == MBX_NOT_FINISHED)
14476 if (error && mboxq)
14477 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14482 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
14483 * @phba: pointer to lpfc hba data structure.
14485 * This routine is to get the next eligible FCF record index in a round
14486 * robin fashion. If the next eligible FCF record index equals to the
14487 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
14488 * shall be returned, otherwise, the next eligible FCF record's index
14489 * shall be returned.
14492 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
14494 uint16_t next_fcf_index;
14496 /* Search start from next bit of currently registered FCF index */
14497 next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
14498 LPFC_SLI4_FCF_TBL_INDX_MAX;
14499 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
14500 LPFC_SLI4_FCF_TBL_INDX_MAX,
14503 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
14504 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
14505 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
14506 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
14508 /* Check roundrobin failover list empty condition */
14509 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
14510 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
14511 "2844 No roundrobin failover FCF available\n");
14512 return LPFC_FCOE_FCF_NEXT_NONE;
14515 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
14516 "2845 Get next roundrobin failover FCF (x%x)\n",
14519 return next_fcf_index;
14523 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
14524 * @phba: pointer to lpfc hba data structure.
14526 * This routine sets the FCF record index in to the eligible bmask for
14527 * roundrobin failover search. It checks to make sure that the index
14528 * does not go beyond the range of the driver allocated bmask dimension
14529 * before setting the bit.
14531 * Returns 0 if the index bit successfully set, otherwise, it returns
14535 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
14537 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
14538 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
14539 "2610 FCF (x%x) reached driver's book "
14540 "keeping dimension:x%x\n",
14541 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
14544 /* Set the eligible FCF record index bmask */
14545 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
14547 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
14548 "2790 Set FCF (x%x) to roundrobin FCF failover "
14549 "bmask\n", fcf_index);
14555 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
14556 * @phba: pointer to lpfc hba data structure.
14558 * This routine clears the FCF record index from the eligible bmask for
14559 * roundrobin failover search. It checks to make sure that the index
14560 * does not go beyond the range of the driver allocated bmask dimension
14561 * before clearing the bit.
14564 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
14566 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
14567 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
14568 "2762 FCF (x%x) reached driver's book "
14569 "keeping dimension:x%x\n",
14570 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
14573 /* Clear the eligible FCF record index bmask */
14574 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
14576 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
14577 "2791 Clear FCF (x%x) from roundrobin failover "
14578 "bmask\n", fcf_index);
14582 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
14583 * @phba: pointer to lpfc hba data structure.
14585 * This routine is the completion routine for the rediscover FCF table mailbox
14586 * command. If the mailbox command returned failure, it will try to stop the
14587 * FCF rediscover wait timer.
14590 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
14592 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
14593 uint32_t shdr_status, shdr_add_status;
14595 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
14597 shdr_status = bf_get(lpfc_mbox_hdr_status,
14598 &redisc_fcf->header.cfg_shdr.response);
14599 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
14600 &redisc_fcf->header.cfg_shdr.response);
14601 if (shdr_status || shdr_add_status) {
14602 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
14603 "2746 Requesting for FCF rediscovery failed "
14604 "status x%x add_status x%x\n",
14605 shdr_status, shdr_add_status);
14606 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
14607 spin_lock_irq(&phba->hbalock);
14608 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
14609 spin_unlock_irq(&phba->hbalock);
14611 * CVL event triggered FCF rediscover request failed,
14612 * last resort to re-try current registered FCF entry.
14614 lpfc_retry_pport_discovery(phba);
14616 spin_lock_irq(&phba->hbalock);
14617 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
14618 spin_unlock_irq(&phba->hbalock);
14620 * DEAD FCF event triggered FCF rediscover request
14621 * failed, last resort to fail over as a link down
14622 * to FCF registration.
14624 lpfc_sli4_fcf_dead_failthrough(phba);
14627 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
14628 "2775 Start FCF rediscover quiescent timer\n");
14630 * Start FCF rediscovery wait timer for pending FCF
14631 * before rescan FCF record table.
14633 lpfc_fcf_redisc_wait_start_timer(phba);
14636 mempool_free(mbox, phba->mbox_mem_pool);
14640 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
14641 * @phba: pointer to lpfc hba data structure.
14643 * This routine is invoked to request for rediscovery of the entire FCF table
14647 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
14649 LPFC_MBOXQ_t *mbox;
14650 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
14653 /* Cancel retry delay timers to all vports before FCF rediscover */
14654 lpfc_cancel_all_vport_retry_delay_timer(phba);
14656 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14658 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14659 "2745 Failed to allocate mbox for "
14660 "requesting FCF rediscover.\n");
14664 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
14665 sizeof(struct lpfc_sli4_cfg_mhdr));
14666 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14667 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
14668 length, LPFC_SLI4_MBX_EMBED);
14670 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
14671 /* Set count to 0 for invalidating the entire FCF database */
14672 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
14674 /* Issue the mailbox command asynchronously */
14675 mbox->vport = phba->pport;
14676 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
14677 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
14679 if (rc == MBX_NOT_FINISHED) {
14680 mempool_free(mbox, phba->mbox_mem_pool);
14687 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
14688 * @phba: pointer to lpfc hba data structure.
14690 * This function is the failover routine as a last resort to the FCF DEAD
14691 * event when driver failed to perform fast FCF failover.
14694 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
14696 uint32_t link_state;
14699 * Last resort as FCF DEAD event failover will treat this as
14700 * a link down, but save the link state because we don't want
14701 * it to be changed to Link Down unless it is already down.
14703 link_state = phba->link_state;
14704 lpfc_linkdown(phba);
14705 phba->link_state = link_state;
14707 /* Unregister FCF if no devices connected to it */
14708 lpfc_unregister_unused_fcf(phba);
14712 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
14713 * @phba: pointer to lpfc hba data structure.
14715 * This function read region 23 and parse TLV for port status to
14716 * decide if the user disaled the port. If the TLV indicates the
14717 * port is disabled, the hba_flag is set accordingly.
14720 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
14722 LPFC_MBOXQ_t *pmb = NULL;
14724 uint8_t *rgn23_data = NULL;
14725 uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
14728 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14731 "2600 lpfc_sli_read_serdes_param failed to"
14732 " allocate mailbox memory\n");
14737 /* Get adapter Region 23 data */
14738 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
14743 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
14744 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
14746 if (rc != MBX_SUCCESS) {
14747 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14748 "2601 lpfc_sli_read_link_ste failed to"
14749 " read config region 23 rc 0x%x Status 0x%x\n",
14750 rc, mb->mbxStatus);
14751 mb->un.varDmp.word_cnt = 0;
14754 * dump mem may return a zero when finished or we got a
14755 * mailbox error, either way we are done.
14757 if (mb->un.varDmp.word_cnt == 0)
14759 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
14760 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
14762 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
14763 rgn23_data + offset,
14764 mb->un.varDmp.word_cnt);
14765 offset += mb->un.varDmp.word_cnt;
14766 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
14768 data_size = offset;
14774 /* Check the region signature first */
14775 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
14776 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14777 "2619 Config region 23 has bad signature\n");
14782 /* Check the data structure version */
14783 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
14784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14785 "2620 Config region 23 has bad version\n");
14790 /* Parse TLV entries in the region */
14791 while (offset < data_size) {
14792 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
14795 * If the TLV is not driver specific TLV or driver id is
14796 * not linux driver id, skip the record.
14798 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
14799 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
14800 (rgn23_data[offset + 3] != 0)) {
14801 offset += rgn23_data[offset + 1] * 4 + 4;
14805 /* Driver found a driver specific TLV in the config region */
14806 sub_tlv_len = rgn23_data[offset + 1] * 4;
14811 * Search for configured port state sub-TLV.
14813 while ((offset < data_size) &&
14814 (tlv_offset < sub_tlv_len)) {
14815 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
14820 if (rgn23_data[offset] != PORT_STE_TYPE) {
14821 offset += rgn23_data[offset + 1] * 4 + 4;
14822 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
14826 /* This HBA contains PORT_STE configured */
14827 if (!rgn23_data[offset + 2])
14828 phba->hba_flag |= LINK_DISABLED;
14835 mempool_free(pmb, phba->mbox_mem_pool);
14841 * lpfc_wr_object - write an object to the firmware
14842 * @phba: HBA structure that indicates port to create a queue on.
14843 * @dmabuf_list: list of dmabufs to write to the port.
14844 * @size: the total byte value of the objects to write to the port.
14845 * @offset: the current offset to be used to start the transfer.
14847 * This routine will create a wr_object mailbox command to send to the port.
14848 * the mailbox command will be constructed using the dma buffers described in
14849 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
14850 * BDEs that the imbedded mailbox can support. The @offset variable will be
14851 * used to indicate the starting offset of the transfer and will also return
14852 * the offset after the write object mailbox has completed. @size is used to
14853 * determine the end of the object and whether the eof bit should be set.
14855 * Return 0 is successful and offset will contain the the new offset to use
14856 * for the next write.
14857 * Return negative value for error cases.
14860 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
14861 uint32_t size, uint32_t *offset)
14863 struct lpfc_mbx_wr_object *wr_object;
14864 LPFC_MBOXQ_t *mbox;
14866 uint32_t shdr_status, shdr_add_status;
14868 union lpfc_sli4_cfg_shdr *shdr;
14869 struct lpfc_dmabuf *dmabuf;
14870 uint32_t written = 0;
14872 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14876 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14877 LPFC_MBOX_OPCODE_WRITE_OBJECT,
14878 sizeof(struct lpfc_mbx_wr_object) -
14879 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
14881 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
14882 wr_object->u.request.write_offset = *offset;
14883 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
14884 wr_object->u.request.object_name[0] =
14885 cpu_to_le32(wr_object->u.request.object_name[0]);
14886 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
14887 list_for_each_entry(dmabuf, dmabuf_list, list) {
14888 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
14890 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
14891 wr_object->u.request.bde[i].addrHigh =
14892 putPaddrHigh(dmabuf->phys);
14893 if (written + SLI4_PAGE_SIZE >= size) {
14894 wr_object->u.request.bde[i].tus.f.bdeSize =
14896 written += (size - written);
14897 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
14899 wr_object->u.request.bde[i].tus.f.bdeSize =
14901 written += SLI4_PAGE_SIZE;
14905 wr_object->u.request.bde_count = i;
14906 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
14907 if (!phba->sli4_hba.intr_enable)
14908 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14910 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
14911 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
14913 /* The IOCTL status is embedded in the mailbox subheader. */
14914 shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
14915 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14916 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14917 if (rc != MBX_TIMEOUT)
14918 mempool_free(mbox, phba->mbox_mem_pool);
14919 if (shdr_status || shdr_add_status || rc) {
14920 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14921 "3025 Write Object mailbox failed with "
14922 "status x%x add_status x%x, mbx status x%x\n",
14923 shdr_status, shdr_add_status, rc);
14926 *offset += wr_object->u.response.actual_write_length;
14931 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
14932 * @vport: pointer to vport data structure.
14934 * This function iterate through the mailboxq and clean up all REG_LOGIN
14935 * and REG_VPI mailbox commands associated with the vport. This function
14936 * is called when driver want to restart discovery of the vport due to
14937 * a Clear Virtual Link event.
14940 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
14942 struct lpfc_hba *phba = vport->phba;
14943 LPFC_MBOXQ_t *mb, *nextmb;
14944 struct lpfc_dmabuf *mp;
14945 struct lpfc_nodelist *ndlp;
14946 struct lpfc_nodelist *act_mbx_ndlp = NULL;
14947 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
14948 LIST_HEAD(mbox_cmd_list);
14949 uint8_t restart_loop;
14951 /* Clean up internally queued mailbox commands with the vport */
14952 spin_lock_irq(&phba->hbalock);
14953 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
14954 if (mb->vport != vport)
14957 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
14958 (mb->u.mb.mbxCommand != MBX_REG_VPI))
14961 list_del(&mb->list);
14962 list_add_tail(&mb->list, &mbox_cmd_list);
14964 /* Clean up active mailbox command with the vport */
14965 mb = phba->sli.mbox_active;
14966 if (mb && (mb->vport == vport)) {
14967 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
14968 (mb->u.mb.mbxCommand == MBX_REG_VPI))
14969 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14970 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
14971 act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
14972 /* Put reference count for delayed processing */
14973 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
14974 /* Unregister the RPI when mailbox complete */
14975 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
14978 /* Cleanup any mailbox completions which are not yet processed */
14981 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
14983 * If this mailox is already processed or it is
14984 * for another vport ignore it.
14986 if ((mb->vport != vport) ||
14987 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
14990 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
14991 (mb->u.mb.mbxCommand != MBX_REG_VPI))
14994 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14995 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
14996 ndlp = (struct lpfc_nodelist *)mb->context2;
14997 /* Unregister the RPI when mailbox complete */
14998 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
15000 spin_unlock_irq(&phba->hbalock);
15001 spin_lock(shost->host_lock);
15002 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
15003 spin_unlock(shost->host_lock);
15004 spin_lock_irq(&phba->hbalock);
15008 } while (restart_loop);
15010 spin_unlock_irq(&phba->hbalock);
15012 /* Release the cleaned-up mailbox commands */
15013 while (!list_empty(&mbox_cmd_list)) {
15014 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
15015 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
15016 mp = (struct lpfc_dmabuf *) (mb->context1);
15018 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
15021 ndlp = (struct lpfc_nodelist *) mb->context2;
15022 mb->context2 = NULL;
15024 spin_lock(shost->host_lock);
15025 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
15026 spin_unlock(shost->host_lock);
15027 lpfc_nlp_put(ndlp);
15030 mempool_free(mb, phba->mbox_mem_pool);
15033 /* Release the ndlp with the cleaned-up active mailbox command */
15034 if (act_mbx_ndlp) {
15035 spin_lock(shost->host_lock);
15036 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
15037 spin_unlock(shost->host_lock);
15038 lpfc_nlp_put(act_mbx_ndlp);
15043 * lpfc_drain_txq - Drain the txq
15044 * @phba: Pointer to HBA context object.
15046 * This function attempt to submit IOCBs on the txq
15047 * to the adapter. For SLI4 adapters, the txq contains
15048 * ELS IOCBs that have been deferred because the there
15049 * are no SGLs. This congestion can occur with large
15050 * vport counts during node discovery.
15054 lpfc_drain_txq(struct lpfc_hba *phba)
15056 LIST_HEAD(completions);
15057 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
15058 struct lpfc_iocbq *piocbq = 0;
15059 unsigned long iflags = 0;
15060 char *fail_msg = NULL;
15061 struct lpfc_sglq *sglq;
15062 union lpfc_wqe wqe;
15064 spin_lock_irqsave(&phba->hbalock, iflags);
15065 if (pring->txq_cnt > pring->txq_max)
15066 pring->txq_max = pring->txq_cnt;
15068 spin_unlock_irqrestore(&phba->hbalock, iflags);
15070 while (pring->txq_cnt) {
15071 spin_lock_irqsave(&phba->hbalock, iflags);
15073 piocbq = lpfc_sli_ringtx_get(phba, pring);
15074 sglq = __lpfc_sli_get_sglq(phba, piocbq);
15076 __lpfc_sli_ringtx_put(phba, pring, piocbq);
15077 spin_unlock_irqrestore(&phba->hbalock, iflags);
15081 /* The txq_cnt out of sync. This should
15084 sglq = __lpfc_clear_active_sglq(phba,
15085 sglq->sli4_lxritag);
15086 spin_unlock_irqrestore(&phba->hbalock, iflags);
15087 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15088 "2823 txq empty and txq_cnt is %d\n ",
15094 /* The xri and iocb resources secured,
15095 * attempt to issue request
15097 piocbq->sli4_lxritag = sglq->sli4_lxritag;
15098 piocbq->sli4_xritag = sglq->sli4_xritag;
15099 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
15100 fail_msg = "to convert bpl to sgl";
15101 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
15102 fail_msg = "to convert iocb to wqe";
15103 else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
15104 fail_msg = " - Wq is full";
15106 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
15109 /* Failed means we can't issue and need to cancel */
15110 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15111 "2822 IOCB failed %s iotag 0x%x "
15114 piocbq->iotag, piocbq->sli4_xritag);
15115 list_add_tail(&piocbq->list, &completions);
15117 spin_unlock_irqrestore(&phba->hbalock, iflags);
15120 /* Cancel all the IOCBs that cannot be issued */
15121 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
15122 IOERR_SLI_ABORTED);
15124 return pring->txq_cnt;