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(wqe_wqec
, &wqe
->generic
.wqe_com
, 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
);
461 if (phba
->iocb_cnt
> phba
->iocb_max
)
462 phba
->iocb_max
= phba
->iocb_cnt
;
467 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
468 * @phba: Pointer to HBA context object.
469 * @xritag: XRI value.
471 * This function clears the sglq pointer from the array of acive
472 * sglq's. The xritag that is passed in is used to index into the
473 * array. Before the xritag can be used it needs to be adjusted
474 * by subtracting the xribase.
476 * Returns sglq ponter = success, NULL = Failure.
478 static struct lpfc_sglq
*
479 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
482 struct lpfc_sglq
*sglq
;
483 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
484 if (adj_xri
> phba
->sli4_hba
.max_cfg_param
.max_xri
)
486 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
];
487 phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
] = NULL
;
492 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
493 * @phba: Pointer to HBA context object.
494 * @xritag: XRI value.
496 * This function returns the sglq pointer from the array of acive
497 * sglq's. The xritag that is passed in is used to index into the
498 * array. Before the xritag can be used it needs to be adjusted
499 * by subtracting the xribase.
501 * Returns sglq ponter = success, NULL = Failure.
504 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
507 struct lpfc_sglq
*sglq
;
508 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
509 if (adj_xri
> phba
->sli4_hba
.max_cfg_param
.max_xri
)
511 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
];
516 * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
517 * @phba: Pointer to HBA context object.
518 * @ndlp: nodelist pointer for this target.
519 * @xritag: xri used in this exchange.
520 * @rxid: Remote Exchange ID.
521 * @send_rrq: Flag used to determine if we should send rrq els cmd.
523 * This function is called with hbalock held.
524 * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
525 * rrq struct and adds it to the active_rrq_list.
527 * returns 0 for rrq slot for this xri
528 * < 0 Were not able to get rrq mem or invalid parameter.
531 __lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
532 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
535 struct lpfc_node_rrq
*rrq
;
539 * set the active bit even if there is no mem available.
541 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
544 if (test_and_set_bit(adj_xri
, ndlp
->active_rrqs
.xri_bitmap
))
546 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
548 rrq
->send_rrq
= send_rrq
;
549 rrq
->xritag
= xritag
;
550 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
552 rrq
->nlp_DID
= ndlp
->nlp_DID
;
553 rrq
->vport
= ndlp
->vport
;
555 empty
= list_empty(&phba
->active_rrq_list
);
556 if (phba
->cfg_enable_rrq
&& send_rrq
)
558 * We need the xri before we can add this to the
559 * phba active rrq list.
561 rrq
->send_rrq
= send_rrq
;
564 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
565 if (!(phba
->hba_flag
& HBA_RRQ_ACTIVE
)) {
566 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
568 lpfc_worker_wake_up(phba
);
576 * __lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
577 * @phba: Pointer to HBA context object.
578 * @xritag: xri used in this exchange.
579 * @rrq: The RRQ to be cleared.
581 * This function is called with hbalock held. This function
584 __lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
586 struct lpfc_node_rrq
*rrq
)
589 struct lpfc_nodelist
*ndlp
;
591 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
593 /* The target DID could have been swapped (cable swap)
594 * we should use the ndlp from the findnode if it is
600 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
601 if (test_and_clear_bit(adj_xri
, ndlp
->active_rrqs
.xri_bitmap
)) {
604 rrq
->rrq_stop_time
= 0;
606 mempool_free(rrq
, phba
->rrq_pool
);
610 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
611 * @phba: Pointer to HBA context object.
613 * This function is called with hbalock held. This function
614 * Checks if stop_time (ratov from setting rrq active) has
615 * been reached, if it has and the send_rrq flag is set then
616 * it will call lpfc_send_rrq. If the send_rrq flag is not set
617 * then it will just call the routine to clear the rrq and
618 * free the rrq resource.
619 * The timer is set to the next rrq that is going to expire before
620 * leaving the routine.
624 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
626 struct lpfc_node_rrq
*rrq
;
627 struct lpfc_node_rrq
*nextrrq
;
628 unsigned long next_time
;
629 unsigned long iflags
;
631 spin_lock_irqsave(&phba
->hbalock
, iflags
);
632 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
633 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
634 list_for_each_entry_safe(rrq
, nextrrq
,
635 &phba
->active_rrq_list
, list
) {
636 if (time_after(jiffies
, rrq
->rrq_stop_time
)) {
637 list_del(&rrq
->list
);
639 /* this call will free the rrq */
640 __lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
642 /* if we send the rrq then the completion handler
643 * will clear the bit in the xribitmap.
645 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
646 if (lpfc_send_rrq(phba
, rrq
)) {
647 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
650 spin_lock_irqsave(&phba
->hbalock
, iflags
);
652 } else if (time_before(rrq
->rrq_stop_time
, next_time
))
653 next_time
= rrq
->rrq_stop_time
;
655 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
656 if (!list_empty(&phba
->active_rrq_list
))
657 mod_timer(&phba
->rrq_tmr
, next_time
);
661 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
662 * @vport: Pointer to vport context object.
663 * @xri: The xri used in the exchange.
664 * @did: The targets DID for this exchange.
666 * returns NULL = rrq not found in the phba->active_rrq_list.
667 * rrq = rrq for this xri and target.
669 struct lpfc_node_rrq
*
670 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
672 struct lpfc_hba
*phba
= vport
->phba
;
673 struct lpfc_node_rrq
*rrq
;
674 struct lpfc_node_rrq
*nextrrq
;
675 unsigned long iflags
;
677 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
679 spin_lock_irqsave(&phba
->hbalock
, iflags
);
680 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
681 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
682 rrq
->nlp_DID
== did
){
683 list_del(&rrq
->list
);
684 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
688 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
693 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
694 * @vport: Pointer to vport context object.
696 * Remove all active RRQs for this vport from the phba->active_rrq_list and
700 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
)
703 struct lpfc_hba
*phba
= vport
->phba
;
704 struct lpfc_node_rrq
*rrq
;
705 struct lpfc_node_rrq
*nextrrq
;
706 unsigned long iflags
;
708 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
710 spin_lock_irqsave(&phba
->hbalock
, iflags
);
711 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
712 if (rrq
->vport
== vport
) {
713 list_del(&rrq
->list
);
714 __lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
717 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
721 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
722 * @phba: Pointer to HBA context object.
724 * Remove all rrqs from the phba->active_rrq_list and free them by
725 * calling __lpfc_clr_active_rrq
729 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
731 struct lpfc_node_rrq
*rrq
;
732 struct lpfc_node_rrq
*nextrrq
;
733 unsigned long next_time
;
734 unsigned long iflags
;
736 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
738 spin_lock_irqsave(&phba
->hbalock
, iflags
);
739 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
740 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
741 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
742 list_del(&rrq
->list
);
743 __lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
745 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
746 if (!list_empty(&phba
->active_rrq_list
))
747 mod_timer(&phba
->rrq_tmr
, next_time
);
752 * __lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
753 * @phba: Pointer to HBA context object.
754 * @ndlp: Targets nodelist pointer for this exchange.
755 * @xritag the xri in the bitmap to test.
757 * This function is called with hbalock held. This function
758 * returns 0 = rrq not active for this xri
759 * 1 = rrq is valid for this xri.
762 __lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
767 adj_xri
= xritag
- phba
->sli4_hba
.max_cfg_param
.xri_base
;
770 if (test_bit(adj_xri
, ndlp
->active_rrqs
.xri_bitmap
))
777 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
778 * @phba: Pointer to HBA context object.
779 * @ndlp: nodelist pointer for this target.
780 * @xritag: xri used in this exchange.
781 * @rxid: Remote Exchange ID.
782 * @send_rrq: Flag used to determine if we should send rrq els cmd.
784 * This function takes the hbalock.
785 * The active bit is always set in the active rrq xri_bitmap even
786 * if there is no slot avaiable for the other rrq information.
788 * returns 0 rrq actived for this xri
789 * < 0 No memory or invalid ndlp.
792 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
793 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
796 unsigned long iflags
;
798 spin_lock_irqsave(&phba
->hbalock
, iflags
);
799 ret
= __lpfc_set_rrq_active(phba
, ndlp
, xritag
, rxid
, send_rrq
);
800 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
805 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
806 * @phba: Pointer to HBA context object.
807 * @xritag: xri used in this exchange.
808 * @rrq: The RRQ to be cleared.
810 * This function is takes the hbalock.
813 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
815 struct lpfc_node_rrq
*rrq
)
817 unsigned long iflags
;
819 spin_lock_irqsave(&phba
->hbalock
, iflags
);
820 __lpfc_clr_rrq_active(phba
, xritag
, rrq
);
821 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
828 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
829 * @phba: Pointer to HBA context object.
830 * @ndlp: Targets nodelist pointer for this exchange.
831 * @xritag the xri in the bitmap to test.
833 * This function takes the hbalock.
834 * returns 0 = rrq not active for this xri
835 * 1 = rrq is valid for this xri.
838 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
842 unsigned long iflags
;
844 spin_lock_irqsave(&phba
->hbalock
, iflags
);
845 ret
= __lpfc_test_rrq_active(phba
, ndlp
, xritag
);
846 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
851 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
852 * @phba: Pointer to HBA context object.
853 * @piocb: Pointer to the iocbq.
855 * This function is called with hbalock held. This function
856 * Gets a new driver sglq object from the sglq list. If the
857 * list is not empty then it is successful, it returns pointer to the newly
858 * allocated sglq object else it returns NULL.
860 static struct lpfc_sglq
*
861 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
863 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
864 struct lpfc_sglq
*sglq
= NULL
;
865 struct lpfc_sglq
*start_sglq
= NULL
;
867 struct lpfc_scsi_buf
*lpfc_cmd
;
868 struct lpfc_nodelist
*ndlp
;
871 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
872 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
873 ndlp
= lpfc_cmd
->rdata
->pnode
;
874 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
875 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
876 ndlp
= piocbq
->context_un
.ndlp
;
878 ndlp
= piocbq
->context1
;
880 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
885 adj_xri
= sglq
->sli4_xritag
-
886 phba
->sli4_hba
.max_cfg_param
.xri_base
;
887 if (__lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_xritag
)) {
888 /* This xri has an rrq outstanding for this DID.
889 * put it back in the list and get another xri.
891 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
893 list_remove_head(lpfc_sgl_list
, sglq
,
894 struct lpfc_sglq
, list
);
895 if (sglq
== start_sglq
) {
903 phba
->sli4_hba
.lpfc_sglq_active_list
[adj_xri
] = sglq
;
904 sglq
->state
= SGL_ALLOCATED
;
910 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
911 * @phba: Pointer to HBA context object.
913 * This function is called with no lock held. This function
914 * allocates a new driver iocb object from the iocb pool. If the
915 * allocation is successful, it returns pointer to the newly
916 * allocated iocb object else it returns NULL.
919 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
921 struct lpfc_iocbq
* iocbq
= NULL
;
922 unsigned long iflags
;
924 spin_lock_irqsave(&phba
->hbalock
, iflags
);
925 iocbq
= __lpfc_sli_get_iocbq(phba
);
926 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
931 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
932 * @phba: Pointer to HBA context object.
933 * @iocbq: Pointer to driver iocb object.
935 * This function is called with hbalock held to release driver
936 * iocb object to the iocb pool. The iotag in the iocb object
937 * does not change for each use of the iocb object. This function
938 * clears all other fields of the iocb object when it is freed.
939 * The sqlq structure that holds the xritag and phys and virtual
940 * mappings for the scatter gather list is retrieved from the
941 * active array of sglq. The get of the sglq pointer also clears
942 * the entry in the array. If the status of the IO indiactes that
943 * this IO was aborted then the sglq entry it put on the
944 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
945 * IO has good status or fails for any other reason then the sglq
946 * entry is added to the free list (lpfc_sgl_list).
949 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
951 struct lpfc_sglq
*sglq
;
952 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
953 unsigned long iflag
= 0;
954 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
956 if (iocbq
->sli4_xritag
== NO_XRI
)
959 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_xritag
);
961 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
962 (sglq
->state
!= SGL_XRI_ABORTED
)) {
963 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
965 list_add(&sglq
->list
,
966 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
967 spin_unlock_irqrestore(
968 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
970 sglq
->state
= SGL_FREED
;
972 list_add(&sglq
->list
, &phba
->sli4_hba
.lpfc_sgl_list
);
974 /* Check if TXQ queue needs to be serviced */
976 lpfc_worker_wake_up(phba
);
982 * Clean all volatile data fields, preserve iotag and node struct.
984 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
985 iocbq
->sli4_xritag
= NO_XRI
;
986 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
991 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
992 * @phba: Pointer to HBA context object.
993 * @iocbq: Pointer to driver iocb object.
995 * This function is called with hbalock held to release driver
996 * iocb object to the iocb pool. The iotag in the iocb object
997 * does not change for each use of the iocb object. This function
998 * clears all other fields of the iocb object when it is freed.
1001 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1003 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1006 * Clean all volatile data fields, preserve iotag and node struct.
1008 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1009 iocbq
->sli4_xritag
= NO_XRI
;
1010 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1014 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1015 * @phba: Pointer to HBA context object.
1016 * @iocbq: Pointer to driver iocb object.
1018 * This function is called with hbalock held to release driver
1019 * iocb object to the iocb pool. The iotag in the iocb object
1020 * does not change for each use of the iocb object. This function
1021 * clears all other fields of the iocb object when it is freed.
1024 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1026 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1031 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1032 * @phba: Pointer to HBA context object.
1033 * @iocbq: Pointer to driver iocb object.
1035 * This function is called with no lock held to release the iocb to
1039 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1041 unsigned long iflags
;
1044 * Clean all volatile data fields, preserve iotag and node struct.
1046 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1047 __lpfc_sli_release_iocbq(phba
, iocbq
);
1048 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1052 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1053 * @phba: Pointer to HBA context object.
1054 * @iocblist: List of IOCBs.
1055 * @ulpstatus: ULP status in IOCB command field.
1056 * @ulpWord4: ULP word-4 in IOCB command field.
1058 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1059 * on the list by invoking the complete callback function associated with the
1060 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1064 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1065 uint32_t ulpstatus
, uint32_t ulpWord4
)
1067 struct lpfc_iocbq
*piocb
;
1069 while (!list_empty(iocblist
)) {
1070 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1072 if (!piocb
->iocb_cmpl
)
1073 lpfc_sli_release_iocbq(phba
, piocb
);
1075 piocb
->iocb
.ulpStatus
= ulpstatus
;
1076 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1077 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1084 * lpfc_sli_iocb_cmd_type - Get the iocb type
1085 * @iocb_cmnd: iocb command code.
1087 * This function is called by ring event handler function to get the iocb type.
1088 * This function translates the iocb command to an iocb command type used to
1089 * decide the final disposition of each completed IOCB.
1090 * The function returns
1091 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1092 * LPFC_SOL_IOCB if it is a solicited iocb completion
1093 * LPFC_ABORT_IOCB if it is an abort iocb
1094 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1096 * The caller is not required to hold any lock.
1098 static lpfc_iocb_type
1099 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1101 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1103 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1106 switch (iocb_cmnd
) {
1107 case CMD_XMIT_SEQUENCE_CR
:
1108 case CMD_XMIT_SEQUENCE_CX
:
1109 case CMD_XMIT_BCAST_CN
:
1110 case CMD_XMIT_BCAST_CX
:
1111 case CMD_ELS_REQUEST_CR
:
1112 case CMD_ELS_REQUEST_CX
:
1113 case CMD_CREATE_XRI_CR
:
1114 case CMD_CREATE_XRI_CX
:
1115 case CMD_GET_RPI_CN
:
1116 case CMD_XMIT_ELS_RSP_CX
:
1117 case CMD_GET_RPI_CR
:
1118 case CMD_FCP_IWRITE_CR
:
1119 case CMD_FCP_IWRITE_CX
:
1120 case CMD_FCP_IREAD_CR
:
1121 case CMD_FCP_IREAD_CX
:
1122 case CMD_FCP_ICMND_CR
:
1123 case CMD_FCP_ICMND_CX
:
1124 case CMD_FCP_TSEND_CX
:
1125 case CMD_FCP_TRSP_CX
:
1126 case CMD_FCP_TRECEIVE_CX
:
1127 case CMD_FCP_AUTO_TRSP_CX
:
1128 case CMD_ADAPTER_MSG
:
1129 case CMD_ADAPTER_DUMP
:
1130 case CMD_XMIT_SEQUENCE64_CR
:
1131 case CMD_XMIT_SEQUENCE64_CX
:
1132 case CMD_XMIT_BCAST64_CN
:
1133 case CMD_XMIT_BCAST64_CX
:
1134 case CMD_ELS_REQUEST64_CR
:
1135 case CMD_ELS_REQUEST64_CX
:
1136 case CMD_FCP_IWRITE64_CR
:
1137 case CMD_FCP_IWRITE64_CX
:
1138 case CMD_FCP_IREAD64_CR
:
1139 case CMD_FCP_IREAD64_CX
:
1140 case CMD_FCP_ICMND64_CR
:
1141 case CMD_FCP_ICMND64_CX
:
1142 case CMD_FCP_TSEND64_CX
:
1143 case CMD_FCP_TRSP64_CX
:
1144 case CMD_FCP_TRECEIVE64_CX
:
1145 case CMD_GEN_REQUEST64_CR
:
1146 case CMD_GEN_REQUEST64_CX
:
1147 case CMD_XMIT_ELS_RSP64_CX
:
1148 case DSSCMD_IWRITE64_CR
:
1149 case DSSCMD_IWRITE64_CX
:
1150 case DSSCMD_IREAD64_CR
:
1151 case DSSCMD_IREAD64_CX
:
1152 type
= LPFC_SOL_IOCB
;
1154 case CMD_ABORT_XRI_CN
:
1155 case CMD_ABORT_XRI_CX
:
1156 case CMD_CLOSE_XRI_CN
:
1157 case CMD_CLOSE_XRI_CX
:
1158 case CMD_XRI_ABORTED_CX
:
1159 case CMD_ABORT_MXRI64_CN
:
1160 case CMD_XMIT_BLS_RSP64_CX
:
1161 type
= LPFC_ABORT_IOCB
;
1163 case CMD_RCV_SEQUENCE_CX
:
1164 case CMD_RCV_ELS_REQ_CX
:
1165 case CMD_RCV_SEQUENCE64_CX
:
1166 case CMD_RCV_ELS_REQ64_CX
:
1167 case CMD_ASYNC_STATUS
:
1168 case CMD_IOCB_RCV_SEQ64_CX
:
1169 case CMD_IOCB_RCV_ELS64_CX
:
1170 case CMD_IOCB_RCV_CONT64_CX
:
1171 case CMD_IOCB_RET_XRI64_CX
:
1172 type
= LPFC_UNSOL_IOCB
;
1174 case CMD_IOCB_XMIT_MSEQ64_CR
:
1175 case CMD_IOCB_XMIT_MSEQ64_CX
:
1176 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1177 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1178 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1179 case CMD_IOCB_ABORT_EXTENDED_CN
:
1180 case CMD_IOCB_RET_HBQE64_CN
:
1181 case CMD_IOCB_FCP_IBIDIR64_CR
:
1182 case CMD_IOCB_FCP_IBIDIR64_CX
:
1183 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1184 case CMD_IOCB_LOGENTRY_CN
:
1185 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1186 printk("%s - Unhandled SLI-3 Command x%x\n",
1187 __func__
, iocb_cmnd
);
1188 type
= LPFC_UNKNOWN_IOCB
;
1191 type
= LPFC_UNKNOWN_IOCB
;
1199 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1200 * @phba: Pointer to HBA context object.
1202 * This function is called from SLI initialization code
1203 * to configure every ring of the HBA's SLI interface. The
1204 * caller is not required to hold any lock. This function issues
1205 * a config_ring mailbox command for each ring.
1206 * This function returns zero if successful else returns a negative
1210 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1212 struct lpfc_sli
*psli
= &phba
->sli
;
1217 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1221 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1222 for (i
= 0; i
< psli
->num_rings
; i
++) {
1223 lpfc_config_ring(phba
, i
, pmb
);
1224 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1225 if (rc
!= MBX_SUCCESS
) {
1226 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1227 "0446 Adapter failed to init (%d), "
1228 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1230 rc
, pmbox
->mbxCommand
,
1231 pmbox
->mbxStatus
, i
);
1232 phba
->link_state
= LPFC_HBA_ERROR
;
1237 mempool_free(pmb
, phba
->mbox_mem_pool
);
1242 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1243 * @phba: Pointer to HBA context object.
1244 * @pring: Pointer to driver SLI ring object.
1245 * @piocb: Pointer to the driver iocb object.
1247 * This function is called with hbalock held. The function adds the
1248 * new iocb to txcmplq of the given ring. This function always returns
1249 * 0. If this function is called for ELS ring, this function checks if
1250 * there is a vport associated with the ELS command. This function also
1251 * starts els_tmofunc timer if this is an ELS command.
1254 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1255 struct lpfc_iocbq
*piocb
)
1257 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1258 piocb
->iocb_flag
|= LPFC_IO_ON_Q
;
1259 pring
->txcmplq_cnt
++;
1260 if (pring
->txcmplq_cnt
> pring
->txcmplq_max
)
1261 pring
->txcmplq_max
= pring
->txcmplq_cnt
;
1263 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1264 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1265 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1269 mod_timer(&piocb
->vport
->els_tmofunc
,
1270 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1278 * lpfc_sli_ringtx_get - Get first element of the txq
1279 * @phba: Pointer to HBA context object.
1280 * @pring: Pointer to driver SLI ring object.
1282 * This function is called with hbalock held to get next
1283 * iocb in txq of the given ring. If there is any iocb in
1284 * the txq, the function returns first iocb in the list after
1285 * removing the iocb from the list, else it returns NULL.
1288 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1290 struct lpfc_iocbq
*cmd_iocb
;
1292 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1293 if (cmd_iocb
!= NULL
)
1299 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1300 * @phba: Pointer to HBA context object.
1301 * @pring: Pointer to driver SLI ring object.
1303 * This function is called with hbalock held and the caller must post the
1304 * iocb without releasing the lock. If the caller releases the lock,
1305 * iocb slot returned by the function is not guaranteed to be available.
1306 * The function returns pointer to the next available iocb slot if there
1307 * is available slot in the ring, else it returns NULL.
1308 * If the get index of the ring is ahead of the put index, the function
1309 * will post an error attention event to the worker thread to take the
1310 * HBA to offline state.
1313 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1315 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1316 uint32_t max_cmd_idx
= pring
->numCiocb
;
1317 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
1318 (++pring
->next_cmdidx
>= max_cmd_idx
))
1319 pring
->next_cmdidx
= 0;
1321 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
1323 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1325 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
1326 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1327 "0315 Ring %d issue: portCmdGet %d "
1328 "is bigger than cmd ring %d\n",
1330 pring
->local_getidx
, max_cmd_idx
);
1332 phba
->link_state
= LPFC_HBA_ERROR
;
1334 * All error attention handlers are posted to
1337 phba
->work_ha
|= HA_ERATT
;
1338 phba
->work_hs
= HS_FFER3
;
1340 lpfc_worker_wake_up(phba
);
1345 if (pring
->local_getidx
== pring
->next_cmdidx
)
1349 return lpfc_cmd_iocb(phba
, pring
);
1353 * lpfc_sli_next_iotag - Get an iotag for the iocb
1354 * @phba: Pointer to HBA context object.
1355 * @iocbq: Pointer to driver iocb object.
1357 * This function gets an iotag for the iocb. If there is no unused iotag and
1358 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1359 * array and assigns a new iotag.
1360 * The function returns the allocated iotag if successful, else returns zero.
1361 * Zero is not a valid iotag.
1362 * The caller is not required to hold any lock.
1365 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1367 struct lpfc_iocbq
**new_arr
;
1368 struct lpfc_iocbq
**old_arr
;
1370 struct lpfc_sli
*psli
= &phba
->sli
;
1373 spin_lock_irq(&phba
->hbalock
);
1374 iotag
= psli
->last_iotag
;
1375 if(++iotag
< psli
->iocbq_lookup_len
) {
1376 psli
->last_iotag
= iotag
;
1377 psli
->iocbq_lookup
[iotag
] = iocbq
;
1378 spin_unlock_irq(&phba
->hbalock
);
1379 iocbq
->iotag
= iotag
;
1381 } else if (psli
->iocbq_lookup_len
< (0xffff
1382 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1383 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1384 spin_unlock_irq(&phba
->hbalock
);
1385 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1388 spin_lock_irq(&phba
->hbalock
);
1389 old_arr
= psli
->iocbq_lookup
;
1390 if (new_len
<= psli
->iocbq_lookup_len
) {
1391 /* highly unprobable case */
1393 iotag
= psli
->last_iotag
;
1394 if(++iotag
< psli
->iocbq_lookup_len
) {
1395 psli
->last_iotag
= iotag
;
1396 psli
->iocbq_lookup
[iotag
] = iocbq
;
1397 spin_unlock_irq(&phba
->hbalock
);
1398 iocbq
->iotag
= iotag
;
1401 spin_unlock_irq(&phba
->hbalock
);
1404 if (psli
->iocbq_lookup
)
1405 memcpy(new_arr
, old_arr
,
1406 ((psli
->last_iotag
+ 1) *
1407 sizeof (struct lpfc_iocbq
*)));
1408 psli
->iocbq_lookup
= new_arr
;
1409 psli
->iocbq_lookup_len
= new_len
;
1410 psli
->last_iotag
= iotag
;
1411 psli
->iocbq_lookup
[iotag
] = iocbq
;
1412 spin_unlock_irq(&phba
->hbalock
);
1413 iocbq
->iotag
= iotag
;
1418 spin_unlock_irq(&phba
->hbalock
);
1420 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1421 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1428 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1429 * @phba: Pointer to HBA context object.
1430 * @pring: Pointer to driver SLI ring object.
1431 * @iocb: Pointer to iocb slot in the ring.
1432 * @nextiocb: Pointer to driver iocb object which need to be
1433 * posted to firmware.
1435 * This function is called with hbalock held to post a new iocb to
1436 * the firmware. This function copies the new iocb to ring iocb slot and
1437 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1438 * a completion call back for this iocb else the function will free the
1442 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1443 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1448 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1451 if (pring
->ringno
== LPFC_ELS_RING
) {
1452 lpfc_debugfs_slow_ring_trc(phba
,
1453 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1454 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1455 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1456 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1460 * Issue iocb command to adapter
1462 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1464 pring
->stats
.iocb_cmd
++;
1467 * If there is no completion routine to call, we can release the
1468 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1469 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1471 if (nextiocb
->iocb_cmpl
)
1472 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1474 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1477 * Let the HBA know what IOCB slot will be the next one the
1478 * driver will put a command into.
1480 pring
->cmdidx
= pring
->next_cmdidx
;
1481 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1485 * lpfc_sli_update_full_ring - Update the chip attention register
1486 * @phba: Pointer to HBA context object.
1487 * @pring: Pointer to driver SLI ring object.
1489 * The caller is not required to hold any lock for calling this function.
1490 * This function updates the chip attention bits for the ring to inform firmware
1491 * that there are pending work to be done for this ring and requests an
1492 * interrupt when there is space available in the ring. This function is
1493 * called when the driver is unable to post more iocbs to the ring due
1494 * to unavailability of space in the ring.
1497 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1499 int ringno
= pring
->ringno
;
1501 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1506 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1507 * The HBA will tell us when an IOCB entry is available.
1509 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1510 readl(phba
->CAregaddr
); /* flush */
1512 pring
->stats
.iocb_cmd_full
++;
1516 * lpfc_sli_update_ring - Update chip attention register
1517 * @phba: Pointer to HBA context object.
1518 * @pring: Pointer to driver SLI ring object.
1520 * This function updates the chip attention register bit for the
1521 * given ring to inform HBA that there is more work to be done
1522 * in this ring. The caller is not required to hold any lock.
1525 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1527 int ringno
= pring
->ringno
;
1530 * Tell the HBA that there is work to do in this ring.
1532 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1534 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1535 readl(phba
->CAregaddr
); /* flush */
1540 * lpfc_sli_resume_iocb - Process iocbs in the txq
1541 * @phba: Pointer to HBA context object.
1542 * @pring: Pointer to driver SLI ring object.
1544 * This function is called with hbalock held to post pending iocbs
1545 * in the txq to the firmware. This function is called when driver
1546 * detects space available in the ring.
1549 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1552 struct lpfc_iocbq
*nextiocb
;
1556 * (a) there is anything on the txq to send
1558 * (c) link attention events can be processed (fcp ring only)
1559 * (d) IOCB processing is not blocked by the outstanding mbox command.
1561 if (pring
->txq_cnt
&&
1562 lpfc_is_link_up(phba
) &&
1563 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1564 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1566 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1567 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1568 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1571 lpfc_sli_update_ring(phba
, pring
);
1573 lpfc_sli_update_full_ring(phba
, pring
);
1580 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1581 * @phba: Pointer to HBA context object.
1582 * @hbqno: HBQ number.
1584 * This function is called with hbalock held to get the next
1585 * available slot for the given HBQ. If there is free slot
1586 * available for the HBQ it will return pointer to the next available
1587 * HBQ entry else it will return NULL.
1589 static struct lpfc_hbq_entry
*
1590 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1592 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1594 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1595 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1596 hbqp
->next_hbqPutIdx
= 0;
1598 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1599 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1600 uint32_t getidx
= le32_to_cpu(raw_index
);
1602 hbqp
->local_hbqGetIdx
= getidx
;
1604 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1605 lpfc_printf_log(phba
, KERN_ERR
,
1606 LOG_SLI
| LOG_VPORT
,
1607 "1802 HBQ %d: local_hbqGetIdx "
1608 "%u is > than hbqp->entry_count %u\n",
1609 hbqno
, hbqp
->local_hbqGetIdx
,
1612 phba
->link_state
= LPFC_HBA_ERROR
;
1616 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1620 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1625 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1626 * @phba: Pointer to HBA context object.
1628 * This function is called with no lock held to free all the
1629 * hbq buffers while uninitializing the SLI interface. It also
1630 * frees the HBQ buffers returned by the firmware but not yet
1631 * processed by the upper layers.
1634 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1636 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1637 struct hbq_dmabuf
*hbq_buf
;
1638 unsigned long flags
;
1642 hbq_count
= lpfc_sli_hbq_count();
1643 /* Return all memory used by all HBQs */
1644 spin_lock_irqsave(&phba
->hbalock
, flags
);
1645 for (i
= 0; i
< hbq_count
; ++i
) {
1646 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1647 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1648 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1649 list_del(&hbq_buf
->dbuf
.list
);
1650 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1652 phba
->hbqs
[i
].buffer_count
= 0;
1654 /* Return all HBQ buffer that are in-fly */
1655 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1657 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1658 list_del(&hbq_buf
->dbuf
.list
);
1659 if (hbq_buf
->tag
== -1) {
1660 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1663 hbqno
= hbq_buf
->tag
>> 16;
1664 if (hbqno
>= LPFC_MAX_HBQS
)
1665 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1668 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1673 /* Mark the HBQs not in use */
1674 phba
->hbq_in_use
= 0;
1675 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1679 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1680 * @phba: Pointer to HBA context object.
1681 * @hbqno: HBQ number.
1682 * @hbq_buf: Pointer to HBQ buffer.
1684 * This function is called with the hbalock held to post a
1685 * hbq buffer to the firmware. If the function finds an empty
1686 * slot in the HBQ, it will post the buffer. The function will return
1687 * pointer to the hbq entry if it successfully post the buffer
1688 * else it will return NULL.
1691 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1692 struct hbq_dmabuf
*hbq_buf
)
1694 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1698 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1699 * @phba: Pointer to HBA context object.
1700 * @hbqno: HBQ number.
1701 * @hbq_buf: Pointer to HBQ buffer.
1703 * This function is called with the hbalock held to post a hbq buffer to the
1704 * firmware. If the function finds an empty slot in the HBQ, it will post the
1705 * buffer and place it on the hbq_buffer_list. The function will return zero if
1706 * it successfully post the buffer else it will return an error.
1709 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1710 struct hbq_dmabuf
*hbq_buf
)
1712 struct lpfc_hbq_entry
*hbqe
;
1713 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1715 /* Get next HBQ entry slot to use */
1716 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1718 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1720 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1721 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1722 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1723 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1724 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1725 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1727 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1728 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1730 readl(phba
->hbq_put
+ hbqno
);
1731 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1738 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1739 * @phba: Pointer to HBA context object.
1740 * @hbqno: HBQ number.
1741 * @hbq_buf: Pointer to HBQ buffer.
1743 * This function is called with the hbalock held to post an RQE to the SLI4
1744 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1745 * the hbq_buffer_list and return zero, otherwise it will return an error.
1748 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1749 struct hbq_dmabuf
*hbq_buf
)
1752 struct lpfc_rqe hrqe
;
1753 struct lpfc_rqe drqe
;
1755 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1756 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1757 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1758 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1759 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1764 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1768 /* HBQ for ELS and CT traffic. */
1769 static struct lpfc_hbq_init lpfc_els_hbq
= {
1774 .ring_mask
= (1 << LPFC_ELS_RING
),
1780 /* HBQ for the extra ring if needed */
1781 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1786 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1793 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1799 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1800 * @phba: Pointer to HBA context object.
1801 * @hbqno: HBQ number.
1802 * @count: Number of HBQ buffers to be posted.
1804 * This function is called with no lock held to post more hbq buffers to the
1805 * given HBQ. The function returns the number of HBQ buffers successfully
1809 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1811 uint32_t i
, posted
= 0;
1812 unsigned long flags
;
1813 struct hbq_dmabuf
*hbq_buffer
;
1814 LIST_HEAD(hbq_buf_list
);
1815 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1818 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1819 lpfc_hbq_defs
[hbqno
]->entry_count
)
1820 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1821 phba
->hbqs
[hbqno
].buffer_count
;
1824 /* Allocate HBQ entries */
1825 for (i
= 0; i
< count
; i
++) {
1826 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1829 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1831 /* Check whether HBQ is still in use */
1832 spin_lock_irqsave(&phba
->hbalock
, flags
);
1833 if (!phba
->hbq_in_use
)
1835 while (!list_empty(&hbq_buf_list
)) {
1836 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1838 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1840 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1841 phba
->hbqs
[hbqno
].buffer_count
++;
1844 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1846 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1849 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1850 while (!list_empty(&hbq_buf_list
)) {
1851 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1853 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1859 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1860 * @phba: Pointer to HBA context object.
1863 * This function posts more buffers to the HBQ. This function
1864 * is called with no lock held. The function returns the number of HBQ entries
1865 * successfully allocated.
1868 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1870 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1873 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1874 lpfc_hbq_defs
[qno
]->add_count
);
1878 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1879 * @phba: Pointer to HBA context object.
1880 * @qno: HBQ queue number.
1882 * This function is called from SLI initialization code path with
1883 * no lock held to post initial HBQ buffers to firmware. The
1884 * function returns the number of HBQ entries successfully allocated.
1887 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1889 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1890 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1891 lpfc_hbq_defs
[qno
]->entry_count
);
1893 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1894 lpfc_hbq_defs
[qno
]->init_count
);
1898 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1899 * @phba: Pointer to HBA context object.
1900 * @hbqno: HBQ number.
1902 * This function removes the first hbq buffer on an hbq list and returns a
1903 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1905 static struct hbq_dmabuf
*
1906 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1908 struct lpfc_dmabuf
*d_buf
;
1910 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1913 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1917 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1918 * @phba: Pointer to HBA context object.
1919 * @tag: Tag of the hbq buffer.
1921 * This function is called with hbalock held. This function searches
1922 * for the hbq buffer associated with the given tag in the hbq buffer
1923 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1926 static struct hbq_dmabuf
*
1927 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1929 struct lpfc_dmabuf
*d_buf
;
1930 struct hbq_dmabuf
*hbq_buf
;
1934 if (hbqno
>= LPFC_MAX_HBQS
)
1937 spin_lock_irq(&phba
->hbalock
);
1938 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1939 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1940 if (hbq_buf
->tag
== tag
) {
1941 spin_unlock_irq(&phba
->hbalock
);
1945 spin_unlock_irq(&phba
->hbalock
);
1946 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1947 "1803 Bad hbq tag. Data: x%x x%x\n",
1948 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1953 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1954 * @phba: Pointer to HBA context object.
1955 * @hbq_buffer: Pointer to HBQ buffer.
1957 * This function is called with hbalock. This function gives back
1958 * the hbq buffer to firmware. If the HBQ does not have space to
1959 * post the buffer, it will free the buffer.
1962 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1967 hbqno
= hbq_buffer
->tag
>> 16;
1968 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1969 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1974 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1975 * @mbxCommand: mailbox command code.
1977 * This function is called by the mailbox event handler function to verify
1978 * that the completed mailbox command is a legitimate mailbox command. If the
1979 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
1980 * and the mailbox event handler will take the HBA offline.
1983 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
1987 switch (mbxCommand
) {
1991 case MBX_WRITE_VPARMS
:
1992 case MBX_RUN_BIU_DIAG
:
1995 case MBX_CONFIG_LINK
:
1996 case MBX_CONFIG_RING
:
1997 case MBX_RESET_RING
:
1998 case MBX_READ_CONFIG
:
1999 case MBX_READ_RCONFIG
:
2000 case MBX_READ_SPARM
:
2001 case MBX_READ_STATUS
:
2005 case MBX_READ_LNK_STAT
:
2007 case MBX_UNREG_LOGIN
:
2009 case MBX_DUMP_MEMORY
:
2010 case MBX_DUMP_CONTEXT
:
2013 case MBX_UPDATE_CFG
:
2015 case MBX_DEL_LD_ENTRY
:
2016 case MBX_RUN_PROGRAM
:
2018 case MBX_SET_VARIABLE
:
2019 case MBX_UNREG_D_ID
:
2020 case MBX_KILL_BOARD
:
2021 case MBX_CONFIG_FARP
:
2024 case MBX_RUN_BIU_DIAG64
:
2025 case MBX_CONFIG_PORT
:
2026 case MBX_READ_SPARM64
:
2027 case MBX_READ_RPI64
:
2028 case MBX_REG_LOGIN64
:
2029 case MBX_READ_TOPOLOGY
:
2032 case MBX_LOAD_EXP_ROM
:
2033 case MBX_ASYNCEVT_ENABLE
:
2037 case MBX_PORT_CAPABILITIES
:
2038 case MBX_PORT_IOV_CONTROL
:
2039 case MBX_SLI4_CONFIG
:
2040 case MBX_SLI4_REQ_FTRS
:
2042 case MBX_UNREG_FCFI
:
2047 case MBX_RESUME_RPI
:
2048 case MBX_READ_EVENT_LOG_STATUS
:
2049 case MBX_READ_EVENT_LOG
:
2050 case MBX_SECURITY_MGMT
:
2062 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2063 * @phba: Pointer to HBA context object.
2064 * @pmboxq: Pointer to mailbox command.
2066 * This is completion handler function for mailbox commands issued from
2067 * lpfc_sli_issue_mbox_wait function. This function is called by the
2068 * mailbox event handler function with no lock held. This function
2069 * will wake up thread waiting on the wait queue pointed by context1
2073 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2075 wait_queue_head_t
*pdone_q
;
2076 unsigned long drvr_flag
;
2079 * If pdone_q is empty, the driver thread gave up waiting and
2080 * continued running.
2082 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2083 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2084 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2086 wake_up_interruptible(pdone_q
);
2087 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2093 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2094 * @phba: Pointer to HBA context object.
2095 * @pmb: Pointer to mailbox object.
2097 * This function is the default mailbox completion handler. It
2098 * frees the memory resources associated with the completed mailbox
2099 * command. If the completed command is a REG_LOGIN mailbox command,
2100 * this function will issue a UREG_LOGIN to re-claim the RPI.
2103 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2105 struct lpfc_vport
*vport
= pmb
->vport
;
2106 struct lpfc_dmabuf
*mp
;
2107 struct lpfc_nodelist
*ndlp
;
2108 struct Scsi_Host
*shost
;
2112 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2115 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2119 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
2120 (phba
->sli_rev
== LPFC_SLI_REV4
) &&
2121 (pmb
->u
.mb
.un
.varUnregLogin
.rsvd1
== 0x0))
2122 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
2125 * If a REG_LOGIN succeeded after node is destroyed or node
2126 * is in re-discovery driver need to cleanup the RPI.
2128 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2129 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2130 !pmb
->u
.mb
.mbxStatus
) {
2131 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2132 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
- phba
->vpi_base
;
2133 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2134 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2135 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2136 if (rc
!= MBX_NOT_FINISHED
)
2140 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2141 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2142 !pmb
->u
.mb
.mbxStatus
) {
2143 shost
= lpfc_shost_from_vport(vport
);
2144 spin_lock_irq(shost
->host_lock
);
2145 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2146 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2147 spin_unlock_irq(shost
->host_lock
);
2150 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2151 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2153 pmb
->context2
= NULL
;
2156 /* Check security permission status on INIT_LINK mailbox command */
2157 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2158 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2159 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2160 "2860 SLI authentication is required "
2161 "for INIT_LINK but has not done yet\n");
2163 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2164 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2166 mempool_free(pmb
, phba
->mbox_mem_pool
);
2170 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2171 * @phba: Pointer to HBA context object.
2173 * This function is called with no lock held. This function processes all
2174 * the completed mailbox commands and gives it to upper layers. The interrupt
2175 * service routine processes mailbox completion interrupt and adds completed
2176 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2177 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2178 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2179 * function returns the mailbox commands to the upper layer by calling the
2180 * completion handler function of each mailbox.
2183 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2190 phba
->sli
.slistat
.mbox_event
++;
2192 /* Get all completed mailboxe buffers into the cmplq */
2193 spin_lock_irq(&phba
->hbalock
);
2194 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2195 spin_unlock_irq(&phba
->hbalock
);
2197 /* Get a Mailbox buffer to setup mailbox commands for callback */
2199 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2205 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2207 lpfc_debugfs_disc_trc(pmb
->vport
,
2208 LPFC_DISC_TRC_MBOX_VPORT
,
2209 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2210 (uint32_t)pmbox
->mbxCommand
,
2211 pmbox
->un
.varWords
[0],
2212 pmbox
->un
.varWords
[1]);
2215 lpfc_debugfs_disc_trc(phba
->pport
,
2217 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2218 (uint32_t)pmbox
->mbxCommand
,
2219 pmbox
->un
.varWords
[0],
2220 pmbox
->un
.varWords
[1]);
2225 * It is a fatal error if unknown mbox command completion.
2227 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2229 /* Unknown mailbox command compl */
2230 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2231 "(%d):0323 Unknown Mailbox command "
2233 pmb
->vport
? pmb
->vport
->vpi
: 0,
2235 lpfc_sli4_mbox_opcode_get(phba
, pmb
));
2236 phba
->link_state
= LPFC_HBA_ERROR
;
2237 phba
->work_hs
= HS_FFER3
;
2238 lpfc_handle_eratt(phba
);
2242 if (pmbox
->mbxStatus
) {
2243 phba
->sli
.slistat
.mbox_stat_err
++;
2244 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2245 /* Mbox cmd cmpl error - RETRYing */
2246 lpfc_printf_log(phba
, KERN_INFO
,
2248 "(%d):0305 Mbox cmd cmpl "
2249 "error - RETRYing Data: x%x "
2250 "(x%x) x%x x%x x%x\n",
2251 pmb
->vport
? pmb
->vport
->vpi
:0,
2253 lpfc_sli4_mbox_opcode_get(phba
,
2256 pmbox
->un
.varWords
[0],
2257 pmb
->vport
->port_state
);
2258 pmbox
->mbxStatus
= 0;
2259 pmbox
->mbxOwner
= OWN_HOST
;
2260 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2261 if (rc
!= MBX_NOT_FINISHED
)
2266 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2267 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2268 "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
2269 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2270 pmb
->vport
? pmb
->vport
->vpi
: 0,
2272 lpfc_sli4_mbox_opcode_get(phba
, pmb
),
2274 *((uint32_t *) pmbox
),
2275 pmbox
->un
.varWords
[0],
2276 pmbox
->un
.varWords
[1],
2277 pmbox
->un
.varWords
[2],
2278 pmbox
->un
.varWords
[3],
2279 pmbox
->un
.varWords
[4],
2280 pmbox
->un
.varWords
[5],
2281 pmbox
->un
.varWords
[6],
2282 pmbox
->un
.varWords
[7]);
2285 pmb
->mbox_cmpl(phba
,pmb
);
2291 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2292 * @phba: Pointer to HBA context object.
2293 * @pring: Pointer to driver SLI ring object.
2296 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2297 * is set in the tag the buffer is posted for a particular exchange,
2298 * the function will return the buffer without replacing the buffer.
2299 * If the buffer is for unsolicited ELS or CT traffic, this function
2300 * returns the buffer and also posts another buffer to the firmware.
2302 static struct lpfc_dmabuf
*
2303 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2304 struct lpfc_sli_ring
*pring
,
2307 struct hbq_dmabuf
*hbq_entry
;
2309 if (tag
& QUE_BUFTAG_BIT
)
2310 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2311 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2314 return &hbq_entry
->dbuf
;
2318 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2319 * @phba: Pointer to HBA context object.
2320 * @pring: Pointer to driver SLI ring object.
2321 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2322 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2323 * @fch_type: the type for the first frame of the sequence.
2325 * This function is called with no lock held. This function uses the r_ctl and
2326 * type of the received sequence to find the correct callback function to call
2327 * to process the sequence.
2330 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2331 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2336 /* unSolicited Responses */
2337 if (pring
->prt
[0].profile
) {
2338 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2339 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2343 /* We must search, based on rctl / type
2344 for the right routine */
2345 for (i
= 0; i
< pring
->num_mask
; i
++) {
2346 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2347 (pring
->prt
[i
].type
== fch_type
)) {
2348 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2349 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2350 (phba
, pring
, saveq
);
2358 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2359 * @phba: Pointer to HBA context object.
2360 * @pring: Pointer to driver SLI ring object.
2361 * @saveq: Pointer to the unsolicited iocb.
2363 * This function is called with no lock held by the ring event handler
2364 * when there is an unsolicited iocb posted to the response ring by the
2365 * firmware. This function gets the buffer associated with the iocbs
2366 * and calls the event handler for the ring. This function handles both
2367 * qring buffers and hbq buffers.
2368 * When the function returns 1 the caller can free the iocb object otherwise
2369 * upper layer functions will free the iocb objects.
2372 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2373 struct lpfc_iocbq
*saveq
)
2377 uint32_t Rctl
, Type
;
2379 struct lpfc_iocbq
*iocbq
;
2380 struct lpfc_dmabuf
*dmzbuf
;
2383 irsp
= &(saveq
->iocb
);
2385 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2386 if (pring
->lpfc_sli_rcv_async_status
)
2387 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2389 lpfc_printf_log(phba
,
2392 "0316 Ring %d handler: unexpected "
2393 "ASYNC_STATUS iocb received evt_code "
2396 irsp
->un
.asyncstat
.evt_code
);
2400 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2401 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2402 if (irsp
->ulpBdeCount
> 0) {
2403 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2404 irsp
->un
.ulpWord
[3]);
2405 lpfc_in_buf_free(phba
, dmzbuf
);
2408 if (irsp
->ulpBdeCount
> 1) {
2409 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2410 irsp
->unsli3
.sli3Words
[3]);
2411 lpfc_in_buf_free(phba
, dmzbuf
);
2414 if (irsp
->ulpBdeCount
> 2) {
2415 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2416 irsp
->unsli3
.sli3Words
[7]);
2417 lpfc_in_buf_free(phba
, dmzbuf
);
2423 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2424 if (irsp
->ulpBdeCount
!= 0) {
2425 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2426 irsp
->un
.ulpWord
[3]);
2427 if (!saveq
->context2
)
2428 lpfc_printf_log(phba
,
2431 "0341 Ring %d Cannot find buffer for "
2432 "an unsolicited iocb. tag 0x%x\n",
2434 irsp
->un
.ulpWord
[3]);
2436 if (irsp
->ulpBdeCount
== 2) {
2437 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2438 irsp
->unsli3
.sli3Words
[7]);
2439 if (!saveq
->context3
)
2440 lpfc_printf_log(phba
,
2443 "0342 Ring %d Cannot find buffer for an"
2444 " unsolicited iocb. tag 0x%x\n",
2446 irsp
->unsli3
.sli3Words
[7]);
2448 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2449 irsp
= &(iocbq
->iocb
);
2450 if (irsp
->ulpBdeCount
!= 0) {
2451 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2452 irsp
->un
.ulpWord
[3]);
2453 if (!iocbq
->context2
)
2454 lpfc_printf_log(phba
,
2457 "0343 Ring %d Cannot find "
2458 "buffer for an unsolicited iocb"
2459 ". tag 0x%x\n", pring
->ringno
,
2460 irsp
->un
.ulpWord
[3]);
2462 if (irsp
->ulpBdeCount
== 2) {
2463 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2464 irsp
->unsli3
.sli3Words
[7]);
2465 if (!iocbq
->context3
)
2466 lpfc_printf_log(phba
,
2469 "0344 Ring %d Cannot find "
2470 "buffer for an unsolicited "
2473 irsp
->unsli3
.sli3Words
[7]);
2477 if (irsp
->ulpBdeCount
!= 0 &&
2478 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2479 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2482 /* search continue save q for same XRI */
2483 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2484 if (iocbq
->iocb
.ulpContext
== saveq
->iocb
.ulpContext
) {
2485 list_add_tail(&saveq
->list
, &iocbq
->list
);
2491 list_add_tail(&saveq
->clist
,
2492 &pring
->iocb_continue_saveq
);
2493 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2494 list_del_init(&iocbq
->clist
);
2496 irsp
= &(saveq
->iocb
);
2500 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2501 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2502 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2503 Rctl
= FC_RCTL_ELS_REQ
;
2506 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2507 Rctl
= w5p
->hcsw
.Rctl
;
2508 Type
= w5p
->hcsw
.Type
;
2510 /* Firmware Workaround */
2511 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2512 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2513 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2514 Rctl
= FC_RCTL_ELS_REQ
;
2516 w5p
->hcsw
.Rctl
= Rctl
;
2517 w5p
->hcsw
.Type
= Type
;
2521 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2522 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2523 "0313 Ring %d handler: unexpected Rctl x%x "
2524 "Type x%x received\n",
2525 pring
->ringno
, Rctl
, Type
);
2531 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2532 * @phba: Pointer to HBA context object.
2533 * @pring: Pointer to driver SLI ring object.
2534 * @prspiocb: Pointer to response iocb object.
2536 * This function looks up the iocb_lookup table to get the command iocb
2537 * corresponding to the given response iocb using the iotag of the
2538 * response iocb. This function is called with the hbalock held.
2539 * This function returns the command iocb object if it finds the command
2540 * iocb else returns NULL.
2542 static struct lpfc_iocbq
*
2543 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2544 struct lpfc_sli_ring
*pring
,
2545 struct lpfc_iocbq
*prspiocb
)
2547 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2550 iotag
= prspiocb
->iocb
.ulpIoTag
;
2552 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2553 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2554 list_del_init(&cmd_iocb
->list
);
2555 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
2556 pring
->txcmplq_cnt
--;
2557 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
2562 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2563 "0317 iotag x%x is out off "
2564 "range: max iotag x%x wd0 x%x\n",
2565 iotag
, phba
->sli
.last_iotag
,
2566 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2571 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2572 * @phba: Pointer to HBA context object.
2573 * @pring: Pointer to driver SLI ring object.
2576 * This function looks up the iocb_lookup table to get the command iocb
2577 * corresponding to the given iotag. This function is called with the
2579 * This function returns the command iocb object if it finds the command
2580 * iocb else returns NULL.
2582 static struct lpfc_iocbq
*
2583 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2584 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2586 struct lpfc_iocbq
*cmd_iocb
;
2588 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2589 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2590 list_del_init(&cmd_iocb
->list
);
2591 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
2592 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
2593 pring
->txcmplq_cnt
--;
2598 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2599 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2600 iotag
, phba
->sli
.last_iotag
);
2605 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2606 * @phba: Pointer to HBA context object.
2607 * @pring: Pointer to driver SLI ring object.
2608 * @saveq: Pointer to the response iocb to be processed.
2610 * This function is called by the ring event handler for non-fcp
2611 * rings when there is a new response iocb in the response ring.
2612 * The caller is not required to hold any locks. This function
2613 * gets the command iocb associated with the response iocb and
2614 * calls the completion handler for the command iocb. If there
2615 * is no completion handler, the function will free the resources
2616 * associated with command iocb. If the response iocb is for
2617 * an already aborted command iocb, the status of the completion
2618 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2619 * This function always returns 1.
2622 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2623 struct lpfc_iocbq
*saveq
)
2625 struct lpfc_iocbq
*cmdiocbp
;
2627 unsigned long iflag
;
2629 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2630 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2631 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2632 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2635 if (cmdiocbp
->iocb_cmpl
) {
2637 * If an ELS command failed send an event to mgmt
2640 if (saveq
->iocb
.ulpStatus
&&
2641 (pring
->ringno
== LPFC_ELS_RING
) &&
2642 (cmdiocbp
->iocb
.ulpCommand
==
2643 CMD_ELS_REQUEST64_CR
))
2644 lpfc_send_els_failure_event(phba
,
2648 * Post all ELS completions to the worker thread.
2649 * All other are passed to the completion callback.
2651 if (pring
->ringno
== LPFC_ELS_RING
) {
2652 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2653 (cmdiocbp
->iocb_flag
&
2654 LPFC_DRIVER_ABORTED
)) {
2655 spin_lock_irqsave(&phba
->hbalock
,
2657 cmdiocbp
->iocb_flag
&=
2658 ~LPFC_DRIVER_ABORTED
;
2659 spin_unlock_irqrestore(&phba
->hbalock
,
2661 saveq
->iocb
.ulpStatus
=
2662 IOSTAT_LOCAL_REJECT
;
2663 saveq
->iocb
.un
.ulpWord
[4] =
2666 /* Firmware could still be in progress
2667 * of DMAing payload, so don't free data
2668 * buffer till after a hbeat.
2670 spin_lock_irqsave(&phba
->hbalock
,
2672 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2673 spin_unlock_irqrestore(&phba
->hbalock
,
2676 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2677 if (saveq
->iocb_flag
&
2678 LPFC_EXCHANGE_BUSY
) {
2679 /* Set cmdiocb flag for the
2680 * exchange busy so sgl (xri)
2681 * will not be released until
2682 * the abort xri is received
2686 &phba
->hbalock
, iflag
);
2687 cmdiocbp
->iocb_flag
|=
2689 spin_unlock_irqrestore(
2690 &phba
->hbalock
, iflag
);
2692 if (cmdiocbp
->iocb_flag
&
2693 LPFC_DRIVER_ABORTED
) {
2695 * Clear LPFC_DRIVER_ABORTED
2696 * bit in case it was driver
2700 &phba
->hbalock
, iflag
);
2701 cmdiocbp
->iocb_flag
&=
2702 ~LPFC_DRIVER_ABORTED
;
2703 spin_unlock_irqrestore(
2704 &phba
->hbalock
, iflag
);
2705 cmdiocbp
->iocb
.ulpStatus
=
2706 IOSTAT_LOCAL_REJECT
;
2707 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2708 IOERR_ABORT_REQUESTED
;
2710 * For SLI4, irsiocb contains
2711 * NO_XRI in sli_xritag, it
2712 * shall not affect releasing
2713 * sgl (xri) process.
2715 saveq
->iocb
.ulpStatus
=
2716 IOSTAT_LOCAL_REJECT
;
2717 saveq
->iocb
.un
.ulpWord
[4] =
2720 &phba
->hbalock
, iflag
);
2722 LPFC_DELAY_MEM_FREE
;
2723 spin_unlock_irqrestore(
2724 &phba
->hbalock
, iflag
);
2728 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2730 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2733 * Unknown initiating command based on the response iotag.
2734 * This could be the case on the ELS ring because of
2737 if (pring
->ringno
!= LPFC_ELS_RING
) {
2739 * Ring <ringno> handler: unexpected completion IoTag
2742 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2743 "0322 Ring %d handler: "
2744 "unexpected completion IoTag x%x "
2745 "Data: x%x x%x x%x x%x\n",
2747 saveq
->iocb
.ulpIoTag
,
2748 saveq
->iocb
.ulpStatus
,
2749 saveq
->iocb
.un
.ulpWord
[4],
2750 saveq
->iocb
.ulpCommand
,
2751 saveq
->iocb
.ulpContext
);
2759 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2760 * @phba: Pointer to HBA context object.
2761 * @pring: Pointer to driver SLI ring object.
2763 * This function is called from the iocb ring event handlers when
2764 * put pointer is ahead of the get pointer for a ring. This function signal
2765 * an error attention condition to the worker thread and the worker
2766 * thread will transition the HBA to offline state.
2769 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2771 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2773 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2774 * rsp ring <portRspMax>
2776 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2777 "0312 Ring %d handler: portRspPut %d "
2778 "is bigger than rsp ring %d\n",
2779 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2782 phba
->link_state
= LPFC_HBA_ERROR
;
2785 * All error attention handlers are posted to
2788 phba
->work_ha
|= HA_ERATT
;
2789 phba
->work_hs
= HS_FFER3
;
2791 lpfc_worker_wake_up(phba
);
2797 * lpfc_poll_eratt - Error attention polling timer timeout handler
2798 * @ptr: Pointer to address of HBA context object.
2800 * This function is invoked by the Error Attention polling timer when the
2801 * timer times out. It will check the SLI Error Attention register for
2802 * possible attention events. If so, it will post an Error Attention event
2803 * and wake up worker thread to process it. Otherwise, it will set up the
2804 * Error Attention polling timer for the next poll.
2806 void lpfc_poll_eratt(unsigned long ptr
)
2808 struct lpfc_hba
*phba
;
2811 phba
= (struct lpfc_hba
*)ptr
;
2813 /* Check chip HA register for error event */
2814 eratt
= lpfc_sli_check_eratt(phba
);
2817 /* Tell the worker thread there is work to do */
2818 lpfc_worker_wake_up(phba
);
2820 /* Restart the timer for next eratt poll */
2821 mod_timer(&phba
->eratt_poll
, jiffies
+
2822 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2828 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2829 * @phba: Pointer to HBA context object.
2830 * @pring: Pointer to driver SLI ring object.
2831 * @mask: Host attention register mask for this ring.
2833 * This function is called from the interrupt context when there is a ring
2834 * event for the fcp ring. The caller does not hold any lock.
2835 * The function processes each response iocb in the response ring until it
2836 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2837 * LE bit set. The function will call the completion handler of the command iocb
2838 * if the response iocb indicates a completion for a command iocb or it is
2839 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2840 * function if this is an unsolicited iocb.
2841 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2842 * to check it explicitly.
2845 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2846 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2848 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2849 IOCB_t
*irsp
= NULL
;
2850 IOCB_t
*entry
= NULL
;
2851 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2852 struct lpfc_iocbq rspiocbq
;
2854 uint32_t portRspPut
, portRspMax
;
2856 lpfc_iocb_type type
;
2857 unsigned long iflag
;
2858 uint32_t rsp_cmpl
= 0;
2860 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2861 pring
->stats
.iocb_event
++;
2864 * The next available response entry should never exceed the maximum
2865 * entries. If it does, treat it as an adapter hardware error.
2867 portRspMax
= pring
->numRiocb
;
2868 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2869 if (unlikely(portRspPut
>= portRspMax
)) {
2870 lpfc_sli_rsp_pointers_error(phba
, pring
);
2871 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2874 if (phba
->fcp_ring_in_use
) {
2875 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2878 phba
->fcp_ring_in_use
= 1;
2881 while (pring
->rspidx
!= portRspPut
) {
2883 * Fetch an entry off the ring and copy it into a local data
2884 * structure. The copy involves a byte-swap since the
2885 * network byte order and pci byte orders are different.
2887 entry
= lpfc_resp_iocb(phba
, pring
);
2888 phba
->last_completion_time
= jiffies
;
2890 if (++pring
->rspidx
>= portRspMax
)
2893 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2894 (uint32_t *) &rspiocbq
.iocb
,
2895 phba
->iocb_rsp_size
);
2896 INIT_LIST_HEAD(&(rspiocbq
.list
));
2897 irsp
= &rspiocbq
.iocb
;
2899 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2900 pring
->stats
.iocb_rsp
++;
2903 if (unlikely(irsp
->ulpStatus
)) {
2905 * If resource errors reported from HBA, reduce
2906 * queuedepths of the SCSI device.
2908 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2909 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2910 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2911 phba
->lpfc_rampdown_queue_depth(phba
);
2912 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2915 /* Rsp ring <ringno> error: IOCB */
2916 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2917 "0336 Rsp Ring %d error: IOCB Data: "
2918 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2920 irsp
->un
.ulpWord
[0],
2921 irsp
->un
.ulpWord
[1],
2922 irsp
->un
.ulpWord
[2],
2923 irsp
->un
.ulpWord
[3],
2924 irsp
->un
.ulpWord
[4],
2925 irsp
->un
.ulpWord
[5],
2926 *(uint32_t *)&irsp
->un1
,
2927 *((uint32_t *)&irsp
->un1
+ 1));
2931 case LPFC_ABORT_IOCB
:
2934 * Idle exchange closed via ABTS from port. No iocb
2935 * resources need to be recovered.
2937 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2938 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2939 "0333 IOCB cmd 0x%x"
2940 " processed. Skipping"
2946 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2948 if (unlikely(!cmdiocbq
))
2950 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
2951 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
2952 if (cmdiocbq
->iocb_cmpl
) {
2953 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2954 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2956 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2959 case LPFC_UNSOL_IOCB
:
2960 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2961 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2962 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2965 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2966 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2967 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2968 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2970 dev_warn(&((phba
->pcidev
)->dev
),
2972 phba
->brd_no
, adaptermsg
);
2974 /* Unknown IOCB command */
2975 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2976 "0334 Unknown IOCB command "
2977 "Data: x%x, x%x x%x x%x x%x\n",
2978 type
, irsp
->ulpCommand
,
2987 * The response IOCB has been processed. Update the ring
2988 * pointer in SLIM. If the port response put pointer has not
2989 * been updated, sync the pgp->rspPutInx and fetch the new port
2990 * response put pointer.
2992 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
2994 if (pring
->rspidx
== portRspPut
)
2995 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2998 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
2999 pring
->stats
.iocb_rsp_full
++;
3000 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3001 writel(status
, phba
->CAregaddr
);
3002 readl(phba
->CAregaddr
);
3004 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3005 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3006 pring
->stats
.iocb_cmd_empty
++;
3008 /* Force update of the local copy of cmdGetInx */
3009 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3010 lpfc_sli_resume_iocb(phba
, pring
);
3012 if ((pring
->lpfc_sli_cmd_available
))
3013 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3017 phba
->fcp_ring_in_use
= 0;
3018 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3023 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3024 * @phba: Pointer to HBA context object.
3025 * @pring: Pointer to driver SLI ring object.
3026 * @rspiocbp: Pointer to driver response IOCB object.
3028 * This function is called from the worker thread when there is a slow-path
3029 * response IOCB to process. This function chains all the response iocbs until
3030 * seeing the iocb with the LE bit set. The function will call
3031 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3032 * completion of a command iocb. The function will call the
3033 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3034 * The function frees the resources or calls the completion handler if this
3035 * iocb is an abort completion. The function returns NULL when the response
3036 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3037 * this function shall chain the iocb on to the iocb_continueq and return the
3038 * response iocb passed in.
3040 static struct lpfc_iocbq
*
3041 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3042 struct lpfc_iocbq
*rspiocbp
)
3044 struct lpfc_iocbq
*saveq
;
3045 struct lpfc_iocbq
*cmdiocbp
;
3046 struct lpfc_iocbq
*next_iocb
;
3047 IOCB_t
*irsp
= NULL
;
3048 uint32_t free_saveq
;
3049 uint8_t iocb_cmd_type
;
3050 lpfc_iocb_type type
;
3051 unsigned long iflag
;
3054 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3055 /* First add the response iocb to the countinueq list */
3056 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3057 pring
->iocb_continueq_cnt
++;
3059 /* Now, determine whetehr the list is completed for processing */
3060 irsp
= &rspiocbp
->iocb
;
3063 * By default, the driver expects to free all resources
3064 * associated with this iocb completion.
3067 saveq
= list_get_first(&pring
->iocb_continueq
,
3068 struct lpfc_iocbq
, list
);
3069 irsp
= &(saveq
->iocb
);
3070 list_del_init(&pring
->iocb_continueq
);
3071 pring
->iocb_continueq_cnt
= 0;
3073 pring
->stats
.iocb_rsp
++;
3076 * If resource errors reported from HBA, reduce
3077 * queuedepths of the SCSI device.
3079 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3080 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
3081 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3082 phba
->lpfc_rampdown_queue_depth(phba
);
3083 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3086 if (irsp
->ulpStatus
) {
3087 /* Rsp ring <ringno> error: IOCB */
3088 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3089 "0328 Rsp Ring %d error: "
3094 "x%x x%x x%x x%x\n",
3096 irsp
->un
.ulpWord
[0],
3097 irsp
->un
.ulpWord
[1],
3098 irsp
->un
.ulpWord
[2],
3099 irsp
->un
.ulpWord
[3],
3100 irsp
->un
.ulpWord
[4],
3101 irsp
->un
.ulpWord
[5],
3102 *(((uint32_t *) irsp
) + 6),
3103 *(((uint32_t *) irsp
) + 7),
3104 *(((uint32_t *) irsp
) + 8),
3105 *(((uint32_t *) irsp
) + 9),
3106 *(((uint32_t *) irsp
) + 10),
3107 *(((uint32_t *) irsp
) + 11),
3108 *(((uint32_t *) irsp
) + 12),
3109 *(((uint32_t *) irsp
) + 13),
3110 *(((uint32_t *) irsp
) + 14),
3111 *(((uint32_t *) irsp
) + 15));
3115 * Fetch the IOCB command type and call the correct completion
3116 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3117 * get freed back to the lpfc_iocb_list by the discovery
3120 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3121 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3124 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3125 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3126 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3129 case LPFC_UNSOL_IOCB
:
3130 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3131 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3132 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3137 case LPFC_ABORT_IOCB
:
3139 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3140 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3143 /* Call the specified completion routine */
3144 if (cmdiocbp
->iocb_cmpl
) {
3145 spin_unlock_irqrestore(&phba
->hbalock
,
3147 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3149 spin_lock_irqsave(&phba
->hbalock
,
3152 __lpfc_sli_release_iocbq(phba
,
3157 case LPFC_UNKNOWN_IOCB
:
3158 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3159 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3160 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3161 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3163 dev_warn(&((phba
->pcidev
)->dev
),
3165 phba
->brd_no
, adaptermsg
);
3167 /* Unknown IOCB command */
3168 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3169 "0335 Unknown IOCB "
3170 "command Data: x%x "
3181 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3182 &saveq
->list
, list
) {
3183 list_del(&rspiocbp
->list
);
3184 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3186 __lpfc_sli_release_iocbq(phba
, saveq
);
3190 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3195 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3196 * @phba: Pointer to HBA context object.
3197 * @pring: Pointer to driver SLI ring object.
3198 * @mask: Host attention register mask for this ring.
3200 * This routine wraps the actual slow_ring event process routine from the
3201 * API jump table function pointer from the lpfc_hba struct.
3204 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3205 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3207 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3211 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3212 * @phba: Pointer to HBA context object.
3213 * @pring: Pointer to driver SLI ring object.
3214 * @mask: Host attention register mask for this ring.
3216 * This function is called from the worker thread when there is a ring event
3217 * for non-fcp rings. The caller does not hold any lock. The function will
3218 * remove each response iocb in the response ring and calls the handle
3219 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3222 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3223 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3225 struct lpfc_pgp
*pgp
;
3227 IOCB_t
*irsp
= NULL
;
3228 struct lpfc_iocbq
*rspiocbp
= NULL
;
3229 uint32_t portRspPut
, portRspMax
;
3230 unsigned long iflag
;
3233 pgp
= &phba
->port_gp
[pring
->ringno
];
3234 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3235 pring
->stats
.iocb_event
++;
3238 * The next available response entry should never exceed the maximum
3239 * entries. If it does, treat it as an adapter hardware error.
3241 portRspMax
= pring
->numRiocb
;
3242 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3243 if (portRspPut
>= portRspMax
) {
3245 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3246 * rsp ring <portRspMax>
3248 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3249 "0303 Ring %d handler: portRspPut %d "
3250 "is bigger than rsp ring %d\n",
3251 pring
->ringno
, portRspPut
, portRspMax
);
3253 phba
->link_state
= LPFC_HBA_ERROR
;
3254 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3256 phba
->work_hs
= HS_FFER3
;
3257 lpfc_handle_eratt(phba
);
3263 while (pring
->rspidx
!= portRspPut
) {
3265 * Build a completion list and call the appropriate handler.
3266 * The process is to get the next available response iocb, get
3267 * a free iocb from the list, copy the response data into the
3268 * free iocb, insert to the continuation list, and update the
3269 * next response index to slim. This process makes response
3270 * iocb's in the ring available to DMA as fast as possible but
3271 * pays a penalty for a copy operation. Since the iocb is
3272 * only 32 bytes, this penalty is considered small relative to
3273 * the PCI reads for register values and a slim write. When
3274 * the ulpLe field is set, the entire Command has been
3277 entry
= lpfc_resp_iocb(phba
, pring
);
3279 phba
->last_completion_time
= jiffies
;
3280 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3281 if (rspiocbp
== NULL
) {
3282 printk(KERN_ERR
"%s: out of buffers! Failing "
3283 "completion.\n", __func__
);
3287 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3288 phba
->iocb_rsp_size
);
3289 irsp
= &rspiocbp
->iocb
;
3291 if (++pring
->rspidx
>= portRspMax
)
3294 if (pring
->ringno
== LPFC_ELS_RING
) {
3295 lpfc_debugfs_slow_ring_trc(phba
,
3296 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3297 *(((uint32_t *) irsp
) + 4),
3298 *(((uint32_t *) irsp
) + 6),
3299 *(((uint32_t *) irsp
) + 7));
3302 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3304 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3305 /* Handle the response IOCB */
3306 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3307 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3310 * If the port response put pointer has not been updated, sync
3311 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3312 * response put pointer.
3314 if (pring
->rspidx
== portRspPut
) {
3315 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3317 } /* while (pring->rspidx != portRspPut) */
3319 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3320 /* At least one response entry has been freed */
3321 pring
->stats
.iocb_rsp_full
++;
3322 /* SET RxRE_RSP in Chip Att register */
3323 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3324 writel(status
, phba
->CAregaddr
);
3325 readl(phba
->CAregaddr
); /* flush */
3327 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3328 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3329 pring
->stats
.iocb_cmd_empty
++;
3331 /* Force update of the local copy of cmdGetInx */
3332 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3333 lpfc_sli_resume_iocb(phba
, pring
);
3335 if ((pring
->lpfc_sli_cmd_available
))
3336 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3340 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3345 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3346 * @phba: Pointer to HBA context object.
3347 * @pring: Pointer to driver SLI ring object.
3348 * @mask: Host attention register mask for this ring.
3350 * This function is called from the worker thread when there is a pending
3351 * ELS response iocb on the driver internal slow-path response iocb worker
3352 * queue. The caller does not hold any lock. The function will remove each
3353 * response iocb from the response worker queue and calls the handle
3354 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3357 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3358 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3360 struct lpfc_iocbq
*irspiocbq
;
3361 struct hbq_dmabuf
*dmabuf
;
3362 struct lpfc_cq_event
*cq_event
;
3363 unsigned long iflag
;
3365 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3366 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3367 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3368 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3369 /* Get the response iocb from the head of work queue */
3370 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3371 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3372 cq_event
, struct lpfc_cq_event
, list
);
3373 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3375 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3376 case CQE_CODE_COMPL_WQE
:
3377 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3379 /* Translate ELS WCQE to response IOCBQ */
3380 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3383 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3386 case CQE_CODE_RECEIVE
:
3387 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3389 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3398 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3399 * @phba: Pointer to HBA context object.
3400 * @pring: Pointer to driver SLI ring object.
3402 * This function aborts all iocbs in the given ring and frees all the iocb
3403 * objects in txq. This function issues an abort iocb for all the iocb commands
3404 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3405 * the return of this function. The caller is not required to hold any locks.
3408 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3410 LIST_HEAD(completions
);
3411 struct lpfc_iocbq
*iocb
, *next_iocb
;
3413 if (pring
->ringno
== LPFC_ELS_RING
) {
3414 lpfc_fabric_abort_hba(phba
);
3417 /* Error everything on txq and txcmplq
3420 spin_lock_irq(&phba
->hbalock
);
3421 list_splice_init(&pring
->txq
, &completions
);
3424 /* Next issue ABTS for everything on the txcmplq */
3425 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3426 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3428 spin_unlock_irq(&phba
->hbalock
);
3430 /* Cancel all the IOCBs from the completions list */
3431 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3436 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3437 * @phba: Pointer to HBA context object.
3439 * This function flushes all iocbs in the fcp ring and frees all the iocb
3440 * objects in txq and txcmplq. This function will not issue abort iocbs
3441 * for all the iocb commands in txcmplq, they will just be returned with
3442 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3443 * slot has been permanently disabled.
3446 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3450 struct lpfc_sli
*psli
= &phba
->sli
;
3451 struct lpfc_sli_ring
*pring
;
3453 /* Currently, only one fcp ring */
3454 pring
= &psli
->ring
[psli
->fcp_ring
];
3456 spin_lock_irq(&phba
->hbalock
);
3457 /* Retrieve everything on txq */
3458 list_splice_init(&pring
->txq
, &txq
);
3461 /* Retrieve everything on the txcmplq */
3462 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3463 pring
->txcmplq_cnt
= 0;
3464 spin_unlock_irq(&phba
->hbalock
);
3467 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3470 /* Flush the txcmpq */
3471 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3476 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3477 * @phba: Pointer to HBA context object.
3478 * @mask: Bit mask to be checked.
3480 * This function reads the host status register and compares
3481 * with the provided bit mask to check if HBA completed
3482 * the restart. This function will wait in a loop for the
3483 * HBA to complete restart. If the HBA does not restart within
3484 * 15 iterations, the function will reset the HBA again. The
3485 * function returns 1 when HBA fail to restart otherwise returns
3489 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3495 /* Read the HBA Host Status Register */
3496 status
= readl(phba
->HSregaddr
);
3499 * Check status register every 100ms for 5 retries, then every
3500 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3501 * every 2.5 sec for 4.
3502 * Break our of the loop if errors occurred during init.
3504 while (((status
& mask
) != mask
) &&
3505 !(status
& HS_FFERM
) &&
3517 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3518 lpfc_sli_brdrestart(phba
);
3520 /* Read the HBA Host Status Register */
3521 status
= readl(phba
->HSregaddr
);
3524 /* Check to see if any errors occurred during init */
3525 if ((status
& HS_FFERM
) || (i
>= 20)) {
3526 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3527 "2751 Adapter failed to restart, "
3528 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3530 readl(phba
->MBslimaddr
+ 0xa8),
3531 readl(phba
->MBslimaddr
+ 0xac));
3532 phba
->link_state
= LPFC_HBA_ERROR
;
3540 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3541 * @phba: Pointer to HBA context object.
3542 * @mask: Bit mask to be checked.
3544 * This function checks the host status register to check if HBA is
3545 * ready. This function will wait in a loop for the HBA to be ready
3546 * If the HBA is not ready , the function will will reset the HBA PCI
3547 * function again. The function returns 1 when HBA fail to be ready
3548 * otherwise returns zero.
3551 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3556 /* Read the HBA Host Status Register */
3557 status
= lpfc_sli4_post_status_check(phba
);
3560 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3561 lpfc_sli_brdrestart(phba
);
3562 status
= lpfc_sli4_post_status_check(phba
);
3565 /* Check to see if any errors occurred during init */
3567 phba
->link_state
= LPFC_HBA_ERROR
;
3570 phba
->sli4_hba
.intr_enable
= 0;
3576 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3577 * @phba: Pointer to HBA context object.
3578 * @mask: Bit mask to be checked.
3580 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3581 * from the API jump table function pointer from the lpfc_hba struct.
3584 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3586 return phba
->lpfc_sli_brdready(phba
, mask
);
3589 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3592 * lpfc_reset_barrier - Make HBA ready for HBA reset
3593 * @phba: Pointer to HBA context object.
3595 * This function is called before resetting an HBA. This
3596 * function requests HBA to quiesce DMAs before a reset.
3598 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3600 uint32_t __iomem
*resp_buf
;
3601 uint32_t __iomem
*mbox_buf
;
3602 volatile uint32_t mbox
;
3607 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3608 if (hdrtype
!= 0x80 ||
3609 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3610 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3614 * Tell the other part of the chip to suspend temporarily all
3617 resp_buf
= phba
->MBslimaddr
;
3619 /* Disable the error attention */
3620 hc_copy
= readl(phba
->HCregaddr
);
3621 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3622 readl(phba
->HCregaddr
); /* flush */
3623 phba
->link_flag
|= LS_IGNORE_ERATT
;
3625 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3626 /* Clear Chip error bit */
3627 writel(HA_ERATT
, phba
->HAregaddr
);
3628 phba
->pport
->stopped
= 1;
3632 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3633 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3635 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3636 mbox_buf
= phba
->MBslimaddr
;
3637 writel(mbox
, mbox_buf
);
3640 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
3643 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
3644 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3645 phba
->pport
->stopped
)
3651 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3652 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
3657 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
3660 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3661 writel(HA_ERATT
, phba
->HAregaddr
);
3662 phba
->pport
->stopped
= 1;
3666 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3667 writel(hc_copy
, phba
->HCregaddr
);
3668 readl(phba
->HCregaddr
); /* flush */
3672 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3673 * @phba: Pointer to HBA context object.
3675 * This function issues a kill_board mailbox command and waits for
3676 * the error attention interrupt. This function is called for stopping
3677 * the firmware processing. The caller is not required to hold any
3678 * locks. This function calls lpfc_hba_down_post function to free
3679 * any pending commands after the kill. The function will return 1 when it
3680 * fails to kill the board else will return 0.
3683 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3685 struct lpfc_sli
*psli
;
3695 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3696 "0329 Kill HBA Data: x%x x%x\n",
3697 phba
->pport
->port_state
, psli
->sli_flag
);
3699 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3703 /* Disable the error attention */
3704 spin_lock_irq(&phba
->hbalock
);
3705 status
= readl(phba
->HCregaddr
);
3706 status
&= ~HC_ERINT_ENA
;
3707 writel(status
, phba
->HCregaddr
);
3708 readl(phba
->HCregaddr
); /* flush */
3709 phba
->link_flag
|= LS_IGNORE_ERATT
;
3710 spin_unlock_irq(&phba
->hbalock
);
3712 lpfc_kill_board(phba
, pmb
);
3713 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3714 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3716 if (retval
!= MBX_SUCCESS
) {
3717 if (retval
!= MBX_BUSY
)
3718 mempool_free(pmb
, phba
->mbox_mem_pool
);
3719 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3720 "2752 KILL_BOARD command failed retval %d\n",
3722 spin_lock_irq(&phba
->hbalock
);
3723 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3724 spin_unlock_irq(&phba
->hbalock
);
3728 spin_lock_irq(&phba
->hbalock
);
3729 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3730 spin_unlock_irq(&phba
->hbalock
);
3732 mempool_free(pmb
, phba
->mbox_mem_pool
);
3734 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3735 * attention every 100ms for 3 seconds. If we don't get ERATT after
3736 * 3 seconds we still set HBA_ERROR state because the status of the
3737 * board is now undefined.
3739 ha_copy
= readl(phba
->HAregaddr
);
3741 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3743 ha_copy
= readl(phba
->HAregaddr
);
3746 del_timer_sync(&psli
->mbox_tmo
);
3747 if (ha_copy
& HA_ERATT
) {
3748 writel(HA_ERATT
, phba
->HAregaddr
);
3749 phba
->pport
->stopped
= 1;
3751 spin_lock_irq(&phba
->hbalock
);
3752 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3753 psli
->mbox_active
= NULL
;
3754 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3755 spin_unlock_irq(&phba
->hbalock
);
3757 lpfc_hba_down_post(phba
);
3758 phba
->link_state
= LPFC_HBA_ERROR
;
3760 return ha_copy
& HA_ERATT
? 0 : 1;
3764 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3765 * @phba: Pointer to HBA context object.
3767 * This function resets the HBA by writing HC_INITFF to the control
3768 * register. After the HBA resets, this function resets all the iocb ring
3769 * indices. This function disables PCI layer parity checking during
3771 * This function returns 0 always.
3772 * The caller is not required to hold any locks.
3775 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3777 struct lpfc_sli
*psli
;
3778 struct lpfc_sli_ring
*pring
;
3785 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3786 "0325 Reset HBA Data: x%x x%x\n",
3787 phba
->pport
->port_state
, psli
->sli_flag
);
3789 /* perform board reset */
3790 phba
->fc_eventTag
= 0;
3791 phba
->link_events
= 0;
3792 phba
->pport
->fc_myDID
= 0;
3793 phba
->pport
->fc_prevDID
= 0;
3795 /* Turn off parity checking and serr during the physical reset */
3796 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3797 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3799 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3801 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3803 /* Now toggle INITFF bit in the Host Control Register */
3804 writel(HC_INITFF
, phba
->HCregaddr
);
3806 readl(phba
->HCregaddr
); /* flush */
3807 writel(0, phba
->HCregaddr
);
3808 readl(phba
->HCregaddr
); /* flush */
3810 /* Restore PCI cmd register */
3811 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3813 /* Initialize relevant SLI info */
3814 for (i
= 0; i
< psli
->num_rings
; i
++) {
3815 pring
= &psli
->ring
[i
];
3818 pring
->next_cmdidx
= 0;
3819 pring
->local_getidx
= 0;
3821 pring
->missbufcnt
= 0;
3824 phba
->link_state
= LPFC_WARM_START
;
3829 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3830 * @phba: Pointer to HBA context object.
3832 * This function resets a SLI4 HBA. This function disables PCI layer parity
3833 * checking during resets the device. The caller is not required to hold
3836 * This function returns 0 always.
3839 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3841 struct lpfc_sli
*psli
= &phba
->sli
;
3846 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3847 "0295 Reset HBA Data: x%x x%x\n",
3848 phba
->pport
->port_state
, psli
->sli_flag
);
3850 /* perform board reset */
3851 phba
->fc_eventTag
= 0;
3852 phba
->link_events
= 0;
3853 phba
->pport
->fc_myDID
= 0;
3854 phba
->pport
->fc_prevDID
= 0;
3856 spin_lock_irq(&phba
->hbalock
);
3857 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3858 phba
->fcf
.fcf_flag
= 0;
3859 /* Clean up the child queue list for the CQs */
3860 list_del_init(&phba
->sli4_hba
.mbx_wq
->list
);
3861 list_del_init(&phba
->sli4_hba
.els_wq
->list
);
3862 list_del_init(&phba
->sli4_hba
.hdr_rq
->list
);
3863 list_del_init(&phba
->sli4_hba
.dat_rq
->list
);
3864 list_del_init(&phba
->sli4_hba
.mbx_cq
->list
);
3865 list_del_init(&phba
->sli4_hba
.els_cq
->list
);
3866 for (qindx
= 0; qindx
< phba
->cfg_fcp_wq_count
; qindx
++)
3867 list_del_init(&phba
->sli4_hba
.fcp_wq
[qindx
]->list
);
3868 for (qindx
= 0; qindx
< phba
->cfg_fcp_eq_count
; qindx
++)
3869 list_del_init(&phba
->sli4_hba
.fcp_cq
[qindx
]->list
);
3870 spin_unlock_irq(&phba
->hbalock
);
3872 /* Now physically reset the device */
3873 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3874 "0389 Performing PCI function reset!\n");
3876 /* Turn off parity checking and serr during the physical reset */
3877 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3878 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3879 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3881 /* Perform FCoE PCI function reset */
3882 lpfc_pci_function_reset(phba
);
3884 /* Restore PCI cmd register */
3885 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3891 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3892 * @phba: Pointer to HBA context object.
3894 * This function is called in the SLI initialization code path to
3895 * restart the HBA. The caller is not required to hold any lock.
3896 * This function writes MBX_RESTART mailbox command to the SLIM and
3897 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3898 * function to free any pending commands. The function enables
3899 * POST only during the first initialization. The function returns zero.
3900 * The function does not guarantee completion of MBX_RESTART mailbox
3901 * command before the return of this function.
3904 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3907 struct lpfc_sli
*psli
;
3908 volatile uint32_t word0
;
3909 void __iomem
*to_slim
;
3910 uint32_t hba_aer_enabled
;
3912 spin_lock_irq(&phba
->hbalock
);
3914 /* Take PCIe device Advanced Error Reporting (AER) state */
3915 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3920 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3921 "0337 Restart HBA Data: x%x x%x\n",
3922 phba
->pport
->port_state
, psli
->sli_flag
);
3925 mb
= (MAILBOX_t
*) &word0
;
3926 mb
->mbxCommand
= MBX_RESTART
;
3929 lpfc_reset_barrier(phba
);
3931 to_slim
= phba
->MBslimaddr
;
3932 writel(*(uint32_t *) mb
, to_slim
);
3933 readl(to_slim
); /* flush */
3935 /* Only skip post after fc_ffinit is completed */
3936 if (phba
->pport
->port_state
)
3937 word0
= 1; /* This is really setting up word1 */
3939 word0
= 0; /* This is really setting up word1 */
3940 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
3941 writel(*(uint32_t *) mb
, to_slim
);
3942 readl(to_slim
); /* flush */
3944 lpfc_sli_brdreset(phba
);
3945 phba
->pport
->stopped
= 0;
3946 phba
->link_state
= LPFC_INIT_START
;
3948 spin_unlock_irq(&phba
->hbalock
);
3950 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3951 psli
->stats_start
= get_seconds();
3953 /* Give the INITFF and Post time to settle. */
3956 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
3957 if (hba_aer_enabled
)
3958 pci_disable_pcie_error_reporting(phba
->pcidev
);
3960 lpfc_hba_down_post(phba
);
3966 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
3967 * @phba: Pointer to HBA context object.
3969 * This function is called in the SLI initialization code path to restart
3970 * a SLI4 HBA. The caller is not required to hold any lock.
3971 * At the end of the function, it calls lpfc_hba_down_post function to
3972 * free any pending commands.
3975 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
3977 struct lpfc_sli
*psli
= &phba
->sli
;
3978 uint32_t hba_aer_enabled
;
3981 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3982 "0296 Restart HBA Data: x%x x%x\n",
3983 phba
->pport
->port_state
, psli
->sli_flag
);
3985 /* Take PCIe device Advanced Error Reporting (AER) state */
3986 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3988 lpfc_sli4_brdreset(phba
);
3990 spin_lock_irq(&phba
->hbalock
);
3991 phba
->pport
->stopped
= 0;
3992 phba
->link_state
= LPFC_INIT_START
;
3994 spin_unlock_irq(&phba
->hbalock
);
3996 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3997 psli
->stats_start
= get_seconds();
3999 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4000 if (hba_aer_enabled
)
4001 pci_disable_pcie_error_reporting(phba
->pcidev
);
4003 lpfc_hba_down_post(phba
);
4009 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4010 * @phba: Pointer to HBA context object.
4012 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4013 * API jump table function pointer from the lpfc_hba struct.
4016 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4018 return phba
->lpfc_sli_brdrestart(phba
);
4022 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4023 * @phba: Pointer to HBA context object.
4025 * This function is called after a HBA restart to wait for successful
4026 * restart of the HBA. Successful restart of the HBA is indicated by
4027 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4028 * iteration, the function will restart the HBA again. The function returns
4029 * zero if HBA successfully restarted else returns negative error code.
4032 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4034 uint32_t status
, i
= 0;
4036 /* Read the HBA Host Status Register */
4037 status
= readl(phba
->HSregaddr
);
4039 /* Check status register to see what current state is */
4041 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4043 /* Check every 10ms for 10 retries, then every 100ms for 90
4044 * retries, then every 1 sec for 50 retires for a total of
4045 * ~60 seconds before reset the board again and check every
4046 * 1 sec for 50 retries. The up to 60 seconds before the
4047 * board ready is required by the Falcon FIPS zeroization
4048 * complete, and any reset the board in between shall cause
4049 * restart of zeroization, further delay the board ready.
4052 /* Adapter failed to init, timeout, status reg
4054 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4055 "0436 Adapter failed to init, "
4056 "timeout, status reg x%x, "
4057 "FW Data: A8 x%x AC x%x\n", status
,
4058 readl(phba
->MBslimaddr
+ 0xa8),
4059 readl(phba
->MBslimaddr
+ 0xac));
4060 phba
->link_state
= LPFC_HBA_ERROR
;
4064 /* Check to see if any errors occurred during init */
4065 if (status
& HS_FFERM
) {
4066 /* ERROR: During chipset initialization */
4067 /* Adapter failed to init, chipset, status reg
4069 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4070 "0437 Adapter failed to init, "
4071 "chipset, status reg x%x, "
4072 "FW Data: A8 x%x AC x%x\n", status
,
4073 readl(phba
->MBslimaddr
+ 0xa8),
4074 readl(phba
->MBslimaddr
+ 0xac));
4075 phba
->link_state
= LPFC_HBA_ERROR
;
4088 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4089 lpfc_sli_brdrestart(phba
);
4091 /* Read the HBA Host Status Register */
4092 status
= readl(phba
->HSregaddr
);
4095 /* Check to see if any errors occurred during init */
4096 if (status
& HS_FFERM
) {
4097 /* ERROR: During chipset initialization */
4098 /* Adapter failed to init, chipset, status reg <status> */
4099 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4100 "0438 Adapter failed to init, chipset, "
4102 "FW Data: A8 x%x AC x%x\n", status
,
4103 readl(phba
->MBslimaddr
+ 0xa8),
4104 readl(phba
->MBslimaddr
+ 0xac));
4105 phba
->link_state
= LPFC_HBA_ERROR
;
4109 /* Clear all interrupt enable conditions */
4110 writel(0, phba
->HCregaddr
);
4111 readl(phba
->HCregaddr
); /* flush */
4113 /* setup host attn register */
4114 writel(0xffffffff, phba
->HAregaddr
);
4115 readl(phba
->HAregaddr
); /* flush */
4120 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4122 * This function calculates and returns the number of HBQs required to be
4126 lpfc_sli_hbq_count(void)
4128 return ARRAY_SIZE(lpfc_hbq_defs
);
4132 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4134 * This function adds the number of hbq entries in every HBQ to get
4135 * the total number of hbq entries required for the HBA and returns
4139 lpfc_sli_hbq_entry_count(void)
4141 int hbq_count
= lpfc_sli_hbq_count();
4145 for (i
= 0; i
< hbq_count
; ++i
)
4146 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4151 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4153 * This function calculates amount of memory required for all hbq entries
4154 * to be configured and returns the total memory required.
4157 lpfc_sli_hbq_size(void)
4159 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4163 * lpfc_sli_hbq_setup - configure and initialize HBQs
4164 * @phba: Pointer to HBA context object.
4166 * This function is called during the SLI initialization to configure
4167 * all the HBQs and post buffers to the HBQ. The caller is not
4168 * required to hold any locks. This function will return zero if successful
4169 * else it will return negative error code.
4172 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4174 int hbq_count
= lpfc_sli_hbq_count();
4178 uint32_t hbq_entry_index
;
4180 /* Get a Mailbox buffer to setup mailbox
4181 * commands for HBA initialization
4183 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4190 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4191 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4192 phba
->hbq_in_use
= 1;
4194 hbq_entry_index
= 0;
4195 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4196 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4197 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4198 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4199 phba
->hbqs
[hbqno
].entry_count
=
4200 lpfc_hbq_defs
[hbqno
]->entry_count
;
4201 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4202 hbq_entry_index
, pmb
);
4203 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4205 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4206 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4207 mbxStatus <status>, ring <num> */
4209 lpfc_printf_log(phba
, KERN_ERR
,
4210 LOG_SLI
| LOG_VPORT
,
4211 "1805 Adapter failed to init. "
4212 "Data: x%x x%x x%x\n",
4214 pmbox
->mbxStatus
, hbqno
);
4216 phba
->link_state
= LPFC_HBA_ERROR
;
4217 mempool_free(pmb
, phba
->mbox_mem_pool
);
4221 phba
->hbq_count
= hbq_count
;
4223 mempool_free(pmb
, phba
->mbox_mem_pool
);
4225 /* Initially populate or replenish the HBQs */
4226 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4227 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4232 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4233 * @phba: Pointer to HBA context object.
4235 * This function is called during the SLI initialization to configure
4236 * all the HBQs and post buffers to the HBQ. The caller is not
4237 * required to hold any locks. This function will return zero if successful
4238 * else it will return negative error code.
4241 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4243 phba
->hbq_in_use
= 1;
4244 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4245 phba
->hbq_count
= 1;
4246 /* Initially populate or replenish the HBQs */
4247 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4252 * lpfc_sli_config_port - Issue config port mailbox command
4253 * @phba: Pointer to HBA context object.
4254 * @sli_mode: sli mode - 2/3
4256 * This function is called by the sli intialization code path
4257 * to issue config_port mailbox command. This function restarts the
4258 * HBA firmware and issues a config_port mailbox command to configure
4259 * the SLI interface in the sli mode specified by sli_mode
4260 * variable. The caller is not required to hold any locks.
4261 * The function returns 0 if successful, else returns negative error
4265 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4268 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4270 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4272 phba
->link_state
= LPFC_HBA_ERROR
;
4276 phba
->sli_rev
= sli_mode
;
4277 while (resetcount
< 2 && !done
) {
4278 spin_lock_irq(&phba
->hbalock
);
4279 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4280 spin_unlock_irq(&phba
->hbalock
);
4281 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4282 lpfc_sli_brdrestart(phba
);
4283 rc
= lpfc_sli_chipset_init(phba
);
4287 spin_lock_irq(&phba
->hbalock
);
4288 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4289 spin_unlock_irq(&phba
->hbalock
);
4292 /* Call pre CONFIG_PORT mailbox command initialization. A
4293 * value of 0 means the call was successful. Any other
4294 * nonzero value is a failure, but if ERESTART is returned,
4295 * the driver may reset the HBA and try again.
4297 rc
= lpfc_config_port_prep(phba
);
4298 if (rc
== -ERESTART
) {
4299 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4303 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4304 lpfc_config_port(phba
, pmb
);
4305 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4306 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4307 LPFC_SLI3_HBQ_ENABLED
|
4308 LPFC_SLI3_CRP_ENABLED
|
4309 LPFC_SLI3_BG_ENABLED
|
4310 LPFC_SLI3_DSS_ENABLED
);
4311 if (rc
!= MBX_SUCCESS
) {
4312 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4313 "0442 Adapter failed to init, mbxCmd x%x "
4314 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4315 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4316 spin_lock_irq(&phba
->hbalock
);
4317 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4318 spin_unlock_irq(&phba
->hbalock
);
4321 /* Allow asynchronous mailbox command to go through */
4322 spin_lock_irq(&phba
->hbalock
);
4323 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4324 spin_unlock_irq(&phba
->hbalock
);
4330 goto do_prep_failed
;
4332 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4333 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4335 goto do_prep_failed
;
4337 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4338 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4339 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4340 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4341 phba
->max_vpi
: phba
->max_vports
;
4345 phba
->fips_level
= 0;
4346 phba
->fips_spec_rev
= 0;
4347 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4348 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4349 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4350 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4351 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4352 "2850 Security Crypto Active. FIPS x%d "
4354 phba
->fips_level
, phba
->fips_spec_rev
);
4356 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4357 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4358 "2856 Config Port Security Crypto "
4360 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4362 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4363 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4364 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4365 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4367 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4368 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4370 if (phba
->cfg_enable_bg
) {
4371 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4372 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4374 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4375 "0443 Adapter did not grant "
4379 phba
->hbq_get
= NULL
;
4380 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4384 mempool_free(pmb
, phba
->mbox_mem_pool
);
4390 * lpfc_sli_hba_setup - SLI intialization function
4391 * @phba: Pointer to HBA context object.
4393 * This function is the main SLI intialization function. This function
4394 * is called by the HBA intialization code, HBA reset code and HBA
4395 * error attention handler code. Caller is not required to hold any
4396 * locks. This function issues config_port mailbox command to configure
4397 * the SLI, setup iocb rings and HBQ rings. In the end the function
4398 * calls the config_port_post function to issue init_link mailbox
4399 * command and to start the discovery. The function will return zero
4400 * if successful, else it will return negative error code.
4403 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4408 switch (lpfc_sli_mode
) {
4410 if (phba
->cfg_enable_npiv
) {
4411 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4412 "1824 NPIV enabled: Override lpfc_sli_mode "
4413 "parameter (%d) to auto (0).\n",
4423 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4424 "1819 Unrecognized lpfc_sli_mode "
4425 "parameter: %d.\n", lpfc_sli_mode
);
4430 rc
= lpfc_sli_config_port(phba
, mode
);
4432 if (rc
&& lpfc_sli_mode
== 3)
4433 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4434 "1820 Unable to select SLI-3. "
4435 "Not supported by adapter.\n");
4436 if (rc
&& mode
!= 2)
4437 rc
= lpfc_sli_config_port(phba
, 2);
4439 goto lpfc_sli_hba_setup_error
;
4441 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4442 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4443 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4445 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4446 "2709 This device supports "
4447 "Advanced Error Reporting (AER)\n");
4448 spin_lock_irq(&phba
->hbalock
);
4449 phba
->hba_flag
|= HBA_AER_ENABLED
;
4450 spin_unlock_irq(&phba
->hbalock
);
4452 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4453 "2708 This device does not support "
4454 "Advanced Error Reporting (AER)\n");
4455 phba
->cfg_aer_support
= 0;
4459 if (phba
->sli_rev
== 3) {
4460 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4461 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4463 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4464 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4465 phba
->sli3_options
= 0;
4468 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4469 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4470 phba
->sli_rev
, phba
->max_vpi
);
4471 rc
= lpfc_sli_ring_map(phba
);
4474 goto lpfc_sli_hba_setup_error
;
4477 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4478 rc
= lpfc_sli_hbq_setup(phba
);
4480 goto lpfc_sli_hba_setup_error
;
4482 spin_lock_irq(&phba
->hbalock
);
4483 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4484 spin_unlock_irq(&phba
->hbalock
);
4486 rc
= lpfc_config_port_post(phba
);
4488 goto lpfc_sli_hba_setup_error
;
4492 lpfc_sli_hba_setup_error
:
4493 phba
->link_state
= LPFC_HBA_ERROR
;
4494 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4495 "0445 Firmware initialization failed\n");
4500 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4501 * @phba: Pointer to HBA context object.
4502 * @mboxq: mailbox pointer.
4503 * This function issue a dump mailbox command to read config region
4504 * 23 and parse the records in the region and populate driver
4508 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
,
4509 LPFC_MBOXQ_t
*mboxq
)
4511 struct lpfc_dmabuf
*mp
;
4512 struct lpfc_mqe
*mqe
;
4513 uint32_t data_length
;
4516 /* Program the default value of vlan_id and fc_map */
4517 phba
->valid_vlan
= 0;
4518 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4519 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4520 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4522 mqe
= &mboxq
->u
.mqe
;
4523 if (lpfc_dump_fcoe_param(phba
, mboxq
))
4526 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4527 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4529 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4530 "(%d):2571 Mailbox cmd x%x Status x%x "
4531 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4532 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4533 "CQ: x%x x%x x%x x%x\n",
4534 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4535 bf_get(lpfc_mqe_command
, mqe
),
4536 bf_get(lpfc_mqe_status
, mqe
),
4537 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4538 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4539 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4540 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4541 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4542 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4543 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4544 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4545 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4547 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4548 mboxq
->mcqe
.trailer
);
4551 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4555 data_length
= mqe
->un
.mb_words
[5];
4556 if (data_length
> DMP_RGN23_SIZE
) {
4557 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4562 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4563 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4569 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4570 * @phba: pointer to lpfc hba data structure.
4571 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4572 * @vpd: pointer to the memory to hold resulting port vpd data.
4573 * @vpd_size: On input, the number of bytes allocated to @vpd.
4574 * On output, the number of data bytes in @vpd.
4576 * This routine executes a READ_REV SLI4 mailbox command. In
4577 * addition, this routine gets the port vpd data.
4581 * -ENOMEM - could not allocated memory.
4584 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4585 uint8_t *vpd
, uint32_t *vpd_size
)
4589 struct lpfc_dmabuf
*dmabuf
;
4590 struct lpfc_mqe
*mqe
;
4592 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4597 * Get a DMA buffer for the vpd data resulting from the READ_REV
4600 dma_size
= *vpd_size
;
4601 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4605 if (!dmabuf
->virt
) {
4609 memset(dmabuf
->virt
, 0, dma_size
);
4612 * The SLI4 implementation of READ_REV conflicts at word1,
4613 * bits 31:16 and SLI4 adds vpd functionality not present
4614 * in SLI3. This code corrects the conflicts.
4616 lpfc_read_rev(phba
, mboxq
);
4617 mqe
= &mboxq
->u
.mqe
;
4618 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4619 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4620 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4621 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4622 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4624 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4626 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4627 dmabuf
->virt
, dmabuf
->phys
);
4633 * The available vpd length cannot be bigger than the
4634 * DMA buffer passed to the port. Catch the less than
4635 * case and update the caller's size.
4637 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4638 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4640 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4642 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4643 dmabuf
->virt
, dmabuf
->phys
);
4649 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4650 * @phba: pointer to lpfc hba data structure.
4652 * This routine is called to explicitly arm the SLI4 device's completion and
4656 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4660 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4661 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4662 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4663 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4665 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4666 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++)
4667 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4672 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
4673 * @phba: Pointer to HBA context object.
4675 * This function is the main SLI4 device intialization PCI function. This
4676 * function is called by the HBA intialization code, HBA reset code and
4677 * HBA error attention handler code. Caller is not required to hold any
4681 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
4684 LPFC_MBOXQ_t
*mboxq
;
4685 struct lpfc_mqe
*mqe
;
4688 uint32_t ftr_rsp
= 0;
4689 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
4690 struct lpfc_vport
*vport
= phba
->pport
;
4691 struct lpfc_dmabuf
*mp
;
4694 * TODO: Why does this routine execute these task in a different
4697 /* Perform a PCI function reset to start from clean */
4698 rc
= lpfc_pci_function_reset(phba
);
4702 /* Check the HBA Host Status Register for readyness */
4703 rc
= lpfc_sli4_post_status_check(phba
);
4707 spin_lock_irq(&phba
->hbalock
);
4708 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
4709 spin_unlock_irq(&phba
->hbalock
);
4713 * Allocate a single mailbox container for initializing the
4716 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4721 * Continue initialization with default values even if driver failed
4722 * to read FCoE param config regions
4724 if (lpfc_sli4_read_fcoe_params(phba
, mboxq
))
4725 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4726 "2570 Failed to read FCoE parameters\n");
4728 /* Issue READ_REV to collect vpd and FW information. */
4729 vpd_size
= SLI4_PAGE_SIZE
;
4730 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
4736 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
4741 mqe
= &mboxq
->u
.mqe
;
4742 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
4743 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
4744 phba
->hba_flag
|= HBA_FCOE_MODE
;
4746 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
4748 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
4750 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
4752 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
4754 if (phba
->sli_rev
!= LPFC_SLI_REV4
||
4755 !(phba
->hba_flag
& HBA_FCOE_MODE
)) {
4756 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4757 "0376 READ_REV Error. SLI Level %d "
4758 "FCoE enabled %d\n",
4759 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
4765 * Evaluate the read rev and vpd data. Populate the driver
4766 * state with the results. If this routine fails, the failure
4767 * is not fatal as the driver will use generic values.
4769 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
4770 if (unlikely(!rc
)) {
4771 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4772 "0377 Error %d parsing vpd. "
4773 "Using defaults.\n", rc
);
4778 /* Save information as VPD data */
4779 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
4780 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
4781 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
4782 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
4784 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
4786 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
4788 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
4790 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4791 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
4792 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
4793 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
4794 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
4795 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
4796 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4797 "(%d):0380 READ_REV Status x%x "
4798 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
4799 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4800 bf_get(lpfc_mqe_status
, mqe
),
4801 phba
->vpd
.rev
.opFwName
,
4802 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
4803 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
4806 * Discover the port's supported feature set and match it against the
4809 lpfc_request_features(phba
, mboxq
);
4810 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4817 * The port must support FCP initiator mode as this is the
4818 * only mode running in the host.
4820 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
4821 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4822 "0378 No support for fcpi mode.\n");
4827 * If the port cannot support the host's requested features
4828 * then turn off the global config parameters to disable the
4829 * feature in the driver. This is not a fatal error.
4831 if ((phba
->cfg_enable_bg
) &&
4832 !(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4835 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
4836 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4840 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4841 "0379 Feature Mismatch Data: x%08x %08x "
4842 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
4843 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
4844 phba
->cfg_enable_npiv
, phba
->max_vpi
);
4845 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
4846 phba
->cfg_enable_bg
= 0;
4847 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
4848 phba
->cfg_enable_npiv
= 0;
4851 /* These SLI3 features are assumed in SLI4 */
4852 spin_lock_irq(&phba
->hbalock
);
4853 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
4854 spin_unlock_irq(&phba
->hbalock
);
4856 /* Read the port's service parameters. */
4857 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
4859 phba
->link_state
= LPFC_HBA_ERROR
;
4864 mboxq
->vport
= vport
;
4865 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4866 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4867 if (rc
== MBX_SUCCESS
) {
4868 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
4873 * This memory was allocated by the lpfc_read_sparam routine. Release
4874 * it to the mbuf pool.
4876 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4878 mboxq
->context1
= NULL
;
4880 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4881 "0382 READ_SPARAM command failed "
4882 "status %d, mbxStatus x%x\n",
4883 rc
, bf_get(lpfc_mqe_status
, mqe
));
4884 phba
->link_state
= LPFC_HBA_ERROR
;
4889 if (phba
->cfg_soft_wwnn
)
4890 u64_to_wwn(phba
->cfg_soft_wwnn
,
4891 vport
->fc_sparam
.nodeName
.u
.wwn
);
4892 if (phba
->cfg_soft_wwpn
)
4893 u64_to_wwn(phba
->cfg_soft_wwpn
,
4894 vport
->fc_sparam
.portName
.u
.wwn
);
4895 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
4896 sizeof(struct lpfc_name
));
4897 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
4898 sizeof(struct lpfc_name
));
4900 /* Update the fc_host data structures with new wwn. */
4901 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
4902 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
4904 /* Register SGL pool to the device using non-embedded mailbox command */
4905 rc
= lpfc_sli4_post_sgl_list(phba
);
4907 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4908 "0582 Error %d during sgl post operation\n",
4914 /* Register SCSI SGL pool to the device */
4915 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
4917 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
4918 "0383 Error %d during scsi sgl post "
4920 /* Some Scsi buffers were moved to the abort scsi list */
4921 /* A pci function reset will repost them */
4926 /* Post the rpi header region to the device. */
4927 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
4929 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4930 "0393 Error %d during rpi post operation\n",
4936 /* Set up all the queues to the device */
4937 rc
= lpfc_sli4_queue_setup(phba
);
4939 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4940 "0381 Error %d during queue setup.\n ", rc
);
4941 goto out_stop_timers
;
4944 /* Arm the CQs and then EQs on device */
4945 lpfc_sli4_arm_cqeq_intr(phba
);
4947 /* Indicate device interrupt mode */
4948 phba
->sli4_hba
.intr_enable
= 1;
4950 /* Allow asynchronous mailbox command to go through */
4951 spin_lock_irq(&phba
->hbalock
);
4952 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4953 spin_unlock_irq(&phba
->hbalock
);
4955 /* Post receive buffers to the device */
4956 lpfc_sli4_rb_setup(phba
);
4958 /* Reset HBA FCF states after HBA reset */
4959 phba
->fcf
.fcf_flag
= 0;
4960 phba
->fcf
.current_rec
.flag
= 0;
4962 /* Start the ELS watchdog timer */
4963 mod_timer(&vport
->els_tmofunc
,
4964 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
4966 /* Start heart beat timer */
4967 mod_timer(&phba
->hb_tmofunc
,
4968 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
4969 phba
->hb_outstanding
= 0;
4970 phba
->last_completion_time
= jiffies
;
4972 /* Start error attention (ERATT) polling timer */
4973 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
4975 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4976 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4977 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4979 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4980 "2829 This device supports "
4981 "Advanced Error Reporting (AER)\n");
4982 spin_lock_irq(&phba
->hbalock
);
4983 phba
->hba_flag
|= HBA_AER_ENABLED
;
4984 spin_unlock_irq(&phba
->hbalock
);
4986 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4987 "2830 This device does not support "
4988 "Advanced Error Reporting (AER)\n");
4989 phba
->cfg_aer_support
= 0;
4993 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
4995 * The FC Port needs to register FCFI (index 0)
4997 lpfc_reg_fcfi(phba
, mboxq
);
4998 mboxq
->vport
= phba
->pport
;
4999 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5000 if (rc
== MBX_SUCCESS
)
5003 goto out_unset_queue
;
5006 * The port is ready, set the host's link state to LINK_DOWN
5007 * in preparation for link interrupts.
5009 spin_lock_irq(&phba
->hbalock
);
5010 phba
->link_state
= LPFC_LINK_DOWN
;
5011 spin_unlock_irq(&phba
->hbalock
);
5012 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
5014 /* Unset all the queues set up in this routine when error out */
5016 lpfc_sli4_queue_unset(phba
);
5019 lpfc_stop_hba_timers(phba
);
5021 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5026 * lpfc_mbox_timeout - Timeout call back function for mbox timer
5027 * @ptr: context object - pointer to hba structure.
5029 * This is the callback function for mailbox timer. The mailbox
5030 * timer is armed when a new mailbox command is issued and the timer
5031 * is deleted when the mailbox complete. The function is called by
5032 * the kernel timer code when a mailbox does not complete within
5033 * expected time. This function wakes up the worker thread to
5034 * process the mailbox timeout and returns. All the processing is
5035 * done by the worker thread function lpfc_mbox_timeout_handler.
5038 lpfc_mbox_timeout(unsigned long ptr
)
5040 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
5041 unsigned long iflag
;
5042 uint32_t tmo_posted
;
5044 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
5045 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
5047 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
5048 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
5051 lpfc_worker_wake_up(phba
);
5057 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
5058 * @phba: Pointer to HBA context object.
5060 * This function is called from worker thread when a mailbox command times out.
5061 * The caller is not required to hold any locks. This function will reset the
5062 * HBA and recover all the pending commands.
5065 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
5067 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
5068 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
5069 struct lpfc_sli
*psli
= &phba
->sli
;
5070 struct lpfc_sli_ring
*pring
;
5072 /* Check the pmbox pointer first. There is a race condition
5073 * between the mbox timeout handler getting executed in the
5074 * worklist and the mailbox actually completing. When this
5075 * race condition occurs, the mbox_active will be NULL.
5077 spin_lock_irq(&phba
->hbalock
);
5078 if (pmbox
== NULL
) {
5079 lpfc_printf_log(phba
, KERN_WARNING
,
5081 "0353 Active Mailbox cleared - mailbox timeout "
5083 spin_unlock_irq(&phba
->hbalock
);
5087 /* Mbox cmd <mbxCommand> timeout */
5088 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5089 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
5091 phba
->pport
->port_state
,
5093 phba
->sli
.mbox_active
);
5094 spin_unlock_irq(&phba
->hbalock
);
5096 /* Setting state unknown so lpfc_sli_abort_iocb_ring
5097 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
5098 * it to fail all oustanding SCSI IO.
5100 spin_lock_irq(&phba
->pport
->work_port_lock
);
5101 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
5102 spin_unlock_irq(&phba
->pport
->work_port_lock
);
5103 spin_lock_irq(&phba
->hbalock
);
5104 phba
->link_state
= LPFC_LINK_UNKNOWN
;
5105 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
5106 spin_unlock_irq(&phba
->hbalock
);
5108 pring
= &psli
->ring
[psli
->fcp_ring
];
5109 lpfc_sli_abort_iocb_ring(phba
, pring
);
5111 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5112 "0345 Resetting board due to mailbox timeout\n");
5114 /* Reset the HBA device */
5115 lpfc_reset_hba(phba
);
5119 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
5120 * @phba: Pointer to HBA context object.
5121 * @pmbox: Pointer to mailbox object.
5122 * @flag: Flag indicating how the mailbox need to be processed.
5124 * This function is called by discovery code and HBA management code
5125 * to submit a mailbox command to firmware with SLI-3 interface spec. This
5126 * function gets the hbalock to protect the data structures.
5127 * The mailbox command can be submitted in polling mode, in which case
5128 * this function will wait in a polling loop for the completion of the
5130 * If the mailbox is submitted in no_wait mode (not polling) the
5131 * function will submit the command and returns immediately without waiting
5132 * for the mailbox completion. The no_wait is supported only when HBA
5133 * is in SLI2/SLI3 mode - interrupts are enabled.
5134 * The SLI interface allows only one mailbox pending at a time. If the
5135 * mailbox is issued in polling mode and there is already a mailbox
5136 * pending, then the function will return an error. If the mailbox is issued
5137 * in NO_WAIT mode and there is a mailbox pending already, the function
5138 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
5139 * The sli layer owns the mailbox object until the completion of mailbox
5140 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
5141 * return codes the caller owns the mailbox command after the return of
5145 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
5149 struct lpfc_sli
*psli
= &phba
->sli
;
5150 uint32_t status
, evtctr
;
5153 unsigned long timeout
;
5154 unsigned long drvr_flag
= 0;
5155 uint32_t word0
, ldata
;
5156 void __iomem
*to_slim
;
5157 int processing_queue
= 0;
5159 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
5161 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5162 /* processing mbox queue from intr_handler */
5163 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5164 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5167 processing_queue
= 1;
5168 pmbox
= lpfc_mbox_get(phba
);
5170 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5175 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
5176 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
5178 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5179 lpfc_printf_log(phba
, KERN_ERR
,
5180 LOG_MBOX
| LOG_VPORT
,
5181 "1806 Mbox x%x failed. No vport\n",
5182 pmbox
->u
.mb
.mbxCommand
);
5184 goto out_not_finished
;
5188 /* If the PCI channel is in offline state, do not post mbox. */
5189 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
5190 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5191 goto out_not_finished
;
5194 /* If HBA has a deferred error attention, fail the iocb. */
5195 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
5196 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5197 goto out_not_finished
;
5203 status
= MBX_SUCCESS
;
5205 if (phba
->link_state
== LPFC_HBA_ERROR
) {
5206 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5208 /* Mbox command <mbxCommand> cannot issue */
5209 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5210 "(%d):0311 Mailbox command x%x cannot "
5211 "issue Data: x%x x%x\n",
5212 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
5213 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
5214 goto out_not_finished
;
5217 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
5218 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
5219 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5220 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5221 "(%d):2528 Mailbox command x%x cannot "
5222 "issue Data: x%x x%x\n",
5223 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
5224 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
5225 goto out_not_finished
;
5228 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5229 /* Polling for a mbox command when another one is already active
5230 * is not allowed in SLI. Also, the driver must have established
5231 * SLI2 mode to queue and process multiple mbox commands.
5234 if (flag
& MBX_POLL
) {
5235 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5237 /* Mbox command <mbxCommand> cannot issue */
5238 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5239 "(%d):2529 Mailbox command x%x "
5240 "cannot issue Data: x%x x%x\n",
5241 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
5242 pmbox
->u
.mb
.mbxCommand
,
5243 psli
->sli_flag
, flag
);
5244 goto out_not_finished
;
5247 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
5248 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5249 /* Mbox command <mbxCommand> cannot issue */
5250 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5251 "(%d):2530 Mailbox command x%x "
5252 "cannot issue Data: x%x x%x\n",
5253 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
5254 pmbox
->u
.mb
.mbxCommand
,
5255 psli
->sli_flag
, flag
);
5256 goto out_not_finished
;
5259 /* Another mailbox command is still being processed, queue this
5260 * command to be processed later.
5262 lpfc_mbox_put(phba
, pmbox
);
5264 /* Mbox cmd issue - BUSY */
5265 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5266 "(%d):0308 Mbox cmd issue - BUSY Data: "
5267 "x%x x%x x%x x%x\n",
5268 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
5269 mb
->mbxCommand
, phba
->pport
->port_state
,
5270 psli
->sli_flag
, flag
);
5272 psli
->slistat
.mbox_busy
++;
5273 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5276 lpfc_debugfs_disc_trc(pmbox
->vport
,
5277 LPFC_DISC_TRC_MBOX_VPORT
,
5278 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
5279 (uint32_t)mb
->mbxCommand
,
5280 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
5283 lpfc_debugfs_disc_trc(phba
->pport
,
5285 "MBOX Bsy: cmd:x%x mb:x%x x%x",
5286 (uint32_t)mb
->mbxCommand
,
5287 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
5293 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5295 /* If we are not polling, we MUST be in SLI2 mode */
5296 if (flag
!= MBX_POLL
) {
5297 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
5298 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
5299 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5300 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5301 /* Mbox command <mbxCommand> cannot issue */
5302 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5303 "(%d):2531 Mailbox command x%x "
5304 "cannot issue Data: x%x x%x\n",
5305 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
5306 pmbox
->u
.mb
.mbxCommand
,
5307 psli
->sli_flag
, flag
);
5308 goto out_not_finished
;
5310 /* timeout active mbox command */
5311 mod_timer(&psli
->mbox_tmo
, (jiffies
+
5312 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
5315 /* Mailbox cmd <cmd> issue */
5316 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5317 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
5319 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
5320 mb
->mbxCommand
, phba
->pport
->port_state
,
5321 psli
->sli_flag
, flag
);
5323 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
5325 lpfc_debugfs_disc_trc(pmbox
->vport
,
5326 LPFC_DISC_TRC_MBOX_VPORT
,
5327 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5328 (uint32_t)mb
->mbxCommand
,
5329 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
5332 lpfc_debugfs_disc_trc(phba
->pport
,
5334 "MBOX Send: cmd:x%x mb:x%x x%x",
5335 (uint32_t)mb
->mbxCommand
,
5336 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
5340 psli
->slistat
.mbox_cmd
++;
5341 evtctr
= psli
->slistat
.mbox_event
;
5343 /* next set own bit for the adapter and copy over command word */
5344 mb
->mbxOwner
= OWN_CHIP
;
5346 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5347 /* Populate mbox extension offset word. */
5348 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
5349 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
5350 = (uint8_t *)phba
->mbox_ext
5351 - (uint8_t *)phba
->mbox
;
5354 /* Copy the mailbox extension data */
5355 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
5356 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
5357 (uint8_t *)phba
->mbox_ext
,
5358 pmbox
->in_ext_byte_len
);
5360 /* Copy command data to host SLIM area */
5361 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
5363 /* Populate mbox extension offset word. */
5364 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
5365 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
5366 = MAILBOX_HBA_EXT_OFFSET
;
5368 /* Copy the mailbox extension data */
5369 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
5370 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
5371 MAILBOX_HBA_EXT_OFFSET
,
5372 pmbox
->context2
, pmbox
->in_ext_byte_len
);
5375 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
5376 /* copy command data into host mbox for cmpl */
5377 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
5380 /* First copy mbox command data to HBA SLIM, skip past first
5382 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
5383 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
5384 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
5386 /* Next copy over first word, with mbxOwner set */
5387 ldata
= *((uint32_t *)mb
);
5388 to_slim
= phba
->MBslimaddr
;
5389 writel(ldata
, to_slim
);
5390 readl(to_slim
); /* flush */
5392 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
5393 /* switch over to host mailbox */
5394 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
5402 /* Set up reference to mailbox command */
5403 psli
->mbox_active
= pmbox
;
5404 /* Interrupt board to do it */
5405 writel(CA_MBATT
, phba
->CAregaddr
);
5406 readl(phba
->CAregaddr
); /* flush */
5407 /* Don't wait for it to finish, just return */
5411 /* Set up null reference to mailbox command */
5412 psli
->mbox_active
= NULL
;
5413 /* Interrupt board to do it */
5414 writel(CA_MBATT
, phba
->CAregaddr
);
5415 readl(phba
->CAregaddr
); /* flush */
5417 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5418 /* First read mbox status word */
5419 word0
= *((uint32_t *)phba
->mbox
);
5420 word0
= le32_to_cpu(word0
);
5422 /* First read mbox status word */
5423 word0
= readl(phba
->MBslimaddr
);
5426 /* Read the HBA Host Attention Register */
5427 ha_copy
= readl(phba
->HAregaddr
);
5428 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
5432 /* Wait for command to complete */
5433 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
5434 (!(ha_copy
& HA_MBATT
) &&
5435 (phba
->link_state
> LPFC_WARM_START
))) {
5436 if (time_after(jiffies
, timeout
)) {
5437 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5438 spin_unlock_irqrestore(&phba
->hbalock
,
5440 goto out_not_finished
;
5443 /* Check if we took a mbox interrupt while we were
5445 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
5446 && (evtctr
!= psli
->slistat
.mbox_event
))
5450 spin_unlock_irqrestore(&phba
->hbalock
,
5453 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
5456 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5457 /* First copy command data */
5458 word0
= *((uint32_t *)phba
->mbox
);
5459 word0
= le32_to_cpu(word0
);
5460 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
5463 /* Check real SLIM for any errors */
5464 slimword0
= readl(phba
->MBslimaddr
);
5465 slimmb
= (MAILBOX_t
*) & slimword0
;
5466 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
5467 && slimmb
->mbxStatus
) {
5474 /* First copy command data */
5475 word0
= readl(phba
->MBslimaddr
);
5477 /* Read the HBA Host Attention Register */
5478 ha_copy
= readl(phba
->HAregaddr
);
5481 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
5482 /* copy results back to user */
5483 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
5484 /* Copy the mailbox extension data */
5485 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
5486 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
5488 pmbox
->out_ext_byte_len
);
5491 /* First copy command data */
5492 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
5494 /* Copy the mailbox extension data */
5495 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
5496 lpfc_memcpy_from_slim(pmbox
->context2
,
5498 MAILBOX_HBA_EXT_OFFSET
,
5499 pmbox
->out_ext_byte_len
);
5503 writel(HA_MBATT
, phba
->HAregaddr
);
5504 readl(phba
->HAregaddr
); /* flush */
5506 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5507 status
= mb
->mbxStatus
;
5510 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
5514 if (processing_queue
) {
5515 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5516 lpfc_mbox_cmpl_put(phba
, pmbox
);
5518 return MBX_NOT_FINISHED
;
5522 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
5523 * @phba: Pointer to HBA context object.
5525 * The function blocks the posting of SLI4 asynchronous mailbox commands from
5526 * the driver internal pending mailbox queue. It will then try to wait out the
5527 * possible outstanding mailbox command before return.
5530 * 0 - the outstanding mailbox command completed; otherwise, the wait for
5531 * the outstanding mailbox command timed out.
5534 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
5536 struct lpfc_sli
*psli
= &phba
->sli
;
5537 uint8_t actcmd
= MBX_HEARTBEAT
;
5539 unsigned long timeout
;
5541 /* Mark the asynchronous mailbox command posting as blocked */
5542 spin_lock_irq(&phba
->hbalock
);
5543 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
5544 if (phba
->sli
.mbox_active
)
5545 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
5546 spin_unlock_irq(&phba
->hbalock
);
5547 /* Determine how long we might wait for the active mailbox
5548 * command to be gracefully completed by firmware.
5550 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) * 1000) +
5552 /* Wait for the outstnading mailbox command to complete */
5553 while (phba
->sli
.mbox_active
) {
5554 /* Check active mailbox complete status every 2ms */
5556 if (time_after(jiffies
, timeout
)) {
5557 /* Timeout, marked the outstanding cmd not complete */
5563 /* Can not cleanly block async mailbox command, fails it */
5565 spin_lock_irq(&phba
->hbalock
);
5566 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5567 spin_unlock_irq(&phba
->hbalock
);
5573 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
5574 * @phba: Pointer to HBA context object.
5576 * The function unblocks and resume posting of SLI4 asynchronous mailbox
5577 * commands from the driver internal pending mailbox queue. It makes sure
5578 * that there is no outstanding mailbox command before resuming posting
5579 * asynchronous mailbox commands. If, for any reason, there is outstanding
5580 * mailbox command, it will try to wait it out before resuming asynchronous
5581 * mailbox command posting.
5584 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
5586 struct lpfc_sli
*psli
= &phba
->sli
;
5588 spin_lock_irq(&phba
->hbalock
);
5589 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5590 /* Asynchronous mailbox posting is not blocked, do nothing */
5591 spin_unlock_irq(&phba
->hbalock
);
5595 /* Outstanding synchronous mailbox command is guaranteed to be done,
5596 * successful or timeout, after timing-out the outstanding mailbox
5597 * command shall always be removed, so just unblock posting async
5598 * mailbox command and resume
5600 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
5601 spin_unlock_irq(&phba
->hbalock
);
5603 /* wake up worker thread to post asynchronlous mailbox command */
5604 lpfc_worker_wake_up(phba
);
5608 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
5609 * @phba: Pointer to HBA context object.
5610 * @mboxq: Pointer to mailbox object.
5612 * The function posts a mailbox to the port. The mailbox is expected
5613 * to be comletely filled in and ready for the port to operate on it.
5614 * This routine executes a synchronous completion operation on the
5615 * mailbox by polling for its completion.
5617 * The caller must not be holding any locks when calling this routine.
5620 * MBX_SUCCESS - mailbox posted successfully
5621 * Any of the MBX error values.
5624 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
5626 int rc
= MBX_SUCCESS
;
5627 unsigned long iflag
;
5629 uint32_t mcqe_status
;
5631 unsigned long timeout
;
5632 struct lpfc_sli
*psli
= &phba
->sli
;
5633 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
5634 struct lpfc_bmbx_create
*mbox_rgn
;
5635 struct dma_address
*dma_address
;
5636 struct lpfc_register bmbx_reg
;
5639 * Only one mailbox can be active to the bootstrap mailbox region
5640 * at a time and there is no queueing provided.
5642 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5643 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5644 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5645 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5646 "(%d):2532 Mailbox command x%x (x%x) "
5647 "cannot issue Data: x%x x%x\n",
5648 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5649 mboxq
->u
.mb
.mbxCommand
,
5650 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5651 psli
->sli_flag
, MBX_POLL
);
5652 return MBXERR_ERROR
;
5654 /* The server grabs the token and owns it until release */
5655 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5656 phba
->sli
.mbox_active
= mboxq
;
5657 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5660 * Initialize the bootstrap memory region to avoid stale data areas
5661 * in the mailbox post. Then copy the caller's mailbox contents to
5662 * the bmbx mailbox region.
5664 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
5665 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
5666 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
5667 sizeof(struct lpfc_mqe
));
5669 /* Post the high mailbox dma address to the port and wait for ready. */
5670 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
5671 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
5673 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5676 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5677 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5681 if (time_after(jiffies
, timeout
)) {
5685 } while (!db_ready
);
5687 /* Post the low mailbox dma address to the port. */
5688 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
5689 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mbx_cmnd
)
5692 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
5693 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
5697 if (time_after(jiffies
, timeout
)) {
5701 } while (!db_ready
);
5704 * Read the CQ to ensure the mailbox has completed.
5705 * If so, update the mailbox status so that the upper layers
5706 * can complete the request normally.
5708 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
5709 sizeof(struct lpfc_mqe
));
5710 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
5711 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
5712 sizeof(struct lpfc_mcqe
));
5713 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
5715 /* Prefix the mailbox status with range x4000 to note SLI4 status. */
5716 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
5717 bf_set(lpfc_mqe_status
, mb
, LPFC_MBX_ERROR_RANGE
| mcqe_status
);
5720 lpfc_sli4_swap_str(phba
, mboxq
);
5722 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5723 "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
5724 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
5725 " x%x x%x CQ: x%x x%x x%x x%x\n",
5726 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5727 mbx_cmnd
, lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5728 bf_get(lpfc_mqe_status
, mb
),
5729 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
5730 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
5731 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
5732 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
5733 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
5734 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
5735 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
5736 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5737 mboxq
->mcqe
.trailer
);
5739 /* We are holding the token, no needed for lock when release */
5740 spin_lock_irqsave(&phba
->hbalock
, iflag
);
5741 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5742 phba
->sli
.mbox_active
= NULL
;
5743 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
5748 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
5749 * @phba: Pointer to HBA context object.
5750 * @pmbox: Pointer to mailbox object.
5751 * @flag: Flag indicating how the mailbox need to be processed.
5753 * This function is called by discovery code and HBA management code to submit
5754 * a mailbox command to firmware with SLI-4 interface spec.
5756 * Return codes the caller owns the mailbox command after the return of the
5760 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5763 struct lpfc_sli
*psli
= &phba
->sli
;
5764 unsigned long iflags
;
5767 rc
= lpfc_mbox_dev_check(phba
);
5769 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5770 "(%d):2544 Mailbox command x%x (x%x) "
5771 "cannot issue Data: x%x x%x\n",
5772 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5773 mboxq
->u
.mb
.mbxCommand
,
5774 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5775 psli
->sli_flag
, flag
);
5776 goto out_not_finished
;
5779 /* Detect polling mode and jump to a handler */
5780 if (!phba
->sli4_hba
.intr_enable
) {
5781 if (flag
== MBX_POLL
)
5782 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5785 if (rc
!= MBX_SUCCESS
)
5786 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5787 "(%d):2541 Mailbox command x%x "
5788 "(x%x) cannot issue Data: x%x x%x\n",
5789 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5790 mboxq
->u
.mb
.mbxCommand
,
5791 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5792 psli
->sli_flag
, flag
);
5794 } else if (flag
== MBX_POLL
) {
5795 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
5796 "(%d):2542 Try to issue mailbox command "
5797 "x%x (x%x) synchronously ahead of async"
5798 "mailbox command queue: x%x x%x\n",
5799 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5800 mboxq
->u
.mb
.mbxCommand
,
5801 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5802 psli
->sli_flag
, flag
);
5803 /* Try to block the asynchronous mailbox posting */
5804 rc
= lpfc_sli4_async_mbox_block(phba
);
5806 /* Successfully blocked, now issue sync mbox cmd */
5807 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
5808 if (rc
!= MBX_SUCCESS
)
5809 lpfc_printf_log(phba
, KERN_ERR
,
5811 "(%d):2597 Mailbox command "
5812 "x%x (x%x) cannot issue "
5815 mboxq
->vport
->vpi
: 0,
5816 mboxq
->u
.mb
.mbxCommand
,
5817 lpfc_sli4_mbox_opcode_get(phba
,
5819 psli
->sli_flag
, flag
);
5820 /* Unblock the async mailbox posting afterward */
5821 lpfc_sli4_async_mbox_unblock(phba
);
5826 /* Now, interrupt mode asynchrous mailbox command */
5827 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
5829 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5830 "(%d):2543 Mailbox command x%x (x%x) "
5831 "cannot issue Data: x%x x%x\n",
5832 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5833 mboxq
->u
.mb
.mbxCommand
,
5834 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5835 psli
->sli_flag
, flag
);
5836 goto out_not_finished
;
5839 /* Put the mailbox command to the driver internal FIFO */
5840 psli
->slistat
.mbox_busy
++;
5841 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5842 lpfc_mbox_put(phba
, mboxq
);
5843 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5844 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5845 "(%d):0354 Mbox cmd issue - Enqueue Data: "
5846 "x%x (x%x) x%x x%x x%x\n",
5847 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
5848 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5849 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5850 phba
->pport
->port_state
,
5851 psli
->sli_flag
, MBX_NOWAIT
);
5852 /* Wake up worker thread to transport mailbox command from head */
5853 lpfc_worker_wake_up(phba
);
5858 return MBX_NOT_FINISHED
;
5862 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
5863 * @phba: Pointer to HBA context object.
5865 * This function is called by worker thread to send a mailbox command to
5866 * SLI4 HBA firmware.
5870 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
5872 struct lpfc_sli
*psli
= &phba
->sli
;
5873 LPFC_MBOXQ_t
*mboxq
;
5874 int rc
= MBX_SUCCESS
;
5875 unsigned long iflags
;
5876 struct lpfc_mqe
*mqe
;
5879 /* Check interrupt mode before post async mailbox command */
5880 if (unlikely(!phba
->sli4_hba
.intr_enable
))
5881 return MBX_NOT_FINISHED
;
5883 /* Check for mailbox command service token */
5884 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5885 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
5886 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5887 return MBX_NOT_FINISHED
;
5889 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
5890 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5891 return MBX_NOT_FINISHED
;
5893 if (unlikely(phba
->sli
.mbox_active
)) {
5894 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5895 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5896 "0384 There is pending active mailbox cmd\n");
5897 return MBX_NOT_FINISHED
;
5899 /* Take the mailbox command service token */
5900 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
5902 /* Get the next mailbox command from head of queue */
5903 mboxq
= lpfc_mbox_get(phba
);
5905 /* If no more mailbox command waiting for post, we're done */
5907 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5908 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5911 phba
->sli
.mbox_active
= mboxq
;
5912 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5914 /* Check device readiness for posting mailbox command */
5915 rc
= lpfc_mbox_dev_check(phba
);
5917 /* Driver clean routine will clean up pending mailbox */
5918 goto out_not_finished
;
5920 /* Prepare the mbox command to be posted */
5921 mqe
= &mboxq
->u
.mqe
;
5922 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
5924 /* Start timer for the mbox_tmo and log some mailbox post messages */
5925 mod_timer(&psli
->mbox_tmo
, (jiffies
+
5926 (HZ
* lpfc_mbox_tmo_val(phba
, mbx_cmnd
))));
5928 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5929 "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
5931 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
5932 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5933 phba
->pport
->port_state
, psli
->sli_flag
);
5935 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
5937 lpfc_debugfs_disc_trc(mboxq
->vport
,
5938 LPFC_DISC_TRC_MBOX_VPORT
,
5939 "MBOX Send vport: cmd:x%x mb:x%x x%x",
5940 mbx_cmnd
, mqe
->un
.mb_words
[0],
5941 mqe
->un
.mb_words
[1]);
5943 lpfc_debugfs_disc_trc(phba
->pport
,
5945 "MBOX Send: cmd:x%x mb:x%x x%x",
5946 mbx_cmnd
, mqe
->un
.mb_words
[0],
5947 mqe
->un
.mb_words
[1]);
5950 psli
->slistat
.mbox_cmd
++;
5952 /* Post the mailbox command to the port */
5953 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
5954 if (rc
!= MBX_SUCCESS
) {
5955 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5956 "(%d):2533 Mailbox command x%x (x%x) "
5957 "cannot issue Data: x%x x%x\n",
5958 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5959 mboxq
->u
.mb
.mbxCommand
,
5960 lpfc_sli4_mbox_opcode_get(phba
, mboxq
),
5961 psli
->sli_flag
, MBX_NOWAIT
);
5962 goto out_not_finished
;
5968 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5969 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
5970 __lpfc_mbox_cmpl_put(phba
, mboxq
);
5971 /* Release the token */
5972 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
5973 phba
->sli
.mbox_active
= NULL
;
5974 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5976 return MBX_NOT_FINISHED
;
5980 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
5981 * @phba: Pointer to HBA context object.
5982 * @pmbox: Pointer to mailbox object.
5983 * @flag: Flag indicating how the mailbox need to be processed.
5985 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
5986 * the API jump table function pointer from the lpfc_hba struct.
5988 * Return codes the caller owns the mailbox command after the return of the
5992 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
5994 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
5998 * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
5999 * @phba: The hba struct for which this call is being executed.
6000 * @dev_grp: The HBA PCI-Device group number.
6002 * This routine sets up the mbox interface API function jump table in @phba
6004 * Returns: 0 - success, -ENODEV - failure.
6007 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6011 case LPFC_PCI_DEV_LP
:
6012 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
6013 phba
->lpfc_sli_handle_slow_ring_event
=
6014 lpfc_sli_handle_slow_ring_event_s3
;
6015 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
6016 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
6017 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
6019 case LPFC_PCI_DEV_OC
:
6020 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
6021 phba
->lpfc_sli_handle_slow_ring_event
=
6022 lpfc_sli_handle_slow_ring_event_s4
;
6023 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
6024 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
6025 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
6028 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6029 "1420 Invalid HBA PCI-device group: 0x%x\n",
6038 * __lpfc_sli_ringtx_put - Add an iocb to the txq
6039 * @phba: Pointer to HBA context object.
6040 * @pring: Pointer to driver SLI ring object.
6041 * @piocb: Pointer to address of newly added command iocb.
6043 * This function is called with hbalock held to add a command
6044 * iocb to the txq when SLI layer cannot submit the command iocb
6048 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6049 struct lpfc_iocbq
*piocb
)
6051 /* Insert the caller's iocb in the txq tail for later processing. */
6052 list_add_tail(&piocb
->list
, &pring
->txq
);
6057 * lpfc_sli_next_iocb - Get the next iocb in the txq
6058 * @phba: Pointer to HBA context object.
6059 * @pring: Pointer to driver SLI ring object.
6060 * @piocb: Pointer to address of newly added command iocb.
6062 * This function is called with hbalock held before a new
6063 * iocb is submitted to the firmware. This function checks
6064 * txq to flush the iocbs in txq to Firmware before
6065 * submitting new iocbs to the Firmware.
6066 * If there are iocbs in the txq which need to be submitted
6067 * to firmware, lpfc_sli_next_iocb returns the first element
6068 * of the txq after dequeuing it from txq.
6069 * If there is no iocb in the txq then the function will return
6070 * *piocb and *piocb is set to NULL. Caller needs to check
6071 * *piocb to find if there are more commands in the txq.
6073 static struct lpfc_iocbq
*
6074 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6075 struct lpfc_iocbq
**piocb
)
6077 struct lpfc_iocbq
* nextiocb
;
6079 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
6089 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
6090 * @phba: Pointer to HBA context object.
6091 * @ring_number: SLI ring number to issue iocb on.
6092 * @piocb: Pointer to command iocb.
6093 * @flag: Flag indicating if this command can be put into txq.
6095 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
6096 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
6097 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
6098 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
6099 * this function allows only iocbs for posting buffers. This function finds
6100 * next available slot in the command ring and posts the command to the
6101 * available slot and writes the port attention register to request HBA start
6102 * processing new iocb. If there is no slot available in the ring and
6103 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
6104 * the function returns IOCB_BUSY.
6106 * This function is called with hbalock held. The function will return success
6107 * after it successfully submit the iocb to firmware or after adding to the
6111 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
6112 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6114 struct lpfc_iocbq
*nextiocb
;
6116 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
6118 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
6119 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
6120 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
6121 lpfc_printf_log(phba
, KERN_ERR
,
6122 LOG_SLI
| LOG_VPORT
,
6123 "1807 IOCB x%x failed. No vport\n",
6124 piocb
->iocb
.ulpCommand
);
6130 /* If the PCI channel is in offline state, do not post iocbs. */
6131 if (unlikely(pci_channel_offline(phba
->pcidev
)))
6134 /* If HBA has a deferred error attention, fail the iocb. */
6135 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
6139 * We should never get an IOCB if we are in a < LINK_DOWN state
6141 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
6145 * Check to see if we are blocking IOCB processing because of a
6146 * outstanding event.
6148 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
6151 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
6153 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
6154 * can be issued if the link is not up.
6156 switch (piocb
->iocb
.ulpCommand
) {
6157 case CMD_GEN_REQUEST64_CR
:
6158 case CMD_GEN_REQUEST64_CX
:
6159 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
6160 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
6161 FC_RCTL_DD_UNSOL_CMD
) ||
6162 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
6163 MENLO_TRANSPORT_TYPE
))
6167 case CMD_QUE_RING_BUF_CN
:
6168 case CMD_QUE_RING_BUF64_CN
:
6170 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
6171 * completion, iocb_cmpl MUST be 0.
6173 if (piocb
->iocb_cmpl
)
6174 piocb
->iocb_cmpl
= NULL
;
6176 case CMD_CREATE_XRI_CR
:
6177 case CMD_CLOSE_XRI_CN
:
6178 case CMD_CLOSE_XRI_CX
:
6185 * For FCP commands, we must be in a state where we can process link
6188 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
6189 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
6193 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
6194 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
6195 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
6198 lpfc_sli_update_ring(phba
, pring
);
6200 lpfc_sli_update_full_ring(phba
, pring
);
6203 return IOCB_SUCCESS
;
6208 pring
->stats
.iocb_cmd_delay
++;
6212 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
6213 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
6214 return IOCB_SUCCESS
;
6221 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
6222 * @phba: Pointer to HBA context object.
6223 * @piocb: Pointer to command iocb.
6224 * @sglq: Pointer to the scatter gather queue object.
6226 * This routine converts the bpl or bde that is in the IOCB
6227 * to a sgl list for the sli4 hardware. The physical address
6228 * of the bpl/bde is converted back to a virtual address.
6229 * If the IOCB contains a BPL then the list of BDE's is
6230 * converted to sli4_sge's. If the IOCB contains a single
6231 * BDE then it is converted to a single sli_sge.
6232 * The IOCB is still in cpu endianess so the contents of
6233 * the bpl can be used without byte swapping.
6235 * Returns valid XRI = Success, NO_XRI = Failure.
6238 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
6239 struct lpfc_sglq
*sglq
)
6241 uint16_t xritag
= NO_XRI
;
6242 struct ulp_bde64
*bpl
= NULL
;
6243 struct ulp_bde64 bde
;
6244 struct sli4_sge
*sgl
= NULL
;
6248 uint32_t offset
= 0; /* accumulated offset in the sg request list */
6249 int inbound
= 0; /* number of sg reply entries inbound from firmware */
6251 if (!piocbq
|| !sglq
)
6254 sgl
= (struct sli4_sge
*)sglq
->sgl
;
6255 icmd
= &piocbq
->iocb
;
6256 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
6257 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
6258 sizeof(struct ulp_bde64
);
6259 /* The addrHigh and addrLow fields within the IOCB
6260 * have not been byteswapped yet so there is no
6261 * need to swap them back.
6263 bpl
= (struct ulp_bde64
*)
6264 ((struct lpfc_dmabuf
*)piocbq
->context3
)->virt
;
6269 for (i
= 0; i
< numBdes
; i
++) {
6270 /* Should already be byte swapped. */
6271 sgl
->addr_hi
= bpl
->addrHigh
;
6272 sgl
->addr_lo
= bpl
->addrLow
;
6274 if ((i
+1) == numBdes
)
6275 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
6277 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
6278 sgl
->word2
= cpu_to_le32(sgl
->word2
);
6279 /* swap the size field back to the cpu so we
6280 * can assign it to the sgl.
6282 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
6283 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
6284 /* The offsets in the sgl need to be accumulated
6285 * separately for the request and reply lists.
6286 * The request is always first, the reply follows.
6288 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
6289 /* add up the reply sg entries */
6290 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
6292 /* first inbound? reset the offset */
6295 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
6296 offset
+= bde
.tus
.f
.bdeSize
;
6301 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
6302 /* The addrHigh and addrLow fields of the BDE have not
6303 * been byteswapped yet so they need to be swapped
6304 * before putting them in the sgl.
6307 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
6309 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
6310 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
6311 sgl
->word2
= cpu_to_le32(sgl
->word2
);
6313 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
6315 return sglq
->sli4_xritag
;
6319 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
6320 * @phba: Pointer to HBA context object.
6322 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
6323 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
6326 * Return: index into SLI4 fast-path FCP queue index.
6329 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
6332 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
6335 return phba
->fcp_qidx
;
6339 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
6340 * @phba: Pointer to HBA context object.
6341 * @piocb: Pointer to command iocb.
6342 * @wqe: Pointer to the work queue entry.
6344 * This routine converts the iocb command to its Work Queue Entry
6345 * equivalent. The wqe pointer should not have any fields set when
6346 * this routine is called because it will memcpy over them.
6347 * This routine does not set the CQ_ID or the WQEC bits in the
6350 * Returns: 0 = Success, IOCB_ERROR = Failure.
6353 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
6354 union lpfc_wqe
*wqe
)
6356 uint32_t xmit_len
= 0, total_len
= 0;
6360 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
6363 uint16_t abrt_iotag
;
6364 struct lpfc_iocbq
*abrtiocbq
;
6365 struct ulp_bde64
*bpl
= NULL
;
6366 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
6368 struct ulp_bde64 bde
;
6370 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
6371 /* The fcp commands will set command type */
6372 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
6373 command_type
= FCP_COMMAND
;
6374 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
6375 command_type
= ELS_COMMAND_FIP
;
6377 command_type
= ELS_COMMAND_NON_FIP
;
6379 /* Some of the fields are in the right position already */
6380 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
6381 abort_tag
= (uint32_t) iocbq
->iotag
;
6382 xritag
= iocbq
->sli4_xritag
;
6383 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
6384 /* words0-2 bpl convert bde */
6385 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
6386 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
6387 sizeof(struct ulp_bde64
);
6388 bpl
= (struct ulp_bde64
*)
6389 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
6393 /* Should already be byte swapped. */
6394 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
6395 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
6396 /* swap the size field back to the cpu so we
6397 * can assign it to the sgl.
6399 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
6400 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
6402 for (i
= 0; i
< numBdes
; i
++) {
6403 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
6404 total_len
+= bde
.tus
.f
.bdeSize
;
6407 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
6409 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
6410 cmnd
= iocbq
->iocb
.ulpCommand
;
6412 switch (iocbq
->iocb
.ulpCommand
) {
6413 case CMD_ELS_REQUEST64_CR
:
6414 if (!iocbq
->iocb
.ulpLe
) {
6415 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6416 "2007 Only Limited Edition cmd Format"
6417 " supported 0x%x\n",
6418 iocbq
->iocb
.ulpCommand
);
6421 wqe
->els_req
.payload_len
= xmit_len
;
6422 /* Els_reguest64 has a TMO */
6423 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
6424 iocbq
->iocb
.ulpTimeout
);
6425 /* Need a VF for word 4 set the vf bit*/
6426 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
6427 /* And a VFID for word 12 */
6428 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
6430 * Set ct field to 3, indicates that the context_tag field
6431 * contains the FCFI and remote N_Port_ID is
6434 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
6435 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
6436 iocbq
->iocb
.ulpContext
);
6437 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
6438 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
6439 /* CCP CCPE PV PRI in word10 were set in the memcpy */
6440 if (command_type
== ELS_COMMAND_FIP
) {
6441 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
6442 >> LPFC_FIP_ELS_ID_SHIFT
);
6444 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
6445 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
6446 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
6447 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
6448 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
6449 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
6451 case CMD_XMIT_SEQUENCE64_CX
:
6452 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
6453 iocbq
->iocb
.un
.ulpWord
[3]);
6454 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
6455 iocbq
->iocb
.ulpContext
);
6456 /* The entire sequence is transmitted for this IOCB */
6457 xmit_len
= total_len
;
6458 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
6459 case CMD_XMIT_SEQUENCE64_CR
:
6460 /* word3 iocb=io_tag32 wqe=reserved */
6461 wqe
->xmit_sequence
.rsvd3
= 0;
6462 /* word4 relative_offset memcpy */
6463 /* word5 r_ctl/df_ctl memcpy */
6464 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
6465 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
6466 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
6467 LPFC_WQE_IOD_WRITE
);
6468 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
6469 LPFC_WQE_LENLOC_WORD12
);
6470 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
6471 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
6472 command_type
= OTHER_COMMAND
;
6474 case CMD_XMIT_BCAST64_CN
:
6475 /* word3 iocb=iotag32 wqe=seq_payload_len */
6476 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
6477 /* word4 iocb=rsvd wqe=rsvd */
6478 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
6479 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
6480 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
6481 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6482 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
6483 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
6484 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
6485 LPFC_WQE_LENLOC_WORD3
);
6486 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
6488 case CMD_FCP_IWRITE64_CR
:
6489 command_type
= FCP_COMMAND_DATA_OUT
;
6490 /* word3 iocb=iotag wqe=payload_offset_len */
6491 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
6492 wqe
->fcp_iwrite
.payload_offset_len
=
6493 xmit_len
+ sizeof(struct fcp_rsp
);
6494 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
6495 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
6496 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
6497 iocbq
->iocb
.ulpFCP2Rcvy
);
6498 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
6499 /* Always open the exchange */
6500 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
6501 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
6502 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
6503 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
6504 LPFC_WQE_LENLOC_WORD4
);
6505 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
6506 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
6508 case CMD_FCP_IREAD64_CR
:
6509 /* word3 iocb=iotag wqe=payload_offset_len */
6510 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
6511 wqe
->fcp_iread
.payload_offset_len
=
6512 xmit_len
+ sizeof(struct fcp_rsp
);
6513 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
6514 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
6515 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
6516 iocbq
->iocb
.ulpFCP2Rcvy
);
6517 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
6518 /* Always open the exchange */
6519 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
6520 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
6521 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
6522 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
6523 LPFC_WQE_LENLOC_WORD4
);
6524 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
6525 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
6527 case CMD_FCP_ICMND64_CR
:
6528 /* word3 iocb=IO_TAG wqe=reserved */
6529 wqe
->fcp_icmd
.rsrvd3
= 0;
6530 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
6531 /* Always open the exchange */
6532 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
6533 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
6534 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
6535 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
6536 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
6537 LPFC_WQE_LENLOC_NONE
);
6538 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
6540 case CMD_GEN_REQUEST64_CR
:
6541 /* For this command calculate the xmit length of the
6545 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
6546 sizeof(struct ulp_bde64
);
6547 for (i
= 0; i
< numBdes
; i
++) {
6548 if (bpl
[i
].tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
6550 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
6551 xmit_len
+= bde
.tus
.f
.bdeSize
;
6553 /* word3 iocb=IO_TAG wqe=request_payload_len */
6554 wqe
->gen_req
.request_payload_len
= xmit_len
;
6555 /* word4 iocb=parameter wqe=relative_offset memcpy */
6556 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
6557 /* word6 context tag copied in memcpy */
6558 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
6559 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
6560 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6561 "2015 Invalid CT %x command 0x%x\n",
6562 ct
, iocbq
->iocb
.ulpCommand
);
6565 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
6566 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
6567 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
6568 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
6569 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
6570 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
6571 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
6572 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
6573 command_type
= OTHER_COMMAND
;
6575 case CMD_XMIT_ELS_RSP64_CX
:
6576 /* words0-2 BDE memcpy */
6577 /* word3 iocb=iotag32 wqe=response_payload_len */
6578 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
6579 /* word4 iocb=did wge=rsvd. */
6580 wqe
->xmit_els_rsp
.rsvd4
= 0;
6581 /* word5 iocb=rsvd wge=did */
6582 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
6583 iocbq
->iocb
.un
.elsreq64
.remoteID
);
6584 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
6585 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6586 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
6587 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
6588 iocbq
->iocb
.ulpContext
);
6589 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
6590 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
6591 iocbq
->vport
->vpi
+ phba
->vpi_base
);
6592 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
6593 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
6594 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
6595 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
6596 LPFC_WQE_LENLOC_WORD3
);
6597 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
6598 command_type
= OTHER_COMMAND
;
6600 case CMD_CLOSE_XRI_CN
:
6601 case CMD_ABORT_XRI_CN
:
6602 case CMD_ABORT_XRI_CX
:
6603 /* words 0-2 memcpy should be 0 rserved */
6604 /* port will send abts */
6605 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
6606 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
6607 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
6608 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
6612 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
6614 * The link is down, or the command was ELS_FIP
6615 * so the fw does not need to send abts
6618 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
6620 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
6621 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
6622 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
6623 wqe
->abort_cmd
.rsrvd5
= 0;
6624 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
6625 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
6626 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
6628 * The abort handler will send us CMD_ABORT_XRI_CN or
6629 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6631 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
6632 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
6633 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
6634 LPFC_WQE_LENLOC_NONE
);
6635 cmnd
= CMD_ABORT_XRI_CX
;
6636 command_type
= OTHER_COMMAND
;
6639 case CMD_XMIT_BLS_RSP64_CX
:
6640 /* As BLS ABTS-ACC WQE is very different from other WQEs,
6641 * we re-construct this WQE here based on information in
6642 * iocbq from scratch.
6644 memset(wqe
, 0, sizeof(union lpfc_wqe
));
6645 /* OX_ID is invariable to who sent ABTS to CT exchange */
6646 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
6647 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_acc
));
6648 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_acc
) ==
6649 LPFC_ABTS_UNSOL_INT
) {
6650 /* ABTS sent by initiator to CT exchange, the
6651 * RX_ID field will be filled with the newly
6652 * allocated responder XRI.
6654 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
6655 iocbq
->sli4_xritag
);
6657 /* ABTS sent by responder to CT exchange, the
6658 * RX_ID field will be filled with the responder
6661 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
6662 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_acc
));
6664 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
6665 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
6666 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
6667 iocbq
->iocb
.ulpContext
);
6668 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
6669 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
6670 LPFC_WQE_LENLOC_NONE
);
6671 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
6672 command_type
= OTHER_COMMAND
;
6674 case CMD_XRI_ABORTED_CX
:
6675 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
6676 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
6677 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
6678 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
6679 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
6681 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6682 "2014 Invalid command 0x%x\n",
6683 iocbq
->iocb
.ulpCommand
);
6687 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
6688 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
6689 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
6690 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
6691 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
6692 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
6693 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
6698 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
6699 * @phba: Pointer to HBA context object.
6700 * @ring_number: SLI ring number to issue iocb on.
6701 * @piocb: Pointer to command iocb.
6702 * @flag: Flag indicating if this command can be put into txq.
6704 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
6705 * an iocb command to an HBA with SLI-4 interface spec.
6707 * This function is called with hbalock held. The function will return success
6708 * after it successfully submit the iocb to firmware or after adding to the
6712 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
6713 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6715 struct lpfc_sglq
*sglq
;
6717 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
6719 if (piocb
->sli4_xritag
== NO_XRI
) {
6720 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
6721 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6724 if (pring
->txq_cnt
) {
6725 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
6726 __lpfc_sli_ringtx_put(phba
,
6728 return IOCB_SUCCESS
;
6733 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
6735 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
6736 __lpfc_sli_ringtx_put(phba
,
6739 return IOCB_SUCCESS
;
6745 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
6746 sglq
= NULL
; /* These IO's already have an XRI and
6750 /* This is a continuation of a commandi,(CX) so this
6751 * sglq is on the active list
6753 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
6759 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
6761 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
6765 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
6768 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
6769 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
6771 * For FCP command IOCB, get a new WQ index to distribute
6772 * WQE across the WQsr. On the other hand, for abort IOCB,
6773 * it carries the same WQ index to the original command
6776 if (piocb
->iocb_flag
& LPFC_IO_FCP
)
6777 piocb
->fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
6778 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
6782 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
6785 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
6791 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
6793 * This routine wraps the actual lockless version for issusing IOCB function
6794 * pointer from the lpfc_hba struct.
6797 * IOCB_ERROR - Error
6798 * IOCB_SUCCESS - Success
6802 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6803 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6805 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6809 * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
6810 * @phba: The hba struct for which this call is being executed.
6811 * @dev_grp: The HBA PCI-Device group number.
6813 * This routine sets up the SLI interface API function jump table in @phba
6815 * Returns: 0 - success, -ENODEV - failure.
6818 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6822 case LPFC_PCI_DEV_LP
:
6823 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
6824 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
6826 case LPFC_PCI_DEV_OC
:
6827 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
6828 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
6831 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6832 "1419 Invalid HBA PCI-device group: 0x%x\n",
6837 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
6842 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
6843 * @phba: Pointer to HBA context object.
6844 * @pring: Pointer to driver SLI ring object.
6845 * @piocb: Pointer to command iocb.
6846 * @flag: Flag indicating if this command can be put into txq.
6848 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
6849 * function. This function gets the hbalock and calls
6850 * __lpfc_sli_issue_iocb function and will return the error returned
6851 * by __lpfc_sli_issue_iocb function. This wrapper is used by
6852 * functions which do not hold hbalock.
6855 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
6856 struct lpfc_iocbq
*piocb
, uint32_t flag
)
6858 unsigned long iflags
;
6861 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6862 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
6863 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6869 * lpfc_extra_ring_setup - Extra ring setup function
6870 * @phba: Pointer to HBA context object.
6872 * This function is called while driver attaches with the
6873 * HBA to setup the extra ring. The extra ring is used
6874 * only when driver needs to support target mode functionality
6875 * or IP over FC functionalities.
6877 * This function is called with no lock held.
6880 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
6882 struct lpfc_sli
*psli
;
6883 struct lpfc_sli_ring
*pring
;
6887 /* Adjust cmd/rsp ring iocb entries more evenly */
6889 /* Take some away from the FCP ring */
6890 pring
= &psli
->ring
[psli
->fcp_ring
];
6891 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6892 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6893 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6894 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6896 /* and give them to the extra ring */
6897 pring
= &psli
->ring
[psli
->extra_ring
];
6899 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
6900 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
6901 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
6902 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
6904 /* Setup default profile for this ring */
6905 pring
->iotag_max
= 4096;
6906 pring
->num_mask
= 1;
6907 pring
->prt
[0].profile
= 0; /* Mask 0 */
6908 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
6909 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
6910 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
6915 * lpfc_sli_async_event_handler - ASYNC iocb handler function
6916 * @phba: Pointer to HBA context object.
6917 * @pring: Pointer to driver SLI ring object.
6918 * @iocbq: Pointer to iocb object.
6920 * This function is called by the slow ring event handler
6921 * function when there is an ASYNC event iocb in the ring.
6922 * This function is called with no lock held.
6923 * Currently this function handles only temperature related
6924 * ASYNC events. The function decodes the temperature sensor
6925 * event message and posts events for the management applications.
6928 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
6929 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
6934 struct temp_event temp_event_data
;
6935 struct Scsi_Host
*shost
;
6938 icmd
= &iocbq
->iocb
;
6939 evt_code
= icmd
->un
.asyncstat
.evt_code
;
6940 temp
= icmd
->ulpContext
;
6942 if ((evt_code
!= ASYNC_TEMP_WARN
) &&
6943 (evt_code
!= ASYNC_TEMP_SAFE
)) {
6944 iocb_w
= (uint32_t *) icmd
;
6945 lpfc_printf_log(phba
,
6948 "0346 Ring %d handler: unexpected ASYNC_STATUS"
6950 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
6951 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
6952 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
6953 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
6955 icmd
->un
.asyncstat
.evt_code
,
6956 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
6957 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
6958 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
6959 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
6963 temp_event_data
.data
= (uint32_t)temp
;
6964 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
6965 if (evt_code
== ASYNC_TEMP_WARN
) {
6966 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
6967 lpfc_printf_log(phba
,
6970 "0347 Adapter is very hot, please take "
6971 "corrective action. temperature : %d Celsius\n",
6974 if (evt_code
== ASYNC_TEMP_SAFE
) {
6975 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
6976 lpfc_printf_log(phba
,
6979 "0340 Adapter temperature is OK now. "
6980 "temperature : %d Celsius\n",
6984 /* Send temperature change event to applications */
6985 shost
= lpfc_shost_from_vport(phba
->pport
);
6986 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6987 sizeof(temp_event_data
), (char *) &temp_event_data
,
6994 * lpfc_sli_setup - SLI ring setup function
6995 * @phba: Pointer to HBA context object.
6997 * lpfc_sli_setup sets up rings of the SLI interface with
6998 * number of iocbs per ring and iotags. This function is
6999 * called while driver attach to the HBA and before the
7000 * interrupts are enabled. So there is no need for locking.
7002 * This function always returns 0.
7005 lpfc_sli_setup(struct lpfc_hba
*phba
)
7007 int i
, totiocbsize
= 0;
7008 struct lpfc_sli
*psli
= &phba
->sli
;
7009 struct lpfc_sli_ring
*pring
;
7011 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
7013 psli
->fcp_ring
= LPFC_FCP_RING
;
7014 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
7015 psli
->extra_ring
= LPFC_EXTRA_RING
;
7017 psli
->iocbq_lookup
= NULL
;
7018 psli
->iocbq_lookup_len
= 0;
7019 psli
->last_iotag
= 0;
7021 for (i
= 0; i
< psli
->num_rings
; i
++) {
7022 pring
= &psli
->ring
[i
];
7024 case LPFC_FCP_RING
: /* ring 0 - FCP */
7025 /* numCiocb and numRiocb are used in config_port */
7026 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
7027 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
7028 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
7029 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
7030 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
7031 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
7032 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
7033 SLI3_IOCB_CMD_SIZE
:
7035 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
7036 SLI3_IOCB_RSP_SIZE
:
7038 pring
->iotag_ctr
= 0;
7040 (phba
->cfg_hba_queue_depth
* 2);
7041 pring
->fast_iotag
= pring
->iotag_max
;
7042 pring
->num_mask
= 0;
7044 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
7045 /* numCiocb and numRiocb are used in config_port */
7046 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
7047 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
7048 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
7049 SLI3_IOCB_CMD_SIZE
:
7051 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
7052 SLI3_IOCB_RSP_SIZE
:
7054 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
7055 pring
->num_mask
= 0;
7057 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
7058 /* numCiocb and numRiocb are used in config_port */
7059 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
7060 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
7061 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
7062 SLI3_IOCB_CMD_SIZE
:
7064 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
7065 SLI3_IOCB_RSP_SIZE
:
7067 pring
->fast_iotag
= 0;
7068 pring
->iotag_ctr
= 0;
7069 pring
->iotag_max
= 4096;
7070 pring
->lpfc_sli_rcv_async_status
=
7071 lpfc_sli_async_event_handler
;
7072 pring
->num_mask
= LPFC_MAX_RING_MASK
;
7073 pring
->prt
[0].profile
= 0; /* Mask 0 */
7074 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
7075 pring
->prt
[0].type
= FC_TYPE_ELS
;
7076 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
7077 lpfc_els_unsol_event
;
7078 pring
->prt
[1].profile
= 0; /* Mask 1 */
7079 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
7080 pring
->prt
[1].type
= FC_TYPE_ELS
;
7081 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
7082 lpfc_els_unsol_event
;
7083 pring
->prt
[2].profile
= 0; /* Mask 2 */
7084 /* NameServer Inquiry */
7085 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
7087 pring
->prt
[2].type
= FC_TYPE_CT
;
7088 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
7089 lpfc_ct_unsol_event
;
7090 pring
->prt
[3].profile
= 0; /* Mask 3 */
7091 /* NameServer response */
7092 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
7094 pring
->prt
[3].type
= FC_TYPE_CT
;
7095 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
7096 lpfc_ct_unsol_event
;
7097 /* abort unsolicited sequence */
7098 pring
->prt
[4].profile
= 0; /* Mask 4 */
7099 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
7100 pring
->prt
[4].type
= FC_TYPE_BLS
;
7101 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
7102 lpfc_sli4_ct_abort_unsol_event
;
7105 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
7106 (pring
->numRiocb
* pring
->sizeRiocb
);
7108 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
7109 /* Too many cmd / rsp ring entries in SLI2 SLIM */
7110 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
7111 "SLI2 SLIM Data: x%x x%lx\n",
7112 phba
->brd_no
, totiocbsize
,
7113 (unsigned long) MAX_SLIM_IOCB_SIZE
);
7115 if (phba
->cfg_multi_ring_support
== 2)
7116 lpfc_extra_ring_setup(phba
);
7122 * lpfc_sli_queue_setup - Queue initialization function
7123 * @phba: Pointer to HBA context object.
7125 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
7126 * ring. This function also initializes ring indices of each ring.
7127 * This function is called during the initialization of the SLI
7128 * interface of an HBA.
7129 * This function is called with no lock held and always returns
7133 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
7135 struct lpfc_sli
*psli
;
7136 struct lpfc_sli_ring
*pring
;
7140 spin_lock_irq(&phba
->hbalock
);
7141 INIT_LIST_HEAD(&psli
->mboxq
);
7142 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
7143 /* Initialize list headers for txq and txcmplq as double linked lists */
7144 for (i
= 0; i
< psli
->num_rings
; i
++) {
7145 pring
= &psli
->ring
[i
];
7147 pring
->next_cmdidx
= 0;
7148 pring
->local_getidx
= 0;
7150 INIT_LIST_HEAD(&pring
->txq
);
7151 INIT_LIST_HEAD(&pring
->txcmplq
);
7152 INIT_LIST_HEAD(&pring
->iocb_continueq
);
7153 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
7154 INIT_LIST_HEAD(&pring
->postbufq
);
7156 spin_unlock_irq(&phba
->hbalock
);
7161 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
7162 * @phba: Pointer to HBA context object.
7164 * This routine flushes the mailbox command subsystem. It will unconditionally
7165 * flush all the mailbox commands in the three possible stages in the mailbox
7166 * command sub-system: pending mailbox command queue; the outstanding mailbox
7167 * command; and completed mailbox command queue. It is caller's responsibility
7168 * to make sure that the driver is in the proper state to flush the mailbox
7169 * command sub-system. Namely, the posting of mailbox commands into the
7170 * pending mailbox command queue from the various clients must be stopped;
7171 * either the HBA is in a state that it will never works on the outstanding
7172 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
7173 * mailbox command has been completed.
7176 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
7178 LIST_HEAD(completions
);
7179 struct lpfc_sli
*psli
= &phba
->sli
;
7181 unsigned long iflag
;
7183 /* Flush all the mailbox commands in the mbox system */
7184 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7185 /* The pending mailbox command queue */
7186 list_splice_init(&phba
->sli
.mboxq
, &completions
);
7187 /* The outstanding active mailbox command */
7188 if (psli
->mbox_active
) {
7189 list_add_tail(&psli
->mbox_active
->list
, &completions
);
7190 psli
->mbox_active
= NULL
;
7191 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7193 /* The completed mailbox command queue */
7194 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
7195 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7197 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
7198 while (!list_empty(&completions
)) {
7199 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
7200 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7202 pmb
->mbox_cmpl(phba
, pmb
);
7207 * lpfc_sli_host_down - Vport cleanup function
7208 * @vport: Pointer to virtual port object.
7210 * lpfc_sli_host_down is called to clean up the resources
7211 * associated with a vport before destroying virtual
7212 * port data structures.
7213 * This function does following operations:
7214 * - Free discovery resources associated with this virtual
7216 * - Free iocbs associated with this virtual port in
7218 * - Send abort for all iocb commands associated with this
7221 * This function is called with no lock held and always returns 1.
7224 lpfc_sli_host_down(struct lpfc_vport
*vport
)
7226 LIST_HEAD(completions
);
7227 struct lpfc_hba
*phba
= vport
->phba
;
7228 struct lpfc_sli
*psli
= &phba
->sli
;
7229 struct lpfc_sli_ring
*pring
;
7230 struct lpfc_iocbq
*iocb
, *next_iocb
;
7232 unsigned long flags
= 0;
7233 uint16_t prev_pring_flag
;
7235 lpfc_cleanup_discovery_resources(vport
);
7237 spin_lock_irqsave(&phba
->hbalock
, flags
);
7238 for (i
= 0; i
< psli
->num_rings
; i
++) {
7239 pring
= &psli
->ring
[i
];
7240 prev_pring_flag
= pring
->flag
;
7241 /* Only slow rings */
7242 if (pring
->ringno
== LPFC_ELS_RING
) {
7243 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
7244 /* Set the lpfc data pending flag */
7245 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
7248 * Error everything on the txq since these iocbs have not been
7249 * given to the FW yet.
7251 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
7252 if (iocb
->vport
!= vport
)
7254 list_move_tail(&iocb
->list
, &completions
);
7258 /* Next issue ABTS for everything on the txcmplq */
7259 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
7261 if (iocb
->vport
!= vport
)
7263 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
7266 pring
->flag
= prev_pring_flag
;
7269 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
7271 /* Cancel all the IOCBs from the completions list */
7272 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7278 * lpfc_sli_hba_down - Resource cleanup function for the HBA
7279 * @phba: Pointer to HBA context object.
7281 * This function cleans up all iocb, buffers, mailbox commands
7282 * while shutting down the HBA. This function is called with no
7283 * lock held and always returns 1.
7284 * This function does the following to cleanup driver resources:
7285 * - Free discovery resources for each virtual port
7286 * - Cleanup any pending fabric iocbs
7287 * - Iterate through the iocb txq and free each entry
7289 * - Free up any buffer posted to the HBA
7290 * - Free mailbox commands in the mailbox queue.
7293 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
7295 LIST_HEAD(completions
);
7296 struct lpfc_sli
*psli
= &phba
->sli
;
7297 struct lpfc_sli_ring
*pring
;
7298 struct lpfc_dmabuf
*buf_ptr
;
7299 unsigned long flags
= 0;
7302 /* Shutdown the mailbox command sub-system */
7303 lpfc_sli_mbox_sys_shutdown(phba
);
7305 lpfc_hba_down_prep(phba
);
7307 lpfc_fabric_abort_hba(phba
);
7309 spin_lock_irqsave(&phba
->hbalock
, flags
);
7310 for (i
= 0; i
< psli
->num_rings
; i
++) {
7311 pring
= &psli
->ring
[i
];
7312 /* Only slow rings */
7313 if (pring
->ringno
== LPFC_ELS_RING
) {
7314 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
7315 /* Set the lpfc data pending flag */
7316 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
7320 * Error everything on the txq since these iocbs have not been
7321 * given to the FW yet.
7323 list_splice_init(&pring
->txq
, &completions
);
7327 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
7329 /* Cancel all the IOCBs from the completions list */
7330 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7333 spin_lock_irqsave(&phba
->hbalock
, flags
);
7334 list_splice_init(&phba
->elsbuf
, &completions
);
7335 phba
->elsbuf_cnt
= 0;
7336 phba
->elsbuf_prev_cnt
= 0;
7337 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
7339 while (!list_empty(&completions
)) {
7340 list_remove_head(&completions
, buf_ptr
,
7341 struct lpfc_dmabuf
, list
);
7342 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
7346 /* Return any active mbox cmds */
7347 del_timer_sync(&psli
->mbox_tmo
);
7349 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
7350 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
7351 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
7357 * lpfc_sli_pcimem_bcopy - SLI memory copy function
7358 * @srcp: Source memory pointer.
7359 * @destp: Destination memory pointer.
7360 * @cnt: Number of words required to be copied.
7362 * This function is used for copying data between driver memory
7363 * and the SLI memory. This function also changes the endianness
7364 * of each word if native endianness is different from SLI
7365 * endianness. This function can be called with or without
7369 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
7371 uint32_t *src
= srcp
;
7372 uint32_t *dest
= destp
;
7376 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
7378 ldata
= le32_to_cpu(ldata
);
7387 * lpfc_sli_bemem_bcopy - SLI memory copy function
7388 * @srcp: Source memory pointer.
7389 * @destp: Destination memory pointer.
7390 * @cnt: Number of words required to be copied.
7392 * This function is used for copying data between a data structure
7393 * with big endian representation to local endianness.
7394 * This function can be called with or without lock.
7397 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
7399 uint32_t *src
= srcp
;
7400 uint32_t *dest
= destp
;
7404 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
7406 ldata
= be32_to_cpu(ldata
);
7414 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
7415 * @phba: Pointer to HBA context object.
7416 * @pring: Pointer to driver SLI ring object.
7417 * @mp: Pointer to driver buffer object.
7419 * This function is called with no lock held.
7420 * It always return zero after adding the buffer to the postbufq
7424 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7425 struct lpfc_dmabuf
*mp
)
7427 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
7429 spin_lock_irq(&phba
->hbalock
);
7430 list_add_tail(&mp
->list
, &pring
->postbufq
);
7431 pring
->postbufq_cnt
++;
7432 spin_unlock_irq(&phba
->hbalock
);
7437 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
7438 * @phba: Pointer to HBA context object.
7440 * When HBQ is enabled, buffers are searched based on tags. This function
7441 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
7442 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
7443 * does not conflict with tags of buffer posted for unsolicited events.
7444 * The function returns the allocated tag. The function is called with
7448 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
7450 spin_lock_irq(&phba
->hbalock
);
7451 phba
->buffer_tag_count
++;
7453 * Always set the QUE_BUFTAG_BIT to distiguish between
7454 * a tag assigned by HBQ.
7456 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
7457 spin_unlock_irq(&phba
->hbalock
);
7458 return phba
->buffer_tag_count
;
7462 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
7463 * @phba: Pointer to HBA context object.
7464 * @pring: Pointer to driver SLI ring object.
7467 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
7468 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
7469 * iocb is posted to the response ring with the tag of the buffer.
7470 * This function searches the pring->postbufq list using the tag
7471 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
7472 * iocb. If the buffer is found then lpfc_dmabuf object of the
7473 * buffer is returned to the caller else NULL is returned.
7474 * This function is called with no lock held.
7476 struct lpfc_dmabuf
*
7477 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7480 struct lpfc_dmabuf
*mp
, *next_mp
;
7481 struct list_head
*slp
= &pring
->postbufq
;
7483 /* Search postbufq, from the begining, looking for a match on tag */
7484 spin_lock_irq(&phba
->hbalock
);
7485 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
7486 if (mp
->buffer_tag
== tag
) {
7487 list_del_init(&mp
->list
);
7488 pring
->postbufq_cnt
--;
7489 spin_unlock_irq(&phba
->hbalock
);
7494 spin_unlock_irq(&phba
->hbalock
);
7495 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7496 "0402 Cannot find virtual addr for buffer tag on "
7497 "ring %d Data x%lx x%p x%p x%x\n",
7498 pring
->ringno
, (unsigned long) tag
,
7499 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
7505 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
7506 * @phba: Pointer to HBA context object.
7507 * @pring: Pointer to driver SLI ring object.
7508 * @phys: DMA address of the buffer.
7510 * This function searches the buffer list using the dma_address
7511 * of unsolicited event to find the driver's lpfc_dmabuf object
7512 * corresponding to the dma_address. The function returns the
7513 * lpfc_dmabuf object if a buffer is found else it returns NULL.
7514 * This function is called by the ct and els unsolicited event
7515 * handlers to get the buffer associated with the unsolicited
7518 * This function is called with no lock held.
7520 struct lpfc_dmabuf
*
7521 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7524 struct lpfc_dmabuf
*mp
, *next_mp
;
7525 struct list_head
*slp
= &pring
->postbufq
;
7527 /* Search postbufq, from the begining, looking for a match on phys */
7528 spin_lock_irq(&phba
->hbalock
);
7529 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
7530 if (mp
->phys
== phys
) {
7531 list_del_init(&mp
->list
);
7532 pring
->postbufq_cnt
--;
7533 spin_unlock_irq(&phba
->hbalock
);
7538 spin_unlock_irq(&phba
->hbalock
);
7539 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7540 "0410 Cannot find virtual addr for mapped buf on "
7541 "ring %d Data x%llx x%p x%p x%x\n",
7542 pring
->ringno
, (unsigned long long)phys
,
7543 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
7548 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
7549 * @phba: Pointer to HBA context object.
7550 * @cmdiocb: Pointer to driver command iocb object.
7551 * @rspiocb: Pointer to driver response iocb object.
7553 * This function is the completion handler for the abort iocbs for
7554 * ELS commands. This function is called from the ELS ring event
7555 * handler with no lock held. This function frees memory resources
7556 * associated with the abort iocb.
7559 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7560 struct lpfc_iocbq
*rspiocb
)
7562 IOCB_t
*irsp
= &rspiocb
->iocb
;
7563 uint16_t abort_iotag
, abort_context
;
7564 struct lpfc_iocbq
*abort_iocb
;
7565 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7569 if (irsp
->ulpStatus
) {
7570 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
7571 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
7573 spin_lock_irq(&phba
->hbalock
);
7574 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7575 if (abort_iotag
!= 0 &&
7576 abort_iotag
<= phba
->sli
.last_iotag
)
7578 phba
->sli
.iocbq_lookup
[abort_iotag
];
7580 /* For sli4 the abort_tag is the XRI,
7581 * so the abort routine puts the iotag of the iocb
7582 * being aborted in the context field of the abort
7585 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
7588 * If the iocb is not found in Firmware queue the iocb
7589 * might have completed already. Do not free it again.
7591 if (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
7592 if (irsp
->un
.ulpWord
[4] != IOERR_NO_XRI
) {
7593 spin_unlock_irq(&phba
->hbalock
);
7594 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7597 /* For SLI4 the ulpContext field for abort IOCB
7598 * holds the iotag of the IOCB being aborted so
7599 * the local abort_context needs to be reset to
7600 * match the aborted IOCBs ulpContext.
7602 if (abort_iocb
&& phba
->sli_rev
== LPFC_SLI_REV4
)
7603 abort_context
= abort_iocb
->iocb
.ulpContext
;
7606 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
7607 "0327 Cannot abort els iocb %p "
7608 "with tag %x context %x, abort status %x, "
7610 abort_iocb
, abort_iotag
, abort_context
,
7611 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
7613 * make sure we have the right iocbq before taking it
7614 * off the txcmplq and try to call completion routine.
7617 abort_iocb
->iocb
.ulpContext
!= abort_context
||
7618 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
7619 spin_unlock_irq(&phba
->hbalock
);
7620 else if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7622 * leave the SLI4 aborted command on the txcmplq
7623 * list and the command complete WCQE's XB bit
7624 * will tell whether the SGL (XRI) can be released
7625 * immediately or to the aborted SGL list for the
7626 * following abort XRI from the HBA.
7628 list_del_init(&abort_iocb
->list
);
7629 if (abort_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
7630 abort_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
7631 pring
->txcmplq_cnt
--;
7634 /* Firmware could still be in progress of DMAing
7635 * payload, so don't free data buffer till after
7638 abort_iocb
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
7639 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
7640 spin_unlock_irq(&phba
->hbalock
);
7642 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
7643 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_ABORT_REQUESTED
;
7644 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
7646 spin_unlock_irq(&phba
->hbalock
);
7649 lpfc_sli_release_iocbq(phba
, cmdiocb
);
7654 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
7655 * @phba: Pointer to HBA context object.
7656 * @cmdiocb: Pointer to driver command iocb object.
7657 * @rspiocb: Pointer to driver response iocb object.
7659 * The function is called from SLI ring event handler with no
7660 * lock held. This function is the completion handler for ELS commands
7661 * which are aborted. The function frees memory resources used for
7662 * the aborted ELS commands.
7665 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7666 struct lpfc_iocbq
*rspiocb
)
7668 IOCB_t
*irsp
= &rspiocb
->iocb
;
7670 /* ELS cmd tag <ulpIoTag> completes */
7671 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
7672 "0139 Ignoring ELS cmd tag x%x completion Data: "
7674 irsp
->ulpIoTag
, irsp
->ulpStatus
,
7675 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
7676 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
7677 lpfc_ct_free_iocb(phba
, cmdiocb
);
7679 lpfc_els_free_iocb(phba
, cmdiocb
);
7684 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
7685 * @phba: Pointer to HBA context object.
7686 * @pring: Pointer to driver SLI ring object.
7687 * @cmdiocb: Pointer to driver command iocb object.
7689 * This function issues an abort iocb for the provided command iocb down to
7690 * the port. Other than the case the outstanding command iocb is an abort
7691 * request, this function issues abort out unconditionally. This function is
7692 * called with hbalock held. The function returns 0 when it fails due to
7693 * memory allocation failure or when the command iocb is an abort request.
7696 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7697 struct lpfc_iocbq
*cmdiocb
)
7699 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7700 struct lpfc_iocbq
*abtsiocbp
;
7701 IOCB_t
*icmd
= NULL
;
7702 IOCB_t
*iabt
= NULL
;
7706 * There are certain command types we don't want to abort. And we
7707 * don't want to abort commands that are already in the process of
7710 icmd
= &cmdiocb
->iocb
;
7711 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
7712 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7713 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
7716 /* issue ABTS for this IOCB based on iotag */
7717 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
7718 if (abtsiocbp
== NULL
)
7721 /* This signals the response to set the correct status
7722 * before calling the completion handler
7724 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
7726 iabt
= &abtsiocbp
->iocb
;
7727 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
7728 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
7729 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7730 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
7731 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
7734 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
7736 iabt
->ulpClass
= icmd
->ulpClass
;
7738 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7739 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
7740 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
7741 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
7743 if (phba
->link_state
>= LPFC_LINK_UP
)
7744 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
7746 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
7748 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
7750 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
7751 "0339 Abort xri x%x, original iotag x%x, "
7752 "abort cmd iotag x%x\n",
7753 iabt
->un
.acxri
.abortIoTag
,
7754 iabt
->un
.acxri
.abortContextTag
,
7756 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
7759 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
7762 * Caller to this routine should check for IOCB_ERROR
7763 * and handle it properly. This routine no longer removes
7764 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7770 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7771 * @phba: Pointer to HBA context object.
7772 * @pring: Pointer to driver SLI ring object.
7773 * @cmdiocb: Pointer to driver command iocb object.
7775 * This function issues an abort iocb for the provided command iocb. In case
7776 * of unloading, the abort iocb will not be issued to commands on the ELS
7777 * ring. Instead, the callback function shall be changed to those commands
7778 * so that nothing happens when them finishes. This function is called with
7779 * hbalock held. The function returns 0 when the command iocb is an abort
7783 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7784 struct lpfc_iocbq
*cmdiocb
)
7786 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7787 int retval
= IOCB_ERROR
;
7788 IOCB_t
*icmd
= NULL
;
7791 * There are certain command types we don't want to abort. And we
7792 * don't want to abort commands that are already in the process of
7795 icmd
= &cmdiocb
->iocb
;
7796 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
7797 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7798 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
7802 * If we're unloading, don't abort iocb on the ELS ring, but change
7803 * the callback so that nothing happens when it finishes.
7805 if ((vport
->load_flag
& FC_UNLOADING
) &&
7806 (pring
->ringno
== LPFC_ELS_RING
)) {
7807 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
7808 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
7810 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
7811 goto abort_iotag_exit
;
7814 /* Now, we try to issue the abort to the cmdiocb out */
7815 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
7819 * Caller to this routine should check for IOCB_ERROR
7820 * and handle it properly. This routine no longer removes
7821 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7827 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
7828 * @phba: Pointer to HBA context object.
7829 * @pring: Pointer to driver SLI ring object.
7831 * This function aborts all iocbs in the given ring and frees all the iocb
7832 * objects in txq. This function issues abort iocbs unconditionally for all
7833 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
7834 * to complete before the return of this function. The caller is not required
7835 * to hold any locks.
7838 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
7840 LIST_HEAD(completions
);
7841 struct lpfc_iocbq
*iocb
, *next_iocb
;
7843 if (pring
->ringno
== LPFC_ELS_RING
)
7844 lpfc_fabric_abort_hba(phba
);
7846 spin_lock_irq(&phba
->hbalock
);
7848 /* Take off all the iocbs on txq for cancelling */
7849 list_splice_init(&pring
->txq
, &completions
);
7852 /* Next issue ABTS for everything on the txcmplq */
7853 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
7854 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
7856 spin_unlock_irq(&phba
->hbalock
);
7858 /* Cancel all the IOCBs from the completions list */
7859 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7864 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
7865 * @phba: pointer to lpfc HBA data structure.
7867 * This routine will abort all pending and outstanding iocbs to an HBA.
7870 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
7872 struct lpfc_sli
*psli
= &phba
->sli
;
7873 struct lpfc_sli_ring
*pring
;
7876 for (i
= 0; i
< psli
->num_rings
; i
++) {
7877 pring
= &psli
->ring
[i
];
7878 lpfc_sli_iocb_ring_abort(phba
, pring
);
7883 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7884 * @iocbq: Pointer to driver iocb object.
7885 * @vport: Pointer to driver virtual port object.
7886 * @tgt_id: SCSI ID of the target.
7887 * @lun_id: LUN ID of the scsi device.
7888 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
7890 * This function acts as an iocb filter for functions which abort or count
7891 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
7892 * 0 if the filtering criteria is met for the given iocb and will return
7893 * 1 if the filtering criteria is not met.
7894 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
7895 * given iocb is for the SCSI device specified by vport, tgt_id and
7897 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
7898 * given iocb is for the SCSI target specified by vport and tgt_id
7900 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
7901 * given iocb is for the SCSI host associated with the given vport.
7902 * This function is called with no locks held.
7905 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
7906 uint16_t tgt_id
, uint64_t lun_id
,
7907 lpfc_ctx_cmd ctx_cmd
)
7909 struct lpfc_scsi_buf
*lpfc_cmd
;
7912 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
7915 if (iocbq
->vport
!= vport
)
7918 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
7920 if (lpfc_cmd
->pCmd
== NULL
)
7925 if ((lpfc_cmd
->rdata
->pnode
) &&
7926 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
7927 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
7931 if ((lpfc_cmd
->rdata
->pnode
) &&
7932 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
7939 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
7948 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
7949 * @vport: Pointer to virtual port.
7950 * @tgt_id: SCSI ID of the target.
7951 * @lun_id: LUN ID of the scsi device.
7952 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
7954 * This function returns number of FCP commands pending for the vport.
7955 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
7956 * commands pending on the vport associated with SCSI device specified
7957 * by tgt_id and lun_id parameters.
7958 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
7959 * commands pending on the vport associated with SCSI target specified
7960 * by tgt_id parameter.
7961 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
7962 * commands pending on the vport.
7963 * This function returns the number of iocbs which satisfy the filter.
7964 * This function is called without any lock held.
7967 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
7968 lpfc_ctx_cmd ctx_cmd
)
7970 struct lpfc_hba
*phba
= vport
->phba
;
7971 struct lpfc_iocbq
*iocbq
;
7974 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
7975 iocbq
= phba
->sli
.iocbq_lookup
[i
];
7977 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
7986 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
7987 * @phba: Pointer to HBA context object
7988 * @cmdiocb: Pointer to command iocb object.
7989 * @rspiocb: Pointer to response iocb object.
7991 * This function is called when an aborted FCP iocb completes. This
7992 * function is called by the ring event handler with no lock held.
7993 * This function frees the iocb.
7996 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7997 struct lpfc_iocbq
*rspiocb
)
7999 lpfc_sli_release_iocbq(phba
, cmdiocb
);
8004 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
8005 * @vport: Pointer to virtual port.
8006 * @pring: Pointer to driver SLI ring object.
8007 * @tgt_id: SCSI ID of the target.
8008 * @lun_id: LUN ID of the scsi device.
8009 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
8011 * This function sends an abort command for every SCSI command
8012 * associated with the given virtual port pending on the ring
8013 * filtered by lpfc_sli_validate_fcp_iocb function.
8014 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
8015 * FCP iocbs associated with lun specified by tgt_id and lun_id
8017 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
8018 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
8019 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
8020 * FCP iocbs associated with virtual port.
8021 * This function returns number of iocbs it failed to abort.
8022 * This function is called with no locks held.
8025 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
8026 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
8028 struct lpfc_hba
*phba
= vport
->phba
;
8029 struct lpfc_iocbq
*iocbq
;
8030 struct lpfc_iocbq
*abtsiocb
;
8032 int errcnt
= 0, ret_val
= 0;
8035 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
8036 iocbq
= phba
->sli
.iocbq_lookup
[i
];
8038 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
8042 /* issue ABTS for this IOCB based on iotag */
8043 abtsiocb
= lpfc_sli_get_iocbq(phba
);
8044 if (abtsiocb
== NULL
) {
8050 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
8051 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
8052 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8053 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
8055 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
8056 abtsiocb
->iocb
.ulpLe
= 1;
8057 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
8058 abtsiocb
->vport
= phba
->pport
;
8060 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
8061 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
8062 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8063 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
8065 if (lpfc_is_link_up(phba
))
8066 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
8068 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
8070 /* Setup callback routine and issue the command. */
8071 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
8072 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
8074 if (ret_val
== IOCB_ERROR
) {
8075 lpfc_sli_release_iocbq(phba
, abtsiocb
);
8085 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
8086 * @phba: Pointer to HBA context object.
8087 * @cmdiocbq: Pointer to command iocb.
8088 * @rspiocbq: Pointer to response iocb.
8090 * This function is the completion handler for iocbs issued using
8091 * lpfc_sli_issue_iocb_wait function. This function is called by the
8092 * ring event handler function without any lock held. This function
8093 * can be called from both worker thread context and interrupt
8094 * context. This function also can be called from other thread which
8095 * cleans up the SLI layer objects.
8096 * This function copy the contents of the response iocb to the
8097 * response iocb memory object provided by the caller of
8098 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
8099 * sleeps for the iocb completion.
8102 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
8103 struct lpfc_iocbq
*cmdiocbq
,
8104 struct lpfc_iocbq
*rspiocbq
)
8106 wait_queue_head_t
*pdone_q
;
8107 unsigned long iflags
;
8108 struct lpfc_scsi_buf
*lpfc_cmd
;
8110 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8111 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
8112 if (cmdiocbq
->context2
&& rspiocbq
)
8113 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
8114 &rspiocbq
->iocb
, sizeof(IOCB_t
));
8116 /* Set the exchange busy flag for task management commands */
8117 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
8118 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
8119 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
8121 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
8124 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
8127 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8132 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
8133 * @phba: Pointer to HBA context object..
8134 * @piocbq: Pointer to command iocb.
8135 * @flag: Flag to test.
8137 * This routine grabs the hbalock and then test the iocb_flag to
8138 * see if the passed in flag is set.
8141 * 0 if flag is not set.
8144 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
8145 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
8147 unsigned long iflags
;
8150 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8151 ret
= piocbq
->iocb_flag
& flag
;
8152 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8158 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
8159 * @phba: Pointer to HBA context object..
8160 * @pring: Pointer to sli ring.
8161 * @piocb: Pointer to command iocb.
8162 * @prspiocbq: Pointer to response iocb.
8163 * @timeout: Timeout in number of seconds.
8165 * This function issues the iocb to firmware and waits for the
8166 * iocb to complete. If the iocb command is not
8167 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
8168 * Caller should not free the iocb resources if this function
8169 * returns IOCB_TIMEDOUT.
8170 * The function waits for the iocb completion using an
8171 * non-interruptible wait.
8172 * This function will sleep while waiting for iocb completion.
8173 * So, this function should not be called from any context which
8174 * does not allow sleeping. Due to the same reason, this function
8175 * cannot be called with interrupt disabled.
8176 * This function assumes that the iocb completions occur while
8177 * this function sleep. So, this function cannot be called from
8178 * the thread which process iocb completion for this ring.
8179 * This function clears the iocb_flag of the iocb object before
8180 * issuing the iocb and the iocb completion handler sets this
8181 * flag and wakes this thread when the iocb completes.
8182 * The contents of the response iocb will be copied to prspiocbq
8183 * by the completion handler when the command completes.
8184 * This function returns IOCB_SUCCESS when success.
8185 * This function is called with no lock held.
8188 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
8189 uint32_t ring_number
,
8190 struct lpfc_iocbq
*piocb
,
8191 struct lpfc_iocbq
*prspiocbq
,
8194 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
8195 long timeleft
, timeout_req
= 0;
8196 int retval
= IOCB_SUCCESS
;
8198 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8200 * If the caller has provided a response iocbq buffer, then context2
8201 * is NULL or its an error.
8204 if (piocb
->context2
)
8206 piocb
->context2
= prspiocbq
;
8209 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
8210 piocb
->context_un
.wait_queue
= &done_q
;
8211 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
8213 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
8214 creg_val
= readl(phba
->HCregaddr
);
8215 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
8216 writel(creg_val
, phba
->HCregaddr
);
8217 readl(phba
->HCregaddr
); /* flush */
8220 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8222 if (retval
== IOCB_SUCCESS
) {
8223 timeout_req
= timeout
* HZ
;
8224 timeleft
= wait_event_timeout(done_q
,
8225 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
8228 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
8229 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8230 "0331 IOCB wake signaled\n");
8231 } else if (timeleft
== 0) {
8232 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8233 "0338 IOCB wait timeout error - no "
8234 "wake response Data x%x\n", timeout
);
8235 retval
= IOCB_TIMEDOUT
;
8237 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8238 "0330 IOCB wake NOT set, "
8240 timeout
, (timeleft
/ jiffies
));
8241 retval
= IOCB_TIMEDOUT
;
8243 } else if (retval
== IOCB_BUSY
) {
8244 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8245 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
8246 phba
->iocb_cnt
, pring
->txq_cnt
, pring
->txcmplq_cnt
);
8249 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8250 "0332 IOCB wait issue failed, Data x%x\n",
8252 retval
= IOCB_ERROR
;
8255 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
8256 creg_val
= readl(phba
->HCregaddr
);
8257 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
8258 writel(creg_val
, phba
->HCregaddr
);
8259 readl(phba
->HCregaddr
); /* flush */
8263 piocb
->context2
= NULL
;
8265 piocb
->context_un
.wait_queue
= NULL
;
8266 piocb
->iocb_cmpl
= NULL
;
8271 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
8272 * @phba: Pointer to HBA context object.
8273 * @pmboxq: Pointer to driver mailbox object.
8274 * @timeout: Timeout in number of seconds.
8276 * This function issues the mailbox to firmware and waits for the
8277 * mailbox command to complete. If the mailbox command is not
8278 * completed within timeout seconds, it returns MBX_TIMEOUT.
8279 * The function waits for the mailbox completion using an
8280 * interruptible wait. If the thread is woken up due to a
8281 * signal, MBX_TIMEOUT error is returned to the caller. Caller
8282 * should not free the mailbox resources, if this function returns
8284 * This function will sleep while waiting for mailbox completion.
8285 * So, this function should not be called from any context which
8286 * does not allow sleeping. Due to the same reason, this function
8287 * cannot be called with interrupt disabled.
8288 * This function assumes that the mailbox completion occurs while
8289 * this function sleep. So, this function cannot be called from
8290 * the worker thread which processes mailbox completion.
8291 * This function is called in the context of HBA management
8293 * This function returns MBX_SUCCESS when successful.
8294 * This function is called with no lock held.
8297 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
8300 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
8304 /* The caller must leave context1 empty. */
8305 if (pmboxq
->context1
)
8306 return MBX_NOT_FINISHED
;
8308 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
8309 /* setup wake call as IOCB callback */
8310 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
8311 /* setup context field to pass wait_queue pointer to wake function */
8312 pmboxq
->context1
= &done_q
;
8314 /* now issue the command */
8315 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
8317 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
8318 wait_event_interruptible_timeout(done_q
,
8319 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
8322 spin_lock_irqsave(&phba
->hbalock
, flag
);
8323 pmboxq
->context1
= NULL
;
8325 * if LPFC_MBX_WAKE flag is set the mailbox is completed
8326 * else do not free the resources.
8328 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
8329 retval
= MBX_SUCCESS
;
8330 lpfc_sli4_swap_str(phba
, pmboxq
);
8332 retval
= MBX_TIMEOUT
;
8333 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
8335 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
8342 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
8343 * @phba: Pointer to HBA context.
8345 * This function is called to shutdown the driver's mailbox sub-system.
8346 * It first marks the mailbox sub-system is in a block state to prevent
8347 * the asynchronous mailbox command from issued off the pending mailbox
8348 * command queue. If the mailbox command sub-system shutdown is due to
8349 * HBA error conditions such as EEH or ERATT, this routine shall invoke
8350 * the mailbox sub-system flush routine to forcefully bring down the
8351 * mailbox sub-system. Otherwise, if it is due to normal condition (such
8352 * as with offline or HBA function reset), this routine will wait for the
8353 * outstanding mailbox command to complete before invoking the mailbox
8354 * sub-system flush routine to gracefully bring down mailbox sub-system.
8357 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
8359 struct lpfc_sli
*psli
= &phba
->sli
;
8360 uint8_t actcmd
= MBX_HEARTBEAT
;
8361 unsigned long timeout
;
8363 spin_lock_irq(&phba
->hbalock
);
8364 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
8365 spin_unlock_irq(&phba
->hbalock
);
8367 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
8368 spin_lock_irq(&phba
->hbalock
);
8369 if (phba
->sli
.mbox_active
)
8370 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
8371 spin_unlock_irq(&phba
->hbalock
);
8372 /* Determine how long we might wait for the active mailbox
8373 * command to be gracefully completed by firmware.
8375 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) *
8377 while (phba
->sli
.mbox_active
) {
8378 /* Check active mailbox complete status every 2ms */
8380 if (time_after(jiffies
, timeout
))
8381 /* Timeout, let the mailbox flush routine to
8382 * forcefully release active mailbox command
8387 lpfc_sli_mbox_sys_flush(phba
);
8391 * lpfc_sli_eratt_read - read sli-3 error attention events
8392 * @phba: Pointer to HBA context.
8394 * This function is called to read the SLI3 device error attention registers
8395 * for possible error attention events. The caller must hold the hostlock
8396 * with spin_lock_irq().
8398 * This fucntion returns 1 when there is Error Attention in the Host Attention
8399 * Register and returns 0 otherwise.
8402 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
8406 /* Read chip Host Attention (HA) register */
8407 ha_copy
= readl(phba
->HAregaddr
);
8408 if (ha_copy
& HA_ERATT
) {
8409 /* Read host status register to retrieve error event */
8410 lpfc_sli_read_hs(phba
);
8412 /* Check if there is a deferred error condition is active */
8413 if ((HS_FFER1
& phba
->work_hs
) &&
8414 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
8415 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
8416 phba
->hba_flag
|= DEFER_ERATT
;
8417 /* Clear all interrupt enable conditions */
8418 writel(0, phba
->HCregaddr
);
8419 readl(phba
->HCregaddr
);
8422 /* Set the driver HA work bitmap */
8423 phba
->work_ha
|= HA_ERATT
;
8424 /* Indicate polling handles this ERATT */
8425 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8432 * lpfc_sli4_eratt_read - read sli-4 error attention events
8433 * @phba: Pointer to HBA context.
8435 * This function is called to read the SLI4 device error attention registers
8436 * for possible error attention events. The caller must hold the hostlock
8437 * with spin_lock_irq().
8439 * This fucntion returns 1 when there is Error Attention in the Host Attention
8440 * Register and returns 0 otherwise.
8443 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
8445 uint32_t uerr_sta_hi
, uerr_sta_lo
;
8446 uint32_t if_type
, portsmphr
;
8447 struct lpfc_register portstat_reg
;
8450 * For now, use the SLI4 device internal unrecoverable error
8451 * registers for error attention. This can be changed later.
8453 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
8455 case LPFC_SLI_INTF_IF_TYPE_0
:
8456 uerr_sta_lo
= readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
8457 uerr_sta_hi
= readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
8458 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
8459 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
8460 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8461 "1423 HBA Unrecoverable error: "
8462 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
8463 "ue_mask_lo_reg=0x%x, "
8464 "ue_mask_hi_reg=0x%x\n",
8465 uerr_sta_lo
, uerr_sta_hi
,
8466 phba
->sli4_hba
.ue_mask_lo
,
8467 phba
->sli4_hba
.ue_mask_hi
);
8468 phba
->work_status
[0] = uerr_sta_lo
;
8469 phba
->work_status
[1] = uerr_sta_hi
;
8470 phba
->work_ha
|= HA_ERATT
;
8471 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8475 case LPFC_SLI_INTF_IF_TYPE_2
:
8476 portstat_reg
.word0
=
8477 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
);
8478 portsmphr
= readl(phba
->sli4_hba
.PSMPHRregaddr
);
8479 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
8480 phba
->work_status
[0] =
8481 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
8482 phba
->work_status
[1] =
8483 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
8484 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8485 "2885 Port Error Detected: "
8486 "port status reg 0x%x, "
8487 "port smphr reg 0x%x, "
8488 "error 1=0x%x, error 2=0x%x\n",
8491 phba
->work_status
[0],
8492 phba
->work_status
[1]);
8493 phba
->work_ha
|= HA_ERATT
;
8494 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8498 case LPFC_SLI_INTF_IF_TYPE_1
:
8500 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8501 "2886 HBA Error Attention on unsupported "
8502 "if type %d.", if_type
);
8510 * lpfc_sli_check_eratt - check error attention events
8511 * @phba: Pointer to HBA context.
8513 * This function is called from timer soft interrupt context to check HBA's
8514 * error attention register bit for error attention events.
8516 * This fucntion returns 1 when there is Error Attention in the Host Attention
8517 * Register and returns 0 otherwise.
8520 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
8524 /* If somebody is waiting to handle an eratt, don't process it
8525 * here. The brdkill function will do this.
8527 if (phba
->link_flag
& LS_IGNORE_ERATT
)
8530 /* Check if interrupt handler handles this ERATT */
8531 spin_lock_irq(&phba
->hbalock
);
8532 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
8533 /* Interrupt handler has handled ERATT */
8534 spin_unlock_irq(&phba
->hbalock
);
8539 * If there is deferred error attention, do not check for error
8542 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8543 spin_unlock_irq(&phba
->hbalock
);
8547 /* If PCI channel is offline, don't process it */
8548 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
8549 spin_unlock_irq(&phba
->hbalock
);
8553 switch (phba
->sli_rev
) {
8556 /* Read chip Host Attention (HA) register */
8557 ha_copy
= lpfc_sli_eratt_read(phba
);
8560 /* Read device Uncoverable Error (UERR) registers */
8561 ha_copy
= lpfc_sli4_eratt_read(phba
);
8564 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8565 "0299 Invalid SLI revision (%d)\n",
8570 spin_unlock_irq(&phba
->hbalock
);
8576 * lpfc_intr_state_check - Check device state for interrupt handling
8577 * @phba: Pointer to HBA context.
8579 * This inline routine checks whether a device or its PCI slot is in a state
8580 * that the interrupt should be handled.
8582 * This function returns 0 if the device or the PCI slot is in a state that
8583 * interrupt should be handled, otherwise -EIO.
8586 lpfc_intr_state_check(struct lpfc_hba
*phba
)
8588 /* If the pci channel is offline, ignore all the interrupts */
8589 if (unlikely(pci_channel_offline(phba
->pcidev
)))
8592 /* Update device level interrupt statistics */
8593 phba
->sli
.slistat
.sli_intr
++;
8595 /* Ignore all interrupts during initialization. */
8596 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
8603 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
8604 * @irq: Interrupt number.
8605 * @dev_id: The device context pointer.
8607 * This function is directly called from the PCI layer as an interrupt
8608 * service routine when device with SLI-3 interface spec is enabled with
8609 * MSI-X multi-message interrupt mode and there are slow-path events in
8610 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
8611 * interrupt mode, this function is called as part of the device-level
8612 * interrupt handler. When the PCI slot is in error recovery or the HBA
8613 * is undergoing initialization, the interrupt handler will not process
8614 * the interrupt. The link attention and ELS ring attention events are
8615 * handled by the worker thread. The interrupt handler signals the worker
8616 * thread and returns for these events. This function is called without
8617 * any lock held. It gets the hbalock to access and update SLI data
8620 * This function returns IRQ_HANDLED when interrupt is handled else it
8624 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
8626 struct lpfc_hba
*phba
;
8627 uint32_t ha_copy
, hc_copy
;
8628 uint32_t work_ha_copy
;
8629 unsigned long status
;
8630 unsigned long iflag
;
8633 MAILBOX_t
*mbox
, *pmbox
;
8634 struct lpfc_vport
*vport
;
8635 struct lpfc_nodelist
*ndlp
;
8636 struct lpfc_dmabuf
*mp
;
8641 * Get the driver's phba structure from the dev_id and
8642 * assume the HBA is not interrupting.
8644 phba
= (struct lpfc_hba
*)dev_id
;
8646 if (unlikely(!phba
))
8650 * Stuff needs to be attented to when this function is invoked as an
8651 * individual interrupt handler in MSI-X multi-message interrupt mode
8653 if (phba
->intr_type
== MSIX
) {
8654 /* Check device state for handling interrupt */
8655 if (lpfc_intr_state_check(phba
))
8657 /* Need to read HA REG for slow-path events */
8658 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8659 ha_copy
= readl(phba
->HAregaddr
);
8660 /* If somebody is waiting to handle an eratt don't process it
8661 * here. The brdkill function will do this.
8663 if (phba
->link_flag
& LS_IGNORE_ERATT
)
8664 ha_copy
&= ~HA_ERATT
;
8665 /* Check the need for handling ERATT in interrupt handler */
8666 if (ha_copy
& HA_ERATT
) {
8667 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
8668 /* ERATT polling has handled ERATT */
8669 ha_copy
&= ~HA_ERATT
;
8671 /* Indicate interrupt handler handles ERATT */
8672 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
8676 * If there is deferred error attention, do not check for any
8679 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8680 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8684 /* Clear up only attention source related to slow-path */
8685 hc_copy
= readl(phba
->HCregaddr
);
8686 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
8687 HC_LAINT_ENA
| HC_ERINT_ENA
),
8689 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
8691 writel(hc_copy
, phba
->HCregaddr
);
8692 readl(phba
->HAregaddr
); /* flush */
8693 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8695 ha_copy
= phba
->ha_copy
;
8697 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
8700 if (work_ha_copy
& HA_LATT
) {
8701 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
8703 * Turn off Link Attention interrupts
8704 * until CLEAR_LA done
8706 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8707 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
8708 control
= readl(phba
->HCregaddr
);
8709 control
&= ~HC_LAINT_ENA
;
8710 writel(control
, phba
->HCregaddr
);
8711 readl(phba
->HCregaddr
); /* flush */
8712 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8715 work_ha_copy
&= ~HA_LATT
;
8718 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
8720 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
8721 * the only slow ring.
8723 status
= (work_ha_copy
&
8724 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
8725 status
>>= (4*LPFC_ELS_RING
);
8726 if (status
& HA_RXMASK
) {
8727 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8728 control
= readl(phba
->HCregaddr
);
8730 lpfc_debugfs_slow_ring_trc(phba
,
8731 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
8733 (uint32_t)phba
->sli
.slistat
.sli_intr
);
8735 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
8736 lpfc_debugfs_slow_ring_trc(phba
,
8738 "pwork:x%x hawork:x%x wait:x%x",
8739 phba
->work_ha
, work_ha_copy
,
8740 (uint32_t)((unsigned long)
8741 &phba
->work_waitq
));
8744 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
8745 writel(control
, phba
->HCregaddr
);
8746 readl(phba
->HCregaddr
); /* flush */
8749 lpfc_debugfs_slow_ring_trc(phba
,
8750 "ISR slow ring: pwork:"
8751 "x%x hawork:x%x wait:x%x",
8752 phba
->work_ha
, work_ha_copy
,
8753 (uint32_t)((unsigned long)
8754 &phba
->work_waitq
));
8756 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8759 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8760 if (work_ha_copy
& HA_ERATT
) {
8761 lpfc_sli_read_hs(phba
);
8763 * Check if there is a deferred error condition
8766 if ((HS_FFER1
& phba
->work_hs
) &&
8767 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
8768 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
8770 phba
->hba_flag
|= DEFER_ERATT
;
8771 /* Clear all interrupt enable conditions */
8772 writel(0, phba
->HCregaddr
);
8773 readl(phba
->HCregaddr
);
8777 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
8778 pmb
= phba
->sli
.mbox_active
;
8783 /* First check out the status word */
8784 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
8785 if (pmbox
->mbxOwner
!= OWN_HOST
) {
8786 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8788 * Stray Mailbox Interrupt, mbxCommand <cmd>
8789 * mbxStatus <status>
8791 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8793 "(%d):0304 Stray Mailbox "
8794 "Interrupt mbxCommand x%x "
8796 (vport
? vport
->vpi
: 0),
8799 /* clear mailbox attention bit */
8800 work_ha_copy
&= ~HA_MBATT
;
8802 phba
->sli
.mbox_active
= NULL
;
8803 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8804 phba
->last_completion_time
= jiffies
;
8805 del_timer(&phba
->sli
.mbox_tmo
);
8806 if (pmb
->mbox_cmpl
) {
8807 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
8809 if (pmb
->out_ext_byte_len
&&
8811 lpfc_sli_pcimem_bcopy(
8814 pmb
->out_ext_byte_len
);
8816 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
8817 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
8819 lpfc_debugfs_disc_trc(vport
,
8820 LPFC_DISC_TRC_MBOX_VPORT
,
8822 "status:x%x rpi:x%x",
8823 (uint32_t)pmbox
->mbxStatus
,
8824 pmbox
->un
.varWords
[0], 0);
8826 if (!pmbox
->mbxStatus
) {
8827 mp
= (struct lpfc_dmabuf
*)
8829 ndlp
= (struct lpfc_nodelist
*)
8832 /* Reg_LOGIN of dflt RPI was
8833 * successful. new lets get
8834 * rid of the RPI using the
8837 lpfc_unreg_login(phba
,
8839 pmbox
->un
.varWords
[0],
8842 lpfc_mbx_cmpl_dflt_rpi
;
8844 pmb
->context2
= ndlp
;
8846 rc
= lpfc_sli_issue_mbox(phba
,
8850 lpfc_printf_log(phba
,
8853 "0350 rc should have"
8855 if (rc
!= MBX_NOT_FINISHED
)
8856 goto send_current_mbox
;
8860 &phba
->pport
->work_port_lock
,
8862 phba
->pport
->work_port_events
&=
8864 spin_unlock_irqrestore(
8865 &phba
->pport
->work_port_lock
,
8867 lpfc_mbox_cmpl_put(phba
, pmb
);
8870 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8872 if ((work_ha_copy
& HA_MBATT
) &&
8873 (phba
->sli
.mbox_active
== NULL
)) {
8875 /* Process next mailbox command if there is one */
8877 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
8879 } while (rc
== MBX_NOT_FINISHED
);
8880 if (rc
!= MBX_SUCCESS
)
8881 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
8882 LOG_SLI
, "0349 rc should be "
8886 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8887 phba
->work_ha
|= work_ha_copy
;
8888 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8889 lpfc_worker_wake_up(phba
);
8893 } /* lpfc_sli_sp_intr_handler */
8896 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
8897 * @irq: Interrupt number.
8898 * @dev_id: The device context pointer.
8900 * This function is directly called from the PCI layer as an interrupt
8901 * service routine when device with SLI-3 interface spec is enabled with
8902 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
8903 * ring event in the HBA. However, when the device is enabled with either
8904 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
8905 * device-level interrupt handler. When the PCI slot is in error recovery
8906 * or the HBA is undergoing initialization, the interrupt handler will not
8907 * process the interrupt. The SCSI FCP fast-path ring event are handled in
8908 * the intrrupt context. This function is called without any lock held.
8909 * It gets the hbalock to access and update SLI data structures.
8911 * This function returns IRQ_HANDLED when interrupt is handled else it
8915 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
8917 struct lpfc_hba
*phba
;
8919 unsigned long status
;
8920 unsigned long iflag
;
8922 /* Get the driver's phba structure from the dev_id and
8923 * assume the HBA is not interrupting.
8925 phba
= (struct lpfc_hba
*) dev_id
;
8927 if (unlikely(!phba
))
8931 * Stuff needs to be attented to when this function is invoked as an
8932 * individual interrupt handler in MSI-X multi-message interrupt mode
8934 if (phba
->intr_type
== MSIX
) {
8935 /* Check device state for handling interrupt */
8936 if (lpfc_intr_state_check(phba
))
8938 /* Need to read HA REG for FCP ring and other ring events */
8939 ha_copy
= readl(phba
->HAregaddr
);
8940 /* Clear up only attention source related to fast-path */
8941 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8943 * If there is deferred error attention, do not check for
8946 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
8947 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8950 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
8952 readl(phba
->HAregaddr
); /* flush */
8953 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8955 ha_copy
= phba
->ha_copy
;
8958 * Process all events on FCP ring. Take the optimized path for FCP IO.
8960 ha_copy
&= ~(phba
->work_ha_mask
);
8962 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
8963 status
>>= (4*LPFC_FCP_RING
);
8964 if (status
& HA_RXMASK
)
8965 lpfc_sli_handle_fast_ring_event(phba
,
8966 &phba
->sli
.ring
[LPFC_FCP_RING
],
8969 if (phba
->cfg_multi_ring_support
== 2) {
8971 * Process all events on extra ring. Take the optimized path
8972 * for extra ring IO.
8974 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
8975 status
>>= (4*LPFC_EXTRA_RING
);
8976 if (status
& HA_RXMASK
) {
8977 lpfc_sli_handle_fast_ring_event(phba
,
8978 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
8983 } /* lpfc_sli_fp_intr_handler */
8986 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
8987 * @irq: Interrupt number.
8988 * @dev_id: The device context pointer.
8990 * This function is the HBA device-level interrupt handler to device with
8991 * SLI-3 interface spec, called from the PCI layer when either MSI or
8992 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
8993 * requires driver attention. This function invokes the slow-path interrupt
8994 * attention handling function and fast-path interrupt attention handling
8995 * function in turn to process the relevant HBA attention events. This
8996 * function is called without any lock held. It gets the hbalock to access
8997 * and update SLI data structures.
8999 * This function returns IRQ_HANDLED when interrupt is handled, else it
9003 lpfc_sli_intr_handler(int irq
, void *dev_id
)
9005 struct lpfc_hba
*phba
;
9006 irqreturn_t sp_irq_rc
, fp_irq_rc
;
9007 unsigned long status1
, status2
;
9011 * Get the driver's phba structure from the dev_id and
9012 * assume the HBA is not interrupting.
9014 phba
= (struct lpfc_hba
*) dev_id
;
9016 if (unlikely(!phba
))
9019 /* Check device state for handling interrupt */
9020 if (lpfc_intr_state_check(phba
))
9023 spin_lock(&phba
->hbalock
);
9024 phba
->ha_copy
= readl(phba
->HAregaddr
);
9025 if (unlikely(!phba
->ha_copy
)) {
9026 spin_unlock(&phba
->hbalock
);
9028 } else if (phba
->ha_copy
& HA_ERATT
) {
9029 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
9030 /* ERATT polling has handled ERATT */
9031 phba
->ha_copy
&= ~HA_ERATT
;
9033 /* Indicate interrupt handler handles ERATT */
9034 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9038 * If there is deferred error attention, do not check for any interrupt.
9040 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
9041 spin_unlock(&phba
->hbalock
);
9045 /* Clear attention sources except link and error attentions */
9046 hc_copy
= readl(phba
->HCregaddr
);
9047 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
9048 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
9050 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
9051 writel(hc_copy
, phba
->HCregaddr
);
9052 readl(phba
->HAregaddr
); /* flush */
9053 spin_unlock(&phba
->hbalock
);
9056 * Invokes slow-path host attention interrupt handling as appropriate.
9059 /* status of events with mailbox and link attention */
9060 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
9062 /* status of events with ELS ring */
9063 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
9064 status2
>>= (4*LPFC_ELS_RING
);
9066 if (status1
|| (status2
& HA_RXMASK
))
9067 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
9069 sp_irq_rc
= IRQ_NONE
;
9072 * Invoke fast-path host attention interrupt handling as appropriate.
9075 /* status of events with FCP ring */
9076 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
9077 status1
>>= (4*LPFC_FCP_RING
);
9079 /* status of events with extra ring */
9080 if (phba
->cfg_multi_ring_support
== 2) {
9081 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
9082 status2
>>= (4*LPFC_EXTRA_RING
);
9086 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
9087 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
9089 fp_irq_rc
= IRQ_NONE
;
9091 /* Return device-level interrupt handling status */
9092 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
9093 } /* lpfc_sli_intr_handler */
9096 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
9097 * @phba: pointer to lpfc hba data structure.
9099 * This routine is invoked by the worker thread to process all the pending
9100 * SLI4 FCP abort XRI events.
9102 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
9104 struct lpfc_cq_event
*cq_event
;
9106 /* First, declare the fcp xri abort event has been handled */
9107 spin_lock_irq(&phba
->hbalock
);
9108 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
9109 spin_unlock_irq(&phba
->hbalock
);
9110 /* Now, handle all the fcp xri abort events */
9111 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
9112 /* Get the first event from the head of the event queue */
9113 spin_lock_irq(&phba
->hbalock
);
9114 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
9115 cq_event
, struct lpfc_cq_event
, list
);
9116 spin_unlock_irq(&phba
->hbalock
);
9117 /* Notify aborted XRI for FCP work queue */
9118 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
9119 /* Free the event processed back to the free pool */
9120 lpfc_sli4_cq_event_release(phba
, cq_event
);
9125 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
9126 * @phba: pointer to lpfc hba data structure.
9128 * This routine is invoked by the worker thread to process all the pending
9129 * SLI4 els abort xri events.
9131 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
9133 struct lpfc_cq_event
*cq_event
;
9135 /* First, declare the els xri abort event has been handled */
9136 spin_lock_irq(&phba
->hbalock
);
9137 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
9138 spin_unlock_irq(&phba
->hbalock
);
9139 /* Now, handle all the els xri abort events */
9140 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
9141 /* Get the first event from the head of the event queue */
9142 spin_lock_irq(&phba
->hbalock
);
9143 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
9144 cq_event
, struct lpfc_cq_event
, list
);
9145 spin_unlock_irq(&phba
->hbalock
);
9146 /* Notify aborted XRI for ELS work queue */
9147 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
9148 /* Free the event processed back to the free pool */
9149 lpfc_sli4_cq_event_release(phba
, cq_event
);
9154 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
9155 * @phba: pointer to lpfc hba data structure
9156 * @pIocbIn: pointer to the rspiocbq
9157 * @pIocbOut: pointer to the cmdiocbq
9158 * @wcqe: pointer to the complete wcqe
9160 * This routine transfers the fields of a command iocbq to a response iocbq
9161 * by copying all the IOCB fields from command iocbq and transferring the
9162 * completion status information from the complete wcqe.
9165 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
9166 struct lpfc_iocbq
*pIocbIn
,
9167 struct lpfc_iocbq
*pIocbOut
,
9168 struct lpfc_wcqe_complete
*wcqe
)
9170 unsigned long iflags
;
9171 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
9173 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
9174 sizeof(struct lpfc_iocbq
) - offset
);
9175 /* Map WCQE parameters into irspiocb parameters */
9176 pIocbIn
->iocb
.ulpStatus
= bf_get(lpfc_wcqe_c_status
, wcqe
);
9177 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
9178 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
9179 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
9180 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
9181 wcqe
->total_data_placed
;
9183 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
9185 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
9186 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
9189 /* Pick up HBA exchange busy condition */
9190 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
9191 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9192 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
9193 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9198 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
9199 * @phba: Pointer to HBA context object.
9200 * @wcqe: Pointer to work-queue completion queue entry.
9202 * This routine handles an ELS work-queue completion event and construct
9203 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
9204 * discovery engine to handle.
9206 * Return: Pointer to the receive IOCBQ, NULL otherwise.
9208 static struct lpfc_iocbq
*
9209 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
9210 struct lpfc_iocbq
*irspiocbq
)
9212 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9213 struct lpfc_iocbq
*cmdiocbq
;
9214 struct lpfc_wcqe_complete
*wcqe
;
9215 unsigned long iflags
;
9217 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
9218 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9219 pring
->stats
.iocb_event
++;
9220 /* Look up the ELS command IOCB and create pseudo response IOCB */
9221 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
9222 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9223 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9225 if (unlikely(!cmdiocbq
)) {
9226 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9227 "0386 ELS complete with no corresponding "
9228 "cmdiocb: iotag (%d)\n",
9229 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9230 lpfc_sli_release_iocbq(phba
, irspiocbq
);
9234 /* Fake the irspiocbq and copy necessary response information */
9235 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
9241 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
9242 * @phba: Pointer to HBA context object.
9243 * @cqe: Pointer to mailbox completion queue entry.
9245 * This routine process a mailbox completion queue entry with asynchrous
9248 * Return: true if work posted to worker thread, otherwise false.
9251 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
9253 struct lpfc_cq_event
*cq_event
;
9254 unsigned long iflags
;
9256 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9257 "0392 Async Event: word0:x%x, word1:x%x, "
9258 "word2:x%x, word3:x%x\n", mcqe
->word0
,
9259 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
9261 /* Allocate a new internal CQ_EVENT entry */
9262 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
9264 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9265 "0394 Failed to allocate CQ_EVENT entry\n");
9269 /* Move the CQE into an asynchronous event entry */
9270 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
9271 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9272 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
9273 /* Set the async event flag */
9274 phba
->hba_flag
|= ASYNC_EVENT
;
9275 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9281 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
9282 * @phba: Pointer to HBA context object.
9283 * @cqe: Pointer to mailbox completion queue entry.
9285 * This routine process a mailbox completion queue entry with mailbox
9288 * Return: true if work posted to worker thread, otherwise false.
9291 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
9293 uint32_t mcqe_status
;
9294 MAILBOX_t
*mbox
, *pmbox
;
9295 struct lpfc_mqe
*mqe
;
9296 struct lpfc_vport
*vport
;
9297 struct lpfc_nodelist
*ndlp
;
9298 struct lpfc_dmabuf
*mp
;
9299 unsigned long iflags
;
9301 bool workposted
= false;
9304 /* If not a mailbox complete MCQE, out by checking mailbox consume */
9305 if (!bf_get(lpfc_trailer_completed
, mcqe
))
9306 goto out_no_mqe_complete
;
9308 /* Get the reference to the active mbox command */
9309 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9310 pmb
= phba
->sli
.mbox_active
;
9311 if (unlikely(!pmb
)) {
9312 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
9313 "1832 No pending MBOX command to handle\n");
9314 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9315 goto out_no_mqe_complete
;
9317 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9319 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
9323 /* Reset heartbeat timer */
9324 phba
->last_completion_time
= jiffies
;
9325 del_timer(&phba
->sli
.mbox_tmo
);
9327 /* Move mbox data to caller's mailbox region, do endian swapping */
9328 if (pmb
->mbox_cmpl
&& mbox
)
9329 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
9330 /* Set the mailbox status with SLI4 range 0x4000 */
9331 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
9332 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
)
9333 bf_set(lpfc_mqe_status
, mqe
,
9334 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
9336 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
9337 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
9338 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
9339 "MBOX dflt rpi: status:x%x rpi:x%x",
9341 pmbox
->un
.varWords
[0], 0);
9342 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
9343 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
9344 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
9345 /* Reg_LOGIN of dflt RPI was successful. Now lets get
9346 * RID of the PPI using the same mbox buffer.
9348 lpfc_unreg_login(phba
, vport
->vpi
,
9349 pmbox
->un
.varWords
[0], pmb
);
9350 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
9352 pmb
->context2
= ndlp
;
9354 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
9356 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
9357 LOG_SLI
, "0385 rc should "
9358 "have been MBX_BUSY\n");
9359 if (rc
!= MBX_NOT_FINISHED
)
9360 goto send_current_mbox
;
9363 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
9364 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9365 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
9367 /* There is mailbox completion work to do */
9368 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9369 __lpfc_mbox_cmpl_put(phba
, pmb
);
9370 phba
->work_ha
|= HA_MBATT
;
9371 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9375 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9376 /* Release the mailbox command posting token */
9377 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9378 /* Setting active mailbox pointer need to be in sync to flag clear */
9379 phba
->sli
.mbox_active
= NULL
;
9380 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9381 /* Wake up worker thread to post the next pending mailbox command */
9382 lpfc_worker_wake_up(phba
);
9383 out_no_mqe_complete
:
9384 if (bf_get(lpfc_trailer_consumed
, mcqe
))
9385 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
9390 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
9391 * @phba: Pointer to HBA context object.
9392 * @cqe: Pointer to mailbox completion queue entry.
9394 * This routine process a mailbox completion queue entry, it invokes the
9395 * proper mailbox complete handling or asynchrous event handling routine
9396 * according to the MCQE's async bit.
9398 * Return: true if work posted to worker thread, otherwise false.
9401 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
9403 struct lpfc_mcqe mcqe
;
9406 /* Copy the mailbox MCQE and convert endian order as needed */
9407 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
9409 /* Invoke the proper event handling routine */
9410 if (!bf_get(lpfc_trailer_async
, &mcqe
))
9411 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
9413 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
9418 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
9419 * @phba: Pointer to HBA context object.
9420 * @wcqe: Pointer to work-queue completion queue entry.
9422 * This routine handles an ELS work-queue completion event.
9424 * Return: true if work posted to worker thread, otherwise false.
9427 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
9428 struct lpfc_wcqe_complete
*wcqe
)
9430 struct lpfc_iocbq
*irspiocbq
;
9431 unsigned long iflags
;
9432 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
9434 /* Get an irspiocbq for later ELS response processing use */
9435 irspiocbq
= lpfc_sli_get_iocbq(phba
);
9437 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9438 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
9439 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
9440 pring
->txq_cnt
, phba
->iocb_cnt
,
9441 phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
,
9442 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
);
9446 /* Save off the slow-path queue event for work thread to process */
9447 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
9448 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9449 list_add_tail(&irspiocbq
->cq_event
.list
,
9450 &phba
->sli4_hba
.sp_queue_event
);
9451 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
9452 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9458 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
9459 * @phba: Pointer to HBA context object.
9460 * @wcqe: Pointer to work-queue completion queue entry.
9462 * This routine handles slow-path WQ entry comsumed event by invoking the
9463 * proper WQ release routine to the slow-path WQ.
9466 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
9467 struct lpfc_wcqe_release
*wcqe
)
9469 /* Check for the slow-path ELS work queue */
9470 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
9471 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
9472 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
9474 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9475 "2579 Slow-path wqe consume event carries "
9476 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
9477 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
9478 phba
->sli4_hba
.els_wq
->queue_id
);
9482 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
9483 * @phba: Pointer to HBA context object.
9484 * @cq: Pointer to a WQ completion queue.
9485 * @wcqe: Pointer to work-queue completion queue entry.
9487 * This routine handles an XRI abort event.
9489 * Return: true if work posted to worker thread, otherwise false.
9492 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
9493 struct lpfc_queue
*cq
,
9494 struct sli4_wcqe_xri_aborted
*wcqe
)
9496 bool workposted
= false;
9497 struct lpfc_cq_event
*cq_event
;
9498 unsigned long iflags
;
9500 /* Allocate a new internal CQ_EVENT entry */
9501 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
9503 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9504 "0602 Failed to allocate CQ_EVENT entry\n");
9508 /* Move the CQE into the proper xri abort event list */
9509 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
9510 switch (cq
->subtype
) {
9512 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9513 list_add_tail(&cq_event
->list
,
9514 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
9515 /* Set the fcp xri abort event flag */
9516 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
9517 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9521 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9522 list_add_tail(&cq_event
->list
,
9523 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
9524 /* Set the els xri abort event flag */
9525 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
9526 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9530 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9531 "0603 Invalid work queue CQE subtype (x%x)\n",
9540 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
9541 * @phba: Pointer to HBA context object.
9542 * @rcqe: Pointer to receive-queue completion queue entry.
9544 * This routine process a receive-queue completion queue entry.
9546 * Return: true if work posted to worker thread, otherwise false.
9549 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
9551 bool workposted
= false;
9552 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
9553 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
9554 struct hbq_dmabuf
*dma_buf
;
9556 unsigned long iflags
;
9558 if (bf_get(lpfc_rcqe_rq_id
, rcqe
) != hrq
->queue_id
)
9561 status
= bf_get(lpfc_rcqe_status
, rcqe
);
9563 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
9564 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9565 "2537 Receive Frame Truncated!!\n");
9566 case FC_STATUS_RQ_SUCCESS
:
9567 lpfc_sli4_rq_release(hrq
, drq
);
9568 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9569 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
9571 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9574 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
9575 /* save off the frame for the word thread to process */
9576 list_add_tail(&dma_buf
->cq_event
.list
,
9577 &phba
->sli4_hba
.sp_queue_event
);
9578 /* Frame received */
9579 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
9580 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9583 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
9584 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
9585 /* Post more buffers if possible */
9586 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9587 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
9588 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9597 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
9598 * @phba: Pointer to HBA context object.
9599 * @cq: Pointer to the completion queue.
9600 * @wcqe: Pointer to a completion queue entry.
9602 * This routine process a slow-path work-queue or recieve queue completion queue
9605 * Return: true if work posted to worker thread, otherwise false.
9608 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9609 struct lpfc_cqe
*cqe
)
9611 struct lpfc_cqe cqevt
;
9612 bool workposted
= false;
9614 /* Copy the work queue CQE and convert endian order if needed */
9615 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
9617 /* Check and process for different type of WCQE and dispatch */
9618 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
9619 case CQE_CODE_COMPL_WQE
:
9620 /* Process the WQ/RQ complete event */
9621 phba
->last_completion_time
= jiffies
;
9622 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
9623 (struct lpfc_wcqe_complete
*)&cqevt
);
9625 case CQE_CODE_RELEASE_WQE
:
9626 /* Process the WQ release event */
9627 lpfc_sli4_sp_handle_rel_wcqe(phba
,
9628 (struct lpfc_wcqe_release
*)&cqevt
);
9630 case CQE_CODE_XRI_ABORTED
:
9631 /* Process the WQ XRI abort event */
9632 phba
->last_completion_time
= jiffies
;
9633 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
9634 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
9636 case CQE_CODE_RECEIVE
:
9637 /* Process the RQ event */
9638 phba
->last_completion_time
= jiffies
;
9639 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
9640 (struct lpfc_rcqe
*)&cqevt
);
9643 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9644 "0388 Not a valid WCQE code: x%x\n",
9645 bf_get(lpfc_cqe_code
, &cqevt
));
9652 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
9653 * @phba: Pointer to HBA context object.
9654 * @eqe: Pointer to fast-path event queue entry.
9656 * This routine process a event queue entry from the slow-path event queue.
9657 * It will check the MajorCode and MinorCode to determine this is for a
9658 * completion event on a completion queue, if not, an error shall be logged
9659 * and just return. Otherwise, it will get to the corresponding completion
9660 * queue and process all the entries on that completion queue, rearm the
9661 * completion queue, and then return.
9665 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
9667 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
9668 struct lpfc_cqe
*cqe
;
9669 bool workposted
= false;
9673 if (bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0) {
9674 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9675 "0359 Not a valid slow-path completion "
9676 "event: majorcode=x%x, minorcode=x%x\n",
9677 bf_get_le32(lpfc_eqe_major_code
, eqe
),
9678 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
9682 /* Get the reference to the corresponding CQ */
9683 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
9685 /* Search for completion queue pointer matching this cqid */
9686 speq
= phba
->sli4_hba
.sp_eq
;
9687 list_for_each_entry(childq
, &speq
->child_list
, list
) {
9688 if (childq
->queue_id
== cqid
) {
9693 if (unlikely(!cq
)) {
9694 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
9695 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9696 "0365 Slow-path CQ identifier "
9697 "(%d) does not exist\n", cqid
);
9701 /* Process all the entries to the CQ */
9704 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9705 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
9706 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9707 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9711 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9712 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
, cqe
);
9713 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9714 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9718 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9719 "0370 Invalid completion queue type (%d)\n",
9724 /* Catch the no cq entry condition, log an error */
9725 if (unlikely(ecount
== 0))
9726 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9727 "0371 No entry from the CQ: identifier "
9728 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
9730 /* In any case, flash and re-arm the RCQ */
9731 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9733 /* wake up worker thread if there are works to be done */
9735 lpfc_worker_wake_up(phba
);
9739 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
9740 * @eqe: Pointer to fast-path completion queue entry.
9742 * This routine process a fast-path work queue completion entry from fast-path
9743 * event queue for FCP command response completion.
9746 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
9747 struct lpfc_wcqe_complete
*wcqe
)
9749 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
9750 struct lpfc_iocbq
*cmdiocbq
;
9751 struct lpfc_iocbq irspiocbq
;
9752 unsigned long iflags
;
9754 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9755 pring
->stats
.iocb_event
++;
9756 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9758 /* Check for response status */
9759 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
9760 /* If resource errors reported from HBA, reduce queue
9761 * depth of the SCSI device.
9763 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
9764 IOSTAT_LOCAL_REJECT
) &&
9765 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
9766 phba
->lpfc_rampdown_queue_depth(phba
);
9768 /* Log the error status */
9769 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9770 "0373 FCP complete error: status=x%x, "
9771 "hw_status=x%x, total_data_specified=%d, "
9772 "parameter=x%x, word3=x%x\n",
9773 bf_get(lpfc_wcqe_c_status
, wcqe
),
9774 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
9775 wcqe
->total_data_placed
, wcqe
->parameter
,
9779 /* Look up the FCP command IOCB and create pseudo response IOCB */
9780 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9781 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
9782 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9783 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9784 if (unlikely(!cmdiocbq
)) {
9785 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9786 "0374 FCP complete with no corresponding "
9787 "cmdiocb: iotag (%d)\n",
9788 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9791 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
9792 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9793 "0375 FCP cmdiocb not callback function "
9795 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
9799 /* Fake the irspiocb and copy necessary response information */
9800 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
9802 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
9803 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9804 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
9805 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9808 /* Pass the cmd_iocb and the rsp state to the upper layer */
9809 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
9813 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
9814 * @phba: Pointer to HBA context object.
9815 * @cq: Pointer to completion queue.
9816 * @wcqe: Pointer to work-queue completion queue entry.
9818 * This routine handles an fast-path WQ entry comsumed event by invoking the
9819 * proper WQ release routine to the slow-path WQ.
9822 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9823 struct lpfc_wcqe_release
*wcqe
)
9825 struct lpfc_queue
*childwq
;
9826 bool wqid_matched
= false;
9829 /* Check for fast-path FCP work queue release */
9830 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
9831 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
9832 if (childwq
->queue_id
== fcp_wqid
) {
9833 lpfc_sli4_wq_release(childwq
,
9834 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
9835 wqid_matched
= true;
9839 /* Report warning log message if no match found */
9840 if (wqid_matched
!= true)
9841 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9842 "2580 Fast-path wqe consume event carries "
9843 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
9847 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
9848 * @cq: Pointer to the completion queue.
9849 * @eqe: Pointer to fast-path completion queue entry.
9851 * This routine process a fast-path work queue completion entry from fast-path
9852 * event queue for FCP command response completion.
9855 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
9856 struct lpfc_cqe
*cqe
)
9858 struct lpfc_wcqe_release wcqe
;
9859 bool workposted
= false;
9861 /* Copy the work queue CQE and convert endian order if needed */
9862 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
9864 /* Check and process for different type of WCQE and dispatch */
9865 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
9866 case CQE_CODE_COMPL_WQE
:
9867 /* Process the WQ complete event */
9868 phba
->last_completion_time
= jiffies
;
9869 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
9870 (struct lpfc_wcqe_complete
*)&wcqe
);
9872 case CQE_CODE_RELEASE_WQE
:
9873 /* Process the WQ release event */
9874 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
9875 (struct lpfc_wcqe_release
*)&wcqe
);
9877 case CQE_CODE_XRI_ABORTED
:
9878 /* Process the WQ XRI abort event */
9879 phba
->last_completion_time
= jiffies
;
9880 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
9881 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
9884 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9885 "0144 Not a valid WCQE code: x%x\n",
9886 bf_get(lpfc_wcqe_c_code
, &wcqe
));
9893 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
9894 * @phba: Pointer to HBA context object.
9895 * @eqe: Pointer to fast-path event queue entry.
9897 * This routine process a event queue entry from the fast-path event queue.
9898 * It will check the MajorCode and MinorCode to determine this is for a
9899 * completion event on a completion queue, if not, an error shall be logged
9900 * and just return. Otherwise, it will get to the corresponding completion
9901 * queue and process all the entries on the completion queue, rearm the
9902 * completion queue, and then return.
9905 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
9908 struct lpfc_queue
*cq
;
9909 struct lpfc_cqe
*cqe
;
9910 bool workposted
= false;
9914 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
9915 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9916 "0366 Not a valid fast-path completion "
9917 "event: majorcode=x%x, minorcode=x%x\n",
9918 bf_get_le32(lpfc_eqe_major_code
, eqe
),
9919 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
9923 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
9924 if (unlikely(!cq
)) {
9925 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
9926 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9927 "0367 Fast-path completion queue "
9928 "does not exist\n");
9932 /* Get the reference to the corresponding CQ */
9933 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
9934 if (unlikely(cqid
!= cq
->queue_id
)) {
9935 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9936 "0368 Miss-matched fast-path completion "
9937 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
9938 cqid
, cq
->queue_id
);
9942 /* Process all the entries to the CQ */
9943 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
9944 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
9945 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
9946 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
9949 /* Catch the no cq entry condition */
9950 if (unlikely(ecount
== 0))
9951 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9952 "0369 No entry from fast-path completion "
9953 "queue fcpcqid=%d\n", cq
->queue_id
);
9955 /* In any case, flash and re-arm the CQ */
9956 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
9958 /* wake up worker thread if there are works to be done */
9960 lpfc_worker_wake_up(phba
);
9964 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
9966 struct lpfc_eqe
*eqe
;
9968 /* walk all the EQ entries and drop on the floor */
9969 while ((eqe
= lpfc_sli4_eq_get(eq
)))
9972 /* Clear and re-arm the EQ */
9973 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
9977 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
9978 * @irq: Interrupt number.
9979 * @dev_id: The device context pointer.
9981 * This function is directly called from the PCI layer as an interrupt
9982 * service routine when device with SLI-4 interface spec is enabled with
9983 * MSI-X multi-message interrupt mode and there are slow-path events in
9984 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
9985 * interrupt mode, this function is called as part of the device-level
9986 * interrupt handler. When the PCI slot is in error recovery or the HBA is
9987 * undergoing initialization, the interrupt handler will not process the
9988 * interrupt. The link attention and ELS ring attention events are handled
9989 * by the worker thread. The interrupt handler signals the worker thread
9990 * and returns for these events. This function is called without any lock
9991 * held. It gets the hbalock to access and update SLI data structures.
9993 * This function returns IRQ_HANDLED when interrupt is handled else it
9997 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
9999 struct lpfc_hba
*phba
;
10000 struct lpfc_queue
*speq
;
10001 struct lpfc_eqe
*eqe
;
10002 unsigned long iflag
;
10006 * Get the driver's phba structure from the dev_id
10008 phba
= (struct lpfc_hba
*)dev_id
;
10010 if (unlikely(!phba
))
10013 /* Get to the EQ struct associated with this vector */
10014 speq
= phba
->sli4_hba
.sp_eq
;
10016 /* Check device state for handling interrupt */
10017 if (unlikely(lpfc_intr_state_check(phba
))) {
10018 /* Check again for link_state with lock held */
10019 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10020 if (phba
->link_state
< LPFC_LINK_DOWN
)
10021 /* Flush, clear interrupt, and rearm the EQ */
10022 lpfc_sli4_eq_flush(phba
, speq
);
10023 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10028 * Process all the event on FCP slow-path EQ
10030 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
10031 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
10032 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
10033 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
10036 /* Always clear and re-arm the slow-path EQ */
10037 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
10039 /* Catch the no cq entry condition */
10040 if (unlikely(ecount
== 0)) {
10041 if (phba
->intr_type
== MSIX
)
10042 /* MSI-X treated interrupt served as no EQ share INT */
10043 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10044 "0357 MSI-X interrupt with no EQE\n");
10046 /* Non MSI-X treated on interrupt as EQ share INT */
10050 return IRQ_HANDLED
;
10051 } /* lpfc_sli4_sp_intr_handler */
10054 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
10055 * @irq: Interrupt number.
10056 * @dev_id: The device context pointer.
10058 * This function is directly called from the PCI layer as an interrupt
10059 * service routine when device with SLI-4 interface spec is enabled with
10060 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10061 * ring event in the HBA. However, when the device is enabled with either
10062 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10063 * device-level interrupt handler. When the PCI slot is in error recovery
10064 * or the HBA is undergoing initialization, the interrupt handler will not
10065 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10066 * the intrrupt context. This function is called without any lock held.
10067 * It gets the hbalock to access and update SLI data structures. Note that,
10068 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
10069 * equal to that of FCP CQ index.
10071 * This function returns IRQ_HANDLED when interrupt is handled else it
10072 * returns IRQ_NONE.
10075 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
10077 struct lpfc_hba
*phba
;
10078 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
10079 struct lpfc_queue
*fpeq
;
10080 struct lpfc_eqe
*eqe
;
10081 unsigned long iflag
;
10083 uint32_t fcp_eqidx
;
10085 /* Get the driver's phba structure from the dev_id */
10086 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
10087 phba
= fcp_eq_hdl
->phba
;
10088 fcp_eqidx
= fcp_eq_hdl
->idx
;
10090 if (unlikely(!phba
))
10093 /* Get to the EQ struct associated with this vector */
10094 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
10096 /* Check device state for handling interrupt */
10097 if (unlikely(lpfc_intr_state_check(phba
))) {
10098 /* Check again for link_state with lock held */
10099 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10100 if (phba
->link_state
< LPFC_LINK_DOWN
)
10101 /* Flush, clear interrupt, and rearm the EQ */
10102 lpfc_sli4_eq_flush(phba
, fpeq
);
10103 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10108 * Process all the event on FCP fast-path EQ
10110 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
10111 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
10112 if (!(++ecount
% LPFC_GET_QE_REL_INT
))
10113 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
10116 /* Always clear and re-arm the fast-path EQ */
10117 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
10119 if (unlikely(ecount
== 0)) {
10120 if (phba
->intr_type
== MSIX
)
10121 /* MSI-X treated interrupt served as no EQ share INT */
10122 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10123 "0358 MSI-X interrupt with no EQE\n");
10125 /* Non MSI-X treated on interrupt as EQ share INT */
10129 return IRQ_HANDLED
;
10130 } /* lpfc_sli4_fp_intr_handler */
10133 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
10134 * @irq: Interrupt number.
10135 * @dev_id: The device context pointer.
10137 * This function is the device-level interrupt handler to device with SLI-4
10138 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
10139 * interrupt mode is enabled and there is an event in the HBA which requires
10140 * driver attention. This function invokes the slow-path interrupt attention
10141 * handling function and fast-path interrupt attention handling function in
10142 * turn to process the relevant HBA attention events. This function is called
10143 * without any lock held. It gets the hbalock to access and update SLI data
10146 * This function returns IRQ_HANDLED when interrupt is handled, else it
10147 * returns IRQ_NONE.
10150 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
10152 struct lpfc_hba
*phba
;
10153 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10154 bool fp_handled
= false;
10155 uint32_t fcp_eqidx
;
10157 /* Get the driver's phba structure from the dev_id */
10158 phba
= (struct lpfc_hba
*)dev_id
;
10160 if (unlikely(!phba
))
10164 * Invokes slow-path host attention interrupt handling as appropriate.
10166 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
10169 * Invoke fast-path host attention interrupt handling as appropriate.
10171 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
10172 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
10173 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
10174 if (fp_irq_rc
== IRQ_HANDLED
)
10175 fp_handled
|= true;
10178 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
10179 } /* lpfc_sli4_intr_handler */
10182 * lpfc_sli4_queue_free - free a queue structure and associated memory
10183 * @queue: The queue structure to free.
10185 * This function frees a queue structure and the DMAable memeory used for
10186 * the host resident queue. This function must be called after destroying the
10187 * queue on the HBA.
10190 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
10192 struct lpfc_dmabuf
*dmabuf
;
10197 while (!list_empty(&queue
->page_list
)) {
10198 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
10200 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
10201 dmabuf
->virt
, dmabuf
->phys
);
10209 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
10210 * @phba: The HBA that this queue is being created on.
10211 * @entry_size: The size of each queue entry for this queue.
10212 * @entry count: The number of entries that this queue will handle.
10214 * This function allocates a queue structure and the DMAable memory used for
10215 * the host resident queue. This function must be called before creating the
10216 * queue on the HBA.
10218 struct lpfc_queue
*
10219 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
10220 uint32_t entry_count
)
10222 struct lpfc_queue
*queue
;
10223 struct lpfc_dmabuf
*dmabuf
;
10224 int x
, total_qe_count
;
10226 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10228 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10229 hw_page_size
= SLI4_PAGE_SIZE
;
10231 queue
= kzalloc(sizeof(struct lpfc_queue
) +
10232 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
10235 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
10236 hw_page_size
))/hw_page_size
;
10237 INIT_LIST_HEAD(&queue
->list
);
10238 INIT_LIST_HEAD(&queue
->page_list
);
10239 INIT_LIST_HEAD(&queue
->child_list
);
10240 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
10241 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
10244 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
10245 hw_page_size
, &dmabuf
->phys
,
10247 if (!dmabuf
->virt
) {
10251 memset(dmabuf
->virt
, 0, hw_page_size
);
10252 dmabuf
->buffer_tag
= x
;
10253 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
10254 /* initialize queue's entry array */
10255 dma_pointer
= dmabuf
->virt
;
10256 for (; total_qe_count
< entry_count
&&
10257 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
10258 total_qe_count
++, dma_pointer
+= entry_size
) {
10259 queue
->qe
[total_qe_count
].address
= dma_pointer
;
10262 queue
->entry_size
= entry_size
;
10263 queue
->entry_count
= entry_count
;
10264 queue
->phba
= phba
;
10268 lpfc_sli4_queue_free(queue
);
10273 * lpfc_eq_create - Create an Event Queue on the HBA
10274 * @phba: HBA structure that indicates port to create a queue on.
10275 * @eq: The queue structure to use to create the event queue.
10276 * @imax: The maximum interrupt per second limit.
10278 * This function creates an event queue, as detailed in @eq, on a port,
10279 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
10281 * The @phba struct is used to send mailbox command to HBA. The @eq struct
10282 * is used to get the entry count and entry size that are necessary to
10283 * determine the number of pages to allocate and use for this queue. This
10284 * function will send the EQ_CREATE mailbox command to the HBA to setup the
10285 * event queue. This function is asynchronous and will wait for the mailbox
10286 * command to finish before continuing.
10288 * On success this function will return a zero. If unable to allocate enough
10289 * memory this function will return -ENOMEM. If the queue create mailbox command
10290 * fails this function will return -ENXIO.
10293 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
10295 struct lpfc_mbx_eq_create
*eq_create
;
10296 LPFC_MBOXQ_t
*mbox
;
10297 int rc
, length
, status
= 0;
10298 struct lpfc_dmabuf
*dmabuf
;
10299 uint32_t shdr_status
, shdr_add_status
;
10300 union lpfc_sli4_cfg_shdr
*shdr
;
10302 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10304 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10305 hw_page_size
= SLI4_PAGE_SIZE
;
10307 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10310 length
= (sizeof(struct lpfc_mbx_eq_create
) -
10311 sizeof(struct lpfc_sli4_cfg_mhdr
));
10312 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10313 LPFC_MBOX_OPCODE_EQ_CREATE
,
10314 length
, LPFC_SLI4_MBX_EMBED
);
10315 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
10316 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
10318 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
10320 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
10321 /* Calculate delay multiper from maximum interrupt per second */
10322 dmult
= LPFC_DMULT_CONST
/imax
- 1;
10323 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
10325 switch (eq
->entry_count
) {
10327 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10328 "0360 Unsupported EQ count. (%d)\n",
10330 if (eq
->entry_count
< 256)
10332 /* otherwise default to smallest count (drop through) */
10334 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
10338 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
10342 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
10346 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
10350 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
10354 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
10355 memset(dmabuf
->virt
, 0, hw_page_size
);
10356 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10357 putPaddrLow(dmabuf
->phys
);
10358 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10359 putPaddrHigh(dmabuf
->phys
);
10361 mbox
->vport
= phba
->pport
;
10362 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10363 mbox
->context1
= NULL
;
10364 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10365 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
10366 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10367 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10368 if (shdr_status
|| shdr_add_status
|| rc
) {
10369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10370 "2500 EQ_CREATE mailbox failed with "
10371 "status x%x add_status x%x, mbx status x%x\n",
10372 shdr_status
, shdr_add_status
, rc
);
10375 eq
->type
= LPFC_EQ
;
10376 eq
->subtype
= LPFC_NONE
;
10377 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
10378 if (eq
->queue_id
== 0xFFFF)
10380 eq
->host_index
= 0;
10383 mempool_free(mbox
, phba
->mbox_mem_pool
);
10388 * lpfc_cq_create - Create a Completion Queue on the HBA
10389 * @phba: HBA structure that indicates port to create a queue on.
10390 * @cq: The queue structure to use to create the completion queue.
10391 * @eq: The event queue to bind this completion queue to.
10393 * This function creates a completion queue, as detailed in @wq, on a port,
10394 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
10396 * The @phba struct is used to send mailbox command to HBA. The @cq struct
10397 * is used to get the entry count and entry size that are necessary to
10398 * determine the number of pages to allocate and use for this queue. The @eq
10399 * is used to indicate which event queue to bind this completion queue to. This
10400 * function will send the CQ_CREATE mailbox command to the HBA to setup the
10401 * completion queue. This function is asynchronous and will wait for the mailbox
10402 * command to finish before continuing.
10404 * On success this function will return a zero. If unable to allocate enough
10405 * memory this function will return -ENOMEM. If the queue create mailbox command
10406 * fails this function will return -ENXIO.
10409 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
10410 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
10412 struct lpfc_mbx_cq_create
*cq_create
;
10413 struct lpfc_dmabuf
*dmabuf
;
10414 LPFC_MBOXQ_t
*mbox
;
10415 int rc
, length
, status
= 0;
10416 uint32_t shdr_status
, shdr_add_status
;
10417 union lpfc_sli4_cfg_shdr
*shdr
;
10418 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10420 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10421 hw_page_size
= SLI4_PAGE_SIZE
;
10424 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10427 length
= (sizeof(struct lpfc_mbx_cq_create
) -
10428 sizeof(struct lpfc_sli4_cfg_mhdr
));
10429 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10430 LPFC_MBOX_OPCODE_CQ_CREATE
,
10431 length
, LPFC_SLI4_MBX_EMBED
);
10432 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
10433 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
10435 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
10436 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
10437 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
, eq
->queue_id
);
10438 switch (cq
->entry_count
) {
10440 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10441 "0361 Unsupported CQ count. (%d)\n",
10443 if (cq
->entry_count
< 256)
10445 /* otherwise default to smallest count (drop through) */
10447 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
10451 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
10455 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
10459 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
10460 memset(dmabuf
->virt
, 0, hw_page_size
);
10461 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10462 putPaddrLow(dmabuf
->phys
);
10463 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10464 putPaddrHigh(dmabuf
->phys
);
10466 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10468 /* The IOCTL status is embedded in the mailbox subheader. */
10469 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
10470 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10471 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10472 if (shdr_status
|| shdr_add_status
|| rc
) {
10473 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10474 "2501 CQ_CREATE mailbox failed with "
10475 "status x%x add_status x%x, mbx status x%x\n",
10476 shdr_status
, shdr_add_status
, rc
);
10480 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
10481 if (cq
->queue_id
== 0xFFFF) {
10485 /* link the cq onto the parent eq child list */
10486 list_add_tail(&cq
->list
, &eq
->child_list
);
10487 /* Set up completion queue's type and subtype */
10489 cq
->subtype
= subtype
;
10490 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
10491 cq
->host_index
= 0;
10495 mempool_free(mbox
, phba
->mbox_mem_pool
);
10500 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
10501 * @phba: HBA structure that indicates port to create a queue on.
10502 * @mq: The queue structure to use to create the mailbox queue.
10503 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
10504 * @cq: The completion queue to associate with this cq.
10506 * This function provides failback (fb) functionality when the
10507 * mq_create_ext fails on older FW generations. It's purpose is identical
10508 * to mq_create_ext otherwise.
10510 * This routine cannot fail as all attributes were previously accessed and
10511 * initialized in mq_create_ext.
10514 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
10515 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
10517 struct lpfc_mbx_mq_create
*mq_create
;
10518 struct lpfc_dmabuf
*dmabuf
;
10521 length
= (sizeof(struct lpfc_mbx_mq_create
) -
10522 sizeof(struct lpfc_sli4_cfg_mhdr
));
10523 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10524 LPFC_MBOX_OPCODE_MQ_CREATE
,
10525 length
, LPFC_SLI4_MBX_EMBED
);
10526 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
10527 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
10529 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
10531 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
10532 switch (mq
->entry_count
) {
10534 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
10538 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
10542 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
10546 bf_set(lpfc_mq_context_count
, &mq_create
->u
.request
.context
,
10550 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
10551 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10552 putPaddrLow(dmabuf
->phys
);
10553 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10554 putPaddrHigh(dmabuf
->phys
);
10559 * lpfc_mq_create - Create a mailbox Queue on the HBA
10560 * @phba: HBA structure that indicates port to create a queue on.
10561 * @mq: The queue structure to use to create the mailbox queue.
10562 * @cq: The completion queue to associate with this cq.
10563 * @subtype: The queue's subtype.
10565 * This function creates a mailbox queue, as detailed in @mq, on a port,
10566 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
10568 * The @phba struct is used to send mailbox command to HBA. The @cq struct
10569 * is used to get the entry count and entry size that are necessary to
10570 * determine the number of pages to allocate and use for this queue. This
10571 * function will send the MQ_CREATE mailbox command to the HBA to setup the
10572 * mailbox queue. This function is asynchronous and will wait for the mailbox
10573 * command to finish before continuing.
10575 * On success this function will return a zero. If unable to allocate enough
10576 * memory this function will return -ENOMEM. If the queue create mailbox command
10577 * fails this function will return -ENXIO.
10580 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
10581 struct lpfc_queue
*cq
, uint32_t subtype
)
10583 struct lpfc_mbx_mq_create
*mq_create
;
10584 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
10585 struct lpfc_dmabuf
*dmabuf
;
10586 LPFC_MBOXQ_t
*mbox
;
10587 int rc
, length
, status
= 0;
10588 uint32_t shdr_status
, shdr_add_status
;
10589 union lpfc_sli4_cfg_shdr
*shdr
;
10590 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10592 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10593 hw_page_size
= SLI4_PAGE_SIZE
;
10595 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10598 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
10599 sizeof(struct lpfc_sli4_cfg_mhdr
));
10600 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10601 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
10602 length
, LPFC_SLI4_MBX_EMBED
);
10604 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
10605 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
10606 &mq_create_ext
->u
.request
, mq
->page_count
);
10607 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
10608 &mq_create_ext
->u
.request
, 1);
10609 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
10610 &mq_create_ext
->u
.request
, 1);
10611 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
10612 &mq_create_ext
->u
.request
, 1);
10613 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
10614 &mq_create_ext
->u
.request
, 1);
10615 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
10616 &mq_create_ext
->u
.request
, 1);
10617 bf_set(lpfc_mq_context_cq_id
,
10618 &mq_create_ext
->u
.request
.context
, cq
->queue_id
);
10619 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
10620 switch (mq
->entry_count
) {
10622 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10623 "0362 Unsupported MQ count. (%d)\n",
10625 if (mq
->entry_count
< 16)
10627 /* otherwise default to smallest count (drop through) */
10629 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
10633 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
10637 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
10641 bf_set(lpfc_mq_context_count
, &mq_create_ext
->u
.request
.context
,
10645 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
10646 memset(dmabuf
->virt
, 0, hw_page_size
);
10647 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10648 putPaddrLow(dmabuf
->phys
);
10649 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10650 putPaddrHigh(dmabuf
->phys
);
10652 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10653 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
10654 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
10655 &mq_create_ext
->u
.response
);
10656 if (rc
!= MBX_SUCCESS
) {
10657 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10658 "2795 MQ_CREATE_EXT failed with "
10659 "status x%x. Failback to MQ_CREATE.\n",
10661 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
10662 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
10663 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10664 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
10665 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
10666 &mq_create
->u
.response
);
10669 /* The IOCTL status is embedded in the mailbox subheader. */
10670 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10671 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10672 if (shdr_status
|| shdr_add_status
|| rc
) {
10673 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10674 "2502 MQ_CREATE mailbox failed with "
10675 "status x%x add_status x%x, mbx status x%x\n",
10676 shdr_status
, shdr_add_status
, rc
);
10680 if (mq
->queue_id
== 0xFFFF) {
10684 mq
->type
= LPFC_MQ
;
10685 mq
->subtype
= subtype
;
10686 mq
->host_index
= 0;
10689 /* link the mq onto the parent cq child list */
10690 list_add_tail(&mq
->list
, &cq
->child_list
);
10692 mempool_free(mbox
, phba
->mbox_mem_pool
);
10697 * lpfc_wq_create - Create a Work Queue on the HBA
10698 * @phba: HBA structure that indicates port to create a queue on.
10699 * @wq: The queue structure to use to create the work queue.
10700 * @cq: The completion queue to bind this work queue to.
10701 * @subtype: The subtype of the work queue indicating its functionality.
10703 * This function creates a work queue, as detailed in @wq, on a port, described
10704 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
10706 * The @phba struct is used to send mailbox command to HBA. The @wq struct
10707 * is used to get the entry count and entry size that are necessary to
10708 * determine the number of pages to allocate and use for this queue. The @cq
10709 * is used to indicate which completion queue to bind this work queue to. This
10710 * function will send the WQ_CREATE mailbox command to the HBA to setup the
10711 * work queue. This function is asynchronous and will wait for the mailbox
10712 * command to finish before continuing.
10714 * On success this function will return a zero. If unable to allocate enough
10715 * memory this function will return -ENOMEM. If the queue create mailbox command
10716 * fails this function will return -ENXIO.
10719 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
10720 struct lpfc_queue
*cq
, uint32_t subtype
)
10722 struct lpfc_mbx_wq_create
*wq_create
;
10723 struct lpfc_dmabuf
*dmabuf
;
10724 LPFC_MBOXQ_t
*mbox
;
10725 int rc
, length
, status
= 0;
10726 uint32_t shdr_status
, shdr_add_status
;
10727 union lpfc_sli4_cfg_shdr
*shdr
;
10728 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10730 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10731 hw_page_size
= SLI4_PAGE_SIZE
;
10733 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10736 length
= (sizeof(struct lpfc_mbx_wq_create
) -
10737 sizeof(struct lpfc_sli4_cfg_mhdr
));
10738 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10739 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
10740 length
, LPFC_SLI4_MBX_EMBED
);
10741 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
10742 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
10744 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
10746 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
10747 memset(dmabuf
->virt
, 0, hw_page_size
);
10748 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10749 putPaddrLow(dmabuf
->phys
);
10750 wq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10751 putPaddrHigh(dmabuf
->phys
);
10753 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10754 /* The IOCTL status is embedded in the mailbox subheader. */
10755 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
10756 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10757 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10758 if (shdr_status
|| shdr_add_status
|| rc
) {
10759 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10760 "2503 WQ_CREATE mailbox failed with "
10761 "status x%x add_status x%x, mbx status x%x\n",
10762 shdr_status
, shdr_add_status
, rc
);
10766 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
10767 if (wq
->queue_id
== 0xFFFF) {
10771 wq
->type
= LPFC_WQ
;
10772 wq
->subtype
= subtype
;
10773 wq
->host_index
= 0;
10776 /* link the wq onto the parent cq child list */
10777 list_add_tail(&wq
->list
, &cq
->child_list
);
10779 mempool_free(mbox
, phba
->mbox_mem_pool
);
10784 * lpfc_rq_create - Create a Receive Queue on the HBA
10785 * @phba: HBA structure that indicates port to create a queue on.
10786 * @hrq: The queue structure to use to create the header receive queue.
10787 * @drq: The queue structure to use to create the data receive queue.
10788 * @cq: The completion queue to bind this work queue to.
10790 * This function creates a receive buffer queue pair , as detailed in @hrq and
10791 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
10794 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
10795 * struct is used to get the entry count that is necessary to determine the
10796 * number of pages to use for this queue. The @cq is used to indicate which
10797 * completion queue to bind received buffers that are posted to these queues to.
10798 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
10799 * receive queue pair. This function is asynchronous and will wait for the
10800 * mailbox command to finish before continuing.
10802 * On success this function will return a zero. If unable to allocate enough
10803 * memory this function will return -ENOMEM. If the queue create mailbox command
10804 * fails this function will return -ENXIO.
10807 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
10808 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
10810 struct lpfc_mbx_rq_create
*rq_create
;
10811 struct lpfc_dmabuf
*dmabuf
;
10812 LPFC_MBOXQ_t
*mbox
;
10813 int rc
, length
, status
= 0;
10814 uint32_t shdr_status
, shdr_add_status
;
10815 union lpfc_sli4_cfg_shdr
*shdr
;
10816 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
10818 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
10819 hw_page_size
= SLI4_PAGE_SIZE
;
10821 if (hrq
->entry_count
!= drq
->entry_count
)
10823 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10826 length
= (sizeof(struct lpfc_mbx_rq_create
) -
10827 sizeof(struct lpfc_sli4_cfg_mhdr
));
10828 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10829 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
10830 length
, LPFC_SLI4_MBX_EMBED
);
10831 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
10832 switch (hrq
->entry_count
) {
10834 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10835 "2535 Unsupported RQ count. (%d)\n",
10837 if (hrq
->entry_count
< 512)
10839 /* otherwise default to smallest count (drop through) */
10841 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10842 LPFC_RQ_RING_SIZE_512
);
10845 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10846 LPFC_RQ_RING_SIZE_1024
);
10849 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10850 LPFC_RQ_RING_SIZE_2048
);
10853 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10854 LPFC_RQ_RING_SIZE_4096
);
10857 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
10859 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
10861 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
10862 LPFC_HDR_BUF_SIZE
);
10863 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
10864 memset(dmabuf
->virt
, 0, hw_page_size
);
10865 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10866 putPaddrLow(dmabuf
->phys
);
10867 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10868 putPaddrHigh(dmabuf
->phys
);
10870 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10871 /* The IOCTL status is embedded in the mailbox subheader. */
10872 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
10873 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10874 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10875 if (shdr_status
|| shdr_add_status
|| rc
) {
10876 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10877 "2504 RQ_CREATE mailbox failed with "
10878 "status x%x add_status x%x, mbx status x%x\n",
10879 shdr_status
, shdr_add_status
, rc
);
10883 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
10884 if (hrq
->queue_id
== 0xFFFF) {
10888 hrq
->type
= LPFC_HRQ
;
10889 hrq
->subtype
= subtype
;
10890 hrq
->host_index
= 0;
10891 hrq
->hba_index
= 0;
10893 /* now create the data queue */
10894 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
10895 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
10896 length
, LPFC_SLI4_MBX_EMBED
);
10897 switch (drq
->entry_count
) {
10899 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10900 "2536 Unsupported RQ count. (%d)\n",
10902 if (drq
->entry_count
< 512)
10904 /* otherwise default to smallest count (drop through) */
10906 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10907 LPFC_RQ_RING_SIZE_512
);
10910 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10911 LPFC_RQ_RING_SIZE_1024
);
10914 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10915 LPFC_RQ_RING_SIZE_2048
);
10918 bf_set(lpfc_rq_context_rq_size
, &rq_create
->u
.request
.context
,
10919 LPFC_RQ_RING_SIZE_4096
);
10922 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
10924 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
10926 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
10927 LPFC_DATA_BUF_SIZE
);
10928 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
10929 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
10930 putPaddrLow(dmabuf
->phys
);
10931 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
10932 putPaddrHigh(dmabuf
->phys
);
10934 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
10935 /* The IOCTL status is embedded in the mailbox subheader. */
10936 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
10937 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10938 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
10939 if (shdr_status
|| shdr_add_status
|| rc
) {
10943 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
10944 if (drq
->queue_id
== 0xFFFF) {
10948 drq
->type
= LPFC_DRQ
;
10949 drq
->subtype
= subtype
;
10950 drq
->host_index
= 0;
10951 drq
->hba_index
= 0;
10953 /* link the header and data RQs onto the parent cq child list */
10954 list_add_tail(&hrq
->list
, &cq
->child_list
);
10955 list_add_tail(&drq
->list
, &cq
->child_list
);
10958 mempool_free(mbox
, phba
->mbox_mem_pool
);
10963 * lpfc_eq_destroy - Destroy an event Queue on the HBA
10964 * @eq: The queue structure associated with the queue to destroy.
10966 * This function destroys a queue, as detailed in @eq by sending an mailbox
10967 * command, specific to the type of queue, to the HBA.
10969 * The @eq struct is used to get the queue ID of the queue to destroy.
10971 * On success this function will return a zero. If the queue destroy mailbox
10972 * command fails this function will return -ENXIO.
10975 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
10977 LPFC_MBOXQ_t
*mbox
;
10978 int rc
, length
, status
= 0;
10979 uint32_t shdr_status
, shdr_add_status
;
10980 union lpfc_sli4_cfg_shdr
*shdr
;
10984 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
10987 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
10988 sizeof(struct lpfc_sli4_cfg_mhdr
));
10989 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10990 LPFC_MBOX_OPCODE_EQ_DESTROY
,
10991 length
, LPFC_SLI4_MBX_EMBED
);
10992 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
10994 mbox
->vport
= eq
->phba
->pport
;
10995 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10997 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
10998 /* The IOCTL status is embedded in the mailbox subheader. */
10999 shdr
= (union lpfc_sli4_cfg_shdr
*)
11000 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
11001 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11002 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11003 if (shdr_status
|| shdr_add_status
|| rc
) {
11004 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11005 "2505 EQ_DESTROY mailbox failed with "
11006 "status x%x add_status x%x, mbx status x%x\n",
11007 shdr_status
, shdr_add_status
, rc
);
11011 /* Remove eq from any list */
11012 list_del_init(&eq
->list
);
11013 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
11018 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
11019 * @cq: The queue structure associated with the queue to destroy.
11021 * This function destroys a queue, as detailed in @cq by sending an mailbox
11022 * command, specific to the type of queue, to the HBA.
11024 * The @cq struct is used to get the queue ID of the queue to destroy.
11026 * On success this function will return a zero. If the queue destroy mailbox
11027 * command fails this function will return -ENXIO.
11030 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
11032 LPFC_MBOXQ_t
*mbox
;
11033 int rc
, length
, status
= 0;
11034 uint32_t shdr_status
, shdr_add_status
;
11035 union lpfc_sli4_cfg_shdr
*shdr
;
11039 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
11042 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
11043 sizeof(struct lpfc_sli4_cfg_mhdr
));
11044 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
11045 LPFC_MBOX_OPCODE_CQ_DESTROY
,
11046 length
, LPFC_SLI4_MBX_EMBED
);
11047 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
11049 mbox
->vport
= cq
->phba
->pport
;
11050 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11051 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
11052 /* The IOCTL status is embedded in the mailbox subheader. */
11053 shdr
= (union lpfc_sli4_cfg_shdr
*)
11054 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
11055 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11056 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11057 if (shdr_status
|| shdr_add_status
|| rc
) {
11058 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11059 "2506 CQ_DESTROY mailbox failed with "
11060 "status x%x add_status x%x, mbx status x%x\n",
11061 shdr_status
, shdr_add_status
, rc
);
11064 /* Remove cq from any list */
11065 list_del_init(&cq
->list
);
11066 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
11071 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
11072 * @qm: The queue structure associated with the queue to destroy.
11074 * This function destroys a queue, as detailed in @mq by sending an mailbox
11075 * command, specific to the type of queue, to the HBA.
11077 * The @mq struct is used to get the queue ID of the queue to destroy.
11079 * On success this function will return a zero. If the queue destroy mailbox
11080 * command fails this function will return -ENXIO.
11083 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
11085 LPFC_MBOXQ_t
*mbox
;
11086 int rc
, length
, status
= 0;
11087 uint32_t shdr_status
, shdr_add_status
;
11088 union lpfc_sli4_cfg_shdr
*shdr
;
11092 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
11095 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
11096 sizeof(struct lpfc_sli4_cfg_mhdr
));
11097 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
11098 LPFC_MBOX_OPCODE_MQ_DESTROY
,
11099 length
, LPFC_SLI4_MBX_EMBED
);
11100 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
11102 mbox
->vport
= mq
->phba
->pport
;
11103 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11104 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
11105 /* The IOCTL status is embedded in the mailbox subheader. */
11106 shdr
= (union lpfc_sli4_cfg_shdr
*)
11107 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
11108 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11109 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11110 if (shdr_status
|| shdr_add_status
|| rc
) {
11111 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11112 "2507 MQ_DESTROY mailbox failed with "
11113 "status x%x add_status x%x, mbx status x%x\n",
11114 shdr_status
, shdr_add_status
, rc
);
11117 /* Remove mq from any list */
11118 list_del_init(&mq
->list
);
11119 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
11124 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
11125 * @wq: The queue structure associated with the queue to destroy.
11127 * This function destroys a queue, as detailed in @wq by sending an mailbox
11128 * command, specific to the type of queue, to the HBA.
11130 * The @wq struct is used to get the queue ID of the queue to destroy.
11132 * On success this function will return a zero. If the queue destroy mailbox
11133 * command fails this function will return -ENXIO.
11136 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
11138 LPFC_MBOXQ_t
*mbox
;
11139 int rc
, length
, status
= 0;
11140 uint32_t shdr_status
, shdr_add_status
;
11141 union lpfc_sli4_cfg_shdr
*shdr
;
11145 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
11148 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
11149 sizeof(struct lpfc_sli4_cfg_mhdr
));
11150 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11151 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
11152 length
, LPFC_SLI4_MBX_EMBED
);
11153 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
11155 mbox
->vport
= wq
->phba
->pport
;
11156 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11157 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
11158 shdr
= (union lpfc_sli4_cfg_shdr
*)
11159 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
11160 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11161 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11162 if (shdr_status
|| shdr_add_status
|| rc
) {
11163 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11164 "2508 WQ_DESTROY mailbox failed with "
11165 "status x%x add_status x%x, mbx status x%x\n",
11166 shdr_status
, shdr_add_status
, rc
);
11169 /* Remove wq from any list */
11170 list_del_init(&wq
->list
);
11171 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
11176 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
11177 * @rq: The queue structure associated with the queue to destroy.
11179 * This function destroys a queue, as detailed in @rq by sending an mailbox
11180 * command, specific to the type of queue, to the HBA.
11182 * The @rq struct is used to get the queue ID of the queue to destroy.
11184 * On success this function will return a zero. If the queue destroy mailbox
11185 * command fails this function will return -ENXIO.
11188 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
11189 struct lpfc_queue
*drq
)
11191 LPFC_MBOXQ_t
*mbox
;
11192 int rc
, length
, status
= 0;
11193 uint32_t shdr_status
, shdr_add_status
;
11194 union lpfc_sli4_cfg_shdr
*shdr
;
11198 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
11201 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
11202 sizeof(struct mbox_header
));
11203 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11204 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
11205 length
, LPFC_SLI4_MBX_EMBED
);
11206 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
11208 mbox
->vport
= hrq
->phba
->pport
;
11209 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11210 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
11211 /* The IOCTL status is embedded in the mailbox subheader. */
11212 shdr
= (union lpfc_sli4_cfg_shdr
*)
11213 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
11214 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11215 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11216 if (shdr_status
|| shdr_add_status
|| rc
) {
11217 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11218 "2509 RQ_DESTROY mailbox failed with "
11219 "status x%x add_status x%x, mbx status x%x\n",
11220 shdr_status
, shdr_add_status
, rc
);
11221 if (rc
!= MBX_TIMEOUT
)
11222 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
11225 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
11227 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
11228 shdr
= (union lpfc_sli4_cfg_shdr
*)
11229 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
11230 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11231 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11232 if (shdr_status
|| shdr_add_status
|| rc
) {
11233 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11234 "2510 RQ_DESTROY mailbox failed with "
11235 "status x%x add_status x%x, mbx status x%x\n",
11236 shdr_status
, shdr_add_status
, rc
);
11239 list_del_init(&hrq
->list
);
11240 list_del_init(&drq
->list
);
11241 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
11246 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
11247 * @phba: The virtual port for which this call being executed.
11248 * @pdma_phys_addr0: Physical address of the 1st SGL page.
11249 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
11250 * @xritag: the xritag that ties this io to the SGL pages.
11252 * This routine will post the sgl pages for the IO that has the xritag
11253 * that is in the iocbq structure. The xritag is assigned during iocbq
11254 * creation and persists for as long as the driver is loaded.
11255 * if the caller has fewer than 256 scatter gather segments to map then
11256 * pdma_phys_addr1 should be 0.
11257 * If the caller needs to map more than 256 scatter gather segment then
11258 * pdma_phys_addr1 should be a valid physical address.
11259 * physical address for SGLs must be 64 byte aligned.
11260 * If you are going to map 2 SGL's then the first one must have 256 entries
11261 * the second sgl can have between 1 and 256 entries.
11265 * -ENXIO, -ENOMEM - Failure
11268 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
11269 dma_addr_t pdma_phys_addr0
,
11270 dma_addr_t pdma_phys_addr1
,
11273 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
11274 LPFC_MBOXQ_t
*mbox
;
11276 uint32_t shdr_status
, shdr_add_status
;
11277 union lpfc_sli4_cfg_shdr
*shdr
;
11279 if (xritag
== NO_XRI
) {
11280 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11281 "0364 Invalid param:\n");
11285 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11289 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11290 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
11291 sizeof(struct lpfc_mbx_post_sgl_pages
) -
11292 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
11294 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
11295 &mbox
->u
.mqe
.un
.post_sgl_pages
;
11296 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
11297 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
11299 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
11300 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
11301 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
11302 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
11304 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
11305 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
11306 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
11307 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
11308 if (!phba
->sli4_hba
.intr_enable
)
11309 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
11311 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
11312 /* The IOCTL status is embedded in the mailbox subheader. */
11313 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
11314 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11315 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11316 if (rc
!= MBX_TIMEOUT
)
11317 mempool_free(mbox
, phba
->mbox_mem_pool
);
11318 if (shdr_status
|| shdr_add_status
|| rc
) {
11319 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11320 "2511 POST_SGL mailbox failed with "
11321 "status x%x add_status x%x, mbx status x%x\n",
11322 shdr_status
, shdr_add_status
, rc
);
11329 * lpfc_sli4_next_xritag - Get an xritag for the io
11330 * @phba: Pointer to HBA context object.
11332 * This function gets an xritag for the iocb. If there is no unused xritag
11333 * it will return 0xffff.
11334 * The function returns the allocated xritag if successful, else returns zero.
11335 * Zero is not a valid xritag.
11336 * The caller is not required to hold any lock.
11339 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
11343 spin_lock_irq(&phba
->hbalock
);
11344 xritag
= phba
->sli4_hba
.next_xri
;
11345 if ((xritag
!= (uint16_t) -1) && xritag
<
11346 (phba
->sli4_hba
.max_cfg_param
.max_xri
11347 + phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
11348 phba
->sli4_hba
.next_xri
++;
11349 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
11350 spin_unlock_irq(&phba
->hbalock
);
11353 spin_unlock_irq(&phba
->hbalock
);
11354 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11355 "2004 Failed to allocate XRI.last XRITAG is %d"
11356 " Max XRI is %d, Used XRI is %d\n",
11357 phba
->sli4_hba
.next_xri
,
11358 phba
->sli4_hba
.max_cfg_param
.max_xri
,
11359 phba
->sli4_hba
.max_cfg_param
.xri_used
);
11364 * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
11365 * @phba: pointer to lpfc hba data structure.
11367 * This routine is invoked to post a block of driver's sgl pages to the
11368 * HBA using non-embedded mailbox command. No Lock is held. This routine
11369 * is only called when the driver is loading and after all IO has been
11373 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
)
11375 struct lpfc_sglq
*sglq_entry
;
11376 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
11377 struct sgl_page_pairs
*sgl_pg_pairs
;
11379 LPFC_MBOXQ_t
*mbox
;
11380 uint32_t reqlen
, alloclen
, pg_pairs
;
11382 uint16_t xritag_start
= 0;
11383 int els_xri_cnt
, rc
= 0;
11384 uint32_t shdr_status
, shdr_add_status
;
11385 union lpfc_sli4_cfg_shdr
*shdr
;
11387 /* The number of sgls to be posted */
11388 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
11390 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
11391 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
11392 if (reqlen
> SLI4_PAGE_SIZE
) {
11393 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
11394 "2559 Block sgl registration required DMA "
11395 "size (%d) great than a page\n", reqlen
);
11398 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11400 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11401 "2560 Failed to allocate mbox cmd memory\n");
11405 /* Allocate DMA memory and set up the non-embedded mailbox command */
11406 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11407 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
11408 LPFC_SLI4_MBX_NEMBED
);
11410 if (alloclen
< reqlen
) {
11411 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11412 "0285 Allocated DMA memory size (%d) is "
11413 "less than the requested DMA memory "
11414 "size (%d)\n", alloclen
, reqlen
);
11415 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
11418 /* Get the first SGE entry from the non-embedded DMA memory */
11419 viraddr
= mbox
->sge_array
->addr
[0];
11421 /* Set up the SGL pages in the non-embedded DMA pages */
11422 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
11423 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
11425 for (pg_pairs
= 0; pg_pairs
< els_xri_cnt
; pg_pairs
++) {
11426 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[pg_pairs
];
11427 /* Set up the sge entry */
11428 sgl_pg_pairs
->sgl_pg0_addr_lo
=
11429 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
11430 sgl_pg_pairs
->sgl_pg0_addr_hi
=
11431 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
11432 sgl_pg_pairs
->sgl_pg1_addr_lo
=
11433 cpu_to_le32(putPaddrLow(0));
11434 sgl_pg_pairs
->sgl_pg1_addr_hi
=
11435 cpu_to_le32(putPaddrHigh(0));
11436 /* Keep the first xritag on the list */
11438 xritag_start
= sglq_entry
->sli4_xritag
;
11441 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
11442 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, els_xri_cnt
);
11443 /* Perform endian conversion if necessary */
11444 sgl
->word0
= cpu_to_le32(sgl
->word0
);
11446 if (!phba
->sli4_hba
.intr_enable
)
11447 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
11449 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
11450 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
11452 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
11453 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11454 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11455 if (rc
!= MBX_TIMEOUT
)
11456 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
11457 if (shdr_status
|| shdr_add_status
|| rc
) {
11458 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11459 "2513 POST_SGL_BLOCK mailbox command failed "
11460 "status x%x add_status x%x mbx status x%x\n",
11461 shdr_status
, shdr_add_status
, rc
);
11468 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
11469 * @phba: pointer to lpfc hba data structure.
11470 * @sblist: pointer to scsi buffer list.
11471 * @count: number of scsi buffers on the list.
11473 * This routine is invoked to post a block of @count scsi sgl pages from a
11474 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
11479 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
, struct list_head
*sblist
,
11482 struct lpfc_scsi_buf
*psb
;
11483 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
11484 struct sgl_page_pairs
*sgl_pg_pairs
;
11486 LPFC_MBOXQ_t
*mbox
;
11487 uint32_t reqlen
, alloclen
, pg_pairs
;
11489 uint16_t xritag_start
= 0;
11491 uint32_t shdr_status
, shdr_add_status
;
11492 dma_addr_t pdma_phys_bpl1
;
11493 union lpfc_sli4_cfg_shdr
*shdr
;
11495 /* Calculate the requested length of the dma memory */
11496 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
11497 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
11498 if (reqlen
> SLI4_PAGE_SIZE
) {
11499 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
11500 "0217 Block sgl registration required DMA "
11501 "size (%d) great than a page\n", reqlen
);
11504 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11506 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11507 "0283 Failed to allocate mbox cmd memory\n");
11511 /* Allocate DMA memory and set up the non-embedded mailbox command */
11512 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
11513 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
11514 LPFC_SLI4_MBX_NEMBED
);
11516 if (alloclen
< reqlen
) {
11517 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11518 "2561 Allocated DMA memory size (%d) is "
11519 "less than the requested DMA memory "
11520 "size (%d)\n", alloclen
, reqlen
);
11521 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
11524 /* Get the first SGE entry from the non-embedded DMA memory */
11525 viraddr
= mbox
->sge_array
->addr
[0];
11527 /* Set up the SGL pages in the non-embedded DMA pages */
11528 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
11529 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
11532 list_for_each_entry(psb
, sblist
, list
) {
11533 /* Set up the sge entry */
11534 sgl_pg_pairs
->sgl_pg0_addr_lo
=
11535 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
11536 sgl_pg_pairs
->sgl_pg0_addr_hi
=
11537 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
11538 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
11539 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
11541 pdma_phys_bpl1
= 0;
11542 sgl_pg_pairs
->sgl_pg1_addr_lo
=
11543 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
11544 sgl_pg_pairs
->sgl_pg1_addr_hi
=
11545 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
11546 /* Keep the first xritag on the list */
11548 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
11552 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
11553 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
11554 /* Perform endian conversion if necessary */
11555 sgl
->word0
= cpu_to_le32(sgl
->word0
);
11557 if (!phba
->sli4_hba
.intr_enable
)
11558 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
11560 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
11561 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
11563 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
11564 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11565 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11566 if (rc
!= MBX_TIMEOUT
)
11567 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
11568 if (shdr_status
|| shdr_add_status
|| rc
) {
11569 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11570 "2564 POST_SGL_BLOCK mailbox command failed "
11571 "status x%x add_status x%x mbx status x%x\n",
11572 shdr_status
, shdr_add_status
, rc
);
11579 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
11580 * @phba: pointer to lpfc_hba struct that the frame was received on
11581 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11583 * This function checks the fields in the @fc_hdr to see if the FC frame is a
11584 * valid type of frame that the LPFC driver will handle. This function will
11585 * return a zero if the frame is a valid frame or a non zero value when the
11586 * frame does not pass the check.
11589 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
11591 char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
11592 char *type_names
[] = FC_TYPE_NAMES_INIT
;
11593 struct fc_vft_header
*fc_vft_hdr
;
11595 switch (fc_hdr
->fh_r_ctl
) {
11596 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
11597 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
11598 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
11599 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
11600 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
11601 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
11602 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
11603 case FC_RCTL_DD_CMD_STATUS
: /* command status */
11604 case FC_RCTL_ELS_REQ
: /* extended link services request */
11605 case FC_RCTL_ELS_REP
: /* extended link services reply */
11606 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
11607 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
11608 case FC_RCTL_BA_NOP
: /* basic link service NOP */
11609 case FC_RCTL_BA_ABTS
: /* basic link service abort */
11610 case FC_RCTL_BA_RMC
: /* remove connection */
11611 case FC_RCTL_BA_ACC
: /* basic accept */
11612 case FC_RCTL_BA_RJT
: /* basic reject */
11613 case FC_RCTL_BA_PRMT
:
11614 case FC_RCTL_ACK_1
: /* acknowledge_1 */
11615 case FC_RCTL_ACK_0
: /* acknowledge_0 */
11616 case FC_RCTL_P_RJT
: /* port reject */
11617 case FC_RCTL_F_RJT
: /* fabric reject */
11618 case FC_RCTL_P_BSY
: /* port busy */
11619 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
11620 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
11621 case FC_RCTL_LCR
: /* link credit reset */
11622 case FC_RCTL_END
: /* end */
11624 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
11625 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
11626 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
11627 return lpfc_fc_frame_check(phba
, fc_hdr
);
11631 switch (fc_hdr
->fh_type
) {
11642 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
11643 "2538 Received frame rctl:%s type:%s\n",
11644 rctl_names
[fc_hdr
->fh_r_ctl
],
11645 type_names
[fc_hdr
->fh_type
]);
11648 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
11649 "2539 Dropped frame rctl:%s type:%s\n",
11650 rctl_names
[fc_hdr
->fh_r_ctl
],
11651 type_names
[fc_hdr
->fh_type
]);
11656 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
11657 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11659 * This function processes the FC header to retrieve the VFI from the VF
11660 * header, if one exists. This function will return the VFI if one exists
11661 * or 0 if no VSAN Header exists.
11664 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
11666 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
11668 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
11670 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
11674 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
11675 * @phba: Pointer to the HBA structure to search for the vport on
11676 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
11677 * @fcfi: The FC Fabric ID that the frame came from
11679 * This function searches the @phba for a vport that matches the content of the
11680 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
11681 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
11682 * returns the matching vport pointer or NULL if unable to match frame to a
11685 static struct lpfc_vport
*
11686 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
11689 struct lpfc_vport
**vports
;
11690 struct lpfc_vport
*vport
= NULL
;
11692 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
11693 fc_hdr
->fh_d_id
[1] << 8 |
11694 fc_hdr
->fh_d_id
[2]);
11696 vports
= lpfc_create_vport_work_array(phba
);
11697 if (vports
!= NULL
)
11698 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
11699 if (phba
->fcf
.fcfi
== fcfi
&&
11700 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
11701 vports
[i
]->fc_myDID
== did
) {
11706 lpfc_destroy_vport_work_array(phba
, vports
);
11711 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
11712 * @vport: The vport to work on.
11714 * This function updates the receive sequence time stamp for this vport. The
11715 * receive sequence time stamp indicates the time that the last frame of the
11716 * the sequence that has been idle for the longest amount of time was received.
11717 * the driver uses this time stamp to indicate if any received sequences have
11721 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
11723 struct lpfc_dmabuf
*h_buf
;
11724 struct hbq_dmabuf
*dmabuf
= NULL
;
11726 /* get the oldest sequence on the rcv list */
11727 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
11728 struct lpfc_dmabuf
, list
);
11731 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11732 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
11736 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
11737 * @vport: The vport that the received sequences were sent to.
11739 * This function cleans up all outstanding received sequences. This is called
11740 * by the driver when a link event or user action invalidates all the received
11744 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
11746 struct lpfc_dmabuf
*h_buf
, *hnext
;
11747 struct lpfc_dmabuf
*d_buf
, *dnext
;
11748 struct hbq_dmabuf
*dmabuf
= NULL
;
11750 /* start with the oldest sequence on the rcv list */
11751 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
11752 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11753 list_del_init(&dmabuf
->hbuf
.list
);
11754 list_for_each_entry_safe(d_buf
, dnext
,
11755 &dmabuf
->dbuf
.list
, list
) {
11756 list_del_init(&d_buf
->list
);
11757 lpfc_in_buf_free(vport
->phba
, d_buf
);
11759 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
11764 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
11765 * @vport: The vport that the received sequences were sent to.
11767 * This function determines whether any received sequences have timed out by
11768 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
11769 * indicates that there is at least one timed out sequence this routine will
11770 * go through the received sequences one at a time from most inactive to most
11771 * active to determine which ones need to be cleaned up. Once it has determined
11772 * that a sequence needs to be cleaned up it will simply free up the resources
11773 * without sending an abort.
11776 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
11778 struct lpfc_dmabuf
*h_buf
, *hnext
;
11779 struct lpfc_dmabuf
*d_buf
, *dnext
;
11780 struct hbq_dmabuf
*dmabuf
= NULL
;
11781 unsigned long timeout
;
11782 int abort_count
= 0;
11784 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
11785 vport
->rcv_buffer_time_stamp
);
11786 if (list_empty(&vport
->rcv_buffer_list
) ||
11787 time_before(jiffies
, timeout
))
11789 /* start with the oldest sequence on the rcv list */
11790 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
11791 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11792 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
11793 dmabuf
->time_stamp
);
11794 if (time_before(jiffies
, timeout
))
11797 list_del_init(&dmabuf
->hbuf
.list
);
11798 list_for_each_entry_safe(d_buf
, dnext
,
11799 &dmabuf
->dbuf
.list
, list
) {
11800 list_del_init(&d_buf
->list
);
11801 lpfc_in_buf_free(vport
->phba
, d_buf
);
11803 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
11806 lpfc_update_rcv_time_stamp(vport
);
11810 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
11811 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
11813 * This function searches through the existing incomplete sequences that have
11814 * been sent to this @vport. If the frame matches one of the incomplete
11815 * sequences then the dbuf in the @dmabuf is added to the list of frames that
11816 * make up that sequence. If no sequence is found that matches this frame then
11817 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
11818 * This function returns a pointer to the first dmabuf in the sequence list that
11819 * the frame was linked to.
11821 static struct hbq_dmabuf
*
11822 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
11824 struct fc_frame_header
*new_hdr
;
11825 struct fc_frame_header
*temp_hdr
;
11826 struct lpfc_dmabuf
*d_buf
;
11827 struct lpfc_dmabuf
*h_buf
;
11828 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
11829 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
11831 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
11832 dmabuf
->time_stamp
= jiffies
;
11833 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11834 /* Use the hdr_buf to find the sequence that this frame belongs to */
11835 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
11836 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
11837 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
11838 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
11839 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
11841 /* found a pending sequence that matches this frame */
11842 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11847 * This indicates first frame received for this sequence.
11848 * Queue the buffer on the vport's rcv_buffer_list.
11850 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11851 lpfc_update_rcv_time_stamp(vport
);
11854 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
11855 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
11856 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
11857 list_del_init(&seq_dmabuf
->hbuf
.list
);
11858 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11859 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
11860 lpfc_update_rcv_time_stamp(vport
);
11863 /* move this sequence to the tail to indicate a young sequence */
11864 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
11865 seq_dmabuf
->time_stamp
= jiffies
;
11866 lpfc_update_rcv_time_stamp(vport
);
11867 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
11868 temp_hdr
= dmabuf
->hbuf
.virt
;
11869 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
11872 /* find the correct place in the sequence to insert this frame */
11873 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
11874 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
11875 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
11877 * If the frame's sequence count is greater than the frame on
11878 * the list then insert the frame right after this frame
11880 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
11881 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
11882 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
11890 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
11891 * @vport: pointer to a vitural port
11892 * @dmabuf: pointer to a dmabuf that describes the FC sequence
11894 * This function tries to abort from the partially assembed sequence, described
11895 * by the information from basic abbort @dmabuf. It checks to see whether such
11896 * partially assembled sequence held by the driver. If so, it shall free up all
11897 * the frames from the partially assembled sequence.
11900 * true -- if there is matching partially assembled sequence present and all
11901 * the frames freed with the sequence;
11902 * false -- if there is no matching partially assembled sequence present so
11903 * nothing got aborted in the lower layer driver
11906 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
11907 struct hbq_dmabuf
*dmabuf
)
11909 struct fc_frame_header
*new_hdr
;
11910 struct fc_frame_header
*temp_hdr
;
11911 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
11912 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
11914 /* Use the hdr_buf to find the sequence that matches this frame */
11915 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
11916 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
11917 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
11918 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
11919 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
11920 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
11921 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
11922 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
11924 /* found a pending sequence that matches this frame */
11925 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
11929 /* Free up all the frames from the partially assembled sequence */
11931 list_for_each_entry_safe(d_buf
, n_buf
,
11932 &seq_dmabuf
->dbuf
.list
, list
) {
11933 list_del_init(&d_buf
->list
);
11934 lpfc_in_buf_free(vport
->phba
, d_buf
);
11942 * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
11943 * @phba: Pointer to HBA context object.
11944 * @cmd_iocbq: pointer to the command iocbq structure.
11945 * @rsp_iocbq: pointer to the response iocbq structure.
11947 * This function handles the sequence abort accept iocb command complete
11948 * event. It properly releases the memory allocated to the sequence abort
11952 lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba
*phba
,
11953 struct lpfc_iocbq
*cmd_iocbq
,
11954 struct lpfc_iocbq
*rsp_iocbq
)
11957 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
11961 * lpfc_sli4_seq_abort_acc - Accept sequence abort
11962 * @phba: Pointer to HBA context object.
11963 * @fc_hdr: pointer to a FC frame header.
11965 * This function sends a basic accept to a previous unsol sequence abort
11966 * event after aborting the sequence handling.
11969 lpfc_sli4_seq_abort_acc(struct lpfc_hba
*phba
,
11970 struct fc_frame_header
*fc_hdr
)
11972 struct lpfc_iocbq
*ctiocb
= NULL
;
11973 struct lpfc_nodelist
*ndlp
;
11974 uint16_t oxid
, rxid
;
11975 uint32_t sid
, fctl
;
11978 if (!lpfc_is_link_up(phba
))
11981 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
11982 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
11983 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
11985 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
11987 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
11988 "1268 Find ndlp returned NULL for oxid:x%x "
11989 "SID:x%x\n", oxid
, sid
);
11992 if (rxid
>= phba
->sli4_hba
.max_cfg_param
.xri_base
11993 && rxid
<= (phba
->sli4_hba
.max_cfg_param
.max_xri
11994 + phba
->sli4_hba
.max_cfg_param
.xri_base
))
11995 lpfc_set_rrq_active(phba
, ndlp
, rxid
, oxid
, 0);
11997 /* Allocate buffer for acc iocb */
11998 ctiocb
= lpfc_sli_get_iocbq(phba
);
12002 /* Extract the F_CTL field from FC_HDR */
12003 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
12005 icmd
= &ctiocb
->iocb
;
12006 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
12007 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
12008 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
12009 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
12010 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
12012 /* Fill in the rest of iocb fields */
12013 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
12014 icmd
->ulpBdeCount
= 0;
12016 icmd
->ulpClass
= CLASS3
;
12017 icmd
->ulpContext
= ndlp
->nlp_rpi
;
12018 ctiocb
->context1
= ndlp
;
12020 ctiocb
->iocb_cmpl
= NULL
;
12021 ctiocb
->vport
= phba
->pport
;
12022 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_acc_cmpl
;
12024 if (fctl
& FC_FC_EX_CTX
) {
12025 /* ABTS sent by responder to CT exchange, construction
12026 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
12027 * field and RX_ID from ABTS for RX_ID field.
12029 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_acc
, LPFC_ABTS_UNSOL_RSP
);
12030 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_acc
, rxid
);
12031 ctiocb
->sli4_xritag
= oxid
;
12033 /* ABTS sent by initiator to CT exchange, construction
12034 * of BA_ACC will need to allocate a new XRI as for the
12035 * XRI_TAG and RX_ID fields.
12037 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_acc
, LPFC_ABTS_UNSOL_INT
);
12038 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_acc
, NO_XRI
);
12039 ctiocb
->sli4_xritag
= NO_XRI
;
12041 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_acc
, oxid
);
12043 /* Xmit CT abts accept on exchange <xid> */
12044 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
12045 "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
12046 CMD_XMIT_BLS_RSP64_CX
, phba
->link_state
);
12047 lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
12051 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
12052 * @vport: Pointer to the vport on which this sequence was received
12053 * @dmabuf: pointer to a dmabuf that describes the FC sequence
12055 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
12056 * receive sequence is only partially assembed by the driver, it shall abort
12057 * the partially assembled frames for the sequence. Otherwise, if the
12058 * unsolicited receive sequence has been completely assembled and passed to
12059 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
12060 * unsolicited sequence has been aborted. After that, it will issue a basic
12061 * accept to accept the abort.
12064 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
12065 struct hbq_dmabuf
*dmabuf
)
12067 struct lpfc_hba
*phba
= vport
->phba
;
12068 struct fc_frame_header fc_hdr
;
12072 /* Make a copy of fc_hdr before the dmabuf being released */
12073 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
12074 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
12076 if (fctl
& FC_FC_EX_CTX
) {
12078 * ABTS sent by responder to exchange, just free the buffer
12080 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
12083 * ABTS sent by initiator to exchange, need to do cleanup
12085 /* Try to abort partially assembled seq */
12086 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
12088 /* Send abort to ULP if partially seq abort failed */
12089 if (abts_par
== false)
12090 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
12092 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
12094 /* Send basic accept (BA_ACC) to the abort requester */
12095 lpfc_sli4_seq_abort_acc(phba
, &fc_hdr
);
12099 * lpfc_seq_complete - Indicates if a sequence is complete
12100 * @dmabuf: pointer to a dmabuf that describes the FC sequence
12102 * This function checks the sequence, starting with the frame described by
12103 * @dmabuf, to see if all the frames associated with this sequence are present.
12104 * the frames associated with this sequence are linked to the @dmabuf using the
12105 * dbuf list. This function looks for two major things. 1) That the first frame
12106 * has a sequence count of zero. 2) There is a frame with last frame of sequence
12107 * set. 3) That there are no holes in the sequence count. The function will
12108 * return 1 when the sequence is complete, otherwise it will return 0.
12111 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
12113 struct fc_frame_header
*hdr
;
12114 struct lpfc_dmabuf
*d_buf
;
12115 struct hbq_dmabuf
*seq_dmabuf
;
12119 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
12120 /* make sure first fame of sequence has a sequence count of zero */
12121 if (hdr
->fh_seq_cnt
!= seq_count
)
12123 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
12124 hdr
->fh_f_ctl
[1] << 8 |
12126 /* If last frame of sequence we can return success. */
12127 if (fctl
& FC_FC_END_SEQ
)
12129 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
12130 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
12131 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
12132 /* If there is a hole in the sequence count then fail. */
12133 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
12135 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
12136 hdr
->fh_f_ctl
[1] << 8 |
12138 /* If last frame of sequence we can return success. */
12139 if (fctl
& FC_FC_END_SEQ
)
12146 * lpfc_prep_seq - Prep sequence for ULP processing
12147 * @vport: Pointer to the vport on which this sequence was received
12148 * @dmabuf: pointer to a dmabuf that describes the FC sequence
12150 * This function takes a sequence, described by a list of frames, and creates
12151 * a list of iocbq structures to describe the sequence. This iocbq list will be
12152 * used to issue to the generic unsolicited sequence handler. This routine
12153 * returns a pointer to the first iocbq in the list. If the function is unable
12154 * to allocate an iocbq then it throw out the received frames that were not
12155 * able to be described and return a pointer to the first iocbq. If unable to
12156 * allocate any iocbqs (including the first) this function will return NULL.
12158 static struct lpfc_iocbq
*
12159 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
12161 struct lpfc_dmabuf
*d_buf
, *n_buf
;
12162 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
12163 struct fc_frame_header
*fc_hdr
;
12165 struct ulp_bde64
*pbde
;
12167 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
12168 /* remove from receive buffer list */
12169 list_del_init(&seq_dmabuf
->hbuf
.list
);
12170 lpfc_update_rcv_time_stamp(vport
);
12171 /* get the Remote Port's SID */
12172 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
12173 /* Get an iocbq struct to fill in. */
12174 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
12176 /* Initialize the first IOCB. */
12177 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
12178 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
12179 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
12180 first_iocbq
->iocb
.ulpContext
= be16_to_cpu(fc_hdr
->fh_ox_id
);
12181 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
12182 vport
->vpi
+ vport
->phba
->vpi_base
;
12183 /* put the first buffer into the first IOCBq */
12184 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
12185 first_iocbq
->context3
= NULL
;
12186 first_iocbq
->iocb
.ulpBdeCount
= 1;
12187 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
12188 LPFC_DATA_BUF_SIZE
;
12189 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
12190 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
12191 bf_get(lpfc_rcqe_length
,
12192 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
12194 iocbq
= first_iocbq
;
12196 * Each IOCBq can have two Buffers assigned, so go through the list
12197 * of buffers for this sequence and save two buffers in each IOCBq
12199 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
12201 lpfc_in_buf_free(vport
->phba
, d_buf
);
12204 if (!iocbq
->context3
) {
12205 iocbq
->context3
= d_buf
;
12206 iocbq
->iocb
.ulpBdeCount
++;
12207 pbde
= (struct ulp_bde64
*)
12208 &iocbq
->iocb
.unsli3
.sli3Words
[4];
12209 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
12210 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
12211 bf_get(lpfc_rcqe_length
,
12212 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
12214 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
12217 first_iocbq
->iocb
.ulpStatus
=
12218 IOSTAT_FCP_RSP_ERROR
;
12219 first_iocbq
->iocb
.un
.ulpWord
[4] =
12220 IOERR_NO_RESOURCES
;
12222 lpfc_in_buf_free(vport
->phba
, d_buf
);
12225 iocbq
->context2
= d_buf
;
12226 iocbq
->context3
= NULL
;
12227 iocbq
->iocb
.ulpBdeCount
= 1;
12228 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
12229 LPFC_DATA_BUF_SIZE
;
12230 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+=
12231 bf_get(lpfc_rcqe_length
,
12232 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
12233 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
12234 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
12237 return first_iocbq
;
12241 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
12242 struct hbq_dmabuf
*seq_dmabuf
)
12244 struct fc_frame_header
*fc_hdr
;
12245 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
12246 struct lpfc_hba
*phba
= vport
->phba
;
12248 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
12249 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
12251 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12252 "2707 Ring %d handler: Failed to allocate "
12253 "iocb Rctl x%x Type x%x received\n",
12255 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
12258 if (!lpfc_complete_unsol_iocb(phba
,
12259 &phba
->sli
.ring
[LPFC_ELS_RING
],
12260 iocbq
, fc_hdr
->fh_r_ctl
,
12262 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12263 "2540 Ring %d handler: unexpected Rctl "
12264 "x%x Type x%x received\n",
12266 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
12268 /* Free iocb created in lpfc_prep_seq */
12269 list_for_each_entry_safe(curr_iocb
, next_iocb
,
12270 &iocbq
->list
, list
) {
12271 list_del_init(&curr_iocb
->list
);
12272 lpfc_sli_release_iocbq(phba
, curr_iocb
);
12274 lpfc_sli_release_iocbq(phba
, iocbq
);
12278 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
12279 * @phba: Pointer to HBA context object.
12281 * This function is called with no lock held. This function processes all
12282 * the received buffers and gives it to upper layers when a received buffer
12283 * indicates that it is the final frame in the sequence. The interrupt
12284 * service routine processes received buffers at interrupt contexts and adds
12285 * received dma buffers to the rb_pend_list queue and signals the worker thread.
12286 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
12287 * appropriate receive function when the final frame in a sequence is received.
12290 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
12291 struct hbq_dmabuf
*dmabuf
)
12293 struct hbq_dmabuf
*seq_dmabuf
;
12294 struct fc_frame_header
*fc_hdr
;
12295 struct lpfc_vport
*vport
;
12298 /* Process each received buffer */
12299 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
12300 /* check to see if this a valid type of frame */
12301 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
12302 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
12305 fcfi
= bf_get(lpfc_rcqe_fcf_id
, &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
12306 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
12307 if (!vport
|| !(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
12308 /* throw out the frame */
12309 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
12312 /* Handle the basic abort sequence (BA_ABTS) event */
12313 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
12314 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
12318 /* Link this frame */
12319 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
12321 /* unable to add frame to vport - throw it out */
12322 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
12325 /* If not last frame in sequence continue processing frames. */
12326 if (!lpfc_seq_complete(seq_dmabuf
))
12329 /* Send the complete sequence to the upper layer protocol */
12330 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
12334 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
12335 * @phba: pointer to lpfc hba data structure.
12337 * This routine is invoked to post rpi header templates to the
12338 * HBA consistent with the SLI-4 interface spec. This routine
12339 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
12340 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
12342 * This routine does not require any locks. It's usage is expected
12343 * to be driver load or reset recovery when the driver is
12348 * -EIO - The mailbox failed to complete successfully.
12349 * When this error occurs, the driver is not guaranteed
12350 * to have any rpi regions posted to the device and
12351 * must either attempt to repost the regions or take a
12355 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
12357 struct lpfc_rpi_hdr
*rpi_page
;
12360 /* Post all rpi memory regions to the port. */
12361 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
12362 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
12363 if (rc
!= MBX_SUCCESS
) {
12364 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12365 "2008 Error %d posting all rpi "
12376 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
12377 * @phba: pointer to lpfc hba data structure.
12378 * @rpi_page: pointer to the rpi memory region.
12380 * This routine is invoked to post a single rpi header to the
12381 * HBA consistent with the SLI-4 interface spec. This memory region
12382 * maps up to 64 rpi context regions.
12386 * -ENOMEM - No available memory
12387 * -EIO - The mailbox failed to complete successfully.
12390 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
12392 LPFC_MBOXQ_t
*mboxq
;
12393 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
12396 uint32_t shdr_status
, shdr_add_status
;
12397 union lpfc_sli4_cfg_shdr
*shdr
;
12399 /* The port is notified of the header region via a mailbox command. */
12400 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12402 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12403 "2001 Unable to allocate memory for issuing "
12404 "SLI_CONFIG_SPECIAL mailbox command\n");
12408 /* Post all rpi memory regions to the port. */
12409 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
12410 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
12411 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12412 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
12413 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
12414 sizeof(struct mbox_header
), LPFC_SLI4_MBX_EMBED
);
12415 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
12416 hdr_tmpl
, rpi_page
->page_count
);
12417 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
12418 rpi_page
->start_rpi
);
12419 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
12420 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
12421 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
12422 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
12423 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12424 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12425 if (rc
!= MBX_TIMEOUT
)
12426 mempool_free(mboxq
, phba
->mbox_mem_pool
);
12427 if (shdr_status
|| shdr_add_status
|| rc
) {
12428 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12429 "2514 POST_RPI_HDR mailbox failed with "
12430 "status x%x add_status x%x, mbx status x%x\n",
12431 shdr_status
, shdr_add_status
, rc
);
12438 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
12439 * @phba: pointer to lpfc hba data structure.
12441 * This routine is invoked to post rpi header templates to the
12442 * HBA consistent with the SLI-4 interface spec. This routine
12443 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
12444 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
12447 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
12448 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
12451 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
12454 uint16_t max_rpi
, rpi_base
, rpi_limit
;
12455 uint16_t rpi_remaining
;
12456 struct lpfc_rpi_hdr
*rpi_hdr
;
12458 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
12459 rpi_base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
12460 rpi_limit
= phba
->sli4_hba
.next_rpi
;
12463 * The valid rpi range is not guaranteed to be zero-based. Start
12464 * the search at the rpi_base as reported by the port.
12466 spin_lock_irq(&phba
->hbalock
);
12467 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, rpi_base
);
12468 if (rpi
>= rpi_limit
|| rpi
< rpi_base
)
12469 rpi
= LPFC_RPI_ALLOC_ERROR
;
12471 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
12472 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
12473 phba
->sli4_hba
.rpi_count
++;
12477 * Don't try to allocate more rpi header regions if the device limit
12478 * on available rpis max has been exhausted.
12480 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
12481 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
12482 spin_unlock_irq(&phba
->hbalock
);
12487 * If the driver is running low on rpi resources, allocate another
12488 * page now. Note that the next_rpi value is used because
12489 * it represents how many are actually in use whereas max_rpi notes
12490 * how many are supported max by the device.
12492 rpi_remaining
= phba
->sli4_hba
.next_rpi
- rpi_base
-
12493 phba
->sli4_hba
.rpi_count
;
12494 spin_unlock_irq(&phba
->hbalock
);
12495 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
12496 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
12498 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12499 "2002 Error Could not grow rpi "
12502 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
12510 * lpfc_sli4_free_rpi - Release an rpi for reuse.
12511 * @phba: pointer to lpfc hba data structure.
12513 * This routine is invoked to release an rpi to the pool of
12514 * available rpis maintained by the driver.
12517 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
12519 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
12520 phba
->sli4_hba
.rpi_count
--;
12521 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
12526 * lpfc_sli4_free_rpi - Release an rpi for reuse.
12527 * @phba: pointer to lpfc hba data structure.
12529 * This routine is invoked to release an rpi to the pool of
12530 * available rpis maintained by the driver.
12533 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
12535 spin_lock_irq(&phba
->hbalock
);
12536 __lpfc_sli4_free_rpi(phba
, rpi
);
12537 spin_unlock_irq(&phba
->hbalock
);
12541 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
12542 * @phba: pointer to lpfc hba data structure.
12544 * This routine is invoked to remove the memory region that
12545 * provided rpi via a bitmask.
12548 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
12550 kfree(phba
->sli4_hba
.rpi_bmask
);
12554 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
12555 * @phba: pointer to lpfc hba data structure.
12557 * This routine is invoked to remove the memory region that
12558 * provided rpi via a bitmask.
12561 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
)
12563 LPFC_MBOXQ_t
*mboxq
;
12564 struct lpfc_hba
*phba
= ndlp
->phba
;
12567 /* The port is notified of the header region via a mailbox command. */
12568 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12572 /* Post all rpi memory regions to the port. */
12573 lpfc_resume_rpi(mboxq
, ndlp
);
12574 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12575 if (rc
== MBX_NOT_FINISHED
) {
12576 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12577 "2010 Resume RPI Mailbox failed "
12578 "status %d, mbxStatus x%x\n", rc
,
12579 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
12580 mempool_free(mboxq
, phba
->mbox_mem_pool
);
12587 * lpfc_sli4_init_vpi - Initialize a vpi with the port
12588 * @vport: Pointer to the vport for which the vpi is being initialized
12590 * This routine is invoked to activate a vpi with the port.
12594 * -Evalue otherwise
12597 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
12599 LPFC_MBOXQ_t
*mboxq
;
12601 int retval
= MBX_SUCCESS
;
12603 struct lpfc_hba
*phba
= vport
->phba
;
12604 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12607 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
12608 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_INIT_VPI
);
12609 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
12610 if (rc
!= MBX_SUCCESS
) {
12611 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
12612 "2022 INIT VPI Mailbox failed "
12613 "status %d, mbxStatus x%x\n", rc
,
12614 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
12617 if (rc
!= MBX_TIMEOUT
)
12618 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
12624 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
12625 * @phba: pointer to lpfc hba data structure.
12626 * @mboxq: Pointer to mailbox object.
12628 * This routine is invoked to manually add a single FCF record. The caller
12629 * must pass a completely initialized FCF_Record. This routine takes
12630 * care of the nonembedded mailbox operations.
12633 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
12636 union lpfc_sli4_cfg_shdr
*shdr
;
12637 uint32_t shdr_status
, shdr_add_status
;
12639 virt_addr
= mboxq
->sge_array
->addr
[0];
12640 /* The IOCTL status is embedded in the mailbox subheader. */
12641 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
12642 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12643 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12645 if ((shdr_status
|| shdr_add_status
) &&
12646 (shdr_status
!= STATUS_FCF_IN_USE
))
12647 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12648 "2558 ADD_FCF_RECORD mailbox failed with "
12649 "status x%x add_status x%x\n",
12650 shdr_status
, shdr_add_status
);
12652 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12656 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
12657 * @phba: pointer to lpfc hba data structure.
12658 * @fcf_record: pointer to the initialized fcf record to add.
12660 * This routine is invoked to manually add a single FCF record. The caller
12661 * must pass a completely initialized FCF_Record. This routine takes
12662 * care of the nonembedded mailbox operations.
12665 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
12668 LPFC_MBOXQ_t
*mboxq
;
12671 dma_addr_t phys_addr
;
12672 struct lpfc_mbx_sge sge
;
12673 uint32_t alloc_len
, req_len
;
12676 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12678 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12679 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
12683 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
12686 /* Allocate DMA memory and set up the non-embedded mailbox command */
12687 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12688 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
12689 req_len
, LPFC_SLI4_MBX_NEMBED
);
12690 if (alloc_len
< req_len
) {
12691 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12692 "2523 Allocated DMA memory size (x%x) is "
12693 "less than the requested DMA memory "
12694 "size (x%x)\n", alloc_len
, req_len
);
12695 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12700 * Get the first SGE entry from the non-embedded DMA memory. This
12701 * routine only uses a single SGE.
12703 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
12704 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
12705 virt_addr
= mboxq
->sge_array
->addr
[0];
12707 * Configure the FCF record for FCFI 0. This is the driver's
12708 * hardcoded default and gets used in nonFIP mode.
12710 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
12711 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
12712 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
12715 * Copy the fcf_index and the FCF Record Data. The data starts after
12716 * the FCoE header plus word10. The data copy needs to be endian
12719 bytep
+= sizeof(uint32_t);
12720 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
12721 mboxq
->vport
= phba
->pport
;
12722 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
12723 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12724 if (rc
== MBX_NOT_FINISHED
) {
12725 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12726 "2515 ADD_FCF_RECORD mailbox failed with "
12727 "status 0x%x\n", rc
);
12728 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12737 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
12738 * @phba: pointer to lpfc hba data structure.
12739 * @fcf_record: pointer to the fcf record to write the default data.
12740 * @fcf_index: FCF table entry index.
12742 * This routine is invoked to build the driver's default FCF record. The
12743 * values used are hardcoded. This routine handles memory initialization.
12747 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
12748 struct fcf_record
*fcf_record
,
12749 uint16_t fcf_index
)
12751 memset(fcf_record
, 0, sizeof(struct fcf_record
));
12752 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
12753 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
12754 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
12755 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
12756 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
12757 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
12758 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
12759 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
12760 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
12761 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
12762 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
12763 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
12764 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
12765 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
12766 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
12767 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
12768 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
12769 /* Set the VLAN bit map */
12770 if (phba
->valid_vlan
) {
12771 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
12772 = 1 << (phba
->vlan_id
% 8);
12777 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
12778 * @phba: pointer to lpfc hba data structure.
12779 * @fcf_index: FCF table entry offset.
12781 * This routine is invoked to scan the entire FCF table by reading FCF
12782 * record and processing it one at a time starting from the @fcf_index
12783 * for initial FCF discovery or fast FCF failover rediscovery.
12785 * Return 0 if the mailbox command is submitted sucessfully, none 0
12789 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12792 LPFC_MBOXQ_t
*mboxq
;
12794 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
12795 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12797 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12798 "2000 Failed to allocate mbox for "
12801 goto fail_fcf_scan
;
12803 /* Construct the read FCF record mailbox command */
12804 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12807 goto fail_fcf_scan
;
12809 /* Issue the mailbox command asynchronously */
12810 mboxq
->vport
= phba
->pport
;
12811 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
12813 spin_lock_irq(&phba
->hbalock
);
12814 phba
->hba_flag
|= FCF_TS_INPROG
;
12815 spin_unlock_irq(&phba
->hbalock
);
12817 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12818 if (rc
== MBX_NOT_FINISHED
)
12821 /* Reset eligible FCF count for new scan */
12822 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
12823 phba
->fcf
.eligible_fcf_cnt
= 0;
12829 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12830 /* FCF scan failed, clear FCF_TS_INPROG flag */
12831 spin_lock_irq(&phba
->hbalock
);
12832 phba
->hba_flag
&= ~FCF_TS_INPROG
;
12833 spin_unlock_irq(&phba
->hbalock
);
12839 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
12840 * @phba: pointer to lpfc hba data structure.
12841 * @fcf_index: FCF table entry offset.
12843 * This routine is invoked to read an FCF record indicated by @fcf_index
12844 * and to use it for FLOGI roundrobin FCF failover.
12846 * Return 0 if the mailbox command is submitted sucessfully, none 0
12850 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12853 LPFC_MBOXQ_t
*mboxq
;
12855 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12857 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
12858 "2763 Failed to allocate mbox for "
12861 goto fail_fcf_read
;
12863 /* Construct the read FCF record mailbox command */
12864 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12867 goto fail_fcf_read
;
12869 /* Issue the mailbox command asynchronously */
12870 mboxq
->vport
= phba
->pport
;
12871 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
12872 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12873 if (rc
== MBX_NOT_FINISHED
)
12879 if (error
&& mboxq
)
12880 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12885 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
12886 * @phba: pointer to lpfc hba data structure.
12887 * @fcf_index: FCF table entry offset.
12889 * This routine is invoked to read an FCF record indicated by @fcf_index to
12890 * determine whether it's eligible for FLOGI roundrobin failover list.
12892 * Return 0 if the mailbox command is submitted sucessfully, none 0
12896 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12899 LPFC_MBOXQ_t
*mboxq
;
12901 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12903 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
12904 "2758 Failed to allocate mbox for "
12907 goto fail_fcf_read
;
12909 /* Construct the read FCF record mailbox command */
12910 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
12913 goto fail_fcf_read
;
12915 /* Issue the mailbox command asynchronously */
12916 mboxq
->vport
= phba
->pport
;
12917 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
12918 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
12919 if (rc
== MBX_NOT_FINISHED
)
12925 if (error
&& mboxq
)
12926 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
12931 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
12932 * @phba: pointer to lpfc hba data structure.
12934 * This routine is to get the next eligible FCF record index in a round
12935 * robin fashion. If the next eligible FCF record index equals to the
12936 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
12937 * shall be returned, otherwise, the next eligible FCF record's index
12938 * shall be returned.
12941 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
12943 uint16_t next_fcf_index
;
12945 /* Search start from next bit of currently registered FCF index */
12946 next_fcf_index
= (phba
->fcf
.current_rec
.fcf_indx
+ 1) %
12947 LPFC_SLI4_FCF_TBL_INDX_MAX
;
12948 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
12949 LPFC_SLI4_FCF_TBL_INDX_MAX
,
12952 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
12953 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
12954 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
12955 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
12957 /* Check roundrobin failover list empty condition */
12958 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
12959 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
12960 "2844 No roundrobin failover FCF available\n");
12961 return LPFC_FCOE_FCF_NEXT_NONE
;
12964 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
12965 "2845 Get next roundrobin failover FCF (x%x)\n",
12968 return next_fcf_index
;
12972 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
12973 * @phba: pointer to lpfc hba data structure.
12975 * This routine sets the FCF record index in to the eligible bmask for
12976 * roundrobin failover search. It checks to make sure that the index
12977 * does not go beyond the range of the driver allocated bmask dimension
12978 * before setting the bit.
12980 * Returns 0 if the index bit successfully set, otherwise, it returns
12984 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
12986 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
12987 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
12988 "2610 FCF (x%x) reached driver's book "
12989 "keeping dimension:x%x\n",
12990 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
12993 /* Set the eligible FCF record index bmask */
12994 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
12996 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
12997 "2790 Set FCF (x%x) to roundrobin FCF failover "
12998 "bmask\n", fcf_index
);
13004 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
13005 * @phba: pointer to lpfc hba data structure.
13007 * This routine clears the FCF record index from the eligible bmask for
13008 * roundrobin failover search. It checks to make sure that the index
13009 * does not go beyond the range of the driver allocated bmask dimension
13010 * before clearing the bit.
13013 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
13015 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
13016 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
13017 "2762 FCF (x%x) reached driver's book "
13018 "keeping dimension:x%x\n",
13019 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
13022 /* Clear the eligible FCF record index bmask */
13023 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
13025 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
13026 "2791 Clear FCF (x%x) from roundrobin failover "
13027 "bmask\n", fcf_index
);
13031 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
13032 * @phba: pointer to lpfc hba data structure.
13034 * This routine is the completion routine for the rediscover FCF table mailbox
13035 * command. If the mailbox command returned failure, it will try to stop the
13036 * FCF rediscover wait timer.
13039 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
13041 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
13042 uint32_t shdr_status
, shdr_add_status
;
13044 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
13046 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
13047 &redisc_fcf
->header
.cfg_shdr
.response
);
13048 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
13049 &redisc_fcf
->header
.cfg_shdr
.response
);
13050 if (shdr_status
|| shdr_add_status
) {
13051 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
13052 "2746 Requesting for FCF rediscovery failed "
13053 "status x%x add_status x%x\n",
13054 shdr_status
, shdr_add_status
);
13055 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
13056 spin_lock_irq(&phba
->hbalock
);
13057 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
13058 spin_unlock_irq(&phba
->hbalock
);
13060 * CVL event triggered FCF rediscover request failed,
13061 * last resort to re-try current registered FCF entry.
13063 lpfc_retry_pport_discovery(phba
);
13065 spin_lock_irq(&phba
->hbalock
);
13066 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
13067 spin_unlock_irq(&phba
->hbalock
);
13069 * DEAD FCF event triggered FCF rediscover request
13070 * failed, last resort to fail over as a link down
13071 * to FCF registration.
13073 lpfc_sli4_fcf_dead_failthrough(phba
);
13076 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
13077 "2775 Start FCF rediscover quiescent timer\n");
13079 * Start FCF rediscovery wait timer for pending FCF
13080 * before rescan FCF record table.
13082 lpfc_fcf_redisc_wait_start_timer(phba
);
13085 mempool_free(mbox
, phba
->mbox_mem_pool
);
13089 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
13090 * @phba: pointer to lpfc hba data structure.
13092 * This routine is invoked to request for rediscovery of the entire FCF table
13096 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
13098 LPFC_MBOXQ_t
*mbox
;
13099 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
13102 /* Cancel retry delay timers to all vports before FCF rediscover */
13103 lpfc_cancel_all_vport_retry_delay_timer(phba
);
13105 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13107 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13108 "2745 Failed to allocate mbox for "
13109 "requesting FCF rediscover.\n");
13113 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
13114 sizeof(struct lpfc_sli4_cfg_mhdr
));
13115 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13116 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
13117 length
, LPFC_SLI4_MBX_EMBED
);
13119 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
13120 /* Set count to 0 for invalidating the entire FCF database */
13121 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
13123 /* Issue the mailbox command asynchronously */
13124 mbox
->vport
= phba
->pport
;
13125 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
13126 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
13128 if (rc
== MBX_NOT_FINISHED
) {
13129 mempool_free(mbox
, phba
->mbox_mem_pool
);
13136 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
13137 * @phba: pointer to lpfc hba data structure.
13139 * This function is the failover routine as a last resort to the FCF DEAD
13140 * event when driver failed to perform fast FCF failover.
13143 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
13145 uint32_t link_state
;
13148 * Last resort as FCF DEAD event failover will treat this as
13149 * a link down, but save the link state because we don't want
13150 * it to be changed to Link Down unless it is already down.
13152 link_state
= phba
->link_state
;
13153 lpfc_linkdown(phba
);
13154 phba
->link_state
= link_state
;
13156 /* Unregister FCF if no devices connected to it */
13157 lpfc_unregister_unused_fcf(phba
);
13161 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
13162 * @phba: pointer to lpfc hba data structure.
13164 * This function read region 23 and parse TLV for port status to
13165 * decide if the user disaled the port. If the TLV indicates the
13166 * port is disabled, the hba_flag is set accordingly.
13169 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
13171 LPFC_MBOXQ_t
*pmb
= NULL
;
13173 uint8_t *rgn23_data
= NULL
;
13174 uint32_t offset
= 0, data_size
, sub_tlv_len
, tlv_offset
;
13177 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13179 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13180 "2600 lpfc_sli_read_serdes_param failed to"
13181 " allocate mailbox memory\n");
13186 /* Get adapter Region 23 data */
13187 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
13192 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
13193 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
13195 if (rc
!= MBX_SUCCESS
) {
13196 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13197 "2601 lpfc_sli_read_link_ste failed to"
13198 " read config region 23 rc 0x%x Status 0x%x\n",
13199 rc
, mb
->mbxStatus
);
13200 mb
->un
.varDmp
.word_cnt
= 0;
13203 * dump mem may return a zero when finished or we got a
13204 * mailbox error, either way we are done.
13206 if (mb
->un
.varDmp
.word_cnt
== 0)
13208 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
13209 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
13211 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
13212 rgn23_data
+ offset
,
13213 mb
->un
.varDmp
.word_cnt
);
13214 offset
+= mb
->un
.varDmp
.word_cnt
;
13215 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
13217 data_size
= offset
;
13223 /* Check the region signature first */
13224 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
13225 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13226 "2619 Config region 23 has bad signature\n");
13231 /* Check the data structure version */
13232 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
13233 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13234 "2620 Config region 23 has bad version\n");
13239 /* Parse TLV entries in the region */
13240 while (offset
< data_size
) {
13241 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
13244 * If the TLV is not driver specific TLV or driver id is
13245 * not linux driver id, skip the record.
13247 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
13248 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
13249 (rgn23_data
[offset
+ 3] != 0)) {
13250 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
13254 /* Driver found a driver specific TLV in the config region */
13255 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
13260 * Search for configured port state sub-TLV.
13262 while ((offset
< data_size
) &&
13263 (tlv_offset
< sub_tlv_len
)) {
13264 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
13269 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
13270 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
13271 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
13275 /* This HBA contains PORT_STE configured */
13276 if (!rgn23_data
[offset
+ 2])
13277 phba
->hba_flag
|= LINK_DISABLED
;
13284 mempool_free(pmb
, phba
->mbox_mem_pool
);
13290 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
13291 * @vport: pointer to vport data structure.
13293 * This function iterate through the mailboxq and clean up all REG_LOGIN
13294 * and REG_VPI mailbox commands associated with the vport. This function
13295 * is called when driver want to restart discovery of the vport due to
13296 * a Clear Virtual Link event.
13299 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
13301 struct lpfc_hba
*phba
= vport
->phba
;
13302 LPFC_MBOXQ_t
*mb
, *nextmb
;
13303 struct lpfc_dmabuf
*mp
;
13304 struct lpfc_nodelist
*ndlp
;
13305 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
13306 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
13307 LIST_HEAD(mbox_cmd_list
);
13308 uint8_t restart_loop
;
13310 /* Clean up internally queued mailbox commands with the vport */
13311 spin_lock_irq(&phba
->hbalock
);
13312 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
13313 if (mb
->vport
!= vport
)
13316 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
13317 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
13320 list_del(&mb
->list
);
13321 list_add_tail(&mb
->list
, &mbox_cmd_list
);
13323 /* Clean up active mailbox command with the vport */
13324 mb
= phba
->sli
.mbox_active
;
13325 if (mb
&& (mb
->vport
== vport
)) {
13326 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
13327 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
13328 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13329 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
13330 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
13331 /* Put reference count for delayed processing */
13332 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
13333 /* Unregister the RPI when mailbox complete */
13334 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
13337 /* Cleanup any mailbox completions which are not yet processed */
13340 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
13342 * If this mailox is already processed or it is
13343 * for another vport ignore it.
13345 if ((mb
->vport
!= vport
) ||
13346 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
13349 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
13350 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
13353 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13354 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
13355 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
13356 /* Unregister the RPI when mailbox complete */
13357 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
13359 spin_unlock_irq(&phba
->hbalock
);
13360 spin_lock(shost
->host_lock
);
13361 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
13362 spin_unlock(shost
->host_lock
);
13363 spin_lock_irq(&phba
->hbalock
);
13367 } while (restart_loop
);
13369 spin_unlock_irq(&phba
->hbalock
);
13371 /* Release the cleaned-up mailbox commands */
13372 while (!list_empty(&mbox_cmd_list
)) {
13373 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
13374 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
13375 if (phba
->sli_rev
== LPFC_SLI_REV4
)
13376 __lpfc_sli4_free_rpi(phba
,
13377 mb
->u
.mb
.un
.varRegLogin
.rpi
);
13378 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
13380 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
13383 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
13384 mb
->context2
= NULL
;
13386 spin_lock(shost
->host_lock
);
13387 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
13388 spin_unlock(shost
->host_lock
);
13389 lpfc_nlp_put(ndlp
);
13392 mempool_free(mb
, phba
->mbox_mem_pool
);
13395 /* Release the ndlp with the cleaned-up active mailbox command */
13396 if (act_mbx_ndlp
) {
13397 spin_lock(shost
->host_lock
);
13398 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
13399 spin_unlock(shost
->host_lock
);
13400 lpfc_nlp_put(act_mbx_ndlp
);
13405 * lpfc_drain_txq - Drain the txq
13406 * @phba: Pointer to HBA context object.
13408 * This function attempt to submit IOCBs on the txq
13409 * to the adapter. For SLI4 adapters, the txq contains
13410 * ELS IOCBs that have been deferred because the there
13411 * are no SGLs. This congestion can occur with large
13412 * vport counts during node discovery.
13416 lpfc_drain_txq(struct lpfc_hba
*phba
)
13418 LIST_HEAD(completions
);
13419 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
13420 struct lpfc_iocbq
*piocbq
= 0;
13421 unsigned long iflags
= 0;
13422 char *fail_msg
= NULL
;
13423 struct lpfc_sglq
*sglq
;
13424 union lpfc_wqe wqe
;
13426 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13427 if (pring
->txq_cnt
> pring
->txq_max
)
13428 pring
->txq_max
= pring
->txq_cnt
;
13430 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13432 while (pring
->txq_cnt
) {
13433 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13435 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
13436 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
13438 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
13439 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13443 /* The txq_cnt out of sync. This should
13446 sglq
= __lpfc_clear_active_sglq(phba
,
13447 sglq
->sli4_xritag
);
13448 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13449 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13450 "2823 txq empty and txq_cnt is %d\n ",
13456 /* The xri and iocb resources secured,
13457 * attempt to issue request
13459 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
13460 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
13461 fail_msg
= "to convert bpl to sgl";
13462 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
13463 fail_msg
= "to convert iocb to wqe";
13464 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
13465 fail_msg
= " - Wq is full";
13467 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
13470 /* Failed means we can't issue and need to cancel */
13471 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13472 "2822 IOCB failed %s iotag 0x%x "
13475 piocbq
->iotag
, piocbq
->sli4_xritag
);
13476 list_add_tail(&piocbq
->list
, &completions
);
13478 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13481 /* Cancel all the IOCBs that cannot be issued */
13482 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
13483 IOERR_SLI_ABORTED
);
13485 return pring
->txq_cnt
;