1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
32 #include <scsi/fc/fc_fs.h>
33 #include <linux/aer.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_compat.h"
46 #include "lpfc_debugfs.h"
47 #include "lpfc_vport.h"
49 /* There are only four IOCB completion types. */
50 typedef enum _lpfc_iocb_type {
58 /* Provide function prototypes local to this module. */
59 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
61 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
62 uint8_t *, uint32_t *);
63 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
65 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
68 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
74 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
75 * @q: The Work Queue to operate on.
76 * @wqe: The work Queue Entry to put on the Work queue.
78 * This routine will copy the contents of @wqe to the next available entry on
79 * the @q. This function will then ring the Work Queue Doorbell to signal the
80 * HBA to start processing the Work Queue Entry. This function returns 0 if
81 * successful. If no entries are available on @q then this function will return
83 * The caller is expected to hold the hbalock when calling this routine.
86 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
88 union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
89 struct lpfc_register doorbell;
92 /* If the host has not yet processed the next entry then we are done */
93 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
95 /* set consumption flag every once in a while */
96 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
97 bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
99 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
101 /* Update the host index before invoking device */
102 host_index = q->host_index;
103 q->host_index = ((q->host_index + 1) % q->entry_count);
107 bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
108 bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
109 bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
110 writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
111 readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
117 * lpfc_sli4_wq_release - Updates internal hba index for WQ
118 * @q: The Work Queue to operate on.
119 * @index: The index to advance the hba index to.
121 * This routine will update the HBA index of a queue to reflect consumption of
122 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
123 * an entry the host calls this function to update the queue's internal
124 * pointers. This routine returns the number of entries that were consumed by
128 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
130 uint32_t released = 0;
132 if (q->hba_index == index)
135 q->hba_index = ((q->hba_index + 1) % q->entry_count);
137 } while (q->hba_index != index);
142 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
143 * @q: The Mailbox Queue to operate on.
144 * @wqe: The Mailbox Queue Entry to put on the Work queue.
146 * This routine will copy the contents of @mqe to the next available entry on
147 * the @q. This function will then ring the Work Queue Doorbell to signal the
148 * HBA to start processing the Work Queue Entry. This function returns 0 if
149 * successful. If no entries are available on @q then this function will return
151 * The caller is expected to hold the hbalock when calling this routine.
154 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
156 struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
157 struct lpfc_register doorbell;
160 /* If the host has not yet processed the next entry then we are done */
161 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
163 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
164 /* Save off the mailbox pointer for completion */
165 q->phba->mbox = (MAILBOX_t *)temp_mqe;
167 /* Update the host index before invoking device */
168 host_index = q->host_index;
169 q->host_index = ((q->host_index + 1) % q->entry_count);
173 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
174 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
175 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
176 readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
181 * lpfc_sli4_mq_release - Updates internal hba index for MQ
182 * @q: The Mailbox Queue to operate on.
184 * This routine will update the HBA index of a queue to reflect consumption of
185 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
186 * an entry the host calls this function to update the queue's internal
187 * pointers. This routine returns the number of entries that were consumed by
191 lpfc_sli4_mq_release(struct lpfc_queue *q)
193 /* Clear the mailbox pointer for completion */
194 q->phba->mbox = NULL;
195 q->hba_index = ((q->hba_index + 1) % q->entry_count);
200 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
201 * @q: The Event Queue to get the first valid EQE from
203 * This routine will get the first valid Event Queue Entry from @q, update
204 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
205 * the Queue (no more work to do), or the Queue is full of EQEs that have been
206 * processed, but not popped back to the HBA then this routine will return NULL.
208 static struct lpfc_eqe *
209 lpfc_sli4_eq_get(struct lpfc_queue *q)
211 struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
213 /* If the next EQE is not valid then we are done */
214 if (!bf_get(lpfc_eqe_valid, eqe))
216 /* If the host has not yet processed the next entry then we are done */
217 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
220 q->hba_index = ((q->hba_index + 1) % q->entry_count);
225 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
226 * @q: The Event Queue that the host has completed processing for.
227 * @arm: Indicates whether the host wants to arms this CQ.
229 * This routine will mark all Event Queue Entries on @q, from the last
230 * known completed entry to the last entry that was processed, as completed
231 * by clearing the valid bit for each completion queue entry. Then it will
232 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
233 * The internal host index in the @q will be updated by this routine to indicate
234 * that the host has finished processing the entries. The @arm parameter
235 * indicates that the queue should be rearmed when ringing the doorbell.
237 * This function will return the number of EQEs that were popped.
240 lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
242 uint32_t released = 0;
243 struct lpfc_eqe *temp_eqe;
244 struct lpfc_register doorbell;
246 /* while there are valid entries */
247 while (q->hba_index != q->host_index) {
248 temp_eqe = q->qe[q->host_index].eqe;
249 bf_set(lpfc_eqe_valid, temp_eqe, 0);
251 q->host_index = ((q->host_index + 1) % q->entry_count);
253 if (unlikely(released == 0 && !arm))
256 /* ring doorbell for number popped */
259 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
260 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
262 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
263 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
264 bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
265 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
266 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
267 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
268 readl(q->phba->sli4_hba.EQCQDBregaddr);
273 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
274 * @q: The Completion Queue to get the first valid CQE from
276 * This routine will get the first valid Completion Queue Entry from @q, update
277 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
278 * the Queue (no more work to do), or the Queue is full of CQEs that have been
279 * processed, but not popped back to the HBA then this routine will return NULL.
281 static struct lpfc_cqe *
282 lpfc_sli4_cq_get(struct lpfc_queue *q)
284 struct lpfc_cqe *cqe;
286 /* If the next CQE is not valid then we are done */
287 if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
289 /* If the host has not yet processed the next entry then we are done */
290 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
293 cqe = q->qe[q->hba_index].cqe;
294 q->hba_index = ((q->hba_index + 1) % q->entry_count);
299 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
300 * @q: The Completion Queue that the host has completed processing for.
301 * @arm: Indicates whether the host wants to arms this CQ.
303 * This routine will mark all Completion queue entries on @q, from the last
304 * known completed entry to the last entry that was processed, as completed
305 * by clearing the valid bit for each completion queue entry. Then it will
306 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
307 * The internal host index in the @q will be updated by this routine to indicate
308 * that the host has finished processing the entries. The @arm parameter
309 * indicates that the queue should be rearmed when ringing the doorbell.
311 * This function will return the number of CQEs that were released.
314 lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
316 uint32_t released = 0;
317 struct lpfc_cqe *temp_qe;
318 struct lpfc_register doorbell;
320 /* while there are valid entries */
321 while (q->hba_index != q->host_index) {
322 temp_qe = q->qe[q->host_index].cqe;
323 bf_set(lpfc_cqe_valid, temp_qe, 0);
325 q->host_index = ((q->host_index + 1) % q->entry_count);
327 if (unlikely(released == 0 && !arm))
330 /* ring doorbell for number popped */
333 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
334 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
335 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
336 bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
337 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
342 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
343 * @q: The Header Receive Queue to operate on.
344 * @wqe: The Receive Queue Entry to put on the Receive queue.
346 * This routine will copy the contents of @wqe to the next available entry on
347 * the @q. This function will then ring the Receive Queue Doorbell to signal the
348 * HBA to start processing the Receive Queue Entry. This function returns the
349 * index that the rqe was copied to if successful. If no entries are available
350 * on @q then this function will return -ENOMEM.
351 * The caller is expected to hold the hbalock when calling this routine.
354 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
355 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
357 struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
358 struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
359 struct lpfc_register doorbell;
360 int put_index = hq->host_index;
362 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
364 if (hq->host_index != dq->host_index)
366 /* If the host has not yet processed the next entry then we are done */
367 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
369 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
370 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
372 /* Update the host index to point to the next slot */
373 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
374 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
376 /* Ring The Header Receive Queue Doorbell */
377 if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
379 bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
381 bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
382 writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
388 * lpfc_sli4_rq_release - Updates internal hba index for RQ
389 * @q: The Header Receive Queue to operate on.
391 * This routine will update the HBA index of a queue to reflect consumption of
392 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
393 * consumed an entry the host calls this function to update the queue's
394 * internal pointers. This routine returns the number of entries that were
395 * consumed by the HBA.
398 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
400 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
402 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
403 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
408 * lpfc_cmd_iocb - Get next command iocb entry in the ring
409 * @phba: Pointer to HBA context object.
410 * @pring: Pointer to driver SLI ring object.
412 * This function returns pointer to next command iocb entry
413 * in the command ring. The caller must hold hbalock to prevent
414 * other threads consume the next command iocb.
415 * SLI-2/SLI-3 provide different sized iocbs.
417 static inline IOCB_t *
418 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
420 return (IOCB_t *) (((char *) pring->cmdringaddr) +
421 pring->cmdidx * phba->iocb_cmd_size);
425 * lpfc_resp_iocb - Get next response iocb entry in the ring
426 * @phba: Pointer to HBA context object.
427 * @pring: Pointer to driver SLI ring object.
429 * This function returns pointer to next response iocb entry
430 * in the response ring. The caller must hold hbalock to make sure
431 * that no other thread consume the next response iocb.
432 * SLI-2/SLI-3 provide different sized iocbs.
434 static inline IOCB_t *
435 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
437 return (IOCB_t *) (((char *) pring->rspringaddr) +
438 pring->rspidx * phba->iocb_rsp_size);
442 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
443 * @phba: Pointer to HBA context object.
445 * This function is called with hbalock held. This function
446 * allocates a new driver iocb object from the iocb pool. If the
447 * allocation is successful, it returns pointer to the newly
448 * allocated iocb object else it returns NULL.
450 static struct lpfc_iocbq *
451 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
453 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
454 struct lpfc_iocbq * iocbq = NULL;
456 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
461 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
462 * @phba: Pointer to HBA context object.
463 * @xritag: XRI value.
465 * This function clears the sglq pointer from the array of acive
466 * sglq's. The xritag that is passed in is used to index into the
467 * array. Before the xritag can be used it needs to be adjusted
468 * by subtracting the xribase.
470 * Returns sglq ponter = success, NULL = Failure.
472 static struct lpfc_sglq *
473 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
476 struct lpfc_sglq *sglq;
477 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
478 if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
480 sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
481 phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
486 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
487 * @phba: Pointer to HBA context object.
488 * @xritag: XRI value.
490 * This function returns the sglq pointer from the array of acive
491 * sglq's. The xritag that is passed in is used to index into the
492 * array. Before the xritag can be used it needs to be adjusted
493 * by subtracting the xribase.
495 * Returns sglq ponter = success, NULL = Failure.
498 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
501 struct lpfc_sglq *sglq;
502 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
503 if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
505 sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
510 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
511 * @phba: Pointer to HBA context object.
513 * This function is called with hbalock held. This function
514 * Gets a new driver sglq object from the sglq list. If the
515 * list is not empty then it is successful, it returns pointer to the newly
516 * allocated sglq object else it returns NULL.
518 static struct lpfc_sglq *
519 __lpfc_sli_get_sglq(struct lpfc_hba *phba)
521 struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
522 struct lpfc_sglq *sglq = NULL;
524 list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
527 adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
528 phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
529 sglq->state = SGL_ALLOCATED;
534 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
535 * @phba: Pointer to HBA context object.
537 * This function is called with no lock held. This function
538 * allocates a new driver iocb object from the iocb pool. If the
539 * allocation is successful, it returns pointer to the newly
540 * allocated iocb object else it returns NULL.
543 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
545 struct lpfc_iocbq * iocbq = NULL;
546 unsigned long iflags;
548 spin_lock_irqsave(&phba->hbalock, iflags);
549 iocbq = __lpfc_sli_get_iocbq(phba);
550 spin_unlock_irqrestore(&phba->hbalock, iflags);
555 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
556 * @phba: Pointer to HBA context object.
557 * @iocbq: Pointer to driver iocb object.
559 * This function is called with hbalock held to release driver
560 * iocb object to the iocb pool. The iotag in the iocb object
561 * does not change for each use of the iocb object. This function
562 * clears all other fields of the iocb object when it is freed.
563 * The sqlq structure that holds the xritag and phys and virtual
564 * mappings for the scatter gather list is retrieved from the
565 * active array of sglq. The get of the sglq pointer also clears
566 * the entry in the array. If the status of the IO indiactes that
567 * this IO was aborted then the sglq entry it put on the
568 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
569 * IO has good status or fails for any other reason then the sglq
570 * entry is added to the free list (lpfc_sgl_list).
573 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
575 struct lpfc_sglq *sglq;
576 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
579 if (iocbq->sli4_xritag == NO_XRI)
582 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
584 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
585 (sglq->state != SGL_XRI_ABORTED)) {
586 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
588 list_add(&sglq->list,
589 &phba->sli4_hba.lpfc_abts_els_sgl_list);
590 spin_unlock_irqrestore(
591 &phba->sli4_hba.abts_sgl_list_lock, iflag);
593 sglq->state = SGL_FREED;
594 list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
600 * Clean all volatile data fields, preserve iotag and node struct.
602 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
603 iocbq->sli4_xritag = NO_XRI;
604 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
608 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
609 * @phba: Pointer to HBA context object.
610 * @iocbq: Pointer to driver iocb object.
612 * This function is called with hbalock held to release driver
613 * iocb object to the iocb pool. The iotag in the iocb object
614 * does not change for each use of the iocb object. This function
615 * clears all other fields of the iocb object when it is freed.
618 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
620 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
623 * Clean all volatile data fields, preserve iotag and node struct.
625 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
626 iocbq->sli4_xritag = NO_XRI;
627 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
631 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
632 * @phba: Pointer to HBA context object.
633 * @iocbq: Pointer to driver iocb object.
635 * This function is called with hbalock held to release driver
636 * iocb object to the iocb pool. The iotag in the iocb object
637 * does not change for each use of the iocb object. This function
638 * clears all other fields of the iocb object when it is freed.
641 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
643 phba->__lpfc_sli_release_iocbq(phba, iocbq);
647 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
648 * @phba: Pointer to HBA context object.
649 * @iocbq: Pointer to driver iocb object.
651 * This function is called with no lock held to release the iocb to
655 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
657 unsigned long iflags;
660 * Clean all volatile data fields, preserve iotag and node struct.
662 spin_lock_irqsave(&phba->hbalock, iflags);
663 __lpfc_sli_release_iocbq(phba, iocbq);
664 spin_unlock_irqrestore(&phba->hbalock, iflags);
668 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
669 * @phba: Pointer to HBA context object.
670 * @iocblist: List of IOCBs.
671 * @ulpstatus: ULP status in IOCB command field.
672 * @ulpWord4: ULP word-4 in IOCB command field.
674 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
675 * on the list by invoking the complete callback function associated with the
676 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
680 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
681 uint32_t ulpstatus, uint32_t ulpWord4)
683 struct lpfc_iocbq *piocb;
685 while (!list_empty(iocblist)) {
686 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
688 if (!piocb->iocb_cmpl)
689 lpfc_sli_release_iocbq(phba, piocb);
691 piocb->iocb.ulpStatus = ulpstatus;
692 piocb->iocb.un.ulpWord[4] = ulpWord4;
693 (piocb->iocb_cmpl) (phba, piocb, piocb);
700 * lpfc_sli_iocb_cmd_type - Get the iocb type
701 * @iocb_cmnd: iocb command code.
703 * This function is called by ring event handler function to get the iocb type.
704 * This function translates the iocb command to an iocb command type used to
705 * decide the final disposition of each completed IOCB.
706 * The function returns
707 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
708 * LPFC_SOL_IOCB if it is a solicited iocb completion
709 * LPFC_ABORT_IOCB if it is an abort iocb
710 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
712 * The caller is not required to hold any lock.
714 static lpfc_iocb_type
715 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
717 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
719 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
723 case CMD_XMIT_SEQUENCE_CR:
724 case CMD_XMIT_SEQUENCE_CX:
725 case CMD_XMIT_BCAST_CN:
726 case CMD_XMIT_BCAST_CX:
727 case CMD_ELS_REQUEST_CR:
728 case CMD_ELS_REQUEST_CX:
729 case CMD_CREATE_XRI_CR:
730 case CMD_CREATE_XRI_CX:
732 case CMD_XMIT_ELS_RSP_CX:
734 case CMD_FCP_IWRITE_CR:
735 case CMD_FCP_IWRITE_CX:
736 case CMD_FCP_IREAD_CR:
737 case CMD_FCP_IREAD_CX:
738 case CMD_FCP_ICMND_CR:
739 case CMD_FCP_ICMND_CX:
740 case CMD_FCP_TSEND_CX:
741 case CMD_FCP_TRSP_CX:
742 case CMD_FCP_TRECEIVE_CX:
743 case CMD_FCP_AUTO_TRSP_CX:
744 case CMD_ADAPTER_MSG:
745 case CMD_ADAPTER_DUMP:
746 case CMD_XMIT_SEQUENCE64_CR:
747 case CMD_XMIT_SEQUENCE64_CX:
748 case CMD_XMIT_BCAST64_CN:
749 case CMD_XMIT_BCAST64_CX:
750 case CMD_ELS_REQUEST64_CR:
751 case CMD_ELS_REQUEST64_CX:
752 case CMD_FCP_IWRITE64_CR:
753 case CMD_FCP_IWRITE64_CX:
754 case CMD_FCP_IREAD64_CR:
755 case CMD_FCP_IREAD64_CX:
756 case CMD_FCP_ICMND64_CR:
757 case CMD_FCP_ICMND64_CX:
758 case CMD_FCP_TSEND64_CX:
759 case CMD_FCP_TRSP64_CX:
760 case CMD_FCP_TRECEIVE64_CX:
761 case CMD_GEN_REQUEST64_CR:
762 case CMD_GEN_REQUEST64_CX:
763 case CMD_XMIT_ELS_RSP64_CX:
764 case DSSCMD_IWRITE64_CR:
765 case DSSCMD_IWRITE64_CX:
766 case DSSCMD_IREAD64_CR:
767 case DSSCMD_IREAD64_CX:
768 type = LPFC_SOL_IOCB;
770 case CMD_ABORT_XRI_CN:
771 case CMD_ABORT_XRI_CX:
772 case CMD_CLOSE_XRI_CN:
773 case CMD_CLOSE_XRI_CX:
774 case CMD_XRI_ABORTED_CX:
775 case CMD_ABORT_MXRI64_CN:
776 case CMD_XMIT_BLS_RSP64_CX:
777 type = LPFC_ABORT_IOCB;
779 case CMD_RCV_SEQUENCE_CX:
780 case CMD_RCV_ELS_REQ_CX:
781 case CMD_RCV_SEQUENCE64_CX:
782 case CMD_RCV_ELS_REQ64_CX:
783 case CMD_ASYNC_STATUS:
784 case CMD_IOCB_RCV_SEQ64_CX:
785 case CMD_IOCB_RCV_ELS64_CX:
786 case CMD_IOCB_RCV_CONT64_CX:
787 case CMD_IOCB_RET_XRI64_CX:
788 type = LPFC_UNSOL_IOCB;
790 case CMD_IOCB_XMIT_MSEQ64_CR:
791 case CMD_IOCB_XMIT_MSEQ64_CX:
792 case CMD_IOCB_RCV_SEQ_LIST64_CX:
793 case CMD_IOCB_RCV_ELS_LIST64_CX:
794 case CMD_IOCB_CLOSE_EXTENDED_CN:
795 case CMD_IOCB_ABORT_EXTENDED_CN:
796 case CMD_IOCB_RET_HBQE64_CN:
797 case CMD_IOCB_FCP_IBIDIR64_CR:
798 case CMD_IOCB_FCP_IBIDIR64_CX:
799 case CMD_IOCB_FCP_ITASKMGT64_CX:
800 case CMD_IOCB_LOGENTRY_CN:
801 case CMD_IOCB_LOGENTRY_ASYNC_CN:
802 printk("%s - Unhandled SLI-3 Command x%x\n",
803 __func__, iocb_cmnd);
804 type = LPFC_UNKNOWN_IOCB;
807 type = LPFC_UNKNOWN_IOCB;
815 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
816 * @phba: Pointer to HBA context object.
818 * This function is called from SLI initialization code
819 * to configure every ring of the HBA's SLI interface. The
820 * caller is not required to hold any lock. This function issues
821 * a config_ring mailbox command for each ring.
822 * This function returns zero if successful else returns a negative
826 lpfc_sli_ring_map(struct lpfc_hba *phba)
828 struct lpfc_sli *psli = &phba->sli;
833 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
837 phba->link_state = LPFC_INIT_MBX_CMDS;
838 for (i = 0; i < psli->num_rings; i++) {
839 lpfc_config_ring(phba, i, pmb);
840 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
841 if (rc != MBX_SUCCESS) {
842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
843 "0446 Adapter failed to init (%d), "
844 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
846 rc, pmbox->mbxCommand,
847 pmbox->mbxStatus, i);
848 phba->link_state = LPFC_HBA_ERROR;
853 mempool_free(pmb, phba->mbox_mem_pool);
858 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
859 * @phba: Pointer to HBA context object.
860 * @pring: Pointer to driver SLI ring object.
861 * @piocb: Pointer to the driver iocb object.
863 * This function is called with hbalock held. The function adds the
864 * new iocb to txcmplq of the given ring. This function always returns
865 * 0. If this function is called for ELS ring, this function checks if
866 * there is a vport associated with the ELS command. This function also
867 * starts els_tmofunc timer if this is an ELS command.
870 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
871 struct lpfc_iocbq *piocb)
873 list_add_tail(&piocb->list, &pring->txcmplq);
874 pring->txcmplq_cnt++;
875 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
876 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
877 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
881 mod_timer(&piocb->vport->els_tmofunc,
882 jiffies + HZ * (phba->fc_ratov << 1));
890 * lpfc_sli_ringtx_get - Get first element of the txq
891 * @phba: Pointer to HBA context object.
892 * @pring: Pointer to driver SLI ring object.
894 * This function is called with hbalock held to get next
895 * iocb in txq of the given ring. If there is any iocb in
896 * the txq, the function returns first iocb in the list after
897 * removing the iocb from the list, else it returns NULL.
899 static struct lpfc_iocbq *
900 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
902 struct lpfc_iocbq *cmd_iocb;
904 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
905 if (cmd_iocb != NULL)
911 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
912 * @phba: Pointer to HBA context object.
913 * @pring: Pointer to driver SLI ring object.
915 * This function is called with hbalock held and the caller must post the
916 * iocb without releasing the lock. If the caller releases the lock,
917 * iocb slot returned by the function is not guaranteed to be available.
918 * The function returns pointer to the next available iocb slot if there
919 * is available slot in the ring, else it returns NULL.
920 * If the get index of the ring is ahead of the put index, the function
921 * will post an error attention event to the worker thread to take the
922 * HBA to offline state.
925 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
927 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
928 uint32_t max_cmd_idx = pring->numCiocb;
929 if ((pring->next_cmdidx == pring->cmdidx) &&
930 (++pring->next_cmdidx >= max_cmd_idx))
931 pring->next_cmdidx = 0;
933 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
935 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
937 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
938 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
939 "0315 Ring %d issue: portCmdGet %d "
940 "is bigger than cmd ring %d\n",
942 pring->local_getidx, max_cmd_idx);
944 phba->link_state = LPFC_HBA_ERROR;
946 * All error attention handlers are posted to
949 phba->work_ha |= HA_ERATT;
950 phba->work_hs = HS_FFER3;
952 lpfc_worker_wake_up(phba);
957 if (pring->local_getidx == pring->next_cmdidx)
961 return lpfc_cmd_iocb(phba, pring);
965 * lpfc_sli_next_iotag - Get an iotag for the iocb
966 * @phba: Pointer to HBA context object.
967 * @iocbq: Pointer to driver iocb object.
969 * This function gets an iotag for the iocb. If there is no unused iotag and
970 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
971 * array and assigns a new iotag.
972 * The function returns the allocated iotag if successful, else returns zero.
973 * Zero is not a valid iotag.
974 * The caller is not required to hold any lock.
977 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
979 struct lpfc_iocbq **new_arr;
980 struct lpfc_iocbq **old_arr;
982 struct lpfc_sli *psli = &phba->sli;
985 spin_lock_irq(&phba->hbalock);
986 iotag = psli->last_iotag;
987 if(++iotag < psli->iocbq_lookup_len) {
988 psli->last_iotag = iotag;
989 psli->iocbq_lookup[iotag] = iocbq;
990 spin_unlock_irq(&phba->hbalock);
991 iocbq->iotag = iotag;
993 } else if (psli->iocbq_lookup_len < (0xffff
994 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
995 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
996 spin_unlock_irq(&phba->hbalock);
997 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
1000 spin_lock_irq(&phba->hbalock);
1001 old_arr = psli->iocbq_lookup;
1002 if (new_len <= psli->iocbq_lookup_len) {
1003 /* highly unprobable case */
1005 iotag = psli->last_iotag;
1006 if(++iotag < psli->iocbq_lookup_len) {
1007 psli->last_iotag = iotag;
1008 psli->iocbq_lookup[iotag] = iocbq;
1009 spin_unlock_irq(&phba->hbalock);
1010 iocbq->iotag = iotag;
1013 spin_unlock_irq(&phba->hbalock);
1016 if (psli->iocbq_lookup)
1017 memcpy(new_arr, old_arr,
1018 ((psli->last_iotag + 1) *
1019 sizeof (struct lpfc_iocbq *)));
1020 psli->iocbq_lookup = new_arr;
1021 psli->iocbq_lookup_len = new_len;
1022 psli->last_iotag = iotag;
1023 psli->iocbq_lookup[iotag] = iocbq;
1024 spin_unlock_irq(&phba->hbalock);
1025 iocbq->iotag = iotag;
1030 spin_unlock_irq(&phba->hbalock);
1032 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
1033 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1040 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1041 * @phba: Pointer to HBA context object.
1042 * @pring: Pointer to driver SLI ring object.
1043 * @iocb: Pointer to iocb slot in the ring.
1044 * @nextiocb: Pointer to driver iocb object which need to be
1045 * posted to firmware.
1047 * This function is called with hbalock held to post a new iocb to
1048 * the firmware. This function copies the new iocb to ring iocb slot and
1049 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1050 * a completion call back for this iocb else the function will free the
1054 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1055 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1060 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1063 if (pring->ringno == LPFC_ELS_RING) {
1064 lpfc_debugfs_slow_ring_trc(phba,
1065 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1066 *(((uint32_t *) &nextiocb->iocb) + 4),
1067 *(((uint32_t *) &nextiocb->iocb) + 6),
1068 *(((uint32_t *) &nextiocb->iocb) + 7));
1072 * Issue iocb command to adapter
1074 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1076 pring->stats.iocb_cmd++;
1079 * If there is no completion routine to call, we can release the
1080 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1081 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1083 if (nextiocb->iocb_cmpl)
1084 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1086 __lpfc_sli_release_iocbq(phba, nextiocb);
1089 * Let the HBA know what IOCB slot will be the next one the
1090 * driver will put a command into.
1092 pring->cmdidx = pring->next_cmdidx;
1093 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1097 * lpfc_sli_update_full_ring - Update the chip attention register
1098 * @phba: Pointer to HBA context object.
1099 * @pring: Pointer to driver SLI ring object.
1101 * The caller is not required to hold any lock for calling this function.
1102 * This function updates the chip attention bits for the ring to inform firmware
1103 * that there are pending work to be done for this ring and requests an
1104 * interrupt when there is space available in the ring. This function is
1105 * called when the driver is unable to post more iocbs to the ring due
1106 * to unavailability of space in the ring.
1109 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1111 int ringno = pring->ringno;
1113 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1118 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1119 * The HBA will tell us when an IOCB entry is available.
1121 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1122 readl(phba->CAregaddr); /* flush */
1124 pring->stats.iocb_cmd_full++;
1128 * lpfc_sli_update_ring - Update chip attention register
1129 * @phba: Pointer to HBA context object.
1130 * @pring: Pointer to driver SLI ring object.
1132 * This function updates the chip attention register bit for the
1133 * given ring to inform HBA that there is more work to be done
1134 * in this ring. The caller is not required to hold any lock.
1137 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1139 int ringno = pring->ringno;
1142 * Tell the HBA that there is work to do in this ring.
1144 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1146 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1147 readl(phba->CAregaddr); /* flush */
1152 * lpfc_sli_resume_iocb - Process iocbs in the txq
1153 * @phba: Pointer to HBA context object.
1154 * @pring: Pointer to driver SLI ring object.
1156 * This function is called with hbalock held to post pending iocbs
1157 * in the txq to the firmware. This function is called when driver
1158 * detects space available in the ring.
1161 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1164 struct lpfc_iocbq *nextiocb;
1168 * (a) there is anything on the txq to send
1170 * (c) link attention events can be processed (fcp ring only)
1171 * (d) IOCB processing is not blocked by the outstanding mbox command.
1173 if (pring->txq_cnt &&
1174 lpfc_is_link_up(phba) &&
1175 (pring->ringno != phba->sli.fcp_ring ||
1176 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1178 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1179 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1180 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1183 lpfc_sli_update_ring(phba, pring);
1185 lpfc_sli_update_full_ring(phba, pring);
1192 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1193 * @phba: Pointer to HBA context object.
1194 * @hbqno: HBQ number.
1196 * This function is called with hbalock held to get the next
1197 * available slot for the given HBQ. If there is free slot
1198 * available for the HBQ it will return pointer to the next available
1199 * HBQ entry else it will return NULL.
1201 static struct lpfc_hbq_entry *
1202 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1204 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1206 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1207 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1208 hbqp->next_hbqPutIdx = 0;
1210 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1211 uint32_t raw_index = phba->hbq_get[hbqno];
1212 uint32_t getidx = le32_to_cpu(raw_index);
1214 hbqp->local_hbqGetIdx = getidx;
1216 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1217 lpfc_printf_log(phba, KERN_ERR,
1218 LOG_SLI | LOG_VPORT,
1219 "1802 HBQ %d: local_hbqGetIdx "
1220 "%u is > than hbqp->entry_count %u\n",
1221 hbqno, hbqp->local_hbqGetIdx,
1224 phba->link_state = LPFC_HBA_ERROR;
1228 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1232 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1237 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1238 * @phba: Pointer to HBA context object.
1240 * This function is called with no lock held to free all the
1241 * hbq buffers while uninitializing the SLI interface. It also
1242 * frees the HBQ buffers returned by the firmware but not yet
1243 * processed by the upper layers.
1246 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1248 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1249 struct hbq_dmabuf *hbq_buf;
1250 unsigned long flags;
1254 hbq_count = lpfc_sli_hbq_count();
1255 /* Return all memory used by all HBQs */
1256 spin_lock_irqsave(&phba->hbalock, flags);
1257 for (i = 0; i < hbq_count; ++i) {
1258 list_for_each_entry_safe(dmabuf, next_dmabuf,
1259 &phba->hbqs[i].hbq_buffer_list, list) {
1260 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1261 list_del(&hbq_buf->dbuf.list);
1262 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1264 phba->hbqs[i].buffer_count = 0;
1266 /* Return all HBQ buffer that are in-fly */
1267 list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
1269 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1270 list_del(&hbq_buf->dbuf.list);
1271 if (hbq_buf->tag == -1) {
1272 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1275 hbqno = hbq_buf->tag >> 16;
1276 if (hbqno >= LPFC_MAX_HBQS)
1277 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1280 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1285 /* Mark the HBQs not in use */
1286 phba->hbq_in_use = 0;
1287 spin_unlock_irqrestore(&phba->hbalock, flags);
1291 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1292 * @phba: Pointer to HBA context object.
1293 * @hbqno: HBQ number.
1294 * @hbq_buf: Pointer to HBQ buffer.
1296 * This function is called with the hbalock held to post a
1297 * hbq buffer to the firmware. If the function finds an empty
1298 * slot in the HBQ, it will post the buffer. The function will return
1299 * pointer to the hbq entry if it successfully post the buffer
1300 * else it will return NULL.
1303 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
1304 struct hbq_dmabuf *hbq_buf)
1306 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1310 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1311 * @phba: Pointer to HBA context object.
1312 * @hbqno: HBQ number.
1313 * @hbq_buf: Pointer to HBQ buffer.
1315 * This function is called with the hbalock held to post a hbq buffer to the
1316 * firmware. If the function finds an empty slot in the HBQ, it will post the
1317 * buffer and place it on the hbq_buffer_list. The function will return zero if
1318 * it successfully post the buffer else it will return an error.
1321 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1322 struct hbq_dmabuf *hbq_buf)
1324 struct lpfc_hbq_entry *hbqe;
1325 dma_addr_t physaddr = hbq_buf->dbuf.phys;
1327 /* Get next HBQ entry slot to use */
1328 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1330 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1332 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1333 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
1334 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
1335 hbqe->bde.tus.f.bdeFlags = 0;
1336 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1337 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1339 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1340 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
1342 readl(phba->hbq_put + hbqno);
1343 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
1350 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1351 * @phba: Pointer to HBA context object.
1352 * @hbqno: HBQ number.
1353 * @hbq_buf: Pointer to HBQ buffer.
1355 * This function is called with the hbalock held to post an RQE to the SLI4
1356 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1357 * the hbq_buffer_list and return zero, otherwise it will return an error.
1360 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1361 struct hbq_dmabuf *hbq_buf)
1364 struct lpfc_rqe hrqe;
1365 struct lpfc_rqe drqe;
1367 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1368 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1369 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1370 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1371 rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
1376 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1380 /* HBQ for ELS and CT traffic. */
1381 static struct lpfc_hbq_init lpfc_els_hbq = {
1386 .ring_mask = (1 << LPFC_ELS_RING),
1392 /* HBQ for the extra ring if needed */
1393 static struct lpfc_hbq_init lpfc_extra_hbq = {
1398 .ring_mask = (1 << LPFC_EXTRA_RING),
1405 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
1411 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1412 * @phba: Pointer to HBA context object.
1413 * @hbqno: HBQ number.
1414 * @count: Number of HBQ buffers to be posted.
1416 * This function is called with no lock held to post more hbq buffers to the
1417 * given HBQ. The function returns the number of HBQ buffers successfully
1421 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1423 uint32_t i, posted = 0;
1424 unsigned long flags;
1425 struct hbq_dmabuf *hbq_buffer;
1426 LIST_HEAD(hbq_buf_list);
1427 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
1430 if ((phba->hbqs[hbqno].buffer_count + count) >
1431 lpfc_hbq_defs[hbqno]->entry_count)
1432 count = lpfc_hbq_defs[hbqno]->entry_count -
1433 phba->hbqs[hbqno].buffer_count;
1436 /* Allocate HBQ entries */
1437 for (i = 0; i < count; i++) {
1438 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1441 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1443 /* Check whether HBQ is still in use */
1444 spin_lock_irqsave(&phba->hbalock, flags);
1445 if (!phba->hbq_in_use)
1447 while (!list_empty(&hbq_buf_list)) {
1448 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1450 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1452 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
1453 phba->hbqs[hbqno].buffer_count++;
1456 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1458 spin_unlock_irqrestore(&phba->hbalock, flags);
1461 spin_unlock_irqrestore(&phba->hbalock, flags);
1462 while (!list_empty(&hbq_buf_list)) {
1463 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1465 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1471 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1472 * @phba: Pointer to HBA context object.
1475 * This function posts more buffers to the HBQ. This function
1476 * is called with no lock held. The function returns the number of HBQ entries
1477 * successfully allocated.
1480 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
1482 if (phba->sli_rev == LPFC_SLI_REV4)
1485 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1486 lpfc_hbq_defs[qno]->add_count);
1490 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1491 * @phba: Pointer to HBA context object.
1492 * @qno: HBQ queue number.
1494 * This function is called from SLI initialization code path with
1495 * no lock held to post initial HBQ buffers to firmware. The
1496 * function returns the number of HBQ entries successfully allocated.
1499 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
1501 if (phba->sli_rev == LPFC_SLI_REV4)
1502 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1503 lpfc_hbq_defs[qno]->entry_count);
1505 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1506 lpfc_hbq_defs[qno]->init_count);
1510 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1511 * @phba: Pointer to HBA context object.
1512 * @hbqno: HBQ number.
1514 * This function removes the first hbq buffer on an hbq list and returns a
1515 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1517 static struct hbq_dmabuf *
1518 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
1520 struct lpfc_dmabuf *d_buf;
1522 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
1525 return container_of(d_buf, struct hbq_dmabuf, dbuf);
1529 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1530 * @phba: Pointer to HBA context object.
1531 * @tag: Tag of the hbq buffer.
1533 * This function is called with hbalock held. This function searches
1534 * for the hbq buffer associated with the given tag in the hbq buffer
1535 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1538 static struct hbq_dmabuf *
1539 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
1541 struct lpfc_dmabuf *d_buf;
1542 struct hbq_dmabuf *hbq_buf;
1546 if (hbqno >= LPFC_MAX_HBQS)
1549 spin_lock_irq(&phba->hbalock);
1550 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
1551 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
1552 if (hbq_buf->tag == tag) {
1553 spin_unlock_irq(&phba->hbalock);
1557 spin_unlock_irq(&phba->hbalock);
1558 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
1559 "1803 Bad hbq tag. Data: x%x x%x\n",
1560 tag, phba->hbqs[tag >> 16].buffer_count);
1565 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1566 * @phba: Pointer to HBA context object.
1567 * @hbq_buffer: Pointer to HBQ buffer.
1569 * This function is called with hbalock. This function gives back
1570 * the hbq buffer to firmware. If the HBQ does not have space to
1571 * post the buffer, it will free the buffer.
1574 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
1579 hbqno = hbq_buffer->tag >> 16;
1580 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
1581 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1586 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1587 * @mbxCommand: mailbox command code.
1589 * This function is called by the mailbox event handler function to verify
1590 * that the completed mailbox command is a legitimate mailbox command. If the
1591 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1592 * and the mailbox event handler will take the HBA offline.
1595 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
1599 switch (mbxCommand) {
1603 case MBX_WRITE_VPARMS:
1604 case MBX_RUN_BIU_DIAG:
1607 case MBX_CONFIG_LINK:
1608 case MBX_CONFIG_RING:
1609 case MBX_RESET_RING:
1610 case MBX_READ_CONFIG:
1611 case MBX_READ_RCONFIG:
1612 case MBX_READ_SPARM:
1613 case MBX_READ_STATUS:
1617 case MBX_READ_LNK_STAT:
1619 case MBX_UNREG_LOGIN:
1622 case MBX_DUMP_MEMORY:
1623 case MBX_DUMP_CONTEXT:
1626 case MBX_UPDATE_CFG:
1628 case MBX_DEL_LD_ENTRY:
1629 case MBX_RUN_PROGRAM:
1631 case MBX_SET_VARIABLE:
1632 case MBX_UNREG_D_ID:
1633 case MBX_KILL_BOARD:
1634 case MBX_CONFIG_FARP:
1637 case MBX_RUN_BIU_DIAG64:
1638 case MBX_CONFIG_PORT:
1639 case MBX_READ_SPARM64:
1640 case MBX_READ_RPI64:
1641 case MBX_REG_LOGIN64:
1645 case MBX_LOAD_EXP_ROM:
1646 case MBX_ASYNCEVT_ENABLE:
1650 case MBX_PORT_CAPABILITIES:
1651 case MBX_PORT_IOV_CONTROL:
1652 case MBX_SLI4_CONFIG:
1653 case MBX_SLI4_REQ_FTRS:
1655 case MBX_UNREG_FCFI:
1660 case MBX_RESUME_RPI:
1671 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
1672 * @phba: Pointer to HBA context object.
1673 * @pmboxq: Pointer to mailbox command.
1675 * This is completion handler function for mailbox commands issued from
1676 * lpfc_sli_issue_mbox_wait function. This function is called by the
1677 * mailbox event handler function with no lock held. This function
1678 * will wake up thread waiting on the wait queue pointed by context1
1682 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
1684 wait_queue_head_t *pdone_q;
1685 unsigned long drvr_flag;
1688 * If pdone_q is empty, the driver thread gave up waiting and
1689 * continued running.
1691 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
1692 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1693 pdone_q = (wait_queue_head_t *) pmboxq->context1;
1695 wake_up_interruptible(pdone_q);
1696 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1702 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
1703 * @phba: Pointer to HBA context object.
1704 * @pmb: Pointer to mailbox object.
1706 * This function is the default mailbox completion handler. It
1707 * frees the memory resources associated with the completed mailbox
1708 * command. If the completed command is a REG_LOGIN mailbox command,
1709 * this function will issue a UREG_LOGIN to re-claim the RPI.
1712 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1714 struct lpfc_dmabuf *mp;
1717 struct lpfc_vport *vport = pmb->vport;
1719 mp = (struct lpfc_dmabuf *) (pmb->context1);
1722 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1726 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
1727 (phba->sli_rev == LPFC_SLI_REV4))
1728 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
1731 * If a REG_LOGIN succeeded after node is destroyed or node
1732 * is in re-discovery driver need to cleanup the RPI.
1734 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1735 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
1736 !pmb->u.mb.mbxStatus) {
1737 rpi = pmb->u.mb.un.varWords[0];
1738 vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
1739 lpfc_unreg_login(phba, vpi, rpi, pmb);
1740 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1741 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1742 if (rc != MBX_NOT_FINISHED)
1746 /* Unreg VPI, if the REG_VPI succeed after VLink failure */
1747 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
1748 !(phba->pport->load_flag & FC_UNLOADING) &&
1749 !pmb->u.mb.mbxStatus) {
1750 lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
1752 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1753 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1754 if (rc != MBX_NOT_FINISHED)
1758 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
1759 lpfc_sli4_mbox_cmd_free(phba, pmb);
1761 mempool_free(pmb, phba->mbox_mem_pool);
1765 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
1766 * @phba: Pointer to HBA context object.
1768 * This function is called with no lock held. This function processes all
1769 * the completed mailbox commands and gives it to upper layers. The interrupt
1770 * service routine processes mailbox completion interrupt and adds completed
1771 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1772 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1773 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1774 * function returns the mailbox commands to the upper layer by calling the
1775 * completion handler function of each mailbox.
1778 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
1785 phba->sli.slistat.mbox_event++;
1787 /* Get all completed mailboxe buffers into the cmplq */
1788 spin_lock_irq(&phba->hbalock);
1789 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
1790 spin_unlock_irq(&phba->hbalock);
1792 /* Get a Mailbox buffer to setup mailbox commands for callback */
1794 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
1800 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
1802 lpfc_debugfs_disc_trc(pmb->vport,
1803 LPFC_DISC_TRC_MBOX_VPORT,
1804 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1805 (uint32_t)pmbox->mbxCommand,
1806 pmbox->un.varWords[0],
1807 pmbox->un.varWords[1]);
1810 lpfc_debugfs_disc_trc(phba->pport,
1812 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1813 (uint32_t)pmbox->mbxCommand,
1814 pmbox->un.varWords[0],
1815 pmbox->un.varWords[1]);
1820 * It is a fatal error if unknown mbox command completion.
1822 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
1824 /* Unknown mailbox command compl */
1825 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1826 "(%d):0323 Unknown Mailbox command "
1828 pmb->vport ? pmb->vport->vpi : 0,
1830 lpfc_sli4_mbox_opcode_get(phba, pmb));
1831 phba->link_state = LPFC_HBA_ERROR;
1832 phba->work_hs = HS_FFER3;
1833 lpfc_handle_eratt(phba);
1837 if (pmbox->mbxStatus) {
1838 phba->sli.slistat.mbox_stat_err++;
1839 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
1840 /* Mbox cmd cmpl error - RETRYing */
1841 lpfc_printf_log(phba, KERN_INFO,
1843 "(%d):0305 Mbox cmd cmpl "
1844 "error - RETRYing Data: x%x "
1845 "(x%x) x%x x%x x%x\n",
1846 pmb->vport ? pmb->vport->vpi :0,
1848 lpfc_sli4_mbox_opcode_get(phba,
1851 pmbox->un.varWords[0],
1852 pmb->vport->port_state);
1853 pmbox->mbxStatus = 0;
1854 pmbox->mbxOwner = OWN_HOST;
1855 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1856 if (rc != MBX_NOT_FINISHED)
1861 /* Mailbox cmd <cmd> Cmpl <cmpl> */
1862 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
1863 "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
1864 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1865 pmb->vport ? pmb->vport->vpi : 0,
1867 lpfc_sli4_mbox_opcode_get(phba, pmb),
1869 *((uint32_t *) pmbox),
1870 pmbox->un.varWords[0],
1871 pmbox->un.varWords[1],
1872 pmbox->un.varWords[2],
1873 pmbox->un.varWords[3],
1874 pmbox->un.varWords[4],
1875 pmbox->un.varWords[5],
1876 pmbox->un.varWords[6],
1877 pmbox->un.varWords[7]);
1880 pmb->mbox_cmpl(phba,pmb);
1886 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
1887 * @phba: Pointer to HBA context object.
1888 * @pring: Pointer to driver SLI ring object.
1891 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1892 * is set in the tag the buffer is posted for a particular exchange,
1893 * the function will return the buffer without replacing the buffer.
1894 * If the buffer is for unsolicited ELS or CT traffic, this function
1895 * returns the buffer and also posts another buffer to the firmware.
1897 static struct lpfc_dmabuf *
1898 lpfc_sli_get_buff(struct lpfc_hba *phba,
1899 struct lpfc_sli_ring *pring,
1902 struct hbq_dmabuf *hbq_entry;
1904 if (tag & QUE_BUFTAG_BIT)
1905 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
1906 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
1909 return &hbq_entry->dbuf;
1913 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
1914 * @phba: Pointer to HBA context object.
1915 * @pring: Pointer to driver SLI ring object.
1916 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
1917 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
1918 * @fch_type: the type for the first frame of the sequence.
1920 * This function is called with no lock held. This function uses the r_ctl and
1921 * type of the received sequence to find the correct callback function to call
1922 * to process the sequence.
1925 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1926 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
1931 /* unSolicited Responses */
1932 if (pring->prt[0].profile) {
1933 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1934 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1938 /* We must search, based on rctl / type
1939 for the right routine */
1940 for (i = 0; i < pring->num_mask; i++) {
1941 if ((pring->prt[i].rctl == fch_r_ctl) &&
1942 (pring->prt[i].type == fch_type)) {
1943 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1944 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1945 (phba, pring, saveq);
1953 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
1954 * @phba: Pointer to HBA context object.
1955 * @pring: Pointer to driver SLI ring object.
1956 * @saveq: Pointer to the unsolicited iocb.
1958 * This function is called with no lock held by the ring event handler
1959 * when there is an unsolicited iocb posted to the response ring by the
1960 * firmware. This function gets the buffer associated with the iocbs
1961 * and calls the event handler for the ring. This function handles both
1962 * qring buffers and hbq buffers.
1963 * When the function returns 1 the caller can free the iocb object otherwise
1964 * upper layer functions will free the iocb objects.
1967 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1968 struct lpfc_iocbq *saveq)
1972 uint32_t Rctl, Type;
1974 struct lpfc_iocbq *iocbq;
1975 struct lpfc_dmabuf *dmzbuf;
1978 irsp = &(saveq->iocb);
1980 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
1981 if (pring->lpfc_sli_rcv_async_status)
1982 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
1984 lpfc_printf_log(phba,
1987 "0316 Ring %d handler: unexpected "
1988 "ASYNC_STATUS iocb received evt_code "
1991 irsp->un.asyncstat.evt_code);
1995 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
1996 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
1997 if (irsp->ulpBdeCount > 0) {
1998 dmzbuf = lpfc_sli_get_buff(phba, pring,
1999 irsp->un.ulpWord[3]);
2000 lpfc_in_buf_free(phba, dmzbuf);
2003 if (irsp->ulpBdeCount > 1) {
2004 dmzbuf = lpfc_sli_get_buff(phba, pring,
2005 irsp->unsli3.sli3Words[3]);
2006 lpfc_in_buf_free(phba, dmzbuf);
2009 if (irsp->ulpBdeCount > 2) {
2010 dmzbuf = lpfc_sli_get_buff(phba, pring,
2011 irsp->unsli3.sli3Words[7]);
2012 lpfc_in_buf_free(phba, dmzbuf);
2018 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2019 if (irsp->ulpBdeCount != 0) {
2020 saveq->context2 = lpfc_sli_get_buff(phba, pring,
2021 irsp->un.ulpWord[3]);
2022 if (!saveq->context2)
2023 lpfc_printf_log(phba,
2026 "0341 Ring %d Cannot find buffer for "
2027 "an unsolicited iocb. tag 0x%x\n",
2029 irsp->un.ulpWord[3]);
2031 if (irsp->ulpBdeCount == 2) {
2032 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2033 irsp->unsli3.sli3Words[7]);
2034 if (!saveq->context3)
2035 lpfc_printf_log(phba,
2038 "0342 Ring %d Cannot find buffer for an"
2039 " unsolicited iocb. tag 0x%x\n",
2041 irsp->unsli3.sli3Words[7]);
2043 list_for_each_entry(iocbq, &saveq->list, list) {
2044 irsp = &(iocbq->iocb);
2045 if (irsp->ulpBdeCount != 0) {
2046 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2047 irsp->un.ulpWord[3]);
2048 if (!iocbq->context2)
2049 lpfc_printf_log(phba,
2052 "0343 Ring %d Cannot find "
2053 "buffer for an unsolicited iocb"
2054 ". tag 0x%x\n", pring->ringno,
2055 irsp->un.ulpWord[3]);
2057 if (irsp->ulpBdeCount == 2) {
2058 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2059 irsp->unsli3.sli3Words[7]);
2060 if (!iocbq->context3)
2061 lpfc_printf_log(phba,
2064 "0344 Ring %d Cannot find "
2065 "buffer for an unsolicited "
2068 irsp->unsli3.sli3Words[7]);
2072 if (irsp->ulpBdeCount != 0 &&
2073 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2074 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2077 /* search continue save q for same XRI */
2078 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2079 if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
2080 list_add_tail(&saveq->list, &iocbq->list);
2086 list_add_tail(&saveq->clist,
2087 &pring->iocb_continue_saveq);
2088 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2089 list_del_init(&iocbq->clist);
2091 irsp = &(saveq->iocb);
2095 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2096 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2097 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2098 Rctl = FC_RCTL_ELS_REQ;
2101 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2102 Rctl = w5p->hcsw.Rctl;
2103 Type = w5p->hcsw.Type;
2105 /* Firmware Workaround */
2106 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2107 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2108 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2109 Rctl = FC_RCTL_ELS_REQ;
2111 w5p->hcsw.Rctl = Rctl;
2112 w5p->hcsw.Type = Type;
2116 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2117 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2118 "0313 Ring %d handler: unexpected Rctl x%x "
2119 "Type x%x received\n",
2120 pring->ringno, Rctl, Type);
2126 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2127 * @phba: Pointer to HBA context object.
2128 * @pring: Pointer to driver SLI ring object.
2129 * @prspiocb: Pointer to response iocb object.
2131 * This function looks up the iocb_lookup table to get the command iocb
2132 * corresponding to the given response iocb using the iotag of the
2133 * response iocb. This function is called with the hbalock held.
2134 * This function returns the command iocb object if it finds the command
2135 * iocb else returns NULL.
2137 static struct lpfc_iocbq *
2138 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2139 struct lpfc_sli_ring *pring,
2140 struct lpfc_iocbq *prspiocb)
2142 struct lpfc_iocbq *cmd_iocb = NULL;
2145 iotag = prspiocb->iocb.ulpIoTag;
2147 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2148 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2149 list_del_init(&cmd_iocb->list);
2150 pring->txcmplq_cnt--;
2154 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2155 "0317 iotag x%x is out off "
2156 "range: max iotag x%x wd0 x%x\n",
2157 iotag, phba->sli.last_iotag,
2158 *(((uint32_t *) &prspiocb->iocb) + 7));
2163 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2164 * @phba: Pointer to HBA context object.
2165 * @pring: Pointer to driver SLI ring object.
2168 * This function looks up the iocb_lookup table to get the command iocb
2169 * corresponding to the given iotag. This function is called with the
2171 * This function returns the command iocb object if it finds the command
2172 * iocb else returns NULL.
2174 static struct lpfc_iocbq *
2175 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2176 struct lpfc_sli_ring *pring, uint16_t iotag)
2178 struct lpfc_iocbq *cmd_iocb;
2180 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2181 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2182 list_del_init(&cmd_iocb->list);
2183 pring->txcmplq_cnt--;
2187 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2188 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2189 iotag, phba->sli.last_iotag);
2194 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2195 * @phba: Pointer to HBA context object.
2196 * @pring: Pointer to driver SLI ring object.
2197 * @saveq: Pointer to the response iocb to be processed.
2199 * This function is called by the ring event handler for non-fcp
2200 * rings when there is a new response iocb in the response ring.
2201 * The caller is not required to hold any locks. This function
2202 * gets the command iocb associated with the response iocb and
2203 * calls the completion handler for the command iocb. If there
2204 * is no completion handler, the function will free the resources
2205 * associated with command iocb. If the response iocb is for
2206 * an already aborted command iocb, the status of the completion
2207 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2208 * This function always returns 1.
2211 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2212 struct lpfc_iocbq *saveq)
2214 struct lpfc_iocbq *cmdiocbp;
2216 unsigned long iflag;
2218 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2219 spin_lock_irqsave(&phba->hbalock, iflag);
2220 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
2221 spin_unlock_irqrestore(&phba->hbalock, iflag);
2224 if (cmdiocbp->iocb_cmpl) {
2226 * If an ELS command failed send an event to mgmt
2229 if (saveq->iocb.ulpStatus &&
2230 (pring->ringno == LPFC_ELS_RING) &&
2231 (cmdiocbp->iocb.ulpCommand ==
2232 CMD_ELS_REQUEST64_CR))
2233 lpfc_send_els_failure_event(phba,
2237 * Post all ELS completions to the worker thread.
2238 * All other are passed to the completion callback.
2240 if (pring->ringno == LPFC_ELS_RING) {
2241 if ((phba->sli_rev < LPFC_SLI_REV4) &&
2242 (cmdiocbp->iocb_flag &
2243 LPFC_DRIVER_ABORTED)) {
2244 spin_lock_irqsave(&phba->hbalock,
2246 cmdiocbp->iocb_flag &=
2247 ~LPFC_DRIVER_ABORTED;
2248 spin_unlock_irqrestore(&phba->hbalock,
2250 saveq->iocb.ulpStatus =
2251 IOSTAT_LOCAL_REJECT;
2252 saveq->iocb.un.ulpWord[4] =
2255 /* Firmware could still be in progress
2256 * of DMAing payload, so don't free data
2257 * buffer till after a hbeat.
2259 spin_lock_irqsave(&phba->hbalock,
2261 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2262 spin_unlock_irqrestore(&phba->hbalock,
2265 if (phba->sli_rev == LPFC_SLI_REV4) {
2266 if (saveq->iocb_flag &
2267 LPFC_EXCHANGE_BUSY) {
2268 /* Set cmdiocb flag for the
2269 * exchange busy so sgl (xri)
2270 * will not be released until
2271 * the abort xri is received
2275 &phba->hbalock, iflag);
2276 cmdiocbp->iocb_flag |=
2278 spin_unlock_irqrestore(
2279 &phba->hbalock, iflag);
2281 if (cmdiocbp->iocb_flag &
2282 LPFC_DRIVER_ABORTED) {
2284 * Clear LPFC_DRIVER_ABORTED
2285 * bit in case it was driver
2289 &phba->hbalock, iflag);
2290 cmdiocbp->iocb_flag &=
2291 ~LPFC_DRIVER_ABORTED;
2292 spin_unlock_irqrestore(
2293 &phba->hbalock, iflag);
2294 cmdiocbp->iocb.ulpStatus =
2295 IOSTAT_LOCAL_REJECT;
2296 cmdiocbp->iocb.un.ulpWord[4] =
2297 IOERR_ABORT_REQUESTED;
2299 * For SLI4, irsiocb contains
2300 * NO_XRI in sli_xritag, it
2301 * shall not affect releasing
2302 * sgl (xri) process.
2304 saveq->iocb.ulpStatus =
2305 IOSTAT_LOCAL_REJECT;
2306 saveq->iocb.un.ulpWord[4] =
2309 &phba->hbalock, iflag);
2311 LPFC_DELAY_MEM_FREE;
2312 spin_unlock_irqrestore(
2313 &phba->hbalock, iflag);
2317 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
2319 lpfc_sli_release_iocbq(phba, cmdiocbp);
2322 * Unknown initiating command based on the response iotag.
2323 * This could be the case on the ELS ring because of
2326 if (pring->ringno != LPFC_ELS_RING) {
2328 * Ring <ringno> handler: unexpected completion IoTag
2331 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2332 "0322 Ring %d handler: "
2333 "unexpected completion IoTag x%x "
2334 "Data: x%x x%x x%x x%x\n",
2336 saveq->iocb.ulpIoTag,
2337 saveq->iocb.ulpStatus,
2338 saveq->iocb.un.ulpWord[4],
2339 saveq->iocb.ulpCommand,
2340 saveq->iocb.ulpContext);
2348 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2349 * @phba: Pointer to HBA context object.
2350 * @pring: Pointer to driver SLI ring object.
2352 * This function is called from the iocb ring event handlers when
2353 * put pointer is ahead of the get pointer for a ring. This function signal
2354 * an error attention condition to the worker thread and the worker
2355 * thread will transition the HBA to offline state.
2358 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2360 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2362 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2363 * rsp ring <portRspMax>
2365 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2366 "0312 Ring %d handler: portRspPut %d "
2367 "is bigger than rsp ring %d\n",
2368 pring->ringno, le32_to_cpu(pgp->rspPutInx),
2371 phba->link_state = LPFC_HBA_ERROR;
2374 * All error attention handlers are posted to
2377 phba->work_ha |= HA_ERATT;
2378 phba->work_hs = HS_FFER3;
2380 lpfc_worker_wake_up(phba);
2386 * lpfc_poll_eratt - Error attention polling timer timeout handler
2387 * @ptr: Pointer to address of HBA context object.
2389 * This function is invoked by the Error Attention polling timer when the
2390 * timer times out. It will check the SLI Error Attention register for
2391 * possible attention events. If so, it will post an Error Attention event
2392 * and wake up worker thread to process it. Otherwise, it will set up the
2393 * Error Attention polling timer for the next poll.
2395 void lpfc_poll_eratt(unsigned long ptr)
2397 struct lpfc_hba *phba;
2400 phba = (struct lpfc_hba *)ptr;
2402 /* Check chip HA register for error event */
2403 eratt = lpfc_sli_check_eratt(phba);
2406 /* Tell the worker thread there is work to do */
2407 lpfc_worker_wake_up(phba);
2409 /* Restart the timer for next eratt poll */
2410 mod_timer(&phba->eratt_poll, jiffies +
2411 HZ * LPFC_ERATT_POLL_INTERVAL);
2417 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2418 * @phba: Pointer to HBA context object.
2419 * @pring: Pointer to driver SLI ring object.
2420 * @mask: Host attention register mask for this ring.
2422 * This function is called from the interrupt context when there is a ring
2423 * event for the fcp ring. The caller does not hold any lock.
2424 * The function processes each response iocb in the response ring until it
2425 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2426 * LE bit set. The function will call the completion handler of the command iocb
2427 * if the response iocb indicates a completion for a command iocb or it is
2428 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2429 * function if this is an unsolicited iocb.
2430 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2431 * to check it explicitly.
2434 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
2435 struct lpfc_sli_ring *pring, uint32_t mask)
2437 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2438 IOCB_t *irsp = NULL;
2439 IOCB_t *entry = NULL;
2440 struct lpfc_iocbq *cmdiocbq = NULL;
2441 struct lpfc_iocbq rspiocbq;
2443 uint32_t portRspPut, portRspMax;
2445 lpfc_iocb_type type;
2446 unsigned long iflag;
2447 uint32_t rsp_cmpl = 0;
2449 spin_lock_irqsave(&phba->hbalock, iflag);
2450 pring->stats.iocb_event++;
2453 * The next available response entry should never exceed the maximum
2454 * entries. If it does, treat it as an adapter hardware error.
2456 portRspMax = pring->numRiocb;
2457 portRspPut = le32_to_cpu(pgp->rspPutInx);
2458 if (unlikely(portRspPut >= portRspMax)) {
2459 lpfc_sli_rsp_pointers_error(phba, pring);
2460 spin_unlock_irqrestore(&phba->hbalock, iflag);
2463 if (phba->fcp_ring_in_use) {
2464 spin_unlock_irqrestore(&phba->hbalock, iflag);
2467 phba->fcp_ring_in_use = 1;
2470 while (pring->rspidx != portRspPut) {
2472 * Fetch an entry off the ring and copy it into a local data
2473 * structure. The copy involves a byte-swap since the
2474 * network byte order and pci byte orders are different.
2476 entry = lpfc_resp_iocb(phba, pring);
2477 phba->last_completion_time = jiffies;
2479 if (++pring->rspidx >= portRspMax)
2482 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2483 (uint32_t *) &rspiocbq.iocb,
2484 phba->iocb_rsp_size);
2485 INIT_LIST_HEAD(&(rspiocbq.list));
2486 irsp = &rspiocbq.iocb;
2488 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2489 pring->stats.iocb_rsp++;
2492 if (unlikely(irsp->ulpStatus)) {
2494 * If resource errors reported from HBA, reduce
2495 * queuedepths of the SCSI device.
2497 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2498 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2499 spin_unlock_irqrestore(&phba->hbalock, iflag);
2500 phba->lpfc_rampdown_queue_depth(phba);
2501 spin_lock_irqsave(&phba->hbalock, iflag);
2504 /* Rsp ring <ringno> error: IOCB */
2505 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2506 "0336 Rsp Ring %d error: IOCB Data: "
2507 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2509 irsp->un.ulpWord[0],
2510 irsp->un.ulpWord[1],
2511 irsp->un.ulpWord[2],
2512 irsp->un.ulpWord[3],
2513 irsp->un.ulpWord[4],
2514 irsp->un.ulpWord[5],
2515 *(uint32_t *)&irsp->un1,
2516 *((uint32_t *)&irsp->un1 + 1));
2520 case LPFC_ABORT_IOCB:
2523 * Idle exchange closed via ABTS from port. No iocb
2524 * resources need to be recovered.
2526 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2527 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2528 "0333 IOCB cmd 0x%x"
2529 " processed. Skipping"
2535 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2537 if (unlikely(!cmdiocbq))
2539 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
2540 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
2541 if (cmdiocbq->iocb_cmpl) {
2542 spin_unlock_irqrestore(&phba->hbalock, iflag);
2543 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2545 spin_lock_irqsave(&phba->hbalock, iflag);
2548 case LPFC_UNSOL_IOCB:
2549 spin_unlock_irqrestore(&phba->hbalock, iflag);
2550 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
2551 spin_lock_irqsave(&phba->hbalock, iflag);
2554 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2555 char adaptermsg[LPFC_MAX_ADPTMSG];
2556 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2557 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2559 dev_warn(&((phba->pcidev)->dev),
2561 phba->brd_no, adaptermsg);
2563 /* Unknown IOCB command */
2564 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2565 "0334 Unknown IOCB command "
2566 "Data: x%x, x%x x%x x%x x%x\n",
2567 type, irsp->ulpCommand,
2576 * The response IOCB has been processed. Update the ring
2577 * pointer in SLIM. If the port response put pointer has not
2578 * been updated, sync the pgp->rspPutInx and fetch the new port
2579 * response put pointer.
2581 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2583 if (pring->rspidx == portRspPut)
2584 portRspPut = le32_to_cpu(pgp->rspPutInx);
2587 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
2588 pring->stats.iocb_rsp_full++;
2589 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2590 writel(status, phba->CAregaddr);
2591 readl(phba->CAregaddr);
2593 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2594 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2595 pring->stats.iocb_cmd_empty++;
2597 /* Force update of the local copy of cmdGetInx */
2598 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2599 lpfc_sli_resume_iocb(phba, pring);
2601 if ((pring->lpfc_sli_cmd_available))
2602 (pring->lpfc_sli_cmd_available) (phba, pring);
2606 phba->fcp_ring_in_use = 0;
2607 spin_unlock_irqrestore(&phba->hbalock, iflag);
2612 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
2613 * @phba: Pointer to HBA context object.
2614 * @pring: Pointer to driver SLI ring object.
2615 * @rspiocbp: Pointer to driver response IOCB object.
2617 * This function is called from the worker thread when there is a slow-path
2618 * response IOCB to process. This function chains all the response iocbs until
2619 * seeing the iocb with the LE bit set. The function will call
2620 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
2621 * completion of a command iocb. The function will call the
2622 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
2623 * The function frees the resources or calls the completion handler if this
2624 * iocb is an abort completion. The function returns NULL when the response
2625 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
2626 * this function shall chain the iocb on to the iocb_continueq and return the
2627 * response iocb passed in.
2629 static struct lpfc_iocbq *
2630 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2631 struct lpfc_iocbq *rspiocbp)
2633 struct lpfc_iocbq *saveq;
2634 struct lpfc_iocbq *cmdiocbp;
2635 struct lpfc_iocbq *next_iocb;
2636 IOCB_t *irsp = NULL;
2637 uint32_t free_saveq;
2638 uint8_t iocb_cmd_type;
2639 lpfc_iocb_type type;
2640 unsigned long iflag;
2643 spin_lock_irqsave(&phba->hbalock, iflag);
2644 /* First add the response iocb to the countinueq list */
2645 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
2646 pring->iocb_continueq_cnt++;
2648 /* Now, determine whetehr the list is completed for processing */
2649 irsp = &rspiocbp->iocb;
2652 * By default, the driver expects to free all resources
2653 * associated with this iocb completion.
2656 saveq = list_get_first(&pring->iocb_continueq,
2657 struct lpfc_iocbq, list);
2658 irsp = &(saveq->iocb);
2659 list_del_init(&pring->iocb_continueq);
2660 pring->iocb_continueq_cnt = 0;
2662 pring->stats.iocb_rsp++;
2665 * If resource errors reported from HBA, reduce
2666 * queuedepths of the SCSI device.
2668 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2669 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2670 spin_unlock_irqrestore(&phba->hbalock, iflag);
2671 phba->lpfc_rampdown_queue_depth(phba);
2672 spin_lock_irqsave(&phba->hbalock, iflag);
2675 if (irsp->ulpStatus) {
2676 /* Rsp ring <ringno> error: IOCB */
2677 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2678 "0328 Rsp Ring %d error: "
2683 "x%x x%x x%x x%x\n",
2685 irsp->un.ulpWord[0],
2686 irsp->un.ulpWord[1],
2687 irsp->un.ulpWord[2],
2688 irsp->un.ulpWord[3],
2689 irsp->un.ulpWord[4],
2690 irsp->un.ulpWord[5],
2691 *(((uint32_t *) irsp) + 6),
2692 *(((uint32_t *) irsp) + 7),
2693 *(((uint32_t *) irsp) + 8),
2694 *(((uint32_t *) irsp) + 9),
2695 *(((uint32_t *) irsp) + 10),
2696 *(((uint32_t *) irsp) + 11),
2697 *(((uint32_t *) irsp) + 12),
2698 *(((uint32_t *) irsp) + 13),
2699 *(((uint32_t *) irsp) + 14),
2700 *(((uint32_t *) irsp) + 15));
2704 * Fetch the IOCB command type and call the correct completion
2705 * routine. Solicited and Unsolicited IOCBs on the ELS ring
2706 * get freed back to the lpfc_iocb_list by the discovery
2709 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
2710 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
2713 spin_unlock_irqrestore(&phba->hbalock, iflag);
2714 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
2715 spin_lock_irqsave(&phba->hbalock, iflag);
2718 case LPFC_UNSOL_IOCB:
2719 spin_unlock_irqrestore(&phba->hbalock, iflag);
2720 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
2721 spin_lock_irqsave(&phba->hbalock, iflag);
2726 case LPFC_ABORT_IOCB:
2728 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
2729 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
2732 /* Call the specified completion routine */
2733 if (cmdiocbp->iocb_cmpl) {
2734 spin_unlock_irqrestore(&phba->hbalock,
2736 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
2738 spin_lock_irqsave(&phba->hbalock,
2741 __lpfc_sli_release_iocbq(phba,
2746 case LPFC_UNKNOWN_IOCB:
2747 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2748 char adaptermsg[LPFC_MAX_ADPTMSG];
2749 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2750 memcpy(&adaptermsg[0], (uint8_t *)irsp,
2752 dev_warn(&((phba->pcidev)->dev),
2754 phba->brd_no, adaptermsg);
2756 /* Unknown IOCB command */
2757 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2758 "0335 Unknown IOCB "
2759 "command Data: x%x "
2770 list_for_each_entry_safe(rspiocbp, next_iocb,
2771 &saveq->list, list) {
2772 list_del(&rspiocbp->list);
2773 __lpfc_sli_release_iocbq(phba, rspiocbp);
2775 __lpfc_sli_release_iocbq(phba, saveq);
2779 spin_unlock_irqrestore(&phba->hbalock, iflag);
2784 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
2785 * @phba: Pointer to HBA context object.
2786 * @pring: Pointer to driver SLI ring object.
2787 * @mask: Host attention register mask for this ring.
2789 * This routine wraps the actual slow_ring event process routine from the
2790 * API jump table function pointer from the lpfc_hba struct.
2793 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
2794 struct lpfc_sli_ring *pring, uint32_t mask)
2796 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
2800 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
2801 * @phba: Pointer to HBA context object.
2802 * @pring: Pointer to driver SLI ring object.
2803 * @mask: Host attention register mask for this ring.
2805 * This function is called from the worker thread when there is a ring event
2806 * for non-fcp rings. The caller does not hold any lock. The function will
2807 * remove each response iocb in the response ring and calls the handle
2808 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2811 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
2812 struct lpfc_sli_ring *pring, uint32_t mask)
2814 struct lpfc_pgp *pgp;
2816 IOCB_t *irsp = NULL;
2817 struct lpfc_iocbq *rspiocbp = NULL;
2818 uint32_t portRspPut, portRspMax;
2819 unsigned long iflag;
2822 pgp = &phba->port_gp[pring->ringno];
2823 spin_lock_irqsave(&phba->hbalock, iflag);
2824 pring->stats.iocb_event++;
2827 * The next available response entry should never exceed the maximum
2828 * entries. If it does, treat it as an adapter hardware error.
2830 portRspMax = pring->numRiocb;
2831 portRspPut = le32_to_cpu(pgp->rspPutInx);
2832 if (portRspPut >= portRspMax) {
2834 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2835 * rsp ring <portRspMax>
2837 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2838 "0303 Ring %d handler: portRspPut %d "
2839 "is bigger than rsp ring %d\n",
2840 pring->ringno, portRspPut, portRspMax);
2842 phba->link_state = LPFC_HBA_ERROR;
2843 spin_unlock_irqrestore(&phba->hbalock, iflag);
2845 phba->work_hs = HS_FFER3;
2846 lpfc_handle_eratt(phba);
2852 while (pring->rspidx != portRspPut) {
2854 * Build a completion list and call the appropriate handler.
2855 * The process is to get the next available response iocb, get
2856 * a free iocb from the list, copy the response data into the
2857 * free iocb, insert to the continuation list, and update the
2858 * next response index to slim. This process makes response
2859 * iocb's in the ring available to DMA as fast as possible but
2860 * pays a penalty for a copy operation. Since the iocb is
2861 * only 32 bytes, this penalty is considered small relative to
2862 * the PCI reads for register values and a slim write. When
2863 * the ulpLe field is set, the entire Command has been
2866 entry = lpfc_resp_iocb(phba, pring);
2868 phba->last_completion_time = jiffies;
2869 rspiocbp = __lpfc_sli_get_iocbq(phba);
2870 if (rspiocbp == NULL) {
2871 printk(KERN_ERR "%s: out of buffers! Failing "
2872 "completion.\n", __func__);
2876 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
2877 phba->iocb_rsp_size);
2878 irsp = &rspiocbp->iocb;
2880 if (++pring->rspidx >= portRspMax)
2883 if (pring->ringno == LPFC_ELS_RING) {
2884 lpfc_debugfs_slow_ring_trc(phba,
2885 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2886 *(((uint32_t *) irsp) + 4),
2887 *(((uint32_t *) irsp) + 6),
2888 *(((uint32_t *) irsp) + 7));
2891 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2893 spin_unlock_irqrestore(&phba->hbalock, iflag);
2894 /* Handle the response IOCB */
2895 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
2896 spin_lock_irqsave(&phba->hbalock, iflag);
2899 * If the port response put pointer has not been updated, sync
2900 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
2901 * response put pointer.
2903 if (pring->rspidx == portRspPut) {
2904 portRspPut = le32_to_cpu(pgp->rspPutInx);
2906 } /* while (pring->rspidx != portRspPut) */
2908 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
2909 /* At least one response entry has been freed */
2910 pring->stats.iocb_rsp_full++;
2911 /* SET RxRE_RSP in Chip Att register */
2912 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2913 writel(status, phba->CAregaddr);
2914 readl(phba->CAregaddr); /* flush */
2916 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2917 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2918 pring->stats.iocb_cmd_empty++;
2920 /* Force update of the local copy of cmdGetInx */
2921 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2922 lpfc_sli_resume_iocb(phba, pring);
2924 if ((pring->lpfc_sli_cmd_available))
2925 (pring->lpfc_sli_cmd_available) (phba, pring);
2929 spin_unlock_irqrestore(&phba->hbalock, iflag);
2934 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
2935 * @phba: Pointer to HBA context object.
2936 * @pring: Pointer to driver SLI ring object.
2937 * @mask: Host attention register mask for this ring.
2939 * This function is called from the worker thread when there is a pending
2940 * ELS response iocb on the driver internal slow-path response iocb worker
2941 * queue. The caller does not hold any lock. The function will remove each
2942 * response iocb from the response worker queue and calls the handle
2943 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2946 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
2947 struct lpfc_sli_ring *pring, uint32_t mask)
2949 struct lpfc_iocbq *irspiocbq;
2950 struct hbq_dmabuf *dmabuf;
2951 struct lpfc_cq_event *cq_event;
2952 unsigned long iflag;
2954 spin_lock_irqsave(&phba->hbalock, iflag);
2955 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
2956 spin_unlock_irqrestore(&phba->hbalock, iflag);
2957 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
2958 /* Get the response iocb from the head of work queue */
2959 spin_lock_irqsave(&phba->hbalock, iflag);
2960 list_remove_head(&phba->sli4_hba.sp_queue_event,
2961 cq_event, struct lpfc_cq_event, list);
2962 spin_unlock_irqrestore(&phba->hbalock, iflag);
2964 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
2965 case CQE_CODE_COMPL_WQE:
2966 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
2968 /* Translate ELS WCQE to response IOCBQ */
2969 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
2972 lpfc_sli_sp_handle_rspiocb(phba, pring,
2975 case CQE_CODE_RECEIVE:
2976 dmabuf = container_of(cq_event, struct hbq_dmabuf,
2978 lpfc_sli4_handle_received_buffer(phba, dmabuf);
2987 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
2988 * @phba: Pointer to HBA context object.
2989 * @pring: Pointer to driver SLI ring object.
2991 * This function aborts all iocbs in the given ring and frees all the iocb
2992 * objects in txq. This function issues an abort iocb for all the iocb commands
2993 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
2994 * the return of this function. The caller is not required to hold any locks.
2997 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2999 LIST_HEAD(completions);
3000 struct lpfc_iocbq *iocb, *next_iocb;
3002 if (pring->ringno == LPFC_ELS_RING) {
3003 lpfc_fabric_abort_hba(phba);
3006 /* Error everything on txq and txcmplq
3009 spin_lock_irq(&phba->hbalock);
3010 list_splice_init(&pring->txq, &completions);
3013 /* Next issue ABTS for everything on the txcmplq */
3014 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3015 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3017 spin_unlock_irq(&phba->hbalock);
3019 /* Cancel all the IOCBs from the completions list */
3020 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3025 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3026 * @phba: Pointer to HBA context object.
3028 * This function flushes all iocbs in the fcp ring and frees all the iocb
3029 * objects in txq and txcmplq. This function will not issue abort iocbs
3030 * for all the iocb commands in txcmplq, they will just be returned with
3031 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3032 * slot has been permanently disabled.
3035 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3039 struct lpfc_sli *psli = &phba->sli;
3040 struct lpfc_sli_ring *pring;
3042 /* Currently, only one fcp ring */
3043 pring = &psli->ring[psli->fcp_ring];
3045 spin_lock_irq(&phba->hbalock);
3046 /* Retrieve everything on txq */
3047 list_splice_init(&pring->txq, &txq);
3050 /* Retrieve everything on the txcmplq */
3051 list_splice_init(&pring->txcmplq, &txcmplq);
3052 pring->txcmplq_cnt = 0;
3053 spin_unlock_irq(&phba->hbalock);
3056 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3059 /* Flush the txcmpq */
3060 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3065 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3066 * @phba: Pointer to HBA context object.
3067 * @mask: Bit mask to be checked.
3069 * This function reads the host status register and compares
3070 * with the provided bit mask to check if HBA completed
3071 * the restart. This function will wait in a loop for the
3072 * HBA to complete restart. If the HBA does not restart within
3073 * 15 iterations, the function will reset the HBA again. The
3074 * function returns 1 when HBA fail to restart otherwise returns
3078 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
3084 /* Read the HBA Host Status Register */
3085 status = readl(phba->HSregaddr);
3088 * Check status register every 100ms for 5 retries, then every
3089 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3090 * every 2.5 sec for 4.
3091 * Break our of the loop if errors occurred during init.
3093 while (((status & mask) != mask) &&
3094 !(status & HS_FFERM) &&
3106 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3107 lpfc_sli_brdrestart(phba);
3109 /* Read the HBA Host Status Register */
3110 status = readl(phba->HSregaddr);
3113 /* Check to see if any errors occurred during init */
3114 if ((status & HS_FFERM) || (i >= 20)) {
3115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3116 "2751 Adapter failed to restart, "
3117 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3119 readl(phba->MBslimaddr + 0xa8),
3120 readl(phba->MBslimaddr + 0xac));
3121 phba->link_state = LPFC_HBA_ERROR;
3129 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3130 * @phba: Pointer to HBA context object.
3131 * @mask: Bit mask to be checked.
3133 * This function checks the host status register to check if HBA is
3134 * ready. This function will wait in a loop for the HBA to be ready
3135 * If the HBA is not ready , the function will will reset the HBA PCI
3136 * function again. The function returns 1 when HBA fail to be ready
3137 * otherwise returns zero.
3140 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3145 /* Read the HBA Host Status Register */
3146 status = lpfc_sli4_post_status_check(phba);
3149 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3150 lpfc_sli_brdrestart(phba);
3151 status = lpfc_sli4_post_status_check(phba);
3154 /* Check to see if any errors occurred during init */
3156 phba->link_state = LPFC_HBA_ERROR;
3159 phba->sli4_hba.intr_enable = 0;
3165 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3166 * @phba: Pointer to HBA context object.
3167 * @mask: Bit mask to be checked.
3169 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3170 * from the API jump table function pointer from the lpfc_hba struct.
3173 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3175 return phba->lpfc_sli_brdready(phba, mask);
3178 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3181 * lpfc_reset_barrier - Make HBA ready for HBA reset
3182 * @phba: Pointer to HBA context object.
3184 * This function is called before resetting an HBA. This
3185 * function requests HBA to quiesce DMAs before a reset.
3187 void lpfc_reset_barrier(struct lpfc_hba *phba)
3189 uint32_t __iomem *resp_buf;
3190 uint32_t __iomem *mbox_buf;
3191 volatile uint32_t mbox;
3196 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3197 if (hdrtype != 0x80 ||
3198 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3199 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3203 * Tell the other part of the chip to suspend temporarily all
3206 resp_buf = phba->MBslimaddr;
3208 /* Disable the error attention */
3209 hc_copy = readl(phba->HCregaddr);
3210 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3211 readl(phba->HCregaddr); /* flush */
3212 phba->link_flag |= LS_IGNORE_ERATT;
3214 if (readl(phba->HAregaddr) & HA_ERATT) {
3215 /* Clear Chip error bit */
3216 writel(HA_ERATT, phba->HAregaddr);
3217 phba->pport->stopped = 1;
3221 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
3222 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
3224 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
3225 mbox_buf = phba->MBslimaddr;
3226 writel(mbox, mbox_buf);
3229 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
3232 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
3233 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
3234 phba->pport->stopped)
3240 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
3241 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
3246 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
3249 if (readl(phba->HAregaddr) & HA_ERATT) {
3250 writel(HA_ERATT, phba->HAregaddr);
3251 phba->pport->stopped = 1;
3255 phba->link_flag &= ~LS_IGNORE_ERATT;
3256 writel(hc_copy, phba->HCregaddr);
3257 readl(phba->HCregaddr); /* flush */
3261 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3262 * @phba: Pointer to HBA context object.
3264 * This function issues a kill_board mailbox command and waits for
3265 * the error attention interrupt. This function is called for stopping
3266 * the firmware processing. The caller is not required to hold any
3267 * locks. This function calls lpfc_hba_down_post function to free
3268 * any pending commands after the kill. The function will return 1 when it
3269 * fails to kill the board else will return 0.
3272 lpfc_sli_brdkill(struct lpfc_hba *phba)
3274 struct lpfc_sli *psli;
3284 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3285 "0329 Kill HBA Data: x%x x%x\n",
3286 phba->pport->port_state, psli->sli_flag);
3288 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3292 /* Disable the error attention */
3293 spin_lock_irq(&phba->hbalock);
3294 status = readl(phba->HCregaddr);
3295 status &= ~HC_ERINT_ENA;
3296 writel(status, phba->HCregaddr);
3297 readl(phba->HCregaddr); /* flush */
3298 phba->link_flag |= LS_IGNORE_ERATT;
3299 spin_unlock_irq(&phba->hbalock);
3301 lpfc_kill_board(phba, pmb);
3302 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3303 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3305 if (retval != MBX_SUCCESS) {
3306 if (retval != MBX_BUSY)
3307 mempool_free(pmb, phba->mbox_mem_pool);
3308 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3309 "2752 KILL_BOARD command failed retval %d\n",
3311 spin_lock_irq(&phba->hbalock);
3312 phba->link_flag &= ~LS_IGNORE_ERATT;
3313 spin_unlock_irq(&phba->hbalock);
3317 spin_lock_irq(&phba->hbalock);
3318 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
3319 spin_unlock_irq(&phba->hbalock);
3321 mempool_free(pmb, phba->mbox_mem_pool);
3323 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3324 * attention every 100ms for 3 seconds. If we don't get ERATT after
3325 * 3 seconds we still set HBA_ERROR state because the status of the
3326 * board is now undefined.
3328 ha_copy = readl(phba->HAregaddr);
3330 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
3332 ha_copy = readl(phba->HAregaddr);
3335 del_timer_sync(&psli->mbox_tmo);
3336 if (ha_copy & HA_ERATT) {
3337 writel(HA_ERATT, phba->HAregaddr);
3338 phba->pport->stopped = 1;
3340 spin_lock_irq(&phba->hbalock);
3341 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3342 psli->mbox_active = NULL;
3343 phba->link_flag &= ~LS_IGNORE_ERATT;
3344 spin_unlock_irq(&phba->hbalock);
3346 lpfc_hba_down_post(phba);
3347 phba->link_state = LPFC_HBA_ERROR;
3349 return ha_copy & HA_ERATT ? 0 : 1;
3353 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3354 * @phba: Pointer to HBA context object.
3356 * This function resets the HBA by writing HC_INITFF to the control
3357 * register. After the HBA resets, this function resets all the iocb ring
3358 * indices. This function disables PCI layer parity checking during
3360 * This function returns 0 always.
3361 * The caller is not required to hold any locks.
3364 lpfc_sli_brdreset(struct lpfc_hba *phba)
3366 struct lpfc_sli *psli;
3367 struct lpfc_sli_ring *pring;
3374 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3375 "0325 Reset HBA Data: x%x x%x\n",
3376 phba->pport->port_state, psli->sli_flag);
3378 /* perform board reset */
3379 phba->fc_eventTag = 0;
3380 phba->link_events = 0;
3381 phba->pport->fc_myDID = 0;
3382 phba->pport->fc_prevDID = 0;
3384 /* Turn off parity checking and serr during the physical reset */
3385 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3386 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3388 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3390 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
3392 /* Now toggle INITFF bit in the Host Control Register */
3393 writel(HC_INITFF, phba->HCregaddr);
3395 readl(phba->HCregaddr); /* flush */
3396 writel(0, phba->HCregaddr);
3397 readl(phba->HCregaddr); /* flush */
3399 /* Restore PCI cmd register */
3400 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3402 /* Initialize relevant SLI info */
3403 for (i = 0; i < psli->num_rings; i++) {
3404 pring = &psli->ring[i];
3407 pring->next_cmdidx = 0;
3408 pring->local_getidx = 0;
3410 pring->missbufcnt = 0;
3413 phba->link_state = LPFC_WARM_START;
3418 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3419 * @phba: Pointer to HBA context object.
3421 * This function resets a SLI4 HBA. This function disables PCI layer parity
3422 * checking during resets the device. The caller is not required to hold
3425 * This function returns 0 always.
3428 lpfc_sli4_brdreset(struct lpfc_hba *phba)
3430 struct lpfc_sli *psli = &phba->sli;
3435 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3436 "0295 Reset HBA Data: x%x x%x\n",
3437 phba->pport->port_state, psli->sli_flag);
3439 /* perform board reset */
3440 phba->fc_eventTag = 0;
3441 phba->link_events = 0;
3442 phba->pport->fc_myDID = 0;
3443 phba->pport->fc_prevDID = 0;
3445 /* Turn off parity checking and serr during the physical reset */
3446 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3447 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3449 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3451 spin_lock_irq(&phba->hbalock);
3452 psli->sli_flag &= ~(LPFC_PROCESS_LA);
3453 phba->fcf.fcf_flag = 0;
3454 /* Clean up the child queue list for the CQs */
3455 list_del_init(&phba->sli4_hba.mbx_wq->list);
3456 list_del_init(&phba->sli4_hba.els_wq->list);
3457 list_del_init(&phba->sli4_hba.hdr_rq->list);
3458 list_del_init(&phba->sli4_hba.dat_rq->list);
3459 list_del_init(&phba->sli4_hba.mbx_cq->list);
3460 list_del_init(&phba->sli4_hba.els_cq->list);
3461 for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
3462 list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
3463 for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
3464 list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
3465 spin_unlock_irq(&phba->hbalock);
3467 /* Now physically reset the device */
3468 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3469 "0389 Performing PCI function reset!\n");
3470 /* Perform FCoE PCI function reset */
3471 lpfc_pci_function_reset(phba);
3477 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3478 * @phba: Pointer to HBA context object.
3480 * This function is called in the SLI initialization code path to
3481 * restart the HBA. The caller is not required to hold any lock.
3482 * This function writes MBX_RESTART mailbox command to the SLIM and
3483 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3484 * function to free any pending commands. The function enables
3485 * POST only during the first initialization. The function returns zero.
3486 * The function does not guarantee completion of MBX_RESTART mailbox
3487 * command before the return of this function.
3490 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
3493 struct lpfc_sli *psli;
3494 volatile uint32_t word0;
3495 void __iomem *to_slim;
3496 uint32_t hba_aer_enabled;
3498 spin_lock_irq(&phba->hbalock);
3500 /* Take PCIe device Advanced Error Reporting (AER) state */
3501 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
3506 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3507 "0337 Restart HBA Data: x%x x%x\n",
3508 phba->pport->port_state, psli->sli_flag);
3511 mb = (MAILBOX_t *) &word0;
3512 mb->mbxCommand = MBX_RESTART;
3515 lpfc_reset_barrier(phba);
3517 to_slim = phba->MBslimaddr;
3518 writel(*(uint32_t *) mb, to_slim);
3519 readl(to_slim); /* flush */
3521 /* Only skip post after fc_ffinit is completed */
3522 if (phba->pport->port_state)
3523 word0 = 1; /* This is really setting up word1 */
3525 word0 = 0; /* This is really setting up word1 */
3526 to_slim = phba->MBslimaddr + sizeof (uint32_t);
3527 writel(*(uint32_t *) mb, to_slim);
3528 readl(to_slim); /* flush */
3530 lpfc_sli_brdreset(phba);
3531 phba->pport->stopped = 0;
3532 phba->link_state = LPFC_INIT_START;
3534 spin_unlock_irq(&phba->hbalock);
3536 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3537 psli->stats_start = get_seconds();
3539 /* Give the INITFF and Post time to settle. */
3542 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
3543 if (hba_aer_enabled)
3544 pci_disable_pcie_error_reporting(phba->pcidev);
3546 lpfc_hba_down_post(phba);
3552 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3553 * @phba: Pointer to HBA context object.
3555 * This function is called in the SLI initialization code path to restart
3556 * a SLI4 HBA. The caller is not required to hold any lock.
3557 * At the end of the function, it calls lpfc_hba_down_post function to
3558 * free any pending commands.
3561 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
3563 struct lpfc_sli *psli = &phba->sli;
3567 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3568 "0296 Restart HBA Data: x%x x%x\n",
3569 phba->pport->port_state, psli->sli_flag);
3571 lpfc_sli4_brdreset(phba);
3573 spin_lock_irq(&phba->hbalock);
3574 phba->pport->stopped = 0;
3575 phba->link_state = LPFC_INIT_START;
3577 spin_unlock_irq(&phba->hbalock);
3579 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3580 psli->stats_start = get_seconds();
3582 lpfc_hba_down_post(phba);
3588 * lpfc_sli_brdrestart - Wrapper func for restarting hba
3589 * @phba: Pointer to HBA context object.
3591 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
3592 * API jump table function pointer from the lpfc_hba struct.
3595 lpfc_sli_brdrestart(struct lpfc_hba *phba)
3597 return phba->lpfc_sli_brdrestart(phba);
3601 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
3602 * @phba: Pointer to HBA context object.
3604 * This function is called after a HBA restart to wait for successful
3605 * restart of the HBA. Successful restart of the HBA is indicated by
3606 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
3607 * iteration, the function will restart the HBA again. The function returns
3608 * zero if HBA successfully restarted else returns negative error code.
3611 lpfc_sli_chipset_init(struct lpfc_hba *phba)
3613 uint32_t status, i = 0;
3615 /* Read the HBA Host Status Register */
3616 status = readl(phba->HSregaddr);
3618 /* Check status register to see what current state is */
3620 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
3622 /* Check every 100ms for 5 retries, then every 500ms for 5, then
3623 * every 2.5 sec for 5, then reset board and every 2.5 sec for
3627 /* Adapter failed to init, timeout, status reg
3629 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3630 "0436 Adapter failed to init, "
3631 "timeout, status reg x%x, "
3632 "FW Data: A8 x%x AC x%x\n", status,
3633 readl(phba->MBslimaddr + 0xa8),
3634 readl(phba->MBslimaddr + 0xac));
3635 phba->link_state = LPFC_HBA_ERROR;
3639 /* Check to see if any errors occurred during init */
3640 if (status & HS_FFERM) {
3641 /* ERROR: During chipset initialization */
3642 /* Adapter failed to init, chipset, status reg
3644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3645 "0437 Adapter failed to init, "
3646 "chipset, status reg x%x, "
3647 "FW Data: A8 x%x AC x%x\n", status,
3648 readl(phba->MBslimaddr + 0xa8),
3649 readl(phba->MBslimaddr + 0xac));
3650 phba->link_state = LPFC_HBA_ERROR;
3656 } else if (i <= 10) {
3664 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3665 lpfc_sli_brdrestart(phba);
3667 /* Read the HBA Host Status Register */
3668 status = readl(phba->HSregaddr);
3671 /* Check to see if any errors occurred during init */
3672 if (status & HS_FFERM) {
3673 /* ERROR: During chipset initialization */
3674 /* Adapter failed to init, chipset, status reg <status> */
3675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3676 "0438 Adapter failed to init, chipset, "
3678 "FW Data: A8 x%x AC x%x\n", status,
3679 readl(phba->MBslimaddr + 0xa8),
3680 readl(phba->MBslimaddr + 0xac));
3681 phba->link_state = LPFC_HBA_ERROR;
3685 /* Clear all interrupt enable conditions */
3686 writel(0, phba->HCregaddr);
3687 readl(phba->HCregaddr); /* flush */
3689 /* setup host attn register */
3690 writel(0xffffffff, phba->HAregaddr);
3691 readl(phba->HAregaddr); /* flush */
3696 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
3698 * This function calculates and returns the number of HBQs required to be
3702 lpfc_sli_hbq_count(void)
3704 return ARRAY_SIZE(lpfc_hbq_defs);
3708 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
3710 * This function adds the number of hbq entries in every HBQ to get
3711 * the total number of hbq entries required for the HBA and returns
3715 lpfc_sli_hbq_entry_count(void)
3717 int hbq_count = lpfc_sli_hbq_count();
3721 for (i = 0; i < hbq_count; ++i)
3722 count += lpfc_hbq_defs[i]->entry_count;
3727 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
3729 * This function calculates amount of memory required for all hbq entries
3730 * to be configured and returns the total memory required.
3733 lpfc_sli_hbq_size(void)
3735 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
3739 * lpfc_sli_hbq_setup - configure and initialize HBQs
3740 * @phba: Pointer to HBA context object.
3742 * This function is called during the SLI initialization to configure
3743 * all the HBQs and post buffers to the HBQ. The caller is not
3744 * required to hold any locks. This function will return zero if successful
3745 * else it will return negative error code.
3748 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
3750 int hbq_count = lpfc_sli_hbq_count();
3754 uint32_t hbq_entry_index;
3756 /* Get a Mailbox buffer to setup mailbox
3757 * commands for HBA initialization
3759 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3766 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
3767 phba->link_state = LPFC_INIT_MBX_CMDS;
3768 phba->hbq_in_use = 1;
3770 hbq_entry_index = 0;
3771 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
3772 phba->hbqs[hbqno].next_hbqPutIdx = 0;
3773 phba->hbqs[hbqno].hbqPutIdx = 0;
3774 phba->hbqs[hbqno].local_hbqGetIdx = 0;
3775 phba->hbqs[hbqno].entry_count =
3776 lpfc_hbq_defs[hbqno]->entry_count;
3777 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
3778 hbq_entry_index, pmb);
3779 hbq_entry_index += phba->hbqs[hbqno].entry_count;
3781 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
3782 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
3783 mbxStatus <status>, ring <num> */
3785 lpfc_printf_log(phba, KERN_ERR,
3786 LOG_SLI | LOG_VPORT,
3787 "1805 Adapter failed to init. "
3788 "Data: x%x x%x x%x\n",
3790 pmbox->mbxStatus, hbqno);
3792 phba->link_state = LPFC_HBA_ERROR;
3793 mempool_free(pmb, phba->mbox_mem_pool);
3797 phba->hbq_count = hbq_count;
3799 mempool_free(pmb, phba->mbox_mem_pool);
3801 /* Initially populate or replenish the HBQs */
3802 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
3803 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
3808 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
3809 * @phba: Pointer to HBA context object.
3811 * This function is called during the SLI initialization to configure
3812 * all the HBQs and post buffers to the HBQ. The caller is not
3813 * required to hold any locks. This function will return zero if successful
3814 * else it will return negative error code.
3817 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
3819 phba->hbq_in_use = 1;
3820 phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
3821 phba->hbq_count = 1;
3822 /* Initially populate or replenish the HBQs */
3823 lpfc_sli_hbqbuf_init_hbqs(phba, 0);
3828 * lpfc_sli_config_port - Issue config port mailbox command
3829 * @phba: Pointer to HBA context object.
3830 * @sli_mode: sli mode - 2/3
3832 * This function is called by the sli intialization code path
3833 * to issue config_port mailbox command. This function restarts the
3834 * HBA firmware and issues a config_port mailbox command to configure
3835 * the SLI interface in the sli mode specified by sli_mode
3836 * variable. The caller is not required to hold any locks.
3837 * The function returns 0 if successful, else returns negative error
3841 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
3844 uint32_t resetcount = 0, rc = 0, done = 0;
3846 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3848 phba->link_state = LPFC_HBA_ERROR;
3852 phba->sli_rev = sli_mode;
3853 while (resetcount < 2 && !done) {
3854 spin_lock_irq(&phba->hbalock);
3855 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
3856 spin_unlock_irq(&phba->hbalock);
3857 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3858 lpfc_sli_brdrestart(phba);
3859 rc = lpfc_sli_chipset_init(phba);
3863 spin_lock_irq(&phba->hbalock);
3864 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3865 spin_unlock_irq(&phba->hbalock);
3868 /* Call pre CONFIG_PORT mailbox command initialization. A
3869 * value of 0 means the call was successful. Any other
3870 * nonzero value is a failure, but if ERESTART is returned,
3871 * the driver may reset the HBA and try again.
3873 rc = lpfc_config_port_prep(phba);
3874 if (rc == -ERESTART) {
3875 phba->link_state = LPFC_LINK_UNKNOWN;
3879 phba->link_state = LPFC_INIT_MBX_CMDS;
3880 lpfc_config_port(phba, pmb);
3881 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
3882 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
3883 LPFC_SLI3_HBQ_ENABLED |
3884 LPFC_SLI3_CRP_ENABLED |
3885 LPFC_SLI3_INB_ENABLED |
3886 LPFC_SLI3_BG_ENABLED);
3887 if (rc != MBX_SUCCESS) {
3888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3889 "0442 Adapter failed to init, mbxCmd x%x "
3890 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3891 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
3892 spin_lock_irq(&phba->hbalock);
3893 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
3894 spin_unlock_irq(&phba->hbalock);
3897 /* Allow asynchronous mailbox command to go through */
3898 spin_lock_irq(&phba->hbalock);
3899 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
3900 spin_unlock_irq(&phba->hbalock);
3906 goto do_prep_failed;
3908 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
3909 if (!pmb->u.mb.un.varCfgPort.cMA) {
3911 goto do_prep_failed;
3913 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
3914 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3915 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
3916 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
3917 phba->max_vpi : phba->max_vports;
3921 if (pmb->u.mb.un.varCfgPort.gdss)
3922 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
3923 if (pmb->u.mb.un.varCfgPort.gerbm)
3924 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
3925 if (pmb->u.mb.un.varCfgPort.gcrp)
3926 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
3927 if (pmb->u.mb.un.varCfgPort.ginb) {
3928 phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
3929 phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
3930 phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
3931 phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
3932 phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
3933 phba->inb_last_counter =
3934 phba->mbox->us.s3_inb_pgp.counter;
3936 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
3937 phba->port_gp = phba->mbox->us.s3_pgp.port;
3938 phba->inb_ha_copy = NULL;
3939 phba->inb_counter = NULL;
3942 if (phba->cfg_enable_bg) {
3943 if (pmb->u.mb.un.varCfgPort.gbg)
3944 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
3946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3947 "0443 Adapter did not grant "
3951 phba->hbq_get = NULL;
3952 phba->port_gp = phba->mbox->us.s2.port;
3953 phba->inb_ha_copy = NULL;
3954 phba->inb_counter = NULL;
3958 mempool_free(pmb, phba->mbox_mem_pool);
3964 * lpfc_sli_hba_setup - SLI intialization function
3965 * @phba: Pointer to HBA context object.
3967 * This function is the main SLI intialization function. This function
3968 * is called by the HBA intialization code, HBA reset code and HBA
3969 * error attention handler code. Caller is not required to hold any
3970 * locks. This function issues config_port mailbox command to configure
3971 * the SLI, setup iocb rings and HBQ rings. In the end the function
3972 * calls the config_port_post function to issue init_link mailbox
3973 * command and to start the discovery. The function will return zero
3974 * if successful, else it will return negative error code.
3977 lpfc_sli_hba_setup(struct lpfc_hba *phba)
3982 switch (lpfc_sli_mode) {
3984 if (phba->cfg_enable_npiv) {
3985 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
3986 "1824 NPIV enabled: Override lpfc_sli_mode "
3987 "parameter (%d) to auto (0).\n",
3997 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
3998 "1819 Unrecognized lpfc_sli_mode "
3999 "parameter: %d.\n", lpfc_sli_mode);
4004 rc = lpfc_sli_config_port(phba, mode);
4006 if (rc && lpfc_sli_mode == 3)
4007 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4008 "1820 Unable to select SLI-3. "
4009 "Not supported by adapter.\n");
4010 if (rc && mode != 2)
4011 rc = lpfc_sli_config_port(phba, 2);
4013 goto lpfc_sli_hba_setup_error;
4015 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4016 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
4017 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4019 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4020 "2709 This device supports "
4021 "Advanced Error Reporting (AER)\n");
4022 spin_lock_irq(&phba->hbalock);
4023 phba->hba_flag |= HBA_AER_ENABLED;
4024 spin_unlock_irq(&phba->hbalock);
4026 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4027 "2708 This device does not support "
4028 "Advanced Error Reporting (AER)\n");
4029 phba->cfg_aer_support = 0;
4033 if (phba->sli_rev == 3) {
4034 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4035 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
4037 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4038 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
4039 phba->sli3_options = 0;
4042 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4043 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4044 phba->sli_rev, phba->max_vpi);
4045 rc = lpfc_sli_ring_map(phba);
4048 goto lpfc_sli_hba_setup_error;
4051 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4052 rc = lpfc_sli_hbq_setup(phba);
4054 goto lpfc_sli_hba_setup_error;
4056 spin_lock_irq(&phba->hbalock);
4057 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4058 spin_unlock_irq(&phba->hbalock);
4060 rc = lpfc_config_port_post(phba);
4062 goto lpfc_sli_hba_setup_error;
4066 lpfc_sli_hba_setup_error:
4067 phba->link_state = LPFC_HBA_ERROR;
4068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4069 "0445 Firmware initialization failed\n");
4074 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4075 * @phba: Pointer to HBA context object.
4076 * @mboxq: mailbox pointer.
4077 * This function issue a dump mailbox command to read config region
4078 * 23 and parse the records in the region and populate driver
4082 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
4083 LPFC_MBOXQ_t *mboxq)
4085 struct lpfc_dmabuf *mp;
4086 struct lpfc_mqe *mqe;
4087 uint32_t data_length;
4090 /* Program the default value of vlan_id and fc_map */
4091 phba->valid_vlan = 0;
4092 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4093 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4094 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4096 mqe = &mboxq->u.mqe;
4097 if (lpfc_dump_fcoe_param(phba, mboxq))
4100 mp = (struct lpfc_dmabuf *) mboxq->context1;
4101 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4103 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4104 "(%d):2571 Mailbox cmd x%x Status x%x "
4105 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4106 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4107 "CQ: x%x x%x x%x x%x\n",
4108 mboxq->vport ? mboxq->vport->vpi : 0,
4109 bf_get(lpfc_mqe_command, mqe),
4110 bf_get(lpfc_mqe_status, mqe),
4111 mqe->un.mb_words[0], mqe->un.mb_words[1],
4112 mqe->un.mb_words[2], mqe->un.mb_words[3],
4113 mqe->un.mb_words[4], mqe->un.mb_words[5],
4114 mqe->un.mb_words[6], mqe->un.mb_words[7],
4115 mqe->un.mb_words[8], mqe->un.mb_words[9],
4116 mqe->un.mb_words[10], mqe->un.mb_words[11],
4117 mqe->un.mb_words[12], mqe->un.mb_words[13],
4118 mqe->un.mb_words[14], mqe->un.mb_words[15],
4119 mqe->un.mb_words[16], mqe->un.mb_words[50],
4121 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4122 mboxq->mcqe.trailer);
4125 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4129 data_length = mqe->un.mb_words[5];
4130 if (data_length > DMP_RGN23_SIZE) {
4131 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4136 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
4137 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4143 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4144 * @phba: pointer to lpfc hba data structure.
4145 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4146 * @vpd: pointer to the memory to hold resulting port vpd data.
4147 * @vpd_size: On input, the number of bytes allocated to @vpd.
4148 * On output, the number of data bytes in @vpd.
4150 * This routine executes a READ_REV SLI4 mailbox command. In
4151 * addition, this routine gets the port vpd data.
4155 * ENOMEM - could not allocated memory.
4158 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4159 uint8_t *vpd, uint32_t *vpd_size)
4163 struct lpfc_dmabuf *dmabuf;
4164 struct lpfc_mqe *mqe;
4166 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4171 * Get a DMA buffer for the vpd data resulting from the READ_REV
4174 dma_size = *vpd_size;
4175 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4179 if (!dmabuf->virt) {
4183 memset(dmabuf->virt, 0, dma_size);
4186 * The SLI4 implementation of READ_REV conflicts at word1,
4187 * bits 31:16 and SLI4 adds vpd functionality not present
4188 * in SLI3. This code corrects the conflicts.
4190 lpfc_read_rev(phba, mboxq);
4191 mqe = &mboxq->u.mqe;
4192 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
4193 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
4194 mqe->un.read_rev.word1 &= 0x0000FFFF;
4195 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
4196 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
4198 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4200 dma_free_coherent(&phba->pcidev->dev, dma_size,
4201 dmabuf->virt, dmabuf->phys);
4207 * The available vpd length cannot be bigger than the
4208 * DMA buffer passed to the port. Catch the less than
4209 * case and update the caller's size.
4211 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
4212 *vpd_size = mqe->un.read_rev.avail_vpd_len;
4214 lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
4215 dma_free_coherent(&phba->pcidev->dev, dma_size,
4216 dmabuf->virt, dmabuf->phys);
4222 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4223 * @phba: pointer to lpfc hba data structure.
4225 * This routine is called to explicitly arm the SLI4 device's completion and
4229 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
4233 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
4234 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
4235 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4236 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
4238 lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
4239 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4240 lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
4245 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4246 * @phba: Pointer to HBA context object.
4248 * This function is the main SLI4 device intialization PCI function. This
4249 * function is called by the HBA intialization code, HBA reset code and
4250 * HBA error attention handler code. Caller is not required to hold any
4254 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
4257 LPFC_MBOXQ_t *mboxq;
4258 struct lpfc_mqe *mqe;
4261 uint32_t ftr_rsp = 0;
4262 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
4263 struct lpfc_vport *vport = phba->pport;
4264 struct lpfc_dmabuf *mp;
4266 /* Perform a PCI function reset to start from clean */
4267 rc = lpfc_pci_function_reset(phba);
4271 /* Check the HBA Host Status Register for readyness */
4272 rc = lpfc_sli4_post_status_check(phba);
4276 spin_lock_irq(&phba->hbalock);
4277 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
4278 spin_unlock_irq(&phba->hbalock);
4282 * Allocate a single mailbox container for initializing the
4285 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4290 * Continue initialization with default values even if driver failed
4291 * to read FCoE param config regions
4293 if (lpfc_sli4_read_fcoe_params(phba, mboxq))
4294 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
4295 "2570 Failed to read FCoE parameters\n");
4297 /* Issue READ_REV to collect vpd and FW information. */
4298 vpd_size = PAGE_SIZE;
4299 vpd = kzalloc(vpd_size, GFP_KERNEL);
4305 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
4309 mqe = &mboxq->u.mqe;
4310 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
4311 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
4312 phba->hba_flag |= HBA_FCOE_SUPPORT;
4314 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
4316 phba->hba_flag |= HBA_FIP_SUPPORT;
4318 phba->hba_flag &= ~HBA_FIP_SUPPORT;
4320 if (phba->sli_rev != LPFC_SLI_REV4 ||
4321 !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
4322 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4323 "0376 READ_REV Error. SLI Level %d "
4324 "FCoE enabled %d\n",
4325 phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
4330 * Evaluate the read rev and vpd data. Populate the driver
4331 * state with the results. If this routine fails, the failure
4332 * is not fatal as the driver will use generic values.
4334 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
4335 if (unlikely(!rc)) {
4336 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4337 "0377 Error %d parsing vpd. "
4338 "Using defaults.\n", rc);
4342 /* Save information as VPD data */
4343 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
4344 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
4345 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
4346 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
4348 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
4350 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
4352 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
4354 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
4355 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
4356 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
4357 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
4358 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
4359 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
4360 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4361 "(%d):0380 READ_REV Status x%x "
4362 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
4363 mboxq->vport ? mboxq->vport->vpi : 0,
4364 bf_get(lpfc_mqe_status, mqe),
4365 phba->vpd.rev.opFwName,
4366 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
4367 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
4370 * Discover the port's supported feature set and match it against the
4373 lpfc_request_features(phba, mboxq);
4374 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4381 * The port must support FCP initiator mode as this is the
4382 * only mode running in the host.
4384 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
4385 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4386 "0378 No support for fcpi mode.\n");
4391 * If the port cannot support the host's requested features
4392 * then turn off the global config parameters to disable the
4393 * feature in the driver. This is not a fatal error.
4395 if ((phba->cfg_enable_bg) &&
4396 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
4399 if (phba->max_vpi && phba->cfg_enable_npiv &&
4400 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
4404 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4405 "0379 Feature Mismatch Data: x%08x %08x "
4406 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
4407 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
4408 phba->cfg_enable_npiv, phba->max_vpi);
4409 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
4410 phba->cfg_enable_bg = 0;
4411 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
4412 phba->cfg_enable_npiv = 0;
4415 /* These SLI3 features are assumed in SLI4 */
4416 spin_lock_irq(&phba->hbalock);
4417 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
4418 spin_unlock_irq(&phba->hbalock);
4420 /* Read the port's service parameters. */
4421 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
4423 phba->link_state = LPFC_HBA_ERROR;
4428 mboxq->vport = vport;
4429 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4430 mp = (struct lpfc_dmabuf *) mboxq->context1;
4431 if (rc == MBX_SUCCESS) {
4432 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
4437 * This memory was allocated by the lpfc_read_sparam routine. Release
4438 * it to the mbuf pool.
4440 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4442 mboxq->context1 = NULL;
4444 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4445 "0382 READ_SPARAM command failed "
4446 "status %d, mbxStatus x%x\n",
4447 rc, bf_get(lpfc_mqe_status, mqe));
4448 phba->link_state = LPFC_HBA_ERROR;
4453 if (phba->cfg_soft_wwnn)
4454 u64_to_wwn(phba->cfg_soft_wwnn,
4455 vport->fc_sparam.nodeName.u.wwn);
4456 if (phba->cfg_soft_wwpn)
4457 u64_to_wwn(phba->cfg_soft_wwpn,
4458 vport->fc_sparam.portName.u.wwn);
4459 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
4460 sizeof(struct lpfc_name));
4461 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
4462 sizeof(struct lpfc_name));
4464 /* Update the fc_host data structures with new wwn. */
4465 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4466 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4468 /* Register SGL pool to the device using non-embedded mailbox command */
4469 rc = lpfc_sli4_post_sgl_list(phba);
4471 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4472 "0582 Error %d during sgl post operation\n",
4478 /* Register SCSI SGL pool to the device */
4479 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
4481 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4482 "0383 Error %d during scsi sgl post "
4484 /* Some Scsi buffers were moved to the abort scsi list */
4485 /* A pci function reset will repost them */
4490 /* Post the rpi header region to the device. */
4491 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
4493 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4494 "0393 Error %d during rpi post operation\n",
4500 /* Set up all the queues to the device */
4501 rc = lpfc_sli4_queue_setup(phba);
4503 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4504 "0381 Error %d during queue setup.\n ", rc);
4505 goto out_stop_timers;
4508 /* Arm the CQs and then EQs on device */
4509 lpfc_sli4_arm_cqeq_intr(phba);
4511 /* Indicate device interrupt mode */
4512 phba->sli4_hba.intr_enable = 1;
4514 /* Allow asynchronous mailbox command to go through */
4515 spin_lock_irq(&phba->hbalock);
4516 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4517 spin_unlock_irq(&phba->hbalock);
4519 /* Post receive buffers to the device */
4520 lpfc_sli4_rb_setup(phba);
4522 /* Reset HBA FCF states after HBA reset */
4523 phba->fcf.fcf_flag = 0;
4524 phba->fcf.current_rec.flag = 0;
4526 /* Start the ELS watchdog timer */
4527 mod_timer(&vport->els_tmofunc,
4528 jiffies + HZ * (phba->fc_ratov * 2));
4530 /* Start heart beat timer */
4531 mod_timer(&phba->hb_tmofunc,
4532 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
4533 phba->hb_outstanding = 0;
4534 phba->last_completion_time = jiffies;
4536 /* Start error attention (ERATT) polling timer */
4537 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
4540 * The port is ready, set the host's link state to LINK_DOWN
4541 * in preparation for link interrupts.
4543 lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
4544 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4545 lpfc_set_loopback_flag(phba);
4546 /* Change driver state to LPFC_LINK_DOWN right before init link */
4547 spin_lock_irq(&phba->hbalock);
4548 phba->link_state = LPFC_LINK_DOWN;
4549 spin_unlock_irq(&phba->hbalock);
4550 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
4551 if (unlikely(rc != MBX_NOT_FINISHED)) {
4557 /* Unset all the queues set up in this routine when error out */
4559 lpfc_sli4_queue_unset(phba);
4563 lpfc_stop_hba_timers(phba);
4567 mempool_free(mboxq, phba->mbox_mem_pool);
4572 * lpfc_mbox_timeout - Timeout call back function for mbox timer
4573 * @ptr: context object - pointer to hba structure.
4575 * This is the callback function for mailbox timer. The mailbox
4576 * timer is armed when a new mailbox command is issued and the timer
4577 * is deleted when the mailbox complete. The function is called by
4578 * the kernel timer code when a mailbox does not complete within
4579 * expected time. This function wakes up the worker thread to
4580 * process the mailbox timeout and returns. All the processing is
4581 * done by the worker thread function lpfc_mbox_timeout_handler.
4584 lpfc_mbox_timeout(unsigned long ptr)
4586 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4587 unsigned long iflag;
4588 uint32_t tmo_posted;
4590 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
4591 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
4593 phba->pport->work_port_events |= WORKER_MBOX_TMO;
4594 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
4597 lpfc_worker_wake_up(phba);
4603 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
4604 * @phba: Pointer to HBA context object.
4606 * This function is called from worker thread when a mailbox command times out.
4607 * The caller is not required to hold any locks. This function will reset the
4608 * HBA and recover all the pending commands.
4611 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
4613 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
4614 MAILBOX_t *mb = &pmbox->u.mb;
4615 struct lpfc_sli *psli = &phba->sli;
4616 struct lpfc_sli_ring *pring;
4618 /* Check the pmbox pointer first. There is a race condition
4619 * between the mbox timeout handler getting executed in the
4620 * worklist and the mailbox actually completing. When this
4621 * race condition occurs, the mbox_active will be NULL.
4623 spin_lock_irq(&phba->hbalock);
4624 if (pmbox == NULL) {
4625 lpfc_printf_log(phba, KERN_WARNING,
4627 "0353 Active Mailbox cleared - mailbox timeout "
4629 spin_unlock_irq(&phba->hbalock);
4633 /* Mbox cmd <mbxCommand> timeout */
4634 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4635 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
4637 phba->pport->port_state,
4639 phba->sli.mbox_active);
4640 spin_unlock_irq(&phba->hbalock);
4642 /* Setting state unknown so lpfc_sli_abort_iocb_ring
4643 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
4644 * it to fail all oustanding SCSI IO.
4646 spin_lock_irq(&phba->pport->work_port_lock);
4647 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
4648 spin_unlock_irq(&phba->pport->work_port_lock);
4649 spin_lock_irq(&phba->hbalock);
4650 phba->link_state = LPFC_LINK_UNKNOWN;
4651 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4652 spin_unlock_irq(&phba->hbalock);
4654 pring = &psli->ring[psli->fcp_ring];
4655 lpfc_sli_abort_iocb_ring(phba, pring);
4657 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4658 "0345 Resetting board due to mailbox timeout\n");
4660 /* Reset the HBA device */
4661 lpfc_reset_hba(phba);
4665 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
4666 * @phba: Pointer to HBA context object.
4667 * @pmbox: Pointer to mailbox object.
4668 * @flag: Flag indicating how the mailbox need to be processed.
4670 * This function is called by discovery code and HBA management code
4671 * to submit a mailbox command to firmware with SLI-3 interface spec. This
4672 * function gets the hbalock to protect the data structures.
4673 * The mailbox command can be submitted in polling mode, in which case
4674 * this function will wait in a polling loop for the completion of the
4676 * If the mailbox is submitted in no_wait mode (not polling) the
4677 * function will submit the command and returns immediately without waiting
4678 * for the mailbox completion. The no_wait is supported only when HBA
4679 * is in SLI2/SLI3 mode - interrupts are enabled.
4680 * The SLI interface allows only one mailbox pending at a time. If the
4681 * mailbox is issued in polling mode and there is already a mailbox
4682 * pending, then the function will return an error. If the mailbox is issued
4683 * in NO_WAIT mode and there is a mailbox pending already, the function
4684 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
4685 * The sli layer owns the mailbox object until the completion of mailbox
4686 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
4687 * return codes the caller owns the mailbox command after the return of
4691 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
4695 struct lpfc_sli *psli = &phba->sli;
4696 uint32_t status, evtctr;
4699 unsigned long timeout;
4700 unsigned long drvr_flag = 0;
4701 uint32_t word0, ldata;
4702 void __iomem *to_slim;
4703 int processing_queue = 0;
4705 spin_lock_irqsave(&phba->hbalock, drvr_flag);
4707 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4708 /* processing mbox queue from intr_handler */
4709 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
4710 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4713 processing_queue = 1;
4714 pmbox = lpfc_mbox_get(phba);
4716 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4721 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
4722 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
4724 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4725 lpfc_printf_log(phba, KERN_ERR,
4726 LOG_MBOX | LOG_VPORT,
4727 "1806 Mbox x%x failed. No vport\n",
4728 pmbox->u.mb.mbxCommand);
4730 goto out_not_finished;
4734 /* If the PCI channel is in offline state, do not post mbox. */
4735 if (unlikely(pci_channel_offline(phba->pcidev))) {
4736 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4737 goto out_not_finished;
4740 /* If HBA has a deferred error attention, fail the iocb. */
4741 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
4742 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4743 goto out_not_finished;
4749 status = MBX_SUCCESS;
4751 if (phba->link_state == LPFC_HBA_ERROR) {
4752 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4754 /* Mbox command <mbxCommand> cannot issue */
4755 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4756 "(%d):0311 Mailbox command x%x cannot "
4757 "issue Data: x%x x%x\n",
4758 pmbox->vport ? pmbox->vport->vpi : 0,
4759 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
4760 goto out_not_finished;
4763 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
4764 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
4765 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4766 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4767 "(%d):2528 Mailbox command x%x cannot "
4768 "issue Data: x%x x%x\n",
4769 pmbox->vport ? pmbox->vport->vpi : 0,
4770 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
4771 goto out_not_finished;
4774 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
4775 /* Polling for a mbox command when another one is already active
4776 * is not allowed in SLI. Also, the driver must have established
4777 * SLI2 mode to queue and process multiple mbox commands.
4780 if (flag & MBX_POLL) {
4781 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4783 /* Mbox command <mbxCommand> cannot issue */
4784 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4785 "(%d):2529 Mailbox command x%x "
4786 "cannot issue Data: x%x x%x\n",
4787 pmbox->vport ? pmbox->vport->vpi : 0,
4788 pmbox->u.mb.mbxCommand,
4789 psli->sli_flag, flag);
4790 goto out_not_finished;
4793 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
4794 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4795 /* Mbox command <mbxCommand> cannot issue */
4796 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4797 "(%d):2530 Mailbox command x%x "
4798 "cannot issue Data: x%x x%x\n",
4799 pmbox->vport ? pmbox->vport->vpi : 0,
4800 pmbox->u.mb.mbxCommand,
4801 psli->sli_flag, flag);
4802 goto out_not_finished;
4805 /* Another mailbox command is still being processed, queue this
4806 * command to be processed later.
4808 lpfc_mbox_put(phba, pmbox);
4810 /* Mbox cmd issue - BUSY */
4811 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4812 "(%d):0308 Mbox cmd issue - BUSY Data: "
4813 "x%x x%x x%x x%x\n",
4814 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
4815 mb->mbxCommand, phba->pport->port_state,
4816 psli->sli_flag, flag);
4818 psli->slistat.mbox_busy++;
4819 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4822 lpfc_debugfs_disc_trc(pmbox->vport,
4823 LPFC_DISC_TRC_MBOX_VPORT,
4824 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
4825 (uint32_t)mb->mbxCommand,
4826 mb->un.varWords[0], mb->un.varWords[1]);
4829 lpfc_debugfs_disc_trc(phba->pport,
4831 "MBOX Bsy: cmd:x%x mb:x%x x%x",
4832 (uint32_t)mb->mbxCommand,
4833 mb->un.varWords[0], mb->un.varWords[1]);
4839 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4841 /* If we are not polling, we MUST be in SLI2 mode */
4842 if (flag != MBX_POLL) {
4843 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
4844 (mb->mbxCommand != MBX_KILL_BOARD)) {
4845 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4846 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4847 /* Mbox command <mbxCommand> cannot issue */
4848 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4849 "(%d):2531 Mailbox command x%x "
4850 "cannot issue Data: x%x x%x\n",
4851 pmbox->vport ? pmbox->vport->vpi : 0,
4852 pmbox->u.mb.mbxCommand,
4853 psli->sli_flag, flag);
4854 goto out_not_finished;
4856 /* timeout active mbox command */
4857 mod_timer(&psli->mbox_tmo, (jiffies +
4858 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
4861 /* Mailbox cmd <cmd> issue */
4862 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4863 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
4865 pmbox->vport ? pmbox->vport->vpi : 0,
4866 mb->mbxCommand, phba->pport->port_state,
4867 psli->sli_flag, flag);
4869 if (mb->mbxCommand != MBX_HEARTBEAT) {
4871 lpfc_debugfs_disc_trc(pmbox->vport,
4872 LPFC_DISC_TRC_MBOX_VPORT,
4873 "MBOX Send vport: cmd:x%x mb:x%x x%x",
4874 (uint32_t)mb->mbxCommand,
4875 mb->un.varWords[0], mb->un.varWords[1]);
4878 lpfc_debugfs_disc_trc(phba->pport,
4880 "MBOX Send: cmd:x%x mb:x%x x%x",
4881 (uint32_t)mb->mbxCommand,
4882 mb->un.varWords[0], mb->un.varWords[1]);
4886 psli->slistat.mbox_cmd++;
4887 evtctr = psli->slistat.mbox_event;
4889 /* next set own bit for the adapter and copy over command word */
4890 mb->mbxOwner = OWN_CHIP;
4892 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4893 /* First copy command data to host SLIM area */
4894 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
4896 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4897 /* copy command data into host mbox for cmpl */
4898 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
4901 /* First copy mbox command data to HBA SLIM, skip past first
4903 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4904 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
4905 MAILBOX_CMD_SIZE - sizeof (uint32_t));
4907 /* Next copy over first word, with mbxOwner set */
4908 ldata = *((uint32_t *)mb);
4909 to_slim = phba->MBslimaddr;
4910 writel(ldata, to_slim);
4911 readl(to_slim); /* flush */
4913 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4914 /* switch over to host mailbox */
4915 psli->sli_flag |= LPFC_SLI_ACTIVE;
4923 /* Set up reference to mailbox command */
4924 psli->mbox_active = pmbox;
4925 /* Interrupt board to do it */
4926 writel(CA_MBATT, phba->CAregaddr);
4927 readl(phba->CAregaddr); /* flush */
4928 /* Don't wait for it to finish, just return */
4932 /* Set up null reference to mailbox command */
4933 psli->mbox_active = NULL;
4934 /* Interrupt board to do it */
4935 writel(CA_MBATT, phba->CAregaddr);
4936 readl(phba->CAregaddr); /* flush */
4938 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4939 /* First read mbox status word */
4940 word0 = *((uint32_t *)phba->mbox);
4941 word0 = le32_to_cpu(word0);
4943 /* First read mbox status word */
4944 word0 = readl(phba->MBslimaddr);
4947 /* Read the HBA Host Attention Register */
4948 ha_copy = readl(phba->HAregaddr);
4949 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
4953 /* Wait for command to complete */
4954 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
4955 (!(ha_copy & HA_MBATT) &&
4956 (phba->link_state > LPFC_WARM_START))) {
4957 if (time_after(jiffies, timeout)) {
4958 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4959 spin_unlock_irqrestore(&phba->hbalock,
4961 goto out_not_finished;
4964 /* Check if we took a mbox interrupt while we were
4966 if (((word0 & OWN_CHIP) != OWN_CHIP)
4967 && (evtctr != psli->slistat.mbox_event))
4971 spin_unlock_irqrestore(&phba->hbalock,
4974 spin_lock_irqsave(&phba->hbalock, drvr_flag);
4977 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4978 /* First copy command data */
4979 word0 = *((uint32_t *)phba->mbox);
4980 word0 = le32_to_cpu(word0);
4981 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4984 /* Check real SLIM for any errors */
4985 slimword0 = readl(phba->MBslimaddr);
4986 slimmb = (MAILBOX_t *) & slimword0;
4987 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
4988 && slimmb->mbxStatus) {
4995 /* First copy command data */
4996 word0 = readl(phba->MBslimaddr);
4998 /* Read the HBA Host Attention Register */
4999 ha_copy = readl(phba->HAregaddr);
5002 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
5003 /* copy results back to user */
5004 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
5006 /* First copy command data */
5007 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
5009 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
5011 lpfc_memcpy_from_slim((void *)pmbox->context2,
5012 phba->MBslimaddr + DMP_RSP_OFFSET,
5013 mb->un.varDmp.word_cnt);
5017 writel(HA_MBATT, phba->HAregaddr);
5018 readl(phba->HAregaddr); /* flush */
5020 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5021 status = mb->mbxStatus;
5024 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
5028 if (processing_queue) {
5029 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
5030 lpfc_mbox_cmpl_put(phba, pmbox);
5032 return MBX_NOT_FINISHED;
5036 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
5037 * @phba: Pointer to HBA context object.
5039 * The function blocks the posting of SLI4 asynchronous mailbox commands from
5040 * the driver internal pending mailbox queue. It will then try to wait out the
5041 * possible outstanding mailbox command before return.
5044 * 0 - the outstanding mailbox command completed; otherwise, the wait for
5045 * the outstanding mailbox command timed out.
5048 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
5050 struct lpfc_sli *psli = &phba->sli;
5051 uint8_t actcmd = MBX_HEARTBEAT;
5053 unsigned long timeout;
5055 /* Mark the asynchronous mailbox command posting as blocked */
5056 spin_lock_irq(&phba->hbalock);
5057 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
5058 if (phba->sli.mbox_active)
5059 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
5060 spin_unlock_irq(&phba->hbalock);
5061 /* Determine how long we might wait for the active mailbox
5062 * command to be gracefully completed by firmware.
5064 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
5066 /* Wait for the outstnading mailbox command to complete */
5067 while (phba->sli.mbox_active) {
5068 /* Check active mailbox complete status every 2ms */
5070 if (time_after(jiffies, timeout)) {
5071 /* Timeout, marked the outstanding cmd not complete */
5077 /* Can not cleanly block async mailbox command, fails it */
5079 spin_lock_irq(&phba->hbalock);
5080 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5081 spin_unlock_irq(&phba->hbalock);
5087 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
5088 * @phba: Pointer to HBA context object.
5090 * The function unblocks and resume posting of SLI4 asynchronous mailbox
5091 * commands from the driver internal pending mailbox queue. It makes sure
5092 * that there is no outstanding mailbox command before resuming posting
5093 * asynchronous mailbox commands. If, for any reason, there is outstanding
5094 * mailbox command, it will try to wait it out before resuming asynchronous
5095 * mailbox command posting.
5098 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
5100 struct lpfc_sli *psli = &phba->sli;
5102 spin_lock_irq(&phba->hbalock);
5103 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
5104 /* Asynchronous mailbox posting is not blocked, do nothing */
5105 spin_unlock_irq(&phba->hbalock);
5109 /* Outstanding synchronous mailbox command is guaranteed to be done,
5110 * successful or timeout, after timing-out the outstanding mailbox
5111 * command shall always be removed, so just unblock posting async
5112 * mailbox command and resume
5114 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5115 spin_unlock_irq(&phba->hbalock);
5117 /* wake up worker thread to post asynchronlous mailbox command */
5118 lpfc_worker_wake_up(phba);
5122 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5123 * @phba: Pointer to HBA context object.
5124 * @mboxq: Pointer to mailbox object.
5126 * The function posts a mailbox to the port. The mailbox is expected
5127 * to be comletely filled in and ready for the port to operate on it.
5128 * This routine executes a synchronous completion operation on the
5129 * mailbox by polling for its completion.
5131 * The caller must not be holding any locks when calling this routine.
5134 * MBX_SUCCESS - mailbox posted successfully
5135 * Any of the MBX error values.
5138 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5140 int rc = MBX_SUCCESS;
5141 unsigned long iflag;
5143 uint32_t mcqe_status;
5145 unsigned long timeout;
5146 struct lpfc_sli *psli = &phba->sli;
5147 struct lpfc_mqe *mb = &mboxq->u.mqe;
5148 struct lpfc_bmbx_create *mbox_rgn;
5149 struct dma_address *dma_address;
5150 struct lpfc_register bmbx_reg;
5153 * Only one mailbox can be active to the bootstrap mailbox region
5154 * at a time and there is no queueing provided.
5156 spin_lock_irqsave(&phba->hbalock, iflag);
5157 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
5158 spin_unlock_irqrestore(&phba->hbalock, iflag);
5159 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5160 "(%d):2532 Mailbox command x%x (x%x) "
5161 "cannot issue Data: x%x x%x\n",
5162 mboxq->vport ? mboxq->vport->vpi : 0,
5163 mboxq->u.mb.mbxCommand,
5164 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5165 psli->sli_flag, MBX_POLL);
5166 return MBXERR_ERROR;
5168 /* The server grabs the token and owns it until release */
5169 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5170 phba->sli.mbox_active = mboxq;
5171 spin_unlock_irqrestore(&phba->hbalock, iflag);
5174 * Initialize the bootstrap memory region to avoid stale data areas
5175 * in the mailbox post. Then copy the caller's mailbox contents to
5176 * the bmbx mailbox region.
5178 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
5179 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
5180 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
5181 sizeof(struct lpfc_mqe));
5183 /* Post the high mailbox dma address to the port and wait for ready. */
5184 dma_address = &phba->sli4_hba.bmbx.dma_address;
5185 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
5187 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
5190 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
5191 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
5195 if (time_after(jiffies, timeout)) {
5199 } while (!db_ready);
5201 /* Post the low mailbox dma address to the port. */
5202 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
5203 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
5206 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
5207 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
5211 if (time_after(jiffies, timeout)) {
5215 } while (!db_ready);
5218 * Read the CQ to ensure the mailbox has completed.
5219 * If so, update the mailbox status so that the upper layers
5220 * can complete the request normally.
5222 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
5223 sizeof(struct lpfc_mqe));
5224 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
5225 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
5226 sizeof(struct lpfc_mcqe));
5227 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
5229 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5230 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
5231 bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
5235 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5236 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5237 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5238 " x%x x%x CQ: x%x x%x x%x x%x\n",
5239 mboxq->vport ? mboxq->vport->vpi : 0,
5240 mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
5241 bf_get(lpfc_mqe_status, mb),
5242 mb->un.mb_words[0], mb->un.mb_words[1],
5243 mb->un.mb_words[2], mb->un.mb_words[3],
5244 mb->un.mb_words[4], mb->un.mb_words[5],
5245 mb->un.mb_words[6], mb->un.mb_words[7],
5246 mb->un.mb_words[8], mb->un.mb_words[9],
5247 mb->un.mb_words[10], mb->un.mb_words[11],
5248 mb->un.mb_words[12], mboxq->mcqe.word0,
5249 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5250 mboxq->mcqe.trailer);
5252 /* We are holding the token, no needed for lock when release */
5253 spin_lock_irqsave(&phba->hbalock, iflag);
5254 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5255 phba->sli.mbox_active = NULL;
5256 spin_unlock_irqrestore(&phba->hbalock, iflag);
5261 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5262 * @phba: Pointer to HBA context object.
5263 * @pmbox: Pointer to mailbox object.
5264 * @flag: Flag indicating how the mailbox need to be processed.
5266 * This function is called by discovery code and HBA management code to submit
5267 * a mailbox command to firmware with SLI-4 interface spec.
5269 * Return codes the caller owns the mailbox command after the return of the
5273 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5276 struct lpfc_sli *psli = &phba->sli;
5277 unsigned long iflags;
5280 rc = lpfc_mbox_dev_check(phba);
5282 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5283 "(%d):2544 Mailbox command x%x (x%x) "
5284 "cannot issue Data: x%x x%x\n",
5285 mboxq->vport ? mboxq->vport->vpi : 0,
5286 mboxq->u.mb.mbxCommand,
5287 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5288 psli->sli_flag, flag);
5289 goto out_not_finished;
5292 /* Detect polling mode and jump to a handler */
5293 if (!phba->sli4_hba.intr_enable) {
5294 if (flag == MBX_POLL)
5295 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
5298 if (rc != MBX_SUCCESS)
5299 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5300 "(%d):2541 Mailbox command x%x "
5301 "(x%x) cannot issue Data: x%x x%x\n",
5302 mboxq->vport ? mboxq->vport->vpi : 0,
5303 mboxq->u.mb.mbxCommand,
5304 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5305 psli->sli_flag, flag);
5307 } else if (flag == MBX_POLL) {
5308 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
5309 "(%d):2542 Try to issue mailbox command "
5310 "x%x (x%x) synchronously ahead of async"
5311 "mailbox command queue: x%x x%x\n",
5312 mboxq->vport ? mboxq->vport->vpi : 0,
5313 mboxq->u.mb.mbxCommand,
5314 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5315 psli->sli_flag, flag);
5316 /* Try to block the asynchronous mailbox posting */
5317 rc = lpfc_sli4_async_mbox_block(phba);
5319 /* Successfully blocked, now issue sync mbox cmd */
5320 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
5321 if (rc != MBX_SUCCESS)
5322 lpfc_printf_log(phba, KERN_ERR,
5324 "(%d):2597 Mailbox command "
5325 "x%x (x%x) cannot issue "
5328 mboxq->vport->vpi : 0,
5329 mboxq->u.mb.mbxCommand,
5330 lpfc_sli4_mbox_opcode_get(phba,
5332 psli->sli_flag, flag);
5333 /* Unblock the async mailbox posting afterward */
5334 lpfc_sli4_async_mbox_unblock(phba);
5339 /* Now, interrupt mode asynchrous mailbox command */
5340 rc = lpfc_mbox_cmd_check(phba, mboxq);
5342 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5343 "(%d):2543 Mailbox command x%x (x%x) "
5344 "cannot issue Data: x%x x%x\n",
5345 mboxq->vport ? mboxq->vport->vpi : 0,
5346 mboxq->u.mb.mbxCommand,
5347 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5348 psli->sli_flag, flag);
5349 goto out_not_finished;
5352 /* Put the mailbox command to the driver internal FIFO */
5353 psli->slistat.mbox_busy++;
5354 spin_lock_irqsave(&phba->hbalock, iflags);
5355 lpfc_mbox_put(phba, mboxq);
5356 spin_unlock_irqrestore(&phba->hbalock, iflags);
5357 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5358 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5359 "x%x (x%x) x%x x%x x%x\n",
5360 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
5361 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5362 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5363 phba->pport->port_state,
5364 psli->sli_flag, MBX_NOWAIT);
5365 /* Wake up worker thread to transport mailbox command from head */
5366 lpfc_worker_wake_up(phba);
5371 return MBX_NOT_FINISHED;
5375 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5376 * @phba: Pointer to HBA context object.
5378 * This function is called by worker thread to send a mailbox command to
5379 * SLI4 HBA firmware.
5383 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
5385 struct lpfc_sli *psli = &phba->sli;
5386 LPFC_MBOXQ_t *mboxq;
5387 int rc = MBX_SUCCESS;
5388 unsigned long iflags;
5389 struct lpfc_mqe *mqe;
5392 /* Check interrupt mode before post async mailbox command */
5393 if (unlikely(!phba->sli4_hba.intr_enable))
5394 return MBX_NOT_FINISHED;
5396 /* Check for mailbox command service token */
5397 spin_lock_irqsave(&phba->hbalock, iflags);
5398 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
5399 spin_unlock_irqrestore(&phba->hbalock, iflags);
5400 return MBX_NOT_FINISHED;
5402 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
5403 spin_unlock_irqrestore(&phba->hbalock, iflags);
5404 return MBX_NOT_FINISHED;
5406 if (unlikely(phba->sli.mbox_active)) {
5407 spin_unlock_irqrestore(&phba->hbalock, iflags);
5408 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5409 "0384 There is pending active mailbox cmd\n");
5410 return MBX_NOT_FINISHED;
5412 /* Take the mailbox command service token */
5413 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5415 /* Get the next mailbox command from head of queue */
5416 mboxq = lpfc_mbox_get(phba);
5418 /* If no more mailbox command waiting for post, we're done */
5420 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5421 spin_unlock_irqrestore(&phba->hbalock, iflags);
5424 phba->sli.mbox_active = mboxq;
5425 spin_unlock_irqrestore(&phba->hbalock, iflags);
5427 /* Check device readiness for posting mailbox command */
5428 rc = lpfc_mbox_dev_check(phba);
5430 /* Driver clean routine will clean up pending mailbox */
5431 goto out_not_finished;
5433 /* Prepare the mbox command to be posted */
5434 mqe = &mboxq->u.mqe;
5435 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
5437 /* Start timer for the mbox_tmo and log some mailbox post messages */
5438 mod_timer(&psli->mbox_tmo, (jiffies +
5439 (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
5441 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5442 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5444 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
5445 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5446 phba->pport->port_state, psli->sli_flag);
5448 if (mbx_cmnd != MBX_HEARTBEAT) {
5450 lpfc_debugfs_disc_trc(mboxq->vport,
5451 LPFC_DISC_TRC_MBOX_VPORT,
5452 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5453 mbx_cmnd, mqe->un.mb_words[0],
5454 mqe->un.mb_words[1]);
5456 lpfc_debugfs_disc_trc(phba->pport,
5458 "MBOX Send: cmd:x%x mb:x%x x%x",
5459 mbx_cmnd, mqe->un.mb_words[0],
5460 mqe->un.mb_words[1]);
5463 psli->slistat.mbox_cmd++;
5465 /* Post the mailbox command to the port */
5466 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
5467 if (rc != MBX_SUCCESS) {
5468 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5469 "(%d):2533 Mailbox command x%x (x%x) "
5470 "cannot issue Data: x%x x%x\n",
5471 mboxq->vport ? mboxq->vport->vpi : 0,
5472 mboxq->u.mb.mbxCommand,
5473 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5474 psli->sli_flag, MBX_NOWAIT);
5475 goto out_not_finished;
5481 spin_lock_irqsave(&phba->hbalock, iflags);
5482 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
5483 __lpfc_mbox_cmpl_put(phba, mboxq);
5484 /* Release the token */
5485 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5486 phba->sli.mbox_active = NULL;
5487 spin_unlock_irqrestore(&phba->hbalock, iflags);
5489 return MBX_NOT_FINISHED;
5493 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5494 * @phba: Pointer to HBA context object.
5495 * @pmbox: Pointer to mailbox object.
5496 * @flag: Flag indicating how the mailbox need to be processed.
5498 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5499 * the API jump table function pointer from the lpfc_hba struct.
5501 * Return codes the caller owns the mailbox command after the return of the
5505 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
5507 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
5511 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5512 * @phba: The hba struct for which this call is being executed.
5513 * @dev_grp: The HBA PCI-Device group number.
5515 * This routine sets up the mbox interface API function jump table in @phba
5517 * Returns: 0 - success, -ENODEV - failure.
5520 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5524 case LPFC_PCI_DEV_LP:
5525 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
5526 phba->lpfc_sli_handle_slow_ring_event =
5527 lpfc_sli_handle_slow_ring_event_s3;
5528 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
5529 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
5530 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
5532 case LPFC_PCI_DEV_OC:
5533 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
5534 phba->lpfc_sli_handle_slow_ring_event =
5535 lpfc_sli_handle_slow_ring_event_s4;
5536 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
5537 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
5538 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
5541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5542 "1420 Invalid HBA PCI-device group: 0x%x\n",
5551 * __lpfc_sli_ringtx_put - Add an iocb to the txq
5552 * @phba: Pointer to HBA context object.
5553 * @pring: Pointer to driver SLI ring object.
5554 * @piocb: Pointer to address of newly added command iocb.
5556 * This function is called with hbalock held to add a command
5557 * iocb to the txq when SLI layer cannot submit the command iocb
5561 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5562 struct lpfc_iocbq *piocb)
5564 /* Insert the caller's iocb in the txq tail for later processing. */
5565 list_add_tail(&piocb->list, &pring->txq);
5570 * lpfc_sli_next_iocb - Get the next iocb in the txq
5571 * @phba: Pointer to HBA context object.
5572 * @pring: Pointer to driver SLI ring object.
5573 * @piocb: Pointer to address of newly added command iocb.
5575 * This function is called with hbalock held before a new
5576 * iocb is submitted to the firmware. This function checks
5577 * txq to flush the iocbs in txq to Firmware before
5578 * submitting new iocbs to the Firmware.
5579 * If there are iocbs in the txq which need to be submitted
5580 * to firmware, lpfc_sli_next_iocb returns the first element
5581 * of the txq after dequeuing it from txq.
5582 * If there is no iocb in the txq then the function will return
5583 * *piocb and *piocb is set to NULL. Caller needs to check
5584 * *piocb to find if there are more commands in the txq.
5586 static struct lpfc_iocbq *
5587 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5588 struct lpfc_iocbq **piocb)
5590 struct lpfc_iocbq * nextiocb;
5592 nextiocb = lpfc_sli_ringtx_get(phba, pring);
5602 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
5603 * @phba: Pointer to HBA context object.
5604 * @ring_number: SLI ring number to issue iocb on.
5605 * @piocb: Pointer to command iocb.
5606 * @flag: Flag indicating if this command can be put into txq.
5608 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
5609 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
5610 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
5611 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
5612 * this function allows only iocbs for posting buffers. This function finds
5613 * next available slot in the command ring and posts the command to the
5614 * available slot and writes the port attention register to request HBA start
5615 * processing new iocb. If there is no slot available in the ring and
5616 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
5617 * the function returns IOCB_BUSY.
5619 * This function is called with hbalock held. The function will return success
5620 * after it successfully submit the iocb to firmware or after adding to the
5624 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
5625 struct lpfc_iocbq *piocb, uint32_t flag)
5627 struct lpfc_iocbq *nextiocb;
5629 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
5631 if (piocb->iocb_cmpl && (!piocb->vport) &&
5632 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
5633 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
5634 lpfc_printf_log(phba, KERN_ERR,
5635 LOG_SLI | LOG_VPORT,
5636 "1807 IOCB x%x failed. No vport\n",
5637 piocb->iocb.ulpCommand);
5643 /* If the PCI channel is in offline state, do not post iocbs. */
5644 if (unlikely(pci_channel_offline(phba->pcidev)))
5647 /* If HBA has a deferred error attention, fail the iocb. */
5648 if (unlikely(phba->hba_flag & DEFER_ERATT))
5652 * We should never get an IOCB if we are in a < LINK_DOWN state
5654 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5658 * Check to see if we are blocking IOCB processing because of a
5659 * outstanding event.
5661 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
5664 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
5666 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
5667 * can be issued if the link is not up.
5669 switch (piocb->iocb.ulpCommand) {
5670 case CMD_GEN_REQUEST64_CR:
5671 case CMD_GEN_REQUEST64_CX:
5672 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
5673 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
5674 FC_RCTL_DD_UNSOL_CMD) ||
5675 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
5676 MENLO_TRANSPORT_TYPE))
5680 case CMD_QUE_RING_BUF_CN:
5681 case CMD_QUE_RING_BUF64_CN:
5683 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
5684 * completion, iocb_cmpl MUST be 0.
5686 if (piocb->iocb_cmpl)
5687 piocb->iocb_cmpl = NULL;
5689 case CMD_CREATE_XRI_CR:
5690 case CMD_CLOSE_XRI_CN:
5691 case CMD_CLOSE_XRI_CX:
5698 * For FCP commands, we must be in a state where we can process link
5701 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
5702 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
5706 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
5707 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
5708 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
5711 lpfc_sli_update_ring(phba, pring);
5713 lpfc_sli_update_full_ring(phba, pring);
5716 return IOCB_SUCCESS;
5721 pring->stats.iocb_cmd_delay++;
5725 if (!(flag & SLI_IOCB_RET_IOCB)) {
5726 __lpfc_sli_ringtx_put(phba, pring, piocb);
5727 return IOCB_SUCCESS;
5734 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
5735 * @phba: Pointer to HBA context object.
5736 * @piocb: Pointer to command iocb.
5737 * @sglq: Pointer to the scatter gather queue object.
5739 * This routine converts the bpl or bde that is in the IOCB
5740 * to a sgl list for the sli4 hardware. The physical address
5741 * of the bpl/bde is converted back to a virtual address.
5742 * If the IOCB contains a BPL then the list of BDE's is
5743 * converted to sli4_sge's. If the IOCB contains a single
5744 * BDE then it is converted to a single sli_sge.
5745 * The IOCB is still in cpu endianess so the contents of
5746 * the bpl can be used without byte swapping.
5748 * Returns valid XRI = Success, NO_XRI = Failure.
5751 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
5752 struct lpfc_sglq *sglq)
5754 uint16_t xritag = NO_XRI;
5755 struct ulp_bde64 *bpl = NULL;
5756 struct ulp_bde64 bde;
5757 struct sli4_sge *sgl = NULL;
5762 if (!piocbq || !sglq)
5765 sgl = (struct sli4_sge *)sglq->sgl;
5766 icmd = &piocbq->iocb;
5767 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5768 numBdes = icmd->un.genreq64.bdl.bdeSize /
5769 sizeof(struct ulp_bde64);
5770 /* The addrHigh and addrLow fields within the IOCB
5771 * have not been byteswapped yet so there is no
5772 * need to swap them back.
5774 bpl = (struct ulp_bde64 *)
5775 ((struct lpfc_dmabuf *)piocbq->context3)->virt;
5780 for (i = 0; i < numBdes; i++) {
5781 /* Should already be byte swapped. */
5782 sgl->addr_hi = bpl->addrHigh;
5783 sgl->addr_lo = bpl->addrLow;
5785 if ((i+1) == numBdes)
5786 bf_set(lpfc_sli4_sge_last, sgl, 1);
5788 bf_set(lpfc_sli4_sge_last, sgl, 0);
5789 sgl->word2 = cpu_to_le32(sgl->word2);
5790 /* swap the size field back to the cpu so we
5791 * can assign it to the sgl.
5793 bde.tus.w = le32_to_cpu(bpl->tus.w);
5794 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
5798 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
5799 /* The addrHigh and addrLow fields of the BDE have not
5800 * been byteswapped yet so they need to be swapped
5801 * before putting them in the sgl.
5804 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
5806 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
5807 bf_set(lpfc_sli4_sge_last, sgl, 1);
5808 sgl->word2 = cpu_to_le32(sgl->word2);
5810 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
5812 return sglq->sli4_xritag;
5816 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5817 * @phba: Pointer to HBA context object.
5819 * This routine performs a round robin SCSI command to SLI4 FCP WQ index
5820 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
5823 * Return: index into SLI4 fast-path FCP queue index.
5826 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
5829 if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
5832 return phba->fcp_qidx;
5836 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
5837 * @phba: Pointer to HBA context object.
5838 * @piocb: Pointer to command iocb.
5839 * @wqe: Pointer to the work queue entry.
5841 * This routine converts the iocb command to its Work Queue Entry
5842 * equivalent. The wqe pointer should not have any fields set when
5843 * this routine is called because it will memcpy over them.
5844 * This routine does not set the CQ_ID or the WQEC bits in the
5847 * Returns: 0 = Success, IOCB_ERROR = Failure.
5850 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
5851 union lpfc_wqe *wqe)
5853 uint32_t xmit_len = 0, total_len = 0;
5857 uint8_t command_type = ELS_COMMAND_NON_FIP;
5860 struct ulp_bde64 *bpl = NULL;
5861 uint32_t els_id = ELS_ID_DEFAULT;
5863 struct ulp_bde64 bde;
5865 fip = phba->hba_flag & HBA_FIP_SUPPORT;
5866 /* The fcp commands will set command type */
5867 if (iocbq->iocb_flag & LPFC_IO_FCP)
5868 command_type = FCP_COMMAND;
5869 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
5870 command_type = ELS_COMMAND_FIP;
5872 command_type = ELS_COMMAND_NON_FIP;
5874 /* Some of the fields are in the right position already */
5875 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
5876 abort_tag = (uint32_t) iocbq->iotag;
5877 xritag = iocbq->sli4_xritag;
5878 wqe->words[7] = 0; /* The ct field has moved so reset */
5879 /* words0-2 bpl convert bde */
5880 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5881 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
5882 sizeof(struct ulp_bde64);
5883 bpl = (struct ulp_bde64 *)
5884 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
5888 /* Should already be byte swapped. */
5889 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
5890 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
5891 /* swap the size field back to the cpu so we
5892 * can assign it to the sgl.
5894 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
5895 xmit_len = wqe->generic.bde.tus.f.bdeSize;
5897 for (i = 0; i < numBdes; i++) {
5898 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
5899 total_len += bde.tus.f.bdeSize;
5902 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
5904 iocbq->iocb.ulpIoTag = iocbq->iotag;
5905 cmnd = iocbq->iocb.ulpCommand;
5907 switch (iocbq->iocb.ulpCommand) {
5908 case CMD_ELS_REQUEST64_CR:
5909 if (!iocbq->iocb.ulpLe) {
5910 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5911 "2007 Only Limited Edition cmd Format"
5912 " supported 0x%x\n",
5913 iocbq->iocb.ulpCommand);
5916 wqe->els_req.payload_len = xmit_len;
5917 /* Els_reguest64 has a TMO */
5918 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
5919 iocbq->iocb.ulpTimeout);
5920 /* Need a VF for word 4 set the vf bit*/
5921 bf_set(els_req64_vf, &wqe->els_req, 0);
5922 /* And a VFID for word 12 */
5923 bf_set(els_req64_vfid, &wqe->els_req, 0);
5925 * Set ct field to 3, indicates that the context_tag field
5926 * contains the FCFI and remote N_Port_ID is
5930 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
5931 bf_set(lpfc_wqe_gen_context, &wqe->generic,
5932 iocbq->iocb.ulpContext);
5934 bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
5935 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
5936 /* CCP CCPE PV PRI in word10 were set in the memcpy */
5938 if (command_type == ELS_COMMAND_FIP) {
5939 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
5940 >> LPFC_FIP_ELS_ID_SHIFT);
5942 bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
5945 case CMD_XMIT_SEQUENCE64_CX:
5946 bf_set(lpfc_wqe_gen_context, &wqe->generic,
5947 iocbq->iocb.un.ulpWord[3]);
5948 wqe->generic.word3 = 0;
5949 bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
5950 /* The entire sequence is transmitted for this IOCB */
5951 xmit_len = total_len;
5952 cmnd = CMD_XMIT_SEQUENCE64_CR;
5953 case CMD_XMIT_SEQUENCE64_CR:
5954 /* word3 iocb=io_tag32 wqe=payload_offset */
5955 /* payload offset used for multilpe outstanding
5956 * sequences on the same exchange
5959 /* word4 relative_offset memcpy */
5960 /* word5 r_ctl/df_ctl memcpy */
5961 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
5962 wqe->xmit_sequence.xmit_len = xmit_len;
5963 command_type = OTHER_COMMAND;
5965 case CMD_XMIT_BCAST64_CN:
5966 /* word3 iocb=iotag32 wqe=payload_len */
5967 wqe->words[3] = 0; /* no definition for this in wqe */
5968 /* word4 iocb=rsvd wqe=rsvd */
5969 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
5970 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
5971 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
5972 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
5974 case CMD_FCP_IWRITE64_CR:
5975 command_type = FCP_COMMAND_DATA_OUT;
5976 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
5978 * word3 is payload_len: byte offset to the sgl entry for the
5980 * word4 is total xfer len, same as the IOCB->ulpParameter.
5981 * word5 is initial xfer len 0 = wait for xfer-ready
5984 /* Always wait for xfer-ready before sending data */
5985 wqe->fcp_iwrite.initial_xfer_len = 0;
5986 /* word 4 (xfer length) should have been set on the memcpy */
5988 /* allow write to fall through to read */
5989 case CMD_FCP_IREAD64_CR:
5990 /* FCP_CMD is always the 1st sgl entry */
5991 wqe->fcp_iread.payload_len =
5992 xmit_len + sizeof(struct fcp_rsp);
5994 /* word 4 (xfer length) should have been set on the memcpy */
5996 bf_set(lpfc_wqe_gen_erp, &wqe->generic,
5997 iocbq->iocb.ulpFCP2Rcvy);
5998 bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
5999 /* The XC bit and the XS bit are similar. The driver never
6000 * tracked whether or not the exchange was previouslly open.
6001 * XC = Exchange create, 0 is create. 1 is already open.
6002 * XS = link cmd: 1 do not close the exchange after command.
6003 * XS = 0 close exchange when command completes.
6004 * The only time we would not set the XC bit is when the XS bit
6005 * is set and we are sending our 2nd or greater command on
6008 /* Always open the exchange */
6009 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
6011 wqe->words[10] &= 0xffff0000; /* zero out ebde count */
6012 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
6014 case CMD_FCP_ICMND64_CR:
6015 /* Always open the exchange */
6016 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
6019 wqe->words[10] &= 0xffff0000; /* zero out ebde count */
6020 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
6022 case CMD_GEN_REQUEST64_CR:
6023 /* word3 command length is described as byte offset to the
6024 * rsp_data. Would always be 16, sizeof(struct sli4_sge)
6029 wqe->gen_req.command_len = xmit_len;
6030 /* Word4 parameter copied in the memcpy */
6031 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
6032 /* word6 context tag copied in memcpy */
6033 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
6034 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
6035 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6036 "2015 Invalid CT %x command 0x%x\n",
6037 ct, iocbq->iocb.ulpCommand);
6040 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
6041 bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
6042 iocbq->iocb.ulpTimeout);
6044 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
6045 command_type = OTHER_COMMAND;
6047 case CMD_XMIT_ELS_RSP64_CX:
6048 /* words0-2 BDE memcpy */
6049 /* word3 iocb=iotag32 wqe=rsvd */
6051 /* word4 iocb=did wge=rsvd. */
6053 /* word5 iocb=rsvd wge=did */
6054 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
6055 iocbq->iocb.un.elsreq64.remoteID);
6057 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
6058 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6060 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
6061 bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
6062 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
6063 bf_set(lpfc_wqe_gen_context, &wqe->generic,
6064 iocbq->vport->vpi + phba->vpi_base);
6065 command_type = OTHER_COMMAND;
6067 case CMD_CLOSE_XRI_CN:
6068 case CMD_ABORT_XRI_CN:
6069 case CMD_ABORT_XRI_CX:
6070 /* words 0-2 memcpy should be 0 rserved */
6071 /* port will send abts */
6072 if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6074 * The link is down so the fw does not need to send abts
6077 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
6079 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
6080 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
6082 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
6083 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6084 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
6086 * The abort handler will send us CMD_ABORT_XRI_CN or
6087 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6089 bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
6090 cmnd = CMD_ABORT_XRI_CX;
6091 command_type = OTHER_COMMAND;
6094 case CMD_XMIT_BLS_RSP64_CX:
6095 /* As BLS ABTS-ACC WQE is very different from other WQEs,
6096 * we re-construct this WQE here based on information in
6097 * iocbq from scratch.
6099 memset(wqe, 0, sizeof(union lpfc_wqe));
6100 /* OX_ID is invariable to who sent ABTS to CT exchange */
6101 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
6102 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
6103 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
6104 LPFC_ABTS_UNSOL_INT) {
6105 /* ABTS sent by initiator to CT exchange, the
6106 * RX_ID field will be filled with the newly
6107 * allocated responder XRI.
6109 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
6110 iocbq->sli4_xritag);
6112 /* ABTS sent by responder to CT exchange, the
6113 * RX_ID field will be filled with the responder
6116 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
6117 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
6119 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
6120 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
6121 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
6122 iocbq->iocb.ulpContext);
6123 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
6124 command_type = OTHER_COMMAND;
6126 case CMD_XRI_ABORTED_CX:
6127 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
6128 /* words0-2 are all 0's no bde */
6129 /* word3 and word4 are rsvrd */
6132 /* word5 iocb=rsvd wge=did */
6133 /* There is no remote port id in the IOCB? */
6134 /* Let this fall through and fail */
6135 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
6136 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
6137 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
6138 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
6140 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6141 "2014 Invalid command 0x%x\n",
6142 iocbq->iocb.ulpCommand);
6147 bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
6148 bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
6149 wqe->generic.abort_tag = abort_tag;
6150 bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
6151 bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
6152 bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
6153 bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
6159 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
6160 * @phba: Pointer to HBA context object.
6161 * @ring_number: SLI ring number to issue iocb on.
6162 * @piocb: Pointer to command iocb.
6163 * @flag: Flag indicating if this command can be put into txq.
6165 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
6166 * an iocb command to an HBA with SLI-4 interface spec.
6168 * This function is called with hbalock held. The function will return success
6169 * after it successfully submit the iocb to firmware or after adding to the
6173 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
6174 struct lpfc_iocbq *piocb, uint32_t flag)
6176 struct lpfc_sglq *sglq;
6179 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
6181 if (piocb->sli4_xritag == NO_XRI) {
6182 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6183 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6186 sglq = __lpfc_sli_get_sglq(phba);
6189 piocb->sli4_xritag = sglq->sli4_xritag;
6191 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
6192 sglq = NULL; /* These IO's already have an XRI and
6196 /* This is a continuation of a commandi,(CX) so this
6197 * sglq is on the active list
6199 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
6205 xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
6206 if (xritag != sglq->sli4_xritag)
6210 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
6213 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
6214 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
6216 * For FCP command IOCB, get a new WQ index to distribute
6217 * WQE across the WQsr. On the other hand, for abort IOCB,
6218 * it carries the same WQ index to the original command
6221 if (piocb->iocb_flag & LPFC_IO_FCP)
6222 piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
6223 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
6227 if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
6230 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
6236 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6238 * This routine wraps the actual lockless version for issusing IOCB function
6239 * pointer from the lpfc_hba struct.
6242 * IOCB_ERROR - Error
6243 * IOCB_SUCCESS - Success
6247 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
6248 struct lpfc_iocbq *piocb, uint32_t flag)
6250 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
6254 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6255 * @phba: The hba struct for which this call is being executed.
6256 * @dev_grp: The HBA PCI-Device group number.
6258 * This routine sets up the SLI interface API function jump table in @phba
6260 * Returns: 0 - success, -ENODEV - failure.
6263 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6267 case LPFC_PCI_DEV_LP:
6268 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
6269 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
6271 case LPFC_PCI_DEV_OC:
6272 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
6273 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
6276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6277 "1419 Invalid HBA PCI-device group: 0x%x\n",
6282 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
6287 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6288 * @phba: Pointer to HBA context object.
6289 * @pring: Pointer to driver SLI ring object.
6290 * @piocb: Pointer to command iocb.
6291 * @flag: Flag indicating if this command can be put into txq.
6293 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6294 * function. This function gets the hbalock and calls
6295 * __lpfc_sli_issue_iocb function and will return the error returned
6296 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6297 * functions which do not hold hbalock.
6300 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
6301 struct lpfc_iocbq *piocb, uint32_t flag)
6303 unsigned long iflags;
6306 spin_lock_irqsave(&phba->hbalock, iflags);
6307 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
6308 spin_unlock_irqrestore(&phba->hbalock, iflags);
6314 * lpfc_extra_ring_setup - Extra ring setup function
6315 * @phba: Pointer to HBA context object.
6317 * This function is called while driver attaches with the
6318 * HBA to setup the extra ring. The extra ring is used
6319 * only when driver needs to support target mode functionality
6320 * or IP over FC functionalities.
6322 * This function is called with no lock held.
6325 lpfc_extra_ring_setup( struct lpfc_hba *phba)
6327 struct lpfc_sli *psli;
6328 struct lpfc_sli_ring *pring;
6332 /* Adjust cmd/rsp ring iocb entries more evenly */
6334 /* Take some away from the FCP ring */
6335 pring = &psli->ring[psli->fcp_ring];
6336 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6337 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6338 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6339 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6341 /* and give them to the extra ring */
6342 pring = &psli->ring[psli->extra_ring];
6344 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6345 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6346 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6347 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6349 /* Setup default profile for this ring */
6350 pring->iotag_max = 4096;
6351 pring->num_mask = 1;
6352 pring->prt[0].profile = 0; /* Mask 0 */
6353 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
6354 pring->prt[0].type = phba->cfg_multi_ring_type;
6355 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
6360 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6361 * @phba: Pointer to HBA context object.
6362 * @pring: Pointer to driver SLI ring object.
6363 * @iocbq: Pointer to iocb object.
6365 * This function is called by the slow ring event handler
6366 * function when there is an ASYNC event iocb in the ring.
6367 * This function is called with no lock held.
6368 * Currently this function handles only temperature related
6369 * ASYNC events. The function decodes the temperature sensor
6370 * event message and posts events for the management applications.
6373 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
6374 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
6379 struct temp_event temp_event_data;
6380 struct Scsi_Host *shost;
6383 icmd = &iocbq->iocb;
6384 evt_code = icmd->un.asyncstat.evt_code;
6385 temp = icmd->ulpContext;
6387 if ((evt_code != ASYNC_TEMP_WARN) &&
6388 (evt_code != ASYNC_TEMP_SAFE)) {
6389 iocb_w = (uint32_t *) icmd;
6390 lpfc_printf_log(phba,
6393 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6395 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6396 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6397 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6398 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6400 icmd->un.asyncstat.evt_code,
6401 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
6402 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
6403 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
6404 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
6408 temp_event_data.data = (uint32_t)temp;
6409 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6410 if (evt_code == ASYNC_TEMP_WARN) {
6411 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6412 lpfc_printf_log(phba,
6415 "0347 Adapter is very hot, please take "
6416 "corrective action. temperature : %d Celsius\n",
6419 if (evt_code == ASYNC_TEMP_SAFE) {
6420 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6421 lpfc_printf_log(phba,
6424 "0340 Adapter temperature is OK now. "
6425 "temperature : %d Celsius\n",
6429 /* Send temperature change event to applications */
6430 shost = lpfc_shost_from_vport(phba->pport);
6431 fc_host_post_vendor_event(shost, fc_get_event_number(),
6432 sizeof(temp_event_data), (char *) &temp_event_data,
6439 * lpfc_sli_setup - SLI ring setup function
6440 * @phba: Pointer to HBA context object.
6442 * lpfc_sli_setup sets up rings of the SLI interface with
6443 * number of iocbs per ring and iotags. This function is
6444 * called while driver attach to the HBA and before the
6445 * interrupts are enabled. So there is no need for locking.
6447 * This function always returns 0.
6450 lpfc_sli_setup(struct lpfc_hba *phba)
6452 int i, totiocbsize = 0;
6453 struct lpfc_sli *psli = &phba->sli;
6454 struct lpfc_sli_ring *pring;
6456 psli->num_rings = MAX_CONFIGURED_RINGS;
6458 psli->fcp_ring = LPFC_FCP_RING;
6459 psli->next_ring = LPFC_FCP_NEXT_RING;
6460 psli->extra_ring = LPFC_EXTRA_RING;
6462 psli->iocbq_lookup = NULL;
6463 psli->iocbq_lookup_len = 0;
6464 psli->last_iotag = 0;
6466 for (i = 0; i < psli->num_rings; i++) {
6467 pring = &psli->ring[i];
6469 case LPFC_FCP_RING: /* ring 0 - FCP */
6470 /* numCiocb and numRiocb are used in config_port */
6471 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
6472 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
6473 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6474 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6475 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6476 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6477 pring->sizeCiocb = (phba->sli_rev == 3) ?
6478 SLI3_IOCB_CMD_SIZE :
6480 pring->sizeRiocb = (phba->sli_rev == 3) ?
6481 SLI3_IOCB_RSP_SIZE :
6483 pring->iotag_ctr = 0;
6485 (phba->cfg_hba_queue_depth * 2);
6486 pring->fast_iotag = pring->iotag_max;
6487 pring->num_mask = 0;
6489 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
6490 /* numCiocb and numRiocb are used in config_port */
6491 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
6492 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
6493 pring->sizeCiocb = (phba->sli_rev == 3) ?
6494 SLI3_IOCB_CMD_SIZE :
6496 pring->sizeRiocb = (phba->sli_rev == 3) ?
6497 SLI3_IOCB_RSP_SIZE :
6499 pring->iotag_max = phba->cfg_hba_queue_depth;
6500 pring->num_mask = 0;
6502 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
6503 /* numCiocb and numRiocb are used in config_port */
6504 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
6505 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
6506 pring->sizeCiocb = (phba->sli_rev == 3) ?
6507 SLI3_IOCB_CMD_SIZE :
6509 pring->sizeRiocb = (phba->sli_rev == 3) ?
6510 SLI3_IOCB_RSP_SIZE :
6512 pring->fast_iotag = 0;
6513 pring->iotag_ctr = 0;
6514 pring->iotag_max = 4096;
6515 pring->lpfc_sli_rcv_async_status =
6516 lpfc_sli_async_event_handler;
6517 pring->num_mask = LPFC_MAX_RING_MASK;
6518 pring->prt[0].profile = 0; /* Mask 0 */
6519 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
6520 pring->prt[0].type = FC_TYPE_ELS;
6521 pring->prt[0].lpfc_sli_rcv_unsol_event =
6522 lpfc_els_unsol_event;
6523 pring->prt[1].profile = 0; /* Mask 1 */
6524 pring->prt[1].rctl = FC_RCTL_ELS_REP;
6525 pring->prt[1].type = FC_TYPE_ELS;
6526 pring->prt[1].lpfc_sli_rcv_unsol_event =
6527 lpfc_els_unsol_event;
6528 pring->prt[2].profile = 0; /* Mask 2 */
6529 /* NameServer Inquiry */
6530 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
6532 pring->prt[2].type = FC_TYPE_CT;
6533 pring->prt[2].lpfc_sli_rcv_unsol_event =
6534 lpfc_ct_unsol_event;
6535 pring->prt[3].profile = 0; /* Mask 3 */
6536 /* NameServer response */
6537 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
6539 pring->prt[3].type = FC_TYPE_CT;
6540 pring->prt[3].lpfc_sli_rcv_unsol_event =
6541 lpfc_ct_unsol_event;
6542 /* abort unsolicited sequence */
6543 pring->prt[4].profile = 0; /* Mask 4 */
6544 pring->prt[4].rctl = FC_RCTL_BA_ABTS;
6545 pring->prt[4].type = FC_TYPE_BLS;
6546 pring->prt[4].lpfc_sli_rcv_unsol_event =
6547 lpfc_sli4_ct_abort_unsol_event;
6550 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
6551 (pring->numRiocb * pring->sizeRiocb);
6553 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
6554 /* Too many cmd / rsp ring entries in SLI2 SLIM */
6555 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
6556 "SLI2 SLIM Data: x%x x%lx\n",
6557 phba->brd_no, totiocbsize,
6558 (unsigned long) MAX_SLIM_IOCB_SIZE);
6560 if (phba->cfg_multi_ring_support == 2)
6561 lpfc_extra_ring_setup(phba);
6567 * lpfc_sli_queue_setup - Queue initialization function
6568 * @phba: Pointer to HBA context object.
6570 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
6571 * ring. This function also initializes ring indices of each ring.
6572 * This function is called during the initialization of the SLI
6573 * interface of an HBA.
6574 * This function is called with no lock held and always returns
6578 lpfc_sli_queue_setup(struct lpfc_hba *phba)
6580 struct lpfc_sli *psli;
6581 struct lpfc_sli_ring *pring;
6585 spin_lock_irq(&phba->hbalock);
6586 INIT_LIST_HEAD(&psli->mboxq);
6587 INIT_LIST_HEAD(&psli->mboxq_cmpl);
6588 /* Initialize list headers for txq and txcmplq as double linked lists */
6589 for (i = 0; i < psli->num_rings; i++) {
6590 pring = &psli->ring[i];
6592 pring->next_cmdidx = 0;
6593 pring->local_getidx = 0;
6595 INIT_LIST_HEAD(&pring->txq);
6596 INIT_LIST_HEAD(&pring->txcmplq);
6597 INIT_LIST_HEAD(&pring->iocb_continueq);
6598 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
6599 INIT_LIST_HEAD(&pring->postbufq);
6601 spin_unlock_irq(&phba->hbalock);
6606 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
6607 * @phba: Pointer to HBA context object.
6609 * This routine flushes the mailbox command subsystem. It will unconditionally
6610 * flush all the mailbox commands in the three possible stages in the mailbox
6611 * command sub-system: pending mailbox command queue; the outstanding mailbox
6612 * command; and completed mailbox command queue. It is caller's responsibility
6613 * to make sure that the driver is in the proper state to flush the mailbox
6614 * command sub-system. Namely, the posting of mailbox commands into the
6615 * pending mailbox command queue from the various clients must be stopped;
6616 * either the HBA is in a state that it will never works on the outstanding
6617 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
6618 * mailbox command has been completed.
6621 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
6623 LIST_HEAD(completions);
6624 struct lpfc_sli *psli = &phba->sli;
6626 unsigned long iflag;
6628 /* Flush all the mailbox commands in the mbox system */
6629 spin_lock_irqsave(&phba->hbalock, iflag);
6630 /* The pending mailbox command queue */
6631 list_splice_init(&phba->sli.mboxq, &completions);
6632 /* The outstanding active mailbox command */
6633 if (psli->mbox_active) {
6634 list_add_tail(&psli->mbox_active->list, &completions);
6635 psli->mbox_active = NULL;
6636 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6638 /* The completed mailbox command queue */
6639 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
6640 spin_unlock_irqrestore(&phba->hbalock, iflag);
6642 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
6643 while (!list_empty(&completions)) {
6644 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
6645 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
6647 pmb->mbox_cmpl(phba, pmb);
6652 * lpfc_sli_host_down - Vport cleanup function
6653 * @vport: Pointer to virtual port object.
6655 * lpfc_sli_host_down is called to clean up the resources
6656 * associated with a vport before destroying virtual
6657 * port data structures.
6658 * This function does following operations:
6659 * - Free discovery resources associated with this virtual
6661 * - Free iocbs associated with this virtual port in
6663 * - Send abort for all iocb commands associated with this
6666 * This function is called with no lock held and always returns 1.
6669 lpfc_sli_host_down(struct lpfc_vport *vport)
6671 LIST_HEAD(completions);
6672 struct lpfc_hba *phba = vport->phba;
6673 struct lpfc_sli *psli = &phba->sli;
6674 struct lpfc_sli_ring *pring;
6675 struct lpfc_iocbq *iocb, *next_iocb;
6677 unsigned long flags = 0;
6678 uint16_t prev_pring_flag;
6680 lpfc_cleanup_discovery_resources(vport);
6682 spin_lock_irqsave(&phba->hbalock, flags);
6683 for (i = 0; i < psli->num_rings; i++) {
6684 pring = &psli->ring[i];
6685 prev_pring_flag = pring->flag;
6686 /* Only slow rings */
6687 if (pring->ringno == LPFC_ELS_RING) {
6688 pring->flag |= LPFC_DEFERRED_RING_EVENT;
6689 /* Set the lpfc data pending flag */
6690 set_bit(LPFC_DATA_READY, &phba->data_flags);
6693 * Error everything on the txq since these iocbs have not been
6694 * given to the FW yet.
6696 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6697 if (iocb->vport != vport)
6699 list_move_tail(&iocb->list, &completions);
6703 /* Next issue ABTS for everything on the txcmplq */
6704 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
6706 if (iocb->vport != vport)
6708 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
6711 pring->flag = prev_pring_flag;
6714 spin_unlock_irqrestore(&phba->hbalock, flags);
6716 /* Cancel all the IOCBs from the completions list */
6717 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6723 * lpfc_sli_hba_down - Resource cleanup function for the HBA
6724 * @phba: Pointer to HBA context object.
6726 * This function cleans up all iocb, buffers, mailbox commands
6727 * while shutting down the HBA. This function is called with no
6728 * lock held and always returns 1.
6729 * This function does the following to cleanup driver resources:
6730 * - Free discovery resources for each virtual port
6731 * - Cleanup any pending fabric iocbs
6732 * - Iterate through the iocb txq and free each entry
6734 * - Free up any buffer posted to the HBA
6735 * - Free mailbox commands in the mailbox queue.
6738 lpfc_sli_hba_down(struct lpfc_hba *phba)
6740 LIST_HEAD(completions);
6741 struct lpfc_sli *psli = &phba->sli;
6742 struct lpfc_sli_ring *pring;
6743 struct lpfc_dmabuf *buf_ptr;
6744 unsigned long flags = 0;
6747 /* Shutdown the mailbox command sub-system */
6748 lpfc_sli_mbox_sys_shutdown(phba);
6750 lpfc_hba_down_prep(phba);
6752 lpfc_fabric_abort_hba(phba);
6754 spin_lock_irqsave(&phba->hbalock, flags);
6755 for (i = 0; i < psli->num_rings; i++) {
6756 pring = &psli->ring[i];
6757 /* Only slow rings */
6758 if (pring->ringno == LPFC_ELS_RING) {
6759 pring->flag |= LPFC_DEFERRED_RING_EVENT;
6760 /* Set the lpfc data pending flag */
6761 set_bit(LPFC_DATA_READY, &phba->data_flags);
6765 * Error everything on the txq since these iocbs have not been
6766 * given to the FW yet.
6768 list_splice_init(&pring->txq, &completions);
6772 spin_unlock_irqrestore(&phba->hbalock, flags);
6774 /* Cancel all the IOCBs from the completions list */
6775 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6778 spin_lock_irqsave(&phba->hbalock, flags);
6779 list_splice_init(&phba->elsbuf, &completions);
6780 phba->elsbuf_cnt = 0;
6781 phba->elsbuf_prev_cnt = 0;
6782 spin_unlock_irqrestore(&phba->hbalock, flags);
6784 while (!list_empty(&completions)) {
6785 list_remove_head(&completions, buf_ptr,
6786 struct lpfc_dmabuf, list);
6787 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
6791 /* Return any active mbox cmds */
6792 del_timer_sync(&psli->mbox_tmo);
6794 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
6795 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
6796 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
6802 * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
6803 * @phba: Pointer to HBA context object.
6805 * This function cleans up all queues, iocb, buffers, mailbox commands while
6806 * shutting down the SLI4 HBA FCoE function. This function is called with no
6807 * lock held and always returns 1.
6809 * This function does the following to cleanup driver FCoE function resources:
6810 * - Free discovery resources for each virtual port
6811 * - Cleanup any pending fabric iocbs
6812 * - Iterate through the iocb txq and free each entry in the list.
6813 * - Free up any buffer posted to the HBA.
6814 * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
6815 * - Free mailbox commands in the mailbox queue.
6818 lpfc_sli4_hba_down(struct lpfc_hba *phba)
6820 /* Stop the SLI4 device port */
6821 lpfc_stop_port(phba);
6823 /* Tear down the queues in the HBA */
6824 lpfc_sli4_queue_unset(phba);
6826 /* unregister default FCFI from the HBA */
6827 lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
6833 * lpfc_sli_pcimem_bcopy - SLI memory copy function
6834 * @srcp: Source memory pointer.
6835 * @destp: Destination memory pointer.
6836 * @cnt: Number of words required to be copied.
6838 * This function is used for copying data between driver memory
6839 * and the SLI memory. This function also changes the endianness
6840 * of each word if native endianness is different from SLI
6841 * endianness. This function can be called with or without
6845 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
6847 uint32_t *src = srcp;
6848 uint32_t *dest = destp;
6852 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
6854 ldata = le32_to_cpu(ldata);
6863 * lpfc_sli_bemem_bcopy - SLI memory copy function
6864 * @srcp: Source memory pointer.
6865 * @destp: Destination memory pointer.
6866 * @cnt: Number of words required to be copied.
6868 * This function is used for copying data between a data structure
6869 * with big endian representation to local endianness.
6870 * This function can be called with or without lock.
6873 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
6875 uint32_t *src = srcp;
6876 uint32_t *dest = destp;
6880 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
6882 ldata = be32_to_cpu(ldata);
6890 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
6891 * @phba: Pointer to HBA context object.
6892 * @pring: Pointer to driver SLI ring object.
6893 * @mp: Pointer to driver buffer object.
6895 * This function is called with no lock held.
6896 * It always return zero after adding the buffer to the postbufq
6900 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6901 struct lpfc_dmabuf *mp)
6903 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
6905 spin_lock_irq(&phba->hbalock);
6906 list_add_tail(&mp->list, &pring->postbufq);
6907 pring->postbufq_cnt++;
6908 spin_unlock_irq(&phba->hbalock);
6913 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
6914 * @phba: Pointer to HBA context object.
6916 * When HBQ is enabled, buffers are searched based on tags. This function
6917 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
6918 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
6919 * does not conflict with tags of buffer posted for unsolicited events.
6920 * The function returns the allocated tag. The function is called with
6924 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
6926 spin_lock_irq(&phba->hbalock);
6927 phba->buffer_tag_count++;
6929 * Always set the QUE_BUFTAG_BIT to distiguish between
6930 * a tag assigned by HBQ.
6932 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
6933 spin_unlock_irq(&phba->hbalock);
6934 return phba->buffer_tag_count;
6938 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
6939 * @phba: Pointer to HBA context object.
6940 * @pring: Pointer to driver SLI ring object.
6943 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
6944 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
6945 * iocb is posted to the response ring with the tag of the buffer.
6946 * This function searches the pring->postbufq list using the tag
6947 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
6948 * iocb. If the buffer is found then lpfc_dmabuf object of the
6949 * buffer is returned to the caller else NULL is returned.
6950 * This function is called with no lock held.
6952 struct lpfc_dmabuf *
6953 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6956 struct lpfc_dmabuf *mp, *next_mp;
6957 struct list_head *slp = &pring->postbufq;
6959 /* Search postbufq, from the begining, looking for a match on tag */
6960 spin_lock_irq(&phba->hbalock);
6961 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
6962 if (mp->buffer_tag == tag) {
6963 list_del_init(&mp->list);
6964 pring->postbufq_cnt--;
6965 spin_unlock_irq(&phba->hbalock);
6970 spin_unlock_irq(&phba->hbalock);
6971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6972 "0402 Cannot find virtual addr for buffer tag on "
6973 "ring %d Data x%lx x%p x%p x%x\n",
6974 pring->ringno, (unsigned long) tag,
6975 slp->next, slp->prev, pring->postbufq_cnt);
6981 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
6982 * @phba: Pointer to HBA context object.
6983 * @pring: Pointer to driver SLI ring object.
6984 * @phys: DMA address of the buffer.
6986 * This function searches the buffer list using the dma_address
6987 * of unsolicited event to find the driver's lpfc_dmabuf object
6988 * corresponding to the dma_address. The function returns the
6989 * lpfc_dmabuf object if a buffer is found else it returns NULL.
6990 * This function is called by the ct and els unsolicited event
6991 * handlers to get the buffer associated with the unsolicited
6994 * This function is called with no lock held.
6996 struct lpfc_dmabuf *
6997 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7000 struct lpfc_dmabuf *mp, *next_mp;
7001 struct list_head *slp = &pring->postbufq;
7003 /* Search postbufq, from the begining, looking for a match on phys */
7004 spin_lock_irq(&phba->hbalock);
7005 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
7006 if (mp->phys == phys) {
7007 list_del_init(&mp->list);
7008 pring->postbufq_cnt--;
7009 spin_unlock_irq(&phba->hbalock);
7014 spin_unlock_irq(&phba->hbalock);
7015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7016 "0410 Cannot find virtual addr for mapped buf on "
7017 "ring %d Data x%llx x%p x%p x%x\n",
7018 pring->ringno, (unsigned long long)phys,
7019 slp->next, slp->prev, pring->postbufq_cnt);
7024 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
7025 * @phba: Pointer to HBA context object.
7026 * @cmdiocb: Pointer to driver command iocb object.
7027 * @rspiocb: Pointer to driver response iocb object.
7029 * This function is the completion handler for the abort iocbs for
7030 * ELS commands. This function is called from the ELS ring event
7031 * handler with no lock held. This function frees memory resources
7032 * associated with the abort iocb.
7035 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7036 struct lpfc_iocbq *rspiocb)
7038 IOCB_t *irsp = &rspiocb->iocb;
7039 uint16_t abort_iotag, abort_context;
7040 struct lpfc_iocbq *abort_iocb;
7041 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7045 if (irsp->ulpStatus) {
7046 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
7047 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
7049 spin_lock_irq(&phba->hbalock);
7050 if (phba->sli_rev < LPFC_SLI_REV4) {
7051 if (abort_iotag != 0 &&
7052 abort_iotag <= phba->sli.last_iotag)
7054 phba->sli.iocbq_lookup[abort_iotag];
7056 /* For sli4 the abort_tag is the XRI,
7057 * so the abort routine puts the iotag of the iocb
7058 * being aborted in the context field of the abort
7061 abort_iocb = phba->sli.iocbq_lookup[abort_context];
7063 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
7064 "0327 Cannot abort els iocb %p "
7065 "with tag %x context %x, abort status %x, "
7067 abort_iocb, abort_iotag, abort_context,
7068 irsp->ulpStatus, irsp->un.ulpWord[4]);
7071 * If the iocb is not found in Firmware queue the iocb
7072 * might have completed already. Do not free it again.
7074 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
7075 if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
7076 spin_unlock_irq(&phba->hbalock);
7077 lpfc_sli_release_iocbq(phba, cmdiocb);
7080 /* For SLI4 the ulpContext field for abort IOCB
7081 * holds the iotag of the IOCB being aborted so
7082 * the local abort_context needs to be reset to
7083 * match the aborted IOCBs ulpContext.
7085 if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
7086 abort_context = abort_iocb->iocb.ulpContext;
7089 * make sure we have the right iocbq before taking it
7090 * off the txcmplq and try to call completion routine.
7093 abort_iocb->iocb.ulpContext != abort_context ||
7094 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
7095 spin_unlock_irq(&phba->hbalock);
7096 else if (phba->sli_rev < LPFC_SLI_REV4) {
7098 * leave the SLI4 aborted command on the txcmplq
7099 * list and the command complete WCQE's XB bit
7100 * will tell whether the SGL (XRI) can be released
7101 * immediately or to the aborted SGL list for the
7102 * following abort XRI from the HBA.
7104 list_del_init(&abort_iocb->list);
7105 pring->txcmplq_cnt--;
7106 spin_unlock_irq(&phba->hbalock);
7108 /* Firmware could still be in progress of DMAing
7109 * payload, so don't free data buffer till after
7112 spin_lock_irq(&phba->hbalock);
7113 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
7114 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
7115 spin_unlock_irq(&phba->hbalock);
7117 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
7118 abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
7119 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
7123 lpfc_sli_release_iocbq(phba, cmdiocb);
7128 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
7129 * @phba: Pointer to HBA context object.
7130 * @cmdiocb: Pointer to driver command iocb object.
7131 * @rspiocb: Pointer to driver response iocb object.
7133 * The function is called from SLI ring event handler with no
7134 * lock held. This function is the completion handler for ELS commands
7135 * which are aborted. The function frees memory resources used for
7136 * the aborted ELS commands.
7139 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7140 struct lpfc_iocbq *rspiocb)
7142 IOCB_t *irsp = &rspiocb->iocb;
7144 /* ELS cmd tag <ulpIoTag> completes */
7145 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
7146 "0139 Ignoring ELS cmd tag x%x completion Data: "
7148 irsp->ulpIoTag, irsp->ulpStatus,
7149 irsp->un.ulpWord[4], irsp->ulpTimeout);
7150 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
7151 lpfc_ct_free_iocb(phba, cmdiocb);
7153 lpfc_els_free_iocb(phba, cmdiocb);
7158 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7159 * @phba: Pointer to HBA context object.
7160 * @pring: Pointer to driver SLI ring object.
7161 * @cmdiocb: Pointer to driver command iocb object.
7163 * This function issues an abort iocb for the provided command
7164 * iocb. This function is called with hbalock held.
7165 * The function returns 0 when it fails due to memory allocation
7166 * failure or when the command iocb is an abort request.
7169 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7170 struct lpfc_iocbq *cmdiocb)
7172 struct lpfc_vport *vport = cmdiocb->vport;
7173 struct lpfc_iocbq *abtsiocbp;
7174 IOCB_t *icmd = NULL;
7175 IOCB_t *iabt = NULL;
7176 int retval = IOCB_ERROR;
7179 * There are certain command types we don't want to abort. And we
7180 * don't want to abort commands that are already in the process of
7183 icmd = &cmdiocb->iocb;
7184 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
7185 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7186 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
7189 /* If we're unloading, don't abort iocb on the ELS ring, but change the
7190 * callback so that nothing happens when it finishes.
7192 if ((vport->load_flag & FC_UNLOADING) &&
7193 (pring->ringno == LPFC_ELS_RING)) {
7194 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
7195 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
7197 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
7198 goto abort_iotag_exit;
7201 /* issue ABTS for this IOCB based on iotag */
7202 abtsiocbp = __lpfc_sli_get_iocbq(phba);
7203 if (abtsiocbp == NULL)
7206 /* This signals the response to set the correct status
7207 * before calling the completion handler
7209 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
7211 iabt = &abtsiocbp->iocb;
7212 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
7213 iabt->un.acxri.abortContextTag = icmd->ulpContext;
7214 if (phba->sli_rev == LPFC_SLI_REV4) {
7215 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
7216 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
7219 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
7221 iabt->ulpClass = icmd->ulpClass;
7223 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7224 abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
7225 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
7226 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
7228 if (phba->link_state >= LPFC_LINK_UP)
7229 iabt->ulpCommand = CMD_ABORT_XRI_CN;
7231 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
7233 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
7235 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
7236 "0339 Abort xri x%x, original iotag x%x, "
7237 "abort cmd iotag x%x\n",
7238 iabt->un.acxri.abortContextTag,
7239 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
7240 retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
7243 __lpfc_sli_release_iocbq(phba, abtsiocbp);
7246 * Caller to this routine should check for IOCB_ERROR
7247 * and handle it properly. This routine no longer removes
7248 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7254 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7255 * @iocbq: Pointer to driver iocb object.
7256 * @vport: Pointer to driver virtual port object.
7257 * @tgt_id: SCSI ID of the target.
7258 * @lun_id: LUN ID of the scsi device.
7259 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
7261 * This function acts as an iocb filter for functions which abort or count
7262 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
7263 * 0 if the filtering criteria is met for the given iocb and will return
7264 * 1 if the filtering criteria is not met.
7265 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
7266 * given iocb is for the SCSI device specified by vport, tgt_id and
7268 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
7269 * given iocb is for the SCSI target specified by vport and tgt_id
7271 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
7272 * given iocb is for the SCSI host associated with the given vport.
7273 * This function is called with no locks held.
7276 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
7277 uint16_t tgt_id, uint64_t lun_id,
7278 lpfc_ctx_cmd ctx_cmd)
7280 struct lpfc_scsi_buf *lpfc_cmd;
7283 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
7286 if (iocbq->vport != vport)
7289 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
7291 if (lpfc_cmd->pCmd == NULL)
7296 if ((lpfc_cmd->rdata->pnode) &&
7297 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
7298 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
7302 if ((lpfc_cmd->rdata->pnode) &&
7303 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
7310 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
7319 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7320 * @vport: Pointer to virtual port.
7321 * @tgt_id: SCSI ID of the target.
7322 * @lun_id: LUN ID of the scsi device.
7323 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7325 * This function returns number of FCP commands pending for the vport.
7326 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7327 * commands pending on the vport associated with SCSI device specified
7328 * by tgt_id and lun_id parameters.
7329 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7330 * commands pending on the vport associated with SCSI target specified
7331 * by tgt_id parameter.
7332 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7333 * commands pending on the vport.
7334 * This function returns the number of iocbs which satisfy the filter.
7335 * This function is called without any lock held.
7338 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
7339 lpfc_ctx_cmd ctx_cmd)
7341 struct lpfc_hba *phba = vport->phba;
7342 struct lpfc_iocbq *iocbq;
7345 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
7346 iocbq = phba->sli.iocbq_lookup[i];
7348 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
7357 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7358 * @phba: Pointer to HBA context object
7359 * @cmdiocb: Pointer to command iocb object.
7360 * @rspiocb: Pointer to response iocb object.
7362 * This function is called when an aborted FCP iocb completes. This
7363 * function is called by the ring event handler with no lock held.
7364 * This function frees the iocb.
7367 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7368 struct lpfc_iocbq *rspiocb)
7370 lpfc_sli_release_iocbq(phba, cmdiocb);
7375 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
7376 * @vport: Pointer to virtual port.
7377 * @pring: Pointer to driver SLI ring object.
7378 * @tgt_id: SCSI ID of the target.
7379 * @lun_id: LUN ID of the scsi device.
7380 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7382 * This function sends an abort command for every SCSI command
7383 * associated with the given virtual port pending on the ring
7384 * filtered by lpfc_sli_validate_fcp_iocb function.
7385 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
7386 * FCP iocbs associated with lun specified by tgt_id and lun_id
7388 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
7389 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
7390 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
7391 * FCP iocbs associated with virtual port.
7392 * This function returns number of iocbs it failed to abort.
7393 * This function is called with no locks held.
7396 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
7397 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
7399 struct lpfc_hba *phba = vport->phba;
7400 struct lpfc_iocbq *iocbq;
7401 struct lpfc_iocbq *abtsiocb;
7403 int errcnt = 0, ret_val = 0;
7406 for (i = 1; i <= phba->sli.last_iotag; i++) {
7407 iocbq = phba->sli.iocbq_lookup[i];
7409 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
7413 /* issue ABTS for this IOCB based on iotag */
7414 abtsiocb = lpfc_sli_get_iocbq(phba);
7415 if (abtsiocb == NULL) {
7421 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
7422 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
7423 if (phba->sli_rev == LPFC_SLI_REV4)
7424 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
7426 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
7427 abtsiocb->iocb.ulpLe = 1;
7428 abtsiocb->iocb.ulpClass = cmd->ulpClass;
7429 abtsiocb->vport = phba->pport;
7431 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7432 abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
7433 if (iocbq->iocb_flag & LPFC_IO_FCP)
7434 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
7436 if (lpfc_is_link_up(phba))
7437 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
7439 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
7441 /* Setup callback routine and issue the command. */
7442 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
7443 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
7445 if (ret_val == IOCB_ERROR) {
7446 lpfc_sli_release_iocbq(phba, abtsiocb);
7456 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
7457 * @phba: Pointer to HBA context object.
7458 * @cmdiocbq: Pointer to command iocb.
7459 * @rspiocbq: Pointer to response iocb.
7461 * This function is the completion handler for iocbs issued using
7462 * lpfc_sli_issue_iocb_wait function. This function is called by the
7463 * ring event handler function without any lock held. This function
7464 * can be called from both worker thread context and interrupt
7465 * context. This function also can be called from other thread which
7466 * cleans up the SLI layer objects.
7467 * This function copy the contents of the response iocb to the
7468 * response iocb memory object provided by the caller of
7469 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
7470 * sleeps for the iocb completion.
7473 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
7474 struct lpfc_iocbq *cmdiocbq,
7475 struct lpfc_iocbq *rspiocbq)
7477 wait_queue_head_t *pdone_q;
7478 unsigned long iflags;
7479 struct lpfc_scsi_buf *lpfc_cmd;
7481 spin_lock_irqsave(&phba->hbalock, iflags);
7482 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
7483 if (cmdiocbq->context2 && rspiocbq)
7484 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
7485 &rspiocbq->iocb, sizeof(IOCB_t));
7487 /* Set the exchange busy flag for task management commands */
7488 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
7489 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
7490 lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
7492 lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
7495 pdone_q = cmdiocbq->context_un.wait_queue;
7498 spin_unlock_irqrestore(&phba->hbalock, iflags);
7503 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
7504 * @phba: Pointer to HBA context object..
7505 * @piocbq: Pointer to command iocb.
7506 * @flag: Flag to test.
7508 * This routine grabs the hbalock and then test the iocb_flag to
7509 * see if the passed in flag is set.
7512 * 0 if flag is not set.
7515 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
7516 struct lpfc_iocbq *piocbq, uint32_t flag)
7518 unsigned long iflags;
7521 spin_lock_irqsave(&phba->hbalock, iflags);
7522 ret = piocbq->iocb_flag & flag;
7523 spin_unlock_irqrestore(&phba->hbalock, iflags);
7529 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
7530 * @phba: Pointer to HBA context object..
7531 * @pring: Pointer to sli ring.
7532 * @piocb: Pointer to command iocb.
7533 * @prspiocbq: Pointer to response iocb.
7534 * @timeout: Timeout in number of seconds.
7536 * This function issues the iocb to firmware and waits for the
7537 * iocb to complete. If the iocb command is not
7538 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
7539 * Caller should not free the iocb resources if this function
7540 * returns IOCB_TIMEDOUT.
7541 * The function waits for the iocb completion using an
7542 * non-interruptible wait.
7543 * This function will sleep while waiting for iocb completion.
7544 * So, this function should not be called from any context which
7545 * does not allow sleeping. Due to the same reason, this function
7546 * cannot be called with interrupt disabled.
7547 * This function assumes that the iocb completions occur while
7548 * this function sleep. So, this function cannot be called from
7549 * the thread which process iocb completion for this ring.
7550 * This function clears the iocb_flag of the iocb object before
7551 * issuing the iocb and the iocb completion handler sets this
7552 * flag and wakes this thread when the iocb completes.
7553 * The contents of the response iocb will be copied to prspiocbq
7554 * by the completion handler when the command completes.
7555 * This function returns IOCB_SUCCESS when success.
7556 * This function is called with no lock held.
7559 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
7560 uint32_t ring_number,
7561 struct lpfc_iocbq *piocb,
7562 struct lpfc_iocbq *prspiocbq,
7565 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
7566 long timeleft, timeout_req = 0;
7567 int retval = IOCB_SUCCESS;
7571 * If the caller has provided a response iocbq buffer, then context2
7572 * is NULL or its an error.
7575 if (piocb->context2)
7577 piocb->context2 = prspiocbq;
7580 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
7581 piocb->context_un.wait_queue = &done_q;
7582 piocb->iocb_flag &= ~LPFC_IO_WAKE;
7584 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7585 creg_val = readl(phba->HCregaddr);
7586 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
7587 writel(creg_val, phba->HCregaddr);
7588 readl(phba->HCregaddr); /* flush */
7591 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
7592 if (retval == IOCB_SUCCESS) {
7593 timeout_req = timeout * HZ;
7594 timeleft = wait_event_timeout(done_q,
7595 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
7598 if (piocb->iocb_flag & LPFC_IO_WAKE) {
7599 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7600 "0331 IOCB wake signaled\n");
7601 } else if (timeleft == 0) {
7602 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7603 "0338 IOCB wait timeout error - no "
7604 "wake response Data x%x\n", timeout);
7605 retval = IOCB_TIMEDOUT;
7607 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7608 "0330 IOCB wake NOT set, "
7610 timeout, (timeleft / jiffies));
7611 retval = IOCB_TIMEDOUT;
7614 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7615 "0332 IOCB wait issue failed, Data x%x\n",
7617 retval = IOCB_ERROR;
7620 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7621 creg_val = readl(phba->HCregaddr);
7622 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
7623 writel(creg_val, phba->HCregaddr);
7624 readl(phba->HCregaddr); /* flush */
7628 piocb->context2 = NULL;
7630 piocb->context_un.wait_queue = NULL;
7631 piocb->iocb_cmpl = NULL;
7636 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
7637 * @phba: Pointer to HBA context object.
7638 * @pmboxq: Pointer to driver mailbox object.
7639 * @timeout: Timeout in number of seconds.
7641 * This function issues the mailbox to firmware and waits for the
7642 * mailbox command to complete. If the mailbox command is not
7643 * completed within timeout seconds, it returns MBX_TIMEOUT.
7644 * The function waits for the mailbox completion using an
7645 * interruptible wait. If the thread is woken up due to a
7646 * signal, MBX_TIMEOUT error is returned to the caller. Caller
7647 * should not free the mailbox resources, if this function returns
7649 * This function will sleep while waiting for mailbox completion.
7650 * So, this function should not be called from any context which
7651 * does not allow sleeping. Due to the same reason, this function
7652 * cannot be called with interrupt disabled.
7653 * This function assumes that the mailbox completion occurs while
7654 * this function sleep. So, this function cannot be called from
7655 * the worker thread which processes mailbox completion.
7656 * This function is called in the context of HBA management
7658 * This function returns MBX_SUCCESS when successful.
7659 * This function is called with no lock held.
7662 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
7665 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
7669 /* The caller must leave context1 empty. */
7670 if (pmboxq->context1)
7671 return MBX_NOT_FINISHED;
7673 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
7674 /* setup wake call as IOCB callback */
7675 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
7676 /* setup context field to pass wait_queue pointer to wake function */
7677 pmboxq->context1 = &done_q;
7679 /* now issue the command */
7680 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
7682 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
7683 wait_event_interruptible_timeout(done_q,
7684 pmboxq->mbox_flag & LPFC_MBX_WAKE,
7687 spin_lock_irqsave(&phba->hbalock, flag);
7688 pmboxq->context1 = NULL;
7690 * if LPFC_MBX_WAKE flag is set the mailbox is completed
7691 * else do not free the resources.
7693 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
7694 retval = MBX_SUCCESS;
7696 retval = MBX_TIMEOUT;
7697 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7699 spin_unlock_irqrestore(&phba->hbalock, flag);
7706 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
7707 * @phba: Pointer to HBA context.
7709 * This function is called to shutdown the driver's mailbox sub-system.
7710 * It first marks the mailbox sub-system is in a block state to prevent
7711 * the asynchronous mailbox command from issued off the pending mailbox
7712 * command queue. If the mailbox command sub-system shutdown is due to
7713 * HBA error conditions such as EEH or ERATT, this routine shall invoke
7714 * the mailbox sub-system flush routine to forcefully bring down the
7715 * mailbox sub-system. Otherwise, if it is due to normal condition (such
7716 * as with offline or HBA function reset), this routine will wait for the
7717 * outstanding mailbox command to complete before invoking the mailbox
7718 * sub-system flush routine to gracefully bring down mailbox sub-system.
7721 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
7723 struct lpfc_sli *psli = &phba->sli;
7724 uint8_t actcmd = MBX_HEARTBEAT;
7725 unsigned long timeout;
7727 spin_lock_irq(&phba->hbalock);
7728 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
7729 spin_unlock_irq(&phba->hbalock);
7731 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7732 spin_lock_irq(&phba->hbalock);
7733 if (phba->sli.mbox_active)
7734 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
7735 spin_unlock_irq(&phba->hbalock);
7736 /* Determine how long we might wait for the active mailbox
7737 * command to be gracefully completed by firmware.
7739 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
7741 while (phba->sli.mbox_active) {
7742 /* Check active mailbox complete status every 2ms */
7744 if (time_after(jiffies, timeout))
7745 /* Timeout, let the mailbox flush routine to
7746 * forcefully release active mailbox command
7751 lpfc_sli_mbox_sys_flush(phba);
7755 * lpfc_sli_eratt_read - read sli-3 error attention events
7756 * @phba: Pointer to HBA context.
7758 * This function is called to read the SLI3 device error attention registers
7759 * for possible error attention events. The caller must hold the hostlock
7760 * with spin_lock_irq().
7762 * This fucntion returns 1 when there is Error Attention in the Host Attention
7763 * Register and returns 0 otherwise.
7766 lpfc_sli_eratt_read(struct lpfc_hba *phba)
7770 /* Read chip Host Attention (HA) register */
7771 ha_copy = readl(phba->HAregaddr);
7772 if (ha_copy & HA_ERATT) {
7773 /* Read host status register to retrieve error event */
7774 lpfc_sli_read_hs(phba);
7776 /* Check if there is a deferred error condition is active */
7777 if ((HS_FFER1 & phba->work_hs) &&
7778 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
7779 HS_FFER6 | HS_FFER7) & phba->work_hs)) {
7780 phba->hba_flag |= DEFER_ERATT;
7781 /* Clear all interrupt enable conditions */
7782 writel(0, phba->HCregaddr);
7783 readl(phba->HCregaddr);
7786 /* Set the driver HA work bitmap */
7787 phba->work_ha |= HA_ERATT;
7788 /* Indicate polling handles this ERATT */
7789 phba->hba_flag |= HBA_ERATT_HANDLED;
7796 * lpfc_sli4_eratt_read - read sli-4 error attention events
7797 * @phba: Pointer to HBA context.
7799 * This function is called to read the SLI4 device error attention registers
7800 * for possible error attention events. The caller must hold the hostlock
7801 * with spin_lock_irq().
7803 * This fucntion returns 1 when there is Error Attention in the Host Attention
7804 * Register and returns 0 otherwise.
7807 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
7809 uint32_t uerr_sta_hi, uerr_sta_lo;
7811 /* For now, use the SLI4 device internal unrecoverable error
7812 * registers for error attention. This can be changed later.
7814 uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
7815 uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
7816 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
7817 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
7818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7819 "1423 HBA Unrecoverable error: "
7820 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
7821 "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
7822 uerr_sta_lo, uerr_sta_hi,
7823 phba->sli4_hba.ue_mask_lo,
7824 phba->sli4_hba.ue_mask_hi);
7825 phba->work_status[0] = uerr_sta_lo;
7826 phba->work_status[1] = uerr_sta_hi;
7827 /* Set the driver HA work bitmap */
7828 phba->work_ha |= HA_ERATT;
7829 /* Indicate polling handles this ERATT */
7830 phba->hba_flag |= HBA_ERATT_HANDLED;
7837 * lpfc_sli_check_eratt - check error attention events
7838 * @phba: Pointer to HBA context.
7840 * This function is called from timer soft interrupt context to check HBA's
7841 * error attention register bit for error attention events.
7843 * This fucntion returns 1 when there is Error Attention in the Host Attention
7844 * Register and returns 0 otherwise.
7847 lpfc_sli_check_eratt(struct lpfc_hba *phba)
7851 /* If somebody is waiting to handle an eratt, don't process it
7852 * here. The brdkill function will do this.
7854 if (phba->link_flag & LS_IGNORE_ERATT)
7857 /* Check if interrupt handler handles this ERATT */
7858 spin_lock_irq(&phba->hbalock);
7859 if (phba->hba_flag & HBA_ERATT_HANDLED) {
7860 /* Interrupt handler has handled ERATT */
7861 spin_unlock_irq(&phba->hbalock);
7866 * If there is deferred error attention, do not check for error
7869 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7870 spin_unlock_irq(&phba->hbalock);
7874 /* If PCI channel is offline, don't process it */
7875 if (unlikely(pci_channel_offline(phba->pcidev))) {
7876 spin_unlock_irq(&phba->hbalock);
7880 switch (phba->sli_rev) {
7883 /* Read chip Host Attention (HA) register */
7884 ha_copy = lpfc_sli_eratt_read(phba);
7887 /* Read devcie Uncoverable Error (UERR) registers */
7888 ha_copy = lpfc_sli4_eratt_read(phba);
7891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7892 "0299 Invalid SLI revision (%d)\n",
7897 spin_unlock_irq(&phba->hbalock);
7903 * lpfc_intr_state_check - Check device state for interrupt handling
7904 * @phba: Pointer to HBA context.
7906 * This inline routine checks whether a device or its PCI slot is in a state
7907 * that the interrupt should be handled.
7909 * This function returns 0 if the device or the PCI slot is in a state that
7910 * interrupt should be handled, otherwise -EIO.
7913 lpfc_intr_state_check(struct lpfc_hba *phba)
7915 /* If the pci channel is offline, ignore all the interrupts */
7916 if (unlikely(pci_channel_offline(phba->pcidev)))
7919 /* Update device level interrupt statistics */
7920 phba->sli.slistat.sli_intr++;
7922 /* Ignore all interrupts during initialization. */
7923 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
7930 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
7931 * @irq: Interrupt number.
7932 * @dev_id: The device context pointer.
7934 * This function is directly called from the PCI layer as an interrupt
7935 * service routine when device with SLI-3 interface spec is enabled with
7936 * MSI-X multi-message interrupt mode and there are slow-path events in
7937 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
7938 * interrupt mode, this function is called as part of the device-level
7939 * interrupt handler. When the PCI slot is in error recovery or the HBA
7940 * is undergoing initialization, the interrupt handler will not process
7941 * the interrupt. The link attention and ELS ring attention events are
7942 * handled by the worker thread. The interrupt handler signals the worker
7943 * thread and returns for these events. This function is called without
7944 * any lock held. It gets the hbalock to access and update SLI data
7947 * This function returns IRQ_HANDLED when interrupt is handled else it
7951 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
7953 struct lpfc_hba *phba;
7954 uint32_t ha_copy, hc_copy;
7955 uint32_t work_ha_copy;
7956 unsigned long status;
7957 unsigned long iflag;
7960 MAILBOX_t *mbox, *pmbox;
7961 struct lpfc_vport *vport;
7962 struct lpfc_nodelist *ndlp;
7963 struct lpfc_dmabuf *mp;
7968 * Get the driver's phba structure from the dev_id and
7969 * assume the HBA is not interrupting.
7971 phba = (struct lpfc_hba *)dev_id;
7973 if (unlikely(!phba))
7977 * Stuff needs to be attented to when this function is invoked as an
7978 * individual interrupt handler in MSI-X multi-message interrupt mode
7980 if (phba->intr_type == MSIX) {
7981 /* Check device state for handling interrupt */
7982 if (lpfc_intr_state_check(phba))
7984 /* Need to read HA REG for slow-path events */
7985 spin_lock_irqsave(&phba->hbalock, iflag);
7986 ha_copy = readl(phba->HAregaddr);
7987 /* If somebody is waiting to handle an eratt don't process it
7988 * here. The brdkill function will do this.
7990 if (phba->link_flag & LS_IGNORE_ERATT)
7991 ha_copy &= ~HA_ERATT;
7992 /* Check the need for handling ERATT in interrupt handler */
7993 if (ha_copy & HA_ERATT) {
7994 if (phba->hba_flag & HBA_ERATT_HANDLED)
7995 /* ERATT polling has handled ERATT */
7996 ha_copy &= ~HA_ERATT;
7998 /* Indicate interrupt handler handles ERATT */
7999 phba->hba_flag |= HBA_ERATT_HANDLED;
8003 * If there is deferred error attention, do not check for any
8006 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8007 spin_unlock_irqrestore(&phba->hbalock, iflag);
8011 /* Clear up only attention source related to slow-path */
8012 hc_copy = readl(phba->HCregaddr);
8013 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
8014 HC_LAINT_ENA | HC_ERINT_ENA),
8016 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
8018 writel(hc_copy, phba->HCregaddr);
8019 readl(phba->HAregaddr); /* flush */
8020 spin_unlock_irqrestore(&phba->hbalock, iflag);
8022 ha_copy = phba->ha_copy;
8024 work_ha_copy = ha_copy & phba->work_ha_mask;
8027 if (work_ha_copy & HA_LATT) {
8028 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
8030 * Turn off Link Attention interrupts
8031 * until CLEAR_LA done
8033 spin_lock_irqsave(&phba->hbalock, iflag);
8034 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
8035 control = readl(phba->HCregaddr);
8036 control &= ~HC_LAINT_ENA;
8037 writel(control, phba->HCregaddr);
8038 readl(phba->HCregaddr); /* flush */
8039 spin_unlock_irqrestore(&phba->hbalock, iflag);
8042 work_ha_copy &= ~HA_LATT;
8045 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
8047 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
8048 * the only slow ring.
8050 status = (work_ha_copy &
8051 (HA_RXMASK << (4*LPFC_ELS_RING)));
8052 status >>= (4*LPFC_ELS_RING);
8053 if (status & HA_RXMASK) {
8054 spin_lock_irqsave(&phba->hbalock, iflag);
8055 control = readl(phba->HCregaddr);
8057 lpfc_debugfs_slow_ring_trc(phba,
8058 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
8060 (uint32_t)phba->sli.slistat.sli_intr);
8062 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
8063 lpfc_debugfs_slow_ring_trc(phba,
8065 "pwork:x%x hawork:x%x wait:x%x",
8066 phba->work_ha, work_ha_copy,
8067 (uint32_t)((unsigned long)
8068 &phba->work_waitq));
8071 ~(HC_R0INT_ENA << LPFC_ELS_RING);
8072 writel(control, phba->HCregaddr);
8073 readl(phba->HCregaddr); /* flush */
8076 lpfc_debugfs_slow_ring_trc(phba,
8077 "ISR slow ring: pwork:"
8078 "x%x hawork:x%x wait:x%x",
8079 phba->work_ha, work_ha_copy,
8080 (uint32_t)((unsigned long)
8081 &phba->work_waitq));
8083 spin_unlock_irqrestore(&phba->hbalock, iflag);
8086 spin_lock_irqsave(&phba->hbalock, iflag);
8087 if (work_ha_copy & HA_ERATT) {
8088 lpfc_sli_read_hs(phba);
8090 * Check if there is a deferred error condition
8093 if ((HS_FFER1 & phba->work_hs) &&
8094 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
8095 HS_FFER6 | HS_FFER7) & phba->work_hs)) {
8096 phba->hba_flag |= DEFER_ERATT;
8097 /* Clear all interrupt enable conditions */
8098 writel(0, phba->HCregaddr);
8099 readl(phba->HCregaddr);
8103 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
8104 pmb = phba->sli.mbox_active;
8109 /* First check out the status word */
8110 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
8111 if (pmbox->mbxOwner != OWN_HOST) {
8112 spin_unlock_irqrestore(&phba->hbalock, iflag);
8114 * Stray Mailbox Interrupt, mbxCommand <cmd>
8115 * mbxStatus <status>
8117 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
8119 "(%d):0304 Stray Mailbox "
8120 "Interrupt mbxCommand x%x "
8122 (vport ? vport->vpi : 0),
8125 /* clear mailbox attention bit */
8126 work_ha_copy &= ~HA_MBATT;
8128 phba->sli.mbox_active = NULL;
8129 spin_unlock_irqrestore(&phba->hbalock, iflag);
8130 phba->last_completion_time = jiffies;
8131 del_timer(&phba->sli.mbox_tmo);
8132 if (pmb->mbox_cmpl) {
8133 lpfc_sli_pcimem_bcopy(mbox, pmbox,
8136 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
8137 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
8139 lpfc_debugfs_disc_trc(vport,
8140 LPFC_DISC_TRC_MBOX_VPORT,
8142 "status:x%x rpi:x%x",
8143 (uint32_t)pmbox->mbxStatus,
8144 pmbox->un.varWords[0], 0);
8146 if (!pmbox->mbxStatus) {
8147 mp = (struct lpfc_dmabuf *)
8149 ndlp = (struct lpfc_nodelist *)
8152 /* Reg_LOGIN of dflt RPI was
8153 * successful. new lets get
8154 * rid of the RPI using the
8157 lpfc_unreg_login(phba,
8159 pmbox->un.varWords[0],
8162 lpfc_mbx_cmpl_dflt_rpi;
8164 pmb->context2 = ndlp;
8166 rc = lpfc_sli_issue_mbox(phba,
8170 lpfc_printf_log(phba,
8173 "0350 rc should have"
8175 if (rc != MBX_NOT_FINISHED)
8176 goto send_current_mbox;
8180 &phba->pport->work_port_lock,
8182 phba->pport->work_port_events &=
8184 spin_unlock_irqrestore(
8185 &phba->pport->work_port_lock,
8187 lpfc_mbox_cmpl_put(phba, pmb);
8190 spin_unlock_irqrestore(&phba->hbalock, iflag);
8192 if ((work_ha_copy & HA_MBATT) &&
8193 (phba->sli.mbox_active == NULL)) {
8195 /* Process next mailbox command if there is one */
8197 rc = lpfc_sli_issue_mbox(phba, NULL,
8199 } while (rc == MBX_NOT_FINISHED);
8200 if (rc != MBX_SUCCESS)
8201 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
8202 LOG_SLI, "0349 rc should be "
8206 spin_lock_irqsave(&phba->hbalock, iflag);
8207 phba->work_ha |= work_ha_copy;
8208 spin_unlock_irqrestore(&phba->hbalock, iflag);
8209 lpfc_worker_wake_up(phba);
8213 } /* lpfc_sli_sp_intr_handler */
8216 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
8217 * @irq: Interrupt number.
8218 * @dev_id: The device context pointer.
8220 * This function is directly called from the PCI layer as an interrupt
8221 * service routine when device with SLI-3 interface spec is enabled with
8222 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8223 * ring event in the HBA. However, when the device is enabled with either
8224 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8225 * device-level interrupt handler. When the PCI slot is in error recovery
8226 * or the HBA is undergoing initialization, the interrupt handler will not
8227 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8228 * the intrrupt context. This function is called without any lock held.
8229 * It gets the hbalock to access and update SLI data structures.
8231 * This function returns IRQ_HANDLED when interrupt is handled else it
8235 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
8237 struct lpfc_hba *phba;
8239 unsigned long status;
8240 unsigned long iflag;
8242 /* Get the driver's phba structure from the dev_id and
8243 * assume the HBA is not interrupting.
8245 phba = (struct lpfc_hba *) dev_id;
8247 if (unlikely(!phba))
8251 * Stuff needs to be attented to when this function is invoked as an
8252 * individual interrupt handler in MSI-X multi-message interrupt mode
8254 if (phba->intr_type == MSIX) {
8255 /* Check device state for handling interrupt */
8256 if (lpfc_intr_state_check(phba))
8258 /* Need to read HA REG for FCP ring and other ring events */
8259 ha_copy = readl(phba->HAregaddr);
8260 /* Clear up only attention source related to fast-path */
8261 spin_lock_irqsave(&phba->hbalock, iflag);
8263 * If there is deferred error attention, do not check for
8266 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8267 spin_unlock_irqrestore(&phba->hbalock, iflag);
8270 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
8272 readl(phba->HAregaddr); /* flush */
8273 spin_unlock_irqrestore(&phba->hbalock, iflag);
8275 ha_copy = phba->ha_copy;
8278 * Process all events on FCP ring. Take the optimized path for FCP IO.
8280 ha_copy &= ~(phba->work_ha_mask);
8282 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
8283 status >>= (4*LPFC_FCP_RING);
8284 if (status & HA_RXMASK)
8285 lpfc_sli_handle_fast_ring_event(phba,
8286 &phba->sli.ring[LPFC_FCP_RING],
8289 if (phba->cfg_multi_ring_support == 2) {
8291 * Process all events on extra ring. Take the optimized path
8292 * for extra ring IO.
8294 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
8295 status >>= (4*LPFC_EXTRA_RING);
8296 if (status & HA_RXMASK) {
8297 lpfc_sli_handle_fast_ring_event(phba,
8298 &phba->sli.ring[LPFC_EXTRA_RING],
8303 } /* lpfc_sli_fp_intr_handler */
8306 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
8307 * @irq: Interrupt number.
8308 * @dev_id: The device context pointer.
8310 * This function is the HBA device-level interrupt handler to device with
8311 * SLI-3 interface spec, called from the PCI layer when either MSI or
8312 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
8313 * requires driver attention. This function invokes the slow-path interrupt
8314 * attention handling function and fast-path interrupt attention handling
8315 * function in turn to process the relevant HBA attention events. This
8316 * function is called without any lock held. It gets the hbalock to access
8317 * and update SLI data structures.
8319 * This function returns IRQ_HANDLED when interrupt is handled, else it
8323 lpfc_sli_intr_handler(int irq, void *dev_id)
8325 struct lpfc_hba *phba;
8326 irqreturn_t sp_irq_rc, fp_irq_rc;
8327 unsigned long status1, status2;
8331 * Get the driver's phba structure from the dev_id and
8332 * assume the HBA is not interrupting.
8334 phba = (struct lpfc_hba *) dev_id;
8336 if (unlikely(!phba))
8339 /* Check device state for handling interrupt */
8340 if (lpfc_intr_state_check(phba))
8343 spin_lock(&phba->hbalock);
8344 phba->ha_copy = readl(phba->HAregaddr);
8345 if (unlikely(!phba->ha_copy)) {
8346 spin_unlock(&phba->hbalock);
8348 } else if (phba->ha_copy & HA_ERATT) {
8349 if (phba->hba_flag & HBA_ERATT_HANDLED)
8350 /* ERATT polling has handled ERATT */
8351 phba->ha_copy &= ~HA_ERATT;
8353 /* Indicate interrupt handler handles ERATT */
8354 phba->hba_flag |= HBA_ERATT_HANDLED;
8358 * If there is deferred error attention, do not check for any interrupt.
8360 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8361 spin_unlock_irq(&phba->hbalock);
8365 /* Clear attention sources except link and error attentions */
8366 hc_copy = readl(phba->HCregaddr);
8367 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
8368 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
8370 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
8371 writel(hc_copy, phba->HCregaddr);
8372 readl(phba->HAregaddr); /* flush */
8373 spin_unlock(&phba->hbalock);
8376 * Invokes slow-path host attention interrupt handling as appropriate.
8379 /* status of events with mailbox and link attention */
8380 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
8382 /* status of events with ELS ring */
8383 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
8384 status2 >>= (4*LPFC_ELS_RING);
8386 if (status1 || (status2 & HA_RXMASK))
8387 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
8389 sp_irq_rc = IRQ_NONE;
8392 * Invoke fast-path host attention interrupt handling as appropriate.
8395 /* status of events with FCP ring */
8396 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
8397 status1 >>= (4*LPFC_FCP_RING);
8399 /* status of events with extra ring */
8400 if (phba->cfg_multi_ring_support == 2) {
8401 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
8402 status2 >>= (4*LPFC_EXTRA_RING);
8406 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
8407 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
8409 fp_irq_rc = IRQ_NONE;
8411 /* Return device-level interrupt handling status */
8412 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
8413 } /* lpfc_sli_intr_handler */
8416 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
8417 * @phba: pointer to lpfc hba data structure.
8419 * This routine is invoked by the worker thread to process all the pending
8420 * SLI4 FCP abort XRI events.
8422 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
8424 struct lpfc_cq_event *cq_event;
8426 /* First, declare the fcp xri abort event has been handled */
8427 spin_lock_irq(&phba->hbalock);
8428 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
8429 spin_unlock_irq(&phba->hbalock);
8430 /* Now, handle all the fcp xri abort events */
8431 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
8432 /* Get the first event from the head of the event queue */
8433 spin_lock_irq(&phba->hbalock);
8434 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8435 cq_event, struct lpfc_cq_event, list);
8436 spin_unlock_irq(&phba->hbalock);
8437 /* Notify aborted XRI for FCP work queue */
8438 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
8439 /* Free the event processed back to the free pool */
8440 lpfc_sli4_cq_event_release(phba, cq_event);
8445 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
8446 * @phba: pointer to lpfc hba data structure.
8448 * This routine is invoked by the worker thread to process all the pending
8449 * SLI4 els abort xri events.
8451 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
8453 struct lpfc_cq_event *cq_event;
8455 /* First, declare the els xri abort event has been handled */
8456 spin_lock_irq(&phba->hbalock);
8457 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
8458 spin_unlock_irq(&phba->hbalock);
8459 /* Now, handle all the els xri abort events */
8460 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
8461 /* Get the first event from the head of the event queue */
8462 spin_lock_irq(&phba->hbalock);
8463 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8464 cq_event, struct lpfc_cq_event, list);
8465 spin_unlock_irq(&phba->hbalock);
8466 /* Notify aborted XRI for ELS work queue */
8467 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
8468 /* Free the event processed back to the free pool */
8469 lpfc_sli4_cq_event_release(phba, cq_event);
8474 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
8475 * @phba: pointer to lpfc hba data structure
8476 * @pIocbIn: pointer to the rspiocbq
8477 * @pIocbOut: pointer to the cmdiocbq
8478 * @wcqe: pointer to the complete wcqe
8480 * This routine transfers the fields of a command iocbq to a response iocbq
8481 * by copying all the IOCB fields from command iocbq and transferring the
8482 * completion status information from the complete wcqe.
8485 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
8486 struct lpfc_iocbq *pIocbIn,
8487 struct lpfc_iocbq *pIocbOut,
8488 struct lpfc_wcqe_complete *wcqe)
8490 unsigned long iflags;
8491 size_t offset = offsetof(struct lpfc_iocbq, iocb);
8493 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
8494 sizeof(struct lpfc_iocbq) - offset);
8495 /* Map WCQE parameters into irspiocb parameters */
8496 pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
8497 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
8498 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
8499 pIocbIn->iocb.un.fcpi.fcpi_parm =
8500 pIocbOut->iocb.un.fcpi.fcpi_parm -
8501 wcqe->total_data_placed;
8503 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8505 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8506 pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
8509 /* Pick up HBA exchange busy condition */
8510 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
8511 spin_lock_irqsave(&phba->hbalock, iflags);
8512 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
8513 spin_unlock_irqrestore(&phba->hbalock, iflags);
8518 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
8519 * @phba: Pointer to HBA context object.
8520 * @wcqe: Pointer to work-queue completion queue entry.
8522 * This routine handles an ELS work-queue completion event and construct
8523 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
8524 * discovery engine to handle.
8526 * Return: Pointer to the receive IOCBQ, NULL otherwise.
8528 static struct lpfc_iocbq *
8529 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
8530 struct lpfc_iocbq *irspiocbq)
8532 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8533 struct lpfc_iocbq *cmdiocbq;
8534 struct lpfc_wcqe_complete *wcqe;
8535 unsigned long iflags;
8537 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
8538 spin_lock_irqsave(&phba->hbalock, iflags);
8539 pring->stats.iocb_event++;
8540 /* Look up the ELS command IOCB and create pseudo response IOCB */
8541 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
8542 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8543 spin_unlock_irqrestore(&phba->hbalock, iflags);
8545 if (unlikely(!cmdiocbq)) {
8546 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8547 "0386 ELS complete with no corresponding "
8548 "cmdiocb: iotag (%d)\n",
8549 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8550 lpfc_sli_release_iocbq(phba, irspiocbq);
8554 /* Fake the irspiocbq and copy necessary response information */
8555 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
8561 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
8562 * @phba: Pointer to HBA context object.
8563 * @cqe: Pointer to mailbox completion queue entry.
8565 * This routine process a mailbox completion queue entry with asynchrous
8568 * Return: true if work posted to worker thread, otherwise false.
8571 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
8573 struct lpfc_cq_event *cq_event;
8574 unsigned long iflags;
8576 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8577 "0392 Async Event: word0:x%x, word1:x%x, "
8578 "word2:x%x, word3:x%x\n", mcqe->word0,
8579 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
8581 /* Allocate a new internal CQ_EVENT entry */
8582 cq_event = lpfc_sli4_cq_event_alloc(phba);
8584 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8585 "0394 Failed to allocate CQ_EVENT entry\n");
8589 /* Move the CQE into an asynchronous event entry */
8590 memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
8591 spin_lock_irqsave(&phba->hbalock, iflags);
8592 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
8593 /* Set the async event flag */
8594 phba->hba_flag |= ASYNC_EVENT;
8595 spin_unlock_irqrestore(&phba->hbalock, iflags);
8601 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
8602 * @phba: Pointer to HBA context object.
8603 * @cqe: Pointer to mailbox completion queue entry.
8605 * This routine process a mailbox completion queue entry with mailbox
8608 * Return: true if work posted to worker thread, otherwise false.
8611 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
8613 uint32_t mcqe_status;
8614 MAILBOX_t *mbox, *pmbox;
8615 struct lpfc_mqe *mqe;
8616 struct lpfc_vport *vport;
8617 struct lpfc_nodelist *ndlp;
8618 struct lpfc_dmabuf *mp;
8619 unsigned long iflags;
8621 bool workposted = false;
8624 /* If not a mailbox complete MCQE, out by checking mailbox consume */
8625 if (!bf_get(lpfc_trailer_completed, mcqe))
8626 goto out_no_mqe_complete;
8628 /* Get the reference to the active mbox command */
8629 spin_lock_irqsave(&phba->hbalock, iflags);
8630 pmb = phba->sli.mbox_active;
8631 if (unlikely(!pmb)) {
8632 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
8633 "1832 No pending MBOX command to handle\n");
8634 spin_unlock_irqrestore(&phba->hbalock, iflags);
8635 goto out_no_mqe_complete;
8637 spin_unlock_irqrestore(&phba->hbalock, iflags);
8639 pmbox = (MAILBOX_t *)&pmb->u.mqe;
8643 /* Reset heartbeat timer */
8644 phba->last_completion_time = jiffies;
8645 del_timer(&phba->sli.mbox_tmo);
8647 /* Move mbox data to caller's mailbox region, do endian swapping */
8648 if (pmb->mbox_cmpl && mbox)
8649 lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
8650 /* Set the mailbox status with SLI4 range 0x4000 */
8651 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
8652 if (mcqe_status != MB_CQE_STATUS_SUCCESS)
8653 bf_set(lpfc_mqe_status, mqe,
8654 (LPFC_MBX_ERROR_RANGE | mcqe_status));
8656 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
8657 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
8658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
8659 "MBOX dflt rpi: status:x%x rpi:x%x",
8661 pmbox->un.varWords[0], 0);
8662 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
8663 mp = (struct lpfc_dmabuf *)(pmb->context1);
8664 ndlp = (struct lpfc_nodelist *)pmb->context2;
8665 /* Reg_LOGIN of dflt RPI was successful. Now lets get
8666 * RID of the PPI using the same mbox buffer.
8668 lpfc_unreg_login(phba, vport->vpi,
8669 pmbox->un.varWords[0], pmb);
8670 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
8672 pmb->context2 = ndlp;
8674 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
8676 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
8677 LOG_SLI, "0385 rc should "
8678 "have been MBX_BUSY\n");
8679 if (rc != MBX_NOT_FINISHED)
8680 goto send_current_mbox;
8683 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8684 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
8685 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8687 /* There is mailbox completion work to do */
8688 spin_lock_irqsave(&phba->hbalock, iflags);
8689 __lpfc_mbox_cmpl_put(phba, pmb);
8690 phba->work_ha |= HA_MBATT;
8691 spin_unlock_irqrestore(&phba->hbalock, iflags);
8695 spin_lock_irqsave(&phba->hbalock, iflags);
8696 /* Release the mailbox command posting token */
8697 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8698 /* Setting active mailbox pointer need to be in sync to flag clear */
8699 phba->sli.mbox_active = NULL;
8700 spin_unlock_irqrestore(&phba->hbalock, iflags);
8701 /* Wake up worker thread to post the next pending mailbox command */
8702 lpfc_worker_wake_up(phba);
8703 out_no_mqe_complete:
8704 if (bf_get(lpfc_trailer_consumed, mcqe))
8705 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
8710 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
8711 * @phba: Pointer to HBA context object.
8712 * @cqe: Pointer to mailbox completion queue entry.
8714 * This routine process a mailbox completion queue entry, it invokes the
8715 * proper mailbox complete handling or asynchrous event handling routine
8716 * according to the MCQE's async bit.
8718 * Return: true if work posted to worker thread, otherwise false.
8721 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
8723 struct lpfc_mcqe mcqe;
8726 /* Copy the mailbox MCQE and convert endian order as needed */
8727 lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
8729 /* Invoke the proper event handling routine */
8730 if (!bf_get(lpfc_trailer_async, &mcqe))
8731 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
8733 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
8738 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
8739 * @phba: Pointer to HBA context object.
8740 * @wcqe: Pointer to work-queue completion queue entry.
8742 * This routine handles an ELS work-queue completion event.
8744 * Return: true if work posted to worker thread, otherwise false.
8747 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
8748 struct lpfc_wcqe_complete *wcqe)
8750 struct lpfc_iocbq *irspiocbq;
8751 unsigned long iflags;
8753 /* Get an irspiocbq for later ELS response processing use */
8754 irspiocbq = lpfc_sli_get_iocbq(phba);
8756 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8757 "0387 Failed to allocate an iocbq\n");
8761 /* Save off the slow-path queue event for work thread to process */
8762 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
8763 spin_lock_irqsave(&phba->hbalock, iflags);
8764 list_add_tail(&irspiocbq->cq_event.list,
8765 &phba->sli4_hba.sp_queue_event);
8766 phba->hba_flag |= HBA_SP_QUEUE_EVT;
8767 spin_unlock_irqrestore(&phba->hbalock, iflags);
8773 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
8774 * @phba: Pointer to HBA context object.
8775 * @wcqe: Pointer to work-queue completion queue entry.
8777 * This routine handles slow-path WQ entry comsumed event by invoking the
8778 * proper WQ release routine to the slow-path WQ.
8781 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
8782 struct lpfc_wcqe_release *wcqe)
8784 /* Check for the slow-path ELS work queue */
8785 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
8786 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
8787 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
8789 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8790 "2579 Slow-path wqe consume event carries "
8791 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
8792 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
8793 phba->sli4_hba.els_wq->queue_id);
8797 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
8798 * @phba: Pointer to HBA context object.
8799 * @cq: Pointer to a WQ completion queue.
8800 * @wcqe: Pointer to work-queue completion queue entry.
8802 * This routine handles an XRI abort event.
8804 * Return: true if work posted to worker thread, otherwise false.
8807 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
8808 struct lpfc_queue *cq,
8809 struct sli4_wcqe_xri_aborted *wcqe)
8811 bool workposted = false;
8812 struct lpfc_cq_event *cq_event;
8813 unsigned long iflags;
8815 /* Allocate a new internal CQ_EVENT entry */
8816 cq_event = lpfc_sli4_cq_event_alloc(phba);
8818 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8819 "0602 Failed to allocate CQ_EVENT entry\n");
8823 /* Move the CQE into the proper xri abort event list */
8824 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
8825 switch (cq->subtype) {
8827 spin_lock_irqsave(&phba->hbalock, iflags);
8828 list_add_tail(&cq_event->list,
8829 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
8830 /* Set the fcp xri abort event flag */
8831 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
8832 spin_unlock_irqrestore(&phba->hbalock, iflags);
8836 spin_lock_irqsave(&phba->hbalock, iflags);
8837 list_add_tail(&cq_event->list,
8838 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
8839 /* Set the els xri abort event flag */
8840 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
8841 spin_unlock_irqrestore(&phba->hbalock, iflags);
8845 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8846 "0603 Invalid work queue CQE subtype (x%x)\n",
8855 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
8856 * @phba: Pointer to HBA context object.
8857 * @rcqe: Pointer to receive-queue completion queue entry.
8859 * This routine process a receive-queue completion queue entry.
8861 * Return: true if work posted to worker thread, otherwise false.
8864 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
8866 bool workposted = false;
8867 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
8868 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
8869 struct hbq_dmabuf *dma_buf;
8871 unsigned long iflags;
8873 if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
8876 status = bf_get(lpfc_rcqe_status, rcqe);
8878 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
8879 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8880 "2537 Receive Frame Truncated!!\n");
8881 case FC_STATUS_RQ_SUCCESS:
8882 lpfc_sli4_rq_release(hrq, drq);
8883 spin_lock_irqsave(&phba->hbalock, iflags);
8884 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
8886 spin_unlock_irqrestore(&phba->hbalock, iflags);
8889 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
8890 /* save off the frame for the word thread to process */
8891 list_add_tail(&dma_buf->cq_event.list,
8892 &phba->sli4_hba.sp_queue_event);
8893 /* Frame received */
8894 phba->hba_flag |= HBA_SP_QUEUE_EVT;
8895 spin_unlock_irqrestore(&phba->hbalock, iflags);
8898 case FC_STATUS_INSUFF_BUF_NEED_BUF:
8899 case FC_STATUS_INSUFF_BUF_FRM_DISC:
8900 /* Post more buffers if possible */
8901 spin_lock_irqsave(&phba->hbalock, iflags);
8902 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
8903 spin_unlock_irqrestore(&phba->hbalock, iflags);
8912 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
8913 * @phba: Pointer to HBA context object.
8914 * @cq: Pointer to the completion queue.
8915 * @wcqe: Pointer to a completion queue entry.
8917 * This routine process a slow-path work-queue or recieve queue completion queue
8920 * Return: true if work posted to worker thread, otherwise false.
8923 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
8924 struct lpfc_cqe *cqe)
8926 struct lpfc_cqe cqevt;
8927 bool workposted = false;
8929 /* Copy the work queue CQE and convert endian order if needed */
8930 lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
8932 /* Check and process for different type of WCQE and dispatch */
8933 switch (bf_get(lpfc_cqe_code, &cqevt)) {
8934 case CQE_CODE_COMPL_WQE:
8935 /* Process the WQ/RQ complete event */
8936 workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
8937 (struct lpfc_wcqe_complete *)&cqevt);
8939 case CQE_CODE_RELEASE_WQE:
8940 /* Process the WQ release event */
8941 lpfc_sli4_sp_handle_rel_wcqe(phba,
8942 (struct lpfc_wcqe_release *)&cqevt);
8944 case CQE_CODE_XRI_ABORTED:
8945 /* Process the WQ XRI abort event */
8946 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
8947 (struct sli4_wcqe_xri_aborted *)&cqevt);
8949 case CQE_CODE_RECEIVE:
8950 /* Process the RQ event */
8951 workposted = lpfc_sli4_sp_handle_rcqe(phba,
8952 (struct lpfc_rcqe *)&cqevt);
8955 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8956 "0388 Not a valid WCQE code: x%x\n",
8957 bf_get(lpfc_cqe_code, &cqevt));
8964 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
8965 * @phba: Pointer to HBA context object.
8966 * @eqe: Pointer to fast-path event queue entry.
8968 * This routine process a event queue entry from the slow-path event queue.
8969 * It will check the MajorCode and MinorCode to determine this is for a
8970 * completion event on a completion queue, if not, an error shall be logged
8971 * and just return. Otherwise, it will get to the corresponding completion
8972 * queue and process all the entries on that completion queue, rearm the
8973 * completion queue, and then return.
8977 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
8979 struct lpfc_queue *cq = NULL, *childq, *speq;
8980 struct lpfc_cqe *cqe;
8981 bool workposted = false;
8985 if (bf_get(lpfc_eqe_major_code, eqe) != 0) {
8986 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8987 "0359 Not a valid slow-path completion "
8988 "event: majorcode=x%x, minorcode=x%x\n",
8989 bf_get(lpfc_eqe_major_code, eqe),
8990 bf_get(lpfc_eqe_minor_code, eqe));
8994 /* Get the reference to the corresponding CQ */
8995 cqid = bf_get(lpfc_eqe_resource_id, eqe);
8997 /* Search for completion queue pointer matching this cqid */
8998 speq = phba->sli4_hba.sp_eq;
8999 list_for_each_entry(childq, &speq->child_list, list) {
9000 if (childq->queue_id == cqid) {
9005 if (unlikely(!cq)) {
9006 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9007 "0365 Slow-path CQ identifier (%d) does "
9008 "not exist\n", cqid);
9012 /* Process all the entries to the CQ */
9015 while ((cqe = lpfc_sli4_cq_get(cq))) {
9016 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
9017 if (!(++ecount % LPFC_GET_QE_REL_INT))
9018 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
9022 while ((cqe = lpfc_sli4_cq_get(cq))) {
9023 workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
9024 if (!(++ecount % LPFC_GET_QE_REL_INT))
9025 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
9029 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9030 "0370 Invalid completion queue type (%d)\n",
9035 /* Catch the no cq entry condition, log an error */
9036 if (unlikely(ecount == 0))
9037 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9038 "0371 No entry from the CQ: identifier "
9039 "(x%x), type (%d)\n", cq->queue_id, cq->type);
9041 /* In any case, flash and re-arm the RCQ */
9042 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
9044 /* wake up worker thread if there are works to be done */
9046 lpfc_worker_wake_up(phba);
9050 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
9051 * @eqe: Pointer to fast-path completion queue entry.
9053 * This routine process a fast-path work queue completion entry from fast-path
9054 * event queue for FCP command response completion.
9057 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
9058 struct lpfc_wcqe_complete *wcqe)
9060 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
9061 struct lpfc_iocbq *cmdiocbq;
9062 struct lpfc_iocbq irspiocbq;
9063 unsigned long iflags;
9065 spin_lock_irqsave(&phba->hbalock, iflags);
9066 pring->stats.iocb_event++;
9067 spin_unlock_irqrestore(&phba->hbalock, iflags);
9069 /* Check for response status */
9070 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
9071 /* If resource errors reported from HBA, reduce queue
9072 * depth of the SCSI device.
9074 if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
9075 IOSTAT_LOCAL_REJECT) &&
9076 (wcqe->parameter == IOERR_NO_RESOURCES)) {
9077 phba->lpfc_rampdown_queue_depth(phba);
9079 /* Log the error status */
9080 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9081 "0373 FCP complete error: status=x%x, "
9082 "hw_status=x%x, total_data_specified=%d, "
9083 "parameter=x%x, word3=x%x\n",
9084 bf_get(lpfc_wcqe_c_status, wcqe),
9085 bf_get(lpfc_wcqe_c_hw_status, wcqe),
9086 wcqe->total_data_placed, wcqe->parameter,
9090 /* Look up the FCP command IOCB and create pseudo response IOCB */
9091 spin_lock_irqsave(&phba->hbalock, iflags);
9092 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
9093 bf_get(lpfc_wcqe_c_request_tag, wcqe));
9094 spin_unlock_irqrestore(&phba->hbalock, iflags);
9095 if (unlikely(!cmdiocbq)) {
9096 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9097 "0374 FCP complete with no corresponding "
9098 "cmdiocb: iotag (%d)\n",
9099 bf_get(lpfc_wcqe_c_request_tag, wcqe));
9102 if (unlikely(!cmdiocbq->iocb_cmpl)) {
9103 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9104 "0375 FCP cmdiocb not callback function "
9106 bf_get(lpfc_wcqe_c_request_tag, wcqe));
9110 /* Fake the irspiocb and copy necessary response information */
9111 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
9113 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
9114 spin_lock_irqsave(&phba->hbalock, iflags);
9115 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
9116 spin_unlock_irqrestore(&phba->hbalock, iflags);
9119 /* Pass the cmd_iocb and the rsp state to the upper layer */
9120 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
9124 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
9125 * @phba: Pointer to HBA context object.
9126 * @cq: Pointer to completion queue.
9127 * @wcqe: Pointer to work-queue completion queue entry.
9129 * This routine handles an fast-path WQ entry comsumed event by invoking the
9130 * proper WQ release routine to the slow-path WQ.
9133 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9134 struct lpfc_wcqe_release *wcqe)
9136 struct lpfc_queue *childwq;
9137 bool wqid_matched = false;
9140 /* Check for fast-path FCP work queue release */
9141 fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
9142 list_for_each_entry(childwq, &cq->child_list, list) {
9143 if (childwq->queue_id == fcp_wqid) {
9144 lpfc_sli4_wq_release(childwq,
9145 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
9146 wqid_matched = true;
9150 /* Report warning log message if no match found */
9151 if (wqid_matched != true)
9152 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9153 "2580 Fast-path wqe consume event carries "
9154 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
9158 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
9159 * @cq: Pointer to the completion queue.
9160 * @eqe: Pointer to fast-path completion queue entry.
9162 * This routine process a fast-path work queue completion entry from fast-path
9163 * event queue for FCP command response completion.
9166 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9167 struct lpfc_cqe *cqe)
9169 struct lpfc_wcqe_release wcqe;
9170 bool workposted = false;
9172 /* Copy the work queue CQE and convert endian order if needed */
9173 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
9175 /* Check and process for different type of WCQE and dispatch */
9176 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
9177 case CQE_CODE_COMPL_WQE:
9178 /* Process the WQ complete event */
9179 lpfc_sli4_fp_handle_fcp_wcqe(phba,
9180 (struct lpfc_wcqe_complete *)&wcqe);
9182 case CQE_CODE_RELEASE_WQE:
9183 /* Process the WQ release event */
9184 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
9185 (struct lpfc_wcqe_release *)&wcqe);
9187 case CQE_CODE_XRI_ABORTED:
9188 /* Process the WQ XRI abort event */
9189 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
9190 (struct sli4_wcqe_xri_aborted *)&wcqe);
9193 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9194 "0144 Not a valid WCQE code: x%x\n",
9195 bf_get(lpfc_wcqe_c_code, &wcqe));
9202 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
9203 * @phba: Pointer to HBA context object.
9204 * @eqe: Pointer to fast-path event queue entry.
9206 * This routine process a event queue entry from the fast-path event queue.
9207 * It will check the MajorCode and MinorCode to determine this is for a
9208 * completion event on a completion queue, if not, an error shall be logged
9209 * and just return. Otherwise, it will get to the corresponding completion
9210 * queue and process all the entries on the completion queue, rearm the
9211 * completion queue, and then return.
9214 lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
9217 struct lpfc_queue *cq;
9218 struct lpfc_cqe *cqe;
9219 bool workposted = false;
9223 if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0)) {
9224 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9225 "0366 Not a valid fast-path completion "
9226 "event: majorcode=x%x, minorcode=x%x\n",
9227 bf_get(lpfc_eqe_major_code, eqe),
9228 bf_get(lpfc_eqe_minor_code, eqe));
9232 cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
9233 if (unlikely(!cq)) {
9234 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9235 "0367 Fast-path completion queue does not "
9240 /* Get the reference to the corresponding CQ */
9241 cqid = bf_get(lpfc_eqe_resource_id, eqe);
9242 if (unlikely(cqid != cq->queue_id)) {
9243 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9244 "0368 Miss-matched fast-path completion "
9245 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
9246 cqid, cq->queue_id);
9250 /* Process all the entries to the CQ */
9251 while ((cqe = lpfc_sli4_cq_get(cq))) {
9252 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
9253 if (!(++ecount % LPFC_GET_QE_REL_INT))
9254 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
9257 /* Catch the no cq entry condition */
9258 if (unlikely(ecount == 0))
9259 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9260 "0369 No entry from fast-path completion "
9261 "queue fcpcqid=%d\n", cq->queue_id);
9263 /* In any case, flash and re-arm the CQ */
9264 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
9266 /* wake up worker thread if there are works to be done */
9268 lpfc_worker_wake_up(phba);
9272 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
9274 struct lpfc_eqe *eqe;
9276 /* walk all the EQ entries and drop on the floor */
9277 while ((eqe = lpfc_sli4_eq_get(eq)))
9280 /* Clear and re-arm the EQ */
9281 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
9285 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
9286 * @irq: Interrupt number.
9287 * @dev_id: The device context pointer.
9289 * This function is directly called from the PCI layer as an interrupt
9290 * service routine when device with SLI-4 interface spec is enabled with
9291 * MSI-X multi-message interrupt mode and there are slow-path events in
9292 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9293 * interrupt mode, this function is called as part of the device-level
9294 * interrupt handler. When the PCI slot is in error recovery or the HBA is
9295 * undergoing initialization, the interrupt handler will not process the
9296 * interrupt. The link attention and ELS ring attention events are handled
9297 * by the worker thread. The interrupt handler signals the worker thread
9298 * and returns for these events. This function is called without any lock
9299 * held. It gets the hbalock to access and update SLI data structures.
9301 * This function returns IRQ_HANDLED when interrupt is handled else it
9305 lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
9307 struct lpfc_hba *phba;
9308 struct lpfc_queue *speq;
9309 struct lpfc_eqe *eqe;
9310 unsigned long iflag;
9314 * Get the driver's phba structure from the dev_id
9316 phba = (struct lpfc_hba *)dev_id;
9318 if (unlikely(!phba))
9321 /* Get to the EQ struct associated with this vector */
9322 speq = phba->sli4_hba.sp_eq;
9324 /* Check device state for handling interrupt */
9325 if (unlikely(lpfc_intr_state_check(phba))) {
9326 /* Check again for link_state with lock held */
9327 spin_lock_irqsave(&phba->hbalock, iflag);
9328 if (phba->link_state < LPFC_LINK_DOWN)
9329 /* Flush, clear interrupt, and rearm the EQ */
9330 lpfc_sli4_eq_flush(phba, speq);
9331 spin_unlock_irqrestore(&phba->hbalock, iflag);
9336 * Process all the event on FCP slow-path EQ
9338 while ((eqe = lpfc_sli4_eq_get(speq))) {
9339 lpfc_sli4_sp_handle_eqe(phba, eqe);
9340 if (!(++ecount % LPFC_GET_QE_REL_INT))
9341 lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
9344 /* Always clear and re-arm the slow-path EQ */
9345 lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
9347 /* Catch the no cq entry condition */
9348 if (unlikely(ecount == 0)) {
9349 if (phba->intr_type == MSIX)
9350 /* MSI-X treated interrupt served as no EQ share INT */
9351 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9352 "0357 MSI-X interrupt with no EQE\n");
9354 /* Non MSI-X treated on interrupt as EQ share INT */
9359 } /* lpfc_sli4_sp_intr_handler */
9362 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
9363 * @irq: Interrupt number.
9364 * @dev_id: The device context pointer.
9366 * This function is directly called from the PCI layer as an interrupt
9367 * service routine when device with SLI-4 interface spec is enabled with
9368 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
9369 * ring event in the HBA. However, when the device is enabled with either
9370 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
9371 * device-level interrupt handler. When the PCI slot is in error recovery
9372 * or the HBA is undergoing initialization, the interrupt handler will not
9373 * process the interrupt. The SCSI FCP fast-path ring event are handled in
9374 * the intrrupt context. This function is called without any lock held.
9375 * It gets the hbalock to access and update SLI data structures. Note that,
9376 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
9377 * equal to that of FCP CQ index.
9379 * This function returns IRQ_HANDLED when interrupt is handled else it
9383 lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
9385 struct lpfc_hba *phba;
9386 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
9387 struct lpfc_queue *fpeq;
9388 struct lpfc_eqe *eqe;
9389 unsigned long iflag;
9393 /* Get the driver's phba structure from the dev_id */
9394 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
9395 phba = fcp_eq_hdl->phba;
9396 fcp_eqidx = fcp_eq_hdl->idx;
9398 if (unlikely(!phba))
9401 /* Get to the EQ struct associated with this vector */
9402 fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
9404 /* Check device state for handling interrupt */
9405 if (unlikely(lpfc_intr_state_check(phba))) {
9406 /* Check again for link_state with lock held */
9407 spin_lock_irqsave(&phba->hbalock, iflag);
9408 if (phba->link_state < LPFC_LINK_DOWN)
9409 /* Flush, clear interrupt, and rearm the EQ */
9410 lpfc_sli4_eq_flush(phba, fpeq);
9411 spin_unlock_irqrestore(&phba->hbalock, iflag);
9416 * Process all the event on FCP fast-path EQ
9418 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
9419 lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
9420 if (!(++ecount % LPFC_GET_QE_REL_INT))
9421 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
9424 /* Always clear and re-arm the fast-path EQ */
9425 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
9427 if (unlikely(ecount == 0)) {
9428 if (phba->intr_type == MSIX)
9429 /* MSI-X treated interrupt served as no EQ share INT */
9430 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9431 "0358 MSI-X interrupt with no EQE\n");
9433 /* Non MSI-X treated on interrupt as EQ share INT */
9438 } /* lpfc_sli4_fp_intr_handler */
9441 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
9442 * @irq: Interrupt number.
9443 * @dev_id: The device context pointer.
9445 * This function is the device-level interrupt handler to device with SLI-4
9446 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
9447 * interrupt mode is enabled and there is an event in the HBA which requires
9448 * driver attention. This function invokes the slow-path interrupt attention
9449 * handling function and fast-path interrupt attention handling function in
9450 * turn to process the relevant HBA attention events. This function is called
9451 * without any lock held. It gets the hbalock to access and update SLI data
9454 * This function returns IRQ_HANDLED when interrupt is handled, else it
9458 lpfc_sli4_intr_handler(int irq, void *dev_id)
9460 struct lpfc_hba *phba;
9461 irqreturn_t sp_irq_rc, fp_irq_rc;
9462 bool fp_handled = false;
9465 /* Get the driver's phba structure from the dev_id */
9466 phba = (struct lpfc_hba *)dev_id;
9468 if (unlikely(!phba))
9472 * Invokes slow-path host attention interrupt handling as appropriate.
9474 sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
9477 * Invoke fast-path host attention interrupt handling as appropriate.
9479 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
9480 fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
9481 &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
9482 if (fp_irq_rc == IRQ_HANDLED)
9486 return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
9487 } /* lpfc_sli4_intr_handler */
9490 * lpfc_sli4_queue_free - free a queue structure and associated memory
9491 * @queue: The queue structure to free.
9493 * This function frees a queue structure and the DMAable memeory used for
9494 * the host resident queue. This function must be called after destroying the
9498 lpfc_sli4_queue_free(struct lpfc_queue *queue)
9500 struct lpfc_dmabuf *dmabuf;
9505 while (!list_empty(&queue->page_list)) {
9506 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
9508 dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
9509 dmabuf->virt, dmabuf->phys);
9517 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
9518 * @phba: The HBA that this queue is being created on.
9519 * @entry_size: The size of each queue entry for this queue.
9520 * @entry count: The number of entries that this queue will handle.
9522 * This function allocates a queue structure and the DMAable memory used for
9523 * the host resident queue. This function must be called before creating the
9527 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
9528 uint32_t entry_count)
9530 struct lpfc_queue *queue;
9531 struct lpfc_dmabuf *dmabuf;
9532 int x, total_qe_count;
9536 queue = kzalloc(sizeof(struct lpfc_queue) +
9537 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
9540 queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
9541 INIT_LIST_HEAD(&queue->list);
9542 INIT_LIST_HEAD(&queue->page_list);
9543 INIT_LIST_HEAD(&queue->child_list);
9544 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
9545 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9548 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9549 PAGE_SIZE, &dmabuf->phys,
9551 if (!dmabuf->virt) {
9555 memset(dmabuf->virt, 0, PAGE_SIZE);
9556 dmabuf->buffer_tag = x;
9557 list_add_tail(&dmabuf->list, &queue->page_list);
9558 /* initialize queue's entry array */
9559 dma_pointer = dmabuf->virt;
9560 for (; total_qe_count < entry_count &&
9561 dma_pointer < (PAGE_SIZE + dmabuf->virt);
9562 total_qe_count++, dma_pointer += entry_size) {
9563 queue->qe[total_qe_count].address = dma_pointer;
9566 queue->entry_size = entry_size;
9567 queue->entry_count = entry_count;
9572 lpfc_sli4_queue_free(queue);
9577 * lpfc_eq_create - Create an Event Queue on the HBA
9578 * @phba: HBA structure that indicates port to create a queue on.
9579 * @eq: The queue structure to use to create the event queue.
9580 * @imax: The maximum interrupt per second limit.
9582 * This function creates an event queue, as detailed in @eq, on a port,
9583 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
9585 * The @phba struct is used to send mailbox command to HBA. The @eq struct
9586 * is used to get the entry count and entry size that are necessary to
9587 * determine the number of pages to allocate and use for this queue. This
9588 * function will send the EQ_CREATE mailbox command to the HBA to setup the
9589 * event queue. This function is asynchronous and will wait for the mailbox
9590 * command to finish before continuing.
9592 * On success this function will return a zero. If unable to allocate enough
9593 * memory this function will return ENOMEM. If the queue create mailbox command
9594 * fails this function will return ENXIO.
9597 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
9599 struct lpfc_mbx_eq_create *eq_create;
9601 int rc, length, status = 0;
9602 struct lpfc_dmabuf *dmabuf;
9603 uint32_t shdr_status, shdr_add_status;
9604 union lpfc_sli4_cfg_shdr *shdr;
9607 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9610 length = (sizeof(struct lpfc_mbx_eq_create) -
9611 sizeof(struct lpfc_sli4_cfg_mhdr));
9612 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9613 LPFC_MBOX_OPCODE_EQ_CREATE,
9614 length, LPFC_SLI4_MBX_EMBED);
9615 eq_create = &mbox->u.mqe.un.eq_create;
9616 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
9618 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
9620 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
9621 /* Calculate delay multiper from maximum interrupt per second */
9622 dmult = LPFC_DMULT_CONST/imax - 1;
9623 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
9625 switch (eq->entry_count) {
9627 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9628 "0360 Unsupported EQ count. (%d)\n",
9630 if (eq->entry_count < 256)
9632 /* otherwise default to smallest count (drop through) */
9634 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9638 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9642 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9646 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9650 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9654 list_for_each_entry(dmabuf, &eq->page_list, list) {
9655 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9656 putPaddrLow(dmabuf->phys);
9657 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9658 putPaddrHigh(dmabuf->phys);
9660 mbox->vport = phba->pport;
9661 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9662 mbox->context1 = NULL;
9663 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9664 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
9665 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9666 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9667 if (shdr_status || shdr_add_status || rc) {
9668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9669 "2500 EQ_CREATE mailbox failed with "
9670 "status x%x add_status x%x, mbx status x%x\n",
9671 shdr_status, shdr_add_status, rc);
9675 eq->subtype = LPFC_NONE;
9676 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
9677 if (eq->queue_id == 0xFFFF)
9682 mempool_free(mbox, phba->mbox_mem_pool);
9687 * lpfc_cq_create - Create a Completion Queue on the HBA
9688 * @phba: HBA structure that indicates port to create a queue on.
9689 * @cq: The queue structure to use to create the completion queue.
9690 * @eq: The event queue to bind this completion queue to.
9692 * This function creates a completion queue, as detailed in @wq, on a port,
9693 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
9695 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9696 * is used to get the entry count and entry size that are necessary to
9697 * determine the number of pages to allocate and use for this queue. The @eq
9698 * is used to indicate which event queue to bind this completion queue to. This
9699 * function will send the CQ_CREATE mailbox command to the HBA to setup the
9700 * completion queue. This function is asynchronous and will wait for the mailbox
9701 * command to finish before continuing.
9703 * On success this function will return a zero. If unable to allocate enough
9704 * memory this function will return ENOMEM. If the queue create mailbox command
9705 * fails this function will return ENXIO.
9708 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
9709 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
9711 struct lpfc_mbx_cq_create *cq_create;
9712 struct lpfc_dmabuf *dmabuf;
9714 int rc, length, status = 0;
9715 uint32_t shdr_status, shdr_add_status;
9716 union lpfc_sli4_cfg_shdr *shdr;
9718 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9721 length = (sizeof(struct lpfc_mbx_cq_create) -
9722 sizeof(struct lpfc_sli4_cfg_mhdr));
9723 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9724 LPFC_MBOX_OPCODE_CQ_CREATE,
9725 length, LPFC_SLI4_MBX_EMBED);
9726 cq_create = &mbox->u.mqe.un.cq_create;
9727 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
9729 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
9730 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
9731 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
9732 switch (cq->entry_count) {
9734 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9735 "0361 Unsupported CQ count. (%d)\n",
9737 if (cq->entry_count < 256)
9739 /* otherwise default to smallest count (drop through) */
9741 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9745 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9749 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9753 list_for_each_entry(dmabuf, &cq->page_list, list) {
9754 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9755 putPaddrLow(dmabuf->phys);
9756 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9757 putPaddrHigh(dmabuf->phys);
9759 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9761 /* The IOCTL status is embedded in the mailbox subheader. */
9762 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
9763 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9764 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9765 if (shdr_status || shdr_add_status || rc) {
9766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9767 "2501 CQ_CREATE mailbox failed with "
9768 "status x%x add_status x%x, mbx status x%x\n",
9769 shdr_status, shdr_add_status, rc);
9773 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
9774 if (cq->queue_id == 0xFFFF) {
9778 /* link the cq onto the parent eq child list */
9779 list_add_tail(&cq->list, &eq->child_list);
9780 /* Set up completion queue's type and subtype */
9782 cq->subtype = subtype;
9783 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
9788 mempool_free(mbox, phba->mbox_mem_pool);
9793 * lpfc_mq_create - Create a mailbox Queue on the HBA
9794 * @phba: HBA structure that indicates port to create a queue on.
9795 * @mq: The queue structure to use to create the mailbox queue.
9797 * This function creates a mailbox queue, as detailed in @mq, on a port,
9798 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
9800 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9801 * is used to get the entry count and entry size that are necessary to
9802 * determine the number of pages to allocate and use for this queue. This
9803 * function will send the MQ_CREATE mailbox command to the HBA to setup the
9804 * mailbox queue. This function is asynchronous and will wait for the mailbox
9805 * command to finish before continuing.
9807 * On success this function will return a zero. If unable to allocate enough
9808 * memory this function will return ENOMEM. If the queue create mailbox command
9809 * fails this function will return ENXIO.
9812 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
9813 struct lpfc_queue *cq, uint32_t subtype)
9815 struct lpfc_mbx_mq_create *mq_create;
9816 struct lpfc_dmabuf *dmabuf;
9818 int rc, length, status = 0;
9819 uint32_t shdr_status, shdr_add_status;
9820 union lpfc_sli4_cfg_shdr *shdr;
9822 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9825 length = (sizeof(struct lpfc_mbx_mq_create) -
9826 sizeof(struct lpfc_sli4_cfg_mhdr));
9827 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9828 LPFC_MBOX_OPCODE_MQ_CREATE,
9829 length, LPFC_SLI4_MBX_EMBED);
9830 mq_create = &mbox->u.mqe.un.mq_create;
9831 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
9833 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
9835 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
9836 switch (mq->entry_count) {
9838 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9839 "0362 Unsupported MQ count. (%d)\n",
9841 if (mq->entry_count < 16)
9843 /* otherwise default to smallest count (drop through) */
9845 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9849 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9853 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9857 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9861 list_for_each_entry(dmabuf, &mq->page_list, list) {
9862 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9863 putPaddrLow(dmabuf->phys);
9864 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9865 putPaddrHigh(dmabuf->phys);
9867 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9868 /* The IOCTL status is embedded in the mailbox subheader. */
9869 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
9870 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9871 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9872 if (shdr_status || shdr_add_status || rc) {
9873 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9874 "2502 MQ_CREATE mailbox failed with "
9875 "status x%x add_status x%x, mbx status x%x\n",
9876 shdr_status, shdr_add_status, rc);
9880 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
9881 if (mq->queue_id == 0xFFFF) {
9886 mq->subtype = subtype;
9890 /* link the mq onto the parent cq child list */
9891 list_add_tail(&mq->list, &cq->child_list);
9893 mempool_free(mbox, phba->mbox_mem_pool);
9898 * lpfc_wq_create - Create a Work Queue on the HBA
9899 * @phba: HBA structure that indicates port to create a queue on.
9900 * @wq: The queue structure to use to create the work queue.
9901 * @cq: The completion queue to bind this work queue to.
9902 * @subtype: The subtype of the work queue indicating its functionality.
9904 * This function creates a work queue, as detailed in @wq, on a port, described
9905 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
9907 * The @phba struct is used to send mailbox command to HBA. The @wq struct
9908 * is used to get the entry count and entry size that are necessary to
9909 * determine the number of pages to allocate and use for this queue. The @cq
9910 * is used to indicate which completion queue to bind this work queue to. This
9911 * function will send the WQ_CREATE mailbox command to the HBA to setup the
9912 * work queue. This function is asynchronous and will wait for the mailbox
9913 * command to finish before continuing.
9915 * On success this function will return a zero. If unable to allocate enough
9916 * memory this function will return ENOMEM. If the queue create mailbox command
9917 * fails this function will return ENXIO.
9920 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
9921 struct lpfc_queue *cq, uint32_t subtype)
9923 struct lpfc_mbx_wq_create *wq_create;
9924 struct lpfc_dmabuf *dmabuf;
9926 int rc, length, status = 0;
9927 uint32_t shdr_status, shdr_add_status;
9928 union lpfc_sli4_cfg_shdr *shdr;
9930 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9933 length = (sizeof(struct lpfc_mbx_wq_create) -
9934 sizeof(struct lpfc_sli4_cfg_mhdr));
9935 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9936 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
9937 length, LPFC_SLI4_MBX_EMBED);
9938 wq_create = &mbox->u.mqe.un.wq_create;
9939 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
9941 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
9943 list_for_each_entry(dmabuf, &wq->page_list, list) {
9944 wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9945 putPaddrLow(dmabuf->phys);
9946 wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9947 putPaddrHigh(dmabuf->phys);
9949 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9950 /* The IOCTL status is embedded in the mailbox subheader. */
9951 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
9952 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9953 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9954 if (shdr_status || shdr_add_status || rc) {
9955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9956 "2503 WQ_CREATE mailbox failed with "
9957 "status x%x add_status x%x, mbx status x%x\n",
9958 shdr_status, shdr_add_status, rc);
9962 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
9963 if (wq->queue_id == 0xFFFF) {
9968 wq->subtype = subtype;
9972 /* link the wq onto the parent cq child list */
9973 list_add_tail(&wq->list, &cq->child_list);
9975 mempool_free(mbox, phba->mbox_mem_pool);
9980 * lpfc_rq_create - Create a Receive Queue on the HBA
9981 * @phba: HBA structure that indicates port to create a queue on.
9982 * @hrq: The queue structure to use to create the header receive queue.
9983 * @drq: The queue structure to use to create the data receive queue.
9984 * @cq: The completion queue to bind this work queue to.
9986 * This function creates a receive buffer queue pair , as detailed in @hrq and
9987 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
9990 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
9991 * struct is used to get the entry count that is necessary to determine the
9992 * number of pages to use for this queue. The @cq is used to indicate which
9993 * completion queue to bind received buffers that are posted to these queues to.
9994 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
9995 * receive queue pair. This function is asynchronous and will wait for the
9996 * mailbox command to finish before continuing.
9998 * On success this function will return a zero. If unable to allocate enough
9999 * memory this function will return ENOMEM. If the queue create mailbox command
10000 * fails this function will return ENXIO.
10003 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
10004 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
10006 struct lpfc_mbx_rq_create *rq_create;
10007 struct lpfc_dmabuf *dmabuf;
10008 LPFC_MBOXQ_t *mbox;
10009 int rc, length, status = 0;
10010 uint32_t shdr_status, shdr_add_status;
10011 union lpfc_sli4_cfg_shdr *shdr;
10013 if (hrq->entry_count != drq->entry_count)
10015 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10018 length = (sizeof(struct lpfc_mbx_rq_create) -
10019 sizeof(struct lpfc_sli4_cfg_mhdr));
10020 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10021 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
10022 length, LPFC_SLI4_MBX_EMBED);
10023 rq_create = &mbox->u.mqe.un.rq_create;
10024 switch (hrq->entry_count) {
10026 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10027 "2535 Unsupported RQ count. (%d)\n",
10029 if (hrq->entry_count < 512)
10031 /* otherwise default to smallest count (drop through) */
10033 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10034 LPFC_RQ_RING_SIZE_512);
10037 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10038 LPFC_RQ_RING_SIZE_1024);
10041 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10042 LPFC_RQ_RING_SIZE_2048);
10045 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10046 LPFC_RQ_RING_SIZE_4096);
10049 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
10051 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
10053 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
10054 LPFC_HDR_BUF_SIZE);
10055 list_for_each_entry(dmabuf, &hrq->page_list, list) {
10056 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
10057 putPaddrLow(dmabuf->phys);
10058 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
10059 putPaddrHigh(dmabuf->phys);
10061 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10062 /* The IOCTL status is embedded in the mailbox subheader. */
10063 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
10064 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10065 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10066 if (shdr_status || shdr_add_status || rc) {
10067 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10068 "2504 RQ_CREATE mailbox failed with "
10069 "status x%x add_status x%x, mbx status x%x\n",
10070 shdr_status, shdr_add_status, rc);
10074 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
10075 if (hrq->queue_id == 0xFFFF) {
10079 hrq->type = LPFC_HRQ;
10080 hrq->subtype = subtype;
10081 hrq->host_index = 0;
10082 hrq->hba_index = 0;
10084 /* now create the data queue */
10085 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10086 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
10087 length, LPFC_SLI4_MBX_EMBED);
10088 switch (drq->entry_count) {
10090 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10091 "2536 Unsupported RQ count. (%d)\n",
10093 if (drq->entry_count < 512)
10095 /* otherwise default to smallest count (drop through) */
10097 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10098 LPFC_RQ_RING_SIZE_512);
10101 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10102 LPFC_RQ_RING_SIZE_1024);
10105 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10106 LPFC_RQ_RING_SIZE_2048);
10109 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
10110 LPFC_RQ_RING_SIZE_4096);
10113 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
10115 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
10117 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
10118 LPFC_DATA_BUF_SIZE);
10119 list_for_each_entry(dmabuf, &drq->page_list, list) {
10120 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
10121 putPaddrLow(dmabuf->phys);
10122 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
10123 putPaddrHigh(dmabuf->phys);
10125 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10126 /* The IOCTL status is embedded in the mailbox subheader. */
10127 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
10128 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10129 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10130 if (shdr_status || shdr_add_status || rc) {
10134 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
10135 if (drq->queue_id == 0xFFFF) {
10139 drq->type = LPFC_DRQ;
10140 drq->subtype = subtype;
10141 drq->host_index = 0;
10142 drq->hba_index = 0;
10144 /* link the header and data RQs onto the parent cq child list */
10145 list_add_tail(&hrq->list, &cq->child_list);
10146 list_add_tail(&drq->list, &cq->child_list);
10149 mempool_free(mbox, phba->mbox_mem_pool);
10154 * lpfc_eq_destroy - Destroy an event Queue on the HBA
10155 * @eq: The queue structure associated with the queue to destroy.
10157 * This function destroys a queue, as detailed in @eq by sending an mailbox
10158 * command, specific to the type of queue, to the HBA.
10160 * The @eq struct is used to get the queue ID of the queue to destroy.
10162 * On success this function will return a zero. If the queue destroy mailbox
10163 * command fails this function will return ENXIO.
10166 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
10168 LPFC_MBOXQ_t *mbox;
10169 int rc, length, status = 0;
10170 uint32_t shdr_status, shdr_add_status;
10171 union lpfc_sli4_cfg_shdr *shdr;
10175 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
10178 length = (sizeof(struct lpfc_mbx_eq_destroy) -
10179 sizeof(struct lpfc_sli4_cfg_mhdr));
10180 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
10181 LPFC_MBOX_OPCODE_EQ_DESTROY,
10182 length, LPFC_SLI4_MBX_EMBED);
10183 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
10185 mbox->vport = eq->phba->pport;
10186 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10188 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
10189 /* The IOCTL status is embedded in the mailbox subheader. */
10190 shdr = (union lpfc_sli4_cfg_shdr *)
10191 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
10192 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10193 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10194 if (shdr_status || shdr_add_status || rc) {
10195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10196 "2505 EQ_DESTROY mailbox failed with "
10197 "status x%x add_status x%x, mbx status x%x\n",
10198 shdr_status, shdr_add_status, rc);
10202 /* Remove eq from any list */
10203 list_del_init(&eq->list);
10204 mempool_free(mbox, eq->phba->mbox_mem_pool);
10209 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
10210 * @cq: The queue structure associated with the queue to destroy.
10212 * This function destroys a queue, as detailed in @cq by sending an mailbox
10213 * command, specific to the type of queue, to the HBA.
10215 * The @cq struct is used to get the queue ID of the queue to destroy.
10217 * On success this function will return a zero. If the queue destroy mailbox
10218 * command fails this function will return ENXIO.
10221 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
10223 LPFC_MBOXQ_t *mbox;
10224 int rc, length, status = 0;
10225 uint32_t shdr_status, shdr_add_status;
10226 union lpfc_sli4_cfg_shdr *shdr;
10230 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
10233 length = (sizeof(struct lpfc_mbx_cq_destroy) -
10234 sizeof(struct lpfc_sli4_cfg_mhdr));
10235 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
10236 LPFC_MBOX_OPCODE_CQ_DESTROY,
10237 length, LPFC_SLI4_MBX_EMBED);
10238 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
10240 mbox->vport = cq->phba->pport;
10241 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10242 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
10243 /* The IOCTL status is embedded in the mailbox subheader. */
10244 shdr = (union lpfc_sli4_cfg_shdr *)
10245 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
10246 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10247 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10248 if (shdr_status || shdr_add_status || rc) {
10249 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10250 "2506 CQ_DESTROY mailbox failed with "
10251 "status x%x add_status x%x, mbx status x%x\n",
10252 shdr_status, shdr_add_status, rc);
10255 /* Remove cq from any list */
10256 list_del_init(&cq->list);
10257 mempool_free(mbox, cq->phba->mbox_mem_pool);
10262 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
10263 * @qm: The queue structure associated with the queue to destroy.
10265 * This function destroys a queue, as detailed in @mq by sending an mailbox
10266 * command, specific to the type of queue, to the HBA.
10268 * The @mq struct is used to get the queue ID of the queue to destroy.
10270 * On success this function will return a zero. If the queue destroy mailbox
10271 * command fails this function will return ENXIO.
10274 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
10276 LPFC_MBOXQ_t *mbox;
10277 int rc, length, status = 0;
10278 uint32_t shdr_status, shdr_add_status;
10279 union lpfc_sli4_cfg_shdr *shdr;
10283 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
10286 length = (sizeof(struct lpfc_mbx_mq_destroy) -
10287 sizeof(struct lpfc_sli4_cfg_mhdr));
10288 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
10289 LPFC_MBOX_OPCODE_MQ_DESTROY,
10290 length, LPFC_SLI4_MBX_EMBED);
10291 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
10293 mbox->vport = mq->phba->pport;
10294 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10295 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
10296 /* The IOCTL status is embedded in the mailbox subheader. */
10297 shdr = (union lpfc_sli4_cfg_shdr *)
10298 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
10299 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10300 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10301 if (shdr_status || shdr_add_status || rc) {
10302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10303 "2507 MQ_DESTROY mailbox failed with "
10304 "status x%x add_status x%x, mbx status x%x\n",
10305 shdr_status, shdr_add_status, rc);
10308 /* Remove mq from any list */
10309 list_del_init(&mq->list);
10310 mempool_free(mbox, mq->phba->mbox_mem_pool);
10315 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
10316 * @wq: The queue structure associated with the queue to destroy.
10318 * This function destroys a queue, as detailed in @wq by sending an mailbox
10319 * command, specific to the type of queue, to the HBA.
10321 * The @wq struct is used to get the queue ID of the queue to destroy.
10323 * On success this function will return a zero. If the queue destroy mailbox
10324 * command fails this function will return ENXIO.
10327 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
10329 LPFC_MBOXQ_t *mbox;
10330 int rc, length, status = 0;
10331 uint32_t shdr_status, shdr_add_status;
10332 union lpfc_sli4_cfg_shdr *shdr;
10336 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
10339 length = (sizeof(struct lpfc_mbx_wq_destroy) -
10340 sizeof(struct lpfc_sli4_cfg_mhdr));
10341 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10342 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
10343 length, LPFC_SLI4_MBX_EMBED);
10344 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
10346 mbox->vport = wq->phba->pport;
10347 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10348 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
10349 shdr = (union lpfc_sli4_cfg_shdr *)
10350 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
10351 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10352 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10353 if (shdr_status || shdr_add_status || rc) {
10354 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10355 "2508 WQ_DESTROY mailbox failed with "
10356 "status x%x add_status x%x, mbx status x%x\n",
10357 shdr_status, shdr_add_status, rc);
10360 /* Remove wq from any list */
10361 list_del_init(&wq->list);
10362 mempool_free(mbox, wq->phba->mbox_mem_pool);
10367 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
10368 * @rq: The queue structure associated with the queue to destroy.
10370 * This function destroys a queue, as detailed in @rq by sending an mailbox
10371 * command, specific to the type of queue, to the HBA.
10373 * The @rq struct is used to get the queue ID of the queue to destroy.
10375 * On success this function will return a zero. If the queue destroy mailbox
10376 * command fails this function will return ENXIO.
10379 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
10380 struct lpfc_queue *drq)
10382 LPFC_MBOXQ_t *mbox;
10383 int rc, length, status = 0;
10384 uint32_t shdr_status, shdr_add_status;
10385 union lpfc_sli4_cfg_shdr *shdr;
10389 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
10392 length = (sizeof(struct lpfc_mbx_rq_destroy) -
10393 sizeof(struct mbox_header));
10394 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10395 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
10396 length, LPFC_SLI4_MBX_EMBED);
10397 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
10399 mbox->vport = hrq->phba->pport;
10400 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10401 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
10402 /* The IOCTL status is embedded in the mailbox subheader. */
10403 shdr = (union lpfc_sli4_cfg_shdr *)
10404 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
10405 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10406 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10407 if (shdr_status || shdr_add_status || rc) {
10408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10409 "2509 RQ_DESTROY mailbox failed with "
10410 "status x%x add_status x%x, mbx status x%x\n",
10411 shdr_status, shdr_add_status, rc);
10412 if (rc != MBX_TIMEOUT)
10413 mempool_free(mbox, hrq->phba->mbox_mem_pool);
10416 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
10418 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
10419 shdr = (union lpfc_sli4_cfg_shdr *)
10420 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
10421 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10422 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10423 if (shdr_status || shdr_add_status || rc) {
10424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10425 "2510 RQ_DESTROY mailbox failed with "
10426 "status x%x add_status x%x, mbx status x%x\n",
10427 shdr_status, shdr_add_status, rc);
10430 list_del_init(&hrq->list);
10431 list_del_init(&drq->list);
10432 mempool_free(mbox, hrq->phba->mbox_mem_pool);
10437 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
10438 * @phba: The virtual port for which this call being executed.
10439 * @pdma_phys_addr0: Physical address of the 1st SGL page.
10440 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
10441 * @xritag: the xritag that ties this io to the SGL pages.
10443 * This routine will post the sgl pages for the IO that has the xritag
10444 * that is in the iocbq structure. The xritag is assigned during iocbq
10445 * creation and persists for as long as the driver is loaded.
10446 * if the caller has fewer than 256 scatter gather segments to map then
10447 * pdma_phys_addr1 should be 0.
10448 * If the caller needs to map more than 256 scatter gather segment then
10449 * pdma_phys_addr1 should be a valid physical address.
10450 * physical address for SGLs must be 64 byte aligned.
10451 * If you are going to map 2 SGL's then the first one must have 256 entries
10452 * the second sgl can have between 1 and 256 entries.
10456 * -ENXIO, -ENOMEM - Failure
10459 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
10460 dma_addr_t pdma_phys_addr0,
10461 dma_addr_t pdma_phys_addr1,
10464 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
10465 LPFC_MBOXQ_t *mbox;
10467 uint32_t shdr_status, shdr_add_status;
10468 union lpfc_sli4_cfg_shdr *shdr;
10470 if (xritag == NO_XRI) {
10471 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10472 "0364 Invalid param:\n");
10476 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10480 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10481 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
10482 sizeof(struct lpfc_mbx_post_sgl_pages) -
10483 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
10485 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
10486 &mbox->u.mqe.un.post_sgl_pages;
10487 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
10488 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
10490 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
10491 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
10492 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
10493 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
10495 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
10496 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
10497 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
10498 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
10499 if (!phba->sli4_hba.intr_enable)
10500 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10502 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
10503 /* The IOCTL status is embedded in the mailbox subheader. */
10504 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
10505 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10506 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10507 if (rc != MBX_TIMEOUT)
10508 mempool_free(mbox, phba->mbox_mem_pool);
10509 if (shdr_status || shdr_add_status || rc) {
10510 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10511 "2511 POST_SGL mailbox failed with "
10512 "status x%x add_status x%x, mbx status x%x\n",
10513 shdr_status, shdr_add_status, rc);
10519 * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
10520 * @phba: The virtual port for which this call being executed.
10522 * This routine will remove all of the sgl pages registered with the hba.
10526 * -ENXIO, -ENOMEM - Failure
10529 lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
10531 LPFC_MBOXQ_t *mbox;
10533 uint32_t shdr_status, shdr_add_status;
10534 union lpfc_sli4_cfg_shdr *shdr;
10536 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10540 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10541 LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
10542 LPFC_SLI4_MBX_EMBED);
10543 if (!phba->sli4_hba.intr_enable)
10544 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10546 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
10547 /* The IOCTL status is embedded in the mailbox subheader. */
10548 shdr = (union lpfc_sli4_cfg_shdr *)
10549 &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
10550 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10551 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10552 if (rc != MBX_TIMEOUT)
10553 mempool_free(mbox, phba->mbox_mem_pool);
10554 if (shdr_status || shdr_add_status || rc) {
10555 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10556 "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
10557 "status x%x add_status x%x, mbx status x%x\n",
10558 shdr_status, shdr_add_status, rc);
10565 * lpfc_sli4_next_xritag - Get an xritag for the io
10566 * @phba: Pointer to HBA context object.
10568 * This function gets an xritag for the iocb. If there is no unused xritag
10569 * it will return 0xffff.
10570 * The function returns the allocated xritag if successful, else returns zero.
10571 * Zero is not a valid xritag.
10572 * The caller is not required to hold any lock.
10575 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
10579 spin_lock_irq(&phba->hbalock);
10580 xritag = phba->sli4_hba.next_xri;
10581 if ((xritag != (uint16_t) -1) && xritag <
10582 (phba->sli4_hba.max_cfg_param.max_xri
10583 + phba->sli4_hba.max_cfg_param.xri_base)) {
10584 phba->sli4_hba.next_xri++;
10585 phba->sli4_hba.max_cfg_param.xri_used++;
10586 spin_unlock_irq(&phba->hbalock);
10589 spin_unlock_irq(&phba->hbalock);
10590 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10591 "2004 Failed to allocate XRI.last XRITAG is %d"
10592 " Max XRI is %d, Used XRI is %d\n",
10593 phba->sli4_hba.next_xri,
10594 phba->sli4_hba.max_cfg_param.max_xri,
10595 phba->sli4_hba.max_cfg_param.xri_used);
10600 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
10601 * @phba: pointer to lpfc hba data structure.
10603 * This routine is invoked to post a block of driver's sgl pages to the
10604 * HBA using non-embedded mailbox command. No Lock is held. This routine
10605 * is only called when the driver is loading and after all IO has been
10609 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
10611 struct lpfc_sglq *sglq_entry;
10612 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
10613 struct sgl_page_pairs *sgl_pg_pairs;
10615 LPFC_MBOXQ_t *mbox;
10616 uint32_t reqlen, alloclen, pg_pairs;
10618 uint16_t xritag_start = 0;
10619 int els_xri_cnt, rc = 0;
10620 uint32_t shdr_status, shdr_add_status;
10621 union lpfc_sli4_cfg_shdr *shdr;
10623 /* The number of sgls to be posted */
10624 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
10626 reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
10627 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
10628 if (reqlen > PAGE_SIZE) {
10629 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10630 "2559 Block sgl registration required DMA "
10631 "size (%d) great than a page\n", reqlen);
10634 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10636 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10637 "2560 Failed to allocate mbox cmd memory\n");
10641 /* Allocate DMA memory and set up the non-embedded mailbox command */
10642 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10643 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
10644 LPFC_SLI4_MBX_NEMBED);
10646 if (alloclen < reqlen) {
10647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10648 "0285 Allocated DMA memory size (%d) is "
10649 "less than the requested DMA memory "
10650 "size (%d)\n", alloclen, reqlen);
10651 lpfc_sli4_mbox_cmd_free(phba, mbox);
10654 /* Get the first SGE entry from the non-embedded DMA memory */
10655 viraddr = mbox->sge_array->addr[0];
10657 /* Set up the SGL pages in the non-embedded DMA pages */
10658 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
10659 sgl_pg_pairs = &sgl->sgl_pg_pairs;
10661 for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
10662 sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
10663 /* Set up the sge entry */
10664 sgl_pg_pairs->sgl_pg0_addr_lo =
10665 cpu_to_le32(putPaddrLow(sglq_entry->phys));
10666 sgl_pg_pairs->sgl_pg0_addr_hi =
10667 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
10668 sgl_pg_pairs->sgl_pg1_addr_lo =
10669 cpu_to_le32(putPaddrLow(0));
10670 sgl_pg_pairs->sgl_pg1_addr_hi =
10671 cpu_to_le32(putPaddrHigh(0));
10672 /* Keep the first xritag on the list */
10674 xritag_start = sglq_entry->sli4_xritag;
10677 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
10678 bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
10679 /* Perform endian conversion if necessary */
10680 sgl->word0 = cpu_to_le32(sgl->word0);
10682 if (!phba->sli4_hba.intr_enable)
10683 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10685 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
10686 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
10688 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
10689 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10690 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10691 if (rc != MBX_TIMEOUT)
10692 lpfc_sli4_mbox_cmd_free(phba, mbox);
10693 if (shdr_status || shdr_add_status || rc) {
10694 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10695 "2513 POST_SGL_BLOCK mailbox command failed "
10696 "status x%x add_status x%x mbx status x%x\n",
10697 shdr_status, shdr_add_status, rc);
10704 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
10705 * @phba: pointer to lpfc hba data structure.
10706 * @sblist: pointer to scsi buffer list.
10707 * @count: number of scsi buffers on the list.
10709 * This routine is invoked to post a block of @count scsi sgl pages from a
10710 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
10715 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
10718 struct lpfc_scsi_buf *psb;
10719 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
10720 struct sgl_page_pairs *sgl_pg_pairs;
10722 LPFC_MBOXQ_t *mbox;
10723 uint32_t reqlen, alloclen, pg_pairs;
10725 uint16_t xritag_start = 0;
10727 uint32_t shdr_status, shdr_add_status;
10728 dma_addr_t pdma_phys_bpl1;
10729 union lpfc_sli4_cfg_shdr *shdr;
10731 /* Calculate the requested length of the dma memory */
10732 reqlen = cnt * sizeof(struct sgl_page_pairs) +
10733 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
10734 if (reqlen > PAGE_SIZE) {
10735 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10736 "0217 Block sgl registration required DMA "
10737 "size (%d) great than a page\n", reqlen);
10740 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10743 "0283 Failed to allocate mbox cmd memory\n");
10747 /* Allocate DMA memory and set up the non-embedded mailbox command */
10748 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10749 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
10750 LPFC_SLI4_MBX_NEMBED);
10752 if (alloclen < reqlen) {
10753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10754 "2561 Allocated DMA memory size (%d) is "
10755 "less than the requested DMA memory "
10756 "size (%d)\n", alloclen, reqlen);
10757 lpfc_sli4_mbox_cmd_free(phba, mbox);
10760 /* Get the first SGE entry from the non-embedded DMA memory */
10761 viraddr = mbox->sge_array->addr[0];
10763 /* Set up the SGL pages in the non-embedded DMA pages */
10764 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
10765 sgl_pg_pairs = &sgl->sgl_pg_pairs;
10768 list_for_each_entry(psb, sblist, list) {
10769 /* Set up the sge entry */
10770 sgl_pg_pairs->sgl_pg0_addr_lo =
10771 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
10772 sgl_pg_pairs->sgl_pg0_addr_hi =
10773 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
10774 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
10775 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
10777 pdma_phys_bpl1 = 0;
10778 sgl_pg_pairs->sgl_pg1_addr_lo =
10779 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
10780 sgl_pg_pairs->sgl_pg1_addr_hi =
10781 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
10782 /* Keep the first xritag on the list */
10784 xritag_start = psb->cur_iocbq.sli4_xritag;
10788 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
10789 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
10790 /* Perform endian conversion if necessary */
10791 sgl->word0 = cpu_to_le32(sgl->word0);
10793 if (!phba->sli4_hba.intr_enable)
10794 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10796 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
10797 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
10799 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
10800 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10801 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10802 if (rc != MBX_TIMEOUT)
10803 lpfc_sli4_mbox_cmd_free(phba, mbox);
10804 if (shdr_status || shdr_add_status || rc) {
10805 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10806 "2564 POST_SGL_BLOCK mailbox command failed "
10807 "status x%x add_status x%x mbx status x%x\n",
10808 shdr_status, shdr_add_status, rc);
10815 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
10816 * @phba: pointer to lpfc_hba struct that the frame was received on
10817 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10819 * This function checks the fields in the @fc_hdr to see if the FC frame is a
10820 * valid type of frame that the LPFC driver will handle. This function will
10821 * return a zero if the frame is a valid frame or a non zero value when the
10822 * frame does not pass the check.
10825 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
10827 char *rctl_names[] = FC_RCTL_NAMES_INIT;
10828 char *type_names[] = FC_TYPE_NAMES_INIT;
10829 struct fc_vft_header *fc_vft_hdr;
10831 switch (fc_hdr->fh_r_ctl) {
10832 case FC_RCTL_DD_UNCAT: /* uncategorized information */
10833 case FC_RCTL_DD_SOL_DATA: /* solicited data */
10834 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
10835 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
10836 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
10837 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
10838 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
10839 case FC_RCTL_DD_CMD_STATUS: /* command status */
10840 case FC_RCTL_ELS_REQ: /* extended link services request */
10841 case FC_RCTL_ELS_REP: /* extended link services reply */
10842 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
10843 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
10844 case FC_RCTL_BA_NOP: /* basic link service NOP */
10845 case FC_RCTL_BA_ABTS: /* basic link service abort */
10846 case FC_RCTL_BA_RMC: /* remove connection */
10847 case FC_RCTL_BA_ACC: /* basic accept */
10848 case FC_RCTL_BA_RJT: /* basic reject */
10849 case FC_RCTL_BA_PRMT:
10850 case FC_RCTL_ACK_1: /* acknowledge_1 */
10851 case FC_RCTL_ACK_0: /* acknowledge_0 */
10852 case FC_RCTL_P_RJT: /* port reject */
10853 case FC_RCTL_F_RJT: /* fabric reject */
10854 case FC_RCTL_P_BSY: /* port busy */
10855 case FC_RCTL_F_BSY: /* fabric busy to data frame */
10856 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
10857 case FC_RCTL_LCR: /* link credit reset */
10858 case FC_RCTL_END: /* end */
10860 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
10861 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
10862 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
10863 return lpfc_fc_frame_check(phba, fc_hdr);
10867 switch (fc_hdr->fh_type) {
10878 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10879 "2538 Received frame rctl:%s type:%s\n",
10880 rctl_names[fc_hdr->fh_r_ctl],
10881 type_names[fc_hdr->fh_type]);
10884 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
10885 "2539 Dropped frame rctl:%s type:%s\n",
10886 rctl_names[fc_hdr->fh_r_ctl],
10887 type_names[fc_hdr->fh_type]);
10892 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
10893 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10895 * This function processes the FC header to retrieve the VFI from the VF
10896 * header, if one exists. This function will return the VFI if one exists
10897 * or 0 if no VSAN Header exists.
10900 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
10902 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
10904 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
10906 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
10910 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
10911 * @phba: Pointer to the HBA structure to search for the vport on
10912 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10913 * @fcfi: The FC Fabric ID that the frame came from
10915 * This function searches the @phba for a vport that matches the content of the
10916 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
10917 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
10918 * returns the matching vport pointer or NULL if unable to match frame to a
10921 static struct lpfc_vport *
10922 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
10925 struct lpfc_vport **vports;
10926 struct lpfc_vport *vport = NULL;
10928 uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
10929 fc_hdr->fh_d_id[1] << 8 |
10930 fc_hdr->fh_d_id[2]);
10932 vports = lpfc_create_vport_work_array(phba);
10933 if (vports != NULL)
10934 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
10935 if (phba->fcf.fcfi == fcfi &&
10936 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
10937 vports[i]->fc_myDID == did) {
10942 lpfc_destroy_vport_work_array(phba, vports);
10947 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
10948 * @vport: The vport to work on.
10950 * This function updates the receive sequence time stamp for this vport. The
10951 * receive sequence time stamp indicates the time that the last frame of the
10952 * the sequence that has been idle for the longest amount of time was received.
10953 * the driver uses this time stamp to indicate if any received sequences have
10957 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
10959 struct lpfc_dmabuf *h_buf;
10960 struct hbq_dmabuf *dmabuf = NULL;
10962 /* get the oldest sequence on the rcv list */
10963 h_buf = list_get_first(&vport->rcv_buffer_list,
10964 struct lpfc_dmabuf, list);
10967 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
10968 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
10972 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
10973 * @vport: The vport that the received sequences were sent to.
10975 * This function cleans up all outstanding received sequences. This is called
10976 * by the driver when a link event or user action invalidates all the received
10980 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
10982 struct lpfc_dmabuf *h_buf, *hnext;
10983 struct lpfc_dmabuf *d_buf, *dnext;
10984 struct hbq_dmabuf *dmabuf = NULL;
10986 /* start with the oldest sequence on the rcv list */
10987 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
10988 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
10989 list_del_init(&dmabuf->hbuf.list);
10990 list_for_each_entry_safe(d_buf, dnext,
10991 &dmabuf->dbuf.list, list) {
10992 list_del_init(&d_buf->list);
10993 lpfc_in_buf_free(vport->phba, d_buf);
10995 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
11000 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
11001 * @vport: The vport that the received sequences were sent to.
11003 * This function determines whether any received sequences have timed out by
11004 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
11005 * indicates that there is at least one timed out sequence this routine will
11006 * go through the received sequences one at a time from most inactive to most
11007 * active to determine which ones need to be cleaned up. Once it has determined
11008 * that a sequence needs to be cleaned up it will simply free up the resources
11009 * without sending an abort.
11012 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
11014 struct lpfc_dmabuf *h_buf, *hnext;
11015 struct lpfc_dmabuf *d_buf, *dnext;
11016 struct hbq_dmabuf *dmabuf = NULL;
11017 unsigned long timeout;
11018 int abort_count = 0;
11020 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
11021 vport->rcv_buffer_time_stamp);
11022 if (list_empty(&vport->rcv_buffer_list) ||
11023 time_before(jiffies, timeout))
11025 /* start with the oldest sequence on the rcv list */
11026 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
11027 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
11028 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
11029 dmabuf->time_stamp);
11030 if (time_before(jiffies, timeout))
11033 list_del_init(&dmabuf->hbuf.list);
11034 list_for_each_entry_safe(d_buf, dnext,
11035 &dmabuf->dbuf.list, list) {
11036 list_del_init(&d_buf->list);
11037 lpfc_in_buf_free(vport->phba, d_buf);
11039 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
11042 lpfc_update_rcv_time_stamp(vport);
11046 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
11047 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
11049 * This function searches through the existing incomplete sequences that have
11050 * been sent to this @vport. If the frame matches one of the incomplete
11051 * sequences then the dbuf in the @dmabuf is added to the list of frames that
11052 * make up that sequence. If no sequence is found that matches this frame then
11053 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
11054 * This function returns a pointer to the first dmabuf in the sequence list that
11055 * the frame was linked to.
11057 static struct hbq_dmabuf *
11058 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
11060 struct fc_frame_header *new_hdr;
11061 struct fc_frame_header *temp_hdr;
11062 struct lpfc_dmabuf *d_buf;
11063 struct lpfc_dmabuf *h_buf;
11064 struct hbq_dmabuf *seq_dmabuf = NULL;
11065 struct hbq_dmabuf *temp_dmabuf = NULL;
11067 INIT_LIST_HEAD(&dmabuf->dbuf.list);
11068 dmabuf->time_stamp = jiffies;
11069 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
11070 /* Use the hdr_buf to find the sequence that this frame belongs to */
11071 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
11072 temp_hdr = (struct fc_frame_header *)h_buf->virt;
11073 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
11074 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
11075 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
11077 /* found a pending sequence that matches this frame */
11078 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
11083 * This indicates first frame received for this sequence.
11084 * Queue the buffer on the vport's rcv_buffer_list.
11086 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
11087 lpfc_update_rcv_time_stamp(vport);
11090 temp_hdr = seq_dmabuf->hbuf.virt;
11091 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
11092 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
11093 list_del_init(&seq_dmabuf->hbuf.list);
11094 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
11095 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
11096 lpfc_update_rcv_time_stamp(vport);
11099 /* move this sequence to the tail to indicate a young sequence */
11100 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
11101 seq_dmabuf->time_stamp = jiffies;
11102 lpfc_update_rcv_time_stamp(vport);
11103 if (list_empty(&seq_dmabuf->dbuf.list)) {
11104 temp_hdr = dmabuf->hbuf.virt;
11105 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
11108 /* find the correct place in the sequence to insert this frame */
11109 list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
11110 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
11111 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
11113 * If the frame's sequence count is greater than the frame on
11114 * the list then insert the frame right after this frame
11116 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
11117 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
11118 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
11126 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
11127 * @vport: pointer to a vitural port
11128 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11130 * This function tries to abort from the partially assembed sequence, described
11131 * by the information from basic abbort @dmabuf. It checks to see whether such
11132 * partially assembled sequence held by the driver. If so, it shall free up all
11133 * the frames from the partially assembled sequence.
11136 * true -- if there is matching partially assembled sequence present and all
11137 * the frames freed with the sequence;
11138 * false -- if there is no matching partially assembled sequence present so
11139 * nothing got aborted in the lower layer driver
11142 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
11143 struct hbq_dmabuf *dmabuf)
11145 struct fc_frame_header *new_hdr;
11146 struct fc_frame_header *temp_hdr;
11147 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
11148 struct hbq_dmabuf *seq_dmabuf = NULL;
11150 /* Use the hdr_buf to find the sequence that matches this frame */
11151 INIT_LIST_HEAD(&dmabuf->dbuf.list);
11152 INIT_LIST_HEAD(&dmabuf->hbuf.list);
11153 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
11154 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
11155 temp_hdr = (struct fc_frame_header *)h_buf->virt;
11156 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
11157 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
11158 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
11160 /* found a pending sequence that matches this frame */
11161 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
11165 /* Free up all the frames from the partially assembled sequence */
11167 list_for_each_entry_safe(d_buf, n_buf,
11168 &seq_dmabuf->dbuf.list, list) {
11169 list_del_init(&d_buf->list);
11170 lpfc_in_buf_free(vport->phba, d_buf);
11178 * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
11179 * @phba: Pointer to HBA context object.
11180 * @cmd_iocbq: pointer to the command iocbq structure.
11181 * @rsp_iocbq: pointer to the response iocbq structure.
11183 * This function handles the sequence abort accept iocb command complete
11184 * event. It properly releases the memory allocated to the sequence abort
11188 lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
11189 struct lpfc_iocbq *cmd_iocbq,
11190 struct lpfc_iocbq *rsp_iocbq)
11193 lpfc_sli_release_iocbq(phba, cmd_iocbq);
11197 * lpfc_sli4_seq_abort_acc - Accept sequence abort
11198 * @phba: Pointer to HBA context object.
11199 * @fc_hdr: pointer to a FC frame header.
11201 * This function sends a basic accept to a previous unsol sequence abort
11202 * event after aborting the sequence handling.
11205 lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
11206 struct fc_frame_header *fc_hdr)
11208 struct lpfc_iocbq *ctiocb = NULL;
11209 struct lpfc_nodelist *ndlp;
11210 uint16_t oxid, rxid;
11211 uint32_t sid, fctl;
11214 if (!lpfc_is_link_up(phba))
11217 sid = sli4_sid_from_fc_hdr(fc_hdr);
11218 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
11219 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
11221 ndlp = lpfc_findnode_did(phba->pport, sid);
11223 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
11224 "1268 Find ndlp returned NULL for oxid:x%x "
11225 "SID:x%x\n", oxid, sid);
11229 /* Allocate buffer for acc iocb */
11230 ctiocb = lpfc_sli_get_iocbq(phba);
11234 /* Extract the F_CTL field from FC_HDR */
11235 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
11237 icmd = &ctiocb->iocb;
11238 icmd->un.xseq64.bdl.bdeSize = 0;
11239 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
11240 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
11241 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
11242 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
11244 /* Fill in the rest of iocb fields */
11245 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
11246 icmd->ulpBdeCount = 0;
11248 icmd->ulpClass = CLASS3;
11249 icmd->ulpContext = ndlp->nlp_rpi;
11251 ctiocb->iocb_cmpl = NULL;
11252 ctiocb->vport = phba->pport;
11253 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
11255 if (fctl & FC_FC_EX_CTX) {
11256 /* ABTS sent by responder to CT exchange, construction
11257 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
11258 * field and RX_ID from ABTS for RX_ID field.
11260 bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
11261 bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
11262 ctiocb->sli4_xritag = oxid;
11264 /* ABTS sent by initiator to CT exchange, construction
11265 * of BA_ACC will need to allocate a new XRI as for the
11266 * XRI_TAG and RX_ID fields.
11268 bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
11269 bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
11270 ctiocb->sli4_xritag = NO_XRI;
11272 bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
11274 /* Xmit CT abts accept on exchange <xid> */
11275 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
11276 "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
11277 CMD_XMIT_BLS_RSP64_CX, phba->link_state);
11278 lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
11282 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
11283 * @vport: Pointer to the vport on which this sequence was received
11284 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11286 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
11287 * receive sequence is only partially assembed by the driver, it shall abort
11288 * the partially assembled frames for the sequence. Otherwise, if the
11289 * unsolicited receive sequence has been completely assembled and passed to
11290 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
11291 * unsolicited sequence has been aborted. After that, it will issue a basic
11292 * accept to accept the abort.
11295 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
11296 struct hbq_dmabuf *dmabuf)
11298 struct lpfc_hba *phba = vport->phba;
11299 struct fc_frame_header fc_hdr;
11303 /* Make a copy of fc_hdr before the dmabuf being released */
11304 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
11305 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
11307 if (fctl & FC_FC_EX_CTX) {
11309 * ABTS sent by responder to exchange, just free the buffer
11311 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11314 * ABTS sent by initiator to exchange, need to do cleanup
11316 /* Try to abort partially assembled seq */
11317 abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
11319 /* Send abort to ULP if partially seq abort failed */
11320 if (abts_par == false)
11321 lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
11323 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11325 /* Send basic accept (BA_ACC) to the abort requester */
11326 lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
11330 * lpfc_seq_complete - Indicates if a sequence is complete
11331 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11333 * This function checks the sequence, starting with the frame described by
11334 * @dmabuf, to see if all the frames associated with this sequence are present.
11335 * the frames associated with this sequence are linked to the @dmabuf using the
11336 * dbuf list. This function looks for two major things. 1) That the first frame
11337 * has a sequence count of zero. 2) There is a frame with last frame of sequence
11338 * set. 3) That there are no holes in the sequence count. The function will
11339 * return 1 when the sequence is complete, otherwise it will return 0.
11342 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
11344 struct fc_frame_header *hdr;
11345 struct lpfc_dmabuf *d_buf;
11346 struct hbq_dmabuf *seq_dmabuf;
11350 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
11351 /* make sure first fame of sequence has a sequence count of zero */
11352 if (hdr->fh_seq_cnt != seq_count)
11354 fctl = (hdr->fh_f_ctl[0] << 16 |
11355 hdr->fh_f_ctl[1] << 8 |
11357 /* If last frame of sequence we can return success. */
11358 if (fctl & FC_FC_END_SEQ)
11360 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
11361 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
11362 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
11363 /* If there is a hole in the sequence count then fail. */
11364 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
11366 fctl = (hdr->fh_f_ctl[0] << 16 |
11367 hdr->fh_f_ctl[1] << 8 |
11369 /* If last frame of sequence we can return success. */
11370 if (fctl & FC_FC_END_SEQ)
11377 * lpfc_prep_seq - Prep sequence for ULP processing
11378 * @vport: Pointer to the vport on which this sequence was received
11379 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11381 * This function takes a sequence, described by a list of frames, and creates
11382 * a list of iocbq structures to describe the sequence. This iocbq list will be
11383 * used to issue to the generic unsolicited sequence handler. This routine
11384 * returns a pointer to the first iocbq in the list. If the function is unable
11385 * to allocate an iocbq then it throw out the received frames that were not
11386 * able to be described and return a pointer to the first iocbq. If unable to
11387 * allocate any iocbqs (including the first) this function will return NULL.
11389 static struct lpfc_iocbq *
11390 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
11392 struct lpfc_dmabuf *d_buf, *n_buf;
11393 struct lpfc_iocbq *first_iocbq, *iocbq;
11394 struct fc_frame_header *fc_hdr;
11396 struct ulp_bde64 *pbde;
11398 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
11399 /* remove from receive buffer list */
11400 list_del_init(&seq_dmabuf->hbuf.list);
11401 lpfc_update_rcv_time_stamp(vport);
11402 /* get the Remote Port's SID */
11403 sid = sli4_sid_from_fc_hdr(fc_hdr);
11404 /* Get an iocbq struct to fill in. */
11405 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
11407 /* Initialize the first IOCB. */
11408 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
11409 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
11410 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
11411 first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
11412 first_iocbq->iocb.unsli3.rcvsli3.vpi =
11413 vport->vpi + vport->phba->vpi_base;
11414 /* put the first buffer into the first IOCBq */
11415 first_iocbq->context2 = &seq_dmabuf->dbuf;
11416 first_iocbq->context3 = NULL;
11417 first_iocbq->iocb.ulpBdeCount = 1;
11418 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
11419 LPFC_DATA_BUF_SIZE;
11420 first_iocbq->iocb.un.rcvels.remoteID = sid;
11421 first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
11422 bf_get(lpfc_rcqe_length,
11423 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
11425 iocbq = first_iocbq;
11427 * Each IOCBq can have two Buffers assigned, so go through the list
11428 * of buffers for this sequence and save two buffers in each IOCBq
11430 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
11432 lpfc_in_buf_free(vport->phba, d_buf);
11435 if (!iocbq->context3) {
11436 iocbq->context3 = d_buf;
11437 iocbq->iocb.ulpBdeCount++;
11438 pbde = (struct ulp_bde64 *)
11439 &iocbq->iocb.unsli3.sli3Words[4];
11440 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
11441 first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
11442 bf_get(lpfc_rcqe_length,
11443 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
11445 iocbq = lpfc_sli_get_iocbq(vport->phba);
11448 first_iocbq->iocb.ulpStatus =
11449 IOSTAT_FCP_RSP_ERROR;
11450 first_iocbq->iocb.un.ulpWord[4] =
11451 IOERR_NO_RESOURCES;
11453 lpfc_in_buf_free(vport->phba, d_buf);
11456 iocbq->context2 = d_buf;
11457 iocbq->context3 = NULL;
11458 iocbq->iocb.ulpBdeCount = 1;
11459 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
11460 LPFC_DATA_BUF_SIZE;
11461 first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
11462 bf_get(lpfc_rcqe_length,
11463 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
11464 iocbq->iocb.un.rcvels.remoteID = sid;
11465 list_add_tail(&iocbq->list, &first_iocbq->list);
11468 return first_iocbq;
11472 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
11473 struct hbq_dmabuf *seq_dmabuf)
11475 struct fc_frame_header *fc_hdr;
11476 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
11477 struct lpfc_hba *phba = vport->phba;
11479 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
11480 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
11482 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11483 "2707 Ring %d handler: Failed to allocate "
11484 "iocb Rctl x%x Type x%x received\n",
11486 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
11489 if (!lpfc_complete_unsol_iocb(phba,
11490 &phba->sli.ring[LPFC_ELS_RING],
11491 iocbq, fc_hdr->fh_r_ctl,
11493 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11494 "2540 Ring %d handler: unexpected Rctl "
11495 "x%x Type x%x received\n",
11497 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
11499 /* Free iocb created in lpfc_prep_seq */
11500 list_for_each_entry_safe(curr_iocb, next_iocb,
11501 &iocbq->list, list) {
11502 list_del_init(&curr_iocb->list);
11503 lpfc_sli_release_iocbq(phba, curr_iocb);
11505 lpfc_sli_release_iocbq(phba, iocbq);
11509 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
11510 * @phba: Pointer to HBA context object.
11512 * This function is called with no lock held. This function processes all
11513 * the received buffers and gives it to upper layers when a received buffer
11514 * indicates that it is the final frame in the sequence. The interrupt
11515 * service routine processes received buffers at interrupt contexts and adds
11516 * received dma buffers to the rb_pend_list queue and signals the worker thread.
11517 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
11518 * appropriate receive function when the final frame in a sequence is received.
11521 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
11522 struct hbq_dmabuf *dmabuf)
11524 struct hbq_dmabuf *seq_dmabuf;
11525 struct fc_frame_header *fc_hdr;
11526 struct lpfc_vport *vport;
11529 /* Process each received buffer */
11530 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
11531 /* check to see if this a valid type of frame */
11532 if (lpfc_fc_frame_check(phba, fc_hdr)) {
11533 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11536 fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
11537 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
11538 if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
11539 /* throw out the frame */
11540 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11543 /* Handle the basic abort sequence (BA_ABTS) event */
11544 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
11545 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
11549 /* Link this frame */
11550 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
11552 /* unable to add frame to vport - throw it out */
11553 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11556 /* If not last frame in sequence continue processing frames. */
11557 if (!lpfc_seq_complete(seq_dmabuf))
11560 /* Send the complete sequence to the upper layer protocol */
11561 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
11565 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
11566 * @phba: pointer to lpfc hba data structure.
11568 * This routine is invoked to post rpi header templates to the
11569 * HBA consistent with the SLI-4 interface spec. This routine
11570 * posts a PAGE_SIZE memory region to the port to hold up to
11571 * PAGE_SIZE modulo 64 rpi context headers.
11573 * This routine does not require any locks. It's usage is expected
11574 * to be driver load or reset recovery when the driver is
11579 * EIO - The mailbox failed to complete successfully.
11580 * When this error occurs, the driver is not guaranteed
11581 * to have any rpi regions posted to the device and
11582 * must either attempt to repost the regions or take a
11586 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
11588 struct lpfc_rpi_hdr *rpi_page;
11591 /* Post all rpi memory regions to the port. */
11592 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
11593 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
11594 if (rc != MBX_SUCCESS) {
11595 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11596 "2008 Error %d posting all rpi "
11607 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
11608 * @phba: pointer to lpfc hba data structure.
11609 * @rpi_page: pointer to the rpi memory region.
11611 * This routine is invoked to post a single rpi header to the
11612 * HBA consistent with the SLI-4 interface spec. This memory region
11613 * maps up to 64 rpi context regions.
11617 * ENOMEM - No available memory
11618 * EIO - The mailbox failed to complete successfully.
11621 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
11623 LPFC_MBOXQ_t *mboxq;
11624 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
11627 uint32_t shdr_status, shdr_add_status;
11628 union lpfc_sli4_cfg_shdr *shdr;
11630 /* The port is notified of the header region via a mailbox command. */
11631 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11633 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11634 "2001 Unable to allocate memory for issuing "
11635 "SLI_CONFIG_SPECIAL mailbox command\n");
11639 /* Post all rpi memory regions to the port. */
11640 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
11641 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
11642 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
11643 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
11644 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
11645 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
11646 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
11647 hdr_tmpl, rpi_page->page_count);
11648 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
11649 rpi_page->start_rpi);
11650 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
11651 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
11652 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11653 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
11654 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11655 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11656 if (rc != MBX_TIMEOUT)
11657 mempool_free(mboxq, phba->mbox_mem_pool);
11658 if (shdr_status || shdr_add_status || rc) {
11659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11660 "2514 POST_RPI_HDR mailbox failed with "
11661 "status x%x add_status x%x, mbx status x%x\n",
11662 shdr_status, shdr_add_status, rc);
11669 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
11670 * @phba: pointer to lpfc hba data structure.
11672 * This routine is invoked to post rpi header templates to the
11673 * HBA consistent with the SLI-4 interface spec. This routine
11674 * posts a PAGE_SIZE memory region to the port to hold up to
11675 * PAGE_SIZE modulo 64 rpi context headers.
11678 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
11679 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
11682 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
11685 uint16_t max_rpi, rpi_base, rpi_limit;
11686 uint16_t rpi_remaining;
11687 struct lpfc_rpi_hdr *rpi_hdr;
11689 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
11690 rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
11691 rpi_limit = phba->sli4_hba.next_rpi;
11694 * The valid rpi range is not guaranteed to be zero-based. Start
11695 * the search at the rpi_base as reported by the port.
11697 spin_lock_irq(&phba->hbalock);
11698 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
11699 if (rpi >= rpi_limit || rpi < rpi_base)
11700 rpi = LPFC_RPI_ALLOC_ERROR;
11702 set_bit(rpi, phba->sli4_hba.rpi_bmask);
11703 phba->sli4_hba.max_cfg_param.rpi_used++;
11704 phba->sli4_hba.rpi_count++;
11708 * Don't try to allocate more rpi header regions if the device limit
11709 * on available rpis max has been exhausted.
11711 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
11712 (phba->sli4_hba.rpi_count >= max_rpi)) {
11713 spin_unlock_irq(&phba->hbalock);
11718 * If the driver is running low on rpi resources, allocate another
11719 * page now. Note that the next_rpi value is used because
11720 * it represents how many are actually in use whereas max_rpi notes
11721 * how many are supported max by the device.
11723 rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
11724 phba->sli4_hba.rpi_count;
11725 spin_unlock_irq(&phba->hbalock);
11726 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
11727 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
11729 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11730 "2002 Error Could not grow rpi "
11733 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
11741 * lpfc_sli4_free_rpi - Release an rpi for reuse.
11742 * @phba: pointer to lpfc hba data structure.
11744 * This routine is invoked to release an rpi to the pool of
11745 * available rpis maintained by the driver.
11748 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
11750 spin_lock_irq(&phba->hbalock);
11751 clear_bit(rpi, phba->sli4_hba.rpi_bmask);
11752 phba->sli4_hba.rpi_count--;
11753 phba->sli4_hba.max_cfg_param.rpi_used--;
11754 spin_unlock_irq(&phba->hbalock);
11758 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
11759 * @phba: pointer to lpfc hba data structure.
11761 * This routine is invoked to remove the memory region that
11762 * provided rpi via a bitmask.
11765 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
11767 kfree(phba->sli4_hba.rpi_bmask);
11771 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
11772 * @phba: pointer to lpfc hba data structure.
11774 * This routine is invoked to remove the memory region that
11775 * provided rpi via a bitmask.
11778 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
11780 LPFC_MBOXQ_t *mboxq;
11781 struct lpfc_hba *phba = ndlp->phba;
11784 /* The port is notified of the header region via a mailbox command. */
11785 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11789 /* Post all rpi memory regions to the port. */
11790 lpfc_resume_rpi(mboxq, ndlp);
11791 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
11792 if (rc == MBX_NOT_FINISHED) {
11793 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11794 "2010 Resume RPI Mailbox failed "
11795 "status %d, mbxStatus x%x\n", rc,
11796 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
11797 mempool_free(mboxq, phba->mbox_mem_pool);
11804 * lpfc_sli4_init_vpi - Initialize a vpi with the port
11805 * @phba: pointer to lpfc hba data structure.
11806 * @vpi: vpi value to activate with the port.
11808 * This routine is invoked to activate a vpi with the
11809 * port when the host intends to use vports with a
11814 * -Evalue otherwise
11817 lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
11819 LPFC_MBOXQ_t *mboxq;
11821 int retval = MBX_SUCCESS;
11826 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11829 lpfc_init_vpi(phba, mboxq, vpi);
11830 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
11831 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11832 if (rc != MBX_SUCCESS) {
11833 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11834 "2022 INIT VPI Mailbox failed "
11835 "status %d, mbxStatus x%x\n", rc,
11836 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
11839 if (rc != MBX_TIMEOUT)
11840 mempool_free(mboxq, phba->mbox_mem_pool);
11846 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
11847 * @phba: pointer to lpfc hba data structure.
11848 * @mboxq: Pointer to mailbox object.
11850 * This routine is invoked to manually add a single FCF record. The caller
11851 * must pass a completely initialized FCF_Record. This routine takes
11852 * care of the nonembedded mailbox operations.
11855 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11858 union lpfc_sli4_cfg_shdr *shdr;
11859 uint32_t shdr_status, shdr_add_status;
11861 virt_addr = mboxq->sge_array->addr[0];
11862 /* The IOCTL status is embedded in the mailbox subheader. */
11863 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
11864 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11865 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11867 if ((shdr_status || shdr_add_status) &&
11868 (shdr_status != STATUS_FCF_IN_USE))
11869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11870 "2558 ADD_FCF_RECORD mailbox failed with "
11871 "status x%x add_status x%x\n",
11872 shdr_status, shdr_add_status);
11874 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11878 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
11879 * @phba: pointer to lpfc hba data structure.
11880 * @fcf_record: pointer to the initialized fcf record to add.
11882 * This routine is invoked to manually add a single FCF record. The caller
11883 * must pass a completely initialized FCF_Record. This routine takes
11884 * care of the nonembedded mailbox operations.
11887 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
11890 LPFC_MBOXQ_t *mboxq;
11893 dma_addr_t phys_addr;
11894 struct lpfc_mbx_sge sge;
11895 uint32_t alloc_len, req_len;
11898 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11901 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
11905 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
11908 /* Allocate DMA memory and set up the non-embedded mailbox command */
11909 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
11910 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
11911 req_len, LPFC_SLI4_MBX_NEMBED);
11912 if (alloc_len < req_len) {
11913 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11914 "2523 Allocated DMA memory size (x%x) is "
11915 "less than the requested DMA memory "
11916 "size (x%x)\n", alloc_len, req_len);
11917 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11922 * Get the first SGE entry from the non-embedded DMA memory. This
11923 * routine only uses a single SGE.
11925 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
11926 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
11927 virt_addr = mboxq->sge_array->addr[0];
11929 * Configure the FCF record for FCFI 0. This is the driver's
11930 * hardcoded default and gets used in nonFIP mode.
11932 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
11933 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
11934 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
11937 * Copy the fcf_index and the FCF Record Data. The data starts after
11938 * the FCoE header plus word10. The data copy needs to be endian
11941 bytep += sizeof(uint32_t);
11942 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
11943 mboxq->vport = phba->pport;
11944 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
11945 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
11946 if (rc == MBX_NOT_FINISHED) {
11947 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11948 "2515 ADD_FCF_RECORD mailbox failed with "
11949 "status 0x%x\n", rc);
11950 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11959 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
11960 * @phba: pointer to lpfc hba data structure.
11961 * @fcf_record: pointer to the fcf record to write the default data.
11962 * @fcf_index: FCF table entry index.
11964 * This routine is invoked to build the driver's default FCF record. The
11965 * values used are hardcoded. This routine handles memory initialization.
11969 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
11970 struct fcf_record *fcf_record,
11971 uint16_t fcf_index)
11973 memset(fcf_record, 0, sizeof(struct fcf_record));
11974 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
11975 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
11976 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
11977 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
11978 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
11979 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
11980 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
11981 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
11982 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
11983 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
11984 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
11985 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
11986 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
11987 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
11988 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
11989 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
11990 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
11991 /* Set the VLAN bit map */
11992 if (phba->valid_vlan) {
11993 fcf_record->vlan_bitmap[phba->vlan_id / 8]
11994 = 1 << (phba->vlan_id % 8);
11999 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
12000 * @phba: pointer to lpfc hba data structure.
12001 * @fcf_index: FCF table entry offset.
12003 * This routine is invoked to scan the entire FCF table by reading FCF
12004 * record and processing it one at a time starting from the @fcf_index
12005 * for initial FCF discovery or fast FCF failover rediscovery.
12007 * Return 0 if the mailbox command is submitted sucessfully, none 0
12011 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
12014 LPFC_MBOXQ_t *mboxq;
12016 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
12017 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12020 "2000 Failed to allocate mbox for "
12023 goto fail_fcf_scan;
12025 /* Construct the read FCF record mailbox command */
12026 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
12029 goto fail_fcf_scan;
12031 /* Issue the mailbox command asynchronously */
12032 mboxq->vport = phba->pport;
12033 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
12034 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
12035 if (rc == MBX_NOT_FINISHED)
12038 spin_lock_irq(&phba->hbalock);
12039 phba->hba_flag |= FCF_DISC_INPROGRESS;
12040 spin_unlock_irq(&phba->hbalock);
12041 /* Reset FCF round robin index bmask for new scan */
12042 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
12043 memset(phba->fcf.fcf_rr_bmask, 0,
12044 sizeof(*phba->fcf.fcf_rr_bmask));
12050 lpfc_sli4_mbox_cmd_free(phba, mboxq);
12051 /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
12052 spin_lock_irq(&phba->hbalock);
12053 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
12054 spin_unlock_irq(&phba->hbalock);
12060 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
12061 * @phba: pointer to lpfc hba data structure.
12062 * @fcf_index: FCF table entry offset.
12064 * This routine is invoked to read an FCF record indicated by @fcf_index
12065 * and to use it for FLOGI round robin FCF failover.
12067 * Return 0 if the mailbox command is submitted sucessfully, none 0
12071 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
12074 LPFC_MBOXQ_t *mboxq;
12076 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12078 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
12079 "2763 Failed to allocate mbox for "
12082 goto fail_fcf_read;
12084 /* Construct the read FCF record mailbox command */
12085 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
12088 goto fail_fcf_read;
12090 /* Issue the mailbox command asynchronously */
12091 mboxq->vport = phba->pport;
12092 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
12093 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
12094 if (rc == MBX_NOT_FINISHED)
12100 if (error && mboxq)
12101 lpfc_sli4_mbox_cmd_free(phba, mboxq);
12106 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
12107 * @phba: pointer to lpfc hba data structure.
12108 * @fcf_index: FCF table entry offset.
12110 * This routine is invoked to read an FCF record indicated by @fcf_index to
12111 * determine whether it's eligible for FLOGI round robin failover list.
12113 * Return 0 if the mailbox command is submitted sucessfully, none 0
12117 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
12120 LPFC_MBOXQ_t *mboxq;
12122 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12124 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
12125 "2758 Failed to allocate mbox for "
12128 goto fail_fcf_read;
12130 /* Construct the read FCF record mailbox command */
12131 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
12134 goto fail_fcf_read;
12136 /* Issue the mailbox command asynchronously */
12137 mboxq->vport = phba->pport;
12138 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
12139 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
12140 if (rc == MBX_NOT_FINISHED)
12146 if (error && mboxq)
12147 lpfc_sli4_mbox_cmd_free(phba, mboxq);
12152 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
12153 * @phba: pointer to lpfc hba data structure.
12155 * This routine is to get the next eligible FCF record index in a round
12156 * robin fashion. If the next eligible FCF record index equals to the
12157 * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
12158 * shall be returned, otherwise, the next eligible FCF record's index
12159 * shall be returned.
12162 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
12164 uint16_t next_fcf_index;
12166 /* Search from the currently registered FCF index */
12167 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
12168 LPFC_SLI4_FCF_TBL_INDX_MAX,
12169 phba->fcf.current_rec.fcf_indx);
12170 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
12171 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
12172 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
12173 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
12174 /* Round robin failover stop condition */
12175 if (next_fcf_index == phba->fcf.fcf_rr_init_indx)
12176 return LPFC_FCOE_FCF_NEXT_NONE;
12178 return next_fcf_index;
12182 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
12183 * @phba: pointer to lpfc hba data structure.
12185 * This routine sets the FCF record index in to the eligible bmask for
12186 * round robin failover search. It checks to make sure that the index
12187 * does not go beyond the range of the driver allocated bmask dimension
12188 * before setting the bit.
12190 * Returns 0 if the index bit successfully set, otherwise, it returns
12194 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
12196 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
12197 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
12198 "2610 HBA FCF index reached driver's "
12199 "book keeping dimension: fcf_index:%d, "
12200 "driver_bmask_max:%d\n",
12201 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
12204 /* Set the eligible FCF record index bmask */
12205 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
12211 * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
12212 * @phba: pointer to lpfc hba data structure.
12214 * This routine clears the FCF record index from the eligible bmask for
12215 * round robin failover search. It checks to make sure that the index
12216 * does not go beyond the range of the driver allocated bmask dimension
12217 * before clearing the bit.
12220 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
12222 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
12223 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
12224 "2762 HBA FCF index goes beyond driver's "
12225 "book keeping dimension: fcf_index:%d, "
12226 "driver_bmask_max:%d\n",
12227 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
12230 /* Clear the eligible FCF record index bmask */
12231 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
12235 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
12236 * @phba: pointer to lpfc hba data structure.
12238 * This routine is the completion routine for the rediscover FCF table mailbox
12239 * command. If the mailbox command returned failure, it will try to stop the
12240 * FCF rediscover wait timer.
12243 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
12245 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
12246 uint32_t shdr_status, shdr_add_status;
12248 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
12250 shdr_status = bf_get(lpfc_mbox_hdr_status,
12251 &redisc_fcf->header.cfg_shdr.response);
12252 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
12253 &redisc_fcf->header.cfg_shdr.response);
12254 if (shdr_status || shdr_add_status) {
12255 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
12256 "2746 Requesting for FCF rediscovery failed "
12257 "status x%x add_status x%x\n",
12258 shdr_status, shdr_add_status);
12259 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
12260 spin_lock_irq(&phba->hbalock);
12261 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
12262 spin_unlock_irq(&phba->hbalock);
12264 * CVL event triggered FCF rediscover request failed,
12265 * last resort to re-try current registered FCF entry.
12267 lpfc_retry_pport_discovery(phba);
12269 spin_lock_irq(&phba->hbalock);
12270 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
12271 spin_unlock_irq(&phba->hbalock);
12273 * DEAD FCF event triggered FCF rediscover request
12274 * failed, last resort to fail over as a link down
12275 * to FCF registration.
12277 lpfc_sli4_fcf_dead_failthrough(phba);
12280 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
12281 "2775 Start FCF rediscovery quiescent period "
12282 "wait timer before scaning FCF table\n");
12284 * Start FCF rediscovery wait timer for pending FCF
12285 * before rescan FCF record table.
12287 lpfc_fcf_redisc_wait_start_timer(phba);
12290 mempool_free(mbox, phba->mbox_mem_pool);
12294 * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
12295 * @phba: pointer to lpfc hba data structure.
12297 * This routine is invoked to request for rediscovery of the entire FCF table
12301 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
12303 LPFC_MBOXQ_t *mbox;
12304 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
12307 /* Cancel retry delay timers to all vports before FCF rediscover */
12308 lpfc_cancel_all_vport_retry_delay_timer(phba);
12310 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12312 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12313 "2745 Failed to allocate mbox for "
12314 "requesting FCF rediscover.\n");
12318 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
12319 sizeof(struct lpfc_sli4_cfg_mhdr));
12320 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12321 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
12322 length, LPFC_SLI4_MBX_EMBED);
12324 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
12325 /* Set count to 0 for invalidating the entire FCF database */
12326 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
12328 /* Issue the mailbox command asynchronously */
12329 mbox->vport = phba->pport;
12330 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
12331 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
12333 if (rc == MBX_NOT_FINISHED) {
12334 mempool_free(mbox, phba->mbox_mem_pool);
12341 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
12342 * @phba: pointer to lpfc hba data structure.
12344 * This function is the failover routine as a last resort to the FCF DEAD
12345 * event when driver failed to perform fast FCF failover.
12348 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
12350 uint32_t link_state;
12353 * Last resort as FCF DEAD event failover will treat this as
12354 * a link down, but save the link state because we don't want
12355 * it to be changed to Link Down unless it is already down.
12357 link_state = phba->link_state;
12358 lpfc_linkdown(phba);
12359 phba->link_state = link_state;
12361 /* Unregister FCF if no devices connected to it */
12362 lpfc_unregister_unused_fcf(phba);
12366 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
12367 * @phba: pointer to lpfc hba data structure.
12369 * This function read region 23 and parse TLV for port status to
12370 * decide if the user disaled the port. If the TLV indicates the
12371 * port is disabled, the hba_flag is set accordingly.
12374 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
12376 LPFC_MBOXQ_t *pmb = NULL;
12378 uint8_t *rgn23_data = NULL;
12379 uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
12382 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12384 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12385 "2600 lpfc_sli_read_serdes_param failed to"
12386 " allocate mailbox memory\n");
12391 /* Get adapter Region 23 data */
12392 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
12397 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
12398 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
12400 if (rc != MBX_SUCCESS) {
12401 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12402 "2601 lpfc_sli_read_link_ste failed to"
12403 " read config region 23 rc 0x%x Status 0x%x\n",
12404 rc, mb->mbxStatus);
12405 mb->un.varDmp.word_cnt = 0;
12408 * dump mem may return a zero when finished or we got a
12409 * mailbox error, either way we are done.
12411 if (mb->un.varDmp.word_cnt == 0)
12413 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
12414 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
12416 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
12417 rgn23_data + offset,
12418 mb->un.varDmp.word_cnt);
12419 offset += mb->un.varDmp.word_cnt;
12420 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
12422 data_size = offset;
12428 /* Check the region signature first */
12429 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
12430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12431 "2619 Config region 23 has bad signature\n");
12436 /* Check the data structure version */
12437 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
12438 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12439 "2620 Config region 23 has bad version\n");
12444 /* Parse TLV entries in the region */
12445 while (offset < data_size) {
12446 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
12449 * If the TLV is not driver specific TLV or driver id is
12450 * not linux driver id, skip the record.
12452 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
12453 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
12454 (rgn23_data[offset + 3] != 0)) {
12455 offset += rgn23_data[offset + 1] * 4 + 4;
12459 /* Driver found a driver specific TLV in the config region */
12460 sub_tlv_len = rgn23_data[offset + 1] * 4;
12465 * Search for configured port state sub-TLV.
12467 while ((offset < data_size) &&
12468 (tlv_offset < sub_tlv_len)) {
12469 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
12474 if (rgn23_data[offset] != PORT_STE_TYPE) {
12475 offset += rgn23_data[offset + 1] * 4 + 4;
12476 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
12480 /* This HBA contains PORT_STE configured */
12481 if (!rgn23_data[offset + 2])
12482 phba->hba_flag |= LINK_DISABLED;
12489 mempool_free(pmb, phba->mbox_mem_pool);
12495 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
12496 * @vport: pointer to vport data structure.
12498 * This function iterate through the mailboxq and clean up all REG_LOGIN
12499 * and REG_VPI mailbox commands associated with the vport. This function
12500 * is called when driver want to restart discovery of the vport due to
12501 * a Clear Virtual Link event.
12504 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
12506 struct lpfc_hba *phba = vport->phba;
12507 LPFC_MBOXQ_t *mb, *nextmb;
12508 struct lpfc_dmabuf *mp;
12510 spin_lock_irq(&phba->hbalock);
12511 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
12512 if (mb->vport != vport)
12515 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
12516 (mb->u.mb.mbxCommand != MBX_REG_VPI))
12519 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
12520 mp = (struct lpfc_dmabuf *) (mb->context1);
12522 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
12526 list_del(&mb->list);
12527 mempool_free(mb, phba->mbox_mem_pool);
12529 mb = phba->sli.mbox_active;
12530 if (mb && (mb->vport == vport)) {
12531 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
12532 (mb->u.mb.mbxCommand == MBX_REG_VPI))
12533 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12535 spin_unlock_irq(&phba->hbalock);