1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <linux/aer.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
48 #include "lpfc_vport.h"
50 /* There are only four IOCB completion types. */
51 typedef enum _lpfc_iocb_type {
59 /* Provide function prototypes local to this module. */
60 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
62 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
63 uint8_t *, uint32_t *);
64 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
66 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
70 static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
72 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
76 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
82 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
83 * @q: The Work Queue to operate on.
84 * @wqe: The work Queue Entry to put on the Work queue.
86 * This routine will copy the contents of @wqe to the next available entry on
87 * the @q. This function will then ring the Work Queue Doorbell to signal the
88 * HBA to start processing the Work Queue Entry. This function returns 0 if
89 * successful. If no entries are available on @q then this function will return
91 * The caller is expected to hold the hbalock when calling this routine.
94 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
96 union lpfc_wqe *temp_wqe;
97 struct lpfc_register doorbell;
101 /* sanity check on queue memory */
104 temp_wqe = q->qe[q->host_index].wqe;
106 /* If the host has not yet processed the next entry then we are done */
107 idx = ((q->host_index + 1) % q->entry_count);
108 if (idx == q->hba_index) {
113 /* set consumption flag every once in a while */
114 if (!((q->host_index + 1) % q->entry_repost))
115 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
116 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
117 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
118 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
120 /* Update the host index before invoking device */
121 host_index = q->host_index;
127 bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
128 bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
129 bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
130 writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
136 * lpfc_sli4_wq_release - Updates internal hba index for WQ
137 * @q: The Work Queue to operate on.
138 * @index: The index to advance the hba index to.
140 * This routine will update the HBA index of a queue to reflect consumption of
141 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
142 * an entry the host calls this function to update the queue's internal
143 * pointers. This routine returns the number of entries that were consumed by
147 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
149 uint32_t released = 0;
151 /* sanity check on queue memory */
155 if (q->hba_index == index)
158 q->hba_index = ((q->hba_index + 1) % q->entry_count);
160 } while (q->hba_index != index);
165 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
166 * @q: The Mailbox Queue to operate on.
167 * @wqe: The Mailbox Queue Entry to put on the Work queue.
169 * This routine will copy the contents of @mqe to the next available entry on
170 * the @q. This function will then ring the Work Queue Doorbell to signal the
171 * HBA to start processing the Work Queue Entry. This function returns 0 if
172 * successful. If no entries are available on @q then this function will return
174 * The caller is expected to hold the hbalock when calling this routine.
177 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
179 struct lpfc_mqe *temp_mqe;
180 struct lpfc_register doorbell;
183 /* sanity check on queue memory */
186 temp_mqe = q->qe[q->host_index].mqe;
188 /* If the host has not yet processed the next entry then we are done */
189 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
191 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
192 /* Save off the mailbox pointer for completion */
193 q->phba->mbox = (MAILBOX_t *)temp_mqe;
195 /* Update the host index before invoking device */
196 host_index = q->host_index;
197 q->host_index = ((q->host_index + 1) % q->entry_count);
201 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
202 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
203 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
208 * lpfc_sli4_mq_release - Updates internal hba index for MQ
209 * @q: The Mailbox Queue to operate on.
211 * This routine will update the HBA index of a queue to reflect consumption of
212 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
213 * an entry the host calls this function to update the queue's internal
214 * pointers. This routine returns the number of entries that were consumed by
218 lpfc_sli4_mq_release(struct lpfc_queue *q)
220 /* sanity check on queue memory */
224 /* Clear the mailbox pointer for completion */
225 q->phba->mbox = NULL;
226 q->hba_index = ((q->hba_index + 1) % q->entry_count);
231 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
232 * @q: The Event Queue to get the first valid EQE from
234 * This routine will get the first valid Event Queue Entry from @q, update
235 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
236 * the Queue (no more work to do), or the Queue is full of EQEs that have been
237 * processed, but not popped back to the HBA then this routine will return NULL.
239 static struct lpfc_eqe *
240 lpfc_sli4_eq_get(struct lpfc_queue *q)
242 struct lpfc_eqe *eqe;
245 /* sanity check on queue memory */
248 eqe = q->qe[q->hba_index].eqe;
250 /* If the next EQE is not valid then we are done */
251 if (!bf_get_le32(lpfc_eqe_valid, eqe))
253 /* If the host has not yet processed the next entry then we are done */
254 idx = ((q->hba_index + 1) % q->entry_count);
255 if (idx == q->host_index)
263 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
264 * @q: The Event Queue to disable interrupts
268 lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
270 struct lpfc_register doorbell;
273 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
274 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
275 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
276 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
277 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
278 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
282 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
283 * @q: The Event Queue that the host has completed processing for.
284 * @arm: Indicates whether the host wants to arms this CQ.
286 * This routine will mark all Event Queue Entries on @q, from the last
287 * known completed entry to the last entry that was processed, as completed
288 * by clearing the valid bit for each completion queue entry. Then it will
289 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
290 * The internal host index in the @q will be updated by this routine to indicate
291 * that the host has finished processing the entries. The @arm parameter
292 * indicates that the queue should be rearmed when ringing the doorbell.
294 * This function will return the number of EQEs that were popped.
297 lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
299 uint32_t released = 0;
300 struct lpfc_eqe *temp_eqe;
301 struct lpfc_register doorbell;
303 /* sanity check on queue memory */
307 /* while there are valid entries */
308 while (q->hba_index != q->host_index) {
309 temp_eqe = q->qe[q->host_index].eqe;
310 bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
312 q->host_index = ((q->host_index + 1) % q->entry_count);
314 if (unlikely(released == 0 && !arm))
317 /* ring doorbell for number popped */
320 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
321 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
323 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
324 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
325 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
326 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
327 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
328 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
329 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
330 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
331 readl(q->phba->sli4_hba.EQCQDBregaddr);
336 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
337 * @q: The Completion Queue to get the first valid CQE from
339 * This routine will get the first valid Completion Queue Entry from @q, update
340 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
341 * the Queue (no more work to do), or the Queue is full of CQEs that have been
342 * processed, but not popped back to the HBA then this routine will return NULL.
344 static struct lpfc_cqe *
345 lpfc_sli4_cq_get(struct lpfc_queue *q)
347 struct lpfc_cqe *cqe;
350 /* sanity check on queue memory */
354 /* If the next CQE is not valid then we are done */
355 if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
357 /* If the host has not yet processed the next entry then we are done */
358 idx = ((q->hba_index + 1) % q->entry_count);
359 if (idx == q->host_index)
362 cqe = q->qe[q->hba_index].cqe;
368 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
369 * @q: The Completion Queue that the host has completed processing for.
370 * @arm: Indicates whether the host wants to arms this CQ.
372 * This routine will mark all Completion queue entries on @q, from the last
373 * known completed entry to the last entry that was processed, as completed
374 * by clearing the valid bit for each completion queue entry. Then it will
375 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
376 * The internal host index in the @q will be updated by this routine to indicate
377 * that the host has finished processing the entries. The @arm parameter
378 * indicates that the queue should be rearmed when ringing the doorbell.
380 * This function will return the number of CQEs that were released.
383 lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
385 uint32_t released = 0;
386 struct lpfc_cqe *temp_qe;
387 struct lpfc_register doorbell;
389 /* sanity check on queue memory */
392 /* while there are valid entries */
393 while (q->hba_index != q->host_index) {
394 temp_qe = q->qe[q->host_index].cqe;
395 bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
397 q->host_index = ((q->host_index + 1) % q->entry_count);
399 if (unlikely(released == 0 && !arm))
402 /* ring doorbell for number popped */
405 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
406 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
407 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
408 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
409 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
410 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
411 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
416 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
417 * @q: The Header Receive Queue to operate on.
418 * @wqe: The Receive Queue Entry to put on the Receive queue.
420 * This routine will copy the contents of @wqe to the next available entry on
421 * the @q. This function will then ring the Receive Queue Doorbell to signal the
422 * HBA to start processing the Receive Queue Entry. This function returns the
423 * index that the rqe was copied to if successful. If no entries are available
424 * on @q then this function will return -ENOMEM.
425 * The caller is expected to hold the hbalock when calling this routine.
428 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
429 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
431 struct lpfc_rqe *temp_hrqe;
432 struct lpfc_rqe *temp_drqe;
433 struct lpfc_register doorbell;
434 int put_index = hq->host_index;
436 /* sanity check on queue memory */
437 if (unlikely(!hq) || unlikely(!dq))
439 temp_hrqe = hq->qe[hq->host_index].rqe;
440 temp_drqe = dq->qe[dq->host_index].rqe;
442 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
444 if (hq->host_index != dq->host_index)
446 /* If the host has not yet processed the next entry then we are done */
447 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
449 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
450 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
452 /* Update the host index to point to the next slot */
453 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
454 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
456 /* Ring The Header Receive Queue Doorbell */
457 if (!(hq->host_index % hq->entry_repost)) {
459 bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
461 bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
462 writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
468 * lpfc_sli4_rq_release - Updates internal hba index for RQ
469 * @q: The Header Receive Queue to operate on.
471 * This routine will update the HBA index of a queue to reflect consumption of
472 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
473 * consumed an entry the host calls this function to update the queue's
474 * internal pointers. This routine returns the number of entries that were
475 * consumed by the HBA.
478 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
480 /* sanity check on queue memory */
481 if (unlikely(!hq) || unlikely(!dq))
484 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
486 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
487 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
492 * lpfc_cmd_iocb - Get next command iocb entry in the ring
493 * @phba: Pointer to HBA context object.
494 * @pring: Pointer to driver SLI ring object.
496 * This function returns pointer to next command iocb entry
497 * in the command ring. The caller must hold hbalock to prevent
498 * other threads consume the next command iocb.
499 * SLI-2/SLI-3 provide different sized iocbs.
501 static inline IOCB_t *
502 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
504 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
505 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
509 * lpfc_resp_iocb - Get next response iocb entry in the ring
510 * @phba: Pointer to HBA context object.
511 * @pring: Pointer to driver SLI ring object.
513 * This function returns pointer to next response iocb entry
514 * in the response ring. The caller must hold hbalock to make sure
515 * that no other thread consume the next response iocb.
516 * SLI-2/SLI-3 provide different sized iocbs.
518 static inline IOCB_t *
519 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
521 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
522 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
526 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
527 * @phba: Pointer to HBA context object.
529 * This function is called with hbalock held. This function
530 * allocates a new driver iocb object from the iocb pool. If the
531 * allocation is successful, it returns pointer to the newly
532 * allocated iocb object else it returns NULL.
535 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
537 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
538 struct lpfc_iocbq * iocbq = NULL;
540 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
543 if (phba->iocb_cnt > phba->iocb_max)
544 phba->iocb_max = phba->iocb_cnt;
549 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
550 * @phba: Pointer to HBA context object.
551 * @xritag: XRI value.
553 * This function clears the sglq pointer from the array of acive
554 * sglq's. The xritag that is passed in is used to index into the
555 * array. Before the xritag can be used it needs to be adjusted
556 * by subtracting the xribase.
558 * Returns sglq ponter = success, NULL = Failure.
560 static struct lpfc_sglq *
561 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
563 struct lpfc_sglq *sglq;
565 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
566 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
571 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
572 * @phba: Pointer to HBA context object.
573 * @xritag: XRI value.
575 * This function returns the sglq pointer from the array of acive
576 * sglq's. The xritag that is passed in is used to index into the
577 * array. Before the xritag can be used it needs to be adjusted
578 * by subtracting the xribase.
580 * Returns sglq ponter = success, NULL = Failure.
583 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
585 struct lpfc_sglq *sglq;
587 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
592 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
593 * @phba: Pointer to HBA context object.
594 * @xritag: xri used in this exchange.
595 * @rrq: The RRQ to be cleared.
599 lpfc_clr_rrq_active(struct lpfc_hba *phba,
601 struct lpfc_node_rrq *rrq)
603 struct lpfc_nodelist *ndlp = NULL;
605 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
606 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
608 /* The target DID could have been swapped (cable swap)
609 * we should use the ndlp from the findnode if it is
612 if ((!ndlp) && rrq->ndlp)
618 if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
621 rrq->rrq_stop_time = 0;
624 mempool_free(rrq, phba->rrq_pool);
628 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
629 * @phba: Pointer to HBA context object.
631 * This function is called with hbalock held. This function
632 * Checks if stop_time (ratov from setting rrq active) has
633 * been reached, if it has and the send_rrq flag is set then
634 * it will call lpfc_send_rrq. If the send_rrq flag is not set
635 * then it will just call the routine to clear the rrq and
636 * free the rrq resource.
637 * The timer is set to the next rrq that is going to expire before
638 * leaving the routine.
642 lpfc_handle_rrq_active(struct lpfc_hba *phba)
644 struct lpfc_node_rrq *rrq;
645 struct lpfc_node_rrq *nextrrq;
646 unsigned long next_time;
647 unsigned long iflags;
650 spin_lock_irqsave(&phba->hbalock, iflags);
651 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
652 next_time = jiffies + HZ * (phba->fc_ratov + 1);
653 list_for_each_entry_safe(rrq, nextrrq,
654 &phba->active_rrq_list, list) {
655 if (time_after(jiffies, rrq->rrq_stop_time))
656 list_move(&rrq->list, &send_rrq);
657 else if (time_before(rrq->rrq_stop_time, next_time))
658 next_time = rrq->rrq_stop_time;
660 spin_unlock_irqrestore(&phba->hbalock, iflags);
661 if (!list_empty(&phba->active_rrq_list))
662 mod_timer(&phba->rrq_tmr, next_time);
663 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
664 list_del(&rrq->list);
666 /* this call will free the rrq */
667 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
668 else if (lpfc_send_rrq(phba, rrq)) {
669 /* if we send the rrq then the completion handler
670 * will clear the bit in the xribitmap.
672 lpfc_clr_rrq_active(phba, rrq->xritag,
679 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
680 * @vport: Pointer to vport context object.
681 * @xri: The xri used in the exchange.
682 * @did: The targets DID for this exchange.
684 * returns NULL = rrq not found in the phba->active_rrq_list.
685 * rrq = rrq for this xri and target.
687 struct lpfc_node_rrq *
688 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
690 struct lpfc_hba *phba = vport->phba;
691 struct lpfc_node_rrq *rrq;
692 struct lpfc_node_rrq *nextrrq;
693 unsigned long iflags;
695 if (phba->sli_rev != LPFC_SLI_REV4)
697 spin_lock_irqsave(&phba->hbalock, iflags);
698 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
699 if (rrq->vport == vport && rrq->xritag == xri &&
700 rrq->nlp_DID == did){
701 list_del(&rrq->list);
702 spin_unlock_irqrestore(&phba->hbalock, iflags);
706 spin_unlock_irqrestore(&phba->hbalock, iflags);
711 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
712 * @vport: Pointer to vport context object.
713 * @ndlp: Pointer to the lpfc_node_list structure.
714 * If ndlp is NULL Remove all active RRQs for this vport from the
715 * phba->active_rrq_list and clear the rrq.
716 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
719 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
722 struct lpfc_hba *phba = vport->phba;
723 struct lpfc_node_rrq *rrq;
724 struct lpfc_node_rrq *nextrrq;
725 unsigned long iflags;
728 if (phba->sli_rev != LPFC_SLI_REV4)
731 lpfc_sli4_vport_delete_els_xri_aborted(vport);
732 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
734 spin_lock_irqsave(&phba->hbalock, iflags);
735 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
736 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
737 list_move(&rrq->list, &rrq_list);
738 spin_unlock_irqrestore(&phba->hbalock, iflags);
740 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
741 list_del(&rrq->list);
742 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
747 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
748 * @phba: Pointer to HBA context object.
750 * Remove all rrqs from the phba->active_rrq_list and free them by
751 * calling __lpfc_clr_active_rrq
755 lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
757 struct lpfc_node_rrq *rrq;
758 struct lpfc_node_rrq *nextrrq;
759 unsigned long next_time;
760 unsigned long iflags;
763 if (phba->sli_rev != LPFC_SLI_REV4)
765 spin_lock_irqsave(&phba->hbalock, iflags);
766 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
767 next_time = jiffies + HZ * (phba->fc_ratov * 2);
768 list_splice_init(&phba->active_rrq_list, &rrq_list);
769 spin_unlock_irqrestore(&phba->hbalock, iflags);
771 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
772 list_del(&rrq->list);
773 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
775 if (!list_empty(&phba->active_rrq_list))
776 mod_timer(&phba->rrq_tmr, next_time);
781 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
782 * @phba: Pointer to HBA context object.
783 * @ndlp: Targets nodelist pointer for this exchange.
784 * @xritag the xri in the bitmap to test.
786 * This function is called with hbalock held. This function
787 * returns 0 = rrq not active for this xri
788 * 1 = rrq is valid for this xri.
791 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
796 if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
803 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
804 * @phba: Pointer to HBA context object.
805 * @ndlp: nodelist pointer for this target.
806 * @xritag: xri used in this exchange.
807 * @rxid: Remote Exchange ID.
808 * @send_rrq: Flag used to determine if we should send rrq els cmd.
810 * This function takes the hbalock.
811 * The active bit is always set in the active rrq xri_bitmap even
812 * if there is no slot avaiable for the other rrq information.
814 * returns 0 rrq actived for this xri
815 * < 0 No memory or invalid ndlp.
818 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
819 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
821 unsigned long iflags;
822 struct lpfc_node_rrq *rrq;
828 if (!phba->cfg_enable_rrq)
831 spin_lock_irqsave(&phba->hbalock, iflags);
832 if (phba->pport->load_flag & FC_UNLOADING) {
833 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
838 * set the active bit even if there is no mem available.
840 if (NLP_CHK_FREE_REQ(ndlp))
843 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
846 if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
849 spin_unlock_irqrestore(&phba->hbalock, iflags);
850 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
852 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
853 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
854 " DID:0x%x Send:%d\n",
855 xritag, rxid, ndlp->nlp_DID, send_rrq);
858 rrq->send_rrq = send_rrq;
859 rrq->xritag = xritag;
860 rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
862 rrq->nlp_DID = ndlp->nlp_DID;
863 rrq->vport = ndlp->vport;
865 rrq->send_rrq = send_rrq;
866 spin_lock_irqsave(&phba->hbalock, iflags);
867 empty = list_empty(&phba->active_rrq_list);
868 list_add_tail(&rrq->list, &phba->active_rrq_list);
869 phba->hba_flag |= HBA_RRQ_ACTIVE;
871 lpfc_worker_wake_up(phba);
872 spin_unlock_irqrestore(&phba->hbalock, iflags);
875 spin_unlock_irqrestore(&phba->hbalock, iflags);
876 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
877 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
878 " DID:0x%x Send:%d\n",
879 xritag, rxid, ndlp->nlp_DID, send_rrq);
884 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
885 * @phba: Pointer to HBA context object.
886 * @piocb: Pointer to the iocbq.
888 * This function is called with hbalock held. This function
889 * gets a new driver sglq object from the sglq list. If the
890 * list is not empty then it is successful, it returns pointer to the newly
891 * allocated sglq object else it returns NULL.
893 static struct lpfc_sglq *
894 __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
896 struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
897 struct lpfc_sglq *sglq = NULL;
898 struct lpfc_sglq *start_sglq = NULL;
899 struct lpfc_scsi_buf *lpfc_cmd;
900 struct lpfc_nodelist *ndlp;
903 if (piocbq->iocb_flag & LPFC_IO_FCP) {
904 lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
905 ndlp = lpfc_cmd->rdata->pnode;
906 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
907 !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
908 ndlp = piocbq->context_un.ndlp;
909 else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) &&
910 (piocbq->iocb_flag & LPFC_IO_LIBDFC))
911 ndlp = piocbq->context_un.ndlp;
913 ndlp = piocbq->context1;
915 list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
920 if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
921 /* This xri has an rrq outstanding for this DID.
922 * put it back in the list and get another xri.
924 list_add_tail(&sglq->list, lpfc_sgl_list);
926 list_remove_head(lpfc_sgl_list, sglq,
927 struct lpfc_sglq, list);
928 if (sglq == start_sglq) {
936 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
937 sglq->state = SGL_ALLOCATED;
943 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
944 * @phba: Pointer to HBA context object.
946 * This function is called with no lock held. This function
947 * allocates a new driver iocb object from the iocb pool. If the
948 * allocation is successful, it returns pointer to the newly
949 * allocated iocb object else it returns NULL.
952 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
954 struct lpfc_iocbq * iocbq = NULL;
955 unsigned long iflags;
957 spin_lock_irqsave(&phba->hbalock, iflags);
958 iocbq = __lpfc_sli_get_iocbq(phba);
959 spin_unlock_irqrestore(&phba->hbalock, iflags);
964 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
965 * @phba: Pointer to HBA context object.
966 * @iocbq: Pointer to driver iocb object.
968 * This function is called with hbalock held to release driver
969 * iocb object to the iocb pool. The iotag in the iocb object
970 * does not change for each use of the iocb object. This function
971 * clears all other fields of the iocb object when it is freed.
972 * The sqlq structure that holds the xritag and phys and virtual
973 * mappings for the scatter gather list is retrieved from the
974 * active array of sglq. The get of the sglq pointer also clears
975 * the entry in the array. If the status of the IO indiactes that
976 * this IO was aborted then the sglq entry it put on the
977 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
978 * IO has good status or fails for any other reason then the sglq
979 * entry is added to the free list (lpfc_sgl_list).
982 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
984 struct lpfc_sglq *sglq;
985 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
986 unsigned long iflag = 0;
987 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
989 if (iocbq->sli4_xritag == NO_XRI)
992 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
995 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
996 (sglq->state != SGL_XRI_ABORTED)) {
997 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
999 list_add(&sglq->list,
1000 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1001 spin_unlock_irqrestore(
1002 &phba->sli4_hba.abts_sgl_list_lock, iflag);
1004 sglq->state = SGL_FREED;
1006 list_add_tail(&sglq->list,
1007 &phba->sli4_hba.lpfc_sgl_list);
1009 /* Check if TXQ queue needs to be serviced */
1011 lpfc_worker_wake_up(phba);
1017 * Clean all volatile data fields, preserve iotag and node struct.
1019 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1020 iocbq->sli4_lxritag = NO_XRI;
1021 iocbq->sli4_xritag = NO_XRI;
1022 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1027 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1028 * @phba: Pointer to HBA context object.
1029 * @iocbq: Pointer to driver iocb object.
1031 * This function is called with hbalock held to release driver
1032 * iocb object to the iocb pool. The iotag in the iocb object
1033 * does not change for each use of the iocb object. This function
1034 * clears all other fields of the iocb object when it is freed.
1037 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1039 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1042 * Clean all volatile data fields, preserve iotag and node struct.
1044 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1045 iocbq->sli4_xritag = NO_XRI;
1046 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1050 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1051 * @phba: Pointer to HBA context object.
1052 * @iocbq: Pointer to driver iocb object.
1054 * This function is called with hbalock held to release driver
1055 * iocb object to the iocb pool. The iotag in the iocb object
1056 * does not change for each use of the iocb object. This function
1057 * clears all other fields of the iocb object when it is freed.
1060 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1062 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1067 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1068 * @phba: Pointer to HBA context object.
1069 * @iocbq: Pointer to driver iocb object.
1071 * This function is called with no lock held to release the iocb to
1075 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1077 unsigned long iflags;
1080 * Clean all volatile data fields, preserve iotag and node struct.
1082 spin_lock_irqsave(&phba->hbalock, iflags);
1083 __lpfc_sli_release_iocbq(phba, iocbq);
1084 spin_unlock_irqrestore(&phba->hbalock, iflags);
1088 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1089 * @phba: Pointer to HBA context object.
1090 * @iocblist: List of IOCBs.
1091 * @ulpstatus: ULP status in IOCB command field.
1092 * @ulpWord4: ULP word-4 in IOCB command field.
1094 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1095 * on the list by invoking the complete callback function associated with the
1096 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1100 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1101 uint32_t ulpstatus, uint32_t ulpWord4)
1103 struct lpfc_iocbq *piocb;
1105 while (!list_empty(iocblist)) {
1106 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1108 if (!piocb->iocb_cmpl)
1109 lpfc_sli_release_iocbq(phba, piocb);
1111 piocb->iocb.ulpStatus = ulpstatus;
1112 piocb->iocb.un.ulpWord[4] = ulpWord4;
1113 (piocb->iocb_cmpl) (phba, piocb, piocb);
1120 * lpfc_sli_iocb_cmd_type - Get the iocb type
1121 * @iocb_cmnd: iocb command code.
1123 * This function is called by ring event handler function to get the iocb type.
1124 * This function translates the iocb command to an iocb command type used to
1125 * decide the final disposition of each completed IOCB.
1126 * The function returns
1127 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1128 * LPFC_SOL_IOCB if it is a solicited iocb completion
1129 * LPFC_ABORT_IOCB if it is an abort iocb
1130 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1132 * The caller is not required to hold any lock.
1134 static lpfc_iocb_type
1135 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1137 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1139 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1142 switch (iocb_cmnd) {
1143 case CMD_XMIT_SEQUENCE_CR:
1144 case CMD_XMIT_SEQUENCE_CX:
1145 case CMD_XMIT_BCAST_CN:
1146 case CMD_XMIT_BCAST_CX:
1147 case CMD_ELS_REQUEST_CR:
1148 case CMD_ELS_REQUEST_CX:
1149 case CMD_CREATE_XRI_CR:
1150 case CMD_CREATE_XRI_CX:
1151 case CMD_GET_RPI_CN:
1152 case CMD_XMIT_ELS_RSP_CX:
1153 case CMD_GET_RPI_CR:
1154 case CMD_FCP_IWRITE_CR:
1155 case CMD_FCP_IWRITE_CX:
1156 case CMD_FCP_IREAD_CR:
1157 case CMD_FCP_IREAD_CX:
1158 case CMD_FCP_ICMND_CR:
1159 case CMD_FCP_ICMND_CX:
1160 case CMD_FCP_TSEND_CX:
1161 case CMD_FCP_TRSP_CX:
1162 case CMD_FCP_TRECEIVE_CX:
1163 case CMD_FCP_AUTO_TRSP_CX:
1164 case CMD_ADAPTER_MSG:
1165 case CMD_ADAPTER_DUMP:
1166 case CMD_XMIT_SEQUENCE64_CR:
1167 case CMD_XMIT_SEQUENCE64_CX:
1168 case CMD_XMIT_BCAST64_CN:
1169 case CMD_XMIT_BCAST64_CX:
1170 case CMD_ELS_REQUEST64_CR:
1171 case CMD_ELS_REQUEST64_CX:
1172 case CMD_FCP_IWRITE64_CR:
1173 case CMD_FCP_IWRITE64_CX:
1174 case CMD_FCP_IREAD64_CR:
1175 case CMD_FCP_IREAD64_CX:
1176 case CMD_FCP_ICMND64_CR:
1177 case CMD_FCP_ICMND64_CX:
1178 case CMD_FCP_TSEND64_CX:
1179 case CMD_FCP_TRSP64_CX:
1180 case CMD_FCP_TRECEIVE64_CX:
1181 case CMD_GEN_REQUEST64_CR:
1182 case CMD_GEN_REQUEST64_CX:
1183 case CMD_XMIT_ELS_RSP64_CX:
1184 case DSSCMD_IWRITE64_CR:
1185 case DSSCMD_IWRITE64_CX:
1186 case DSSCMD_IREAD64_CR:
1187 case DSSCMD_IREAD64_CX:
1188 type = LPFC_SOL_IOCB;
1190 case CMD_ABORT_XRI_CN:
1191 case CMD_ABORT_XRI_CX:
1192 case CMD_CLOSE_XRI_CN:
1193 case CMD_CLOSE_XRI_CX:
1194 case CMD_XRI_ABORTED_CX:
1195 case CMD_ABORT_MXRI64_CN:
1196 case CMD_XMIT_BLS_RSP64_CX:
1197 type = LPFC_ABORT_IOCB;
1199 case CMD_RCV_SEQUENCE_CX:
1200 case CMD_RCV_ELS_REQ_CX:
1201 case CMD_RCV_SEQUENCE64_CX:
1202 case CMD_RCV_ELS_REQ64_CX:
1203 case CMD_ASYNC_STATUS:
1204 case CMD_IOCB_RCV_SEQ64_CX:
1205 case CMD_IOCB_RCV_ELS64_CX:
1206 case CMD_IOCB_RCV_CONT64_CX:
1207 case CMD_IOCB_RET_XRI64_CX:
1208 type = LPFC_UNSOL_IOCB;
1210 case CMD_IOCB_XMIT_MSEQ64_CR:
1211 case CMD_IOCB_XMIT_MSEQ64_CX:
1212 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1213 case CMD_IOCB_RCV_ELS_LIST64_CX:
1214 case CMD_IOCB_CLOSE_EXTENDED_CN:
1215 case CMD_IOCB_ABORT_EXTENDED_CN:
1216 case CMD_IOCB_RET_HBQE64_CN:
1217 case CMD_IOCB_FCP_IBIDIR64_CR:
1218 case CMD_IOCB_FCP_IBIDIR64_CX:
1219 case CMD_IOCB_FCP_ITASKMGT64_CX:
1220 case CMD_IOCB_LOGENTRY_CN:
1221 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1222 printk("%s - Unhandled SLI-3 Command x%x\n",
1223 __func__, iocb_cmnd);
1224 type = LPFC_UNKNOWN_IOCB;
1227 type = LPFC_UNKNOWN_IOCB;
1235 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1236 * @phba: Pointer to HBA context object.
1238 * This function is called from SLI initialization code
1239 * to configure every ring of the HBA's SLI interface. The
1240 * caller is not required to hold any lock. This function issues
1241 * a config_ring mailbox command for each ring.
1242 * This function returns zero if successful else returns a negative
1246 lpfc_sli_ring_map(struct lpfc_hba *phba)
1248 struct lpfc_sli *psli = &phba->sli;
1253 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1257 phba->link_state = LPFC_INIT_MBX_CMDS;
1258 for (i = 0; i < psli->num_rings; i++) {
1259 lpfc_config_ring(phba, i, pmb);
1260 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1261 if (rc != MBX_SUCCESS) {
1262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1263 "0446 Adapter failed to init (%d), "
1264 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1266 rc, pmbox->mbxCommand,
1267 pmbox->mbxStatus, i);
1268 phba->link_state = LPFC_HBA_ERROR;
1273 mempool_free(pmb, phba->mbox_mem_pool);
1278 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1279 * @phba: Pointer to HBA context object.
1280 * @pring: Pointer to driver SLI ring object.
1281 * @piocb: Pointer to the driver iocb object.
1283 * This function is called with hbalock held. The function adds the
1284 * new iocb to txcmplq of the given ring. This function always returns
1285 * 0. If this function is called for ELS ring, this function checks if
1286 * there is a vport associated with the ELS command. This function also
1287 * starts els_tmofunc timer if this is an ELS command.
1290 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1291 struct lpfc_iocbq *piocb)
1293 list_add_tail(&piocb->list, &pring->txcmplq);
1294 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1295 pring->txcmplq_cnt++;
1296 if (pring->txcmplq_cnt > pring->txcmplq_max)
1297 pring->txcmplq_max = pring->txcmplq_cnt;
1299 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1300 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1301 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1305 mod_timer(&piocb->vport->els_tmofunc,
1306 jiffies + HZ * (phba->fc_ratov << 1));
1314 * lpfc_sli_ringtx_get - Get first element of the txq
1315 * @phba: Pointer to HBA context object.
1316 * @pring: Pointer to driver SLI ring object.
1318 * This function is called with hbalock held to get next
1319 * iocb in txq of the given ring. If there is any iocb in
1320 * the txq, the function returns first iocb in the list after
1321 * removing the iocb from the list, else it returns NULL.
1324 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1326 struct lpfc_iocbq *cmd_iocb;
1328 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1329 if (cmd_iocb != NULL)
1335 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1336 * @phba: Pointer to HBA context object.
1337 * @pring: Pointer to driver SLI ring object.
1339 * This function is called with hbalock held and the caller must post the
1340 * iocb without releasing the lock. If the caller releases the lock,
1341 * iocb slot returned by the function is not guaranteed to be available.
1342 * The function returns pointer to the next available iocb slot if there
1343 * is available slot in the ring, else it returns NULL.
1344 * If the get index of the ring is ahead of the put index, the function
1345 * will post an error attention event to the worker thread to take the
1346 * HBA to offline state.
1349 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1351 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1352 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
1353 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
1354 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
1355 pring->sli.sli3.next_cmdidx = 0;
1357 if (unlikely(pring->sli.sli3.local_getidx ==
1358 pring->sli.sli3.next_cmdidx)) {
1360 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
1362 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
1363 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1364 "0315 Ring %d issue: portCmdGet %d "
1365 "is bigger than cmd ring %d\n",
1367 pring->sli.sli3.local_getidx,
1370 phba->link_state = LPFC_HBA_ERROR;
1372 * All error attention handlers are posted to
1375 phba->work_ha |= HA_ERATT;
1376 phba->work_hs = HS_FFER3;
1378 lpfc_worker_wake_up(phba);
1383 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
1387 return lpfc_cmd_iocb(phba, pring);
1391 * lpfc_sli_next_iotag - Get an iotag for the iocb
1392 * @phba: Pointer to HBA context object.
1393 * @iocbq: Pointer to driver iocb object.
1395 * This function gets an iotag for the iocb. If there is no unused iotag and
1396 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1397 * array and assigns a new iotag.
1398 * The function returns the allocated iotag if successful, else returns zero.
1399 * Zero is not a valid iotag.
1400 * The caller is not required to hold any lock.
1403 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1405 struct lpfc_iocbq **new_arr;
1406 struct lpfc_iocbq **old_arr;
1408 struct lpfc_sli *psli = &phba->sli;
1411 spin_lock_irq(&phba->hbalock);
1412 iotag = psli->last_iotag;
1413 if(++iotag < psli->iocbq_lookup_len) {
1414 psli->last_iotag = iotag;
1415 psli->iocbq_lookup[iotag] = iocbq;
1416 spin_unlock_irq(&phba->hbalock);
1417 iocbq->iotag = iotag;
1419 } else if (psli->iocbq_lookup_len < (0xffff
1420 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1421 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1422 spin_unlock_irq(&phba->hbalock);
1423 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
1426 spin_lock_irq(&phba->hbalock);
1427 old_arr = psli->iocbq_lookup;
1428 if (new_len <= psli->iocbq_lookup_len) {
1429 /* highly unprobable case */
1431 iotag = psli->last_iotag;
1432 if(++iotag < psli->iocbq_lookup_len) {
1433 psli->last_iotag = iotag;
1434 psli->iocbq_lookup[iotag] = iocbq;
1435 spin_unlock_irq(&phba->hbalock);
1436 iocbq->iotag = iotag;
1439 spin_unlock_irq(&phba->hbalock);
1442 if (psli->iocbq_lookup)
1443 memcpy(new_arr, old_arr,
1444 ((psli->last_iotag + 1) *
1445 sizeof (struct lpfc_iocbq *)));
1446 psli->iocbq_lookup = new_arr;
1447 psli->iocbq_lookup_len = new_len;
1448 psli->last_iotag = iotag;
1449 psli->iocbq_lookup[iotag] = iocbq;
1450 spin_unlock_irq(&phba->hbalock);
1451 iocbq->iotag = iotag;
1456 spin_unlock_irq(&phba->hbalock);
1458 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1459 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1466 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1467 * @phba: Pointer to HBA context object.
1468 * @pring: Pointer to driver SLI ring object.
1469 * @iocb: Pointer to iocb slot in the ring.
1470 * @nextiocb: Pointer to driver iocb object which need to be
1471 * posted to firmware.
1473 * This function is called with hbalock held to post a new iocb to
1474 * the firmware. This function copies the new iocb to ring iocb slot and
1475 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1476 * a completion call back for this iocb else the function will free the
1480 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1481 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1486 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1489 if (pring->ringno == LPFC_ELS_RING) {
1490 lpfc_debugfs_slow_ring_trc(phba,
1491 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1492 *(((uint32_t *) &nextiocb->iocb) + 4),
1493 *(((uint32_t *) &nextiocb->iocb) + 6),
1494 *(((uint32_t *) &nextiocb->iocb) + 7));
1498 * Issue iocb command to adapter
1500 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1502 pring->stats.iocb_cmd++;
1505 * If there is no completion routine to call, we can release the
1506 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1507 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1509 if (nextiocb->iocb_cmpl)
1510 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1512 __lpfc_sli_release_iocbq(phba, nextiocb);
1515 * Let the HBA know what IOCB slot will be the next one the
1516 * driver will put a command into.
1518 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
1519 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1523 * lpfc_sli_update_full_ring - Update the chip attention register
1524 * @phba: Pointer to HBA context object.
1525 * @pring: Pointer to driver SLI ring object.
1527 * The caller is not required to hold any lock for calling this function.
1528 * This function updates the chip attention bits for the ring to inform firmware
1529 * that there are pending work to be done for this ring and requests an
1530 * interrupt when there is space available in the ring. This function is
1531 * called when the driver is unable to post more iocbs to the ring due
1532 * to unavailability of space in the ring.
1535 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1537 int ringno = pring->ringno;
1539 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1544 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1545 * The HBA will tell us when an IOCB entry is available.
1547 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1548 readl(phba->CAregaddr); /* flush */
1550 pring->stats.iocb_cmd_full++;
1554 * lpfc_sli_update_ring - Update chip attention register
1555 * @phba: Pointer to HBA context object.
1556 * @pring: Pointer to driver SLI ring object.
1558 * This function updates the chip attention register bit for the
1559 * given ring to inform HBA that there is more work to be done
1560 * in this ring. The caller is not required to hold any lock.
1563 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1565 int ringno = pring->ringno;
1568 * Tell the HBA that there is work to do in this ring.
1570 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1572 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1573 readl(phba->CAregaddr); /* flush */
1578 * lpfc_sli_resume_iocb - Process iocbs in the txq
1579 * @phba: Pointer to HBA context object.
1580 * @pring: Pointer to driver SLI ring object.
1582 * This function is called with hbalock held to post pending iocbs
1583 * in the txq to the firmware. This function is called when driver
1584 * detects space available in the ring.
1587 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1590 struct lpfc_iocbq *nextiocb;
1594 * (a) there is anything on the txq to send
1596 * (c) link attention events can be processed (fcp ring only)
1597 * (d) IOCB processing is not blocked by the outstanding mbox command.
1599 if (pring->txq_cnt &&
1600 lpfc_is_link_up(phba) &&
1601 (pring->ringno != phba->sli.fcp_ring ||
1602 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1604 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1605 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1606 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1609 lpfc_sli_update_ring(phba, pring);
1611 lpfc_sli_update_full_ring(phba, pring);
1618 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1619 * @phba: Pointer to HBA context object.
1620 * @hbqno: HBQ number.
1622 * This function is called with hbalock held to get the next
1623 * available slot for the given HBQ. If there is free slot
1624 * available for the HBQ it will return pointer to the next available
1625 * HBQ entry else it will return NULL.
1627 static struct lpfc_hbq_entry *
1628 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1630 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1632 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1633 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1634 hbqp->next_hbqPutIdx = 0;
1636 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1637 uint32_t raw_index = phba->hbq_get[hbqno];
1638 uint32_t getidx = le32_to_cpu(raw_index);
1640 hbqp->local_hbqGetIdx = getidx;
1642 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1643 lpfc_printf_log(phba, KERN_ERR,
1644 LOG_SLI | LOG_VPORT,
1645 "1802 HBQ %d: local_hbqGetIdx "
1646 "%u is > than hbqp->entry_count %u\n",
1647 hbqno, hbqp->local_hbqGetIdx,
1650 phba->link_state = LPFC_HBA_ERROR;
1654 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1658 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1663 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1664 * @phba: Pointer to HBA context object.
1666 * This function is called with no lock held to free all the
1667 * hbq buffers while uninitializing the SLI interface. It also
1668 * frees the HBQ buffers returned by the firmware but not yet
1669 * processed by the upper layers.
1672 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1674 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1675 struct hbq_dmabuf *hbq_buf;
1676 unsigned long flags;
1680 hbq_count = lpfc_sli_hbq_count();
1681 /* Return all memory used by all HBQs */
1682 spin_lock_irqsave(&phba->hbalock, flags);
1683 for (i = 0; i < hbq_count; ++i) {
1684 list_for_each_entry_safe(dmabuf, next_dmabuf,
1685 &phba->hbqs[i].hbq_buffer_list, list) {
1686 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1687 list_del(&hbq_buf->dbuf.list);
1688 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1690 phba->hbqs[i].buffer_count = 0;
1692 /* Return all HBQ buffer that are in-fly */
1693 list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
1695 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1696 list_del(&hbq_buf->dbuf.list);
1697 if (hbq_buf->tag == -1) {
1698 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1701 hbqno = hbq_buf->tag >> 16;
1702 if (hbqno >= LPFC_MAX_HBQS)
1703 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1706 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1711 /* Mark the HBQs not in use */
1712 phba->hbq_in_use = 0;
1713 spin_unlock_irqrestore(&phba->hbalock, flags);
1717 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1718 * @phba: Pointer to HBA context object.
1719 * @hbqno: HBQ number.
1720 * @hbq_buf: Pointer to HBQ buffer.
1722 * This function is called with the hbalock held to post a
1723 * hbq buffer to the firmware. If the function finds an empty
1724 * slot in the HBQ, it will post the buffer. The function will return
1725 * pointer to the hbq entry if it successfully post the buffer
1726 * else it will return NULL.
1729 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
1730 struct hbq_dmabuf *hbq_buf)
1732 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1736 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1737 * @phba: Pointer to HBA context object.
1738 * @hbqno: HBQ number.
1739 * @hbq_buf: Pointer to HBQ buffer.
1741 * This function is called with the hbalock held to post a hbq buffer to the
1742 * firmware. If the function finds an empty slot in the HBQ, it will post the
1743 * buffer and place it on the hbq_buffer_list. The function will return zero if
1744 * it successfully post the buffer else it will return an error.
1747 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1748 struct hbq_dmabuf *hbq_buf)
1750 struct lpfc_hbq_entry *hbqe;
1751 dma_addr_t physaddr = hbq_buf->dbuf.phys;
1753 /* Get next HBQ entry slot to use */
1754 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1756 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1758 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1759 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
1760 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
1761 hbqe->bde.tus.f.bdeFlags = 0;
1762 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1763 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1765 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1766 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
1768 readl(phba->hbq_put + hbqno);
1769 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
1776 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1777 * @phba: Pointer to HBA context object.
1778 * @hbqno: HBQ number.
1779 * @hbq_buf: Pointer to HBQ buffer.
1781 * This function is called with the hbalock held to post an RQE to the SLI4
1782 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1783 * the hbq_buffer_list and return zero, otherwise it will return an error.
1786 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1787 struct hbq_dmabuf *hbq_buf)
1790 struct lpfc_rqe hrqe;
1791 struct lpfc_rqe drqe;
1793 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1794 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1795 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1796 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1797 rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
1802 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1806 /* HBQ for ELS and CT traffic. */
1807 static struct lpfc_hbq_init lpfc_els_hbq = {
1812 .ring_mask = (1 << LPFC_ELS_RING),
1818 /* HBQ for the extra ring if needed */
1819 static struct lpfc_hbq_init lpfc_extra_hbq = {
1824 .ring_mask = (1 << LPFC_EXTRA_RING),
1831 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
1837 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1838 * @phba: Pointer to HBA context object.
1839 * @hbqno: HBQ number.
1840 * @count: Number of HBQ buffers to be posted.
1842 * This function is called with no lock held to post more hbq buffers to the
1843 * given HBQ. The function returns the number of HBQ buffers successfully
1847 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1849 uint32_t i, posted = 0;
1850 unsigned long flags;
1851 struct hbq_dmabuf *hbq_buffer;
1852 LIST_HEAD(hbq_buf_list);
1853 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
1856 if ((phba->hbqs[hbqno].buffer_count + count) >
1857 lpfc_hbq_defs[hbqno]->entry_count)
1858 count = lpfc_hbq_defs[hbqno]->entry_count -
1859 phba->hbqs[hbqno].buffer_count;
1862 /* Allocate HBQ entries */
1863 for (i = 0; i < count; i++) {
1864 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1867 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1869 /* Check whether HBQ is still in use */
1870 spin_lock_irqsave(&phba->hbalock, flags);
1871 if (!phba->hbq_in_use)
1873 while (!list_empty(&hbq_buf_list)) {
1874 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1876 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1878 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
1879 phba->hbqs[hbqno].buffer_count++;
1882 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1884 spin_unlock_irqrestore(&phba->hbalock, flags);
1887 spin_unlock_irqrestore(&phba->hbalock, flags);
1888 while (!list_empty(&hbq_buf_list)) {
1889 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1891 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1897 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1898 * @phba: Pointer to HBA context object.
1901 * This function posts more buffers to the HBQ. This function
1902 * is called with no lock held. The function returns the number of HBQ entries
1903 * successfully allocated.
1906 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
1908 if (phba->sli_rev == LPFC_SLI_REV4)
1911 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1912 lpfc_hbq_defs[qno]->add_count);
1916 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1917 * @phba: Pointer to HBA context object.
1918 * @qno: HBQ queue number.
1920 * This function is called from SLI initialization code path with
1921 * no lock held to post initial HBQ buffers to firmware. The
1922 * function returns the number of HBQ entries successfully allocated.
1925 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
1927 if (phba->sli_rev == LPFC_SLI_REV4)
1928 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1929 lpfc_hbq_defs[qno]->entry_count);
1931 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1932 lpfc_hbq_defs[qno]->init_count);
1936 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1937 * @phba: Pointer to HBA context object.
1938 * @hbqno: HBQ number.
1940 * This function removes the first hbq buffer on an hbq list and returns a
1941 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1943 static struct hbq_dmabuf *
1944 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
1946 struct lpfc_dmabuf *d_buf;
1948 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
1951 return container_of(d_buf, struct hbq_dmabuf, dbuf);
1955 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1956 * @phba: Pointer to HBA context object.
1957 * @tag: Tag of the hbq buffer.
1959 * This function is called with hbalock held. This function searches
1960 * for the hbq buffer associated with the given tag in the hbq buffer
1961 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1964 static struct hbq_dmabuf *
1965 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
1967 struct lpfc_dmabuf *d_buf;
1968 struct hbq_dmabuf *hbq_buf;
1972 if (hbqno >= LPFC_MAX_HBQS)
1975 spin_lock_irq(&phba->hbalock);
1976 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
1977 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
1978 if (hbq_buf->tag == tag) {
1979 spin_unlock_irq(&phba->hbalock);
1983 spin_unlock_irq(&phba->hbalock);
1984 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
1985 "1803 Bad hbq tag. Data: x%x x%x\n",
1986 tag, phba->hbqs[tag >> 16].buffer_count);
1991 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1992 * @phba: Pointer to HBA context object.
1993 * @hbq_buffer: Pointer to HBQ buffer.
1995 * This function is called with hbalock. This function gives back
1996 * the hbq buffer to firmware. If the HBQ does not have space to
1997 * post the buffer, it will free the buffer.
2000 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2005 hbqno = hbq_buffer->tag >> 16;
2006 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2007 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2012 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2013 * @mbxCommand: mailbox command code.
2015 * This function is called by the mailbox event handler function to verify
2016 * that the completed mailbox command is a legitimate mailbox command. If the
2017 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2018 * and the mailbox event handler will take the HBA offline.
2021 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2025 switch (mbxCommand) {
2029 case MBX_WRITE_VPARMS:
2030 case MBX_RUN_BIU_DIAG:
2033 case MBX_CONFIG_LINK:
2034 case MBX_CONFIG_RING:
2035 case MBX_RESET_RING:
2036 case MBX_READ_CONFIG:
2037 case MBX_READ_RCONFIG:
2038 case MBX_READ_SPARM:
2039 case MBX_READ_STATUS:
2043 case MBX_READ_LNK_STAT:
2045 case MBX_UNREG_LOGIN:
2047 case MBX_DUMP_MEMORY:
2048 case MBX_DUMP_CONTEXT:
2051 case MBX_UPDATE_CFG:
2053 case MBX_DEL_LD_ENTRY:
2054 case MBX_RUN_PROGRAM:
2056 case MBX_SET_VARIABLE:
2057 case MBX_UNREG_D_ID:
2058 case MBX_KILL_BOARD:
2059 case MBX_CONFIG_FARP:
2062 case MBX_RUN_BIU_DIAG64:
2063 case MBX_CONFIG_PORT:
2064 case MBX_READ_SPARM64:
2065 case MBX_READ_RPI64:
2066 case MBX_REG_LOGIN64:
2067 case MBX_READ_TOPOLOGY:
2070 case MBX_LOAD_EXP_ROM:
2071 case MBX_ASYNCEVT_ENABLE:
2075 case MBX_PORT_CAPABILITIES:
2076 case MBX_PORT_IOV_CONTROL:
2077 case MBX_SLI4_CONFIG:
2078 case MBX_SLI4_REQ_FTRS:
2080 case MBX_UNREG_FCFI:
2085 case MBX_RESUME_RPI:
2086 case MBX_READ_EVENT_LOG_STATUS:
2087 case MBX_READ_EVENT_LOG:
2088 case MBX_SECURITY_MGMT:
2090 case MBX_ACCESS_VDATA:
2101 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2102 * @phba: Pointer to HBA context object.
2103 * @pmboxq: Pointer to mailbox command.
2105 * This is completion handler function for mailbox commands issued from
2106 * lpfc_sli_issue_mbox_wait function. This function is called by the
2107 * mailbox event handler function with no lock held. This function
2108 * will wake up thread waiting on the wait queue pointed by context1
2112 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2114 wait_queue_head_t *pdone_q;
2115 unsigned long drvr_flag;
2118 * If pdone_q is empty, the driver thread gave up waiting and
2119 * continued running.
2121 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2122 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2123 pdone_q = (wait_queue_head_t *) pmboxq->context1;
2125 wake_up_interruptible(pdone_q);
2126 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2132 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2133 * @phba: Pointer to HBA context object.
2134 * @pmb: Pointer to mailbox object.
2136 * This function is the default mailbox completion handler. It
2137 * frees the memory resources associated with the completed mailbox
2138 * command. If the completed command is a REG_LOGIN mailbox command,
2139 * this function will issue a UREG_LOGIN to re-claim the RPI.
2142 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2144 struct lpfc_vport *vport = pmb->vport;
2145 struct lpfc_dmabuf *mp;
2146 struct lpfc_nodelist *ndlp;
2147 struct Scsi_Host *shost;
2151 mp = (struct lpfc_dmabuf *) (pmb->context1);
2154 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2159 * If a REG_LOGIN succeeded after node is destroyed or node
2160 * is in re-discovery driver need to cleanup the RPI.
2162 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2163 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2164 !pmb->u.mb.mbxStatus) {
2165 rpi = pmb->u.mb.un.varWords[0];
2166 vpi = pmb->u.mb.un.varRegLogin.vpi;
2167 lpfc_unreg_login(phba, vpi, rpi, pmb);
2168 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2169 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2170 if (rc != MBX_NOT_FINISHED)
2174 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2175 !(phba->pport->load_flag & FC_UNLOADING) &&
2176 !pmb->u.mb.mbxStatus) {
2177 shost = lpfc_shost_from_vport(vport);
2178 spin_lock_irq(shost->host_lock);
2179 vport->vpi_state |= LPFC_VPI_REGISTERED;
2180 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2181 spin_unlock_irq(shost->host_lock);
2184 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2185 ndlp = (struct lpfc_nodelist *)pmb->context2;
2187 pmb->context2 = NULL;
2190 /* Check security permission status on INIT_LINK mailbox command */
2191 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2192 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2193 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2194 "2860 SLI authentication is required "
2195 "for INIT_LINK but has not done yet\n");
2197 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2198 lpfc_sli4_mbox_cmd_free(phba, pmb);
2200 mempool_free(pmb, phba->mbox_mem_pool);
2204 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2205 * @phba: Pointer to HBA context object.
2207 * This function is called with no lock held. This function processes all
2208 * the completed mailbox commands and gives it to upper layers. The interrupt
2209 * service routine processes mailbox completion interrupt and adds completed
2210 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2211 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2212 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2213 * function returns the mailbox commands to the upper layer by calling the
2214 * completion handler function of each mailbox.
2217 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
2224 phba->sli.slistat.mbox_event++;
2226 /* Get all completed mailboxe buffers into the cmplq */
2227 spin_lock_irq(&phba->hbalock);
2228 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2229 spin_unlock_irq(&phba->hbalock);
2231 /* Get a Mailbox buffer to setup mailbox commands for callback */
2233 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2239 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2241 lpfc_debugfs_disc_trc(pmb->vport,
2242 LPFC_DISC_TRC_MBOX_VPORT,
2243 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2244 (uint32_t)pmbox->mbxCommand,
2245 pmbox->un.varWords[0],
2246 pmbox->un.varWords[1]);
2249 lpfc_debugfs_disc_trc(phba->pport,
2251 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2252 (uint32_t)pmbox->mbxCommand,
2253 pmbox->un.varWords[0],
2254 pmbox->un.varWords[1]);
2259 * It is a fatal error if unknown mbox command completion.
2261 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2263 /* Unknown mailbox command compl */
2264 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2265 "(%d):0323 Unknown Mailbox command "
2266 "x%x (x%x/x%x) Cmpl\n",
2267 pmb->vport ? pmb->vport->vpi : 0,
2269 lpfc_sli_config_mbox_subsys_get(phba,
2271 lpfc_sli_config_mbox_opcode_get(phba,
2273 phba->link_state = LPFC_HBA_ERROR;
2274 phba->work_hs = HS_FFER3;
2275 lpfc_handle_eratt(phba);
2279 if (pmbox->mbxStatus) {
2280 phba->sli.slistat.mbox_stat_err++;
2281 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2282 /* Mbox cmd cmpl error - RETRYing */
2283 lpfc_printf_log(phba, KERN_INFO,
2285 "(%d):0305 Mbox cmd cmpl "
2286 "error - RETRYing Data: x%x "
2287 "(x%x/x%x) x%x x%x x%x\n",
2288 pmb->vport ? pmb->vport->vpi : 0,
2290 lpfc_sli_config_mbox_subsys_get(phba,
2292 lpfc_sli_config_mbox_opcode_get(phba,
2295 pmbox->un.varWords[0],
2296 pmb->vport->port_state);
2297 pmbox->mbxStatus = 0;
2298 pmbox->mbxOwner = OWN_HOST;
2299 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2300 if (rc != MBX_NOT_FINISHED)
2305 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2306 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2307 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2308 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2309 pmb->vport ? pmb->vport->vpi : 0,
2311 lpfc_sli_config_mbox_subsys_get(phba, pmb),
2312 lpfc_sli_config_mbox_opcode_get(phba, pmb),
2314 *((uint32_t *) pmbox),
2315 pmbox->un.varWords[0],
2316 pmbox->un.varWords[1],
2317 pmbox->un.varWords[2],
2318 pmbox->un.varWords[3],
2319 pmbox->un.varWords[4],
2320 pmbox->un.varWords[5],
2321 pmbox->un.varWords[6],
2322 pmbox->un.varWords[7]);
2325 pmb->mbox_cmpl(phba,pmb);
2331 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2332 * @phba: Pointer to HBA context object.
2333 * @pring: Pointer to driver SLI ring object.
2336 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2337 * is set in the tag the buffer is posted for a particular exchange,
2338 * the function will return the buffer without replacing the buffer.
2339 * If the buffer is for unsolicited ELS or CT traffic, this function
2340 * returns the buffer and also posts another buffer to the firmware.
2342 static struct lpfc_dmabuf *
2343 lpfc_sli_get_buff(struct lpfc_hba *phba,
2344 struct lpfc_sli_ring *pring,
2347 struct hbq_dmabuf *hbq_entry;
2349 if (tag & QUE_BUFTAG_BIT)
2350 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
2351 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2354 return &hbq_entry->dbuf;
2358 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2359 * @phba: Pointer to HBA context object.
2360 * @pring: Pointer to driver SLI ring object.
2361 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2362 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2363 * @fch_type: the type for the first frame of the sequence.
2365 * This function is called with no lock held. This function uses the r_ctl and
2366 * type of the received sequence to find the correct callback function to call
2367 * to process the sequence.
2370 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2371 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
2376 /* unSolicited Responses */
2377 if (pring->prt[0].profile) {
2378 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
2379 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
2383 /* We must search, based on rctl / type
2384 for the right routine */
2385 for (i = 0; i < pring->num_mask; i++) {
2386 if ((pring->prt[i].rctl == fch_r_ctl) &&
2387 (pring->prt[i].type == fch_type)) {
2388 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
2389 (pring->prt[i].lpfc_sli_rcv_unsol_event)
2390 (phba, pring, saveq);
2398 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2399 * @phba: Pointer to HBA context object.
2400 * @pring: Pointer to driver SLI ring object.
2401 * @saveq: Pointer to the unsolicited iocb.
2403 * This function is called with no lock held by the ring event handler
2404 * when there is an unsolicited iocb posted to the response ring by the
2405 * firmware. This function gets the buffer associated with the iocbs
2406 * and calls the event handler for the ring. This function handles both
2407 * qring buffers and hbq buffers.
2408 * When the function returns 1 the caller can free the iocb object otherwise
2409 * upper layer functions will free the iocb objects.
2412 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2413 struct lpfc_iocbq *saveq)
2417 uint32_t Rctl, Type;
2419 struct lpfc_iocbq *iocbq;
2420 struct lpfc_dmabuf *dmzbuf;
2423 irsp = &(saveq->iocb);
2425 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
2426 if (pring->lpfc_sli_rcv_async_status)
2427 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
2429 lpfc_printf_log(phba,
2432 "0316 Ring %d handler: unexpected "
2433 "ASYNC_STATUS iocb received evt_code "
2436 irsp->un.asyncstat.evt_code);
2440 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
2441 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
2442 if (irsp->ulpBdeCount > 0) {
2443 dmzbuf = lpfc_sli_get_buff(phba, pring,
2444 irsp->un.ulpWord[3]);
2445 lpfc_in_buf_free(phba, dmzbuf);
2448 if (irsp->ulpBdeCount > 1) {
2449 dmzbuf = lpfc_sli_get_buff(phba, pring,
2450 irsp->unsli3.sli3Words[3]);
2451 lpfc_in_buf_free(phba, dmzbuf);
2454 if (irsp->ulpBdeCount > 2) {
2455 dmzbuf = lpfc_sli_get_buff(phba, pring,
2456 irsp->unsli3.sli3Words[7]);
2457 lpfc_in_buf_free(phba, dmzbuf);
2463 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2464 if (irsp->ulpBdeCount != 0) {
2465 saveq->context2 = lpfc_sli_get_buff(phba, pring,
2466 irsp->un.ulpWord[3]);
2467 if (!saveq->context2)
2468 lpfc_printf_log(phba,
2471 "0341 Ring %d Cannot find buffer for "
2472 "an unsolicited iocb. tag 0x%x\n",
2474 irsp->un.ulpWord[3]);
2476 if (irsp->ulpBdeCount == 2) {
2477 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2478 irsp->unsli3.sli3Words[7]);
2479 if (!saveq->context3)
2480 lpfc_printf_log(phba,
2483 "0342 Ring %d Cannot find buffer for an"
2484 " unsolicited iocb. tag 0x%x\n",
2486 irsp->unsli3.sli3Words[7]);
2488 list_for_each_entry(iocbq, &saveq->list, list) {
2489 irsp = &(iocbq->iocb);
2490 if (irsp->ulpBdeCount != 0) {
2491 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2492 irsp->un.ulpWord[3]);
2493 if (!iocbq->context2)
2494 lpfc_printf_log(phba,
2497 "0343 Ring %d Cannot find "
2498 "buffer for an unsolicited iocb"
2499 ". tag 0x%x\n", pring->ringno,
2500 irsp->un.ulpWord[3]);
2502 if (irsp->ulpBdeCount == 2) {
2503 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2504 irsp->unsli3.sli3Words[7]);
2505 if (!iocbq->context3)
2506 lpfc_printf_log(phba,
2509 "0344 Ring %d Cannot find "
2510 "buffer for an unsolicited "
2513 irsp->unsli3.sli3Words[7]);
2517 if (irsp->ulpBdeCount != 0 &&
2518 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2519 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2522 /* search continue save q for same XRI */
2523 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2524 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
2525 saveq->iocb.unsli3.rcvsli3.ox_id) {
2526 list_add_tail(&saveq->list, &iocbq->list);
2532 list_add_tail(&saveq->clist,
2533 &pring->iocb_continue_saveq);
2534 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2535 list_del_init(&iocbq->clist);
2537 irsp = &(saveq->iocb);
2541 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2542 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2543 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2544 Rctl = FC_RCTL_ELS_REQ;
2547 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2548 Rctl = w5p->hcsw.Rctl;
2549 Type = w5p->hcsw.Type;
2551 /* Firmware Workaround */
2552 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2553 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2554 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2555 Rctl = FC_RCTL_ELS_REQ;
2557 w5p->hcsw.Rctl = Rctl;
2558 w5p->hcsw.Type = Type;
2562 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2563 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2564 "0313 Ring %d handler: unexpected Rctl x%x "
2565 "Type x%x received\n",
2566 pring->ringno, Rctl, Type);
2572 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2573 * @phba: Pointer to HBA context object.
2574 * @pring: Pointer to driver SLI ring object.
2575 * @prspiocb: Pointer to response iocb object.
2577 * This function looks up the iocb_lookup table to get the command iocb
2578 * corresponding to the given response iocb using the iotag of the
2579 * response iocb. This function is called with the hbalock held.
2580 * This function returns the command iocb object if it finds the command
2581 * iocb else returns NULL.
2583 static struct lpfc_iocbq *
2584 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2585 struct lpfc_sli_ring *pring,
2586 struct lpfc_iocbq *prspiocb)
2588 struct lpfc_iocbq *cmd_iocb = NULL;
2591 iotag = prspiocb->iocb.ulpIoTag;
2593 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2594 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2595 list_del_init(&cmd_iocb->list);
2596 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
2597 pring->txcmplq_cnt--;
2598 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
2603 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2604 "0317 iotag x%x is out off "
2605 "range: max iotag x%x wd0 x%x\n",
2606 iotag, phba->sli.last_iotag,
2607 *(((uint32_t *) &prspiocb->iocb) + 7));
2612 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2613 * @phba: Pointer to HBA context object.
2614 * @pring: Pointer to driver SLI ring object.
2617 * This function looks up the iocb_lookup table to get the command iocb
2618 * corresponding to the given iotag. This function is called with the
2620 * This function returns the command iocb object if it finds the command
2621 * iocb else returns NULL.
2623 static struct lpfc_iocbq *
2624 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2625 struct lpfc_sli_ring *pring, uint16_t iotag)
2627 struct lpfc_iocbq *cmd_iocb;
2629 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2630 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2631 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
2632 /* remove from txcmpl queue list */
2633 list_del_init(&cmd_iocb->list);
2634 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
2635 pring->txcmplq_cnt--;
2639 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2640 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2641 iotag, phba->sli.last_iotag);
2646 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2647 * @phba: Pointer to HBA context object.
2648 * @pring: Pointer to driver SLI ring object.
2649 * @saveq: Pointer to the response iocb to be processed.
2651 * This function is called by the ring event handler for non-fcp
2652 * rings when there is a new response iocb in the response ring.
2653 * The caller is not required to hold any locks. This function
2654 * gets the command iocb associated with the response iocb and
2655 * calls the completion handler for the command iocb. If there
2656 * is no completion handler, the function will free the resources
2657 * associated with command iocb. If the response iocb is for
2658 * an already aborted command iocb, the status of the completion
2659 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2660 * This function always returns 1.
2663 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2664 struct lpfc_iocbq *saveq)
2666 struct lpfc_iocbq *cmdiocbp;
2668 unsigned long iflag;
2670 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2671 spin_lock_irqsave(&phba->hbalock, iflag);
2672 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
2673 spin_unlock_irqrestore(&phba->hbalock, iflag);
2676 if (cmdiocbp->iocb_cmpl) {
2678 * If an ELS command failed send an event to mgmt
2681 if (saveq->iocb.ulpStatus &&
2682 (pring->ringno == LPFC_ELS_RING) &&
2683 (cmdiocbp->iocb.ulpCommand ==
2684 CMD_ELS_REQUEST64_CR))
2685 lpfc_send_els_failure_event(phba,
2689 * Post all ELS completions to the worker thread.
2690 * All other are passed to the completion callback.
2692 if (pring->ringno == LPFC_ELS_RING) {
2693 if ((phba->sli_rev < LPFC_SLI_REV4) &&
2694 (cmdiocbp->iocb_flag &
2695 LPFC_DRIVER_ABORTED)) {
2696 spin_lock_irqsave(&phba->hbalock,
2698 cmdiocbp->iocb_flag &=
2699 ~LPFC_DRIVER_ABORTED;
2700 spin_unlock_irqrestore(&phba->hbalock,
2702 saveq->iocb.ulpStatus =
2703 IOSTAT_LOCAL_REJECT;
2704 saveq->iocb.un.ulpWord[4] =
2707 /* Firmware could still be in progress
2708 * of DMAing payload, so don't free data
2709 * buffer till after a hbeat.
2711 spin_lock_irqsave(&phba->hbalock,
2713 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2714 spin_unlock_irqrestore(&phba->hbalock,
2717 if (phba->sli_rev == LPFC_SLI_REV4) {
2718 if (saveq->iocb_flag &
2719 LPFC_EXCHANGE_BUSY) {
2720 /* Set cmdiocb flag for the
2721 * exchange busy so sgl (xri)
2722 * will not be released until
2723 * the abort xri is received
2727 &phba->hbalock, iflag);
2728 cmdiocbp->iocb_flag |=
2730 spin_unlock_irqrestore(
2731 &phba->hbalock, iflag);
2733 if (cmdiocbp->iocb_flag &
2734 LPFC_DRIVER_ABORTED) {
2736 * Clear LPFC_DRIVER_ABORTED
2737 * bit in case it was driver
2741 &phba->hbalock, iflag);
2742 cmdiocbp->iocb_flag &=
2743 ~LPFC_DRIVER_ABORTED;
2744 spin_unlock_irqrestore(
2745 &phba->hbalock, iflag);
2746 cmdiocbp->iocb.ulpStatus =
2747 IOSTAT_LOCAL_REJECT;
2748 cmdiocbp->iocb.un.ulpWord[4] =
2749 IOERR_ABORT_REQUESTED;
2751 * For SLI4, irsiocb contains
2752 * NO_XRI in sli_xritag, it
2753 * shall not affect releasing
2754 * sgl (xri) process.
2756 saveq->iocb.ulpStatus =
2757 IOSTAT_LOCAL_REJECT;
2758 saveq->iocb.un.ulpWord[4] =
2761 &phba->hbalock, iflag);
2763 LPFC_DELAY_MEM_FREE;
2764 spin_unlock_irqrestore(
2765 &phba->hbalock, iflag);
2769 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
2771 lpfc_sli_release_iocbq(phba, cmdiocbp);
2774 * Unknown initiating command based on the response iotag.
2775 * This could be the case on the ELS ring because of
2778 if (pring->ringno != LPFC_ELS_RING) {
2780 * Ring <ringno> handler: unexpected completion IoTag
2783 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2784 "0322 Ring %d handler: "
2785 "unexpected completion IoTag x%x "
2786 "Data: x%x x%x x%x x%x\n",
2788 saveq->iocb.ulpIoTag,
2789 saveq->iocb.ulpStatus,
2790 saveq->iocb.un.ulpWord[4],
2791 saveq->iocb.ulpCommand,
2792 saveq->iocb.ulpContext);
2800 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2801 * @phba: Pointer to HBA context object.
2802 * @pring: Pointer to driver SLI ring object.
2804 * This function is called from the iocb ring event handlers when
2805 * put pointer is ahead of the get pointer for a ring. This function signal
2806 * an error attention condition to the worker thread and the worker
2807 * thread will transition the HBA to offline state.
2810 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2812 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2814 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2815 * rsp ring <portRspMax>
2817 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2818 "0312 Ring %d handler: portRspPut %d "
2819 "is bigger than rsp ring %d\n",
2820 pring->ringno, le32_to_cpu(pgp->rspPutInx),
2821 pring->sli.sli3.numRiocb);
2823 phba->link_state = LPFC_HBA_ERROR;
2826 * All error attention handlers are posted to
2829 phba->work_ha |= HA_ERATT;
2830 phba->work_hs = HS_FFER3;
2832 lpfc_worker_wake_up(phba);
2838 * lpfc_poll_eratt - Error attention polling timer timeout handler
2839 * @ptr: Pointer to address of HBA context object.
2841 * This function is invoked by the Error Attention polling timer when the
2842 * timer times out. It will check the SLI Error Attention register for
2843 * possible attention events. If so, it will post an Error Attention event
2844 * and wake up worker thread to process it. Otherwise, it will set up the
2845 * Error Attention polling timer for the next poll.
2847 void lpfc_poll_eratt(unsigned long ptr)
2849 struct lpfc_hba *phba;
2850 uint32_t eratt = 0, rem;
2851 uint64_t sli_intr, cnt;
2853 phba = (struct lpfc_hba *)ptr;
2855 /* Here we will also keep track of interrupts per sec of the hba */
2856 sli_intr = phba->sli.slistat.sli_intr;
2858 if (phba->sli.slistat.sli_prev_intr > sli_intr)
2859 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
2862 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
2864 /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
2865 rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
2866 phba->sli.slistat.sli_ips = cnt;
2868 phba->sli.slistat.sli_prev_intr = sli_intr;
2870 /* Check chip HA register for error event */
2871 eratt = lpfc_sli_check_eratt(phba);
2874 /* Tell the worker thread there is work to do */
2875 lpfc_worker_wake_up(phba);
2877 /* Restart the timer for next eratt poll */
2878 mod_timer(&phba->eratt_poll, jiffies +
2879 HZ * LPFC_ERATT_POLL_INTERVAL);
2885 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2886 * @phba: Pointer to HBA context object.
2887 * @pring: Pointer to driver SLI ring object.
2888 * @mask: Host attention register mask for this ring.
2890 * This function is called from the interrupt context when there is a ring
2891 * event for the fcp ring. The caller does not hold any lock.
2892 * The function processes each response iocb in the response ring until it
2893 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2894 * LE bit set. The function will call the completion handler of the command iocb
2895 * if the response iocb indicates a completion for a command iocb or it is
2896 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2897 * function if this is an unsolicited iocb.
2898 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2899 * to check it explicitly.
2902 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
2903 struct lpfc_sli_ring *pring, uint32_t mask)
2905 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2906 IOCB_t *irsp = NULL;
2907 IOCB_t *entry = NULL;
2908 struct lpfc_iocbq *cmdiocbq = NULL;
2909 struct lpfc_iocbq rspiocbq;
2911 uint32_t portRspPut, portRspMax;
2913 lpfc_iocb_type type;
2914 unsigned long iflag;
2915 uint32_t rsp_cmpl = 0;
2917 spin_lock_irqsave(&phba->hbalock, iflag);
2918 pring->stats.iocb_event++;
2921 * The next available response entry should never exceed the maximum
2922 * entries. If it does, treat it as an adapter hardware error.
2924 portRspMax = pring->sli.sli3.numRiocb;
2925 portRspPut = le32_to_cpu(pgp->rspPutInx);
2926 if (unlikely(portRspPut >= portRspMax)) {
2927 lpfc_sli_rsp_pointers_error(phba, pring);
2928 spin_unlock_irqrestore(&phba->hbalock, iflag);
2931 if (phba->fcp_ring_in_use) {
2932 spin_unlock_irqrestore(&phba->hbalock, iflag);
2935 phba->fcp_ring_in_use = 1;
2938 while (pring->sli.sli3.rspidx != portRspPut) {
2940 * Fetch an entry off the ring and copy it into a local data
2941 * structure. The copy involves a byte-swap since the
2942 * network byte order and pci byte orders are different.
2944 entry = lpfc_resp_iocb(phba, pring);
2945 phba->last_completion_time = jiffies;
2947 if (++pring->sli.sli3.rspidx >= portRspMax)
2948 pring->sli.sli3.rspidx = 0;
2950 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2951 (uint32_t *) &rspiocbq.iocb,
2952 phba->iocb_rsp_size);
2953 INIT_LIST_HEAD(&(rspiocbq.list));
2954 irsp = &rspiocbq.iocb;
2956 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2957 pring->stats.iocb_rsp++;
2960 if (unlikely(irsp->ulpStatus)) {
2962 * If resource errors reported from HBA, reduce
2963 * queuedepths of the SCSI device.
2965 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2966 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
2967 IOERR_NO_RESOURCES)) {
2968 spin_unlock_irqrestore(&phba->hbalock, iflag);
2969 phba->lpfc_rampdown_queue_depth(phba);
2970 spin_lock_irqsave(&phba->hbalock, iflag);
2973 /* Rsp ring <ringno> error: IOCB */
2974 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2975 "0336 Rsp Ring %d error: IOCB Data: "
2976 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2978 irsp->un.ulpWord[0],
2979 irsp->un.ulpWord[1],
2980 irsp->un.ulpWord[2],
2981 irsp->un.ulpWord[3],
2982 irsp->un.ulpWord[4],
2983 irsp->un.ulpWord[5],
2984 *(uint32_t *)&irsp->un1,
2985 *((uint32_t *)&irsp->un1 + 1));
2989 case LPFC_ABORT_IOCB:
2992 * Idle exchange closed via ABTS from port. No iocb
2993 * resources need to be recovered.
2995 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2996 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2997 "0333 IOCB cmd 0x%x"
2998 " processed. Skipping"
3004 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3006 if (unlikely(!cmdiocbq))
3008 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3009 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3010 if (cmdiocbq->iocb_cmpl) {
3011 spin_unlock_irqrestore(&phba->hbalock, iflag);
3012 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
3014 spin_lock_irqsave(&phba->hbalock, iflag);
3017 case LPFC_UNSOL_IOCB:
3018 spin_unlock_irqrestore(&phba->hbalock, iflag);
3019 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
3020 spin_lock_irqsave(&phba->hbalock, iflag);
3023 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3024 char adaptermsg[LPFC_MAX_ADPTMSG];
3025 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3026 memcpy(&adaptermsg[0], (uint8_t *) irsp,
3028 dev_warn(&((phba->pcidev)->dev),
3030 phba->brd_no, adaptermsg);
3032 /* Unknown IOCB command */
3033 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3034 "0334 Unknown IOCB command "
3035 "Data: x%x, x%x x%x x%x x%x\n",
3036 type, irsp->ulpCommand,
3045 * The response IOCB has been processed. Update the ring
3046 * pointer in SLIM. If the port response put pointer has not
3047 * been updated, sync the pgp->rspPutInx and fetch the new port
3048 * response put pointer.
3050 writel(pring->sli.sli3.rspidx,
3051 &phba->host_gp[pring->ringno].rspGetInx);
3053 if (pring->sli.sli3.rspidx == portRspPut)
3054 portRspPut = le32_to_cpu(pgp->rspPutInx);
3057 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
3058 pring->stats.iocb_rsp_full++;
3059 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3060 writel(status, phba->CAregaddr);
3061 readl(phba->CAregaddr);
3063 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3064 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3065 pring->stats.iocb_cmd_empty++;
3067 /* Force update of the local copy of cmdGetInx */
3068 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3069 lpfc_sli_resume_iocb(phba, pring);
3071 if ((pring->lpfc_sli_cmd_available))
3072 (pring->lpfc_sli_cmd_available) (phba, pring);
3076 phba->fcp_ring_in_use = 0;
3077 spin_unlock_irqrestore(&phba->hbalock, iflag);
3082 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3083 * @phba: Pointer to HBA context object.
3084 * @pring: Pointer to driver SLI ring object.
3085 * @rspiocbp: Pointer to driver response IOCB object.
3087 * This function is called from the worker thread when there is a slow-path
3088 * response IOCB to process. This function chains all the response iocbs until
3089 * seeing the iocb with the LE bit set. The function will call
3090 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3091 * completion of a command iocb. The function will call the
3092 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3093 * The function frees the resources or calls the completion handler if this
3094 * iocb is an abort completion. The function returns NULL when the response
3095 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3096 * this function shall chain the iocb on to the iocb_continueq and return the
3097 * response iocb passed in.
3099 static struct lpfc_iocbq *
3100 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3101 struct lpfc_iocbq *rspiocbp)
3103 struct lpfc_iocbq *saveq;
3104 struct lpfc_iocbq *cmdiocbp;
3105 struct lpfc_iocbq *next_iocb;
3106 IOCB_t *irsp = NULL;
3107 uint32_t free_saveq;
3108 uint8_t iocb_cmd_type;
3109 lpfc_iocb_type type;
3110 unsigned long iflag;
3113 spin_lock_irqsave(&phba->hbalock, iflag);
3114 /* First add the response iocb to the countinueq list */
3115 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3116 pring->iocb_continueq_cnt++;
3118 /* Now, determine whether the list is completed for processing */
3119 irsp = &rspiocbp->iocb;
3122 * By default, the driver expects to free all resources
3123 * associated with this iocb completion.
3126 saveq = list_get_first(&pring->iocb_continueq,
3127 struct lpfc_iocbq, list);
3128 irsp = &(saveq->iocb);
3129 list_del_init(&pring->iocb_continueq);
3130 pring->iocb_continueq_cnt = 0;
3132 pring->stats.iocb_rsp++;
3135 * If resource errors reported from HBA, reduce
3136 * queuedepths of the SCSI device.
3138 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3139 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3140 IOERR_NO_RESOURCES)) {
3141 spin_unlock_irqrestore(&phba->hbalock, iflag);
3142 phba->lpfc_rampdown_queue_depth(phba);
3143 spin_lock_irqsave(&phba->hbalock, iflag);
3146 if (irsp->ulpStatus) {
3147 /* Rsp ring <ringno> error: IOCB */
3148 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3149 "0328 Rsp Ring %d error: "
3154 "x%x x%x x%x x%x\n",
3156 irsp->un.ulpWord[0],
3157 irsp->un.ulpWord[1],
3158 irsp->un.ulpWord[2],
3159 irsp->un.ulpWord[3],
3160 irsp->un.ulpWord[4],
3161 irsp->un.ulpWord[5],
3162 *(((uint32_t *) irsp) + 6),
3163 *(((uint32_t *) irsp) + 7),
3164 *(((uint32_t *) irsp) + 8),
3165 *(((uint32_t *) irsp) + 9),
3166 *(((uint32_t *) irsp) + 10),
3167 *(((uint32_t *) irsp) + 11),
3168 *(((uint32_t *) irsp) + 12),
3169 *(((uint32_t *) irsp) + 13),
3170 *(((uint32_t *) irsp) + 14),
3171 *(((uint32_t *) irsp) + 15));
3175 * Fetch the IOCB command type and call the correct completion
3176 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3177 * get freed back to the lpfc_iocb_list by the discovery
3180 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3181 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3184 spin_unlock_irqrestore(&phba->hbalock, iflag);
3185 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3186 spin_lock_irqsave(&phba->hbalock, iflag);
3189 case LPFC_UNSOL_IOCB:
3190 spin_unlock_irqrestore(&phba->hbalock, iflag);
3191 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3192 spin_lock_irqsave(&phba->hbalock, iflag);
3197 case LPFC_ABORT_IOCB:
3199 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
3200 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3203 /* Call the specified completion routine */
3204 if (cmdiocbp->iocb_cmpl) {
3205 spin_unlock_irqrestore(&phba->hbalock,
3207 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3209 spin_lock_irqsave(&phba->hbalock,
3212 __lpfc_sli_release_iocbq(phba,
3217 case LPFC_UNKNOWN_IOCB:
3218 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3219 char adaptermsg[LPFC_MAX_ADPTMSG];
3220 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3221 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3223 dev_warn(&((phba->pcidev)->dev),
3225 phba->brd_no, adaptermsg);
3227 /* Unknown IOCB command */
3228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3229 "0335 Unknown IOCB "
3230 "command Data: x%x "
3241 list_for_each_entry_safe(rspiocbp, next_iocb,
3242 &saveq->list, list) {
3243 list_del(&rspiocbp->list);
3244 __lpfc_sli_release_iocbq(phba, rspiocbp);
3246 __lpfc_sli_release_iocbq(phba, saveq);
3250 spin_unlock_irqrestore(&phba->hbalock, iflag);
3255 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3256 * @phba: Pointer to HBA context object.
3257 * @pring: Pointer to driver SLI ring object.
3258 * @mask: Host attention register mask for this ring.
3260 * This routine wraps the actual slow_ring event process routine from the
3261 * API jump table function pointer from the lpfc_hba struct.
3264 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
3265 struct lpfc_sli_ring *pring, uint32_t mask)
3267 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
3271 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3272 * @phba: Pointer to HBA context object.
3273 * @pring: Pointer to driver SLI ring object.
3274 * @mask: Host attention register mask for this ring.
3276 * This function is called from the worker thread when there is a ring event
3277 * for non-fcp rings. The caller does not hold any lock. The function will
3278 * remove each response iocb in the response ring and calls the handle
3279 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3282 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
3283 struct lpfc_sli_ring *pring, uint32_t mask)
3285 struct lpfc_pgp *pgp;
3287 IOCB_t *irsp = NULL;
3288 struct lpfc_iocbq *rspiocbp = NULL;
3289 uint32_t portRspPut, portRspMax;
3290 unsigned long iflag;
3293 pgp = &phba->port_gp[pring->ringno];
3294 spin_lock_irqsave(&phba->hbalock, iflag);
3295 pring->stats.iocb_event++;
3298 * The next available response entry should never exceed the maximum
3299 * entries. If it does, treat it as an adapter hardware error.
3301 portRspMax = pring->sli.sli3.numRiocb;
3302 portRspPut = le32_to_cpu(pgp->rspPutInx);
3303 if (portRspPut >= portRspMax) {
3305 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3306 * rsp ring <portRspMax>
3308 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3309 "0303 Ring %d handler: portRspPut %d "
3310 "is bigger than rsp ring %d\n",
3311 pring->ringno, portRspPut, portRspMax);
3313 phba->link_state = LPFC_HBA_ERROR;
3314 spin_unlock_irqrestore(&phba->hbalock, iflag);
3316 phba->work_hs = HS_FFER3;
3317 lpfc_handle_eratt(phba);
3323 while (pring->sli.sli3.rspidx != portRspPut) {
3325 * Build a completion list and call the appropriate handler.
3326 * The process is to get the next available response iocb, get
3327 * a free iocb from the list, copy the response data into the
3328 * free iocb, insert to the continuation list, and update the
3329 * next response index to slim. This process makes response
3330 * iocb's in the ring available to DMA as fast as possible but
3331 * pays a penalty for a copy operation. Since the iocb is
3332 * only 32 bytes, this penalty is considered small relative to
3333 * the PCI reads for register values and a slim write. When
3334 * the ulpLe field is set, the entire Command has been
3337 entry = lpfc_resp_iocb(phba, pring);
3339 phba->last_completion_time = jiffies;
3340 rspiocbp = __lpfc_sli_get_iocbq(phba);
3341 if (rspiocbp == NULL) {
3342 printk(KERN_ERR "%s: out of buffers! Failing "
3343 "completion.\n", __func__);
3347 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
3348 phba->iocb_rsp_size);
3349 irsp = &rspiocbp->iocb;
3351 if (++pring->sli.sli3.rspidx >= portRspMax)
3352 pring->sli.sli3.rspidx = 0;
3354 if (pring->ringno == LPFC_ELS_RING) {
3355 lpfc_debugfs_slow_ring_trc(phba,
3356 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3357 *(((uint32_t *) irsp) + 4),
3358 *(((uint32_t *) irsp) + 6),
3359 *(((uint32_t *) irsp) + 7));
3362 writel(pring->sli.sli3.rspidx,
3363 &phba->host_gp[pring->ringno].rspGetInx);
3365 spin_unlock_irqrestore(&phba->hbalock, iflag);
3366 /* Handle the response IOCB */
3367 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
3368 spin_lock_irqsave(&phba->hbalock, iflag);
3371 * If the port response put pointer has not been updated, sync
3372 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3373 * response put pointer.
3375 if (pring->sli.sli3.rspidx == portRspPut) {
3376 portRspPut = le32_to_cpu(pgp->rspPutInx);
3378 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3380 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
3381 /* At least one response entry has been freed */
3382 pring->stats.iocb_rsp_full++;
3383 /* SET RxRE_RSP in Chip Att register */
3384 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3385 writel(status, phba->CAregaddr);
3386 readl(phba->CAregaddr); /* flush */
3388 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3389 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3390 pring->stats.iocb_cmd_empty++;
3392 /* Force update of the local copy of cmdGetInx */
3393 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3394 lpfc_sli_resume_iocb(phba, pring);
3396 if ((pring->lpfc_sli_cmd_available))
3397 (pring->lpfc_sli_cmd_available) (phba, pring);
3401 spin_unlock_irqrestore(&phba->hbalock, iflag);
3406 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3407 * @phba: Pointer to HBA context object.
3408 * @pring: Pointer to driver SLI ring object.
3409 * @mask: Host attention register mask for this ring.
3411 * This function is called from the worker thread when there is a pending
3412 * ELS response iocb on the driver internal slow-path response iocb worker
3413 * queue. The caller does not hold any lock. The function will remove each
3414 * response iocb from the response worker queue and calls the handle
3415 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3418 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3419 struct lpfc_sli_ring *pring, uint32_t mask)
3421 struct lpfc_iocbq *irspiocbq;
3422 struct hbq_dmabuf *dmabuf;
3423 struct lpfc_cq_event *cq_event;
3424 unsigned long iflag;
3426 spin_lock_irqsave(&phba->hbalock, iflag);
3427 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
3428 spin_unlock_irqrestore(&phba->hbalock, iflag);
3429 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
3430 /* Get the response iocb from the head of work queue */
3431 spin_lock_irqsave(&phba->hbalock, iflag);
3432 list_remove_head(&phba->sli4_hba.sp_queue_event,
3433 cq_event, struct lpfc_cq_event, list);
3434 spin_unlock_irqrestore(&phba->hbalock, iflag);
3436 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
3437 case CQE_CODE_COMPL_WQE:
3438 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
3440 /* Translate ELS WCQE to response IOCBQ */
3441 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
3444 lpfc_sli_sp_handle_rspiocb(phba, pring,
3447 case CQE_CODE_RECEIVE:
3448 case CQE_CODE_RECEIVE_V1:
3449 dmabuf = container_of(cq_event, struct hbq_dmabuf,
3451 lpfc_sli4_handle_received_buffer(phba, dmabuf);
3460 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3461 * @phba: Pointer to HBA context object.
3462 * @pring: Pointer to driver SLI ring object.
3464 * This function aborts all iocbs in the given ring and frees all the iocb
3465 * objects in txq. This function issues an abort iocb for all the iocb commands
3466 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3467 * the return of this function. The caller is not required to hold any locks.
3470 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3472 LIST_HEAD(completions);
3473 struct lpfc_iocbq *iocb, *next_iocb;
3475 if (pring->ringno == LPFC_ELS_RING) {
3476 lpfc_fabric_abort_hba(phba);
3479 /* Error everything on txq and txcmplq
3482 spin_lock_irq(&phba->hbalock);
3483 list_splice_init(&pring->txq, &completions);
3486 /* Next issue ABTS for everything on the txcmplq */
3487 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3488 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3490 spin_unlock_irq(&phba->hbalock);
3492 /* Cancel all the IOCBs from the completions list */
3493 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3498 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3499 * @phba: Pointer to HBA context object.
3501 * This function flushes all iocbs in the fcp ring and frees all the iocb
3502 * objects in txq and txcmplq. This function will not issue abort iocbs
3503 * for all the iocb commands in txcmplq, they will just be returned with
3504 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3505 * slot has been permanently disabled.
3508 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3512 struct lpfc_sli *psli = &phba->sli;
3513 struct lpfc_sli_ring *pring;
3515 /* Currently, only one fcp ring */
3516 pring = &psli->ring[psli->fcp_ring];
3518 spin_lock_irq(&phba->hbalock);
3519 /* Retrieve everything on txq */
3520 list_splice_init(&pring->txq, &txq);
3523 /* Retrieve everything on the txcmplq */
3524 list_splice_init(&pring->txcmplq, &txcmplq);
3525 pring->txcmplq_cnt = 0;
3527 /* Indicate the I/O queues are flushed */
3528 phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
3529 spin_unlock_irq(&phba->hbalock);
3532 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3535 /* Flush the txcmpq */
3536 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3541 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3542 * @phba: Pointer to HBA context object.
3543 * @mask: Bit mask to be checked.
3545 * This function reads the host status register and compares
3546 * with the provided bit mask to check if HBA completed
3547 * the restart. This function will wait in a loop for the
3548 * HBA to complete restart. If the HBA does not restart within
3549 * 15 iterations, the function will reset the HBA again. The
3550 * function returns 1 when HBA fail to restart otherwise returns
3554 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
3560 /* Read the HBA Host Status Register */
3561 if (lpfc_readl(phba->HSregaddr, &status))
3565 * Check status register every 100ms for 5 retries, then every
3566 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3567 * every 2.5 sec for 4.
3568 * Break our of the loop if errors occurred during init.
3570 while (((status & mask) != mask) &&
3571 !(status & HS_FFERM) &&
3583 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3584 lpfc_sli_brdrestart(phba);
3586 /* Read the HBA Host Status Register */
3587 if (lpfc_readl(phba->HSregaddr, &status)) {
3593 /* Check to see if any errors occurred during init */
3594 if ((status & HS_FFERM) || (i >= 20)) {
3595 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3596 "2751 Adapter failed to restart, "
3597 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3599 readl(phba->MBslimaddr + 0xa8),
3600 readl(phba->MBslimaddr + 0xac));
3601 phba->link_state = LPFC_HBA_ERROR;
3609 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3610 * @phba: Pointer to HBA context object.
3611 * @mask: Bit mask to be checked.
3613 * This function checks the host status register to check if HBA is
3614 * ready. This function will wait in a loop for the HBA to be ready
3615 * If the HBA is not ready , the function will will reset the HBA PCI
3616 * function again. The function returns 1 when HBA fail to be ready
3617 * otherwise returns zero.
3620 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3625 /* Read the HBA Host Status Register */
3626 status = lpfc_sli4_post_status_check(phba);
3629 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3630 lpfc_sli_brdrestart(phba);
3631 status = lpfc_sli4_post_status_check(phba);
3634 /* Check to see if any errors occurred during init */
3636 phba->link_state = LPFC_HBA_ERROR;
3639 phba->sli4_hba.intr_enable = 0;
3645 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3646 * @phba: Pointer to HBA context object.
3647 * @mask: Bit mask to be checked.
3649 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3650 * from the API jump table function pointer from the lpfc_hba struct.
3653 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3655 return phba->lpfc_sli_brdready(phba, mask);
3658 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3661 * lpfc_reset_barrier - Make HBA ready for HBA reset
3662 * @phba: Pointer to HBA context object.
3664 * This function is called before resetting an HBA. This function is called
3665 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3667 void lpfc_reset_barrier(struct lpfc_hba *phba)
3669 uint32_t __iomem *resp_buf;
3670 uint32_t __iomem *mbox_buf;
3671 volatile uint32_t mbox;
3672 uint32_t hc_copy, ha_copy, resp_data;
3676 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3677 if (hdrtype != 0x80 ||
3678 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3679 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3683 * Tell the other part of the chip to suspend temporarily all
3686 resp_buf = phba->MBslimaddr;
3688 /* Disable the error attention */
3689 if (lpfc_readl(phba->HCregaddr, &hc_copy))
3691 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3692 readl(phba->HCregaddr); /* flush */
3693 phba->link_flag |= LS_IGNORE_ERATT;
3695 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3697 if (ha_copy & HA_ERATT) {
3698 /* Clear Chip error bit */
3699 writel(HA_ERATT, phba->HAregaddr);
3700 phba->pport->stopped = 1;
3704 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
3705 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
3707 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
3708 mbox_buf = phba->MBslimaddr;
3709 writel(mbox, mbox_buf);
3711 for (i = 0; i < 50; i++) {
3712 if (lpfc_readl((resp_buf + 1), &resp_data))
3714 if (resp_data != ~(BARRIER_TEST_PATTERN))
3720 if (lpfc_readl((resp_buf + 1), &resp_data))
3722 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
3723 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
3724 phba->pport->stopped)
3730 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
3732 for (i = 0; i < 500; i++) {
3733 if (lpfc_readl(resp_buf, &resp_data))
3735 if (resp_data != mbox)
3744 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3746 if (!(ha_copy & HA_ERATT))
3752 if (readl(phba->HAregaddr) & HA_ERATT) {
3753 writel(HA_ERATT, phba->HAregaddr);
3754 phba->pport->stopped = 1;
3758 phba->link_flag &= ~LS_IGNORE_ERATT;
3759 writel(hc_copy, phba->HCregaddr);
3760 readl(phba->HCregaddr); /* flush */
3764 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3765 * @phba: Pointer to HBA context object.
3767 * This function issues a kill_board mailbox command and waits for
3768 * the error attention interrupt. This function is called for stopping
3769 * the firmware processing. The caller is not required to hold any
3770 * locks. This function calls lpfc_hba_down_post function to free
3771 * any pending commands after the kill. The function will return 1 when it
3772 * fails to kill the board else will return 0.
3775 lpfc_sli_brdkill(struct lpfc_hba *phba)
3777 struct lpfc_sli *psli;
3787 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3788 "0329 Kill HBA Data: x%x x%x\n",
3789 phba->pport->port_state, psli->sli_flag);
3791 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3795 /* Disable the error attention */
3796 spin_lock_irq(&phba->hbalock);
3797 if (lpfc_readl(phba->HCregaddr, &status)) {
3798 spin_unlock_irq(&phba->hbalock);
3799 mempool_free(pmb, phba->mbox_mem_pool);
3802 status &= ~HC_ERINT_ENA;
3803 writel(status, phba->HCregaddr);
3804 readl(phba->HCregaddr); /* flush */
3805 phba->link_flag |= LS_IGNORE_ERATT;
3806 spin_unlock_irq(&phba->hbalock);
3808 lpfc_kill_board(phba, pmb);
3809 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3810 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3812 if (retval != MBX_SUCCESS) {
3813 if (retval != MBX_BUSY)
3814 mempool_free(pmb, phba->mbox_mem_pool);
3815 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3816 "2752 KILL_BOARD command failed retval %d\n",
3818 spin_lock_irq(&phba->hbalock);
3819 phba->link_flag &= ~LS_IGNORE_ERATT;
3820 spin_unlock_irq(&phba->hbalock);
3824 spin_lock_irq(&phba->hbalock);
3825 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
3826 spin_unlock_irq(&phba->hbalock);
3828 mempool_free(pmb, phba->mbox_mem_pool);
3830 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3831 * attention every 100ms for 3 seconds. If we don't get ERATT after
3832 * 3 seconds we still set HBA_ERROR state because the status of the
3833 * board is now undefined.
3835 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3837 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
3839 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3843 del_timer_sync(&psli->mbox_tmo);
3844 if (ha_copy & HA_ERATT) {
3845 writel(HA_ERATT, phba->HAregaddr);
3846 phba->pport->stopped = 1;
3848 spin_lock_irq(&phba->hbalock);
3849 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3850 psli->mbox_active = NULL;
3851 phba->link_flag &= ~LS_IGNORE_ERATT;
3852 spin_unlock_irq(&phba->hbalock);
3854 lpfc_hba_down_post(phba);
3855 phba->link_state = LPFC_HBA_ERROR;
3857 return ha_copy & HA_ERATT ? 0 : 1;
3861 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3862 * @phba: Pointer to HBA context object.
3864 * This function resets the HBA by writing HC_INITFF to the control
3865 * register. After the HBA resets, this function resets all the iocb ring
3866 * indices. This function disables PCI layer parity checking during
3868 * This function returns 0 always.
3869 * The caller is not required to hold any locks.
3872 lpfc_sli_brdreset(struct lpfc_hba *phba)
3874 struct lpfc_sli *psli;
3875 struct lpfc_sli_ring *pring;
3882 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3883 "0325 Reset HBA Data: x%x x%x\n",
3884 phba->pport->port_state, psli->sli_flag);
3886 /* perform board reset */
3887 phba->fc_eventTag = 0;
3888 phba->link_events = 0;
3889 phba->pport->fc_myDID = 0;
3890 phba->pport->fc_prevDID = 0;
3892 /* Turn off parity checking and serr during the physical reset */
3893 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3894 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3896 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3898 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
3900 /* Now toggle INITFF bit in the Host Control Register */
3901 writel(HC_INITFF, phba->HCregaddr);
3903 readl(phba->HCregaddr); /* flush */
3904 writel(0, phba->HCregaddr);
3905 readl(phba->HCregaddr); /* flush */
3907 /* Restore PCI cmd register */
3908 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3910 /* Initialize relevant SLI info */
3911 for (i = 0; i < psli->num_rings; i++) {
3912 pring = &psli->ring[i];
3914 pring->sli.sli3.rspidx = 0;
3915 pring->sli.sli3.next_cmdidx = 0;
3916 pring->sli.sli3.local_getidx = 0;
3917 pring->sli.sli3.cmdidx = 0;
3918 pring->missbufcnt = 0;
3921 phba->link_state = LPFC_WARM_START;
3926 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3927 * @phba: Pointer to HBA context object.
3929 * This function resets a SLI4 HBA. This function disables PCI layer parity
3930 * checking during resets the device. The caller is not required to hold
3933 * This function returns 0 always.
3936 lpfc_sli4_brdreset(struct lpfc_hba *phba)
3938 struct lpfc_sli *psli = &phba->sli;
3943 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3944 "0295 Reset HBA Data: x%x x%x\n",
3945 phba->pport->port_state, psli->sli_flag);
3947 /* perform board reset */
3948 phba->fc_eventTag = 0;
3949 phba->link_events = 0;
3950 phba->pport->fc_myDID = 0;
3951 phba->pport->fc_prevDID = 0;
3953 spin_lock_irq(&phba->hbalock);
3954 psli->sli_flag &= ~(LPFC_PROCESS_LA);
3955 phba->fcf.fcf_flag = 0;
3956 spin_unlock_irq(&phba->hbalock);
3958 /* Now physically reset the device */
3959 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3960 "0389 Performing PCI function reset!\n");
3962 /* Turn off parity checking and serr during the physical reset */
3963 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3964 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
3965 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3967 /* Perform FCoE PCI function reset */
3968 lpfc_sli4_queue_destroy(phba);
3969 rc = lpfc_pci_function_reset(phba);
3971 /* Restore PCI cmd register */
3972 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3978 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3979 * @phba: Pointer to HBA context object.
3981 * This function is called in the SLI initialization code path to
3982 * restart the HBA. The caller is not required to hold any lock.
3983 * This function writes MBX_RESTART mailbox command to the SLIM and
3984 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3985 * function to free any pending commands. The function enables
3986 * POST only during the first initialization. The function returns zero.
3987 * The function does not guarantee completion of MBX_RESTART mailbox
3988 * command before the return of this function.
3991 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
3994 struct lpfc_sli *psli;
3995 volatile uint32_t word0;
3996 void __iomem *to_slim;
3997 uint32_t hba_aer_enabled;
3999 spin_lock_irq(&phba->hbalock);
4001 /* Take PCIe device Advanced Error Reporting (AER) state */
4002 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4007 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4008 "0337 Restart HBA Data: x%x x%x\n",
4009 phba->pport->port_state, psli->sli_flag);
4012 mb = (MAILBOX_t *) &word0;
4013 mb->mbxCommand = MBX_RESTART;
4016 lpfc_reset_barrier(phba);
4018 to_slim = phba->MBslimaddr;
4019 writel(*(uint32_t *) mb, to_slim);
4020 readl(to_slim); /* flush */
4022 /* Only skip post after fc_ffinit is completed */
4023 if (phba->pport->port_state)
4024 word0 = 1; /* This is really setting up word1 */
4026 word0 = 0; /* This is really setting up word1 */
4027 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4028 writel(*(uint32_t *) mb, to_slim);
4029 readl(to_slim); /* flush */
4031 lpfc_sli_brdreset(phba);
4032 phba->pport->stopped = 0;
4033 phba->link_state = LPFC_INIT_START;
4035 spin_unlock_irq(&phba->hbalock);
4037 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4038 psli->stats_start = get_seconds();
4040 /* Give the INITFF and Post time to settle. */
4043 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4044 if (hba_aer_enabled)
4045 pci_disable_pcie_error_reporting(phba->pcidev);
4047 lpfc_hba_down_post(phba);
4053 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4054 * @phba: Pointer to HBA context object.
4056 * This function is called in the SLI initialization code path to restart
4057 * a SLI4 HBA. The caller is not required to hold any lock.
4058 * At the end of the function, it calls lpfc_hba_down_post function to
4059 * free any pending commands.
4062 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
4064 struct lpfc_sli *psli = &phba->sli;
4065 uint32_t hba_aer_enabled;
4069 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4070 "0296 Restart HBA Data: x%x x%x\n",
4071 phba->pport->port_state, psli->sli_flag);
4073 /* Take PCIe device Advanced Error Reporting (AER) state */
4074 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4076 rc = lpfc_sli4_brdreset(phba);
4078 spin_lock_irq(&phba->hbalock);
4079 phba->pport->stopped = 0;
4080 phba->link_state = LPFC_INIT_START;
4082 spin_unlock_irq(&phba->hbalock);
4084 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4085 psli->stats_start = get_seconds();
4087 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4088 if (hba_aer_enabled)
4089 pci_disable_pcie_error_reporting(phba->pcidev);
4091 lpfc_hba_down_post(phba);
4097 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4098 * @phba: Pointer to HBA context object.
4100 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4101 * API jump table function pointer from the lpfc_hba struct.
4104 lpfc_sli_brdrestart(struct lpfc_hba *phba)
4106 return phba->lpfc_sli_brdrestart(phba);
4110 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4111 * @phba: Pointer to HBA context object.
4113 * This function is called after a HBA restart to wait for successful
4114 * restart of the HBA. Successful restart of the HBA is indicated by
4115 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4116 * iteration, the function will restart the HBA again. The function returns
4117 * zero if HBA successfully restarted else returns negative error code.
4120 lpfc_sli_chipset_init(struct lpfc_hba *phba)
4122 uint32_t status, i = 0;
4124 /* Read the HBA Host Status Register */
4125 if (lpfc_readl(phba->HSregaddr, &status))
4128 /* Check status register to see what current state is */
4130 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4132 /* Check every 10ms for 10 retries, then every 100ms for 90
4133 * retries, then every 1 sec for 50 retires for a total of
4134 * ~60 seconds before reset the board again and check every
4135 * 1 sec for 50 retries. The up to 60 seconds before the
4136 * board ready is required by the Falcon FIPS zeroization
4137 * complete, and any reset the board in between shall cause
4138 * restart of zeroization, further delay the board ready.
4141 /* Adapter failed to init, timeout, status reg
4143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4144 "0436 Adapter failed to init, "
4145 "timeout, status reg x%x, "
4146 "FW Data: A8 x%x AC x%x\n", status,
4147 readl(phba->MBslimaddr + 0xa8),
4148 readl(phba->MBslimaddr + 0xac));
4149 phba->link_state = LPFC_HBA_ERROR;
4153 /* Check to see if any errors occurred during init */
4154 if (status & HS_FFERM) {
4155 /* ERROR: During chipset initialization */
4156 /* Adapter failed to init, chipset, status reg
4158 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4159 "0437 Adapter failed to init, "
4160 "chipset, status reg x%x, "
4161 "FW Data: A8 x%x AC x%x\n", status,
4162 readl(phba->MBslimaddr + 0xa8),
4163 readl(phba->MBslimaddr + 0xac));
4164 phba->link_state = LPFC_HBA_ERROR;
4177 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4178 lpfc_sli_brdrestart(phba);
4180 /* Read the HBA Host Status Register */
4181 if (lpfc_readl(phba->HSregaddr, &status))
4185 /* Check to see if any errors occurred during init */
4186 if (status & HS_FFERM) {
4187 /* ERROR: During chipset initialization */
4188 /* Adapter failed to init, chipset, status reg <status> */
4189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4190 "0438 Adapter failed to init, chipset, "
4192 "FW Data: A8 x%x AC x%x\n", status,
4193 readl(phba->MBslimaddr + 0xa8),
4194 readl(phba->MBslimaddr + 0xac));
4195 phba->link_state = LPFC_HBA_ERROR;
4199 /* Clear all interrupt enable conditions */
4200 writel(0, phba->HCregaddr);
4201 readl(phba->HCregaddr); /* flush */
4203 /* setup host attn register */
4204 writel(0xffffffff, phba->HAregaddr);
4205 readl(phba->HAregaddr); /* flush */
4210 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4212 * This function calculates and returns the number of HBQs required to be
4216 lpfc_sli_hbq_count(void)
4218 return ARRAY_SIZE(lpfc_hbq_defs);
4222 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4224 * This function adds the number of hbq entries in every HBQ to get
4225 * the total number of hbq entries required for the HBA and returns
4229 lpfc_sli_hbq_entry_count(void)
4231 int hbq_count = lpfc_sli_hbq_count();
4235 for (i = 0; i < hbq_count; ++i)
4236 count += lpfc_hbq_defs[i]->entry_count;
4241 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4243 * This function calculates amount of memory required for all hbq entries
4244 * to be configured and returns the total memory required.
4247 lpfc_sli_hbq_size(void)
4249 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
4253 * lpfc_sli_hbq_setup - configure and initialize HBQs
4254 * @phba: Pointer to HBA context object.
4256 * This function is called during the SLI initialization to configure
4257 * all the HBQs and post buffers to the HBQ. The caller is not
4258 * required to hold any locks. This function will return zero if successful
4259 * else it will return negative error code.
4262 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
4264 int hbq_count = lpfc_sli_hbq_count();
4268 uint32_t hbq_entry_index;
4270 /* Get a Mailbox buffer to setup mailbox
4271 * commands for HBA initialization
4273 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4280 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4281 phba->link_state = LPFC_INIT_MBX_CMDS;
4282 phba->hbq_in_use = 1;
4284 hbq_entry_index = 0;
4285 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
4286 phba->hbqs[hbqno].next_hbqPutIdx = 0;
4287 phba->hbqs[hbqno].hbqPutIdx = 0;
4288 phba->hbqs[hbqno].local_hbqGetIdx = 0;
4289 phba->hbqs[hbqno].entry_count =
4290 lpfc_hbq_defs[hbqno]->entry_count;
4291 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
4292 hbq_entry_index, pmb);
4293 hbq_entry_index += phba->hbqs[hbqno].entry_count;
4295 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
4296 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4297 mbxStatus <status>, ring <num> */
4299 lpfc_printf_log(phba, KERN_ERR,
4300 LOG_SLI | LOG_VPORT,
4301 "1805 Adapter failed to init. "
4302 "Data: x%x x%x x%x\n",
4304 pmbox->mbxStatus, hbqno);
4306 phba->link_state = LPFC_HBA_ERROR;
4307 mempool_free(pmb, phba->mbox_mem_pool);
4311 phba->hbq_count = hbq_count;
4313 mempool_free(pmb, phba->mbox_mem_pool);
4315 /* Initially populate or replenish the HBQs */
4316 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
4317 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
4322 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4323 * @phba: Pointer to HBA context object.
4325 * This function is called during the SLI initialization to configure
4326 * all the HBQs and post buffers to the HBQ. The caller is not
4327 * required to hold any locks. This function will return zero if successful
4328 * else it will return negative error code.
4331 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
4333 phba->hbq_in_use = 1;
4334 phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
4335 phba->hbq_count = 1;
4336 /* Initially populate or replenish the HBQs */
4337 lpfc_sli_hbqbuf_init_hbqs(phba, 0);
4342 * lpfc_sli_config_port - Issue config port mailbox command
4343 * @phba: Pointer to HBA context object.
4344 * @sli_mode: sli mode - 2/3
4346 * This function is called by the sli intialization code path
4347 * to issue config_port mailbox command. This function restarts the
4348 * HBA firmware and issues a config_port mailbox command to configure
4349 * the SLI interface in the sli mode specified by sli_mode
4350 * variable. The caller is not required to hold any locks.
4351 * The function returns 0 if successful, else returns negative error
4355 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
4358 uint32_t resetcount = 0, rc = 0, done = 0;
4360 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4362 phba->link_state = LPFC_HBA_ERROR;
4366 phba->sli_rev = sli_mode;
4367 while (resetcount < 2 && !done) {
4368 spin_lock_irq(&phba->hbalock);
4369 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4370 spin_unlock_irq(&phba->hbalock);
4371 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4372 lpfc_sli_brdrestart(phba);
4373 rc = lpfc_sli_chipset_init(phba);
4377 spin_lock_irq(&phba->hbalock);
4378 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4379 spin_unlock_irq(&phba->hbalock);
4382 /* Call pre CONFIG_PORT mailbox command initialization. A
4383 * value of 0 means the call was successful. Any other
4384 * nonzero value is a failure, but if ERESTART is returned,
4385 * the driver may reset the HBA and try again.
4387 rc = lpfc_config_port_prep(phba);
4388 if (rc == -ERESTART) {
4389 phba->link_state = LPFC_LINK_UNKNOWN;
4394 phba->link_state = LPFC_INIT_MBX_CMDS;
4395 lpfc_config_port(phba, pmb);
4396 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4397 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
4398 LPFC_SLI3_HBQ_ENABLED |
4399 LPFC_SLI3_CRP_ENABLED |
4400 LPFC_SLI3_BG_ENABLED |
4401 LPFC_SLI3_DSS_ENABLED);
4402 if (rc != MBX_SUCCESS) {
4403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4404 "0442 Adapter failed to init, mbxCmd x%x "
4405 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4406 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
4407 spin_lock_irq(&phba->hbalock);
4408 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
4409 spin_unlock_irq(&phba->hbalock);
4412 /* Allow asynchronous mailbox command to go through */
4413 spin_lock_irq(&phba->hbalock);
4414 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4415 spin_unlock_irq(&phba->hbalock);
4418 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
4419 (pmb->u.mb.un.varCfgPort.gasabt == 0))
4420 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4421 "3110 Port did not grant ASABT\n");
4426 goto do_prep_failed;
4428 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
4429 if (!pmb->u.mb.un.varCfgPort.cMA) {
4431 goto do_prep_failed;
4433 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
4434 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
4435 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
4436 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
4437 phba->max_vpi : phba->max_vports;
4441 phba->fips_level = 0;
4442 phba->fips_spec_rev = 0;
4443 if (pmb->u.mb.un.varCfgPort.gdss) {
4444 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
4445 phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
4446 phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
4447 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4448 "2850 Security Crypto Active. FIPS x%d "
4450 phba->fips_level, phba->fips_spec_rev);
4452 if (pmb->u.mb.un.varCfgPort.sec_err) {
4453 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4454 "2856 Config Port Security Crypto "
4456 pmb->u.mb.un.varCfgPort.sec_err);
4458 if (pmb->u.mb.un.varCfgPort.gerbm)
4459 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
4460 if (pmb->u.mb.un.varCfgPort.gcrp)
4461 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
4463 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
4464 phba->port_gp = phba->mbox->us.s3_pgp.port;
4466 if (phba->cfg_enable_bg) {
4467 if (pmb->u.mb.un.varCfgPort.gbg)
4468 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
4470 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4471 "0443 Adapter did not grant "
4475 phba->hbq_get = NULL;
4476 phba->port_gp = phba->mbox->us.s2.port;
4480 mempool_free(pmb, phba->mbox_mem_pool);
4486 * lpfc_sli_hba_setup - SLI intialization function
4487 * @phba: Pointer to HBA context object.
4489 * This function is the main SLI intialization function. This function
4490 * is called by the HBA intialization code, HBA reset code and HBA
4491 * error attention handler code. Caller is not required to hold any
4492 * locks. This function issues config_port mailbox command to configure
4493 * the SLI, setup iocb rings and HBQ rings. In the end the function
4494 * calls the config_port_post function to issue init_link mailbox
4495 * command and to start the discovery. The function will return zero
4496 * if successful, else it will return negative error code.
4499 lpfc_sli_hba_setup(struct lpfc_hba *phba)
4505 switch (lpfc_sli_mode) {
4507 if (phba->cfg_enable_npiv) {
4508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4509 "1824 NPIV enabled: Override lpfc_sli_mode "
4510 "parameter (%d) to auto (0).\n",
4520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4521 "1819 Unrecognized lpfc_sli_mode "
4522 "parameter: %d.\n", lpfc_sli_mode);
4527 rc = lpfc_sli_config_port(phba, mode);
4529 if (rc && lpfc_sli_mode == 3)
4530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4531 "1820 Unable to select SLI-3. "
4532 "Not supported by adapter.\n");
4533 if (rc && mode != 2)
4534 rc = lpfc_sli_config_port(phba, 2);
4536 goto lpfc_sli_hba_setup_error;
4538 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4539 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
4540 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4542 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4543 "2709 This device supports "
4544 "Advanced Error Reporting (AER)\n");
4545 spin_lock_irq(&phba->hbalock);
4546 phba->hba_flag |= HBA_AER_ENABLED;
4547 spin_unlock_irq(&phba->hbalock);
4549 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4550 "2708 This device does not support "
4551 "Advanced Error Reporting (AER)\n");
4552 phba->cfg_aer_support = 0;
4556 if (phba->sli_rev == 3) {
4557 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4558 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
4560 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4561 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
4562 phba->sli3_options = 0;
4565 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4566 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4567 phba->sli_rev, phba->max_vpi);
4568 rc = lpfc_sli_ring_map(phba);
4571 goto lpfc_sli_hba_setup_error;
4573 /* Initialize VPIs. */
4574 if (phba->sli_rev == LPFC_SLI_REV3) {
4576 * The VPI bitmask and physical ID array are allocated
4577 * and initialized once only - at driver load. A port
4578 * reset doesn't need to reinitialize this memory.
4580 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
4581 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
4582 phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
4584 if (!phba->vpi_bmask) {
4586 goto lpfc_sli_hba_setup_error;
4589 phba->vpi_ids = kzalloc(
4590 (phba->max_vpi+1) * sizeof(uint16_t),
4592 if (!phba->vpi_ids) {
4593 kfree(phba->vpi_bmask);
4595 goto lpfc_sli_hba_setup_error;
4597 for (i = 0; i < phba->max_vpi; i++)
4598 phba->vpi_ids[i] = i;
4603 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4604 rc = lpfc_sli_hbq_setup(phba);
4606 goto lpfc_sli_hba_setup_error;
4608 spin_lock_irq(&phba->hbalock);
4609 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4610 spin_unlock_irq(&phba->hbalock);
4612 rc = lpfc_config_port_post(phba);
4614 goto lpfc_sli_hba_setup_error;
4618 lpfc_sli_hba_setup_error:
4619 phba->link_state = LPFC_HBA_ERROR;
4620 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4621 "0445 Firmware initialization failed\n");
4626 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4627 * @phba: Pointer to HBA context object.
4628 * @mboxq: mailbox pointer.
4629 * This function issue a dump mailbox command to read config region
4630 * 23 and parse the records in the region and populate driver
4634 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
4636 LPFC_MBOXQ_t *mboxq;
4637 struct lpfc_dmabuf *mp;
4638 struct lpfc_mqe *mqe;
4639 uint32_t data_length;
4642 /* Program the default value of vlan_id and fc_map */
4643 phba->valid_vlan = 0;
4644 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4645 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4646 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4648 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4652 mqe = &mboxq->u.mqe;
4653 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
4655 goto out_free_mboxq;
4658 mp = (struct lpfc_dmabuf *) mboxq->context1;
4659 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4661 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4662 "(%d):2571 Mailbox cmd x%x Status x%x "
4663 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4664 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4665 "CQ: x%x x%x x%x x%x\n",
4666 mboxq->vport ? mboxq->vport->vpi : 0,
4667 bf_get(lpfc_mqe_command, mqe),
4668 bf_get(lpfc_mqe_status, mqe),
4669 mqe->un.mb_words[0], mqe->un.mb_words[1],
4670 mqe->un.mb_words[2], mqe->un.mb_words[3],
4671 mqe->un.mb_words[4], mqe->un.mb_words[5],
4672 mqe->un.mb_words[6], mqe->un.mb_words[7],
4673 mqe->un.mb_words[8], mqe->un.mb_words[9],
4674 mqe->un.mb_words[10], mqe->un.mb_words[11],
4675 mqe->un.mb_words[12], mqe->un.mb_words[13],
4676 mqe->un.mb_words[14], mqe->un.mb_words[15],
4677 mqe->un.mb_words[16], mqe->un.mb_words[50],
4679 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4680 mboxq->mcqe.trailer);
4683 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4686 goto out_free_mboxq;
4688 data_length = mqe->un.mb_words[5];
4689 if (data_length > DMP_RGN23_SIZE) {
4690 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4693 goto out_free_mboxq;
4696 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
4697 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4702 mempool_free(mboxq, phba->mbox_mem_pool);
4707 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4708 * @phba: pointer to lpfc hba data structure.
4709 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4710 * @vpd: pointer to the memory to hold resulting port vpd data.
4711 * @vpd_size: On input, the number of bytes allocated to @vpd.
4712 * On output, the number of data bytes in @vpd.
4714 * This routine executes a READ_REV SLI4 mailbox command. In
4715 * addition, this routine gets the port vpd data.
4719 * -ENOMEM - could not allocated memory.
4722 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4723 uint8_t *vpd, uint32_t *vpd_size)
4727 struct lpfc_dmabuf *dmabuf;
4728 struct lpfc_mqe *mqe;
4730 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4735 * Get a DMA buffer for the vpd data resulting from the READ_REV
4738 dma_size = *vpd_size;
4739 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4743 if (!dmabuf->virt) {
4747 memset(dmabuf->virt, 0, dma_size);
4750 * The SLI4 implementation of READ_REV conflicts at word1,
4751 * bits 31:16 and SLI4 adds vpd functionality not present
4752 * in SLI3. This code corrects the conflicts.
4754 lpfc_read_rev(phba, mboxq);
4755 mqe = &mboxq->u.mqe;
4756 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
4757 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
4758 mqe->un.read_rev.word1 &= 0x0000FFFF;
4759 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
4760 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
4762 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4764 dma_free_coherent(&phba->pcidev->dev, dma_size,
4765 dmabuf->virt, dmabuf->phys);
4771 * The available vpd length cannot be bigger than the
4772 * DMA buffer passed to the port. Catch the less than
4773 * case and update the caller's size.
4775 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
4776 *vpd_size = mqe->un.read_rev.avail_vpd_len;
4778 memcpy(vpd, dmabuf->virt, *vpd_size);
4780 dma_free_coherent(&phba->pcidev->dev, dma_size,
4781 dmabuf->virt, dmabuf->phys);
4787 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4788 * @phba: pointer to lpfc hba data structure.
4790 * This routine retrieves SLI4 device physical port name this PCI function
4795 * otherwise - failed to retrieve physical port name
4798 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
4800 LPFC_MBOXQ_t *mboxq;
4801 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
4802 struct lpfc_controller_attribute *cntl_attr;
4803 struct lpfc_mbx_get_port_name *get_port_name;
4804 void *virtaddr = NULL;
4805 uint32_t alloclen, reqlen;
4806 uint32_t shdr_status, shdr_add_status;
4807 union lpfc_sli4_cfg_shdr *shdr;
4808 char cport_name = 0;
4811 /* We assume nothing at this point */
4812 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
4813 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
4815 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4818 /* obtain link type and link number via READ_CONFIG */
4819 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
4820 lpfc_sli4_read_config(phba);
4821 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
4822 goto retrieve_ppname;
4824 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4825 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
4826 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
4827 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
4828 LPFC_SLI4_MBX_NEMBED);
4829 if (alloclen < reqlen) {
4830 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4831 "3084 Allocated DMA memory size (%d) is "
4832 "less than the requested DMA memory size "
4833 "(%d)\n", alloclen, reqlen);
4835 goto out_free_mboxq;
4837 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4838 virtaddr = mboxq->sge_array->addr[0];
4839 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
4840 shdr = &mbx_cntl_attr->cfg_shdr;
4841 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
4842 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
4843 if (shdr_status || shdr_add_status || rc) {
4844 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4845 "3085 Mailbox x%x (x%x/x%x) failed, "
4846 "rc:x%x, status:x%x, add_status:x%x\n",
4847 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4848 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
4849 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
4850 rc, shdr_status, shdr_add_status);
4852 goto out_free_mboxq;
4854 cntl_attr = &mbx_cntl_attr->cntl_attr;
4855 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
4856 phba->sli4_hba.lnk_info.lnk_tp =
4857 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
4858 phba->sli4_hba.lnk_info.lnk_no =
4859 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
4860 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4861 "3086 lnk_type:%d, lnk_numb:%d\n",
4862 phba->sli4_hba.lnk_info.lnk_tp,
4863 phba->sli4_hba.lnk_info.lnk_no);
4866 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
4867 LPFC_MBOX_OPCODE_GET_PORT_NAME,
4868 sizeof(struct lpfc_mbx_get_port_name) -
4869 sizeof(struct lpfc_sli4_cfg_mhdr),
4870 LPFC_SLI4_MBX_EMBED);
4871 get_port_name = &mboxq->u.mqe.un.get_port_name;
4872 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
4873 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
4874 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
4875 phba->sli4_hba.lnk_info.lnk_tp);
4876 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4877 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
4878 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
4879 if (shdr_status || shdr_add_status || rc) {
4880 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4881 "3087 Mailbox x%x (x%x/x%x) failed: "
4882 "rc:x%x, status:x%x, add_status:x%x\n",
4883 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4884 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
4885 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
4886 rc, shdr_status, shdr_add_status);
4888 goto out_free_mboxq;
4890 switch (phba->sli4_hba.lnk_info.lnk_no) {
4891 case LPFC_LINK_NUMBER_0:
4892 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
4893 &get_port_name->u.response);
4894 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4896 case LPFC_LINK_NUMBER_1:
4897 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
4898 &get_port_name->u.response);
4899 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4901 case LPFC_LINK_NUMBER_2:
4902 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
4903 &get_port_name->u.response);
4904 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4906 case LPFC_LINK_NUMBER_3:
4907 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
4908 &get_port_name->u.response);
4909 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4915 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
4916 phba->Port[0] = cport_name;
4917 phba->Port[1] = '\0';
4918 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4919 "3091 SLI get port name: %s\n", phba->Port);
4923 if (rc != MBX_TIMEOUT) {
4924 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
4925 lpfc_sli4_mbox_cmd_free(phba, mboxq);
4927 mempool_free(mboxq, phba->mbox_mem_pool);
4933 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4934 * @phba: pointer to lpfc hba data structure.
4936 * This routine is called to explicitly arm the SLI4 device's completion and
4940 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
4944 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
4945 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
4947 if (phba->sli4_hba.fcp_cq) {
4949 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
4951 } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
4953 if (phba->sli4_hba.hba_eq) {
4954 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
4956 lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
4962 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4963 * @phba: Pointer to HBA context object.
4964 * @type: The resource extent type.
4965 * @extnt_count: buffer to hold port available extent count.
4966 * @extnt_size: buffer to hold element count per extent.
4968 * This function calls the port and retrievs the number of available
4969 * extents and their size for a particular extent type.
4971 * Returns: 0 if successful. Nonzero otherwise.
4974 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
4975 uint16_t *extnt_count, uint16_t *extnt_size)
4980 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
4983 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4987 /* Find out how many extents are available for this resource type */
4988 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
4989 sizeof(struct lpfc_sli4_cfg_mhdr));
4990 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
4991 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
4992 length, LPFC_SLI4_MBX_EMBED);
4994 /* Send an extents count of 0 - the GET doesn't use it. */
4995 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
4996 LPFC_SLI4_MBX_EMBED);
5002 if (!phba->sli4_hba.intr_enable)
5003 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5005 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5006 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5013 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
5014 if (bf_get(lpfc_mbox_hdr_status,
5015 &rsrc_info->header.cfg_shdr.response)) {
5016 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5017 "2930 Failed to get resource extents "
5018 "Status 0x%x Add'l Status 0x%x\n",
5019 bf_get(lpfc_mbox_hdr_status,
5020 &rsrc_info->header.cfg_shdr.response),
5021 bf_get(lpfc_mbox_hdr_add_status,
5022 &rsrc_info->header.cfg_shdr.response));
5027 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
5029 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
5032 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5033 "3162 Retrieved extents type-%d from port: count:%d, "
5034 "size:%d\n", type, *extnt_count, *extnt_size);
5037 mempool_free(mbox, phba->mbox_mem_pool);
5042 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5043 * @phba: Pointer to HBA context object.
5044 * @type: The extent type to check.
5046 * This function reads the current available extents from the port and checks
5047 * if the extent count or extent size has changed since the last access.
5048 * Callers use this routine post port reset to understand if there is a
5049 * extent reprovisioning requirement.
5052 * -Error: error indicates problem.
5053 * 1: Extent count or size has changed.
5057 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
5059 uint16_t curr_ext_cnt, rsrc_ext_cnt;
5060 uint16_t size_diff, rsrc_ext_size;
5062 struct lpfc_rsrc_blks *rsrc_entry;
5063 struct list_head *rsrc_blk_list = NULL;
5067 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5074 case LPFC_RSC_TYPE_FCOE_RPI:
5075 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5077 case LPFC_RSC_TYPE_FCOE_VPI:
5078 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
5080 case LPFC_RSC_TYPE_FCOE_XRI:
5081 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5083 case LPFC_RSC_TYPE_FCOE_VFI:
5084 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5090 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
5092 if (rsrc_entry->rsrc_size != rsrc_ext_size)
5096 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
5103 * lpfc_sli4_cfg_post_extnts -
5104 * @phba: Pointer to HBA context object.
5105 * @extnt_cnt - number of available extents.
5106 * @type - the extent type (rpi, xri, vfi, vpi).
5107 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5108 * @mbox - pointer to the caller's allocated mailbox structure.
5110 * This function executes the extents allocation request. It also
5111 * takes care of the amount of memory needed to allocate or get the
5112 * allocated extents. It is the caller's responsibility to evaluate
5116 * -Error: Error value describes the condition found.
5120 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
5121 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
5126 uint32_t alloc_len, mbox_tmo;
5128 /* Calculate the total requested length of the dma memory */
5129 req_len = extnt_cnt * sizeof(uint16_t);
5132 * Calculate the size of an embedded mailbox. The uint32_t
5133 * accounts for extents-specific word.
5135 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5139 * Presume the allocation and response will fit into an embedded
5140 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5142 *emb = LPFC_SLI4_MBX_EMBED;
5143 if (req_len > emb_len) {
5144 req_len = extnt_cnt * sizeof(uint16_t) +
5145 sizeof(union lpfc_sli4_cfg_shdr) +
5147 *emb = LPFC_SLI4_MBX_NEMBED;
5150 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5151 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
5153 if (alloc_len < req_len) {
5154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5155 "2982 Allocated DMA memory size (x%x) is "
5156 "less than the requested DMA memory "
5157 "size (x%x)\n", alloc_len, req_len);
5160 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
5164 if (!phba->sli4_hba.intr_enable)
5165 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5167 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5168 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5177 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5178 * @phba: Pointer to HBA context object.
5179 * @type: The resource extent type to allocate.
5181 * This function allocates the number of elements for the specified
5185 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
5188 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
5189 uint16_t rsrc_id, rsrc_start, j, k;
5192 unsigned long longs;
5193 unsigned long *bmask;
5194 struct lpfc_rsrc_blks *rsrc_blks;
5197 struct lpfc_id_range *id_array = NULL;
5198 void *virtaddr = NULL;
5199 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5200 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5201 struct list_head *ext_blk_list;
5203 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5209 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
5210 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5211 "3009 No available Resource Extents "
5212 "for resource type 0x%x: Count: 0x%x, "
5213 "Size 0x%x\n", type, rsrc_cnt,
5218 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
5219 "2903 Post resource extents type-0x%x: "
5220 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
5222 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5226 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
5233 * Figure out where the response is located. Then get local pointers
5234 * to the response data. The port does not guarantee to respond to
5235 * all extents counts request so update the local variable with the
5236 * allocated count from the port.
5238 if (emb == LPFC_SLI4_MBX_EMBED) {
5239 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
5240 id_array = &rsrc_ext->u.rsp.id[0];
5241 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
5243 virtaddr = mbox->sge_array->addr[0];
5244 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
5245 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
5246 id_array = &n_rsrc->id;
5249 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
5250 rsrc_id_cnt = rsrc_cnt * rsrc_size;
5253 * Based on the resource size and count, correct the base and max
5256 length = sizeof(struct lpfc_rsrc_blks);
5258 case LPFC_RSC_TYPE_FCOE_RPI:
5259 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5260 sizeof(unsigned long),
5262 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5266 phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
5269 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5270 kfree(phba->sli4_hba.rpi_bmask);
5276 * The next_rpi was initialized with the maximum available
5277 * count but the port may allocate a smaller number. Catch
5278 * that case and update the next_rpi.
5280 phba->sli4_hba.next_rpi = rsrc_id_cnt;
5282 /* Initialize local ptrs for common extent processing later. */
5283 bmask = phba->sli4_hba.rpi_bmask;
5284 ids = phba->sli4_hba.rpi_ids;
5285 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5287 case LPFC_RSC_TYPE_FCOE_VPI:
5288 phba->vpi_bmask = kzalloc(longs *
5289 sizeof(unsigned long),
5291 if (unlikely(!phba->vpi_bmask)) {
5295 phba->vpi_ids = kzalloc(rsrc_id_cnt *
5298 if (unlikely(!phba->vpi_ids)) {
5299 kfree(phba->vpi_bmask);
5304 /* Initialize local ptrs for common extent processing later. */
5305 bmask = phba->vpi_bmask;
5306 ids = phba->vpi_ids;
5307 ext_blk_list = &phba->lpfc_vpi_blk_list;
5309 case LPFC_RSC_TYPE_FCOE_XRI:
5310 phba->sli4_hba.xri_bmask = kzalloc(longs *
5311 sizeof(unsigned long),
5313 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5317 phba->sli4_hba.max_cfg_param.xri_used = 0;
5318 phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
5321 if (unlikely(!phba->sli4_hba.xri_ids)) {
5322 kfree(phba->sli4_hba.xri_bmask);
5327 /* Initialize local ptrs for common extent processing later. */
5328 bmask = phba->sli4_hba.xri_bmask;
5329 ids = phba->sli4_hba.xri_ids;
5330 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5332 case LPFC_RSC_TYPE_FCOE_VFI:
5333 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5334 sizeof(unsigned long),
5336 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5340 phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
5343 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5344 kfree(phba->sli4_hba.vfi_bmask);
5349 /* Initialize local ptrs for common extent processing later. */
5350 bmask = phba->sli4_hba.vfi_bmask;
5351 ids = phba->sli4_hba.vfi_ids;
5352 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5355 /* Unsupported Opcode. Fail call. */
5359 ext_blk_list = NULL;
5364 * Complete initializing the extent configuration with the
5365 * allocated ids assigned to this function. The bitmask serves
5366 * as an index into the array and manages the available ids. The
5367 * array just stores the ids communicated to the port via the wqes.
5369 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
5371 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
5374 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
5377 rsrc_blks = kzalloc(length, GFP_KERNEL);
5378 if (unlikely(!rsrc_blks)) {
5384 rsrc_blks->rsrc_start = rsrc_id;
5385 rsrc_blks->rsrc_size = rsrc_size;
5386 list_add_tail(&rsrc_blks->list, ext_blk_list);
5387 rsrc_start = rsrc_id;
5388 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
5389 phba->sli4_hba.scsi_xri_start = rsrc_start +
5390 lpfc_sli4_get_els_iocb_cnt(phba);
5392 while (rsrc_id < (rsrc_start + rsrc_size)) {
5397 /* Entire word processed. Get next word.*/
5402 lpfc_sli4_mbox_cmd_free(phba, mbox);
5407 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5408 * @phba: Pointer to HBA context object.
5409 * @type: the extent's type.
5411 * This function deallocates all extents of a particular resource type.
5412 * SLI4 does not allow for deallocating a particular extent range. It
5413 * is the caller's responsibility to release all kernel memory resources.
5416 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
5419 uint32_t length, mbox_tmo = 0;
5421 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
5422 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
5424 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5429 * This function sends an embedded mailbox because it only sends the
5430 * the resource type. All extents of this type are released by the
5433 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
5434 sizeof(struct lpfc_sli4_cfg_mhdr));
5435 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5436 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
5437 length, LPFC_SLI4_MBX_EMBED);
5439 /* Send an extents count of 0 - the dealloc doesn't use it. */
5440 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5441 LPFC_SLI4_MBX_EMBED);
5446 if (!phba->sli4_hba.intr_enable)
5447 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5449 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5450 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5457 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
5458 if (bf_get(lpfc_mbox_hdr_status,
5459 &dealloc_rsrc->header.cfg_shdr.response)) {
5460 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5461 "2919 Failed to release resource extents "
5462 "for type %d - Status 0x%x Add'l Status 0x%x. "
5463 "Resource memory not released.\n",
5465 bf_get(lpfc_mbox_hdr_status,
5466 &dealloc_rsrc->header.cfg_shdr.response),
5467 bf_get(lpfc_mbox_hdr_add_status,
5468 &dealloc_rsrc->header.cfg_shdr.response));
5473 /* Release kernel memory resources for the specific type. */
5475 case LPFC_RSC_TYPE_FCOE_VPI:
5476 kfree(phba->vpi_bmask);
5477 kfree(phba->vpi_ids);
5478 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5479 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5480 &phba->lpfc_vpi_blk_list, list) {
5481 list_del_init(&rsrc_blk->list);
5485 case LPFC_RSC_TYPE_FCOE_XRI:
5486 kfree(phba->sli4_hba.xri_bmask);
5487 kfree(phba->sli4_hba.xri_ids);
5488 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5489 &phba->sli4_hba.lpfc_xri_blk_list, list) {
5490 list_del_init(&rsrc_blk->list);
5494 case LPFC_RSC_TYPE_FCOE_VFI:
5495 kfree(phba->sli4_hba.vfi_bmask);
5496 kfree(phba->sli4_hba.vfi_ids);
5497 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5498 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5499 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
5500 list_del_init(&rsrc_blk->list);
5504 case LPFC_RSC_TYPE_FCOE_RPI:
5505 /* RPI bitmask and physical id array are cleaned up earlier. */
5506 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5507 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
5508 list_del_init(&rsrc_blk->list);
5516 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5519 mempool_free(mbox, phba->mbox_mem_pool);
5524 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5525 * @phba: Pointer to HBA context object.
5527 * This function allocates all SLI4 resource identifiers.
5530 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
5532 int i, rc, error = 0;
5533 uint16_t count, base;
5534 unsigned long longs;
5536 if (!phba->sli4_hba.rpi_hdrs_in_use)
5537 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
5538 if (phba->sli4_hba.extents_in_use) {
5540 * The port supports resource extents. The XRI, VPI, VFI, RPI
5541 * resource extent count must be read and allocated before
5542 * provisioning the resource id arrays.
5544 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5545 LPFC_IDX_RSRC_RDY) {
5547 * Extent-based resources are set - the driver could
5548 * be in a port reset. Figure out if any corrective
5549 * actions need to be taken.
5551 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5552 LPFC_RSC_TYPE_FCOE_VFI);
5555 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5556 LPFC_RSC_TYPE_FCOE_VPI);
5559 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5560 LPFC_RSC_TYPE_FCOE_XRI);
5563 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5564 LPFC_RSC_TYPE_FCOE_RPI);
5569 * It's possible that the number of resources
5570 * provided to this port instance changed between
5571 * resets. Detect this condition and reallocate
5572 * resources. Otherwise, there is no action.
5575 lpfc_printf_log(phba, KERN_INFO,
5576 LOG_MBOX | LOG_INIT,
5577 "2931 Detected extent resource "
5578 "change. Reallocating all "
5580 rc = lpfc_sli4_dealloc_extent(phba,
5581 LPFC_RSC_TYPE_FCOE_VFI);
5582 rc = lpfc_sli4_dealloc_extent(phba,
5583 LPFC_RSC_TYPE_FCOE_VPI);
5584 rc = lpfc_sli4_dealloc_extent(phba,
5585 LPFC_RSC_TYPE_FCOE_XRI);
5586 rc = lpfc_sli4_dealloc_extent(phba,
5587 LPFC_RSC_TYPE_FCOE_RPI);
5592 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5596 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5600 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5604 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5607 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5612 * The port does not support resource extents. The XRI, VPI,
5613 * VFI, RPI resource ids were determined from READ_CONFIG.
5614 * Just allocate the bitmasks and provision the resource id
5615 * arrays. If a port reset is active, the resources don't
5616 * need any action - just exit.
5618 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5619 LPFC_IDX_RSRC_RDY) {
5620 lpfc_sli4_dealloc_resource_identifiers(phba);
5621 lpfc_sli4_remove_rpis(phba);
5624 count = phba->sli4_hba.max_cfg_param.max_rpi;
5625 base = phba->sli4_hba.max_cfg_param.rpi_base;
5626 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5627 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5628 sizeof(unsigned long),
5630 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5634 phba->sli4_hba.rpi_ids = kzalloc(count *
5637 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5639 goto free_rpi_bmask;
5642 for (i = 0; i < count; i++)
5643 phba->sli4_hba.rpi_ids[i] = base + i;
5646 count = phba->sli4_hba.max_cfg_param.max_vpi;
5647 base = phba->sli4_hba.max_cfg_param.vpi_base;
5648 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5649 phba->vpi_bmask = kzalloc(longs *
5650 sizeof(unsigned long),
5652 if (unlikely(!phba->vpi_bmask)) {
5656 phba->vpi_ids = kzalloc(count *
5659 if (unlikely(!phba->vpi_ids)) {
5661 goto free_vpi_bmask;
5664 for (i = 0; i < count; i++)
5665 phba->vpi_ids[i] = base + i;
5668 count = phba->sli4_hba.max_cfg_param.max_xri;
5669 base = phba->sli4_hba.max_cfg_param.xri_base;
5670 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5671 phba->sli4_hba.xri_bmask = kzalloc(longs *
5672 sizeof(unsigned long),
5674 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5678 phba->sli4_hba.max_cfg_param.xri_used = 0;
5679 phba->sli4_hba.xri_ids = kzalloc(count *
5682 if (unlikely(!phba->sli4_hba.xri_ids)) {
5684 goto free_xri_bmask;
5687 for (i = 0; i < count; i++)
5688 phba->sli4_hba.xri_ids[i] = base + i;
5691 count = phba->sli4_hba.max_cfg_param.max_vfi;
5692 base = phba->sli4_hba.max_cfg_param.vfi_base;
5693 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5694 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5695 sizeof(unsigned long),
5697 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5701 phba->sli4_hba.vfi_ids = kzalloc(count *
5704 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5706 goto free_vfi_bmask;
5709 for (i = 0; i < count; i++)
5710 phba->sli4_hba.vfi_ids[i] = base + i;
5713 * Mark all resources ready. An HBA reset doesn't need
5714 * to reset the initialization.
5716 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5722 kfree(phba->sli4_hba.vfi_bmask);
5724 kfree(phba->sli4_hba.xri_ids);
5726 kfree(phba->sli4_hba.xri_bmask);
5728 kfree(phba->vpi_ids);
5730 kfree(phba->vpi_bmask);
5732 kfree(phba->sli4_hba.rpi_ids);
5734 kfree(phba->sli4_hba.rpi_bmask);
5740 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5741 * @phba: Pointer to HBA context object.
5743 * This function allocates the number of elements for the specified
5747 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
5749 if (phba->sli4_hba.extents_in_use) {
5750 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5751 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5752 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5753 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5755 kfree(phba->vpi_bmask);
5756 kfree(phba->vpi_ids);
5757 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5758 kfree(phba->sli4_hba.xri_bmask);
5759 kfree(phba->sli4_hba.xri_ids);
5760 kfree(phba->sli4_hba.vfi_bmask);
5761 kfree(phba->sli4_hba.vfi_ids);
5762 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5763 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5770 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5771 * @phba: Pointer to HBA context object.
5772 * @type: The resource extent type.
5773 * @extnt_count: buffer to hold port extent count response
5774 * @extnt_size: buffer to hold port extent size response.
5776 * This function calls the port to read the host allocated extents
5777 * for a particular type.
5780 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
5781 uint16_t *extnt_cnt, uint16_t *extnt_size)
5785 uint16_t curr_blks = 0;
5786 uint32_t req_len, emb_len;
5787 uint32_t alloc_len, mbox_tmo;
5788 struct list_head *blk_list_head;
5789 struct lpfc_rsrc_blks *rsrc_blk;
5791 void *virtaddr = NULL;
5792 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5793 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5794 union lpfc_sli4_cfg_shdr *shdr;
5797 case LPFC_RSC_TYPE_FCOE_VPI:
5798 blk_list_head = &phba->lpfc_vpi_blk_list;
5800 case LPFC_RSC_TYPE_FCOE_XRI:
5801 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
5803 case LPFC_RSC_TYPE_FCOE_VFI:
5804 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
5806 case LPFC_RSC_TYPE_FCOE_RPI:
5807 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
5813 /* Count the number of extents currently allocatd for this type. */
5814 list_for_each_entry(rsrc_blk, blk_list_head, list) {
5815 if (curr_blks == 0) {
5817 * The GET_ALLOCATED mailbox does not return the size,
5818 * just the count. The size should be just the size
5819 * stored in the current allocated block and all sizes
5820 * for an extent type are the same so set the return
5823 *extnt_size = rsrc_blk->rsrc_size;
5828 /* Calculate the total requested length of the dma memory. */
5829 req_len = curr_blks * sizeof(uint16_t);
5832 * Calculate the size of an embedded mailbox. The uint32_t
5833 * accounts for extents-specific word.
5835 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5839 * Presume the allocation and response will fit into an embedded
5840 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5842 emb = LPFC_SLI4_MBX_EMBED;
5844 if (req_len > emb_len) {
5845 req_len = curr_blks * sizeof(uint16_t) +
5846 sizeof(union lpfc_sli4_cfg_shdr) +
5848 emb = LPFC_SLI4_MBX_NEMBED;
5851 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5854 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
5856 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5857 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
5859 if (alloc_len < req_len) {
5860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5861 "2983 Allocated DMA memory size (x%x) is "
5862 "less than the requested DMA memory "
5863 "size (x%x)\n", alloc_len, req_len);
5867 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
5873 if (!phba->sli4_hba.intr_enable)
5874 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5876 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5877 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5886 * Figure out where the response is located. Then get local pointers
5887 * to the response data. The port does not guarantee to respond to
5888 * all extents counts request so update the local variable with the
5889 * allocated count from the port.
5891 if (emb == LPFC_SLI4_MBX_EMBED) {
5892 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
5893 shdr = &rsrc_ext->header.cfg_shdr;
5894 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
5896 virtaddr = mbox->sge_array->addr[0];
5897 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
5898 shdr = &n_rsrc->cfg_shdr;
5899 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
5902 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
5903 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5904 "2984 Failed to read allocated resources "
5905 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5907 bf_get(lpfc_mbox_hdr_status, &shdr->response),
5908 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
5913 lpfc_sli4_mbox_cmd_free(phba, mbox);
5918 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
5919 * @phba: pointer to lpfc hba data structure.
5921 * This routine walks the list of els buffers that have been allocated and
5922 * repost them to the port by using SGL block post. This is needed after a
5923 * pci_function_reset/warm_start or start. It attempts to construct blocks
5924 * of els buffer sgls which contains contiguous xris and uses the non-embedded
5925 * SGL block post mailbox commands to post them to the port. For single els
5926 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
5927 * mailbox command for posting.
5929 * Returns: 0 = success, non-zero failure.
5932 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
5934 struct lpfc_sglq *sglq_entry = NULL;
5935 struct lpfc_sglq *sglq_entry_next = NULL;
5936 struct lpfc_sglq *sglq_entry_first = NULL;
5937 int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
5938 int last_xritag = NO_XRI;
5939 LIST_HEAD(prep_sgl_list);
5940 LIST_HEAD(blck_sgl_list);
5941 LIST_HEAD(allc_sgl_list);
5942 LIST_HEAD(post_sgl_list);
5943 LIST_HEAD(free_sgl_list);
5945 spin_lock(&phba->hbalock);
5946 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
5947 spin_unlock(&phba->hbalock);
5949 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
5950 &allc_sgl_list, list) {
5951 list_del_init(&sglq_entry->list);
5953 if ((last_xritag != NO_XRI) &&
5954 (sglq_entry->sli4_xritag != last_xritag + 1)) {
5955 /* a hole in xri block, form a sgl posting block */
5956 list_splice_init(&prep_sgl_list, &blck_sgl_list);
5957 post_cnt = block_cnt - 1;
5958 /* prepare list for next posting block */
5959 list_add_tail(&sglq_entry->list, &prep_sgl_list);
5962 /* prepare list for next posting block */
5963 list_add_tail(&sglq_entry->list, &prep_sgl_list);
5964 /* enough sgls for non-embed sgl mbox command */
5965 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
5966 list_splice_init(&prep_sgl_list,
5968 post_cnt = block_cnt;
5974 /* keep track of last sgl's xritag */
5975 last_xritag = sglq_entry->sli4_xritag;
5977 /* end of repost sgl list condition for els buffers */
5978 if (num_posted == phba->sli4_hba.els_xri_cnt) {
5979 if (post_cnt == 0) {
5980 list_splice_init(&prep_sgl_list,
5982 post_cnt = block_cnt;
5983 } else if (block_cnt == 1) {
5984 status = lpfc_sli4_post_sgl(phba,
5985 sglq_entry->phys, 0,
5986 sglq_entry->sli4_xritag);
5988 /* successful, put sgl to posted list */
5989 list_add_tail(&sglq_entry->list,
5992 /* Failure, put sgl to free list */
5993 lpfc_printf_log(phba, KERN_WARNING,
5995 "3159 Failed to post els "
5996 "sgl, xritag:x%x\n",
5997 sglq_entry->sli4_xritag);
5998 list_add_tail(&sglq_entry->list,
6000 spin_lock_irq(&phba->hbalock);
6001 phba->sli4_hba.els_xri_cnt--;
6002 spin_unlock_irq(&phba->hbalock);
6007 /* continue until a nembed page worth of sgls */
6011 /* post the els buffer list sgls as a block */
6012 status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
6016 /* success, put sgl list to posted sgl list */
6017 list_splice_init(&blck_sgl_list, &post_sgl_list);
6019 /* Failure, put sgl list to free sgl list */
6020 sglq_entry_first = list_first_entry(&blck_sgl_list,
6023 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6024 "3160 Failed to post els sgl-list, "
6026 sglq_entry_first->sli4_xritag,
6027 (sglq_entry_first->sli4_xritag +
6029 list_splice_init(&blck_sgl_list, &free_sgl_list);
6030 spin_lock_irq(&phba->hbalock);
6031 phba->sli4_hba.els_xri_cnt -= post_cnt;
6032 spin_unlock_irq(&phba->hbalock);
6035 /* don't reset xirtag due to hole in xri block */
6037 last_xritag = NO_XRI;
6039 /* reset els sgl post count for next round of posting */
6043 /* free the els sgls failed to post */
6044 lpfc_free_sgl_list(phba, &free_sgl_list);
6046 /* push els sgls posted to the availble list */
6047 if (!list_empty(&post_sgl_list)) {
6048 spin_lock(&phba->hbalock);
6049 list_splice_init(&post_sgl_list,
6050 &phba->sli4_hba.lpfc_sgl_list);
6051 spin_unlock(&phba->hbalock);
6053 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6054 "3161 Failure to post els sgl to port.\n");
6061 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6062 * @phba: Pointer to HBA context object.
6064 * This function is the main SLI4 device intialization PCI function. This
6065 * function is called by the HBA intialization code, HBA reset code and
6066 * HBA error attention handler code. Caller is not required to hold any
6070 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
6073 LPFC_MBOXQ_t *mboxq;
6074 struct lpfc_mqe *mqe;
6077 uint32_t ftr_rsp = 0;
6078 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
6079 struct lpfc_vport *vport = phba->pport;
6080 struct lpfc_dmabuf *mp;
6082 /* Perform a PCI function reset to start from clean */
6083 rc = lpfc_pci_function_reset(phba);
6087 /* Check the HBA Host Status Register for readyness */
6088 rc = lpfc_sli4_post_status_check(phba);
6092 spin_lock_irq(&phba->hbalock);
6093 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
6094 spin_unlock_irq(&phba->hbalock);
6098 * Allocate a single mailbox container for initializing the
6101 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6105 /* Issue READ_REV to collect vpd and FW information. */
6106 vpd_size = SLI4_PAGE_SIZE;
6107 vpd = kzalloc(vpd_size, GFP_KERNEL);
6113 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
6118 mqe = &mboxq->u.mqe;
6119 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
6120 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
6121 phba->hba_flag |= HBA_FCOE_MODE;
6123 phba->hba_flag &= ~HBA_FCOE_MODE;
6125 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
6127 phba->hba_flag |= HBA_FIP_SUPPORT;
6129 phba->hba_flag &= ~HBA_FIP_SUPPORT;
6131 phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
6133 if (phba->sli_rev != LPFC_SLI_REV4) {
6134 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6135 "0376 READ_REV Error. SLI Level %d "
6136 "FCoE enabled %d\n",
6137 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
6144 * Continue initialization with default values even if driver failed
6145 * to read FCoE param config regions, only read parameters if the
6148 if (phba->hba_flag & HBA_FCOE_MODE &&
6149 lpfc_sli4_read_fcoe_params(phba))
6150 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
6151 "2570 Failed to read FCoE parameters\n");
6154 * Retrieve sli4 device physical port name, failure of doing it
6155 * is considered as non-fatal.
6157 rc = lpfc_sli4_retrieve_pport_name(phba);
6159 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6160 "3080 Successful retrieving SLI4 device "
6161 "physical port name: %s.\n", phba->Port);
6164 * Evaluate the read rev and vpd data. Populate the driver
6165 * state with the results. If this routine fails, the failure
6166 * is not fatal as the driver will use generic values.
6168 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
6169 if (unlikely(!rc)) {
6170 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6171 "0377 Error %d parsing vpd. "
6172 "Using defaults.\n", rc);
6177 /* Save information as VPD data */
6178 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
6179 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
6180 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
6181 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
6183 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
6185 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
6187 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
6189 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
6190 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
6191 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
6192 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
6193 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
6194 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
6195 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6196 "(%d):0380 READ_REV Status x%x "
6197 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6198 mboxq->vport ? mboxq->vport->vpi : 0,
6199 bf_get(lpfc_mqe_status, mqe),
6200 phba->vpd.rev.opFwName,
6201 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
6202 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
6205 * Discover the port's supported feature set and match it against the
6208 lpfc_request_features(phba, mboxq);
6209 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6216 * The port must support FCP initiator mode as this is the
6217 * only mode running in the host.
6219 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
6220 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6221 "0378 No support for fcpi mode.\n");
6224 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
6225 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
6227 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
6229 * If the port cannot support the host's requested features
6230 * then turn off the global config parameters to disable the
6231 * feature in the driver. This is not a fatal error.
6233 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
6234 if (phba->cfg_enable_bg) {
6235 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
6236 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6241 if (phba->max_vpi && phba->cfg_enable_npiv &&
6242 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
6246 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6247 "0379 Feature Mismatch Data: x%08x %08x "
6248 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
6249 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
6250 phba->cfg_enable_npiv, phba->max_vpi);
6251 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
6252 phba->cfg_enable_bg = 0;
6253 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
6254 phba->cfg_enable_npiv = 0;
6257 /* These SLI3 features are assumed in SLI4 */
6258 spin_lock_irq(&phba->hbalock);
6259 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
6260 spin_unlock_irq(&phba->hbalock);
6263 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6264 * calls depends on these resources to complete port setup.
6266 rc = lpfc_sli4_alloc_resource_identifiers(phba);
6268 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6269 "2920 Failed to alloc Resource IDs "
6274 /* Read the port's service parameters. */
6275 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
6277 phba->link_state = LPFC_HBA_ERROR;
6282 mboxq->vport = vport;
6283 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6284 mp = (struct lpfc_dmabuf *) mboxq->context1;
6285 if (rc == MBX_SUCCESS) {
6286 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
6291 * This memory was allocated by the lpfc_read_sparam routine. Release
6292 * it to the mbuf pool.
6294 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6296 mboxq->context1 = NULL;
6298 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6299 "0382 READ_SPARAM command failed "
6300 "status %d, mbxStatus x%x\n",
6301 rc, bf_get(lpfc_mqe_status, mqe));
6302 phba->link_state = LPFC_HBA_ERROR;
6307 lpfc_update_vport_wwn(vport);
6309 /* Update the fc_host data structures with new wwn. */
6310 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
6311 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
6313 /* update host els and scsi xri-sgl sizes and mappings */
6314 rc = lpfc_sli4_xri_sgl_update(phba);
6316 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6317 "1400 Failed to update xri-sgl size and "
6318 "mapping: %d\n", rc);
6322 /* register the els sgl pool to the port */
6323 rc = lpfc_sli4_repost_els_sgl_list(phba);
6325 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6326 "0582 Error %d during els sgl post "
6332 /* register the allocated scsi sgl pool to the port */
6333 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
6335 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6336 "0383 Error %d during scsi sgl post "
6338 /* Some Scsi buffers were moved to the abort scsi list */
6339 /* A pci function reset will repost them */
6344 /* Post the rpi header region to the device. */
6345 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
6347 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6348 "0393 Error %d during rpi post operation\n",
6353 lpfc_sli4_node_prep(phba);
6355 /* Create all the SLI4 queues */
6356 rc = lpfc_sli4_queue_create(phba);
6358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6359 "3089 Failed to allocate queues\n");
6361 goto out_stop_timers;
6363 /* Set up all the queues to the device */
6364 rc = lpfc_sli4_queue_setup(phba);
6366 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6367 "0381 Error %d during queue setup.\n ", rc);
6368 goto out_destroy_queue;
6371 /* Arm the CQs and then EQs on device */
6372 lpfc_sli4_arm_cqeq_intr(phba);
6374 /* Indicate device interrupt mode */
6375 phba->sli4_hba.intr_enable = 1;
6377 /* Allow asynchronous mailbox command to go through */
6378 spin_lock_irq(&phba->hbalock);
6379 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
6380 spin_unlock_irq(&phba->hbalock);
6382 /* Post receive buffers to the device */
6383 lpfc_sli4_rb_setup(phba);
6385 /* Reset HBA FCF states after HBA reset */
6386 phba->fcf.fcf_flag = 0;
6387 phba->fcf.current_rec.flag = 0;
6389 /* Start the ELS watchdog timer */
6390 mod_timer(&vport->els_tmofunc,
6391 jiffies + HZ * (phba->fc_ratov * 2));
6393 /* Start heart beat timer */
6394 mod_timer(&phba->hb_tmofunc,
6395 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
6396 phba->hb_outstanding = 0;
6397 phba->last_completion_time = jiffies;
6399 /* Start error attention (ERATT) polling timer */
6400 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
6402 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6403 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
6404 rc = pci_enable_pcie_error_reporting(phba->pcidev);
6406 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6407 "2829 This device supports "
6408 "Advanced Error Reporting (AER)\n");
6409 spin_lock_irq(&phba->hbalock);
6410 phba->hba_flag |= HBA_AER_ENABLED;
6411 spin_unlock_irq(&phba->hbalock);
6413 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6414 "2830 This device does not support "
6415 "Advanced Error Reporting (AER)\n");
6416 phba->cfg_aer_support = 0;
6421 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
6423 * The FC Port needs to register FCFI (index 0)
6425 lpfc_reg_fcfi(phba, mboxq);
6426 mboxq->vport = phba->pport;
6427 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6428 if (rc != MBX_SUCCESS)
6429 goto out_unset_queue;
6431 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
6432 &mboxq->u.mqe.un.reg_fcfi);
6434 /* Check if the port is configured to be disabled */
6435 lpfc_sli_read_link_ste(phba);
6439 * The port is ready, set the host's link state to LINK_DOWN
6440 * in preparation for link interrupts.
6442 spin_lock_irq(&phba->hbalock);
6443 phba->link_state = LPFC_LINK_DOWN;
6444 spin_unlock_irq(&phba->hbalock);
6445 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
6446 (phba->hba_flag & LINK_DISABLED)) {
6447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
6448 "3103 Adapter Link is disabled.\n");
6449 lpfc_down_link(phba, mboxq);
6450 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6451 if (rc != MBX_SUCCESS) {
6452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
6453 "3104 Adapter failed to issue "
6454 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
6455 goto out_unset_queue;
6457 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
6458 /* don't perform init_link on SLI4 FC port loopback test */
6459 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
6460 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
6462 goto out_unset_queue;
6465 mempool_free(mboxq, phba->mbox_mem_pool);
6468 /* Unset all the queues set up in this routine when error out */
6469 lpfc_sli4_queue_unset(phba);
6471 lpfc_sli4_queue_destroy(phba);
6473 lpfc_stop_hba_timers(phba);
6475 mempool_free(mboxq, phba->mbox_mem_pool);
6480 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6481 * @ptr: context object - pointer to hba structure.
6483 * This is the callback function for mailbox timer. The mailbox
6484 * timer is armed when a new mailbox command is issued and the timer
6485 * is deleted when the mailbox complete. The function is called by
6486 * the kernel timer code when a mailbox does not complete within
6487 * expected time. This function wakes up the worker thread to
6488 * process the mailbox timeout and returns. All the processing is
6489 * done by the worker thread function lpfc_mbox_timeout_handler.
6492 lpfc_mbox_timeout(unsigned long ptr)
6494 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6495 unsigned long iflag;
6496 uint32_t tmo_posted;
6498 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
6499 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
6501 phba->pport->work_port_events |= WORKER_MBOX_TMO;
6502 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
6505 lpfc_worker_wake_up(phba);
6511 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6512 * @phba: Pointer to HBA context object.
6514 * This function is called from worker thread when a mailbox command times out.
6515 * The caller is not required to hold any locks. This function will reset the
6516 * HBA and recover all the pending commands.
6519 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
6521 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
6522 MAILBOX_t *mb = &pmbox->u.mb;
6523 struct lpfc_sli *psli = &phba->sli;
6524 struct lpfc_sli_ring *pring;
6526 /* Check the pmbox pointer first. There is a race condition
6527 * between the mbox timeout handler getting executed in the
6528 * worklist and the mailbox actually completing. When this
6529 * race condition occurs, the mbox_active will be NULL.
6531 spin_lock_irq(&phba->hbalock);
6532 if (pmbox == NULL) {
6533 lpfc_printf_log(phba, KERN_WARNING,
6535 "0353 Active Mailbox cleared - mailbox timeout "
6537 spin_unlock_irq(&phba->hbalock);
6541 /* Mbox cmd <mbxCommand> timeout */
6542 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6543 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6545 phba->pport->port_state,
6547 phba->sli.mbox_active);
6548 spin_unlock_irq(&phba->hbalock);
6550 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6551 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6552 * it to fail all outstanding SCSI IO.
6554 spin_lock_irq(&phba->pport->work_port_lock);
6555 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
6556 spin_unlock_irq(&phba->pport->work_port_lock);
6557 spin_lock_irq(&phba->hbalock);
6558 phba->link_state = LPFC_LINK_UNKNOWN;
6559 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
6560 spin_unlock_irq(&phba->hbalock);
6562 pring = &psli->ring[psli->fcp_ring];
6563 lpfc_sli_abort_iocb_ring(phba, pring);
6565 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6566 "0345 Resetting board due to mailbox timeout\n");
6568 /* Reset the HBA device */
6569 lpfc_reset_hba(phba);
6573 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6574 * @phba: Pointer to HBA context object.
6575 * @pmbox: Pointer to mailbox object.
6576 * @flag: Flag indicating how the mailbox need to be processed.
6578 * This function is called by discovery code and HBA management code
6579 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6580 * function gets the hbalock to protect the data structures.
6581 * The mailbox command can be submitted in polling mode, in which case
6582 * this function will wait in a polling loop for the completion of the
6584 * If the mailbox is submitted in no_wait mode (not polling) the
6585 * function will submit the command and returns immediately without waiting
6586 * for the mailbox completion. The no_wait is supported only when HBA
6587 * is in SLI2/SLI3 mode - interrupts are enabled.
6588 * The SLI interface allows only one mailbox pending at a time. If the
6589 * mailbox is issued in polling mode and there is already a mailbox
6590 * pending, then the function will return an error. If the mailbox is issued
6591 * in NO_WAIT mode and there is a mailbox pending already, the function
6592 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6593 * The sli layer owns the mailbox object until the completion of mailbox
6594 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6595 * return codes the caller owns the mailbox command after the return of
6599 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
6603 struct lpfc_sli *psli = &phba->sli;
6604 uint32_t status, evtctr;
6605 uint32_t ha_copy, hc_copy;
6607 unsigned long timeout;
6608 unsigned long drvr_flag = 0;
6609 uint32_t word0, ldata;
6610 void __iomem *to_slim;
6611 int processing_queue = 0;
6613 spin_lock_irqsave(&phba->hbalock, drvr_flag);
6615 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6616 /* processing mbox queue from intr_handler */
6617 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
6618 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6621 processing_queue = 1;
6622 pmbox = lpfc_mbox_get(phba);
6624 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6629 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
6630 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
6632 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6633 lpfc_printf_log(phba, KERN_ERR,
6634 LOG_MBOX | LOG_VPORT,
6635 "1806 Mbox x%x failed. No vport\n",
6636 pmbox->u.mb.mbxCommand);
6638 goto out_not_finished;
6642 /* If the PCI channel is in offline state, do not post mbox. */
6643 if (unlikely(pci_channel_offline(phba->pcidev))) {
6644 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6645 goto out_not_finished;
6648 /* If HBA has a deferred error attention, fail the iocb. */
6649 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
6650 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6651 goto out_not_finished;
6657 status = MBX_SUCCESS;
6659 if (phba->link_state == LPFC_HBA_ERROR) {
6660 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6662 /* Mbox command <mbxCommand> cannot issue */
6663 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6664 "(%d):0311 Mailbox command x%x cannot "
6665 "issue Data: x%x x%x\n",
6666 pmbox->vport ? pmbox->vport->vpi : 0,
6667 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
6668 goto out_not_finished;
6671 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
6672 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
6673 !(hc_copy & HC_MBINT_ENA)) {
6674 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6675 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6676 "(%d):2528 Mailbox command x%x cannot "
6677 "issue Data: x%x x%x\n",
6678 pmbox->vport ? pmbox->vport->vpi : 0,
6679 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
6680 goto out_not_finished;
6684 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6685 /* Polling for a mbox command when another one is already active
6686 * is not allowed in SLI. Also, the driver must have established
6687 * SLI2 mode to queue and process multiple mbox commands.
6690 if (flag & MBX_POLL) {
6691 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6693 /* Mbox command <mbxCommand> cannot issue */
6694 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6695 "(%d):2529 Mailbox command x%x "
6696 "cannot issue Data: x%x x%x\n",
6697 pmbox->vport ? pmbox->vport->vpi : 0,
6698 pmbox->u.mb.mbxCommand,
6699 psli->sli_flag, flag);
6700 goto out_not_finished;
6703 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
6704 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6705 /* Mbox command <mbxCommand> cannot issue */
6706 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6707 "(%d):2530 Mailbox command x%x "
6708 "cannot issue Data: x%x x%x\n",
6709 pmbox->vport ? pmbox->vport->vpi : 0,
6710 pmbox->u.mb.mbxCommand,
6711 psli->sli_flag, flag);
6712 goto out_not_finished;
6715 /* Another mailbox command is still being processed, queue this
6716 * command to be processed later.
6718 lpfc_mbox_put(phba, pmbox);
6720 /* Mbox cmd issue - BUSY */
6721 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6722 "(%d):0308 Mbox cmd issue - BUSY Data: "
6723 "x%x x%x x%x x%x\n",
6724 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
6725 mb->mbxCommand, phba->pport->port_state,
6726 psli->sli_flag, flag);
6728 psli->slistat.mbox_busy++;
6729 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6732 lpfc_debugfs_disc_trc(pmbox->vport,
6733 LPFC_DISC_TRC_MBOX_VPORT,
6734 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6735 (uint32_t)mb->mbxCommand,
6736 mb->un.varWords[0], mb->un.varWords[1]);
6739 lpfc_debugfs_disc_trc(phba->pport,
6741 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6742 (uint32_t)mb->mbxCommand,
6743 mb->un.varWords[0], mb->un.varWords[1]);
6749 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
6751 /* If we are not polling, we MUST be in SLI2 mode */
6752 if (flag != MBX_POLL) {
6753 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
6754 (mb->mbxCommand != MBX_KILL_BOARD)) {
6755 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6756 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6757 /* Mbox command <mbxCommand> cannot issue */
6758 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6759 "(%d):2531 Mailbox command x%x "
6760 "cannot issue Data: x%x x%x\n",
6761 pmbox->vport ? pmbox->vport->vpi : 0,
6762 pmbox->u.mb.mbxCommand,
6763 psli->sli_flag, flag);
6764 goto out_not_finished;
6766 /* timeout active mbox command */
6767 mod_timer(&psli->mbox_tmo, (jiffies +
6768 (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
6771 /* Mailbox cmd <cmd> issue */
6772 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6773 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6775 pmbox->vport ? pmbox->vport->vpi : 0,
6776 mb->mbxCommand, phba->pport->port_state,
6777 psli->sli_flag, flag);
6779 if (mb->mbxCommand != MBX_HEARTBEAT) {
6781 lpfc_debugfs_disc_trc(pmbox->vport,
6782 LPFC_DISC_TRC_MBOX_VPORT,
6783 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6784 (uint32_t)mb->mbxCommand,
6785 mb->un.varWords[0], mb->un.varWords[1]);
6788 lpfc_debugfs_disc_trc(phba->pport,
6790 "MBOX Send: cmd:x%x mb:x%x x%x",
6791 (uint32_t)mb->mbxCommand,
6792 mb->un.varWords[0], mb->un.varWords[1]);
6796 psli->slistat.mbox_cmd++;
6797 evtctr = psli->slistat.mbox_event;
6799 /* next set own bit for the adapter and copy over command word */
6800 mb->mbxOwner = OWN_CHIP;
6802 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6803 /* Populate mbox extension offset word. */
6804 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
6805 *(((uint32_t *)mb) + pmbox->mbox_offset_word)
6806 = (uint8_t *)phba->mbox_ext
6807 - (uint8_t *)phba->mbox;
6810 /* Copy the mailbox extension data */
6811 if (pmbox->in_ext_byte_len && pmbox->context2) {
6812 lpfc_sli_pcimem_bcopy(pmbox->context2,
6813 (uint8_t *)phba->mbox_ext,
6814 pmbox->in_ext_byte_len);
6816 /* Copy command data to host SLIM area */
6817 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
6819 /* Populate mbox extension offset word. */
6820 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
6821 *(((uint32_t *)mb) + pmbox->mbox_offset_word)
6822 = MAILBOX_HBA_EXT_OFFSET;
6824 /* Copy the mailbox extension data */
6825 if (pmbox->in_ext_byte_len && pmbox->context2) {
6826 lpfc_memcpy_to_slim(phba->MBslimaddr +
6827 MAILBOX_HBA_EXT_OFFSET,
6828 pmbox->context2, pmbox->in_ext_byte_len);
6831 if (mb->mbxCommand == MBX_CONFIG_PORT) {
6832 /* copy command data into host mbox for cmpl */
6833 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
6836 /* First copy mbox command data to HBA SLIM, skip past first
6838 to_slim = phba->MBslimaddr + sizeof (uint32_t);
6839 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
6840 MAILBOX_CMD_SIZE - sizeof (uint32_t));
6842 /* Next copy over first word, with mbxOwner set */
6843 ldata = *((uint32_t *)mb);
6844 to_slim = phba->MBslimaddr;
6845 writel(ldata, to_slim);
6846 readl(to_slim); /* flush */
6848 if (mb->mbxCommand == MBX_CONFIG_PORT) {
6849 /* switch over to host mailbox */
6850 psli->sli_flag |= LPFC_SLI_ACTIVE;
6858 /* Set up reference to mailbox command */
6859 psli->mbox_active = pmbox;
6860 /* Interrupt board to do it */
6861 writel(CA_MBATT, phba->CAregaddr);
6862 readl(phba->CAregaddr); /* flush */
6863 /* Don't wait for it to finish, just return */
6867 /* Set up null reference to mailbox command */
6868 psli->mbox_active = NULL;
6869 /* Interrupt board to do it */
6870 writel(CA_MBATT, phba->CAregaddr);
6871 readl(phba->CAregaddr); /* flush */
6873 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6874 /* First read mbox status word */
6875 word0 = *((uint32_t *)phba->mbox);
6876 word0 = le32_to_cpu(word0);
6878 /* First read mbox status word */
6879 if (lpfc_readl(phba->MBslimaddr, &word0)) {
6880 spin_unlock_irqrestore(&phba->hbalock,
6882 goto out_not_finished;
6886 /* Read the HBA Host Attention Register */
6887 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
6888 spin_unlock_irqrestore(&phba->hbalock,
6890 goto out_not_finished;
6892 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
6895 /* Wait for command to complete */
6896 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
6897 (!(ha_copy & HA_MBATT) &&
6898 (phba->link_state > LPFC_WARM_START))) {
6899 if (time_after(jiffies, timeout)) {
6900 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6901 spin_unlock_irqrestore(&phba->hbalock,
6903 goto out_not_finished;
6906 /* Check if we took a mbox interrupt while we were
6908 if (((word0 & OWN_CHIP) != OWN_CHIP)
6909 && (evtctr != psli->slistat.mbox_event))
6913 spin_unlock_irqrestore(&phba->hbalock,
6916 spin_lock_irqsave(&phba->hbalock, drvr_flag);
6919 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6920 /* First copy command data */
6921 word0 = *((uint32_t *)phba->mbox);
6922 word0 = le32_to_cpu(word0);
6923 if (mb->mbxCommand == MBX_CONFIG_PORT) {
6926 /* Check real SLIM for any errors */
6927 slimword0 = readl(phba->MBslimaddr);
6928 slimmb = (MAILBOX_t *) & slimword0;
6929 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
6930 && slimmb->mbxStatus) {
6937 /* First copy command data */
6938 word0 = readl(phba->MBslimaddr);
6940 /* Read the HBA Host Attention Register */
6941 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
6942 spin_unlock_irqrestore(&phba->hbalock,
6944 goto out_not_finished;
6948 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
6949 /* copy results back to user */
6950 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
6951 /* Copy the mailbox extension data */
6952 if (pmbox->out_ext_byte_len && pmbox->context2) {
6953 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
6955 pmbox->out_ext_byte_len);
6958 /* First copy command data */
6959 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
6961 /* Copy the mailbox extension data */
6962 if (pmbox->out_ext_byte_len && pmbox->context2) {
6963 lpfc_memcpy_from_slim(pmbox->context2,
6965 MAILBOX_HBA_EXT_OFFSET,
6966 pmbox->out_ext_byte_len);
6970 writel(HA_MBATT, phba->HAregaddr);
6971 readl(phba->HAregaddr); /* flush */
6973 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6974 status = mb->mbxStatus;
6977 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6981 if (processing_queue) {
6982 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
6983 lpfc_mbox_cmpl_put(phba, pmbox);
6985 return MBX_NOT_FINISHED;
6989 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6990 * @phba: Pointer to HBA context object.
6992 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6993 * the driver internal pending mailbox queue. It will then try to wait out the
6994 * possible outstanding mailbox command before return.
6997 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6998 * the outstanding mailbox command timed out.
7001 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
7003 struct lpfc_sli *psli = &phba->sli;
7005 unsigned long timeout = 0;
7007 /* Mark the asynchronous mailbox command posting as blocked */
7008 spin_lock_irq(&phba->hbalock);
7009 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
7010 /* Determine how long we might wait for the active mailbox
7011 * command to be gracefully completed by firmware.
7013 if (phba->sli.mbox_active)
7014 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
7015 phba->sli.mbox_active) *
7017 spin_unlock_irq(&phba->hbalock);
7019 /* Wait for the outstnading mailbox command to complete */
7020 while (phba->sli.mbox_active) {
7021 /* Check active mailbox complete status every 2ms */
7023 if (time_after(jiffies, timeout)) {
7024 /* Timeout, marked the outstanding cmd not complete */
7030 /* Can not cleanly block async mailbox command, fails it */
7032 spin_lock_irq(&phba->hbalock);
7033 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7034 spin_unlock_irq(&phba->hbalock);
7040 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7041 * @phba: Pointer to HBA context object.
7043 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7044 * commands from the driver internal pending mailbox queue. It makes sure
7045 * that there is no outstanding mailbox command before resuming posting
7046 * asynchronous mailbox commands. If, for any reason, there is outstanding
7047 * mailbox command, it will try to wait it out before resuming asynchronous
7048 * mailbox command posting.
7051 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
7053 struct lpfc_sli *psli = &phba->sli;
7055 spin_lock_irq(&phba->hbalock);
7056 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
7057 /* Asynchronous mailbox posting is not blocked, do nothing */
7058 spin_unlock_irq(&phba->hbalock);
7062 /* Outstanding synchronous mailbox command is guaranteed to be done,
7063 * successful or timeout, after timing-out the outstanding mailbox
7064 * command shall always be removed, so just unblock posting async
7065 * mailbox command and resume
7067 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7068 spin_unlock_irq(&phba->hbalock);
7070 /* wake up worker thread to post asynchronlous mailbox command */
7071 lpfc_worker_wake_up(phba);
7075 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7076 * @phba: Pointer to HBA context object.
7077 * @mboxq: Pointer to mailbox object.
7079 * The function posts a mailbox to the port. The mailbox is expected
7080 * to be comletely filled in and ready for the port to operate on it.
7081 * This routine executes a synchronous completion operation on the
7082 * mailbox by polling for its completion.
7084 * The caller must not be holding any locks when calling this routine.
7087 * MBX_SUCCESS - mailbox posted successfully
7088 * Any of the MBX error values.
7091 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7093 int rc = MBX_SUCCESS;
7094 unsigned long iflag;
7096 uint32_t mcqe_status;
7098 unsigned long timeout;
7099 struct lpfc_sli *psli = &phba->sli;
7100 struct lpfc_mqe *mb = &mboxq->u.mqe;
7101 struct lpfc_bmbx_create *mbox_rgn;
7102 struct dma_address *dma_address;
7103 struct lpfc_register bmbx_reg;
7106 * Only one mailbox can be active to the bootstrap mailbox region
7107 * at a time and there is no queueing provided.
7109 spin_lock_irqsave(&phba->hbalock, iflag);
7110 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
7111 spin_unlock_irqrestore(&phba->hbalock, iflag);
7112 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7113 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7114 "cannot issue Data: x%x x%x\n",
7115 mboxq->vport ? mboxq->vport->vpi : 0,
7116 mboxq->u.mb.mbxCommand,
7117 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7118 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7119 psli->sli_flag, MBX_POLL);
7120 return MBXERR_ERROR;
7122 /* The server grabs the token and owns it until release */
7123 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
7124 phba->sli.mbox_active = mboxq;
7125 spin_unlock_irqrestore(&phba->hbalock, iflag);
7128 * Initialize the bootstrap memory region to avoid stale data areas
7129 * in the mailbox post. Then copy the caller's mailbox contents to
7130 * the bmbx mailbox region.
7132 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
7133 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
7134 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
7135 sizeof(struct lpfc_mqe));
7137 /* Post the high mailbox dma address to the port and wait for ready. */
7138 dma_address = &phba->sli4_hba.bmbx.dma_address;
7139 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
7141 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
7144 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
7145 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
7149 if (time_after(jiffies, timeout)) {
7153 } while (!db_ready);
7155 /* Post the low mailbox dma address to the port. */
7156 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
7157 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
7160 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
7161 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
7165 if (time_after(jiffies, timeout)) {
7169 } while (!db_ready);
7172 * Read the CQ to ensure the mailbox has completed.
7173 * If so, update the mailbox status so that the upper layers
7174 * can complete the request normally.
7176 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
7177 sizeof(struct lpfc_mqe));
7178 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
7179 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
7180 sizeof(struct lpfc_mcqe));
7181 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
7183 * When the CQE status indicates a failure and the mailbox status
7184 * indicates success then copy the CQE status into the mailbox status
7185 * (and prefix it with x4000).
7187 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
7188 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
7189 bf_set(lpfc_mqe_status, mb,
7190 (LPFC_MBX_ERROR_RANGE | mcqe_status));
7193 lpfc_sli4_swap_str(phba, mboxq);
7195 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7196 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7197 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7198 " x%x x%x CQ: x%x x%x x%x x%x\n",
7199 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
7200 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7201 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7202 bf_get(lpfc_mqe_status, mb),
7203 mb->un.mb_words[0], mb->un.mb_words[1],
7204 mb->un.mb_words[2], mb->un.mb_words[3],
7205 mb->un.mb_words[4], mb->un.mb_words[5],
7206 mb->un.mb_words[6], mb->un.mb_words[7],
7207 mb->un.mb_words[8], mb->un.mb_words[9],
7208 mb->un.mb_words[10], mb->un.mb_words[11],
7209 mb->un.mb_words[12], mboxq->mcqe.word0,
7210 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
7211 mboxq->mcqe.trailer);
7213 /* We are holding the token, no needed for lock when release */
7214 spin_lock_irqsave(&phba->hbalock, iflag);
7215 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7216 phba->sli.mbox_active = NULL;
7217 spin_unlock_irqrestore(&phba->hbalock, iflag);
7222 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7223 * @phba: Pointer to HBA context object.
7224 * @pmbox: Pointer to mailbox object.
7225 * @flag: Flag indicating how the mailbox need to be processed.
7227 * This function is called by discovery code and HBA management code to submit
7228 * a mailbox command to firmware with SLI-4 interface spec.
7230 * Return codes the caller owns the mailbox command after the return of the
7234 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
7237 struct lpfc_sli *psli = &phba->sli;
7238 unsigned long iflags;
7241 /* dump from issue mailbox command if setup */
7242 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
7244 rc = lpfc_mbox_dev_check(phba);
7246 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7247 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7248 "cannot issue Data: x%x x%x\n",
7249 mboxq->vport ? mboxq->vport->vpi : 0,
7250 mboxq->u.mb.mbxCommand,
7251 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7252 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7253 psli->sli_flag, flag);
7254 goto out_not_finished;
7257 /* Detect polling mode and jump to a handler */
7258 if (!phba->sli4_hba.intr_enable) {
7259 if (flag == MBX_POLL)
7260 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
7263 if (rc != MBX_SUCCESS)
7264 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7265 "(%d):2541 Mailbox command x%x "
7266 "(x%x/x%x) failure: "
7267 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7269 mboxq->vport ? mboxq->vport->vpi : 0,
7270 mboxq->u.mb.mbxCommand,
7271 lpfc_sli_config_mbox_subsys_get(phba,
7273 lpfc_sli_config_mbox_opcode_get(phba,
7275 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
7276 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
7277 bf_get(lpfc_mcqe_ext_status,
7279 psli->sli_flag, flag);
7281 } else if (flag == MBX_POLL) {
7282 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7283 "(%d):2542 Try to issue mailbox command "
7284 "x%x (x%x/x%x) synchronously ahead of async"
7285 "mailbox command queue: x%x x%x\n",
7286 mboxq->vport ? mboxq->vport->vpi : 0,
7287 mboxq->u.mb.mbxCommand,
7288 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7289 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7290 psli->sli_flag, flag);
7291 /* Try to block the asynchronous mailbox posting */
7292 rc = lpfc_sli4_async_mbox_block(phba);
7294 /* Successfully blocked, now issue sync mbox cmd */
7295 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
7296 if (rc != MBX_SUCCESS)
7297 lpfc_printf_log(phba, KERN_WARNING,
7299 "(%d):2597 Sync Mailbox command "
7300 "x%x (x%x/x%x) failure: "
7301 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7303 mboxq->vport ? mboxq->vport->vpi : 0,
7304 mboxq->u.mb.mbxCommand,
7305 lpfc_sli_config_mbox_subsys_get(phba,
7307 lpfc_sli_config_mbox_opcode_get(phba,
7309 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
7310 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
7311 bf_get(lpfc_mcqe_ext_status,
7313 psli->sli_flag, flag);
7314 /* Unblock the async mailbox posting afterward */
7315 lpfc_sli4_async_mbox_unblock(phba);
7320 /* Now, interrupt mode asynchrous mailbox command */
7321 rc = lpfc_mbox_cmd_check(phba, mboxq);
7323 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7324 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7325 "cannot issue Data: x%x x%x\n",
7326 mboxq->vport ? mboxq->vport->vpi : 0,
7327 mboxq->u.mb.mbxCommand,
7328 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7329 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7330 psli->sli_flag, flag);
7331 goto out_not_finished;
7334 /* Put the mailbox command to the driver internal FIFO */
7335 psli->slistat.mbox_busy++;
7336 spin_lock_irqsave(&phba->hbalock, iflags);
7337 lpfc_mbox_put(phba, mboxq);
7338 spin_unlock_irqrestore(&phba->hbalock, iflags);
7339 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7340 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7341 "x%x (x%x/x%x) x%x x%x x%x\n",
7342 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
7343 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7344 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7345 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7346 phba->pport->port_state,
7347 psli->sli_flag, MBX_NOWAIT);
7348 /* Wake up worker thread to transport mailbox command from head */
7349 lpfc_worker_wake_up(phba);
7354 return MBX_NOT_FINISHED;
7358 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7359 * @phba: Pointer to HBA context object.
7361 * This function is called by worker thread to send a mailbox command to
7362 * SLI4 HBA firmware.
7366 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
7368 struct lpfc_sli *psli = &phba->sli;
7369 LPFC_MBOXQ_t *mboxq;
7370 int rc = MBX_SUCCESS;
7371 unsigned long iflags;
7372 struct lpfc_mqe *mqe;
7375 /* Check interrupt mode before post async mailbox command */
7376 if (unlikely(!phba->sli4_hba.intr_enable))
7377 return MBX_NOT_FINISHED;
7379 /* Check for mailbox command service token */
7380 spin_lock_irqsave(&phba->hbalock, iflags);
7381 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
7382 spin_unlock_irqrestore(&phba->hbalock, iflags);
7383 return MBX_NOT_FINISHED;
7385 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
7386 spin_unlock_irqrestore(&phba->hbalock, iflags);
7387 return MBX_NOT_FINISHED;
7389 if (unlikely(phba->sli.mbox_active)) {
7390 spin_unlock_irqrestore(&phba->hbalock, iflags);
7391 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7392 "0384 There is pending active mailbox cmd\n");
7393 return MBX_NOT_FINISHED;
7395 /* Take the mailbox command service token */
7396 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
7398 /* Get the next mailbox command from head of queue */
7399 mboxq = lpfc_mbox_get(phba);
7401 /* If no more mailbox command waiting for post, we're done */
7403 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7404 spin_unlock_irqrestore(&phba->hbalock, iflags);
7407 phba->sli.mbox_active = mboxq;
7408 spin_unlock_irqrestore(&phba->hbalock, iflags);
7410 /* Check device readiness for posting mailbox command */
7411 rc = lpfc_mbox_dev_check(phba);
7413 /* Driver clean routine will clean up pending mailbox */
7414 goto out_not_finished;
7416 /* Prepare the mbox command to be posted */
7417 mqe = &mboxq->u.mqe;
7418 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
7420 /* Start timer for the mbox_tmo and log some mailbox post messages */
7421 mod_timer(&psli->mbox_tmo, (jiffies +
7422 (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
7424 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7425 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7427 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
7428 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7429 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7430 phba->pport->port_state, psli->sli_flag);
7432 if (mbx_cmnd != MBX_HEARTBEAT) {
7434 lpfc_debugfs_disc_trc(mboxq->vport,
7435 LPFC_DISC_TRC_MBOX_VPORT,
7436 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7437 mbx_cmnd, mqe->un.mb_words[0],
7438 mqe->un.mb_words[1]);
7440 lpfc_debugfs_disc_trc(phba->pport,
7442 "MBOX Send: cmd:x%x mb:x%x x%x",
7443 mbx_cmnd, mqe->un.mb_words[0],
7444 mqe->un.mb_words[1]);
7447 psli->slistat.mbox_cmd++;
7449 /* Post the mailbox command to the port */
7450 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
7451 if (rc != MBX_SUCCESS) {
7452 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7453 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7454 "cannot issue Data: x%x x%x\n",
7455 mboxq->vport ? mboxq->vport->vpi : 0,
7456 mboxq->u.mb.mbxCommand,
7457 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7458 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7459 psli->sli_flag, MBX_NOWAIT);
7460 goto out_not_finished;
7466 spin_lock_irqsave(&phba->hbalock, iflags);
7467 if (phba->sli.mbox_active) {
7468 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
7469 __lpfc_mbox_cmpl_put(phba, mboxq);
7470 /* Release the token */
7471 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7472 phba->sli.mbox_active = NULL;
7474 spin_unlock_irqrestore(&phba->hbalock, iflags);
7476 return MBX_NOT_FINISHED;
7480 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7481 * @phba: Pointer to HBA context object.
7482 * @pmbox: Pointer to mailbox object.
7483 * @flag: Flag indicating how the mailbox need to be processed.
7485 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7486 * the API jump table function pointer from the lpfc_hba struct.
7488 * Return codes the caller owns the mailbox command after the return of the
7492 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
7494 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
7498 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7499 * @phba: The hba struct for which this call is being executed.
7500 * @dev_grp: The HBA PCI-Device group number.
7502 * This routine sets up the mbox interface API function jump table in @phba
7504 * Returns: 0 - success, -ENODEV - failure.
7507 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7511 case LPFC_PCI_DEV_LP:
7512 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
7513 phba->lpfc_sli_handle_slow_ring_event =
7514 lpfc_sli_handle_slow_ring_event_s3;
7515 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
7516 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
7517 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
7519 case LPFC_PCI_DEV_OC:
7520 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
7521 phba->lpfc_sli_handle_slow_ring_event =
7522 lpfc_sli_handle_slow_ring_event_s4;
7523 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
7524 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
7525 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
7528 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7529 "1420 Invalid HBA PCI-device group: 0x%x\n",
7538 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7539 * @phba: Pointer to HBA context object.
7540 * @pring: Pointer to driver SLI ring object.
7541 * @piocb: Pointer to address of newly added command iocb.
7543 * This function is called with hbalock held to add a command
7544 * iocb to the txq when SLI layer cannot submit the command iocb
7548 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7549 struct lpfc_iocbq *piocb)
7551 /* Insert the caller's iocb in the txq tail for later processing. */
7552 list_add_tail(&piocb->list, &pring->txq);
7557 * lpfc_sli_next_iocb - Get the next iocb in the txq
7558 * @phba: Pointer to HBA context object.
7559 * @pring: Pointer to driver SLI ring object.
7560 * @piocb: Pointer to address of newly added command iocb.
7562 * This function is called with hbalock held before a new
7563 * iocb is submitted to the firmware. This function checks
7564 * txq to flush the iocbs in txq to Firmware before
7565 * submitting new iocbs to the Firmware.
7566 * If there are iocbs in the txq which need to be submitted
7567 * to firmware, lpfc_sli_next_iocb returns the first element
7568 * of the txq after dequeuing it from txq.
7569 * If there is no iocb in the txq then the function will return
7570 * *piocb and *piocb is set to NULL. Caller needs to check
7571 * *piocb to find if there are more commands in the txq.
7573 static struct lpfc_iocbq *
7574 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7575 struct lpfc_iocbq **piocb)
7577 struct lpfc_iocbq * nextiocb;
7579 nextiocb = lpfc_sli_ringtx_get(phba, pring);
7589 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7590 * @phba: Pointer to HBA context object.
7591 * @ring_number: SLI ring number to issue iocb on.
7592 * @piocb: Pointer to command iocb.
7593 * @flag: Flag indicating if this command can be put into txq.
7595 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7596 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7597 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7598 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7599 * this function allows only iocbs for posting buffers. This function finds
7600 * next available slot in the command ring and posts the command to the
7601 * available slot and writes the port attention register to request HBA start
7602 * processing new iocb. If there is no slot available in the ring and
7603 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7604 * the function returns IOCB_BUSY.
7606 * This function is called with hbalock held. The function will return success
7607 * after it successfully submit the iocb to firmware or after adding to the
7611 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
7612 struct lpfc_iocbq *piocb, uint32_t flag)
7614 struct lpfc_iocbq *nextiocb;
7616 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
7618 if (piocb->iocb_cmpl && (!piocb->vport) &&
7619 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
7620 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
7621 lpfc_printf_log(phba, KERN_ERR,
7622 LOG_SLI | LOG_VPORT,
7623 "1807 IOCB x%x failed. No vport\n",
7624 piocb->iocb.ulpCommand);
7630 /* If the PCI channel is in offline state, do not post iocbs. */
7631 if (unlikely(pci_channel_offline(phba->pcidev)))
7634 /* If HBA has a deferred error attention, fail the iocb. */
7635 if (unlikely(phba->hba_flag & DEFER_ERATT))
7639 * We should never get an IOCB if we are in a < LINK_DOWN state
7641 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
7645 * Check to see if we are blocking IOCB processing because of a
7646 * outstanding event.
7648 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
7651 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
7653 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7654 * can be issued if the link is not up.
7656 switch (piocb->iocb.ulpCommand) {
7657 case CMD_GEN_REQUEST64_CR:
7658 case CMD_GEN_REQUEST64_CX:
7659 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
7660 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
7661 FC_RCTL_DD_UNSOL_CMD) ||
7662 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
7663 MENLO_TRANSPORT_TYPE))
7667 case CMD_QUE_RING_BUF_CN:
7668 case CMD_QUE_RING_BUF64_CN:
7670 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7671 * completion, iocb_cmpl MUST be 0.
7673 if (piocb->iocb_cmpl)
7674 piocb->iocb_cmpl = NULL;
7676 case CMD_CREATE_XRI_CR:
7677 case CMD_CLOSE_XRI_CN:
7678 case CMD_CLOSE_XRI_CX:
7685 * For FCP commands, we must be in a state where we can process link
7688 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
7689 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
7693 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
7694 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
7695 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
7698 lpfc_sli_update_ring(phba, pring);
7700 lpfc_sli_update_full_ring(phba, pring);
7703 return IOCB_SUCCESS;
7708 pring->stats.iocb_cmd_delay++;
7712 if (!(flag & SLI_IOCB_RET_IOCB)) {
7713 __lpfc_sli_ringtx_put(phba, pring, piocb);
7714 return IOCB_SUCCESS;
7721 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7722 * @phba: Pointer to HBA context object.
7723 * @piocb: Pointer to command iocb.
7724 * @sglq: Pointer to the scatter gather queue object.
7726 * This routine converts the bpl or bde that is in the IOCB
7727 * to a sgl list for the sli4 hardware. The physical address
7728 * of the bpl/bde is converted back to a virtual address.
7729 * If the IOCB contains a BPL then the list of BDE's is
7730 * converted to sli4_sge's. If the IOCB contains a single
7731 * BDE then it is converted to a single sli_sge.
7732 * The IOCB is still in cpu endianess so the contents of
7733 * the bpl can be used without byte swapping.
7735 * Returns valid XRI = Success, NO_XRI = Failure.
7738 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
7739 struct lpfc_sglq *sglq)
7741 uint16_t xritag = NO_XRI;
7742 struct ulp_bde64 *bpl = NULL;
7743 struct ulp_bde64 bde;
7744 struct sli4_sge *sgl = NULL;
7745 struct lpfc_dmabuf *dmabuf;
7749 uint32_t offset = 0; /* accumulated offset in the sg request list */
7750 int inbound = 0; /* number of sg reply entries inbound from firmware */
7752 if (!piocbq || !sglq)
7755 sgl = (struct sli4_sge *)sglq->sgl;
7756 icmd = &piocbq->iocb;
7757 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
7758 return sglq->sli4_xritag;
7759 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
7760 numBdes = icmd->un.genreq64.bdl.bdeSize /
7761 sizeof(struct ulp_bde64);
7762 /* The addrHigh and addrLow fields within the IOCB
7763 * have not been byteswapped yet so there is no
7764 * need to swap them back.
7766 if (piocbq->context3)
7767 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
7771 bpl = (struct ulp_bde64 *)dmabuf->virt;
7775 for (i = 0; i < numBdes; i++) {
7776 /* Should already be byte swapped. */
7777 sgl->addr_hi = bpl->addrHigh;
7778 sgl->addr_lo = bpl->addrLow;
7780 sgl->word2 = le32_to_cpu(sgl->word2);
7781 if ((i+1) == numBdes)
7782 bf_set(lpfc_sli4_sge_last, sgl, 1);
7784 bf_set(lpfc_sli4_sge_last, sgl, 0);
7785 /* swap the size field back to the cpu so we
7786 * can assign it to the sgl.
7788 bde.tus.w = le32_to_cpu(bpl->tus.w);
7789 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
7790 /* The offsets in the sgl need to be accumulated
7791 * separately for the request and reply lists.
7792 * The request is always first, the reply follows.
7794 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
7795 /* add up the reply sg entries */
7796 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
7798 /* first inbound? reset the offset */
7801 bf_set(lpfc_sli4_sge_offset, sgl, offset);
7802 bf_set(lpfc_sli4_sge_type, sgl,
7803 LPFC_SGE_TYPE_DATA);
7804 offset += bde.tus.f.bdeSize;
7806 sgl->word2 = cpu_to_le32(sgl->word2);
7810 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
7811 /* The addrHigh and addrLow fields of the BDE have not
7812 * been byteswapped yet so they need to be swapped
7813 * before putting them in the sgl.
7816 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
7818 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
7819 sgl->word2 = le32_to_cpu(sgl->word2);
7820 bf_set(lpfc_sli4_sge_last, sgl, 1);
7821 sgl->word2 = cpu_to_le32(sgl->word2);
7823 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
7825 return sglq->sli4_xritag;
7829 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7830 * @phba: Pointer to HBA context object.
7832 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7833 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7836 * Return: index into SLI4 fast-path FCP queue index.
7838 static inline uint32_t
7839 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
7843 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU)
7844 i = smp_processor_id();
7846 i = atomic_add_return(1, &phba->fcp_qidx);
7848 i = (i % phba->cfg_fcp_io_channel);
7853 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7854 * @phba: Pointer to HBA context object.
7855 * @piocb: Pointer to command iocb.
7856 * @wqe: Pointer to the work queue entry.
7858 * This routine converts the iocb command to its Work Queue Entry
7859 * equivalent. The wqe pointer should not have any fields set when
7860 * this routine is called because it will memcpy over them.
7861 * This routine does not set the CQ_ID or the WQEC bits in the
7864 * Returns: 0 = Success, IOCB_ERROR = Failure.
7867 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
7868 union lpfc_wqe *wqe)
7870 uint32_t xmit_len = 0, total_len = 0;
7874 uint8_t command_type = ELS_COMMAND_NON_FIP;
7877 uint16_t abrt_iotag;
7878 struct lpfc_iocbq *abrtiocbq;
7879 struct ulp_bde64 *bpl = NULL;
7880 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
7882 struct ulp_bde64 bde;
7883 struct lpfc_nodelist *ndlp;
7887 fip = phba->hba_flag & HBA_FIP_SUPPORT;
7888 /* The fcp commands will set command type */
7889 if (iocbq->iocb_flag & LPFC_IO_FCP)
7890 command_type = FCP_COMMAND;
7891 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
7892 command_type = ELS_COMMAND_FIP;
7894 command_type = ELS_COMMAND_NON_FIP;
7896 /* Some of the fields are in the right position already */
7897 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
7898 abort_tag = (uint32_t) iocbq->iotag;
7899 xritag = iocbq->sli4_xritag;
7900 wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
7901 /* words0-2 bpl convert bde */
7902 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
7903 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
7904 sizeof(struct ulp_bde64);
7905 bpl = (struct ulp_bde64 *)
7906 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
7910 /* Should already be byte swapped. */
7911 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
7912 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
7913 /* swap the size field back to the cpu so we
7914 * can assign it to the sgl.
7916 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
7917 xmit_len = wqe->generic.bde.tus.f.bdeSize;
7919 for (i = 0; i < numBdes; i++) {
7920 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
7921 total_len += bde.tus.f.bdeSize;
7924 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
7926 iocbq->iocb.ulpIoTag = iocbq->iotag;
7927 cmnd = iocbq->iocb.ulpCommand;
7929 switch (iocbq->iocb.ulpCommand) {
7930 case CMD_ELS_REQUEST64_CR:
7931 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
7932 ndlp = iocbq->context_un.ndlp;
7934 ndlp = (struct lpfc_nodelist *)iocbq->context1;
7935 if (!iocbq->iocb.ulpLe) {
7936 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7937 "2007 Only Limited Edition cmd Format"
7938 " supported 0x%x\n",
7939 iocbq->iocb.ulpCommand);
7943 wqe->els_req.payload_len = xmit_len;
7944 /* Els_reguest64 has a TMO */
7945 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
7946 iocbq->iocb.ulpTimeout);
7947 /* Need a VF for word 4 set the vf bit*/
7948 bf_set(els_req64_vf, &wqe->els_req, 0);
7949 /* And a VFID for word 12 */
7950 bf_set(els_req64_vfid, &wqe->els_req, 0);
7951 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
7952 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
7953 iocbq->iocb.ulpContext);
7954 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
7955 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
7956 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7957 if (command_type == ELS_COMMAND_FIP)
7958 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
7959 >> LPFC_FIP_ELS_ID_SHIFT);
7960 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7961 iocbq->context2)->virt);
7962 if_type = bf_get(lpfc_sli_intf_if_type,
7963 &phba->sli4_hba.sli_intf);
7964 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7965 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
7966 *pcmd == ELS_CMD_SCR ||
7967 *pcmd == ELS_CMD_FDISC ||
7968 *pcmd == ELS_CMD_LOGO ||
7969 *pcmd == ELS_CMD_PLOGI)) {
7970 bf_set(els_req64_sp, &wqe->els_req, 1);
7971 bf_set(els_req64_sid, &wqe->els_req,
7972 iocbq->vport->fc_myDID);
7973 if ((*pcmd == ELS_CMD_FLOGI) &&
7974 !(phba->fc_topology ==
7975 LPFC_TOPOLOGY_LOOP))
7976 bf_set(els_req64_sid, &wqe->els_req, 0);
7977 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
7978 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
7979 phba->vpi_ids[iocbq->vport->vpi]);
7980 } else if (pcmd && iocbq->context1) {
7981 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
7982 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
7983 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
7986 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
7987 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
7988 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
7989 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
7990 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
7991 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
7992 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
7993 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
7995 case CMD_XMIT_SEQUENCE64_CX:
7996 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
7997 iocbq->iocb.un.ulpWord[3]);
7998 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
7999 iocbq->iocb.unsli3.rcvsli3.ox_id);
8000 /* The entire sequence is transmitted for this IOCB */
8001 xmit_len = total_len;
8002 cmnd = CMD_XMIT_SEQUENCE64_CR;
8003 if (phba->link_flag & LS_LOOPBACK_MODE)
8004 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
8005 case CMD_XMIT_SEQUENCE64_CR:
8006 /* word3 iocb=io_tag32 wqe=reserved */
8007 wqe->xmit_sequence.rsvd3 = 0;
8008 /* word4 relative_offset memcpy */
8009 /* word5 r_ctl/df_ctl memcpy */
8010 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
8011 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
8012 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
8013 LPFC_WQE_IOD_WRITE);
8014 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
8015 LPFC_WQE_LENLOC_WORD12);
8016 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
8017 wqe->xmit_sequence.xmit_len = xmit_len;
8018 command_type = OTHER_COMMAND;
8020 case CMD_XMIT_BCAST64_CN:
8021 /* word3 iocb=iotag32 wqe=seq_payload_len */
8022 wqe->xmit_bcast64.seq_payload_len = xmit_len;
8023 /* word4 iocb=rsvd wqe=rsvd */
8024 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8025 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8026 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
8027 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8028 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
8029 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
8030 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
8031 LPFC_WQE_LENLOC_WORD3);
8032 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
8034 case CMD_FCP_IWRITE64_CR:
8035 command_type = FCP_COMMAND_DATA_OUT;
8036 /* word3 iocb=iotag wqe=payload_offset_len */
8037 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8038 wqe->fcp_iwrite.payload_offset_len =
8039 xmit_len + sizeof(struct fcp_rsp);
8040 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8041 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8042 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
8043 iocbq->iocb.ulpFCP2Rcvy);
8044 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
8045 /* Always open the exchange */
8046 bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
8047 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
8048 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
8049 LPFC_WQE_LENLOC_WORD4);
8050 bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
8051 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
8052 if (iocbq->iocb_flag & LPFC_IO_DIF) {
8053 iocbq->iocb_flag &= ~LPFC_IO_DIF;
8054 bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
8056 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
8058 case CMD_FCP_IREAD64_CR:
8059 /* word3 iocb=iotag wqe=payload_offset_len */
8060 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8061 wqe->fcp_iread.payload_offset_len =
8062 xmit_len + sizeof(struct fcp_rsp);
8063 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8064 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8065 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
8066 iocbq->iocb.ulpFCP2Rcvy);
8067 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
8068 /* Always open the exchange */
8069 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
8070 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
8071 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
8072 LPFC_WQE_LENLOC_WORD4);
8073 bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
8074 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
8075 if (iocbq->iocb_flag & LPFC_IO_DIF) {
8076 iocbq->iocb_flag &= ~LPFC_IO_DIF;
8077 bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
8079 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
8081 case CMD_FCP_ICMND64_CR:
8082 /* word3 iocb=IO_TAG wqe=reserved */
8083 wqe->fcp_icmd.rsrvd3 = 0;
8084 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
8085 /* Always open the exchange */
8086 bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
8087 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
8088 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
8089 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
8090 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
8091 LPFC_WQE_LENLOC_NONE);
8092 bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
8094 case CMD_GEN_REQUEST64_CR:
8095 /* For this command calculate the xmit length of the
8099 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
8100 sizeof(struct ulp_bde64);
8101 for (i = 0; i < numBdes; i++) {
8102 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
8103 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
8105 xmit_len += bde.tus.f.bdeSize;
8107 /* word3 iocb=IO_TAG wqe=request_payload_len */
8108 wqe->gen_req.request_payload_len = xmit_len;
8109 /* word4 iocb=parameter wqe=relative_offset memcpy */
8110 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8111 /* word6 context tag copied in memcpy */
8112 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
8113 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
8114 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8115 "2015 Invalid CT %x command 0x%x\n",
8116 ct, iocbq->iocb.ulpCommand);
8119 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
8120 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
8121 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
8122 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
8123 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
8124 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
8125 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
8126 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
8127 command_type = OTHER_COMMAND;
8129 case CMD_XMIT_ELS_RSP64_CX:
8130 ndlp = (struct lpfc_nodelist *)iocbq->context1;
8131 /* words0-2 BDE memcpy */
8132 /* word3 iocb=iotag32 wqe=response_payload_len */
8133 wqe->xmit_els_rsp.response_payload_len = xmit_len;
8135 wqe->xmit_els_rsp.word4 = 0;
8136 /* word5 iocb=rsvd wge=did */
8137 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
8138 iocbq->iocb.un.xseq64.xmit_els_remoteID);
8140 if_type = bf_get(lpfc_sli_intf_if_type,
8141 &phba->sli4_hba.sli_intf);
8142 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8143 if (iocbq->vport->fc_flag & FC_PT2PT) {
8144 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
8145 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
8146 iocbq->vport->fc_myDID);
8147 if (iocbq->vport->fc_myDID == Fabric_DID) {
8149 &wqe->xmit_els_rsp.wqe_dest, 0);
8153 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
8154 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8155 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
8156 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8157 iocbq->iocb.unsli3.rcvsli3.ox_id);
8158 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
8159 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
8160 phba->vpi_ids[iocbq->vport->vpi]);
8161 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
8162 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
8163 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
8164 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
8165 LPFC_WQE_LENLOC_WORD3);
8166 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
8167 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
8168 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
8169 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8170 iocbq->context2)->virt);
8171 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8172 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
8173 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
8174 iocbq->vport->fc_myDID);
8175 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
8176 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
8177 phba->vpi_ids[phba->pport->vpi]);
8179 command_type = OTHER_COMMAND;
8181 case CMD_CLOSE_XRI_CN:
8182 case CMD_ABORT_XRI_CN:
8183 case CMD_ABORT_XRI_CX:
8184 /* words 0-2 memcpy should be 0 rserved */
8185 /* port will send abts */
8186 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
8187 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
8188 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
8189 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
8193 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
8195 * The link is down, or the command was ELS_FIP
8196 * so the fw does not need to send abts
8199 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
8201 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
8202 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
8203 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8204 wqe->abort_cmd.rsrvd5 = 0;
8205 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
8206 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8207 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
8209 * The abort handler will send us CMD_ABORT_XRI_CN or
8210 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8212 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
8213 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
8214 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
8215 LPFC_WQE_LENLOC_NONE);
8216 cmnd = CMD_ABORT_XRI_CX;
8217 command_type = OTHER_COMMAND;
8220 case CMD_XMIT_BLS_RSP64_CX:
8221 ndlp = (struct lpfc_nodelist *)iocbq->context1;
8222 /* As BLS ABTS RSP WQE is very different from other WQEs,
8223 * we re-construct this WQE here based on information in
8224 * iocbq from scratch.
8226 memset(wqe, 0, sizeof(union lpfc_wqe));
8227 /* OX_ID is invariable to who sent ABTS to CT exchange */
8228 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
8229 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
8230 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
8231 LPFC_ABTS_UNSOL_INT) {
8232 /* ABTS sent by initiator to CT exchange, the
8233 * RX_ID field will be filled with the newly
8234 * allocated responder XRI.
8236 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
8237 iocbq->sli4_xritag);
8239 /* ABTS sent by responder to CT exchange, the
8240 * RX_ID field will be filled with the responder
8243 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
8244 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
8246 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
8247 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
8250 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
8252 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
8253 iocbq->iocb.ulpContext);
8254 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
8255 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
8256 phba->vpi_ids[phba->pport->vpi]);
8257 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
8258 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
8259 LPFC_WQE_LENLOC_NONE);
8260 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8261 command_type = OTHER_COMMAND;
8262 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
8263 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
8264 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
8265 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
8266 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
8267 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
8268 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
8272 case CMD_XRI_ABORTED_CX:
8273 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
8274 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
8275 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
8276 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
8277 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
8279 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8280 "2014 Invalid command 0x%x\n",
8281 iocbq->iocb.ulpCommand);
8286 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
8287 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
8288 wqe->generic.wqe_com.abort_tag = abort_tag;
8289 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
8290 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
8291 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
8292 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
8297 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8298 * @phba: Pointer to HBA context object.
8299 * @ring_number: SLI ring number to issue iocb on.
8300 * @piocb: Pointer to command iocb.
8301 * @flag: Flag indicating if this command can be put into txq.
8303 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8304 * an iocb command to an HBA with SLI-4 interface spec.
8306 * This function is called with hbalock held. The function will return success
8307 * after it successfully submit the iocb to firmware or after adding to the
8311 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
8312 struct lpfc_iocbq *piocb, uint32_t flag)
8314 struct lpfc_sglq *sglq;
8316 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
8318 if (piocb->sli4_xritag == NO_XRI) {
8319 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8320 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
8323 if (pring->txq_cnt) {
8324 if (!(flag & SLI_IOCB_RET_IOCB)) {
8325 __lpfc_sli_ringtx_put(phba,
8327 return IOCB_SUCCESS;
8332 sglq = __lpfc_sli_get_sglq(phba, piocb);
8334 if (!(flag & SLI_IOCB_RET_IOCB)) {
8335 __lpfc_sli_ringtx_put(phba,
8338 return IOCB_SUCCESS;
8344 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
8345 /* These IO's already have an XRI and a mapped sgl. */
8349 * This is a continuation of a commandi,(CX) so this
8350 * sglq is on the active list
8352 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
8358 piocb->sli4_lxritag = sglq->sli4_lxritag;
8359 piocb->sli4_xritag = sglq->sli4_xritag;
8360 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
8364 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
8367 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
8368 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
8369 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
8373 if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
8376 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
8382 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8384 * This routine wraps the actual lockless version for issusing IOCB function
8385 * pointer from the lpfc_hba struct.
8388 * IOCB_ERROR - Error
8389 * IOCB_SUCCESS - Success
8393 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
8394 struct lpfc_iocbq *piocb, uint32_t flag)
8396 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
8400 * lpfc_sli_api_table_setup - Set up sli api function jump table
8401 * @phba: The hba struct for which this call is being executed.
8402 * @dev_grp: The HBA PCI-Device group number.
8404 * This routine sets up the SLI interface API function jump table in @phba
8406 * Returns: 0 - success, -ENODEV - failure.
8409 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8413 case LPFC_PCI_DEV_LP:
8414 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
8415 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
8417 case LPFC_PCI_DEV_OC:
8418 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
8419 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
8422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8423 "1419 Invalid HBA PCI-device group: 0x%x\n",
8428 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
8433 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8434 * @phba: Pointer to HBA context object.
8435 * @pring: Pointer to driver SLI ring object.
8436 * @piocb: Pointer to command iocb.
8437 * @flag: Flag indicating if this command can be put into txq.
8439 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8440 * function. This function gets the hbalock and calls
8441 * __lpfc_sli_issue_iocb function and will return the error returned
8442 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8443 * functions which do not hold hbalock.
8446 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
8447 struct lpfc_iocbq *piocb, uint32_t flag)
8449 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
8450 struct lpfc_sli_ring *pring;
8451 struct lpfc_queue *fpeq;
8452 struct lpfc_eqe *eqe;
8453 unsigned long iflags;
8456 if (phba->sli_rev == LPFC_SLI_REV4) {
8457 if (piocb->iocb_flag & LPFC_IO_FCP) {
8458 if (unlikely(!phba->sli4_hba.fcp_wq))
8460 idx = lpfc_sli4_scmd_to_wqidx_distr(phba);
8461 piocb->fcp_wqidx = idx;
8462 ring_number = MAX_SLI3_CONFIGURED_RINGS + idx;
8464 pring = &phba->sli.ring[ring_number];
8465 spin_lock_irqsave(&pring->ring_lock, iflags);
8466 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
8468 spin_unlock_irqrestore(&pring->ring_lock, iflags);
8470 if (lpfc_fcp_look_ahead) {
8471 fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
8473 if (atomic_dec_and_test(&fcp_eq_hdl->
8476 /* Get associated EQ with this index */
8477 fpeq = phba->sli4_hba.hba_eq[idx];
8479 /* Turn off interrupts from this EQ */
8480 lpfc_sli4_eq_clr_intr(fpeq);
8483 * Process all the events on FCP EQ
8485 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
8486 lpfc_sli4_hba_handle_eqe(phba,
8488 fpeq->EQ_processed++;
8491 /* Always clear and re-arm the EQ */
8492 lpfc_sli4_eq_release(fpeq,
8495 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
8498 pring = &phba->sli.ring[ring_number];
8499 spin_lock_irqsave(&pring->ring_lock, iflags);
8500 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
8502 spin_unlock_irqrestore(&pring->ring_lock, iflags);
8506 /* For now, SLI2/3 will still use hbalock */
8507 spin_lock_irqsave(&phba->hbalock, iflags);
8508 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
8509 spin_unlock_irqrestore(&phba->hbalock, iflags);
8515 * lpfc_extra_ring_setup - Extra ring setup function
8516 * @phba: Pointer to HBA context object.
8518 * This function is called while driver attaches with the
8519 * HBA to setup the extra ring. The extra ring is used
8520 * only when driver needs to support target mode functionality
8521 * or IP over FC functionalities.
8523 * This function is called with no lock held.
8526 lpfc_extra_ring_setup( struct lpfc_hba *phba)
8528 struct lpfc_sli *psli;
8529 struct lpfc_sli_ring *pring;
8533 /* Adjust cmd/rsp ring iocb entries more evenly */
8535 /* Take some away from the FCP ring */
8536 pring = &psli->ring[psli->fcp_ring];
8537 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
8538 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
8539 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
8540 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
8542 /* and give them to the extra ring */
8543 pring = &psli->ring[psli->extra_ring];
8545 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
8546 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
8547 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
8548 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
8550 /* Setup default profile for this ring */
8551 pring->iotag_max = 4096;
8552 pring->num_mask = 1;
8553 pring->prt[0].profile = 0; /* Mask 0 */
8554 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
8555 pring->prt[0].type = phba->cfg_multi_ring_type;
8556 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
8560 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8561 * @phba: Pointer to HBA context object.
8562 * @iocbq: Pointer to iocb object.
8564 * The async_event handler calls this routine when it receives
8565 * an ASYNC_STATUS_CN event from the port. The port generates
8566 * this event when an Abort Sequence request to an rport fails
8567 * twice in succession. The abort could be originated by the
8568 * driver or by the port. The ABTS could have been for an ELS
8569 * or FCP IO. The port only generates this event when an ABTS
8570 * fails to complete after one retry.
8573 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
8574 struct lpfc_iocbq *iocbq)
8576 struct lpfc_nodelist *ndlp = NULL;
8577 uint16_t rpi = 0, vpi = 0;
8578 struct lpfc_vport *vport = NULL;
8580 /* The rpi in the ulpContext is vport-sensitive. */
8581 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
8582 rpi = iocbq->iocb.ulpContext;
8584 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8585 "3092 Port generated ABTS async event "
8586 "on vpi %d rpi %d status 0x%x\n",
8587 vpi, rpi, iocbq->iocb.ulpStatus);
8589 vport = lpfc_find_vport_by_vpid(phba, vpi);
8592 ndlp = lpfc_findnode_rpi(vport, rpi);
8593 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8596 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
8597 lpfc_sli_abts_recover_port(vport, ndlp);
8601 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8602 "3095 Event Context not found, no "
8603 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8604 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
8608 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8609 * @phba: pointer to HBA context object.
8610 * @ndlp: nodelist pointer for the impacted rport.
8611 * @axri: pointer to the wcqe containing the failed exchange.
8613 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8614 * port. The port generates this event when an abort exchange request to an
8615 * rport fails twice in succession with no reply. The abort could be originated
8616 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8619 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
8620 struct lpfc_nodelist *ndlp,
8621 struct sli4_wcqe_xri_aborted *axri)
8623 struct lpfc_vport *vport;
8624 uint32_t ext_status = 0;
8626 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
8627 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8628 "3115 Node Context not found, driver "
8629 "ignoring abts err event\n");
8633 vport = ndlp->vport;
8634 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8635 "3116 Port generated FCP XRI ABORT event on "
8636 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8637 ndlp->vport->vpi, ndlp->nlp_rpi,
8638 bf_get(lpfc_wcqe_xa_xri, axri),
8639 bf_get(lpfc_wcqe_xa_status, axri),
8643 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8644 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8645 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8647 ext_status = axri->parameter & IOERR_PARAM_MASK;
8648 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
8649 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
8650 lpfc_sli_abts_recover_port(vport, ndlp);
8654 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8655 * @phba: Pointer to HBA context object.
8656 * @pring: Pointer to driver SLI ring object.
8657 * @iocbq: Pointer to iocb object.
8659 * This function is called by the slow ring event handler
8660 * function when there is an ASYNC event iocb in the ring.
8661 * This function is called with no lock held.
8662 * Currently this function handles only temperature related
8663 * ASYNC events. The function decodes the temperature sensor
8664 * event message and posts events for the management applications.
8667 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
8668 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
8672 struct temp_event temp_event_data;
8673 struct Scsi_Host *shost;
8676 icmd = &iocbq->iocb;
8677 evt_code = icmd->un.asyncstat.evt_code;
8680 case ASYNC_TEMP_WARN:
8681 case ASYNC_TEMP_SAFE:
8682 temp_event_data.data = (uint32_t) icmd->ulpContext;
8683 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
8684 if (evt_code == ASYNC_TEMP_WARN) {
8685 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
8686 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
8687 "0347 Adapter is very hot, please take "
8688 "corrective action. temperature : %d Celsius\n",
8689 (uint32_t) icmd->ulpContext);
8691 temp_event_data.event_code = LPFC_NORMAL_TEMP;
8692 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
8693 "0340 Adapter temperature is OK now. "
8694 "temperature : %d Celsius\n",
8695 (uint32_t) icmd->ulpContext);
8698 /* Send temperature change event to applications */
8699 shost = lpfc_shost_from_vport(phba->pport);
8700 fc_host_post_vendor_event(shost, fc_get_event_number(),
8701 sizeof(temp_event_data), (char *) &temp_event_data,
8704 case ASYNC_STATUS_CN:
8705 lpfc_sli_abts_err_handler(phba, iocbq);
8708 iocb_w = (uint32_t *) icmd;
8709 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8710 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8712 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8713 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8714 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8715 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8716 pring->ringno, icmd->un.asyncstat.evt_code,
8717 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
8718 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
8719 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
8720 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
8728 * lpfc_sli_setup - SLI ring setup function
8729 * @phba: Pointer to HBA context object.
8731 * lpfc_sli_setup sets up rings of the SLI interface with
8732 * number of iocbs per ring and iotags. This function is
8733 * called while driver attach to the HBA and before the
8734 * interrupts are enabled. So there is no need for locking.
8736 * This function always returns 0.
8739 lpfc_sli_setup(struct lpfc_hba *phba)
8741 int i, totiocbsize = 0;
8742 struct lpfc_sli *psli = &phba->sli;
8743 struct lpfc_sli_ring *pring;
8745 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
8746 if (phba->sli_rev == LPFC_SLI_REV4)
8747 psli->num_rings += phba->cfg_fcp_io_channel;
8749 psli->fcp_ring = LPFC_FCP_RING;
8750 psli->next_ring = LPFC_FCP_NEXT_RING;
8751 psli->extra_ring = LPFC_EXTRA_RING;
8753 psli->iocbq_lookup = NULL;
8754 psli->iocbq_lookup_len = 0;
8755 psli->last_iotag = 0;
8757 for (i = 0; i < psli->num_rings; i++) {
8758 pring = &psli->ring[i];
8760 case LPFC_FCP_RING: /* ring 0 - FCP */
8761 /* numCiocb and numRiocb are used in config_port */
8762 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
8763 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
8764 pring->sli.sli3.numCiocb +=
8765 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
8766 pring->sli.sli3.numRiocb +=
8767 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
8768 pring->sli.sli3.numCiocb +=
8769 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
8770 pring->sli.sli3.numRiocb +=
8771 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
8772 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
8773 SLI3_IOCB_CMD_SIZE :
8775 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
8776 SLI3_IOCB_RSP_SIZE :
8778 pring->iotag_ctr = 0;
8780 (phba->cfg_hba_queue_depth * 2);
8781 pring->fast_iotag = pring->iotag_max;
8782 pring->num_mask = 0;
8784 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
8785 /* numCiocb and numRiocb are used in config_port */
8786 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
8787 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
8788 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
8789 SLI3_IOCB_CMD_SIZE :
8791 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
8792 SLI3_IOCB_RSP_SIZE :
8794 pring->iotag_max = phba->cfg_hba_queue_depth;
8795 pring->num_mask = 0;
8797 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
8798 /* numCiocb and numRiocb are used in config_port */
8799 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
8800 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
8801 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
8802 SLI3_IOCB_CMD_SIZE :
8804 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
8805 SLI3_IOCB_RSP_SIZE :
8807 pring->fast_iotag = 0;
8808 pring->iotag_ctr = 0;
8809 pring->iotag_max = 4096;
8810 pring->lpfc_sli_rcv_async_status =
8811 lpfc_sli_async_event_handler;
8812 pring->num_mask = LPFC_MAX_RING_MASK;
8813 pring->prt[0].profile = 0; /* Mask 0 */
8814 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
8815 pring->prt[0].type = FC_TYPE_ELS;
8816 pring->prt[0].lpfc_sli_rcv_unsol_event =
8817 lpfc_els_unsol_event;
8818 pring->prt[1].profile = 0; /* Mask 1 */
8819 pring->prt[1].rctl = FC_RCTL_ELS_REP;
8820 pring->prt[1].type = FC_TYPE_ELS;
8821 pring->prt[1].lpfc_sli_rcv_unsol_event =
8822 lpfc_els_unsol_event;
8823 pring->prt[2].profile = 0; /* Mask 2 */
8824 /* NameServer Inquiry */
8825 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
8827 pring->prt[2].type = FC_TYPE_CT;
8828 pring->prt[2].lpfc_sli_rcv_unsol_event =
8829 lpfc_ct_unsol_event;
8830 pring->prt[3].profile = 0; /* Mask 3 */
8831 /* NameServer response */
8832 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
8834 pring->prt[3].type = FC_TYPE_CT;
8835 pring->prt[3].lpfc_sli_rcv_unsol_event =
8836 lpfc_ct_unsol_event;
8837 /* abort unsolicited sequence */
8838 pring->prt[4].profile = 0; /* Mask 4 */
8839 pring->prt[4].rctl = FC_RCTL_BA_ABTS;
8840 pring->prt[4].type = FC_TYPE_BLS;
8841 pring->prt[4].lpfc_sli_rcv_unsol_event =
8842 lpfc_sli4_ct_abort_unsol_event;
8845 totiocbsize += (pring->sli.sli3.numCiocb *
8846 pring->sli.sli3.sizeCiocb) +
8847 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
8849 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
8850 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8851 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
8852 "SLI2 SLIM Data: x%x x%lx\n",
8853 phba->brd_no, totiocbsize,
8854 (unsigned long) MAX_SLIM_IOCB_SIZE);
8856 if (phba->cfg_multi_ring_support == 2)
8857 lpfc_extra_ring_setup(phba);
8863 * lpfc_sli_queue_setup - Queue initialization function
8864 * @phba: Pointer to HBA context object.
8866 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8867 * ring. This function also initializes ring indices of each ring.
8868 * This function is called during the initialization of the SLI
8869 * interface of an HBA.
8870 * This function is called with no lock held and always returns
8874 lpfc_sli_queue_setup(struct lpfc_hba *phba)
8876 struct lpfc_sli *psli;
8877 struct lpfc_sli_ring *pring;
8881 spin_lock_irq(&phba->hbalock);
8882 INIT_LIST_HEAD(&psli->mboxq);
8883 INIT_LIST_HEAD(&psli->mboxq_cmpl);
8884 /* Initialize list headers for txq and txcmplq as double linked lists */
8885 for (i = 0; i < psli->num_rings; i++) {
8886 pring = &psli->ring[i];
8888 pring->sli.sli3.next_cmdidx = 0;
8889 pring->sli.sli3.local_getidx = 0;
8890 pring->sli.sli3.cmdidx = 0;
8891 INIT_LIST_HEAD(&pring->txq);
8892 INIT_LIST_HEAD(&pring->txcmplq);
8893 INIT_LIST_HEAD(&pring->iocb_continueq);
8894 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
8895 INIT_LIST_HEAD(&pring->postbufq);
8896 spin_lock_init(&pring->ring_lock);
8898 spin_unlock_irq(&phba->hbalock);
8903 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8904 * @phba: Pointer to HBA context object.
8906 * This routine flushes the mailbox command subsystem. It will unconditionally
8907 * flush all the mailbox commands in the three possible stages in the mailbox
8908 * command sub-system: pending mailbox command queue; the outstanding mailbox
8909 * command; and completed mailbox command queue. It is caller's responsibility
8910 * to make sure that the driver is in the proper state to flush the mailbox
8911 * command sub-system. Namely, the posting of mailbox commands into the
8912 * pending mailbox command queue from the various clients must be stopped;
8913 * either the HBA is in a state that it will never works on the outstanding
8914 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8915 * mailbox command has been completed.
8918 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
8920 LIST_HEAD(completions);
8921 struct lpfc_sli *psli = &phba->sli;
8923 unsigned long iflag;
8925 /* Flush all the mailbox commands in the mbox system */
8926 spin_lock_irqsave(&phba->hbalock, iflag);
8927 /* The pending mailbox command queue */
8928 list_splice_init(&phba->sli.mboxq, &completions);
8929 /* The outstanding active mailbox command */
8930 if (psli->mbox_active) {
8931 list_add_tail(&psli->mbox_active->list, &completions);
8932 psli->mbox_active = NULL;
8933 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8935 /* The completed mailbox command queue */
8936 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
8937 spin_unlock_irqrestore(&phba->hbalock, iflag);
8939 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8940 while (!list_empty(&completions)) {
8941 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
8942 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
8944 pmb->mbox_cmpl(phba, pmb);
8949 * lpfc_sli_host_down - Vport cleanup function
8950 * @vport: Pointer to virtual port object.
8952 * lpfc_sli_host_down is called to clean up the resources
8953 * associated with a vport before destroying virtual
8954 * port data structures.
8955 * This function does following operations:
8956 * - Free discovery resources associated with this virtual
8958 * - Free iocbs associated with this virtual port in
8960 * - Send abort for all iocb commands associated with this
8963 * This function is called with no lock held and always returns 1.
8966 lpfc_sli_host_down(struct lpfc_vport *vport)
8968 LIST_HEAD(completions);
8969 struct lpfc_hba *phba = vport->phba;
8970 struct lpfc_sli *psli = &phba->sli;
8971 struct lpfc_sli_ring *pring;
8972 struct lpfc_iocbq *iocb, *next_iocb;
8974 unsigned long flags = 0;
8975 uint16_t prev_pring_flag;
8977 lpfc_cleanup_discovery_resources(vport);
8979 spin_lock_irqsave(&phba->hbalock, flags);
8980 for (i = 0; i < psli->num_rings; i++) {
8981 pring = &psli->ring[i];
8982 prev_pring_flag = pring->flag;
8983 /* Only slow rings */
8984 if (pring->ringno == LPFC_ELS_RING) {
8985 pring->flag |= LPFC_DEFERRED_RING_EVENT;
8986 /* Set the lpfc data pending flag */
8987 set_bit(LPFC_DATA_READY, &phba->data_flags);
8990 * Error everything on the txq since these iocbs have not been
8991 * given to the FW yet.
8993 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
8994 if (iocb->vport != vport)
8996 list_move_tail(&iocb->list, &completions);
9000 /* Next issue ABTS for everything on the txcmplq */
9001 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
9003 if (iocb->vport != vport)
9005 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
9008 pring->flag = prev_pring_flag;
9011 spin_unlock_irqrestore(&phba->hbalock, flags);
9013 /* Cancel all the IOCBs from the completions list */
9014 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9020 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9021 * @phba: Pointer to HBA context object.
9023 * This function cleans up all iocb, buffers, mailbox commands
9024 * while shutting down the HBA. This function is called with no
9025 * lock held and always returns 1.
9026 * This function does the following to cleanup driver resources:
9027 * - Free discovery resources for each virtual port
9028 * - Cleanup any pending fabric iocbs
9029 * - Iterate through the iocb txq and free each entry
9031 * - Free up any buffer posted to the HBA
9032 * - Free mailbox commands in the mailbox queue.
9035 lpfc_sli_hba_down(struct lpfc_hba *phba)
9037 LIST_HEAD(completions);
9038 struct lpfc_sli *psli = &phba->sli;
9039 struct lpfc_sli_ring *pring;
9040 struct lpfc_dmabuf *buf_ptr;
9041 unsigned long flags = 0;
9044 /* Shutdown the mailbox command sub-system */
9045 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
9047 lpfc_hba_down_prep(phba);
9049 lpfc_fabric_abort_hba(phba);
9051 spin_lock_irqsave(&phba->hbalock, flags);
9052 for (i = 0; i < psli->num_rings; i++) {
9053 pring = &psli->ring[i];
9054 /* Only slow rings */
9055 if (pring->ringno == LPFC_ELS_RING) {
9056 pring->flag |= LPFC_DEFERRED_RING_EVENT;
9057 /* Set the lpfc data pending flag */
9058 set_bit(LPFC_DATA_READY, &phba->data_flags);
9062 * Error everything on the txq since these iocbs have not been
9063 * given to the FW yet.
9065 list_splice_init(&pring->txq, &completions);
9069 spin_unlock_irqrestore(&phba->hbalock, flags);
9071 /* Cancel all the IOCBs from the completions list */
9072 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9075 spin_lock_irqsave(&phba->hbalock, flags);
9076 list_splice_init(&phba->elsbuf, &completions);
9077 phba->elsbuf_cnt = 0;
9078 phba->elsbuf_prev_cnt = 0;
9079 spin_unlock_irqrestore(&phba->hbalock, flags);
9081 while (!list_empty(&completions)) {
9082 list_remove_head(&completions, buf_ptr,
9083 struct lpfc_dmabuf, list);
9084 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
9088 /* Return any active mbox cmds */
9089 del_timer_sync(&psli->mbox_tmo);
9091 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
9092 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
9093 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
9099 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9100 * @srcp: Source memory pointer.
9101 * @destp: Destination memory pointer.
9102 * @cnt: Number of words required to be copied.
9104 * This function is used for copying data between driver memory
9105 * and the SLI memory. This function also changes the endianness
9106 * of each word if native endianness is different from SLI
9107 * endianness. This function can be called with or without
9111 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
9113 uint32_t *src = srcp;
9114 uint32_t *dest = destp;
9118 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
9120 ldata = le32_to_cpu(ldata);
9129 * lpfc_sli_bemem_bcopy - SLI memory copy function
9130 * @srcp: Source memory pointer.
9131 * @destp: Destination memory pointer.
9132 * @cnt: Number of words required to be copied.
9134 * This function is used for copying data between a data structure
9135 * with big endian representation to local endianness.
9136 * This function can be called with or without lock.
9139 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
9141 uint32_t *src = srcp;
9142 uint32_t *dest = destp;
9146 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
9148 ldata = be32_to_cpu(ldata);
9156 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9157 * @phba: Pointer to HBA context object.
9158 * @pring: Pointer to driver SLI ring object.
9159 * @mp: Pointer to driver buffer object.
9161 * This function is called with no lock held.
9162 * It always return zero after adding the buffer to the postbufq
9166 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9167 struct lpfc_dmabuf *mp)
9169 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9171 spin_lock_irq(&phba->hbalock);
9172 list_add_tail(&mp->list, &pring->postbufq);
9173 pring->postbufq_cnt++;
9174 spin_unlock_irq(&phba->hbalock);
9179 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9180 * @phba: Pointer to HBA context object.
9182 * When HBQ is enabled, buffers are searched based on tags. This function
9183 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9184 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9185 * does not conflict with tags of buffer posted for unsolicited events.
9186 * The function returns the allocated tag. The function is called with
9190 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
9192 spin_lock_irq(&phba->hbalock);
9193 phba->buffer_tag_count++;
9195 * Always set the QUE_BUFTAG_BIT to distiguish between
9196 * a tag assigned by HBQ.
9198 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
9199 spin_unlock_irq(&phba->hbalock);
9200 return phba->buffer_tag_count;
9204 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9205 * @phba: Pointer to HBA context object.
9206 * @pring: Pointer to driver SLI ring object.
9209 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9210 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9211 * iocb is posted to the response ring with the tag of the buffer.
9212 * This function searches the pring->postbufq list using the tag
9213 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9214 * iocb. If the buffer is found then lpfc_dmabuf object of the
9215 * buffer is returned to the caller else NULL is returned.
9216 * This function is called with no lock held.
9218 struct lpfc_dmabuf *
9219 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9222 struct lpfc_dmabuf *mp, *next_mp;
9223 struct list_head *slp = &pring->postbufq;
9225 /* Search postbufq, from the beginning, looking for a match on tag */
9226 spin_lock_irq(&phba->hbalock);
9227 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
9228 if (mp->buffer_tag == tag) {
9229 list_del_init(&mp->list);
9230 pring->postbufq_cnt--;
9231 spin_unlock_irq(&phba->hbalock);
9236 spin_unlock_irq(&phba->hbalock);
9237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9238 "0402 Cannot find virtual addr for buffer tag on "
9239 "ring %d Data x%lx x%p x%p x%x\n",
9240 pring->ringno, (unsigned long) tag,
9241 slp->next, slp->prev, pring->postbufq_cnt);
9247 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9248 * @phba: Pointer to HBA context object.
9249 * @pring: Pointer to driver SLI ring object.
9250 * @phys: DMA address of the buffer.
9252 * This function searches the buffer list using the dma_address
9253 * of unsolicited event to find the driver's lpfc_dmabuf object
9254 * corresponding to the dma_address. The function returns the
9255 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9256 * This function is called by the ct and els unsolicited event
9257 * handlers to get the buffer associated with the unsolicited
9260 * This function is called with no lock held.
9262 struct lpfc_dmabuf *
9263 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9266 struct lpfc_dmabuf *mp, *next_mp;
9267 struct list_head *slp = &pring->postbufq;
9269 /* Search postbufq, from the beginning, looking for a match on phys */
9270 spin_lock_irq(&phba->hbalock);
9271 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
9272 if (mp->phys == phys) {
9273 list_del_init(&mp->list);
9274 pring->postbufq_cnt--;
9275 spin_unlock_irq(&phba->hbalock);
9280 spin_unlock_irq(&phba->hbalock);
9281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9282 "0410 Cannot find virtual addr for mapped buf on "
9283 "ring %d Data x%llx x%p x%p x%x\n",
9284 pring->ringno, (unsigned long long)phys,
9285 slp->next, slp->prev, pring->postbufq_cnt);
9290 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9291 * @phba: Pointer to HBA context object.
9292 * @cmdiocb: Pointer to driver command iocb object.
9293 * @rspiocb: Pointer to driver response iocb object.
9295 * This function is the completion handler for the abort iocbs for
9296 * ELS commands. This function is called from the ELS ring event
9297 * handler with no lock held. This function frees memory resources
9298 * associated with the abort iocb.
9301 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9302 struct lpfc_iocbq *rspiocb)
9304 IOCB_t *irsp = &rspiocb->iocb;
9305 uint16_t abort_iotag, abort_context;
9306 struct lpfc_iocbq *abort_iocb = NULL;
9308 if (irsp->ulpStatus) {
9311 * Assume that the port already completed and returned, or
9312 * will return the iocb. Just Log the message.
9314 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
9315 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
9317 spin_lock_irq(&phba->hbalock);
9318 if (phba->sli_rev < LPFC_SLI_REV4) {
9319 if (abort_iotag != 0 &&
9320 abort_iotag <= phba->sli.last_iotag)
9322 phba->sli.iocbq_lookup[abort_iotag];
9324 /* For sli4 the abort_tag is the XRI,
9325 * so the abort routine puts the iotag of the iocb
9326 * being aborted in the context field of the abort
9329 abort_iocb = phba->sli.iocbq_lookup[abort_context];
9331 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
9332 "0327 Cannot abort els iocb %p "
9333 "with tag %x context %x, abort status %x, "
9335 abort_iocb, abort_iotag, abort_context,
9336 irsp->ulpStatus, irsp->un.ulpWord[4]);
9338 spin_unlock_irq(&phba->hbalock);
9340 lpfc_sli_release_iocbq(phba, cmdiocb);
9345 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9346 * @phba: Pointer to HBA context object.
9347 * @cmdiocb: Pointer to driver command iocb object.
9348 * @rspiocb: Pointer to driver response iocb object.
9350 * The function is called from SLI ring event handler with no
9351 * lock held. This function is the completion handler for ELS commands
9352 * which are aborted. The function frees memory resources used for
9353 * the aborted ELS commands.
9356 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9357 struct lpfc_iocbq *rspiocb)
9359 IOCB_t *irsp = &rspiocb->iocb;
9361 /* ELS cmd tag <ulpIoTag> completes */
9362 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9363 "0139 Ignoring ELS cmd tag x%x completion Data: "
9365 irsp->ulpIoTag, irsp->ulpStatus,
9366 irsp->un.ulpWord[4], irsp->ulpTimeout);
9367 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
9368 lpfc_ct_free_iocb(phba, cmdiocb);
9370 lpfc_els_free_iocb(phba, cmdiocb);
9375 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9376 * @phba: Pointer to HBA context object.
9377 * @pring: Pointer to driver SLI ring object.
9378 * @cmdiocb: Pointer to driver command iocb object.
9380 * This function issues an abort iocb for the provided command iocb down to
9381 * the port. Other than the case the outstanding command iocb is an abort
9382 * request, this function issues abort out unconditionally. This function is
9383 * called with hbalock held. The function returns 0 when it fails due to
9384 * memory allocation failure or when the command iocb is an abort request.
9387 lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9388 struct lpfc_iocbq *cmdiocb)
9390 struct lpfc_vport *vport = cmdiocb->vport;
9391 struct lpfc_iocbq *abtsiocbp;
9392 IOCB_t *icmd = NULL;
9393 IOCB_t *iabt = NULL;
9395 unsigned long iflags;
9398 * There are certain command types we don't want to abort. And we
9399 * don't want to abort commands that are already in the process of
9402 icmd = &cmdiocb->iocb;
9403 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
9404 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
9405 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
9408 /* issue ABTS for this IOCB based on iotag */
9409 abtsiocbp = __lpfc_sli_get_iocbq(phba);
9410 if (abtsiocbp == NULL)
9413 /* This signals the response to set the correct status
9414 * before calling the completion handler
9416 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
9418 iabt = &abtsiocbp->iocb;
9419 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
9420 iabt->un.acxri.abortContextTag = icmd->ulpContext;
9421 if (phba->sli_rev == LPFC_SLI_REV4) {
9422 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
9423 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
9426 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
9428 iabt->ulpClass = icmd->ulpClass;
9430 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9431 abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
9432 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
9433 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
9435 if (phba->link_state >= LPFC_LINK_UP)
9436 iabt->ulpCommand = CMD_ABORT_XRI_CN;
9438 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
9440 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
9442 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
9443 "0339 Abort xri x%x, original iotag x%x, "
9444 "abort cmd iotag x%x\n",
9445 iabt->un.acxri.abortIoTag,
9446 iabt->un.acxri.abortContextTag,
9449 if (phba->sli_rev == LPFC_SLI_REV4) {
9450 /* Note: both hbalock and ring_lock need to be set here */
9451 spin_lock_irqsave(&pring->ring_lock, iflags);
9452 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
9454 spin_unlock_irqrestore(&pring->ring_lock, iflags);
9456 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
9461 __lpfc_sli_release_iocbq(phba, abtsiocbp);
9464 * Caller to this routine should check for IOCB_ERROR
9465 * and handle it properly. This routine no longer removes
9466 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9472 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9473 * @phba: Pointer to HBA context object.
9474 * @pring: Pointer to driver SLI ring object.
9475 * @cmdiocb: Pointer to driver command iocb object.
9477 * This function issues an abort iocb for the provided command iocb. In case
9478 * of unloading, the abort iocb will not be issued to commands on the ELS
9479 * ring. Instead, the callback function shall be changed to those commands
9480 * so that nothing happens when them finishes. This function is called with
9481 * hbalock held. The function returns 0 when the command iocb is an abort
9485 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9486 struct lpfc_iocbq *cmdiocb)
9488 struct lpfc_vport *vport = cmdiocb->vport;
9489 int retval = IOCB_ERROR;
9490 IOCB_t *icmd = NULL;
9493 * There are certain command types we don't want to abort. And we
9494 * don't want to abort commands that are already in the process of
9497 icmd = &cmdiocb->iocb;
9498 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
9499 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
9500 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
9504 * If we're unloading, don't abort iocb on the ELS ring, but change
9505 * the callback so that nothing happens when it finishes.
9507 if ((vport->load_flag & FC_UNLOADING) &&
9508 (pring->ringno == LPFC_ELS_RING)) {
9509 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
9510 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
9512 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
9513 goto abort_iotag_exit;
9516 /* Now, we try to issue the abort to the cmdiocb out */
9517 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
9521 * Caller to this routine should check for IOCB_ERROR
9522 * and handle it properly. This routine no longer removes
9523 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9529 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9530 * @phba: Pointer to HBA context object.
9531 * @pring: Pointer to driver SLI ring object.
9533 * This function aborts all iocbs in the given ring and frees all the iocb
9534 * objects in txq. This function issues abort iocbs unconditionally for all
9535 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9536 * to complete before the return of this function. The caller is not required
9537 * to hold any locks.
9540 lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
9542 LIST_HEAD(completions);
9543 struct lpfc_iocbq *iocb, *next_iocb;
9545 if (pring->ringno == LPFC_ELS_RING)
9546 lpfc_fabric_abort_hba(phba);
9548 spin_lock_irq(&phba->hbalock);
9550 /* Take off all the iocbs on txq for cancelling */
9551 list_splice_init(&pring->txq, &completions);
9554 /* Next issue ABTS for everything on the txcmplq */
9555 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
9556 lpfc_sli_abort_iotag_issue(phba, pring, iocb);
9558 spin_unlock_irq(&phba->hbalock);
9560 /* Cancel all the IOCBs from the completions list */
9561 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9566 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9567 * @phba: pointer to lpfc HBA data structure.
9569 * This routine will abort all pending and outstanding iocbs to an HBA.
9572 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
9574 struct lpfc_sli *psli = &phba->sli;
9575 struct lpfc_sli_ring *pring;
9578 for (i = 0; i < psli->num_rings; i++) {
9579 pring = &psli->ring[i];
9580 lpfc_sli_iocb_ring_abort(phba, pring);
9585 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9586 * @iocbq: Pointer to driver iocb object.
9587 * @vport: Pointer to driver virtual port object.
9588 * @tgt_id: SCSI ID of the target.
9589 * @lun_id: LUN ID of the scsi device.
9590 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9592 * This function acts as an iocb filter for functions which abort or count
9593 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9594 * 0 if the filtering criteria is met for the given iocb and will return
9595 * 1 if the filtering criteria is not met.
9596 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9597 * given iocb is for the SCSI device specified by vport, tgt_id and
9599 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9600 * given iocb is for the SCSI target specified by vport and tgt_id
9602 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9603 * given iocb is for the SCSI host associated with the given vport.
9604 * This function is called with no locks held.
9607 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
9608 uint16_t tgt_id, uint64_t lun_id,
9609 lpfc_ctx_cmd ctx_cmd)
9611 struct lpfc_scsi_buf *lpfc_cmd;
9614 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
9617 if (iocbq->vport != vport)
9620 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
9622 if (lpfc_cmd->pCmd == NULL)
9627 if ((lpfc_cmd->rdata->pnode) &&
9628 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
9629 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
9633 if ((lpfc_cmd->rdata->pnode) &&
9634 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
9641 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
9650 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9651 * @vport: Pointer to virtual port.
9652 * @tgt_id: SCSI ID of the target.
9653 * @lun_id: LUN ID of the scsi device.
9654 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9656 * This function returns number of FCP commands pending for the vport.
9657 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9658 * commands pending on the vport associated with SCSI device specified
9659 * by tgt_id and lun_id parameters.
9660 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9661 * commands pending on the vport associated with SCSI target specified
9662 * by tgt_id parameter.
9663 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9664 * commands pending on the vport.
9665 * This function returns the number of iocbs which satisfy the filter.
9666 * This function is called without any lock held.
9669 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
9670 lpfc_ctx_cmd ctx_cmd)
9672 struct lpfc_hba *phba = vport->phba;
9673 struct lpfc_iocbq *iocbq;
9676 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
9677 iocbq = phba->sli.iocbq_lookup[i];
9679 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
9688 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9689 * @phba: Pointer to HBA context object
9690 * @cmdiocb: Pointer to command iocb object.
9691 * @rspiocb: Pointer to response iocb object.
9693 * This function is called when an aborted FCP iocb completes. This
9694 * function is called by the ring event handler with no lock held.
9695 * This function frees the iocb.
9698 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9699 struct lpfc_iocbq *rspiocb)
9701 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9702 "3096 ABORT_XRI_CN completing on xri x%x "
9703 "original iotag x%x, abort cmd iotag x%x "
9704 "status 0x%x, reason 0x%x\n",
9705 cmdiocb->iocb.un.acxri.abortContextTag,
9706 cmdiocb->iocb.un.acxri.abortIoTag,
9707 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
9708 rspiocb->iocb.un.ulpWord[4]);
9709 lpfc_sli_release_iocbq(phba, cmdiocb);
9714 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9715 * @vport: Pointer to virtual port.
9716 * @pring: Pointer to driver SLI ring object.
9717 * @tgt_id: SCSI ID of the target.
9718 * @lun_id: LUN ID of the scsi device.
9719 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9721 * This function sends an abort command for every SCSI command
9722 * associated with the given virtual port pending on the ring
9723 * filtered by lpfc_sli_validate_fcp_iocb function.
9724 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9725 * FCP iocbs associated with lun specified by tgt_id and lun_id
9727 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9728 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9729 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9730 * FCP iocbs associated with virtual port.
9731 * This function returns number of iocbs it failed to abort.
9732 * This function is called with no locks held.
9735 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
9736 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
9738 struct lpfc_hba *phba = vport->phba;
9739 struct lpfc_iocbq *iocbq;
9740 struct lpfc_iocbq *abtsiocb;
9742 int errcnt = 0, ret_val = 0;
9745 for (i = 1; i <= phba->sli.last_iotag; i++) {
9746 iocbq = phba->sli.iocbq_lookup[i];
9748 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
9752 /* issue ABTS for this IOCB based on iotag */
9753 abtsiocb = lpfc_sli_get_iocbq(phba);
9754 if (abtsiocb == NULL) {
9760 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
9761 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
9762 if (phba->sli_rev == LPFC_SLI_REV4)
9763 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
9765 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
9766 abtsiocb->iocb.ulpLe = 1;
9767 abtsiocb->iocb.ulpClass = cmd->ulpClass;
9768 abtsiocb->vport = phba->pport;
9770 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9771 abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
9772 if (iocbq->iocb_flag & LPFC_IO_FCP)
9773 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
9775 if (lpfc_is_link_up(phba))
9776 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
9778 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
9780 /* Setup callback routine and issue the command. */
9781 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
9782 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
9784 if (ret_val == IOCB_ERROR) {
9785 lpfc_sli_release_iocbq(phba, abtsiocb);
9795 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9796 * @phba: Pointer to HBA context object.
9797 * @cmdiocbq: Pointer to command iocb.
9798 * @rspiocbq: Pointer to response iocb.
9800 * This function is the completion handler for iocbs issued using
9801 * lpfc_sli_issue_iocb_wait function. This function is called by the
9802 * ring event handler function without any lock held. This function
9803 * can be called from both worker thread context and interrupt
9804 * context. This function also can be called from other thread which
9805 * cleans up the SLI layer objects.
9806 * This function copy the contents of the response iocb to the
9807 * response iocb memory object provided by the caller of
9808 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9809 * sleeps for the iocb completion.
9812 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
9813 struct lpfc_iocbq *cmdiocbq,
9814 struct lpfc_iocbq *rspiocbq)
9816 wait_queue_head_t *pdone_q;
9817 unsigned long iflags;
9818 struct lpfc_scsi_buf *lpfc_cmd;
9820 spin_lock_irqsave(&phba->hbalock, iflags);
9821 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
9822 if (cmdiocbq->context2 && rspiocbq)
9823 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
9824 &rspiocbq->iocb, sizeof(IOCB_t));
9826 /* Set the exchange busy flag for task management commands */
9827 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
9828 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
9829 lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
9831 lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
9834 pdone_q = cmdiocbq->context_un.wait_queue;
9837 spin_unlock_irqrestore(&phba->hbalock, iflags);
9842 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9843 * @phba: Pointer to HBA context object..
9844 * @piocbq: Pointer to command iocb.
9845 * @flag: Flag to test.
9847 * This routine grabs the hbalock and then test the iocb_flag to
9848 * see if the passed in flag is set.
9851 * 0 if flag is not set.
9854 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
9855 struct lpfc_iocbq *piocbq, uint32_t flag)
9857 unsigned long iflags;
9860 spin_lock_irqsave(&phba->hbalock, iflags);
9861 ret = piocbq->iocb_flag & flag;
9862 spin_unlock_irqrestore(&phba->hbalock, iflags);
9868 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9869 * @phba: Pointer to HBA context object..
9870 * @pring: Pointer to sli ring.
9871 * @piocb: Pointer to command iocb.
9872 * @prspiocbq: Pointer to response iocb.
9873 * @timeout: Timeout in number of seconds.
9875 * This function issues the iocb to firmware and waits for the
9876 * iocb to complete. If the iocb command is not
9877 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9878 * Caller should not free the iocb resources if this function
9879 * returns IOCB_TIMEDOUT.
9880 * The function waits for the iocb completion using an
9881 * non-interruptible wait.
9882 * This function will sleep while waiting for iocb completion.
9883 * So, this function should not be called from any context which
9884 * does not allow sleeping. Due to the same reason, this function
9885 * cannot be called with interrupt disabled.
9886 * This function assumes that the iocb completions occur while
9887 * this function sleep. So, this function cannot be called from
9888 * the thread which process iocb completion for this ring.
9889 * This function clears the iocb_flag of the iocb object before
9890 * issuing the iocb and the iocb completion handler sets this
9891 * flag and wakes this thread when the iocb completes.
9892 * The contents of the response iocb will be copied to prspiocbq
9893 * by the completion handler when the command completes.
9894 * This function returns IOCB_SUCCESS when success.
9895 * This function is called with no lock held.
9898 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
9899 uint32_t ring_number,
9900 struct lpfc_iocbq *piocb,
9901 struct lpfc_iocbq *prspiocbq,
9904 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
9905 long timeleft, timeout_req = 0;
9906 int retval = IOCB_SUCCESS;
9908 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
9910 * If the caller has provided a response iocbq buffer, then context2
9911 * is NULL or its an error.
9914 if (piocb->context2)
9916 piocb->context2 = prspiocbq;
9919 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
9920 piocb->context_un.wait_queue = &done_q;
9921 piocb->iocb_flag &= ~LPFC_IO_WAKE;
9923 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9924 if (lpfc_readl(phba->HCregaddr, &creg_val))
9926 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
9927 writel(creg_val, phba->HCregaddr);
9928 readl(phba->HCregaddr); /* flush */
9931 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
9933 if (retval == IOCB_SUCCESS) {
9934 timeout_req = timeout * HZ;
9935 timeleft = wait_event_timeout(done_q,
9936 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
9939 if (piocb->iocb_flag & LPFC_IO_WAKE) {
9940 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9941 "0331 IOCB wake signaled\n");
9942 } else if (timeleft == 0) {
9943 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9944 "0338 IOCB wait timeout error - no "
9945 "wake response Data x%x\n", timeout);
9946 retval = IOCB_TIMEDOUT;
9948 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9949 "0330 IOCB wake NOT set, "
9951 timeout, (timeleft / jiffies));
9952 retval = IOCB_TIMEDOUT;
9954 } else if (retval == IOCB_BUSY) {
9955 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9956 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
9957 phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
9960 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9961 "0332 IOCB wait issue failed, Data x%x\n",
9963 retval = IOCB_ERROR;
9966 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9967 if (lpfc_readl(phba->HCregaddr, &creg_val))
9969 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
9970 writel(creg_val, phba->HCregaddr);
9971 readl(phba->HCregaddr); /* flush */
9975 piocb->context2 = NULL;
9977 piocb->context_un.wait_queue = NULL;
9978 piocb->iocb_cmpl = NULL;
9983 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
9984 * @phba: Pointer to HBA context object.
9985 * @pmboxq: Pointer to driver mailbox object.
9986 * @timeout: Timeout in number of seconds.
9988 * This function issues the mailbox to firmware and waits for the
9989 * mailbox command to complete. If the mailbox command is not
9990 * completed within timeout seconds, it returns MBX_TIMEOUT.
9991 * The function waits for the mailbox completion using an
9992 * interruptible wait. If the thread is woken up due to a
9993 * signal, MBX_TIMEOUT error is returned to the caller. Caller
9994 * should not free the mailbox resources, if this function returns
9996 * This function will sleep while waiting for mailbox completion.
9997 * So, this function should not be called from any context which
9998 * does not allow sleeping. Due to the same reason, this function
9999 * cannot be called with interrupt disabled.
10000 * This function assumes that the mailbox completion occurs while
10001 * this function sleep. So, this function cannot be called from
10002 * the worker thread which processes mailbox completion.
10003 * This function is called in the context of HBA management
10005 * This function returns MBX_SUCCESS when successful.
10006 * This function is called with no lock held.
10009 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
10012 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
10014 unsigned long flag;
10016 /* The caller must leave context1 empty. */
10017 if (pmboxq->context1)
10018 return MBX_NOT_FINISHED;
10020 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
10021 /* setup wake call as IOCB callback */
10022 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
10023 /* setup context field to pass wait_queue pointer to wake function */
10024 pmboxq->context1 = &done_q;
10026 /* now issue the command */
10027 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
10028 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
10029 wait_event_interruptible_timeout(done_q,
10030 pmboxq->mbox_flag & LPFC_MBX_WAKE,
10033 spin_lock_irqsave(&phba->hbalock, flag);
10034 pmboxq->context1 = NULL;
10036 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10037 * else do not free the resources.
10039 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
10040 retval = MBX_SUCCESS;
10041 lpfc_sli4_swap_str(phba, pmboxq);
10043 retval = MBX_TIMEOUT;
10044 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10046 spin_unlock_irqrestore(&phba->hbalock, flag);
10053 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10054 * @phba: Pointer to HBA context.
10056 * This function is called to shutdown the driver's mailbox sub-system.
10057 * It first marks the mailbox sub-system is in a block state to prevent
10058 * the asynchronous mailbox command from issued off the pending mailbox
10059 * command queue. If the mailbox command sub-system shutdown is due to
10060 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10061 * the mailbox sub-system flush routine to forcefully bring down the
10062 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10063 * as with offline or HBA function reset), this routine will wait for the
10064 * outstanding mailbox command to complete before invoking the mailbox
10065 * sub-system flush routine to gracefully bring down mailbox sub-system.
10068 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
10070 struct lpfc_sli *psli = &phba->sli;
10071 unsigned long timeout;
10073 if (mbx_action == LPFC_MBX_NO_WAIT) {
10074 /* delay 100ms for port state */
10076 lpfc_sli_mbox_sys_flush(phba);
10079 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
10081 spin_lock_irq(&phba->hbalock);
10082 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10084 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
10085 /* Determine how long we might wait for the active mailbox
10086 * command to be gracefully completed by firmware.
10088 if (phba->sli.mbox_active)
10089 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
10090 phba->sli.mbox_active) *
10092 spin_unlock_irq(&phba->hbalock);
10094 while (phba->sli.mbox_active) {
10095 /* Check active mailbox complete status every 2ms */
10097 if (time_after(jiffies, timeout))
10098 /* Timeout, let the mailbox flush routine to
10099 * forcefully release active mailbox command
10104 spin_unlock_irq(&phba->hbalock);
10106 lpfc_sli_mbox_sys_flush(phba);
10110 * lpfc_sli_eratt_read - read sli-3 error attention events
10111 * @phba: Pointer to HBA context.
10113 * This function is called to read the SLI3 device error attention registers
10114 * for possible error attention events. The caller must hold the hostlock
10115 * with spin_lock_irq().
10117 * This function returns 1 when there is Error Attention in the Host Attention
10118 * Register and returns 0 otherwise.
10121 lpfc_sli_eratt_read(struct lpfc_hba *phba)
10125 /* Read chip Host Attention (HA) register */
10126 if (lpfc_readl(phba->HAregaddr, &ha_copy))
10129 if (ha_copy & HA_ERATT) {
10130 /* Read host status register to retrieve error event */
10131 if (lpfc_sli_read_hs(phba))
10134 /* Check if there is a deferred error condition is active */
10135 if ((HS_FFER1 & phba->work_hs) &&
10136 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
10137 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
10138 phba->hba_flag |= DEFER_ERATT;
10139 /* Clear all interrupt enable conditions */
10140 writel(0, phba->HCregaddr);
10141 readl(phba->HCregaddr);
10144 /* Set the driver HA work bitmap */
10145 phba->work_ha |= HA_ERATT;
10146 /* Indicate polling handles this ERATT */
10147 phba->hba_flag |= HBA_ERATT_HANDLED;
10153 /* Set the driver HS work bitmap */
10154 phba->work_hs |= UNPLUG_ERR;
10155 /* Set the driver HA work bitmap */
10156 phba->work_ha |= HA_ERATT;
10157 /* Indicate polling handles this ERATT */
10158 phba->hba_flag |= HBA_ERATT_HANDLED;
10163 * lpfc_sli4_eratt_read - read sli-4 error attention events
10164 * @phba: Pointer to HBA context.
10166 * This function is called to read the SLI4 device error attention registers
10167 * for possible error attention events. The caller must hold the hostlock
10168 * with spin_lock_irq().
10170 * This function returns 1 when there is Error Attention in the Host Attention
10171 * Register and returns 0 otherwise.
10174 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
10176 uint32_t uerr_sta_hi, uerr_sta_lo;
10177 uint32_t if_type, portsmphr;
10178 struct lpfc_register portstat_reg;
10181 * For now, use the SLI4 device internal unrecoverable error
10182 * registers for error attention. This can be changed later.
10184 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10186 case LPFC_SLI_INTF_IF_TYPE_0:
10187 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
10189 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
10191 phba->work_hs |= UNPLUG_ERR;
10192 phba->work_ha |= HA_ERATT;
10193 phba->hba_flag |= HBA_ERATT_HANDLED;
10196 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
10197 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
10198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10199 "1423 HBA Unrecoverable error: "
10200 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10201 "ue_mask_lo_reg=0x%x, "
10202 "ue_mask_hi_reg=0x%x\n",
10203 uerr_sta_lo, uerr_sta_hi,
10204 phba->sli4_hba.ue_mask_lo,
10205 phba->sli4_hba.ue_mask_hi);
10206 phba->work_status[0] = uerr_sta_lo;
10207 phba->work_status[1] = uerr_sta_hi;
10208 phba->work_ha |= HA_ERATT;
10209 phba->hba_flag |= HBA_ERATT_HANDLED;
10213 case LPFC_SLI_INTF_IF_TYPE_2:
10214 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
10215 &portstat_reg.word0) ||
10216 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
10218 phba->work_hs |= UNPLUG_ERR;
10219 phba->work_ha |= HA_ERATT;
10220 phba->hba_flag |= HBA_ERATT_HANDLED;
10223 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
10224 phba->work_status[0] =
10225 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
10226 phba->work_status[1] =
10227 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
10228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10229 "2885 Port Status Event: "
10230 "port status reg 0x%x, "
10231 "port smphr reg 0x%x, "
10232 "error 1=0x%x, error 2=0x%x\n",
10233 portstat_reg.word0,
10235 phba->work_status[0],
10236 phba->work_status[1]);
10237 phba->work_ha |= HA_ERATT;
10238 phba->hba_flag |= HBA_ERATT_HANDLED;
10242 case LPFC_SLI_INTF_IF_TYPE_1:
10244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10245 "2886 HBA Error Attention on unsupported "
10246 "if type %d.", if_type);
10254 * lpfc_sli_check_eratt - check error attention events
10255 * @phba: Pointer to HBA context.
10257 * This function is called from timer soft interrupt context to check HBA's
10258 * error attention register bit for error attention events.
10260 * This function returns 1 when there is Error Attention in the Host Attention
10261 * Register and returns 0 otherwise.
10264 lpfc_sli_check_eratt(struct lpfc_hba *phba)
10268 /* If somebody is waiting to handle an eratt, don't process it
10269 * here. The brdkill function will do this.
10271 if (phba->link_flag & LS_IGNORE_ERATT)
10274 /* Check if interrupt handler handles this ERATT */
10275 spin_lock_irq(&phba->hbalock);
10276 if (phba->hba_flag & HBA_ERATT_HANDLED) {
10277 /* Interrupt handler has handled ERATT */
10278 spin_unlock_irq(&phba->hbalock);
10283 * If there is deferred error attention, do not check for error
10286 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
10287 spin_unlock_irq(&phba->hbalock);
10291 /* If PCI channel is offline, don't process it */
10292 if (unlikely(pci_channel_offline(phba->pcidev))) {
10293 spin_unlock_irq(&phba->hbalock);
10297 switch (phba->sli_rev) {
10298 case LPFC_SLI_REV2:
10299 case LPFC_SLI_REV3:
10300 /* Read chip Host Attention (HA) register */
10301 ha_copy = lpfc_sli_eratt_read(phba);
10303 case LPFC_SLI_REV4:
10304 /* Read device Uncoverable Error (UERR) registers */
10305 ha_copy = lpfc_sli4_eratt_read(phba);
10308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10309 "0299 Invalid SLI revision (%d)\n",
10314 spin_unlock_irq(&phba->hbalock);
10320 * lpfc_intr_state_check - Check device state for interrupt handling
10321 * @phba: Pointer to HBA context.
10323 * This inline routine checks whether a device or its PCI slot is in a state
10324 * that the interrupt should be handled.
10326 * This function returns 0 if the device or the PCI slot is in a state that
10327 * interrupt should be handled, otherwise -EIO.
10330 lpfc_intr_state_check(struct lpfc_hba *phba)
10332 /* If the pci channel is offline, ignore all the interrupts */
10333 if (unlikely(pci_channel_offline(phba->pcidev)))
10336 /* Update device level interrupt statistics */
10337 phba->sli.slistat.sli_intr++;
10339 /* Ignore all interrupts during initialization. */
10340 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
10347 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10348 * @irq: Interrupt number.
10349 * @dev_id: The device context pointer.
10351 * This function is directly called from the PCI layer as an interrupt
10352 * service routine when device with SLI-3 interface spec is enabled with
10353 * MSI-X multi-message interrupt mode and there are slow-path events in
10354 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10355 * interrupt mode, this function is called as part of the device-level
10356 * interrupt handler. When the PCI slot is in error recovery or the HBA
10357 * is undergoing initialization, the interrupt handler will not process
10358 * the interrupt. The link attention and ELS ring attention events are
10359 * handled by the worker thread. The interrupt handler signals the worker
10360 * thread and returns for these events. This function is called without
10361 * any lock held. It gets the hbalock to access and update SLI data
10364 * This function returns IRQ_HANDLED when interrupt is handled else it
10365 * returns IRQ_NONE.
10368 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
10370 struct lpfc_hba *phba;
10371 uint32_t ha_copy, hc_copy;
10372 uint32_t work_ha_copy;
10373 unsigned long status;
10374 unsigned long iflag;
10377 MAILBOX_t *mbox, *pmbox;
10378 struct lpfc_vport *vport;
10379 struct lpfc_nodelist *ndlp;
10380 struct lpfc_dmabuf *mp;
10385 * Get the driver's phba structure from the dev_id and
10386 * assume the HBA is not interrupting.
10388 phba = (struct lpfc_hba *)dev_id;
10390 if (unlikely(!phba))
10394 * Stuff needs to be attented to when this function is invoked as an
10395 * individual interrupt handler in MSI-X multi-message interrupt mode
10397 if (phba->intr_type == MSIX) {
10398 /* Check device state for handling interrupt */
10399 if (lpfc_intr_state_check(phba))
10401 /* Need to read HA REG for slow-path events */
10402 spin_lock_irqsave(&phba->hbalock, iflag);
10403 if (lpfc_readl(phba->HAregaddr, &ha_copy))
10405 /* If somebody is waiting to handle an eratt don't process it
10406 * here. The brdkill function will do this.
10408 if (phba->link_flag & LS_IGNORE_ERATT)
10409 ha_copy &= ~HA_ERATT;
10410 /* Check the need for handling ERATT in interrupt handler */
10411 if (ha_copy & HA_ERATT) {
10412 if (phba->hba_flag & HBA_ERATT_HANDLED)
10413 /* ERATT polling has handled ERATT */
10414 ha_copy &= ~HA_ERATT;
10416 /* Indicate interrupt handler handles ERATT */
10417 phba->hba_flag |= HBA_ERATT_HANDLED;
10421 * If there is deferred error attention, do not check for any
10424 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
10425 spin_unlock_irqrestore(&phba->hbalock, iflag);
10429 /* Clear up only attention source related to slow-path */
10430 if (lpfc_readl(phba->HCregaddr, &hc_copy))
10433 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
10434 HC_LAINT_ENA | HC_ERINT_ENA),
10436 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
10438 writel(hc_copy, phba->HCregaddr);
10439 readl(phba->HAregaddr); /* flush */
10440 spin_unlock_irqrestore(&phba->hbalock, iflag);
10442 ha_copy = phba->ha_copy;
10444 work_ha_copy = ha_copy & phba->work_ha_mask;
10446 if (work_ha_copy) {
10447 if (work_ha_copy & HA_LATT) {
10448 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
10450 * Turn off Link Attention interrupts
10451 * until CLEAR_LA done
10453 spin_lock_irqsave(&phba->hbalock, iflag);
10454 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
10455 if (lpfc_readl(phba->HCregaddr, &control))
10457 control &= ~HC_LAINT_ENA;
10458 writel(control, phba->HCregaddr);
10459 readl(phba->HCregaddr); /* flush */
10460 spin_unlock_irqrestore(&phba->hbalock, iflag);
10463 work_ha_copy &= ~HA_LATT;
10466 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
10468 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10469 * the only slow ring.
10471 status = (work_ha_copy &
10472 (HA_RXMASK << (4*LPFC_ELS_RING)));
10473 status >>= (4*LPFC_ELS_RING);
10474 if (status & HA_RXMASK) {
10475 spin_lock_irqsave(&phba->hbalock, iflag);
10476 if (lpfc_readl(phba->HCregaddr, &control))
10479 lpfc_debugfs_slow_ring_trc(phba,
10480 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10482 (uint32_t)phba->sli.slistat.sli_intr);
10484 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
10485 lpfc_debugfs_slow_ring_trc(phba,
10486 "ISR Disable ring:"
10487 "pwork:x%x hawork:x%x wait:x%x",
10488 phba->work_ha, work_ha_copy,
10489 (uint32_t)((unsigned long)
10490 &phba->work_waitq));
10493 ~(HC_R0INT_ENA << LPFC_ELS_RING);
10494 writel(control, phba->HCregaddr);
10495 readl(phba->HCregaddr); /* flush */
10498 lpfc_debugfs_slow_ring_trc(phba,
10499 "ISR slow ring: pwork:"
10500 "x%x hawork:x%x wait:x%x",
10501 phba->work_ha, work_ha_copy,
10502 (uint32_t)((unsigned long)
10503 &phba->work_waitq));
10505 spin_unlock_irqrestore(&phba->hbalock, iflag);
10508 spin_lock_irqsave(&phba->hbalock, iflag);
10509 if (work_ha_copy & HA_ERATT) {
10510 if (lpfc_sli_read_hs(phba))
10513 * Check if there is a deferred error condition
10516 if ((HS_FFER1 & phba->work_hs) &&
10517 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
10518 HS_FFER6 | HS_FFER7 | HS_FFER8) &
10520 phba->hba_flag |= DEFER_ERATT;
10521 /* Clear all interrupt enable conditions */
10522 writel(0, phba->HCregaddr);
10523 readl(phba->HCregaddr);
10527 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
10528 pmb = phba->sli.mbox_active;
10529 pmbox = &pmb->u.mb;
10531 vport = pmb->vport;
10533 /* First check out the status word */
10534 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
10535 if (pmbox->mbxOwner != OWN_HOST) {
10536 spin_unlock_irqrestore(&phba->hbalock, iflag);
10538 * Stray Mailbox Interrupt, mbxCommand <cmd>
10539 * mbxStatus <status>
10541 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
10543 "(%d):0304 Stray Mailbox "
10544 "Interrupt mbxCommand x%x "
10546 (vport ? vport->vpi : 0),
10549 /* clear mailbox attention bit */
10550 work_ha_copy &= ~HA_MBATT;
10552 phba->sli.mbox_active = NULL;
10553 spin_unlock_irqrestore(&phba->hbalock, iflag);
10554 phba->last_completion_time = jiffies;
10555 del_timer(&phba->sli.mbox_tmo);
10556 if (pmb->mbox_cmpl) {
10557 lpfc_sli_pcimem_bcopy(mbox, pmbox,
10559 if (pmb->out_ext_byte_len &&
10561 lpfc_sli_pcimem_bcopy(
10564 pmb->out_ext_byte_len);
10566 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
10567 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
10569 lpfc_debugfs_disc_trc(vport,
10570 LPFC_DISC_TRC_MBOX_VPORT,
10571 "MBOX dflt rpi: : "
10572 "status:x%x rpi:x%x",
10573 (uint32_t)pmbox->mbxStatus,
10574 pmbox->un.varWords[0], 0);
10576 if (!pmbox->mbxStatus) {
10577 mp = (struct lpfc_dmabuf *)
10579 ndlp = (struct lpfc_nodelist *)
10582 /* Reg_LOGIN of dflt RPI was
10583 * successful. new lets get
10584 * rid of the RPI using the
10585 * same mbox buffer.
10587 lpfc_unreg_login(phba,
10589 pmbox->un.varWords[0],
10592 lpfc_mbx_cmpl_dflt_rpi;
10593 pmb->context1 = mp;
10594 pmb->context2 = ndlp;
10595 pmb->vport = vport;
10596 rc = lpfc_sli_issue_mbox(phba,
10599 if (rc != MBX_BUSY)
10600 lpfc_printf_log(phba,
10602 LOG_MBOX | LOG_SLI,
10603 "0350 rc should have"
10604 "been MBX_BUSY\n");
10605 if (rc != MBX_NOT_FINISHED)
10606 goto send_current_mbox;
10610 &phba->pport->work_port_lock,
10612 phba->pport->work_port_events &=
10614 spin_unlock_irqrestore(
10615 &phba->pport->work_port_lock,
10617 lpfc_mbox_cmpl_put(phba, pmb);
10620 spin_unlock_irqrestore(&phba->hbalock, iflag);
10622 if ((work_ha_copy & HA_MBATT) &&
10623 (phba->sli.mbox_active == NULL)) {
10625 /* Process next mailbox command if there is one */
10627 rc = lpfc_sli_issue_mbox(phba, NULL,
10629 } while (rc == MBX_NOT_FINISHED);
10630 if (rc != MBX_SUCCESS)
10631 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
10632 LOG_SLI, "0349 rc should be "
10636 spin_lock_irqsave(&phba->hbalock, iflag);
10637 phba->work_ha |= work_ha_copy;
10638 spin_unlock_irqrestore(&phba->hbalock, iflag);
10639 lpfc_worker_wake_up(phba);
10641 return IRQ_HANDLED;
10643 spin_unlock_irqrestore(&phba->hbalock, iflag);
10644 return IRQ_HANDLED;
10646 } /* lpfc_sli_sp_intr_handler */
10649 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10650 * @irq: Interrupt number.
10651 * @dev_id: The device context pointer.
10653 * This function is directly called from the PCI layer as an interrupt
10654 * service routine when device with SLI-3 interface spec is enabled with
10655 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10656 * ring event in the HBA. However, when the device is enabled with either
10657 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10658 * device-level interrupt handler. When the PCI slot is in error recovery
10659 * or the HBA is undergoing initialization, the interrupt handler will not
10660 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10661 * the intrrupt context. This function is called without any lock held.
10662 * It gets the hbalock to access and update SLI data structures.
10664 * This function returns IRQ_HANDLED when interrupt is handled else it
10665 * returns IRQ_NONE.
10668 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
10670 struct lpfc_hba *phba;
10672 unsigned long status;
10673 unsigned long iflag;
10675 /* Get the driver's phba structure from the dev_id and
10676 * assume the HBA is not interrupting.
10678 phba = (struct lpfc_hba *) dev_id;
10680 if (unlikely(!phba))
10684 * Stuff needs to be attented to when this function is invoked as an
10685 * individual interrupt handler in MSI-X multi-message interrupt mode
10687 if (phba->intr_type == MSIX) {
10688 /* Check device state for handling interrupt */
10689 if (lpfc_intr_state_check(phba))
10691 /* Need to read HA REG for FCP ring and other ring events */
10692 if (lpfc_readl(phba->HAregaddr, &ha_copy))
10693 return IRQ_HANDLED;
10694 /* Clear up only attention source related to fast-path */
10695 spin_lock_irqsave(&phba->hbalock, iflag);
10697 * If there is deferred error attention, do not check for
10700 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
10701 spin_unlock_irqrestore(&phba->hbalock, iflag);
10704 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
10706 readl(phba->HAregaddr); /* flush */
10707 spin_unlock_irqrestore(&phba->hbalock, iflag);
10709 ha_copy = phba->ha_copy;
10712 * Process all events on FCP ring. Take the optimized path for FCP IO.
10714 ha_copy &= ~(phba->work_ha_mask);
10716 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
10717 status >>= (4*LPFC_FCP_RING);
10718 if (status & HA_RXMASK)
10719 lpfc_sli_handle_fast_ring_event(phba,
10720 &phba->sli.ring[LPFC_FCP_RING],
10723 if (phba->cfg_multi_ring_support == 2) {
10725 * Process all events on extra ring. Take the optimized path
10726 * for extra ring IO.
10728 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
10729 status >>= (4*LPFC_EXTRA_RING);
10730 if (status & HA_RXMASK) {
10731 lpfc_sli_handle_fast_ring_event(phba,
10732 &phba->sli.ring[LPFC_EXTRA_RING],
10736 return IRQ_HANDLED;
10737 } /* lpfc_sli_fp_intr_handler */
10740 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10741 * @irq: Interrupt number.
10742 * @dev_id: The device context pointer.
10744 * This function is the HBA device-level interrupt handler to device with
10745 * SLI-3 interface spec, called from the PCI layer when either MSI or
10746 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10747 * requires driver attention. This function invokes the slow-path interrupt
10748 * attention handling function and fast-path interrupt attention handling
10749 * function in turn to process the relevant HBA attention events. This
10750 * function is called without any lock held. It gets the hbalock to access
10751 * and update SLI data structures.
10753 * This function returns IRQ_HANDLED when interrupt is handled, else it
10754 * returns IRQ_NONE.
10757 lpfc_sli_intr_handler(int irq, void *dev_id)
10759 struct lpfc_hba *phba;
10760 irqreturn_t sp_irq_rc, fp_irq_rc;
10761 unsigned long status1, status2;
10765 * Get the driver's phba structure from the dev_id and
10766 * assume the HBA is not interrupting.
10768 phba = (struct lpfc_hba *) dev_id;
10770 if (unlikely(!phba))
10773 /* Check device state for handling interrupt */
10774 if (lpfc_intr_state_check(phba))
10777 spin_lock(&phba->hbalock);
10778 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
10779 spin_unlock(&phba->hbalock);
10780 return IRQ_HANDLED;
10783 if (unlikely(!phba->ha_copy)) {
10784 spin_unlock(&phba->hbalock);
10786 } else if (phba->ha_copy & HA_ERATT) {
10787 if (phba->hba_flag & HBA_ERATT_HANDLED)
10788 /* ERATT polling has handled ERATT */
10789 phba->ha_copy &= ~HA_ERATT;
10791 /* Indicate interrupt handler handles ERATT */
10792 phba->hba_flag |= HBA_ERATT_HANDLED;
10796 * If there is deferred error attention, do not check for any interrupt.
10798 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
10799 spin_unlock(&phba->hbalock);
10803 /* Clear attention sources except link and error attentions */
10804 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
10805 spin_unlock(&phba->hbalock);
10806 return IRQ_HANDLED;
10808 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
10809 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
10811 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
10812 writel(hc_copy, phba->HCregaddr);
10813 readl(phba->HAregaddr); /* flush */
10814 spin_unlock(&phba->hbalock);
10817 * Invokes slow-path host attention interrupt handling as appropriate.
10820 /* status of events with mailbox and link attention */
10821 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
10823 /* status of events with ELS ring */
10824 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
10825 status2 >>= (4*LPFC_ELS_RING);
10827 if (status1 || (status2 & HA_RXMASK))
10828 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
10830 sp_irq_rc = IRQ_NONE;
10833 * Invoke fast-path host attention interrupt handling as appropriate.
10836 /* status of events with FCP ring */
10837 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
10838 status1 >>= (4*LPFC_FCP_RING);
10840 /* status of events with extra ring */
10841 if (phba->cfg_multi_ring_support == 2) {
10842 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
10843 status2 >>= (4*LPFC_EXTRA_RING);
10847 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
10848 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
10850 fp_irq_rc = IRQ_NONE;
10852 /* Return device-level interrupt handling status */
10853 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
10854 } /* lpfc_sli_intr_handler */
10857 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10858 * @phba: pointer to lpfc hba data structure.
10860 * This routine is invoked by the worker thread to process all the pending
10861 * SLI4 FCP abort XRI events.
10863 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
10865 struct lpfc_cq_event *cq_event;
10867 /* First, declare the fcp xri abort event has been handled */
10868 spin_lock_irq(&phba->hbalock);
10869 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
10870 spin_unlock_irq(&phba->hbalock);
10871 /* Now, handle all the fcp xri abort events */
10872 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
10873 /* Get the first event from the head of the event queue */
10874 spin_lock_irq(&phba->hbalock);
10875 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
10876 cq_event, struct lpfc_cq_event, list);
10877 spin_unlock_irq(&phba->hbalock);
10878 /* Notify aborted XRI for FCP work queue */
10879 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
10880 /* Free the event processed back to the free pool */
10881 lpfc_sli4_cq_event_release(phba, cq_event);
10886 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10887 * @phba: pointer to lpfc hba data structure.
10889 * This routine is invoked by the worker thread to process all the pending
10890 * SLI4 els abort xri events.
10892 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
10894 struct lpfc_cq_event *cq_event;
10896 /* First, declare the els xri abort event has been handled */
10897 spin_lock_irq(&phba->hbalock);
10898 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
10899 spin_unlock_irq(&phba->hbalock);
10900 /* Now, handle all the els xri abort events */
10901 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
10902 /* Get the first event from the head of the event queue */
10903 spin_lock_irq(&phba->hbalock);
10904 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10905 cq_event, struct lpfc_cq_event, list);
10906 spin_unlock_irq(&phba->hbalock);
10907 /* Notify aborted XRI for ELS work queue */
10908 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
10909 /* Free the event processed back to the free pool */
10910 lpfc_sli4_cq_event_release(phba, cq_event);
10915 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10916 * @phba: pointer to lpfc hba data structure
10917 * @pIocbIn: pointer to the rspiocbq
10918 * @pIocbOut: pointer to the cmdiocbq
10919 * @wcqe: pointer to the complete wcqe
10921 * This routine transfers the fields of a command iocbq to a response iocbq
10922 * by copying all the IOCB fields from command iocbq and transferring the
10923 * completion status information from the complete wcqe.
10926 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
10927 struct lpfc_iocbq *pIocbIn,
10928 struct lpfc_iocbq *pIocbOut,
10929 struct lpfc_wcqe_complete *wcqe)
10931 unsigned long iflags;
10933 size_t offset = offsetof(struct lpfc_iocbq, iocb);
10935 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
10936 sizeof(struct lpfc_iocbq) - offset);
10937 /* Map WCQE parameters into irspiocb parameters */
10938 status = bf_get(lpfc_wcqe_c_status, wcqe);
10939 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
10940 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
10941 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
10942 pIocbIn->iocb.un.fcpi.fcpi_parm =
10943 pIocbOut->iocb.un.fcpi.fcpi_parm -
10944 wcqe->total_data_placed;
10946 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
10948 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
10949 pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
10952 /* Convert BG errors for completion status */
10953 if (status == CQE_STATUS_DI_ERROR) {
10954 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
10956 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
10957 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
10959 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
10961 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
10962 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
10963 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
10964 BGS_GUARD_ERR_MASK;
10965 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
10966 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
10967 BGS_APPTAG_ERR_MASK;
10968 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
10969 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
10970 BGS_REFTAG_ERR_MASK;
10972 /* Check to see if there was any good data before the error */
10973 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
10974 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
10975 BGS_HI_WATER_MARK_PRESENT_MASK;
10976 pIocbIn->iocb.unsli3.sli3_bg.bghm =
10977 wcqe->total_data_placed;
10981 * Set ALL the error bits to indicate we don't know what
10982 * type of error it is.
10984 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
10985 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
10986 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
10987 BGS_GUARD_ERR_MASK);
10990 /* Pick up HBA exchange busy condition */
10991 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
10992 spin_lock_irqsave(&phba->hbalock, iflags);
10993 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
10994 spin_unlock_irqrestore(&phba->hbalock, iflags);
10999 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11000 * @phba: Pointer to HBA context object.
11001 * @wcqe: Pointer to work-queue completion queue entry.
11003 * This routine handles an ELS work-queue completion event and construct
11004 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11005 * discovery engine to handle.
11007 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11009 static struct lpfc_iocbq *
11010 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
11011 struct lpfc_iocbq *irspiocbq)
11013 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
11014 struct lpfc_iocbq *cmdiocbq;
11015 struct lpfc_wcqe_complete *wcqe;
11016 unsigned long iflags;
11018 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
11019 spin_lock_irqsave(&pring->ring_lock, iflags);
11020 pring->stats.iocb_event++;
11021 /* Look up the ELS command IOCB and create pseudo response IOCB */
11022 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
11023 bf_get(lpfc_wcqe_c_request_tag, wcqe));
11024 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11026 if (unlikely(!cmdiocbq)) {
11027 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11028 "0386 ELS complete with no corresponding "
11029 "cmdiocb: iotag (%d)\n",
11030 bf_get(lpfc_wcqe_c_request_tag, wcqe));
11031 lpfc_sli_release_iocbq(phba, irspiocbq);
11035 /* Fake the irspiocbq and copy necessary response information */
11036 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
11042 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11043 * @phba: Pointer to HBA context object.
11044 * @cqe: Pointer to mailbox completion queue entry.
11046 * This routine process a mailbox completion queue entry with asynchrous
11049 * Return: true if work posted to worker thread, otherwise false.
11052 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
11054 struct lpfc_cq_event *cq_event;
11055 unsigned long iflags;
11057 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11058 "0392 Async Event: word0:x%x, word1:x%x, "
11059 "word2:x%x, word3:x%x\n", mcqe->word0,
11060 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
11062 /* Allocate a new internal CQ_EVENT entry */
11063 cq_event = lpfc_sli4_cq_event_alloc(phba);
11065 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11066 "0394 Failed to allocate CQ_EVENT entry\n");
11070 /* Move the CQE into an asynchronous event entry */
11071 memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
11072 spin_lock_irqsave(&phba->hbalock, iflags);
11073 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
11074 /* Set the async event flag */
11075 phba->hba_flag |= ASYNC_EVENT;
11076 spin_unlock_irqrestore(&phba->hbalock, iflags);
11082 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11083 * @phba: Pointer to HBA context object.
11084 * @cqe: Pointer to mailbox completion queue entry.
11086 * This routine process a mailbox completion queue entry with mailbox
11087 * completion event.
11089 * Return: true if work posted to worker thread, otherwise false.
11092 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
11094 uint32_t mcqe_status;
11095 MAILBOX_t *mbox, *pmbox;
11096 struct lpfc_mqe *mqe;
11097 struct lpfc_vport *vport;
11098 struct lpfc_nodelist *ndlp;
11099 struct lpfc_dmabuf *mp;
11100 unsigned long iflags;
11102 bool workposted = false;
11105 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11106 if (!bf_get(lpfc_trailer_completed, mcqe))
11107 goto out_no_mqe_complete;
11109 /* Get the reference to the active mbox command */
11110 spin_lock_irqsave(&phba->hbalock, iflags);
11111 pmb = phba->sli.mbox_active;
11112 if (unlikely(!pmb)) {
11113 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
11114 "1832 No pending MBOX command to handle\n");
11115 spin_unlock_irqrestore(&phba->hbalock, iflags);
11116 goto out_no_mqe_complete;
11118 spin_unlock_irqrestore(&phba->hbalock, iflags);
11120 pmbox = (MAILBOX_t *)&pmb->u.mqe;
11122 vport = pmb->vport;
11124 /* Reset heartbeat timer */
11125 phba->last_completion_time = jiffies;
11126 del_timer(&phba->sli.mbox_tmo);
11128 /* Move mbox data to caller's mailbox region, do endian swapping */
11129 if (pmb->mbox_cmpl && mbox)
11130 lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
11133 * For mcqe errors, conditionally move a modified error code to
11134 * the mbox so that the error will not be missed.
11136 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
11137 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
11138 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
11139 bf_set(lpfc_mqe_status, mqe,
11140 (LPFC_MBX_ERROR_RANGE | mcqe_status));
11142 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
11143 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
11144 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
11145 "MBOX dflt rpi: status:x%x rpi:x%x",
11147 pmbox->un.varWords[0], 0);
11148 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
11149 mp = (struct lpfc_dmabuf *)(pmb->context1);
11150 ndlp = (struct lpfc_nodelist *)pmb->context2;
11151 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11152 * RID of the PPI using the same mbox buffer.
11154 lpfc_unreg_login(phba, vport->vpi,
11155 pmbox->un.varWords[0], pmb);
11156 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
11157 pmb->context1 = mp;
11158 pmb->context2 = ndlp;
11159 pmb->vport = vport;
11160 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
11161 if (rc != MBX_BUSY)
11162 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
11163 LOG_SLI, "0385 rc should "
11164 "have been MBX_BUSY\n");
11165 if (rc != MBX_NOT_FINISHED)
11166 goto send_current_mbox;
11169 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11170 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
11171 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11173 /* There is mailbox completion work to do */
11174 spin_lock_irqsave(&phba->hbalock, iflags);
11175 __lpfc_mbox_cmpl_put(phba, pmb);
11176 phba->work_ha |= HA_MBATT;
11177 spin_unlock_irqrestore(&phba->hbalock, iflags);
11181 spin_lock_irqsave(&phba->hbalock, iflags);
11182 /* Release the mailbox command posting token */
11183 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11184 /* Setting active mailbox pointer need to be in sync to flag clear */
11185 phba->sli.mbox_active = NULL;
11186 spin_unlock_irqrestore(&phba->hbalock, iflags);
11187 /* Wake up worker thread to post the next pending mailbox command */
11188 lpfc_worker_wake_up(phba);
11189 out_no_mqe_complete:
11190 if (bf_get(lpfc_trailer_consumed, mcqe))
11191 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
11196 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11197 * @phba: Pointer to HBA context object.
11198 * @cqe: Pointer to mailbox completion queue entry.
11200 * This routine process a mailbox completion queue entry, it invokes the
11201 * proper mailbox complete handling or asynchrous event handling routine
11202 * according to the MCQE's async bit.
11204 * Return: true if work posted to worker thread, otherwise false.
11207 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
11209 struct lpfc_mcqe mcqe;
11212 /* Copy the mailbox MCQE and convert endian order as needed */
11213 lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
11215 /* Invoke the proper event handling routine */
11216 if (!bf_get(lpfc_trailer_async, &mcqe))
11217 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
11219 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
11224 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11225 * @phba: Pointer to HBA context object.
11226 * @cq: Pointer to associated CQ
11227 * @wcqe: Pointer to work-queue completion queue entry.
11229 * This routine handles an ELS work-queue completion event.
11231 * Return: true if work posted to worker thread, otherwise false.
11234 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
11235 struct lpfc_wcqe_complete *wcqe)
11237 struct lpfc_iocbq *irspiocbq;
11238 unsigned long iflags;
11239 struct lpfc_sli_ring *pring = cq->pring;
11241 /* Get an irspiocbq for later ELS response processing use */
11242 irspiocbq = lpfc_sli_get_iocbq(phba);
11244 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11245 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11246 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
11247 pring->txq_cnt, phba->iocb_cnt,
11248 phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
11249 phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
11253 /* Save off the slow-path queue event for work thread to process */
11254 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
11255 spin_lock_irqsave(&phba->hbalock, iflags);
11256 list_add_tail(&irspiocbq->cq_event.list,
11257 &phba->sli4_hba.sp_queue_event);
11258 phba->hba_flag |= HBA_SP_QUEUE_EVT;
11259 spin_unlock_irqrestore(&phba->hbalock, iflags);
11265 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11266 * @phba: Pointer to HBA context object.
11267 * @wcqe: Pointer to work-queue completion queue entry.
11269 * This routine handles slow-path WQ entry comsumed event by invoking the
11270 * proper WQ release routine to the slow-path WQ.
11273 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
11274 struct lpfc_wcqe_release *wcqe)
11276 /* sanity check on queue memory */
11277 if (unlikely(!phba->sli4_hba.els_wq))
11279 /* Check for the slow-path ELS work queue */
11280 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
11281 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
11282 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
11284 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11285 "2579 Slow-path wqe consume event carries "
11286 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11287 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
11288 phba->sli4_hba.els_wq->queue_id);
11292 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11293 * @phba: Pointer to HBA context object.
11294 * @cq: Pointer to a WQ completion queue.
11295 * @wcqe: Pointer to work-queue completion queue entry.
11297 * This routine handles an XRI abort event.
11299 * Return: true if work posted to worker thread, otherwise false.
11302 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
11303 struct lpfc_queue *cq,
11304 struct sli4_wcqe_xri_aborted *wcqe)
11306 bool workposted = false;
11307 struct lpfc_cq_event *cq_event;
11308 unsigned long iflags;
11310 /* Allocate a new internal CQ_EVENT entry */
11311 cq_event = lpfc_sli4_cq_event_alloc(phba);
11313 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11314 "0602 Failed to allocate CQ_EVENT entry\n");
11318 /* Move the CQE into the proper xri abort event list */
11319 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
11320 switch (cq->subtype) {
11322 spin_lock_irqsave(&phba->hbalock, iflags);
11323 list_add_tail(&cq_event->list,
11324 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
11325 /* Set the fcp xri abort event flag */
11326 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
11327 spin_unlock_irqrestore(&phba->hbalock, iflags);
11331 spin_lock_irqsave(&phba->hbalock, iflags);
11332 list_add_tail(&cq_event->list,
11333 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
11334 /* Set the els xri abort event flag */
11335 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
11336 spin_unlock_irqrestore(&phba->hbalock, iflags);
11340 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11341 "0603 Invalid work queue CQE subtype (x%x)\n",
11343 workposted = false;
11350 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11351 * @phba: Pointer to HBA context object.
11352 * @rcqe: Pointer to receive-queue completion queue entry.
11354 * This routine process a receive-queue completion queue entry.
11356 * Return: true if work posted to worker thread, otherwise false.
11359 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
11361 bool workposted = false;
11362 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
11363 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
11364 struct hbq_dmabuf *dma_buf;
11365 uint32_t status, rq_id;
11366 unsigned long iflags;
11368 /* sanity check on queue memory */
11369 if (unlikely(!hrq) || unlikely(!drq))
11372 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
11373 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
11375 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
11376 if (rq_id != hrq->queue_id)
11379 status = bf_get(lpfc_rcqe_status, rcqe);
11381 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
11382 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11383 "2537 Receive Frame Truncated!!\n");
11384 hrq->RQ_buf_trunc++;
11385 case FC_STATUS_RQ_SUCCESS:
11386 lpfc_sli4_rq_release(hrq, drq);
11387 spin_lock_irqsave(&phba->hbalock, iflags);
11388 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
11390 hrq->RQ_no_buf_found++;
11391 spin_unlock_irqrestore(&phba->hbalock, iflags);
11395 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
11396 /* save off the frame for the word thread to process */
11397 list_add_tail(&dma_buf->cq_event.list,
11398 &phba->sli4_hba.sp_queue_event);
11399 /* Frame received */
11400 phba->hba_flag |= HBA_SP_QUEUE_EVT;
11401 spin_unlock_irqrestore(&phba->hbalock, iflags);
11404 case FC_STATUS_INSUFF_BUF_NEED_BUF:
11405 case FC_STATUS_INSUFF_BUF_FRM_DISC:
11406 hrq->RQ_no_posted_buf++;
11407 /* Post more buffers if possible */
11408 spin_lock_irqsave(&phba->hbalock, iflags);
11409 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
11410 spin_unlock_irqrestore(&phba->hbalock, iflags);
11419 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11420 * @phba: Pointer to HBA context object.
11421 * @cq: Pointer to the completion queue.
11422 * @wcqe: Pointer to a completion queue entry.
11424 * This routine process a slow-path work-queue or receive queue completion queue
11427 * Return: true if work posted to worker thread, otherwise false.
11430 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
11431 struct lpfc_cqe *cqe)
11433 struct lpfc_cqe cqevt;
11434 bool workposted = false;
11436 /* Copy the work queue CQE and convert endian order if needed */
11437 lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
11439 /* Check and process for different type of WCQE and dispatch */
11440 switch (bf_get(lpfc_cqe_code, &cqevt)) {
11441 case CQE_CODE_COMPL_WQE:
11442 /* Process the WQ/RQ complete event */
11443 phba->last_completion_time = jiffies;
11444 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
11445 (struct lpfc_wcqe_complete *)&cqevt);
11447 case CQE_CODE_RELEASE_WQE:
11448 /* Process the WQ release event */
11449 lpfc_sli4_sp_handle_rel_wcqe(phba,
11450 (struct lpfc_wcqe_release *)&cqevt);
11452 case CQE_CODE_XRI_ABORTED:
11453 /* Process the WQ XRI abort event */
11454 phba->last_completion_time = jiffies;
11455 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
11456 (struct sli4_wcqe_xri_aborted *)&cqevt);
11458 case CQE_CODE_RECEIVE:
11459 case CQE_CODE_RECEIVE_V1:
11460 /* Process the RQ event */
11461 phba->last_completion_time = jiffies;
11462 workposted = lpfc_sli4_sp_handle_rcqe(phba,
11463 (struct lpfc_rcqe *)&cqevt);
11466 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11467 "0388 Not a valid WCQE code: x%x\n",
11468 bf_get(lpfc_cqe_code, &cqevt));
11475 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11476 * @phba: Pointer to HBA context object.
11477 * @eqe: Pointer to fast-path event queue entry.
11479 * This routine process a event queue entry from the slow-path event queue.
11480 * It will check the MajorCode and MinorCode to determine this is for a
11481 * completion event on a completion queue, if not, an error shall be logged
11482 * and just return. Otherwise, it will get to the corresponding completion
11483 * queue and process all the entries on that completion queue, rearm the
11484 * completion queue, and then return.
11488 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
11489 struct lpfc_queue *speq)
11491 struct lpfc_queue *cq = NULL, *childq;
11492 struct lpfc_cqe *cqe;
11493 bool workposted = false;
11497 /* Get the reference to the corresponding CQ */
11498 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
11500 list_for_each_entry(childq, &speq->child_list, list) {
11501 if (childq->queue_id == cqid) {
11506 if (unlikely(!cq)) {
11507 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
11508 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11509 "0365 Slow-path CQ identifier "
11510 "(%d) does not exist\n", cqid);
11514 /* Process all the entries to the CQ */
11515 switch (cq->type) {
11517 while ((cqe = lpfc_sli4_cq_get(cq))) {
11518 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
11519 if (!(++ecount % cq->entry_repost))
11520 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
11525 while ((cqe = lpfc_sli4_cq_get(cq))) {
11526 if (cq->subtype == LPFC_FCP)
11527 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
11530 workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
11532 if (!(++ecount % cq->entry_repost))
11533 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
11536 /* Track the max number of CQEs processed in 1 EQ */
11537 if (ecount > cq->CQ_max_cqe)
11538 cq->CQ_max_cqe = ecount;
11541 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11542 "0370 Invalid completion queue type (%d)\n",
11547 /* Catch the no cq entry condition, log an error */
11548 if (unlikely(ecount == 0))
11549 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11550 "0371 No entry from the CQ: identifier "
11551 "(x%x), type (%d)\n", cq->queue_id, cq->type);
11553 /* In any case, flash and re-arm the RCQ */
11554 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
11556 /* wake up worker thread if there are works to be done */
11558 lpfc_worker_wake_up(phba);
11562 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11563 * @phba: Pointer to HBA context object.
11564 * @cq: Pointer to associated CQ
11565 * @wcqe: Pointer to work-queue completion queue entry.
11567 * This routine process a fast-path work queue completion entry from fast-path
11568 * event queue for FCP command response completion.
11571 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
11572 struct lpfc_wcqe_complete *wcqe)
11574 struct lpfc_sli_ring *pring = cq->pring;
11575 struct lpfc_iocbq *cmdiocbq;
11576 struct lpfc_iocbq irspiocbq;
11577 unsigned long iflags;
11579 /* Check for response status */
11580 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
11581 /* If resource errors reported from HBA, reduce queue
11582 * depth of the SCSI device.
11584 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
11585 IOSTAT_LOCAL_REJECT)) &&
11586 ((wcqe->parameter & IOERR_PARAM_MASK) ==
11587 IOERR_NO_RESOURCES))
11588 phba->lpfc_rampdown_queue_depth(phba);
11590 /* Log the error status */
11591 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11592 "0373 FCP complete error: status=x%x, "
11593 "hw_status=x%x, total_data_specified=%d, "
11594 "parameter=x%x, word3=x%x\n",
11595 bf_get(lpfc_wcqe_c_status, wcqe),
11596 bf_get(lpfc_wcqe_c_hw_status, wcqe),
11597 wcqe->total_data_placed, wcqe->parameter,
11601 /* Look up the FCP command IOCB and create pseudo response IOCB */
11602 spin_lock_irqsave(&pring->ring_lock, iflags);
11603 pring->stats.iocb_event++;
11604 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
11605 bf_get(lpfc_wcqe_c_request_tag, wcqe));
11606 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11607 if (unlikely(!cmdiocbq)) {
11608 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11609 "0374 FCP complete with no corresponding "
11610 "cmdiocb: iotag (%d)\n",
11611 bf_get(lpfc_wcqe_c_request_tag, wcqe));
11614 if (unlikely(!cmdiocbq->iocb_cmpl)) {
11615 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11616 "0375 FCP cmdiocb not callback function "
11618 bf_get(lpfc_wcqe_c_request_tag, wcqe));
11622 /* Fake the irspiocb and copy necessary response information */
11623 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
11625 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
11626 spin_lock_irqsave(&phba->hbalock, iflags);
11627 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
11628 spin_unlock_irqrestore(&phba->hbalock, iflags);
11631 /* Pass the cmd_iocb and the rsp state to the upper layer */
11632 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
11636 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11637 * @phba: Pointer to HBA context object.
11638 * @cq: Pointer to completion queue.
11639 * @wcqe: Pointer to work-queue completion queue entry.
11641 * This routine handles an fast-path WQ entry comsumed event by invoking the
11642 * proper WQ release routine to the slow-path WQ.
11645 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
11646 struct lpfc_wcqe_release *wcqe)
11648 struct lpfc_queue *childwq;
11649 bool wqid_matched = false;
11652 /* Check for fast-path FCP work queue release */
11653 fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
11654 list_for_each_entry(childwq, &cq->child_list, list) {
11655 if (childwq->queue_id == fcp_wqid) {
11656 lpfc_sli4_wq_release(childwq,
11657 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
11658 wqid_matched = true;
11662 /* Report warning log message if no match found */
11663 if (wqid_matched != true)
11664 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11665 "2580 Fast-path wqe consume event carries "
11666 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
11670 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11671 * @cq: Pointer to the completion queue.
11672 * @eqe: Pointer to fast-path completion queue entry.
11674 * This routine process a fast-path work queue completion entry from fast-path
11675 * event queue for FCP command response completion.
11678 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
11679 struct lpfc_cqe *cqe)
11681 struct lpfc_wcqe_release wcqe;
11682 bool workposted = false;
11684 /* Copy the work queue CQE and convert endian order if needed */
11685 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
11687 /* Check and process for different type of WCQE and dispatch */
11688 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
11689 case CQE_CODE_COMPL_WQE:
11691 /* Process the WQ complete event */
11692 phba->last_completion_time = jiffies;
11693 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
11694 (struct lpfc_wcqe_complete *)&wcqe);
11696 case CQE_CODE_RELEASE_WQE:
11697 cq->CQ_release_wqe++;
11698 /* Process the WQ release event */
11699 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
11700 (struct lpfc_wcqe_release *)&wcqe);
11702 case CQE_CODE_XRI_ABORTED:
11703 cq->CQ_xri_aborted++;
11704 /* Process the WQ XRI abort event */
11705 phba->last_completion_time = jiffies;
11706 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
11707 (struct sli4_wcqe_xri_aborted *)&wcqe);
11710 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11711 "0144 Not a valid WCQE code: x%x\n",
11712 bf_get(lpfc_wcqe_c_code, &wcqe));
11719 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
11720 * @phba: Pointer to HBA context object.
11721 * @eqe: Pointer to fast-path event queue entry.
11723 * This routine process a event queue entry from the fast-path event queue.
11724 * It will check the MajorCode and MinorCode to determine this is for a
11725 * completion event on a completion queue, if not, an error shall be logged
11726 * and just return. Otherwise, it will get to the corresponding completion
11727 * queue and process all the entries on the completion queue, rearm the
11728 * completion queue, and then return.
11731 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
11734 struct lpfc_queue *cq;
11735 struct lpfc_cqe *cqe;
11736 bool workposted = false;
11740 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
11741 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11742 "0366 Not a valid completion "
11743 "event: majorcode=x%x, minorcode=x%x\n",
11744 bf_get_le32(lpfc_eqe_major_code, eqe),
11745 bf_get_le32(lpfc_eqe_minor_code, eqe));
11749 /* Get the reference to the corresponding CQ */
11750 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
11752 /* Check if this is a Slow path event */
11753 if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
11754 lpfc_sli4_sp_handle_eqe(phba, eqe,
11755 phba->sli4_hba.hba_eq[qidx]);
11759 if (unlikely(!phba->sli4_hba.fcp_cq)) {
11760 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11761 "3146 Fast-path completion queues "
11762 "does not exist\n");
11765 cq = phba->sli4_hba.fcp_cq[qidx];
11766 if (unlikely(!cq)) {
11767 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
11768 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11769 "0367 Fast-path completion queue "
11770 "(%d) does not exist\n", qidx);
11774 if (unlikely(cqid != cq->queue_id)) {
11775 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11776 "0368 Miss-matched fast-path completion "
11777 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11778 cqid, cq->queue_id);
11782 /* Process all the entries to the CQ */
11783 while ((cqe = lpfc_sli4_cq_get(cq))) {
11784 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
11785 if (!(++ecount % cq->entry_repost))
11786 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
11789 /* Track the max number of CQEs processed in 1 EQ */
11790 if (ecount > cq->CQ_max_cqe)
11791 cq->CQ_max_cqe = ecount;
11793 /* Catch the no cq entry condition */
11794 if (unlikely(ecount == 0))
11795 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11796 "0369 No entry from fast-path completion "
11797 "queue fcpcqid=%d\n", cq->queue_id);
11799 /* In any case, flash and re-arm the CQ */
11800 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
11802 /* wake up worker thread if there are works to be done */
11804 lpfc_worker_wake_up(phba);
11808 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
11810 struct lpfc_eqe *eqe;
11812 /* walk all the EQ entries and drop on the floor */
11813 while ((eqe = lpfc_sli4_eq_get(eq)))
11816 /* Clear and re-arm the EQ */
11817 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
11821 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
11822 * @irq: Interrupt number.
11823 * @dev_id: The device context pointer.
11825 * This function is directly called from the PCI layer as an interrupt
11826 * service routine when device with SLI-4 interface spec is enabled with
11827 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11828 * ring event in the HBA. However, when the device is enabled with either
11829 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11830 * device-level interrupt handler. When the PCI slot is in error recovery
11831 * or the HBA is undergoing initialization, the interrupt handler will not
11832 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11833 * the intrrupt context. This function is called without any lock held.
11834 * It gets the hbalock to access and update SLI data structures. Note that,
11835 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11836 * equal to that of FCP CQ index.
11838 * The link attention and ELS ring attention events are handled
11839 * by the worker thread. The interrupt handler signals the worker thread
11840 * and returns for these events. This function is called without any lock
11841 * held. It gets the hbalock to access and update SLI data structures.
11843 * This function returns IRQ_HANDLED when interrupt is handled else it
11844 * returns IRQ_NONE.
11847 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
11849 struct lpfc_hba *phba;
11850 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
11851 struct lpfc_queue *fpeq;
11852 struct lpfc_eqe *eqe;
11853 unsigned long iflag;
11855 uint32_t fcp_eqidx;
11857 /* Get the driver's phba structure from the dev_id */
11858 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
11859 phba = fcp_eq_hdl->phba;
11860 fcp_eqidx = fcp_eq_hdl->idx;
11862 if (unlikely(!phba))
11864 if (unlikely(!phba->sli4_hba.hba_eq))
11867 /* Get to the EQ struct associated with this vector */
11868 fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
11869 if (unlikely(!fpeq))
11872 if (lpfc_fcp_look_ahead) {
11873 if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
11874 lpfc_sli4_eq_clr_intr(fpeq);
11876 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
11881 /* Check device state for handling interrupt */
11882 if (unlikely(lpfc_intr_state_check(phba))) {
11883 fpeq->EQ_badstate++;
11884 /* Check again for link_state with lock held */
11885 spin_lock_irqsave(&phba->hbalock, iflag);
11886 if (phba->link_state < LPFC_LINK_DOWN)
11887 /* Flush, clear interrupt, and rearm the EQ */
11888 lpfc_sli4_eq_flush(phba, fpeq);
11889 spin_unlock_irqrestore(&phba->hbalock, iflag);
11890 if (lpfc_fcp_look_ahead)
11891 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
11896 * Process all the event on FCP fast-path EQ
11898 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
11899 lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
11900 if (!(++ecount % fpeq->entry_repost))
11901 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
11902 fpeq->EQ_processed++;
11905 /* Track the max number of EQEs processed in 1 intr */
11906 if (ecount > fpeq->EQ_max_eqe)
11907 fpeq->EQ_max_eqe = ecount;
11909 /* Always clear and re-arm the fast-path EQ */
11910 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
11912 if (unlikely(ecount == 0)) {
11913 fpeq->EQ_no_entry++;
11915 if (lpfc_fcp_look_ahead) {
11916 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
11920 if (phba->intr_type == MSIX)
11921 /* MSI-X treated interrupt served as no EQ share INT */
11922 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11923 "0358 MSI-X interrupt with no EQE\n");
11925 /* Non MSI-X treated on interrupt as EQ share INT */
11929 if (lpfc_fcp_look_ahead)
11930 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
11931 return IRQ_HANDLED;
11932 } /* lpfc_sli4_fp_intr_handler */
11935 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11936 * @irq: Interrupt number.
11937 * @dev_id: The device context pointer.
11939 * This function is the device-level interrupt handler to device with SLI-4
11940 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11941 * interrupt mode is enabled and there is an event in the HBA which requires
11942 * driver attention. This function invokes the slow-path interrupt attention
11943 * handling function and fast-path interrupt attention handling function in
11944 * turn to process the relevant HBA attention events. This function is called
11945 * without any lock held. It gets the hbalock to access and update SLI data
11948 * This function returns IRQ_HANDLED when interrupt is handled, else it
11949 * returns IRQ_NONE.
11952 lpfc_sli4_intr_handler(int irq, void *dev_id)
11954 struct lpfc_hba *phba;
11955 irqreturn_t hba_irq_rc;
11956 bool hba_handled = false;
11957 uint32_t fcp_eqidx;
11959 /* Get the driver's phba structure from the dev_id */
11960 phba = (struct lpfc_hba *)dev_id;
11962 if (unlikely(!phba))
11966 * Invoke fast-path host attention interrupt handling as appropriate.
11968 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
11969 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
11970 &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
11971 if (hba_irq_rc == IRQ_HANDLED)
11972 hba_handled |= true;
11975 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
11976 } /* lpfc_sli4_intr_handler */
11979 * lpfc_sli4_queue_free - free a queue structure and associated memory
11980 * @queue: The queue structure to free.
11982 * This function frees a queue structure and the DMAable memory used for
11983 * the host resident queue. This function must be called after destroying the
11984 * queue on the HBA.
11987 lpfc_sli4_queue_free(struct lpfc_queue *queue)
11989 struct lpfc_dmabuf *dmabuf;
11994 while (!list_empty(&queue->page_list)) {
11995 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
11997 dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
11998 dmabuf->virt, dmabuf->phys);
12006 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12007 * @phba: The HBA that this queue is being created on.
12008 * @entry_size: The size of each queue entry for this queue.
12009 * @entry count: The number of entries that this queue will handle.
12011 * This function allocates a queue structure and the DMAable memory used for
12012 * the host resident queue. This function must be called before creating the
12013 * queue on the HBA.
12015 struct lpfc_queue *
12016 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
12017 uint32_t entry_count)
12019 struct lpfc_queue *queue;
12020 struct lpfc_dmabuf *dmabuf;
12021 int x, total_qe_count;
12023 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12025 if (!phba->sli4_hba.pc_sli4_params.supported)
12026 hw_page_size = SLI4_PAGE_SIZE;
12028 queue = kzalloc(sizeof(struct lpfc_queue) +
12029 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
12032 queue->page_count = (ALIGN(entry_size * entry_count,
12033 hw_page_size))/hw_page_size;
12034 INIT_LIST_HEAD(&queue->list);
12035 INIT_LIST_HEAD(&queue->page_list);
12036 INIT_LIST_HEAD(&queue->child_list);
12037 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
12038 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
12041 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
12042 hw_page_size, &dmabuf->phys,
12044 if (!dmabuf->virt) {
12048 memset(dmabuf->virt, 0, hw_page_size);
12049 dmabuf->buffer_tag = x;
12050 list_add_tail(&dmabuf->list, &queue->page_list);
12051 /* initialize queue's entry array */
12052 dma_pointer = dmabuf->virt;
12053 for (; total_qe_count < entry_count &&
12054 dma_pointer < (hw_page_size + dmabuf->virt);
12055 total_qe_count++, dma_pointer += entry_size) {
12056 queue->qe[total_qe_count].address = dma_pointer;
12059 queue->entry_size = entry_size;
12060 queue->entry_count = entry_count;
12063 * entry_repost is calculated based on the number of entries in the
12064 * queue. This works out except for RQs. If buffers are NOT initially
12065 * posted for every RQE, entry_repost should be adjusted accordingly.
12067 queue->entry_repost = (entry_count >> 3);
12068 if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
12069 queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
12070 queue->phba = phba;
12074 lpfc_sli4_queue_free(queue);
12079 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
12080 * @phba: HBA structure that indicates port to create a queue on.
12081 * @startq: The starting FCP EQ to modify
12083 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
12085 * The @phba struct is used to send mailbox command to HBA. The @startq
12086 * is used to get the starting FCP EQ to change.
12087 * This function is asynchronous and will wait for the mailbox
12088 * command to finish before continuing.
12090 * On success this function will return a zero. If unable to allocate enough
12091 * memory this function will return -ENOMEM. If the queue create mailbox command
12092 * fails this function will return -ENXIO.
12095 lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq)
12097 struct lpfc_mbx_modify_eq_delay *eq_delay;
12098 LPFC_MBOXQ_t *mbox;
12099 struct lpfc_queue *eq;
12100 int cnt, rc, length, status = 0;
12101 uint32_t shdr_status, shdr_add_status;
12103 union lpfc_sli4_cfg_shdr *shdr;
12106 if (startq >= phba->cfg_fcp_io_channel)
12109 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12112 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
12113 sizeof(struct lpfc_sli4_cfg_mhdr));
12114 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12115 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
12116 length, LPFC_SLI4_MBX_EMBED);
12117 eq_delay = &mbox->u.mqe.un.eq_delay;
12119 /* Calculate delay multiper from maximum interrupt per second */
12120 dmult = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
12121 dmult = LPFC_DMULT_CONST/dmult - 1;
12124 for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
12126 eq = phba->sli4_hba.hba_eq[fcp_eqidx];
12129 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
12130 eq_delay->u.request.eq[cnt].phase = 0;
12131 eq_delay->u.request.eq[cnt].delay_multi = dmult;
12133 if (cnt >= LPFC_MAX_EQ_DELAY)
12136 eq_delay->u.request.num_eq = cnt;
12138 mbox->vport = phba->pport;
12139 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12140 mbox->context1 = NULL;
12141 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12142 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
12143 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12144 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12145 if (shdr_status || shdr_add_status || rc) {
12146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12147 "2512 MODIFY_EQ_DELAY mailbox failed with "
12148 "status x%x add_status x%x, mbx status x%x\n",
12149 shdr_status, shdr_add_status, rc);
12152 mempool_free(mbox, phba->mbox_mem_pool);
12157 * lpfc_eq_create - Create an Event Queue on the HBA
12158 * @phba: HBA structure that indicates port to create a queue on.
12159 * @eq: The queue structure to use to create the event queue.
12160 * @imax: The maximum interrupt per second limit.
12162 * This function creates an event queue, as detailed in @eq, on a port,
12163 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12165 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12166 * is used to get the entry count and entry size that are necessary to
12167 * determine the number of pages to allocate and use for this queue. This
12168 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12169 * event queue. This function is asynchronous and will wait for the mailbox
12170 * command to finish before continuing.
12172 * On success this function will return a zero. If unable to allocate enough
12173 * memory this function will return -ENOMEM. If the queue create mailbox command
12174 * fails this function will return -ENXIO.
12177 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
12179 struct lpfc_mbx_eq_create *eq_create;
12180 LPFC_MBOXQ_t *mbox;
12181 int rc, length, status = 0;
12182 struct lpfc_dmabuf *dmabuf;
12183 uint32_t shdr_status, shdr_add_status;
12184 union lpfc_sli4_cfg_shdr *shdr;
12186 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12188 /* sanity check on queue memory */
12191 if (!phba->sli4_hba.pc_sli4_params.supported)
12192 hw_page_size = SLI4_PAGE_SIZE;
12194 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12197 length = (sizeof(struct lpfc_mbx_eq_create) -
12198 sizeof(struct lpfc_sli4_cfg_mhdr));
12199 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12200 LPFC_MBOX_OPCODE_EQ_CREATE,
12201 length, LPFC_SLI4_MBX_EMBED);
12202 eq_create = &mbox->u.mqe.un.eq_create;
12203 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
12205 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
12207 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
12208 /* Calculate delay multiper from maximum interrupt per second */
12209 dmult = LPFC_DMULT_CONST/imax - 1;
12210 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
12212 switch (eq->entry_count) {
12214 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12215 "0360 Unsupported EQ count. (%d)\n",
12217 if (eq->entry_count < 256)
12219 /* otherwise default to smallest count (drop through) */
12221 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12225 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12229 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12233 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12237 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12241 list_for_each_entry(dmabuf, &eq->page_list, list) {
12242 memset(dmabuf->virt, 0, hw_page_size);
12243 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
12244 putPaddrLow(dmabuf->phys);
12245 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
12246 putPaddrHigh(dmabuf->phys);
12248 mbox->vport = phba->pport;
12249 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12250 mbox->context1 = NULL;
12251 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12252 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
12253 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12254 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12255 if (shdr_status || shdr_add_status || rc) {
12256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12257 "2500 EQ_CREATE mailbox failed with "
12258 "status x%x add_status x%x, mbx status x%x\n",
12259 shdr_status, shdr_add_status, rc);
12262 eq->type = LPFC_EQ;
12263 eq->subtype = LPFC_NONE;
12264 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
12265 if (eq->queue_id == 0xFFFF)
12267 eq->host_index = 0;
12270 mempool_free(mbox, phba->mbox_mem_pool);
12275 * lpfc_cq_create - Create a Completion Queue on the HBA
12276 * @phba: HBA structure that indicates port to create a queue on.
12277 * @cq: The queue structure to use to create the completion queue.
12278 * @eq: The event queue to bind this completion queue to.
12280 * This function creates a completion queue, as detailed in @wq, on a port,
12281 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
12283 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12284 * is used to get the entry count and entry size that are necessary to
12285 * determine the number of pages to allocate and use for this queue. The @eq
12286 * is used to indicate which event queue to bind this completion queue to. This
12287 * function will send the CQ_CREATE mailbox command to the HBA to setup the
12288 * completion queue. This function is asynchronous and will wait for the mailbox
12289 * command to finish before continuing.
12291 * On success this function will return a zero. If unable to allocate enough
12292 * memory this function will return -ENOMEM. If the queue create mailbox command
12293 * fails this function will return -ENXIO.
12296 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
12297 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
12299 struct lpfc_mbx_cq_create *cq_create;
12300 struct lpfc_dmabuf *dmabuf;
12301 LPFC_MBOXQ_t *mbox;
12302 int rc, length, status = 0;
12303 uint32_t shdr_status, shdr_add_status;
12304 union lpfc_sli4_cfg_shdr *shdr;
12305 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12307 /* sanity check on queue memory */
12310 if (!phba->sli4_hba.pc_sli4_params.supported)
12311 hw_page_size = SLI4_PAGE_SIZE;
12313 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12316 length = (sizeof(struct lpfc_mbx_cq_create) -
12317 sizeof(struct lpfc_sli4_cfg_mhdr));
12318 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12319 LPFC_MBOX_OPCODE_CQ_CREATE,
12320 length, LPFC_SLI4_MBX_EMBED);
12321 cq_create = &mbox->u.mqe.un.cq_create;
12322 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
12323 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
12325 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
12326 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
12327 bf_set(lpfc_mbox_hdr_version, &shdr->request,
12328 phba->sli4_hba.pc_sli4_params.cqv);
12329 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
12330 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12331 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
12332 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
12335 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
12338 switch (cq->entry_count) {
12340 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12341 "0361 Unsupported CQ count. (%d)\n",
12343 if (cq->entry_count < 256) {
12347 /* otherwise default to smallest count (drop through) */
12349 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
12353 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
12357 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
12361 list_for_each_entry(dmabuf, &cq->page_list, list) {
12362 memset(dmabuf->virt, 0, hw_page_size);
12363 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
12364 putPaddrLow(dmabuf->phys);
12365 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
12366 putPaddrHigh(dmabuf->phys);
12368 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12370 /* The IOCTL status is embedded in the mailbox subheader. */
12371 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12372 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12373 if (shdr_status || shdr_add_status || rc) {
12374 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12375 "2501 CQ_CREATE mailbox failed with "
12376 "status x%x add_status x%x, mbx status x%x\n",
12377 shdr_status, shdr_add_status, rc);
12381 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
12382 if (cq->queue_id == 0xFFFF) {
12386 /* link the cq onto the parent eq child list */
12387 list_add_tail(&cq->list, &eq->child_list);
12388 /* Set up completion queue's type and subtype */
12390 cq->subtype = subtype;
12391 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
12392 cq->assoc_qid = eq->queue_id;
12393 cq->host_index = 0;
12397 mempool_free(mbox, phba->mbox_mem_pool);
12402 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12403 * @phba: HBA structure that indicates port to create a queue on.
12404 * @mq: The queue structure to use to create the mailbox queue.
12405 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12406 * @cq: The completion queue to associate with this cq.
12408 * This function provides failback (fb) functionality when the
12409 * mq_create_ext fails on older FW generations. It's purpose is identical
12410 * to mq_create_ext otherwise.
12412 * This routine cannot fail as all attributes were previously accessed and
12413 * initialized in mq_create_ext.
12416 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
12417 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
12419 struct lpfc_mbx_mq_create *mq_create;
12420 struct lpfc_dmabuf *dmabuf;
12423 length = (sizeof(struct lpfc_mbx_mq_create) -
12424 sizeof(struct lpfc_sli4_cfg_mhdr));
12425 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12426 LPFC_MBOX_OPCODE_MQ_CREATE,
12427 length, LPFC_SLI4_MBX_EMBED);
12428 mq_create = &mbox->u.mqe.un.mq_create;
12429 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
12431 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
12433 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
12434 switch (mq->entry_count) {
12436 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
12437 LPFC_MQ_RING_SIZE_16);
12440 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
12441 LPFC_MQ_RING_SIZE_32);
12444 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
12445 LPFC_MQ_RING_SIZE_64);
12448 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
12449 LPFC_MQ_RING_SIZE_128);
12452 list_for_each_entry(dmabuf, &mq->page_list, list) {
12453 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
12454 putPaddrLow(dmabuf->phys);
12455 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
12456 putPaddrHigh(dmabuf->phys);
12461 * lpfc_mq_create - Create a mailbox Queue on the HBA
12462 * @phba: HBA structure that indicates port to create a queue on.
12463 * @mq: The queue structure to use to create the mailbox queue.
12464 * @cq: The completion queue to associate with this cq.
12465 * @subtype: The queue's subtype.
12467 * This function creates a mailbox queue, as detailed in @mq, on a port,
12468 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12470 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12471 * is used to get the entry count and entry size that are necessary to
12472 * determine the number of pages to allocate and use for this queue. This
12473 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12474 * mailbox queue. This function is asynchronous and will wait for the mailbox
12475 * command to finish before continuing.
12477 * On success this function will return a zero. If unable to allocate enough
12478 * memory this function will return -ENOMEM. If the queue create mailbox command
12479 * fails this function will return -ENXIO.
12482 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
12483 struct lpfc_queue *cq, uint32_t subtype)
12485 struct lpfc_mbx_mq_create *mq_create;
12486 struct lpfc_mbx_mq_create_ext *mq_create_ext;
12487 struct lpfc_dmabuf *dmabuf;
12488 LPFC_MBOXQ_t *mbox;
12489 int rc, length, status = 0;
12490 uint32_t shdr_status, shdr_add_status;
12491 union lpfc_sli4_cfg_shdr *shdr;
12492 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12494 /* sanity check on queue memory */
12497 if (!phba->sli4_hba.pc_sli4_params.supported)
12498 hw_page_size = SLI4_PAGE_SIZE;
12500 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12503 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
12504 sizeof(struct lpfc_sli4_cfg_mhdr));
12505 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12506 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
12507 length, LPFC_SLI4_MBX_EMBED);
12509 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
12510 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
12511 bf_set(lpfc_mbx_mq_create_ext_num_pages,
12512 &mq_create_ext->u.request, mq->page_count);
12513 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
12514 &mq_create_ext->u.request, 1);
12515 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
12516 &mq_create_ext->u.request, 1);
12517 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
12518 &mq_create_ext->u.request, 1);
12519 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
12520 &mq_create_ext->u.request, 1);
12521 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
12522 &mq_create_ext->u.request, 1);
12523 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
12524 bf_set(lpfc_mbox_hdr_version, &shdr->request,
12525 phba->sli4_hba.pc_sli4_params.mqv);
12526 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
12527 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
12530 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
12532 switch (mq->entry_count) {
12534 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12535 "0362 Unsupported MQ count. (%d)\n",
12537 if (mq->entry_count < 16) {
12541 /* otherwise default to smallest count (drop through) */
12543 bf_set(lpfc_mq_context_ring_size,
12544 &mq_create_ext->u.request.context,
12545 LPFC_MQ_RING_SIZE_16);
12548 bf_set(lpfc_mq_context_ring_size,
12549 &mq_create_ext->u.request.context,
12550 LPFC_MQ_RING_SIZE_32);
12553 bf_set(lpfc_mq_context_ring_size,
12554 &mq_create_ext->u.request.context,
12555 LPFC_MQ_RING_SIZE_64);
12558 bf_set(lpfc_mq_context_ring_size,
12559 &mq_create_ext->u.request.context,
12560 LPFC_MQ_RING_SIZE_128);
12563 list_for_each_entry(dmabuf, &mq->page_list, list) {
12564 memset(dmabuf->virt, 0, hw_page_size);
12565 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
12566 putPaddrLow(dmabuf->phys);
12567 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
12568 putPaddrHigh(dmabuf->phys);
12570 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12571 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
12572 &mq_create_ext->u.response);
12573 if (rc != MBX_SUCCESS) {
12574 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12575 "2795 MQ_CREATE_EXT failed with "
12576 "status x%x. Failback to MQ_CREATE.\n",
12578 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
12579 mq_create = &mbox->u.mqe.un.mq_create;
12580 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12581 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
12582 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
12583 &mq_create->u.response);
12586 /* The IOCTL status is embedded in the mailbox subheader. */
12587 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12588 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12589 if (shdr_status || shdr_add_status || rc) {
12590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12591 "2502 MQ_CREATE mailbox failed with "
12592 "status x%x add_status x%x, mbx status x%x\n",
12593 shdr_status, shdr_add_status, rc);
12597 if (mq->queue_id == 0xFFFF) {
12601 mq->type = LPFC_MQ;
12602 mq->assoc_qid = cq->queue_id;
12603 mq->subtype = subtype;
12604 mq->host_index = 0;
12607 /* link the mq onto the parent cq child list */
12608 list_add_tail(&mq->list, &cq->child_list);
12610 mempool_free(mbox, phba->mbox_mem_pool);
12615 * lpfc_wq_create - Create a Work Queue on the HBA
12616 * @phba: HBA structure that indicates port to create a queue on.
12617 * @wq: The queue structure to use to create the work queue.
12618 * @cq: The completion queue to bind this work queue to.
12619 * @subtype: The subtype of the work queue indicating its functionality.
12621 * This function creates a work queue, as detailed in @wq, on a port, described
12622 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12624 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12625 * is used to get the entry count and entry size that are necessary to
12626 * determine the number of pages to allocate and use for this queue. The @cq
12627 * is used to indicate which completion queue to bind this work queue to. This
12628 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12629 * work queue. This function is asynchronous and will wait for the mailbox
12630 * command to finish before continuing.
12632 * On success this function will return a zero. If unable to allocate enough
12633 * memory this function will return -ENOMEM. If the queue create mailbox command
12634 * fails this function will return -ENXIO.
12637 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
12638 struct lpfc_queue *cq, uint32_t subtype)
12640 struct lpfc_mbx_wq_create *wq_create;
12641 struct lpfc_dmabuf *dmabuf;
12642 LPFC_MBOXQ_t *mbox;
12643 int rc, length, status = 0;
12644 uint32_t shdr_status, shdr_add_status;
12645 union lpfc_sli4_cfg_shdr *shdr;
12646 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12647 struct dma_address *page;
12649 /* sanity check on queue memory */
12652 if (!phba->sli4_hba.pc_sli4_params.supported)
12653 hw_page_size = SLI4_PAGE_SIZE;
12655 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12658 length = (sizeof(struct lpfc_mbx_wq_create) -
12659 sizeof(struct lpfc_sli4_cfg_mhdr));
12660 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12661 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
12662 length, LPFC_SLI4_MBX_EMBED);
12663 wq_create = &mbox->u.mqe.un.wq_create;
12664 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
12665 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
12667 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
12669 bf_set(lpfc_mbox_hdr_version, &shdr->request,
12670 phba->sli4_hba.pc_sli4_params.wqv);
12671 if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
12672 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
12674 switch (wq->entry_size) {
12677 bf_set(lpfc_mbx_wq_create_wqe_size,
12678 &wq_create->u.request_1,
12679 LPFC_WQ_WQE_SIZE_64);
12682 bf_set(lpfc_mbx_wq_create_wqe_size,
12683 &wq_create->u.request_1,
12684 LPFC_WQ_WQE_SIZE_128);
12687 bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
12688 (PAGE_SIZE/SLI4_PAGE_SIZE));
12689 page = wq_create->u.request_1.page;
12691 page = wq_create->u.request.page;
12693 list_for_each_entry(dmabuf, &wq->page_list, list) {
12694 memset(dmabuf->virt, 0, hw_page_size);
12695 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
12696 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
12698 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12699 /* The IOCTL status is embedded in the mailbox subheader. */
12700 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12701 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12702 if (shdr_status || shdr_add_status || rc) {
12703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12704 "2503 WQ_CREATE mailbox failed with "
12705 "status x%x add_status x%x, mbx status x%x\n",
12706 shdr_status, shdr_add_status, rc);
12710 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
12711 if (wq->queue_id == 0xFFFF) {
12715 wq->type = LPFC_WQ;
12716 wq->assoc_qid = cq->queue_id;
12717 wq->subtype = subtype;
12718 wq->host_index = 0;
12720 wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
12722 /* link the wq onto the parent cq child list */
12723 list_add_tail(&wq->list, &cq->child_list);
12725 mempool_free(mbox, phba->mbox_mem_pool);
12730 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12731 * @phba: HBA structure that indicates port to create a queue on.
12732 * @rq: The queue structure to use for the receive queue.
12733 * @qno: The associated HBQ number
12736 * For SLI4 we need to adjust the RQ repost value based on
12737 * the number of buffers that are initially posted to the RQ.
12740 lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
12744 /* sanity check on queue memory */
12747 cnt = lpfc_hbq_defs[qno]->entry_count;
12749 /* Recalc repost for RQs based on buffers initially posted */
12751 if (cnt < LPFC_QUEUE_MIN_REPOST)
12752 cnt = LPFC_QUEUE_MIN_REPOST;
12754 rq->entry_repost = cnt;
12758 * lpfc_rq_create - Create a Receive Queue on the HBA
12759 * @phba: HBA structure that indicates port to create a queue on.
12760 * @hrq: The queue structure to use to create the header receive queue.
12761 * @drq: The queue structure to use to create the data receive queue.
12762 * @cq: The completion queue to bind this work queue to.
12764 * This function creates a receive buffer queue pair , as detailed in @hrq and
12765 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12768 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12769 * struct is used to get the entry count that is necessary to determine the
12770 * number of pages to use for this queue. The @cq is used to indicate which
12771 * completion queue to bind received buffers that are posted to these queues to.
12772 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12773 * receive queue pair. This function is asynchronous and will wait for the
12774 * mailbox command to finish before continuing.
12776 * On success this function will return a zero. If unable to allocate enough
12777 * memory this function will return -ENOMEM. If the queue create mailbox command
12778 * fails this function will return -ENXIO.
12781 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
12782 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
12784 struct lpfc_mbx_rq_create *rq_create;
12785 struct lpfc_dmabuf *dmabuf;
12786 LPFC_MBOXQ_t *mbox;
12787 int rc, length, status = 0;
12788 uint32_t shdr_status, shdr_add_status;
12789 union lpfc_sli4_cfg_shdr *shdr;
12790 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12792 /* sanity check on queue memory */
12793 if (!hrq || !drq || !cq)
12795 if (!phba->sli4_hba.pc_sli4_params.supported)
12796 hw_page_size = SLI4_PAGE_SIZE;
12798 if (hrq->entry_count != drq->entry_count)
12800 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12803 length = (sizeof(struct lpfc_mbx_rq_create) -
12804 sizeof(struct lpfc_sli4_cfg_mhdr));
12805 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12806 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
12807 length, LPFC_SLI4_MBX_EMBED);
12808 rq_create = &mbox->u.mqe.un.rq_create;
12809 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
12810 bf_set(lpfc_mbox_hdr_version, &shdr->request,
12811 phba->sli4_hba.pc_sli4_params.rqv);
12812 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
12813 bf_set(lpfc_rq_context_rqe_count_1,
12814 &rq_create->u.request.context,
12816 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
12817 bf_set(lpfc_rq_context_rqe_size,
12818 &rq_create->u.request.context,
12820 bf_set(lpfc_rq_context_page_size,
12821 &rq_create->u.request.context,
12822 (PAGE_SIZE/SLI4_PAGE_SIZE));
12824 switch (hrq->entry_count) {
12826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12827 "2535 Unsupported RQ count. (%d)\n",
12829 if (hrq->entry_count < 512) {
12833 /* otherwise default to smallest count (drop through) */
12835 bf_set(lpfc_rq_context_rqe_count,
12836 &rq_create->u.request.context,
12837 LPFC_RQ_RING_SIZE_512);
12840 bf_set(lpfc_rq_context_rqe_count,
12841 &rq_create->u.request.context,
12842 LPFC_RQ_RING_SIZE_1024);
12845 bf_set(lpfc_rq_context_rqe_count,
12846 &rq_create->u.request.context,
12847 LPFC_RQ_RING_SIZE_2048);
12850 bf_set(lpfc_rq_context_rqe_count,
12851 &rq_create->u.request.context,
12852 LPFC_RQ_RING_SIZE_4096);
12855 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
12856 LPFC_HDR_BUF_SIZE);
12858 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
12860 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
12862 list_for_each_entry(dmabuf, &hrq->page_list, list) {
12863 memset(dmabuf->virt, 0, hw_page_size);
12864 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
12865 putPaddrLow(dmabuf->phys);
12866 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
12867 putPaddrHigh(dmabuf->phys);
12869 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12870 /* The IOCTL status is embedded in the mailbox subheader. */
12871 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12872 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12873 if (shdr_status || shdr_add_status || rc) {
12874 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12875 "2504 RQ_CREATE mailbox failed with "
12876 "status x%x add_status x%x, mbx status x%x\n",
12877 shdr_status, shdr_add_status, rc);
12881 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
12882 if (hrq->queue_id == 0xFFFF) {
12886 hrq->type = LPFC_HRQ;
12887 hrq->assoc_qid = cq->queue_id;
12888 hrq->subtype = subtype;
12889 hrq->host_index = 0;
12890 hrq->hba_index = 0;
12892 /* now create the data queue */
12893 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12894 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
12895 length, LPFC_SLI4_MBX_EMBED);
12896 bf_set(lpfc_mbox_hdr_version, &shdr->request,
12897 phba->sli4_hba.pc_sli4_params.rqv);
12898 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
12899 bf_set(lpfc_rq_context_rqe_count_1,
12900 &rq_create->u.request.context, hrq->entry_count);
12901 rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
12902 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
12904 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
12905 (PAGE_SIZE/SLI4_PAGE_SIZE));
12907 switch (drq->entry_count) {
12909 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12910 "2536 Unsupported RQ count. (%d)\n",
12912 if (drq->entry_count < 512) {
12916 /* otherwise default to smallest count (drop through) */
12918 bf_set(lpfc_rq_context_rqe_count,
12919 &rq_create->u.request.context,
12920 LPFC_RQ_RING_SIZE_512);
12923 bf_set(lpfc_rq_context_rqe_count,
12924 &rq_create->u.request.context,
12925 LPFC_RQ_RING_SIZE_1024);
12928 bf_set(lpfc_rq_context_rqe_count,
12929 &rq_create->u.request.context,
12930 LPFC_RQ_RING_SIZE_2048);
12933 bf_set(lpfc_rq_context_rqe_count,
12934 &rq_create->u.request.context,
12935 LPFC_RQ_RING_SIZE_4096);
12938 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
12939 LPFC_DATA_BUF_SIZE);
12941 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
12943 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
12945 list_for_each_entry(dmabuf, &drq->page_list, list) {
12946 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
12947 putPaddrLow(dmabuf->phys);
12948 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
12949 putPaddrHigh(dmabuf->phys);
12951 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12952 /* The IOCTL status is embedded in the mailbox subheader. */
12953 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
12954 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12955 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12956 if (shdr_status || shdr_add_status || rc) {
12960 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
12961 if (drq->queue_id == 0xFFFF) {
12965 drq->type = LPFC_DRQ;
12966 drq->assoc_qid = cq->queue_id;
12967 drq->subtype = subtype;
12968 drq->host_index = 0;
12969 drq->hba_index = 0;
12971 /* link the header and data RQs onto the parent cq child list */
12972 list_add_tail(&hrq->list, &cq->child_list);
12973 list_add_tail(&drq->list, &cq->child_list);
12976 mempool_free(mbox, phba->mbox_mem_pool);
12981 * lpfc_eq_destroy - Destroy an event Queue on the HBA
12982 * @eq: The queue structure associated with the queue to destroy.
12984 * This function destroys a queue, as detailed in @eq by sending an mailbox
12985 * command, specific to the type of queue, to the HBA.
12987 * The @eq struct is used to get the queue ID of the queue to destroy.
12989 * On success this function will return a zero. If the queue destroy mailbox
12990 * command fails this function will return -ENXIO.
12993 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
12995 LPFC_MBOXQ_t *mbox;
12996 int rc, length, status = 0;
12997 uint32_t shdr_status, shdr_add_status;
12998 union lpfc_sli4_cfg_shdr *shdr;
13000 /* sanity check on queue memory */
13003 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
13006 length = (sizeof(struct lpfc_mbx_eq_destroy) -
13007 sizeof(struct lpfc_sli4_cfg_mhdr));
13008 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13009 LPFC_MBOX_OPCODE_EQ_DESTROY,
13010 length, LPFC_SLI4_MBX_EMBED);
13011 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
13013 mbox->vport = eq->phba->pport;
13014 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13016 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
13017 /* The IOCTL status is embedded in the mailbox subheader. */
13018 shdr = (union lpfc_sli4_cfg_shdr *)
13019 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
13020 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13021 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13022 if (shdr_status || shdr_add_status || rc) {
13023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13024 "2505 EQ_DESTROY mailbox failed with "
13025 "status x%x add_status x%x, mbx status x%x\n",
13026 shdr_status, shdr_add_status, rc);
13030 /* Remove eq from any list */
13031 list_del_init(&eq->list);
13032 mempool_free(mbox, eq->phba->mbox_mem_pool);
13037 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
13038 * @cq: The queue structure associated with the queue to destroy.
13040 * This function destroys a queue, as detailed in @cq by sending an mailbox
13041 * command, specific to the type of queue, to the HBA.
13043 * The @cq struct is used to get the queue ID of the queue to destroy.
13045 * On success this function will return a zero. If the queue destroy mailbox
13046 * command fails this function will return -ENXIO.
13049 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
13051 LPFC_MBOXQ_t *mbox;
13052 int rc, length, status = 0;
13053 uint32_t shdr_status, shdr_add_status;
13054 union lpfc_sli4_cfg_shdr *shdr;
13056 /* sanity check on queue memory */
13059 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
13062 length = (sizeof(struct lpfc_mbx_cq_destroy) -
13063 sizeof(struct lpfc_sli4_cfg_mhdr));
13064 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13065 LPFC_MBOX_OPCODE_CQ_DESTROY,
13066 length, LPFC_SLI4_MBX_EMBED);
13067 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
13069 mbox->vport = cq->phba->pport;
13070 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13071 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
13072 /* The IOCTL status is embedded in the mailbox subheader. */
13073 shdr = (union lpfc_sli4_cfg_shdr *)
13074 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
13075 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13076 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13077 if (shdr_status || shdr_add_status || rc) {
13078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13079 "2506 CQ_DESTROY mailbox failed with "
13080 "status x%x add_status x%x, mbx status x%x\n",
13081 shdr_status, shdr_add_status, rc);
13084 /* Remove cq from any list */
13085 list_del_init(&cq->list);
13086 mempool_free(mbox, cq->phba->mbox_mem_pool);
13091 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
13092 * @qm: The queue structure associated with the queue to destroy.
13094 * This function destroys a queue, as detailed in @mq by sending an mailbox
13095 * command, specific to the type of queue, to the HBA.
13097 * The @mq struct is used to get the queue ID of the queue to destroy.
13099 * On success this function will return a zero. If the queue destroy mailbox
13100 * command fails this function will return -ENXIO.
13103 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
13105 LPFC_MBOXQ_t *mbox;
13106 int rc, length, status = 0;
13107 uint32_t shdr_status, shdr_add_status;
13108 union lpfc_sli4_cfg_shdr *shdr;
13110 /* sanity check on queue memory */
13113 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
13116 length = (sizeof(struct lpfc_mbx_mq_destroy) -
13117 sizeof(struct lpfc_sli4_cfg_mhdr));
13118 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13119 LPFC_MBOX_OPCODE_MQ_DESTROY,
13120 length, LPFC_SLI4_MBX_EMBED);
13121 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
13123 mbox->vport = mq->phba->pport;
13124 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13125 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
13126 /* The IOCTL status is embedded in the mailbox subheader. */
13127 shdr = (union lpfc_sli4_cfg_shdr *)
13128 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
13129 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13130 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13131 if (shdr_status || shdr_add_status || rc) {
13132 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13133 "2507 MQ_DESTROY mailbox failed with "
13134 "status x%x add_status x%x, mbx status x%x\n",
13135 shdr_status, shdr_add_status, rc);
13138 /* Remove mq from any list */
13139 list_del_init(&mq->list);
13140 mempool_free(mbox, mq->phba->mbox_mem_pool);
13145 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
13146 * @wq: The queue structure associated with the queue to destroy.
13148 * This function destroys a queue, as detailed in @wq by sending an mailbox
13149 * command, specific to the type of queue, to the HBA.
13151 * The @wq struct is used to get the queue ID of the queue to destroy.
13153 * On success this function will return a zero. If the queue destroy mailbox
13154 * command fails this function will return -ENXIO.
13157 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
13159 LPFC_MBOXQ_t *mbox;
13160 int rc, length, status = 0;
13161 uint32_t shdr_status, shdr_add_status;
13162 union lpfc_sli4_cfg_shdr *shdr;
13164 /* sanity check on queue memory */
13167 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
13170 length = (sizeof(struct lpfc_mbx_wq_destroy) -
13171 sizeof(struct lpfc_sli4_cfg_mhdr));
13172 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13173 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
13174 length, LPFC_SLI4_MBX_EMBED);
13175 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
13177 mbox->vport = wq->phba->pport;
13178 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13179 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
13180 shdr = (union lpfc_sli4_cfg_shdr *)
13181 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
13182 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13183 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13184 if (shdr_status || shdr_add_status || rc) {
13185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13186 "2508 WQ_DESTROY mailbox failed with "
13187 "status x%x add_status x%x, mbx status x%x\n",
13188 shdr_status, shdr_add_status, rc);
13191 /* Remove wq from any list */
13192 list_del_init(&wq->list);
13193 mempool_free(mbox, wq->phba->mbox_mem_pool);
13198 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
13199 * @rq: The queue structure associated with the queue to destroy.
13201 * This function destroys a queue, as detailed in @rq by sending an mailbox
13202 * command, specific to the type of queue, to the HBA.
13204 * The @rq struct is used to get the queue ID of the queue to destroy.
13206 * On success this function will return a zero. If the queue destroy mailbox
13207 * command fails this function will return -ENXIO.
13210 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
13211 struct lpfc_queue *drq)
13213 LPFC_MBOXQ_t *mbox;
13214 int rc, length, status = 0;
13215 uint32_t shdr_status, shdr_add_status;
13216 union lpfc_sli4_cfg_shdr *shdr;
13218 /* sanity check on queue memory */
13221 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
13224 length = (sizeof(struct lpfc_mbx_rq_destroy) -
13225 sizeof(struct lpfc_sli4_cfg_mhdr));
13226 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13227 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
13228 length, LPFC_SLI4_MBX_EMBED);
13229 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
13231 mbox->vport = hrq->phba->pport;
13232 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13233 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
13234 /* The IOCTL status is embedded in the mailbox subheader. */
13235 shdr = (union lpfc_sli4_cfg_shdr *)
13236 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
13237 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13238 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13239 if (shdr_status || shdr_add_status || rc) {
13240 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13241 "2509 RQ_DESTROY mailbox failed with "
13242 "status x%x add_status x%x, mbx status x%x\n",
13243 shdr_status, shdr_add_status, rc);
13244 if (rc != MBX_TIMEOUT)
13245 mempool_free(mbox, hrq->phba->mbox_mem_pool);
13248 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
13250 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
13251 shdr = (union lpfc_sli4_cfg_shdr *)
13252 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
13253 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13254 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13255 if (shdr_status || shdr_add_status || rc) {
13256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13257 "2510 RQ_DESTROY mailbox failed with "
13258 "status x%x add_status x%x, mbx status x%x\n",
13259 shdr_status, shdr_add_status, rc);
13262 list_del_init(&hrq->list);
13263 list_del_init(&drq->list);
13264 mempool_free(mbox, hrq->phba->mbox_mem_pool);
13269 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
13270 * @phba: The virtual port for which this call being executed.
13271 * @pdma_phys_addr0: Physical address of the 1st SGL page.
13272 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
13273 * @xritag: the xritag that ties this io to the SGL pages.
13275 * This routine will post the sgl pages for the IO that has the xritag
13276 * that is in the iocbq structure. The xritag is assigned during iocbq
13277 * creation and persists for as long as the driver is loaded.
13278 * if the caller has fewer than 256 scatter gather segments to map then
13279 * pdma_phys_addr1 should be 0.
13280 * If the caller needs to map more than 256 scatter gather segment then
13281 * pdma_phys_addr1 should be a valid physical address.
13282 * physical address for SGLs must be 64 byte aligned.
13283 * If you are going to map 2 SGL's then the first one must have 256 entries
13284 * the second sgl can have between 1 and 256 entries.
13288 * -ENXIO, -ENOMEM - Failure
13291 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
13292 dma_addr_t pdma_phys_addr0,
13293 dma_addr_t pdma_phys_addr1,
13296 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
13297 LPFC_MBOXQ_t *mbox;
13299 uint32_t shdr_status, shdr_add_status;
13301 union lpfc_sli4_cfg_shdr *shdr;
13303 if (xritag == NO_XRI) {
13304 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13305 "0364 Invalid param:\n");
13309 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13313 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13314 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
13315 sizeof(struct lpfc_mbx_post_sgl_pages) -
13316 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
13318 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
13319 &mbox->u.mqe.un.post_sgl_pages;
13320 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
13321 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
13323 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
13324 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
13325 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
13326 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
13328 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
13329 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
13330 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
13331 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
13332 if (!phba->sli4_hba.intr_enable)
13333 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13335 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
13336 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
13338 /* The IOCTL status is embedded in the mailbox subheader. */
13339 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
13340 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13341 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13342 if (rc != MBX_TIMEOUT)
13343 mempool_free(mbox, phba->mbox_mem_pool);
13344 if (shdr_status || shdr_add_status || rc) {
13345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13346 "2511 POST_SGL mailbox failed with "
13347 "status x%x add_status x%x, mbx status x%x\n",
13348 shdr_status, shdr_add_status, rc);
13355 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13356 * @phba: pointer to lpfc hba data structure.
13358 * This routine is invoked to post rpi header templates to the
13359 * HBA consistent with the SLI-4 interface spec. This routine
13360 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13361 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13364 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13365 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13368 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
13373 * Fetch the next logical xri. Because this index is logical,
13374 * the driver starts at 0 each time.
13376 spin_lock_irq(&phba->hbalock);
13377 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
13378 phba->sli4_hba.max_cfg_param.max_xri, 0);
13379 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
13380 spin_unlock_irq(&phba->hbalock);
13383 set_bit(xri, phba->sli4_hba.xri_bmask);
13384 phba->sli4_hba.max_cfg_param.xri_used++;
13386 spin_unlock_irq(&phba->hbalock);
13391 * lpfc_sli4_free_xri - Release an xri for reuse.
13392 * @phba: pointer to lpfc hba data structure.
13394 * This routine is invoked to release an xri to the pool of
13395 * available rpis maintained by the driver.
13398 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
13400 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
13401 phba->sli4_hba.max_cfg_param.xri_used--;
13406 * lpfc_sli4_free_xri - Release an xri for reuse.
13407 * @phba: pointer to lpfc hba data structure.
13409 * This routine is invoked to release an xri to the pool of
13410 * available rpis maintained by the driver.
13413 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
13415 spin_lock_irq(&phba->hbalock);
13416 __lpfc_sli4_free_xri(phba, xri);
13417 spin_unlock_irq(&phba->hbalock);
13421 * lpfc_sli4_next_xritag - Get an xritag for the io
13422 * @phba: Pointer to HBA context object.
13424 * This function gets an xritag for the iocb. If there is no unused xritag
13425 * it will return 0xffff.
13426 * The function returns the allocated xritag if successful, else returns zero.
13427 * Zero is not a valid xritag.
13428 * The caller is not required to hold any lock.
13431 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
13433 uint16_t xri_index;
13435 xri_index = lpfc_sli4_alloc_xri(phba);
13436 if (xri_index == NO_XRI)
13437 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13438 "2004 Failed to allocate XRI.last XRITAG is %d"
13439 " Max XRI is %d, Used XRI is %d\n",
13441 phba->sli4_hba.max_cfg_param.max_xri,
13442 phba->sli4_hba.max_cfg_param.xri_used);
13447 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13448 * @phba: pointer to lpfc hba data structure.
13449 * @post_sgl_list: pointer to els sgl entry list.
13450 * @count: number of els sgl entries on the list.
13452 * This routine is invoked to post a block of driver's sgl pages to the
13453 * HBA using non-embedded mailbox command. No Lock is held. This routine
13454 * is only called when the driver is loading and after all IO has been
13458 lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
13459 struct list_head *post_sgl_list,
13462 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
13463 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
13464 struct sgl_page_pairs *sgl_pg_pairs;
13466 LPFC_MBOXQ_t *mbox;
13467 uint32_t reqlen, alloclen, pg_pairs;
13469 uint16_t xritag_start = 0;
13471 uint32_t shdr_status, shdr_add_status;
13472 union lpfc_sli4_cfg_shdr *shdr;
13474 reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
13475 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
13476 if (reqlen > SLI4_PAGE_SIZE) {
13477 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13478 "2559 Block sgl registration required DMA "
13479 "size (%d) great than a page\n", reqlen);
13482 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13486 /* Allocate DMA memory and set up the non-embedded mailbox command */
13487 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13488 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
13489 LPFC_SLI4_MBX_NEMBED);
13491 if (alloclen < reqlen) {
13492 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13493 "0285 Allocated DMA memory size (%d) is "
13494 "less than the requested DMA memory "
13495 "size (%d)\n", alloclen, reqlen);
13496 lpfc_sli4_mbox_cmd_free(phba, mbox);
13499 /* Set up the SGL pages in the non-embedded DMA pages */
13500 viraddr = mbox->sge_array->addr[0];
13501 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
13502 sgl_pg_pairs = &sgl->sgl_pg_pairs;
13505 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
13506 /* Set up the sge entry */
13507 sgl_pg_pairs->sgl_pg0_addr_lo =
13508 cpu_to_le32(putPaddrLow(sglq_entry->phys));
13509 sgl_pg_pairs->sgl_pg0_addr_hi =
13510 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
13511 sgl_pg_pairs->sgl_pg1_addr_lo =
13512 cpu_to_le32(putPaddrLow(0));
13513 sgl_pg_pairs->sgl_pg1_addr_hi =
13514 cpu_to_le32(putPaddrHigh(0));
13516 /* Keep the first xritag on the list */
13518 xritag_start = sglq_entry->sli4_xritag;
13523 /* Complete initialization and perform endian conversion. */
13524 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
13525 bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
13526 sgl->word0 = cpu_to_le32(sgl->word0);
13527 if (!phba->sli4_hba.intr_enable)
13528 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13530 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
13531 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
13533 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
13534 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13535 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13536 if (rc != MBX_TIMEOUT)
13537 lpfc_sli4_mbox_cmd_free(phba, mbox);
13538 if (shdr_status || shdr_add_status || rc) {
13539 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13540 "2513 POST_SGL_BLOCK mailbox command failed "
13541 "status x%x add_status x%x mbx status x%x\n",
13542 shdr_status, shdr_add_status, rc);
13549 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13550 * @phba: pointer to lpfc hba data structure.
13551 * @sblist: pointer to scsi buffer list.
13552 * @count: number of scsi buffers on the list.
13554 * This routine is invoked to post a block of @count scsi sgl pages from a
13555 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13560 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
13561 struct list_head *sblist,
13564 struct lpfc_scsi_buf *psb;
13565 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
13566 struct sgl_page_pairs *sgl_pg_pairs;
13568 LPFC_MBOXQ_t *mbox;
13569 uint32_t reqlen, alloclen, pg_pairs;
13571 uint16_t xritag_start = 0;
13573 uint32_t shdr_status, shdr_add_status;
13574 dma_addr_t pdma_phys_bpl1;
13575 union lpfc_sli4_cfg_shdr *shdr;
13577 /* Calculate the requested length of the dma memory */
13578 reqlen = count * sizeof(struct sgl_page_pairs) +
13579 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
13580 if (reqlen > SLI4_PAGE_SIZE) {
13581 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13582 "0217 Block sgl registration required DMA "
13583 "size (%d) great than a page\n", reqlen);
13586 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13588 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13589 "0283 Failed to allocate mbox cmd memory\n");
13593 /* Allocate DMA memory and set up the non-embedded mailbox command */
13594 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13595 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
13596 LPFC_SLI4_MBX_NEMBED);
13598 if (alloclen < reqlen) {
13599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13600 "2561 Allocated DMA memory size (%d) is "
13601 "less than the requested DMA memory "
13602 "size (%d)\n", alloclen, reqlen);
13603 lpfc_sli4_mbox_cmd_free(phba, mbox);
13607 /* Get the first SGE entry from the non-embedded DMA memory */
13608 viraddr = mbox->sge_array->addr[0];
13610 /* Set up the SGL pages in the non-embedded DMA pages */
13611 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
13612 sgl_pg_pairs = &sgl->sgl_pg_pairs;
13615 list_for_each_entry(psb, sblist, list) {
13616 /* Set up the sge entry */
13617 sgl_pg_pairs->sgl_pg0_addr_lo =
13618 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
13619 sgl_pg_pairs->sgl_pg0_addr_hi =
13620 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
13621 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
13622 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
13624 pdma_phys_bpl1 = 0;
13625 sgl_pg_pairs->sgl_pg1_addr_lo =
13626 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
13627 sgl_pg_pairs->sgl_pg1_addr_hi =
13628 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
13629 /* Keep the first xritag on the list */
13631 xritag_start = psb->cur_iocbq.sli4_xritag;
13635 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
13636 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
13637 /* Perform endian conversion if necessary */
13638 sgl->word0 = cpu_to_le32(sgl->word0);
13640 if (!phba->sli4_hba.intr_enable)
13641 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13643 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
13644 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
13646 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
13647 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13648 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13649 if (rc != MBX_TIMEOUT)
13650 lpfc_sli4_mbox_cmd_free(phba, mbox);
13651 if (shdr_status || shdr_add_status || rc) {
13652 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13653 "2564 POST_SGL_BLOCK mailbox command failed "
13654 "status x%x add_status x%x mbx status x%x\n",
13655 shdr_status, shdr_add_status, rc);
13662 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13663 * @phba: pointer to lpfc_hba struct that the frame was received on
13664 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13666 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13667 * valid type of frame that the LPFC driver will handle. This function will
13668 * return a zero if the frame is a valid frame or a non zero value when the
13669 * frame does not pass the check.
13672 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
13674 /* make rctl_names static to save stack space */
13675 static char *rctl_names[] = FC_RCTL_NAMES_INIT;
13676 char *type_names[] = FC_TYPE_NAMES_INIT;
13677 struct fc_vft_header *fc_vft_hdr;
13678 uint32_t *header = (uint32_t *) fc_hdr;
13680 switch (fc_hdr->fh_r_ctl) {
13681 case FC_RCTL_DD_UNCAT: /* uncategorized information */
13682 case FC_RCTL_DD_SOL_DATA: /* solicited data */
13683 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
13684 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
13685 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
13686 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
13687 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
13688 case FC_RCTL_DD_CMD_STATUS: /* command status */
13689 case FC_RCTL_ELS_REQ: /* extended link services request */
13690 case FC_RCTL_ELS_REP: /* extended link services reply */
13691 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
13692 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
13693 case FC_RCTL_BA_NOP: /* basic link service NOP */
13694 case FC_RCTL_BA_ABTS: /* basic link service abort */
13695 case FC_RCTL_BA_RMC: /* remove connection */
13696 case FC_RCTL_BA_ACC: /* basic accept */
13697 case FC_RCTL_BA_RJT: /* basic reject */
13698 case FC_RCTL_BA_PRMT:
13699 case FC_RCTL_ACK_1: /* acknowledge_1 */
13700 case FC_RCTL_ACK_0: /* acknowledge_0 */
13701 case FC_RCTL_P_RJT: /* port reject */
13702 case FC_RCTL_F_RJT: /* fabric reject */
13703 case FC_RCTL_P_BSY: /* port busy */
13704 case FC_RCTL_F_BSY: /* fabric busy to data frame */
13705 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
13706 case FC_RCTL_LCR: /* link credit reset */
13707 case FC_RCTL_END: /* end */
13709 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
13710 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
13711 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
13712 return lpfc_fc_frame_check(phba, fc_hdr);
13716 switch (fc_hdr->fh_type) {
13728 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
13729 "2538 Received frame rctl:%s type:%s "
13730 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13731 rctl_names[fc_hdr->fh_r_ctl],
13732 type_names[fc_hdr->fh_type],
13733 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
13734 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
13735 be32_to_cpu(header[4]), be32_to_cpu(header[5]));
13738 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
13739 "2539 Dropped frame rctl:%s type:%s\n",
13740 rctl_names[fc_hdr->fh_r_ctl],
13741 type_names[fc_hdr->fh_type]);
13746 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13747 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13749 * This function processes the FC header to retrieve the VFI from the VF
13750 * header, if one exists. This function will return the VFI if one exists
13751 * or 0 if no VSAN Header exists.
13754 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
13756 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
13758 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
13760 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
13764 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13765 * @phba: Pointer to the HBA structure to search for the vport on
13766 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13767 * @fcfi: The FC Fabric ID that the frame came from
13769 * This function searches the @phba for a vport that matches the content of the
13770 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13771 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13772 * returns the matching vport pointer or NULL if unable to match frame to a
13775 static struct lpfc_vport *
13776 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
13779 struct lpfc_vport **vports;
13780 struct lpfc_vport *vport = NULL;
13782 uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
13783 fc_hdr->fh_d_id[1] << 8 |
13784 fc_hdr->fh_d_id[2]);
13786 if (did == Fabric_DID)
13787 return phba->pport;
13788 if ((phba->pport->fc_flag & FC_PT2PT) &&
13789 !(phba->link_state == LPFC_HBA_READY))
13790 return phba->pport;
13792 vports = lpfc_create_vport_work_array(phba);
13793 if (vports != NULL)
13794 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
13795 if (phba->fcf.fcfi == fcfi &&
13796 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
13797 vports[i]->fc_myDID == did) {
13802 lpfc_destroy_vport_work_array(phba, vports);
13807 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13808 * @vport: The vport to work on.
13810 * This function updates the receive sequence time stamp for this vport. The
13811 * receive sequence time stamp indicates the time that the last frame of the
13812 * the sequence that has been idle for the longest amount of time was received.
13813 * the driver uses this time stamp to indicate if any received sequences have
13817 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
13819 struct lpfc_dmabuf *h_buf;
13820 struct hbq_dmabuf *dmabuf = NULL;
13822 /* get the oldest sequence on the rcv list */
13823 h_buf = list_get_first(&vport->rcv_buffer_list,
13824 struct lpfc_dmabuf, list);
13827 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13828 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
13832 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13833 * @vport: The vport that the received sequences were sent to.
13835 * This function cleans up all outstanding received sequences. This is called
13836 * by the driver when a link event or user action invalidates all the received
13840 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
13842 struct lpfc_dmabuf *h_buf, *hnext;
13843 struct lpfc_dmabuf *d_buf, *dnext;
13844 struct hbq_dmabuf *dmabuf = NULL;
13846 /* start with the oldest sequence on the rcv list */
13847 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
13848 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13849 list_del_init(&dmabuf->hbuf.list);
13850 list_for_each_entry_safe(d_buf, dnext,
13851 &dmabuf->dbuf.list, list) {
13852 list_del_init(&d_buf->list);
13853 lpfc_in_buf_free(vport->phba, d_buf);
13855 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
13860 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13861 * @vport: The vport that the received sequences were sent to.
13863 * This function determines whether any received sequences have timed out by
13864 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13865 * indicates that there is at least one timed out sequence this routine will
13866 * go through the received sequences one at a time from most inactive to most
13867 * active to determine which ones need to be cleaned up. Once it has determined
13868 * that a sequence needs to be cleaned up it will simply free up the resources
13869 * without sending an abort.
13872 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
13874 struct lpfc_dmabuf *h_buf, *hnext;
13875 struct lpfc_dmabuf *d_buf, *dnext;
13876 struct hbq_dmabuf *dmabuf = NULL;
13877 unsigned long timeout;
13878 int abort_count = 0;
13880 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
13881 vport->rcv_buffer_time_stamp);
13882 if (list_empty(&vport->rcv_buffer_list) ||
13883 time_before(jiffies, timeout))
13885 /* start with the oldest sequence on the rcv list */
13886 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
13887 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13888 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
13889 dmabuf->time_stamp);
13890 if (time_before(jiffies, timeout))
13893 list_del_init(&dmabuf->hbuf.list);
13894 list_for_each_entry_safe(d_buf, dnext,
13895 &dmabuf->dbuf.list, list) {
13896 list_del_init(&d_buf->list);
13897 lpfc_in_buf_free(vport->phba, d_buf);
13899 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
13902 lpfc_update_rcv_time_stamp(vport);
13906 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13907 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13909 * This function searches through the existing incomplete sequences that have
13910 * been sent to this @vport. If the frame matches one of the incomplete
13911 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13912 * make up that sequence. If no sequence is found that matches this frame then
13913 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13914 * This function returns a pointer to the first dmabuf in the sequence list that
13915 * the frame was linked to.
13917 static struct hbq_dmabuf *
13918 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
13920 struct fc_frame_header *new_hdr;
13921 struct fc_frame_header *temp_hdr;
13922 struct lpfc_dmabuf *d_buf;
13923 struct lpfc_dmabuf *h_buf;
13924 struct hbq_dmabuf *seq_dmabuf = NULL;
13925 struct hbq_dmabuf *temp_dmabuf = NULL;
13927 INIT_LIST_HEAD(&dmabuf->dbuf.list);
13928 dmabuf->time_stamp = jiffies;
13929 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
13930 /* Use the hdr_buf to find the sequence that this frame belongs to */
13931 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
13932 temp_hdr = (struct fc_frame_header *)h_buf->virt;
13933 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
13934 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
13935 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
13937 /* found a pending sequence that matches this frame */
13938 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
13943 * This indicates first frame received for this sequence.
13944 * Queue the buffer on the vport's rcv_buffer_list.
13946 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
13947 lpfc_update_rcv_time_stamp(vport);
13950 temp_hdr = seq_dmabuf->hbuf.virt;
13951 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
13952 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
13953 list_del_init(&seq_dmabuf->hbuf.list);
13954 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
13955 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
13956 lpfc_update_rcv_time_stamp(vport);
13959 /* move this sequence to the tail to indicate a young sequence */
13960 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
13961 seq_dmabuf->time_stamp = jiffies;
13962 lpfc_update_rcv_time_stamp(vport);
13963 if (list_empty(&seq_dmabuf->dbuf.list)) {
13964 temp_hdr = dmabuf->hbuf.virt;
13965 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
13968 /* find the correct place in the sequence to insert this frame */
13969 list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
13970 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
13971 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
13973 * If the frame's sequence count is greater than the frame on
13974 * the list then insert the frame right after this frame
13976 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
13977 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
13978 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
13986 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
13987 * @vport: pointer to a vitural port
13988 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13990 * This function tries to abort from the partially assembed sequence, described
13991 * by the information from basic abbort @dmabuf. It checks to see whether such
13992 * partially assembled sequence held by the driver. If so, it shall free up all
13993 * the frames from the partially assembled sequence.
13996 * true -- if there is matching partially assembled sequence present and all
13997 * the frames freed with the sequence;
13998 * false -- if there is no matching partially assembled sequence present so
13999 * nothing got aborted in the lower layer driver
14002 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
14003 struct hbq_dmabuf *dmabuf)
14005 struct fc_frame_header *new_hdr;
14006 struct fc_frame_header *temp_hdr;
14007 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
14008 struct hbq_dmabuf *seq_dmabuf = NULL;
14010 /* Use the hdr_buf to find the sequence that matches this frame */
14011 INIT_LIST_HEAD(&dmabuf->dbuf.list);
14012 INIT_LIST_HEAD(&dmabuf->hbuf.list);
14013 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
14014 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
14015 temp_hdr = (struct fc_frame_header *)h_buf->virt;
14016 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
14017 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
14018 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
14020 /* found a pending sequence that matches this frame */
14021 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
14025 /* Free up all the frames from the partially assembled sequence */
14027 list_for_each_entry_safe(d_buf, n_buf,
14028 &seq_dmabuf->dbuf.list, list) {
14029 list_del_init(&d_buf->list);
14030 lpfc_in_buf_free(vport->phba, d_buf);
14038 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14039 * @phba: Pointer to HBA context object.
14040 * @cmd_iocbq: pointer to the command iocbq structure.
14041 * @rsp_iocbq: pointer to the response iocbq structure.
14043 * This function handles the sequence abort response iocb command complete
14044 * event. It properly releases the memory allocated to the sequence abort
14048 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
14049 struct lpfc_iocbq *cmd_iocbq,
14050 struct lpfc_iocbq *rsp_iocbq)
14053 lpfc_sli_release_iocbq(phba, cmd_iocbq);
14055 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14056 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
14057 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14058 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14059 rsp_iocbq->iocb.ulpStatus,
14060 rsp_iocbq->iocb.un.ulpWord[4]);
14064 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14065 * @phba: Pointer to HBA context object.
14066 * @xri: xri id in transaction.
14068 * This function validates the xri maps to the known range of XRIs allocated an
14069 * used by the driver.
14072 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
14077 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
14078 if (xri == phba->sli4_hba.xri_ids[i])
14085 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14086 * @phba: Pointer to HBA context object.
14087 * @fc_hdr: pointer to a FC frame header.
14089 * This function sends a basic response to a previous unsol sequence abort
14090 * event after aborting the sequence handling.
14093 lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
14094 struct fc_frame_header *fc_hdr)
14096 struct lpfc_iocbq *ctiocb = NULL;
14097 struct lpfc_nodelist *ndlp;
14098 uint16_t oxid, rxid, xri, lxri;
14099 uint32_t sid, fctl;
14103 if (!lpfc_is_link_up(phba))
14106 sid = sli4_sid_from_fc_hdr(fc_hdr);
14107 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
14108 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
14110 ndlp = lpfc_findnode_did(phba->pport, sid);
14112 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
14113 "1268 Find ndlp returned NULL for oxid:x%x "
14114 "SID:x%x\n", oxid, sid);
14118 /* Allocate buffer for rsp iocb */
14119 ctiocb = lpfc_sli_get_iocbq(phba);
14123 /* Extract the F_CTL field from FC_HDR */
14124 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
14126 icmd = &ctiocb->iocb;
14127 icmd->un.xseq64.bdl.bdeSize = 0;
14128 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
14129 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
14130 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
14131 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
14133 /* Fill in the rest of iocb fields */
14134 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
14135 icmd->ulpBdeCount = 0;
14137 icmd->ulpClass = CLASS3;
14138 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
14139 ctiocb->context1 = ndlp;
14141 ctiocb->iocb_cmpl = NULL;
14142 ctiocb->vport = phba->pport;
14143 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
14144 ctiocb->sli4_lxritag = NO_XRI;
14145 ctiocb->sli4_xritag = NO_XRI;
14147 if (fctl & FC_FC_EX_CTX)
14148 /* Exchange responder sent the abort so we
14154 lxri = lpfc_sli4_xri_inrange(phba, xri);
14155 if (lxri != NO_XRI)
14156 lpfc_set_rrq_active(phba, ndlp, lxri,
14157 (xri == oxid) ? rxid : oxid, 0);
14158 /* If the oxid maps to the FCP XRI range or if it is out of range,
14159 * send a BLS_RJT. The driver no longer has that exchange.
14160 * Override the IOCB for a BA_RJT.
14162 if (xri > (phba->sli4_hba.max_cfg_param.max_xri +
14163 phba->sli4_hba.max_cfg_param.xri_base) ||
14164 xri > (lpfc_sli4_get_els_iocb_cnt(phba) +
14165 phba->sli4_hba.max_cfg_param.xri_base)) {
14166 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
14167 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
14168 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
14169 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
14172 if (fctl & FC_FC_EX_CTX) {
14173 /* ABTS sent by responder to CT exchange, construction
14174 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14175 * field and RX_ID from ABTS for RX_ID field.
14177 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
14179 /* ABTS sent by initiator to CT exchange, construction
14180 * of BA_ACC will need to allocate a new XRI as for the
14183 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
14185 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
14186 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
14188 /* Xmit CT abts response on exchange <xid> */
14189 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
14190 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14191 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
14193 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
14194 if (rc == IOCB_ERROR) {
14195 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
14196 "2925 Failed to issue CT ABTS RSP x%x on "
14197 "xri x%x, Data x%x\n",
14198 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
14200 lpfc_sli_release_iocbq(phba, ctiocb);
14205 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14206 * @vport: Pointer to the vport on which this sequence was received
14207 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14209 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14210 * receive sequence is only partially assembed by the driver, it shall abort
14211 * the partially assembled frames for the sequence. Otherwise, if the
14212 * unsolicited receive sequence has been completely assembled and passed to
14213 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14214 * unsolicited sequence has been aborted. After that, it will issue a basic
14215 * accept to accept the abort.
14218 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
14219 struct hbq_dmabuf *dmabuf)
14221 struct lpfc_hba *phba = vport->phba;
14222 struct fc_frame_header fc_hdr;
14226 /* Make a copy of fc_hdr before the dmabuf being released */
14227 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
14228 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
14230 if (fctl & FC_FC_EX_CTX) {
14232 * ABTS sent by responder to exchange, just free the buffer
14234 lpfc_in_buf_free(phba, &dmabuf->dbuf);
14237 * ABTS sent by initiator to exchange, need to do cleanup
14239 /* Try to abort partially assembled seq */
14240 abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
14242 /* Send abort to ULP if partially seq abort failed */
14243 if (abts_par == false)
14244 lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
14246 lpfc_in_buf_free(phba, &dmabuf->dbuf);
14248 /* Send basic accept (BA_ACC) to the abort requester */
14249 lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
14253 * lpfc_seq_complete - Indicates if a sequence is complete
14254 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14256 * This function checks the sequence, starting with the frame described by
14257 * @dmabuf, to see if all the frames associated with this sequence are present.
14258 * the frames associated with this sequence are linked to the @dmabuf using the
14259 * dbuf list. This function looks for two major things. 1) That the first frame
14260 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14261 * set. 3) That there are no holes in the sequence count. The function will
14262 * return 1 when the sequence is complete, otherwise it will return 0.
14265 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
14267 struct fc_frame_header *hdr;
14268 struct lpfc_dmabuf *d_buf;
14269 struct hbq_dmabuf *seq_dmabuf;
14273 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
14274 /* make sure first fame of sequence has a sequence count of zero */
14275 if (hdr->fh_seq_cnt != seq_count)
14277 fctl = (hdr->fh_f_ctl[0] << 16 |
14278 hdr->fh_f_ctl[1] << 8 |
14280 /* If last frame of sequence we can return success. */
14281 if (fctl & FC_FC_END_SEQ)
14283 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
14284 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
14285 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
14286 /* If there is a hole in the sequence count then fail. */
14287 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
14289 fctl = (hdr->fh_f_ctl[0] << 16 |
14290 hdr->fh_f_ctl[1] << 8 |
14292 /* If last frame of sequence we can return success. */
14293 if (fctl & FC_FC_END_SEQ)
14300 * lpfc_prep_seq - Prep sequence for ULP processing
14301 * @vport: Pointer to the vport on which this sequence was received
14302 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14304 * This function takes a sequence, described by a list of frames, and creates
14305 * a list of iocbq structures to describe the sequence. This iocbq list will be
14306 * used to issue to the generic unsolicited sequence handler. This routine
14307 * returns a pointer to the first iocbq in the list. If the function is unable
14308 * to allocate an iocbq then it throw out the received frames that were not
14309 * able to be described and return a pointer to the first iocbq. If unable to
14310 * allocate any iocbqs (including the first) this function will return NULL.
14312 static struct lpfc_iocbq *
14313 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
14315 struct hbq_dmabuf *hbq_buf;
14316 struct lpfc_dmabuf *d_buf, *n_buf;
14317 struct lpfc_iocbq *first_iocbq, *iocbq;
14318 struct fc_frame_header *fc_hdr;
14320 uint32_t len, tot_len;
14321 struct ulp_bde64 *pbde;
14323 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
14324 /* remove from receive buffer list */
14325 list_del_init(&seq_dmabuf->hbuf.list);
14326 lpfc_update_rcv_time_stamp(vport);
14327 /* get the Remote Port's SID */
14328 sid = sli4_sid_from_fc_hdr(fc_hdr);
14330 /* Get an iocbq struct to fill in. */
14331 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
14333 /* Initialize the first IOCB. */
14334 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
14335 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
14337 /* Check FC Header to see what TYPE of frame we are rcv'ing */
14338 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
14339 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
14340 first_iocbq->iocb.un.rcvels.parmRo =
14341 sli4_did_from_fc_hdr(fc_hdr);
14342 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
14344 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
14345 first_iocbq->iocb.ulpContext = NO_XRI;
14346 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
14347 be16_to_cpu(fc_hdr->fh_ox_id);
14348 /* iocbq is prepped for internal consumption. Physical vpi. */
14349 first_iocbq->iocb.unsli3.rcvsli3.vpi =
14350 vport->phba->vpi_ids[vport->vpi];
14351 /* put the first buffer into the first IOCBq */
14352 first_iocbq->context2 = &seq_dmabuf->dbuf;
14353 first_iocbq->context3 = NULL;
14354 first_iocbq->iocb.ulpBdeCount = 1;
14355 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
14356 LPFC_DATA_BUF_SIZE;
14357 first_iocbq->iocb.un.rcvels.remoteID = sid;
14358 tot_len = bf_get(lpfc_rcqe_length,
14359 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
14360 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
14362 iocbq = first_iocbq;
14364 * Each IOCBq can have two Buffers assigned, so go through the list
14365 * of buffers for this sequence and save two buffers in each IOCBq
14367 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
14369 lpfc_in_buf_free(vport->phba, d_buf);
14372 if (!iocbq->context3) {
14373 iocbq->context3 = d_buf;
14374 iocbq->iocb.ulpBdeCount++;
14375 pbde = (struct ulp_bde64 *)
14376 &iocbq->iocb.unsli3.sli3Words[4];
14377 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
14379 /* We need to get the size out of the right CQE */
14380 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
14381 len = bf_get(lpfc_rcqe_length,
14382 &hbq_buf->cq_event.cqe.rcqe_cmpl);
14383 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
14386 iocbq = lpfc_sli_get_iocbq(vport->phba);
14389 first_iocbq->iocb.ulpStatus =
14390 IOSTAT_FCP_RSP_ERROR;
14391 first_iocbq->iocb.un.ulpWord[4] =
14392 IOERR_NO_RESOURCES;
14394 lpfc_in_buf_free(vport->phba, d_buf);
14397 iocbq->context2 = d_buf;
14398 iocbq->context3 = NULL;
14399 iocbq->iocb.ulpBdeCount = 1;
14400 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
14401 LPFC_DATA_BUF_SIZE;
14403 /* We need to get the size out of the right CQE */
14404 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
14405 len = bf_get(lpfc_rcqe_length,
14406 &hbq_buf->cq_event.cqe.rcqe_cmpl);
14408 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
14410 iocbq->iocb.un.rcvels.remoteID = sid;
14411 list_add_tail(&iocbq->list, &first_iocbq->list);
14414 return first_iocbq;
14418 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
14419 struct hbq_dmabuf *seq_dmabuf)
14421 struct fc_frame_header *fc_hdr;
14422 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
14423 struct lpfc_hba *phba = vport->phba;
14425 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
14426 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
14428 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14429 "2707 Ring %d handler: Failed to allocate "
14430 "iocb Rctl x%x Type x%x received\n",
14432 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
14435 if (!lpfc_complete_unsol_iocb(phba,
14436 &phba->sli.ring[LPFC_ELS_RING],
14437 iocbq, fc_hdr->fh_r_ctl,
14439 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14440 "2540 Ring %d handler: unexpected Rctl "
14441 "x%x Type x%x received\n",
14443 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
14445 /* Free iocb created in lpfc_prep_seq */
14446 list_for_each_entry_safe(curr_iocb, next_iocb,
14447 &iocbq->list, list) {
14448 list_del_init(&curr_iocb->list);
14449 lpfc_sli_release_iocbq(phba, curr_iocb);
14451 lpfc_sli_release_iocbq(phba, iocbq);
14455 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14456 * @phba: Pointer to HBA context object.
14458 * This function is called with no lock held. This function processes all
14459 * the received buffers and gives it to upper layers when a received buffer
14460 * indicates that it is the final frame in the sequence. The interrupt
14461 * service routine processes received buffers at interrupt contexts and adds
14462 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14463 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14464 * appropriate receive function when the final frame in a sequence is received.
14467 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
14468 struct hbq_dmabuf *dmabuf)
14470 struct hbq_dmabuf *seq_dmabuf;
14471 struct fc_frame_header *fc_hdr;
14472 struct lpfc_vport *vport;
14476 /* Process each received buffer */
14477 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
14478 /* check to see if this a valid type of frame */
14479 if (lpfc_fc_frame_check(phba, fc_hdr)) {
14480 lpfc_in_buf_free(phba, &dmabuf->dbuf);
14483 if ((bf_get(lpfc_cqe_code,
14484 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
14485 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
14486 &dmabuf->cq_event.cqe.rcqe_cmpl);
14488 fcfi = bf_get(lpfc_rcqe_fcf_id,
14489 &dmabuf->cq_event.cqe.rcqe_cmpl);
14491 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
14493 /* throw out the frame */
14494 lpfc_in_buf_free(phba, &dmabuf->dbuf);
14498 /* d_id this frame is directed to */
14499 did = sli4_did_from_fc_hdr(fc_hdr);
14501 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
14502 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
14503 (did != Fabric_DID)) {
14505 * Throw out the frame if we are not pt2pt.
14506 * The pt2pt protocol allows for discovery frames
14507 * to be received without a registered VPI.
14509 if (!(vport->fc_flag & FC_PT2PT) ||
14510 (phba->link_state == LPFC_HBA_READY)) {
14511 lpfc_in_buf_free(phba, &dmabuf->dbuf);
14516 /* Handle the basic abort sequence (BA_ABTS) event */
14517 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
14518 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
14522 /* Link this frame */
14523 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
14525 /* unable to add frame to vport - throw it out */
14526 lpfc_in_buf_free(phba, &dmabuf->dbuf);
14529 /* If not last frame in sequence continue processing frames. */
14530 if (!lpfc_seq_complete(seq_dmabuf))
14533 /* Send the complete sequence to the upper layer protocol */
14534 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
14538 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14539 * @phba: pointer to lpfc hba data structure.
14541 * This routine is invoked to post rpi header templates to the
14542 * HBA consistent with the SLI-4 interface spec. This routine
14543 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14544 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14546 * This routine does not require any locks. It's usage is expected
14547 * to be driver load or reset recovery when the driver is
14552 * -EIO - The mailbox failed to complete successfully.
14553 * When this error occurs, the driver is not guaranteed
14554 * to have any rpi regions posted to the device and
14555 * must either attempt to repost the regions or take a
14559 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
14561 struct lpfc_rpi_hdr *rpi_page;
14565 /* SLI4 ports that support extents do not require RPI headers. */
14566 if (!phba->sli4_hba.rpi_hdrs_in_use)
14568 if (phba->sli4_hba.extents_in_use)
14571 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
14573 * Assign the rpi headers a physical rpi only if the driver
14574 * has not initialized those resources. A port reset only
14575 * needs the headers posted.
14577 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
14579 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
14581 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
14582 if (rc != MBX_SUCCESS) {
14583 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14584 "2008 Error %d posting all rpi "
14592 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
14593 LPFC_RPI_RSRC_RDY);
14598 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14599 * @phba: pointer to lpfc hba data structure.
14600 * @rpi_page: pointer to the rpi memory region.
14602 * This routine is invoked to post a single rpi header to the
14603 * HBA consistent with the SLI-4 interface spec. This memory region
14604 * maps up to 64 rpi context regions.
14608 * -ENOMEM - No available memory
14609 * -EIO - The mailbox failed to complete successfully.
14612 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
14614 LPFC_MBOXQ_t *mboxq;
14615 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
14617 uint32_t shdr_status, shdr_add_status;
14618 union lpfc_sli4_cfg_shdr *shdr;
14620 /* SLI4 ports that support extents do not require RPI headers. */
14621 if (!phba->sli4_hba.rpi_hdrs_in_use)
14623 if (phba->sli4_hba.extents_in_use)
14626 /* The port is notified of the header region via a mailbox command. */
14627 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14629 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14630 "2001 Unable to allocate memory for issuing "
14631 "SLI_CONFIG_SPECIAL mailbox command\n");
14635 /* Post all rpi memory regions to the port. */
14636 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
14637 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
14638 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
14639 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
14640 sizeof(struct lpfc_sli4_cfg_mhdr),
14641 LPFC_SLI4_MBX_EMBED);
14644 /* Post the physical rpi to the port for this rpi header. */
14645 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
14646 rpi_page->start_rpi);
14647 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
14648 hdr_tmpl, rpi_page->page_count);
14650 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
14651 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
14652 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
14653 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
14654 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14655 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14656 if (rc != MBX_TIMEOUT)
14657 mempool_free(mboxq, phba->mbox_mem_pool);
14658 if (shdr_status || shdr_add_status || rc) {
14659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14660 "2514 POST_RPI_HDR mailbox failed with "
14661 "status x%x add_status x%x, mbx status x%x\n",
14662 shdr_status, shdr_add_status, rc);
14669 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14670 * @phba: pointer to lpfc hba data structure.
14672 * This routine is invoked to post rpi header templates to the
14673 * HBA consistent with the SLI-4 interface spec. This routine
14674 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14675 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14678 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14679 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14682 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
14685 uint16_t max_rpi, rpi_limit;
14686 uint16_t rpi_remaining, lrpi = 0;
14687 struct lpfc_rpi_hdr *rpi_hdr;
14689 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
14690 rpi_limit = phba->sli4_hba.next_rpi;
14693 * Fetch the next logical rpi. Because this index is logical,
14694 * the driver starts at 0 each time.
14696 spin_lock_irq(&phba->hbalock);
14697 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
14698 if (rpi >= rpi_limit)
14699 rpi = LPFC_RPI_ALLOC_ERROR;
14701 set_bit(rpi, phba->sli4_hba.rpi_bmask);
14702 phba->sli4_hba.max_cfg_param.rpi_used++;
14703 phba->sli4_hba.rpi_count++;
14707 * Don't try to allocate more rpi header regions if the device limit
14708 * has been exhausted.
14710 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
14711 (phba->sli4_hba.rpi_count >= max_rpi)) {
14712 spin_unlock_irq(&phba->hbalock);
14717 * RPI header postings are not required for SLI4 ports capable of
14720 if (!phba->sli4_hba.rpi_hdrs_in_use) {
14721 spin_unlock_irq(&phba->hbalock);
14726 * If the driver is running low on rpi resources, allocate another
14727 * page now. Note that the next_rpi value is used because
14728 * it represents how many are actually in use whereas max_rpi notes
14729 * how many are supported max by the device.
14731 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
14732 spin_unlock_irq(&phba->hbalock);
14733 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
14734 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
14736 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14737 "2002 Error Could not grow rpi "
14740 lrpi = rpi_hdr->start_rpi;
14741 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
14742 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
14750 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14751 * @phba: pointer to lpfc hba data structure.
14753 * This routine is invoked to release an rpi to the pool of
14754 * available rpis maintained by the driver.
14757 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
14759 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
14760 phba->sli4_hba.rpi_count--;
14761 phba->sli4_hba.max_cfg_param.rpi_used--;
14766 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14767 * @phba: pointer to lpfc hba data structure.
14769 * This routine is invoked to release an rpi to the pool of
14770 * available rpis maintained by the driver.
14773 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
14775 spin_lock_irq(&phba->hbalock);
14776 __lpfc_sli4_free_rpi(phba, rpi);
14777 spin_unlock_irq(&phba->hbalock);
14781 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14782 * @phba: pointer to lpfc hba data structure.
14784 * This routine is invoked to remove the memory region that
14785 * provided rpi via a bitmask.
14788 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
14790 kfree(phba->sli4_hba.rpi_bmask);
14791 kfree(phba->sli4_hba.rpi_ids);
14792 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
14796 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14797 * @phba: pointer to lpfc hba data structure.
14799 * This routine is invoked to remove the memory region that
14800 * provided rpi via a bitmask.
14803 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
14804 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
14806 LPFC_MBOXQ_t *mboxq;
14807 struct lpfc_hba *phba = ndlp->phba;
14810 /* The port is notified of the header region via a mailbox command. */
14811 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14815 /* Post all rpi memory regions to the port. */
14816 lpfc_resume_rpi(mboxq, ndlp);
14818 mboxq->mbox_cmpl = cmpl;
14819 mboxq->context1 = arg;
14820 mboxq->context2 = ndlp;
14822 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14823 mboxq->vport = ndlp->vport;
14824 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14825 if (rc == MBX_NOT_FINISHED) {
14826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14827 "2010 Resume RPI Mailbox failed "
14828 "status %d, mbxStatus x%x\n", rc,
14829 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
14830 mempool_free(mboxq, phba->mbox_mem_pool);
14837 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14838 * @vport: Pointer to the vport for which the vpi is being initialized
14840 * This routine is invoked to activate a vpi with the port.
14844 * -Evalue otherwise
14847 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
14849 LPFC_MBOXQ_t *mboxq;
14851 int retval = MBX_SUCCESS;
14853 struct lpfc_hba *phba = vport->phba;
14854 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14857 lpfc_init_vpi(phba, mboxq, vport->vpi);
14858 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
14859 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
14860 if (rc != MBX_SUCCESS) {
14861 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
14862 "2022 INIT VPI Mailbox failed "
14863 "status %d, mbxStatus x%x\n", rc,
14864 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
14867 if (rc != MBX_TIMEOUT)
14868 mempool_free(mboxq, vport->phba->mbox_mem_pool);
14874 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14875 * @phba: pointer to lpfc hba data structure.
14876 * @mboxq: Pointer to mailbox object.
14878 * This routine is invoked to manually add a single FCF record. The caller
14879 * must pass a completely initialized FCF_Record. This routine takes
14880 * care of the nonembedded mailbox operations.
14883 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
14886 union lpfc_sli4_cfg_shdr *shdr;
14887 uint32_t shdr_status, shdr_add_status;
14889 virt_addr = mboxq->sge_array->addr[0];
14890 /* The IOCTL status is embedded in the mailbox subheader. */
14891 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
14892 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14893 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14895 if ((shdr_status || shdr_add_status) &&
14896 (shdr_status != STATUS_FCF_IN_USE))
14897 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14898 "2558 ADD_FCF_RECORD mailbox failed with "
14899 "status x%x add_status x%x\n",
14900 shdr_status, shdr_add_status);
14902 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14906 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14907 * @phba: pointer to lpfc hba data structure.
14908 * @fcf_record: pointer to the initialized fcf record to add.
14910 * This routine is invoked to manually add a single FCF record. The caller
14911 * must pass a completely initialized FCF_Record. This routine takes
14912 * care of the nonembedded mailbox operations.
14915 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
14918 LPFC_MBOXQ_t *mboxq;
14921 dma_addr_t phys_addr;
14922 struct lpfc_mbx_sge sge;
14923 uint32_t alloc_len, req_len;
14926 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14929 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14933 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
14936 /* Allocate DMA memory and set up the non-embedded mailbox command */
14937 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
14938 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
14939 req_len, LPFC_SLI4_MBX_NEMBED);
14940 if (alloc_len < req_len) {
14941 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14942 "2523 Allocated DMA memory size (x%x) is "
14943 "less than the requested DMA memory "
14944 "size (x%x)\n", alloc_len, req_len);
14945 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14950 * Get the first SGE entry from the non-embedded DMA memory. This
14951 * routine only uses a single SGE.
14953 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
14954 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
14955 virt_addr = mboxq->sge_array->addr[0];
14957 * Configure the FCF record for FCFI 0. This is the driver's
14958 * hardcoded default and gets used in nonFIP mode.
14960 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
14961 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
14962 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
14965 * Copy the fcf_index and the FCF Record Data. The data starts after
14966 * the FCoE header plus word10. The data copy needs to be endian
14969 bytep += sizeof(uint32_t);
14970 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
14971 mboxq->vport = phba->pport;
14972 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
14973 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
14974 if (rc == MBX_NOT_FINISHED) {
14975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14976 "2515 ADD_FCF_RECORD mailbox failed with "
14977 "status 0x%x\n", rc);
14978 lpfc_sli4_mbox_cmd_free(phba, mboxq);
14987 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
14988 * @phba: pointer to lpfc hba data structure.
14989 * @fcf_record: pointer to the fcf record to write the default data.
14990 * @fcf_index: FCF table entry index.
14992 * This routine is invoked to build the driver's default FCF record. The
14993 * values used are hardcoded. This routine handles memory initialization.
14997 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
14998 struct fcf_record *fcf_record,
14999 uint16_t fcf_index)
15001 memset(fcf_record, 0, sizeof(struct fcf_record));
15002 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
15003 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
15004 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
15005 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
15006 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
15007 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
15008 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
15009 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
15010 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
15011 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
15012 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
15013 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
15014 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
15015 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
15016 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
15017 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
15018 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
15019 /* Set the VLAN bit map */
15020 if (phba->valid_vlan) {
15021 fcf_record->vlan_bitmap[phba->vlan_id / 8]
15022 = 1 << (phba->vlan_id % 8);
15027 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
15028 * @phba: pointer to lpfc hba data structure.
15029 * @fcf_index: FCF table entry offset.
15031 * This routine is invoked to scan the entire FCF table by reading FCF
15032 * record and processing it one at a time starting from the @fcf_index
15033 * for initial FCF discovery or fast FCF failover rediscovery.
15035 * Return 0 if the mailbox command is submitted successfully, none 0
15039 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
15042 LPFC_MBOXQ_t *mboxq;
15044 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
15045 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
15046 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15049 "2000 Failed to allocate mbox for "
15052 goto fail_fcf_scan;
15054 /* Construct the read FCF record mailbox command */
15055 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
15058 goto fail_fcf_scan;
15060 /* Issue the mailbox command asynchronously */
15061 mboxq->vport = phba->pport;
15062 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
15064 spin_lock_irq(&phba->hbalock);
15065 phba->hba_flag |= FCF_TS_INPROG;
15066 spin_unlock_irq(&phba->hbalock);
15068 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
15069 if (rc == MBX_NOT_FINISHED)
15072 /* Reset eligible FCF count for new scan */
15073 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
15074 phba->fcf.eligible_fcf_cnt = 0;
15080 lpfc_sli4_mbox_cmd_free(phba, mboxq);
15081 /* FCF scan failed, clear FCF_TS_INPROG flag */
15082 spin_lock_irq(&phba->hbalock);
15083 phba->hba_flag &= ~FCF_TS_INPROG;
15084 spin_unlock_irq(&phba->hbalock);
15090 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15091 * @phba: pointer to lpfc hba data structure.
15092 * @fcf_index: FCF table entry offset.
15094 * This routine is invoked to read an FCF record indicated by @fcf_index
15095 * and to use it for FLOGI roundrobin FCF failover.
15097 * Return 0 if the mailbox command is submitted successfully, none 0
15101 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
15104 LPFC_MBOXQ_t *mboxq;
15106 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15108 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
15109 "2763 Failed to allocate mbox for "
15112 goto fail_fcf_read;
15114 /* Construct the read FCF record mailbox command */
15115 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
15118 goto fail_fcf_read;
15120 /* Issue the mailbox command asynchronously */
15121 mboxq->vport = phba->pport;
15122 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
15123 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
15124 if (rc == MBX_NOT_FINISHED)
15130 if (error && mboxq)
15131 lpfc_sli4_mbox_cmd_free(phba, mboxq);
15136 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15137 * @phba: pointer to lpfc hba data structure.
15138 * @fcf_index: FCF table entry offset.
15140 * This routine is invoked to read an FCF record indicated by @fcf_index to
15141 * determine whether it's eligible for FLOGI roundrobin failover list.
15143 * Return 0 if the mailbox command is submitted successfully, none 0
15147 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
15150 LPFC_MBOXQ_t *mboxq;
15152 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15154 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
15155 "2758 Failed to allocate mbox for "
15158 goto fail_fcf_read;
15160 /* Construct the read FCF record mailbox command */
15161 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
15164 goto fail_fcf_read;
15166 /* Issue the mailbox command asynchronously */
15167 mboxq->vport = phba->pport;
15168 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
15169 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
15170 if (rc == MBX_NOT_FINISHED)
15176 if (error && mboxq)
15177 lpfc_sli4_mbox_cmd_free(phba, mboxq);
15182 * lpfc_check_next_fcf_pri
15183 * phba pointer to the lpfc_hba struct for this port.
15184 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15185 * routine when the rr_bmask is empty. The FCF indecies are put into the
15186 * rr_bmask based on their priority level. Starting from the highest priority
15187 * to the lowest. The most likely FCF candidate will be in the highest
15188 * priority group. When this routine is called it searches the fcf_pri list for
15189 * next lowest priority group and repopulates the rr_bmask with only those
15192 * 1=success 0=failure
15195 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
15197 uint16_t next_fcf_pri;
15198 uint16_t last_index;
15199 struct lpfc_fcf_pri *fcf_pri;
15203 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
15204 LPFC_SLI4_FCF_TBL_INDX_MAX);
15205 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
15206 "3060 Last IDX %d\n", last_index);
15207 if (list_empty(&phba->fcf.fcf_pri_list)) {
15208 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
15209 "3061 Last IDX %d\n", last_index);
15210 return 0; /* Empty rr list */
15214 * Clear the rr_bmask and set all of the bits that are at this
15217 memset(phba->fcf.fcf_rr_bmask, 0,
15218 sizeof(*phba->fcf.fcf_rr_bmask));
15219 spin_lock_irq(&phba->hbalock);
15220 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
15221 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
15224 * the 1st priority that has not FLOGI failed
15225 * will be the highest.
15228 next_fcf_pri = fcf_pri->fcf_rec.priority;
15229 spin_unlock_irq(&phba->hbalock);
15230 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
15231 rc = lpfc_sli4_fcf_rr_index_set(phba,
15232 fcf_pri->fcf_rec.fcf_index);
15236 spin_lock_irq(&phba->hbalock);
15239 * if next_fcf_pri was not set above and the list is not empty then
15240 * we have failed flogis on all of them. So reset flogi failed
15241 * and start at the beginning.
15243 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
15244 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
15245 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
15247 * the 1st priority that has not FLOGI failed
15248 * will be the highest.
15251 next_fcf_pri = fcf_pri->fcf_rec.priority;
15252 spin_unlock_irq(&phba->hbalock);
15253 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
15254 rc = lpfc_sli4_fcf_rr_index_set(phba,
15255 fcf_pri->fcf_rec.fcf_index);
15259 spin_lock_irq(&phba->hbalock);
15263 spin_unlock_irq(&phba->hbalock);
15268 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15269 * @phba: pointer to lpfc hba data structure.
15271 * This routine is to get the next eligible FCF record index in a round
15272 * robin fashion. If the next eligible FCF record index equals to the
15273 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15274 * shall be returned, otherwise, the next eligible FCF record's index
15275 * shall be returned.
15278 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
15280 uint16_t next_fcf_index;
15282 /* Search start from next bit of currently registered FCF index */
15284 next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
15285 LPFC_SLI4_FCF_TBL_INDX_MAX;
15286 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
15287 LPFC_SLI4_FCF_TBL_INDX_MAX,
15290 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15291 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
15293 * If we have wrapped then we need to clear the bits that
15294 * have been tested so that we can detect when we should
15295 * change the priority level.
15297 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
15298 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
15302 /* Check roundrobin failover list empty condition */
15303 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
15304 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
15306 * If next fcf index is not found check if there are lower
15307 * Priority level fcf's in the fcf_priority list.
15308 * Set up the rr_bmask with all of the avaiable fcf bits
15309 * at that level and continue the selection process.
15311 if (lpfc_check_next_fcf_pri_level(phba))
15312 goto next_priority;
15313 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
15314 "2844 No roundrobin failover FCF available\n");
15315 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
15316 return LPFC_FCOE_FCF_NEXT_NONE;
15318 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
15319 "3063 Only FCF available idx %d, flag %x\n",
15321 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
15322 return next_fcf_index;
15326 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
15327 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
15328 LPFC_FCF_FLOGI_FAILED)
15329 goto next_priority;
15331 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
15332 "2845 Get next roundrobin failover FCF (x%x)\n",
15335 return next_fcf_index;
15339 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15340 * @phba: pointer to lpfc hba data structure.
15342 * This routine sets the FCF record index in to the eligible bmask for
15343 * roundrobin failover search. It checks to make sure that the index
15344 * does not go beyond the range of the driver allocated bmask dimension
15345 * before setting the bit.
15347 * Returns 0 if the index bit successfully set, otherwise, it returns
15351 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
15353 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
15354 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
15355 "2610 FCF (x%x) reached driver's book "
15356 "keeping dimension:x%x\n",
15357 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
15360 /* Set the eligible FCF record index bmask */
15361 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
15363 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
15364 "2790 Set FCF (x%x) to roundrobin FCF failover "
15365 "bmask\n", fcf_index);
15371 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15372 * @phba: pointer to lpfc hba data structure.
15374 * This routine clears the FCF record index from the eligible bmask for
15375 * roundrobin failover search. It checks to make sure that the index
15376 * does not go beyond the range of the driver allocated bmask dimension
15377 * before clearing the bit.
15380 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
15382 struct lpfc_fcf_pri *fcf_pri;
15383 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
15384 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
15385 "2762 FCF (x%x) reached driver's book "
15386 "keeping dimension:x%x\n",
15387 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
15390 /* Clear the eligible FCF record index bmask */
15391 spin_lock_irq(&phba->hbalock);
15392 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
15393 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
15394 list_del_init(&fcf_pri->list);
15398 spin_unlock_irq(&phba->hbalock);
15399 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
15401 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
15402 "2791 Clear FCF (x%x) from roundrobin failover "
15403 "bmask\n", fcf_index);
15407 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15408 * @phba: pointer to lpfc hba data structure.
15410 * This routine is the completion routine for the rediscover FCF table mailbox
15411 * command. If the mailbox command returned failure, it will try to stop the
15412 * FCF rediscover wait timer.
15415 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
15417 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
15418 uint32_t shdr_status, shdr_add_status;
15420 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
15422 shdr_status = bf_get(lpfc_mbox_hdr_status,
15423 &redisc_fcf->header.cfg_shdr.response);
15424 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
15425 &redisc_fcf->header.cfg_shdr.response);
15426 if (shdr_status || shdr_add_status) {
15427 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
15428 "2746 Requesting for FCF rediscovery failed "
15429 "status x%x add_status x%x\n",
15430 shdr_status, shdr_add_status);
15431 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
15432 spin_lock_irq(&phba->hbalock);
15433 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
15434 spin_unlock_irq(&phba->hbalock);
15436 * CVL event triggered FCF rediscover request failed,
15437 * last resort to re-try current registered FCF entry.
15439 lpfc_retry_pport_discovery(phba);
15441 spin_lock_irq(&phba->hbalock);
15442 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
15443 spin_unlock_irq(&phba->hbalock);
15445 * DEAD FCF event triggered FCF rediscover request
15446 * failed, last resort to fail over as a link down
15447 * to FCF registration.
15449 lpfc_sli4_fcf_dead_failthrough(phba);
15452 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
15453 "2775 Start FCF rediscover quiescent timer\n");
15455 * Start FCF rediscovery wait timer for pending FCF
15456 * before rescan FCF record table.
15458 lpfc_fcf_redisc_wait_start_timer(phba);
15461 mempool_free(mbox, phba->mbox_mem_pool);
15465 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15466 * @phba: pointer to lpfc hba data structure.
15468 * This routine is invoked to request for rediscovery of the entire FCF table
15472 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
15474 LPFC_MBOXQ_t *mbox;
15475 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
15478 /* Cancel retry delay timers to all vports before FCF rediscover */
15479 lpfc_cancel_all_vport_retry_delay_timer(phba);
15481 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15483 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15484 "2745 Failed to allocate mbox for "
15485 "requesting FCF rediscover.\n");
15489 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
15490 sizeof(struct lpfc_sli4_cfg_mhdr));
15491 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15492 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
15493 length, LPFC_SLI4_MBX_EMBED);
15495 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
15496 /* Set count to 0 for invalidating the entire FCF database */
15497 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
15499 /* Issue the mailbox command asynchronously */
15500 mbox->vport = phba->pport;
15501 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
15502 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
15504 if (rc == MBX_NOT_FINISHED) {
15505 mempool_free(mbox, phba->mbox_mem_pool);
15512 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15513 * @phba: pointer to lpfc hba data structure.
15515 * This function is the failover routine as a last resort to the FCF DEAD
15516 * event when driver failed to perform fast FCF failover.
15519 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
15521 uint32_t link_state;
15524 * Last resort as FCF DEAD event failover will treat this as
15525 * a link down, but save the link state because we don't want
15526 * it to be changed to Link Down unless it is already down.
15528 link_state = phba->link_state;
15529 lpfc_linkdown(phba);
15530 phba->link_state = link_state;
15532 /* Unregister FCF if no devices connected to it */
15533 lpfc_unregister_unused_fcf(phba);
15537 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15538 * @phba: pointer to lpfc hba data structure.
15539 * @rgn23_data: pointer to configure region 23 data.
15541 * This function gets SLI3 port configure region 23 data through memory dump
15542 * mailbox command. When it successfully retrieves data, the size of the data
15543 * will be returned, otherwise, 0 will be returned.
15546 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
15548 LPFC_MBOXQ_t *pmb = NULL;
15550 uint32_t offset = 0;
15556 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15558 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15559 "2600 failed to allocate mailbox memory\n");
15565 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
15566 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
15568 if (rc != MBX_SUCCESS) {
15569 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15570 "2601 failed to read config "
15571 "region 23, rc 0x%x Status 0x%x\n",
15572 rc, mb->mbxStatus);
15573 mb->un.varDmp.word_cnt = 0;
15576 * dump mem may return a zero when finished or we got a
15577 * mailbox error, either way we are done.
15579 if (mb->un.varDmp.word_cnt == 0)
15581 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
15582 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
15584 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
15585 rgn23_data + offset,
15586 mb->un.varDmp.word_cnt);
15587 offset += mb->un.varDmp.word_cnt;
15588 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
15590 mempool_free(pmb, phba->mbox_mem_pool);
15595 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15596 * @phba: pointer to lpfc hba data structure.
15597 * @rgn23_data: pointer to configure region 23 data.
15599 * This function gets SLI4 port configure region 23 data through memory dump
15600 * mailbox command. When it successfully retrieves data, the size of the data
15601 * will be returned, otherwise, 0 will be returned.
15604 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
15606 LPFC_MBOXQ_t *mboxq = NULL;
15607 struct lpfc_dmabuf *mp = NULL;
15608 struct lpfc_mqe *mqe;
15609 uint32_t data_length = 0;
15615 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15618 "3105 failed to allocate mailbox memory\n");
15622 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
15624 mqe = &mboxq->u.mqe;
15625 mp = (struct lpfc_dmabuf *) mboxq->context1;
15626 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
15629 data_length = mqe->un.mb_words[5];
15630 if (data_length == 0)
15632 if (data_length > DMP_RGN23_SIZE) {
15636 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
15638 mempool_free(mboxq, phba->mbox_mem_pool);
15640 lpfc_mbuf_free(phba, mp->virt, mp->phys);
15643 return data_length;
15647 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15648 * @phba: pointer to lpfc hba data structure.
15650 * This function read region 23 and parse TLV for port status to
15651 * decide if the user disaled the port. If the TLV indicates the
15652 * port is disabled, the hba_flag is set accordingly.
15655 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
15657 uint8_t *rgn23_data = NULL;
15658 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
15659 uint32_t offset = 0;
15661 /* Get adapter Region 23 data */
15662 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
15666 if (phba->sli_rev < LPFC_SLI_REV4)
15667 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
15669 if_type = bf_get(lpfc_sli_intf_if_type,
15670 &phba->sli4_hba.sli_intf);
15671 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
15673 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
15679 /* Check the region signature first */
15680 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
15681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15682 "2619 Config region 23 has bad signature\n");
15687 /* Check the data structure version */
15688 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
15689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15690 "2620 Config region 23 has bad version\n");
15695 /* Parse TLV entries in the region */
15696 while (offset < data_size) {
15697 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
15700 * If the TLV is not driver specific TLV or driver id is
15701 * not linux driver id, skip the record.
15703 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
15704 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
15705 (rgn23_data[offset + 3] != 0)) {
15706 offset += rgn23_data[offset + 1] * 4 + 4;
15710 /* Driver found a driver specific TLV in the config region */
15711 sub_tlv_len = rgn23_data[offset + 1] * 4;
15716 * Search for configured port state sub-TLV.
15718 while ((offset < data_size) &&
15719 (tlv_offset < sub_tlv_len)) {
15720 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
15725 if (rgn23_data[offset] != PORT_STE_TYPE) {
15726 offset += rgn23_data[offset + 1] * 4 + 4;
15727 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
15731 /* This HBA contains PORT_STE configured */
15732 if (!rgn23_data[offset + 2])
15733 phba->hba_flag |= LINK_DISABLED;
15745 * lpfc_wr_object - write an object to the firmware
15746 * @phba: HBA structure that indicates port to create a queue on.
15747 * @dmabuf_list: list of dmabufs to write to the port.
15748 * @size: the total byte value of the objects to write to the port.
15749 * @offset: the current offset to be used to start the transfer.
15751 * This routine will create a wr_object mailbox command to send to the port.
15752 * the mailbox command will be constructed using the dma buffers described in
15753 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
15754 * BDEs that the imbedded mailbox can support. The @offset variable will be
15755 * used to indicate the starting offset of the transfer and will also return
15756 * the offset after the write object mailbox has completed. @size is used to
15757 * determine the end of the object and whether the eof bit should be set.
15759 * Return 0 is successful and offset will contain the the new offset to use
15760 * for the next write.
15761 * Return negative value for error cases.
15764 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
15765 uint32_t size, uint32_t *offset)
15767 struct lpfc_mbx_wr_object *wr_object;
15768 LPFC_MBOXQ_t *mbox;
15770 uint32_t shdr_status, shdr_add_status;
15772 union lpfc_sli4_cfg_shdr *shdr;
15773 struct lpfc_dmabuf *dmabuf;
15774 uint32_t written = 0;
15776 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15780 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15781 LPFC_MBOX_OPCODE_WRITE_OBJECT,
15782 sizeof(struct lpfc_mbx_wr_object) -
15783 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
15785 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
15786 wr_object->u.request.write_offset = *offset;
15787 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
15788 wr_object->u.request.object_name[0] =
15789 cpu_to_le32(wr_object->u.request.object_name[0]);
15790 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
15791 list_for_each_entry(dmabuf, dmabuf_list, list) {
15792 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
15794 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
15795 wr_object->u.request.bde[i].addrHigh =
15796 putPaddrHigh(dmabuf->phys);
15797 if (written + SLI4_PAGE_SIZE >= size) {
15798 wr_object->u.request.bde[i].tus.f.bdeSize =
15800 written += (size - written);
15801 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
15803 wr_object->u.request.bde[i].tus.f.bdeSize =
15805 written += SLI4_PAGE_SIZE;
15809 wr_object->u.request.bde_count = i;
15810 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
15811 if (!phba->sli4_hba.intr_enable)
15812 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15814 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
15815 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
15817 /* The IOCTL status is embedded in the mailbox subheader. */
15818 shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
15819 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15820 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15821 if (rc != MBX_TIMEOUT)
15822 mempool_free(mbox, phba->mbox_mem_pool);
15823 if (shdr_status || shdr_add_status || rc) {
15824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15825 "3025 Write Object mailbox failed with "
15826 "status x%x add_status x%x, mbx status x%x\n",
15827 shdr_status, shdr_add_status, rc);
15830 *offset += wr_object->u.response.actual_write_length;
15835 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
15836 * @vport: pointer to vport data structure.
15838 * This function iterate through the mailboxq and clean up all REG_LOGIN
15839 * and REG_VPI mailbox commands associated with the vport. This function
15840 * is called when driver want to restart discovery of the vport due to
15841 * a Clear Virtual Link event.
15844 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
15846 struct lpfc_hba *phba = vport->phba;
15847 LPFC_MBOXQ_t *mb, *nextmb;
15848 struct lpfc_dmabuf *mp;
15849 struct lpfc_nodelist *ndlp;
15850 struct lpfc_nodelist *act_mbx_ndlp = NULL;
15851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
15852 LIST_HEAD(mbox_cmd_list);
15853 uint8_t restart_loop;
15855 /* Clean up internally queued mailbox commands with the vport */
15856 spin_lock_irq(&phba->hbalock);
15857 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
15858 if (mb->vport != vport)
15861 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
15862 (mb->u.mb.mbxCommand != MBX_REG_VPI))
15865 list_del(&mb->list);
15866 list_add_tail(&mb->list, &mbox_cmd_list);
15868 /* Clean up active mailbox command with the vport */
15869 mb = phba->sli.mbox_active;
15870 if (mb && (mb->vport == vport)) {
15871 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
15872 (mb->u.mb.mbxCommand == MBX_REG_VPI))
15873 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
15874 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
15875 act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
15876 /* Put reference count for delayed processing */
15877 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
15878 /* Unregister the RPI when mailbox complete */
15879 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
15882 /* Cleanup any mailbox completions which are not yet processed */
15885 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
15887 * If this mailox is already processed or it is
15888 * for another vport ignore it.
15890 if ((mb->vport != vport) ||
15891 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
15894 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
15895 (mb->u.mb.mbxCommand != MBX_REG_VPI))
15898 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
15899 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
15900 ndlp = (struct lpfc_nodelist *)mb->context2;
15901 /* Unregister the RPI when mailbox complete */
15902 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
15904 spin_unlock_irq(&phba->hbalock);
15905 spin_lock(shost->host_lock);
15906 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
15907 spin_unlock(shost->host_lock);
15908 spin_lock_irq(&phba->hbalock);
15912 } while (restart_loop);
15914 spin_unlock_irq(&phba->hbalock);
15916 /* Release the cleaned-up mailbox commands */
15917 while (!list_empty(&mbox_cmd_list)) {
15918 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
15919 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
15920 mp = (struct lpfc_dmabuf *) (mb->context1);
15922 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
15925 ndlp = (struct lpfc_nodelist *) mb->context2;
15926 mb->context2 = NULL;
15928 spin_lock(shost->host_lock);
15929 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
15930 spin_unlock(shost->host_lock);
15931 lpfc_nlp_put(ndlp);
15934 mempool_free(mb, phba->mbox_mem_pool);
15937 /* Release the ndlp with the cleaned-up active mailbox command */
15938 if (act_mbx_ndlp) {
15939 spin_lock(shost->host_lock);
15940 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
15941 spin_unlock(shost->host_lock);
15942 lpfc_nlp_put(act_mbx_ndlp);
15947 * lpfc_drain_txq - Drain the txq
15948 * @phba: Pointer to HBA context object.
15950 * This function attempt to submit IOCBs on the txq
15951 * to the adapter. For SLI4 adapters, the txq contains
15952 * ELS IOCBs that have been deferred because the there
15953 * are no SGLs. This congestion can occur with large
15954 * vport counts during node discovery.
15958 lpfc_drain_txq(struct lpfc_hba *phba)
15960 LIST_HEAD(completions);
15961 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
15962 struct lpfc_iocbq *piocbq = 0;
15963 unsigned long iflags = 0;
15964 char *fail_msg = NULL;
15965 struct lpfc_sglq *sglq;
15966 union lpfc_wqe wqe;
15968 spin_lock_irqsave(&phba->hbalock, iflags);
15969 if (pring->txq_cnt > pring->txq_max)
15970 pring->txq_max = pring->txq_cnt;
15972 spin_unlock_irqrestore(&phba->hbalock, iflags);
15974 while (pring->txq_cnt) {
15975 spin_lock_irqsave(&phba->hbalock, iflags);
15977 piocbq = lpfc_sli_ringtx_get(phba, pring);
15979 spin_unlock_irqrestore(&phba->hbalock, iflags);
15980 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15981 "2823 txq empty and txq_cnt is %d\n ",
15985 sglq = __lpfc_sli_get_sglq(phba, piocbq);
15987 __lpfc_sli_ringtx_put(phba, pring, piocbq);
15988 spin_unlock_irqrestore(&phba->hbalock, iflags);
15992 /* The xri and iocb resources secured,
15993 * attempt to issue request
15995 piocbq->sli4_lxritag = sglq->sli4_lxritag;
15996 piocbq->sli4_xritag = sglq->sli4_xritag;
15997 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
15998 fail_msg = "to convert bpl to sgl";
15999 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
16000 fail_msg = "to convert iocb to wqe";
16001 else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
16002 fail_msg = " - Wq is full";
16004 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
16007 /* Failed means we can't issue and need to cancel */
16008 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16009 "2822 IOCB failed %s iotag 0x%x "
16012 piocbq->iotag, piocbq->sli4_xritag);
16013 list_add_tail(&piocbq->list, &completions);
16015 spin_unlock_irqrestore(&phba->hbalock, iflags);
16018 /* Cancel all the IOCBs that cannot be issued */
16019 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
16020 IOERR_SLI_ABORTED);
16022 return pring->txq_cnt;