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>
26 #include <linux/slab.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <linux/aer.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
48 #include "lpfc_vport.h"
50 /* There are only four IOCB completion types. */
51 typedef enum _lpfc_iocb_type
{
59 /* Provide function prototypes local to this module. */
60 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
62 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
63 uint8_t *, uint32_t *);
64 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
66 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
69 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
75 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
76 * @q: The Work Queue to operate on.
77 * @wqe: The work Queue Entry to put on the Work queue.
79 * This routine will copy the contents of @wqe to the next available entry on
80 * the @q. This function will then ring the Work Queue Doorbell to signal the
81 * HBA to start processing the Work Queue Entry. This function returns 0 if
82 * successful. If no entries are available on @q then this function will return
84 * The caller is expected to hold the hbalock when calling this routine.
87 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
89 union lpfc_wqe
*temp_wqe
= q
->qe
[q
->host_index
].wqe
;
90 struct lpfc_register doorbell
;
93 /* If the host has not yet processed the next entry then we are done */
94 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
96 /* set consumption flag every once in a while */
97 if (!((q
->host_index
+ 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL
))
98 bf_set(lpfc_wqe_gen_wqec
, &wqe
->generic
, 1);
100 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
102 /* Update the host index before invoking device */
103 host_index
= q
->host_index
;
104 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
108 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
109 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
110 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
111 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
112 readl(q
->phba
->sli4_hba
.WQDBregaddr
); /* Flush */
118 * lpfc_sli4_wq_release - Updates internal hba index for WQ
119 * @q: The Work Queue to operate on.
120 * @index: The index to advance the hba index to.
122 * This routine will update the HBA index of a queue to reflect consumption of
123 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
124 * an entry the host calls this function to update the queue's internal
125 * pointers. This routine returns the number of entries that were consumed by
129 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
131 uint32_t released
= 0;
133 if (q
->hba_index
== index
)
136 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
138 } while (q
->hba_index
!= index
);
143 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
144 * @q: The Mailbox Queue to operate on.
145 * @wqe: The Mailbox Queue Entry to put on the Work queue.
147 * This routine will copy the contents of @mqe to the next available entry on
148 * the @q. This function will then ring the Work Queue Doorbell to signal the
149 * HBA to start processing the Work Queue Entry. This function returns 0 if
150 * successful. If no entries are available on @q then this function will return
152 * The caller is expected to hold the hbalock when calling this routine.
155 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
157 struct lpfc_mqe
*temp_mqe
= q
->qe
[q
->host_index
].mqe
;
158 struct lpfc_register doorbell
;
161 /* If the host has not yet processed the next entry then we are done */
162 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
164 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
165 /* Save off the mailbox pointer for completion */
166 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
168 /* Update the host index before invoking device */
169 host_index
= q
->host_index
;
170 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
174 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
175 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
176 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
177 readl(q
->phba
->sli4_hba
.MQDBregaddr
); /* Flush */
182 * lpfc_sli4_mq_release - Updates internal hba index for MQ
183 * @q: The Mailbox Queue to operate on.
185 * This routine will update the HBA index of a queue to reflect consumption of
186 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
187 * an entry the host calls this function to update the queue's internal
188 * pointers. This routine returns the number of entries that were consumed by
192 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
194 /* Clear the mailbox pointer for completion */
195 q
->phba
->mbox
= NULL
;
196 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
201 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
202 * @q: The Event Queue to get the first valid EQE from
204 * This routine will get the first valid Event Queue Entry from @q, update
205 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
206 * the Queue (no more work to do), or the Queue is full of EQEs that have been
207 * processed, but not popped back to the HBA then this routine will return NULL.
209 static struct lpfc_eqe
*
210 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
212 struct lpfc_eqe
*eqe
= q
->qe
[q
->hba_index
].eqe
;
214 /* If the next EQE is not valid then we are done */
215 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
217 /* If the host has not yet processed the next entry then we are done */
218 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
221 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
226 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
227 * @q: The Event Queue that the host has completed processing for.
228 * @arm: Indicates whether the host wants to arms this CQ.
230 * This routine will mark all Event Queue Entries on @q, from the last
231 * known completed entry to the last entry that was processed, as completed
232 * by clearing the valid bit for each completion queue entry. Then it will
233 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
234 * The internal host index in the @q will be updated by this routine to indicate
235 * that the host has finished processing the entries. The @arm parameter
236 * indicates that the queue should be rearmed when ringing the doorbell.
238 * This function will return the number of EQEs that were popped.
241 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
243 uint32_t released
= 0;
244 struct lpfc_eqe
*temp_eqe
;
245 struct lpfc_register doorbell
;
247 /* while there are valid entries */
248 while (q
->hba_index
!= q
->host_index
) {
249 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
250 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
252 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
254 if (unlikely(released
== 0 && !arm
))
257 /* ring doorbell for number popped */
260 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
261 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
263 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
264 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
265 bf_set(lpfc_eqcq_doorbell_eqid
, &doorbell
, q
->queue_id
);
266 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
267 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
268 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
269 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
274 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
275 * @q: The Completion Queue to get the first valid CQE from
277 * This routine will get the first valid Completion Queue Entry from @q, update
278 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
279 * the Queue (no more work to do), or the Queue is full of CQEs that have been
280 * processed, but not popped back to the HBA then this routine will return NULL.
282 static struct lpfc_cqe
*
283 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
285 struct lpfc_cqe
*cqe
;
287 /* If the next CQE is not valid then we are done */
288 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
290 /* If the host has not yet processed the next entry then we are done */
291 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
294 cqe
= q
->qe
[q
->hba_index
].cqe
;
295 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
300 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
301 * @q: The Completion Queue that the host has completed processing for.
302 * @arm: Indicates whether the host wants to arms this CQ.
304 * This routine will mark all Completion queue entries on @q, from the last
305 * known completed entry to the last entry that was processed, as completed
306 * by clearing the valid bit for each completion queue entry. Then it will
307 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
308 * The internal host index in the @q will be updated by this routine to indicate
309 * that the host has finished processing the entries. The @arm parameter
310 * indicates that the queue should be rearmed when ringing the doorbell.
312 * This function will return the number of CQEs that were released.
315 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
317 uint32_t released
= 0;
318 struct lpfc_cqe
*temp_qe
;
319 struct lpfc_register doorbell
;
321 /* while there are valid entries */
322 while (q
->hba_index
!= q
->host_index
) {
323 temp_qe
= q
->qe
[q
->host_index
].cqe
;
324 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
326 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
328 if (unlikely(released
== 0 && !arm
))
331 /* ring doorbell for number popped */
334 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
335 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
336 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
337 bf_set(lpfc_eqcq_doorbell_cqid
, &doorbell
, q
->queue_id
);
338 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
343 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
344 * @q: The Header Receive Queue to operate on.
345 * @wqe: The Receive Queue Entry to put on the Receive queue.
347 * This routine will copy the contents of @wqe to the next available entry on
348 * the @q. This function will then ring the Receive Queue Doorbell to signal the
349 * HBA to start processing the Receive Queue Entry. This function returns the
350 * index that the rqe was copied to if successful. If no entries are available
351 * on @q then this function will return -ENOMEM.
352 * The caller is expected to hold the hbalock when calling this routine.
355 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
356 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
358 struct lpfc_rqe
*temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
359 struct lpfc_rqe
*temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
360 struct lpfc_register doorbell
;
361 int put_index
= hq
->host_index
;
363 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
365 if (hq
->host_index
!= dq
->host_index
)
367 /* If the host has not yet processed the next entry then we are done */
368 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
370 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
371 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
373 /* Update the host index to point to the next slot */
374 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
375 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
377 /* Ring The Header Receive Queue Doorbell */
378 if (!(hq
->host_index
% LPFC_RQ_POST_BATCH
)) {
380 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
382 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
383 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
389 * lpfc_sli4_rq_release - Updates internal hba index for RQ
390 * @q: The Header Receive Queue to operate on.
392 * This routine will update the HBA index of a queue to reflect consumption of
393 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
394 * consumed an entry the host calls this function to update the queue's
395 * internal pointers. This routine returns the number of entries that were
396 * consumed by the HBA.
399 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
401 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
403 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
404 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
409 * lpfc_cmd_iocb - Get next command iocb entry in the ring
410 * @phba: Pointer to HBA context object.
411 * @pring: Pointer to driver SLI ring object.
413 * This function returns pointer to next command iocb entry
414 * in the command ring. The caller must hold hbalock to prevent
415 * other threads consume the next command iocb.
416 * SLI-2/SLI-3 provide different sized iocbs.
418 static inline IOCB_t
*
419 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
421 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
422 pring
->cmdidx
* phba
->iocb_cmd_size
);
426 * lpfc_resp_iocb - Get next response iocb entry in the ring
427 * @phba: Pointer to HBA context object.
428 * @pring: Pointer to driver SLI ring object.
430 * This function returns pointer to next response iocb entry
431 * in the response ring. The caller must hold hbalock to make sure
432 * that no other thread consume the next response iocb.
433 * SLI-2/SLI-3 provide different sized iocbs.
435 static inline IOCB_t
*
436 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
438 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
439 pring
->rspidx
* phba
->iocb_rsp_size
);
443 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
444 * @phba: Pointer to HBA context object.
446 * This function is called with hbalock held. This function
447 * allocates a new driver iocb object from the iocb pool. If the
448 * allocation is successful, it returns pointer to the newly
449 * allocated iocb object else it returns NULL.
451 static struct lpfc_iocbq
*
452 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
454 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
455 struct lpfc_iocbq
* iocbq
= NULL
;
457 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
462 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
463 * @phba: Pointer to HBA context object.
464 * @xritag: XRI value.
466 * This function clears the sglq pointer from the array of acive
467 * sglq's. The xritag that is passed in is used to index into the
468 * array. Before the xritag can be used it needs to be adjusted
469 * by subtracting the xribase.
471 * Returns sglq ponter = success, NULL = Failure.
473 static struct lpfc_sglq
*
474 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
477 struct lpfc_sglq
*sglq
;
478 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
479 if (adj_xri
> phba
->sli4_hba
.max_cfg_param
.max_xri
)
481 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
];
482 phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
] = NULL
;
487 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
488 * @phba: Pointer to HBA context object.
489 * @xritag: XRI value.
491 * This function returns the sglq pointer from the array of acive
492 * sglq's. The xritag that is passed in is used to index into the
493 * array. Before the xritag can be used it needs to be adjusted
494 * by subtracting the xribase.
496 * Returns sglq ponter = success, NULL = Failure.
499 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
502 struct lpfc_sglq
*sglq
;
503 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
504 if (adj_xri
> phba
->sli4_hba
.max_cfg_param
.max_xri
)
506 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
];
511 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
512 * @phba: Pointer to HBA context object.
514 * This function is called with hbalock held. This function
515 * Gets a new driver sglq object from the sglq list. If the
516 * list is not empty then it is successful, it returns pointer to the newly
517 * allocated sglq object else it returns NULL.
519 static struct lpfc_sglq
*
520 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
)
522 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
523 struct lpfc_sglq
*sglq
= NULL
;
525 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
528 adj_xri
= sglq
->sli4_xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
529 phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
] = sglq
;
530 sglq
->state
= SGL_ALLOCATED
;
535 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
536 * @phba: Pointer to HBA context object.
538 * This function is called with no lock held. This function
539 * allocates a new driver iocb object from the iocb pool. If the
540 * allocation is successful, it returns pointer to the newly
541 * allocated iocb object else it returns NULL.
544 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
546 struct lpfc_iocbq
* iocbq
= NULL
;
547 unsigned long iflags
;
549 spin_lock_irqsave(&phba
->hbalock
, iflags
);
550 iocbq
= __lpfc_sli_get_iocbq(phba
);
551 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
556 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
557 * @phba: Pointer to HBA context object.
558 * @iocbq: Pointer to driver iocb object.
560 * This function is called with hbalock held to release driver
561 * iocb object to the iocb pool. The iotag in the iocb object
562 * does not change for each use of the iocb object. This function
563 * clears all other fields of the iocb object when it is freed.
564 * The sqlq structure that holds the xritag and phys and virtual
565 * mappings for the scatter gather list is retrieved from the
566 * active array of sglq. The get of the sglq pointer also clears
567 * the entry in the array. If the status of the IO indiactes that
568 * this IO was aborted then the sglq entry it put on the
569 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
570 * IO has good status or fails for any other reason then the sglq
571 * entry is added to the free list (lpfc_sgl_list).
574 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
576 struct lpfc_sglq
*sglq
;
577 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
580 if (iocbq
->sli4_xritag
== NO_XRI
)
583 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_xritag
);
585 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
586 (sglq
->state
!= SGL_XRI_ABORTED
)) {
587 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
589 list_add(&sglq
->list
,
590 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
591 spin_unlock_irqrestore(
592 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
594 sglq
->state
= SGL_FREED
;
595 list_add(&sglq
->list
, &phba
->sli4_hba
.lpfc_sgl_list
);
601 * Clean all volatile data fields, preserve iotag and node struct.
603 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
604 iocbq
->sli4_xritag
= NO_XRI
;
605 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
609 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
610 * @phba: Pointer to HBA context object.
611 * @iocbq: Pointer to driver iocb object.
613 * This function is called with hbalock held to release driver
614 * iocb object to the iocb pool. The iotag in the iocb object
615 * does not change for each use of the iocb object. This function
616 * clears all other fields of the iocb object when it is freed.
619 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
621 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
624 * Clean all volatile data fields, preserve iotag and node struct.
626 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
627 iocbq
->sli4_xritag
= NO_XRI
;
628 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
632 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
633 * @phba: Pointer to HBA context object.
634 * @iocbq: Pointer to driver iocb object.
636 * This function is called with hbalock held to release driver
637 * iocb object to the iocb pool. The iotag in the iocb object
638 * does not change for each use of the iocb object. This function
639 * clears all other fields of the iocb object when it is freed.
642 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
644 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
648 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
649 * @phba: Pointer to HBA context object.
650 * @iocbq: Pointer to driver iocb object.
652 * This function is called with no lock held to release the iocb to
656 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
658 unsigned long iflags
;
661 * Clean all volatile data fields, preserve iotag and node struct.
663 spin_lock_irqsave(&phba
->hbalock
, iflags
);
664 __lpfc_sli_release_iocbq(phba
, iocbq
);
665 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
669 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
670 * @phba: Pointer to HBA context object.
671 * @iocblist: List of IOCBs.
672 * @ulpstatus: ULP status in IOCB command field.
673 * @ulpWord4: ULP word-4 in IOCB command field.
675 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
676 * on the list by invoking the complete callback function associated with the
677 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
681 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
682 uint32_t ulpstatus
, uint32_t ulpWord4
)
684 struct lpfc_iocbq
*piocb
;
686 while (!list_empty(iocblist
)) {
687 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
689 if (!piocb
->iocb_cmpl
)
690 lpfc_sli_release_iocbq(phba
, piocb
);
692 piocb
->iocb
.ulpStatus
= ulpstatus
;
693 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
694 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
701 * lpfc_sli_iocb_cmd_type - Get the iocb type
702 * @iocb_cmnd: iocb command code.
704 * This function is called by ring event handler function to get the iocb type.
705 * This function translates the iocb command to an iocb command type used to
706 * decide the final disposition of each completed IOCB.
707 * The function returns
708 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
709 * LPFC_SOL_IOCB if it is a solicited iocb completion
710 * LPFC_ABORT_IOCB if it is an abort iocb
711 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
713 * The caller is not required to hold any lock.
715 static lpfc_iocb_type
716 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
718 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
720 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
724 case CMD_XMIT_SEQUENCE_CR
:
725 case CMD_XMIT_SEQUENCE_CX
:
726 case CMD_XMIT_BCAST_CN
:
727 case CMD_XMIT_BCAST_CX
:
728 case CMD_ELS_REQUEST_CR
:
729 case CMD_ELS_REQUEST_CX
:
730 case CMD_CREATE_XRI_CR
:
731 case CMD_CREATE_XRI_CX
:
733 case CMD_XMIT_ELS_RSP_CX
:
735 case CMD_FCP_IWRITE_CR
:
736 case CMD_FCP_IWRITE_CX
:
737 case CMD_FCP_IREAD_CR
:
738 case CMD_FCP_IREAD_CX
:
739 case CMD_FCP_ICMND_CR
:
740 case CMD_FCP_ICMND_CX
:
741 case CMD_FCP_TSEND_CX
:
742 case CMD_FCP_TRSP_CX
:
743 case CMD_FCP_TRECEIVE_CX
:
744 case CMD_FCP_AUTO_TRSP_CX
:
745 case CMD_ADAPTER_MSG
:
746 case CMD_ADAPTER_DUMP
:
747 case CMD_XMIT_SEQUENCE64_CR
:
748 case CMD_XMIT_SEQUENCE64_CX
:
749 case CMD_XMIT_BCAST64_CN
:
750 case CMD_XMIT_BCAST64_CX
:
751 case CMD_ELS_REQUEST64_CR
:
752 case CMD_ELS_REQUEST64_CX
:
753 case CMD_FCP_IWRITE64_CR
:
754 case CMD_FCP_IWRITE64_CX
:
755 case CMD_FCP_IREAD64_CR
:
756 case CMD_FCP_IREAD64_CX
:
757 case CMD_FCP_ICMND64_CR
:
758 case CMD_FCP_ICMND64_CX
:
759 case CMD_FCP_TSEND64_CX
:
760 case CMD_FCP_TRSP64_CX
:
761 case CMD_FCP_TRECEIVE64_CX
:
762 case CMD_GEN_REQUEST64_CR
:
763 case CMD_GEN_REQUEST64_CX
:
764 case CMD_XMIT_ELS_RSP64_CX
:
765 case DSSCMD_IWRITE64_CR
:
766 case DSSCMD_IWRITE64_CX
:
767 case DSSCMD_IREAD64_CR
:
768 case DSSCMD_IREAD64_CX
:
769 type
= LPFC_SOL_IOCB
;
771 case CMD_ABORT_XRI_CN
:
772 case CMD_ABORT_XRI_CX
:
773 case CMD_CLOSE_XRI_CN
:
774 case CMD_CLOSE_XRI_CX
:
775 case CMD_XRI_ABORTED_CX
:
776 case CMD_ABORT_MXRI64_CN
:
777 case CMD_XMIT_BLS_RSP64_CX
:
778 type
= LPFC_ABORT_IOCB
;
780 case CMD_RCV_SEQUENCE_CX
:
781 case CMD_RCV_ELS_REQ_CX
:
782 case CMD_RCV_SEQUENCE64_CX
:
783 case CMD_RCV_ELS_REQ64_CX
:
784 case CMD_ASYNC_STATUS
:
785 case CMD_IOCB_RCV_SEQ64_CX
:
786 case CMD_IOCB_RCV_ELS64_CX
:
787 case CMD_IOCB_RCV_CONT64_CX
:
788 case CMD_IOCB_RET_XRI64_CX
:
789 type
= LPFC_UNSOL_IOCB
;
791 case CMD_IOCB_XMIT_MSEQ64_CR
:
792 case CMD_IOCB_XMIT_MSEQ64_CX
:
793 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
794 case CMD_IOCB_RCV_ELS_LIST64_CX
:
795 case CMD_IOCB_CLOSE_EXTENDED_CN
:
796 case CMD_IOCB_ABORT_EXTENDED_CN
:
797 case CMD_IOCB_RET_HBQE64_CN
:
798 case CMD_IOCB_FCP_IBIDIR64_CR
:
799 case CMD_IOCB_FCP_IBIDIR64_CX
:
800 case CMD_IOCB_FCP_ITASKMGT64_CX
:
801 case CMD_IOCB_LOGENTRY_CN
:
802 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
803 printk("%s - Unhandled SLI-3 Command x%x\n",
804 __func__
, iocb_cmnd
);
805 type
= LPFC_UNKNOWN_IOCB
;
808 type
= LPFC_UNKNOWN_IOCB
;
816 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
817 * @phba: Pointer to HBA context object.
819 * This function is called from SLI initialization code
820 * to configure every ring of the HBA's SLI interface. The
821 * caller is not required to hold any lock. This function issues
822 * a config_ring mailbox command for each ring.
823 * This function returns zero if successful else returns a negative
827 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
829 struct lpfc_sli
*psli
= &phba
->sli
;
834 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
838 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
839 for (i
= 0; i
< psli
->num_rings
; i
++) {
840 lpfc_config_ring(phba
, i
, pmb
);
841 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
842 if (rc
!= MBX_SUCCESS
) {
843 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
844 "0446 Adapter failed to init (%d), "
845 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
847 rc
, pmbox
->mbxCommand
,
848 pmbox
->mbxStatus
, i
);
849 phba
->link_state
= LPFC_HBA_ERROR
;
854 mempool_free(pmb
, phba
->mbox_mem_pool
);
859 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
860 * @phba: Pointer to HBA context object.
861 * @pring: Pointer to driver SLI ring object.
862 * @piocb: Pointer to the driver iocb object.
864 * This function is called with hbalock held. The function adds the
865 * new iocb to txcmplq of the given ring. This function always returns
866 * 0. If this function is called for ELS ring, this function checks if
867 * there is a vport associated with the ELS command. This function also
868 * starts els_tmofunc timer if this is an ELS command.
871 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
872 struct lpfc_iocbq
*piocb
)
874 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
875 pring
->txcmplq_cnt
++;
876 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
877 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
878 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
882 mod_timer(&piocb
->vport
->els_tmofunc
,
883 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
891 * lpfc_sli_ringtx_get - Get first element of the txq
892 * @phba: Pointer to HBA context object.
893 * @pring: Pointer to driver SLI ring object.
895 * This function is called with hbalock held to get next
896 * iocb in txq of the given ring. If there is any iocb in
897 * the txq, the function returns first iocb in the list after
898 * removing the iocb from the list, else it returns NULL.
900 static struct lpfc_iocbq
*
901 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
903 struct lpfc_iocbq
*cmd_iocb
;
905 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
906 if (cmd_iocb
!= NULL
)
912 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
913 * @phba: Pointer to HBA context object.
914 * @pring: Pointer to driver SLI ring object.
916 * This function is called with hbalock held and the caller must post the
917 * iocb without releasing the lock. If the caller releases the lock,
918 * iocb slot returned by the function is not guaranteed to be available.
919 * The function returns pointer to the next available iocb slot if there
920 * is available slot in the ring, else it returns NULL.
921 * If the get index of the ring is ahead of the put index, the function
922 * will post an error attention event to the worker thread to take the
923 * HBA to offline state.
926 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
928 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
929 uint32_t max_cmd_idx
= pring
->numCiocb
;
930 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
931 (++pring
->next_cmdidx
>= max_cmd_idx
))
932 pring
->next_cmdidx
= 0;
934 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
936 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
938 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
939 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
940 "0315 Ring %d issue: portCmdGet %d "
941 "is bigger than cmd ring %d\n",
943 pring
->local_getidx
, max_cmd_idx
);
945 phba
->link_state
= LPFC_HBA_ERROR
;
947 * All error attention handlers are posted to
950 phba
->work_ha
|= HA_ERATT
;
951 phba
->work_hs
= HS_FFER3
;
953 lpfc_worker_wake_up(phba
);
958 if (pring
->local_getidx
== pring
->next_cmdidx
)
962 return lpfc_cmd_iocb(phba
, pring
);
966 * lpfc_sli_next_iotag - Get an iotag for the iocb
967 * @phba: Pointer to HBA context object.
968 * @iocbq: Pointer to driver iocb object.
970 * This function gets an iotag for the iocb. If there is no unused iotag and
971 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
972 * array and assigns a new iotag.
973 * The function returns the allocated iotag if successful, else returns zero.
974 * Zero is not a valid iotag.
975 * The caller is not required to hold any lock.
978 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
980 struct lpfc_iocbq
**new_arr
;
981 struct lpfc_iocbq
**old_arr
;
983 struct lpfc_sli
*psli
= &phba
->sli
;
986 spin_lock_irq(&phba
->hbalock
);
987 iotag
= psli
->last_iotag
;
988 if(++iotag
< psli
->iocbq_lookup_len
) {
989 psli
->last_iotag
= iotag
;
990 psli
->iocbq_lookup
[iotag
] = iocbq
;
991 spin_unlock_irq(&phba
->hbalock
);
992 iocbq
->iotag
= iotag
;
994 } else if (psli
->iocbq_lookup_len
< (0xffff
995 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
996 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
997 spin_unlock_irq(&phba
->hbalock
);
998 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1001 spin_lock_irq(&phba
->hbalock
);
1002 old_arr
= psli
->iocbq_lookup
;
1003 if (new_len
<= psli
->iocbq_lookup_len
) {
1004 /* highly unprobable case */
1006 iotag
= psli
->last_iotag
;
1007 if(++iotag
< psli
->iocbq_lookup_len
) {
1008 psli
->last_iotag
= iotag
;
1009 psli
->iocbq_lookup
[iotag
] = iocbq
;
1010 spin_unlock_irq(&phba
->hbalock
);
1011 iocbq
->iotag
= iotag
;
1014 spin_unlock_irq(&phba
->hbalock
);
1017 if (psli
->iocbq_lookup
)
1018 memcpy(new_arr
, old_arr
,
1019 ((psli
->last_iotag
+ 1) *
1020 sizeof (struct lpfc_iocbq
*)));
1021 psli
->iocbq_lookup
= new_arr
;
1022 psli
->iocbq_lookup_len
= new_len
;
1023 psli
->last_iotag
= iotag
;
1024 psli
->iocbq_lookup
[iotag
] = iocbq
;
1025 spin_unlock_irq(&phba
->hbalock
);
1026 iocbq
->iotag
= iotag
;
1031 spin_unlock_irq(&phba
->hbalock
);
1033 lpfc_printf_log(phba
, KERN_ERR
,LOG_SLI
,
1034 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1041 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1042 * @phba: Pointer to HBA context object.
1043 * @pring: Pointer to driver SLI ring object.
1044 * @iocb: Pointer to iocb slot in the ring.
1045 * @nextiocb: Pointer to driver iocb object which need to be
1046 * posted to firmware.
1048 * This function is called with hbalock held to post a new iocb to
1049 * the firmware. This function copies the new iocb to ring iocb slot and
1050 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1051 * a completion call back for this iocb else the function will free the
1055 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1056 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1061 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1064 if (pring
->ringno
== LPFC_ELS_RING
) {
1065 lpfc_debugfs_slow_ring_trc(phba
,
1066 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1067 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1068 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1069 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1073 * Issue iocb command to adapter
1075 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1077 pring
->stats
.iocb_cmd
++;
1080 * If there is no completion routine to call, we can release the
1081 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1082 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1084 if (nextiocb
->iocb_cmpl
)
1085 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1087 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1090 * Let the HBA know what IOCB slot will be the next one the
1091 * driver will put a command into.
1093 pring
->cmdidx
= pring
->next_cmdidx
;
1094 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1098 * lpfc_sli_update_full_ring - Update the chip attention register
1099 * @phba: Pointer to HBA context object.
1100 * @pring: Pointer to driver SLI ring object.
1102 * The caller is not required to hold any lock for calling this function.
1103 * This function updates the chip attention bits for the ring to inform firmware
1104 * that there are pending work to be done for this ring and requests an
1105 * interrupt when there is space available in the ring. This function is
1106 * called when the driver is unable to post more iocbs to the ring due
1107 * to unavailability of space in the ring.
1110 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1112 int ringno
= pring
->ringno
;
1114 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1119 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1120 * The HBA will tell us when an IOCB entry is available.
1122 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1123 readl(phba
->CAregaddr
); /* flush */
1125 pring
->stats
.iocb_cmd_full
++;
1129 * lpfc_sli_update_ring - Update chip attention register
1130 * @phba: Pointer to HBA context object.
1131 * @pring: Pointer to driver SLI ring object.
1133 * This function updates the chip attention register bit for the
1134 * given ring to inform HBA that there is more work to be done
1135 * in this ring. The caller is not required to hold any lock.
1138 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1140 int ringno
= pring
->ringno
;
1143 * Tell the HBA that there is work to do in this ring.
1145 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1147 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1148 readl(phba
->CAregaddr
); /* flush */
1153 * lpfc_sli_resume_iocb - Process iocbs in the txq
1154 * @phba: Pointer to HBA context object.
1155 * @pring: Pointer to driver SLI ring object.
1157 * This function is called with hbalock held to post pending iocbs
1158 * in the txq to the firmware. This function is called when driver
1159 * detects space available in the ring.
1162 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1165 struct lpfc_iocbq
*nextiocb
;
1169 * (a) there is anything on the txq to send
1171 * (c) link attention events can be processed (fcp ring only)
1172 * (d) IOCB processing is not blocked by the outstanding mbox command.
1174 if (pring
->txq_cnt
&&
1175 lpfc_is_link_up(phba
) &&
1176 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1177 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1179 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1180 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1181 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1184 lpfc_sli_update_ring(phba
, pring
);
1186 lpfc_sli_update_full_ring(phba
, pring
);
1193 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1194 * @phba: Pointer to HBA context object.
1195 * @hbqno: HBQ number.
1197 * This function is called with hbalock held to get the next
1198 * available slot for the given HBQ. If there is free slot
1199 * available for the HBQ it will return pointer to the next available
1200 * HBQ entry else it will return NULL.
1202 static struct lpfc_hbq_entry
*
1203 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1205 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1207 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1208 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1209 hbqp
->next_hbqPutIdx
= 0;
1211 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1212 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1213 uint32_t getidx
= le32_to_cpu(raw_index
);
1215 hbqp
->local_hbqGetIdx
= getidx
;
1217 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1218 lpfc_printf_log(phba
, KERN_ERR
,
1219 LOG_SLI
| LOG_VPORT
,
1220 "1802 HBQ %d: local_hbqGetIdx "
1221 "%u is > than hbqp->entry_count %u\n",
1222 hbqno
, hbqp
->local_hbqGetIdx
,
1225 phba
->link_state
= LPFC_HBA_ERROR
;
1229 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1233 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1238 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1239 * @phba: Pointer to HBA context object.
1241 * This function is called with no lock held to free all the
1242 * hbq buffers while uninitializing the SLI interface. It also
1243 * frees the HBQ buffers returned by the firmware but not yet
1244 * processed by the upper layers.
1247 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1249 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1250 struct hbq_dmabuf
*hbq_buf
;
1251 unsigned long flags
;
1255 hbq_count
= lpfc_sli_hbq_count();
1256 /* Return all memory used by all HBQs */
1257 spin_lock_irqsave(&phba
->hbalock
, flags
);
1258 for (i
= 0; i
< hbq_count
; ++i
) {
1259 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1260 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1261 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1262 list_del(&hbq_buf
->dbuf
.list
);
1263 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1265 phba
->hbqs
[i
].buffer_count
= 0;
1267 /* Return all HBQ buffer that are in-fly */
1268 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1270 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1271 list_del(&hbq_buf
->dbuf
.list
);
1272 if (hbq_buf
->tag
== -1) {
1273 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1276 hbqno
= hbq_buf
->tag
>> 16;
1277 if (hbqno
>= LPFC_MAX_HBQS
)
1278 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1281 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1286 /* Mark the HBQs not in use */
1287 phba
->hbq_in_use
= 0;
1288 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1292 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1293 * @phba: Pointer to HBA context object.
1294 * @hbqno: HBQ number.
1295 * @hbq_buf: Pointer to HBQ buffer.
1297 * This function is called with the hbalock held to post a
1298 * hbq buffer to the firmware. If the function finds an empty
1299 * slot in the HBQ, it will post the buffer. The function will return
1300 * pointer to the hbq entry if it successfully post the buffer
1301 * else it will return NULL.
1304 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1305 struct hbq_dmabuf
*hbq_buf
)
1307 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1311 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1312 * @phba: Pointer to HBA context object.
1313 * @hbqno: HBQ number.
1314 * @hbq_buf: Pointer to HBQ buffer.
1316 * This function is called with the hbalock held to post a hbq buffer to the
1317 * firmware. If the function finds an empty slot in the HBQ, it will post the
1318 * buffer and place it on the hbq_buffer_list. The function will return zero if
1319 * it successfully post the buffer else it will return an error.
1322 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1323 struct hbq_dmabuf
*hbq_buf
)
1325 struct lpfc_hbq_entry
*hbqe
;
1326 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1328 /* Get next HBQ entry slot to use */
1329 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1331 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1333 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1334 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1335 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1336 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1337 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1338 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1340 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1341 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1343 readl(phba
->hbq_put
+ hbqno
);
1344 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1351 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1352 * @phba: Pointer to HBA context object.
1353 * @hbqno: HBQ number.
1354 * @hbq_buf: Pointer to HBQ buffer.
1356 * This function is called with the hbalock held to post an RQE to the SLI4
1357 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1358 * the hbq_buffer_list and return zero, otherwise it will return an error.
1361 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1362 struct hbq_dmabuf
*hbq_buf
)
1365 struct lpfc_rqe hrqe
;
1366 struct lpfc_rqe drqe
;
1368 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1369 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1370 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1371 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1372 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1377 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1381 /* HBQ for ELS and CT traffic. */
1382 static struct lpfc_hbq_init lpfc_els_hbq
= {
1387 .ring_mask
= (1 << LPFC_ELS_RING
),
1393 /* HBQ for the extra ring if needed */
1394 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1399 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1406 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1412 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1413 * @phba: Pointer to HBA context object.
1414 * @hbqno: HBQ number.
1415 * @count: Number of HBQ buffers to be posted.
1417 * This function is called with no lock held to post more hbq buffers to the
1418 * given HBQ. The function returns the number of HBQ buffers successfully
1422 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1424 uint32_t i
, posted
= 0;
1425 unsigned long flags
;
1426 struct hbq_dmabuf
*hbq_buffer
;
1427 LIST_HEAD(hbq_buf_list
);
1428 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1431 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1432 lpfc_hbq_defs
[hbqno
]->entry_count
)
1433 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1434 phba
->hbqs
[hbqno
].buffer_count
;
1437 /* Allocate HBQ entries */
1438 for (i
= 0; i
< count
; i
++) {
1439 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1442 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1444 /* Check whether HBQ is still in use */
1445 spin_lock_irqsave(&phba
->hbalock
, flags
);
1446 if (!phba
->hbq_in_use
)
1448 while (!list_empty(&hbq_buf_list
)) {
1449 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1451 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1453 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1454 phba
->hbqs
[hbqno
].buffer_count
++;
1457 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1459 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1462 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1463 while (!list_empty(&hbq_buf_list
)) {
1464 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1466 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1472 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1473 * @phba: Pointer to HBA context object.
1476 * This function posts more buffers to the HBQ. This function
1477 * is called with no lock held. The function returns the number of HBQ entries
1478 * successfully allocated.
1481 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1483 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1486 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1487 lpfc_hbq_defs
[qno
]->add_count
);
1491 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1492 * @phba: Pointer to HBA context object.
1493 * @qno: HBQ queue number.
1495 * This function is called from SLI initialization code path with
1496 * no lock held to post initial HBQ buffers to firmware. The
1497 * function returns the number of HBQ entries successfully allocated.
1500 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1502 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1503 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1504 lpfc_hbq_defs
[qno
]->entry_count
);
1506 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1507 lpfc_hbq_defs
[qno
]->init_count
);
1511 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1512 * @phba: Pointer to HBA context object.
1513 * @hbqno: HBQ number.
1515 * This function removes the first hbq buffer on an hbq list and returns a
1516 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1518 static struct hbq_dmabuf
*
1519 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1521 struct lpfc_dmabuf
*d_buf
;
1523 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1526 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1530 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1531 * @phba: Pointer to HBA context object.
1532 * @tag: Tag of the hbq buffer.
1534 * This function is called with hbalock held. This function searches
1535 * for the hbq buffer associated with the given tag in the hbq buffer
1536 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1539 static struct hbq_dmabuf
*
1540 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1542 struct lpfc_dmabuf
*d_buf
;
1543 struct hbq_dmabuf
*hbq_buf
;
1547 if (hbqno
>= LPFC_MAX_HBQS
)
1550 spin_lock_irq(&phba
->hbalock
);
1551 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1552 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1553 if (hbq_buf
->tag
== tag
) {
1554 spin_unlock_irq(&phba
->hbalock
);
1558 spin_unlock_irq(&phba
->hbalock
);
1559 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1560 "1803 Bad hbq tag. Data: x%x x%x\n",
1561 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1566 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1567 * @phba: Pointer to HBA context object.
1568 * @hbq_buffer: Pointer to HBQ buffer.
1570 * This function is called with hbalock. This function gives back
1571 * the hbq buffer to firmware. If the HBQ does not have space to
1572 * post the buffer, it will free the buffer.
1575 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1580 hbqno
= hbq_buffer
->tag
>> 16;
1581 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1582 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1587 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1588 * @mbxCommand: mailbox command code.
1590 * This function is called by the mailbox event handler function to verify
1591 * that the completed mailbox command is a legitimate mailbox command. If the
1592 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1593 * and the mailbox event handler will take the HBA offline.
1596 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
1600 switch (mbxCommand
) {
1604 case MBX_WRITE_VPARMS
:
1605 case MBX_RUN_BIU_DIAG
:
1608 case MBX_CONFIG_LINK
:
1609 case MBX_CONFIG_RING
:
1610 case MBX_RESET_RING
:
1611 case MBX_READ_CONFIG
:
1612 case MBX_READ_RCONFIG
:
1613 case MBX_READ_SPARM
:
1614 case MBX_READ_STATUS
:
1618 case MBX_READ_LNK_STAT
:
1620 case MBX_UNREG_LOGIN
:
1623 case MBX_DUMP_MEMORY
:
1624 case MBX_DUMP_CONTEXT
:
1627 case MBX_UPDATE_CFG
:
1629 case MBX_DEL_LD_ENTRY
:
1630 case MBX_RUN_PROGRAM
:
1632 case MBX_SET_VARIABLE
:
1633 case MBX_UNREG_D_ID
:
1634 case MBX_KILL_BOARD
:
1635 case MBX_CONFIG_FARP
:
1638 case MBX_RUN_BIU_DIAG64
:
1639 case MBX_CONFIG_PORT
:
1640 case MBX_READ_SPARM64
:
1641 case MBX_READ_RPI64
:
1642 case MBX_REG_LOGIN64
:
1646 case MBX_LOAD_EXP_ROM
:
1647 case MBX_ASYNCEVT_ENABLE
:
1651 case MBX_PORT_CAPABILITIES
:
1652 case MBX_PORT_IOV_CONTROL
:
1653 case MBX_SLI4_CONFIG
:
1654 case MBX_SLI4_REQ_FTRS
:
1656 case MBX_UNREG_FCFI
:
1661 case MBX_RESUME_RPI
:
1662 case MBX_READ_EVENT_LOG_STATUS
:
1663 case MBX_READ_EVENT_LOG
:
1674 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
1675 * @phba: Pointer to HBA context object.
1676 * @pmboxq: Pointer to mailbox command.
1678 * This is completion handler function for mailbox commands issued from
1679 * lpfc_sli_issue_mbox_wait function. This function is called by the
1680 * mailbox event handler function with no lock held. This function
1681 * will wake up thread waiting on the wait queue pointed by context1
1685 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
1687 wait_queue_head_t
*pdone_q
;
1688 unsigned long drvr_flag
;
1691 * If pdone_q is empty, the driver thread gave up waiting and
1692 * continued running.
1694 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
1695 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1696 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
1698 wake_up_interruptible(pdone_q
);
1699 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1705 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
1706 * @phba: Pointer to HBA context object.
1707 * @pmb: Pointer to mailbox object.
1709 * This function is the default mailbox completion handler. It
1710 * frees the memory resources associated with the completed mailbox
1711 * command. If the completed command is a REG_LOGIN mailbox command,
1712 * this function will issue a UREG_LOGIN to re-claim the RPI.
1715 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1717 struct lpfc_dmabuf
*mp
;
1720 struct lpfc_vport
*vport
= pmb
->vport
;
1722 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1725 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1729 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
1730 (phba
->sli_rev
== LPFC_SLI_REV4
))
1731 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
1734 * If a REG_LOGIN succeeded after node is destroyed or node
1735 * is in re-discovery driver need to cleanup the RPI.
1737 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1738 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
1739 !pmb
->u
.mb
.mbxStatus
) {
1740 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1741 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
- phba
->vpi_base
;
1742 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
1743 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1744 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1745 if (rc
!= MBX_NOT_FINISHED
)
1749 /* Unreg VPI, if the REG_VPI succeed after VLink failure */
1750 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
1751 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1752 !pmb
->u
.mb
.mbxStatus
) {
1753 lpfc_unreg_vpi(phba
, pmb
->u
.mb
.un
.varRegVpi
.vpi
, pmb
);
1755 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1756 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1757 if (rc
!= MBX_NOT_FINISHED
)
1761 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
1762 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
1764 mempool_free(pmb
, phba
->mbox_mem_pool
);
1768 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
1769 * @phba: Pointer to HBA context object.
1771 * This function is called with no lock held. This function processes all
1772 * the completed mailbox commands and gives it to upper layers. The interrupt
1773 * service routine processes mailbox completion interrupt and adds completed
1774 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1775 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1776 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1777 * function returns the mailbox commands to the upper layer by calling the
1778 * completion handler function of each mailbox.
1781 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
1788 phba
->sli
.slistat
.mbox_event
++;
1790 /* Get all completed mailboxe buffers into the cmplq */
1791 spin_lock_irq(&phba
->hbalock
);
1792 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
1793 spin_unlock_irq(&phba
->hbalock
);
1795 /* Get a Mailbox buffer to setup mailbox commands for callback */
1797 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
1803 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
1805 lpfc_debugfs_disc_trc(pmb
->vport
,
1806 LPFC_DISC_TRC_MBOX_VPORT
,
1807 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1808 (uint32_t)pmbox
->mbxCommand
,
1809 pmbox
->un
.varWords
[0],
1810 pmbox
->un
.varWords
[1]);
1813 lpfc_debugfs_disc_trc(phba
->pport
,
1815 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1816 (uint32_t)pmbox
->mbxCommand
,
1817 pmbox
->un
.varWords
[0],
1818 pmbox
->un
.varWords
[1]);
1823 * It is a fatal error if unknown mbox command completion.
1825 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
1827 /* Unknown mailbox command compl */
1828 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
1829 "(%d):0323 Unknown Mailbox command "
1831 pmb
->vport
? pmb
->vport
->vpi
: 0,
1833 lpfc_sli4_mbox_opcode_get(phba
, pmb
));
1834 phba
->link_state
= LPFC_HBA_ERROR
;
1835 phba
->work_hs
= HS_FFER3
;
1836 lpfc_handle_eratt(phba
);
1840 if (pmbox
->mbxStatus
) {
1841 phba
->sli
.slistat
.mbox_stat_err
++;
1842 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
1843 /* Mbox cmd cmpl error - RETRYing */
1844 lpfc_printf_log(phba
, KERN_INFO
,
1846 "(%d):0305 Mbox cmd cmpl "
1847 "error - RETRYing Data: x%x "
1848 "(x%x) x%x x%x x%x\n",
1849 pmb
->vport
? pmb
->vport
->vpi
:0,
1851 lpfc_sli4_mbox_opcode_get(phba
,
1854 pmbox
->un
.varWords
[0],
1855 pmb
->vport
->port_state
);
1856 pmbox
->mbxStatus
= 0;
1857 pmbox
->mbxOwner
= OWN_HOST
;
1858 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1859 if (rc
!= MBX_NOT_FINISHED
)
1864 /* Mailbox cmd <cmd> Cmpl <cmpl> */
1865 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
1866 "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
1867 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1868 pmb
->vport
? pmb
->vport
->vpi
: 0,
1870 lpfc_sli4_mbox_opcode_get(phba
, pmb
),
1872 *((uint32_t *) pmbox
),
1873 pmbox
->un
.varWords
[0],
1874 pmbox
->un
.varWords
[1],
1875 pmbox
->un
.varWords
[2],
1876 pmbox
->un
.varWords
[3],
1877 pmbox
->un
.varWords
[4],
1878 pmbox
->un
.varWords
[5],
1879 pmbox
->un
.varWords
[6],
1880 pmbox
->un
.varWords
[7]);
1883 pmb
->mbox_cmpl(phba
,pmb
);
1889 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
1890 * @phba: Pointer to HBA context object.
1891 * @pring: Pointer to driver SLI ring object.
1894 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1895 * is set in the tag the buffer is posted for a particular exchange,
1896 * the function will return the buffer without replacing the buffer.
1897 * If the buffer is for unsolicited ELS or CT traffic, this function
1898 * returns the buffer and also posts another buffer to the firmware.
1900 static struct lpfc_dmabuf
*
1901 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
1902 struct lpfc_sli_ring
*pring
,
1905 struct hbq_dmabuf
*hbq_entry
;
1907 if (tag
& QUE_BUFTAG_BIT
)
1908 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
1909 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
1912 return &hbq_entry
->dbuf
;
1916 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
1917 * @phba: Pointer to HBA context object.
1918 * @pring: Pointer to driver SLI ring object.
1919 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
1920 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
1921 * @fch_type: the type for the first frame of the sequence.
1923 * This function is called with no lock held. This function uses the r_ctl and
1924 * type of the received sequence to find the correct callback function to call
1925 * to process the sequence.
1928 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1929 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
1934 /* unSolicited Responses */
1935 if (pring
->prt
[0].profile
) {
1936 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
1937 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
1941 /* We must search, based on rctl / type
1942 for the right routine */
1943 for (i
= 0; i
< pring
->num_mask
; i
++) {
1944 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
1945 (pring
->prt
[i
].type
== fch_type
)) {
1946 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1947 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1948 (phba
, pring
, saveq
);
1956 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
1957 * @phba: Pointer to HBA context object.
1958 * @pring: Pointer to driver SLI ring object.
1959 * @saveq: Pointer to the unsolicited iocb.
1961 * This function is called with no lock held by the ring event handler
1962 * when there is an unsolicited iocb posted to the response ring by the
1963 * firmware. This function gets the buffer associated with the iocbs
1964 * and calls the event handler for the ring. This function handles both
1965 * qring buffers and hbq buffers.
1966 * When the function returns 1 the caller can free the iocb object otherwise
1967 * upper layer functions will free the iocb objects.
1970 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1971 struct lpfc_iocbq
*saveq
)
1975 uint32_t Rctl
, Type
;
1977 struct lpfc_iocbq
*iocbq
;
1978 struct lpfc_dmabuf
*dmzbuf
;
1981 irsp
= &(saveq
->iocb
);
1983 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
1984 if (pring
->lpfc_sli_rcv_async_status
)
1985 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
1987 lpfc_printf_log(phba
,
1990 "0316 Ring %d handler: unexpected "
1991 "ASYNC_STATUS iocb received evt_code "
1994 irsp
->un
.asyncstat
.evt_code
);
1998 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
1999 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2000 if (irsp
->ulpBdeCount
> 0) {
2001 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2002 irsp
->un
.ulpWord
[3]);
2003 lpfc_in_buf_free(phba
, dmzbuf
);
2006 if (irsp
->ulpBdeCount
> 1) {
2007 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2008 irsp
->unsli3
.sli3Words
[3]);
2009 lpfc_in_buf_free(phba
, dmzbuf
);
2012 if (irsp
->ulpBdeCount
> 2) {
2013 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2014 irsp
->unsli3
.sli3Words
[7]);
2015 lpfc_in_buf_free(phba
, dmzbuf
);
2021 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2022 if (irsp
->ulpBdeCount
!= 0) {
2023 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2024 irsp
->un
.ulpWord
[3]);
2025 if (!saveq
->context2
)
2026 lpfc_printf_log(phba
,
2029 "0341 Ring %d Cannot find buffer for "
2030 "an unsolicited iocb. tag 0x%x\n",
2032 irsp
->un
.ulpWord
[3]);
2034 if (irsp
->ulpBdeCount
== 2) {
2035 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2036 irsp
->unsli3
.sli3Words
[7]);
2037 if (!saveq
->context3
)
2038 lpfc_printf_log(phba
,
2041 "0342 Ring %d Cannot find buffer for an"
2042 " unsolicited iocb. tag 0x%x\n",
2044 irsp
->unsli3
.sli3Words
[7]);
2046 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2047 irsp
= &(iocbq
->iocb
);
2048 if (irsp
->ulpBdeCount
!= 0) {
2049 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2050 irsp
->un
.ulpWord
[3]);
2051 if (!iocbq
->context2
)
2052 lpfc_printf_log(phba
,
2055 "0343 Ring %d Cannot find "
2056 "buffer for an unsolicited iocb"
2057 ". tag 0x%x\n", pring
->ringno
,
2058 irsp
->un
.ulpWord
[3]);
2060 if (irsp
->ulpBdeCount
== 2) {
2061 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2062 irsp
->unsli3
.sli3Words
[7]);
2063 if (!iocbq
->context3
)
2064 lpfc_printf_log(phba
,
2067 "0344 Ring %d Cannot find "
2068 "buffer for an unsolicited "
2071 irsp
->unsli3
.sli3Words
[7]);
2075 if (irsp
->ulpBdeCount
!= 0 &&
2076 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2077 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2080 /* search continue save q for same XRI */
2081 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2082 if (iocbq
->iocb
.ulpContext
== saveq
->iocb
.ulpContext
) {
2083 list_add_tail(&saveq
->list
, &iocbq
->list
);
2089 list_add_tail(&saveq
->clist
,
2090 &pring
->iocb_continue_saveq
);
2091 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2092 list_del_init(&iocbq
->clist
);
2094 irsp
= &(saveq
->iocb
);
2098 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2099 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2100 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2101 Rctl
= FC_RCTL_ELS_REQ
;
2104 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2105 Rctl
= w5p
->hcsw
.Rctl
;
2106 Type
= w5p
->hcsw
.Type
;
2108 /* Firmware Workaround */
2109 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2110 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2111 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2112 Rctl
= FC_RCTL_ELS_REQ
;
2114 w5p
->hcsw
.Rctl
= Rctl
;
2115 w5p
->hcsw
.Type
= Type
;
2119 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2120 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2121 "0313 Ring %d handler: unexpected Rctl x%x "
2122 "Type x%x received\n",
2123 pring
->ringno
, Rctl
, Type
);
2129 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2130 * @phba: Pointer to HBA context object.
2131 * @pring: Pointer to driver SLI ring object.
2132 * @prspiocb: Pointer to response iocb object.
2134 * This function looks up the iocb_lookup table to get the command iocb
2135 * corresponding to the given response iocb using the iotag of the
2136 * response iocb. This function is called with the hbalock held.
2137 * This function returns the command iocb object if it finds the command
2138 * iocb else returns NULL.
2140 static struct lpfc_iocbq
*
2141 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2142 struct lpfc_sli_ring
*pring
,
2143 struct lpfc_iocbq
*prspiocb
)
2145 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2148 iotag
= prspiocb
->iocb
.ulpIoTag
;
2150 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2151 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2152 list_del_init(&cmd_iocb
->list
);
2153 pring
->txcmplq_cnt
--;
2157 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2158 "0317 iotag x%x is out off "
2159 "range: max iotag x%x wd0 x%x\n",
2160 iotag
, phba
->sli
.last_iotag
,
2161 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2166 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2167 * @phba: Pointer to HBA context object.
2168 * @pring: Pointer to driver SLI ring object.
2171 * This function looks up the iocb_lookup table to get the command iocb
2172 * corresponding to the given iotag. This function is called with the
2174 * This function returns the command iocb object if it finds the command
2175 * iocb else returns NULL.
2177 static struct lpfc_iocbq
*
2178 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2179 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2181 struct lpfc_iocbq
*cmd_iocb
;
2183 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2184 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2185 list_del_init(&cmd_iocb
->list
);
2186 pring
->txcmplq_cnt
--;
2190 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2191 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2192 iotag
, phba
->sli
.last_iotag
);
2197 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2198 * @phba: Pointer to HBA context object.
2199 * @pring: Pointer to driver SLI ring object.
2200 * @saveq: Pointer to the response iocb to be processed.
2202 * This function is called by the ring event handler for non-fcp
2203 * rings when there is a new response iocb in the response ring.
2204 * The caller is not required to hold any locks. This function
2205 * gets the command iocb associated with the response iocb and
2206 * calls the completion handler for the command iocb. If there
2207 * is no completion handler, the function will free the resources
2208 * associated with command iocb. If the response iocb is for
2209 * an already aborted command iocb, the status of the completion
2210 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2211 * This function always returns 1.
2214 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2215 struct lpfc_iocbq
*saveq
)
2217 struct lpfc_iocbq
*cmdiocbp
;
2219 unsigned long iflag
;
2221 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2222 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2223 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2224 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2227 if (cmdiocbp
->iocb_cmpl
) {
2229 * If an ELS command failed send an event to mgmt
2232 if (saveq
->iocb
.ulpStatus
&&
2233 (pring
->ringno
== LPFC_ELS_RING
) &&
2234 (cmdiocbp
->iocb
.ulpCommand
==
2235 CMD_ELS_REQUEST64_CR
))
2236 lpfc_send_els_failure_event(phba
,
2240 * Post all ELS completions to the worker thread.
2241 * All other are passed to the completion callback.
2243 if (pring
->ringno
== LPFC_ELS_RING
) {
2244 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2245 (cmdiocbp
->iocb_flag
&
2246 LPFC_DRIVER_ABORTED
)) {
2247 spin_lock_irqsave(&phba
->hbalock
,
2249 cmdiocbp
->iocb_flag
&=
2250 ~LPFC_DRIVER_ABORTED
;
2251 spin_unlock_irqrestore(&phba
->hbalock
,
2253 saveq
->iocb
.ulpStatus
=
2254 IOSTAT_LOCAL_REJECT
;
2255 saveq
->iocb
.un
.ulpWord
[4] =
2258 /* Firmware could still be in progress
2259 * of DMAing payload, so don't free data
2260 * buffer till after a hbeat.
2262 spin_lock_irqsave(&phba
->hbalock
,
2264 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2265 spin_unlock_irqrestore(&phba
->hbalock
,
2268 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2269 if (saveq
->iocb_flag
&
2270 LPFC_EXCHANGE_BUSY
) {
2271 /* Set cmdiocb flag for the
2272 * exchange busy so sgl (xri)
2273 * will not be released until
2274 * the abort xri is received
2278 &phba
->hbalock
, iflag
);
2279 cmdiocbp
->iocb_flag
|=
2281 spin_unlock_irqrestore(
2282 &phba
->hbalock
, iflag
);
2284 if (cmdiocbp
->iocb_flag
&
2285 LPFC_DRIVER_ABORTED
) {
2287 * Clear LPFC_DRIVER_ABORTED
2288 * bit in case it was driver
2292 &phba
->hbalock
, iflag
);
2293 cmdiocbp
->iocb_flag
&=
2294 ~LPFC_DRIVER_ABORTED
;
2295 spin_unlock_irqrestore(
2296 &phba
->hbalock
, iflag
);
2297 cmdiocbp
->iocb
.ulpStatus
=
2298 IOSTAT_LOCAL_REJECT
;
2299 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2300 IOERR_ABORT_REQUESTED
;
2302 * For SLI4, irsiocb contains
2303 * NO_XRI in sli_xritag, it
2304 * shall not affect releasing
2305 * sgl (xri) process.
2307 saveq
->iocb
.ulpStatus
=
2308 IOSTAT_LOCAL_REJECT
;
2309 saveq
->iocb
.un
.ulpWord
[4] =
2312 &phba
->hbalock
, iflag
);
2314 LPFC_DELAY_MEM_FREE
;
2315 spin_unlock_irqrestore(
2316 &phba
->hbalock
, iflag
);
2320 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2322 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2325 * Unknown initiating command based on the response iotag.
2326 * This could be the case on the ELS ring because of
2329 if (pring
->ringno
!= LPFC_ELS_RING
) {
2331 * Ring <ringno> handler: unexpected completion IoTag
2334 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2335 "0322 Ring %d handler: "
2336 "unexpected completion IoTag x%x "
2337 "Data: x%x x%x x%x x%x\n",
2339 saveq
->iocb
.ulpIoTag
,
2340 saveq
->iocb
.ulpStatus
,
2341 saveq
->iocb
.un
.ulpWord
[4],
2342 saveq
->iocb
.ulpCommand
,
2343 saveq
->iocb
.ulpContext
);
2351 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2352 * @phba: Pointer to HBA context object.
2353 * @pring: Pointer to driver SLI ring object.
2355 * This function is called from the iocb ring event handlers when
2356 * put pointer is ahead of the get pointer for a ring. This function signal
2357 * an error attention condition to the worker thread and the worker
2358 * thread will transition the HBA to offline state.
2361 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2363 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2365 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2366 * rsp ring <portRspMax>
2368 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2369 "0312 Ring %d handler: portRspPut %d "
2370 "is bigger than rsp ring %d\n",
2371 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2374 phba
->link_state
= LPFC_HBA_ERROR
;
2377 * All error attention handlers are posted to
2380 phba
->work_ha
|= HA_ERATT
;
2381 phba
->work_hs
= HS_FFER3
;
2383 lpfc_worker_wake_up(phba
);
2389 * lpfc_poll_eratt - Error attention polling timer timeout handler
2390 * @ptr: Pointer to address of HBA context object.
2392 * This function is invoked by the Error Attention polling timer when the
2393 * timer times out. It will check the SLI Error Attention register for
2394 * possible attention events. If so, it will post an Error Attention event
2395 * and wake up worker thread to process it. Otherwise, it will set up the
2396 * Error Attention polling timer for the next poll.
2398 void lpfc_poll_eratt(unsigned long ptr
)
2400 struct lpfc_hba
*phba
;
2403 phba
= (struct lpfc_hba
*)ptr
;
2405 /* Check chip HA register for error event */
2406 eratt
= lpfc_sli_check_eratt(phba
);
2409 /* Tell the worker thread there is work to do */
2410 lpfc_worker_wake_up(phba
);
2412 /* Restart the timer for next eratt poll */
2413 mod_timer(&phba
->eratt_poll
, jiffies
+
2414 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2420 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2421 * @phba: Pointer to HBA context object.
2422 * @pring: Pointer to driver SLI ring object.
2423 * @mask: Host attention register mask for this ring.
2425 * This function is called from the interrupt context when there is a ring
2426 * event for the fcp ring. The caller does not hold any lock.
2427 * The function processes each response iocb in the response ring until it
2428 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2429 * LE bit set. The function will call the completion handler of the command iocb
2430 * if the response iocb indicates a completion for a command iocb or it is
2431 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2432 * function if this is an unsolicited iocb.
2433 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2434 * to check it explicitly.
2437 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2438 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2440 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2441 IOCB_t
*irsp
= NULL
;
2442 IOCB_t
*entry
= NULL
;
2443 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2444 struct lpfc_iocbq rspiocbq
;
2446 uint32_t portRspPut
, portRspMax
;
2448 lpfc_iocb_type type
;
2449 unsigned long iflag
;
2450 uint32_t rsp_cmpl
= 0;
2452 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2453 pring
->stats
.iocb_event
++;
2456 * The next available response entry should never exceed the maximum
2457 * entries. If it does, treat it as an adapter hardware error.
2459 portRspMax
= pring
->numRiocb
;
2460 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2461 if (unlikely(portRspPut
>= portRspMax
)) {
2462 lpfc_sli_rsp_pointers_error(phba
, pring
);
2463 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2466 if (phba
->fcp_ring_in_use
) {
2467 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2470 phba
->fcp_ring_in_use
= 1;
2473 while (pring
->rspidx
!= portRspPut
) {
2475 * Fetch an entry off the ring and copy it into a local data
2476 * structure. The copy involves a byte-swap since the
2477 * network byte order and pci byte orders are different.
2479 entry
= lpfc_resp_iocb(phba
, pring
);
2480 phba
->last_completion_time
= jiffies
;
2482 if (++pring
->rspidx
>= portRspMax
)
2485 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2486 (uint32_t *) &rspiocbq
.iocb
,
2487 phba
->iocb_rsp_size
);
2488 INIT_LIST_HEAD(&(rspiocbq
.list
));
2489 irsp
= &rspiocbq
.iocb
;
2491 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2492 pring
->stats
.iocb_rsp
++;
2495 if (unlikely(irsp
->ulpStatus
)) {
2497 * If resource errors reported from HBA, reduce
2498 * queuedepths of the SCSI device.
2500 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2501 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2502 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2503 phba
->lpfc_rampdown_queue_depth(phba
);
2504 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2507 /* Rsp ring <ringno> error: IOCB */
2508 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2509 "0336 Rsp Ring %d error: IOCB Data: "
2510 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2512 irsp
->un
.ulpWord
[0],
2513 irsp
->un
.ulpWord
[1],
2514 irsp
->un
.ulpWord
[2],
2515 irsp
->un
.ulpWord
[3],
2516 irsp
->un
.ulpWord
[4],
2517 irsp
->un
.ulpWord
[5],
2518 *(uint32_t *)&irsp
->un1
,
2519 *((uint32_t *)&irsp
->un1
+ 1));
2523 case LPFC_ABORT_IOCB
:
2526 * Idle exchange closed via ABTS from port. No iocb
2527 * resources need to be recovered.
2529 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2530 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2531 "0333 IOCB cmd 0x%x"
2532 " processed. Skipping"
2538 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2540 if (unlikely(!cmdiocbq
))
2542 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
2543 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
2544 if (cmdiocbq
->iocb_cmpl
) {
2545 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2546 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2548 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2551 case LPFC_UNSOL_IOCB
:
2552 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2553 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2554 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2557 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2558 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2559 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2560 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2562 dev_warn(&((phba
->pcidev
)->dev
),
2564 phba
->brd_no
, adaptermsg
);
2566 /* Unknown IOCB command */
2567 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2568 "0334 Unknown IOCB command "
2569 "Data: x%x, x%x x%x x%x x%x\n",
2570 type
, irsp
->ulpCommand
,
2579 * The response IOCB has been processed. Update the ring
2580 * pointer in SLIM. If the port response put pointer has not
2581 * been updated, sync the pgp->rspPutInx and fetch the new port
2582 * response put pointer.
2584 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2586 if (pring
->rspidx
== portRspPut
)
2587 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2590 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
2591 pring
->stats
.iocb_rsp_full
++;
2592 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
2593 writel(status
, phba
->CAregaddr
);
2594 readl(phba
->CAregaddr
);
2596 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
2597 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
2598 pring
->stats
.iocb_cmd_empty
++;
2600 /* Force update of the local copy of cmdGetInx */
2601 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
2602 lpfc_sli_resume_iocb(phba
, pring
);
2604 if ((pring
->lpfc_sli_cmd_available
))
2605 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
2609 phba
->fcp_ring_in_use
= 0;
2610 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2615 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
2616 * @phba: Pointer to HBA context object.
2617 * @pring: Pointer to driver SLI ring object.
2618 * @rspiocbp: Pointer to driver response IOCB object.
2620 * This function is called from the worker thread when there is a slow-path
2621 * response IOCB to process. This function chains all the response iocbs until
2622 * seeing the iocb with the LE bit set. The function will call
2623 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
2624 * completion of a command iocb. The function will call the
2625 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
2626 * The function frees the resources or calls the completion handler if this
2627 * iocb is an abort completion. The function returns NULL when the response
2628 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
2629 * this function shall chain the iocb on to the iocb_continueq and return the
2630 * response iocb passed in.
2632 static struct lpfc_iocbq
*
2633 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2634 struct lpfc_iocbq
*rspiocbp
)
2636 struct lpfc_iocbq
*saveq
;
2637 struct lpfc_iocbq
*cmdiocbp
;
2638 struct lpfc_iocbq
*next_iocb
;
2639 IOCB_t
*irsp
= NULL
;
2640 uint32_t free_saveq
;
2641 uint8_t iocb_cmd_type
;
2642 lpfc_iocb_type type
;
2643 unsigned long iflag
;
2646 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2647 /* First add the response iocb to the countinueq list */
2648 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
2649 pring
->iocb_continueq_cnt
++;
2651 /* Now, determine whetehr the list is completed for processing */
2652 irsp
= &rspiocbp
->iocb
;
2655 * By default, the driver expects to free all resources
2656 * associated with this iocb completion.
2659 saveq
= list_get_first(&pring
->iocb_continueq
,
2660 struct lpfc_iocbq
, list
);
2661 irsp
= &(saveq
->iocb
);
2662 list_del_init(&pring
->iocb_continueq
);
2663 pring
->iocb_continueq_cnt
= 0;
2665 pring
->stats
.iocb_rsp
++;
2668 * If resource errors reported from HBA, reduce
2669 * queuedepths of the SCSI device.
2671 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2672 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2673 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2674 phba
->lpfc_rampdown_queue_depth(phba
);
2675 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2678 if (irsp
->ulpStatus
) {
2679 /* Rsp ring <ringno> error: IOCB */
2680 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2681 "0328 Rsp Ring %d error: "
2686 "x%x x%x x%x x%x\n",
2688 irsp
->un
.ulpWord
[0],
2689 irsp
->un
.ulpWord
[1],
2690 irsp
->un
.ulpWord
[2],
2691 irsp
->un
.ulpWord
[3],
2692 irsp
->un
.ulpWord
[4],
2693 irsp
->un
.ulpWord
[5],
2694 *(((uint32_t *) irsp
) + 6),
2695 *(((uint32_t *) irsp
) + 7),
2696 *(((uint32_t *) irsp
) + 8),
2697 *(((uint32_t *) irsp
) + 9),
2698 *(((uint32_t *) irsp
) + 10),
2699 *(((uint32_t *) irsp
) + 11),
2700 *(((uint32_t *) irsp
) + 12),
2701 *(((uint32_t *) irsp
) + 13),
2702 *(((uint32_t *) irsp
) + 14),
2703 *(((uint32_t *) irsp
) + 15));
2707 * Fetch the IOCB command type and call the correct completion
2708 * routine. Solicited and Unsolicited IOCBs on the ELS ring
2709 * get freed back to the lpfc_iocb_list by the discovery
2712 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
2713 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
2716 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2717 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
2718 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2721 case LPFC_UNSOL_IOCB
:
2722 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2723 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
2724 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2729 case LPFC_ABORT_IOCB
:
2731 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
2732 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
2735 /* Call the specified completion routine */
2736 if (cmdiocbp
->iocb_cmpl
) {
2737 spin_unlock_irqrestore(&phba
->hbalock
,
2739 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
2741 spin_lock_irqsave(&phba
->hbalock
,
2744 __lpfc_sli_release_iocbq(phba
,
2749 case LPFC_UNKNOWN_IOCB
:
2750 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2751 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2752 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2753 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
2755 dev_warn(&((phba
->pcidev
)->dev
),
2757 phba
->brd_no
, adaptermsg
);
2759 /* Unknown IOCB command */
2760 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2761 "0335 Unknown IOCB "
2762 "command Data: x%x "
2773 list_for_each_entry_safe(rspiocbp
, next_iocb
,
2774 &saveq
->list
, list
) {
2775 list_del(&rspiocbp
->list
);
2776 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
2778 __lpfc_sli_release_iocbq(phba
, saveq
);
2782 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2787 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
2788 * @phba: Pointer to HBA context object.
2789 * @pring: Pointer to driver SLI ring object.
2790 * @mask: Host attention register mask for this ring.
2792 * This routine wraps the actual slow_ring event process routine from the
2793 * API jump table function pointer from the lpfc_hba struct.
2796 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
2797 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2799 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
2803 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
2804 * @phba: Pointer to HBA context object.
2805 * @pring: Pointer to driver SLI ring object.
2806 * @mask: Host attention register mask for this ring.
2808 * This function is called from the worker thread when there is a ring event
2809 * for non-fcp rings. The caller does not hold any lock. The function will
2810 * remove each response iocb in the response ring and calls the handle
2811 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2814 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
2815 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2817 struct lpfc_pgp
*pgp
;
2819 IOCB_t
*irsp
= NULL
;
2820 struct lpfc_iocbq
*rspiocbp
= NULL
;
2821 uint32_t portRspPut
, portRspMax
;
2822 unsigned long iflag
;
2825 pgp
= &phba
->port_gp
[pring
->ringno
];
2826 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2827 pring
->stats
.iocb_event
++;
2830 * The next available response entry should never exceed the maximum
2831 * entries. If it does, treat it as an adapter hardware error.
2833 portRspMax
= pring
->numRiocb
;
2834 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2835 if (portRspPut
>= portRspMax
) {
2837 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2838 * rsp ring <portRspMax>
2840 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2841 "0303 Ring %d handler: portRspPut %d "
2842 "is bigger than rsp ring %d\n",
2843 pring
->ringno
, portRspPut
, portRspMax
);
2845 phba
->link_state
= LPFC_HBA_ERROR
;
2846 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2848 phba
->work_hs
= HS_FFER3
;
2849 lpfc_handle_eratt(phba
);
2855 while (pring
->rspidx
!= portRspPut
) {
2857 * Build a completion list and call the appropriate handler.
2858 * The process is to get the next available response iocb, get
2859 * a free iocb from the list, copy the response data into the
2860 * free iocb, insert to the continuation list, and update the
2861 * next response index to slim. This process makes response
2862 * iocb's in the ring available to DMA as fast as possible but
2863 * pays a penalty for a copy operation. Since the iocb is
2864 * only 32 bytes, this penalty is considered small relative to
2865 * the PCI reads for register values and a slim write. When
2866 * the ulpLe field is set, the entire Command has been
2869 entry
= lpfc_resp_iocb(phba
, pring
);
2871 phba
->last_completion_time
= jiffies
;
2872 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
2873 if (rspiocbp
== NULL
) {
2874 printk(KERN_ERR
"%s: out of buffers! Failing "
2875 "completion.\n", __func__
);
2879 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
2880 phba
->iocb_rsp_size
);
2881 irsp
= &rspiocbp
->iocb
;
2883 if (++pring
->rspidx
>= portRspMax
)
2886 if (pring
->ringno
== LPFC_ELS_RING
) {
2887 lpfc_debugfs_slow_ring_trc(phba
,
2888 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2889 *(((uint32_t *) irsp
) + 4),
2890 *(((uint32_t *) irsp
) + 6),
2891 *(((uint32_t *) irsp
) + 7));
2894 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2896 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2897 /* Handle the response IOCB */
2898 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
2899 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2902 * If the port response put pointer has not been updated, sync
2903 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
2904 * response put pointer.
2906 if (pring
->rspidx
== portRspPut
) {
2907 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2909 } /* while (pring->rspidx != portRspPut) */
2911 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
2912 /* At least one response entry has been freed */
2913 pring
->stats
.iocb_rsp_full
++;
2914 /* SET RxRE_RSP in Chip Att register */
2915 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
2916 writel(status
, phba
->CAregaddr
);
2917 readl(phba
->CAregaddr
); /* flush */
2919 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
2920 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
2921 pring
->stats
.iocb_cmd_empty
++;
2923 /* Force update of the local copy of cmdGetInx */
2924 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
2925 lpfc_sli_resume_iocb(phba
, pring
);
2927 if ((pring
->lpfc_sli_cmd_available
))
2928 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
2932 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2937 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
2938 * @phba: Pointer to HBA context object.
2939 * @pring: Pointer to driver SLI ring object.
2940 * @mask: Host attention register mask for this ring.
2942 * This function is called from the worker thread when there is a pending
2943 * ELS response iocb on the driver internal slow-path response iocb worker
2944 * queue. The caller does not hold any lock. The function will remove each
2945 * response iocb from the response worker queue and calls the handle
2946 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
2949 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
2950 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2952 struct lpfc_iocbq
*irspiocbq
;
2953 struct hbq_dmabuf
*dmabuf
;
2954 struct lpfc_cq_event
*cq_event
;
2955 unsigned long iflag
;
2957 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2958 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
2959 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2960 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
2961 /* Get the response iocb from the head of work queue */
2962 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2963 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
2964 cq_event
, struct lpfc_cq_event
, list
);
2965 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2967 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
2968 case CQE_CODE_COMPL_WQE
:
2969 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
2971 /* Translate ELS WCQE to response IOCBQ */
2972 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
2975 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
2978 case CQE_CODE_RECEIVE
:
2979 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
2981 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
2990 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
2991 * @phba: Pointer to HBA context object.
2992 * @pring: Pointer to driver SLI ring object.
2994 * This function aborts all iocbs in the given ring and frees all the iocb
2995 * objects in txq. This function issues an abort iocb for all the iocb commands
2996 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
2997 * the return of this function. The caller is not required to hold any locks.
3000 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3002 LIST_HEAD(completions
);
3003 struct lpfc_iocbq
*iocb
, *next_iocb
;
3005 if (pring
->ringno
== LPFC_ELS_RING
) {
3006 lpfc_fabric_abort_hba(phba
);
3009 /* Error everything on txq and txcmplq
3012 spin_lock_irq(&phba
->hbalock
);
3013 list_splice_init(&pring
->txq
, &completions
);
3016 /* Next issue ABTS for everything on the txcmplq */
3017 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3018 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3020 spin_unlock_irq(&phba
->hbalock
);
3022 /* Cancel all the IOCBs from the completions list */
3023 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3028 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3029 * @phba: Pointer to HBA context object.
3031 * This function flushes all iocbs in the fcp ring and frees all the iocb
3032 * objects in txq and txcmplq. This function will not issue abort iocbs
3033 * for all the iocb commands in txcmplq, they will just be returned with
3034 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3035 * slot has been permanently disabled.
3038 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3042 struct lpfc_sli
*psli
= &phba
->sli
;
3043 struct lpfc_sli_ring
*pring
;
3045 /* Currently, only one fcp ring */
3046 pring
= &psli
->ring
[psli
->fcp_ring
];
3048 spin_lock_irq(&phba
->hbalock
);
3049 /* Retrieve everything on txq */
3050 list_splice_init(&pring
->txq
, &txq
);
3053 /* Retrieve everything on the txcmplq */
3054 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3055 pring
->txcmplq_cnt
= 0;
3056 spin_unlock_irq(&phba
->hbalock
);
3059 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3062 /* Flush the txcmpq */
3063 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3068 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3069 * @phba: Pointer to HBA context object.
3070 * @mask: Bit mask to be checked.
3072 * This function reads the host status register and compares
3073 * with the provided bit mask to check if HBA completed
3074 * the restart. This function will wait in a loop for the
3075 * HBA to complete restart. If the HBA does not restart within
3076 * 15 iterations, the function will reset the HBA again. The
3077 * function returns 1 when HBA fail to restart otherwise returns
3081 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3087 /* Read the HBA Host Status Register */
3088 status
= readl(phba
->HSregaddr
);
3091 * Check status register every 100ms for 5 retries, then every
3092 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3093 * every 2.5 sec for 4.
3094 * Break our of the loop if errors occurred during init.
3096 while (((status
& mask
) != mask
) &&
3097 !(status
& HS_FFERM
) &&
3109 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3110 lpfc_sli_brdrestart(phba
);
3112 /* Read the HBA Host Status Register */
3113 status
= readl(phba
->HSregaddr
);
3116 /* Check to see if any errors occurred during init */
3117 if ((status
& HS_FFERM
) || (i
>= 20)) {
3118 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3119 "2751 Adapter failed to restart, "
3120 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3122 readl(phba
->MBslimaddr
+ 0xa8),
3123 readl(phba
->MBslimaddr
+ 0xac));
3124 phba
->link_state
= LPFC_HBA_ERROR
;
3132 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3133 * @phba: Pointer to HBA context object.
3134 * @mask: Bit mask to be checked.
3136 * This function checks the host status register to check if HBA is
3137 * ready. This function will wait in a loop for the HBA to be ready
3138 * If the HBA is not ready , the function will will reset the HBA PCI
3139 * function again. The function returns 1 when HBA fail to be ready
3140 * otherwise returns zero.
3143 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3148 /* Read the HBA Host Status Register */
3149 status
= lpfc_sli4_post_status_check(phba
);
3152 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3153 lpfc_sli_brdrestart(phba
);
3154 status
= lpfc_sli4_post_status_check(phba
);
3157 /* Check to see if any errors occurred during init */
3159 phba
->link_state
= LPFC_HBA_ERROR
;
3162 phba
->sli4_hba
.intr_enable
= 0;
3168 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3169 * @phba: Pointer to HBA context object.
3170 * @mask: Bit mask to be checked.
3172 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3173 * from the API jump table function pointer from the lpfc_hba struct.
3176 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3178 return phba
->lpfc_sli_brdready(phba
, mask
);
3181 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3184 * lpfc_reset_barrier - Make HBA ready for HBA reset
3185 * @phba: Pointer to HBA context object.
3187 * This function is called before resetting an HBA. This
3188 * function requests HBA to quiesce DMAs before a reset.
3190 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3192 uint32_t __iomem
*resp_buf
;
3193 uint32_t __iomem
*mbox_buf
;
3194 volatile uint32_t mbox
;
3199 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3200 if (hdrtype
!= 0x80 ||
3201 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3202 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3206 * Tell the other part of the chip to suspend temporarily all
3209 resp_buf
= phba
->MBslimaddr
;
3211 /* Disable the error attention */
3212 hc_copy
= readl(phba
->HCregaddr
);
3213 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3214 readl(phba
->HCregaddr
); /* flush */
3215 phba
->link_flag
|= LS_IGNORE_ERATT
;
3217 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3218 /* Clear Chip error bit */
3219 writel(HA_ERATT
, phba
->HAregaddr
);
3220 phba
->pport
->stopped
= 1;
3224 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3225 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3227 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3228 mbox_buf
= phba
->MBslimaddr
;
3229 writel(mbox
, mbox_buf
);
3232 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
3235 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
3236 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3237 phba
->pport
->stopped
)
3243 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3244 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
3249 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
3252 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3253 writel(HA_ERATT
, phba
->HAregaddr
);
3254 phba
->pport
->stopped
= 1;
3258 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3259 writel(hc_copy
, phba
->HCregaddr
);
3260 readl(phba
->HCregaddr
); /* flush */
3264 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3265 * @phba: Pointer to HBA context object.
3267 * This function issues a kill_board mailbox command and waits for
3268 * the error attention interrupt. This function is called for stopping
3269 * the firmware processing. The caller is not required to hold any
3270 * locks. This function calls lpfc_hba_down_post function to free
3271 * any pending commands after the kill. The function will return 1 when it
3272 * fails to kill the board else will return 0.
3275 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3277 struct lpfc_sli
*psli
;
3287 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3288 "0329 Kill HBA Data: x%x x%x\n",
3289 phba
->pport
->port_state
, psli
->sli_flag
);
3291 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3295 /* Disable the error attention */
3296 spin_lock_irq(&phba
->hbalock
);
3297 status
= readl(phba
->HCregaddr
);
3298 status
&= ~HC_ERINT_ENA
;
3299 writel(status
, phba
->HCregaddr
);
3300 readl(phba
->HCregaddr
); /* flush */
3301 phba
->link_flag
|= LS_IGNORE_ERATT
;
3302 spin_unlock_irq(&phba
->hbalock
);
3304 lpfc_kill_board(phba
, pmb
);
3305 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3306 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3308 if (retval
!= MBX_SUCCESS
) {
3309 if (retval
!= MBX_BUSY
)
3310 mempool_free(pmb
, phba
->mbox_mem_pool
);
3311 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3312 "2752 KILL_BOARD command failed retval %d\n",
3314 spin_lock_irq(&phba
->hbalock
);
3315 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3316 spin_unlock_irq(&phba
->hbalock
);
3320 spin_lock_irq(&phba
->hbalock
);
3321 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3322 spin_unlock_irq(&phba
->hbalock
);
3324 mempool_free(pmb
, phba
->mbox_mem_pool
);
3326 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3327 * attention every 100ms for 3 seconds. If we don't get ERATT after
3328 * 3 seconds we still set HBA_ERROR state because the status of the
3329 * board is now undefined.
3331 ha_copy
= readl(phba
->HAregaddr
);
3333 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3335 ha_copy
= readl(phba
->HAregaddr
);
3338 del_timer_sync(&psli
->mbox_tmo
);
3339 if (ha_copy
& HA_ERATT
) {
3340 writel(HA_ERATT
, phba
->HAregaddr
);
3341 phba
->pport
->stopped
= 1;
3343 spin_lock_irq(&phba
->hbalock
);
3344 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3345 psli
->mbox_active
= NULL
;
3346 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3347 spin_unlock_irq(&phba
->hbalock
);
3349 lpfc_hba_down_post(phba
);
3350 phba
->link_state
= LPFC_HBA_ERROR
;
3352 return ha_copy
& HA_ERATT
? 0 : 1;
3356 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3357 * @phba: Pointer to HBA context object.
3359 * This function resets the HBA by writing HC_INITFF to the control
3360 * register. After the HBA resets, this function resets all the iocb ring
3361 * indices. This function disables PCI layer parity checking during
3363 * This function returns 0 always.
3364 * The caller is not required to hold any locks.
3367 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3369 struct lpfc_sli
*psli
;
3370 struct lpfc_sli_ring
*pring
;
3377 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3378 "0325 Reset HBA Data: x%x x%x\n",
3379 phba
->pport
->port_state
, psli
->sli_flag
);
3381 /* perform board reset */
3382 phba
->fc_eventTag
= 0;
3383 phba
->link_events
= 0;
3384 phba
->pport
->fc_myDID
= 0;
3385 phba
->pport
->fc_prevDID
= 0;
3387 /* Turn off parity checking and serr during the physical reset */
3388 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3389 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3391 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3393 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3395 /* Now toggle INITFF bit in the Host Control Register */
3396 writel(HC_INITFF
, phba
->HCregaddr
);
3398 readl(phba
->HCregaddr
); /* flush */
3399 writel(0, phba
->HCregaddr
);
3400 readl(phba
->HCregaddr
); /* flush */
3402 /* Restore PCI cmd register */
3403 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3405 /* Initialize relevant SLI info */
3406 for (i
= 0; i
< psli
->num_rings
; i
++) {
3407 pring
= &psli
->ring
[i
];
3410 pring
->next_cmdidx
= 0;
3411 pring
->local_getidx
= 0;
3413 pring
->missbufcnt
= 0;
3416 phba
->link_state
= LPFC_WARM_START
;
3421 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3422 * @phba: Pointer to HBA context object.
3424 * This function resets a SLI4 HBA. This function disables PCI layer parity
3425 * checking during resets the device. The caller is not required to hold
3428 * This function returns 0 always.
3431 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3433 struct lpfc_sli
*psli
= &phba
->sli
;
3438 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3439 "0295 Reset HBA Data: x%x x%x\n",
3440 phba
->pport
->port_state
, psli
->sli_flag
);
3442 /* perform board reset */
3443 phba
->fc_eventTag
= 0;
3444 phba
->link_events
= 0;
3445 phba
->pport
->fc_myDID
= 0;
3446 phba
->pport
->fc_prevDID
= 0;
3448 /* Turn off parity checking and serr during the physical reset */
3449 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3450 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3452 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3454 spin_lock_irq(&phba
->hbalock
);
3455 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3456 phba
->fcf
.fcf_flag
= 0;
3457 /* Clean up the child queue list for the CQs */
3458 list_del_init(&phba
->sli4_hba
.mbx_wq
->list
);
3459 list_del_init(&phba
->sli4_hba
.els_wq
->list
);
3460 list_del_init(&phba
->sli4_hba
.hdr_rq
->list
);
3461 list_del_init(&phba
->sli4_hba
.dat_rq
->list
);
3462 list_del_init(&phba
->sli4_hba
.mbx_cq
->list
);
3463 list_del_init(&phba
->sli4_hba
.els_cq
->list
);
3464 for (qindx
= 0; qindx
< phba
->cfg_fcp_wq_count
; qindx
++)
3465 list_del_init(&phba
->sli4_hba
.fcp_wq
[qindx
]->list
);
3466 for (qindx
= 0; qindx
< phba
->cfg_fcp_eq_count
; qindx
++)
3467 list_del_init(&phba
->sli4_hba
.fcp_cq
[qindx
]->list
);
3468 spin_unlock_irq(&phba
->hbalock
);
3470 /* Now physically reset the device */
3471 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3472 "0389 Performing PCI function reset!\n");
3473 /* Perform FCoE PCI function reset */
3474 lpfc_pci_function_reset(phba
);
3480 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3481 * @phba: Pointer to HBA context object.
3483 * This function is called in the SLI initialization code path to
3484 * restart the HBA. The caller is not required to hold any lock.
3485 * This function writes MBX_RESTART mailbox command to the SLIM and
3486 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3487 * function to free any pending commands. The function enables
3488 * POST only during the first initialization. The function returns zero.
3489 * The function does not guarantee completion of MBX_RESTART mailbox
3490 * command before the return of this function.
3493 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3496 struct lpfc_sli
*psli
;
3497 volatile uint32_t word0
;
3498 void __iomem
*to_slim
;
3499 uint32_t hba_aer_enabled
;
3501 spin_lock_irq(&phba
->hbalock
);
3503 /* Take PCIe device Advanced Error Reporting (AER) state */
3504 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3509 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3510 "0337 Restart HBA Data: x%x x%x\n",
3511 phba
->pport
->port_state
, psli
->sli_flag
);
3514 mb
= (MAILBOX_t
*) &word0
;
3515 mb
->mbxCommand
= MBX_RESTART
;
3518 lpfc_reset_barrier(phba
);
3520 to_slim
= phba
->MBslimaddr
;
3521 writel(*(uint32_t *) mb
, to_slim
);
3522 readl(to_slim
); /* flush */
3524 /* Only skip post after fc_ffinit is completed */
3525 if (phba
->pport
->port_state
)
3526 word0
= 1; /* This is really setting up word1 */
3528 word0
= 0; /* This is really setting up word1 */
3529 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
3530 writel(*(uint32_t *) mb
, to_slim
);
3531 readl(to_slim
); /* flush */
3533 lpfc_sli_brdreset(phba
);
3534 phba
->pport
->stopped
= 0;
3535 phba
->link_state
= LPFC_INIT_START
;
3537 spin_unlock_irq(&phba
->hbalock
);
3539 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3540 psli
->stats_start
= get_seconds();
3542 /* Give the INITFF and Post time to settle. */
3545 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
3546 if (hba_aer_enabled
)
3547 pci_disable_pcie_error_reporting(phba
->pcidev
);
3549 lpfc_hba_down_post(phba
);
3555 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3556 * @phba: Pointer to HBA context object.
3558 * This function is called in the SLI initialization code path to restart
3559 * a SLI4 HBA. The caller is not required to hold any lock.
3560 * At the end of the function, it calls lpfc_hba_down_post function to
3561 * free any pending commands.
3564 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
3566 struct lpfc_sli
*psli
= &phba
->sli
;
3570 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3571 "0296 Restart HBA Data: x%x x%x\n",
3572 phba
->pport
->port_state
, psli
->sli_flag
);
3574 lpfc_sli4_brdreset(phba
);
3576 spin_lock_irq(&phba
->hbalock
);
3577 phba
->pport
->stopped
= 0;
3578 phba
->link_state
= LPFC_INIT_START
;
3580 spin_unlock_irq(&phba
->hbalock
);
3582 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3583 psli
->stats_start
= get_seconds();
3585 lpfc_hba_down_post(phba
);
3591 * lpfc_sli_brdrestart - Wrapper func for restarting hba
3592 * @phba: Pointer to HBA context object.
3594 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
3595 * API jump table function pointer from the lpfc_hba struct.
3598 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
3600 return phba
->lpfc_sli_brdrestart(phba
);
3604 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
3605 * @phba: Pointer to HBA context object.
3607 * This function is called after a HBA restart to wait for successful
3608 * restart of the HBA. Successful restart of the HBA is indicated by
3609 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
3610 * iteration, the function will restart the HBA again. The function returns
3611 * zero if HBA successfully restarted else returns negative error code.
3614 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
3616 uint32_t status
, i
= 0;
3618 /* Read the HBA Host Status Register */
3619 status
= readl(phba
->HSregaddr
);
3621 /* Check status register to see what current state is */
3623 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
3625 /* Check every 100ms for 5 retries, then every 500ms for 5, then
3626 * every 2.5 sec for 5, then reset board and every 2.5 sec for
3630 /* Adapter failed to init, timeout, status reg
3632 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3633 "0436 Adapter failed to init, "
3634 "timeout, status reg x%x, "
3635 "FW Data: A8 x%x AC x%x\n", status
,
3636 readl(phba
->MBslimaddr
+ 0xa8),
3637 readl(phba
->MBslimaddr
+ 0xac));
3638 phba
->link_state
= LPFC_HBA_ERROR
;
3642 /* Check to see if any errors occurred during init */
3643 if (status
& HS_FFERM
) {
3644 /* ERROR: During chipset initialization */
3645 /* Adapter failed to init, chipset, status reg
3647 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3648 "0437 Adapter failed to init, "
3649 "chipset, status reg x%x, "
3650 "FW Data: A8 x%x AC x%x\n", status
,
3651 readl(phba
->MBslimaddr
+ 0xa8),
3652 readl(phba
->MBslimaddr
+ 0xac));
3653 phba
->link_state
= LPFC_HBA_ERROR
;
3659 } else if (i
<= 10) {
3667 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3668 lpfc_sli_brdrestart(phba
);
3670 /* Read the HBA Host Status Register */
3671 status
= readl(phba
->HSregaddr
);
3674 /* Check to see if any errors occurred during init */
3675 if (status
& HS_FFERM
) {
3676 /* ERROR: During chipset initialization */
3677 /* Adapter failed to init, chipset, status reg <status> */
3678 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3679 "0438 Adapter failed to init, chipset, "
3681 "FW Data: A8 x%x AC x%x\n", status
,
3682 readl(phba
->MBslimaddr
+ 0xa8),
3683 readl(phba
->MBslimaddr
+ 0xac));
3684 phba
->link_state
= LPFC_HBA_ERROR
;
3688 /* Clear all interrupt enable conditions */
3689 writel(0, phba
->HCregaddr
);
3690 readl(phba
->HCregaddr
); /* flush */
3692 /* setup host attn register */
3693 writel(0xffffffff, phba
->HAregaddr
);
3694 readl(phba
->HAregaddr
); /* flush */
3699 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
3701 * This function calculates and returns the number of HBQs required to be
3705 lpfc_sli_hbq_count(void)
3707 return ARRAY_SIZE(lpfc_hbq_defs
);
3711 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
3713 * This function adds the number of hbq entries in every HBQ to get
3714 * the total number of hbq entries required for the HBA and returns
3718 lpfc_sli_hbq_entry_count(void)
3720 int hbq_count
= lpfc_sli_hbq_count();
3724 for (i
= 0; i
< hbq_count
; ++i
)
3725 count
+= lpfc_hbq_defs
[i
]->entry_count
;
3730 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
3732 * This function calculates amount of memory required for all hbq entries
3733 * to be configured and returns the total memory required.
3736 lpfc_sli_hbq_size(void)
3738 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
3742 * lpfc_sli_hbq_setup - configure and initialize HBQs
3743 * @phba: Pointer to HBA context object.
3745 * This function is called during the SLI initialization to configure
3746 * all the HBQs and post buffers to the HBQ. The caller is not
3747 * required to hold any locks. This function will return zero if successful
3748 * else it will return negative error code.
3751 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
3753 int hbq_count
= lpfc_sli_hbq_count();
3757 uint32_t hbq_entry_index
;
3759 /* Get a Mailbox buffer to setup mailbox
3760 * commands for HBA initialization
3762 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3769 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
3770 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
3771 phba
->hbq_in_use
= 1;
3773 hbq_entry_index
= 0;
3774 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
3775 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
3776 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
3777 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
3778 phba
->hbqs
[hbqno
].entry_count
=
3779 lpfc_hbq_defs
[hbqno
]->entry_count
;
3780 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
3781 hbq_entry_index
, pmb
);
3782 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
3784 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
3785 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
3786 mbxStatus <status>, ring <num> */
3788 lpfc_printf_log(phba
, KERN_ERR
,
3789 LOG_SLI
| LOG_VPORT
,
3790 "1805 Adapter failed to init. "
3791 "Data: x%x x%x x%x\n",
3793 pmbox
->mbxStatus
, hbqno
);
3795 phba
->link_state
= LPFC_HBA_ERROR
;
3796 mempool_free(pmb
, phba
->mbox_mem_pool
);
3800 phba
->hbq_count
= hbq_count
;
3802 mempool_free(pmb
, phba
->mbox_mem_pool
);
3804 /* Initially populate or replenish the HBQs */
3805 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
3806 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
3811 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
3812 * @phba: Pointer to HBA context object.
3814 * This function is called during the SLI initialization to configure
3815 * all the HBQs and post buffers to the HBQ. The caller is not
3816 * required to hold any locks. This function will return zero if successful
3817 * else it will return negative error code.
3820 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
3822 phba
->hbq_in_use
= 1;
3823 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
3824 phba
->hbq_count
= 1;
3825 /* Initially populate or replenish the HBQs */
3826 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
3831 * lpfc_sli_config_port - Issue config port mailbox command
3832 * @phba: Pointer to HBA context object.
3833 * @sli_mode: sli mode - 2/3
3835 * This function is called by the sli intialization code path
3836 * to issue config_port mailbox command. This function restarts the
3837 * HBA firmware and issues a config_port mailbox command to configure
3838 * the SLI interface in the sli mode specified by sli_mode
3839 * variable. The caller is not required to hold any locks.
3840 * The function returns 0 if successful, else returns negative error
3844 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
3847 uint32_t resetcount
= 0, rc
= 0, done
= 0;
3849 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3851 phba
->link_state
= LPFC_HBA_ERROR
;
3855 phba
->sli_rev
= sli_mode
;
3856 while (resetcount
< 2 && !done
) {
3857 spin_lock_irq(&phba
->hbalock
);
3858 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
3859 spin_unlock_irq(&phba
->hbalock
);
3860 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3861 lpfc_sli_brdrestart(phba
);
3862 rc
= lpfc_sli_chipset_init(phba
);
3866 spin_lock_irq(&phba
->hbalock
);
3867 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3868 spin_unlock_irq(&phba
->hbalock
);
3871 /* Call pre CONFIG_PORT mailbox command initialization. A
3872 * value of 0 means the call was successful. Any other
3873 * nonzero value is a failure, but if ERESTART is returned,
3874 * the driver may reset the HBA and try again.
3876 rc
= lpfc_config_port_prep(phba
);
3877 if (rc
== -ERESTART
) {
3878 phba
->link_state
= LPFC_LINK_UNKNOWN
;
3882 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
3883 lpfc_config_port(phba
, pmb
);
3884 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
3885 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
3886 LPFC_SLI3_HBQ_ENABLED
|
3887 LPFC_SLI3_CRP_ENABLED
|
3888 LPFC_SLI3_BG_ENABLED
);
3889 if (rc
!= MBX_SUCCESS
) {
3890 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3891 "0442 Adapter failed to init, mbxCmd x%x "
3892 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3893 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
3894 spin_lock_irq(&phba
->hbalock
);
3895 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
3896 spin_unlock_irq(&phba
->hbalock
);
3899 /* Allow asynchronous mailbox command to go through */
3900 spin_lock_irq(&phba
->hbalock
);
3901 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
3902 spin_unlock_irq(&phba
->hbalock
);
3908 goto do_prep_failed
;
3910 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
3911 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
3913 goto do_prep_failed
;
3915 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
3916 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
3917 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
3918 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
3919 phba
->max_vpi
: phba
->max_vports
;
3923 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
)
3924 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
3925 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
3926 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
3927 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
3928 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
3930 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
3931 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
3933 if (phba
->cfg_enable_bg
) {
3934 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
3935 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
3937 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3938 "0443 Adapter did not grant "
3942 phba
->hbq_get
= NULL
;
3943 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
3947 mempool_free(pmb
, phba
->mbox_mem_pool
);
3953 * lpfc_sli_hba_setup - SLI intialization function
3954 * @phba: Pointer to HBA context object.
3956 * This function is the main SLI intialization function. This function
3957 * is called by the HBA intialization code, HBA reset code and HBA
3958 * error attention handler code. Caller is not required to hold any
3959 * locks. This function issues config_port mailbox command to configure
3960 * the SLI, setup iocb rings and HBQ rings. In the end the function
3961 * calls the config_port_post function to issue init_link mailbox
3962 * command and to start the discovery. The function will return zero
3963 * if successful, else it will return negative error code.
3966 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
3971 switch (lpfc_sli_mode
) {
3973 if (phba
->cfg_enable_npiv
) {
3974 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
3975 "1824 NPIV enabled: Override lpfc_sli_mode "
3976 "parameter (%d) to auto (0).\n",
3986 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
3987 "1819 Unrecognized lpfc_sli_mode "
3988 "parameter: %d.\n", lpfc_sli_mode
);
3993 rc
= lpfc_sli_config_port(phba
, mode
);
3995 if (rc
&& lpfc_sli_mode
== 3)
3996 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
3997 "1820 Unable to select SLI-3. "
3998 "Not supported by adapter.\n");
3999 if (rc
&& mode
!= 2)
4000 rc
= lpfc_sli_config_port(phba
, 2);
4002 goto lpfc_sli_hba_setup_error
;
4004 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4005 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4006 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4008 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4009 "2709 This device supports "
4010 "Advanced Error Reporting (AER)\n");
4011 spin_lock_irq(&phba
->hbalock
);
4012 phba
->hba_flag
|= HBA_AER_ENABLED
;
4013 spin_unlock_irq(&phba
->hbalock
);
4015 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4016 "2708 This device does not support "
4017 "Advanced Error Reporting (AER)\n");
4018 phba
->cfg_aer_support
= 0;
4022 if (phba
->sli_rev
== 3) {
4023 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4024 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4026 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4027 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4028 phba
->sli3_options
= 0;
4031 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4032 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4033 phba
->sli_rev
, phba
->max_vpi
);
4034 rc
= lpfc_sli_ring_map(phba
);
4037 goto lpfc_sli_hba_setup_error
;
4040 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4041 rc
= lpfc_sli_hbq_setup(phba
);
4043 goto lpfc_sli_hba_setup_error
;
4045 spin_lock_irq(&phba
->hbalock
);
4046 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4047 spin_unlock_irq(&phba
->hbalock
);
4049 rc
= lpfc_config_port_post(phba
);
4051 goto lpfc_sli_hba_setup_error
;
4055 lpfc_sli_hba_setup_error
:
4056 phba
->link_state
= LPFC_HBA_ERROR
;
4057 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4058 "0445 Firmware initialization failed\n");
4063 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4064 * @phba: Pointer to HBA context object.
4065 * @mboxq: mailbox pointer.
4066 * This function issue a dump mailbox command to read config region
4067 * 23 and parse the records in the region and populate driver
4071 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
,
4072 LPFC_MBOXQ_t
*mboxq
)
4074 struct lpfc_dmabuf
*mp
;
4075 struct lpfc_mqe
*mqe
;
4076 uint32_t data_length
;
4079 /* Program the default value of vlan_id and fc_map */
4080 phba
->valid_vlan
= 0;
4081 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4082 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4083 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4085 mqe
= &mboxq
->u
.mqe
;
4086 if (lpfc_dump_fcoe_param(phba
, mboxq
))
4089 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4090 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4092 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4093 "(%d):2571 Mailbox cmd x%x Status x%x "
4094 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4095 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4096 "CQ: x%x x%x x%x x%x\n",
4097 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4098 bf_get(lpfc_mqe_command
, mqe
),
4099 bf_get(lpfc_mqe_status
, mqe
),
4100 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4101 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4102 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4103 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4104 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4105 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4106 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4107 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4108 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4110 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4111 mboxq
->mcqe
.trailer
);
4114 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4118 data_length
= mqe
->un
.mb_words
[5];
4119 if (data_length
> DMP_RGN23_SIZE
) {
4120 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4125 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4126 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4132 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4133 * @phba: pointer to lpfc hba data structure.
4134 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4135 * @vpd: pointer to the memory to hold resulting port vpd data.
4136 * @vpd_size: On input, the number of bytes allocated to @vpd.
4137 * On output, the number of data bytes in @vpd.
4139 * This routine executes a READ_REV SLI4 mailbox command. In
4140 * addition, this routine gets the port vpd data.
4144 * ENOMEM - could not allocated memory.
4147 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4148 uint8_t *vpd
, uint32_t *vpd_size
)
4152 struct lpfc_dmabuf
*dmabuf
;
4153 struct lpfc_mqe
*mqe
;
4155 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4160 * Get a DMA buffer for the vpd data resulting from the READ_REV
4163 dma_size
= *vpd_size
;
4164 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4168 if (!dmabuf
->virt
) {
4172 memset(dmabuf
->virt
, 0, dma_size
);
4175 * The SLI4 implementation of READ_REV conflicts at word1,
4176 * bits 31:16 and SLI4 adds vpd functionality not present
4177 * in SLI3. This code corrects the conflicts.
4179 lpfc_read_rev(phba
, mboxq
);
4180 mqe
= &mboxq
->u
.mqe
;
4181 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4182 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4183 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4184 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4185 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4187 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4189 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4190 dmabuf
->virt
, dmabuf
->phys
);
4196 * The available vpd length cannot be bigger than the
4197 * DMA buffer passed to the port. Catch the less than
4198 * case and update the caller's size.
4200 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4201 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4203 lpfc_sli_pcimem_bcopy(dmabuf
->virt
, vpd
, *vpd_size
);
4204 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4205 dmabuf
->virt
, dmabuf
->phys
);
4211 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4212 * @phba: pointer to lpfc hba data structure.
4214 * This routine is called to explicitly arm the SLI4 device's completion and
4218 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4222 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4223 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4224 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4225 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4227 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4228 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4229 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4234 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4235 * @phba: Pointer to HBA context object.
4237 * This function is the main SLI4 device intialization PCI function. This
4238 * function is called by the HBA intialization code, HBA reset code and
4239 * HBA error attention handler code. Caller is not required to hold any
4243 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
4246 LPFC_MBOXQ_t
*mboxq
;
4247 struct lpfc_mqe
*mqe
;
4250 uint32_t ftr_rsp
= 0;
4251 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
4252 struct lpfc_vport
*vport
= phba
->pport
;
4253 struct lpfc_dmabuf
*mp
;
4255 /* Perform a PCI function reset to start from clean */
4256 rc
= lpfc_pci_function_reset(phba
);
4260 /* Check the HBA Host Status Register for readyness */
4261 rc
= lpfc_sli4_post_status_check(phba
);
4265 spin_lock_irq(&phba
->hbalock
);
4266 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
4267 spin_unlock_irq(&phba
->hbalock
);
4271 * Allocate a single mailbox container for initializing the
4274 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4279 * Continue initialization with default values even if driver failed
4280 * to read FCoE param config regions
4282 if (lpfc_sli4_read_fcoe_params(phba
, mboxq
))
4283 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4284 "2570 Failed to read FCoE parameters\n");
4286 /* Issue READ_REV to collect vpd and FW information. */
4287 vpd_size
= SLI4_PAGE_SIZE
;
4288 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
4294 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
4298 mqe
= &mboxq
->u
.mqe
;
4299 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
4300 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
4301 phba
->hba_flag
|= HBA_FCOE_SUPPORT
;
4303 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
4305 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
4307 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
4309 if (phba
->sli_rev
!= LPFC_SLI_REV4
||
4310 !(phba
->hba_flag
& HBA_FCOE_SUPPORT
)) {
4311 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4312 "0376 READ_REV Error. SLI Level %d "
4313 "FCoE enabled %d\n",
4314 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_SUPPORT
);
4319 * Evaluate the read rev and vpd data. Populate the driver
4320 * state with the results. If this routine fails, the failure
4321 * is not fatal as the driver will use generic values.
4323 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
4324 if (unlikely(!rc
)) {
4325 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4326 "0377 Error %d parsing vpd. "
4327 "Using defaults.\n", rc
);
4331 /* Save information as VPD data */
4332 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
4333 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
4334 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
4335 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
4337 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
4339 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
4341 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
4343 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4344 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
4345 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
4346 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
4347 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4348 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
4349 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4350 "(%d):0380 READ_REV Status x%x "
4351 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
4352 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4353 bf_get(lpfc_mqe_status
, mqe
),
4354 phba
->vpd
.rev
.opFwName
,
4355 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
4356 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
4359 * Discover the port's supported feature set and match it against the
4362 lpfc_request_features(phba
, mboxq
);
4363 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4370 * The port must support FCP initiator mode as this is the
4371 * only mode running in the host.
4373 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
4374 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4375 "0378 No support for fcpi mode.\n");
4380 * If the port cannot support the host's requested features
4381 * then turn off the global config parameters to disable the
4382 * feature in the driver. This is not a fatal error.
4384 if ((phba
->cfg_enable_bg
) &&
4385 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4388 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
4389 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4393 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4394 "0379 Feature Mismatch Data: x%08x %08x "
4395 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
4396 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
4397 phba
->cfg_enable_npiv
, phba
->max_vpi
);
4398 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4399 phba
->cfg_enable_bg
= 0;
4400 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4401 phba
->cfg_enable_npiv
= 0;
4404 /* These SLI3 features are assumed in SLI4 */
4405 spin_lock_irq(&phba
->hbalock
);
4406 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
4407 spin_unlock_irq(&phba
->hbalock
);
4409 /* Read the port's service parameters. */
4410 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
4412 phba
->link_state
= LPFC_HBA_ERROR
;
4417 mboxq
->vport
= vport
;
4418 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4419 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4420 if (rc
== MBX_SUCCESS
) {
4421 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
4426 * This memory was allocated by the lpfc_read_sparam routine. Release
4427 * it to the mbuf pool.
4429 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4431 mboxq
->context1
= NULL
;
4433 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4434 "0382 READ_SPARAM command failed "
4435 "status %d, mbxStatus x%x\n",
4436 rc
, bf_get(lpfc_mqe_status
, mqe
));
4437 phba
->link_state
= LPFC_HBA_ERROR
;
4442 if (phba
->cfg_soft_wwnn
)
4443 u64_to_wwn(phba
->cfg_soft_wwnn
,
4444 vport
->fc_sparam
.nodeName
.u
.wwn
);
4445 if (phba
->cfg_soft_wwpn
)
4446 u64_to_wwn(phba
->cfg_soft_wwpn
,
4447 vport
->fc_sparam
.portName
.u
.wwn
);
4448 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
4449 sizeof(struct lpfc_name
));
4450 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
4451 sizeof(struct lpfc_name
));
4453 /* Update the fc_host data structures with new wwn. */
4454 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
4455 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
4457 /* Register SGL pool to the device using non-embedded mailbox command */
4458 rc
= lpfc_sli4_post_sgl_list(phba
);
4460 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4461 "0582 Error %d during sgl post operation\n",
4467 /* Register SCSI SGL pool to the device */
4468 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
4470 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4471 "0383 Error %d during scsi sgl post "
4473 /* Some Scsi buffers were moved to the abort scsi list */
4474 /* A pci function reset will repost them */
4479 /* Post the rpi header region to the device. */
4480 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
4482 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4483 "0393 Error %d during rpi post operation\n",
4489 /* Set up all the queues to the device */
4490 rc
= lpfc_sli4_queue_setup(phba
);
4492 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4493 "0381 Error %d during queue setup.\n ", rc
);
4494 goto out_stop_timers
;
4497 /* Arm the CQs and then EQs on device */
4498 lpfc_sli4_arm_cqeq_intr(phba
);
4500 /* Indicate device interrupt mode */
4501 phba
->sli4_hba
.intr_enable
= 1;
4503 /* Allow asynchronous mailbox command to go through */
4504 spin_lock_irq(&phba
->hbalock
);
4505 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4506 spin_unlock_irq(&phba
->hbalock
);
4508 /* Post receive buffers to the device */
4509 lpfc_sli4_rb_setup(phba
);
4511 /* Reset HBA FCF states after HBA reset */
4512 phba
->fcf
.fcf_flag
= 0;
4513 phba
->fcf
.current_rec
.flag
= 0;
4515 /* Start the ELS watchdog timer */
4516 mod_timer(&vport
->els_tmofunc
,
4517 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
4519 /* Start heart beat timer */
4520 mod_timer(&phba
->hb_tmofunc
,
4521 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
4522 phba
->hb_outstanding
= 0;
4523 phba
->last_completion_time
= jiffies
;
4525 /* Start error attention (ERATT) polling timer */
4526 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
4529 * The port is ready, set the host's link state to LINK_DOWN
4530 * in preparation for link interrupts.
4532 lpfc_init_link(phba
, mboxq
, phba
->cfg_topology
, phba
->cfg_link_speed
);
4533 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4534 lpfc_set_loopback_flag(phba
);
4535 /* Change driver state to LPFC_LINK_DOWN right before init link */
4536 spin_lock_irq(&phba
->hbalock
);
4537 phba
->link_state
= LPFC_LINK_DOWN
;
4538 spin_unlock_irq(&phba
->hbalock
);
4539 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
4540 if (unlikely(rc
!= MBX_NOT_FINISHED
)) {
4546 /* Unset all the queues set up in this routine when error out */
4548 lpfc_sli4_queue_unset(phba
);
4552 lpfc_stop_hba_timers(phba
);
4556 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4561 * lpfc_mbox_timeout - Timeout call back function for mbox timer
4562 * @ptr: context object - pointer to hba structure.
4564 * This is the callback function for mailbox timer. The mailbox
4565 * timer is armed when a new mailbox command is issued and the timer
4566 * is deleted when the mailbox complete. The function is called by
4567 * the kernel timer code when a mailbox does not complete within
4568 * expected time. This function wakes up the worker thread to
4569 * process the mailbox timeout and returns. All the processing is
4570 * done by the worker thread function lpfc_mbox_timeout_handler.
4573 lpfc_mbox_timeout(unsigned long ptr
)
4575 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4576 unsigned long iflag
;
4577 uint32_t tmo_posted
;
4579 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
4580 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
4582 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
4583 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
4586 lpfc_worker_wake_up(phba
);
4592 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
4593 * @phba: Pointer to HBA context object.
4595 * This function is called from worker thread when a mailbox command times out.
4596 * The caller is not required to hold any locks. This function will reset the
4597 * HBA and recover all the pending commands.
4600 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
4602 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
4603 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
4604 struct lpfc_sli
*psli
= &phba
->sli
;
4605 struct lpfc_sli_ring
*pring
;
4607 /* Check the pmbox pointer first. There is a race condition
4608 * between the mbox timeout handler getting executed in the
4609 * worklist and the mailbox actually completing. When this
4610 * race condition occurs, the mbox_active will be NULL.
4612 spin_lock_irq(&phba
->hbalock
);
4613 if (pmbox
== NULL
) {
4614 lpfc_printf_log(phba
, KERN_WARNING
,
4616 "0353 Active Mailbox cleared - mailbox timeout "
4618 spin_unlock_irq(&phba
->hbalock
);
4622 /* Mbox cmd <mbxCommand> timeout */
4623 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4624 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
4626 phba
->pport
->port_state
,
4628 phba
->sli
.mbox_active
);
4629 spin_unlock_irq(&phba
->hbalock
);
4631 /* Setting state unknown so lpfc_sli_abort_iocb_ring
4632 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
4633 * it to fail all oustanding SCSI IO.
4635 spin_lock_irq(&phba
->pport
->work_port_lock
);
4636 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
4637 spin_unlock_irq(&phba
->pport
->work_port_lock
);
4638 spin_lock_irq(&phba
->hbalock
);
4639 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4640 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
4641 spin_unlock_irq(&phba
->hbalock
);
4643 pring
= &psli
->ring
[psli
->fcp_ring
];
4644 lpfc_sli_abort_iocb_ring(phba
, pring
);
4646 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4647 "0345 Resetting board due to mailbox timeout\n");
4649 /* Reset the HBA device */
4650 lpfc_reset_hba(phba
);
4654 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
4655 * @phba: Pointer to HBA context object.
4656 * @pmbox: Pointer to mailbox object.
4657 * @flag: Flag indicating how the mailbox need to be processed.
4659 * This function is called by discovery code and HBA management code
4660 * to submit a mailbox command to firmware with SLI-3 interface spec. This
4661 * function gets the hbalock to protect the data structures.
4662 * The mailbox command can be submitted in polling mode, in which case
4663 * this function will wait in a polling loop for the completion of the
4665 * If the mailbox is submitted in no_wait mode (not polling) the
4666 * function will submit the command and returns immediately without waiting
4667 * for the mailbox completion. The no_wait is supported only when HBA
4668 * is in SLI2/SLI3 mode - interrupts are enabled.
4669 * The SLI interface allows only one mailbox pending at a time. If the
4670 * mailbox is issued in polling mode and there is already a mailbox
4671 * pending, then the function will return an error. If the mailbox is issued
4672 * in NO_WAIT mode and there is a mailbox pending already, the function
4673 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
4674 * The sli layer owns the mailbox object until the completion of mailbox
4675 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
4676 * return codes the caller owns the mailbox command after the return of
4680 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
4684 struct lpfc_sli
*psli
= &phba
->sli
;
4685 uint32_t status
, evtctr
;
4688 unsigned long timeout
;
4689 unsigned long drvr_flag
= 0;
4690 uint32_t word0
, ldata
;
4691 void __iomem
*to_slim
;
4692 int processing_queue
= 0;
4694 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
4696 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4697 /* processing mbox queue from intr_handler */
4698 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
4699 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4702 processing_queue
= 1;
4703 pmbox
= lpfc_mbox_get(phba
);
4705 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4710 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
4711 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
4713 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4714 lpfc_printf_log(phba
, KERN_ERR
,
4715 LOG_MBOX
| LOG_VPORT
,
4716 "1806 Mbox x%x failed. No vport\n",
4717 pmbox
->u
.mb
.mbxCommand
);
4719 goto out_not_finished
;
4723 /* If the PCI channel is in offline state, do not post mbox. */
4724 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
4725 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4726 goto out_not_finished
;
4729 /* If HBA has a deferred error attention, fail the iocb. */
4730 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
4731 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4732 goto out_not_finished
;
4738 status
= MBX_SUCCESS
;
4740 if (phba
->link_state
== LPFC_HBA_ERROR
) {
4741 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4743 /* Mbox command <mbxCommand> cannot issue */
4744 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4745 "(%d):0311 Mailbox command x%x cannot "
4746 "issue Data: x%x x%x\n",
4747 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4748 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
4749 goto out_not_finished
;
4752 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
4753 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
4754 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4755 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4756 "(%d):2528 Mailbox command x%x cannot "
4757 "issue Data: x%x x%x\n",
4758 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4759 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
4760 goto out_not_finished
;
4763 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
4764 /* Polling for a mbox command when another one is already active
4765 * is not allowed in SLI. Also, the driver must have established
4766 * SLI2 mode to queue and process multiple mbox commands.
4769 if (flag
& MBX_POLL
) {
4770 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4772 /* Mbox command <mbxCommand> cannot issue */
4773 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4774 "(%d):2529 Mailbox command x%x "
4775 "cannot issue Data: x%x x%x\n",
4776 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4777 pmbox
->u
.mb
.mbxCommand
,
4778 psli
->sli_flag
, flag
);
4779 goto out_not_finished
;
4782 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
4783 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4784 /* Mbox command <mbxCommand> cannot issue */
4785 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4786 "(%d):2530 Mailbox command x%x "
4787 "cannot issue Data: x%x x%x\n",
4788 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4789 pmbox
->u
.mb
.mbxCommand
,
4790 psli
->sli_flag
, flag
);
4791 goto out_not_finished
;
4794 /* Another mailbox command is still being processed, queue this
4795 * command to be processed later.
4797 lpfc_mbox_put(phba
, pmbox
);
4799 /* Mbox cmd issue - BUSY */
4800 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4801 "(%d):0308 Mbox cmd issue - BUSY Data: "
4802 "x%x x%x x%x x%x\n",
4803 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
4804 mb
->mbxCommand
, phba
->pport
->port_state
,
4805 psli
->sli_flag
, flag
);
4807 psli
->slistat
.mbox_busy
++;
4808 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4811 lpfc_debugfs_disc_trc(pmbox
->vport
,
4812 LPFC_DISC_TRC_MBOX_VPORT
,
4813 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
4814 (uint32_t)mb
->mbxCommand
,
4815 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4818 lpfc_debugfs_disc_trc(phba
->pport
,
4820 "MBOX Bsy: cmd:x%x mb:x%x x%x",
4821 (uint32_t)mb
->mbxCommand
,
4822 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4828 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4830 /* If we are not polling, we MUST be in SLI2 mode */
4831 if (flag
!= MBX_POLL
) {
4832 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
4833 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
4834 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4835 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4836 /* Mbox command <mbxCommand> cannot issue */
4837 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4838 "(%d):2531 Mailbox command x%x "
4839 "cannot issue Data: x%x x%x\n",
4840 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4841 pmbox
->u
.mb
.mbxCommand
,
4842 psli
->sli_flag
, flag
);
4843 goto out_not_finished
;
4845 /* timeout active mbox command */
4846 mod_timer(&psli
->mbox_tmo
, (jiffies
+
4847 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
4850 /* Mailbox cmd <cmd> issue */
4851 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4852 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
4854 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4855 mb
->mbxCommand
, phba
->pport
->port_state
,
4856 psli
->sli_flag
, flag
);
4858 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
4860 lpfc_debugfs_disc_trc(pmbox
->vport
,
4861 LPFC_DISC_TRC_MBOX_VPORT
,
4862 "MBOX Send vport: cmd:x%x mb:x%x x%x",
4863 (uint32_t)mb
->mbxCommand
,
4864 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4867 lpfc_debugfs_disc_trc(phba
->pport
,
4869 "MBOX Send: cmd:x%x mb:x%x x%x",
4870 (uint32_t)mb
->mbxCommand
,
4871 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4875 psli
->slistat
.mbox_cmd
++;
4876 evtctr
= psli
->slistat
.mbox_event
;
4878 /* next set own bit for the adapter and copy over command word */
4879 mb
->mbxOwner
= OWN_CHIP
;
4881 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4882 /* Populate mbox extension offset word. */
4883 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
4884 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
4885 = (uint8_t *)phba
->mbox_ext
4886 - (uint8_t *)phba
->mbox
;
4889 /* Copy the mailbox extension data */
4890 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
4891 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
4892 (uint8_t *)phba
->mbox_ext
,
4893 pmbox
->in_ext_byte_len
);
4895 /* Copy command data to host SLIM area */
4896 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
4898 /* Populate mbox extension offset word. */
4899 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
4900 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
4901 = MAILBOX_HBA_EXT_OFFSET
;
4903 /* Copy the mailbox extension data */
4904 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
4905 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
4906 MAILBOX_HBA_EXT_OFFSET
,
4907 pmbox
->context2
, pmbox
->in_ext_byte_len
);
4910 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4911 /* copy command data into host mbox for cmpl */
4912 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
4915 /* First copy mbox command data to HBA SLIM, skip past first
4917 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4918 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
4919 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
4921 /* Next copy over first word, with mbxOwner set */
4922 ldata
= *((uint32_t *)mb
);
4923 to_slim
= phba
->MBslimaddr
;
4924 writel(ldata
, to_slim
);
4925 readl(to_slim
); /* flush */
4927 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4928 /* switch over to host mailbox */
4929 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
4937 /* Set up reference to mailbox command */
4938 psli
->mbox_active
= pmbox
;
4939 /* Interrupt board to do it */
4940 writel(CA_MBATT
, phba
->CAregaddr
);
4941 readl(phba
->CAregaddr
); /* flush */
4942 /* Don't wait for it to finish, just return */
4946 /* Set up null reference to mailbox command */
4947 psli
->mbox_active
= NULL
;
4948 /* Interrupt board to do it */
4949 writel(CA_MBATT
, phba
->CAregaddr
);
4950 readl(phba
->CAregaddr
); /* flush */
4952 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4953 /* First read mbox status word */
4954 word0
= *((uint32_t *)phba
->mbox
);
4955 word0
= le32_to_cpu(word0
);
4957 /* First read mbox status word */
4958 word0
= readl(phba
->MBslimaddr
);
4961 /* Read the HBA Host Attention Register */
4962 ha_copy
= readl(phba
->HAregaddr
);
4963 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
4967 /* Wait for command to complete */
4968 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
4969 (!(ha_copy
& HA_MBATT
) &&
4970 (phba
->link_state
> LPFC_WARM_START
))) {
4971 if (time_after(jiffies
, timeout
)) {
4972 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4973 spin_unlock_irqrestore(&phba
->hbalock
,
4975 goto out_not_finished
;
4978 /* Check if we took a mbox interrupt while we were
4980 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
4981 && (evtctr
!= psli
->slistat
.mbox_event
))
4985 spin_unlock_irqrestore(&phba
->hbalock
,
4988 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
4991 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4992 /* First copy command data */
4993 word0
= *((uint32_t *)phba
->mbox
);
4994 word0
= le32_to_cpu(word0
);
4995 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4998 /* Check real SLIM for any errors */
4999 slimword0
= readl(phba
->MBslimaddr
);
5000 slimmb
= (MAILBOX_t
*) & slimword0
;
5001 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
5002 && slimmb
->mbxStatus
) {
5009 /* First copy command data */
5010 word0
= readl(phba
->MBslimaddr
);
5012 /* Read the HBA Host Attention Register */
5013 ha_copy
= readl(phba
->HAregaddr
);
5016 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5017 /* copy results back to user */
5018 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
5019 /* Copy the mailbox extension data */
5020 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
5021 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
5023 pmbox
->out_ext_byte_len
);
5026 /* First copy command data */
5027 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
5029 /* Copy the mailbox extension data */
5030 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
5031 lpfc_memcpy_from_slim(pmbox
->context2
,
5033 MAILBOX_HBA_EXT_OFFSET
,
5034 pmbox
->out_ext_byte_len
);
5038 writel(HA_MBATT
, phba
->HAregaddr
);
5039 readl(phba
->HAregaddr
); /* flush */
5041 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5042 status
= mb
->mbxStatus
;
5045 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5049 if (processing_queue
) {
5050 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5051 lpfc_mbox_cmpl_put(phba
, pmbox
);
5053 return MBX_NOT_FINISHED
;
5057 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
5058 * @phba: Pointer to HBA context object.
5060 * The function blocks the posting of SLI4 asynchronous mailbox commands from
5061 * the driver internal pending mailbox queue. It will then try to wait out the
5062 * possible outstanding mailbox command before return.
5065 * 0 - the outstanding mailbox command completed; otherwise, the wait for
5066 * the outstanding mailbox command timed out.
5069 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
5071 struct lpfc_sli
*psli
= &phba
->sli
;
5072 uint8_t actcmd
= MBX_HEARTBEAT
;
5074 unsigned long timeout
;
5076 /* Mark the asynchronous mailbox command posting as blocked */
5077 spin_lock_irq(&phba
->hbalock
);
5078 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
5079 if (phba
->sli
.mbox_active
)
5080 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
5081 spin_unlock_irq(&phba
->hbalock
);
5082 /* Determine how long we might wait for the active mailbox
5083 * command to be gracefully completed by firmware.
5085 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) * 1000) +
5087 /* Wait for the outstnading mailbox command to complete */
5088 while (phba
->sli
.mbox_active
) {
5089 /* Check active mailbox complete status every 2ms */
5091 if (time_after(jiffies
, timeout
)) {
5092 /* Timeout, marked the outstanding cmd not complete */
5098 /* Can not cleanly block async mailbox command, fails it */
5100 spin_lock_irq(&phba
->hbalock
);
5101 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5102 spin_unlock_irq(&phba
->hbalock
);
5108 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
5109 * @phba: Pointer to HBA context object.
5111 * The function unblocks and resume posting of SLI4 asynchronous mailbox
5112 * commands from the driver internal pending mailbox queue. It makes sure
5113 * that there is no outstanding mailbox command before resuming posting
5114 * asynchronous mailbox commands. If, for any reason, there is outstanding
5115 * mailbox command, it will try to wait it out before resuming asynchronous
5116 * mailbox command posting.
5119 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
5121 struct lpfc_sli
*psli
= &phba
->sli
;
5123 spin_lock_irq(&phba
->hbalock
);
5124 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5125 /* Asynchronous mailbox posting is not blocked, do nothing */
5126 spin_unlock_irq(&phba
->hbalock
);
5130 /* Outstanding synchronous mailbox command is guaranteed to be done,
5131 * successful or timeout, after timing-out the outstanding mailbox
5132 * command shall always be removed, so just unblock posting async
5133 * mailbox command and resume
5135 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5136 spin_unlock_irq(&phba
->hbalock
);
5138 /* wake up worker thread to post asynchronlous mailbox command */
5139 lpfc_worker_wake_up(phba
);
5143 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5144 * @phba: Pointer to HBA context object.
5145 * @mboxq: Pointer to mailbox object.
5147 * The function posts a mailbox to the port. The mailbox is expected
5148 * to be comletely filled in and ready for the port to operate on it.
5149 * This routine executes a synchronous completion operation on the
5150 * mailbox by polling for its completion.
5152 * The caller must not be holding any locks when calling this routine.
5155 * MBX_SUCCESS - mailbox posted successfully
5156 * Any of the MBX error values.
5159 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
5161 int rc
= MBX_SUCCESS
;
5162 unsigned long iflag
;
5164 uint32_t mcqe_status
;
5166 unsigned long timeout
;
5167 struct lpfc_sli
*psli
= &phba
->sli
;
5168 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
5169 struct lpfc_bmbx_create
*mbox_rgn
;
5170 struct dma_address
*dma_address
;
5171 struct lpfc_register bmbx_reg
;
5174 * Only one mailbox can be active to the bootstrap mailbox region
5175 * at a time and there is no queueing provided.
5177 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5178 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5179 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5180 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5181 "(%d):2532 Mailbox command x%x (x%x) "
5182 "cannot issue Data: x%x x%x\n",
5183 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5184 mboxq
->u
.mb
.mbxCommand
,
5185 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5186 psli
->sli_flag
, MBX_POLL
);
5187 return MBXERR_ERROR
;
5189 /* The server grabs the token and owns it until release */
5190 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5191 phba
->sli
.mbox_active
= mboxq
;
5192 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5195 * Initialize the bootstrap memory region to avoid stale data areas
5196 * in the mailbox post. Then copy the caller's mailbox contents to
5197 * the bmbx mailbox region.
5199 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
5200 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
5201 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
5202 sizeof(struct lpfc_mqe
));
5204 /* Post the high mailbox dma address to the port and wait for ready. */
5205 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
5206 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
5208 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5211 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5212 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5216 if (time_after(jiffies
, timeout
)) {
5220 } while (!db_ready
);
5222 /* Post the low mailbox dma address to the port. */
5223 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
5224 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5227 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5228 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5232 if (time_after(jiffies
, timeout
)) {
5236 } while (!db_ready
);
5239 * Read the CQ to ensure the mailbox has completed.
5240 * If so, update the mailbox status so that the upper layers
5241 * can complete the request normally.
5243 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
5244 sizeof(struct lpfc_mqe
));
5245 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
5246 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
5247 sizeof(struct lpfc_mcqe
));
5248 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
5250 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5251 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
5252 bf_set(lpfc_mqe_status
, mb
, LPFC_MBX_ERROR_RANGE
| mcqe_status
);
5256 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5257 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5258 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5259 " x%x x%x CQ: x%x x%x x%x x%x\n",
5260 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5261 mbx_cmnd
, lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5262 bf_get(lpfc_mqe_status
, mb
),
5263 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
5264 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
5265 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
5266 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
5267 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
5268 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
5269 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
5270 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5271 mboxq
->mcqe
.trailer
);
5273 /* We are holding the token, no needed for lock when release */
5274 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5275 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5276 phba
->sli
.mbox_active
= NULL
;
5277 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5282 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5283 * @phba: Pointer to HBA context object.
5284 * @pmbox: Pointer to mailbox object.
5285 * @flag: Flag indicating how the mailbox need to be processed.
5287 * This function is called by discovery code and HBA management code to submit
5288 * a mailbox command to firmware with SLI-4 interface spec.
5290 * Return codes the caller owns the mailbox command after the return of the
5294 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5297 struct lpfc_sli
*psli
= &phba
->sli
;
5298 unsigned long iflags
;
5301 rc
= lpfc_mbox_dev_check(phba
);
5303 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5304 "(%d):2544 Mailbox command x%x (x%x) "
5305 "cannot issue Data: x%x x%x\n",
5306 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5307 mboxq
->u
.mb
.mbxCommand
,
5308 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5309 psli
->sli_flag
, flag
);
5310 goto out_not_finished
;
5313 /* Detect polling mode and jump to a handler */
5314 if (!phba
->sli4_hba
.intr_enable
) {
5315 if (flag
== MBX_POLL
)
5316 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5319 if (rc
!= MBX_SUCCESS
)
5320 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5321 "(%d):2541 Mailbox command x%x "
5322 "(x%x) cannot issue Data: x%x x%x\n",
5323 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5324 mboxq
->u
.mb
.mbxCommand
,
5325 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5326 psli
->sli_flag
, flag
);
5328 } else if (flag
== MBX_POLL
) {
5329 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
5330 "(%d):2542 Try to issue mailbox command "
5331 "x%x (x%x) synchronously ahead of async"
5332 "mailbox command queue: x%x x%x\n",
5333 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5334 mboxq
->u
.mb
.mbxCommand
,
5335 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5336 psli
->sli_flag
, flag
);
5337 /* Try to block the asynchronous mailbox posting */
5338 rc
= lpfc_sli4_async_mbox_block(phba
);
5340 /* Successfully blocked, now issue sync mbox cmd */
5341 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5342 if (rc
!= MBX_SUCCESS
)
5343 lpfc_printf_log(phba
, KERN_ERR
,
5345 "(%d):2597 Mailbox command "
5346 "x%x (x%x) cannot issue "
5349 mboxq
->vport
->vpi
: 0,
5350 mboxq
->u
.mb
.mbxCommand
,
5351 lpfc_sli4_mbox_opcode_get(phba
,
5353 psli
->sli_flag
, flag
);
5354 /* Unblock the async mailbox posting afterward */
5355 lpfc_sli4_async_mbox_unblock(phba
);
5360 /* Now, interrupt mode asynchrous mailbox command */
5361 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
5363 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5364 "(%d):2543 Mailbox command x%x (x%x) "
5365 "cannot issue Data: x%x x%x\n",
5366 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5367 mboxq
->u
.mb
.mbxCommand
,
5368 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5369 psli
->sli_flag
, flag
);
5370 goto out_not_finished
;
5373 /* Put the mailbox command to the driver internal FIFO */
5374 psli
->slistat
.mbox_busy
++;
5375 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5376 lpfc_mbox_put(phba
, mboxq
);
5377 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5378 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5379 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5380 "x%x (x%x) x%x x%x x%x\n",
5381 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
5382 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5383 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5384 phba
->pport
->port_state
,
5385 psli
->sli_flag
, MBX_NOWAIT
);
5386 /* Wake up worker thread to transport mailbox command from head */
5387 lpfc_worker_wake_up(phba
);
5392 return MBX_NOT_FINISHED
;
5396 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5397 * @phba: Pointer to HBA context object.
5399 * This function is called by worker thread to send a mailbox command to
5400 * SLI4 HBA firmware.
5404 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
5406 struct lpfc_sli
*psli
= &phba
->sli
;
5407 LPFC_MBOXQ_t
*mboxq
;
5408 int rc
= MBX_SUCCESS
;
5409 unsigned long iflags
;
5410 struct lpfc_mqe
*mqe
;
5413 /* Check interrupt mode before post async mailbox command */
5414 if (unlikely(!phba
->sli4_hba
.intr_enable
))
5415 return MBX_NOT_FINISHED
;
5417 /* Check for mailbox command service token */
5418 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5419 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5420 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5421 return MBX_NOT_FINISHED
;
5423 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5424 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5425 return MBX_NOT_FINISHED
;
5427 if (unlikely(phba
->sli
.mbox_active
)) {
5428 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5429 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5430 "0384 There is pending active mailbox cmd\n");
5431 return MBX_NOT_FINISHED
;
5433 /* Take the mailbox command service token */
5434 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5436 /* Get the next mailbox command from head of queue */
5437 mboxq
= lpfc_mbox_get(phba
);
5439 /* If no more mailbox command waiting for post, we're done */
5441 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5442 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5445 phba
->sli
.mbox_active
= mboxq
;
5446 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5448 /* Check device readiness for posting mailbox command */
5449 rc
= lpfc_mbox_dev_check(phba
);
5451 /* Driver clean routine will clean up pending mailbox */
5452 goto out_not_finished
;
5454 /* Prepare the mbox command to be posted */
5455 mqe
= &mboxq
->u
.mqe
;
5456 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
5458 /* Start timer for the mbox_tmo and log some mailbox post messages */
5459 mod_timer(&psli
->mbox_tmo
, (jiffies
+
5460 (HZ
* lpfc_mbox_tmo_val(phba
, mbx_cmnd
))));
5462 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5463 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5465 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
5466 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5467 phba
->pport
->port_state
, psli
->sli_flag
);
5469 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
5471 lpfc_debugfs_disc_trc(mboxq
->vport
,
5472 LPFC_DISC_TRC_MBOX_VPORT
,
5473 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5474 mbx_cmnd
, mqe
->un
.mb_words
[0],
5475 mqe
->un
.mb_words
[1]);
5477 lpfc_debugfs_disc_trc(phba
->pport
,
5479 "MBOX Send: cmd:x%x mb:x%x x%x",
5480 mbx_cmnd
, mqe
->un
.mb_words
[0],
5481 mqe
->un
.mb_words
[1]);
5484 psli
->slistat
.mbox_cmd
++;
5486 /* Post the mailbox command to the port */
5487 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
5488 if (rc
!= MBX_SUCCESS
) {
5489 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5490 "(%d):2533 Mailbox command x%x (x%x) "
5491 "cannot issue Data: x%x x%x\n",
5492 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5493 mboxq
->u
.mb
.mbxCommand
,
5494 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5495 psli
->sli_flag
, MBX_NOWAIT
);
5496 goto out_not_finished
;
5502 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5503 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5504 __lpfc_mbox_cmpl_put(phba
, mboxq
);
5505 /* Release the token */
5506 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5507 phba
->sli
.mbox_active
= NULL
;
5508 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5510 return MBX_NOT_FINISHED
;
5514 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5515 * @phba: Pointer to HBA context object.
5516 * @pmbox: Pointer to mailbox object.
5517 * @flag: Flag indicating how the mailbox need to be processed.
5519 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5520 * the API jump table function pointer from the lpfc_hba struct.
5522 * Return codes the caller owns the mailbox command after the return of the
5526 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
5528 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
5532 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5533 * @phba: The hba struct for which this call is being executed.
5534 * @dev_grp: The HBA PCI-Device group number.
5536 * This routine sets up the mbox interface API function jump table in @phba
5538 * Returns: 0 - success, -ENODEV - failure.
5541 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5545 case LPFC_PCI_DEV_LP
:
5546 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
5547 phba
->lpfc_sli_handle_slow_ring_event
=
5548 lpfc_sli_handle_slow_ring_event_s3
;
5549 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
5550 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
5551 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
5553 case LPFC_PCI_DEV_OC
:
5554 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
5555 phba
->lpfc_sli_handle_slow_ring_event
=
5556 lpfc_sli_handle_slow_ring_event_s4
;
5557 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
5558 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
5559 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
5562 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5563 "1420 Invalid HBA PCI-device group: 0x%x\n",
5572 * __lpfc_sli_ringtx_put - Add an iocb to the txq
5573 * @phba: Pointer to HBA context object.
5574 * @pring: Pointer to driver SLI ring object.
5575 * @piocb: Pointer to address of newly added command iocb.
5577 * This function is called with hbalock held to add a command
5578 * iocb to the txq when SLI layer cannot submit the command iocb
5582 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5583 struct lpfc_iocbq
*piocb
)
5585 /* Insert the caller's iocb in the txq tail for later processing. */
5586 list_add_tail(&piocb
->list
, &pring
->txq
);
5591 * lpfc_sli_next_iocb - Get the next iocb in the txq
5592 * @phba: Pointer to HBA context object.
5593 * @pring: Pointer to driver SLI ring object.
5594 * @piocb: Pointer to address of newly added command iocb.
5596 * This function is called with hbalock held before a new
5597 * iocb is submitted to the firmware. This function checks
5598 * txq to flush the iocbs in txq to Firmware before
5599 * submitting new iocbs to the Firmware.
5600 * If there are iocbs in the txq which need to be submitted
5601 * to firmware, lpfc_sli_next_iocb returns the first element
5602 * of the txq after dequeuing it from txq.
5603 * If there is no iocb in the txq then the function will return
5604 * *piocb and *piocb is set to NULL. Caller needs to check
5605 * *piocb to find if there are more commands in the txq.
5607 static struct lpfc_iocbq
*
5608 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5609 struct lpfc_iocbq
**piocb
)
5611 struct lpfc_iocbq
* nextiocb
;
5613 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
5623 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
5624 * @phba: Pointer to HBA context object.
5625 * @ring_number: SLI ring number to issue iocb on.
5626 * @piocb: Pointer to command iocb.
5627 * @flag: Flag indicating if this command can be put into txq.
5629 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
5630 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
5631 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
5632 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
5633 * this function allows only iocbs for posting buffers. This function finds
5634 * next available slot in the command ring and posts the command to the
5635 * available slot and writes the port attention register to request HBA start
5636 * processing new iocb. If there is no slot available in the ring and
5637 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
5638 * the function returns IOCB_BUSY.
5640 * This function is called with hbalock held. The function will return success
5641 * after it successfully submit the iocb to firmware or after adding to the
5645 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
5646 struct lpfc_iocbq
*piocb
, uint32_t flag
)
5648 struct lpfc_iocbq
*nextiocb
;
5650 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
5652 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
5653 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
5654 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
5655 lpfc_printf_log(phba
, KERN_ERR
,
5656 LOG_SLI
| LOG_VPORT
,
5657 "1807 IOCB x%x failed. No vport\n",
5658 piocb
->iocb
.ulpCommand
);
5664 /* If the PCI channel is in offline state, do not post iocbs. */
5665 if (unlikely(pci_channel_offline(phba
->pcidev
)))
5668 /* If HBA has a deferred error attention, fail the iocb. */
5669 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
5673 * We should never get an IOCB if we are in a < LINK_DOWN state
5675 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
5679 * Check to see if we are blocking IOCB processing because of a
5680 * outstanding event.
5682 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
5685 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
5687 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
5688 * can be issued if the link is not up.
5690 switch (piocb
->iocb
.ulpCommand
) {
5691 case CMD_GEN_REQUEST64_CR
:
5692 case CMD_GEN_REQUEST64_CX
:
5693 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
5694 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
5695 FC_RCTL_DD_UNSOL_CMD
) ||
5696 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
5697 MENLO_TRANSPORT_TYPE
))
5701 case CMD_QUE_RING_BUF_CN
:
5702 case CMD_QUE_RING_BUF64_CN
:
5704 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
5705 * completion, iocb_cmpl MUST be 0.
5707 if (piocb
->iocb_cmpl
)
5708 piocb
->iocb_cmpl
= NULL
;
5710 case CMD_CREATE_XRI_CR
:
5711 case CMD_CLOSE_XRI_CN
:
5712 case CMD_CLOSE_XRI_CX
:
5719 * For FCP commands, we must be in a state where we can process link
5722 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
5723 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
5727 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
5728 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
5729 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
5732 lpfc_sli_update_ring(phba
, pring
);
5734 lpfc_sli_update_full_ring(phba
, pring
);
5737 return IOCB_SUCCESS
;
5742 pring
->stats
.iocb_cmd_delay
++;
5746 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
5747 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
5748 return IOCB_SUCCESS
;
5755 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
5756 * @phba: Pointer to HBA context object.
5757 * @piocb: Pointer to command iocb.
5758 * @sglq: Pointer to the scatter gather queue object.
5760 * This routine converts the bpl or bde that is in the IOCB
5761 * to a sgl list for the sli4 hardware. The physical address
5762 * of the bpl/bde is converted back to a virtual address.
5763 * If the IOCB contains a BPL then the list of BDE's is
5764 * converted to sli4_sge's. If the IOCB contains a single
5765 * BDE then it is converted to a single sli_sge.
5766 * The IOCB is still in cpu endianess so the contents of
5767 * the bpl can be used without byte swapping.
5769 * Returns valid XRI = Success, NO_XRI = Failure.
5772 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
5773 struct lpfc_sglq
*sglq
)
5775 uint16_t xritag
= NO_XRI
;
5776 struct ulp_bde64
*bpl
= NULL
;
5777 struct ulp_bde64 bde
;
5778 struct sli4_sge
*sgl
= NULL
;
5783 if (!piocbq
|| !sglq
)
5786 sgl
= (struct sli4_sge
*)sglq
->sgl
;
5787 icmd
= &piocbq
->iocb
;
5788 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
5789 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
5790 sizeof(struct ulp_bde64
);
5791 /* The addrHigh and addrLow fields within the IOCB
5792 * have not been byteswapped yet so there is no
5793 * need to swap them back.
5795 bpl
= (struct ulp_bde64
*)
5796 ((struct lpfc_dmabuf
*)piocbq
->context3
)->virt
;
5801 for (i
= 0; i
< numBdes
; i
++) {
5802 /* Should already be byte swapped. */
5803 sgl
->addr_hi
= bpl
->addrHigh
;
5804 sgl
->addr_lo
= bpl
->addrLow
;
5806 if ((i
+1) == numBdes
)
5807 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
5809 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
5810 sgl
->word2
= cpu_to_le32(sgl
->word2
);
5811 /* swap the size field back to the cpu so we
5812 * can assign it to the sgl.
5814 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5815 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
5819 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
5820 /* The addrHigh and addrLow fields of the BDE have not
5821 * been byteswapped yet so they need to be swapped
5822 * before putting them in the sgl.
5825 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
5827 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
5828 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
5829 sgl
->word2
= cpu_to_le32(sgl
->word2
);
5831 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
5833 return sglq
->sli4_xritag
;
5837 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5838 * @phba: Pointer to HBA context object.
5840 * This routine performs a round robin SCSI command to SLI4 FCP WQ index
5841 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
5844 * Return: index into SLI4 fast-path FCP queue index.
5847 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
5850 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
5853 return phba
->fcp_qidx
;
5857 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
5858 * @phba: Pointer to HBA context object.
5859 * @piocb: Pointer to command iocb.
5860 * @wqe: Pointer to the work queue entry.
5862 * This routine converts the iocb command to its Work Queue Entry
5863 * equivalent. The wqe pointer should not have any fields set when
5864 * this routine is called because it will memcpy over them.
5865 * This routine does not set the CQ_ID or the WQEC bits in the
5868 * Returns: 0 = Success, IOCB_ERROR = Failure.
5871 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
5872 union lpfc_wqe
*wqe
)
5874 uint32_t xmit_len
= 0, total_len
= 0;
5878 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
5881 struct ulp_bde64
*bpl
= NULL
;
5882 uint32_t els_id
= ELS_ID_DEFAULT
;
5884 struct ulp_bde64 bde
;
5886 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
5887 /* The fcp commands will set command type */
5888 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
5889 command_type
= FCP_COMMAND
;
5890 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
5891 command_type
= ELS_COMMAND_FIP
;
5893 command_type
= ELS_COMMAND_NON_FIP
;
5895 /* Some of the fields are in the right position already */
5896 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
5897 abort_tag
= (uint32_t) iocbq
->iotag
;
5898 xritag
= iocbq
->sli4_xritag
;
5899 wqe
->words
[7] = 0; /* The ct field has moved so reset */
5900 /* words0-2 bpl convert bde */
5901 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
5902 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
5903 sizeof(struct ulp_bde64
);
5904 bpl
= (struct ulp_bde64
*)
5905 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
5909 /* Should already be byte swapped. */
5910 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
5911 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
5912 /* swap the size field back to the cpu so we
5913 * can assign it to the sgl.
5915 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5916 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
5918 for (i
= 0; i
< numBdes
; i
++) {
5919 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
5920 total_len
+= bde
.tus
.f
.bdeSize
;
5923 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
5925 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
5926 cmnd
= iocbq
->iocb
.ulpCommand
;
5928 switch (iocbq
->iocb
.ulpCommand
) {
5929 case CMD_ELS_REQUEST64_CR
:
5930 if (!iocbq
->iocb
.ulpLe
) {
5931 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5932 "2007 Only Limited Edition cmd Format"
5933 " supported 0x%x\n",
5934 iocbq
->iocb
.ulpCommand
);
5937 wqe
->els_req
.payload_len
= xmit_len
;
5938 /* Els_reguest64 has a TMO */
5939 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
5940 iocbq
->iocb
.ulpTimeout
);
5941 /* Need a VF for word 4 set the vf bit*/
5942 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
5943 /* And a VFID for word 12 */
5944 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
5946 * Set ct field to 3, indicates that the context_tag field
5947 * contains the FCFI and remote N_Port_ID is
5951 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
5952 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
5953 iocbq
->iocb
.ulpContext
);
5955 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
, ct
);
5956 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5957 /* CCP CCPE PV PRI in word10 were set in the memcpy */
5959 if (command_type
== ELS_COMMAND_FIP
) {
5960 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
5961 >> LPFC_FIP_ELS_ID_SHIFT
);
5963 bf_set(lpfc_wqe_gen_els_id
, &wqe
->generic
, els_id
);
5966 case CMD_XMIT_SEQUENCE64_CX
:
5967 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
5968 iocbq
->iocb
.un
.ulpWord
[3]);
5969 wqe
->generic
.word3
= 0;
5970 bf_set(wqe_rcvoxid
, &wqe
->generic
, iocbq
->iocb
.ulpContext
);
5971 /* The entire sequence is transmitted for this IOCB */
5972 xmit_len
= total_len
;
5973 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
5974 case CMD_XMIT_SEQUENCE64_CR
:
5975 /* word3 iocb=io_tag32 wqe=payload_offset */
5976 /* payload offset used for multilpe outstanding
5977 * sequences on the same exchange
5980 /* word4 relative_offset memcpy */
5981 /* word5 r_ctl/df_ctl memcpy */
5982 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5983 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
5984 command_type
= OTHER_COMMAND
;
5986 case CMD_XMIT_BCAST64_CN
:
5987 /* word3 iocb=iotag32 wqe=payload_len */
5988 wqe
->words
[3] = 0; /* no definition for this in wqe */
5989 /* word4 iocb=rsvd wqe=rsvd */
5990 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
5991 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
5992 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
5993 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
5995 case CMD_FCP_IWRITE64_CR
:
5996 command_type
= FCP_COMMAND_DATA_OUT
;
5997 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
5999 * word3 is payload_len: byte offset to the sgl entry for the
6001 * word4 is total xfer len, same as the IOCB->ulpParameter.
6002 * word5 is initial xfer len 0 = wait for xfer-ready
6005 /* Always wait for xfer-ready before sending data */
6006 wqe
->fcp_iwrite
.initial_xfer_len
= 0;
6007 /* word 4 (xfer length) should have been set on the memcpy */
6009 /* allow write to fall through to read */
6010 case CMD_FCP_IREAD64_CR
:
6011 /* FCP_CMD is always the 1st sgl entry */
6012 wqe
->fcp_iread
.payload_len
=
6013 xmit_len
+ sizeof(struct fcp_rsp
);
6015 /* word 4 (xfer length) should have been set on the memcpy */
6017 bf_set(lpfc_wqe_gen_erp
, &wqe
->generic
,
6018 iocbq
->iocb
.ulpFCP2Rcvy
);
6019 bf_set(lpfc_wqe_gen_lnk
, &wqe
->generic
, iocbq
->iocb
.ulpXS
);
6020 /* The XC bit and the XS bit are similar. The driver never
6021 * tracked whether or not the exchange was previouslly open.
6022 * XC = Exchange create, 0 is create. 1 is already open.
6023 * XS = link cmd: 1 do not close the exchange after command.
6024 * XS = 0 close exchange when command completes.
6025 * The only time we would not set the XC bit is when the XS bit
6026 * is set and we are sending our 2nd or greater command on
6029 /* Always open the exchange */
6030 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
6032 wqe
->words
[10] &= 0xffff0000; /* zero out ebde count */
6033 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6035 case CMD_FCP_ICMND64_CR
:
6036 /* Always open the exchange */
6037 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
6040 wqe
->words
[10] &= 0xffff0000; /* zero out ebde count */
6041 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
6043 case CMD_GEN_REQUEST64_CR
:
6044 /* word3 command length is described as byte offset to the
6045 * rsp_data. Would always be 16, sizeof(struct sli4_sge)
6050 wqe
->gen_req
.command_len
= xmit_len
;
6051 /* Word4 parameter copied in the memcpy */
6052 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
6053 /* word6 context tag copied in memcpy */
6054 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
6055 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
6056 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6057 "2015 Invalid CT %x command 0x%x\n",
6058 ct
, iocbq
->iocb
.ulpCommand
);
6061 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
, 0);
6062 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
,
6063 iocbq
->iocb
.ulpTimeout
);
6065 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6066 command_type
= OTHER_COMMAND
;
6068 case CMD_XMIT_ELS_RSP64_CX
:
6069 /* words0-2 BDE memcpy */
6070 /* word3 iocb=iotag32 wqe=rsvd */
6072 /* word4 iocb=did wge=rsvd. */
6074 /* word5 iocb=rsvd wge=did */
6075 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
6076 iocbq
->iocb
.un
.elsreq64
.remoteID
);
6078 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6079 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6081 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6082 bf_set(wqe_rcvoxid
, &wqe
->generic
, iocbq
->iocb
.ulpContext
);
6083 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
6084 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
6085 iocbq
->vport
->vpi
+ phba
->vpi_base
);
6086 command_type
= OTHER_COMMAND
;
6088 case CMD_CLOSE_XRI_CN
:
6089 case CMD_ABORT_XRI_CN
:
6090 case CMD_ABORT_XRI_CX
:
6091 /* words 0-2 memcpy should be 0 rserved */
6092 /* port will send abts */
6093 if (iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6095 * The link is down so the fw does not need to send abts
6098 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
6100 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
6101 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
6103 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6104 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6105 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
6107 * The abort handler will send us CMD_ABORT_XRI_CN or
6108 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6110 bf_set(lpfc_wqe_gen_command
, &wqe
->generic
, CMD_ABORT_XRI_CX
);
6111 cmnd
= CMD_ABORT_XRI_CX
;
6112 command_type
= OTHER_COMMAND
;
6115 case CMD_XMIT_BLS_RSP64_CX
:
6116 /* As BLS ABTS-ACC WQE is very different from other WQEs,
6117 * we re-construct this WQE here based on information in
6118 * iocbq from scratch.
6120 memset(wqe
, 0, sizeof(union lpfc_wqe
));
6121 /* OX_ID is invariable to who sent ABTS to CT exchange */
6122 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
6123 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_acc
));
6124 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_acc
) ==
6125 LPFC_ABTS_UNSOL_INT
) {
6126 /* ABTS sent by initiator to CT exchange, the
6127 * RX_ID field will be filled with the newly
6128 * allocated responder XRI.
6130 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
6131 iocbq
->sli4_xritag
);
6133 /* ABTS sent by responder to CT exchange, the
6134 * RX_ID field will be filled with the responder
6137 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
6138 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_acc
));
6140 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
6141 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
6142 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
6143 iocbq
->iocb
.ulpContext
);
6144 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
6145 command_type
= OTHER_COMMAND
;
6147 case CMD_XRI_ABORTED_CX
:
6148 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
6149 /* words0-2 are all 0's no bde */
6150 /* word3 and word4 are rsvrd */
6153 /* word5 iocb=rsvd wge=did */
6154 /* There is no remote port id in the IOCB? */
6155 /* Let this fall through and fail */
6156 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
6157 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
6158 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
6159 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
6161 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6162 "2014 Invalid command 0x%x\n",
6163 iocbq
->iocb
.ulpCommand
);
6168 bf_set(lpfc_wqe_gen_xri
, &wqe
->generic
, xritag
);
6169 bf_set(lpfc_wqe_gen_request_tag
, &wqe
->generic
, iocbq
->iotag
);
6170 wqe
->generic
.abort_tag
= abort_tag
;
6171 bf_set(lpfc_wqe_gen_cmd_type
, &wqe
->generic
, command_type
);
6172 bf_set(lpfc_wqe_gen_command
, &wqe
->generic
, cmnd
);
6173 bf_set(lpfc_wqe_gen_class
, &wqe
->generic
, iocbq
->iocb
.ulpClass
);
6174 bf_set(lpfc_wqe_gen_cq_id
, &wqe
->generic
, LPFC_WQE_CQ_ID_DEFAULT
);
6180 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
6181 * @phba: Pointer to HBA context object.
6182 * @ring_number: SLI ring number to issue iocb on.
6183 * @piocb: Pointer to command iocb.
6184 * @flag: Flag indicating if this command can be put into txq.
6186 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
6187 * an iocb command to an HBA with SLI-4 interface spec.
6189 * This function is called with hbalock held. The function will return success
6190 * after it successfully submit the iocb to firmware or after adding to the
6194 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
6195 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6197 struct lpfc_sglq
*sglq
;
6200 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
6202 if (piocb
->sli4_xritag
== NO_XRI
) {
6203 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
6204 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6207 sglq
= __lpfc_sli_get_sglq(phba
);
6210 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
6212 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
6213 sglq
= NULL
; /* These IO's already have an XRI and
6217 /* This is a continuation of a commandi,(CX) so this
6218 * sglq is on the active list
6220 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
6226 xritag
= lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
);
6227 if (xritag
!= sglq
->sli4_xritag
)
6231 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
6234 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
6235 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
6237 * For FCP command IOCB, get a new WQ index to distribute
6238 * WQE across the WQsr. On the other hand, for abort IOCB,
6239 * it carries the same WQ index to the original command
6242 if (piocb
->iocb_flag
& LPFC_IO_FCP
)
6243 piocb
->fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
6244 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
6248 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
6251 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
6257 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6259 * This routine wraps the actual lockless version for issusing IOCB function
6260 * pointer from the lpfc_hba struct.
6263 * IOCB_ERROR - Error
6264 * IOCB_SUCCESS - Success
6268 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6269 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6271 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6275 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6276 * @phba: The hba struct for which this call is being executed.
6277 * @dev_grp: The HBA PCI-Device group number.
6279 * This routine sets up the SLI interface API function jump table in @phba
6281 * Returns: 0 - success, -ENODEV - failure.
6284 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6288 case LPFC_PCI_DEV_LP
:
6289 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
6290 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
6292 case LPFC_PCI_DEV_OC
:
6293 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
6294 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
6297 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6298 "1419 Invalid HBA PCI-device group: 0x%x\n",
6303 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
6308 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6309 * @phba: Pointer to HBA context object.
6310 * @pring: Pointer to driver SLI ring object.
6311 * @piocb: Pointer to command iocb.
6312 * @flag: Flag indicating if this command can be put into txq.
6314 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6315 * function. This function gets the hbalock and calls
6316 * __lpfc_sli_issue_iocb function and will return the error returned
6317 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6318 * functions which do not hold hbalock.
6321 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6322 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6324 unsigned long iflags
;
6327 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6328 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6329 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6335 * lpfc_extra_ring_setup - Extra ring setup function
6336 * @phba: Pointer to HBA context object.
6338 * This function is called while driver attaches with the
6339 * HBA to setup the extra ring. The extra ring is used
6340 * only when driver needs to support target mode functionality
6341 * or IP over FC functionalities.
6343 * This function is called with no lock held.
6346 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
6348 struct lpfc_sli
*psli
;
6349 struct lpfc_sli_ring
*pring
;
6353 /* Adjust cmd/rsp ring iocb entries more evenly */
6355 /* Take some away from the FCP ring */
6356 pring
= &psli
->ring
[psli
->fcp_ring
];
6357 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6358 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6359 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6360 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6362 /* and give them to the extra ring */
6363 pring
= &psli
->ring
[psli
->extra_ring
];
6365 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6366 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6367 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6368 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6370 /* Setup default profile for this ring */
6371 pring
->iotag_max
= 4096;
6372 pring
->num_mask
= 1;
6373 pring
->prt
[0].profile
= 0; /* Mask 0 */
6374 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
6375 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
6376 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
6381 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6382 * @phba: Pointer to HBA context object.
6383 * @pring: Pointer to driver SLI ring object.
6384 * @iocbq: Pointer to iocb object.
6386 * This function is called by the slow ring event handler
6387 * function when there is an ASYNC event iocb in the ring.
6388 * This function is called with no lock held.
6389 * Currently this function handles only temperature related
6390 * ASYNC events. The function decodes the temperature sensor
6391 * event message and posts events for the management applications.
6394 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
6395 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
6400 struct temp_event temp_event_data
;
6401 struct Scsi_Host
*shost
;
6404 icmd
= &iocbq
->iocb
;
6405 evt_code
= icmd
->un
.asyncstat
.evt_code
;
6406 temp
= icmd
->ulpContext
;
6408 if ((evt_code
!= ASYNC_TEMP_WARN
) &&
6409 (evt_code
!= ASYNC_TEMP_SAFE
)) {
6410 iocb_w
= (uint32_t *) icmd
;
6411 lpfc_printf_log(phba
,
6414 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6416 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6417 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6418 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6419 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6421 icmd
->un
.asyncstat
.evt_code
,
6422 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
6423 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
6424 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
6425 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
6429 temp_event_data
.data
= (uint32_t)temp
;
6430 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
6431 if (evt_code
== ASYNC_TEMP_WARN
) {
6432 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
6433 lpfc_printf_log(phba
,
6436 "0347 Adapter is very hot, please take "
6437 "corrective action. temperature : %d Celsius\n",
6440 if (evt_code
== ASYNC_TEMP_SAFE
) {
6441 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
6442 lpfc_printf_log(phba
,
6445 "0340 Adapter temperature is OK now. "
6446 "temperature : %d Celsius\n",
6450 /* Send temperature change event to applications */
6451 shost
= lpfc_shost_from_vport(phba
->pport
);
6452 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6453 sizeof(temp_event_data
), (char *) &temp_event_data
,
6460 * lpfc_sli_setup - SLI ring setup function
6461 * @phba: Pointer to HBA context object.
6463 * lpfc_sli_setup sets up rings of the SLI interface with
6464 * number of iocbs per ring and iotags. This function is
6465 * called while driver attach to the HBA and before the
6466 * interrupts are enabled. So there is no need for locking.
6468 * This function always returns 0.
6471 lpfc_sli_setup(struct lpfc_hba
*phba
)
6473 int i
, totiocbsize
= 0;
6474 struct lpfc_sli
*psli
= &phba
->sli
;
6475 struct lpfc_sli_ring
*pring
;
6477 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
6479 psli
->fcp_ring
= LPFC_FCP_RING
;
6480 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
6481 psli
->extra_ring
= LPFC_EXTRA_RING
;
6483 psli
->iocbq_lookup
= NULL
;
6484 psli
->iocbq_lookup_len
= 0;
6485 psli
->last_iotag
= 0;
6487 for (i
= 0; i
< psli
->num_rings
; i
++) {
6488 pring
= &psli
->ring
[i
];
6490 case LPFC_FCP_RING
: /* ring 0 - FCP */
6491 /* numCiocb and numRiocb are used in config_port */
6492 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
6493 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
6494 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6495 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6496 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6497 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6498 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6499 SLI3_IOCB_CMD_SIZE
:
6501 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6502 SLI3_IOCB_RSP_SIZE
:
6504 pring
->iotag_ctr
= 0;
6506 (phba
->cfg_hba_queue_depth
* 2);
6507 pring
->fast_iotag
= pring
->iotag_max
;
6508 pring
->num_mask
= 0;
6510 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
6511 /* numCiocb and numRiocb are used in config_port */
6512 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
6513 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
6514 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6515 SLI3_IOCB_CMD_SIZE
:
6517 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6518 SLI3_IOCB_RSP_SIZE
:
6520 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
6521 pring
->num_mask
= 0;
6523 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
6524 /* numCiocb and numRiocb are used in config_port */
6525 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
6526 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
6527 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6528 SLI3_IOCB_CMD_SIZE
:
6530 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6531 SLI3_IOCB_RSP_SIZE
:
6533 pring
->fast_iotag
= 0;
6534 pring
->iotag_ctr
= 0;
6535 pring
->iotag_max
= 4096;
6536 pring
->lpfc_sli_rcv_async_status
=
6537 lpfc_sli_async_event_handler
;
6538 pring
->num_mask
= LPFC_MAX_RING_MASK
;
6539 pring
->prt
[0].profile
= 0; /* Mask 0 */
6540 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
6541 pring
->prt
[0].type
= FC_TYPE_ELS
;
6542 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
6543 lpfc_els_unsol_event
;
6544 pring
->prt
[1].profile
= 0; /* Mask 1 */
6545 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
6546 pring
->prt
[1].type
= FC_TYPE_ELS
;
6547 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
6548 lpfc_els_unsol_event
;
6549 pring
->prt
[2].profile
= 0; /* Mask 2 */
6550 /* NameServer Inquiry */
6551 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
6553 pring
->prt
[2].type
= FC_TYPE_CT
;
6554 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
6555 lpfc_ct_unsol_event
;
6556 pring
->prt
[3].profile
= 0; /* Mask 3 */
6557 /* NameServer response */
6558 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
6560 pring
->prt
[3].type
= FC_TYPE_CT
;
6561 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
6562 lpfc_ct_unsol_event
;
6563 /* abort unsolicited sequence */
6564 pring
->prt
[4].profile
= 0; /* Mask 4 */
6565 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
6566 pring
->prt
[4].type
= FC_TYPE_BLS
;
6567 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
6568 lpfc_sli4_ct_abort_unsol_event
;
6571 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
6572 (pring
->numRiocb
* pring
->sizeRiocb
);
6574 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
6575 /* Too many cmd / rsp ring entries in SLI2 SLIM */
6576 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
6577 "SLI2 SLIM Data: x%x x%lx\n",
6578 phba
->brd_no
, totiocbsize
,
6579 (unsigned long) MAX_SLIM_IOCB_SIZE
);
6581 if (phba
->cfg_multi_ring_support
== 2)
6582 lpfc_extra_ring_setup(phba
);
6588 * lpfc_sli_queue_setup - Queue initialization function
6589 * @phba: Pointer to HBA context object.
6591 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
6592 * ring. This function also initializes ring indices of each ring.
6593 * This function is called during the initialization of the SLI
6594 * interface of an HBA.
6595 * This function is called with no lock held and always returns
6599 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
6601 struct lpfc_sli
*psli
;
6602 struct lpfc_sli_ring
*pring
;
6606 spin_lock_irq(&phba
->hbalock
);
6607 INIT_LIST_HEAD(&psli
->mboxq
);
6608 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
6609 /* Initialize list headers for txq and txcmplq as double linked lists */
6610 for (i
= 0; i
< psli
->num_rings
; i
++) {
6611 pring
= &psli
->ring
[i
];
6613 pring
->next_cmdidx
= 0;
6614 pring
->local_getidx
= 0;
6616 INIT_LIST_HEAD(&pring
->txq
);
6617 INIT_LIST_HEAD(&pring
->txcmplq
);
6618 INIT_LIST_HEAD(&pring
->iocb_continueq
);
6619 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
6620 INIT_LIST_HEAD(&pring
->postbufq
);
6622 spin_unlock_irq(&phba
->hbalock
);
6627 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
6628 * @phba: Pointer to HBA context object.
6630 * This routine flushes the mailbox command subsystem. It will unconditionally
6631 * flush all the mailbox commands in the three possible stages in the mailbox
6632 * command sub-system: pending mailbox command queue; the outstanding mailbox
6633 * command; and completed mailbox command queue. It is caller's responsibility
6634 * to make sure that the driver is in the proper state to flush the mailbox
6635 * command sub-system. Namely, the posting of mailbox commands into the
6636 * pending mailbox command queue from the various clients must be stopped;
6637 * either the HBA is in a state that it will never works on the outstanding
6638 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
6639 * mailbox command has been completed.
6642 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
6644 LIST_HEAD(completions
);
6645 struct lpfc_sli
*psli
= &phba
->sli
;
6647 unsigned long iflag
;
6649 /* Flush all the mailbox commands in the mbox system */
6650 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6651 /* The pending mailbox command queue */
6652 list_splice_init(&phba
->sli
.mboxq
, &completions
);
6653 /* The outstanding active mailbox command */
6654 if (psli
->mbox_active
) {
6655 list_add_tail(&psli
->mbox_active
->list
, &completions
);
6656 psli
->mbox_active
= NULL
;
6657 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6659 /* The completed mailbox command queue */
6660 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
6661 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6663 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
6664 while (!list_empty(&completions
)) {
6665 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
6666 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6668 pmb
->mbox_cmpl(phba
, pmb
);
6673 * lpfc_sli_host_down - Vport cleanup function
6674 * @vport: Pointer to virtual port object.
6676 * lpfc_sli_host_down is called to clean up the resources
6677 * associated with a vport before destroying virtual
6678 * port data structures.
6679 * This function does following operations:
6680 * - Free discovery resources associated with this virtual
6682 * - Free iocbs associated with this virtual port in
6684 * - Send abort for all iocb commands associated with this
6687 * This function is called with no lock held and always returns 1.
6690 lpfc_sli_host_down(struct lpfc_vport
*vport
)
6692 LIST_HEAD(completions
);
6693 struct lpfc_hba
*phba
= vport
->phba
;
6694 struct lpfc_sli
*psli
= &phba
->sli
;
6695 struct lpfc_sli_ring
*pring
;
6696 struct lpfc_iocbq
*iocb
, *next_iocb
;
6698 unsigned long flags
= 0;
6699 uint16_t prev_pring_flag
;
6701 lpfc_cleanup_discovery_resources(vport
);
6703 spin_lock_irqsave(&phba
->hbalock
, flags
);
6704 for (i
= 0; i
< psli
->num_rings
; i
++) {
6705 pring
= &psli
->ring
[i
];
6706 prev_pring_flag
= pring
->flag
;
6707 /* Only slow rings */
6708 if (pring
->ringno
== LPFC_ELS_RING
) {
6709 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
6710 /* Set the lpfc data pending flag */
6711 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
6714 * Error everything on the txq since these iocbs have not been
6715 * given to the FW yet.
6717 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
6718 if (iocb
->vport
!= vport
)
6720 list_move_tail(&iocb
->list
, &completions
);
6724 /* Next issue ABTS for everything on the txcmplq */
6725 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
6727 if (iocb
->vport
!= vport
)
6729 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
6732 pring
->flag
= prev_pring_flag
;
6735 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6737 /* Cancel all the IOCBs from the completions list */
6738 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6744 * lpfc_sli_hba_down - Resource cleanup function for the HBA
6745 * @phba: Pointer to HBA context object.
6747 * This function cleans up all iocb, buffers, mailbox commands
6748 * while shutting down the HBA. This function is called with no
6749 * lock held and always returns 1.
6750 * This function does the following to cleanup driver resources:
6751 * - Free discovery resources for each virtual port
6752 * - Cleanup any pending fabric iocbs
6753 * - Iterate through the iocb txq and free each entry
6755 * - Free up any buffer posted to the HBA
6756 * - Free mailbox commands in the mailbox queue.
6759 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
6761 LIST_HEAD(completions
);
6762 struct lpfc_sli
*psli
= &phba
->sli
;
6763 struct lpfc_sli_ring
*pring
;
6764 struct lpfc_dmabuf
*buf_ptr
;
6765 unsigned long flags
= 0;
6768 /* Shutdown the mailbox command sub-system */
6769 lpfc_sli_mbox_sys_shutdown(phba
);
6771 lpfc_hba_down_prep(phba
);
6773 lpfc_fabric_abort_hba(phba
);
6775 spin_lock_irqsave(&phba
->hbalock
, flags
);
6776 for (i
= 0; i
< psli
->num_rings
; i
++) {
6777 pring
= &psli
->ring
[i
];
6778 /* Only slow rings */
6779 if (pring
->ringno
== LPFC_ELS_RING
) {
6780 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
6781 /* Set the lpfc data pending flag */
6782 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
6786 * Error everything on the txq since these iocbs have not been
6787 * given to the FW yet.
6789 list_splice_init(&pring
->txq
, &completions
);
6793 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6795 /* Cancel all the IOCBs from the completions list */
6796 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6799 spin_lock_irqsave(&phba
->hbalock
, flags
);
6800 list_splice_init(&phba
->elsbuf
, &completions
);
6801 phba
->elsbuf_cnt
= 0;
6802 phba
->elsbuf_prev_cnt
= 0;
6803 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6805 while (!list_empty(&completions
)) {
6806 list_remove_head(&completions
, buf_ptr
,
6807 struct lpfc_dmabuf
, list
);
6808 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
6812 /* Return any active mbox cmds */
6813 del_timer_sync(&psli
->mbox_tmo
);
6815 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
6816 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6817 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
6823 * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
6824 * @phba: Pointer to HBA context object.
6826 * This function cleans up all queues, iocb, buffers, mailbox commands while
6827 * shutting down the SLI4 HBA FCoE function. This function is called with no
6828 * lock held and always returns 1.
6830 * This function does the following to cleanup driver FCoE function resources:
6831 * - Free discovery resources for each virtual port
6832 * - Cleanup any pending fabric iocbs
6833 * - Iterate through the iocb txq and free each entry in the list.
6834 * - Free up any buffer posted to the HBA.
6835 * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
6836 * - Free mailbox commands in the mailbox queue.
6839 lpfc_sli4_hba_down(struct lpfc_hba
*phba
)
6841 /* Stop the SLI4 device port */
6842 lpfc_stop_port(phba
);
6844 /* Tear down the queues in the HBA */
6845 lpfc_sli4_queue_unset(phba
);
6847 /* unregister default FCFI from the HBA */
6848 lpfc_sli4_fcfi_unreg(phba
, phba
->fcf
.fcfi
);
6854 * lpfc_sli_pcimem_bcopy - SLI memory copy function
6855 * @srcp: Source memory pointer.
6856 * @destp: Destination memory pointer.
6857 * @cnt: Number of words required to be copied.
6859 * This function is used for copying data between driver memory
6860 * and the SLI memory. This function also changes the endianness
6861 * of each word if native endianness is different from SLI
6862 * endianness. This function can be called with or without
6866 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
6868 uint32_t *src
= srcp
;
6869 uint32_t *dest
= destp
;
6873 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
6875 ldata
= le32_to_cpu(ldata
);
6884 * lpfc_sli_bemem_bcopy - SLI memory copy function
6885 * @srcp: Source memory pointer.
6886 * @destp: Destination memory pointer.
6887 * @cnt: Number of words required to be copied.
6889 * This function is used for copying data between a data structure
6890 * with big endian representation to local endianness.
6891 * This function can be called with or without lock.
6894 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
6896 uint32_t *src
= srcp
;
6897 uint32_t *dest
= destp
;
6901 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
6903 ldata
= be32_to_cpu(ldata
);
6911 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
6912 * @phba: Pointer to HBA context object.
6913 * @pring: Pointer to driver SLI ring object.
6914 * @mp: Pointer to driver buffer object.
6916 * This function is called with no lock held.
6917 * It always return zero after adding the buffer to the postbufq
6921 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6922 struct lpfc_dmabuf
*mp
)
6924 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
6926 spin_lock_irq(&phba
->hbalock
);
6927 list_add_tail(&mp
->list
, &pring
->postbufq
);
6928 pring
->postbufq_cnt
++;
6929 spin_unlock_irq(&phba
->hbalock
);
6934 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
6935 * @phba: Pointer to HBA context object.
6937 * When HBQ is enabled, buffers are searched based on tags. This function
6938 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
6939 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
6940 * does not conflict with tags of buffer posted for unsolicited events.
6941 * The function returns the allocated tag. The function is called with
6945 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
6947 spin_lock_irq(&phba
->hbalock
);
6948 phba
->buffer_tag_count
++;
6950 * Always set the QUE_BUFTAG_BIT to distiguish between
6951 * a tag assigned by HBQ.
6953 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
6954 spin_unlock_irq(&phba
->hbalock
);
6955 return phba
->buffer_tag_count
;
6959 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
6960 * @phba: Pointer to HBA context object.
6961 * @pring: Pointer to driver SLI ring object.
6964 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
6965 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
6966 * iocb is posted to the response ring with the tag of the buffer.
6967 * This function searches the pring->postbufq list using the tag
6968 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
6969 * iocb. If the buffer is found then lpfc_dmabuf object of the
6970 * buffer is returned to the caller else NULL is returned.
6971 * This function is called with no lock held.
6973 struct lpfc_dmabuf
*
6974 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6977 struct lpfc_dmabuf
*mp
, *next_mp
;
6978 struct list_head
*slp
= &pring
->postbufq
;
6980 /* Search postbufq, from the begining, looking for a match on tag */
6981 spin_lock_irq(&phba
->hbalock
);
6982 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
6983 if (mp
->buffer_tag
== tag
) {
6984 list_del_init(&mp
->list
);
6985 pring
->postbufq_cnt
--;
6986 spin_unlock_irq(&phba
->hbalock
);
6991 spin_unlock_irq(&phba
->hbalock
);
6992 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6993 "0402 Cannot find virtual addr for buffer tag on "
6994 "ring %d Data x%lx x%p x%p x%x\n",
6995 pring
->ringno
, (unsigned long) tag
,
6996 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
7002 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
7003 * @phba: Pointer to HBA context object.
7004 * @pring: Pointer to driver SLI ring object.
7005 * @phys: DMA address of the buffer.
7007 * This function searches the buffer list using the dma_address
7008 * of unsolicited event to find the driver's lpfc_dmabuf object
7009 * corresponding to the dma_address. The function returns the
7010 * lpfc_dmabuf object if a buffer is found else it returns NULL.
7011 * This function is called by the ct and els unsolicited event
7012 * handlers to get the buffer associated with the unsolicited
7015 * This function is called with no lock held.
7017 struct lpfc_dmabuf
*
7018 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7021 struct lpfc_dmabuf
*mp
, *next_mp
;
7022 struct list_head
*slp
= &pring
->postbufq
;
7024 /* Search postbufq, from the begining, looking for a match on phys */
7025 spin_lock_irq(&phba
->hbalock
);
7026 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
7027 if (mp
->phys
== phys
) {
7028 list_del_init(&mp
->list
);
7029 pring
->postbufq_cnt
--;
7030 spin_unlock_irq(&phba
->hbalock
);
7035 spin_unlock_irq(&phba
->hbalock
);
7036 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7037 "0410 Cannot find virtual addr for mapped buf on "
7038 "ring %d Data x%llx x%p x%p x%x\n",
7039 pring
->ringno
, (unsigned long long)phys
,
7040 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
7045 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
7046 * @phba: Pointer to HBA context object.
7047 * @cmdiocb: Pointer to driver command iocb object.
7048 * @rspiocb: Pointer to driver response iocb object.
7050 * This function is the completion handler for the abort iocbs for
7051 * ELS commands. This function is called from the ELS ring event
7052 * handler with no lock held. This function frees memory resources
7053 * associated with the abort iocb.
7056 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7057 struct lpfc_iocbq
*rspiocb
)
7059 IOCB_t
*irsp
= &rspiocb
->iocb
;
7060 uint16_t abort_iotag
, abort_context
;
7061 struct lpfc_iocbq
*abort_iocb
;
7062 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7066 if (irsp
->ulpStatus
) {
7067 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
7068 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
7070 spin_lock_irq(&phba
->hbalock
);
7071 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7072 if (abort_iotag
!= 0 &&
7073 abort_iotag
<= phba
->sli
.last_iotag
)
7075 phba
->sli
.iocbq_lookup
[abort_iotag
];
7077 /* For sli4 the abort_tag is the XRI,
7078 * so the abort routine puts the iotag of the iocb
7079 * being aborted in the context field of the abort
7082 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
7084 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_SLI
,
7085 "0327 Cannot abort els iocb %p "
7086 "with tag %x context %x, abort status %x, "
7088 abort_iocb
, abort_iotag
, abort_context
,
7089 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
7092 * If the iocb is not found in Firmware queue the iocb
7093 * might have completed already. Do not free it again.
7095 if (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
7096 if (irsp
->un
.ulpWord
[4] != IOERR_NO_XRI
) {
7097 spin_unlock_irq(&phba
->hbalock
);
7098 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7101 /* For SLI4 the ulpContext field for abort IOCB
7102 * holds the iotag of the IOCB being aborted so
7103 * the local abort_context needs to be reset to
7104 * match the aborted IOCBs ulpContext.
7106 if (abort_iocb
&& phba
->sli_rev
== LPFC_SLI_REV4
)
7107 abort_context
= abort_iocb
->iocb
.ulpContext
;
7110 * make sure we have the right iocbq before taking it
7111 * off the txcmplq and try to call completion routine.
7114 abort_iocb
->iocb
.ulpContext
!= abort_context
||
7115 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
7116 spin_unlock_irq(&phba
->hbalock
);
7117 else if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7119 * leave the SLI4 aborted command on the txcmplq
7120 * list and the command complete WCQE's XB bit
7121 * will tell whether the SGL (XRI) can be released
7122 * immediately or to the aborted SGL list for the
7123 * following abort XRI from the HBA.
7125 list_del_init(&abort_iocb
->list
);
7126 pring
->txcmplq_cnt
--;
7128 /* Firmware could still be in progress of DMAing
7129 * payload, so don't free data buffer till after
7132 abort_iocb
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
7133 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
7134 spin_unlock_irq(&phba
->hbalock
);
7136 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
7137 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_ABORT_REQUESTED
;
7138 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
7140 spin_unlock_irq(&phba
->hbalock
);
7143 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7148 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
7149 * @phba: Pointer to HBA context object.
7150 * @cmdiocb: Pointer to driver command iocb object.
7151 * @rspiocb: Pointer to driver response iocb object.
7153 * The function is called from SLI ring event handler with no
7154 * lock held. This function is the completion handler for ELS commands
7155 * which are aborted. The function frees memory resources used for
7156 * the aborted ELS commands.
7159 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7160 struct lpfc_iocbq
*rspiocb
)
7162 IOCB_t
*irsp
= &rspiocb
->iocb
;
7164 /* ELS cmd tag <ulpIoTag> completes */
7165 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
7166 "0139 Ignoring ELS cmd tag x%x completion Data: "
7168 irsp
->ulpIoTag
, irsp
->ulpStatus
,
7169 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
7170 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
7171 lpfc_ct_free_iocb(phba
, cmdiocb
);
7173 lpfc_els_free_iocb(phba
, cmdiocb
);
7178 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7179 * @phba: Pointer to HBA context object.
7180 * @pring: Pointer to driver SLI ring object.
7181 * @cmdiocb: Pointer to driver command iocb object.
7183 * This function issues an abort iocb for the provided command
7184 * iocb. This function is called with hbalock held.
7185 * The function returns 0 when it fails due to memory allocation
7186 * failure or when the command iocb is an abort request.
7189 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7190 struct lpfc_iocbq
*cmdiocb
)
7192 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7193 struct lpfc_iocbq
*abtsiocbp
;
7194 IOCB_t
*icmd
= NULL
;
7195 IOCB_t
*iabt
= NULL
;
7196 int retval
= IOCB_ERROR
;
7199 * There are certain command types we don't want to abort. And we
7200 * don't want to abort commands that are already in the process of
7203 icmd
= &cmdiocb
->iocb
;
7204 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
7205 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7206 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
7209 /* If we're unloading, don't abort iocb on the ELS ring, but change the
7210 * callback so that nothing happens when it finishes.
7212 if ((vport
->load_flag
& FC_UNLOADING
) &&
7213 (pring
->ringno
== LPFC_ELS_RING
)) {
7214 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
7215 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
7217 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
7218 goto abort_iotag_exit
;
7221 /* issue ABTS for this IOCB based on iotag */
7222 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
7223 if (abtsiocbp
== NULL
)
7226 /* This signals the response to set the correct status
7227 * before calling the completion handler
7229 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
7231 iabt
= &abtsiocbp
->iocb
;
7232 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7233 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
7234 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7235 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
7236 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
7239 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
7241 iabt
->ulpClass
= icmd
->ulpClass
;
7243 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7244 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
7245 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
7246 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
7248 if (phba
->link_state
>= LPFC_LINK_UP
)
7249 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
7251 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
7253 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
7255 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
7256 "0339 Abort xri x%x, original iotag x%x, "
7257 "abort cmd iotag x%x\n",
7258 iabt
->un
.acxri
.abortContextTag
,
7259 iabt
->un
.acxri
.abortIoTag
, abtsiocbp
->iotag
);
7260 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
7263 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
7266 * Caller to this routine should check for IOCB_ERROR
7267 * and handle it properly. This routine no longer removes
7268 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7274 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7275 * @iocbq: Pointer to driver iocb object.
7276 * @vport: Pointer to driver virtual port object.
7277 * @tgt_id: SCSI ID of the target.
7278 * @lun_id: LUN ID of the scsi device.
7279 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
7281 * This function acts as an iocb filter for functions which abort or count
7282 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
7283 * 0 if the filtering criteria is met for the given iocb and will return
7284 * 1 if the filtering criteria is not met.
7285 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
7286 * given iocb is for the SCSI device specified by vport, tgt_id and
7288 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
7289 * given iocb is for the SCSI target specified by vport and tgt_id
7291 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
7292 * given iocb is for the SCSI host associated with the given vport.
7293 * This function is called with no locks held.
7296 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
7297 uint16_t tgt_id
, uint64_t lun_id
,
7298 lpfc_ctx_cmd ctx_cmd
)
7300 struct lpfc_scsi_buf
*lpfc_cmd
;
7303 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
7306 if (iocbq
->vport
!= vport
)
7309 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
7311 if (lpfc_cmd
->pCmd
== NULL
)
7316 if ((lpfc_cmd
->rdata
->pnode
) &&
7317 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
7318 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
7322 if ((lpfc_cmd
->rdata
->pnode
) &&
7323 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
7330 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
7339 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7340 * @vport: Pointer to virtual port.
7341 * @tgt_id: SCSI ID of the target.
7342 * @lun_id: LUN ID of the scsi device.
7343 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7345 * This function returns number of FCP commands pending for the vport.
7346 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7347 * commands pending on the vport associated with SCSI device specified
7348 * by tgt_id and lun_id parameters.
7349 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7350 * commands pending on the vport associated with SCSI target specified
7351 * by tgt_id parameter.
7352 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7353 * commands pending on the vport.
7354 * This function returns the number of iocbs which satisfy the filter.
7355 * This function is called without any lock held.
7358 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
7359 lpfc_ctx_cmd ctx_cmd
)
7361 struct lpfc_hba
*phba
= vport
->phba
;
7362 struct lpfc_iocbq
*iocbq
;
7365 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
7366 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7368 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
7377 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7378 * @phba: Pointer to HBA context object
7379 * @cmdiocb: Pointer to command iocb object.
7380 * @rspiocb: Pointer to response iocb object.
7382 * This function is called when an aborted FCP iocb completes. This
7383 * function is called by the ring event handler with no lock held.
7384 * This function frees the iocb.
7387 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7388 struct lpfc_iocbq
*rspiocb
)
7390 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7395 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
7396 * @vport: Pointer to virtual port.
7397 * @pring: Pointer to driver SLI ring object.
7398 * @tgt_id: SCSI ID of the target.
7399 * @lun_id: LUN ID of the scsi device.
7400 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7402 * This function sends an abort command for every SCSI command
7403 * associated with the given virtual port pending on the ring
7404 * filtered by lpfc_sli_validate_fcp_iocb function.
7405 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
7406 * FCP iocbs associated with lun specified by tgt_id and lun_id
7408 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
7409 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
7410 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
7411 * FCP iocbs associated with virtual port.
7412 * This function returns number of iocbs it failed to abort.
7413 * This function is called with no locks held.
7416 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
7417 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
7419 struct lpfc_hba
*phba
= vport
->phba
;
7420 struct lpfc_iocbq
*iocbq
;
7421 struct lpfc_iocbq
*abtsiocb
;
7423 int errcnt
= 0, ret_val
= 0;
7426 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
7427 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7429 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
7433 /* issue ABTS for this IOCB based on iotag */
7434 abtsiocb
= lpfc_sli_get_iocbq(phba
);
7435 if (abtsiocb
== NULL
) {
7441 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7442 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
7443 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7444 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
7446 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
7447 abtsiocb
->iocb
.ulpLe
= 1;
7448 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
7449 abtsiocb
->vport
= phba
->pport
;
7451 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7452 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
7453 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7454 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
7456 if (lpfc_is_link_up(phba
))
7457 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
7459 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
7461 /* Setup callback routine and issue the command. */
7462 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
7463 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
7465 if (ret_val
== IOCB_ERROR
) {
7466 lpfc_sli_release_iocbq(phba
, abtsiocb
);
7476 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
7477 * @phba: Pointer to HBA context object.
7478 * @cmdiocbq: Pointer to command iocb.
7479 * @rspiocbq: Pointer to response iocb.
7481 * This function is the completion handler for iocbs issued using
7482 * lpfc_sli_issue_iocb_wait function. This function is called by the
7483 * ring event handler function without any lock held. This function
7484 * can be called from both worker thread context and interrupt
7485 * context. This function also can be called from other thread which
7486 * cleans up the SLI layer objects.
7487 * This function copy the contents of the response iocb to the
7488 * response iocb memory object provided by the caller of
7489 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
7490 * sleeps for the iocb completion.
7493 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
7494 struct lpfc_iocbq
*cmdiocbq
,
7495 struct lpfc_iocbq
*rspiocbq
)
7497 wait_queue_head_t
*pdone_q
;
7498 unsigned long iflags
;
7499 struct lpfc_scsi_buf
*lpfc_cmd
;
7501 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7502 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
7503 if (cmdiocbq
->context2
&& rspiocbq
)
7504 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
7505 &rspiocbq
->iocb
, sizeof(IOCB_t
));
7507 /* Set the exchange busy flag for task management commands */
7508 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
7509 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
7510 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
7512 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
7515 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
7518 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7523 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
7524 * @phba: Pointer to HBA context object..
7525 * @piocbq: Pointer to command iocb.
7526 * @flag: Flag to test.
7528 * This routine grabs the hbalock and then test the iocb_flag to
7529 * see if the passed in flag is set.
7532 * 0 if flag is not set.
7535 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
7536 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
7538 unsigned long iflags
;
7541 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7542 ret
= piocbq
->iocb_flag
& flag
;
7543 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7549 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
7550 * @phba: Pointer to HBA context object..
7551 * @pring: Pointer to sli ring.
7552 * @piocb: Pointer to command iocb.
7553 * @prspiocbq: Pointer to response iocb.
7554 * @timeout: Timeout in number of seconds.
7556 * This function issues the iocb to firmware and waits for the
7557 * iocb to complete. If the iocb command is not
7558 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
7559 * Caller should not free the iocb resources if this function
7560 * returns IOCB_TIMEDOUT.
7561 * The function waits for the iocb completion using an
7562 * non-interruptible wait.
7563 * This function will sleep while waiting for iocb completion.
7564 * So, this function should not be called from any context which
7565 * does not allow sleeping. Due to the same reason, this function
7566 * cannot be called with interrupt disabled.
7567 * This function assumes that the iocb completions occur while
7568 * this function sleep. So, this function cannot be called from
7569 * the thread which process iocb completion for this ring.
7570 * This function clears the iocb_flag of the iocb object before
7571 * issuing the iocb and the iocb completion handler sets this
7572 * flag and wakes this thread when the iocb completes.
7573 * The contents of the response iocb will be copied to prspiocbq
7574 * by the completion handler when the command completes.
7575 * This function returns IOCB_SUCCESS when success.
7576 * This function is called with no lock held.
7579 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
7580 uint32_t ring_number
,
7581 struct lpfc_iocbq
*piocb
,
7582 struct lpfc_iocbq
*prspiocbq
,
7585 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
7586 long timeleft
, timeout_req
= 0;
7587 int retval
= IOCB_SUCCESS
;
7591 * If the caller has provided a response iocbq buffer, then context2
7592 * is NULL or its an error.
7595 if (piocb
->context2
)
7597 piocb
->context2
= prspiocbq
;
7600 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
7601 piocb
->context_un
.wait_queue
= &done_q
;
7602 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
7604 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7605 creg_val
= readl(phba
->HCregaddr
);
7606 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
7607 writel(creg_val
, phba
->HCregaddr
);
7608 readl(phba
->HCregaddr
); /* flush */
7611 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, 0);
7612 if (retval
== IOCB_SUCCESS
) {
7613 timeout_req
= timeout
* HZ
;
7614 timeleft
= wait_event_timeout(done_q
,
7615 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
7618 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
7619 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7620 "0331 IOCB wake signaled\n");
7621 } else if (timeleft
== 0) {
7622 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7623 "0338 IOCB wait timeout error - no "
7624 "wake response Data x%x\n", timeout
);
7625 retval
= IOCB_TIMEDOUT
;
7627 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7628 "0330 IOCB wake NOT set, "
7630 timeout
, (timeleft
/ jiffies
));
7631 retval
= IOCB_TIMEDOUT
;
7634 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7635 "0332 IOCB wait issue failed, Data x%x\n",
7637 retval
= IOCB_ERROR
;
7640 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7641 creg_val
= readl(phba
->HCregaddr
);
7642 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
7643 writel(creg_val
, phba
->HCregaddr
);
7644 readl(phba
->HCregaddr
); /* flush */
7648 piocb
->context2
= NULL
;
7650 piocb
->context_un
.wait_queue
= NULL
;
7651 piocb
->iocb_cmpl
= NULL
;
7656 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
7657 * @phba: Pointer to HBA context object.
7658 * @pmboxq: Pointer to driver mailbox object.
7659 * @timeout: Timeout in number of seconds.
7661 * This function issues the mailbox to firmware and waits for the
7662 * mailbox command to complete. If the mailbox command is not
7663 * completed within timeout seconds, it returns MBX_TIMEOUT.
7664 * The function waits for the mailbox completion using an
7665 * interruptible wait. If the thread is woken up due to a
7666 * signal, MBX_TIMEOUT error is returned to the caller. Caller
7667 * should not free the mailbox resources, if this function returns
7669 * This function will sleep while waiting for mailbox completion.
7670 * So, this function should not be called from any context which
7671 * does not allow sleeping. Due to the same reason, this function
7672 * cannot be called with interrupt disabled.
7673 * This function assumes that the mailbox completion occurs while
7674 * this function sleep. So, this function cannot be called from
7675 * the worker thread which processes mailbox completion.
7676 * This function is called in the context of HBA management
7678 * This function returns MBX_SUCCESS when successful.
7679 * This function is called with no lock held.
7682 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
7685 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
7689 /* The caller must leave context1 empty. */
7690 if (pmboxq
->context1
)
7691 return MBX_NOT_FINISHED
;
7693 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
7694 /* setup wake call as IOCB callback */
7695 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
7696 /* setup context field to pass wait_queue pointer to wake function */
7697 pmboxq
->context1
= &done_q
;
7699 /* now issue the command */
7700 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
7702 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
7703 wait_event_interruptible_timeout(done_q
,
7704 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
7707 spin_lock_irqsave(&phba
->hbalock
, flag
);
7708 pmboxq
->context1
= NULL
;
7710 * if LPFC_MBX_WAKE flag is set the mailbox is completed
7711 * else do not free the resources.
7713 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
)
7714 retval
= MBX_SUCCESS
;
7716 retval
= MBX_TIMEOUT
;
7717 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
7719 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
7726 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
7727 * @phba: Pointer to HBA context.
7729 * This function is called to shutdown the driver's mailbox sub-system.
7730 * It first marks the mailbox sub-system is in a block state to prevent
7731 * the asynchronous mailbox command from issued off the pending mailbox
7732 * command queue. If the mailbox command sub-system shutdown is due to
7733 * HBA error conditions such as EEH or ERATT, this routine shall invoke
7734 * the mailbox sub-system flush routine to forcefully bring down the
7735 * mailbox sub-system. Otherwise, if it is due to normal condition (such
7736 * as with offline or HBA function reset), this routine will wait for the
7737 * outstanding mailbox command to complete before invoking the mailbox
7738 * sub-system flush routine to gracefully bring down mailbox sub-system.
7741 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
7743 struct lpfc_sli
*psli
= &phba
->sli
;
7744 uint8_t actcmd
= MBX_HEARTBEAT
;
7745 unsigned long timeout
;
7747 spin_lock_irq(&phba
->hbalock
);
7748 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7749 spin_unlock_irq(&phba
->hbalock
);
7751 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7752 spin_lock_irq(&phba
->hbalock
);
7753 if (phba
->sli
.mbox_active
)
7754 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
7755 spin_unlock_irq(&phba
->hbalock
);
7756 /* Determine how long we might wait for the active mailbox
7757 * command to be gracefully completed by firmware.
7759 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) *
7761 while (phba
->sli
.mbox_active
) {
7762 /* Check active mailbox complete status every 2ms */
7764 if (time_after(jiffies
, timeout
))
7765 /* Timeout, let the mailbox flush routine to
7766 * forcefully release active mailbox command
7771 lpfc_sli_mbox_sys_flush(phba
);
7775 * lpfc_sli_eratt_read - read sli-3 error attention events
7776 * @phba: Pointer to HBA context.
7778 * This function is called to read the SLI3 device error attention registers
7779 * for possible error attention events. The caller must hold the hostlock
7780 * with spin_lock_irq().
7782 * This fucntion returns 1 when there is Error Attention in the Host Attention
7783 * Register and returns 0 otherwise.
7786 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
7790 /* Read chip Host Attention (HA) register */
7791 ha_copy
= readl(phba
->HAregaddr
);
7792 if (ha_copy
& HA_ERATT
) {
7793 /* Read host status register to retrieve error event */
7794 lpfc_sli_read_hs(phba
);
7796 /* Check if there is a deferred error condition is active */
7797 if ((HS_FFER1
& phba
->work_hs
) &&
7798 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
7799 HS_FFER6
| HS_FFER7
) & phba
->work_hs
)) {
7800 phba
->hba_flag
|= DEFER_ERATT
;
7801 /* Clear all interrupt enable conditions */
7802 writel(0, phba
->HCregaddr
);
7803 readl(phba
->HCregaddr
);
7806 /* Set the driver HA work bitmap */
7807 phba
->work_ha
|= HA_ERATT
;
7808 /* Indicate polling handles this ERATT */
7809 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7816 * lpfc_sli4_eratt_read - read sli-4 error attention events
7817 * @phba: Pointer to HBA context.
7819 * This function is called to read the SLI4 device error attention registers
7820 * for possible error attention events. The caller must hold the hostlock
7821 * with spin_lock_irq().
7823 * This fucntion returns 1 when there is Error Attention in the Host Attention
7824 * Register and returns 0 otherwise.
7827 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
7829 uint32_t uerr_sta_hi
, uerr_sta_lo
;
7831 /* For now, use the SLI4 device internal unrecoverable error
7832 * registers for error attention. This can be changed later.
7834 uerr_sta_lo
= readl(phba
->sli4_hba
.UERRLOregaddr
);
7835 uerr_sta_hi
= readl(phba
->sli4_hba
.UERRHIregaddr
);
7836 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
7837 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
7838 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7839 "1423 HBA Unrecoverable error: "
7840 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
7841 "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
7842 uerr_sta_lo
, uerr_sta_hi
,
7843 phba
->sli4_hba
.ue_mask_lo
,
7844 phba
->sli4_hba
.ue_mask_hi
);
7845 phba
->work_status
[0] = uerr_sta_lo
;
7846 phba
->work_status
[1] = uerr_sta_hi
;
7847 /* Set the driver HA work bitmap */
7848 phba
->work_ha
|= HA_ERATT
;
7849 /* Indicate polling handles this ERATT */
7850 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7857 * lpfc_sli_check_eratt - check error attention events
7858 * @phba: Pointer to HBA context.
7860 * This function is called from timer soft interrupt context to check HBA's
7861 * error attention register bit for error attention events.
7863 * This fucntion returns 1 when there is Error Attention in the Host Attention
7864 * Register and returns 0 otherwise.
7867 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
7871 /* If somebody is waiting to handle an eratt, don't process it
7872 * here. The brdkill function will do this.
7874 if (phba
->link_flag
& LS_IGNORE_ERATT
)
7877 /* Check if interrupt handler handles this ERATT */
7878 spin_lock_irq(&phba
->hbalock
);
7879 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
7880 /* Interrupt handler has handled ERATT */
7881 spin_unlock_irq(&phba
->hbalock
);
7886 * If there is deferred error attention, do not check for error
7889 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7890 spin_unlock_irq(&phba
->hbalock
);
7894 /* If PCI channel is offline, don't process it */
7895 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7896 spin_unlock_irq(&phba
->hbalock
);
7900 switch (phba
->sli_rev
) {
7903 /* Read chip Host Attention (HA) register */
7904 ha_copy
= lpfc_sli_eratt_read(phba
);
7907 /* Read devcie Uncoverable Error (UERR) registers */
7908 ha_copy
= lpfc_sli4_eratt_read(phba
);
7911 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7912 "0299 Invalid SLI revision (%d)\n",
7917 spin_unlock_irq(&phba
->hbalock
);
7923 * lpfc_intr_state_check - Check device state for interrupt handling
7924 * @phba: Pointer to HBA context.
7926 * This inline routine checks whether a device or its PCI slot is in a state
7927 * that the interrupt should be handled.
7929 * This function returns 0 if the device or the PCI slot is in a state that
7930 * interrupt should be handled, otherwise -EIO.
7933 lpfc_intr_state_check(struct lpfc_hba
*phba
)
7935 /* If the pci channel is offline, ignore all the interrupts */
7936 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7939 /* Update device level interrupt statistics */
7940 phba
->sli
.slistat
.sli_intr
++;
7942 /* Ignore all interrupts during initialization. */
7943 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7950 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
7951 * @irq: Interrupt number.
7952 * @dev_id: The device context pointer.
7954 * This function is directly called from the PCI layer as an interrupt
7955 * service routine when device with SLI-3 interface spec is enabled with
7956 * MSI-X multi-message interrupt mode and there are slow-path events in
7957 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
7958 * interrupt mode, this function is called as part of the device-level
7959 * interrupt handler. When the PCI slot is in error recovery or the HBA
7960 * is undergoing initialization, the interrupt handler will not process
7961 * the interrupt. The link attention and ELS ring attention events are
7962 * handled by the worker thread. The interrupt handler signals the worker
7963 * thread and returns for these events. This function is called without
7964 * any lock held. It gets the hbalock to access and update SLI data
7967 * This function returns IRQ_HANDLED when interrupt is handled else it
7971 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
7973 struct lpfc_hba
*phba
;
7974 uint32_t ha_copy
, hc_copy
;
7975 uint32_t work_ha_copy
;
7976 unsigned long status
;
7977 unsigned long iflag
;
7980 MAILBOX_t
*mbox
, *pmbox
;
7981 struct lpfc_vport
*vport
;
7982 struct lpfc_nodelist
*ndlp
;
7983 struct lpfc_dmabuf
*mp
;
7988 * Get the driver's phba structure from the dev_id and
7989 * assume the HBA is not interrupting.
7991 phba
= (struct lpfc_hba
*)dev_id
;
7993 if (unlikely(!phba
))
7997 * Stuff needs to be attented to when this function is invoked as an
7998 * individual interrupt handler in MSI-X multi-message interrupt mode
8000 if (phba
->intr_type
== MSIX
) {
8001 /* Check device state for handling interrupt */
8002 if (lpfc_intr_state_check(phba
))
8004 /* Need to read HA REG for slow-path events */
8005 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8006 ha_copy
= readl(phba
->HAregaddr
);
8007 /* If somebody is waiting to handle an eratt don't process it
8008 * here. The brdkill function will do this.
8010 if (phba
->link_flag
& LS_IGNORE_ERATT
)
8011 ha_copy
&= ~HA_ERATT
;
8012 /* Check the need for handling ERATT in interrupt handler */
8013 if (ha_copy
& HA_ERATT
) {
8014 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
8015 /* ERATT polling has handled ERATT */
8016 ha_copy
&= ~HA_ERATT
;
8018 /* Indicate interrupt handler handles ERATT */
8019 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8023 * If there is deferred error attention, do not check for any
8026 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8027 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8031 /* Clear up only attention source related to slow-path */
8032 hc_copy
= readl(phba
->HCregaddr
);
8033 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
8034 HC_LAINT_ENA
| HC_ERINT_ENA
),
8036 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
8038 writel(hc_copy
, phba
->HCregaddr
);
8039 readl(phba
->HAregaddr
); /* flush */
8040 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8042 ha_copy
= phba
->ha_copy
;
8044 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
8047 if (work_ha_copy
& HA_LATT
) {
8048 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
8050 * Turn off Link Attention interrupts
8051 * until CLEAR_LA done
8053 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8054 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
8055 control
= readl(phba
->HCregaddr
);
8056 control
&= ~HC_LAINT_ENA
;
8057 writel(control
, phba
->HCregaddr
);
8058 readl(phba
->HCregaddr
); /* flush */
8059 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8062 work_ha_copy
&= ~HA_LATT
;
8065 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
8067 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
8068 * the only slow ring.
8070 status
= (work_ha_copy
&
8071 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
8072 status
>>= (4*LPFC_ELS_RING
);
8073 if (status
& HA_RXMASK
) {
8074 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8075 control
= readl(phba
->HCregaddr
);
8077 lpfc_debugfs_slow_ring_trc(phba
,
8078 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
8080 (uint32_t)phba
->sli
.slistat
.sli_intr
);
8082 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
8083 lpfc_debugfs_slow_ring_trc(phba
,
8085 "pwork:x%x hawork:x%x wait:x%x",
8086 phba
->work_ha
, work_ha_copy
,
8087 (uint32_t)((unsigned long)
8088 &phba
->work_waitq
));
8091 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
8092 writel(control
, phba
->HCregaddr
);
8093 readl(phba
->HCregaddr
); /* flush */
8096 lpfc_debugfs_slow_ring_trc(phba
,
8097 "ISR slow ring: pwork:"
8098 "x%x hawork:x%x wait:x%x",
8099 phba
->work_ha
, work_ha_copy
,
8100 (uint32_t)((unsigned long)
8101 &phba
->work_waitq
));
8103 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8106 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8107 if (work_ha_copy
& HA_ERATT
) {
8108 lpfc_sli_read_hs(phba
);
8110 * Check if there is a deferred error condition
8113 if ((HS_FFER1
& phba
->work_hs
) &&
8114 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
8115 HS_FFER6
| HS_FFER7
) & phba
->work_hs
)) {
8116 phba
->hba_flag
|= DEFER_ERATT
;
8117 /* Clear all interrupt enable conditions */
8118 writel(0, phba
->HCregaddr
);
8119 readl(phba
->HCregaddr
);
8123 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
8124 pmb
= phba
->sli
.mbox_active
;
8129 /* First check out the status word */
8130 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
8131 if (pmbox
->mbxOwner
!= OWN_HOST
) {
8132 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8134 * Stray Mailbox Interrupt, mbxCommand <cmd>
8135 * mbxStatus <status>
8137 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8139 "(%d):0304 Stray Mailbox "
8140 "Interrupt mbxCommand x%x "
8142 (vport
? vport
->vpi
: 0),
8145 /* clear mailbox attention bit */
8146 work_ha_copy
&= ~HA_MBATT
;
8148 phba
->sli
.mbox_active
= NULL
;
8149 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8150 phba
->last_completion_time
= jiffies
;
8151 del_timer(&phba
->sli
.mbox_tmo
);
8152 if (pmb
->mbox_cmpl
) {
8153 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
8155 if (pmb
->out_ext_byte_len
&&
8157 lpfc_sli_pcimem_bcopy(
8160 pmb
->out_ext_byte_len
);
8162 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8163 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8165 lpfc_debugfs_disc_trc(vport
,
8166 LPFC_DISC_TRC_MBOX_VPORT
,
8168 "status:x%x rpi:x%x",
8169 (uint32_t)pmbox
->mbxStatus
,
8170 pmbox
->un
.varWords
[0], 0);
8172 if (!pmbox
->mbxStatus
) {
8173 mp
= (struct lpfc_dmabuf
*)
8175 ndlp
= (struct lpfc_nodelist
*)
8178 /* Reg_LOGIN of dflt RPI was
8179 * successful. new lets get
8180 * rid of the RPI using the
8183 lpfc_unreg_login(phba
,
8185 pmbox
->un
.varWords
[0],
8188 lpfc_mbx_cmpl_dflt_rpi
;
8190 pmb
->context2
= ndlp
;
8192 rc
= lpfc_sli_issue_mbox(phba
,
8196 lpfc_printf_log(phba
,
8199 "0350 rc should have"
8201 if (rc
!= MBX_NOT_FINISHED
)
8202 goto send_current_mbox
;
8206 &phba
->pport
->work_port_lock
,
8208 phba
->pport
->work_port_events
&=
8210 spin_unlock_irqrestore(
8211 &phba
->pport
->work_port_lock
,
8213 lpfc_mbox_cmpl_put(phba
, pmb
);
8216 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8218 if ((work_ha_copy
& HA_MBATT
) &&
8219 (phba
->sli
.mbox_active
== NULL
)) {
8221 /* Process next mailbox command if there is one */
8223 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
8225 } while (rc
== MBX_NOT_FINISHED
);
8226 if (rc
!= MBX_SUCCESS
)
8227 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8228 LOG_SLI
, "0349 rc should be "
8232 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8233 phba
->work_ha
|= work_ha_copy
;
8234 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8235 lpfc_worker_wake_up(phba
);
8239 } /* lpfc_sli_sp_intr_handler */
8242 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
8243 * @irq: Interrupt number.
8244 * @dev_id: The device context pointer.
8246 * This function is directly called from the PCI layer as an interrupt
8247 * service routine when device with SLI-3 interface spec is enabled with
8248 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8249 * ring event in the HBA. However, when the device is enabled with either
8250 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8251 * device-level interrupt handler. When the PCI slot is in error recovery
8252 * or the HBA is undergoing initialization, the interrupt handler will not
8253 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8254 * the intrrupt context. This function is called without any lock held.
8255 * It gets the hbalock to access and update SLI data structures.
8257 * This function returns IRQ_HANDLED when interrupt is handled else it
8261 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
8263 struct lpfc_hba
*phba
;
8265 unsigned long status
;
8266 unsigned long iflag
;
8268 /* Get the driver's phba structure from the dev_id and
8269 * assume the HBA is not interrupting.
8271 phba
= (struct lpfc_hba
*) dev_id
;
8273 if (unlikely(!phba
))
8277 * Stuff needs to be attented to when this function is invoked as an
8278 * individual interrupt handler in MSI-X multi-message interrupt mode
8280 if (phba
->intr_type
== MSIX
) {
8281 /* Check device state for handling interrupt */
8282 if (lpfc_intr_state_check(phba
))
8284 /* Need to read HA REG for FCP ring and other ring events */
8285 ha_copy
= readl(phba
->HAregaddr
);
8286 /* Clear up only attention source related to fast-path */
8287 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8289 * If there is deferred error attention, do not check for
8292 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8293 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8296 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
8298 readl(phba
->HAregaddr
); /* flush */
8299 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8301 ha_copy
= phba
->ha_copy
;
8304 * Process all events on FCP ring. Take the optimized path for FCP IO.
8306 ha_copy
&= ~(phba
->work_ha_mask
);
8308 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8309 status
>>= (4*LPFC_FCP_RING
);
8310 if (status
& HA_RXMASK
)
8311 lpfc_sli_handle_fast_ring_event(phba
,
8312 &phba
->sli
.ring
[LPFC_FCP_RING
],
8315 if (phba
->cfg_multi_ring_support
== 2) {
8317 * Process all events on extra ring. Take the optimized path
8318 * for extra ring IO.
8320 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8321 status
>>= (4*LPFC_EXTRA_RING
);
8322 if (status
& HA_RXMASK
) {
8323 lpfc_sli_handle_fast_ring_event(phba
,
8324 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
8329 } /* lpfc_sli_fp_intr_handler */
8332 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
8333 * @irq: Interrupt number.
8334 * @dev_id: The device context pointer.
8336 * This function is the HBA device-level interrupt handler to device with
8337 * SLI-3 interface spec, called from the PCI layer when either MSI or
8338 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
8339 * requires driver attention. This function invokes the slow-path interrupt
8340 * attention handling function and fast-path interrupt attention handling
8341 * function in turn to process the relevant HBA attention events. This
8342 * function is called without any lock held. It gets the hbalock to access
8343 * and update SLI data structures.
8345 * This function returns IRQ_HANDLED when interrupt is handled, else it
8349 lpfc_sli_intr_handler(int irq
, void *dev_id
)
8351 struct lpfc_hba
*phba
;
8352 irqreturn_t sp_irq_rc
, fp_irq_rc
;
8353 unsigned long status1
, status2
;
8357 * Get the driver's phba structure from the dev_id and
8358 * assume the HBA is not interrupting.
8360 phba
= (struct lpfc_hba
*) dev_id
;
8362 if (unlikely(!phba
))
8365 /* Check device state for handling interrupt */
8366 if (lpfc_intr_state_check(phba
))
8369 spin_lock(&phba
->hbalock
);
8370 phba
->ha_copy
= readl(phba
->HAregaddr
);
8371 if (unlikely(!phba
->ha_copy
)) {
8372 spin_unlock(&phba
->hbalock
);
8374 } else if (phba
->ha_copy
& HA_ERATT
) {
8375 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
8376 /* ERATT polling has handled ERATT */
8377 phba
->ha_copy
&= ~HA_ERATT
;
8379 /* Indicate interrupt handler handles ERATT */
8380 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8384 * If there is deferred error attention, do not check for any interrupt.
8386 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8387 spin_unlock_irq(&phba
->hbalock
);
8391 /* Clear attention sources except link and error attentions */
8392 hc_copy
= readl(phba
->HCregaddr
);
8393 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
8394 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
8396 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
8397 writel(hc_copy
, phba
->HCregaddr
);
8398 readl(phba
->HAregaddr
); /* flush */
8399 spin_unlock(&phba
->hbalock
);
8402 * Invokes slow-path host attention interrupt handling as appropriate.
8405 /* status of events with mailbox and link attention */
8406 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
8408 /* status of events with ELS ring */
8409 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
8410 status2
>>= (4*LPFC_ELS_RING
);
8412 if (status1
|| (status2
& HA_RXMASK
))
8413 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
8415 sp_irq_rc
= IRQ_NONE
;
8418 * Invoke fast-path host attention interrupt handling as appropriate.
8421 /* status of events with FCP ring */
8422 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8423 status1
>>= (4*LPFC_FCP_RING
);
8425 /* status of events with extra ring */
8426 if (phba
->cfg_multi_ring_support
== 2) {
8427 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8428 status2
>>= (4*LPFC_EXTRA_RING
);
8432 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
8433 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
8435 fp_irq_rc
= IRQ_NONE
;
8437 /* Return device-level interrupt handling status */
8438 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
8439 } /* lpfc_sli_intr_handler */
8442 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
8443 * @phba: pointer to lpfc hba data structure.
8445 * This routine is invoked by the worker thread to process all the pending
8446 * SLI4 FCP abort XRI events.
8448 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
8450 struct lpfc_cq_event
*cq_event
;
8452 /* First, declare the fcp xri abort event has been handled */
8453 spin_lock_irq(&phba
->hbalock
);
8454 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
8455 spin_unlock_irq(&phba
->hbalock
);
8456 /* Now, handle all the fcp xri abort events */
8457 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
8458 /* Get the first event from the head of the event queue */
8459 spin_lock_irq(&phba
->hbalock
);
8460 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
8461 cq_event
, struct lpfc_cq_event
, list
);
8462 spin_unlock_irq(&phba
->hbalock
);
8463 /* Notify aborted XRI for FCP work queue */
8464 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
8465 /* Free the event processed back to the free pool */
8466 lpfc_sli4_cq_event_release(phba
, cq_event
);
8471 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
8472 * @phba: pointer to lpfc hba data structure.
8474 * This routine is invoked by the worker thread to process all the pending
8475 * SLI4 els abort xri events.
8477 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
8479 struct lpfc_cq_event
*cq_event
;
8481 /* First, declare the els xri abort event has been handled */
8482 spin_lock_irq(&phba
->hbalock
);
8483 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
8484 spin_unlock_irq(&phba
->hbalock
);
8485 /* Now, handle all the els xri abort events */
8486 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
8487 /* Get the first event from the head of the event queue */
8488 spin_lock_irq(&phba
->hbalock
);
8489 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
8490 cq_event
, struct lpfc_cq_event
, list
);
8491 spin_unlock_irq(&phba
->hbalock
);
8492 /* Notify aborted XRI for ELS work queue */
8493 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
8494 /* Free the event processed back to the free pool */
8495 lpfc_sli4_cq_event_release(phba
, cq_event
);
8500 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
8501 * @phba: pointer to lpfc hba data structure
8502 * @pIocbIn: pointer to the rspiocbq
8503 * @pIocbOut: pointer to the cmdiocbq
8504 * @wcqe: pointer to the complete wcqe
8506 * This routine transfers the fields of a command iocbq to a response iocbq
8507 * by copying all the IOCB fields from command iocbq and transferring the
8508 * completion status information from the complete wcqe.
8511 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
8512 struct lpfc_iocbq
*pIocbIn
,
8513 struct lpfc_iocbq
*pIocbOut
,
8514 struct lpfc_wcqe_complete
*wcqe
)
8516 unsigned long iflags
;
8517 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
8519 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
8520 sizeof(struct lpfc_iocbq
) - offset
);
8521 /* Map WCQE parameters into irspiocb parameters */
8522 pIocbIn
->iocb
.ulpStatus
= bf_get(lpfc_wcqe_c_status
, wcqe
);
8523 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
8524 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
8525 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
8526 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
8527 wcqe
->total_data_placed
;
8529 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
8531 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
8532 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
8535 /* Pick up HBA exchange busy condition */
8536 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
8537 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8538 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
8539 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8544 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
8545 * @phba: Pointer to HBA context object.
8546 * @wcqe: Pointer to work-queue completion queue entry.
8548 * This routine handles an ELS work-queue completion event and construct
8549 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
8550 * discovery engine to handle.
8552 * Return: Pointer to the receive IOCBQ, NULL otherwise.
8554 static struct lpfc_iocbq
*
8555 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
8556 struct lpfc_iocbq
*irspiocbq
)
8558 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8559 struct lpfc_iocbq
*cmdiocbq
;
8560 struct lpfc_wcqe_complete
*wcqe
;
8561 unsigned long iflags
;
8563 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
8564 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8565 pring
->stats
.iocb_event
++;
8566 /* Look up the ELS command IOCB and create pseudo response IOCB */
8567 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
8568 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8569 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8571 if (unlikely(!cmdiocbq
)) {
8572 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8573 "0386 ELS complete with no corresponding "
8574 "cmdiocb: iotag (%d)\n",
8575 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8576 lpfc_sli_release_iocbq(phba
, irspiocbq
);
8580 /* Fake the irspiocbq and copy necessary response information */
8581 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
8587 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
8588 * @phba: Pointer to HBA context object.
8589 * @cqe: Pointer to mailbox completion queue entry.
8591 * This routine process a mailbox completion queue entry with asynchrous
8594 * Return: true if work posted to worker thread, otherwise false.
8597 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
8599 struct lpfc_cq_event
*cq_event
;
8600 unsigned long iflags
;
8602 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8603 "0392 Async Event: word0:x%x, word1:x%x, "
8604 "word2:x%x, word3:x%x\n", mcqe
->word0
,
8605 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
8607 /* Allocate a new internal CQ_EVENT entry */
8608 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
8610 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8611 "0394 Failed to allocate CQ_EVENT entry\n");
8615 /* Move the CQE into an asynchronous event entry */
8616 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
8617 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8618 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
8619 /* Set the async event flag */
8620 phba
->hba_flag
|= ASYNC_EVENT
;
8621 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8627 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
8628 * @phba: Pointer to HBA context object.
8629 * @cqe: Pointer to mailbox completion queue entry.
8631 * This routine process a mailbox completion queue entry with mailbox
8634 * Return: true if work posted to worker thread, otherwise false.
8637 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
8639 uint32_t mcqe_status
;
8640 MAILBOX_t
*mbox
, *pmbox
;
8641 struct lpfc_mqe
*mqe
;
8642 struct lpfc_vport
*vport
;
8643 struct lpfc_nodelist
*ndlp
;
8644 struct lpfc_dmabuf
*mp
;
8645 unsigned long iflags
;
8647 bool workposted
= false;
8650 /* If not a mailbox complete MCQE, out by checking mailbox consume */
8651 if (!bf_get(lpfc_trailer_completed
, mcqe
))
8652 goto out_no_mqe_complete
;
8654 /* Get the reference to the active mbox command */
8655 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8656 pmb
= phba
->sli
.mbox_active
;
8657 if (unlikely(!pmb
)) {
8658 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
8659 "1832 No pending MBOX command to handle\n");
8660 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8661 goto out_no_mqe_complete
;
8663 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8665 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
8669 /* Reset heartbeat timer */
8670 phba
->last_completion_time
= jiffies
;
8671 del_timer(&phba
->sli
.mbox_tmo
);
8673 /* Move mbox data to caller's mailbox region, do endian swapping */
8674 if (pmb
->mbox_cmpl
&& mbox
)
8675 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
8676 /* Set the mailbox status with SLI4 range 0x4000 */
8677 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
8678 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
)
8679 bf_set(lpfc_mqe_status
, mqe
,
8680 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
8682 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8683 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8684 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
8685 "MBOX dflt rpi: status:x%x rpi:x%x",
8687 pmbox
->un
.varWords
[0], 0);
8688 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
8689 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
8690 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
8691 /* Reg_LOGIN of dflt RPI was successful. Now lets get
8692 * RID of the PPI using the same mbox buffer.
8694 lpfc_unreg_login(phba
, vport
->vpi
,
8695 pmbox
->un
.varWords
[0], pmb
);
8696 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
8698 pmb
->context2
= ndlp
;
8700 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
8702 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8703 LOG_SLI
, "0385 rc should "
8704 "have been MBX_BUSY\n");
8705 if (rc
!= MBX_NOT_FINISHED
)
8706 goto send_current_mbox
;
8709 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
8710 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
8711 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
8713 /* There is mailbox completion work to do */
8714 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8715 __lpfc_mbox_cmpl_put(phba
, pmb
);
8716 phba
->work_ha
|= HA_MBATT
;
8717 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8721 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8722 /* Release the mailbox command posting token */
8723 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8724 /* Setting active mailbox pointer need to be in sync to flag clear */
8725 phba
->sli
.mbox_active
= NULL
;
8726 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8727 /* Wake up worker thread to post the next pending mailbox command */
8728 lpfc_worker_wake_up(phba
);
8729 out_no_mqe_complete
:
8730 if (bf_get(lpfc_trailer_consumed
, mcqe
))
8731 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
8736 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
8737 * @phba: Pointer to HBA context object.
8738 * @cqe: Pointer to mailbox completion queue entry.
8740 * This routine process a mailbox completion queue entry, it invokes the
8741 * proper mailbox complete handling or asynchrous event handling routine
8742 * according to the MCQE's async bit.
8744 * Return: true if work posted to worker thread, otherwise false.
8747 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
8749 struct lpfc_mcqe mcqe
;
8752 /* Copy the mailbox MCQE and convert endian order as needed */
8753 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
8755 /* Invoke the proper event handling routine */
8756 if (!bf_get(lpfc_trailer_async
, &mcqe
))
8757 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
8759 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
8764 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
8765 * @phba: Pointer to HBA context object.
8766 * @wcqe: Pointer to work-queue completion queue entry.
8768 * This routine handles an ELS work-queue completion event.
8770 * Return: true if work posted to worker thread, otherwise false.
8773 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
8774 struct lpfc_wcqe_complete
*wcqe
)
8776 struct lpfc_iocbq
*irspiocbq
;
8777 unsigned long iflags
;
8779 /* Get an irspiocbq for later ELS response processing use */
8780 irspiocbq
= lpfc_sli_get_iocbq(phba
);
8782 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8783 "0387 Failed to allocate an iocbq\n");
8787 /* Save off the slow-path queue event for work thread to process */
8788 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
8789 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8790 list_add_tail(&irspiocbq
->cq_event
.list
,
8791 &phba
->sli4_hba
.sp_queue_event
);
8792 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
8793 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8799 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
8800 * @phba: Pointer to HBA context object.
8801 * @wcqe: Pointer to work-queue completion queue entry.
8803 * This routine handles slow-path WQ entry comsumed event by invoking the
8804 * proper WQ release routine to the slow-path WQ.
8807 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
8808 struct lpfc_wcqe_release
*wcqe
)
8810 /* Check for the slow-path ELS work queue */
8811 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
8812 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
8813 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
8815 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8816 "2579 Slow-path wqe consume event carries "
8817 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
8818 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
8819 phba
->sli4_hba
.els_wq
->queue_id
);
8823 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
8824 * @phba: Pointer to HBA context object.
8825 * @cq: Pointer to a WQ completion queue.
8826 * @wcqe: Pointer to work-queue completion queue entry.
8828 * This routine handles an XRI abort event.
8830 * Return: true if work posted to worker thread, otherwise false.
8833 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
8834 struct lpfc_queue
*cq
,
8835 struct sli4_wcqe_xri_aborted
*wcqe
)
8837 bool workposted
= false;
8838 struct lpfc_cq_event
*cq_event
;
8839 unsigned long iflags
;
8841 /* Allocate a new internal CQ_EVENT entry */
8842 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
8844 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8845 "0602 Failed to allocate CQ_EVENT entry\n");
8849 /* Move the CQE into the proper xri abort event list */
8850 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
8851 switch (cq
->subtype
) {
8853 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8854 list_add_tail(&cq_event
->list
,
8855 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
8856 /* Set the fcp xri abort event flag */
8857 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
8858 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8862 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8863 list_add_tail(&cq_event
->list
,
8864 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
8865 /* Set the els xri abort event flag */
8866 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
8867 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8871 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8872 "0603 Invalid work queue CQE subtype (x%x)\n",
8881 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
8882 * @phba: Pointer to HBA context object.
8883 * @rcqe: Pointer to receive-queue completion queue entry.
8885 * This routine process a receive-queue completion queue entry.
8887 * Return: true if work posted to worker thread, otherwise false.
8890 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
8892 bool workposted
= false;
8893 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
8894 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
8895 struct hbq_dmabuf
*dma_buf
;
8897 unsigned long iflags
;
8899 if (bf_get(lpfc_rcqe_rq_id
, rcqe
) != hrq
->queue_id
)
8902 status
= bf_get(lpfc_rcqe_status
, rcqe
);
8904 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
8905 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8906 "2537 Receive Frame Truncated!!\n");
8907 case FC_STATUS_RQ_SUCCESS
:
8908 lpfc_sli4_rq_release(hrq
, drq
);
8909 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8910 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
8912 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8915 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
8916 /* save off the frame for the word thread to process */
8917 list_add_tail(&dma_buf
->cq_event
.list
,
8918 &phba
->sli4_hba
.sp_queue_event
);
8919 /* Frame received */
8920 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
8921 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8924 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
8925 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
8926 /* Post more buffers if possible */
8927 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8928 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
8929 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8938 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
8939 * @phba: Pointer to HBA context object.
8940 * @cq: Pointer to the completion queue.
8941 * @wcqe: Pointer to a completion queue entry.
8943 * This routine process a slow-path work-queue or recieve queue completion queue
8946 * Return: true if work posted to worker thread, otherwise false.
8949 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
8950 struct lpfc_cqe
*cqe
)
8952 struct lpfc_cqe cqevt
;
8953 bool workposted
= false;
8955 /* Copy the work queue CQE and convert endian order if needed */
8956 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
8958 /* Check and process for different type of WCQE and dispatch */
8959 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
8960 case CQE_CODE_COMPL_WQE
:
8961 /* Process the WQ/RQ complete event */
8962 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
8963 (struct lpfc_wcqe_complete
*)&cqevt
);
8965 case CQE_CODE_RELEASE_WQE
:
8966 /* Process the WQ release event */
8967 lpfc_sli4_sp_handle_rel_wcqe(phba
,
8968 (struct lpfc_wcqe_release
*)&cqevt
);
8970 case CQE_CODE_XRI_ABORTED
:
8971 /* Process the WQ XRI abort event */
8972 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
8973 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
8975 case CQE_CODE_RECEIVE
:
8976 /* Process the RQ event */
8977 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
8978 (struct lpfc_rcqe
*)&cqevt
);
8981 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8982 "0388 Not a valid WCQE code: x%x\n",
8983 bf_get(lpfc_cqe_code
, &cqevt
));
8990 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
8991 * @phba: Pointer to HBA context object.
8992 * @eqe: Pointer to fast-path event queue entry.
8994 * This routine process a event queue entry from the slow-path event queue.
8995 * It will check the MajorCode and MinorCode to determine this is for a
8996 * completion event on a completion queue, if not, an error shall be logged
8997 * and just return. Otherwise, it will get to the corresponding completion
8998 * queue and process all the entries on that completion queue, rearm the
8999 * completion queue, and then return.
9003 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
9005 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
9006 struct lpfc_cqe
*cqe
;
9007 bool workposted
= false;
9011 if (bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0) {
9012 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9013 "0359 Not a valid slow-path completion "
9014 "event: majorcode=x%x, minorcode=x%x\n",
9015 bf_get_le32(lpfc_eqe_major_code
, eqe
),
9016 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
9020 /* Get the reference to the corresponding CQ */
9021 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
9023 /* Search for completion queue pointer matching this cqid */
9024 speq
= phba
->sli4_hba
.sp_eq
;
9025 list_for_each_entry(childq
, &speq
->child_list
, list
) {
9026 if (childq
->queue_id
== cqid
) {
9031 if (unlikely(!cq
)) {
9032 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9033 "0365 Slow-path CQ identifier (%d) does "
9034 "not exist\n", cqid
);
9038 /* Process all the entries to the CQ */
9041 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9042 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
9043 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9044 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9048 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9049 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
, cqe
);
9050 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9051 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9055 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9056 "0370 Invalid completion queue type (%d)\n",
9061 /* Catch the no cq entry condition, log an error */
9062 if (unlikely(ecount
== 0))
9063 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9064 "0371 No entry from the CQ: identifier "
9065 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
9067 /* In any case, flash and re-arm the RCQ */
9068 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9070 /* wake up worker thread if there are works to be done */
9072 lpfc_worker_wake_up(phba
);
9076 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
9077 * @eqe: Pointer to fast-path completion queue entry.
9079 * This routine process a fast-path work queue completion entry from fast-path
9080 * event queue for FCP command response completion.
9083 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
9084 struct lpfc_wcqe_complete
*wcqe
)
9086 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
9087 struct lpfc_iocbq
*cmdiocbq
;
9088 struct lpfc_iocbq irspiocbq
;
9089 unsigned long iflags
;
9091 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9092 pring
->stats
.iocb_event
++;
9093 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9095 /* Check for response status */
9096 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
9097 /* If resource errors reported from HBA, reduce queue
9098 * depth of the SCSI device.
9100 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
9101 IOSTAT_LOCAL_REJECT
) &&
9102 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
9103 phba
->lpfc_rampdown_queue_depth(phba
);
9105 /* Log the error status */
9106 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9107 "0373 FCP complete error: status=x%x, "
9108 "hw_status=x%x, total_data_specified=%d, "
9109 "parameter=x%x, word3=x%x\n",
9110 bf_get(lpfc_wcqe_c_status
, wcqe
),
9111 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
9112 wcqe
->total_data_placed
, wcqe
->parameter
,
9116 /* Look up the FCP command IOCB and create pseudo response IOCB */
9117 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9118 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
9119 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9120 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9121 if (unlikely(!cmdiocbq
)) {
9122 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9123 "0374 FCP complete with no corresponding "
9124 "cmdiocb: iotag (%d)\n",
9125 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9128 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
9129 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9130 "0375 FCP cmdiocb not callback function "
9132 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9136 /* Fake the irspiocb and copy necessary response information */
9137 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
9139 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
9140 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9141 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
9142 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9145 /* Pass the cmd_iocb and the rsp state to the upper layer */
9146 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
9150 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
9151 * @phba: Pointer to HBA context object.
9152 * @cq: Pointer to completion queue.
9153 * @wcqe: Pointer to work-queue completion queue entry.
9155 * This routine handles an fast-path WQ entry comsumed event by invoking the
9156 * proper WQ release routine to the slow-path WQ.
9159 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9160 struct lpfc_wcqe_release
*wcqe
)
9162 struct lpfc_queue
*childwq
;
9163 bool wqid_matched
= false;
9166 /* Check for fast-path FCP work queue release */
9167 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
9168 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
9169 if (childwq
->queue_id
== fcp_wqid
) {
9170 lpfc_sli4_wq_release(childwq
,
9171 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
9172 wqid_matched
= true;
9176 /* Report warning log message if no match found */
9177 if (wqid_matched
!= true)
9178 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9179 "2580 Fast-path wqe consume event carries "
9180 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
9184 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
9185 * @cq: Pointer to the completion queue.
9186 * @eqe: Pointer to fast-path completion queue entry.
9188 * This routine process a fast-path work queue completion entry from fast-path
9189 * event queue for FCP command response completion.
9192 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9193 struct lpfc_cqe
*cqe
)
9195 struct lpfc_wcqe_release wcqe
;
9196 bool workposted
= false;
9198 /* Copy the work queue CQE and convert endian order if needed */
9199 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
9201 /* Check and process for different type of WCQE and dispatch */
9202 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
9203 case CQE_CODE_COMPL_WQE
:
9204 /* Process the WQ complete event */
9205 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
9206 (struct lpfc_wcqe_complete
*)&wcqe
);
9208 case CQE_CODE_RELEASE_WQE
:
9209 /* Process the WQ release event */
9210 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
9211 (struct lpfc_wcqe_release
*)&wcqe
);
9213 case CQE_CODE_XRI_ABORTED
:
9214 /* Process the WQ XRI abort event */
9215 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
9216 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
9219 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9220 "0144 Not a valid WCQE code: x%x\n",
9221 bf_get(lpfc_wcqe_c_code
, &wcqe
));
9228 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
9229 * @phba: Pointer to HBA context object.
9230 * @eqe: Pointer to fast-path event queue entry.
9232 * This routine process a event queue entry from the fast-path event queue.
9233 * It will check the MajorCode and MinorCode to determine this is for a
9234 * completion event on a completion queue, if not, an error shall be logged
9235 * and just return. Otherwise, it will get to the corresponding completion
9236 * queue and process all the entries on the completion queue, rearm the
9237 * completion queue, and then return.
9240 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
9243 struct lpfc_queue
*cq
;
9244 struct lpfc_cqe
*cqe
;
9245 bool workposted
= false;
9249 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
9250 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9251 "0366 Not a valid fast-path completion "
9252 "event: majorcode=x%x, minorcode=x%x\n",
9253 bf_get_le32(lpfc_eqe_major_code
, eqe
),
9254 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
9258 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
9259 if (unlikely(!cq
)) {
9260 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9261 "0367 Fast-path completion queue does not "
9266 /* Get the reference to the corresponding CQ */
9267 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
9268 if (unlikely(cqid
!= cq
->queue_id
)) {
9269 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9270 "0368 Miss-matched fast-path completion "
9271 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
9272 cqid
, cq
->queue_id
);
9276 /* Process all the entries to the CQ */
9277 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9278 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
9279 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9280 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9283 /* Catch the no cq entry condition */
9284 if (unlikely(ecount
== 0))
9285 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9286 "0369 No entry from fast-path completion "
9287 "queue fcpcqid=%d\n", cq
->queue_id
);
9289 /* In any case, flash and re-arm the CQ */
9290 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9292 /* wake up worker thread if there are works to be done */
9294 lpfc_worker_wake_up(phba
);
9298 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
9300 struct lpfc_eqe
*eqe
;
9302 /* walk all the EQ entries and drop on the floor */
9303 while ((eqe
= lpfc_sli4_eq_get(eq
)))
9306 /* Clear and re-arm the EQ */
9307 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
9311 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
9312 * @irq: Interrupt number.
9313 * @dev_id: The device context pointer.
9315 * This function is directly called from the PCI layer as an interrupt
9316 * service routine when device with SLI-4 interface spec is enabled with
9317 * MSI-X multi-message interrupt mode and there are slow-path events in
9318 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9319 * interrupt mode, this function is called as part of the device-level
9320 * interrupt handler. When the PCI slot is in error recovery or the HBA is
9321 * undergoing initialization, the interrupt handler will not process the
9322 * interrupt. The link attention and ELS ring attention events are handled
9323 * by the worker thread. The interrupt handler signals the worker thread
9324 * and returns for these events. This function is called without any lock
9325 * held. It gets the hbalock to access and update SLI data structures.
9327 * This function returns IRQ_HANDLED when interrupt is handled else it
9331 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
9333 struct lpfc_hba
*phba
;
9334 struct lpfc_queue
*speq
;
9335 struct lpfc_eqe
*eqe
;
9336 unsigned long iflag
;
9340 * Get the driver's phba structure from the dev_id
9342 phba
= (struct lpfc_hba
*)dev_id
;
9344 if (unlikely(!phba
))
9347 /* Get to the EQ struct associated with this vector */
9348 speq
= phba
->sli4_hba
.sp_eq
;
9350 /* Check device state for handling interrupt */
9351 if (unlikely(lpfc_intr_state_check(phba
))) {
9352 /* Check again for link_state with lock held */
9353 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9354 if (phba
->link_state
< LPFC_LINK_DOWN
)
9355 /* Flush, clear interrupt, and rearm the EQ */
9356 lpfc_sli4_eq_flush(phba
, speq
);
9357 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9362 * Process all the event on FCP slow-path EQ
9364 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
9365 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
9366 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9367 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
9370 /* Always clear and re-arm the slow-path EQ */
9371 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
9373 /* Catch the no cq entry condition */
9374 if (unlikely(ecount
== 0)) {
9375 if (phba
->intr_type
== MSIX
)
9376 /* MSI-X treated interrupt served as no EQ share INT */
9377 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9378 "0357 MSI-X interrupt with no EQE\n");
9380 /* Non MSI-X treated on interrupt as EQ share INT */
9385 } /* lpfc_sli4_sp_intr_handler */
9388 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
9389 * @irq: Interrupt number.
9390 * @dev_id: The device context pointer.
9392 * This function is directly called from the PCI layer as an interrupt
9393 * service routine when device with SLI-4 interface spec is enabled with
9394 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
9395 * ring event in the HBA. However, when the device is enabled with either
9396 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
9397 * device-level interrupt handler. When the PCI slot is in error recovery
9398 * or the HBA is undergoing initialization, the interrupt handler will not
9399 * process the interrupt. The SCSI FCP fast-path ring event are handled in
9400 * the intrrupt context. This function is called without any lock held.
9401 * It gets the hbalock to access and update SLI data structures. Note that,
9402 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
9403 * equal to that of FCP CQ index.
9405 * This function returns IRQ_HANDLED when interrupt is handled else it
9409 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
9411 struct lpfc_hba
*phba
;
9412 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
9413 struct lpfc_queue
*fpeq
;
9414 struct lpfc_eqe
*eqe
;
9415 unsigned long iflag
;
9419 /* Get the driver's phba structure from the dev_id */
9420 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
9421 phba
= fcp_eq_hdl
->phba
;
9422 fcp_eqidx
= fcp_eq_hdl
->idx
;
9424 if (unlikely(!phba
))
9427 /* Get to the EQ struct associated with this vector */
9428 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
9430 /* Check device state for handling interrupt */
9431 if (unlikely(lpfc_intr_state_check(phba
))) {
9432 /* Check again for link_state with lock held */
9433 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9434 if (phba
->link_state
< LPFC_LINK_DOWN
)
9435 /* Flush, clear interrupt, and rearm the EQ */
9436 lpfc_sli4_eq_flush(phba
, fpeq
);
9437 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9442 * Process all the event on FCP fast-path EQ
9444 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9445 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
9446 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9447 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
9450 /* Always clear and re-arm the fast-path EQ */
9451 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
9453 if (unlikely(ecount
== 0)) {
9454 if (phba
->intr_type
== MSIX
)
9455 /* MSI-X treated interrupt served as no EQ share INT */
9456 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9457 "0358 MSI-X interrupt with no EQE\n");
9459 /* Non MSI-X treated on interrupt as EQ share INT */
9464 } /* lpfc_sli4_fp_intr_handler */
9467 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
9468 * @irq: Interrupt number.
9469 * @dev_id: The device context pointer.
9471 * This function is the device-level interrupt handler to device with SLI-4
9472 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
9473 * interrupt mode is enabled and there is an event in the HBA which requires
9474 * driver attention. This function invokes the slow-path interrupt attention
9475 * handling function and fast-path interrupt attention handling function in
9476 * turn to process the relevant HBA attention events. This function is called
9477 * without any lock held. It gets the hbalock to access and update SLI data
9480 * This function returns IRQ_HANDLED when interrupt is handled, else it
9484 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
9486 struct lpfc_hba
*phba
;
9487 irqreturn_t sp_irq_rc
, fp_irq_rc
;
9488 bool fp_handled
= false;
9491 /* Get the driver's phba structure from the dev_id */
9492 phba
= (struct lpfc_hba
*)dev_id
;
9494 if (unlikely(!phba
))
9498 * Invokes slow-path host attention interrupt handling as appropriate.
9500 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
9503 * Invoke fast-path host attention interrupt handling as appropriate.
9505 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
9506 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
9507 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
9508 if (fp_irq_rc
== IRQ_HANDLED
)
9512 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
9513 } /* lpfc_sli4_intr_handler */
9516 * lpfc_sli4_queue_free - free a queue structure and associated memory
9517 * @queue: The queue structure to free.
9519 * This function frees a queue structure and the DMAable memeory used for
9520 * the host resident queue. This function must be called after destroying the
9524 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
9526 struct lpfc_dmabuf
*dmabuf
;
9531 while (!list_empty(&queue
->page_list
)) {
9532 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
9534 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
9535 dmabuf
->virt
, dmabuf
->phys
);
9543 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
9544 * @phba: The HBA that this queue is being created on.
9545 * @entry_size: The size of each queue entry for this queue.
9546 * @entry count: The number of entries that this queue will handle.
9548 * This function allocates a queue structure and the DMAable memory used for
9549 * the host resident queue. This function must be called before creating the
9553 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
9554 uint32_t entry_count
)
9556 struct lpfc_queue
*queue
;
9557 struct lpfc_dmabuf
*dmabuf
;
9558 int x
, total_qe_count
;
9560 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9562 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9563 hw_page_size
= SLI4_PAGE_SIZE
;
9565 queue
= kzalloc(sizeof(struct lpfc_queue
) +
9566 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
9569 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
9570 hw_page_size
))/hw_page_size
;
9571 INIT_LIST_HEAD(&queue
->list
);
9572 INIT_LIST_HEAD(&queue
->page_list
);
9573 INIT_LIST_HEAD(&queue
->child_list
);
9574 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
9575 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
9578 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
9579 hw_page_size
, &dmabuf
->phys
,
9581 if (!dmabuf
->virt
) {
9585 memset(dmabuf
->virt
, 0, hw_page_size
);
9586 dmabuf
->buffer_tag
= x
;
9587 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
9588 /* initialize queue's entry array */
9589 dma_pointer
= dmabuf
->virt
;
9590 for (; total_qe_count
< entry_count
&&
9591 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
9592 total_qe_count
++, dma_pointer
+= entry_size
) {
9593 queue
->qe
[total_qe_count
].address
= dma_pointer
;
9596 queue
->entry_size
= entry_size
;
9597 queue
->entry_count
= entry_count
;
9602 lpfc_sli4_queue_free(queue
);
9607 * lpfc_eq_create - Create an Event Queue on the HBA
9608 * @phba: HBA structure that indicates port to create a queue on.
9609 * @eq: The queue structure to use to create the event queue.
9610 * @imax: The maximum interrupt per second limit.
9612 * This function creates an event queue, as detailed in @eq, on a port,
9613 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
9615 * The @phba struct is used to send mailbox command to HBA. The @eq struct
9616 * is used to get the entry count and entry size that are necessary to
9617 * determine the number of pages to allocate and use for this queue. This
9618 * function will send the EQ_CREATE mailbox command to the HBA to setup the
9619 * event queue. This function is asynchronous and will wait for the mailbox
9620 * command to finish before continuing.
9622 * On success this function will return a zero. If unable to allocate enough
9623 * memory this function will return ENOMEM. If the queue create mailbox command
9624 * fails this function will return ENXIO.
9627 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
9629 struct lpfc_mbx_eq_create
*eq_create
;
9631 int rc
, length
, status
= 0;
9632 struct lpfc_dmabuf
*dmabuf
;
9633 uint32_t shdr_status
, shdr_add_status
;
9634 union lpfc_sli4_cfg_shdr
*shdr
;
9636 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9638 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9639 hw_page_size
= SLI4_PAGE_SIZE
;
9641 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9644 length
= (sizeof(struct lpfc_mbx_eq_create
) -
9645 sizeof(struct lpfc_sli4_cfg_mhdr
));
9646 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9647 LPFC_MBOX_OPCODE_EQ_CREATE
,
9648 length
, LPFC_SLI4_MBX_EMBED
);
9649 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
9650 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
9652 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
9654 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
9655 /* Calculate delay multiper from maximum interrupt per second */
9656 dmult
= LPFC_DMULT_CONST
/imax
- 1;
9657 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
9659 switch (eq
->entry_count
) {
9661 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9662 "0360 Unsupported EQ count. (%d)\n",
9664 if (eq
->entry_count
< 256)
9666 /* otherwise default to smallest count (drop through) */
9668 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9672 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9676 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9680 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9684 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9688 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
9689 memset(dmabuf
->virt
, 0, hw_page_size
);
9690 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9691 putPaddrLow(dmabuf
->phys
);
9692 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9693 putPaddrHigh(dmabuf
->phys
);
9695 mbox
->vport
= phba
->pport
;
9696 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
9697 mbox
->context1
= NULL
;
9698 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9699 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
9700 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9701 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9702 if (shdr_status
|| shdr_add_status
|| rc
) {
9703 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9704 "2500 EQ_CREATE mailbox failed with "
9705 "status x%x add_status x%x, mbx status x%x\n",
9706 shdr_status
, shdr_add_status
, rc
);
9710 eq
->subtype
= LPFC_NONE
;
9711 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
9712 if (eq
->queue_id
== 0xFFFF)
9717 mempool_free(mbox
, phba
->mbox_mem_pool
);
9722 * lpfc_cq_create - Create a Completion Queue on the HBA
9723 * @phba: HBA structure that indicates port to create a queue on.
9724 * @cq: The queue structure to use to create the completion queue.
9725 * @eq: The event queue to bind this completion queue to.
9727 * This function creates a completion queue, as detailed in @wq, on a port,
9728 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
9730 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9731 * is used to get the entry count and entry size that are necessary to
9732 * determine the number of pages to allocate and use for this queue. The @eq
9733 * is used to indicate which event queue to bind this completion queue to. This
9734 * function will send the CQ_CREATE mailbox command to the HBA to setup the
9735 * completion queue. This function is asynchronous and will wait for the mailbox
9736 * command to finish before continuing.
9738 * On success this function will return a zero. If unable to allocate enough
9739 * memory this function will return ENOMEM. If the queue create mailbox command
9740 * fails this function will return ENXIO.
9743 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9744 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
9746 struct lpfc_mbx_cq_create
*cq_create
;
9747 struct lpfc_dmabuf
*dmabuf
;
9749 int rc
, length
, status
= 0;
9750 uint32_t shdr_status
, shdr_add_status
;
9751 union lpfc_sli4_cfg_shdr
*shdr
;
9752 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9754 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9755 hw_page_size
= SLI4_PAGE_SIZE
;
9758 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9761 length
= (sizeof(struct lpfc_mbx_cq_create
) -
9762 sizeof(struct lpfc_sli4_cfg_mhdr
));
9763 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9764 LPFC_MBOX_OPCODE_CQ_CREATE
,
9765 length
, LPFC_SLI4_MBX_EMBED
);
9766 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
9767 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
9769 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
9770 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
9771 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
, eq
->queue_id
);
9772 switch (cq
->entry_count
) {
9774 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9775 "0361 Unsupported CQ count. (%d)\n",
9777 if (cq
->entry_count
< 256)
9779 /* otherwise default to smallest count (drop through) */
9781 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9785 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9789 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9793 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
9794 memset(dmabuf
->virt
, 0, hw_page_size
);
9795 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9796 putPaddrLow(dmabuf
->phys
);
9797 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9798 putPaddrHigh(dmabuf
->phys
);
9800 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9802 /* The IOCTL status is embedded in the mailbox subheader. */
9803 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
9804 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9805 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9806 if (shdr_status
|| shdr_add_status
|| rc
) {
9807 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9808 "2501 CQ_CREATE mailbox failed with "
9809 "status x%x add_status x%x, mbx status x%x\n",
9810 shdr_status
, shdr_add_status
, rc
);
9814 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
9815 if (cq
->queue_id
== 0xFFFF) {
9819 /* link the cq onto the parent eq child list */
9820 list_add_tail(&cq
->list
, &eq
->child_list
);
9821 /* Set up completion queue's type and subtype */
9823 cq
->subtype
= subtype
;
9824 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
9829 mempool_free(mbox
, phba
->mbox_mem_pool
);
9834 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
9835 * @phba: HBA structure that indicates port to create a queue on.
9836 * @mq: The queue structure to use to create the mailbox queue.
9837 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
9838 * @cq: The completion queue to associate with this cq.
9840 * This function provides failback (fb) functionality when the
9841 * mq_create_ext fails on older FW generations. It's purpose is identical
9842 * to mq_create_ext otherwise.
9844 * This routine cannot fail as all attributes were previously accessed and
9845 * initialized in mq_create_ext.
9848 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
9849 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
9851 struct lpfc_mbx_mq_create
*mq_create
;
9852 struct lpfc_dmabuf
*dmabuf
;
9855 length
= (sizeof(struct lpfc_mbx_mq_create
) -
9856 sizeof(struct lpfc_sli4_cfg_mhdr
));
9857 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9858 LPFC_MBOX_OPCODE_MQ_CREATE
,
9859 length
, LPFC_SLI4_MBX_EMBED
);
9860 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
9861 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
9863 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
9865 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
9866 switch (mq
->entry_count
) {
9868 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9872 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9876 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9880 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9884 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
9885 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9886 putPaddrLow(dmabuf
->phys
);
9887 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9888 putPaddrHigh(dmabuf
->phys
);
9893 * lpfc_mq_create - Create a mailbox Queue on the HBA
9894 * @phba: HBA structure that indicates port to create a queue on.
9895 * @mq: The queue structure to use to create the mailbox queue.
9896 * @cq: The completion queue to associate with this cq.
9897 * @subtype: The queue's subtype.
9899 * This function creates a mailbox queue, as detailed in @mq, on a port,
9900 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
9902 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9903 * is used to get the entry count and entry size that are necessary to
9904 * determine the number of pages to allocate and use for this queue. This
9905 * function will send the MQ_CREATE mailbox command to the HBA to setup the
9906 * mailbox queue. This function is asynchronous and will wait for the mailbox
9907 * command to finish before continuing.
9909 * On success this function will return a zero. If unable to allocate enough
9910 * memory this function will return ENOMEM. If the queue create mailbox command
9911 * fails this function will return ENXIO.
9914 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
9915 struct lpfc_queue
*cq
, uint32_t subtype
)
9917 struct lpfc_mbx_mq_create
*mq_create
;
9918 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
9919 struct lpfc_dmabuf
*dmabuf
;
9921 int rc
, length
, status
= 0;
9922 uint32_t shdr_status
, shdr_add_status
;
9923 union lpfc_sli4_cfg_shdr
*shdr
;
9924 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9926 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9927 hw_page_size
= SLI4_PAGE_SIZE
;
9929 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9932 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
9933 sizeof(struct lpfc_sli4_cfg_mhdr
));
9934 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9935 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
9936 length
, LPFC_SLI4_MBX_EMBED
);
9938 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
9939 bf_set(lpfc_mbx_mq_create_ext_num_pages
, &mq_create_ext
->u
.request
,
9941 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
, &mq_create_ext
->u
.request
,
9943 bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste
,
9944 &mq_create_ext
->u
.request
, 1);
9945 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
9946 &mq_create_ext
->u
.request
, 1);
9947 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
9949 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
9950 switch (mq
->entry_count
) {
9952 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9953 "0362 Unsupported MQ count. (%d)\n",
9955 if (mq
->entry_count
< 16)
9957 /* otherwise default to smallest count (drop through) */
9959 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9963 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9967 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9971 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9975 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
9976 memset(dmabuf
->virt
, 0, hw_page_size
);
9977 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9978 putPaddrLow(dmabuf
->phys
);
9979 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9980 putPaddrHigh(dmabuf
->phys
);
9982 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9983 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
9984 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
9985 &mq_create_ext
->u
.response
);
9986 if (rc
!= MBX_SUCCESS
) {
9987 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9988 "2795 MQ_CREATE_EXT failed with "
9989 "status x%x. Failback to MQ_CREATE.\n",
9991 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
9992 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
9993 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9994 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
9995 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
9996 &mq_create
->u
.response
);
9999 /* The IOCTL status is embedded in the mailbox subheader. */
10000 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10001 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10002 if (shdr_status
|| shdr_add_status
|| rc
) {
10003 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10004 "2502 MQ_CREATE mailbox failed with "
10005 "status x%x add_status x%x, mbx status x%x\n",
10006 shdr_status
, shdr_add_status
, rc
);
10010 if (mq
->queue_id
== 0xFFFF) {
10014 mq
->type
= LPFC_MQ
;
10015 mq
->subtype
= subtype
;
10016 mq
->host_index
= 0;
10019 /* link the mq onto the parent cq child list */
10020 list_add_tail(&mq
->list
, &cq
->child_list
);
10022 mempool_free(mbox
, phba
->mbox_mem_pool
);
10027 * lpfc_wq_create - Create a Work Queue on the HBA
10028 * @phba: HBA structure that indicates port to create a queue on.
10029 * @wq: The queue structure to use to create the work queue.
10030 * @cq: The completion queue to bind this work queue to.
10031 * @subtype: The subtype of the work queue indicating its functionality.
10033 * This function creates a work queue, as detailed in @wq, on a port, described
10034 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
10036 * The @phba struct is used to send mailbox command to HBA. The @wq struct
10037 * is used to get the entry count and entry size that are necessary to
10038 * determine the number of pages to allocate and use for this queue. The @cq
10039 * is used to indicate which completion queue to bind this work queue to. This
10040 * function will send the WQ_CREATE mailbox command to the HBA to setup the
10041 * work queue. This function is asynchronous and will wait for the mailbox
10042 * command to finish before continuing.
10044 * On success this function will return a zero. If unable to allocate enough
10045 * memory this function will return ENOMEM. If the queue create mailbox command
10046 * fails this function will return ENXIO.
10049 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
10050 struct lpfc_queue
*cq
, uint32_t subtype
)
10052 struct lpfc_mbx_wq_create
*wq_create
;
10053 struct lpfc_dmabuf
*dmabuf
;
10054 LPFC_MBOXQ_t
*mbox
;
10055 int rc
, length
, status
= 0;
10056 uint32_t shdr_status
, shdr_add_status
;
10057 union lpfc_sli4_cfg_shdr
*shdr
;
10058 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10060 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10061 hw_page_size
= SLI4_PAGE_SIZE
;
10063 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10066 length
= (sizeof(struct lpfc_mbx_wq_create
) -
10067 sizeof(struct lpfc_sli4_cfg_mhdr
));
10068 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10069 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
10070 length
, LPFC_SLI4_MBX_EMBED
);
10071 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
10072 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
10074 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
10076 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
10077 memset(dmabuf
->virt
, 0, hw_page_size
);
10078 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10079 putPaddrLow(dmabuf
->phys
);
10080 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10081 putPaddrHigh(dmabuf
->phys
);
10083 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10084 /* The IOCTL status is embedded in the mailbox subheader. */
10085 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
10086 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10087 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10088 if (shdr_status
|| shdr_add_status
|| rc
) {
10089 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10090 "2503 WQ_CREATE mailbox failed with "
10091 "status x%x add_status x%x, mbx status x%x\n",
10092 shdr_status
, shdr_add_status
, rc
);
10096 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
10097 if (wq
->queue_id
== 0xFFFF) {
10101 wq
->type
= LPFC_WQ
;
10102 wq
->subtype
= subtype
;
10103 wq
->host_index
= 0;
10106 /* link the wq onto the parent cq child list */
10107 list_add_tail(&wq
->list
, &cq
->child_list
);
10109 mempool_free(mbox
, phba
->mbox_mem_pool
);
10114 * lpfc_rq_create - Create a Receive Queue on the HBA
10115 * @phba: HBA structure that indicates port to create a queue on.
10116 * @hrq: The queue structure to use to create the header receive queue.
10117 * @drq: The queue structure to use to create the data receive queue.
10118 * @cq: The completion queue to bind this work queue to.
10120 * This function creates a receive buffer queue pair , as detailed in @hrq and
10121 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
10124 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
10125 * struct is used to get the entry count that is necessary to determine the
10126 * number of pages to use for this queue. The @cq is used to indicate which
10127 * completion queue to bind received buffers that are posted to these queues to.
10128 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
10129 * receive queue pair. This function is asynchronous and will wait for the
10130 * mailbox command to finish before continuing.
10132 * On success this function will return a zero. If unable to allocate enough
10133 * memory this function will return ENOMEM. If the queue create mailbox command
10134 * fails this function will return ENXIO.
10137 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
10138 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
10140 struct lpfc_mbx_rq_create
*rq_create
;
10141 struct lpfc_dmabuf
*dmabuf
;
10142 LPFC_MBOXQ_t
*mbox
;
10143 int rc
, length
, status
= 0;
10144 uint32_t shdr_status
, shdr_add_status
;
10145 union lpfc_sli4_cfg_shdr
*shdr
;
10146 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10148 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10149 hw_page_size
= SLI4_PAGE_SIZE
;
10151 if (hrq
->entry_count
!= drq
->entry_count
)
10153 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10156 length
= (sizeof(struct lpfc_mbx_rq_create
) -
10157 sizeof(struct lpfc_sli4_cfg_mhdr
));
10158 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10159 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
10160 length
, LPFC_SLI4_MBX_EMBED
);
10161 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
10162 switch (hrq
->entry_count
) {
10164 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10165 "2535 Unsupported RQ count. (%d)\n",
10167 if (hrq
->entry_count
< 512)
10169 /* otherwise default to smallest count (drop through) */
10171 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10172 LPFC_RQ_RING_SIZE_512
);
10175 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10176 LPFC_RQ_RING_SIZE_1024
);
10179 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10180 LPFC_RQ_RING_SIZE_2048
);
10183 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10184 LPFC_RQ_RING_SIZE_4096
);
10187 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
10189 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
10191 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
10192 LPFC_HDR_BUF_SIZE
);
10193 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
10194 memset(dmabuf
->virt
, 0, hw_page_size
);
10195 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10196 putPaddrLow(dmabuf
->phys
);
10197 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10198 putPaddrHigh(dmabuf
->phys
);
10200 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10201 /* The IOCTL status is embedded in the mailbox subheader. */
10202 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
10203 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10204 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10205 if (shdr_status
|| shdr_add_status
|| rc
) {
10206 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10207 "2504 RQ_CREATE mailbox failed with "
10208 "status x%x add_status x%x, mbx status x%x\n",
10209 shdr_status
, shdr_add_status
, rc
);
10213 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
10214 if (hrq
->queue_id
== 0xFFFF) {
10218 hrq
->type
= LPFC_HRQ
;
10219 hrq
->subtype
= subtype
;
10220 hrq
->host_index
= 0;
10221 hrq
->hba_index
= 0;
10223 /* now create the data queue */
10224 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10225 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
10226 length
, LPFC_SLI4_MBX_EMBED
);
10227 switch (drq
->entry_count
) {
10229 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10230 "2536 Unsupported RQ count. (%d)\n",
10232 if (drq
->entry_count
< 512)
10234 /* otherwise default to smallest count (drop through) */
10236 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10237 LPFC_RQ_RING_SIZE_512
);
10240 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10241 LPFC_RQ_RING_SIZE_1024
);
10244 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10245 LPFC_RQ_RING_SIZE_2048
);
10248 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10249 LPFC_RQ_RING_SIZE_4096
);
10252 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
10254 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
10256 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
10257 LPFC_DATA_BUF_SIZE
);
10258 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
10259 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10260 putPaddrLow(dmabuf
->phys
);
10261 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10262 putPaddrHigh(dmabuf
->phys
);
10264 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10265 /* The IOCTL status is embedded in the mailbox subheader. */
10266 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
10267 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10268 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10269 if (shdr_status
|| shdr_add_status
|| rc
) {
10273 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
10274 if (drq
->queue_id
== 0xFFFF) {
10278 drq
->type
= LPFC_DRQ
;
10279 drq
->subtype
= subtype
;
10280 drq
->host_index
= 0;
10281 drq
->hba_index
= 0;
10283 /* link the header and data RQs onto the parent cq child list */
10284 list_add_tail(&hrq
->list
, &cq
->child_list
);
10285 list_add_tail(&drq
->list
, &cq
->child_list
);
10288 mempool_free(mbox
, phba
->mbox_mem_pool
);
10293 * lpfc_eq_destroy - Destroy an event Queue on the HBA
10294 * @eq: The queue structure associated with the queue to destroy.
10296 * This function destroys a queue, as detailed in @eq by sending an mailbox
10297 * command, specific to the type of queue, to the HBA.
10299 * The @eq struct is used to get the queue ID of the queue to destroy.
10301 * On success this function will return a zero. If the queue destroy mailbox
10302 * command fails this function will return ENXIO.
10305 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
10307 LPFC_MBOXQ_t
*mbox
;
10308 int rc
, length
, status
= 0;
10309 uint32_t shdr_status
, shdr_add_status
;
10310 union lpfc_sli4_cfg_shdr
*shdr
;
10314 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10317 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
10318 sizeof(struct lpfc_sli4_cfg_mhdr
));
10319 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10320 LPFC_MBOX_OPCODE_EQ_DESTROY
,
10321 length
, LPFC_SLI4_MBX_EMBED
);
10322 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
10324 mbox
->vport
= eq
->phba
->pport
;
10325 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10327 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
10328 /* The IOCTL status is embedded in the mailbox subheader. */
10329 shdr
= (union lpfc_sli4_cfg_shdr
*)
10330 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
10331 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10332 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10333 if (shdr_status
|| shdr_add_status
|| rc
) {
10334 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10335 "2505 EQ_DESTROY mailbox failed with "
10336 "status x%x add_status x%x, mbx status x%x\n",
10337 shdr_status
, shdr_add_status
, rc
);
10341 /* Remove eq from any list */
10342 list_del_init(&eq
->list
);
10343 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
10348 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
10349 * @cq: The queue structure associated with the queue to destroy.
10351 * This function destroys a queue, as detailed in @cq by sending an mailbox
10352 * command, specific to the type of queue, to the HBA.
10354 * The @cq struct is used to get the queue ID of the queue to destroy.
10356 * On success this function will return a zero. If the queue destroy mailbox
10357 * command fails this function will return ENXIO.
10360 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
10362 LPFC_MBOXQ_t
*mbox
;
10363 int rc
, length
, status
= 0;
10364 uint32_t shdr_status
, shdr_add_status
;
10365 union lpfc_sli4_cfg_shdr
*shdr
;
10369 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10372 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
10373 sizeof(struct lpfc_sli4_cfg_mhdr
));
10374 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10375 LPFC_MBOX_OPCODE_CQ_DESTROY
,
10376 length
, LPFC_SLI4_MBX_EMBED
);
10377 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
10379 mbox
->vport
= cq
->phba
->pport
;
10380 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10381 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
10382 /* The IOCTL status is embedded in the mailbox subheader. */
10383 shdr
= (union lpfc_sli4_cfg_shdr
*)
10384 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
10385 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10386 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10387 if (shdr_status
|| shdr_add_status
|| rc
) {
10388 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10389 "2506 CQ_DESTROY mailbox failed with "
10390 "status x%x add_status x%x, mbx status x%x\n",
10391 shdr_status
, shdr_add_status
, rc
);
10394 /* Remove cq from any list */
10395 list_del_init(&cq
->list
);
10396 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
10401 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
10402 * @qm: The queue structure associated with the queue to destroy.
10404 * This function destroys a queue, as detailed in @mq by sending an mailbox
10405 * command, specific to the type of queue, to the HBA.
10407 * The @mq struct is used to get the queue ID of the queue to destroy.
10409 * On success this function will return a zero. If the queue destroy mailbox
10410 * command fails this function will return ENXIO.
10413 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
10415 LPFC_MBOXQ_t
*mbox
;
10416 int rc
, length
, status
= 0;
10417 uint32_t shdr_status
, shdr_add_status
;
10418 union lpfc_sli4_cfg_shdr
*shdr
;
10422 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10425 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
10426 sizeof(struct lpfc_sli4_cfg_mhdr
));
10427 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10428 LPFC_MBOX_OPCODE_MQ_DESTROY
,
10429 length
, LPFC_SLI4_MBX_EMBED
);
10430 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
10432 mbox
->vport
= mq
->phba
->pport
;
10433 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10434 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
10435 /* The IOCTL status is embedded in the mailbox subheader. */
10436 shdr
= (union lpfc_sli4_cfg_shdr
*)
10437 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
10438 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10439 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10440 if (shdr_status
|| shdr_add_status
|| rc
) {
10441 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10442 "2507 MQ_DESTROY mailbox failed with "
10443 "status x%x add_status x%x, mbx status x%x\n",
10444 shdr_status
, shdr_add_status
, rc
);
10447 /* Remove mq from any list */
10448 list_del_init(&mq
->list
);
10449 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
10454 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
10455 * @wq: The queue structure associated with the queue to destroy.
10457 * This function destroys a queue, as detailed in @wq by sending an mailbox
10458 * command, specific to the type of queue, to the HBA.
10460 * The @wq struct is used to get the queue ID of the queue to destroy.
10462 * On success this function will return a zero. If the queue destroy mailbox
10463 * command fails this function will return ENXIO.
10466 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
10468 LPFC_MBOXQ_t
*mbox
;
10469 int rc
, length
, status
= 0;
10470 uint32_t shdr_status
, shdr_add_status
;
10471 union lpfc_sli4_cfg_shdr
*shdr
;
10475 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10478 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
10479 sizeof(struct lpfc_sli4_cfg_mhdr
));
10480 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10481 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
10482 length
, LPFC_SLI4_MBX_EMBED
);
10483 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
10485 mbox
->vport
= wq
->phba
->pport
;
10486 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10487 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
10488 shdr
= (union lpfc_sli4_cfg_shdr
*)
10489 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
10490 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10491 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10492 if (shdr_status
|| shdr_add_status
|| rc
) {
10493 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10494 "2508 WQ_DESTROY mailbox failed with "
10495 "status x%x add_status x%x, mbx status x%x\n",
10496 shdr_status
, shdr_add_status
, rc
);
10499 /* Remove wq from any list */
10500 list_del_init(&wq
->list
);
10501 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
10506 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
10507 * @rq: The queue structure associated with the queue to destroy.
10509 * This function destroys a queue, as detailed in @rq by sending an mailbox
10510 * command, specific to the type of queue, to the HBA.
10512 * The @rq struct is used to get the queue ID of the queue to destroy.
10514 * On success this function will return a zero. If the queue destroy mailbox
10515 * command fails this function will return ENXIO.
10518 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
10519 struct lpfc_queue
*drq
)
10521 LPFC_MBOXQ_t
*mbox
;
10522 int rc
, length
, status
= 0;
10523 uint32_t shdr_status
, shdr_add_status
;
10524 union lpfc_sli4_cfg_shdr
*shdr
;
10528 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10531 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
10532 sizeof(struct mbox_header
));
10533 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10534 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
10535 length
, LPFC_SLI4_MBX_EMBED
);
10536 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
10538 mbox
->vport
= hrq
->phba
->pport
;
10539 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10540 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
10541 /* The IOCTL status is embedded in the mailbox subheader. */
10542 shdr
= (union lpfc_sli4_cfg_shdr
*)
10543 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
10544 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10545 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10546 if (shdr_status
|| shdr_add_status
|| rc
) {
10547 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10548 "2509 RQ_DESTROY mailbox failed with "
10549 "status x%x add_status x%x, mbx status x%x\n",
10550 shdr_status
, shdr_add_status
, rc
);
10551 if (rc
!= MBX_TIMEOUT
)
10552 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
10555 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
10557 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
10558 shdr
= (union lpfc_sli4_cfg_shdr
*)
10559 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
10560 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10561 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10562 if (shdr_status
|| shdr_add_status
|| rc
) {
10563 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10564 "2510 RQ_DESTROY mailbox failed with "
10565 "status x%x add_status x%x, mbx status x%x\n",
10566 shdr_status
, shdr_add_status
, rc
);
10569 list_del_init(&hrq
->list
);
10570 list_del_init(&drq
->list
);
10571 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
10576 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
10577 * @phba: The virtual port for which this call being executed.
10578 * @pdma_phys_addr0: Physical address of the 1st SGL page.
10579 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
10580 * @xritag: the xritag that ties this io to the SGL pages.
10582 * This routine will post the sgl pages for the IO that has the xritag
10583 * that is in the iocbq structure. The xritag is assigned during iocbq
10584 * creation and persists for as long as the driver is loaded.
10585 * if the caller has fewer than 256 scatter gather segments to map then
10586 * pdma_phys_addr1 should be 0.
10587 * If the caller needs to map more than 256 scatter gather segment then
10588 * pdma_phys_addr1 should be a valid physical address.
10589 * physical address for SGLs must be 64 byte aligned.
10590 * If you are going to map 2 SGL's then the first one must have 256 entries
10591 * the second sgl can have between 1 and 256 entries.
10595 * -ENXIO, -ENOMEM - Failure
10598 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
10599 dma_addr_t pdma_phys_addr0
,
10600 dma_addr_t pdma_phys_addr1
,
10603 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
10604 LPFC_MBOXQ_t
*mbox
;
10606 uint32_t shdr_status
, shdr_add_status
;
10607 union lpfc_sli4_cfg_shdr
*shdr
;
10609 if (xritag
== NO_XRI
) {
10610 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10611 "0364 Invalid param:\n");
10615 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10619 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10620 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
10621 sizeof(struct lpfc_mbx_post_sgl_pages
) -
10622 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
10624 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
10625 &mbox
->u
.mqe
.un
.post_sgl_pages
;
10626 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
10627 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
10629 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
10630 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
10631 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
10632 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
10634 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
10635 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
10636 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
10637 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
10638 if (!phba
->sli4_hba
.intr_enable
)
10639 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10641 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
10642 /* The IOCTL status is embedded in the mailbox subheader. */
10643 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
10644 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10645 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10646 if (rc
!= MBX_TIMEOUT
)
10647 mempool_free(mbox
, phba
->mbox_mem_pool
);
10648 if (shdr_status
|| shdr_add_status
|| rc
) {
10649 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10650 "2511 POST_SGL mailbox failed with "
10651 "status x%x add_status x%x, mbx status x%x\n",
10652 shdr_status
, shdr_add_status
, rc
);
10658 * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
10659 * @phba: The virtual port for which this call being executed.
10661 * This routine will remove all of the sgl pages registered with the hba.
10665 * -ENXIO, -ENOMEM - Failure
10668 lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba
*phba
)
10670 LPFC_MBOXQ_t
*mbox
;
10672 uint32_t shdr_status
, shdr_add_status
;
10673 union lpfc_sli4_cfg_shdr
*shdr
;
10675 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10679 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10680 LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES
, 0,
10681 LPFC_SLI4_MBX_EMBED
);
10682 if (!phba
->sli4_hba
.intr_enable
)
10683 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10685 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
10686 /* The IOCTL status is embedded in the mailbox subheader. */
10687 shdr
= (union lpfc_sli4_cfg_shdr
*)
10688 &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
10689 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10690 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10691 if (rc
!= MBX_TIMEOUT
)
10692 mempool_free(mbox
, phba
->mbox_mem_pool
);
10693 if (shdr_status
|| shdr_add_status
|| rc
) {
10694 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10695 "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
10696 "status x%x add_status x%x, mbx status x%x\n",
10697 shdr_status
, shdr_add_status
, rc
);
10704 * lpfc_sli4_next_xritag - Get an xritag for the io
10705 * @phba: Pointer to HBA context object.
10707 * This function gets an xritag for the iocb. If there is no unused xritag
10708 * it will return 0xffff.
10709 * The function returns the allocated xritag if successful, else returns zero.
10710 * Zero is not a valid xritag.
10711 * The caller is not required to hold any lock.
10714 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
10718 spin_lock_irq(&phba
->hbalock
);
10719 xritag
= phba
->sli4_hba
.next_xri
;
10720 if ((xritag
!= (uint16_t) -1) && xritag
<
10721 (phba
->sli4_hba
.max_cfg_param
.max_xri
10722 + phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
10723 phba
->sli4_hba
.next_xri
++;
10724 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
10725 spin_unlock_irq(&phba
->hbalock
);
10728 spin_unlock_irq(&phba
->hbalock
);
10729 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10730 "2004 Failed to allocate XRI.last XRITAG is %d"
10731 " Max XRI is %d, Used XRI is %d\n",
10732 phba
->sli4_hba
.next_xri
,
10733 phba
->sli4_hba
.max_cfg_param
.max_xri
,
10734 phba
->sli4_hba
.max_cfg_param
.xri_used
);
10739 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
10740 * @phba: pointer to lpfc hba data structure.
10742 * This routine is invoked to post a block of driver's sgl pages to the
10743 * HBA using non-embedded mailbox command. No Lock is held. This routine
10744 * is only called when the driver is loading and after all IO has been
10748 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
)
10750 struct lpfc_sglq
*sglq_entry
;
10751 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
10752 struct sgl_page_pairs
*sgl_pg_pairs
;
10754 LPFC_MBOXQ_t
*mbox
;
10755 uint32_t reqlen
, alloclen
, pg_pairs
;
10757 uint16_t xritag_start
= 0;
10758 int els_xri_cnt
, rc
= 0;
10759 uint32_t shdr_status
, shdr_add_status
;
10760 union lpfc_sli4_cfg_shdr
*shdr
;
10762 /* The number of sgls to be posted */
10763 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
10765 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
10766 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
10767 if (reqlen
> SLI4_PAGE_SIZE
) {
10768 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10769 "2559 Block sgl registration required DMA "
10770 "size (%d) great than a page\n", reqlen
);
10773 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10775 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10776 "2560 Failed to allocate mbox cmd memory\n");
10780 /* Allocate DMA memory and set up the non-embedded mailbox command */
10781 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10782 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
10783 LPFC_SLI4_MBX_NEMBED
);
10785 if (alloclen
< reqlen
) {
10786 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10787 "0285 Allocated DMA memory size (%d) is "
10788 "less than the requested DMA memory "
10789 "size (%d)\n", alloclen
, reqlen
);
10790 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10793 /* Get the first SGE entry from the non-embedded DMA memory */
10794 viraddr
= mbox
->sge_array
->addr
[0];
10796 /* Set up the SGL pages in the non-embedded DMA pages */
10797 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
10798 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
10800 for (pg_pairs
= 0; pg_pairs
< els_xri_cnt
; pg_pairs
++) {
10801 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[pg_pairs
];
10802 /* Set up the sge entry */
10803 sgl_pg_pairs
->sgl_pg0_addr_lo
=
10804 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
10805 sgl_pg_pairs
->sgl_pg0_addr_hi
=
10806 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
10807 sgl_pg_pairs
->sgl_pg1_addr_lo
=
10808 cpu_to_le32(putPaddrLow(0));
10809 sgl_pg_pairs
->sgl_pg1_addr_hi
=
10810 cpu_to_le32(putPaddrHigh(0));
10811 /* Keep the first xritag on the list */
10813 xritag_start
= sglq_entry
->sli4_xritag
;
10816 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
10817 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, els_xri_cnt
);
10818 /* Perform endian conversion if necessary */
10819 sgl
->word0
= cpu_to_le32(sgl
->word0
);
10821 if (!phba
->sli4_hba
.intr_enable
)
10822 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10824 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
10825 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
10827 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
10828 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10829 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10830 if (rc
!= MBX_TIMEOUT
)
10831 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10832 if (shdr_status
|| shdr_add_status
|| rc
) {
10833 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10834 "2513 POST_SGL_BLOCK mailbox command failed "
10835 "status x%x add_status x%x mbx status x%x\n",
10836 shdr_status
, shdr_add_status
, rc
);
10843 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
10844 * @phba: pointer to lpfc hba data structure.
10845 * @sblist: pointer to scsi buffer list.
10846 * @count: number of scsi buffers on the list.
10848 * This routine is invoked to post a block of @count scsi sgl pages from a
10849 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
10854 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
, struct list_head
*sblist
,
10857 struct lpfc_scsi_buf
*psb
;
10858 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
10859 struct sgl_page_pairs
*sgl_pg_pairs
;
10861 LPFC_MBOXQ_t
*mbox
;
10862 uint32_t reqlen
, alloclen
, pg_pairs
;
10864 uint16_t xritag_start
= 0;
10866 uint32_t shdr_status
, shdr_add_status
;
10867 dma_addr_t pdma_phys_bpl1
;
10868 union lpfc_sli4_cfg_shdr
*shdr
;
10870 /* Calculate the requested length of the dma memory */
10871 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
10872 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
10873 if (reqlen
> SLI4_PAGE_SIZE
) {
10874 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10875 "0217 Block sgl registration required DMA "
10876 "size (%d) great than a page\n", reqlen
);
10879 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10881 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10882 "0283 Failed to allocate mbox cmd memory\n");
10886 /* Allocate DMA memory and set up the non-embedded mailbox command */
10887 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10888 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
10889 LPFC_SLI4_MBX_NEMBED
);
10891 if (alloclen
< reqlen
) {
10892 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10893 "2561 Allocated DMA memory size (%d) is "
10894 "less than the requested DMA memory "
10895 "size (%d)\n", alloclen
, reqlen
);
10896 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10899 /* Get the first SGE entry from the non-embedded DMA memory */
10900 viraddr
= mbox
->sge_array
->addr
[0];
10902 /* Set up the SGL pages in the non-embedded DMA pages */
10903 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
10904 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
10907 list_for_each_entry(psb
, sblist
, list
) {
10908 /* Set up the sge entry */
10909 sgl_pg_pairs
->sgl_pg0_addr_lo
=
10910 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
10911 sgl_pg_pairs
->sgl_pg0_addr_hi
=
10912 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
10913 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
10914 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
10916 pdma_phys_bpl1
= 0;
10917 sgl_pg_pairs
->sgl_pg1_addr_lo
=
10918 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
10919 sgl_pg_pairs
->sgl_pg1_addr_hi
=
10920 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
10921 /* Keep the first xritag on the list */
10923 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
10927 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
10928 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
10929 /* Perform endian conversion if necessary */
10930 sgl
->word0
= cpu_to_le32(sgl
->word0
);
10932 if (!phba
->sli4_hba
.intr_enable
)
10933 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10935 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
10936 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
10938 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
10939 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10940 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10941 if (rc
!= MBX_TIMEOUT
)
10942 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10943 if (shdr_status
|| shdr_add_status
|| rc
) {
10944 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10945 "2564 POST_SGL_BLOCK mailbox command failed "
10946 "status x%x add_status x%x mbx status x%x\n",
10947 shdr_status
, shdr_add_status
, rc
);
10954 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
10955 * @phba: pointer to lpfc_hba struct that the frame was received on
10956 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10958 * This function checks the fields in the @fc_hdr to see if the FC frame is a
10959 * valid type of frame that the LPFC driver will handle. This function will
10960 * return a zero if the frame is a valid frame or a non zero value when the
10961 * frame does not pass the check.
10964 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
10966 char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
10967 char *type_names
[] = FC_TYPE_NAMES_INIT
;
10968 struct fc_vft_header
*fc_vft_hdr
;
10970 switch (fc_hdr
->fh_r_ctl
) {
10971 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
10972 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
10973 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
10974 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
10975 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
10976 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
10977 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
10978 case FC_RCTL_DD_CMD_STATUS
: /* command status */
10979 case FC_RCTL_ELS_REQ
: /* extended link services request */
10980 case FC_RCTL_ELS_REP
: /* extended link services reply */
10981 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
10982 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
10983 case FC_RCTL_BA_NOP
: /* basic link service NOP */
10984 case FC_RCTL_BA_ABTS
: /* basic link service abort */
10985 case FC_RCTL_BA_RMC
: /* remove connection */
10986 case FC_RCTL_BA_ACC
: /* basic accept */
10987 case FC_RCTL_BA_RJT
: /* basic reject */
10988 case FC_RCTL_BA_PRMT
:
10989 case FC_RCTL_ACK_1
: /* acknowledge_1 */
10990 case FC_RCTL_ACK_0
: /* acknowledge_0 */
10991 case FC_RCTL_P_RJT
: /* port reject */
10992 case FC_RCTL_F_RJT
: /* fabric reject */
10993 case FC_RCTL_P_BSY
: /* port busy */
10994 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
10995 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
10996 case FC_RCTL_LCR
: /* link credit reset */
10997 case FC_RCTL_END
: /* end */
10999 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
11000 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
11001 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
11002 return lpfc_fc_frame_check(phba
, fc_hdr
);
11006 switch (fc_hdr
->fh_type
) {
11017 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
11018 "2538 Received frame rctl:%s type:%s\n",
11019 rctl_names
[fc_hdr
->fh_r_ctl
],
11020 type_names
[fc_hdr
->fh_type
]);
11023 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
11024 "2539 Dropped frame rctl:%s type:%s\n",
11025 rctl_names
[fc_hdr
->fh_r_ctl
],
11026 type_names
[fc_hdr
->fh_type
]);
11031 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
11032 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11034 * This function processes the FC header to retrieve the VFI from the VF
11035 * header, if one exists. This function will return the VFI if one exists
11036 * or 0 if no VSAN Header exists.
11039 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
11041 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
11043 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
11045 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
11049 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
11050 * @phba: Pointer to the HBA structure to search for the vport on
11051 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11052 * @fcfi: The FC Fabric ID that the frame came from
11054 * This function searches the @phba for a vport that matches the content of the
11055 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
11056 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
11057 * returns the matching vport pointer or NULL if unable to match frame to a
11060 static struct lpfc_vport
*
11061 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
11064 struct lpfc_vport
**vports
;
11065 struct lpfc_vport
*vport
= NULL
;
11067 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
11068 fc_hdr
->fh_d_id
[1] << 8 |
11069 fc_hdr
->fh_d_id
[2]);
11071 vports
= lpfc_create_vport_work_array(phba
);
11072 if (vports
!= NULL
)
11073 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
11074 if (phba
->fcf
.fcfi
== fcfi
&&
11075 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
11076 vports
[i
]->fc_myDID
== did
) {
11081 lpfc_destroy_vport_work_array(phba
, vports
);
11086 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
11087 * @vport: The vport to work on.
11089 * This function updates the receive sequence time stamp for this vport. The
11090 * receive sequence time stamp indicates the time that the last frame of the
11091 * the sequence that has been idle for the longest amount of time was received.
11092 * the driver uses this time stamp to indicate if any received sequences have
11096 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
11098 struct lpfc_dmabuf
*h_buf
;
11099 struct hbq_dmabuf
*dmabuf
= NULL
;
11101 /* get the oldest sequence on the rcv list */
11102 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
11103 struct lpfc_dmabuf
, list
);
11106 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11107 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
11111 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
11112 * @vport: The vport that the received sequences were sent to.
11114 * This function cleans up all outstanding received sequences. This is called
11115 * by the driver when a link event or user action invalidates all the received
11119 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
11121 struct lpfc_dmabuf
*h_buf
, *hnext
;
11122 struct lpfc_dmabuf
*d_buf
, *dnext
;
11123 struct hbq_dmabuf
*dmabuf
= NULL
;
11125 /* start with the oldest sequence on the rcv list */
11126 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
11127 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11128 list_del_init(&dmabuf
->hbuf
.list
);
11129 list_for_each_entry_safe(d_buf
, dnext
,
11130 &dmabuf
->dbuf
.list
, list
) {
11131 list_del_init(&d_buf
->list
);
11132 lpfc_in_buf_free(vport
->phba
, d_buf
);
11134 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
11139 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
11140 * @vport: The vport that the received sequences were sent to.
11142 * This function determines whether any received sequences have timed out by
11143 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
11144 * indicates that there is at least one timed out sequence this routine will
11145 * go through the received sequences one at a time from most inactive to most
11146 * active to determine which ones need to be cleaned up. Once it has determined
11147 * that a sequence needs to be cleaned up it will simply free up the resources
11148 * without sending an abort.
11151 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
11153 struct lpfc_dmabuf
*h_buf
, *hnext
;
11154 struct lpfc_dmabuf
*d_buf
, *dnext
;
11155 struct hbq_dmabuf
*dmabuf
= NULL
;
11156 unsigned long timeout
;
11157 int abort_count
= 0;
11159 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
11160 vport
->rcv_buffer_time_stamp
);
11161 if (list_empty(&vport
->rcv_buffer_list
) ||
11162 time_before(jiffies
, timeout
))
11164 /* start with the oldest sequence on the rcv list */
11165 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
11166 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11167 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
11168 dmabuf
->time_stamp
);
11169 if (time_before(jiffies
, timeout
))
11172 list_del_init(&dmabuf
->hbuf
.list
);
11173 list_for_each_entry_safe(d_buf
, dnext
,
11174 &dmabuf
->dbuf
.list
, list
) {
11175 list_del_init(&d_buf
->list
);
11176 lpfc_in_buf_free(vport
->phba
, d_buf
);
11178 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
11181 lpfc_update_rcv_time_stamp(vport
);
11185 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
11186 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
11188 * This function searches through the existing incomplete sequences that have
11189 * been sent to this @vport. If the frame matches one of the incomplete
11190 * sequences then the dbuf in the @dmabuf is added to the list of frames that
11191 * make up that sequence. If no sequence is found that matches this frame then
11192 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
11193 * This function returns a pointer to the first dmabuf in the sequence list that
11194 * the frame was linked to.
11196 static struct hbq_dmabuf
*
11197 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
11199 struct fc_frame_header
*new_hdr
;
11200 struct fc_frame_header
*temp_hdr
;
11201 struct lpfc_dmabuf
*d_buf
;
11202 struct lpfc_dmabuf
*h_buf
;
11203 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
11204 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
11206 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
11207 dmabuf
->time_stamp
= jiffies
;
11208 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11209 /* Use the hdr_buf to find the sequence that this frame belongs to */
11210 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
11211 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
11212 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
11213 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
11214 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
11216 /* found a pending sequence that matches this frame */
11217 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11222 * This indicates first frame received for this sequence.
11223 * Queue the buffer on the vport's rcv_buffer_list.
11225 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11226 lpfc_update_rcv_time_stamp(vport
);
11229 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
11230 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
11231 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
11232 list_del_init(&seq_dmabuf
->hbuf
.list
);
11233 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11234 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
11235 lpfc_update_rcv_time_stamp(vport
);
11238 /* move this sequence to the tail to indicate a young sequence */
11239 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11240 seq_dmabuf
->time_stamp
= jiffies
;
11241 lpfc_update_rcv_time_stamp(vport
);
11242 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
11243 temp_hdr
= dmabuf
->hbuf
.virt
;
11244 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
11247 /* find the correct place in the sequence to insert this frame */
11248 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
11249 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
11250 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
11252 * If the frame's sequence count is greater than the frame on
11253 * the list then insert the frame right after this frame
11255 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
11256 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
11257 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
11265 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
11266 * @vport: pointer to a vitural port
11267 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11269 * This function tries to abort from the partially assembed sequence, described
11270 * by the information from basic abbort @dmabuf. It checks to see whether such
11271 * partially assembled sequence held by the driver. If so, it shall free up all
11272 * the frames from the partially assembled sequence.
11275 * true -- if there is matching partially assembled sequence present and all
11276 * the frames freed with the sequence;
11277 * false -- if there is no matching partially assembled sequence present so
11278 * nothing got aborted in the lower layer driver
11281 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
11282 struct hbq_dmabuf
*dmabuf
)
11284 struct fc_frame_header
*new_hdr
;
11285 struct fc_frame_header
*temp_hdr
;
11286 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
11287 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
11289 /* Use the hdr_buf to find the sequence that matches this frame */
11290 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
11291 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
11292 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11293 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
11294 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
11295 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
11296 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
11297 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
11299 /* found a pending sequence that matches this frame */
11300 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11304 /* Free up all the frames from the partially assembled sequence */
11306 list_for_each_entry_safe(d_buf
, n_buf
,
11307 &seq_dmabuf
->dbuf
.list
, list
) {
11308 list_del_init(&d_buf
->list
);
11309 lpfc_in_buf_free(vport
->phba
, d_buf
);
11317 * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
11318 * @phba: Pointer to HBA context object.
11319 * @cmd_iocbq: pointer to the command iocbq structure.
11320 * @rsp_iocbq: pointer to the response iocbq structure.
11322 * This function handles the sequence abort accept iocb command complete
11323 * event. It properly releases the memory allocated to the sequence abort
11327 lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba
*phba
,
11328 struct lpfc_iocbq
*cmd_iocbq
,
11329 struct lpfc_iocbq
*rsp_iocbq
)
11332 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
11336 * lpfc_sli4_seq_abort_acc - Accept sequence abort
11337 * @phba: Pointer to HBA context object.
11338 * @fc_hdr: pointer to a FC frame header.
11340 * This function sends a basic accept to a previous unsol sequence abort
11341 * event after aborting the sequence handling.
11344 lpfc_sli4_seq_abort_acc(struct lpfc_hba
*phba
,
11345 struct fc_frame_header
*fc_hdr
)
11347 struct lpfc_iocbq
*ctiocb
= NULL
;
11348 struct lpfc_nodelist
*ndlp
;
11349 uint16_t oxid
, rxid
;
11350 uint32_t sid
, fctl
;
11353 if (!lpfc_is_link_up(phba
))
11356 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
11357 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
11358 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
11360 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
11362 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
11363 "1268 Find ndlp returned NULL for oxid:x%x "
11364 "SID:x%x\n", oxid
, sid
);
11368 /* Allocate buffer for acc iocb */
11369 ctiocb
= lpfc_sli_get_iocbq(phba
);
11373 /* Extract the F_CTL field from FC_HDR */
11374 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
11376 icmd
= &ctiocb
->iocb
;
11377 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
11378 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
11379 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
11380 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
11381 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
11383 /* Fill in the rest of iocb fields */
11384 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
11385 icmd
->ulpBdeCount
= 0;
11387 icmd
->ulpClass
= CLASS3
;
11388 icmd
->ulpContext
= ndlp
->nlp_rpi
;
11390 ctiocb
->iocb_cmpl
= NULL
;
11391 ctiocb
->vport
= phba
->pport
;
11392 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_acc_cmpl
;
11394 if (fctl
& FC_FC_EX_CTX
) {
11395 /* ABTS sent by responder to CT exchange, construction
11396 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
11397 * field and RX_ID from ABTS for RX_ID field.
11399 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_acc
, LPFC_ABTS_UNSOL_RSP
);
11400 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_acc
, rxid
);
11401 ctiocb
->sli4_xritag
= oxid
;
11403 /* ABTS sent by initiator to CT exchange, construction
11404 * of BA_ACC will need to allocate a new XRI as for the
11405 * XRI_TAG and RX_ID fields.
11407 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_acc
, LPFC_ABTS_UNSOL_INT
);
11408 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_acc
, NO_XRI
);
11409 ctiocb
->sli4_xritag
= NO_XRI
;
11411 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_acc
, oxid
);
11413 /* Xmit CT abts accept on exchange <xid> */
11414 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
11415 "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
11416 CMD_XMIT_BLS_RSP64_CX
, phba
->link_state
);
11417 lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
11421 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
11422 * @vport: Pointer to the vport on which this sequence was received
11423 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11425 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
11426 * receive sequence is only partially assembed by the driver, it shall abort
11427 * the partially assembled frames for the sequence. Otherwise, if the
11428 * unsolicited receive sequence has been completely assembled and passed to
11429 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
11430 * unsolicited sequence has been aborted. After that, it will issue a basic
11431 * accept to accept the abort.
11434 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
11435 struct hbq_dmabuf
*dmabuf
)
11437 struct lpfc_hba
*phba
= vport
->phba
;
11438 struct fc_frame_header fc_hdr
;
11442 /* Make a copy of fc_hdr before the dmabuf being released */
11443 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
11444 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
11446 if (fctl
& FC_FC_EX_CTX
) {
11448 * ABTS sent by responder to exchange, just free the buffer
11450 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11453 * ABTS sent by initiator to exchange, need to do cleanup
11455 /* Try to abort partially assembled seq */
11456 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
11458 /* Send abort to ULP if partially seq abort failed */
11459 if (abts_par
== false)
11460 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
11462 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11464 /* Send basic accept (BA_ACC) to the abort requester */
11465 lpfc_sli4_seq_abort_acc(phba
, &fc_hdr
);
11469 * lpfc_seq_complete - Indicates if a sequence is complete
11470 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11472 * This function checks the sequence, starting with the frame described by
11473 * @dmabuf, to see if all the frames associated with this sequence are present.
11474 * the frames associated with this sequence are linked to the @dmabuf using the
11475 * dbuf list. This function looks for two major things. 1) That the first frame
11476 * has a sequence count of zero. 2) There is a frame with last frame of sequence
11477 * set. 3) That there are no holes in the sequence count. The function will
11478 * return 1 when the sequence is complete, otherwise it will return 0.
11481 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
11483 struct fc_frame_header
*hdr
;
11484 struct lpfc_dmabuf
*d_buf
;
11485 struct hbq_dmabuf
*seq_dmabuf
;
11489 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11490 /* make sure first fame of sequence has a sequence count of zero */
11491 if (hdr
->fh_seq_cnt
!= seq_count
)
11493 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
11494 hdr
->fh_f_ctl
[1] << 8 |
11496 /* If last frame of sequence we can return success. */
11497 if (fctl
& FC_FC_END_SEQ
)
11499 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
11500 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
11501 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11502 /* If there is a hole in the sequence count then fail. */
11503 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
11505 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
11506 hdr
->fh_f_ctl
[1] << 8 |
11508 /* If last frame of sequence we can return success. */
11509 if (fctl
& FC_FC_END_SEQ
)
11516 * lpfc_prep_seq - Prep sequence for ULP processing
11517 * @vport: Pointer to the vport on which this sequence was received
11518 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11520 * This function takes a sequence, described by a list of frames, and creates
11521 * a list of iocbq structures to describe the sequence. This iocbq list will be
11522 * used to issue to the generic unsolicited sequence handler. This routine
11523 * returns a pointer to the first iocbq in the list. If the function is unable
11524 * to allocate an iocbq then it throw out the received frames that were not
11525 * able to be described and return a pointer to the first iocbq. If unable to
11526 * allocate any iocbqs (including the first) this function will return NULL.
11528 static struct lpfc_iocbq
*
11529 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
11531 struct lpfc_dmabuf
*d_buf
, *n_buf
;
11532 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
11533 struct fc_frame_header
*fc_hdr
;
11535 struct ulp_bde64
*pbde
;
11537 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11538 /* remove from receive buffer list */
11539 list_del_init(&seq_dmabuf
->hbuf
.list
);
11540 lpfc_update_rcv_time_stamp(vport
);
11541 /* get the Remote Port's SID */
11542 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
11543 /* Get an iocbq struct to fill in. */
11544 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
11546 /* Initialize the first IOCB. */
11547 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
11548 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
11549 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
11550 first_iocbq
->iocb
.ulpContext
= be16_to_cpu(fc_hdr
->fh_ox_id
);
11551 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
11552 vport
->vpi
+ vport
->phba
->vpi_base
;
11553 /* put the first buffer into the first IOCBq */
11554 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
11555 first_iocbq
->context3
= NULL
;
11556 first_iocbq
->iocb
.ulpBdeCount
= 1;
11557 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
11558 LPFC_DATA_BUF_SIZE
;
11559 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
11560 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
11561 bf_get(lpfc_rcqe_length
,
11562 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11564 iocbq
= first_iocbq
;
11566 * Each IOCBq can have two Buffers assigned, so go through the list
11567 * of buffers for this sequence and save two buffers in each IOCBq
11569 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
11571 lpfc_in_buf_free(vport
->phba
, d_buf
);
11574 if (!iocbq
->context3
) {
11575 iocbq
->context3
= d_buf
;
11576 iocbq
->iocb
.ulpBdeCount
++;
11577 pbde
= (struct ulp_bde64
*)
11578 &iocbq
->iocb
.unsli3
.sli3Words
[4];
11579 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
11580 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
11581 bf_get(lpfc_rcqe_length
,
11582 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11584 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
11587 first_iocbq
->iocb
.ulpStatus
=
11588 IOSTAT_FCP_RSP_ERROR
;
11589 first_iocbq
->iocb
.un
.ulpWord
[4] =
11590 IOERR_NO_RESOURCES
;
11592 lpfc_in_buf_free(vport
->phba
, d_buf
);
11595 iocbq
->context2
= d_buf
;
11596 iocbq
->context3
= NULL
;
11597 iocbq
->iocb
.ulpBdeCount
= 1;
11598 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
11599 LPFC_DATA_BUF_SIZE
;
11600 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
11601 bf_get(lpfc_rcqe_length
,
11602 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11603 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
11604 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
11607 return first_iocbq
;
11611 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
11612 struct hbq_dmabuf
*seq_dmabuf
)
11614 struct fc_frame_header
*fc_hdr
;
11615 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
11616 struct lpfc_hba
*phba
= vport
->phba
;
11618 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11619 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
11621 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11622 "2707 Ring %d handler: Failed to allocate "
11623 "iocb Rctl x%x Type x%x received\n",
11625 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
11628 if (!lpfc_complete_unsol_iocb(phba
,
11629 &phba
->sli
.ring
[LPFC_ELS_RING
],
11630 iocbq
, fc_hdr
->fh_r_ctl
,
11632 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11633 "2540 Ring %d handler: unexpected Rctl "
11634 "x%x Type x%x received\n",
11636 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
11638 /* Free iocb created in lpfc_prep_seq */
11639 list_for_each_entry_safe(curr_iocb
, next_iocb
,
11640 &iocbq
->list
, list
) {
11641 list_del_init(&curr_iocb
->list
);
11642 lpfc_sli_release_iocbq(phba
, curr_iocb
);
11644 lpfc_sli_release_iocbq(phba
, iocbq
);
11648 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
11649 * @phba: Pointer to HBA context object.
11651 * This function is called with no lock held. This function processes all
11652 * the received buffers and gives it to upper layers when a received buffer
11653 * indicates that it is the final frame in the sequence. The interrupt
11654 * service routine processes received buffers at interrupt contexts and adds
11655 * received dma buffers to the rb_pend_list queue and signals the worker thread.
11656 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
11657 * appropriate receive function when the final frame in a sequence is received.
11660 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
11661 struct hbq_dmabuf
*dmabuf
)
11663 struct hbq_dmabuf
*seq_dmabuf
;
11664 struct fc_frame_header
*fc_hdr
;
11665 struct lpfc_vport
*vport
;
11668 /* Process each received buffer */
11669 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11670 /* check to see if this a valid type of frame */
11671 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
11672 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11675 fcfi
= bf_get(lpfc_rcqe_fcf_id
, &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11676 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
11677 if (!vport
|| !(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
11678 /* throw out the frame */
11679 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11682 /* Handle the basic abort sequence (BA_ABTS) event */
11683 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
11684 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
11688 /* Link this frame */
11689 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
11691 /* unable to add frame to vport - throw it out */
11692 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11695 /* If not last frame in sequence continue processing frames. */
11696 if (!lpfc_seq_complete(seq_dmabuf
))
11699 /* Send the complete sequence to the upper layer protocol */
11700 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
11704 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
11705 * @phba: pointer to lpfc hba data structure.
11707 * This routine is invoked to post rpi header templates to the
11708 * HBA consistent with the SLI-4 interface spec. This routine
11709 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
11710 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
11712 * This routine does not require any locks. It's usage is expected
11713 * to be driver load or reset recovery when the driver is
11718 * EIO - The mailbox failed to complete successfully.
11719 * When this error occurs, the driver is not guaranteed
11720 * to have any rpi regions posted to the device and
11721 * must either attempt to repost the regions or take a
11725 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
11727 struct lpfc_rpi_hdr
*rpi_page
;
11730 /* Post all rpi memory regions to the port. */
11731 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
11732 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
11733 if (rc
!= MBX_SUCCESS
) {
11734 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11735 "2008 Error %d posting all rpi "
11746 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
11747 * @phba: pointer to lpfc hba data structure.
11748 * @rpi_page: pointer to the rpi memory region.
11750 * This routine is invoked to post a single rpi header to the
11751 * HBA consistent with the SLI-4 interface spec. This memory region
11752 * maps up to 64 rpi context regions.
11756 * ENOMEM - No available memory
11757 * EIO - The mailbox failed to complete successfully.
11760 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
11762 LPFC_MBOXQ_t
*mboxq
;
11763 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
11766 uint32_t shdr_status
, shdr_add_status
;
11767 union lpfc_sli4_cfg_shdr
*shdr
;
11769 /* The port is notified of the header region via a mailbox command. */
11770 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11772 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11773 "2001 Unable to allocate memory for issuing "
11774 "SLI_CONFIG_SPECIAL mailbox command\n");
11778 /* Post all rpi memory regions to the port. */
11779 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
11780 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
11781 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11782 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
11783 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
11784 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
11785 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
11786 hdr_tmpl
, rpi_page
->page_count
);
11787 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
11788 rpi_page
->start_rpi
);
11789 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
11790 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
11791 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
11792 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
11793 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11794 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11795 if (rc
!= MBX_TIMEOUT
)
11796 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11797 if (shdr_status
|| shdr_add_status
|| rc
) {
11798 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11799 "2514 POST_RPI_HDR mailbox failed with "
11800 "status x%x add_status x%x, mbx status x%x\n",
11801 shdr_status
, shdr_add_status
, rc
);
11808 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
11809 * @phba: pointer to lpfc hba data structure.
11811 * This routine is invoked to post rpi header templates to the
11812 * HBA consistent with the SLI-4 interface spec. This routine
11813 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
11814 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
11817 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
11818 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
11821 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
11824 uint16_t max_rpi
, rpi_base
, rpi_limit
;
11825 uint16_t rpi_remaining
;
11826 struct lpfc_rpi_hdr
*rpi_hdr
;
11828 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
11829 rpi_base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
11830 rpi_limit
= phba
->sli4_hba
.next_rpi
;
11833 * The valid rpi range is not guaranteed to be zero-based. Start
11834 * the search at the rpi_base as reported by the port.
11836 spin_lock_irq(&phba
->hbalock
);
11837 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, rpi_base
);
11838 if (rpi
>= rpi_limit
|| rpi
< rpi_base
)
11839 rpi
= LPFC_RPI_ALLOC_ERROR
;
11841 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
11842 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
11843 phba
->sli4_hba
.rpi_count
++;
11847 * Don't try to allocate more rpi header regions if the device limit
11848 * on available rpis max has been exhausted.
11850 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
11851 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
11852 spin_unlock_irq(&phba
->hbalock
);
11857 * If the driver is running low on rpi resources, allocate another
11858 * page now. Note that the next_rpi value is used because
11859 * it represents how many are actually in use whereas max_rpi notes
11860 * how many are supported max by the device.
11862 rpi_remaining
= phba
->sli4_hba
.next_rpi
- rpi_base
-
11863 phba
->sli4_hba
.rpi_count
;
11864 spin_unlock_irq(&phba
->hbalock
);
11865 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
11866 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
11868 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11869 "2002 Error Could not grow rpi "
11872 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
11880 * lpfc_sli4_free_rpi - Release an rpi for reuse.
11881 * @phba: pointer to lpfc hba data structure.
11883 * This routine is invoked to release an rpi to the pool of
11884 * available rpis maintained by the driver.
11887 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
11889 spin_lock_irq(&phba
->hbalock
);
11890 clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
11891 phba
->sli4_hba
.rpi_count
--;
11892 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
11893 spin_unlock_irq(&phba
->hbalock
);
11897 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
11898 * @phba: pointer to lpfc hba data structure.
11900 * This routine is invoked to remove the memory region that
11901 * provided rpi via a bitmask.
11904 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
11906 kfree(phba
->sli4_hba
.rpi_bmask
);
11910 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
11911 * @phba: pointer to lpfc hba data structure.
11913 * This routine is invoked to remove the memory region that
11914 * provided rpi via a bitmask.
11917 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
)
11919 LPFC_MBOXQ_t
*mboxq
;
11920 struct lpfc_hba
*phba
= ndlp
->phba
;
11923 /* The port is notified of the header region via a mailbox command. */
11924 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11928 /* Post all rpi memory regions to the port. */
11929 lpfc_resume_rpi(mboxq
, ndlp
);
11930 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
11931 if (rc
== MBX_NOT_FINISHED
) {
11932 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11933 "2010 Resume RPI Mailbox failed "
11934 "status %d, mbxStatus x%x\n", rc
,
11935 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
11936 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11943 * lpfc_sli4_init_vpi - Initialize a vpi with the port
11944 * @phba: pointer to lpfc hba data structure.
11945 * @vpi: vpi value to activate with the port.
11947 * This routine is invoked to activate a vpi with the
11948 * port when the host intends to use vports with a
11953 * -Evalue otherwise
11956 lpfc_sli4_init_vpi(struct lpfc_hba
*phba
, uint16_t vpi
)
11958 LPFC_MBOXQ_t
*mboxq
;
11960 int retval
= MBX_SUCCESS
;
11965 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11968 lpfc_init_vpi(phba
, mboxq
, vpi
);
11969 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_INIT_VPI
);
11970 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
11971 if (rc
!= MBX_SUCCESS
) {
11972 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11973 "2022 INIT VPI Mailbox failed "
11974 "status %d, mbxStatus x%x\n", rc
,
11975 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
11978 if (rc
!= MBX_TIMEOUT
)
11979 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11985 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
11986 * @phba: pointer to lpfc hba data structure.
11987 * @mboxq: Pointer to mailbox object.
11989 * This routine is invoked to manually add a single FCF record. The caller
11990 * must pass a completely initialized FCF_Record. This routine takes
11991 * care of the nonembedded mailbox operations.
11994 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
11997 union lpfc_sli4_cfg_shdr
*shdr
;
11998 uint32_t shdr_status
, shdr_add_status
;
12000 virt_addr
= mboxq
->sge_array
->addr
[0];
12001 /* The IOCTL status is embedded in the mailbox subheader. */
12002 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
12003 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12004 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12006 if ((shdr_status
|| shdr_add_status
) &&
12007 (shdr_status
!= STATUS_FCF_IN_USE
))
12008 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12009 "2558 ADD_FCF_RECORD mailbox failed with "
12010 "status x%x add_status x%x\n",
12011 shdr_status
, shdr_add_status
);
12013 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12017 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
12018 * @phba: pointer to lpfc hba data structure.
12019 * @fcf_record: pointer to the initialized fcf record to add.
12021 * This routine is invoked to manually add a single FCF record. The caller
12022 * must pass a completely initialized FCF_Record. This routine takes
12023 * care of the nonembedded mailbox operations.
12026 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
12029 LPFC_MBOXQ_t
*mboxq
;
12032 dma_addr_t phys_addr
;
12033 struct lpfc_mbx_sge sge
;
12034 uint32_t alloc_len
, req_len
;
12037 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12039 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12040 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
12044 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
12047 /* Allocate DMA memory and set up the non-embedded mailbox command */
12048 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12049 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
12050 req_len
, LPFC_SLI4_MBX_NEMBED
);
12051 if (alloc_len
< req_len
) {
12052 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12053 "2523 Allocated DMA memory size (x%x) is "
12054 "less than the requested DMA memory "
12055 "size (x%x)\n", alloc_len
, req_len
);
12056 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12061 * Get the first SGE entry from the non-embedded DMA memory. This
12062 * routine only uses a single SGE.
12064 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
12065 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
12066 virt_addr
= mboxq
->sge_array
->addr
[0];
12068 * Configure the FCF record for FCFI 0. This is the driver's
12069 * hardcoded default and gets used in nonFIP mode.
12071 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
12072 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
12073 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
12076 * Copy the fcf_index and the FCF Record Data. The data starts after
12077 * the FCoE header plus word10. The data copy needs to be endian
12080 bytep
+= sizeof(uint32_t);
12081 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
12082 mboxq
->vport
= phba
->pport
;
12083 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
12084 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12085 if (rc
== MBX_NOT_FINISHED
) {
12086 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12087 "2515 ADD_FCF_RECORD mailbox failed with "
12088 "status 0x%x\n", rc
);
12089 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12098 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
12099 * @phba: pointer to lpfc hba data structure.
12100 * @fcf_record: pointer to the fcf record to write the default data.
12101 * @fcf_index: FCF table entry index.
12103 * This routine is invoked to build the driver's default FCF record. The
12104 * values used are hardcoded. This routine handles memory initialization.
12108 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
12109 struct fcf_record
*fcf_record
,
12110 uint16_t fcf_index
)
12112 memset(fcf_record
, 0, sizeof(struct fcf_record
));
12113 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
12114 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
12115 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
12116 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
12117 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
12118 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
12119 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
12120 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
12121 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
12122 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
12123 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
12124 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
12125 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
12126 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
12127 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
12128 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
12129 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
12130 /* Set the VLAN bit map */
12131 if (phba
->valid_vlan
) {
12132 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
12133 = 1 << (phba
->vlan_id
% 8);
12138 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
12139 * @phba: pointer to lpfc hba data structure.
12140 * @fcf_index: FCF table entry offset.
12142 * This routine is invoked to scan the entire FCF table by reading FCF
12143 * record and processing it one at a time starting from the @fcf_index
12144 * for initial FCF discovery or fast FCF failover rediscovery.
12146 * Return 0 if the mailbox command is submitted sucessfully, none 0
12150 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12153 LPFC_MBOXQ_t
*mboxq
;
12155 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
12156 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12158 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12159 "2000 Failed to allocate mbox for "
12162 goto fail_fcf_scan
;
12164 /* Construct the read FCF record mailbox command */
12165 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12168 goto fail_fcf_scan
;
12170 /* Issue the mailbox command asynchronously */
12171 mboxq
->vport
= phba
->pport
;
12172 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
12173 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12174 if (rc
== MBX_NOT_FINISHED
)
12177 spin_lock_irq(&phba
->hbalock
);
12178 phba
->hba_flag
|= FCF_DISC_INPROGRESS
;
12179 spin_unlock_irq(&phba
->hbalock
);
12180 /* Reset FCF round robin index bmask for new scan */
12181 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
) {
12182 memset(phba
->fcf
.fcf_rr_bmask
, 0,
12183 sizeof(*phba
->fcf
.fcf_rr_bmask
));
12184 phba
->fcf
.eligible_fcf_cnt
= 0;
12191 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12192 /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
12193 spin_lock_irq(&phba
->hbalock
);
12194 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
12195 spin_unlock_irq(&phba
->hbalock
);
12201 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
12202 * @phba: pointer to lpfc hba data structure.
12203 * @fcf_index: FCF table entry offset.
12205 * This routine is invoked to read an FCF record indicated by @fcf_index
12206 * and to use it for FLOGI round robin FCF failover.
12208 * Return 0 if the mailbox command is submitted sucessfully, none 0
12212 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12215 LPFC_MBOXQ_t
*mboxq
;
12217 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12219 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
12220 "2763 Failed to allocate mbox for "
12223 goto fail_fcf_read
;
12225 /* Construct the read FCF record mailbox command */
12226 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12229 goto fail_fcf_read
;
12231 /* Issue the mailbox command asynchronously */
12232 mboxq
->vport
= phba
->pport
;
12233 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
12234 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12235 if (rc
== MBX_NOT_FINISHED
)
12241 if (error
&& mboxq
)
12242 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12247 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
12248 * @phba: pointer to lpfc hba data structure.
12249 * @fcf_index: FCF table entry offset.
12251 * This routine is invoked to read an FCF record indicated by @fcf_index to
12252 * determine whether it's eligible for FLOGI round robin failover list.
12254 * Return 0 if the mailbox command is submitted sucessfully, none 0
12258 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12261 LPFC_MBOXQ_t
*mboxq
;
12263 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12265 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
12266 "2758 Failed to allocate mbox for "
12269 goto fail_fcf_read
;
12271 /* Construct the read FCF record mailbox command */
12272 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12275 goto fail_fcf_read
;
12277 /* Issue the mailbox command asynchronously */
12278 mboxq
->vport
= phba
->pport
;
12279 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
12280 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12281 if (rc
== MBX_NOT_FINISHED
)
12287 if (error
&& mboxq
)
12288 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12293 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
12294 * @phba: pointer to lpfc hba data structure.
12296 * This routine is to get the next eligible FCF record index in a round
12297 * robin fashion. If the next eligible FCF record index equals to the
12298 * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
12299 * shall be returned, otherwise, the next eligible FCF record's index
12300 * shall be returned.
12303 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
12305 uint16_t next_fcf_index
;
12307 /* Search from the currently registered FCF index */
12308 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
12309 LPFC_SLI4_FCF_TBL_INDX_MAX
,
12310 phba
->fcf
.current_rec
.fcf_indx
);
12311 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
12312 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
12313 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
12314 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
12315 /* Round robin failover stop condition */
12316 if (next_fcf_index
== phba
->fcf
.fcf_rr_init_indx
)
12317 return LPFC_FCOE_FCF_NEXT_NONE
;
12319 return next_fcf_index
;
12323 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
12324 * @phba: pointer to lpfc hba data structure.
12326 * This routine sets the FCF record index in to the eligible bmask for
12327 * round robin failover search. It checks to make sure that the index
12328 * does not go beyond the range of the driver allocated bmask dimension
12329 * before setting the bit.
12331 * Returns 0 if the index bit successfully set, otherwise, it returns
12335 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12337 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
12338 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12339 "2610 HBA FCF index reached driver's "
12340 "book keeping dimension: fcf_index:%d, "
12341 "driver_bmask_max:%d\n",
12342 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
12345 /* Set the eligible FCF record index bmask */
12346 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
12352 * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
12353 * @phba: pointer to lpfc hba data structure.
12355 * This routine clears the FCF record index from the eligible bmask for
12356 * round robin failover search. It checks to make sure that the index
12357 * does not go beyond the range of the driver allocated bmask dimension
12358 * before clearing the bit.
12361 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12363 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
12364 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12365 "2762 HBA FCF index goes beyond driver's "
12366 "book keeping dimension: fcf_index:%d, "
12367 "driver_bmask_max:%d\n",
12368 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
12371 /* Clear the eligible FCF record index bmask */
12372 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
12376 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
12377 * @phba: pointer to lpfc hba data structure.
12379 * This routine is the completion routine for the rediscover FCF table mailbox
12380 * command. If the mailbox command returned failure, it will try to stop the
12381 * FCF rediscover wait timer.
12384 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
12386 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
12387 uint32_t shdr_status
, shdr_add_status
;
12389 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
12391 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
12392 &redisc_fcf
->header
.cfg_shdr
.response
);
12393 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
12394 &redisc_fcf
->header
.cfg_shdr
.response
);
12395 if (shdr_status
|| shdr_add_status
) {
12396 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12397 "2746 Requesting for FCF rediscovery failed "
12398 "status x%x add_status x%x\n",
12399 shdr_status
, shdr_add_status
);
12400 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
12401 spin_lock_irq(&phba
->hbalock
);
12402 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
12403 spin_unlock_irq(&phba
->hbalock
);
12405 * CVL event triggered FCF rediscover request failed,
12406 * last resort to re-try current registered FCF entry.
12408 lpfc_retry_pport_discovery(phba
);
12410 spin_lock_irq(&phba
->hbalock
);
12411 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
12412 spin_unlock_irq(&phba
->hbalock
);
12414 * DEAD FCF event triggered FCF rediscover request
12415 * failed, last resort to fail over as a link down
12416 * to FCF registration.
12418 lpfc_sli4_fcf_dead_failthrough(phba
);
12421 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
12422 "2775 Start FCF rediscovery quiescent period "
12423 "wait timer before scaning FCF table\n");
12425 * Start FCF rediscovery wait timer for pending FCF
12426 * before rescan FCF record table.
12428 lpfc_fcf_redisc_wait_start_timer(phba
);
12431 mempool_free(mbox
, phba
->mbox_mem_pool
);
12435 * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
12436 * @phba: pointer to lpfc hba data structure.
12438 * This routine is invoked to request for rediscovery of the entire FCF table
12442 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
12444 LPFC_MBOXQ_t
*mbox
;
12445 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
12448 /* Cancel retry delay timers to all vports before FCF rediscover */
12449 lpfc_cancel_all_vport_retry_delay_timer(phba
);
12451 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12453 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12454 "2745 Failed to allocate mbox for "
12455 "requesting FCF rediscover.\n");
12459 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
12460 sizeof(struct lpfc_sli4_cfg_mhdr
));
12461 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12462 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
12463 length
, LPFC_SLI4_MBX_EMBED
);
12465 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
12466 /* Set count to 0 for invalidating the entire FCF database */
12467 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
12469 /* Issue the mailbox command asynchronously */
12470 mbox
->vport
= phba
->pport
;
12471 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
12472 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
12474 if (rc
== MBX_NOT_FINISHED
) {
12475 mempool_free(mbox
, phba
->mbox_mem_pool
);
12482 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
12483 * @phba: pointer to lpfc hba data structure.
12485 * This function is the failover routine as a last resort to the FCF DEAD
12486 * event when driver failed to perform fast FCF failover.
12489 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
12491 uint32_t link_state
;
12494 * Last resort as FCF DEAD event failover will treat this as
12495 * a link down, but save the link state because we don't want
12496 * it to be changed to Link Down unless it is already down.
12498 link_state
= phba
->link_state
;
12499 lpfc_linkdown(phba
);
12500 phba
->link_state
= link_state
;
12502 /* Unregister FCF if no devices connected to it */
12503 lpfc_unregister_unused_fcf(phba
);
12507 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
12508 * @phba: pointer to lpfc hba data structure.
12510 * This function read region 23 and parse TLV for port status to
12511 * decide if the user disaled the port. If the TLV indicates the
12512 * port is disabled, the hba_flag is set accordingly.
12515 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
12517 LPFC_MBOXQ_t
*pmb
= NULL
;
12519 uint8_t *rgn23_data
= NULL
;
12520 uint32_t offset
= 0, data_size
, sub_tlv_len
, tlv_offset
;
12523 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12525 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12526 "2600 lpfc_sli_read_serdes_param failed to"
12527 " allocate mailbox memory\n");
12532 /* Get adapter Region 23 data */
12533 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
12538 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
12539 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
12541 if (rc
!= MBX_SUCCESS
) {
12542 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12543 "2601 lpfc_sli_read_link_ste failed to"
12544 " read config region 23 rc 0x%x Status 0x%x\n",
12545 rc
, mb
->mbxStatus
);
12546 mb
->un
.varDmp
.word_cnt
= 0;
12549 * dump mem may return a zero when finished or we got a
12550 * mailbox error, either way we are done.
12552 if (mb
->un
.varDmp
.word_cnt
== 0)
12554 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
12555 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
12557 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
12558 rgn23_data
+ offset
,
12559 mb
->un
.varDmp
.word_cnt
);
12560 offset
+= mb
->un
.varDmp
.word_cnt
;
12561 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
12563 data_size
= offset
;
12569 /* Check the region signature first */
12570 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
12571 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12572 "2619 Config region 23 has bad signature\n");
12577 /* Check the data structure version */
12578 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
12579 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12580 "2620 Config region 23 has bad version\n");
12585 /* Parse TLV entries in the region */
12586 while (offset
< data_size
) {
12587 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
12590 * If the TLV is not driver specific TLV or driver id is
12591 * not linux driver id, skip the record.
12593 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
12594 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
12595 (rgn23_data
[offset
+ 3] != 0)) {
12596 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
12600 /* Driver found a driver specific TLV in the config region */
12601 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
12606 * Search for configured port state sub-TLV.
12608 while ((offset
< data_size
) &&
12609 (tlv_offset
< sub_tlv_len
)) {
12610 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
12615 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
12616 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
12617 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
12621 /* This HBA contains PORT_STE configured */
12622 if (!rgn23_data
[offset
+ 2])
12623 phba
->hba_flag
|= LINK_DISABLED
;
12630 mempool_free(pmb
, phba
->mbox_mem_pool
);
12636 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
12637 * @vport: pointer to vport data structure.
12639 * This function iterate through the mailboxq and clean up all REG_LOGIN
12640 * and REG_VPI mailbox commands associated with the vport. This function
12641 * is called when driver want to restart discovery of the vport due to
12642 * a Clear Virtual Link event.
12645 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
12647 struct lpfc_hba
*phba
= vport
->phba
;
12648 LPFC_MBOXQ_t
*mb
, *nextmb
;
12649 struct lpfc_dmabuf
*mp
;
12650 struct lpfc_nodelist
*ndlp
;
12652 spin_lock_irq(&phba
->hbalock
);
12653 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
12654 if (mb
->vport
!= vport
)
12657 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
12658 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
12661 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
12662 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
12664 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
12667 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
12669 lpfc_nlp_put(ndlp
);
12670 mb
->context2
= NULL
;
12673 list_del(&mb
->list
);
12674 mempool_free(mb
, phba
->mbox_mem_pool
);
12676 mb
= phba
->sli
.mbox_active
;
12677 if (mb
&& (mb
->vport
== vport
)) {
12678 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
12679 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
12680 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12681 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
12682 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
12684 lpfc_nlp_put(ndlp
);
12685 mb
->context2
= NULL
;
12687 /* Unregister the RPI when mailbox complete */
12688 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
12691 spin_unlock_irq(&phba
->hbalock
);