1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_compat.h"
45 #include "lpfc_debugfs.h"
46 #include "lpfc_vport.h"
48 /* There are only four IOCB completion types. */
49 typedef enum _lpfc_iocb_type {
57 /* Provide function prototypes local to this module. */
58 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
60 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
61 uint8_t *, uint32_t *);
62 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
65 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
71 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
72 * @q: The Work Queue to operate on.
73 * @wqe: The work Queue Entry to put on the Work queue.
75 * This routine will copy the contents of @wqe to the next available entry on
76 * the @q. This function will then ring the Work Queue Doorbell to signal the
77 * HBA to start processing the Work Queue Entry. This function returns 0 if
78 * successful. If no entries are available on @q then this function will return
80 * The caller is expected to hold the hbalock when calling this routine.
83 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
85 union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
86 struct lpfc_register doorbell;
89 /* If the host has not yet processed the next entry then we are done */
90 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
92 /* set consumption flag every once in a while */
93 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
94 bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
96 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
98 /* Update the host index before invoking device */
99 host_index = q->host_index;
100 q->host_index = ((q->host_index + 1) % q->entry_count);
104 bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
105 bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
106 bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
107 writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
108 readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
114 * lpfc_sli4_wq_release - Updates internal hba index for WQ
115 * @q: The Work Queue to operate on.
116 * @index: The index to advance the hba index to.
118 * This routine will update the HBA index of a queue to reflect consumption of
119 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
120 * an entry the host calls this function to update the queue's internal
121 * pointers. This routine returns the number of entries that were consumed by
125 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
127 uint32_t released = 0;
129 if (q->hba_index == index)
132 q->hba_index = ((q->hba_index + 1) % q->entry_count);
134 } while (q->hba_index != index);
139 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
140 * @q: The Mailbox Queue to operate on.
141 * @wqe: The Mailbox Queue Entry to put on the Work queue.
143 * This routine will copy the contents of @mqe to the next available entry on
144 * the @q. This function will then ring the Work Queue Doorbell to signal the
145 * HBA to start processing the Work Queue Entry. This function returns 0 if
146 * successful. If no entries are available on @q then this function will return
148 * The caller is expected to hold the hbalock when calling this routine.
151 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
153 struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
154 struct lpfc_register doorbell;
157 /* If the host has not yet processed the next entry then we are done */
158 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
160 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
161 /* Save off the mailbox pointer for completion */
162 q->phba->mbox = (MAILBOX_t *)temp_mqe;
164 /* Update the host index before invoking device */
165 host_index = q->host_index;
166 q->host_index = ((q->host_index + 1) % q->entry_count);
170 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
171 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
172 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
173 readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
178 * lpfc_sli4_mq_release - Updates internal hba index for MQ
179 * @q: The Mailbox Queue to operate on.
181 * This routine will update the HBA index of a queue to reflect consumption of
182 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
183 * an entry the host calls this function to update the queue's internal
184 * pointers. This routine returns the number of entries that were consumed by
188 lpfc_sli4_mq_release(struct lpfc_queue *q)
190 /* Clear the mailbox pointer for completion */
191 q->phba->mbox = NULL;
192 q->hba_index = ((q->hba_index + 1) % q->entry_count);
197 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
198 * @q: The Event Queue to get the first valid EQE from
200 * This routine will get the first valid Event Queue Entry from @q, update
201 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
202 * the Queue (no more work to do), or the Queue is full of EQEs that have been
203 * processed, but not popped back to the HBA then this routine will return NULL.
205 static struct lpfc_eqe *
206 lpfc_sli4_eq_get(struct lpfc_queue *q)
208 struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
210 /* If the next EQE is not valid then we are done */
211 if (!bf_get(lpfc_eqe_valid, eqe))
213 /* If the host has not yet processed the next entry then we are done */
214 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
217 q->hba_index = ((q->hba_index + 1) % q->entry_count);
222 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
223 * @q: The Event Queue that the host has completed processing for.
224 * @arm: Indicates whether the host wants to arms this CQ.
226 * This routine will mark all Event Queue Entries on @q, from the last
227 * known completed entry to the last entry that was processed, as completed
228 * by clearing the valid bit for each completion queue entry. Then it will
229 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
230 * The internal host index in the @q will be updated by this routine to indicate
231 * that the host has finished processing the entries. The @arm parameter
232 * indicates that the queue should be rearmed when ringing the doorbell.
234 * This function will return the number of EQEs that were popped.
237 lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
239 uint32_t released = 0;
240 struct lpfc_eqe *temp_eqe;
241 struct lpfc_register doorbell;
243 /* while there are valid entries */
244 while (q->hba_index != q->host_index) {
245 temp_eqe = q->qe[q->host_index].eqe;
246 bf_set(lpfc_eqe_valid, temp_eqe, 0);
248 q->host_index = ((q->host_index + 1) % q->entry_count);
250 if (unlikely(released == 0 && !arm))
253 /* ring doorbell for number popped */
256 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
257 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
259 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
260 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
261 bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
262 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
267 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
268 * @q: The Completion Queue to get the first valid CQE from
270 * This routine will get the first valid Completion Queue Entry from @q, update
271 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
272 * the Queue (no more work to do), or the Queue is full of CQEs that have been
273 * processed, but not popped back to the HBA then this routine will return NULL.
275 static struct lpfc_cqe *
276 lpfc_sli4_cq_get(struct lpfc_queue *q)
278 struct lpfc_cqe *cqe;
280 /* If the next CQE is not valid then we are done */
281 if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
283 /* If the host has not yet processed the next entry then we are done */
284 if (((q->hba_index + 1) % q->entry_count) == q->host_index)
287 cqe = q->qe[q->hba_index].cqe;
288 q->hba_index = ((q->hba_index + 1) % q->entry_count);
293 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
294 * @q: The Completion Queue that the host has completed processing for.
295 * @arm: Indicates whether the host wants to arms this CQ.
297 * This routine will mark all Completion queue entries on @q, from the last
298 * known completed entry to the last entry that was processed, as completed
299 * by clearing the valid bit for each completion queue entry. Then it will
300 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
301 * The internal host index in the @q will be updated by this routine to indicate
302 * that the host has finished processing the entries. The @arm parameter
303 * indicates that the queue should be rearmed when ringing the doorbell.
305 * This function will return the number of CQEs that were released.
308 lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
310 uint32_t released = 0;
311 struct lpfc_cqe *temp_qe;
312 struct lpfc_register doorbell;
314 /* while there are valid entries */
315 while (q->hba_index != q->host_index) {
316 temp_qe = q->qe[q->host_index].cqe;
317 bf_set(lpfc_cqe_valid, temp_qe, 0);
319 q->host_index = ((q->host_index + 1) % q->entry_count);
321 if (unlikely(released == 0 && !arm))
324 /* ring doorbell for number popped */
327 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
328 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
329 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
330 bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
331 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
336 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
337 * @q: The Header Receive Queue to operate on.
338 * @wqe: The Receive Queue Entry to put on the Receive queue.
340 * This routine will copy the contents of @wqe to the next available entry on
341 * the @q. This function will then ring the Receive Queue Doorbell to signal the
342 * HBA to start processing the Receive Queue Entry. This function returns the
343 * index that the rqe was copied to if successful. If no entries are available
344 * on @q then this function will return -ENOMEM.
345 * The caller is expected to hold the hbalock when calling this routine.
348 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
349 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
351 struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
352 struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
353 struct lpfc_register doorbell;
354 int put_index = hq->host_index;
356 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
358 if (hq->host_index != dq->host_index)
360 /* If the host has not yet processed the next entry then we are done */
361 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
363 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
364 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
366 /* Update the host index to point to the next slot */
367 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
368 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
370 /* Ring The Header Receive Queue Doorbell */
371 if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
373 bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
375 bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
376 writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
382 * lpfc_sli4_rq_release - Updates internal hba index for RQ
383 * @q: The Header Receive Queue to operate on.
385 * This routine will update the HBA index of a queue to reflect consumption of
386 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
387 * consumed an entry the host calls this function to update the queue's
388 * internal pointers. This routine returns the number of entries that were
389 * consumed by the HBA.
392 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
394 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
396 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
397 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
402 * lpfc_cmd_iocb - Get next command iocb entry in the ring
403 * @phba: Pointer to HBA context object.
404 * @pring: Pointer to driver SLI ring object.
406 * This function returns pointer to next command iocb entry
407 * in the command ring. The caller must hold hbalock to prevent
408 * other threads consume the next command iocb.
409 * SLI-2/SLI-3 provide different sized iocbs.
411 static inline IOCB_t *
412 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
414 return (IOCB_t *) (((char *) pring->cmdringaddr) +
415 pring->cmdidx * phba->iocb_cmd_size);
419 * lpfc_resp_iocb - Get next response iocb entry in the ring
420 * @phba: Pointer to HBA context object.
421 * @pring: Pointer to driver SLI ring object.
423 * This function returns pointer to next response iocb entry
424 * in the response ring. The caller must hold hbalock to make sure
425 * that no other thread consume the next response iocb.
426 * SLI-2/SLI-3 provide different sized iocbs.
428 static inline IOCB_t *
429 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
431 return (IOCB_t *) (((char *) pring->rspringaddr) +
432 pring->rspidx * phba->iocb_rsp_size);
436 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
437 * @phba: Pointer to HBA context object.
439 * This function is called with hbalock held. This function
440 * allocates a new driver iocb object from the iocb pool. If the
441 * allocation is successful, it returns pointer to the newly
442 * allocated iocb object else it returns NULL.
444 static struct lpfc_iocbq *
445 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
447 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
448 struct lpfc_iocbq * iocbq = NULL;
450 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
455 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
456 * @phba: Pointer to HBA context object.
457 * @xritag: XRI value.
459 * This function clears the sglq pointer from the array of acive
460 * sglq's. The xritag that is passed in is used to index into the
461 * array. Before the xritag can be used it needs to be adjusted
462 * by subtracting the xribase.
464 * Returns sglq ponter = success, NULL = Failure.
466 static struct lpfc_sglq *
467 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
470 struct lpfc_sglq *sglq;
471 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
472 if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
474 sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
475 phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
480 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
481 * @phba: Pointer to HBA context object.
482 * @xritag: XRI value.
484 * This function returns the sglq pointer from the array of acive
485 * sglq's. The xritag that is passed in is used to index into the
486 * array. Before the xritag can be used it needs to be adjusted
487 * by subtracting the xribase.
489 * Returns sglq ponter = success, NULL = Failure.
491 static struct lpfc_sglq *
492 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
495 struct lpfc_sglq *sglq;
496 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
497 if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
499 sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
504 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
505 * @phba: Pointer to HBA context object.
507 * This function is called with hbalock held. This function
508 * Gets a new driver sglq object from the sglq list. If the
509 * list is not empty then it is successful, it returns pointer to the newly
510 * allocated sglq object else it returns NULL.
512 static struct lpfc_sglq *
513 __lpfc_sli_get_sglq(struct lpfc_hba *phba)
515 struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
516 struct lpfc_sglq *sglq = NULL;
518 list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
519 adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
520 phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
525 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
526 * @phba: Pointer to HBA context object.
528 * This function is called with no lock held. This function
529 * allocates a new driver iocb object from the iocb pool. If the
530 * allocation is successful, it returns pointer to the newly
531 * allocated iocb object else it returns NULL.
534 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
536 struct lpfc_iocbq * iocbq = NULL;
537 unsigned long iflags;
539 spin_lock_irqsave(&phba->hbalock, iflags);
540 iocbq = __lpfc_sli_get_iocbq(phba);
541 spin_unlock_irqrestore(&phba->hbalock, iflags);
546 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
547 * @phba: Pointer to HBA context object.
548 * @iocbq: Pointer to driver iocb object.
550 * This function is called with hbalock held to release driver
551 * iocb object to the iocb pool. The iotag in the iocb object
552 * does not change for each use of the iocb object. This function
553 * clears all other fields of the iocb object when it is freed.
554 * The sqlq structure that holds the xritag and phys and virtual
555 * mappings for the scatter gather list is retrieved from the
556 * active array of sglq. The get of the sglq pointer also clears
557 * the entry in the array. If the status of the IO indiactes that
558 * this IO was aborted then the sglq entry it put on the
559 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
560 * IO has good status or fails for any other reason then the sglq
561 * entry is added to the free list (lpfc_sgl_list).
564 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
566 struct lpfc_sglq *sglq;
567 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
570 if (iocbq->sli4_xritag == NO_XRI)
573 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
575 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
576 && ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
577 && (iocbq->iocb.un.ulpWord[4]
578 == IOERR_ABORT_REQUESTED))) {
579 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
581 list_add(&sglq->list,
582 &phba->sli4_hba.lpfc_abts_els_sgl_list);
583 spin_unlock_irqrestore(
584 &phba->sli4_hba.abts_sgl_list_lock, iflag);
586 list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
591 * Clean all volatile data fields, preserve iotag and node struct.
593 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
594 iocbq->sli4_xritag = NO_XRI;
595 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
599 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
600 * @phba: Pointer to HBA context object.
601 * @iocbq: Pointer to driver iocb object.
603 * This function is called with hbalock held to release driver
604 * iocb object to the iocb pool. The iotag in the iocb object
605 * does not change for each use of the iocb object. This function
606 * clears all other fields of the iocb object when it is freed.
609 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
611 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
614 * Clean all volatile data fields, preserve iotag and node struct.
616 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
617 iocbq->sli4_xritag = NO_XRI;
618 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
622 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
623 * @phba: Pointer to HBA context object.
624 * @iocbq: Pointer to driver iocb object.
626 * This function is called with hbalock held to release driver
627 * iocb object to the iocb pool. The iotag in the iocb object
628 * does not change for each use of the iocb object. This function
629 * clears all other fields of the iocb object when it is freed.
632 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
634 phba->__lpfc_sli_release_iocbq(phba, iocbq);
638 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
639 * @phba: Pointer to HBA context object.
640 * @iocbq: Pointer to driver iocb object.
642 * This function is called with no lock held to release the iocb to
646 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
648 unsigned long iflags;
651 * Clean all volatile data fields, preserve iotag and node struct.
653 spin_lock_irqsave(&phba->hbalock, iflags);
654 __lpfc_sli_release_iocbq(phba, iocbq);
655 spin_unlock_irqrestore(&phba->hbalock, iflags);
659 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
660 * @phba: Pointer to HBA context object.
661 * @iocblist: List of IOCBs.
662 * @ulpstatus: ULP status in IOCB command field.
663 * @ulpWord4: ULP word-4 in IOCB command field.
665 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
666 * on the list by invoking the complete callback function associated with the
667 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
671 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
672 uint32_t ulpstatus, uint32_t ulpWord4)
674 struct lpfc_iocbq *piocb;
676 while (!list_empty(iocblist)) {
677 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
679 if (!piocb->iocb_cmpl)
680 lpfc_sli_release_iocbq(phba, piocb);
682 piocb->iocb.ulpStatus = ulpstatus;
683 piocb->iocb.un.ulpWord[4] = ulpWord4;
684 (piocb->iocb_cmpl) (phba, piocb, piocb);
691 * lpfc_sli_iocb_cmd_type - Get the iocb type
692 * @iocb_cmnd: iocb command code.
694 * This function is called by ring event handler function to get the iocb type.
695 * This function translates the iocb command to an iocb command type used to
696 * decide the final disposition of each completed IOCB.
697 * The function returns
698 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
699 * LPFC_SOL_IOCB if it is a solicited iocb completion
700 * LPFC_ABORT_IOCB if it is an abort iocb
701 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
703 * The caller is not required to hold any lock.
705 static lpfc_iocb_type
706 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
708 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
710 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
714 case CMD_XMIT_SEQUENCE_CR:
715 case CMD_XMIT_SEQUENCE_CX:
716 case CMD_XMIT_BCAST_CN:
717 case CMD_XMIT_BCAST_CX:
718 case CMD_ELS_REQUEST_CR:
719 case CMD_ELS_REQUEST_CX:
720 case CMD_CREATE_XRI_CR:
721 case CMD_CREATE_XRI_CX:
723 case CMD_XMIT_ELS_RSP_CX:
725 case CMD_FCP_IWRITE_CR:
726 case CMD_FCP_IWRITE_CX:
727 case CMD_FCP_IREAD_CR:
728 case CMD_FCP_IREAD_CX:
729 case CMD_FCP_ICMND_CR:
730 case CMD_FCP_ICMND_CX:
731 case CMD_FCP_TSEND_CX:
732 case CMD_FCP_TRSP_CX:
733 case CMD_FCP_TRECEIVE_CX:
734 case CMD_FCP_AUTO_TRSP_CX:
735 case CMD_ADAPTER_MSG:
736 case CMD_ADAPTER_DUMP:
737 case CMD_XMIT_SEQUENCE64_CR:
738 case CMD_XMIT_SEQUENCE64_CX:
739 case CMD_XMIT_BCAST64_CN:
740 case CMD_XMIT_BCAST64_CX:
741 case CMD_ELS_REQUEST64_CR:
742 case CMD_ELS_REQUEST64_CX:
743 case CMD_FCP_IWRITE64_CR:
744 case CMD_FCP_IWRITE64_CX:
745 case CMD_FCP_IREAD64_CR:
746 case CMD_FCP_IREAD64_CX:
747 case CMD_FCP_ICMND64_CR:
748 case CMD_FCP_ICMND64_CX:
749 case CMD_FCP_TSEND64_CX:
750 case CMD_FCP_TRSP64_CX:
751 case CMD_FCP_TRECEIVE64_CX:
752 case CMD_GEN_REQUEST64_CR:
753 case CMD_GEN_REQUEST64_CX:
754 case CMD_XMIT_ELS_RSP64_CX:
755 case DSSCMD_IWRITE64_CR:
756 case DSSCMD_IWRITE64_CX:
757 case DSSCMD_IREAD64_CR:
758 case DSSCMD_IREAD64_CX:
759 case DSSCMD_INVALIDATE_DEK:
761 case DSSCMD_GET_KEK_ID:
762 case DSSCMD_GEN_XFER:
763 type = LPFC_SOL_IOCB;
765 case CMD_ABORT_XRI_CN:
766 case CMD_ABORT_XRI_CX:
767 case CMD_CLOSE_XRI_CN:
768 case CMD_CLOSE_XRI_CX:
769 case CMD_XRI_ABORTED_CX:
770 case CMD_ABORT_MXRI64_CN:
771 case CMD_XMIT_BLS_RSP64_CX:
772 type = LPFC_ABORT_IOCB;
774 case CMD_RCV_SEQUENCE_CX:
775 case CMD_RCV_ELS_REQ_CX:
776 case CMD_RCV_SEQUENCE64_CX:
777 case CMD_RCV_ELS_REQ64_CX:
778 case CMD_ASYNC_STATUS:
779 case CMD_IOCB_RCV_SEQ64_CX:
780 case CMD_IOCB_RCV_ELS64_CX:
781 case CMD_IOCB_RCV_CONT64_CX:
782 case CMD_IOCB_RET_XRI64_CX:
783 type = LPFC_UNSOL_IOCB;
785 case CMD_IOCB_XMIT_MSEQ64_CR:
786 case CMD_IOCB_XMIT_MSEQ64_CX:
787 case CMD_IOCB_RCV_SEQ_LIST64_CX:
788 case CMD_IOCB_RCV_ELS_LIST64_CX:
789 case CMD_IOCB_CLOSE_EXTENDED_CN:
790 case CMD_IOCB_ABORT_EXTENDED_CN:
791 case CMD_IOCB_RET_HBQE64_CN:
792 case CMD_IOCB_FCP_IBIDIR64_CR:
793 case CMD_IOCB_FCP_IBIDIR64_CX:
794 case CMD_IOCB_FCP_ITASKMGT64_CX:
795 case CMD_IOCB_LOGENTRY_CN:
796 case CMD_IOCB_LOGENTRY_ASYNC_CN:
797 printk("%s - Unhandled SLI-3 Command x%x\n",
798 __func__, iocb_cmnd);
799 type = LPFC_UNKNOWN_IOCB;
802 type = LPFC_UNKNOWN_IOCB;
810 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
811 * @phba: Pointer to HBA context object.
813 * This function is called from SLI initialization code
814 * to configure every ring of the HBA's SLI interface. The
815 * caller is not required to hold any lock. This function issues
816 * a config_ring mailbox command for each ring.
817 * This function returns zero if successful else returns a negative
821 lpfc_sli_ring_map(struct lpfc_hba *phba)
823 struct lpfc_sli *psli = &phba->sli;
828 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
832 phba->link_state = LPFC_INIT_MBX_CMDS;
833 for (i = 0; i < psli->num_rings; i++) {
834 lpfc_config_ring(phba, i, pmb);
835 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
836 if (rc != MBX_SUCCESS) {
837 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
838 "0446 Adapter failed to init (%d), "
839 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
841 rc, pmbox->mbxCommand,
842 pmbox->mbxStatus, i);
843 phba->link_state = LPFC_HBA_ERROR;
848 mempool_free(pmb, phba->mbox_mem_pool);
853 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
854 * @phba: Pointer to HBA context object.
855 * @pring: Pointer to driver SLI ring object.
856 * @piocb: Pointer to the driver iocb object.
858 * This function is called with hbalock held. The function adds the
859 * new iocb to txcmplq of the given ring. This function always returns
860 * 0. If this function is called for ELS ring, this function checks if
861 * there is a vport associated with the ELS command. This function also
862 * starts els_tmofunc timer if this is an ELS command.
865 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
866 struct lpfc_iocbq *piocb)
868 list_add_tail(&piocb->list, &pring->txcmplq);
869 pring->txcmplq_cnt++;
870 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
871 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
872 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
876 mod_timer(&piocb->vport->els_tmofunc,
877 jiffies + HZ * (phba->fc_ratov << 1));
885 * lpfc_sli_ringtx_get - Get first element of the txq
886 * @phba: Pointer to HBA context object.
887 * @pring: Pointer to driver SLI ring object.
889 * This function is called with hbalock held to get next
890 * iocb in txq of the given ring. If there is any iocb in
891 * the txq, the function returns first iocb in the list after
892 * removing the iocb from the list, else it returns NULL.
894 static struct lpfc_iocbq *
895 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
897 struct lpfc_iocbq *cmd_iocb;
899 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
900 if (cmd_iocb != NULL)
906 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
907 * @phba: Pointer to HBA context object.
908 * @pring: Pointer to driver SLI ring object.
910 * This function is called with hbalock held and the caller must post the
911 * iocb without releasing the lock. If the caller releases the lock,
912 * iocb slot returned by the function is not guaranteed to be available.
913 * The function returns pointer to the next available iocb slot if there
914 * is available slot in the ring, else it returns NULL.
915 * If the get index of the ring is ahead of the put index, the function
916 * will post an error attention event to the worker thread to take the
917 * HBA to offline state.
920 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
922 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
923 uint32_t max_cmd_idx = pring->numCiocb;
924 if ((pring->next_cmdidx == pring->cmdidx) &&
925 (++pring->next_cmdidx >= max_cmd_idx))
926 pring->next_cmdidx = 0;
928 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
930 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
932 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
933 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
934 "0315 Ring %d issue: portCmdGet %d "
935 "is bigger than cmd ring %d\n",
937 pring->local_getidx, max_cmd_idx);
939 phba->link_state = LPFC_HBA_ERROR;
941 * All error attention handlers are posted to
944 phba->work_ha |= HA_ERATT;
945 phba->work_hs = HS_FFER3;
947 lpfc_worker_wake_up(phba);
952 if (pring->local_getidx == pring->next_cmdidx)
956 return lpfc_cmd_iocb(phba, pring);
960 * lpfc_sli_next_iotag - Get an iotag for the iocb
961 * @phba: Pointer to HBA context object.
962 * @iocbq: Pointer to driver iocb object.
964 * This function gets an iotag for the iocb. If there is no unused iotag and
965 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
966 * array and assigns a new iotag.
967 * The function returns the allocated iotag if successful, else returns zero.
968 * Zero is not a valid iotag.
969 * The caller is not required to hold any lock.
972 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
974 struct lpfc_iocbq **new_arr;
975 struct lpfc_iocbq **old_arr;
977 struct lpfc_sli *psli = &phba->sli;
980 spin_lock_irq(&phba->hbalock);
981 iotag = psli->last_iotag;
982 if(++iotag < psli->iocbq_lookup_len) {
983 psli->last_iotag = iotag;
984 psli->iocbq_lookup[iotag] = iocbq;
985 spin_unlock_irq(&phba->hbalock);
986 iocbq->iotag = iotag;
988 } else if (psli->iocbq_lookup_len < (0xffff
989 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
990 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
991 spin_unlock_irq(&phba->hbalock);
992 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
995 spin_lock_irq(&phba->hbalock);
996 old_arr = psli->iocbq_lookup;
997 if (new_len <= psli->iocbq_lookup_len) {
998 /* highly unprobable case */
1000 iotag = psli->last_iotag;
1001 if(++iotag < psli->iocbq_lookup_len) {
1002 psli->last_iotag = iotag;
1003 psli->iocbq_lookup[iotag] = iocbq;
1004 spin_unlock_irq(&phba->hbalock);
1005 iocbq->iotag = iotag;
1008 spin_unlock_irq(&phba->hbalock);
1011 if (psli->iocbq_lookup)
1012 memcpy(new_arr, old_arr,
1013 ((psli->last_iotag + 1) *
1014 sizeof (struct lpfc_iocbq *)));
1015 psli->iocbq_lookup = new_arr;
1016 psli->iocbq_lookup_len = new_len;
1017 psli->last_iotag = iotag;
1018 psli->iocbq_lookup[iotag] = iocbq;
1019 spin_unlock_irq(&phba->hbalock);
1020 iocbq->iotag = iotag;
1025 spin_unlock_irq(&phba->hbalock);
1027 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
1028 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1035 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1036 * @phba: Pointer to HBA context object.
1037 * @pring: Pointer to driver SLI ring object.
1038 * @iocb: Pointer to iocb slot in the ring.
1039 * @nextiocb: Pointer to driver iocb object which need to be
1040 * posted to firmware.
1042 * This function is called with hbalock held to post a new iocb to
1043 * the firmware. This function copies the new iocb to ring iocb slot and
1044 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1045 * a completion call back for this iocb else the function will free the
1049 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1050 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1055 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1058 if (pring->ringno == LPFC_ELS_RING) {
1059 lpfc_debugfs_slow_ring_trc(phba,
1060 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1061 *(((uint32_t *) &nextiocb->iocb) + 4),
1062 *(((uint32_t *) &nextiocb->iocb) + 6),
1063 *(((uint32_t *) &nextiocb->iocb) + 7));
1067 * Issue iocb command to adapter
1069 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1071 pring->stats.iocb_cmd++;
1074 * If there is no completion routine to call, we can release the
1075 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1076 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1078 if (nextiocb->iocb_cmpl)
1079 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1081 __lpfc_sli_release_iocbq(phba, nextiocb);
1084 * Let the HBA know what IOCB slot will be the next one the
1085 * driver will put a command into.
1087 pring->cmdidx = pring->next_cmdidx;
1088 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1092 * lpfc_sli_update_full_ring - Update the chip attention register
1093 * @phba: Pointer to HBA context object.
1094 * @pring: Pointer to driver SLI ring object.
1096 * The caller is not required to hold any lock for calling this function.
1097 * This function updates the chip attention bits for the ring to inform firmware
1098 * that there are pending work to be done for this ring and requests an
1099 * interrupt when there is space available in the ring. This function is
1100 * called when the driver is unable to post more iocbs to the ring due
1101 * to unavailability of space in the ring.
1104 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1106 int ringno = pring->ringno;
1108 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1113 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1114 * The HBA will tell us when an IOCB entry is available.
1116 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1117 readl(phba->CAregaddr); /* flush */
1119 pring->stats.iocb_cmd_full++;
1123 * lpfc_sli_update_ring - Update chip attention register
1124 * @phba: Pointer to HBA context object.
1125 * @pring: Pointer to driver SLI ring object.
1127 * This function updates the chip attention register bit for the
1128 * given ring to inform HBA that there is more work to be done
1129 * in this ring. The caller is not required to hold any lock.
1132 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1134 int ringno = pring->ringno;
1137 * Tell the HBA that there is work to do in this ring.
1139 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1141 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1142 readl(phba->CAregaddr); /* flush */
1147 * lpfc_sli_resume_iocb - Process iocbs in the txq
1148 * @phba: Pointer to HBA context object.
1149 * @pring: Pointer to driver SLI ring object.
1151 * This function is called with hbalock held to post pending iocbs
1152 * in the txq to the firmware. This function is called when driver
1153 * detects space available in the ring.
1156 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1159 struct lpfc_iocbq *nextiocb;
1163 * (a) there is anything on the txq to send
1165 * (c) link attention events can be processed (fcp ring only)
1166 * (d) IOCB processing is not blocked by the outstanding mbox command.
1168 if (pring->txq_cnt &&
1169 lpfc_is_link_up(phba) &&
1170 (pring->ringno != phba->sli.fcp_ring ||
1171 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1173 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1174 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1175 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1178 lpfc_sli_update_ring(phba, pring);
1180 lpfc_sli_update_full_ring(phba, pring);
1187 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1188 * @phba: Pointer to HBA context object.
1189 * @hbqno: HBQ number.
1191 * This function is called with hbalock held to get the next
1192 * available slot for the given HBQ. If there is free slot
1193 * available for the HBQ it will return pointer to the next available
1194 * HBQ entry else it will return NULL.
1196 static struct lpfc_hbq_entry *
1197 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1199 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1201 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1202 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1203 hbqp->next_hbqPutIdx = 0;
1205 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1206 uint32_t raw_index = phba->hbq_get[hbqno];
1207 uint32_t getidx = le32_to_cpu(raw_index);
1209 hbqp->local_hbqGetIdx = getidx;
1211 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1212 lpfc_printf_log(phba, KERN_ERR,
1213 LOG_SLI | LOG_VPORT,
1214 "1802 HBQ %d: local_hbqGetIdx "
1215 "%u is > than hbqp->entry_count %u\n",
1216 hbqno, hbqp->local_hbqGetIdx,
1219 phba->link_state = LPFC_HBA_ERROR;
1223 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1227 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1232 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1233 * @phba: Pointer to HBA context object.
1235 * This function is called with no lock held to free all the
1236 * hbq buffers while uninitializing the SLI interface. It also
1237 * frees the HBQ buffers returned by the firmware but not yet
1238 * processed by the upper layers.
1241 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1243 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1244 struct hbq_dmabuf *hbq_buf;
1245 unsigned long flags;
1249 hbq_count = lpfc_sli_hbq_count();
1250 /* Return all memory used by all HBQs */
1251 spin_lock_irqsave(&phba->hbalock, flags);
1252 for (i = 0; i < hbq_count; ++i) {
1253 list_for_each_entry_safe(dmabuf, next_dmabuf,
1254 &phba->hbqs[i].hbq_buffer_list, list) {
1255 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1256 list_del(&hbq_buf->dbuf.list);
1257 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1259 phba->hbqs[i].buffer_count = 0;
1261 /* Return all HBQ buffer that are in-fly */
1262 list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
1264 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1265 list_del(&hbq_buf->dbuf.list);
1266 if (hbq_buf->tag == -1) {
1267 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1270 hbqno = hbq_buf->tag >> 16;
1271 if (hbqno >= LPFC_MAX_HBQS)
1272 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1275 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1280 /* Mark the HBQs not in use */
1281 phba->hbq_in_use = 0;
1282 spin_unlock_irqrestore(&phba->hbalock, flags);
1286 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1287 * @phba: Pointer to HBA context object.
1288 * @hbqno: HBQ number.
1289 * @hbq_buf: Pointer to HBQ buffer.
1291 * This function is called with the hbalock held to post a
1292 * hbq buffer to the firmware. If the function finds an empty
1293 * slot in the HBQ, it will post the buffer. The function will return
1294 * pointer to the hbq entry if it successfully post the buffer
1295 * else it will return NULL.
1298 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
1299 struct hbq_dmabuf *hbq_buf)
1301 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1305 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1306 * @phba: Pointer to HBA context object.
1307 * @hbqno: HBQ number.
1308 * @hbq_buf: Pointer to HBQ buffer.
1310 * This function is called with the hbalock held to post a hbq buffer to the
1311 * firmware. If the function finds an empty slot in the HBQ, it will post the
1312 * buffer and place it on the hbq_buffer_list. The function will return zero if
1313 * it successfully post the buffer else it will return an error.
1316 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1317 struct hbq_dmabuf *hbq_buf)
1319 struct lpfc_hbq_entry *hbqe;
1320 dma_addr_t physaddr = hbq_buf->dbuf.phys;
1322 /* Get next HBQ entry slot to use */
1323 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1325 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1327 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1328 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
1329 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
1330 hbqe->bde.tus.f.bdeFlags = 0;
1331 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1332 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1334 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1335 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
1337 readl(phba->hbq_put + hbqno);
1338 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
1345 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1346 * @phba: Pointer to HBA context object.
1347 * @hbqno: HBQ number.
1348 * @hbq_buf: Pointer to HBQ buffer.
1350 * This function is called with the hbalock held to post an RQE to the SLI4
1351 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1352 * the hbq_buffer_list and return zero, otherwise it will return an error.
1355 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1356 struct hbq_dmabuf *hbq_buf)
1359 struct lpfc_rqe hrqe;
1360 struct lpfc_rqe drqe;
1362 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1363 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1364 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1365 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1366 rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
1371 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1375 /* HBQ for ELS and CT traffic. */
1376 static struct lpfc_hbq_init lpfc_els_hbq = {
1381 .ring_mask = (1 << LPFC_ELS_RING),
1387 /* HBQ for the extra ring if needed */
1388 static struct lpfc_hbq_init lpfc_extra_hbq = {
1393 .ring_mask = (1 << LPFC_EXTRA_RING),
1400 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
1406 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1407 * @phba: Pointer to HBA context object.
1408 * @hbqno: HBQ number.
1409 * @count: Number of HBQ buffers to be posted.
1411 * This function is called with no lock held to post more hbq buffers to the
1412 * given HBQ. The function returns the number of HBQ buffers successfully
1416 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1418 uint32_t i, posted = 0;
1419 unsigned long flags;
1420 struct hbq_dmabuf *hbq_buffer;
1421 LIST_HEAD(hbq_buf_list);
1422 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
1425 if ((phba->hbqs[hbqno].buffer_count + count) >
1426 lpfc_hbq_defs[hbqno]->entry_count)
1427 count = lpfc_hbq_defs[hbqno]->entry_count -
1428 phba->hbqs[hbqno].buffer_count;
1431 /* Allocate HBQ entries */
1432 for (i = 0; i < count; i++) {
1433 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1436 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1438 /* Check whether HBQ is still in use */
1439 spin_lock_irqsave(&phba->hbalock, flags);
1440 if (!phba->hbq_in_use)
1442 while (!list_empty(&hbq_buf_list)) {
1443 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1445 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1447 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
1448 phba->hbqs[hbqno].buffer_count++;
1451 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1453 spin_unlock_irqrestore(&phba->hbalock, flags);
1456 spin_unlock_irqrestore(&phba->hbalock, flags);
1457 while (!list_empty(&hbq_buf_list)) {
1458 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1460 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1466 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1467 * @phba: Pointer to HBA context object.
1470 * This function posts more buffers to the HBQ. This function
1471 * is called with no lock held. The function returns the number of HBQ entries
1472 * successfully allocated.
1475 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
1477 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1478 lpfc_hbq_defs[qno]->add_count));
1482 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1483 * @phba: Pointer to HBA context object.
1484 * @qno: HBQ queue number.
1486 * This function is called from SLI initialization code path with
1487 * no lock held to post initial HBQ buffers to firmware. The
1488 * function returns the number of HBQ entries successfully allocated.
1491 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
1493 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1494 lpfc_hbq_defs[qno]->init_count));
1498 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1499 * @phba: Pointer to HBA context object.
1500 * @hbqno: HBQ number.
1502 * This function removes the first hbq buffer on an hbq list and returns a
1503 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1505 static struct hbq_dmabuf *
1506 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
1508 struct lpfc_dmabuf *d_buf;
1510 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
1513 return container_of(d_buf, struct hbq_dmabuf, dbuf);
1517 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1518 * @phba: Pointer to HBA context object.
1519 * @tag: Tag of the hbq buffer.
1521 * This function is called with hbalock held. This function searches
1522 * for the hbq buffer associated with the given tag in the hbq buffer
1523 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1526 static struct hbq_dmabuf *
1527 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
1529 struct lpfc_dmabuf *d_buf;
1530 struct hbq_dmabuf *hbq_buf;
1534 if (hbqno >= LPFC_MAX_HBQS)
1537 spin_lock_irq(&phba->hbalock);
1538 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
1539 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
1540 if (hbq_buf->tag == tag) {
1541 spin_unlock_irq(&phba->hbalock);
1545 spin_unlock_irq(&phba->hbalock);
1546 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
1547 "1803 Bad hbq tag. Data: x%x x%x\n",
1548 tag, phba->hbqs[tag >> 16].buffer_count);
1553 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1554 * @phba: Pointer to HBA context object.
1555 * @hbq_buffer: Pointer to HBQ buffer.
1557 * This function is called with hbalock. This function gives back
1558 * the hbq buffer to firmware. If the HBQ does not have space to
1559 * post the buffer, it will free the buffer.
1562 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
1567 hbqno = hbq_buffer->tag >> 16;
1568 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
1569 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1574 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1575 * @mbxCommand: mailbox command code.
1577 * This function is called by the mailbox event handler function to verify
1578 * that the completed mailbox command is a legitimate mailbox command. If the
1579 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1580 * and the mailbox event handler will take the HBA offline.
1583 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
1587 switch (mbxCommand) {
1591 case MBX_WRITE_VPARMS:
1592 case MBX_RUN_BIU_DIAG:
1595 case MBX_CONFIG_LINK:
1596 case MBX_CONFIG_RING:
1597 case MBX_RESET_RING:
1598 case MBX_READ_CONFIG:
1599 case MBX_READ_RCONFIG:
1600 case MBX_READ_SPARM:
1601 case MBX_READ_STATUS:
1605 case MBX_READ_LNK_STAT:
1607 case MBX_UNREG_LOGIN:
1610 case MBX_DUMP_MEMORY:
1611 case MBX_DUMP_CONTEXT:
1614 case MBX_UPDATE_CFG:
1616 case MBX_DEL_LD_ENTRY:
1617 case MBX_RUN_PROGRAM:
1619 case MBX_SET_VARIABLE:
1620 case MBX_UNREG_D_ID:
1621 case MBX_KILL_BOARD:
1622 case MBX_CONFIG_FARP:
1625 case MBX_RUN_BIU_DIAG64:
1626 case MBX_CONFIG_PORT:
1627 case MBX_READ_SPARM64:
1628 case MBX_READ_RPI64:
1629 case MBX_REG_LOGIN64:
1633 case MBX_LOAD_EXP_ROM:
1634 case MBX_ASYNCEVT_ENABLE:
1638 case MBX_PORT_CAPABILITIES:
1639 case MBX_PORT_IOV_CONTROL:
1640 case MBX_SLI4_CONFIG:
1641 case MBX_SLI4_REQ_FTRS:
1643 case MBX_UNREG_FCFI:
1648 case MBX_RESUME_RPI:
1659 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
1660 * @phba: Pointer to HBA context object.
1661 * @pmboxq: Pointer to mailbox command.
1663 * This is completion handler function for mailbox commands issued from
1664 * lpfc_sli_issue_mbox_wait function. This function is called by the
1665 * mailbox event handler function with no lock held. This function
1666 * will wake up thread waiting on the wait queue pointed by context1
1670 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
1672 wait_queue_head_t *pdone_q;
1673 unsigned long drvr_flag;
1676 * If pdone_q is empty, the driver thread gave up waiting and
1677 * continued running.
1679 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
1680 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1681 pdone_q = (wait_queue_head_t *) pmboxq->context1;
1683 wake_up_interruptible(pdone_q);
1684 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1690 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
1691 * @phba: Pointer to HBA context object.
1692 * @pmb: Pointer to mailbox object.
1694 * This function is the default mailbox completion handler. It
1695 * frees the memory resources associated with the completed mailbox
1696 * command. If the completed command is a REG_LOGIN mailbox command,
1697 * this function will issue a UREG_LOGIN to re-claim the RPI.
1700 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1702 struct lpfc_dmabuf *mp;
1706 mp = (struct lpfc_dmabuf *) (pmb->context1);
1709 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1713 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
1714 (phba->sli_rev == LPFC_SLI_REV4))
1715 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
1718 * If a REG_LOGIN succeeded after node is destroyed or node
1719 * is in re-discovery driver need to cleanup the RPI.
1721 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1722 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
1723 !pmb->u.mb.mbxStatus) {
1724 rpi = pmb->u.mb.un.varWords[0];
1725 vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
1726 lpfc_unreg_login(phba, vpi, rpi, pmb);
1727 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1728 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1729 if (rc != MBX_NOT_FINISHED)
1733 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
1734 lpfc_sli4_mbox_cmd_free(phba, pmb);
1736 mempool_free(pmb, phba->mbox_mem_pool);
1740 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
1741 * @phba: Pointer to HBA context object.
1743 * This function is called with no lock held. This function processes all
1744 * the completed mailbox commands and gives it to upper layers. The interrupt
1745 * service routine processes mailbox completion interrupt and adds completed
1746 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1747 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1748 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1749 * function returns the mailbox commands to the upper layer by calling the
1750 * completion handler function of each mailbox.
1753 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
1760 phba->sli.slistat.mbox_event++;
1762 /* Get all completed mailboxe buffers into the cmplq */
1763 spin_lock_irq(&phba->hbalock);
1764 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
1765 spin_unlock_irq(&phba->hbalock);
1767 /* Get a Mailbox buffer to setup mailbox commands for callback */
1769 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
1775 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
1777 lpfc_debugfs_disc_trc(pmb->vport,
1778 LPFC_DISC_TRC_MBOX_VPORT,
1779 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1780 (uint32_t)pmbox->mbxCommand,
1781 pmbox->un.varWords[0],
1782 pmbox->un.varWords[1]);
1785 lpfc_debugfs_disc_trc(phba->pport,
1787 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1788 (uint32_t)pmbox->mbxCommand,
1789 pmbox->un.varWords[0],
1790 pmbox->un.varWords[1]);
1795 * It is a fatal error if unknown mbox command completion.
1797 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
1799 /* Unknow mailbox command compl */
1800 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1801 "(%d):0323 Unknown Mailbox command "
1803 pmb->vport ? pmb->vport->vpi : 0,
1805 lpfc_sli4_mbox_opcode_get(phba, pmb));
1806 phba->link_state = LPFC_HBA_ERROR;
1807 phba->work_hs = HS_FFER3;
1808 lpfc_handle_eratt(phba);
1812 if (pmbox->mbxStatus) {
1813 phba->sli.slistat.mbox_stat_err++;
1814 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
1815 /* Mbox cmd cmpl error - RETRYing */
1816 lpfc_printf_log(phba, KERN_INFO,
1818 "(%d):0305 Mbox cmd cmpl "
1819 "error - RETRYing Data: x%x "
1820 "(x%x) x%x x%x x%x\n",
1821 pmb->vport ? pmb->vport->vpi :0,
1823 lpfc_sli4_mbox_opcode_get(phba,
1826 pmbox->un.varWords[0],
1827 pmb->vport->port_state);
1828 pmbox->mbxStatus = 0;
1829 pmbox->mbxOwner = OWN_HOST;
1830 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1831 if (rc != MBX_NOT_FINISHED)
1836 /* Mailbox cmd <cmd> Cmpl <cmpl> */
1837 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
1838 "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
1839 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1840 pmb->vport ? pmb->vport->vpi : 0,
1842 lpfc_sli4_mbox_opcode_get(phba, pmb),
1844 *((uint32_t *) pmbox),
1845 pmbox->un.varWords[0],
1846 pmbox->un.varWords[1],
1847 pmbox->un.varWords[2],
1848 pmbox->un.varWords[3],
1849 pmbox->un.varWords[4],
1850 pmbox->un.varWords[5],
1851 pmbox->un.varWords[6],
1852 pmbox->un.varWords[7]);
1855 pmb->mbox_cmpl(phba,pmb);
1861 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
1862 * @phba: Pointer to HBA context object.
1863 * @pring: Pointer to driver SLI ring object.
1866 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1867 * is set in the tag the buffer is posted for a particular exchange,
1868 * the function will return the buffer without replacing the buffer.
1869 * If the buffer is for unsolicited ELS or CT traffic, this function
1870 * returns the buffer and also posts another buffer to the firmware.
1872 static struct lpfc_dmabuf *
1873 lpfc_sli_get_buff(struct lpfc_hba *phba,
1874 struct lpfc_sli_ring *pring,
1877 struct hbq_dmabuf *hbq_entry;
1879 if (tag & QUE_BUFTAG_BIT)
1880 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
1881 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
1884 return &hbq_entry->dbuf;
1888 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
1889 * @phba: Pointer to HBA context object.
1890 * @pring: Pointer to driver SLI ring object.
1891 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
1892 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
1893 * @fch_type: the type for the first frame of the sequence.
1895 * This function is called with no lock held. This function uses the r_ctl and
1896 * type of the received sequence to find the correct callback function to call
1897 * to process the sequence.
1900 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1901 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
1906 /* unSolicited Responses */
1907 if (pring->prt[0].profile) {
1908 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1909 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1913 /* We must search, based on rctl / type
1914 for the right routine */
1915 for (i = 0; i < pring->num_mask; i++) {
1916 if ((pring->prt[i].rctl == fch_r_ctl) &&
1917 (pring->prt[i].type == fch_type)) {
1918 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1919 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1920 (phba, pring, saveq);
1928 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
1929 * @phba: Pointer to HBA context object.
1930 * @pring: Pointer to driver SLI ring object.
1931 * @saveq: Pointer to the unsolicited iocb.
1933 * This function is called with no lock held by the ring event handler
1934 * when there is an unsolicited iocb posted to the response ring by the
1935 * firmware. This function gets the buffer associated with the iocbs
1936 * and calls the event handler for the ring. This function handles both
1937 * qring buffers and hbq buffers.
1938 * When the function returns 1 the caller can free the iocb object otherwise
1939 * upper layer functions will free the iocb objects.
1942 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1943 struct lpfc_iocbq *saveq)
1947 uint32_t Rctl, Type;
1949 struct lpfc_iocbq *iocbq;
1950 struct lpfc_dmabuf *dmzbuf;
1953 irsp = &(saveq->iocb);
1955 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
1956 if (pring->lpfc_sli_rcv_async_status)
1957 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
1959 lpfc_printf_log(phba,
1962 "0316 Ring %d handler: unexpected "
1963 "ASYNC_STATUS iocb received evt_code "
1966 irsp->un.asyncstat.evt_code);
1970 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
1971 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
1972 if (irsp->ulpBdeCount > 0) {
1973 dmzbuf = lpfc_sli_get_buff(phba, pring,
1974 irsp->un.ulpWord[3]);
1975 lpfc_in_buf_free(phba, dmzbuf);
1978 if (irsp->ulpBdeCount > 1) {
1979 dmzbuf = lpfc_sli_get_buff(phba, pring,
1980 irsp->unsli3.sli3Words[3]);
1981 lpfc_in_buf_free(phba, dmzbuf);
1984 if (irsp->ulpBdeCount > 2) {
1985 dmzbuf = lpfc_sli_get_buff(phba, pring,
1986 irsp->unsli3.sli3Words[7]);
1987 lpfc_in_buf_free(phba, dmzbuf);
1993 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1994 if (irsp->ulpBdeCount != 0) {
1995 saveq->context2 = lpfc_sli_get_buff(phba, pring,
1996 irsp->un.ulpWord[3]);
1997 if (!saveq->context2)
1998 lpfc_printf_log(phba,
2001 "0341 Ring %d Cannot find buffer for "
2002 "an unsolicited iocb. tag 0x%x\n",
2004 irsp->un.ulpWord[3]);
2006 if (irsp->ulpBdeCount == 2) {
2007 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2008 irsp->unsli3.sli3Words[7]);
2009 if (!saveq->context3)
2010 lpfc_printf_log(phba,
2013 "0342 Ring %d Cannot find buffer for an"
2014 " unsolicited iocb. tag 0x%x\n",
2016 irsp->unsli3.sli3Words[7]);
2018 list_for_each_entry(iocbq, &saveq->list, list) {
2019 irsp = &(iocbq->iocb);
2020 if (irsp->ulpBdeCount != 0) {
2021 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2022 irsp->un.ulpWord[3]);
2023 if (!iocbq->context2)
2024 lpfc_printf_log(phba,
2027 "0343 Ring %d Cannot find "
2028 "buffer for an unsolicited iocb"
2029 ". tag 0x%x\n", pring->ringno,
2030 irsp->un.ulpWord[3]);
2032 if (irsp->ulpBdeCount == 2) {
2033 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2034 irsp->unsli3.sli3Words[7]);
2035 if (!iocbq->context3)
2036 lpfc_printf_log(phba,
2039 "0344 Ring %d Cannot find "
2040 "buffer for an unsolicited "
2043 irsp->unsli3.sli3Words[7]);
2047 if (irsp->ulpBdeCount != 0 &&
2048 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2049 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2052 /* search continue save q for same XRI */
2053 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2054 if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
2055 list_add_tail(&saveq->list, &iocbq->list);
2061 list_add_tail(&saveq->clist,
2062 &pring->iocb_continue_saveq);
2063 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2064 list_del_init(&iocbq->clist);
2066 irsp = &(saveq->iocb);
2070 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2071 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2072 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2076 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2077 Rctl = w5p->hcsw.Rctl;
2078 Type = w5p->hcsw.Type;
2080 /* Firmware Workaround */
2081 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2082 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2083 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2086 w5p->hcsw.Rctl = Rctl;
2087 w5p->hcsw.Type = Type;
2091 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2092 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2093 "0313 Ring %d handler: unexpected Rctl x%x "
2094 "Type x%x received\n",
2095 pring->ringno, Rctl, Type);
2101 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2102 * @phba: Pointer to HBA context object.
2103 * @pring: Pointer to driver SLI ring object.
2104 * @prspiocb: Pointer to response iocb object.
2106 * This function looks up the iocb_lookup table to get the command iocb
2107 * corresponding to the given response iocb using the iotag of the
2108 * response iocb. This function is called with the hbalock held.
2109 * This function returns the command iocb object if it finds the command
2110 * iocb else returns NULL.
2112 static struct lpfc_iocbq *
2113 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2114 struct lpfc_sli_ring *pring,
2115 struct lpfc_iocbq *prspiocb)
2117 struct lpfc_iocbq *cmd_iocb = NULL;
2120 iotag = prspiocb->iocb.ulpIoTag;
2122 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2123 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2124 list_del_init(&cmd_iocb->list);
2125 pring->txcmplq_cnt--;
2129 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2130 "0317 iotag x%x is out off "
2131 "range: max iotag x%x wd0 x%x\n",
2132 iotag, phba->sli.last_iotag,
2133 *(((uint32_t *) &prspiocb->iocb) + 7));
2138 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2139 * @phba: Pointer to HBA context object.
2140 * @pring: Pointer to driver SLI ring object.
2143 * This function looks up the iocb_lookup table to get the command iocb
2144 * corresponding to the given iotag. This function is called with the
2146 * This function returns the command iocb object if it finds the command
2147 * iocb else returns NULL.
2149 static struct lpfc_iocbq *
2150 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2151 struct lpfc_sli_ring *pring, uint16_t iotag)
2153 struct lpfc_iocbq *cmd_iocb;
2155 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2156 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2157 list_del_init(&cmd_iocb->list);
2158 pring->txcmplq_cnt--;
2162 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2163 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2164 iotag, phba->sli.last_iotag);
2169 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2170 * @phba: Pointer to HBA context object.
2171 * @pring: Pointer to driver SLI ring object.
2172 * @saveq: Pointer to the response iocb to be processed.
2174 * This function is called by the ring event handler for non-fcp
2175 * rings when there is a new response iocb in the response ring.
2176 * The caller is not required to hold any locks. This function
2177 * gets the command iocb associated with the response iocb and
2178 * calls the completion handler for the command iocb. If there
2179 * is no completion handler, the function will free the resources
2180 * associated with command iocb. If the response iocb is for
2181 * an already aborted command iocb, the status of the completion
2182 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2183 * This function always returns 1.
2186 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2187 struct lpfc_iocbq *saveq)
2189 struct lpfc_iocbq *cmdiocbp;
2191 unsigned long iflag;
2193 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2194 spin_lock_irqsave(&phba->hbalock, iflag);
2195 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
2196 spin_unlock_irqrestore(&phba->hbalock, iflag);
2199 if (cmdiocbp->iocb_cmpl) {
2201 * If an ELS command failed send an event to mgmt
2204 if (saveq->iocb.ulpStatus &&
2205 (pring->ringno == LPFC_ELS_RING) &&
2206 (cmdiocbp->iocb.ulpCommand ==
2207 CMD_ELS_REQUEST64_CR))
2208 lpfc_send_els_failure_event(phba,
2212 * Post all ELS completions to the worker thread.
2213 * All other are passed to the completion callback.
2215 if (pring->ringno == LPFC_ELS_RING) {
2216 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
2217 cmdiocbp->iocb_flag &=
2218 ~LPFC_DRIVER_ABORTED;
2219 saveq->iocb.ulpStatus =
2220 IOSTAT_LOCAL_REJECT;
2221 saveq->iocb.un.ulpWord[4] =
2224 /* Firmware could still be in progress
2225 * of DMAing payload, so don't free data
2226 * buffer till after a hbeat.
2228 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2231 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
2233 lpfc_sli_release_iocbq(phba, cmdiocbp);
2236 * Unknown initiating command based on the response iotag.
2237 * This could be the case on the ELS ring because of
2240 if (pring->ringno != LPFC_ELS_RING) {
2242 * Ring <ringno> handler: unexpected completion IoTag
2245 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2246 "0322 Ring %d handler: "
2247 "unexpected completion IoTag x%x "
2248 "Data: x%x x%x x%x x%x\n",
2250 saveq->iocb.ulpIoTag,
2251 saveq->iocb.ulpStatus,
2252 saveq->iocb.un.ulpWord[4],
2253 saveq->iocb.ulpCommand,
2254 saveq->iocb.ulpContext);
2262 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2263 * @phba: Pointer to HBA context object.
2264 * @pring: Pointer to driver SLI ring object.
2266 * This function is called from the iocb ring event handlers when
2267 * put pointer is ahead of the get pointer for a ring. This function signal
2268 * an error attention condition to the worker thread and the worker
2269 * thread will transition the HBA to offline state.
2272 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2274 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2276 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2277 * rsp ring <portRspMax>
2279 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2280 "0312 Ring %d handler: portRspPut %d "
2281 "is bigger than rsp ring %d\n",
2282 pring->ringno, le32_to_cpu(pgp->rspPutInx),
2285 phba->link_state = LPFC_HBA_ERROR;
2288 * All error attention handlers are posted to
2291 phba->work_ha |= HA_ERATT;
2292 phba->work_hs = HS_FFER3;
2294 lpfc_worker_wake_up(phba);
2300 * lpfc_poll_eratt - Error attention polling timer timeout handler
2301 * @ptr: Pointer to address of HBA context object.
2303 * This function is invoked by the Error Attention polling timer when the
2304 * timer times out. It will check the SLI Error Attention register for
2305 * possible attention events. If so, it will post an Error Attention event
2306 * and wake up worker thread to process it. Otherwise, it will set up the
2307 * Error Attention polling timer for the next poll.
2309 void lpfc_poll_eratt(unsigned long ptr)
2311 struct lpfc_hba *phba;
2314 phba = (struct lpfc_hba *)ptr;
2316 /* Check chip HA register for error event */
2317 eratt = lpfc_sli_check_eratt(phba);
2320 /* Tell the worker thread there is work to do */
2321 lpfc_worker_wake_up(phba);
2323 /* Restart the timer for next eratt poll */
2324 mod_timer(&phba->eratt_poll, jiffies +
2325 HZ * LPFC_ERATT_POLL_INTERVAL);
2330 * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
2331 * @phba: Pointer to HBA context object.
2333 * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
2334 * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
2337 * The caller does not hold any lock.
2338 * The function processes each response iocb in the response ring until it
2339 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2340 * LE bit set. The function will call the completion handler of the command iocb
2341 * if the response iocb indicates a completion for a command iocb or it is
2342 * an abort completion.
2344 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
2346 struct lpfc_sli *psli = &phba->sli;
2347 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
2348 IOCB_t *irsp = NULL;
2349 IOCB_t *entry = NULL;
2350 struct lpfc_iocbq *cmdiocbq = NULL;
2351 struct lpfc_iocbq rspiocbq;
2352 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2354 uint32_t portRspPut, portRspMax;
2356 uint32_t rsp_cmpl = 0;
2358 unsigned long iflags;
2360 pring->stats.iocb_event++;
2363 * The next available response entry should never exceed the maximum
2364 * entries. If it does, treat it as an adapter hardware error.
2366 portRspMax = pring->numRiocb;
2367 portRspPut = le32_to_cpu(pgp->rspPutInx);
2368 if (unlikely(portRspPut >= portRspMax)) {
2369 lpfc_sli_rsp_pointers_error(phba, pring);
2374 while (pring->rspidx != portRspPut) {
2375 entry = lpfc_resp_iocb(phba, pring);
2376 if (++pring->rspidx >= portRspMax)
2379 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2380 (uint32_t *) &rspiocbq.iocb,
2381 phba->iocb_rsp_size);
2382 irsp = &rspiocbq.iocb;
2383 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2384 pring->stats.iocb_rsp++;
2387 if (unlikely(irsp->ulpStatus)) {
2388 /* Rsp ring <ringno> error: IOCB */
2389 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2390 "0326 Rsp Ring %d error: IOCB Data: "
2391 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2393 irsp->un.ulpWord[0],
2394 irsp->un.ulpWord[1],
2395 irsp->un.ulpWord[2],
2396 irsp->un.ulpWord[3],
2397 irsp->un.ulpWord[4],
2398 irsp->un.ulpWord[5],
2399 *(uint32_t *)&irsp->un1,
2400 *((uint32_t *)&irsp->un1 + 1));
2404 case LPFC_ABORT_IOCB:
2407 * Idle exchange closed via ABTS from port. No iocb
2408 * resources need to be recovered.
2410 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2411 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2412 "0314 IOCB cmd 0x%x "
2413 "processed. Skipping "
2419 spin_lock_irqsave(&phba->hbalock, iflags);
2420 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2422 spin_unlock_irqrestore(&phba->hbalock, iflags);
2423 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
2424 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2429 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2430 char adaptermsg[LPFC_MAX_ADPTMSG];
2431 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2432 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2434 dev_warn(&((phba->pcidev)->dev),
2436 phba->brd_no, adaptermsg);
2438 /* Unknown IOCB command */
2439 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2440 "0321 Unknown IOCB command "
2441 "Data: x%x, x%x x%x x%x x%x\n",
2442 type, irsp->ulpCommand,
2451 * The response IOCB has been processed. Update the ring
2452 * pointer in SLIM. If the port response put pointer has not
2453 * been updated, sync the pgp->rspPutInx and fetch the new port
2454 * response put pointer.
2456 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2458 if (pring->rspidx == portRspPut)
2459 portRspPut = le32_to_cpu(pgp->rspPutInx);
2462 ha_copy = readl(phba->HAregaddr);
2463 ha_copy >>= (LPFC_FCP_RING * 4);
2465 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
2466 spin_lock_irqsave(&phba->hbalock, iflags);
2467 pring->stats.iocb_rsp_full++;
2468 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
2469 writel(status, phba->CAregaddr);
2470 readl(phba->CAregaddr);
2471 spin_unlock_irqrestore(&phba->hbalock, iflags);
2473 if ((ha_copy & HA_R0CE_RSP) &&
2474 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2475 spin_lock_irqsave(&phba->hbalock, iflags);
2476 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2477 pring->stats.iocb_cmd_empty++;
2479 /* Force update of the local copy of cmdGetInx */
2480 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2481 lpfc_sli_resume_iocb(phba, pring);
2483 if ((pring->lpfc_sli_cmd_available))
2484 (pring->lpfc_sli_cmd_available) (phba, pring);
2486 spin_unlock_irqrestore(&phba->hbalock, iflags);
2493 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2494 * @phba: Pointer to HBA context object.
2495 * @pring: Pointer to driver SLI ring object.
2496 * @mask: Host attention register mask for this ring.
2498 * This function is called from the interrupt context when there is a ring
2499 * event for the fcp ring. The caller does not hold any lock.
2500 * The function processes each response iocb in the response ring until it
2501 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2502 * LE bit set. The function will call the completion handler of the command iocb
2503 * if the response iocb indicates a completion for a command iocb or it is
2504 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2505 * function if this is an unsolicited iocb.
2506 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2507 * to check it explicitly. This function always returns 1.
2510 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
2511 struct lpfc_sli_ring *pring, uint32_t mask)
2513 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2514 IOCB_t *irsp = NULL;
2515 IOCB_t *entry = NULL;
2516 struct lpfc_iocbq *cmdiocbq = NULL;
2517 struct lpfc_iocbq rspiocbq;
2519 uint32_t portRspPut, portRspMax;
2521 lpfc_iocb_type type;
2522 unsigned long iflag;
2523 uint32_t rsp_cmpl = 0;
2525 spin_lock_irqsave(&phba->hbalock, iflag);
2526 pring->stats.iocb_event++;
2529 * The next available response entry should never exceed the maximum
2530 * entries. If it does, treat it as an adapter hardware error.
2532 portRspMax = pring->numRiocb;
2533 portRspPut = le32_to_cpu(pgp->rspPutInx);
2534 if (unlikely(portRspPut >= portRspMax)) {
2535 lpfc_sli_rsp_pointers_error(phba, pring);
2536 spin_unlock_irqrestore(&phba->hbalock, iflag);
2541 while (pring->rspidx != portRspPut) {
2543 * Fetch an entry off the ring and copy it into a local data
2544 * structure. The copy involves a byte-swap since the
2545 * network byte order and pci byte orders are different.
2547 entry = lpfc_resp_iocb(phba, pring);
2548 phba->last_completion_time = jiffies;
2550 if (++pring->rspidx >= portRspMax)
2553 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2554 (uint32_t *) &rspiocbq.iocb,
2555 phba->iocb_rsp_size);
2556 INIT_LIST_HEAD(&(rspiocbq.list));
2557 irsp = &rspiocbq.iocb;
2559 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2560 pring->stats.iocb_rsp++;
2563 if (unlikely(irsp->ulpStatus)) {
2565 * If resource errors reported from HBA, reduce
2566 * queuedepths of the SCSI device.
2568 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2569 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2570 spin_unlock_irqrestore(&phba->hbalock, iflag);
2571 phba->lpfc_rampdown_queue_depth(phba);
2572 spin_lock_irqsave(&phba->hbalock, iflag);
2575 /* Rsp ring <ringno> error: IOCB */
2576 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2577 "0336 Rsp Ring %d error: IOCB Data: "
2578 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2580 irsp->un.ulpWord[0],
2581 irsp->un.ulpWord[1],
2582 irsp->un.ulpWord[2],
2583 irsp->un.ulpWord[3],
2584 irsp->un.ulpWord[4],
2585 irsp->un.ulpWord[5],
2586 *(uint32_t *)&irsp->un1,
2587 *((uint32_t *)&irsp->un1 + 1));
2591 case LPFC_ABORT_IOCB:
2594 * Idle exchange closed via ABTS from port. No iocb
2595 * resources need to be recovered.
2597 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2598 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2599 "0333 IOCB cmd 0x%x"
2600 " processed. Skipping"
2606 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2608 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
2609 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
2610 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2613 spin_unlock_irqrestore(&phba->hbalock,
2615 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2617 spin_lock_irqsave(&phba->hbalock,
2622 case LPFC_UNSOL_IOCB:
2623 spin_unlock_irqrestore(&phba->hbalock, iflag);
2624 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
2625 spin_lock_irqsave(&phba->hbalock, iflag);
2628 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2629 char adaptermsg[LPFC_MAX_ADPTMSG];
2630 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2631 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2633 dev_warn(&((phba->pcidev)->dev),
2635 phba->brd_no, adaptermsg);
2637 /* Unknown IOCB command */
2638 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2639 "0334 Unknown IOCB command "
2640 "Data: x%x, x%x x%x x%x x%x\n",
2641 type, irsp->ulpCommand,
2650 * The response IOCB has been processed. Update the ring
2651 * pointer in SLIM. If the port response put pointer has not
2652 * been updated, sync the pgp->rspPutInx and fetch the new port
2653 * response put pointer.
2655 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2657 if (pring->rspidx == portRspPut)
2658 portRspPut = le32_to_cpu(pgp->rspPutInx);
2661 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
2662 pring->stats.iocb_rsp_full++;
2663 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2664 writel(status, phba->CAregaddr);
2665 readl(phba->CAregaddr);
2667 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2668 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2669 pring->stats.iocb_cmd_empty++;
2671 /* Force update of the local copy of cmdGetInx */
2672 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2673 lpfc_sli_resume_iocb(phba, pring);
2675 if ((pring->lpfc_sli_cmd_available))
2676 (pring->lpfc_sli_cmd_available) (phba, pring);
2680 spin_unlock_irqrestore(&phba->hbalock, iflag);
2685 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
2686 * @phba: Pointer to HBA context object.
2687 * @pring: Pointer to driver SLI ring object.
2688 * @rspiocbp: Pointer to driver response IOCB object.
2690 * This function is called from the worker thread when there is a slow-path
2691 * response IOCB to process. This function chains all the response iocbs until
2692 * seeing the iocb with the LE bit set. The function will call
2693 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
2694 * completion of a command iocb. The function will call the
2695 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
2696 * The function frees the resources or calls the completion handler if this
2697 * iocb is an abort completion. The function returns NULL when the response
2698 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
2699 * this function shall chain the iocb on to the iocb_continueq and return the
2700 * response iocb passed in.
2702 static struct lpfc_iocbq *
2703 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2704 struct lpfc_iocbq *rspiocbp)
2706 struct lpfc_iocbq *saveq;
2707 struct lpfc_iocbq *cmdiocbp;
2708 struct lpfc_iocbq *next_iocb;
2709 IOCB_t *irsp = NULL;
2710 uint32_t free_saveq;
2711 uint8_t iocb_cmd_type;
2712 lpfc_iocb_type type;
2713 unsigned long iflag;
2716 spin_lock_irqsave(&phba->hbalock, iflag);
2717 /* First add the response iocb to the countinueq list */
2718 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
2719 pring->iocb_continueq_cnt++;
2721 /* Now, determine whetehr the list is completed for processing */
2722 irsp = &rspiocbp->iocb;
2725 * By default, the driver expects to free all resources
2726 * associated with this iocb completion.
2729 saveq = list_get_first(&pring->iocb_continueq,
2730 struct lpfc_iocbq, list);
2731 irsp = &(saveq->iocb);
2732 list_del_init(&pring->iocb_continueq);
2733 pring->iocb_continueq_cnt = 0;
2735 pring->stats.iocb_rsp++;
2738 * If resource errors reported from HBA, reduce
2739 * queuedepths of the SCSI device.
2741 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2742 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2743 spin_unlock_irqrestore(&phba->hbalock, iflag);
2744 phba->lpfc_rampdown_queue_depth(phba);
2745 spin_lock_irqsave(&phba->hbalock, iflag);
2748 if (irsp->ulpStatus) {
2749 /* Rsp ring <ringno> error: IOCB */
2750 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2751 "0328 Rsp Ring %d error: "
2756 "x%x x%x x%x x%x\n",
2758 irsp->un.ulpWord[0],
2759 irsp->un.ulpWord[1],
2760 irsp->un.ulpWord[2],
2761 irsp->un.ulpWord[3],
2762 irsp->un.ulpWord[4],
2763 irsp->un.ulpWord[5],
2764 *(((uint32_t *) irsp) + 6),
2765 *(((uint32_t *) irsp) + 7),
2766 *(((uint32_t *) irsp) + 8),
2767 *(((uint32_t *) irsp) + 9),
2768 *(((uint32_t *) irsp) + 10),
2769 *(((uint32_t *) irsp) + 11),
2770 *(((uint32_t *) irsp) + 12),
2771 *(((uint32_t *) irsp) + 13),
2772 *(((uint32_t *) irsp) + 14),
2773 *(((uint32_t *) irsp) + 15));
2777 * Fetch the IOCB command type and call the correct completion
2778 * routine. Solicited and Unsolicited IOCBs on the ELS ring
2779 * get freed back to the lpfc_iocb_list by the discovery
2782 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
2783 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
2786 spin_unlock_irqrestore(&phba->hbalock, iflag);
2787 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
2788 spin_lock_irqsave(&phba->hbalock, iflag);
2791 case LPFC_UNSOL_IOCB:
2792 spin_unlock_irqrestore(&phba->hbalock, iflag);
2793 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
2794 spin_lock_irqsave(&phba->hbalock, iflag);
2799 case LPFC_ABORT_IOCB:
2801 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
2802 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
2805 /* Call the specified completion routine */
2806 if (cmdiocbp->iocb_cmpl) {
2807 spin_unlock_irqrestore(&phba->hbalock,
2809 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
2811 spin_lock_irqsave(&phba->hbalock,
2814 __lpfc_sli_release_iocbq(phba,
2819 case LPFC_UNKNOWN_IOCB:
2820 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2821 char adaptermsg[LPFC_MAX_ADPTMSG];
2822 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2823 memcpy(&adaptermsg[0], (uint8_t *)irsp,
2825 dev_warn(&((phba->pcidev)->dev),
2827 phba->brd_no, adaptermsg);
2829 /* Unknown IOCB command */
2830 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2831 "0335 Unknown IOCB "
2832 "command Data: x%x "
2843 list_for_each_entry_safe(rspiocbp, next_iocb,
2844 &saveq->list, list) {
2845 list_del(&rspiocbp->list);
2846 __lpfc_sli_release_iocbq(phba, rspiocbp);
2848 __lpfc_sli_release_iocbq(phba, saveq);
2852 spin_unlock_irqrestore(&phba->hbalock, iflag);
2857 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
2858 * @phba: Pointer to HBA context object.
2859 * @pring: Pointer to driver SLI ring object.
2860 * @mask: Host attention register mask for this ring.
2862 * This routine wraps the actual slow_ring event process routine from the
2863 * API jump table function pointer from the lpfc_hba struct.
2866 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
2867 struct lpfc_sli_ring *pring, uint32_t mask)
2869 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
2873 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
2874 * @phba: Pointer to HBA context object.
2875 * @pring: Pointer to driver SLI ring object.
2876 * @mask: Host attention register mask for this ring.
2878 * This function is called from the worker thread when there is a ring event
2879 * for non-fcp rings. The caller does not hold any lock. The function will
2880 * remove each response iocb in the response ring and calls the handle
2881 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2884 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
2885 struct lpfc_sli_ring *pring, uint32_t mask)
2887 struct lpfc_pgp *pgp;
2889 IOCB_t *irsp = NULL;
2890 struct lpfc_iocbq *rspiocbp = NULL;
2891 uint32_t portRspPut, portRspMax;
2892 unsigned long iflag;
2895 pgp = &phba->port_gp[pring->ringno];
2896 spin_lock_irqsave(&phba->hbalock, iflag);
2897 pring->stats.iocb_event++;
2900 * The next available response entry should never exceed the maximum
2901 * entries. If it does, treat it as an adapter hardware error.
2903 portRspMax = pring->numRiocb;
2904 portRspPut = le32_to_cpu(pgp->rspPutInx);
2905 if (portRspPut >= portRspMax) {
2907 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2908 * rsp ring <portRspMax>
2910 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2911 "0303 Ring %d handler: portRspPut %d "
2912 "is bigger than rsp ring %d\n",
2913 pring->ringno, portRspPut, portRspMax);
2915 phba->link_state = LPFC_HBA_ERROR;
2916 spin_unlock_irqrestore(&phba->hbalock, iflag);
2918 phba->work_hs = HS_FFER3;
2919 lpfc_handle_eratt(phba);
2925 while (pring->rspidx != portRspPut) {
2927 * Build a completion list and call the appropriate handler.
2928 * The process is to get the next available response iocb, get
2929 * a free iocb from the list, copy the response data into the
2930 * free iocb, insert to the continuation list, and update the
2931 * next response index to slim. This process makes response
2932 * iocb's in the ring available to DMA as fast as possible but
2933 * pays a penalty for a copy operation. Since the iocb is
2934 * only 32 bytes, this penalty is considered small relative to
2935 * the PCI reads for register values and a slim write. When
2936 * the ulpLe field is set, the entire Command has been
2939 entry = lpfc_resp_iocb(phba, pring);
2941 phba->last_completion_time = jiffies;
2942 rspiocbp = __lpfc_sli_get_iocbq(phba);
2943 if (rspiocbp == NULL) {
2944 printk(KERN_ERR "%s: out of buffers! Failing "
2945 "completion.\n", __func__);
2949 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
2950 phba->iocb_rsp_size);
2951 irsp = &rspiocbp->iocb;
2953 if (++pring->rspidx >= portRspMax)
2956 if (pring->ringno == LPFC_ELS_RING) {
2957 lpfc_debugfs_slow_ring_trc(phba,
2958 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2959 *(((uint32_t *) irsp) + 4),
2960 *(((uint32_t *) irsp) + 6),
2961 *(((uint32_t *) irsp) + 7));
2964 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2966 spin_unlock_irqrestore(&phba->hbalock, iflag);
2967 /* Handle the response IOCB */
2968 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
2969 spin_lock_irqsave(&phba->hbalock, iflag);
2972 * If the port response put pointer has not been updated, sync
2973 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
2974 * response put pointer.
2976 if (pring->rspidx == portRspPut) {
2977 portRspPut = le32_to_cpu(pgp->rspPutInx);
2979 } /* while (pring->rspidx != portRspPut) */
2981 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
2982 /* At least one response entry has been freed */
2983 pring->stats.iocb_rsp_full++;
2984 /* SET RxRE_RSP in Chip Att register */
2985 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2986 writel(status, phba->CAregaddr);
2987 readl(phba->CAregaddr); /* flush */
2989 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2990 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2991 pring->stats.iocb_cmd_empty++;
2993 /* Force update of the local copy of cmdGetInx */
2994 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2995 lpfc_sli_resume_iocb(phba, pring);
2997 if ((pring->lpfc_sli_cmd_available))
2998 (pring->lpfc_sli_cmd_available) (phba, pring);
3002 spin_unlock_irqrestore(&phba->hbalock, iflag);
3007 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3008 * @phba: Pointer to HBA context object.
3009 * @pring: Pointer to driver SLI ring object.
3010 * @mask: Host attention register mask for this ring.
3012 * This function is called from the worker thread when there is a pending
3013 * ELS response iocb on the driver internal slow-path response iocb worker
3014 * queue. The caller does not hold any lock. The function will remove each
3015 * response iocb from the response worker queue and calls the handle
3016 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3019 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3020 struct lpfc_sli_ring *pring, uint32_t mask)
3022 struct lpfc_iocbq *irspiocbq;
3023 struct hbq_dmabuf *dmabuf;
3024 struct lpfc_cq_event *cq_event;
3025 unsigned long iflag;
3027 while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) {
3028 /* Get the response iocb from the head of work queue */
3029 spin_lock_irqsave(&phba->hbalock, iflag);
3030 list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue,
3031 cq_event, struct lpfc_cq_event, list);
3032 spin_unlock_irqrestore(&phba->hbalock, iflag);
3034 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
3035 case CQE_CODE_COMPL_WQE:
3036 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
3038 lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq);
3040 case CQE_CODE_RECEIVE:
3041 dmabuf = container_of(cq_event, struct hbq_dmabuf,
3043 lpfc_sli4_handle_received_buffer(phba, dmabuf);
3052 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3053 * @phba: Pointer to HBA context object.
3054 * @pring: Pointer to driver SLI ring object.
3056 * This function aborts all iocbs in the given ring and frees all the iocb
3057 * objects in txq. This function issues an abort iocb for all the iocb commands
3058 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3059 * the return of this function. The caller is not required to hold any locks.
3062 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3064 LIST_HEAD(completions);
3065 struct lpfc_iocbq *iocb, *next_iocb;
3067 if (pring->ringno == LPFC_ELS_RING) {
3068 lpfc_fabric_abort_hba(phba);
3071 /* Error everything on txq and txcmplq
3074 spin_lock_irq(&phba->hbalock);
3075 list_splice_init(&pring->txq, &completions);
3078 /* Next issue ABTS for everything on the txcmplq */
3079 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3080 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3082 spin_unlock_irq(&phba->hbalock);
3084 /* Cancel all the IOCBs from the completions list */
3085 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3090 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3091 * @phba: Pointer to HBA context object.
3093 * This function flushes all iocbs in the fcp ring and frees all the iocb
3094 * objects in txq and txcmplq. This function will not issue abort iocbs
3095 * for all the iocb commands in txcmplq, they will just be returned with
3096 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3097 * slot has been permanently disabled.
3100 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3104 struct lpfc_sli *psli = &phba->sli;
3105 struct lpfc_sli_ring *pring;
3107 /* Currently, only one fcp ring */
3108 pring = &psli->ring[psli->fcp_ring];
3110 spin_lock_irq(&phba->hbalock);
3111 /* Retrieve everything on txq */
3112 list_splice_init(&pring->txq, &txq);
3115 /* Retrieve everything on the txcmplq */
3116 list_splice_init(&pring->txcmplq, &txcmplq);
3117 pring->txcmplq_cnt = 0;
3118 spin_unlock_irq(&phba->hbalock);
3121 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3124 /* Flush the txcmpq */
3125 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3130 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3131 * @phba: Pointer to HBA context object.
3132 * @mask: Bit mask to be checked.
3134 * This function reads the host status register and compares
3135 * with the provided bit mask to check if HBA completed
3136 * the restart. This function will wait in a loop for the
3137 * HBA to complete restart. If the HBA does not restart within
3138 * 15 iterations, the function will reset the HBA again. The
3139 * function returns 1 when HBA fail to restart otherwise returns
3143 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
3149 /* Read the HBA Host Status Register */
3150 status = readl(phba->HSregaddr);
3153 * Check status register every 100ms for 5 retries, then every
3154 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3155 * every 2.5 sec for 4.
3156 * Break our of the loop if errors occurred during init.
3158 while (((status & mask) != mask) &&
3159 !(status & HS_FFERM) &&
3171 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3172 lpfc_sli_brdrestart(phba);
3174 /* Read the HBA Host Status Register */
3175 status = readl(phba->HSregaddr);
3178 /* Check to see if any errors occurred during init */
3179 if ((status & HS_FFERM) || (i >= 20)) {
3180 phba->link_state = LPFC_HBA_ERROR;
3188 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3189 * @phba: Pointer to HBA context object.
3190 * @mask: Bit mask to be checked.
3192 * This function checks the host status register to check if HBA is
3193 * ready. This function will wait in a loop for the HBA to be ready
3194 * If the HBA is not ready , the function will will reset the HBA PCI
3195 * function again. The function returns 1 when HBA fail to be ready
3196 * otherwise returns zero.
3199 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3204 /* Read the HBA Host Status Register */
3205 status = lpfc_sli4_post_status_check(phba);
3208 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3209 lpfc_sli_brdrestart(phba);
3210 status = lpfc_sli4_post_status_check(phba);
3213 /* Check to see if any errors occurred during init */
3215 phba->link_state = LPFC_HBA_ERROR;
3218 phba->sli4_hba.intr_enable = 0;
3224 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3225 * @phba: Pointer to HBA context object.
3226 * @mask: Bit mask to be checked.
3228 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3229 * from the API jump table function pointer from the lpfc_hba struct.
3232 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3234 return phba->lpfc_sli_brdready(phba, mask);
3237 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3240 * lpfc_reset_barrier - Make HBA ready for HBA reset
3241 * @phba: Pointer to HBA context object.
3243 * This function is called before resetting an HBA. This
3244 * function requests HBA to quiesce DMAs before a reset.
3246 void lpfc_reset_barrier(struct lpfc_hba *phba)
3248 uint32_t __iomem *resp_buf;
3249 uint32_t __iomem *mbox_buf;
3250 volatile uint32_t mbox;
3255 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3256 if (hdrtype != 0x80 ||
3257 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3258 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3262 * Tell the other part of the chip to suspend temporarily all
3265 resp_buf = phba->MBslimaddr;
3267 /* Disable the error attention */
3268 hc_copy = readl(phba->HCregaddr);
3269 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3270 readl(phba->HCregaddr); /* flush */
3271 phba->link_flag |= LS_IGNORE_ERATT;
3273 if (readl(phba->HAregaddr) & HA_ERATT) {
3274 /* Clear Chip error bit */
3275 writel(HA_ERATT, phba->HAregaddr);
3276 phba->pport->stopped = 1;
3280 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
3281 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
3283 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
3284 mbox_buf = phba->MBslimaddr;
3285 writel(mbox, mbox_buf);
3288 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
3291 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
3292 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
3293 phba->pport->stopped)
3299 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
3300 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
3305 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
3308 if (readl(phba->HAregaddr) & HA_ERATT) {
3309 writel(HA_ERATT, phba->HAregaddr);
3310 phba->pport->stopped = 1;
3314 phba->link_flag &= ~LS_IGNORE_ERATT;
3315 writel(hc_copy, phba->HCregaddr);
3316 readl(phba->HCregaddr); /* flush */
3320 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3321 * @phba: Pointer to HBA context object.
3323 * This function issues a kill_board mailbox command and waits for
3324 * the error attention interrupt. This function is called for stopping
3325 * the firmware processing. The caller is not required to hold any
3326 * locks. This function calls lpfc_hba_down_post function to free
3327 * any pending commands after the kill. The function will return 1 when it
3328 * fails to kill the board else will return 0.
3331 lpfc_sli_brdkill(struct lpfc_hba *phba)
3333 struct lpfc_sli *psli;
3343 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3344 "0329 Kill HBA Data: x%x x%x\n",
3345 phba->pport->port_state, psli->sli_flag);
3347 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3351 /* Disable the error attention */
3352 spin_lock_irq(&phba->hbalock);
3353 status = readl(phba->HCregaddr);
3354 status &= ~HC_ERINT_ENA;
3355 writel(status, phba->HCregaddr);
3356 readl(phba->HCregaddr); /* flush */
3357 phba->link_flag |= LS_IGNORE_ERATT;
3358 spin_unlock_irq(&phba->hbalock);
3360 lpfc_kill_board(phba, pmb);
3361 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3362 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3364 if (retval != MBX_SUCCESS) {
3365 if (retval != MBX_BUSY)
3366 mempool_free(pmb, phba->mbox_mem_pool);
3367 spin_lock_irq(&phba->hbalock);
3368 phba->link_flag &= ~LS_IGNORE_ERATT;
3369 spin_unlock_irq(&phba->hbalock);
3373 spin_lock_irq(&phba->hbalock);
3374 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
3375 spin_unlock_irq(&phba->hbalock);
3377 mempool_free(pmb, phba->mbox_mem_pool);
3379 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3380 * attention every 100ms for 3 seconds. If we don't get ERATT after
3381 * 3 seconds we still set HBA_ERROR state because the status of the
3382 * board is now undefined.
3384 ha_copy = readl(phba->HAregaddr);
3386 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
3388 ha_copy = readl(phba->HAregaddr);
3391 del_timer_sync(&psli->mbox_tmo);
3392 if (ha_copy & HA_ERATT) {
3393 writel(HA_ERATT, phba->HAregaddr);
3394 phba->pport->stopped = 1;
3396 spin_lock_irq(&phba->hbalock);
3397 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3398 psli->mbox_active = NULL;
3399 phba->link_flag &= ~LS_IGNORE_ERATT;
3400 spin_unlock_irq(&phba->hbalock);
3402 lpfc_hba_down_post(phba);
3403 phba->link_state = LPFC_HBA_ERROR;
3405 return ha_copy & HA_ERATT ? 0 : 1;
3409 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3410 * @phba: Pointer to HBA context object.
3412 * This function resets the HBA by writing HC_INITFF to the control
3413 * register. After the HBA resets, this function resets all the iocb ring
3414 * indices. This function disables PCI layer parity checking during
3416 * This function returns 0 always.
3417 * The caller is not required to hold any locks.
3420 lpfc_sli_brdreset(struct lpfc_hba *phba)
3422 struct lpfc_sli *psli;
3423 struct lpfc_sli_ring *pring;
3430 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3431 "0325 Reset HBA Data: x%x x%x\n",
3432 phba->pport->port_state, psli->sli_flag);
3434 /* perform board reset */
3435 phba->fc_eventTag = 0;
3436 phba->link_events = 0;
3437 phba->pport->fc_myDID = 0;
3438 phba->pport->fc_prevDID = 0;
3440 /* Turn off parity checking and serr during the physical reset */
3441 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3442 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3444 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3446 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
3448 /* Now toggle INITFF bit in the Host Control Register */
3449 writel(HC_INITFF, phba->HCregaddr);
3451 readl(phba->HCregaddr); /* flush */
3452 writel(0, phba->HCregaddr);
3453 readl(phba->HCregaddr); /* flush */
3455 /* Restore PCI cmd register */
3456 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
3458 /* Initialize relevant SLI info */
3459 for (i = 0; i < psli->num_rings; i++) {
3460 pring = &psli->ring[i];
3463 pring->next_cmdidx = 0;
3464 pring->local_getidx = 0;
3466 pring->missbufcnt = 0;
3469 phba->link_state = LPFC_WARM_START;
3474 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3475 * @phba: Pointer to HBA context object.
3477 * This function resets a SLI4 HBA. This function disables PCI layer parity
3478 * checking during resets the device. The caller is not required to hold
3481 * This function returns 0 always.
3484 lpfc_sli4_brdreset(struct lpfc_hba *phba)
3486 struct lpfc_sli *psli = &phba->sli;
3491 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3492 "0295 Reset HBA Data: x%x x%x\n",
3493 phba->pport->port_state, psli->sli_flag);
3495 /* perform board reset */
3496 phba->fc_eventTag = 0;
3497 phba->link_events = 0;
3498 phba->pport->fc_myDID = 0;
3499 phba->pport->fc_prevDID = 0;
3501 /* Turn off parity checking and serr during the physical reset */
3502 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3503 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3505 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3507 spin_lock_irq(&phba->hbalock);
3508 psli->sli_flag &= ~(LPFC_PROCESS_LA);
3509 phba->fcf.fcf_flag = 0;
3510 /* Clean up the child queue list for the CQs */
3511 list_del_init(&phba->sli4_hba.mbx_wq->list);
3512 list_del_init(&phba->sli4_hba.els_wq->list);
3513 list_del_init(&phba->sli4_hba.hdr_rq->list);
3514 list_del_init(&phba->sli4_hba.dat_rq->list);
3515 list_del_init(&phba->sli4_hba.mbx_cq->list);
3516 list_del_init(&phba->sli4_hba.els_cq->list);
3517 for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
3518 list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
3519 for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
3520 list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
3521 spin_unlock_irq(&phba->hbalock);
3523 /* Now physically reset the device */
3524 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3525 "0389 Performing PCI function reset!\n");
3526 /* Perform FCoE PCI function reset */
3527 lpfc_pci_function_reset(phba);
3533 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3534 * @phba: Pointer to HBA context object.
3536 * This function is called in the SLI initialization code path to
3537 * restart the HBA. The caller is not required to hold any lock.
3538 * This function writes MBX_RESTART mailbox command to the SLIM and
3539 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3540 * function to free any pending commands. The function enables
3541 * POST only during the first initialization. The function returns zero.
3542 * The function does not guarantee completion of MBX_RESTART mailbox
3543 * command before the return of this function.
3546 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
3549 struct lpfc_sli *psli;
3550 volatile uint32_t word0;
3551 void __iomem *to_slim;
3553 spin_lock_irq(&phba->hbalock);
3558 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3559 "0337 Restart HBA Data: x%x x%x\n",
3560 phba->pport->port_state, psli->sli_flag);
3563 mb = (MAILBOX_t *) &word0;
3564 mb->mbxCommand = MBX_RESTART;
3567 lpfc_reset_barrier(phba);
3569 to_slim = phba->MBslimaddr;
3570 writel(*(uint32_t *) mb, to_slim);
3571 readl(to_slim); /* flush */
3573 /* Only skip post after fc_ffinit is completed */
3574 if (phba->pport->port_state)
3575 word0 = 1; /* This is really setting up word1 */
3577 word0 = 0; /* This is really setting up word1 */
3578 to_slim = phba->MBslimaddr + sizeof (uint32_t);
3579 writel(*(uint32_t *) mb, to_slim);
3580 readl(to_slim); /* flush */
3582 lpfc_sli_brdreset(phba);
3583 phba->pport->stopped = 0;
3584 phba->link_state = LPFC_INIT_START;
3586 spin_unlock_irq(&phba->hbalock);
3588 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3589 psli->stats_start = get_seconds();
3591 /* Give the INITFF and Post time to settle. */
3594 lpfc_hba_down_post(phba);
3600 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3601 * @phba: Pointer to HBA context object.
3603 * This function is called in the SLI initialization code path to restart
3604 * a SLI4 HBA. The caller is not required to hold any lock.
3605 * At the end of the function, it calls lpfc_hba_down_post function to
3606 * free any pending commands.
3609 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
3611 struct lpfc_sli *psli = &phba->sli;
3615 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3616 "0296 Restart HBA Data: x%x x%x\n",
3617 phba->pport->port_state, psli->sli_flag);
3619 lpfc_sli4_brdreset(phba);
3621 spin_lock_irq(&phba->hbalock);
3622 phba->pport->stopped = 0;
3623 phba->link_state = LPFC_INIT_START;
3625 spin_unlock_irq(&phba->hbalock);
3627 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
3628 psli->stats_start = get_seconds();
3630 lpfc_hba_down_post(phba);
3636 * lpfc_sli_brdrestart - Wrapper func for restarting hba
3637 * @phba: Pointer to HBA context object.
3639 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
3640 * API jump table function pointer from the lpfc_hba struct.
3643 lpfc_sli_brdrestart(struct lpfc_hba *phba)
3645 return phba->lpfc_sli_brdrestart(phba);
3649 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
3650 * @phba: Pointer to HBA context object.
3652 * This function is called after a HBA restart to wait for successful
3653 * restart of the HBA. Successful restart of the HBA is indicated by
3654 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
3655 * iteration, the function will restart the HBA again. The function returns
3656 * zero if HBA successfully restarted else returns negative error code.
3659 lpfc_sli_chipset_init(struct lpfc_hba *phba)
3661 uint32_t status, i = 0;
3663 /* Read the HBA Host Status Register */
3664 status = readl(phba->HSregaddr);
3666 /* Check status register to see what current state is */
3668 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
3670 /* Check every 100ms for 5 retries, then every 500ms for 5, then
3671 * every 2.5 sec for 5, then reset board and every 2.5 sec for
3675 /* Adapter failed to init, timeout, status reg
3677 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3678 "0436 Adapter failed to init, "
3679 "timeout, status reg x%x, "
3680 "FW Data: A8 x%x AC x%x\n", status,
3681 readl(phba->MBslimaddr + 0xa8),
3682 readl(phba->MBslimaddr + 0xac));
3683 phba->link_state = LPFC_HBA_ERROR;
3687 /* Check to see if any errors occurred during init */
3688 if (status & HS_FFERM) {
3689 /* ERROR: During chipset initialization */
3690 /* Adapter failed to init, chipset, status reg
3692 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3693 "0437 Adapter failed to init, "
3694 "chipset, status reg x%x, "
3695 "FW Data: A8 x%x AC x%x\n", status,
3696 readl(phba->MBslimaddr + 0xa8),
3697 readl(phba->MBslimaddr + 0xac));
3698 phba->link_state = LPFC_HBA_ERROR;
3704 } else if (i <= 10) {
3712 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3713 lpfc_sli_brdrestart(phba);
3715 /* Read the HBA Host Status Register */
3716 status = readl(phba->HSregaddr);
3719 /* Check to see if any errors occurred during init */
3720 if (status & HS_FFERM) {
3721 /* ERROR: During chipset initialization */
3722 /* Adapter failed to init, chipset, status reg <status> */
3723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3724 "0438 Adapter failed to init, chipset, "
3726 "FW Data: A8 x%x AC x%x\n", status,
3727 readl(phba->MBslimaddr + 0xa8),
3728 readl(phba->MBslimaddr + 0xac));
3729 phba->link_state = LPFC_HBA_ERROR;
3733 /* Clear all interrupt enable conditions */
3734 writel(0, phba->HCregaddr);
3735 readl(phba->HCregaddr); /* flush */
3737 /* setup host attn register */
3738 writel(0xffffffff, phba->HAregaddr);
3739 readl(phba->HAregaddr); /* flush */
3744 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
3746 * This function calculates and returns the number of HBQs required to be
3750 lpfc_sli_hbq_count(void)
3752 return ARRAY_SIZE(lpfc_hbq_defs);
3756 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
3758 * This function adds the number of hbq entries in every HBQ to get
3759 * the total number of hbq entries required for the HBA and returns
3763 lpfc_sli_hbq_entry_count(void)
3765 int hbq_count = lpfc_sli_hbq_count();
3769 for (i = 0; i < hbq_count; ++i)
3770 count += lpfc_hbq_defs[i]->entry_count;
3775 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
3777 * This function calculates amount of memory required for all hbq entries
3778 * to be configured and returns the total memory required.
3781 lpfc_sli_hbq_size(void)
3783 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
3787 * lpfc_sli_hbq_setup - configure and initialize HBQs
3788 * @phba: Pointer to HBA context object.
3790 * This function is called during the SLI initialization to configure
3791 * all the HBQs and post buffers to the HBQ. The caller is not
3792 * required to hold any locks. This function will return zero if successful
3793 * else it will return negative error code.
3796 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
3798 int hbq_count = lpfc_sli_hbq_count();
3802 uint32_t hbq_entry_index;
3804 /* Get a Mailbox buffer to setup mailbox
3805 * commands for HBA initialization
3807 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3814 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
3815 phba->link_state = LPFC_INIT_MBX_CMDS;
3816 phba->hbq_in_use = 1;
3818 hbq_entry_index = 0;
3819 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
3820 phba->hbqs[hbqno].next_hbqPutIdx = 0;
3821 phba->hbqs[hbqno].hbqPutIdx = 0;
3822 phba->hbqs[hbqno].local_hbqGetIdx = 0;
3823 phba->hbqs[hbqno].entry_count =
3824 lpfc_hbq_defs[hbqno]->entry_count;
3825 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
3826 hbq_entry_index, pmb);
3827 hbq_entry_index += phba->hbqs[hbqno].entry_count;
3829 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
3830 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
3831 mbxStatus <status>, ring <num> */
3833 lpfc_printf_log(phba, KERN_ERR,
3834 LOG_SLI | LOG_VPORT,
3835 "1805 Adapter failed to init. "
3836 "Data: x%x x%x x%x\n",
3838 pmbox->mbxStatus, hbqno);
3840 phba->link_state = LPFC_HBA_ERROR;
3841 mempool_free(pmb, phba->mbox_mem_pool);
3845 phba->hbq_count = hbq_count;
3847 mempool_free(pmb, phba->mbox_mem_pool);
3849 /* Initially populate or replenish the HBQs */
3850 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
3851 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
3856 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
3857 * @phba: Pointer to HBA context object.
3859 * This function is called during the SLI initialization to configure
3860 * all the HBQs and post buffers to the HBQ. The caller is not
3861 * required to hold any locks. This function will return zero if successful
3862 * else it will return negative error code.
3865 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
3867 phba->hbq_in_use = 1;
3868 phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
3869 phba->hbq_count = 1;
3870 /* Initially populate or replenish the HBQs */
3871 lpfc_sli_hbqbuf_init_hbqs(phba, 0);
3876 * lpfc_sli_config_port - Issue config port mailbox command
3877 * @phba: Pointer to HBA context object.
3878 * @sli_mode: sli mode - 2/3
3880 * This function is called by the sli intialization code path
3881 * to issue config_port mailbox command. This function restarts the
3882 * HBA firmware and issues a config_port mailbox command to configure
3883 * the SLI interface in the sli mode specified by sli_mode
3884 * variable. The caller is not required to hold any locks.
3885 * The function returns 0 if successful, else returns negative error
3889 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
3892 uint32_t resetcount = 0, rc = 0, done = 0;
3894 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3896 phba->link_state = LPFC_HBA_ERROR;
3900 phba->sli_rev = sli_mode;
3901 while (resetcount < 2 && !done) {
3902 spin_lock_irq(&phba->hbalock);
3903 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
3904 spin_unlock_irq(&phba->hbalock);
3905 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3906 lpfc_sli_brdrestart(phba);
3907 rc = lpfc_sli_chipset_init(phba);
3911 spin_lock_irq(&phba->hbalock);
3912 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3913 spin_unlock_irq(&phba->hbalock);
3916 /* Call pre CONFIG_PORT mailbox command initialization. A
3917 * value of 0 means the call was successful. Any other
3918 * nonzero value is a failure, but if ERESTART is returned,
3919 * the driver may reset the HBA and try again.
3921 rc = lpfc_config_port_prep(phba);
3922 if (rc == -ERESTART) {
3923 phba->link_state = LPFC_LINK_UNKNOWN;
3927 phba->link_state = LPFC_INIT_MBX_CMDS;
3928 lpfc_config_port(phba, pmb);
3929 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
3930 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
3931 LPFC_SLI3_HBQ_ENABLED |
3932 LPFC_SLI3_CRP_ENABLED |
3933 LPFC_SLI3_INB_ENABLED |
3934 LPFC_SLI3_BG_ENABLED);
3935 if (rc != MBX_SUCCESS) {
3936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3937 "0442 Adapter failed to init, mbxCmd x%x "
3938 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3939 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
3940 spin_lock_irq(&phba->hbalock);
3941 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
3942 spin_unlock_irq(&phba->hbalock);
3945 /* Allow asynchronous mailbox command to go through */
3946 spin_lock_irq(&phba->hbalock);
3947 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
3948 spin_unlock_irq(&phba->hbalock);
3954 goto do_prep_failed;
3956 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
3957 if (!pmb->u.mb.un.varCfgPort.cMA) {
3959 goto do_prep_failed;
3961 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
3962 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3963 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
3964 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
3965 phba->max_vpi : phba->max_vports;
3969 if (pmb->u.mb.un.varCfgPort.gdss)
3970 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
3971 if (pmb->u.mb.un.varCfgPort.gerbm)
3972 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
3973 if (pmb->u.mb.un.varCfgPort.gcrp)
3974 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
3975 if (pmb->u.mb.un.varCfgPort.ginb) {
3976 phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
3977 phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
3978 phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
3979 phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
3980 phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
3981 phba->inb_last_counter =
3982 phba->mbox->us.s3_inb_pgp.counter;
3984 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
3985 phba->port_gp = phba->mbox->us.s3_pgp.port;
3986 phba->inb_ha_copy = NULL;
3987 phba->inb_counter = NULL;
3990 if (phba->cfg_enable_bg) {
3991 if (pmb->u.mb.un.varCfgPort.gbg)
3992 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
3994 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3995 "0443 Adapter did not grant "
3999 phba->hbq_get = NULL;
4000 phba->port_gp = phba->mbox->us.s2.port;
4001 phba->inb_ha_copy = NULL;
4002 phba->inb_counter = NULL;
4006 mempool_free(pmb, phba->mbox_mem_pool);
4012 * lpfc_sli_hba_setup - SLI intialization function
4013 * @phba: Pointer to HBA context object.
4015 * This function is the main SLI intialization function. This function
4016 * is called by the HBA intialization code, HBA reset code and HBA
4017 * error attention handler code. Caller is not required to hold any
4018 * locks. This function issues config_port mailbox command to configure
4019 * the SLI, setup iocb rings and HBQ rings. In the end the function
4020 * calls the config_port_post function to issue init_link mailbox
4021 * command and to start the discovery. The function will return zero
4022 * if successful, else it will return negative error code.
4025 lpfc_sli_hba_setup(struct lpfc_hba *phba)
4030 switch (lpfc_sli_mode) {
4032 if (phba->cfg_enable_npiv) {
4033 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4034 "1824 NPIV enabled: Override lpfc_sli_mode "
4035 "parameter (%d) to auto (0).\n",
4045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4046 "1819 Unrecognized lpfc_sli_mode "
4047 "parameter: %d.\n", lpfc_sli_mode);
4052 rc = lpfc_sli_config_port(phba, mode);
4054 if (rc && lpfc_sli_mode == 3)
4055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4056 "1820 Unable to select SLI-3. "
4057 "Not supported by adapter.\n");
4058 if (rc && mode != 2)
4059 rc = lpfc_sli_config_port(phba, 2);
4061 goto lpfc_sli_hba_setup_error;
4063 if (phba->sli_rev == 3) {
4064 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4065 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
4067 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4068 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
4069 phba->sli3_options = 0;
4072 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4073 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4074 phba->sli_rev, phba->max_vpi);
4075 rc = lpfc_sli_ring_map(phba);
4078 goto lpfc_sli_hba_setup_error;
4081 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4082 rc = lpfc_sli_hbq_setup(phba);
4084 goto lpfc_sli_hba_setup_error;
4086 spin_lock_irq(&phba->hbalock);
4087 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4088 spin_unlock_irq(&phba->hbalock);
4090 rc = lpfc_config_port_post(phba);
4092 goto lpfc_sli_hba_setup_error;
4096 lpfc_sli_hba_setup_error:
4097 phba->link_state = LPFC_HBA_ERROR;
4098 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4099 "0445 Firmware initialization failed\n");
4104 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4105 * @phba: Pointer to HBA context object.
4106 * @mboxq: mailbox pointer.
4107 * This function issue a dump mailbox command to read config region
4108 * 23 and parse the records in the region and populate driver
4112 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
4113 LPFC_MBOXQ_t *mboxq)
4115 struct lpfc_dmabuf *mp;
4116 struct lpfc_mqe *mqe;
4117 uint32_t data_length;
4120 /* Program the default value of vlan_id and fc_map */
4121 phba->valid_vlan = 0;
4122 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4123 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4124 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4126 mqe = &mboxq->u.mqe;
4127 if (lpfc_dump_fcoe_param(phba, mboxq))
4130 mp = (struct lpfc_dmabuf *) mboxq->context1;
4131 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4133 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4134 "(%d):2571 Mailbox cmd x%x Status x%x "
4135 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4136 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4137 "CQ: x%x x%x x%x x%x\n",
4138 mboxq->vport ? mboxq->vport->vpi : 0,
4139 bf_get(lpfc_mqe_command, mqe),
4140 bf_get(lpfc_mqe_status, mqe),
4141 mqe->un.mb_words[0], mqe->un.mb_words[1],
4142 mqe->un.mb_words[2], mqe->un.mb_words[3],
4143 mqe->un.mb_words[4], mqe->un.mb_words[5],
4144 mqe->un.mb_words[6], mqe->un.mb_words[7],
4145 mqe->un.mb_words[8], mqe->un.mb_words[9],
4146 mqe->un.mb_words[10], mqe->un.mb_words[11],
4147 mqe->un.mb_words[12], mqe->un.mb_words[13],
4148 mqe->un.mb_words[14], mqe->un.mb_words[15],
4149 mqe->un.mb_words[16], mqe->un.mb_words[50],
4151 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4152 mboxq->mcqe.trailer);
4155 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4159 data_length = mqe->un.mb_words[5];
4160 if (data_length > DMP_RGN23_SIZE) {
4161 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4166 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
4167 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4173 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4174 * @phba: pointer to lpfc hba data structure.
4175 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4176 * @vpd: pointer to the memory to hold resulting port vpd data.
4177 * @vpd_size: On input, the number of bytes allocated to @vpd.
4178 * On output, the number of data bytes in @vpd.
4180 * This routine executes a READ_REV SLI4 mailbox command. In
4181 * addition, this routine gets the port vpd data.
4185 * ENOMEM - could not allocated memory.
4188 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4189 uint8_t *vpd, uint32_t *vpd_size)
4193 struct lpfc_dmabuf *dmabuf;
4194 struct lpfc_mqe *mqe;
4196 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4201 * Get a DMA buffer for the vpd data resulting from the READ_REV
4204 dma_size = *vpd_size;
4205 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4209 if (!dmabuf->virt) {
4213 memset(dmabuf->virt, 0, dma_size);
4216 * The SLI4 implementation of READ_REV conflicts at word1,
4217 * bits 31:16 and SLI4 adds vpd functionality not present
4218 * in SLI3. This code corrects the conflicts.
4220 lpfc_read_rev(phba, mboxq);
4221 mqe = &mboxq->u.mqe;
4222 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
4223 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
4224 mqe->un.read_rev.word1 &= 0x0000FFFF;
4225 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
4226 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
4228 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4230 dma_free_coherent(&phba->pcidev->dev, dma_size,
4231 dmabuf->virt, dmabuf->phys);
4236 * The available vpd length cannot be bigger than the
4237 * DMA buffer passed to the port. Catch the less than
4238 * case and update the caller's size.
4240 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
4241 *vpd_size = mqe->un.read_rev.avail_vpd_len;
4243 lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
4244 dma_free_coherent(&phba->pcidev->dev, dma_size,
4245 dmabuf->virt, dmabuf->phys);
4251 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4252 * @phba: pointer to lpfc hba data structure.
4254 * This routine is called to explicitly arm the SLI4 device's completion and
4258 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
4262 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
4263 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
4264 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4265 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
4267 lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
4268 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
4269 lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
4274 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4275 * @phba: Pointer to HBA context object.
4277 * This function is the main SLI4 device intialization PCI function. This
4278 * function is called by the HBA intialization code, HBA reset code and
4279 * HBA error attention handler code. Caller is not required to hold any
4283 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
4286 LPFC_MBOXQ_t *mboxq;
4287 struct lpfc_mqe *mqe;
4290 uint32_t ftr_rsp = 0;
4291 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
4292 struct lpfc_vport *vport = phba->pport;
4293 struct lpfc_dmabuf *mp;
4295 /* Perform a PCI function reset to start from clean */
4296 rc = lpfc_pci_function_reset(phba);
4300 /* Check the HBA Host Status Register for readyness */
4301 rc = lpfc_sli4_post_status_check(phba);
4305 spin_lock_irq(&phba->hbalock);
4306 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
4307 spin_unlock_irq(&phba->hbalock);
4311 * Allocate a single mailbox container for initializing the
4314 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4319 * Continue initialization with default values even if driver failed
4320 * to read FCoE param config regions
4322 if (lpfc_sli4_read_fcoe_params(phba, mboxq))
4323 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
4324 "2570 Failed to read FCoE parameters\n");
4326 /* Issue READ_REV to collect vpd and FW information. */
4327 vpd_size = PAGE_SIZE;
4328 vpd = kzalloc(vpd_size, GFP_KERNEL);
4334 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
4338 mqe = &mboxq->u.mqe;
4339 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
4340 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
4341 phba->hba_flag |= HBA_FCOE_SUPPORT;
4342 if (phba->sli_rev != LPFC_SLI_REV4 ||
4343 !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
4344 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4345 "0376 READ_REV Error. SLI Level %d "
4346 "FCoE enabled %d\n",
4347 phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
4352 * Evaluate the read rev and vpd data. Populate the driver
4353 * state with the results. If this routine fails, the failure
4354 * is not fatal as the driver will use generic values.
4356 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
4357 if (unlikely(!rc)) {
4358 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4359 "0377 Error %d parsing vpd. "
4360 "Using defaults.\n", rc);
4364 /* Save information as VPD data */
4365 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
4366 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
4367 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
4368 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
4370 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
4372 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
4374 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
4376 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
4377 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
4378 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
4379 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
4380 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
4381 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
4382 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4383 "(%d):0380 READ_REV Status x%x "
4384 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
4385 mboxq->vport ? mboxq->vport->vpi : 0,
4386 bf_get(lpfc_mqe_status, mqe),
4387 phba->vpd.rev.opFwName,
4388 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
4389 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
4392 * Discover the port's supported feature set and match it against the
4395 lpfc_request_features(phba, mboxq);
4396 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4403 * The port must support FCP initiator mode as this is the
4404 * only mode running in the host.
4406 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
4407 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4408 "0378 No support for fcpi mode.\n");
4413 * If the port cannot support the host's requested features
4414 * then turn off the global config parameters to disable the
4415 * feature in the driver. This is not a fatal error.
4417 if ((phba->cfg_enable_bg) &&
4418 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
4421 if (phba->max_vpi && phba->cfg_enable_npiv &&
4422 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
4426 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4427 "0379 Feature Mismatch Data: x%08x %08x "
4428 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
4429 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
4430 phba->cfg_enable_npiv, phba->max_vpi);
4431 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
4432 phba->cfg_enable_bg = 0;
4433 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
4434 phba->cfg_enable_npiv = 0;
4437 /* These SLI3 features are assumed in SLI4 */
4438 spin_lock_irq(&phba->hbalock);
4439 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
4440 spin_unlock_irq(&phba->hbalock);
4442 /* Read the port's service parameters. */
4443 lpfc_read_sparam(phba, mboxq, vport->vpi);
4444 mboxq->vport = vport;
4445 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4446 mp = (struct lpfc_dmabuf *) mboxq->context1;
4447 if (rc == MBX_SUCCESS) {
4448 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
4453 * This memory was allocated by the lpfc_read_sparam routine. Release
4454 * it to the mbuf pool.
4456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4458 mboxq->context1 = NULL;
4460 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4461 "0382 READ_SPARAM command failed "
4462 "status %d, mbxStatus x%x\n",
4463 rc, bf_get(lpfc_mqe_status, mqe));
4464 phba->link_state = LPFC_HBA_ERROR;
4469 if (phba->cfg_soft_wwnn)
4470 u64_to_wwn(phba->cfg_soft_wwnn,
4471 vport->fc_sparam.nodeName.u.wwn);
4472 if (phba->cfg_soft_wwpn)
4473 u64_to_wwn(phba->cfg_soft_wwpn,
4474 vport->fc_sparam.portName.u.wwn);
4475 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
4476 sizeof(struct lpfc_name));
4477 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
4478 sizeof(struct lpfc_name));
4480 /* Update the fc_host data structures with new wwn. */
4481 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4482 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4484 /* Register SGL pool to the device using non-embedded mailbox command */
4485 rc = lpfc_sli4_post_sgl_list(phba);
4487 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4488 "0582 Error %d during sgl post operation", rc);
4493 /* Register SCSI SGL pool to the device */
4494 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
4496 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
4497 "0383 Error %d during scsi sgl post opeation",
4499 /* Some Scsi buffers were moved to the abort scsi list */
4500 /* A pci function reset will repost them */
4505 /* Post the rpi header region to the device. */
4506 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
4508 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4509 "0393 Error %d during rpi post operation\n",
4514 if (phba->cfg_enable_fip)
4515 bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 1);
4517 bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
4519 /* Set up all the queues to the device */
4520 rc = lpfc_sli4_queue_setup(phba);
4522 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4523 "0381 Error %d during queue setup.\n ", rc);
4524 goto out_stop_timers;
4527 /* Arm the CQs and then EQs on device */
4528 lpfc_sli4_arm_cqeq_intr(phba);
4530 /* Indicate device interrupt mode */
4531 phba->sli4_hba.intr_enable = 1;
4533 /* Allow asynchronous mailbox command to go through */
4534 spin_lock_irq(&phba->hbalock);
4535 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4536 spin_unlock_irq(&phba->hbalock);
4538 /* Post receive buffers to the device */
4539 lpfc_sli4_rb_setup(phba);
4541 /* Start the ELS watchdog timer */
4542 mod_timer(&vport->els_tmofunc,
4543 jiffies + HZ * (phba->fc_ratov * 2));
4545 /* Start heart beat timer */
4546 mod_timer(&phba->hb_tmofunc,
4547 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
4548 phba->hb_outstanding = 0;
4549 phba->last_completion_time = jiffies;
4551 /* Start error attention (ERATT) polling timer */
4552 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
4555 * The port is ready, set the host's link state to LINK_DOWN
4556 * in preparation for link interrupts.
4558 lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
4559 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4560 lpfc_set_loopback_flag(phba);
4561 /* Change driver state to LPFC_LINK_DOWN right before init link */
4562 spin_lock_irq(&phba->hbalock);
4563 phba->link_state = LPFC_LINK_DOWN;
4564 spin_unlock_irq(&phba->hbalock);
4565 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
4566 if (unlikely(rc != MBX_NOT_FINISHED)) {
4572 /* Unset all the queues set up in this routine when error out */
4574 lpfc_sli4_queue_unset(phba);
4578 lpfc_stop_hba_timers(phba);
4582 mempool_free(mboxq, phba->mbox_mem_pool);
4587 * lpfc_mbox_timeout - Timeout call back function for mbox timer
4588 * @ptr: context object - pointer to hba structure.
4590 * This is the callback function for mailbox timer. The mailbox
4591 * timer is armed when a new mailbox command is issued and the timer
4592 * is deleted when the mailbox complete. The function is called by
4593 * the kernel timer code when a mailbox does not complete within
4594 * expected time. This function wakes up the worker thread to
4595 * process the mailbox timeout and returns. All the processing is
4596 * done by the worker thread function lpfc_mbox_timeout_handler.
4599 lpfc_mbox_timeout(unsigned long ptr)
4601 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4602 unsigned long iflag;
4603 uint32_t tmo_posted;
4605 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
4606 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
4608 phba->pport->work_port_events |= WORKER_MBOX_TMO;
4609 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
4612 lpfc_worker_wake_up(phba);
4618 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
4619 * @phba: Pointer to HBA context object.
4621 * This function is called from worker thread when a mailbox command times out.
4622 * The caller is not required to hold any locks. This function will reset the
4623 * HBA and recover all the pending commands.
4626 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
4628 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
4629 MAILBOX_t *mb = &pmbox->u.mb;
4630 struct lpfc_sli *psli = &phba->sli;
4631 struct lpfc_sli_ring *pring;
4633 /* Check the pmbox pointer first. There is a race condition
4634 * between the mbox timeout handler getting executed in the
4635 * worklist and the mailbox actually completing. When this
4636 * race condition occurs, the mbox_active will be NULL.
4638 spin_lock_irq(&phba->hbalock);
4639 if (pmbox == NULL) {
4640 lpfc_printf_log(phba, KERN_WARNING,
4642 "0353 Active Mailbox cleared - mailbox timeout "
4644 spin_unlock_irq(&phba->hbalock);
4648 /* Mbox cmd <mbxCommand> timeout */
4649 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4650 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
4652 phba->pport->port_state,
4654 phba->sli.mbox_active);
4655 spin_unlock_irq(&phba->hbalock);
4657 /* Setting state unknown so lpfc_sli_abort_iocb_ring
4658 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
4659 * it to fail all oustanding SCSI IO.
4661 spin_lock_irq(&phba->pport->work_port_lock);
4662 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
4663 spin_unlock_irq(&phba->pport->work_port_lock);
4664 spin_lock_irq(&phba->hbalock);
4665 phba->link_state = LPFC_LINK_UNKNOWN;
4666 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4667 spin_unlock_irq(&phba->hbalock);
4669 pring = &psli->ring[psli->fcp_ring];
4670 lpfc_sli_abort_iocb_ring(phba, pring);
4672 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4673 "0345 Resetting board due to mailbox timeout\n");
4675 /* Reset the HBA device */
4676 lpfc_reset_hba(phba);
4680 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
4681 * @phba: Pointer to HBA context object.
4682 * @pmbox: Pointer to mailbox object.
4683 * @flag: Flag indicating how the mailbox need to be processed.
4685 * This function is called by discovery code and HBA management code
4686 * to submit a mailbox command to firmware with SLI-3 interface spec. This
4687 * function gets the hbalock to protect the data structures.
4688 * The mailbox command can be submitted in polling mode, in which case
4689 * this function will wait in a polling loop for the completion of the
4691 * If the mailbox is submitted in no_wait mode (not polling) the
4692 * function will submit the command and returns immediately without waiting
4693 * for the mailbox completion. The no_wait is supported only when HBA
4694 * is in SLI2/SLI3 mode - interrupts are enabled.
4695 * The SLI interface allows only one mailbox pending at a time. If the
4696 * mailbox is issued in polling mode and there is already a mailbox
4697 * pending, then the function will return an error. If the mailbox is issued
4698 * in NO_WAIT mode and there is a mailbox pending already, the function
4699 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
4700 * The sli layer owns the mailbox object until the completion of mailbox
4701 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
4702 * return codes the caller owns the mailbox command after the return of
4706 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
4710 struct lpfc_sli *psli = &phba->sli;
4711 uint32_t status, evtctr;
4714 unsigned long timeout;
4715 unsigned long drvr_flag = 0;
4716 uint32_t word0, ldata;
4717 void __iomem *to_slim;
4718 int processing_queue = 0;
4720 spin_lock_irqsave(&phba->hbalock, drvr_flag);
4722 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4723 /* processing mbox queue from intr_handler */
4724 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
4725 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4728 processing_queue = 1;
4729 pmbox = lpfc_mbox_get(phba);
4731 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4736 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
4737 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
4739 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4740 lpfc_printf_log(phba, KERN_ERR,
4741 LOG_MBOX | LOG_VPORT,
4742 "1806 Mbox x%x failed. No vport\n",
4743 pmbox->u.mb.mbxCommand);
4745 goto out_not_finished;
4749 /* If the PCI channel is in offline state, do not post mbox. */
4750 if (unlikely(pci_channel_offline(phba->pcidev))) {
4751 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4752 goto out_not_finished;
4755 /* If HBA has a deferred error attention, fail the iocb. */
4756 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
4757 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4758 goto out_not_finished;
4764 status = MBX_SUCCESS;
4766 if (phba->link_state == LPFC_HBA_ERROR) {
4767 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4769 /* Mbox command <mbxCommand> cannot issue */
4770 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4771 "(%d):0311 Mailbox command x%x cannot "
4772 "issue Data: x%x x%x\n",
4773 pmbox->vport ? pmbox->vport->vpi : 0,
4774 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
4775 goto out_not_finished;
4778 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
4779 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
4780 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4781 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4782 "(%d):2528 Mailbox command x%x cannot "
4783 "issue Data: x%x x%x\n",
4784 pmbox->vport ? pmbox->vport->vpi : 0,
4785 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
4786 goto out_not_finished;
4789 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
4790 /* Polling for a mbox command when another one is already active
4791 * is not allowed in SLI. Also, the driver must have established
4792 * SLI2 mode to queue and process multiple mbox commands.
4795 if (flag & MBX_POLL) {
4796 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4798 /* Mbox command <mbxCommand> cannot issue */
4799 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4800 "(%d):2529 Mailbox command x%x "
4801 "cannot issue Data: x%x x%x\n",
4802 pmbox->vport ? pmbox->vport->vpi : 0,
4803 pmbox->u.mb.mbxCommand,
4804 psli->sli_flag, flag);
4805 goto out_not_finished;
4808 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
4809 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4810 /* Mbox command <mbxCommand> cannot issue */
4811 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4812 "(%d):2530 Mailbox command x%x "
4813 "cannot issue Data: x%x x%x\n",
4814 pmbox->vport ? pmbox->vport->vpi : 0,
4815 pmbox->u.mb.mbxCommand,
4816 psli->sli_flag, flag);
4817 goto out_not_finished;
4820 /* Another mailbox command is still being processed, queue this
4821 * command to be processed later.
4823 lpfc_mbox_put(phba, pmbox);
4825 /* Mbox cmd issue - BUSY */
4826 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4827 "(%d):0308 Mbox cmd issue - BUSY Data: "
4828 "x%x x%x x%x x%x\n",
4829 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
4830 mb->mbxCommand, phba->pport->port_state,
4831 psli->sli_flag, flag);
4833 psli->slistat.mbox_busy++;
4834 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4837 lpfc_debugfs_disc_trc(pmbox->vport,
4838 LPFC_DISC_TRC_MBOX_VPORT,
4839 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
4840 (uint32_t)mb->mbxCommand,
4841 mb->un.varWords[0], mb->un.varWords[1]);
4844 lpfc_debugfs_disc_trc(phba->pport,
4846 "MBOX Bsy: cmd:x%x mb:x%x x%x",
4847 (uint32_t)mb->mbxCommand,
4848 mb->un.varWords[0], mb->un.varWords[1]);
4854 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4856 /* If we are not polling, we MUST be in SLI2 mode */
4857 if (flag != MBX_POLL) {
4858 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
4859 (mb->mbxCommand != MBX_KILL_BOARD)) {
4860 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4861 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
4862 /* Mbox command <mbxCommand> cannot issue */
4863 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
4864 "(%d):2531 Mailbox command x%x "
4865 "cannot issue Data: x%x x%x\n",
4866 pmbox->vport ? pmbox->vport->vpi : 0,
4867 pmbox->u.mb.mbxCommand,
4868 psli->sli_flag, flag);
4869 goto out_not_finished;
4871 /* timeout active mbox command */
4872 mod_timer(&psli->mbox_tmo, (jiffies +
4873 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
4876 /* Mailbox cmd <cmd> issue */
4877 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4878 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
4880 pmbox->vport ? pmbox->vport->vpi : 0,
4881 mb->mbxCommand, phba->pport->port_state,
4882 psli->sli_flag, flag);
4884 if (mb->mbxCommand != MBX_HEARTBEAT) {
4886 lpfc_debugfs_disc_trc(pmbox->vport,
4887 LPFC_DISC_TRC_MBOX_VPORT,
4888 "MBOX Send vport: cmd:x%x mb:x%x x%x",
4889 (uint32_t)mb->mbxCommand,
4890 mb->un.varWords[0], mb->un.varWords[1]);
4893 lpfc_debugfs_disc_trc(phba->pport,
4895 "MBOX Send: cmd:x%x mb:x%x x%x",
4896 (uint32_t)mb->mbxCommand,
4897 mb->un.varWords[0], mb->un.varWords[1]);
4901 psli->slistat.mbox_cmd++;
4902 evtctr = psli->slistat.mbox_event;
4904 /* next set own bit for the adapter and copy over command word */
4905 mb->mbxOwner = OWN_CHIP;
4907 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4908 /* First copy command data to host SLIM area */
4909 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
4911 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4912 /* copy command data into host mbox for cmpl */
4913 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
4916 /* First copy mbox command data to HBA SLIM, skip past first
4918 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4919 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
4920 MAILBOX_CMD_SIZE - sizeof (uint32_t));
4922 /* Next copy over first word, with mbxOwner set */
4923 ldata = *((uint32_t *)mb);
4924 to_slim = phba->MBslimaddr;
4925 writel(ldata, to_slim);
4926 readl(to_slim); /* flush */
4928 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4929 /* switch over to host mailbox */
4930 psli->sli_flag |= LPFC_SLI_ACTIVE;
4938 /* Set up reference to mailbox command */
4939 psli->mbox_active = pmbox;
4940 /* Interrupt board to do it */
4941 writel(CA_MBATT, phba->CAregaddr);
4942 readl(phba->CAregaddr); /* flush */
4943 /* Don't wait for it to finish, just return */
4947 /* Set up null reference to mailbox command */
4948 psli->mbox_active = NULL;
4949 /* Interrupt board to do it */
4950 writel(CA_MBATT, phba->CAregaddr);
4951 readl(phba->CAregaddr); /* flush */
4953 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4954 /* First read mbox status word */
4955 word0 = *((uint32_t *)phba->mbox);
4956 word0 = le32_to_cpu(word0);
4958 /* First read mbox status word */
4959 word0 = readl(phba->MBslimaddr);
4962 /* Read the HBA Host Attention Register */
4963 ha_copy = readl(phba->HAregaddr);
4964 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
4968 /* Wait for command to complete */
4969 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
4970 (!(ha_copy & HA_MBATT) &&
4971 (phba->link_state > LPFC_WARM_START))) {
4972 if (time_after(jiffies, timeout)) {
4973 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4974 spin_unlock_irqrestore(&phba->hbalock,
4976 goto out_not_finished;
4979 /* Check if we took a mbox interrupt while we were
4981 if (((word0 & OWN_CHIP) != OWN_CHIP)
4982 && (evtctr != psli->slistat.mbox_event))
4986 spin_unlock_irqrestore(&phba->hbalock,
4989 spin_lock_irqsave(&phba->hbalock, drvr_flag);
4992 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
4993 /* First copy command data */
4994 word0 = *((uint32_t *)phba->mbox);
4995 word0 = le32_to_cpu(word0);
4996 if (mb->mbxCommand == MBX_CONFIG_PORT) {
4999 /* Check real SLIM for any errors */
5000 slimword0 = readl(phba->MBslimaddr);
5001 slimmb = (MAILBOX_t *) & slimword0;
5002 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
5003 && slimmb->mbxStatus) {
5010 /* First copy command data */
5011 word0 = readl(phba->MBslimaddr);
5013 /* Read the HBA Host Attention Register */
5014 ha_copy = readl(phba->HAregaddr);
5017 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
5018 /* copy results back to user */
5019 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
5021 /* First copy command data */
5022 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
5024 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
5026 lpfc_memcpy_from_slim((void *)pmbox->context2,
5027 phba->MBslimaddr + DMP_RSP_OFFSET,
5028 mb->un.varDmp.word_cnt);
5032 writel(HA_MBATT, phba->HAregaddr);
5033 readl(phba->HAregaddr); /* flush */
5035 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5036 status = mb->mbxStatus;
5039 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
5043 if (processing_queue) {
5044 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
5045 lpfc_mbox_cmpl_put(phba, pmbox);
5047 return MBX_NOT_FINISHED;
5051 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
5052 * @phba: Pointer to HBA context object.
5054 * The function blocks the posting of SLI4 asynchronous mailbox commands from
5055 * the driver internal pending mailbox queue. It will then try to wait out the
5056 * possible outstanding mailbox command before return.
5059 * 0 - the outstanding mailbox command completed; otherwise, the wait for
5060 * the outstanding mailbox command timed out.
5063 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
5065 struct lpfc_sli *psli = &phba->sli;
5066 uint8_t actcmd = MBX_HEARTBEAT;
5068 unsigned long timeout;
5070 /* Mark the asynchronous mailbox command posting as blocked */
5071 spin_lock_irq(&phba->hbalock);
5072 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
5073 if (phba->sli.mbox_active)
5074 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
5075 spin_unlock_irq(&phba->hbalock);
5076 /* Determine how long we might wait for the active mailbox
5077 * command to be gracefully completed by firmware.
5079 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
5081 /* Wait for the outstnading mailbox command to complete */
5082 while (phba->sli.mbox_active) {
5083 /* Check active mailbox complete status every 2ms */
5085 if (time_after(jiffies, timeout)) {
5086 /* Timeout, marked the outstanding cmd not complete */
5092 /* Can not cleanly block async mailbox command, fails it */
5094 spin_lock_irq(&phba->hbalock);
5095 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5096 spin_unlock_irq(&phba->hbalock);
5102 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
5103 * @phba: Pointer to HBA context object.
5105 * The function unblocks and resume posting of SLI4 asynchronous mailbox
5106 * commands from the driver internal pending mailbox queue. It makes sure
5107 * that there is no outstanding mailbox command before resuming posting
5108 * asynchronous mailbox commands. If, for any reason, there is outstanding
5109 * mailbox command, it will try to wait it out before resuming asynchronous
5110 * mailbox command posting.
5113 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
5115 struct lpfc_sli *psli = &phba->sli;
5117 spin_lock_irq(&phba->hbalock);
5118 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
5119 /* Asynchronous mailbox posting is not blocked, do nothing */
5120 spin_unlock_irq(&phba->hbalock);
5124 /* Outstanding synchronous mailbox command is guaranteed to be done,
5125 * successful or timeout, after timing-out the outstanding mailbox
5126 * command shall always be removed, so just unblock posting async
5127 * mailbox command and resume
5129 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5130 spin_unlock_irq(&phba->hbalock);
5132 /* wake up worker thread to post asynchronlous mailbox command */
5133 lpfc_worker_wake_up(phba);
5137 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5138 * @phba: Pointer to HBA context object.
5139 * @mboxq: Pointer to mailbox object.
5141 * The function posts a mailbox to the port. The mailbox is expected
5142 * to be comletely filled in and ready for the port to operate on it.
5143 * This routine executes a synchronous completion operation on the
5144 * mailbox by polling for its completion.
5146 * The caller must not be holding any locks when calling this routine.
5149 * MBX_SUCCESS - mailbox posted successfully
5150 * Any of the MBX error values.
5153 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5155 int rc = MBX_SUCCESS;
5156 unsigned long iflag;
5158 uint32_t mcqe_status;
5160 unsigned long timeout;
5161 struct lpfc_sli *psli = &phba->sli;
5162 struct lpfc_mqe *mb = &mboxq->u.mqe;
5163 struct lpfc_bmbx_create *mbox_rgn;
5164 struct dma_address *dma_address;
5165 struct lpfc_register bmbx_reg;
5168 * Only one mailbox can be active to the bootstrap mailbox region
5169 * at a time and there is no queueing provided.
5171 spin_lock_irqsave(&phba->hbalock, iflag);
5172 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
5173 spin_unlock_irqrestore(&phba->hbalock, iflag);
5174 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5175 "(%d):2532 Mailbox command x%x (x%x) "
5176 "cannot issue Data: x%x x%x\n",
5177 mboxq->vport ? mboxq->vport->vpi : 0,
5178 mboxq->u.mb.mbxCommand,
5179 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5180 psli->sli_flag, MBX_POLL);
5181 return MBXERR_ERROR;
5183 /* The server grabs the token and owns it until release */
5184 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5185 phba->sli.mbox_active = mboxq;
5186 spin_unlock_irqrestore(&phba->hbalock, iflag);
5189 * Initialize the bootstrap memory region to avoid stale data areas
5190 * in the mailbox post. Then copy the caller's mailbox contents to
5191 * the bmbx mailbox region.
5193 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
5194 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
5195 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
5196 sizeof(struct lpfc_mqe));
5198 /* Post the high mailbox dma address to the port and wait for ready. */
5199 dma_address = &phba->sli4_hba.bmbx.dma_address;
5200 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
5202 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
5205 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
5206 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
5210 if (time_after(jiffies, timeout)) {
5214 } while (!db_ready);
5216 /* Post the low mailbox dma address to the port. */
5217 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
5218 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
5221 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
5222 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
5226 if (time_after(jiffies, timeout)) {
5230 } while (!db_ready);
5233 * Read the CQ to ensure the mailbox has completed.
5234 * If so, update the mailbox status so that the upper layers
5235 * can complete the request normally.
5237 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
5238 sizeof(struct lpfc_mqe));
5239 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
5240 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
5241 sizeof(struct lpfc_mcqe));
5242 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
5244 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5245 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
5246 bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
5250 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5251 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5252 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5253 " x%x x%x CQ: x%x x%x x%x x%x\n",
5254 mboxq->vport ? mboxq->vport->vpi : 0,
5255 mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
5256 bf_get(lpfc_mqe_status, mb),
5257 mb->un.mb_words[0], mb->un.mb_words[1],
5258 mb->un.mb_words[2], mb->un.mb_words[3],
5259 mb->un.mb_words[4], mb->un.mb_words[5],
5260 mb->un.mb_words[6], mb->un.mb_words[7],
5261 mb->un.mb_words[8], mb->un.mb_words[9],
5262 mb->un.mb_words[10], mb->un.mb_words[11],
5263 mb->un.mb_words[12], mboxq->mcqe.word0,
5264 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5265 mboxq->mcqe.trailer);
5267 /* We are holding the token, no needed for lock when release */
5268 spin_lock_irqsave(&phba->hbalock, iflag);
5269 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5270 phba->sli.mbox_active = NULL;
5271 spin_unlock_irqrestore(&phba->hbalock, iflag);
5276 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5277 * @phba: Pointer to HBA context object.
5278 * @pmbox: Pointer to mailbox object.
5279 * @flag: Flag indicating how the mailbox need to be processed.
5281 * This function is called by discovery code and HBA management code to submit
5282 * a mailbox command to firmware with SLI-4 interface spec.
5284 * Return codes the caller owns the mailbox command after the return of the
5288 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5291 struct lpfc_sli *psli = &phba->sli;
5292 unsigned long iflags;
5295 rc = lpfc_mbox_dev_check(phba);
5297 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5298 "(%d):2544 Mailbox command x%x (x%x) "
5299 "cannot issue Data: x%x x%x\n",
5300 mboxq->vport ? mboxq->vport->vpi : 0,
5301 mboxq->u.mb.mbxCommand,
5302 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5303 psli->sli_flag, flag);
5304 goto out_not_finished;
5307 /* Detect polling mode and jump to a handler */
5308 if (!phba->sli4_hba.intr_enable) {
5309 if (flag == MBX_POLL)
5310 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
5313 if (rc != MBX_SUCCESS)
5314 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5315 "(%d):2541 Mailbox command x%x "
5316 "(x%x) cannot issue Data: x%x x%x\n",
5317 mboxq->vport ? mboxq->vport->vpi : 0,
5318 mboxq->u.mb.mbxCommand,
5319 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5320 psli->sli_flag, flag);
5322 } else if (flag == MBX_POLL) {
5323 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
5324 "(%d):2542 Try to issue mailbox command "
5325 "x%x (x%x) synchronously ahead of async"
5326 "mailbox command queue: x%x x%x\n",
5327 mboxq->vport ? mboxq->vport->vpi : 0,
5328 mboxq->u.mb.mbxCommand,
5329 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5330 psli->sli_flag, flag);
5331 /* Try to block the asynchronous mailbox posting */
5332 rc = lpfc_sli4_async_mbox_block(phba);
5334 /* Successfully blocked, now issue sync mbox cmd */
5335 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
5336 if (rc != MBX_SUCCESS)
5337 lpfc_printf_log(phba, KERN_ERR,
5339 "(%d):2597 Mailbox command "
5340 "x%x (x%x) cannot issue "
5343 mboxq->vport->vpi : 0,
5344 mboxq->u.mb.mbxCommand,
5345 lpfc_sli4_mbox_opcode_get(phba,
5347 psli->sli_flag, flag);
5348 /* Unblock the async mailbox posting afterward */
5349 lpfc_sli4_async_mbox_unblock(phba);
5354 /* Now, interrupt mode asynchrous mailbox command */
5355 rc = lpfc_mbox_cmd_check(phba, mboxq);
5357 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5358 "(%d):2543 Mailbox command x%x (x%x) "
5359 "cannot issue Data: x%x x%x\n",
5360 mboxq->vport ? mboxq->vport->vpi : 0,
5361 mboxq->u.mb.mbxCommand,
5362 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5363 psli->sli_flag, flag);
5364 goto out_not_finished;
5367 /* Put the mailbox command to the driver internal FIFO */
5368 psli->slistat.mbox_busy++;
5369 spin_lock_irqsave(&phba->hbalock, iflags);
5370 lpfc_mbox_put(phba, mboxq);
5371 spin_unlock_irqrestore(&phba->hbalock, iflags);
5372 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5373 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5374 "x%x (x%x) x%x x%x x%x\n",
5375 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
5376 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5377 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5378 phba->pport->port_state,
5379 psli->sli_flag, MBX_NOWAIT);
5380 /* Wake up worker thread to transport mailbox command from head */
5381 lpfc_worker_wake_up(phba);
5386 return MBX_NOT_FINISHED;
5390 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5391 * @phba: Pointer to HBA context object.
5393 * This function is called by worker thread to send a mailbox command to
5394 * SLI4 HBA firmware.
5398 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
5400 struct lpfc_sli *psli = &phba->sli;
5401 LPFC_MBOXQ_t *mboxq;
5402 int rc = MBX_SUCCESS;
5403 unsigned long iflags;
5404 struct lpfc_mqe *mqe;
5407 /* Check interrupt mode before post async mailbox command */
5408 if (unlikely(!phba->sli4_hba.intr_enable))
5409 return MBX_NOT_FINISHED;
5411 /* Check for mailbox command service token */
5412 spin_lock_irqsave(&phba->hbalock, iflags);
5413 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
5414 spin_unlock_irqrestore(&phba->hbalock, iflags);
5415 return MBX_NOT_FINISHED;
5417 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
5418 spin_unlock_irqrestore(&phba->hbalock, iflags);
5419 return MBX_NOT_FINISHED;
5421 if (unlikely(phba->sli.mbox_active)) {
5422 spin_unlock_irqrestore(&phba->hbalock, iflags);
5423 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5424 "0384 There is pending active mailbox cmd\n");
5425 return MBX_NOT_FINISHED;
5427 /* Take the mailbox command service token */
5428 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5430 /* Get the next mailbox command from head of queue */
5431 mboxq = lpfc_mbox_get(phba);
5433 /* If no more mailbox command waiting for post, we're done */
5435 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5436 spin_unlock_irqrestore(&phba->hbalock, iflags);
5439 phba->sli.mbox_active = mboxq;
5440 spin_unlock_irqrestore(&phba->hbalock, iflags);
5442 /* Check device readiness for posting mailbox command */
5443 rc = lpfc_mbox_dev_check(phba);
5445 /* Driver clean routine will clean up pending mailbox */
5446 goto out_not_finished;
5448 /* Prepare the mbox command to be posted */
5449 mqe = &mboxq->u.mqe;
5450 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
5452 /* Start timer for the mbox_tmo and log some mailbox post messages */
5453 mod_timer(&psli->mbox_tmo, (jiffies +
5454 (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
5456 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5457 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5459 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
5460 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5461 phba->pport->port_state, psli->sli_flag);
5463 if (mbx_cmnd != MBX_HEARTBEAT) {
5465 lpfc_debugfs_disc_trc(mboxq->vport,
5466 LPFC_DISC_TRC_MBOX_VPORT,
5467 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5468 mbx_cmnd, mqe->un.mb_words[0],
5469 mqe->un.mb_words[1]);
5471 lpfc_debugfs_disc_trc(phba->pport,
5473 "MBOX Send: cmd:x%x mb:x%x x%x",
5474 mbx_cmnd, mqe->un.mb_words[0],
5475 mqe->un.mb_words[1]);
5478 psli->slistat.mbox_cmd++;
5480 /* Post the mailbox command to the port */
5481 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
5482 if (rc != MBX_SUCCESS) {
5483 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5484 "(%d):2533 Mailbox command x%x (x%x) "
5485 "cannot issue Data: x%x x%x\n",
5486 mboxq->vport ? mboxq->vport->vpi : 0,
5487 mboxq->u.mb.mbxCommand,
5488 lpfc_sli4_mbox_opcode_get(phba, mboxq),
5489 psli->sli_flag, MBX_NOWAIT);
5490 goto out_not_finished;
5496 spin_lock_irqsave(&phba->hbalock, iflags);
5497 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
5498 __lpfc_mbox_cmpl_put(phba, mboxq);
5499 /* Release the token */
5500 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5501 phba->sli.mbox_active = NULL;
5502 spin_unlock_irqrestore(&phba->hbalock, iflags);
5504 return MBX_NOT_FINISHED;
5508 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5509 * @phba: Pointer to HBA context object.
5510 * @pmbox: Pointer to mailbox object.
5511 * @flag: Flag indicating how the mailbox need to be processed.
5513 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5514 * the API jump table function pointer from the lpfc_hba struct.
5516 * Return codes the caller owns the mailbox command after the return of the
5520 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
5522 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
5526 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5527 * @phba: The hba struct for which this call is being executed.
5528 * @dev_grp: The HBA PCI-Device group number.
5530 * This routine sets up the mbox interface API function jump table in @phba
5532 * Returns: 0 - success, -ENODEV - failure.
5535 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5539 case LPFC_PCI_DEV_LP:
5540 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
5541 phba->lpfc_sli_handle_slow_ring_event =
5542 lpfc_sli_handle_slow_ring_event_s3;
5543 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
5544 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
5545 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
5547 case LPFC_PCI_DEV_OC:
5548 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
5549 phba->lpfc_sli_handle_slow_ring_event =
5550 lpfc_sli_handle_slow_ring_event_s4;
5551 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
5552 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
5553 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
5556 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5557 "1420 Invalid HBA PCI-device group: 0x%x\n",
5566 * __lpfc_sli_ringtx_put - Add an iocb to the txq
5567 * @phba: Pointer to HBA context object.
5568 * @pring: Pointer to driver SLI ring object.
5569 * @piocb: Pointer to address of newly added command iocb.
5571 * This function is called with hbalock held to add a command
5572 * iocb to the txq when SLI layer cannot submit the command iocb
5576 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5577 struct lpfc_iocbq *piocb)
5579 /* Insert the caller's iocb in the txq tail for later processing. */
5580 list_add_tail(&piocb->list, &pring->txq);
5585 * lpfc_sli_next_iocb - Get the next iocb in the txq
5586 * @phba: Pointer to HBA context object.
5587 * @pring: Pointer to driver SLI ring object.
5588 * @piocb: Pointer to address of newly added command iocb.
5590 * This function is called with hbalock held before a new
5591 * iocb is submitted to the firmware. This function checks
5592 * txq to flush the iocbs in txq to Firmware before
5593 * submitting new iocbs to the Firmware.
5594 * If there are iocbs in the txq which need to be submitted
5595 * to firmware, lpfc_sli_next_iocb returns the first element
5596 * of the txq after dequeuing it from txq.
5597 * If there is no iocb in the txq then the function will return
5598 * *piocb and *piocb is set to NULL. Caller needs to check
5599 * *piocb to find if there are more commands in the txq.
5601 static struct lpfc_iocbq *
5602 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5603 struct lpfc_iocbq **piocb)
5605 struct lpfc_iocbq * nextiocb;
5607 nextiocb = lpfc_sli_ringtx_get(phba, pring);
5617 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
5618 * @phba: Pointer to HBA context object.
5619 * @ring_number: SLI ring number to issue iocb on.
5620 * @piocb: Pointer to command iocb.
5621 * @flag: Flag indicating if this command can be put into txq.
5623 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
5624 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
5625 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
5626 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
5627 * this function allows only iocbs for posting buffers. This function finds
5628 * next available slot in the command ring and posts the command to the
5629 * available slot and writes the port attention register to request HBA start
5630 * processing new iocb. If there is no slot available in the ring and
5631 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
5632 * the function returns IOCB_BUSY.
5634 * This function is called with hbalock held. The function will return success
5635 * after it successfully submit the iocb to firmware or after adding to the
5639 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
5640 struct lpfc_iocbq *piocb, uint32_t flag)
5642 struct lpfc_iocbq *nextiocb;
5644 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
5646 if (piocb->iocb_cmpl && (!piocb->vport) &&
5647 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
5648 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
5649 lpfc_printf_log(phba, KERN_ERR,
5650 LOG_SLI | LOG_VPORT,
5651 "1807 IOCB x%x failed. No vport\n",
5652 piocb->iocb.ulpCommand);
5658 /* If the PCI channel is in offline state, do not post iocbs. */
5659 if (unlikely(pci_channel_offline(phba->pcidev)))
5662 /* If HBA has a deferred error attention, fail the iocb. */
5663 if (unlikely(phba->hba_flag & DEFER_ERATT))
5667 * We should never get an IOCB if we are in a < LINK_DOWN state
5669 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5673 * Check to see if we are blocking IOCB processing because of a
5674 * outstanding event.
5676 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
5679 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
5681 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
5682 * can be issued if the link is not up.
5684 switch (piocb->iocb.ulpCommand) {
5685 case CMD_GEN_REQUEST64_CR:
5686 case CMD_GEN_REQUEST64_CX:
5687 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
5688 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
5690 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
5691 MENLO_TRANSPORT_TYPE))
5695 case CMD_QUE_RING_BUF_CN:
5696 case CMD_QUE_RING_BUF64_CN:
5698 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
5699 * completion, iocb_cmpl MUST be 0.
5701 if (piocb->iocb_cmpl)
5702 piocb->iocb_cmpl = NULL;
5704 case CMD_CREATE_XRI_CR:
5705 case CMD_CLOSE_XRI_CN:
5706 case CMD_CLOSE_XRI_CX:
5713 * For FCP commands, we must be in a state where we can process link
5716 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
5717 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
5721 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
5722 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
5723 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
5726 lpfc_sli_update_ring(phba, pring);
5728 lpfc_sli_update_full_ring(phba, pring);
5731 return IOCB_SUCCESS;
5736 pring->stats.iocb_cmd_delay++;
5740 if (!(flag & SLI_IOCB_RET_IOCB)) {
5741 __lpfc_sli_ringtx_put(phba, pring, piocb);
5742 return IOCB_SUCCESS;
5749 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
5750 * @phba: Pointer to HBA context object.
5751 * @piocb: Pointer to command iocb.
5752 * @sglq: Pointer to the scatter gather queue object.
5754 * This routine converts the bpl or bde that is in the IOCB
5755 * to a sgl list for the sli4 hardware. The physical address
5756 * of the bpl/bde is converted back to a virtual address.
5757 * If the IOCB contains a BPL then the list of BDE's is
5758 * converted to sli4_sge's. If the IOCB contains a single
5759 * BDE then it is converted to a single sli_sge.
5760 * The IOCB is still in cpu endianess so the contents of
5761 * the bpl can be used without byte swapping.
5763 * Returns valid XRI = Success, NO_XRI = Failure.
5766 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
5767 struct lpfc_sglq *sglq)
5769 uint16_t xritag = NO_XRI;
5770 struct ulp_bde64 *bpl = NULL;
5771 struct ulp_bde64 bde;
5772 struct sli4_sge *sgl = NULL;
5777 if (!piocbq || !sglq)
5780 sgl = (struct sli4_sge *)sglq->sgl;
5781 icmd = &piocbq->iocb;
5782 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5783 numBdes = icmd->un.genreq64.bdl.bdeSize /
5784 sizeof(struct ulp_bde64);
5785 /* The addrHigh and addrLow fields within the IOCB
5786 * have not been byteswapped yet so there is no
5787 * need to swap them back.
5789 bpl = (struct ulp_bde64 *)
5790 ((struct lpfc_dmabuf *)piocbq->context3)->virt;
5795 for (i = 0; i < numBdes; i++) {
5796 /* Should already be byte swapped. */
5797 sgl->addr_hi = bpl->addrHigh;
5798 sgl->addr_lo = bpl->addrLow;
5799 /* swap the size field back to the cpu so we
5800 * can assign it to the sgl.
5802 bde.tus.w = le32_to_cpu(bpl->tus.w);
5803 bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
5804 if ((i+1) == numBdes)
5805 bf_set(lpfc_sli4_sge_last, sgl, 1);
5807 bf_set(lpfc_sli4_sge_last, sgl, 0);
5808 sgl->word2 = cpu_to_le32(sgl->word2);
5809 sgl->word3 = cpu_to_le32(sgl->word3);
5813 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
5814 /* The addrHigh and addrLow fields of the BDE have not
5815 * been byteswapped yet so they need to be swapped
5816 * before putting them in the sgl.
5819 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
5821 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
5822 bf_set(lpfc_sli4_sge_len, sgl,
5823 icmd->un.genreq64.bdl.bdeSize);
5824 bf_set(lpfc_sli4_sge_last, sgl, 1);
5825 sgl->word2 = cpu_to_le32(sgl->word2);
5826 sgl->word3 = cpu_to_le32(sgl->word3);
5828 return sglq->sli4_xritag;
5832 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5833 * @phba: Pointer to HBA context object.
5835 * This routine performs a round robin SCSI command to SLI4 FCP WQ index
5836 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
5839 * Return: index into SLI4 fast-path FCP queue index.
5842 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
5845 if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
5848 return phba->fcp_qidx;
5852 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
5853 * @phba: Pointer to HBA context object.
5854 * @piocb: Pointer to command iocb.
5855 * @wqe: Pointer to the work queue entry.
5857 * This routine converts the iocb command to its Work Queue Entry
5858 * equivalent. The wqe pointer should not have any fields set when
5859 * this routine is called because it will memcpy over them.
5860 * This routine does not set the CQ_ID or the WQEC bits in the
5863 * Returns: 0 = Success, IOCB_ERROR = Failure.
5866 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
5867 union lpfc_wqe *wqe)
5869 uint32_t payload_len = 0;
5873 uint8_t command_type = ELS_COMMAND_NON_FIP;
5876 struct ulp_bde64 *bpl = NULL;
5878 fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
5879 /* The fcp commands will set command type */
5880 if (iocbq->iocb_flag & LPFC_IO_FCP)
5881 command_type = FCP_COMMAND;
5882 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS))
5883 command_type = ELS_COMMAND_FIP;
5885 command_type = ELS_COMMAND_NON_FIP;
5887 /* Some of the fields are in the right position already */
5888 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
5889 abort_tag = (uint32_t) iocbq->iotag;
5890 xritag = iocbq->sli4_xritag;
5891 wqe->words[7] = 0; /* The ct field has moved so reset */
5892 /* words0-2 bpl convert bde */
5893 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5894 bpl = (struct ulp_bde64 *)
5895 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
5899 /* Should already be byte swapped. */
5900 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
5901 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
5902 /* swap the size field back to the cpu so we
5903 * can assign it to the sgl.
5905 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
5906 payload_len = wqe->generic.bde.tus.f.bdeSize;
5908 payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
5910 iocbq->iocb.ulpIoTag = iocbq->iotag;
5911 cmnd = iocbq->iocb.ulpCommand;
5913 switch (iocbq->iocb.ulpCommand) {
5914 case CMD_ELS_REQUEST64_CR:
5915 if (!iocbq->iocb.ulpLe) {
5916 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5917 "2007 Only Limited Edition cmd Format"
5918 " supported 0x%x\n",
5919 iocbq->iocb.ulpCommand);
5922 wqe->els_req.payload_len = payload_len;
5923 /* Els_reguest64 has a TMO */
5924 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
5925 iocbq->iocb.ulpTimeout);
5926 /* Need a VF for word 4 set the vf bit*/
5927 bf_set(els_req64_vf, &wqe->els_req, 0);
5928 /* And a VFID for word 12 */
5929 bf_set(els_req64_vfid, &wqe->els_req, 0);
5931 * Set ct field to 3, indicates that the context_tag field
5932 * contains the FCFI and remote N_Port_ID is
5936 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
5937 bf_set(lpfc_wqe_gen_context, &wqe->generic,
5938 iocbq->iocb.ulpContext);
5940 bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
5941 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
5942 /* CCP CCPE PV PRI in word10 were set in the memcpy */
5944 case CMD_XMIT_SEQUENCE64_CR:
5945 /* word3 iocb=io_tag32 wqe=payload_offset */
5946 /* payload offset used for multilpe outstanding
5947 * sequences on the same exchange
5950 /* word4 relative_offset memcpy */
5951 /* word5 r_ctl/df_ctl memcpy */
5952 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
5953 wqe->xmit_sequence.xmit_len = payload_len;
5955 case CMD_XMIT_BCAST64_CN:
5956 /* word3 iocb=iotag32 wqe=payload_len */
5957 wqe->words[3] = 0; /* no definition for this in wqe */
5958 /* word4 iocb=rsvd wqe=rsvd */
5959 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
5960 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
5961 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
5962 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
5964 case CMD_FCP_IWRITE64_CR:
5965 command_type = FCP_COMMAND_DATA_OUT;
5966 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
5968 * word3 is payload_len: byte offset to the sgl entry for the
5970 * word4 is total xfer len, same as the IOCB->ulpParameter.
5971 * word5 is initial xfer len 0 = wait for xfer-ready
5974 /* Always wait for xfer-ready before sending data */
5975 wqe->fcp_iwrite.initial_xfer_len = 0;
5976 /* word 4 (xfer length) should have been set on the memcpy */
5978 /* allow write to fall through to read */
5979 case CMD_FCP_IREAD64_CR:
5980 /* FCP_CMD is always the 1st sgl entry */
5981 wqe->fcp_iread.payload_len =
5982 payload_len + sizeof(struct fcp_rsp);
5984 /* word 4 (xfer length) should have been set on the memcpy */
5986 bf_set(lpfc_wqe_gen_erp, &wqe->generic,
5987 iocbq->iocb.ulpFCP2Rcvy);
5988 bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
5989 /* The XC bit and the XS bit are similar. The driver never
5990 * tracked whether or not the exchange was previouslly open.
5991 * XC = Exchange create, 0 is create. 1 is already open.
5992 * XS = link cmd: 1 do not close the exchange after command.
5993 * XS = 0 close exchange when command completes.
5994 * The only time we would not set the XC bit is when the XS bit
5995 * is set and we are sending our 2nd or greater command on
5998 /* Always open the exchange */
5999 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
6001 wqe->words[10] &= 0xffff0000; /* zero out ebde count */
6002 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
6004 case CMD_FCP_ICMND64_CR:
6005 /* Always open the exchange */
6006 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
6009 wqe->words[10] &= 0xffff0000; /* zero out ebde count */
6010 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
6012 case CMD_GEN_REQUEST64_CR:
6013 /* word3 command length is described as byte offset to the
6014 * rsp_data. Would always be 16, sizeof(struct sli4_sge)
6019 wqe->gen_req.command_len = payload_len;
6020 /* Word4 parameter copied in the memcpy */
6021 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
6022 /* word6 context tag copied in memcpy */
6023 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
6024 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
6025 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6026 "2015 Invalid CT %x command 0x%x\n",
6027 ct, iocbq->iocb.ulpCommand);
6030 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
6031 bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
6032 iocbq->iocb.ulpTimeout);
6034 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
6035 command_type = OTHER_COMMAND;
6037 case CMD_XMIT_ELS_RSP64_CX:
6038 /* words0-2 BDE memcpy */
6039 /* word3 iocb=iotag32 wqe=rsvd */
6041 /* word4 iocb=did wge=rsvd. */
6043 /* word5 iocb=rsvd wge=did */
6044 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
6045 iocbq->iocb.un.elsreq64.remoteID);
6047 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
6048 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6050 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
6051 bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
6052 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
6053 bf_set(lpfc_wqe_gen_context, &wqe->generic,
6054 iocbq->vport->vpi + phba->vpi_base);
6055 command_type = OTHER_COMMAND;
6057 case CMD_CLOSE_XRI_CN:
6058 case CMD_ABORT_XRI_CN:
6059 case CMD_ABORT_XRI_CX:
6060 /* words 0-2 memcpy should be 0 rserved */
6061 /* port will send abts */
6062 if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6064 * The link is down so the fw does not need to send abts
6067 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
6069 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
6070 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
6071 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
6073 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
6074 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6075 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
6076 wqe->generic.abort_tag = abort_tag;
6078 * The abort handler will send us CMD_ABORT_XRI_CN or
6079 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6081 bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
6082 cmnd = CMD_ABORT_XRI_CX;
6083 command_type = OTHER_COMMAND;
6086 case CMD_XMIT_BLS_RSP64_CX:
6087 /* As BLS ABTS-ACC WQE is very different from other WQEs,
6088 * we re-construct this WQE here based on information in
6089 * iocbq from scratch.
6091 memset(wqe, 0, sizeof(union lpfc_wqe));
6092 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
6093 iocbq->iocb.un.ulpWord[3]);
6094 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
6095 iocbq->sli4_xritag);
6096 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
6097 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
6098 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
6099 iocbq->iocb.ulpContext);
6100 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
6101 command_type = OTHER_COMMAND;
6103 case CMD_XRI_ABORTED_CX:
6104 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
6105 /* words0-2 are all 0's no bde */
6106 /* word3 and word4 are rsvrd */
6109 /* word5 iocb=rsvd wge=did */
6110 /* There is no remote port id in the IOCB? */
6111 /* Let this fall through and fail */
6112 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
6113 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
6114 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
6115 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
6117 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6118 "2014 Invalid command 0x%x\n",
6119 iocbq->iocb.ulpCommand);
6124 bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
6125 bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
6126 wqe->generic.abort_tag = abort_tag;
6127 bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
6128 bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
6129 bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
6130 bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
6136 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
6137 * @phba: Pointer to HBA context object.
6138 * @ring_number: SLI ring number to issue iocb on.
6139 * @piocb: Pointer to command iocb.
6140 * @flag: Flag indicating if this command can be put into txq.
6142 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
6143 * an iocb command to an HBA with SLI-4 interface spec.
6145 * This function is called with hbalock held. The function will return success
6146 * after it successfully submit the iocb to firmware or after adding to the
6150 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
6151 struct lpfc_iocbq *piocb, uint32_t flag)
6153 struct lpfc_sglq *sglq;
6156 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
6159 if (piocb->sli4_xritag == NO_XRI) {
6160 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6161 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6164 sglq = __lpfc_sli_get_sglq(phba);
6167 piocb->sli4_xritag = sglq->sli4_xritag;
6169 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
6170 sglq = NULL; /* These IO's already have an XRI and
6174 /* This is a continuation of a commandi,(CX) so this
6175 * sglq is on the active list
6177 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
6183 xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
6184 if (xritag != sglq->sli4_xritag)
6188 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
6191 if (piocb->iocb_flag & LPFC_IO_FCP) {
6192 fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
6193 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
6196 if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
6199 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
6205 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6207 * This routine wraps the actual lockless version for issusing IOCB function
6208 * pointer from the lpfc_hba struct.
6211 * IOCB_ERROR - Error
6212 * IOCB_SUCCESS - Success
6216 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
6217 struct lpfc_iocbq *piocb, uint32_t flag)
6219 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
6223 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6224 * @phba: The hba struct for which this call is being executed.
6225 * @dev_grp: The HBA PCI-Device group number.
6227 * This routine sets up the SLI interface API function jump table in @phba
6229 * Returns: 0 - success, -ENODEV - failure.
6232 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6236 case LPFC_PCI_DEV_LP:
6237 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
6238 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
6240 case LPFC_PCI_DEV_OC:
6241 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
6242 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
6245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6246 "1419 Invalid HBA PCI-device group: 0x%x\n",
6251 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
6256 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6257 * @phba: Pointer to HBA context object.
6258 * @pring: Pointer to driver SLI ring object.
6259 * @piocb: Pointer to command iocb.
6260 * @flag: Flag indicating if this command can be put into txq.
6262 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6263 * function. This function gets the hbalock and calls
6264 * __lpfc_sli_issue_iocb function and will return the error returned
6265 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6266 * functions which do not hold hbalock.
6269 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
6270 struct lpfc_iocbq *piocb, uint32_t flag)
6272 unsigned long iflags;
6275 spin_lock_irqsave(&phba->hbalock, iflags);
6276 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
6277 spin_unlock_irqrestore(&phba->hbalock, iflags);
6283 * lpfc_extra_ring_setup - Extra ring setup function
6284 * @phba: Pointer to HBA context object.
6286 * This function is called while driver attaches with the
6287 * HBA to setup the extra ring. The extra ring is used
6288 * only when driver needs to support target mode functionality
6289 * or IP over FC functionalities.
6291 * This function is called with no lock held.
6294 lpfc_extra_ring_setup( struct lpfc_hba *phba)
6296 struct lpfc_sli *psli;
6297 struct lpfc_sli_ring *pring;
6301 /* Adjust cmd/rsp ring iocb entries more evenly */
6303 /* Take some away from the FCP ring */
6304 pring = &psli->ring[psli->fcp_ring];
6305 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6306 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6307 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6308 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6310 /* and give them to the extra ring */
6311 pring = &psli->ring[psli->extra_ring];
6313 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6314 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6315 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6316 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6318 /* Setup default profile for this ring */
6319 pring->iotag_max = 4096;
6320 pring->num_mask = 1;
6321 pring->prt[0].profile = 0; /* Mask 0 */
6322 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
6323 pring->prt[0].type = phba->cfg_multi_ring_type;
6324 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
6329 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6330 * @phba: Pointer to HBA context object.
6331 * @pring: Pointer to driver SLI ring object.
6332 * @iocbq: Pointer to iocb object.
6334 * This function is called by the slow ring event handler
6335 * function when there is an ASYNC event iocb in the ring.
6336 * This function is called with no lock held.
6337 * Currently this function handles only temperature related
6338 * ASYNC events. The function decodes the temperature sensor
6339 * event message and posts events for the management applications.
6342 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
6343 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
6348 struct temp_event temp_event_data;
6349 struct Scsi_Host *shost;
6352 icmd = &iocbq->iocb;
6353 evt_code = icmd->un.asyncstat.evt_code;
6354 temp = icmd->ulpContext;
6356 if ((evt_code != ASYNC_TEMP_WARN) &&
6357 (evt_code != ASYNC_TEMP_SAFE)) {
6358 iocb_w = (uint32_t *) icmd;
6359 lpfc_printf_log(phba,
6362 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6364 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6365 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6366 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6367 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6369 icmd->un.asyncstat.evt_code,
6370 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
6371 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
6372 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
6373 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
6377 temp_event_data.data = (uint32_t)temp;
6378 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6379 if (evt_code == ASYNC_TEMP_WARN) {
6380 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6381 lpfc_printf_log(phba,
6384 "0347 Adapter is very hot, please take "
6385 "corrective action. temperature : %d Celsius\n",
6388 if (evt_code == ASYNC_TEMP_SAFE) {
6389 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6390 lpfc_printf_log(phba,
6393 "0340 Adapter temperature is OK now. "
6394 "temperature : %d Celsius\n",
6398 /* Send temperature change event to applications */
6399 shost = lpfc_shost_from_vport(phba->pport);
6400 fc_host_post_vendor_event(shost, fc_get_event_number(),
6401 sizeof(temp_event_data), (char *) &temp_event_data,
6408 * lpfc_sli_setup - SLI ring setup function
6409 * @phba: Pointer to HBA context object.
6411 * lpfc_sli_setup sets up rings of the SLI interface with
6412 * number of iocbs per ring and iotags. This function is
6413 * called while driver attach to the HBA and before the
6414 * interrupts are enabled. So there is no need for locking.
6416 * This function always returns 0.
6419 lpfc_sli_setup(struct lpfc_hba *phba)
6421 int i, totiocbsize = 0;
6422 struct lpfc_sli *psli = &phba->sli;
6423 struct lpfc_sli_ring *pring;
6425 psli->num_rings = MAX_CONFIGURED_RINGS;
6427 psli->fcp_ring = LPFC_FCP_RING;
6428 psli->next_ring = LPFC_FCP_NEXT_RING;
6429 psli->extra_ring = LPFC_EXTRA_RING;
6431 psli->iocbq_lookup = NULL;
6432 psli->iocbq_lookup_len = 0;
6433 psli->last_iotag = 0;
6435 for (i = 0; i < psli->num_rings; i++) {
6436 pring = &psli->ring[i];
6438 case LPFC_FCP_RING: /* ring 0 - FCP */
6439 /* numCiocb and numRiocb are used in config_port */
6440 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
6441 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
6442 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
6443 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
6444 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
6445 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
6446 pring->sizeCiocb = (phba->sli_rev == 3) ?
6447 SLI3_IOCB_CMD_SIZE :
6449 pring->sizeRiocb = (phba->sli_rev == 3) ?
6450 SLI3_IOCB_RSP_SIZE :
6452 pring->iotag_ctr = 0;
6454 (phba->cfg_hba_queue_depth * 2);
6455 pring->fast_iotag = pring->iotag_max;
6456 pring->num_mask = 0;
6458 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
6459 /* numCiocb and numRiocb are used in config_port */
6460 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
6461 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
6462 pring->sizeCiocb = (phba->sli_rev == 3) ?
6463 SLI3_IOCB_CMD_SIZE :
6465 pring->sizeRiocb = (phba->sli_rev == 3) ?
6466 SLI3_IOCB_RSP_SIZE :
6468 pring->iotag_max = phba->cfg_hba_queue_depth;
6469 pring->num_mask = 0;
6471 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
6472 /* numCiocb and numRiocb are used in config_port */
6473 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
6474 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
6475 pring->sizeCiocb = (phba->sli_rev == 3) ?
6476 SLI3_IOCB_CMD_SIZE :
6478 pring->sizeRiocb = (phba->sli_rev == 3) ?
6479 SLI3_IOCB_RSP_SIZE :
6481 pring->fast_iotag = 0;
6482 pring->iotag_ctr = 0;
6483 pring->iotag_max = 4096;
6484 pring->lpfc_sli_rcv_async_status =
6485 lpfc_sli_async_event_handler;
6486 pring->num_mask = LPFC_MAX_RING_MASK;
6487 pring->prt[0].profile = 0; /* Mask 0 */
6488 pring->prt[0].rctl = FC_ELS_REQ;
6489 pring->prt[0].type = FC_ELS_DATA;
6490 pring->prt[0].lpfc_sli_rcv_unsol_event =
6491 lpfc_els_unsol_event;
6492 pring->prt[1].profile = 0; /* Mask 1 */
6493 pring->prt[1].rctl = FC_ELS_RSP;
6494 pring->prt[1].type = FC_ELS_DATA;
6495 pring->prt[1].lpfc_sli_rcv_unsol_event =
6496 lpfc_els_unsol_event;
6497 pring->prt[2].profile = 0; /* Mask 2 */
6498 /* NameServer Inquiry */
6499 pring->prt[2].rctl = FC_UNSOL_CTL;
6501 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
6502 pring->prt[2].lpfc_sli_rcv_unsol_event =
6503 lpfc_ct_unsol_event;
6504 pring->prt[3].profile = 0; /* Mask 3 */
6505 /* NameServer response */
6506 pring->prt[3].rctl = FC_SOL_CTL;
6508 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
6509 pring->prt[3].lpfc_sli_rcv_unsol_event =
6510 lpfc_ct_unsol_event;
6511 /* abort unsolicited sequence */
6512 pring->prt[4].profile = 0; /* Mask 4 */
6513 pring->prt[4].rctl = FC_RCTL_BA_ABTS;
6514 pring->prt[4].type = FC_TYPE_BLS;
6515 pring->prt[4].lpfc_sli_rcv_unsol_event =
6516 lpfc_sli4_ct_abort_unsol_event;
6519 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
6520 (pring->numRiocb * pring->sizeRiocb);
6522 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
6523 /* Too many cmd / rsp ring entries in SLI2 SLIM */
6524 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
6525 "SLI2 SLIM Data: x%x x%lx\n",
6526 phba->brd_no, totiocbsize,
6527 (unsigned long) MAX_SLIM_IOCB_SIZE);
6529 if (phba->cfg_multi_ring_support == 2)
6530 lpfc_extra_ring_setup(phba);
6536 * lpfc_sli_queue_setup - Queue initialization function
6537 * @phba: Pointer to HBA context object.
6539 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
6540 * ring. This function also initializes ring indices of each ring.
6541 * This function is called during the initialization of the SLI
6542 * interface of an HBA.
6543 * This function is called with no lock held and always returns
6547 lpfc_sli_queue_setup(struct lpfc_hba *phba)
6549 struct lpfc_sli *psli;
6550 struct lpfc_sli_ring *pring;
6554 spin_lock_irq(&phba->hbalock);
6555 INIT_LIST_HEAD(&psli->mboxq);
6556 INIT_LIST_HEAD(&psli->mboxq_cmpl);
6557 /* Initialize list headers for txq and txcmplq as double linked lists */
6558 for (i = 0; i < psli->num_rings; i++) {
6559 pring = &psli->ring[i];
6561 pring->next_cmdidx = 0;
6562 pring->local_getidx = 0;
6564 INIT_LIST_HEAD(&pring->txq);
6565 INIT_LIST_HEAD(&pring->txcmplq);
6566 INIT_LIST_HEAD(&pring->iocb_continueq);
6567 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
6568 INIT_LIST_HEAD(&pring->postbufq);
6570 spin_unlock_irq(&phba->hbalock);
6575 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
6576 * @phba: Pointer to HBA context object.
6578 * This routine flushes the mailbox command subsystem. It will unconditionally
6579 * flush all the mailbox commands in the three possible stages in the mailbox
6580 * command sub-system: pending mailbox command queue; the outstanding mailbox
6581 * command; and completed mailbox command queue. It is caller's responsibility
6582 * to make sure that the driver is in the proper state to flush the mailbox
6583 * command sub-system. Namely, the posting of mailbox commands into the
6584 * pending mailbox command queue from the various clients must be stopped;
6585 * either the HBA is in a state that it will never works on the outstanding
6586 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
6587 * mailbox command has been completed.
6590 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
6592 LIST_HEAD(completions);
6593 struct lpfc_sli *psli = &phba->sli;
6595 unsigned long iflag;
6597 /* Flush all the mailbox commands in the mbox system */
6598 spin_lock_irqsave(&phba->hbalock, iflag);
6599 /* The pending mailbox command queue */
6600 list_splice_init(&phba->sli.mboxq, &completions);
6601 /* The outstanding active mailbox command */
6602 if (psli->mbox_active) {
6603 list_add_tail(&psli->mbox_active->list, &completions);
6604 psli->mbox_active = NULL;
6605 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6607 /* The completed mailbox command queue */
6608 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
6609 spin_unlock_irqrestore(&phba->hbalock, iflag);
6611 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
6612 while (!list_empty(&completions)) {
6613 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
6614 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
6616 pmb->mbox_cmpl(phba, pmb);
6621 * lpfc_sli_host_down - Vport cleanup function
6622 * @vport: Pointer to virtual port object.
6624 * lpfc_sli_host_down is called to clean up the resources
6625 * associated with a vport before destroying virtual
6626 * port data structures.
6627 * This function does following operations:
6628 * - Free discovery resources associated with this virtual
6630 * - Free iocbs associated with this virtual port in
6632 * - Send abort for all iocb commands associated with this
6635 * This function is called with no lock held and always returns 1.
6638 lpfc_sli_host_down(struct lpfc_vport *vport)
6640 LIST_HEAD(completions);
6641 struct lpfc_hba *phba = vport->phba;
6642 struct lpfc_sli *psli = &phba->sli;
6643 struct lpfc_sli_ring *pring;
6644 struct lpfc_iocbq *iocb, *next_iocb;
6646 unsigned long flags = 0;
6647 uint16_t prev_pring_flag;
6649 lpfc_cleanup_discovery_resources(vport);
6651 spin_lock_irqsave(&phba->hbalock, flags);
6652 for (i = 0; i < psli->num_rings; i++) {
6653 pring = &psli->ring[i];
6654 prev_pring_flag = pring->flag;
6655 /* Only slow rings */
6656 if (pring->ringno == LPFC_ELS_RING) {
6657 pring->flag |= LPFC_DEFERRED_RING_EVENT;
6658 /* Set the lpfc data pending flag */
6659 set_bit(LPFC_DATA_READY, &phba->data_flags);
6662 * Error everything on the txq since these iocbs have not been
6663 * given to the FW yet.
6665 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6666 if (iocb->vport != vport)
6668 list_move_tail(&iocb->list, &completions);
6672 /* Next issue ABTS for everything on the txcmplq */
6673 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
6675 if (iocb->vport != vport)
6677 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
6680 pring->flag = prev_pring_flag;
6683 spin_unlock_irqrestore(&phba->hbalock, flags);
6685 /* Cancel all the IOCBs from the completions list */
6686 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6692 * lpfc_sli_hba_down - Resource cleanup function for the HBA
6693 * @phba: Pointer to HBA context object.
6695 * This function cleans up all iocb, buffers, mailbox commands
6696 * while shutting down the HBA. This function is called with no
6697 * lock held and always returns 1.
6698 * This function does the following to cleanup driver resources:
6699 * - Free discovery resources for each virtual port
6700 * - Cleanup any pending fabric iocbs
6701 * - Iterate through the iocb txq and free each entry
6703 * - Free up any buffer posted to the HBA
6704 * - Free mailbox commands in the mailbox queue.
6707 lpfc_sli_hba_down(struct lpfc_hba *phba)
6709 LIST_HEAD(completions);
6710 struct lpfc_sli *psli = &phba->sli;
6711 struct lpfc_sli_ring *pring;
6712 struct lpfc_dmabuf *buf_ptr;
6713 unsigned long flags = 0;
6716 /* Shutdown the mailbox command sub-system */
6717 lpfc_sli_mbox_sys_shutdown(phba);
6719 lpfc_hba_down_prep(phba);
6721 lpfc_fabric_abort_hba(phba);
6723 spin_lock_irqsave(&phba->hbalock, flags);
6724 for (i = 0; i < psli->num_rings; i++) {
6725 pring = &psli->ring[i];
6726 /* Only slow rings */
6727 if (pring->ringno == LPFC_ELS_RING) {
6728 pring->flag |= LPFC_DEFERRED_RING_EVENT;
6729 /* Set the lpfc data pending flag */
6730 set_bit(LPFC_DATA_READY, &phba->data_flags);
6734 * Error everything on the txq since these iocbs have not been
6735 * given to the FW yet.
6737 list_splice_init(&pring->txq, &completions);
6741 spin_unlock_irqrestore(&phba->hbalock, flags);
6743 /* Cancel all the IOCBs from the completions list */
6744 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6747 spin_lock_irqsave(&phba->hbalock, flags);
6748 list_splice_init(&phba->elsbuf, &completions);
6749 phba->elsbuf_cnt = 0;
6750 phba->elsbuf_prev_cnt = 0;
6751 spin_unlock_irqrestore(&phba->hbalock, flags);
6753 while (!list_empty(&completions)) {
6754 list_remove_head(&completions, buf_ptr,
6755 struct lpfc_dmabuf, list);
6756 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
6760 /* Return any active mbox cmds */
6761 del_timer_sync(&psli->mbox_tmo);
6763 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
6764 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
6765 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
6771 * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
6772 * @phba: Pointer to HBA context object.
6774 * This function cleans up all queues, iocb, buffers, mailbox commands while
6775 * shutting down the SLI4 HBA FCoE function. This function is called with no
6776 * lock held and always returns 1.
6778 * This function does the following to cleanup driver FCoE function resources:
6779 * - Free discovery resources for each virtual port
6780 * - Cleanup any pending fabric iocbs
6781 * - Iterate through the iocb txq and free each entry in the list.
6782 * - Free up any buffer posted to the HBA.
6783 * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
6784 * - Free mailbox commands in the mailbox queue.
6787 lpfc_sli4_hba_down(struct lpfc_hba *phba)
6789 /* Stop the SLI4 device port */
6790 lpfc_stop_port(phba);
6792 /* Tear down the queues in the HBA */
6793 lpfc_sli4_queue_unset(phba);
6795 /* unregister default FCFI from the HBA */
6796 lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
6802 * lpfc_sli_pcimem_bcopy - SLI memory copy function
6803 * @srcp: Source memory pointer.
6804 * @destp: Destination memory pointer.
6805 * @cnt: Number of words required to be copied.
6807 * This function is used for copying data between driver memory
6808 * and the SLI memory. This function also changes the endianness
6809 * of each word if native endianness is different from SLI
6810 * endianness. This function can be called with or without
6814 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
6816 uint32_t *src = srcp;
6817 uint32_t *dest = destp;
6821 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
6823 ldata = le32_to_cpu(ldata);
6832 * lpfc_sli_bemem_bcopy - SLI memory copy function
6833 * @srcp: Source memory pointer.
6834 * @destp: Destination memory pointer.
6835 * @cnt: Number of words required to be copied.
6837 * This function is used for copying data between a data structure
6838 * with big endian representation to local endianness.
6839 * This function can be called with or without lock.
6842 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
6844 uint32_t *src = srcp;
6845 uint32_t *dest = destp;
6849 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
6851 ldata = be32_to_cpu(ldata);
6859 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
6860 * @phba: Pointer to HBA context object.
6861 * @pring: Pointer to driver SLI ring object.
6862 * @mp: Pointer to driver buffer object.
6864 * This function is called with no lock held.
6865 * It always return zero after adding the buffer to the postbufq
6869 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6870 struct lpfc_dmabuf *mp)
6872 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
6874 spin_lock_irq(&phba->hbalock);
6875 list_add_tail(&mp->list, &pring->postbufq);
6876 pring->postbufq_cnt++;
6877 spin_unlock_irq(&phba->hbalock);
6882 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
6883 * @phba: Pointer to HBA context object.
6885 * When HBQ is enabled, buffers are searched based on tags. This function
6886 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
6887 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
6888 * does not conflict with tags of buffer posted for unsolicited events.
6889 * The function returns the allocated tag. The function is called with
6893 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
6895 spin_lock_irq(&phba->hbalock);
6896 phba->buffer_tag_count++;
6898 * Always set the QUE_BUFTAG_BIT to distiguish between
6899 * a tag assigned by HBQ.
6901 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
6902 spin_unlock_irq(&phba->hbalock);
6903 return phba->buffer_tag_count;
6907 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
6908 * @phba: Pointer to HBA context object.
6909 * @pring: Pointer to driver SLI ring object.
6912 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
6913 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
6914 * iocb is posted to the response ring with the tag of the buffer.
6915 * This function searches the pring->postbufq list using the tag
6916 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
6917 * iocb. If the buffer is found then lpfc_dmabuf object of the
6918 * buffer is returned to the caller else NULL is returned.
6919 * This function is called with no lock held.
6921 struct lpfc_dmabuf *
6922 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6925 struct lpfc_dmabuf *mp, *next_mp;
6926 struct list_head *slp = &pring->postbufq;
6928 /* Search postbufq, from the begining, looking for a match on tag */
6929 spin_lock_irq(&phba->hbalock);
6930 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
6931 if (mp->buffer_tag == tag) {
6932 list_del_init(&mp->list);
6933 pring->postbufq_cnt--;
6934 spin_unlock_irq(&phba->hbalock);
6939 spin_unlock_irq(&phba->hbalock);
6940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6941 "0402 Cannot find virtual addr for buffer tag on "
6942 "ring %d Data x%lx x%p x%p x%x\n",
6943 pring->ringno, (unsigned long) tag,
6944 slp->next, slp->prev, pring->postbufq_cnt);
6950 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
6951 * @phba: Pointer to HBA context object.
6952 * @pring: Pointer to driver SLI ring object.
6953 * @phys: DMA address of the buffer.
6955 * This function searches the buffer list using the dma_address
6956 * of unsolicited event to find the driver's lpfc_dmabuf object
6957 * corresponding to the dma_address. The function returns the
6958 * lpfc_dmabuf object if a buffer is found else it returns NULL.
6959 * This function is called by the ct and els unsolicited event
6960 * handlers to get the buffer associated with the unsolicited
6963 * This function is called with no lock held.
6965 struct lpfc_dmabuf *
6966 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6969 struct lpfc_dmabuf *mp, *next_mp;
6970 struct list_head *slp = &pring->postbufq;
6972 /* Search postbufq, from the begining, looking for a match on phys */
6973 spin_lock_irq(&phba->hbalock);
6974 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
6975 if (mp->phys == phys) {
6976 list_del_init(&mp->list);
6977 pring->postbufq_cnt--;
6978 spin_unlock_irq(&phba->hbalock);
6983 spin_unlock_irq(&phba->hbalock);
6984 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6985 "0410 Cannot find virtual addr for mapped buf on "
6986 "ring %d Data x%llx x%p x%p x%x\n",
6987 pring->ringno, (unsigned long long)phys,
6988 slp->next, slp->prev, pring->postbufq_cnt);
6993 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
6994 * @phba: Pointer to HBA context object.
6995 * @cmdiocb: Pointer to driver command iocb object.
6996 * @rspiocb: Pointer to driver response iocb object.
6998 * This function is the completion handler for the abort iocbs for
6999 * ELS commands. This function is called from the ELS ring event
7000 * handler with no lock held. This function frees memory resources
7001 * associated with the abort iocb.
7004 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7005 struct lpfc_iocbq *rspiocb)
7007 IOCB_t *irsp = &rspiocb->iocb;
7008 uint16_t abort_iotag, abort_context;
7009 struct lpfc_iocbq *abort_iocb;
7010 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7014 if (irsp->ulpStatus) {
7015 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
7016 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
7018 spin_lock_irq(&phba->hbalock);
7019 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
7020 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
7022 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
7023 "0327 Cannot abort els iocb %p "
7024 "with tag %x context %x, abort status %x, "
7026 abort_iocb, abort_iotag, abort_context,
7027 irsp->ulpStatus, irsp->un.ulpWord[4]);
7030 * If the iocb is not found in Firmware queue the iocb
7031 * might have completed already. Do not free it again.
7033 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
7034 spin_unlock_irq(&phba->hbalock);
7035 lpfc_sli_release_iocbq(phba, cmdiocb);
7039 * make sure we have the right iocbq before taking it
7040 * off the txcmplq and try to call completion routine.
7043 abort_iocb->iocb.ulpContext != abort_context ||
7044 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
7045 spin_unlock_irq(&phba->hbalock);
7047 list_del_init(&abort_iocb->list);
7048 pring->txcmplq_cnt--;
7049 spin_unlock_irq(&phba->hbalock);
7051 /* Firmware could still be in progress of DMAing
7052 * payload, so don't free data buffer till after
7055 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
7057 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
7058 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
7059 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
7060 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
7064 lpfc_sli_release_iocbq(phba, cmdiocb);
7069 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
7070 * @phba: Pointer to HBA context object.
7071 * @cmdiocb: Pointer to driver command iocb object.
7072 * @rspiocb: Pointer to driver response iocb object.
7074 * The function is called from SLI ring event handler with no
7075 * lock held. This function is the completion handler for ELS commands
7076 * which are aborted. The function frees memory resources used for
7077 * the aborted ELS commands.
7080 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7081 struct lpfc_iocbq *rspiocb)
7083 IOCB_t *irsp = &rspiocb->iocb;
7085 /* ELS cmd tag <ulpIoTag> completes */
7086 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
7087 "0139 Ignoring ELS cmd tag x%x completion Data: "
7089 irsp->ulpIoTag, irsp->ulpStatus,
7090 irsp->un.ulpWord[4], irsp->ulpTimeout);
7091 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
7092 lpfc_ct_free_iocb(phba, cmdiocb);
7094 lpfc_els_free_iocb(phba, cmdiocb);
7099 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7100 * @phba: Pointer to HBA context object.
7101 * @pring: Pointer to driver SLI ring object.
7102 * @cmdiocb: Pointer to driver command iocb object.
7104 * This function issues an abort iocb for the provided command
7105 * iocb. This function is called with hbalock held.
7106 * The function returns 0 when it fails due to memory allocation
7107 * failure or when the command iocb is an abort request.
7110 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7111 struct lpfc_iocbq *cmdiocb)
7113 struct lpfc_vport *vport = cmdiocb->vport;
7114 struct lpfc_iocbq *abtsiocbp;
7115 IOCB_t *icmd = NULL;
7116 IOCB_t *iabt = NULL;
7117 int retval = IOCB_ERROR;
7120 * There are certain command types we don't want to abort. And we
7121 * don't want to abort commands that are already in the process of
7124 icmd = &cmdiocb->iocb;
7125 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
7126 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7127 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
7130 /* If we're unloading, don't abort iocb on the ELS ring, but change the
7131 * callback so that nothing happens when it finishes.
7133 if ((vport->load_flag & FC_UNLOADING) &&
7134 (pring->ringno == LPFC_ELS_RING)) {
7135 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
7136 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
7138 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
7139 goto abort_iotag_exit;
7142 /* issue ABTS for this IOCB based on iotag */
7143 abtsiocbp = __lpfc_sli_get_iocbq(phba);
7144 if (abtsiocbp == NULL)
7147 /* This signals the response to set the correct status
7148 * before calling the completion handler.
7150 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
7152 iabt = &abtsiocbp->iocb;
7153 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
7154 iabt->un.acxri.abortContextTag = icmd->ulpContext;
7155 if (phba->sli_rev == LPFC_SLI_REV4)
7156 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
7158 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
7160 iabt->ulpClass = icmd->ulpClass;
7162 if (phba->link_state >= LPFC_LINK_UP)
7163 iabt->ulpCommand = CMD_ABORT_XRI_CN;
7165 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
7167 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
7169 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
7170 "0339 Abort xri x%x, original iotag x%x, "
7171 "abort cmd iotag x%x\n",
7172 iabt->un.acxri.abortContextTag,
7173 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
7174 retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
7177 __lpfc_sli_release_iocbq(phba, abtsiocbp);
7180 * Caller to this routine should check for IOCB_ERROR
7181 * and handle it properly. This routine no longer removes
7182 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7188 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7189 * @iocbq: Pointer to driver iocb object.
7190 * @vport: Pointer to driver virtual port object.
7191 * @tgt_id: SCSI ID of the target.
7192 * @lun_id: LUN ID of the scsi device.
7193 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
7195 * This function acts as an iocb filter for functions which abort or count
7196 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
7197 * 0 if the filtering criteria is met for the given iocb and will return
7198 * 1 if the filtering criteria is not met.
7199 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
7200 * given iocb is for the SCSI device specified by vport, tgt_id and
7202 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
7203 * given iocb is for the SCSI target specified by vport and tgt_id
7205 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
7206 * given iocb is for the SCSI host associated with the given vport.
7207 * This function is called with no locks held.
7210 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
7211 uint16_t tgt_id, uint64_t lun_id,
7212 lpfc_ctx_cmd ctx_cmd)
7214 struct lpfc_scsi_buf *lpfc_cmd;
7217 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
7220 if (iocbq->vport != vport)
7223 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
7225 if (lpfc_cmd->pCmd == NULL)
7230 if ((lpfc_cmd->rdata->pnode) &&
7231 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
7232 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
7236 if ((lpfc_cmd->rdata->pnode) &&
7237 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
7244 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
7253 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7254 * @vport: Pointer to virtual port.
7255 * @tgt_id: SCSI ID of the target.
7256 * @lun_id: LUN ID of the scsi device.
7257 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7259 * This function returns number of FCP commands pending for the vport.
7260 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7261 * commands pending on the vport associated with SCSI device specified
7262 * by tgt_id and lun_id parameters.
7263 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7264 * commands pending on the vport associated with SCSI target specified
7265 * by tgt_id parameter.
7266 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7267 * commands pending on the vport.
7268 * This function returns the number of iocbs which satisfy the filter.
7269 * This function is called without any lock held.
7272 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
7273 lpfc_ctx_cmd ctx_cmd)
7275 struct lpfc_hba *phba = vport->phba;
7276 struct lpfc_iocbq *iocbq;
7279 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
7280 iocbq = phba->sli.iocbq_lookup[i];
7282 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
7291 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7292 * @phba: Pointer to HBA context object
7293 * @cmdiocb: Pointer to command iocb object.
7294 * @rspiocb: Pointer to response iocb object.
7296 * This function is called when an aborted FCP iocb completes. This
7297 * function is called by the ring event handler with no lock held.
7298 * This function frees the iocb.
7301 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7302 struct lpfc_iocbq *rspiocb)
7304 lpfc_sli_release_iocbq(phba, cmdiocb);
7309 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
7310 * @vport: Pointer to virtual port.
7311 * @pring: Pointer to driver SLI ring object.
7312 * @tgt_id: SCSI ID of the target.
7313 * @lun_id: LUN ID of the scsi device.
7314 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7316 * This function sends an abort command for every SCSI command
7317 * associated with the given virtual port pending on the ring
7318 * filtered by lpfc_sli_validate_fcp_iocb function.
7319 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
7320 * FCP iocbs associated with lun specified by tgt_id and lun_id
7322 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
7323 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
7324 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
7325 * FCP iocbs associated with virtual port.
7326 * This function returns number of iocbs it failed to abort.
7327 * This function is called with no locks held.
7330 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
7331 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
7333 struct lpfc_hba *phba = vport->phba;
7334 struct lpfc_iocbq *iocbq;
7335 struct lpfc_iocbq *abtsiocb;
7337 int errcnt = 0, ret_val = 0;
7340 for (i = 1; i <= phba->sli.last_iotag; i++) {
7341 iocbq = phba->sli.iocbq_lookup[i];
7343 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
7347 /* issue ABTS for this IOCB based on iotag */
7348 abtsiocb = lpfc_sli_get_iocbq(phba);
7349 if (abtsiocb == NULL) {
7355 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
7356 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
7357 if (phba->sli_rev == LPFC_SLI_REV4)
7358 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
7360 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
7361 abtsiocb->iocb.ulpLe = 1;
7362 abtsiocb->iocb.ulpClass = cmd->ulpClass;
7363 abtsiocb->vport = phba->pport;
7365 if (lpfc_is_link_up(phba))
7366 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
7368 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
7370 /* Setup callback routine and issue the command. */
7371 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
7372 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
7374 if (ret_val == IOCB_ERROR) {
7375 lpfc_sli_release_iocbq(phba, abtsiocb);
7385 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
7386 * @phba: Pointer to HBA context object.
7387 * @cmdiocbq: Pointer to command iocb.
7388 * @rspiocbq: Pointer to response iocb.
7390 * This function is the completion handler for iocbs issued using
7391 * lpfc_sli_issue_iocb_wait function. This function is called by the
7392 * ring event handler function without any lock held. This function
7393 * can be called from both worker thread context and interrupt
7394 * context. This function also can be called from other thread which
7395 * cleans up the SLI layer objects.
7396 * This function copy the contents of the response iocb to the
7397 * response iocb memory object provided by the caller of
7398 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
7399 * sleeps for the iocb completion.
7402 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
7403 struct lpfc_iocbq *cmdiocbq,
7404 struct lpfc_iocbq *rspiocbq)
7406 wait_queue_head_t *pdone_q;
7407 unsigned long iflags;
7409 spin_lock_irqsave(&phba->hbalock, iflags);
7410 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
7411 if (cmdiocbq->context2 && rspiocbq)
7412 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
7413 &rspiocbq->iocb, sizeof(IOCB_t));
7415 pdone_q = cmdiocbq->context_un.wait_queue;
7418 spin_unlock_irqrestore(&phba->hbalock, iflags);
7423 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
7424 * @phba: Pointer to HBA context object..
7425 * @piocbq: Pointer to command iocb.
7426 * @flag: Flag to test.
7428 * This routine grabs the hbalock and then test the iocb_flag to
7429 * see if the passed in flag is set.
7432 * 0 if flag is not set.
7435 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
7436 struct lpfc_iocbq *piocbq, uint32_t flag)
7438 unsigned long iflags;
7441 spin_lock_irqsave(&phba->hbalock, iflags);
7442 ret = piocbq->iocb_flag & flag;
7443 spin_unlock_irqrestore(&phba->hbalock, iflags);
7449 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
7450 * @phba: Pointer to HBA context object..
7451 * @pring: Pointer to sli ring.
7452 * @piocb: Pointer to command iocb.
7453 * @prspiocbq: Pointer to response iocb.
7454 * @timeout: Timeout in number of seconds.
7456 * This function issues the iocb to firmware and waits for the
7457 * iocb to complete. If the iocb command is not
7458 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
7459 * Caller should not free the iocb resources if this function
7460 * returns IOCB_TIMEDOUT.
7461 * The function waits for the iocb completion using an
7462 * non-interruptible wait.
7463 * This function will sleep while waiting for iocb completion.
7464 * So, this function should not be called from any context which
7465 * does not allow sleeping. Due to the same reason, this function
7466 * cannot be called with interrupt disabled.
7467 * This function assumes that the iocb completions occur while
7468 * this function sleep. So, this function cannot be called from
7469 * the thread which process iocb completion for this ring.
7470 * This function clears the iocb_flag of the iocb object before
7471 * issuing the iocb and the iocb completion handler sets this
7472 * flag and wakes this thread when the iocb completes.
7473 * The contents of the response iocb will be copied to prspiocbq
7474 * by the completion handler when the command completes.
7475 * This function returns IOCB_SUCCESS when success.
7476 * This function is called with no lock held.
7479 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
7480 uint32_t ring_number,
7481 struct lpfc_iocbq *piocb,
7482 struct lpfc_iocbq *prspiocbq,
7485 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
7486 long timeleft, timeout_req = 0;
7487 int retval = IOCB_SUCCESS;
7491 * If the caller has provided a response iocbq buffer, then context2
7492 * is NULL or its an error.
7495 if (piocb->context2)
7497 piocb->context2 = prspiocbq;
7500 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
7501 piocb->context_un.wait_queue = &done_q;
7502 piocb->iocb_flag &= ~LPFC_IO_WAKE;
7504 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7505 creg_val = readl(phba->HCregaddr);
7506 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
7507 writel(creg_val, phba->HCregaddr);
7508 readl(phba->HCregaddr); /* flush */
7511 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
7512 if (retval == IOCB_SUCCESS) {
7513 timeout_req = timeout * HZ;
7514 timeleft = wait_event_timeout(done_q,
7515 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
7518 if (piocb->iocb_flag & LPFC_IO_WAKE) {
7519 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7520 "0331 IOCB wake signaled\n");
7521 } else if (timeleft == 0) {
7522 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7523 "0338 IOCB wait timeout error - no "
7524 "wake response Data x%x\n", timeout);
7525 retval = IOCB_TIMEDOUT;
7527 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7528 "0330 IOCB wake NOT set, "
7530 timeout, (timeleft / jiffies));
7531 retval = IOCB_TIMEDOUT;
7534 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7535 "0332 IOCB wait issue failed, Data x%x\n",
7537 retval = IOCB_ERROR;
7540 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7541 creg_val = readl(phba->HCregaddr);
7542 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
7543 writel(creg_val, phba->HCregaddr);
7544 readl(phba->HCregaddr); /* flush */
7548 piocb->context2 = NULL;
7550 piocb->context_un.wait_queue = NULL;
7551 piocb->iocb_cmpl = NULL;
7556 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
7557 * @phba: Pointer to HBA context object.
7558 * @pmboxq: Pointer to driver mailbox object.
7559 * @timeout: Timeout in number of seconds.
7561 * This function issues the mailbox to firmware and waits for the
7562 * mailbox command to complete. If the mailbox command is not
7563 * completed within timeout seconds, it returns MBX_TIMEOUT.
7564 * The function waits for the mailbox completion using an
7565 * interruptible wait. If the thread is woken up due to a
7566 * signal, MBX_TIMEOUT error is returned to the caller. Caller
7567 * should not free the mailbox resources, if this function returns
7569 * This function will sleep while waiting for mailbox completion.
7570 * So, this function should not be called from any context which
7571 * does not allow sleeping. Due to the same reason, this function
7572 * cannot be called with interrupt disabled.
7573 * This function assumes that the mailbox completion occurs while
7574 * this function sleep. So, this function cannot be called from
7575 * the worker thread which processes mailbox completion.
7576 * This function is called in the context of HBA management
7578 * This function returns MBX_SUCCESS when successful.
7579 * This function is called with no lock held.
7582 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
7585 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
7589 /* The caller must leave context1 empty. */
7590 if (pmboxq->context1)
7591 return MBX_NOT_FINISHED;
7593 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
7594 /* setup wake call as IOCB callback */
7595 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
7596 /* setup context field to pass wait_queue pointer to wake function */
7597 pmboxq->context1 = &done_q;
7599 /* now issue the command */
7600 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
7602 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
7603 wait_event_interruptible_timeout(done_q,
7604 pmboxq->mbox_flag & LPFC_MBX_WAKE,
7607 spin_lock_irqsave(&phba->hbalock, flag);
7608 pmboxq->context1 = NULL;
7610 * if LPFC_MBX_WAKE flag is set the mailbox is completed
7611 * else do not free the resources.
7613 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
7614 retval = MBX_SUCCESS;
7616 retval = MBX_TIMEOUT;
7617 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7619 spin_unlock_irqrestore(&phba->hbalock, flag);
7626 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
7627 * @phba: Pointer to HBA context.
7629 * This function is called to shutdown the driver's mailbox sub-system.
7630 * It first marks the mailbox sub-system is in a block state to prevent
7631 * the asynchronous mailbox command from issued off the pending mailbox
7632 * command queue. If the mailbox command sub-system shutdown is due to
7633 * HBA error conditions such as EEH or ERATT, this routine shall invoke
7634 * the mailbox sub-system flush routine to forcefully bring down the
7635 * mailbox sub-system. Otherwise, if it is due to normal condition (such
7636 * as with offline or HBA function reset), this routine will wait for the
7637 * outstanding mailbox command to complete before invoking the mailbox
7638 * sub-system flush routine to gracefully bring down mailbox sub-system.
7641 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
7643 struct lpfc_sli *psli = &phba->sli;
7644 uint8_t actcmd = MBX_HEARTBEAT;
7645 unsigned long timeout;
7647 spin_lock_irq(&phba->hbalock);
7648 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
7649 spin_unlock_irq(&phba->hbalock);
7651 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7652 spin_lock_irq(&phba->hbalock);
7653 if (phba->sli.mbox_active)
7654 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
7655 spin_unlock_irq(&phba->hbalock);
7656 /* Determine how long we might wait for the active mailbox
7657 * command to be gracefully completed by firmware.
7659 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
7661 while (phba->sli.mbox_active) {
7662 /* Check active mailbox complete status every 2ms */
7664 if (time_after(jiffies, timeout))
7665 /* Timeout, let the mailbox flush routine to
7666 * forcefully release active mailbox command
7671 lpfc_sli_mbox_sys_flush(phba);
7675 * lpfc_sli_eratt_read - read sli-3 error attention events
7676 * @phba: Pointer to HBA context.
7678 * This function is called to read the SLI3 device error attention registers
7679 * for possible error attention events. The caller must hold the hostlock
7680 * with spin_lock_irq().
7682 * This fucntion returns 1 when there is Error Attention in the Host Attention
7683 * Register and returns 0 otherwise.
7686 lpfc_sli_eratt_read(struct lpfc_hba *phba)
7690 /* Read chip Host Attention (HA) register */
7691 ha_copy = readl(phba->HAregaddr);
7692 if (ha_copy & HA_ERATT) {
7693 /* Read host status register to retrieve error event */
7694 lpfc_sli_read_hs(phba);
7696 /* Check if there is a deferred error condition is active */
7697 if ((HS_FFER1 & phba->work_hs) &&
7698 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
7699 HS_FFER6 | HS_FFER7) & phba->work_hs)) {
7700 phba->hba_flag |= DEFER_ERATT;
7701 /* Clear all interrupt enable conditions */
7702 writel(0, phba->HCregaddr);
7703 readl(phba->HCregaddr);
7706 /* Set the driver HA work bitmap */
7707 phba->work_ha |= HA_ERATT;
7708 /* Indicate polling handles this ERATT */
7709 phba->hba_flag |= HBA_ERATT_HANDLED;
7716 * lpfc_sli4_eratt_read - read sli-4 error attention events
7717 * @phba: Pointer to HBA context.
7719 * This function is called to read the SLI4 device error attention registers
7720 * for possible error attention events. The caller must hold the hostlock
7721 * with spin_lock_irq().
7723 * This fucntion returns 1 when there is Error Attention in the Host Attention
7724 * Register and returns 0 otherwise.
7727 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
7729 uint32_t uerr_sta_hi, uerr_sta_lo;
7730 uint32_t onlnreg0, onlnreg1;
7732 /* For now, use the SLI4 device internal unrecoverable error
7733 * registers for error attention. This can be changed later.
7735 onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
7736 onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
7737 if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
7738 uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
7739 uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
7740 if (uerr_sta_lo || uerr_sta_hi) {
7741 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7742 "1423 HBA Unrecoverable error: "
7743 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
7744 "online0_reg=0x%x, online1_reg=0x%x\n",
7745 uerr_sta_lo, uerr_sta_hi,
7746 onlnreg0, onlnreg1);
7747 phba->work_status[0] = uerr_sta_lo;
7748 phba->work_status[1] = uerr_sta_hi;
7749 /* Set the driver HA work bitmap */
7750 phba->work_ha |= HA_ERATT;
7751 /* Indicate polling handles this ERATT */
7752 phba->hba_flag |= HBA_ERATT_HANDLED;
7760 * lpfc_sli_check_eratt - check error attention events
7761 * @phba: Pointer to HBA context.
7763 * This function is called from timer soft interrupt context to check HBA's
7764 * error attention register bit for error attention events.
7766 * This fucntion returns 1 when there is Error Attention in the Host Attention
7767 * Register and returns 0 otherwise.
7770 lpfc_sli_check_eratt(struct lpfc_hba *phba)
7774 /* If somebody is waiting to handle an eratt, don't process it
7775 * here. The brdkill function will do this.
7777 if (phba->link_flag & LS_IGNORE_ERATT)
7780 /* Check if interrupt handler handles this ERATT */
7781 spin_lock_irq(&phba->hbalock);
7782 if (phba->hba_flag & HBA_ERATT_HANDLED) {
7783 /* Interrupt handler has handled ERATT */
7784 spin_unlock_irq(&phba->hbalock);
7789 * If there is deferred error attention, do not check for error
7792 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7793 spin_unlock_irq(&phba->hbalock);
7797 /* If PCI channel is offline, don't process it */
7798 if (unlikely(pci_channel_offline(phba->pcidev))) {
7799 spin_unlock_irq(&phba->hbalock);
7803 switch (phba->sli_rev) {
7806 /* Read chip Host Attention (HA) register */
7807 ha_copy = lpfc_sli_eratt_read(phba);
7810 /* Read devcie Uncoverable Error (UERR) registers */
7811 ha_copy = lpfc_sli4_eratt_read(phba);
7814 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7815 "0299 Invalid SLI revision (%d)\n",
7820 spin_unlock_irq(&phba->hbalock);
7826 * lpfc_intr_state_check - Check device state for interrupt handling
7827 * @phba: Pointer to HBA context.
7829 * This inline routine checks whether a device or its PCI slot is in a state
7830 * that the interrupt should be handled.
7832 * This function returns 0 if the device or the PCI slot is in a state that
7833 * interrupt should be handled, otherwise -EIO.
7836 lpfc_intr_state_check(struct lpfc_hba *phba)
7838 /* If the pci channel is offline, ignore all the interrupts */
7839 if (unlikely(pci_channel_offline(phba->pcidev)))
7842 /* Update device level interrupt statistics */
7843 phba->sli.slistat.sli_intr++;
7845 /* Ignore all interrupts during initialization. */
7846 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
7853 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
7854 * @irq: Interrupt number.
7855 * @dev_id: The device context pointer.
7857 * This function is directly called from the PCI layer as an interrupt
7858 * service routine when device with SLI-3 interface spec is enabled with
7859 * MSI-X multi-message interrupt mode and there are slow-path events in
7860 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
7861 * interrupt mode, this function is called as part of the device-level
7862 * interrupt handler. When the PCI slot is in error recovery or the HBA
7863 * is undergoing initialization, the interrupt handler will not process
7864 * the interrupt. The link attention and ELS ring attention events are
7865 * handled by the worker thread. The interrupt handler signals the worker
7866 * thread and returns for these events. This function is called without
7867 * any lock held. It gets the hbalock to access and update SLI data
7870 * This function returns IRQ_HANDLED when interrupt is handled else it
7874 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
7876 struct lpfc_hba *phba;
7878 uint32_t work_ha_copy;
7879 unsigned long status;
7880 unsigned long iflag;
7883 MAILBOX_t *mbox, *pmbox;
7884 struct lpfc_vport *vport;
7885 struct lpfc_nodelist *ndlp;
7886 struct lpfc_dmabuf *mp;
7891 * Get the driver's phba structure from the dev_id and
7892 * assume the HBA is not interrupting.
7894 phba = (struct lpfc_hba *)dev_id;
7896 if (unlikely(!phba))
7900 * Stuff needs to be attented to when this function is invoked as an
7901 * individual interrupt handler in MSI-X multi-message interrupt mode
7903 if (phba->intr_type == MSIX) {
7904 /* Check device state for handling interrupt */
7905 if (lpfc_intr_state_check(phba))
7907 /* Need to read HA REG for slow-path events */
7908 spin_lock_irqsave(&phba->hbalock, iflag);
7909 ha_copy = readl(phba->HAregaddr);
7910 /* If somebody is waiting to handle an eratt don't process it
7911 * here. The brdkill function will do this.
7913 if (phba->link_flag & LS_IGNORE_ERATT)
7914 ha_copy &= ~HA_ERATT;
7915 /* Check the need for handling ERATT in interrupt handler */
7916 if (ha_copy & HA_ERATT) {
7917 if (phba->hba_flag & HBA_ERATT_HANDLED)
7918 /* ERATT polling has handled ERATT */
7919 ha_copy &= ~HA_ERATT;
7921 /* Indicate interrupt handler handles ERATT */
7922 phba->hba_flag |= HBA_ERATT_HANDLED;
7926 * If there is deferred error attention, do not check for any
7929 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7930 spin_unlock_irqrestore(&phba->hbalock, iflag);
7934 /* Clear up only attention source related to slow-path */
7935 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
7937 readl(phba->HAregaddr); /* flush */
7938 spin_unlock_irqrestore(&phba->hbalock, iflag);
7940 ha_copy = phba->ha_copy;
7942 work_ha_copy = ha_copy & phba->work_ha_mask;
7945 if (work_ha_copy & HA_LATT) {
7946 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
7948 * Turn off Link Attention interrupts
7949 * until CLEAR_LA done
7951 spin_lock_irqsave(&phba->hbalock, iflag);
7952 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
7953 control = readl(phba->HCregaddr);
7954 control &= ~HC_LAINT_ENA;
7955 writel(control, phba->HCregaddr);
7956 readl(phba->HCregaddr); /* flush */
7957 spin_unlock_irqrestore(&phba->hbalock, iflag);
7960 work_ha_copy &= ~HA_LATT;
7963 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
7965 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
7966 * the only slow ring.
7968 status = (work_ha_copy &
7969 (HA_RXMASK << (4*LPFC_ELS_RING)));
7970 status >>= (4*LPFC_ELS_RING);
7971 if (status & HA_RXMASK) {
7972 spin_lock_irqsave(&phba->hbalock, iflag);
7973 control = readl(phba->HCregaddr);
7975 lpfc_debugfs_slow_ring_trc(phba,
7976 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
7978 (uint32_t)phba->sli.slistat.sli_intr);
7980 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
7981 lpfc_debugfs_slow_ring_trc(phba,
7983 "pwork:x%x hawork:x%x wait:x%x",
7984 phba->work_ha, work_ha_copy,
7985 (uint32_t)((unsigned long)
7986 &phba->work_waitq));
7989 ~(HC_R0INT_ENA << LPFC_ELS_RING);
7990 writel(control, phba->HCregaddr);
7991 readl(phba->HCregaddr); /* flush */
7994 lpfc_debugfs_slow_ring_trc(phba,
7995 "ISR slow ring: pwork:"
7996 "x%x hawork:x%x wait:x%x",
7997 phba->work_ha, work_ha_copy,
7998 (uint32_t)((unsigned long)
7999 &phba->work_waitq));
8001 spin_unlock_irqrestore(&phba->hbalock, iflag);
8004 spin_lock_irqsave(&phba->hbalock, iflag);
8005 if (work_ha_copy & HA_ERATT) {
8006 lpfc_sli_read_hs(phba);
8008 * Check if there is a deferred error condition
8011 if ((HS_FFER1 & phba->work_hs) &&
8012 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
8013 HS_FFER6 | HS_FFER7) & phba->work_hs)) {
8014 phba->hba_flag |= DEFER_ERATT;
8015 /* Clear all interrupt enable conditions */
8016 writel(0, phba->HCregaddr);
8017 readl(phba->HCregaddr);
8021 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
8022 pmb = phba->sli.mbox_active;
8027 /* First check out the status word */
8028 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
8029 if (pmbox->mbxOwner != OWN_HOST) {
8030 spin_unlock_irqrestore(&phba->hbalock, iflag);
8032 * Stray Mailbox Interrupt, mbxCommand <cmd>
8033 * mbxStatus <status>
8035 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
8037 "(%d):0304 Stray Mailbox "
8038 "Interrupt mbxCommand x%x "
8040 (vport ? vport->vpi : 0),
8043 /* clear mailbox attention bit */
8044 work_ha_copy &= ~HA_MBATT;
8046 phba->sli.mbox_active = NULL;
8047 spin_unlock_irqrestore(&phba->hbalock, iflag);
8048 phba->last_completion_time = jiffies;
8049 del_timer(&phba->sli.mbox_tmo);
8050 if (pmb->mbox_cmpl) {
8051 lpfc_sli_pcimem_bcopy(mbox, pmbox,
8054 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
8055 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
8057 lpfc_debugfs_disc_trc(vport,
8058 LPFC_DISC_TRC_MBOX_VPORT,
8060 "status:x%x rpi:x%x",
8061 (uint32_t)pmbox->mbxStatus,
8062 pmbox->un.varWords[0], 0);
8064 if (!pmbox->mbxStatus) {
8065 mp = (struct lpfc_dmabuf *)
8067 ndlp = (struct lpfc_nodelist *)
8070 /* Reg_LOGIN of dflt RPI was
8071 * successful. new lets get
8072 * rid of the RPI using the
8075 lpfc_unreg_login(phba,
8077 pmbox->un.varWords[0],
8080 lpfc_mbx_cmpl_dflt_rpi;
8082 pmb->context2 = ndlp;
8084 rc = lpfc_sli_issue_mbox(phba,
8088 lpfc_printf_log(phba,
8091 "0350 rc should have"
8093 if (rc != MBX_NOT_FINISHED)
8094 goto send_current_mbox;
8098 &phba->pport->work_port_lock,
8100 phba->pport->work_port_events &=
8102 spin_unlock_irqrestore(
8103 &phba->pport->work_port_lock,
8105 lpfc_mbox_cmpl_put(phba, pmb);
8108 spin_unlock_irqrestore(&phba->hbalock, iflag);
8110 if ((work_ha_copy & HA_MBATT) &&
8111 (phba->sli.mbox_active == NULL)) {
8113 /* Process next mailbox command if there is one */
8115 rc = lpfc_sli_issue_mbox(phba, NULL,
8117 } while (rc == MBX_NOT_FINISHED);
8118 if (rc != MBX_SUCCESS)
8119 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
8120 LOG_SLI, "0349 rc should be "
8124 spin_lock_irqsave(&phba->hbalock, iflag);
8125 phba->work_ha |= work_ha_copy;
8126 spin_unlock_irqrestore(&phba->hbalock, iflag);
8127 lpfc_worker_wake_up(phba);
8131 } /* lpfc_sli_sp_intr_handler */
8134 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
8135 * @irq: Interrupt number.
8136 * @dev_id: The device context pointer.
8138 * This function is directly called from the PCI layer as an interrupt
8139 * service routine when device with SLI-3 interface spec is enabled with
8140 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8141 * ring event in the HBA. However, when the device is enabled with either
8142 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8143 * device-level interrupt handler. When the PCI slot is in error recovery
8144 * or the HBA is undergoing initialization, the interrupt handler will not
8145 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8146 * the intrrupt context. This function is called without any lock held.
8147 * It gets the hbalock to access and update SLI data structures.
8149 * This function returns IRQ_HANDLED when interrupt is handled else it
8153 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
8155 struct lpfc_hba *phba;
8157 unsigned long status;
8158 unsigned long iflag;
8160 /* Get the driver's phba structure from the dev_id and
8161 * assume the HBA is not interrupting.
8163 phba = (struct lpfc_hba *) dev_id;
8165 if (unlikely(!phba))
8169 * Stuff needs to be attented to when this function is invoked as an
8170 * individual interrupt handler in MSI-X multi-message interrupt mode
8172 if (phba->intr_type == MSIX) {
8173 /* Check device state for handling interrupt */
8174 if (lpfc_intr_state_check(phba))
8176 /* Need to read HA REG for FCP ring and other ring events */
8177 ha_copy = readl(phba->HAregaddr);
8178 /* Clear up only attention source related to fast-path */
8179 spin_lock_irqsave(&phba->hbalock, iflag);
8181 * If there is deferred error attention, do not check for
8184 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8185 spin_unlock_irqrestore(&phba->hbalock, iflag);
8188 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
8190 readl(phba->HAregaddr); /* flush */
8191 spin_unlock_irqrestore(&phba->hbalock, iflag);
8193 ha_copy = phba->ha_copy;
8196 * Process all events on FCP ring. Take the optimized path for FCP IO.
8198 ha_copy &= ~(phba->work_ha_mask);
8200 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
8201 status >>= (4*LPFC_FCP_RING);
8202 if (status & HA_RXMASK)
8203 lpfc_sli_handle_fast_ring_event(phba,
8204 &phba->sli.ring[LPFC_FCP_RING],
8207 if (phba->cfg_multi_ring_support == 2) {
8209 * Process all events on extra ring. Take the optimized path
8210 * for extra ring IO.
8212 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
8213 status >>= (4*LPFC_EXTRA_RING);
8214 if (status & HA_RXMASK) {
8215 lpfc_sli_handle_fast_ring_event(phba,
8216 &phba->sli.ring[LPFC_EXTRA_RING],
8221 } /* lpfc_sli_fp_intr_handler */
8224 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
8225 * @irq: Interrupt number.
8226 * @dev_id: The device context pointer.
8228 * This function is the HBA device-level interrupt handler to device with
8229 * SLI-3 interface spec, called from the PCI layer when either MSI or
8230 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
8231 * requires driver attention. This function invokes the slow-path interrupt
8232 * attention handling function and fast-path interrupt attention handling
8233 * function in turn to process the relevant HBA attention events. This
8234 * function is called without any lock held. It gets the hbalock to access
8235 * and update SLI data structures.
8237 * This function returns IRQ_HANDLED when interrupt is handled, else it
8241 lpfc_sli_intr_handler(int irq, void *dev_id)
8243 struct lpfc_hba *phba;
8244 irqreturn_t sp_irq_rc, fp_irq_rc;
8245 unsigned long status1, status2;
8248 * Get the driver's phba structure from the dev_id and
8249 * assume the HBA is not interrupting.
8251 phba = (struct lpfc_hba *) dev_id;
8253 if (unlikely(!phba))
8256 /* Check device state for handling interrupt */
8257 if (lpfc_intr_state_check(phba))
8260 spin_lock(&phba->hbalock);
8261 phba->ha_copy = readl(phba->HAregaddr);
8262 if (unlikely(!phba->ha_copy)) {
8263 spin_unlock(&phba->hbalock);
8265 } else if (phba->ha_copy & HA_ERATT) {
8266 if (phba->hba_flag & HBA_ERATT_HANDLED)
8267 /* ERATT polling has handled ERATT */
8268 phba->ha_copy &= ~HA_ERATT;
8270 /* Indicate interrupt handler handles ERATT */
8271 phba->hba_flag |= HBA_ERATT_HANDLED;
8275 * If there is deferred error attention, do not check for any interrupt.
8277 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8278 spin_unlock_irq(&phba->hbalock);
8282 /* Clear attention sources except link and error attentions */
8283 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
8284 readl(phba->HAregaddr); /* flush */
8285 spin_unlock(&phba->hbalock);
8288 * Invokes slow-path host attention interrupt handling as appropriate.
8291 /* status of events with mailbox and link attention */
8292 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
8294 /* status of events with ELS ring */
8295 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
8296 status2 >>= (4*LPFC_ELS_RING);
8298 if (status1 || (status2 & HA_RXMASK))
8299 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
8301 sp_irq_rc = IRQ_NONE;
8304 * Invoke fast-path host attention interrupt handling as appropriate.
8307 /* status of events with FCP ring */
8308 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
8309 status1 >>= (4*LPFC_FCP_RING);
8311 /* status of events with extra ring */
8312 if (phba->cfg_multi_ring_support == 2) {
8313 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
8314 status2 >>= (4*LPFC_EXTRA_RING);
8318 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
8319 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
8321 fp_irq_rc = IRQ_NONE;
8323 /* Return device-level interrupt handling status */
8324 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
8325 } /* lpfc_sli_intr_handler */
8328 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
8329 * @phba: pointer to lpfc hba data structure.
8331 * This routine is invoked by the worker thread to process all the pending
8332 * SLI4 FCP abort XRI events.
8334 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
8336 struct lpfc_cq_event *cq_event;
8338 /* First, declare the fcp xri abort event has been handled */
8339 spin_lock_irq(&phba->hbalock);
8340 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
8341 spin_unlock_irq(&phba->hbalock);
8342 /* Now, handle all the fcp xri abort events */
8343 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
8344 /* Get the first event from the head of the event queue */
8345 spin_lock_irq(&phba->hbalock);
8346 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8347 cq_event, struct lpfc_cq_event, list);
8348 spin_unlock_irq(&phba->hbalock);
8349 /* Notify aborted XRI for FCP work queue */
8350 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
8351 /* Free the event processed back to the free pool */
8352 lpfc_sli4_cq_event_release(phba, cq_event);
8357 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
8358 * @phba: pointer to lpfc hba data structure.
8360 * This routine is invoked by the worker thread to process all the pending
8361 * SLI4 els abort xri events.
8363 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
8365 struct lpfc_cq_event *cq_event;
8367 /* First, declare the els xri abort event has been handled */
8368 spin_lock_irq(&phba->hbalock);
8369 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
8370 spin_unlock_irq(&phba->hbalock);
8371 /* Now, handle all the els xri abort events */
8372 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
8373 /* Get the first event from the head of the event queue */
8374 spin_lock_irq(&phba->hbalock);
8375 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8376 cq_event, struct lpfc_cq_event, list);
8377 spin_unlock_irq(&phba->hbalock);
8378 /* Notify aborted XRI for ELS work queue */
8379 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
8380 /* Free the event processed back to the free pool */
8381 lpfc_sli4_cq_event_release(phba, cq_event);
8386 lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
8387 struct lpfc_iocbq *pIocbOut,
8388 struct lpfc_wcqe_complete *wcqe)
8390 size_t offset = offsetof(struct lpfc_iocbq, iocb);
8392 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
8393 sizeof(struct lpfc_iocbq) - offset);
8394 pIocbIn->cq_event.cqe.wcqe_cmpl = *wcqe;
8395 /* Map WCQE parameters into irspiocb parameters */
8396 pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
8397 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
8398 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
8399 pIocbIn->iocb.un.fcpi.fcpi_parm =
8400 pIocbOut->iocb.un.fcpi.fcpi_parm -
8401 wcqe->total_data_placed;
8403 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8405 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8409 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
8410 * @phba: Pointer to HBA context object.
8411 * @cqe: Pointer to mailbox completion queue entry.
8413 * This routine process a mailbox completion queue entry with asynchrous
8416 * Return: true if work posted to worker thread, otherwise false.
8419 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
8421 struct lpfc_cq_event *cq_event;
8422 unsigned long iflags;
8424 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8425 "0392 Async Event: word0:x%x, word1:x%x, "
8426 "word2:x%x, word3:x%x\n", mcqe->word0,
8427 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
8429 /* Allocate a new internal CQ_EVENT entry */
8430 cq_event = lpfc_sli4_cq_event_alloc(phba);
8432 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8433 "0394 Failed to allocate CQ_EVENT entry\n");
8437 /* Move the CQE into an asynchronous event entry */
8438 memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
8439 spin_lock_irqsave(&phba->hbalock, iflags);
8440 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
8441 /* Set the async event flag */
8442 phba->hba_flag |= ASYNC_EVENT;
8443 spin_unlock_irqrestore(&phba->hbalock, iflags);
8449 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
8450 * @phba: Pointer to HBA context object.
8451 * @cqe: Pointer to mailbox completion queue entry.
8453 * This routine process a mailbox completion queue entry with mailbox
8456 * Return: true if work posted to worker thread, otherwise false.
8459 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
8461 uint32_t mcqe_status;
8462 MAILBOX_t *mbox, *pmbox;
8463 struct lpfc_mqe *mqe;
8464 struct lpfc_vport *vport;
8465 struct lpfc_nodelist *ndlp;
8466 struct lpfc_dmabuf *mp;
8467 unsigned long iflags;
8469 bool workposted = false;
8472 /* If not a mailbox complete MCQE, out by checking mailbox consume */
8473 if (!bf_get(lpfc_trailer_completed, mcqe))
8474 goto out_no_mqe_complete;
8476 /* Get the reference to the active mbox command */
8477 spin_lock_irqsave(&phba->hbalock, iflags);
8478 pmb = phba->sli.mbox_active;
8479 if (unlikely(!pmb)) {
8480 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
8481 "1832 No pending MBOX command to handle\n");
8482 spin_unlock_irqrestore(&phba->hbalock, iflags);
8483 goto out_no_mqe_complete;
8485 spin_unlock_irqrestore(&phba->hbalock, iflags);
8487 pmbox = (MAILBOX_t *)&pmb->u.mqe;
8491 /* Reset heartbeat timer */
8492 phba->last_completion_time = jiffies;
8493 del_timer(&phba->sli.mbox_tmo);
8495 /* Move mbox data to caller's mailbox region, do endian swapping */
8496 if (pmb->mbox_cmpl && mbox)
8497 lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
8498 /* Set the mailbox status with SLI4 range 0x4000 */
8499 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
8500 if (mcqe_status != MB_CQE_STATUS_SUCCESS)
8501 bf_set(lpfc_mqe_status, mqe,
8502 (LPFC_MBX_ERROR_RANGE | mcqe_status));
8504 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
8505 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
8506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
8507 "MBOX dflt rpi: status:x%x rpi:x%x",
8509 pmbox->un.varWords[0], 0);
8510 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
8511 mp = (struct lpfc_dmabuf *)(pmb->context1);
8512 ndlp = (struct lpfc_nodelist *)pmb->context2;
8513 /* Reg_LOGIN of dflt RPI was successful. Now lets get
8514 * RID of the PPI using the same mbox buffer.
8516 lpfc_unreg_login(phba, vport->vpi,
8517 pmbox->un.varWords[0], pmb);
8518 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
8520 pmb->context2 = ndlp;
8522 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
8524 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
8525 LOG_SLI, "0385 rc should "
8526 "have been MBX_BUSY\n");
8527 if (rc != MBX_NOT_FINISHED)
8528 goto send_current_mbox;
8531 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8532 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
8533 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8535 /* There is mailbox completion work to do */
8536 spin_lock_irqsave(&phba->hbalock, iflags);
8537 __lpfc_mbox_cmpl_put(phba, pmb);
8538 phba->work_ha |= HA_MBATT;
8539 spin_unlock_irqrestore(&phba->hbalock, iflags);
8543 spin_lock_irqsave(&phba->hbalock, iflags);
8544 /* Release the mailbox command posting token */
8545 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8546 /* Setting active mailbox pointer need to be in sync to flag clear */
8547 phba->sli.mbox_active = NULL;
8548 spin_unlock_irqrestore(&phba->hbalock, iflags);
8549 /* Wake up worker thread to post the next pending mailbox command */
8550 lpfc_worker_wake_up(phba);
8551 out_no_mqe_complete:
8552 if (bf_get(lpfc_trailer_consumed, mcqe))
8553 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
8558 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
8559 * @phba: Pointer to HBA context object.
8560 * @cqe: Pointer to mailbox completion queue entry.
8562 * This routine process a mailbox completion queue entry, it invokes the
8563 * proper mailbox complete handling or asynchrous event handling routine
8564 * according to the MCQE's async bit.
8566 * Return: true if work posted to worker thread, otherwise false.
8569 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
8571 struct lpfc_mcqe mcqe;
8574 /* Copy the mailbox MCQE and convert endian order as needed */
8575 lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
8577 /* Invoke the proper event handling routine */
8578 if (!bf_get(lpfc_trailer_async, &mcqe))
8579 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
8581 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
8586 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
8587 * @phba: Pointer to HBA context object.
8588 * @wcqe: Pointer to work-queue completion queue entry.
8590 * This routine handles an ELS work-queue completion event.
8592 * Return: true if work posted to worker thread, otherwise false.
8595 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
8596 struct lpfc_wcqe_complete *wcqe)
8598 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8599 struct lpfc_iocbq *cmdiocbq;
8600 struct lpfc_iocbq *irspiocbq;
8601 unsigned long iflags;
8602 bool workposted = false;
8604 spin_lock_irqsave(&phba->hbalock, iflags);
8605 pring->stats.iocb_event++;
8606 /* Look up the ELS command IOCB and create pseudo response IOCB */
8607 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
8608 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8609 spin_unlock_irqrestore(&phba->hbalock, iflags);
8611 if (unlikely(!cmdiocbq)) {
8612 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8613 "0386 ELS complete with no corresponding "
8614 "cmdiocb: iotag (%d)\n",
8615 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8619 /* Fake the irspiocbq and copy necessary response information */
8620 irspiocbq = lpfc_sli_get_iocbq(phba);
8622 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8623 "0387 Failed to allocate an iocbq\n");
8626 lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
8628 /* Add the irspiocb to the response IOCB work list */
8629 spin_lock_irqsave(&phba->hbalock, iflags);
8630 list_add_tail(&irspiocbq->cq_event.list,
8631 &phba->sli4_hba.sp_rspiocb_work_queue);
8632 /* Indicate ELS ring attention */
8633 phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
8634 spin_unlock_irqrestore(&phba->hbalock, iflags);
8641 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
8642 * @phba: Pointer to HBA context object.
8643 * @wcqe: Pointer to work-queue completion queue entry.
8645 * This routine handles slow-path WQ entry comsumed event by invoking the
8646 * proper WQ release routine to the slow-path WQ.
8649 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
8650 struct lpfc_wcqe_release *wcqe)
8652 /* Check for the slow-path ELS work queue */
8653 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
8654 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
8655 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
8657 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8658 "2579 Slow-path wqe consume event carries "
8659 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
8660 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
8661 phba->sli4_hba.els_wq->queue_id);
8665 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
8666 * @phba: Pointer to HBA context object.
8667 * @cq: Pointer to a WQ completion queue.
8668 * @wcqe: Pointer to work-queue completion queue entry.
8670 * This routine handles an XRI abort event.
8672 * Return: true if work posted to worker thread, otherwise false.
8675 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
8676 struct lpfc_queue *cq,
8677 struct sli4_wcqe_xri_aborted *wcqe)
8679 bool workposted = false;
8680 struct lpfc_cq_event *cq_event;
8681 unsigned long iflags;
8683 /* Allocate a new internal CQ_EVENT entry */
8684 cq_event = lpfc_sli4_cq_event_alloc(phba);
8686 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8687 "0602 Failed to allocate CQ_EVENT entry\n");
8691 /* Move the CQE into the proper xri abort event list */
8692 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
8693 switch (cq->subtype) {
8695 spin_lock_irqsave(&phba->hbalock, iflags);
8696 list_add_tail(&cq_event->list,
8697 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
8698 /* Set the fcp xri abort event flag */
8699 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
8700 spin_unlock_irqrestore(&phba->hbalock, iflags);
8704 spin_lock_irqsave(&phba->hbalock, iflags);
8705 list_add_tail(&cq_event->list,
8706 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
8707 /* Set the els xri abort event flag */
8708 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
8709 spin_unlock_irqrestore(&phba->hbalock, iflags);
8713 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8714 "0603 Invalid work queue CQE subtype (x%x)\n",
8723 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
8724 * @phba: Pointer to HBA context object.
8725 * @rcqe: Pointer to receive-queue completion queue entry.
8727 * This routine process a receive-queue completion queue entry.
8729 * Return: true if work posted to worker thread, otherwise false.
8732 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
8734 bool workposted = false;
8735 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
8736 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
8737 struct hbq_dmabuf *dma_buf;
8739 unsigned long iflags;
8741 lpfc_sli4_rq_release(hrq, drq);
8742 if (bf_get(lpfc_rcqe_code, rcqe) != CQE_CODE_RECEIVE)
8744 if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
8747 status = bf_get(lpfc_rcqe_status, rcqe);
8749 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
8750 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8751 "2537 Receive Frame Truncated!!\n");
8752 case FC_STATUS_RQ_SUCCESS:
8753 spin_lock_irqsave(&phba->hbalock, iflags);
8754 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
8756 spin_unlock_irqrestore(&phba->hbalock, iflags);
8759 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
8760 /* save off the frame for the word thread to process */
8761 list_add_tail(&dma_buf->cq_event.list,
8762 &phba->sli4_hba.sp_rspiocb_work_queue);
8763 /* Frame received */
8764 phba->hba_flag |= HBA_RECEIVE_BUFFER;
8765 spin_unlock_irqrestore(&phba->hbalock, iflags);
8768 case FC_STATUS_INSUFF_BUF_NEED_BUF:
8769 case FC_STATUS_INSUFF_BUF_FRM_DISC:
8770 /* Post more buffers if possible */
8771 spin_lock_irqsave(&phba->hbalock, iflags);
8772 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
8773 spin_unlock_irqrestore(&phba->hbalock, iflags);
8783 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
8784 * @phba: Pointer to HBA context object.
8785 * @cq: Pointer to the completion queue.
8786 * @wcqe: Pointer to a completion queue entry.
8788 * This routine process a slow-path work-queue or recieve queue completion queue
8791 * Return: true if work posted to worker thread, otherwise false.
8794 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
8795 struct lpfc_cqe *cqe)
8797 struct lpfc_wcqe_complete wcqe;
8798 bool workposted = false;
8800 /* Copy the work queue CQE and convert endian order if needed */
8801 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
8803 /* Check and process for different type of WCQE and dispatch */
8804 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
8805 case CQE_CODE_COMPL_WQE:
8806 /* Process the WQ complete event */
8807 workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
8808 (struct lpfc_wcqe_complete *)&wcqe);
8810 case CQE_CODE_RELEASE_WQE:
8811 /* Process the WQ release event */
8812 lpfc_sli4_sp_handle_rel_wcqe(phba,
8813 (struct lpfc_wcqe_release *)&wcqe);
8815 case CQE_CODE_XRI_ABORTED:
8816 /* Process the WQ XRI abort event */
8817 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
8818 (struct sli4_wcqe_xri_aborted *)&wcqe);
8820 case CQE_CODE_RECEIVE:
8821 /* Process the RQ event */
8822 workposted = lpfc_sli4_sp_handle_rcqe(phba,
8823 (struct lpfc_rcqe *)&wcqe);
8826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8827 "0388 Not a valid WCQE code: x%x\n",
8828 bf_get(lpfc_wcqe_c_code, &wcqe));
8835 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
8836 * @phba: Pointer to HBA context object.
8837 * @eqe: Pointer to fast-path event queue entry.
8839 * This routine process a event queue entry from the slow-path event queue.
8840 * It will check the MajorCode and MinorCode to determine this is for a
8841 * completion event on a completion queue, if not, an error shall be logged
8842 * and just return. Otherwise, it will get to the corresponding completion
8843 * queue and process all the entries on that completion queue, rearm the
8844 * completion queue, and then return.
8848 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
8850 struct lpfc_queue *cq = NULL, *childq, *speq;
8851 struct lpfc_cqe *cqe;
8852 bool workposted = false;
8856 if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
8857 bf_get(lpfc_eqe_minor_code, eqe) != 0) {
8858 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8859 "0359 Not a valid slow-path completion "
8860 "event: majorcode=x%x, minorcode=x%x\n",
8861 bf_get(lpfc_eqe_major_code, eqe),
8862 bf_get(lpfc_eqe_minor_code, eqe));
8866 /* Get the reference to the corresponding CQ */
8867 cqid = bf_get(lpfc_eqe_resource_id, eqe);
8869 /* Search for completion queue pointer matching this cqid */
8870 speq = phba->sli4_hba.sp_eq;
8871 list_for_each_entry(childq, &speq->child_list, list) {
8872 if (childq->queue_id == cqid) {
8877 if (unlikely(!cq)) {
8878 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8879 "0365 Slow-path CQ identifier (%d) does "
8880 "not exist\n", cqid);
8884 /* Process all the entries to the CQ */
8887 while ((cqe = lpfc_sli4_cq_get(cq))) {
8888 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
8889 if (!(++ecount % LPFC_GET_QE_REL_INT))
8890 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
8894 while ((cqe = lpfc_sli4_cq_get(cq))) {
8895 workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
8896 if (!(++ecount % LPFC_GET_QE_REL_INT))
8897 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
8901 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8902 "0370 Invalid completion queue type (%d)\n",
8907 /* Catch the no cq entry condition, log an error */
8908 if (unlikely(ecount == 0))
8909 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8910 "0371 No entry from the CQ: identifier "
8911 "(x%x), type (%d)\n", cq->queue_id, cq->type);
8913 /* In any case, flash and re-arm the RCQ */
8914 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
8916 /* wake up worker thread if there are works to be done */
8918 lpfc_worker_wake_up(phba);
8922 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
8923 * @eqe: Pointer to fast-path completion queue entry.
8925 * This routine process a fast-path work queue completion entry from fast-path
8926 * event queue for FCP command response completion.
8929 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
8930 struct lpfc_wcqe_complete *wcqe)
8932 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
8933 struct lpfc_iocbq *cmdiocbq;
8934 struct lpfc_iocbq irspiocbq;
8935 unsigned long iflags;
8937 spin_lock_irqsave(&phba->hbalock, iflags);
8938 pring->stats.iocb_event++;
8939 spin_unlock_irqrestore(&phba->hbalock, iflags);
8941 /* Check for response status */
8942 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
8943 /* If resource errors reported from HBA, reduce queue
8944 * depth of the SCSI device.
8946 if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
8947 IOSTAT_LOCAL_REJECT) &&
8948 (wcqe->parameter == IOERR_NO_RESOURCES)) {
8949 phba->lpfc_rampdown_queue_depth(phba);
8951 /* Log the error status */
8952 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8953 "0373 FCP complete error: status=x%x, "
8954 "hw_status=x%x, total_data_specified=%d, "
8955 "parameter=x%x, word3=x%x\n",
8956 bf_get(lpfc_wcqe_c_status, wcqe),
8957 bf_get(lpfc_wcqe_c_hw_status, wcqe),
8958 wcqe->total_data_placed, wcqe->parameter,
8962 /* Look up the FCP command IOCB and create pseudo response IOCB */
8963 spin_lock_irqsave(&phba->hbalock, iflags);
8964 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
8965 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8966 spin_unlock_irqrestore(&phba->hbalock, iflags);
8967 if (unlikely(!cmdiocbq)) {
8968 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8969 "0374 FCP complete with no corresponding "
8970 "cmdiocb: iotag (%d)\n",
8971 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8974 if (unlikely(!cmdiocbq->iocb_cmpl)) {
8975 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8976 "0375 FCP cmdiocb not callback function "
8978 bf_get(lpfc_wcqe_c_request_tag, wcqe));
8982 /* Fake the irspiocb and copy necessary response information */
8983 lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
8985 /* Pass the cmd_iocb and the rsp state to the upper layer */
8986 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
8990 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
8991 * @phba: Pointer to HBA context object.
8992 * @cq: Pointer to completion queue.
8993 * @wcqe: Pointer to work-queue completion queue entry.
8995 * This routine handles an fast-path WQ entry comsumed event by invoking the
8996 * proper WQ release routine to the slow-path WQ.
8999 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9000 struct lpfc_wcqe_release *wcqe)
9002 struct lpfc_queue *childwq;
9003 bool wqid_matched = false;
9006 /* Check for fast-path FCP work queue release */
9007 fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
9008 list_for_each_entry(childwq, &cq->child_list, list) {
9009 if (childwq->queue_id == fcp_wqid) {
9010 lpfc_sli4_wq_release(childwq,
9011 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
9012 wqid_matched = true;
9016 /* Report warning log message if no match found */
9017 if (wqid_matched != true)
9018 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9019 "2580 Fast-path wqe consume event carries "
9020 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
9024 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
9025 * @cq: Pointer to the completion queue.
9026 * @eqe: Pointer to fast-path completion queue entry.
9028 * This routine process a fast-path work queue completion entry from fast-path
9029 * event queue for FCP command response completion.
9032 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9033 struct lpfc_cqe *cqe)
9035 struct lpfc_wcqe_release wcqe;
9036 bool workposted = false;
9038 /* Copy the work queue CQE and convert endian order if needed */
9039 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
9041 /* Check and process for different type of WCQE and dispatch */
9042 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
9043 case CQE_CODE_COMPL_WQE:
9044 /* Process the WQ complete event */
9045 lpfc_sli4_fp_handle_fcp_wcqe(phba,
9046 (struct lpfc_wcqe_complete *)&wcqe);
9048 case CQE_CODE_RELEASE_WQE:
9049 /* Process the WQ release event */
9050 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
9051 (struct lpfc_wcqe_release *)&wcqe);
9053 case CQE_CODE_XRI_ABORTED:
9054 /* Process the WQ XRI abort event */
9055 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
9056 (struct sli4_wcqe_xri_aborted *)&wcqe);
9059 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9060 "0144 Not a valid WCQE code: x%x\n",
9061 bf_get(lpfc_wcqe_c_code, &wcqe));
9068 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
9069 * @phba: Pointer to HBA context object.
9070 * @eqe: Pointer to fast-path event queue entry.
9072 * This routine process a event queue entry from the fast-path event queue.
9073 * It will check the MajorCode and MinorCode to determine this is for a
9074 * completion event on a completion queue, if not, an error shall be logged
9075 * and just return. Otherwise, it will get to the corresponding completion
9076 * queue and process all the entries on the completion queue, rearm the
9077 * completion queue, and then return.
9080 lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
9083 struct lpfc_queue *cq;
9084 struct lpfc_cqe *cqe;
9085 bool workposted = false;
9089 if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
9090 unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
9091 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9092 "0366 Not a valid fast-path completion "
9093 "event: majorcode=x%x, minorcode=x%x\n",
9094 bf_get(lpfc_eqe_major_code, eqe),
9095 bf_get(lpfc_eqe_minor_code, eqe));
9099 cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
9100 if (unlikely(!cq)) {
9101 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9102 "0367 Fast-path completion queue does not "
9107 /* Get the reference to the corresponding CQ */
9108 cqid = bf_get(lpfc_eqe_resource_id, eqe);
9109 if (unlikely(cqid != cq->queue_id)) {
9110 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9111 "0368 Miss-matched fast-path completion "
9112 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
9113 cqid, cq->queue_id);
9117 /* Process all the entries to the CQ */
9118 while ((cqe = lpfc_sli4_cq_get(cq))) {
9119 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
9120 if (!(++ecount % LPFC_GET_QE_REL_INT))
9121 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
9124 /* Catch the no cq entry condition */
9125 if (unlikely(ecount == 0))
9126 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9127 "0369 No entry from fast-path completion "
9128 "queue fcpcqid=%d\n", cq->queue_id);
9130 /* In any case, flash and re-arm the CQ */
9131 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
9133 /* wake up worker thread if there are works to be done */
9135 lpfc_worker_wake_up(phba);
9139 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
9141 struct lpfc_eqe *eqe;
9143 /* walk all the EQ entries and drop on the floor */
9144 while ((eqe = lpfc_sli4_eq_get(eq)))
9147 /* Clear and re-arm the EQ */
9148 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
9152 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
9153 * @irq: Interrupt number.
9154 * @dev_id: The device context pointer.
9156 * This function is directly called from the PCI layer as an interrupt
9157 * service routine when device with SLI-4 interface spec is enabled with
9158 * MSI-X multi-message interrupt mode and there are slow-path events in
9159 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9160 * interrupt mode, this function is called as part of the device-level
9161 * interrupt handler. When the PCI slot is in error recovery or the HBA is
9162 * undergoing initialization, the interrupt handler will not process the
9163 * interrupt. The link attention and ELS ring attention events are handled
9164 * by the worker thread. The interrupt handler signals the worker thread
9165 * and returns for these events. This function is called without any lock
9166 * held. It gets the hbalock to access and update SLI data structures.
9168 * This function returns IRQ_HANDLED when interrupt is handled else it
9172 lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
9174 struct lpfc_hba *phba;
9175 struct lpfc_queue *speq;
9176 struct lpfc_eqe *eqe;
9177 unsigned long iflag;
9181 * Get the driver's phba structure from the dev_id
9183 phba = (struct lpfc_hba *)dev_id;
9185 if (unlikely(!phba))
9188 /* Get to the EQ struct associated with this vector */
9189 speq = phba->sli4_hba.sp_eq;
9191 /* Check device state for handling interrupt */
9192 if (unlikely(lpfc_intr_state_check(phba))) {
9193 /* Check again for link_state with lock held */
9194 spin_lock_irqsave(&phba->hbalock, iflag);
9195 if (phba->link_state < LPFC_LINK_DOWN)
9196 /* Flush, clear interrupt, and rearm the EQ */
9197 lpfc_sli4_eq_flush(phba, speq);
9198 spin_unlock_irqrestore(&phba->hbalock, iflag);
9203 * Process all the event on FCP slow-path EQ
9205 while ((eqe = lpfc_sli4_eq_get(speq))) {
9206 lpfc_sli4_sp_handle_eqe(phba, eqe);
9207 if (!(++ecount % LPFC_GET_QE_REL_INT))
9208 lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
9211 /* Always clear and re-arm the slow-path EQ */
9212 lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
9214 /* Catch the no cq entry condition */
9215 if (unlikely(ecount == 0)) {
9216 if (phba->intr_type == MSIX)
9217 /* MSI-X treated interrupt served as no EQ share INT */
9218 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9219 "0357 MSI-X interrupt with no EQE\n");
9221 /* Non MSI-X treated on interrupt as EQ share INT */
9226 } /* lpfc_sli4_sp_intr_handler */
9229 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
9230 * @irq: Interrupt number.
9231 * @dev_id: The device context pointer.
9233 * This function is directly called from the PCI layer as an interrupt
9234 * service routine when device with SLI-4 interface spec is enabled with
9235 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
9236 * ring event in the HBA. However, when the device is enabled with either
9237 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
9238 * device-level interrupt handler. When the PCI slot is in error recovery
9239 * or the HBA is undergoing initialization, the interrupt handler will not
9240 * process the interrupt. The SCSI FCP fast-path ring event are handled in
9241 * the intrrupt context. This function is called without any lock held.
9242 * It gets the hbalock to access and update SLI data structures. Note that,
9243 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
9244 * equal to that of FCP CQ index.
9246 * This function returns IRQ_HANDLED when interrupt is handled else it
9250 lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
9252 struct lpfc_hba *phba;
9253 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
9254 struct lpfc_queue *fpeq;
9255 struct lpfc_eqe *eqe;
9256 unsigned long iflag;
9260 /* Get the driver's phba structure from the dev_id */
9261 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
9262 phba = fcp_eq_hdl->phba;
9263 fcp_eqidx = fcp_eq_hdl->idx;
9265 if (unlikely(!phba))
9268 /* Get to the EQ struct associated with this vector */
9269 fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
9271 /* Check device state for handling interrupt */
9272 if (unlikely(lpfc_intr_state_check(phba))) {
9273 /* Check again for link_state with lock held */
9274 spin_lock_irqsave(&phba->hbalock, iflag);
9275 if (phba->link_state < LPFC_LINK_DOWN)
9276 /* Flush, clear interrupt, and rearm the EQ */
9277 lpfc_sli4_eq_flush(phba, fpeq);
9278 spin_unlock_irqrestore(&phba->hbalock, iflag);
9283 * Process all the event on FCP fast-path EQ
9285 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
9286 lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
9287 if (!(++ecount % LPFC_GET_QE_REL_INT))
9288 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
9291 /* Always clear and re-arm the fast-path EQ */
9292 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
9294 if (unlikely(ecount == 0)) {
9295 if (phba->intr_type == MSIX)
9296 /* MSI-X treated interrupt served as no EQ share INT */
9297 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9298 "0358 MSI-X interrupt with no EQE\n");
9300 /* Non MSI-X treated on interrupt as EQ share INT */
9305 } /* lpfc_sli4_fp_intr_handler */
9308 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
9309 * @irq: Interrupt number.
9310 * @dev_id: The device context pointer.
9312 * This function is the device-level interrupt handler to device with SLI-4
9313 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
9314 * interrupt mode is enabled and there is an event in the HBA which requires
9315 * driver attention. This function invokes the slow-path interrupt attention
9316 * handling function and fast-path interrupt attention handling function in
9317 * turn to process the relevant HBA attention events. This function is called
9318 * without any lock held. It gets the hbalock to access and update SLI data
9321 * This function returns IRQ_HANDLED when interrupt is handled, else it
9325 lpfc_sli4_intr_handler(int irq, void *dev_id)
9327 struct lpfc_hba *phba;
9328 irqreturn_t sp_irq_rc, fp_irq_rc;
9329 bool fp_handled = false;
9332 /* Get the driver's phba structure from the dev_id */
9333 phba = (struct lpfc_hba *)dev_id;
9335 if (unlikely(!phba))
9339 * Invokes slow-path host attention interrupt handling as appropriate.
9341 sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
9344 * Invoke fast-path host attention interrupt handling as appropriate.
9346 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
9347 fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
9348 &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
9349 if (fp_irq_rc == IRQ_HANDLED)
9353 return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
9354 } /* lpfc_sli4_intr_handler */
9357 * lpfc_sli4_queue_free - free a queue structure and associated memory
9358 * @queue: The queue structure to free.
9360 * This function frees a queue structure and the DMAable memeory used for
9361 * the host resident queue. This function must be called after destroying the
9365 lpfc_sli4_queue_free(struct lpfc_queue *queue)
9367 struct lpfc_dmabuf *dmabuf;
9372 while (!list_empty(&queue->page_list)) {
9373 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
9375 dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
9376 dmabuf->virt, dmabuf->phys);
9384 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
9385 * @phba: The HBA that this queue is being created on.
9386 * @entry_size: The size of each queue entry for this queue.
9387 * @entry count: The number of entries that this queue will handle.
9389 * This function allocates a queue structure and the DMAable memory used for
9390 * the host resident queue. This function must be called before creating the
9394 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
9395 uint32_t entry_count)
9397 struct lpfc_queue *queue;
9398 struct lpfc_dmabuf *dmabuf;
9399 int x, total_qe_count;
9403 queue = kzalloc(sizeof(struct lpfc_queue) +
9404 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
9407 queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
9408 INIT_LIST_HEAD(&queue->list);
9409 INIT_LIST_HEAD(&queue->page_list);
9410 INIT_LIST_HEAD(&queue->child_list);
9411 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
9412 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9415 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9416 PAGE_SIZE, &dmabuf->phys,
9418 if (!dmabuf->virt) {
9422 memset(dmabuf->virt, 0, PAGE_SIZE);
9423 dmabuf->buffer_tag = x;
9424 list_add_tail(&dmabuf->list, &queue->page_list);
9425 /* initialize queue's entry array */
9426 dma_pointer = dmabuf->virt;
9427 for (; total_qe_count < entry_count &&
9428 dma_pointer < (PAGE_SIZE + dmabuf->virt);
9429 total_qe_count++, dma_pointer += entry_size) {
9430 queue->qe[total_qe_count].address = dma_pointer;
9433 queue->entry_size = entry_size;
9434 queue->entry_count = entry_count;
9439 lpfc_sli4_queue_free(queue);
9444 * lpfc_eq_create - Create an Event Queue on the HBA
9445 * @phba: HBA structure that indicates port to create a queue on.
9446 * @eq: The queue structure to use to create the event queue.
9447 * @imax: The maximum interrupt per second limit.
9449 * This function creates an event queue, as detailed in @eq, on a port,
9450 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
9452 * The @phba struct is used to send mailbox command to HBA. The @eq struct
9453 * is used to get the entry count and entry size that are necessary to
9454 * determine the number of pages to allocate and use for this queue. This
9455 * function will send the EQ_CREATE mailbox command to the HBA to setup the
9456 * event queue. This function is asynchronous and will wait for the mailbox
9457 * command to finish before continuing.
9459 * On success this function will return a zero. If unable to allocate enough
9460 * memory this function will return ENOMEM. If the queue create mailbox command
9461 * fails this function will return ENXIO.
9464 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
9466 struct lpfc_mbx_eq_create *eq_create;
9468 int rc, length, status = 0;
9469 struct lpfc_dmabuf *dmabuf;
9470 uint32_t shdr_status, shdr_add_status;
9471 union lpfc_sli4_cfg_shdr *shdr;
9474 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9477 length = (sizeof(struct lpfc_mbx_eq_create) -
9478 sizeof(struct lpfc_sli4_cfg_mhdr));
9479 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9480 LPFC_MBOX_OPCODE_EQ_CREATE,
9481 length, LPFC_SLI4_MBX_EMBED);
9482 eq_create = &mbox->u.mqe.un.eq_create;
9483 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
9485 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
9487 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
9488 /* Calculate delay multiper from maximum interrupt per second */
9489 dmult = LPFC_DMULT_CONST/imax - 1;
9490 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
9492 switch (eq->entry_count) {
9494 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9495 "0360 Unsupported EQ count. (%d)\n",
9497 if (eq->entry_count < 256)
9499 /* otherwise default to smallest count (drop through) */
9501 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9505 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9509 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9513 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9517 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
9521 list_for_each_entry(dmabuf, &eq->page_list, list) {
9522 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9523 putPaddrLow(dmabuf->phys);
9524 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9525 putPaddrHigh(dmabuf->phys);
9527 mbox->vport = phba->pport;
9528 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9529 mbox->context1 = NULL;
9530 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9531 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
9532 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9533 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9534 if (shdr_status || shdr_add_status || rc) {
9535 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9536 "2500 EQ_CREATE mailbox failed with "
9537 "status x%x add_status x%x, mbx status x%x\n",
9538 shdr_status, shdr_add_status, rc);
9542 eq->subtype = LPFC_NONE;
9543 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
9544 if (eq->queue_id == 0xFFFF)
9549 mempool_free(mbox, phba->mbox_mem_pool);
9554 * lpfc_cq_create - Create a Completion Queue on the HBA
9555 * @phba: HBA structure that indicates port to create a queue on.
9556 * @cq: The queue structure to use to create the completion queue.
9557 * @eq: The event queue to bind this completion queue to.
9559 * This function creates a completion queue, as detailed in @wq, on a port,
9560 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
9562 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9563 * is used to get the entry count and entry size that are necessary to
9564 * determine the number of pages to allocate and use for this queue. The @eq
9565 * is used to indicate which event queue to bind this completion queue to. This
9566 * function will send the CQ_CREATE mailbox command to the HBA to setup the
9567 * completion queue. This function is asynchronous and will wait for the mailbox
9568 * command to finish before continuing.
9570 * On success this function will return a zero. If unable to allocate enough
9571 * memory this function will return ENOMEM. If the queue create mailbox command
9572 * fails this function will return ENXIO.
9575 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
9576 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
9578 struct lpfc_mbx_cq_create *cq_create;
9579 struct lpfc_dmabuf *dmabuf;
9581 int rc, length, status = 0;
9582 uint32_t shdr_status, shdr_add_status;
9583 union lpfc_sli4_cfg_shdr *shdr;
9585 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9588 length = (sizeof(struct lpfc_mbx_cq_create) -
9589 sizeof(struct lpfc_sli4_cfg_mhdr));
9590 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9591 LPFC_MBOX_OPCODE_CQ_CREATE,
9592 length, LPFC_SLI4_MBX_EMBED);
9593 cq_create = &mbox->u.mqe.un.cq_create;
9594 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
9596 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
9597 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
9598 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
9599 switch (cq->entry_count) {
9601 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9602 "0361 Unsupported CQ count. (%d)\n",
9604 if (cq->entry_count < 256)
9606 /* otherwise default to smallest count (drop through) */
9608 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9612 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9616 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
9620 list_for_each_entry(dmabuf, &cq->page_list, list) {
9621 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9622 putPaddrLow(dmabuf->phys);
9623 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9624 putPaddrHigh(dmabuf->phys);
9626 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9628 /* The IOCTL status is embedded in the mailbox subheader. */
9629 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
9630 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9631 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9632 if (shdr_status || shdr_add_status || rc) {
9633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9634 "2501 CQ_CREATE mailbox failed with "
9635 "status x%x add_status x%x, mbx status x%x\n",
9636 shdr_status, shdr_add_status, rc);
9640 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
9641 if (cq->queue_id == 0xFFFF) {
9645 /* link the cq onto the parent eq child list */
9646 list_add_tail(&cq->list, &eq->child_list);
9647 /* Set up completion queue's type and subtype */
9649 cq->subtype = subtype;
9650 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
9655 mempool_free(mbox, phba->mbox_mem_pool);
9660 * lpfc_mq_create - Create a mailbox Queue on the HBA
9661 * @phba: HBA structure that indicates port to create a queue on.
9662 * @mq: The queue structure to use to create the mailbox queue.
9664 * This function creates a mailbox queue, as detailed in @mq, on a port,
9665 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
9667 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9668 * is used to get the entry count and entry size that are necessary to
9669 * determine the number of pages to allocate and use for this queue. This
9670 * function will send the MQ_CREATE mailbox command to the HBA to setup the
9671 * mailbox queue. This function is asynchronous and will wait for the mailbox
9672 * command to finish before continuing.
9674 * On success this function will return a zero. If unable to allocate enough
9675 * memory this function will return ENOMEM. If the queue create mailbox command
9676 * fails this function will return ENXIO.
9679 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
9680 struct lpfc_queue *cq, uint32_t subtype)
9682 struct lpfc_mbx_mq_create *mq_create;
9683 struct lpfc_dmabuf *dmabuf;
9685 int rc, length, status = 0;
9686 uint32_t shdr_status, shdr_add_status;
9687 union lpfc_sli4_cfg_shdr *shdr;
9689 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9692 length = (sizeof(struct lpfc_mbx_mq_create) -
9693 sizeof(struct lpfc_sli4_cfg_mhdr));
9694 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
9695 LPFC_MBOX_OPCODE_MQ_CREATE,
9696 length, LPFC_SLI4_MBX_EMBED);
9697 mq_create = &mbox->u.mqe.un.mq_create;
9698 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
9700 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
9702 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
9703 switch (mq->entry_count) {
9705 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9706 "0362 Unsupported MQ count. (%d)\n",
9708 if (mq->entry_count < 16)
9710 /* otherwise default to smallest count (drop through) */
9712 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9716 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9720 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9724 bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
9728 list_for_each_entry(dmabuf, &mq->page_list, list) {
9729 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9730 putPaddrLow(dmabuf->phys);
9731 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9732 putPaddrHigh(dmabuf->phys);
9734 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9735 /* The IOCTL status is embedded in the mailbox subheader. */
9736 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
9737 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9738 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9739 if (shdr_status || shdr_add_status || rc) {
9740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9741 "2502 MQ_CREATE mailbox failed with "
9742 "status x%x add_status x%x, mbx status x%x\n",
9743 shdr_status, shdr_add_status, rc);
9747 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
9748 if (mq->queue_id == 0xFFFF) {
9753 mq->subtype = subtype;
9757 /* link the mq onto the parent cq child list */
9758 list_add_tail(&mq->list, &cq->child_list);
9760 mempool_free(mbox, phba->mbox_mem_pool);
9765 * lpfc_wq_create - Create a Work Queue on the HBA
9766 * @phba: HBA structure that indicates port to create a queue on.
9767 * @wq: The queue structure to use to create the work queue.
9768 * @cq: The completion queue to bind this work queue to.
9769 * @subtype: The subtype of the work queue indicating its functionality.
9771 * This function creates a work queue, as detailed in @wq, on a port, described
9772 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
9774 * The @phba struct is used to send mailbox command to HBA. The @wq struct
9775 * is used to get the entry count and entry size that are necessary to
9776 * determine the number of pages to allocate and use for this queue. The @cq
9777 * is used to indicate which completion queue to bind this work queue to. This
9778 * function will send the WQ_CREATE mailbox command to the HBA to setup the
9779 * work queue. This function is asynchronous and will wait for the mailbox
9780 * command to finish before continuing.
9782 * On success this function will return a zero. If unable to allocate enough
9783 * memory this function will return ENOMEM. If the queue create mailbox command
9784 * fails this function will return ENXIO.
9787 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
9788 struct lpfc_queue *cq, uint32_t subtype)
9790 struct lpfc_mbx_wq_create *wq_create;
9791 struct lpfc_dmabuf *dmabuf;
9793 int rc, length, status = 0;
9794 uint32_t shdr_status, shdr_add_status;
9795 union lpfc_sli4_cfg_shdr *shdr;
9797 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9800 length = (sizeof(struct lpfc_mbx_wq_create) -
9801 sizeof(struct lpfc_sli4_cfg_mhdr));
9802 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9803 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
9804 length, LPFC_SLI4_MBX_EMBED);
9805 wq_create = &mbox->u.mqe.un.wq_create;
9806 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
9808 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
9810 list_for_each_entry(dmabuf, &wq->page_list, list) {
9811 wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9812 putPaddrLow(dmabuf->phys);
9813 wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9814 putPaddrHigh(dmabuf->phys);
9816 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9817 /* The IOCTL status is embedded in the mailbox subheader. */
9818 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
9819 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9820 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9821 if (shdr_status || shdr_add_status || rc) {
9822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9823 "2503 WQ_CREATE mailbox failed with "
9824 "status x%x add_status x%x, mbx status x%x\n",
9825 shdr_status, shdr_add_status, rc);
9829 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
9830 if (wq->queue_id == 0xFFFF) {
9835 wq->subtype = subtype;
9839 /* link the wq onto the parent cq child list */
9840 list_add_tail(&wq->list, &cq->child_list);
9842 mempool_free(mbox, phba->mbox_mem_pool);
9847 * lpfc_rq_create - Create a Receive Queue on the HBA
9848 * @phba: HBA structure that indicates port to create a queue on.
9849 * @hrq: The queue structure to use to create the header receive queue.
9850 * @drq: The queue structure to use to create the data receive queue.
9851 * @cq: The completion queue to bind this work queue to.
9853 * This function creates a receive buffer queue pair , as detailed in @hrq and
9854 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
9857 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
9858 * struct is used to get the entry count that is necessary to determine the
9859 * number of pages to use for this queue. The @cq is used to indicate which
9860 * completion queue to bind received buffers that are posted to these queues to.
9861 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
9862 * receive queue pair. This function is asynchronous and will wait for the
9863 * mailbox command to finish before continuing.
9865 * On success this function will return a zero. If unable to allocate enough
9866 * memory this function will return ENOMEM. If the queue create mailbox command
9867 * fails this function will return ENXIO.
9870 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
9871 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
9873 struct lpfc_mbx_rq_create *rq_create;
9874 struct lpfc_dmabuf *dmabuf;
9876 int rc, length, status = 0;
9877 uint32_t shdr_status, shdr_add_status;
9878 union lpfc_sli4_cfg_shdr *shdr;
9880 if (hrq->entry_count != drq->entry_count)
9882 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9885 length = (sizeof(struct lpfc_mbx_rq_create) -
9886 sizeof(struct lpfc_sli4_cfg_mhdr));
9887 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9888 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
9889 length, LPFC_SLI4_MBX_EMBED);
9890 rq_create = &mbox->u.mqe.un.rq_create;
9891 switch (hrq->entry_count) {
9893 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9894 "2535 Unsupported RQ count. (%d)\n",
9896 if (hrq->entry_count < 512)
9898 /* otherwise default to smallest count (drop through) */
9900 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9901 LPFC_RQ_RING_SIZE_512);
9904 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9905 LPFC_RQ_RING_SIZE_1024);
9908 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9909 LPFC_RQ_RING_SIZE_2048);
9912 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9913 LPFC_RQ_RING_SIZE_4096);
9916 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
9918 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
9920 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
9922 list_for_each_entry(dmabuf, &hrq->page_list, list) {
9923 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9924 putPaddrLow(dmabuf->phys);
9925 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9926 putPaddrHigh(dmabuf->phys);
9928 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9929 /* The IOCTL status is embedded in the mailbox subheader. */
9930 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
9931 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9932 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9933 if (shdr_status || shdr_add_status || rc) {
9934 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9935 "2504 RQ_CREATE mailbox failed with "
9936 "status x%x add_status x%x, mbx status x%x\n",
9937 shdr_status, shdr_add_status, rc);
9941 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
9942 if (hrq->queue_id == 0xFFFF) {
9946 hrq->type = LPFC_HRQ;
9947 hrq->subtype = subtype;
9948 hrq->host_index = 0;
9951 /* now create the data queue */
9952 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
9953 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
9954 length, LPFC_SLI4_MBX_EMBED);
9955 switch (drq->entry_count) {
9957 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9958 "2536 Unsupported RQ count. (%d)\n",
9960 if (drq->entry_count < 512)
9962 /* otherwise default to smallest count (drop through) */
9964 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9965 LPFC_RQ_RING_SIZE_512);
9968 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9969 LPFC_RQ_RING_SIZE_1024);
9972 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9973 LPFC_RQ_RING_SIZE_2048);
9976 bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
9977 LPFC_RQ_RING_SIZE_4096);
9980 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
9982 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
9984 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
9985 LPFC_DATA_BUF_SIZE);
9986 list_for_each_entry(dmabuf, &drq->page_list, list) {
9987 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
9988 putPaddrLow(dmabuf->phys);
9989 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
9990 putPaddrHigh(dmabuf->phys);
9992 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
9993 /* The IOCTL status is embedded in the mailbox subheader. */
9994 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
9995 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9996 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9997 if (shdr_status || shdr_add_status || rc) {
10001 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
10002 if (drq->queue_id == 0xFFFF) {
10006 drq->type = LPFC_DRQ;
10007 drq->subtype = subtype;
10008 drq->host_index = 0;
10009 drq->hba_index = 0;
10011 /* link the header and data RQs onto the parent cq child list */
10012 list_add_tail(&hrq->list, &cq->child_list);
10013 list_add_tail(&drq->list, &cq->child_list);
10016 mempool_free(mbox, phba->mbox_mem_pool);
10021 * lpfc_eq_destroy - Destroy an event Queue on the HBA
10022 * @eq: The queue structure associated with the queue to destroy.
10024 * This function destroys a queue, as detailed in @eq by sending an mailbox
10025 * command, specific to the type of queue, to the HBA.
10027 * The @eq struct is used to get the queue ID of the queue to destroy.
10029 * On success this function will return a zero. If the queue destroy mailbox
10030 * command fails this function will return ENXIO.
10033 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
10035 LPFC_MBOXQ_t *mbox;
10036 int rc, length, status = 0;
10037 uint32_t shdr_status, shdr_add_status;
10038 union lpfc_sli4_cfg_shdr *shdr;
10042 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
10045 length = (sizeof(struct lpfc_mbx_eq_destroy) -
10046 sizeof(struct lpfc_sli4_cfg_mhdr));
10047 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
10048 LPFC_MBOX_OPCODE_EQ_DESTROY,
10049 length, LPFC_SLI4_MBX_EMBED);
10050 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
10052 mbox->vport = eq->phba->pport;
10053 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10055 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
10056 /* The IOCTL status is embedded in the mailbox subheader. */
10057 shdr = (union lpfc_sli4_cfg_shdr *)
10058 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
10059 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10060 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10061 if (shdr_status || shdr_add_status || rc) {
10062 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10063 "2505 EQ_DESTROY mailbox failed with "
10064 "status x%x add_status x%x, mbx status x%x\n",
10065 shdr_status, shdr_add_status, rc);
10069 /* Remove eq from any list */
10070 list_del_init(&eq->list);
10071 mempool_free(mbox, eq->phba->mbox_mem_pool);
10076 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
10077 * @cq: The queue structure associated with the queue to destroy.
10079 * This function destroys a queue, as detailed in @cq by sending an mailbox
10080 * command, specific to the type of queue, to the HBA.
10082 * The @cq struct is used to get the queue ID of the queue to destroy.
10084 * On success this function will return a zero. If the queue destroy mailbox
10085 * command fails this function will return ENXIO.
10088 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
10090 LPFC_MBOXQ_t *mbox;
10091 int rc, length, status = 0;
10092 uint32_t shdr_status, shdr_add_status;
10093 union lpfc_sli4_cfg_shdr *shdr;
10097 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
10100 length = (sizeof(struct lpfc_mbx_cq_destroy) -
10101 sizeof(struct lpfc_sli4_cfg_mhdr));
10102 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
10103 LPFC_MBOX_OPCODE_CQ_DESTROY,
10104 length, LPFC_SLI4_MBX_EMBED);
10105 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
10107 mbox->vport = cq->phba->pport;
10108 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10109 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
10110 /* The IOCTL status is embedded in the mailbox subheader. */
10111 shdr = (union lpfc_sli4_cfg_shdr *)
10112 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
10113 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10114 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10115 if (shdr_status || shdr_add_status || rc) {
10116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10117 "2506 CQ_DESTROY mailbox failed with "
10118 "status x%x add_status x%x, mbx status x%x\n",
10119 shdr_status, shdr_add_status, rc);
10122 /* Remove cq from any list */
10123 list_del_init(&cq->list);
10124 mempool_free(mbox, cq->phba->mbox_mem_pool);
10129 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
10130 * @qm: The queue structure associated with the queue to destroy.
10132 * This function destroys a queue, as detailed in @mq by sending an mailbox
10133 * command, specific to the type of queue, to the HBA.
10135 * The @mq struct is used to get the queue ID of the queue to destroy.
10137 * On success this function will return a zero. If the queue destroy mailbox
10138 * command fails this function will return ENXIO.
10141 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
10143 LPFC_MBOXQ_t *mbox;
10144 int rc, length, status = 0;
10145 uint32_t shdr_status, shdr_add_status;
10146 union lpfc_sli4_cfg_shdr *shdr;
10150 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
10153 length = (sizeof(struct lpfc_mbx_mq_destroy) -
10154 sizeof(struct lpfc_sli4_cfg_mhdr));
10155 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
10156 LPFC_MBOX_OPCODE_MQ_DESTROY,
10157 length, LPFC_SLI4_MBX_EMBED);
10158 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
10160 mbox->vport = mq->phba->pport;
10161 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10162 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
10163 /* The IOCTL status is embedded in the mailbox subheader. */
10164 shdr = (union lpfc_sli4_cfg_shdr *)
10165 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
10166 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10167 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10168 if (shdr_status || shdr_add_status || rc) {
10169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10170 "2507 MQ_DESTROY mailbox failed with "
10171 "status x%x add_status x%x, mbx status x%x\n",
10172 shdr_status, shdr_add_status, rc);
10175 /* Remove mq from any list */
10176 list_del_init(&mq->list);
10177 mempool_free(mbox, mq->phba->mbox_mem_pool);
10182 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
10183 * @wq: The queue structure associated with the queue to destroy.
10185 * This function destroys a queue, as detailed in @wq by sending an mailbox
10186 * command, specific to the type of queue, to the HBA.
10188 * The @wq struct is used to get the queue ID of the queue to destroy.
10190 * On success this function will return a zero. If the queue destroy mailbox
10191 * command fails this function will return ENXIO.
10194 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
10196 LPFC_MBOXQ_t *mbox;
10197 int rc, length, status = 0;
10198 uint32_t shdr_status, shdr_add_status;
10199 union lpfc_sli4_cfg_shdr *shdr;
10203 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
10206 length = (sizeof(struct lpfc_mbx_wq_destroy) -
10207 sizeof(struct lpfc_sli4_cfg_mhdr));
10208 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10209 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
10210 length, LPFC_SLI4_MBX_EMBED);
10211 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
10213 mbox->vport = wq->phba->pport;
10214 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10215 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
10216 shdr = (union lpfc_sli4_cfg_shdr *)
10217 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
10218 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10219 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10220 if (shdr_status || shdr_add_status || rc) {
10221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10222 "2508 WQ_DESTROY mailbox failed with "
10223 "status x%x add_status x%x, mbx status x%x\n",
10224 shdr_status, shdr_add_status, rc);
10227 /* Remove wq from any list */
10228 list_del_init(&wq->list);
10229 mempool_free(mbox, wq->phba->mbox_mem_pool);
10234 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
10235 * @rq: The queue structure associated with the queue to destroy.
10237 * This function destroys a queue, as detailed in @rq by sending an mailbox
10238 * command, specific to the type of queue, to the HBA.
10240 * The @rq struct is used to get the queue ID of the queue to destroy.
10242 * On success this function will return a zero. If the queue destroy mailbox
10243 * command fails this function will return ENXIO.
10246 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
10247 struct lpfc_queue *drq)
10249 LPFC_MBOXQ_t *mbox;
10250 int rc, length, status = 0;
10251 uint32_t shdr_status, shdr_add_status;
10252 union lpfc_sli4_cfg_shdr *shdr;
10256 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
10259 length = (sizeof(struct lpfc_mbx_rq_destroy) -
10260 sizeof(struct mbox_header));
10261 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10262 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
10263 length, LPFC_SLI4_MBX_EMBED);
10264 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
10266 mbox->vport = hrq->phba->pport;
10267 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10268 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
10269 /* The IOCTL status is embedded in the mailbox subheader. */
10270 shdr = (union lpfc_sli4_cfg_shdr *)
10271 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
10272 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10273 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10274 if (shdr_status || shdr_add_status || rc) {
10275 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10276 "2509 RQ_DESTROY mailbox failed with "
10277 "status x%x add_status x%x, mbx status x%x\n",
10278 shdr_status, shdr_add_status, rc);
10279 if (rc != MBX_TIMEOUT)
10280 mempool_free(mbox, hrq->phba->mbox_mem_pool);
10283 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
10285 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
10286 shdr = (union lpfc_sli4_cfg_shdr *)
10287 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
10288 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10289 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10290 if (shdr_status || shdr_add_status || rc) {
10291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10292 "2510 RQ_DESTROY mailbox failed with "
10293 "status x%x add_status x%x, mbx status x%x\n",
10294 shdr_status, shdr_add_status, rc);
10297 list_del_init(&hrq->list);
10298 list_del_init(&drq->list);
10299 mempool_free(mbox, hrq->phba->mbox_mem_pool);
10304 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
10305 * @phba: The virtual port for which this call being executed.
10306 * @pdma_phys_addr0: Physical address of the 1st SGL page.
10307 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
10308 * @xritag: the xritag that ties this io to the SGL pages.
10310 * This routine will post the sgl pages for the IO that has the xritag
10311 * that is in the iocbq structure. The xritag is assigned during iocbq
10312 * creation and persists for as long as the driver is loaded.
10313 * if the caller has fewer than 256 scatter gather segments to map then
10314 * pdma_phys_addr1 should be 0.
10315 * If the caller needs to map more than 256 scatter gather segment then
10316 * pdma_phys_addr1 should be a valid physical address.
10317 * physical address for SGLs must be 64 byte aligned.
10318 * If you are going to map 2 SGL's then the first one must have 256 entries
10319 * the second sgl can have between 1 and 256 entries.
10323 * -ENXIO, -ENOMEM - Failure
10326 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
10327 dma_addr_t pdma_phys_addr0,
10328 dma_addr_t pdma_phys_addr1,
10331 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
10332 LPFC_MBOXQ_t *mbox;
10334 uint32_t shdr_status, shdr_add_status;
10335 union lpfc_sli4_cfg_shdr *shdr;
10337 if (xritag == NO_XRI) {
10338 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10339 "0364 Invalid param:\n");
10343 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10347 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10348 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
10349 sizeof(struct lpfc_mbx_post_sgl_pages) -
10350 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
10352 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
10353 &mbox->u.mqe.un.post_sgl_pages;
10354 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
10355 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
10357 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
10358 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
10359 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
10360 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
10362 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
10363 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
10364 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
10365 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
10366 if (!phba->sli4_hba.intr_enable)
10367 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10369 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
10370 /* The IOCTL status is embedded in the mailbox subheader. */
10371 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
10372 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10373 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10374 if (rc != MBX_TIMEOUT)
10375 mempool_free(mbox, phba->mbox_mem_pool);
10376 if (shdr_status || shdr_add_status || rc) {
10377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10378 "2511 POST_SGL mailbox failed with "
10379 "status x%x add_status x%x, mbx status x%x\n",
10380 shdr_status, shdr_add_status, rc);
10386 * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
10387 * @phba: The virtual port for which this call being executed.
10389 * This routine will remove all of the sgl pages registered with the hba.
10393 * -ENXIO, -ENOMEM - Failure
10396 lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
10398 LPFC_MBOXQ_t *mbox;
10400 uint32_t shdr_status, shdr_add_status;
10401 union lpfc_sli4_cfg_shdr *shdr;
10403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10407 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10408 LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
10409 LPFC_SLI4_MBX_EMBED);
10410 if (!phba->sli4_hba.intr_enable)
10411 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10413 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
10414 /* The IOCTL status is embedded in the mailbox subheader. */
10415 shdr = (union lpfc_sli4_cfg_shdr *)
10416 &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
10417 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10418 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10419 if (rc != MBX_TIMEOUT)
10420 mempool_free(mbox, phba->mbox_mem_pool);
10421 if (shdr_status || shdr_add_status || rc) {
10422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10423 "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
10424 "status x%x add_status x%x, mbx status x%x\n",
10425 shdr_status, shdr_add_status, rc);
10432 * lpfc_sli4_next_xritag - Get an xritag for the io
10433 * @phba: Pointer to HBA context object.
10435 * This function gets an xritag for the iocb. If there is no unused xritag
10436 * it will return 0xffff.
10437 * The function returns the allocated xritag if successful, else returns zero.
10438 * Zero is not a valid xritag.
10439 * The caller is not required to hold any lock.
10442 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
10446 spin_lock_irq(&phba->hbalock);
10447 xritag = phba->sli4_hba.next_xri;
10448 if ((xritag != (uint16_t) -1) && xritag <
10449 (phba->sli4_hba.max_cfg_param.max_xri
10450 + phba->sli4_hba.max_cfg_param.xri_base)) {
10451 phba->sli4_hba.next_xri++;
10452 phba->sli4_hba.max_cfg_param.xri_used++;
10453 spin_unlock_irq(&phba->hbalock);
10456 spin_unlock_irq(&phba->hbalock);
10458 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10459 "2004 Failed to allocate XRI.last XRITAG is %d"
10460 " Max XRI is %d, Used XRI is %d\n",
10461 phba->sli4_hba.next_xri,
10462 phba->sli4_hba.max_cfg_param.max_xri,
10463 phba->sli4_hba.max_cfg_param.xri_used);
10468 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
10469 * @phba: pointer to lpfc hba data structure.
10471 * This routine is invoked to post a block of driver's sgl pages to the
10472 * HBA using non-embedded mailbox command. No Lock is held. This routine
10473 * is only called when the driver is loading and after all IO has been
10477 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
10479 struct lpfc_sglq *sglq_entry;
10480 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
10481 struct sgl_page_pairs *sgl_pg_pairs;
10483 LPFC_MBOXQ_t *mbox;
10484 uint32_t reqlen, alloclen, pg_pairs;
10486 uint16_t xritag_start = 0;
10487 int els_xri_cnt, rc = 0;
10488 uint32_t shdr_status, shdr_add_status;
10489 union lpfc_sli4_cfg_shdr *shdr;
10491 /* The number of sgls to be posted */
10492 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
10494 reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
10495 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
10496 if (reqlen > PAGE_SIZE) {
10497 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10498 "2559 Block sgl registration required DMA "
10499 "size (%d) great than a page\n", reqlen);
10502 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10505 "2560 Failed to allocate mbox cmd memory\n");
10509 /* Allocate DMA memory and set up the non-embedded mailbox command */
10510 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10511 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
10512 LPFC_SLI4_MBX_NEMBED);
10514 if (alloclen < reqlen) {
10515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10516 "0285 Allocated DMA memory size (%d) is "
10517 "less than the requested DMA memory "
10518 "size (%d)\n", alloclen, reqlen);
10519 lpfc_sli4_mbox_cmd_free(phba, mbox);
10523 /* Get the first SGE entry from the non-embedded DMA memory */
10524 if (unlikely(!mbox->sge_array)) {
10525 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
10526 "2525 Failed to get the non-embedded SGE "
10527 "virtual address\n");
10528 lpfc_sli4_mbox_cmd_free(phba, mbox);
10531 viraddr = mbox->sge_array->addr[0];
10533 /* Set up the SGL pages in the non-embedded DMA pages */
10534 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
10535 sgl_pg_pairs = &sgl->sgl_pg_pairs;
10537 for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
10538 sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
10539 /* Set up the sge entry */
10540 sgl_pg_pairs->sgl_pg0_addr_lo =
10541 cpu_to_le32(putPaddrLow(sglq_entry->phys));
10542 sgl_pg_pairs->sgl_pg0_addr_hi =
10543 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
10544 sgl_pg_pairs->sgl_pg1_addr_lo =
10545 cpu_to_le32(putPaddrLow(0));
10546 sgl_pg_pairs->sgl_pg1_addr_hi =
10547 cpu_to_le32(putPaddrHigh(0));
10548 /* Keep the first xritag on the list */
10550 xritag_start = sglq_entry->sli4_xritag;
10553 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
10554 pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
10555 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
10556 /* Perform endian conversion if necessary */
10557 sgl->word0 = cpu_to_le32(sgl->word0);
10559 if (!phba->sli4_hba.intr_enable)
10560 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10562 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
10563 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
10565 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
10566 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10567 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10568 if (rc != MBX_TIMEOUT)
10569 lpfc_sli4_mbox_cmd_free(phba, mbox);
10570 if (shdr_status || shdr_add_status || rc) {
10571 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10572 "2513 POST_SGL_BLOCK mailbox command failed "
10573 "status x%x add_status x%x mbx status x%x\n",
10574 shdr_status, shdr_add_status, rc);
10581 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
10582 * @phba: pointer to lpfc hba data structure.
10583 * @sblist: pointer to scsi buffer list.
10584 * @count: number of scsi buffers on the list.
10586 * This routine is invoked to post a block of @count scsi sgl pages from a
10587 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
10592 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
10595 struct lpfc_scsi_buf *psb;
10596 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
10597 struct sgl_page_pairs *sgl_pg_pairs;
10599 LPFC_MBOXQ_t *mbox;
10600 uint32_t reqlen, alloclen, pg_pairs;
10602 uint16_t xritag_start = 0;
10604 uint32_t shdr_status, shdr_add_status;
10605 dma_addr_t pdma_phys_bpl1;
10606 union lpfc_sli4_cfg_shdr *shdr;
10608 /* Calculate the requested length of the dma memory */
10609 reqlen = cnt * sizeof(struct sgl_page_pairs) +
10610 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
10611 if (reqlen > PAGE_SIZE) {
10612 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10613 "0217 Block sgl registration required DMA "
10614 "size (%d) great than a page\n", reqlen);
10617 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10619 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10620 "0283 Failed to allocate mbox cmd memory\n");
10624 /* Allocate DMA memory and set up the non-embedded mailbox command */
10625 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
10626 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
10627 LPFC_SLI4_MBX_NEMBED);
10629 if (alloclen < reqlen) {
10630 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10631 "2561 Allocated DMA memory size (%d) is "
10632 "less than the requested DMA memory "
10633 "size (%d)\n", alloclen, reqlen);
10634 lpfc_sli4_mbox_cmd_free(phba, mbox);
10638 /* Get the first SGE entry from the non-embedded DMA memory */
10639 if (unlikely(!mbox->sge_array)) {
10640 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
10641 "2565 Failed to get the non-embedded SGE "
10642 "virtual address\n");
10643 lpfc_sli4_mbox_cmd_free(phba, mbox);
10646 viraddr = mbox->sge_array->addr[0];
10648 /* Set up the SGL pages in the non-embedded DMA pages */
10649 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
10650 sgl_pg_pairs = &sgl->sgl_pg_pairs;
10653 list_for_each_entry(psb, sblist, list) {
10654 /* Set up the sge entry */
10655 sgl_pg_pairs->sgl_pg0_addr_lo =
10656 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
10657 sgl_pg_pairs->sgl_pg0_addr_hi =
10658 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
10659 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
10660 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
10662 pdma_phys_bpl1 = 0;
10663 sgl_pg_pairs->sgl_pg1_addr_lo =
10664 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
10665 sgl_pg_pairs->sgl_pg1_addr_hi =
10666 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
10667 /* Keep the first xritag on the list */
10669 xritag_start = psb->cur_iocbq.sli4_xritag;
10673 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
10674 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
10675 /* Perform endian conversion if necessary */
10676 sgl->word0 = cpu_to_le32(sgl->word0);
10678 if (!phba->sli4_hba.intr_enable)
10679 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
10681 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
10682 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
10684 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
10685 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10686 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10687 if (rc != MBX_TIMEOUT)
10688 lpfc_sli4_mbox_cmd_free(phba, mbox);
10689 if (shdr_status || shdr_add_status || rc) {
10690 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10691 "2564 POST_SGL_BLOCK mailbox command failed "
10692 "status x%x add_status x%x mbx status x%x\n",
10693 shdr_status, shdr_add_status, rc);
10700 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
10701 * @phba: pointer to lpfc_hba struct that the frame was received on
10702 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10704 * This function checks the fields in the @fc_hdr to see if the FC frame is a
10705 * valid type of frame that the LPFC driver will handle. This function will
10706 * return a zero if the frame is a valid frame or a non zero value when the
10707 * frame does not pass the check.
10710 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
10712 char *rctl_names[] = FC_RCTL_NAMES_INIT;
10713 char *type_names[] = FC_TYPE_NAMES_INIT;
10714 struct fc_vft_header *fc_vft_hdr;
10716 switch (fc_hdr->fh_r_ctl) {
10717 case FC_RCTL_DD_UNCAT: /* uncategorized information */
10718 case FC_RCTL_DD_SOL_DATA: /* solicited data */
10719 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
10720 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
10721 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
10722 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
10723 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
10724 case FC_RCTL_DD_CMD_STATUS: /* command status */
10725 case FC_RCTL_ELS_REQ: /* extended link services request */
10726 case FC_RCTL_ELS_REP: /* extended link services reply */
10727 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
10728 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
10729 case FC_RCTL_BA_NOP: /* basic link service NOP */
10730 case FC_RCTL_BA_ABTS: /* basic link service abort */
10731 case FC_RCTL_BA_RMC: /* remove connection */
10732 case FC_RCTL_BA_ACC: /* basic accept */
10733 case FC_RCTL_BA_RJT: /* basic reject */
10734 case FC_RCTL_BA_PRMT:
10735 case FC_RCTL_ACK_1: /* acknowledge_1 */
10736 case FC_RCTL_ACK_0: /* acknowledge_0 */
10737 case FC_RCTL_P_RJT: /* port reject */
10738 case FC_RCTL_F_RJT: /* fabric reject */
10739 case FC_RCTL_P_BSY: /* port busy */
10740 case FC_RCTL_F_BSY: /* fabric busy to data frame */
10741 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
10742 case FC_RCTL_LCR: /* link credit reset */
10743 case FC_RCTL_END: /* end */
10745 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
10746 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
10747 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
10748 return lpfc_fc_frame_check(phba, fc_hdr);
10752 switch (fc_hdr->fh_type) {
10763 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10764 "2538 Received frame rctl:%s type:%s\n",
10765 rctl_names[fc_hdr->fh_r_ctl],
10766 type_names[fc_hdr->fh_type]);
10769 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
10770 "2539 Dropped frame rctl:%s type:%s\n",
10771 rctl_names[fc_hdr->fh_r_ctl],
10772 type_names[fc_hdr->fh_type]);
10777 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
10778 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10780 * This function processes the FC header to retrieve the VFI from the VF
10781 * header, if one exists. This function will return the VFI if one exists
10782 * or 0 if no VSAN Header exists.
10785 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
10787 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
10789 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
10791 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
10795 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
10796 * @phba: Pointer to the HBA structure to search for the vport on
10797 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10798 * @fcfi: The FC Fabric ID that the frame came from
10800 * This function searches the @phba for a vport that matches the content of the
10801 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
10802 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
10803 * returns the matching vport pointer or NULL if unable to match frame to a
10806 static struct lpfc_vport *
10807 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
10810 struct lpfc_vport **vports;
10811 struct lpfc_vport *vport = NULL;
10813 uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
10814 fc_hdr->fh_d_id[1] << 8 |
10815 fc_hdr->fh_d_id[2]);
10817 vports = lpfc_create_vport_work_array(phba);
10818 if (vports != NULL)
10819 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
10820 if (phba->fcf.fcfi == fcfi &&
10821 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
10822 vports[i]->fc_myDID == did) {
10827 lpfc_destroy_vport_work_array(phba, vports);
10832 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
10833 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
10835 * This function searches through the existing incomplete sequences that have
10836 * been sent to this @vport. If the frame matches one of the incomplete
10837 * sequences then the dbuf in the @dmabuf is added to the list of frames that
10838 * make up that sequence. If no sequence is found that matches this frame then
10839 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
10840 * This function returns a pointer to the first dmabuf in the sequence list that
10841 * the frame was linked to.
10843 static struct hbq_dmabuf *
10844 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
10846 struct fc_frame_header *new_hdr;
10847 struct fc_frame_header *temp_hdr;
10848 struct lpfc_dmabuf *d_buf;
10849 struct lpfc_dmabuf *h_buf;
10850 struct hbq_dmabuf *seq_dmabuf = NULL;
10851 struct hbq_dmabuf *temp_dmabuf = NULL;
10853 INIT_LIST_HEAD(&dmabuf->dbuf.list);
10854 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
10855 /* Use the hdr_buf to find the sequence that this frame belongs to */
10856 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
10857 temp_hdr = (struct fc_frame_header *)h_buf->virt;
10858 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
10859 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
10860 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
10862 /* found a pending sequence that matches this frame */
10863 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
10868 * This indicates first frame received for this sequence.
10869 * Queue the buffer on the vport's rcv_buffer_list.
10871 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
10874 temp_hdr = seq_dmabuf->hbuf.virt;
10875 if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
10876 list_del_init(&seq_dmabuf->hbuf.list);
10877 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
10878 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
10881 /* find the correct place in the sequence to insert this frame */
10882 list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
10883 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
10884 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
10886 * If the frame's sequence count is greater than the frame on
10887 * the list then insert the frame right after this frame
10889 if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
10890 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
10898 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
10899 * @vport: pointer to a vitural port
10900 * @dmabuf: pointer to a dmabuf that describes the FC sequence
10902 * This function tries to abort from the partially assembed sequence, described
10903 * by the information from basic abbort @dmabuf. It checks to see whether such
10904 * partially assembled sequence held by the driver. If so, it shall free up all
10905 * the frames from the partially assembled sequence.
10908 * true -- if there is matching partially assembled sequence present and all
10909 * the frames freed with the sequence;
10910 * false -- if there is no matching partially assembled sequence present so
10911 * nothing got aborted in the lower layer driver
10914 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
10915 struct hbq_dmabuf *dmabuf)
10917 struct fc_frame_header *new_hdr;
10918 struct fc_frame_header *temp_hdr;
10919 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
10920 struct hbq_dmabuf *seq_dmabuf = NULL;
10922 /* Use the hdr_buf to find the sequence that matches this frame */
10923 INIT_LIST_HEAD(&dmabuf->dbuf.list);
10924 INIT_LIST_HEAD(&dmabuf->hbuf.list);
10925 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
10926 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
10927 temp_hdr = (struct fc_frame_header *)h_buf->virt;
10928 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
10929 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
10930 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
10932 /* found a pending sequence that matches this frame */
10933 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
10937 /* Free up all the frames from the partially assembled sequence */
10939 list_for_each_entry_safe(d_buf, n_buf,
10940 &seq_dmabuf->dbuf.list, list) {
10941 list_del_init(&d_buf->list);
10942 lpfc_in_buf_free(vport->phba, d_buf);
10950 * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
10951 * @phba: Pointer to HBA context object.
10952 * @cmd_iocbq: pointer to the command iocbq structure.
10953 * @rsp_iocbq: pointer to the response iocbq structure.
10955 * This function handles the sequence abort accept iocb command complete
10956 * event. It properly releases the memory allocated to the sequence abort
10960 lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
10961 struct lpfc_iocbq *cmd_iocbq,
10962 struct lpfc_iocbq *rsp_iocbq)
10965 lpfc_sli_release_iocbq(phba, cmd_iocbq);
10969 * lpfc_sli4_seq_abort_acc - Accept sequence abort
10970 * @phba: Pointer to HBA context object.
10971 * @fc_hdr: pointer to a FC frame header.
10973 * This function sends a basic accept to a previous unsol sequence abort
10974 * event after aborting the sequence handling.
10977 lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
10978 struct fc_frame_header *fc_hdr)
10980 struct lpfc_iocbq *ctiocb = NULL;
10981 struct lpfc_nodelist *ndlp;
10986 if (!lpfc_is_link_up(phba))
10989 sid = sli4_sid_from_fc_hdr(fc_hdr);
10990 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
10992 ndlp = lpfc_findnode_did(phba->pport, sid);
10994 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
10995 "1268 Find ndlp returned NULL for oxid:x%x "
10996 "SID:x%x\n", oxid, sid);
11000 /* Allocate buffer for acc iocb */
11001 ctiocb = lpfc_sli_get_iocbq(phba);
11005 icmd = &ctiocb->iocb;
11006 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
11007 icmd->un.xseq64.bdl.bdeSize = 0;
11008 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
11009 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
11010 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
11012 /* Fill in the rest of iocb fields */
11013 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
11014 icmd->ulpBdeCount = 0;
11016 icmd->ulpClass = CLASS3;
11017 icmd->ulpContext = ndlp->nlp_rpi;
11018 icmd->un.ulpWord[3] = oxid;
11020 ctiocb->sli4_xritag = NO_XRI;
11021 ctiocb->iocb_cmpl = NULL;
11022 ctiocb->vport = phba->pport;
11023 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
11025 /* Xmit CT abts accept on exchange <xid> */
11026 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
11027 "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
11028 CMD_XMIT_BLS_RSP64_CX, phba->link_state);
11029 lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
11033 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
11034 * @vport: Pointer to the vport on which this sequence was received
11035 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11037 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
11038 * receive sequence is only partially assembed by the driver, it shall abort
11039 * the partially assembled frames for the sequence. Otherwise, if the
11040 * unsolicited receive sequence has been completely assembled and passed to
11041 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
11042 * unsolicited sequence has been aborted. After that, it will issue a basic
11043 * accept to accept the abort.
11046 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
11047 struct hbq_dmabuf *dmabuf)
11049 struct lpfc_hba *phba = vport->phba;
11050 struct fc_frame_header fc_hdr;
11053 /* Try to abort partially assembled seq */
11054 abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
11056 /* Make a copy of fc_hdr before the dmabuf being released */
11057 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
11059 /* Send abort to ULP if partially seq abort failed */
11060 if (abts_par == false)
11061 lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
11063 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11064 /* Send basic accept (BA_ACC) to the abort requester */
11065 lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
11069 * lpfc_seq_complete - Indicates if a sequence is complete
11070 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11072 * This function checks the sequence, starting with the frame described by
11073 * @dmabuf, to see if all the frames associated with this sequence are present.
11074 * the frames associated with this sequence are linked to the @dmabuf using the
11075 * dbuf list. This function looks for two major things. 1) That the first frame
11076 * has a sequence count of zero. 2) There is a frame with last frame of sequence
11077 * set. 3) That there are no holes in the sequence count. The function will
11078 * return 1 when the sequence is complete, otherwise it will return 0.
11081 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
11083 struct fc_frame_header *hdr;
11084 struct lpfc_dmabuf *d_buf;
11085 struct hbq_dmabuf *seq_dmabuf;
11089 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
11090 /* make sure first fame of sequence has a sequence count of zero */
11091 if (hdr->fh_seq_cnt != seq_count)
11093 fctl = (hdr->fh_f_ctl[0] << 16 |
11094 hdr->fh_f_ctl[1] << 8 |
11096 /* If last frame of sequence we can return success. */
11097 if (fctl & FC_FC_END_SEQ)
11099 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
11100 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
11101 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
11102 /* If there is a hole in the sequence count then fail. */
11103 if (++seq_count != hdr->fh_seq_cnt)
11105 fctl = (hdr->fh_f_ctl[0] << 16 |
11106 hdr->fh_f_ctl[1] << 8 |
11108 /* If last frame of sequence we can return success. */
11109 if (fctl & FC_FC_END_SEQ)
11116 * lpfc_prep_seq - Prep sequence for ULP processing
11117 * @vport: Pointer to the vport on which this sequence was received
11118 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11120 * This function takes a sequence, described by a list of frames, and creates
11121 * a list of iocbq structures to describe the sequence. This iocbq list will be
11122 * used to issue to the generic unsolicited sequence handler. This routine
11123 * returns a pointer to the first iocbq in the list. If the function is unable
11124 * to allocate an iocbq then it throw out the received frames that were not
11125 * able to be described and return a pointer to the first iocbq. If unable to
11126 * allocate any iocbqs (including the first) this function will return NULL.
11128 static struct lpfc_iocbq *
11129 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
11131 struct lpfc_dmabuf *d_buf, *n_buf;
11132 struct lpfc_iocbq *first_iocbq, *iocbq;
11133 struct fc_frame_header *fc_hdr;
11136 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
11137 /* remove from receive buffer list */
11138 list_del_init(&seq_dmabuf->hbuf.list);
11139 /* get the Remote Port's SID */
11140 sid = sli4_sid_from_fc_hdr(fc_hdr);
11141 /* Get an iocbq struct to fill in. */
11142 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
11144 /* Initialize the first IOCB. */
11145 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
11146 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
11147 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
11148 first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
11149 first_iocbq->iocb.unsli3.rcvsli3.vpi =
11150 vport->vpi + vport->phba->vpi_base;
11151 /* put the first buffer into the first IOCBq */
11152 first_iocbq->context2 = &seq_dmabuf->dbuf;
11153 first_iocbq->context3 = NULL;
11154 first_iocbq->iocb.ulpBdeCount = 1;
11155 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
11156 LPFC_DATA_BUF_SIZE;
11157 first_iocbq->iocb.un.rcvels.remoteID = sid;
11158 first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
11159 bf_get(lpfc_rcqe_length,
11160 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
11162 iocbq = first_iocbq;
11164 * Each IOCBq can have two Buffers assigned, so go through the list
11165 * of buffers for this sequence and save two buffers in each IOCBq
11167 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
11169 lpfc_in_buf_free(vport->phba, d_buf);
11172 if (!iocbq->context3) {
11173 iocbq->context3 = d_buf;
11174 iocbq->iocb.ulpBdeCount++;
11175 iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
11176 LPFC_DATA_BUF_SIZE;
11177 first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
11178 bf_get(lpfc_rcqe_length,
11179 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
11181 iocbq = lpfc_sli_get_iocbq(vport->phba);
11184 first_iocbq->iocb.ulpStatus =
11185 IOSTAT_FCP_RSP_ERROR;
11186 first_iocbq->iocb.un.ulpWord[4] =
11187 IOERR_NO_RESOURCES;
11189 lpfc_in_buf_free(vport->phba, d_buf);
11192 iocbq->context2 = d_buf;
11193 iocbq->context3 = NULL;
11194 iocbq->iocb.ulpBdeCount = 1;
11195 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
11196 LPFC_DATA_BUF_SIZE;
11197 first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
11198 bf_get(lpfc_rcqe_length,
11199 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
11200 iocbq->iocb.un.rcvels.remoteID = sid;
11201 list_add_tail(&iocbq->list, &first_iocbq->list);
11204 return first_iocbq;
11208 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
11209 struct hbq_dmabuf *seq_dmabuf)
11211 struct fc_frame_header *fc_hdr;
11212 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
11213 struct lpfc_hba *phba = vport->phba;
11215 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
11216 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
11218 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11219 "2707 Ring %d handler: Failed to allocate "
11220 "iocb Rctl x%x Type x%x received\n",
11222 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
11225 if (!lpfc_complete_unsol_iocb(phba,
11226 &phba->sli.ring[LPFC_ELS_RING],
11227 iocbq, fc_hdr->fh_r_ctl,
11229 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11230 "2540 Ring %d handler: unexpected Rctl "
11231 "x%x Type x%x received\n",
11233 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
11235 /* Free iocb created in lpfc_prep_seq */
11236 list_for_each_entry_safe(curr_iocb, next_iocb,
11237 &iocbq->list, list) {
11238 list_del_init(&curr_iocb->list);
11239 lpfc_sli_release_iocbq(phba, curr_iocb);
11241 lpfc_sli_release_iocbq(phba, iocbq);
11245 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
11246 * @phba: Pointer to HBA context object.
11248 * This function is called with no lock held. This function processes all
11249 * the received buffers and gives it to upper layers when a received buffer
11250 * indicates that it is the final frame in the sequence. The interrupt
11251 * service routine processes received buffers at interrupt contexts and adds
11252 * received dma buffers to the rb_pend_list queue and signals the worker thread.
11253 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
11254 * appropriate receive function when the final frame in a sequence is received.
11257 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
11258 struct hbq_dmabuf *dmabuf)
11260 struct hbq_dmabuf *seq_dmabuf;
11261 struct fc_frame_header *fc_hdr;
11262 struct lpfc_vport *vport;
11265 /* Clear hba flag and get all received buffers into the cmplq */
11266 spin_lock_irq(&phba->hbalock);
11267 phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
11268 spin_unlock_irq(&phba->hbalock);
11270 /* Process each received buffer */
11271 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
11272 /* check to see if this a valid type of frame */
11273 if (lpfc_fc_frame_check(phba, fc_hdr)) {
11274 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11277 fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
11278 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
11280 /* throw out the frame */
11281 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11284 /* Handle the basic abort sequence (BA_ABTS) event */
11285 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
11286 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
11290 /* Link this frame */
11291 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
11293 /* unable to add frame to vport - throw it out */
11294 lpfc_in_buf_free(phba, &dmabuf->dbuf);
11297 /* If not last frame in sequence continue processing frames. */
11298 if (!lpfc_seq_complete(seq_dmabuf)) {
11300 * When saving off frames post a new one and mark this
11301 * frame to be freed when it is finished.
11303 lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
11307 /* Send the complete sequence to the upper layer protocol */
11308 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
11312 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
11313 * @phba: pointer to lpfc hba data structure.
11315 * This routine is invoked to post rpi header templates to the
11316 * HBA consistent with the SLI-4 interface spec. This routine
11317 * posts a PAGE_SIZE memory region to the port to hold up to
11318 * PAGE_SIZE modulo 64 rpi context headers.
11320 * This routine does not require any locks. It's usage is expected
11321 * to be driver load or reset recovery when the driver is
11326 * EIO - The mailbox failed to complete successfully.
11327 * When this error occurs, the driver is not guaranteed
11328 * to have any rpi regions posted to the device and
11329 * must either attempt to repost the regions or take a
11333 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
11335 struct lpfc_rpi_hdr *rpi_page;
11338 /* Post all rpi memory regions to the port. */
11339 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
11340 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
11341 if (rc != MBX_SUCCESS) {
11342 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11343 "2008 Error %d posting all rpi "
11354 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
11355 * @phba: pointer to lpfc hba data structure.
11356 * @rpi_page: pointer to the rpi memory region.
11358 * This routine is invoked to post a single rpi header to the
11359 * HBA consistent with the SLI-4 interface spec. This memory region
11360 * maps up to 64 rpi context regions.
11364 * ENOMEM - No available memory
11365 * EIO - The mailbox failed to complete successfully.
11368 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
11370 LPFC_MBOXQ_t *mboxq;
11371 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
11374 uint32_t shdr_status, shdr_add_status;
11375 union lpfc_sli4_cfg_shdr *shdr;
11377 /* The port is notified of the header region via a mailbox command. */
11378 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11380 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11381 "2001 Unable to allocate memory for issuing "
11382 "SLI_CONFIG_SPECIAL mailbox command\n");
11386 /* Post all rpi memory regions to the port. */
11387 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
11388 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
11389 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
11390 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
11391 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
11392 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
11393 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
11394 hdr_tmpl, rpi_page->page_count);
11395 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
11396 rpi_page->start_rpi);
11397 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
11398 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
11399 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11400 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
11401 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11402 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11403 if (rc != MBX_TIMEOUT)
11404 mempool_free(mboxq, phba->mbox_mem_pool);
11405 if (shdr_status || shdr_add_status || rc) {
11406 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11407 "2514 POST_RPI_HDR mailbox failed with "
11408 "status x%x add_status x%x, mbx status x%x\n",
11409 shdr_status, shdr_add_status, rc);
11416 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
11417 * @phba: pointer to lpfc hba data structure.
11419 * This routine is invoked to post rpi header templates to the
11420 * HBA consistent with the SLI-4 interface spec. This routine
11421 * posts a PAGE_SIZE memory region to the port to hold up to
11422 * PAGE_SIZE modulo 64 rpi context headers.
11425 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
11426 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
11429 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
11432 uint16_t max_rpi, rpi_base, rpi_limit;
11433 uint16_t rpi_remaining;
11434 struct lpfc_rpi_hdr *rpi_hdr;
11436 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
11437 rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
11438 rpi_limit = phba->sli4_hba.next_rpi;
11441 * The valid rpi range is not guaranteed to be zero-based. Start
11442 * the search at the rpi_base as reported by the port.
11444 spin_lock_irq(&phba->hbalock);
11445 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
11446 if (rpi >= rpi_limit || rpi < rpi_base)
11447 rpi = LPFC_RPI_ALLOC_ERROR;
11449 set_bit(rpi, phba->sli4_hba.rpi_bmask);
11450 phba->sli4_hba.max_cfg_param.rpi_used++;
11451 phba->sli4_hba.rpi_count++;
11455 * Don't try to allocate more rpi header regions if the device limit
11456 * on available rpis max has been exhausted.
11458 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
11459 (phba->sli4_hba.rpi_count >= max_rpi)) {
11460 spin_unlock_irq(&phba->hbalock);
11465 * If the driver is running low on rpi resources, allocate another
11466 * page now. Note that the next_rpi value is used because
11467 * it represents how many are actually in use whereas max_rpi notes
11468 * how many are supported max by the device.
11470 rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
11471 phba->sli4_hba.rpi_count;
11472 spin_unlock_irq(&phba->hbalock);
11473 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
11474 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
11476 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11477 "2002 Error Could not grow rpi "
11480 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
11488 * lpfc_sli4_free_rpi - Release an rpi for reuse.
11489 * @phba: pointer to lpfc hba data structure.
11491 * This routine is invoked to release an rpi to the pool of
11492 * available rpis maintained by the driver.
11495 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
11497 spin_lock_irq(&phba->hbalock);
11498 clear_bit(rpi, phba->sli4_hba.rpi_bmask);
11499 phba->sli4_hba.rpi_count--;
11500 phba->sli4_hba.max_cfg_param.rpi_used--;
11501 spin_unlock_irq(&phba->hbalock);
11505 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
11506 * @phba: pointer to lpfc hba data structure.
11508 * This routine is invoked to remove the memory region that
11509 * provided rpi via a bitmask.
11512 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
11514 kfree(phba->sli4_hba.rpi_bmask);
11518 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
11519 * @phba: pointer to lpfc hba data structure.
11521 * This routine is invoked to remove the memory region that
11522 * provided rpi via a bitmask.
11525 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
11527 LPFC_MBOXQ_t *mboxq;
11528 struct lpfc_hba *phba = ndlp->phba;
11531 /* The port is notified of the header region via a mailbox command. */
11532 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11536 /* Post all rpi memory regions to the port. */
11537 lpfc_resume_rpi(mboxq, ndlp);
11538 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
11539 if (rc == MBX_NOT_FINISHED) {
11540 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11541 "2010 Resume RPI Mailbox failed "
11542 "status %d, mbxStatus x%x\n", rc,
11543 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
11544 mempool_free(mboxq, phba->mbox_mem_pool);
11551 * lpfc_sli4_init_vpi - Initialize a vpi with the port
11552 * @phba: pointer to lpfc hba data structure.
11553 * @vpi: vpi value to activate with the port.
11555 * This routine is invoked to activate a vpi with the
11556 * port when the host intends to use vports with a
11561 * -Evalue otherwise
11564 lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
11566 LPFC_MBOXQ_t *mboxq;
11572 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11575 lpfc_init_vpi(phba, mboxq, vpi);
11576 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
11577 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11578 if (rc != MBX_TIMEOUT)
11579 mempool_free(mboxq, phba->mbox_mem_pool);
11580 if (rc != MBX_SUCCESS) {
11581 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11582 "2022 INIT VPI Mailbox failed "
11583 "status %d, mbxStatus x%x\n", rc,
11584 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
11591 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
11592 * @phba: pointer to lpfc hba data structure.
11593 * @mboxq: Pointer to mailbox object.
11595 * This routine is invoked to manually add a single FCF record. The caller
11596 * must pass a completely initialized FCF_Record. This routine takes
11597 * care of the nonembedded mailbox operations.
11600 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11603 union lpfc_sli4_cfg_shdr *shdr;
11604 uint32_t shdr_status, shdr_add_status;
11606 virt_addr = mboxq->sge_array->addr[0];
11607 /* The IOCTL status is embedded in the mailbox subheader. */
11608 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
11609 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11610 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11612 if ((shdr_status || shdr_add_status) &&
11613 (shdr_status != STATUS_FCF_IN_USE))
11614 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11615 "2558 ADD_FCF_RECORD mailbox failed with "
11616 "status x%x add_status x%x\n",
11617 shdr_status, shdr_add_status);
11619 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11623 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
11624 * @phba: pointer to lpfc hba data structure.
11625 * @fcf_record: pointer to the initialized fcf record to add.
11627 * This routine is invoked to manually add a single FCF record. The caller
11628 * must pass a completely initialized FCF_Record. This routine takes
11629 * care of the nonembedded mailbox operations.
11632 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
11635 LPFC_MBOXQ_t *mboxq;
11638 dma_addr_t phys_addr;
11639 struct lpfc_mbx_sge sge;
11640 uint32_t alloc_len, req_len;
11643 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11646 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
11650 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
11653 /* Allocate DMA memory and set up the non-embedded mailbox command */
11654 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
11655 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
11656 req_len, LPFC_SLI4_MBX_NEMBED);
11657 if (alloc_len < req_len) {
11658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11659 "2523 Allocated DMA memory size (x%x) is "
11660 "less than the requested DMA memory "
11661 "size (x%x)\n", alloc_len, req_len);
11662 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11667 * Get the first SGE entry from the non-embedded DMA memory. This
11668 * routine only uses a single SGE.
11670 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
11671 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
11672 if (unlikely(!mboxq->sge_array)) {
11673 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
11674 "2526 Failed to get the non-embedded SGE "
11675 "virtual address\n");
11676 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11679 virt_addr = mboxq->sge_array->addr[0];
11681 * Configure the FCF record for FCFI 0. This is the driver's
11682 * hardcoded default and gets used in nonFIP mode.
11684 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
11685 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
11686 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
11689 * Copy the fcf_index and the FCF Record Data. The data starts after
11690 * the FCoE header plus word10. The data copy needs to be endian
11693 bytep += sizeof(uint32_t);
11694 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
11695 mboxq->vport = phba->pport;
11696 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
11697 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
11698 if (rc == MBX_NOT_FINISHED) {
11699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11700 "2515 ADD_FCF_RECORD mailbox failed with "
11701 "status 0x%x\n", rc);
11702 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11711 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
11712 * @phba: pointer to lpfc hba data structure.
11713 * @fcf_record: pointer to the fcf record to write the default data.
11714 * @fcf_index: FCF table entry index.
11716 * This routine is invoked to build the driver's default FCF record. The
11717 * values used are hardcoded. This routine handles memory initialization.
11721 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
11722 struct fcf_record *fcf_record,
11723 uint16_t fcf_index)
11725 memset(fcf_record, 0, sizeof(struct fcf_record));
11726 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
11727 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
11728 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
11729 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
11730 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
11731 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
11732 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
11733 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
11734 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
11735 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
11736 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
11737 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
11738 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
11739 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
11740 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
11741 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
11742 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
11743 /* Set the VLAN bit map */
11744 if (phba->valid_vlan) {
11745 fcf_record->vlan_bitmap[phba->vlan_id / 8]
11746 = 1 << (phba->vlan_id % 8);
11751 * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
11752 * @phba: pointer to lpfc hba data structure.
11753 * @fcf_index: FCF table entry offset.
11755 * This routine is invoked to read up to @fcf_num of FCF record from the
11756 * device starting with the given @fcf_index.
11759 lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
11762 LPFC_MBOXQ_t *mboxq;
11764 dma_addr_t phys_addr;
11766 struct lpfc_mbx_sge sge;
11767 uint32_t alloc_len, req_len;
11768 struct lpfc_mbx_read_fcf_tbl *read_fcf;
11770 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
11771 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11774 "2000 Failed to allocate mbox for "
11780 req_len = sizeof(struct fcf_record) +
11781 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
11783 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
11784 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
11785 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
11786 LPFC_SLI4_MBX_NEMBED);
11788 if (alloc_len < req_len) {
11789 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11790 "0291 Allocated DMA memory size (x%x) is "
11791 "less than the requested DMA memory "
11792 "size (x%x)\n", alloc_len, req_len);
11797 /* Get the first SGE entry from the non-embedded DMA memory. This
11798 * routine only uses a single SGE.
11800 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
11801 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
11802 if (unlikely(!mboxq->sge_array)) {
11803 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
11804 "2527 Failed to get the non-embedded SGE "
11805 "virtual address\n");
11809 virt_addr = mboxq->sge_array->addr[0];
11810 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
11812 /* Set up command fields */
11813 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
11814 /* Perform necessary endian conversion */
11815 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
11816 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
11817 mboxq->vport = phba->pport;
11818 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
11819 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
11820 if (rc == MBX_NOT_FINISHED) {
11823 spin_lock_irq(&phba->hbalock);
11824 phba->hba_flag |= FCF_DISC_INPROGRESS;
11825 spin_unlock_irq(&phba->hbalock);
11831 lpfc_sli4_mbox_cmd_free(phba, mboxq);
11832 /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
11833 spin_lock_irq(&phba->hbalock);
11834 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
11835 spin_unlock_irq(&phba->hbalock);
11841 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
11842 * @phba: pointer to lpfc hba data structure.
11844 * This function read region 23 and parse TLV for port status to
11845 * decide if the user disaled the port. If the TLV indicates the
11846 * port is disabled, the hba_flag is set accordingly.
11849 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
11851 LPFC_MBOXQ_t *pmb = NULL;
11853 uint8_t *rgn23_data = NULL;
11854 uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
11857 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11859 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11860 "2600 lpfc_sli_read_serdes_param failed to"
11861 " allocate mailbox memory\n");
11866 /* Get adapter Region 23 data */
11867 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
11872 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
11873 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
11875 if (rc != MBX_SUCCESS) {
11876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11877 "2601 lpfc_sli_read_link_ste failed to"
11878 " read config region 23 rc 0x%x Status 0x%x\n",
11879 rc, mb->mbxStatus);
11880 mb->un.varDmp.word_cnt = 0;
11883 * dump mem may return a zero when finished or we got a
11884 * mailbox error, either way we are done.
11886 if (mb->un.varDmp.word_cnt == 0)
11888 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
11889 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
11891 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
11892 rgn23_data + offset,
11893 mb->un.varDmp.word_cnt);
11894 offset += mb->un.varDmp.word_cnt;
11895 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
11897 data_size = offset;
11903 /* Check the region signature first */
11904 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
11905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11906 "2619 Config region 23 has bad signature\n");
11911 /* Check the data structure version */
11912 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
11913 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11914 "2620 Config region 23 has bad version\n");
11919 /* Parse TLV entries in the region */
11920 while (offset < data_size) {
11921 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
11924 * If the TLV is not driver specific TLV or driver id is
11925 * not linux driver id, skip the record.
11927 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
11928 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
11929 (rgn23_data[offset + 3] != 0)) {
11930 offset += rgn23_data[offset + 1] * 4 + 4;
11934 /* Driver found a driver specific TLV in the config region */
11935 sub_tlv_len = rgn23_data[offset + 1] * 4;
11940 * Search for configured port state sub-TLV.
11942 while ((offset < data_size) &&
11943 (tlv_offset < sub_tlv_len)) {
11944 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
11949 if (rgn23_data[offset] != PORT_STE_TYPE) {
11950 offset += rgn23_data[offset + 1] * 4 + 4;
11951 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
11955 /* This HBA contains PORT_STE configured */
11956 if (!rgn23_data[offset + 2])
11957 phba->hba_flag |= LINK_DISABLED;
11964 mempool_free(pmb, phba->mbox_mem_pool);