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_INB_ENABLED
|
3889 LPFC_SLI3_BG_ENABLED
);
3890 if (rc
!= MBX_SUCCESS
) {
3891 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3892 "0442 Adapter failed to init, mbxCmd x%x "
3893 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3894 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
3895 spin_lock_irq(&phba
->hbalock
);
3896 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
3897 spin_unlock_irq(&phba
->hbalock
);
3900 /* Allow asynchronous mailbox command to go through */
3901 spin_lock_irq(&phba
->hbalock
);
3902 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
3903 spin_unlock_irq(&phba
->hbalock
);
3909 goto do_prep_failed
;
3911 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
3912 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
3914 goto do_prep_failed
;
3916 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
3917 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
3918 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
3919 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
3920 phba
->max_vpi
: phba
->max_vports
;
3924 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
)
3925 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
3926 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
3927 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
3928 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
3929 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
3930 if (pmb
->u
.mb
.un
.varCfgPort
.ginb
) {
3931 phba
->sli3_options
|= LPFC_SLI3_INB_ENABLED
;
3932 phba
->hbq_get
= phba
->mbox
->us
.s3_inb_pgp
.hbq_get
;
3933 phba
->port_gp
= phba
->mbox
->us
.s3_inb_pgp
.port
;
3934 phba
->inb_ha_copy
= &phba
->mbox
->us
.s3_inb_pgp
.ha_copy
;
3935 phba
->inb_counter
= &phba
->mbox
->us
.s3_inb_pgp
.counter
;
3936 phba
->inb_last_counter
=
3937 phba
->mbox
->us
.s3_inb_pgp
.counter
;
3939 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
3940 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
3941 phba
->inb_ha_copy
= NULL
;
3942 phba
->inb_counter
= NULL
;
3945 if (phba
->cfg_enable_bg
) {
3946 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
3947 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
3949 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3950 "0443 Adapter did not grant "
3954 phba
->hbq_get
= NULL
;
3955 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
3956 phba
->inb_ha_copy
= NULL
;
3957 phba
->inb_counter
= NULL
;
3961 mempool_free(pmb
, phba
->mbox_mem_pool
);
3967 * lpfc_sli_hba_setup - SLI intialization function
3968 * @phba: Pointer to HBA context object.
3970 * This function is the main SLI intialization function. This function
3971 * is called by the HBA intialization code, HBA reset code and HBA
3972 * error attention handler code. Caller is not required to hold any
3973 * locks. This function issues config_port mailbox command to configure
3974 * the SLI, setup iocb rings and HBQ rings. In the end the function
3975 * calls the config_port_post function to issue init_link mailbox
3976 * command and to start the discovery. The function will return zero
3977 * if successful, else it will return negative error code.
3980 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
3985 switch (lpfc_sli_mode
) {
3987 if (phba
->cfg_enable_npiv
) {
3988 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
3989 "1824 NPIV enabled: Override lpfc_sli_mode "
3990 "parameter (%d) to auto (0).\n",
4000 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4001 "1819 Unrecognized lpfc_sli_mode "
4002 "parameter: %d.\n", lpfc_sli_mode
);
4007 rc
= lpfc_sli_config_port(phba
, mode
);
4009 if (rc
&& lpfc_sli_mode
== 3)
4010 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4011 "1820 Unable to select SLI-3. "
4012 "Not supported by adapter.\n");
4013 if (rc
&& mode
!= 2)
4014 rc
= lpfc_sli_config_port(phba
, 2);
4016 goto lpfc_sli_hba_setup_error
;
4018 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4019 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4020 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4022 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4023 "2709 This device supports "
4024 "Advanced Error Reporting (AER)\n");
4025 spin_lock_irq(&phba
->hbalock
);
4026 phba
->hba_flag
|= HBA_AER_ENABLED
;
4027 spin_unlock_irq(&phba
->hbalock
);
4029 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4030 "2708 This device does not support "
4031 "Advanced Error Reporting (AER)\n");
4032 phba
->cfg_aer_support
= 0;
4036 if (phba
->sli_rev
== 3) {
4037 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4038 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4040 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4041 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4042 phba
->sli3_options
= 0;
4045 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4046 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4047 phba
->sli_rev
, phba
->max_vpi
);
4048 rc
= lpfc_sli_ring_map(phba
);
4051 goto lpfc_sli_hba_setup_error
;
4054 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4055 rc
= lpfc_sli_hbq_setup(phba
);
4057 goto lpfc_sli_hba_setup_error
;
4059 spin_lock_irq(&phba
->hbalock
);
4060 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4061 spin_unlock_irq(&phba
->hbalock
);
4063 rc
= lpfc_config_port_post(phba
);
4065 goto lpfc_sli_hba_setup_error
;
4069 lpfc_sli_hba_setup_error
:
4070 phba
->link_state
= LPFC_HBA_ERROR
;
4071 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4072 "0445 Firmware initialization failed\n");
4077 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4078 * @phba: Pointer to HBA context object.
4079 * @mboxq: mailbox pointer.
4080 * This function issue a dump mailbox command to read config region
4081 * 23 and parse the records in the region and populate driver
4085 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
,
4086 LPFC_MBOXQ_t
*mboxq
)
4088 struct lpfc_dmabuf
*mp
;
4089 struct lpfc_mqe
*mqe
;
4090 uint32_t data_length
;
4093 /* Program the default value of vlan_id and fc_map */
4094 phba
->valid_vlan
= 0;
4095 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4096 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4097 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4099 mqe
= &mboxq
->u
.mqe
;
4100 if (lpfc_dump_fcoe_param(phba
, mboxq
))
4103 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4104 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4106 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4107 "(%d):2571 Mailbox cmd x%x Status x%x "
4108 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4109 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4110 "CQ: x%x x%x x%x x%x\n",
4111 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4112 bf_get(lpfc_mqe_command
, mqe
),
4113 bf_get(lpfc_mqe_status
, mqe
),
4114 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4115 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4116 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4117 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4118 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4119 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4120 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4121 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4122 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4124 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4125 mboxq
->mcqe
.trailer
);
4128 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4132 data_length
= mqe
->un
.mb_words
[5];
4133 if (data_length
> DMP_RGN23_SIZE
) {
4134 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4139 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4140 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4146 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4147 * @phba: pointer to lpfc hba data structure.
4148 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4149 * @vpd: pointer to the memory to hold resulting port vpd data.
4150 * @vpd_size: On input, the number of bytes allocated to @vpd.
4151 * On output, the number of data bytes in @vpd.
4153 * This routine executes a READ_REV SLI4 mailbox command. In
4154 * addition, this routine gets the port vpd data.
4158 * ENOMEM - could not allocated memory.
4161 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4162 uint8_t *vpd
, uint32_t *vpd_size
)
4166 struct lpfc_dmabuf
*dmabuf
;
4167 struct lpfc_mqe
*mqe
;
4169 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4174 * Get a DMA buffer for the vpd data resulting from the READ_REV
4177 dma_size
= *vpd_size
;
4178 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4182 if (!dmabuf
->virt
) {
4186 memset(dmabuf
->virt
, 0, dma_size
);
4189 * The SLI4 implementation of READ_REV conflicts at word1,
4190 * bits 31:16 and SLI4 adds vpd functionality not present
4191 * in SLI3. This code corrects the conflicts.
4193 lpfc_read_rev(phba
, mboxq
);
4194 mqe
= &mboxq
->u
.mqe
;
4195 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4196 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4197 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4198 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4199 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4201 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4203 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4204 dmabuf
->virt
, dmabuf
->phys
);
4210 * The available vpd length cannot be bigger than the
4211 * DMA buffer passed to the port. Catch the less than
4212 * case and update the caller's size.
4214 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4215 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4217 lpfc_sli_pcimem_bcopy(dmabuf
->virt
, vpd
, *vpd_size
);
4218 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4219 dmabuf
->virt
, dmabuf
->phys
);
4225 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4226 * @phba: pointer to lpfc hba data structure.
4228 * This routine is called to explicitly arm the SLI4 device's completion and
4232 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4236 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4237 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4238 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4239 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4241 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4242 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4243 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4248 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4249 * @phba: Pointer to HBA context object.
4251 * This function is the main SLI4 device intialization PCI function. This
4252 * function is called by the HBA intialization code, HBA reset code and
4253 * HBA error attention handler code. Caller is not required to hold any
4257 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
4260 LPFC_MBOXQ_t
*mboxq
;
4261 struct lpfc_mqe
*mqe
;
4264 uint32_t ftr_rsp
= 0;
4265 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
4266 struct lpfc_vport
*vport
= phba
->pport
;
4267 struct lpfc_dmabuf
*mp
;
4269 /* Perform a PCI function reset to start from clean */
4270 rc
= lpfc_pci_function_reset(phba
);
4274 /* Check the HBA Host Status Register for readyness */
4275 rc
= lpfc_sli4_post_status_check(phba
);
4279 spin_lock_irq(&phba
->hbalock
);
4280 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
4281 spin_unlock_irq(&phba
->hbalock
);
4285 * Allocate a single mailbox container for initializing the
4288 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4293 * Continue initialization with default values even if driver failed
4294 * to read FCoE param config regions
4296 if (lpfc_sli4_read_fcoe_params(phba
, mboxq
))
4297 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4298 "2570 Failed to read FCoE parameters\n");
4300 /* Issue READ_REV to collect vpd and FW information. */
4301 vpd_size
= SLI4_PAGE_SIZE
;
4302 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
4308 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
4312 mqe
= &mboxq
->u
.mqe
;
4313 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
4314 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
4315 phba
->hba_flag
|= HBA_FCOE_SUPPORT
;
4317 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
4319 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
4321 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
4323 if (phba
->sli_rev
!= LPFC_SLI_REV4
||
4324 !(phba
->hba_flag
& HBA_FCOE_SUPPORT
)) {
4325 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4326 "0376 READ_REV Error. SLI Level %d "
4327 "FCoE enabled %d\n",
4328 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_SUPPORT
);
4333 * Evaluate the read rev and vpd data. Populate the driver
4334 * state with the results. If this routine fails, the failure
4335 * is not fatal as the driver will use generic values.
4337 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
4338 if (unlikely(!rc
)) {
4339 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4340 "0377 Error %d parsing vpd. "
4341 "Using defaults.\n", rc
);
4345 /* Save information as VPD data */
4346 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
4347 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
4348 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
4349 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
4351 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
4353 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
4355 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
4357 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4358 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
4359 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
4360 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
4361 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4362 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
4363 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4364 "(%d):0380 READ_REV Status x%x "
4365 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
4366 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4367 bf_get(lpfc_mqe_status
, mqe
),
4368 phba
->vpd
.rev
.opFwName
,
4369 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
4370 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
4373 * Discover the port's supported feature set and match it against the
4376 lpfc_request_features(phba
, mboxq
);
4377 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4384 * The port must support FCP initiator mode as this is the
4385 * only mode running in the host.
4387 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
4388 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4389 "0378 No support for fcpi mode.\n");
4394 * If the port cannot support the host's requested features
4395 * then turn off the global config parameters to disable the
4396 * feature in the driver. This is not a fatal error.
4398 if ((phba
->cfg_enable_bg
) &&
4399 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4402 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
4403 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4407 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4408 "0379 Feature Mismatch Data: x%08x %08x "
4409 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
4410 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
4411 phba
->cfg_enable_npiv
, phba
->max_vpi
);
4412 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4413 phba
->cfg_enable_bg
= 0;
4414 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4415 phba
->cfg_enable_npiv
= 0;
4418 /* These SLI3 features are assumed in SLI4 */
4419 spin_lock_irq(&phba
->hbalock
);
4420 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
4421 spin_unlock_irq(&phba
->hbalock
);
4423 /* Read the port's service parameters. */
4424 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
4426 phba
->link_state
= LPFC_HBA_ERROR
;
4431 mboxq
->vport
= vport
;
4432 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4433 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4434 if (rc
== MBX_SUCCESS
) {
4435 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
4440 * This memory was allocated by the lpfc_read_sparam routine. Release
4441 * it to the mbuf pool.
4443 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4445 mboxq
->context1
= NULL
;
4447 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4448 "0382 READ_SPARAM command failed "
4449 "status %d, mbxStatus x%x\n",
4450 rc
, bf_get(lpfc_mqe_status
, mqe
));
4451 phba
->link_state
= LPFC_HBA_ERROR
;
4456 if (phba
->cfg_soft_wwnn
)
4457 u64_to_wwn(phba
->cfg_soft_wwnn
,
4458 vport
->fc_sparam
.nodeName
.u
.wwn
);
4459 if (phba
->cfg_soft_wwpn
)
4460 u64_to_wwn(phba
->cfg_soft_wwpn
,
4461 vport
->fc_sparam
.portName
.u
.wwn
);
4462 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
4463 sizeof(struct lpfc_name
));
4464 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
4465 sizeof(struct lpfc_name
));
4467 /* Update the fc_host data structures with new wwn. */
4468 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
4469 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
4471 /* Register SGL pool to the device using non-embedded mailbox command */
4472 rc
= lpfc_sli4_post_sgl_list(phba
);
4474 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4475 "0582 Error %d during sgl post operation\n",
4481 /* Register SCSI SGL pool to the device */
4482 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
4484 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4485 "0383 Error %d during scsi sgl post "
4487 /* Some Scsi buffers were moved to the abort scsi list */
4488 /* A pci function reset will repost them */
4493 /* Post the rpi header region to the device. */
4494 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
4496 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4497 "0393 Error %d during rpi post operation\n",
4503 /* Set up all the queues to the device */
4504 rc
= lpfc_sli4_queue_setup(phba
);
4506 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4507 "0381 Error %d during queue setup.\n ", rc
);
4508 goto out_stop_timers
;
4511 /* Arm the CQs and then EQs on device */
4512 lpfc_sli4_arm_cqeq_intr(phba
);
4514 /* Indicate device interrupt mode */
4515 phba
->sli4_hba
.intr_enable
= 1;
4517 /* Allow asynchronous mailbox command to go through */
4518 spin_lock_irq(&phba
->hbalock
);
4519 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4520 spin_unlock_irq(&phba
->hbalock
);
4522 /* Post receive buffers to the device */
4523 lpfc_sli4_rb_setup(phba
);
4525 /* Reset HBA FCF states after HBA reset */
4526 phba
->fcf
.fcf_flag
= 0;
4527 phba
->fcf
.current_rec
.flag
= 0;
4529 /* Start the ELS watchdog timer */
4530 mod_timer(&vport
->els_tmofunc
,
4531 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
4533 /* Start heart beat timer */
4534 mod_timer(&phba
->hb_tmofunc
,
4535 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
4536 phba
->hb_outstanding
= 0;
4537 phba
->last_completion_time
= jiffies
;
4539 /* Start error attention (ERATT) polling timer */
4540 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
4543 * The port is ready, set the host's link state to LINK_DOWN
4544 * in preparation for link interrupts.
4546 lpfc_init_link(phba
, mboxq
, phba
->cfg_topology
, phba
->cfg_link_speed
);
4547 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4548 lpfc_set_loopback_flag(phba
);
4549 /* Change driver state to LPFC_LINK_DOWN right before init link */
4550 spin_lock_irq(&phba
->hbalock
);
4551 phba
->link_state
= LPFC_LINK_DOWN
;
4552 spin_unlock_irq(&phba
->hbalock
);
4553 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
4554 if (unlikely(rc
!= MBX_NOT_FINISHED
)) {
4560 /* Unset all the queues set up in this routine when error out */
4562 lpfc_sli4_queue_unset(phba
);
4566 lpfc_stop_hba_timers(phba
);
4570 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4575 * lpfc_mbox_timeout - Timeout call back function for mbox timer
4576 * @ptr: context object - pointer to hba structure.
4578 * This is the callback function for mailbox timer. The mailbox
4579 * timer is armed when a new mailbox command is issued and the timer
4580 * is deleted when the mailbox complete. The function is called by
4581 * the kernel timer code when a mailbox does not complete within
4582 * expected time. This function wakes up the worker thread to
4583 * process the mailbox timeout and returns. All the processing is
4584 * done by the worker thread function lpfc_mbox_timeout_handler.
4587 lpfc_mbox_timeout(unsigned long ptr
)
4589 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4590 unsigned long iflag
;
4591 uint32_t tmo_posted
;
4593 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
4594 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
4596 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
4597 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
4600 lpfc_worker_wake_up(phba
);
4606 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
4607 * @phba: Pointer to HBA context object.
4609 * This function is called from worker thread when a mailbox command times out.
4610 * The caller is not required to hold any locks. This function will reset the
4611 * HBA and recover all the pending commands.
4614 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
4616 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
4617 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
4618 struct lpfc_sli
*psli
= &phba
->sli
;
4619 struct lpfc_sli_ring
*pring
;
4621 /* Check the pmbox pointer first. There is a race condition
4622 * between the mbox timeout handler getting executed in the
4623 * worklist and the mailbox actually completing. When this
4624 * race condition occurs, the mbox_active will be NULL.
4626 spin_lock_irq(&phba
->hbalock
);
4627 if (pmbox
== NULL
) {
4628 lpfc_printf_log(phba
, KERN_WARNING
,
4630 "0353 Active Mailbox cleared - mailbox timeout "
4632 spin_unlock_irq(&phba
->hbalock
);
4636 /* Mbox cmd <mbxCommand> timeout */
4637 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4638 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
4640 phba
->pport
->port_state
,
4642 phba
->sli
.mbox_active
);
4643 spin_unlock_irq(&phba
->hbalock
);
4645 /* Setting state unknown so lpfc_sli_abort_iocb_ring
4646 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
4647 * it to fail all oustanding SCSI IO.
4649 spin_lock_irq(&phba
->pport
->work_port_lock
);
4650 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
4651 spin_unlock_irq(&phba
->pport
->work_port_lock
);
4652 spin_lock_irq(&phba
->hbalock
);
4653 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4654 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
4655 spin_unlock_irq(&phba
->hbalock
);
4657 pring
= &psli
->ring
[psli
->fcp_ring
];
4658 lpfc_sli_abort_iocb_ring(phba
, pring
);
4660 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4661 "0345 Resetting board due to mailbox timeout\n");
4663 /* Reset the HBA device */
4664 lpfc_reset_hba(phba
);
4668 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
4669 * @phba: Pointer to HBA context object.
4670 * @pmbox: Pointer to mailbox object.
4671 * @flag: Flag indicating how the mailbox need to be processed.
4673 * This function is called by discovery code and HBA management code
4674 * to submit a mailbox command to firmware with SLI-3 interface spec. This
4675 * function gets the hbalock to protect the data structures.
4676 * The mailbox command can be submitted in polling mode, in which case
4677 * this function will wait in a polling loop for the completion of the
4679 * If the mailbox is submitted in no_wait mode (not polling) the
4680 * function will submit the command and returns immediately without waiting
4681 * for the mailbox completion. The no_wait is supported only when HBA
4682 * is in SLI2/SLI3 mode - interrupts are enabled.
4683 * The SLI interface allows only one mailbox pending at a time. If the
4684 * mailbox is issued in polling mode and there is already a mailbox
4685 * pending, then the function will return an error. If the mailbox is issued
4686 * in NO_WAIT mode and there is a mailbox pending already, the function
4687 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
4688 * The sli layer owns the mailbox object until the completion of mailbox
4689 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
4690 * return codes the caller owns the mailbox command after the return of
4694 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
4698 struct lpfc_sli
*psli
= &phba
->sli
;
4699 uint32_t status
, evtctr
;
4702 unsigned long timeout
;
4703 unsigned long drvr_flag
= 0;
4704 uint32_t word0
, ldata
;
4705 void __iomem
*to_slim
;
4706 int processing_queue
= 0;
4708 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
4710 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4711 /* processing mbox queue from intr_handler */
4712 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
4713 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4716 processing_queue
= 1;
4717 pmbox
= lpfc_mbox_get(phba
);
4719 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4724 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
4725 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
4727 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4728 lpfc_printf_log(phba
, KERN_ERR
,
4729 LOG_MBOX
| LOG_VPORT
,
4730 "1806 Mbox x%x failed. No vport\n",
4731 pmbox
->u
.mb
.mbxCommand
);
4733 goto out_not_finished
;
4737 /* If the PCI channel is in offline state, do not post mbox. */
4738 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
4739 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4740 goto out_not_finished
;
4743 /* If HBA has a deferred error attention, fail the iocb. */
4744 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
4745 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4746 goto out_not_finished
;
4752 status
= MBX_SUCCESS
;
4754 if (phba
->link_state
== LPFC_HBA_ERROR
) {
4755 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4757 /* Mbox command <mbxCommand> cannot issue */
4758 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4759 "(%d):0311 Mailbox command x%x cannot "
4760 "issue Data: x%x x%x\n",
4761 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4762 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
4763 goto out_not_finished
;
4766 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
4767 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
4768 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4769 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4770 "(%d):2528 Mailbox command x%x cannot "
4771 "issue Data: x%x x%x\n",
4772 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4773 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
4774 goto out_not_finished
;
4777 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
4778 /* Polling for a mbox command when another one is already active
4779 * is not allowed in SLI. Also, the driver must have established
4780 * SLI2 mode to queue and process multiple mbox commands.
4783 if (flag
& MBX_POLL
) {
4784 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4786 /* Mbox command <mbxCommand> cannot issue */
4787 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4788 "(%d):2529 Mailbox command x%x "
4789 "cannot issue Data: x%x x%x\n",
4790 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4791 pmbox
->u
.mb
.mbxCommand
,
4792 psli
->sli_flag
, flag
);
4793 goto out_not_finished
;
4796 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
4797 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4798 /* Mbox command <mbxCommand> cannot issue */
4799 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4800 "(%d):2530 Mailbox command x%x "
4801 "cannot issue Data: x%x x%x\n",
4802 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4803 pmbox
->u
.mb
.mbxCommand
,
4804 psli
->sli_flag
, flag
);
4805 goto out_not_finished
;
4808 /* Another mailbox command is still being processed, queue this
4809 * command to be processed later.
4811 lpfc_mbox_put(phba
, pmbox
);
4813 /* Mbox cmd issue - BUSY */
4814 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4815 "(%d):0308 Mbox cmd issue - BUSY Data: "
4816 "x%x x%x x%x x%x\n",
4817 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
4818 mb
->mbxCommand
, phba
->pport
->port_state
,
4819 psli
->sli_flag
, flag
);
4821 psli
->slistat
.mbox_busy
++;
4822 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4825 lpfc_debugfs_disc_trc(pmbox
->vport
,
4826 LPFC_DISC_TRC_MBOX_VPORT
,
4827 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
4828 (uint32_t)mb
->mbxCommand
,
4829 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4832 lpfc_debugfs_disc_trc(phba
->pport
,
4834 "MBOX Bsy: cmd:x%x mb:x%x x%x",
4835 (uint32_t)mb
->mbxCommand
,
4836 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4842 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4844 /* If we are not polling, we MUST be in SLI2 mode */
4845 if (flag
!= MBX_POLL
) {
4846 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
4847 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
4848 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4849 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
4850 /* Mbox command <mbxCommand> cannot issue */
4851 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4852 "(%d):2531 Mailbox command x%x "
4853 "cannot issue Data: x%x x%x\n",
4854 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4855 pmbox
->u
.mb
.mbxCommand
,
4856 psli
->sli_flag
, flag
);
4857 goto out_not_finished
;
4859 /* timeout active mbox command */
4860 mod_timer(&psli
->mbox_tmo
, (jiffies
+
4861 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
4864 /* Mailbox cmd <cmd> issue */
4865 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4866 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
4868 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
4869 mb
->mbxCommand
, phba
->pport
->port_state
,
4870 psli
->sli_flag
, flag
);
4872 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
4874 lpfc_debugfs_disc_trc(pmbox
->vport
,
4875 LPFC_DISC_TRC_MBOX_VPORT
,
4876 "MBOX Send vport: cmd:x%x mb:x%x x%x",
4877 (uint32_t)mb
->mbxCommand
,
4878 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4881 lpfc_debugfs_disc_trc(phba
->pport
,
4883 "MBOX Send: cmd:x%x mb:x%x x%x",
4884 (uint32_t)mb
->mbxCommand
,
4885 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
4889 psli
->slistat
.mbox_cmd
++;
4890 evtctr
= psli
->slistat
.mbox_event
;
4892 /* next set own bit for the adapter and copy over command word */
4893 mb
->mbxOwner
= OWN_CHIP
;
4895 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4896 /* Populate mbox extension offset word. */
4897 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
4898 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
4899 = (uint8_t *)phba
->mbox_ext
4900 - (uint8_t *)phba
->mbox
;
4903 /* Copy the mailbox extension data */
4904 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
4905 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
4906 (uint8_t *)phba
->mbox_ext
,
4907 pmbox
->in_ext_byte_len
);
4909 /* Copy command data to host SLIM area */
4910 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
4912 /* Populate mbox extension offset word. */
4913 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
4914 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
4915 = MAILBOX_HBA_EXT_OFFSET
;
4917 /* Copy the mailbox extension data */
4918 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
4919 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
4920 MAILBOX_HBA_EXT_OFFSET
,
4921 pmbox
->context2
, pmbox
->in_ext_byte_len
);
4924 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4925 /* copy command data into host mbox for cmpl */
4926 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
4929 /* First copy mbox command data to HBA SLIM, skip past first
4931 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4932 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
4933 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
4935 /* Next copy over first word, with mbxOwner set */
4936 ldata
= *((uint32_t *)mb
);
4937 to_slim
= phba
->MBslimaddr
;
4938 writel(ldata
, to_slim
);
4939 readl(to_slim
); /* flush */
4941 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
4942 /* switch over to host mailbox */
4943 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
4951 /* Set up reference to mailbox command */
4952 psli
->mbox_active
= pmbox
;
4953 /* Interrupt board to do it */
4954 writel(CA_MBATT
, phba
->CAregaddr
);
4955 readl(phba
->CAregaddr
); /* flush */
4956 /* Don't wait for it to finish, just return */
4960 /* Set up null reference to mailbox command */
4961 psli
->mbox_active
= NULL
;
4962 /* Interrupt board to do it */
4963 writel(CA_MBATT
, phba
->CAregaddr
);
4964 readl(phba
->CAregaddr
); /* flush */
4966 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
4967 /* First read mbox status word */
4968 word0
= *((uint32_t *)phba
->mbox
);
4969 word0
= le32_to_cpu(word0
);
4971 /* First read mbox status word */
4972 word0
= readl(phba
->MBslimaddr
);
4975 /* Read the HBA Host Attention Register */
4976 ha_copy
= readl(phba
->HAregaddr
);
4977 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
4981 /* Wait for command to complete */
4982 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
4983 (!(ha_copy
& HA_MBATT
) &&
4984 (phba
->link_state
> LPFC_WARM_START
))) {
4985 if (time_after(jiffies
, timeout
)) {
4986 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4987 spin_unlock_irqrestore(&phba
->hbalock
,
4989 goto out_not_finished
;
4992 /* Check if we took a mbox interrupt while we were
4994 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
4995 && (evtctr
!= psli
->slistat
.mbox_event
))
4999 spin_unlock_irqrestore(&phba
->hbalock
,
5002 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
5005 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5006 /* First copy command data */
5007 word0
= *((uint32_t *)phba
->mbox
);
5008 word0
= le32_to_cpu(word0
);
5009 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
5012 /* Check real SLIM for any errors */
5013 slimword0
= readl(phba
->MBslimaddr
);
5014 slimmb
= (MAILBOX_t
*) & slimword0
;
5015 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
5016 && slimmb
->mbxStatus
) {
5023 /* First copy command data */
5024 word0
= readl(phba
->MBslimaddr
);
5026 /* Read the HBA Host Attention Register */
5027 ha_copy
= readl(phba
->HAregaddr
);
5030 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5031 /* copy results back to user */
5032 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
5033 /* Copy the mailbox extension data */
5034 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
5035 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
5037 pmbox
->out_ext_byte_len
);
5040 /* First copy command data */
5041 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
5043 /* Copy the mailbox extension data */
5044 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
5045 lpfc_memcpy_from_slim(pmbox
->context2
,
5047 MAILBOX_HBA_EXT_OFFSET
,
5048 pmbox
->out_ext_byte_len
);
5052 writel(HA_MBATT
, phba
->HAregaddr
);
5053 readl(phba
->HAregaddr
); /* flush */
5055 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5056 status
= mb
->mbxStatus
;
5059 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5063 if (processing_queue
) {
5064 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5065 lpfc_mbox_cmpl_put(phba
, pmbox
);
5067 return MBX_NOT_FINISHED
;
5071 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
5072 * @phba: Pointer to HBA context object.
5074 * The function blocks the posting of SLI4 asynchronous mailbox commands from
5075 * the driver internal pending mailbox queue. It will then try to wait out the
5076 * possible outstanding mailbox command before return.
5079 * 0 - the outstanding mailbox command completed; otherwise, the wait for
5080 * the outstanding mailbox command timed out.
5083 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
5085 struct lpfc_sli
*psli
= &phba
->sli
;
5086 uint8_t actcmd
= MBX_HEARTBEAT
;
5088 unsigned long timeout
;
5090 /* Mark the asynchronous mailbox command posting as blocked */
5091 spin_lock_irq(&phba
->hbalock
);
5092 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
5093 if (phba
->sli
.mbox_active
)
5094 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
5095 spin_unlock_irq(&phba
->hbalock
);
5096 /* Determine how long we might wait for the active mailbox
5097 * command to be gracefully completed by firmware.
5099 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) * 1000) +
5101 /* Wait for the outstnading mailbox command to complete */
5102 while (phba
->sli
.mbox_active
) {
5103 /* Check active mailbox complete status every 2ms */
5105 if (time_after(jiffies
, timeout
)) {
5106 /* Timeout, marked the outstanding cmd not complete */
5112 /* Can not cleanly block async mailbox command, fails it */
5114 spin_lock_irq(&phba
->hbalock
);
5115 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5116 spin_unlock_irq(&phba
->hbalock
);
5122 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
5123 * @phba: Pointer to HBA context object.
5125 * The function unblocks and resume posting of SLI4 asynchronous mailbox
5126 * commands from the driver internal pending mailbox queue. It makes sure
5127 * that there is no outstanding mailbox command before resuming posting
5128 * asynchronous mailbox commands. If, for any reason, there is outstanding
5129 * mailbox command, it will try to wait it out before resuming asynchronous
5130 * mailbox command posting.
5133 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
5135 struct lpfc_sli
*psli
= &phba
->sli
;
5137 spin_lock_irq(&phba
->hbalock
);
5138 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5139 /* Asynchronous mailbox posting is not blocked, do nothing */
5140 spin_unlock_irq(&phba
->hbalock
);
5144 /* Outstanding synchronous mailbox command is guaranteed to be done,
5145 * successful or timeout, after timing-out the outstanding mailbox
5146 * command shall always be removed, so just unblock posting async
5147 * mailbox command and resume
5149 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5150 spin_unlock_irq(&phba
->hbalock
);
5152 /* wake up worker thread to post asynchronlous mailbox command */
5153 lpfc_worker_wake_up(phba
);
5157 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5158 * @phba: Pointer to HBA context object.
5159 * @mboxq: Pointer to mailbox object.
5161 * The function posts a mailbox to the port. The mailbox is expected
5162 * to be comletely filled in and ready for the port to operate on it.
5163 * This routine executes a synchronous completion operation on the
5164 * mailbox by polling for its completion.
5166 * The caller must not be holding any locks when calling this routine.
5169 * MBX_SUCCESS - mailbox posted successfully
5170 * Any of the MBX error values.
5173 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
5175 int rc
= MBX_SUCCESS
;
5176 unsigned long iflag
;
5178 uint32_t mcqe_status
;
5180 unsigned long timeout
;
5181 struct lpfc_sli
*psli
= &phba
->sli
;
5182 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
5183 struct lpfc_bmbx_create
*mbox_rgn
;
5184 struct dma_address
*dma_address
;
5185 struct lpfc_register bmbx_reg
;
5188 * Only one mailbox can be active to the bootstrap mailbox region
5189 * at a time and there is no queueing provided.
5191 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5192 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5193 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5194 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5195 "(%d):2532 Mailbox command x%x (x%x) "
5196 "cannot issue Data: x%x x%x\n",
5197 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5198 mboxq
->u
.mb
.mbxCommand
,
5199 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5200 psli
->sli_flag
, MBX_POLL
);
5201 return MBXERR_ERROR
;
5203 /* The server grabs the token and owns it until release */
5204 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5205 phba
->sli
.mbox_active
= mboxq
;
5206 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5209 * Initialize the bootstrap memory region to avoid stale data areas
5210 * in the mailbox post. Then copy the caller's mailbox contents to
5211 * the bmbx mailbox region.
5213 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
5214 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
5215 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
5216 sizeof(struct lpfc_mqe
));
5218 /* Post the high mailbox dma address to the port and wait for ready. */
5219 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
5220 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
5222 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5225 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5226 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5230 if (time_after(jiffies
, timeout
)) {
5234 } while (!db_ready
);
5236 /* Post the low mailbox dma address to the port. */
5237 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
5238 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5241 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5242 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5246 if (time_after(jiffies
, timeout
)) {
5250 } while (!db_ready
);
5253 * Read the CQ to ensure the mailbox has completed.
5254 * If so, update the mailbox status so that the upper layers
5255 * can complete the request normally.
5257 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
5258 sizeof(struct lpfc_mqe
));
5259 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
5260 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
5261 sizeof(struct lpfc_mcqe
));
5262 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
5264 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5265 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
5266 bf_set(lpfc_mqe_status
, mb
, LPFC_MBX_ERROR_RANGE
| mcqe_status
);
5270 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5271 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5272 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5273 " x%x x%x CQ: x%x x%x x%x x%x\n",
5274 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5275 mbx_cmnd
, lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5276 bf_get(lpfc_mqe_status
, mb
),
5277 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
5278 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
5279 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
5280 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
5281 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
5282 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
5283 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
5284 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5285 mboxq
->mcqe
.trailer
);
5287 /* We are holding the token, no needed for lock when release */
5288 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5289 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5290 phba
->sli
.mbox_active
= NULL
;
5291 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5296 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5297 * @phba: Pointer to HBA context object.
5298 * @pmbox: Pointer to mailbox object.
5299 * @flag: Flag indicating how the mailbox need to be processed.
5301 * This function is called by discovery code and HBA management code to submit
5302 * a mailbox command to firmware with SLI-4 interface spec.
5304 * Return codes the caller owns the mailbox command after the return of the
5308 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5311 struct lpfc_sli
*psli
= &phba
->sli
;
5312 unsigned long iflags
;
5315 rc
= lpfc_mbox_dev_check(phba
);
5317 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5318 "(%d):2544 Mailbox command x%x (x%x) "
5319 "cannot issue Data: x%x x%x\n",
5320 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5321 mboxq
->u
.mb
.mbxCommand
,
5322 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5323 psli
->sli_flag
, flag
);
5324 goto out_not_finished
;
5327 /* Detect polling mode and jump to a handler */
5328 if (!phba
->sli4_hba
.intr_enable
) {
5329 if (flag
== MBX_POLL
)
5330 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5333 if (rc
!= MBX_SUCCESS
)
5334 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5335 "(%d):2541 Mailbox command x%x "
5336 "(x%x) cannot issue Data: x%x x%x\n",
5337 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5338 mboxq
->u
.mb
.mbxCommand
,
5339 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5340 psli
->sli_flag
, flag
);
5342 } else if (flag
== MBX_POLL
) {
5343 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
5344 "(%d):2542 Try to issue mailbox command "
5345 "x%x (x%x) synchronously ahead of async"
5346 "mailbox command queue: x%x x%x\n",
5347 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5348 mboxq
->u
.mb
.mbxCommand
,
5349 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5350 psli
->sli_flag
, flag
);
5351 /* Try to block the asynchronous mailbox posting */
5352 rc
= lpfc_sli4_async_mbox_block(phba
);
5354 /* Successfully blocked, now issue sync mbox cmd */
5355 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5356 if (rc
!= MBX_SUCCESS
)
5357 lpfc_printf_log(phba
, KERN_ERR
,
5359 "(%d):2597 Mailbox command "
5360 "x%x (x%x) cannot issue "
5363 mboxq
->vport
->vpi
: 0,
5364 mboxq
->u
.mb
.mbxCommand
,
5365 lpfc_sli4_mbox_opcode_get(phba
,
5367 psli
->sli_flag
, flag
);
5368 /* Unblock the async mailbox posting afterward */
5369 lpfc_sli4_async_mbox_unblock(phba
);
5374 /* Now, interrupt mode asynchrous mailbox command */
5375 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
5377 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5378 "(%d):2543 Mailbox command x%x (x%x) "
5379 "cannot issue Data: x%x x%x\n",
5380 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5381 mboxq
->u
.mb
.mbxCommand
,
5382 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5383 psli
->sli_flag
, flag
);
5384 goto out_not_finished
;
5387 /* Put the mailbox command to the driver internal FIFO */
5388 psli
->slistat
.mbox_busy
++;
5389 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5390 lpfc_mbox_put(phba
, mboxq
);
5391 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5392 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5393 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5394 "x%x (x%x) x%x x%x x%x\n",
5395 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
5396 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5397 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5398 phba
->pport
->port_state
,
5399 psli
->sli_flag
, MBX_NOWAIT
);
5400 /* Wake up worker thread to transport mailbox command from head */
5401 lpfc_worker_wake_up(phba
);
5406 return MBX_NOT_FINISHED
;
5410 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5411 * @phba: Pointer to HBA context object.
5413 * This function is called by worker thread to send a mailbox command to
5414 * SLI4 HBA firmware.
5418 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
5420 struct lpfc_sli
*psli
= &phba
->sli
;
5421 LPFC_MBOXQ_t
*mboxq
;
5422 int rc
= MBX_SUCCESS
;
5423 unsigned long iflags
;
5424 struct lpfc_mqe
*mqe
;
5427 /* Check interrupt mode before post async mailbox command */
5428 if (unlikely(!phba
->sli4_hba
.intr_enable
))
5429 return MBX_NOT_FINISHED
;
5431 /* Check for mailbox command service token */
5432 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5433 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5434 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5435 return MBX_NOT_FINISHED
;
5437 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5438 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5439 return MBX_NOT_FINISHED
;
5441 if (unlikely(phba
->sli
.mbox_active
)) {
5442 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5443 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5444 "0384 There is pending active mailbox cmd\n");
5445 return MBX_NOT_FINISHED
;
5447 /* Take the mailbox command service token */
5448 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5450 /* Get the next mailbox command from head of queue */
5451 mboxq
= lpfc_mbox_get(phba
);
5453 /* If no more mailbox command waiting for post, we're done */
5455 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5456 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5459 phba
->sli
.mbox_active
= mboxq
;
5460 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5462 /* Check device readiness for posting mailbox command */
5463 rc
= lpfc_mbox_dev_check(phba
);
5465 /* Driver clean routine will clean up pending mailbox */
5466 goto out_not_finished
;
5468 /* Prepare the mbox command to be posted */
5469 mqe
= &mboxq
->u
.mqe
;
5470 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
5472 /* Start timer for the mbox_tmo and log some mailbox post messages */
5473 mod_timer(&psli
->mbox_tmo
, (jiffies
+
5474 (HZ
* lpfc_mbox_tmo_val(phba
, mbx_cmnd
))));
5476 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5477 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5479 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
5480 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5481 phba
->pport
->port_state
, psli
->sli_flag
);
5483 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
5485 lpfc_debugfs_disc_trc(mboxq
->vport
,
5486 LPFC_DISC_TRC_MBOX_VPORT
,
5487 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5488 mbx_cmnd
, mqe
->un
.mb_words
[0],
5489 mqe
->un
.mb_words
[1]);
5491 lpfc_debugfs_disc_trc(phba
->pport
,
5493 "MBOX Send: cmd:x%x mb:x%x x%x",
5494 mbx_cmnd
, mqe
->un
.mb_words
[0],
5495 mqe
->un
.mb_words
[1]);
5498 psli
->slistat
.mbox_cmd
++;
5500 /* Post the mailbox command to the port */
5501 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
5502 if (rc
!= MBX_SUCCESS
) {
5503 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5504 "(%d):2533 Mailbox command x%x (x%x) "
5505 "cannot issue Data: x%x x%x\n",
5506 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5507 mboxq
->u
.mb
.mbxCommand
,
5508 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5509 psli
->sli_flag
, MBX_NOWAIT
);
5510 goto out_not_finished
;
5516 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5517 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5518 __lpfc_mbox_cmpl_put(phba
, mboxq
);
5519 /* Release the token */
5520 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5521 phba
->sli
.mbox_active
= NULL
;
5522 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5524 return MBX_NOT_FINISHED
;
5528 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5529 * @phba: Pointer to HBA context object.
5530 * @pmbox: Pointer to mailbox object.
5531 * @flag: Flag indicating how the mailbox need to be processed.
5533 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5534 * the API jump table function pointer from the lpfc_hba struct.
5536 * Return codes the caller owns the mailbox command after the return of the
5540 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
5542 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
5546 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5547 * @phba: The hba struct for which this call is being executed.
5548 * @dev_grp: The HBA PCI-Device group number.
5550 * This routine sets up the mbox interface API function jump table in @phba
5552 * Returns: 0 - success, -ENODEV - failure.
5555 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5559 case LPFC_PCI_DEV_LP
:
5560 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
5561 phba
->lpfc_sli_handle_slow_ring_event
=
5562 lpfc_sli_handle_slow_ring_event_s3
;
5563 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
5564 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
5565 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
5567 case LPFC_PCI_DEV_OC
:
5568 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
5569 phba
->lpfc_sli_handle_slow_ring_event
=
5570 lpfc_sli_handle_slow_ring_event_s4
;
5571 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
5572 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
5573 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
5576 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5577 "1420 Invalid HBA PCI-device group: 0x%x\n",
5586 * __lpfc_sli_ringtx_put - Add an iocb to the txq
5587 * @phba: Pointer to HBA context object.
5588 * @pring: Pointer to driver SLI ring object.
5589 * @piocb: Pointer to address of newly added command iocb.
5591 * This function is called with hbalock held to add a command
5592 * iocb to the txq when SLI layer cannot submit the command iocb
5596 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5597 struct lpfc_iocbq
*piocb
)
5599 /* Insert the caller's iocb in the txq tail for later processing. */
5600 list_add_tail(&piocb
->list
, &pring
->txq
);
5605 * lpfc_sli_next_iocb - Get the next iocb in the txq
5606 * @phba: Pointer to HBA context object.
5607 * @pring: Pointer to driver SLI ring object.
5608 * @piocb: Pointer to address of newly added command iocb.
5610 * This function is called with hbalock held before a new
5611 * iocb is submitted to the firmware. This function checks
5612 * txq to flush the iocbs in txq to Firmware before
5613 * submitting new iocbs to the Firmware.
5614 * If there are iocbs in the txq which need to be submitted
5615 * to firmware, lpfc_sli_next_iocb returns the first element
5616 * of the txq after dequeuing it from txq.
5617 * If there is no iocb in the txq then the function will return
5618 * *piocb and *piocb is set to NULL. Caller needs to check
5619 * *piocb to find if there are more commands in the txq.
5621 static struct lpfc_iocbq
*
5622 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5623 struct lpfc_iocbq
**piocb
)
5625 struct lpfc_iocbq
* nextiocb
;
5627 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
5637 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
5638 * @phba: Pointer to HBA context object.
5639 * @ring_number: SLI ring number to issue iocb on.
5640 * @piocb: Pointer to command iocb.
5641 * @flag: Flag indicating if this command can be put into txq.
5643 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
5644 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
5645 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
5646 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
5647 * this function allows only iocbs for posting buffers. This function finds
5648 * next available slot in the command ring and posts the command to the
5649 * available slot and writes the port attention register to request HBA start
5650 * processing new iocb. If there is no slot available in the ring and
5651 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
5652 * the function returns IOCB_BUSY.
5654 * This function is called with hbalock held. The function will return success
5655 * after it successfully submit the iocb to firmware or after adding to the
5659 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
5660 struct lpfc_iocbq
*piocb
, uint32_t flag
)
5662 struct lpfc_iocbq
*nextiocb
;
5664 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
5666 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
5667 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
5668 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
5669 lpfc_printf_log(phba
, KERN_ERR
,
5670 LOG_SLI
| LOG_VPORT
,
5671 "1807 IOCB x%x failed. No vport\n",
5672 piocb
->iocb
.ulpCommand
);
5678 /* If the PCI channel is in offline state, do not post iocbs. */
5679 if (unlikely(pci_channel_offline(phba
->pcidev
)))
5682 /* If HBA has a deferred error attention, fail the iocb. */
5683 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
5687 * We should never get an IOCB if we are in a < LINK_DOWN state
5689 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
5693 * Check to see if we are blocking IOCB processing because of a
5694 * outstanding event.
5696 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
5699 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
5701 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
5702 * can be issued if the link is not up.
5704 switch (piocb
->iocb
.ulpCommand
) {
5705 case CMD_GEN_REQUEST64_CR
:
5706 case CMD_GEN_REQUEST64_CX
:
5707 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
5708 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
5709 FC_RCTL_DD_UNSOL_CMD
) ||
5710 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
5711 MENLO_TRANSPORT_TYPE
))
5715 case CMD_QUE_RING_BUF_CN
:
5716 case CMD_QUE_RING_BUF64_CN
:
5718 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
5719 * completion, iocb_cmpl MUST be 0.
5721 if (piocb
->iocb_cmpl
)
5722 piocb
->iocb_cmpl
= NULL
;
5724 case CMD_CREATE_XRI_CR
:
5725 case CMD_CLOSE_XRI_CN
:
5726 case CMD_CLOSE_XRI_CX
:
5733 * For FCP commands, we must be in a state where we can process link
5736 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
5737 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
5741 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
5742 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
5743 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
5746 lpfc_sli_update_ring(phba
, pring
);
5748 lpfc_sli_update_full_ring(phba
, pring
);
5751 return IOCB_SUCCESS
;
5756 pring
->stats
.iocb_cmd_delay
++;
5760 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
5761 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
5762 return IOCB_SUCCESS
;
5769 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
5770 * @phba: Pointer to HBA context object.
5771 * @piocb: Pointer to command iocb.
5772 * @sglq: Pointer to the scatter gather queue object.
5774 * This routine converts the bpl or bde that is in the IOCB
5775 * to a sgl list for the sli4 hardware. The physical address
5776 * of the bpl/bde is converted back to a virtual address.
5777 * If the IOCB contains a BPL then the list of BDE's is
5778 * converted to sli4_sge's. If the IOCB contains a single
5779 * BDE then it is converted to a single sli_sge.
5780 * The IOCB is still in cpu endianess so the contents of
5781 * the bpl can be used without byte swapping.
5783 * Returns valid XRI = Success, NO_XRI = Failure.
5786 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
5787 struct lpfc_sglq
*sglq
)
5789 uint16_t xritag
= NO_XRI
;
5790 struct ulp_bde64
*bpl
= NULL
;
5791 struct ulp_bde64 bde
;
5792 struct sli4_sge
*sgl
= NULL
;
5797 if (!piocbq
|| !sglq
)
5800 sgl
= (struct sli4_sge
*)sglq
->sgl
;
5801 icmd
= &piocbq
->iocb
;
5802 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
5803 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
5804 sizeof(struct ulp_bde64
);
5805 /* The addrHigh and addrLow fields within the IOCB
5806 * have not been byteswapped yet so there is no
5807 * need to swap them back.
5809 bpl
= (struct ulp_bde64
*)
5810 ((struct lpfc_dmabuf
*)piocbq
->context3
)->virt
;
5815 for (i
= 0; i
< numBdes
; i
++) {
5816 /* Should already be byte swapped. */
5817 sgl
->addr_hi
= bpl
->addrHigh
;
5818 sgl
->addr_lo
= bpl
->addrLow
;
5820 if ((i
+1) == numBdes
)
5821 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
5823 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
5824 sgl
->word2
= cpu_to_le32(sgl
->word2
);
5825 /* swap the size field back to the cpu so we
5826 * can assign it to the sgl.
5828 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5829 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
5833 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
5834 /* The addrHigh and addrLow fields of the BDE have not
5835 * been byteswapped yet so they need to be swapped
5836 * before putting them in the sgl.
5839 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
5841 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
5842 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
5843 sgl
->word2
= cpu_to_le32(sgl
->word2
);
5845 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
5847 return sglq
->sli4_xritag
;
5851 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5852 * @phba: Pointer to HBA context object.
5854 * This routine performs a round robin SCSI command to SLI4 FCP WQ index
5855 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
5858 * Return: index into SLI4 fast-path FCP queue index.
5861 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
5864 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
5867 return phba
->fcp_qidx
;
5871 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
5872 * @phba: Pointer to HBA context object.
5873 * @piocb: Pointer to command iocb.
5874 * @wqe: Pointer to the work queue entry.
5876 * This routine converts the iocb command to its Work Queue Entry
5877 * equivalent. The wqe pointer should not have any fields set when
5878 * this routine is called because it will memcpy over them.
5879 * This routine does not set the CQ_ID or the WQEC bits in the
5882 * Returns: 0 = Success, IOCB_ERROR = Failure.
5885 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
5886 union lpfc_wqe
*wqe
)
5888 uint32_t xmit_len
= 0, total_len
= 0;
5892 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
5895 struct ulp_bde64
*bpl
= NULL
;
5896 uint32_t els_id
= ELS_ID_DEFAULT
;
5898 struct ulp_bde64 bde
;
5900 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
5901 /* The fcp commands will set command type */
5902 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
5903 command_type
= FCP_COMMAND
;
5904 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
5905 command_type
= ELS_COMMAND_FIP
;
5907 command_type
= ELS_COMMAND_NON_FIP
;
5909 /* Some of the fields are in the right position already */
5910 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
5911 abort_tag
= (uint32_t) iocbq
->iotag
;
5912 xritag
= iocbq
->sli4_xritag
;
5913 wqe
->words
[7] = 0; /* The ct field has moved so reset */
5914 /* words0-2 bpl convert bde */
5915 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
5916 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
5917 sizeof(struct ulp_bde64
);
5918 bpl
= (struct ulp_bde64
*)
5919 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
5923 /* Should already be byte swapped. */
5924 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
5925 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
5926 /* swap the size field back to the cpu so we
5927 * can assign it to the sgl.
5929 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5930 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
5932 for (i
= 0; i
< numBdes
; i
++) {
5933 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
5934 total_len
+= bde
.tus
.f
.bdeSize
;
5937 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
5939 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
5940 cmnd
= iocbq
->iocb
.ulpCommand
;
5942 switch (iocbq
->iocb
.ulpCommand
) {
5943 case CMD_ELS_REQUEST64_CR
:
5944 if (!iocbq
->iocb
.ulpLe
) {
5945 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5946 "2007 Only Limited Edition cmd Format"
5947 " supported 0x%x\n",
5948 iocbq
->iocb
.ulpCommand
);
5951 wqe
->els_req
.payload_len
= xmit_len
;
5952 /* Els_reguest64 has a TMO */
5953 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
5954 iocbq
->iocb
.ulpTimeout
);
5955 /* Need a VF for word 4 set the vf bit*/
5956 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
5957 /* And a VFID for word 12 */
5958 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
5960 * Set ct field to 3, indicates that the context_tag field
5961 * contains the FCFI and remote N_Port_ID is
5965 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
5966 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
5967 iocbq
->iocb
.ulpContext
);
5969 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
, ct
);
5970 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5971 /* CCP CCPE PV PRI in word10 were set in the memcpy */
5973 if (command_type
== ELS_COMMAND_FIP
) {
5974 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
5975 >> LPFC_FIP_ELS_ID_SHIFT
);
5977 bf_set(lpfc_wqe_gen_els_id
, &wqe
->generic
, els_id
);
5980 case CMD_XMIT_SEQUENCE64_CX
:
5981 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
5982 iocbq
->iocb
.un
.ulpWord
[3]);
5983 wqe
->generic
.word3
= 0;
5984 bf_set(wqe_rcvoxid
, &wqe
->generic
, iocbq
->iocb
.ulpContext
);
5985 /* The entire sequence is transmitted for this IOCB */
5986 xmit_len
= total_len
;
5987 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
5988 case CMD_XMIT_SEQUENCE64_CR
:
5989 /* word3 iocb=io_tag32 wqe=payload_offset */
5990 /* payload offset used for multilpe outstanding
5991 * sequences on the same exchange
5994 /* word4 relative_offset memcpy */
5995 /* word5 r_ctl/df_ctl memcpy */
5996 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
5997 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
5998 command_type
= OTHER_COMMAND
;
6000 case CMD_XMIT_BCAST64_CN
:
6001 /* word3 iocb=iotag32 wqe=payload_len */
6002 wqe
->words
[3] = 0; /* no definition for this in wqe */
6003 /* word4 iocb=rsvd wqe=rsvd */
6004 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
6005 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
6006 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6007 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6009 case CMD_FCP_IWRITE64_CR
:
6010 command_type
= FCP_COMMAND_DATA_OUT
;
6011 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
6013 * word3 is payload_len: byte offset to the sgl entry for the
6015 * word4 is total xfer len, same as the IOCB->ulpParameter.
6016 * word5 is initial xfer len 0 = wait for xfer-ready
6019 /* Always wait for xfer-ready before sending data */
6020 wqe
->fcp_iwrite
.initial_xfer_len
= 0;
6021 /* word 4 (xfer length) should have been set on the memcpy */
6023 /* allow write to fall through to read */
6024 case CMD_FCP_IREAD64_CR
:
6025 /* FCP_CMD is always the 1st sgl entry */
6026 wqe
->fcp_iread
.payload_len
=
6027 xmit_len
+ sizeof(struct fcp_rsp
);
6029 /* word 4 (xfer length) should have been set on the memcpy */
6031 bf_set(lpfc_wqe_gen_erp
, &wqe
->generic
,
6032 iocbq
->iocb
.ulpFCP2Rcvy
);
6033 bf_set(lpfc_wqe_gen_lnk
, &wqe
->generic
, iocbq
->iocb
.ulpXS
);
6034 /* The XC bit and the XS bit are similar. The driver never
6035 * tracked whether or not the exchange was previouslly open.
6036 * XC = Exchange create, 0 is create. 1 is already open.
6037 * XS = link cmd: 1 do not close the exchange after command.
6038 * XS = 0 close exchange when command completes.
6039 * The only time we would not set the XC bit is when the XS bit
6040 * is set and we are sending our 2nd or greater command on
6043 /* Always open the exchange */
6044 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
6046 wqe
->words
[10] &= 0xffff0000; /* zero out ebde count */
6047 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6049 case CMD_FCP_ICMND64_CR
:
6050 /* Always open the exchange */
6051 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
6054 wqe
->words
[10] &= 0xffff0000; /* zero out ebde count */
6055 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, 0);
6057 case CMD_GEN_REQUEST64_CR
:
6058 /* word3 command length is described as byte offset to the
6059 * rsp_data. Would always be 16, sizeof(struct sli4_sge)
6064 wqe
->gen_req
.command_len
= xmit_len
;
6065 /* Word4 parameter copied in the memcpy */
6066 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
6067 /* word6 context tag copied in memcpy */
6068 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
6069 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
6070 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6071 "2015 Invalid CT %x command 0x%x\n",
6072 ct
, iocbq
->iocb
.ulpCommand
);
6075 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
, 0);
6076 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
,
6077 iocbq
->iocb
.ulpTimeout
);
6079 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6080 command_type
= OTHER_COMMAND
;
6082 case CMD_XMIT_ELS_RSP64_CX
:
6083 /* words0-2 BDE memcpy */
6084 /* word3 iocb=iotag32 wqe=rsvd */
6086 /* word4 iocb=did wge=rsvd. */
6088 /* word5 iocb=rsvd wge=did */
6089 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
6090 iocbq
->iocb
.un
.elsreq64
.remoteID
);
6092 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6093 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6095 bf_set(lpfc_wqe_gen_pu
, &wqe
->generic
, iocbq
->iocb
.ulpPU
);
6096 bf_set(wqe_rcvoxid
, &wqe
->generic
, iocbq
->iocb
.ulpContext
);
6097 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
6098 bf_set(lpfc_wqe_gen_context
, &wqe
->generic
,
6099 iocbq
->vport
->vpi
+ phba
->vpi_base
);
6100 command_type
= OTHER_COMMAND
;
6102 case CMD_CLOSE_XRI_CN
:
6103 case CMD_ABORT_XRI_CN
:
6104 case CMD_ABORT_XRI_CX
:
6105 /* words 0-2 memcpy should be 0 rserved */
6106 /* port will send abts */
6107 if (iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6109 * The link is down so the fw does not need to send abts
6112 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
6114 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
6115 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
6117 bf_set(lpfc_wqe_gen_ct
, &wqe
->generic
,
6118 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6119 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
6121 * The abort handler will send us CMD_ABORT_XRI_CN or
6122 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6124 bf_set(lpfc_wqe_gen_command
, &wqe
->generic
, CMD_ABORT_XRI_CX
);
6125 cmnd
= CMD_ABORT_XRI_CX
;
6126 command_type
= OTHER_COMMAND
;
6129 case CMD_XMIT_BLS_RSP64_CX
:
6130 /* As BLS ABTS-ACC WQE is very different from other WQEs,
6131 * we re-construct this WQE here based on information in
6132 * iocbq from scratch.
6134 memset(wqe
, 0, sizeof(union lpfc_wqe
));
6135 /* OX_ID is invariable to who sent ABTS to CT exchange */
6136 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
6137 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_acc
));
6138 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_acc
) ==
6139 LPFC_ABTS_UNSOL_INT
) {
6140 /* ABTS sent by initiator to CT exchange, the
6141 * RX_ID field will be filled with the newly
6142 * allocated responder XRI.
6144 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
6145 iocbq
->sli4_xritag
);
6147 /* ABTS sent by responder to CT exchange, the
6148 * RX_ID field will be filled with the responder
6151 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
6152 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_acc
));
6154 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
6155 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
6156 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
6157 iocbq
->iocb
.ulpContext
);
6158 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
6159 command_type
= OTHER_COMMAND
;
6161 case CMD_XRI_ABORTED_CX
:
6162 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
6163 /* words0-2 are all 0's no bde */
6164 /* word3 and word4 are rsvrd */
6167 /* word5 iocb=rsvd wge=did */
6168 /* There is no remote port id in the IOCB? */
6169 /* Let this fall through and fail */
6170 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
6171 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
6172 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
6173 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
6175 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6176 "2014 Invalid command 0x%x\n",
6177 iocbq
->iocb
.ulpCommand
);
6182 bf_set(lpfc_wqe_gen_xri
, &wqe
->generic
, xritag
);
6183 bf_set(lpfc_wqe_gen_request_tag
, &wqe
->generic
, iocbq
->iotag
);
6184 wqe
->generic
.abort_tag
= abort_tag
;
6185 bf_set(lpfc_wqe_gen_cmd_type
, &wqe
->generic
, command_type
);
6186 bf_set(lpfc_wqe_gen_command
, &wqe
->generic
, cmnd
);
6187 bf_set(lpfc_wqe_gen_class
, &wqe
->generic
, iocbq
->iocb
.ulpClass
);
6188 bf_set(lpfc_wqe_gen_cq_id
, &wqe
->generic
, LPFC_WQE_CQ_ID_DEFAULT
);
6194 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
6195 * @phba: Pointer to HBA context object.
6196 * @ring_number: SLI ring number to issue iocb on.
6197 * @piocb: Pointer to command iocb.
6198 * @flag: Flag indicating if this command can be put into txq.
6200 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
6201 * an iocb command to an HBA with SLI-4 interface spec.
6203 * This function is called with hbalock held. The function will return success
6204 * after it successfully submit the iocb to firmware or after adding to the
6208 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
6209 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6211 struct lpfc_sglq
*sglq
;
6214 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
6216 if (piocb
->sli4_xritag
== NO_XRI
) {
6217 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
6218 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6221 sglq
= __lpfc_sli_get_sglq(phba
);
6224 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
6226 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
6227 sglq
= NULL
; /* These IO's already have an XRI and
6231 /* This is a continuation of a commandi,(CX) so this
6232 * sglq is on the active list
6234 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
6240 xritag
= lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
);
6241 if (xritag
!= sglq
->sli4_xritag
)
6245 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
6248 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
6249 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
6251 * For FCP command IOCB, get a new WQ index to distribute
6252 * WQE across the WQsr. On the other hand, for abort IOCB,
6253 * it carries the same WQ index to the original command
6256 if (piocb
->iocb_flag
& LPFC_IO_FCP
)
6257 piocb
->fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
6258 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
6262 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
6265 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
6271 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6273 * This routine wraps the actual lockless version for issusing IOCB function
6274 * pointer from the lpfc_hba struct.
6277 * IOCB_ERROR - Error
6278 * IOCB_SUCCESS - Success
6282 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6283 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6285 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6289 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6290 * @phba: The hba struct for which this call is being executed.
6291 * @dev_grp: The HBA PCI-Device group number.
6293 * This routine sets up the SLI interface API function jump table in @phba
6295 * Returns: 0 - success, -ENODEV - failure.
6298 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6302 case LPFC_PCI_DEV_LP
:
6303 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
6304 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
6306 case LPFC_PCI_DEV_OC
:
6307 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
6308 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
6311 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6312 "1419 Invalid HBA PCI-device group: 0x%x\n",
6317 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
6322 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6323 * @phba: Pointer to HBA context object.
6324 * @pring: Pointer to driver SLI ring object.
6325 * @piocb: Pointer to command iocb.
6326 * @flag: Flag indicating if this command can be put into txq.
6328 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6329 * function. This function gets the hbalock and calls
6330 * __lpfc_sli_issue_iocb function and will return the error returned
6331 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6332 * functions which do not hold hbalock.
6335 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6336 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6338 unsigned long iflags
;
6341 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6342 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6343 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6349 * lpfc_extra_ring_setup - Extra ring setup function
6350 * @phba: Pointer to HBA context object.
6352 * This function is called while driver attaches with the
6353 * HBA to setup the extra ring. The extra ring is used
6354 * only when driver needs to support target mode functionality
6355 * or IP over FC functionalities.
6357 * This function is called with no lock held.
6360 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
6362 struct lpfc_sli
*psli
;
6363 struct lpfc_sli_ring
*pring
;
6367 /* Adjust cmd/rsp ring iocb entries more evenly */
6369 /* Take some away from the FCP ring */
6370 pring
= &psli
->ring
[psli
->fcp_ring
];
6371 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6372 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6373 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6374 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6376 /* and give them to the extra ring */
6377 pring
= &psli
->ring
[psli
->extra_ring
];
6379 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6380 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6381 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6382 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6384 /* Setup default profile for this ring */
6385 pring
->iotag_max
= 4096;
6386 pring
->num_mask
= 1;
6387 pring
->prt
[0].profile
= 0; /* Mask 0 */
6388 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
6389 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
6390 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
6395 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6396 * @phba: Pointer to HBA context object.
6397 * @pring: Pointer to driver SLI ring object.
6398 * @iocbq: Pointer to iocb object.
6400 * This function is called by the slow ring event handler
6401 * function when there is an ASYNC event iocb in the ring.
6402 * This function is called with no lock held.
6403 * Currently this function handles only temperature related
6404 * ASYNC events. The function decodes the temperature sensor
6405 * event message and posts events for the management applications.
6408 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
6409 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
6414 struct temp_event temp_event_data
;
6415 struct Scsi_Host
*shost
;
6418 icmd
= &iocbq
->iocb
;
6419 evt_code
= icmd
->un
.asyncstat
.evt_code
;
6420 temp
= icmd
->ulpContext
;
6422 if ((evt_code
!= ASYNC_TEMP_WARN
) &&
6423 (evt_code
!= ASYNC_TEMP_SAFE
)) {
6424 iocb_w
= (uint32_t *) icmd
;
6425 lpfc_printf_log(phba
,
6428 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6430 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6431 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6432 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6433 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6435 icmd
->un
.asyncstat
.evt_code
,
6436 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
6437 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
6438 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
6439 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
6443 temp_event_data
.data
= (uint32_t)temp
;
6444 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
6445 if (evt_code
== ASYNC_TEMP_WARN
) {
6446 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
6447 lpfc_printf_log(phba
,
6450 "0347 Adapter is very hot, please take "
6451 "corrective action. temperature : %d Celsius\n",
6454 if (evt_code
== ASYNC_TEMP_SAFE
) {
6455 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
6456 lpfc_printf_log(phba
,
6459 "0340 Adapter temperature is OK now. "
6460 "temperature : %d Celsius\n",
6464 /* Send temperature change event to applications */
6465 shost
= lpfc_shost_from_vport(phba
->pport
);
6466 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6467 sizeof(temp_event_data
), (char *) &temp_event_data
,
6474 * lpfc_sli_setup - SLI ring setup function
6475 * @phba: Pointer to HBA context object.
6477 * lpfc_sli_setup sets up rings of the SLI interface with
6478 * number of iocbs per ring and iotags. This function is
6479 * called while driver attach to the HBA and before the
6480 * interrupts are enabled. So there is no need for locking.
6482 * This function always returns 0.
6485 lpfc_sli_setup(struct lpfc_hba
*phba
)
6487 int i
, totiocbsize
= 0;
6488 struct lpfc_sli
*psli
= &phba
->sli
;
6489 struct lpfc_sli_ring
*pring
;
6491 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
6493 psli
->fcp_ring
= LPFC_FCP_RING
;
6494 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
6495 psli
->extra_ring
= LPFC_EXTRA_RING
;
6497 psli
->iocbq_lookup
= NULL
;
6498 psli
->iocbq_lookup_len
= 0;
6499 psli
->last_iotag
= 0;
6501 for (i
= 0; i
< psli
->num_rings
; i
++) {
6502 pring
= &psli
->ring
[i
];
6504 case LPFC_FCP_RING
: /* ring 0 - FCP */
6505 /* numCiocb and numRiocb are used in config_port */
6506 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
6507 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
6508 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6509 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6510 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6511 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6512 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6513 SLI3_IOCB_CMD_SIZE
:
6515 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6516 SLI3_IOCB_RSP_SIZE
:
6518 pring
->iotag_ctr
= 0;
6520 (phba
->cfg_hba_queue_depth
* 2);
6521 pring
->fast_iotag
= pring
->iotag_max
;
6522 pring
->num_mask
= 0;
6524 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
6525 /* numCiocb and numRiocb are used in config_port */
6526 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
6527 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
6528 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6529 SLI3_IOCB_CMD_SIZE
:
6531 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6532 SLI3_IOCB_RSP_SIZE
:
6534 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
6535 pring
->num_mask
= 0;
6537 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
6538 /* numCiocb and numRiocb are used in config_port */
6539 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
6540 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
6541 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
6542 SLI3_IOCB_CMD_SIZE
:
6544 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
6545 SLI3_IOCB_RSP_SIZE
:
6547 pring
->fast_iotag
= 0;
6548 pring
->iotag_ctr
= 0;
6549 pring
->iotag_max
= 4096;
6550 pring
->lpfc_sli_rcv_async_status
=
6551 lpfc_sli_async_event_handler
;
6552 pring
->num_mask
= LPFC_MAX_RING_MASK
;
6553 pring
->prt
[0].profile
= 0; /* Mask 0 */
6554 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
6555 pring
->prt
[0].type
= FC_TYPE_ELS
;
6556 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
6557 lpfc_els_unsol_event
;
6558 pring
->prt
[1].profile
= 0; /* Mask 1 */
6559 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
6560 pring
->prt
[1].type
= FC_TYPE_ELS
;
6561 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
6562 lpfc_els_unsol_event
;
6563 pring
->prt
[2].profile
= 0; /* Mask 2 */
6564 /* NameServer Inquiry */
6565 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
6567 pring
->prt
[2].type
= FC_TYPE_CT
;
6568 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
6569 lpfc_ct_unsol_event
;
6570 pring
->prt
[3].profile
= 0; /* Mask 3 */
6571 /* NameServer response */
6572 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
6574 pring
->prt
[3].type
= FC_TYPE_CT
;
6575 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
6576 lpfc_ct_unsol_event
;
6577 /* abort unsolicited sequence */
6578 pring
->prt
[4].profile
= 0; /* Mask 4 */
6579 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
6580 pring
->prt
[4].type
= FC_TYPE_BLS
;
6581 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
6582 lpfc_sli4_ct_abort_unsol_event
;
6585 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
6586 (pring
->numRiocb
* pring
->sizeRiocb
);
6588 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
6589 /* Too many cmd / rsp ring entries in SLI2 SLIM */
6590 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
6591 "SLI2 SLIM Data: x%x x%lx\n",
6592 phba
->brd_no
, totiocbsize
,
6593 (unsigned long) MAX_SLIM_IOCB_SIZE
);
6595 if (phba
->cfg_multi_ring_support
== 2)
6596 lpfc_extra_ring_setup(phba
);
6602 * lpfc_sli_queue_setup - Queue initialization function
6603 * @phba: Pointer to HBA context object.
6605 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
6606 * ring. This function also initializes ring indices of each ring.
6607 * This function is called during the initialization of the SLI
6608 * interface of an HBA.
6609 * This function is called with no lock held and always returns
6613 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
6615 struct lpfc_sli
*psli
;
6616 struct lpfc_sli_ring
*pring
;
6620 spin_lock_irq(&phba
->hbalock
);
6621 INIT_LIST_HEAD(&psli
->mboxq
);
6622 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
6623 /* Initialize list headers for txq and txcmplq as double linked lists */
6624 for (i
= 0; i
< psli
->num_rings
; i
++) {
6625 pring
= &psli
->ring
[i
];
6627 pring
->next_cmdidx
= 0;
6628 pring
->local_getidx
= 0;
6630 INIT_LIST_HEAD(&pring
->txq
);
6631 INIT_LIST_HEAD(&pring
->txcmplq
);
6632 INIT_LIST_HEAD(&pring
->iocb_continueq
);
6633 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
6634 INIT_LIST_HEAD(&pring
->postbufq
);
6636 spin_unlock_irq(&phba
->hbalock
);
6641 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
6642 * @phba: Pointer to HBA context object.
6644 * This routine flushes the mailbox command subsystem. It will unconditionally
6645 * flush all the mailbox commands in the three possible stages in the mailbox
6646 * command sub-system: pending mailbox command queue; the outstanding mailbox
6647 * command; and completed mailbox command queue. It is caller's responsibility
6648 * to make sure that the driver is in the proper state to flush the mailbox
6649 * command sub-system. Namely, the posting of mailbox commands into the
6650 * pending mailbox command queue from the various clients must be stopped;
6651 * either the HBA is in a state that it will never works on the outstanding
6652 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
6653 * mailbox command has been completed.
6656 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
6658 LIST_HEAD(completions
);
6659 struct lpfc_sli
*psli
= &phba
->sli
;
6661 unsigned long iflag
;
6663 /* Flush all the mailbox commands in the mbox system */
6664 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6665 /* The pending mailbox command queue */
6666 list_splice_init(&phba
->sli
.mboxq
, &completions
);
6667 /* The outstanding active mailbox command */
6668 if (psli
->mbox_active
) {
6669 list_add_tail(&psli
->mbox_active
->list
, &completions
);
6670 psli
->mbox_active
= NULL
;
6671 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6673 /* The completed mailbox command queue */
6674 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
6675 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6677 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
6678 while (!list_empty(&completions
)) {
6679 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
6680 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6682 pmb
->mbox_cmpl(phba
, pmb
);
6687 * lpfc_sli_host_down - Vport cleanup function
6688 * @vport: Pointer to virtual port object.
6690 * lpfc_sli_host_down is called to clean up the resources
6691 * associated with a vport before destroying virtual
6692 * port data structures.
6693 * This function does following operations:
6694 * - Free discovery resources associated with this virtual
6696 * - Free iocbs associated with this virtual port in
6698 * - Send abort for all iocb commands associated with this
6701 * This function is called with no lock held and always returns 1.
6704 lpfc_sli_host_down(struct lpfc_vport
*vport
)
6706 LIST_HEAD(completions
);
6707 struct lpfc_hba
*phba
= vport
->phba
;
6708 struct lpfc_sli
*psli
= &phba
->sli
;
6709 struct lpfc_sli_ring
*pring
;
6710 struct lpfc_iocbq
*iocb
, *next_iocb
;
6712 unsigned long flags
= 0;
6713 uint16_t prev_pring_flag
;
6715 lpfc_cleanup_discovery_resources(vport
);
6717 spin_lock_irqsave(&phba
->hbalock
, flags
);
6718 for (i
= 0; i
< psli
->num_rings
; i
++) {
6719 pring
= &psli
->ring
[i
];
6720 prev_pring_flag
= pring
->flag
;
6721 /* Only slow rings */
6722 if (pring
->ringno
== LPFC_ELS_RING
) {
6723 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
6724 /* Set the lpfc data pending flag */
6725 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
6728 * Error everything on the txq since these iocbs have not been
6729 * given to the FW yet.
6731 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
6732 if (iocb
->vport
!= vport
)
6734 list_move_tail(&iocb
->list
, &completions
);
6738 /* Next issue ABTS for everything on the txcmplq */
6739 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
6741 if (iocb
->vport
!= vport
)
6743 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
6746 pring
->flag
= prev_pring_flag
;
6749 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6751 /* Cancel all the IOCBs from the completions list */
6752 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6758 * lpfc_sli_hba_down - Resource cleanup function for the HBA
6759 * @phba: Pointer to HBA context object.
6761 * This function cleans up all iocb, buffers, mailbox commands
6762 * while shutting down the HBA. This function is called with no
6763 * lock held and always returns 1.
6764 * This function does the following to cleanup driver resources:
6765 * - Free discovery resources for each virtual port
6766 * - Cleanup any pending fabric iocbs
6767 * - Iterate through the iocb txq and free each entry
6769 * - Free up any buffer posted to the HBA
6770 * - Free mailbox commands in the mailbox queue.
6773 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
6775 LIST_HEAD(completions
);
6776 struct lpfc_sli
*psli
= &phba
->sli
;
6777 struct lpfc_sli_ring
*pring
;
6778 struct lpfc_dmabuf
*buf_ptr
;
6779 unsigned long flags
= 0;
6782 /* Shutdown the mailbox command sub-system */
6783 lpfc_sli_mbox_sys_shutdown(phba
);
6785 lpfc_hba_down_prep(phba
);
6787 lpfc_fabric_abort_hba(phba
);
6789 spin_lock_irqsave(&phba
->hbalock
, flags
);
6790 for (i
= 0; i
< psli
->num_rings
; i
++) {
6791 pring
= &psli
->ring
[i
];
6792 /* Only slow rings */
6793 if (pring
->ringno
== LPFC_ELS_RING
) {
6794 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
6795 /* Set the lpfc data pending flag */
6796 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
6800 * Error everything on the txq since these iocbs have not been
6801 * given to the FW yet.
6803 list_splice_init(&pring
->txq
, &completions
);
6807 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6809 /* Cancel all the IOCBs from the completions list */
6810 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6813 spin_lock_irqsave(&phba
->hbalock
, flags
);
6814 list_splice_init(&phba
->elsbuf
, &completions
);
6815 phba
->elsbuf_cnt
= 0;
6816 phba
->elsbuf_prev_cnt
= 0;
6817 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6819 while (!list_empty(&completions
)) {
6820 list_remove_head(&completions
, buf_ptr
,
6821 struct lpfc_dmabuf
, list
);
6822 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
6826 /* Return any active mbox cmds */
6827 del_timer_sync(&psli
->mbox_tmo
);
6829 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
6830 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6831 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
6837 * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
6838 * @phba: Pointer to HBA context object.
6840 * This function cleans up all queues, iocb, buffers, mailbox commands while
6841 * shutting down the SLI4 HBA FCoE function. This function is called with no
6842 * lock held and always returns 1.
6844 * This function does the following to cleanup driver FCoE function resources:
6845 * - Free discovery resources for each virtual port
6846 * - Cleanup any pending fabric iocbs
6847 * - Iterate through the iocb txq and free each entry in the list.
6848 * - Free up any buffer posted to the HBA.
6849 * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
6850 * - Free mailbox commands in the mailbox queue.
6853 lpfc_sli4_hba_down(struct lpfc_hba
*phba
)
6855 /* Stop the SLI4 device port */
6856 lpfc_stop_port(phba
);
6858 /* Tear down the queues in the HBA */
6859 lpfc_sli4_queue_unset(phba
);
6861 /* unregister default FCFI from the HBA */
6862 lpfc_sli4_fcfi_unreg(phba
, phba
->fcf
.fcfi
);
6868 * lpfc_sli_pcimem_bcopy - SLI memory copy function
6869 * @srcp: Source memory pointer.
6870 * @destp: Destination memory pointer.
6871 * @cnt: Number of words required to be copied.
6873 * This function is used for copying data between driver memory
6874 * and the SLI memory. This function also changes the endianness
6875 * of each word if native endianness is different from SLI
6876 * endianness. This function can be called with or without
6880 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
6882 uint32_t *src
= srcp
;
6883 uint32_t *dest
= destp
;
6887 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
6889 ldata
= le32_to_cpu(ldata
);
6898 * lpfc_sli_bemem_bcopy - SLI memory copy function
6899 * @srcp: Source memory pointer.
6900 * @destp: Destination memory pointer.
6901 * @cnt: Number of words required to be copied.
6903 * This function is used for copying data between a data structure
6904 * with big endian representation to local endianness.
6905 * This function can be called with or without lock.
6908 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
6910 uint32_t *src
= srcp
;
6911 uint32_t *dest
= destp
;
6915 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
6917 ldata
= be32_to_cpu(ldata
);
6925 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
6926 * @phba: Pointer to HBA context object.
6927 * @pring: Pointer to driver SLI ring object.
6928 * @mp: Pointer to driver buffer object.
6930 * This function is called with no lock held.
6931 * It always return zero after adding the buffer to the postbufq
6935 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6936 struct lpfc_dmabuf
*mp
)
6938 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
6940 spin_lock_irq(&phba
->hbalock
);
6941 list_add_tail(&mp
->list
, &pring
->postbufq
);
6942 pring
->postbufq_cnt
++;
6943 spin_unlock_irq(&phba
->hbalock
);
6948 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
6949 * @phba: Pointer to HBA context object.
6951 * When HBQ is enabled, buffers are searched based on tags. This function
6952 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
6953 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
6954 * does not conflict with tags of buffer posted for unsolicited events.
6955 * The function returns the allocated tag. The function is called with
6959 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
6961 spin_lock_irq(&phba
->hbalock
);
6962 phba
->buffer_tag_count
++;
6964 * Always set the QUE_BUFTAG_BIT to distiguish between
6965 * a tag assigned by HBQ.
6967 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
6968 spin_unlock_irq(&phba
->hbalock
);
6969 return phba
->buffer_tag_count
;
6973 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
6974 * @phba: Pointer to HBA context object.
6975 * @pring: Pointer to driver SLI ring object.
6978 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
6979 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
6980 * iocb is posted to the response ring with the tag of the buffer.
6981 * This function searches the pring->postbufq list using the tag
6982 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
6983 * iocb. If the buffer is found then lpfc_dmabuf object of the
6984 * buffer is returned to the caller else NULL is returned.
6985 * This function is called with no lock held.
6987 struct lpfc_dmabuf
*
6988 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6991 struct lpfc_dmabuf
*mp
, *next_mp
;
6992 struct list_head
*slp
= &pring
->postbufq
;
6994 /* Search postbufq, from the begining, looking for a match on tag */
6995 spin_lock_irq(&phba
->hbalock
);
6996 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
6997 if (mp
->buffer_tag
== tag
) {
6998 list_del_init(&mp
->list
);
6999 pring
->postbufq_cnt
--;
7000 spin_unlock_irq(&phba
->hbalock
);
7005 spin_unlock_irq(&phba
->hbalock
);
7006 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7007 "0402 Cannot find virtual addr for buffer tag on "
7008 "ring %d Data x%lx x%p x%p x%x\n",
7009 pring
->ringno
, (unsigned long) tag
,
7010 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
7016 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
7017 * @phba: Pointer to HBA context object.
7018 * @pring: Pointer to driver SLI ring object.
7019 * @phys: DMA address of the buffer.
7021 * This function searches the buffer list using the dma_address
7022 * of unsolicited event to find the driver's lpfc_dmabuf object
7023 * corresponding to the dma_address. The function returns the
7024 * lpfc_dmabuf object if a buffer is found else it returns NULL.
7025 * This function is called by the ct and els unsolicited event
7026 * handlers to get the buffer associated with the unsolicited
7029 * This function is called with no lock held.
7031 struct lpfc_dmabuf
*
7032 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7035 struct lpfc_dmabuf
*mp
, *next_mp
;
7036 struct list_head
*slp
= &pring
->postbufq
;
7038 /* Search postbufq, from the begining, looking for a match on phys */
7039 spin_lock_irq(&phba
->hbalock
);
7040 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
7041 if (mp
->phys
== phys
) {
7042 list_del_init(&mp
->list
);
7043 pring
->postbufq_cnt
--;
7044 spin_unlock_irq(&phba
->hbalock
);
7049 spin_unlock_irq(&phba
->hbalock
);
7050 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7051 "0410 Cannot find virtual addr for mapped buf on "
7052 "ring %d Data x%llx x%p x%p x%x\n",
7053 pring
->ringno
, (unsigned long long)phys
,
7054 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
7059 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
7060 * @phba: Pointer to HBA context object.
7061 * @cmdiocb: Pointer to driver command iocb object.
7062 * @rspiocb: Pointer to driver response iocb object.
7064 * This function is the completion handler for the abort iocbs for
7065 * ELS commands. This function is called from the ELS ring event
7066 * handler with no lock held. This function frees memory resources
7067 * associated with the abort iocb.
7070 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7071 struct lpfc_iocbq
*rspiocb
)
7073 IOCB_t
*irsp
= &rspiocb
->iocb
;
7074 uint16_t abort_iotag
, abort_context
;
7075 struct lpfc_iocbq
*abort_iocb
;
7076 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7080 if (irsp
->ulpStatus
) {
7081 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
7082 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
7084 spin_lock_irq(&phba
->hbalock
);
7085 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7086 if (abort_iotag
!= 0 &&
7087 abort_iotag
<= phba
->sli
.last_iotag
)
7089 phba
->sli
.iocbq_lookup
[abort_iotag
];
7091 /* For sli4 the abort_tag is the XRI,
7092 * so the abort routine puts the iotag of the iocb
7093 * being aborted in the context field of the abort
7096 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
7098 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_SLI
,
7099 "0327 Cannot abort els iocb %p "
7100 "with tag %x context %x, abort status %x, "
7102 abort_iocb
, abort_iotag
, abort_context
,
7103 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
7106 * If the iocb is not found in Firmware queue the iocb
7107 * might have completed already. Do not free it again.
7109 if (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
7110 if (irsp
->un
.ulpWord
[4] != IOERR_NO_XRI
) {
7111 spin_unlock_irq(&phba
->hbalock
);
7112 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7115 /* For SLI4 the ulpContext field for abort IOCB
7116 * holds the iotag of the IOCB being aborted so
7117 * the local abort_context needs to be reset to
7118 * match the aborted IOCBs ulpContext.
7120 if (abort_iocb
&& phba
->sli_rev
== LPFC_SLI_REV4
)
7121 abort_context
= abort_iocb
->iocb
.ulpContext
;
7124 * make sure we have the right iocbq before taking it
7125 * off the txcmplq and try to call completion routine.
7128 abort_iocb
->iocb
.ulpContext
!= abort_context
||
7129 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
7130 spin_unlock_irq(&phba
->hbalock
);
7131 else if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7133 * leave the SLI4 aborted command on the txcmplq
7134 * list and the command complete WCQE's XB bit
7135 * will tell whether the SGL (XRI) can be released
7136 * immediately or to the aborted SGL list for the
7137 * following abort XRI from the HBA.
7139 list_del_init(&abort_iocb
->list
);
7140 pring
->txcmplq_cnt
--;
7142 /* Firmware could still be in progress of DMAing
7143 * payload, so don't free data buffer till after
7146 abort_iocb
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
7147 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
7148 spin_unlock_irq(&phba
->hbalock
);
7150 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
7151 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_ABORT_REQUESTED
;
7152 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
7154 spin_unlock_irq(&phba
->hbalock
);
7157 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7162 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
7163 * @phba: Pointer to HBA context object.
7164 * @cmdiocb: Pointer to driver command iocb object.
7165 * @rspiocb: Pointer to driver response iocb object.
7167 * The function is called from SLI ring event handler with no
7168 * lock held. This function is the completion handler for ELS commands
7169 * which are aborted. The function frees memory resources used for
7170 * the aborted ELS commands.
7173 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7174 struct lpfc_iocbq
*rspiocb
)
7176 IOCB_t
*irsp
= &rspiocb
->iocb
;
7178 /* ELS cmd tag <ulpIoTag> completes */
7179 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
7180 "0139 Ignoring ELS cmd tag x%x completion Data: "
7182 irsp
->ulpIoTag
, irsp
->ulpStatus
,
7183 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
7184 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
7185 lpfc_ct_free_iocb(phba
, cmdiocb
);
7187 lpfc_els_free_iocb(phba
, cmdiocb
);
7192 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7193 * @phba: Pointer to HBA context object.
7194 * @pring: Pointer to driver SLI ring object.
7195 * @cmdiocb: Pointer to driver command iocb object.
7197 * This function issues an abort iocb for the provided command
7198 * iocb. This function is called with hbalock held.
7199 * The function returns 0 when it fails due to memory allocation
7200 * failure or when the command iocb is an abort request.
7203 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7204 struct lpfc_iocbq
*cmdiocb
)
7206 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7207 struct lpfc_iocbq
*abtsiocbp
;
7208 IOCB_t
*icmd
= NULL
;
7209 IOCB_t
*iabt
= NULL
;
7210 int retval
= IOCB_ERROR
;
7213 * There are certain command types we don't want to abort. And we
7214 * don't want to abort commands that are already in the process of
7217 icmd
= &cmdiocb
->iocb
;
7218 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
7219 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7220 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
7223 /* If we're unloading, don't abort iocb on the ELS ring, but change the
7224 * callback so that nothing happens when it finishes.
7226 if ((vport
->load_flag
& FC_UNLOADING
) &&
7227 (pring
->ringno
== LPFC_ELS_RING
)) {
7228 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
7229 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
7231 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
7232 goto abort_iotag_exit
;
7235 /* issue ABTS for this IOCB based on iotag */
7236 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
7237 if (abtsiocbp
== NULL
)
7240 /* This signals the response to set the correct status
7241 * before calling the completion handler
7243 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
7245 iabt
= &abtsiocbp
->iocb
;
7246 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7247 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
7248 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7249 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
7250 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
7253 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
7255 iabt
->ulpClass
= icmd
->ulpClass
;
7257 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7258 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
7259 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
7260 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
7262 if (phba
->link_state
>= LPFC_LINK_UP
)
7263 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
7265 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
7267 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
7269 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
7270 "0339 Abort xri x%x, original iotag x%x, "
7271 "abort cmd iotag x%x\n",
7272 iabt
->un
.acxri
.abortContextTag
,
7273 iabt
->un
.acxri
.abortIoTag
, abtsiocbp
->iotag
);
7274 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
7277 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
7280 * Caller to this routine should check for IOCB_ERROR
7281 * and handle it properly. This routine no longer removes
7282 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7288 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7289 * @iocbq: Pointer to driver iocb object.
7290 * @vport: Pointer to driver virtual port object.
7291 * @tgt_id: SCSI ID of the target.
7292 * @lun_id: LUN ID of the scsi device.
7293 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
7295 * This function acts as an iocb filter for functions which abort or count
7296 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
7297 * 0 if the filtering criteria is met for the given iocb and will return
7298 * 1 if the filtering criteria is not met.
7299 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
7300 * given iocb is for the SCSI device specified by vport, tgt_id and
7302 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
7303 * given iocb is for the SCSI target specified by vport and tgt_id
7305 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
7306 * given iocb is for the SCSI host associated with the given vport.
7307 * This function is called with no locks held.
7310 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
7311 uint16_t tgt_id
, uint64_t lun_id
,
7312 lpfc_ctx_cmd ctx_cmd
)
7314 struct lpfc_scsi_buf
*lpfc_cmd
;
7317 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
7320 if (iocbq
->vport
!= vport
)
7323 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
7325 if (lpfc_cmd
->pCmd
== NULL
)
7330 if ((lpfc_cmd
->rdata
->pnode
) &&
7331 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
7332 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
7336 if ((lpfc_cmd
->rdata
->pnode
) &&
7337 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
7344 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
7353 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7354 * @vport: Pointer to virtual port.
7355 * @tgt_id: SCSI ID of the target.
7356 * @lun_id: LUN ID of the scsi device.
7357 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7359 * This function returns number of FCP commands pending for the vport.
7360 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7361 * commands pending on the vport associated with SCSI device specified
7362 * by tgt_id and lun_id parameters.
7363 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7364 * commands pending on the vport associated with SCSI target specified
7365 * by tgt_id parameter.
7366 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7367 * commands pending on the vport.
7368 * This function returns the number of iocbs which satisfy the filter.
7369 * This function is called without any lock held.
7372 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
7373 lpfc_ctx_cmd ctx_cmd
)
7375 struct lpfc_hba
*phba
= vport
->phba
;
7376 struct lpfc_iocbq
*iocbq
;
7379 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
7380 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7382 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
7391 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7392 * @phba: Pointer to HBA context object
7393 * @cmdiocb: Pointer to command iocb object.
7394 * @rspiocb: Pointer to response iocb object.
7396 * This function is called when an aborted FCP iocb completes. This
7397 * function is called by the ring event handler with no lock held.
7398 * This function frees the iocb.
7401 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7402 struct lpfc_iocbq
*rspiocb
)
7404 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7409 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
7410 * @vport: Pointer to virtual port.
7411 * @pring: Pointer to driver SLI ring object.
7412 * @tgt_id: SCSI ID of the target.
7413 * @lun_id: LUN ID of the scsi device.
7414 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7416 * This function sends an abort command for every SCSI command
7417 * associated with the given virtual port pending on the ring
7418 * filtered by lpfc_sli_validate_fcp_iocb function.
7419 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
7420 * FCP iocbs associated with lun specified by tgt_id and lun_id
7422 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
7423 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
7424 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
7425 * FCP iocbs associated with virtual port.
7426 * This function returns number of iocbs it failed to abort.
7427 * This function is called with no locks held.
7430 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
7431 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
7433 struct lpfc_hba
*phba
= vport
->phba
;
7434 struct lpfc_iocbq
*iocbq
;
7435 struct lpfc_iocbq
*abtsiocb
;
7437 int errcnt
= 0, ret_val
= 0;
7440 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
7441 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7443 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
7447 /* issue ABTS for this IOCB based on iotag */
7448 abtsiocb
= lpfc_sli_get_iocbq(phba
);
7449 if (abtsiocb
== NULL
) {
7455 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7456 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
7457 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7458 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
7460 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
7461 abtsiocb
->iocb
.ulpLe
= 1;
7462 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
7463 abtsiocb
->vport
= phba
->pport
;
7465 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7466 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
7467 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7468 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
7470 if (lpfc_is_link_up(phba
))
7471 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
7473 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
7475 /* Setup callback routine and issue the command. */
7476 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
7477 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
7479 if (ret_val
== IOCB_ERROR
) {
7480 lpfc_sli_release_iocbq(phba
, abtsiocb
);
7490 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
7491 * @phba: Pointer to HBA context object.
7492 * @cmdiocbq: Pointer to command iocb.
7493 * @rspiocbq: Pointer to response iocb.
7495 * This function is the completion handler for iocbs issued using
7496 * lpfc_sli_issue_iocb_wait function. This function is called by the
7497 * ring event handler function without any lock held. This function
7498 * can be called from both worker thread context and interrupt
7499 * context. This function also can be called from other thread which
7500 * cleans up the SLI layer objects.
7501 * This function copy the contents of the response iocb to the
7502 * response iocb memory object provided by the caller of
7503 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
7504 * sleeps for the iocb completion.
7507 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
7508 struct lpfc_iocbq
*cmdiocbq
,
7509 struct lpfc_iocbq
*rspiocbq
)
7511 wait_queue_head_t
*pdone_q
;
7512 unsigned long iflags
;
7513 struct lpfc_scsi_buf
*lpfc_cmd
;
7515 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7516 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
7517 if (cmdiocbq
->context2
&& rspiocbq
)
7518 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
7519 &rspiocbq
->iocb
, sizeof(IOCB_t
));
7521 /* Set the exchange busy flag for task management commands */
7522 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
7523 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
7524 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
7526 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
7529 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
7532 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7537 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
7538 * @phba: Pointer to HBA context object..
7539 * @piocbq: Pointer to command iocb.
7540 * @flag: Flag to test.
7542 * This routine grabs the hbalock and then test the iocb_flag to
7543 * see if the passed in flag is set.
7546 * 0 if flag is not set.
7549 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
7550 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
7552 unsigned long iflags
;
7555 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7556 ret
= piocbq
->iocb_flag
& flag
;
7557 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7563 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
7564 * @phba: Pointer to HBA context object..
7565 * @pring: Pointer to sli ring.
7566 * @piocb: Pointer to command iocb.
7567 * @prspiocbq: Pointer to response iocb.
7568 * @timeout: Timeout in number of seconds.
7570 * This function issues the iocb to firmware and waits for the
7571 * iocb to complete. If the iocb command is not
7572 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
7573 * Caller should not free the iocb resources if this function
7574 * returns IOCB_TIMEDOUT.
7575 * The function waits for the iocb completion using an
7576 * non-interruptible wait.
7577 * This function will sleep while waiting for iocb completion.
7578 * So, this function should not be called from any context which
7579 * does not allow sleeping. Due to the same reason, this function
7580 * cannot be called with interrupt disabled.
7581 * This function assumes that the iocb completions occur while
7582 * this function sleep. So, this function cannot be called from
7583 * the thread which process iocb completion for this ring.
7584 * This function clears the iocb_flag of the iocb object before
7585 * issuing the iocb and the iocb completion handler sets this
7586 * flag and wakes this thread when the iocb completes.
7587 * The contents of the response iocb will be copied to prspiocbq
7588 * by the completion handler when the command completes.
7589 * This function returns IOCB_SUCCESS when success.
7590 * This function is called with no lock held.
7593 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
7594 uint32_t ring_number
,
7595 struct lpfc_iocbq
*piocb
,
7596 struct lpfc_iocbq
*prspiocbq
,
7599 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
7600 long timeleft
, timeout_req
= 0;
7601 int retval
= IOCB_SUCCESS
;
7605 * If the caller has provided a response iocbq buffer, then context2
7606 * is NULL or its an error.
7609 if (piocb
->context2
)
7611 piocb
->context2
= prspiocbq
;
7614 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
7615 piocb
->context_un
.wait_queue
= &done_q
;
7616 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
7618 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7619 creg_val
= readl(phba
->HCregaddr
);
7620 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
7621 writel(creg_val
, phba
->HCregaddr
);
7622 readl(phba
->HCregaddr
); /* flush */
7625 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, 0);
7626 if (retval
== IOCB_SUCCESS
) {
7627 timeout_req
= timeout
* HZ
;
7628 timeleft
= wait_event_timeout(done_q
,
7629 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
7632 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
7633 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7634 "0331 IOCB wake signaled\n");
7635 } else if (timeleft
== 0) {
7636 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7637 "0338 IOCB wait timeout error - no "
7638 "wake response Data x%x\n", timeout
);
7639 retval
= IOCB_TIMEDOUT
;
7641 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7642 "0330 IOCB wake NOT set, "
7644 timeout
, (timeleft
/ jiffies
));
7645 retval
= IOCB_TIMEDOUT
;
7648 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7649 "0332 IOCB wait issue failed, Data x%x\n",
7651 retval
= IOCB_ERROR
;
7654 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7655 creg_val
= readl(phba
->HCregaddr
);
7656 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
7657 writel(creg_val
, phba
->HCregaddr
);
7658 readl(phba
->HCregaddr
); /* flush */
7662 piocb
->context2
= NULL
;
7664 piocb
->context_un
.wait_queue
= NULL
;
7665 piocb
->iocb_cmpl
= NULL
;
7670 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
7671 * @phba: Pointer to HBA context object.
7672 * @pmboxq: Pointer to driver mailbox object.
7673 * @timeout: Timeout in number of seconds.
7675 * This function issues the mailbox to firmware and waits for the
7676 * mailbox command to complete. If the mailbox command is not
7677 * completed within timeout seconds, it returns MBX_TIMEOUT.
7678 * The function waits for the mailbox completion using an
7679 * interruptible wait. If the thread is woken up due to a
7680 * signal, MBX_TIMEOUT error is returned to the caller. Caller
7681 * should not free the mailbox resources, if this function returns
7683 * This function will sleep while waiting for mailbox completion.
7684 * So, this function should not be called from any context which
7685 * does not allow sleeping. Due to the same reason, this function
7686 * cannot be called with interrupt disabled.
7687 * This function assumes that the mailbox completion occurs while
7688 * this function sleep. So, this function cannot be called from
7689 * the worker thread which processes mailbox completion.
7690 * This function is called in the context of HBA management
7692 * This function returns MBX_SUCCESS when successful.
7693 * This function is called with no lock held.
7696 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
7699 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
7703 /* The caller must leave context1 empty. */
7704 if (pmboxq
->context1
)
7705 return MBX_NOT_FINISHED
;
7707 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
7708 /* setup wake call as IOCB callback */
7709 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
7710 /* setup context field to pass wait_queue pointer to wake function */
7711 pmboxq
->context1
= &done_q
;
7713 /* now issue the command */
7714 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
7716 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
7717 wait_event_interruptible_timeout(done_q
,
7718 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
7721 spin_lock_irqsave(&phba
->hbalock
, flag
);
7722 pmboxq
->context1
= NULL
;
7724 * if LPFC_MBX_WAKE flag is set the mailbox is completed
7725 * else do not free the resources.
7727 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
)
7728 retval
= MBX_SUCCESS
;
7730 retval
= MBX_TIMEOUT
;
7731 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
7733 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
7740 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
7741 * @phba: Pointer to HBA context.
7743 * This function is called to shutdown the driver's mailbox sub-system.
7744 * It first marks the mailbox sub-system is in a block state to prevent
7745 * the asynchronous mailbox command from issued off the pending mailbox
7746 * command queue. If the mailbox command sub-system shutdown is due to
7747 * HBA error conditions such as EEH or ERATT, this routine shall invoke
7748 * the mailbox sub-system flush routine to forcefully bring down the
7749 * mailbox sub-system. Otherwise, if it is due to normal condition (such
7750 * as with offline or HBA function reset), this routine will wait for the
7751 * outstanding mailbox command to complete before invoking the mailbox
7752 * sub-system flush routine to gracefully bring down mailbox sub-system.
7755 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
7757 struct lpfc_sli
*psli
= &phba
->sli
;
7758 uint8_t actcmd
= MBX_HEARTBEAT
;
7759 unsigned long timeout
;
7761 spin_lock_irq(&phba
->hbalock
);
7762 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7763 spin_unlock_irq(&phba
->hbalock
);
7765 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7766 spin_lock_irq(&phba
->hbalock
);
7767 if (phba
->sli
.mbox_active
)
7768 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
7769 spin_unlock_irq(&phba
->hbalock
);
7770 /* Determine how long we might wait for the active mailbox
7771 * command to be gracefully completed by firmware.
7773 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) *
7775 while (phba
->sli
.mbox_active
) {
7776 /* Check active mailbox complete status every 2ms */
7778 if (time_after(jiffies
, timeout
))
7779 /* Timeout, let the mailbox flush routine to
7780 * forcefully release active mailbox command
7785 lpfc_sli_mbox_sys_flush(phba
);
7789 * lpfc_sli_eratt_read - read sli-3 error attention events
7790 * @phba: Pointer to HBA context.
7792 * This function is called to read the SLI3 device error attention registers
7793 * for possible error attention events. The caller must hold the hostlock
7794 * with spin_lock_irq().
7796 * This fucntion returns 1 when there is Error Attention in the Host Attention
7797 * Register and returns 0 otherwise.
7800 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
7804 /* Read chip Host Attention (HA) register */
7805 ha_copy
= readl(phba
->HAregaddr
);
7806 if (ha_copy
& HA_ERATT
) {
7807 /* Read host status register to retrieve error event */
7808 lpfc_sli_read_hs(phba
);
7810 /* Check if there is a deferred error condition is active */
7811 if ((HS_FFER1
& phba
->work_hs
) &&
7812 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
7813 HS_FFER6
| HS_FFER7
) & phba
->work_hs
)) {
7814 phba
->hba_flag
|= DEFER_ERATT
;
7815 /* Clear all interrupt enable conditions */
7816 writel(0, phba
->HCregaddr
);
7817 readl(phba
->HCregaddr
);
7820 /* Set the driver HA work bitmap */
7821 phba
->work_ha
|= HA_ERATT
;
7822 /* Indicate polling handles this ERATT */
7823 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7830 * lpfc_sli4_eratt_read - read sli-4 error attention events
7831 * @phba: Pointer to HBA context.
7833 * This function is called to read the SLI4 device error attention registers
7834 * for possible error attention events. The caller must hold the hostlock
7835 * with spin_lock_irq().
7837 * This fucntion returns 1 when there is Error Attention in the Host Attention
7838 * Register and returns 0 otherwise.
7841 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
7843 uint32_t uerr_sta_hi
, uerr_sta_lo
;
7845 /* For now, use the SLI4 device internal unrecoverable error
7846 * registers for error attention. This can be changed later.
7848 uerr_sta_lo
= readl(phba
->sli4_hba
.UERRLOregaddr
);
7849 uerr_sta_hi
= readl(phba
->sli4_hba
.UERRHIregaddr
);
7850 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
7851 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
7852 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7853 "1423 HBA Unrecoverable error: "
7854 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
7855 "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
7856 uerr_sta_lo
, uerr_sta_hi
,
7857 phba
->sli4_hba
.ue_mask_lo
,
7858 phba
->sli4_hba
.ue_mask_hi
);
7859 phba
->work_status
[0] = uerr_sta_lo
;
7860 phba
->work_status
[1] = uerr_sta_hi
;
7861 /* Set the driver HA work bitmap */
7862 phba
->work_ha
|= HA_ERATT
;
7863 /* Indicate polling handles this ERATT */
7864 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
7871 * lpfc_sli_check_eratt - check error attention events
7872 * @phba: Pointer to HBA context.
7874 * This function is called from timer soft interrupt context to check HBA's
7875 * error attention register bit for error attention events.
7877 * This fucntion returns 1 when there is Error Attention in the Host Attention
7878 * Register and returns 0 otherwise.
7881 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
7885 /* If somebody is waiting to handle an eratt, don't process it
7886 * here. The brdkill function will do this.
7888 if (phba
->link_flag
& LS_IGNORE_ERATT
)
7891 /* Check if interrupt handler handles this ERATT */
7892 spin_lock_irq(&phba
->hbalock
);
7893 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
7894 /* Interrupt handler has handled ERATT */
7895 spin_unlock_irq(&phba
->hbalock
);
7900 * If there is deferred error attention, do not check for error
7903 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7904 spin_unlock_irq(&phba
->hbalock
);
7908 /* If PCI channel is offline, don't process it */
7909 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7910 spin_unlock_irq(&phba
->hbalock
);
7914 switch (phba
->sli_rev
) {
7917 /* Read chip Host Attention (HA) register */
7918 ha_copy
= lpfc_sli_eratt_read(phba
);
7921 /* Read devcie Uncoverable Error (UERR) registers */
7922 ha_copy
= lpfc_sli4_eratt_read(phba
);
7925 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7926 "0299 Invalid SLI revision (%d)\n",
7931 spin_unlock_irq(&phba
->hbalock
);
7937 * lpfc_intr_state_check - Check device state for interrupt handling
7938 * @phba: Pointer to HBA context.
7940 * This inline routine checks whether a device or its PCI slot is in a state
7941 * that the interrupt should be handled.
7943 * This function returns 0 if the device or the PCI slot is in a state that
7944 * interrupt should be handled, otherwise -EIO.
7947 lpfc_intr_state_check(struct lpfc_hba
*phba
)
7949 /* If the pci channel is offline, ignore all the interrupts */
7950 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7953 /* Update device level interrupt statistics */
7954 phba
->sli
.slistat
.sli_intr
++;
7956 /* Ignore all interrupts during initialization. */
7957 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7964 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
7965 * @irq: Interrupt number.
7966 * @dev_id: The device context pointer.
7968 * This function is directly called from the PCI layer as an interrupt
7969 * service routine when device with SLI-3 interface spec is enabled with
7970 * MSI-X multi-message interrupt mode and there are slow-path events in
7971 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
7972 * interrupt mode, this function is called as part of the device-level
7973 * interrupt handler. When the PCI slot is in error recovery or the HBA
7974 * is undergoing initialization, the interrupt handler will not process
7975 * the interrupt. The link attention and ELS ring attention events are
7976 * handled by the worker thread. The interrupt handler signals the worker
7977 * thread and returns for these events. This function is called without
7978 * any lock held. It gets the hbalock to access and update SLI data
7981 * This function returns IRQ_HANDLED when interrupt is handled else it
7985 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
7987 struct lpfc_hba
*phba
;
7988 uint32_t ha_copy
, hc_copy
;
7989 uint32_t work_ha_copy
;
7990 unsigned long status
;
7991 unsigned long iflag
;
7994 MAILBOX_t
*mbox
, *pmbox
;
7995 struct lpfc_vport
*vport
;
7996 struct lpfc_nodelist
*ndlp
;
7997 struct lpfc_dmabuf
*mp
;
8002 * Get the driver's phba structure from the dev_id and
8003 * assume the HBA is not interrupting.
8005 phba
= (struct lpfc_hba
*)dev_id
;
8007 if (unlikely(!phba
))
8011 * Stuff needs to be attented to when this function is invoked as an
8012 * individual interrupt handler in MSI-X multi-message interrupt mode
8014 if (phba
->intr_type
== MSIX
) {
8015 /* Check device state for handling interrupt */
8016 if (lpfc_intr_state_check(phba
))
8018 /* Need to read HA REG for slow-path events */
8019 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8020 ha_copy
= readl(phba
->HAregaddr
);
8021 /* If somebody is waiting to handle an eratt don't process it
8022 * here. The brdkill function will do this.
8024 if (phba
->link_flag
& LS_IGNORE_ERATT
)
8025 ha_copy
&= ~HA_ERATT
;
8026 /* Check the need for handling ERATT in interrupt handler */
8027 if (ha_copy
& HA_ERATT
) {
8028 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
8029 /* ERATT polling has handled ERATT */
8030 ha_copy
&= ~HA_ERATT
;
8032 /* Indicate interrupt handler handles ERATT */
8033 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8037 * If there is deferred error attention, do not check for any
8040 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8041 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8045 /* Clear up only attention source related to slow-path */
8046 hc_copy
= readl(phba
->HCregaddr
);
8047 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
8048 HC_LAINT_ENA
| HC_ERINT_ENA
),
8050 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
8052 writel(hc_copy
, phba
->HCregaddr
);
8053 readl(phba
->HAregaddr
); /* flush */
8054 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8056 ha_copy
= phba
->ha_copy
;
8058 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
8061 if (work_ha_copy
& HA_LATT
) {
8062 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
8064 * Turn off Link Attention interrupts
8065 * until CLEAR_LA done
8067 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8068 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
8069 control
= readl(phba
->HCregaddr
);
8070 control
&= ~HC_LAINT_ENA
;
8071 writel(control
, phba
->HCregaddr
);
8072 readl(phba
->HCregaddr
); /* flush */
8073 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8076 work_ha_copy
&= ~HA_LATT
;
8079 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
8081 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
8082 * the only slow ring.
8084 status
= (work_ha_copy
&
8085 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
8086 status
>>= (4*LPFC_ELS_RING
);
8087 if (status
& HA_RXMASK
) {
8088 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8089 control
= readl(phba
->HCregaddr
);
8091 lpfc_debugfs_slow_ring_trc(phba
,
8092 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
8094 (uint32_t)phba
->sli
.slistat
.sli_intr
);
8096 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
8097 lpfc_debugfs_slow_ring_trc(phba
,
8099 "pwork:x%x hawork:x%x wait:x%x",
8100 phba
->work_ha
, work_ha_copy
,
8101 (uint32_t)((unsigned long)
8102 &phba
->work_waitq
));
8105 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
8106 writel(control
, phba
->HCregaddr
);
8107 readl(phba
->HCregaddr
); /* flush */
8110 lpfc_debugfs_slow_ring_trc(phba
,
8111 "ISR slow ring: pwork:"
8112 "x%x hawork:x%x wait:x%x",
8113 phba
->work_ha
, work_ha_copy
,
8114 (uint32_t)((unsigned long)
8115 &phba
->work_waitq
));
8117 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8120 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8121 if (work_ha_copy
& HA_ERATT
) {
8122 lpfc_sli_read_hs(phba
);
8124 * Check if there is a deferred error condition
8127 if ((HS_FFER1
& phba
->work_hs
) &&
8128 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
8129 HS_FFER6
| HS_FFER7
) & phba
->work_hs
)) {
8130 phba
->hba_flag
|= DEFER_ERATT
;
8131 /* Clear all interrupt enable conditions */
8132 writel(0, phba
->HCregaddr
);
8133 readl(phba
->HCregaddr
);
8137 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
8138 pmb
= phba
->sli
.mbox_active
;
8143 /* First check out the status word */
8144 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
8145 if (pmbox
->mbxOwner
!= OWN_HOST
) {
8146 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8148 * Stray Mailbox Interrupt, mbxCommand <cmd>
8149 * mbxStatus <status>
8151 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8153 "(%d):0304 Stray Mailbox "
8154 "Interrupt mbxCommand x%x "
8156 (vport
? vport
->vpi
: 0),
8159 /* clear mailbox attention bit */
8160 work_ha_copy
&= ~HA_MBATT
;
8162 phba
->sli
.mbox_active
= NULL
;
8163 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8164 phba
->last_completion_time
= jiffies
;
8165 del_timer(&phba
->sli
.mbox_tmo
);
8166 if (pmb
->mbox_cmpl
) {
8167 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
8169 if (pmb
->out_ext_byte_len
&&
8171 lpfc_sli_pcimem_bcopy(
8174 pmb
->out_ext_byte_len
);
8176 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8177 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8179 lpfc_debugfs_disc_trc(vport
,
8180 LPFC_DISC_TRC_MBOX_VPORT
,
8182 "status:x%x rpi:x%x",
8183 (uint32_t)pmbox
->mbxStatus
,
8184 pmbox
->un
.varWords
[0], 0);
8186 if (!pmbox
->mbxStatus
) {
8187 mp
= (struct lpfc_dmabuf
*)
8189 ndlp
= (struct lpfc_nodelist
*)
8192 /* Reg_LOGIN of dflt RPI was
8193 * successful. new lets get
8194 * rid of the RPI using the
8197 lpfc_unreg_login(phba
,
8199 pmbox
->un
.varWords
[0],
8202 lpfc_mbx_cmpl_dflt_rpi
;
8204 pmb
->context2
= ndlp
;
8206 rc
= lpfc_sli_issue_mbox(phba
,
8210 lpfc_printf_log(phba
,
8213 "0350 rc should have"
8215 if (rc
!= MBX_NOT_FINISHED
)
8216 goto send_current_mbox
;
8220 &phba
->pport
->work_port_lock
,
8222 phba
->pport
->work_port_events
&=
8224 spin_unlock_irqrestore(
8225 &phba
->pport
->work_port_lock
,
8227 lpfc_mbox_cmpl_put(phba
, pmb
);
8230 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8232 if ((work_ha_copy
& HA_MBATT
) &&
8233 (phba
->sli
.mbox_active
== NULL
)) {
8235 /* Process next mailbox command if there is one */
8237 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
8239 } while (rc
== MBX_NOT_FINISHED
);
8240 if (rc
!= MBX_SUCCESS
)
8241 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8242 LOG_SLI
, "0349 rc should be "
8246 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8247 phba
->work_ha
|= work_ha_copy
;
8248 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8249 lpfc_worker_wake_up(phba
);
8253 } /* lpfc_sli_sp_intr_handler */
8256 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
8257 * @irq: Interrupt number.
8258 * @dev_id: The device context pointer.
8260 * This function is directly called from the PCI layer as an interrupt
8261 * service routine when device with SLI-3 interface spec is enabled with
8262 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8263 * ring event in the HBA. However, when the device is enabled with either
8264 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8265 * device-level interrupt handler. When the PCI slot is in error recovery
8266 * or the HBA is undergoing initialization, the interrupt handler will not
8267 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8268 * the intrrupt context. This function is called without any lock held.
8269 * It gets the hbalock to access and update SLI data structures.
8271 * This function returns IRQ_HANDLED when interrupt is handled else it
8275 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
8277 struct lpfc_hba
*phba
;
8279 unsigned long status
;
8280 unsigned long iflag
;
8282 /* Get the driver's phba structure from the dev_id and
8283 * assume the HBA is not interrupting.
8285 phba
= (struct lpfc_hba
*) dev_id
;
8287 if (unlikely(!phba
))
8291 * Stuff needs to be attented to when this function is invoked as an
8292 * individual interrupt handler in MSI-X multi-message interrupt mode
8294 if (phba
->intr_type
== MSIX
) {
8295 /* Check device state for handling interrupt */
8296 if (lpfc_intr_state_check(phba
))
8298 /* Need to read HA REG for FCP ring and other ring events */
8299 ha_copy
= readl(phba
->HAregaddr
);
8300 /* Clear up only attention source related to fast-path */
8301 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8303 * If there is deferred error attention, do not check for
8306 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8307 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8310 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
8312 readl(phba
->HAregaddr
); /* flush */
8313 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8315 ha_copy
= phba
->ha_copy
;
8318 * Process all events on FCP ring. Take the optimized path for FCP IO.
8320 ha_copy
&= ~(phba
->work_ha_mask
);
8322 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8323 status
>>= (4*LPFC_FCP_RING
);
8324 if (status
& HA_RXMASK
)
8325 lpfc_sli_handle_fast_ring_event(phba
,
8326 &phba
->sli
.ring
[LPFC_FCP_RING
],
8329 if (phba
->cfg_multi_ring_support
== 2) {
8331 * Process all events on extra ring. Take the optimized path
8332 * for extra ring IO.
8334 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8335 status
>>= (4*LPFC_EXTRA_RING
);
8336 if (status
& HA_RXMASK
) {
8337 lpfc_sli_handle_fast_ring_event(phba
,
8338 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
8343 } /* lpfc_sli_fp_intr_handler */
8346 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
8347 * @irq: Interrupt number.
8348 * @dev_id: The device context pointer.
8350 * This function is the HBA device-level interrupt handler to device with
8351 * SLI-3 interface spec, called from the PCI layer when either MSI or
8352 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
8353 * requires driver attention. This function invokes the slow-path interrupt
8354 * attention handling function and fast-path interrupt attention handling
8355 * function in turn to process the relevant HBA attention events. This
8356 * function is called without any lock held. It gets the hbalock to access
8357 * and update SLI data structures.
8359 * This function returns IRQ_HANDLED when interrupt is handled, else it
8363 lpfc_sli_intr_handler(int irq
, void *dev_id
)
8365 struct lpfc_hba
*phba
;
8366 irqreturn_t sp_irq_rc
, fp_irq_rc
;
8367 unsigned long status1
, status2
;
8371 * Get the driver's phba structure from the dev_id and
8372 * assume the HBA is not interrupting.
8374 phba
= (struct lpfc_hba
*) dev_id
;
8376 if (unlikely(!phba
))
8379 /* Check device state for handling interrupt */
8380 if (lpfc_intr_state_check(phba
))
8383 spin_lock(&phba
->hbalock
);
8384 phba
->ha_copy
= readl(phba
->HAregaddr
);
8385 if (unlikely(!phba
->ha_copy
)) {
8386 spin_unlock(&phba
->hbalock
);
8388 } else if (phba
->ha_copy
& HA_ERATT
) {
8389 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
8390 /* ERATT polling has handled ERATT */
8391 phba
->ha_copy
&= ~HA_ERATT
;
8393 /* Indicate interrupt handler handles ERATT */
8394 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8398 * If there is deferred error attention, do not check for any interrupt.
8400 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8401 spin_unlock_irq(&phba
->hbalock
);
8405 /* Clear attention sources except link and error attentions */
8406 hc_copy
= readl(phba
->HCregaddr
);
8407 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
8408 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
8410 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
8411 writel(hc_copy
, phba
->HCregaddr
);
8412 readl(phba
->HAregaddr
); /* flush */
8413 spin_unlock(&phba
->hbalock
);
8416 * Invokes slow-path host attention interrupt handling as appropriate.
8419 /* status of events with mailbox and link attention */
8420 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
8422 /* status of events with ELS ring */
8423 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
8424 status2
>>= (4*LPFC_ELS_RING
);
8426 if (status1
|| (status2
& HA_RXMASK
))
8427 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
8429 sp_irq_rc
= IRQ_NONE
;
8432 * Invoke fast-path host attention interrupt handling as appropriate.
8435 /* status of events with FCP ring */
8436 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8437 status1
>>= (4*LPFC_FCP_RING
);
8439 /* status of events with extra ring */
8440 if (phba
->cfg_multi_ring_support
== 2) {
8441 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8442 status2
>>= (4*LPFC_EXTRA_RING
);
8446 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
8447 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
8449 fp_irq_rc
= IRQ_NONE
;
8451 /* Return device-level interrupt handling status */
8452 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
8453 } /* lpfc_sli_intr_handler */
8456 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
8457 * @phba: pointer to lpfc hba data structure.
8459 * This routine is invoked by the worker thread to process all the pending
8460 * SLI4 FCP abort XRI events.
8462 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
8464 struct lpfc_cq_event
*cq_event
;
8466 /* First, declare the fcp xri abort event has been handled */
8467 spin_lock_irq(&phba
->hbalock
);
8468 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
8469 spin_unlock_irq(&phba
->hbalock
);
8470 /* Now, handle all the fcp xri abort events */
8471 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
8472 /* Get the first event from the head of the event queue */
8473 spin_lock_irq(&phba
->hbalock
);
8474 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
8475 cq_event
, struct lpfc_cq_event
, list
);
8476 spin_unlock_irq(&phba
->hbalock
);
8477 /* Notify aborted XRI for FCP work queue */
8478 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
8479 /* Free the event processed back to the free pool */
8480 lpfc_sli4_cq_event_release(phba
, cq_event
);
8485 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
8486 * @phba: pointer to lpfc hba data structure.
8488 * This routine is invoked by the worker thread to process all the pending
8489 * SLI4 els abort xri events.
8491 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
8493 struct lpfc_cq_event
*cq_event
;
8495 /* First, declare the els xri abort event has been handled */
8496 spin_lock_irq(&phba
->hbalock
);
8497 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
8498 spin_unlock_irq(&phba
->hbalock
);
8499 /* Now, handle all the els xri abort events */
8500 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
8501 /* Get the first event from the head of the event queue */
8502 spin_lock_irq(&phba
->hbalock
);
8503 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
8504 cq_event
, struct lpfc_cq_event
, list
);
8505 spin_unlock_irq(&phba
->hbalock
);
8506 /* Notify aborted XRI for ELS work queue */
8507 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
8508 /* Free the event processed back to the free pool */
8509 lpfc_sli4_cq_event_release(phba
, cq_event
);
8514 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
8515 * @phba: pointer to lpfc hba data structure
8516 * @pIocbIn: pointer to the rspiocbq
8517 * @pIocbOut: pointer to the cmdiocbq
8518 * @wcqe: pointer to the complete wcqe
8520 * This routine transfers the fields of a command iocbq to a response iocbq
8521 * by copying all the IOCB fields from command iocbq and transferring the
8522 * completion status information from the complete wcqe.
8525 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
8526 struct lpfc_iocbq
*pIocbIn
,
8527 struct lpfc_iocbq
*pIocbOut
,
8528 struct lpfc_wcqe_complete
*wcqe
)
8530 unsigned long iflags
;
8531 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
8533 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
8534 sizeof(struct lpfc_iocbq
) - offset
);
8535 /* Map WCQE parameters into irspiocb parameters */
8536 pIocbIn
->iocb
.ulpStatus
= bf_get(lpfc_wcqe_c_status
, wcqe
);
8537 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
8538 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
8539 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
8540 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
8541 wcqe
->total_data_placed
;
8543 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
8545 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
8546 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
8549 /* Pick up HBA exchange busy condition */
8550 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
8551 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8552 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
8553 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8558 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
8559 * @phba: Pointer to HBA context object.
8560 * @wcqe: Pointer to work-queue completion queue entry.
8562 * This routine handles an ELS work-queue completion event and construct
8563 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
8564 * discovery engine to handle.
8566 * Return: Pointer to the receive IOCBQ, NULL otherwise.
8568 static struct lpfc_iocbq
*
8569 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
8570 struct lpfc_iocbq
*irspiocbq
)
8572 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8573 struct lpfc_iocbq
*cmdiocbq
;
8574 struct lpfc_wcqe_complete
*wcqe
;
8575 unsigned long iflags
;
8577 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
8578 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8579 pring
->stats
.iocb_event
++;
8580 /* Look up the ELS command IOCB and create pseudo response IOCB */
8581 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
8582 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8583 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8585 if (unlikely(!cmdiocbq
)) {
8586 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8587 "0386 ELS complete with no corresponding "
8588 "cmdiocb: iotag (%d)\n",
8589 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
8590 lpfc_sli_release_iocbq(phba
, irspiocbq
);
8594 /* Fake the irspiocbq and copy necessary response information */
8595 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
8601 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
8602 * @phba: Pointer to HBA context object.
8603 * @cqe: Pointer to mailbox completion queue entry.
8605 * This routine process a mailbox completion queue entry with asynchrous
8608 * Return: true if work posted to worker thread, otherwise false.
8611 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
8613 struct lpfc_cq_event
*cq_event
;
8614 unsigned long iflags
;
8616 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8617 "0392 Async Event: word0:x%x, word1:x%x, "
8618 "word2:x%x, word3:x%x\n", mcqe
->word0
,
8619 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
8621 /* Allocate a new internal CQ_EVENT entry */
8622 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
8624 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8625 "0394 Failed to allocate CQ_EVENT entry\n");
8629 /* Move the CQE into an asynchronous event entry */
8630 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
8631 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8632 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
8633 /* Set the async event flag */
8634 phba
->hba_flag
|= ASYNC_EVENT
;
8635 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8641 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
8642 * @phba: Pointer to HBA context object.
8643 * @cqe: Pointer to mailbox completion queue entry.
8645 * This routine process a mailbox completion queue entry with mailbox
8648 * Return: true if work posted to worker thread, otherwise false.
8651 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
8653 uint32_t mcqe_status
;
8654 MAILBOX_t
*mbox
, *pmbox
;
8655 struct lpfc_mqe
*mqe
;
8656 struct lpfc_vport
*vport
;
8657 struct lpfc_nodelist
*ndlp
;
8658 struct lpfc_dmabuf
*mp
;
8659 unsigned long iflags
;
8661 bool workposted
= false;
8664 /* If not a mailbox complete MCQE, out by checking mailbox consume */
8665 if (!bf_get(lpfc_trailer_completed
, mcqe
))
8666 goto out_no_mqe_complete
;
8668 /* Get the reference to the active mbox command */
8669 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8670 pmb
= phba
->sli
.mbox_active
;
8671 if (unlikely(!pmb
)) {
8672 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
8673 "1832 No pending MBOX command to handle\n");
8674 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8675 goto out_no_mqe_complete
;
8677 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8679 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
8683 /* Reset heartbeat timer */
8684 phba
->last_completion_time
= jiffies
;
8685 del_timer(&phba
->sli
.mbox_tmo
);
8687 /* Move mbox data to caller's mailbox region, do endian swapping */
8688 if (pmb
->mbox_cmpl
&& mbox
)
8689 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
8690 /* Set the mailbox status with SLI4 range 0x4000 */
8691 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
8692 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
)
8693 bf_set(lpfc_mqe_status
, mqe
,
8694 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
8696 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8697 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8698 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
8699 "MBOX dflt rpi: status:x%x rpi:x%x",
8701 pmbox
->un
.varWords
[0], 0);
8702 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
8703 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
8704 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
8705 /* Reg_LOGIN of dflt RPI was successful. Now lets get
8706 * RID of the PPI using the same mbox buffer.
8708 lpfc_unreg_login(phba
, vport
->vpi
,
8709 pmbox
->un
.varWords
[0], pmb
);
8710 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
8712 pmb
->context2
= ndlp
;
8714 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
8716 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8717 LOG_SLI
, "0385 rc should "
8718 "have been MBX_BUSY\n");
8719 if (rc
!= MBX_NOT_FINISHED
)
8720 goto send_current_mbox
;
8723 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
8724 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
8725 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
8727 /* There is mailbox completion work to do */
8728 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8729 __lpfc_mbox_cmpl_put(phba
, pmb
);
8730 phba
->work_ha
|= HA_MBATT
;
8731 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8735 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8736 /* Release the mailbox command posting token */
8737 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8738 /* Setting active mailbox pointer need to be in sync to flag clear */
8739 phba
->sli
.mbox_active
= NULL
;
8740 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8741 /* Wake up worker thread to post the next pending mailbox command */
8742 lpfc_worker_wake_up(phba
);
8743 out_no_mqe_complete
:
8744 if (bf_get(lpfc_trailer_consumed
, mcqe
))
8745 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
8750 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
8751 * @phba: Pointer to HBA context object.
8752 * @cqe: Pointer to mailbox completion queue entry.
8754 * This routine process a mailbox completion queue entry, it invokes the
8755 * proper mailbox complete handling or asynchrous event handling routine
8756 * according to the MCQE's async bit.
8758 * Return: true if work posted to worker thread, otherwise false.
8761 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
8763 struct lpfc_mcqe mcqe
;
8766 /* Copy the mailbox MCQE and convert endian order as needed */
8767 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
8769 /* Invoke the proper event handling routine */
8770 if (!bf_get(lpfc_trailer_async
, &mcqe
))
8771 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
8773 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
8778 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
8779 * @phba: Pointer to HBA context object.
8780 * @wcqe: Pointer to work-queue completion queue entry.
8782 * This routine handles an ELS work-queue completion event.
8784 * Return: true if work posted to worker thread, otherwise false.
8787 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
8788 struct lpfc_wcqe_complete
*wcqe
)
8790 struct lpfc_iocbq
*irspiocbq
;
8791 unsigned long iflags
;
8793 /* Get an irspiocbq for later ELS response processing use */
8794 irspiocbq
= lpfc_sli_get_iocbq(phba
);
8796 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8797 "0387 Failed to allocate an iocbq\n");
8801 /* Save off the slow-path queue event for work thread to process */
8802 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
8803 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8804 list_add_tail(&irspiocbq
->cq_event
.list
,
8805 &phba
->sli4_hba
.sp_queue_event
);
8806 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
8807 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8813 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
8814 * @phba: Pointer to HBA context object.
8815 * @wcqe: Pointer to work-queue completion queue entry.
8817 * This routine handles slow-path WQ entry comsumed event by invoking the
8818 * proper WQ release routine to the slow-path WQ.
8821 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
8822 struct lpfc_wcqe_release
*wcqe
)
8824 /* Check for the slow-path ELS work queue */
8825 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
8826 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
8827 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
8829 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8830 "2579 Slow-path wqe consume event carries "
8831 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
8832 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
8833 phba
->sli4_hba
.els_wq
->queue_id
);
8837 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
8838 * @phba: Pointer to HBA context object.
8839 * @cq: Pointer to a WQ completion queue.
8840 * @wcqe: Pointer to work-queue completion queue entry.
8842 * This routine handles an XRI abort event.
8844 * Return: true if work posted to worker thread, otherwise false.
8847 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
8848 struct lpfc_queue
*cq
,
8849 struct sli4_wcqe_xri_aborted
*wcqe
)
8851 bool workposted
= false;
8852 struct lpfc_cq_event
*cq_event
;
8853 unsigned long iflags
;
8855 /* Allocate a new internal CQ_EVENT entry */
8856 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
8858 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8859 "0602 Failed to allocate CQ_EVENT entry\n");
8863 /* Move the CQE into the proper xri abort event list */
8864 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
8865 switch (cq
->subtype
) {
8867 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8868 list_add_tail(&cq_event
->list
,
8869 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
8870 /* Set the fcp xri abort event flag */
8871 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
8872 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8876 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8877 list_add_tail(&cq_event
->list
,
8878 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
8879 /* Set the els xri abort event flag */
8880 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
8881 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8885 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8886 "0603 Invalid work queue CQE subtype (x%x)\n",
8895 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
8896 * @phba: Pointer to HBA context object.
8897 * @rcqe: Pointer to receive-queue completion queue entry.
8899 * This routine process a receive-queue completion queue entry.
8901 * Return: true if work posted to worker thread, otherwise false.
8904 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
8906 bool workposted
= false;
8907 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
8908 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
8909 struct hbq_dmabuf
*dma_buf
;
8911 unsigned long iflags
;
8913 if (bf_get(lpfc_rcqe_rq_id
, rcqe
) != hrq
->queue_id
)
8916 status
= bf_get(lpfc_rcqe_status
, rcqe
);
8918 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
8919 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8920 "2537 Receive Frame Truncated!!\n");
8921 case FC_STATUS_RQ_SUCCESS
:
8922 lpfc_sli4_rq_release(hrq
, drq
);
8923 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8924 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
8926 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8929 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
8930 /* save off the frame for the word thread to process */
8931 list_add_tail(&dma_buf
->cq_event
.list
,
8932 &phba
->sli4_hba
.sp_queue_event
);
8933 /* Frame received */
8934 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
8935 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8938 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
8939 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
8940 /* Post more buffers if possible */
8941 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8942 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
8943 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8952 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
8953 * @phba: Pointer to HBA context object.
8954 * @cq: Pointer to the completion queue.
8955 * @wcqe: Pointer to a completion queue entry.
8957 * This routine process a slow-path work-queue or recieve queue completion queue
8960 * Return: true if work posted to worker thread, otherwise false.
8963 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
8964 struct lpfc_cqe
*cqe
)
8966 struct lpfc_cqe cqevt
;
8967 bool workposted
= false;
8969 /* Copy the work queue CQE and convert endian order if needed */
8970 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
8972 /* Check and process for different type of WCQE and dispatch */
8973 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
8974 case CQE_CODE_COMPL_WQE
:
8975 /* Process the WQ/RQ complete event */
8976 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
8977 (struct lpfc_wcqe_complete
*)&cqevt
);
8979 case CQE_CODE_RELEASE_WQE
:
8980 /* Process the WQ release event */
8981 lpfc_sli4_sp_handle_rel_wcqe(phba
,
8982 (struct lpfc_wcqe_release
*)&cqevt
);
8984 case CQE_CODE_XRI_ABORTED
:
8985 /* Process the WQ XRI abort event */
8986 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
8987 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
8989 case CQE_CODE_RECEIVE
:
8990 /* Process the RQ event */
8991 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
8992 (struct lpfc_rcqe
*)&cqevt
);
8995 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8996 "0388 Not a valid WCQE code: x%x\n",
8997 bf_get(lpfc_cqe_code
, &cqevt
));
9004 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
9005 * @phba: Pointer to HBA context object.
9006 * @eqe: Pointer to fast-path event queue entry.
9008 * This routine process a event queue entry from the slow-path event queue.
9009 * It will check the MajorCode and MinorCode to determine this is for a
9010 * completion event on a completion queue, if not, an error shall be logged
9011 * and just return. Otherwise, it will get to the corresponding completion
9012 * queue and process all the entries on that completion queue, rearm the
9013 * completion queue, and then return.
9017 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
9019 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
9020 struct lpfc_cqe
*cqe
;
9021 bool workposted
= false;
9025 if (bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0) {
9026 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9027 "0359 Not a valid slow-path completion "
9028 "event: majorcode=x%x, minorcode=x%x\n",
9029 bf_get_le32(lpfc_eqe_major_code
, eqe
),
9030 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
9034 /* Get the reference to the corresponding CQ */
9035 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
9037 /* Search for completion queue pointer matching this cqid */
9038 speq
= phba
->sli4_hba
.sp_eq
;
9039 list_for_each_entry(childq
, &speq
->child_list
, list
) {
9040 if (childq
->queue_id
== cqid
) {
9045 if (unlikely(!cq
)) {
9046 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9047 "0365 Slow-path CQ identifier (%d) does "
9048 "not exist\n", cqid
);
9052 /* Process all the entries to the CQ */
9055 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9056 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
9057 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9058 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9062 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9063 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
, cqe
);
9064 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9065 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9069 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9070 "0370 Invalid completion queue type (%d)\n",
9075 /* Catch the no cq entry condition, log an error */
9076 if (unlikely(ecount
== 0))
9077 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9078 "0371 No entry from the CQ: identifier "
9079 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
9081 /* In any case, flash and re-arm the RCQ */
9082 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9084 /* wake up worker thread if there are works to be done */
9086 lpfc_worker_wake_up(phba
);
9090 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
9091 * @eqe: Pointer to fast-path completion queue entry.
9093 * This routine process a fast-path work queue completion entry from fast-path
9094 * event queue for FCP command response completion.
9097 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
9098 struct lpfc_wcqe_complete
*wcqe
)
9100 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
9101 struct lpfc_iocbq
*cmdiocbq
;
9102 struct lpfc_iocbq irspiocbq
;
9103 unsigned long iflags
;
9105 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9106 pring
->stats
.iocb_event
++;
9107 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9109 /* Check for response status */
9110 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
9111 /* If resource errors reported from HBA, reduce queue
9112 * depth of the SCSI device.
9114 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
9115 IOSTAT_LOCAL_REJECT
) &&
9116 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
9117 phba
->lpfc_rampdown_queue_depth(phba
);
9119 /* Log the error status */
9120 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9121 "0373 FCP complete error: status=x%x, "
9122 "hw_status=x%x, total_data_specified=%d, "
9123 "parameter=x%x, word3=x%x\n",
9124 bf_get(lpfc_wcqe_c_status
, wcqe
),
9125 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
9126 wcqe
->total_data_placed
, wcqe
->parameter
,
9130 /* Look up the FCP command IOCB and create pseudo response IOCB */
9131 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9132 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
9133 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9134 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9135 if (unlikely(!cmdiocbq
)) {
9136 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9137 "0374 FCP complete with no corresponding "
9138 "cmdiocb: iotag (%d)\n",
9139 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9142 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
9143 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9144 "0375 FCP cmdiocb not callback function "
9146 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9150 /* Fake the irspiocb and copy necessary response information */
9151 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
9153 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
9154 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9155 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
9156 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9159 /* Pass the cmd_iocb and the rsp state to the upper layer */
9160 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
9164 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
9165 * @phba: Pointer to HBA context object.
9166 * @cq: Pointer to completion queue.
9167 * @wcqe: Pointer to work-queue completion queue entry.
9169 * This routine handles an fast-path WQ entry comsumed event by invoking the
9170 * proper WQ release routine to the slow-path WQ.
9173 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9174 struct lpfc_wcqe_release
*wcqe
)
9176 struct lpfc_queue
*childwq
;
9177 bool wqid_matched
= false;
9180 /* Check for fast-path FCP work queue release */
9181 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
9182 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
9183 if (childwq
->queue_id
== fcp_wqid
) {
9184 lpfc_sli4_wq_release(childwq
,
9185 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
9186 wqid_matched
= true;
9190 /* Report warning log message if no match found */
9191 if (wqid_matched
!= true)
9192 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9193 "2580 Fast-path wqe consume event carries "
9194 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
9198 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
9199 * @cq: Pointer to the completion queue.
9200 * @eqe: Pointer to fast-path completion queue entry.
9202 * This routine process a fast-path work queue completion entry from fast-path
9203 * event queue for FCP command response completion.
9206 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9207 struct lpfc_cqe
*cqe
)
9209 struct lpfc_wcqe_release wcqe
;
9210 bool workposted
= false;
9212 /* Copy the work queue CQE and convert endian order if needed */
9213 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
9215 /* Check and process for different type of WCQE and dispatch */
9216 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
9217 case CQE_CODE_COMPL_WQE
:
9218 /* Process the WQ complete event */
9219 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
9220 (struct lpfc_wcqe_complete
*)&wcqe
);
9222 case CQE_CODE_RELEASE_WQE
:
9223 /* Process the WQ release event */
9224 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
9225 (struct lpfc_wcqe_release
*)&wcqe
);
9227 case CQE_CODE_XRI_ABORTED
:
9228 /* Process the WQ XRI abort event */
9229 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
9230 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
9233 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9234 "0144 Not a valid WCQE code: x%x\n",
9235 bf_get(lpfc_wcqe_c_code
, &wcqe
));
9242 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
9243 * @phba: Pointer to HBA context object.
9244 * @eqe: Pointer to fast-path event queue entry.
9246 * This routine process a event queue entry from the fast-path event queue.
9247 * It will check the MajorCode and MinorCode to determine this is for a
9248 * completion event on a completion queue, if not, an error shall be logged
9249 * and just return. Otherwise, it will get to the corresponding completion
9250 * queue and process all the entries on the completion queue, rearm the
9251 * completion queue, and then return.
9254 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
9257 struct lpfc_queue
*cq
;
9258 struct lpfc_cqe
*cqe
;
9259 bool workposted
= false;
9263 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
9264 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9265 "0366 Not a valid fast-path completion "
9266 "event: majorcode=x%x, minorcode=x%x\n",
9267 bf_get_le32(lpfc_eqe_major_code
, eqe
),
9268 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
9272 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
9273 if (unlikely(!cq
)) {
9274 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9275 "0367 Fast-path completion queue does not "
9280 /* Get the reference to the corresponding CQ */
9281 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
9282 if (unlikely(cqid
!= cq
->queue_id
)) {
9283 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9284 "0368 Miss-matched fast-path completion "
9285 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
9286 cqid
, cq
->queue_id
);
9290 /* Process all the entries to the CQ */
9291 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9292 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
9293 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9294 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9297 /* Catch the no cq entry condition */
9298 if (unlikely(ecount
== 0))
9299 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9300 "0369 No entry from fast-path completion "
9301 "queue fcpcqid=%d\n", cq
->queue_id
);
9303 /* In any case, flash and re-arm the CQ */
9304 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9306 /* wake up worker thread if there are works to be done */
9308 lpfc_worker_wake_up(phba
);
9312 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
9314 struct lpfc_eqe
*eqe
;
9316 /* walk all the EQ entries and drop on the floor */
9317 while ((eqe
= lpfc_sli4_eq_get(eq
)))
9320 /* Clear and re-arm the EQ */
9321 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
9325 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
9326 * @irq: Interrupt number.
9327 * @dev_id: The device context pointer.
9329 * This function is directly called from the PCI layer as an interrupt
9330 * service routine when device with SLI-4 interface spec is enabled with
9331 * MSI-X multi-message interrupt mode and there are slow-path events in
9332 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9333 * interrupt mode, this function is called as part of the device-level
9334 * interrupt handler. When the PCI slot is in error recovery or the HBA is
9335 * undergoing initialization, the interrupt handler will not process the
9336 * interrupt. The link attention and ELS ring attention events are handled
9337 * by the worker thread. The interrupt handler signals the worker thread
9338 * and returns for these events. This function is called without any lock
9339 * held. It gets the hbalock to access and update SLI data structures.
9341 * This function returns IRQ_HANDLED when interrupt is handled else it
9345 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
9347 struct lpfc_hba
*phba
;
9348 struct lpfc_queue
*speq
;
9349 struct lpfc_eqe
*eqe
;
9350 unsigned long iflag
;
9354 * Get the driver's phba structure from the dev_id
9356 phba
= (struct lpfc_hba
*)dev_id
;
9358 if (unlikely(!phba
))
9361 /* Get to the EQ struct associated with this vector */
9362 speq
= phba
->sli4_hba
.sp_eq
;
9364 /* Check device state for handling interrupt */
9365 if (unlikely(lpfc_intr_state_check(phba
))) {
9366 /* Check again for link_state with lock held */
9367 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9368 if (phba
->link_state
< LPFC_LINK_DOWN
)
9369 /* Flush, clear interrupt, and rearm the EQ */
9370 lpfc_sli4_eq_flush(phba
, speq
);
9371 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9376 * Process all the event on FCP slow-path EQ
9378 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
9379 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
9380 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9381 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
9384 /* Always clear and re-arm the slow-path EQ */
9385 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
9387 /* Catch the no cq entry condition */
9388 if (unlikely(ecount
== 0)) {
9389 if (phba
->intr_type
== MSIX
)
9390 /* MSI-X treated interrupt served as no EQ share INT */
9391 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9392 "0357 MSI-X interrupt with no EQE\n");
9394 /* Non MSI-X treated on interrupt as EQ share INT */
9399 } /* lpfc_sli4_sp_intr_handler */
9402 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
9403 * @irq: Interrupt number.
9404 * @dev_id: The device context pointer.
9406 * This function is directly called from the PCI layer as an interrupt
9407 * service routine when device with SLI-4 interface spec is enabled with
9408 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
9409 * ring event in the HBA. However, when the device is enabled with either
9410 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
9411 * device-level interrupt handler. When the PCI slot is in error recovery
9412 * or the HBA is undergoing initialization, the interrupt handler will not
9413 * process the interrupt. The SCSI FCP fast-path ring event are handled in
9414 * the intrrupt context. This function is called without any lock held.
9415 * It gets the hbalock to access and update SLI data structures. Note that,
9416 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
9417 * equal to that of FCP CQ index.
9419 * This function returns IRQ_HANDLED when interrupt is handled else it
9423 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
9425 struct lpfc_hba
*phba
;
9426 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
9427 struct lpfc_queue
*fpeq
;
9428 struct lpfc_eqe
*eqe
;
9429 unsigned long iflag
;
9433 /* Get the driver's phba structure from the dev_id */
9434 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
9435 phba
= fcp_eq_hdl
->phba
;
9436 fcp_eqidx
= fcp_eq_hdl
->idx
;
9438 if (unlikely(!phba
))
9441 /* Get to the EQ struct associated with this vector */
9442 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
9444 /* Check device state for handling interrupt */
9445 if (unlikely(lpfc_intr_state_check(phba
))) {
9446 /* Check again for link_state with lock held */
9447 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9448 if (phba
->link_state
< LPFC_LINK_DOWN
)
9449 /* Flush, clear interrupt, and rearm the EQ */
9450 lpfc_sli4_eq_flush(phba
, fpeq
);
9451 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9456 * Process all the event on FCP fast-path EQ
9458 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9459 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
9460 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9461 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
9464 /* Always clear and re-arm the fast-path EQ */
9465 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
9467 if (unlikely(ecount
== 0)) {
9468 if (phba
->intr_type
== MSIX
)
9469 /* MSI-X treated interrupt served as no EQ share INT */
9470 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9471 "0358 MSI-X interrupt with no EQE\n");
9473 /* Non MSI-X treated on interrupt as EQ share INT */
9478 } /* lpfc_sli4_fp_intr_handler */
9481 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
9482 * @irq: Interrupt number.
9483 * @dev_id: The device context pointer.
9485 * This function is the device-level interrupt handler to device with SLI-4
9486 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
9487 * interrupt mode is enabled and there is an event in the HBA which requires
9488 * driver attention. This function invokes the slow-path interrupt attention
9489 * handling function and fast-path interrupt attention handling function in
9490 * turn to process the relevant HBA attention events. This function is called
9491 * without any lock held. It gets the hbalock to access and update SLI data
9494 * This function returns IRQ_HANDLED when interrupt is handled, else it
9498 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
9500 struct lpfc_hba
*phba
;
9501 irqreturn_t sp_irq_rc
, fp_irq_rc
;
9502 bool fp_handled
= false;
9505 /* Get the driver's phba structure from the dev_id */
9506 phba
= (struct lpfc_hba
*)dev_id
;
9508 if (unlikely(!phba
))
9512 * Invokes slow-path host attention interrupt handling as appropriate.
9514 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
9517 * Invoke fast-path host attention interrupt handling as appropriate.
9519 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
9520 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
9521 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
9522 if (fp_irq_rc
== IRQ_HANDLED
)
9526 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
9527 } /* lpfc_sli4_intr_handler */
9530 * lpfc_sli4_queue_free - free a queue structure and associated memory
9531 * @queue: The queue structure to free.
9533 * This function frees a queue structure and the DMAable memeory used for
9534 * the host resident queue. This function must be called after destroying the
9538 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
9540 struct lpfc_dmabuf
*dmabuf
;
9545 while (!list_empty(&queue
->page_list
)) {
9546 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
9548 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
9549 dmabuf
->virt
, dmabuf
->phys
);
9557 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
9558 * @phba: The HBA that this queue is being created on.
9559 * @entry_size: The size of each queue entry for this queue.
9560 * @entry count: The number of entries that this queue will handle.
9562 * This function allocates a queue structure and the DMAable memory used for
9563 * the host resident queue. This function must be called before creating the
9567 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
9568 uint32_t entry_count
)
9570 struct lpfc_queue
*queue
;
9571 struct lpfc_dmabuf
*dmabuf
;
9572 int x
, total_qe_count
;
9574 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9576 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9577 hw_page_size
= SLI4_PAGE_SIZE
;
9579 queue
= kzalloc(sizeof(struct lpfc_queue
) +
9580 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
9583 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
9584 hw_page_size
))/hw_page_size
;
9585 INIT_LIST_HEAD(&queue
->list
);
9586 INIT_LIST_HEAD(&queue
->page_list
);
9587 INIT_LIST_HEAD(&queue
->child_list
);
9588 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
9589 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
9592 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
9593 hw_page_size
, &dmabuf
->phys
,
9595 if (!dmabuf
->virt
) {
9599 memset(dmabuf
->virt
, 0, hw_page_size
);
9600 dmabuf
->buffer_tag
= x
;
9601 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
9602 /* initialize queue's entry array */
9603 dma_pointer
= dmabuf
->virt
;
9604 for (; total_qe_count
< entry_count
&&
9605 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
9606 total_qe_count
++, dma_pointer
+= entry_size
) {
9607 queue
->qe
[total_qe_count
].address
= dma_pointer
;
9610 queue
->entry_size
= entry_size
;
9611 queue
->entry_count
= entry_count
;
9616 lpfc_sli4_queue_free(queue
);
9621 * lpfc_eq_create - Create an Event Queue on the HBA
9622 * @phba: HBA structure that indicates port to create a queue on.
9623 * @eq: The queue structure to use to create the event queue.
9624 * @imax: The maximum interrupt per second limit.
9626 * This function creates an event queue, as detailed in @eq, on a port,
9627 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
9629 * The @phba struct is used to send mailbox command to HBA. The @eq struct
9630 * is used to get the entry count and entry size that are necessary to
9631 * determine the number of pages to allocate and use for this queue. This
9632 * function will send the EQ_CREATE mailbox command to the HBA to setup the
9633 * event queue. This function is asynchronous and will wait for the mailbox
9634 * command to finish before continuing.
9636 * On success this function will return a zero. If unable to allocate enough
9637 * memory this function will return ENOMEM. If the queue create mailbox command
9638 * fails this function will return ENXIO.
9641 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
9643 struct lpfc_mbx_eq_create
*eq_create
;
9645 int rc
, length
, status
= 0;
9646 struct lpfc_dmabuf
*dmabuf
;
9647 uint32_t shdr_status
, shdr_add_status
;
9648 union lpfc_sli4_cfg_shdr
*shdr
;
9650 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9652 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9653 hw_page_size
= SLI4_PAGE_SIZE
;
9655 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9658 length
= (sizeof(struct lpfc_mbx_eq_create
) -
9659 sizeof(struct lpfc_sli4_cfg_mhdr
));
9660 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9661 LPFC_MBOX_OPCODE_EQ_CREATE
,
9662 length
, LPFC_SLI4_MBX_EMBED
);
9663 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
9664 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
9666 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
9668 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
9669 /* Calculate delay multiper from maximum interrupt per second */
9670 dmult
= LPFC_DMULT_CONST
/imax
- 1;
9671 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
9673 switch (eq
->entry_count
) {
9675 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9676 "0360 Unsupported EQ count. (%d)\n",
9678 if (eq
->entry_count
< 256)
9680 /* otherwise default to smallest count (drop through) */
9682 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9686 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9690 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9694 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9698 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
9702 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
9703 memset(dmabuf
->virt
, 0, hw_page_size
);
9704 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9705 putPaddrLow(dmabuf
->phys
);
9706 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9707 putPaddrHigh(dmabuf
->phys
);
9709 mbox
->vport
= phba
->pport
;
9710 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
9711 mbox
->context1
= NULL
;
9712 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9713 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
9714 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9715 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9716 if (shdr_status
|| shdr_add_status
|| rc
) {
9717 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9718 "2500 EQ_CREATE mailbox failed with "
9719 "status x%x add_status x%x, mbx status x%x\n",
9720 shdr_status
, shdr_add_status
, rc
);
9724 eq
->subtype
= LPFC_NONE
;
9725 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
9726 if (eq
->queue_id
== 0xFFFF)
9731 mempool_free(mbox
, phba
->mbox_mem_pool
);
9736 * lpfc_cq_create - Create a Completion Queue on the HBA
9737 * @phba: HBA structure that indicates port to create a queue on.
9738 * @cq: The queue structure to use to create the completion queue.
9739 * @eq: The event queue to bind this completion queue to.
9741 * This function creates a completion queue, as detailed in @wq, on a port,
9742 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
9744 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9745 * is used to get the entry count and entry size that are necessary to
9746 * determine the number of pages to allocate and use for this queue. The @eq
9747 * is used to indicate which event queue to bind this completion queue to. This
9748 * function will send the CQ_CREATE mailbox command to the HBA to setup the
9749 * completion queue. This function is asynchronous and will wait for the mailbox
9750 * command to finish before continuing.
9752 * On success this function will return a zero. If unable to allocate enough
9753 * memory this function will return ENOMEM. If the queue create mailbox command
9754 * fails this function will return ENXIO.
9757 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9758 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
9760 struct lpfc_mbx_cq_create
*cq_create
;
9761 struct lpfc_dmabuf
*dmabuf
;
9763 int rc
, length
, status
= 0;
9764 uint32_t shdr_status
, shdr_add_status
;
9765 union lpfc_sli4_cfg_shdr
*shdr
;
9766 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9768 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9769 hw_page_size
= SLI4_PAGE_SIZE
;
9772 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9775 length
= (sizeof(struct lpfc_mbx_cq_create
) -
9776 sizeof(struct lpfc_sli4_cfg_mhdr
));
9777 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9778 LPFC_MBOX_OPCODE_CQ_CREATE
,
9779 length
, LPFC_SLI4_MBX_EMBED
);
9780 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
9781 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
9783 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
9784 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
9785 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
, eq
->queue_id
);
9786 switch (cq
->entry_count
) {
9788 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9789 "0361 Unsupported CQ count. (%d)\n",
9791 if (cq
->entry_count
< 256)
9793 /* otherwise default to smallest count (drop through) */
9795 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9799 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9803 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
9807 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
9808 memset(dmabuf
->virt
, 0, hw_page_size
);
9809 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9810 putPaddrLow(dmabuf
->phys
);
9811 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9812 putPaddrHigh(dmabuf
->phys
);
9814 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9816 /* The IOCTL status is embedded in the mailbox subheader. */
9817 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
9818 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9819 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9820 if (shdr_status
|| shdr_add_status
|| rc
) {
9821 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9822 "2501 CQ_CREATE mailbox failed with "
9823 "status x%x add_status x%x, mbx status x%x\n",
9824 shdr_status
, shdr_add_status
, rc
);
9828 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
9829 if (cq
->queue_id
== 0xFFFF) {
9833 /* link the cq onto the parent eq child list */
9834 list_add_tail(&cq
->list
, &eq
->child_list
);
9835 /* Set up completion queue's type and subtype */
9837 cq
->subtype
= subtype
;
9838 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
9843 mempool_free(mbox
, phba
->mbox_mem_pool
);
9848 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
9849 * @phba: HBA structure that indicates port to create a queue on.
9850 * @mq: The queue structure to use to create the mailbox queue.
9851 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
9852 * @cq: The completion queue to associate with this cq.
9854 * This function provides failback (fb) functionality when the
9855 * mq_create_ext fails on older FW generations. It's purpose is identical
9856 * to mq_create_ext otherwise.
9858 * This routine cannot fail as all attributes were previously accessed and
9859 * initialized in mq_create_ext.
9862 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
9863 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
9865 struct lpfc_mbx_mq_create
*mq_create
;
9866 struct lpfc_dmabuf
*dmabuf
;
9869 length
= (sizeof(struct lpfc_mbx_mq_create
) -
9870 sizeof(struct lpfc_sli4_cfg_mhdr
));
9871 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9872 LPFC_MBOX_OPCODE_MQ_CREATE
,
9873 length
, LPFC_SLI4_MBX_EMBED
);
9874 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
9875 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
9877 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
9879 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
9880 switch (mq
->entry_count
) {
9882 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9886 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9890 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9894 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
9898 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
9899 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9900 putPaddrLow(dmabuf
->phys
);
9901 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9902 putPaddrHigh(dmabuf
->phys
);
9907 * lpfc_mq_create - Create a mailbox Queue on the HBA
9908 * @phba: HBA structure that indicates port to create a queue on.
9909 * @mq: The queue structure to use to create the mailbox queue.
9910 * @cq: The completion queue to associate with this cq.
9911 * @subtype: The queue's subtype.
9913 * This function creates a mailbox queue, as detailed in @mq, on a port,
9914 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
9916 * The @phba struct is used to send mailbox command to HBA. The @cq struct
9917 * is used to get the entry count and entry size that are necessary to
9918 * determine the number of pages to allocate and use for this queue. This
9919 * function will send the MQ_CREATE mailbox command to the HBA to setup the
9920 * mailbox queue. This function is asynchronous and will wait for the mailbox
9921 * command to finish before continuing.
9923 * On success this function will return a zero. If unable to allocate enough
9924 * memory this function will return ENOMEM. If the queue create mailbox command
9925 * fails this function will return ENXIO.
9928 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
9929 struct lpfc_queue
*cq
, uint32_t subtype
)
9931 struct lpfc_mbx_mq_create
*mq_create
;
9932 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
9933 struct lpfc_dmabuf
*dmabuf
;
9935 int rc
, length
, status
= 0;
9936 uint32_t shdr_status
, shdr_add_status
;
9937 union lpfc_sli4_cfg_shdr
*shdr
;
9938 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
9940 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
9941 hw_page_size
= SLI4_PAGE_SIZE
;
9943 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9946 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
9947 sizeof(struct lpfc_sli4_cfg_mhdr
));
9948 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9949 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
9950 length
, LPFC_SLI4_MBX_EMBED
);
9952 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
9953 bf_set(lpfc_mbx_mq_create_ext_num_pages
, &mq_create_ext
->u
.request
,
9955 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
, &mq_create_ext
->u
.request
,
9957 bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste
,
9958 &mq_create_ext
->u
.request
, 1);
9959 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
9960 &mq_create_ext
->u
.request
, 1);
9961 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
9963 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
9964 switch (mq
->entry_count
) {
9966 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9967 "0362 Unsupported MQ count. (%d)\n",
9969 if (mq
->entry_count
< 16)
9971 /* otherwise default to smallest count (drop through) */
9973 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9977 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9981 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9985 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
9989 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
9990 memset(dmabuf
->virt
, 0, hw_page_size
);
9991 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
9992 putPaddrLow(dmabuf
->phys
);
9993 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
9994 putPaddrHigh(dmabuf
->phys
);
9996 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
9997 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
9998 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
9999 &mq_create_ext
->u
.response
);
10000 if (rc
!= MBX_SUCCESS
) {
10001 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10002 "2795 MQ_CREATE_EXT failed with "
10003 "status x%x. Failback to MQ_CREATE.\n",
10005 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
10006 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
10007 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10008 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
10009 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
10010 &mq_create
->u
.response
);
10013 /* The IOCTL status is embedded in the mailbox subheader. */
10014 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10015 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10016 if (shdr_status
|| shdr_add_status
|| rc
) {
10017 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10018 "2502 MQ_CREATE mailbox failed with "
10019 "status x%x add_status x%x, mbx status x%x\n",
10020 shdr_status
, shdr_add_status
, rc
);
10024 if (mq
->queue_id
== 0xFFFF) {
10028 mq
->type
= LPFC_MQ
;
10029 mq
->subtype
= subtype
;
10030 mq
->host_index
= 0;
10033 /* link the mq onto the parent cq child list */
10034 list_add_tail(&mq
->list
, &cq
->child_list
);
10036 mempool_free(mbox
, phba
->mbox_mem_pool
);
10041 * lpfc_wq_create - Create a Work Queue on the HBA
10042 * @phba: HBA structure that indicates port to create a queue on.
10043 * @wq: The queue structure to use to create the work queue.
10044 * @cq: The completion queue to bind this work queue to.
10045 * @subtype: The subtype of the work queue indicating its functionality.
10047 * This function creates a work queue, as detailed in @wq, on a port, described
10048 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
10050 * The @phba struct is used to send mailbox command to HBA. The @wq struct
10051 * is used to get the entry count and entry size that are necessary to
10052 * determine the number of pages to allocate and use for this queue. The @cq
10053 * is used to indicate which completion queue to bind this work queue to. This
10054 * function will send the WQ_CREATE mailbox command to the HBA to setup the
10055 * work queue. This function is asynchronous and will wait for the mailbox
10056 * command to finish before continuing.
10058 * On success this function will return a zero. If unable to allocate enough
10059 * memory this function will return ENOMEM. If the queue create mailbox command
10060 * fails this function will return ENXIO.
10063 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
10064 struct lpfc_queue
*cq
, uint32_t subtype
)
10066 struct lpfc_mbx_wq_create
*wq_create
;
10067 struct lpfc_dmabuf
*dmabuf
;
10068 LPFC_MBOXQ_t
*mbox
;
10069 int rc
, length
, status
= 0;
10070 uint32_t shdr_status
, shdr_add_status
;
10071 union lpfc_sli4_cfg_shdr
*shdr
;
10072 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10074 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10075 hw_page_size
= SLI4_PAGE_SIZE
;
10077 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10080 length
= (sizeof(struct lpfc_mbx_wq_create
) -
10081 sizeof(struct lpfc_sli4_cfg_mhdr
));
10082 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10083 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
10084 length
, LPFC_SLI4_MBX_EMBED
);
10085 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
10086 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
10088 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
10090 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
10091 memset(dmabuf
->virt
, 0, hw_page_size
);
10092 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10093 putPaddrLow(dmabuf
->phys
);
10094 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10095 putPaddrHigh(dmabuf
->phys
);
10097 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10098 /* The IOCTL status is embedded in the mailbox subheader. */
10099 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
10100 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10101 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10102 if (shdr_status
|| shdr_add_status
|| rc
) {
10103 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10104 "2503 WQ_CREATE mailbox failed with "
10105 "status x%x add_status x%x, mbx status x%x\n",
10106 shdr_status
, shdr_add_status
, rc
);
10110 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
10111 if (wq
->queue_id
== 0xFFFF) {
10115 wq
->type
= LPFC_WQ
;
10116 wq
->subtype
= subtype
;
10117 wq
->host_index
= 0;
10120 /* link the wq onto the parent cq child list */
10121 list_add_tail(&wq
->list
, &cq
->child_list
);
10123 mempool_free(mbox
, phba
->mbox_mem_pool
);
10128 * lpfc_rq_create - Create a Receive Queue on the HBA
10129 * @phba: HBA structure that indicates port to create a queue on.
10130 * @hrq: The queue structure to use to create the header receive queue.
10131 * @drq: The queue structure to use to create the data receive queue.
10132 * @cq: The completion queue to bind this work queue to.
10134 * This function creates a receive buffer queue pair , as detailed in @hrq and
10135 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
10138 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
10139 * struct is used to get the entry count that is necessary to determine the
10140 * number of pages to use for this queue. The @cq is used to indicate which
10141 * completion queue to bind received buffers that are posted to these queues to.
10142 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
10143 * receive queue pair. This function is asynchronous and will wait for the
10144 * mailbox command to finish before continuing.
10146 * On success this function will return a zero. If unable to allocate enough
10147 * memory this function will return ENOMEM. If the queue create mailbox command
10148 * fails this function will return ENXIO.
10151 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
10152 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
10154 struct lpfc_mbx_rq_create
*rq_create
;
10155 struct lpfc_dmabuf
*dmabuf
;
10156 LPFC_MBOXQ_t
*mbox
;
10157 int rc
, length
, status
= 0;
10158 uint32_t shdr_status
, shdr_add_status
;
10159 union lpfc_sli4_cfg_shdr
*shdr
;
10160 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10162 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10163 hw_page_size
= SLI4_PAGE_SIZE
;
10165 if (hrq
->entry_count
!= drq
->entry_count
)
10167 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10170 length
= (sizeof(struct lpfc_mbx_rq_create
) -
10171 sizeof(struct lpfc_sli4_cfg_mhdr
));
10172 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10173 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
10174 length
, LPFC_SLI4_MBX_EMBED
);
10175 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
10176 switch (hrq
->entry_count
) {
10178 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10179 "2535 Unsupported RQ count. (%d)\n",
10181 if (hrq
->entry_count
< 512)
10183 /* otherwise default to smallest count (drop through) */
10185 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10186 LPFC_RQ_RING_SIZE_512
);
10189 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10190 LPFC_RQ_RING_SIZE_1024
);
10193 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10194 LPFC_RQ_RING_SIZE_2048
);
10197 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10198 LPFC_RQ_RING_SIZE_4096
);
10201 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
10203 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
10205 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
10206 LPFC_HDR_BUF_SIZE
);
10207 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
10208 memset(dmabuf
->virt
, 0, hw_page_size
);
10209 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10210 putPaddrLow(dmabuf
->phys
);
10211 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10212 putPaddrHigh(dmabuf
->phys
);
10214 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10215 /* The IOCTL status is embedded in the mailbox subheader. */
10216 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
10217 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10218 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10219 if (shdr_status
|| shdr_add_status
|| rc
) {
10220 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10221 "2504 RQ_CREATE mailbox failed with "
10222 "status x%x add_status x%x, mbx status x%x\n",
10223 shdr_status
, shdr_add_status
, rc
);
10227 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
10228 if (hrq
->queue_id
== 0xFFFF) {
10232 hrq
->type
= LPFC_HRQ
;
10233 hrq
->subtype
= subtype
;
10234 hrq
->host_index
= 0;
10235 hrq
->hba_index
= 0;
10237 /* now create the data queue */
10238 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10239 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
10240 length
, LPFC_SLI4_MBX_EMBED
);
10241 switch (drq
->entry_count
) {
10243 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10244 "2536 Unsupported RQ count. (%d)\n",
10246 if (drq
->entry_count
< 512)
10248 /* otherwise default to smallest count (drop through) */
10250 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10251 LPFC_RQ_RING_SIZE_512
);
10254 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10255 LPFC_RQ_RING_SIZE_1024
);
10258 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10259 LPFC_RQ_RING_SIZE_2048
);
10262 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10263 LPFC_RQ_RING_SIZE_4096
);
10266 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
10268 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
10270 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
10271 LPFC_DATA_BUF_SIZE
);
10272 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
10273 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10274 putPaddrLow(dmabuf
->phys
);
10275 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10276 putPaddrHigh(dmabuf
->phys
);
10278 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10279 /* The IOCTL status is embedded in the mailbox subheader. */
10280 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
10281 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10282 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10283 if (shdr_status
|| shdr_add_status
|| rc
) {
10287 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
10288 if (drq
->queue_id
== 0xFFFF) {
10292 drq
->type
= LPFC_DRQ
;
10293 drq
->subtype
= subtype
;
10294 drq
->host_index
= 0;
10295 drq
->hba_index
= 0;
10297 /* link the header and data RQs onto the parent cq child list */
10298 list_add_tail(&hrq
->list
, &cq
->child_list
);
10299 list_add_tail(&drq
->list
, &cq
->child_list
);
10302 mempool_free(mbox
, phba
->mbox_mem_pool
);
10307 * lpfc_eq_destroy - Destroy an event Queue on the HBA
10308 * @eq: The queue structure associated with the queue to destroy.
10310 * This function destroys a queue, as detailed in @eq by sending an mailbox
10311 * command, specific to the type of queue, to the HBA.
10313 * The @eq struct is used to get the queue ID of the queue to destroy.
10315 * On success this function will return a zero. If the queue destroy mailbox
10316 * command fails this function will return ENXIO.
10319 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
10321 LPFC_MBOXQ_t
*mbox
;
10322 int rc
, length
, status
= 0;
10323 uint32_t shdr_status
, shdr_add_status
;
10324 union lpfc_sli4_cfg_shdr
*shdr
;
10328 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10331 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
10332 sizeof(struct lpfc_sli4_cfg_mhdr
));
10333 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10334 LPFC_MBOX_OPCODE_EQ_DESTROY
,
10335 length
, LPFC_SLI4_MBX_EMBED
);
10336 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
10338 mbox
->vport
= eq
->phba
->pport
;
10339 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10341 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
10342 /* The IOCTL status is embedded in the mailbox subheader. */
10343 shdr
= (union lpfc_sli4_cfg_shdr
*)
10344 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
10345 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10346 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10347 if (shdr_status
|| shdr_add_status
|| rc
) {
10348 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10349 "2505 EQ_DESTROY mailbox failed with "
10350 "status x%x add_status x%x, mbx status x%x\n",
10351 shdr_status
, shdr_add_status
, rc
);
10355 /* Remove eq from any list */
10356 list_del_init(&eq
->list
);
10357 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
10362 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
10363 * @cq: The queue structure associated with the queue to destroy.
10365 * This function destroys a queue, as detailed in @cq by sending an mailbox
10366 * command, specific to the type of queue, to the HBA.
10368 * The @cq struct is used to get the queue ID of the queue to destroy.
10370 * On success this function will return a zero. If the queue destroy mailbox
10371 * command fails this function will return ENXIO.
10374 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
10376 LPFC_MBOXQ_t
*mbox
;
10377 int rc
, length
, status
= 0;
10378 uint32_t shdr_status
, shdr_add_status
;
10379 union lpfc_sli4_cfg_shdr
*shdr
;
10383 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10386 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
10387 sizeof(struct lpfc_sli4_cfg_mhdr
));
10388 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10389 LPFC_MBOX_OPCODE_CQ_DESTROY
,
10390 length
, LPFC_SLI4_MBX_EMBED
);
10391 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
10393 mbox
->vport
= cq
->phba
->pport
;
10394 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10395 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
10396 /* The IOCTL status is embedded in the mailbox subheader. */
10397 shdr
= (union lpfc_sli4_cfg_shdr
*)
10398 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
10399 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10400 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10401 if (shdr_status
|| shdr_add_status
|| rc
) {
10402 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10403 "2506 CQ_DESTROY mailbox failed with "
10404 "status x%x add_status x%x, mbx status x%x\n",
10405 shdr_status
, shdr_add_status
, rc
);
10408 /* Remove cq from any list */
10409 list_del_init(&cq
->list
);
10410 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
10415 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
10416 * @qm: The queue structure associated with the queue to destroy.
10418 * This function destroys a queue, as detailed in @mq by sending an mailbox
10419 * command, specific to the type of queue, to the HBA.
10421 * The @mq struct is used to get the queue ID of the queue to destroy.
10423 * On success this function will return a zero. If the queue destroy mailbox
10424 * command fails this function will return ENXIO.
10427 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
10429 LPFC_MBOXQ_t
*mbox
;
10430 int rc
, length
, status
= 0;
10431 uint32_t shdr_status
, shdr_add_status
;
10432 union lpfc_sli4_cfg_shdr
*shdr
;
10436 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10439 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
10440 sizeof(struct lpfc_sli4_cfg_mhdr
));
10441 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10442 LPFC_MBOX_OPCODE_MQ_DESTROY
,
10443 length
, LPFC_SLI4_MBX_EMBED
);
10444 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
10446 mbox
->vport
= mq
->phba
->pport
;
10447 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10448 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
10449 /* The IOCTL status is embedded in the mailbox subheader. */
10450 shdr
= (union lpfc_sli4_cfg_shdr
*)
10451 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
10452 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10453 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10454 if (shdr_status
|| shdr_add_status
|| rc
) {
10455 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10456 "2507 MQ_DESTROY mailbox failed with "
10457 "status x%x add_status x%x, mbx status x%x\n",
10458 shdr_status
, shdr_add_status
, rc
);
10461 /* Remove mq from any list */
10462 list_del_init(&mq
->list
);
10463 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
10468 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
10469 * @wq: The queue structure associated with the queue to destroy.
10471 * This function destroys a queue, as detailed in @wq by sending an mailbox
10472 * command, specific to the type of queue, to the HBA.
10474 * The @wq struct is used to get the queue ID of the queue to destroy.
10476 * On success this function will return a zero. If the queue destroy mailbox
10477 * command fails this function will return ENXIO.
10480 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
10482 LPFC_MBOXQ_t
*mbox
;
10483 int rc
, length
, status
= 0;
10484 uint32_t shdr_status
, shdr_add_status
;
10485 union lpfc_sli4_cfg_shdr
*shdr
;
10489 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10492 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
10493 sizeof(struct lpfc_sli4_cfg_mhdr
));
10494 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10495 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
10496 length
, LPFC_SLI4_MBX_EMBED
);
10497 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
10499 mbox
->vport
= wq
->phba
->pport
;
10500 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10501 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
10502 shdr
= (union lpfc_sli4_cfg_shdr
*)
10503 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
10504 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10505 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10506 if (shdr_status
|| shdr_add_status
|| rc
) {
10507 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10508 "2508 WQ_DESTROY mailbox failed with "
10509 "status x%x add_status x%x, mbx status x%x\n",
10510 shdr_status
, shdr_add_status
, rc
);
10513 /* Remove wq from any list */
10514 list_del_init(&wq
->list
);
10515 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
10520 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
10521 * @rq: The queue structure associated with the queue to destroy.
10523 * This function destroys a queue, as detailed in @rq by sending an mailbox
10524 * command, specific to the type of queue, to the HBA.
10526 * The @rq struct is used to get the queue ID of the queue to destroy.
10528 * On success this function will return a zero. If the queue destroy mailbox
10529 * command fails this function will return ENXIO.
10532 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
10533 struct lpfc_queue
*drq
)
10535 LPFC_MBOXQ_t
*mbox
;
10536 int rc
, length
, status
= 0;
10537 uint32_t shdr_status
, shdr_add_status
;
10538 union lpfc_sli4_cfg_shdr
*shdr
;
10542 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10545 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
10546 sizeof(struct mbox_header
));
10547 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10548 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
10549 length
, LPFC_SLI4_MBX_EMBED
);
10550 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
10552 mbox
->vport
= hrq
->phba
->pport
;
10553 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10554 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
10555 /* The IOCTL status is embedded in the mailbox subheader. */
10556 shdr
= (union lpfc_sli4_cfg_shdr
*)
10557 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
10558 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10559 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10560 if (shdr_status
|| shdr_add_status
|| rc
) {
10561 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10562 "2509 RQ_DESTROY mailbox failed with "
10563 "status x%x add_status x%x, mbx status x%x\n",
10564 shdr_status
, shdr_add_status
, rc
);
10565 if (rc
!= MBX_TIMEOUT
)
10566 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
10569 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
10571 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
10572 shdr
= (union lpfc_sli4_cfg_shdr
*)
10573 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
10574 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10575 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10576 if (shdr_status
|| shdr_add_status
|| rc
) {
10577 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10578 "2510 RQ_DESTROY mailbox failed with "
10579 "status x%x add_status x%x, mbx status x%x\n",
10580 shdr_status
, shdr_add_status
, rc
);
10583 list_del_init(&hrq
->list
);
10584 list_del_init(&drq
->list
);
10585 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
10590 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
10591 * @phba: The virtual port for which this call being executed.
10592 * @pdma_phys_addr0: Physical address of the 1st SGL page.
10593 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
10594 * @xritag: the xritag that ties this io to the SGL pages.
10596 * This routine will post the sgl pages for the IO that has the xritag
10597 * that is in the iocbq structure. The xritag is assigned during iocbq
10598 * creation and persists for as long as the driver is loaded.
10599 * if the caller has fewer than 256 scatter gather segments to map then
10600 * pdma_phys_addr1 should be 0.
10601 * If the caller needs to map more than 256 scatter gather segment then
10602 * pdma_phys_addr1 should be a valid physical address.
10603 * physical address for SGLs must be 64 byte aligned.
10604 * If you are going to map 2 SGL's then the first one must have 256 entries
10605 * the second sgl can have between 1 and 256 entries.
10609 * -ENXIO, -ENOMEM - Failure
10612 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
10613 dma_addr_t pdma_phys_addr0
,
10614 dma_addr_t pdma_phys_addr1
,
10617 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
10618 LPFC_MBOXQ_t
*mbox
;
10620 uint32_t shdr_status
, shdr_add_status
;
10621 union lpfc_sli4_cfg_shdr
*shdr
;
10623 if (xritag
== NO_XRI
) {
10624 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10625 "0364 Invalid param:\n");
10629 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10633 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10634 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
10635 sizeof(struct lpfc_mbx_post_sgl_pages
) -
10636 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
10638 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
10639 &mbox
->u
.mqe
.un
.post_sgl_pages
;
10640 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
10641 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
10643 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
10644 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
10645 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
10646 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
10648 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
10649 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
10650 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
10651 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
10652 if (!phba
->sli4_hba
.intr_enable
)
10653 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10655 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
10656 /* The IOCTL status is embedded in the mailbox subheader. */
10657 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
10658 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10659 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10660 if (rc
!= MBX_TIMEOUT
)
10661 mempool_free(mbox
, phba
->mbox_mem_pool
);
10662 if (shdr_status
|| shdr_add_status
|| rc
) {
10663 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10664 "2511 POST_SGL mailbox failed with "
10665 "status x%x add_status x%x, mbx status x%x\n",
10666 shdr_status
, shdr_add_status
, rc
);
10672 * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
10673 * @phba: The virtual port for which this call being executed.
10675 * This routine will remove all of the sgl pages registered with the hba.
10679 * -ENXIO, -ENOMEM - Failure
10682 lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba
*phba
)
10684 LPFC_MBOXQ_t
*mbox
;
10686 uint32_t shdr_status
, shdr_add_status
;
10687 union lpfc_sli4_cfg_shdr
*shdr
;
10689 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10693 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10694 LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES
, 0,
10695 LPFC_SLI4_MBX_EMBED
);
10696 if (!phba
->sli4_hba
.intr_enable
)
10697 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10699 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
10700 /* The IOCTL status is embedded in the mailbox subheader. */
10701 shdr
= (union lpfc_sli4_cfg_shdr
*)
10702 &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
10703 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10704 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10705 if (rc
!= MBX_TIMEOUT
)
10706 mempool_free(mbox
, phba
->mbox_mem_pool
);
10707 if (shdr_status
|| shdr_add_status
|| rc
) {
10708 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10709 "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
10710 "status x%x add_status x%x, mbx status x%x\n",
10711 shdr_status
, shdr_add_status
, rc
);
10718 * lpfc_sli4_next_xritag - Get an xritag for the io
10719 * @phba: Pointer to HBA context object.
10721 * This function gets an xritag for the iocb. If there is no unused xritag
10722 * it will return 0xffff.
10723 * The function returns the allocated xritag if successful, else returns zero.
10724 * Zero is not a valid xritag.
10725 * The caller is not required to hold any lock.
10728 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
10732 spin_lock_irq(&phba
->hbalock
);
10733 xritag
= phba
->sli4_hba
.next_xri
;
10734 if ((xritag
!= (uint16_t) -1) && xritag
<
10735 (phba
->sli4_hba
.max_cfg_param
.max_xri
10736 + phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
10737 phba
->sli4_hba
.next_xri
++;
10738 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
10739 spin_unlock_irq(&phba
->hbalock
);
10742 spin_unlock_irq(&phba
->hbalock
);
10743 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10744 "2004 Failed to allocate XRI.last XRITAG is %d"
10745 " Max XRI is %d, Used XRI is %d\n",
10746 phba
->sli4_hba
.next_xri
,
10747 phba
->sli4_hba
.max_cfg_param
.max_xri
,
10748 phba
->sli4_hba
.max_cfg_param
.xri_used
);
10753 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
10754 * @phba: pointer to lpfc hba data structure.
10756 * This routine is invoked to post a block of driver's sgl pages to the
10757 * HBA using non-embedded mailbox command. No Lock is held. This routine
10758 * is only called when the driver is loading and after all IO has been
10762 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
)
10764 struct lpfc_sglq
*sglq_entry
;
10765 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
10766 struct sgl_page_pairs
*sgl_pg_pairs
;
10768 LPFC_MBOXQ_t
*mbox
;
10769 uint32_t reqlen
, alloclen
, pg_pairs
;
10771 uint16_t xritag_start
= 0;
10772 int els_xri_cnt
, rc
= 0;
10773 uint32_t shdr_status
, shdr_add_status
;
10774 union lpfc_sli4_cfg_shdr
*shdr
;
10776 /* The number of sgls to be posted */
10777 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
10779 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
10780 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
10781 if (reqlen
> SLI4_PAGE_SIZE
) {
10782 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10783 "2559 Block sgl registration required DMA "
10784 "size (%d) great than a page\n", reqlen
);
10787 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10789 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10790 "2560 Failed to allocate mbox cmd memory\n");
10794 /* Allocate DMA memory and set up the non-embedded mailbox command */
10795 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10796 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
10797 LPFC_SLI4_MBX_NEMBED
);
10799 if (alloclen
< reqlen
) {
10800 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10801 "0285 Allocated DMA memory size (%d) is "
10802 "less than the requested DMA memory "
10803 "size (%d)\n", alloclen
, reqlen
);
10804 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10807 /* Get the first SGE entry from the non-embedded DMA memory */
10808 viraddr
= mbox
->sge_array
->addr
[0];
10810 /* Set up the SGL pages in the non-embedded DMA pages */
10811 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
10812 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
10814 for (pg_pairs
= 0; pg_pairs
< els_xri_cnt
; pg_pairs
++) {
10815 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[pg_pairs
];
10816 /* Set up the sge entry */
10817 sgl_pg_pairs
->sgl_pg0_addr_lo
=
10818 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
10819 sgl_pg_pairs
->sgl_pg0_addr_hi
=
10820 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
10821 sgl_pg_pairs
->sgl_pg1_addr_lo
=
10822 cpu_to_le32(putPaddrLow(0));
10823 sgl_pg_pairs
->sgl_pg1_addr_hi
=
10824 cpu_to_le32(putPaddrHigh(0));
10825 /* Keep the first xritag on the list */
10827 xritag_start
= sglq_entry
->sli4_xritag
;
10830 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
10831 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, els_xri_cnt
);
10832 /* Perform endian conversion if necessary */
10833 sgl
->word0
= cpu_to_le32(sgl
->word0
);
10835 if (!phba
->sli4_hba
.intr_enable
)
10836 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10838 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
10839 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
10841 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
10842 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10843 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10844 if (rc
!= MBX_TIMEOUT
)
10845 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10846 if (shdr_status
|| shdr_add_status
|| rc
) {
10847 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10848 "2513 POST_SGL_BLOCK mailbox command failed "
10849 "status x%x add_status x%x mbx status x%x\n",
10850 shdr_status
, shdr_add_status
, rc
);
10857 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
10858 * @phba: pointer to lpfc hba data structure.
10859 * @sblist: pointer to scsi buffer list.
10860 * @count: number of scsi buffers on the list.
10862 * This routine is invoked to post a block of @count scsi sgl pages from a
10863 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
10868 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
, struct list_head
*sblist
,
10871 struct lpfc_scsi_buf
*psb
;
10872 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
10873 struct sgl_page_pairs
*sgl_pg_pairs
;
10875 LPFC_MBOXQ_t
*mbox
;
10876 uint32_t reqlen
, alloclen
, pg_pairs
;
10878 uint16_t xritag_start
= 0;
10880 uint32_t shdr_status
, shdr_add_status
;
10881 dma_addr_t pdma_phys_bpl1
;
10882 union lpfc_sli4_cfg_shdr
*shdr
;
10884 /* Calculate the requested length of the dma memory */
10885 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
10886 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
10887 if (reqlen
> SLI4_PAGE_SIZE
) {
10888 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10889 "0217 Block sgl registration required DMA "
10890 "size (%d) great than a page\n", reqlen
);
10893 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10895 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10896 "0283 Failed to allocate mbox cmd memory\n");
10900 /* Allocate DMA memory and set up the non-embedded mailbox command */
10901 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10902 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
10903 LPFC_SLI4_MBX_NEMBED
);
10905 if (alloclen
< reqlen
) {
10906 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10907 "2561 Allocated DMA memory size (%d) is "
10908 "less than the requested DMA memory "
10909 "size (%d)\n", alloclen
, reqlen
);
10910 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10913 /* Get the first SGE entry from the non-embedded DMA memory */
10914 viraddr
= mbox
->sge_array
->addr
[0];
10916 /* Set up the SGL pages in the non-embedded DMA pages */
10917 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
10918 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
10921 list_for_each_entry(psb
, sblist
, list
) {
10922 /* Set up the sge entry */
10923 sgl_pg_pairs
->sgl_pg0_addr_lo
=
10924 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
10925 sgl_pg_pairs
->sgl_pg0_addr_hi
=
10926 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
10927 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
10928 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
10930 pdma_phys_bpl1
= 0;
10931 sgl_pg_pairs
->sgl_pg1_addr_lo
=
10932 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
10933 sgl_pg_pairs
->sgl_pg1_addr_hi
=
10934 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
10935 /* Keep the first xritag on the list */
10937 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
10941 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
10942 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
10943 /* Perform endian conversion if necessary */
10944 sgl
->word0
= cpu_to_le32(sgl
->word0
);
10946 if (!phba
->sli4_hba
.intr_enable
)
10947 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10949 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
10950 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
10952 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
10953 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10954 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10955 if (rc
!= MBX_TIMEOUT
)
10956 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
10957 if (shdr_status
|| shdr_add_status
|| rc
) {
10958 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10959 "2564 POST_SGL_BLOCK mailbox command failed "
10960 "status x%x add_status x%x mbx status x%x\n",
10961 shdr_status
, shdr_add_status
, rc
);
10968 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
10969 * @phba: pointer to lpfc_hba struct that the frame was received on
10970 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
10972 * This function checks the fields in the @fc_hdr to see if the FC frame is a
10973 * valid type of frame that the LPFC driver will handle. This function will
10974 * return a zero if the frame is a valid frame or a non zero value when the
10975 * frame does not pass the check.
10978 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
10980 char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
10981 char *type_names
[] = FC_TYPE_NAMES_INIT
;
10982 struct fc_vft_header
*fc_vft_hdr
;
10984 switch (fc_hdr
->fh_r_ctl
) {
10985 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
10986 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
10987 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
10988 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
10989 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
10990 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
10991 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
10992 case FC_RCTL_DD_CMD_STATUS
: /* command status */
10993 case FC_RCTL_ELS_REQ
: /* extended link services request */
10994 case FC_RCTL_ELS_REP
: /* extended link services reply */
10995 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
10996 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
10997 case FC_RCTL_BA_NOP
: /* basic link service NOP */
10998 case FC_RCTL_BA_ABTS
: /* basic link service abort */
10999 case FC_RCTL_BA_RMC
: /* remove connection */
11000 case FC_RCTL_BA_ACC
: /* basic accept */
11001 case FC_RCTL_BA_RJT
: /* basic reject */
11002 case FC_RCTL_BA_PRMT
:
11003 case FC_RCTL_ACK_1
: /* acknowledge_1 */
11004 case FC_RCTL_ACK_0
: /* acknowledge_0 */
11005 case FC_RCTL_P_RJT
: /* port reject */
11006 case FC_RCTL_F_RJT
: /* fabric reject */
11007 case FC_RCTL_P_BSY
: /* port busy */
11008 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
11009 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
11010 case FC_RCTL_LCR
: /* link credit reset */
11011 case FC_RCTL_END
: /* end */
11013 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
11014 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
11015 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
11016 return lpfc_fc_frame_check(phba
, fc_hdr
);
11020 switch (fc_hdr
->fh_type
) {
11031 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
11032 "2538 Received frame rctl:%s type:%s\n",
11033 rctl_names
[fc_hdr
->fh_r_ctl
],
11034 type_names
[fc_hdr
->fh_type
]);
11037 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
11038 "2539 Dropped frame rctl:%s type:%s\n",
11039 rctl_names
[fc_hdr
->fh_r_ctl
],
11040 type_names
[fc_hdr
->fh_type
]);
11045 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
11046 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11048 * This function processes the FC header to retrieve the VFI from the VF
11049 * header, if one exists. This function will return the VFI if one exists
11050 * or 0 if no VSAN Header exists.
11053 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
11055 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
11057 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
11059 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
11063 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
11064 * @phba: Pointer to the HBA structure to search for the vport on
11065 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11066 * @fcfi: The FC Fabric ID that the frame came from
11068 * This function searches the @phba for a vport that matches the content of the
11069 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
11070 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
11071 * returns the matching vport pointer or NULL if unable to match frame to a
11074 static struct lpfc_vport
*
11075 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
11078 struct lpfc_vport
**vports
;
11079 struct lpfc_vport
*vport
= NULL
;
11081 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
11082 fc_hdr
->fh_d_id
[1] << 8 |
11083 fc_hdr
->fh_d_id
[2]);
11085 vports
= lpfc_create_vport_work_array(phba
);
11086 if (vports
!= NULL
)
11087 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
11088 if (phba
->fcf
.fcfi
== fcfi
&&
11089 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
11090 vports
[i
]->fc_myDID
== did
) {
11095 lpfc_destroy_vport_work_array(phba
, vports
);
11100 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
11101 * @vport: The vport to work on.
11103 * This function updates the receive sequence time stamp for this vport. The
11104 * receive sequence time stamp indicates the time that the last frame of the
11105 * the sequence that has been idle for the longest amount of time was received.
11106 * the driver uses this time stamp to indicate if any received sequences have
11110 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
11112 struct lpfc_dmabuf
*h_buf
;
11113 struct hbq_dmabuf
*dmabuf
= NULL
;
11115 /* get the oldest sequence on the rcv list */
11116 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
11117 struct lpfc_dmabuf
, list
);
11120 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11121 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
11125 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
11126 * @vport: The vport that the received sequences were sent to.
11128 * This function cleans up all outstanding received sequences. This is called
11129 * by the driver when a link event or user action invalidates all the received
11133 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
11135 struct lpfc_dmabuf
*h_buf
, *hnext
;
11136 struct lpfc_dmabuf
*d_buf
, *dnext
;
11137 struct hbq_dmabuf
*dmabuf
= NULL
;
11139 /* start with the oldest sequence on the rcv list */
11140 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
11141 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11142 list_del_init(&dmabuf
->hbuf
.list
);
11143 list_for_each_entry_safe(d_buf
, dnext
,
11144 &dmabuf
->dbuf
.list
, list
) {
11145 list_del_init(&d_buf
->list
);
11146 lpfc_in_buf_free(vport
->phba
, d_buf
);
11148 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
11153 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
11154 * @vport: The vport that the received sequences were sent to.
11156 * This function determines whether any received sequences have timed out by
11157 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
11158 * indicates that there is at least one timed out sequence this routine will
11159 * go through the received sequences one at a time from most inactive to most
11160 * active to determine which ones need to be cleaned up. Once it has determined
11161 * that a sequence needs to be cleaned up it will simply free up the resources
11162 * without sending an abort.
11165 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
11167 struct lpfc_dmabuf
*h_buf
, *hnext
;
11168 struct lpfc_dmabuf
*d_buf
, *dnext
;
11169 struct hbq_dmabuf
*dmabuf
= NULL
;
11170 unsigned long timeout
;
11171 int abort_count
= 0;
11173 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
11174 vport
->rcv_buffer_time_stamp
);
11175 if (list_empty(&vport
->rcv_buffer_list
) ||
11176 time_before(jiffies
, timeout
))
11178 /* start with the oldest sequence on the rcv list */
11179 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
11180 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11181 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
11182 dmabuf
->time_stamp
);
11183 if (time_before(jiffies
, timeout
))
11186 list_del_init(&dmabuf
->hbuf
.list
);
11187 list_for_each_entry_safe(d_buf
, dnext
,
11188 &dmabuf
->dbuf
.list
, list
) {
11189 list_del_init(&d_buf
->list
);
11190 lpfc_in_buf_free(vport
->phba
, d_buf
);
11192 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
11195 lpfc_update_rcv_time_stamp(vport
);
11199 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
11200 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
11202 * This function searches through the existing incomplete sequences that have
11203 * been sent to this @vport. If the frame matches one of the incomplete
11204 * sequences then the dbuf in the @dmabuf is added to the list of frames that
11205 * make up that sequence. If no sequence is found that matches this frame then
11206 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
11207 * This function returns a pointer to the first dmabuf in the sequence list that
11208 * the frame was linked to.
11210 static struct hbq_dmabuf
*
11211 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
11213 struct fc_frame_header
*new_hdr
;
11214 struct fc_frame_header
*temp_hdr
;
11215 struct lpfc_dmabuf
*d_buf
;
11216 struct lpfc_dmabuf
*h_buf
;
11217 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
11218 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
11220 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
11221 dmabuf
->time_stamp
= jiffies
;
11222 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11223 /* Use the hdr_buf to find the sequence that this frame belongs to */
11224 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
11225 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
11226 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
11227 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
11228 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
11230 /* found a pending sequence that matches this frame */
11231 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11236 * This indicates first frame received for this sequence.
11237 * Queue the buffer on the vport's rcv_buffer_list.
11239 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11240 lpfc_update_rcv_time_stamp(vport
);
11243 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
11244 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
11245 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
11246 list_del_init(&seq_dmabuf
->hbuf
.list
);
11247 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11248 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
11249 lpfc_update_rcv_time_stamp(vport
);
11252 /* move this sequence to the tail to indicate a young sequence */
11253 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11254 seq_dmabuf
->time_stamp
= jiffies
;
11255 lpfc_update_rcv_time_stamp(vport
);
11256 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
11257 temp_hdr
= dmabuf
->hbuf
.virt
;
11258 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
11261 /* find the correct place in the sequence to insert this frame */
11262 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
11263 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
11264 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
11266 * If the frame's sequence count is greater than the frame on
11267 * the list then insert the frame right after this frame
11269 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
11270 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
11271 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
11279 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
11280 * @vport: pointer to a vitural port
11281 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11283 * This function tries to abort from the partially assembed sequence, described
11284 * by the information from basic abbort @dmabuf. It checks to see whether such
11285 * partially assembled sequence held by the driver. If so, it shall free up all
11286 * the frames from the partially assembled sequence.
11289 * true -- if there is matching partially assembled sequence present and all
11290 * the frames freed with the sequence;
11291 * false -- if there is no matching partially assembled sequence present so
11292 * nothing got aborted in the lower layer driver
11295 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
11296 struct hbq_dmabuf
*dmabuf
)
11298 struct fc_frame_header
*new_hdr
;
11299 struct fc_frame_header
*temp_hdr
;
11300 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
11301 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
11303 /* Use the hdr_buf to find the sequence that matches this frame */
11304 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
11305 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
11306 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11307 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
11308 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
11309 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
11310 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
11311 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
11313 /* found a pending sequence that matches this frame */
11314 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11318 /* Free up all the frames from the partially assembled sequence */
11320 list_for_each_entry_safe(d_buf
, n_buf
,
11321 &seq_dmabuf
->dbuf
.list
, list
) {
11322 list_del_init(&d_buf
->list
);
11323 lpfc_in_buf_free(vport
->phba
, d_buf
);
11331 * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
11332 * @phba: Pointer to HBA context object.
11333 * @cmd_iocbq: pointer to the command iocbq structure.
11334 * @rsp_iocbq: pointer to the response iocbq structure.
11336 * This function handles the sequence abort accept iocb command complete
11337 * event. It properly releases the memory allocated to the sequence abort
11341 lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba
*phba
,
11342 struct lpfc_iocbq
*cmd_iocbq
,
11343 struct lpfc_iocbq
*rsp_iocbq
)
11346 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
11350 * lpfc_sli4_seq_abort_acc - Accept sequence abort
11351 * @phba: Pointer to HBA context object.
11352 * @fc_hdr: pointer to a FC frame header.
11354 * This function sends a basic accept to a previous unsol sequence abort
11355 * event after aborting the sequence handling.
11358 lpfc_sli4_seq_abort_acc(struct lpfc_hba
*phba
,
11359 struct fc_frame_header
*fc_hdr
)
11361 struct lpfc_iocbq
*ctiocb
= NULL
;
11362 struct lpfc_nodelist
*ndlp
;
11363 uint16_t oxid
, rxid
;
11364 uint32_t sid
, fctl
;
11367 if (!lpfc_is_link_up(phba
))
11370 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
11371 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
11372 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
11374 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
11376 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
11377 "1268 Find ndlp returned NULL for oxid:x%x "
11378 "SID:x%x\n", oxid
, sid
);
11382 /* Allocate buffer for acc iocb */
11383 ctiocb
= lpfc_sli_get_iocbq(phba
);
11387 /* Extract the F_CTL field from FC_HDR */
11388 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
11390 icmd
= &ctiocb
->iocb
;
11391 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
11392 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
11393 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
11394 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
11395 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
11397 /* Fill in the rest of iocb fields */
11398 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
11399 icmd
->ulpBdeCount
= 0;
11401 icmd
->ulpClass
= CLASS3
;
11402 icmd
->ulpContext
= ndlp
->nlp_rpi
;
11404 ctiocb
->iocb_cmpl
= NULL
;
11405 ctiocb
->vport
= phba
->pport
;
11406 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_acc_cmpl
;
11408 if (fctl
& FC_FC_EX_CTX
) {
11409 /* ABTS sent by responder to CT exchange, construction
11410 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
11411 * field and RX_ID from ABTS for RX_ID field.
11413 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_acc
, LPFC_ABTS_UNSOL_RSP
);
11414 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_acc
, rxid
);
11415 ctiocb
->sli4_xritag
= oxid
;
11417 /* ABTS sent by initiator to CT exchange, construction
11418 * of BA_ACC will need to allocate a new XRI as for the
11419 * XRI_TAG and RX_ID fields.
11421 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_acc
, LPFC_ABTS_UNSOL_INT
);
11422 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_acc
, NO_XRI
);
11423 ctiocb
->sli4_xritag
= NO_XRI
;
11425 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_acc
, oxid
);
11427 /* Xmit CT abts accept on exchange <xid> */
11428 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
11429 "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
11430 CMD_XMIT_BLS_RSP64_CX
, phba
->link_state
);
11431 lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
11435 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
11436 * @vport: Pointer to the vport on which this sequence was received
11437 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11439 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
11440 * receive sequence is only partially assembed by the driver, it shall abort
11441 * the partially assembled frames for the sequence. Otherwise, if the
11442 * unsolicited receive sequence has been completely assembled and passed to
11443 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
11444 * unsolicited sequence has been aborted. After that, it will issue a basic
11445 * accept to accept the abort.
11448 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
11449 struct hbq_dmabuf
*dmabuf
)
11451 struct lpfc_hba
*phba
= vport
->phba
;
11452 struct fc_frame_header fc_hdr
;
11456 /* Make a copy of fc_hdr before the dmabuf being released */
11457 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
11458 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
11460 if (fctl
& FC_FC_EX_CTX
) {
11462 * ABTS sent by responder to exchange, just free the buffer
11464 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11467 * ABTS sent by initiator to exchange, need to do cleanup
11469 /* Try to abort partially assembled seq */
11470 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
11472 /* Send abort to ULP if partially seq abort failed */
11473 if (abts_par
== false)
11474 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
11476 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11478 /* Send basic accept (BA_ACC) to the abort requester */
11479 lpfc_sli4_seq_abort_acc(phba
, &fc_hdr
);
11483 * lpfc_seq_complete - Indicates if a sequence is complete
11484 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11486 * This function checks the sequence, starting with the frame described by
11487 * @dmabuf, to see if all the frames associated with this sequence are present.
11488 * the frames associated with this sequence are linked to the @dmabuf using the
11489 * dbuf list. This function looks for two major things. 1) That the first frame
11490 * has a sequence count of zero. 2) There is a frame with last frame of sequence
11491 * set. 3) That there are no holes in the sequence count. The function will
11492 * return 1 when the sequence is complete, otherwise it will return 0.
11495 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
11497 struct fc_frame_header
*hdr
;
11498 struct lpfc_dmabuf
*d_buf
;
11499 struct hbq_dmabuf
*seq_dmabuf
;
11503 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11504 /* make sure first fame of sequence has a sequence count of zero */
11505 if (hdr
->fh_seq_cnt
!= seq_count
)
11507 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
11508 hdr
->fh_f_ctl
[1] << 8 |
11510 /* If last frame of sequence we can return success. */
11511 if (fctl
& FC_FC_END_SEQ
)
11513 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
11514 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
11515 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11516 /* If there is a hole in the sequence count then fail. */
11517 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
11519 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
11520 hdr
->fh_f_ctl
[1] << 8 |
11522 /* If last frame of sequence we can return success. */
11523 if (fctl
& FC_FC_END_SEQ
)
11530 * lpfc_prep_seq - Prep sequence for ULP processing
11531 * @vport: Pointer to the vport on which this sequence was received
11532 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11534 * This function takes a sequence, described by a list of frames, and creates
11535 * a list of iocbq structures to describe the sequence. This iocbq list will be
11536 * used to issue to the generic unsolicited sequence handler. This routine
11537 * returns a pointer to the first iocbq in the list. If the function is unable
11538 * to allocate an iocbq then it throw out the received frames that were not
11539 * able to be described and return a pointer to the first iocbq. If unable to
11540 * allocate any iocbqs (including the first) this function will return NULL.
11542 static struct lpfc_iocbq
*
11543 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
11545 struct lpfc_dmabuf
*d_buf
, *n_buf
;
11546 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
11547 struct fc_frame_header
*fc_hdr
;
11549 struct ulp_bde64
*pbde
;
11551 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11552 /* remove from receive buffer list */
11553 list_del_init(&seq_dmabuf
->hbuf
.list
);
11554 lpfc_update_rcv_time_stamp(vport
);
11555 /* get the Remote Port's SID */
11556 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
11557 /* Get an iocbq struct to fill in. */
11558 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
11560 /* Initialize the first IOCB. */
11561 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
11562 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
11563 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
11564 first_iocbq
->iocb
.ulpContext
= be16_to_cpu(fc_hdr
->fh_ox_id
);
11565 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
11566 vport
->vpi
+ vport
->phba
->vpi_base
;
11567 /* put the first buffer into the first IOCBq */
11568 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
11569 first_iocbq
->context3
= NULL
;
11570 first_iocbq
->iocb
.ulpBdeCount
= 1;
11571 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
11572 LPFC_DATA_BUF_SIZE
;
11573 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
11574 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
11575 bf_get(lpfc_rcqe_length
,
11576 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11578 iocbq
= first_iocbq
;
11580 * Each IOCBq can have two Buffers assigned, so go through the list
11581 * of buffers for this sequence and save two buffers in each IOCBq
11583 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
11585 lpfc_in_buf_free(vport
->phba
, d_buf
);
11588 if (!iocbq
->context3
) {
11589 iocbq
->context3
= d_buf
;
11590 iocbq
->iocb
.ulpBdeCount
++;
11591 pbde
= (struct ulp_bde64
*)
11592 &iocbq
->iocb
.unsli3
.sli3Words
[4];
11593 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
11594 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
11595 bf_get(lpfc_rcqe_length
,
11596 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11598 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
11601 first_iocbq
->iocb
.ulpStatus
=
11602 IOSTAT_FCP_RSP_ERROR
;
11603 first_iocbq
->iocb
.un
.ulpWord
[4] =
11604 IOERR_NO_RESOURCES
;
11606 lpfc_in_buf_free(vport
->phba
, d_buf
);
11609 iocbq
->context2
= d_buf
;
11610 iocbq
->context3
= NULL
;
11611 iocbq
->iocb
.ulpBdeCount
= 1;
11612 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
11613 LPFC_DATA_BUF_SIZE
;
11614 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
11615 bf_get(lpfc_rcqe_length
,
11616 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11617 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
11618 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
11621 return first_iocbq
;
11625 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
11626 struct hbq_dmabuf
*seq_dmabuf
)
11628 struct fc_frame_header
*fc_hdr
;
11629 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
11630 struct lpfc_hba
*phba
= vport
->phba
;
11632 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
11633 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
11635 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11636 "2707 Ring %d handler: Failed to allocate "
11637 "iocb Rctl x%x Type x%x received\n",
11639 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
11642 if (!lpfc_complete_unsol_iocb(phba
,
11643 &phba
->sli
.ring
[LPFC_ELS_RING
],
11644 iocbq
, fc_hdr
->fh_r_ctl
,
11646 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11647 "2540 Ring %d handler: unexpected Rctl "
11648 "x%x Type x%x received\n",
11650 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
11652 /* Free iocb created in lpfc_prep_seq */
11653 list_for_each_entry_safe(curr_iocb
, next_iocb
,
11654 &iocbq
->list
, list
) {
11655 list_del_init(&curr_iocb
->list
);
11656 lpfc_sli_release_iocbq(phba
, curr_iocb
);
11658 lpfc_sli_release_iocbq(phba
, iocbq
);
11662 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
11663 * @phba: Pointer to HBA context object.
11665 * This function is called with no lock held. This function processes all
11666 * the received buffers and gives it to upper layers when a received buffer
11667 * indicates that it is the final frame in the sequence. The interrupt
11668 * service routine processes received buffers at interrupt contexts and adds
11669 * received dma buffers to the rb_pend_list queue and signals the worker thread.
11670 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
11671 * appropriate receive function when the final frame in a sequence is received.
11674 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
11675 struct hbq_dmabuf
*dmabuf
)
11677 struct hbq_dmabuf
*seq_dmabuf
;
11678 struct fc_frame_header
*fc_hdr
;
11679 struct lpfc_vport
*vport
;
11682 /* Process each received buffer */
11683 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11684 /* check to see if this a valid type of frame */
11685 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
11686 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11689 fcfi
= bf_get(lpfc_rcqe_fcf_id
, &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
11690 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
11691 if (!vport
|| !(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
11692 /* throw out the frame */
11693 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11696 /* Handle the basic abort sequence (BA_ABTS) event */
11697 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
11698 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
11702 /* Link this frame */
11703 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
11705 /* unable to add frame to vport - throw it out */
11706 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
11709 /* If not last frame in sequence continue processing frames. */
11710 if (!lpfc_seq_complete(seq_dmabuf
))
11713 /* Send the complete sequence to the upper layer protocol */
11714 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
11718 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
11719 * @phba: pointer to lpfc hba data structure.
11721 * This routine is invoked to post rpi header templates to the
11722 * HBA consistent with the SLI-4 interface spec. This routine
11723 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
11724 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
11726 * This routine does not require any locks. It's usage is expected
11727 * to be driver load or reset recovery when the driver is
11732 * EIO - The mailbox failed to complete successfully.
11733 * When this error occurs, the driver is not guaranteed
11734 * to have any rpi regions posted to the device and
11735 * must either attempt to repost the regions or take a
11739 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
11741 struct lpfc_rpi_hdr
*rpi_page
;
11744 /* Post all rpi memory regions to the port. */
11745 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
11746 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
11747 if (rc
!= MBX_SUCCESS
) {
11748 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11749 "2008 Error %d posting all rpi "
11760 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
11761 * @phba: pointer to lpfc hba data structure.
11762 * @rpi_page: pointer to the rpi memory region.
11764 * This routine is invoked to post a single rpi header to the
11765 * HBA consistent with the SLI-4 interface spec. This memory region
11766 * maps up to 64 rpi context regions.
11770 * ENOMEM - No available memory
11771 * EIO - The mailbox failed to complete successfully.
11774 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
11776 LPFC_MBOXQ_t
*mboxq
;
11777 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
11780 uint32_t shdr_status
, shdr_add_status
;
11781 union lpfc_sli4_cfg_shdr
*shdr
;
11783 /* The port is notified of the header region via a mailbox command. */
11784 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11786 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11787 "2001 Unable to allocate memory for issuing "
11788 "SLI_CONFIG_SPECIAL mailbox command\n");
11792 /* Post all rpi memory regions to the port. */
11793 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
11794 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
11795 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11796 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
11797 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
11798 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
11799 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
11800 hdr_tmpl
, rpi_page
->page_count
);
11801 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
11802 rpi_page
->start_rpi
);
11803 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
11804 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
11805 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
11806 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
11807 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11808 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11809 if (rc
!= MBX_TIMEOUT
)
11810 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11811 if (shdr_status
|| shdr_add_status
|| rc
) {
11812 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11813 "2514 POST_RPI_HDR mailbox failed with "
11814 "status x%x add_status x%x, mbx status x%x\n",
11815 shdr_status
, shdr_add_status
, rc
);
11822 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
11823 * @phba: pointer to lpfc hba data structure.
11825 * This routine is invoked to post rpi header templates to the
11826 * HBA consistent with the SLI-4 interface spec. This routine
11827 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
11828 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
11831 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
11832 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
11835 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
11838 uint16_t max_rpi
, rpi_base
, rpi_limit
;
11839 uint16_t rpi_remaining
;
11840 struct lpfc_rpi_hdr
*rpi_hdr
;
11842 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
11843 rpi_base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
11844 rpi_limit
= phba
->sli4_hba
.next_rpi
;
11847 * The valid rpi range is not guaranteed to be zero-based. Start
11848 * the search at the rpi_base as reported by the port.
11850 spin_lock_irq(&phba
->hbalock
);
11851 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, rpi_base
);
11852 if (rpi
>= rpi_limit
|| rpi
< rpi_base
)
11853 rpi
= LPFC_RPI_ALLOC_ERROR
;
11855 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
11856 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
11857 phba
->sli4_hba
.rpi_count
++;
11861 * Don't try to allocate more rpi header regions if the device limit
11862 * on available rpis max has been exhausted.
11864 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
11865 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
11866 spin_unlock_irq(&phba
->hbalock
);
11871 * If the driver is running low on rpi resources, allocate another
11872 * page now. Note that the next_rpi value is used because
11873 * it represents how many are actually in use whereas max_rpi notes
11874 * how many are supported max by the device.
11876 rpi_remaining
= phba
->sli4_hba
.next_rpi
- rpi_base
-
11877 phba
->sli4_hba
.rpi_count
;
11878 spin_unlock_irq(&phba
->hbalock
);
11879 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
11880 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
11882 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11883 "2002 Error Could not grow rpi "
11886 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
11894 * lpfc_sli4_free_rpi - Release an rpi for reuse.
11895 * @phba: pointer to lpfc hba data structure.
11897 * This routine is invoked to release an rpi to the pool of
11898 * available rpis maintained by the driver.
11901 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
11903 spin_lock_irq(&phba
->hbalock
);
11904 clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
11905 phba
->sli4_hba
.rpi_count
--;
11906 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
11907 spin_unlock_irq(&phba
->hbalock
);
11911 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
11912 * @phba: pointer to lpfc hba data structure.
11914 * This routine is invoked to remove the memory region that
11915 * provided rpi via a bitmask.
11918 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
11920 kfree(phba
->sli4_hba
.rpi_bmask
);
11924 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
11925 * @phba: pointer to lpfc hba data structure.
11927 * This routine is invoked to remove the memory region that
11928 * provided rpi via a bitmask.
11931 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
)
11933 LPFC_MBOXQ_t
*mboxq
;
11934 struct lpfc_hba
*phba
= ndlp
->phba
;
11937 /* The port is notified of the header region via a mailbox command. */
11938 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11942 /* Post all rpi memory regions to the port. */
11943 lpfc_resume_rpi(mboxq
, ndlp
);
11944 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
11945 if (rc
== MBX_NOT_FINISHED
) {
11946 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11947 "2010 Resume RPI Mailbox failed "
11948 "status %d, mbxStatus x%x\n", rc
,
11949 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
11950 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11957 * lpfc_sli4_init_vpi - Initialize a vpi with the port
11958 * @phba: pointer to lpfc hba data structure.
11959 * @vpi: vpi value to activate with the port.
11961 * This routine is invoked to activate a vpi with the
11962 * port when the host intends to use vports with a
11967 * -Evalue otherwise
11970 lpfc_sli4_init_vpi(struct lpfc_hba
*phba
, uint16_t vpi
)
11972 LPFC_MBOXQ_t
*mboxq
;
11974 int retval
= MBX_SUCCESS
;
11979 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11982 lpfc_init_vpi(phba
, mboxq
, vpi
);
11983 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_INIT_VPI
);
11984 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
11985 if (rc
!= MBX_SUCCESS
) {
11986 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11987 "2022 INIT VPI Mailbox failed "
11988 "status %d, mbxStatus x%x\n", rc
,
11989 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
11992 if (rc
!= MBX_TIMEOUT
)
11993 mempool_free(mboxq
, phba
->mbox_mem_pool
);
11999 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
12000 * @phba: pointer to lpfc hba data structure.
12001 * @mboxq: Pointer to mailbox object.
12003 * This routine is invoked to manually add a single FCF record. The caller
12004 * must pass a completely initialized FCF_Record. This routine takes
12005 * care of the nonembedded mailbox operations.
12008 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
12011 union lpfc_sli4_cfg_shdr
*shdr
;
12012 uint32_t shdr_status
, shdr_add_status
;
12014 virt_addr
= mboxq
->sge_array
->addr
[0];
12015 /* The IOCTL status is embedded in the mailbox subheader. */
12016 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
12017 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12018 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12020 if ((shdr_status
|| shdr_add_status
) &&
12021 (shdr_status
!= STATUS_FCF_IN_USE
))
12022 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12023 "2558 ADD_FCF_RECORD mailbox failed with "
12024 "status x%x add_status x%x\n",
12025 shdr_status
, shdr_add_status
);
12027 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12031 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
12032 * @phba: pointer to lpfc hba data structure.
12033 * @fcf_record: pointer to the initialized fcf record to add.
12035 * This routine is invoked to manually add a single FCF record. The caller
12036 * must pass a completely initialized FCF_Record. This routine takes
12037 * care of the nonembedded mailbox operations.
12040 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
12043 LPFC_MBOXQ_t
*mboxq
;
12046 dma_addr_t phys_addr
;
12047 struct lpfc_mbx_sge sge
;
12048 uint32_t alloc_len
, req_len
;
12051 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12053 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12054 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
12058 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
12061 /* Allocate DMA memory and set up the non-embedded mailbox command */
12062 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12063 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
12064 req_len
, LPFC_SLI4_MBX_NEMBED
);
12065 if (alloc_len
< req_len
) {
12066 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12067 "2523 Allocated DMA memory size (x%x) is "
12068 "less than the requested DMA memory "
12069 "size (x%x)\n", alloc_len
, req_len
);
12070 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12075 * Get the first SGE entry from the non-embedded DMA memory. This
12076 * routine only uses a single SGE.
12078 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
12079 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
12080 virt_addr
= mboxq
->sge_array
->addr
[0];
12082 * Configure the FCF record for FCFI 0. This is the driver's
12083 * hardcoded default and gets used in nonFIP mode.
12085 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
12086 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
12087 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
12090 * Copy the fcf_index and the FCF Record Data. The data starts after
12091 * the FCoE header plus word10. The data copy needs to be endian
12094 bytep
+= sizeof(uint32_t);
12095 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
12096 mboxq
->vport
= phba
->pport
;
12097 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
12098 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12099 if (rc
== MBX_NOT_FINISHED
) {
12100 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12101 "2515 ADD_FCF_RECORD mailbox failed with "
12102 "status 0x%x\n", rc
);
12103 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12112 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
12113 * @phba: pointer to lpfc hba data structure.
12114 * @fcf_record: pointer to the fcf record to write the default data.
12115 * @fcf_index: FCF table entry index.
12117 * This routine is invoked to build the driver's default FCF record. The
12118 * values used are hardcoded. This routine handles memory initialization.
12122 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
12123 struct fcf_record
*fcf_record
,
12124 uint16_t fcf_index
)
12126 memset(fcf_record
, 0, sizeof(struct fcf_record
));
12127 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
12128 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
12129 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
12130 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
12131 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
12132 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
12133 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
12134 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
12135 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
12136 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
12137 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
12138 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
12139 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
12140 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
12141 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
12142 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
12143 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
12144 /* Set the VLAN bit map */
12145 if (phba
->valid_vlan
) {
12146 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
12147 = 1 << (phba
->vlan_id
% 8);
12152 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
12153 * @phba: pointer to lpfc hba data structure.
12154 * @fcf_index: FCF table entry offset.
12156 * This routine is invoked to scan the entire FCF table by reading FCF
12157 * record and processing it one at a time starting from the @fcf_index
12158 * for initial FCF discovery or fast FCF failover rediscovery.
12160 * Return 0 if the mailbox command is submitted sucessfully, none 0
12164 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12167 LPFC_MBOXQ_t
*mboxq
;
12169 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
12170 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12172 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12173 "2000 Failed to allocate mbox for "
12176 goto fail_fcf_scan
;
12178 /* Construct the read FCF record mailbox command */
12179 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12182 goto fail_fcf_scan
;
12184 /* Issue the mailbox command asynchronously */
12185 mboxq
->vport
= phba
->pport
;
12186 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
12187 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12188 if (rc
== MBX_NOT_FINISHED
)
12191 spin_lock_irq(&phba
->hbalock
);
12192 phba
->hba_flag
|= FCF_DISC_INPROGRESS
;
12193 spin_unlock_irq(&phba
->hbalock
);
12194 /* Reset FCF round robin index bmask for new scan */
12195 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
) {
12196 memset(phba
->fcf
.fcf_rr_bmask
, 0,
12197 sizeof(*phba
->fcf
.fcf_rr_bmask
));
12198 phba
->fcf
.eligible_fcf_cnt
= 0;
12205 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12206 /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
12207 spin_lock_irq(&phba
->hbalock
);
12208 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
12209 spin_unlock_irq(&phba
->hbalock
);
12215 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
12216 * @phba: pointer to lpfc hba data structure.
12217 * @fcf_index: FCF table entry offset.
12219 * This routine is invoked to read an FCF record indicated by @fcf_index
12220 * and to use it for FLOGI round robin FCF failover.
12222 * Return 0 if the mailbox command is submitted sucessfully, none 0
12226 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12229 LPFC_MBOXQ_t
*mboxq
;
12231 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12233 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
12234 "2763 Failed to allocate mbox for "
12237 goto fail_fcf_read
;
12239 /* Construct the read FCF record mailbox command */
12240 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12243 goto fail_fcf_read
;
12245 /* Issue the mailbox command asynchronously */
12246 mboxq
->vport
= phba
->pport
;
12247 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
12248 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12249 if (rc
== MBX_NOT_FINISHED
)
12255 if (error
&& mboxq
)
12256 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12261 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
12262 * @phba: pointer to lpfc hba data structure.
12263 * @fcf_index: FCF table entry offset.
12265 * This routine is invoked to read an FCF record indicated by @fcf_index to
12266 * determine whether it's eligible for FLOGI round robin failover list.
12268 * Return 0 if the mailbox command is submitted sucessfully, none 0
12272 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12275 LPFC_MBOXQ_t
*mboxq
;
12277 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12279 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
12280 "2758 Failed to allocate mbox for "
12283 goto fail_fcf_read
;
12285 /* Construct the read FCF record mailbox command */
12286 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12289 goto fail_fcf_read
;
12291 /* Issue the mailbox command asynchronously */
12292 mboxq
->vport
= phba
->pport
;
12293 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
12294 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12295 if (rc
== MBX_NOT_FINISHED
)
12301 if (error
&& mboxq
)
12302 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12307 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
12308 * @phba: pointer to lpfc hba data structure.
12310 * This routine is to get the next eligible FCF record index in a round
12311 * robin fashion. If the next eligible FCF record index equals to the
12312 * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
12313 * shall be returned, otherwise, the next eligible FCF record's index
12314 * shall be returned.
12317 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
12319 uint16_t next_fcf_index
;
12321 /* Search from the currently registered FCF index */
12322 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
12323 LPFC_SLI4_FCF_TBL_INDX_MAX
,
12324 phba
->fcf
.current_rec
.fcf_indx
);
12325 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
12326 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
12327 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
12328 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
12329 /* Round robin failover stop condition */
12330 if (next_fcf_index
== phba
->fcf
.fcf_rr_init_indx
)
12331 return LPFC_FCOE_FCF_NEXT_NONE
;
12333 return next_fcf_index
;
12337 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
12338 * @phba: pointer to lpfc hba data structure.
12340 * This routine sets the FCF record index in to the eligible bmask for
12341 * round robin failover search. It checks to make sure that the index
12342 * does not go beyond the range of the driver allocated bmask dimension
12343 * before setting the bit.
12345 * Returns 0 if the index bit successfully set, otherwise, it returns
12349 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12351 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
12352 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12353 "2610 HBA FCF index reached driver's "
12354 "book keeping dimension: fcf_index:%d, "
12355 "driver_bmask_max:%d\n",
12356 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
12359 /* Set the eligible FCF record index bmask */
12360 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
12366 * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
12367 * @phba: pointer to lpfc hba data structure.
12369 * This routine clears the FCF record index from the eligible bmask for
12370 * round robin failover search. It checks to make sure that the index
12371 * does not go beyond the range of the driver allocated bmask dimension
12372 * before clearing the bit.
12375 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12377 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
12378 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12379 "2762 HBA FCF index goes beyond driver's "
12380 "book keeping dimension: fcf_index:%d, "
12381 "driver_bmask_max:%d\n",
12382 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
12385 /* Clear the eligible FCF record index bmask */
12386 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
12390 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
12391 * @phba: pointer to lpfc hba data structure.
12393 * This routine is the completion routine for the rediscover FCF table mailbox
12394 * command. If the mailbox command returned failure, it will try to stop the
12395 * FCF rediscover wait timer.
12398 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
12400 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
12401 uint32_t shdr_status
, shdr_add_status
;
12403 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
12405 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
12406 &redisc_fcf
->header
.cfg_shdr
.response
);
12407 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
12408 &redisc_fcf
->header
.cfg_shdr
.response
);
12409 if (shdr_status
|| shdr_add_status
) {
12410 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12411 "2746 Requesting for FCF rediscovery failed "
12412 "status x%x add_status x%x\n",
12413 shdr_status
, shdr_add_status
);
12414 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
12415 spin_lock_irq(&phba
->hbalock
);
12416 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
12417 spin_unlock_irq(&phba
->hbalock
);
12419 * CVL event triggered FCF rediscover request failed,
12420 * last resort to re-try current registered FCF entry.
12422 lpfc_retry_pport_discovery(phba
);
12424 spin_lock_irq(&phba
->hbalock
);
12425 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
12426 spin_unlock_irq(&phba
->hbalock
);
12428 * DEAD FCF event triggered FCF rediscover request
12429 * failed, last resort to fail over as a link down
12430 * to FCF registration.
12432 lpfc_sli4_fcf_dead_failthrough(phba
);
12435 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
12436 "2775 Start FCF rediscovery quiescent period "
12437 "wait timer before scaning FCF table\n");
12439 * Start FCF rediscovery wait timer for pending FCF
12440 * before rescan FCF record table.
12442 lpfc_fcf_redisc_wait_start_timer(phba
);
12445 mempool_free(mbox
, phba
->mbox_mem_pool
);
12449 * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
12450 * @phba: pointer to lpfc hba data structure.
12452 * This routine is invoked to request for rediscovery of the entire FCF table
12456 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
12458 LPFC_MBOXQ_t
*mbox
;
12459 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
12462 /* Cancel retry delay timers to all vports before FCF rediscover */
12463 lpfc_cancel_all_vport_retry_delay_timer(phba
);
12465 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12467 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12468 "2745 Failed to allocate mbox for "
12469 "requesting FCF rediscover.\n");
12473 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
12474 sizeof(struct lpfc_sli4_cfg_mhdr
));
12475 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12476 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
12477 length
, LPFC_SLI4_MBX_EMBED
);
12479 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
12480 /* Set count to 0 for invalidating the entire FCF database */
12481 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
12483 /* Issue the mailbox command asynchronously */
12484 mbox
->vport
= phba
->pport
;
12485 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
12486 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
12488 if (rc
== MBX_NOT_FINISHED
) {
12489 mempool_free(mbox
, phba
->mbox_mem_pool
);
12496 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
12497 * @phba: pointer to lpfc hba data structure.
12499 * This function is the failover routine as a last resort to the FCF DEAD
12500 * event when driver failed to perform fast FCF failover.
12503 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
12505 uint32_t link_state
;
12508 * Last resort as FCF DEAD event failover will treat this as
12509 * a link down, but save the link state because we don't want
12510 * it to be changed to Link Down unless it is already down.
12512 link_state
= phba
->link_state
;
12513 lpfc_linkdown(phba
);
12514 phba
->link_state
= link_state
;
12516 /* Unregister FCF if no devices connected to it */
12517 lpfc_unregister_unused_fcf(phba
);
12521 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
12522 * @phba: pointer to lpfc hba data structure.
12524 * This function read region 23 and parse TLV for port status to
12525 * decide if the user disaled the port. If the TLV indicates the
12526 * port is disabled, the hba_flag is set accordingly.
12529 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
12531 LPFC_MBOXQ_t
*pmb
= NULL
;
12533 uint8_t *rgn23_data
= NULL
;
12534 uint32_t offset
= 0, data_size
, sub_tlv_len
, tlv_offset
;
12537 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12539 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12540 "2600 lpfc_sli_read_serdes_param failed to"
12541 " allocate mailbox memory\n");
12546 /* Get adapter Region 23 data */
12547 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
12552 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
12553 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
12555 if (rc
!= MBX_SUCCESS
) {
12556 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12557 "2601 lpfc_sli_read_link_ste failed to"
12558 " read config region 23 rc 0x%x Status 0x%x\n",
12559 rc
, mb
->mbxStatus
);
12560 mb
->un
.varDmp
.word_cnt
= 0;
12563 * dump mem may return a zero when finished or we got a
12564 * mailbox error, either way we are done.
12566 if (mb
->un
.varDmp
.word_cnt
== 0)
12568 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
12569 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
12571 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
12572 rgn23_data
+ offset
,
12573 mb
->un
.varDmp
.word_cnt
);
12574 offset
+= mb
->un
.varDmp
.word_cnt
;
12575 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
12577 data_size
= offset
;
12583 /* Check the region signature first */
12584 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
12585 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12586 "2619 Config region 23 has bad signature\n");
12591 /* Check the data structure version */
12592 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
12593 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12594 "2620 Config region 23 has bad version\n");
12599 /* Parse TLV entries in the region */
12600 while (offset
< data_size
) {
12601 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
12604 * If the TLV is not driver specific TLV or driver id is
12605 * not linux driver id, skip the record.
12607 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
12608 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
12609 (rgn23_data
[offset
+ 3] != 0)) {
12610 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
12614 /* Driver found a driver specific TLV in the config region */
12615 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
12620 * Search for configured port state sub-TLV.
12622 while ((offset
< data_size
) &&
12623 (tlv_offset
< sub_tlv_len
)) {
12624 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
12629 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
12630 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
12631 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
12635 /* This HBA contains PORT_STE configured */
12636 if (!rgn23_data
[offset
+ 2])
12637 phba
->hba_flag
|= LINK_DISABLED
;
12644 mempool_free(pmb
, phba
->mbox_mem_pool
);
12650 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
12651 * @vport: pointer to vport data structure.
12653 * This function iterate through the mailboxq and clean up all REG_LOGIN
12654 * and REG_VPI mailbox commands associated with the vport. This function
12655 * is called when driver want to restart discovery of the vport due to
12656 * a Clear Virtual Link event.
12659 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
12661 struct lpfc_hba
*phba
= vport
->phba
;
12662 LPFC_MBOXQ_t
*mb
, *nextmb
;
12663 struct lpfc_dmabuf
*mp
;
12664 struct lpfc_nodelist
*ndlp
;
12666 spin_lock_irq(&phba
->hbalock
);
12667 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
12668 if (mb
->vport
!= vport
)
12671 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
12672 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
12675 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
12676 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
12678 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
12681 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
12683 lpfc_nlp_put(ndlp
);
12684 mb
->context2
= NULL
;
12687 list_del(&mb
->list
);
12688 mempool_free(mb
, phba
->mbox_mem_pool
);
12690 mb
= phba
->sli
.mbox_active
;
12691 if (mb
&& (mb
->vport
== vport
)) {
12692 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
12693 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
12694 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12695 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
12696 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
12698 lpfc_nlp_put(ndlp
);
12699 mb
->context2
= NULL
;
12701 /* Unregister the RPI when mailbox complete */
12702 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
12705 spin_unlock_irq(&phba
->hbalock
);