1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 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
*,
68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*, struct lpfc_queue
*,
72 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
78 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
79 * @q: The Work Queue to operate on.
80 * @wqe: The work Queue Entry to put on the Work queue.
82 * This routine will copy the contents of @wqe to the next available entry on
83 * the @q. This function will then ring the Work Queue Doorbell to signal the
84 * HBA to start processing the Work Queue Entry. This function returns 0 if
85 * successful. If no entries are available on @q then this function will return
87 * The caller is expected to hold the hbalock when calling this routine.
90 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
92 union lpfc_wqe
*temp_wqe
;
93 struct lpfc_register doorbell
;
96 /* sanity check on queue memory */
99 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
101 /* If the host has not yet processed the next entry then we are done */
102 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
104 /* set consumption flag every once in a while */
105 if (!((q
->host_index
+ 1) % q
->entry_repost
))
106 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
107 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
108 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
109 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
111 /* Update the host index before invoking device */
112 host_index
= q
->host_index
;
113 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
117 bf_set(lpfc_wq_doorbell_num_posted
, &doorbell
, 1);
118 bf_set(lpfc_wq_doorbell_index
, &doorbell
, host_index
);
119 bf_set(lpfc_wq_doorbell_id
, &doorbell
, q
->queue_id
);
120 writel(doorbell
.word0
, q
->phba
->sli4_hba
.WQDBregaddr
);
121 readl(q
->phba
->sli4_hba
.WQDBregaddr
); /* Flush */
127 * lpfc_sli4_wq_release - Updates internal hba index for WQ
128 * @q: The Work Queue to operate on.
129 * @index: The index to advance the hba index to.
131 * This routine will update the HBA index of a queue to reflect consumption of
132 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
133 * an entry the host calls this function to update the queue's internal
134 * pointers. This routine returns the number of entries that were consumed by
138 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
140 uint32_t released
= 0;
142 /* sanity check on queue memory */
146 if (q
->hba_index
== index
)
149 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
151 } while (q
->hba_index
!= index
);
156 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
157 * @q: The Mailbox Queue to operate on.
158 * @wqe: The Mailbox Queue Entry to put on the Work queue.
160 * This routine will copy the contents of @mqe to the next available entry on
161 * the @q. This function will then ring the Work Queue Doorbell to signal the
162 * HBA to start processing the Work Queue Entry. This function returns 0 if
163 * successful. If no entries are available on @q then this function will return
165 * The caller is expected to hold the hbalock when calling this routine.
168 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
170 struct lpfc_mqe
*temp_mqe
;
171 struct lpfc_register doorbell
;
174 /* sanity check on queue memory */
177 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
179 /* If the host has not yet processed the next entry then we are done */
180 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
182 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
183 /* Save off the mailbox pointer for completion */
184 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
186 /* Update the host index before invoking device */
187 host_index
= q
->host_index
;
188 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
192 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
193 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
194 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
195 readl(q
->phba
->sli4_hba
.MQDBregaddr
); /* Flush */
200 * lpfc_sli4_mq_release - Updates internal hba index for MQ
201 * @q: The Mailbox Queue to operate on.
203 * This routine will update the HBA index of a queue to reflect consumption of
204 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
205 * an entry the host calls this function to update the queue's internal
206 * pointers. This routine returns the number of entries that were consumed by
210 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
212 /* sanity check on queue memory */
216 /* Clear the mailbox pointer for completion */
217 q
->phba
->mbox
= NULL
;
218 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
223 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
224 * @q: The Event Queue to get the first valid EQE from
226 * This routine will get the first valid Event Queue Entry from @q, update
227 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
228 * the Queue (no more work to do), or the Queue is full of EQEs that have been
229 * processed, but not popped back to the HBA then this routine will return NULL.
231 static struct lpfc_eqe
*
232 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
234 struct lpfc_eqe
*eqe
;
236 /* sanity check on queue memory */
239 eqe
= q
->qe
[q
->hba_index
].eqe
;
241 /* If the next EQE is not valid then we are done */
242 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
244 /* If the host has not yet processed the next entry then we are done */
245 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
248 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
253 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
254 * @q: The Event Queue that the host has completed processing for.
255 * @arm: Indicates whether the host wants to arms this CQ.
257 * This routine will mark all Event Queue Entries on @q, from the last
258 * known completed entry to the last entry that was processed, as completed
259 * by clearing the valid bit for each completion queue entry. Then it will
260 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
261 * The internal host index in the @q will be updated by this routine to indicate
262 * that the host has finished processing the entries. The @arm parameter
263 * indicates that the queue should be rearmed when ringing the doorbell.
265 * This function will return the number of EQEs that were popped.
268 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
270 uint32_t released
= 0;
271 struct lpfc_eqe
*temp_eqe
;
272 struct lpfc_register doorbell
;
274 /* sanity check on queue memory */
278 /* while there are valid entries */
279 while (q
->hba_index
!= q
->host_index
) {
280 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
281 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
283 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
285 if (unlikely(released
== 0 && !arm
))
288 /* ring doorbell for number popped */
291 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
292 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
294 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
295 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
296 bf_set(lpfc_eqcq_doorbell_eqid
, &doorbell
, q
->queue_id
);
297 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
298 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
299 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
300 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
305 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
306 * @q: The Completion Queue to get the first valid CQE from
308 * This routine will get the first valid Completion Queue Entry from @q, update
309 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
310 * the Queue (no more work to do), or the Queue is full of CQEs that have been
311 * processed, but not popped back to the HBA then this routine will return NULL.
313 static struct lpfc_cqe
*
314 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
316 struct lpfc_cqe
*cqe
;
318 /* sanity check on queue memory */
322 /* If the next CQE is not valid then we are done */
323 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
325 /* If the host has not yet processed the next entry then we are done */
326 if (((q
->hba_index
+ 1) % q
->entry_count
) == q
->host_index
)
329 cqe
= q
->qe
[q
->hba_index
].cqe
;
330 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
335 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
336 * @q: The Completion Queue that the host has completed processing for.
337 * @arm: Indicates whether the host wants to arms this CQ.
339 * This routine will mark all Completion queue entries on @q, from the last
340 * known completed entry to the last entry that was processed, as completed
341 * by clearing the valid bit for each completion queue entry. Then it will
342 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
343 * The internal host index in the @q will be updated by this routine to indicate
344 * that the host has finished processing the entries. The @arm parameter
345 * indicates that the queue should be rearmed when ringing the doorbell.
347 * This function will return the number of CQEs that were released.
350 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
352 uint32_t released
= 0;
353 struct lpfc_cqe
*temp_qe
;
354 struct lpfc_register doorbell
;
356 /* sanity check on queue memory */
359 /* while there are valid entries */
360 while (q
->hba_index
!= q
->host_index
) {
361 temp_qe
= q
->qe
[q
->host_index
].cqe
;
362 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
364 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
366 if (unlikely(released
== 0 && !arm
))
369 /* ring doorbell for number popped */
372 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
373 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
374 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
375 bf_set(lpfc_eqcq_doorbell_cqid
, &doorbell
, q
->queue_id
);
376 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
381 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
382 * @q: The Header Receive Queue to operate on.
383 * @wqe: The Receive Queue Entry to put on the Receive queue.
385 * This routine will copy the contents of @wqe to the next available entry on
386 * the @q. This function will then ring the Receive Queue Doorbell to signal the
387 * HBA to start processing the Receive Queue Entry. This function returns the
388 * index that the rqe was copied to if successful. If no entries are available
389 * on @q then this function will return -ENOMEM.
390 * The caller is expected to hold the hbalock when calling this routine.
393 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
394 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
396 struct lpfc_rqe
*temp_hrqe
;
397 struct lpfc_rqe
*temp_drqe
;
398 struct lpfc_register doorbell
;
399 int put_index
= hq
->host_index
;
401 /* sanity check on queue memory */
402 if (unlikely(!hq
) || unlikely(!dq
))
404 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
405 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
407 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
409 if (hq
->host_index
!= dq
->host_index
)
411 /* If the host has not yet processed the next entry then we are done */
412 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
414 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
415 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
417 /* Update the host index to point to the next slot */
418 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
419 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
421 /* Ring The Header Receive Queue Doorbell */
422 if (!(hq
->host_index
% hq
->entry_repost
)) {
424 bf_set(lpfc_rq_doorbell_num_posted
, &doorbell
,
426 bf_set(lpfc_rq_doorbell_id
, &doorbell
, hq
->queue_id
);
427 writel(doorbell
.word0
, hq
->phba
->sli4_hba
.RQDBregaddr
);
433 * lpfc_sli4_rq_release - Updates internal hba index for RQ
434 * @q: The Header Receive Queue to operate on.
436 * This routine will update the HBA index of a queue to reflect consumption of
437 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
438 * consumed an entry the host calls this function to update the queue's
439 * internal pointers. This routine returns the number of entries that were
440 * consumed by the HBA.
443 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
445 /* sanity check on queue memory */
446 if (unlikely(!hq
) || unlikely(!dq
))
449 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
451 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
452 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
457 * lpfc_cmd_iocb - Get next command iocb entry in the ring
458 * @phba: Pointer to HBA context object.
459 * @pring: Pointer to driver SLI ring object.
461 * This function returns pointer to next command iocb entry
462 * in the command ring. The caller must hold hbalock to prevent
463 * other threads consume the next command iocb.
464 * SLI-2/SLI-3 provide different sized iocbs.
466 static inline IOCB_t
*
467 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
469 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
470 pring
->cmdidx
* phba
->iocb_cmd_size
);
474 * lpfc_resp_iocb - Get next response iocb entry in the ring
475 * @phba: Pointer to HBA context object.
476 * @pring: Pointer to driver SLI ring object.
478 * This function returns pointer to next response iocb entry
479 * in the response ring. The caller must hold hbalock to make sure
480 * that no other thread consume the next response iocb.
481 * SLI-2/SLI-3 provide different sized iocbs.
483 static inline IOCB_t
*
484 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
486 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
487 pring
->rspidx
* phba
->iocb_rsp_size
);
491 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
492 * @phba: Pointer to HBA context object.
494 * This function is called with hbalock held. This function
495 * allocates a new driver iocb object from the iocb pool. If the
496 * allocation is successful, it returns pointer to the newly
497 * allocated iocb object else it returns NULL.
499 static struct lpfc_iocbq
*
500 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
502 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
503 struct lpfc_iocbq
* iocbq
= NULL
;
505 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
508 if (phba
->iocb_cnt
> phba
->iocb_max
)
509 phba
->iocb_max
= phba
->iocb_cnt
;
514 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
515 * @phba: Pointer to HBA context object.
516 * @xritag: XRI value.
518 * This function clears the sglq pointer from the array of acive
519 * sglq's. The xritag that is passed in is used to index into the
520 * array. Before the xritag can be used it needs to be adjusted
521 * by subtracting the xribase.
523 * Returns sglq ponter = success, NULL = Failure.
525 static struct lpfc_sglq
*
526 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
528 struct lpfc_sglq
*sglq
;
530 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
531 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
536 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
537 * @phba: Pointer to HBA context object.
538 * @xritag: XRI value.
540 * This function returns the sglq pointer from the array of acive
541 * sglq's. The xritag that is passed in is used to index into the
542 * array. Before the xritag can be used it needs to be adjusted
543 * by subtracting the xribase.
545 * Returns sglq ponter = success, NULL = Failure.
548 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
550 struct lpfc_sglq
*sglq
;
552 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
557 * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
558 * @phba: Pointer to HBA context object.
559 * @ndlp: nodelist pointer for this target.
560 * @xritag: xri used in this exchange.
561 * @rxid: Remote Exchange ID.
562 * @send_rrq: Flag used to determine if we should send rrq els cmd.
564 * This function is called with hbalock held.
565 * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
566 * rrq struct and adds it to the active_rrq_list.
568 * returns 0 for rrq slot for this xri
569 * < 0 Were not able to get rrq mem or invalid parameter.
572 __lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
573 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
575 struct lpfc_node_rrq
*rrq
;
583 if (!phba
->cfg_enable_rrq
)
586 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
587 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
593 * set the active bit even if there is no mem available.
595 if (NLP_CHK_FREE_REQ(ndlp
))
598 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
601 if (test_and_set_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
604 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
606 rrq
->send_rrq
= send_rrq
;
607 rrq
->xritag
= xritag
;
608 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
610 rrq
->nlp_DID
= ndlp
->nlp_DID
;
611 rrq
->vport
= ndlp
->vport
;
613 empty
= list_empty(&phba
->active_rrq_list
);
614 rrq
->send_rrq
= send_rrq
;
615 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
616 if (!(phba
->hba_flag
& HBA_RRQ_ACTIVE
)) {
617 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
619 lpfc_worker_wake_up(phba
);
624 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
625 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
626 " DID:0x%x Send:%d\n",
627 xritag
, rxid
, did
, send_rrq
);
632 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
633 * @phba: Pointer to HBA context object.
634 * @xritag: xri used in this exchange.
635 * @rrq: The RRQ to be cleared.
639 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
641 struct lpfc_node_rrq
*rrq
)
643 struct lpfc_nodelist
*ndlp
= NULL
;
645 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
646 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
648 /* The target DID could have been swapped (cable swap)
649 * we should use the ndlp from the findnode if it is
652 if ((!ndlp
) && rrq
->ndlp
)
658 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
)) {
661 rrq
->rrq_stop_time
= 0;
664 mempool_free(rrq
, phba
->rrq_pool
);
668 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
669 * @phba: Pointer to HBA context object.
671 * This function is called with hbalock held. This function
672 * Checks if stop_time (ratov from setting rrq active) has
673 * been reached, if it has and the send_rrq flag is set then
674 * it will call lpfc_send_rrq. If the send_rrq flag is not set
675 * then it will just call the routine to clear the rrq and
676 * free the rrq resource.
677 * The timer is set to the next rrq that is going to expire before
678 * leaving the routine.
682 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
684 struct lpfc_node_rrq
*rrq
;
685 struct lpfc_node_rrq
*nextrrq
;
686 unsigned long next_time
;
687 unsigned long iflags
;
690 spin_lock_irqsave(&phba
->hbalock
, iflags
);
691 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
692 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
693 list_for_each_entry_safe(rrq
, nextrrq
,
694 &phba
->active_rrq_list
, list
) {
695 if (time_after(jiffies
, rrq
->rrq_stop_time
))
696 list_move(&rrq
->list
, &send_rrq
);
697 else if (time_before(rrq
->rrq_stop_time
, next_time
))
698 next_time
= rrq
->rrq_stop_time
;
700 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
701 if (!list_empty(&phba
->active_rrq_list
))
702 mod_timer(&phba
->rrq_tmr
, next_time
);
703 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
704 list_del(&rrq
->list
);
706 /* this call will free the rrq */
707 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
708 else if (lpfc_send_rrq(phba
, rrq
)) {
709 /* if we send the rrq then the completion handler
710 * will clear the bit in the xribitmap.
712 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
719 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
720 * @vport: Pointer to vport context object.
721 * @xri: The xri used in the exchange.
722 * @did: The targets DID for this exchange.
724 * returns NULL = rrq not found in the phba->active_rrq_list.
725 * rrq = rrq for this xri and target.
727 struct lpfc_node_rrq
*
728 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
730 struct lpfc_hba
*phba
= vport
->phba
;
731 struct lpfc_node_rrq
*rrq
;
732 struct lpfc_node_rrq
*nextrrq
;
733 unsigned long iflags
;
735 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
737 spin_lock_irqsave(&phba
->hbalock
, iflags
);
738 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
739 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
740 rrq
->nlp_DID
== did
){
741 list_del(&rrq
->list
);
742 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
746 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
751 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
752 * @vport: Pointer to vport context object.
753 * @ndlp: Pointer to the lpfc_node_list structure.
754 * If ndlp is NULL Remove all active RRQs for this vport from the
755 * phba->active_rrq_list and clear the rrq.
756 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
759 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
762 struct lpfc_hba
*phba
= vport
->phba
;
763 struct lpfc_node_rrq
*rrq
;
764 struct lpfc_node_rrq
*nextrrq
;
765 unsigned long iflags
;
768 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
771 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
772 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
774 spin_lock_irqsave(&phba
->hbalock
, iflags
);
775 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
776 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
777 list_move(&rrq
->list
, &rrq_list
);
778 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
780 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
781 list_del(&rrq
->list
);
782 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
787 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
788 * @phba: Pointer to HBA context object.
790 * Remove all rrqs from the phba->active_rrq_list and free them by
791 * calling __lpfc_clr_active_rrq
795 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
797 struct lpfc_node_rrq
*rrq
;
798 struct lpfc_node_rrq
*nextrrq
;
799 unsigned long next_time
;
800 unsigned long iflags
;
803 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
805 spin_lock_irqsave(&phba
->hbalock
, iflags
);
806 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
807 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
808 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
809 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
811 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
812 list_del(&rrq
->list
);
813 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
815 if (!list_empty(&phba
->active_rrq_list
))
816 mod_timer(&phba
->rrq_tmr
, next_time
);
821 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
822 * @phba: Pointer to HBA context object.
823 * @ndlp: Targets nodelist pointer for this exchange.
824 * @xritag the xri in the bitmap to test.
826 * This function is called with hbalock held. This function
827 * returns 0 = rrq not active for this xri
828 * 1 = rrq is valid for this xri.
831 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
836 if (test_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
843 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
844 * @phba: Pointer to HBA context object.
845 * @ndlp: nodelist pointer for this target.
846 * @xritag: xri used in this exchange.
847 * @rxid: Remote Exchange ID.
848 * @send_rrq: Flag used to determine if we should send rrq els cmd.
850 * This function takes the hbalock.
851 * The active bit is always set in the active rrq xri_bitmap even
852 * if there is no slot avaiable for the other rrq information.
854 * returns 0 rrq actived for this xri
855 * < 0 No memory or invalid ndlp.
858 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
859 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
862 unsigned long iflags
;
864 spin_lock_irqsave(&phba
->hbalock
, iflags
);
865 ret
= __lpfc_set_rrq_active(phba
, ndlp
, xritag
, rxid
, send_rrq
);
866 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
871 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
872 * @phba: Pointer to HBA context object.
873 * @piocb: Pointer to the iocbq.
875 * This function is called with hbalock held. This function
876 * gets a new driver sglq object from the sglq list. If the
877 * list is not empty then it is successful, it returns pointer to the newly
878 * allocated sglq object else it returns NULL.
880 static struct lpfc_sglq
*
881 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
883 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
884 struct lpfc_sglq
*sglq
= NULL
;
885 struct lpfc_sglq
*start_sglq
= NULL
;
886 struct lpfc_scsi_buf
*lpfc_cmd
;
887 struct lpfc_nodelist
*ndlp
;
890 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
891 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
892 ndlp
= lpfc_cmd
->rdata
->pnode
;
893 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
894 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
895 ndlp
= piocbq
->context_un
.ndlp
;
897 ndlp
= piocbq
->context1
;
899 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
904 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_xritag
)) {
905 /* This xri has an rrq outstanding for this DID.
906 * put it back in the list and get another xri.
908 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
910 list_remove_head(lpfc_sgl_list
, sglq
,
911 struct lpfc_sglq
, list
);
912 if (sglq
== start_sglq
) {
920 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
921 sglq
->state
= SGL_ALLOCATED
;
927 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
928 * @phba: Pointer to HBA context object.
930 * This function is called with no lock held. This function
931 * allocates a new driver iocb object from the iocb pool. If the
932 * allocation is successful, it returns pointer to the newly
933 * allocated iocb object else it returns NULL.
936 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
938 struct lpfc_iocbq
* iocbq
= NULL
;
939 unsigned long iflags
;
941 spin_lock_irqsave(&phba
->hbalock
, iflags
);
942 iocbq
= __lpfc_sli_get_iocbq(phba
);
943 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
948 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
949 * @phba: Pointer to HBA context object.
950 * @iocbq: Pointer to driver iocb object.
952 * This function is called with hbalock held to release driver
953 * iocb object to the iocb pool. The iotag in the iocb object
954 * does not change for each use of the iocb object. This function
955 * clears all other fields of the iocb object when it is freed.
956 * The sqlq structure that holds the xritag and phys and virtual
957 * mappings for the scatter gather list is retrieved from the
958 * active array of sglq. The get of the sglq pointer also clears
959 * the entry in the array. If the status of the IO indiactes that
960 * this IO was aborted then the sglq entry it put on the
961 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
962 * IO has good status or fails for any other reason then the sglq
963 * entry is added to the free list (lpfc_sgl_list).
966 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
968 struct lpfc_sglq
*sglq
;
969 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
970 unsigned long iflag
= 0;
971 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
973 if (iocbq
->sli4_xritag
== NO_XRI
)
976 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
979 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
980 (sglq
->state
!= SGL_XRI_ABORTED
)) {
981 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
983 list_add(&sglq
->list
,
984 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
985 spin_unlock_irqrestore(
986 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
988 sglq
->state
= SGL_FREED
;
990 list_add_tail(&sglq
->list
,
991 &phba
->sli4_hba
.lpfc_sgl_list
);
993 /* Check if TXQ queue needs to be serviced */
995 lpfc_worker_wake_up(phba
);
1001 * Clean all volatile data fields, preserve iotag and node struct.
1003 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1004 iocbq
->sli4_lxritag
= NO_XRI
;
1005 iocbq
->sli4_xritag
= NO_XRI
;
1006 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1011 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1012 * @phba: Pointer to HBA context object.
1013 * @iocbq: Pointer to driver iocb object.
1015 * This function is called with hbalock held to release driver
1016 * iocb object to the iocb pool. The iotag in the iocb object
1017 * does not change for each use of the iocb object. This function
1018 * clears all other fields of the iocb object when it is freed.
1021 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1023 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1026 * Clean all volatile data fields, preserve iotag and node struct.
1028 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1029 iocbq
->sli4_xritag
= NO_XRI
;
1030 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1034 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1035 * @phba: Pointer to HBA context object.
1036 * @iocbq: Pointer to driver iocb object.
1038 * This function is called with hbalock held to release driver
1039 * iocb object to the iocb pool. The iotag in the iocb object
1040 * does not change for each use of the iocb object. This function
1041 * clears all other fields of the iocb object when it is freed.
1044 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1046 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1051 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1052 * @phba: Pointer to HBA context object.
1053 * @iocbq: Pointer to driver iocb object.
1055 * This function is called with no lock held to release the iocb to
1059 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1061 unsigned long iflags
;
1064 * Clean all volatile data fields, preserve iotag and node struct.
1066 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1067 __lpfc_sli_release_iocbq(phba
, iocbq
);
1068 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1072 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1073 * @phba: Pointer to HBA context object.
1074 * @iocblist: List of IOCBs.
1075 * @ulpstatus: ULP status in IOCB command field.
1076 * @ulpWord4: ULP word-4 in IOCB command field.
1078 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1079 * on the list by invoking the complete callback function associated with the
1080 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1084 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1085 uint32_t ulpstatus
, uint32_t ulpWord4
)
1087 struct lpfc_iocbq
*piocb
;
1089 while (!list_empty(iocblist
)) {
1090 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1092 if (!piocb
->iocb_cmpl
)
1093 lpfc_sli_release_iocbq(phba
, piocb
);
1095 piocb
->iocb
.ulpStatus
= ulpstatus
;
1096 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1097 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1104 * lpfc_sli_iocb_cmd_type - Get the iocb type
1105 * @iocb_cmnd: iocb command code.
1107 * This function is called by ring event handler function to get the iocb type.
1108 * This function translates the iocb command to an iocb command type used to
1109 * decide the final disposition of each completed IOCB.
1110 * The function returns
1111 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1112 * LPFC_SOL_IOCB if it is a solicited iocb completion
1113 * LPFC_ABORT_IOCB if it is an abort iocb
1114 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1116 * The caller is not required to hold any lock.
1118 static lpfc_iocb_type
1119 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1121 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1123 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1126 switch (iocb_cmnd
) {
1127 case CMD_XMIT_SEQUENCE_CR
:
1128 case CMD_XMIT_SEQUENCE_CX
:
1129 case CMD_XMIT_BCAST_CN
:
1130 case CMD_XMIT_BCAST_CX
:
1131 case CMD_ELS_REQUEST_CR
:
1132 case CMD_ELS_REQUEST_CX
:
1133 case CMD_CREATE_XRI_CR
:
1134 case CMD_CREATE_XRI_CX
:
1135 case CMD_GET_RPI_CN
:
1136 case CMD_XMIT_ELS_RSP_CX
:
1137 case CMD_GET_RPI_CR
:
1138 case CMD_FCP_IWRITE_CR
:
1139 case CMD_FCP_IWRITE_CX
:
1140 case CMD_FCP_IREAD_CR
:
1141 case CMD_FCP_IREAD_CX
:
1142 case CMD_FCP_ICMND_CR
:
1143 case CMD_FCP_ICMND_CX
:
1144 case CMD_FCP_TSEND_CX
:
1145 case CMD_FCP_TRSP_CX
:
1146 case CMD_FCP_TRECEIVE_CX
:
1147 case CMD_FCP_AUTO_TRSP_CX
:
1148 case CMD_ADAPTER_MSG
:
1149 case CMD_ADAPTER_DUMP
:
1150 case CMD_XMIT_SEQUENCE64_CR
:
1151 case CMD_XMIT_SEQUENCE64_CX
:
1152 case CMD_XMIT_BCAST64_CN
:
1153 case CMD_XMIT_BCAST64_CX
:
1154 case CMD_ELS_REQUEST64_CR
:
1155 case CMD_ELS_REQUEST64_CX
:
1156 case CMD_FCP_IWRITE64_CR
:
1157 case CMD_FCP_IWRITE64_CX
:
1158 case CMD_FCP_IREAD64_CR
:
1159 case CMD_FCP_IREAD64_CX
:
1160 case CMD_FCP_ICMND64_CR
:
1161 case CMD_FCP_ICMND64_CX
:
1162 case CMD_FCP_TSEND64_CX
:
1163 case CMD_FCP_TRSP64_CX
:
1164 case CMD_FCP_TRECEIVE64_CX
:
1165 case CMD_GEN_REQUEST64_CR
:
1166 case CMD_GEN_REQUEST64_CX
:
1167 case CMD_XMIT_ELS_RSP64_CX
:
1168 case DSSCMD_IWRITE64_CR
:
1169 case DSSCMD_IWRITE64_CX
:
1170 case DSSCMD_IREAD64_CR
:
1171 case DSSCMD_IREAD64_CX
:
1172 type
= LPFC_SOL_IOCB
;
1174 case CMD_ABORT_XRI_CN
:
1175 case CMD_ABORT_XRI_CX
:
1176 case CMD_CLOSE_XRI_CN
:
1177 case CMD_CLOSE_XRI_CX
:
1178 case CMD_XRI_ABORTED_CX
:
1179 case CMD_ABORT_MXRI64_CN
:
1180 case CMD_XMIT_BLS_RSP64_CX
:
1181 type
= LPFC_ABORT_IOCB
;
1183 case CMD_RCV_SEQUENCE_CX
:
1184 case CMD_RCV_ELS_REQ_CX
:
1185 case CMD_RCV_SEQUENCE64_CX
:
1186 case CMD_RCV_ELS_REQ64_CX
:
1187 case CMD_ASYNC_STATUS
:
1188 case CMD_IOCB_RCV_SEQ64_CX
:
1189 case CMD_IOCB_RCV_ELS64_CX
:
1190 case CMD_IOCB_RCV_CONT64_CX
:
1191 case CMD_IOCB_RET_XRI64_CX
:
1192 type
= LPFC_UNSOL_IOCB
;
1194 case CMD_IOCB_XMIT_MSEQ64_CR
:
1195 case CMD_IOCB_XMIT_MSEQ64_CX
:
1196 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1197 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1198 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1199 case CMD_IOCB_ABORT_EXTENDED_CN
:
1200 case CMD_IOCB_RET_HBQE64_CN
:
1201 case CMD_IOCB_FCP_IBIDIR64_CR
:
1202 case CMD_IOCB_FCP_IBIDIR64_CX
:
1203 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1204 case CMD_IOCB_LOGENTRY_CN
:
1205 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1206 printk("%s - Unhandled SLI-3 Command x%x\n",
1207 __func__
, iocb_cmnd
);
1208 type
= LPFC_UNKNOWN_IOCB
;
1211 type
= LPFC_UNKNOWN_IOCB
;
1219 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1220 * @phba: Pointer to HBA context object.
1222 * This function is called from SLI initialization code
1223 * to configure every ring of the HBA's SLI interface. The
1224 * caller is not required to hold any lock. This function issues
1225 * a config_ring mailbox command for each ring.
1226 * This function returns zero if successful else returns a negative
1230 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1232 struct lpfc_sli
*psli
= &phba
->sli
;
1237 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1241 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1242 for (i
= 0; i
< psli
->num_rings
; i
++) {
1243 lpfc_config_ring(phba
, i
, pmb
);
1244 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1245 if (rc
!= MBX_SUCCESS
) {
1246 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1247 "0446 Adapter failed to init (%d), "
1248 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1250 rc
, pmbox
->mbxCommand
,
1251 pmbox
->mbxStatus
, i
);
1252 phba
->link_state
= LPFC_HBA_ERROR
;
1257 mempool_free(pmb
, phba
->mbox_mem_pool
);
1262 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1263 * @phba: Pointer to HBA context object.
1264 * @pring: Pointer to driver SLI ring object.
1265 * @piocb: Pointer to the driver iocb object.
1267 * This function is called with hbalock held. The function adds the
1268 * new iocb to txcmplq of the given ring. This function always returns
1269 * 0. If this function is called for ELS ring, this function checks if
1270 * there is a vport associated with the ELS command. This function also
1271 * starts els_tmofunc timer if this is an ELS command.
1274 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1275 struct lpfc_iocbq
*piocb
)
1277 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1278 piocb
->iocb_flag
|= LPFC_IO_ON_Q
;
1279 pring
->txcmplq_cnt
++;
1280 if (pring
->txcmplq_cnt
> pring
->txcmplq_max
)
1281 pring
->txcmplq_max
= pring
->txcmplq_cnt
;
1283 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1284 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1285 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1289 mod_timer(&piocb
->vport
->els_tmofunc
,
1290 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1298 * lpfc_sli_ringtx_get - Get first element of the txq
1299 * @phba: Pointer to HBA context object.
1300 * @pring: Pointer to driver SLI ring object.
1302 * This function is called with hbalock held to get next
1303 * iocb in txq of the given ring. If there is any iocb in
1304 * the txq, the function returns first iocb in the list after
1305 * removing the iocb from the list, else it returns NULL.
1308 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1310 struct lpfc_iocbq
*cmd_iocb
;
1312 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1313 if (cmd_iocb
!= NULL
)
1319 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1320 * @phba: Pointer to HBA context object.
1321 * @pring: Pointer to driver SLI ring object.
1323 * This function is called with hbalock held and the caller must post the
1324 * iocb without releasing the lock. If the caller releases the lock,
1325 * iocb slot returned by the function is not guaranteed to be available.
1326 * The function returns pointer to the next available iocb slot if there
1327 * is available slot in the ring, else it returns NULL.
1328 * If the get index of the ring is ahead of the put index, the function
1329 * will post an error attention event to the worker thread to take the
1330 * HBA to offline state.
1333 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1335 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1336 uint32_t max_cmd_idx
= pring
->numCiocb
;
1337 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
1338 (++pring
->next_cmdidx
>= max_cmd_idx
))
1339 pring
->next_cmdidx
= 0;
1341 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
1343 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1345 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
1346 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1347 "0315 Ring %d issue: portCmdGet %d "
1348 "is bigger than cmd ring %d\n",
1350 pring
->local_getidx
, max_cmd_idx
);
1352 phba
->link_state
= LPFC_HBA_ERROR
;
1354 * All error attention handlers are posted to
1357 phba
->work_ha
|= HA_ERATT
;
1358 phba
->work_hs
= HS_FFER3
;
1360 lpfc_worker_wake_up(phba
);
1365 if (pring
->local_getidx
== pring
->next_cmdidx
)
1369 return lpfc_cmd_iocb(phba
, pring
);
1373 * lpfc_sli_next_iotag - Get an iotag for the iocb
1374 * @phba: Pointer to HBA context object.
1375 * @iocbq: Pointer to driver iocb object.
1377 * This function gets an iotag for the iocb. If there is no unused iotag and
1378 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1379 * array and assigns a new iotag.
1380 * The function returns the allocated iotag if successful, else returns zero.
1381 * Zero is not a valid iotag.
1382 * The caller is not required to hold any lock.
1385 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1387 struct lpfc_iocbq
**new_arr
;
1388 struct lpfc_iocbq
**old_arr
;
1390 struct lpfc_sli
*psli
= &phba
->sli
;
1393 spin_lock_irq(&phba
->hbalock
);
1394 iotag
= psli
->last_iotag
;
1395 if(++iotag
< psli
->iocbq_lookup_len
) {
1396 psli
->last_iotag
= iotag
;
1397 psli
->iocbq_lookup
[iotag
] = iocbq
;
1398 spin_unlock_irq(&phba
->hbalock
);
1399 iocbq
->iotag
= iotag
;
1401 } else if (psli
->iocbq_lookup_len
< (0xffff
1402 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1403 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1404 spin_unlock_irq(&phba
->hbalock
);
1405 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1408 spin_lock_irq(&phba
->hbalock
);
1409 old_arr
= psli
->iocbq_lookup
;
1410 if (new_len
<= psli
->iocbq_lookup_len
) {
1411 /* highly unprobable case */
1413 iotag
= psli
->last_iotag
;
1414 if(++iotag
< psli
->iocbq_lookup_len
) {
1415 psli
->last_iotag
= iotag
;
1416 psli
->iocbq_lookup
[iotag
] = iocbq
;
1417 spin_unlock_irq(&phba
->hbalock
);
1418 iocbq
->iotag
= iotag
;
1421 spin_unlock_irq(&phba
->hbalock
);
1424 if (psli
->iocbq_lookup
)
1425 memcpy(new_arr
, old_arr
,
1426 ((psli
->last_iotag
+ 1) *
1427 sizeof (struct lpfc_iocbq
*)));
1428 psli
->iocbq_lookup
= new_arr
;
1429 psli
->iocbq_lookup_len
= new_len
;
1430 psli
->last_iotag
= iotag
;
1431 psli
->iocbq_lookup
[iotag
] = iocbq
;
1432 spin_unlock_irq(&phba
->hbalock
);
1433 iocbq
->iotag
= iotag
;
1438 spin_unlock_irq(&phba
->hbalock
);
1440 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1441 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1448 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1449 * @phba: Pointer to HBA context object.
1450 * @pring: Pointer to driver SLI ring object.
1451 * @iocb: Pointer to iocb slot in the ring.
1452 * @nextiocb: Pointer to driver iocb object which need to be
1453 * posted to firmware.
1455 * This function is called with hbalock held to post a new iocb to
1456 * the firmware. This function copies the new iocb to ring iocb slot and
1457 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1458 * a completion call back for this iocb else the function will free the
1462 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1463 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1468 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1471 if (pring
->ringno
== LPFC_ELS_RING
) {
1472 lpfc_debugfs_slow_ring_trc(phba
,
1473 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1474 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1475 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1476 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1480 * Issue iocb command to adapter
1482 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1484 pring
->stats
.iocb_cmd
++;
1487 * If there is no completion routine to call, we can release the
1488 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1489 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1491 if (nextiocb
->iocb_cmpl
)
1492 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1494 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1497 * Let the HBA know what IOCB slot will be the next one the
1498 * driver will put a command into.
1500 pring
->cmdidx
= pring
->next_cmdidx
;
1501 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1505 * lpfc_sli_update_full_ring - Update the chip attention register
1506 * @phba: Pointer to HBA context object.
1507 * @pring: Pointer to driver SLI ring object.
1509 * The caller is not required to hold any lock for calling this function.
1510 * This function updates the chip attention bits for the ring to inform firmware
1511 * that there are pending work to be done for this ring and requests an
1512 * interrupt when there is space available in the ring. This function is
1513 * called when the driver is unable to post more iocbs to the ring due
1514 * to unavailability of space in the ring.
1517 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1519 int ringno
= pring
->ringno
;
1521 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1526 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1527 * The HBA will tell us when an IOCB entry is available.
1529 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1530 readl(phba
->CAregaddr
); /* flush */
1532 pring
->stats
.iocb_cmd_full
++;
1536 * lpfc_sli_update_ring - Update chip attention register
1537 * @phba: Pointer to HBA context object.
1538 * @pring: Pointer to driver SLI ring object.
1540 * This function updates the chip attention register bit for the
1541 * given ring to inform HBA that there is more work to be done
1542 * in this ring. The caller is not required to hold any lock.
1545 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1547 int ringno
= pring
->ringno
;
1550 * Tell the HBA that there is work to do in this ring.
1552 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1554 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1555 readl(phba
->CAregaddr
); /* flush */
1560 * lpfc_sli_resume_iocb - Process iocbs in the txq
1561 * @phba: Pointer to HBA context object.
1562 * @pring: Pointer to driver SLI ring object.
1564 * This function is called with hbalock held to post pending iocbs
1565 * in the txq to the firmware. This function is called when driver
1566 * detects space available in the ring.
1569 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1572 struct lpfc_iocbq
*nextiocb
;
1576 * (a) there is anything on the txq to send
1578 * (c) link attention events can be processed (fcp ring only)
1579 * (d) IOCB processing is not blocked by the outstanding mbox command.
1581 if (pring
->txq_cnt
&&
1582 lpfc_is_link_up(phba
) &&
1583 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1584 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1586 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1587 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1588 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1591 lpfc_sli_update_ring(phba
, pring
);
1593 lpfc_sli_update_full_ring(phba
, pring
);
1600 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1601 * @phba: Pointer to HBA context object.
1602 * @hbqno: HBQ number.
1604 * This function is called with hbalock held to get the next
1605 * available slot for the given HBQ. If there is free slot
1606 * available for the HBQ it will return pointer to the next available
1607 * HBQ entry else it will return NULL.
1609 static struct lpfc_hbq_entry
*
1610 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1612 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1614 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1615 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1616 hbqp
->next_hbqPutIdx
= 0;
1618 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1619 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1620 uint32_t getidx
= le32_to_cpu(raw_index
);
1622 hbqp
->local_hbqGetIdx
= getidx
;
1624 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1625 lpfc_printf_log(phba
, KERN_ERR
,
1626 LOG_SLI
| LOG_VPORT
,
1627 "1802 HBQ %d: local_hbqGetIdx "
1628 "%u is > than hbqp->entry_count %u\n",
1629 hbqno
, hbqp
->local_hbqGetIdx
,
1632 phba
->link_state
= LPFC_HBA_ERROR
;
1636 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1640 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1645 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1646 * @phba: Pointer to HBA context object.
1648 * This function is called with no lock held to free all the
1649 * hbq buffers while uninitializing the SLI interface. It also
1650 * frees the HBQ buffers returned by the firmware but not yet
1651 * processed by the upper layers.
1654 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1656 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1657 struct hbq_dmabuf
*hbq_buf
;
1658 unsigned long flags
;
1662 hbq_count
= lpfc_sli_hbq_count();
1663 /* Return all memory used by all HBQs */
1664 spin_lock_irqsave(&phba
->hbalock
, flags
);
1665 for (i
= 0; i
< hbq_count
; ++i
) {
1666 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1667 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1668 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1669 list_del(&hbq_buf
->dbuf
.list
);
1670 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1672 phba
->hbqs
[i
].buffer_count
= 0;
1674 /* Return all HBQ buffer that are in-fly */
1675 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1677 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1678 list_del(&hbq_buf
->dbuf
.list
);
1679 if (hbq_buf
->tag
== -1) {
1680 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1683 hbqno
= hbq_buf
->tag
>> 16;
1684 if (hbqno
>= LPFC_MAX_HBQS
)
1685 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1688 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1693 /* Mark the HBQs not in use */
1694 phba
->hbq_in_use
= 0;
1695 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1699 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1700 * @phba: Pointer to HBA context object.
1701 * @hbqno: HBQ number.
1702 * @hbq_buf: Pointer to HBQ buffer.
1704 * This function is called with the hbalock held to post a
1705 * hbq buffer to the firmware. If the function finds an empty
1706 * slot in the HBQ, it will post the buffer. The function will return
1707 * pointer to the hbq entry if it successfully post the buffer
1708 * else it will return NULL.
1711 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1712 struct hbq_dmabuf
*hbq_buf
)
1714 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1718 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1719 * @phba: Pointer to HBA context object.
1720 * @hbqno: HBQ number.
1721 * @hbq_buf: Pointer to HBQ buffer.
1723 * This function is called with the hbalock held to post a hbq buffer to the
1724 * firmware. If the function finds an empty slot in the HBQ, it will post the
1725 * buffer and place it on the hbq_buffer_list. The function will return zero if
1726 * it successfully post the buffer else it will return an error.
1729 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1730 struct hbq_dmabuf
*hbq_buf
)
1732 struct lpfc_hbq_entry
*hbqe
;
1733 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1735 /* Get next HBQ entry slot to use */
1736 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1738 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1740 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1741 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1742 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1743 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1744 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1745 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1747 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1748 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1750 readl(phba
->hbq_put
+ hbqno
);
1751 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1758 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1759 * @phba: Pointer to HBA context object.
1760 * @hbqno: HBQ number.
1761 * @hbq_buf: Pointer to HBQ buffer.
1763 * This function is called with the hbalock held to post an RQE to the SLI4
1764 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1765 * the hbq_buffer_list and return zero, otherwise it will return an error.
1768 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1769 struct hbq_dmabuf
*hbq_buf
)
1772 struct lpfc_rqe hrqe
;
1773 struct lpfc_rqe drqe
;
1775 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1776 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1777 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1778 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1779 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1784 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1788 /* HBQ for ELS and CT traffic. */
1789 static struct lpfc_hbq_init lpfc_els_hbq
= {
1794 .ring_mask
= (1 << LPFC_ELS_RING
),
1800 /* HBQ for the extra ring if needed */
1801 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1806 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1813 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1819 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1820 * @phba: Pointer to HBA context object.
1821 * @hbqno: HBQ number.
1822 * @count: Number of HBQ buffers to be posted.
1824 * This function is called with no lock held to post more hbq buffers to the
1825 * given HBQ. The function returns the number of HBQ buffers successfully
1829 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1831 uint32_t i
, posted
= 0;
1832 unsigned long flags
;
1833 struct hbq_dmabuf
*hbq_buffer
;
1834 LIST_HEAD(hbq_buf_list
);
1835 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1838 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1839 lpfc_hbq_defs
[hbqno
]->entry_count
)
1840 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1841 phba
->hbqs
[hbqno
].buffer_count
;
1844 /* Allocate HBQ entries */
1845 for (i
= 0; i
< count
; i
++) {
1846 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1849 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1851 /* Check whether HBQ is still in use */
1852 spin_lock_irqsave(&phba
->hbalock
, flags
);
1853 if (!phba
->hbq_in_use
)
1855 while (!list_empty(&hbq_buf_list
)) {
1856 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1858 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1860 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1861 phba
->hbqs
[hbqno
].buffer_count
++;
1864 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1866 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1869 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1870 while (!list_empty(&hbq_buf_list
)) {
1871 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1873 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1879 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1880 * @phba: Pointer to HBA context object.
1883 * This function posts more buffers to the HBQ. This function
1884 * is called with no lock held. The function returns the number of HBQ entries
1885 * successfully allocated.
1888 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1890 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1893 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1894 lpfc_hbq_defs
[qno
]->add_count
);
1898 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1899 * @phba: Pointer to HBA context object.
1900 * @qno: HBQ queue number.
1902 * This function is called from SLI initialization code path with
1903 * no lock held to post initial HBQ buffers to firmware. The
1904 * function returns the number of HBQ entries successfully allocated.
1907 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1909 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1910 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1911 lpfc_hbq_defs
[qno
]->entry_count
);
1913 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1914 lpfc_hbq_defs
[qno
]->init_count
);
1918 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1919 * @phba: Pointer to HBA context object.
1920 * @hbqno: HBQ number.
1922 * This function removes the first hbq buffer on an hbq list and returns a
1923 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1925 static struct hbq_dmabuf
*
1926 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1928 struct lpfc_dmabuf
*d_buf
;
1930 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1933 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1937 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1938 * @phba: Pointer to HBA context object.
1939 * @tag: Tag of the hbq buffer.
1941 * This function is called with hbalock held. This function searches
1942 * for the hbq buffer associated with the given tag in the hbq buffer
1943 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1946 static struct hbq_dmabuf
*
1947 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1949 struct lpfc_dmabuf
*d_buf
;
1950 struct hbq_dmabuf
*hbq_buf
;
1954 if (hbqno
>= LPFC_MAX_HBQS
)
1957 spin_lock_irq(&phba
->hbalock
);
1958 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
1959 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1960 if (hbq_buf
->tag
== tag
) {
1961 spin_unlock_irq(&phba
->hbalock
);
1965 spin_unlock_irq(&phba
->hbalock
);
1966 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
1967 "1803 Bad hbq tag. Data: x%x x%x\n",
1968 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
1973 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
1974 * @phba: Pointer to HBA context object.
1975 * @hbq_buffer: Pointer to HBQ buffer.
1977 * This function is called with hbalock. This function gives back
1978 * the hbq buffer to firmware. If the HBQ does not have space to
1979 * post the buffer, it will free the buffer.
1982 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
1987 hbqno
= hbq_buffer
->tag
>> 16;
1988 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
1989 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1994 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
1995 * @mbxCommand: mailbox command code.
1997 * This function is called by the mailbox event handler function to verify
1998 * that the completed mailbox command is a legitimate mailbox command. If the
1999 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2000 * and the mailbox event handler will take the HBA offline.
2003 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2007 switch (mbxCommand
) {
2011 case MBX_WRITE_VPARMS
:
2012 case MBX_RUN_BIU_DIAG
:
2015 case MBX_CONFIG_LINK
:
2016 case MBX_CONFIG_RING
:
2017 case MBX_RESET_RING
:
2018 case MBX_READ_CONFIG
:
2019 case MBX_READ_RCONFIG
:
2020 case MBX_READ_SPARM
:
2021 case MBX_READ_STATUS
:
2025 case MBX_READ_LNK_STAT
:
2027 case MBX_UNREG_LOGIN
:
2029 case MBX_DUMP_MEMORY
:
2030 case MBX_DUMP_CONTEXT
:
2033 case MBX_UPDATE_CFG
:
2035 case MBX_DEL_LD_ENTRY
:
2036 case MBX_RUN_PROGRAM
:
2038 case MBX_SET_VARIABLE
:
2039 case MBX_UNREG_D_ID
:
2040 case MBX_KILL_BOARD
:
2041 case MBX_CONFIG_FARP
:
2044 case MBX_RUN_BIU_DIAG64
:
2045 case MBX_CONFIG_PORT
:
2046 case MBX_READ_SPARM64
:
2047 case MBX_READ_RPI64
:
2048 case MBX_REG_LOGIN64
:
2049 case MBX_READ_TOPOLOGY
:
2052 case MBX_LOAD_EXP_ROM
:
2053 case MBX_ASYNCEVT_ENABLE
:
2057 case MBX_PORT_CAPABILITIES
:
2058 case MBX_PORT_IOV_CONTROL
:
2059 case MBX_SLI4_CONFIG
:
2060 case MBX_SLI4_REQ_FTRS
:
2062 case MBX_UNREG_FCFI
:
2067 case MBX_RESUME_RPI
:
2068 case MBX_READ_EVENT_LOG_STATUS
:
2069 case MBX_READ_EVENT_LOG
:
2070 case MBX_SECURITY_MGMT
:
2082 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2083 * @phba: Pointer to HBA context object.
2084 * @pmboxq: Pointer to mailbox command.
2086 * This is completion handler function for mailbox commands issued from
2087 * lpfc_sli_issue_mbox_wait function. This function is called by the
2088 * mailbox event handler function with no lock held. This function
2089 * will wake up thread waiting on the wait queue pointed by context1
2093 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2095 wait_queue_head_t
*pdone_q
;
2096 unsigned long drvr_flag
;
2099 * If pdone_q is empty, the driver thread gave up waiting and
2100 * continued running.
2102 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2103 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2104 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2106 wake_up_interruptible(pdone_q
);
2107 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2113 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2114 * @phba: Pointer to HBA context object.
2115 * @pmb: Pointer to mailbox object.
2117 * This function is the default mailbox completion handler. It
2118 * frees the memory resources associated with the completed mailbox
2119 * command. If the completed command is a REG_LOGIN mailbox command,
2120 * this function will issue a UREG_LOGIN to re-claim the RPI.
2123 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2125 struct lpfc_vport
*vport
= pmb
->vport
;
2126 struct lpfc_dmabuf
*mp
;
2127 struct lpfc_nodelist
*ndlp
;
2128 struct Scsi_Host
*shost
;
2132 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2135 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2140 * If a REG_LOGIN succeeded after node is destroyed or node
2141 * is in re-discovery driver need to cleanup the RPI.
2143 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2144 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2145 !pmb
->u
.mb
.mbxStatus
) {
2146 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2147 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2148 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2149 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2150 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2151 if (rc
!= MBX_NOT_FINISHED
)
2155 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2156 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2157 !pmb
->u
.mb
.mbxStatus
) {
2158 shost
= lpfc_shost_from_vport(vport
);
2159 spin_lock_irq(shost
->host_lock
);
2160 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2161 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2162 spin_unlock_irq(shost
->host_lock
);
2165 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2166 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2168 pmb
->context2
= NULL
;
2171 /* Check security permission status on INIT_LINK mailbox command */
2172 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2173 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2174 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2175 "2860 SLI authentication is required "
2176 "for INIT_LINK but has not done yet\n");
2178 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2179 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2181 mempool_free(pmb
, phba
->mbox_mem_pool
);
2185 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2186 * @phba: Pointer to HBA context object.
2188 * This function is called with no lock held. This function processes all
2189 * the completed mailbox commands and gives it to upper layers. The interrupt
2190 * service routine processes mailbox completion interrupt and adds completed
2191 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2192 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2193 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2194 * function returns the mailbox commands to the upper layer by calling the
2195 * completion handler function of each mailbox.
2198 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2205 phba
->sli
.slistat
.mbox_event
++;
2207 /* Get all completed mailboxe buffers into the cmplq */
2208 spin_lock_irq(&phba
->hbalock
);
2209 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2210 spin_unlock_irq(&phba
->hbalock
);
2212 /* Get a Mailbox buffer to setup mailbox commands for callback */
2214 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2220 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2222 lpfc_debugfs_disc_trc(pmb
->vport
,
2223 LPFC_DISC_TRC_MBOX_VPORT
,
2224 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2225 (uint32_t)pmbox
->mbxCommand
,
2226 pmbox
->un
.varWords
[0],
2227 pmbox
->un
.varWords
[1]);
2230 lpfc_debugfs_disc_trc(phba
->pport
,
2232 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2233 (uint32_t)pmbox
->mbxCommand
,
2234 pmbox
->un
.varWords
[0],
2235 pmbox
->un
.varWords
[1]);
2240 * It is a fatal error if unknown mbox command completion.
2242 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2244 /* Unknown mailbox command compl */
2245 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2246 "(%d):0323 Unknown Mailbox command "
2247 "x%x (x%x/x%x) Cmpl\n",
2248 pmb
->vport
? pmb
->vport
->vpi
: 0,
2250 lpfc_sli_config_mbox_subsys_get(phba
,
2252 lpfc_sli_config_mbox_opcode_get(phba
,
2254 phba
->link_state
= LPFC_HBA_ERROR
;
2255 phba
->work_hs
= HS_FFER3
;
2256 lpfc_handle_eratt(phba
);
2260 if (pmbox
->mbxStatus
) {
2261 phba
->sli
.slistat
.mbox_stat_err
++;
2262 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2263 /* Mbox cmd cmpl error - RETRYing */
2264 lpfc_printf_log(phba
, KERN_INFO
,
2266 "(%d):0305 Mbox cmd cmpl "
2267 "error - RETRYing Data: x%x "
2268 "(x%x/x%x) x%x x%x x%x\n",
2269 pmb
->vport
? pmb
->vport
->vpi
: 0,
2271 lpfc_sli_config_mbox_subsys_get(phba
,
2273 lpfc_sli_config_mbox_opcode_get(phba
,
2276 pmbox
->un
.varWords
[0],
2277 pmb
->vport
->port_state
);
2278 pmbox
->mbxStatus
= 0;
2279 pmbox
->mbxOwner
= OWN_HOST
;
2280 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2281 if (rc
!= MBX_NOT_FINISHED
)
2286 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2287 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2288 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2289 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2290 pmb
->vport
? pmb
->vport
->vpi
: 0,
2292 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2293 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2295 *((uint32_t *) pmbox
),
2296 pmbox
->un
.varWords
[0],
2297 pmbox
->un
.varWords
[1],
2298 pmbox
->un
.varWords
[2],
2299 pmbox
->un
.varWords
[3],
2300 pmbox
->un
.varWords
[4],
2301 pmbox
->un
.varWords
[5],
2302 pmbox
->un
.varWords
[6],
2303 pmbox
->un
.varWords
[7]);
2306 pmb
->mbox_cmpl(phba
,pmb
);
2312 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2313 * @phba: Pointer to HBA context object.
2314 * @pring: Pointer to driver SLI ring object.
2317 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2318 * is set in the tag the buffer is posted for a particular exchange,
2319 * the function will return the buffer without replacing the buffer.
2320 * If the buffer is for unsolicited ELS or CT traffic, this function
2321 * returns the buffer and also posts another buffer to the firmware.
2323 static struct lpfc_dmabuf
*
2324 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2325 struct lpfc_sli_ring
*pring
,
2328 struct hbq_dmabuf
*hbq_entry
;
2330 if (tag
& QUE_BUFTAG_BIT
)
2331 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2332 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2335 return &hbq_entry
->dbuf
;
2339 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2340 * @phba: Pointer to HBA context object.
2341 * @pring: Pointer to driver SLI ring object.
2342 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2343 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2344 * @fch_type: the type for the first frame of the sequence.
2346 * This function is called with no lock held. This function uses the r_ctl and
2347 * type of the received sequence to find the correct callback function to call
2348 * to process the sequence.
2351 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2352 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2357 /* unSolicited Responses */
2358 if (pring
->prt
[0].profile
) {
2359 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2360 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2364 /* We must search, based on rctl / type
2365 for the right routine */
2366 for (i
= 0; i
< pring
->num_mask
; i
++) {
2367 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2368 (pring
->prt
[i
].type
== fch_type
)) {
2369 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2370 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2371 (phba
, pring
, saveq
);
2379 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2380 * @phba: Pointer to HBA context object.
2381 * @pring: Pointer to driver SLI ring object.
2382 * @saveq: Pointer to the unsolicited iocb.
2384 * This function is called with no lock held by the ring event handler
2385 * when there is an unsolicited iocb posted to the response ring by the
2386 * firmware. This function gets the buffer associated with the iocbs
2387 * and calls the event handler for the ring. This function handles both
2388 * qring buffers and hbq buffers.
2389 * When the function returns 1 the caller can free the iocb object otherwise
2390 * upper layer functions will free the iocb objects.
2393 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2394 struct lpfc_iocbq
*saveq
)
2398 uint32_t Rctl
, Type
;
2400 struct lpfc_iocbq
*iocbq
;
2401 struct lpfc_dmabuf
*dmzbuf
;
2404 irsp
= &(saveq
->iocb
);
2406 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2407 if (pring
->lpfc_sli_rcv_async_status
)
2408 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2410 lpfc_printf_log(phba
,
2413 "0316 Ring %d handler: unexpected "
2414 "ASYNC_STATUS iocb received evt_code "
2417 irsp
->un
.asyncstat
.evt_code
);
2421 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2422 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2423 if (irsp
->ulpBdeCount
> 0) {
2424 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2425 irsp
->un
.ulpWord
[3]);
2426 lpfc_in_buf_free(phba
, dmzbuf
);
2429 if (irsp
->ulpBdeCount
> 1) {
2430 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2431 irsp
->unsli3
.sli3Words
[3]);
2432 lpfc_in_buf_free(phba
, dmzbuf
);
2435 if (irsp
->ulpBdeCount
> 2) {
2436 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2437 irsp
->unsli3
.sli3Words
[7]);
2438 lpfc_in_buf_free(phba
, dmzbuf
);
2444 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2445 if (irsp
->ulpBdeCount
!= 0) {
2446 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2447 irsp
->un
.ulpWord
[3]);
2448 if (!saveq
->context2
)
2449 lpfc_printf_log(phba
,
2452 "0341 Ring %d Cannot find buffer for "
2453 "an unsolicited iocb. tag 0x%x\n",
2455 irsp
->un
.ulpWord
[3]);
2457 if (irsp
->ulpBdeCount
== 2) {
2458 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2459 irsp
->unsli3
.sli3Words
[7]);
2460 if (!saveq
->context3
)
2461 lpfc_printf_log(phba
,
2464 "0342 Ring %d Cannot find buffer for an"
2465 " unsolicited iocb. tag 0x%x\n",
2467 irsp
->unsli3
.sli3Words
[7]);
2469 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2470 irsp
= &(iocbq
->iocb
);
2471 if (irsp
->ulpBdeCount
!= 0) {
2472 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2473 irsp
->un
.ulpWord
[3]);
2474 if (!iocbq
->context2
)
2475 lpfc_printf_log(phba
,
2478 "0343 Ring %d Cannot find "
2479 "buffer for an unsolicited iocb"
2480 ". tag 0x%x\n", pring
->ringno
,
2481 irsp
->un
.ulpWord
[3]);
2483 if (irsp
->ulpBdeCount
== 2) {
2484 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2485 irsp
->unsli3
.sli3Words
[7]);
2486 if (!iocbq
->context3
)
2487 lpfc_printf_log(phba
,
2490 "0344 Ring %d Cannot find "
2491 "buffer for an unsolicited "
2494 irsp
->unsli3
.sli3Words
[7]);
2498 if (irsp
->ulpBdeCount
!= 0 &&
2499 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2500 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2503 /* search continue save q for same XRI */
2504 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2505 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2506 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2507 list_add_tail(&saveq
->list
, &iocbq
->list
);
2513 list_add_tail(&saveq
->clist
,
2514 &pring
->iocb_continue_saveq
);
2515 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2516 list_del_init(&iocbq
->clist
);
2518 irsp
= &(saveq
->iocb
);
2522 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2523 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2524 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2525 Rctl
= FC_RCTL_ELS_REQ
;
2528 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2529 Rctl
= w5p
->hcsw
.Rctl
;
2530 Type
= w5p
->hcsw
.Type
;
2532 /* Firmware Workaround */
2533 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2534 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2535 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2536 Rctl
= FC_RCTL_ELS_REQ
;
2538 w5p
->hcsw
.Rctl
= Rctl
;
2539 w5p
->hcsw
.Type
= Type
;
2543 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2544 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2545 "0313 Ring %d handler: unexpected Rctl x%x "
2546 "Type x%x received\n",
2547 pring
->ringno
, Rctl
, Type
);
2553 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2554 * @phba: Pointer to HBA context object.
2555 * @pring: Pointer to driver SLI ring object.
2556 * @prspiocb: Pointer to response iocb object.
2558 * This function looks up the iocb_lookup table to get the command iocb
2559 * corresponding to the given response iocb using the iotag of the
2560 * response iocb. This function is called with the hbalock held.
2561 * This function returns the command iocb object if it finds the command
2562 * iocb else returns NULL.
2564 static struct lpfc_iocbq
*
2565 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2566 struct lpfc_sli_ring
*pring
,
2567 struct lpfc_iocbq
*prspiocb
)
2569 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2572 iotag
= prspiocb
->iocb
.ulpIoTag
;
2574 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2575 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2576 list_del_init(&cmd_iocb
->list
);
2577 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
2578 pring
->txcmplq_cnt
--;
2579 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
2584 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2585 "0317 iotag x%x is out off "
2586 "range: max iotag x%x wd0 x%x\n",
2587 iotag
, phba
->sli
.last_iotag
,
2588 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2593 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2594 * @phba: Pointer to HBA context object.
2595 * @pring: Pointer to driver SLI ring object.
2598 * This function looks up the iocb_lookup table to get the command iocb
2599 * corresponding to the given iotag. This function is called with the
2601 * This function returns the command iocb object if it finds the command
2602 * iocb else returns NULL.
2604 static struct lpfc_iocbq
*
2605 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2606 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2608 struct lpfc_iocbq
*cmd_iocb
;
2610 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2611 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2612 list_del_init(&cmd_iocb
->list
);
2613 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_Q
) {
2614 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_Q
;
2615 pring
->txcmplq_cnt
--;
2620 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2621 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2622 iotag
, phba
->sli
.last_iotag
);
2627 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2628 * @phba: Pointer to HBA context object.
2629 * @pring: Pointer to driver SLI ring object.
2630 * @saveq: Pointer to the response iocb to be processed.
2632 * This function is called by the ring event handler for non-fcp
2633 * rings when there is a new response iocb in the response ring.
2634 * The caller is not required to hold any locks. This function
2635 * gets the command iocb associated with the response iocb and
2636 * calls the completion handler for the command iocb. If there
2637 * is no completion handler, the function will free the resources
2638 * associated with command iocb. If the response iocb is for
2639 * an already aborted command iocb, the status of the completion
2640 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2641 * This function always returns 1.
2644 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2645 struct lpfc_iocbq
*saveq
)
2647 struct lpfc_iocbq
*cmdiocbp
;
2649 unsigned long iflag
;
2651 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2652 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2653 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2654 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2657 if (cmdiocbp
->iocb_cmpl
) {
2659 * If an ELS command failed send an event to mgmt
2662 if (saveq
->iocb
.ulpStatus
&&
2663 (pring
->ringno
== LPFC_ELS_RING
) &&
2664 (cmdiocbp
->iocb
.ulpCommand
==
2665 CMD_ELS_REQUEST64_CR
))
2666 lpfc_send_els_failure_event(phba
,
2670 * Post all ELS completions to the worker thread.
2671 * All other are passed to the completion callback.
2673 if (pring
->ringno
== LPFC_ELS_RING
) {
2674 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2675 (cmdiocbp
->iocb_flag
&
2676 LPFC_DRIVER_ABORTED
)) {
2677 spin_lock_irqsave(&phba
->hbalock
,
2679 cmdiocbp
->iocb_flag
&=
2680 ~LPFC_DRIVER_ABORTED
;
2681 spin_unlock_irqrestore(&phba
->hbalock
,
2683 saveq
->iocb
.ulpStatus
=
2684 IOSTAT_LOCAL_REJECT
;
2685 saveq
->iocb
.un
.ulpWord
[4] =
2688 /* Firmware could still be in progress
2689 * of DMAing payload, so don't free data
2690 * buffer till after a hbeat.
2692 spin_lock_irqsave(&phba
->hbalock
,
2694 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2695 spin_unlock_irqrestore(&phba
->hbalock
,
2698 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2699 if (saveq
->iocb_flag
&
2700 LPFC_EXCHANGE_BUSY
) {
2701 /* Set cmdiocb flag for the
2702 * exchange busy so sgl (xri)
2703 * will not be released until
2704 * the abort xri is received
2708 &phba
->hbalock
, iflag
);
2709 cmdiocbp
->iocb_flag
|=
2711 spin_unlock_irqrestore(
2712 &phba
->hbalock
, iflag
);
2714 if (cmdiocbp
->iocb_flag
&
2715 LPFC_DRIVER_ABORTED
) {
2717 * Clear LPFC_DRIVER_ABORTED
2718 * bit in case it was driver
2722 &phba
->hbalock
, iflag
);
2723 cmdiocbp
->iocb_flag
&=
2724 ~LPFC_DRIVER_ABORTED
;
2725 spin_unlock_irqrestore(
2726 &phba
->hbalock
, iflag
);
2727 cmdiocbp
->iocb
.ulpStatus
=
2728 IOSTAT_LOCAL_REJECT
;
2729 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2730 IOERR_ABORT_REQUESTED
;
2732 * For SLI4, irsiocb contains
2733 * NO_XRI in sli_xritag, it
2734 * shall not affect releasing
2735 * sgl (xri) process.
2737 saveq
->iocb
.ulpStatus
=
2738 IOSTAT_LOCAL_REJECT
;
2739 saveq
->iocb
.un
.ulpWord
[4] =
2742 &phba
->hbalock
, iflag
);
2744 LPFC_DELAY_MEM_FREE
;
2745 spin_unlock_irqrestore(
2746 &phba
->hbalock
, iflag
);
2750 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2752 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2755 * Unknown initiating command based on the response iotag.
2756 * This could be the case on the ELS ring because of
2759 if (pring
->ringno
!= LPFC_ELS_RING
) {
2761 * Ring <ringno> handler: unexpected completion IoTag
2764 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2765 "0322 Ring %d handler: "
2766 "unexpected completion IoTag x%x "
2767 "Data: x%x x%x x%x x%x\n",
2769 saveq
->iocb
.ulpIoTag
,
2770 saveq
->iocb
.ulpStatus
,
2771 saveq
->iocb
.un
.ulpWord
[4],
2772 saveq
->iocb
.ulpCommand
,
2773 saveq
->iocb
.ulpContext
);
2781 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2782 * @phba: Pointer to HBA context object.
2783 * @pring: Pointer to driver SLI ring object.
2785 * This function is called from the iocb ring event handlers when
2786 * put pointer is ahead of the get pointer for a ring. This function signal
2787 * an error attention condition to the worker thread and the worker
2788 * thread will transition the HBA to offline state.
2791 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2793 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2795 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2796 * rsp ring <portRspMax>
2798 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2799 "0312 Ring %d handler: portRspPut %d "
2800 "is bigger than rsp ring %d\n",
2801 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2804 phba
->link_state
= LPFC_HBA_ERROR
;
2807 * All error attention handlers are posted to
2810 phba
->work_ha
|= HA_ERATT
;
2811 phba
->work_hs
= HS_FFER3
;
2813 lpfc_worker_wake_up(phba
);
2819 * lpfc_poll_eratt - Error attention polling timer timeout handler
2820 * @ptr: Pointer to address of HBA context object.
2822 * This function is invoked by the Error Attention polling timer when the
2823 * timer times out. It will check the SLI Error Attention register for
2824 * possible attention events. If so, it will post an Error Attention event
2825 * and wake up worker thread to process it. Otherwise, it will set up the
2826 * Error Attention polling timer for the next poll.
2828 void lpfc_poll_eratt(unsigned long ptr
)
2830 struct lpfc_hba
*phba
;
2833 phba
= (struct lpfc_hba
*)ptr
;
2835 /* Check chip HA register for error event */
2836 eratt
= lpfc_sli_check_eratt(phba
);
2839 /* Tell the worker thread there is work to do */
2840 lpfc_worker_wake_up(phba
);
2842 /* Restart the timer for next eratt poll */
2843 mod_timer(&phba
->eratt_poll
, jiffies
+
2844 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2850 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2851 * @phba: Pointer to HBA context object.
2852 * @pring: Pointer to driver SLI ring object.
2853 * @mask: Host attention register mask for this ring.
2855 * This function is called from the interrupt context when there is a ring
2856 * event for the fcp ring. The caller does not hold any lock.
2857 * The function processes each response iocb in the response ring until it
2858 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2859 * LE bit set. The function will call the completion handler of the command iocb
2860 * if the response iocb indicates a completion for a command iocb or it is
2861 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2862 * function if this is an unsolicited iocb.
2863 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2864 * to check it explicitly.
2867 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2868 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2870 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2871 IOCB_t
*irsp
= NULL
;
2872 IOCB_t
*entry
= NULL
;
2873 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2874 struct lpfc_iocbq rspiocbq
;
2876 uint32_t portRspPut
, portRspMax
;
2878 lpfc_iocb_type type
;
2879 unsigned long iflag
;
2880 uint32_t rsp_cmpl
= 0;
2882 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2883 pring
->stats
.iocb_event
++;
2886 * The next available response entry should never exceed the maximum
2887 * entries. If it does, treat it as an adapter hardware error.
2889 portRspMax
= pring
->numRiocb
;
2890 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2891 if (unlikely(portRspPut
>= portRspMax
)) {
2892 lpfc_sli_rsp_pointers_error(phba
, pring
);
2893 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2896 if (phba
->fcp_ring_in_use
) {
2897 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2900 phba
->fcp_ring_in_use
= 1;
2903 while (pring
->rspidx
!= portRspPut
) {
2905 * Fetch an entry off the ring and copy it into a local data
2906 * structure. The copy involves a byte-swap since the
2907 * network byte order and pci byte orders are different.
2909 entry
= lpfc_resp_iocb(phba
, pring
);
2910 phba
->last_completion_time
= jiffies
;
2912 if (++pring
->rspidx
>= portRspMax
)
2915 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2916 (uint32_t *) &rspiocbq
.iocb
,
2917 phba
->iocb_rsp_size
);
2918 INIT_LIST_HEAD(&(rspiocbq
.list
));
2919 irsp
= &rspiocbq
.iocb
;
2921 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2922 pring
->stats
.iocb_rsp
++;
2925 if (unlikely(irsp
->ulpStatus
)) {
2927 * If resource errors reported from HBA, reduce
2928 * queuedepths of the SCSI device.
2930 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2931 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
2932 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2933 phba
->lpfc_rampdown_queue_depth(phba
);
2934 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2937 /* Rsp ring <ringno> error: IOCB */
2938 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2939 "0336 Rsp Ring %d error: IOCB Data: "
2940 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
2942 irsp
->un
.ulpWord
[0],
2943 irsp
->un
.ulpWord
[1],
2944 irsp
->un
.ulpWord
[2],
2945 irsp
->un
.ulpWord
[3],
2946 irsp
->un
.ulpWord
[4],
2947 irsp
->un
.ulpWord
[5],
2948 *(uint32_t *)&irsp
->un1
,
2949 *((uint32_t *)&irsp
->un1
+ 1));
2953 case LPFC_ABORT_IOCB
:
2956 * Idle exchange closed via ABTS from port. No iocb
2957 * resources need to be recovered.
2959 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
2960 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2961 "0333 IOCB cmd 0x%x"
2962 " processed. Skipping"
2968 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
2970 if (unlikely(!cmdiocbq
))
2972 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
2973 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
2974 if (cmdiocbq
->iocb_cmpl
) {
2975 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2976 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
2978 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2981 case LPFC_UNSOL_IOCB
:
2982 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2983 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
2984 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2987 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
2988 char adaptermsg
[LPFC_MAX_ADPTMSG
];
2989 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
2990 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
2992 dev_warn(&((phba
->pcidev
)->dev
),
2994 phba
->brd_no
, adaptermsg
);
2996 /* Unknown IOCB command */
2997 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2998 "0334 Unknown IOCB command "
2999 "Data: x%x, x%x x%x x%x x%x\n",
3000 type
, irsp
->ulpCommand
,
3009 * The response IOCB has been processed. Update the ring
3010 * pointer in SLIM. If the port response put pointer has not
3011 * been updated, sync the pgp->rspPutInx and fetch the new port
3012 * response put pointer.
3014 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3016 if (pring
->rspidx
== portRspPut
)
3017 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3020 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3021 pring
->stats
.iocb_rsp_full
++;
3022 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3023 writel(status
, phba
->CAregaddr
);
3024 readl(phba
->CAregaddr
);
3026 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3027 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3028 pring
->stats
.iocb_cmd_empty
++;
3030 /* Force update of the local copy of cmdGetInx */
3031 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3032 lpfc_sli_resume_iocb(phba
, pring
);
3034 if ((pring
->lpfc_sli_cmd_available
))
3035 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3039 phba
->fcp_ring_in_use
= 0;
3040 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3045 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3046 * @phba: Pointer to HBA context object.
3047 * @pring: Pointer to driver SLI ring object.
3048 * @rspiocbp: Pointer to driver response IOCB object.
3050 * This function is called from the worker thread when there is a slow-path
3051 * response IOCB to process. This function chains all the response iocbs until
3052 * seeing the iocb with the LE bit set. The function will call
3053 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3054 * completion of a command iocb. The function will call the
3055 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3056 * The function frees the resources or calls the completion handler if this
3057 * iocb is an abort completion. The function returns NULL when the response
3058 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3059 * this function shall chain the iocb on to the iocb_continueq and return the
3060 * response iocb passed in.
3062 static struct lpfc_iocbq
*
3063 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3064 struct lpfc_iocbq
*rspiocbp
)
3066 struct lpfc_iocbq
*saveq
;
3067 struct lpfc_iocbq
*cmdiocbp
;
3068 struct lpfc_iocbq
*next_iocb
;
3069 IOCB_t
*irsp
= NULL
;
3070 uint32_t free_saveq
;
3071 uint8_t iocb_cmd_type
;
3072 lpfc_iocb_type type
;
3073 unsigned long iflag
;
3076 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3077 /* First add the response iocb to the countinueq list */
3078 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3079 pring
->iocb_continueq_cnt
++;
3081 /* Now, determine whether the list is completed for processing */
3082 irsp
= &rspiocbp
->iocb
;
3085 * By default, the driver expects to free all resources
3086 * associated with this iocb completion.
3089 saveq
= list_get_first(&pring
->iocb_continueq
,
3090 struct lpfc_iocbq
, list
);
3091 irsp
= &(saveq
->iocb
);
3092 list_del_init(&pring
->iocb_continueq
);
3093 pring
->iocb_continueq_cnt
= 0;
3095 pring
->stats
.iocb_rsp
++;
3098 * If resource errors reported from HBA, reduce
3099 * queuedepths of the SCSI device.
3101 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3102 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
3103 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3104 phba
->lpfc_rampdown_queue_depth(phba
);
3105 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3108 if (irsp
->ulpStatus
) {
3109 /* Rsp ring <ringno> error: IOCB */
3110 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3111 "0328 Rsp Ring %d error: "
3116 "x%x x%x x%x x%x\n",
3118 irsp
->un
.ulpWord
[0],
3119 irsp
->un
.ulpWord
[1],
3120 irsp
->un
.ulpWord
[2],
3121 irsp
->un
.ulpWord
[3],
3122 irsp
->un
.ulpWord
[4],
3123 irsp
->un
.ulpWord
[5],
3124 *(((uint32_t *) irsp
) + 6),
3125 *(((uint32_t *) irsp
) + 7),
3126 *(((uint32_t *) irsp
) + 8),
3127 *(((uint32_t *) irsp
) + 9),
3128 *(((uint32_t *) irsp
) + 10),
3129 *(((uint32_t *) irsp
) + 11),
3130 *(((uint32_t *) irsp
) + 12),
3131 *(((uint32_t *) irsp
) + 13),
3132 *(((uint32_t *) irsp
) + 14),
3133 *(((uint32_t *) irsp
) + 15));
3137 * Fetch the IOCB command type and call the correct completion
3138 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3139 * get freed back to the lpfc_iocb_list by the discovery
3142 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3143 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3146 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3147 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3148 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3151 case LPFC_UNSOL_IOCB
:
3152 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3153 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3154 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3159 case LPFC_ABORT_IOCB
:
3161 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3162 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3165 /* Call the specified completion routine */
3166 if (cmdiocbp
->iocb_cmpl
) {
3167 spin_unlock_irqrestore(&phba
->hbalock
,
3169 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3171 spin_lock_irqsave(&phba
->hbalock
,
3174 __lpfc_sli_release_iocbq(phba
,
3179 case LPFC_UNKNOWN_IOCB
:
3180 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3181 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3182 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3183 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3185 dev_warn(&((phba
->pcidev
)->dev
),
3187 phba
->brd_no
, adaptermsg
);
3189 /* Unknown IOCB command */
3190 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3191 "0335 Unknown IOCB "
3192 "command Data: x%x "
3203 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3204 &saveq
->list
, list
) {
3205 list_del(&rspiocbp
->list
);
3206 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3208 __lpfc_sli_release_iocbq(phba
, saveq
);
3212 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3217 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3218 * @phba: Pointer to HBA context object.
3219 * @pring: Pointer to driver SLI ring object.
3220 * @mask: Host attention register mask for this ring.
3222 * This routine wraps the actual slow_ring event process routine from the
3223 * API jump table function pointer from the lpfc_hba struct.
3226 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3227 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3229 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3233 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3234 * @phba: Pointer to HBA context object.
3235 * @pring: Pointer to driver SLI ring object.
3236 * @mask: Host attention register mask for this ring.
3238 * This function is called from the worker thread when there is a ring event
3239 * for non-fcp rings. The caller does not hold any lock. The function will
3240 * remove each response iocb in the response ring and calls the handle
3241 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3244 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3245 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3247 struct lpfc_pgp
*pgp
;
3249 IOCB_t
*irsp
= NULL
;
3250 struct lpfc_iocbq
*rspiocbp
= NULL
;
3251 uint32_t portRspPut
, portRspMax
;
3252 unsigned long iflag
;
3255 pgp
= &phba
->port_gp
[pring
->ringno
];
3256 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3257 pring
->stats
.iocb_event
++;
3260 * The next available response entry should never exceed the maximum
3261 * entries. If it does, treat it as an adapter hardware error.
3263 portRspMax
= pring
->numRiocb
;
3264 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3265 if (portRspPut
>= portRspMax
) {
3267 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3268 * rsp ring <portRspMax>
3270 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3271 "0303 Ring %d handler: portRspPut %d "
3272 "is bigger than rsp ring %d\n",
3273 pring
->ringno
, portRspPut
, portRspMax
);
3275 phba
->link_state
= LPFC_HBA_ERROR
;
3276 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3278 phba
->work_hs
= HS_FFER3
;
3279 lpfc_handle_eratt(phba
);
3285 while (pring
->rspidx
!= portRspPut
) {
3287 * Build a completion list and call the appropriate handler.
3288 * The process is to get the next available response iocb, get
3289 * a free iocb from the list, copy the response data into the
3290 * free iocb, insert to the continuation list, and update the
3291 * next response index to slim. This process makes response
3292 * iocb's in the ring available to DMA as fast as possible but
3293 * pays a penalty for a copy operation. Since the iocb is
3294 * only 32 bytes, this penalty is considered small relative to
3295 * the PCI reads for register values and a slim write. When
3296 * the ulpLe field is set, the entire Command has been
3299 entry
= lpfc_resp_iocb(phba
, pring
);
3301 phba
->last_completion_time
= jiffies
;
3302 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3303 if (rspiocbp
== NULL
) {
3304 printk(KERN_ERR
"%s: out of buffers! Failing "
3305 "completion.\n", __func__
);
3309 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3310 phba
->iocb_rsp_size
);
3311 irsp
= &rspiocbp
->iocb
;
3313 if (++pring
->rspidx
>= portRspMax
)
3316 if (pring
->ringno
== LPFC_ELS_RING
) {
3317 lpfc_debugfs_slow_ring_trc(phba
,
3318 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3319 *(((uint32_t *) irsp
) + 4),
3320 *(((uint32_t *) irsp
) + 6),
3321 *(((uint32_t *) irsp
) + 7));
3324 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3326 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3327 /* Handle the response IOCB */
3328 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3329 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3332 * If the port response put pointer has not been updated, sync
3333 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3334 * response put pointer.
3336 if (pring
->rspidx
== portRspPut
) {
3337 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3339 } /* while (pring->rspidx != portRspPut) */
3341 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3342 /* At least one response entry has been freed */
3343 pring
->stats
.iocb_rsp_full
++;
3344 /* SET RxRE_RSP in Chip Att register */
3345 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3346 writel(status
, phba
->CAregaddr
);
3347 readl(phba
->CAregaddr
); /* flush */
3349 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3350 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3351 pring
->stats
.iocb_cmd_empty
++;
3353 /* Force update of the local copy of cmdGetInx */
3354 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3355 lpfc_sli_resume_iocb(phba
, pring
);
3357 if ((pring
->lpfc_sli_cmd_available
))
3358 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3362 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3367 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3368 * @phba: Pointer to HBA context object.
3369 * @pring: Pointer to driver SLI ring object.
3370 * @mask: Host attention register mask for this ring.
3372 * This function is called from the worker thread when there is a pending
3373 * ELS response iocb on the driver internal slow-path response iocb worker
3374 * queue. The caller does not hold any lock. The function will remove each
3375 * response iocb from the response worker queue and calls the handle
3376 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3379 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3380 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3382 struct lpfc_iocbq
*irspiocbq
;
3383 struct hbq_dmabuf
*dmabuf
;
3384 struct lpfc_cq_event
*cq_event
;
3385 unsigned long iflag
;
3387 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3388 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3389 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3390 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3391 /* Get the response iocb from the head of work queue */
3392 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3393 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3394 cq_event
, struct lpfc_cq_event
, list
);
3395 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3397 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3398 case CQE_CODE_COMPL_WQE
:
3399 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3401 /* Translate ELS WCQE to response IOCBQ */
3402 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3405 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3408 case CQE_CODE_RECEIVE
:
3409 case CQE_CODE_RECEIVE_V1
:
3410 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3412 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3421 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3422 * @phba: Pointer to HBA context object.
3423 * @pring: Pointer to driver SLI ring object.
3425 * This function aborts all iocbs in the given ring and frees all the iocb
3426 * objects in txq. This function issues an abort iocb for all the iocb commands
3427 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3428 * the return of this function. The caller is not required to hold any locks.
3431 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3433 LIST_HEAD(completions
);
3434 struct lpfc_iocbq
*iocb
, *next_iocb
;
3436 if (pring
->ringno
== LPFC_ELS_RING
) {
3437 lpfc_fabric_abort_hba(phba
);
3440 /* Error everything on txq and txcmplq
3443 spin_lock_irq(&phba
->hbalock
);
3444 list_splice_init(&pring
->txq
, &completions
);
3447 /* Next issue ABTS for everything on the txcmplq */
3448 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3449 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3451 spin_unlock_irq(&phba
->hbalock
);
3453 /* Cancel all the IOCBs from the completions list */
3454 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3459 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3460 * @phba: Pointer to HBA context object.
3462 * This function flushes all iocbs in the fcp ring and frees all the iocb
3463 * objects in txq and txcmplq. This function will not issue abort iocbs
3464 * for all the iocb commands in txcmplq, they will just be returned with
3465 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3466 * slot has been permanently disabled.
3469 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3473 struct lpfc_sli
*psli
= &phba
->sli
;
3474 struct lpfc_sli_ring
*pring
;
3476 /* Currently, only one fcp ring */
3477 pring
= &psli
->ring
[psli
->fcp_ring
];
3479 spin_lock_irq(&phba
->hbalock
);
3480 /* Retrieve everything on txq */
3481 list_splice_init(&pring
->txq
, &txq
);
3484 /* Retrieve everything on the txcmplq */
3485 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3486 pring
->txcmplq_cnt
= 0;
3487 spin_unlock_irq(&phba
->hbalock
);
3490 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3493 /* Flush the txcmpq */
3494 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3499 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3500 * @phba: Pointer to HBA context object.
3501 * @mask: Bit mask to be checked.
3503 * This function reads the host status register and compares
3504 * with the provided bit mask to check if HBA completed
3505 * the restart. This function will wait in a loop for the
3506 * HBA to complete restart. If the HBA does not restart within
3507 * 15 iterations, the function will reset the HBA again. The
3508 * function returns 1 when HBA fail to restart otherwise returns
3512 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3518 /* Read the HBA Host Status Register */
3519 if (lpfc_readl(phba
->HSregaddr
, &status
))
3523 * Check status register every 100ms for 5 retries, then every
3524 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3525 * every 2.5 sec for 4.
3526 * Break our of the loop if errors occurred during init.
3528 while (((status
& mask
) != mask
) &&
3529 !(status
& HS_FFERM
) &&
3541 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3542 lpfc_sli_brdrestart(phba
);
3544 /* Read the HBA Host Status Register */
3545 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3551 /* Check to see if any errors occurred during init */
3552 if ((status
& HS_FFERM
) || (i
>= 20)) {
3553 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3554 "2751 Adapter failed to restart, "
3555 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3557 readl(phba
->MBslimaddr
+ 0xa8),
3558 readl(phba
->MBslimaddr
+ 0xac));
3559 phba
->link_state
= LPFC_HBA_ERROR
;
3567 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3568 * @phba: Pointer to HBA context object.
3569 * @mask: Bit mask to be checked.
3571 * This function checks the host status register to check if HBA is
3572 * ready. This function will wait in a loop for the HBA to be ready
3573 * If the HBA is not ready , the function will will reset the HBA PCI
3574 * function again. The function returns 1 when HBA fail to be ready
3575 * otherwise returns zero.
3578 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3583 /* Read the HBA Host Status Register */
3584 status
= lpfc_sli4_post_status_check(phba
);
3587 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3588 lpfc_sli_brdrestart(phba
);
3589 status
= lpfc_sli4_post_status_check(phba
);
3592 /* Check to see if any errors occurred during init */
3594 phba
->link_state
= LPFC_HBA_ERROR
;
3597 phba
->sli4_hba
.intr_enable
= 0;
3603 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3604 * @phba: Pointer to HBA context object.
3605 * @mask: Bit mask to be checked.
3607 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3608 * from the API jump table function pointer from the lpfc_hba struct.
3611 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3613 return phba
->lpfc_sli_brdready(phba
, mask
);
3616 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3619 * lpfc_reset_barrier - Make HBA ready for HBA reset
3620 * @phba: Pointer to HBA context object.
3622 * This function is called before resetting an HBA. This function is called
3623 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3625 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3627 uint32_t __iomem
*resp_buf
;
3628 uint32_t __iomem
*mbox_buf
;
3629 volatile uint32_t mbox
;
3630 uint32_t hc_copy
, ha_copy
, resp_data
;
3634 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3635 if (hdrtype
!= 0x80 ||
3636 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3637 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3641 * Tell the other part of the chip to suspend temporarily all
3644 resp_buf
= phba
->MBslimaddr
;
3646 /* Disable the error attention */
3647 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3649 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3650 readl(phba
->HCregaddr
); /* flush */
3651 phba
->link_flag
|= LS_IGNORE_ERATT
;
3653 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3655 if (ha_copy
& HA_ERATT
) {
3656 /* Clear Chip error bit */
3657 writel(HA_ERATT
, phba
->HAregaddr
);
3658 phba
->pport
->stopped
= 1;
3662 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3663 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3665 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3666 mbox_buf
= phba
->MBslimaddr
;
3667 writel(mbox
, mbox_buf
);
3669 for (i
= 0; i
< 50; i
++) {
3670 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3672 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3678 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3680 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3681 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3682 phba
->pport
->stopped
)
3688 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3690 for (i
= 0; i
< 500; i
++) {
3691 if (lpfc_readl(resp_buf
, &resp_data
))
3693 if (resp_data
!= mbox
)
3702 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3704 if (!(ha_copy
& HA_ERATT
))
3710 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3711 writel(HA_ERATT
, phba
->HAregaddr
);
3712 phba
->pport
->stopped
= 1;
3716 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3717 writel(hc_copy
, phba
->HCregaddr
);
3718 readl(phba
->HCregaddr
); /* flush */
3722 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3723 * @phba: Pointer to HBA context object.
3725 * This function issues a kill_board mailbox command and waits for
3726 * the error attention interrupt. This function is called for stopping
3727 * the firmware processing. The caller is not required to hold any
3728 * locks. This function calls lpfc_hba_down_post function to free
3729 * any pending commands after the kill. The function will return 1 when it
3730 * fails to kill the board else will return 0.
3733 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3735 struct lpfc_sli
*psli
;
3745 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3746 "0329 Kill HBA Data: x%x x%x\n",
3747 phba
->pport
->port_state
, psli
->sli_flag
);
3749 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3753 /* Disable the error attention */
3754 spin_lock_irq(&phba
->hbalock
);
3755 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3756 spin_unlock_irq(&phba
->hbalock
);
3757 mempool_free(pmb
, phba
->mbox_mem_pool
);
3760 status
&= ~HC_ERINT_ENA
;
3761 writel(status
, phba
->HCregaddr
);
3762 readl(phba
->HCregaddr
); /* flush */
3763 phba
->link_flag
|= LS_IGNORE_ERATT
;
3764 spin_unlock_irq(&phba
->hbalock
);
3766 lpfc_kill_board(phba
, pmb
);
3767 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3768 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3770 if (retval
!= MBX_SUCCESS
) {
3771 if (retval
!= MBX_BUSY
)
3772 mempool_free(pmb
, phba
->mbox_mem_pool
);
3773 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3774 "2752 KILL_BOARD command failed retval %d\n",
3776 spin_lock_irq(&phba
->hbalock
);
3777 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3778 spin_unlock_irq(&phba
->hbalock
);
3782 spin_lock_irq(&phba
->hbalock
);
3783 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3784 spin_unlock_irq(&phba
->hbalock
);
3786 mempool_free(pmb
, phba
->mbox_mem_pool
);
3788 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3789 * attention every 100ms for 3 seconds. If we don't get ERATT after
3790 * 3 seconds we still set HBA_ERROR state because the status of the
3791 * board is now undefined.
3793 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3795 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3797 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3801 del_timer_sync(&psli
->mbox_tmo
);
3802 if (ha_copy
& HA_ERATT
) {
3803 writel(HA_ERATT
, phba
->HAregaddr
);
3804 phba
->pport
->stopped
= 1;
3806 spin_lock_irq(&phba
->hbalock
);
3807 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3808 psli
->mbox_active
= NULL
;
3809 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3810 spin_unlock_irq(&phba
->hbalock
);
3812 lpfc_hba_down_post(phba
);
3813 phba
->link_state
= LPFC_HBA_ERROR
;
3815 return ha_copy
& HA_ERATT
? 0 : 1;
3819 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3820 * @phba: Pointer to HBA context object.
3822 * This function resets the HBA by writing HC_INITFF to the control
3823 * register. After the HBA resets, this function resets all the iocb ring
3824 * indices. This function disables PCI layer parity checking during
3826 * This function returns 0 always.
3827 * The caller is not required to hold any locks.
3830 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3832 struct lpfc_sli
*psli
;
3833 struct lpfc_sli_ring
*pring
;
3840 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3841 "0325 Reset HBA Data: x%x x%x\n",
3842 phba
->pport
->port_state
, psli
->sli_flag
);
3844 /* perform board reset */
3845 phba
->fc_eventTag
= 0;
3846 phba
->link_events
= 0;
3847 phba
->pport
->fc_myDID
= 0;
3848 phba
->pport
->fc_prevDID
= 0;
3850 /* Turn off parity checking and serr during the physical reset */
3851 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3852 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3854 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3856 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3858 /* Now toggle INITFF bit in the Host Control Register */
3859 writel(HC_INITFF
, phba
->HCregaddr
);
3861 readl(phba
->HCregaddr
); /* flush */
3862 writel(0, phba
->HCregaddr
);
3863 readl(phba
->HCregaddr
); /* flush */
3865 /* Restore PCI cmd register */
3866 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3868 /* Initialize relevant SLI info */
3869 for (i
= 0; i
< psli
->num_rings
; i
++) {
3870 pring
= &psli
->ring
[i
];
3873 pring
->next_cmdidx
= 0;
3874 pring
->local_getidx
= 0;
3876 pring
->missbufcnt
= 0;
3879 phba
->link_state
= LPFC_WARM_START
;
3884 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3885 * @phba: Pointer to HBA context object.
3887 * This function resets a SLI4 HBA. This function disables PCI layer parity
3888 * checking during resets the device. The caller is not required to hold
3891 * This function returns 0 always.
3894 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3896 struct lpfc_sli
*psli
= &phba
->sli
;
3900 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3901 "0295 Reset HBA Data: x%x x%x\n",
3902 phba
->pport
->port_state
, psli
->sli_flag
);
3904 /* perform board reset */
3905 phba
->fc_eventTag
= 0;
3906 phba
->link_events
= 0;
3907 phba
->pport
->fc_myDID
= 0;
3908 phba
->pport
->fc_prevDID
= 0;
3910 spin_lock_irq(&phba
->hbalock
);
3911 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3912 phba
->fcf
.fcf_flag
= 0;
3913 spin_unlock_irq(&phba
->hbalock
);
3915 /* Now physically reset the device */
3916 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3917 "0389 Performing PCI function reset!\n");
3919 /* Turn off parity checking and serr during the physical reset */
3920 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3921 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3922 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3924 /* Perform FCoE PCI function reset */
3925 lpfc_sli4_queue_destroy(phba
);
3926 lpfc_pci_function_reset(phba
);
3928 /* Restore PCI cmd register */
3929 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3935 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
3936 * @phba: Pointer to HBA context object.
3938 * This function is called in the SLI initialization code path to
3939 * restart the HBA. The caller is not required to hold any lock.
3940 * This function writes MBX_RESTART mailbox command to the SLIM and
3941 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
3942 * function to free any pending commands. The function enables
3943 * POST only during the first initialization. The function returns zero.
3944 * The function does not guarantee completion of MBX_RESTART mailbox
3945 * command before the return of this function.
3948 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
3951 struct lpfc_sli
*psli
;
3952 volatile uint32_t word0
;
3953 void __iomem
*to_slim
;
3954 uint32_t hba_aer_enabled
;
3956 spin_lock_irq(&phba
->hbalock
);
3958 /* Take PCIe device Advanced Error Reporting (AER) state */
3959 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
3964 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3965 "0337 Restart HBA Data: x%x x%x\n",
3966 phba
->pport
->port_state
, psli
->sli_flag
);
3969 mb
= (MAILBOX_t
*) &word0
;
3970 mb
->mbxCommand
= MBX_RESTART
;
3973 lpfc_reset_barrier(phba
);
3975 to_slim
= phba
->MBslimaddr
;
3976 writel(*(uint32_t *) mb
, to_slim
);
3977 readl(to_slim
); /* flush */
3979 /* Only skip post after fc_ffinit is completed */
3980 if (phba
->pport
->port_state
)
3981 word0
= 1; /* This is really setting up word1 */
3983 word0
= 0; /* This is really setting up word1 */
3984 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
3985 writel(*(uint32_t *) mb
, to_slim
);
3986 readl(to_slim
); /* flush */
3988 lpfc_sli_brdreset(phba
);
3989 phba
->pport
->stopped
= 0;
3990 phba
->link_state
= LPFC_INIT_START
;
3992 spin_unlock_irq(&phba
->hbalock
);
3994 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
3995 psli
->stats_start
= get_seconds();
3997 /* Give the INITFF and Post time to settle. */
4000 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4001 if (hba_aer_enabled
)
4002 pci_disable_pcie_error_reporting(phba
->pcidev
);
4004 lpfc_hba_down_post(phba
);
4010 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4011 * @phba: Pointer to HBA context object.
4013 * This function is called in the SLI initialization code path to restart
4014 * a SLI4 HBA. The caller is not required to hold any lock.
4015 * At the end of the function, it calls lpfc_hba_down_post function to
4016 * free any pending commands.
4019 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4021 struct lpfc_sli
*psli
= &phba
->sli
;
4022 uint32_t hba_aer_enabled
;
4025 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4026 "0296 Restart HBA Data: x%x x%x\n",
4027 phba
->pport
->port_state
, psli
->sli_flag
);
4029 /* Take PCIe device Advanced Error Reporting (AER) state */
4030 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4032 lpfc_sli4_brdreset(phba
);
4034 spin_lock_irq(&phba
->hbalock
);
4035 phba
->pport
->stopped
= 0;
4036 phba
->link_state
= LPFC_INIT_START
;
4038 spin_unlock_irq(&phba
->hbalock
);
4040 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4041 psli
->stats_start
= get_seconds();
4043 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4044 if (hba_aer_enabled
)
4045 pci_disable_pcie_error_reporting(phba
->pcidev
);
4047 lpfc_hba_down_post(phba
);
4053 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4054 * @phba: Pointer to HBA context object.
4056 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4057 * API jump table function pointer from the lpfc_hba struct.
4060 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4062 return phba
->lpfc_sli_brdrestart(phba
);
4066 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4067 * @phba: Pointer to HBA context object.
4069 * This function is called after a HBA restart to wait for successful
4070 * restart of the HBA. Successful restart of the HBA is indicated by
4071 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4072 * iteration, the function will restart the HBA again. The function returns
4073 * zero if HBA successfully restarted else returns negative error code.
4076 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4078 uint32_t status
, i
= 0;
4080 /* Read the HBA Host Status Register */
4081 if (lpfc_readl(phba
->HSregaddr
, &status
))
4084 /* Check status register to see what current state is */
4086 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4088 /* Check every 10ms for 10 retries, then every 100ms for 90
4089 * retries, then every 1 sec for 50 retires for a total of
4090 * ~60 seconds before reset the board again and check every
4091 * 1 sec for 50 retries. The up to 60 seconds before the
4092 * board ready is required by the Falcon FIPS zeroization
4093 * complete, and any reset the board in between shall cause
4094 * restart of zeroization, further delay the board ready.
4097 /* Adapter failed to init, timeout, status reg
4099 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4100 "0436 Adapter failed to init, "
4101 "timeout, status reg x%x, "
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 /* Check to see if any errors occurred during init */
4110 if (status
& HS_FFERM
) {
4111 /* ERROR: During chipset initialization */
4112 /* Adapter failed to init, chipset, status reg
4114 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4115 "0437 Adapter failed to init, "
4116 "chipset, status reg x%x, "
4117 "FW Data: A8 x%x AC x%x\n", status
,
4118 readl(phba
->MBslimaddr
+ 0xa8),
4119 readl(phba
->MBslimaddr
+ 0xac));
4120 phba
->link_state
= LPFC_HBA_ERROR
;
4133 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4134 lpfc_sli_brdrestart(phba
);
4136 /* Read the HBA Host Status Register */
4137 if (lpfc_readl(phba
->HSregaddr
, &status
))
4141 /* Check to see if any errors occurred during init */
4142 if (status
& HS_FFERM
) {
4143 /* ERROR: During chipset initialization */
4144 /* Adapter failed to init, chipset, status reg <status> */
4145 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4146 "0438 Adapter failed to init, chipset, "
4148 "FW Data: A8 x%x AC x%x\n", status
,
4149 readl(phba
->MBslimaddr
+ 0xa8),
4150 readl(phba
->MBslimaddr
+ 0xac));
4151 phba
->link_state
= LPFC_HBA_ERROR
;
4155 /* Clear all interrupt enable conditions */
4156 writel(0, phba
->HCregaddr
);
4157 readl(phba
->HCregaddr
); /* flush */
4159 /* setup host attn register */
4160 writel(0xffffffff, phba
->HAregaddr
);
4161 readl(phba
->HAregaddr
); /* flush */
4166 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4168 * This function calculates and returns the number of HBQs required to be
4172 lpfc_sli_hbq_count(void)
4174 return ARRAY_SIZE(lpfc_hbq_defs
);
4178 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4180 * This function adds the number of hbq entries in every HBQ to get
4181 * the total number of hbq entries required for the HBA and returns
4185 lpfc_sli_hbq_entry_count(void)
4187 int hbq_count
= lpfc_sli_hbq_count();
4191 for (i
= 0; i
< hbq_count
; ++i
)
4192 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4197 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4199 * This function calculates amount of memory required for all hbq entries
4200 * to be configured and returns the total memory required.
4203 lpfc_sli_hbq_size(void)
4205 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4209 * lpfc_sli_hbq_setup - configure and initialize HBQs
4210 * @phba: Pointer to HBA context object.
4212 * This function is called during the SLI initialization to configure
4213 * all the HBQs and post buffers to the HBQ. The caller is not
4214 * required to hold any locks. This function will return zero if successful
4215 * else it will return negative error code.
4218 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4220 int hbq_count
= lpfc_sli_hbq_count();
4224 uint32_t hbq_entry_index
;
4226 /* Get a Mailbox buffer to setup mailbox
4227 * commands for HBA initialization
4229 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4236 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4237 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4238 phba
->hbq_in_use
= 1;
4240 hbq_entry_index
= 0;
4241 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4242 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4243 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4244 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4245 phba
->hbqs
[hbqno
].entry_count
=
4246 lpfc_hbq_defs
[hbqno
]->entry_count
;
4247 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4248 hbq_entry_index
, pmb
);
4249 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4251 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4252 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4253 mbxStatus <status>, ring <num> */
4255 lpfc_printf_log(phba
, KERN_ERR
,
4256 LOG_SLI
| LOG_VPORT
,
4257 "1805 Adapter failed to init. "
4258 "Data: x%x x%x x%x\n",
4260 pmbox
->mbxStatus
, hbqno
);
4262 phba
->link_state
= LPFC_HBA_ERROR
;
4263 mempool_free(pmb
, phba
->mbox_mem_pool
);
4267 phba
->hbq_count
= hbq_count
;
4269 mempool_free(pmb
, phba
->mbox_mem_pool
);
4271 /* Initially populate or replenish the HBQs */
4272 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4273 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4278 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4279 * @phba: Pointer to HBA context object.
4281 * This function is called during the SLI initialization to configure
4282 * all the HBQs and post buffers to the HBQ. The caller is not
4283 * required to hold any locks. This function will return zero if successful
4284 * else it will return negative error code.
4287 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4289 phba
->hbq_in_use
= 1;
4290 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4291 phba
->hbq_count
= 1;
4292 /* Initially populate or replenish the HBQs */
4293 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4298 * lpfc_sli_config_port - Issue config port mailbox command
4299 * @phba: Pointer to HBA context object.
4300 * @sli_mode: sli mode - 2/3
4302 * This function is called by the sli intialization code path
4303 * to issue config_port mailbox command. This function restarts the
4304 * HBA firmware and issues a config_port mailbox command to configure
4305 * the SLI interface in the sli mode specified by sli_mode
4306 * variable. The caller is not required to hold any locks.
4307 * The function returns 0 if successful, else returns negative error
4311 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4314 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4316 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4318 phba
->link_state
= LPFC_HBA_ERROR
;
4322 phba
->sli_rev
= sli_mode
;
4323 while (resetcount
< 2 && !done
) {
4324 spin_lock_irq(&phba
->hbalock
);
4325 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4326 spin_unlock_irq(&phba
->hbalock
);
4327 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4328 lpfc_sli_brdrestart(phba
);
4329 rc
= lpfc_sli_chipset_init(phba
);
4333 spin_lock_irq(&phba
->hbalock
);
4334 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4335 spin_unlock_irq(&phba
->hbalock
);
4338 /* Call pre CONFIG_PORT mailbox command initialization. A
4339 * value of 0 means the call was successful. Any other
4340 * nonzero value is a failure, but if ERESTART is returned,
4341 * the driver may reset the HBA and try again.
4343 rc
= lpfc_config_port_prep(phba
);
4344 if (rc
== -ERESTART
) {
4345 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4350 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4351 lpfc_config_port(phba
, pmb
);
4352 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4353 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4354 LPFC_SLI3_HBQ_ENABLED
|
4355 LPFC_SLI3_CRP_ENABLED
|
4356 LPFC_SLI3_BG_ENABLED
|
4357 LPFC_SLI3_DSS_ENABLED
);
4358 if (rc
!= MBX_SUCCESS
) {
4359 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4360 "0442 Adapter failed to init, mbxCmd x%x "
4361 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4362 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4363 spin_lock_irq(&phba
->hbalock
);
4364 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4365 spin_unlock_irq(&phba
->hbalock
);
4368 /* Allow asynchronous mailbox command to go through */
4369 spin_lock_irq(&phba
->hbalock
);
4370 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4371 spin_unlock_irq(&phba
->hbalock
);
4374 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4375 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4376 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4377 "3110 Port did not grant ASABT\n");
4382 goto do_prep_failed
;
4384 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4385 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4387 goto do_prep_failed
;
4389 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4390 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4391 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4392 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4393 phba
->max_vpi
: phba
->max_vports
;
4397 phba
->fips_level
= 0;
4398 phba
->fips_spec_rev
= 0;
4399 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4400 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4401 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4402 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4403 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4404 "2850 Security Crypto Active. FIPS x%d "
4406 phba
->fips_level
, phba
->fips_spec_rev
);
4408 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4409 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4410 "2856 Config Port Security Crypto "
4412 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4414 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4415 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4416 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4417 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4419 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4420 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4422 if (phba
->cfg_enable_bg
) {
4423 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4424 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4426 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4427 "0443 Adapter did not grant "
4431 phba
->hbq_get
= NULL
;
4432 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4436 mempool_free(pmb
, phba
->mbox_mem_pool
);
4442 * lpfc_sli_hba_setup - SLI intialization function
4443 * @phba: Pointer to HBA context object.
4445 * This function is the main SLI intialization function. This function
4446 * is called by the HBA intialization code, HBA reset code and HBA
4447 * error attention handler code. Caller is not required to hold any
4448 * locks. This function issues config_port mailbox command to configure
4449 * the SLI, setup iocb rings and HBQ rings. In the end the function
4450 * calls the config_port_post function to issue init_link mailbox
4451 * command and to start the discovery. The function will return zero
4452 * if successful, else it will return negative error code.
4455 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4461 switch (lpfc_sli_mode
) {
4463 if (phba
->cfg_enable_npiv
) {
4464 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4465 "1824 NPIV enabled: Override lpfc_sli_mode "
4466 "parameter (%d) to auto (0).\n",
4476 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4477 "1819 Unrecognized lpfc_sli_mode "
4478 "parameter: %d.\n", lpfc_sli_mode
);
4483 rc
= lpfc_sli_config_port(phba
, mode
);
4485 if (rc
&& lpfc_sli_mode
== 3)
4486 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4487 "1820 Unable to select SLI-3. "
4488 "Not supported by adapter.\n");
4489 if (rc
&& mode
!= 2)
4490 rc
= lpfc_sli_config_port(phba
, 2);
4492 goto lpfc_sli_hba_setup_error
;
4494 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4495 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4496 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4498 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4499 "2709 This device supports "
4500 "Advanced Error Reporting (AER)\n");
4501 spin_lock_irq(&phba
->hbalock
);
4502 phba
->hba_flag
|= HBA_AER_ENABLED
;
4503 spin_unlock_irq(&phba
->hbalock
);
4505 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4506 "2708 This device does not support "
4507 "Advanced Error Reporting (AER)\n");
4508 phba
->cfg_aer_support
= 0;
4512 if (phba
->sli_rev
== 3) {
4513 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4514 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4516 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4517 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4518 phba
->sli3_options
= 0;
4521 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4522 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4523 phba
->sli_rev
, phba
->max_vpi
);
4524 rc
= lpfc_sli_ring_map(phba
);
4527 goto lpfc_sli_hba_setup_error
;
4529 /* Initialize VPIs. */
4530 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4532 * The VPI bitmask and physical ID array are allocated
4533 * and initialized once only - at driver load. A port
4534 * reset doesn't need to reinitialize this memory.
4536 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4537 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4538 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4540 if (!phba
->vpi_bmask
) {
4542 goto lpfc_sli_hba_setup_error
;
4545 phba
->vpi_ids
= kzalloc(
4546 (phba
->max_vpi
+1) * sizeof(uint16_t),
4548 if (!phba
->vpi_ids
) {
4549 kfree(phba
->vpi_bmask
);
4551 goto lpfc_sli_hba_setup_error
;
4553 for (i
= 0; i
< phba
->max_vpi
; i
++)
4554 phba
->vpi_ids
[i
] = i
;
4559 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4560 rc
= lpfc_sli_hbq_setup(phba
);
4562 goto lpfc_sli_hba_setup_error
;
4564 spin_lock_irq(&phba
->hbalock
);
4565 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4566 spin_unlock_irq(&phba
->hbalock
);
4568 rc
= lpfc_config_port_post(phba
);
4570 goto lpfc_sli_hba_setup_error
;
4574 lpfc_sli_hba_setup_error
:
4575 phba
->link_state
= LPFC_HBA_ERROR
;
4576 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4577 "0445 Firmware initialization failed\n");
4582 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4583 * @phba: Pointer to HBA context object.
4584 * @mboxq: mailbox pointer.
4585 * This function issue a dump mailbox command to read config region
4586 * 23 and parse the records in the region and populate driver
4590 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4592 LPFC_MBOXQ_t
*mboxq
;
4593 struct lpfc_dmabuf
*mp
;
4594 struct lpfc_mqe
*mqe
;
4595 uint32_t data_length
;
4598 /* Program the default value of vlan_id and fc_map */
4599 phba
->valid_vlan
= 0;
4600 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4601 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4602 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4604 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4608 mqe
= &mboxq
->u
.mqe
;
4609 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4611 goto out_free_mboxq
;
4614 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4615 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4617 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4618 "(%d):2571 Mailbox cmd x%x Status x%x "
4619 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4620 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4621 "CQ: x%x x%x x%x x%x\n",
4622 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4623 bf_get(lpfc_mqe_command
, mqe
),
4624 bf_get(lpfc_mqe_status
, mqe
),
4625 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4626 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4627 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4628 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4629 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4630 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4631 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4632 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4633 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4635 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4636 mboxq
->mcqe
.trailer
);
4639 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4642 goto out_free_mboxq
;
4644 data_length
= mqe
->un
.mb_words
[5];
4645 if (data_length
> DMP_RGN23_SIZE
) {
4646 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4649 goto out_free_mboxq
;
4652 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4653 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4658 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4663 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4664 * @phba: pointer to lpfc hba data structure.
4665 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4666 * @vpd: pointer to the memory to hold resulting port vpd data.
4667 * @vpd_size: On input, the number of bytes allocated to @vpd.
4668 * On output, the number of data bytes in @vpd.
4670 * This routine executes a READ_REV SLI4 mailbox command. In
4671 * addition, this routine gets the port vpd data.
4675 * -ENOMEM - could not allocated memory.
4678 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4679 uint8_t *vpd
, uint32_t *vpd_size
)
4683 struct lpfc_dmabuf
*dmabuf
;
4684 struct lpfc_mqe
*mqe
;
4686 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4691 * Get a DMA buffer for the vpd data resulting from the READ_REV
4694 dma_size
= *vpd_size
;
4695 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4699 if (!dmabuf
->virt
) {
4703 memset(dmabuf
->virt
, 0, dma_size
);
4706 * The SLI4 implementation of READ_REV conflicts at word1,
4707 * bits 31:16 and SLI4 adds vpd functionality not present
4708 * in SLI3. This code corrects the conflicts.
4710 lpfc_read_rev(phba
, mboxq
);
4711 mqe
= &mboxq
->u
.mqe
;
4712 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4713 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4714 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4715 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4716 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4718 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4720 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4721 dmabuf
->virt
, dmabuf
->phys
);
4727 * The available vpd length cannot be bigger than the
4728 * DMA buffer passed to the port. Catch the less than
4729 * case and update the caller's size.
4731 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4732 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4734 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4736 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4737 dmabuf
->virt
, dmabuf
->phys
);
4743 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4744 * @phba: pointer to lpfc hba data structure.
4746 * This routine retrieves SLI4 device physical port name this PCI function
4751 * otherwise - failed to retrieve physical port name
4754 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4756 LPFC_MBOXQ_t
*mboxq
;
4757 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4758 struct lpfc_controller_attribute
*cntl_attr
;
4759 struct lpfc_mbx_get_port_name
*get_port_name
;
4760 void *virtaddr
= NULL
;
4761 uint32_t alloclen
, reqlen
;
4762 uint32_t shdr_status
, shdr_add_status
;
4763 union lpfc_sli4_cfg_shdr
*shdr
;
4764 char cport_name
= 0;
4767 /* We assume nothing at this point */
4768 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4769 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4771 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4774 /* obtain link type and link number via READ_CONFIG */
4775 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4776 lpfc_sli4_read_config(phba
);
4777 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4778 goto retrieve_ppname
;
4780 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4781 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4782 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4783 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4784 LPFC_SLI4_MBX_NEMBED
);
4785 if (alloclen
< reqlen
) {
4786 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4787 "3084 Allocated DMA memory size (%d) is "
4788 "less than the requested DMA memory size "
4789 "(%d)\n", alloclen
, reqlen
);
4791 goto out_free_mboxq
;
4793 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4794 virtaddr
= mboxq
->sge_array
->addr
[0];
4795 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4796 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4797 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4798 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4799 if (shdr_status
|| shdr_add_status
|| rc
) {
4800 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4801 "3085 Mailbox x%x (x%x/x%x) failed, "
4802 "rc:x%x, status:x%x, add_status:x%x\n",
4803 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4804 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4805 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4806 rc
, shdr_status
, shdr_add_status
);
4808 goto out_free_mboxq
;
4810 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4811 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4812 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4813 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4814 phba
->sli4_hba
.lnk_info
.lnk_no
=
4815 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4816 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4817 "3086 lnk_type:%d, lnk_numb:%d\n",
4818 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4819 phba
->sli4_hba
.lnk_info
.lnk_no
);
4822 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4823 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4824 sizeof(struct lpfc_mbx_get_port_name
) -
4825 sizeof(struct lpfc_sli4_cfg_mhdr
),
4826 LPFC_SLI4_MBX_EMBED
);
4827 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4828 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4829 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4830 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4831 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4832 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4833 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4834 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4835 if (shdr_status
|| shdr_add_status
|| rc
) {
4836 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4837 "3087 Mailbox x%x (x%x/x%x) failed: "
4838 "rc:x%x, status:x%x, add_status:x%x\n",
4839 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4840 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4841 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4842 rc
, shdr_status
, shdr_add_status
);
4844 goto out_free_mboxq
;
4846 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4847 case LPFC_LINK_NUMBER_0
:
4848 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4849 &get_port_name
->u
.response
);
4850 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4852 case LPFC_LINK_NUMBER_1
:
4853 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4854 &get_port_name
->u
.response
);
4855 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4857 case LPFC_LINK_NUMBER_2
:
4858 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4859 &get_port_name
->u
.response
);
4860 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4862 case LPFC_LINK_NUMBER_3
:
4863 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4864 &get_port_name
->u
.response
);
4865 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4871 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4872 phba
->Port
[0] = cport_name
;
4873 phba
->Port
[1] = '\0';
4874 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4875 "3091 SLI get port name: %s\n", phba
->Port
);
4879 if (rc
!= MBX_TIMEOUT
) {
4880 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4881 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4883 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4889 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4890 * @phba: pointer to lpfc hba data structure.
4892 * This routine is called to explicitly arm the SLI4 device's completion and
4896 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4900 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4901 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4903 if (phba
->sli4_hba
.fcp_cq
) {
4905 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4907 while (++fcp_eqidx
< phba
->cfg_fcp_eq_count
);
4909 lpfc_sli4_eq_release(phba
->sli4_hba
.sp_eq
, LPFC_QUEUE_REARM
);
4910 if (phba
->sli4_hba
.fp_eq
) {
4911 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
;
4913 lpfc_sli4_eq_release(phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
4919 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4920 * @phba: Pointer to HBA context object.
4921 * @type: The resource extent type.
4922 * @extnt_count: buffer to hold port available extent count.
4923 * @extnt_size: buffer to hold element count per extent.
4925 * This function calls the port and retrievs the number of available
4926 * extents and their size for a particular extent type.
4928 * Returns: 0 if successful. Nonzero otherwise.
4931 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
4932 uint16_t *extnt_count
, uint16_t *extnt_size
)
4937 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
4940 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4944 /* Find out how many extents are available for this resource type */
4945 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
4946 sizeof(struct lpfc_sli4_cfg_mhdr
));
4947 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4948 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
4949 length
, LPFC_SLI4_MBX_EMBED
);
4951 /* Send an extents count of 0 - the GET doesn't use it. */
4952 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
4953 LPFC_SLI4_MBX_EMBED
);
4959 if (!phba
->sli4_hba
.intr_enable
)
4960 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
4962 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
4963 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
4970 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
4971 if (bf_get(lpfc_mbox_hdr_status
,
4972 &rsrc_info
->header
.cfg_shdr
.response
)) {
4973 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
4974 "2930 Failed to get resource extents "
4975 "Status 0x%x Add'l Status 0x%x\n",
4976 bf_get(lpfc_mbox_hdr_status
,
4977 &rsrc_info
->header
.cfg_shdr
.response
),
4978 bf_get(lpfc_mbox_hdr_add_status
,
4979 &rsrc_info
->header
.cfg_shdr
.response
));
4984 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
4986 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
4989 mempool_free(mbox
, phba
->mbox_mem_pool
);
4994 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
4995 * @phba: Pointer to HBA context object.
4996 * @type: The extent type to check.
4998 * This function reads the current available extents from the port and checks
4999 * if the extent count or extent size has changed since the last access.
5000 * Callers use this routine post port reset to understand if there is a
5001 * extent reprovisioning requirement.
5004 * -Error: error indicates problem.
5005 * 1: Extent count or size has changed.
5009 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5011 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5012 uint16_t size_diff
, rsrc_ext_size
;
5014 struct lpfc_rsrc_blks
*rsrc_entry
;
5015 struct list_head
*rsrc_blk_list
= NULL
;
5019 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5026 case LPFC_RSC_TYPE_FCOE_RPI
:
5027 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5029 case LPFC_RSC_TYPE_FCOE_VPI
:
5030 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5032 case LPFC_RSC_TYPE_FCOE_XRI
:
5033 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5035 case LPFC_RSC_TYPE_FCOE_VFI
:
5036 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5042 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5044 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5048 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5055 * lpfc_sli4_cfg_post_extnts -
5056 * @phba: Pointer to HBA context object.
5057 * @extnt_cnt - number of available extents.
5058 * @type - the extent type (rpi, xri, vfi, vpi).
5059 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5060 * @mbox - pointer to the caller's allocated mailbox structure.
5062 * This function executes the extents allocation request. It also
5063 * takes care of the amount of memory needed to allocate or get the
5064 * allocated extents. It is the caller's responsibility to evaluate
5068 * -Error: Error value describes the condition found.
5072 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t *extnt_cnt
,
5073 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5078 uint32_t alloc_len
, mbox_tmo
;
5080 /* Calculate the total requested length of the dma memory */
5081 req_len
= *extnt_cnt
* sizeof(uint16_t);
5084 * Calculate the size of an embedded mailbox. The uint32_t
5085 * accounts for extents-specific word.
5087 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5091 * Presume the allocation and response will fit into an embedded
5092 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5094 *emb
= LPFC_SLI4_MBX_EMBED
;
5095 if (req_len
> emb_len
) {
5096 req_len
= *extnt_cnt
* sizeof(uint16_t) +
5097 sizeof(union lpfc_sli4_cfg_shdr
) +
5099 *emb
= LPFC_SLI4_MBX_NEMBED
;
5102 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5103 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5105 if (alloc_len
< req_len
) {
5106 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5107 "2982 Allocated DMA memory size (x%x) is "
5108 "less than the requested DMA memory "
5109 "size (x%x)\n", alloc_len
, req_len
);
5112 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, *extnt_cnt
, type
, *emb
);
5116 if (!phba
->sli4_hba
.intr_enable
)
5117 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5119 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5120 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5129 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5130 * @phba: Pointer to HBA context object.
5131 * @type: The resource extent type to allocate.
5133 * This function allocates the number of elements for the specified
5137 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5140 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5141 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5144 unsigned long longs
;
5145 unsigned long *bmask
;
5146 struct lpfc_rsrc_blks
*rsrc_blks
;
5149 struct lpfc_id_range
*id_array
= NULL
;
5150 void *virtaddr
= NULL
;
5151 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5152 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5153 struct list_head
*ext_blk_list
;
5155 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5161 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5162 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5163 "3009 No available Resource Extents "
5164 "for resource type 0x%x: Count: 0x%x, "
5165 "Size 0x%x\n", type
, rsrc_cnt
,
5170 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
,
5171 "2903 Available Resource Extents "
5172 "for resource type 0x%x: Count: 0x%x, "
5173 "Size 0x%x\n", type
, rsrc_cnt
,
5176 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5180 rc
= lpfc_sli4_cfg_post_extnts(phba
, &rsrc_cnt
, type
, &emb
, mbox
);
5187 * Figure out where the response is located. Then get local pointers
5188 * to the response data. The port does not guarantee to respond to
5189 * all extents counts request so update the local variable with the
5190 * allocated count from the port.
5192 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5193 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5194 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5195 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5197 virtaddr
= mbox
->sge_array
->addr
[0];
5198 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5199 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5200 id_array
= &n_rsrc
->id
;
5203 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5204 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5207 * Based on the resource size and count, correct the base and max
5210 length
= sizeof(struct lpfc_rsrc_blks
);
5212 case LPFC_RSC_TYPE_FCOE_RPI
:
5213 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5214 sizeof(unsigned long),
5216 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5220 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5223 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5224 kfree(phba
->sli4_hba
.rpi_bmask
);
5230 * The next_rpi was initialized with the maximum available
5231 * count but the port may allocate a smaller number. Catch
5232 * that case and update the next_rpi.
5234 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5236 /* Initialize local ptrs for common extent processing later. */
5237 bmask
= phba
->sli4_hba
.rpi_bmask
;
5238 ids
= phba
->sli4_hba
.rpi_ids
;
5239 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5241 case LPFC_RSC_TYPE_FCOE_VPI
:
5242 phba
->vpi_bmask
= kzalloc(longs
*
5243 sizeof(unsigned long),
5245 if (unlikely(!phba
->vpi_bmask
)) {
5249 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5252 if (unlikely(!phba
->vpi_ids
)) {
5253 kfree(phba
->vpi_bmask
);
5258 /* Initialize local ptrs for common extent processing later. */
5259 bmask
= phba
->vpi_bmask
;
5260 ids
= phba
->vpi_ids
;
5261 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5263 case LPFC_RSC_TYPE_FCOE_XRI
:
5264 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5265 sizeof(unsigned long),
5267 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5271 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5274 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5275 kfree(phba
->sli4_hba
.xri_bmask
);
5280 /* Initialize local ptrs for common extent processing later. */
5281 bmask
= phba
->sli4_hba
.xri_bmask
;
5282 ids
= phba
->sli4_hba
.xri_ids
;
5283 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5285 case LPFC_RSC_TYPE_FCOE_VFI
:
5286 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5287 sizeof(unsigned long),
5289 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5293 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5296 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5297 kfree(phba
->sli4_hba
.vfi_bmask
);
5302 /* Initialize local ptrs for common extent processing later. */
5303 bmask
= phba
->sli4_hba
.vfi_bmask
;
5304 ids
= phba
->sli4_hba
.vfi_ids
;
5305 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5308 /* Unsupported Opcode. Fail call. */
5312 ext_blk_list
= NULL
;
5317 * Complete initializing the extent configuration with the
5318 * allocated ids assigned to this function. The bitmask serves
5319 * as an index into the array and manages the available ids. The
5320 * array just stores the ids communicated to the port via the wqes.
5322 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5324 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5327 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5330 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5331 if (unlikely(!rsrc_blks
)) {
5337 rsrc_blks
->rsrc_start
= rsrc_id
;
5338 rsrc_blks
->rsrc_size
= rsrc_size
;
5339 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5340 rsrc_start
= rsrc_id
;
5341 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5342 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5343 lpfc_sli4_get_els_iocb_cnt(phba
);
5345 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5350 /* Entire word processed. Get next word.*/
5355 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5360 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5361 * @phba: Pointer to HBA context object.
5362 * @type: the extent's type.
5364 * This function deallocates all extents of a particular resource type.
5365 * SLI4 does not allow for deallocating a particular extent range. It
5366 * is the caller's responsibility to release all kernel memory resources.
5369 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5372 uint32_t length
, mbox_tmo
= 0;
5374 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5375 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5377 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5382 * This function sends an embedded mailbox because it only sends the
5383 * the resource type. All extents of this type are released by the
5386 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5387 sizeof(struct lpfc_sli4_cfg_mhdr
));
5388 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5389 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5390 length
, LPFC_SLI4_MBX_EMBED
);
5392 /* Send an extents count of 0 - the dealloc doesn't use it. */
5393 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5394 LPFC_SLI4_MBX_EMBED
);
5399 if (!phba
->sli4_hba
.intr_enable
)
5400 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5402 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5403 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5410 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5411 if (bf_get(lpfc_mbox_hdr_status
,
5412 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5413 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5414 "2919 Failed to release resource extents "
5415 "for type %d - Status 0x%x Add'l Status 0x%x. "
5416 "Resource memory not released.\n",
5418 bf_get(lpfc_mbox_hdr_status
,
5419 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5420 bf_get(lpfc_mbox_hdr_add_status
,
5421 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5426 /* Release kernel memory resources for the specific type. */
5428 case LPFC_RSC_TYPE_FCOE_VPI
:
5429 kfree(phba
->vpi_bmask
);
5430 kfree(phba
->vpi_ids
);
5431 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5432 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5433 &phba
->lpfc_vpi_blk_list
, list
) {
5434 list_del_init(&rsrc_blk
->list
);
5438 case LPFC_RSC_TYPE_FCOE_XRI
:
5439 kfree(phba
->sli4_hba
.xri_bmask
);
5440 kfree(phba
->sli4_hba
.xri_ids
);
5441 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5442 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5443 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5444 list_del_init(&rsrc_blk
->list
);
5448 case LPFC_RSC_TYPE_FCOE_VFI
:
5449 kfree(phba
->sli4_hba
.vfi_bmask
);
5450 kfree(phba
->sli4_hba
.vfi_ids
);
5451 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5452 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5453 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5454 list_del_init(&rsrc_blk
->list
);
5458 case LPFC_RSC_TYPE_FCOE_RPI
:
5459 /* RPI bitmask and physical id array are cleaned up earlier. */
5460 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5461 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5462 list_del_init(&rsrc_blk
->list
);
5470 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5473 mempool_free(mbox
, phba
->mbox_mem_pool
);
5478 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5479 * @phba: Pointer to HBA context object.
5481 * This function allocates all SLI4 resource identifiers.
5484 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5486 int i
, rc
, error
= 0;
5487 uint16_t count
, base
;
5488 unsigned long longs
;
5490 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5491 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5492 if (phba
->sli4_hba
.extents_in_use
) {
5494 * The port supports resource extents. The XRI, VPI, VFI, RPI
5495 * resource extent count must be read and allocated before
5496 * provisioning the resource id arrays.
5498 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5499 LPFC_IDX_RSRC_RDY
) {
5501 * Extent-based resources are set - the driver could
5502 * be in a port reset. Figure out if any corrective
5503 * actions need to be taken.
5505 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5506 LPFC_RSC_TYPE_FCOE_VFI
);
5509 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5510 LPFC_RSC_TYPE_FCOE_VPI
);
5513 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5514 LPFC_RSC_TYPE_FCOE_XRI
);
5517 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5518 LPFC_RSC_TYPE_FCOE_RPI
);
5523 * It's possible that the number of resources
5524 * provided to this port instance changed between
5525 * resets. Detect this condition and reallocate
5526 * resources. Otherwise, there is no action.
5529 lpfc_printf_log(phba
, KERN_INFO
,
5530 LOG_MBOX
| LOG_INIT
,
5531 "2931 Detected extent resource "
5532 "change. Reallocating all "
5534 rc
= lpfc_sli4_dealloc_extent(phba
,
5535 LPFC_RSC_TYPE_FCOE_VFI
);
5536 rc
= lpfc_sli4_dealloc_extent(phba
,
5537 LPFC_RSC_TYPE_FCOE_VPI
);
5538 rc
= lpfc_sli4_dealloc_extent(phba
,
5539 LPFC_RSC_TYPE_FCOE_XRI
);
5540 rc
= lpfc_sli4_dealloc_extent(phba
,
5541 LPFC_RSC_TYPE_FCOE_RPI
);
5546 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5550 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5554 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5558 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5561 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5566 * The port does not support resource extents. The XRI, VPI,
5567 * VFI, RPI resource ids were determined from READ_CONFIG.
5568 * Just allocate the bitmasks and provision the resource id
5569 * arrays. If a port reset is active, the resources don't
5570 * need any action - just exit.
5572 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5573 LPFC_IDX_RSRC_RDY
) {
5574 lpfc_sli4_dealloc_resource_identifiers(phba
);
5575 lpfc_sli4_remove_rpis(phba
);
5578 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5579 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5580 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5581 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5582 sizeof(unsigned long),
5584 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5588 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5591 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5593 goto free_rpi_bmask
;
5596 for (i
= 0; i
< count
; i
++)
5597 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5600 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5601 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5602 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5603 phba
->vpi_bmask
= kzalloc(longs
*
5604 sizeof(unsigned long),
5606 if (unlikely(!phba
->vpi_bmask
)) {
5610 phba
->vpi_ids
= kzalloc(count
*
5613 if (unlikely(!phba
->vpi_ids
)) {
5615 goto free_vpi_bmask
;
5618 for (i
= 0; i
< count
; i
++)
5619 phba
->vpi_ids
[i
] = base
+ i
;
5622 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5623 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5624 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5625 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5626 sizeof(unsigned long),
5628 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5632 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5635 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5637 goto free_xri_bmask
;
5640 for (i
= 0; i
< count
; i
++)
5641 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5644 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5645 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5646 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5647 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5648 sizeof(unsigned long),
5650 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5654 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5657 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5659 goto free_vfi_bmask
;
5662 for (i
= 0; i
< count
; i
++)
5663 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5666 * Mark all resources ready. An HBA reset doesn't need
5667 * to reset the initialization.
5669 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5675 kfree(phba
->sli4_hba
.vfi_bmask
);
5677 kfree(phba
->sli4_hba
.xri_ids
);
5679 kfree(phba
->sli4_hba
.xri_bmask
);
5681 kfree(phba
->vpi_ids
);
5683 kfree(phba
->vpi_bmask
);
5685 kfree(phba
->sli4_hba
.rpi_ids
);
5687 kfree(phba
->sli4_hba
.rpi_bmask
);
5693 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5694 * @phba: Pointer to HBA context object.
5696 * This function allocates the number of elements for the specified
5700 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5702 if (phba
->sli4_hba
.extents_in_use
) {
5703 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5704 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5705 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5706 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5708 kfree(phba
->vpi_bmask
);
5709 kfree(phba
->vpi_ids
);
5710 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5711 kfree(phba
->sli4_hba
.xri_bmask
);
5712 kfree(phba
->sli4_hba
.xri_ids
);
5713 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5714 kfree(phba
->sli4_hba
.vfi_bmask
);
5715 kfree(phba
->sli4_hba
.vfi_ids
);
5716 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5717 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5724 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5725 * @phba: Pointer to HBA context object.
5726 * @type: The resource extent type.
5727 * @extnt_count: buffer to hold port extent count response
5728 * @extnt_size: buffer to hold port extent size response.
5730 * This function calls the port to read the host allocated extents
5731 * for a particular type.
5734 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5735 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5739 uint16_t curr_blks
= 0;
5740 uint32_t req_len
, emb_len
;
5741 uint32_t alloc_len
, mbox_tmo
;
5742 struct list_head
*blk_list_head
;
5743 struct lpfc_rsrc_blks
*rsrc_blk
;
5745 void *virtaddr
= NULL
;
5746 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5747 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5748 union lpfc_sli4_cfg_shdr
*shdr
;
5751 case LPFC_RSC_TYPE_FCOE_VPI
:
5752 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5754 case LPFC_RSC_TYPE_FCOE_XRI
:
5755 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5757 case LPFC_RSC_TYPE_FCOE_VFI
:
5758 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5760 case LPFC_RSC_TYPE_FCOE_RPI
:
5761 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5767 /* Count the number of extents currently allocatd for this type. */
5768 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5769 if (curr_blks
== 0) {
5771 * The GET_ALLOCATED mailbox does not return the size,
5772 * just the count. The size should be just the size
5773 * stored in the current allocated block and all sizes
5774 * for an extent type are the same so set the return
5777 *extnt_size
= rsrc_blk
->rsrc_size
;
5782 /* Calculate the total requested length of the dma memory. */
5783 req_len
= curr_blks
* sizeof(uint16_t);
5786 * Calculate the size of an embedded mailbox. The uint32_t
5787 * accounts for extents-specific word.
5789 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5793 * Presume the allocation and response will fit into an embedded
5794 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5796 emb
= LPFC_SLI4_MBX_EMBED
;
5798 if (req_len
> emb_len
) {
5799 req_len
= curr_blks
* sizeof(uint16_t) +
5800 sizeof(union lpfc_sli4_cfg_shdr
) +
5802 emb
= LPFC_SLI4_MBX_NEMBED
;
5805 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5808 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5810 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5811 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5813 if (alloc_len
< req_len
) {
5814 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5815 "2983 Allocated DMA memory size (x%x) is "
5816 "less than the requested DMA memory "
5817 "size (x%x)\n", alloc_len
, req_len
);
5821 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5827 if (!phba
->sli4_hba
.intr_enable
)
5828 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5830 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5831 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5840 * Figure out where the response is located. Then get local pointers
5841 * to the response data. The port does not guarantee to respond to
5842 * all extents counts request so update the local variable with the
5843 * allocated count from the port.
5845 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5846 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5847 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5848 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5850 virtaddr
= mbox
->sge_array
->addr
[0];
5851 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5852 shdr
= &n_rsrc
->cfg_shdr
;
5853 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5856 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5857 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5858 "2984 Failed to read allocated resources "
5859 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5861 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5862 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5867 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5872 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
5873 * @phba: Pointer to HBA context object.
5875 * This function is the main SLI4 device intialization PCI function. This
5876 * function is called by the HBA intialization code, HBA reset code and
5877 * HBA error attention handler code. Caller is not required to hold any
5881 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
5884 LPFC_MBOXQ_t
*mboxq
;
5885 struct lpfc_mqe
*mqe
;
5888 uint32_t ftr_rsp
= 0;
5889 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
5890 struct lpfc_vport
*vport
= phba
->pport
;
5891 struct lpfc_dmabuf
*mp
;
5893 /* Perform a PCI function reset to start from clean */
5894 rc
= lpfc_pci_function_reset(phba
);
5898 /* Check the HBA Host Status Register for readyness */
5899 rc
= lpfc_sli4_post_status_check(phba
);
5903 spin_lock_irq(&phba
->hbalock
);
5904 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
5905 spin_unlock_irq(&phba
->hbalock
);
5909 * Allocate a single mailbox container for initializing the
5912 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5916 /* Issue READ_REV to collect vpd and FW information. */
5917 vpd_size
= SLI4_PAGE_SIZE
;
5918 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
5924 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
5929 mqe
= &mboxq
->u
.mqe
;
5930 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
5931 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
5932 phba
->hba_flag
|= HBA_FCOE_MODE
;
5934 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
5936 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
5938 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
5940 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
5942 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5943 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5944 "0376 READ_REV Error. SLI Level %d "
5945 "FCoE enabled %d\n",
5946 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
5953 * Continue initialization with default values even if driver failed
5954 * to read FCoE param config regions, only read parameters if the
5957 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
5958 lpfc_sli4_read_fcoe_params(phba
))
5959 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
5960 "2570 Failed to read FCoE parameters\n");
5963 * Retrieve sli4 device physical port name, failure of doing it
5964 * is considered as non-fatal.
5966 rc
= lpfc_sli4_retrieve_pport_name(phba
);
5968 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5969 "3080 Successful retrieving SLI4 device "
5970 "physical port name: %s.\n", phba
->Port
);
5973 * Evaluate the read rev and vpd data. Populate the driver
5974 * state with the results. If this routine fails, the failure
5975 * is not fatal as the driver will use generic values.
5977 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
5978 if (unlikely(!rc
)) {
5979 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5980 "0377 Error %d parsing vpd. "
5981 "Using defaults.\n", rc
);
5986 /* Save information as VPD data */
5987 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
5988 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
5989 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
5990 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
5992 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
5994 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
5996 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
5998 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
5999 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6000 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6001 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6002 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6003 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6004 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6005 "(%d):0380 READ_REV Status x%x "
6006 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6007 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6008 bf_get(lpfc_mqe_status
, mqe
),
6009 phba
->vpd
.rev
.opFwName
,
6010 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6011 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6014 * Discover the port's supported feature set and match it against the
6017 lpfc_request_features(phba
, mboxq
);
6018 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6025 * The port must support FCP initiator mode as this is the
6026 * only mode running in the host.
6028 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6029 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6030 "0378 No support for fcpi mode.\n");
6033 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6034 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6036 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6038 * If the port cannot support the host's requested features
6039 * then turn off the global config parameters to disable the
6040 * feature in the driver. This is not a fatal error.
6042 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6043 if (phba
->cfg_enable_bg
) {
6044 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6045 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6050 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6051 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6055 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6056 "0379 Feature Mismatch Data: x%08x %08x "
6057 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6058 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6059 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6060 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6061 phba
->cfg_enable_bg
= 0;
6062 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6063 phba
->cfg_enable_npiv
= 0;
6066 /* These SLI3 features are assumed in SLI4 */
6067 spin_lock_irq(&phba
->hbalock
);
6068 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6069 spin_unlock_irq(&phba
->hbalock
);
6072 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6073 * calls depends on these resources to complete port setup.
6075 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6077 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6078 "2920 Failed to alloc Resource IDs "
6082 /* update physical xri mappings in the scsi buffers */
6083 lpfc_scsi_buf_update(phba
);
6085 /* Read the port's service parameters. */
6086 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6088 phba
->link_state
= LPFC_HBA_ERROR
;
6093 mboxq
->vport
= vport
;
6094 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6095 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6096 if (rc
== MBX_SUCCESS
) {
6097 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6102 * This memory was allocated by the lpfc_read_sparam routine. Release
6103 * it to the mbuf pool.
6105 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6107 mboxq
->context1
= NULL
;
6109 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6110 "0382 READ_SPARAM command failed "
6111 "status %d, mbxStatus x%x\n",
6112 rc
, bf_get(lpfc_mqe_status
, mqe
));
6113 phba
->link_state
= LPFC_HBA_ERROR
;
6118 lpfc_update_vport_wwn(vport
);
6120 /* Update the fc_host data structures with new wwn. */
6121 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6122 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6124 /* Register SGL pool to the device using non-embedded mailbox command */
6125 if (!phba
->sli4_hba
.extents_in_use
) {
6126 rc
= lpfc_sli4_post_els_sgl_list(phba
);
6128 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6129 "0582 Error %d during els sgl post "
6135 rc
= lpfc_sli4_post_els_sgl_list_ext(phba
);
6137 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6138 "2560 Error %d during els sgl post "
6145 /* Register SCSI SGL pool to the device */
6146 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6148 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6149 "0383 Error %d during scsi sgl post "
6151 /* Some Scsi buffers were moved to the abort scsi list */
6152 /* A pci function reset will repost them */
6157 /* Post the rpi header region to the device. */
6158 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6160 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6161 "0393 Error %d during rpi post operation\n",
6167 /* Create all the SLI4 queues */
6168 rc
= lpfc_sli4_queue_create(phba
);
6170 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6171 "3089 Failed to allocate queues\n");
6173 goto out_stop_timers
;
6175 /* Set up all the queues to the device */
6176 rc
= lpfc_sli4_queue_setup(phba
);
6178 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6179 "0381 Error %d during queue setup.\n ", rc
);
6180 goto out_destroy_queue
;
6183 /* Arm the CQs and then EQs on device */
6184 lpfc_sli4_arm_cqeq_intr(phba
);
6186 /* Indicate device interrupt mode */
6187 phba
->sli4_hba
.intr_enable
= 1;
6189 /* Allow asynchronous mailbox command to go through */
6190 spin_lock_irq(&phba
->hbalock
);
6191 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6192 spin_unlock_irq(&phba
->hbalock
);
6194 /* Post receive buffers to the device */
6195 lpfc_sli4_rb_setup(phba
);
6197 /* Reset HBA FCF states after HBA reset */
6198 phba
->fcf
.fcf_flag
= 0;
6199 phba
->fcf
.current_rec
.flag
= 0;
6201 /* Start the ELS watchdog timer */
6202 mod_timer(&vport
->els_tmofunc
,
6203 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
6205 /* Start heart beat timer */
6206 mod_timer(&phba
->hb_tmofunc
,
6207 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
6208 phba
->hb_outstanding
= 0;
6209 phba
->last_completion_time
= jiffies
;
6211 /* Start error attention (ERATT) polling timer */
6212 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
6214 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6215 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6216 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6218 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6219 "2829 This device supports "
6220 "Advanced Error Reporting (AER)\n");
6221 spin_lock_irq(&phba
->hbalock
);
6222 phba
->hba_flag
|= HBA_AER_ENABLED
;
6223 spin_unlock_irq(&phba
->hbalock
);
6225 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6226 "2830 This device does not support "
6227 "Advanced Error Reporting (AER)\n");
6228 phba
->cfg_aer_support
= 0;
6233 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6235 * The FC Port needs to register FCFI (index 0)
6237 lpfc_reg_fcfi(phba
, mboxq
);
6238 mboxq
->vport
= phba
->pport
;
6239 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6240 if (rc
!= MBX_SUCCESS
)
6241 goto out_unset_queue
;
6243 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6244 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6246 /* Check if the port is configured to be disabled */
6247 lpfc_sli_read_link_ste(phba
);
6251 * The port is ready, set the host's link state to LINK_DOWN
6252 * in preparation for link interrupts.
6254 spin_lock_irq(&phba
->hbalock
);
6255 phba
->link_state
= LPFC_LINK_DOWN
;
6256 spin_unlock_irq(&phba
->hbalock
);
6257 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6258 (phba
->hba_flag
& LINK_DISABLED
)) {
6259 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6260 "3103 Adapter Link is disabled.\n");
6261 lpfc_down_link(phba
, mboxq
);
6262 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6263 if (rc
!= MBX_SUCCESS
) {
6264 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6265 "3104 Adapter failed to issue "
6266 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6267 goto out_unset_queue
;
6269 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6270 /* don't perform init_link on SLI4 FC port loopback test */
6271 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6272 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6274 goto out_unset_queue
;
6277 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6280 /* Unset all the queues set up in this routine when error out */
6281 lpfc_sli4_queue_unset(phba
);
6283 lpfc_sli4_queue_destroy(phba
);
6285 lpfc_stop_hba_timers(phba
);
6287 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6292 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6293 * @ptr: context object - pointer to hba structure.
6295 * This is the callback function for mailbox timer. The mailbox
6296 * timer is armed when a new mailbox command is issued and the timer
6297 * is deleted when the mailbox complete. The function is called by
6298 * the kernel timer code when a mailbox does not complete within
6299 * expected time. This function wakes up the worker thread to
6300 * process the mailbox timeout and returns. All the processing is
6301 * done by the worker thread function lpfc_mbox_timeout_handler.
6304 lpfc_mbox_timeout(unsigned long ptr
)
6306 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6307 unsigned long iflag
;
6308 uint32_t tmo_posted
;
6310 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6311 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6313 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6314 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6317 lpfc_worker_wake_up(phba
);
6323 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6324 * @phba: Pointer to HBA context object.
6326 * This function is called from worker thread when a mailbox command times out.
6327 * The caller is not required to hold any locks. This function will reset the
6328 * HBA and recover all the pending commands.
6331 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6333 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6334 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6335 struct lpfc_sli
*psli
= &phba
->sli
;
6336 struct lpfc_sli_ring
*pring
;
6338 /* Check the pmbox pointer first. There is a race condition
6339 * between the mbox timeout handler getting executed in the
6340 * worklist and the mailbox actually completing. When this
6341 * race condition occurs, the mbox_active will be NULL.
6343 spin_lock_irq(&phba
->hbalock
);
6344 if (pmbox
== NULL
) {
6345 lpfc_printf_log(phba
, KERN_WARNING
,
6347 "0353 Active Mailbox cleared - mailbox timeout "
6349 spin_unlock_irq(&phba
->hbalock
);
6353 /* Mbox cmd <mbxCommand> timeout */
6354 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6355 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6357 phba
->pport
->port_state
,
6359 phba
->sli
.mbox_active
);
6360 spin_unlock_irq(&phba
->hbalock
);
6362 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6363 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6364 * it to fail all outstanding SCSI IO.
6366 spin_lock_irq(&phba
->pport
->work_port_lock
);
6367 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6368 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6369 spin_lock_irq(&phba
->hbalock
);
6370 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6371 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6372 spin_unlock_irq(&phba
->hbalock
);
6374 pring
= &psli
->ring
[psli
->fcp_ring
];
6375 lpfc_sli_abort_iocb_ring(phba
, pring
);
6377 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6378 "0345 Resetting board due to mailbox timeout\n");
6380 /* Reset the HBA device */
6381 lpfc_reset_hba(phba
);
6385 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6386 * @phba: Pointer to HBA context object.
6387 * @pmbox: Pointer to mailbox object.
6388 * @flag: Flag indicating how the mailbox need to be processed.
6390 * This function is called by discovery code and HBA management code
6391 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6392 * function gets the hbalock to protect the data structures.
6393 * The mailbox command can be submitted in polling mode, in which case
6394 * this function will wait in a polling loop for the completion of the
6396 * If the mailbox is submitted in no_wait mode (not polling) the
6397 * function will submit the command and returns immediately without waiting
6398 * for the mailbox completion. The no_wait is supported only when HBA
6399 * is in SLI2/SLI3 mode - interrupts are enabled.
6400 * The SLI interface allows only one mailbox pending at a time. If the
6401 * mailbox is issued in polling mode and there is already a mailbox
6402 * pending, then the function will return an error. If the mailbox is issued
6403 * in NO_WAIT mode and there is a mailbox pending already, the function
6404 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6405 * The sli layer owns the mailbox object until the completion of mailbox
6406 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6407 * return codes the caller owns the mailbox command after the return of
6411 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6415 struct lpfc_sli
*psli
= &phba
->sli
;
6416 uint32_t status
, evtctr
;
6417 uint32_t ha_copy
, hc_copy
;
6419 unsigned long timeout
;
6420 unsigned long drvr_flag
= 0;
6421 uint32_t word0
, ldata
;
6422 void __iomem
*to_slim
;
6423 int processing_queue
= 0;
6425 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6427 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6428 /* processing mbox queue from intr_handler */
6429 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6430 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6433 processing_queue
= 1;
6434 pmbox
= lpfc_mbox_get(phba
);
6436 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6441 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6442 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6444 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6445 lpfc_printf_log(phba
, KERN_ERR
,
6446 LOG_MBOX
| LOG_VPORT
,
6447 "1806 Mbox x%x failed. No vport\n",
6448 pmbox
->u
.mb
.mbxCommand
);
6450 goto out_not_finished
;
6454 /* If the PCI channel is in offline state, do not post mbox. */
6455 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6456 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6457 goto out_not_finished
;
6460 /* If HBA has a deferred error attention, fail the iocb. */
6461 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6462 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6463 goto out_not_finished
;
6469 status
= MBX_SUCCESS
;
6471 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6472 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6474 /* Mbox command <mbxCommand> cannot issue */
6475 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6476 "(%d):0311 Mailbox command x%x cannot "
6477 "issue Data: x%x x%x\n",
6478 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6479 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6480 goto out_not_finished
;
6483 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6484 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6485 !(hc_copy
& HC_MBINT_ENA
)) {
6486 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6487 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6488 "(%d):2528 Mailbox command x%x cannot "
6489 "issue Data: x%x x%x\n",
6490 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6491 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6492 goto out_not_finished
;
6496 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6497 /* Polling for a mbox command when another one is already active
6498 * is not allowed in SLI. Also, the driver must have established
6499 * SLI2 mode to queue and process multiple mbox commands.
6502 if (flag
& MBX_POLL
) {
6503 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6505 /* Mbox command <mbxCommand> cannot issue */
6506 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6507 "(%d):2529 Mailbox command x%x "
6508 "cannot issue Data: x%x x%x\n",
6509 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6510 pmbox
->u
.mb
.mbxCommand
,
6511 psli
->sli_flag
, flag
);
6512 goto out_not_finished
;
6515 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6516 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6517 /* Mbox command <mbxCommand> cannot issue */
6518 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6519 "(%d):2530 Mailbox command x%x "
6520 "cannot issue Data: x%x x%x\n",
6521 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6522 pmbox
->u
.mb
.mbxCommand
,
6523 psli
->sli_flag
, flag
);
6524 goto out_not_finished
;
6527 /* Another mailbox command is still being processed, queue this
6528 * command to be processed later.
6530 lpfc_mbox_put(phba
, pmbox
);
6532 /* Mbox cmd issue - BUSY */
6533 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6534 "(%d):0308 Mbox cmd issue - BUSY Data: "
6535 "x%x x%x x%x x%x\n",
6536 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6537 mb
->mbxCommand
, phba
->pport
->port_state
,
6538 psli
->sli_flag
, flag
);
6540 psli
->slistat
.mbox_busy
++;
6541 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6544 lpfc_debugfs_disc_trc(pmbox
->vport
,
6545 LPFC_DISC_TRC_MBOX_VPORT
,
6546 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6547 (uint32_t)mb
->mbxCommand
,
6548 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6551 lpfc_debugfs_disc_trc(phba
->pport
,
6553 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6554 (uint32_t)mb
->mbxCommand
,
6555 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6561 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6563 /* If we are not polling, we MUST be in SLI2 mode */
6564 if (flag
!= MBX_POLL
) {
6565 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6566 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
6567 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6568 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6569 /* Mbox command <mbxCommand> cannot issue */
6570 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6571 "(%d):2531 Mailbox command x%x "
6572 "cannot issue Data: x%x x%x\n",
6573 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6574 pmbox
->u
.mb
.mbxCommand
,
6575 psli
->sli_flag
, flag
);
6576 goto out_not_finished
;
6578 /* timeout active mbox command */
6579 mod_timer(&psli
->mbox_tmo
, (jiffies
+
6580 (HZ
* lpfc_mbox_tmo_val(phba
, pmbox
))));
6583 /* Mailbox cmd <cmd> issue */
6584 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6585 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6587 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6588 mb
->mbxCommand
, phba
->pport
->port_state
,
6589 psli
->sli_flag
, flag
);
6591 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
6593 lpfc_debugfs_disc_trc(pmbox
->vport
,
6594 LPFC_DISC_TRC_MBOX_VPORT
,
6595 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6596 (uint32_t)mb
->mbxCommand
,
6597 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6600 lpfc_debugfs_disc_trc(phba
->pport
,
6602 "MBOX Send: cmd:x%x mb:x%x x%x",
6603 (uint32_t)mb
->mbxCommand
,
6604 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
6608 psli
->slistat
.mbox_cmd
++;
6609 evtctr
= psli
->slistat
.mbox_event
;
6611 /* next set own bit for the adapter and copy over command word */
6612 mb
->mbxOwner
= OWN_CHIP
;
6614 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6615 /* Populate mbox extension offset word. */
6616 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6617 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6618 = (uint8_t *)phba
->mbox_ext
6619 - (uint8_t *)phba
->mbox
;
6622 /* Copy the mailbox extension data */
6623 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6624 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6625 (uint8_t *)phba
->mbox_ext
,
6626 pmbox
->in_ext_byte_len
);
6628 /* Copy command data to host SLIM area */
6629 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6631 /* Populate mbox extension offset word. */
6632 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6633 *(((uint32_t *)mb
) + pmbox
->mbox_offset_word
)
6634 = MAILBOX_HBA_EXT_OFFSET
;
6636 /* Copy the mailbox extension data */
6637 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6638 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
6639 MAILBOX_HBA_EXT_OFFSET
,
6640 pmbox
->context2
, pmbox
->in_ext_byte_len
);
6643 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6644 /* copy command data into host mbox for cmpl */
6645 lpfc_sli_pcimem_bcopy(mb
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6648 /* First copy mbox command data to HBA SLIM, skip past first
6650 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
6651 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
6652 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
6654 /* Next copy over first word, with mbxOwner set */
6655 ldata
= *((uint32_t *)mb
);
6656 to_slim
= phba
->MBslimaddr
;
6657 writel(ldata
, to_slim
);
6658 readl(to_slim
); /* flush */
6660 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6661 /* switch over to host mailbox */
6662 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
6670 /* Set up reference to mailbox command */
6671 psli
->mbox_active
= pmbox
;
6672 /* Interrupt board to do it */
6673 writel(CA_MBATT
, phba
->CAregaddr
);
6674 readl(phba
->CAregaddr
); /* flush */
6675 /* Don't wait for it to finish, just return */
6679 /* Set up null reference to mailbox command */
6680 psli
->mbox_active
= NULL
;
6681 /* Interrupt board to do it */
6682 writel(CA_MBATT
, phba
->CAregaddr
);
6683 readl(phba
->CAregaddr
); /* flush */
6685 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6686 /* First read mbox status word */
6687 word0
= *((uint32_t *)phba
->mbox
);
6688 word0
= le32_to_cpu(word0
);
6690 /* First read mbox status word */
6691 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
6692 spin_unlock_irqrestore(&phba
->hbalock
,
6694 goto out_not_finished
;
6698 /* Read the HBA Host Attention Register */
6699 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6700 spin_unlock_irqrestore(&phba
->hbalock
,
6702 goto out_not_finished
;
6704 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6707 /* Wait for command to complete */
6708 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
6709 (!(ha_copy
& HA_MBATT
) &&
6710 (phba
->link_state
> LPFC_WARM_START
))) {
6711 if (time_after(jiffies
, timeout
)) {
6712 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6713 spin_unlock_irqrestore(&phba
->hbalock
,
6715 goto out_not_finished
;
6718 /* Check if we took a mbox interrupt while we were
6720 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
6721 && (evtctr
!= psli
->slistat
.mbox_event
))
6725 spin_unlock_irqrestore(&phba
->hbalock
,
6728 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6731 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6732 /* First copy command data */
6733 word0
= *((uint32_t *)phba
->mbox
);
6734 word0
= le32_to_cpu(word0
);
6735 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
6738 /* Check real SLIM for any errors */
6739 slimword0
= readl(phba
->MBslimaddr
);
6740 slimmb
= (MAILBOX_t
*) & slimword0
;
6741 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
6742 && slimmb
->mbxStatus
) {
6749 /* First copy command data */
6750 word0
= readl(phba
->MBslimaddr
);
6752 /* Read the HBA Host Attention Register */
6753 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6754 spin_unlock_irqrestore(&phba
->hbalock
,
6756 goto out_not_finished
;
6760 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6761 /* copy results back to user */
6762 lpfc_sli_pcimem_bcopy(phba
->mbox
, mb
, MAILBOX_CMD_SIZE
);
6763 /* Copy the mailbox extension data */
6764 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6765 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
6767 pmbox
->out_ext_byte_len
);
6770 /* First copy command data */
6771 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
6773 /* Copy the mailbox extension data */
6774 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
6775 lpfc_memcpy_from_slim(pmbox
->context2
,
6777 MAILBOX_HBA_EXT_OFFSET
,
6778 pmbox
->out_ext_byte_len
);
6782 writel(HA_MBATT
, phba
->HAregaddr
);
6783 readl(phba
->HAregaddr
); /* flush */
6785 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6786 status
= mb
->mbxStatus
;
6789 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6793 if (processing_queue
) {
6794 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6795 lpfc_mbox_cmpl_put(phba
, pmbox
);
6797 return MBX_NOT_FINISHED
;
6801 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
6802 * @phba: Pointer to HBA context object.
6804 * The function blocks the posting of SLI4 asynchronous mailbox commands from
6805 * the driver internal pending mailbox queue. It will then try to wait out the
6806 * possible outstanding mailbox command before return.
6809 * 0 - the outstanding mailbox command completed; otherwise, the wait for
6810 * the outstanding mailbox command timed out.
6813 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
6815 struct lpfc_sli
*psli
= &phba
->sli
;
6817 unsigned long timeout
= 0;
6819 /* Mark the asynchronous mailbox command posting as blocked */
6820 spin_lock_irq(&phba
->hbalock
);
6821 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
6822 /* Determine how long we might wait for the active mailbox
6823 * command to be gracefully completed by firmware.
6825 if (phba
->sli
.mbox_active
)
6826 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
6827 phba
->sli
.mbox_active
) *
6829 spin_unlock_irq(&phba
->hbalock
);
6831 /* Wait for the outstnading mailbox command to complete */
6832 while (phba
->sli
.mbox_active
) {
6833 /* Check active mailbox complete status every 2ms */
6835 if (time_after(jiffies
, timeout
)) {
6836 /* Timeout, marked the outstanding cmd not complete */
6842 /* Can not cleanly block async mailbox command, fails it */
6844 spin_lock_irq(&phba
->hbalock
);
6845 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6846 spin_unlock_irq(&phba
->hbalock
);
6852 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
6853 * @phba: Pointer to HBA context object.
6855 * The function unblocks and resume posting of SLI4 asynchronous mailbox
6856 * commands from the driver internal pending mailbox queue. It makes sure
6857 * that there is no outstanding mailbox command before resuming posting
6858 * asynchronous mailbox commands. If, for any reason, there is outstanding
6859 * mailbox command, it will try to wait it out before resuming asynchronous
6860 * mailbox command posting.
6863 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
6865 struct lpfc_sli
*psli
= &phba
->sli
;
6867 spin_lock_irq(&phba
->hbalock
);
6868 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6869 /* Asynchronous mailbox posting is not blocked, do nothing */
6870 spin_unlock_irq(&phba
->hbalock
);
6874 /* Outstanding synchronous mailbox command is guaranteed to be done,
6875 * successful or timeout, after timing-out the outstanding mailbox
6876 * command shall always be removed, so just unblock posting async
6877 * mailbox command and resume
6879 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6880 spin_unlock_irq(&phba
->hbalock
);
6882 /* wake up worker thread to post asynchronlous mailbox command */
6883 lpfc_worker_wake_up(phba
);
6887 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
6888 * @phba: Pointer to HBA context object.
6889 * @mboxq: Pointer to mailbox object.
6891 * The function posts a mailbox to the port. The mailbox is expected
6892 * to be comletely filled in and ready for the port to operate on it.
6893 * This routine executes a synchronous completion operation on the
6894 * mailbox by polling for its completion.
6896 * The caller must not be holding any locks when calling this routine.
6899 * MBX_SUCCESS - mailbox posted successfully
6900 * Any of the MBX error values.
6903 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6905 int rc
= MBX_SUCCESS
;
6906 unsigned long iflag
;
6908 uint32_t mcqe_status
;
6910 unsigned long timeout
;
6911 struct lpfc_sli
*psli
= &phba
->sli
;
6912 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
6913 struct lpfc_bmbx_create
*mbox_rgn
;
6914 struct dma_address
*dma_address
;
6915 struct lpfc_register bmbx_reg
;
6918 * Only one mailbox can be active to the bootstrap mailbox region
6919 * at a time and there is no queueing provided.
6921 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6922 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6923 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6924 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6925 "(%d):2532 Mailbox command x%x (x%x/x%x) "
6926 "cannot issue Data: x%x x%x\n",
6927 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6928 mboxq
->u
.mb
.mbxCommand
,
6929 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
6930 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
6931 psli
->sli_flag
, MBX_POLL
);
6932 return MBXERR_ERROR
;
6934 /* The server grabs the token and owns it until release */
6935 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6936 phba
->sli
.mbox_active
= mboxq
;
6937 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6940 * Initialize the bootstrap memory region to avoid stale data areas
6941 * in the mailbox post. Then copy the caller's mailbox contents to
6942 * the bmbx mailbox region.
6944 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
6945 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
6946 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
6947 sizeof(struct lpfc_mqe
));
6949 /* Post the high mailbox dma address to the port and wait for ready. */
6950 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
6951 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
6953 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
6956 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
6957 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
6961 if (time_after(jiffies
, timeout
)) {
6965 } while (!db_ready
);
6967 /* Post the low mailbox dma address to the port. */
6968 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
6969 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
6972 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
6973 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
6977 if (time_after(jiffies
, timeout
)) {
6981 } while (!db_ready
);
6984 * Read the CQ to ensure the mailbox has completed.
6985 * If so, update the mailbox status so that the upper layers
6986 * can complete the request normally.
6988 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
6989 sizeof(struct lpfc_mqe
));
6990 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
6991 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
6992 sizeof(struct lpfc_mcqe
));
6993 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
6995 * When the CQE status indicates a failure and the mailbox status
6996 * indicates success then copy the CQE status into the mailbox status
6997 * (and prefix it with x4000).
6999 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7000 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7001 bf_set(lpfc_mqe_status
, mb
,
7002 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7005 lpfc_sli4_swap_str(phba
, mboxq
);
7007 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7008 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7009 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7010 " x%x x%x CQ: x%x x%x x%x x%x\n",
7011 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7012 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7013 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7014 bf_get(lpfc_mqe_status
, mb
),
7015 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7016 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7017 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7018 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7019 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7020 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7021 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7022 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7023 mboxq
->mcqe
.trailer
);
7025 /* We are holding the token, no needed for lock when release */
7026 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7027 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7028 phba
->sli
.mbox_active
= NULL
;
7029 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7034 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7035 * @phba: Pointer to HBA context object.
7036 * @pmbox: Pointer to mailbox object.
7037 * @flag: Flag indicating how the mailbox need to be processed.
7039 * This function is called by discovery code and HBA management code to submit
7040 * a mailbox command to firmware with SLI-4 interface spec.
7042 * Return codes the caller owns the mailbox command after the return of the
7046 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7049 struct lpfc_sli
*psli
= &phba
->sli
;
7050 unsigned long iflags
;
7053 /* dump from issue mailbox command if setup */
7054 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7056 rc
= lpfc_mbox_dev_check(phba
);
7058 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7059 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7060 "cannot issue Data: x%x x%x\n",
7061 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7062 mboxq
->u
.mb
.mbxCommand
,
7063 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7064 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7065 psli
->sli_flag
, flag
);
7066 goto out_not_finished
;
7069 /* Detect polling mode and jump to a handler */
7070 if (!phba
->sli4_hba
.intr_enable
) {
7071 if (flag
== MBX_POLL
)
7072 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7075 if (rc
!= MBX_SUCCESS
)
7076 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7077 "(%d):2541 Mailbox command x%x "
7078 "(x%x/x%x) cannot issue Data: "
7080 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7081 mboxq
->u
.mb
.mbxCommand
,
7082 lpfc_sli_config_mbox_subsys_get(phba
,
7084 lpfc_sli_config_mbox_opcode_get(phba
,
7086 psli
->sli_flag
, flag
);
7088 } else if (flag
== MBX_POLL
) {
7089 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7090 "(%d):2542 Try to issue mailbox command "
7091 "x%x (x%x/x%x) synchronously ahead of async"
7092 "mailbox command queue: x%x x%x\n",
7093 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7094 mboxq
->u
.mb
.mbxCommand
,
7095 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7096 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7097 psli
->sli_flag
, flag
);
7098 /* Try to block the asynchronous mailbox posting */
7099 rc
= lpfc_sli4_async_mbox_block(phba
);
7101 /* Successfully blocked, now issue sync mbox cmd */
7102 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7103 if (rc
!= MBX_SUCCESS
)
7104 lpfc_printf_log(phba
, KERN_ERR
,
7106 "(%d):2597 Mailbox command "
7107 "x%x (x%x/x%x) cannot issue "
7110 mboxq
->vport
->vpi
: 0,
7111 mboxq
->u
.mb
.mbxCommand
,
7112 lpfc_sli_config_mbox_subsys_get(phba
,
7114 lpfc_sli_config_mbox_opcode_get(phba
,
7116 psli
->sli_flag
, flag
);
7117 /* Unblock the async mailbox posting afterward */
7118 lpfc_sli4_async_mbox_unblock(phba
);
7123 /* Now, interrupt mode asynchrous mailbox command */
7124 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7126 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7127 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7128 "cannot issue Data: x%x x%x\n",
7129 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7130 mboxq
->u
.mb
.mbxCommand
,
7131 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7132 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7133 psli
->sli_flag
, flag
);
7134 goto out_not_finished
;
7137 /* Put the mailbox command to the driver internal FIFO */
7138 psli
->slistat
.mbox_busy
++;
7139 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7140 lpfc_mbox_put(phba
, mboxq
);
7141 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7142 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7143 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7144 "x%x (x%x/x%x) x%x x%x x%x\n",
7145 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7146 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7147 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7148 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7149 phba
->pport
->port_state
,
7150 psli
->sli_flag
, MBX_NOWAIT
);
7151 /* Wake up worker thread to transport mailbox command from head */
7152 lpfc_worker_wake_up(phba
);
7157 return MBX_NOT_FINISHED
;
7161 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7162 * @phba: Pointer to HBA context object.
7164 * This function is called by worker thread to send a mailbox command to
7165 * SLI4 HBA firmware.
7169 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7171 struct lpfc_sli
*psli
= &phba
->sli
;
7172 LPFC_MBOXQ_t
*mboxq
;
7173 int rc
= MBX_SUCCESS
;
7174 unsigned long iflags
;
7175 struct lpfc_mqe
*mqe
;
7178 /* Check interrupt mode before post async mailbox command */
7179 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7180 return MBX_NOT_FINISHED
;
7182 /* Check for mailbox command service token */
7183 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7184 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7185 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7186 return MBX_NOT_FINISHED
;
7188 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7189 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7190 return MBX_NOT_FINISHED
;
7192 if (unlikely(phba
->sli
.mbox_active
)) {
7193 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7194 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7195 "0384 There is pending active mailbox cmd\n");
7196 return MBX_NOT_FINISHED
;
7198 /* Take the mailbox command service token */
7199 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7201 /* Get the next mailbox command from head of queue */
7202 mboxq
= lpfc_mbox_get(phba
);
7204 /* If no more mailbox command waiting for post, we're done */
7206 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7207 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7210 phba
->sli
.mbox_active
= mboxq
;
7211 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7213 /* Check device readiness for posting mailbox command */
7214 rc
= lpfc_mbox_dev_check(phba
);
7216 /* Driver clean routine will clean up pending mailbox */
7217 goto out_not_finished
;
7219 /* Prepare the mbox command to be posted */
7220 mqe
= &mboxq
->u
.mqe
;
7221 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7223 /* Start timer for the mbox_tmo and log some mailbox post messages */
7224 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7225 (HZ
* lpfc_mbox_tmo_val(phba
, mboxq
))));
7227 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7228 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7230 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7231 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7232 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7233 phba
->pport
->port_state
, psli
->sli_flag
);
7235 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7237 lpfc_debugfs_disc_trc(mboxq
->vport
,
7238 LPFC_DISC_TRC_MBOX_VPORT
,
7239 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7240 mbx_cmnd
, mqe
->un
.mb_words
[0],
7241 mqe
->un
.mb_words
[1]);
7243 lpfc_debugfs_disc_trc(phba
->pport
,
7245 "MBOX Send: cmd:x%x mb:x%x x%x",
7246 mbx_cmnd
, mqe
->un
.mb_words
[0],
7247 mqe
->un
.mb_words
[1]);
7250 psli
->slistat
.mbox_cmd
++;
7252 /* Post the mailbox command to the port */
7253 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7254 if (rc
!= MBX_SUCCESS
) {
7255 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7256 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7257 "cannot issue Data: x%x x%x\n",
7258 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7259 mboxq
->u
.mb
.mbxCommand
,
7260 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7261 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7262 psli
->sli_flag
, MBX_NOWAIT
);
7263 goto out_not_finished
;
7269 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7270 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7271 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7272 /* Release the token */
7273 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7274 phba
->sli
.mbox_active
= NULL
;
7275 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7277 return MBX_NOT_FINISHED
;
7281 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7282 * @phba: Pointer to HBA context object.
7283 * @pmbox: Pointer to mailbox object.
7284 * @flag: Flag indicating how the mailbox need to be processed.
7286 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7287 * the API jump table function pointer from the lpfc_hba struct.
7289 * Return codes the caller owns the mailbox command after the return of the
7293 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7295 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7299 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7300 * @phba: The hba struct for which this call is being executed.
7301 * @dev_grp: The HBA PCI-Device group number.
7303 * This routine sets up the mbox interface API function jump table in @phba
7305 * Returns: 0 - success, -ENODEV - failure.
7308 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7312 case LPFC_PCI_DEV_LP
:
7313 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7314 phba
->lpfc_sli_handle_slow_ring_event
=
7315 lpfc_sli_handle_slow_ring_event_s3
;
7316 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7317 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7318 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7320 case LPFC_PCI_DEV_OC
:
7321 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7322 phba
->lpfc_sli_handle_slow_ring_event
=
7323 lpfc_sli_handle_slow_ring_event_s4
;
7324 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7325 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7326 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7329 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7330 "1420 Invalid HBA PCI-device group: 0x%x\n",
7339 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7340 * @phba: Pointer to HBA context object.
7341 * @pring: Pointer to driver SLI ring object.
7342 * @piocb: Pointer to address of newly added command iocb.
7344 * This function is called with hbalock held to add a command
7345 * iocb to the txq when SLI layer cannot submit the command iocb
7349 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7350 struct lpfc_iocbq
*piocb
)
7352 /* Insert the caller's iocb in the txq tail for later processing. */
7353 list_add_tail(&piocb
->list
, &pring
->txq
);
7358 * lpfc_sli_next_iocb - Get the next iocb in the txq
7359 * @phba: Pointer to HBA context object.
7360 * @pring: Pointer to driver SLI ring object.
7361 * @piocb: Pointer to address of newly added command iocb.
7363 * This function is called with hbalock held before a new
7364 * iocb is submitted to the firmware. This function checks
7365 * txq to flush the iocbs in txq to Firmware before
7366 * submitting new iocbs to the Firmware.
7367 * If there are iocbs in the txq which need to be submitted
7368 * to firmware, lpfc_sli_next_iocb returns the first element
7369 * of the txq after dequeuing it from txq.
7370 * If there is no iocb in the txq then the function will return
7371 * *piocb and *piocb is set to NULL. Caller needs to check
7372 * *piocb to find if there are more commands in the txq.
7374 static struct lpfc_iocbq
*
7375 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7376 struct lpfc_iocbq
**piocb
)
7378 struct lpfc_iocbq
* nextiocb
;
7380 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7390 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7391 * @phba: Pointer to HBA context object.
7392 * @ring_number: SLI ring number to issue iocb on.
7393 * @piocb: Pointer to command iocb.
7394 * @flag: Flag indicating if this command can be put into txq.
7396 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7397 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7398 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7399 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7400 * this function allows only iocbs for posting buffers. This function finds
7401 * next available slot in the command ring and posts the command to the
7402 * available slot and writes the port attention register to request HBA start
7403 * processing new iocb. If there is no slot available in the ring and
7404 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7405 * the function returns IOCB_BUSY.
7407 * This function is called with hbalock held. The function will return success
7408 * after it successfully submit the iocb to firmware or after adding to the
7412 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7413 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7415 struct lpfc_iocbq
*nextiocb
;
7417 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7419 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7420 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7421 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7422 lpfc_printf_log(phba
, KERN_ERR
,
7423 LOG_SLI
| LOG_VPORT
,
7424 "1807 IOCB x%x failed. No vport\n",
7425 piocb
->iocb
.ulpCommand
);
7431 /* If the PCI channel is in offline state, do not post iocbs. */
7432 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7435 /* If HBA has a deferred error attention, fail the iocb. */
7436 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7440 * We should never get an IOCB if we are in a < LINK_DOWN state
7442 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7446 * Check to see if we are blocking IOCB processing because of a
7447 * outstanding event.
7449 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7452 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7454 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7455 * can be issued if the link is not up.
7457 switch (piocb
->iocb
.ulpCommand
) {
7458 case CMD_GEN_REQUEST64_CR
:
7459 case CMD_GEN_REQUEST64_CX
:
7460 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7461 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7462 FC_RCTL_DD_UNSOL_CMD
) ||
7463 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7464 MENLO_TRANSPORT_TYPE
))
7468 case CMD_QUE_RING_BUF_CN
:
7469 case CMD_QUE_RING_BUF64_CN
:
7471 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7472 * completion, iocb_cmpl MUST be 0.
7474 if (piocb
->iocb_cmpl
)
7475 piocb
->iocb_cmpl
= NULL
;
7477 case CMD_CREATE_XRI_CR
:
7478 case CMD_CLOSE_XRI_CN
:
7479 case CMD_CLOSE_XRI_CX
:
7486 * For FCP commands, we must be in a state where we can process link
7489 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7490 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7494 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7495 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7496 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7499 lpfc_sli_update_ring(phba
, pring
);
7501 lpfc_sli_update_full_ring(phba
, pring
);
7504 return IOCB_SUCCESS
;
7509 pring
->stats
.iocb_cmd_delay
++;
7513 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7514 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7515 return IOCB_SUCCESS
;
7522 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7523 * @phba: Pointer to HBA context object.
7524 * @piocb: Pointer to command iocb.
7525 * @sglq: Pointer to the scatter gather queue object.
7527 * This routine converts the bpl or bde that is in the IOCB
7528 * to a sgl list for the sli4 hardware. The physical address
7529 * of the bpl/bde is converted back to a virtual address.
7530 * If the IOCB contains a BPL then the list of BDE's is
7531 * converted to sli4_sge's. If the IOCB contains a single
7532 * BDE then it is converted to a single sli_sge.
7533 * The IOCB is still in cpu endianess so the contents of
7534 * the bpl can be used without byte swapping.
7536 * Returns valid XRI = Success, NO_XRI = Failure.
7539 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7540 struct lpfc_sglq
*sglq
)
7542 uint16_t xritag
= NO_XRI
;
7543 struct ulp_bde64
*bpl
= NULL
;
7544 struct ulp_bde64 bde
;
7545 struct sli4_sge
*sgl
= NULL
;
7546 struct lpfc_dmabuf
*dmabuf
;
7550 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7551 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7553 if (!piocbq
|| !sglq
)
7556 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7557 icmd
= &piocbq
->iocb
;
7558 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7559 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7560 sizeof(struct ulp_bde64
);
7561 /* The addrHigh and addrLow fields within the IOCB
7562 * have not been byteswapped yet so there is no
7563 * need to swap them back.
7565 if (piocbq
->context3
)
7566 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7570 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7574 for (i
= 0; i
< numBdes
; i
++) {
7575 /* Should already be byte swapped. */
7576 sgl
->addr_hi
= bpl
->addrHigh
;
7577 sgl
->addr_lo
= bpl
->addrLow
;
7579 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7580 if ((i
+1) == numBdes
)
7581 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7583 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7584 /* swap the size field back to the cpu so we
7585 * can assign it to the sgl.
7587 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7588 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7589 /* The offsets in the sgl need to be accumulated
7590 * separately for the request and reply lists.
7591 * The request is always first, the reply follows.
7593 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7594 /* add up the reply sg entries */
7595 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7597 /* first inbound? reset the offset */
7600 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7601 bf_set(lpfc_sli4_sge_type
, sgl
,
7602 LPFC_SGE_TYPE_DATA
);
7603 offset
+= bde
.tus
.f
.bdeSize
;
7605 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7609 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
7610 /* The addrHigh and addrLow fields of the BDE have not
7611 * been byteswapped yet so they need to be swapped
7612 * before putting them in the sgl.
7615 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
7617 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
7618 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7619 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7620 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7622 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
7624 return sglq
->sli4_xritag
;
7628 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7629 * @phba: Pointer to HBA context object.
7631 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7632 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7635 * Return: index into SLI4 fast-path FCP queue index.
7638 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
7641 if (phba
->fcp_qidx
>= phba
->cfg_fcp_wq_count
)
7644 return phba
->fcp_qidx
;
7648 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7649 * @phba: Pointer to HBA context object.
7650 * @piocb: Pointer to command iocb.
7651 * @wqe: Pointer to the work queue entry.
7653 * This routine converts the iocb command to its Work Queue Entry
7654 * equivalent. The wqe pointer should not have any fields set when
7655 * this routine is called because it will memcpy over them.
7656 * This routine does not set the CQ_ID or the WQEC bits in the
7659 * Returns: 0 = Success, IOCB_ERROR = Failure.
7662 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
7663 union lpfc_wqe
*wqe
)
7665 uint32_t xmit_len
= 0, total_len
= 0;
7669 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
7672 uint16_t abrt_iotag
;
7673 struct lpfc_iocbq
*abrtiocbq
;
7674 struct ulp_bde64
*bpl
= NULL
;
7675 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
7677 struct ulp_bde64 bde
;
7678 struct lpfc_nodelist
*ndlp
;
7682 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
7683 /* The fcp commands will set command type */
7684 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7685 command_type
= FCP_COMMAND
;
7686 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
7687 command_type
= ELS_COMMAND_FIP
;
7689 command_type
= ELS_COMMAND_NON_FIP
;
7691 /* Some of the fields are in the right position already */
7692 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
7693 abort_tag
= (uint32_t) iocbq
->iotag
;
7694 xritag
= iocbq
->sli4_xritag
;
7695 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
7696 /* words0-2 bpl convert bde */
7697 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7698 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7699 sizeof(struct ulp_bde64
);
7700 bpl
= (struct ulp_bde64
*)
7701 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
7705 /* Should already be byte swapped. */
7706 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
7707 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
7708 /* swap the size field back to the cpu so we
7709 * can assign it to the sgl.
7711 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7712 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
7714 for (i
= 0; i
< numBdes
; i
++) {
7715 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7716 total_len
+= bde
.tus
.f
.bdeSize
;
7719 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
7721 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
7722 cmnd
= iocbq
->iocb
.ulpCommand
;
7724 switch (iocbq
->iocb
.ulpCommand
) {
7725 case CMD_ELS_REQUEST64_CR
:
7726 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7727 if (!iocbq
->iocb
.ulpLe
) {
7728 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7729 "2007 Only Limited Edition cmd Format"
7730 " supported 0x%x\n",
7731 iocbq
->iocb
.ulpCommand
);
7735 wqe
->els_req
.payload_len
= xmit_len
;
7736 /* Els_reguest64 has a TMO */
7737 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
7738 iocbq
->iocb
.ulpTimeout
);
7739 /* Need a VF for word 4 set the vf bit*/
7740 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
7741 /* And a VFID for word 12 */
7742 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
7743 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7744 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7745 iocbq
->iocb
.ulpContext
);
7746 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
7747 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
7748 /* CCP CCPE PV PRI in word10 were set in the memcpy */
7749 if (command_type
== ELS_COMMAND_FIP
)
7750 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
7751 >> LPFC_FIP_ELS_ID_SHIFT
);
7752 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7753 iocbq
->context2
)->virt
);
7754 if_type
= bf_get(lpfc_sli_intf_if_type
,
7755 &phba
->sli4_hba
.sli_intf
);
7756 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7757 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
7758 *pcmd
== ELS_CMD_SCR
||
7759 *pcmd
== ELS_CMD_PLOGI
)) {
7760 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7761 bf_set(els_req64_sid
, &wqe
->els_req
,
7762 iocbq
->vport
->fc_myDID
);
7763 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7764 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7765 phba
->vpi_ids
[phba
->pport
->vpi
]);
7766 } else if (iocbq
->context1
) {
7767 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
7768 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7769 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7772 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
7773 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7774 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
7775 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
7776 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7777 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
7778 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7779 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
7781 case CMD_XMIT_SEQUENCE64_CX
:
7782 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
7783 iocbq
->iocb
.un
.ulpWord
[3]);
7784 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
7785 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7786 /* The entire sequence is transmitted for this IOCB */
7787 xmit_len
= total_len
;
7788 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
7789 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
7790 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
7791 case CMD_XMIT_SEQUENCE64_CR
:
7792 /* word3 iocb=io_tag32 wqe=reserved */
7793 wqe
->xmit_sequence
.rsvd3
= 0;
7794 /* word4 relative_offset memcpy */
7795 /* word5 r_ctl/df_ctl memcpy */
7796 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
7797 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
7798 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
7799 LPFC_WQE_IOD_WRITE
);
7800 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
7801 LPFC_WQE_LENLOC_WORD12
);
7802 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
7803 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
7804 command_type
= OTHER_COMMAND
;
7806 case CMD_XMIT_BCAST64_CN
:
7807 /* word3 iocb=iotag32 wqe=seq_payload_len */
7808 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
7809 /* word4 iocb=rsvd wqe=rsvd */
7810 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
7811 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
7812 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
7813 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7814 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
7815 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7816 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
7817 LPFC_WQE_LENLOC_WORD3
);
7818 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
7820 case CMD_FCP_IWRITE64_CR
:
7821 command_type
= FCP_COMMAND_DATA_OUT
;
7822 /* word3 iocb=iotag wqe=payload_offset_len */
7823 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7824 wqe
->fcp_iwrite
.payload_offset_len
=
7825 xmit_len
+ sizeof(struct fcp_rsp
);
7826 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7827 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7828 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
7829 iocbq
->iocb
.ulpFCP2Rcvy
);
7830 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
7831 /* Always open the exchange */
7832 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
7833 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
7834 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7835 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
7836 LPFC_WQE_LENLOC_WORD4
);
7837 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
7838 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
7840 case CMD_FCP_IREAD64_CR
:
7841 /* word3 iocb=iotag wqe=payload_offset_len */
7842 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
7843 wqe
->fcp_iread
.payload_offset_len
=
7844 xmit_len
+ sizeof(struct fcp_rsp
);
7845 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
7846 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
7847 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
7848 iocbq
->iocb
.ulpFCP2Rcvy
);
7849 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
7850 /* Always open the exchange */
7851 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
7852 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
7853 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
7854 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
7855 LPFC_WQE_LENLOC_WORD4
);
7856 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
7857 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
7859 case CMD_FCP_ICMND64_CR
:
7860 /* word3 iocb=IO_TAG wqe=reserved */
7861 wqe
->fcp_icmd
.rsrvd3
= 0;
7862 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
7863 /* Always open the exchange */
7864 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
7865 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
7866 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7867 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
7868 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
7869 LPFC_WQE_LENLOC_NONE
);
7870 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
7872 case CMD_GEN_REQUEST64_CR
:
7873 /* For this command calculate the xmit length of the
7877 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7878 sizeof(struct ulp_bde64
);
7879 for (i
= 0; i
< numBdes
; i
++) {
7880 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7881 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
7883 xmit_len
+= bde
.tus
.f
.bdeSize
;
7885 /* word3 iocb=IO_TAG wqe=request_payload_len */
7886 wqe
->gen_req
.request_payload_len
= xmit_len
;
7887 /* word4 iocb=parameter wqe=relative_offset memcpy */
7888 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
7889 /* word6 context tag copied in memcpy */
7890 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
7891 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
7892 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7893 "2015 Invalid CT %x command 0x%x\n",
7894 ct
, iocbq
->iocb
.ulpCommand
);
7897 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
7898 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
7899 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
7900 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
7901 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
7902 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
7903 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
7904 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
7905 command_type
= OTHER_COMMAND
;
7907 case CMD_XMIT_ELS_RSP64_CX
:
7908 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
7909 /* words0-2 BDE memcpy */
7910 /* word3 iocb=iotag32 wqe=response_payload_len */
7911 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
7912 /* word4 iocb=did wge=rsvd. */
7913 wqe
->xmit_els_rsp
.rsvd4
= 0;
7914 /* word5 iocb=rsvd wge=did */
7915 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
7916 iocbq
->iocb
.un
.elsreq64
.remoteID
);
7917 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
7918 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7919 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
7920 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
7921 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
7922 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
7923 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
7924 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
7925 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
7926 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
7927 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
7928 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
7929 LPFC_WQE_LENLOC_WORD3
);
7930 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
7931 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
7932 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
7933 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7934 iocbq
->context2
)->virt
);
7935 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
7936 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
7937 bf_set(els_req64_sid
, &wqe
->els_req
,
7938 iocbq
->vport
->fc_myDID
);
7939 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
7940 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
7941 phba
->vpi_ids
[phba
->pport
->vpi
]);
7943 command_type
= OTHER_COMMAND
;
7945 case CMD_CLOSE_XRI_CN
:
7946 case CMD_ABORT_XRI_CN
:
7947 case CMD_ABORT_XRI_CX
:
7948 /* words 0-2 memcpy should be 0 rserved */
7949 /* port will send abts */
7950 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
7951 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
7952 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
7953 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
7957 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
7959 * The link is down, or the command was ELS_FIP
7960 * so the fw does not need to send abts
7963 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
7965 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
7966 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
7967 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
7968 wqe
->abort_cmd
.rsrvd5
= 0;
7969 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
7970 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
7971 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
7973 * The abort handler will send us CMD_ABORT_XRI_CN or
7974 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
7976 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
7977 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
7978 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
7979 LPFC_WQE_LENLOC_NONE
);
7980 cmnd
= CMD_ABORT_XRI_CX
;
7981 command_type
= OTHER_COMMAND
;
7984 case CMD_XMIT_BLS_RSP64_CX
:
7985 /* As BLS ABTS RSP WQE is very different from other WQEs,
7986 * we re-construct this WQE here based on information in
7987 * iocbq from scratch.
7989 memset(wqe
, 0, sizeof(union lpfc_wqe
));
7990 /* OX_ID is invariable to who sent ABTS to CT exchange */
7991 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
7992 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
7993 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
7994 LPFC_ABTS_UNSOL_INT
) {
7995 /* ABTS sent by initiator to CT exchange, the
7996 * RX_ID field will be filled with the newly
7997 * allocated responder XRI.
7999 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8000 iocbq
->sli4_xritag
);
8002 /* ABTS sent by responder to CT exchange, the
8003 * RX_ID field will be filled with the responder
8006 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8007 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8009 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8010 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8011 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8012 iocbq
->iocb
.ulpContext
);
8013 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8014 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8015 LPFC_WQE_LENLOC_NONE
);
8016 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8017 command_type
= OTHER_COMMAND
;
8018 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8019 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8020 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8021 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8022 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8023 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8024 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8028 case CMD_XRI_ABORTED_CX
:
8029 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8030 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8031 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8032 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8033 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8035 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8036 "2014 Invalid command 0x%x\n",
8037 iocbq
->iocb
.ulpCommand
);
8042 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8043 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8044 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8045 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8046 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8047 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8048 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8053 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8054 * @phba: Pointer to HBA context object.
8055 * @ring_number: SLI ring number to issue iocb on.
8056 * @piocb: Pointer to command iocb.
8057 * @flag: Flag indicating if this command can be put into txq.
8059 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8060 * an iocb command to an HBA with SLI-4 interface spec.
8062 * This function is called with hbalock held. The function will return success
8063 * after it successfully submit the iocb to firmware or after adding to the
8067 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8068 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8070 struct lpfc_sglq
*sglq
;
8072 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8074 if (piocb
->sli4_xritag
== NO_XRI
) {
8075 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8076 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
||
8077 piocb
->iocb
.ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
8080 if (pring
->txq_cnt
) {
8081 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8082 __lpfc_sli_ringtx_put(phba
,
8084 return IOCB_SUCCESS
;
8089 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8091 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8092 __lpfc_sli_ringtx_put(phba
,
8095 return IOCB_SUCCESS
;
8101 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8102 /* These IO's already have an XRI and a mapped sgl. */
8106 * This is a continuation of a commandi,(CX) so this
8107 * sglq is on the active list
8109 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_xritag
);
8115 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8116 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8117 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8121 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8124 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8125 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8127 * For FCP command IOCB, get a new WQ index to distribute
8128 * WQE across the WQsr. On the other hand, for abort IOCB,
8129 * it carries the same WQ index to the original command
8132 if (piocb
->iocb_flag
& LPFC_IO_FCP
)
8133 piocb
->fcp_wqidx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8134 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8136 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8140 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8143 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8149 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8151 * This routine wraps the actual lockless version for issusing IOCB function
8152 * pointer from the lpfc_hba struct.
8155 * IOCB_ERROR - Error
8156 * IOCB_SUCCESS - Success
8160 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8161 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8163 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8167 * lpfc_sli_api_table_setup - Set up sli api function jump table
8168 * @phba: The hba struct for which this call is being executed.
8169 * @dev_grp: The HBA PCI-Device group number.
8171 * This routine sets up the SLI interface API function jump table in @phba
8173 * Returns: 0 - success, -ENODEV - failure.
8176 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8180 case LPFC_PCI_DEV_LP
:
8181 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8182 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8184 case LPFC_PCI_DEV_OC
:
8185 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8186 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8189 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8190 "1419 Invalid HBA PCI-device group: 0x%x\n",
8195 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8200 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8201 * @phba: Pointer to HBA context object.
8202 * @pring: Pointer to driver SLI ring object.
8203 * @piocb: Pointer to command iocb.
8204 * @flag: Flag indicating if this command can be put into txq.
8206 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8207 * function. This function gets the hbalock and calls
8208 * __lpfc_sli_issue_iocb function and will return the error returned
8209 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8210 * functions which do not hold hbalock.
8213 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8214 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8216 unsigned long iflags
;
8219 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8220 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8221 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8227 * lpfc_extra_ring_setup - Extra ring setup function
8228 * @phba: Pointer to HBA context object.
8230 * This function is called while driver attaches with the
8231 * HBA to setup the extra ring. The extra ring is used
8232 * only when driver needs to support target mode functionality
8233 * or IP over FC functionalities.
8235 * This function is called with no lock held.
8238 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8240 struct lpfc_sli
*psli
;
8241 struct lpfc_sli_ring
*pring
;
8245 /* Adjust cmd/rsp ring iocb entries more evenly */
8247 /* Take some away from the FCP ring */
8248 pring
= &psli
->ring
[psli
->fcp_ring
];
8249 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8250 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8251 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8252 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8254 /* and give them to the extra ring */
8255 pring
= &psli
->ring
[psli
->extra_ring
];
8257 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8258 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8259 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8260 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8262 /* Setup default profile for this ring */
8263 pring
->iotag_max
= 4096;
8264 pring
->num_mask
= 1;
8265 pring
->prt
[0].profile
= 0; /* Mask 0 */
8266 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8267 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8268 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8272 /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
8273 * @vport: pointer to virtual port object.
8274 * @ndlp: nodelist pointer for the impacted rport.
8276 * The driver calls this routine in response to a XRI ABORT CQE
8277 * event from the port. In this event, the driver is required to
8278 * recover its login to the rport even though its login may be valid
8279 * from the driver's perspective. The failed ABTS notice from the
8280 * port indicates the rport is not responding.
8283 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8284 struct lpfc_nodelist
*ndlp
)
8286 struct Scsi_Host
*shost
;
8287 struct lpfc_hba
*phba
;
8288 unsigned long flags
= 0;
8290 shost
= lpfc_shost_from_vport(vport
);
8292 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8293 lpfc_printf_log(phba
, KERN_INFO
,
8294 LOG_SLI
, "3093 No rport recovery needed. "
8295 "rport in state 0x%x\n",
8299 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8300 "3094 Start rport recovery on shost id 0x%x "
8301 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8303 shost
->host_no
, ndlp
->nlp_DID
,
8304 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8307 * The rport is not responding. Don't attempt ADISC recovery.
8308 * Remove the FCP-2 flag to force a PLOGI.
8310 spin_lock_irqsave(shost
->host_lock
, flags
);
8311 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8312 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8313 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
8314 NLP_EVT_DEVICE_RECOVERY
);
8315 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
8316 spin_lock_irqsave(shost
->host_lock
, flags
);
8317 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
8318 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8319 lpfc_disc_start(vport
);
8322 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8323 * @phba: Pointer to HBA context object.
8324 * @iocbq: Pointer to iocb object.
8326 * The async_event handler calls this routine when it receives
8327 * an ASYNC_STATUS_CN event from the port. The port generates
8328 * this event when an Abort Sequence request to an rport fails
8329 * twice in succession. The abort could be originated by the
8330 * driver or by the port. The ABTS could have been for an ELS
8331 * or FCP IO. The port only generates this event when an ABTS
8332 * fails to complete after one retry.
8335 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8336 struct lpfc_iocbq
*iocbq
)
8338 struct lpfc_nodelist
*ndlp
= NULL
;
8339 uint16_t rpi
= 0, vpi
= 0;
8340 struct lpfc_vport
*vport
= NULL
;
8342 /* The rpi in the ulpContext is vport-sensitive. */
8343 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8344 rpi
= iocbq
->iocb
.ulpContext
;
8346 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8347 "3092 Port generated ABTS async event "
8348 "on vpi %d rpi %d status 0x%x\n",
8349 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8351 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8354 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8355 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8358 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8359 lpfc_sli_abts_recover_port(vport
, ndlp
);
8363 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8364 "3095 Event Context not found, no "
8365 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8366 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8370 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8371 * @phba: pointer to HBA context object.
8372 * @ndlp: nodelist pointer for the impacted rport.
8373 * @axri: pointer to the wcqe containing the failed exchange.
8375 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8376 * port. The port generates this event when an abort exchange request to an
8377 * rport fails twice in succession with no reply. The abort could be originated
8378 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8381 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8382 struct lpfc_nodelist
*ndlp
,
8383 struct sli4_wcqe_xri_aborted
*axri
)
8385 struct lpfc_vport
*vport
;
8387 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8388 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8389 "3115 Node Context not found, driver "
8390 "ignoring abts err event\n");
8391 vport
= ndlp
->vport
;
8392 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8393 "3116 Port generated FCP XRI ABORT event on "
8394 "vpi %d rpi %d xri x%x status 0x%x\n",
8395 ndlp
->vport
->vpi
, ndlp
->nlp_rpi
,
8396 bf_get(lpfc_wcqe_xa_xri
, axri
),
8397 bf_get(lpfc_wcqe_xa_status
, axri
));
8399 if (bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
)
8400 lpfc_sli_abts_recover_port(vport
, ndlp
);
8404 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8405 * @phba: Pointer to HBA context object.
8406 * @pring: Pointer to driver SLI ring object.
8407 * @iocbq: Pointer to iocb object.
8409 * This function is called by the slow ring event handler
8410 * function when there is an ASYNC event iocb in the ring.
8411 * This function is called with no lock held.
8412 * Currently this function handles only temperature related
8413 * ASYNC events. The function decodes the temperature sensor
8414 * event message and posts events for the management applications.
8417 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8418 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8422 struct temp_event temp_event_data
;
8423 struct Scsi_Host
*shost
;
8426 icmd
= &iocbq
->iocb
;
8427 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8430 case ASYNC_TEMP_WARN
:
8431 case ASYNC_TEMP_SAFE
:
8432 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8433 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8434 if (evt_code
== ASYNC_TEMP_WARN
) {
8435 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8436 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8437 "0347 Adapter is very hot, please take "
8438 "corrective action. temperature : %d Celsius\n",
8439 (uint32_t) icmd
->ulpContext
);
8441 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8442 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8443 "0340 Adapter temperature is OK now. "
8444 "temperature : %d Celsius\n",
8445 (uint32_t) icmd
->ulpContext
);
8448 /* Send temperature change event to applications */
8449 shost
= lpfc_shost_from_vport(phba
->pport
);
8450 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8451 sizeof(temp_event_data
), (char *) &temp_event_data
,
8454 case ASYNC_STATUS_CN
:
8455 lpfc_sli_abts_err_handler(phba
, iocbq
);
8458 iocb_w
= (uint32_t *) icmd
;
8459 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8460 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8462 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8463 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8464 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8465 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8466 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8467 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8468 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8469 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8470 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8478 * lpfc_sli_setup - SLI ring setup function
8479 * @phba: Pointer to HBA context object.
8481 * lpfc_sli_setup sets up rings of the SLI interface with
8482 * number of iocbs per ring and iotags. This function is
8483 * called while driver attach to the HBA and before the
8484 * interrupts are enabled. So there is no need for locking.
8486 * This function always returns 0.
8489 lpfc_sli_setup(struct lpfc_hba
*phba
)
8491 int i
, totiocbsize
= 0;
8492 struct lpfc_sli
*psli
= &phba
->sli
;
8493 struct lpfc_sli_ring
*pring
;
8495 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
8497 psli
->fcp_ring
= LPFC_FCP_RING
;
8498 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8499 psli
->extra_ring
= LPFC_EXTRA_RING
;
8501 psli
->iocbq_lookup
= NULL
;
8502 psli
->iocbq_lookup_len
= 0;
8503 psli
->last_iotag
= 0;
8505 for (i
= 0; i
< psli
->num_rings
; i
++) {
8506 pring
= &psli
->ring
[i
];
8508 case LPFC_FCP_RING
: /* ring 0 - FCP */
8509 /* numCiocb and numRiocb are used in config_port */
8510 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8511 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8512 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8513 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8514 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8515 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8516 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8517 SLI3_IOCB_CMD_SIZE
:
8519 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8520 SLI3_IOCB_RSP_SIZE
:
8522 pring
->iotag_ctr
= 0;
8524 (phba
->cfg_hba_queue_depth
* 2);
8525 pring
->fast_iotag
= pring
->iotag_max
;
8526 pring
->num_mask
= 0;
8528 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
8529 /* numCiocb and numRiocb are used in config_port */
8530 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
8531 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
8532 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8533 SLI3_IOCB_CMD_SIZE
:
8535 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8536 SLI3_IOCB_RSP_SIZE
:
8538 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
8539 pring
->num_mask
= 0;
8541 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
8542 /* numCiocb and numRiocb are used in config_port */
8543 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
8544 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
8545 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
8546 SLI3_IOCB_CMD_SIZE
:
8548 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
8549 SLI3_IOCB_RSP_SIZE
:
8551 pring
->fast_iotag
= 0;
8552 pring
->iotag_ctr
= 0;
8553 pring
->iotag_max
= 4096;
8554 pring
->lpfc_sli_rcv_async_status
=
8555 lpfc_sli_async_event_handler
;
8556 pring
->num_mask
= LPFC_MAX_RING_MASK
;
8557 pring
->prt
[0].profile
= 0; /* Mask 0 */
8558 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
8559 pring
->prt
[0].type
= FC_TYPE_ELS
;
8560 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
8561 lpfc_els_unsol_event
;
8562 pring
->prt
[1].profile
= 0; /* Mask 1 */
8563 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
8564 pring
->prt
[1].type
= FC_TYPE_ELS
;
8565 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
8566 lpfc_els_unsol_event
;
8567 pring
->prt
[2].profile
= 0; /* Mask 2 */
8568 /* NameServer Inquiry */
8569 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
8571 pring
->prt
[2].type
= FC_TYPE_CT
;
8572 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
8573 lpfc_ct_unsol_event
;
8574 pring
->prt
[3].profile
= 0; /* Mask 3 */
8575 /* NameServer response */
8576 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
8578 pring
->prt
[3].type
= FC_TYPE_CT
;
8579 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
8580 lpfc_ct_unsol_event
;
8581 /* abort unsolicited sequence */
8582 pring
->prt
[4].profile
= 0; /* Mask 4 */
8583 pring
->prt
[4].rctl
= FC_RCTL_BA_ABTS
;
8584 pring
->prt
[4].type
= FC_TYPE_BLS
;
8585 pring
->prt
[4].lpfc_sli_rcv_unsol_event
=
8586 lpfc_sli4_ct_abort_unsol_event
;
8589 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
8590 (pring
->numRiocb
* pring
->sizeRiocb
);
8592 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
8593 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8594 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
8595 "SLI2 SLIM Data: x%x x%lx\n",
8596 phba
->brd_no
, totiocbsize
,
8597 (unsigned long) MAX_SLIM_IOCB_SIZE
);
8599 if (phba
->cfg_multi_ring_support
== 2)
8600 lpfc_extra_ring_setup(phba
);
8606 * lpfc_sli_queue_setup - Queue initialization function
8607 * @phba: Pointer to HBA context object.
8609 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8610 * ring. This function also initializes ring indices of each ring.
8611 * This function is called during the initialization of the SLI
8612 * interface of an HBA.
8613 * This function is called with no lock held and always returns
8617 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
8619 struct lpfc_sli
*psli
;
8620 struct lpfc_sli_ring
*pring
;
8624 spin_lock_irq(&phba
->hbalock
);
8625 INIT_LIST_HEAD(&psli
->mboxq
);
8626 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
8627 /* Initialize list headers for txq and txcmplq as double linked lists */
8628 for (i
= 0; i
< psli
->num_rings
; i
++) {
8629 pring
= &psli
->ring
[i
];
8631 pring
->next_cmdidx
= 0;
8632 pring
->local_getidx
= 0;
8634 INIT_LIST_HEAD(&pring
->txq
);
8635 INIT_LIST_HEAD(&pring
->txcmplq
);
8636 INIT_LIST_HEAD(&pring
->iocb_continueq
);
8637 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
8638 INIT_LIST_HEAD(&pring
->postbufq
);
8640 spin_unlock_irq(&phba
->hbalock
);
8645 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8646 * @phba: Pointer to HBA context object.
8648 * This routine flushes the mailbox command subsystem. It will unconditionally
8649 * flush all the mailbox commands in the three possible stages in the mailbox
8650 * command sub-system: pending mailbox command queue; the outstanding mailbox
8651 * command; and completed mailbox command queue. It is caller's responsibility
8652 * to make sure that the driver is in the proper state to flush the mailbox
8653 * command sub-system. Namely, the posting of mailbox commands into the
8654 * pending mailbox command queue from the various clients must be stopped;
8655 * either the HBA is in a state that it will never works on the outstanding
8656 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8657 * mailbox command has been completed.
8660 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
8662 LIST_HEAD(completions
);
8663 struct lpfc_sli
*psli
= &phba
->sli
;
8665 unsigned long iflag
;
8667 /* Flush all the mailbox commands in the mbox system */
8668 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8669 /* The pending mailbox command queue */
8670 list_splice_init(&phba
->sli
.mboxq
, &completions
);
8671 /* The outstanding active mailbox command */
8672 if (psli
->mbox_active
) {
8673 list_add_tail(&psli
->mbox_active
->list
, &completions
);
8674 psli
->mbox_active
= NULL
;
8675 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8677 /* The completed mailbox command queue */
8678 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
8679 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8681 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
8682 while (!list_empty(&completions
)) {
8683 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
8684 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8686 pmb
->mbox_cmpl(phba
, pmb
);
8691 * lpfc_sli_host_down - Vport cleanup function
8692 * @vport: Pointer to virtual port object.
8694 * lpfc_sli_host_down is called to clean up the resources
8695 * associated with a vport before destroying virtual
8696 * port data structures.
8697 * This function does following operations:
8698 * - Free discovery resources associated with this virtual
8700 * - Free iocbs associated with this virtual port in
8702 * - Send abort for all iocb commands associated with this
8705 * This function is called with no lock held and always returns 1.
8708 lpfc_sli_host_down(struct lpfc_vport
*vport
)
8710 LIST_HEAD(completions
);
8711 struct lpfc_hba
*phba
= vport
->phba
;
8712 struct lpfc_sli
*psli
= &phba
->sli
;
8713 struct lpfc_sli_ring
*pring
;
8714 struct lpfc_iocbq
*iocb
, *next_iocb
;
8716 unsigned long flags
= 0;
8717 uint16_t prev_pring_flag
;
8719 lpfc_cleanup_discovery_resources(vport
);
8721 spin_lock_irqsave(&phba
->hbalock
, flags
);
8722 for (i
= 0; i
< psli
->num_rings
; i
++) {
8723 pring
= &psli
->ring
[i
];
8724 prev_pring_flag
= pring
->flag
;
8725 /* Only slow rings */
8726 if (pring
->ringno
== LPFC_ELS_RING
) {
8727 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8728 /* Set the lpfc data pending flag */
8729 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8732 * Error everything on the txq since these iocbs have not been
8733 * given to the FW yet.
8735 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
8736 if (iocb
->vport
!= vport
)
8738 list_move_tail(&iocb
->list
, &completions
);
8742 /* Next issue ABTS for everything on the txcmplq */
8743 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
8745 if (iocb
->vport
!= vport
)
8747 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
8750 pring
->flag
= prev_pring_flag
;
8753 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8755 /* Cancel all the IOCBs from the completions list */
8756 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8762 * lpfc_sli_hba_down - Resource cleanup function for the HBA
8763 * @phba: Pointer to HBA context object.
8765 * This function cleans up all iocb, buffers, mailbox commands
8766 * while shutting down the HBA. This function is called with no
8767 * lock held and always returns 1.
8768 * This function does the following to cleanup driver resources:
8769 * - Free discovery resources for each virtual port
8770 * - Cleanup any pending fabric iocbs
8771 * - Iterate through the iocb txq and free each entry
8773 * - Free up any buffer posted to the HBA
8774 * - Free mailbox commands in the mailbox queue.
8777 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
8779 LIST_HEAD(completions
);
8780 struct lpfc_sli
*psli
= &phba
->sli
;
8781 struct lpfc_sli_ring
*pring
;
8782 struct lpfc_dmabuf
*buf_ptr
;
8783 unsigned long flags
= 0;
8786 /* Shutdown the mailbox command sub-system */
8787 lpfc_sli_mbox_sys_shutdown(phba
);
8789 lpfc_hba_down_prep(phba
);
8791 lpfc_fabric_abort_hba(phba
);
8793 spin_lock_irqsave(&phba
->hbalock
, flags
);
8794 for (i
= 0; i
< psli
->num_rings
; i
++) {
8795 pring
= &psli
->ring
[i
];
8796 /* Only slow rings */
8797 if (pring
->ringno
== LPFC_ELS_RING
) {
8798 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
8799 /* Set the lpfc data pending flag */
8800 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
8804 * Error everything on the txq since these iocbs have not been
8805 * given to the FW yet.
8807 list_splice_init(&pring
->txq
, &completions
);
8811 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8813 /* Cancel all the IOCBs from the completions list */
8814 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8817 spin_lock_irqsave(&phba
->hbalock
, flags
);
8818 list_splice_init(&phba
->elsbuf
, &completions
);
8819 phba
->elsbuf_cnt
= 0;
8820 phba
->elsbuf_prev_cnt
= 0;
8821 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
8823 while (!list_empty(&completions
)) {
8824 list_remove_head(&completions
, buf_ptr
,
8825 struct lpfc_dmabuf
, list
);
8826 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
8830 /* Return any active mbox cmds */
8831 del_timer_sync(&psli
->mbox_tmo
);
8833 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
8834 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
8835 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
8841 * lpfc_sli_pcimem_bcopy - SLI memory copy function
8842 * @srcp: Source memory pointer.
8843 * @destp: Destination memory pointer.
8844 * @cnt: Number of words required to be copied.
8846 * This function is used for copying data between driver memory
8847 * and the SLI memory. This function also changes the endianness
8848 * of each word if native endianness is different from SLI
8849 * endianness. This function can be called with or without
8853 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
8855 uint32_t *src
= srcp
;
8856 uint32_t *dest
= destp
;
8860 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
8862 ldata
= le32_to_cpu(ldata
);
8871 * lpfc_sli_bemem_bcopy - SLI memory copy function
8872 * @srcp: Source memory pointer.
8873 * @destp: Destination memory pointer.
8874 * @cnt: Number of words required to be copied.
8876 * This function is used for copying data between a data structure
8877 * with big endian representation to local endianness.
8878 * This function can be called with or without lock.
8881 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
8883 uint32_t *src
= srcp
;
8884 uint32_t *dest
= destp
;
8888 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
8890 ldata
= be32_to_cpu(ldata
);
8898 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
8899 * @phba: Pointer to HBA context object.
8900 * @pring: Pointer to driver SLI ring object.
8901 * @mp: Pointer to driver buffer object.
8903 * This function is called with no lock held.
8904 * It always return zero after adding the buffer to the postbufq
8908 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8909 struct lpfc_dmabuf
*mp
)
8911 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
8913 spin_lock_irq(&phba
->hbalock
);
8914 list_add_tail(&mp
->list
, &pring
->postbufq
);
8915 pring
->postbufq_cnt
++;
8916 spin_unlock_irq(&phba
->hbalock
);
8921 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
8922 * @phba: Pointer to HBA context object.
8924 * When HBQ is enabled, buffers are searched based on tags. This function
8925 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
8926 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
8927 * does not conflict with tags of buffer posted for unsolicited events.
8928 * The function returns the allocated tag. The function is called with
8932 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
8934 spin_lock_irq(&phba
->hbalock
);
8935 phba
->buffer_tag_count
++;
8937 * Always set the QUE_BUFTAG_BIT to distiguish between
8938 * a tag assigned by HBQ.
8940 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
8941 spin_unlock_irq(&phba
->hbalock
);
8942 return phba
->buffer_tag_count
;
8946 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
8947 * @phba: Pointer to HBA context object.
8948 * @pring: Pointer to driver SLI ring object.
8951 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
8952 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
8953 * iocb is posted to the response ring with the tag of the buffer.
8954 * This function searches the pring->postbufq list using the tag
8955 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
8956 * iocb. If the buffer is found then lpfc_dmabuf object of the
8957 * buffer is returned to the caller else NULL is returned.
8958 * This function is called with no lock held.
8960 struct lpfc_dmabuf
*
8961 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8964 struct lpfc_dmabuf
*mp
, *next_mp
;
8965 struct list_head
*slp
= &pring
->postbufq
;
8967 /* Search postbufq, from the beginning, looking for a match on tag */
8968 spin_lock_irq(&phba
->hbalock
);
8969 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
8970 if (mp
->buffer_tag
== tag
) {
8971 list_del_init(&mp
->list
);
8972 pring
->postbufq_cnt
--;
8973 spin_unlock_irq(&phba
->hbalock
);
8978 spin_unlock_irq(&phba
->hbalock
);
8979 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8980 "0402 Cannot find virtual addr for buffer tag on "
8981 "ring %d Data x%lx x%p x%p x%x\n",
8982 pring
->ringno
, (unsigned long) tag
,
8983 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
8989 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
8990 * @phba: Pointer to HBA context object.
8991 * @pring: Pointer to driver SLI ring object.
8992 * @phys: DMA address of the buffer.
8994 * This function searches the buffer list using the dma_address
8995 * of unsolicited event to find the driver's lpfc_dmabuf object
8996 * corresponding to the dma_address. The function returns the
8997 * lpfc_dmabuf object if a buffer is found else it returns NULL.
8998 * This function is called by the ct and els unsolicited event
8999 * handlers to get the buffer associated with the unsolicited
9002 * This function is called with no lock held.
9004 struct lpfc_dmabuf
*
9005 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9008 struct lpfc_dmabuf
*mp
, *next_mp
;
9009 struct list_head
*slp
= &pring
->postbufq
;
9011 /* Search postbufq, from the beginning, looking for a match on phys */
9012 spin_lock_irq(&phba
->hbalock
);
9013 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9014 if (mp
->phys
== phys
) {
9015 list_del_init(&mp
->list
);
9016 pring
->postbufq_cnt
--;
9017 spin_unlock_irq(&phba
->hbalock
);
9022 spin_unlock_irq(&phba
->hbalock
);
9023 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9024 "0410 Cannot find virtual addr for mapped buf on "
9025 "ring %d Data x%llx x%p x%p x%x\n",
9026 pring
->ringno
, (unsigned long long)phys
,
9027 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9032 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9033 * @phba: Pointer to HBA context object.
9034 * @cmdiocb: Pointer to driver command iocb object.
9035 * @rspiocb: Pointer to driver response iocb object.
9037 * This function is the completion handler for the abort iocbs for
9038 * ELS commands. This function is called from the ELS ring event
9039 * handler with no lock held. This function frees memory resources
9040 * associated with the abort iocb.
9043 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9044 struct lpfc_iocbq
*rspiocb
)
9046 IOCB_t
*irsp
= &rspiocb
->iocb
;
9047 uint16_t abort_iotag
, abort_context
;
9048 struct lpfc_iocbq
*abort_iocb
= NULL
;
9050 if (irsp
->ulpStatus
) {
9053 * Assume that the port already completed and returned, or
9054 * will return the iocb. Just Log the message.
9056 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9057 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9059 spin_lock_irq(&phba
->hbalock
);
9060 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9061 if (abort_iotag
!= 0 &&
9062 abort_iotag
<= phba
->sli
.last_iotag
)
9064 phba
->sli
.iocbq_lookup
[abort_iotag
];
9066 /* For sli4 the abort_tag is the XRI,
9067 * so the abort routine puts the iotag of the iocb
9068 * being aborted in the context field of the abort
9071 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9073 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9074 "0327 Cannot abort els iocb %p "
9075 "with tag %x context %x, abort status %x, "
9077 abort_iocb
, abort_iotag
, abort_context
,
9078 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9080 spin_unlock_irq(&phba
->hbalock
);
9082 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9087 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9088 * @phba: Pointer to HBA context object.
9089 * @cmdiocb: Pointer to driver command iocb object.
9090 * @rspiocb: Pointer to driver response iocb object.
9092 * The function is called from SLI ring event handler with no
9093 * lock held. This function is the completion handler for ELS commands
9094 * which are aborted. The function frees memory resources used for
9095 * the aborted ELS commands.
9098 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9099 struct lpfc_iocbq
*rspiocb
)
9101 IOCB_t
*irsp
= &rspiocb
->iocb
;
9103 /* ELS cmd tag <ulpIoTag> completes */
9104 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9105 "0139 Ignoring ELS cmd tag x%x completion Data: "
9107 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9108 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9109 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9110 lpfc_ct_free_iocb(phba
, cmdiocb
);
9112 lpfc_els_free_iocb(phba
, cmdiocb
);
9117 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9118 * @phba: Pointer to HBA context object.
9119 * @pring: Pointer to driver SLI ring object.
9120 * @cmdiocb: Pointer to driver command iocb object.
9122 * This function issues an abort iocb for the provided command iocb down to
9123 * the port. Other than the case the outstanding command iocb is an abort
9124 * request, this function issues abort out unconditionally. This function is
9125 * called with hbalock held. The function returns 0 when it fails due to
9126 * memory allocation failure or when the command iocb is an abort request.
9129 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9130 struct lpfc_iocbq
*cmdiocb
)
9132 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9133 struct lpfc_iocbq
*abtsiocbp
;
9134 IOCB_t
*icmd
= NULL
;
9135 IOCB_t
*iabt
= NULL
;
9139 * There are certain command types we don't want to abort. And we
9140 * don't want to abort commands that are already in the process of
9143 icmd
= &cmdiocb
->iocb
;
9144 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9145 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9146 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9149 /* issue ABTS for this IOCB based on iotag */
9150 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9151 if (abtsiocbp
== NULL
)
9154 /* This signals the response to set the correct status
9155 * before calling the completion handler
9157 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9159 iabt
= &abtsiocbp
->iocb
;
9160 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9161 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9162 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9163 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9164 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9167 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9169 iabt
->ulpClass
= icmd
->ulpClass
;
9171 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9172 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9173 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9174 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9176 if (phba
->link_state
>= LPFC_LINK_UP
)
9177 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9179 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9181 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9183 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9184 "0339 Abort xri x%x, original iotag x%x, "
9185 "abort cmd iotag x%x\n",
9186 iabt
->un
.acxri
.abortIoTag
,
9187 iabt
->un
.acxri
.abortContextTag
,
9189 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
, abtsiocbp
, 0);
9192 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9195 * Caller to this routine should check for IOCB_ERROR
9196 * and handle it properly. This routine no longer removes
9197 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9203 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9204 * @phba: Pointer to HBA context object.
9205 * @pring: Pointer to driver SLI ring object.
9206 * @cmdiocb: Pointer to driver command iocb object.
9208 * This function issues an abort iocb for the provided command iocb. In case
9209 * of unloading, the abort iocb will not be issued to commands on the ELS
9210 * ring. Instead, the callback function shall be changed to those commands
9211 * so that nothing happens when them finishes. This function is called with
9212 * hbalock held. The function returns 0 when the command iocb is an abort
9216 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9217 struct lpfc_iocbq
*cmdiocb
)
9219 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9220 int retval
= IOCB_ERROR
;
9221 IOCB_t
*icmd
= NULL
;
9224 * There are certain command types we don't want to abort. And we
9225 * don't want to abort commands that are already in the process of
9228 icmd
= &cmdiocb
->iocb
;
9229 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9230 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9231 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9235 * If we're unloading, don't abort iocb on the ELS ring, but change
9236 * the callback so that nothing happens when it finishes.
9238 if ((vport
->load_flag
& FC_UNLOADING
) &&
9239 (pring
->ringno
== LPFC_ELS_RING
)) {
9240 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9241 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9243 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9244 goto abort_iotag_exit
;
9247 /* Now, we try to issue the abort to the cmdiocb out */
9248 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9252 * Caller to this routine should check for IOCB_ERROR
9253 * and handle it properly. This routine no longer removes
9254 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9260 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9261 * @phba: Pointer to HBA context object.
9262 * @pring: Pointer to driver SLI ring object.
9264 * This function aborts all iocbs in the given ring and frees all the iocb
9265 * objects in txq. This function issues abort iocbs unconditionally for all
9266 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9267 * to complete before the return of this function. The caller is not required
9268 * to hold any locks.
9271 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9273 LIST_HEAD(completions
);
9274 struct lpfc_iocbq
*iocb
, *next_iocb
;
9276 if (pring
->ringno
== LPFC_ELS_RING
)
9277 lpfc_fabric_abort_hba(phba
);
9279 spin_lock_irq(&phba
->hbalock
);
9281 /* Take off all the iocbs on txq for cancelling */
9282 list_splice_init(&pring
->txq
, &completions
);
9285 /* Next issue ABTS for everything on the txcmplq */
9286 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9287 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9289 spin_unlock_irq(&phba
->hbalock
);
9291 /* Cancel all the IOCBs from the completions list */
9292 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9297 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9298 * @phba: pointer to lpfc HBA data structure.
9300 * This routine will abort all pending and outstanding iocbs to an HBA.
9303 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9305 struct lpfc_sli
*psli
= &phba
->sli
;
9306 struct lpfc_sli_ring
*pring
;
9309 for (i
= 0; i
< psli
->num_rings
; i
++) {
9310 pring
= &psli
->ring
[i
];
9311 lpfc_sli_iocb_ring_abort(phba
, pring
);
9316 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9317 * @iocbq: Pointer to driver iocb object.
9318 * @vport: Pointer to driver virtual port object.
9319 * @tgt_id: SCSI ID of the target.
9320 * @lun_id: LUN ID of the scsi device.
9321 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9323 * This function acts as an iocb filter for functions which abort or count
9324 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9325 * 0 if the filtering criteria is met for the given iocb and will return
9326 * 1 if the filtering criteria is not met.
9327 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9328 * given iocb is for the SCSI device specified by vport, tgt_id and
9330 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9331 * given iocb is for the SCSI target specified by vport and tgt_id
9333 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9334 * given iocb is for the SCSI host associated with the given vport.
9335 * This function is called with no locks held.
9338 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9339 uint16_t tgt_id
, uint64_t lun_id
,
9340 lpfc_ctx_cmd ctx_cmd
)
9342 struct lpfc_scsi_buf
*lpfc_cmd
;
9345 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9348 if (iocbq
->vport
!= vport
)
9351 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9353 if (lpfc_cmd
->pCmd
== NULL
)
9358 if ((lpfc_cmd
->rdata
->pnode
) &&
9359 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9360 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9364 if ((lpfc_cmd
->rdata
->pnode
) &&
9365 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9372 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9381 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9382 * @vport: Pointer to virtual port.
9383 * @tgt_id: SCSI ID of the target.
9384 * @lun_id: LUN ID of the scsi device.
9385 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9387 * This function returns number of FCP commands pending for the vport.
9388 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9389 * commands pending on the vport associated with SCSI device specified
9390 * by tgt_id and lun_id parameters.
9391 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9392 * commands pending on the vport associated with SCSI target specified
9393 * by tgt_id parameter.
9394 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9395 * commands pending on the vport.
9396 * This function returns the number of iocbs which satisfy the filter.
9397 * This function is called without any lock held.
9400 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9401 lpfc_ctx_cmd ctx_cmd
)
9403 struct lpfc_hba
*phba
= vport
->phba
;
9404 struct lpfc_iocbq
*iocbq
;
9407 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9408 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9410 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9419 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9420 * @phba: Pointer to HBA context object
9421 * @cmdiocb: Pointer to command iocb object.
9422 * @rspiocb: Pointer to response iocb object.
9424 * This function is called when an aborted FCP iocb completes. This
9425 * function is called by the ring event handler with no lock held.
9426 * This function frees the iocb.
9429 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9430 struct lpfc_iocbq
*rspiocb
)
9432 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9433 "3096 ABORT_XRI_CN completing on xri x%x "
9434 "original iotag x%x, abort cmd iotag x%x "
9435 "status 0x%x, reason 0x%x\n",
9436 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9437 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9438 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9439 rspiocb
->iocb
.un
.ulpWord
[4]);
9440 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9445 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9446 * @vport: Pointer to virtual port.
9447 * @pring: Pointer to driver SLI ring object.
9448 * @tgt_id: SCSI ID of the target.
9449 * @lun_id: LUN ID of the scsi device.
9450 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9452 * This function sends an abort command for every SCSI command
9453 * associated with the given virtual port pending on the ring
9454 * filtered by lpfc_sli_validate_fcp_iocb function.
9455 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9456 * FCP iocbs associated with lun specified by tgt_id and lun_id
9458 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9459 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9460 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9461 * FCP iocbs associated with virtual port.
9462 * This function returns number of iocbs it failed to abort.
9463 * This function is called with no locks held.
9466 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9467 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9469 struct lpfc_hba
*phba
= vport
->phba
;
9470 struct lpfc_iocbq
*iocbq
;
9471 struct lpfc_iocbq
*abtsiocb
;
9473 int errcnt
= 0, ret_val
= 0;
9476 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9477 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9479 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9483 /* issue ABTS for this IOCB based on iotag */
9484 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9485 if (abtsiocb
== NULL
) {
9491 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9492 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9493 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9494 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9496 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9497 abtsiocb
->iocb
.ulpLe
= 1;
9498 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9499 abtsiocb
->vport
= phba
->pport
;
9501 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9502 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9503 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9504 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9506 if (lpfc_is_link_up(phba
))
9507 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9509 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
9511 /* Setup callback routine and issue the command. */
9512 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
9513 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9515 if (ret_val
== IOCB_ERROR
) {
9516 lpfc_sli_release_iocbq(phba
, abtsiocb
);
9526 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9527 * @phba: Pointer to HBA context object.
9528 * @cmdiocbq: Pointer to command iocb.
9529 * @rspiocbq: Pointer to response iocb.
9531 * This function is the completion handler for iocbs issued using
9532 * lpfc_sli_issue_iocb_wait function. This function is called by the
9533 * ring event handler function without any lock held. This function
9534 * can be called from both worker thread context and interrupt
9535 * context. This function also can be called from other thread which
9536 * cleans up the SLI layer objects.
9537 * This function copy the contents of the response iocb to the
9538 * response iocb memory object provided by the caller of
9539 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9540 * sleeps for the iocb completion.
9543 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
9544 struct lpfc_iocbq
*cmdiocbq
,
9545 struct lpfc_iocbq
*rspiocbq
)
9547 wait_queue_head_t
*pdone_q
;
9548 unsigned long iflags
;
9549 struct lpfc_scsi_buf
*lpfc_cmd
;
9551 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9552 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
9553 if (cmdiocbq
->context2
&& rspiocbq
)
9554 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
9555 &rspiocbq
->iocb
, sizeof(IOCB_t
));
9557 /* Set the exchange busy flag for task management commands */
9558 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
9559 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
9560 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
9562 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
9565 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
9568 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9573 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9574 * @phba: Pointer to HBA context object..
9575 * @piocbq: Pointer to command iocb.
9576 * @flag: Flag to test.
9578 * This routine grabs the hbalock and then test the iocb_flag to
9579 * see if the passed in flag is set.
9582 * 0 if flag is not set.
9585 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
9586 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
9588 unsigned long iflags
;
9591 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9592 ret
= piocbq
->iocb_flag
& flag
;
9593 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9599 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9600 * @phba: Pointer to HBA context object..
9601 * @pring: Pointer to sli ring.
9602 * @piocb: Pointer to command iocb.
9603 * @prspiocbq: Pointer to response iocb.
9604 * @timeout: Timeout in number of seconds.
9606 * This function issues the iocb to firmware and waits for the
9607 * iocb to complete. If the iocb command is not
9608 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9609 * Caller should not free the iocb resources if this function
9610 * returns IOCB_TIMEDOUT.
9611 * The function waits for the iocb completion using an
9612 * non-interruptible wait.
9613 * This function will sleep while waiting for iocb completion.
9614 * So, this function should not be called from any context which
9615 * does not allow sleeping. Due to the same reason, this function
9616 * cannot be called with interrupt disabled.
9617 * This function assumes that the iocb completions occur while
9618 * this function sleep. So, this function cannot be called from
9619 * the thread which process iocb completion for this ring.
9620 * This function clears the iocb_flag of the iocb object before
9621 * issuing the iocb and the iocb completion handler sets this
9622 * flag and wakes this thread when the iocb completes.
9623 * The contents of the response iocb will be copied to prspiocbq
9624 * by the completion handler when the command completes.
9625 * This function returns IOCB_SUCCESS when success.
9626 * This function is called with no lock held.
9629 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
9630 uint32_t ring_number
,
9631 struct lpfc_iocbq
*piocb
,
9632 struct lpfc_iocbq
*prspiocbq
,
9635 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9636 long timeleft
, timeout_req
= 0;
9637 int retval
= IOCB_SUCCESS
;
9639 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9641 * If the caller has provided a response iocbq buffer, then context2
9642 * is NULL or its an error.
9645 if (piocb
->context2
)
9647 piocb
->context2
= prspiocbq
;
9650 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
9651 piocb
->context_un
.wait_queue
= &done_q
;
9652 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
9654 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9655 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9657 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
9658 writel(creg_val
, phba
->HCregaddr
);
9659 readl(phba
->HCregaddr
); /* flush */
9662 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
9664 if (retval
== IOCB_SUCCESS
) {
9665 timeout_req
= timeout
* HZ
;
9666 timeleft
= wait_event_timeout(done_q
,
9667 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
9670 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
9671 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9672 "0331 IOCB wake signaled\n");
9673 } else if (timeleft
== 0) {
9674 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9675 "0338 IOCB wait timeout error - no "
9676 "wake response Data x%x\n", timeout
);
9677 retval
= IOCB_TIMEDOUT
;
9679 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9680 "0330 IOCB wake NOT set, "
9682 timeout
, (timeleft
/ jiffies
));
9683 retval
= IOCB_TIMEDOUT
;
9685 } else if (retval
== IOCB_BUSY
) {
9686 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9687 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
9688 phba
->iocb_cnt
, pring
->txq_cnt
, pring
->txcmplq_cnt
);
9691 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9692 "0332 IOCB wait issue failed, Data x%x\n",
9694 retval
= IOCB_ERROR
;
9697 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9698 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9700 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
9701 writel(creg_val
, phba
->HCregaddr
);
9702 readl(phba
->HCregaddr
); /* flush */
9706 piocb
->context2
= NULL
;
9708 piocb
->context_un
.wait_queue
= NULL
;
9709 piocb
->iocb_cmpl
= NULL
;
9714 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
9715 * @phba: Pointer to HBA context object.
9716 * @pmboxq: Pointer to driver mailbox object.
9717 * @timeout: Timeout in number of seconds.
9719 * This function issues the mailbox to firmware and waits for the
9720 * mailbox command to complete. If the mailbox command is not
9721 * completed within timeout seconds, it returns MBX_TIMEOUT.
9722 * The function waits for the mailbox completion using an
9723 * interruptible wait. If the thread is woken up due to a
9724 * signal, MBX_TIMEOUT error is returned to the caller. Caller
9725 * should not free the mailbox resources, if this function returns
9727 * This function will sleep while waiting for mailbox completion.
9728 * So, this function should not be called from any context which
9729 * does not allow sleeping. Due to the same reason, this function
9730 * cannot be called with interrupt disabled.
9731 * This function assumes that the mailbox completion occurs while
9732 * this function sleep. So, this function cannot be called from
9733 * the worker thread which processes mailbox completion.
9734 * This function is called in the context of HBA management
9736 * This function returns MBX_SUCCESS when successful.
9737 * This function is called with no lock held.
9740 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
9743 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9747 /* The caller must leave context1 empty. */
9748 if (pmboxq
->context1
)
9749 return MBX_NOT_FINISHED
;
9751 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
9752 /* setup wake call as IOCB callback */
9753 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
9754 /* setup context field to pass wait_queue pointer to wake function */
9755 pmboxq
->context1
= &done_q
;
9757 /* now issue the command */
9758 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
9759 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
9760 wait_event_interruptible_timeout(done_q
,
9761 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
9764 spin_lock_irqsave(&phba
->hbalock
, flag
);
9765 pmboxq
->context1
= NULL
;
9767 * if LPFC_MBX_WAKE flag is set the mailbox is completed
9768 * else do not free the resources.
9770 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
9771 retval
= MBX_SUCCESS
;
9772 lpfc_sli4_swap_str(phba
, pmboxq
);
9774 retval
= MBX_TIMEOUT
;
9775 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
9777 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
9784 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
9785 * @phba: Pointer to HBA context.
9787 * This function is called to shutdown the driver's mailbox sub-system.
9788 * It first marks the mailbox sub-system is in a block state to prevent
9789 * the asynchronous mailbox command from issued off the pending mailbox
9790 * command queue. If the mailbox command sub-system shutdown is due to
9791 * HBA error conditions such as EEH or ERATT, this routine shall invoke
9792 * the mailbox sub-system flush routine to forcefully bring down the
9793 * mailbox sub-system. Otherwise, if it is due to normal condition (such
9794 * as with offline or HBA function reset), this routine will wait for the
9795 * outstanding mailbox command to complete before invoking the mailbox
9796 * sub-system flush routine to gracefully bring down mailbox sub-system.
9799 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
)
9801 struct lpfc_sli
*psli
= &phba
->sli
;
9802 unsigned long timeout
;
9804 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
9805 spin_lock_irq(&phba
->hbalock
);
9806 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
9807 spin_unlock_irq(&phba
->hbalock
);
9809 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
9810 spin_lock_irq(&phba
->hbalock
);
9811 /* Determine how long we might wait for the active mailbox
9812 * command to be gracefully completed by firmware.
9814 if (phba
->sli
.mbox_active
)
9815 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
9816 phba
->sli
.mbox_active
) *
9818 spin_unlock_irq(&phba
->hbalock
);
9820 while (phba
->sli
.mbox_active
) {
9821 /* Check active mailbox complete status every 2ms */
9823 if (time_after(jiffies
, timeout
))
9824 /* Timeout, let the mailbox flush routine to
9825 * forcefully release active mailbox command
9830 lpfc_sli_mbox_sys_flush(phba
);
9834 * lpfc_sli_eratt_read - read sli-3 error attention events
9835 * @phba: Pointer to HBA context.
9837 * This function is called to read the SLI3 device error attention registers
9838 * for possible error attention events. The caller must hold the hostlock
9839 * with spin_lock_irq().
9841 * This function returns 1 when there is Error Attention in the Host Attention
9842 * Register and returns 0 otherwise.
9845 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
9849 /* Read chip Host Attention (HA) register */
9850 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
9853 if (ha_copy
& HA_ERATT
) {
9854 /* Read host status register to retrieve error event */
9855 if (lpfc_sli_read_hs(phba
))
9858 /* Check if there is a deferred error condition is active */
9859 if ((HS_FFER1
& phba
->work_hs
) &&
9860 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
9861 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
9862 phba
->hba_flag
|= DEFER_ERATT
;
9863 /* Clear all interrupt enable conditions */
9864 writel(0, phba
->HCregaddr
);
9865 readl(phba
->HCregaddr
);
9868 /* Set the driver HA work bitmap */
9869 phba
->work_ha
|= HA_ERATT
;
9870 /* Indicate polling handles this ERATT */
9871 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9877 /* Set the driver HS work bitmap */
9878 phba
->work_hs
|= UNPLUG_ERR
;
9879 /* Set the driver HA work bitmap */
9880 phba
->work_ha
|= HA_ERATT
;
9881 /* Indicate polling handles this ERATT */
9882 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9887 * lpfc_sli4_eratt_read - read sli-4 error attention events
9888 * @phba: Pointer to HBA context.
9890 * This function is called to read the SLI4 device error attention registers
9891 * for possible error attention events. The caller must hold the hostlock
9892 * with spin_lock_irq().
9894 * This function returns 1 when there is Error Attention in the Host Attention
9895 * Register and returns 0 otherwise.
9898 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
9900 uint32_t uerr_sta_hi
, uerr_sta_lo
;
9901 uint32_t if_type
, portsmphr
;
9902 struct lpfc_register portstat_reg
;
9905 * For now, use the SLI4 device internal unrecoverable error
9906 * registers for error attention. This can be changed later.
9908 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
9910 case LPFC_SLI_INTF_IF_TYPE_0
:
9911 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
9913 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
9915 phba
->work_hs
|= UNPLUG_ERR
;
9916 phba
->work_ha
|= HA_ERATT
;
9917 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9920 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
9921 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
9922 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9923 "1423 HBA Unrecoverable error: "
9924 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
9925 "ue_mask_lo_reg=0x%x, "
9926 "ue_mask_hi_reg=0x%x\n",
9927 uerr_sta_lo
, uerr_sta_hi
,
9928 phba
->sli4_hba
.ue_mask_lo
,
9929 phba
->sli4_hba
.ue_mask_hi
);
9930 phba
->work_status
[0] = uerr_sta_lo
;
9931 phba
->work_status
[1] = uerr_sta_hi
;
9932 phba
->work_ha
|= HA_ERATT
;
9933 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9937 case LPFC_SLI_INTF_IF_TYPE_2
:
9938 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
9939 &portstat_reg
.word0
) ||
9940 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
9942 phba
->work_hs
|= UNPLUG_ERR
;
9943 phba
->work_ha
|= HA_ERATT
;
9944 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9947 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
9948 phba
->work_status
[0] =
9949 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
9950 phba
->work_status
[1] =
9951 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
9952 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9953 "2885 Port Status Event: "
9954 "port status reg 0x%x, "
9955 "port smphr reg 0x%x, "
9956 "error 1=0x%x, error 2=0x%x\n",
9959 phba
->work_status
[0],
9960 phba
->work_status
[1]);
9961 phba
->work_ha
|= HA_ERATT
;
9962 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
9966 case LPFC_SLI_INTF_IF_TYPE_1
:
9968 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9969 "2886 HBA Error Attention on unsupported "
9970 "if type %d.", if_type
);
9978 * lpfc_sli_check_eratt - check error attention events
9979 * @phba: Pointer to HBA context.
9981 * This function is called from timer soft interrupt context to check HBA's
9982 * error attention register bit for error attention events.
9984 * This function returns 1 when there is Error Attention in the Host Attention
9985 * Register and returns 0 otherwise.
9988 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
9992 /* If somebody is waiting to handle an eratt, don't process it
9993 * here. The brdkill function will do this.
9995 if (phba
->link_flag
& LS_IGNORE_ERATT
)
9998 /* Check if interrupt handler handles this ERATT */
9999 spin_lock_irq(&phba
->hbalock
);
10000 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10001 /* Interrupt handler has handled ERATT */
10002 spin_unlock_irq(&phba
->hbalock
);
10007 * If there is deferred error attention, do not check for error
10010 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10011 spin_unlock_irq(&phba
->hbalock
);
10015 /* If PCI channel is offline, don't process it */
10016 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10017 spin_unlock_irq(&phba
->hbalock
);
10021 switch (phba
->sli_rev
) {
10022 case LPFC_SLI_REV2
:
10023 case LPFC_SLI_REV3
:
10024 /* Read chip Host Attention (HA) register */
10025 ha_copy
= lpfc_sli_eratt_read(phba
);
10027 case LPFC_SLI_REV4
:
10028 /* Read device Uncoverable Error (UERR) registers */
10029 ha_copy
= lpfc_sli4_eratt_read(phba
);
10032 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10033 "0299 Invalid SLI revision (%d)\n",
10038 spin_unlock_irq(&phba
->hbalock
);
10044 * lpfc_intr_state_check - Check device state for interrupt handling
10045 * @phba: Pointer to HBA context.
10047 * This inline routine checks whether a device or its PCI slot is in a state
10048 * that the interrupt should be handled.
10050 * This function returns 0 if the device or the PCI slot is in a state that
10051 * interrupt should be handled, otherwise -EIO.
10054 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10056 /* If the pci channel is offline, ignore all the interrupts */
10057 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10060 /* Update device level interrupt statistics */
10061 phba
->sli
.slistat
.sli_intr
++;
10063 /* Ignore all interrupts during initialization. */
10064 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10071 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10072 * @irq: Interrupt number.
10073 * @dev_id: The device context pointer.
10075 * This function is directly called from the PCI layer as an interrupt
10076 * service routine when device with SLI-3 interface spec is enabled with
10077 * MSI-X multi-message interrupt mode and there are slow-path events in
10078 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10079 * interrupt mode, this function is called as part of the device-level
10080 * interrupt handler. When the PCI slot is in error recovery or the HBA
10081 * is undergoing initialization, the interrupt handler will not process
10082 * the interrupt. The link attention and ELS ring attention events are
10083 * handled by the worker thread. The interrupt handler signals the worker
10084 * thread and returns for these events. This function is called without
10085 * any lock held. It gets the hbalock to access and update SLI data
10088 * This function returns IRQ_HANDLED when interrupt is handled else it
10089 * returns IRQ_NONE.
10092 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10094 struct lpfc_hba
*phba
;
10095 uint32_t ha_copy
, hc_copy
;
10096 uint32_t work_ha_copy
;
10097 unsigned long status
;
10098 unsigned long iflag
;
10101 MAILBOX_t
*mbox
, *pmbox
;
10102 struct lpfc_vport
*vport
;
10103 struct lpfc_nodelist
*ndlp
;
10104 struct lpfc_dmabuf
*mp
;
10109 * Get the driver's phba structure from the dev_id and
10110 * assume the HBA is not interrupting.
10112 phba
= (struct lpfc_hba
*)dev_id
;
10114 if (unlikely(!phba
))
10118 * Stuff needs to be attented to when this function is invoked as an
10119 * individual interrupt handler in MSI-X multi-message interrupt mode
10121 if (phba
->intr_type
== MSIX
) {
10122 /* Check device state for handling interrupt */
10123 if (lpfc_intr_state_check(phba
))
10125 /* Need to read HA REG for slow-path events */
10126 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10127 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10129 /* If somebody is waiting to handle an eratt don't process it
10130 * here. The brdkill function will do this.
10132 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10133 ha_copy
&= ~HA_ERATT
;
10134 /* Check the need for handling ERATT in interrupt handler */
10135 if (ha_copy
& HA_ERATT
) {
10136 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10137 /* ERATT polling has handled ERATT */
10138 ha_copy
&= ~HA_ERATT
;
10140 /* Indicate interrupt handler handles ERATT */
10141 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10145 * If there is deferred error attention, do not check for any
10148 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10149 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10153 /* Clear up only attention source related to slow-path */
10154 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10157 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10158 HC_LAINT_ENA
| HC_ERINT_ENA
),
10160 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10162 writel(hc_copy
, phba
->HCregaddr
);
10163 readl(phba
->HAregaddr
); /* flush */
10164 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10166 ha_copy
= phba
->ha_copy
;
10168 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10170 if (work_ha_copy
) {
10171 if (work_ha_copy
& HA_LATT
) {
10172 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10174 * Turn off Link Attention interrupts
10175 * until CLEAR_LA done
10177 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10178 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10179 if (lpfc_readl(phba
->HCregaddr
, &control
))
10181 control
&= ~HC_LAINT_ENA
;
10182 writel(control
, phba
->HCregaddr
);
10183 readl(phba
->HCregaddr
); /* flush */
10184 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10187 work_ha_copy
&= ~HA_LATT
;
10190 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10192 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10193 * the only slow ring.
10195 status
= (work_ha_copy
&
10196 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10197 status
>>= (4*LPFC_ELS_RING
);
10198 if (status
& HA_RXMASK
) {
10199 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10200 if (lpfc_readl(phba
->HCregaddr
, &control
))
10203 lpfc_debugfs_slow_ring_trc(phba
,
10204 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10206 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10208 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10209 lpfc_debugfs_slow_ring_trc(phba
,
10210 "ISR Disable ring:"
10211 "pwork:x%x hawork:x%x wait:x%x",
10212 phba
->work_ha
, work_ha_copy
,
10213 (uint32_t)((unsigned long)
10214 &phba
->work_waitq
));
10217 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10218 writel(control
, phba
->HCregaddr
);
10219 readl(phba
->HCregaddr
); /* flush */
10222 lpfc_debugfs_slow_ring_trc(phba
,
10223 "ISR slow ring: pwork:"
10224 "x%x hawork:x%x wait:x%x",
10225 phba
->work_ha
, work_ha_copy
,
10226 (uint32_t)((unsigned long)
10227 &phba
->work_waitq
));
10229 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10232 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10233 if (work_ha_copy
& HA_ERATT
) {
10234 if (lpfc_sli_read_hs(phba
))
10237 * Check if there is a deferred error condition
10240 if ((HS_FFER1
& phba
->work_hs
) &&
10241 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10242 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10244 phba
->hba_flag
|= DEFER_ERATT
;
10245 /* Clear all interrupt enable conditions */
10246 writel(0, phba
->HCregaddr
);
10247 readl(phba
->HCregaddr
);
10251 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10252 pmb
= phba
->sli
.mbox_active
;
10253 pmbox
= &pmb
->u
.mb
;
10255 vport
= pmb
->vport
;
10257 /* First check out the status word */
10258 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10259 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10260 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10262 * Stray Mailbox Interrupt, mbxCommand <cmd>
10263 * mbxStatus <status>
10265 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10267 "(%d):0304 Stray Mailbox "
10268 "Interrupt mbxCommand x%x "
10270 (vport
? vport
->vpi
: 0),
10273 /* clear mailbox attention bit */
10274 work_ha_copy
&= ~HA_MBATT
;
10276 phba
->sli
.mbox_active
= NULL
;
10277 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10278 phba
->last_completion_time
= jiffies
;
10279 del_timer(&phba
->sli
.mbox_tmo
);
10280 if (pmb
->mbox_cmpl
) {
10281 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10283 if (pmb
->out_ext_byte_len
&&
10285 lpfc_sli_pcimem_bcopy(
10288 pmb
->out_ext_byte_len
);
10290 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10291 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10293 lpfc_debugfs_disc_trc(vport
,
10294 LPFC_DISC_TRC_MBOX_VPORT
,
10295 "MBOX dflt rpi: : "
10296 "status:x%x rpi:x%x",
10297 (uint32_t)pmbox
->mbxStatus
,
10298 pmbox
->un
.varWords
[0], 0);
10300 if (!pmbox
->mbxStatus
) {
10301 mp
= (struct lpfc_dmabuf
*)
10303 ndlp
= (struct lpfc_nodelist
*)
10306 /* Reg_LOGIN of dflt RPI was
10307 * successful. new lets get
10308 * rid of the RPI using the
10309 * same mbox buffer.
10311 lpfc_unreg_login(phba
,
10313 pmbox
->un
.varWords
[0],
10316 lpfc_mbx_cmpl_dflt_rpi
;
10317 pmb
->context1
= mp
;
10318 pmb
->context2
= ndlp
;
10319 pmb
->vport
= vport
;
10320 rc
= lpfc_sli_issue_mbox(phba
,
10323 if (rc
!= MBX_BUSY
)
10324 lpfc_printf_log(phba
,
10326 LOG_MBOX
| LOG_SLI
,
10327 "0350 rc should have"
10328 "been MBX_BUSY\n");
10329 if (rc
!= MBX_NOT_FINISHED
)
10330 goto send_current_mbox
;
10334 &phba
->pport
->work_port_lock
,
10336 phba
->pport
->work_port_events
&=
10338 spin_unlock_irqrestore(
10339 &phba
->pport
->work_port_lock
,
10341 lpfc_mbox_cmpl_put(phba
, pmb
);
10344 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10346 if ((work_ha_copy
& HA_MBATT
) &&
10347 (phba
->sli
.mbox_active
== NULL
)) {
10349 /* Process next mailbox command if there is one */
10351 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10353 } while (rc
== MBX_NOT_FINISHED
);
10354 if (rc
!= MBX_SUCCESS
)
10355 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10356 LOG_SLI
, "0349 rc should be "
10360 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10361 phba
->work_ha
|= work_ha_copy
;
10362 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10363 lpfc_worker_wake_up(phba
);
10365 return IRQ_HANDLED
;
10367 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10368 return IRQ_HANDLED
;
10370 } /* lpfc_sli_sp_intr_handler */
10373 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10374 * @irq: Interrupt number.
10375 * @dev_id: The device context pointer.
10377 * This function is directly called from the PCI layer as an interrupt
10378 * service routine when device with SLI-3 interface spec is enabled with
10379 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10380 * ring event in the HBA. However, when the device is enabled with either
10381 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10382 * device-level interrupt handler. When the PCI slot is in error recovery
10383 * or the HBA is undergoing initialization, the interrupt handler will not
10384 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10385 * the intrrupt context. This function is called without any lock held.
10386 * It gets the hbalock to access and update SLI data structures.
10388 * This function returns IRQ_HANDLED when interrupt is handled else it
10389 * returns IRQ_NONE.
10392 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10394 struct lpfc_hba
*phba
;
10396 unsigned long status
;
10397 unsigned long iflag
;
10399 /* Get the driver's phba structure from the dev_id and
10400 * assume the HBA is not interrupting.
10402 phba
= (struct lpfc_hba
*) dev_id
;
10404 if (unlikely(!phba
))
10408 * Stuff needs to be attented to when this function is invoked as an
10409 * individual interrupt handler in MSI-X multi-message interrupt mode
10411 if (phba
->intr_type
== MSIX
) {
10412 /* Check device state for handling interrupt */
10413 if (lpfc_intr_state_check(phba
))
10415 /* Need to read HA REG for FCP ring and other ring events */
10416 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10417 return IRQ_HANDLED
;
10418 /* Clear up only attention source related to fast-path */
10419 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10421 * If there is deferred error attention, do not check for
10424 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10425 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10428 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10430 readl(phba
->HAregaddr
); /* flush */
10431 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10433 ha_copy
= phba
->ha_copy
;
10436 * Process all events on FCP ring. Take the optimized path for FCP IO.
10438 ha_copy
&= ~(phba
->work_ha_mask
);
10440 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10441 status
>>= (4*LPFC_FCP_RING
);
10442 if (status
& HA_RXMASK
)
10443 lpfc_sli_handle_fast_ring_event(phba
,
10444 &phba
->sli
.ring
[LPFC_FCP_RING
],
10447 if (phba
->cfg_multi_ring_support
== 2) {
10449 * Process all events on extra ring. Take the optimized path
10450 * for extra ring IO.
10452 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10453 status
>>= (4*LPFC_EXTRA_RING
);
10454 if (status
& HA_RXMASK
) {
10455 lpfc_sli_handle_fast_ring_event(phba
,
10456 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
10460 return IRQ_HANDLED
;
10461 } /* lpfc_sli_fp_intr_handler */
10464 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10465 * @irq: Interrupt number.
10466 * @dev_id: The device context pointer.
10468 * This function is the HBA device-level interrupt handler to device with
10469 * SLI-3 interface spec, called from the PCI layer when either MSI or
10470 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10471 * requires driver attention. This function invokes the slow-path interrupt
10472 * attention handling function and fast-path interrupt attention handling
10473 * function in turn to process the relevant HBA attention events. This
10474 * function is called without any lock held. It gets the hbalock to access
10475 * and update SLI data structures.
10477 * This function returns IRQ_HANDLED when interrupt is handled, else it
10478 * returns IRQ_NONE.
10481 lpfc_sli_intr_handler(int irq
, void *dev_id
)
10483 struct lpfc_hba
*phba
;
10484 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10485 unsigned long status1
, status2
;
10489 * Get the driver's phba structure from the dev_id and
10490 * assume the HBA is not interrupting.
10492 phba
= (struct lpfc_hba
*) dev_id
;
10494 if (unlikely(!phba
))
10497 /* Check device state for handling interrupt */
10498 if (lpfc_intr_state_check(phba
))
10501 spin_lock(&phba
->hbalock
);
10502 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
10503 spin_unlock(&phba
->hbalock
);
10504 return IRQ_HANDLED
;
10507 if (unlikely(!phba
->ha_copy
)) {
10508 spin_unlock(&phba
->hbalock
);
10510 } else if (phba
->ha_copy
& HA_ERATT
) {
10511 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10512 /* ERATT polling has handled ERATT */
10513 phba
->ha_copy
&= ~HA_ERATT
;
10515 /* Indicate interrupt handler handles ERATT */
10516 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10520 * If there is deferred error attention, do not check for any interrupt.
10522 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10523 spin_unlock(&phba
->hbalock
);
10527 /* Clear attention sources except link and error attentions */
10528 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
10529 spin_unlock(&phba
->hbalock
);
10530 return IRQ_HANDLED
;
10532 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
10533 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
10535 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
10536 writel(hc_copy
, phba
->HCregaddr
);
10537 readl(phba
->HAregaddr
); /* flush */
10538 spin_unlock(&phba
->hbalock
);
10541 * Invokes slow-path host attention interrupt handling as appropriate.
10544 /* status of events with mailbox and link attention */
10545 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
10547 /* status of events with ELS ring */
10548 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10549 status2
>>= (4*LPFC_ELS_RING
);
10551 if (status1
|| (status2
& HA_RXMASK
))
10552 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
10554 sp_irq_rc
= IRQ_NONE
;
10557 * Invoke fast-path host attention interrupt handling as appropriate.
10560 /* status of events with FCP ring */
10561 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10562 status1
>>= (4*LPFC_FCP_RING
);
10564 /* status of events with extra ring */
10565 if (phba
->cfg_multi_ring_support
== 2) {
10566 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10567 status2
>>= (4*LPFC_EXTRA_RING
);
10571 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
10572 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
10574 fp_irq_rc
= IRQ_NONE
;
10576 /* Return device-level interrupt handling status */
10577 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
10578 } /* lpfc_sli_intr_handler */
10581 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10582 * @phba: pointer to lpfc hba data structure.
10584 * This routine is invoked by the worker thread to process all the pending
10585 * SLI4 FCP abort XRI events.
10587 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
10589 struct lpfc_cq_event
*cq_event
;
10591 /* First, declare the fcp xri abort event has been handled */
10592 spin_lock_irq(&phba
->hbalock
);
10593 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
10594 spin_unlock_irq(&phba
->hbalock
);
10595 /* Now, handle all the fcp xri abort events */
10596 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
10597 /* Get the first event from the head of the event queue */
10598 spin_lock_irq(&phba
->hbalock
);
10599 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10600 cq_event
, struct lpfc_cq_event
, list
);
10601 spin_unlock_irq(&phba
->hbalock
);
10602 /* Notify aborted XRI for FCP work queue */
10603 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10604 /* Free the event processed back to the free pool */
10605 lpfc_sli4_cq_event_release(phba
, cq_event
);
10610 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10611 * @phba: pointer to lpfc hba data structure.
10613 * This routine is invoked by the worker thread to process all the pending
10614 * SLI4 els abort xri events.
10616 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
10618 struct lpfc_cq_event
*cq_event
;
10620 /* First, declare the els xri abort event has been handled */
10621 spin_lock_irq(&phba
->hbalock
);
10622 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
10623 spin_unlock_irq(&phba
->hbalock
);
10624 /* Now, handle all the els xri abort events */
10625 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
10626 /* Get the first event from the head of the event queue */
10627 spin_lock_irq(&phba
->hbalock
);
10628 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10629 cq_event
, struct lpfc_cq_event
, list
);
10630 spin_unlock_irq(&phba
->hbalock
);
10631 /* Notify aborted XRI for ELS work queue */
10632 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10633 /* Free the event processed back to the free pool */
10634 lpfc_sli4_cq_event_release(phba
, cq_event
);
10639 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10640 * @phba: pointer to lpfc hba data structure
10641 * @pIocbIn: pointer to the rspiocbq
10642 * @pIocbOut: pointer to the cmdiocbq
10643 * @wcqe: pointer to the complete wcqe
10645 * This routine transfers the fields of a command iocbq to a response iocbq
10646 * by copying all the IOCB fields from command iocbq and transferring the
10647 * completion status information from the complete wcqe.
10650 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
10651 struct lpfc_iocbq
*pIocbIn
,
10652 struct lpfc_iocbq
*pIocbOut
,
10653 struct lpfc_wcqe_complete
*wcqe
)
10655 unsigned long iflags
;
10656 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
10658 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
10659 sizeof(struct lpfc_iocbq
) - offset
);
10660 /* Map WCQE parameters into irspiocb parameters */
10661 pIocbIn
->iocb
.ulpStatus
= bf_get(lpfc_wcqe_c_status
, wcqe
);
10662 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
10663 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
10664 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
10665 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
10666 wcqe
->total_data_placed
;
10668 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10670 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
10671 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
10674 /* Pick up HBA exchange busy condition */
10675 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
10676 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10677 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
10678 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10683 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
10684 * @phba: Pointer to HBA context object.
10685 * @wcqe: Pointer to work-queue completion queue entry.
10687 * This routine handles an ELS work-queue completion event and construct
10688 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
10689 * discovery engine to handle.
10691 * Return: Pointer to the receive IOCBQ, NULL otherwise.
10693 static struct lpfc_iocbq
*
10694 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
10695 struct lpfc_iocbq
*irspiocbq
)
10697 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10698 struct lpfc_iocbq
*cmdiocbq
;
10699 struct lpfc_wcqe_complete
*wcqe
;
10700 unsigned long iflags
;
10702 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
10703 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10704 pring
->stats
.iocb_event
++;
10705 /* Look up the ELS command IOCB and create pseudo response IOCB */
10706 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
10707 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
10708 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10710 if (unlikely(!cmdiocbq
)) {
10711 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10712 "0386 ELS complete with no corresponding "
10713 "cmdiocb: iotag (%d)\n",
10714 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
10715 lpfc_sli_release_iocbq(phba
, irspiocbq
);
10719 /* Fake the irspiocbq and copy necessary response information */
10720 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
10726 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
10727 * @phba: Pointer to HBA context object.
10728 * @cqe: Pointer to mailbox completion queue entry.
10730 * This routine process a mailbox completion queue entry with asynchrous
10733 * Return: true if work posted to worker thread, otherwise false.
10736 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
10738 struct lpfc_cq_event
*cq_event
;
10739 unsigned long iflags
;
10741 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10742 "0392 Async Event: word0:x%x, word1:x%x, "
10743 "word2:x%x, word3:x%x\n", mcqe
->word0
,
10744 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
10746 /* Allocate a new internal CQ_EVENT entry */
10747 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
10749 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10750 "0394 Failed to allocate CQ_EVENT entry\n");
10754 /* Move the CQE into an asynchronous event entry */
10755 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
10756 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10757 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
10758 /* Set the async event flag */
10759 phba
->hba_flag
|= ASYNC_EVENT
;
10760 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10766 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
10767 * @phba: Pointer to HBA context object.
10768 * @cqe: Pointer to mailbox completion queue entry.
10770 * This routine process a mailbox completion queue entry with mailbox
10771 * completion event.
10773 * Return: true if work posted to worker thread, otherwise false.
10776 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
10778 uint32_t mcqe_status
;
10779 MAILBOX_t
*mbox
, *pmbox
;
10780 struct lpfc_mqe
*mqe
;
10781 struct lpfc_vport
*vport
;
10782 struct lpfc_nodelist
*ndlp
;
10783 struct lpfc_dmabuf
*mp
;
10784 unsigned long iflags
;
10786 bool workposted
= false;
10789 /* If not a mailbox complete MCQE, out by checking mailbox consume */
10790 if (!bf_get(lpfc_trailer_completed
, mcqe
))
10791 goto out_no_mqe_complete
;
10793 /* Get the reference to the active mbox command */
10794 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10795 pmb
= phba
->sli
.mbox_active
;
10796 if (unlikely(!pmb
)) {
10797 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
10798 "1832 No pending MBOX command to handle\n");
10799 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10800 goto out_no_mqe_complete
;
10802 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10804 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
10806 vport
= pmb
->vport
;
10808 /* Reset heartbeat timer */
10809 phba
->last_completion_time
= jiffies
;
10810 del_timer(&phba
->sli
.mbox_tmo
);
10812 /* Move mbox data to caller's mailbox region, do endian swapping */
10813 if (pmb
->mbox_cmpl
&& mbox
)
10814 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
10817 * For mcqe errors, conditionally move a modified error code to
10818 * the mbox so that the error will not be missed.
10820 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
10821 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
10822 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
10823 bf_set(lpfc_mqe_status
, mqe
,
10824 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
10826 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10827 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10828 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
10829 "MBOX dflt rpi: status:x%x rpi:x%x",
10831 pmbox
->un
.varWords
[0], 0);
10832 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
10833 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
10834 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
10835 /* Reg_LOGIN of dflt RPI was successful. Now lets get
10836 * RID of the PPI using the same mbox buffer.
10838 lpfc_unreg_login(phba
, vport
->vpi
,
10839 pmbox
->un
.varWords
[0], pmb
);
10840 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
10841 pmb
->context1
= mp
;
10842 pmb
->context2
= ndlp
;
10843 pmb
->vport
= vport
;
10844 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
10845 if (rc
!= MBX_BUSY
)
10846 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10847 LOG_SLI
, "0385 rc should "
10848 "have been MBX_BUSY\n");
10849 if (rc
!= MBX_NOT_FINISHED
)
10850 goto send_current_mbox
;
10853 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
10854 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
10855 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
10857 /* There is mailbox completion work to do */
10858 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10859 __lpfc_mbox_cmpl_put(phba
, pmb
);
10860 phba
->work_ha
|= HA_MBATT
;
10861 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10865 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10866 /* Release the mailbox command posting token */
10867 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
10868 /* Setting active mailbox pointer need to be in sync to flag clear */
10869 phba
->sli
.mbox_active
= NULL
;
10870 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10871 /* Wake up worker thread to post the next pending mailbox command */
10872 lpfc_worker_wake_up(phba
);
10873 out_no_mqe_complete
:
10874 if (bf_get(lpfc_trailer_consumed
, mcqe
))
10875 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
10880 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
10881 * @phba: Pointer to HBA context object.
10882 * @cqe: Pointer to mailbox completion queue entry.
10884 * This routine process a mailbox completion queue entry, it invokes the
10885 * proper mailbox complete handling or asynchrous event handling routine
10886 * according to the MCQE's async bit.
10888 * Return: true if work posted to worker thread, otherwise false.
10891 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
10893 struct lpfc_mcqe mcqe
;
10896 /* Copy the mailbox MCQE and convert endian order as needed */
10897 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
10899 /* Invoke the proper event handling routine */
10900 if (!bf_get(lpfc_trailer_async
, &mcqe
))
10901 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
10903 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
10908 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
10909 * @phba: Pointer to HBA context object.
10910 * @wcqe: Pointer to work-queue completion queue entry.
10912 * This routine handles an ELS work-queue completion event.
10914 * Return: true if work posted to worker thread, otherwise false.
10917 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
,
10918 struct lpfc_wcqe_complete
*wcqe
)
10920 struct lpfc_iocbq
*irspiocbq
;
10921 unsigned long iflags
;
10922 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
10924 /* Get an irspiocbq for later ELS response processing use */
10925 irspiocbq
= lpfc_sli_get_iocbq(phba
);
10927 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10928 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
10929 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
10930 pring
->txq_cnt
, phba
->iocb_cnt
,
10931 phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
,
10932 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
);
10936 /* Save off the slow-path queue event for work thread to process */
10937 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
10938 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10939 list_add_tail(&irspiocbq
->cq_event
.list
,
10940 &phba
->sli4_hba
.sp_queue_event
);
10941 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
10942 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10948 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
10949 * @phba: Pointer to HBA context object.
10950 * @wcqe: Pointer to work-queue completion queue entry.
10952 * This routine handles slow-path WQ entry comsumed event by invoking the
10953 * proper WQ release routine to the slow-path WQ.
10956 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
10957 struct lpfc_wcqe_release
*wcqe
)
10959 /* sanity check on queue memory */
10960 if (unlikely(!phba
->sli4_hba
.els_wq
))
10962 /* Check for the slow-path ELS work queue */
10963 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
10964 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
10965 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
10967 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
10968 "2579 Slow-path wqe consume event carries "
10969 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
10970 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
10971 phba
->sli4_hba
.els_wq
->queue_id
);
10975 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
10976 * @phba: Pointer to HBA context object.
10977 * @cq: Pointer to a WQ completion queue.
10978 * @wcqe: Pointer to work-queue completion queue entry.
10980 * This routine handles an XRI abort event.
10982 * Return: true if work posted to worker thread, otherwise false.
10985 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
10986 struct lpfc_queue
*cq
,
10987 struct sli4_wcqe_xri_aborted
*wcqe
)
10989 bool workposted
= false;
10990 struct lpfc_cq_event
*cq_event
;
10991 unsigned long iflags
;
10993 /* Allocate a new internal CQ_EVENT entry */
10994 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
10996 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10997 "0602 Failed to allocate CQ_EVENT entry\n");
11001 /* Move the CQE into the proper xri abort event list */
11002 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11003 switch (cq
->subtype
) {
11005 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11006 list_add_tail(&cq_event
->list
,
11007 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11008 /* Set the fcp xri abort event flag */
11009 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11010 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11014 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11015 list_add_tail(&cq_event
->list
,
11016 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11017 /* Set the els xri abort event flag */
11018 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11019 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11023 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11024 "0603 Invalid work queue CQE subtype (x%x)\n",
11026 workposted
= false;
11033 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11034 * @phba: Pointer to HBA context object.
11035 * @rcqe: Pointer to receive-queue completion queue entry.
11037 * This routine process a receive-queue completion queue entry.
11039 * Return: true if work posted to worker thread, otherwise false.
11042 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11044 bool workposted
= false;
11045 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11046 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11047 struct hbq_dmabuf
*dma_buf
;
11048 uint32_t status
, rq_id
;
11049 unsigned long iflags
;
11051 /* sanity check on queue memory */
11052 if (unlikely(!hrq
) || unlikely(!drq
))
11055 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11056 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11058 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11059 if (rq_id
!= hrq
->queue_id
)
11062 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11064 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11065 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11066 "2537 Receive Frame Truncated!!\n");
11067 case FC_STATUS_RQ_SUCCESS
:
11068 lpfc_sli4_rq_release(hrq
, drq
);
11069 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11070 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11072 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11075 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11076 /* save off the frame for the word thread to process */
11077 list_add_tail(&dma_buf
->cq_event
.list
,
11078 &phba
->sli4_hba
.sp_queue_event
);
11079 /* Frame received */
11080 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11081 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11084 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11085 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11086 /* Post more buffers if possible */
11087 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11088 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11089 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11098 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11099 * @phba: Pointer to HBA context object.
11100 * @cq: Pointer to the completion queue.
11101 * @wcqe: Pointer to a completion queue entry.
11103 * This routine process a slow-path work-queue or receive queue completion queue
11106 * Return: true if work posted to worker thread, otherwise false.
11109 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11110 struct lpfc_cqe
*cqe
)
11112 struct lpfc_cqe cqevt
;
11113 bool workposted
= false;
11115 /* Copy the work queue CQE and convert endian order if needed */
11116 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11118 /* Check and process for different type of WCQE and dispatch */
11119 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11120 case CQE_CODE_COMPL_WQE
:
11121 /* Process the WQ/RQ complete event */
11122 phba
->last_completion_time
= jiffies
;
11123 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
,
11124 (struct lpfc_wcqe_complete
*)&cqevt
);
11126 case CQE_CODE_RELEASE_WQE
:
11127 /* Process the WQ release event */
11128 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11129 (struct lpfc_wcqe_release
*)&cqevt
);
11131 case CQE_CODE_XRI_ABORTED
:
11132 /* Process the WQ XRI abort event */
11133 phba
->last_completion_time
= jiffies
;
11134 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11135 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11137 case CQE_CODE_RECEIVE
:
11138 case CQE_CODE_RECEIVE_V1
:
11139 /* Process the RQ event */
11140 phba
->last_completion_time
= jiffies
;
11141 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11142 (struct lpfc_rcqe
*)&cqevt
);
11145 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11146 "0388 Not a valid WCQE code: x%x\n",
11147 bf_get(lpfc_cqe_code
, &cqevt
));
11154 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11155 * @phba: Pointer to HBA context object.
11156 * @eqe: Pointer to fast-path event queue entry.
11158 * This routine process a event queue entry from the slow-path event queue.
11159 * It will check the MajorCode and MinorCode to determine this is for a
11160 * completion event on a completion queue, if not, an error shall be logged
11161 * and just return. Otherwise, it will get to the corresponding completion
11162 * queue and process all the entries on that completion queue, rearm the
11163 * completion queue, and then return.
11167 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
11169 struct lpfc_queue
*cq
= NULL
, *childq
, *speq
;
11170 struct lpfc_cqe
*cqe
;
11171 bool workposted
= false;
11175 if (bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0) {
11176 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11177 "0359 Not a valid slow-path completion "
11178 "event: majorcode=x%x, minorcode=x%x\n",
11179 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11180 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11184 /* Get the reference to the corresponding CQ */
11185 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11187 /* Search for completion queue pointer matching this cqid */
11188 speq
= phba
->sli4_hba
.sp_eq
;
11189 /* sanity check on queue memory */
11190 if (unlikely(!speq
))
11192 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11193 if (childq
->queue_id
== cqid
) {
11198 if (unlikely(!cq
)) {
11199 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11200 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11201 "0365 Slow-path CQ identifier "
11202 "(%d) does not exist\n", cqid
);
11206 /* Process all the entries to the CQ */
11207 switch (cq
->type
) {
11209 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11210 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11211 if (!(++ecount
% cq
->entry_repost
))
11212 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11216 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11217 if (cq
->subtype
== LPFC_FCP
)
11218 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11221 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11223 if (!(++ecount
% cq
->entry_repost
))
11224 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11228 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11229 "0370 Invalid completion queue type (%d)\n",
11234 /* Catch the no cq entry condition, log an error */
11235 if (unlikely(ecount
== 0))
11236 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11237 "0371 No entry from the CQ: identifier "
11238 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11240 /* In any case, flash and re-arm the RCQ */
11241 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11243 /* wake up worker thread if there are works to be done */
11245 lpfc_worker_wake_up(phba
);
11249 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11250 * @eqe: Pointer to fast-path completion queue entry.
11252 * This routine process a fast-path work queue completion entry from fast-path
11253 * event queue for FCP command response completion.
11256 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
,
11257 struct lpfc_wcqe_complete
*wcqe
)
11259 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_FCP_RING
];
11260 struct lpfc_iocbq
*cmdiocbq
;
11261 struct lpfc_iocbq irspiocbq
;
11262 unsigned long iflags
;
11264 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11265 pring
->stats
.iocb_event
++;
11266 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11268 /* Check for response status */
11269 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11270 /* If resource errors reported from HBA, reduce queue
11271 * depth of the SCSI device.
11273 if ((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11274 IOSTAT_LOCAL_REJECT
) &&
11275 (wcqe
->parameter
== IOERR_NO_RESOURCES
)) {
11276 phba
->lpfc_rampdown_queue_depth(phba
);
11278 /* Log the error status */
11279 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11280 "0373 FCP complete error: status=x%x, "
11281 "hw_status=x%x, total_data_specified=%d, "
11282 "parameter=x%x, word3=x%x\n",
11283 bf_get(lpfc_wcqe_c_status
, wcqe
),
11284 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11285 wcqe
->total_data_placed
, wcqe
->parameter
,
11289 /* Look up the FCP command IOCB and create pseudo response IOCB */
11290 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11291 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11292 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11293 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11294 if (unlikely(!cmdiocbq
)) {
11295 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11296 "0374 FCP complete with no corresponding "
11297 "cmdiocb: iotag (%d)\n",
11298 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11301 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11302 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11303 "0375 FCP cmdiocb not callback function "
11305 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11309 /* Fake the irspiocb and copy necessary response information */
11310 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11312 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11313 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11314 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11315 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11318 /* Pass the cmd_iocb and the rsp state to the upper layer */
11319 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11323 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11324 * @phba: Pointer to HBA context object.
11325 * @cq: Pointer to completion queue.
11326 * @wcqe: Pointer to work-queue completion queue entry.
11328 * This routine handles an fast-path WQ entry comsumed event by invoking the
11329 * proper WQ release routine to the slow-path WQ.
11332 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11333 struct lpfc_wcqe_release
*wcqe
)
11335 struct lpfc_queue
*childwq
;
11336 bool wqid_matched
= false;
11339 /* Check for fast-path FCP work queue release */
11340 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11341 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11342 if (childwq
->queue_id
== fcp_wqid
) {
11343 lpfc_sli4_wq_release(childwq
,
11344 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11345 wqid_matched
= true;
11349 /* Report warning log message if no match found */
11350 if (wqid_matched
!= true)
11351 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11352 "2580 Fast-path wqe consume event carries "
11353 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11357 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11358 * @cq: Pointer to the completion queue.
11359 * @eqe: Pointer to fast-path completion queue entry.
11361 * This routine process a fast-path work queue completion entry from fast-path
11362 * event queue for FCP command response completion.
11365 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11366 struct lpfc_cqe
*cqe
)
11368 struct lpfc_wcqe_release wcqe
;
11369 bool workposted
= false;
11371 /* Copy the work queue CQE and convert endian order if needed */
11372 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
11374 /* Check and process for different type of WCQE and dispatch */
11375 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
11376 case CQE_CODE_COMPL_WQE
:
11377 /* Process the WQ complete event */
11378 phba
->last_completion_time
= jiffies
;
11379 lpfc_sli4_fp_handle_fcp_wcqe(phba
,
11380 (struct lpfc_wcqe_complete
*)&wcqe
);
11382 case CQE_CODE_RELEASE_WQE
:
11383 /* Process the WQ release event */
11384 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
11385 (struct lpfc_wcqe_release
*)&wcqe
);
11387 case CQE_CODE_XRI_ABORTED
:
11388 /* Process the WQ XRI abort event */
11389 phba
->last_completion_time
= jiffies
;
11390 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11391 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
11394 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11395 "0144 Not a valid WCQE code: x%x\n",
11396 bf_get(lpfc_wcqe_c_code
, &wcqe
));
11403 * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
11404 * @phba: Pointer to HBA context object.
11405 * @eqe: Pointer to fast-path event queue entry.
11407 * This routine process a event queue entry from the fast-path event queue.
11408 * It will check the MajorCode and MinorCode to determine this is for a
11409 * completion event on a completion queue, if not, an error shall be logged
11410 * and just return. Otherwise, it will get to the corresponding completion
11411 * queue and process all the entries on the completion queue, rearm the
11412 * completion queue, and then return.
11415 lpfc_sli4_fp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11416 uint32_t fcp_cqidx
)
11418 struct lpfc_queue
*cq
;
11419 struct lpfc_cqe
*cqe
;
11420 bool workposted
= false;
11424 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
11425 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11426 "0366 Not a valid fast-path completion "
11427 "event: majorcode=x%x, minorcode=x%x\n",
11428 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11429 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11433 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
11434 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11435 "3146 Fast-path completion queues "
11436 "does not exist\n");
11439 cq
= phba
->sli4_hba
.fcp_cq
[fcp_cqidx
];
11440 if (unlikely(!cq
)) {
11441 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11442 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11443 "0367 Fast-path completion queue "
11444 "(%d) does not exist\n", fcp_cqidx
);
11448 /* Get the reference to the corresponding CQ */
11449 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11450 if (unlikely(cqid
!= cq
->queue_id
)) {
11451 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11452 "0368 Miss-matched fast-path completion "
11453 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11454 cqid
, cq
->queue_id
);
11458 /* Process all the entries to the CQ */
11459 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11460 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
11461 if (!(++ecount
% cq
->entry_repost
))
11462 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11465 /* Catch the no cq entry condition */
11466 if (unlikely(ecount
== 0))
11467 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11468 "0369 No entry from fast-path completion "
11469 "queue fcpcqid=%d\n", cq
->queue_id
);
11471 /* In any case, flash and re-arm the CQ */
11472 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11474 /* wake up worker thread if there are works to be done */
11476 lpfc_worker_wake_up(phba
);
11480 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
11482 struct lpfc_eqe
*eqe
;
11484 /* walk all the EQ entries and drop on the floor */
11485 while ((eqe
= lpfc_sli4_eq_get(eq
)))
11488 /* Clear and re-arm the EQ */
11489 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
11493 * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
11494 * @irq: Interrupt number.
11495 * @dev_id: The device context pointer.
11497 * This function is directly called from the PCI layer as an interrupt
11498 * service routine when device with SLI-4 interface spec is enabled with
11499 * MSI-X multi-message interrupt mode and there are slow-path events in
11500 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11501 * interrupt mode, this function is called as part of the device-level
11502 * interrupt handler. When the PCI slot is in error recovery or the HBA is
11503 * undergoing initialization, the interrupt handler will not process the
11504 * interrupt. The link attention and ELS ring attention events are handled
11505 * by the worker thread. The interrupt handler signals the worker thread
11506 * and returns for these events. This function is called without any lock
11507 * held. It gets the hbalock to access and update SLI data structures.
11509 * This function returns IRQ_HANDLED when interrupt is handled else it
11510 * returns IRQ_NONE.
11513 lpfc_sli4_sp_intr_handler(int irq
, void *dev_id
)
11515 struct lpfc_hba
*phba
;
11516 struct lpfc_queue
*speq
;
11517 struct lpfc_eqe
*eqe
;
11518 unsigned long iflag
;
11522 * Get the driver's phba structure from the dev_id
11524 phba
= (struct lpfc_hba
*)dev_id
;
11526 if (unlikely(!phba
))
11529 /* Get to the EQ struct associated with this vector */
11530 speq
= phba
->sli4_hba
.sp_eq
;
11531 if (unlikely(!speq
))
11534 /* Check device state for handling interrupt */
11535 if (unlikely(lpfc_intr_state_check(phba
))) {
11536 /* Check again for link_state with lock held */
11537 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11538 if (phba
->link_state
< LPFC_LINK_DOWN
)
11539 /* Flush, clear interrupt, and rearm the EQ */
11540 lpfc_sli4_eq_flush(phba
, speq
);
11541 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11546 * Process all the event on FCP slow-path EQ
11548 while ((eqe
= lpfc_sli4_eq_get(speq
))) {
11549 lpfc_sli4_sp_handle_eqe(phba
, eqe
);
11550 if (!(++ecount
% speq
->entry_repost
))
11551 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_NOARM
);
11554 /* Always clear and re-arm the slow-path EQ */
11555 lpfc_sli4_eq_release(speq
, LPFC_QUEUE_REARM
);
11557 /* Catch the no cq entry condition */
11558 if (unlikely(ecount
== 0)) {
11559 if (phba
->intr_type
== MSIX
)
11560 /* MSI-X treated interrupt served as no EQ share INT */
11561 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11562 "0357 MSI-X interrupt with no EQE\n");
11564 /* Non MSI-X treated on interrupt as EQ share INT */
11568 return IRQ_HANDLED
;
11569 } /* lpfc_sli4_sp_intr_handler */
11572 * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
11573 * @irq: Interrupt number.
11574 * @dev_id: The device context pointer.
11576 * This function is directly called from the PCI layer as an interrupt
11577 * service routine when device with SLI-4 interface spec is enabled with
11578 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11579 * ring event in the HBA. However, when the device is enabled with either
11580 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11581 * device-level interrupt handler. When the PCI slot is in error recovery
11582 * or the HBA is undergoing initialization, the interrupt handler will not
11583 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11584 * the intrrupt context. This function is called without any lock held.
11585 * It gets the hbalock to access and update SLI data structures. Note that,
11586 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11587 * equal to that of FCP CQ index.
11589 * This function returns IRQ_HANDLED when interrupt is handled else it
11590 * returns IRQ_NONE.
11593 lpfc_sli4_fp_intr_handler(int irq
, void *dev_id
)
11595 struct lpfc_hba
*phba
;
11596 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
11597 struct lpfc_queue
*fpeq
;
11598 struct lpfc_eqe
*eqe
;
11599 unsigned long iflag
;
11601 uint32_t fcp_eqidx
;
11603 /* Get the driver's phba structure from the dev_id */
11604 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
11605 phba
= fcp_eq_hdl
->phba
;
11606 fcp_eqidx
= fcp_eq_hdl
->idx
;
11608 if (unlikely(!phba
))
11610 if (unlikely(!phba
->sli4_hba
.fp_eq
))
11613 /* Get to the EQ struct associated with this vector */
11614 fpeq
= phba
->sli4_hba
.fp_eq
[fcp_eqidx
];
11615 if (unlikely(!fpeq
))
11618 /* Check device state for handling interrupt */
11619 if (unlikely(lpfc_intr_state_check(phba
))) {
11620 /* Check again for link_state with lock held */
11621 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11622 if (phba
->link_state
< LPFC_LINK_DOWN
)
11623 /* Flush, clear interrupt, and rearm the EQ */
11624 lpfc_sli4_eq_flush(phba
, fpeq
);
11625 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11630 * Process all the event on FCP fast-path EQ
11632 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
11633 lpfc_sli4_fp_handle_eqe(phba
, eqe
, fcp_eqidx
);
11634 if (!(++ecount
% fpeq
->entry_repost
))
11635 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
11638 /* Always clear and re-arm the fast-path EQ */
11639 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
11641 if (unlikely(ecount
== 0)) {
11642 if (phba
->intr_type
== MSIX
)
11643 /* MSI-X treated interrupt served as no EQ share INT */
11644 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11645 "0358 MSI-X interrupt with no EQE\n");
11647 /* Non MSI-X treated on interrupt as EQ share INT */
11651 return IRQ_HANDLED
;
11652 } /* lpfc_sli4_fp_intr_handler */
11655 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
11656 * @irq: Interrupt number.
11657 * @dev_id: The device context pointer.
11659 * This function is the device-level interrupt handler to device with SLI-4
11660 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
11661 * interrupt mode is enabled and there is an event in the HBA which requires
11662 * driver attention. This function invokes the slow-path interrupt attention
11663 * handling function and fast-path interrupt attention handling function in
11664 * turn to process the relevant HBA attention events. This function is called
11665 * without any lock held. It gets the hbalock to access and update SLI data
11668 * This function returns IRQ_HANDLED when interrupt is handled, else it
11669 * returns IRQ_NONE.
11672 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
11674 struct lpfc_hba
*phba
;
11675 irqreturn_t sp_irq_rc
, fp_irq_rc
;
11676 bool fp_handled
= false;
11677 uint32_t fcp_eqidx
;
11679 /* Get the driver's phba structure from the dev_id */
11680 phba
= (struct lpfc_hba
*)dev_id
;
11682 if (unlikely(!phba
))
11686 * Invokes slow-path host attention interrupt handling as appropriate.
11688 sp_irq_rc
= lpfc_sli4_sp_intr_handler(irq
, dev_id
);
11691 * Invoke fast-path host attention interrupt handling as appropriate.
11693 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
11694 fp_irq_rc
= lpfc_sli4_fp_intr_handler(irq
,
11695 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
11696 if (fp_irq_rc
== IRQ_HANDLED
)
11697 fp_handled
|= true;
11700 return (fp_handled
== true) ? IRQ_HANDLED
: sp_irq_rc
;
11701 } /* lpfc_sli4_intr_handler */
11704 * lpfc_sli4_queue_free - free a queue structure and associated memory
11705 * @queue: The queue structure to free.
11707 * This function frees a queue structure and the DMAable memory used for
11708 * the host resident queue. This function must be called after destroying the
11709 * queue on the HBA.
11712 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
11714 struct lpfc_dmabuf
*dmabuf
;
11719 while (!list_empty(&queue
->page_list
)) {
11720 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
11722 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
11723 dmabuf
->virt
, dmabuf
->phys
);
11731 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
11732 * @phba: The HBA that this queue is being created on.
11733 * @entry_size: The size of each queue entry for this queue.
11734 * @entry count: The number of entries that this queue will handle.
11736 * This function allocates a queue structure and the DMAable memory used for
11737 * the host resident queue. This function must be called before creating the
11738 * queue on the HBA.
11740 struct lpfc_queue
*
11741 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
11742 uint32_t entry_count
)
11744 struct lpfc_queue
*queue
;
11745 struct lpfc_dmabuf
*dmabuf
;
11746 int x
, total_qe_count
;
11748 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11750 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11751 hw_page_size
= SLI4_PAGE_SIZE
;
11753 queue
= kzalloc(sizeof(struct lpfc_queue
) +
11754 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
11757 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
11758 hw_page_size
))/hw_page_size
;
11759 INIT_LIST_HEAD(&queue
->list
);
11760 INIT_LIST_HEAD(&queue
->page_list
);
11761 INIT_LIST_HEAD(&queue
->child_list
);
11762 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
11763 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
11766 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
11767 hw_page_size
, &dmabuf
->phys
,
11769 if (!dmabuf
->virt
) {
11773 memset(dmabuf
->virt
, 0, hw_page_size
);
11774 dmabuf
->buffer_tag
= x
;
11775 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
11776 /* initialize queue's entry array */
11777 dma_pointer
= dmabuf
->virt
;
11778 for (; total_qe_count
< entry_count
&&
11779 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
11780 total_qe_count
++, dma_pointer
+= entry_size
) {
11781 queue
->qe
[total_qe_count
].address
= dma_pointer
;
11784 queue
->entry_size
= entry_size
;
11785 queue
->entry_count
= entry_count
;
11788 * entry_repost is calculated based on the number of entries in the
11789 * queue. This works out except for RQs. If buffers are NOT initially
11790 * posted for every RQE, entry_repost should be adjusted accordingly.
11792 queue
->entry_repost
= (entry_count
>> 3);
11793 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
11794 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
11795 queue
->phba
= phba
;
11799 lpfc_sli4_queue_free(queue
);
11804 * lpfc_eq_create - Create an Event Queue on the HBA
11805 * @phba: HBA structure that indicates port to create a queue on.
11806 * @eq: The queue structure to use to create the event queue.
11807 * @imax: The maximum interrupt per second limit.
11809 * This function creates an event queue, as detailed in @eq, on a port,
11810 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
11812 * The @phba struct is used to send mailbox command to HBA. The @eq struct
11813 * is used to get the entry count and entry size that are necessary to
11814 * determine the number of pages to allocate and use for this queue. This
11815 * function will send the EQ_CREATE mailbox command to the HBA to setup the
11816 * event queue. This function is asynchronous and will wait for the mailbox
11817 * command to finish before continuing.
11819 * On success this function will return a zero. If unable to allocate enough
11820 * memory this function will return -ENOMEM. If the queue create mailbox command
11821 * fails this function will return -ENXIO.
11824 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint16_t imax
)
11826 struct lpfc_mbx_eq_create
*eq_create
;
11827 LPFC_MBOXQ_t
*mbox
;
11828 int rc
, length
, status
= 0;
11829 struct lpfc_dmabuf
*dmabuf
;
11830 uint32_t shdr_status
, shdr_add_status
;
11831 union lpfc_sli4_cfg_shdr
*shdr
;
11833 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11835 /* sanity check on queue memory */
11838 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11839 hw_page_size
= SLI4_PAGE_SIZE
;
11841 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11844 length
= (sizeof(struct lpfc_mbx_eq_create
) -
11845 sizeof(struct lpfc_sli4_cfg_mhdr
));
11846 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
11847 LPFC_MBOX_OPCODE_EQ_CREATE
,
11848 length
, LPFC_SLI4_MBX_EMBED
);
11849 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
11850 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
11852 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
11854 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
11855 /* Calculate delay multiper from maximum interrupt per second */
11856 dmult
= LPFC_DMULT_CONST
/imax
- 1;
11857 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
11859 switch (eq
->entry_count
) {
11861 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11862 "0360 Unsupported EQ count. (%d)\n",
11864 if (eq
->entry_count
< 256)
11866 /* otherwise default to smallest count (drop through) */
11868 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11872 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11876 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11880 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11884 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
11888 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
11889 memset(dmabuf
->virt
, 0, hw_page_size
);
11890 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
11891 putPaddrLow(dmabuf
->phys
);
11892 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
11893 putPaddrHigh(dmabuf
->phys
);
11895 mbox
->vport
= phba
->pport
;
11896 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11897 mbox
->context1
= NULL
;
11898 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
11899 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
11900 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
11901 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
11902 if (shdr_status
|| shdr_add_status
|| rc
) {
11903 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11904 "2500 EQ_CREATE mailbox failed with "
11905 "status x%x add_status x%x, mbx status x%x\n",
11906 shdr_status
, shdr_add_status
, rc
);
11909 eq
->type
= LPFC_EQ
;
11910 eq
->subtype
= LPFC_NONE
;
11911 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
11912 if (eq
->queue_id
== 0xFFFF)
11914 eq
->host_index
= 0;
11917 mempool_free(mbox
, phba
->mbox_mem_pool
);
11922 * lpfc_cq_create - Create a Completion Queue on the HBA
11923 * @phba: HBA structure that indicates port to create a queue on.
11924 * @cq: The queue structure to use to create the completion queue.
11925 * @eq: The event queue to bind this completion queue to.
11927 * This function creates a completion queue, as detailed in @wq, on a port,
11928 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
11930 * The @phba struct is used to send mailbox command to HBA. The @cq struct
11931 * is used to get the entry count and entry size that are necessary to
11932 * determine the number of pages to allocate and use for this queue. The @eq
11933 * is used to indicate which event queue to bind this completion queue to. This
11934 * function will send the CQ_CREATE mailbox command to the HBA to setup the
11935 * completion queue. This function is asynchronous and will wait for the mailbox
11936 * command to finish before continuing.
11938 * On success this function will return a zero. If unable to allocate enough
11939 * memory this function will return -ENOMEM. If the queue create mailbox command
11940 * fails this function will return -ENXIO.
11943 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11944 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
11946 struct lpfc_mbx_cq_create
*cq_create
;
11947 struct lpfc_dmabuf
*dmabuf
;
11948 LPFC_MBOXQ_t
*mbox
;
11949 int rc
, length
, status
= 0;
11950 uint32_t shdr_status
, shdr_add_status
;
11951 union lpfc_sli4_cfg_shdr
*shdr
;
11952 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
11954 /* sanity check on queue memory */
11957 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
11958 hw_page_size
= SLI4_PAGE_SIZE
;
11960 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11963 length
= (sizeof(struct lpfc_mbx_cq_create
) -
11964 sizeof(struct lpfc_sli4_cfg_mhdr
));
11965 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
11966 LPFC_MBOX_OPCODE_CQ_CREATE
,
11967 length
, LPFC_SLI4_MBX_EMBED
);
11968 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
11969 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
11970 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
11972 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
11973 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
11974 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
11975 phba
->sli4_hba
.pc_sli4_params
.cqv
);
11976 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
11977 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
11978 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
11979 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
11982 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
11985 switch (cq
->entry_count
) {
11987 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11988 "0361 Unsupported CQ count. (%d)\n",
11990 if (cq
->entry_count
< 256)
11992 /* otherwise default to smallest count (drop through) */
11994 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
11998 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12002 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12006 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12007 memset(dmabuf
->virt
, 0, hw_page_size
);
12008 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12009 putPaddrLow(dmabuf
->phys
);
12010 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12011 putPaddrHigh(dmabuf
->phys
);
12013 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12015 /* The IOCTL status is embedded in the mailbox subheader. */
12016 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12017 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12018 if (shdr_status
|| shdr_add_status
|| rc
) {
12019 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12020 "2501 CQ_CREATE mailbox failed with "
12021 "status x%x add_status x%x, mbx status x%x\n",
12022 shdr_status
, shdr_add_status
, rc
);
12026 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12027 if (cq
->queue_id
== 0xFFFF) {
12031 /* link the cq onto the parent eq child list */
12032 list_add_tail(&cq
->list
, &eq
->child_list
);
12033 /* Set up completion queue's type and subtype */
12035 cq
->subtype
= subtype
;
12036 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12037 cq
->assoc_qid
= eq
->queue_id
;
12038 cq
->host_index
= 0;
12042 mempool_free(mbox
, phba
->mbox_mem_pool
);
12047 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12048 * @phba: HBA structure that indicates port to create a queue on.
12049 * @mq: The queue structure to use to create the mailbox queue.
12050 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12051 * @cq: The completion queue to associate with this cq.
12053 * This function provides failback (fb) functionality when the
12054 * mq_create_ext fails on older FW generations. It's purpose is identical
12055 * to mq_create_ext otherwise.
12057 * This routine cannot fail as all attributes were previously accessed and
12058 * initialized in mq_create_ext.
12061 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12062 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12064 struct lpfc_mbx_mq_create
*mq_create
;
12065 struct lpfc_dmabuf
*dmabuf
;
12068 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12069 sizeof(struct lpfc_sli4_cfg_mhdr
));
12070 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12071 LPFC_MBOX_OPCODE_MQ_CREATE
,
12072 length
, LPFC_SLI4_MBX_EMBED
);
12073 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12074 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12076 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12078 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12079 switch (mq
->entry_count
) {
12081 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12082 LPFC_MQ_RING_SIZE_16
);
12085 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12086 LPFC_MQ_RING_SIZE_32
);
12089 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12090 LPFC_MQ_RING_SIZE_64
);
12093 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12094 LPFC_MQ_RING_SIZE_128
);
12097 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12098 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12099 putPaddrLow(dmabuf
->phys
);
12100 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12101 putPaddrHigh(dmabuf
->phys
);
12106 * lpfc_mq_create - Create a mailbox Queue on the HBA
12107 * @phba: HBA structure that indicates port to create a queue on.
12108 * @mq: The queue structure to use to create the mailbox queue.
12109 * @cq: The completion queue to associate with this cq.
12110 * @subtype: The queue's subtype.
12112 * This function creates a mailbox queue, as detailed in @mq, on a port,
12113 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12115 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12116 * is used to get the entry count and entry size that are necessary to
12117 * determine the number of pages to allocate and use for this queue. This
12118 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12119 * mailbox queue. This function is asynchronous and will wait for the mailbox
12120 * command to finish before continuing.
12122 * On success this function will return a zero. If unable to allocate enough
12123 * memory this function will return -ENOMEM. If the queue create mailbox command
12124 * fails this function will return -ENXIO.
12127 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12128 struct lpfc_queue
*cq
, uint32_t subtype
)
12130 struct lpfc_mbx_mq_create
*mq_create
;
12131 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12132 struct lpfc_dmabuf
*dmabuf
;
12133 LPFC_MBOXQ_t
*mbox
;
12134 int rc
, length
, status
= 0;
12135 uint32_t shdr_status
, shdr_add_status
;
12136 union lpfc_sli4_cfg_shdr
*shdr
;
12137 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12139 /* sanity check on queue memory */
12142 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12143 hw_page_size
= SLI4_PAGE_SIZE
;
12145 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12148 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12149 sizeof(struct lpfc_sli4_cfg_mhdr
));
12150 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12151 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12152 length
, LPFC_SLI4_MBX_EMBED
);
12154 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12155 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12156 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12157 &mq_create_ext
->u
.request
, mq
->page_count
);
12158 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12159 &mq_create_ext
->u
.request
, 1);
12160 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12161 &mq_create_ext
->u
.request
, 1);
12162 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12163 &mq_create_ext
->u
.request
, 1);
12164 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12165 &mq_create_ext
->u
.request
, 1);
12166 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12167 &mq_create_ext
->u
.request
, 1);
12168 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12169 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12170 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12171 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12172 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12175 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12177 switch (mq
->entry_count
) {
12179 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12180 "0362 Unsupported MQ count. (%d)\n",
12182 if (mq
->entry_count
< 16)
12184 /* otherwise default to smallest count (drop through) */
12186 bf_set(lpfc_mq_context_ring_size
,
12187 &mq_create_ext
->u
.request
.context
,
12188 LPFC_MQ_RING_SIZE_16
);
12191 bf_set(lpfc_mq_context_ring_size
,
12192 &mq_create_ext
->u
.request
.context
,
12193 LPFC_MQ_RING_SIZE_32
);
12196 bf_set(lpfc_mq_context_ring_size
,
12197 &mq_create_ext
->u
.request
.context
,
12198 LPFC_MQ_RING_SIZE_64
);
12201 bf_set(lpfc_mq_context_ring_size
,
12202 &mq_create_ext
->u
.request
.context
,
12203 LPFC_MQ_RING_SIZE_128
);
12206 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12207 memset(dmabuf
->virt
, 0, hw_page_size
);
12208 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12209 putPaddrLow(dmabuf
->phys
);
12210 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12211 putPaddrHigh(dmabuf
->phys
);
12213 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12214 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12215 &mq_create_ext
->u
.response
);
12216 if (rc
!= MBX_SUCCESS
) {
12217 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12218 "2795 MQ_CREATE_EXT failed with "
12219 "status x%x. Failback to MQ_CREATE.\n",
12221 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12222 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12223 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12224 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12225 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12226 &mq_create
->u
.response
);
12229 /* The IOCTL status is embedded in the mailbox subheader. */
12230 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12231 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12232 if (shdr_status
|| shdr_add_status
|| rc
) {
12233 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12234 "2502 MQ_CREATE mailbox failed with "
12235 "status x%x add_status x%x, mbx status x%x\n",
12236 shdr_status
, shdr_add_status
, rc
);
12240 if (mq
->queue_id
== 0xFFFF) {
12244 mq
->type
= LPFC_MQ
;
12245 mq
->assoc_qid
= cq
->queue_id
;
12246 mq
->subtype
= subtype
;
12247 mq
->host_index
= 0;
12250 /* link the mq onto the parent cq child list */
12251 list_add_tail(&mq
->list
, &cq
->child_list
);
12253 mempool_free(mbox
, phba
->mbox_mem_pool
);
12258 * lpfc_wq_create - Create a Work Queue on the HBA
12259 * @phba: HBA structure that indicates port to create a queue on.
12260 * @wq: The queue structure to use to create the work queue.
12261 * @cq: The completion queue to bind this work queue to.
12262 * @subtype: The subtype of the work queue indicating its functionality.
12264 * This function creates a work queue, as detailed in @wq, on a port, described
12265 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12267 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12268 * is used to get the entry count and entry size that are necessary to
12269 * determine the number of pages to allocate and use for this queue. The @cq
12270 * is used to indicate which completion queue to bind this work queue to. This
12271 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12272 * work queue. This function is asynchronous and will wait for the mailbox
12273 * command to finish before continuing.
12275 * On success this function will return a zero. If unable to allocate enough
12276 * memory this function will return -ENOMEM. If the queue create mailbox command
12277 * fails this function will return -ENXIO.
12280 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12281 struct lpfc_queue
*cq
, uint32_t subtype
)
12283 struct lpfc_mbx_wq_create
*wq_create
;
12284 struct lpfc_dmabuf
*dmabuf
;
12285 LPFC_MBOXQ_t
*mbox
;
12286 int rc
, length
, status
= 0;
12287 uint32_t shdr_status
, shdr_add_status
;
12288 union lpfc_sli4_cfg_shdr
*shdr
;
12289 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12290 struct dma_address
*page
;
12292 /* sanity check on queue memory */
12295 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12296 hw_page_size
= SLI4_PAGE_SIZE
;
12298 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12301 length
= (sizeof(struct lpfc_mbx_wq_create
) -
12302 sizeof(struct lpfc_sli4_cfg_mhdr
));
12303 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12304 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
12305 length
, LPFC_SLI4_MBX_EMBED
);
12306 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
12307 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
12308 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
12310 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
12312 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12313 phba
->sli4_hba
.pc_sli4_params
.wqv
);
12314 if (phba
->sli4_hba
.pc_sli4_params
.wqv
== LPFC_Q_CREATE_VERSION_1
) {
12315 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
12317 switch (wq
->entry_size
) {
12320 bf_set(lpfc_mbx_wq_create_wqe_size
,
12321 &wq_create
->u
.request_1
,
12322 LPFC_WQ_WQE_SIZE_64
);
12325 bf_set(lpfc_mbx_wq_create_wqe_size
,
12326 &wq_create
->u
.request_1
,
12327 LPFC_WQ_WQE_SIZE_128
);
12330 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
12331 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12332 page
= wq_create
->u
.request_1
.page
;
12334 page
= wq_create
->u
.request
.page
;
12336 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
12337 memset(dmabuf
->virt
, 0, hw_page_size
);
12338 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
12339 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
12341 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12342 /* The IOCTL status is embedded in the mailbox subheader. */
12343 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12344 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12345 if (shdr_status
|| shdr_add_status
|| rc
) {
12346 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12347 "2503 WQ_CREATE mailbox failed with "
12348 "status x%x add_status x%x, mbx status x%x\n",
12349 shdr_status
, shdr_add_status
, rc
);
12353 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
12354 if (wq
->queue_id
== 0xFFFF) {
12358 wq
->type
= LPFC_WQ
;
12359 wq
->assoc_qid
= cq
->queue_id
;
12360 wq
->subtype
= subtype
;
12361 wq
->host_index
= 0;
12363 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
12365 /* link the wq onto the parent cq child list */
12366 list_add_tail(&wq
->list
, &cq
->child_list
);
12368 mempool_free(mbox
, phba
->mbox_mem_pool
);
12373 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12374 * @phba: HBA structure that indicates port to create a queue on.
12375 * @rq: The queue structure to use for the receive queue.
12376 * @qno: The associated HBQ number
12379 * For SLI4 we need to adjust the RQ repost value based on
12380 * the number of buffers that are initially posted to the RQ.
12383 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
12387 /* sanity check on queue memory */
12390 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
12392 /* Recalc repost for RQs based on buffers initially posted */
12394 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
12395 cnt
= LPFC_QUEUE_MIN_REPOST
;
12397 rq
->entry_repost
= cnt
;
12401 * lpfc_rq_create - Create a Receive Queue on the HBA
12402 * @phba: HBA structure that indicates port to create a queue on.
12403 * @hrq: The queue structure to use to create the header receive queue.
12404 * @drq: The queue structure to use to create the data receive queue.
12405 * @cq: The completion queue to bind this work queue to.
12407 * This function creates a receive buffer queue pair , as detailed in @hrq and
12408 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12411 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12412 * struct is used to get the entry count that is necessary to determine the
12413 * number of pages to use for this queue. The @cq is used to indicate which
12414 * completion queue to bind received buffers that are posted to these queues to.
12415 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12416 * receive queue pair. This function is asynchronous and will wait for the
12417 * mailbox command to finish before continuing.
12419 * On success this function will return a zero. If unable to allocate enough
12420 * memory this function will return -ENOMEM. If the queue create mailbox command
12421 * fails this function will return -ENXIO.
12424 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12425 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
12427 struct lpfc_mbx_rq_create
*rq_create
;
12428 struct lpfc_dmabuf
*dmabuf
;
12429 LPFC_MBOXQ_t
*mbox
;
12430 int rc
, length
, status
= 0;
12431 uint32_t shdr_status
, shdr_add_status
;
12432 union lpfc_sli4_cfg_shdr
*shdr
;
12433 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12435 /* sanity check on queue memory */
12436 if (!hrq
|| !drq
|| !cq
)
12438 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12439 hw_page_size
= SLI4_PAGE_SIZE
;
12441 if (hrq
->entry_count
!= drq
->entry_count
)
12443 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12446 length
= (sizeof(struct lpfc_mbx_rq_create
) -
12447 sizeof(struct lpfc_sli4_cfg_mhdr
));
12448 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12449 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12450 length
, LPFC_SLI4_MBX_EMBED
);
12451 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
12452 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12453 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12454 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12455 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12456 bf_set(lpfc_rq_context_rqe_count_1
,
12457 &rq_create
->u
.request
.context
,
12459 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
12460 bf_set(lpfc_rq_context_rqe_size
,
12461 &rq_create
->u
.request
.context
,
12463 bf_set(lpfc_rq_context_page_size
,
12464 &rq_create
->u
.request
.context
,
12465 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12467 switch (hrq
->entry_count
) {
12469 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12470 "2535 Unsupported RQ count. (%d)\n",
12472 if (hrq
->entry_count
< 512)
12474 /* otherwise default to smallest count (drop through) */
12476 bf_set(lpfc_rq_context_rqe_count
,
12477 &rq_create
->u
.request
.context
,
12478 LPFC_RQ_RING_SIZE_512
);
12481 bf_set(lpfc_rq_context_rqe_count
,
12482 &rq_create
->u
.request
.context
,
12483 LPFC_RQ_RING_SIZE_1024
);
12486 bf_set(lpfc_rq_context_rqe_count
,
12487 &rq_create
->u
.request
.context
,
12488 LPFC_RQ_RING_SIZE_2048
);
12491 bf_set(lpfc_rq_context_rqe_count
,
12492 &rq_create
->u
.request
.context
,
12493 LPFC_RQ_RING_SIZE_4096
);
12496 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12497 LPFC_HDR_BUF_SIZE
);
12499 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12501 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12503 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
12504 memset(dmabuf
->virt
, 0, hw_page_size
);
12505 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12506 putPaddrLow(dmabuf
->phys
);
12507 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12508 putPaddrHigh(dmabuf
->phys
);
12510 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12511 /* The IOCTL status is embedded in the mailbox subheader. */
12512 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12513 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12514 if (shdr_status
|| shdr_add_status
|| rc
) {
12515 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12516 "2504 RQ_CREATE mailbox failed with "
12517 "status x%x add_status x%x, mbx status x%x\n",
12518 shdr_status
, shdr_add_status
, rc
);
12522 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12523 if (hrq
->queue_id
== 0xFFFF) {
12527 hrq
->type
= LPFC_HRQ
;
12528 hrq
->assoc_qid
= cq
->queue_id
;
12529 hrq
->subtype
= subtype
;
12530 hrq
->host_index
= 0;
12531 hrq
->hba_index
= 0;
12533 /* now create the data queue */
12534 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12535 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
12536 length
, LPFC_SLI4_MBX_EMBED
);
12537 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12538 phba
->sli4_hba
.pc_sli4_params
.rqv
);
12539 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
12540 bf_set(lpfc_rq_context_rqe_count_1
,
12541 &rq_create
->u
.request
.context
, hrq
->entry_count
);
12542 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
12543 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
12545 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
12546 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12548 switch (drq
->entry_count
) {
12550 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12551 "2536 Unsupported RQ count. (%d)\n",
12553 if (drq
->entry_count
< 512)
12555 /* otherwise default to smallest count (drop through) */
12557 bf_set(lpfc_rq_context_rqe_count
,
12558 &rq_create
->u
.request
.context
,
12559 LPFC_RQ_RING_SIZE_512
);
12562 bf_set(lpfc_rq_context_rqe_count
,
12563 &rq_create
->u
.request
.context
,
12564 LPFC_RQ_RING_SIZE_1024
);
12567 bf_set(lpfc_rq_context_rqe_count
,
12568 &rq_create
->u
.request
.context
,
12569 LPFC_RQ_RING_SIZE_2048
);
12572 bf_set(lpfc_rq_context_rqe_count
,
12573 &rq_create
->u
.request
.context
,
12574 LPFC_RQ_RING_SIZE_4096
);
12577 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
12578 LPFC_DATA_BUF_SIZE
);
12580 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
12582 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
12584 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
12585 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12586 putPaddrLow(dmabuf
->phys
);
12587 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12588 putPaddrHigh(dmabuf
->phys
);
12590 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12591 /* The IOCTL status is embedded in the mailbox subheader. */
12592 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
12593 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12594 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12595 if (shdr_status
|| shdr_add_status
|| rc
) {
12599 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
12600 if (drq
->queue_id
== 0xFFFF) {
12604 drq
->type
= LPFC_DRQ
;
12605 drq
->assoc_qid
= cq
->queue_id
;
12606 drq
->subtype
= subtype
;
12607 drq
->host_index
= 0;
12608 drq
->hba_index
= 0;
12610 /* link the header and data RQs onto the parent cq child list */
12611 list_add_tail(&hrq
->list
, &cq
->child_list
);
12612 list_add_tail(&drq
->list
, &cq
->child_list
);
12615 mempool_free(mbox
, phba
->mbox_mem_pool
);
12620 * lpfc_eq_destroy - Destroy an event Queue on the HBA
12621 * @eq: The queue structure associated with the queue to destroy.
12623 * This function destroys a queue, as detailed in @eq by sending an mailbox
12624 * command, specific to the type of queue, to the HBA.
12626 * The @eq struct is used to get the queue ID of the queue to destroy.
12628 * On success this function will return a zero. If the queue destroy mailbox
12629 * command fails this function will return -ENXIO.
12632 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12634 LPFC_MBOXQ_t
*mbox
;
12635 int rc
, length
, status
= 0;
12636 uint32_t shdr_status
, shdr_add_status
;
12637 union lpfc_sli4_cfg_shdr
*shdr
;
12639 /* sanity check on queue memory */
12642 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12645 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
12646 sizeof(struct lpfc_sli4_cfg_mhdr
));
12647 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12648 LPFC_MBOX_OPCODE_EQ_DESTROY
,
12649 length
, LPFC_SLI4_MBX_EMBED
);
12650 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
12652 mbox
->vport
= eq
->phba
->pport
;
12653 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12655 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
12656 /* The IOCTL status is embedded in the mailbox subheader. */
12657 shdr
= (union lpfc_sli4_cfg_shdr
*)
12658 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
12659 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12660 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12661 if (shdr_status
|| shdr_add_status
|| rc
) {
12662 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12663 "2505 EQ_DESTROY mailbox failed with "
12664 "status x%x add_status x%x, mbx status x%x\n",
12665 shdr_status
, shdr_add_status
, rc
);
12669 /* Remove eq from any list */
12670 list_del_init(&eq
->list
);
12671 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
12676 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
12677 * @cq: The queue structure associated with the queue to destroy.
12679 * This function destroys a queue, as detailed in @cq by sending an mailbox
12680 * command, specific to the type of queue, to the HBA.
12682 * The @cq struct is used to get the queue ID of the queue to destroy.
12684 * On success this function will return a zero. If the queue destroy mailbox
12685 * command fails this function will return -ENXIO.
12688 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
12690 LPFC_MBOXQ_t
*mbox
;
12691 int rc
, length
, status
= 0;
12692 uint32_t shdr_status
, shdr_add_status
;
12693 union lpfc_sli4_cfg_shdr
*shdr
;
12695 /* sanity check on queue memory */
12698 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12701 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
12702 sizeof(struct lpfc_sli4_cfg_mhdr
));
12703 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12704 LPFC_MBOX_OPCODE_CQ_DESTROY
,
12705 length
, LPFC_SLI4_MBX_EMBED
);
12706 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
12708 mbox
->vport
= cq
->phba
->pport
;
12709 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12710 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
12711 /* The IOCTL status is embedded in the mailbox subheader. */
12712 shdr
= (union lpfc_sli4_cfg_shdr
*)
12713 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
12714 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12715 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12716 if (shdr_status
|| shdr_add_status
|| rc
) {
12717 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12718 "2506 CQ_DESTROY mailbox failed with "
12719 "status x%x add_status x%x, mbx status x%x\n",
12720 shdr_status
, shdr_add_status
, rc
);
12723 /* Remove cq from any list */
12724 list_del_init(&cq
->list
);
12725 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
12730 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
12731 * @qm: The queue structure associated with the queue to destroy.
12733 * This function destroys a queue, as detailed in @mq by sending an mailbox
12734 * command, specific to the type of queue, to the HBA.
12736 * The @mq struct is used to get the queue ID of the queue to destroy.
12738 * On success this function will return a zero. If the queue destroy mailbox
12739 * command fails this function will return -ENXIO.
12742 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
12744 LPFC_MBOXQ_t
*mbox
;
12745 int rc
, length
, status
= 0;
12746 uint32_t shdr_status
, shdr_add_status
;
12747 union lpfc_sli4_cfg_shdr
*shdr
;
12749 /* sanity check on queue memory */
12752 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12755 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
12756 sizeof(struct lpfc_sli4_cfg_mhdr
));
12757 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12758 LPFC_MBOX_OPCODE_MQ_DESTROY
,
12759 length
, LPFC_SLI4_MBX_EMBED
);
12760 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
12762 mbox
->vport
= mq
->phba
->pport
;
12763 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12764 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
12765 /* The IOCTL status is embedded in the mailbox subheader. */
12766 shdr
= (union lpfc_sli4_cfg_shdr
*)
12767 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
12768 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12769 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12770 if (shdr_status
|| shdr_add_status
|| rc
) {
12771 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12772 "2507 MQ_DESTROY mailbox failed with "
12773 "status x%x add_status x%x, mbx status x%x\n",
12774 shdr_status
, shdr_add_status
, rc
);
12777 /* Remove mq from any list */
12778 list_del_init(&mq
->list
);
12779 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
12784 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
12785 * @wq: The queue structure associated with the queue to destroy.
12787 * This function destroys a queue, as detailed in @wq by sending an mailbox
12788 * command, specific to the type of queue, to the HBA.
12790 * The @wq struct is used to get the queue ID of the queue to destroy.
12792 * On success this function will return a zero. If the queue destroy mailbox
12793 * command fails this function will return -ENXIO.
12796 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
12798 LPFC_MBOXQ_t
*mbox
;
12799 int rc
, length
, status
= 0;
12800 uint32_t shdr_status
, shdr_add_status
;
12801 union lpfc_sli4_cfg_shdr
*shdr
;
12803 /* sanity check on queue memory */
12806 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12809 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
12810 sizeof(struct lpfc_sli4_cfg_mhdr
));
12811 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12812 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
12813 length
, LPFC_SLI4_MBX_EMBED
);
12814 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
12816 mbox
->vport
= wq
->phba
->pport
;
12817 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12818 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
12819 shdr
= (union lpfc_sli4_cfg_shdr
*)
12820 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
12821 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12822 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12823 if (shdr_status
|| shdr_add_status
|| rc
) {
12824 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12825 "2508 WQ_DESTROY mailbox failed with "
12826 "status x%x add_status x%x, mbx status x%x\n",
12827 shdr_status
, shdr_add_status
, rc
);
12830 /* Remove wq from any list */
12831 list_del_init(&wq
->list
);
12832 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
12837 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
12838 * @rq: The queue structure associated with the queue to destroy.
12840 * This function destroys a queue, as detailed in @rq by sending an mailbox
12841 * command, specific to the type of queue, to the HBA.
12843 * The @rq struct is used to get the queue ID of the queue to destroy.
12845 * On success this function will return a zero. If the queue destroy mailbox
12846 * command fails this function will return -ENXIO.
12849 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12850 struct lpfc_queue
*drq
)
12852 LPFC_MBOXQ_t
*mbox
;
12853 int rc
, length
, status
= 0;
12854 uint32_t shdr_status
, shdr_add_status
;
12855 union lpfc_sli4_cfg_shdr
*shdr
;
12857 /* sanity check on queue memory */
12860 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
12863 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
12864 sizeof(struct lpfc_sli4_cfg_mhdr
));
12865 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12866 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
12867 length
, LPFC_SLI4_MBX_EMBED
);
12868 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
12870 mbox
->vport
= hrq
->phba
->pport
;
12871 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12872 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
12873 /* The IOCTL status is embedded in the mailbox subheader. */
12874 shdr
= (union lpfc_sli4_cfg_shdr
*)
12875 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
12876 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12877 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12878 if (shdr_status
|| shdr_add_status
|| rc
) {
12879 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12880 "2509 RQ_DESTROY mailbox failed with "
12881 "status x%x add_status x%x, mbx status x%x\n",
12882 shdr_status
, shdr_add_status
, rc
);
12883 if (rc
!= MBX_TIMEOUT
)
12884 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
12887 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
12889 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
12890 shdr
= (union lpfc_sli4_cfg_shdr
*)
12891 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
12892 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12893 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12894 if (shdr_status
|| shdr_add_status
|| rc
) {
12895 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12896 "2510 RQ_DESTROY mailbox failed with "
12897 "status x%x add_status x%x, mbx status x%x\n",
12898 shdr_status
, shdr_add_status
, rc
);
12901 list_del_init(&hrq
->list
);
12902 list_del_init(&drq
->list
);
12903 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
12908 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
12909 * @phba: The virtual port for which this call being executed.
12910 * @pdma_phys_addr0: Physical address of the 1st SGL page.
12911 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
12912 * @xritag: the xritag that ties this io to the SGL pages.
12914 * This routine will post the sgl pages for the IO that has the xritag
12915 * that is in the iocbq structure. The xritag is assigned during iocbq
12916 * creation and persists for as long as the driver is loaded.
12917 * if the caller has fewer than 256 scatter gather segments to map then
12918 * pdma_phys_addr1 should be 0.
12919 * If the caller needs to map more than 256 scatter gather segment then
12920 * pdma_phys_addr1 should be a valid physical address.
12921 * physical address for SGLs must be 64 byte aligned.
12922 * If you are going to map 2 SGL's then the first one must have 256 entries
12923 * the second sgl can have between 1 and 256 entries.
12927 * -ENXIO, -ENOMEM - Failure
12930 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
12931 dma_addr_t pdma_phys_addr0
,
12932 dma_addr_t pdma_phys_addr1
,
12935 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
12936 LPFC_MBOXQ_t
*mbox
;
12938 uint32_t shdr_status
, shdr_add_status
;
12940 union lpfc_sli4_cfg_shdr
*shdr
;
12942 if (xritag
== NO_XRI
) {
12943 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12944 "0364 Invalid param:\n");
12948 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12952 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12953 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
12954 sizeof(struct lpfc_mbx_post_sgl_pages
) -
12955 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
12957 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
12958 &mbox
->u
.mqe
.un
.post_sgl_pages
;
12959 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
12960 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
12962 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
12963 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
12964 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
12965 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
12967 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
12968 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
12969 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
12970 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
12971 if (!phba
->sli4_hba
.intr_enable
)
12972 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12974 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
12975 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
12977 /* The IOCTL status is embedded in the mailbox subheader. */
12978 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
12979 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12980 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12981 if (rc
!= MBX_TIMEOUT
)
12982 mempool_free(mbox
, phba
->mbox_mem_pool
);
12983 if (shdr_status
|| shdr_add_status
|| rc
) {
12984 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12985 "2511 POST_SGL mailbox failed with "
12986 "status x%x add_status x%x, mbx status x%x\n",
12987 shdr_status
, shdr_add_status
, rc
);
12994 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
12995 * @phba: pointer to lpfc hba data structure.
12997 * This routine is invoked to post rpi header templates to the
12998 * HBA consistent with the SLI-4 interface spec. This routine
12999 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13000 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13003 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13004 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13007 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13012 * Fetch the next logical xri. Because this index is logical,
13013 * the driver starts at 0 each time.
13015 spin_lock_irq(&phba
->hbalock
);
13016 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13017 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13018 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13019 spin_unlock_irq(&phba
->hbalock
);
13022 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13023 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13024 phba
->sli4_hba
.xri_count
++;
13027 spin_unlock_irq(&phba
->hbalock
);
13032 * lpfc_sli4_free_xri - Release an xri for reuse.
13033 * @phba: pointer to lpfc hba data structure.
13035 * This routine is invoked to release an xri to the pool of
13036 * available rpis maintained by the driver.
13039 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13041 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13042 phba
->sli4_hba
.xri_count
--;
13043 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13048 * lpfc_sli4_free_xri - Release an xri for reuse.
13049 * @phba: pointer to lpfc hba data structure.
13051 * This routine is invoked to release an xri to the pool of
13052 * available rpis maintained by the driver.
13055 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13057 spin_lock_irq(&phba
->hbalock
);
13058 __lpfc_sli4_free_xri(phba
, xri
);
13059 spin_unlock_irq(&phba
->hbalock
);
13063 * lpfc_sli4_next_xritag - Get an xritag for the io
13064 * @phba: Pointer to HBA context object.
13066 * This function gets an xritag for the iocb. If there is no unused xritag
13067 * it will return 0xffff.
13068 * The function returns the allocated xritag if successful, else returns zero.
13069 * Zero is not a valid xritag.
13070 * The caller is not required to hold any lock.
13073 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13075 uint16_t xri_index
;
13077 xri_index
= lpfc_sli4_alloc_xri(phba
);
13078 if (xri_index
!= NO_XRI
)
13081 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13082 "2004 Failed to allocate XRI.last XRITAG is %d"
13083 " Max XRI is %d, Used XRI is %d\n",
13085 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13086 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13091 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13092 * @phba: pointer to lpfc hba data structure.
13094 * This routine is invoked to post a block of driver's sgl pages to the
13095 * HBA using non-embedded mailbox command. No Lock is held. This routine
13096 * is only called when the driver is loading and after all IO has been
13100 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
)
13102 struct lpfc_sglq
*sglq_entry
;
13103 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13104 struct sgl_page_pairs
*sgl_pg_pairs
;
13106 LPFC_MBOXQ_t
*mbox
;
13107 uint32_t reqlen
, alloclen
, pg_pairs
;
13109 uint16_t xritag_start
= 0, lxri
= 0;
13110 int els_xri_cnt
, rc
= 0;
13111 uint32_t shdr_status
, shdr_add_status
;
13112 union lpfc_sli4_cfg_shdr
*shdr
;
13114 /* The number of sgls to be posted */
13115 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
13117 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13118 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13119 if (reqlen
> SLI4_PAGE_SIZE
) {
13120 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13121 "2559 Block sgl registration required DMA "
13122 "size (%d) great than a page\n", reqlen
);
13125 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13129 /* Allocate DMA memory and set up the non-embedded mailbox command */
13130 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13131 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13132 LPFC_SLI4_MBX_NEMBED
);
13134 if (alloclen
< reqlen
) {
13135 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13136 "0285 Allocated DMA memory size (%d) is "
13137 "less than the requested DMA memory "
13138 "size (%d)\n", alloclen
, reqlen
);
13139 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13142 /* Set up the SGL pages in the non-embedded DMA pages */
13143 viraddr
= mbox
->sge_array
->addr
[0];
13144 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13145 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13147 for (pg_pairs
= 0; pg_pairs
< els_xri_cnt
; pg_pairs
++) {
13148 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[pg_pairs
];
13151 * Assign the sglq a physical xri only if the driver has not
13152 * initialized those resources. A port reset only needs
13153 * the sglq's posted.
13155 if (bf_get(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
13156 LPFC_XRI_RSRC_RDY
) {
13157 lxri
= lpfc_sli4_next_xritag(phba
);
13158 if (lxri
== NO_XRI
) {
13159 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13162 sglq_entry
->sli4_lxritag
= lxri
;
13163 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
13166 /* Set up the sge entry */
13167 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13168 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13169 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13170 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13171 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13172 cpu_to_le32(putPaddrLow(0));
13173 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13174 cpu_to_le32(putPaddrHigh(0));
13176 /* Keep the first xritag on the list */
13178 xritag_start
= sglq_entry
->sli4_xritag
;
13182 /* Complete initialization and perform endian conversion. */
13183 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13184 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, els_xri_cnt
);
13185 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13186 if (!phba
->sli4_hba
.intr_enable
)
13187 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13189 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13190 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13192 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13193 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13194 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13195 if (rc
!= MBX_TIMEOUT
)
13196 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13197 if (shdr_status
|| shdr_add_status
|| rc
) {
13198 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13199 "2513 POST_SGL_BLOCK mailbox command failed "
13200 "status x%x add_status x%x mbx status x%x\n",
13201 shdr_status
, shdr_add_status
, rc
);
13206 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
13207 LPFC_XRI_RSRC_RDY
);
13212 * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port.
13213 * @phba: pointer to lpfc hba data structure.
13215 * This routine is invoked to post a block of driver's sgl pages to the
13216 * HBA using non-embedded mailbox command. No Lock is held. This routine
13217 * is only called when the driver is loading and after all IO has been
13221 lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba
*phba
)
13223 struct lpfc_sglq
*sglq_entry
;
13224 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13225 struct sgl_page_pairs
*sgl_pg_pairs
;
13227 LPFC_MBOXQ_t
*mbox
;
13228 uint32_t reqlen
, alloclen
, index
;
13230 uint16_t rsrc_start
, rsrc_size
, els_xri_cnt
;
13231 uint16_t xritag_start
= 0, lxri
= 0;
13232 struct lpfc_rsrc_blks
*rsrc_blk
;
13233 int cnt
, ttl_cnt
, rc
= 0;
13235 uint32_t shdr_status
, shdr_add_status
;
13236 union lpfc_sli4_cfg_shdr
*shdr
;
13238 /* The number of sgls to be posted */
13239 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
13241 reqlen
= els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13242 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13243 if (reqlen
> SLI4_PAGE_SIZE
) {
13244 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13245 "2989 Block sgl registration required DMA "
13246 "size (%d) great than a page\n", reqlen
);
13252 list_for_each_entry(rsrc_blk
, &phba
->sli4_hba
.lpfc_xri_blk_list
,
13254 rsrc_start
= rsrc_blk
->rsrc_start
;
13255 rsrc_size
= rsrc_blk
->rsrc_size
;
13257 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13258 "3014 Working ELS Extent start %d, cnt %d\n",
13259 rsrc_start
, rsrc_size
);
13261 loop_cnt
= min(els_xri_cnt
, rsrc_size
);
13262 if (ttl_cnt
+ loop_cnt
>= els_xri_cnt
) {
13263 loop_cnt
= els_xri_cnt
- ttl_cnt
;
13264 ttl_cnt
= els_xri_cnt
;
13267 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13271 * Allocate DMA memory and set up the non-embedded mailbox
13274 alloclen
= lpfc_sli4_config(phba
, mbox
,
13275 LPFC_MBOX_SUBSYSTEM_FCOE
,
13276 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13277 reqlen
, LPFC_SLI4_MBX_NEMBED
);
13278 if (alloclen
< reqlen
) {
13279 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13280 "2987 Allocated DMA memory size (%d) "
13281 "is less than the requested DMA memory "
13282 "size (%d)\n", alloclen
, reqlen
);
13283 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13287 /* Set up the SGL pages in the non-embedded DMA pages */
13288 viraddr
= mbox
->sge_array
->addr
[0];
13289 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13290 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13293 * The starting resource may not begin at zero. Control
13294 * the loop variants via the block resource parameters,
13295 * but handle the sge pointers with a zero-based index
13296 * that doesn't get reset per loop pass.
13298 for (index
= rsrc_start
;
13299 index
< rsrc_start
+ loop_cnt
;
13301 sglq_entry
= phba
->sli4_hba
.lpfc_els_sgl_array
[cnt
];
13304 * Assign the sglq a physical xri only if the driver
13305 * has not initialized those resources. A port reset
13306 * only needs the sglq's posted.
13308 if (bf_get(lpfc_xri_rsrc_rdy
,
13309 &phba
->sli4_hba
.sli4_flags
) !=
13310 LPFC_XRI_RSRC_RDY
) {
13311 lxri
= lpfc_sli4_next_xritag(phba
);
13312 if (lxri
== NO_XRI
) {
13313 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13317 sglq_entry
->sli4_lxritag
= lxri
;
13318 sglq_entry
->sli4_xritag
=
13319 phba
->sli4_hba
.xri_ids
[lxri
];
13322 /* Set up the sge entry */
13323 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13324 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13325 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13326 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13327 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13328 cpu_to_le32(putPaddrLow(0));
13329 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13330 cpu_to_le32(putPaddrHigh(0));
13332 /* Track the starting physical XRI for the mailbox. */
13333 if (index
== rsrc_start
)
13334 xritag_start
= sglq_entry
->sli4_xritag
;
13339 /* Complete initialization and perform endian conversion. */
13340 rsrc_blk
->rsrc_used
+= loop_cnt
;
13341 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13342 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, loop_cnt
);
13343 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13345 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13346 "3015 Post ELS Extent SGL, start %d, "
13347 "cnt %d, used %d\n",
13348 xritag_start
, loop_cnt
, rsrc_blk
->rsrc_used
);
13349 if (!phba
->sli4_hba
.intr_enable
)
13350 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13352 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13353 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13355 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13356 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
13358 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
13360 if (rc
!= MBX_TIMEOUT
)
13361 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13362 if (shdr_status
|| shdr_add_status
|| rc
) {
13363 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13364 "2988 POST_SGL_BLOCK mailbox "
13365 "command failed status x%x "
13366 "add_status x%x mbx status x%x\n",
13367 shdr_status
, shdr_add_status
, rc
);
13371 if (ttl_cnt
>= els_xri_cnt
)
13377 bf_set(lpfc_xri_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
13378 LPFC_XRI_RSRC_RDY
);
13383 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13384 * @phba: pointer to lpfc hba data structure.
13385 * @sblist: pointer to scsi buffer list.
13386 * @count: number of scsi buffers on the list.
13388 * This routine is invoked to post a block of @count scsi sgl pages from a
13389 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13394 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
, struct list_head
*sblist
,
13397 struct lpfc_scsi_buf
*psb
;
13398 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13399 struct sgl_page_pairs
*sgl_pg_pairs
;
13401 LPFC_MBOXQ_t
*mbox
;
13402 uint32_t reqlen
, alloclen
, pg_pairs
;
13404 uint16_t xritag_start
= 0;
13406 uint32_t shdr_status
, shdr_add_status
;
13407 dma_addr_t pdma_phys_bpl1
;
13408 union lpfc_sli4_cfg_shdr
*shdr
;
13410 /* Calculate the requested length of the dma memory */
13411 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
13412 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13413 if (reqlen
> SLI4_PAGE_SIZE
) {
13414 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13415 "0217 Block sgl registration required DMA "
13416 "size (%d) great than a page\n", reqlen
);
13419 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13421 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13422 "0283 Failed to allocate mbox cmd memory\n");
13426 /* Allocate DMA memory and set up the non-embedded mailbox command */
13427 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13428 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13429 LPFC_SLI4_MBX_NEMBED
);
13431 if (alloclen
< reqlen
) {
13432 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13433 "2561 Allocated DMA memory size (%d) is "
13434 "less than the requested DMA memory "
13435 "size (%d)\n", alloclen
, reqlen
);
13436 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13440 /* Get the first SGE entry from the non-embedded DMA memory */
13441 viraddr
= mbox
->sge_array
->addr
[0];
13443 /* Set up the SGL pages in the non-embedded DMA pages */
13444 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13445 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13448 list_for_each_entry(psb
, sblist
, list
) {
13449 /* Set up the sge entry */
13450 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13451 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13452 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13453 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13454 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13455 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
13457 pdma_phys_bpl1
= 0;
13458 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13459 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13460 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13461 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13462 /* Keep the first xritag on the list */
13464 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
13468 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13469 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13470 /* Perform endian conversion if necessary */
13471 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13473 if (!phba
->sli4_hba
.intr_enable
)
13474 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13476 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13477 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13479 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13480 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13481 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13482 if (rc
!= MBX_TIMEOUT
)
13483 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13484 if (shdr_status
|| shdr_add_status
|| rc
) {
13485 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13486 "2564 POST_SGL_BLOCK mailbox command failed "
13487 "status x%x add_status x%x mbx status x%x\n",
13488 shdr_status
, shdr_add_status
, rc
);
13495 * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port.
13496 * @phba: pointer to lpfc hba data structure.
13497 * @sblist: pointer to scsi buffer list.
13498 * @count: number of scsi buffers on the list.
13500 * This routine is invoked to post a block of @count scsi sgl pages from a
13501 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13506 lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba
*phba
, struct list_head
*sblist
,
13509 struct lpfc_scsi_buf
*psb
= NULL
;
13510 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13511 struct sgl_page_pairs
*sgl_pg_pairs
;
13513 LPFC_MBOXQ_t
*mbox
;
13514 uint32_t reqlen
, alloclen
, pg_pairs
;
13516 uint16_t xri_start
= 0, scsi_xri_start
;
13517 uint16_t rsrc_range
;
13518 int rc
= 0, avail_cnt
;
13519 uint32_t shdr_status
, shdr_add_status
;
13520 dma_addr_t pdma_phys_bpl1
;
13521 union lpfc_sli4_cfg_shdr
*shdr
;
13522 struct lpfc_rsrc_blks
*rsrc_blk
;
13523 uint32_t xri_cnt
= 0;
13525 /* Calculate the total requested length of the dma memory */
13526 reqlen
= cnt
* sizeof(struct sgl_page_pairs
) +
13527 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13528 if (reqlen
> SLI4_PAGE_SIZE
) {
13529 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13530 "2932 Block sgl registration required DMA "
13531 "size (%d) great than a page\n", reqlen
);
13536 * The use of extents requires the driver to post the sgl headers
13537 * in multiple postings to meet the contiguous resource assignment.
13539 psb
= list_prepare_entry(psb
, sblist
, list
);
13540 scsi_xri_start
= phba
->sli4_hba
.scsi_xri_start
;
13541 list_for_each_entry(rsrc_blk
, &phba
->sli4_hba
.lpfc_xri_blk_list
,
13543 rsrc_range
= rsrc_blk
->rsrc_start
+ rsrc_blk
->rsrc_size
;
13544 if (rsrc_range
< scsi_xri_start
)
13546 else if (rsrc_blk
->rsrc_used
>= rsrc_blk
->rsrc_size
)
13549 avail_cnt
= rsrc_blk
->rsrc_size
- rsrc_blk
->rsrc_used
;
13551 reqlen
= (avail_cnt
* sizeof(struct sgl_page_pairs
)) +
13552 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13554 * Allocate DMA memory and set up the non-embedded mailbox
13555 * command. The mbox is used to post an SGL page per loop
13556 * but the DMA memory has a use-once semantic so the mailbox
13557 * is used and freed per loop pass.
13559 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13561 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13562 "2933 Failed to allocate mbox cmd "
13566 alloclen
= lpfc_sli4_config(phba
, mbox
,
13567 LPFC_MBOX_SUBSYSTEM_FCOE
,
13568 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13570 LPFC_SLI4_MBX_NEMBED
);
13571 if (alloclen
< reqlen
) {
13572 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13573 "2934 Allocated DMA memory size (%d) "
13574 "is less than the requested DMA memory "
13575 "size (%d)\n", alloclen
, reqlen
);
13576 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13580 /* Get the first SGE entry from the non-embedded DMA memory */
13581 viraddr
= mbox
->sge_array
->addr
[0];
13583 /* Set up the SGL pages in the non-embedded DMA pages */
13584 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13585 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13587 /* pg_pairs tracks posted SGEs per loop iteration. */
13589 list_for_each_entry_continue(psb
, sblist
, list
) {
13590 /* Set up the sge entry */
13591 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13592 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13593 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13594 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13595 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13596 pdma_phys_bpl1
= psb
->dma_phys_bpl
+
13599 pdma_phys_bpl1
= 0;
13600 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13601 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13602 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13603 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13604 /* Keep the first xri for this extent. */
13606 xri_start
= psb
->cur_iocbq
.sli4_xritag
;
13612 * Track two exit conditions - the loop has constructed
13613 * all of the caller's SGE pairs or all available
13614 * resource IDs in this extent are consumed.
13616 if ((xri_cnt
== cnt
) || (pg_pairs
>= avail_cnt
))
13619 rsrc_blk
->rsrc_used
+= pg_pairs
;
13620 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xri_start
);
13621 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13623 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13624 "3016 Post SCSI Extent SGL, start %d, cnt %d "
13626 xri_start
, pg_pairs
, rsrc_blk
->rsrc_used
);
13627 /* Perform endian conversion if necessary */
13628 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13629 if (!phba
->sli4_hba
.intr_enable
)
13630 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13632 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13633 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13635 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13636 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13637 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
13639 if (rc
!= MBX_TIMEOUT
)
13640 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13641 if (shdr_status
|| shdr_add_status
|| rc
) {
13642 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13643 "2935 POST_SGL_BLOCK mailbox command "
13644 "failed status x%x add_status x%x "
13645 "mbx status x%x\n",
13646 shdr_status
, shdr_add_status
, rc
);
13650 /* Post only what is requested. */
13651 if (xri_cnt
>= cnt
)
13658 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13659 * @phba: pointer to lpfc_hba struct that the frame was received on
13660 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13662 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13663 * valid type of frame that the LPFC driver will handle. This function will
13664 * return a zero if the frame is a valid frame or a non zero value when the
13665 * frame does not pass the check.
13668 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
13670 /* make rctl_names static to save stack space */
13671 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
13672 char *type_names
[] = FC_TYPE_NAMES_INIT
;
13673 struct fc_vft_header
*fc_vft_hdr
;
13674 uint32_t *header
= (uint32_t *) fc_hdr
;
13676 switch (fc_hdr
->fh_r_ctl
) {
13677 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
13678 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
13679 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
13680 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
13681 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
13682 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
13683 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
13684 case FC_RCTL_DD_CMD_STATUS
: /* command status */
13685 case FC_RCTL_ELS_REQ
: /* extended link services request */
13686 case FC_RCTL_ELS_REP
: /* extended link services reply */
13687 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
13688 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
13689 case FC_RCTL_BA_NOP
: /* basic link service NOP */
13690 case FC_RCTL_BA_ABTS
: /* basic link service abort */
13691 case FC_RCTL_BA_RMC
: /* remove connection */
13692 case FC_RCTL_BA_ACC
: /* basic accept */
13693 case FC_RCTL_BA_RJT
: /* basic reject */
13694 case FC_RCTL_BA_PRMT
:
13695 case FC_RCTL_ACK_1
: /* acknowledge_1 */
13696 case FC_RCTL_ACK_0
: /* acknowledge_0 */
13697 case FC_RCTL_P_RJT
: /* port reject */
13698 case FC_RCTL_F_RJT
: /* fabric reject */
13699 case FC_RCTL_P_BSY
: /* port busy */
13700 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
13701 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
13702 case FC_RCTL_LCR
: /* link credit reset */
13703 case FC_RCTL_END
: /* end */
13705 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
13706 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13707 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
13708 return lpfc_fc_frame_check(phba
, fc_hdr
);
13712 switch (fc_hdr
->fh_type
) {
13724 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
13725 "2538 Received frame rctl:%s type:%s "
13726 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13727 rctl_names
[fc_hdr
->fh_r_ctl
],
13728 type_names
[fc_hdr
->fh_type
],
13729 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
13730 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
13731 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]));
13734 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13735 "2539 Dropped frame rctl:%s type:%s\n",
13736 rctl_names
[fc_hdr
->fh_r_ctl
],
13737 type_names
[fc_hdr
->fh_type
]);
13742 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13743 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13745 * This function processes the FC header to retrieve the VFI from the VF
13746 * header, if one exists. This function will return the VFI if one exists
13747 * or 0 if no VSAN Header exists.
13750 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
13752 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13754 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
13756 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
13760 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
13761 * @phba: Pointer to the HBA structure to search for the vport on
13762 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13763 * @fcfi: The FC Fabric ID that the frame came from
13765 * This function searches the @phba for a vport that matches the content of the
13766 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
13767 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
13768 * returns the matching vport pointer or NULL if unable to match frame to a
13771 static struct lpfc_vport
*
13772 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
13775 struct lpfc_vport
**vports
;
13776 struct lpfc_vport
*vport
= NULL
;
13778 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
13779 fc_hdr
->fh_d_id
[1] << 8 |
13780 fc_hdr
->fh_d_id
[2]);
13781 if (did
== Fabric_DID
)
13782 return phba
->pport
;
13783 vports
= lpfc_create_vport_work_array(phba
);
13784 if (vports
!= NULL
)
13785 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
13786 if (phba
->fcf
.fcfi
== fcfi
&&
13787 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
13788 vports
[i
]->fc_myDID
== did
) {
13793 lpfc_destroy_vport_work_array(phba
, vports
);
13798 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
13799 * @vport: The vport to work on.
13801 * This function updates the receive sequence time stamp for this vport. The
13802 * receive sequence time stamp indicates the time that the last frame of the
13803 * the sequence that has been idle for the longest amount of time was received.
13804 * the driver uses this time stamp to indicate if any received sequences have
13808 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
13810 struct lpfc_dmabuf
*h_buf
;
13811 struct hbq_dmabuf
*dmabuf
= NULL
;
13813 /* get the oldest sequence on the rcv list */
13814 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
13815 struct lpfc_dmabuf
, list
);
13818 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13819 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
13823 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
13824 * @vport: The vport that the received sequences were sent to.
13826 * This function cleans up all outstanding received sequences. This is called
13827 * by the driver when a link event or user action invalidates all the received
13831 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
13833 struct lpfc_dmabuf
*h_buf
, *hnext
;
13834 struct lpfc_dmabuf
*d_buf
, *dnext
;
13835 struct hbq_dmabuf
*dmabuf
= NULL
;
13837 /* start with the oldest sequence on the rcv list */
13838 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13839 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13840 list_del_init(&dmabuf
->hbuf
.list
);
13841 list_for_each_entry_safe(d_buf
, dnext
,
13842 &dmabuf
->dbuf
.list
, list
) {
13843 list_del_init(&d_buf
->list
);
13844 lpfc_in_buf_free(vport
->phba
, d_buf
);
13846 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13851 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
13852 * @vport: The vport that the received sequences were sent to.
13854 * This function determines whether any received sequences have timed out by
13855 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
13856 * indicates that there is at least one timed out sequence this routine will
13857 * go through the received sequences one at a time from most inactive to most
13858 * active to determine which ones need to be cleaned up. Once it has determined
13859 * that a sequence needs to be cleaned up it will simply free up the resources
13860 * without sending an abort.
13863 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
13865 struct lpfc_dmabuf
*h_buf
, *hnext
;
13866 struct lpfc_dmabuf
*d_buf
, *dnext
;
13867 struct hbq_dmabuf
*dmabuf
= NULL
;
13868 unsigned long timeout
;
13869 int abort_count
= 0;
13871 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13872 vport
->rcv_buffer_time_stamp
);
13873 if (list_empty(&vport
->rcv_buffer_list
) ||
13874 time_before(jiffies
, timeout
))
13876 /* start with the oldest sequence on the rcv list */
13877 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
13878 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13879 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
13880 dmabuf
->time_stamp
);
13881 if (time_before(jiffies
, timeout
))
13884 list_del_init(&dmabuf
->hbuf
.list
);
13885 list_for_each_entry_safe(d_buf
, dnext
,
13886 &dmabuf
->dbuf
.list
, list
) {
13887 list_del_init(&d_buf
->list
);
13888 lpfc_in_buf_free(vport
->phba
, d_buf
);
13890 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
13893 lpfc_update_rcv_time_stamp(vport
);
13897 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
13898 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
13900 * This function searches through the existing incomplete sequences that have
13901 * been sent to this @vport. If the frame matches one of the incomplete
13902 * sequences then the dbuf in the @dmabuf is added to the list of frames that
13903 * make up that sequence. If no sequence is found that matches this frame then
13904 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
13905 * This function returns a pointer to the first dmabuf in the sequence list that
13906 * the frame was linked to.
13908 static struct hbq_dmabuf
*
13909 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
13911 struct fc_frame_header
*new_hdr
;
13912 struct fc_frame_header
*temp_hdr
;
13913 struct lpfc_dmabuf
*d_buf
;
13914 struct lpfc_dmabuf
*h_buf
;
13915 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
13916 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
13918 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
13919 dmabuf
->time_stamp
= jiffies
;
13920 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
13921 /* Use the hdr_buf to find the sequence that this frame belongs to */
13922 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
13923 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
13924 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
13925 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
13926 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
13928 /* found a pending sequence that matches this frame */
13929 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
13934 * This indicates first frame received for this sequence.
13935 * Queue the buffer on the vport's rcv_buffer_list.
13937 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13938 lpfc_update_rcv_time_stamp(vport
);
13941 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
13942 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
13943 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13944 list_del_init(&seq_dmabuf
->hbuf
.list
);
13945 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13946 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
13947 lpfc_update_rcv_time_stamp(vport
);
13950 /* move this sequence to the tail to indicate a young sequence */
13951 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
13952 seq_dmabuf
->time_stamp
= jiffies
;
13953 lpfc_update_rcv_time_stamp(vport
);
13954 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
13955 temp_hdr
= dmabuf
->hbuf
.virt
;
13956 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
13959 /* find the correct place in the sequence to insert this frame */
13960 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
13961 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
13962 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
13964 * If the frame's sequence count is greater than the frame on
13965 * the list then insert the frame right after this frame
13967 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
13968 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
13969 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
13977 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
13978 * @vport: pointer to a vitural port
13979 * @dmabuf: pointer to a dmabuf that describes the FC sequence
13981 * This function tries to abort from the partially assembed sequence, described
13982 * by the information from basic abbort @dmabuf. It checks to see whether such
13983 * partially assembled sequence held by the driver. If so, it shall free up all
13984 * the frames from the partially assembled sequence.
13987 * true -- if there is matching partially assembled sequence present and all
13988 * the frames freed with the sequence;
13989 * false -- if there is no matching partially assembled sequence present so
13990 * nothing got aborted in the lower layer driver
13993 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
13994 struct hbq_dmabuf
*dmabuf
)
13996 struct fc_frame_header
*new_hdr
;
13997 struct fc_frame_header
*temp_hdr
;
13998 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
13999 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14001 /* Use the hdr_buf to find the sequence that matches this frame */
14002 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14003 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
14004 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14005 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14006 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14007 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14008 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14009 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14011 /* found a pending sequence that matches this frame */
14012 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14016 /* Free up all the frames from the partially assembled sequence */
14018 list_for_each_entry_safe(d_buf
, n_buf
,
14019 &seq_dmabuf
->dbuf
.list
, list
) {
14020 list_del_init(&d_buf
->list
);
14021 lpfc_in_buf_free(vport
->phba
, d_buf
);
14029 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14030 * @phba: Pointer to HBA context object.
14031 * @cmd_iocbq: pointer to the command iocbq structure.
14032 * @rsp_iocbq: pointer to the response iocbq structure.
14034 * This function handles the sequence abort response iocb command complete
14035 * event. It properly releases the memory allocated to the sequence abort
14039 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
14040 struct lpfc_iocbq
*cmd_iocbq
,
14041 struct lpfc_iocbq
*rsp_iocbq
)
14044 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
14048 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14049 * @phba: Pointer to HBA context object.
14050 * @xri: xri id in transaction.
14052 * This function validates the xri maps to the known range of XRIs allocated an
14053 * used by the driver.
14056 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
14061 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
14062 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
14070 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14071 * @phba: Pointer to HBA context object.
14072 * @fc_hdr: pointer to a FC frame header.
14074 * This function sends a basic response to a previous unsol sequence abort
14075 * event after aborting the sequence handling.
14078 lpfc_sli4_seq_abort_rsp(struct lpfc_hba
*phba
,
14079 struct fc_frame_header
*fc_hdr
)
14081 struct lpfc_iocbq
*ctiocb
= NULL
;
14082 struct lpfc_nodelist
*ndlp
;
14083 uint16_t oxid
, rxid
;
14084 uint32_t sid
, fctl
;
14088 if (!lpfc_is_link_up(phba
))
14091 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14092 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
14093 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
14095 ndlp
= lpfc_findnode_did(phba
->pport
, sid
);
14097 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14098 "1268 Find ndlp returned NULL for oxid:x%x "
14099 "SID:x%x\n", oxid
, sid
);
14102 if (lpfc_sli4_xri_inrange(phba
, rxid
))
14103 lpfc_set_rrq_active(phba
, ndlp
, rxid
, oxid
, 0);
14105 /* Allocate buffer for rsp iocb */
14106 ctiocb
= lpfc_sli_get_iocbq(phba
);
14110 /* Extract the F_CTL field from FC_HDR */
14111 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
14113 icmd
= &ctiocb
->iocb
;
14114 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
14115 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
14116 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
14117 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
14118 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
14120 /* Fill in the rest of iocb fields */
14121 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
14122 icmd
->ulpBdeCount
= 0;
14124 icmd
->ulpClass
= CLASS3
;
14125 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
14126 ctiocb
->context1
= ndlp
;
14128 ctiocb
->iocb_cmpl
= NULL
;
14129 ctiocb
->vport
= phba
->pport
;
14130 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
14131 ctiocb
->sli4_lxritag
= NO_XRI
;
14132 ctiocb
->sli4_xritag
= NO_XRI
;
14134 /* If the oxid maps to the FCP XRI range or if it is out of range,
14135 * send a BLS_RJT. The driver no longer has that exchange.
14136 * Override the IOCB for a BA_RJT.
14138 if (oxid
> (phba
->sli4_hba
.max_cfg_param
.max_xri
+
14139 phba
->sli4_hba
.max_cfg_param
.xri_base
) ||
14140 oxid
> (lpfc_sli4_get_els_iocb_cnt(phba
) +
14141 phba
->sli4_hba
.max_cfg_param
.xri_base
)) {
14142 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14143 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14144 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14145 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14148 if (fctl
& FC_FC_EX_CTX
) {
14149 /* ABTS sent by responder to CT exchange, construction
14150 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14151 * field and RX_ID from ABTS for RX_ID field.
14153 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14154 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14156 /* ABTS sent by initiator to CT exchange, construction
14157 * of BA_ACC will need to allocate a new XRI as for the
14158 * XRI_TAG and RX_ID fields.
14160 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14161 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, NO_XRI
);
14163 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14165 /* Xmit CT abts response on exchange <xid> */
14166 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14167 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14168 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14170 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14171 if (rc
== IOCB_ERROR
) {
14172 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
14173 "2925 Failed to issue CT ABTS RSP x%x on "
14174 "xri x%x, Data x%x\n",
14175 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14177 lpfc_sli_release_iocbq(phba
, ctiocb
);
14182 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14183 * @vport: Pointer to the vport on which this sequence was received
14184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14186 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14187 * receive sequence is only partially assembed by the driver, it shall abort
14188 * the partially assembled frames for the sequence. Otherwise, if the
14189 * unsolicited receive sequence has been completely assembled and passed to
14190 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14191 * unsolicited sequence has been aborted. After that, it will issue a basic
14192 * accept to accept the abort.
14195 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14196 struct hbq_dmabuf
*dmabuf
)
14198 struct lpfc_hba
*phba
= vport
->phba
;
14199 struct fc_frame_header fc_hdr
;
14203 /* Make a copy of fc_hdr before the dmabuf being released */
14204 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14205 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14207 if (fctl
& FC_FC_EX_CTX
) {
14209 * ABTS sent by responder to exchange, just free the buffer
14211 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14214 * ABTS sent by initiator to exchange, need to do cleanup
14216 /* Try to abort partially assembled seq */
14217 abts_par
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14219 /* Send abort to ULP if partially seq abort failed */
14220 if (abts_par
== false)
14221 lpfc_sli4_send_seq_to_ulp(vport
, dmabuf
);
14223 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14225 /* Send basic accept (BA_ACC) to the abort requester */
14226 lpfc_sli4_seq_abort_rsp(phba
, &fc_hdr
);
14230 * lpfc_seq_complete - Indicates if a sequence is complete
14231 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14233 * This function checks the sequence, starting with the frame described by
14234 * @dmabuf, to see if all the frames associated with this sequence are present.
14235 * the frames associated with this sequence are linked to the @dmabuf using the
14236 * dbuf list. This function looks for two major things. 1) That the first frame
14237 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14238 * set. 3) That there are no holes in the sequence count. The function will
14239 * return 1 when the sequence is complete, otherwise it will return 0.
14242 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14244 struct fc_frame_header
*hdr
;
14245 struct lpfc_dmabuf
*d_buf
;
14246 struct hbq_dmabuf
*seq_dmabuf
;
14250 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14251 /* make sure first fame of sequence has a sequence count of zero */
14252 if (hdr
->fh_seq_cnt
!= seq_count
)
14254 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14255 hdr
->fh_f_ctl
[1] << 8 |
14257 /* If last frame of sequence we can return success. */
14258 if (fctl
& FC_FC_END_SEQ
)
14260 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14261 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14262 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14263 /* If there is a hole in the sequence count then fail. */
14264 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14266 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14267 hdr
->fh_f_ctl
[1] << 8 |
14269 /* If last frame of sequence we can return success. */
14270 if (fctl
& FC_FC_END_SEQ
)
14277 * lpfc_prep_seq - Prep sequence for ULP processing
14278 * @vport: Pointer to the vport on which this sequence was received
14279 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14281 * This function takes a sequence, described by a list of frames, and creates
14282 * a list of iocbq structures to describe the sequence. This iocbq list will be
14283 * used to issue to the generic unsolicited sequence handler. This routine
14284 * returns a pointer to the first iocbq in the list. If the function is unable
14285 * to allocate an iocbq then it throw out the received frames that were not
14286 * able to be described and return a pointer to the first iocbq. If unable to
14287 * allocate any iocbqs (including the first) this function will return NULL.
14289 static struct lpfc_iocbq
*
14290 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14292 struct hbq_dmabuf
*hbq_buf
;
14293 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14294 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14295 struct fc_frame_header
*fc_hdr
;
14297 uint32_t len
, tot_len
;
14298 struct ulp_bde64
*pbde
;
14300 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14301 /* remove from receive buffer list */
14302 list_del_init(&seq_dmabuf
->hbuf
.list
);
14303 lpfc_update_rcv_time_stamp(vport
);
14304 /* get the Remote Port's SID */
14305 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14307 /* Get an iocbq struct to fill in. */
14308 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14310 /* Initialize the first IOCB. */
14311 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14312 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14313 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14314 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14315 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14316 be16_to_cpu(fc_hdr
->fh_ox_id
);
14317 /* iocbq is prepped for internal consumption. Physical vpi. */
14318 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14319 vport
->phba
->vpi_ids
[vport
->vpi
];
14320 /* put the first buffer into the first IOCBq */
14321 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14322 first_iocbq
->context3
= NULL
;
14323 first_iocbq
->iocb
.ulpBdeCount
= 1;
14324 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14325 LPFC_DATA_BUF_SIZE
;
14326 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14327 tot_len
= bf_get(lpfc_rcqe_length
,
14328 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14329 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14331 iocbq
= first_iocbq
;
14333 * Each IOCBq can have two Buffers assigned, so go through the list
14334 * of buffers for this sequence and save two buffers in each IOCBq
14336 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14338 lpfc_in_buf_free(vport
->phba
, d_buf
);
14341 if (!iocbq
->context3
) {
14342 iocbq
->context3
= d_buf
;
14343 iocbq
->iocb
.ulpBdeCount
++;
14344 pbde
= (struct ulp_bde64
*)
14345 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14346 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14348 /* We need to get the size out of the right CQE */
14349 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14350 len
= bf_get(lpfc_rcqe_length
,
14351 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14352 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14355 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14358 first_iocbq
->iocb
.ulpStatus
=
14359 IOSTAT_FCP_RSP_ERROR
;
14360 first_iocbq
->iocb
.un
.ulpWord
[4] =
14361 IOERR_NO_RESOURCES
;
14363 lpfc_in_buf_free(vport
->phba
, d_buf
);
14366 iocbq
->context2
= d_buf
;
14367 iocbq
->context3
= NULL
;
14368 iocbq
->iocb
.ulpBdeCount
= 1;
14369 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14370 LPFC_DATA_BUF_SIZE
;
14372 /* We need to get the size out of the right CQE */
14373 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14374 len
= bf_get(lpfc_rcqe_length
,
14375 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14377 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14379 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14380 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14383 return first_iocbq
;
14387 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14388 struct hbq_dmabuf
*seq_dmabuf
)
14390 struct fc_frame_header
*fc_hdr
;
14391 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
14392 struct lpfc_hba
*phba
= vport
->phba
;
14394 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14395 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
14397 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14398 "2707 Ring %d handler: Failed to allocate "
14399 "iocb Rctl x%x Type x%x received\n",
14401 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14404 if (!lpfc_complete_unsol_iocb(phba
,
14405 &phba
->sli
.ring
[LPFC_ELS_RING
],
14406 iocbq
, fc_hdr
->fh_r_ctl
,
14408 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14409 "2540 Ring %d handler: unexpected Rctl "
14410 "x%x Type x%x received\n",
14412 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14414 /* Free iocb created in lpfc_prep_seq */
14415 list_for_each_entry_safe(curr_iocb
, next_iocb
,
14416 &iocbq
->list
, list
) {
14417 list_del_init(&curr_iocb
->list
);
14418 lpfc_sli_release_iocbq(phba
, curr_iocb
);
14420 lpfc_sli_release_iocbq(phba
, iocbq
);
14424 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14425 * @phba: Pointer to HBA context object.
14427 * This function is called with no lock held. This function processes all
14428 * the received buffers and gives it to upper layers when a received buffer
14429 * indicates that it is the final frame in the sequence. The interrupt
14430 * service routine processes received buffers at interrupt contexts and adds
14431 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14432 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14433 * appropriate receive function when the final frame in a sequence is received.
14436 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
14437 struct hbq_dmabuf
*dmabuf
)
14439 struct hbq_dmabuf
*seq_dmabuf
;
14440 struct fc_frame_header
*fc_hdr
;
14441 struct lpfc_vport
*vport
;
14444 /* Process each received buffer */
14445 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14446 /* check to see if this a valid type of frame */
14447 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
14448 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14451 if ((bf_get(lpfc_cqe_code
,
14452 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
14453 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
14454 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14456 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
14457 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14458 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
14459 if (!vport
|| !(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
14460 /* throw out the frame */
14461 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14464 /* Handle the basic abort sequence (BA_ABTS) event */
14465 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
14466 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
14470 /* Link this frame */
14471 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
14473 /* unable to add frame to vport - throw it out */
14474 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14477 /* If not last frame in sequence continue processing frames. */
14478 if (!lpfc_seq_complete(seq_dmabuf
))
14481 /* Send the complete sequence to the upper layer protocol */
14482 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
14486 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14487 * @phba: pointer to lpfc hba data structure.
14489 * This routine is invoked to post rpi header templates to the
14490 * HBA consistent with the SLI-4 interface spec. This routine
14491 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14492 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14494 * This routine does not require any locks. It's usage is expected
14495 * to be driver load or reset recovery when the driver is
14500 * -EIO - The mailbox failed to complete successfully.
14501 * When this error occurs, the driver is not guaranteed
14502 * to have any rpi regions posted to the device and
14503 * must either attempt to repost the regions or take a
14507 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
14509 struct lpfc_rpi_hdr
*rpi_page
;
14513 /* SLI4 ports that support extents do not require RPI headers. */
14514 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14516 if (phba
->sli4_hba
.extents_in_use
)
14519 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
14521 * Assign the rpi headers a physical rpi only if the driver
14522 * has not initialized those resources. A port reset only
14523 * needs the headers posted.
14525 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
14527 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14529 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
14530 if (rc
!= MBX_SUCCESS
) {
14531 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14532 "2008 Error %d posting all rpi "
14540 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
14541 LPFC_RPI_RSRC_RDY
);
14546 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14547 * @phba: pointer to lpfc hba data structure.
14548 * @rpi_page: pointer to the rpi memory region.
14550 * This routine is invoked to post a single rpi header to the
14551 * HBA consistent with the SLI-4 interface spec. This memory region
14552 * maps up to 64 rpi context regions.
14556 * -ENOMEM - No available memory
14557 * -EIO - The mailbox failed to complete successfully.
14560 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
14562 LPFC_MBOXQ_t
*mboxq
;
14563 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
14565 uint32_t shdr_status
, shdr_add_status
;
14566 union lpfc_sli4_cfg_shdr
*shdr
;
14568 /* SLI4 ports that support extents do not require RPI headers. */
14569 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14571 if (phba
->sli4_hba
.extents_in_use
)
14574 /* The port is notified of the header region via a mailbox command. */
14575 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14577 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14578 "2001 Unable to allocate memory for issuing "
14579 "SLI_CONFIG_SPECIAL mailbox command\n");
14583 /* Post all rpi memory regions to the port. */
14584 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
14585 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14586 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
14587 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
14588 sizeof(struct lpfc_sli4_cfg_mhdr
),
14589 LPFC_SLI4_MBX_EMBED
);
14592 /* Post the physical rpi to the port for this rpi header. */
14593 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
14594 rpi_page
->start_rpi
);
14595 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
14596 hdr_tmpl
, rpi_page
->page_count
);
14598 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
14599 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
14600 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
14601 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
14602 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14603 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14604 if (rc
!= MBX_TIMEOUT
)
14605 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14606 if (shdr_status
|| shdr_add_status
|| rc
) {
14607 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14608 "2514 POST_RPI_HDR mailbox failed with "
14609 "status x%x add_status x%x, mbx status x%x\n",
14610 shdr_status
, shdr_add_status
, rc
);
14617 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14618 * @phba: pointer to lpfc hba data structure.
14620 * This routine is invoked to post rpi header templates to the
14621 * HBA consistent with the SLI-4 interface spec. This routine
14622 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14623 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14626 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14627 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14630 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
14633 uint16_t max_rpi
, rpi_limit
;
14634 uint16_t rpi_remaining
, lrpi
= 0;
14635 struct lpfc_rpi_hdr
*rpi_hdr
;
14637 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
14638 rpi_limit
= phba
->sli4_hba
.next_rpi
;
14641 * Fetch the next logical rpi. Because this index is logical,
14642 * the driver starts at 0 each time.
14644 spin_lock_irq(&phba
->hbalock
);
14645 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
14646 if (rpi
>= rpi_limit
)
14647 rpi
= LPFC_RPI_ALLOC_ERROR
;
14649 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
14650 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
14651 phba
->sli4_hba
.rpi_count
++;
14655 * Don't try to allocate more rpi header regions if the device limit
14656 * has been exhausted.
14658 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
14659 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
14660 spin_unlock_irq(&phba
->hbalock
);
14665 * RPI header postings are not required for SLI4 ports capable of
14668 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
14669 spin_unlock_irq(&phba
->hbalock
);
14674 * If the driver is running low on rpi resources, allocate another
14675 * page now. Note that the next_rpi value is used because
14676 * it represents how many are actually in use whereas max_rpi notes
14677 * how many are supported max by the device.
14679 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
14680 spin_unlock_irq(&phba
->hbalock
);
14681 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
14682 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
14684 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14685 "2002 Error Could not grow rpi "
14688 lrpi
= rpi_hdr
->start_rpi
;
14689 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14690 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
14698 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14699 * @phba: pointer to lpfc hba data structure.
14701 * This routine is invoked to release an rpi to the pool of
14702 * available rpis maintained by the driver.
14705 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14707 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
14708 phba
->sli4_hba
.rpi_count
--;
14709 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
14714 * lpfc_sli4_free_rpi - Release an rpi for reuse.
14715 * @phba: pointer to lpfc hba data structure.
14717 * This routine is invoked to release an rpi to the pool of
14718 * available rpis maintained by the driver.
14721 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
14723 spin_lock_irq(&phba
->hbalock
);
14724 __lpfc_sli4_free_rpi(phba
, rpi
);
14725 spin_unlock_irq(&phba
->hbalock
);
14729 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
14730 * @phba: pointer to lpfc hba data structure.
14732 * This routine is invoked to remove the memory region that
14733 * provided rpi via a bitmask.
14736 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
14738 kfree(phba
->sli4_hba
.rpi_bmask
);
14739 kfree(phba
->sli4_hba
.rpi_ids
);
14740 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
14744 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
14745 * @phba: pointer to lpfc hba data structure.
14747 * This routine is invoked to remove the memory region that
14748 * provided rpi via a bitmask.
14751 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
)
14753 LPFC_MBOXQ_t
*mboxq
;
14754 struct lpfc_hba
*phba
= ndlp
->phba
;
14757 /* The port is notified of the header region via a mailbox command. */
14758 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14762 /* Post all rpi memory regions to the port. */
14763 lpfc_resume_rpi(mboxq
, ndlp
);
14764 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14765 if (rc
== MBX_NOT_FINISHED
) {
14766 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14767 "2010 Resume RPI Mailbox failed "
14768 "status %d, mbxStatus x%x\n", rc
,
14769 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14770 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14777 * lpfc_sli4_init_vpi - Initialize a vpi with the port
14778 * @vport: Pointer to the vport for which the vpi is being initialized
14780 * This routine is invoked to activate a vpi with the port.
14784 * -Evalue otherwise
14787 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
14789 LPFC_MBOXQ_t
*mboxq
;
14791 int retval
= MBX_SUCCESS
;
14793 struct lpfc_hba
*phba
= vport
->phba
;
14794 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14797 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
14798 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
14799 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
14800 if (rc
!= MBX_SUCCESS
) {
14801 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
14802 "2022 INIT VPI Mailbox failed "
14803 "status %d, mbxStatus x%x\n", rc
,
14804 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
14807 if (rc
!= MBX_TIMEOUT
)
14808 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
14814 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
14815 * @phba: pointer to lpfc hba data structure.
14816 * @mboxq: Pointer to mailbox object.
14818 * This routine is invoked to manually add a single FCF record. The caller
14819 * must pass a completely initialized FCF_Record. This routine takes
14820 * care of the nonembedded mailbox operations.
14823 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
14826 union lpfc_sli4_cfg_shdr
*shdr
;
14827 uint32_t shdr_status
, shdr_add_status
;
14829 virt_addr
= mboxq
->sge_array
->addr
[0];
14830 /* The IOCTL status is embedded in the mailbox subheader. */
14831 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
14832 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14833 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14835 if ((shdr_status
|| shdr_add_status
) &&
14836 (shdr_status
!= STATUS_FCF_IN_USE
))
14837 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14838 "2558 ADD_FCF_RECORD mailbox failed with "
14839 "status x%x add_status x%x\n",
14840 shdr_status
, shdr_add_status
);
14842 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14846 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
14847 * @phba: pointer to lpfc hba data structure.
14848 * @fcf_record: pointer to the initialized fcf record to add.
14850 * This routine is invoked to manually add a single FCF record. The caller
14851 * must pass a completely initialized FCF_Record. This routine takes
14852 * care of the nonembedded mailbox operations.
14855 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
14858 LPFC_MBOXQ_t
*mboxq
;
14861 dma_addr_t phys_addr
;
14862 struct lpfc_mbx_sge sge
;
14863 uint32_t alloc_len
, req_len
;
14866 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14868 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14869 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
14873 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
14876 /* Allocate DMA memory and set up the non-embedded mailbox command */
14877 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14878 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
14879 req_len
, LPFC_SLI4_MBX_NEMBED
);
14880 if (alloc_len
< req_len
) {
14881 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14882 "2523 Allocated DMA memory size (x%x) is "
14883 "less than the requested DMA memory "
14884 "size (x%x)\n", alloc_len
, req_len
);
14885 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14890 * Get the first SGE entry from the non-embedded DMA memory. This
14891 * routine only uses a single SGE.
14893 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
14894 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
14895 virt_addr
= mboxq
->sge_array
->addr
[0];
14897 * Configure the FCF record for FCFI 0. This is the driver's
14898 * hardcoded default and gets used in nonFIP mode.
14900 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
14901 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
14902 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
14905 * Copy the fcf_index and the FCF Record Data. The data starts after
14906 * the FCoE header plus word10. The data copy needs to be endian
14909 bytep
+= sizeof(uint32_t);
14910 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
14911 mboxq
->vport
= phba
->pport
;
14912 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
14913 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
14914 if (rc
== MBX_NOT_FINISHED
) {
14915 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14916 "2515 ADD_FCF_RECORD mailbox failed with "
14917 "status 0x%x\n", rc
);
14918 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
14927 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
14928 * @phba: pointer to lpfc hba data structure.
14929 * @fcf_record: pointer to the fcf record to write the default data.
14930 * @fcf_index: FCF table entry index.
14932 * This routine is invoked to build the driver's default FCF record. The
14933 * values used are hardcoded. This routine handles memory initialization.
14937 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
14938 struct fcf_record
*fcf_record
,
14939 uint16_t fcf_index
)
14941 memset(fcf_record
, 0, sizeof(struct fcf_record
));
14942 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
14943 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
14944 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
14945 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
14946 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
14947 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
14948 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
14949 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
14950 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
14951 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
14952 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
14953 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
14954 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
14955 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
14956 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
14957 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
14958 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
14959 /* Set the VLAN bit map */
14960 if (phba
->valid_vlan
) {
14961 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
14962 = 1 << (phba
->vlan_id
% 8);
14967 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
14968 * @phba: pointer to lpfc hba data structure.
14969 * @fcf_index: FCF table entry offset.
14971 * This routine is invoked to scan the entire FCF table by reading FCF
14972 * record and processing it one at a time starting from the @fcf_index
14973 * for initial FCF discovery or fast FCF failover rediscovery.
14975 * Return 0 if the mailbox command is submitted successfully, none 0
14979 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
14982 LPFC_MBOXQ_t
*mboxq
;
14984 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
14985 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14987 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14988 "2000 Failed to allocate mbox for "
14991 goto fail_fcf_scan
;
14993 /* Construct the read FCF record mailbox command */
14994 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
14997 goto fail_fcf_scan
;
14999 /* Issue the mailbox command asynchronously */
15000 mboxq
->vport
= phba
->pport
;
15001 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
15003 spin_lock_irq(&phba
->hbalock
);
15004 phba
->hba_flag
|= FCF_TS_INPROG
;
15005 spin_unlock_irq(&phba
->hbalock
);
15007 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15008 if (rc
== MBX_NOT_FINISHED
)
15011 /* Reset eligible FCF count for new scan */
15012 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
15013 phba
->fcf
.eligible_fcf_cnt
= 0;
15019 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15020 /* FCF scan failed, clear FCF_TS_INPROG flag */
15021 spin_lock_irq(&phba
->hbalock
);
15022 phba
->hba_flag
&= ~FCF_TS_INPROG
;
15023 spin_unlock_irq(&phba
->hbalock
);
15029 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15030 * @phba: pointer to lpfc hba data structure.
15031 * @fcf_index: FCF table entry offset.
15033 * This routine is invoked to read an FCF record indicated by @fcf_index
15034 * and to use it for FLOGI roundrobin FCF failover.
15036 * Return 0 if the mailbox command is submitted successfully, none 0
15040 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15043 LPFC_MBOXQ_t
*mboxq
;
15045 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15047 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15048 "2763 Failed to allocate mbox for "
15051 goto fail_fcf_read
;
15053 /* Construct the read FCF record mailbox command */
15054 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15057 goto fail_fcf_read
;
15059 /* Issue the mailbox command asynchronously */
15060 mboxq
->vport
= phba
->pport
;
15061 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
15062 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15063 if (rc
== MBX_NOT_FINISHED
)
15069 if (error
&& mboxq
)
15070 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15075 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15076 * @phba: pointer to lpfc hba data structure.
15077 * @fcf_index: FCF table entry offset.
15079 * This routine is invoked to read an FCF record indicated by @fcf_index to
15080 * determine whether it's eligible for FLOGI roundrobin failover list.
15082 * Return 0 if the mailbox command is submitted successfully, none 0
15086 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15089 LPFC_MBOXQ_t
*mboxq
;
15091 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15093 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15094 "2758 Failed to allocate mbox for "
15097 goto fail_fcf_read
;
15099 /* Construct the read FCF record mailbox command */
15100 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15103 goto fail_fcf_read
;
15105 /* Issue the mailbox command asynchronously */
15106 mboxq
->vport
= phba
->pport
;
15107 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
15108 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15109 if (rc
== MBX_NOT_FINISHED
)
15115 if (error
&& mboxq
)
15116 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15121 * lpfc_check_next_fcf_pri
15122 * phba pointer to the lpfc_hba struct for this port.
15123 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15124 * routine when the rr_bmask is empty. The FCF indecies are put into the
15125 * rr_bmask based on their priority level. Starting from the highest priority
15126 * to the lowest. The most likely FCF candidate will be in the highest
15127 * priority group. When this routine is called it searches the fcf_pri list for
15128 * next lowest priority group and repopulates the rr_bmask with only those
15131 * 1=success 0=failure
15134 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15136 uint16_t next_fcf_pri
;
15137 uint16_t last_index
;
15138 struct lpfc_fcf_pri
*fcf_pri
;
15142 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15143 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15144 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15145 "3060 Last IDX %d\n", last_index
);
15146 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
15147 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15148 "3061 Last IDX %d\n", last_index
);
15149 return 0; /* Empty rr list */
15153 * Clear the rr_bmask and set all of the bits that are at this
15156 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15157 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15158 spin_lock_irq(&phba
->hbalock
);
15159 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15160 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15163 * the 1st priority that has not FLOGI failed
15164 * will be the highest.
15167 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15168 spin_unlock_irq(&phba
->hbalock
);
15169 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15170 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15171 fcf_pri
->fcf_rec
.fcf_index
);
15175 spin_lock_irq(&phba
->hbalock
);
15178 * if next_fcf_pri was not set above and the list is not empty then
15179 * we have failed flogis on all of them. So reset flogi failed
15180 * and start at the begining.
15182 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15183 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15184 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15186 * the 1st priority that has not FLOGI failed
15187 * will be the highest.
15190 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15191 spin_unlock_irq(&phba
->hbalock
);
15192 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15193 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15194 fcf_pri
->fcf_rec
.fcf_index
);
15198 spin_lock_irq(&phba
->hbalock
);
15202 spin_unlock_irq(&phba
->hbalock
);
15207 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15208 * @phba: pointer to lpfc hba data structure.
15210 * This routine is to get the next eligible FCF record index in a round
15211 * robin fashion. If the next eligible FCF record index equals to the
15212 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15213 * shall be returned, otherwise, the next eligible FCF record's index
15214 * shall be returned.
15217 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15219 uint16_t next_fcf_index
;
15221 /* Search start from next bit of currently registered FCF index */
15223 next_fcf_index
= (phba
->fcf
.current_rec
.fcf_indx
+ 1) %
15224 LPFC_SLI4_FCF_TBL_INDX_MAX
;
15225 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15226 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15229 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15230 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15232 * If we have wrapped then we need to clear the bits that
15233 * have been tested so that we can detect when we should
15234 * change the priority level.
15236 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15237 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15241 /* Check roundrobin failover list empty condition */
15242 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15243 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15245 * If next fcf index is not found check if there are lower
15246 * Priority level fcf's in the fcf_priority list.
15247 * Set up the rr_bmask with all of the avaiable fcf bits
15248 * at that level and continue the selection process.
15250 if (lpfc_check_next_fcf_pri_level(phba
))
15251 goto next_priority
;
15252 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15253 "2844 No roundrobin failover FCF available\n");
15254 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15255 return LPFC_FCOE_FCF_NEXT_NONE
;
15257 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15258 "3063 Only FCF available idx %d, flag %x\n",
15260 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15261 return next_fcf_index
;
15265 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15266 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15267 LPFC_FCF_FLOGI_FAILED
)
15268 goto next_priority
;
15270 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15271 "2845 Get next roundrobin failover FCF (x%x)\n",
15274 return next_fcf_index
;
15278 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15279 * @phba: pointer to lpfc hba data structure.
15281 * This routine sets the FCF record index in to the eligible bmask for
15282 * roundrobin failover search. It checks to make sure that the index
15283 * does not go beyond the range of the driver allocated bmask dimension
15284 * before setting the bit.
15286 * Returns 0 if the index bit successfully set, otherwise, it returns
15290 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15292 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15293 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15294 "2610 FCF (x%x) reached driver's book "
15295 "keeping dimension:x%x\n",
15296 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15299 /* Set the eligible FCF record index bmask */
15300 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15302 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15303 "2790 Set FCF (x%x) to roundrobin FCF failover "
15304 "bmask\n", fcf_index
);
15310 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15311 * @phba: pointer to lpfc hba data structure.
15313 * This routine clears the FCF record index from the eligible bmask for
15314 * roundrobin failover search. It checks to make sure that the index
15315 * does not go beyond the range of the driver allocated bmask dimension
15316 * before clearing the bit.
15319 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15321 struct lpfc_fcf_pri
*fcf_pri
;
15322 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15323 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15324 "2762 FCF (x%x) reached driver's book "
15325 "keeping dimension:x%x\n",
15326 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15329 /* Clear the eligible FCF record index bmask */
15330 spin_lock_irq(&phba
->hbalock
);
15331 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15332 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15333 list_del_init(&fcf_pri
->list
);
15337 spin_unlock_irq(&phba
->hbalock
);
15338 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15340 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15341 "2791 Clear FCF (x%x) from roundrobin failover "
15342 "bmask\n", fcf_index
);
15346 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15347 * @phba: pointer to lpfc hba data structure.
15349 * This routine is the completion routine for the rediscover FCF table mailbox
15350 * command. If the mailbox command returned failure, it will try to stop the
15351 * FCF rediscover wait timer.
15354 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
15356 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15357 uint32_t shdr_status
, shdr_add_status
;
15359 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15361 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
15362 &redisc_fcf
->header
.cfg_shdr
.response
);
15363 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
15364 &redisc_fcf
->header
.cfg_shdr
.response
);
15365 if (shdr_status
|| shdr_add_status
) {
15366 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15367 "2746 Requesting for FCF rediscovery failed "
15368 "status x%x add_status x%x\n",
15369 shdr_status
, shdr_add_status
);
15370 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
15371 spin_lock_irq(&phba
->hbalock
);
15372 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
15373 spin_unlock_irq(&phba
->hbalock
);
15375 * CVL event triggered FCF rediscover request failed,
15376 * last resort to re-try current registered FCF entry.
15378 lpfc_retry_pport_discovery(phba
);
15380 spin_lock_irq(&phba
->hbalock
);
15381 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
15382 spin_unlock_irq(&phba
->hbalock
);
15384 * DEAD FCF event triggered FCF rediscover request
15385 * failed, last resort to fail over as a link down
15386 * to FCF registration.
15388 lpfc_sli4_fcf_dead_failthrough(phba
);
15391 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15392 "2775 Start FCF rediscover quiescent timer\n");
15394 * Start FCF rediscovery wait timer for pending FCF
15395 * before rescan FCF record table.
15397 lpfc_fcf_redisc_wait_start_timer(phba
);
15400 mempool_free(mbox
, phba
->mbox_mem_pool
);
15404 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15405 * @phba: pointer to lpfc hba data structure.
15407 * This routine is invoked to request for rediscovery of the entire FCF table
15411 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
15413 LPFC_MBOXQ_t
*mbox
;
15414 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15417 /* Cancel retry delay timers to all vports before FCF rediscover */
15418 lpfc_cancel_all_vport_retry_delay_timer(phba
);
15420 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15422 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15423 "2745 Failed to allocate mbox for "
15424 "requesting FCF rediscover.\n");
15428 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
15429 sizeof(struct lpfc_sli4_cfg_mhdr
));
15430 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15431 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
15432 length
, LPFC_SLI4_MBX_EMBED
);
15434 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15435 /* Set count to 0 for invalidating the entire FCF database */
15436 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
15438 /* Issue the mailbox command asynchronously */
15439 mbox
->vport
= phba
->pport
;
15440 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
15441 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
15443 if (rc
== MBX_NOT_FINISHED
) {
15444 mempool_free(mbox
, phba
->mbox_mem_pool
);
15451 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15452 * @phba: pointer to lpfc hba data structure.
15454 * This function is the failover routine as a last resort to the FCF DEAD
15455 * event when driver failed to perform fast FCF failover.
15458 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
15460 uint32_t link_state
;
15463 * Last resort as FCF DEAD event failover will treat this as
15464 * a link down, but save the link state because we don't want
15465 * it to be changed to Link Down unless it is already down.
15467 link_state
= phba
->link_state
;
15468 lpfc_linkdown(phba
);
15469 phba
->link_state
= link_state
;
15471 /* Unregister FCF if no devices connected to it */
15472 lpfc_unregister_unused_fcf(phba
);
15476 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15477 * @phba: pointer to lpfc hba data structure.
15478 * @rgn23_data: pointer to configure region 23 data.
15480 * This function gets SLI3 port configure region 23 data through memory dump
15481 * mailbox command. When it successfully retrieves data, the size of the data
15482 * will be returned, otherwise, 0 will be returned.
15485 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15487 LPFC_MBOXQ_t
*pmb
= NULL
;
15489 uint32_t offset
= 0;
15495 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15497 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15498 "2600 failed to allocate mailbox memory\n");
15504 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
15505 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
15507 if (rc
!= MBX_SUCCESS
) {
15508 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15509 "2601 failed to read config "
15510 "region 23, rc 0x%x Status 0x%x\n",
15511 rc
, mb
->mbxStatus
);
15512 mb
->un
.varDmp
.word_cnt
= 0;
15515 * dump mem may return a zero when finished or we got a
15516 * mailbox error, either way we are done.
15518 if (mb
->un
.varDmp
.word_cnt
== 0)
15520 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
15521 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
15523 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
15524 rgn23_data
+ offset
,
15525 mb
->un
.varDmp
.word_cnt
);
15526 offset
+= mb
->un
.varDmp
.word_cnt
;
15527 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
15529 mempool_free(pmb
, phba
->mbox_mem_pool
);
15534 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15535 * @phba: pointer to lpfc hba data structure.
15536 * @rgn23_data: pointer to configure region 23 data.
15538 * This function gets SLI4 port configure region 23 data through memory dump
15539 * mailbox command. When it successfully retrieves data, the size of the data
15540 * will be returned, otherwise, 0 will be returned.
15543 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15545 LPFC_MBOXQ_t
*mboxq
= NULL
;
15546 struct lpfc_dmabuf
*mp
= NULL
;
15547 struct lpfc_mqe
*mqe
;
15548 uint32_t data_length
= 0;
15554 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15556 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15557 "3105 failed to allocate mailbox memory\n");
15561 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
15563 mqe
= &mboxq
->u
.mqe
;
15564 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
15565 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15568 data_length
= mqe
->un
.mb_words
[5];
15569 if (data_length
== 0)
15571 if (data_length
> DMP_RGN23_SIZE
) {
15575 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
15577 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15579 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15582 return data_length
;
15586 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15587 * @phba: pointer to lpfc hba data structure.
15589 * This function read region 23 and parse TLV for port status to
15590 * decide if the user disaled the port. If the TLV indicates the
15591 * port is disabled, the hba_flag is set accordingly.
15594 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
15596 uint8_t *rgn23_data
= NULL
;
15597 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
15598 uint32_t offset
= 0;
15600 /* Get adapter Region 23 data */
15601 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
15605 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15606 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
15608 if_type
= bf_get(lpfc_sli_intf_if_type
,
15609 &phba
->sli4_hba
.sli_intf
);
15610 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
15612 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
15618 /* Check the region signature first */
15619 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
15620 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15621 "2619 Config region 23 has bad signature\n");
15626 /* Check the data structure version */
15627 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
15628 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15629 "2620 Config region 23 has bad version\n");
15634 /* Parse TLV entries in the region */
15635 while (offset
< data_size
) {
15636 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
15639 * If the TLV is not driver specific TLV or driver id is
15640 * not linux driver id, skip the record.
15642 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
15643 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
15644 (rgn23_data
[offset
+ 3] != 0)) {
15645 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15649 /* Driver found a driver specific TLV in the config region */
15650 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
15655 * Search for configured port state sub-TLV.
15657 while ((offset
< data_size
) &&
15658 (tlv_offset
< sub_tlv_len
)) {
15659 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
15664 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
15665 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15666 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
15670 /* This HBA contains PORT_STE configured */
15671 if (!rgn23_data
[offset
+ 2])
15672 phba
->hba_flag
|= LINK_DISABLED
;
15684 * lpfc_wr_object - write an object to the firmware
15685 * @phba: HBA structure that indicates port to create a queue on.
15686 * @dmabuf_list: list of dmabufs to write to the port.
15687 * @size: the total byte value of the objects to write to the port.
15688 * @offset: the current offset to be used to start the transfer.
15690 * This routine will create a wr_object mailbox command to send to the port.
15691 * the mailbox command will be constructed using the dma buffers described in
15692 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
15693 * BDEs that the imbedded mailbox can support. The @offset variable will be
15694 * used to indicate the starting offset of the transfer and will also return
15695 * the offset after the write object mailbox has completed. @size is used to
15696 * determine the end of the object and whether the eof bit should be set.
15698 * Return 0 is successful and offset will contain the the new offset to use
15699 * for the next write.
15700 * Return negative value for error cases.
15703 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
15704 uint32_t size
, uint32_t *offset
)
15706 struct lpfc_mbx_wr_object
*wr_object
;
15707 LPFC_MBOXQ_t
*mbox
;
15709 uint32_t shdr_status
, shdr_add_status
;
15711 union lpfc_sli4_cfg_shdr
*shdr
;
15712 struct lpfc_dmabuf
*dmabuf
;
15713 uint32_t written
= 0;
15715 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15719 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15720 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
15721 sizeof(struct lpfc_mbx_wr_object
) -
15722 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15724 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
15725 wr_object
->u
.request
.write_offset
= *offset
;
15726 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
15727 wr_object
->u
.request
.object_name
[0] =
15728 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
15729 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
15730 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
15731 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
15733 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
15734 wr_object
->u
.request
.bde
[i
].addrHigh
=
15735 putPaddrHigh(dmabuf
->phys
);
15736 if (written
+ SLI4_PAGE_SIZE
>= size
) {
15737 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15739 written
+= (size
- written
);
15740 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
15742 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
15744 written
+= SLI4_PAGE_SIZE
;
15748 wr_object
->u
.request
.bde_count
= i
;
15749 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
15750 if (!phba
->sli4_hba
.intr_enable
)
15751 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15753 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15754 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15756 /* The IOCTL status is embedded in the mailbox subheader. */
15757 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
15758 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15759 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15760 if (rc
!= MBX_TIMEOUT
)
15761 mempool_free(mbox
, phba
->mbox_mem_pool
);
15762 if (shdr_status
|| shdr_add_status
|| rc
) {
15763 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15764 "3025 Write Object mailbox failed with "
15765 "status x%x add_status x%x, mbx status x%x\n",
15766 shdr_status
, shdr_add_status
, rc
);
15769 *offset
+= wr_object
->u
.response
.actual_write_length
;
15774 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
15775 * @vport: pointer to vport data structure.
15777 * This function iterate through the mailboxq and clean up all REG_LOGIN
15778 * and REG_VPI mailbox commands associated with the vport. This function
15779 * is called when driver want to restart discovery of the vport due to
15780 * a Clear Virtual Link event.
15783 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
15785 struct lpfc_hba
*phba
= vport
->phba
;
15786 LPFC_MBOXQ_t
*mb
, *nextmb
;
15787 struct lpfc_dmabuf
*mp
;
15788 struct lpfc_nodelist
*ndlp
;
15789 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
15790 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
15791 LIST_HEAD(mbox_cmd_list
);
15792 uint8_t restart_loop
;
15794 /* Clean up internally queued mailbox commands with the vport */
15795 spin_lock_irq(&phba
->hbalock
);
15796 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
15797 if (mb
->vport
!= vport
)
15800 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15801 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15804 list_del(&mb
->list
);
15805 list_add_tail(&mb
->list
, &mbox_cmd_list
);
15807 /* Clean up active mailbox command with the vport */
15808 mb
= phba
->sli
.mbox_active
;
15809 if (mb
&& (mb
->vport
== vport
)) {
15810 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
15811 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
15812 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15813 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15814 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15815 /* Put reference count for delayed processing */
15816 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
15817 /* Unregister the RPI when mailbox complete */
15818 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15821 /* Cleanup any mailbox completions which are not yet processed */
15824 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
15826 * If this mailox is already processed or it is
15827 * for another vport ignore it.
15829 if ((mb
->vport
!= vport
) ||
15830 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
15833 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
15834 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
15837 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15838 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15839 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
15840 /* Unregister the RPI when mailbox complete */
15841 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
15843 spin_unlock_irq(&phba
->hbalock
);
15844 spin_lock(shost
->host_lock
);
15845 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15846 spin_unlock(shost
->host_lock
);
15847 spin_lock_irq(&phba
->hbalock
);
15851 } while (restart_loop
);
15853 spin_unlock_irq(&phba
->hbalock
);
15855 /* Release the cleaned-up mailbox commands */
15856 while (!list_empty(&mbox_cmd_list
)) {
15857 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
15858 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
15859 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
15861 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15864 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
15865 mb
->context2
= NULL
;
15867 spin_lock(shost
->host_lock
);
15868 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15869 spin_unlock(shost
->host_lock
);
15870 lpfc_nlp_put(ndlp
);
15873 mempool_free(mb
, phba
->mbox_mem_pool
);
15876 /* Release the ndlp with the cleaned-up active mailbox command */
15877 if (act_mbx_ndlp
) {
15878 spin_lock(shost
->host_lock
);
15879 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
15880 spin_unlock(shost
->host_lock
);
15881 lpfc_nlp_put(act_mbx_ndlp
);
15886 * lpfc_drain_txq - Drain the txq
15887 * @phba: Pointer to HBA context object.
15889 * This function attempt to submit IOCBs on the txq
15890 * to the adapter. For SLI4 adapters, the txq contains
15891 * ELS IOCBs that have been deferred because the there
15892 * are no SGLs. This congestion can occur with large
15893 * vport counts during node discovery.
15897 lpfc_drain_txq(struct lpfc_hba
*phba
)
15899 LIST_HEAD(completions
);
15900 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
15901 struct lpfc_iocbq
*piocbq
= 0;
15902 unsigned long iflags
= 0;
15903 char *fail_msg
= NULL
;
15904 struct lpfc_sglq
*sglq
;
15905 union lpfc_wqe wqe
;
15907 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15908 if (pring
->txq_cnt
> pring
->txq_max
)
15909 pring
->txq_max
= pring
->txq_cnt
;
15911 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15913 while (pring
->txq_cnt
) {
15914 spin_lock_irqsave(&phba
->hbalock
, iflags
);
15916 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
15917 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
15919 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
15920 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15924 /* The txq_cnt out of sync. This should
15927 sglq
= __lpfc_clear_active_sglq(phba
,
15928 sglq
->sli4_lxritag
);
15929 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15930 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15931 "2823 txq empty and txq_cnt is %d\n ",
15937 /* The xri and iocb resources secured,
15938 * attempt to issue request
15940 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
15941 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
15942 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
15943 fail_msg
= "to convert bpl to sgl";
15944 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
15945 fail_msg
= "to convert iocb to wqe";
15946 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
15947 fail_msg
= " - Wq is full";
15949 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
15952 /* Failed means we can't issue and need to cancel */
15953 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15954 "2822 IOCB failed %s iotag 0x%x "
15957 piocbq
->iotag
, piocbq
->sli4_xritag
);
15958 list_add_tail(&piocbq
->list
, &completions
);
15960 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
15963 /* Cancel all the IOCBs that cannot be issued */
15964 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
15965 IOERR_SLI_ABORTED
);
15967 return pring
->txq_cnt
;