blob: 7185aac243246382de1b66b68cba966b85060011 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart16a59fb2014-04-04 13:52:41 -04004 * Copyright (C) 2004-2014 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040028#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050029#include <scsi/scsi_cmnd.h>
30#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040032#include <scsi/scsi_transport_fc.h>
James Smartda0436e2009-05-22 14:51:39 -040033#include <scsi/fc/fc_fs.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
dea31012005-04-17 16:05:31 -050035
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_crtn.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050047#include "lpfc_debugfs.h"
James Smart04c68492009-05-22 14:52:52 -040048#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050049
50/* There are only four IOCB completion types. */
51typedef enum _lpfc_iocb_type {
52 LPFC_UNKNOWN_IOCB,
53 LPFC_UNSOL_IOCB,
54 LPFC_SOL_IOCB,
55 LPFC_ABORT_IOCB
56} lpfc_iocb_type;
57
James Smart4f774512009-05-22 14:52:35 -040058
59/* Provide function prototypes local to this module. */
60static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
61 uint32_t);
62static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
James Smart45ed1192009-10-02 15:17:02 -040063 uint8_t *, uint32_t *);
64static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
65 struct lpfc_iocbq *);
James Smart6669f9b2009-10-02 15:16:45 -040066static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
67 struct hbq_dmabuf *);
James Smart05580562011-05-24 11:40:48 -040068static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
69 struct lpfc_cqe *);
James Smart8a9d2e82012-05-09 21:16:12 -040070static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
71 int);
James Smartba20c852012-08-03 12:36:52 -040072static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
73 uint32_t);
James Smarte8d3c3b2013-10-10 12:21:30 -040074static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
75static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
James Smart05580562011-05-24 11:40:48 -040076
James Smart4f774512009-05-22 14:52:35 -040077static IOCB_t *
78lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
79{
80 return &iocbq->iocb;
81}
82
83/**
84 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
85 * @q: The Work Queue to operate on.
86 * @wqe: The work Queue Entry to put on the Work queue.
87 *
88 * This routine will copy the contents of @wqe to the next available entry on
89 * the @q. This function will then ring the Work Queue Doorbell to signal the
90 * HBA to start processing the Work Queue Entry. This function returns 0 if
91 * successful. If no entries are available on @q then this function will return
92 * -ENOMEM.
93 * The caller is expected to hold the hbalock when calling this routine.
94 **/
95static uint32_t
96lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
97{
James Smart2e90f4b2011-12-13 13:22:37 -050098 union lpfc_wqe *temp_wqe;
James Smart4f774512009-05-22 14:52:35 -040099 struct lpfc_register doorbell;
100 uint32_t host_index;
James Smart027140e2012-08-03 12:35:44 -0400101 uint32_t idx;
James Smart4f774512009-05-22 14:52:35 -0400102
James Smart2e90f4b2011-12-13 13:22:37 -0500103 /* sanity check on queue memory */
104 if (unlikely(!q))
105 return -ENOMEM;
106 temp_wqe = q->qe[q->host_index].wqe;
107
James Smart4f774512009-05-22 14:52:35 -0400108 /* If the host has not yet processed the next entry then we are done */
James Smart027140e2012-08-03 12:35:44 -0400109 idx = ((q->host_index + 1) % q->entry_count);
110 if (idx == q->hba_index) {
James Smartb84daac2012-08-03 12:35:13 -0400111 q->WQ_overflow++;
James Smart4f774512009-05-22 14:52:35 -0400112 return -ENOMEM;
James Smartb84daac2012-08-03 12:35:13 -0400113 }
114 q->WQ_posted++;
James Smart4f774512009-05-22 14:52:35 -0400115 /* set consumption flag every once in a while */
James Smartff78d8f2011-12-13 13:21:35 -0500116 if (!((q->host_index + 1) % q->entry_repost))
James Smartf0d9bcc2010-10-22 11:07:09 -0400117 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
James Smartfedd3b72011-02-16 12:39:24 -0500118 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
119 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
James Smart4f774512009-05-22 14:52:35 -0400120 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
121
122 /* Update the host index before invoking device */
123 host_index = q->host_index;
James Smart027140e2012-08-03 12:35:44 -0400124
125 q->host_index = idx;
James Smart4f774512009-05-22 14:52:35 -0400126
127 /* Ring Doorbell */
128 doorbell.word0 = 0;
James Smart962bc512013-01-03 15:44:00 -0500129 if (q->db_format == LPFC_DB_LIST_FORMAT) {
130 bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
131 bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
132 bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
133 } else if (q->db_format == LPFC_DB_RING_FORMAT) {
134 bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
135 bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
136 } else {
137 return -EINVAL;
138 }
139 writel(doorbell.word0, q->db_regaddr);
James Smart4f774512009-05-22 14:52:35 -0400140
141 return 0;
142}
143
144/**
145 * lpfc_sli4_wq_release - Updates internal hba index for WQ
146 * @q: The Work Queue to operate on.
147 * @index: The index to advance the hba index to.
148 *
149 * This routine will update the HBA index of a queue to reflect consumption of
150 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
151 * an entry the host calls this function to update the queue's internal
152 * pointers. This routine returns the number of entries that were consumed by
153 * the HBA.
154 **/
155static uint32_t
156lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
157{
158 uint32_t released = 0;
159
James Smart2e90f4b2011-12-13 13:22:37 -0500160 /* sanity check on queue memory */
161 if (unlikely(!q))
162 return 0;
163
James Smart4f774512009-05-22 14:52:35 -0400164 if (q->hba_index == index)
165 return 0;
166 do {
167 q->hba_index = ((q->hba_index + 1) % q->entry_count);
168 released++;
169 } while (q->hba_index != index);
170 return released;
171}
172
173/**
174 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
175 * @q: The Mailbox Queue to operate on.
176 * @wqe: The Mailbox Queue Entry to put on the Work queue.
177 *
178 * This routine will copy the contents of @mqe to the next available entry on
179 * the @q. This function will then ring the Work Queue Doorbell to signal the
180 * HBA to start processing the Work Queue Entry. This function returns 0 if
181 * successful. If no entries are available on @q then this function will return
182 * -ENOMEM.
183 * The caller is expected to hold the hbalock when calling this routine.
184 **/
185static uint32_t
186lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
187{
James Smart2e90f4b2011-12-13 13:22:37 -0500188 struct lpfc_mqe *temp_mqe;
James Smart4f774512009-05-22 14:52:35 -0400189 struct lpfc_register doorbell;
190 uint32_t host_index;
191
James Smart2e90f4b2011-12-13 13:22:37 -0500192 /* sanity check on queue memory */
193 if (unlikely(!q))
194 return -ENOMEM;
195 temp_mqe = q->qe[q->host_index].mqe;
196
James Smart4f774512009-05-22 14:52:35 -0400197 /* If the host has not yet processed the next entry then we are done */
198 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
199 return -ENOMEM;
200 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
201 /* Save off the mailbox pointer for completion */
202 q->phba->mbox = (MAILBOX_t *)temp_mqe;
203
204 /* Update the host index before invoking device */
205 host_index = q->host_index;
206 q->host_index = ((q->host_index + 1) % q->entry_count);
207
208 /* Ring Doorbell */
209 doorbell.word0 = 0;
210 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
211 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
212 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
James Smart4f774512009-05-22 14:52:35 -0400213 return 0;
214}
215
216/**
217 * lpfc_sli4_mq_release - Updates internal hba index for MQ
218 * @q: The Mailbox Queue to operate on.
219 *
220 * This routine will update the HBA index of a queue to reflect consumption of
221 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
222 * an entry the host calls this function to update the queue's internal
223 * pointers. This routine returns the number of entries that were consumed by
224 * the HBA.
225 **/
226static uint32_t
227lpfc_sli4_mq_release(struct lpfc_queue *q)
228{
James Smart2e90f4b2011-12-13 13:22:37 -0500229 /* sanity check on queue memory */
230 if (unlikely(!q))
231 return 0;
232
James Smart4f774512009-05-22 14:52:35 -0400233 /* Clear the mailbox pointer for completion */
234 q->phba->mbox = NULL;
235 q->hba_index = ((q->hba_index + 1) % q->entry_count);
236 return 1;
237}
238
239/**
240 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
241 * @q: The Event Queue to get the first valid EQE from
242 *
243 * This routine will get the first valid Event Queue Entry from @q, update
244 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
245 * the Queue (no more work to do), or the Queue is full of EQEs that have been
246 * processed, but not popped back to the HBA then this routine will return NULL.
247 **/
248static struct lpfc_eqe *
249lpfc_sli4_eq_get(struct lpfc_queue *q)
250{
James Smart2e90f4b2011-12-13 13:22:37 -0500251 struct lpfc_eqe *eqe;
James Smart027140e2012-08-03 12:35:44 -0400252 uint32_t idx;
James Smart2e90f4b2011-12-13 13:22:37 -0500253
254 /* sanity check on queue memory */
255 if (unlikely(!q))
256 return NULL;
257 eqe = q->qe[q->hba_index].eqe;
James Smart4f774512009-05-22 14:52:35 -0400258
259 /* If the next EQE is not valid then we are done */
James Smartcb5172e2010-03-15 11:25:07 -0400260 if (!bf_get_le32(lpfc_eqe_valid, eqe))
James Smart4f774512009-05-22 14:52:35 -0400261 return NULL;
262 /* If the host has not yet processed the next entry then we are done */
James Smart027140e2012-08-03 12:35:44 -0400263 idx = ((q->hba_index + 1) % q->entry_count);
264 if (idx == q->host_index)
James Smart4f774512009-05-22 14:52:35 -0400265 return NULL;
266
James Smart027140e2012-08-03 12:35:44 -0400267 q->hba_index = idx;
James Smart27f344e2014-05-07 17:16:46 -0400268
269 /*
270 * insert barrier for instruction interlock : data from the hardware
271 * must have the valid bit checked before it can be copied and acted
272 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
273 * instructions allowing action on content before valid bit checked,
274 * add barrier here as well. May not be needed as "content" is a
275 * single 32-bit entity here (vs multi word structure for cq's).
276 */
277 mb();
James Smart4f774512009-05-22 14:52:35 -0400278 return eqe;
279}
280
281/**
James Smartba20c852012-08-03 12:36:52 -0400282 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
283 * @q: The Event Queue to disable interrupts
284 *
285 **/
286static inline void
287lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
288{
289 struct lpfc_register doorbell;
290
291 doorbell.word0 = 0;
292 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
293 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
294 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
295 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
296 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
297 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
298}
299
300/**
James Smart4f774512009-05-22 14:52:35 -0400301 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
302 * @q: The Event Queue that the host has completed processing for.
303 * @arm: Indicates whether the host wants to arms this CQ.
304 *
305 * This routine will mark all Event Queue Entries on @q, from the last
306 * known completed entry to the last entry that was processed, as completed
307 * by clearing the valid bit for each completion queue entry. Then it will
308 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
309 * The internal host index in the @q will be updated by this routine to indicate
310 * that the host has finished processing the entries. The @arm parameter
311 * indicates that the queue should be rearmed when ringing the doorbell.
312 *
313 * This function will return the number of EQEs that were popped.
314 **/
315uint32_t
316lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
317{
318 uint32_t released = 0;
319 struct lpfc_eqe *temp_eqe;
320 struct lpfc_register doorbell;
321
James Smart2e90f4b2011-12-13 13:22:37 -0500322 /* sanity check on queue memory */
323 if (unlikely(!q))
324 return 0;
325
James Smart4f774512009-05-22 14:52:35 -0400326 /* while there are valid entries */
327 while (q->hba_index != q->host_index) {
328 temp_eqe = q->qe[q->host_index].eqe;
James Smartcb5172e2010-03-15 11:25:07 -0400329 bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
James Smart4f774512009-05-22 14:52:35 -0400330 released++;
331 q->host_index = ((q->host_index + 1) % q->entry_count);
332 }
333 if (unlikely(released == 0 && !arm))
334 return 0;
335
336 /* ring doorbell for number popped */
337 doorbell.word0 = 0;
338 if (arm) {
339 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
340 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
341 }
342 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
343 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
James Smart6b5151f2012-01-18 16:24:06 -0500344 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
345 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
346 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
James Smart4f774512009-05-22 14:52:35 -0400347 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
James Smarta747c9c2009-11-18 15:41:10 -0500348 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
349 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
350 readl(q->phba->sli4_hba.EQCQDBregaddr);
James Smart4f774512009-05-22 14:52:35 -0400351 return released;
352}
353
354/**
355 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
356 * @q: The Completion Queue to get the first valid CQE from
357 *
358 * This routine will get the first valid Completion Queue Entry from @q, update
359 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
360 * the Queue (no more work to do), or the Queue is full of CQEs that have been
361 * processed, but not popped back to the HBA then this routine will return NULL.
362 **/
363static struct lpfc_cqe *
364lpfc_sli4_cq_get(struct lpfc_queue *q)
365{
366 struct lpfc_cqe *cqe;
James Smart027140e2012-08-03 12:35:44 -0400367 uint32_t idx;
James Smart4f774512009-05-22 14:52:35 -0400368
James Smart2e90f4b2011-12-13 13:22:37 -0500369 /* sanity check on queue memory */
370 if (unlikely(!q))
371 return NULL;
372
James Smart4f774512009-05-22 14:52:35 -0400373 /* If the next CQE is not valid then we are done */
James Smartcb5172e2010-03-15 11:25:07 -0400374 if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
James Smart4f774512009-05-22 14:52:35 -0400375 return NULL;
376 /* If the host has not yet processed the next entry then we are done */
James Smart027140e2012-08-03 12:35:44 -0400377 idx = ((q->hba_index + 1) % q->entry_count);
378 if (idx == q->host_index)
James Smart4f774512009-05-22 14:52:35 -0400379 return NULL;
380
381 cqe = q->qe[q->hba_index].cqe;
James Smart027140e2012-08-03 12:35:44 -0400382 q->hba_index = idx;
James Smart27f344e2014-05-07 17:16:46 -0400383
384 /*
385 * insert barrier for instruction interlock : data from the hardware
386 * must have the valid bit checked before it can be copied and acted
387 * upon. Speculative instructions were allowing a bcopy at the start
388 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
389 * after our return, to copy data before the valid bit check above
390 * was done. As such, some of the copied data was stale. The barrier
391 * ensures the check is before any data is copied.
392 */
393 mb();
James Smart4f774512009-05-22 14:52:35 -0400394 return cqe;
395}
396
397/**
398 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
399 * @q: The Completion Queue that the host has completed processing for.
400 * @arm: Indicates whether the host wants to arms this CQ.
401 *
402 * This routine will mark all Completion queue entries on @q, from the last
403 * known completed entry to the last entry that was processed, as completed
404 * by clearing the valid bit for each completion queue entry. Then it will
405 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
406 * The internal host index in the @q will be updated by this routine to indicate
407 * that the host has finished processing the entries. The @arm parameter
408 * indicates that the queue should be rearmed when ringing the doorbell.
409 *
410 * This function will return the number of CQEs that were released.
411 **/
412uint32_t
413lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
414{
415 uint32_t released = 0;
416 struct lpfc_cqe *temp_qe;
417 struct lpfc_register doorbell;
418
James Smart2e90f4b2011-12-13 13:22:37 -0500419 /* sanity check on queue memory */
420 if (unlikely(!q))
421 return 0;
James Smart4f774512009-05-22 14:52:35 -0400422 /* while there are valid entries */
423 while (q->hba_index != q->host_index) {
424 temp_qe = q->qe[q->host_index].cqe;
James Smartcb5172e2010-03-15 11:25:07 -0400425 bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
James Smart4f774512009-05-22 14:52:35 -0400426 released++;
427 q->host_index = ((q->host_index + 1) % q->entry_count);
428 }
429 if (unlikely(released == 0 && !arm))
430 return 0;
431
432 /* ring doorbell for number popped */
433 doorbell.word0 = 0;
434 if (arm)
435 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
436 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
437 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
James Smart6b5151f2012-01-18 16:24:06 -0500438 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
439 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
440 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
James Smart4f774512009-05-22 14:52:35 -0400441 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
442 return released;
443}
444
445/**
446 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
447 * @q: The Header Receive Queue to operate on.
448 * @wqe: The Receive Queue Entry to put on the Receive queue.
449 *
450 * This routine will copy the contents of @wqe to the next available entry on
451 * the @q. This function will then ring the Receive Queue Doorbell to signal the
452 * HBA to start processing the Receive Queue Entry. This function returns the
453 * index that the rqe was copied to if successful. If no entries are available
454 * on @q then this function will return -ENOMEM.
455 * The caller is expected to hold the hbalock when calling this routine.
456 **/
457static int
458lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
459 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
460{
James Smart2e90f4b2011-12-13 13:22:37 -0500461 struct lpfc_rqe *temp_hrqe;
462 struct lpfc_rqe *temp_drqe;
James Smart4f774512009-05-22 14:52:35 -0400463 struct lpfc_register doorbell;
Wei Yongjun5a25bf32012-12-02 08:33:24 -0500464 int put_index;
James Smart4f774512009-05-22 14:52:35 -0400465
James Smart2e90f4b2011-12-13 13:22:37 -0500466 /* sanity check on queue memory */
467 if (unlikely(!hq) || unlikely(!dq))
468 return -ENOMEM;
Wei Yongjun5a25bf32012-12-02 08:33:24 -0500469 put_index = hq->host_index;
James Smart2e90f4b2011-12-13 13:22:37 -0500470 temp_hrqe = hq->qe[hq->host_index].rqe;
471 temp_drqe = dq->qe[dq->host_index].rqe;
472
James Smart4f774512009-05-22 14:52:35 -0400473 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
474 return -EINVAL;
475 if (hq->host_index != dq->host_index)
476 return -EINVAL;
477 /* If the host has not yet processed the next entry then we are done */
478 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
479 return -EBUSY;
480 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
481 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
482
483 /* Update the host index to point to the next slot */
484 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
485 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
486
487 /* Ring The Header Receive Queue Doorbell */
James Smart73d91e52011-10-10 21:32:10 -0400488 if (!(hq->host_index % hq->entry_repost)) {
James Smart4f774512009-05-22 14:52:35 -0400489 doorbell.word0 = 0;
James Smart962bc512013-01-03 15:44:00 -0500490 if (hq->db_format == LPFC_DB_RING_FORMAT) {
491 bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
492 hq->entry_repost);
493 bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
494 } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
495 bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
496 hq->entry_repost);
497 bf_set(lpfc_rq_db_list_fm_index, &doorbell,
498 hq->host_index);
499 bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
500 } else {
501 return -EINVAL;
502 }
503 writel(doorbell.word0, hq->db_regaddr);
James Smart4f774512009-05-22 14:52:35 -0400504 }
505 return put_index;
506}
507
508/**
509 * lpfc_sli4_rq_release - Updates internal hba index for RQ
510 * @q: The Header Receive Queue to operate on.
511 *
512 * This routine will update the HBA index of a queue to reflect consumption of
513 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
514 * consumed an entry the host calls this function to update the queue's
515 * internal pointers. This routine returns the number of entries that were
516 * consumed by the HBA.
517 **/
518static uint32_t
519lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
520{
James Smart2e90f4b2011-12-13 13:22:37 -0500521 /* sanity check on queue memory */
522 if (unlikely(!hq) || unlikely(!dq))
523 return 0;
524
James Smart4f774512009-05-22 14:52:35 -0400525 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
526 return 0;
527 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
528 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
529 return 1;
530}
531
James Smarte59058c2008-08-24 21:49:00 -0400532/**
James Smart3621a712009-04-06 18:47:14 -0400533 * lpfc_cmd_iocb - Get next command iocb entry in the ring
James Smarte59058c2008-08-24 21:49:00 -0400534 * @phba: Pointer to HBA context object.
535 * @pring: Pointer to driver SLI ring object.
536 *
537 * This function returns pointer to next command iocb entry
538 * in the command ring. The caller must hold hbalock to prevent
539 * other threads consume the next command iocb.
540 * SLI-2/SLI-3 provide different sized iocbs.
541 **/
James Smarted957682007-06-17 19:56:37 -0500542static inline IOCB_t *
543lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
544{
James Smart7e56aa22012-08-03 12:35:34 -0400545 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
546 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
James Smarted957682007-06-17 19:56:37 -0500547}
548
James Smarte59058c2008-08-24 21:49:00 -0400549/**
James Smart3621a712009-04-06 18:47:14 -0400550 * lpfc_resp_iocb - Get next response iocb entry in the ring
James Smarte59058c2008-08-24 21:49:00 -0400551 * @phba: Pointer to HBA context object.
552 * @pring: Pointer to driver SLI ring object.
553 *
554 * This function returns pointer to next response iocb entry
555 * in the response ring. The caller must hold hbalock to make sure
556 * that no other thread consume the next response iocb.
557 * SLI-2/SLI-3 provide different sized iocbs.
558 **/
James Smarted957682007-06-17 19:56:37 -0500559static inline IOCB_t *
560lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
561{
James Smart7e56aa22012-08-03 12:35:34 -0400562 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
563 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
James Smarted957682007-06-17 19:56:37 -0500564}
565
James Smarte59058c2008-08-24 21:49:00 -0400566/**
James Smart3621a712009-04-06 18:47:14 -0400567 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
James Smarte59058c2008-08-24 21:49:00 -0400568 * @phba: Pointer to HBA context object.
569 *
570 * This function is called with hbalock held. This function
571 * allocates a new driver iocb object from the iocb pool. If the
572 * allocation is successful, it returns pointer to the newly
573 * allocated iocb object else it returns NULL.
574 **/
James Smart4f2e66c2012-05-09 21:17:07 -0400575struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500576__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400577{
578 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
579 struct lpfc_iocbq * iocbq = NULL;
580
581 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
James Smart2a9bf3d2010-06-07 15:24:45 -0400582 if (iocbq)
583 phba->iocb_cnt++;
584 if (phba->iocb_cnt > phba->iocb_max)
585 phba->iocb_max = phba->iocb_cnt;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400586 return iocbq;
587}
588
James Smarte59058c2008-08-24 21:49:00 -0400589/**
James Smartda0436e2009-05-22 14:51:39 -0400590 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
591 * @phba: Pointer to HBA context object.
592 * @xritag: XRI value.
593 *
594 * This function clears the sglq pointer from the array of acive
595 * sglq's. The xritag that is passed in is used to index into the
596 * array. Before the xritag can be used it needs to be adjusted
597 * by subtracting the xribase.
598 *
599 * Returns sglq ponter = success, NULL = Failure.
600 **/
601static struct lpfc_sglq *
602__lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
603{
James Smartda0436e2009-05-22 14:51:39 -0400604 struct lpfc_sglq *sglq;
James Smart6d368e52011-05-24 11:44:12 -0400605
606 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
607 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
James Smartda0436e2009-05-22 14:51:39 -0400608 return sglq;
609}
610
611/**
612 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
613 * @phba: Pointer to HBA context object.
614 * @xritag: XRI value.
615 *
616 * This function returns the sglq pointer from the array of acive
617 * sglq's. The xritag that is passed in is used to index into the
618 * array. Before the xritag can be used it needs to be adjusted
619 * by subtracting the xribase.
620 *
621 * Returns sglq ponter = success, NULL = Failure.
622 **/
James Smart0f65ff62010-02-26 14:14:23 -0500623struct lpfc_sglq *
James Smartda0436e2009-05-22 14:51:39 -0400624__lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
625{
James Smartda0436e2009-05-22 14:51:39 -0400626 struct lpfc_sglq *sglq;
James Smart6d368e52011-05-24 11:44:12 -0400627
628 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
James Smartda0436e2009-05-22 14:51:39 -0400629 return sglq;
630}
631
632/**
James Smart1151e3e2011-02-16 12:39:35 -0500633 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
James Smart19ca7602010-11-20 23:11:55 -0500634 * @phba: Pointer to HBA context object.
635 * @xritag: xri used in this exchange.
636 * @rrq: The RRQ to be cleared.
637 *
James Smart19ca7602010-11-20 23:11:55 -0500638 **/
James Smart1151e3e2011-02-16 12:39:35 -0500639void
640lpfc_clr_rrq_active(struct lpfc_hba *phba,
641 uint16_t xritag,
642 struct lpfc_node_rrq *rrq)
James Smart19ca7602010-11-20 23:11:55 -0500643{
James Smart1151e3e2011-02-16 12:39:35 -0500644 struct lpfc_nodelist *ndlp = NULL;
James Smart19ca7602010-11-20 23:11:55 -0500645
James Smart1151e3e2011-02-16 12:39:35 -0500646 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
647 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -0500648
649 /* The target DID could have been swapped (cable swap)
650 * we should use the ndlp from the findnode if it is
651 * available.
652 */
James Smart1151e3e2011-02-16 12:39:35 -0500653 if ((!ndlp) && rrq->ndlp)
James Smart19ca7602010-11-20 23:11:55 -0500654 ndlp = rrq->ndlp;
655
James Smart1151e3e2011-02-16 12:39:35 -0500656 if (!ndlp)
657 goto out;
658
James Smartcff261f2013-12-17 20:29:47 -0500659 if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
James Smart19ca7602010-11-20 23:11:55 -0500660 rrq->send_rrq = 0;
661 rrq->xritag = 0;
662 rrq->rrq_stop_time = 0;
663 }
James Smart1151e3e2011-02-16 12:39:35 -0500664out:
James Smart19ca7602010-11-20 23:11:55 -0500665 mempool_free(rrq, phba->rrq_pool);
666}
667
668/**
669 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
670 * @phba: Pointer to HBA context object.
671 *
672 * This function is called with hbalock held. This function
673 * Checks if stop_time (ratov from setting rrq active) has
674 * been reached, if it has and the send_rrq flag is set then
675 * it will call lpfc_send_rrq. If the send_rrq flag is not set
676 * then it will just call the routine to clear the rrq and
677 * free the rrq resource.
678 * The timer is set to the next rrq that is going to expire before
679 * leaving the routine.
680 *
681 **/
682void
683lpfc_handle_rrq_active(struct lpfc_hba *phba)
684{
685 struct lpfc_node_rrq *rrq;
686 struct lpfc_node_rrq *nextrrq;
687 unsigned long next_time;
688 unsigned long iflags;
James Smart1151e3e2011-02-16 12:39:35 -0500689 LIST_HEAD(send_rrq);
James Smart19ca7602010-11-20 23:11:55 -0500690
691 spin_lock_irqsave(&phba->hbalock, iflags);
692 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart256ec0d2013-04-17 20:14:58 -0400693 next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
James Smart19ca7602010-11-20 23:11:55 -0500694 list_for_each_entry_safe(rrq, nextrrq,
James Smart1151e3e2011-02-16 12:39:35 -0500695 &phba->active_rrq_list, list) {
696 if (time_after(jiffies, rrq->rrq_stop_time))
697 list_move(&rrq->list, &send_rrq);
698 else if (time_before(rrq->rrq_stop_time, next_time))
James Smart19ca7602010-11-20 23:11:55 -0500699 next_time = rrq->rrq_stop_time;
700 }
701 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart06918ac2014-02-20 09:57:57 -0500702 if ((!list_empty(&phba->active_rrq_list)) &&
703 (!(phba->pport->load_flag & FC_UNLOADING)))
James Smart19ca7602010-11-20 23:11:55 -0500704 mod_timer(&phba->rrq_tmr, next_time);
James Smart1151e3e2011-02-16 12:39:35 -0500705 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
706 list_del(&rrq->list);
707 if (!rrq->send_rrq)
708 /* this call will free the rrq */
709 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
710 else if (lpfc_send_rrq(phba, rrq)) {
711 /* if we send the rrq then the completion handler
712 * will clear the bit in the xribitmap.
713 */
714 lpfc_clr_rrq_active(phba, rrq->xritag,
715 rrq);
716 }
717 }
James Smart19ca7602010-11-20 23:11:55 -0500718}
719
720/**
721 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
722 * @vport: Pointer to vport context object.
723 * @xri: The xri used in the exchange.
724 * @did: The targets DID for this exchange.
725 *
726 * returns NULL = rrq not found in the phba->active_rrq_list.
727 * rrq = rrq for this xri and target.
728 **/
729struct lpfc_node_rrq *
730lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
731{
732 struct lpfc_hba *phba = vport->phba;
733 struct lpfc_node_rrq *rrq;
734 struct lpfc_node_rrq *nextrrq;
735 unsigned long iflags;
736
737 if (phba->sli_rev != LPFC_SLI_REV4)
738 return NULL;
739 spin_lock_irqsave(&phba->hbalock, iflags);
740 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
741 if (rrq->vport == vport && rrq->xritag == xri &&
742 rrq->nlp_DID == did){
743 list_del(&rrq->list);
744 spin_unlock_irqrestore(&phba->hbalock, iflags);
745 return rrq;
746 }
747 }
748 spin_unlock_irqrestore(&phba->hbalock, iflags);
749 return NULL;
750}
751
752/**
753 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
754 * @vport: Pointer to vport context object.
James Smart1151e3e2011-02-16 12:39:35 -0500755 * @ndlp: Pointer to the lpfc_node_list structure.
756 * If ndlp is NULL Remove all active RRQs for this vport from the
757 * phba->active_rrq_list and clear the rrq.
758 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
James Smart19ca7602010-11-20 23:11:55 -0500759 **/
760void
James Smart1151e3e2011-02-16 12:39:35 -0500761lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -0500762
763{
764 struct lpfc_hba *phba = vport->phba;
765 struct lpfc_node_rrq *rrq;
766 struct lpfc_node_rrq *nextrrq;
767 unsigned long iflags;
James Smart1151e3e2011-02-16 12:39:35 -0500768 LIST_HEAD(rrq_list);
James Smart19ca7602010-11-20 23:11:55 -0500769
770 if (phba->sli_rev != LPFC_SLI_REV4)
771 return;
James Smart1151e3e2011-02-16 12:39:35 -0500772 if (!ndlp) {
773 lpfc_sli4_vport_delete_els_xri_aborted(vport);
774 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
James Smart19ca7602010-11-20 23:11:55 -0500775 }
James Smart1151e3e2011-02-16 12:39:35 -0500776 spin_lock_irqsave(&phba->hbalock, iflags);
777 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
778 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
779 list_move(&rrq->list, &rrq_list);
James Smart19ca7602010-11-20 23:11:55 -0500780 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart1151e3e2011-02-16 12:39:35 -0500781
782 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
783 list_del(&rrq->list);
784 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
785 }
James Smart19ca7602010-11-20 23:11:55 -0500786}
787
788/**
James Smart1151e3e2011-02-16 12:39:35 -0500789 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
James Smart19ca7602010-11-20 23:11:55 -0500790 * @phba: Pointer to HBA context object.
791 * @ndlp: Targets nodelist pointer for this exchange.
792 * @xritag the xri in the bitmap to test.
793 *
794 * This function is called with hbalock held. This function
795 * returns 0 = rrq not active for this xri
796 * 1 = rrq is valid for this xri.
797 **/
James Smart1151e3e2011-02-16 12:39:35 -0500798int
799lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
James Smart19ca7602010-11-20 23:11:55 -0500800 uint16_t xritag)
801{
James Smart19ca7602010-11-20 23:11:55 -0500802 if (!ndlp)
803 return 0;
James Smartcff261f2013-12-17 20:29:47 -0500804 if (!ndlp->active_rrqs_xri_bitmap)
805 return 0;
806 if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
James Smart19ca7602010-11-20 23:11:55 -0500807 return 1;
808 else
809 return 0;
810}
811
812/**
813 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
814 * @phba: Pointer to HBA context object.
815 * @ndlp: nodelist pointer for this target.
816 * @xritag: xri used in this exchange.
817 * @rxid: Remote Exchange ID.
818 * @send_rrq: Flag used to determine if we should send rrq els cmd.
819 *
820 * This function takes the hbalock.
821 * The active bit is always set in the active rrq xri_bitmap even
822 * if there is no slot avaiable for the other rrq information.
823 *
824 * returns 0 rrq actived for this xri
825 * < 0 No memory or invalid ndlp.
826 **/
827int
828lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
James Smartb42c07c2012-01-18 16:25:55 -0500829 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
James Smart19ca7602010-11-20 23:11:55 -0500830{
James Smart19ca7602010-11-20 23:11:55 -0500831 unsigned long iflags;
James Smartb42c07c2012-01-18 16:25:55 -0500832 struct lpfc_node_rrq *rrq;
833 int empty;
834
835 if (!ndlp)
836 return -EINVAL;
837
838 if (!phba->cfg_enable_rrq)
839 return -EINVAL;
James Smart19ca7602010-11-20 23:11:55 -0500840
841 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartb42c07c2012-01-18 16:25:55 -0500842 if (phba->pport->load_flag & FC_UNLOADING) {
843 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
844 goto out;
845 }
846
847 /*
848 * set the active bit even if there is no mem available.
849 */
850 if (NLP_CHK_FREE_REQ(ndlp))
851 goto out;
852
853 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
854 goto out;
855
James Smartcff261f2013-12-17 20:29:47 -0500856 if (!ndlp->active_rrqs_xri_bitmap)
857 goto out;
858
859 if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
James Smartb42c07c2012-01-18 16:25:55 -0500860 goto out;
861
James Smart19ca7602010-11-20 23:11:55 -0500862 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smartb42c07c2012-01-18 16:25:55 -0500863 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
864 if (!rrq) {
865 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
866 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
867 " DID:0x%x Send:%d\n",
868 xritag, rxid, ndlp->nlp_DID, send_rrq);
869 return -EINVAL;
870 }
James Smarte5771b42013-03-01 16:37:14 -0500871 if (phba->cfg_enable_rrq == 1)
872 rrq->send_rrq = send_rrq;
873 else
874 rrq->send_rrq = 0;
James Smartb42c07c2012-01-18 16:25:55 -0500875 rrq->xritag = xritag;
James Smart256ec0d2013-04-17 20:14:58 -0400876 rrq->rrq_stop_time = jiffies +
877 msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
James Smartb42c07c2012-01-18 16:25:55 -0500878 rrq->ndlp = ndlp;
879 rrq->nlp_DID = ndlp->nlp_DID;
880 rrq->vport = ndlp->vport;
881 rrq->rxid = rxid;
James Smartb42c07c2012-01-18 16:25:55 -0500882 spin_lock_irqsave(&phba->hbalock, iflags);
883 empty = list_empty(&phba->active_rrq_list);
884 list_add_tail(&rrq->list, &phba->active_rrq_list);
885 phba->hba_flag |= HBA_RRQ_ACTIVE;
886 if (empty)
887 lpfc_worker_wake_up(phba);
888 spin_unlock_irqrestore(&phba->hbalock, iflags);
889 return 0;
890out:
891 spin_unlock_irqrestore(&phba->hbalock, iflags);
892 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
893 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
894 " DID:0x%x Send:%d\n",
895 xritag, rxid, ndlp->nlp_DID, send_rrq);
896 return -EINVAL;
James Smart19ca7602010-11-20 23:11:55 -0500897}
898
899/**
James Smartda0436e2009-05-22 14:51:39 -0400900 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
901 * @phba: Pointer to HBA context object.
James Smart19ca7602010-11-20 23:11:55 -0500902 * @piocb: Pointer to the iocbq.
James Smartda0436e2009-05-22 14:51:39 -0400903 *
James Smartdafe8ce2014-09-03 12:56:40 -0400904 * This function is called with the ring lock held. This function
James Smart6d368e52011-05-24 11:44:12 -0400905 * gets a new driver sglq object from the sglq list. If the
James Smartda0436e2009-05-22 14:51:39 -0400906 * list is not empty then it is successful, it returns pointer to the newly
907 * allocated sglq object else it returns NULL.
908 **/
909static struct lpfc_sglq *
James Smart19ca7602010-11-20 23:11:55 -0500910__lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
James Smartda0436e2009-05-22 14:51:39 -0400911{
912 struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
913 struct lpfc_sglq *sglq = NULL;
James Smart19ca7602010-11-20 23:11:55 -0500914 struct lpfc_sglq *start_sglq = NULL;
James Smart19ca7602010-11-20 23:11:55 -0500915 struct lpfc_scsi_buf *lpfc_cmd;
916 struct lpfc_nodelist *ndlp;
917 int found = 0;
918
919 if (piocbq->iocb_flag & LPFC_IO_FCP) {
920 lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
921 ndlp = lpfc_cmd->rdata->pnode;
James Smartbe858b62010-12-15 17:57:20 -0500922 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
923 !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
James Smart19ca7602010-11-20 23:11:55 -0500924 ndlp = piocbq->context_un.ndlp;
James Smartd5ce53b2013-04-17 20:17:26 -0400925 else if (piocbq->iocb_flag & LPFC_IO_LIBDFC)
James Smart93d1379e2012-05-09 21:19:34 -0400926 ndlp = piocbq->context_un.ndlp;
James Smart19ca7602010-11-20 23:11:55 -0500927 else
928 ndlp = piocbq->context1;
929
James Smartda0436e2009-05-22 14:51:39 -0400930 list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
James Smart19ca7602010-11-20 23:11:55 -0500931 start_sglq = sglq;
932 while (!found) {
933 if (!sglq)
934 return NULL;
James Smartee0f4fe2012-05-09 21:19:14 -0400935 if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
James Smart19ca7602010-11-20 23:11:55 -0500936 /* This xri has an rrq outstanding for this DID.
937 * put it back in the list and get another xri.
938 */
939 list_add_tail(&sglq->list, lpfc_sgl_list);
940 sglq = NULL;
941 list_remove_head(lpfc_sgl_list, sglq,
942 struct lpfc_sglq, list);
943 if (sglq == start_sglq) {
944 sglq = NULL;
945 break;
946 } else
947 continue;
948 }
949 sglq->ndlp = ndlp;
950 found = 1;
James Smart6d368e52011-05-24 11:44:12 -0400951 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
James Smart19ca7602010-11-20 23:11:55 -0500952 sglq->state = SGL_ALLOCATED;
953 }
James Smartda0436e2009-05-22 14:51:39 -0400954 return sglq;
955}
956
957/**
James Smart3621a712009-04-06 18:47:14 -0400958 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
James Smarte59058c2008-08-24 21:49:00 -0400959 * @phba: Pointer to HBA context object.
960 *
961 * This function is called with no lock held. This function
962 * allocates a new driver iocb object from the iocb pool. If the
963 * allocation is successful, it returns pointer to the newly
964 * allocated iocb object else it returns NULL.
965 **/
James Smart2e0fef82007-06-17 19:56:36 -0500966struct lpfc_iocbq *
967lpfc_sli_get_iocbq(struct lpfc_hba *phba)
James Bottomley604a3e32005-10-29 10:28:33 -0500968{
James Smart2e0fef82007-06-17 19:56:36 -0500969 struct lpfc_iocbq * iocbq = NULL;
970 unsigned long iflags;
971
972 spin_lock_irqsave(&phba->hbalock, iflags);
973 iocbq = __lpfc_sli_get_iocbq(phba);
974 spin_unlock_irqrestore(&phba->hbalock, iflags);
975 return iocbq;
976}
977
James Smarte59058c2008-08-24 21:49:00 -0400978/**
James Smart4f774512009-05-22 14:52:35 -0400979 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
980 * @phba: Pointer to HBA context object.
981 * @iocbq: Pointer to driver iocb object.
982 *
983 * This function is called with hbalock held to release driver
984 * iocb object to the iocb pool. The iotag in the iocb object
985 * does not change for each use of the iocb object. This function
986 * clears all other fields of the iocb object when it is freed.
987 * The sqlq structure that holds the xritag and phys and virtual
988 * mappings for the scatter gather list is retrieved from the
989 * active array of sglq. The get of the sglq pointer also clears
990 * the entry in the array. If the status of the IO indiactes that
991 * this IO was aborted then the sglq entry it put on the
992 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
993 * IO has good status or fails for any other reason then the sglq
994 * entry is added to the free list (lpfc_sgl_list).
995 **/
996static void
997__lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
998{
999 struct lpfc_sglq *sglq;
1000 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
James Smart2a9bf3d2010-06-07 15:24:45 -04001001 unsigned long iflag = 0;
1002 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart4f774512009-05-22 14:52:35 -04001003
1004 if (iocbq->sli4_xritag == NO_XRI)
1005 sglq = NULL;
1006 else
James Smart6d368e52011-05-24 11:44:12 -04001007 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
1008
James Smart0e9bb8d2013-03-01 16:35:12 -05001009
James Smart4f774512009-05-22 14:52:35 -04001010 if (sglq) {
James Smart0f65ff62010-02-26 14:14:23 -05001011 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
1012 (sglq->state != SGL_XRI_ABORTED)) {
James Smart4f774512009-05-22 14:52:35 -04001013 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
1014 iflag);
1015 list_add(&sglq->list,
1016 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1017 spin_unlock_irqrestore(
1018 &phba->sli4_hba.abts_sgl_list_lock, iflag);
James Smart0f65ff62010-02-26 14:14:23 -05001019 } else {
James Smartdafe8ce2014-09-03 12:56:40 -04001020 spin_lock_irqsave(&pring->ring_lock, iflag);
James Smart0f65ff62010-02-26 14:14:23 -05001021 sglq->state = SGL_FREED;
James Smart19ca7602010-11-20 23:11:55 -05001022 sglq->ndlp = NULL;
James Smartfedd3b72011-02-16 12:39:24 -05001023 list_add_tail(&sglq->list,
1024 &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04001025 spin_unlock_irqrestore(&pring->ring_lock, iflag);
James Smart2a9bf3d2010-06-07 15:24:45 -04001026
1027 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05001028 if (!list_empty(&pring->txq))
James Smart2a9bf3d2010-06-07 15:24:45 -04001029 lpfc_worker_wake_up(phba);
James Smart0f65ff62010-02-26 14:14:23 -05001030 }
James Smart4f774512009-05-22 14:52:35 -04001031 }
1032
1033
1034 /*
1035 * Clean all volatile data fields, preserve iotag and node struct.
1036 */
1037 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
James Smart6d368e52011-05-24 11:44:12 -04001038 iocbq->sli4_lxritag = NO_XRI;
James Smart4f774512009-05-22 14:52:35 -04001039 iocbq->sli4_xritag = NO_XRI;
1040 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1041}
1042
James Smart2a9bf3d2010-06-07 15:24:45 -04001043
James Smart4f774512009-05-22 14:52:35 -04001044/**
James Smart3772a992009-05-22 14:50:54 -04001045 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1046 * @phba: Pointer to HBA context object.
1047 * @iocbq: Pointer to driver iocb object.
1048 *
1049 * This function is called with hbalock held to release driver
1050 * iocb object to the iocb pool. The iotag in the iocb object
1051 * does not change for each use of the iocb object. This function
1052 * clears all other fields of the iocb object when it is freed.
1053 **/
1054static void
1055__lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1056{
1057 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1058
James Smart0e9bb8d2013-03-01 16:35:12 -05001059
1060 /*
James Smart3772a992009-05-22 14:50:54 -04001061 * Clean all volatile data fields, preserve iotag and node struct.
1062 */
1063 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1064 iocbq->sli4_xritag = NO_XRI;
1065 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1066}
1067
1068/**
James Smart3621a712009-04-06 18:47:14 -04001069 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
James Smarte59058c2008-08-24 21:49:00 -04001070 * @phba: Pointer to HBA context object.
1071 * @iocbq: Pointer to driver iocb object.
1072 *
1073 * This function is called with hbalock held to release driver
1074 * iocb object to the iocb pool. The iotag in the iocb object
1075 * does not change for each use of the iocb object. This function
1076 * clears all other fields of the iocb object when it is freed.
1077 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001078static void
James Smart2e0fef82007-06-17 19:56:36 -05001079__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1080{
James Smart3772a992009-05-22 14:50:54 -04001081 phba->__lpfc_sli_release_iocbq(phba, iocbq);
James Smart2a9bf3d2010-06-07 15:24:45 -04001082 phba->iocb_cnt--;
James Bottomley604a3e32005-10-29 10:28:33 -05001083}
1084
James Smarte59058c2008-08-24 21:49:00 -04001085/**
James Smart3621a712009-04-06 18:47:14 -04001086 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
James Smarte59058c2008-08-24 21:49:00 -04001087 * @phba: Pointer to HBA context object.
1088 * @iocbq: Pointer to driver iocb object.
1089 *
1090 * This function is called with no lock held to release the iocb to
1091 * iocb pool.
1092 **/
James Smart2e0fef82007-06-17 19:56:36 -05001093void
1094lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1095{
1096 unsigned long iflags;
1097
1098 /*
1099 * Clean all volatile data fields, preserve iotag and node struct.
1100 */
1101 spin_lock_irqsave(&phba->hbalock, iflags);
1102 __lpfc_sli_release_iocbq(phba, iocbq);
1103 spin_unlock_irqrestore(&phba->hbalock, iflags);
1104}
1105
James Smarte59058c2008-08-24 21:49:00 -04001106/**
James Smarta257bf92009-04-06 18:48:10 -04001107 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1108 * @phba: Pointer to HBA context object.
1109 * @iocblist: List of IOCBs.
1110 * @ulpstatus: ULP status in IOCB command field.
1111 * @ulpWord4: ULP word-4 in IOCB command field.
1112 *
1113 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1114 * on the list by invoking the complete callback function associated with the
1115 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1116 * fields.
1117 **/
1118void
1119lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1120 uint32_t ulpstatus, uint32_t ulpWord4)
1121{
1122 struct lpfc_iocbq *piocb;
1123
1124 while (!list_empty(iocblist)) {
1125 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
James Smarta257bf92009-04-06 18:48:10 -04001126 if (!piocb->iocb_cmpl)
1127 lpfc_sli_release_iocbq(phba, piocb);
1128 else {
1129 piocb->iocb.ulpStatus = ulpstatus;
1130 piocb->iocb.un.ulpWord[4] = ulpWord4;
1131 (piocb->iocb_cmpl) (phba, piocb, piocb);
1132 }
1133 }
1134 return;
1135}
1136
1137/**
James Smart3621a712009-04-06 18:47:14 -04001138 * lpfc_sli_iocb_cmd_type - Get the iocb type
1139 * @iocb_cmnd: iocb command code.
James Smarte59058c2008-08-24 21:49:00 -04001140 *
1141 * This function is called by ring event handler function to get the iocb type.
1142 * This function translates the iocb command to an iocb command type used to
1143 * decide the final disposition of each completed IOCB.
1144 * The function returns
1145 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1146 * LPFC_SOL_IOCB if it is a solicited iocb completion
1147 * LPFC_ABORT_IOCB if it is an abort iocb
1148 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1149 *
1150 * The caller is not required to hold any lock.
1151 **/
dea31012005-04-17 16:05:31 -05001152static lpfc_iocb_type
1153lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1154{
1155 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1156
1157 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1158 return 0;
1159
1160 switch (iocb_cmnd) {
1161 case CMD_XMIT_SEQUENCE_CR:
1162 case CMD_XMIT_SEQUENCE_CX:
1163 case CMD_XMIT_BCAST_CN:
1164 case CMD_XMIT_BCAST_CX:
1165 case CMD_ELS_REQUEST_CR:
1166 case CMD_ELS_REQUEST_CX:
1167 case CMD_CREATE_XRI_CR:
1168 case CMD_CREATE_XRI_CX:
1169 case CMD_GET_RPI_CN:
1170 case CMD_XMIT_ELS_RSP_CX:
1171 case CMD_GET_RPI_CR:
1172 case CMD_FCP_IWRITE_CR:
1173 case CMD_FCP_IWRITE_CX:
1174 case CMD_FCP_IREAD_CR:
1175 case CMD_FCP_IREAD_CX:
1176 case CMD_FCP_ICMND_CR:
1177 case CMD_FCP_ICMND_CX:
James Smartf5603512006-12-02 13:35:43 -05001178 case CMD_FCP_TSEND_CX:
1179 case CMD_FCP_TRSP_CX:
1180 case CMD_FCP_TRECEIVE_CX:
1181 case CMD_FCP_AUTO_TRSP_CX:
dea31012005-04-17 16:05:31 -05001182 case CMD_ADAPTER_MSG:
1183 case CMD_ADAPTER_DUMP:
1184 case CMD_XMIT_SEQUENCE64_CR:
1185 case CMD_XMIT_SEQUENCE64_CX:
1186 case CMD_XMIT_BCAST64_CN:
1187 case CMD_XMIT_BCAST64_CX:
1188 case CMD_ELS_REQUEST64_CR:
1189 case CMD_ELS_REQUEST64_CX:
1190 case CMD_FCP_IWRITE64_CR:
1191 case CMD_FCP_IWRITE64_CX:
1192 case CMD_FCP_IREAD64_CR:
1193 case CMD_FCP_IREAD64_CX:
1194 case CMD_FCP_ICMND64_CR:
1195 case CMD_FCP_ICMND64_CX:
James Smartf5603512006-12-02 13:35:43 -05001196 case CMD_FCP_TSEND64_CX:
1197 case CMD_FCP_TRSP64_CX:
1198 case CMD_FCP_TRECEIVE64_CX:
dea31012005-04-17 16:05:31 -05001199 case CMD_GEN_REQUEST64_CR:
1200 case CMD_GEN_REQUEST64_CX:
1201 case CMD_XMIT_ELS_RSP64_CX:
James Smartda0436e2009-05-22 14:51:39 -04001202 case DSSCMD_IWRITE64_CR:
1203 case DSSCMD_IWRITE64_CX:
1204 case DSSCMD_IREAD64_CR:
1205 case DSSCMD_IREAD64_CX:
dea31012005-04-17 16:05:31 -05001206 type = LPFC_SOL_IOCB;
1207 break;
1208 case CMD_ABORT_XRI_CN:
1209 case CMD_ABORT_XRI_CX:
1210 case CMD_CLOSE_XRI_CN:
1211 case CMD_CLOSE_XRI_CX:
1212 case CMD_XRI_ABORTED_CX:
1213 case CMD_ABORT_MXRI64_CN:
James Smart6669f9b2009-10-02 15:16:45 -04001214 case CMD_XMIT_BLS_RSP64_CX:
dea31012005-04-17 16:05:31 -05001215 type = LPFC_ABORT_IOCB;
1216 break;
1217 case CMD_RCV_SEQUENCE_CX:
1218 case CMD_RCV_ELS_REQ_CX:
1219 case CMD_RCV_SEQUENCE64_CX:
1220 case CMD_RCV_ELS_REQ64_CX:
James Smart57127f12007-10-27 13:37:05 -04001221 case CMD_ASYNC_STATUS:
James Smarted957682007-06-17 19:56:37 -05001222 case CMD_IOCB_RCV_SEQ64_CX:
1223 case CMD_IOCB_RCV_ELS64_CX:
1224 case CMD_IOCB_RCV_CONT64_CX:
James Smart3163f722008-02-08 18:50:25 -05001225 case CMD_IOCB_RET_XRI64_CX:
dea31012005-04-17 16:05:31 -05001226 type = LPFC_UNSOL_IOCB;
1227 break;
James Smart3163f722008-02-08 18:50:25 -05001228 case CMD_IOCB_XMIT_MSEQ64_CR:
1229 case CMD_IOCB_XMIT_MSEQ64_CX:
1230 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1231 case CMD_IOCB_RCV_ELS_LIST64_CX:
1232 case CMD_IOCB_CLOSE_EXTENDED_CN:
1233 case CMD_IOCB_ABORT_EXTENDED_CN:
1234 case CMD_IOCB_RET_HBQE64_CN:
1235 case CMD_IOCB_FCP_IBIDIR64_CR:
1236 case CMD_IOCB_FCP_IBIDIR64_CX:
1237 case CMD_IOCB_FCP_ITASKMGT64_CX:
1238 case CMD_IOCB_LOGENTRY_CN:
1239 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1240 printk("%s - Unhandled SLI-3 Command x%x\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07001241 __func__, iocb_cmnd);
James Smart3163f722008-02-08 18:50:25 -05001242 type = LPFC_UNKNOWN_IOCB;
1243 break;
dea31012005-04-17 16:05:31 -05001244 default:
1245 type = LPFC_UNKNOWN_IOCB;
1246 break;
1247 }
1248
1249 return type;
1250}
1251
James Smarte59058c2008-08-24 21:49:00 -04001252/**
James Smart3621a712009-04-06 18:47:14 -04001253 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
James Smarte59058c2008-08-24 21:49:00 -04001254 * @phba: Pointer to HBA context object.
1255 *
1256 * This function is called from SLI initialization code
1257 * to configure every ring of the HBA's SLI interface. The
1258 * caller is not required to hold any lock. This function issues
1259 * a config_ring mailbox command for each ring.
1260 * This function returns zero if successful else returns a negative
1261 * error code.
1262 **/
dea31012005-04-17 16:05:31 -05001263static int
James Smarted957682007-06-17 19:56:37 -05001264lpfc_sli_ring_map(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001265{
1266 struct lpfc_sli *psli = &phba->sli;
James Smarted957682007-06-17 19:56:37 -05001267 LPFC_MBOXQ_t *pmb;
1268 MAILBOX_t *pmbox;
1269 int i, rc, ret = 0;
dea31012005-04-17 16:05:31 -05001270
James Smarted957682007-06-17 19:56:37 -05001271 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1272 if (!pmb)
1273 return -ENOMEM;
James Smart04c68492009-05-22 14:52:52 -04001274 pmbox = &pmb->u.mb;
James Smarted957682007-06-17 19:56:37 -05001275 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -05001276 for (i = 0; i < psli->num_rings; i++) {
dea31012005-04-17 16:05:31 -05001277 lpfc_config_ring(phba, i, pmb);
1278 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1279 if (rc != MBX_SUCCESS) {
James Smart92d7f7b2007-06-17 19:56:38 -05001280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001281 "0446 Adapter failed to init (%d), "
dea31012005-04-17 16:05:31 -05001282 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1283 "ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04001284 rc, pmbox->mbxCommand,
1285 pmbox->mbxStatus, i);
James Smart2e0fef82007-06-17 19:56:36 -05001286 phba->link_state = LPFC_HBA_ERROR;
James Smarted957682007-06-17 19:56:37 -05001287 ret = -ENXIO;
1288 break;
dea31012005-04-17 16:05:31 -05001289 }
1290 }
James Smarted957682007-06-17 19:56:37 -05001291 mempool_free(pmb, phba->mbox_mem_pool);
1292 return ret;
dea31012005-04-17 16:05:31 -05001293}
1294
James Smarte59058c2008-08-24 21:49:00 -04001295/**
James Smart3621a712009-04-06 18:47:14 -04001296 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
James Smarte59058c2008-08-24 21:49:00 -04001297 * @phba: Pointer to HBA context object.
1298 * @pring: Pointer to driver SLI ring object.
1299 * @piocb: Pointer to the driver iocb object.
1300 *
1301 * This function is called with hbalock held. The function adds the
1302 * new iocb to txcmplq of the given ring. This function always returns
1303 * 0. If this function is called for ELS ring, this function checks if
1304 * there is a vport associated with the ELS command. This function also
1305 * starts els_tmofunc timer if this is an ELS command.
1306 **/
dea31012005-04-17 16:05:31 -05001307static int
James Smart2e0fef82007-06-17 19:56:36 -05001308lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1309 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -05001310{
dea31012005-04-17 16:05:31 -05001311 list_add_tail(&piocb->list, &pring->txcmplq);
James Smart4f2e66c2012-05-09 21:17:07 -04001312 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
James Smart2a9bf3d2010-06-07 15:24:45 -04001313
James Smart92d7f7b2007-06-17 19:56:38 -05001314 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1315 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
James Smart06918ac2014-02-20 09:57:57 -05001316 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN) &&
1317 (!(piocb->vport->load_flag & FC_UNLOADING))) {
James Smart92d7f7b2007-06-17 19:56:38 -05001318 if (!piocb->vport)
1319 BUG();
1320 else
1321 mod_timer(&piocb->vport->els_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001322 jiffies +
1323 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
James Smart92d7f7b2007-06-17 19:56:38 -05001324 }
1325
dea31012005-04-17 16:05:31 -05001326
James Smart2e0fef82007-06-17 19:56:36 -05001327 return 0;
dea31012005-04-17 16:05:31 -05001328}
1329
James Smarte59058c2008-08-24 21:49:00 -04001330/**
James Smart3621a712009-04-06 18:47:14 -04001331 * lpfc_sli_ringtx_get - Get first element of the txq
James Smarte59058c2008-08-24 21:49:00 -04001332 * @phba: Pointer to HBA context object.
1333 * @pring: Pointer to driver SLI ring object.
1334 *
1335 * This function is called with hbalock held to get next
1336 * iocb in txq of the given ring. If there is any iocb in
1337 * the txq, the function returns first iocb in the list after
1338 * removing the iocb from the list, else it returns NULL.
1339 **/
James Smart2a9bf3d2010-06-07 15:24:45 -04001340struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -05001341lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -05001342{
dea31012005-04-17 16:05:31 -05001343 struct lpfc_iocbq *cmd_iocb;
1344
James Smart858c9f62007-06-17 19:56:39 -05001345 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
James Smart2e0fef82007-06-17 19:56:36 -05001346 return cmd_iocb;
dea31012005-04-17 16:05:31 -05001347}
1348
James Smarte59058c2008-08-24 21:49:00 -04001349/**
James Smart3621a712009-04-06 18:47:14 -04001350 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
James Smarte59058c2008-08-24 21:49:00 -04001351 * @phba: Pointer to HBA context object.
1352 * @pring: Pointer to driver SLI ring object.
1353 *
1354 * This function is called with hbalock held and the caller must post the
1355 * iocb without releasing the lock. If the caller releases the lock,
1356 * iocb slot returned by the function is not guaranteed to be available.
1357 * The function returns pointer to the next available iocb slot if there
1358 * is available slot in the ring, else it returns NULL.
1359 * If the get index of the ring is ahead of the put index, the function
1360 * will post an error attention event to the worker thread to take the
1361 * HBA to offline state.
1362 **/
dea31012005-04-17 16:05:31 -05001363static IOCB_t *
1364lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1365{
James Smart34b02dc2008-08-24 21:49:55 -04001366 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
James Smart7e56aa22012-08-03 12:35:34 -04001367 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
1368 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
1369 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
1370 pring->sli.sli3.next_cmdidx = 0;
dea31012005-04-17 16:05:31 -05001371
James Smart7e56aa22012-08-03 12:35:34 -04001372 if (unlikely(pring->sli.sli3.local_getidx ==
1373 pring->sli.sli3.next_cmdidx)) {
dea31012005-04-17 16:05:31 -05001374
James Smart7e56aa22012-08-03 12:35:34 -04001375 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
dea31012005-04-17 16:05:31 -05001376
James Smart7e56aa22012-08-03 12:35:34 -04001377 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
dea31012005-04-17 16:05:31 -05001378 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001379 "0315 Ring %d issue: portCmdGet %d "
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001380 "is bigger than cmd ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04001381 pring->ringno,
James Smart7e56aa22012-08-03 12:35:34 -04001382 pring->sli.sli3.local_getidx,
1383 max_cmd_idx);
dea31012005-04-17 16:05:31 -05001384
James Smart2e0fef82007-06-17 19:56:36 -05001385 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001386 /*
1387 * All error attention handlers are posted to
1388 * worker thread
1389 */
1390 phba->work_ha |= HA_ERATT;
1391 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -05001392
James Smart5e9d9b82008-06-14 22:52:53 -04001393 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001394
1395 return NULL;
1396 }
1397
James Smart7e56aa22012-08-03 12:35:34 -04001398 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
dea31012005-04-17 16:05:31 -05001399 return NULL;
1400 }
1401
James Smarted957682007-06-17 19:56:37 -05001402 return lpfc_cmd_iocb(phba, pring);
dea31012005-04-17 16:05:31 -05001403}
1404
James Smarte59058c2008-08-24 21:49:00 -04001405/**
James Smart3621a712009-04-06 18:47:14 -04001406 * lpfc_sli_next_iotag - Get an iotag for the iocb
James Smarte59058c2008-08-24 21:49:00 -04001407 * @phba: Pointer to HBA context object.
1408 * @iocbq: Pointer to driver iocb object.
1409 *
1410 * This function gets an iotag for the iocb. If there is no unused iotag and
1411 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1412 * array and assigns a new iotag.
1413 * The function returns the allocated iotag if successful, else returns zero.
1414 * Zero is not a valid iotag.
1415 * The caller is not required to hold any lock.
1416 **/
James Bottomley604a3e32005-10-29 10:28:33 -05001417uint16_t
James Smart2e0fef82007-06-17 19:56:36 -05001418lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
dea31012005-04-17 16:05:31 -05001419{
James Smart2e0fef82007-06-17 19:56:36 -05001420 struct lpfc_iocbq **new_arr;
1421 struct lpfc_iocbq **old_arr;
James Bottomley604a3e32005-10-29 10:28:33 -05001422 size_t new_len;
1423 struct lpfc_sli *psli = &phba->sli;
1424 uint16_t iotag;
dea31012005-04-17 16:05:31 -05001425
James Smart2e0fef82007-06-17 19:56:36 -05001426 spin_lock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -05001427 iotag = psli->last_iotag;
1428 if(++iotag < psli->iocbq_lookup_len) {
1429 psli->last_iotag = iotag;
1430 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -05001431 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -05001432 iocbq->iotag = iotag;
1433 return iotag;
James Smart2e0fef82007-06-17 19:56:36 -05001434 } else if (psli->iocbq_lookup_len < (0xffff
James Bottomley604a3e32005-10-29 10:28:33 -05001435 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1436 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
James Smart2e0fef82007-06-17 19:56:36 -05001437 spin_unlock_irq(&phba->hbalock);
1438 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
James Bottomley604a3e32005-10-29 10:28:33 -05001439 GFP_KERNEL);
1440 if (new_arr) {
James Smart2e0fef82007-06-17 19:56:36 -05001441 spin_lock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -05001442 old_arr = psli->iocbq_lookup;
1443 if (new_len <= psli->iocbq_lookup_len) {
1444 /* highly unprobable case */
1445 kfree(new_arr);
1446 iotag = psli->last_iotag;
1447 if(++iotag < psli->iocbq_lookup_len) {
1448 psli->last_iotag = iotag;
1449 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -05001450 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -05001451 iocbq->iotag = iotag;
1452 return iotag;
1453 }
James Smart2e0fef82007-06-17 19:56:36 -05001454 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -05001455 return 0;
1456 }
1457 if (psli->iocbq_lookup)
1458 memcpy(new_arr, old_arr,
1459 ((psli->last_iotag + 1) *
James Smart311464e2007-08-02 11:10:37 -04001460 sizeof (struct lpfc_iocbq *)));
James Bottomley604a3e32005-10-29 10:28:33 -05001461 psli->iocbq_lookup = new_arr;
1462 psli->iocbq_lookup_len = new_len;
1463 psli->last_iotag = iotag;
1464 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -05001465 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -05001466 iocbq->iotag = iotag;
1467 kfree(old_arr);
1468 return iotag;
1469 }
James Smart8f6d98d2006-08-01 07:34:00 -04001470 } else
James Smart2e0fef82007-06-17 19:56:36 -05001471 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001472
James Smartbc739052010-08-04 16:11:18 -04001473 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001474 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1475 psli->last_iotag);
dea31012005-04-17 16:05:31 -05001476
James Bottomley604a3e32005-10-29 10:28:33 -05001477 return 0;
dea31012005-04-17 16:05:31 -05001478}
1479
James Smarte59058c2008-08-24 21:49:00 -04001480/**
James Smart3621a712009-04-06 18:47:14 -04001481 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
James Smarte59058c2008-08-24 21:49:00 -04001482 * @phba: Pointer to HBA context object.
1483 * @pring: Pointer to driver SLI ring object.
1484 * @iocb: Pointer to iocb slot in the ring.
1485 * @nextiocb: Pointer to driver iocb object which need to be
1486 * posted to firmware.
1487 *
1488 * This function is called with hbalock held to post a new iocb to
1489 * the firmware. This function copies the new iocb to ring iocb slot and
1490 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1491 * a completion call back for this iocb else the function will free the
1492 * iocb object.
1493 **/
dea31012005-04-17 16:05:31 -05001494static void
1495lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1496 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1497{
1498 /*
James Bottomley604a3e32005-10-29 10:28:33 -05001499 * Set up an iotag
dea31012005-04-17 16:05:31 -05001500 */
James Bottomley604a3e32005-10-29 10:28:33 -05001501 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
dea31012005-04-17 16:05:31 -05001502
James Smarte2a0a9d2008-12-04 22:40:02 -05001503
James Smarta58cbd52007-08-02 11:09:43 -04001504 if (pring->ringno == LPFC_ELS_RING) {
1505 lpfc_debugfs_slow_ring_trc(phba,
1506 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1507 *(((uint32_t *) &nextiocb->iocb) + 4),
1508 *(((uint32_t *) &nextiocb->iocb) + 6),
1509 *(((uint32_t *) &nextiocb->iocb) + 7));
1510 }
1511
dea31012005-04-17 16:05:31 -05001512 /*
1513 * Issue iocb command to adapter
1514 */
James Smart92d7f7b2007-06-17 19:56:38 -05001515 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
dea31012005-04-17 16:05:31 -05001516 wmb();
1517 pring->stats.iocb_cmd++;
1518
1519 /*
1520 * If there is no completion routine to call, we can release the
1521 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1522 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1523 */
1524 if (nextiocb->iocb_cmpl)
1525 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
James Bottomley604a3e32005-10-29 10:28:33 -05001526 else
James Smart2e0fef82007-06-17 19:56:36 -05001527 __lpfc_sli_release_iocbq(phba, nextiocb);
dea31012005-04-17 16:05:31 -05001528
1529 /*
1530 * Let the HBA know what IOCB slot will be the next one the
1531 * driver will put a command into.
1532 */
James Smart7e56aa22012-08-03 12:35:34 -04001533 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
1534 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
dea31012005-04-17 16:05:31 -05001535}
1536
James Smarte59058c2008-08-24 21:49:00 -04001537/**
James Smart3621a712009-04-06 18:47:14 -04001538 * lpfc_sli_update_full_ring - Update the chip attention register
James Smarte59058c2008-08-24 21:49:00 -04001539 * @phba: Pointer to HBA context object.
1540 * @pring: Pointer to driver SLI ring object.
1541 *
1542 * The caller is not required to hold any lock for calling this function.
1543 * This function updates the chip attention bits for the ring to inform firmware
1544 * that there are pending work to be done for this ring and requests an
1545 * interrupt when there is space available in the ring. This function is
1546 * called when the driver is unable to post more iocbs to the ring due
1547 * to unavailability of space in the ring.
1548 **/
dea31012005-04-17 16:05:31 -05001549static void
James Smart2e0fef82007-06-17 19:56:36 -05001550lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -05001551{
1552 int ringno = pring->ringno;
1553
1554 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1555
1556 wmb();
1557
1558 /*
1559 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1560 * The HBA will tell us when an IOCB entry is available.
1561 */
1562 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1563 readl(phba->CAregaddr); /* flush */
1564
1565 pring->stats.iocb_cmd_full++;
1566}
1567
James Smarte59058c2008-08-24 21:49:00 -04001568/**
James Smart3621a712009-04-06 18:47:14 -04001569 * lpfc_sli_update_ring - Update chip attention register
James Smarte59058c2008-08-24 21:49:00 -04001570 * @phba: Pointer to HBA context object.
1571 * @pring: Pointer to driver SLI ring object.
1572 *
1573 * This function updates the chip attention register bit for the
1574 * given ring to inform HBA that there is more work to be done
1575 * in this ring. The caller is not required to hold any lock.
1576 **/
dea31012005-04-17 16:05:31 -05001577static void
James Smart2e0fef82007-06-17 19:56:36 -05001578lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -05001579{
1580 int ringno = pring->ringno;
1581
1582 /*
1583 * Tell the HBA that there is work to do in this ring.
1584 */
James Smart34b02dc2008-08-24 21:49:55 -04001585 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1586 wmb();
1587 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1588 readl(phba->CAregaddr); /* flush */
1589 }
dea31012005-04-17 16:05:31 -05001590}
1591
James Smarte59058c2008-08-24 21:49:00 -04001592/**
James Smart3621a712009-04-06 18:47:14 -04001593 * lpfc_sli_resume_iocb - Process iocbs in the txq
James Smarte59058c2008-08-24 21:49:00 -04001594 * @phba: Pointer to HBA context object.
1595 * @pring: Pointer to driver SLI ring object.
1596 *
1597 * This function is called with hbalock held to post pending iocbs
1598 * in the txq to the firmware. This function is called when driver
1599 * detects space available in the ring.
1600 **/
dea31012005-04-17 16:05:31 -05001601static void
James Smart2e0fef82007-06-17 19:56:36 -05001602lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -05001603{
1604 IOCB_t *iocb;
1605 struct lpfc_iocbq *nextiocb;
1606
1607 /*
1608 * Check to see if:
1609 * (a) there is anything on the txq to send
1610 * (b) link is up
1611 * (c) link attention events can be processed (fcp ring only)
1612 * (d) IOCB processing is not blocked by the outstanding mbox command.
1613 */
James Smart0e9bb8d2013-03-01 16:35:12 -05001614
1615 if (lpfc_is_link_up(phba) &&
1616 (!list_empty(&pring->txq)) &&
dea31012005-04-17 16:05:31 -05001617 (pring->ringno != phba->sli.fcp_ring ||
James Smart0b727fe2007-10-27 13:37:25 -04001618 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
dea31012005-04-17 16:05:31 -05001619
1620 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1621 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1622 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1623
1624 if (iocb)
1625 lpfc_sli_update_ring(phba, pring);
1626 else
1627 lpfc_sli_update_full_ring(phba, pring);
1628 }
1629
1630 return;
1631}
1632
James Smarte59058c2008-08-24 21:49:00 -04001633/**
James Smart3621a712009-04-06 18:47:14 -04001634 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
James Smarte59058c2008-08-24 21:49:00 -04001635 * @phba: Pointer to HBA context object.
1636 * @hbqno: HBQ number.
1637 *
1638 * This function is called with hbalock held to get the next
1639 * available slot for the given HBQ. If there is free slot
1640 * available for the HBQ it will return pointer to the next available
1641 * HBQ entry else it will return NULL.
1642 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001643static struct lpfc_hbq_entry *
James Smarted957682007-06-17 19:56:37 -05001644lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1645{
1646 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1647
1648 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1649 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1650 hbqp->next_hbqPutIdx = 0;
1651
1652 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001653 uint32_t raw_index = phba->hbq_get[hbqno];
James Smarted957682007-06-17 19:56:37 -05001654 uint32_t getidx = le32_to_cpu(raw_index);
1655
1656 hbqp->local_hbqGetIdx = getidx;
1657
1658 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1659 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05001660 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04001661 "1802 HBQ %d: local_hbqGetIdx "
James Smarted957682007-06-17 19:56:37 -05001662 "%u is > than hbqp->entry_count %u\n",
James Smarte8b62012007-08-02 11:10:09 -04001663 hbqno, hbqp->local_hbqGetIdx,
James Smarted957682007-06-17 19:56:37 -05001664 hbqp->entry_count);
1665
1666 phba->link_state = LPFC_HBA_ERROR;
1667 return NULL;
1668 }
1669
1670 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1671 return NULL;
1672 }
1673
James Smart51ef4c22007-08-02 11:10:31 -04001674 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1675 hbqp->hbqPutIdx;
James Smarted957682007-06-17 19:56:37 -05001676}
1677
James Smarte59058c2008-08-24 21:49:00 -04001678/**
James Smart3621a712009-04-06 18:47:14 -04001679 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
James Smarte59058c2008-08-24 21:49:00 -04001680 * @phba: Pointer to HBA context object.
1681 *
1682 * This function is called with no lock held to free all the
1683 * hbq buffers while uninitializing the SLI interface. It also
1684 * frees the HBQ buffers returned by the firmware but not yet
1685 * processed by the upper layers.
1686 **/
James Smarted957682007-06-17 19:56:37 -05001687void
1688lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1689{
James Smart92d7f7b2007-06-17 19:56:38 -05001690 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1691 struct hbq_dmabuf *hbq_buf;
James Smart3163f722008-02-08 18:50:25 -05001692 unsigned long flags;
James Smart51ef4c22007-08-02 11:10:31 -04001693 int i, hbq_count;
James Smart3163f722008-02-08 18:50:25 -05001694 uint32_t hbqno;
James Smarted957682007-06-17 19:56:37 -05001695
James Smart51ef4c22007-08-02 11:10:31 -04001696 hbq_count = lpfc_sli_hbq_count();
James Smarted957682007-06-17 19:56:37 -05001697 /* Return all memory used by all HBQs */
James Smart3163f722008-02-08 18:50:25 -05001698 spin_lock_irqsave(&phba->hbalock, flags);
James Smart51ef4c22007-08-02 11:10:31 -04001699 for (i = 0; i < hbq_count; ++i) {
1700 list_for_each_entry_safe(dmabuf, next_dmabuf,
1701 &phba->hbqs[i].hbq_buffer_list, list) {
1702 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1703 list_del(&hbq_buf->dbuf.list);
1704 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1705 }
James Smarta8adb832007-10-27 13:37:53 -04001706 phba->hbqs[i].buffer_count = 0;
James Smarted957682007-06-17 19:56:37 -05001707 }
James Smart3163f722008-02-08 18:50:25 -05001708 /* Return all HBQ buffer that are in-fly */
James Smart3772a992009-05-22 14:50:54 -04001709 list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
1710 list) {
James Smart3163f722008-02-08 18:50:25 -05001711 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1712 list_del(&hbq_buf->dbuf.list);
1713 if (hbq_buf->tag == -1) {
1714 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1715 (phba, hbq_buf);
1716 } else {
1717 hbqno = hbq_buf->tag >> 16;
1718 if (hbqno >= LPFC_MAX_HBQS)
1719 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
1720 (phba, hbq_buf);
1721 else
1722 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1723 hbq_buf);
1724 }
1725 }
1726
1727 /* Mark the HBQs not in use */
1728 phba->hbq_in_use = 0;
1729 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smarted957682007-06-17 19:56:37 -05001730}
1731
James Smarte59058c2008-08-24 21:49:00 -04001732/**
James Smart3621a712009-04-06 18:47:14 -04001733 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
James Smarte59058c2008-08-24 21:49:00 -04001734 * @phba: Pointer to HBA context object.
1735 * @hbqno: HBQ number.
1736 * @hbq_buf: Pointer to HBQ buffer.
1737 *
1738 * This function is called with the hbalock held to post a
1739 * hbq buffer to the firmware. If the function finds an empty
1740 * slot in the HBQ, it will post the buffer. The function will return
1741 * pointer to the hbq entry if it successfully post the buffer
1742 * else it will return NULL.
1743 **/
James Smart3772a992009-05-22 14:50:54 -04001744static int
James Smarted957682007-06-17 19:56:37 -05001745lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
James Smart92d7f7b2007-06-17 19:56:38 -05001746 struct hbq_dmabuf *hbq_buf)
James Smarted957682007-06-17 19:56:37 -05001747{
James Smart3772a992009-05-22 14:50:54 -04001748 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1749}
1750
1751/**
1752 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1753 * @phba: Pointer to HBA context object.
1754 * @hbqno: HBQ number.
1755 * @hbq_buf: Pointer to HBQ buffer.
1756 *
1757 * This function is called with the hbalock held to post a hbq buffer to the
1758 * firmware. If the function finds an empty slot in the HBQ, it will post the
1759 * buffer and place it on the hbq_buffer_list. The function will return zero if
1760 * it successfully post the buffer else it will return an error.
1761 **/
1762static int
1763lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1764 struct hbq_dmabuf *hbq_buf)
1765{
James Smarted957682007-06-17 19:56:37 -05001766 struct lpfc_hbq_entry *hbqe;
James Smart92d7f7b2007-06-17 19:56:38 -05001767 dma_addr_t physaddr = hbq_buf->dbuf.phys;
James Smarted957682007-06-17 19:56:37 -05001768
1769 /* Get next HBQ entry slot to use */
1770 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1771 if (hbqe) {
1772 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1773
James Smart92d7f7b2007-06-17 19:56:38 -05001774 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1775 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
James Smart51ef4c22007-08-02 11:10:31 -04001776 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
James Smarted957682007-06-17 19:56:37 -05001777 hbqe->bde.tus.f.bdeFlags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001778 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1779 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1780 /* Sync SLIM */
James Smarted957682007-06-17 19:56:37 -05001781 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1782 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
James Smart92d7f7b2007-06-17 19:56:38 -05001783 /* flush */
James Smarted957682007-06-17 19:56:37 -05001784 readl(phba->hbq_put + hbqno);
James Smart51ef4c22007-08-02 11:10:31 -04001785 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
James Smart3772a992009-05-22 14:50:54 -04001786 return 0;
1787 } else
1788 return -ENOMEM;
James Smarted957682007-06-17 19:56:37 -05001789}
1790
James Smart4f774512009-05-22 14:52:35 -04001791/**
1792 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1793 * @phba: Pointer to HBA context object.
1794 * @hbqno: HBQ number.
1795 * @hbq_buf: Pointer to HBQ buffer.
1796 *
1797 * This function is called with the hbalock held to post an RQE to the SLI4
1798 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1799 * the hbq_buffer_list and return zero, otherwise it will return an error.
1800 **/
1801static int
1802lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1803 struct hbq_dmabuf *hbq_buf)
1804{
1805 int rc;
1806 struct lpfc_rqe hrqe;
1807 struct lpfc_rqe drqe;
1808
1809 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1810 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1811 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1812 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1813 rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
1814 &hrqe, &drqe);
1815 if (rc < 0)
1816 return rc;
1817 hbq_buf->tag = rc;
1818 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1819 return 0;
1820}
1821
James Smarte59058c2008-08-24 21:49:00 -04001822/* HBQ for ELS and CT traffic. */
James Smart92d7f7b2007-06-17 19:56:38 -05001823static struct lpfc_hbq_init lpfc_els_hbq = {
1824 .rn = 1,
James Smartdef9c7a2009-12-21 17:02:28 -05001825 .entry_count = 256,
James Smart92d7f7b2007-06-17 19:56:38 -05001826 .mask_count = 0,
1827 .profile = 0,
James Smart51ef4c22007-08-02 11:10:31 -04001828 .ring_mask = (1 << LPFC_ELS_RING),
James Smart92d7f7b2007-06-17 19:56:38 -05001829 .buffer_count = 0,
James Smarta257bf92009-04-06 18:48:10 -04001830 .init_count = 40,
1831 .add_count = 40,
James Smart92d7f7b2007-06-17 19:56:38 -05001832};
James Smarted957682007-06-17 19:56:37 -05001833
James Smarte59058c2008-08-24 21:49:00 -04001834/* HBQ for the extra ring if needed */
James Smart51ef4c22007-08-02 11:10:31 -04001835static struct lpfc_hbq_init lpfc_extra_hbq = {
1836 .rn = 1,
1837 .entry_count = 200,
1838 .mask_count = 0,
1839 .profile = 0,
1840 .ring_mask = (1 << LPFC_EXTRA_RING),
1841 .buffer_count = 0,
1842 .init_count = 0,
1843 .add_count = 5,
1844};
1845
James Smarte59058c2008-08-24 21:49:00 -04001846/* Array of HBQs */
James Smart78b2d852007-08-02 11:10:21 -04001847struct lpfc_hbq_init *lpfc_hbq_defs[] = {
James Smart92d7f7b2007-06-17 19:56:38 -05001848 &lpfc_els_hbq,
James Smart51ef4c22007-08-02 11:10:31 -04001849 &lpfc_extra_hbq,
James Smart92d7f7b2007-06-17 19:56:38 -05001850};
1851
James Smarte59058c2008-08-24 21:49:00 -04001852/**
James Smart3621a712009-04-06 18:47:14 -04001853 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
James Smarte59058c2008-08-24 21:49:00 -04001854 * @phba: Pointer to HBA context object.
1855 * @hbqno: HBQ number.
1856 * @count: Number of HBQ buffers to be posted.
1857 *
James Smartd7c255b2008-08-24 21:50:00 -04001858 * This function is called with no lock held to post more hbq buffers to the
1859 * given HBQ. The function returns the number of HBQ buffers successfully
1860 * posted.
James Smarte59058c2008-08-24 21:49:00 -04001861 **/
James Smart311464e2007-08-02 11:10:37 -04001862static int
James Smart92d7f7b2007-06-17 19:56:38 -05001863lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1864{
James Smartd7c255b2008-08-24 21:50:00 -04001865 uint32_t i, posted = 0;
James Smart3163f722008-02-08 18:50:25 -05001866 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05001867 struct hbq_dmabuf *hbq_buffer;
James Smartd7c255b2008-08-24 21:50:00 -04001868 LIST_HEAD(hbq_buf_list);
Matthew Wilcoxeafe1df2008-02-21 05:44:33 -07001869 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
James Smart51ef4c22007-08-02 11:10:31 -04001870 return 0;
James Smart51ef4c22007-08-02 11:10:31 -04001871
James Smartd7c255b2008-08-24 21:50:00 -04001872 if ((phba->hbqs[hbqno].buffer_count + count) >
1873 lpfc_hbq_defs[hbqno]->entry_count)
1874 count = lpfc_hbq_defs[hbqno]->entry_count -
1875 phba->hbqs[hbqno].buffer_count;
1876 if (!count)
1877 return 0;
1878 /* Allocate HBQ entries */
1879 for (i = 0; i < count; i++) {
1880 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1881 if (!hbq_buffer)
1882 break;
1883 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1884 }
James Smart3163f722008-02-08 18:50:25 -05001885 /* Check whether HBQ is still in use */
1886 spin_lock_irqsave(&phba->hbalock, flags);
Matthew Wilcoxeafe1df2008-02-21 05:44:33 -07001887 if (!phba->hbq_in_use)
James Smartd7c255b2008-08-24 21:50:00 -04001888 goto err;
1889 while (!list_empty(&hbq_buf_list)) {
1890 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1891 dbuf.list);
1892 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1893 (hbqno << 16));
James Smart3772a992009-05-22 14:50:54 -04001894 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
James Smarta8adb832007-10-27 13:37:53 -04001895 phba->hbqs[hbqno].buffer_count++;
James Smartd7c255b2008-08-24 21:50:00 -04001896 posted++;
1897 } else
James Smart51ef4c22007-08-02 11:10:31 -04001898 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
James Smart92d7f7b2007-06-17 19:56:38 -05001899 }
James Smart3163f722008-02-08 18:50:25 -05001900 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smartd7c255b2008-08-24 21:50:00 -04001901 return posted;
1902err:
1903 spin_unlock_irqrestore(&phba->hbalock, flags);
1904 while (!list_empty(&hbq_buf_list)) {
1905 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1906 dbuf.list);
1907 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1908 }
James Smart92d7f7b2007-06-17 19:56:38 -05001909 return 0;
James Smarted957682007-06-17 19:56:37 -05001910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
James Smart3621a712009-04-06 18:47:14 -04001913 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
James Smarte59058c2008-08-24 21:49:00 -04001914 * @phba: Pointer to HBA context object.
1915 * @qno: HBQ number.
1916 *
1917 * This function posts more buffers to the HBQ. This function
James Smartd7c255b2008-08-24 21:50:00 -04001918 * is called with no lock held. The function returns the number of HBQ entries
1919 * successfully allocated.
James Smarte59058c2008-08-24 21:49:00 -04001920 **/
James Smarted957682007-06-17 19:56:37 -05001921int
James Smart92d7f7b2007-06-17 19:56:38 -05001922lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -05001923{
James Smartdef9c7a2009-12-21 17:02:28 -05001924 if (phba->sli_rev == LPFC_SLI_REV4)
1925 return 0;
1926 else
1927 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1928 lpfc_hbq_defs[qno]->add_count);
James Smarted957682007-06-17 19:56:37 -05001929}
1930
James Smarte59058c2008-08-24 21:49:00 -04001931/**
James Smart3621a712009-04-06 18:47:14 -04001932 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
James Smarte59058c2008-08-24 21:49:00 -04001933 * @phba: Pointer to HBA context object.
1934 * @qno: HBQ queue number.
1935 *
1936 * This function is called from SLI initialization code path with
1937 * no lock held to post initial HBQ buffers to firmware. The
James Smartd7c255b2008-08-24 21:50:00 -04001938 * function returns the number of HBQ entries successfully allocated.
James Smarte59058c2008-08-24 21:49:00 -04001939 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001940static int
James Smart92d7f7b2007-06-17 19:56:38 -05001941lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -05001942{
James Smartdef9c7a2009-12-21 17:02:28 -05001943 if (phba->sli_rev == LPFC_SLI_REV4)
1944 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
James Smart73d91e52011-10-10 21:32:10 -04001945 lpfc_hbq_defs[qno]->entry_count);
James Smartdef9c7a2009-12-21 17:02:28 -05001946 else
1947 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1948 lpfc_hbq_defs[qno]->init_count);
James Smarted957682007-06-17 19:56:37 -05001949}
1950
James Smarte59058c2008-08-24 21:49:00 -04001951/**
James Smart3772a992009-05-22 14:50:54 -04001952 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1953 * @phba: Pointer to HBA context object.
1954 * @hbqno: HBQ number.
1955 *
1956 * This function removes the first hbq buffer on an hbq list and returns a
1957 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1958 **/
1959static struct hbq_dmabuf *
1960lpfc_sli_hbqbuf_get(struct list_head *rb_list)
1961{
1962 struct lpfc_dmabuf *d_buf;
1963
1964 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
1965 if (!d_buf)
1966 return NULL;
1967 return container_of(d_buf, struct hbq_dmabuf, dbuf);
1968}
1969
1970/**
James Smart3621a712009-04-06 18:47:14 -04001971 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
James Smarte59058c2008-08-24 21:49:00 -04001972 * @phba: Pointer to HBA context object.
1973 * @tag: Tag of the hbq buffer.
1974 *
1975 * This function is called with hbalock held. This function searches
1976 * for the hbq buffer associated with the given tag in the hbq buffer
1977 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1978 * it returns NULL.
1979 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001980static struct hbq_dmabuf *
James Smarted957682007-06-17 19:56:37 -05001981lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
1982{
James Smart92d7f7b2007-06-17 19:56:38 -05001983 struct lpfc_dmabuf *d_buf;
1984 struct hbq_dmabuf *hbq_buf;
James Smart51ef4c22007-08-02 11:10:31 -04001985 uint32_t hbqno;
James Smarted957682007-06-17 19:56:37 -05001986
James Smart51ef4c22007-08-02 11:10:31 -04001987 hbqno = tag >> 16;
Jesper Juhla0a74e452007-08-09 20:47:15 +02001988 if (hbqno >= LPFC_MAX_HBQS)
James Smart51ef4c22007-08-02 11:10:31 -04001989 return NULL;
1990
James Smart3772a992009-05-22 14:50:54 -04001991 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04001992 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
James Smart92d7f7b2007-06-17 19:56:38 -05001993 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
James Smart51ef4c22007-08-02 11:10:31 -04001994 if (hbq_buf->tag == tag) {
James Smart3772a992009-05-22 14:50:54 -04001995 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05001996 return hbq_buf;
James Smarted957682007-06-17 19:56:37 -05001997 }
1998 }
James Smart3772a992009-05-22 14:50:54 -04001999 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05002000 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002001 "1803 Bad hbq tag. Data: x%x x%x\n",
James Smarta8adb832007-10-27 13:37:53 -04002002 tag, phba->hbqs[tag >> 16].buffer_count);
James Smart92d7f7b2007-06-17 19:56:38 -05002003 return NULL;
James Smarted957682007-06-17 19:56:37 -05002004}
2005
James Smarte59058c2008-08-24 21:49:00 -04002006/**
James Smart3621a712009-04-06 18:47:14 -04002007 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
James Smarte59058c2008-08-24 21:49:00 -04002008 * @phba: Pointer to HBA context object.
2009 * @hbq_buffer: Pointer to HBQ buffer.
2010 *
2011 * This function is called with hbalock. This function gives back
2012 * the hbq buffer to firmware. If the HBQ does not have space to
2013 * post the buffer, it will free the buffer.
2014 **/
James Smarted957682007-06-17 19:56:37 -05002015void
James Smart51ef4c22007-08-02 11:10:31 -04002016lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
James Smarted957682007-06-17 19:56:37 -05002017{
2018 uint32_t hbqno;
2019
James Smart51ef4c22007-08-02 11:10:31 -04002020 if (hbq_buffer) {
2021 hbqno = hbq_buffer->tag >> 16;
James Smart3772a992009-05-22 14:50:54 -04002022 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
James Smart51ef4c22007-08-02 11:10:31 -04002023 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
James Smarted957682007-06-17 19:56:37 -05002024 }
2025}
2026
James Smarte59058c2008-08-24 21:49:00 -04002027/**
James Smart3621a712009-04-06 18:47:14 -04002028 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
James Smarte59058c2008-08-24 21:49:00 -04002029 * @mbxCommand: mailbox command code.
2030 *
2031 * This function is called by the mailbox event handler function to verify
2032 * that the completed mailbox command is a legitimate mailbox command. If the
2033 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2034 * and the mailbox event handler will take the HBA offline.
2035 **/
dea31012005-04-17 16:05:31 -05002036static int
2037lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2038{
2039 uint8_t ret;
2040
2041 switch (mbxCommand) {
2042 case MBX_LOAD_SM:
2043 case MBX_READ_NV:
2044 case MBX_WRITE_NV:
James Smarta8adb832007-10-27 13:37:53 -04002045 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05002046 case MBX_RUN_BIU_DIAG:
2047 case MBX_INIT_LINK:
2048 case MBX_DOWN_LINK:
2049 case MBX_CONFIG_LINK:
2050 case MBX_CONFIG_RING:
2051 case MBX_RESET_RING:
2052 case MBX_READ_CONFIG:
2053 case MBX_READ_RCONFIG:
2054 case MBX_READ_SPARM:
2055 case MBX_READ_STATUS:
2056 case MBX_READ_RPI:
2057 case MBX_READ_XRI:
2058 case MBX_READ_REV:
2059 case MBX_READ_LNK_STAT:
2060 case MBX_REG_LOGIN:
2061 case MBX_UNREG_LOGIN:
dea31012005-04-17 16:05:31 -05002062 case MBX_CLEAR_LA:
2063 case MBX_DUMP_MEMORY:
2064 case MBX_DUMP_CONTEXT:
2065 case MBX_RUN_DIAGS:
2066 case MBX_RESTART:
2067 case MBX_UPDATE_CFG:
2068 case MBX_DOWN_LOAD:
2069 case MBX_DEL_LD_ENTRY:
2070 case MBX_RUN_PROGRAM:
2071 case MBX_SET_MASK:
James Smart09372822008-01-11 01:52:54 -05002072 case MBX_SET_VARIABLE:
dea31012005-04-17 16:05:31 -05002073 case MBX_UNREG_D_ID:
Jamie Wellnitz41415862006-02-28 19:25:27 -05002074 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05002075 case MBX_CONFIG_FARP:
Jamie Wellnitz41415862006-02-28 19:25:27 -05002076 case MBX_BEACON:
dea31012005-04-17 16:05:31 -05002077 case MBX_LOAD_AREA:
2078 case MBX_RUN_BIU_DIAG64:
2079 case MBX_CONFIG_PORT:
2080 case MBX_READ_SPARM64:
2081 case MBX_READ_RPI64:
2082 case MBX_REG_LOGIN64:
James Smart76a95d72010-11-20 23:11:48 -05002083 case MBX_READ_TOPOLOGY:
James Smart09372822008-01-11 01:52:54 -05002084 case MBX_WRITE_WWN:
dea31012005-04-17 16:05:31 -05002085 case MBX_SET_DEBUG:
2086 case MBX_LOAD_EXP_ROM:
James Smart57127f12007-10-27 13:37:05 -04002087 case MBX_ASYNCEVT_ENABLE:
James Smart92d7f7b2007-06-17 19:56:38 -05002088 case MBX_REG_VPI:
2089 case MBX_UNREG_VPI:
James Smart858c9f62007-06-17 19:56:39 -05002090 case MBX_HEARTBEAT:
James Smart84774a42008-08-24 21:50:06 -04002091 case MBX_PORT_CAPABILITIES:
2092 case MBX_PORT_IOV_CONTROL:
James Smart04c68492009-05-22 14:52:52 -04002093 case MBX_SLI4_CONFIG:
2094 case MBX_SLI4_REQ_FTRS:
2095 case MBX_REG_FCFI:
2096 case MBX_UNREG_FCFI:
2097 case MBX_REG_VFI:
2098 case MBX_UNREG_VFI:
2099 case MBX_INIT_VPI:
2100 case MBX_INIT_VFI:
2101 case MBX_RESUME_RPI:
James Smartc7495932010-04-06 15:05:28 -04002102 case MBX_READ_EVENT_LOG_STATUS:
2103 case MBX_READ_EVENT_LOG:
James Smartdcf2a4e2010-09-29 11:18:53 -04002104 case MBX_SECURITY_MGMT:
2105 case MBX_AUTH_PORT:
James Smart940eb682012-08-03 12:37:08 -04002106 case MBX_ACCESS_VDATA:
dea31012005-04-17 16:05:31 -05002107 ret = mbxCommand;
2108 break;
2109 default:
2110 ret = MBX_SHUTDOWN;
2111 break;
2112 }
James Smart2e0fef82007-06-17 19:56:36 -05002113 return ret;
dea31012005-04-17 16:05:31 -05002114}
James Smarte59058c2008-08-24 21:49:00 -04002115
2116/**
James Smart3621a712009-04-06 18:47:14 -04002117 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
James Smarte59058c2008-08-24 21:49:00 -04002118 * @phba: Pointer to HBA context object.
2119 * @pmboxq: Pointer to mailbox command.
2120 *
2121 * This is completion handler function for mailbox commands issued from
2122 * lpfc_sli_issue_mbox_wait function. This function is called by the
2123 * mailbox event handler function with no lock held. This function
2124 * will wake up thread waiting on the wait queue pointed by context1
2125 * of the mailbox.
2126 **/
James Smart04c68492009-05-22 14:52:52 -04002127void
James Smart2e0fef82007-06-17 19:56:36 -05002128lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
dea31012005-04-17 16:05:31 -05002129{
2130 wait_queue_head_t *pdone_q;
James Smart858c9f62007-06-17 19:56:39 -05002131 unsigned long drvr_flag;
dea31012005-04-17 16:05:31 -05002132
2133 /*
2134 * If pdone_q is empty, the driver thread gave up waiting and
2135 * continued running.
2136 */
James Smart7054a602007-04-25 09:52:34 -04002137 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
James Smart858c9f62007-06-17 19:56:39 -05002138 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002139 pdone_q = (wait_queue_head_t *) pmboxq->context1;
2140 if (pdone_q)
2141 wake_up_interruptible(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -05002142 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002143 return;
2144}
2145
James Smarte59058c2008-08-24 21:49:00 -04002146
2147/**
James Smart3621a712009-04-06 18:47:14 -04002148 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
James Smarte59058c2008-08-24 21:49:00 -04002149 * @phba: Pointer to HBA context object.
2150 * @pmb: Pointer to mailbox object.
2151 *
2152 * This function is the default mailbox completion handler. It
2153 * frees the memory resources associated with the completed mailbox
2154 * command. If the completed command is a REG_LOGIN mailbox command,
2155 * this function will issue a UREG_LOGIN to re-claim the RPI.
2156 **/
dea31012005-04-17 16:05:31 -05002157void
James Smart2e0fef82007-06-17 19:56:36 -05002158lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002159{
James Smartd439d282010-09-29 11:18:45 -04002160 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002161 struct lpfc_dmabuf *mp;
James Smartd439d282010-09-29 11:18:45 -04002162 struct lpfc_nodelist *ndlp;
James Smart5af5eee2010-10-22 11:06:38 -04002163 struct Scsi_Host *shost;
James Smart04c68492009-05-22 14:52:52 -04002164 uint16_t rpi, vpi;
James Smart7054a602007-04-25 09:52:34 -04002165 int rc;
2166
dea31012005-04-17 16:05:31 -05002167 mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart7054a602007-04-25 09:52:34 -04002168
dea31012005-04-17 16:05:31 -05002169 if (mp) {
2170 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2171 kfree(mp);
2172 }
James Smart7054a602007-04-25 09:52:34 -04002173
2174 /*
2175 * If a REG_LOGIN succeeded after node is destroyed or node
2176 * is in re-discovery driver need to cleanup the RPI.
2177 */
James Smart2e0fef82007-06-17 19:56:36 -05002178 if (!(phba->pport->load_flag & FC_UNLOADING) &&
James Smart04c68492009-05-22 14:52:52 -04002179 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2180 !pmb->u.mb.mbxStatus) {
2181 rpi = pmb->u.mb.un.varWords[0];
James Smart6d368e52011-05-24 11:44:12 -04002182 vpi = pmb->u.mb.un.varRegLogin.vpi;
James Smart04c68492009-05-22 14:52:52 -04002183 lpfc_unreg_login(phba, vpi, rpi, pmb);
James Smart92d7f7b2007-06-17 19:56:38 -05002184 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart7054a602007-04-25 09:52:34 -04002185 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2186 if (rc != MBX_NOT_FINISHED)
2187 return;
2188 }
2189
James Smart695a8142010-01-26 23:08:03 -05002190 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2191 !(phba->pport->load_flag & FC_UNLOADING) &&
2192 !pmb->u.mb.mbxStatus) {
James Smart5af5eee2010-10-22 11:06:38 -04002193 shost = lpfc_shost_from_vport(vport);
2194 spin_lock_irq(shost->host_lock);
2195 vport->vpi_state |= LPFC_VPI_REGISTERED;
2196 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2197 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002198 }
2199
James Smartd439d282010-09-29 11:18:45 -04002200 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2201 ndlp = (struct lpfc_nodelist *)pmb->context2;
2202 lpfc_nlp_put(ndlp);
2203 pmb->context2 = NULL;
2204 }
2205
James Smartdcf2a4e2010-09-29 11:18:53 -04002206 /* Check security permission status on INIT_LINK mailbox command */
2207 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2208 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2209 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2210 "2860 SLI authentication is required "
2211 "for INIT_LINK but has not done yet\n");
2212
James Smart04c68492009-05-22 14:52:52 -04002213 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2214 lpfc_sli4_mbox_cmd_free(phba, pmb);
2215 else
2216 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002217}
2218
James Smarte59058c2008-08-24 21:49:00 -04002219/**
James Smart3621a712009-04-06 18:47:14 -04002220 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
James Smarte59058c2008-08-24 21:49:00 -04002221 * @phba: Pointer to HBA context object.
2222 *
2223 * This function is called with no lock held. This function processes all
2224 * the completed mailbox commands and gives it to upper layers. The interrupt
2225 * service routine processes mailbox completion interrupt and adds completed
2226 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2227 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2228 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2229 * function returns the mailbox commands to the upper layer by calling the
2230 * completion handler function of each mailbox.
2231 **/
dea31012005-04-17 16:05:31 -05002232int
James Smart2e0fef82007-06-17 19:56:36 -05002233lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002234{
James Smart92d7f7b2007-06-17 19:56:38 -05002235 MAILBOX_t *pmbox;
dea31012005-04-17 16:05:31 -05002236 LPFC_MBOXQ_t *pmb;
James Smart92d7f7b2007-06-17 19:56:38 -05002237 int rc;
2238 LIST_HEAD(cmplq);
dea31012005-04-17 16:05:31 -05002239
2240 phba->sli.slistat.mbox_event++;
2241
James Smart92d7f7b2007-06-17 19:56:38 -05002242 /* Get all completed mailboxe buffers into the cmplq */
2243 spin_lock_irq(&phba->hbalock);
2244 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2245 spin_unlock_irq(&phba->hbalock);
2246
dea31012005-04-17 16:05:31 -05002247 /* Get a Mailbox buffer to setup mailbox commands for callback */
James Smart92d7f7b2007-06-17 19:56:38 -05002248 do {
2249 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2250 if (pmb == NULL)
2251 break;
2252
James Smart04c68492009-05-22 14:52:52 -04002253 pmbox = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002254
James Smart858c9f62007-06-17 19:56:39 -05002255 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2256 if (pmb->vport) {
2257 lpfc_debugfs_disc_trc(pmb->vport,
2258 LPFC_DISC_TRC_MBOX_VPORT,
2259 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2260 (uint32_t)pmbox->mbxCommand,
2261 pmbox->un.varWords[0],
2262 pmbox->un.varWords[1]);
2263 }
2264 else {
2265 lpfc_debugfs_disc_trc(phba->pport,
2266 LPFC_DISC_TRC_MBOX,
2267 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2268 (uint32_t)pmbox->mbxCommand,
2269 pmbox->un.varWords[0],
2270 pmbox->un.varWords[1]);
2271 }
2272 }
2273
dea31012005-04-17 16:05:31 -05002274 /*
2275 * It is a fatal error if unknown mbox command completion.
2276 */
2277 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2278 MBX_SHUTDOWN) {
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002279 /* Unknown mailbox command compl */
James Smart92d7f7b2007-06-17 19:56:38 -05002280 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002281 "(%d):0323 Unknown Mailbox command "
James Smarta183a152011-10-10 21:32:43 -04002282 "x%x (x%x/x%x) Cmpl\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002283 pmb->vport ? pmb->vport->vpi : 0,
James Smart04c68492009-05-22 14:52:52 -04002284 pmbox->mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04002285 lpfc_sli_config_mbox_subsys_get(phba,
2286 pmb),
2287 lpfc_sli_config_mbox_opcode_get(phba,
2288 pmb));
James Smart2e0fef82007-06-17 19:56:36 -05002289 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002290 phba->work_hs = HS_FFER3;
2291 lpfc_handle_eratt(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002292 continue;
dea31012005-04-17 16:05:31 -05002293 }
2294
dea31012005-04-17 16:05:31 -05002295 if (pmbox->mbxStatus) {
2296 phba->sli.slistat.mbox_stat_err++;
2297 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2298 /* Mbox cmd cmpl error - RETRYing */
James Smart92d7f7b2007-06-17 19:56:38 -05002299 lpfc_printf_log(phba, KERN_INFO,
James Smarta183a152011-10-10 21:32:43 -04002300 LOG_MBOX | LOG_SLI,
2301 "(%d):0305 Mbox cmd cmpl "
2302 "error - RETRYing Data: x%x "
2303 "(x%x/x%x) x%x x%x x%x\n",
2304 pmb->vport ? pmb->vport->vpi : 0,
2305 pmbox->mbxCommand,
2306 lpfc_sli_config_mbox_subsys_get(phba,
2307 pmb),
2308 lpfc_sli_config_mbox_opcode_get(phba,
2309 pmb),
2310 pmbox->mbxStatus,
2311 pmbox->un.varWords[0],
2312 pmb->vport->port_state);
dea31012005-04-17 16:05:31 -05002313 pmbox->mbxStatus = 0;
2314 pmbox->mbxOwner = OWN_HOST;
dea31012005-04-17 16:05:31 -05002315 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart04c68492009-05-22 14:52:52 -04002316 if (rc != MBX_NOT_FINISHED)
James Smart92d7f7b2007-06-17 19:56:38 -05002317 continue;
dea31012005-04-17 16:05:31 -05002318 }
2319 }
2320
2321 /* Mailbox cmd <cmd> Cmpl <cmpl> */
James Smart92d7f7b2007-06-17 19:56:38 -05002322 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04002323 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
James Smarte74c03c2013-04-17 20:15:19 -04002324 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2325 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002326 pmb->vport ? pmb->vport->vpi : 0,
dea31012005-04-17 16:05:31 -05002327 pmbox->mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04002328 lpfc_sli_config_mbox_subsys_get(phba, pmb),
2329 lpfc_sli_config_mbox_opcode_get(phba, pmb),
dea31012005-04-17 16:05:31 -05002330 pmb->mbox_cmpl,
2331 *((uint32_t *) pmbox),
2332 pmbox->un.varWords[0],
2333 pmbox->un.varWords[1],
2334 pmbox->un.varWords[2],
2335 pmbox->un.varWords[3],
2336 pmbox->un.varWords[4],
2337 pmbox->un.varWords[5],
2338 pmbox->un.varWords[6],
James Smarte74c03c2013-04-17 20:15:19 -04002339 pmbox->un.varWords[7],
2340 pmbox->un.varWords[8],
2341 pmbox->un.varWords[9],
2342 pmbox->un.varWords[10]);
dea31012005-04-17 16:05:31 -05002343
James Smart92d7f7b2007-06-17 19:56:38 -05002344 if (pmb->mbox_cmpl)
dea31012005-04-17 16:05:31 -05002345 pmb->mbox_cmpl(phba,pmb);
James Smart92d7f7b2007-06-17 19:56:38 -05002346 } while (1);
James Smart2e0fef82007-06-17 19:56:36 -05002347 return 0;
dea31012005-04-17 16:05:31 -05002348}
James Smart92d7f7b2007-06-17 19:56:38 -05002349
James Smarte59058c2008-08-24 21:49:00 -04002350/**
James Smart3621a712009-04-06 18:47:14 -04002351 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
James Smarte59058c2008-08-24 21:49:00 -04002352 * @phba: Pointer to HBA context object.
2353 * @pring: Pointer to driver SLI ring object.
2354 * @tag: buffer tag.
2355 *
2356 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2357 * is set in the tag the buffer is posted for a particular exchange,
2358 * the function will return the buffer without replacing the buffer.
2359 * If the buffer is for unsolicited ELS or CT traffic, this function
2360 * returns the buffer and also posts another buffer to the firmware.
2361 **/
James Smart76bb24e2007-10-27 13:38:00 -04002362static struct lpfc_dmabuf *
2363lpfc_sli_get_buff(struct lpfc_hba *phba,
James Smart9f1e1b52008-12-04 22:39:40 -05002364 struct lpfc_sli_ring *pring,
2365 uint32_t tag)
James Smart76bb24e2007-10-27 13:38:00 -04002366{
James Smart9f1e1b52008-12-04 22:39:40 -05002367 struct hbq_dmabuf *hbq_entry;
2368
James Smart76bb24e2007-10-27 13:38:00 -04002369 if (tag & QUE_BUFTAG_BIT)
2370 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
James Smart9f1e1b52008-12-04 22:39:40 -05002371 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2372 if (!hbq_entry)
2373 return NULL;
2374 return &hbq_entry->dbuf;
James Smart76bb24e2007-10-27 13:38:00 -04002375}
James Smart57127f12007-10-27 13:37:05 -04002376
James Smart3772a992009-05-22 14:50:54 -04002377/**
2378 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2379 * @phba: Pointer to HBA context object.
2380 * @pring: Pointer to driver SLI ring object.
2381 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2382 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2383 * @fch_type: the type for the first frame of the sequence.
2384 *
2385 * This function is called with no lock held. This function uses the r_ctl and
2386 * type of the received sequence to find the correct callback function to call
2387 * to process the sequence.
2388 **/
2389static int
2390lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2391 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
2392 uint32_t fch_type)
2393{
2394 int i;
2395
2396 /* unSolicited Responses */
2397 if (pring->prt[0].profile) {
2398 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
2399 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
2400 saveq);
2401 return 1;
2402 }
2403 /* We must search, based on rctl / type
2404 for the right routine */
2405 for (i = 0; i < pring->num_mask; i++) {
2406 if ((pring->prt[i].rctl == fch_r_ctl) &&
2407 (pring->prt[i].type == fch_type)) {
2408 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
2409 (pring->prt[i].lpfc_sli_rcv_unsol_event)
2410 (phba, pring, saveq);
2411 return 1;
2412 }
2413 }
2414 return 0;
2415}
James Smarte59058c2008-08-24 21:49:00 -04002416
2417/**
James Smart3621a712009-04-06 18:47:14 -04002418 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
James Smarte59058c2008-08-24 21:49:00 -04002419 * @phba: Pointer to HBA context object.
2420 * @pring: Pointer to driver SLI ring object.
2421 * @saveq: Pointer to the unsolicited iocb.
2422 *
2423 * This function is called with no lock held by the ring event handler
2424 * when there is an unsolicited iocb posted to the response ring by the
2425 * firmware. This function gets the buffer associated with the iocbs
2426 * and calls the event handler for the ring. This function handles both
2427 * qring buffers and hbq buffers.
2428 * When the function returns 1 the caller can free the iocb object otherwise
2429 * upper layer functions will free the iocb objects.
2430 **/
dea31012005-04-17 16:05:31 -05002431static int
2432lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2433 struct lpfc_iocbq *saveq)
2434{
2435 IOCB_t * irsp;
2436 WORD5 * w5p;
2437 uint32_t Rctl, Type;
James Smart3772a992009-05-22 14:50:54 -04002438 uint32_t match;
James Smart76bb24e2007-10-27 13:38:00 -04002439 struct lpfc_iocbq *iocbq;
James Smart3163f722008-02-08 18:50:25 -05002440 struct lpfc_dmabuf *dmzbuf;
dea31012005-04-17 16:05:31 -05002441
2442 match = 0;
2443 irsp = &(saveq->iocb);
James Smart57127f12007-10-27 13:37:05 -04002444
2445 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
2446 if (pring->lpfc_sli_rcv_async_status)
2447 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
2448 else
2449 lpfc_printf_log(phba,
2450 KERN_WARNING,
2451 LOG_SLI,
2452 "0316 Ring %d handler: unexpected "
2453 "ASYNC_STATUS iocb received evt_code "
2454 "0x%x\n",
2455 pring->ringno,
2456 irsp->un.asyncstat.evt_code);
2457 return 1;
2458 }
2459
James Smart3163f722008-02-08 18:50:25 -05002460 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
2461 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
2462 if (irsp->ulpBdeCount > 0) {
2463 dmzbuf = lpfc_sli_get_buff(phba, pring,
2464 irsp->un.ulpWord[3]);
2465 lpfc_in_buf_free(phba, dmzbuf);
2466 }
2467
2468 if (irsp->ulpBdeCount > 1) {
2469 dmzbuf = lpfc_sli_get_buff(phba, pring,
2470 irsp->unsli3.sli3Words[3]);
2471 lpfc_in_buf_free(phba, dmzbuf);
2472 }
2473
2474 if (irsp->ulpBdeCount > 2) {
2475 dmzbuf = lpfc_sli_get_buff(phba, pring,
2476 irsp->unsli3.sli3Words[7]);
2477 lpfc_in_buf_free(phba, dmzbuf);
2478 }
2479
2480 return 1;
2481 }
2482
James Smart92d7f7b2007-06-17 19:56:38 -05002483 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart76bb24e2007-10-27 13:38:00 -04002484 if (irsp->ulpBdeCount != 0) {
2485 saveq->context2 = lpfc_sli_get_buff(phba, pring,
James Smart92d7f7b2007-06-17 19:56:38 -05002486 irsp->un.ulpWord[3]);
James Smart76bb24e2007-10-27 13:38:00 -04002487 if (!saveq->context2)
2488 lpfc_printf_log(phba,
2489 KERN_ERR,
2490 LOG_SLI,
2491 "0341 Ring %d Cannot find buffer for "
2492 "an unsolicited iocb. tag 0x%x\n",
2493 pring->ringno,
2494 irsp->un.ulpWord[3]);
James Smart76bb24e2007-10-27 13:38:00 -04002495 }
2496 if (irsp->ulpBdeCount == 2) {
2497 saveq->context3 = lpfc_sli_get_buff(phba, pring,
James Smart51ef4c22007-08-02 11:10:31 -04002498 irsp->unsli3.sli3Words[7]);
James Smart76bb24e2007-10-27 13:38:00 -04002499 if (!saveq->context3)
2500 lpfc_printf_log(phba,
2501 KERN_ERR,
2502 LOG_SLI,
2503 "0342 Ring %d Cannot find buffer for an"
2504 " unsolicited iocb. tag 0x%x\n",
2505 pring->ringno,
2506 irsp->unsli3.sli3Words[7]);
2507 }
2508 list_for_each_entry(iocbq, &saveq->list, list) {
James Smart76bb24e2007-10-27 13:38:00 -04002509 irsp = &(iocbq->iocb);
James Smart76bb24e2007-10-27 13:38:00 -04002510 if (irsp->ulpBdeCount != 0) {
2511 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2512 irsp->un.ulpWord[3]);
James Smart9c2face2008-01-11 01:53:18 -05002513 if (!iocbq->context2)
James Smart76bb24e2007-10-27 13:38:00 -04002514 lpfc_printf_log(phba,
2515 KERN_ERR,
2516 LOG_SLI,
2517 "0343 Ring %d Cannot find "
2518 "buffer for an unsolicited iocb"
2519 ". tag 0x%x\n", pring->ringno,
2520 irsp->un.ulpWord[3]);
2521 }
2522 if (irsp->ulpBdeCount == 2) {
2523 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2524 irsp->unsli3.sli3Words[7]);
James Smart9c2face2008-01-11 01:53:18 -05002525 if (!iocbq->context3)
James Smart76bb24e2007-10-27 13:38:00 -04002526 lpfc_printf_log(phba,
2527 KERN_ERR,
2528 LOG_SLI,
2529 "0344 Ring %d Cannot find "
2530 "buffer for an unsolicited "
2531 "iocb. tag 0x%x\n",
2532 pring->ringno,
2533 irsp->unsli3.sli3Words[7]);
2534 }
2535 }
James Smart92d7f7b2007-06-17 19:56:38 -05002536 }
James Smart9c2face2008-01-11 01:53:18 -05002537 if (irsp->ulpBdeCount != 0 &&
2538 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2539 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2540 int found = 0;
2541
2542 /* search continue save q for same XRI */
2543 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
James Smart7851fe22011-07-22 18:36:52 -04002544 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
2545 saveq->iocb.unsli3.rcvsli3.ox_id) {
James Smart9c2face2008-01-11 01:53:18 -05002546 list_add_tail(&saveq->list, &iocbq->list);
2547 found = 1;
2548 break;
2549 }
2550 }
2551 if (!found)
2552 list_add_tail(&saveq->clist,
2553 &pring->iocb_continue_saveq);
2554 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2555 list_del_init(&iocbq->clist);
2556 saveq = iocbq;
2557 irsp = &(saveq->iocb);
2558 } else
2559 return 0;
2560 }
2561 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2562 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2563 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
James Smart6a9c52c2009-10-02 15:16:51 -04002564 Rctl = FC_RCTL_ELS_REQ;
2565 Type = FC_TYPE_ELS;
James Smart9c2face2008-01-11 01:53:18 -05002566 } else {
2567 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2568 Rctl = w5p->hcsw.Rctl;
2569 Type = w5p->hcsw.Type;
2570
2571 /* Firmware Workaround */
2572 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2573 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2574 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
James Smart6a9c52c2009-10-02 15:16:51 -04002575 Rctl = FC_RCTL_ELS_REQ;
2576 Type = FC_TYPE_ELS;
James Smart9c2face2008-01-11 01:53:18 -05002577 w5p->hcsw.Rctl = Rctl;
2578 w5p->hcsw.Type = Type;
2579 }
2580 }
James Smart92d7f7b2007-06-17 19:56:38 -05002581
James Smart3772a992009-05-22 14:50:54 -04002582 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
James Smart92d7f7b2007-06-17 19:56:38 -05002583 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002584 "0313 Ring %d handler: unexpected Rctl x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05002585 "Type x%x received\n",
James Smarte8b62012007-08-02 11:10:09 -04002586 pring->ringno, Rctl, Type);
James Smart3772a992009-05-22 14:50:54 -04002587
James Smart92d7f7b2007-06-17 19:56:38 -05002588 return 1;
dea31012005-04-17 16:05:31 -05002589}
2590
James Smarte59058c2008-08-24 21:49:00 -04002591/**
James Smart3621a712009-04-06 18:47:14 -04002592 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
James Smarte59058c2008-08-24 21:49:00 -04002593 * @phba: Pointer to HBA context object.
2594 * @pring: Pointer to driver SLI ring object.
2595 * @prspiocb: Pointer to response iocb object.
2596 *
2597 * This function looks up the iocb_lookup table to get the command iocb
2598 * corresponding to the given response iocb using the iotag of the
2599 * response iocb. This function is called with the hbalock held.
2600 * This function returns the command iocb object if it finds the command
2601 * iocb else returns NULL.
2602 **/
dea31012005-04-17 16:05:31 -05002603static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -05002604lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2605 struct lpfc_sli_ring *pring,
2606 struct lpfc_iocbq *prspiocb)
dea31012005-04-17 16:05:31 -05002607{
dea31012005-04-17 16:05:31 -05002608 struct lpfc_iocbq *cmd_iocb = NULL;
2609 uint16_t iotag;
2610
James Bottomley604a3e32005-10-29 10:28:33 -05002611 iotag = prspiocb->iocb.ulpIoTag;
dea31012005-04-17 16:05:31 -05002612
James Bottomley604a3e32005-10-29 10:28:33 -05002613 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2614 cmd_iocb = phba->sli.iocbq_lookup[iotag];
James Smart92d7f7b2007-06-17 19:56:38 -05002615 list_del_init(&cmd_iocb->list);
James Smart4f2e66c2012-05-09 21:17:07 -04002616 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
James Smart4f2e66c2012-05-09 21:17:07 -04002617 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart2a9bf3d2010-06-07 15:24:45 -04002618 }
James Bottomley604a3e32005-10-29 10:28:33 -05002619 return cmd_iocb;
dea31012005-04-17 16:05:31 -05002620 }
2621
dea31012005-04-17 16:05:31 -05002622 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002623 "0317 iotag x%x is out off "
James Bottomley604a3e32005-10-29 10:28:33 -05002624 "range: max iotag x%x wd0 x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002625 iotag, phba->sli.last_iotag,
James Bottomley604a3e32005-10-29 10:28:33 -05002626 *(((uint32_t *) &prspiocb->iocb) + 7));
dea31012005-04-17 16:05:31 -05002627 return NULL;
2628}
2629
James Smarte59058c2008-08-24 21:49:00 -04002630/**
James Smart3772a992009-05-22 14:50:54 -04002631 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2632 * @phba: Pointer to HBA context object.
2633 * @pring: Pointer to driver SLI ring object.
2634 * @iotag: IOCB tag.
2635 *
2636 * This function looks up the iocb_lookup table to get the command iocb
2637 * corresponding to the given iotag. This function is called with the
2638 * hbalock held.
2639 * This function returns the command iocb object if it finds the command
2640 * iocb else returns NULL.
2641 **/
2642static struct lpfc_iocbq *
2643lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2644 struct lpfc_sli_ring *pring, uint16_t iotag)
2645{
2646 struct lpfc_iocbq *cmd_iocb;
2647
2648 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2649 cmd_iocb = phba->sli.iocbq_lookup[iotag];
James Smart4f2e66c2012-05-09 21:17:07 -04002650 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
2651 /* remove from txcmpl queue list */
2652 list_del_init(&cmd_iocb->list);
2653 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart4f2e66c2012-05-09 21:17:07 -04002654 return cmd_iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04002655 }
James Smart3772a992009-05-22 14:50:54 -04002656 }
James Smart3772a992009-05-22 14:50:54 -04002657 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2658 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2659 iotag, phba->sli.last_iotag);
2660 return NULL;
2661}
2662
2663/**
James Smart3621a712009-04-06 18:47:14 -04002664 * lpfc_sli_process_sol_iocb - process solicited iocb completion
James Smarte59058c2008-08-24 21:49:00 -04002665 * @phba: Pointer to HBA context object.
2666 * @pring: Pointer to driver SLI ring object.
2667 * @saveq: Pointer to the response iocb to be processed.
2668 *
2669 * This function is called by the ring event handler for non-fcp
2670 * rings when there is a new response iocb in the response ring.
2671 * The caller is not required to hold any locks. This function
2672 * gets the command iocb associated with the response iocb and
2673 * calls the completion handler for the command iocb. If there
2674 * is no completion handler, the function will free the resources
2675 * associated with command iocb. If the response iocb is for
2676 * an already aborted command iocb, the status of the completion
2677 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2678 * This function always returns 1.
2679 **/
dea31012005-04-17 16:05:31 -05002680static int
James Smart2e0fef82007-06-17 19:56:36 -05002681lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05002682 struct lpfc_iocbq *saveq)
2683{
James Smart2e0fef82007-06-17 19:56:36 -05002684 struct lpfc_iocbq *cmdiocbp;
dea31012005-04-17 16:05:31 -05002685 int rc = 1;
2686 unsigned long iflag;
2687
2688 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
James Smart2e0fef82007-06-17 19:56:36 -05002689 spin_lock_irqsave(&phba->hbalock, iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05002690 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
James Smart2e0fef82007-06-17 19:56:36 -05002691 spin_unlock_irqrestore(&phba->hbalock, iflag);
2692
dea31012005-04-17 16:05:31 -05002693 if (cmdiocbp) {
2694 if (cmdiocbp->iocb_cmpl) {
2695 /*
James Smartea2151b2008-09-07 11:52:10 -04002696 * If an ELS command failed send an event to mgmt
2697 * application.
2698 */
2699 if (saveq->iocb.ulpStatus &&
2700 (pring->ringno == LPFC_ELS_RING) &&
2701 (cmdiocbp->iocb.ulpCommand ==
2702 CMD_ELS_REQUEST64_CR))
2703 lpfc_send_els_failure_event(phba,
2704 cmdiocbp, saveq);
2705
2706 /*
dea31012005-04-17 16:05:31 -05002707 * Post all ELS completions to the worker thread.
2708 * All other are passed to the completion callback.
2709 */
2710 if (pring->ringno == LPFC_ELS_RING) {
James Smart341af102010-01-26 23:07:37 -05002711 if ((phba->sli_rev < LPFC_SLI_REV4) &&
2712 (cmdiocbp->iocb_flag &
2713 LPFC_DRIVER_ABORTED)) {
2714 spin_lock_irqsave(&phba->hbalock,
2715 iflag);
James Smart07951072007-04-25 09:51:38 -04002716 cmdiocbp->iocb_flag &=
2717 ~LPFC_DRIVER_ABORTED;
James Smart341af102010-01-26 23:07:37 -05002718 spin_unlock_irqrestore(&phba->hbalock,
2719 iflag);
James Smart07951072007-04-25 09:51:38 -04002720 saveq->iocb.ulpStatus =
2721 IOSTAT_LOCAL_REJECT;
2722 saveq->iocb.un.ulpWord[4] =
2723 IOERR_SLI_ABORTED;
James Smart0ff10d42008-01-11 01:52:36 -05002724
2725 /* Firmware could still be in progress
2726 * of DMAing payload, so don't free data
2727 * buffer till after a hbeat.
2728 */
James Smart341af102010-01-26 23:07:37 -05002729 spin_lock_irqsave(&phba->hbalock,
2730 iflag);
James Smart0ff10d42008-01-11 01:52:36 -05002731 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
James Smart341af102010-01-26 23:07:37 -05002732 spin_unlock_irqrestore(&phba->hbalock,
2733 iflag);
2734 }
James Smart0f65ff62010-02-26 14:14:23 -05002735 if (phba->sli_rev == LPFC_SLI_REV4) {
2736 if (saveq->iocb_flag &
2737 LPFC_EXCHANGE_BUSY) {
2738 /* Set cmdiocb flag for the
2739 * exchange busy so sgl (xri)
2740 * will not be released until
2741 * the abort xri is received
2742 * from hba.
2743 */
2744 spin_lock_irqsave(
2745 &phba->hbalock, iflag);
2746 cmdiocbp->iocb_flag |=
2747 LPFC_EXCHANGE_BUSY;
2748 spin_unlock_irqrestore(
2749 &phba->hbalock, iflag);
2750 }
2751 if (cmdiocbp->iocb_flag &
2752 LPFC_DRIVER_ABORTED) {
2753 /*
2754 * Clear LPFC_DRIVER_ABORTED
2755 * bit in case it was driver
2756 * initiated abort.
2757 */
2758 spin_lock_irqsave(
2759 &phba->hbalock, iflag);
2760 cmdiocbp->iocb_flag &=
2761 ~LPFC_DRIVER_ABORTED;
2762 spin_unlock_irqrestore(
2763 &phba->hbalock, iflag);
2764 cmdiocbp->iocb.ulpStatus =
2765 IOSTAT_LOCAL_REJECT;
2766 cmdiocbp->iocb.un.ulpWord[4] =
2767 IOERR_ABORT_REQUESTED;
2768 /*
2769 * For SLI4, irsiocb contains
2770 * NO_XRI in sli_xritag, it
2771 * shall not affect releasing
2772 * sgl (xri) process.
2773 */
2774 saveq->iocb.ulpStatus =
2775 IOSTAT_LOCAL_REJECT;
2776 saveq->iocb.un.ulpWord[4] =
2777 IOERR_SLI_ABORTED;
2778 spin_lock_irqsave(
2779 &phba->hbalock, iflag);
2780 saveq->iocb_flag |=
2781 LPFC_DELAY_MEM_FREE;
2782 spin_unlock_irqrestore(
2783 &phba->hbalock, iflag);
2784 }
James Smart07951072007-04-25 09:51:38 -04002785 }
dea31012005-04-17 16:05:31 -05002786 }
James Smart2e0fef82007-06-17 19:56:36 -05002787 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
James Bottomley604a3e32005-10-29 10:28:33 -05002788 } else
2789 lpfc_sli_release_iocbq(phba, cmdiocbp);
dea31012005-04-17 16:05:31 -05002790 } else {
2791 /*
2792 * Unknown initiating command based on the response iotag.
2793 * This could be the case on the ELS ring because of
2794 * lpfc_els_abort().
2795 */
2796 if (pring->ringno != LPFC_ELS_RING) {
2797 /*
2798 * Ring <ringno> handler: unexpected completion IoTag
2799 * <IoTag>
2800 */
James Smarta257bf92009-04-06 18:48:10 -04002801 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002802 "0322 Ring %d handler: "
2803 "unexpected completion IoTag x%x "
2804 "Data: x%x x%x x%x x%x\n",
2805 pring->ringno,
2806 saveq->iocb.ulpIoTag,
2807 saveq->iocb.ulpStatus,
2808 saveq->iocb.un.ulpWord[4],
2809 saveq->iocb.ulpCommand,
2810 saveq->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002811 }
2812 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002813
dea31012005-04-17 16:05:31 -05002814 return rc;
2815}
2816
James Smarte59058c2008-08-24 21:49:00 -04002817/**
James Smart3621a712009-04-06 18:47:14 -04002818 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
James Smarte59058c2008-08-24 21:49:00 -04002819 * @phba: Pointer to HBA context object.
2820 * @pring: Pointer to driver SLI ring object.
2821 *
2822 * This function is called from the iocb ring event handlers when
2823 * put pointer is ahead of the get pointer for a ring. This function signal
2824 * an error attention condition to the worker thread and the worker
2825 * thread will transition the HBA to offline state.
2826 **/
James Smart2e0fef82007-06-17 19:56:36 -05002827static void
2828lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002829{
James Smart34b02dc2008-08-24 21:49:55 -04002830 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002831 /*
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02002832 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002833 * rsp ring <portRspMax>
2834 */
2835 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002836 "0312 Ring %d handler: portRspPut %d "
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02002837 "is bigger than rsp ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04002838 pring->ringno, le32_to_cpu(pgp->rspPutInx),
James Smart7e56aa22012-08-03 12:35:34 -04002839 pring->sli.sli3.numRiocb);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002840
James Smart2e0fef82007-06-17 19:56:36 -05002841 phba->link_state = LPFC_HBA_ERROR;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002842
2843 /*
2844 * All error attention handlers are posted to
2845 * worker thread
2846 */
2847 phba->work_ha |= HA_ERATT;
2848 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -05002849
James Smart5e9d9b82008-06-14 22:52:53 -04002850 lpfc_worker_wake_up(phba);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002851
2852 return;
2853}
2854
James Smarte59058c2008-08-24 21:49:00 -04002855/**
James Smart3621a712009-04-06 18:47:14 -04002856 * lpfc_poll_eratt - Error attention polling timer timeout handler
James Smart93996272008-08-24 21:50:30 -04002857 * @ptr: Pointer to address of HBA context object.
2858 *
2859 * This function is invoked by the Error Attention polling timer when the
2860 * timer times out. It will check the SLI Error Attention register for
2861 * possible attention events. If so, it will post an Error Attention event
2862 * and wake up worker thread to process it. Otherwise, it will set up the
2863 * Error Attention polling timer for the next poll.
2864 **/
2865void lpfc_poll_eratt(unsigned long ptr)
2866{
2867 struct lpfc_hba *phba;
James Smartaa6fbb72012-08-03 12:36:03 -04002868 uint32_t eratt = 0, rem;
2869 uint64_t sli_intr, cnt;
James Smart93996272008-08-24 21:50:30 -04002870
2871 phba = (struct lpfc_hba *)ptr;
2872
James Smartaa6fbb72012-08-03 12:36:03 -04002873 /* Here we will also keep track of interrupts per sec of the hba */
2874 sli_intr = phba->sli.slistat.sli_intr;
2875
2876 if (phba->sli.slistat.sli_prev_intr > sli_intr)
2877 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
2878 sli_intr);
2879 else
2880 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
2881
2882 /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
2883 rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
2884 phba->sli.slistat.sli_ips = cnt;
2885
2886 phba->sli.slistat.sli_prev_intr = sli_intr;
2887
James Smart93996272008-08-24 21:50:30 -04002888 /* Check chip HA register for error event */
2889 eratt = lpfc_sli_check_eratt(phba);
2890
2891 if (eratt)
2892 /* Tell the worker thread there is work to do */
2893 lpfc_worker_wake_up(phba);
2894 else
2895 /* Restart the timer for next eratt poll */
James Smart256ec0d2013-04-17 20:14:58 -04002896 mod_timer(&phba->eratt_poll,
2897 jiffies +
2898 msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
James Smart93996272008-08-24 21:50:30 -04002899 return;
2900}
2901
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002902
James Smarte59058c2008-08-24 21:49:00 -04002903/**
James Smart3621a712009-04-06 18:47:14 -04002904 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
James Smarte59058c2008-08-24 21:49:00 -04002905 * @phba: Pointer to HBA context object.
2906 * @pring: Pointer to driver SLI ring object.
2907 * @mask: Host attention register mask for this ring.
2908 *
2909 * This function is called from the interrupt context when there is a ring
2910 * event for the fcp ring. The caller does not hold any lock.
2911 * The function processes each response iocb in the response ring until it
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002912 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
James Smarte59058c2008-08-24 21:49:00 -04002913 * LE bit set. The function will call the completion handler of the command iocb
2914 * if the response iocb indicates a completion for a command iocb or it is
2915 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2916 * function if this is an unsolicited iocb.
dea31012005-04-17 16:05:31 -05002917 * This routine presumes LPFC_FCP_RING handling and doesn't bother
James Smart45ed1192009-10-02 15:17:02 -04002918 * to check it explicitly.
2919 */
2920int
James Smart2e0fef82007-06-17 19:56:36 -05002921lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
2922 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05002923{
James Smart34b02dc2008-08-24 21:49:55 -04002924 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
dea31012005-04-17 16:05:31 -05002925 IOCB_t *irsp = NULL;
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04002926 IOCB_t *entry = NULL;
dea31012005-04-17 16:05:31 -05002927 struct lpfc_iocbq *cmdiocbq = NULL;
2928 struct lpfc_iocbq rspiocbq;
dea31012005-04-17 16:05:31 -05002929 uint32_t status;
2930 uint32_t portRspPut, portRspMax;
2931 int rc = 1;
2932 lpfc_iocb_type type;
2933 unsigned long iflag;
2934 uint32_t rsp_cmpl = 0;
dea31012005-04-17 16:05:31 -05002935
James Smart2e0fef82007-06-17 19:56:36 -05002936 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002937 pring->stats.iocb_event++;
2938
dea31012005-04-17 16:05:31 -05002939 /*
2940 * The next available response entry should never exceed the maximum
2941 * entries. If it does, treat it as an adapter hardware error.
2942 */
James Smart7e56aa22012-08-03 12:35:34 -04002943 portRspMax = pring->sli.sli3.numRiocb;
dea31012005-04-17 16:05:31 -05002944 portRspPut = le32_to_cpu(pgp->rspPutInx);
2945 if (unlikely(portRspPut >= portRspMax)) {
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002946 lpfc_sli_rsp_pointers_error(phba, pring);
James Smart2e0fef82007-06-17 19:56:36 -05002947 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002948 return 1;
2949 }
James Smart45ed1192009-10-02 15:17:02 -04002950 if (phba->fcp_ring_in_use) {
2951 spin_unlock_irqrestore(&phba->hbalock, iflag);
2952 return 1;
2953 } else
2954 phba->fcp_ring_in_use = 1;
dea31012005-04-17 16:05:31 -05002955
2956 rmb();
James Smart7e56aa22012-08-03 12:35:34 -04002957 while (pring->sli.sli3.rspidx != portRspPut) {
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04002958 /*
2959 * Fetch an entry off the ring and copy it into a local data
2960 * structure. The copy involves a byte-swap since the
2961 * network byte order and pci byte orders are different.
2962 */
James Smarted957682007-06-17 19:56:37 -05002963 entry = lpfc_resp_iocb(phba, pring);
James Smart858c9f62007-06-17 19:56:39 -05002964 phba->last_completion_time = jiffies;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002965
James Smart7e56aa22012-08-03 12:35:34 -04002966 if (++pring->sli.sli3.rspidx >= portRspMax)
2967 pring->sli.sli3.rspidx = 0;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002968
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04002969 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
2970 (uint32_t *) &rspiocbq.iocb,
James Smarted957682007-06-17 19:56:37 -05002971 phba->iocb_rsp_size);
James Smarta4bc3372006-12-02 13:34:16 -05002972 INIT_LIST_HEAD(&(rspiocbq.list));
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04002973 irsp = &rspiocbq.iocb;
2974
dea31012005-04-17 16:05:31 -05002975 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
2976 pring->stats.iocb_rsp++;
2977 rsp_cmpl++;
2978
2979 if (unlikely(irsp->ulpStatus)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002980 /*
2981 * If resource errors reported from HBA, reduce
2982 * queuedepths of the SCSI device.
2983 */
2984 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04002985 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
2986 IOERR_NO_RESOURCES)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002987 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart3772a992009-05-22 14:50:54 -04002988 phba->lpfc_rampdown_queue_depth(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002989 spin_lock_irqsave(&phba->hbalock, iflag);
2990 }
2991
dea31012005-04-17 16:05:31 -05002992 /* Rsp ring <ringno> error: IOCB */
2993 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002994 "0336 Rsp Ring %d error: IOCB Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05002995 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002996 pring->ringno,
James Smart92d7f7b2007-06-17 19:56:38 -05002997 irsp->un.ulpWord[0],
2998 irsp->un.ulpWord[1],
2999 irsp->un.ulpWord[2],
3000 irsp->un.ulpWord[3],
3001 irsp->un.ulpWord[4],
3002 irsp->un.ulpWord[5],
James Smartd7c255b2008-08-24 21:50:00 -04003003 *(uint32_t *)&irsp->un1,
3004 *((uint32_t *)&irsp->un1 + 1));
dea31012005-04-17 16:05:31 -05003005 }
3006
3007 switch (type) {
3008 case LPFC_ABORT_IOCB:
3009 case LPFC_SOL_IOCB:
3010 /*
3011 * Idle exchange closed via ABTS from port. No iocb
3012 * resources need to be recovered.
3013 */
3014 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04003015 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003016 "0333 IOCB cmd 0x%x"
James Smartdca94792006-08-01 07:34:08 -04003017 " processed. Skipping"
James Smart92d7f7b2007-06-17 19:56:38 -05003018 " completion\n",
James Smartdca94792006-08-01 07:34:08 -04003019 irsp->ulpCommand);
dea31012005-04-17 16:05:31 -05003020 break;
3021 }
3022
James Bottomley604a3e32005-10-29 10:28:33 -05003023 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3024 &rspiocbq);
James Smart0f65ff62010-02-26 14:14:23 -05003025 if (unlikely(!cmdiocbq))
3026 break;
3027 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3028 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3029 if (cmdiocbq->iocb_cmpl) {
3030 spin_unlock_irqrestore(&phba->hbalock, iflag);
3031 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
3032 &rspiocbq);
3033 spin_lock_irqsave(&phba->hbalock, iflag);
3034 }
dea31012005-04-17 16:05:31 -05003035 break;
James Smarta4bc3372006-12-02 13:34:16 -05003036 case LPFC_UNSOL_IOCB:
James Smart2e0fef82007-06-17 19:56:36 -05003037 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05003038 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05003039 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05003040 break;
dea31012005-04-17 16:05:31 -05003041 default:
3042 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3043 char adaptermsg[LPFC_MAX_ADPTMSG];
3044 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3045 memcpy(&adaptermsg[0], (uint8_t *) irsp,
3046 MAX_MSG_DATA);
Joe Perches898eb712007-10-18 03:06:30 -07003047 dev_warn(&((phba->pcidev)->dev),
3048 "lpfc%d: %s\n",
dea31012005-04-17 16:05:31 -05003049 phba->brd_no, adaptermsg);
3050 } else {
3051 /* Unknown IOCB command */
3052 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003053 "0334 Unknown IOCB command "
James Smart92d7f7b2007-06-17 19:56:38 -05003054 "Data: x%x, x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003055 type, irsp->ulpCommand,
James Smart92d7f7b2007-06-17 19:56:38 -05003056 irsp->ulpStatus,
3057 irsp->ulpIoTag,
3058 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05003059 }
3060 break;
3061 }
3062
3063 /*
3064 * The response IOCB has been processed. Update the ring
3065 * pointer in SLIM. If the port response put pointer has not
3066 * been updated, sync the pgp->rspPutInx and fetch the new port
3067 * response put pointer.
3068 */
James Smart7e56aa22012-08-03 12:35:34 -04003069 writel(pring->sli.sli3.rspidx,
3070 &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05003071
James Smart7e56aa22012-08-03 12:35:34 -04003072 if (pring->sli.sli3.rspidx == portRspPut)
dea31012005-04-17 16:05:31 -05003073 portRspPut = le32_to_cpu(pgp->rspPutInx);
3074 }
3075
3076 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
3077 pring->stats.iocb_rsp_full++;
3078 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3079 writel(status, phba->CAregaddr);
3080 readl(phba->CAregaddr);
3081 }
3082 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3083 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3084 pring->stats.iocb_cmd_empty++;
3085
3086 /* Force update of the local copy of cmdGetInx */
James Smart7e56aa22012-08-03 12:35:34 -04003087 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
dea31012005-04-17 16:05:31 -05003088 lpfc_sli_resume_iocb(phba, pring);
3089
3090 if ((pring->lpfc_sli_cmd_available))
3091 (pring->lpfc_sli_cmd_available) (phba, pring);
3092
3093 }
3094
James Smart45ed1192009-10-02 15:17:02 -04003095 phba->fcp_ring_in_use = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003096 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003097 return rc;
3098}
3099
James Smarte59058c2008-08-24 21:49:00 -04003100/**
James Smart3772a992009-05-22 14:50:54 -04003101 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3102 * @phba: Pointer to HBA context object.
3103 * @pring: Pointer to driver SLI ring object.
3104 * @rspiocbp: Pointer to driver response IOCB object.
3105 *
3106 * This function is called from the worker thread when there is a slow-path
3107 * response IOCB to process. This function chains all the response iocbs until
3108 * seeing the iocb with the LE bit set. The function will call
3109 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3110 * completion of a command iocb. The function will call the
3111 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3112 * The function frees the resources or calls the completion handler if this
3113 * iocb is an abort completion. The function returns NULL when the response
3114 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3115 * this function shall chain the iocb on to the iocb_continueq and return the
3116 * response iocb passed in.
3117 **/
3118static struct lpfc_iocbq *
3119lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3120 struct lpfc_iocbq *rspiocbp)
3121{
3122 struct lpfc_iocbq *saveq;
3123 struct lpfc_iocbq *cmdiocbp;
3124 struct lpfc_iocbq *next_iocb;
3125 IOCB_t *irsp = NULL;
3126 uint32_t free_saveq;
3127 uint8_t iocb_cmd_type;
3128 lpfc_iocb_type type;
3129 unsigned long iflag;
3130 int rc;
3131
3132 spin_lock_irqsave(&phba->hbalock, iflag);
3133 /* First add the response iocb to the countinueq list */
3134 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3135 pring->iocb_continueq_cnt++;
3136
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02003137 /* Now, determine whether the list is completed for processing */
James Smart3772a992009-05-22 14:50:54 -04003138 irsp = &rspiocbp->iocb;
3139 if (irsp->ulpLe) {
3140 /*
3141 * By default, the driver expects to free all resources
3142 * associated with this iocb completion.
3143 */
3144 free_saveq = 1;
3145 saveq = list_get_first(&pring->iocb_continueq,
3146 struct lpfc_iocbq, list);
3147 irsp = &(saveq->iocb);
3148 list_del_init(&pring->iocb_continueq);
3149 pring->iocb_continueq_cnt = 0;
3150
3151 pring->stats.iocb_rsp++;
3152
3153 /*
3154 * If resource errors reported from HBA, reduce
3155 * queuedepths of the SCSI device.
3156 */
3157 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04003158 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3159 IOERR_NO_RESOURCES)) {
James Smart3772a992009-05-22 14:50:54 -04003160 spin_unlock_irqrestore(&phba->hbalock, iflag);
3161 phba->lpfc_rampdown_queue_depth(phba);
3162 spin_lock_irqsave(&phba->hbalock, iflag);
3163 }
3164
3165 if (irsp->ulpStatus) {
3166 /* Rsp ring <ringno> error: IOCB */
3167 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3168 "0328 Rsp Ring %d error: "
3169 "IOCB Data: "
3170 "x%x x%x x%x x%x "
3171 "x%x x%x x%x x%x "
3172 "x%x x%x x%x x%x "
3173 "x%x x%x x%x x%x\n",
3174 pring->ringno,
3175 irsp->un.ulpWord[0],
3176 irsp->un.ulpWord[1],
3177 irsp->un.ulpWord[2],
3178 irsp->un.ulpWord[3],
3179 irsp->un.ulpWord[4],
3180 irsp->un.ulpWord[5],
3181 *(((uint32_t *) irsp) + 6),
3182 *(((uint32_t *) irsp) + 7),
3183 *(((uint32_t *) irsp) + 8),
3184 *(((uint32_t *) irsp) + 9),
3185 *(((uint32_t *) irsp) + 10),
3186 *(((uint32_t *) irsp) + 11),
3187 *(((uint32_t *) irsp) + 12),
3188 *(((uint32_t *) irsp) + 13),
3189 *(((uint32_t *) irsp) + 14),
3190 *(((uint32_t *) irsp) + 15));
3191 }
3192
3193 /*
3194 * Fetch the IOCB command type and call the correct completion
3195 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3196 * get freed back to the lpfc_iocb_list by the discovery
3197 * kernel thread.
3198 */
3199 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3200 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3201 switch (type) {
3202 case LPFC_SOL_IOCB:
3203 spin_unlock_irqrestore(&phba->hbalock, iflag);
3204 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3205 spin_lock_irqsave(&phba->hbalock, iflag);
3206 break;
3207
3208 case LPFC_UNSOL_IOCB:
3209 spin_unlock_irqrestore(&phba->hbalock, iflag);
3210 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3211 spin_lock_irqsave(&phba->hbalock, iflag);
3212 if (!rc)
3213 free_saveq = 0;
3214 break;
3215
3216 case LPFC_ABORT_IOCB:
3217 cmdiocbp = NULL;
3218 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
3219 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3220 saveq);
3221 if (cmdiocbp) {
3222 /* Call the specified completion routine */
3223 if (cmdiocbp->iocb_cmpl) {
3224 spin_unlock_irqrestore(&phba->hbalock,
3225 iflag);
3226 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3227 saveq);
3228 spin_lock_irqsave(&phba->hbalock,
3229 iflag);
3230 } else
3231 __lpfc_sli_release_iocbq(phba,
3232 cmdiocbp);
3233 }
3234 break;
3235
3236 case LPFC_UNKNOWN_IOCB:
3237 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3238 char adaptermsg[LPFC_MAX_ADPTMSG];
3239 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3240 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3241 MAX_MSG_DATA);
3242 dev_warn(&((phba->pcidev)->dev),
3243 "lpfc%d: %s\n",
3244 phba->brd_no, adaptermsg);
3245 } else {
3246 /* Unknown IOCB command */
3247 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3248 "0335 Unknown IOCB "
3249 "command Data: x%x "
3250 "x%x x%x x%x\n",
3251 irsp->ulpCommand,
3252 irsp->ulpStatus,
3253 irsp->ulpIoTag,
3254 irsp->ulpContext);
3255 }
3256 break;
3257 }
3258
3259 if (free_saveq) {
3260 list_for_each_entry_safe(rspiocbp, next_iocb,
3261 &saveq->list, list) {
James Smart61f35bf2013-05-31 17:03:48 -04003262 list_del_init(&rspiocbp->list);
James Smart3772a992009-05-22 14:50:54 -04003263 __lpfc_sli_release_iocbq(phba, rspiocbp);
3264 }
3265 __lpfc_sli_release_iocbq(phba, saveq);
3266 }
3267 rspiocbp = NULL;
3268 }
3269 spin_unlock_irqrestore(&phba->hbalock, iflag);
3270 return rspiocbp;
3271}
3272
3273/**
3274 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
James Smarte59058c2008-08-24 21:49:00 -04003275 * @phba: Pointer to HBA context object.
3276 * @pring: Pointer to driver SLI ring object.
3277 * @mask: Host attention register mask for this ring.
3278 *
James Smart3772a992009-05-22 14:50:54 -04003279 * This routine wraps the actual slow_ring event process routine from the
3280 * API jump table function pointer from the lpfc_hba struct.
James Smarte59058c2008-08-24 21:49:00 -04003281 **/
James Smart3772a992009-05-22 14:50:54 -04003282void
James Smart2e0fef82007-06-17 19:56:36 -05003283lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
3284 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05003285{
James Smart3772a992009-05-22 14:50:54 -04003286 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
3287}
3288
3289/**
3290 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3291 * @phba: Pointer to HBA context object.
3292 * @pring: Pointer to driver SLI ring object.
3293 * @mask: Host attention register mask for this ring.
3294 *
3295 * This function is called from the worker thread when there is a ring event
3296 * for non-fcp rings. The caller does not hold any lock. The function will
3297 * remove each response iocb in the response ring and calls the handle
3298 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3299 **/
3300static void
3301lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
3302 struct lpfc_sli_ring *pring, uint32_t mask)
3303{
James Smart34b02dc2008-08-24 21:49:55 -04003304 struct lpfc_pgp *pgp;
dea31012005-04-17 16:05:31 -05003305 IOCB_t *entry;
3306 IOCB_t *irsp = NULL;
3307 struct lpfc_iocbq *rspiocbp = NULL;
dea31012005-04-17 16:05:31 -05003308 uint32_t portRspPut, portRspMax;
dea31012005-04-17 16:05:31 -05003309 unsigned long iflag;
James Smart3772a992009-05-22 14:50:54 -04003310 uint32_t status;
dea31012005-04-17 16:05:31 -05003311
James Smart34b02dc2008-08-24 21:49:55 -04003312 pgp = &phba->port_gp[pring->ringno];
James Smart2e0fef82007-06-17 19:56:36 -05003313 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003314 pring->stats.iocb_event++;
3315
dea31012005-04-17 16:05:31 -05003316 /*
3317 * The next available response entry should never exceed the maximum
3318 * entries. If it does, treat it as an adapter hardware error.
3319 */
James Smart7e56aa22012-08-03 12:35:34 -04003320 portRspMax = pring->sli.sli3.numRiocb;
dea31012005-04-17 16:05:31 -05003321 portRspPut = le32_to_cpu(pgp->rspPutInx);
3322 if (portRspPut >= portRspMax) {
3323 /*
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003324 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
dea31012005-04-17 16:05:31 -05003325 * rsp ring <portRspMax>
3326 */
James Smarted957682007-06-17 19:56:37 -05003327 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003328 "0303 Ring %d handler: portRspPut %d "
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003329 "is bigger than rsp ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003330 pring->ringno, portRspPut, portRspMax);
dea31012005-04-17 16:05:31 -05003331
James Smart2e0fef82007-06-17 19:56:36 -05003332 phba->link_state = LPFC_HBA_ERROR;
3333 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003334
3335 phba->work_hs = HS_FFER3;
3336 lpfc_handle_eratt(phba);
3337
James Smart3772a992009-05-22 14:50:54 -04003338 return;
dea31012005-04-17 16:05:31 -05003339 }
3340
3341 rmb();
James Smart7e56aa22012-08-03 12:35:34 -04003342 while (pring->sli.sli3.rspidx != portRspPut) {
dea31012005-04-17 16:05:31 -05003343 /*
3344 * Build a completion list and call the appropriate handler.
3345 * The process is to get the next available response iocb, get
3346 * a free iocb from the list, copy the response data into the
3347 * free iocb, insert to the continuation list, and update the
3348 * next response index to slim. This process makes response
3349 * iocb's in the ring available to DMA as fast as possible but
3350 * pays a penalty for a copy operation. Since the iocb is
3351 * only 32 bytes, this penalty is considered small relative to
3352 * the PCI reads for register values and a slim write. When
3353 * the ulpLe field is set, the entire Command has been
3354 * received.
3355 */
James Smarted957682007-06-17 19:56:37 -05003356 entry = lpfc_resp_iocb(phba, pring);
3357
James Smart858c9f62007-06-17 19:56:39 -05003358 phba->last_completion_time = jiffies;
James Smart2e0fef82007-06-17 19:56:36 -05003359 rspiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003360 if (rspiocbp == NULL) {
3361 printk(KERN_ERR "%s: out of buffers! Failing "
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07003362 "completion.\n", __func__);
dea31012005-04-17 16:05:31 -05003363 break;
3364 }
3365
James Smarted957682007-06-17 19:56:37 -05003366 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
3367 phba->iocb_rsp_size);
dea31012005-04-17 16:05:31 -05003368 irsp = &rspiocbp->iocb;
3369
James Smart7e56aa22012-08-03 12:35:34 -04003370 if (++pring->sli.sli3.rspidx >= portRspMax)
3371 pring->sli.sli3.rspidx = 0;
dea31012005-04-17 16:05:31 -05003372
James Smarta58cbd52007-08-02 11:09:43 -04003373 if (pring->ringno == LPFC_ELS_RING) {
3374 lpfc_debugfs_slow_ring_trc(phba,
3375 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3376 *(((uint32_t *) irsp) + 4),
3377 *(((uint32_t *) irsp) + 6),
3378 *(((uint32_t *) irsp) + 7));
3379 }
3380
James Smart7e56aa22012-08-03 12:35:34 -04003381 writel(pring->sli.sli3.rspidx,
3382 &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05003383
James Smart3772a992009-05-22 14:50:54 -04003384 spin_unlock_irqrestore(&phba->hbalock, iflag);
3385 /* Handle the response IOCB */
3386 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
3387 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003388
3389 /*
3390 * If the port response put pointer has not been updated, sync
3391 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3392 * response put pointer.
3393 */
James Smart7e56aa22012-08-03 12:35:34 -04003394 if (pring->sli.sli3.rspidx == portRspPut) {
dea31012005-04-17 16:05:31 -05003395 portRspPut = le32_to_cpu(pgp->rspPutInx);
3396 }
James Smart7e56aa22012-08-03 12:35:34 -04003397 } /* while (pring->sli.sli3.rspidx != portRspPut) */
dea31012005-04-17 16:05:31 -05003398
James Smart92d7f7b2007-06-17 19:56:38 -05003399 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
dea31012005-04-17 16:05:31 -05003400 /* At least one response entry has been freed */
3401 pring->stats.iocb_rsp_full++;
3402 /* SET RxRE_RSP in Chip Att register */
3403 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3404 writel(status, phba->CAregaddr);
3405 readl(phba->CAregaddr); /* flush */
3406 }
3407 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3408 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3409 pring->stats.iocb_cmd_empty++;
3410
3411 /* Force update of the local copy of cmdGetInx */
James Smart7e56aa22012-08-03 12:35:34 -04003412 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
dea31012005-04-17 16:05:31 -05003413 lpfc_sli_resume_iocb(phba, pring);
3414
3415 if ((pring->lpfc_sli_cmd_available))
3416 (pring->lpfc_sli_cmd_available) (phba, pring);
3417
3418 }
3419
James Smart2e0fef82007-06-17 19:56:36 -05003420 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart3772a992009-05-22 14:50:54 -04003421 return;
dea31012005-04-17 16:05:31 -05003422}
3423
James Smarte59058c2008-08-24 21:49:00 -04003424/**
James Smart4f774512009-05-22 14:52:35 -04003425 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3426 * @phba: Pointer to HBA context object.
3427 * @pring: Pointer to driver SLI ring object.
3428 * @mask: Host attention register mask for this ring.
3429 *
3430 * This function is called from the worker thread when there is a pending
3431 * ELS response iocb on the driver internal slow-path response iocb worker
3432 * queue. The caller does not hold any lock. The function will remove each
3433 * response iocb from the response worker queue and calls the handle
3434 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3435 **/
3436static void
3437lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3438 struct lpfc_sli_ring *pring, uint32_t mask)
3439{
3440 struct lpfc_iocbq *irspiocbq;
James Smart4d9ab992009-10-02 15:16:39 -04003441 struct hbq_dmabuf *dmabuf;
3442 struct lpfc_cq_event *cq_event;
James Smart4f774512009-05-22 14:52:35 -04003443 unsigned long iflag;
3444
James Smart45ed1192009-10-02 15:17:02 -04003445 spin_lock_irqsave(&phba->hbalock, iflag);
3446 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
3447 spin_unlock_irqrestore(&phba->hbalock, iflag);
3448 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
James Smart4f774512009-05-22 14:52:35 -04003449 /* Get the response iocb from the head of work queue */
3450 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart45ed1192009-10-02 15:17:02 -04003451 list_remove_head(&phba->sli4_hba.sp_queue_event,
James Smart4d9ab992009-10-02 15:16:39 -04003452 cq_event, struct lpfc_cq_event, list);
James Smart4f774512009-05-22 14:52:35 -04003453 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart4d9ab992009-10-02 15:16:39 -04003454
3455 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
3456 case CQE_CODE_COMPL_WQE:
3457 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
3458 cq_event);
James Smart45ed1192009-10-02 15:17:02 -04003459 /* Translate ELS WCQE to response IOCBQ */
3460 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
3461 irspiocbq);
3462 if (irspiocbq)
3463 lpfc_sli_sp_handle_rspiocb(phba, pring,
3464 irspiocbq);
James Smart4d9ab992009-10-02 15:16:39 -04003465 break;
3466 case CQE_CODE_RECEIVE:
James Smart7851fe22011-07-22 18:36:52 -04003467 case CQE_CODE_RECEIVE_V1:
James Smart4d9ab992009-10-02 15:16:39 -04003468 dmabuf = container_of(cq_event, struct hbq_dmabuf,
3469 cq_event);
3470 lpfc_sli4_handle_received_buffer(phba, dmabuf);
3471 break;
3472 default:
3473 break;
3474 }
James Smart4f774512009-05-22 14:52:35 -04003475 }
3476}
3477
3478/**
James Smart3621a712009-04-06 18:47:14 -04003479 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
James Smarte59058c2008-08-24 21:49:00 -04003480 * @phba: Pointer to HBA context object.
3481 * @pring: Pointer to driver SLI ring object.
3482 *
3483 * This function aborts all iocbs in the given ring and frees all the iocb
3484 * objects in txq. This function issues an abort iocb for all the iocb commands
3485 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3486 * the return of this function. The caller is not required to hold any locks.
3487 **/
James Smart2e0fef82007-06-17 19:56:36 -05003488void
dea31012005-04-17 16:05:31 -05003489lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3490{
James Smart2534ba72007-04-25 09:52:20 -04003491 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05003492 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -05003493
James Smart92d7f7b2007-06-17 19:56:38 -05003494 if (pring->ringno == LPFC_ELS_RING) {
3495 lpfc_fabric_abort_hba(phba);
3496 }
3497
dea31012005-04-17 16:05:31 -05003498 /* Error everything on txq and txcmplq
3499 * First do the txq.
3500 */
James Smartdb55fba2014-04-04 13:52:02 -04003501 if (phba->sli_rev >= LPFC_SLI_REV4) {
3502 spin_lock_irq(&pring->ring_lock);
3503 list_splice_init(&pring->txq, &completions);
3504 pring->txq_cnt = 0;
3505 spin_unlock_irq(&pring->ring_lock);
dea31012005-04-17 16:05:31 -05003506
James Smartdb55fba2014-04-04 13:52:02 -04003507 spin_lock_irq(&phba->hbalock);
3508 /* Next issue ABTS for everything on the txcmplq */
3509 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3510 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3511 spin_unlock_irq(&phba->hbalock);
3512 } else {
3513 spin_lock_irq(&phba->hbalock);
3514 list_splice_init(&pring->txq, &completions);
3515 pring->txq_cnt = 0;
James Smart2534ba72007-04-25 09:52:20 -04003516
James Smartdb55fba2014-04-04 13:52:02 -04003517 /* Next issue ABTS for everything on the txcmplq */
3518 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3519 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3520 spin_unlock_irq(&phba->hbalock);
3521 }
James Smart2534ba72007-04-25 09:52:20 -04003522
James Smarta257bf92009-04-06 18:48:10 -04003523 /* Cancel all the IOCBs from the completions list */
3524 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3525 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05003526}
3527
James Smarte59058c2008-08-24 21:49:00 -04003528/**
James Smartdb55fba2014-04-04 13:52:02 -04003529 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3530 * @phba: Pointer to HBA context object.
3531 * @pring: Pointer to driver SLI ring object.
3532 *
3533 * This function aborts all iocbs in FCP rings and frees all the iocb
3534 * objects in txq. This function issues an abort iocb for all the iocb commands
3535 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3536 * the return of this function. The caller is not required to hold any locks.
3537 **/
3538void
3539lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
3540{
3541 struct lpfc_sli *psli = &phba->sli;
3542 struct lpfc_sli_ring *pring;
3543 uint32_t i;
3544
3545 /* Look on all the FCP Rings for the iotag */
3546 if (phba->sli_rev >= LPFC_SLI_REV4) {
3547 for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
3548 pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
3549 lpfc_sli_abort_iocb_ring(phba, pring);
3550 }
3551 } else {
3552 pring = &psli->ring[psli->fcp_ring];
3553 lpfc_sli_abort_iocb_ring(phba, pring);
3554 }
3555}
3556
3557
3558/**
James Smart3621a712009-04-06 18:47:14 -04003559 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
James Smarta8e497d2008-08-24 21:50:11 -04003560 * @phba: Pointer to HBA context object.
3561 *
3562 * This function flushes all iocbs in the fcp ring and frees all the iocb
3563 * objects in txq and txcmplq. This function will not issue abort iocbs
3564 * for all the iocb commands in txcmplq, they will just be returned with
3565 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3566 * slot has been permanently disabled.
3567 **/
3568void
3569lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3570{
3571 LIST_HEAD(txq);
3572 LIST_HEAD(txcmplq);
James Smarta8e497d2008-08-24 21:50:11 -04003573 struct lpfc_sli *psli = &phba->sli;
3574 struct lpfc_sli_ring *pring;
James Smartdb55fba2014-04-04 13:52:02 -04003575 uint32_t i;
James Smarta8e497d2008-08-24 21:50:11 -04003576
3577 spin_lock_irq(&phba->hbalock);
James Smart4f2e66c2012-05-09 21:17:07 -04003578 /* Indicate the I/O queues are flushed */
3579 phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
James Smarta8e497d2008-08-24 21:50:11 -04003580 spin_unlock_irq(&phba->hbalock);
3581
James Smartdb55fba2014-04-04 13:52:02 -04003582 /* Look on all the FCP Rings for the iotag */
3583 if (phba->sli_rev >= LPFC_SLI_REV4) {
3584 for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
3585 pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
James Smarta8e497d2008-08-24 21:50:11 -04003586
James Smartdb55fba2014-04-04 13:52:02 -04003587 spin_lock_irq(&pring->ring_lock);
3588 /* Retrieve everything on txq */
3589 list_splice_init(&pring->txq, &txq);
3590 /* Retrieve everything on the txcmplq */
3591 list_splice_init(&pring->txcmplq, &txcmplq);
3592 pring->txq_cnt = 0;
3593 pring->txcmplq_cnt = 0;
3594 spin_unlock_irq(&pring->ring_lock);
3595
3596 /* Flush the txq */
3597 lpfc_sli_cancel_iocbs(phba, &txq,
3598 IOSTAT_LOCAL_REJECT,
3599 IOERR_SLI_DOWN);
3600 /* Flush the txcmpq */
3601 lpfc_sli_cancel_iocbs(phba, &txcmplq,
3602 IOSTAT_LOCAL_REJECT,
3603 IOERR_SLI_DOWN);
3604 }
3605 } else {
3606 pring = &psli->ring[psli->fcp_ring];
3607
3608 spin_lock_irq(&phba->hbalock);
3609 /* Retrieve everything on txq */
3610 list_splice_init(&pring->txq, &txq);
3611 /* Retrieve everything on the txcmplq */
3612 list_splice_init(&pring->txcmplq, &txcmplq);
3613 pring->txq_cnt = 0;
3614 pring->txcmplq_cnt = 0;
3615 spin_unlock_irq(&phba->hbalock);
3616
3617 /* Flush the txq */
3618 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3619 IOERR_SLI_DOWN);
3620 /* Flush the txcmpq */
3621 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3622 IOERR_SLI_DOWN);
3623 }
James Smarta8e497d2008-08-24 21:50:11 -04003624}
3625
3626/**
James Smart3772a992009-05-22 14:50:54 -04003627 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
James Smarte59058c2008-08-24 21:49:00 -04003628 * @phba: Pointer to HBA context object.
3629 * @mask: Bit mask to be checked.
3630 *
3631 * This function reads the host status register and compares
3632 * with the provided bit mask to check if HBA completed
3633 * the restart. This function will wait in a loop for the
3634 * HBA to complete restart. If the HBA does not restart within
3635 * 15 iterations, the function will reset the HBA again. The
3636 * function returns 1 when HBA fail to restart otherwise returns
3637 * zero.
3638 **/
James Smart3772a992009-05-22 14:50:54 -04003639static int
3640lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
dea31012005-04-17 16:05:31 -05003641{
Jamie Wellnitz41415862006-02-28 19:25:27 -05003642 uint32_t status;
3643 int i = 0;
3644 int retval = 0;
dea31012005-04-17 16:05:31 -05003645
Jamie Wellnitz41415862006-02-28 19:25:27 -05003646 /* Read the HBA Host Status Register */
James Smart9940b972011-03-11 16:06:12 -05003647 if (lpfc_readl(phba->HSregaddr, &status))
3648 return 1;
dea31012005-04-17 16:05:31 -05003649
Jamie Wellnitz41415862006-02-28 19:25:27 -05003650 /*
3651 * Check status register every 100ms for 5 retries, then every
3652 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3653 * every 2.5 sec for 4.
3654 * Break our of the loop if errors occurred during init.
3655 */
3656 while (((status & mask) != mask) &&
3657 !(status & HS_FFERM) &&
3658 i++ < 20) {
dea31012005-04-17 16:05:31 -05003659
Jamie Wellnitz41415862006-02-28 19:25:27 -05003660 if (i <= 5)
3661 msleep(10);
3662 else if (i <= 10)
3663 msleep(500);
3664 else
3665 msleep(2500);
dea31012005-04-17 16:05:31 -05003666
Jamie Wellnitz41415862006-02-28 19:25:27 -05003667 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05003668 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05003669 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003670 lpfc_sli_brdrestart(phba);
3671 }
3672 /* Read the HBA Host Status Register */
James Smart9940b972011-03-11 16:06:12 -05003673 if (lpfc_readl(phba->HSregaddr, &status)) {
3674 retval = 1;
3675 break;
3676 }
dea31012005-04-17 16:05:31 -05003677 }
dea31012005-04-17 16:05:31 -05003678
Jamie Wellnitz41415862006-02-28 19:25:27 -05003679 /* Check to see if any errors occurred during init */
3680 if ((status & HS_FFERM) || (i >= 20)) {
James Smarte40a02c2010-02-26 14:13:54 -05003681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3682 "2751 Adapter failed to restart, "
3683 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3684 status,
3685 readl(phba->MBslimaddr + 0xa8),
3686 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05003687 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003688 retval = 1;
3689 }
dea31012005-04-17 16:05:31 -05003690
Jamie Wellnitz41415862006-02-28 19:25:27 -05003691 return retval;
dea31012005-04-17 16:05:31 -05003692}
3693
James Smartda0436e2009-05-22 14:51:39 -04003694/**
3695 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3696 * @phba: Pointer to HBA context object.
3697 * @mask: Bit mask to be checked.
3698 *
3699 * This function checks the host status register to check if HBA is
3700 * ready. This function will wait in a loop for the HBA to be ready
3701 * If the HBA is not ready , the function will will reset the HBA PCI
3702 * function again. The function returns 1 when HBA fail to be ready
3703 * otherwise returns zero.
3704 **/
3705static int
3706lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3707{
3708 uint32_t status;
3709 int retval = 0;
3710
3711 /* Read the HBA Host Status Register */
3712 status = lpfc_sli4_post_status_check(phba);
3713
3714 if (status) {
3715 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3716 lpfc_sli_brdrestart(phba);
3717 status = lpfc_sli4_post_status_check(phba);
3718 }
3719
3720 /* Check to see if any errors occurred during init */
3721 if (status) {
3722 phba->link_state = LPFC_HBA_ERROR;
3723 retval = 1;
3724 } else
3725 phba->sli4_hba.intr_enable = 0;
3726
3727 return retval;
3728}
3729
3730/**
3731 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3732 * @phba: Pointer to HBA context object.
3733 * @mask: Bit mask to be checked.
3734 *
3735 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3736 * from the API jump table function pointer from the lpfc_hba struct.
3737 **/
3738int
3739lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3740{
3741 return phba->lpfc_sli_brdready(phba, mask);
3742}
3743
James Smart92908312006-03-07 15:04:13 -05003744#define BARRIER_TEST_PATTERN (0xdeadbeef)
3745
James Smarte59058c2008-08-24 21:49:00 -04003746/**
James Smart3621a712009-04-06 18:47:14 -04003747 * lpfc_reset_barrier - Make HBA ready for HBA reset
James Smarte59058c2008-08-24 21:49:00 -04003748 * @phba: Pointer to HBA context object.
3749 *
James Smart1b511972011-12-13 13:23:09 -05003750 * This function is called before resetting an HBA. This function is called
3751 * with hbalock held and requests HBA to quiesce DMAs before a reset.
James Smarte59058c2008-08-24 21:49:00 -04003752 **/
James Smart2e0fef82007-06-17 19:56:36 -05003753void lpfc_reset_barrier(struct lpfc_hba *phba)
James Smart92908312006-03-07 15:04:13 -05003754{
James Smart65a29c12006-07-06 15:50:50 -04003755 uint32_t __iomem *resp_buf;
3756 uint32_t __iomem *mbox_buf;
James Smart92908312006-03-07 15:04:13 -05003757 volatile uint32_t mbox;
James Smart9940b972011-03-11 16:06:12 -05003758 uint32_t hc_copy, ha_copy, resp_data;
James Smart92908312006-03-07 15:04:13 -05003759 int i;
3760 uint8_t hdrtype;
3761
3762 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3763 if (hdrtype != 0x80 ||
3764 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3765 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3766 return;
3767
3768 /*
3769 * Tell the other part of the chip to suspend temporarily all
3770 * its DMA activity.
3771 */
James Smart65a29c12006-07-06 15:50:50 -04003772 resp_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05003773
3774 /* Disable the error attention */
James Smart9940b972011-03-11 16:06:12 -05003775 if (lpfc_readl(phba->HCregaddr, &hc_copy))
3776 return;
James Smart92908312006-03-07 15:04:13 -05003777 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3778 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003779 phba->link_flag |= LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05003780
James Smart9940b972011-03-11 16:06:12 -05003781 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3782 return;
3783 if (ha_copy & HA_ERATT) {
James Smart92908312006-03-07 15:04:13 -05003784 /* Clear Chip error bit */
3785 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05003786 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05003787 }
3788
3789 mbox = 0;
3790 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
3791 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
3792
3793 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
James Smart65a29c12006-07-06 15:50:50 -04003794 mbox_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05003795 writel(mbox, mbox_buf);
3796
James Smart9940b972011-03-11 16:06:12 -05003797 for (i = 0; i < 50; i++) {
3798 if (lpfc_readl((resp_buf + 1), &resp_data))
3799 return;
3800 if (resp_data != ~(BARRIER_TEST_PATTERN))
3801 mdelay(1);
3802 else
3803 break;
3804 }
3805 resp_data = 0;
3806 if (lpfc_readl((resp_buf + 1), &resp_data))
3807 return;
3808 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
James Smartf4b4c682009-05-22 14:53:12 -04003809 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
James Smart2e0fef82007-06-17 19:56:36 -05003810 phba->pport->stopped)
James Smart92908312006-03-07 15:04:13 -05003811 goto restore_hc;
3812 else
3813 goto clear_errat;
3814 }
3815
3816 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
James Smart9940b972011-03-11 16:06:12 -05003817 resp_data = 0;
3818 for (i = 0; i < 500; i++) {
3819 if (lpfc_readl(resp_buf, &resp_data))
3820 return;
3821 if (resp_data != mbox)
3822 mdelay(1);
3823 else
3824 break;
3825 }
James Smart92908312006-03-07 15:04:13 -05003826
3827clear_errat:
3828
James Smart9940b972011-03-11 16:06:12 -05003829 while (++i < 500) {
3830 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3831 return;
3832 if (!(ha_copy & HA_ERATT))
3833 mdelay(1);
3834 else
3835 break;
3836 }
James Smart92908312006-03-07 15:04:13 -05003837
3838 if (readl(phba->HAregaddr) & HA_ERATT) {
3839 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05003840 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05003841 }
3842
3843restore_hc:
James Smart2e0fef82007-06-17 19:56:36 -05003844 phba->link_flag &= ~LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05003845 writel(hc_copy, phba->HCregaddr);
3846 readl(phba->HCregaddr); /* flush */
3847}
3848
James Smarte59058c2008-08-24 21:49:00 -04003849/**
James Smart3621a712009-04-06 18:47:14 -04003850 * lpfc_sli_brdkill - Issue a kill_board mailbox command
James Smarte59058c2008-08-24 21:49:00 -04003851 * @phba: Pointer to HBA context object.
3852 *
3853 * This function issues a kill_board mailbox command and waits for
3854 * the error attention interrupt. This function is called for stopping
3855 * the firmware processing. The caller is not required to hold any
3856 * locks. This function calls lpfc_hba_down_post function to free
3857 * any pending commands after the kill. The function will return 1 when it
3858 * fails to kill the board else will return 0.
3859 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05003860int
James Smart2e0fef82007-06-17 19:56:36 -05003861lpfc_sli_brdkill(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003862{
Jamie Wellnitz41415862006-02-28 19:25:27 -05003863 struct lpfc_sli *psli;
3864 LPFC_MBOXQ_t *pmb;
3865 uint32_t status;
3866 uint32_t ha_copy;
3867 int retval;
3868 int i = 0;
3869
3870 psli = &phba->sli;
3871
3872 /* Kill HBA */
James Smarted957682007-06-17 19:56:37 -05003873 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003874 "0329 Kill HBA Data: x%x x%x\n",
3875 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05003876
James Smart98c9ea52007-10-27 13:37:33 -04003877 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3878 if (!pmb)
Jamie Wellnitz41415862006-02-28 19:25:27 -05003879 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003880
3881 /* Disable the error attention */
James Smart2e0fef82007-06-17 19:56:36 -05003882 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05003883 if (lpfc_readl(phba->HCregaddr, &status)) {
3884 spin_unlock_irq(&phba->hbalock);
3885 mempool_free(pmb, phba->mbox_mem_pool);
3886 return 1;
3887 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05003888 status &= ~HC_ERINT_ENA;
3889 writel(status, phba->HCregaddr);
3890 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003891 phba->link_flag |= LS_IGNORE_ERATT;
3892 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05003893
3894 lpfc_kill_board(phba, pmb);
3895 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3896 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3897
3898 if (retval != MBX_SUCCESS) {
3899 if (retval != MBX_BUSY)
3900 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte40a02c2010-02-26 14:13:54 -05003901 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3902 "2752 KILL_BOARD command failed retval %d\n",
3903 retval);
James Smart2e0fef82007-06-17 19:56:36 -05003904 spin_lock_irq(&phba->hbalock);
3905 phba->link_flag &= ~LS_IGNORE_ERATT;
3906 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05003907 return 1;
3908 }
3909
James Smartf4b4c682009-05-22 14:53:12 -04003910 spin_lock_irq(&phba->hbalock);
3911 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
3912 spin_unlock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -05003913
Jamie Wellnitz41415862006-02-28 19:25:27 -05003914 mempool_free(pmb, phba->mbox_mem_pool);
3915
3916 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3917 * attention every 100ms for 3 seconds. If we don't get ERATT after
3918 * 3 seconds we still set HBA_ERROR state because the status of the
3919 * board is now undefined.
3920 */
James Smart9940b972011-03-11 16:06:12 -05003921 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3922 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003923 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
3924 mdelay(100);
James Smart9940b972011-03-11 16:06:12 -05003925 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3926 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003927 }
3928
3929 del_timer_sync(&psli->mbox_tmo);
James Smart92908312006-03-07 15:04:13 -05003930 if (ha_copy & HA_ERATT) {
3931 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05003932 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05003933 }
James Smart2e0fef82007-06-17 19:56:36 -05003934 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05003935 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart04c68492009-05-22 14:52:52 -04003936 psli->mbox_active = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003937 phba->link_flag &= ~LS_IGNORE_ERATT;
3938 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05003939
Jamie Wellnitz41415862006-02-28 19:25:27 -05003940 lpfc_hba_down_post(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003941 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003942
James Smart2e0fef82007-06-17 19:56:36 -05003943 return ha_copy & HA_ERATT ? 0 : 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003944}
3945
James Smarte59058c2008-08-24 21:49:00 -04003946/**
James Smart3772a992009-05-22 14:50:54 -04003947 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
James Smarte59058c2008-08-24 21:49:00 -04003948 * @phba: Pointer to HBA context object.
3949 *
3950 * This function resets the HBA by writing HC_INITFF to the control
3951 * register. After the HBA resets, this function resets all the iocb ring
3952 * indices. This function disables PCI layer parity checking during
3953 * the reset.
3954 * This function returns 0 always.
3955 * The caller is not required to hold any locks.
3956 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05003957int
James Smart2e0fef82007-06-17 19:56:36 -05003958lpfc_sli_brdreset(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05003959{
3960 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05003961 struct lpfc_sli_ring *pring;
Jamie Wellnitz41415862006-02-28 19:25:27 -05003962 uint16_t cfg_value;
dea31012005-04-17 16:05:31 -05003963 int i;
dea31012005-04-17 16:05:31 -05003964
Jamie Wellnitz41415862006-02-28 19:25:27 -05003965 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003966
Jamie Wellnitz41415862006-02-28 19:25:27 -05003967 /* Reset HBA */
3968 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003969 "0325 Reset HBA Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05003970 phba->pport->port_state, psli->sli_flag);
dea31012005-04-17 16:05:31 -05003971
3972 /* perform board reset */
3973 phba->fc_eventTag = 0;
James Smart4d9ab992009-10-02 15:16:39 -04003974 phba->link_events = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003975 phba->pport->fc_myDID = 0;
3976 phba->pport->fc_prevDID = 0;
dea31012005-04-17 16:05:31 -05003977
Jamie Wellnitz41415862006-02-28 19:25:27 -05003978 /* Turn off parity checking and serr during the physical reset */
3979 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
3980 pci_write_config_word(phba->pcidev, PCI_COMMAND,
3981 (cfg_value &
3982 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
3983
James Smart3772a992009-05-22 14:50:54 -04003984 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
3985
Jamie Wellnitz41415862006-02-28 19:25:27 -05003986 /* Now toggle INITFF bit in the Host Control Register */
3987 writel(HC_INITFF, phba->HCregaddr);
3988 mdelay(1);
3989 readl(phba->HCregaddr); /* flush */
3990 writel(0, phba->HCregaddr);
3991 readl(phba->HCregaddr); /* flush */
3992
3993 /* Restore PCI cmd register */
3994 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
dea31012005-04-17 16:05:31 -05003995
3996 /* Initialize relevant SLI info */
Jamie Wellnitz41415862006-02-28 19:25:27 -05003997 for (i = 0; i < psli->num_rings; i++) {
3998 pring = &psli->ring[i];
dea31012005-04-17 16:05:31 -05003999 pring->flag = 0;
James Smart7e56aa22012-08-03 12:35:34 -04004000 pring->sli.sli3.rspidx = 0;
4001 pring->sli.sli3.next_cmdidx = 0;
4002 pring->sli.sli3.local_getidx = 0;
4003 pring->sli.sli3.cmdidx = 0;
dea31012005-04-17 16:05:31 -05004004 pring->missbufcnt = 0;
4005 }
dea31012005-04-17 16:05:31 -05004006
James Smart2e0fef82007-06-17 19:56:36 -05004007 phba->link_state = LPFC_WARM_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05004008 return 0;
4009}
4010
James Smarte59058c2008-08-24 21:49:00 -04004011/**
James Smartda0436e2009-05-22 14:51:39 -04004012 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4013 * @phba: Pointer to HBA context object.
4014 *
4015 * This function resets a SLI4 HBA. This function disables PCI layer parity
4016 * checking during resets the device. The caller is not required to hold
4017 * any locks.
4018 *
4019 * This function returns 0 always.
4020 **/
4021int
4022lpfc_sli4_brdreset(struct lpfc_hba *phba)
4023{
4024 struct lpfc_sli *psli = &phba->sli;
4025 uint16_t cfg_value;
James Smart02936352014-04-04 13:52:12 -04004026 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04004027
4028 /* Reset HBA */
4029 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart02936352014-04-04 13:52:12 -04004030 "0295 Reset HBA Data: x%x x%x x%x\n",
4031 phba->pport->port_state, psli->sli_flag,
4032 phba->hba_flag);
James Smartda0436e2009-05-22 14:51:39 -04004033
4034 /* perform board reset */
4035 phba->fc_eventTag = 0;
James Smart4d9ab992009-10-02 15:16:39 -04004036 phba->link_events = 0;
James Smartda0436e2009-05-22 14:51:39 -04004037 phba->pport->fc_myDID = 0;
4038 phba->pport->fc_prevDID = 0;
4039
James Smartda0436e2009-05-22 14:51:39 -04004040 spin_lock_irq(&phba->hbalock);
4041 psli->sli_flag &= ~(LPFC_PROCESS_LA);
4042 phba->fcf.fcf_flag = 0;
James Smartda0436e2009-05-22 14:51:39 -04004043 spin_unlock_irq(&phba->hbalock);
4044
James Smart02936352014-04-04 13:52:12 -04004045 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4046 if (phba->hba_flag & HBA_FW_DUMP_OP) {
4047 phba->hba_flag &= ~HBA_FW_DUMP_OP;
4048 return rc;
4049 }
4050
James Smartda0436e2009-05-22 14:51:39 -04004051 /* Now physically reset the device */
4052 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4053 "0389 Performing PCI function reset!\n");
James Smartbe858b62010-12-15 17:57:20 -05004054
4055 /* Turn off parity checking and serr during the physical reset */
4056 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
4057 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
4058 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4059
James Smart88318812012-09-29 11:29:29 -04004060 /* Perform FCoE PCI function reset before freeing queue memory */
James Smart27b01b82012-05-09 21:19:44 -04004061 rc = lpfc_pci_function_reset(phba);
James Smart88318812012-09-29 11:29:29 -04004062 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04004063
James Smartbe858b62010-12-15 17:57:20 -05004064 /* Restore PCI cmd register */
4065 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4066
James Smart27b01b82012-05-09 21:19:44 -04004067 return rc;
James Smartda0436e2009-05-22 14:51:39 -04004068}
4069
4070/**
4071 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
James Smarte59058c2008-08-24 21:49:00 -04004072 * @phba: Pointer to HBA context object.
4073 *
4074 * This function is called in the SLI initialization code path to
4075 * restart the HBA. The caller is not required to hold any lock.
4076 * This function writes MBX_RESTART mailbox command to the SLIM and
4077 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4078 * function to free any pending commands. The function enables
4079 * POST only during the first initialization. The function returns zero.
4080 * The function does not guarantee completion of MBX_RESTART mailbox
4081 * command before the return of this function.
4082 **/
James Smartda0436e2009-05-22 14:51:39 -04004083static int
4084lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05004085{
4086 MAILBOX_t *mb;
4087 struct lpfc_sli *psli;
Jamie Wellnitz41415862006-02-28 19:25:27 -05004088 volatile uint32_t word0;
4089 void __iomem *to_slim;
James Smart0d878412009-10-02 15:16:56 -04004090 uint32_t hba_aer_enabled;
Jamie Wellnitz41415862006-02-28 19:25:27 -05004091
James Smart2e0fef82007-06-17 19:56:36 -05004092 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05004093
James Smart0d878412009-10-02 15:16:56 -04004094 /* Take PCIe device Advanced Error Reporting (AER) state */
4095 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4096
Jamie Wellnitz41415862006-02-28 19:25:27 -05004097 psli = &phba->sli;
4098
4099 /* Restart HBA */
4100 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04004101 "0337 Restart HBA Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05004102 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05004103
4104 word0 = 0;
4105 mb = (MAILBOX_t *) &word0;
4106 mb->mbxCommand = MBX_RESTART;
4107 mb->mbxHc = 1;
4108
James Smart92908312006-03-07 15:04:13 -05004109 lpfc_reset_barrier(phba);
4110
Jamie Wellnitz41415862006-02-28 19:25:27 -05004111 to_slim = phba->MBslimaddr;
4112 writel(*(uint32_t *) mb, to_slim);
4113 readl(to_slim); /* flush */
4114
4115 /* Only skip post after fc_ffinit is completed */
James Smarteaf15d52008-12-04 22:39:29 -05004116 if (phba->pport->port_state)
Jamie Wellnitz41415862006-02-28 19:25:27 -05004117 word0 = 1; /* This is really setting up word1 */
James Smarteaf15d52008-12-04 22:39:29 -05004118 else
Jamie Wellnitz41415862006-02-28 19:25:27 -05004119 word0 = 0; /* This is really setting up word1 */
James Smart65a29c12006-07-06 15:50:50 -04004120 to_slim = phba->MBslimaddr + sizeof (uint32_t);
Jamie Wellnitz41415862006-02-28 19:25:27 -05004121 writel(*(uint32_t *) mb, to_slim);
4122 readl(to_slim); /* flush */
4123
4124 lpfc_sli_brdreset(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004125 phba->pport->stopped = 0;
4126 phba->link_state = LPFC_INIT_START;
James Smartda0436e2009-05-22 14:51:39 -04004127 phba->hba_flag = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004128 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05004129
James Smart64ba8812006-08-02 15:24:34 -04004130 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4131 psli->stats_start = get_seconds();
4132
James Smarteaf15d52008-12-04 22:39:29 -05004133 /* Give the INITFF and Post time to settle. */
4134 mdelay(100);
dea31012005-04-17 16:05:31 -05004135
James Smart0d878412009-10-02 15:16:56 -04004136 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4137 if (hba_aer_enabled)
4138 pci_disable_pcie_error_reporting(phba->pcidev);
4139
Jamie Wellnitz41415862006-02-28 19:25:27 -05004140 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -05004141
4142 return 0;
4143}
4144
James Smarte59058c2008-08-24 21:49:00 -04004145/**
James Smartda0436e2009-05-22 14:51:39 -04004146 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4147 * @phba: Pointer to HBA context object.
4148 *
4149 * This function is called in the SLI initialization code path to restart
4150 * a SLI4 HBA. The caller is not required to hold any lock.
4151 * At the end of the function, it calls lpfc_hba_down_post function to
4152 * free any pending commands.
4153 **/
4154static int
4155lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
4156{
4157 struct lpfc_sli *psli = &phba->sli;
James Smart75baf692010-06-08 18:31:21 -04004158 uint32_t hba_aer_enabled;
James Smart27b01b82012-05-09 21:19:44 -04004159 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004160
4161 /* Restart HBA */
4162 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4163 "0296 Restart HBA Data: x%x x%x\n",
4164 phba->pport->port_state, psli->sli_flag);
4165
James Smart75baf692010-06-08 18:31:21 -04004166 /* Take PCIe device Advanced Error Reporting (AER) state */
4167 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4168
James Smart27b01b82012-05-09 21:19:44 -04004169 rc = lpfc_sli4_brdreset(phba);
James Smartda0436e2009-05-22 14:51:39 -04004170
4171 spin_lock_irq(&phba->hbalock);
4172 phba->pport->stopped = 0;
4173 phba->link_state = LPFC_INIT_START;
4174 phba->hba_flag = 0;
4175 spin_unlock_irq(&phba->hbalock);
4176
4177 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4178 psli->stats_start = get_seconds();
4179
James Smart75baf692010-06-08 18:31:21 -04004180 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4181 if (hba_aer_enabled)
4182 pci_disable_pcie_error_reporting(phba->pcidev);
4183
James Smartda0436e2009-05-22 14:51:39 -04004184 lpfc_hba_down_post(phba);
4185
James Smart27b01b82012-05-09 21:19:44 -04004186 return rc;
James Smartda0436e2009-05-22 14:51:39 -04004187}
4188
4189/**
4190 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4191 * @phba: Pointer to HBA context object.
4192 *
4193 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4194 * API jump table function pointer from the lpfc_hba struct.
4195**/
4196int
4197lpfc_sli_brdrestart(struct lpfc_hba *phba)
4198{
4199 return phba->lpfc_sli_brdrestart(phba);
4200}
4201
4202/**
James Smart3621a712009-04-06 18:47:14 -04004203 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
James Smarte59058c2008-08-24 21:49:00 -04004204 * @phba: Pointer to HBA context object.
4205 *
4206 * This function is called after a HBA restart to wait for successful
4207 * restart of the HBA. Successful restart of the HBA is indicated by
4208 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4209 * iteration, the function will restart the HBA again. The function returns
4210 * zero if HBA successfully restarted else returns negative error code.
4211 **/
dea31012005-04-17 16:05:31 -05004212static int
4213lpfc_sli_chipset_init(struct lpfc_hba *phba)
4214{
4215 uint32_t status, i = 0;
4216
4217 /* Read the HBA Host Status Register */
James Smart9940b972011-03-11 16:06:12 -05004218 if (lpfc_readl(phba->HSregaddr, &status))
4219 return -EIO;
dea31012005-04-17 16:05:31 -05004220
4221 /* Check status register to see what current state is */
4222 i = 0;
4223 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4224
James Smartdcf2a4e2010-09-29 11:18:53 -04004225 /* Check every 10ms for 10 retries, then every 100ms for 90
4226 * retries, then every 1 sec for 50 retires for a total of
4227 * ~60 seconds before reset the board again and check every
4228 * 1 sec for 50 retries. The up to 60 seconds before the
4229 * board ready is required by the Falcon FIPS zeroization
4230 * complete, and any reset the board in between shall cause
4231 * restart of zeroization, further delay the board ready.
dea31012005-04-17 16:05:31 -05004232 */
James Smartdcf2a4e2010-09-29 11:18:53 -04004233 if (i++ >= 200) {
dea31012005-04-17 16:05:31 -05004234 /* Adapter failed to init, timeout, status reg
4235 <status> */
James Smarted957682007-06-17 19:56:37 -05004236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004237 "0436 Adapter failed to init, "
James Smart09372822008-01-11 01:52:54 -05004238 "timeout, status reg x%x, "
4239 "FW Data: A8 x%x AC x%x\n", status,
4240 readl(phba->MBslimaddr + 0xa8),
4241 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05004242 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05004243 return -ETIMEDOUT;
4244 }
4245
4246 /* Check to see if any errors occurred during init */
4247 if (status & HS_FFERM) {
4248 /* ERROR: During chipset initialization */
4249 /* Adapter failed to init, chipset, status reg
4250 <status> */
James Smarted957682007-06-17 19:56:37 -05004251 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004252 "0437 Adapter failed to init, "
James Smart09372822008-01-11 01:52:54 -05004253 "chipset, status reg x%x, "
4254 "FW Data: A8 x%x AC x%x\n", status,
4255 readl(phba->MBslimaddr + 0xa8),
4256 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05004257 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05004258 return -EIO;
4259 }
4260
James Smartdcf2a4e2010-09-29 11:18:53 -04004261 if (i <= 10)
dea31012005-04-17 16:05:31 -05004262 msleep(10);
James Smartdcf2a4e2010-09-29 11:18:53 -04004263 else if (i <= 100)
4264 msleep(100);
4265 else
4266 msleep(1000);
dea31012005-04-17 16:05:31 -05004267
James Smartdcf2a4e2010-09-29 11:18:53 -04004268 if (i == 150) {
4269 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05004270 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05004271 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05004272 }
4273 /* Read the HBA Host Status Register */
James Smart9940b972011-03-11 16:06:12 -05004274 if (lpfc_readl(phba->HSregaddr, &status))
4275 return -EIO;
dea31012005-04-17 16:05:31 -05004276 }
4277
4278 /* Check to see if any errors occurred during init */
4279 if (status & HS_FFERM) {
4280 /* ERROR: During chipset initialization */
4281 /* Adapter failed to init, chipset, status reg <status> */
James Smarted957682007-06-17 19:56:37 -05004282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004283 "0438 Adapter failed to init, chipset, "
James Smart09372822008-01-11 01:52:54 -05004284 "status reg x%x, "
4285 "FW Data: A8 x%x AC x%x\n", status,
4286 readl(phba->MBslimaddr + 0xa8),
4287 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05004288 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05004289 return -EIO;
4290 }
4291
4292 /* Clear all interrupt enable conditions */
4293 writel(0, phba->HCregaddr);
4294 readl(phba->HCregaddr); /* flush */
4295
4296 /* setup host attn register */
4297 writel(0xffffffff, phba->HAregaddr);
4298 readl(phba->HAregaddr); /* flush */
4299 return 0;
4300}
4301
James Smarte59058c2008-08-24 21:49:00 -04004302/**
James Smart3621a712009-04-06 18:47:14 -04004303 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
James Smarte59058c2008-08-24 21:49:00 -04004304 *
4305 * This function calculates and returns the number of HBQs required to be
4306 * configured.
4307 **/
James Smart78b2d852007-08-02 11:10:21 -04004308int
James Smarted957682007-06-17 19:56:37 -05004309lpfc_sli_hbq_count(void)
4310{
James Smart92d7f7b2007-06-17 19:56:38 -05004311 return ARRAY_SIZE(lpfc_hbq_defs);
James Smarted957682007-06-17 19:56:37 -05004312}
4313
James Smarte59058c2008-08-24 21:49:00 -04004314/**
James Smart3621a712009-04-06 18:47:14 -04004315 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
James Smarte59058c2008-08-24 21:49:00 -04004316 *
4317 * This function adds the number of hbq entries in every HBQ to get
4318 * the total number of hbq entries required for the HBA and returns
4319 * the total count.
4320 **/
James Smarted957682007-06-17 19:56:37 -05004321static int
4322lpfc_sli_hbq_entry_count(void)
4323{
4324 int hbq_count = lpfc_sli_hbq_count();
4325 int count = 0;
4326 int i;
4327
4328 for (i = 0; i < hbq_count; ++i)
James Smart92d7f7b2007-06-17 19:56:38 -05004329 count += lpfc_hbq_defs[i]->entry_count;
James Smarted957682007-06-17 19:56:37 -05004330 return count;
4331}
4332
James Smarte59058c2008-08-24 21:49:00 -04004333/**
James Smart3621a712009-04-06 18:47:14 -04004334 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
James Smarte59058c2008-08-24 21:49:00 -04004335 *
4336 * This function calculates amount of memory required for all hbq entries
4337 * to be configured and returns the total memory required.
4338 **/
dea31012005-04-17 16:05:31 -05004339int
James Smarted957682007-06-17 19:56:37 -05004340lpfc_sli_hbq_size(void)
4341{
4342 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
4343}
4344
James Smarte59058c2008-08-24 21:49:00 -04004345/**
James Smart3621a712009-04-06 18:47:14 -04004346 * lpfc_sli_hbq_setup - configure and initialize HBQs
James Smarte59058c2008-08-24 21:49:00 -04004347 * @phba: Pointer to HBA context object.
4348 *
4349 * This function is called during the SLI initialization to configure
4350 * all the HBQs and post buffers to the HBQ. The caller is not
4351 * required to hold any locks. This function will return zero if successful
4352 * else it will return negative error code.
4353 **/
James Smarted957682007-06-17 19:56:37 -05004354static int
4355lpfc_sli_hbq_setup(struct lpfc_hba *phba)
4356{
4357 int hbq_count = lpfc_sli_hbq_count();
4358 LPFC_MBOXQ_t *pmb;
4359 MAILBOX_t *pmbox;
4360 uint32_t hbqno;
4361 uint32_t hbq_entry_index;
James Smarted957682007-06-17 19:56:37 -05004362
James Smart92d7f7b2007-06-17 19:56:38 -05004363 /* Get a Mailbox buffer to setup mailbox
4364 * commands for HBA initialization
4365 */
James Smarted957682007-06-17 19:56:37 -05004366 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4367
4368 if (!pmb)
4369 return -ENOMEM;
4370
James Smart04c68492009-05-22 14:52:52 -04004371 pmbox = &pmb->u.mb;
James Smarted957682007-06-17 19:56:37 -05004372
4373 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4374 phba->link_state = LPFC_INIT_MBX_CMDS;
James Smart3163f722008-02-08 18:50:25 -05004375 phba->hbq_in_use = 1;
James Smarted957682007-06-17 19:56:37 -05004376
4377 hbq_entry_index = 0;
4378 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
4379 phba->hbqs[hbqno].next_hbqPutIdx = 0;
4380 phba->hbqs[hbqno].hbqPutIdx = 0;
4381 phba->hbqs[hbqno].local_hbqGetIdx = 0;
4382 phba->hbqs[hbqno].entry_count =
James Smart92d7f7b2007-06-17 19:56:38 -05004383 lpfc_hbq_defs[hbqno]->entry_count;
James Smart51ef4c22007-08-02 11:10:31 -04004384 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
4385 hbq_entry_index, pmb);
James Smarted957682007-06-17 19:56:37 -05004386 hbq_entry_index += phba->hbqs[hbqno].entry_count;
4387
4388 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
4389 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4390 mbxStatus <status>, ring <num> */
4391
4392 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05004393 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04004394 "1805 Adapter failed to init. "
James Smarted957682007-06-17 19:56:37 -05004395 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004396 pmbox->mbxCommand,
James Smarted957682007-06-17 19:56:37 -05004397 pmbox->mbxStatus, hbqno);
4398
4399 phba->link_state = LPFC_HBA_ERROR;
4400 mempool_free(pmb, phba->mbox_mem_pool);
James Smart6e7288d2010-06-07 15:23:35 -04004401 return -ENXIO;
James Smarted957682007-06-17 19:56:37 -05004402 }
4403 }
4404 phba->hbq_count = hbq_count;
4405
James Smarted957682007-06-17 19:56:37 -05004406 mempool_free(pmb, phba->mbox_mem_pool);
4407
James Smart92d7f7b2007-06-17 19:56:38 -05004408 /* Initially populate or replenish the HBQs */
James Smartd7c255b2008-08-24 21:50:00 -04004409 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
4410 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
James Smarted957682007-06-17 19:56:37 -05004411 return 0;
4412}
4413
James Smarte59058c2008-08-24 21:49:00 -04004414/**
James Smart4f774512009-05-22 14:52:35 -04004415 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4416 * @phba: Pointer to HBA context object.
4417 *
4418 * This function is called during the SLI initialization to configure
4419 * all the HBQs and post buffers to the HBQ. The caller is not
4420 * required to hold any locks. This function will return zero if successful
4421 * else it will return negative error code.
4422 **/
4423static int
4424lpfc_sli4_rb_setup(struct lpfc_hba *phba)
4425{
4426 phba->hbq_in_use = 1;
4427 phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
4428 phba->hbq_count = 1;
4429 /* Initially populate or replenish the HBQs */
4430 lpfc_sli_hbqbuf_init_hbqs(phba, 0);
4431 return 0;
4432}
4433
4434/**
James Smart3621a712009-04-06 18:47:14 -04004435 * lpfc_sli_config_port - Issue config port mailbox command
James Smarte59058c2008-08-24 21:49:00 -04004436 * @phba: Pointer to HBA context object.
4437 * @sli_mode: sli mode - 2/3
4438 *
4439 * This function is called by the sli intialization code path
4440 * to issue config_port mailbox command. This function restarts the
4441 * HBA firmware and issues a config_port mailbox command to configure
4442 * the SLI interface in the sli mode specified by sli_mode
4443 * variable. The caller is not required to hold any locks.
4444 * The function returns 0 if successful, else returns negative error
4445 * code.
4446 **/
James Smart93996272008-08-24 21:50:30 -04004447int
4448lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
dea31012005-04-17 16:05:31 -05004449{
4450 LPFC_MBOXQ_t *pmb;
4451 uint32_t resetcount = 0, rc = 0, done = 0;
4452
4453 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4454 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -05004455 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05004456 return -ENOMEM;
4457 }
4458
James Smarted957682007-06-17 19:56:37 -05004459 phba->sli_rev = sli_mode;
dea31012005-04-17 16:05:31 -05004460 while (resetcount < 2 && !done) {
James Smart2e0fef82007-06-17 19:56:36 -05004461 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04004462 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05004463 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05004464 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05004465 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05004466 rc = lpfc_sli_chipset_init(phba);
4467 if (rc)
4468 break;
4469
James Smart2e0fef82007-06-17 19:56:36 -05004470 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04004471 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05004472 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004473 resetcount++;
4474
James Smarted957682007-06-17 19:56:37 -05004475 /* Call pre CONFIG_PORT mailbox command initialization. A
4476 * value of 0 means the call was successful. Any other
4477 * nonzero value is a failure, but if ERESTART is returned,
4478 * the driver may reset the HBA and try again.
4479 */
dea31012005-04-17 16:05:31 -05004480 rc = lpfc_config_port_prep(phba);
4481 if (rc == -ERESTART) {
James Smarted957682007-06-17 19:56:37 -05004482 phba->link_state = LPFC_LINK_UNKNOWN;
dea31012005-04-17 16:05:31 -05004483 continue;
James Smart34b02dc2008-08-24 21:49:55 -04004484 } else if (rc)
dea31012005-04-17 16:05:31 -05004485 break;
James Smart6d368e52011-05-24 11:44:12 -04004486
James Smart2e0fef82007-06-17 19:56:36 -05004487 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -05004488 lpfc_config_port(phba, pmb);
4489 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart34b02dc2008-08-24 21:49:55 -04004490 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
4491 LPFC_SLI3_HBQ_ENABLED |
4492 LPFC_SLI3_CRP_ENABLED |
James Smartbc739052010-08-04 16:11:18 -04004493 LPFC_SLI3_BG_ENABLED |
4494 LPFC_SLI3_DSS_ENABLED);
James Smarted957682007-06-17 19:56:37 -05004495 if (rc != MBX_SUCCESS) {
dea31012005-04-17 16:05:31 -05004496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004497 "0442 Adapter failed to init, mbxCmd x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05004498 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
James Smart04c68492009-05-22 14:52:52 -04004499 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
James Smart2e0fef82007-06-17 19:56:36 -05004500 spin_lock_irq(&phba->hbalock);
James Smart04c68492009-05-22 14:52:52 -04004501 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05004502 spin_unlock_irq(&phba->hbalock);
4503 rc = -ENXIO;
James Smart04c68492009-05-22 14:52:52 -04004504 } else {
4505 /* Allow asynchronous mailbox command to go through */
4506 spin_lock_irq(&phba->hbalock);
4507 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4508 spin_unlock_irq(&phba->hbalock);
James Smarted957682007-06-17 19:56:37 -05004509 done = 1;
James Smartcb69f7d2011-12-13 13:21:57 -05004510
4511 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
4512 (pmb->u.mb.un.varCfgPort.gasabt == 0))
4513 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4514 "3110 Port did not grant ASABT\n");
James Smart04c68492009-05-22 14:52:52 -04004515 }
dea31012005-04-17 16:05:31 -05004516 }
James Smarted957682007-06-17 19:56:37 -05004517 if (!done) {
4518 rc = -EINVAL;
4519 goto do_prep_failed;
4520 }
James Smart04c68492009-05-22 14:52:52 -04004521 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
4522 if (!pmb->u.mb.un.varCfgPort.cMA) {
James Smart34b02dc2008-08-24 21:49:55 -04004523 rc = -ENXIO;
4524 goto do_prep_failed;
4525 }
James Smart04c68492009-05-22 14:52:52 -04004526 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
James Smart34b02dc2008-08-24 21:49:55 -04004527 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
James Smart04c68492009-05-22 14:52:52 -04004528 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
4529 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
4530 phba->max_vpi : phba->max_vports;
4531
James Smart34b02dc2008-08-24 21:49:55 -04004532 } else
4533 phba->max_vpi = 0;
James Smartbc739052010-08-04 16:11:18 -04004534 phba->fips_level = 0;
4535 phba->fips_spec_rev = 0;
4536 if (pmb->u.mb.un.varCfgPort.gdss) {
James Smart04c68492009-05-22 14:52:52 -04004537 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
James Smartbc739052010-08-04 16:11:18 -04004538 phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
4539 phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
4540 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4541 "2850 Security Crypto Active. FIPS x%d "
4542 "(Spec Rev: x%d)",
4543 phba->fips_level, phba->fips_spec_rev);
4544 }
4545 if (pmb->u.mb.un.varCfgPort.sec_err) {
4546 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4547 "2856 Config Port Security Crypto "
4548 "Error: x%x ",
4549 pmb->u.mb.un.varCfgPort.sec_err);
4550 }
James Smart04c68492009-05-22 14:52:52 -04004551 if (pmb->u.mb.un.varCfgPort.gerbm)
James Smart34b02dc2008-08-24 21:49:55 -04004552 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
James Smart04c68492009-05-22 14:52:52 -04004553 if (pmb->u.mb.un.varCfgPort.gcrp)
James Smart34b02dc2008-08-24 21:49:55 -04004554 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
James Smart6e7288d2010-06-07 15:23:35 -04004555
4556 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
4557 phba->port_gp = phba->mbox->us.s3_pgp.port;
James Smarte2a0a9d2008-12-04 22:40:02 -05004558
4559 if (phba->cfg_enable_bg) {
James Smart04c68492009-05-22 14:52:52 -04004560 if (pmb->u.mb.un.varCfgPort.gbg)
James Smarte2a0a9d2008-12-04 22:40:02 -05004561 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
4562 else
4563 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4564 "0443 Adapter did not grant "
4565 "BlockGuard\n");
4566 }
James Smart34b02dc2008-08-24 21:49:55 -04004567 } else {
James Smart8f34f4c2008-12-04 22:39:23 -05004568 phba->hbq_get = NULL;
James Smart34b02dc2008-08-24 21:49:55 -04004569 phba->port_gp = phba->mbox->us.s2.port;
James Smartd7c255b2008-08-24 21:50:00 -04004570 phba->max_vpi = 0;
James Smarted957682007-06-17 19:56:37 -05004571 }
James Smart92d7f7b2007-06-17 19:56:38 -05004572do_prep_failed:
James Smarted957682007-06-17 19:56:37 -05004573 mempool_free(pmb, phba->mbox_mem_pool);
4574 return rc;
4575}
4576
James Smarte59058c2008-08-24 21:49:00 -04004577
4578/**
James Smart3621a712009-04-06 18:47:14 -04004579 * lpfc_sli_hba_setup - SLI intialization function
James Smarte59058c2008-08-24 21:49:00 -04004580 * @phba: Pointer to HBA context object.
4581 *
4582 * This function is the main SLI intialization function. This function
4583 * is called by the HBA intialization code, HBA reset code and HBA
4584 * error attention handler code. Caller is not required to hold any
4585 * locks. This function issues config_port mailbox command to configure
4586 * the SLI, setup iocb rings and HBQ rings. In the end the function
4587 * calls the config_port_post function to issue init_link mailbox
4588 * command and to start the discovery. The function will return zero
4589 * if successful, else it will return negative error code.
4590 **/
James Smarted957682007-06-17 19:56:37 -05004591int
4592lpfc_sli_hba_setup(struct lpfc_hba *phba)
4593{
4594 uint32_t rc;
James Smart6d368e52011-05-24 11:44:12 -04004595 int mode = 3, i;
4596 int longs;
James Smarted957682007-06-17 19:56:37 -05004597
4598 switch (lpfc_sli_mode) {
4599 case 2:
James Smart78b2d852007-08-02 11:10:21 -04004600 if (phba->cfg_enable_npiv) {
James Smart92d7f7b2007-06-17 19:56:38 -05004601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04004602 "1824 NPIV enabled: Override lpfc_sli_mode "
James Smart92d7f7b2007-06-17 19:56:38 -05004603 "parameter (%d) to auto (0).\n",
James Smarte8b62012007-08-02 11:10:09 -04004604 lpfc_sli_mode);
James Smart92d7f7b2007-06-17 19:56:38 -05004605 break;
4606 }
James Smarted957682007-06-17 19:56:37 -05004607 mode = 2;
4608 break;
4609 case 0:
4610 case 3:
4611 break;
4612 default:
James Smart92d7f7b2007-06-17 19:56:38 -05004613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04004614 "1819 Unrecognized lpfc_sli_mode "
4615 "parameter: %d.\n", lpfc_sli_mode);
James Smarted957682007-06-17 19:56:37 -05004616
4617 break;
4618 }
4619
James Smart93996272008-08-24 21:50:30 -04004620 rc = lpfc_sli_config_port(phba, mode);
4621
James Smarted957682007-06-17 19:56:37 -05004622 if (rc && lpfc_sli_mode == 3)
James Smart92d7f7b2007-06-17 19:56:38 -05004623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04004624 "1820 Unable to select SLI-3. "
4625 "Not supported by adapter.\n");
James Smarted957682007-06-17 19:56:37 -05004626 if (rc && mode != 2)
James Smart93996272008-08-24 21:50:30 -04004627 rc = lpfc_sli_config_port(phba, 2);
James Smarted957682007-06-17 19:56:37 -05004628 if (rc)
dea31012005-04-17 16:05:31 -05004629 goto lpfc_sli_hba_setup_error;
4630
James Smart0d878412009-10-02 15:16:56 -04004631 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4632 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
4633 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4634 if (!rc) {
4635 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4636 "2709 This device supports "
4637 "Advanced Error Reporting (AER)\n");
4638 spin_lock_irq(&phba->hbalock);
4639 phba->hba_flag |= HBA_AER_ENABLED;
4640 spin_unlock_irq(&phba->hbalock);
4641 } else {
4642 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4643 "2708 This device does not support "
James Smartb069d7e2013-05-31 17:04:36 -04004644 "Advanced Error Reporting (AER): %d\n",
4645 rc);
James Smart0d878412009-10-02 15:16:56 -04004646 phba->cfg_aer_support = 0;
4647 }
4648 }
4649
James Smarted957682007-06-17 19:56:37 -05004650 if (phba->sli_rev == 3) {
4651 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4652 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
James Smarted957682007-06-17 19:56:37 -05004653 } else {
4654 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4655 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
James Smart92d7f7b2007-06-17 19:56:38 -05004656 phba->sli3_options = 0;
James Smarted957682007-06-17 19:56:37 -05004657 }
4658
4659 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004660 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4661 phba->sli_rev, phba->max_vpi);
James Smarted957682007-06-17 19:56:37 -05004662 rc = lpfc_sli_ring_map(phba);
dea31012005-04-17 16:05:31 -05004663
4664 if (rc)
4665 goto lpfc_sli_hba_setup_error;
4666
James Smart6d368e52011-05-24 11:44:12 -04004667 /* Initialize VPIs. */
4668 if (phba->sli_rev == LPFC_SLI_REV3) {
4669 /*
4670 * The VPI bitmask and physical ID array are allocated
4671 * and initialized once only - at driver load. A port
4672 * reset doesn't need to reinitialize this memory.
4673 */
4674 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
4675 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
4676 phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
4677 GFP_KERNEL);
4678 if (!phba->vpi_bmask) {
4679 rc = -ENOMEM;
4680 goto lpfc_sli_hba_setup_error;
4681 }
4682
4683 phba->vpi_ids = kzalloc(
4684 (phba->max_vpi+1) * sizeof(uint16_t),
4685 GFP_KERNEL);
4686 if (!phba->vpi_ids) {
4687 kfree(phba->vpi_bmask);
4688 rc = -ENOMEM;
4689 goto lpfc_sli_hba_setup_error;
4690 }
4691 for (i = 0; i < phba->max_vpi; i++)
4692 phba->vpi_ids[i] = i;
4693 }
4694 }
4695
James Smart93996272008-08-24 21:50:30 -04004696 /* Init HBQs */
James Smarted957682007-06-17 19:56:37 -05004697 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4698 rc = lpfc_sli_hbq_setup(phba);
4699 if (rc)
4700 goto lpfc_sli_hba_setup_error;
4701 }
James Smart04c68492009-05-22 14:52:52 -04004702 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004703 phba->sli.sli_flag |= LPFC_PROCESS_LA;
James Smart04c68492009-05-22 14:52:52 -04004704 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004705
4706 rc = lpfc_config_port_post(phba);
4707 if (rc)
4708 goto lpfc_sli_hba_setup_error;
4709
James Smarted957682007-06-17 19:56:37 -05004710 return rc;
4711
James Smart92d7f7b2007-06-17 19:56:38 -05004712lpfc_sli_hba_setup_error:
James Smart2e0fef82007-06-17 19:56:36 -05004713 phba->link_state = LPFC_HBA_ERROR;
James Smarte40a02c2010-02-26 14:13:54 -05004714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004715 "0445 Firmware initialization failed\n");
dea31012005-04-17 16:05:31 -05004716 return rc;
4717}
4718
James Smartda0436e2009-05-22 14:51:39 -04004719/**
4720 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4721 * @phba: Pointer to HBA context object.
4722 * @mboxq: mailbox pointer.
4723 * This function issue a dump mailbox command to read config region
4724 * 23 and parse the records in the region and populate driver
4725 * data structure.
4726 **/
4727static int
James Smartff78d8f2011-12-13 13:21:35 -05004728lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04004729{
James Smartff78d8f2011-12-13 13:21:35 -05004730 LPFC_MBOXQ_t *mboxq;
James Smartda0436e2009-05-22 14:51:39 -04004731 struct lpfc_dmabuf *mp;
4732 struct lpfc_mqe *mqe;
4733 uint32_t data_length;
4734 int rc;
4735
4736 /* Program the default value of vlan_id and fc_map */
4737 phba->valid_vlan = 0;
4738 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4739 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4740 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4741
James Smartff78d8f2011-12-13 13:21:35 -05004742 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4743 if (!mboxq)
James Smartda0436e2009-05-22 14:51:39 -04004744 return -ENOMEM;
4745
James Smartff78d8f2011-12-13 13:21:35 -05004746 mqe = &mboxq->u.mqe;
4747 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
4748 rc = -ENOMEM;
4749 goto out_free_mboxq;
4750 }
4751
James Smartda0436e2009-05-22 14:51:39 -04004752 mp = (struct lpfc_dmabuf *) mboxq->context1;
4753 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4754
4755 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4756 "(%d):2571 Mailbox cmd x%x Status x%x "
4757 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4758 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4759 "CQ: x%x x%x x%x x%x\n",
4760 mboxq->vport ? mboxq->vport->vpi : 0,
4761 bf_get(lpfc_mqe_command, mqe),
4762 bf_get(lpfc_mqe_status, mqe),
4763 mqe->un.mb_words[0], mqe->un.mb_words[1],
4764 mqe->un.mb_words[2], mqe->un.mb_words[3],
4765 mqe->un.mb_words[4], mqe->un.mb_words[5],
4766 mqe->un.mb_words[6], mqe->un.mb_words[7],
4767 mqe->un.mb_words[8], mqe->un.mb_words[9],
4768 mqe->un.mb_words[10], mqe->un.mb_words[11],
4769 mqe->un.mb_words[12], mqe->un.mb_words[13],
4770 mqe->un.mb_words[14], mqe->un.mb_words[15],
4771 mqe->un.mb_words[16], mqe->un.mb_words[50],
4772 mboxq->mcqe.word0,
4773 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4774 mboxq->mcqe.trailer);
4775
4776 if (rc) {
4777 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4778 kfree(mp);
James Smartff78d8f2011-12-13 13:21:35 -05004779 rc = -EIO;
4780 goto out_free_mboxq;
James Smartda0436e2009-05-22 14:51:39 -04004781 }
4782 data_length = mqe->un.mb_words[5];
James Smarta0c87cb2009-07-19 10:01:10 -04004783 if (data_length > DMP_RGN23_SIZE) {
James Smartd11e31d2009-06-10 17:23:06 -04004784 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4785 kfree(mp);
James Smartff78d8f2011-12-13 13:21:35 -05004786 rc = -EIO;
4787 goto out_free_mboxq;
James Smartd11e31d2009-06-10 17:23:06 -04004788 }
James Smartda0436e2009-05-22 14:51:39 -04004789
4790 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
4791 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4792 kfree(mp);
James Smartff78d8f2011-12-13 13:21:35 -05004793 rc = 0;
4794
4795out_free_mboxq:
4796 mempool_free(mboxq, phba->mbox_mem_pool);
4797 return rc;
James Smartda0436e2009-05-22 14:51:39 -04004798}
4799
4800/**
4801 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4802 * @phba: pointer to lpfc hba data structure.
4803 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4804 * @vpd: pointer to the memory to hold resulting port vpd data.
4805 * @vpd_size: On input, the number of bytes allocated to @vpd.
4806 * On output, the number of data bytes in @vpd.
4807 *
4808 * This routine executes a READ_REV SLI4 mailbox command. In
4809 * addition, this routine gets the port vpd data.
4810 *
4811 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004812 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04004813 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04004814 **/
4815static int
4816lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4817 uint8_t *vpd, uint32_t *vpd_size)
4818{
4819 int rc = 0;
4820 uint32_t dma_size;
4821 struct lpfc_dmabuf *dmabuf;
4822 struct lpfc_mqe *mqe;
4823
4824 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4825 if (!dmabuf)
4826 return -ENOMEM;
4827
4828 /*
4829 * Get a DMA buffer for the vpd data resulting from the READ_REV
4830 * mailbox command.
4831 */
4832 dma_size = *vpd_size;
Joe Perches1aee3832014-09-03 12:56:12 -04004833 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size,
4834 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04004835 if (!dmabuf->virt) {
4836 kfree(dmabuf);
4837 return -ENOMEM;
4838 }
James Smartda0436e2009-05-22 14:51:39 -04004839
4840 /*
4841 * The SLI4 implementation of READ_REV conflicts at word1,
4842 * bits 31:16 and SLI4 adds vpd functionality not present
4843 * in SLI3. This code corrects the conflicts.
4844 */
4845 lpfc_read_rev(phba, mboxq);
4846 mqe = &mboxq->u.mqe;
4847 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
4848 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
4849 mqe->un.read_rev.word1 &= 0x0000FFFF;
4850 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
4851 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
4852
4853 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4854 if (rc) {
4855 dma_free_coherent(&phba->pcidev->dev, dma_size,
4856 dmabuf->virt, dmabuf->phys);
James Smartdef9c7a2009-12-21 17:02:28 -05004857 kfree(dmabuf);
James Smartda0436e2009-05-22 14:51:39 -04004858 return -EIO;
4859 }
4860
James Smartda0436e2009-05-22 14:51:39 -04004861 /*
4862 * The available vpd length cannot be bigger than the
4863 * DMA buffer passed to the port. Catch the less than
4864 * case and update the caller's size.
4865 */
4866 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
4867 *vpd_size = mqe->un.read_rev.avail_vpd_len;
4868
James Smartd7c47992010-06-08 18:31:54 -04004869 memcpy(vpd, dmabuf->virt, *vpd_size);
4870
James Smartda0436e2009-05-22 14:51:39 -04004871 dma_free_coherent(&phba->pcidev->dev, dma_size,
4872 dmabuf->virt, dmabuf->phys);
4873 kfree(dmabuf);
4874 return 0;
4875}
4876
4877/**
James Smartcd1c8302011-10-10 21:33:25 -04004878 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4879 * @phba: pointer to lpfc hba data structure.
4880 *
4881 * This routine retrieves SLI4 device physical port name this PCI function
4882 * is attached to.
4883 *
4884 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07004885 * 0 - successful
James Smartcd1c8302011-10-10 21:33:25 -04004886 * otherwise - failed to retrieve physical port name
4887 **/
4888static int
4889lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
4890{
4891 LPFC_MBOXQ_t *mboxq;
James Smartcd1c8302011-10-10 21:33:25 -04004892 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
4893 struct lpfc_controller_attribute *cntl_attr;
4894 struct lpfc_mbx_get_port_name *get_port_name;
4895 void *virtaddr = NULL;
4896 uint32_t alloclen, reqlen;
4897 uint32_t shdr_status, shdr_add_status;
4898 union lpfc_sli4_cfg_shdr *shdr;
4899 char cport_name = 0;
4900 int rc;
4901
4902 /* We assume nothing at this point */
4903 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
4904 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
4905
4906 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4907 if (!mboxq)
4908 return -ENOMEM;
James Smartcd1c8302011-10-10 21:33:25 -04004909 /* obtain link type and link number via READ_CONFIG */
James Smartff78d8f2011-12-13 13:21:35 -05004910 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
4911 lpfc_sli4_read_config(phba);
4912 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
4913 goto retrieve_ppname;
James Smartcd1c8302011-10-10 21:33:25 -04004914
4915 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4916 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
4917 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
4918 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
4919 LPFC_SLI4_MBX_NEMBED);
4920 if (alloclen < reqlen) {
4921 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4922 "3084 Allocated DMA memory size (%d) is "
4923 "less than the requested DMA memory size "
4924 "(%d)\n", alloclen, reqlen);
4925 rc = -ENOMEM;
4926 goto out_free_mboxq;
4927 }
4928 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4929 virtaddr = mboxq->sge_array->addr[0];
4930 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
4931 shdr = &mbx_cntl_attr->cfg_shdr;
4932 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
4933 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
4934 if (shdr_status || shdr_add_status || rc) {
4935 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4936 "3085 Mailbox x%x (x%x/x%x) failed, "
4937 "rc:x%x, status:x%x, add_status:x%x\n",
4938 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4939 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
4940 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
4941 rc, shdr_status, shdr_add_status);
4942 rc = -ENXIO;
4943 goto out_free_mboxq;
4944 }
4945 cntl_attr = &mbx_cntl_attr->cntl_attr;
4946 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
4947 phba->sli4_hba.lnk_info.lnk_tp =
4948 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
4949 phba->sli4_hba.lnk_info.lnk_no =
4950 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
4951 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4952 "3086 lnk_type:%d, lnk_numb:%d\n",
4953 phba->sli4_hba.lnk_info.lnk_tp,
4954 phba->sli4_hba.lnk_info.lnk_no);
4955
4956retrieve_ppname:
4957 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
4958 LPFC_MBOX_OPCODE_GET_PORT_NAME,
4959 sizeof(struct lpfc_mbx_get_port_name) -
4960 sizeof(struct lpfc_sli4_cfg_mhdr),
4961 LPFC_SLI4_MBX_EMBED);
4962 get_port_name = &mboxq->u.mqe.un.get_port_name;
4963 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
4964 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
4965 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
4966 phba->sli4_hba.lnk_info.lnk_tp);
4967 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4968 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
4969 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
4970 if (shdr_status || shdr_add_status || rc) {
4971 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4972 "3087 Mailbox x%x (x%x/x%x) failed: "
4973 "rc:x%x, status:x%x, add_status:x%x\n",
4974 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4975 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
4976 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
4977 rc, shdr_status, shdr_add_status);
4978 rc = -ENXIO;
4979 goto out_free_mboxq;
4980 }
4981 switch (phba->sli4_hba.lnk_info.lnk_no) {
4982 case LPFC_LINK_NUMBER_0:
4983 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
4984 &get_port_name->u.response);
4985 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4986 break;
4987 case LPFC_LINK_NUMBER_1:
4988 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
4989 &get_port_name->u.response);
4990 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4991 break;
4992 case LPFC_LINK_NUMBER_2:
4993 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
4994 &get_port_name->u.response);
4995 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
4996 break;
4997 case LPFC_LINK_NUMBER_3:
4998 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
4999 &get_port_name->u.response);
5000 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5001 break;
5002 default:
5003 break;
5004 }
5005
5006 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
5007 phba->Port[0] = cport_name;
5008 phba->Port[1] = '\0';
5009 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5010 "3091 SLI get port name: %s\n", phba->Port);
5011 }
5012
5013out_free_mboxq:
5014 if (rc != MBX_TIMEOUT) {
5015 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5016 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5017 else
5018 mempool_free(mboxq, phba->mbox_mem_pool);
5019 }
5020 return rc;
5021}
5022
5023/**
James Smartda0436e2009-05-22 14:51:39 -04005024 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5025 * @phba: pointer to lpfc hba data structure.
5026 *
5027 * This routine is called to explicitly arm the SLI4 device's completion and
5028 * event queues
5029 **/
5030static void
5031lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
5032{
James Smart962bc512013-01-03 15:44:00 -05005033 int fcp_eqidx;
James Smartda0436e2009-05-22 14:51:39 -04005034
5035 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
5036 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
James Smart05580562011-05-24 11:40:48 -04005037 fcp_eqidx = 0;
James Smart2e90f4b2011-12-13 13:22:37 -05005038 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04005039 do {
James Smart2e90f4b2011-12-13 13:22:37 -05005040 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
5041 LPFC_QUEUE_REARM);
James Smart67d12732012-08-03 12:36:13 -04005042 } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
James Smart2e90f4b2011-12-13 13:22:37 -05005043 }
James Smart1ba981f2014-02-20 09:56:45 -05005044
James Smartf38fa0b2014-04-04 13:52:21 -04005045 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05005046 lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM);
5047
James Smart67d12732012-08-03 12:36:13 -04005048 if (phba->sli4_hba.hba_eq) {
5049 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05005050 fcp_eqidx++)
James Smart67d12732012-08-03 12:36:13 -04005051 lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
James Smart2e90f4b2011-12-13 13:22:37 -05005052 LPFC_QUEUE_REARM);
5053 }
James Smart1ba981f2014-02-20 09:56:45 -05005054
5055 if (phba->cfg_fof)
5056 lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM);
James Smartda0436e2009-05-22 14:51:39 -04005057}
5058
5059/**
James Smart6d368e52011-05-24 11:44:12 -04005060 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5061 * @phba: Pointer to HBA context object.
5062 * @type: The resource extent type.
James Smartb76f2dc2011-07-22 18:37:42 -04005063 * @extnt_count: buffer to hold port available extent count.
5064 * @extnt_size: buffer to hold element count per extent.
James Smart6d368e52011-05-24 11:44:12 -04005065 *
James Smartb76f2dc2011-07-22 18:37:42 -04005066 * This function calls the port and retrievs the number of available
5067 * extents and their size for a particular extent type.
5068 *
5069 * Returns: 0 if successful. Nonzero otherwise.
James Smart6d368e52011-05-24 11:44:12 -04005070 **/
James Smartb76f2dc2011-07-22 18:37:42 -04005071int
James Smart6d368e52011-05-24 11:44:12 -04005072lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
5073 uint16_t *extnt_count, uint16_t *extnt_size)
5074{
5075 int rc = 0;
5076 uint32_t length;
5077 uint32_t mbox_tmo;
5078 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
5079 LPFC_MBOXQ_t *mbox;
5080
5081 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5082 if (!mbox)
5083 return -ENOMEM;
5084
5085 /* Find out how many extents are available for this resource type */
5086 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
5087 sizeof(struct lpfc_sli4_cfg_mhdr));
5088 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5089 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
5090 length, LPFC_SLI4_MBX_EMBED);
5091
5092 /* Send an extents count of 0 - the GET doesn't use it. */
5093 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5094 LPFC_SLI4_MBX_EMBED);
5095 if (unlikely(rc)) {
5096 rc = -EIO;
5097 goto err_exit;
5098 }
5099
5100 if (!phba->sli4_hba.intr_enable)
5101 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5102 else {
James Smarta183a152011-10-10 21:32:43 -04005103 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart6d368e52011-05-24 11:44:12 -04005104 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5105 }
5106 if (unlikely(rc)) {
5107 rc = -EIO;
5108 goto err_exit;
5109 }
5110
5111 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
5112 if (bf_get(lpfc_mbox_hdr_status,
5113 &rsrc_info->header.cfg_shdr.response)) {
5114 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5115 "2930 Failed to get resource extents "
5116 "Status 0x%x Add'l Status 0x%x\n",
5117 bf_get(lpfc_mbox_hdr_status,
5118 &rsrc_info->header.cfg_shdr.response),
5119 bf_get(lpfc_mbox_hdr_add_status,
5120 &rsrc_info->header.cfg_shdr.response));
5121 rc = -EIO;
5122 goto err_exit;
5123 }
5124
5125 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
5126 &rsrc_info->u.rsp);
5127 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
5128 &rsrc_info->u.rsp);
James Smart8a9d2e82012-05-09 21:16:12 -04005129
5130 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5131 "3162 Retrieved extents type-%d from port: count:%d, "
5132 "size:%d\n", type, *extnt_count, *extnt_size);
5133
5134err_exit:
James Smart6d368e52011-05-24 11:44:12 -04005135 mempool_free(mbox, phba->mbox_mem_pool);
5136 return rc;
5137}
5138
5139/**
5140 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5141 * @phba: Pointer to HBA context object.
5142 * @type: The extent type to check.
5143 *
5144 * This function reads the current available extents from the port and checks
5145 * if the extent count or extent size has changed since the last access.
5146 * Callers use this routine post port reset to understand if there is a
5147 * extent reprovisioning requirement.
5148 *
5149 * Returns:
5150 * -Error: error indicates problem.
5151 * 1: Extent count or size has changed.
5152 * 0: No changes.
5153 **/
5154static int
5155lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
5156{
5157 uint16_t curr_ext_cnt, rsrc_ext_cnt;
5158 uint16_t size_diff, rsrc_ext_size;
5159 int rc = 0;
5160 struct lpfc_rsrc_blks *rsrc_entry;
5161 struct list_head *rsrc_blk_list = NULL;
5162
5163 size_diff = 0;
5164 curr_ext_cnt = 0;
5165 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5166 &rsrc_ext_cnt,
5167 &rsrc_ext_size);
5168 if (unlikely(rc))
5169 return -EIO;
5170
5171 switch (type) {
5172 case LPFC_RSC_TYPE_FCOE_RPI:
5173 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5174 break;
5175 case LPFC_RSC_TYPE_FCOE_VPI:
5176 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
5177 break;
5178 case LPFC_RSC_TYPE_FCOE_XRI:
5179 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5180 break;
5181 case LPFC_RSC_TYPE_FCOE_VFI:
5182 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5183 break;
5184 default:
5185 break;
5186 }
5187
5188 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
5189 curr_ext_cnt++;
5190 if (rsrc_entry->rsrc_size != rsrc_ext_size)
5191 size_diff++;
5192 }
5193
5194 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
5195 rc = 1;
5196
5197 return rc;
5198}
5199
5200/**
5201 * lpfc_sli4_cfg_post_extnts -
5202 * @phba: Pointer to HBA context object.
5203 * @extnt_cnt - number of available extents.
5204 * @type - the extent type (rpi, xri, vfi, vpi).
5205 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5206 * @mbox - pointer to the caller's allocated mailbox structure.
5207 *
5208 * This function executes the extents allocation request. It also
5209 * takes care of the amount of memory needed to allocate or get the
5210 * allocated extents. It is the caller's responsibility to evaluate
5211 * the response.
5212 *
5213 * Returns:
5214 * -Error: Error value describes the condition found.
5215 * 0: if successful
5216 **/
5217static int
James Smart8a9d2e82012-05-09 21:16:12 -04005218lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
James Smart6d368e52011-05-24 11:44:12 -04005219 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
5220{
5221 int rc = 0;
5222 uint32_t req_len;
5223 uint32_t emb_len;
5224 uint32_t alloc_len, mbox_tmo;
5225
5226 /* Calculate the total requested length of the dma memory */
James Smart8a9d2e82012-05-09 21:16:12 -04005227 req_len = extnt_cnt * sizeof(uint16_t);
James Smart6d368e52011-05-24 11:44:12 -04005228
5229 /*
5230 * Calculate the size of an embedded mailbox. The uint32_t
5231 * accounts for extents-specific word.
5232 */
5233 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5234 sizeof(uint32_t);
5235
5236 /*
5237 * Presume the allocation and response will fit into an embedded
5238 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5239 */
5240 *emb = LPFC_SLI4_MBX_EMBED;
5241 if (req_len > emb_len) {
James Smart8a9d2e82012-05-09 21:16:12 -04005242 req_len = extnt_cnt * sizeof(uint16_t) +
James Smart6d368e52011-05-24 11:44:12 -04005243 sizeof(union lpfc_sli4_cfg_shdr) +
5244 sizeof(uint32_t);
5245 *emb = LPFC_SLI4_MBX_NEMBED;
5246 }
5247
5248 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5249 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
5250 req_len, *emb);
5251 if (alloc_len < req_len) {
5252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartb76f2dc2011-07-22 18:37:42 -04005253 "2982 Allocated DMA memory size (x%x) is "
James Smart6d368e52011-05-24 11:44:12 -04005254 "less than the requested DMA memory "
5255 "size (x%x)\n", alloc_len, req_len);
5256 return -ENOMEM;
5257 }
James Smart8a9d2e82012-05-09 21:16:12 -04005258 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
James Smart6d368e52011-05-24 11:44:12 -04005259 if (unlikely(rc))
5260 return -EIO;
5261
5262 if (!phba->sli4_hba.intr_enable)
5263 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5264 else {
James Smarta183a152011-10-10 21:32:43 -04005265 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart6d368e52011-05-24 11:44:12 -04005266 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5267 }
5268
5269 if (unlikely(rc))
5270 rc = -EIO;
5271 return rc;
5272}
5273
5274/**
5275 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5276 * @phba: Pointer to HBA context object.
5277 * @type: The resource extent type to allocate.
5278 *
5279 * This function allocates the number of elements for the specified
5280 * resource type.
5281 **/
5282static int
5283lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
5284{
5285 bool emb = false;
5286 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
5287 uint16_t rsrc_id, rsrc_start, j, k;
5288 uint16_t *ids;
5289 int i, rc;
5290 unsigned long longs;
5291 unsigned long *bmask;
5292 struct lpfc_rsrc_blks *rsrc_blks;
5293 LPFC_MBOXQ_t *mbox;
5294 uint32_t length;
5295 struct lpfc_id_range *id_array = NULL;
5296 void *virtaddr = NULL;
5297 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5298 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5299 struct list_head *ext_blk_list;
5300
5301 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5302 &rsrc_cnt,
5303 &rsrc_size);
5304 if (unlikely(rc))
5305 return -EIO;
5306
5307 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
5308 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5309 "3009 No available Resource Extents "
5310 "for resource type 0x%x: Count: 0x%x, "
5311 "Size 0x%x\n", type, rsrc_cnt,
5312 rsrc_size);
5313 return -ENOMEM;
5314 }
5315
James Smart8a9d2e82012-05-09 21:16:12 -04005316 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
5317 "2903 Post resource extents type-0x%x: "
5318 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
James Smart6d368e52011-05-24 11:44:12 -04005319
5320 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5321 if (!mbox)
5322 return -ENOMEM;
5323
James Smart8a9d2e82012-05-09 21:16:12 -04005324 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
James Smart6d368e52011-05-24 11:44:12 -04005325 if (unlikely(rc)) {
5326 rc = -EIO;
5327 goto err_exit;
5328 }
5329
5330 /*
5331 * Figure out where the response is located. Then get local pointers
5332 * to the response data. The port does not guarantee to respond to
5333 * all extents counts request so update the local variable with the
5334 * allocated count from the port.
5335 */
5336 if (emb == LPFC_SLI4_MBX_EMBED) {
5337 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
5338 id_array = &rsrc_ext->u.rsp.id[0];
5339 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
5340 } else {
5341 virtaddr = mbox->sge_array->addr[0];
5342 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
5343 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
5344 id_array = &n_rsrc->id;
5345 }
5346
5347 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
5348 rsrc_id_cnt = rsrc_cnt * rsrc_size;
5349
5350 /*
5351 * Based on the resource size and count, correct the base and max
5352 * resource values.
5353 */
5354 length = sizeof(struct lpfc_rsrc_blks);
5355 switch (type) {
5356 case LPFC_RSC_TYPE_FCOE_RPI:
5357 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5358 sizeof(unsigned long),
5359 GFP_KERNEL);
5360 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5361 rc = -ENOMEM;
5362 goto err_exit;
5363 }
5364 phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
5365 sizeof(uint16_t),
5366 GFP_KERNEL);
5367 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5368 kfree(phba->sli4_hba.rpi_bmask);
5369 rc = -ENOMEM;
5370 goto err_exit;
5371 }
5372
5373 /*
5374 * The next_rpi was initialized with the maximum available
5375 * count but the port may allocate a smaller number. Catch
5376 * that case and update the next_rpi.
5377 */
5378 phba->sli4_hba.next_rpi = rsrc_id_cnt;
5379
5380 /* Initialize local ptrs for common extent processing later. */
5381 bmask = phba->sli4_hba.rpi_bmask;
5382 ids = phba->sli4_hba.rpi_ids;
5383 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5384 break;
5385 case LPFC_RSC_TYPE_FCOE_VPI:
5386 phba->vpi_bmask = kzalloc(longs *
5387 sizeof(unsigned long),
5388 GFP_KERNEL);
5389 if (unlikely(!phba->vpi_bmask)) {
5390 rc = -ENOMEM;
5391 goto err_exit;
5392 }
5393 phba->vpi_ids = kzalloc(rsrc_id_cnt *
5394 sizeof(uint16_t),
5395 GFP_KERNEL);
5396 if (unlikely(!phba->vpi_ids)) {
5397 kfree(phba->vpi_bmask);
5398 rc = -ENOMEM;
5399 goto err_exit;
5400 }
5401
5402 /* Initialize local ptrs for common extent processing later. */
5403 bmask = phba->vpi_bmask;
5404 ids = phba->vpi_ids;
5405 ext_blk_list = &phba->lpfc_vpi_blk_list;
5406 break;
5407 case LPFC_RSC_TYPE_FCOE_XRI:
5408 phba->sli4_hba.xri_bmask = kzalloc(longs *
5409 sizeof(unsigned long),
5410 GFP_KERNEL);
5411 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5412 rc = -ENOMEM;
5413 goto err_exit;
5414 }
James Smart8a9d2e82012-05-09 21:16:12 -04005415 phba->sli4_hba.max_cfg_param.xri_used = 0;
James Smart6d368e52011-05-24 11:44:12 -04005416 phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
5417 sizeof(uint16_t),
5418 GFP_KERNEL);
5419 if (unlikely(!phba->sli4_hba.xri_ids)) {
5420 kfree(phba->sli4_hba.xri_bmask);
5421 rc = -ENOMEM;
5422 goto err_exit;
5423 }
5424
5425 /* Initialize local ptrs for common extent processing later. */
5426 bmask = phba->sli4_hba.xri_bmask;
5427 ids = phba->sli4_hba.xri_ids;
5428 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5429 break;
5430 case LPFC_RSC_TYPE_FCOE_VFI:
5431 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5432 sizeof(unsigned long),
5433 GFP_KERNEL);
5434 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5435 rc = -ENOMEM;
5436 goto err_exit;
5437 }
5438 phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
5439 sizeof(uint16_t),
5440 GFP_KERNEL);
5441 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5442 kfree(phba->sli4_hba.vfi_bmask);
5443 rc = -ENOMEM;
5444 goto err_exit;
5445 }
5446
5447 /* Initialize local ptrs for common extent processing later. */
5448 bmask = phba->sli4_hba.vfi_bmask;
5449 ids = phba->sli4_hba.vfi_ids;
5450 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5451 break;
5452 default:
5453 /* Unsupported Opcode. Fail call. */
5454 id_array = NULL;
5455 bmask = NULL;
5456 ids = NULL;
5457 ext_blk_list = NULL;
5458 goto err_exit;
5459 }
5460
5461 /*
5462 * Complete initializing the extent configuration with the
5463 * allocated ids assigned to this function. The bitmask serves
5464 * as an index into the array and manages the available ids. The
5465 * array just stores the ids communicated to the port via the wqes.
5466 */
5467 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
5468 if ((i % 2) == 0)
5469 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
5470 &id_array[k]);
5471 else
5472 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
5473 &id_array[k]);
5474
5475 rsrc_blks = kzalloc(length, GFP_KERNEL);
5476 if (unlikely(!rsrc_blks)) {
5477 rc = -ENOMEM;
5478 kfree(bmask);
5479 kfree(ids);
5480 goto err_exit;
5481 }
5482 rsrc_blks->rsrc_start = rsrc_id;
5483 rsrc_blks->rsrc_size = rsrc_size;
5484 list_add_tail(&rsrc_blks->list, ext_blk_list);
5485 rsrc_start = rsrc_id;
5486 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
5487 phba->sli4_hba.scsi_xri_start = rsrc_start +
5488 lpfc_sli4_get_els_iocb_cnt(phba);
5489
5490 while (rsrc_id < (rsrc_start + rsrc_size)) {
5491 ids[j] = rsrc_id;
5492 rsrc_id++;
5493 j++;
5494 }
5495 /* Entire word processed. Get next word.*/
5496 if ((i % 2) == 1)
5497 k++;
5498 }
5499 err_exit:
5500 lpfc_sli4_mbox_cmd_free(phba, mbox);
5501 return rc;
5502}
5503
5504/**
5505 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5506 * @phba: Pointer to HBA context object.
5507 * @type: the extent's type.
5508 *
5509 * This function deallocates all extents of a particular resource type.
5510 * SLI4 does not allow for deallocating a particular extent range. It
5511 * is the caller's responsibility to release all kernel memory resources.
5512 **/
5513static int
5514lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
5515{
5516 int rc;
5517 uint32_t length, mbox_tmo = 0;
5518 LPFC_MBOXQ_t *mbox;
5519 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
5520 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
5521
5522 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5523 if (!mbox)
5524 return -ENOMEM;
5525
5526 /*
5527 * This function sends an embedded mailbox because it only sends the
5528 * the resource type. All extents of this type are released by the
5529 * port.
5530 */
5531 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
5532 sizeof(struct lpfc_sli4_cfg_mhdr));
5533 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5534 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
5535 length, LPFC_SLI4_MBX_EMBED);
5536
5537 /* Send an extents count of 0 - the dealloc doesn't use it. */
5538 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5539 LPFC_SLI4_MBX_EMBED);
5540 if (unlikely(rc)) {
5541 rc = -EIO;
5542 goto out_free_mbox;
5543 }
5544 if (!phba->sli4_hba.intr_enable)
5545 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5546 else {
James Smarta183a152011-10-10 21:32:43 -04005547 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart6d368e52011-05-24 11:44:12 -04005548 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5549 }
5550 if (unlikely(rc)) {
5551 rc = -EIO;
5552 goto out_free_mbox;
5553 }
5554
5555 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
5556 if (bf_get(lpfc_mbox_hdr_status,
5557 &dealloc_rsrc->header.cfg_shdr.response)) {
5558 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5559 "2919 Failed to release resource extents "
5560 "for type %d - Status 0x%x Add'l Status 0x%x. "
5561 "Resource memory not released.\n",
5562 type,
5563 bf_get(lpfc_mbox_hdr_status,
5564 &dealloc_rsrc->header.cfg_shdr.response),
5565 bf_get(lpfc_mbox_hdr_add_status,
5566 &dealloc_rsrc->header.cfg_shdr.response));
5567 rc = -EIO;
5568 goto out_free_mbox;
5569 }
5570
5571 /* Release kernel memory resources for the specific type. */
5572 switch (type) {
5573 case LPFC_RSC_TYPE_FCOE_VPI:
5574 kfree(phba->vpi_bmask);
5575 kfree(phba->vpi_ids);
5576 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5577 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5578 &phba->lpfc_vpi_blk_list, list) {
5579 list_del_init(&rsrc_blk->list);
5580 kfree(rsrc_blk);
5581 }
James Smart16a3a202013-04-17 20:14:38 -04005582 phba->sli4_hba.max_cfg_param.vpi_used = 0;
James Smart6d368e52011-05-24 11:44:12 -04005583 break;
5584 case LPFC_RSC_TYPE_FCOE_XRI:
5585 kfree(phba->sli4_hba.xri_bmask);
5586 kfree(phba->sli4_hba.xri_ids);
James Smart6d368e52011-05-24 11:44:12 -04005587 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5588 &phba->sli4_hba.lpfc_xri_blk_list, list) {
5589 list_del_init(&rsrc_blk->list);
5590 kfree(rsrc_blk);
5591 }
5592 break;
5593 case LPFC_RSC_TYPE_FCOE_VFI:
5594 kfree(phba->sli4_hba.vfi_bmask);
5595 kfree(phba->sli4_hba.vfi_ids);
5596 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5597 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5598 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
5599 list_del_init(&rsrc_blk->list);
5600 kfree(rsrc_blk);
5601 }
5602 break;
5603 case LPFC_RSC_TYPE_FCOE_RPI:
5604 /* RPI bitmask and physical id array are cleaned up earlier. */
5605 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5606 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
5607 list_del_init(&rsrc_blk->list);
5608 kfree(rsrc_blk);
5609 }
5610 break;
5611 default:
5612 break;
5613 }
5614
5615 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5616
5617 out_free_mbox:
5618 mempool_free(mbox, phba->mbox_mem_pool);
5619 return rc;
5620}
5621
5622/**
5623 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5624 * @phba: Pointer to HBA context object.
5625 *
5626 * This function allocates all SLI4 resource identifiers.
5627 **/
5628int
5629lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
5630{
5631 int i, rc, error = 0;
5632 uint16_t count, base;
5633 unsigned long longs;
5634
James Smartff78d8f2011-12-13 13:21:35 -05005635 if (!phba->sli4_hba.rpi_hdrs_in_use)
5636 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
James Smart6d368e52011-05-24 11:44:12 -04005637 if (phba->sli4_hba.extents_in_use) {
5638 /*
5639 * The port supports resource extents. The XRI, VPI, VFI, RPI
5640 * resource extent count must be read and allocated before
5641 * provisioning the resource id arrays.
5642 */
5643 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5644 LPFC_IDX_RSRC_RDY) {
5645 /*
5646 * Extent-based resources are set - the driver could
5647 * be in a port reset. Figure out if any corrective
5648 * actions need to be taken.
5649 */
5650 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5651 LPFC_RSC_TYPE_FCOE_VFI);
5652 if (rc != 0)
5653 error++;
5654 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5655 LPFC_RSC_TYPE_FCOE_VPI);
5656 if (rc != 0)
5657 error++;
5658 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5659 LPFC_RSC_TYPE_FCOE_XRI);
5660 if (rc != 0)
5661 error++;
5662 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5663 LPFC_RSC_TYPE_FCOE_RPI);
5664 if (rc != 0)
5665 error++;
5666
5667 /*
5668 * It's possible that the number of resources
5669 * provided to this port instance changed between
5670 * resets. Detect this condition and reallocate
5671 * resources. Otherwise, there is no action.
5672 */
5673 if (error) {
5674 lpfc_printf_log(phba, KERN_INFO,
5675 LOG_MBOX | LOG_INIT,
5676 "2931 Detected extent resource "
5677 "change. Reallocating all "
5678 "extents.\n");
5679 rc = lpfc_sli4_dealloc_extent(phba,
5680 LPFC_RSC_TYPE_FCOE_VFI);
5681 rc = lpfc_sli4_dealloc_extent(phba,
5682 LPFC_RSC_TYPE_FCOE_VPI);
5683 rc = lpfc_sli4_dealloc_extent(phba,
5684 LPFC_RSC_TYPE_FCOE_XRI);
5685 rc = lpfc_sli4_dealloc_extent(phba,
5686 LPFC_RSC_TYPE_FCOE_RPI);
5687 } else
5688 return 0;
5689 }
5690
5691 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5692 if (unlikely(rc))
5693 goto err_exit;
5694
5695 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5696 if (unlikely(rc))
5697 goto err_exit;
5698
5699 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5700 if (unlikely(rc))
5701 goto err_exit;
5702
5703 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5704 if (unlikely(rc))
5705 goto err_exit;
5706 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5707 LPFC_IDX_RSRC_RDY);
5708 return rc;
5709 } else {
5710 /*
5711 * The port does not support resource extents. The XRI, VPI,
5712 * VFI, RPI resource ids were determined from READ_CONFIG.
5713 * Just allocate the bitmasks and provision the resource id
5714 * arrays. If a port reset is active, the resources don't
5715 * need any action - just exit.
5716 */
5717 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
James Smartff78d8f2011-12-13 13:21:35 -05005718 LPFC_IDX_RSRC_RDY) {
5719 lpfc_sli4_dealloc_resource_identifiers(phba);
5720 lpfc_sli4_remove_rpis(phba);
5721 }
James Smart6d368e52011-05-24 11:44:12 -04005722 /* RPIs. */
5723 count = phba->sli4_hba.max_cfg_param.max_rpi;
James Smart0a630c22013-01-03 15:44:09 -05005724 if (count <= 0) {
5725 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5726 "3279 Invalid provisioning of "
5727 "rpi:%d\n", count);
5728 rc = -EINVAL;
5729 goto err_exit;
5730 }
James Smart6d368e52011-05-24 11:44:12 -04005731 base = phba->sli4_hba.max_cfg_param.rpi_base;
5732 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5733 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5734 sizeof(unsigned long),
5735 GFP_KERNEL);
5736 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5737 rc = -ENOMEM;
5738 goto err_exit;
5739 }
5740 phba->sli4_hba.rpi_ids = kzalloc(count *
5741 sizeof(uint16_t),
5742 GFP_KERNEL);
5743 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5744 rc = -ENOMEM;
5745 goto free_rpi_bmask;
5746 }
5747
5748 for (i = 0; i < count; i++)
5749 phba->sli4_hba.rpi_ids[i] = base + i;
5750
5751 /* VPIs. */
5752 count = phba->sli4_hba.max_cfg_param.max_vpi;
James Smart0a630c22013-01-03 15:44:09 -05005753 if (count <= 0) {
5754 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5755 "3280 Invalid provisioning of "
5756 "vpi:%d\n", count);
5757 rc = -EINVAL;
5758 goto free_rpi_ids;
5759 }
James Smart6d368e52011-05-24 11:44:12 -04005760 base = phba->sli4_hba.max_cfg_param.vpi_base;
5761 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5762 phba->vpi_bmask = kzalloc(longs *
5763 sizeof(unsigned long),
5764 GFP_KERNEL);
5765 if (unlikely(!phba->vpi_bmask)) {
5766 rc = -ENOMEM;
5767 goto free_rpi_ids;
5768 }
5769 phba->vpi_ids = kzalloc(count *
5770 sizeof(uint16_t),
5771 GFP_KERNEL);
5772 if (unlikely(!phba->vpi_ids)) {
5773 rc = -ENOMEM;
5774 goto free_vpi_bmask;
5775 }
5776
5777 for (i = 0; i < count; i++)
5778 phba->vpi_ids[i] = base + i;
5779
5780 /* XRIs. */
5781 count = phba->sli4_hba.max_cfg_param.max_xri;
James Smart0a630c22013-01-03 15:44:09 -05005782 if (count <= 0) {
5783 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5784 "3281 Invalid provisioning of "
5785 "xri:%d\n", count);
5786 rc = -EINVAL;
5787 goto free_vpi_ids;
5788 }
James Smart6d368e52011-05-24 11:44:12 -04005789 base = phba->sli4_hba.max_cfg_param.xri_base;
5790 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5791 phba->sli4_hba.xri_bmask = kzalloc(longs *
5792 sizeof(unsigned long),
5793 GFP_KERNEL);
5794 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5795 rc = -ENOMEM;
5796 goto free_vpi_ids;
5797 }
James Smart41899be2012-03-01 22:34:19 -05005798 phba->sli4_hba.max_cfg_param.xri_used = 0;
James Smart6d368e52011-05-24 11:44:12 -04005799 phba->sli4_hba.xri_ids = kzalloc(count *
5800 sizeof(uint16_t),
5801 GFP_KERNEL);
5802 if (unlikely(!phba->sli4_hba.xri_ids)) {
5803 rc = -ENOMEM;
5804 goto free_xri_bmask;
5805 }
5806
5807 for (i = 0; i < count; i++)
5808 phba->sli4_hba.xri_ids[i] = base + i;
5809
5810 /* VFIs. */
5811 count = phba->sli4_hba.max_cfg_param.max_vfi;
James Smart0a630c22013-01-03 15:44:09 -05005812 if (count <= 0) {
5813 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5814 "3282 Invalid provisioning of "
5815 "vfi:%d\n", count);
5816 rc = -EINVAL;
5817 goto free_xri_ids;
5818 }
James Smart6d368e52011-05-24 11:44:12 -04005819 base = phba->sli4_hba.max_cfg_param.vfi_base;
5820 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5821 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5822 sizeof(unsigned long),
5823 GFP_KERNEL);
5824 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5825 rc = -ENOMEM;
5826 goto free_xri_ids;
5827 }
5828 phba->sli4_hba.vfi_ids = kzalloc(count *
5829 sizeof(uint16_t),
5830 GFP_KERNEL);
5831 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5832 rc = -ENOMEM;
5833 goto free_vfi_bmask;
5834 }
5835
5836 for (i = 0; i < count; i++)
5837 phba->sli4_hba.vfi_ids[i] = base + i;
5838
5839 /*
5840 * Mark all resources ready. An HBA reset doesn't need
5841 * to reset the initialization.
5842 */
5843 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5844 LPFC_IDX_RSRC_RDY);
5845 return 0;
5846 }
5847
5848 free_vfi_bmask:
5849 kfree(phba->sli4_hba.vfi_bmask);
5850 free_xri_ids:
5851 kfree(phba->sli4_hba.xri_ids);
5852 free_xri_bmask:
5853 kfree(phba->sli4_hba.xri_bmask);
5854 free_vpi_ids:
5855 kfree(phba->vpi_ids);
5856 free_vpi_bmask:
5857 kfree(phba->vpi_bmask);
5858 free_rpi_ids:
5859 kfree(phba->sli4_hba.rpi_ids);
5860 free_rpi_bmask:
5861 kfree(phba->sli4_hba.rpi_bmask);
5862 err_exit:
5863 return rc;
5864}
5865
5866/**
5867 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5868 * @phba: Pointer to HBA context object.
5869 *
5870 * This function allocates the number of elements for the specified
5871 * resource type.
5872 **/
5873int
5874lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
5875{
5876 if (phba->sli4_hba.extents_in_use) {
5877 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5878 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5879 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5880 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5881 } else {
5882 kfree(phba->vpi_bmask);
James Smart16a3a202013-04-17 20:14:38 -04005883 phba->sli4_hba.max_cfg_param.vpi_used = 0;
James Smart6d368e52011-05-24 11:44:12 -04005884 kfree(phba->vpi_ids);
5885 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5886 kfree(phba->sli4_hba.xri_bmask);
5887 kfree(phba->sli4_hba.xri_ids);
James Smart6d368e52011-05-24 11:44:12 -04005888 kfree(phba->sli4_hba.vfi_bmask);
5889 kfree(phba->sli4_hba.vfi_ids);
5890 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5891 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5892 }
5893
5894 return 0;
5895}
5896
5897/**
James Smartb76f2dc2011-07-22 18:37:42 -04005898 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5899 * @phba: Pointer to HBA context object.
5900 * @type: The resource extent type.
5901 * @extnt_count: buffer to hold port extent count response
5902 * @extnt_size: buffer to hold port extent size response.
5903 *
5904 * This function calls the port to read the host allocated extents
5905 * for a particular type.
5906 **/
5907int
5908lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
5909 uint16_t *extnt_cnt, uint16_t *extnt_size)
5910{
5911 bool emb;
5912 int rc = 0;
5913 uint16_t curr_blks = 0;
5914 uint32_t req_len, emb_len;
5915 uint32_t alloc_len, mbox_tmo;
5916 struct list_head *blk_list_head;
5917 struct lpfc_rsrc_blks *rsrc_blk;
5918 LPFC_MBOXQ_t *mbox;
5919 void *virtaddr = NULL;
5920 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5921 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5922 union lpfc_sli4_cfg_shdr *shdr;
5923
5924 switch (type) {
5925 case LPFC_RSC_TYPE_FCOE_VPI:
5926 blk_list_head = &phba->lpfc_vpi_blk_list;
5927 break;
5928 case LPFC_RSC_TYPE_FCOE_XRI:
5929 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
5930 break;
5931 case LPFC_RSC_TYPE_FCOE_VFI:
5932 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
5933 break;
5934 case LPFC_RSC_TYPE_FCOE_RPI:
5935 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
5936 break;
5937 default:
5938 return -EIO;
5939 }
5940
5941 /* Count the number of extents currently allocatd for this type. */
5942 list_for_each_entry(rsrc_blk, blk_list_head, list) {
5943 if (curr_blks == 0) {
5944 /*
5945 * The GET_ALLOCATED mailbox does not return the size,
5946 * just the count. The size should be just the size
5947 * stored in the current allocated block and all sizes
5948 * for an extent type are the same so set the return
5949 * value now.
5950 */
5951 *extnt_size = rsrc_blk->rsrc_size;
5952 }
5953 curr_blks++;
5954 }
5955
5956 /* Calculate the total requested length of the dma memory. */
5957 req_len = curr_blks * sizeof(uint16_t);
5958
5959 /*
5960 * Calculate the size of an embedded mailbox. The uint32_t
5961 * accounts for extents-specific word.
5962 */
5963 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5964 sizeof(uint32_t);
5965
5966 /*
5967 * Presume the allocation and response will fit into an embedded
5968 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5969 */
5970 emb = LPFC_SLI4_MBX_EMBED;
5971 req_len = emb_len;
5972 if (req_len > emb_len) {
5973 req_len = curr_blks * sizeof(uint16_t) +
5974 sizeof(union lpfc_sli4_cfg_shdr) +
5975 sizeof(uint32_t);
5976 emb = LPFC_SLI4_MBX_NEMBED;
5977 }
5978
5979 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5980 if (!mbox)
5981 return -ENOMEM;
5982 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
5983
5984 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5985 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
5986 req_len, emb);
5987 if (alloc_len < req_len) {
5988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5989 "2983 Allocated DMA memory size (x%x) is "
5990 "less than the requested DMA memory "
5991 "size (x%x)\n", alloc_len, req_len);
5992 rc = -ENOMEM;
5993 goto err_exit;
5994 }
5995 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
5996 if (unlikely(rc)) {
5997 rc = -EIO;
5998 goto err_exit;
5999 }
6000
6001 if (!phba->sli4_hba.intr_enable)
6002 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6003 else {
James Smarta183a152011-10-10 21:32:43 -04006004 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smartb76f2dc2011-07-22 18:37:42 -04006005 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6006 }
6007
6008 if (unlikely(rc)) {
6009 rc = -EIO;
6010 goto err_exit;
6011 }
6012
6013 /*
6014 * Figure out where the response is located. Then get local pointers
6015 * to the response data. The port does not guarantee to respond to
6016 * all extents counts request so update the local variable with the
6017 * allocated count from the port.
6018 */
6019 if (emb == LPFC_SLI4_MBX_EMBED) {
6020 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
6021 shdr = &rsrc_ext->header.cfg_shdr;
6022 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
6023 } else {
6024 virtaddr = mbox->sge_array->addr[0];
6025 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6026 shdr = &n_rsrc->cfg_shdr;
6027 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6028 }
6029
6030 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
6031 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
6032 "2984 Failed to read allocated resources "
6033 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6034 type,
6035 bf_get(lpfc_mbox_hdr_status, &shdr->response),
6036 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
6037 rc = -EIO;
6038 goto err_exit;
6039 }
6040 err_exit:
6041 lpfc_sli4_mbox_cmd_free(phba, mbox);
6042 return rc;
6043}
6044
6045/**
James Smart8a9d2e82012-05-09 21:16:12 -04006046 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
6047 * @phba: pointer to lpfc hba data structure.
6048 *
6049 * This routine walks the list of els buffers that have been allocated and
6050 * repost them to the port by using SGL block post. This is needed after a
6051 * pci_function_reset/warm_start or start. It attempts to construct blocks
6052 * of els buffer sgls which contains contiguous xris and uses the non-embedded
6053 * SGL block post mailbox commands to post them to the port. For single els
6054 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6055 * mailbox command for posting.
6056 *
6057 * Returns: 0 = success, non-zero failure.
6058 **/
6059static int
6060lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
6061{
6062 struct lpfc_sglq *sglq_entry = NULL;
6063 struct lpfc_sglq *sglq_entry_next = NULL;
6064 struct lpfc_sglq *sglq_entry_first = NULL;
James Smart711ea882013-04-17 20:18:29 -04006065 int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04006066 int last_xritag = NO_XRI;
James Smartdafe8ce2014-09-03 12:56:40 -04006067 struct lpfc_sli_ring *pring;
James Smart8a9d2e82012-05-09 21:16:12 -04006068 LIST_HEAD(prep_sgl_list);
6069 LIST_HEAD(blck_sgl_list);
6070 LIST_HEAD(allc_sgl_list);
6071 LIST_HEAD(post_sgl_list);
6072 LIST_HEAD(free_sgl_list);
6073
James Smartdafe8ce2014-09-03 12:56:40 -04006074 pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart38c20672013-03-01 16:37:44 -05006075 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04006076 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04006077 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04006078 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05006079 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04006080
James Smart711ea882013-04-17 20:18:29 -04006081 total_cnt = phba->sli4_hba.els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04006082 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
6083 &allc_sgl_list, list) {
6084 list_del_init(&sglq_entry->list);
6085 block_cnt++;
6086 if ((last_xritag != NO_XRI) &&
6087 (sglq_entry->sli4_xritag != last_xritag + 1)) {
6088 /* a hole in xri block, form a sgl posting block */
6089 list_splice_init(&prep_sgl_list, &blck_sgl_list);
6090 post_cnt = block_cnt - 1;
6091 /* prepare list for next posting block */
6092 list_add_tail(&sglq_entry->list, &prep_sgl_list);
6093 block_cnt = 1;
6094 } else {
6095 /* prepare list for next posting block */
6096 list_add_tail(&sglq_entry->list, &prep_sgl_list);
6097 /* enough sgls for non-embed sgl mbox command */
6098 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
6099 list_splice_init(&prep_sgl_list,
6100 &blck_sgl_list);
6101 post_cnt = block_cnt;
6102 block_cnt = 0;
6103 }
6104 }
6105 num_posted++;
6106
6107 /* keep track of last sgl's xritag */
6108 last_xritag = sglq_entry->sli4_xritag;
6109
6110 /* end of repost sgl list condition for els buffers */
6111 if (num_posted == phba->sli4_hba.els_xri_cnt) {
6112 if (post_cnt == 0) {
6113 list_splice_init(&prep_sgl_list,
6114 &blck_sgl_list);
6115 post_cnt = block_cnt;
6116 } else if (block_cnt == 1) {
6117 status = lpfc_sli4_post_sgl(phba,
6118 sglq_entry->phys, 0,
6119 sglq_entry->sli4_xritag);
6120 if (!status) {
6121 /* successful, put sgl to posted list */
6122 list_add_tail(&sglq_entry->list,
6123 &post_sgl_list);
6124 } else {
6125 /* Failure, put sgl to free list */
6126 lpfc_printf_log(phba, KERN_WARNING,
6127 LOG_SLI,
6128 "3159 Failed to post els "
6129 "sgl, xritag:x%x\n",
6130 sglq_entry->sli4_xritag);
6131 list_add_tail(&sglq_entry->list,
6132 &free_sgl_list);
James Smart711ea882013-04-17 20:18:29 -04006133 total_cnt--;
James Smart8a9d2e82012-05-09 21:16:12 -04006134 }
6135 }
6136 }
6137
6138 /* continue until a nembed page worth of sgls */
6139 if (post_cnt == 0)
6140 continue;
6141
6142 /* post the els buffer list sgls as a block */
6143 status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
6144 post_cnt);
6145
6146 if (!status) {
6147 /* success, put sgl list to posted sgl list */
6148 list_splice_init(&blck_sgl_list, &post_sgl_list);
6149 } else {
6150 /* Failure, put sgl list to free sgl list */
6151 sglq_entry_first = list_first_entry(&blck_sgl_list,
6152 struct lpfc_sglq,
6153 list);
6154 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6155 "3160 Failed to post els sgl-list, "
6156 "xritag:x%x-x%x\n",
6157 sglq_entry_first->sli4_xritag,
6158 (sglq_entry_first->sli4_xritag +
6159 post_cnt - 1));
6160 list_splice_init(&blck_sgl_list, &free_sgl_list);
James Smart711ea882013-04-17 20:18:29 -04006161 total_cnt -= post_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04006162 }
6163
6164 /* don't reset xirtag due to hole in xri block */
6165 if (block_cnt == 0)
6166 last_xritag = NO_XRI;
6167
6168 /* reset els sgl post count for next round of posting */
6169 post_cnt = 0;
6170 }
James Smart711ea882013-04-17 20:18:29 -04006171 /* update the number of XRIs posted for ELS */
6172 phba->sli4_hba.els_xri_cnt = total_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04006173
6174 /* free the els sgls failed to post */
6175 lpfc_free_sgl_list(phba, &free_sgl_list);
6176
6177 /* push els sgls posted to the availble list */
6178 if (!list_empty(&post_sgl_list)) {
James Smart38c20672013-03-01 16:37:44 -05006179 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04006180 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04006181 list_splice_init(&post_sgl_list,
6182 &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04006183 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05006184 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04006185 } else {
6186 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6187 "3161 Failure to post els sgl to port.\n");
6188 return -EIO;
6189 }
6190 return 0;
6191}
6192
6193/**
James Smartda0436e2009-05-22 14:51:39 -04006194 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6195 * @phba: Pointer to HBA context object.
6196 *
6197 * This function is the main SLI4 device intialization PCI function. This
6198 * function is called by the HBA intialization code, HBA reset code and
6199 * HBA error attention handler code. Caller is not required to hold any
6200 * locks.
6201 **/
6202int
6203lpfc_sli4_hba_setup(struct lpfc_hba *phba)
6204{
6205 int rc;
6206 LPFC_MBOXQ_t *mboxq;
6207 struct lpfc_mqe *mqe;
6208 uint8_t *vpd;
6209 uint32_t vpd_size;
6210 uint32_t ftr_rsp = 0;
6211 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
6212 struct lpfc_vport *vport = phba->pport;
6213 struct lpfc_dmabuf *mp;
6214
6215 /* Perform a PCI function reset to start from clean */
6216 rc = lpfc_pci_function_reset(phba);
6217 if (unlikely(rc))
6218 return -ENODEV;
6219
6220 /* Check the HBA Host Status Register for readyness */
6221 rc = lpfc_sli4_post_status_check(phba);
6222 if (unlikely(rc))
6223 return -ENODEV;
6224 else {
6225 spin_lock_irq(&phba->hbalock);
6226 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
6227 spin_unlock_irq(&phba->hbalock);
6228 }
6229
6230 /*
6231 * Allocate a single mailbox container for initializing the
6232 * port.
6233 */
6234 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6235 if (!mboxq)
6236 return -ENOMEM;
6237
James Smartda0436e2009-05-22 14:51:39 -04006238 /* Issue READ_REV to collect vpd and FW information. */
James Smart49198b32010-04-06 15:04:33 -04006239 vpd_size = SLI4_PAGE_SIZE;
James Smartda0436e2009-05-22 14:51:39 -04006240 vpd = kzalloc(vpd_size, GFP_KERNEL);
6241 if (!vpd) {
6242 rc = -ENOMEM;
6243 goto out_free_mbox;
6244 }
6245
6246 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
James Smart76a95d72010-11-20 23:11:48 -05006247 if (unlikely(rc)) {
6248 kfree(vpd);
6249 goto out_free_mbox;
6250 }
James Smart572709e2013-07-15 18:32:43 -04006251
James Smartda0436e2009-05-22 14:51:39 -04006252 mqe = &mboxq->u.mqe;
James Smartf1126682009-06-10 17:22:44 -04006253 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
6254 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
James Smart76a95d72010-11-20 23:11:48 -05006255 phba->hba_flag |= HBA_FCOE_MODE;
6256 else
6257 phba->hba_flag &= ~HBA_FCOE_MODE;
James Smart45ed1192009-10-02 15:17:02 -04006258
6259 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
6260 LPFC_DCBX_CEE_MODE)
6261 phba->hba_flag |= HBA_FIP_SUPPORT;
6262 else
6263 phba->hba_flag &= ~HBA_FIP_SUPPORT;
6264
James Smart4f2e66c2012-05-09 21:17:07 -04006265 phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
6266
James Smartc31098c2011-04-16 11:03:33 -04006267 if (phba->sli_rev != LPFC_SLI_REV4) {
James Smartda0436e2009-05-22 14:51:39 -04006268 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6269 "0376 READ_REV Error. SLI Level %d "
6270 "FCoE enabled %d\n",
James Smart76a95d72010-11-20 23:11:48 -05006271 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
James Smartda0436e2009-05-22 14:51:39 -04006272 rc = -EIO;
James Smart76a95d72010-11-20 23:11:48 -05006273 kfree(vpd);
6274 goto out_free_mbox;
James Smartda0436e2009-05-22 14:51:39 -04006275 }
James Smartcd1c8302011-10-10 21:33:25 -04006276
6277 /*
James Smartff78d8f2011-12-13 13:21:35 -05006278 * Continue initialization with default values even if driver failed
6279 * to read FCoE param config regions, only read parameters if the
6280 * board is FCoE
6281 */
6282 if (phba->hba_flag & HBA_FCOE_MODE &&
6283 lpfc_sli4_read_fcoe_params(phba))
6284 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
6285 "2570 Failed to read FCoE parameters\n");
6286
6287 /*
James Smartcd1c8302011-10-10 21:33:25 -04006288 * Retrieve sli4 device physical port name, failure of doing it
6289 * is considered as non-fatal.
6290 */
6291 rc = lpfc_sli4_retrieve_pport_name(phba);
6292 if (!rc)
6293 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6294 "3080 Successful retrieving SLI4 device "
6295 "physical port name: %s.\n", phba->Port);
6296
James Smartda0436e2009-05-22 14:51:39 -04006297 /*
6298 * Evaluate the read rev and vpd data. Populate the driver
6299 * state with the results. If this routine fails, the failure
6300 * is not fatal as the driver will use generic values.
6301 */
6302 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
6303 if (unlikely(!rc)) {
6304 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6305 "0377 Error %d parsing vpd. "
6306 "Using defaults.\n", rc);
6307 rc = 0;
6308 }
James Smart76a95d72010-11-20 23:11:48 -05006309 kfree(vpd);
James Smartda0436e2009-05-22 14:51:39 -04006310
James Smartf1126682009-06-10 17:22:44 -04006311 /* Save information as VPD data */
6312 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
6313 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
6314 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
6315 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
6316 &mqe->un.read_rev);
6317 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
6318 &mqe->un.read_rev);
6319 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
6320 &mqe->un.read_rev);
6321 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
6322 &mqe->un.read_rev);
6323 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
6324 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
6325 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
6326 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
6327 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
6328 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
6329 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6330 "(%d):0380 READ_REV Status x%x "
6331 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6332 mboxq->vport ? mboxq->vport->vpi : 0,
6333 bf_get(lpfc_mqe_status, mqe),
6334 phba->vpd.rev.opFwName,
6335 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
6336 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
James Smartda0436e2009-05-22 14:51:39 -04006337
James Smart572709e2013-07-15 18:32:43 -04006338 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6339 rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3);
6340 if (phba->pport->cfg_lun_queue_depth > rc) {
6341 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6342 "3362 LUN queue depth changed from %d to %d\n",
6343 phba->pport->cfg_lun_queue_depth, rc);
6344 phba->pport->cfg_lun_queue_depth = rc;
6345 }
6346
6347
James Smartda0436e2009-05-22 14:51:39 -04006348 /*
6349 * Discover the port's supported feature set and match it against the
6350 * hosts requests.
6351 */
6352 lpfc_request_features(phba, mboxq);
6353 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6354 if (unlikely(rc)) {
6355 rc = -EIO;
James Smart76a95d72010-11-20 23:11:48 -05006356 goto out_free_mbox;
James Smartda0436e2009-05-22 14:51:39 -04006357 }
6358
6359 /*
6360 * The port must support FCP initiator mode as this is the
6361 * only mode running in the host.
6362 */
6363 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
6364 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6365 "0378 No support for fcpi mode.\n");
6366 ftr_rsp++;
6367 }
James Smartfedd3b72011-02-16 12:39:24 -05006368 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
6369 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
6370 else
6371 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
James Smartda0436e2009-05-22 14:51:39 -04006372 /*
6373 * If the port cannot support the host's requested features
6374 * then turn off the global config parameters to disable the
6375 * feature in the driver. This is not a fatal error.
6376 */
James Smartbf086112011-08-21 21:48:13 -04006377 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
6378 if (phba->cfg_enable_bg) {
6379 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
6380 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6381 else
6382 ftr_rsp++;
6383 }
James Smartda0436e2009-05-22 14:51:39 -04006384
6385 if (phba->max_vpi && phba->cfg_enable_npiv &&
6386 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
6387 ftr_rsp++;
6388
6389 if (ftr_rsp) {
6390 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6391 "0379 Feature Mismatch Data: x%08x %08x "
6392 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
6393 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
6394 phba->cfg_enable_npiv, phba->max_vpi);
6395 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
6396 phba->cfg_enable_bg = 0;
6397 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
6398 phba->cfg_enable_npiv = 0;
6399 }
6400
6401 /* These SLI3 features are assumed in SLI4 */
6402 spin_lock_irq(&phba->hbalock);
6403 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
6404 spin_unlock_irq(&phba->hbalock);
6405
James Smart6d368e52011-05-24 11:44:12 -04006406 /*
6407 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6408 * calls depends on these resources to complete port setup.
6409 */
6410 rc = lpfc_sli4_alloc_resource_identifiers(phba);
6411 if (rc) {
6412 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6413 "2920 Failed to alloc Resource IDs "
6414 "rc = x%x\n", rc);
6415 goto out_free_mbox;
6416 }
6417
James Smartda0436e2009-05-22 14:51:39 -04006418 /* Read the port's service parameters. */
James Smart9f1177a2010-02-26 14:12:57 -05006419 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
6420 if (rc) {
6421 phba->link_state = LPFC_HBA_ERROR;
6422 rc = -ENOMEM;
James Smart76a95d72010-11-20 23:11:48 -05006423 goto out_free_mbox;
James Smart9f1177a2010-02-26 14:12:57 -05006424 }
6425
James Smartda0436e2009-05-22 14:51:39 -04006426 mboxq->vport = vport;
6427 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6428 mp = (struct lpfc_dmabuf *) mboxq->context1;
6429 if (rc == MBX_SUCCESS) {
6430 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
6431 rc = 0;
6432 }
6433
6434 /*
6435 * This memory was allocated by the lpfc_read_sparam routine. Release
6436 * it to the mbuf pool.
6437 */
6438 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6439 kfree(mp);
6440 mboxq->context1 = NULL;
6441 if (unlikely(rc)) {
6442 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6443 "0382 READ_SPARAM command failed "
6444 "status %d, mbxStatus x%x\n",
6445 rc, bf_get(lpfc_mqe_status, mqe));
6446 phba->link_state = LPFC_HBA_ERROR;
6447 rc = -EIO;
James Smart76a95d72010-11-20 23:11:48 -05006448 goto out_free_mbox;
James Smartda0436e2009-05-22 14:51:39 -04006449 }
6450
James Smart05580562011-05-24 11:40:48 -04006451 lpfc_update_vport_wwn(vport);
James Smartda0436e2009-05-22 14:51:39 -04006452
6453 /* Update the fc_host data structures with new wwn. */
6454 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
6455 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
6456
James Smart8a9d2e82012-05-09 21:16:12 -04006457 /* update host els and scsi xri-sgl sizes and mappings */
6458 rc = lpfc_sli4_xri_sgl_update(phba);
6459 if (unlikely(rc)) {
6460 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6461 "1400 Failed to update xri-sgl size and "
6462 "mapping: %d\n", rc);
6463 goto out_free_mbox;
James Smartda0436e2009-05-22 14:51:39 -04006464 }
6465
James Smart8a9d2e82012-05-09 21:16:12 -04006466 /* register the els sgl pool to the port */
6467 rc = lpfc_sli4_repost_els_sgl_list(phba);
6468 if (unlikely(rc)) {
6469 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6470 "0582 Error %d during els sgl post "
6471 "operation\n", rc);
6472 rc = -ENODEV;
6473 goto out_free_mbox;
6474 }
6475
6476 /* register the allocated scsi sgl pool to the port */
James Smartda0436e2009-05-22 14:51:39 -04006477 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
6478 if (unlikely(rc)) {
James Smart6d368e52011-05-24 11:44:12 -04006479 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smart6a9c52c2009-10-02 15:16:51 -04006480 "0383 Error %d during scsi sgl post "
6481 "operation\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04006482 /* Some Scsi buffers were moved to the abort scsi list */
6483 /* A pci function reset will repost them */
6484 rc = -ENODEV;
James Smart76a95d72010-11-20 23:11:48 -05006485 goto out_free_mbox;
James Smartda0436e2009-05-22 14:51:39 -04006486 }
6487
6488 /* Post the rpi header region to the device. */
6489 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
6490 if (unlikely(rc)) {
6491 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6492 "0393 Error %d during rpi post operation\n",
6493 rc);
6494 rc = -ENODEV;
James Smart76a95d72010-11-20 23:11:48 -05006495 goto out_free_mbox;
James Smartda0436e2009-05-22 14:51:39 -04006496 }
James Smart97f2ecf2012-03-01 22:35:23 -05006497 lpfc_sli4_node_prep(phba);
James Smartda0436e2009-05-22 14:51:39 -04006498
James Smart5350d872011-10-10 21:33:49 -04006499 /* Create all the SLI4 queues */
6500 rc = lpfc_sli4_queue_create(phba);
6501 if (rc) {
6502 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6503 "3089 Failed to allocate queues\n");
6504 rc = -ENODEV;
6505 goto out_stop_timers;
6506 }
James Smartda0436e2009-05-22 14:51:39 -04006507 /* Set up all the queues to the device */
6508 rc = lpfc_sli4_queue_setup(phba);
6509 if (unlikely(rc)) {
6510 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6511 "0381 Error %d during queue setup.\n ", rc);
James Smart5350d872011-10-10 21:33:49 -04006512 goto out_destroy_queue;
James Smartda0436e2009-05-22 14:51:39 -04006513 }
6514
6515 /* Arm the CQs and then EQs on device */
6516 lpfc_sli4_arm_cqeq_intr(phba);
6517
6518 /* Indicate device interrupt mode */
6519 phba->sli4_hba.intr_enable = 1;
6520
6521 /* Allow asynchronous mailbox command to go through */
6522 spin_lock_irq(&phba->hbalock);
6523 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
6524 spin_unlock_irq(&phba->hbalock);
6525
6526 /* Post receive buffers to the device */
6527 lpfc_sli4_rb_setup(phba);
6528
James Smartfc2b9892010-02-26 14:15:29 -05006529 /* Reset HBA FCF states after HBA reset */
6530 phba->fcf.fcf_flag = 0;
6531 phba->fcf.current_rec.flag = 0;
6532
James Smartda0436e2009-05-22 14:51:39 -04006533 /* Start the ELS watchdog timer */
James Smart8fa38512009-07-19 10:01:03 -04006534 mod_timer(&vport->els_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04006535 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
James Smartda0436e2009-05-22 14:51:39 -04006536
6537 /* Start heart beat timer */
6538 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04006539 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smartda0436e2009-05-22 14:51:39 -04006540 phba->hb_outstanding = 0;
6541 phba->last_completion_time = jiffies;
6542
6543 /* Start error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -04006544 mod_timer(&phba->eratt_poll,
6545 jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
James Smartda0436e2009-05-22 14:51:39 -04006546
James Smart75baf692010-06-08 18:31:21 -04006547 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6548 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
6549 rc = pci_enable_pcie_error_reporting(phba->pcidev);
6550 if (!rc) {
6551 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6552 "2829 This device supports "
6553 "Advanced Error Reporting (AER)\n");
6554 spin_lock_irq(&phba->hbalock);
6555 phba->hba_flag |= HBA_AER_ENABLED;
6556 spin_unlock_irq(&phba->hbalock);
6557 } else {
6558 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6559 "2830 This device does not support "
6560 "Advanced Error Reporting (AER)\n");
6561 phba->cfg_aer_support = 0;
6562 }
James Smart0a96e972011-07-22 18:37:28 -04006563 rc = 0;
James Smart75baf692010-06-08 18:31:21 -04006564 }
6565
James Smart76a95d72010-11-20 23:11:48 -05006566 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
6567 /*
6568 * The FC Port needs to register FCFI (index 0)
6569 */
6570 lpfc_reg_fcfi(phba, mboxq);
6571 mboxq->vport = phba->pport;
6572 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smart9589b0622011-04-16 11:03:17 -04006573 if (rc != MBX_SUCCESS)
James Smart76a95d72010-11-20 23:11:48 -05006574 goto out_unset_queue;
James Smart9589b0622011-04-16 11:03:17 -04006575 rc = 0;
6576 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
6577 &mboxq->u.mqe.un.reg_fcfi);
James Smart026abb82011-12-13 13:20:45 -05006578
6579 /* Check if the port is configured to be disabled */
6580 lpfc_sli_read_link_ste(phba);
James Smart76a95d72010-11-20 23:11:48 -05006581 }
James Smart026abb82011-12-13 13:20:45 -05006582
James Smartda0436e2009-05-22 14:51:39 -04006583 /*
6584 * The port is ready, set the host's link state to LINK_DOWN
6585 * in preparation for link interrupts.
6586 */
James Smartda0436e2009-05-22 14:51:39 -04006587 spin_lock_irq(&phba->hbalock);
6588 phba->link_state = LPFC_LINK_DOWN;
6589 spin_unlock_irq(&phba->hbalock);
James Smart026abb82011-12-13 13:20:45 -05006590 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
6591 (phba->hba_flag & LINK_DISABLED)) {
6592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
6593 "3103 Adapter Link is disabled.\n");
6594 lpfc_down_link(phba, mboxq);
6595 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6596 if (rc != MBX_SUCCESS) {
6597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
6598 "3104 Adapter failed to issue "
6599 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
6600 goto out_unset_queue;
6601 }
6602 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart1b511972011-12-13 13:23:09 -05006603 /* don't perform init_link on SLI4 FC port loopback test */
6604 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
6605 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
6606 if (rc)
6607 goto out_unset_queue;
6608 }
James Smart5350d872011-10-10 21:33:49 -04006609 }
6610 mempool_free(mboxq, phba->mbox_mem_pool);
6611 return rc;
James Smart76a95d72010-11-20 23:11:48 -05006612out_unset_queue:
James Smartda0436e2009-05-22 14:51:39 -04006613 /* Unset all the queues set up in this routine when error out */
James Smart5350d872011-10-10 21:33:49 -04006614 lpfc_sli4_queue_unset(phba);
6615out_destroy_queue:
6616 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006617out_stop_timers:
James Smart5350d872011-10-10 21:33:49 -04006618 lpfc_stop_hba_timers(phba);
James Smartda0436e2009-05-22 14:51:39 -04006619out_free_mbox:
6620 mempool_free(mboxq, phba->mbox_mem_pool);
6621 return rc;
6622}
James Smarte59058c2008-08-24 21:49:00 -04006623
6624/**
James Smart3621a712009-04-06 18:47:14 -04006625 * lpfc_mbox_timeout - Timeout call back function for mbox timer
James Smarte59058c2008-08-24 21:49:00 -04006626 * @ptr: context object - pointer to hba structure.
dea31012005-04-17 16:05:31 -05006627 *
James Smarte59058c2008-08-24 21:49:00 -04006628 * This is the callback function for mailbox timer. The mailbox
6629 * timer is armed when a new mailbox command is issued and the timer
6630 * is deleted when the mailbox complete. The function is called by
6631 * the kernel timer code when a mailbox does not complete within
6632 * expected time. This function wakes up the worker thread to
6633 * process the mailbox timeout and returns. All the processing is
6634 * done by the worker thread function lpfc_mbox_timeout_handler.
6635 **/
dea31012005-04-17 16:05:31 -05006636void
6637lpfc_mbox_timeout(unsigned long ptr)
6638{
James Smart92d7f7b2007-06-17 19:56:38 -05006639 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
dea31012005-04-17 16:05:31 -05006640 unsigned long iflag;
James Smart2e0fef82007-06-17 19:56:36 -05006641 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006642
James Smart2e0fef82007-06-17 19:56:36 -05006643 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006644 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05006645 if (!tmo_posted)
6646 phba->pport->work_port_events |= WORKER_MBOX_TMO;
6647 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
6648
James Smart5e9d9b82008-06-14 22:52:53 -04006649 if (!tmo_posted)
6650 lpfc_worker_wake_up(phba);
6651 return;
dea31012005-04-17 16:05:31 -05006652}
6653
James Smarte8d3c3b2013-10-10 12:21:30 -04006654/**
6655 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
6656 * are pending
6657 * @phba: Pointer to HBA context object.
6658 *
6659 * This function checks if any mailbox completions are present on the mailbox
6660 * completion queue.
6661 **/
6662bool
6663lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
6664{
6665
6666 uint32_t idx;
6667 struct lpfc_queue *mcq;
6668 struct lpfc_mcqe *mcqe;
6669 bool pending_completions = false;
6670
6671 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
6672 return false;
6673
6674 /* Check for completions on mailbox completion queue */
6675
6676 mcq = phba->sli4_hba.mbx_cq;
6677 idx = mcq->hba_index;
6678 while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) {
6679 mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe;
6680 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
6681 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
6682 pending_completions = true;
6683 break;
6684 }
6685 idx = (idx + 1) % mcq->entry_count;
6686 if (mcq->hba_index == idx)
6687 break;
6688 }
6689 return pending_completions;
6690
6691}
6692
6693/**
6694 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
6695 * that were missed.
6696 * @phba: Pointer to HBA context object.
6697 *
6698 * For sli4, it is possible to miss an interrupt. As such mbox completions
6699 * maybe missed causing erroneous mailbox timeouts to occur. This function
6700 * checks to see if mbox completions are on the mailbox completion queue
6701 * and will process all the completions associated with the eq for the
6702 * mailbox completion queue.
6703 **/
6704bool
6705lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
6706{
6707
6708 uint32_t eqidx;
6709 struct lpfc_queue *fpeq = NULL;
6710 struct lpfc_eqe *eqe;
6711 bool mbox_pending;
6712
6713 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
6714 return false;
6715
6716 /* Find the eq associated with the mcq */
6717
6718 if (phba->sli4_hba.hba_eq)
6719 for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++)
6720 if (phba->sli4_hba.hba_eq[eqidx]->queue_id ==
6721 phba->sli4_hba.mbx_cq->assoc_qid) {
6722 fpeq = phba->sli4_hba.hba_eq[eqidx];
6723 break;
6724 }
6725 if (!fpeq)
6726 return false;
6727
6728 /* Turn off interrupts from this EQ */
6729
6730 lpfc_sli4_eq_clr_intr(fpeq);
6731
6732 /* Check to see if a mbox completion is pending */
6733
6734 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
6735
6736 /*
6737 * If a mbox completion is pending, process all the events on EQ
6738 * associated with the mbox completion queue (this could include
6739 * mailbox commands, async events, els commands, receive queue data
6740 * and fcp commands)
6741 */
6742
6743 if (mbox_pending)
6744 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
6745 lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx);
6746 fpeq->EQ_processed++;
6747 }
6748
6749 /* Always clear and re-arm the EQ */
6750
6751 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
6752
6753 return mbox_pending;
6754
6755}
James Smarte59058c2008-08-24 21:49:00 -04006756
6757/**
James Smart3621a712009-04-06 18:47:14 -04006758 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
James Smarte59058c2008-08-24 21:49:00 -04006759 * @phba: Pointer to HBA context object.
6760 *
6761 * This function is called from worker thread when a mailbox command times out.
6762 * The caller is not required to hold any locks. This function will reset the
6763 * HBA and recover all the pending commands.
6764 **/
dea31012005-04-17 16:05:31 -05006765void
6766lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
6767{
James Smart2e0fef82007-06-17 19:56:36 -05006768 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
James Smart04c68492009-05-22 14:52:52 -04006769 MAILBOX_t *mb = &pmbox->u.mb;
James Smart1dcb58e2007-04-25 09:51:30 -04006770 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05006771
James Smarte8d3c3b2013-10-10 12:21:30 -04006772 /* If the mailbox completed, process the completion and return */
6773 if (lpfc_sli4_process_missed_mbox_completions(phba))
6774 return;
6775
James Smarta257bf92009-04-06 18:48:10 -04006776 /* Check the pmbox pointer first. There is a race condition
6777 * between the mbox timeout handler getting executed in the
6778 * worklist and the mailbox actually completing. When this
6779 * race condition occurs, the mbox_active will be NULL.
6780 */
6781 spin_lock_irq(&phba->hbalock);
6782 if (pmbox == NULL) {
6783 lpfc_printf_log(phba, KERN_WARNING,
6784 LOG_MBOX | LOG_SLI,
6785 "0353 Active Mailbox cleared - mailbox timeout "
6786 "exiting\n");
6787 spin_unlock_irq(&phba->hbalock);
6788 return;
6789 }
6790
dea31012005-04-17 16:05:31 -05006791 /* Mbox cmd <mbxCommand> timeout */
James Smarted957682007-06-17 19:56:37 -05006792 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04006793 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
James Smart92d7f7b2007-06-17 19:56:38 -05006794 mb->mbxCommand,
6795 phba->pport->port_state,
6796 phba->sli.sli_flag,
6797 phba->sli.mbox_active);
James Smarta257bf92009-04-06 18:48:10 -04006798 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006799
James Smart1dcb58e2007-04-25 09:51:30 -04006800 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6801 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006802 * it to fail all outstanding SCSI IO.
James Smart1dcb58e2007-04-25 09:51:30 -04006803 */
James Smart2e0fef82007-06-17 19:56:36 -05006804 spin_lock_irq(&phba->pport->work_port_lock);
6805 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
6806 spin_unlock_irq(&phba->pport->work_port_lock);
6807 spin_lock_irq(&phba->hbalock);
6808 phba->link_state = LPFC_LINK_UNKNOWN;
James Smartf4b4c682009-05-22 14:53:12 -04006809 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05006810 spin_unlock_irq(&phba->hbalock);
James Smart1dcb58e2007-04-25 09:51:30 -04006811
James Smartdb55fba2014-04-04 13:52:02 -04006812 lpfc_sli_abort_fcp_rings(phba);
James Smart1dcb58e2007-04-25 09:51:30 -04006813
6814 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smart76bb24e2007-10-27 13:38:00 -04006815 "0345 Resetting board due to mailbox timeout\n");
James Smart3772a992009-05-22 14:50:54 -04006816
6817 /* Reset the HBA device */
6818 lpfc_reset_hba(phba);
dea31012005-04-17 16:05:31 -05006819}
6820
James Smarte59058c2008-08-24 21:49:00 -04006821/**
James Smart3772a992009-05-22 14:50:54 -04006822 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
James Smarte59058c2008-08-24 21:49:00 -04006823 * @phba: Pointer to HBA context object.
6824 * @pmbox: Pointer to mailbox object.
6825 * @flag: Flag indicating how the mailbox need to be processed.
6826 *
6827 * This function is called by discovery code and HBA management code
James Smart3772a992009-05-22 14:50:54 -04006828 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6829 * function gets the hbalock to protect the data structures.
James Smarte59058c2008-08-24 21:49:00 -04006830 * The mailbox command can be submitted in polling mode, in which case
6831 * this function will wait in a polling loop for the completion of the
6832 * mailbox.
6833 * If the mailbox is submitted in no_wait mode (not polling) the
6834 * function will submit the command and returns immediately without waiting
6835 * for the mailbox completion. The no_wait is supported only when HBA
6836 * is in SLI2/SLI3 mode - interrupts are enabled.
6837 * The SLI interface allows only one mailbox pending at a time. If the
6838 * mailbox is issued in polling mode and there is already a mailbox
6839 * pending, then the function will return an error. If the mailbox is issued
6840 * in NO_WAIT mode and there is a mailbox pending already, the function
6841 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6842 * The sli layer owns the mailbox object until the completion of mailbox
6843 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6844 * return codes the caller owns the mailbox command after the return of
6845 * the function.
6846 **/
James Smart3772a992009-05-22 14:50:54 -04006847static int
6848lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
6849 uint32_t flag)
dea31012005-04-17 16:05:31 -05006850{
Randy Dunlapbf07bde2013-02-22 10:23:54 -08006851 MAILBOX_t *mbx;
James Smart2e0fef82007-06-17 19:56:36 -05006852 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05006853 uint32_t status, evtctr;
James Smart9940b972011-03-11 16:06:12 -05006854 uint32_t ha_copy, hc_copy;
dea31012005-04-17 16:05:31 -05006855 int i;
James Smart09372822008-01-11 01:52:54 -05006856 unsigned long timeout;
dea31012005-04-17 16:05:31 -05006857 unsigned long drvr_flag = 0;
James Smart34b02dc2008-08-24 21:49:55 -04006858 uint32_t word0, ldata;
dea31012005-04-17 16:05:31 -05006859 void __iomem *to_slim;
James Smart58da1ff2008-04-07 10:15:56 -04006860 int processing_queue = 0;
6861
6862 spin_lock_irqsave(&phba->hbalock, drvr_flag);
6863 if (!pmbox) {
James Smart8568a4d2009-07-19 10:01:16 -04006864 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart58da1ff2008-04-07 10:15:56 -04006865 /* processing mbox queue from intr_handler */
James Smart3772a992009-05-22 14:50:54 -04006866 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
6867 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6868 return MBX_SUCCESS;
6869 }
James Smart58da1ff2008-04-07 10:15:56 -04006870 processing_queue = 1;
James Smart58da1ff2008-04-07 10:15:56 -04006871 pmbox = lpfc_mbox_get(phba);
6872 if (!pmbox) {
6873 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6874 return MBX_SUCCESS;
6875 }
6876 }
dea31012005-04-17 16:05:31 -05006877
James Smarted957682007-06-17 19:56:37 -05006878 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
James Smart92d7f7b2007-06-17 19:56:38 -05006879 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
James Smarted957682007-06-17 19:56:37 -05006880 if(!pmbox->vport) {
James Smart58da1ff2008-04-07 10:15:56 -04006881 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
James Smarted957682007-06-17 19:56:37 -05006882 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05006883 LOG_MBOX | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04006884 "1806 Mbox x%x failed. No vport\n",
James Smart3772a992009-05-22 14:50:54 -04006885 pmbox->u.mb.mbxCommand);
James Smarted957682007-06-17 19:56:37 -05006886 dump_stack();
James Smart58da1ff2008-04-07 10:15:56 -04006887 goto out_not_finished;
James Smarted957682007-06-17 19:56:37 -05006888 }
6889 }
6890
Linas Vepstas8d63f372007-02-14 14:28:36 -06006891 /* If the PCI channel is in offline state, do not post mbox. */
James Smart58da1ff2008-04-07 10:15:56 -04006892 if (unlikely(pci_channel_offline(phba->pcidev))) {
6893 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6894 goto out_not_finished;
6895 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06006896
James Smarta257bf92009-04-06 18:48:10 -04006897 /* If HBA has a deferred error attention, fail the iocb. */
6898 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
6899 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6900 goto out_not_finished;
6901 }
6902
dea31012005-04-17 16:05:31 -05006903 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05006904
Randy Dunlapbf07bde2013-02-22 10:23:54 -08006905 mbx = &pmbox->u.mb;
dea31012005-04-17 16:05:31 -05006906 status = MBX_SUCCESS;
6907
James Smart2e0fef82007-06-17 19:56:36 -05006908 if (phba->link_state == LPFC_HBA_ERROR) {
6909 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05006910
6911 /* Mbox command <mbxCommand> cannot issue */
James Smart3772a992009-05-22 14:50:54 -04006912 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6913 "(%d):0311 Mailbox command x%x cannot "
6914 "issue Data: x%x x%x\n",
6915 pmbox->vport ? pmbox->vport->vpi : 0,
6916 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
James Smart58da1ff2008-04-07 10:15:56 -04006917 goto out_not_finished;
Jamie Wellnitz41415862006-02-28 19:25:27 -05006918 }
6919
Randy Dunlapbf07bde2013-02-22 10:23:54 -08006920 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
James Smart9940b972011-03-11 16:06:12 -05006921 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
6922 !(hc_copy & HC_MBINT_ENA)) {
6923 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
6924 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smart3772a992009-05-22 14:50:54 -04006925 "(%d):2528 Mailbox command x%x cannot "
6926 "issue Data: x%x x%x\n",
6927 pmbox->vport ? pmbox->vport->vpi : 0,
6928 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
James Smart9940b972011-03-11 16:06:12 -05006929 goto out_not_finished;
6930 }
James Smart92908312006-03-07 15:04:13 -05006931 }
6932
dea31012005-04-17 16:05:31 -05006933 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6934 /* Polling for a mbox command when another one is already active
6935 * is not allowed in SLI. Also, the driver must have established
6936 * SLI2 mode to queue and process multiple mbox commands.
6937 */
6938
6939 if (flag & MBX_POLL) {
James Smart2e0fef82007-06-17 19:56:36 -05006940 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05006941
6942 /* Mbox command <mbxCommand> cannot issue */
James Smart3772a992009-05-22 14:50:54 -04006943 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6944 "(%d):2529 Mailbox command x%x "
6945 "cannot issue Data: x%x x%x\n",
6946 pmbox->vport ? pmbox->vport->vpi : 0,
6947 pmbox->u.mb.mbxCommand,
6948 psli->sli_flag, flag);
James Smart58da1ff2008-04-07 10:15:56 -04006949 goto out_not_finished;
dea31012005-04-17 16:05:31 -05006950 }
6951
James Smart3772a992009-05-22 14:50:54 -04006952 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05006953 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05006954 /* Mbox command <mbxCommand> cannot issue */
James Smart3772a992009-05-22 14:50:54 -04006955 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6956 "(%d):2530 Mailbox command x%x "
6957 "cannot issue Data: x%x x%x\n",
6958 pmbox->vport ? pmbox->vport->vpi : 0,
6959 pmbox->u.mb.mbxCommand,
6960 psli->sli_flag, flag);
James Smart58da1ff2008-04-07 10:15:56 -04006961 goto out_not_finished;
dea31012005-04-17 16:05:31 -05006962 }
6963
dea31012005-04-17 16:05:31 -05006964 /* Another mailbox command is still being processed, queue this
6965 * command to be processed later.
6966 */
6967 lpfc_mbox_put(phba, pmbox);
6968
6969 /* Mbox cmd issue - BUSY */
James Smarted957682007-06-17 19:56:37 -05006970 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04006971 "(%d):0308 Mbox cmd issue - BUSY Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05006972 "x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05006973 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
Randy Dunlapbf07bde2013-02-22 10:23:54 -08006974 mbx->mbxCommand, phba->pport->port_state,
James Smart92d7f7b2007-06-17 19:56:38 -05006975 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05006976
6977 psli->slistat.mbox_busy++;
James Smart2e0fef82007-06-17 19:56:36 -05006978 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05006979
James Smart858c9f62007-06-17 19:56:39 -05006980 if (pmbox->vport) {
6981 lpfc_debugfs_disc_trc(pmbox->vport,
6982 LPFC_DISC_TRC_MBOX_VPORT,
6983 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
Randy Dunlapbf07bde2013-02-22 10:23:54 -08006984 (uint32_t)mbx->mbxCommand,
6985 mbx->un.varWords[0], mbx->un.varWords[1]);
James Smart858c9f62007-06-17 19:56:39 -05006986 }
6987 else {
6988 lpfc_debugfs_disc_trc(phba->pport,
6989 LPFC_DISC_TRC_MBOX,
6990 "MBOX Bsy: cmd:x%x mb:x%x x%x",
Randy Dunlapbf07bde2013-02-22 10:23:54 -08006991 (uint32_t)mbx->mbxCommand,
6992 mbx->un.varWords[0], mbx->un.varWords[1]);
James Smart858c9f62007-06-17 19:56:39 -05006993 }
6994
James Smart2e0fef82007-06-17 19:56:36 -05006995 return MBX_BUSY;
dea31012005-04-17 16:05:31 -05006996 }
6997
dea31012005-04-17 16:05:31 -05006998 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
6999
7000 /* If we are not polling, we MUST be in SLI2 mode */
7001 if (flag != MBX_POLL) {
James Smart3772a992009-05-22 14:50:54 -04007002 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007003 (mbx->mbxCommand != MBX_KILL_BOARD)) {
dea31012005-04-17 16:05:31 -05007004 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05007005 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05007006 /* Mbox command <mbxCommand> cannot issue */
James Smart3772a992009-05-22 14:50:54 -04007007 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7008 "(%d):2531 Mailbox command x%x "
7009 "cannot issue Data: x%x x%x\n",
7010 pmbox->vport ? pmbox->vport->vpi : 0,
7011 pmbox->u.mb.mbxCommand,
7012 psli->sli_flag, flag);
James Smart58da1ff2008-04-07 10:15:56 -04007013 goto out_not_finished;
dea31012005-04-17 16:05:31 -05007014 }
7015 /* timeout active mbox command */
James Smart256ec0d2013-04-17 20:14:58 -04007016 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
7017 1000);
7018 mod_timer(&psli->mbox_tmo, jiffies + timeout);
dea31012005-04-17 16:05:31 -05007019 }
7020
7021 /* Mailbox cmd <cmd> issue */
James Smarted957682007-06-17 19:56:37 -05007022 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04007023 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05007024 "x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04007025 pmbox->vport ? pmbox->vport->vpi : 0,
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007026 mbx->mbxCommand, phba->pport->port_state,
James Smart92d7f7b2007-06-17 19:56:38 -05007027 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05007028
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007029 if (mbx->mbxCommand != MBX_HEARTBEAT) {
James Smart858c9f62007-06-17 19:56:39 -05007030 if (pmbox->vport) {
7031 lpfc_debugfs_disc_trc(pmbox->vport,
7032 LPFC_DISC_TRC_MBOX_VPORT,
7033 "MBOX Send vport: cmd:x%x mb:x%x x%x",
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007034 (uint32_t)mbx->mbxCommand,
7035 mbx->un.varWords[0], mbx->un.varWords[1]);
James Smart858c9f62007-06-17 19:56:39 -05007036 }
7037 else {
7038 lpfc_debugfs_disc_trc(phba->pport,
7039 LPFC_DISC_TRC_MBOX,
7040 "MBOX Send: cmd:x%x mb:x%x x%x",
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007041 (uint32_t)mbx->mbxCommand,
7042 mbx->un.varWords[0], mbx->un.varWords[1]);
James Smart858c9f62007-06-17 19:56:39 -05007043 }
7044 }
7045
dea31012005-04-17 16:05:31 -05007046 psli->slistat.mbox_cmd++;
7047 evtctr = psli->slistat.mbox_event;
7048
7049 /* next set own bit for the adapter and copy over command word */
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007050 mbx->mbxOwner = OWN_CHIP;
dea31012005-04-17 16:05:31 -05007051
James Smart3772a992009-05-22 14:50:54 -04007052 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
James Smart7a470272010-03-15 11:25:20 -04007053 /* Populate mbox extension offset word. */
7054 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007055 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
James Smart7a470272010-03-15 11:25:20 -04007056 = (uint8_t *)phba->mbox_ext
7057 - (uint8_t *)phba->mbox;
7058 }
7059
7060 /* Copy the mailbox extension data */
7061 if (pmbox->in_ext_byte_len && pmbox->context2) {
7062 lpfc_sli_pcimem_bcopy(pmbox->context2,
7063 (uint8_t *)phba->mbox_ext,
7064 pmbox->in_ext_byte_len);
7065 }
7066 /* Copy command data to host SLIM area */
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007067 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05007068 } else {
James Smart7a470272010-03-15 11:25:20 -04007069 /* Populate mbox extension offset word. */
7070 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007071 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
James Smart7a470272010-03-15 11:25:20 -04007072 = MAILBOX_HBA_EXT_OFFSET;
7073
7074 /* Copy the mailbox extension data */
7075 if (pmbox->in_ext_byte_len && pmbox->context2) {
7076 lpfc_memcpy_to_slim(phba->MBslimaddr +
7077 MAILBOX_HBA_EXT_OFFSET,
7078 pmbox->context2, pmbox->in_ext_byte_len);
7079
7080 }
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007081 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05007082 /* copy command data into host mbox for cmpl */
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007083 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05007084 }
7085
7086 /* First copy mbox command data to HBA SLIM, skip past first
7087 word */
7088 to_slim = phba->MBslimaddr + sizeof (uint32_t);
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007089 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
dea31012005-04-17 16:05:31 -05007090 MAILBOX_CMD_SIZE - sizeof (uint32_t));
7091
7092 /* Next copy over first word, with mbxOwner set */
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007093 ldata = *((uint32_t *)mbx);
dea31012005-04-17 16:05:31 -05007094 to_slim = phba->MBslimaddr;
7095 writel(ldata, to_slim);
7096 readl(to_slim); /* flush */
7097
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007098 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05007099 /* switch over to host mailbox */
James Smart3772a992009-05-22 14:50:54 -04007100 psli->sli_flag |= LPFC_SLI_ACTIVE;
dea31012005-04-17 16:05:31 -05007101 }
7102 }
7103
7104 wmb();
dea31012005-04-17 16:05:31 -05007105
7106 switch (flag) {
7107 case MBX_NOWAIT:
James Smart09372822008-01-11 01:52:54 -05007108 /* Set up reference to mailbox command */
dea31012005-04-17 16:05:31 -05007109 psli->mbox_active = pmbox;
James Smart09372822008-01-11 01:52:54 -05007110 /* Interrupt board to do it */
7111 writel(CA_MBATT, phba->CAregaddr);
7112 readl(phba->CAregaddr); /* flush */
7113 /* Don't wait for it to finish, just return */
dea31012005-04-17 16:05:31 -05007114 break;
7115
7116 case MBX_POLL:
James Smart09372822008-01-11 01:52:54 -05007117 /* Set up null reference to mailbox command */
dea31012005-04-17 16:05:31 -05007118 psli->mbox_active = NULL;
James Smart09372822008-01-11 01:52:54 -05007119 /* Interrupt board to do it */
7120 writel(CA_MBATT, phba->CAregaddr);
7121 readl(phba->CAregaddr); /* flush */
7122
James Smart3772a992009-05-22 14:50:54 -04007123 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
dea31012005-04-17 16:05:31 -05007124 /* First read mbox status word */
James Smart34b02dc2008-08-24 21:49:55 -04007125 word0 = *((uint32_t *)phba->mbox);
dea31012005-04-17 16:05:31 -05007126 word0 = le32_to_cpu(word0);
7127 } else {
7128 /* First read mbox status word */
James Smart9940b972011-03-11 16:06:12 -05007129 if (lpfc_readl(phba->MBslimaddr, &word0)) {
7130 spin_unlock_irqrestore(&phba->hbalock,
7131 drvr_flag);
7132 goto out_not_finished;
7133 }
dea31012005-04-17 16:05:31 -05007134 }
7135
7136 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -05007137 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
7138 spin_unlock_irqrestore(&phba->hbalock,
7139 drvr_flag);
7140 goto out_not_finished;
7141 }
James Smarta183a152011-10-10 21:32:43 -04007142 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
7143 1000) + jiffies;
James Smart09372822008-01-11 01:52:54 -05007144 i = 0;
dea31012005-04-17 16:05:31 -05007145 /* Wait for command to complete */
Jamie Wellnitz41415862006-02-28 19:25:27 -05007146 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
7147 (!(ha_copy & HA_MBATT) &&
James Smart2e0fef82007-06-17 19:56:36 -05007148 (phba->link_state > LPFC_WARM_START))) {
James Smart09372822008-01-11 01:52:54 -05007149 if (time_after(jiffies, timeout)) {
dea31012005-04-17 16:05:31 -05007150 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05007151 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05007152 drvr_flag);
James Smart58da1ff2008-04-07 10:15:56 -04007153 goto out_not_finished;
dea31012005-04-17 16:05:31 -05007154 }
7155
7156 /* Check if we took a mbox interrupt while we were
7157 polling */
7158 if (((word0 & OWN_CHIP) != OWN_CHIP)
7159 && (evtctr != psli->slistat.mbox_event))
7160 break;
7161
James Smart09372822008-01-11 01:52:54 -05007162 if (i++ > 10) {
7163 spin_unlock_irqrestore(&phba->hbalock,
7164 drvr_flag);
7165 msleep(1);
7166 spin_lock_irqsave(&phba->hbalock, drvr_flag);
7167 }
dea31012005-04-17 16:05:31 -05007168
James Smart3772a992009-05-22 14:50:54 -04007169 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
dea31012005-04-17 16:05:31 -05007170 /* First copy command data */
James Smart34b02dc2008-08-24 21:49:55 -04007171 word0 = *((uint32_t *)phba->mbox);
dea31012005-04-17 16:05:31 -05007172 word0 = le32_to_cpu(word0);
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007173 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05007174 MAILBOX_t *slimmb;
James Smart34b02dc2008-08-24 21:49:55 -04007175 uint32_t slimword0;
dea31012005-04-17 16:05:31 -05007176 /* Check real SLIM for any errors */
7177 slimword0 = readl(phba->MBslimaddr);
7178 slimmb = (MAILBOX_t *) & slimword0;
7179 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
7180 && slimmb->mbxStatus) {
7181 psli->sli_flag &=
James Smart3772a992009-05-22 14:50:54 -04007182 ~LPFC_SLI_ACTIVE;
dea31012005-04-17 16:05:31 -05007183 word0 = slimword0;
7184 }
7185 }
7186 } else {
7187 /* First copy command data */
7188 word0 = readl(phba->MBslimaddr);
7189 }
7190 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -05007191 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
7192 spin_unlock_irqrestore(&phba->hbalock,
7193 drvr_flag);
7194 goto out_not_finished;
7195 }
dea31012005-04-17 16:05:31 -05007196 }
7197
James Smart3772a992009-05-22 14:50:54 -04007198 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
dea31012005-04-17 16:05:31 -05007199 /* copy results back to user */
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007200 lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
James Smart7a470272010-03-15 11:25:20 -04007201 /* Copy the mailbox extension data */
7202 if (pmbox->out_ext_byte_len && pmbox->context2) {
7203 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
7204 pmbox->context2,
7205 pmbox->out_ext_byte_len);
7206 }
dea31012005-04-17 16:05:31 -05007207 } else {
7208 /* First copy command data */
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007209 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
dea31012005-04-17 16:05:31 -05007210 MAILBOX_CMD_SIZE);
James Smart7a470272010-03-15 11:25:20 -04007211 /* Copy the mailbox extension data */
7212 if (pmbox->out_ext_byte_len && pmbox->context2) {
7213 lpfc_memcpy_from_slim(pmbox->context2,
7214 phba->MBslimaddr +
7215 MAILBOX_HBA_EXT_OFFSET,
7216 pmbox->out_ext_byte_len);
dea31012005-04-17 16:05:31 -05007217 }
7218 }
7219
7220 writel(HA_MBATT, phba->HAregaddr);
7221 readl(phba->HAregaddr); /* flush */
7222
7223 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
Randy Dunlapbf07bde2013-02-22 10:23:54 -08007224 status = mbx->mbxStatus;
dea31012005-04-17 16:05:31 -05007225 }
7226
James Smart2e0fef82007-06-17 19:56:36 -05007227 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7228 return status;
James Smart58da1ff2008-04-07 10:15:56 -04007229
7230out_not_finished:
7231 if (processing_queue) {
James Smartda0436e2009-05-22 14:51:39 -04007232 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
James Smart58da1ff2008-04-07 10:15:56 -04007233 lpfc_mbox_cmpl_put(phba, pmbox);
7234 }
7235 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05007236}
7237
James Smarte59058c2008-08-24 21:49:00 -04007238/**
James Smartf1126682009-06-10 17:22:44 -04007239 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7240 * @phba: Pointer to HBA context object.
7241 *
7242 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7243 * the driver internal pending mailbox queue. It will then try to wait out the
7244 * possible outstanding mailbox command before return.
7245 *
7246 * Returns:
7247 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7248 * the outstanding mailbox command timed out.
7249 **/
7250static int
7251lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
7252{
7253 struct lpfc_sli *psli = &phba->sli;
James Smartf1126682009-06-10 17:22:44 -04007254 int rc = 0;
James Smarta183a152011-10-10 21:32:43 -04007255 unsigned long timeout = 0;
James Smartf1126682009-06-10 17:22:44 -04007256
7257 /* Mark the asynchronous mailbox command posting as blocked */
7258 spin_lock_irq(&phba->hbalock);
7259 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
James Smartf1126682009-06-10 17:22:44 -04007260 /* Determine how long we might wait for the active mailbox
7261 * command to be gracefully completed by firmware.
7262 */
James Smarta183a152011-10-10 21:32:43 -04007263 if (phba->sli.mbox_active)
7264 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
7265 phba->sli.mbox_active) *
7266 1000) + jiffies;
7267 spin_unlock_irq(&phba->hbalock);
7268
James Smarte8d3c3b2013-10-10 12:21:30 -04007269 /* Make sure the mailbox is really active */
7270 if (timeout)
7271 lpfc_sli4_process_missed_mbox_completions(phba);
7272
James Smartf1126682009-06-10 17:22:44 -04007273 /* Wait for the outstnading mailbox command to complete */
7274 while (phba->sli.mbox_active) {
7275 /* Check active mailbox complete status every 2ms */
7276 msleep(2);
7277 if (time_after(jiffies, timeout)) {
7278 /* Timeout, marked the outstanding cmd not complete */
7279 rc = 1;
7280 break;
7281 }
7282 }
7283
7284 /* Can not cleanly block async mailbox command, fails it */
7285 if (rc) {
7286 spin_lock_irq(&phba->hbalock);
7287 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7288 spin_unlock_irq(&phba->hbalock);
7289 }
7290 return rc;
7291}
7292
7293/**
7294 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7295 * @phba: Pointer to HBA context object.
7296 *
7297 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7298 * commands from the driver internal pending mailbox queue. It makes sure
7299 * that there is no outstanding mailbox command before resuming posting
7300 * asynchronous mailbox commands. If, for any reason, there is outstanding
7301 * mailbox command, it will try to wait it out before resuming asynchronous
7302 * mailbox command posting.
7303 **/
7304static void
7305lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
7306{
7307 struct lpfc_sli *psli = &phba->sli;
7308
7309 spin_lock_irq(&phba->hbalock);
7310 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
7311 /* Asynchronous mailbox posting is not blocked, do nothing */
7312 spin_unlock_irq(&phba->hbalock);
7313 return;
7314 }
7315
7316 /* Outstanding synchronous mailbox command is guaranteed to be done,
7317 * successful or timeout, after timing-out the outstanding mailbox
7318 * command shall always be removed, so just unblock posting async
7319 * mailbox command and resume
7320 */
7321 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7322 spin_unlock_irq(&phba->hbalock);
7323
7324 /* wake up worker thread to post asynchronlous mailbox command */
7325 lpfc_worker_wake_up(phba);
7326}
7327
7328/**
James Smart2d843ed2012-09-29 11:29:06 -04007329 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7330 * @phba: Pointer to HBA context object.
7331 * @mboxq: Pointer to mailbox object.
7332 *
7333 * The function waits for the bootstrap mailbox register ready bit from
7334 * port for twice the regular mailbox command timeout value.
7335 *
7336 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7337 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7338 **/
7339static int
7340lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7341{
7342 uint32_t db_ready;
7343 unsigned long timeout;
7344 struct lpfc_register bmbx_reg;
7345
7346 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
7347 * 1000) + jiffies;
7348
7349 do {
7350 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
7351 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
7352 if (!db_ready)
7353 msleep(2);
7354
7355 if (time_after(jiffies, timeout))
7356 return MBXERR_ERROR;
7357 } while (!db_ready);
7358
7359 return 0;
7360}
7361
7362/**
James Smartda0436e2009-05-22 14:51:39 -04007363 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7364 * @phba: Pointer to HBA context object.
7365 * @mboxq: Pointer to mailbox object.
7366 *
7367 * The function posts a mailbox to the port. The mailbox is expected
7368 * to be comletely filled in and ready for the port to operate on it.
7369 * This routine executes a synchronous completion operation on the
7370 * mailbox by polling for its completion.
7371 *
7372 * The caller must not be holding any locks when calling this routine.
7373 *
7374 * Returns:
7375 * MBX_SUCCESS - mailbox posted successfully
7376 * Any of the MBX error values.
7377 **/
7378static int
7379lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7380{
7381 int rc = MBX_SUCCESS;
7382 unsigned long iflag;
James Smartda0436e2009-05-22 14:51:39 -04007383 uint32_t mcqe_status;
7384 uint32_t mbx_cmnd;
James Smartda0436e2009-05-22 14:51:39 -04007385 struct lpfc_sli *psli = &phba->sli;
7386 struct lpfc_mqe *mb = &mboxq->u.mqe;
7387 struct lpfc_bmbx_create *mbox_rgn;
7388 struct dma_address *dma_address;
James Smartda0436e2009-05-22 14:51:39 -04007389
7390 /*
7391 * Only one mailbox can be active to the bootstrap mailbox region
7392 * at a time and there is no queueing provided.
7393 */
7394 spin_lock_irqsave(&phba->hbalock, iflag);
7395 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
7396 spin_unlock_irqrestore(&phba->hbalock, iflag);
7397 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04007398 "(%d):2532 Mailbox command x%x (x%x/x%x) "
James Smartda0436e2009-05-22 14:51:39 -04007399 "cannot issue Data: x%x x%x\n",
7400 mboxq->vport ? mboxq->vport->vpi : 0,
7401 mboxq->u.mb.mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04007402 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7403 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007404 psli->sli_flag, MBX_POLL);
7405 return MBXERR_ERROR;
7406 }
7407 /* The server grabs the token and owns it until release */
7408 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
7409 phba->sli.mbox_active = mboxq;
7410 spin_unlock_irqrestore(&phba->hbalock, iflag);
7411
James Smart2d843ed2012-09-29 11:29:06 -04007412 /* wait for bootstrap mbox register for readyness */
7413 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
7414 if (rc)
7415 goto exit;
7416
James Smartda0436e2009-05-22 14:51:39 -04007417 /*
7418 * Initialize the bootstrap memory region to avoid stale data areas
7419 * in the mailbox post. Then copy the caller's mailbox contents to
7420 * the bmbx mailbox region.
7421 */
7422 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
7423 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
7424 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
7425 sizeof(struct lpfc_mqe));
7426
7427 /* Post the high mailbox dma address to the port and wait for ready. */
7428 dma_address = &phba->sli4_hba.bmbx.dma_address;
7429 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
7430
James Smart2d843ed2012-09-29 11:29:06 -04007431 /* wait for bootstrap mbox register for hi-address write done */
7432 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
7433 if (rc)
7434 goto exit;
James Smartda0436e2009-05-22 14:51:39 -04007435
7436 /* Post the low mailbox dma address to the port. */
7437 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
James Smartda0436e2009-05-22 14:51:39 -04007438
James Smart2d843ed2012-09-29 11:29:06 -04007439 /* wait for bootstrap mbox register for low address write done */
7440 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
7441 if (rc)
7442 goto exit;
James Smartda0436e2009-05-22 14:51:39 -04007443
7444 /*
7445 * Read the CQ to ensure the mailbox has completed.
7446 * If so, update the mailbox status so that the upper layers
7447 * can complete the request normally.
7448 */
7449 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
7450 sizeof(struct lpfc_mqe));
7451 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
7452 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
7453 sizeof(struct lpfc_mcqe));
7454 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
James Smart05580562011-05-24 11:40:48 -04007455 /*
7456 * When the CQE status indicates a failure and the mailbox status
7457 * indicates success then copy the CQE status into the mailbox status
7458 * (and prefix it with x4000).
7459 */
James Smartda0436e2009-05-22 14:51:39 -04007460 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
James Smart05580562011-05-24 11:40:48 -04007461 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
7462 bf_set(lpfc_mqe_status, mb,
7463 (LPFC_MBX_ERROR_RANGE | mcqe_status));
James Smartda0436e2009-05-22 14:51:39 -04007464 rc = MBXERR_ERROR;
James Smartd7c47992010-06-08 18:31:54 -04007465 } else
7466 lpfc_sli4_swap_str(phba, mboxq);
James Smartda0436e2009-05-22 14:51:39 -04007467
7468 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04007469 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
James Smartda0436e2009-05-22 14:51:39 -04007470 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7471 " x%x x%x CQ: x%x x%x x%x x%x\n",
James Smarta183a152011-10-10 21:32:43 -04007472 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
7473 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7474 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007475 bf_get(lpfc_mqe_status, mb),
7476 mb->un.mb_words[0], mb->un.mb_words[1],
7477 mb->un.mb_words[2], mb->un.mb_words[3],
7478 mb->un.mb_words[4], mb->un.mb_words[5],
7479 mb->un.mb_words[6], mb->un.mb_words[7],
7480 mb->un.mb_words[8], mb->un.mb_words[9],
7481 mb->un.mb_words[10], mb->un.mb_words[11],
7482 mb->un.mb_words[12], mboxq->mcqe.word0,
7483 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
7484 mboxq->mcqe.trailer);
7485exit:
7486 /* We are holding the token, no needed for lock when release */
7487 spin_lock_irqsave(&phba->hbalock, iflag);
7488 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7489 phba->sli.mbox_active = NULL;
7490 spin_unlock_irqrestore(&phba->hbalock, iflag);
7491 return rc;
7492}
7493
7494/**
7495 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7496 * @phba: Pointer to HBA context object.
7497 * @pmbox: Pointer to mailbox object.
7498 * @flag: Flag indicating how the mailbox need to be processed.
7499 *
7500 * This function is called by discovery code and HBA management code to submit
7501 * a mailbox command to firmware with SLI-4 interface spec.
7502 *
7503 * Return codes the caller owns the mailbox command after the return of the
7504 * function.
7505 **/
7506static int
7507lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
7508 uint32_t flag)
7509{
7510 struct lpfc_sli *psli = &phba->sli;
7511 unsigned long iflags;
7512 int rc;
7513
James Smartb76f2dc2011-07-22 18:37:42 -04007514 /* dump from issue mailbox command if setup */
7515 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
7516
James Smart8fa38512009-07-19 10:01:03 -04007517 rc = lpfc_mbox_dev_check(phba);
7518 if (unlikely(rc)) {
7519 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04007520 "(%d):2544 Mailbox command x%x (x%x/x%x) "
James Smart8fa38512009-07-19 10:01:03 -04007521 "cannot issue Data: x%x x%x\n",
7522 mboxq->vport ? mboxq->vport->vpi : 0,
7523 mboxq->u.mb.mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04007524 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7525 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smart8fa38512009-07-19 10:01:03 -04007526 psli->sli_flag, flag);
7527 goto out_not_finished;
7528 }
7529
James Smartda0436e2009-05-22 14:51:39 -04007530 /* Detect polling mode and jump to a handler */
7531 if (!phba->sli4_hba.intr_enable) {
7532 if (flag == MBX_POLL)
7533 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
7534 else
7535 rc = -EIO;
7536 if (rc != MBX_SUCCESS)
James Smart05580562011-05-24 11:40:48 -04007537 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
James Smartda0436e2009-05-22 14:51:39 -04007538 "(%d):2541 Mailbox command x%x "
James Smartcc459f12012-05-09 21:18:30 -04007539 "(x%x/x%x) failure: "
7540 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7541 "Data: x%x x%x\n,",
James Smartda0436e2009-05-22 14:51:39 -04007542 mboxq->vport ? mboxq->vport->vpi : 0,
7543 mboxq->u.mb.mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04007544 lpfc_sli_config_mbox_subsys_get(phba,
7545 mboxq),
7546 lpfc_sli_config_mbox_opcode_get(phba,
7547 mboxq),
James Smartcc459f12012-05-09 21:18:30 -04007548 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
7549 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
7550 bf_get(lpfc_mcqe_ext_status,
7551 &mboxq->mcqe),
James Smartda0436e2009-05-22 14:51:39 -04007552 psli->sli_flag, flag);
7553 return rc;
7554 } else if (flag == MBX_POLL) {
James Smartf1126682009-06-10 17:22:44 -04007555 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7556 "(%d):2542 Try to issue mailbox command "
James Smarta183a152011-10-10 21:32:43 -04007557 "x%x (x%x/x%x) synchronously ahead of async"
James Smartf1126682009-06-10 17:22:44 -04007558 "mailbox command queue: x%x x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04007559 mboxq->vport ? mboxq->vport->vpi : 0,
7560 mboxq->u.mb.mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04007561 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7562 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007563 psli->sli_flag, flag);
James Smartf1126682009-06-10 17:22:44 -04007564 /* Try to block the asynchronous mailbox posting */
7565 rc = lpfc_sli4_async_mbox_block(phba);
7566 if (!rc) {
7567 /* Successfully blocked, now issue sync mbox cmd */
7568 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
7569 if (rc != MBX_SUCCESS)
James Smartcc459f12012-05-09 21:18:30 -04007570 lpfc_printf_log(phba, KERN_WARNING,
James Smarta183a152011-10-10 21:32:43 -04007571 LOG_MBOX | LOG_SLI,
James Smartcc459f12012-05-09 21:18:30 -04007572 "(%d):2597 Sync Mailbox command "
7573 "x%x (x%x/x%x) failure: "
7574 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7575 "Data: x%x x%x\n,",
7576 mboxq->vport ? mboxq->vport->vpi : 0,
James Smarta183a152011-10-10 21:32:43 -04007577 mboxq->u.mb.mbxCommand,
7578 lpfc_sli_config_mbox_subsys_get(phba,
7579 mboxq),
7580 lpfc_sli_config_mbox_opcode_get(phba,
7581 mboxq),
James Smartcc459f12012-05-09 21:18:30 -04007582 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
7583 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
7584 bf_get(lpfc_mcqe_ext_status,
7585 &mboxq->mcqe),
James Smarta183a152011-10-10 21:32:43 -04007586 psli->sli_flag, flag);
James Smartf1126682009-06-10 17:22:44 -04007587 /* Unblock the async mailbox posting afterward */
7588 lpfc_sli4_async_mbox_unblock(phba);
7589 }
7590 return rc;
James Smartda0436e2009-05-22 14:51:39 -04007591 }
7592
7593 /* Now, interrupt mode asynchrous mailbox command */
7594 rc = lpfc_mbox_cmd_check(phba, mboxq);
7595 if (rc) {
7596 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04007597 "(%d):2543 Mailbox command x%x (x%x/x%x) "
James Smartda0436e2009-05-22 14:51:39 -04007598 "cannot issue Data: x%x x%x\n",
7599 mboxq->vport ? mboxq->vport->vpi : 0,
7600 mboxq->u.mb.mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04007601 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7602 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007603 psli->sli_flag, flag);
7604 goto out_not_finished;
7605 }
James Smartda0436e2009-05-22 14:51:39 -04007606
7607 /* Put the mailbox command to the driver internal FIFO */
7608 psli->slistat.mbox_busy++;
7609 spin_lock_irqsave(&phba->hbalock, iflags);
7610 lpfc_mbox_put(phba, mboxq);
7611 spin_unlock_irqrestore(&phba->hbalock, iflags);
7612 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7613 "(%d):0354 Mbox cmd issue - Enqueue Data: "
James Smarta183a152011-10-10 21:32:43 -04007614 "x%x (x%x/x%x) x%x x%x x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04007615 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
7616 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
James Smarta183a152011-10-10 21:32:43 -04007617 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7618 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007619 phba->pport->port_state,
7620 psli->sli_flag, MBX_NOWAIT);
7621 /* Wake up worker thread to transport mailbox command from head */
7622 lpfc_worker_wake_up(phba);
7623
7624 return MBX_BUSY;
7625
7626out_not_finished:
7627 return MBX_NOT_FINISHED;
7628}
7629
7630/**
7631 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7632 * @phba: Pointer to HBA context object.
7633 *
7634 * This function is called by worker thread to send a mailbox command to
7635 * SLI4 HBA firmware.
7636 *
7637 **/
7638int
7639lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
7640{
7641 struct lpfc_sli *psli = &phba->sli;
7642 LPFC_MBOXQ_t *mboxq;
7643 int rc = MBX_SUCCESS;
7644 unsigned long iflags;
7645 struct lpfc_mqe *mqe;
7646 uint32_t mbx_cmnd;
7647
7648 /* Check interrupt mode before post async mailbox command */
7649 if (unlikely(!phba->sli4_hba.intr_enable))
7650 return MBX_NOT_FINISHED;
7651
7652 /* Check for mailbox command service token */
7653 spin_lock_irqsave(&phba->hbalock, iflags);
7654 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
7655 spin_unlock_irqrestore(&phba->hbalock, iflags);
7656 return MBX_NOT_FINISHED;
7657 }
7658 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
7659 spin_unlock_irqrestore(&phba->hbalock, iflags);
7660 return MBX_NOT_FINISHED;
7661 }
7662 if (unlikely(phba->sli.mbox_active)) {
7663 spin_unlock_irqrestore(&phba->hbalock, iflags);
7664 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7665 "0384 There is pending active mailbox cmd\n");
7666 return MBX_NOT_FINISHED;
7667 }
7668 /* Take the mailbox command service token */
7669 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
7670
7671 /* Get the next mailbox command from head of queue */
7672 mboxq = lpfc_mbox_get(phba);
7673
7674 /* If no more mailbox command waiting for post, we're done */
7675 if (!mboxq) {
7676 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7677 spin_unlock_irqrestore(&phba->hbalock, iflags);
7678 return MBX_SUCCESS;
7679 }
7680 phba->sli.mbox_active = mboxq;
7681 spin_unlock_irqrestore(&phba->hbalock, iflags);
7682
7683 /* Check device readiness for posting mailbox command */
7684 rc = lpfc_mbox_dev_check(phba);
7685 if (unlikely(rc))
7686 /* Driver clean routine will clean up pending mailbox */
7687 goto out_not_finished;
7688
7689 /* Prepare the mbox command to be posted */
7690 mqe = &mboxq->u.mqe;
7691 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
7692
7693 /* Start timer for the mbox_tmo and log some mailbox post messages */
7694 mod_timer(&psli->mbox_tmo, (jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04007695 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
James Smartda0436e2009-05-22 14:51:39 -04007696
7697 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04007698 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
James Smartda0436e2009-05-22 14:51:39 -04007699 "x%x x%x\n",
7700 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
James Smarta183a152011-10-10 21:32:43 -04007701 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7702 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007703 phba->pport->port_state, psli->sli_flag);
7704
7705 if (mbx_cmnd != MBX_HEARTBEAT) {
7706 if (mboxq->vport) {
7707 lpfc_debugfs_disc_trc(mboxq->vport,
7708 LPFC_DISC_TRC_MBOX_VPORT,
7709 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7710 mbx_cmnd, mqe->un.mb_words[0],
7711 mqe->un.mb_words[1]);
7712 } else {
7713 lpfc_debugfs_disc_trc(phba->pport,
7714 LPFC_DISC_TRC_MBOX,
7715 "MBOX Send: cmd:x%x mb:x%x x%x",
7716 mbx_cmnd, mqe->un.mb_words[0],
7717 mqe->un.mb_words[1]);
7718 }
7719 }
7720 psli->slistat.mbox_cmd++;
7721
7722 /* Post the mailbox command to the port */
7723 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
7724 if (rc != MBX_SUCCESS) {
7725 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarta183a152011-10-10 21:32:43 -04007726 "(%d):2533 Mailbox command x%x (x%x/x%x) "
James Smartda0436e2009-05-22 14:51:39 -04007727 "cannot issue Data: x%x x%x\n",
7728 mboxq->vport ? mboxq->vport->vpi : 0,
7729 mboxq->u.mb.mbxCommand,
James Smarta183a152011-10-10 21:32:43 -04007730 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7731 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
James Smartda0436e2009-05-22 14:51:39 -04007732 psli->sli_flag, MBX_NOWAIT);
7733 goto out_not_finished;
7734 }
7735
7736 return rc;
7737
7738out_not_finished:
7739 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartd7069f02012-03-01 22:36:29 -05007740 if (phba->sli.mbox_active) {
7741 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
7742 __lpfc_mbox_cmpl_put(phba, mboxq);
7743 /* Release the token */
7744 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7745 phba->sli.mbox_active = NULL;
7746 }
James Smartda0436e2009-05-22 14:51:39 -04007747 spin_unlock_irqrestore(&phba->hbalock, iflags);
7748
7749 return MBX_NOT_FINISHED;
7750}
7751
7752/**
7753 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7754 * @phba: Pointer to HBA context object.
7755 * @pmbox: Pointer to mailbox object.
7756 * @flag: Flag indicating how the mailbox need to be processed.
7757 *
7758 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7759 * the API jump table function pointer from the lpfc_hba struct.
7760 *
7761 * Return codes the caller owns the mailbox command after the return of the
7762 * function.
7763 **/
7764int
7765lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
7766{
7767 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
7768}
7769
7770/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007771 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
James Smartda0436e2009-05-22 14:51:39 -04007772 * @phba: The hba struct for which this call is being executed.
7773 * @dev_grp: The HBA PCI-Device group number.
7774 *
7775 * This routine sets up the mbox interface API function jump table in @phba
7776 * struct.
7777 * Returns: 0 - success, -ENODEV - failure.
7778 **/
7779int
7780lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7781{
7782
7783 switch (dev_grp) {
7784 case LPFC_PCI_DEV_LP:
7785 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
7786 phba->lpfc_sli_handle_slow_ring_event =
7787 lpfc_sli_handle_slow_ring_event_s3;
7788 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
7789 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
7790 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
7791 break;
7792 case LPFC_PCI_DEV_OC:
7793 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
7794 phba->lpfc_sli_handle_slow_ring_event =
7795 lpfc_sli_handle_slow_ring_event_s4;
7796 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
7797 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
7798 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
7799 break;
7800 default:
7801 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7802 "1420 Invalid HBA PCI-device group: 0x%x\n",
7803 dev_grp);
7804 return -ENODEV;
7805 break;
7806 }
7807 return 0;
7808}
7809
7810/**
James Smart3621a712009-04-06 18:47:14 -04007811 * __lpfc_sli_ringtx_put - Add an iocb to the txq
James Smarte59058c2008-08-24 21:49:00 -04007812 * @phba: Pointer to HBA context object.
7813 * @pring: Pointer to driver SLI ring object.
7814 * @piocb: Pointer to address of newly added command iocb.
7815 *
7816 * This function is called with hbalock held to add a command
7817 * iocb to the txq when SLI layer cannot submit the command iocb
7818 * to the ring.
7819 **/
James Smart2a9bf3d2010-06-07 15:24:45 -04007820void
James Smart92d7f7b2007-06-17 19:56:38 -05007821__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05007822 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -05007823{
7824 /* Insert the caller's iocb in the txq tail for later processing. */
7825 list_add_tail(&piocb->list, &pring->txq);
dea31012005-04-17 16:05:31 -05007826}
7827
James Smarte59058c2008-08-24 21:49:00 -04007828/**
James Smart3621a712009-04-06 18:47:14 -04007829 * lpfc_sli_next_iocb - Get the next iocb in the txq
James Smarte59058c2008-08-24 21:49:00 -04007830 * @phba: Pointer to HBA context object.
7831 * @pring: Pointer to driver SLI ring object.
7832 * @piocb: Pointer to address of newly added command iocb.
7833 *
7834 * This function is called with hbalock held before a new
7835 * iocb is submitted to the firmware. This function checks
7836 * txq to flush the iocbs in txq to Firmware before
7837 * submitting new iocbs to the Firmware.
7838 * If there are iocbs in the txq which need to be submitted
7839 * to firmware, lpfc_sli_next_iocb returns the first element
7840 * of the txq after dequeuing it from txq.
7841 * If there is no iocb in the txq then the function will return
7842 * *piocb and *piocb is set to NULL. Caller needs to check
7843 * *piocb to find if there are more commands in the txq.
7844 **/
dea31012005-04-17 16:05:31 -05007845static struct lpfc_iocbq *
7846lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05007847 struct lpfc_iocbq **piocb)
dea31012005-04-17 16:05:31 -05007848{
7849 struct lpfc_iocbq * nextiocb;
7850
7851 nextiocb = lpfc_sli_ringtx_get(phba, pring);
7852 if (!nextiocb) {
7853 nextiocb = *piocb;
7854 *piocb = NULL;
7855 }
7856
7857 return nextiocb;
7858}
7859
James Smarte59058c2008-08-24 21:49:00 -04007860/**
James Smart3772a992009-05-22 14:50:54 -04007861 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
James Smarte59058c2008-08-24 21:49:00 -04007862 * @phba: Pointer to HBA context object.
James Smart3772a992009-05-22 14:50:54 -04007863 * @ring_number: SLI ring number to issue iocb on.
James Smarte59058c2008-08-24 21:49:00 -04007864 * @piocb: Pointer to command iocb.
7865 * @flag: Flag indicating if this command can be put into txq.
7866 *
James Smart3772a992009-05-22 14:50:54 -04007867 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7868 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7869 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7870 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7871 * this function allows only iocbs for posting buffers. This function finds
7872 * next available slot in the command ring and posts the command to the
7873 * available slot and writes the port attention register to request HBA start
7874 * processing new iocb. If there is no slot available in the ring and
7875 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7876 * the function returns IOCB_BUSY.
James Smarte59058c2008-08-24 21:49:00 -04007877 *
James Smart3772a992009-05-22 14:50:54 -04007878 * This function is called with hbalock held. The function will return success
7879 * after it successfully submit the iocb to firmware or after adding to the
7880 * txq.
James Smarte59058c2008-08-24 21:49:00 -04007881 **/
James Smart98c9ea52007-10-27 13:37:33 -04007882static int
James Smart3772a992009-05-22 14:50:54 -04007883__lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
dea31012005-04-17 16:05:31 -05007884 struct lpfc_iocbq *piocb, uint32_t flag)
7885{
7886 struct lpfc_iocbq *nextiocb;
7887 IOCB_t *iocb;
James Smart3772a992009-05-22 14:50:54 -04007888 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
dea31012005-04-17 16:05:31 -05007889
James Smart92d7f7b2007-06-17 19:56:38 -05007890 if (piocb->iocb_cmpl && (!piocb->vport) &&
7891 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
7892 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
7893 lpfc_printf_log(phba, KERN_ERR,
7894 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04007895 "1807 IOCB x%x failed. No vport\n",
James Smart92d7f7b2007-06-17 19:56:38 -05007896 piocb->iocb.ulpCommand);
7897 dump_stack();
7898 return IOCB_ERROR;
7899 }
7900
7901
Linas Vepstas8d63f372007-02-14 14:28:36 -06007902 /* If the PCI channel is in offline state, do not post iocbs. */
7903 if (unlikely(pci_channel_offline(phba->pcidev)))
7904 return IOCB_ERROR;
7905
James Smarta257bf92009-04-06 18:48:10 -04007906 /* If HBA has a deferred error attention, fail the iocb. */
7907 if (unlikely(phba->hba_flag & DEFER_ERATT))
7908 return IOCB_ERROR;
7909
dea31012005-04-17 16:05:31 -05007910 /*
7911 * We should never get an IOCB if we are in a < LINK_DOWN state
7912 */
James Smart2e0fef82007-06-17 19:56:36 -05007913 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05007914 return IOCB_ERROR;
7915
7916 /*
7917 * Check to see if we are blocking IOCB processing because of a
James Smart0b727fe2007-10-27 13:37:25 -04007918 * outstanding event.
dea31012005-04-17 16:05:31 -05007919 */
James Smart0b727fe2007-10-27 13:37:25 -04007920 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
dea31012005-04-17 16:05:31 -05007921 goto iocb_busy;
7922
James Smart2e0fef82007-06-17 19:56:36 -05007923 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
dea31012005-04-17 16:05:31 -05007924 /*
James Smart2680eea2007-04-25 09:52:55 -04007925 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
dea31012005-04-17 16:05:31 -05007926 * can be issued if the link is not up.
7927 */
7928 switch (piocb->iocb.ulpCommand) {
James Smart84774a42008-08-24 21:50:06 -04007929 case CMD_GEN_REQUEST64_CR:
7930 case CMD_GEN_REQUEST64_CX:
7931 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
7932 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
James Smart6a9c52c2009-10-02 15:16:51 -04007933 FC_RCTL_DD_UNSOL_CMD) ||
James Smart84774a42008-08-24 21:50:06 -04007934 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
7935 MENLO_TRANSPORT_TYPE))
7936
7937 goto iocb_busy;
7938 break;
dea31012005-04-17 16:05:31 -05007939 case CMD_QUE_RING_BUF_CN:
7940 case CMD_QUE_RING_BUF64_CN:
dea31012005-04-17 16:05:31 -05007941 /*
7942 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7943 * completion, iocb_cmpl MUST be 0.
7944 */
7945 if (piocb->iocb_cmpl)
7946 piocb->iocb_cmpl = NULL;
7947 /*FALLTHROUGH*/
7948 case CMD_CREATE_XRI_CR:
James Smart2680eea2007-04-25 09:52:55 -04007949 case CMD_CLOSE_XRI_CN:
7950 case CMD_CLOSE_XRI_CX:
dea31012005-04-17 16:05:31 -05007951 break;
7952 default:
7953 goto iocb_busy;
7954 }
7955
7956 /*
7957 * For FCP commands, we must be in a state where we can process link
7958 * attention events.
7959 */
7960 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
James Smart92d7f7b2007-06-17 19:56:38 -05007961 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
dea31012005-04-17 16:05:31 -05007962 goto iocb_busy;
James Smart92d7f7b2007-06-17 19:56:38 -05007963 }
dea31012005-04-17 16:05:31 -05007964
dea31012005-04-17 16:05:31 -05007965 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
7966 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
7967 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
7968
7969 if (iocb)
7970 lpfc_sli_update_ring(phba, pring);
7971 else
7972 lpfc_sli_update_full_ring(phba, pring);
7973
7974 if (!piocb)
7975 return IOCB_SUCCESS;
7976
7977 goto out_busy;
7978
7979 iocb_busy:
7980 pring->stats.iocb_cmd_delay++;
7981
7982 out_busy:
7983
7984 if (!(flag & SLI_IOCB_RET_IOCB)) {
James Smart92d7f7b2007-06-17 19:56:38 -05007985 __lpfc_sli_ringtx_put(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05007986 return IOCB_SUCCESS;
7987 }
7988
7989 return IOCB_BUSY;
7990}
7991
James Smart3772a992009-05-22 14:50:54 -04007992/**
James Smart4f774512009-05-22 14:52:35 -04007993 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7994 * @phba: Pointer to HBA context object.
7995 * @piocb: Pointer to command iocb.
7996 * @sglq: Pointer to the scatter gather queue object.
7997 *
7998 * This routine converts the bpl or bde that is in the IOCB
7999 * to a sgl list for the sli4 hardware. The physical address
8000 * of the bpl/bde is converted back to a virtual address.
8001 * If the IOCB contains a BPL then the list of BDE's is
8002 * converted to sli4_sge's. If the IOCB contains a single
8003 * BDE then it is converted to a single sli_sge.
8004 * The IOCB is still in cpu endianess so the contents of
8005 * the bpl can be used without byte swapping.
8006 *
8007 * Returns valid XRI = Success, NO_XRI = Failure.
8008**/
8009static uint16_t
8010lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
8011 struct lpfc_sglq *sglq)
8012{
8013 uint16_t xritag = NO_XRI;
8014 struct ulp_bde64 *bpl = NULL;
8015 struct ulp_bde64 bde;
8016 struct sli4_sge *sgl = NULL;
James Smart1b511972011-12-13 13:23:09 -05008017 struct lpfc_dmabuf *dmabuf;
James Smart4f774512009-05-22 14:52:35 -04008018 IOCB_t *icmd;
8019 int numBdes = 0;
8020 int i = 0;
James Smart63e801c2010-11-20 23:14:19 -05008021 uint32_t offset = 0; /* accumulated offset in the sg request list */
8022 int inbound = 0; /* number of sg reply entries inbound from firmware */
James Smart4f774512009-05-22 14:52:35 -04008023
8024 if (!piocbq || !sglq)
8025 return xritag;
8026
8027 sgl = (struct sli4_sge *)sglq->sgl;
8028 icmd = &piocbq->iocb;
James Smart6b5151f2012-01-18 16:24:06 -05008029 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
8030 return sglq->sli4_xritag;
James Smart4f774512009-05-22 14:52:35 -04008031 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
8032 numBdes = icmd->un.genreq64.bdl.bdeSize /
8033 sizeof(struct ulp_bde64);
8034 /* The addrHigh and addrLow fields within the IOCB
8035 * have not been byteswapped yet so there is no
8036 * need to swap them back.
8037 */
James Smart1b511972011-12-13 13:23:09 -05008038 if (piocbq->context3)
8039 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
8040 else
8041 return xritag;
James Smart4f774512009-05-22 14:52:35 -04008042
James Smart1b511972011-12-13 13:23:09 -05008043 bpl = (struct ulp_bde64 *)dmabuf->virt;
James Smart4f774512009-05-22 14:52:35 -04008044 if (!bpl)
8045 return xritag;
8046
8047 for (i = 0; i < numBdes; i++) {
8048 /* Should already be byte swapped. */
James Smart28baac72010-02-12 14:42:03 -05008049 sgl->addr_hi = bpl->addrHigh;
8050 sgl->addr_lo = bpl->addrLow;
8051
James Smart05580562011-05-24 11:40:48 -04008052 sgl->word2 = le32_to_cpu(sgl->word2);
James Smart4f774512009-05-22 14:52:35 -04008053 if ((i+1) == numBdes)
8054 bf_set(lpfc_sli4_sge_last, sgl, 1);
8055 else
8056 bf_set(lpfc_sli4_sge_last, sgl, 0);
James Smart28baac72010-02-12 14:42:03 -05008057 /* swap the size field back to the cpu so we
8058 * can assign it to the sgl.
8059 */
8060 bde.tus.w = le32_to_cpu(bpl->tus.w);
8061 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
James Smart63e801c2010-11-20 23:14:19 -05008062 /* The offsets in the sgl need to be accumulated
8063 * separately for the request and reply lists.
8064 * The request is always first, the reply follows.
8065 */
8066 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
8067 /* add up the reply sg entries */
8068 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
8069 inbound++;
8070 /* first inbound? reset the offset */
8071 if (inbound == 1)
8072 offset = 0;
8073 bf_set(lpfc_sli4_sge_offset, sgl, offset);
James Smartf9bb2da2011-10-10 21:34:11 -04008074 bf_set(lpfc_sli4_sge_type, sgl,
8075 LPFC_SGE_TYPE_DATA);
James Smart63e801c2010-11-20 23:14:19 -05008076 offset += bde.tus.f.bdeSize;
8077 }
James Smart546fc852011-03-11 16:06:29 -05008078 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart4f774512009-05-22 14:52:35 -04008079 bpl++;
8080 sgl++;
8081 }
8082 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
8083 /* The addrHigh and addrLow fields of the BDE have not
8084 * been byteswapped yet so they need to be swapped
8085 * before putting them in the sgl.
8086 */
8087 sgl->addr_hi =
8088 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
8089 sgl->addr_lo =
8090 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
James Smart05580562011-05-24 11:40:48 -04008091 sgl->word2 = le32_to_cpu(sgl->word2);
James Smart4f774512009-05-22 14:52:35 -04008092 bf_set(lpfc_sli4_sge_last, sgl, 1);
8093 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -05008094 sgl->sge_len =
8095 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
James Smart4f774512009-05-22 14:52:35 -04008096 }
8097 return sglq->sli4_xritag;
8098}
8099
8100/**
8101 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
8102 * @phba: Pointer to HBA context object.
James Smart4f774512009-05-22 14:52:35 -04008103 *
James Smarta93ff372010-10-22 11:06:08 -04008104 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
James Smart8fa38512009-07-19 10:01:03 -04008105 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
8106 * held.
James Smart4f774512009-05-22 14:52:35 -04008107 *
8108 * Return: index into SLI4 fast-path FCP queue index.
8109 **/
James Smart2a76a282012-08-03 12:35:54 -04008110static inline uint32_t
James Smart8fa38512009-07-19 10:01:03 -04008111lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
James Smart4f774512009-05-22 14:52:35 -04008112{
James Smart7bb03bb2013-04-17 20:19:16 -04008113 struct lpfc_vector_map_info *cpup;
8114 int chann, cpu;
James Smart4f774512009-05-22 14:52:35 -04008115
James Smart76f96b62013-12-17 20:29:01 -05008116 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU
8117 && phba->cfg_fcp_io_channel > 1) {
James Smart7bb03bb2013-04-17 20:19:16 -04008118 cpu = smp_processor_id();
8119 if (cpu < phba->sli4_hba.num_present_cpu) {
8120 cpup = phba->sli4_hba.cpu_map;
8121 cpup += cpu;
8122 return cpup->channel_id;
8123 }
8124 chann = cpu;
8125 }
8126 chann = atomic_add_return(1, &phba->fcp_qidx);
8127 chann = (chann % phba->cfg_fcp_io_channel);
8128 return chann;
James Smart4f774512009-05-22 14:52:35 -04008129}
8130
8131/**
8132 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8133 * @phba: Pointer to HBA context object.
8134 * @piocb: Pointer to command iocb.
8135 * @wqe: Pointer to the work queue entry.
8136 *
8137 * This routine converts the iocb command to its Work Queue Entry
8138 * equivalent. The wqe pointer should not have any fields set when
8139 * this routine is called because it will memcpy over them.
8140 * This routine does not set the CQ_ID or the WQEC bits in the
8141 * wqe.
8142 *
8143 * Returns: 0 = Success, IOCB_ERROR = Failure.
8144 **/
8145static int
8146lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
8147 union lpfc_wqe *wqe)
8148{
James Smart5ffc2662009-11-18 15:39:44 -05008149 uint32_t xmit_len = 0, total_len = 0;
James Smart4f774512009-05-22 14:52:35 -04008150 uint8_t ct = 0;
8151 uint32_t fip;
8152 uint32_t abort_tag;
8153 uint8_t command_type = ELS_COMMAND_NON_FIP;
8154 uint8_t cmnd;
8155 uint16_t xritag;
James Smartdcf2a4e2010-09-29 11:18:53 -04008156 uint16_t abrt_iotag;
8157 struct lpfc_iocbq *abrtiocbq;
James Smart4f774512009-05-22 14:52:35 -04008158 struct ulp_bde64 *bpl = NULL;
James Smartf0d9bcc2010-10-22 11:07:09 -04008159 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
James Smart5ffc2662009-11-18 15:39:44 -05008160 int numBdes, i;
8161 struct ulp_bde64 bde;
James Smartc31098c2011-04-16 11:03:33 -04008162 struct lpfc_nodelist *ndlp;
James Smartff78d8f2011-12-13 13:21:35 -05008163 uint32_t *pcmd;
James Smart1b511972011-12-13 13:23:09 -05008164 uint32_t if_type;
James Smart4f774512009-05-22 14:52:35 -04008165
James Smart45ed1192009-10-02 15:17:02 -04008166 fip = phba->hba_flag & HBA_FIP_SUPPORT;
James Smart4f774512009-05-22 14:52:35 -04008167 /* The fcp commands will set command type */
James Smart0c287582009-06-10 17:22:56 -04008168 if (iocbq->iocb_flag & LPFC_IO_FCP)
James Smart4f774512009-05-22 14:52:35 -04008169 command_type = FCP_COMMAND;
James Smartc8685952009-11-18 15:39:16 -05008170 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
James Smart0c287582009-06-10 17:22:56 -04008171 command_type = ELS_COMMAND_FIP;
8172 else
8173 command_type = ELS_COMMAND_NON_FIP;
8174
James Smart4f774512009-05-22 14:52:35 -04008175 /* Some of the fields are in the right position already */
8176 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
8177 abort_tag = (uint32_t) iocbq->iotag;
8178 xritag = iocbq->sli4_xritag;
James Smartf0d9bcc2010-10-22 11:07:09 -04008179 wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
James Smart28d7f3d2014-05-21 08:05:28 -04008180 wqe->generic.wqe_com.word10 = 0;
James Smart4f774512009-05-22 14:52:35 -04008181 /* words0-2 bpl convert bde */
8182 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
James Smart5ffc2662009-11-18 15:39:44 -05008183 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
8184 sizeof(struct ulp_bde64);
James Smart4f774512009-05-22 14:52:35 -04008185 bpl = (struct ulp_bde64 *)
8186 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
8187 if (!bpl)
8188 return IOCB_ERROR;
8189
8190 /* Should already be byte swapped. */
8191 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
8192 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
8193 /* swap the size field back to the cpu so we
8194 * can assign it to the sgl.
8195 */
8196 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
James Smart5ffc2662009-11-18 15:39:44 -05008197 xmit_len = wqe->generic.bde.tus.f.bdeSize;
8198 total_len = 0;
8199 for (i = 0; i < numBdes; i++) {
8200 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
8201 total_len += bde.tus.f.bdeSize;
8202 }
James Smart4f774512009-05-22 14:52:35 -04008203 } else
James Smart5ffc2662009-11-18 15:39:44 -05008204 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
James Smart4f774512009-05-22 14:52:35 -04008205
8206 iocbq->iocb.ulpIoTag = iocbq->iotag;
8207 cmnd = iocbq->iocb.ulpCommand;
8208
8209 switch (iocbq->iocb.ulpCommand) {
8210 case CMD_ELS_REQUEST64_CR:
James Smart93d1379e2012-05-09 21:19:34 -04008211 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
8212 ndlp = iocbq->context_un.ndlp;
8213 else
8214 ndlp = (struct lpfc_nodelist *)iocbq->context1;
James Smart4f774512009-05-22 14:52:35 -04008215 if (!iocbq->iocb.ulpLe) {
8216 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8217 "2007 Only Limited Edition cmd Format"
8218 " supported 0x%x\n",
8219 iocbq->iocb.ulpCommand);
8220 return IOCB_ERROR;
8221 }
James Smartff78d8f2011-12-13 13:21:35 -05008222
James Smart5ffc2662009-11-18 15:39:44 -05008223 wqe->els_req.payload_len = xmit_len;
James Smart4f774512009-05-22 14:52:35 -04008224 /* Els_reguest64 has a TMO */
8225 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
8226 iocbq->iocb.ulpTimeout);
8227 /* Need a VF for word 4 set the vf bit*/
8228 bf_set(els_req64_vf, &wqe->els_req, 0);
8229 /* And a VFID for word 12 */
8230 bf_set(els_req64_vfid, &wqe->els_req, 0);
James Smart4f774512009-05-22 14:52:35 -04008231 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
James Smartf0d9bcc2010-10-22 11:07:09 -04008232 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
8233 iocbq->iocb.ulpContext);
8234 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
8235 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
James Smart4f774512009-05-22 14:52:35 -04008236 /* CCP CCPE PV PRI in word10 were set in the memcpy */
James Smartff78d8f2011-12-13 13:21:35 -05008237 if (command_type == ELS_COMMAND_FIP)
James Smartc8685952009-11-18 15:39:16 -05008238 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
8239 >> LPFC_FIP_ELS_ID_SHIFT);
James Smartff78d8f2011-12-13 13:21:35 -05008240 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8241 iocbq->context2)->virt);
James Smart1b511972011-12-13 13:23:09 -05008242 if_type = bf_get(lpfc_sli_intf_if_type,
8243 &phba->sli4_hba.sli_intf);
8244 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
James Smartff78d8f2011-12-13 13:21:35 -05008245 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
James Smartcb69f7d2011-12-13 13:21:57 -05008246 *pcmd == ELS_CMD_SCR ||
James Smart6b5151f2012-01-18 16:24:06 -05008247 *pcmd == ELS_CMD_FDISC ||
James Smartbdcd2b92012-03-01 22:33:52 -05008248 *pcmd == ELS_CMD_LOGO ||
James Smartff78d8f2011-12-13 13:21:35 -05008249 *pcmd == ELS_CMD_PLOGI)) {
8250 bf_set(els_req64_sp, &wqe->els_req, 1);
8251 bf_set(els_req64_sid, &wqe->els_req,
8252 iocbq->vport->fc_myDID);
James Smart939723a2012-05-09 21:19:03 -04008253 if ((*pcmd == ELS_CMD_FLOGI) &&
8254 !(phba->fc_topology ==
8255 LPFC_TOPOLOGY_LOOP))
8256 bf_set(els_req64_sid, &wqe->els_req, 0);
James Smartff78d8f2011-12-13 13:21:35 -05008257 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
8258 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
James Smarta7dd9c02012-05-09 21:16:50 -04008259 phba->vpi_ids[iocbq->vport->vpi]);
James Smart3ef6d242012-01-18 16:23:48 -05008260 } else if (pcmd && iocbq->context1) {
James Smartff78d8f2011-12-13 13:21:35 -05008261 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
8262 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
8263 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
8264 }
James Smartc8685952009-11-18 15:39:16 -05008265 }
James Smart6d368e52011-05-24 11:44:12 -04008266 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
8267 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
James Smartf0d9bcc2010-10-22 11:07:09 -04008268 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
8269 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
8270 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
8271 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
8272 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
8273 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
James Smartaf227412013-10-10 12:23:10 -04008274 wqe->els_req.max_response_payload_len = total_len - xmit_len;
James Smart7851fe22011-07-22 18:36:52 -04008275 break;
James Smart5ffc2662009-11-18 15:39:44 -05008276 case CMD_XMIT_SEQUENCE64_CX:
James Smartf0d9bcc2010-10-22 11:07:09 -04008277 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
8278 iocbq->iocb.un.ulpWord[3]);
8279 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
James Smart7851fe22011-07-22 18:36:52 -04008280 iocbq->iocb.unsli3.rcvsli3.ox_id);
James Smart5ffc2662009-11-18 15:39:44 -05008281 /* The entire sequence is transmitted for this IOCB */
8282 xmit_len = total_len;
8283 cmnd = CMD_XMIT_SEQUENCE64_CR;
James Smart1b511972011-12-13 13:23:09 -05008284 if (phba->link_flag & LS_LOOPBACK_MODE)
8285 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
James Smart4f774512009-05-22 14:52:35 -04008286 case CMD_XMIT_SEQUENCE64_CR:
James Smartf0d9bcc2010-10-22 11:07:09 -04008287 /* word3 iocb=io_tag32 wqe=reserved */
8288 wqe->xmit_sequence.rsvd3 = 0;
James Smart4f774512009-05-22 14:52:35 -04008289 /* word4 relative_offset memcpy */
8290 /* word5 r_ctl/df_ctl memcpy */
James Smartf0d9bcc2010-10-22 11:07:09 -04008291 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
8292 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
8293 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
8294 LPFC_WQE_IOD_WRITE);
8295 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
8296 LPFC_WQE_LENLOC_WORD12);
8297 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
James Smart5ffc2662009-11-18 15:39:44 -05008298 wqe->xmit_sequence.xmit_len = xmit_len;
8299 command_type = OTHER_COMMAND;
James Smart7851fe22011-07-22 18:36:52 -04008300 break;
James Smart4f774512009-05-22 14:52:35 -04008301 case CMD_XMIT_BCAST64_CN:
James Smartf0d9bcc2010-10-22 11:07:09 -04008302 /* word3 iocb=iotag32 wqe=seq_payload_len */
8303 wqe->xmit_bcast64.seq_payload_len = xmit_len;
James Smart4f774512009-05-22 14:52:35 -04008304 /* word4 iocb=rsvd wqe=rsvd */
8305 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8306 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
James Smartf0d9bcc2010-10-22 11:07:09 -04008307 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
James Smart4f774512009-05-22 14:52:35 -04008308 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
James Smartf0d9bcc2010-10-22 11:07:09 -04008309 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
8310 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
8311 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
8312 LPFC_WQE_LENLOC_WORD3);
8313 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
James Smart7851fe22011-07-22 18:36:52 -04008314 break;
James Smart4f774512009-05-22 14:52:35 -04008315 case CMD_FCP_IWRITE64_CR:
8316 command_type = FCP_COMMAND_DATA_OUT;
James Smartf0d9bcc2010-10-22 11:07:09 -04008317 /* word3 iocb=iotag wqe=payload_offset_len */
8318 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
James Smart0ba4b212013-10-10 12:22:38 -04008319 bf_set(payload_offset_len, &wqe->fcp_iwrite,
8320 xmit_len + sizeof(struct fcp_rsp));
8321 bf_set(cmd_buff_len, &wqe->fcp_iwrite,
8322 0);
James Smartf0d9bcc2010-10-22 11:07:09 -04008323 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8324 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8325 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
8326 iocbq->iocb.ulpFCP2Rcvy);
8327 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
8328 /* Always open the exchange */
8329 bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
James Smartf0d9bcc2010-10-22 11:07:09 -04008330 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
8331 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
8332 LPFC_WQE_LENLOC_WORD4);
8333 bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
8334 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
James Smartacd68592012-01-18 16:25:09 -05008335 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008336 if (iocbq->iocb_flag & LPFC_IO_OAS) {
8337 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
8338 if (phba->cfg_XLanePriority) {
8339 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
8340 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
8341 (phba->cfg_XLanePriority << 1));
8342 }
8343 }
James Smart7851fe22011-07-22 18:36:52 -04008344 break;
James Smartf0d9bcc2010-10-22 11:07:09 -04008345 case CMD_FCP_IREAD64_CR:
8346 /* word3 iocb=iotag wqe=payload_offset_len */
8347 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
James Smart0ba4b212013-10-10 12:22:38 -04008348 bf_set(payload_offset_len, &wqe->fcp_iread,
8349 xmit_len + sizeof(struct fcp_rsp));
8350 bf_set(cmd_buff_len, &wqe->fcp_iread,
8351 0);
James Smartf0d9bcc2010-10-22 11:07:09 -04008352 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8353 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8354 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
8355 iocbq->iocb.ulpFCP2Rcvy);
8356 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
James Smart4f774512009-05-22 14:52:35 -04008357 /* Always open the exchange */
8358 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
James Smartf0d9bcc2010-10-22 11:07:09 -04008359 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
8360 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
8361 LPFC_WQE_LENLOC_WORD4);
8362 bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
8363 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
James Smartacd68592012-01-18 16:25:09 -05008364 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008365 if (iocbq->iocb_flag & LPFC_IO_OAS) {
8366 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
8367 if (phba->cfg_XLanePriority) {
8368 bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
8369 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
8370 (phba->cfg_XLanePriority << 1));
8371 }
8372 }
James Smart7851fe22011-07-22 18:36:52 -04008373 break;
James Smartf1126682009-06-10 17:22:44 -04008374 case CMD_FCP_ICMND64_CR:
James Smart0ba4b212013-10-10 12:22:38 -04008375 /* word3 iocb=iotag wqe=payload_offset_len */
8376 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8377 bf_set(payload_offset_len, &wqe->fcp_icmd,
8378 xmit_len + sizeof(struct fcp_rsp));
8379 bf_set(cmd_buff_len, &wqe->fcp_icmd,
8380 0);
James Smartf0d9bcc2010-10-22 11:07:09 -04008381 /* word3 iocb=IO_TAG wqe=reserved */
James Smartf0d9bcc2010-10-22 11:07:09 -04008382 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
James Smartf1126682009-06-10 17:22:44 -04008383 /* Always open the exchange */
James Smartf0d9bcc2010-10-22 11:07:09 -04008384 bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
8385 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
8386 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
8387 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
8388 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
8389 LPFC_WQE_LENLOC_NONE);
8390 bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
James Smart2a94aea2012-09-29 11:30:31 -04008391 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
8392 iocbq->iocb.ulpFCP2Rcvy);
James Smart1ba981f2014-02-20 09:56:45 -05008393 if (iocbq->iocb_flag & LPFC_IO_OAS) {
8394 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
8395 if (phba->cfg_XLanePriority) {
8396 bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
8397 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
8398 (phba->cfg_XLanePriority << 1));
8399 }
8400 }
James Smart7851fe22011-07-22 18:36:52 -04008401 break;
James Smart4f774512009-05-22 14:52:35 -04008402 case CMD_GEN_REQUEST64_CR:
James Smart63e801c2010-11-20 23:14:19 -05008403 /* For this command calculate the xmit length of the
8404 * request bde.
8405 */
8406 xmit_len = 0;
8407 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
8408 sizeof(struct ulp_bde64);
8409 for (i = 0; i < numBdes; i++) {
James Smart63e801c2010-11-20 23:14:19 -05008410 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
James Smart546fc852011-03-11 16:06:29 -05008411 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
8412 break;
James Smart63e801c2010-11-20 23:14:19 -05008413 xmit_len += bde.tus.f.bdeSize;
8414 }
James Smartf0d9bcc2010-10-22 11:07:09 -04008415 /* word3 iocb=IO_TAG wqe=request_payload_len */
8416 wqe->gen_req.request_payload_len = xmit_len;
8417 /* word4 iocb=parameter wqe=relative_offset memcpy */
8418 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
James Smart4f774512009-05-22 14:52:35 -04008419 /* word6 context tag copied in memcpy */
8420 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
8421 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
8422 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8423 "2015 Invalid CT %x command 0x%x\n",
8424 ct, iocbq->iocb.ulpCommand);
8425 return IOCB_ERROR;
8426 }
James Smartf0d9bcc2010-10-22 11:07:09 -04008427 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
8428 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
8429 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
8430 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
8431 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
8432 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
8433 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
8434 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
James Smartaf227412013-10-10 12:23:10 -04008435 wqe->gen_req.max_response_payload_len = total_len - xmit_len;
James Smart4f774512009-05-22 14:52:35 -04008436 command_type = OTHER_COMMAND;
James Smart7851fe22011-07-22 18:36:52 -04008437 break;
James Smart4f774512009-05-22 14:52:35 -04008438 case CMD_XMIT_ELS_RSP64_CX:
James Smartc31098c2011-04-16 11:03:33 -04008439 ndlp = (struct lpfc_nodelist *)iocbq->context1;
James Smart4f774512009-05-22 14:52:35 -04008440 /* words0-2 BDE memcpy */
James Smartf0d9bcc2010-10-22 11:07:09 -04008441 /* word3 iocb=iotag32 wqe=response_payload_len */
8442 wqe->xmit_els_rsp.response_payload_len = xmit_len;
James Smart939723a2012-05-09 21:19:03 -04008443 /* word4 */
8444 wqe->xmit_els_rsp.word4 = 0;
James Smart4f774512009-05-22 14:52:35 -04008445 /* word5 iocb=rsvd wge=did */
8446 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
James Smart939723a2012-05-09 21:19:03 -04008447 iocbq->iocb.un.xseq64.xmit_els_remoteID);
8448
8449 if_type = bf_get(lpfc_sli_intf_if_type,
8450 &phba->sli4_hba.sli_intf);
8451 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8452 if (iocbq->vport->fc_flag & FC_PT2PT) {
8453 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
8454 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
8455 iocbq->vport->fc_myDID);
8456 if (iocbq->vport->fc_myDID == Fabric_DID) {
8457 bf_set(wqe_els_did,
8458 &wqe->xmit_els_rsp.wqe_dest, 0);
8459 }
8460 }
8461 }
James Smartf0d9bcc2010-10-22 11:07:09 -04008462 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
8463 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8464 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
8465 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
James Smart7851fe22011-07-22 18:36:52 -04008466 iocbq->iocb.unsli3.rcvsli3.ox_id);
James Smart4f774512009-05-22 14:52:35 -04008467 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
James Smartf0d9bcc2010-10-22 11:07:09 -04008468 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
James Smart6d368e52011-05-24 11:44:12 -04008469 phba->vpi_ids[iocbq->vport->vpi]);
James Smartf0d9bcc2010-10-22 11:07:09 -04008470 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
8471 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
8472 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
8473 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
8474 LPFC_WQE_LENLOC_WORD3);
8475 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
James Smart6d368e52011-05-24 11:44:12 -04008476 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
8477 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
James Smartff78d8f2011-12-13 13:21:35 -05008478 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8479 iocbq->context2)->virt);
8480 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart939723a2012-05-09 21:19:03 -04008481 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
8482 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
James Smartff78d8f2011-12-13 13:21:35 -05008483 iocbq->vport->fc_myDID);
James Smart939723a2012-05-09 21:19:03 -04008484 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
8485 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
James Smartff78d8f2011-12-13 13:21:35 -05008486 phba->vpi_ids[phba->pport->vpi]);
8487 }
James Smart4f774512009-05-22 14:52:35 -04008488 command_type = OTHER_COMMAND;
James Smart7851fe22011-07-22 18:36:52 -04008489 break;
James Smart4f774512009-05-22 14:52:35 -04008490 case CMD_CLOSE_XRI_CN:
8491 case CMD_ABORT_XRI_CN:
8492 case CMD_ABORT_XRI_CX:
8493 /* words 0-2 memcpy should be 0 rserved */
8494 /* port will send abts */
James Smartdcf2a4e2010-09-29 11:18:53 -04008495 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
8496 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
8497 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
8498 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
8499 } else
8500 fip = 0;
8501
8502 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
James Smart4f774512009-05-22 14:52:35 -04008503 /*
James Smartdcf2a4e2010-09-29 11:18:53 -04008504 * The link is down, or the command was ELS_FIP
8505 * so the fw does not need to send abts
James Smart4f774512009-05-22 14:52:35 -04008506 * on the wire.
8507 */
8508 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
8509 else
8510 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
8511 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
James Smartf0d9bcc2010-10-22 11:07:09 -04008512 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8513 wqe->abort_cmd.rsrvd5 = 0;
8514 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
James Smart4f774512009-05-22 14:52:35 -04008515 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8516 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
James Smart4f774512009-05-22 14:52:35 -04008517 /*
8518 * The abort handler will send us CMD_ABORT_XRI_CN or
8519 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8520 */
James Smartf0d9bcc2010-10-22 11:07:09 -04008521 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
8522 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
8523 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
8524 LPFC_WQE_LENLOC_NONE);
James Smart4f774512009-05-22 14:52:35 -04008525 cmnd = CMD_ABORT_XRI_CX;
8526 command_type = OTHER_COMMAND;
8527 xritag = 0;
James Smart7851fe22011-07-22 18:36:52 -04008528 break;
James Smart6669f9b2009-10-02 15:16:45 -04008529 case CMD_XMIT_BLS_RSP64_CX:
James Smart6b5151f2012-01-18 16:24:06 -05008530 ndlp = (struct lpfc_nodelist *)iocbq->context1;
James Smart546fc852011-03-11 16:06:29 -05008531 /* As BLS ABTS RSP WQE is very different from other WQEs,
James Smart6669f9b2009-10-02 15:16:45 -04008532 * we re-construct this WQE here based on information in
8533 * iocbq from scratch.
8534 */
8535 memset(wqe, 0, sizeof(union lpfc_wqe));
James Smart5ffc2662009-11-18 15:39:44 -05008536 /* OX_ID is invariable to who sent ABTS to CT exchange */
James Smart6669f9b2009-10-02 15:16:45 -04008537 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
James Smart546fc852011-03-11 16:06:29 -05008538 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
8539 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
James Smart5ffc2662009-11-18 15:39:44 -05008540 LPFC_ABTS_UNSOL_INT) {
8541 /* ABTS sent by initiator to CT exchange, the
8542 * RX_ID field will be filled with the newly
8543 * allocated responder XRI.
8544 */
8545 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
8546 iocbq->sli4_xritag);
8547 } else {
8548 /* ABTS sent by responder to CT exchange, the
8549 * RX_ID field will be filled with the responder
8550 * RX_ID from ABTS.
8551 */
8552 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
James Smart546fc852011-03-11 16:06:29 -05008553 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
James Smart5ffc2662009-11-18 15:39:44 -05008554 }
James Smart6669f9b2009-10-02 15:16:45 -04008555 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
8556 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
James Smart6b5151f2012-01-18 16:24:06 -05008557
8558 /* Use CT=VPI */
8559 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
8560 ndlp->nlp_DID);
8561 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
8562 iocbq->iocb.ulpContext);
8563 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
James Smart6669f9b2009-10-02 15:16:45 -04008564 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
James Smart6b5151f2012-01-18 16:24:06 -05008565 phba->vpi_ids[phba->pport->vpi]);
James Smartf0d9bcc2010-10-22 11:07:09 -04008566 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
8567 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
8568 LPFC_WQE_LENLOC_NONE);
James Smart6669f9b2009-10-02 15:16:45 -04008569 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8570 command_type = OTHER_COMMAND;
James Smart546fc852011-03-11 16:06:29 -05008571 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
8572 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
8573 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
8574 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
8575 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
8576 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
8577 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
8578 }
8579
James Smart7851fe22011-07-22 18:36:52 -04008580 break;
James Smart4f774512009-05-22 14:52:35 -04008581 case CMD_XRI_ABORTED_CX:
8582 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
James Smart4f774512009-05-22 14:52:35 -04008583 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
8584 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
8585 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
8586 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
8587 default:
8588 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8589 "2014 Invalid command 0x%x\n",
8590 iocbq->iocb.ulpCommand);
8591 return IOCB_ERROR;
James Smart7851fe22011-07-22 18:36:52 -04008592 break;
James Smart4f774512009-05-22 14:52:35 -04008593 }
James Smart6d368e52011-05-24 11:44:12 -04008594
James Smart8012cc32012-10-31 14:44:49 -04008595 if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
8596 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
8597 else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
8598 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
8599 else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
8600 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
8601 iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
8602 LPFC_IO_DIF_INSERT);
James Smartf0d9bcc2010-10-22 11:07:09 -04008603 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
8604 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
8605 wqe->generic.wqe_com.abort_tag = abort_tag;
8606 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
8607 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
8608 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
8609 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
James Smart4f774512009-05-22 14:52:35 -04008610 return 0;
8611}
8612
8613/**
8614 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8615 * @phba: Pointer to HBA context object.
8616 * @ring_number: SLI ring number to issue iocb on.
8617 * @piocb: Pointer to command iocb.
8618 * @flag: Flag indicating if this command can be put into txq.
8619 *
8620 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8621 * an iocb command to an HBA with SLI-4 interface spec.
8622 *
8623 * This function is called with hbalock held. The function will return success
8624 * after it successfully submit the iocb to firmware or after adding to the
8625 * txq.
8626 **/
8627static int
8628__lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
8629 struct lpfc_iocbq *piocb, uint32_t flag)
8630{
8631 struct lpfc_sglq *sglq;
James Smart4f774512009-05-22 14:52:35 -04008632 union lpfc_wqe wqe;
James Smart1ba981f2014-02-20 09:56:45 -05008633 struct lpfc_queue *wq;
James Smart4f774512009-05-22 14:52:35 -04008634 struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
James Smart4f774512009-05-22 14:52:35 -04008635
8636 if (piocb->sli4_xritag == NO_XRI) {
8637 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
James Smart6b5151f2012-01-18 16:24:06 -05008638 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
James Smart4f774512009-05-22 14:52:35 -04008639 sglq = NULL;
8640 else {
James Smart0e9bb8d2013-03-01 16:35:12 -05008641 if (!list_empty(&pring->txq)) {
James Smart2a9bf3d2010-06-07 15:24:45 -04008642 if (!(flag & SLI_IOCB_RET_IOCB)) {
8643 __lpfc_sli_ringtx_put(phba,
8644 pring, piocb);
8645 return IOCB_SUCCESS;
8646 } else {
8647 return IOCB_BUSY;
8648 }
8649 } else {
James Smart6d368e52011-05-24 11:44:12 -04008650 sglq = __lpfc_sli_get_sglq(phba, piocb);
James Smart2a9bf3d2010-06-07 15:24:45 -04008651 if (!sglq) {
8652 if (!(flag & SLI_IOCB_RET_IOCB)) {
8653 __lpfc_sli_ringtx_put(phba,
8654 pring,
8655 piocb);
8656 return IOCB_SUCCESS;
8657 } else
8658 return IOCB_BUSY;
8659 }
8660 }
James Smart4f774512009-05-22 14:52:35 -04008661 }
8662 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
James Smart6d368e52011-05-24 11:44:12 -04008663 /* These IO's already have an XRI and a mapped sgl. */
8664 sglq = NULL;
James Smart4f774512009-05-22 14:52:35 -04008665 } else {
James Smart6d368e52011-05-24 11:44:12 -04008666 /*
8667 * This is a continuation of a commandi,(CX) so this
James Smart4f774512009-05-22 14:52:35 -04008668 * sglq is on the active list
8669 */
James Smartedccdc12013-01-03 15:43:45 -05008670 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
James Smart4f774512009-05-22 14:52:35 -04008671 if (!sglq)
8672 return IOCB_ERROR;
8673 }
8674
8675 if (sglq) {
James Smart6d368e52011-05-24 11:44:12 -04008676 piocb->sli4_lxritag = sglq->sli4_lxritag;
James Smart2a9bf3d2010-06-07 15:24:45 -04008677 piocb->sli4_xritag = sglq->sli4_xritag;
James Smart2a9bf3d2010-06-07 15:24:45 -04008678 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
James Smart4f774512009-05-22 14:52:35 -04008679 return IOCB_ERROR;
8680 }
8681
8682 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
8683 return IOCB_ERROR;
8684
James Smart341af102010-01-26 23:07:37 -05008685 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
James Smart1ba981f2014-02-20 09:56:45 -05008686 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
James Smartf38fa0b2014-04-04 13:52:21 -04008687 if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) {
James Smart1ba981f2014-02-20 09:56:45 -05008688 wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx];
8689 } else {
8690 wq = phba->sli4_hba.oas_wq;
8691 }
8692 if (lpfc_sli4_wq_put(wq, &wqe))
James Smart4f774512009-05-22 14:52:35 -04008693 return IOCB_ERROR;
8694 } else {
James Smartea714f32013-04-17 20:18:47 -04008695 if (unlikely(!phba->sli4_hba.els_wq))
8696 return IOCB_ERROR;
James Smart4f774512009-05-22 14:52:35 -04008697 if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
8698 return IOCB_ERROR;
8699 }
8700 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
8701
8702 return 0;
8703}
8704
8705/**
James Smart3772a992009-05-22 14:50:54 -04008706 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8707 *
8708 * This routine wraps the actual lockless version for issusing IOCB function
8709 * pointer from the lpfc_hba struct.
8710 *
8711 * Return codes:
8712 * IOCB_ERROR - Error
8713 * IOCB_SUCCESS - Success
8714 * IOCB_BUSY - Busy
8715 **/
James Smart2a9bf3d2010-06-07 15:24:45 -04008716int
James Smart3772a992009-05-22 14:50:54 -04008717__lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
8718 struct lpfc_iocbq *piocb, uint32_t flag)
8719{
8720 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
8721}
8722
8723/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008724 * lpfc_sli_api_table_setup - Set up sli api function jump table
James Smart3772a992009-05-22 14:50:54 -04008725 * @phba: The hba struct for which this call is being executed.
8726 * @dev_grp: The HBA PCI-Device group number.
8727 *
8728 * This routine sets up the SLI interface API function jump table in @phba
8729 * struct.
8730 * Returns: 0 - success, -ENODEV - failure.
8731 **/
8732int
8733lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8734{
8735
8736 switch (dev_grp) {
8737 case LPFC_PCI_DEV_LP:
8738 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
8739 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
8740 break;
James Smart4f774512009-05-22 14:52:35 -04008741 case LPFC_PCI_DEV_OC:
8742 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
8743 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
8744 break;
James Smart3772a992009-05-22 14:50:54 -04008745 default:
8746 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8747 "1419 Invalid HBA PCI-device group: 0x%x\n",
8748 dev_grp);
8749 return -ENODEV;
8750 break;
8751 }
8752 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
8753 return 0;
8754}
James Smart92d7f7b2007-06-17 19:56:38 -05008755
James Smart9bd2bff52014-09-03 12:57:30 -04008756int
8757lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number,
8758 struct lpfc_iocbq *piocb)
8759{
8760 uint32_t idx;
8761
8762 if (phba->sli_rev == LPFC_SLI_REV4) {
8763 if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
8764 /*
8765 * fcp_wqidx should already be setup based on what
8766 * completion queue we want to use.
8767 */
8768 if (!(phba->cfg_fof) ||
8769 (!(piocb->iocb_flag & LPFC_IO_FOF))) {
8770 if (unlikely(!phba->sli4_hba.fcp_wq))
8771 return LPFC_HBA_ERROR;
8772 idx = lpfc_sli4_scmd_to_wqidx_distr(phba);
8773 piocb->fcp_wqidx = idx;
8774 ring_number = MAX_SLI3_CONFIGURED_RINGS + idx;
8775 } else {
8776 if (unlikely(!phba->sli4_hba.oas_wq))
8777 return LPFC_HBA_ERROR;
8778 idx = 0;
8779 piocb->fcp_wqidx = idx;
8780 ring_number = LPFC_FCP_OAS_RING;
8781 }
8782 }
8783 }
8784 return ring_number;
8785}
8786
James Smarte59058c2008-08-24 21:49:00 -04008787/**
James Smart3621a712009-04-06 18:47:14 -04008788 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
James Smarte59058c2008-08-24 21:49:00 -04008789 * @phba: Pointer to HBA context object.
8790 * @pring: Pointer to driver SLI ring object.
8791 * @piocb: Pointer to command iocb.
8792 * @flag: Flag indicating if this command can be put into txq.
8793 *
8794 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8795 * function. This function gets the hbalock and calls
8796 * __lpfc_sli_issue_iocb function and will return the error returned
8797 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8798 * functions which do not hold hbalock.
8799 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008800int
James Smart3772a992009-05-22 14:50:54 -04008801lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
James Smart92d7f7b2007-06-17 19:56:38 -05008802 struct lpfc_iocbq *piocb, uint32_t flag)
8803{
James Smartba20c852012-08-03 12:36:52 -04008804 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
James Smart2a76a282012-08-03 12:35:54 -04008805 struct lpfc_sli_ring *pring;
James Smartba20c852012-08-03 12:36:52 -04008806 struct lpfc_queue *fpeq;
8807 struct lpfc_eqe *eqe;
James Smart92d7f7b2007-06-17 19:56:38 -05008808 unsigned long iflags;
James Smart2a76a282012-08-03 12:35:54 -04008809 int rc, idx;
James Smart92d7f7b2007-06-17 19:56:38 -05008810
James Smart7e56aa22012-08-03 12:35:34 -04008811 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart9bd2bff52014-09-03 12:57:30 -04008812 ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb);
8813 if (unlikely(ring_number == LPFC_HBA_ERROR))
8814 return IOCB_ERROR;
8815 idx = piocb->fcp_wqidx;
James Smartba20c852012-08-03 12:36:52 -04008816
James Smart9bd2bff52014-09-03 12:57:30 -04008817 pring = &phba->sli.ring[ring_number];
8818 spin_lock_irqsave(&pring->ring_lock, iflags);
8819 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
8820 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smartba20c852012-08-03 12:36:52 -04008821
James Smart9bd2bff52014-09-03 12:57:30 -04008822 if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) {
8823 fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
James Smartba20c852012-08-03 12:36:52 -04008824
James Smart9bd2bff52014-09-03 12:57:30 -04008825 if (atomic_dec_and_test(&fcp_eq_hdl->
8826 fcp_eq_in_use)) {
James Smartba20c852012-08-03 12:36:52 -04008827
James Smart9bd2bff52014-09-03 12:57:30 -04008828 /* Get associated EQ with this index */
8829 fpeq = phba->sli4_hba.hba_eq[idx];
James Smartba20c852012-08-03 12:36:52 -04008830
James Smart9bd2bff52014-09-03 12:57:30 -04008831 /* Turn off interrupts from this EQ */
8832 lpfc_sli4_eq_clr_intr(fpeq);
James Smartba20c852012-08-03 12:36:52 -04008833
James Smart9bd2bff52014-09-03 12:57:30 -04008834 /*
8835 * Process all the events on FCP EQ
8836 */
8837 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
8838 lpfc_sli4_hba_handle_eqe(phba,
8839 eqe, idx);
8840 fpeq->EQ_processed++;
James Smartba20c852012-08-03 12:36:52 -04008841 }
James Smartba20c852012-08-03 12:36:52 -04008842
James Smart9bd2bff52014-09-03 12:57:30 -04008843 /* Always clear and re-arm the EQ */
8844 lpfc_sli4_eq_release(fpeq,
8845 LPFC_QUEUE_REARM);
8846 }
8847 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
James Smart2a76a282012-08-03 12:35:54 -04008848 }
James Smart7e56aa22012-08-03 12:35:34 -04008849 } else {
8850 /* For now, SLI2/3 will still use hbalock */
8851 spin_lock_irqsave(&phba->hbalock, iflags);
8852 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
8853 spin_unlock_irqrestore(&phba->hbalock, iflags);
8854 }
James Smart92d7f7b2007-06-17 19:56:38 -05008855 return rc;
8856}
8857
James Smarte59058c2008-08-24 21:49:00 -04008858/**
James Smart3621a712009-04-06 18:47:14 -04008859 * lpfc_extra_ring_setup - Extra ring setup function
James Smarte59058c2008-08-24 21:49:00 -04008860 * @phba: Pointer to HBA context object.
8861 *
8862 * This function is called while driver attaches with the
8863 * HBA to setup the extra ring. The extra ring is used
8864 * only when driver needs to support target mode functionality
8865 * or IP over FC functionalities.
8866 *
8867 * This function is called with no lock held.
8868 **/
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05008869static int
8870lpfc_extra_ring_setup( struct lpfc_hba *phba)
8871{
8872 struct lpfc_sli *psli;
8873 struct lpfc_sli_ring *pring;
8874
8875 psli = &phba->sli;
8876
8877 /* Adjust cmd/rsp ring iocb entries more evenly */
James Smarta4bc3372006-12-02 13:34:16 -05008878
8879 /* Take some away from the FCP ring */
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05008880 pring = &psli->ring[psli->fcp_ring];
James Smart7e56aa22012-08-03 12:35:34 -04008881 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
8882 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
8883 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
8884 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05008885
James Smarta4bc3372006-12-02 13:34:16 -05008886 /* and give them to the extra ring */
8887 pring = &psli->ring[psli->extra_ring];
8888
James Smart7e56aa22012-08-03 12:35:34 -04008889 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
8890 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
8891 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
8892 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05008893
8894 /* Setup default profile for this ring */
8895 pring->iotag_max = 4096;
8896 pring->num_mask = 1;
8897 pring->prt[0].profile = 0; /* Mask 0 */
James Smarta4bc3372006-12-02 13:34:16 -05008898 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
8899 pring->prt[0].type = phba->cfg_multi_ring_type;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05008900 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
8901 return 0;
8902}
8903
James Smartcb69f7d2011-12-13 13:21:57 -05008904/* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8905 * @phba: Pointer to HBA context object.
8906 * @iocbq: Pointer to iocb object.
8907 *
8908 * The async_event handler calls this routine when it receives
8909 * an ASYNC_STATUS_CN event from the port. The port generates
8910 * this event when an Abort Sequence request to an rport fails
8911 * twice in succession. The abort could be originated by the
8912 * driver or by the port. The ABTS could have been for an ELS
8913 * or FCP IO. The port only generates this event when an ABTS
8914 * fails to complete after one retry.
8915 */
8916static void
8917lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
8918 struct lpfc_iocbq *iocbq)
8919{
8920 struct lpfc_nodelist *ndlp = NULL;
8921 uint16_t rpi = 0, vpi = 0;
8922 struct lpfc_vport *vport = NULL;
8923
8924 /* The rpi in the ulpContext is vport-sensitive. */
8925 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
8926 rpi = iocbq->iocb.ulpContext;
8927
8928 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8929 "3092 Port generated ABTS async event "
8930 "on vpi %d rpi %d status 0x%x\n",
8931 vpi, rpi, iocbq->iocb.ulpStatus);
8932
8933 vport = lpfc_find_vport_by_vpid(phba, vpi);
8934 if (!vport)
8935 goto err_exit;
8936 ndlp = lpfc_findnode_rpi(vport, rpi);
8937 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8938 goto err_exit;
8939
8940 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
8941 lpfc_sli_abts_recover_port(vport, ndlp);
8942 return;
8943
8944 err_exit:
8945 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8946 "3095 Event Context not found, no "
8947 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8948 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
8949 vpi, rpi);
8950}
8951
8952/* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8953 * @phba: pointer to HBA context object.
8954 * @ndlp: nodelist pointer for the impacted rport.
8955 * @axri: pointer to the wcqe containing the failed exchange.
8956 *
8957 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8958 * port. The port generates this event when an abort exchange request to an
8959 * rport fails twice in succession with no reply. The abort could be originated
8960 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8961 */
8962void
8963lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
8964 struct lpfc_nodelist *ndlp,
8965 struct sli4_wcqe_xri_aborted *axri)
8966{
8967 struct lpfc_vport *vport;
James Smart5c1db2a2012-03-01 22:34:36 -05008968 uint32_t ext_status = 0;
James Smartcb69f7d2011-12-13 13:21:57 -05008969
James Smart6b5151f2012-01-18 16:24:06 -05008970 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartcb69f7d2011-12-13 13:21:57 -05008971 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8972 "3115 Node Context not found, driver "
8973 "ignoring abts err event\n");
James Smart6b5151f2012-01-18 16:24:06 -05008974 return;
8975 }
8976
James Smartcb69f7d2011-12-13 13:21:57 -05008977 vport = ndlp->vport;
8978 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8979 "3116 Port generated FCP XRI ABORT event on "
James Smart5c1db2a2012-03-01 22:34:36 -05008980 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
James Smart8e668af2013-05-31 17:04:28 -04008981 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
James Smartcb69f7d2011-12-13 13:21:57 -05008982 bf_get(lpfc_wcqe_xa_xri, axri),
James Smart5c1db2a2012-03-01 22:34:36 -05008983 bf_get(lpfc_wcqe_xa_status, axri),
8984 axri->parameter);
James Smartcb69f7d2011-12-13 13:21:57 -05008985
James Smart5c1db2a2012-03-01 22:34:36 -05008986 /*
8987 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8988 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8989 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8990 */
James Smarte3d2b802012-08-14 14:25:43 -04008991 ext_status = axri->parameter & IOERR_PARAM_MASK;
James Smart5c1db2a2012-03-01 22:34:36 -05008992 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
8993 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
James Smartcb69f7d2011-12-13 13:21:57 -05008994 lpfc_sli_abts_recover_port(vport, ndlp);
8995}
8996
James Smarte59058c2008-08-24 21:49:00 -04008997/**
James Smart3621a712009-04-06 18:47:14 -04008998 * lpfc_sli_async_event_handler - ASYNC iocb handler function
James Smarte59058c2008-08-24 21:49:00 -04008999 * @phba: Pointer to HBA context object.
9000 * @pring: Pointer to driver SLI ring object.
9001 * @iocbq: Pointer to iocb object.
9002 *
9003 * This function is called by the slow ring event handler
9004 * function when there is an ASYNC event iocb in the ring.
9005 * This function is called with no lock held.
9006 * Currently this function handles only temperature related
9007 * ASYNC events. The function decodes the temperature sensor
9008 * event message and posts events for the management applications.
9009 **/
James Smart98c9ea52007-10-27 13:37:33 -04009010static void
James Smart57127f12007-10-27 13:37:05 -04009011lpfc_sli_async_event_handler(struct lpfc_hba * phba,
9012 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
9013{
9014 IOCB_t *icmd;
9015 uint16_t evt_code;
James Smart57127f12007-10-27 13:37:05 -04009016 struct temp_event temp_event_data;
9017 struct Scsi_Host *shost;
James Smarta257bf92009-04-06 18:48:10 -04009018 uint32_t *iocb_w;
James Smart57127f12007-10-27 13:37:05 -04009019
9020 icmd = &iocbq->iocb;
9021 evt_code = icmd->un.asyncstat.evt_code;
James Smart57127f12007-10-27 13:37:05 -04009022
James Smartcb69f7d2011-12-13 13:21:57 -05009023 switch (evt_code) {
9024 case ASYNC_TEMP_WARN:
9025 case ASYNC_TEMP_SAFE:
9026 temp_event_data.data = (uint32_t) icmd->ulpContext;
9027 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
9028 if (evt_code == ASYNC_TEMP_WARN) {
9029 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
9030 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
9031 "0347 Adapter is very hot, please take "
9032 "corrective action. temperature : %d Celsius\n",
9033 (uint32_t) icmd->ulpContext);
9034 } else {
9035 temp_event_data.event_code = LPFC_NORMAL_TEMP;
9036 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
9037 "0340 Adapter temperature is OK now. "
9038 "temperature : %d Celsius\n",
9039 (uint32_t) icmd->ulpContext);
9040 }
9041
9042 /* Send temperature change event to applications */
9043 shost = lpfc_shost_from_vport(phba->pport);
9044 fc_host_post_vendor_event(shost, fc_get_event_number(),
9045 sizeof(temp_event_data), (char *) &temp_event_data,
9046 LPFC_NL_VENDOR_ID);
9047 break;
9048 case ASYNC_STATUS_CN:
9049 lpfc_sli_abts_err_handler(phba, iocbq);
9050 break;
9051 default:
James Smarta257bf92009-04-06 18:48:10 -04009052 iocb_w = (uint32_t *) icmd;
James Smartcb69f7d2011-12-13 13:21:57 -05009053 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart76bb24e2007-10-27 13:38:00 -04009054 "0346 Ring %d handler: unexpected ASYNC_STATUS"
James Smarte4e74272009-07-19 10:01:38 -04009055 " evt_code 0x%x\n"
James Smarta257bf92009-04-06 18:48:10 -04009056 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9057 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9058 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9059 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
James Smartcb69f7d2011-12-13 13:21:57 -05009060 pring->ringno, icmd->un.asyncstat.evt_code,
James Smarta257bf92009-04-06 18:48:10 -04009061 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
9062 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
9063 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
9064 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
9065
James Smartcb69f7d2011-12-13 13:21:57 -05009066 break;
James Smart57127f12007-10-27 13:37:05 -04009067 }
James Smart57127f12007-10-27 13:37:05 -04009068}
9069
9070
James Smarte59058c2008-08-24 21:49:00 -04009071/**
James Smart3621a712009-04-06 18:47:14 -04009072 * lpfc_sli_setup - SLI ring setup function
James Smarte59058c2008-08-24 21:49:00 -04009073 * @phba: Pointer to HBA context object.
9074 *
9075 * lpfc_sli_setup sets up rings of the SLI interface with
9076 * number of iocbs per ring and iotags. This function is
9077 * called while driver attach to the HBA and before the
9078 * interrupts are enabled. So there is no need for locking.
9079 *
9080 * This function always returns 0.
9081 **/
dea31012005-04-17 16:05:31 -05009082int
9083lpfc_sli_setup(struct lpfc_hba *phba)
9084{
James Smarted957682007-06-17 19:56:37 -05009085 int i, totiocbsize = 0;
dea31012005-04-17 16:05:31 -05009086 struct lpfc_sli *psli = &phba->sli;
9087 struct lpfc_sli_ring *pring;
9088
James Smart2a76a282012-08-03 12:35:54 -04009089 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
9090 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart67d12732012-08-03 12:36:13 -04009091 psli->num_rings += phba->cfg_fcp_io_channel;
dea31012005-04-17 16:05:31 -05009092 psli->sli_flag = 0;
9093 psli->fcp_ring = LPFC_FCP_RING;
9094 psli->next_ring = LPFC_FCP_NEXT_RING;
James Smarta4bc3372006-12-02 13:34:16 -05009095 psli->extra_ring = LPFC_EXTRA_RING;
dea31012005-04-17 16:05:31 -05009096
James Bottomley604a3e32005-10-29 10:28:33 -05009097 psli->iocbq_lookup = NULL;
9098 psli->iocbq_lookup_len = 0;
9099 psli->last_iotag = 0;
9100
dea31012005-04-17 16:05:31 -05009101 for (i = 0; i < psli->num_rings; i++) {
9102 pring = &psli->ring[i];
9103 switch (i) {
9104 case LPFC_FCP_RING: /* ring 0 - FCP */
9105 /* numCiocb and numRiocb are used in config_port */
James Smart7e56aa22012-08-03 12:35:34 -04009106 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
9107 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
9108 pring->sli.sli3.numCiocb +=
9109 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
9110 pring->sli.sli3.numRiocb +=
9111 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
9112 pring->sli.sli3.numCiocb +=
9113 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
9114 pring->sli.sli3.numRiocb +=
9115 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
9116 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05009117 SLI3_IOCB_CMD_SIZE :
9118 SLI2_IOCB_CMD_SIZE;
James Smart7e56aa22012-08-03 12:35:34 -04009119 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05009120 SLI3_IOCB_RSP_SIZE :
9121 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05009122 pring->iotag_ctr = 0;
9123 pring->iotag_max =
James Smart92d7f7b2007-06-17 19:56:38 -05009124 (phba->cfg_hba_queue_depth * 2);
dea31012005-04-17 16:05:31 -05009125 pring->fast_iotag = pring->iotag_max;
9126 pring->num_mask = 0;
9127 break;
James Smarta4bc3372006-12-02 13:34:16 -05009128 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
dea31012005-04-17 16:05:31 -05009129 /* numCiocb and numRiocb are used in config_port */
James Smart7e56aa22012-08-03 12:35:34 -04009130 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
9131 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
9132 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05009133 SLI3_IOCB_CMD_SIZE :
9134 SLI2_IOCB_CMD_SIZE;
James Smart7e56aa22012-08-03 12:35:34 -04009135 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05009136 SLI3_IOCB_RSP_SIZE :
9137 SLI2_IOCB_RSP_SIZE;
James Smart2e0fef82007-06-17 19:56:36 -05009138 pring->iotag_max = phba->cfg_hba_queue_depth;
dea31012005-04-17 16:05:31 -05009139 pring->num_mask = 0;
9140 break;
9141 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
9142 /* numCiocb and numRiocb are used in config_port */
James Smart7e56aa22012-08-03 12:35:34 -04009143 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
9144 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
9145 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05009146 SLI3_IOCB_CMD_SIZE :
9147 SLI2_IOCB_CMD_SIZE;
James Smart7e56aa22012-08-03 12:35:34 -04009148 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05009149 SLI3_IOCB_RSP_SIZE :
9150 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05009151 pring->fast_iotag = 0;
9152 pring->iotag_ctr = 0;
9153 pring->iotag_max = 4096;
James Smart57127f12007-10-27 13:37:05 -04009154 pring->lpfc_sli_rcv_async_status =
9155 lpfc_sli_async_event_handler;
James Smart6669f9b2009-10-02 15:16:45 -04009156 pring->num_mask = LPFC_MAX_RING_MASK;
dea31012005-04-17 16:05:31 -05009157 pring->prt[0].profile = 0; /* Mask 0 */
James Smart6a9c52c2009-10-02 15:16:51 -04009158 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
9159 pring->prt[0].type = FC_TYPE_ELS;
dea31012005-04-17 16:05:31 -05009160 pring->prt[0].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05009161 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05009162 pring->prt[1].profile = 0; /* Mask 1 */
James Smart6a9c52c2009-10-02 15:16:51 -04009163 pring->prt[1].rctl = FC_RCTL_ELS_REP;
9164 pring->prt[1].type = FC_TYPE_ELS;
dea31012005-04-17 16:05:31 -05009165 pring->prt[1].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05009166 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05009167 pring->prt[2].profile = 0; /* Mask 2 */
9168 /* NameServer Inquiry */
James Smart6a9c52c2009-10-02 15:16:51 -04009169 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
dea31012005-04-17 16:05:31 -05009170 /* NameServer */
James Smart6a9c52c2009-10-02 15:16:51 -04009171 pring->prt[2].type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -05009172 pring->prt[2].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05009173 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05009174 pring->prt[3].profile = 0; /* Mask 3 */
9175 /* NameServer response */
James Smart6a9c52c2009-10-02 15:16:51 -04009176 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
dea31012005-04-17 16:05:31 -05009177 /* NameServer */
James Smart6a9c52c2009-10-02 15:16:51 -04009178 pring->prt[3].type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -05009179 pring->prt[3].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05009180 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05009181 break;
9182 }
James Smart7e56aa22012-08-03 12:35:34 -04009183 totiocbsize += (pring->sli.sli3.numCiocb *
9184 pring->sli.sli3.sizeCiocb) +
9185 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
dea31012005-04-17 16:05:31 -05009186 }
James Smarted957682007-06-17 19:56:37 -05009187 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
dea31012005-04-17 16:05:31 -05009188 /* Too many cmd / rsp ring entries in SLI2 SLIM */
James Smarte8b62012007-08-02 11:10:09 -04009189 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
9190 "SLI2 SLIM Data: x%x x%lx\n",
9191 phba->brd_no, totiocbsize,
9192 (unsigned long) MAX_SLIM_IOCB_SIZE);
dea31012005-04-17 16:05:31 -05009193 }
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05009194 if (phba->cfg_multi_ring_support == 2)
9195 lpfc_extra_ring_setup(phba);
dea31012005-04-17 16:05:31 -05009196
9197 return 0;
9198}
9199
James Smarte59058c2008-08-24 21:49:00 -04009200/**
James Smart3621a712009-04-06 18:47:14 -04009201 * lpfc_sli_queue_setup - Queue initialization function
James Smarte59058c2008-08-24 21:49:00 -04009202 * @phba: Pointer to HBA context object.
9203 *
9204 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
9205 * ring. This function also initializes ring indices of each ring.
9206 * This function is called during the initialization of the SLI
9207 * interface of an HBA.
9208 * This function is called with no lock held and always returns
9209 * 1.
9210 **/
dea31012005-04-17 16:05:31 -05009211int
James Smart2e0fef82007-06-17 19:56:36 -05009212lpfc_sli_queue_setup(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05009213{
9214 struct lpfc_sli *psli;
9215 struct lpfc_sli_ring *pring;
James Bottomley604a3e32005-10-29 10:28:33 -05009216 int i;
dea31012005-04-17 16:05:31 -05009217
9218 psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05009219 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009220 INIT_LIST_HEAD(&psli->mboxq);
James Smart92d7f7b2007-06-17 19:56:38 -05009221 INIT_LIST_HEAD(&psli->mboxq_cmpl);
dea31012005-04-17 16:05:31 -05009222 /* Initialize list headers for txq and txcmplq as double linked lists */
9223 for (i = 0; i < psli->num_rings; i++) {
9224 pring = &psli->ring[i];
9225 pring->ringno = i;
James Smart7e56aa22012-08-03 12:35:34 -04009226 pring->sli.sli3.next_cmdidx = 0;
9227 pring->sli.sli3.local_getidx = 0;
9228 pring->sli.sli3.cmdidx = 0;
James Smart68e814f2014-05-21 08:04:59 -04009229 pring->flag = 0;
dea31012005-04-17 16:05:31 -05009230 INIT_LIST_HEAD(&pring->txq);
9231 INIT_LIST_HEAD(&pring->txcmplq);
9232 INIT_LIST_HEAD(&pring->iocb_continueq);
James Smart9c2face2008-01-11 01:53:18 -05009233 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
dea31012005-04-17 16:05:31 -05009234 INIT_LIST_HEAD(&pring->postbufq);
James Smart7e56aa22012-08-03 12:35:34 -04009235 spin_lock_init(&pring->ring_lock);
dea31012005-04-17 16:05:31 -05009236 }
James Smart2e0fef82007-06-17 19:56:36 -05009237 spin_unlock_irq(&phba->hbalock);
9238 return 1;
dea31012005-04-17 16:05:31 -05009239}
9240
James Smarte59058c2008-08-24 21:49:00 -04009241/**
James Smart04c68492009-05-22 14:52:52 -04009242 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9243 * @phba: Pointer to HBA context object.
9244 *
9245 * This routine flushes the mailbox command subsystem. It will unconditionally
9246 * flush all the mailbox commands in the three possible stages in the mailbox
9247 * command sub-system: pending mailbox command queue; the outstanding mailbox
9248 * command; and completed mailbox command queue. It is caller's responsibility
9249 * to make sure that the driver is in the proper state to flush the mailbox
9250 * command sub-system. Namely, the posting of mailbox commands into the
9251 * pending mailbox command queue from the various clients must be stopped;
9252 * either the HBA is in a state that it will never works on the outstanding
9253 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
9254 * mailbox command has been completed.
9255 **/
9256static void
9257lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
9258{
9259 LIST_HEAD(completions);
9260 struct lpfc_sli *psli = &phba->sli;
9261 LPFC_MBOXQ_t *pmb;
9262 unsigned long iflag;
9263
9264 /* Flush all the mailbox commands in the mbox system */
9265 spin_lock_irqsave(&phba->hbalock, iflag);
9266 /* The pending mailbox command queue */
9267 list_splice_init(&phba->sli.mboxq, &completions);
9268 /* The outstanding active mailbox command */
9269 if (psli->mbox_active) {
9270 list_add_tail(&psli->mbox_active->list, &completions);
9271 psli->mbox_active = NULL;
9272 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9273 }
9274 /* The completed mailbox command queue */
9275 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
9276 spin_unlock_irqrestore(&phba->hbalock, iflag);
9277
9278 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
9279 while (!list_empty(&completions)) {
9280 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
9281 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
9282 if (pmb->mbox_cmpl)
9283 pmb->mbox_cmpl(phba, pmb);
9284 }
9285}
9286
9287/**
James Smart3621a712009-04-06 18:47:14 -04009288 * lpfc_sli_host_down - Vport cleanup function
James Smarte59058c2008-08-24 21:49:00 -04009289 * @vport: Pointer to virtual port object.
9290 *
9291 * lpfc_sli_host_down is called to clean up the resources
9292 * associated with a vport before destroying virtual
9293 * port data structures.
9294 * This function does following operations:
9295 * - Free discovery resources associated with this virtual
9296 * port.
9297 * - Free iocbs associated with this virtual port in
9298 * the txq.
9299 * - Send abort for all iocb commands associated with this
9300 * vport in txcmplq.
9301 *
9302 * This function is called with no lock held and always returns 1.
9303 **/
dea31012005-04-17 16:05:31 -05009304int
James Smart92d7f7b2007-06-17 19:56:38 -05009305lpfc_sli_host_down(struct lpfc_vport *vport)
9306{
James Smart858c9f62007-06-17 19:56:39 -05009307 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009308 struct lpfc_hba *phba = vport->phba;
9309 struct lpfc_sli *psli = &phba->sli;
9310 struct lpfc_sli_ring *pring;
9311 struct lpfc_iocbq *iocb, *next_iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05009312 int i;
9313 unsigned long flags = 0;
9314 uint16_t prev_pring_flag;
9315
9316 lpfc_cleanup_discovery_resources(vport);
9317
9318 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05009319 for (i = 0; i < psli->num_rings; i++) {
9320 pring = &psli->ring[i];
9321 prev_pring_flag = pring->flag;
James Smart5e9d9b82008-06-14 22:52:53 -04009322 /* Only slow rings */
9323 if (pring->ringno == LPFC_ELS_RING) {
James Smart858c9f62007-06-17 19:56:39 -05009324 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -04009325 /* Set the lpfc data pending flag */
9326 set_bit(LPFC_DATA_READY, &phba->data_flags);
9327 }
James Smart92d7f7b2007-06-17 19:56:38 -05009328 /*
9329 * Error everything on the txq since these iocbs have not been
9330 * given to the FW yet.
9331 */
James Smart92d7f7b2007-06-17 19:56:38 -05009332 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
9333 if (iocb->vport != vport)
9334 continue;
James Smart858c9f62007-06-17 19:56:39 -05009335 list_move_tail(&iocb->list, &completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009336 }
9337
9338 /* Next issue ABTS for everything on the txcmplq */
9339 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
9340 list) {
9341 if (iocb->vport != vport)
9342 continue;
9343 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
9344 }
9345
9346 pring->flag = prev_pring_flag;
9347 }
9348
9349 spin_unlock_irqrestore(&phba->hbalock, flags);
9350
James Smarta257bf92009-04-06 18:48:10 -04009351 /* Cancel all the IOCBs from the completions list */
9352 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9353 IOERR_SLI_DOWN);
James Smart92d7f7b2007-06-17 19:56:38 -05009354 return 1;
9355}
9356
James Smarte59058c2008-08-24 21:49:00 -04009357/**
James Smart3621a712009-04-06 18:47:14 -04009358 * lpfc_sli_hba_down - Resource cleanup function for the HBA
James Smarte59058c2008-08-24 21:49:00 -04009359 * @phba: Pointer to HBA context object.
9360 *
9361 * This function cleans up all iocb, buffers, mailbox commands
9362 * while shutting down the HBA. This function is called with no
9363 * lock held and always returns 1.
9364 * This function does the following to cleanup driver resources:
9365 * - Free discovery resources for each virtual port
9366 * - Cleanup any pending fabric iocbs
9367 * - Iterate through the iocb txq and free each entry
9368 * in the list.
9369 * - Free up any buffer posted to the HBA
9370 * - Free mailbox commands in the mailbox queue.
9371 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009372int
James Smart2e0fef82007-06-17 19:56:36 -05009373lpfc_sli_hba_down(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05009374{
James Smart2534ba72007-04-25 09:52:20 -04009375 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05009376 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05009377 struct lpfc_sli_ring *pring;
James Smart0ff10d42008-01-11 01:52:36 -05009378 struct lpfc_dmabuf *buf_ptr;
dea31012005-04-17 16:05:31 -05009379 unsigned long flags = 0;
James Smart04c68492009-05-22 14:52:52 -04009380 int i;
9381
9382 /* Shutdown the mailbox command sub-system */
James Smart618a5232012-06-12 13:54:36 -04009383 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05009384
dea31012005-04-17 16:05:31 -05009385 lpfc_hba_down_prep(phba);
9386
James Smart92d7f7b2007-06-17 19:56:38 -05009387 lpfc_fabric_abort_hba(phba);
9388
James Smart2e0fef82007-06-17 19:56:36 -05009389 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05009390 for (i = 0; i < psli->num_rings; i++) {
9391 pring = &psli->ring[i];
James Smart5e9d9b82008-06-14 22:52:53 -04009392 /* Only slow rings */
9393 if (pring->ringno == LPFC_ELS_RING) {
James Smart858c9f62007-06-17 19:56:39 -05009394 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -04009395 /* Set the lpfc data pending flag */
9396 set_bit(LPFC_DATA_READY, &phba->data_flags);
9397 }
dea31012005-04-17 16:05:31 -05009398
9399 /*
9400 * Error everything on the txq since these iocbs have not been
9401 * given to the FW yet.
9402 */
James Smart2534ba72007-04-25 09:52:20 -04009403 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05009404 }
James Smart2e0fef82007-06-17 19:56:36 -05009405 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05009406
James Smarta257bf92009-04-06 18:48:10 -04009407 /* Cancel all the IOCBs from the completions list */
9408 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9409 IOERR_SLI_DOWN);
James Smart2534ba72007-04-25 09:52:20 -04009410
James Smart0ff10d42008-01-11 01:52:36 -05009411 spin_lock_irqsave(&phba->hbalock, flags);
9412 list_splice_init(&phba->elsbuf, &completions);
9413 phba->elsbuf_cnt = 0;
9414 phba->elsbuf_prev_cnt = 0;
9415 spin_unlock_irqrestore(&phba->hbalock, flags);
9416
9417 while (!list_empty(&completions)) {
9418 list_remove_head(&completions, buf_ptr,
9419 struct lpfc_dmabuf, list);
9420 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
9421 kfree(buf_ptr);
9422 }
9423
dea31012005-04-17 16:05:31 -05009424 /* Return any active mbox cmds */
9425 del_timer_sync(&psli->mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05009426
James Smartda0436e2009-05-22 14:51:39 -04009427 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05009428 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
James Smartda0436e2009-05-22 14:51:39 -04009429 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05009430
James Smartda0436e2009-05-22 14:51:39 -04009431 return 1;
9432}
James Smart92d7f7b2007-06-17 19:56:38 -05009433
James Smartda0436e2009-05-22 14:51:39 -04009434/**
James Smart3621a712009-04-06 18:47:14 -04009435 * lpfc_sli_pcimem_bcopy - SLI memory copy function
James Smarte59058c2008-08-24 21:49:00 -04009436 * @srcp: Source memory pointer.
9437 * @destp: Destination memory pointer.
9438 * @cnt: Number of words required to be copied.
9439 *
9440 * This function is used for copying data between driver memory
9441 * and the SLI memory. This function also changes the endianness
9442 * of each word if native endianness is different from SLI
9443 * endianness. This function can be called with or without
9444 * lock.
9445 **/
dea31012005-04-17 16:05:31 -05009446void
9447lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
9448{
9449 uint32_t *src = srcp;
9450 uint32_t *dest = destp;
9451 uint32_t ldata;
9452 int i;
9453
9454 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
9455 ldata = *src;
9456 ldata = le32_to_cpu(ldata);
9457 *dest = ldata;
9458 src++;
9459 dest++;
9460 }
9461}
9462
James Smarte59058c2008-08-24 21:49:00 -04009463
9464/**
James Smarta0c87cb2009-07-19 10:01:10 -04009465 * lpfc_sli_bemem_bcopy - SLI memory copy function
9466 * @srcp: Source memory pointer.
9467 * @destp: Destination memory pointer.
9468 * @cnt: Number of words required to be copied.
9469 *
9470 * This function is used for copying data between a data structure
9471 * with big endian representation to local endianness.
9472 * This function can be called with or without lock.
9473 **/
9474void
9475lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
9476{
9477 uint32_t *src = srcp;
9478 uint32_t *dest = destp;
9479 uint32_t ldata;
9480 int i;
9481
9482 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
9483 ldata = *src;
9484 ldata = be32_to_cpu(ldata);
9485 *dest = ldata;
9486 src++;
9487 dest++;
9488 }
9489}
9490
9491/**
James Smart3621a712009-04-06 18:47:14 -04009492 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
James Smarte59058c2008-08-24 21:49:00 -04009493 * @phba: Pointer to HBA context object.
9494 * @pring: Pointer to driver SLI ring object.
9495 * @mp: Pointer to driver buffer object.
9496 *
9497 * This function is called with no lock held.
9498 * It always return zero after adding the buffer to the postbufq
9499 * buffer list.
9500 **/
dea31012005-04-17 16:05:31 -05009501int
James Smart2e0fef82007-06-17 19:56:36 -05009502lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9503 struct lpfc_dmabuf *mp)
dea31012005-04-17 16:05:31 -05009504{
9505 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9506 later */
James Smart2e0fef82007-06-17 19:56:36 -05009507 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009508 list_add_tail(&mp->list, &pring->postbufq);
dea31012005-04-17 16:05:31 -05009509 pring->postbufq_cnt++;
James Smart2e0fef82007-06-17 19:56:36 -05009510 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009511 return 0;
9512}
9513
James Smarte59058c2008-08-24 21:49:00 -04009514/**
James Smart3621a712009-04-06 18:47:14 -04009515 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
James Smarte59058c2008-08-24 21:49:00 -04009516 * @phba: Pointer to HBA context object.
9517 *
9518 * When HBQ is enabled, buffers are searched based on tags. This function
9519 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9520 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9521 * does not conflict with tags of buffer posted for unsolicited events.
9522 * The function returns the allocated tag. The function is called with
9523 * no locks held.
9524 **/
James Smart76bb24e2007-10-27 13:38:00 -04009525uint32_t
9526lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
9527{
9528 spin_lock_irq(&phba->hbalock);
9529 phba->buffer_tag_count++;
9530 /*
9531 * Always set the QUE_BUFTAG_BIT to distiguish between
9532 * a tag assigned by HBQ.
9533 */
9534 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
9535 spin_unlock_irq(&phba->hbalock);
9536 return phba->buffer_tag_count;
9537}
9538
James Smarte59058c2008-08-24 21:49:00 -04009539/**
James Smart3621a712009-04-06 18:47:14 -04009540 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
James Smarte59058c2008-08-24 21:49:00 -04009541 * @phba: Pointer to HBA context object.
9542 * @pring: Pointer to driver SLI ring object.
9543 * @tag: Buffer tag.
9544 *
9545 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9546 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9547 * iocb is posted to the response ring with the tag of the buffer.
9548 * This function searches the pring->postbufq list using the tag
9549 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9550 * iocb. If the buffer is found then lpfc_dmabuf object of the
9551 * buffer is returned to the caller else NULL is returned.
9552 * This function is called with no lock held.
9553 **/
James Smart76bb24e2007-10-27 13:38:00 -04009554struct lpfc_dmabuf *
9555lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9556 uint32_t tag)
9557{
9558 struct lpfc_dmabuf *mp, *next_mp;
9559 struct list_head *slp = &pring->postbufq;
9560
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009561 /* Search postbufq, from the beginning, looking for a match on tag */
James Smart76bb24e2007-10-27 13:38:00 -04009562 spin_lock_irq(&phba->hbalock);
9563 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
9564 if (mp->buffer_tag == tag) {
9565 list_del_init(&mp->list);
9566 pring->postbufq_cnt--;
9567 spin_unlock_irq(&phba->hbalock);
9568 return mp;
9569 }
9570 }
9571
9572 spin_unlock_irq(&phba->hbalock);
9573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04009574 "0402 Cannot find virtual addr for buffer tag on "
James Smart76bb24e2007-10-27 13:38:00 -04009575 "ring %d Data x%lx x%p x%p x%x\n",
9576 pring->ringno, (unsigned long) tag,
9577 slp->next, slp->prev, pring->postbufq_cnt);
9578
9579 return NULL;
9580}
dea31012005-04-17 16:05:31 -05009581
James Smarte59058c2008-08-24 21:49:00 -04009582/**
James Smart3621a712009-04-06 18:47:14 -04009583 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
James Smarte59058c2008-08-24 21:49:00 -04009584 * @phba: Pointer to HBA context object.
9585 * @pring: Pointer to driver SLI ring object.
9586 * @phys: DMA address of the buffer.
9587 *
9588 * This function searches the buffer list using the dma_address
9589 * of unsolicited event to find the driver's lpfc_dmabuf object
9590 * corresponding to the dma_address. The function returns the
9591 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9592 * This function is called by the ct and els unsolicited event
9593 * handlers to get the buffer associated with the unsolicited
9594 * event.
9595 *
9596 * This function is called with no lock held.
9597 **/
dea31012005-04-17 16:05:31 -05009598struct lpfc_dmabuf *
9599lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9600 dma_addr_t phys)
9601{
9602 struct lpfc_dmabuf *mp, *next_mp;
9603 struct list_head *slp = &pring->postbufq;
9604
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009605 /* Search postbufq, from the beginning, looking for a match on phys */
James Smart2e0fef82007-06-17 19:56:36 -05009606 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009607 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
9608 if (mp->phys == phys) {
9609 list_del_init(&mp->list);
9610 pring->postbufq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05009611 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009612 return mp;
9613 }
9614 }
9615
James Smart2e0fef82007-06-17 19:56:36 -05009616 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04009618 "0410 Cannot find virtual addr for mapped buf on "
dea31012005-04-17 16:05:31 -05009619 "ring %d Data x%llx x%p x%p x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04009620 pring->ringno, (unsigned long long)phys,
dea31012005-04-17 16:05:31 -05009621 slp->next, slp->prev, pring->postbufq_cnt);
9622 return NULL;
9623}
9624
James Smarte59058c2008-08-24 21:49:00 -04009625/**
James Smart3621a712009-04-06 18:47:14 -04009626 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
James Smarte59058c2008-08-24 21:49:00 -04009627 * @phba: Pointer to HBA context object.
9628 * @cmdiocb: Pointer to driver command iocb object.
9629 * @rspiocb: Pointer to driver response iocb object.
9630 *
9631 * This function is the completion handler for the abort iocbs for
9632 * ELS commands. This function is called from the ELS ring event
9633 * handler with no lock held. This function frees memory resources
9634 * associated with the abort iocb.
9635 **/
dea31012005-04-17 16:05:31 -05009636static void
James Smart2e0fef82007-06-17 19:56:36 -05009637lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9638 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05009639{
James Smart2e0fef82007-06-17 19:56:36 -05009640 IOCB_t *irsp = &rspiocb->iocb;
James Smart2680eea2007-04-25 09:52:55 -04009641 uint16_t abort_iotag, abort_context;
James Smartff78d8f2011-12-13 13:21:35 -05009642 struct lpfc_iocbq *abort_iocb = NULL;
James Smart2680eea2007-04-25 09:52:55 -04009643
9644 if (irsp->ulpStatus) {
James Smartff78d8f2011-12-13 13:21:35 -05009645
9646 /*
9647 * Assume that the port already completed and returned, or
9648 * will return the iocb. Just Log the message.
9649 */
James Smart2680eea2007-04-25 09:52:55 -04009650 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
9651 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
9652
James Smart2e0fef82007-06-17 19:56:36 -05009653 spin_lock_irq(&phba->hbalock);
James Smart45ed1192009-10-02 15:17:02 -04009654 if (phba->sli_rev < LPFC_SLI_REV4) {
9655 if (abort_iotag != 0 &&
9656 abort_iotag <= phba->sli.last_iotag)
9657 abort_iocb =
9658 phba->sli.iocbq_lookup[abort_iotag];
9659 } else
9660 /* For sli4 the abort_tag is the XRI,
9661 * so the abort routine puts the iotag of the iocb
9662 * being aborted in the context field of the abort
9663 * IOCB.
9664 */
9665 abort_iocb = phba->sli.iocbq_lookup[abort_context];
James Smart2680eea2007-04-25 09:52:55 -04009666
James Smart2a9bf3d2010-06-07 15:24:45 -04009667 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
9668 "0327 Cannot abort els iocb %p "
9669 "with tag %x context %x, abort status %x, "
9670 "abort code %x\n",
9671 abort_iocb, abort_iotag, abort_context,
9672 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart2680eea2007-04-25 09:52:55 -04009673
James Smartff78d8f2011-12-13 13:21:35 -05009674 spin_unlock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04009675 }
James Bottomley604a3e32005-10-29 10:28:33 -05009676 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05009677 return;
9678}
9679
James Smarte59058c2008-08-24 21:49:00 -04009680/**
James Smart3621a712009-04-06 18:47:14 -04009681 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
James Smarte59058c2008-08-24 21:49:00 -04009682 * @phba: Pointer to HBA context object.
9683 * @cmdiocb: Pointer to driver command iocb object.
9684 * @rspiocb: Pointer to driver response iocb object.
9685 *
9686 * The function is called from SLI ring event handler with no
9687 * lock held. This function is the completion handler for ELS commands
9688 * which are aborted. The function frees memory resources used for
9689 * the aborted ELS commands.
9690 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009691static void
9692lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9693 struct lpfc_iocbq *rspiocb)
9694{
9695 IOCB_t *irsp = &rspiocb->iocb;
9696
9697 /* ELS cmd tag <ulpIoTag> completes */
9698 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04009699 "0139 Ignoring ELS cmd tag x%x completion Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05009700 "x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04009701 irsp->ulpIoTag, irsp->ulpStatus,
James Smart92d7f7b2007-06-17 19:56:38 -05009702 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smart858c9f62007-06-17 19:56:39 -05009703 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
9704 lpfc_ct_free_iocb(phba, cmdiocb);
9705 else
9706 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05009707 return;
9708}
9709
James Smarte59058c2008-08-24 21:49:00 -04009710/**
James Smart5af5eee2010-10-22 11:06:38 -04009711 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
James Smarte59058c2008-08-24 21:49:00 -04009712 * @phba: Pointer to HBA context object.
9713 * @pring: Pointer to driver SLI ring object.
9714 * @cmdiocb: Pointer to driver command iocb object.
9715 *
James Smart5af5eee2010-10-22 11:06:38 -04009716 * This function issues an abort iocb for the provided command iocb down to
9717 * the port. Other than the case the outstanding command iocb is an abort
9718 * request, this function issues abort out unconditionally. This function is
9719 * called with hbalock held. The function returns 0 when it fails due to
9720 * memory allocation failure or when the command iocb is an abort request.
James Smarte59058c2008-08-24 21:49:00 -04009721 **/
James Smart5af5eee2010-10-22 11:06:38 -04009722static int
9723lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05009724 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -05009725{
James Smart2e0fef82007-06-17 19:56:36 -05009726 struct lpfc_vport *vport = cmdiocb->vport;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009727 struct lpfc_iocbq *abtsiocbp;
dea31012005-04-17 16:05:31 -05009728 IOCB_t *icmd = NULL;
9729 IOCB_t *iabt = NULL;
James Smart9bd2bff52014-09-03 12:57:30 -04009730 int ring_number;
James Smart5af5eee2010-10-22 11:06:38 -04009731 int retval;
James Smart7e56aa22012-08-03 12:35:34 -04009732 unsigned long iflags;
James Smart07951072007-04-25 09:51:38 -04009733
James Smart92d7f7b2007-06-17 19:56:38 -05009734 /*
9735 * There are certain command types we don't want to abort. And we
9736 * don't want to abort commands that are already in the process of
9737 * being aborted.
James Smart07951072007-04-25 09:51:38 -04009738 */
9739 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05009740 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
James Smart92d7f7b2007-06-17 19:56:38 -05009741 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
9742 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
James Smart07951072007-04-25 09:51:38 -04009743 return 0;
9744
dea31012005-04-17 16:05:31 -05009745 /* issue ABTS for this IOCB based on iotag */
James Smart92d7f7b2007-06-17 19:56:38 -05009746 abtsiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05009747 if (abtsiocbp == NULL)
9748 return 0;
dea31012005-04-17 16:05:31 -05009749
James Smart07951072007-04-25 09:51:38 -04009750 /* This signals the response to set the correct status
James Smart341af102010-01-26 23:07:37 -05009751 * before calling the completion handler
James Smart07951072007-04-25 09:51:38 -04009752 */
9753 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
9754
dea31012005-04-17 16:05:31 -05009755 iabt = &abtsiocbp->iocb;
James Smart07951072007-04-25 09:51:38 -04009756 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
9757 iabt->un.acxri.abortContextTag = icmd->ulpContext;
James Smart45ed1192009-10-02 15:17:02 -04009758 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartda0436e2009-05-22 14:51:39 -04009759 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
James Smart45ed1192009-10-02 15:17:02 -04009760 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
9761 }
James Smartda0436e2009-05-22 14:51:39 -04009762 else
9763 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05009764 iabt->ulpLe = 1;
James Smart07951072007-04-25 09:51:38 -04009765 iabt->ulpClass = icmd->ulpClass;
dea31012005-04-17 16:05:31 -05009766
James Smart5ffc2662009-11-18 15:39:44 -05009767 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9768 abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
James Smart341af102010-01-26 23:07:37 -05009769 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
9770 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
James Smart9bd2bff52014-09-03 12:57:30 -04009771 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
9772 abtsiocbp->iocb_flag |= LPFC_IO_FOF;
James Smart5ffc2662009-11-18 15:39:44 -05009773
James Smart2e0fef82007-06-17 19:56:36 -05009774 if (phba->link_state >= LPFC_LINK_UP)
James Smart07951072007-04-25 09:51:38 -04009775 iabt->ulpCommand = CMD_ABORT_XRI_CN;
9776 else
9777 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
9778
9779 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -04009780
James Smarte8b62012007-08-02 11:10:09 -04009781 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
9782 "0339 Abort xri x%x, original iotag x%x, "
9783 "abort cmd iotag x%x\n",
James Smart2a9bf3d2010-06-07 15:24:45 -04009784 iabt->un.acxri.abortIoTag,
James Smarte8b62012007-08-02 11:10:09 -04009785 iabt->un.acxri.abortContextTag,
James Smart2a9bf3d2010-06-07 15:24:45 -04009786 abtsiocbp->iotag);
James Smart7e56aa22012-08-03 12:35:34 -04009787
9788 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart9bd2bff52014-09-03 12:57:30 -04009789 ring_number =
9790 lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp);
9791 if (unlikely(ring_number == LPFC_HBA_ERROR))
9792 return 0;
9793 pring = &phba->sli.ring[ring_number];
James Smart7e56aa22012-08-03 12:35:34 -04009794 /* Note: both hbalock and ring_lock need to be set here */
9795 spin_lock_irqsave(&pring->ring_lock, iflags);
9796 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
9797 abtsiocbp, 0);
9798 spin_unlock_irqrestore(&pring->ring_lock, iflags);
9799 } else {
9800 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
9801 abtsiocbp, 0);
9802 }
James Smart07951072007-04-25 09:51:38 -04009803
James Smartd7c255b2008-08-24 21:50:00 -04009804 if (retval)
9805 __lpfc_sli_release_iocbq(phba, abtsiocbp);
James Smart5af5eee2010-10-22 11:06:38 -04009806
9807 /*
9808 * Caller to this routine should check for IOCB_ERROR
9809 * and handle it properly. This routine no longer removes
9810 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9811 */
9812 return retval;
9813}
9814
9815/**
9816 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9817 * @phba: Pointer to HBA context object.
9818 * @pring: Pointer to driver SLI ring object.
9819 * @cmdiocb: Pointer to driver command iocb object.
9820 *
9821 * This function issues an abort iocb for the provided command iocb. In case
9822 * of unloading, the abort iocb will not be issued to commands on the ELS
9823 * ring. Instead, the callback function shall be changed to those commands
9824 * so that nothing happens when them finishes. This function is called with
9825 * hbalock held. The function returns 0 when the command iocb is an abort
9826 * request.
9827 **/
9828int
9829lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9830 struct lpfc_iocbq *cmdiocb)
9831{
9832 struct lpfc_vport *vport = cmdiocb->vport;
9833 int retval = IOCB_ERROR;
9834 IOCB_t *icmd = NULL;
9835
9836 /*
9837 * There are certain command types we don't want to abort. And we
9838 * don't want to abort commands that are already in the process of
9839 * being aborted.
9840 */
9841 icmd = &cmdiocb->iocb;
9842 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
9843 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
9844 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
9845 return 0;
9846
9847 /*
9848 * If we're unloading, don't abort iocb on the ELS ring, but change
9849 * the callback so that nothing happens when it finishes.
9850 */
9851 if ((vport->load_flag & FC_UNLOADING) &&
9852 (pring->ringno == LPFC_ELS_RING)) {
9853 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
9854 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
9855 else
9856 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
9857 goto abort_iotag_exit;
9858 }
9859
9860 /* Now, we try to issue the abort to the cmdiocb out */
9861 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
9862
James Smart07951072007-04-25 09:51:38 -04009863abort_iotag_exit:
James Smart2e0fef82007-06-17 19:56:36 -05009864 /*
9865 * Caller to this routine should check for IOCB_ERROR
9866 * and handle it properly. This routine no longer removes
9867 * iocb off txcmplq and call compl in case of IOCB_ERROR.
James Smart07951072007-04-25 09:51:38 -04009868 */
James Smart2e0fef82007-06-17 19:56:36 -05009869 return retval;
dea31012005-04-17 16:05:31 -05009870}
9871
James Smarte59058c2008-08-24 21:49:00 -04009872/**
James Smart5af5eee2010-10-22 11:06:38 -04009873 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9874 * @phba: pointer to lpfc HBA data structure.
9875 *
9876 * This routine will abort all pending and outstanding iocbs to an HBA.
9877 **/
9878void
9879lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
9880{
9881 struct lpfc_sli *psli = &phba->sli;
9882 struct lpfc_sli_ring *pring;
9883 int i;
9884
9885 for (i = 0; i < psli->num_rings; i++) {
9886 pring = &psli->ring[i];
James Smartdb55fba2014-04-04 13:52:02 -04009887 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart5af5eee2010-10-22 11:06:38 -04009888 }
9889}
9890
9891/**
James Smart3621a712009-04-06 18:47:14 -04009892 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
James Smarte59058c2008-08-24 21:49:00 -04009893 * @iocbq: Pointer to driver iocb object.
9894 * @vport: Pointer to driver virtual port object.
9895 * @tgt_id: SCSI ID of the target.
9896 * @lun_id: LUN ID of the scsi device.
9897 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9898 *
James Smart3621a712009-04-06 18:47:14 -04009899 * This function acts as an iocb filter for functions which abort or count
James Smarte59058c2008-08-24 21:49:00 -04009900 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9901 * 0 if the filtering criteria is met for the given iocb and will return
9902 * 1 if the filtering criteria is not met.
9903 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9904 * given iocb is for the SCSI device specified by vport, tgt_id and
9905 * lun_id parameter.
9906 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9907 * given iocb is for the SCSI target specified by vport and tgt_id
9908 * parameters.
9909 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9910 * given iocb is for the SCSI host associated with the given vport.
9911 * This function is called with no locks held.
9912 **/
dea31012005-04-17 16:05:31 -05009913static int
James Smart51ef4c22007-08-02 11:10:31 -04009914lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
9915 uint16_t tgt_id, uint64_t lun_id,
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009916 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05009917{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009918 struct lpfc_scsi_buf *lpfc_cmd;
dea31012005-04-17 16:05:31 -05009919 int rc = 1;
9920
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009921 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
9922 return rc;
9923
James Smart51ef4c22007-08-02 11:10:31 -04009924 if (iocbq->vport != vport)
9925 return rc;
9926
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009927 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009928
James Smart495a7142008-06-14 22:52:59 -04009929 if (lpfc_cmd->pCmd == NULL)
dea31012005-04-17 16:05:31 -05009930 return rc;
9931
9932 switch (ctx_cmd) {
9933 case LPFC_CTX_LUN:
James Smart495a7142008-06-14 22:52:59 -04009934 if ((lpfc_cmd->rdata->pnode) &&
9935 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
9936 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
dea31012005-04-17 16:05:31 -05009937 rc = 0;
9938 break;
9939 case LPFC_CTX_TGT:
James Smart495a7142008-06-14 22:52:59 -04009940 if ((lpfc_cmd->rdata->pnode) &&
9941 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
dea31012005-04-17 16:05:31 -05009942 rc = 0;
9943 break;
dea31012005-04-17 16:05:31 -05009944 case LPFC_CTX_HOST:
9945 rc = 0;
9946 break;
9947 default:
9948 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07009949 __func__, ctx_cmd);
dea31012005-04-17 16:05:31 -05009950 break;
9951 }
9952
9953 return rc;
9954}
9955
James Smarte59058c2008-08-24 21:49:00 -04009956/**
James Smart3621a712009-04-06 18:47:14 -04009957 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
James Smarte59058c2008-08-24 21:49:00 -04009958 * @vport: Pointer to virtual port.
9959 * @tgt_id: SCSI ID of the target.
9960 * @lun_id: LUN ID of the scsi device.
9961 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9962 *
9963 * This function returns number of FCP commands pending for the vport.
9964 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9965 * commands pending on the vport associated with SCSI device specified
9966 * by tgt_id and lun_id parameters.
9967 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9968 * commands pending on the vport associated with SCSI target specified
9969 * by tgt_id parameter.
9970 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9971 * commands pending on the vport.
9972 * This function returns the number of iocbs which satisfy the filter.
9973 * This function is called without any lock held.
9974 **/
dea31012005-04-17 16:05:31 -05009975int
James Smart51ef4c22007-08-02 11:10:31 -04009976lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
9977 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05009978{
James Smart51ef4c22007-08-02 11:10:31 -04009979 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009980 struct lpfc_iocbq *iocbq;
9981 int sum, i;
dea31012005-04-17 16:05:31 -05009982
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009983 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
9984 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05009985
James Smart51ef4c22007-08-02 11:10:31 -04009986 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
9987 ctx_cmd) == 0)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009988 sum++;
dea31012005-04-17 16:05:31 -05009989 }
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04009990
dea31012005-04-17 16:05:31 -05009991 return sum;
9992}
9993
James Smarte59058c2008-08-24 21:49:00 -04009994/**
James Smart3621a712009-04-06 18:47:14 -04009995 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
James Smarte59058c2008-08-24 21:49:00 -04009996 * @phba: Pointer to HBA context object
9997 * @cmdiocb: Pointer to command iocb object.
9998 * @rspiocb: Pointer to response iocb object.
9999 *
10000 * This function is called when an aborted FCP iocb completes. This
10001 * function is called by the ring event handler with no lock held.
10002 * This function frees the iocb.
10003 **/
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -040010004void
James Smart2e0fef82007-06-17 19:56:36 -050010005lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10006 struct lpfc_iocbq *rspiocb)
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -040010007{
James Smartcb69f7d2011-12-13 13:21:57 -050010008 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart8e668af2013-05-31 17:04:28 -040010009 "3096 ABORT_XRI_CN completing on rpi x%x "
James Smartcb69f7d2011-12-13 13:21:57 -050010010 "original iotag x%x, abort cmd iotag x%x "
10011 "status 0x%x, reason 0x%x\n",
10012 cmdiocb->iocb.un.acxri.abortContextTag,
10013 cmdiocb->iocb.un.acxri.abortIoTag,
10014 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
10015 rspiocb->iocb.un.ulpWord[4]);
James Bottomley604a3e32005-10-29 10:28:33 -050010016 lpfc_sli_release_iocbq(phba, cmdiocb);
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -040010017 return;
10018}
10019
James Smarte59058c2008-08-24 21:49:00 -040010020/**
James Smart3621a712009-04-06 18:47:14 -040010021 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
James Smarte59058c2008-08-24 21:49:00 -040010022 * @vport: Pointer to virtual port.
10023 * @pring: Pointer to driver SLI ring object.
10024 * @tgt_id: SCSI ID of the target.
10025 * @lun_id: LUN ID of the scsi device.
10026 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10027 *
10028 * This function sends an abort command for every SCSI command
10029 * associated with the given virtual port pending on the ring
10030 * filtered by lpfc_sli_validate_fcp_iocb function.
10031 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
10032 * FCP iocbs associated with lun specified by tgt_id and lun_id
10033 * parameters
10034 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
10035 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10036 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
10037 * FCP iocbs associated with virtual port.
10038 * This function returns number of iocbs it failed to abort.
10039 * This function is called with no locks held.
10040 **/
dea31012005-04-17 16:05:31 -050010041int
James Smart51ef4c22007-08-02 11:10:31 -040010042lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
10043 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
dea31012005-04-17 16:05:31 -050010044{
James Smart51ef4c22007-08-02 11:10:31 -040010045 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040010046 struct lpfc_iocbq *iocbq;
10047 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -050010048 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -050010049 int errcnt = 0, ret_val = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040010050 int i;
dea31012005-04-17 16:05:31 -050010051
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040010052 for (i = 1; i <= phba->sli.last_iotag; i++) {
10053 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -050010054
James Smart51ef4c22007-08-02 11:10:31 -040010055 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
James Smart2e0fef82007-06-17 19:56:36 -050010056 abort_cmd) != 0)
dea31012005-04-17 16:05:31 -050010057 continue;
10058
James Smartafbd8d82013-09-06 12:22:13 -040010059 /*
10060 * If the iocbq is already being aborted, don't take a second
10061 * action, but do count it.
10062 */
10063 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
10064 continue;
10065
dea31012005-04-17 16:05:31 -050010066 /* issue ABTS for this IOCB based on iotag */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040010067 abtsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -050010068 if (abtsiocb == NULL) {
10069 errcnt++;
10070 continue;
10071 }
dea31012005-04-17 16:05:31 -050010072
James Smartafbd8d82013-09-06 12:22:13 -040010073 /* indicate the IO is being aborted by the driver. */
10074 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
10075
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040010076 cmd = &iocbq->iocb;
dea31012005-04-17 16:05:31 -050010077 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
10078 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
James Smartda0436e2009-05-22 14:51:39 -040010079 if (phba->sli_rev == LPFC_SLI_REV4)
10080 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
10081 else
10082 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
dea31012005-04-17 16:05:31 -050010083 abtsiocb->iocb.ulpLe = 1;
10084 abtsiocb->iocb.ulpClass = cmd->ulpClass;
James Smartafbd8d82013-09-06 12:22:13 -040010085 abtsiocb->vport = vport;
dea31012005-04-17 16:05:31 -050010086
James Smart5ffc2662009-11-18 15:39:44 -050010087 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10088 abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
James Smart341af102010-01-26 23:07:37 -050010089 if (iocbq->iocb_flag & LPFC_IO_FCP)
10090 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
James Smart9bd2bff52014-09-03 12:57:30 -040010091 if (iocbq->iocb_flag & LPFC_IO_FOF)
10092 abtsiocb->iocb_flag |= LPFC_IO_FOF;
James Smart5ffc2662009-11-18 15:39:44 -050010093
James Smart2e0fef82007-06-17 19:56:36 -050010094 if (lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -050010095 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
10096 else
10097 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
10098
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -040010099 /* Setup callback routine and issue the command. */
10100 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
James Smartda0436e2009-05-22 14:51:39 -040010101 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
10102 abtsiocb, 0);
dea31012005-04-17 16:05:31 -050010103 if (ret_val == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -050010104 lpfc_sli_release_iocbq(phba, abtsiocb);
dea31012005-04-17 16:05:31 -050010105 errcnt++;
10106 continue;
10107 }
10108 }
10109
10110 return errcnt;
10111}
10112
James Smarte59058c2008-08-24 21:49:00 -040010113/**
James Smart98912dda2014-04-04 13:52:31 -040010114 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
10115 * @vport: Pointer to virtual port.
10116 * @pring: Pointer to driver SLI ring object.
10117 * @tgt_id: SCSI ID of the target.
10118 * @lun_id: LUN ID of the scsi device.
10119 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10120 *
10121 * This function sends an abort command for every SCSI command
10122 * associated with the given virtual port pending on the ring
10123 * filtered by lpfc_sli_validate_fcp_iocb function.
10124 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
10125 * FCP iocbs associated with lun specified by tgt_id and lun_id
10126 * parameters
10127 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
10128 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10129 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
10130 * FCP iocbs associated with virtual port.
10131 * This function returns number of iocbs it aborted .
10132 * This function is called with no locks held right after a taskmgmt
10133 * command is sent.
10134 **/
10135int
10136lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
10137 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
10138{
10139 struct lpfc_hba *phba = vport->phba;
10140 struct lpfc_iocbq *abtsiocbq;
10141 struct lpfc_iocbq *iocbq;
10142 IOCB_t *icmd;
10143 int sum, i, ret_val;
10144 unsigned long iflags;
10145 struct lpfc_sli_ring *pring_s4;
10146 uint32_t ring_number;
10147
10148 spin_lock_irq(&phba->hbalock);
10149
10150 /* all I/Os are in process of being flushed */
10151 if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
10152 spin_unlock_irq(&phba->hbalock);
10153 return 0;
10154 }
10155 sum = 0;
10156
10157 for (i = 1; i <= phba->sli.last_iotag; i++) {
10158 iocbq = phba->sli.iocbq_lookup[i];
10159
10160 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
10161 cmd) != 0)
10162 continue;
10163
10164 /*
10165 * If the iocbq is already being aborted, don't take a second
10166 * action, but do count it.
10167 */
10168 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
10169 continue;
10170
10171 /* issue ABTS for this IOCB based on iotag */
10172 abtsiocbq = __lpfc_sli_get_iocbq(phba);
10173 if (abtsiocbq == NULL)
10174 continue;
10175
10176 icmd = &iocbq->iocb;
10177 abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
10178 abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
10179 if (phba->sli_rev == LPFC_SLI_REV4)
10180 abtsiocbq->iocb.un.acxri.abortIoTag =
10181 iocbq->sli4_xritag;
10182 else
10183 abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
10184 abtsiocbq->iocb.ulpLe = 1;
10185 abtsiocbq->iocb.ulpClass = icmd->ulpClass;
10186 abtsiocbq->vport = vport;
10187
10188 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10189 abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx;
10190 if (iocbq->iocb_flag & LPFC_IO_FCP)
10191 abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
James Smart9bd2bff52014-09-03 12:57:30 -040010192 if (iocbq->iocb_flag & LPFC_IO_FOF)
10193 abtsiocbq->iocb_flag |= LPFC_IO_FOF;
James Smart98912dda2014-04-04 13:52:31 -040010194
10195 if (lpfc_is_link_up(phba))
10196 abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
10197 else
10198 abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
10199
10200 /* Setup callback routine and issue the command. */
10201 abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
10202
10203 /*
10204 * Indicate the IO is being aborted by the driver and set
10205 * the caller's flag into the aborted IO.
10206 */
10207 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
10208
10209 if (phba->sli_rev == LPFC_SLI_REV4) {
10210 ring_number = MAX_SLI3_CONFIGURED_RINGS +
10211 iocbq->fcp_wqidx;
10212 pring_s4 = &phba->sli.ring[ring_number];
10213 /* Note: both hbalock and ring_lock must be set here */
10214 spin_lock_irqsave(&pring_s4->ring_lock, iflags);
10215 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
10216 abtsiocbq, 0);
10217 spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
10218 } else {
10219 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
10220 abtsiocbq, 0);
10221 }
10222
10223
10224 if (ret_val == IOCB_ERROR)
10225 __lpfc_sli_release_iocbq(phba, abtsiocbq);
10226 else
10227 sum++;
10228 }
10229 spin_unlock_irq(&phba->hbalock);
10230 return sum;
10231}
10232
10233/**
James Smart3621a712009-04-06 18:47:14 -040010234 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
James Smarte59058c2008-08-24 21:49:00 -040010235 * @phba: Pointer to HBA context object.
10236 * @cmdiocbq: Pointer to command iocb.
10237 * @rspiocbq: Pointer to response iocb.
10238 *
10239 * This function is the completion handler for iocbs issued using
10240 * lpfc_sli_issue_iocb_wait function. This function is called by the
10241 * ring event handler function without any lock held. This function
10242 * can be called from both worker thread context and interrupt
10243 * context. This function also can be called from other thread which
10244 * cleans up the SLI layer objects.
10245 * This function copy the contents of the response iocb to the
10246 * response iocb memory object provided by the caller of
10247 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
10248 * sleeps for the iocb completion.
10249 **/
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010250static void
10251lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
10252 struct lpfc_iocbq *cmdiocbq,
10253 struct lpfc_iocbq *rspiocbq)
dea31012005-04-17 16:05:31 -050010254{
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010255 wait_queue_head_t *pdone_q;
10256 unsigned long iflags;
James Smart0f65ff62010-02-26 14:14:23 -050010257 struct lpfc_scsi_buf *lpfc_cmd;
dea31012005-04-17 16:05:31 -050010258
James Smart2e0fef82007-06-17 19:56:36 -050010259 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart5a0916b2013-07-15 18:31:42 -040010260 if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
10261
10262 /*
10263 * A time out has occurred for the iocb. If a time out
10264 * completion handler has been supplied, call it. Otherwise,
10265 * just free the iocbq.
10266 */
10267
10268 spin_unlock_irqrestore(&phba->hbalock, iflags);
10269 cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
10270 cmdiocbq->wait_iocb_cmpl = NULL;
10271 if (cmdiocbq->iocb_cmpl)
10272 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
10273 else
10274 lpfc_sli_release_iocbq(phba, cmdiocbq);
10275 return;
10276 }
10277
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010278 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
10279 if (cmdiocbq->context2 && rspiocbq)
10280 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
10281 &rspiocbq->iocb, sizeof(IOCB_t));
10282
James Smart0f65ff62010-02-26 14:14:23 -050010283 /* Set the exchange busy flag for task management commands */
10284 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
10285 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
10286 lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
10287 cur_iocbq);
10288 lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
10289 }
10290
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010291 pdone_q = cmdiocbq->context_un.wait_queue;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010292 if (pdone_q)
10293 wake_up(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -050010294 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -050010295 return;
10296}
10297
James Smarte59058c2008-08-24 21:49:00 -040010298/**
James Smartd11e31d2009-06-10 17:23:06 -040010299 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
10300 * @phba: Pointer to HBA context object..
10301 * @piocbq: Pointer to command iocb.
10302 * @flag: Flag to test.
10303 *
10304 * This routine grabs the hbalock and then test the iocb_flag to
10305 * see if the passed in flag is set.
10306 * Returns:
10307 * 1 if flag is set.
10308 * 0 if flag is not set.
10309 **/
10310static int
10311lpfc_chk_iocb_flg(struct lpfc_hba *phba,
10312 struct lpfc_iocbq *piocbq, uint32_t flag)
10313{
10314 unsigned long iflags;
10315 int ret;
10316
10317 spin_lock_irqsave(&phba->hbalock, iflags);
10318 ret = piocbq->iocb_flag & flag;
10319 spin_unlock_irqrestore(&phba->hbalock, iflags);
10320 return ret;
10321
10322}
10323
10324/**
James Smart3621a712009-04-06 18:47:14 -040010325 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
James Smarte59058c2008-08-24 21:49:00 -040010326 * @phba: Pointer to HBA context object..
10327 * @pring: Pointer to sli ring.
10328 * @piocb: Pointer to command iocb.
10329 * @prspiocbq: Pointer to response iocb.
10330 * @timeout: Timeout in number of seconds.
10331 *
10332 * This function issues the iocb to firmware and waits for the
James Smart5a0916b2013-07-15 18:31:42 -040010333 * iocb to complete. The iocb_cmpl field of the shall be used
10334 * to handle iocbs which time out. If the field is NULL, the
10335 * function shall free the iocbq structure. If more clean up is
10336 * needed, the caller is expected to provide a completion function
10337 * that will provide the needed clean up. If the iocb command is
10338 * not completed within timeout seconds, the function will either
10339 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
10340 * completion function set in the iocb_cmpl field and then return
10341 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
10342 * resources if this function returns IOCB_TIMEDOUT.
James Smarte59058c2008-08-24 21:49:00 -040010343 * The function waits for the iocb completion using an
10344 * non-interruptible wait.
10345 * This function will sleep while waiting for iocb completion.
10346 * So, this function should not be called from any context which
10347 * does not allow sleeping. Due to the same reason, this function
10348 * cannot be called with interrupt disabled.
10349 * This function assumes that the iocb completions occur while
10350 * this function sleep. So, this function cannot be called from
10351 * the thread which process iocb completion for this ring.
10352 * This function clears the iocb_flag of the iocb object before
10353 * issuing the iocb and the iocb completion handler sets this
10354 * flag and wakes this thread when the iocb completes.
10355 * The contents of the response iocb will be copied to prspiocbq
10356 * by the completion handler when the command completes.
10357 * This function returns IOCB_SUCCESS when success.
10358 * This function is called with no lock held.
10359 **/
dea31012005-04-17 16:05:31 -050010360int
James Smart2e0fef82007-06-17 19:56:36 -050010361lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
James Smartda0436e2009-05-22 14:51:39 -040010362 uint32_t ring_number,
James Smart2e0fef82007-06-17 19:56:36 -050010363 struct lpfc_iocbq *piocb,
10364 struct lpfc_iocbq *prspiocbq,
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010365 uint32_t timeout)
dea31012005-04-17 16:05:31 -050010366{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -080010367 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010368 long timeleft, timeout_req = 0;
10369 int retval = IOCB_SUCCESS;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -050010370 uint32_t creg_val;
James Smart0e9bb8d2013-03-01 16:35:12 -050010371 struct lpfc_iocbq *iocb;
10372 int txq_cnt = 0;
10373 int txcmplq_cnt = 0;
James Smart2a9bf3d2010-06-07 15:24:45 -040010374 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart5a0916b2013-07-15 18:31:42 -040010375 unsigned long iflags;
10376 bool iocb_completed = true;
10377
dea31012005-04-17 16:05:31 -050010378 /*
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010379 * If the caller has provided a response iocbq buffer, then context2
10380 * is NULL or its an error.
dea31012005-04-17 16:05:31 -050010381 */
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010382 if (prspiocbq) {
10383 if (piocb->context2)
10384 return IOCB_ERROR;
10385 piocb->context2 = prspiocbq;
dea31012005-04-17 16:05:31 -050010386 }
10387
James Smart5a0916b2013-07-15 18:31:42 -040010388 piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010389 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
10390 piocb->context_un.wait_queue = &done_q;
James Smart5a0916b2013-07-15 18:31:42 -040010391 piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
dea31012005-04-17 16:05:31 -050010392
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -050010393 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
James Smart9940b972011-03-11 16:06:12 -050010394 if (lpfc_readl(phba->HCregaddr, &creg_val))
10395 return IOCB_ERROR;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -050010396 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
10397 writel(creg_val, phba->HCregaddr);
10398 readl(phba->HCregaddr); /* flush */
10399 }
10400
James Smart2a9bf3d2010-06-07 15:24:45 -040010401 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
10402 SLI_IOCB_RET_IOCB);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010403 if (retval == IOCB_SUCCESS) {
James Smart256ec0d2013-04-17 20:14:58 -040010404 timeout_req = msecs_to_jiffies(timeout * 1000);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010405 timeleft = wait_event_timeout(done_q,
James Smartd11e31d2009-06-10 17:23:06 -040010406 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010407 timeout_req);
James Smart5a0916b2013-07-15 18:31:42 -040010408 spin_lock_irqsave(&phba->hbalock, iflags);
10409 if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
dea31012005-04-17 16:05:31 -050010410
James Smart5a0916b2013-07-15 18:31:42 -040010411 /*
10412 * IOCB timed out. Inform the wake iocb wait
10413 * completion function and set local status
10414 */
10415
10416 iocb_completed = false;
10417 piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
10418 }
10419 spin_unlock_irqrestore(&phba->hbalock, iflags);
10420 if (iocb_completed) {
James Smart7054a602007-04-25 09:52:34 -040010421 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -040010422 "0331 IOCB wake signaled\n");
James Smart53151bb2013-10-10 12:24:07 -040010423 /* Note: we are not indicating if the IOCB has a success
10424 * status or not - that's for the caller to check.
10425 * IOCB_SUCCESS means just that the command was sent and
10426 * completed. Not that it completed successfully.
10427 * */
James Smart7054a602007-04-25 09:52:34 -040010428 } else if (timeleft == 0) {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010429 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -040010430 "0338 IOCB wait timeout error - no "
10431 "wake response Data x%x\n", timeout);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010432 retval = IOCB_TIMEDOUT;
James Smart7054a602007-04-25 09:52:34 -040010433 } else {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010434 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -040010435 "0330 IOCB wake NOT set, "
10436 "Data x%x x%lx\n",
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010437 timeout, (timeleft / jiffies));
10438 retval = IOCB_TIMEDOUT;
dea31012005-04-17 16:05:31 -050010439 }
James Smart2a9bf3d2010-06-07 15:24:45 -040010440 } else if (retval == IOCB_BUSY) {
James Smart0e9bb8d2013-03-01 16:35:12 -050010441 if (phba->cfg_log_verbose & LOG_SLI) {
10442 list_for_each_entry(iocb, &pring->txq, list) {
10443 txq_cnt++;
10444 }
10445 list_for_each_entry(iocb, &pring->txcmplq, list) {
10446 txcmplq_cnt++;
10447 }
10448 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10449 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
10450 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
10451 }
James Smart2a9bf3d2010-06-07 15:24:45 -040010452 return retval;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010453 } else {
10454 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartd7c255b2008-08-24 21:50:00 -040010455 "0332 IOCB wait issue failed, Data x%x\n",
James Smarte8b62012007-08-02 11:10:09 -040010456 retval);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010457 retval = IOCB_ERROR;
dea31012005-04-17 16:05:31 -050010458 }
10459
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -050010460 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
James Smart9940b972011-03-11 16:06:12 -050010461 if (lpfc_readl(phba->HCregaddr, &creg_val))
10462 return IOCB_ERROR;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -050010463 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
10464 writel(creg_val, phba->HCregaddr);
10465 readl(phba->HCregaddr); /* flush */
10466 }
10467
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010468 if (prspiocbq)
10469 piocb->context2 = NULL;
10470
10471 piocb->context_un.wait_queue = NULL;
10472 piocb->iocb_cmpl = NULL;
dea31012005-04-17 16:05:31 -050010473 return retval;
10474}
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -040010475
James Smarte59058c2008-08-24 21:49:00 -040010476/**
James Smart3621a712009-04-06 18:47:14 -040010477 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
James Smarte59058c2008-08-24 21:49:00 -040010478 * @phba: Pointer to HBA context object.
10479 * @pmboxq: Pointer to driver mailbox object.
10480 * @timeout: Timeout in number of seconds.
10481 *
10482 * This function issues the mailbox to firmware and waits for the
10483 * mailbox command to complete. If the mailbox command is not
10484 * completed within timeout seconds, it returns MBX_TIMEOUT.
10485 * The function waits for the mailbox completion using an
10486 * interruptible wait. If the thread is woken up due to a
10487 * signal, MBX_TIMEOUT error is returned to the caller. Caller
10488 * should not free the mailbox resources, if this function returns
10489 * MBX_TIMEOUT.
10490 * This function will sleep while waiting for mailbox completion.
10491 * So, this function should not be called from any context which
10492 * does not allow sleeping. Due to the same reason, this function
10493 * cannot be called with interrupt disabled.
10494 * This function assumes that the mailbox completion occurs while
10495 * this function sleep. So, this function cannot be called from
10496 * the worker thread which processes mailbox completion.
10497 * This function is called in the context of HBA management
10498 * applications.
10499 * This function returns MBX_SUCCESS when successful.
10500 * This function is called with no lock held.
10501 **/
dea31012005-04-17 16:05:31 -050010502int
James Smart2e0fef82007-06-17 19:56:36 -050010503lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
dea31012005-04-17 16:05:31 -050010504 uint32_t timeout)
10505{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -080010506 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
James Smartb230b8a2013-05-31 17:05:27 -040010507 MAILBOX_t *mb = NULL;
dea31012005-04-17 16:05:31 -050010508 int retval;
James Smart858c9f62007-06-17 19:56:39 -050010509 unsigned long flag;
dea31012005-04-17 16:05:31 -050010510
James Smartb230b8a2013-05-31 17:05:27 -040010511 /* The caller might set context1 for extended buffer */
James Smart98c9ea52007-10-27 13:37:33 -040010512 if (pmboxq->context1)
James Smartb230b8a2013-05-31 17:05:27 -040010513 mb = (MAILBOX_t *)pmboxq->context1;
dea31012005-04-17 16:05:31 -050010514
James Smart495a7142008-06-14 22:52:59 -040010515 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
dea31012005-04-17 16:05:31 -050010516 /* setup wake call as IOCB callback */
10517 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
10518 /* setup context field to pass wait_queue pointer to wake function */
10519 pmboxq->context1 = &done_q;
10520
dea31012005-04-17 16:05:31 -050010521 /* now issue the command */
10522 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -050010523 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
James Smart7054a602007-04-25 09:52:34 -040010524 wait_event_interruptible_timeout(done_q,
10525 pmboxq->mbox_flag & LPFC_MBX_WAKE,
James Smart256ec0d2013-04-17 20:14:58 -040010526 msecs_to_jiffies(timeout * 1000));
James Smart7054a602007-04-25 09:52:34 -040010527
James Smart858c9f62007-06-17 19:56:39 -050010528 spin_lock_irqsave(&phba->hbalock, flag);
James Smartb230b8a2013-05-31 17:05:27 -040010529 /* restore the possible extended buffer for free resource */
10530 pmboxq->context1 = (uint8_t *)mb;
James Smart7054a602007-04-25 09:52:34 -040010531 /*
10532 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10533 * else do not free the resources.
10534 */
James Smartd7c47992010-06-08 18:31:54 -040010535 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
dea31012005-04-17 16:05:31 -050010536 retval = MBX_SUCCESS;
James Smartd7c47992010-06-08 18:31:54 -040010537 } else {
James Smart7054a602007-04-25 09:52:34 -040010538 retval = MBX_TIMEOUT;
James Smart858c9f62007-06-17 19:56:39 -050010539 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10540 }
10541 spin_unlock_irqrestore(&phba->hbalock, flag);
James Smartb230b8a2013-05-31 17:05:27 -040010542 } else {
10543 /* restore the possible extended buffer for free resource */
10544 pmboxq->context1 = (uint8_t *)mb;
dea31012005-04-17 16:05:31 -050010545 }
10546
dea31012005-04-17 16:05:31 -050010547 return retval;
10548}
10549
James Smarte59058c2008-08-24 21:49:00 -040010550/**
James Smart3772a992009-05-22 14:50:54 -040010551 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
James Smarte59058c2008-08-24 21:49:00 -040010552 * @phba: Pointer to HBA context.
10553 *
James Smart3772a992009-05-22 14:50:54 -040010554 * This function is called to shutdown the driver's mailbox sub-system.
10555 * It first marks the mailbox sub-system is in a block state to prevent
10556 * the asynchronous mailbox command from issued off the pending mailbox
10557 * command queue. If the mailbox command sub-system shutdown is due to
10558 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10559 * the mailbox sub-system flush routine to forcefully bring down the
10560 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10561 * as with offline or HBA function reset), this routine will wait for the
10562 * outstanding mailbox command to complete before invoking the mailbox
10563 * sub-system flush routine to gracefully bring down mailbox sub-system.
James Smarte59058c2008-08-24 21:49:00 -040010564 **/
James Smart3772a992009-05-22 14:50:54 -040010565void
James Smart618a5232012-06-12 13:54:36 -040010566lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
James Smartb4c02652006-07-06 15:50:43 -040010567{
James Smart3772a992009-05-22 14:50:54 -040010568 struct lpfc_sli *psli = &phba->sli;
James Smart3772a992009-05-22 14:50:54 -040010569 unsigned long timeout;
10570
James Smart618a5232012-06-12 13:54:36 -040010571 if (mbx_action == LPFC_MBX_NO_WAIT) {
10572 /* delay 100ms for port state */
10573 msleep(100);
10574 lpfc_sli_mbox_sys_flush(phba);
10575 return;
10576 }
James Smarta183a152011-10-10 21:32:43 -040010577 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
James Smartd7069f02012-03-01 22:36:29 -050010578
James Smart3772a992009-05-22 14:50:54 -040010579 spin_lock_irq(&phba->hbalock);
10580 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
James Smart3772a992009-05-22 14:50:54 -040010581
10582 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
James Smart3772a992009-05-22 14:50:54 -040010583 /* Determine how long we might wait for the active mailbox
10584 * command to be gracefully completed by firmware.
10585 */
James Smarta183a152011-10-10 21:32:43 -040010586 if (phba->sli.mbox_active)
10587 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
10588 phba->sli.mbox_active) *
10589 1000) + jiffies;
10590 spin_unlock_irq(&phba->hbalock);
10591
James Smart3772a992009-05-22 14:50:54 -040010592 while (phba->sli.mbox_active) {
10593 /* Check active mailbox complete status every 2ms */
10594 msleep(2);
10595 if (time_after(jiffies, timeout))
10596 /* Timeout, let the mailbox flush routine to
10597 * forcefully release active mailbox command
10598 */
10599 break;
10600 }
James Smartd7069f02012-03-01 22:36:29 -050010601 } else
10602 spin_unlock_irq(&phba->hbalock);
10603
James Smart3772a992009-05-22 14:50:54 -040010604 lpfc_sli_mbox_sys_flush(phba);
10605}
10606
10607/**
10608 * lpfc_sli_eratt_read - read sli-3 error attention events
10609 * @phba: Pointer to HBA context.
10610 *
10611 * This function is called to read the SLI3 device error attention registers
10612 * for possible error attention events. The caller must hold the hostlock
10613 * with spin_lock_irq().
10614 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010615 * This function returns 1 when there is Error Attention in the Host Attention
James Smart3772a992009-05-22 14:50:54 -040010616 * Register and returns 0 otherwise.
10617 **/
10618static int
10619lpfc_sli_eratt_read(struct lpfc_hba *phba)
10620{
James Smarted957682007-06-17 19:56:37 -050010621 uint32_t ha_copy;
James Smartb4c02652006-07-06 15:50:43 -040010622
James Smart3772a992009-05-22 14:50:54 -040010623 /* Read chip Host Attention (HA) register */
James Smart9940b972011-03-11 16:06:12 -050010624 if (lpfc_readl(phba->HAregaddr, &ha_copy))
10625 goto unplug_err;
10626
James Smart3772a992009-05-22 14:50:54 -040010627 if (ha_copy & HA_ERATT) {
10628 /* Read host status register to retrieve error event */
James Smart9940b972011-03-11 16:06:12 -050010629 if (lpfc_sli_read_hs(phba))
10630 goto unplug_err;
James Smartb4c02652006-07-06 15:50:43 -040010631
James Smart3772a992009-05-22 14:50:54 -040010632 /* Check if there is a deferred error condition is active */
10633 if ((HS_FFER1 & phba->work_hs) &&
10634 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
James Smartdcf2a4e2010-09-29 11:18:53 -040010635 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
James Smart3772a992009-05-22 14:50:54 -040010636 phba->hba_flag |= DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -040010637 /* Clear all interrupt enable conditions */
10638 writel(0, phba->HCregaddr);
10639 readl(phba->HCregaddr);
10640 }
10641
10642 /* Set the driver HA work bitmap */
James Smart3772a992009-05-22 14:50:54 -040010643 phba->work_ha |= HA_ERATT;
10644 /* Indicate polling handles this ERATT */
10645 phba->hba_flag |= HBA_ERATT_HANDLED;
James Smart3772a992009-05-22 14:50:54 -040010646 return 1;
James Smartb4c02652006-07-06 15:50:43 -040010647 }
James Smart3772a992009-05-22 14:50:54 -040010648 return 0;
James Smart9940b972011-03-11 16:06:12 -050010649
10650unplug_err:
10651 /* Set the driver HS work bitmap */
10652 phba->work_hs |= UNPLUG_ERR;
10653 /* Set the driver HA work bitmap */
10654 phba->work_ha |= HA_ERATT;
10655 /* Indicate polling handles this ERATT */
10656 phba->hba_flag |= HBA_ERATT_HANDLED;
10657 return 1;
James Smartb4c02652006-07-06 15:50:43 -040010658}
10659
James Smarte59058c2008-08-24 21:49:00 -040010660/**
James Smartda0436e2009-05-22 14:51:39 -040010661 * lpfc_sli4_eratt_read - read sli-4 error attention events
10662 * @phba: Pointer to HBA context.
10663 *
10664 * This function is called to read the SLI4 device error attention registers
10665 * for possible error attention events. The caller must hold the hostlock
10666 * with spin_lock_irq().
10667 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010668 * This function returns 1 when there is Error Attention in the Host Attention
James Smartda0436e2009-05-22 14:51:39 -040010669 * Register and returns 0 otherwise.
10670 **/
10671static int
10672lpfc_sli4_eratt_read(struct lpfc_hba *phba)
10673{
10674 uint32_t uerr_sta_hi, uerr_sta_lo;
James Smart2fcee4b2010-12-15 17:57:46 -050010675 uint32_t if_type, portsmphr;
10676 struct lpfc_register portstat_reg;
James Smartda0436e2009-05-22 14:51:39 -040010677
James Smart2fcee4b2010-12-15 17:57:46 -050010678 /*
10679 * For now, use the SLI4 device internal unrecoverable error
James Smartda0436e2009-05-22 14:51:39 -040010680 * registers for error attention. This can be changed later.
10681 */
James Smart2fcee4b2010-12-15 17:57:46 -050010682 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10683 switch (if_type) {
10684 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart9940b972011-03-11 16:06:12 -050010685 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
10686 &uerr_sta_lo) ||
10687 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
10688 &uerr_sta_hi)) {
10689 phba->work_hs |= UNPLUG_ERR;
10690 phba->work_ha |= HA_ERATT;
10691 phba->hba_flag |= HBA_ERATT_HANDLED;
10692 return 1;
10693 }
James Smart2fcee4b2010-12-15 17:57:46 -050010694 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
10695 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
10696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10697 "1423 HBA Unrecoverable error: "
10698 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10699 "ue_mask_lo_reg=0x%x, "
10700 "ue_mask_hi_reg=0x%x\n",
10701 uerr_sta_lo, uerr_sta_hi,
10702 phba->sli4_hba.ue_mask_lo,
10703 phba->sli4_hba.ue_mask_hi);
10704 phba->work_status[0] = uerr_sta_lo;
10705 phba->work_status[1] = uerr_sta_hi;
10706 phba->work_ha |= HA_ERATT;
10707 phba->hba_flag |= HBA_ERATT_HANDLED;
10708 return 1;
10709 }
10710 break;
10711 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart9940b972011-03-11 16:06:12 -050010712 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
10713 &portstat_reg.word0) ||
10714 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
10715 &portsmphr)){
10716 phba->work_hs |= UNPLUG_ERR;
10717 phba->work_ha |= HA_ERATT;
10718 phba->hba_flag |= HBA_ERATT_HANDLED;
10719 return 1;
10720 }
James Smart2fcee4b2010-12-15 17:57:46 -050010721 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
10722 phba->work_status[0] =
10723 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
10724 phba->work_status[1] =
10725 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
10726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2e90f4b2011-12-13 13:22:37 -050010727 "2885 Port Status Event: "
James Smart2fcee4b2010-12-15 17:57:46 -050010728 "port status reg 0x%x, "
10729 "port smphr reg 0x%x, "
10730 "error 1=0x%x, error 2=0x%x\n",
10731 portstat_reg.word0,
10732 portsmphr,
10733 phba->work_status[0],
10734 phba->work_status[1]);
10735 phba->work_ha |= HA_ERATT;
10736 phba->hba_flag |= HBA_ERATT_HANDLED;
10737 return 1;
10738 }
10739 break;
10740 case LPFC_SLI_INTF_IF_TYPE_1:
10741 default:
James Smarta747c9c2009-11-18 15:41:10 -050010742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -050010743 "2886 HBA Error Attention on unsupported "
10744 "if type %d.", if_type);
James Smarta747c9c2009-11-18 15:41:10 -050010745 return 1;
James Smartda0436e2009-05-22 14:51:39 -040010746 }
James Smart2fcee4b2010-12-15 17:57:46 -050010747
James Smartda0436e2009-05-22 14:51:39 -040010748 return 0;
10749}
10750
10751/**
James Smart3621a712009-04-06 18:47:14 -040010752 * lpfc_sli_check_eratt - check error attention events
James Smart93996272008-08-24 21:50:30 -040010753 * @phba: Pointer to HBA context.
10754 *
James Smart3772a992009-05-22 14:50:54 -040010755 * This function is called from timer soft interrupt context to check HBA's
James Smart93996272008-08-24 21:50:30 -040010756 * error attention register bit for error attention events.
10757 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010758 * This function returns 1 when there is Error Attention in the Host Attention
James Smart93996272008-08-24 21:50:30 -040010759 * Register and returns 0 otherwise.
10760 **/
10761int
10762lpfc_sli_check_eratt(struct lpfc_hba *phba)
10763{
10764 uint32_t ha_copy;
10765
10766 /* If somebody is waiting to handle an eratt, don't process it
10767 * here. The brdkill function will do this.
10768 */
10769 if (phba->link_flag & LS_IGNORE_ERATT)
10770 return 0;
10771
10772 /* Check if interrupt handler handles this ERATT */
10773 spin_lock_irq(&phba->hbalock);
10774 if (phba->hba_flag & HBA_ERATT_HANDLED) {
10775 /* Interrupt handler has handled ERATT */
10776 spin_unlock_irq(&phba->hbalock);
10777 return 0;
10778 }
10779
James Smarta257bf92009-04-06 18:48:10 -040010780 /*
10781 * If there is deferred error attention, do not check for error
10782 * attention
10783 */
10784 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
10785 spin_unlock_irq(&phba->hbalock);
10786 return 0;
10787 }
10788
James Smart3772a992009-05-22 14:50:54 -040010789 /* If PCI channel is offline, don't process it */
10790 if (unlikely(pci_channel_offline(phba->pcidev))) {
James Smart93996272008-08-24 21:50:30 -040010791 spin_unlock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010792 return 0;
10793 }
10794
10795 switch (phba->sli_rev) {
10796 case LPFC_SLI_REV2:
10797 case LPFC_SLI_REV3:
10798 /* Read chip Host Attention (HA) register */
10799 ha_copy = lpfc_sli_eratt_read(phba);
10800 break;
James Smartda0436e2009-05-22 14:51:39 -040010801 case LPFC_SLI_REV4:
James Smart2fcee4b2010-12-15 17:57:46 -050010802 /* Read device Uncoverable Error (UERR) registers */
James Smartda0436e2009-05-22 14:51:39 -040010803 ha_copy = lpfc_sli4_eratt_read(phba);
10804 break;
James Smart3772a992009-05-22 14:50:54 -040010805 default:
10806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10807 "0299 Invalid SLI revision (%d)\n",
10808 phba->sli_rev);
10809 ha_copy = 0;
10810 break;
James Smart93996272008-08-24 21:50:30 -040010811 }
10812 spin_unlock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010813
10814 return ha_copy;
10815}
10816
10817/**
10818 * lpfc_intr_state_check - Check device state for interrupt handling
10819 * @phba: Pointer to HBA context.
10820 *
10821 * This inline routine checks whether a device or its PCI slot is in a state
10822 * that the interrupt should be handled.
10823 *
10824 * This function returns 0 if the device or the PCI slot is in a state that
10825 * interrupt should be handled, otherwise -EIO.
10826 */
10827static inline int
10828lpfc_intr_state_check(struct lpfc_hba *phba)
10829{
10830 /* If the pci channel is offline, ignore all the interrupts */
10831 if (unlikely(pci_channel_offline(phba->pcidev)))
10832 return -EIO;
10833
10834 /* Update device level interrupt statistics */
10835 phba->sli.slistat.sli_intr++;
10836
10837 /* Ignore all interrupts during initialization. */
10838 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
10839 return -EIO;
10840
James Smart93996272008-08-24 21:50:30 -040010841 return 0;
10842}
10843
10844/**
James Smart3772a992009-05-22 14:50:54 -040010845 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
James Smarte59058c2008-08-24 21:49:00 -040010846 * @irq: Interrupt number.
10847 * @dev_id: The device context pointer.
10848 *
James Smart93996272008-08-24 21:50:30 -040010849 * This function is directly called from the PCI layer as an interrupt
James Smart3772a992009-05-22 14:50:54 -040010850 * service routine when device with SLI-3 interface spec is enabled with
10851 * MSI-X multi-message interrupt mode and there are slow-path events in
10852 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10853 * interrupt mode, this function is called as part of the device-level
10854 * interrupt handler. When the PCI slot is in error recovery or the HBA
10855 * is undergoing initialization, the interrupt handler will not process
10856 * the interrupt. The link attention and ELS ring attention events are
10857 * handled by the worker thread. The interrupt handler signals the worker
10858 * thread and returns for these events. This function is called without
10859 * any lock held. It gets the hbalock to access and update SLI data
James Smart93996272008-08-24 21:50:30 -040010860 * structures.
10861 *
10862 * This function returns IRQ_HANDLED when interrupt is handled else it
10863 * returns IRQ_NONE.
James Smarte59058c2008-08-24 21:49:00 -040010864 **/
dea31012005-04-17 16:05:31 -050010865irqreturn_t
James Smart3772a992009-05-22 14:50:54 -040010866lpfc_sli_sp_intr_handler(int irq, void *dev_id)
dea31012005-04-17 16:05:31 -050010867{
James Smart2e0fef82007-06-17 19:56:36 -050010868 struct lpfc_hba *phba;
James Smarta747c9c2009-11-18 15:41:10 -050010869 uint32_t ha_copy, hc_copy;
dea31012005-04-17 16:05:31 -050010870 uint32_t work_ha_copy;
10871 unsigned long status;
James Smart5b75da22008-12-04 22:39:35 -050010872 unsigned long iflag;
dea31012005-04-17 16:05:31 -050010873 uint32_t control;
10874
James Smart92d7f7b2007-06-17 19:56:38 -050010875 MAILBOX_t *mbox, *pmbox;
James Smart858c9f62007-06-17 19:56:39 -050010876 struct lpfc_vport *vport;
10877 struct lpfc_nodelist *ndlp;
10878 struct lpfc_dmabuf *mp;
James Smart92d7f7b2007-06-17 19:56:38 -050010879 LPFC_MBOXQ_t *pmb;
10880 int rc;
10881
dea31012005-04-17 16:05:31 -050010882 /*
10883 * Get the driver's phba structure from the dev_id and
10884 * assume the HBA is not interrupting.
10885 */
James Smart93996272008-08-24 21:50:30 -040010886 phba = (struct lpfc_hba *)dev_id;
dea31012005-04-17 16:05:31 -050010887
10888 if (unlikely(!phba))
10889 return IRQ_NONE;
10890
dea31012005-04-17 16:05:31 -050010891 /*
James Smart93996272008-08-24 21:50:30 -040010892 * Stuff needs to be attented to when this function is invoked as an
10893 * individual interrupt handler in MSI-X multi-message interrupt mode
dea31012005-04-17 16:05:31 -050010894 */
James Smart93996272008-08-24 21:50:30 -040010895 if (phba->intr_type == MSIX) {
James Smart3772a992009-05-22 14:50:54 -040010896 /* Check device state for handling interrupt */
10897 if (lpfc_intr_state_check(phba))
James Smart93996272008-08-24 21:50:30 -040010898 return IRQ_NONE;
10899 /* Need to read HA REG for slow-path events */
James Smart5b75da22008-12-04 22:39:35 -050010900 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart9940b972011-03-11 16:06:12 -050010901 if (lpfc_readl(phba->HAregaddr, &ha_copy))
10902 goto unplug_error;
James Smart93996272008-08-24 21:50:30 -040010903 /* If somebody is waiting to handle an eratt don't process it
10904 * here. The brdkill function will do this.
10905 */
10906 if (phba->link_flag & LS_IGNORE_ERATT)
10907 ha_copy &= ~HA_ERATT;
10908 /* Check the need for handling ERATT in interrupt handler */
10909 if (ha_copy & HA_ERATT) {
10910 if (phba->hba_flag & HBA_ERATT_HANDLED)
10911 /* ERATT polling has handled ERATT */
10912 ha_copy &= ~HA_ERATT;
10913 else
10914 /* Indicate interrupt handler handles ERATT */
10915 phba->hba_flag |= HBA_ERATT_HANDLED;
10916 }
James Smarta257bf92009-04-06 18:48:10 -040010917
10918 /*
10919 * If there is deferred error attention, do not check for any
10920 * interrupt.
10921 */
10922 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
James Smart3772a992009-05-22 14:50:54 -040010923 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta257bf92009-04-06 18:48:10 -040010924 return IRQ_NONE;
10925 }
10926
James Smart93996272008-08-24 21:50:30 -040010927 /* Clear up only attention source related to slow-path */
James Smart9940b972011-03-11 16:06:12 -050010928 if (lpfc_readl(phba->HCregaddr, &hc_copy))
10929 goto unplug_error;
10930
James Smarta747c9c2009-11-18 15:41:10 -050010931 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
10932 HC_LAINT_ENA | HC_ERINT_ENA),
10933 phba->HCregaddr);
James Smart93996272008-08-24 21:50:30 -040010934 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
10935 phba->HAregaddr);
James Smarta747c9c2009-11-18 15:41:10 -050010936 writel(hc_copy, phba->HCregaddr);
James Smart93996272008-08-24 21:50:30 -040010937 readl(phba->HAregaddr); /* flush */
James Smart5b75da22008-12-04 22:39:35 -050010938 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart93996272008-08-24 21:50:30 -040010939 } else
10940 ha_copy = phba->ha_copy;
dea31012005-04-17 16:05:31 -050010941
dea31012005-04-17 16:05:31 -050010942 work_ha_copy = ha_copy & phba->work_ha_mask;
10943
James Smart93996272008-08-24 21:50:30 -040010944 if (work_ha_copy) {
dea31012005-04-17 16:05:31 -050010945 if (work_ha_copy & HA_LATT) {
10946 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
10947 /*
10948 * Turn off Link Attention interrupts
10949 * until CLEAR_LA done
10950 */
James Smart5b75da22008-12-04 22:39:35 -050010951 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -050010952 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
James Smart9940b972011-03-11 16:06:12 -050010953 if (lpfc_readl(phba->HCregaddr, &control))
10954 goto unplug_error;
dea31012005-04-17 16:05:31 -050010955 control &= ~HC_LAINT_ENA;
10956 writel(control, phba->HCregaddr);
10957 readl(phba->HCregaddr); /* flush */
James Smart5b75da22008-12-04 22:39:35 -050010958 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -050010959 }
10960 else
10961 work_ha_copy &= ~HA_LATT;
10962 }
10963
James Smart93996272008-08-24 21:50:30 -040010964 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
James Smart858c9f62007-06-17 19:56:39 -050010965 /*
10966 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10967 * the only slow ring.
10968 */
10969 status = (work_ha_copy &
10970 (HA_RXMASK << (4*LPFC_ELS_RING)));
10971 status >>= (4*LPFC_ELS_RING);
10972 if (status & HA_RXMASK) {
James Smart5b75da22008-12-04 22:39:35 -050010973 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart9940b972011-03-11 16:06:12 -050010974 if (lpfc_readl(phba->HCregaddr, &control))
10975 goto unplug_error;
James Smarta58cbd52007-08-02 11:09:43 -040010976
10977 lpfc_debugfs_slow_ring_trc(phba,
10978 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10979 control, status,
10980 (uint32_t)phba->sli.slistat.sli_intr);
10981
James Smart858c9f62007-06-17 19:56:39 -050010982 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
James Smarta58cbd52007-08-02 11:09:43 -040010983 lpfc_debugfs_slow_ring_trc(phba,
10984 "ISR Disable ring:"
10985 "pwork:x%x hawork:x%x wait:x%x",
10986 phba->work_ha, work_ha_copy,
10987 (uint32_t)((unsigned long)
James Smart5e9d9b82008-06-14 22:52:53 -040010988 &phba->work_waitq));
James Smarta58cbd52007-08-02 11:09:43 -040010989
James Smart858c9f62007-06-17 19:56:39 -050010990 control &=
10991 ~(HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -050010992 writel(control, phba->HCregaddr);
10993 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -050010994 }
James Smarta58cbd52007-08-02 11:09:43 -040010995 else {
10996 lpfc_debugfs_slow_ring_trc(phba,
10997 "ISR slow ring: pwork:"
10998 "x%x hawork:x%x wait:x%x",
10999 phba->work_ha, work_ha_copy,
11000 (uint32_t)((unsigned long)
James Smart5e9d9b82008-06-14 22:52:53 -040011001 &phba->work_waitq));
James Smarta58cbd52007-08-02 11:09:43 -040011002 }
James Smart5b75da22008-12-04 22:39:35 -050011003 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -050011004 }
11005 }
James Smart5b75da22008-12-04 22:39:35 -050011006 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta257bf92009-04-06 18:48:10 -040011007 if (work_ha_copy & HA_ERATT) {
James Smart9940b972011-03-11 16:06:12 -050011008 if (lpfc_sli_read_hs(phba))
11009 goto unplug_error;
James Smarta257bf92009-04-06 18:48:10 -040011010 /*
11011 * Check if there is a deferred error condition
11012 * is active
11013 */
11014 if ((HS_FFER1 & phba->work_hs) &&
11015 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
James Smartdcf2a4e2010-09-29 11:18:53 -040011016 HS_FFER6 | HS_FFER7 | HS_FFER8) &
11017 phba->work_hs)) {
James Smarta257bf92009-04-06 18:48:10 -040011018 phba->hba_flag |= DEFER_ERATT;
11019 /* Clear all interrupt enable conditions */
11020 writel(0, phba->HCregaddr);
11021 readl(phba->HCregaddr);
11022 }
11023 }
11024
James Smart93996272008-08-24 21:50:30 -040011025 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
James Smart92d7f7b2007-06-17 19:56:38 -050011026 pmb = phba->sli.mbox_active;
James Smart04c68492009-05-22 14:52:52 -040011027 pmbox = &pmb->u.mb;
James Smart34b02dc2008-08-24 21:49:55 -040011028 mbox = phba->mbox;
James Smart858c9f62007-06-17 19:56:39 -050011029 vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -050011030
11031 /* First check out the status word */
11032 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
11033 if (pmbox->mbxOwner != OWN_HOST) {
James Smart5b75da22008-12-04 22:39:35 -050011034 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -050011035 /*
11036 * Stray Mailbox Interrupt, mbxCommand <cmd>
11037 * mbxStatus <status>
11038 */
James Smart09372822008-01-11 01:52:54 -050011039 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
James Smart92d7f7b2007-06-17 19:56:38 -050011040 LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -040011041 "(%d):0304 Stray Mailbox "
James Smart92d7f7b2007-06-17 19:56:38 -050011042 "Interrupt mbxCommand x%x "
11043 "mbxStatus x%x\n",
James Smarte8b62012007-08-02 11:10:09 -040011044 (vport ? vport->vpi : 0),
James Smart92d7f7b2007-06-17 19:56:38 -050011045 pmbox->mbxCommand,
11046 pmbox->mbxStatus);
James Smart09372822008-01-11 01:52:54 -050011047 /* clear mailbox attention bit */
11048 work_ha_copy &= ~HA_MBATT;
11049 } else {
James Smart97eab632008-04-07 10:16:05 -040011050 phba->sli.mbox_active = NULL;
James Smart5b75da22008-12-04 22:39:35 -050011051 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart09372822008-01-11 01:52:54 -050011052 phba->last_completion_time = jiffies;
11053 del_timer(&phba->sli.mbox_tmo);
James Smart09372822008-01-11 01:52:54 -050011054 if (pmb->mbox_cmpl) {
11055 lpfc_sli_pcimem_bcopy(mbox, pmbox,
11056 MAILBOX_CMD_SIZE);
James Smart7a470272010-03-15 11:25:20 -040011057 if (pmb->out_ext_byte_len &&
11058 pmb->context2)
11059 lpfc_sli_pcimem_bcopy(
11060 phba->mbox_ext,
11061 pmb->context2,
11062 pmb->out_ext_byte_len);
James Smart858c9f62007-06-17 19:56:39 -050011063 }
James Smart09372822008-01-11 01:52:54 -050011064 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
11065 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
11066
11067 lpfc_debugfs_disc_trc(vport,
11068 LPFC_DISC_TRC_MBOX_VPORT,
11069 "MBOX dflt rpi: : "
11070 "status:x%x rpi:x%x",
11071 (uint32_t)pmbox->mbxStatus,
11072 pmbox->un.varWords[0], 0);
11073
11074 if (!pmbox->mbxStatus) {
11075 mp = (struct lpfc_dmabuf *)
11076 (pmb->context1);
11077 ndlp = (struct lpfc_nodelist *)
11078 pmb->context2;
11079
11080 /* Reg_LOGIN of dflt RPI was
11081 * successful. new lets get
11082 * rid of the RPI using the
11083 * same mbox buffer.
11084 */
11085 lpfc_unreg_login(phba,
11086 vport->vpi,
11087 pmbox->un.varWords[0],
11088 pmb);
11089 pmb->mbox_cmpl =
11090 lpfc_mbx_cmpl_dflt_rpi;
11091 pmb->context1 = mp;
11092 pmb->context2 = ndlp;
11093 pmb->vport = vport;
James Smart58da1ff2008-04-07 10:15:56 -040011094 rc = lpfc_sli_issue_mbox(phba,
11095 pmb,
11096 MBX_NOWAIT);
11097 if (rc != MBX_BUSY)
11098 lpfc_printf_log(phba,
11099 KERN_ERR,
11100 LOG_MBOX | LOG_SLI,
James Smartd7c255b2008-08-24 21:50:00 -040011101 "0350 rc should have"
James Smart6a9c52c2009-10-02 15:16:51 -040011102 "been MBX_BUSY\n");
James Smart3772a992009-05-22 14:50:54 -040011103 if (rc != MBX_NOT_FINISHED)
11104 goto send_current_mbox;
James Smart09372822008-01-11 01:52:54 -050011105 }
11106 }
James Smart5b75da22008-12-04 22:39:35 -050011107 spin_lock_irqsave(
11108 &phba->pport->work_port_lock,
11109 iflag);
James Smart09372822008-01-11 01:52:54 -050011110 phba->pport->work_port_events &=
11111 ~WORKER_MBOX_TMO;
James Smart5b75da22008-12-04 22:39:35 -050011112 spin_unlock_irqrestore(
11113 &phba->pport->work_port_lock,
11114 iflag);
James Smart09372822008-01-11 01:52:54 -050011115 lpfc_mbox_cmpl_put(phba, pmb);
James Smart858c9f62007-06-17 19:56:39 -050011116 }
James Smart97eab632008-04-07 10:16:05 -040011117 } else
James Smart5b75da22008-12-04 22:39:35 -050011118 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart93996272008-08-24 21:50:30 -040011119
James Smart92d7f7b2007-06-17 19:56:38 -050011120 if ((work_ha_copy & HA_MBATT) &&
11121 (phba->sli.mbox_active == NULL)) {
James Smart858c9f62007-06-17 19:56:39 -050011122send_current_mbox:
James Smart92d7f7b2007-06-17 19:56:38 -050011123 /* Process next mailbox command if there is one */
James Smart58da1ff2008-04-07 10:15:56 -040011124 do {
11125 rc = lpfc_sli_issue_mbox(phba, NULL,
11126 MBX_NOWAIT);
11127 } while (rc == MBX_NOT_FINISHED);
11128 if (rc != MBX_SUCCESS)
11129 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
11130 LOG_SLI, "0349 rc should be "
James Smart6a9c52c2009-10-02 15:16:51 -040011131 "MBX_SUCCESS\n");
James Smart92d7f7b2007-06-17 19:56:38 -050011132 }
11133
James Smart5b75da22008-12-04 22:39:35 -050011134 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -050011135 phba->work_ha |= work_ha_copy;
James Smart5b75da22008-12-04 22:39:35 -050011136 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -040011137 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -050011138 }
James Smart93996272008-08-24 21:50:30 -040011139 return IRQ_HANDLED;
James Smart9940b972011-03-11 16:06:12 -050011140unplug_error:
11141 spin_unlock_irqrestore(&phba->hbalock, iflag);
11142 return IRQ_HANDLED;
dea31012005-04-17 16:05:31 -050011143
James Smart3772a992009-05-22 14:50:54 -040011144} /* lpfc_sli_sp_intr_handler */
James Smart93996272008-08-24 21:50:30 -040011145
11146/**
James Smart3772a992009-05-22 14:50:54 -040011147 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
James Smart93996272008-08-24 21:50:30 -040011148 * @irq: Interrupt number.
11149 * @dev_id: The device context pointer.
11150 *
11151 * This function is directly called from the PCI layer as an interrupt
James Smart3772a992009-05-22 14:50:54 -040011152 * service routine when device with SLI-3 interface spec is enabled with
11153 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11154 * ring event in the HBA. However, when the device is enabled with either
11155 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11156 * device-level interrupt handler. When the PCI slot is in error recovery
11157 * or the HBA is undergoing initialization, the interrupt handler will not
11158 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11159 * the intrrupt context. This function is called without any lock held.
11160 * It gets the hbalock to access and update SLI data structures.
James Smart93996272008-08-24 21:50:30 -040011161 *
11162 * This function returns IRQ_HANDLED when interrupt is handled else it
11163 * returns IRQ_NONE.
11164 **/
11165irqreturn_t
James Smart3772a992009-05-22 14:50:54 -040011166lpfc_sli_fp_intr_handler(int irq, void *dev_id)
James Smart93996272008-08-24 21:50:30 -040011167{
11168 struct lpfc_hba *phba;
11169 uint32_t ha_copy;
11170 unsigned long status;
James Smart5b75da22008-12-04 22:39:35 -050011171 unsigned long iflag;
James Smart93996272008-08-24 21:50:30 -040011172
11173 /* Get the driver's phba structure from the dev_id and
11174 * assume the HBA is not interrupting.
11175 */
11176 phba = (struct lpfc_hba *) dev_id;
11177
11178 if (unlikely(!phba))
11179 return IRQ_NONE;
dea31012005-04-17 16:05:31 -050011180
11181 /*
James Smart93996272008-08-24 21:50:30 -040011182 * Stuff needs to be attented to when this function is invoked as an
11183 * individual interrupt handler in MSI-X multi-message interrupt mode
dea31012005-04-17 16:05:31 -050011184 */
James Smart93996272008-08-24 21:50:30 -040011185 if (phba->intr_type == MSIX) {
James Smart3772a992009-05-22 14:50:54 -040011186 /* Check device state for handling interrupt */
11187 if (lpfc_intr_state_check(phba))
James Smart93996272008-08-24 21:50:30 -040011188 return IRQ_NONE;
11189 /* Need to read HA REG for FCP ring and other ring events */
James Smart9940b972011-03-11 16:06:12 -050011190 if (lpfc_readl(phba->HAregaddr, &ha_copy))
11191 return IRQ_HANDLED;
James Smart93996272008-08-24 21:50:30 -040011192 /* Clear up only attention source related to fast-path */
James Smart5b75da22008-12-04 22:39:35 -050011193 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta257bf92009-04-06 18:48:10 -040011194 /*
11195 * If there is deferred error attention, do not check for
11196 * any interrupt.
11197 */
11198 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
James Smart3772a992009-05-22 14:50:54 -040011199 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta257bf92009-04-06 18:48:10 -040011200 return IRQ_NONE;
11201 }
James Smart93996272008-08-24 21:50:30 -040011202 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
11203 phba->HAregaddr);
11204 readl(phba->HAregaddr); /* flush */
James Smart5b75da22008-12-04 22:39:35 -050011205 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart93996272008-08-24 21:50:30 -040011206 } else
11207 ha_copy = phba->ha_copy;
11208
11209 /*
11210 * Process all events on FCP ring. Take the optimized path for FCP IO.
11211 */
11212 ha_copy &= ~(phba->work_ha_mask);
11213
11214 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
dea31012005-04-17 16:05:31 -050011215 status >>= (4*LPFC_FCP_RING);
James Smart858c9f62007-06-17 19:56:39 -050011216 if (status & HA_RXMASK)
dea31012005-04-17 16:05:31 -050011217 lpfc_sli_handle_fast_ring_event(phba,
11218 &phba->sli.ring[LPFC_FCP_RING],
11219 status);
James Smarta4bc3372006-12-02 13:34:16 -050011220
11221 if (phba->cfg_multi_ring_support == 2) {
11222 /*
James Smart93996272008-08-24 21:50:30 -040011223 * Process all events on extra ring. Take the optimized path
11224 * for extra ring IO.
James Smarta4bc3372006-12-02 13:34:16 -050011225 */
James Smart93996272008-08-24 21:50:30 -040011226 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
James Smarta4bc3372006-12-02 13:34:16 -050011227 status >>= (4*LPFC_EXTRA_RING);
James Smart858c9f62007-06-17 19:56:39 -050011228 if (status & HA_RXMASK) {
James Smarta4bc3372006-12-02 13:34:16 -050011229 lpfc_sli_handle_fast_ring_event(phba,
11230 &phba->sli.ring[LPFC_EXTRA_RING],
11231 status);
11232 }
11233 }
dea31012005-04-17 16:05:31 -050011234 return IRQ_HANDLED;
James Smart3772a992009-05-22 14:50:54 -040011235} /* lpfc_sli_fp_intr_handler */
dea31012005-04-17 16:05:31 -050011236
James Smart93996272008-08-24 21:50:30 -040011237/**
James Smart3772a992009-05-22 14:50:54 -040011238 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
James Smart93996272008-08-24 21:50:30 -040011239 * @irq: Interrupt number.
11240 * @dev_id: The device context pointer.
11241 *
James Smart3772a992009-05-22 14:50:54 -040011242 * This function is the HBA device-level interrupt handler to device with
11243 * SLI-3 interface spec, called from the PCI layer when either MSI or
11244 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
11245 * requires driver attention. This function invokes the slow-path interrupt
11246 * attention handling function and fast-path interrupt attention handling
11247 * function in turn to process the relevant HBA attention events. This
11248 * function is called without any lock held. It gets the hbalock to access
11249 * and update SLI data structures.
James Smart93996272008-08-24 21:50:30 -040011250 *
11251 * This function returns IRQ_HANDLED when interrupt is handled, else it
11252 * returns IRQ_NONE.
11253 **/
11254irqreturn_t
James Smart3772a992009-05-22 14:50:54 -040011255lpfc_sli_intr_handler(int irq, void *dev_id)
James Smart93996272008-08-24 21:50:30 -040011256{
11257 struct lpfc_hba *phba;
11258 irqreturn_t sp_irq_rc, fp_irq_rc;
11259 unsigned long status1, status2;
James Smarta747c9c2009-11-18 15:41:10 -050011260 uint32_t hc_copy;
James Smart93996272008-08-24 21:50:30 -040011261
11262 /*
11263 * Get the driver's phba structure from the dev_id and
11264 * assume the HBA is not interrupting.
11265 */
11266 phba = (struct lpfc_hba *) dev_id;
11267
11268 if (unlikely(!phba))
11269 return IRQ_NONE;
11270
James Smart3772a992009-05-22 14:50:54 -040011271 /* Check device state for handling interrupt */
11272 if (lpfc_intr_state_check(phba))
James Smart93996272008-08-24 21:50:30 -040011273 return IRQ_NONE;
11274
11275 spin_lock(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -050011276 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
11277 spin_unlock(&phba->hbalock);
11278 return IRQ_HANDLED;
11279 }
11280
James Smart93996272008-08-24 21:50:30 -040011281 if (unlikely(!phba->ha_copy)) {
11282 spin_unlock(&phba->hbalock);
11283 return IRQ_NONE;
11284 } else if (phba->ha_copy & HA_ERATT) {
11285 if (phba->hba_flag & HBA_ERATT_HANDLED)
11286 /* ERATT polling has handled ERATT */
11287 phba->ha_copy &= ~HA_ERATT;
11288 else
11289 /* Indicate interrupt handler handles ERATT */
11290 phba->hba_flag |= HBA_ERATT_HANDLED;
11291 }
11292
James Smarta257bf92009-04-06 18:48:10 -040011293 /*
11294 * If there is deferred error attention, do not check for any interrupt.
11295 */
11296 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
Dan Carpenterec21b3b2010-08-08 00:15:17 +020011297 spin_unlock(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -040011298 return IRQ_NONE;
11299 }
11300
James Smart93996272008-08-24 21:50:30 -040011301 /* Clear attention sources except link and error attentions */
James Smart9940b972011-03-11 16:06:12 -050011302 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
11303 spin_unlock(&phba->hbalock);
11304 return IRQ_HANDLED;
11305 }
James Smarta747c9c2009-11-18 15:41:10 -050011306 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
11307 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
11308 phba->HCregaddr);
James Smart93996272008-08-24 21:50:30 -040011309 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
James Smarta747c9c2009-11-18 15:41:10 -050011310 writel(hc_copy, phba->HCregaddr);
James Smart93996272008-08-24 21:50:30 -040011311 readl(phba->HAregaddr); /* flush */
11312 spin_unlock(&phba->hbalock);
11313
11314 /*
11315 * Invokes slow-path host attention interrupt handling as appropriate.
11316 */
11317
11318 /* status of events with mailbox and link attention */
11319 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
11320
11321 /* status of events with ELS ring */
11322 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
11323 status2 >>= (4*LPFC_ELS_RING);
11324
11325 if (status1 || (status2 & HA_RXMASK))
James Smart3772a992009-05-22 14:50:54 -040011326 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
James Smart93996272008-08-24 21:50:30 -040011327 else
11328 sp_irq_rc = IRQ_NONE;
11329
11330 /*
11331 * Invoke fast-path host attention interrupt handling as appropriate.
11332 */
11333
11334 /* status of events with FCP ring */
11335 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
11336 status1 >>= (4*LPFC_FCP_RING);
11337
11338 /* status of events with extra ring */
11339 if (phba->cfg_multi_ring_support == 2) {
11340 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
11341 status2 >>= (4*LPFC_EXTRA_RING);
11342 } else
11343 status2 = 0;
11344
11345 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
James Smart3772a992009-05-22 14:50:54 -040011346 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
James Smart93996272008-08-24 21:50:30 -040011347 else
11348 fp_irq_rc = IRQ_NONE;
11349
11350 /* Return device-level interrupt handling status */
11351 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
James Smart3772a992009-05-22 14:50:54 -040011352} /* lpfc_sli_intr_handler */
James Smart4f774512009-05-22 14:52:35 -040011353
11354/**
11355 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
11356 * @phba: pointer to lpfc hba data structure.
11357 *
11358 * This routine is invoked by the worker thread to process all the pending
11359 * SLI4 FCP abort XRI events.
11360 **/
11361void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
11362{
11363 struct lpfc_cq_event *cq_event;
11364
11365 /* First, declare the fcp xri abort event has been handled */
11366 spin_lock_irq(&phba->hbalock);
11367 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
11368 spin_unlock_irq(&phba->hbalock);
11369 /* Now, handle all the fcp xri abort events */
11370 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
11371 /* Get the first event from the head of the event queue */
11372 spin_lock_irq(&phba->hbalock);
11373 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
11374 cq_event, struct lpfc_cq_event, list);
11375 spin_unlock_irq(&phba->hbalock);
11376 /* Notify aborted XRI for FCP work queue */
11377 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
11378 /* Free the event processed back to the free pool */
11379 lpfc_sli4_cq_event_release(phba, cq_event);
11380 }
11381}
11382
11383/**
11384 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
11385 * @phba: pointer to lpfc hba data structure.
11386 *
11387 * This routine is invoked by the worker thread to process all the pending
11388 * SLI4 els abort xri events.
11389 **/
11390void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
11391{
11392 struct lpfc_cq_event *cq_event;
11393
11394 /* First, declare the els xri abort event has been handled */
11395 spin_lock_irq(&phba->hbalock);
11396 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
11397 spin_unlock_irq(&phba->hbalock);
11398 /* Now, handle all the els xri abort events */
11399 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
11400 /* Get the first event from the head of the event queue */
11401 spin_lock_irq(&phba->hbalock);
11402 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
11403 cq_event, struct lpfc_cq_event, list);
11404 spin_unlock_irq(&phba->hbalock);
11405 /* Notify aborted XRI for ELS work queue */
11406 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
11407 /* Free the event processed back to the free pool */
11408 lpfc_sli4_cq_event_release(phba, cq_event);
11409 }
11410}
11411
James Smart341af102010-01-26 23:07:37 -050011412/**
11413 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
11414 * @phba: pointer to lpfc hba data structure
11415 * @pIocbIn: pointer to the rspiocbq
11416 * @pIocbOut: pointer to the cmdiocbq
11417 * @wcqe: pointer to the complete wcqe
11418 *
11419 * This routine transfers the fields of a command iocbq to a response iocbq
11420 * by copying all the IOCB fields from command iocbq and transferring the
11421 * completion status information from the complete wcqe.
11422 **/
James Smart4f774512009-05-22 14:52:35 -040011423static void
James Smart341af102010-01-26 23:07:37 -050011424lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
11425 struct lpfc_iocbq *pIocbIn,
James Smart4f774512009-05-22 14:52:35 -040011426 struct lpfc_iocbq *pIocbOut,
11427 struct lpfc_wcqe_complete *wcqe)
11428{
James Smartaf227412013-10-10 12:23:10 -040011429 int numBdes, i;
James Smart341af102010-01-26 23:07:37 -050011430 unsigned long iflags;
James Smartaf227412013-10-10 12:23:10 -040011431 uint32_t status, max_response;
11432 struct lpfc_dmabuf *dmabuf;
11433 struct ulp_bde64 *bpl, bde;
James Smart4f774512009-05-22 14:52:35 -040011434 size_t offset = offsetof(struct lpfc_iocbq, iocb);
11435
11436 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
11437 sizeof(struct lpfc_iocbq) - offset);
James Smart4f774512009-05-22 14:52:35 -040011438 /* Map WCQE parameters into irspiocb parameters */
James Smartacd68592012-01-18 16:25:09 -050011439 status = bf_get(lpfc_wcqe_c_status, wcqe);
11440 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
James Smart4f774512009-05-22 14:52:35 -040011441 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
11442 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
11443 pIocbIn->iocb.un.fcpi.fcpi_parm =
11444 pIocbOut->iocb.un.fcpi.fcpi_parm -
11445 wcqe->total_data_placed;
11446 else
11447 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
James Smart695a8142010-01-26 23:08:03 -050011448 else {
James Smart4f774512009-05-22 14:52:35 -040011449 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
James Smartaf227412013-10-10 12:23:10 -040011450 switch (pIocbOut->iocb.ulpCommand) {
11451 case CMD_ELS_REQUEST64_CR:
11452 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
11453 bpl = (struct ulp_bde64 *)dmabuf->virt;
11454 bde.tus.w = le32_to_cpu(bpl[1].tus.w);
11455 max_response = bde.tus.f.bdeSize;
11456 break;
11457 case CMD_GEN_REQUEST64_CR:
11458 max_response = 0;
11459 if (!pIocbOut->context3)
11460 break;
11461 numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
11462 sizeof(struct ulp_bde64);
11463 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
11464 bpl = (struct ulp_bde64 *)dmabuf->virt;
11465 for (i = 0; i < numBdes; i++) {
11466 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
11467 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
11468 max_response += bde.tus.f.bdeSize;
11469 }
11470 break;
11471 default:
11472 max_response = wcqe->total_data_placed;
11473 break;
11474 }
11475 if (max_response < wcqe->total_data_placed)
11476 pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
11477 else
11478 pIocbIn->iocb.un.genreq64.bdl.bdeSize =
11479 wcqe->total_data_placed;
James Smart695a8142010-01-26 23:08:03 -050011480 }
James Smart341af102010-01-26 23:07:37 -050011481
James Smartacd68592012-01-18 16:25:09 -050011482 /* Convert BG errors for completion status */
11483 if (status == CQE_STATUS_DI_ERROR) {
11484 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
11485
11486 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
11487 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
11488 else
11489 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
11490
11491 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
11492 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
11493 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
11494 BGS_GUARD_ERR_MASK;
11495 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
11496 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
11497 BGS_APPTAG_ERR_MASK;
11498 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
11499 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
11500 BGS_REFTAG_ERR_MASK;
11501
11502 /* Check to see if there was any good data before the error */
11503 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
11504 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
11505 BGS_HI_WATER_MARK_PRESENT_MASK;
11506 pIocbIn->iocb.unsli3.sli3_bg.bghm =
11507 wcqe->total_data_placed;
11508 }
11509
11510 /*
11511 * Set ALL the error bits to indicate we don't know what
11512 * type of error it is.
11513 */
11514 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
11515 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
11516 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
11517 BGS_GUARD_ERR_MASK);
11518 }
11519
James Smart341af102010-01-26 23:07:37 -050011520 /* Pick up HBA exchange busy condition */
11521 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
11522 spin_lock_irqsave(&phba->hbalock, iflags);
11523 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
11524 spin_unlock_irqrestore(&phba->hbalock, iflags);
11525 }
James Smart4f774512009-05-22 14:52:35 -040011526}
11527
11528/**
James Smart45ed1192009-10-02 15:17:02 -040011529 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11530 * @phba: Pointer to HBA context object.
11531 * @wcqe: Pointer to work-queue completion queue entry.
11532 *
11533 * This routine handles an ELS work-queue completion event and construct
11534 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11535 * discovery engine to handle.
11536 *
11537 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11538 **/
11539static struct lpfc_iocbq *
11540lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
11541 struct lpfc_iocbq *irspiocbq)
11542{
11543 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
11544 struct lpfc_iocbq *cmdiocbq;
11545 struct lpfc_wcqe_complete *wcqe;
11546 unsigned long iflags;
11547
11548 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
James Smart7e56aa22012-08-03 12:35:34 -040011549 spin_lock_irqsave(&pring->ring_lock, iflags);
James Smart45ed1192009-10-02 15:17:02 -040011550 pring->stats.iocb_event++;
11551 /* Look up the ELS command IOCB and create pseudo response IOCB */
11552 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
11553 bf_get(lpfc_wcqe_c_request_tag, wcqe));
James Smart7e56aa22012-08-03 12:35:34 -040011554 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smart45ed1192009-10-02 15:17:02 -040011555
11556 if (unlikely(!cmdiocbq)) {
11557 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11558 "0386 ELS complete with no corresponding "
11559 "cmdiocb: iotag (%d)\n",
11560 bf_get(lpfc_wcqe_c_request_tag, wcqe));
11561 lpfc_sli_release_iocbq(phba, irspiocbq);
11562 return NULL;
11563 }
11564
11565 /* Fake the irspiocbq and copy necessary response information */
James Smart341af102010-01-26 23:07:37 -050011566 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
James Smart45ed1192009-10-02 15:17:02 -040011567
11568 return irspiocbq;
11569}
11570
11571/**
James Smart04c68492009-05-22 14:52:52 -040011572 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11573 * @phba: Pointer to HBA context object.
11574 * @cqe: Pointer to mailbox completion queue entry.
11575 *
11576 * This routine process a mailbox completion queue entry with asynchrous
11577 * event.
11578 *
11579 * Return: true if work posted to worker thread, otherwise false.
11580 **/
11581static bool
11582lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
11583{
11584 struct lpfc_cq_event *cq_event;
11585 unsigned long iflags;
11586
11587 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11588 "0392 Async Event: word0:x%x, word1:x%x, "
11589 "word2:x%x, word3:x%x\n", mcqe->word0,
11590 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
11591
11592 /* Allocate a new internal CQ_EVENT entry */
11593 cq_event = lpfc_sli4_cq_event_alloc(phba);
11594 if (!cq_event) {
11595 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11596 "0394 Failed to allocate CQ_EVENT entry\n");
11597 return false;
11598 }
11599
11600 /* Move the CQE into an asynchronous event entry */
11601 memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
11602 spin_lock_irqsave(&phba->hbalock, iflags);
11603 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
11604 /* Set the async event flag */
11605 phba->hba_flag |= ASYNC_EVENT;
11606 spin_unlock_irqrestore(&phba->hbalock, iflags);
11607
11608 return true;
11609}
11610
11611/**
11612 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11613 * @phba: Pointer to HBA context object.
11614 * @cqe: Pointer to mailbox completion queue entry.
11615 *
11616 * This routine process a mailbox completion queue entry with mailbox
11617 * completion event.
11618 *
11619 * Return: true if work posted to worker thread, otherwise false.
11620 **/
11621static bool
11622lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
11623{
11624 uint32_t mcqe_status;
11625 MAILBOX_t *mbox, *pmbox;
11626 struct lpfc_mqe *mqe;
11627 struct lpfc_vport *vport;
11628 struct lpfc_nodelist *ndlp;
11629 struct lpfc_dmabuf *mp;
11630 unsigned long iflags;
11631 LPFC_MBOXQ_t *pmb;
11632 bool workposted = false;
11633 int rc;
11634
11635 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11636 if (!bf_get(lpfc_trailer_completed, mcqe))
11637 goto out_no_mqe_complete;
11638
11639 /* Get the reference to the active mbox command */
11640 spin_lock_irqsave(&phba->hbalock, iflags);
11641 pmb = phba->sli.mbox_active;
11642 if (unlikely(!pmb)) {
11643 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
11644 "1832 No pending MBOX command to handle\n");
11645 spin_unlock_irqrestore(&phba->hbalock, iflags);
11646 goto out_no_mqe_complete;
11647 }
11648 spin_unlock_irqrestore(&phba->hbalock, iflags);
11649 mqe = &pmb->u.mqe;
11650 pmbox = (MAILBOX_t *)&pmb->u.mqe;
11651 mbox = phba->mbox;
11652 vport = pmb->vport;
11653
11654 /* Reset heartbeat timer */
11655 phba->last_completion_time = jiffies;
11656 del_timer(&phba->sli.mbox_tmo);
11657
11658 /* Move mbox data to caller's mailbox region, do endian swapping */
11659 if (pmb->mbox_cmpl && mbox)
11660 lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
James Smart04c68492009-05-22 14:52:52 -040011661
James Smart73d91e52011-10-10 21:32:10 -040011662 /*
11663 * For mcqe errors, conditionally move a modified error code to
11664 * the mbox so that the error will not be missed.
11665 */
11666 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
11667 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
11668 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
11669 bf_set(lpfc_mqe_status, mqe,
11670 (LPFC_MBX_ERROR_RANGE | mcqe_status));
11671 }
James Smart04c68492009-05-22 14:52:52 -040011672 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
11673 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
11674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
11675 "MBOX dflt rpi: status:x%x rpi:x%x",
11676 mcqe_status,
11677 pmbox->un.varWords[0], 0);
11678 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
11679 mp = (struct lpfc_dmabuf *)(pmb->context1);
11680 ndlp = (struct lpfc_nodelist *)pmb->context2;
11681 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11682 * RID of the PPI using the same mbox buffer.
11683 */
11684 lpfc_unreg_login(phba, vport->vpi,
11685 pmbox->un.varWords[0], pmb);
11686 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
11687 pmb->context1 = mp;
11688 pmb->context2 = ndlp;
11689 pmb->vport = vport;
11690 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
11691 if (rc != MBX_BUSY)
11692 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
11693 LOG_SLI, "0385 rc should "
11694 "have been MBX_BUSY\n");
11695 if (rc != MBX_NOT_FINISHED)
11696 goto send_current_mbox;
11697 }
11698 }
11699 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11700 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
11701 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11702
11703 /* There is mailbox completion work to do */
11704 spin_lock_irqsave(&phba->hbalock, iflags);
11705 __lpfc_mbox_cmpl_put(phba, pmb);
11706 phba->work_ha |= HA_MBATT;
11707 spin_unlock_irqrestore(&phba->hbalock, iflags);
11708 workposted = true;
11709
11710send_current_mbox:
11711 spin_lock_irqsave(&phba->hbalock, iflags);
11712 /* Release the mailbox command posting token */
11713 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11714 /* Setting active mailbox pointer need to be in sync to flag clear */
11715 phba->sli.mbox_active = NULL;
11716 spin_unlock_irqrestore(&phba->hbalock, iflags);
11717 /* Wake up worker thread to post the next pending mailbox command */
11718 lpfc_worker_wake_up(phba);
11719out_no_mqe_complete:
11720 if (bf_get(lpfc_trailer_consumed, mcqe))
11721 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
11722 return workposted;
11723}
11724
11725/**
11726 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11727 * @phba: Pointer to HBA context object.
11728 * @cqe: Pointer to mailbox completion queue entry.
11729 *
11730 * This routine process a mailbox completion queue entry, it invokes the
11731 * proper mailbox complete handling or asynchrous event handling routine
11732 * according to the MCQE's async bit.
11733 *
11734 * Return: true if work posted to worker thread, otherwise false.
11735 **/
11736static bool
11737lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
11738{
11739 struct lpfc_mcqe mcqe;
11740 bool workposted;
11741
11742 /* Copy the mailbox MCQE and convert endian order as needed */
11743 lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
11744
11745 /* Invoke the proper event handling routine */
11746 if (!bf_get(lpfc_trailer_async, &mcqe))
11747 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
11748 else
11749 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
11750 return workposted;
11751}
11752
11753/**
James Smart4f774512009-05-22 14:52:35 -040011754 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11755 * @phba: Pointer to HBA context object.
James Smart2a76a282012-08-03 12:35:54 -040011756 * @cq: Pointer to associated CQ
James Smart4f774512009-05-22 14:52:35 -040011757 * @wcqe: Pointer to work-queue completion queue entry.
11758 *
11759 * This routine handles an ELS work-queue completion event.
11760 *
11761 * Return: true if work posted to worker thread, otherwise false.
11762 **/
11763static bool
James Smart2a76a282012-08-03 12:35:54 -040011764lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
James Smart4f774512009-05-22 14:52:35 -040011765 struct lpfc_wcqe_complete *wcqe)
11766{
James Smart4f774512009-05-22 14:52:35 -040011767 struct lpfc_iocbq *irspiocbq;
11768 unsigned long iflags;
James Smart2a76a282012-08-03 12:35:54 -040011769 struct lpfc_sli_ring *pring = cq->pring;
James Smart0e9bb8d2013-03-01 16:35:12 -050011770 int txq_cnt = 0;
11771 int txcmplq_cnt = 0;
11772 int fcp_txcmplq_cnt = 0;
James Smart4f774512009-05-22 14:52:35 -040011773
James Smart45ed1192009-10-02 15:17:02 -040011774 /* Get an irspiocbq for later ELS response processing use */
James Smart4f774512009-05-22 14:52:35 -040011775 irspiocbq = lpfc_sli_get_iocbq(phba);
11776 if (!irspiocbq) {
James Smart0e9bb8d2013-03-01 16:35:12 -050011777 if (!list_empty(&pring->txq))
11778 txq_cnt++;
11779 if (!list_empty(&pring->txcmplq))
11780 txcmplq_cnt++;
11781 if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
11782 fcp_txcmplq_cnt++;
James Smart4f774512009-05-22 14:52:35 -040011783 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart2a9bf3d2010-06-07 15:24:45 -040011784 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11785 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
James Smart0e9bb8d2013-03-01 16:35:12 -050011786 txq_cnt, phba->iocb_cnt,
11787 fcp_txcmplq_cnt,
11788 txcmplq_cnt);
James Smart45ed1192009-10-02 15:17:02 -040011789 return false;
James Smart4f774512009-05-22 14:52:35 -040011790 }
James Smart4f774512009-05-22 14:52:35 -040011791
James Smart45ed1192009-10-02 15:17:02 -040011792 /* Save off the slow-path queue event for work thread to process */
11793 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
James Smart4f774512009-05-22 14:52:35 -040011794 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart4d9ab992009-10-02 15:16:39 -040011795 list_add_tail(&irspiocbq->cq_event.list,
James Smart45ed1192009-10-02 15:17:02 -040011796 &phba->sli4_hba.sp_queue_event);
11797 phba->hba_flag |= HBA_SP_QUEUE_EVT;
James Smart4f774512009-05-22 14:52:35 -040011798 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart4f774512009-05-22 14:52:35 -040011799
James Smart45ed1192009-10-02 15:17:02 -040011800 return true;
James Smart4f774512009-05-22 14:52:35 -040011801}
11802
11803/**
11804 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11805 * @phba: Pointer to HBA context object.
11806 * @wcqe: Pointer to work-queue completion queue entry.
11807 *
11808 * This routine handles slow-path WQ entry comsumed event by invoking the
11809 * proper WQ release routine to the slow-path WQ.
11810 **/
11811static void
11812lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
11813 struct lpfc_wcqe_release *wcqe)
11814{
James Smart2e90f4b2011-12-13 13:22:37 -050011815 /* sanity check on queue memory */
11816 if (unlikely(!phba->sli4_hba.els_wq))
11817 return;
James Smart4f774512009-05-22 14:52:35 -040011818 /* Check for the slow-path ELS work queue */
11819 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
11820 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
11821 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
11822 else
11823 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11824 "2579 Slow-path wqe consume event carries "
11825 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11826 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
11827 phba->sli4_hba.els_wq->queue_id);
11828}
11829
11830/**
11831 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11832 * @phba: Pointer to HBA context object.
11833 * @cq: Pointer to a WQ completion queue.
11834 * @wcqe: Pointer to work-queue completion queue entry.
11835 *
11836 * This routine handles an XRI abort event.
11837 *
11838 * Return: true if work posted to worker thread, otherwise false.
11839 **/
11840static bool
11841lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
11842 struct lpfc_queue *cq,
11843 struct sli4_wcqe_xri_aborted *wcqe)
11844{
11845 bool workposted = false;
11846 struct lpfc_cq_event *cq_event;
11847 unsigned long iflags;
11848
11849 /* Allocate a new internal CQ_EVENT entry */
11850 cq_event = lpfc_sli4_cq_event_alloc(phba);
11851 if (!cq_event) {
11852 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11853 "0602 Failed to allocate CQ_EVENT entry\n");
11854 return false;
11855 }
11856
11857 /* Move the CQE into the proper xri abort event list */
11858 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
11859 switch (cq->subtype) {
11860 case LPFC_FCP:
11861 spin_lock_irqsave(&phba->hbalock, iflags);
11862 list_add_tail(&cq_event->list,
11863 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
11864 /* Set the fcp xri abort event flag */
11865 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
11866 spin_unlock_irqrestore(&phba->hbalock, iflags);
11867 workposted = true;
11868 break;
11869 case LPFC_ELS:
11870 spin_lock_irqsave(&phba->hbalock, iflags);
11871 list_add_tail(&cq_event->list,
11872 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
11873 /* Set the els xri abort event flag */
11874 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
11875 spin_unlock_irqrestore(&phba->hbalock, iflags);
11876 workposted = true;
11877 break;
11878 default:
11879 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11880 "0603 Invalid work queue CQE subtype (x%x)\n",
11881 cq->subtype);
11882 workposted = false;
11883 break;
11884 }
11885 return workposted;
11886}
11887
11888/**
James Smart4d9ab992009-10-02 15:16:39 -040011889 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
James Smart4f774512009-05-22 14:52:35 -040011890 * @phba: Pointer to HBA context object.
James Smart4d9ab992009-10-02 15:16:39 -040011891 * @rcqe: Pointer to receive-queue completion queue entry.
James Smart4f774512009-05-22 14:52:35 -040011892 *
James Smart4d9ab992009-10-02 15:16:39 -040011893 * This routine process a receive-queue completion queue entry.
James Smart4f774512009-05-22 14:52:35 -040011894 *
11895 * Return: true if work posted to worker thread, otherwise false.
11896 **/
11897static bool
James Smart4d9ab992009-10-02 15:16:39 -040011898lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
11899{
11900 bool workposted = false;
11901 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
11902 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
11903 struct hbq_dmabuf *dma_buf;
James Smart7851fe22011-07-22 18:36:52 -040011904 uint32_t status, rq_id;
James Smart4d9ab992009-10-02 15:16:39 -040011905 unsigned long iflags;
11906
James Smart2e90f4b2011-12-13 13:22:37 -050011907 /* sanity check on queue memory */
11908 if (unlikely(!hrq) || unlikely(!drq))
11909 return workposted;
11910
James Smart7851fe22011-07-22 18:36:52 -040011911 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
11912 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
11913 else
11914 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
11915 if (rq_id != hrq->queue_id)
James Smart4d9ab992009-10-02 15:16:39 -040011916 goto out;
11917
11918 status = bf_get(lpfc_rcqe_status, rcqe);
11919 switch (status) {
11920 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
11921 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11922 "2537 Receive Frame Truncated!!\n");
James Smartb84daac2012-08-03 12:35:13 -040011923 hrq->RQ_buf_trunc++;
James Smart4d9ab992009-10-02 15:16:39 -040011924 case FC_STATUS_RQ_SUCCESS:
James Smart5ffc2662009-11-18 15:39:44 -050011925 lpfc_sli4_rq_release(hrq, drq);
James Smart4d9ab992009-10-02 15:16:39 -040011926 spin_lock_irqsave(&phba->hbalock, iflags);
11927 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
11928 if (!dma_buf) {
James Smartb84daac2012-08-03 12:35:13 -040011929 hrq->RQ_no_buf_found++;
James Smart4d9ab992009-10-02 15:16:39 -040011930 spin_unlock_irqrestore(&phba->hbalock, iflags);
11931 goto out;
11932 }
James Smartb84daac2012-08-03 12:35:13 -040011933 hrq->RQ_rcv_buf++;
James Smart4d9ab992009-10-02 15:16:39 -040011934 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
11935 /* save off the frame for the word thread to process */
11936 list_add_tail(&dma_buf->cq_event.list,
James Smart45ed1192009-10-02 15:17:02 -040011937 &phba->sli4_hba.sp_queue_event);
James Smart4d9ab992009-10-02 15:16:39 -040011938 /* Frame received */
James Smart45ed1192009-10-02 15:17:02 -040011939 phba->hba_flag |= HBA_SP_QUEUE_EVT;
James Smart4d9ab992009-10-02 15:16:39 -040011940 spin_unlock_irqrestore(&phba->hbalock, iflags);
11941 workposted = true;
11942 break;
11943 case FC_STATUS_INSUFF_BUF_NEED_BUF:
11944 case FC_STATUS_INSUFF_BUF_FRM_DISC:
James Smartb84daac2012-08-03 12:35:13 -040011945 hrq->RQ_no_posted_buf++;
James Smart4d9ab992009-10-02 15:16:39 -040011946 /* Post more buffers if possible */
11947 spin_lock_irqsave(&phba->hbalock, iflags);
11948 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
11949 spin_unlock_irqrestore(&phba->hbalock, iflags);
11950 workposted = true;
11951 break;
11952 }
11953out:
11954 return workposted;
James Smart4d9ab992009-10-02 15:16:39 -040011955}
11956
11957/**
11958 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11959 * @phba: Pointer to HBA context object.
11960 * @cq: Pointer to the completion queue.
11961 * @wcqe: Pointer to a completion queue entry.
11962 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030011963 * This routine process a slow-path work-queue or receive queue completion queue
James Smart4d9ab992009-10-02 15:16:39 -040011964 * entry.
11965 *
11966 * Return: true if work posted to worker thread, otherwise false.
11967 **/
11968static bool
11969lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
James Smart4f774512009-05-22 14:52:35 -040011970 struct lpfc_cqe *cqe)
11971{
James Smart45ed1192009-10-02 15:17:02 -040011972 struct lpfc_cqe cqevt;
James Smart4f774512009-05-22 14:52:35 -040011973 bool workposted = false;
11974
11975 /* Copy the work queue CQE and convert endian order if needed */
James Smart45ed1192009-10-02 15:17:02 -040011976 lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
James Smart4f774512009-05-22 14:52:35 -040011977
11978 /* Check and process for different type of WCQE and dispatch */
James Smart45ed1192009-10-02 15:17:02 -040011979 switch (bf_get(lpfc_cqe_code, &cqevt)) {
James Smart4f774512009-05-22 14:52:35 -040011980 case CQE_CODE_COMPL_WQE:
James Smart45ed1192009-10-02 15:17:02 -040011981 /* Process the WQ/RQ complete event */
James Smartbc739052010-08-04 16:11:18 -040011982 phba->last_completion_time = jiffies;
James Smart2a76a282012-08-03 12:35:54 -040011983 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
James Smart45ed1192009-10-02 15:17:02 -040011984 (struct lpfc_wcqe_complete *)&cqevt);
James Smart4f774512009-05-22 14:52:35 -040011985 break;
11986 case CQE_CODE_RELEASE_WQE:
11987 /* Process the WQ release event */
11988 lpfc_sli4_sp_handle_rel_wcqe(phba,
James Smart45ed1192009-10-02 15:17:02 -040011989 (struct lpfc_wcqe_release *)&cqevt);
James Smart4f774512009-05-22 14:52:35 -040011990 break;
11991 case CQE_CODE_XRI_ABORTED:
11992 /* Process the WQ XRI abort event */
James Smartbc739052010-08-04 16:11:18 -040011993 phba->last_completion_time = jiffies;
James Smart4f774512009-05-22 14:52:35 -040011994 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
James Smart45ed1192009-10-02 15:17:02 -040011995 (struct sli4_wcqe_xri_aborted *)&cqevt);
James Smart4f774512009-05-22 14:52:35 -040011996 break;
James Smart4d9ab992009-10-02 15:16:39 -040011997 case CQE_CODE_RECEIVE:
James Smart7851fe22011-07-22 18:36:52 -040011998 case CQE_CODE_RECEIVE_V1:
James Smart4d9ab992009-10-02 15:16:39 -040011999 /* Process the RQ event */
James Smartbc739052010-08-04 16:11:18 -040012000 phba->last_completion_time = jiffies;
James Smart4d9ab992009-10-02 15:16:39 -040012001 workposted = lpfc_sli4_sp_handle_rcqe(phba,
James Smart45ed1192009-10-02 15:17:02 -040012002 (struct lpfc_rcqe *)&cqevt);
James Smart4d9ab992009-10-02 15:16:39 -040012003 break;
James Smart4f774512009-05-22 14:52:35 -040012004 default:
12005 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12006 "0388 Not a valid WCQE code: x%x\n",
James Smart45ed1192009-10-02 15:17:02 -040012007 bf_get(lpfc_cqe_code, &cqevt));
James Smart4f774512009-05-22 14:52:35 -040012008 break;
12009 }
12010 return workposted;
12011}
12012
12013/**
James Smart4f774512009-05-22 14:52:35 -040012014 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
12015 * @phba: Pointer to HBA context object.
12016 * @eqe: Pointer to fast-path event queue entry.
12017 *
12018 * This routine process a event queue entry from the slow-path event queue.
12019 * It will check the MajorCode and MinorCode to determine this is for a
12020 * completion event on a completion queue, if not, an error shall be logged
12021 * and just return. Otherwise, it will get to the corresponding completion
12022 * queue and process all the entries on that completion queue, rearm the
12023 * completion queue, and then return.
12024 *
12025 **/
12026static void
James Smart67d12732012-08-03 12:36:13 -040012027lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
12028 struct lpfc_queue *speq)
James Smart4f774512009-05-22 14:52:35 -040012029{
James Smart67d12732012-08-03 12:36:13 -040012030 struct lpfc_queue *cq = NULL, *childq;
James Smart4f774512009-05-22 14:52:35 -040012031 struct lpfc_cqe *cqe;
12032 bool workposted = false;
12033 int ecount = 0;
12034 uint16_t cqid;
12035
James Smart4f774512009-05-22 14:52:35 -040012036 /* Get the reference to the corresponding CQ */
James Smartcb5172e2010-03-15 11:25:07 -040012037 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
James Smart4f774512009-05-22 14:52:35 -040012038
James Smart4f774512009-05-22 14:52:35 -040012039 list_for_each_entry(childq, &speq->child_list, list) {
12040 if (childq->queue_id == cqid) {
12041 cq = childq;
12042 break;
12043 }
12044 }
12045 if (unlikely(!cq)) {
James Smart75baf692010-06-08 18:31:21 -040012046 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
12047 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12048 "0365 Slow-path CQ identifier "
12049 "(%d) does not exist\n", cqid);
James Smart4f774512009-05-22 14:52:35 -040012050 return;
12051 }
12052
12053 /* Process all the entries to the CQ */
12054 switch (cq->type) {
12055 case LPFC_MCQ:
12056 while ((cqe = lpfc_sli4_cq_get(cq))) {
12057 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
James Smart73d91e52011-10-10 21:32:10 -040012058 if (!(++ecount % cq->entry_repost))
James Smart4f774512009-05-22 14:52:35 -040012059 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
James Smartb84daac2012-08-03 12:35:13 -040012060 cq->CQ_mbox++;
James Smart4f774512009-05-22 14:52:35 -040012061 }
12062 break;
12063 case LPFC_WCQ:
12064 while ((cqe = lpfc_sli4_cq_get(cq))) {
James Smart05580562011-05-24 11:40:48 -040012065 if (cq->subtype == LPFC_FCP)
12066 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
12067 cqe);
12068 else
12069 workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
12070 cqe);
James Smart73d91e52011-10-10 21:32:10 -040012071 if (!(++ecount % cq->entry_repost))
James Smart4f774512009-05-22 14:52:35 -040012072 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
12073 }
James Smartb84daac2012-08-03 12:35:13 -040012074
12075 /* Track the max number of CQEs processed in 1 EQ */
12076 if (ecount > cq->CQ_max_cqe)
12077 cq->CQ_max_cqe = ecount;
James Smart4f774512009-05-22 14:52:35 -040012078 break;
12079 default:
12080 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12081 "0370 Invalid completion queue type (%d)\n",
12082 cq->type);
12083 return;
12084 }
12085
12086 /* Catch the no cq entry condition, log an error */
12087 if (unlikely(ecount == 0))
12088 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12089 "0371 No entry from the CQ: identifier "
12090 "(x%x), type (%d)\n", cq->queue_id, cq->type);
12091
12092 /* In any case, flash and re-arm the RCQ */
12093 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
12094
12095 /* wake up worker thread if there are works to be done */
12096 if (workposted)
12097 lpfc_worker_wake_up(phba);
12098}
12099
12100/**
12101 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
James Smart2a76a282012-08-03 12:35:54 -040012102 * @phba: Pointer to HBA context object.
12103 * @cq: Pointer to associated CQ
12104 * @wcqe: Pointer to work-queue completion queue entry.
James Smart4f774512009-05-22 14:52:35 -040012105 *
12106 * This routine process a fast-path work queue completion entry from fast-path
12107 * event queue for FCP command response completion.
12108 **/
12109static void
James Smart2a76a282012-08-03 12:35:54 -040012110lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
James Smart4f774512009-05-22 14:52:35 -040012111 struct lpfc_wcqe_complete *wcqe)
12112{
James Smart2a76a282012-08-03 12:35:54 -040012113 struct lpfc_sli_ring *pring = cq->pring;
James Smart4f774512009-05-22 14:52:35 -040012114 struct lpfc_iocbq *cmdiocbq;
12115 struct lpfc_iocbq irspiocbq;
12116 unsigned long iflags;
12117
James Smart4f774512009-05-22 14:52:35 -040012118 /* Check for response status */
12119 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
12120 /* If resource errors reported from HBA, reduce queue
12121 * depth of the SCSI device.
12122 */
James Smarte3d2b802012-08-14 14:25:43 -040012123 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
12124 IOSTAT_LOCAL_REJECT)) &&
12125 ((wcqe->parameter & IOERR_PARAM_MASK) ==
12126 IOERR_NO_RESOURCES))
James Smart4f774512009-05-22 14:52:35 -040012127 phba->lpfc_rampdown_queue_depth(phba);
James Smarte3d2b802012-08-14 14:25:43 -040012128
James Smart4f774512009-05-22 14:52:35 -040012129 /* Log the error status */
12130 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12131 "0373 FCP complete error: status=x%x, "
12132 "hw_status=x%x, total_data_specified=%d, "
12133 "parameter=x%x, word3=x%x\n",
12134 bf_get(lpfc_wcqe_c_status, wcqe),
12135 bf_get(lpfc_wcqe_c_hw_status, wcqe),
12136 wcqe->total_data_placed, wcqe->parameter,
12137 wcqe->word3);
12138 }
12139
12140 /* Look up the FCP command IOCB and create pseudo response IOCB */
James Smart7e56aa22012-08-03 12:35:34 -040012141 spin_lock_irqsave(&pring->ring_lock, iflags);
12142 pring->stats.iocb_event++;
James Smart4f774512009-05-22 14:52:35 -040012143 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
12144 bf_get(lpfc_wcqe_c_request_tag, wcqe));
James Smart7e56aa22012-08-03 12:35:34 -040012145 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smart4f774512009-05-22 14:52:35 -040012146 if (unlikely(!cmdiocbq)) {
12147 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12148 "0374 FCP complete with no corresponding "
12149 "cmdiocb: iotag (%d)\n",
12150 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12151 return;
12152 }
12153 if (unlikely(!cmdiocbq->iocb_cmpl)) {
12154 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12155 "0375 FCP cmdiocb not callback function "
12156 "iotag: (%d)\n",
12157 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12158 return;
12159 }
12160
12161 /* Fake the irspiocb and copy necessary response information */
James Smart341af102010-01-26 23:07:37 -050012162 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
James Smart4f774512009-05-22 14:52:35 -040012163
James Smart0f65ff62010-02-26 14:14:23 -050012164 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
12165 spin_lock_irqsave(&phba->hbalock, iflags);
12166 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
12167 spin_unlock_irqrestore(&phba->hbalock, iflags);
12168 }
12169
James Smart4f774512009-05-22 14:52:35 -040012170 /* Pass the cmd_iocb and the rsp state to the upper layer */
12171 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
12172}
12173
12174/**
12175 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
12176 * @phba: Pointer to HBA context object.
12177 * @cq: Pointer to completion queue.
12178 * @wcqe: Pointer to work-queue completion queue entry.
12179 *
12180 * This routine handles an fast-path WQ entry comsumed event by invoking the
12181 * proper WQ release routine to the slow-path WQ.
12182 **/
12183static void
12184lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
12185 struct lpfc_wcqe_release *wcqe)
12186{
12187 struct lpfc_queue *childwq;
12188 bool wqid_matched = false;
12189 uint16_t fcp_wqid;
12190
12191 /* Check for fast-path FCP work queue release */
12192 fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
12193 list_for_each_entry(childwq, &cq->child_list, list) {
12194 if (childwq->queue_id == fcp_wqid) {
12195 lpfc_sli4_wq_release(childwq,
12196 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
12197 wqid_matched = true;
12198 break;
12199 }
12200 }
12201 /* Report warning log message if no match found */
12202 if (wqid_matched != true)
12203 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12204 "2580 Fast-path wqe consume event carries "
12205 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
12206}
12207
12208/**
12209 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
12210 * @cq: Pointer to the completion queue.
12211 * @eqe: Pointer to fast-path completion queue entry.
12212 *
12213 * This routine process a fast-path work queue completion entry from fast-path
12214 * event queue for FCP command response completion.
12215 **/
12216static int
12217lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
12218 struct lpfc_cqe *cqe)
12219{
12220 struct lpfc_wcqe_release wcqe;
12221 bool workposted = false;
12222
12223 /* Copy the work queue CQE and convert endian order if needed */
12224 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
12225
12226 /* Check and process for different type of WCQE and dispatch */
12227 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
12228 case CQE_CODE_COMPL_WQE:
James Smartb84daac2012-08-03 12:35:13 -040012229 cq->CQ_wq++;
James Smart4f774512009-05-22 14:52:35 -040012230 /* Process the WQ complete event */
James Smart98fc5dd2010-06-07 15:24:29 -040012231 phba->last_completion_time = jiffies;
James Smart2a76a282012-08-03 12:35:54 -040012232 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
James Smart4f774512009-05-22 14:52:35 -040012233 (struct lpfc_wcqe_complete *)&wcqe);
12234 break;
12235 case CQE_CODE_RELEASE_WQE:
James Smartb84daac2012-08-03 12:35:13 -040012236 cq->CQ_release_wqe++;
James Smart4f774512009-05-22 14:52:35 -040012237 /* Process the WQ release event */
12238 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
12239 (struct lpfc_wcqe_release *)&wcqe);
12240 break;
12241 case CQE_CODE_XRI_ABORTED:
James Smartb84daac2012-08-03 12:35:13 -040012242 cq->CQ_xri_aborted++;
James Smart4f774512009-05-22 14:52:35 -040012243 /* Process the WQ XRI abort event */
James Smartbc739052010-08-04 16:11:18 -040012244 phba->last_completion_time = jiffies;
James Smart4f774512009-05-22 14:52:35 -040012245 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
12246 (struct sli4_wcqe_xri_aborted *)&wcqe);
12247 break;
12248 default:
12249 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12250 "0144 Not a valid WCQE code: x%x\n",
12251 bf_get(lpfc_wcqe_c_code, &wcqe));
12252 break;
12253 }
12254 return workposted;
12255}
12256
12257/**
James Smart67d12732012-08-03 12:36:13 -040012258 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
James Smart4f774512009-05-22 14:52:35 -040012259 * @phba: Pointer to HBA context object.
12260 * @eqe: Pointer to fast-path event queue entry.
12261 *
12262 * This routine process a event queue entry from the fast-path event queue.
12263 * It will check the MajorCode and MinorCode to determine this is for a
12264 * completion event on a completion queue, if not, an error shall be logged
12265 * and just return. Otherwise, it will get to the corresponding completion
12266 * queue and process all the entries on the completion queue, rearm the
12267 * completion queue, and then return.
12268 **/
12269static void
James Smart67d12732012-08-03 12:36:13 -040012270lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
12271 uint32_t qidx)
James Smart4f774512009-05-22 14:52:35 -040012272{
12273 struct lpfc_queue *cq;
12274 struct lpfc_cqe *cqe;
12275 bool workposted = false;
12276 uint16_t cqid;
12277 int ecount = 0;
12278
James Smartcb5172e2010-03-15 11:25:07 -040012279 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
James Smart4f774512009-05-22 14:52:35 -040012280 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart67d12732012-08-03 12:36:13 -040012281 "0366 Not a valid completion "
James Smart4f774512009-05-22 14:52:35 -040012282 "event: majorcode=x%x, minorcode=x%x\n",
James Smartcb5172e2010-03-15 11:25:07 -040012283 bf_get_le32(lpfc_eqe_major_code, eqe),
12284 bf_get_le32(lpfc_eqe_minor_code, eqe));
James Smart4f774512009-05-22 14:52:35 -040012285 return;
12286 }
12287
James Smart67d12732012-08-03 12:36:13 -040012288 /* Get the reference to the corresponding CQ */
12289 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
12290
12291 /* Check if this is a Slow path event */
12292 if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
12293 lpfc_sli4_sp_handle_eqe(phba, eqe,
12294 phba->sli4_hba.hba_eq[qidx]);
12295 return;
12296 }
12297
James Smart2e90f4b2011-12-13 13:22:37 -050012298 if (unlikely(!phba->sli4_hba.fcp_cq)) {
12299 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12300 "3146 Fast-path completion queues "
12301 "does not exist\n");
12302 return;
12303 }
James Smart67d12732012-08-03 12:36:13 -040012304 cq = phba->sli4_hba.fcp_cq[qidx];
James Smart4f774512009-05-22 14:52:35 -040012305 if (unlikely(!cq)) {
James Smart75baf692010-06-08 18:31:21 -040012306 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
12307 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12308 "0367 Fast-path completion queue "
James Smart67d12732012-08-03 12:36:13 -040012309 "(%d) does not exist\n", qidx);
James Smart4f774512009-05-22 14:52:35 -040012310 return;
12311 }
12312
James Smart4f774512009-05-22 14:52:35 -040012313 if (unlikely(cqid != cq->queue_id)) {
12314 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12315 "0368 Miss-matched fast-path completion "
12316 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
12317 cqid, cq->queue_id);
12318 return;
12319 }
12320
12321 /* Process all the entries to the CQ */
12322 while ((cqe = lpfc_sli4_cq_get(cq))) {
12323 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
James Smart73d91e52011-10-10 21:32:10 -040012324 if (!(++ecount % cq->entry_repost))
James Smart4f774512009-05-22 14:52:35 -040012325 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
12326 }
12327
James Smartb84daac2012-08-03 12:35:13 -040012328 /* Track the max number of CQEs processed in 1 EQ */
12329 if (ecount > cq->CQ_max_cqe)
12330 cq->CQ_max_cqe = ecount;
12331
James Smart4f774512009-05-22 14:52:35 -040012332 /* Catch the no cq entry condition */
12333 if (unlikely(ecount == 0))
12334 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12335 "0369 No entry from fast-path completion "
12336 "queue fcpcqid=%d\n", cq->queue_id);
12337
12338 /* In any case, flash and re-arm the CQ */
12339 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
12340
12341 /* wake up worker thread if there are works to be done */
12342 if (workposted)
12343 lpfc_worker_wake_up(phba);
12344}
12345
12346static void
12347lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
12348{
12349 struct lpfc_eqe *eqe;
12350
12351 /* walk all the EQ entries and drop on the floor */
12352 while ((eqe = lpfc_sli4_eq_get(eq)))
12353 ;
12354
12355 /* Clear and re-arm the EQ */
12356 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
12357}
12358
James Smart1ba981f2014-02-20 09:56:45 -050012359
12360/**
12361 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
12362 * entry
12363 * @phba: Pointer to HBA context object.
12364 * @eqe: Pointer to fast-path event queue entry.
12365 *
12366 * This routine process a event queue entry from the Flash Optimized Fabric
12367 * event queue. It will check the MajorCode and MinorCode to determine this
12368 * is for a completion event on a completion queue, if not, an error shall be
12369 * logged and just return. Otherwise, it will get to the corresponding
12370 * completion queue and process all the entries on the completion queue, rearm
12371 * the completion queue, and then return.
12372 **/
12373static void
12374lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
12375{
12376 struct lpfc_queue *cq;
12377 struct lpfc_cqe *cqe;
12378 bool workposted = false;
12379 uint16_t cqid;
12380 int ecount = 0;
12381
12382 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
12383 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12384 "9147 Not a valid completion "
12385 "event: majorcode=x%x, minorcode=x%x\n",
12386 bf_get_le32(lpfc_eqe_major_code, eqe),
12387 bf_get_le32(lpfc_eqe_minor_code, eqe));
12388 return;
12389 }
12390
12391 /* Get the reference to the corresponding CQ */
12392 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
12393
12394 /* Next check for OAS */
12395 cq = phba->sli4_hba.oas_cq;
12396 if (unlikely(!cq)) {
12397 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
12398 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12399 "9148 OAS completion queue "
12400 "does not exist\n");
12401 return;
12402 }
12403
12404 if (unlikely(cqid != cq->queue_id)) {
12405 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12406 "9149 Miss-matched fast-path compl "
12407 "queue id: eqcqid=%d, fcpcqid=%d\n",
12408 cqid, cq->queue_id);
12409 return;
12410 }
12411
12412 /* Process all the entries to the OAS CQ */
12413 while ((cqe = lpfc_sli4_cq_get(cq))) {
12414 workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
12415 if (!(++ecount % cq->entry_repost))
12416 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
12417 }
12418
12419 /* Track the max number of CQEs processed in 1 EQ */
12420 if (ecount > cq->CQ_max_cqe)
12421 cq->CQ_max_cqe = ecount;
12422
12423 /* Catch the no cq entry condition */
12424 if (unlikely(ecount == 0))
12425 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12426 "9153 No entry from fast-path completion "
12427 "queue fcpcqid=%d\n", cq->queue_id);
12428
12429 /* In any case, flash and re-arm the CQ */
12430 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
12431
12432 /* wake up worker thread if there are works to be done */
12433 if (workposted)
12434 lpfc_worker_wake_up(phba);
12435}
12436
12437/**
12438 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
12439 * @irq: Interrupt number.
12440 * @dev_id: The device context pointer.
12441 *
12442 * This function is directly called from the PCI layer as an interrupt
12443 * service routine when device with SLI-4 interface spec is enabled with
12444 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
12445 * IOCB ring event in the HBA. However, when the device is enabled with either
12446 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12447 * device-level interrupt handler. When the PCI slot is in error recovery
12448 * or the HBA is undergoing initialization, the interrupt handler will not
12449 * process the interrupt. The Flash Optimized Fabric ring event are handled in
12450 * the intrrupt context. This function is called without any lock held.
12451 * It gets the hbalock to access and update SLI data structures. Note that,
12452 * the EQ to CQ are one-to-one map such that the EQ index is
12453 * equal to that of CQ index.
12454 *
12455 * This function returns IRQ_HANDLED when interrupt is handled else it
12456 * returns IRQ_NONE.
12457 **/
12458irqreturn_t
12459lpfc_sli4_fof_intr_handler(int irq, void *dev_id)
12460{
12461 struct lpfc_hba *phba;
12462 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
12463 struct lpfc_queue *eq;
12464 struct lpfc_eqe *eqe;
12465 unsigned long iflag;
12466 int ecount = 0;
12467 uint32_t eqidx;
12468
12469 /* Get the driver's phba structure from the dev_id */
12470 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
12471 phba = fcp_eq_hdl->phba;
12472 eqidx = fcp_eq_hdl->idx;
12473
12474 if (unlikely(!phba))
12475 return IRQ_NONE;
12476
12477 /* Get to the EQ struct associated with this vector */
12478 eq = phba->sli4_hba.fof_eq;
12479 if (unlikely(!eq))
12480 return IRQ_NONE;
12481
12482 /* Check device state for handling interrupt */
12483 if (unlikely(lpfc_intr_state_check(phba))) {
12484 eq->EQ_badstate++;
12485 /* Check again for link_state with lock held */
12486 spin_lock_irqsave(&phba->hbalock, iflag);
12487 if (phba->link_state < LPFC_LINK_DOWN)
12488 /* Flush, clear interrupt, and rearm the EQ */
12489 lpfc_sli4_eq_flush(phba, eq);
12490 spin_unlock_irqrestore(&phba->hbalock, iflag);
12491 return IRQ_NONE;
12492 }
12493
12494 /*
12495 * Process all the event on FCP fast-path EQ
12496 */
12497 while ((eqe = lpfc_sli4_eq_get(eq))) {
12498 lpfc_sli4_fof_handle_eqe(phba, eqe);
12499 if (!(++ecount % eq->entry_repost))
12500 lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM);
12501 eq->EQ_processed++;
12502 }
12503
12504 /* Track the max number of EQEs processed in 1 intr */
12505 if (ecount > eq->EQ_max_eqe)
12506 eq->EQ_max_eqe = ecount;
12507
12508
12509 if (unlikely(ecount == 0)) {
12510 eq->EQ_no_entry++;
12511
12512 if (phba->intr_type == MSIX)
12513 /* MSI-X treated interrupt served as no EQ share INT */
12514 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12515 "9145 MSI-X interrupt with no EQE\n");
12516 else {
12517 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12518 "9146 ISR interrupt with no EQE\n");
12519 /* Non MSI-X treated on interrupt as EQ share INT */
12520 return IRQ_NONE;
12521 }
12522 }
12523 /* Always clear and re-arm the fast-path EQ */
12524 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
12525 return IRQ_HANDLED;
12526}
12527
James Smart4f774512009-05-22 14:52:35 -040012528/**
James Smart67d12732012-08-03 12:36:13 -040012529 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
James Smart4f774512009-05-22 14:52:35 -040012530 * @irq: Interrupt number.
12531 * @dev_id: The device context pointer.
12532 *
12533 * This function is directly called from the PCI layer as an interrupt
12534 * service routine when device with SLI-4 interface spec is enabled with
12535 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12536 * ring event in the HBA. However, when the device is enabled with either
12537 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12538 * device-level interrupt handler. When the PCI slot is in error recovery
12539 * or the HBA is undergoing initialization, the interrupt handler will not
12540 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12541 * the intrrupt context. This function is called without any lock held.
12542 * It gets the hbalock to access and update SLI data structures. Note that,
12543 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
12544 * equal to that of FCP CQ index.
12545 *
James Smart67d12732012-08-03 12:36:13 -040012546 * The link attention and ELS ring attention events are handled
12547 * by the worker thread. The interrupt handler signals the worker thread
12548 * and returns for these events. This function is called without any lock
12549 * held. It gets the hbalock to access and update SLI data structures.
12550 *
James Smart4f774512009-05-22 14:52:35 -040012551 * This function returns IRQ_HANDLED when interrupt is handled else it
12552 * returns IRQ_NONE.
12553 **/
12554irqreturn_t
James Smart67d12732012-08-03 12:36:13 -040012555lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
James Smart4f774512009-05-22 14:52:35 -040012556{
12557 struct lpfc_hba *phba;
12558 struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
12559 struct lpfc_queue *fpeq;
12560 struct lpfc_eqe *eqe;
12561 unsigned long iflag;
12562 int ecount = 0;
James Smart962bc512013-01-03 15:44:00 -050012563 int fcp_eqidx;
James Smart4f774512009-05-22 14:52:35 -040012564
12565 /* Get the driver's phba structure from the dev_id */
12566 fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
12567 phba = fcp_eq_hdl->phba;
12568 fcp_eqidx = fcp_eq_hdl->idx;
12569
12570 if (unlikely(!phba))
12571 return IRQ_NONE;
James Smart67d12732012-08-03 12:36:13 -040012572 if (unlikely(!phba->sli4_hba.hba_eq))
James Smart5350d872011-10-10 21:33:49 -040012573 return IRQ_NONE;
James Smart4f774512009-05-22 14:52:35 -040012574
12575 /* Get to the EQ struct associated with this vector */
James Smart67d12732012-08-03 12:36:13 -040012576 fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
James Smart2e90f4b2011-12-13 13:22:37 -050012577 if (unlikely(!fpeq))
12578 return IRQ_NONE;
James Smart4f774512009-05-22 14:52:35 -040012579
James Smartba20c852012-08-03 12:36:52 -040012580 if (lpfc_fcp_look_ahead) {
12581 if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
12582 lpfc_sli4_eq_clr_intr(fpeq);
12583 else {
12584 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
12585 return IRQ_NONE;
12586 }
12587 }
12588
James Smart4f774512009-05-22 14:52:35 -040012589 /* Check device state for handling interrupt */
12590 if (unlikely(lpfc_intr_state_check(phba))) {
James Smartb84daac2012-08-03 12:35:13 -040012591 fpeq->EQ_badstate++;
James Smart4f774512009-05-22 14:52:35 -040012592 /* Check again for link_state with lock held */
12593 spin_lock_irqsave(&phba->hbalock, iflag);
12594 if (phba->link_state < LPFC_LINK_DOWN)
12595 /* Flush, clear interrupt, and rearm the EQ */
12596 lpfc_sli4_eq_flush(phba, fpeq);
12597 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartba20c852012-08-03 12:36:52 -040012598 if (lpfc_fcp_look_ahead)
12599 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
James Smart4f774512009-05-22 14:52:35 -040012600 return IRQ_NONE;
12601 }
12602
12603 /*
12604 * Process all the event on FCP fast-path EQ
12605 */
12606 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
James Smart67d12732012-08-03 12:36:13 -040012607 lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
James Smart73d91e52011-10-10 21:32:10 -040012608 if (!(++ecount % fpeq->entry_repost))
James Smart4f774512009-05-22 14:52:35 -040012609 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
James Smartb84daac2012-08-03 12:35:13 -040012610 fpeq->EQ_processed++;
James Smart4f774512009-05-22 14:52:35 -040012611 }
12612
James Smartb84daac2012-08-03 12:35:13 -040012613 /* Track the max number of EQEs processed in 1 intr */
12614 if (ecount > fpeq->EQ_max_eqe)
12615 fpeq->EQ_max_eqe = ecount;
12616
James Smart4f774512009-05-22 14:52:35 -040012617 /* Always clear and re-arm the fast-path EQ */
12618 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
12619
12620 if (unlikely(ecount == 0)) {
James Smartb84daac2012-08-03 12:35:13 -040012621 fpeq->EQ_no_entry++;
James Smartba20c852012-08-03 12:36:52 -040012622
12623 if (lpfc_fcp_look_ahead) {
12624 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
12625 return IRQ_NONE;
12626 }
12627
James Smart4f774512009-05-22 14:52:35 -040012628 if (phba->intr_type == MSIX)
12629 /* MSI-X treated interrupt served as no EQ share INT */
12630 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12631 "0358 MSI-X interrupt with no EQE\n");
12632 else
12633 /* Non MSI-X treated on interrupt as EQ share INT */
12634 return IRQ_NONE;
12635 }
12636
James Smartba20c852012-08-03 12:36:52 -040012637 if (lpfc_fcp_look_ahead)
12638 atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
James Smart4f774512009-05-22 14:52:35 -040012639 return IRQ_HANDLED;
12640} /* lpfc_sli4_fp_intr_handler */
12641
12642/**
12643 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
12644 * @irq: Interrupt number.
12645 * @dev_id: The device context pointer.
12646 *
12647 * This function is the device-level interrupt handler to device with SLI-4
12648 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
12649 * interrupt mode is enabled and there is an event in the HBA which requires
12650 * driver attention. This function invokes the slow-path interrupt attention
12651 * handling function and fast-path interrupt attention handling function in
12652 * turn to process the relevant HBA attention events. This function is called
12653 * without any lock held. It gets the hbalock to access and update SLI data
12654 * structures.
12655 *
12656 * This function returns IRQ_HANDLED when interrupt is handled, else it
12657 * returns IRQ_NONE.
12658 **/
12659irqreturn_t
12660lpfc_sli4_intr_handler(int irq, void *dev_id)
12661{
12662 struct lpfc_hba *phba;
James Smart67d12732012-08-03 12:36:13 -040012663 irqreturn_t hba_irq_rc;
12664 bool hba_handled = false;
James Smart962bc512013-01-03 15:44:00 -050012665 int fcp_eqidx;
James Smart4f774512009-05-22 14:52:35 -040012666
12667 /* Get the driver's phba structure from the dev_id */
12668 phba = (struct lpfc_hba *)dev_id;
12669
12670 if (unlikely(!phba))
12671 return IRQ_NONE;
12672
12673 /*
James Smart4f774512009-05-22 14:52:35 -040012674 * Invoke fast-path host attention interrupt handling as appropriate.
12675 */
James Smart67d12732012-08-03 12:36:13 -040012676 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
12677 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
James Smart4f774512009-05-22 14:52:35 -040012678 &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
James Smart67d12732012-08-03 12:36:13 -040012679 if (hba_irq_rc == IRQ_HANDLED)
12680 hba_handled |= true;
James Smart4f774512009-05-22 14:52:35 -040012681 }
12682
James Smart1ba981f2014-02-20 09:56:45 -050012683 if (phba->cfg_fof) {
12684 hba_irq_rc = lpfc_sli4_fof_intr_handler(irq,
12685 &phba->sli4_hba.fcp_eq_hdl[0]);
12686 if (hba_irq_rc == IRQ_HANDLED)
12687 hba_handled |= true;
12688 }
12689
James Smart67d12732012-08-03 12:36:13 -040012690 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
James Smart4f774512009-05-22 14:52:35 -040012691} /* lpfc_sli4_intr_handler */
12692
12693/**
12694 * lpfc_sli4_queue_free - free a queue structure and associated memory
12695 * @queue: The queue structure to free.
12696 *
Uwe Kleine-Königb5950762010-11-01 15:38:34 -040012697 * This function frees a queue structure and the DMAable memory used for
James Smart4f774512009-05-22 14:52:35 -040012698 * the host resident queue. This function must be called after destroying the
12699 * queue on the HBA.
12700 **/
12701void
12702lpfc_sli4_queue_free(struct lpfc_queue *queue)
12703{
12704 struct lpfc_dmabuf *dmabuf;
12705
12706 if (!queue)
12707 return;
12708
12709 while (!list_empty(&queue->page_list)) {
12710 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
12711 list);
James Smart49198b32010-04-06 15:04:33 -040012712 dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
James Smart4f774512009-05-22 14:52:35 -040012713 dmabuf->virt, dmabuf->phys);
12714 kfree(dmabuf);
12715 }
12716 kfree(queue);
12717 return;
12718}
12719
12720/**
12721 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12722 * @phba: The HBA that this queue is being created on.
12723 * @entry_size: The size of each queue entry for this queue.
12724 * @entry count: The number of entries that this queue will handle.
12725 *
12726 * This function allocates a queue structure and the DMAable memory used for
12727 * the host resident queue. This function must be called before creating the
12728 * queue on the HBA.
12729 **/
12730struct lpfc_queue *
12731lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
12732 uint32_t entry_count)
12733{
12734 struct lpfc_queue *queue;
12735 struct lpfc_dmabuf *dmabuf;
12736 int x, total_qe_count;
12737 void *dma_pointer;
James Smartcb5172e2010-03-15 11:25:07 -040012738 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
James Smart4f774512009-05-22 14:52:35 -040012739
James Smartcb5172e2010-03-15 11:25:07 -040012740 if (!phba->sli4_hba.pc_sli4_params.supported)
12741 hw_page_size = SLI4_PAGE_SIZE;
12742
James Smart4f774512009-05-22 14:52:35 -040012743 queue = kzalloc(sizeof(struct lpfc_queue) +
12744 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
12745 if (!queue)
12746 return NULL;
James Smartcb5172e2010-03-15 11:25:07 -040012747 queue->page_count = (ALIGN(entry_size * entry_count,
12748 hw_page_size))/hw_page_size;
James Smart4f774512009-05-22 14:52:35 -040012749 INIT_LIST_HEAD(&queue->list);
12750 INIT_LIST_HEAD(&queue->page_list);
12751 INIT_LIST_HEAD(&queue->child_list);
12752 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
12753 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
12754 if (!dmabuf)
12755 goto out_fail;
Joe Perches1aee3832014-09-03 12:56:12 -040012756 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
12757 hw_page_size, &dmabuf->phys,
12758 GFP_KERNEL);
James Smart4f774512009-05-22 14:52:35 -040012759 if (!dmabuf->virt) {
12760 kfree(dmabuf);
12761 goto out_fail;
12762 }
12763 dmabuf->buffer_tag = x;
12764 list_add_tail(&dmabuf->list, &queue->page_list);
12765 /* initialize queue's entry array */
12766 dma_pointer = dmabuf->virt;
12767 for (; total_qe_count < entry_count &&
James Smartcb5172e2010-03-15 11:25:07 -040012768 dma_pointer < (hw_page_size + dmabuf->virt);
James Smart4f774512009-05-22 14:52:35 -040012769 total_qe_count++, dma_pointer += entry_size) {
12770 queue->qe[total_qe_count].address = dma_pointer;
12771 }
12772 }
12773 queue->entry_size = entry_size;
12774 queue->entry_count = entry_count;
James Smart73d91e52011-10-10 21:32:10 -040012775
12776 /*
12777 * entry_repost is calculated based on the number of entries in the
12778 * queue. This works out except for RQs. If buffers are NOT initially
12779 * posted for every RQE, entry_repost should be adjusted accordingly.
12780 */
12781 queue->entry_repost = (entry_count >> 3);
12782 if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
12783 queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
James Smart4f774512009-05-22 14:52:35 -040012784 queue->phba = phba;
12785
12786 return queue;
12787out_fail:
12788 lpfc_sli4_queue_free(queue);
12789 return NULL;
12790}
12791
12792/**
James Smart962bc512013-01-03 15:44:00 -050012793 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
12794 * @phba: HBA structure that indicates port to create a queue on.
12795 * @pci_barset: PCI BAR set flag.
12796 *
12797 * This function shall perform iomap of the specified PCI BAR address to host
12798 * memory address if not already done so and return it. The returned host
12799 * memory address can be NULL.
12800 */
12801static void __iomem *
12802lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
12803{
12804 struct pci_dev *pdev;
James Smart962bc512013-01-03 15:44:00 -050012805
12806 if (!phba->pcidev)
12807 return NULL;
12808 else
12809 pdev = phba->pcidev;
12810
12811 switch (pci_barset) {
12812 case WQ_PCI_BAR_0_AND_1:
James Smart962bc512013-01-03 15:44:00 -050012813 return phba->pci_bar0_memmap_p;
12814 case WQ_PCI_BAR_2_AND_3:
James Smart962bc512013-01-03 15:44:00 -050012815 return phba->pci_bar2_memmap_p;
12816 case WQ_PCI_BAR_4_AND_5:
James Smart962bc512013-01-03 15:44:00 -050012817 return phba->pci_bar4_memmap_p;
12818 default:
12819 break;
12820 }
12821 return NULL;
12822}
12823
12824/**
James Smart173edbb2012-06-12 13:54:50 -040012825 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
12826 * @phba: HBA structure that indicates port to create a queue on.
12827 * @startq: The starting FCP EQ to modify
12828 *
12829 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
12830 *
12831 * The @phba struct is used to send mailbox command to HBA. The @startq
12832 * is used to get the starting FCP EQ to change.
12833 * This function is asynchronous and will wait for the mailbox
12834 * command to finish before continuing.
12835 *
12836 * On success this function will return a zero. If unable to allocate enough
12837 * memory this function will return -ENOMEM. If the queue create mailbox command
12838 * fails this function will return -ENXIO.
12839 **/
12840uint32_t
12841lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq)
12842{
12843 struct lpfc_mbx_modify_eq_delay *eq_delay;
12844 LPFC_MBOXQ_t *mbox;
12845 struct lpfc_queue *eq;
12846 int cnt, rc, length, status = 0;
12847 uint32_t shdr_status, shdr_add_status;
James Smartee020062012-09-29 11:28:52 -040012848 uint32_t result;
James Smart173edbb2012-06-12 13:54:50 -040012849 int fcp_eqidx;
12850 union lpfc_sli4_cfg_shdr *shdr;
12851 uint16_t dmult;
12852
James Smart67d12732012-08-03 12:36:13 -040012853 if (startq >= phba->cfg_fcp_io_channel)
James Smart173edbb2012-06-12 13:54:50 -040012854 return 0;
12855
12856 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12857 if (!mbox)
12858 return -ENOMEM;
12859 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
12860 sizeof(struct lpfc_sli4_cfg_mhdr));
12861 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12862 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
12863 length, LPFC_SLI4_MBX_EMBED);
12864 eq_delay = &mbox->u.mqe.un.eq_delay;
12865
12866 /* Calculate delay multiper from maximum interrupt per second */
James Smartee020062012-09-29 11:28:52 -040012867 result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
12868 if (result > LPFC_DMULT_CONST)
12869 dmult = 0;
12870 else
12871 dmult = LPFC_DMULT_CONST/result - 1;
James Smart173edbb2012-06-12 13:54:50 -040012872
12873 cnt = 0;
James Smart67d12732012-08-03 12:36:13 -040012874 for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
James Smart173edbb2012-06-12 13:54:50 -040012875 fcp_eqidx++) {
James Smart67d12732012-08-03 12:36:13 -040012876 eq = phba->sli4_hba.hba_eq[fcp_eqidx];
James Smart173edbb2012-06-12 13:54:50 -040012877 if (!eq)
12878 continue;
12879 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
12880 eq_delay->u.request.eq[cnt].phase = 0;
12881 eq_delay->u.request.eq[cnt].delay_multi = dmult;
12882 cnt++;
12883 if (cnt >= LPFC_MAX_EQ_DELAY)
12884 break;
12885 }
12886 eq_delay->u.request.num_eq = cnt;
12887
12888 mbox->vport = phba->pport;
12889 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12890 mbox->context1 = NULL;
12891 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
12892 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
12893 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12894 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
12895 if (shdr_status || shdr_add_status || rc) {
12896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12897 "2512 MODIFY_EQ_DELAY mailbox failed with "
12898 "status x%x add_status x%x, mbx status x%x\n",
12899 shdr_status, shdr_add_status, rc);
12900 status = -ENXIO;
12901 }
12902 mempool_free(mbox, phba->mbox_mem_pool);
12903 return status;
12904}
12905
12906/**
James Smart4f774512009-05-22 14:52:35 -040012907 * lpfc_eq_create - Create an Event Queue on the HBA
12908 * @phba: HBA structure that indicates port to create a queue on.
12909 * @eq: The queue structure to use to create the event queue.
12910 * @imax: The maximum interrupt per second limit.
12911 *
12912 * This function creates an event queue, as detailed in @eq, on a port,
12913 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12914 *
12915 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12916 * is used to get the entry count and entry size that are necessary to
12917 * determine the number of pages to allocate and use for this queue. This
12918 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12919 * event queue. This function is asynchronous and will wait for the mailbox
12920 * command to finish before continuing.
12921 *
12922 * On success this function will return a zero. If unable to allocate enough
James Smartd439d282010-09-29 11:18:45 -040012923 * memory this function will return -ENOMEM. If the queue create mailbox command
12924 * fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040012925 **/
12926uint32_t
James Smartee020062012-09-29 11:28:52 -040012927lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
James Smart4f774512009-05-22 14:52:35 -040012928{
12929 struct lpfc_mbx_eq_create *eq_create;
12930 LPFC_MBOXQ_t *mbox;
12931 int rc, length, status = 0;
12932 struct lpfc_dmabuf *dmabuf;
12933 uint32_t shdr_status, shdr_add_status;
12934 union lpfc_sli4_cfg_shdr *shdr;
12935 uint16_t dmult;
James Smart49198b32010-04-06 15:04:33 -040012936 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
12937
James Smart2e90f4b2011-12-13 13:22:37 -050012938 /* sanity check on queue memory */
12939 if (!eq)
12940 return -ENODEV;
James Smart49198b32010-04-06 15:04:33 -040012941 if (!phba->sli4_hba.pc_sli4_params.supported)
12942 hw_page_size = SLI4_PAGE_SIZE;
James Smart4f774512009-05-22 14:52:35 -040012943
12944 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12945 if (!mbox)
12946 return -ENOMEM;
12947 length = (sizeof(struct lpfc_mbx_eq_create) -
12948 sizeof(struct lpfc_sli4_cfg_mhdr));
12949 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
12950 LPFC_MBOX_OPCODE_EQ_CREATE,
12951 length, LPFC_SLI4_MBX_EMBED);
12952 eq_create = &mbox->u.mqe.un.eq_create;
12953 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
12954 eq->page_count);
12955 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
12956 LPFC_EQE_SIZE);
12957 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
12958 /* Calculate delay multiper from maximum interrupt per second */
James Smartee020062012-09-29 11:28:52 -040012959 if (imax > LPFC_DMULT_CONST)
12960 dmult = 0;
12961 else
12962 dmult = LPFC_DMULT_CONST/imax - 1;
James Smart4f774512009-05-22 14:52:35 -040012963 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
12964 dmult);
12965 switch (eq->entry_count) {
12966 default:
12967 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12968 "0360 Unsupported EQ count. (%d)\n",
12969 eq->entry_count);
12970 if (eq->entry_count < 256)
12971 return -EINVAL;
12972 /* otherwise default to smallest count (drop through) */
12973 case 256:
12974 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12975 LPFC_EQ_CNT_256);
12976 break;
12977 case 512:
12978 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12979 LPFC_EQ_CNT_512);
12980 break;
12981 case 1024:
12982 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12983 LPFC_EQ_CNT_1024);
12984 break;
12985 case 2048:
12986 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12987 LPFC_EQ_CNT_2048);
12988 break;
12989 case 4096:
12990 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
12991 LPFC_EQ_CNT_4096);
12992 break;
12993 }
12994 list_for_each_entry(dmabuf, &eq->page_list, list) {
James Smart49198b32010-04-06 15:04:33 -040012995 memset(dmabuf->virt, 0, hw_page_size);
James Smart4f774512009-05-22 14:52:35 -040012996 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
12997 putPaddrLow(dmabuf->phys);
12998 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
12999 putPaddrHigh(dmabuf->phys);
13000 }
13001 mbox->vport = phba->pport;
13002 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13003 mbox->context1 = NULL;
13004 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13005 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
13006 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13007 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13008 if (shdr_status || shdr_add_status || rc) {
13009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13010 "2500 EQ_CREATE mailbox failed with "
13011 "status x%x add_status x%x, mbx status x%x\n",
13012 shdr_status, shdr_add_status, rc);
13013 status = -ENXIO;
13014 }
13015 eq->type = LPFC_EQ;
13016 eq->subtype = LPFC_NONE;
13017 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
13018 if (eq->queue_id == 0xFFFF)
13019 status = -ENXIO;
13020 eq->host_index = 0;
13021 eq->hba_index = 0;
13022
James Smart8fa38512009-07-19 10:01:03 -040013023 mempool_free(mbox, phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040013024 return status;
13025}
13026
13027/**
13028 * lpfc_cq_create - Create a Completion Queue on the HBA
13029 * @phba: HBA structure that indicates port to create a queue on.
13030 * @cq: The queue structure to use to create the completion queue.
13031 * @eq: The event queue to bind this completion queue to.
13032 *
13033 * This function creates a completion queue, as detailed in @wq, on a port,
13034 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
13035 *
13036 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13037 * is used to get the entry count and entry size that are necessary to
13038 * determine the number of pages to allocate and use for this queue. The @eq
13039 * is used to indicate which event queue to bind this completion queue to. This
13040 * function will send the CQ_CREATE mailbox command to the HBA to setup the
13041 * completion queue. This function is asynchronous and will wait for the mailbox
13042 * command to finish before continuing.
13043 *
13044 * On success this function will return a zero. If unable to allocate enough
James Smartd439d282010-09-29 11:18:45 -040013045 * memory this function will return -ENOMEM. If the queue create mailbox command
13046 * fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040013047 **/
13048uint32_t
13049lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
13050 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
13051{
13052 struct lpfc_mbx_cq_create *cq_create;
13053 struct lpfc_dmabuf *dmabuf;
13054 LPFC_MBOXQ_t *mbox;
13055 int rc, length, status = 0;
13056 uint32_t shdr_status, shdr_add_status;
13057 union lpfc_sli4_cfg_shdr *shdr;
James Smart49198b32010-04-06 15:04:33 -040013058 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
13059
James Smart2e90f4b2011-12-13 13:22:37 -050013060 /* sanity check on queue memory */
13061 if (!cq || !eq)
13062 return -ENODEV;
James Smart49198b32010-04-06 15:04:33 -040013063 if (!phba->sli4_hba.pc_sli4_params.supported)
13064 hw_page_size = SLI4_PAGE_SIZE;
13065
James Smart4f774512009-05-22 14:52:35 -040013066 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13067 if (!mbox)
13068 return -ENOMEM;
13069 length = (sizeof(struct lpfc_mbx_cq_create) -
13070 sizeof(struct lpfc_sli4_cfg_mhdr));
13071 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13072 LPFC_MBOX_OPCODE_CQ_CREATE,
13073 length, LPFC_SLI4_MBX_EMBED);
13074 cq_create = &mbox->u.mqe.un.cq_create;
James Smart5a6f1332011-03-11 16:05:35 -050013075 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
James Smart4f774512009-05-22 14:52:35 -040013076 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
13077 cq->page_count);
13078 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
13079 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
James Smart5a6f1332011-03-11 16:05:35 -050013080 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13081 phba->sli4_hba.pc_sli4_params.cqv);
13082 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
James Smartc31098c2011-04-16 11:03:33 -040013083 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
13084 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
James Smart5a6f1332011-03-11 16:05:35 -050013085 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
13086 eq->queue_id);
13087 } else {
13088 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
13089 eq->queue_id);
13090 }
James Smart4f774512009-05-22 14:52:35 -040013091 switch (cq->entry_count) {
13092 default:
13093 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13094 "0361 Unsupported CQ count. (%d)\n",
13095 cq->entry_count);
James Smart4f4c1862012-06-12 13:54:02 -040013096 if (cq->entry_count < 256) {
13097 status = -EINVAL;
13098 goto out;
13099 }
James Smart4f774512009-05-22 14:52:35 -040013100 /* otherwise default to smallest count (drop through) */
13101 case 256:
13102 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
13103 LPFC_CQ_CNT_256);
13104 break;
13105 case 512:
13106 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
13107 LPFC_CQ_CNT_512);
13108 break;
13109 case 1024:
13110 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
13111 LPFC_CQ_CNT_1024);
13112 break;
13113 }
13114 list_for_each_entry(dmabuf, &cq->page_list, list) {
James Smart49198b32010-04-06 15:04:33 -040013115 memset(dmabuf->virt, 0, hw_page_size);
James Smart4f774512009-05-22 14:52:35 -040013116 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
13117 putPaddrLow(dmabuf->phys);
13118 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
13119 putPaddrHigh(dmabuf->phys);
13120 }
13121 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13122
13123 /* The IOCTL status is embedded in the mailbox subheader. */
James Smart4f774512009-05-22 14:52:35 -040013124 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13125 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13126 if (shdr_status || shdr_add_status || rc) {
13127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13128 "2501 CQ_CREATE mailbox failed with "
13129 "status x%x add_status x%x, mbx status x%x\n",
13130 shdr_status, shdr_add_status, rc);
13131 status = -ENXIO;
13132 goto out;
13133 }
13134 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
13135 if (cq->queue_id == 0xFFFF) {
13136 status = -ENXIO;
13137 goto out;
13138 }
13139 /* link the cq onto the parent eq child list */
13140 list_add_tail(&cq->list, &eq->child_list);
13141 /* Set up completion queue's type and subtype */
13142 cq->type = type;
13143 cq->subtype = subtype;
13144 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
James Smart2a622bf2011-02-16 12:40:06 -050013145 cq->assoc_qid = eq->queue_id;
James Smart4f774512009-05-22 14:52:35 -040013146 cq->host_index = 0;
13147 cq->hba_index = 0;
James Smart4f774512009-05-22 14:52:35 -040013148
James Smart8fa38512009-07-19 10:01:03 -040013149out:
13150 mempool_free(mbox, phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040013151 return status;
13152}
13153
13154/**
James Smartb19a0612010-04-06 14:48:51 -040013155 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
James Smart04c68492009-05-22 14:52:52 -040013156 * @phba: HBA structure that indicates port to create a queue on.
13157 * @mq: The queue structure to use to create the mailbox queue.
James Smartb19a0612010-04-06 14:48:51 -040013158 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
13159 * @cq: The completion queue to associate with this cq.
James Smart04c68492009-05-22 14:52:52 -040013160 *
James Smartb19a0612010-04-06 14:48:51 -040013161 * This function provides failback (fb) functionality when the
13162 * mq_create_ext fails on older FW generations. It's purpose is identical
13163 * to mq_create_ext otherwise.
James Smart04c68492009-05-22 14:52:52 -040013164 *
James Smartb19a0612010-04-06 14:48:51 -040013165 * This routine cannot fail as all attributes were previously accessed and
13166 * initialized in mq_create_ext.
James Smart04c68492009-05-22 14:52:52 -040013167 **/
James Smartb19a0612010-04-06 14:48:51 -040013168static void
13169lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
13170 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
James Smart04c68492009-05-22 14:52:52 -040013171{
13172 struct lpfc_mbx_mq_create *mq_create;
13173 struct lpfc_dmabuf *dmabuf;
James Smartb19a0612010-04-06 14:48:51 -040013174 int length;
James Smart04c68492009-05-22 14:52:52 -040013175
James Smart04c68492009-05-22 14:52:52 -040013176 length = (sizeof(struct lpfc_mbx_mq_create) -
13177 sizeof(struct lpfc_sli4_cfg_mhdr));
13178 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13179 LPFC_MBOX_OPCODE_MQ_CREATE,
13180 length, LPFC_SLI4_MBX_EMBED);
13181 mq_create = &mbox->u.mqe.un.mq_create;
13182 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
James Smartb19a0612010-04-06 14:48:51 -040013183 mq->page_count);
James Smart04c68492009-05-22 14:52:52 -040013184 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
James Smartb19a0612010-04-06 14:48:51 -040013185 cq->queue_id);
James Smart04c68492009-05-22 14:52:52 -040013186 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
13187 switch (mq->entry_count) {
James Smart04c68492009-05-22 14:52:52 -040013188 case 16:
James Smart5a6f1332011-03-11 16:05:35 -050013189 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
13190 LPFC_MQ_RING_SIZE_16);
James Smart04c68492009-05-22 14:52:52 -040013191 break;
13192 case 32:
James Smart5a6f1332011-03-11 16:05:35 -050013193 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
13194 LPFC_MQ_RING_SIZE_32);
James Smart04c68492009-05-22 14:52:52 -040013195 break;
13196 case 64:
James Smart5a6f1332011-03-11 16:05:35 -050013197 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
13198 LPFC_MQ_RING_SIZE_64);
James Smart04c68492009-05-22 14:52:52 -040013199 break;
13200 case 128:
James Smart5a6f1332011-03-11 16:05:35 -050013201 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
13202 LPFC_MQ_RING_SIZE_128);
James Smart04c68492009-05-22 14:52:52 -040013203 break;
13204 }
13205 list_for_each_entry(dmabuf, &mq->page_list, list) {
13206 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
James Smartb19a0612010-04-06 14:48:51 -040013207 putPaddrLow(dmabuf->phys);
James Smart04c68492009-05-22 14:52:52 -040013208 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
James Smartb19a0612010-04-06 14:48:51 -040013209 putPaddrHigh(dmabuf->phys);
13210 }
13211}
13212
13213/**
13214 * lpfc_mq_create - Create a mailbox Queue on the HBA
13215 * @phba: HBA structure that indicates port to create a queue on.
13216 * @mq: The queue structure to use to create the mailbox queue.
13217 * @cq: The completion queue to associate with this cq.
13218 * @subtype: The queue's subtype.
13219 *
13220 * This function creates a mailbox queue, as detailed in @mq, on a port,
13221 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
13222 *
13223 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13224 * is used to get the entry count and entry size that are necessary to
13225 * determine the number of pages to allocate and use for this queue. This
13226 * function will send the MQ_CREATE mailbox command to the HBA to setup the
13227 * mailbox queue. This function is asynchronous and will wait for the mailbox
13228 * command to finish before continuing.
13229 *
13230 * On success this function will return a zero. If unable to allocate enough
James Smartd439d282010-09-29 11:18:45 -040013231 * memory this function will return -ENOMEM. If the queue create mailbox command
13232 * fails this function will return -ENXIO.
James Smartb19a0612010-04-06 14:48:51 -040013233 **/
13234int32_t
13235lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
13236 struct lpfc_queue *cq, uint32_t subtype)
13237{
13238 struct lpfc_mbx_mq_create *mq_create;
13239 struct lpfc_mbx_mq_create_ext *mq_create_ext;
13240 struct lpfc_dmabuf *dmabuf;
13241 LPFC_MBOXQ_t *mbox;
13242 int rc, length, status = 0;
13243 uint32_t shdr_status, shdr_add_status;
13244 union lpfc_sli4_cfg_shdr *shdr;
James Smart49198b32010-04-06 15:04:33 -040013245 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
James Smartb19a0612010-04-06 14:48:51 -040013246
James Smart2e90f4b2011-12-13 13:22:37 -050013247 /* sanity check on queue memory */
13248 if (!mq || !cq)
13249 return -ENODEV;
James Smart49198b32010-04-06 15:04:33 -040013250 if (!phba->sli4_hba.pc_sli4_params.supported)
13251 hw_page_size = SLI4_PAGE_SIZE;
James Smartb19a0612010-04-06 14:48:51 -040013252
13253 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13254 if (!mbox)
13255 return -ENOMEM;
13256 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
13257 sizeof(struct lpfc_sli4_cfg_mhdr));
13258 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13259 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
13260 length, LPFC_SLI4_MBX_EMBED);
13261
13262 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
James Smart5a6f1332011-03-11 16:05:35 -050013263 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
James Smart70f3c072010-12-15 17:57:33 -050013264 bf_set(lpfc_mbx_mq_create_ext_num_pages,
13265 &mq_create_ext->u.request, mq->page_count);
13266 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
13267 &mq_create_ext->u.request, 1);
13268 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
James Smartb19a0612010-04-06 14:48:51 -040013269 &mq_create_ext->u.request, 1);
13270 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
13271 &mq_create_ext->u.request, 1);
James Smart70f3c072010-12-15 17:57:33 -050013272 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
13273 &mq_create_ext->u.request, 1);
13274 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
13275 &mq_create_ext->u.request, 1);
James Smartb19a0612010-04-06 14:48:51 -040013276 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
James Smart5a6f1332011-03-11 16:05:35 -050013277 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13278 phba->sli4_hba.pc_sli4_params.mqv);
13279 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
13280 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
13281 cq->queue_id);
13282 else
13283 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
13284 cq->queue_id);
James Smartb19a0612010-04-06 14:48:51 -040013285 switch (mq->entry_count) {
13286 default:
13287 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13288 "0362 Unsupported MQ count. (%d)\n",
13289 mq->entry_count);
James Smart4f4c1862012-06-12 13:54:02 -040013290 if (mq->entry_count < 16) {
13291 status = -EINVAL;
13292 goto out;
13293 }
James Smartb19a0612010-04-06 14:48:51 -040013294 /* otherwise default to smallest count (drop through) */
13295 case 16:
James Smart5a6f1332011-03-11 16:05:35 -050013296 bf_set(lpfc_mq_context_ring_size,
13297 &mq_create_ext->u.request.context,
13298 LPFC_MQ_RING_SIZE_16);
James Smartb19a0612010-04-06 14:48:51 -040013299 break;
13300 case 32:
James Smart5a6f1332011-03-11 16:05:35 -050013301 bf_set(lpfc_mq_context_ring_size,
13302 &mq_create_ext->u.request.context,
13303 LPFC_MQ_RING_SIZE_32);
James Smartb19a0612010-04-06 14:48:51 -040013304 break;
13305 case 64:
James Smart5a6f1332011-03-11 16:05:35 -050013306 bf_set(lpfc_mq_context_ring_size,
13307 &mq_create_ext->u.request.context,
13308 LPFC_MQ_RING_SIZE_64);
James Smartb19a0612010-04-06 14:48:51 -040013309 break;
13310 case 128:
James Smart5a6f1332011-03-11 16:05:35 -050013311 bf_set(lpfc_mq_context_ring_size,
13312 &mq_create_ext->u.request.context,
13313 LPFC_MQ_RING_SIZE_128);
James Smartb19a0612010-04-06 14:48:51 -040013314 break;
13315 }
13316 list_for_each_entry(dmabuf, &mq->page_list, list) {
James Smart49198b32010-04-06 15:04:33 -040013317 memset(dmabuf->virt, 0, hw_page_size);
James Smartb19a0612010-04-06 14:48:51 -040013318 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
13319 putPaddrLow(dmabuf->phys);
13320 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
James Smart04c68492009-05-22 14:52:52 -040013321 putPaddrHigh(dmabuf->phys);
13322 }
13323 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
James Smartb19a0612010-04-06 14:48:51 -040013324 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
13325 &mq_create_ext->u.response);
13326 if (rc != MBX_SUCCESS) {
13327 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13328 "2795 MQ_CREATE_EXT failed with "
13329 "status x%x. Failback to MQ_CREATE.\n",
13330 rc);
13331 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
13332 mq_create = &mbox->u.mqe.un.mq_create;
13333 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13334 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
13335 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
13336 &mq_create->u.response);
13337 }
13338
James Smart04c68492009-05-22 14:52:52 -040013339 /* The IOCTL status is embedded in the mailbox subheader. */
James Smart04c68492009-05-22 14:52:52 -040013340 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13341 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13342 if (shdr_status || shdr_add_status || rc) {
13343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13344 "2502 MQ_CREATE mailbox failed with "
13345 "status x%x add_status x%x, mbx status x%x\n",
13346 shdr_status, shdr_add_status, rc);
13347 status = -ENXIO;
13348 goto out;
13349 }
James Smart04c68492009-05-22 14:52:52 -040013350 if (mq->queue_id == 0xFFFF) {
13351 status = -ENXIO;
13352 goto out;
13353 }
13354 mq->type = LPFC_MQ;
James Smart2a622bf2011-02-16 12:40:06 -050013355 mq->assoc_qid = cq->queue_id;
James Smart04c68492009-05-22 14:52:52 -040013356 mq->subtype = subtype;
13357 mq->host_index = 0;
13358 mq->hba_index = 0;
13359
13360 /* link the mq onto the parent cq child list */
13361 list_add_tail(&mq->list, &cq->child_list);
13362out:
James Smart8fa38512009-07-19 10:01:03 -040013363 mempool_free(mbox, phba->mbox_mem_pool);
James Smart04c68492009-05-22 14:52:52 -040013364 return status;
13365}
13366
13367/**
James Smart4f774512009-05-22 14:52:35 -040013368 * lpfc_wq_create - Create a Work Queue on the HBA
13369 * @phba: HBA structure that indicates port to create a queue on.
13370 * @wq: The queue structure to use to create the work queue.
13371 * @cq: The completion queue to bind this work queue to.
13372 * @subtype: The subtype of the work queue indicating its functionality.
13373 *
13374 * This function creates a work queue, as detailed in @wq, on a port, described
13375 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
13376 *
13377 * The @phba struct is used to send mailbox command to HBA. The @wq struct
13378 * is used to get the entry count and entry size that are necessary to
13379 * determine the number of pages to allocate and use for this queue. The @cq
13380 * is used to indicate which completion queue to bind this work queue to. This
13381 * function will send the WQ_CREATE mailbox command to the HBA to setup the
13382 * work queue. This function is asynchronous and will wait for the mailbox
13383 * command to finish before continuing.
13384 *
13385 * On success this function will return a zero. If unable to allocate enough
James Smartd439d282010-09-29 11:18:45 -040013386 * memory this function will return -ENOMEM. If the queue create mailbox command
13387 * fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040013388 **/
13389uint32_t
13390lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
13391 struct lpfc_queue *cq, uint32_t subtype)
13392{
13393 struct lpfc_mbx_wq_create *wq_create;
13394 struct lpfc_dmabuf *dmabuf;
13395 LPFC_MBOXQ_t *mbox;
13396 int rc, length, status = 0;
13397 uint32_t shdr_status, shdr_add_status;
13398 union lpfc_sli4_cfg_shdr *shdr;
James Smart49198b32010-04-06 15:04:33 -040013399 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
James Smart5a6f1332011-03-11 16:05:35 -050013400 struct dma_address *page;
James Smart962bc512013-01-03 15:44:00 -050013401 void __iomem *bar_memmap_p;
13402 uint32_t db_offset;
13403 uint16_t pci_barset;
James Smart49198b32010-04-06 15:04:33 -040013404
James Smart2e90f4b2011-12-13 13:22:37 -050013405 /* sanity check on queue memory */
13406 if (!wq || !cq)
13407 return -ENODEV;
James Smart49198b32010-04-06 15:04:33 -040013408 if (!phba->sli4_hba.pc_sli4_params.supported)
13409 hw_page_size = SLI4_PAGE_SIZE;
James Smart4f774512009-05-22 14:52:35 -040013410
13411 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13412 if (!mbox)
13413 return -ENOMEM;
13414 length = (sizeof(struct lpfc_mbx_wq_create) -
13415 sizeof(struct lpfc_sli4_cfg_mhdr));
13416 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13417 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
13418 length, LPFC_SLI4_MBX_EMBED);
13419 wq_create = &mbox->u.mqe.un.wq_create;
James Smart5a6f1332011-03-11 16:05:35 -050013420 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
James Smart4f774512009-05-22 14:52:35 -040013421 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
13422 wq->page_count);
13423 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
13424 cq->queue_id);
James Smart0c651872013-07-15 18:33:23 -040013425
13426 /* wqv is the earliest version supported, NOT the latest */
James Smart5a6f1332011-03-11 16:05:35 -050013427 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13428 phba->sli4_hba.pc_sli4_params.wqv);
James Smart962bc512013-01-03 15:44:00 -050013429
James Smart0c651872013-07-15 18:33:23 -040013430 switch (phba->sli4_hba.pc_sli4_params.wqv) {
13431 case LPFC_Q_CREATE_VERSION_0:
13432 switch (wq->entry_size) {
13433 default:
13434 case 64:
13435 /* Nothing to do, version 0 ONLY supports 64 byte */
13436 page = wq_create->u.request.page;
13437 break;
13438 case 128:
13439 if (!(phba->sli4_hba.pc_sli4_params.wqsize &
13440 LPFC_WQ_SZ128_SUPPORT)) {
13441 status = -ERANGE;
13442 goto out;
13443 }
13444 /* If we get here the HBA MUST also support V1 and
13445 * we MUST use it
13446 */
13447 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13448 LPFC_Q_CREATE_VERSION_1);
13449
13450 bf_set(lpfc_mbx_wq_create_wqe_count,
13451 &wq_create->u.request_1, wq->entry_count);
13452 bf_set(lpfc_mbx_wq_create_wqe_size,
13453 &wq_create->u.request_1,
13454 LPFC_WQ_WQE_SIZE_128);
13455 bf_set(lpfc_mbx_wq_create_page_size,
13456 &wq_create->u.request_1,
13457 (PAGE_SIZE/SLI4_PAGE_SIZE));
13458 page = wq_create->u.request_1.page;
13459 break;
13460 }
13461 break;
13462 case LPFC_Q_CREATE_VERSION_1:
James Smart5a6f1332011-03-11 16:05:35 -050013463 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
13464 wq->entry_count);
13465 switch (wq->entry_size) {
13466 default:
13467 case 64:
13468 bf_set(lpfc_mbx_wq_create_wqe_size,
13469 &wq_create->u.request_1,
13470 LPFC_WQ_WQE_SIZE_64);
13471 break;
13472 case 128:
James Smart0c651872013-07-15 18:33:23 -040013473 if (!(phba->sli4_hba.pc_sli4_params.wqsize &
13474 LPFC_WQ_SZ128_SUPPORT)) {
13475 status = -ERANGE;
13476 goto out;
13477 }
James Smart5a6f1332011-03-11 16:05:35 -050013478 bf_set(lpfc_mbx_wq_create_wqe_size,
13479 &wq_create->u.request_1,
13480 LPFC_WQ_WQE_SIZE_128);
13481 break;
13482 }
13483 bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
13484 (PAGE_SIZE/SLI4_PAGE_SIZE));
13485 page = wq_create->u.request_1.page;
James Smart0c651872013-07-15 18:33:23 -040013486 break;
13487 default:
13488 status = -ERANGE;
13489 goto out;
James Smart5a6f1332011-03-11 16:05:35 -050013490 }
James Smart0c651872013-07-15 18:33:23 -040013491
James Smart4f774512009-05-22 14:52:35 -040013492 list_for_each_entry(dmabuf, &wq->page_list, list) {
James Smart49198b32010-04-06 15:04:33 -040013493 memset(dmabuf->virt, 0, hw_page_size);
James Smart5a6f1332011-03-11 16:05:35 -050013494 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
13495 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
James Smart4f774512009-05-22 14:52:35 -040013496 }
James Smart962bc512013-01-03 15:44:00 -050013497
13498 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
13499 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
13500
James Smart4f774512009-05-22 14:52:35 -040013501 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13502 /* The IOCTL status is embedded in the mailbox subheader. */
James Smart4f774512009-05-22 14:52:35 -040013503 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13504 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13505 if (shdr_status || shdr_add_status || rc) {
13506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13507 "2503 WQ_CREATE mailbox failed with "
13508 "status x%x add_status x%x, mbx status x%x\n",
13509 shdr_status, shdr_add_status, rc);
13510 status = -ENXIO;
13511 goto out;
13512 }
13513 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
13514 if (wq->queue_id == 0xFFFF) {
13515 status = -ENXIO;
13516 goto out;
13517 }
James Smart962bc512013-01-03 15:44:00 -050013518 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
13519 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
13520 &wq_create->u.response);
13521 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
13522 (wq->db_format != LPFC_DB_RING_FORMAT)) {
13523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13524 "3265 WQ[%d] doorbell format not "
13525 "supported: x%x\n", wq->queue_id,
13526 wq->db_format);
13527 status = -EINVAL;
13528 goto out;
13529 }
13530 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
13531 &wq_create->u.response);
13532 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
13533 if (!bar_memmap_p) {
13534 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13535 "3263 WQ[%d] failed to memmap pci "
13536 "barset:x%x\n", wq->queue_id,
13537 pci_barset);
13538 status = -ENOMEM;
13539 goto out;
13540 }
13541 db_offset = wq_create->u.response.doorbell_offset;
13542 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
13543 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
13544 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13545 "3252 WQ[%d] doorbell offset not "
13546 "supported: x%x\n", wq->queue_id,
13547 db_offset);
13548 status = -EINVAL;
13549 goto out;
13550 }
13551 wq->db_regaddr = bar_memmap_p + db_offset;
13552 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarta22e7db2013-04-17 20:16:37 -040013553 "3264 WQ[%d]: barset:x%x, offset:x%x, "
13554 "format:x%x\n", wq->queue_id, pci_barset,
13555 db_offset, wq->db_format);
James Smart962bc512013-01-03 15:44:00 -050013556 } else {
13557 wq->db_format = LPFC_DB_LIST_FORMAT;
13558 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
13559 }
James Smart4f774512009-05-22 14:52:35 -040013560 wq->type = LPFC_WQ;
James Smart2a622bf2011-02-16 12:40:06 -050013561 wq->assoc_qid = cq->queue_id;
James Smart4f774512009-05-22 14:52:35 -040013562 wq->subtype = subtype;
13563 wq->host_index = 0;
13564 wq->hba_index = 0;
James Smartff78d8f2011-12-13 13:21:35 -050013565 wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
James Smart4f774512009-05-22 14:52:35 -040013566
13567 /* link the wq onto the parent cq child list */
13568 list_add_tail(&wq->list, &cq->child_list);
13569out:
James Smart8fa38512009-07-19 10:01:03 -040013570 mempool_free(mbox, phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040013571 return status;
13572}
13573
13574/**
James Smart73d91e52011-10-10 21:32:10 -040013575 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
13576 * @phba: HBA structure that indicates port to create a queue on.
13577 * @rq: The queue structure to use for the receive queue.
13578 * @qno: The associated HBQ number
13579 *
13580 *
13581 * For SLI4 we need to adjust the RQ repost value based on
13582 * the number of buffers that are initially posted to the RQ.
13583 */
13584void
13585lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
13586{
13587 uint32_t cnt;
13588
James Smart2e90f4b2011-12-13 13:22:37 -050013589 /* sanity check on queue memory */
13590 if (!rq)
13591 return;
James Smart73d91e52011-10-10 21:32:10 -040013592 cnt = lpfc_hbq_defs[qno]->entry_count;
13593
13594 /* Recalc repost for RQs based on buffers initially posted */
13595 cnt = (cnt >> 3);
13596 if (cnt < LPFC_QUEUE_MIN_REPOST)
13597 cnt = LPFC_QUEUE_MIN_REPOST;
13598
13599 rq->entry_repost = cnt;
13600}
13601
13602/**
James Smart4f774512009-05-22 14:52:35 -040013603 * lpfc_rq_create - Create a Receive Queue on the HBA
13604 * @phba: HBA structure that indicates port to create a queue on.
13605 * @hrq: The queue structure to use to create the header receive queue.
13606 * @drq: The queue structure to use to create the data receive queue.
13607 * @cq: The completion queue to bind this work queue to.
13608 *
13609 * This function creates a receive buffer queue pair , as detailed in @hrq and
13610 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
13611 * to the HBA.
13612 *
13613 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
13614 * struct is used to get the entry count that is necessary to determine the
13615 * number of pages to use for this queue. The @cq is used to indicate which
13616 * completion queue to bind received buffers that are posted to these queues to.
13617 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
13618 * receive queue pair. This function is asynchronous and will wait for the
13619 * mailbox command to finish before continuing.
13620 *
13621 * On success this function will return a zero. If unable to allocate enough
James Smartd439d282010-09-29 11:18:45 -040013622 * memory this function will return -ENOMEM. If the queue create mailbox command
13623 * fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040013624 **/
13625uint32_t
13626lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
13627 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
13628{
13629 struct lpfc_mbx_rq_create *rq_create;
13630 struct lpfc_dmabuf *dmabuf;
13631 LPFC_MBOXQ_t *mbox;
13632 int rc, length, status = 0;
13633 uint32_t shdr_status, shdr_add_status;
13634 union lpfc_sli4_cfg_shdr *shdr;
James Smart49198b32010-04-06 15:04:33 -040013635 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
James Smart962bc512013-01-03 15:44:00 -050013636 void __iomem *bar_memmap_p;
13637 uint32_t db_offset;
13638 uint16_t pci_barset;
James Smart49198b32010-04-06 15:04:33 -040013639
James Smart2e90f4b2011-12-13 13:22:37 -050013640 /* sanity check on queue memory */
13641 if (!hrq || !drq || !cq)
13642 return -ENODEV;
James Smart49198b32010-04-06 15:04:33 -040013643 if (!phba->sli4_hba.pc_sli4_params.supported)
13644 hw_page_size = SLI4_PAGE_SIZE;
James Smart4f774512009-05-22 14:52:35 -040013645
13646 if (hrq->entry_count != drq->entry_count)
13647 return -EINVAL;
13648 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13649 if (!mbox)
13650 return -ENOMEM;
13651 length = (sizeof(struct lpfc_mbx_rq_create) -
13652 sizeof(struct lpfc_sli4_cfg_mhdr));
13653 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13654 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
13655 length, LPFC_SLI4_MBX_EMBED);
13656 rq_create = &mbox->u.mqe.un.rq_create;
James Smart5a6f1332011-03-11 16:05:35 -050013657 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
13658 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13659 phba->sli4_hba.pc_sli4_params.rqv);
13660 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
13661 bf_set(lpfc_rq_context_rqe_count_1,
13662 &rq_create->u.request.context,
13663 hrq->entry_count);
13664 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
James Smartc31098c2011-04-16 11:03:33 -040013665 bf_set(lpfc_rq_context_rqe_size,
13666 &rq_create->u.request.context,
13667 LPFC_RQE_SIZE_8);
13668 bf_set(lpfc_rq_context_page_size,
13669 &rq_create->u.request.context,
13670 (PAGE_SIZE/SLI4_PAGE_SIZE));
James Smart5a6f1332011-03-11 16:05:35 -050013671 } else {
13672 switch (hrq->entry_count) {
13673 default:
13674 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13675 "2535 Unsupported RQ count. (%d)\n",
13676 hrq->entry_count);
James Smart4f4c1862012-06-12 13:54:02 -040013677 if (hrq->entry_count < 512) {
13678 status = -EINVAL;
13679 goto out;
13680 }
James Smart5a6f1332011-03-11 16:05:35 -050013681 /* otherwise default to smallest count (drop through) */
13682 case 512:
13683 bf_set(lpfc_rq_context_rqe_count,
13684 &rq_create->u.request.context,
13685 LPFC_RQ_RING_SIZE_512);
13686 break;
13687 case 1024:
13688 bf_set(lpfc_rq_context_rqe_count,
13689 &rq_create->u.request.context,
13690 LPFC_RQ_RING_SIZE_1024);
13691 break;
13692 case 2048:
13693 bf_set(lpfc_rq_context_rqe_count,
13694 &rq_create->u.request.context,
13695 LPFC_RQ_RING_SIZE_2048);
13696 break;
13697 case 4096:
13698 bf_set(lpfc_rq_context_rqe_count,
13699 &rq_create->u.request.context,
13700 LPFC_RQ_RING_SIZE_4096);
13701 break;
13702 }
13703 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
13704 LPFC_HDR_BUF_SIZE);
James Smart4f774512009-05-22 14:52:35 -040013705 }
13706 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
13707 cq->queue_id);
13708 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
13709 hrq->page_count);
James Smart4f774512009-05-22 14:52:35 -040013710 list_for_each_entry(dmabuf, &hrq->page_list, list) {
James Smart49198b32010-04-06 15:04:33 -040013711 memset(dmabuf->virt, 0, hw_page_size);
James Smart4f774512009-05-22 14:52:35 -040013712 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
13713 putPaddrLow(dmabuf->phys);
13714 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
13715 putPaddrHigh(dmabuf->phys);
13716 }
James Smart962bc512013-01-03 15:44:00 -050013717 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
13718 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
13719
James Smart4f774512009-05-22 14:52:35 -040013720 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13721 /* The IOCTL status is embedded in the mailbox subheader. */
James Smart4f774512009-05-22 14:52:35 -040013722 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13723 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13724 if (shdr_status || shdr_add_status || rc) {
13725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13726 "2504 RQ_CREATE mailbox failed with "
13727 "status x%x add_status x%x, mbx status x%x\n",
13728 shdr_status, shdr_add_status, rc);
13729 status = -ENXIO;
13730 goto out;
13731 }
13732 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
13733 if (hrq->queue_id == 0xFFFF) {
13734 status = -ENXIO;
13735 goto out;
13736 }
James Smart962bc512013-01-03 15:44:00 -050013737
13738 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
13739 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
13740 &rq_create->u.response);
13741 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
13742 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
13743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13744 "3262 RQ [%d] doorbell format not "
13745 "supported: x%x\n", hrq->queue_id,
13746 hrq->db_format);
13747 status = -EINVAL;
13748 goto out;
13749 }
13750
13751 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
13752 &rq_create->u.response);
13753 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
13754 if (!bar_memmap_p) {
13755 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13756 "3269 RQ[%d] failed to memmap pci "
13757 "barset:x%x\n", hrq->queue_id,
13758 pci_barset);
13759 status = -ENOMEM;
13760 goto out;
13761 }
13762
13763 db_offset = rq_create->u.response.doorbell_offset;
13764 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
13765 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
13766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13767 "3270 RQ[%d] doorbell offset not "
13768 "supported: x%x\n", hrq->queue_id,
13769 db_offset);
13770 status = -EINVAL;
13771 goto out;
13772 }
13773 hrq->db_regaddr = bar_memmap_p + db_offset;
13774 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarta22e7db2013-04-17 20:16:37 -040013775 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
13776 "format:x%x\n", hrq->queue_id, pci_barset,
13777 db_offset, hrq->db_format);
James Smart962bc512013-01-03 15:44:00 -050013778 } else {
13779 hrq->db_format = LPFC_DB_RING_FORMAT;
13780 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
13781 }
James Smart4f774512009-05-22 14:52:35 -040013782 hrq->type = LPFC_HRQ;
James Smart2a622bf2011-02-16 12:40:06 -050013783 hrq->assoc_qid = cq->queue_id;
James Smart4f774512009-05-22 14:52:35 -040013784 hrq->subtype = subtype;
13785 hrq->host_index = 0;
13786 hrq->hba_index = 0;
13787
13788 /* now create the data queue */
13789 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
13790 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
13791 length, LPFC_SLI4_MBX_EMBED);
James Smart5a6f1332011-03-11 16:05:35 -050013792 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13793 phba->sli4_hba.pc_sli4_params.rqv);
13794 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
13795 bf_set(lpfc_rq_context_rqe_count_1,
James Smartc31098c2011-04-16 11:03:33 -040013796 &rq_create->u.request.context, hrq->entry_count);
James Smart5a6f1332011-03-11 16:05:35 -050013797 rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
James Smartc31098c2011-04-16 11:03:33 -040013798 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
13799 LPFC_RQE_SIZE_8);
13800 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
13801 (PAGE_SIZE/SLI4_PAGE_SIZE));
James Smart5a6f1332011-03-11 16:05:35 -050013802 } else {
13803 switch (drq->entry_count) {
13804 default:
13805 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13806 "2536 Unsupported RQ count. (%d)\n",
13807 drq->entry_count);
James Smart4f4c1862012-06-12 13:54:02 -040013808 if (drq->entry_count < 512) {
13809 status = -EINVAL;
13810 goto out;
13811 }
James Smart5a6f1332011-03-11 16:05:35 -050013812 /* otherwise default to smallest count (drop through) */
13813 case 512:
13814 bf_set(lpfc_rq_context_rqe_count,
13815 &rq_create->u.request.context,
13816 LPFC_RQ_RING_SIZE_512);
13817 break;
13818 case 1024:
13819 bf_set(lpfc_rq_context_rqe_count,
13820 &rq_create->u.request.context,
13821 LPFC_RQ_RING_SIZE_1024);
13822 break;
13823 case 2048:
13824 bf_set(lpfc_rq_context_rqe_count,
13825 &rq_create->u.request.context,
13826 LPFC_RQ_RING_SIZE_2048);
13827 break;
13828 case 4096:
13829 bf_set(lpfc_rq_context_rqe_count,
13830 &rq_create->u.request.context,
13831 LPFC_RQ_RING_SIZE_4096);
13832 break;
13833 }
13834 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
13835 LPFC_DATA_BUF_SIZE);
James Smart4f774512009-05-22 14:52:35 -040013836 }
13837 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
13838 cq->queue_id);
13839 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
13840 drq->page_count);
James Smart4f774512009-05-22 14:52:35 -040013841 list_for_each_entry(dmabuf, &drq->page_list, list) {
13842 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
13843 putPaddrLow(dmabuf->phys);
13844 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
13845 putPaddrHigh(dmabuf->phys);
13846 }
James Smart962bc512013-01-03 15:44:00 -050013847 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
13848 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
James Smart4f774512009-05-22 14:52:35 -040013849 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13850 /* The IOCTL status is embedded in the mailbox subheader. */
13851 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
13852 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13853 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13854 if (shdr_status || shdr_add_status || rc) {
13855 status = -ENXIO;
13856 goto out;
13857 }
13858 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
13859 if (drq->queue_id == 0xFFFF) {
13860 status = -ENXIO;
13861 goto out;
13862 }
13863 drq->type = LPFC_DRQ;
James Smart2a622bf2011-02-16 12:40:06 -050013864 drq->assoc_qid = cq->queue_id;
James Smart4f774512009-05-22 14:52:35 -040013865 drq->subtype = subtype;
13866 drq->host_index = 0;
13867 drq->hba_index = 0;
13868
13869 /* link the header and data RQs onto the parent cq child list */
13870 list_add_tail(&hrq->list, &cq->child_list);
13871 list_add_tail(&drq->list, &cq->child_list);
13872
13873out:
James Smart8fa38512009-07-19 10:01:03 -040013874 mempool_free(mbox, phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040013875 return status;
13876}
13877
13878/**
13879 * lpfc_eq_destroy - Destroy an event Queue on the HBA
13880 * @eq: The queue structure associated with the queue to destroy.
13881 *
13882 * This function destroys a queue, as detailed in @eq by sending an mailbox
13883 * command, specific to the type of queue, to the HBA.
13884 *
13885 * The @eq struct is used to get the queue ID of the queue to destroy.
13886 *
13887 * On success this function will return a zero. If the queue destroy mailbox
James Smartd439d282010-09-29 11:18:45 -040013888 * command fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040013889 **/
13890uint32_t
13891lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
13892{
13893 LPFC_MBOXQ_t *mbox;
13894 int rc, length, status = 0;
13895 uint32_t shdr_status, shdr_add_status;
13896 union lpfc_sli4_cfg_shdr *shdr;
13897
James Smart2e90f4b2011-12-13 13:22:37 -050013898 /* sanity check on queue memory */
James Smart4f774512009-05-22 14:52:35 -040013899 if (!eq)
13900 return -ENODEV;
13901 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
13902 if (!mbox)
13903 return -ENOMEM;
13904 length = (sizeof(struct lpfc_mbx_eq_destroy) -
13905 sizeof(struct lpfc_sli4_cfg_mhdr));
13906 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13907 LPFC_MBOX_OPCODE_EQ_DESTROY,
13908 length, LPFC_SLI4_MBX_EMBED);
13909 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
13910 eq->queue_id);
13911 mbox->vport = eq->phba->pport;
13912 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13913
13914 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
13915 /* The IOCTL status is embedded in the mailbox subheader. */
13916 shdr = (union lpfc_sli4_cfg_shdr *)
13917 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
13918 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13919 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13920 if (shdr_status || shdr_add_status || rc) {
13921 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13922 "2505 EQ_DESTROY mailbox failed with "
13923 "status x%x add_status x%x, mbx status x%x\n",
13924 shdr_status, shdr_add_status, rc);
13925 status = -ENXIO;
13926 }
13927
13928 /* Remove eq from any list */
13929 list_del_init(&eq->list);
James Smart8fa38512009-07-19 10:01:03 -040013930 mempool_free(mbox, eq->phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040013931 return status;
13932}
13933
13934/**
13935 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
13936 * @cq: The queue structure associated with the queue to destroy.
13937 *
13938 * This function destroys a queue, as detailed in @cq by sending an mailbox
13939 * command, specific to the type of queue, to the HBA.
13940 *
13941 * The @cq struct is used to get the queue ID of the queue to destroy.
13942 *
13943 * On success this function will return a zero. If the queue destroy mailbox
James Smartd439d282010-09-29 11:18:45 -040013944 * command fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040013945 **/
13946uint32_t
13947lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
13948{
13949 LPFC_MBOXQ_t *mbox;
13950 int rc, length, status = 0;
13951 uint32_t shdr_status, shdr_add_status;
13952 union lpfc_sli4_cfg_shdr *shdr;
13953
James Smart2e90f4b2011-12-13 13:22:37 -050013954 /* sanity check on queue memory */
James Smart4f774512009-05-22 14:52:35 -040013955 if (!cq)
13956 return -ENODEV;
13957 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
13958 if (!mbox)
13959 return -ENOMEM;
13960 length = (sizeof(struct lpfc_mbx_cq_destroy) -
13961 sizeof(struct lpfc_sli4_cfg_mhdr));
13962 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13963 LPFC_MBOX_OPCODE_CQ_DESTROY,
13964 length, LPFC_SLI4_MBX_EMBED);
13965 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
13966 cq->queue_id);
13967 mbox->vport = cq->phba->pport;
13968 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13969 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
13970 /* The IOCTL status is embedded in the mailbox subheader. */
13971 shdr = (union lpfc_sli4_cfg_shdr *)
13972 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
13973 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13974 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13975 if (shdr_status || shdr_add_status || rc) {
13976 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13977 "2506 CQ_DESTROY mailbox failed with "
13978 "status x%x add_status x%x, mbx status x%x\n",
13979 shdr_status, shdr_add_status, rc);
13980 status = -ENXIO;
13981 }
13982 /* Remove cq from any list */
13983 list_del_init(&cq->list);
James Smart8fa38512009-07-19 10:01:03 -040013984 mempool_free(mbox, cq->phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040013985 return status;
13986}
13987
13988/**
James Smart04c68492009-05-22 14:52:52 -040013989 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
13990 * @qm: The queue structure associated with the queue to destroy.
13991 *
13992 * This function destroys a queue, as detailed in @mq by sending an mailbox
13993 * command, specific to the type of queue, to the HBA.
13994 *
13995 * The @mq struct is used to get the queue ID of the queue to destroy.
13996 *
13997 * On success this function will return a zero. If the queue destroy mailbox
James Smartd439d282010-09-29 11:18:45 -040013998 * command fails this function will return -ENXIO.
James Smart04c68492009-05-22 14:52:52 -040013999 **/
14000uint32_t
14001lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
14002{
14003 LPFC_MBOXQ_t *mbox;
14004 int rc, length, status = 0;
14005 uint32_t shdr_status, shdr_add_status;
14006 union lpfc_sli4_cfg_shdr *shdr;
14007
James Smart2e90f4b2011-12-13 13:22:37 -050014008 /* sanity check on queue memory */
James Smart04c68492009-05-22 14:52:52 -040014009 if (!mq)
14010 return -ENODEV;
14011 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
14012 if (!mbox)
14013 return -ENOMEM;
14014 length = (sizeof(struct lpfc_mbx_mq_destroy) -
14015 sizeof(struct lpfc_sli4_cfg_mhdr));
14016 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14017 LPFC_MBOX_OPCODE_MQ_DESTROY,
14018 length, LPFC_SLI4_MBX_EMBED);
14019 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
14020 mq->queue_id);
14021 mbox->vport = mq->phba->pport;
14022 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14023 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
14024 /* The IOCTL status is embedded in the mailbox subheader. */
14025 shdr = (union lpfc_sli4_cfg_shdr *)
14026 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
14027 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14028 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14029 if (shdr_status || shdr_add_status || rc) {
14030 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14031 "2507 MQ_DESTROY mailbox failed with "
14032 "status x%x add_status x%x, mbx status x%x\n",
14033 shdr_status, shdr_add_status, rc);
14034 status = -ENXIO;
14035 }
14036 /* Remove mq from any list */
14037 list_del_init(&mq->list);
James Smart8fa38512009-07-19 10:01:03 -040014038 mempool_free(mbox, mq->phba->mbox_mem_pool);
James Smart04c68492009-05-22 14:52:52 -040014039 return status;
14040}
14041
14042/**
James Smart4f774512009-05-22 14:52:35 -040014043 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
14044 * @wq: The queue structure associated with the queue to destroy.
14045 *
14046 * This function destroys a queue, as detailed in @wq by sending an mailbox
14047 * command, specific to the type of queue, to the HBA.
14048 *
14049 * The @wq struct is used to get the queue ID of the queue to destroy.
14050 *
14051 * On success this function will return a zero. If the queue destroy mailbox
James Smartd439d282010-09-29 11:18:45 -040014052 * command fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040014053 **/
14054uint32_t
14055lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
14056{
14057 LPFC_MBOXQ_t *mbox;
14058 int rc, length, status = 0;
14059 uint32_t shdr_status, shdr_add_status;
14060 union lpfc_sli4_cfg_shdr *shdr;
14061
James Smart2e90f4b2011-12-13 13:22:37 -050014062 /* sanity check on queue memory */
James Smart4f774512009-05-22 14:52:35 -040014063 if (!wq)
14064 return -ENODEV;
14065 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
14066 if (!mbox)
14067 return -ENOMEM;
14068 length = (sizeof(struct lpfc_mbx_wq_destroy) -
14069 sizeof(struct lpfc_sli4_cfg_mhdr));
14070 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14071 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
14072 length, LPFC_SLI4_MBX_EMBED);
14073 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
14074 wq->queue_id);
14075 mbox->vport = wq->phba->pport;
14076 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14077 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
14078 shdr = (union lpfc_sli4_cfg_shdr *)
14079 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
14080 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14081 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14082 if (shdr_status || shdr_add_status || rc) {
14083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14084 "2508 WQ_DESTROY mailbox failed with "
14085 "status x%x add_status x%x, mbx status x%x\n",
14086 shdr_status, shdr_add_status, rc);
14087 status = -ENXIO;
14088 }
14089 /* Remove wq from any list */
14090 list_del_init(&wq->list);
James Smart8fa38512009-07-19 10:01:03 -040014091 mempool_free(mbox, wq->phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040014092 return status;
14093}
14094
14095/**
14096 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
14097 * @rq: The queue structure associated with the queue to destroy.
14098 *
14099 * This function destroys a queue, as detailed in @rq by sending an mailbox
14100 * command, specific to the type of queue, to the HBA.
14101 *
14102 * The @rq struct is used to get the queue ID of the queue to destroy.
14103 *
14104 * On success this function will return a zero. If the queue destroy mailbox
James Smartd439d282010-09-29 11:18:45 -040014105 * command fails this function will return -ENXIO.
James Smart4f774512009-05-22 14:52:35 -040014106 **/
14107uint32_t
14108lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
14109 struct lpfc_queue *drq)
14110{
14111 LPFC_MBOXQ_t *mbox;
14112 int rc, length, status = 0;
14113 uint32_t shdr_status, shdr_add_status;
14114 union lpfc_sli4_cfg_shdr *shdr;
14115
James Smart2e90f4b2011-12-13 13:22:37 -050014116 /* sanity check on queue memory */
James Smart4f774512009-05-22 14:52:35 -040014117 if (!hrq || !drq)
14118 return -ENODEV;
14119 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
14120 if (!mbox)
14121 return -ENOMEM;
14122 length = (sizeof(struct lpfc_mbx_rq_destroy) -
James Smartfedd3b72011-02-16 12:39:24 -050014123 sizeof(struct lpfc_sli4_cfg_mhdr));
James Smart4f774512009-05-22 14:52:35 -040014124 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14125 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
14126 length, LPFC_SLI4_MBX_EMBED);
14127 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
14128 hrq->queue_id);
14129 mbox->vport = hrq->phba->pport;
14130 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14131 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
14132 /* The IOCTL status is embedded in the mailbox subheader. */
14133 shdr = (union lpfc_sli4_cfg_shdr *)
14134 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
14135 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14136 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14137 if (shdr_status || shdr_add_status || rc) {
14138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14139 "2509 RQ_DESTROY mailbox failed with "
14140 "status x%x add_status x%x, mbx status x%x\n",
14141 shdr_status, shdr_add_status, rc);
14142 if (rc != MBX_TIMEOUT)
14143 mempool_free(mbox, hrq->phba->mbox_mem_pool);
14144 return -ENXIO;
14145 }
14146 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
14147 drq->queue_id);
14148 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
14149 shdr = (union lpfc_sli4_cfg_shdr *)
14150 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
14151 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14152 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14153 if (shdr_status || shdr_add_status || rc) {
14154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14155 "2510 RQ_DESTROY mailbox failed with "
14156 "status x%x add_status x%x, mbx status x%x\n",
14157 shdr_status, shdr_add_status, rc);
14158 status = -ENXIO;
14159 }
14160 list_del_init(&hrq->list);
14161 list_del_init(&drq->list);
James Smart8fa38512009-07-19 10:01:03 -040014162 mempool_free(mbox, hrq->phba->mbox_mem_pool);
James Smart4f774512009-05-22 14:52:35 -040014163 return status;
14164}
14165
14166/**
14167 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
14168 * @phba: The virtual port for which this call being executed.
14169 * @pdma_phys_addr0: Physical address of the 1st SGL page.
14170 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
14171 * @xritag: the xritag that ties this io to the SGL pages.
14172 *
14173 * This routine will post the sgl pages for the IO that has the xritag
14174 * that is in the iocbq structure. The xritag is assigned during iocbq
14175 * creation and persists for as long as the driver is loaded.
14176 * if the caller has fewer than 256 scatter gather segments to map then
14177 * pdma_phys_addr1 should be 0.
14178 * If the caller needs to map more than 256 scatter gather segment then
14179 * pdma_phys_addr1 should be a valid physical address.
14180 * physical address for SGLs must be 64 byte aligned.
14181 * If you are going to map 2 SGL's then the first one must have 256 entries
14182 * the second sgl can have between 1 and 256 entries.
14183 *
14184 * Return codes:
14185 * 0 - Success
14186 * -ENXIO, -ENOMEM - Failure
14187 **/
14188int
14189lpfc_sli4_post_sgl(struct lpfc_hba *phba,
14190 dma_addr_t pdma_phys_addr0,
14191 dma_addr_t pdma_phys_addr1,
14192 uint16_t xritag)
14193{
14194 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
14195 LPFC_MBOXQ_t *mbox;
14196 int rc;
14197 uint32_t shdr_status, shdr_add_status;
James Smart6d368e52011-05-24 11:44:12 -040014198 uint32_t mbox_tmo;
James Smart4f774512009-05-22 14:52:35 -040014199 union lpfc_sli4_cfg_shdr *shdr;
14200
14201 if (xritag == NO_XRI) {
14202 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14203 "0364 Invalid param:\n");
14204 return -EINVAL;
14205 }
14206
14207 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14208 if (!mbox)
14209 return -ENOMEM;
14210
14211 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14212 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
14213 sizeof(struct lpfc_mbx_post_sgl_pages) -
James Smartfedd3b72011-02-16 12:39:24 -050014214 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
James Smart4f774512009-05-22 14:52:35 -040014215
14216 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
14217 &mbox->u.mqe.un.post_sgl_pages;
14218 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
14219 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
14220
14221 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
14222 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
14223 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
14224 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
14225
14226 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
14227 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
14228 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
14229 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
14230 if (!phba->sli4_hba.intr_enable)
14231 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
James Smart6d368e52011-05-24 11:44:12 -040014232 else {
James Smarta183a152011-10-10 21:32:43 -040014233 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart6d368e52011-05-24 11:44:12 -040014234 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
14235 }
James Smart4f774512009-05-22 14:52:35 -040014236 /* The IOCTL status is embedded in the mailbox subheader. */
14237 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
14238 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14239 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14240 if (rc != MBX_TIMEOUT)
14241 mempool_free(mbox, phba->mbox_mem_pool);
14242 if (shdr_status || shdr_add_status || rc) {
14243 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14244 "2511 POST_SGL mailbox failed with "
14245 "status x%x add_status x%x, mbx status x%x\n",
14246 shdr_status, shdr_add_status, rc);
14247 rc = -ENXIO;
14248 }
14249 return 0;
14250}
James Smart4f774512009-05-22 14:52:35 -040014251
14252/**
James Smart88a2cfb2011-07-22 18:36:33 -040014253 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
James Smart6d368e52011-05-24 11:44:12 -040014254 * @phba: pointer to lpfc hba data structure.
14255 *
14256 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -040014257 * HBA consistent with the SLI-4 interface spec. This routine
14258 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14259 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
James Smart6d368e52011-05-24 11:44:12 -040014260 *
James Smart88a2cfb2011-07-22 18:36:33 -040014261 * Returns
14262 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14263 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14264 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040014265static uint16_t
James Smart6d368e52011-05-24 11:44:12 -040014266lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
14267{
14268 unsigned long xri;
14269
14270 /*
14271 * Fetch the next logical xri. Because this index is logical,
14272 * the driver starts at 0 each time.
14273 */
14274 spin_lock_irq(&phba->hbalock);
14275 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
14276 phba->sli4_hba.max_cfg_param.max_xri, 0);
14277 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
14278 spin_unlock_irq(&phba->hbalock);
14279 return NO_XRI;
14280 } else {
14281 set_bit(xri, phba->sli4_hba.xri_bmask);
14282 phba->sli4_hba.max_cfg_param.xri_used++;
James Smart6d368e52011-05-24 11:44:12 -040014283 }
James Smart6d368e52011-05-24 11:44:12 -040014284 spin_unlock_irq(&phba->hbalock);
14285 return xri;
14286}
14287
14288/**
14289 * lpfc_sli4_free_xri - Release an xri for reuse.
14290 * @phba: pointer to lpfc hba data structure.
14291 *
14292 * This routine is invoked to release an xri to the pool of
14293 * available rpis maintained by the driver.
14294 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040014295static void
James Smart6d368e52011-05-24 11:44:12 -040014296__lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
14297{
14298 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
James Smart6d368e52011-05-24 11:44:12 -040014299 phba->sli4_hba.max_cfg_param.xri_used--;
14300 }
14301}
14302
14303/**
14304 * lpfc_sli4_free_xri - Release an xri for reuse.
14305 * @phba: pointer to lpfc hba data structure.
14306 *
14307 * This routine is invoked to release an xri to the pool of
14308 * available rpis maintained by the driver.
14309 **/
14310void
14311lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
14312{
14313 spin_lock_irq(&phba->hbalock);
14314 __lpfc_sli4_free_xri(phba, xri);
14315 spin_unlock_irq(&phba->hbalock);
14316}
14317
14318/**
James Smart4f774512009-05-22 14:52:35 -040014319 * lpfc_sli4_next_xritag - Get an xritag for the io
14320 * @phba: Pointer to HBA context object.
14321 *
14322 * This function gets an xritag for the iocb. If there is no unused xritag
14323 * it will return 0xffff.
14324 * The function returns the allocated xritag if successful, else returns zero.
14325 * Zero is not a valid xritag.
14326 * The caller is not required to hold any lock.
14327 **/
14328uint16_t
14329lpfc_sli4_next_xritag(struct lpfc_hba *phba)
14330{
James Smart6d368e52011-05-24 11:44:12 -040014331 uint16_t xri_index;
James Smart4f774512009-05-22 14:52:35 -040014332
James Smart6d368e52011-05-24 11:44:12 -040014333 xri_index = lpfc_sli4_alloc_xri(phba);
James Smart81378052012-05-09 21:17:37 -040014334 if (xri_index == NO_XRI)
14335 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14336 "2004 Failed to allocate XRI.last XRITAG is %d"
14337 " Max XRI is %d, Used XRI is %d\n",
14338 xri_index,
14339 phba->sli4_hba.max_cfg_param.max_xri,
14340 phba->sli4_hba.max_cfg_param.xri_used);
14341 return xri_index;
James Smart4f774512009-05-22 14:52:35 -040014342}
14343
14344/**
James Smart6d368e52011-05-24 11:44:12 -040014345 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
James Smart4f774512009-05-22 14:52:35 -040014346 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -040014347 * @post_sgl_list: pointer to els sgl entry list.
14348 * @count: number of els sgl entries on the list.
James Smart4f774512009-05-22 14:52:35 -040014349 *
14350 * This routine is invoked to post a block of driver's sgl pages to the
14351 * HBA using non-embedded mailbox command. No Lock is held. This routine
14352 * is only called when the driver is loading and after all IO has been
14353 * stopped.
14354 **/
James Smart8a9d2e82012-05-09 21:16:12 -040014355static int
14356lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
14357 struct list_head *post_sgl_list,
14358 int post_cnt)
James Smart4f774512009-05-22 14:52:35 -040014359{
James Smart8a9d2e82012-05-09 21:16:12 -040014360 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart4f774512009-05-22 14:52:35 -040014361 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
14362 struct sgl_page_pairs *sgl_pg_pairs;
14363 void *viraddr;
14364 LPFC_MBOXQ_t *mbox;
14365 uint32_t reqlen, alloclen, pg_pairs;
14366 uint32_t mbox_tmo;
James Smart8a9d2e82012-05-09 21:16:12 -040014367 uint16_t xritag_start = 0;
14368 int rc = 0;
James Smart4f774512009-05-22 14:52:35 -040014369 uint32_t shdr_status, shdr_add_status;
14370 union lpfc_sli4_cfg_shdr *shdr;
14371
James Smart8a9d2e82012-05-09 21:16:12 -040014372 reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
James Smart4f774512009-05-22 14:52:35 -040014373 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
James Smart49198b32010-04-06 15:04:33 -040014374 if (reqlen > SLI4_PAGE_SIZE) {
James Smart4f774512009-05-22 14:52:35 -040014375 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
14376 "2559 Block sgl registration required DMA "
14377 "size (%d) great than a page\n", reqlen);
14378 return -ENOMEM;
14379 }
14380 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart6d368e52011-05-24 11:44:12 -040014381 if (!mbox)
James Smart4f774512009-05-22 14:52:35 -040014382 return -ENOMEM;
James Smart4f774512009-05-22 14:52:35 -040014383
14384 /* Allocate DMA memory and set up the non-embedded mailbox command */
14385 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14386 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
14387 LPFC_SLI4_MBX_NEMBED);
14388
14389 if (alloclen < reqlen) {
14390 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14391 "0285 Allocated DMA memory size (%d) is "
14392 "less than the requested DMA memory "
14393 "size (%d)\n", alloclen, reqlen);
14394 lpfc_sli4_mbox_cmd_free(phba, mbox);
14395 return -ENOMEM;
14396 }
James Smart4f774512009-05-22 14:52:35 -040014397 /* Set up the SGL pages in the non-embedded DMA pages */
James Smart6d368e52011-05-24 11:44:12 -040014398 viraddr = mbox->sge_array->addr[0];
James Smart4f774512009-05-22 14:52:35 -040014399 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
14400 sgl_pg_pairs = &sgl->sgl_pg_pairs;
14401
James Smart8a9d2e82012-05-09 21:16:12 -040014402 pg_pairs = 0;
14403 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
James Smart4f774512009-05-22 14:52:35 -040014404 /* Set up the sge entry */
14405 sgl_pg_pairs->sgl_pg0_addr_lo =
14406 cpu_to_le32(putPaddrLow(sglq_entry->phys));
14407 sgl_pg_pairs->sgl_pg0_addr_hi =
14408 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
14409 sgl_pg_pairs->sgl_pg1_addr_lo =
14410 cpu_to_le32(putPaddrLow(0));
14411 sgl_pg_pairs->sgl_pg1_addr_hi =
14412 cpu_to_le32(putPaddrHigh(0));
James Smart6d368e52011-05-24 11:44:12 -040014413
James Smart4f774512009-05-22 14:52:35 -040014414 /* Keep the first xritag on the list */
14415 if (pg_pairs == 0)
14416 xritag_start = sglq_entry->sli4_xritag;
14417 sgl_pg_pairs++;
James Smart8a9d2e82012-05-09 21:16:12 -040014418 pg_pairs++;
James Smart4f774512009-05-22 14:52:35 -040014419 }
James Smart6d368e52011-05-24 11:44:12 -040014420
14421 /* Complete initialization and perform endian conversion. */
James Smart4f774512009-05-22 14:52:35 -040014422 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
James Smart8a9d2e82012-05-09 21:16:12 -040014423 bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
James Smart4f774512009-05-22 14:52:35 -040014424 sgl->word0 = cpu_to_le32(sgl->word0);
James Smart4f774512009-05-22 14:52:35 -040014425 if (!phba->sli4_hba.intr_enable)
14426 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14427 else {
James Smarta183a152011-10-10 21:32:43 -040014428 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart4f774512009-05-22 14:52:35 -040014429 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
14430 }
14431 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
14432 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14433 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14434 if (rc != MBX_TIMEOUT)
14435 lpfc_sli4_mbox_cmd_free(phba, mbox);
14436 if (shdr_status || shdr_add_status || rc) {
14437 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14438 "2513 POST_SGL_BLOCK mailbox command failed "
14439 "status x%x add_status x%x mbx status x%x\n",
14440 shdr_status, shdr_add_status, rc);
14441 rc = -ENXIO;
14442 }
14443 return rc;
14444}
14445
14446/**
14447 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
14448 * @phba: pointer to lpfc hba data structure.
14449 * @sblist: pointer to scsi buffer list.
14450 * @count: number of scsi buffers on the list.
14451 *
14452 * This routine is invoked to post a block of @count scsi sgl pages from a
14453 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
14454 * No Lock is held.
14455 *
14456 **/
14457int
James Smart8a9d2e82012-05-09 21:16:12 -040014458lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
14459 struct list_head *sblist,
14460 int count)
James Smart4f774512009-05-22 14:52:35 -040014461{
14462 struct lpfc_scsi_buf *psb;
14463 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
14464 struct sgl_page_pairs *sgl_pg_pairs;
14465 void *viraddr;
14466 LPFC_MBOXQ_t *mbox;
14467 uint32_t reqlen, alloclen, pg_pairs;
14468 uint32_t mbox_tmo;
14469 uint16_t xritag_start = 0;
14470 int rc = 0;
14471 uint32_t shdr_status, shdr_add_status;
14472 dma_addr_t pdma_phys_bpl1;
14473 union lpfc_sli4_cfg_shdr *shdr;
14474
14475 /* Calculate the requested length of the dma memory */
James Smart8a9d2e82012-05-09 21:16:12 -040014476 reqlen = count * sizeof(struct sgl_page_pairs) +
James Smart4f774512009-05-22 14:52:35 -040014477 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
James Smart49198b32010-04-06 15:04:33 -040014478 if (reqlen > SLI4_PAGE_SIZE) {
James Smart4f774512009-05-22 14:52:35 -040014479 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
14480 "0217 Block sgl registration required DMA "
14481 "size (%d) great than a page\n", reqlen);
14482 return -ENOMEM;
14483 }
14484 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14485 if (!mbox) {
14486 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14487 "0283 Failed to allocate mbox cmd memory\n");
14488 return -ENOMEM;
14489 }
14490
14491 /* Allocate DMA memory and set up the non-embedded mailbox command */
14492 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14493 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
14494 LPFC_SLI4_MBX_NEMBED);
14495
14496 if (alloclen < reqlen) {
14497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14498 "2561 Allocated DMA memory size (%d) is "
14499 "less than the requested DMA memory "
14500 "size (%d)\n", alloclen, reqlen);
14501 lpfc_sli4_mbox_cmd_free(phba, mbox);
14502 return -ENOMEM;
14503 }
James Smart6d368e52011-05-24 11:44:12 -040014504
James Smart4f774512009-05-22 14:52:35 -040014505 /* Get the first SGE entry from the non-embedded DMA memory */
James Smart4f774512009-05-22 14:52:35 -040014506 viraddr = mbox->sge_array->addr[0];
14507
14508 /* Set up the SGL pages in the non-embedded DMA pages */
14509 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
14510 sgl_pg_pairs = &sgl->sgl_pg_pairs;
14511
14512 pg_pairs = 0;
14513 list_for_each_entry(psb, sblist, list) {
14514 /* Set up the sge entry */
14515 sgl_pg_pairs->sgl_pg0_addr_lo =
14516 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
14517 sgl_pg_pairs->sgl_pg0_addr_hi =
14518 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
14519 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
14520 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
14521 else
14522 pdma_phys_bpl1 = 0;
14523 sgl_pg_pairs->sgl_pg1_addr_lo =
14524 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
14525 sgl_pg_pairs->sgl_pg1_addr_hi =
14526 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
14527 /* Keep the first xritag on the list */
14528 if (pg_pairs == 0)
14529 xritag_start = psb->cur_iocbq.sli4_xritag;
14530 sgl_pg_pairs++;
14531 pg_pairs++;
14532 }
14533 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
14534 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
14535 /* Perform endian conversion if necessary */
14536 sgl->word0 = cpu_to_le32(sgl->word0);
14537
14538 if (!phba->sli4_hba.intr_enable)
14539 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14540 else {
James Smarta183a152011-10-10 21:32:43 -040014541 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart4f774512009-05-22 14:52:35 -040014542 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
14543 }
14544 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
14545 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14546 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14547 if (rc != MBX_TIMEOUT)
14548 lpfc_sli4_mbox_cmd_free(phba, mbox);
14549 if (shdr_status || shdr_add_status || rc) {
14550 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14551 "2564 POST_SGL_BLOCK mailbox command failed "
14552 "status x%x add_status x%x mbx status x%x\n",
14553 shdr_status, shdr_add_status, rc);
14554 rc = -ENXIO;
14555 }
14556 return rc;
14557}
14558
14559/**
14560 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
14561 * @phba: pointer to lpfc_hba struct that the frame was received on
14562 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14563 *
14564 * This function checks the fields in the @fc_hdr to see if the FC frame is a
14565 * valid type of frame that the LPFC driver will handle. This function will
14566 * return a zero if the frame is a valid frame or a non zero value when the
14567 * frame does not pass the check.
14568 **/
14569static int
14570lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
14571{
Tomas Henzl474ffb72010-12-22 16:52:40 +010014572 /* make rctl_names static to save stack space */
14573 static char *rctl_names[] = FC_RCTL_NAMES_INIT;
James Smart4f774512009-05-22 14:52:35 -040014574 char *type_names[] = FC_TYPE_NAMES_INIT;
14575 struct fc_vft_header *fc_vft_hdr;
James Smart546fc852011-03-11 16:06:29 -050014576 uint32_t *header = (uint32_t *) fc_hdr;
James Smart4f774512009-05-22 14:52:35 -040014577
14578 switch (fc_hdr->fh_r_ctl) {
14579 case FC_RCTL_DD_UNCAT: /* uncategorized information */
14580 case FC_RCTL_DD_SOL_DATA: /* solicited data */
14581 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
14582 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
14583 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
14584 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
14585 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
14586 case FC_RCTL_DD_CMD_STATUS: /* command status */
14587 case FC_RCTL_ELS_REQ: /* extended link services request */
14588 case FC_RCTL_ELS_REP: /* extended link services reply */
14589 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
14590 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
14591 case FC_RCTL_BA_NOP: /* basic link service NOP */
14592 case FC_RCTL_BA_ABTS: /* basic link service abort */
14593 case FC_RCTL_BA_RMC: /* remove connection */
14594 case FC_RCTL_BA_ACC: /* basic accept */
14595 case FC_RCTL_BA_RJT: /* basic reject */
14596 case FC_RCTL_BA_PRMT:
14597 case FC_RCTL_ACK_1: /* acknowledge_1 */
14598 case FC_RCTL_ACK_0: /* acknowledge_0 */
14599 case FC_RCTL_P_RJT: /* port reject */
14600 case FC_RCTL_F_RJT: /* fabric reject */
14601 case FC_RCTL_P_BSY: /* port busy */
14602 case FC_RCTL_F_BSY: /* fabric busy to data frame */
14603 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
14604 case FC_RCTL_LCR: /* link credit reset */
14605 case FC_RCTL_END: /* end */
14606 break;
14607 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
14608 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
14609 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
14610 return lpfc_fc_frame_check(phba, fc_hdr);
14611 default:
14612 goto drop;
14613 }
14614 switch (fc_hdr->fh_type) {
14615 case FC_TYPE_BLS:
14616 case FC_TYPE_ELS:
14617 case FC_TYPE_FCP:
14618 case FC_TYPE_CT:
14619 break;
14620 case FC_TYPE_IP:
14621 case FC_TYPE_ILS:
14622 default:
14623 goto drop;
14624 }
James Smart546fc852011-03-11 16:06:29 -050014625
James Smart4f774512009-05-22 14:52:35 -040014626 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -040014627 "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
14628 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
14629 rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl,
14630 type_names[fc_hdr->fh_type], fc_hdr->fh_type,
James Smart546fc852011-03-11 16:06:29 -050014631 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
14632 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
James Smart88f43a02013-04-17 20:19:44 -040014633 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
14634 be32_to_cpu(header[6]));
James Smart4f774512009-05-22 14:52:35 -040014635 return 0;
14636drop:
14637 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
14638 "2539 Dropped frame rctl:%s type:%s\n",
14639 rctl_names[fc_hdr->fh_r_ctl],
14640 type_names[fc_hdr->fh_type]);
14641 return 1;
14642}
14643
14644/**
14645 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
14646 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14647 *
14648 * This function processes the FC header to retrieve the VFI from the VF
14649 * header, if one exists. This function will return the VFI if one exists
14650 * or 0 if no VSAN Header exists.
14651 **/
14652static uint32_t
14653lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
14654{
14655 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
14656
14657 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
14658 return 0;
14659 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
14660}
14661
14662/**
14663 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
14664 * @phba: Pointer to the HBA structure to search for the vport on
14665 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14666 * @fcfi: The FC Fabric ID that the frame came from
14667 *
14668 * This function searches the @phba for a vport that matches the content of the
14669 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
14670 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
14671 * returns the matching vport pointer or NULL if unable to match frame to a
14672 * vport.
14673 **/
14674static struct lpfc_vport *
14675lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
14676 uint16_t fcfi)
14677{
14678 struct lpfc_vport **vports;
14679 struct lpfc_vport *vport = NULL;
14680 int i;
14681 uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
14682 fc_hdr->fh_d_id[1] << 8 |
14683 fc_hdr->fh_d_id[2]);
James Smart939723a2012-05-09 21:19:03 -040014684
James Smartbf086112011-08-21 21:48:13 -040014685 if (did == Fabric_DID)
14686 return phba->pport;
James Smart939723a2012-05-09 21:19:03 -040014687 if ((phba->pport->fc_flag & FC_PT2PT) &&
14688 !(phba->link_state == LPFC_HBA_READY))
14689 return phba->pport;
14690
James Smart4f774512009-05-22 14:52:35 -040014691 vports = lpfc_create_vport_work_array(phba);
14692 if (vports != NULL)
14693 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
14694 if (phba->fcf.fcfi == fcfi &&
14695 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
14696 vports[i]->fc_myDID == did) {
14697 vport = vports[i];
14698 break;
14699 }
14700 }
14701 lpfc_destroy_vport_work_array(phba, vports);
14702 return vport;
14703}
14704
14705/**
James Smart45ed1192009-10-02 15:17:02 -040014706 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
14707 * @vport: The vport to work on.
14708 *
14709 * This function updates the receive sequence time stamp for this vport. The
14710 * receive sequence time stamp indicates the time that the last frame of the
14711 * the sequence that has been idle for the longest amount of time was received.
14712 * the driver uses this time stamp to indicate if any received sequences have
14713 * timed out.
14714 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040014715static void
James Smart45ed1192009-10-02 15:17:02 -040014716lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
14717{
14718 struct lpfc_dmabuf *h_buf;
14719 struct hbq_dmabuf *dmabuf = NULL;
14720
14721 /* get the oldest sequence on the rcv list */
14722 h_buf = list_get_first(&vport->rcv_buffer_list,
14723 struct lpfc_dmabuf, list);
14724 if (!h_buf)
14725 return;
14726 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
14727 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
14728}
14729
14730/**
14731 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
14732 * @vport: The vport that the received sequences were sent to.
14733 *
14734 * This function cleans up all outstanding received sequences. This is called
14735 * by the driver when a link event or user action invalidates all the received
14736 * sequences.
14737 **/
14738void
14739lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
14740{
14741 struct lpfc_dmabuf *h_buf, *hnext;
14742 struct lpfc_dmabuf *d_buf, *dnext;
14743 struct hbq_dmabuf *dmabuf = NULL;
14744
14745 /* start with the oldest sequence on the rcv list */
14746 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
14747 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
14748 list_del_init(&dmabuf->hbuf.list);
14749 list_for_each_entry_safe(d_buf, dnext,
14750 &dmabuf->dbuf.list, list) {
14751 list_del_init(&d_buf->list);
14752 lpfc_in_buf_free(vport->phba, d_buf);
14753 }
14754 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
14755 }
14756}
14757
14758/**
14759 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
14760 * @vport: The vport that the received sequences were sent to.
14761 *
14762 * This function determines whether any received sequences have timed out by
14763 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
14764 * indicates that there is at least one timed out sequence this routine will
14765 * go through the received sequences one at a time from most inactive to most
14766 * active to determine which ones need to be cleaned up. Once it has determined
14767 * that a sequence needs to be cleaned up it will simply free up the resources
14768 * without sending an abort.
14769 **/
14770void
14771lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
14772{
14773 struct lpfc_dmabuf *h_buf, *hnext;
14774 struct lpfc_dmabuf *d_buf, *dnext;
14775 struct hbq_dmabuf *dmabuf = NULL;
14776 unsigned long timeout;
14777 int abort_count = 0;
14778
14779 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
14780 vport->rcv_buffer_time_stamp);
14781 if (list_empty(&vport->rcv_buffer_list) ||
14782 time_before(jiffies, timeout))
14783 return;
14784 /* start with the oldest sequence on the rcv list */
14785 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
14786 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
14787 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
14788 dmabuf->time_stamp);
14789 if (time_before(jiffies, timeout))
14790 break;
14791 abort_count++;
14792 list_del_init(&dmabuf->hbuf.list);
14793 list_for_each_entry_safe(d_buf, dnext,
14794 &dmabuf->dbuf.list, list) {
14795 list_del_init(&d_buf->list);
14796 lpfc_in_buf_free(vport->phba, d_buf);
14797 }
14798 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
14799 }
14800 if (abort_count)
14801 lpfc_update_rcv_time_stamp(vport);
14802}
14803
14804/**
James Smart4f774512009-05-22 14:52:35 -040014805 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
14806 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
14807 *
14808 * This function searches through the existing incomplete sequences that have
14809 * been sent to this @vport. If the frame matches one of the incomplete
14810 * sequences then the dbuf in the @dmabuf is added to the list of frames that
14811 * make up that sequence. If no sequence is found that matches this frame then
14812 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
14813 * This function returns a pointer to the first dmabuf in the sequence list that
14814 * the frame was linked to.
14815 **/
14816static struct hbq_dmabuf *
14817lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
14818{
14819 struct fc_frame_header *new_hdr;
14820 struct fc_frame_header *temp_hdr;
14821 struct lpfc_dmabuf *d_buf;
14822 struct lpfc_dmabuf *h_buf;
14823 struct hbq_dmabuf *seq_dmabuf = NULL;
14824 struct hbq_dmabuf *temp_dmabuf = NULL;
14825
James Smart4d9ab992009-10-02 15:16:39 -040014826 INIT_LIST_HEAD(&dmabuf->dbuf.list);
James Smart45ed1192009-10-02 15:17:02 -040014827 dmabuf->time_stamp = jiffies;
James Smart4f774512009-05-22 14:52:35 -040014828 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
14829 /* Use the hdr_buf to find the sequence that this frame belongs to */
14830 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
14831 temp_hdr = (struct fc_frame_header *)h_buf->virt;
14832 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
14833 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
14834 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
14835 continue;
14836 /* found a pending sequence that matches this frame */
14837 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
14838 break;
14839 }
14840 if (!seq_dmabuf) {
14841 /*
14842 * This indicates first frame received for this sequence.
14843 * Queue the buffer on the vport's rcv_buffer_list.
14844 */
14845 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
James Smart45ed1192009-10-02 15:17:02 -040014846 lpfc_update_rcv_time_stamp(vport);
James Smart4f774512009-05-22 14:52:35 -040014847 return dmabuf;
14848 }
14849 temp_hdr = seq_dmabuf->hbuf.virt;
James Smarteeead812009-12-21 17:01:23 -050014850 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
14851 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
James Smart4d9ab992009-10-02 15:16:39 -040014852 list_del_init(&seq_dmabuf->hbuf.list);
14853 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
14854 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
James Smart45ed1192009-10-02 15:17:02 -040014855 lpfc_update_rcv_time_stamp(vport);
James Smart4f774512009-05-22 14:52:35 -040014856 return dmabuf;
14857 }
James Smart45ed1192009-10-02 15:17:02 -040014858 /* move this sequence to the tail to indicate a young sequence */
14859 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
14860 seq_dmabuf->time_stamp = jiffies;
14861 lpfc_update_rcv_time_stamp(vport);
James Smarteeead812009-12-21 17:01:23 -050014862 if (list_empty(&seq_dmabuf->dbuf.list)) {
14863 temp_hdr = dmabuf->hbuf.virt;
14864 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
14865 return seq_dmabuf;
14866 }
James Smart4f774512009-05-22 14:52:35 -040014867 /* find the correct place in the sequence to insert this frame */
14868 list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
14869 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
14870 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
14871 /*
14872 * If the frame's sequence count is greater than the frame on
14873 * the list then insert the frame right after this frame
14874 */
James Smarteeead812009-12-21 17:01:23 -050014875 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
14876 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
James Smart4f774512009-05-22 14:52:35 -040014877 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
14878 return seq_dmabuf;
14879 }
14880 }
14881 return NULL;
14882}
14883
14884/**
James Smart6669f9b2009-10-02 15:16:45 -040014885 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
14886 * @vport: pointer to a vitural port
14887 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14888 *
14889 * This function tries to abort from the partially assembed sequence, described
14890 * by the information from basic abbort @dmabuf. It checks to see whether such
14891 * partially assembled sequence held by the driver. If so, it shall free up all
14892 * the frames from the partially assembled sequence.
14893 *
14894 * Return
14895 * true -- if there is matching partially assembled sequence present and all
14896 * the frames freed with the sequence;
14897 * false -- if there is no matching partially assembled sequence present so
14898 * nothing got aborted in the lower layer driver
14899 **/
14900static bool
14901lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
14902 struct hbq_dmabuf *dmabuf)
14903{
14904 struct fc_frame_header *new_hdr;
14905 struct fc_frame_header *temp_hdr;
14906 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
14907 struct hbq_dmabuf *seq_dmabuf = NULL;
14908
14909 /* Use the hdr_buf to find the sequence that matches this frame */
14910 INIT_LIST_HEAD(&dmabuf->dbuf.list);
14911 INIT_LIST_HEAD(&dmabuf->hbuf.list);
14912 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
14913 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
14914 temp_hdr = (struct fc_frame_header *)h_buf->virt;
14915 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
14916 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
14917 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
14918 continue;
14919 /* found a pending sequence that matches this frame */
14920 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
14921 break;
14922 }
14923
14924 /* Free up all the frames from the partially assembled sequence */
14925 if (seq_dmabuf) {
14926 list_for_each_entry_safe(d_buf, n_buf,
14927 &seq_dmabuf->dbuf.list, list) {
14928 list_del_init(&d_buf->list);
14929 lpfc_in_buf_free(vport->phba, d_buf);
14930 }
14931 return true;
14932 }
14933 return false;
14934}
14935
14936/**
James Smart6dd9e312013-01-03 15:43:37 -050014937 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
14938 * @vport: pointer to a vitural port
14939 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14940 *
14941 * This function tries to abort from the assembed sequence from upper level
14942 * protocol, described by the information from basic abbort @dmabuf. It
14943 * checks to see whether such pending context exists at upper level protocol.
14944 * If so, it shall clean up the pending context.
14945 *
14946 * Return
14947 * true -- if there is matching pending context of the sequence cleaned
14948 * at ulp;
14949 * false -- if there is no matching pending context of the sequence present
14950 * at ulp.
14951 **/
14952static bool
14953lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
14954{
14955 struct lpfc_hba *phba = vport->phba;
14956 int handled;
14957
14958 /* Accepting abort at ulp with SLI4 only */
14959 if (phba->sli_rev < LPFC_SLI_REV4)
14960 return false;
14961
14962 /* Register all caring upper level protocols to attend abort */
14963 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
14964 if (handled)
14965 return true;
14966
14967 return false;
14968}
14969
14970/**
James Smart546fc852011-03-11 16:06:29 -050014971 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
James Smart6669f9b2009-10-02 15:16:45 -040014972 * @phba: Pointer to HBA context object.
14973 * @cmd_iocbq: pointer to the command iocbq structure.
14974 * @rsp_iocbq: pointer to the response iocbq structure.
14975 *
James Smart546fc852011-03-11 16:06:29 -050014976 * This function handles the sequence abort response iocb command complete
James Smart6669f9b2009-10-02 15:16:45 -040014977 * event. It properly releases the memory allocated to the sequence abort
14978 * accept iocb.
14979 **/
14980static void
James Smart546fc852011-03-11 16:06:29 -050014981lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
James Smart6669f9b2009-10-02 15:16:45 -040014982 struct lpfc_iocbq *cmd_iocbq,
14983 struct lpfc_iocbq *rsp_iocbq)
14984{
James Smart6dd9e312013-01-03 15:43:37 -050014985 struct lpfc_nodelist *ndlp;
14986
14987 if (cmd_iocbq) {
14988 ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
14989 lpfc_nlp_put(ndlp);
14990 lpfc_nlp_not_used(ndlp);
James Smart6669f9b2009-10-02 15:16:45 -040014991 lpfc_sli_release_iocbq(phba, cmd_iocbq);
James Smart6dd9e312013-01-03 15:43:37 -050014992 }
James Smart6b5151f2012-01-18 16:24:06 -050014993
14994 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14995 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
14996 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14997 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14998 rsp_iocbq->iocb.ulpStatus,
14999 rsp_iocbq->iocb.un.ulpWord[4]);
James Smart6669f9b2009-10-02 15:16:45 -040015000}
15001
15002/**
James Smart6d368e52011-05-24 11:44:12 -040015003 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
15004 * @phba: Pointer to HBA context object.
15005 * @xri: xri id in transaction.
15006 *
15007 * This function validates the xri maps to the known range of XRIs allocated an
15008 * used by the driver.
15009 **/
James Smart7851fe22011-07-22 18:36:52 -040015010uint16_t
James Smart6d368e52011-05-24 11:44:12 -040015011lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
15012 uint16_t xri)
15013{
15014 int i;
15015
15016 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
15017 if (xri == phba->sli4_hba.xri_ids[i])
15018 return i;
15019 }
15020 return NO_XRI;
15021}
15022
James Smart6d368e52011-05-24 11:44:12 -040015023/**
James Smart546fc852011-03-11 16:06:29 -050015024 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
James Smart6669f9b2009-10-02 15:16:45 -040015025 * @phba: Pointer to HBA context object.
15026 * @fc_hdr: pointer to a FC frame header.
15027 *
James Smart546fc852011-03-11 16:06:29 -050015028 * This function sends a basic response to a previous unsol sequence abort
James Smart6669f9b2009-10-02 15:16:45 -040015029 * event after aborting the sequence handling.
15030 **/
15031static void
James Smart6dd9e312013-01-03 15:43:37 -050015032lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
15033 struct fc_frame_header *fc_hdr, bool aborted)
James Smart6669f9b2009-10-02 15:16:45 -040015034{
James Smart6dd9e312013-01-03 15:43:37 -050015035 struct lpfc_hba *phba = vport->phba;
James Smart6669f9b2009-10-02 15:16:45 -040015036 struct lpfc_iocbq *ctiocb = NULL;
15037 struct lpfc_nodelist *ndlp;
James Smartee0f4fe2012-05-09 21:19:14 -040015038 uint16_t oxid, rxid, xri, lxri;
James Smart5ffc2662009-11-18 15:39:44 -050015039 uint32_t sid, fctl;
James Smart6669f9b2009-10-02 15:16:45 -040015040 IOCB_t *icmd;
James Smart546fc852011-03-11 16:06:29 -050015041 int rc;
James Smart6669f9b2009-10-02 15:16:45 -040015042
15043 if (!lpfc_is_link_up(phba))
15044 return;
15045
15046 sid = sli4_sid_from_fc_hdr(fc_hdr);
15047 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
James Smart5ffc2662009-11-18 15:39:44 -050015048 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
James Smart6669f9b2009-10-02 15:16:45 -040015049
James Smart6dd9e312013-01-03 15:43:37 -050015050 ndlp = lpfc_findnode_did(vport, sid);
James Smart6669f9b2009-10-02 15:16:45 -040015051 if (!ndlp) {
James Smart6dd9e312013-01-03 15:43:37 -050015052 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
15053 if (!ndlp) {
15054 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
15055 "1268 Failed to allocate ndlp for "
15056 "oxid:x%x SID:x%x\n", oxid, sid);
15057 return;
15058 }
15059 lpfc_nlp_init(vport, ndlp, sid);
15060 /* Put ndlp onto pport node list */
15061 lpfc_enqueue_node(vport, ndlp);
15062 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
15063 /* re-setup ndlp without removing from node list */
15064 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
15065 if (!ndlp) {
15066 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
15067 "3275 Failed to active ndlp found "
15068 "for oxid:x%x SID:x%x\n", oxid, sid);
15069 return;
15070 }
James Smart6669f9b2009-10-02 15:16:45 -040015071 }
15072
James Smart546fc852011-03-11 16:06:29 -050015073 /* Allocate buffer for rsp iocb */
James Smart6669f9b2009-10-02 15:16:45 -040015074 ctiocb = lpfc_sli_get_iocbq(phba);
15075 if (!ctiocb)
15076 return;
15077
James Smart5ffc2662009-11-18 15:39:44 -050015078 /* Extract the F_CTL field from FC_HDR */
15079 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
15080
James Smart6669f9b2009-10-02 15:16:45 -040015081 icmd = &ctiocb->iocb;
James Smart6669f9b2009-10-02 15:16:45 -040015082 icmd->un.xseq64.bdl.bdeSize = 0;
James Smart5ffc2662009-11-18 15:39:44 -050015083 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
James Smart6669f9b2009-10-02 15:16:45 -040015084 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
15085 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
15086 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
15087
15088 /* Fill in the rest of iocb fields */
15089 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
15090 icmd->ulpBdeCount = 0;
15091 icmd->ulpLe = 1;
15092 icmd->ulpClass = CLASS3;
James Smart6d368e52011-05-24 11:44:12 -040015093 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart6dd9e312013-01-03 15:43:37 -050015094 ctiocb->context1 = lpfc_nlp_get(ndlp);
James Smart6669f9b2009-10-02 15:16:45 -040015095
James Smart6669f9b2009-10-02 15:16:45 -040015096 ctiocb->iocb_cmpl = NULL;
15097 ctiocb->vport = phba->pport;
James Smart546fc852011-03-11 16:06:29 -050015098 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
James Smart6d368e52011-05-24 11:44:12 -040015099 ctiocb->sli4_lxritag = NO_XRI;
James Smart546fc852011-03-11 16:06:29 -050015100 ctiocb->sli4_xritag = NO_XRI;
15101
James Smartee0f4fe2012-05-09 21:19:14 -040015102 if (fctl & FC_FC_EX_CTX)
15103 /* Exchange responder sent the abort so we
15104 * own the oxid.
15105 */
15106 xri = oxid;
15107 else
15108 xri = rxid;
15109 lxri = lpfc_sli4_xri_inrange(phba, xri);
15110 if (lxri != NO_XRI)
15111 lpfc_set_rrq_active(phba, ndlp, lxri,
15112 (xri == oxid) ? rxid : oxid, 0);
James Smart6dd9e312013-01-03 15:43:37 -050015113 /* For BA_ABTS from exchange responder, if the logical xri with
15114 * the oxid maps to the FCP XRI range, the port no longer has
15115 * that exchange context, send a BLS_RJT. Override the IOCB for
15116 * a BA_RJT.
James Smart546fc852011-03-11 16:06:29 -050015117 */
James Smart6dd9e312013-01-03 15:43:37 -050015118 if ((fctl & FC_FC_EX_CTX) &&
15119 (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
15120 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
15121 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
15122 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
15123 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
15124 }
15125
15126 /* If BA_ABTS failed to abort a partially assembled receive sequence,
15127 * the driver no longer has that exchange, send a BLS_RJT. Override
15128 * the IOCB for a BA_RJT.
15129 */
15130 if (aborted == false) {
James Smart546fc852011-03-11 16:06:29 -050015131 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
15132 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
15133 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
15134 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
15135 }
James Smart6669f9b2009-10-02 15:16:45 -040015136
James Smart5ffc2662009-11-18 15:39:44 -050015137 if (fctl & FC_FC_EX_CTX) {
15138 /* ABTS sent by responder to CT exchange, construction
15139 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
15140 * field and RX_ID from ABTS for RX_ID field.
15141 */
James Smart546fc852011-03-11 16:06:29 -050015142 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
James Smart5ffc2662009-11-18 15:39:44 -050015143 } else {
15144 /* ABTS sent by initiator to CT exchange, construction
15145 * of BA_ACC will need to allocate a new XRI as for the
James Smartf09c3ac2012-03-01 22:33:29 -050015146 * XRI_TAG field.
James Smart5ffc2662009-11-18 15:39:44 -050015147 */
James Smart546fc852011-03-11 16:06:29 -050015148 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
James Smart5ffc2662009-11-18 15:39:44 -050015149 }
James Smartf09c3ac2012-03-01 22:33:29 -050015150 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
James Smart546fc852011-03-11 16:06:29 -050015151 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
James Smart5ffc2662009-11-18 15:39:44 -050015152
James Smart546fc852011-03-11 16:06:29 -050015153 /* Xmit CT abts response on exchange <xid> */
James Smart6dd9e312013-01-03 15:43:37 -050015154 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
15155 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
15156 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
James Smart546fc852011-03-11 16:06:29 -050015157
15158 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
15159 if (rc == IOCB_ERROR) {
James Smart6dd9e312013-01-03 15:43:37 -050015160 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
15161 "2925 Failed to issue CT ABTS RSP x%x on "
15162 "xri x%x, Data x%x\n",
15163 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
15164 phba->link_state);
15165 lpfc_nlp_put(ndlp);
15166 ctiocb->context1 = NULL;
James Smart546fc852011-03-11 16:06:29 -050015167 lpfc_sli_release_iocbq(phba, ctiocb);
15168 }
James Smart6669f9b2009-10-02 15:16:45 -040015169}
15170
15171/**
15172 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
15173 * @vport: Pointer to the vport on which this sequence was received
15174 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15175 *
15176 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
15177 * receive sequence is only partially assembed by the driver, it shall abort
15178 * the partially assembled frames for the sequence. Otherwise, if the
15179 * unsolicited receive sequence has been completely assembled and passed to
15180 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
15181 * unsolicited sequence has been aborted. After that, it will issue a basic
15182 * accept to accept the abort.
15183 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040015184static void
James Smart6669f9b2009-10-02 15:16:45 -040015185lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
15186 struct hbq_dmabuf *dmabuf)
15187{
15188 struct lpfc_hba *phba = vport->phba;
15189 struct fc_frame_header fc_hdr;
James Smart5ffc2662009-11-18 15:39:44 -050015190 uint32_t fctl;
James Smart6dd9e312013-01-03 15:43:37 -050015191 bool aborted;
James Smart6669f9b2009-10-02 15:16:45 -040015192
James Smart6669f9b2009-10-02 15:16:45 -040015193 /* Make a copy of fc_hdr before the dmabuf being released */
15194 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
James Smart5ffc2662009-11-18 15:39:44 -050015195 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
James Smart6669f9b2009-10-02 15:16:45 -040015196
James Smart5ffc2662009-11-18 15:39:44 -050015197 if (fctl & FC_FC_EX_CTX) {
James Smart6dd9e312013-01-03 15:43:37 -050015198 /* ABTS by responder to exchange, no cleanup needed */
15199 aborted = true;
James Smart5ffc2662009-11-18 15:39:44 -050015200 } else {
James Smart6dd9e312013-01-03 15:43:37 -050015201 /* ABTS by initiator to exchange, need to do cleanup */
15202 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
15203 if (aborted == false)
15204 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
James Smart5ffc2662009-11-18 15:39:44 -050015205 }
James Smart6dd9e312013-01-03 15:43:37 -050015206 lpfc_in_buf_free(phba, &dmabuf->dbuf);
15207
15208 /* Respond with BA_ACC or BA_RJT accordingly */
15209 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
James Smart6669f9b2009-10-02 15:16:45 -040015210}
15211
15212/**
James Smart4f774512009-05-22 14:52:35 -040015213 * lpfc_seq_complete - Indicates if a sequence is complete
15214 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15215 *
15216 * This function checks the sequence, starting with the frame described by
15217 * @dmabuf, to see if all the frames associated with this sequence are present.
15218 * the frames associated with this sequence are linked to the @dmabuf using the
15219 * dbuf list. This function looks for two major things. 1) That the first frame
15220 * has a sequence count of zero. 2) There is a frame with last frame of sequence
15221 * set. 3) That there are no holes in the sequence count. The function will
15222 * return 1 when the sequence is complete, otherwise it will return 0.
15223 **/
15224static int
15225lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
15226{
15227 struct fc_frame_header *hdr;
15228 struct lpfc_dmabuf *d_buf;
15229 struct hbq_dmabuf *seq_dmabuf;
15230 uint32_t fctl;
15231 int seq_count = 0;
15232
15233 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
15234 /* make sure first fame of sequence has a sequence count of zero */
15235 if (hdr->fh_seq_cnt != seq_count)
15236 return 0;
15237 fctl = (hdr->fh_f_ctl[0] << 16 |
15238 hdr->fh_f_ctl[1] << 8 |
15239 hdr->fh_f_ctl[2]);
15240 /* If last frame of sequence we can return success. */
15241 if (fctl & FC_FC_END_SEQ)
15242 return 1;
15243 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
15244 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
15245 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
15246 /* If there is a hole in the sequence count then fail. */
James Smarteeead812009-12-21 17:01:23 -050015247 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
James Smart4f774512009-05-22 14:52:35 -040015248 return 0;
15249 fctl = (hdr->fh_f_ctl[0] << 16 |
15250 hdr->fh_f_ctl[1] << 8 |
15251 hdr->fh_f_ctl[2]);
15252 /* If last frame of sequence we can return success. */
15253 if (fctl & FC_FC_END_SEQ)
15254 return 1;
15255 }
15256 return 0;
15257}
15258
15259/**
15260 * lpfc_prep_seq - Prep sequence for ULP processing
15261 * @vport: Pointer to the vport on which this sequence was received
15262 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15263 *
15264 * This function takes a sequence, described by a list of frames, and creates
15265 * a list of iocbq structures to describe the sequence. This iocbq list will be
15266 * used to issue to the generic unsolicited sequence handler. This routine
15267 * returns a pointer to the first iocbq in the list. If the function is unable
15268 * to allocate an iocbq then it throw out the received frames that were not
15269 * able to be described and return a pointer to the first iocbq. If unable to
15270 * allocate any iocbqs (including the first) this function will return NULL.
15271 **/
15272static struct lpfc_iocbq *
15273lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
15274{
James Smart7851fe22011-07-22 18:36:52 -040015275 struct hbq_dmabuf *hbq_buf;
James Smart4f774512009-05-22 14:52:35 -040015276 struct lpfc_dmabuf *d_buf, *n_buf;
15277 struct lpfc_iocbq *first_iocbq, *iocbq;
15278 struct fc_frame_header *fc_hdr;
15279 uint32_t sid;
James Smart7851fe22011-07-22 18:36:52 -040015280 uint32_t len, tot_len;
James Smarteeead812009-12-21 17:01:23 -050015281 struct ulp_bde64 *pbde;
James Smart4f774512009-05-22 14:52:35 -040015282
15283 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
15284 /* remove from receive buffer list */
15285 list_del_init(&seq_dmabuf->hbuf.list);
James Smart45ed1192009-10-02 15:17:02 -040015286 lpfc_update_rcv_time_stamp(vport);
James Smart4f774512009-05-22 14:52:35 -040015287 /* get the Remote Port's SID */
James Smart6669f9b2009-10-02 15:16:45 -040015288 sid = sli4_sid_from_fc_hdr(fc_hdr);
James Smart7851fe22011-07-22 18:36:52 -040015289 tot_len = 0;
James Smart4f774512009-05-22 14:52:35 -040015290 /* Get an iocbq struct to fill in. */
15291 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
15292 if (first_iocbq) {
15293 /* Initialize the first IOCB. */
James Smart8fa38512009-07-19 10:01:03 -040015294 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
James Smart4f774512009-05-22 14:52:35 -040015295 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
James Smart939723a2012-05-09 21:19:03 -040015296
15297 /* Check FC Header to see what TYPE of frame we are rcv'ing */
15298 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
15299 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
15300 first_iocbq->iocb.un.rcvels.parmRo =
15301 sli4_did_from_fc_hdr(fc_hdr);
15302 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
15303 } else
15304 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
James Smart7851fe22011-07-22 18:36:52 -040015305 first_iocbq->iocb.ulpContext = NO_XRI;
15306 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
15307 be16_to_cpu(fc_hdr->fh_ox_id);
15308 /* iocbq is prepped for internal consumption. Physical vpi. */
15309 first_iocbq->iocb.unsli3.rcvsli3.vpi =
15310 vport->phba->vpi_ids[vport->vpi];
James Smart4f774512009-05-22 14:52:35 -040015311 /* put the first buffer into the first IOCBq */
James Smart48a5a662013-07-15 18:32:28 -040015312 tot_len = bf_get(lpfc_rcqe_length,
15313 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
15314
James Smart4f774512009-05-22 14:52:35 -040015315 first_iocbq->context2 = &seq_dmabuf->dbuf;
15316 first_iocbq->context3 = NULL;
15317 first_iocbq->iocb.ulpBdeCount = 1;
James Smart48a5a662013-07-15 18:32:28 -040015318 if (tot_len > LPFC_DATA_BUF_SIZE)
15319 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
James Smart4f774512009-05-22 14:52:35 -040015320 LPFC_DATA_BUF_SIZE;
James Smart48a5a662013-07-15 18:32:28 -040015321 else
15322 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
15323
James Smart4f774512009-05-22 14:52:35 -040015324 first_iocbq->iocb.un.rcvels.remoteID = sid;
James Smart48a5a662013-07-15 18:32:28 -040015325
James Smart7851fe22011-07-22 18:36:52 -040015326 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
James Smart4f774512009-05-22 14:52:35 -040015327 }
15328 iocbq = first_iocbq;
15329 /*
15330 * Each IOCBq can have two Buffers assigned, so go through the list
15331 * of buffers for this sequence and save two buffers in each IOCBq
15332 */
15333 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
15334 if (!iocbq) {
15335 lpfc_in_buf_free(vport->phba, d_buf);
15336 continue;
15337 }
15338 if (!iocbq->context3) {
15339 iocbq->context3 = d_buf;
15340 iocbq->iocb.ulpBdeCount++;
James Smart7851fe22011-07-22 18:36:52 -040015341 /* We need to get the size out of the right CQE */
15342 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
15343 len = bf_get(lpfc_rcqe_length,
15344 &hbq_buf->cq_event.cqe.rcqe_cmpl);
James Smart48a5a662013-07-15 18:32:28 -040015345 pbde = (struct ulp_bde64 *)
15346 &iocbq->iocb.unsli3.sli3Words[4];
15347 if (len > LPFC_DATA_BUF_SIZE)
15348 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
15349 else
15350 pbde->tus.f.bdeSize = len;
15351
James Smart7851fe22011-07-22 18:36:52 -040015352 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
15353 tot_len += len;
James Smart4f774512009-05-22 14:52:35 -040015354 } else {
15355 iocbq = lpfc_sli_get_iocbq(vport->phba);
15356 if (!iocbq) {
15357 if (first_iocbq) {
15358 first_iocbq->iocb.ulpStatus =
15359 IOSTAT_FCP_RSP_ERROR;
15360 first_iocbq->iocb.un.ulpWord[4] =
15361 IOERR_NO_RESOURCES;
15362 }
15363 lpfc_in_buf_free(vport->phba, d_buf);
15364 continue;
15365 }
James Smart7851fe22011-07-22 18:36:52 -040015366 /* We need to get the size out of the right CQE */
15367 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
15368 len = bf_get(lpfc_rcqe_length,
15369 &hbq_buf->cq_event.cqe.rcqe_cmpl);
James Smart48a5a662013-07-15 18:32:28 -040015370 iocbq->context2 = d_buf;
15371 iocbq->context3 = NULL;
15372 iocbq->iocb.ulpBdeCount = 1;
15373 if (len > LPFC_DATA_BUF_SIZE)
15374 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
15375 LPFC_DATA_BUF_SIZE;
15376 else
15377 iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
15378
James Smart7851fe22011-07-22 18:36:52 -040015379 tot_len += len;
15380 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
15381
James Smart4f774512009-05-22 14:52:35 -040015382 iocbq->iocb.un.rcvels.remoteID = sid;
15383 list_add_tail(&iocbq->list, &first_iocbq->list);
15384 }
15385 }
15386 return first_iocbq;
15387}
15388
James Smart6669f9b2009-10-02 15:16:45 -040015389static void
15390lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
15391 struct hbq_dmabuf *seq_dmabuf)
15392{
15393 struct fc_frame_header *fc_hdr;
15394 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
15395 struct lpfc_hba *phba = vport->phba;
15396
15397 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
15398 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
15399 if (!iocbq) {
15400 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15401 "2707 Ring %d handler: Failed to allocate "
15402 "iocb Rctl x%x Type x%x received\n",
15403 LPFC_ELS_RING,
15404 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
15405 return;
15406 }
15407 if (!lpfc_complete_unsol_iocb(phba,
15408 &phba->sli.ring[LPFC_ELS_RING],
15409 iocbq, fc_hdr->fh_r_ctl,
15410 fc_hdr->fh_type))
James Smart6d368e52011-05-24 11:44:12 -040015411 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart6669f9b2009-10-02 15:16:45 -040015412 "2540 Ring %d handler: unexpected Rctl "
15413 "x%x Type x%x received\n",
15414 LPFC_ELS_RING,
15415 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
15416
15417 /* Free iocb created in lpfc_prep_seq */
15418 list_for_each_entry_safe(curr_iocb, next_iocb,
15419 &iocbq->list, list) {
15420 list_del_init(&curr_iocb->list);
15421 lpfc_sli_release_iocbq(phba, curr_iocb);
15422 }
15423 lpfc_sli_release_iocbq(phba, iocbq);
15424}
15425
James Smart4f774512009-05-22 14:52:35 -040015426/**
15427 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
15428 * @phba: Pointer to HBA context object.
15429 *
15430 * This function is called with no lock held. This function processes all
15431 * the received buffers and gives it to upper layers when a received buffer
15432 * indicates that it is the final frame in the sequence. The interrupt
15433 * service routine processes received buffers at interrupt contexts and adds
15434 * received dma buffers to the rb_pend_list queue and signals the worker thread.
15435 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
15436 * appropriate receive function when the final frame in a sequence is received.
15437 **/
James Smart4d9ab992009-10-02 15:16:39 -040015438void
15439lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
15440 struct hbq_dmabuf *dmabuf)
James Smart4f774512009-05-22 14:52:35 -040015441{
James Smart4d9ab992009-10-02 15:16:39 -040015442 struct hbq_dmabuf *seq_dmabuf;
James Smart4f774512009-05-22 14:52:35 -040015443 struct fc_frame_header *fc_hdr;
15444 struct lpfc_vport *vport;
15445 uint32_t fcfi;
James Smart939723a2012-05-09 21:19:03 -040015446 uint32_t did;
James Smart4f774512009-05-22 14:52:35 -040015447
James Smart4f774512009-05-22 14:52:35 -040015448 /* Process each received buffer */
James Smart4d9ab992009-10-02 15:16:39 -040015449 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
15450 /* check to see if this a valid type of frame */
15451 if (lpfc_fc_frame_check(phba, fc_hdr)) {
15452 lpfc_in_buf_free(phba, &dmabuf->dbuf);
15453 return;
15454 }
James Smart7851fe22011-07-22 18:36:52 -040015455 if ((bf_get(lpfc_cqe_code,
15456 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
15457 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
15458 &dmabuf->cq_event.cqe.rcqe_cmpl);
15459 else
15460 fcfi = bf_get(lpfc_rcqe_fcf_id,
15461 &dmabuf->cq_event.cqe.rcqe_cmpl);
James Smart939723a2012-05-09 21:19:03 -040015462
James Smart4d9ab992009-10-02 15:16:39 -040015463 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
James Smart939723a2012-05-09 21:19:03 -040015464 if (!vport) {
James Smart4d9ab992009-10-02 15:16:39 -040015465 /* throw out the frame */
15466 lpfc_in_buf_free(phba, &dmabuf->dbuf);
15467 return;
15468 }
James Smart939723a2012-05-09 21:19:03 -040015469
15470 /* d_id this frame is directed to */
15471 did = sli4_did_from_fc_hdr(fc_hdr);
15472
15473 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
15474 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
15475 (did != Fabric_DID)) {
15476 /*
15477 * Throw out the frame if we are not pt2pt.
15478 * The pt2pt protocol allows for discovery frames
15479 * to be received without a registered VPI.
15480 */
15481 if (!(vport->fc_flag & FC_PT2PT) ||
15482 (phba->link_state == LPFC_HBA_READY)) {
15483 lpfc_in_buf_free(phba, &dmabuf->dbuf);
15484 return;
15485 }
15486 }
15487
James Smart6669f9b2009-10-02 15:16:45 -040015488 /* Handle the basic abort sequence (BA_ABTS) event */
15489 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
15490 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
15491 return;
15492 }
15493
James Smart4d9ab992009-10-02 15:16:39 -040015494 /* Link this frame */
15495 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
15496 if (!seq_dmabuf) {
15497 /* unable to add frame to vport - throw it out */
15498 lpfc_in_buf_free(phba, &dmabuf->dbuf);
15499 return;
15500 }
15501 /* If not last frame in sequence continue processing frames. */
James Smartdef9c7a2009-12-21 17:02:28 -050015502 if (!lpfc_seq_complete(seq_dmabuf))
James Smart4d9ab992009-10-02 15:16:39 -040015503 return;
James Smartdef9c7a2009-12-21 17:02:28 -050015504
James Smart6669f9b2009-10-02 15:16:45 -040015505 /* Send the complete sequence to the upper layer protocol */
15506 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
James Smart4f774512009-05-22 14:52:35 -040015507}
James Smart6fb120a2009-05-22 14:52:59 -040015508
15509/**
15510 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
15511 * @phba: pointer to lpfc hba data structure.
15512 *
15513 * This routine is invoked to post rpi header templates to the
15514 * HBA consistent with the SLI-4 interface spec. This routine
James Smart49198b32010-04-06 15:04:33 -040015515 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15516 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
James Smart6fb120a2009-05-22 14:52:59 -040015517 *
15518 * This routine does not require any locks. It's usage is expected
15519 * to be driver load or reset recovery when the driver is
15520 * sequential.
15521 *
15522 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020015523 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -040015524 * -EIO - The mailbox failed to complete successfully.
James Smart6fb120a2009-05-22 14:52:59 -040015525 * When this error occurs, the driver is not guaranteed
15526 * to have any rpi regions posted to the device and
15527 * must either attempt to repost the regions or take a
15528 * fatal error.
15529 **/
15530int
15531lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
15532{
15533 struct lpfc_rpi_hdr *rpi_page;
15534 uint32_t rc = 0;
James Smart6d368e52011-05-24 11:44:12 -040015535 uint16_t lrpi = 0;
James Smart6fb120a2009-05-22 14:52:59 -040015536
James Smart6d368e52011-05-24 11:44:12 -040015537 /* SLI4 ports that support extents do not require RPI headers. */
15538 if (!phba->sli4_hba.rpi_hdrs_in_use)
15539 goto exit;
15540 if (phba->sli4_hba.extents_in_use)
15541 return -EIO;
15542
James Smart6fb120a2009-05-22 14:52:59 -040015543 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
James Smart6d368e52011-05-24 11:44:12 -040015544 /*
15545 * Assign the rpi headers a physical rpi only if the driver
15546 * has not initialized those resources. A port reset only
15547 * needs the headers posted.
15548 */
15549 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
15550 LPFC_RPI_RSRC_RDY)
15551 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
15552
James Smart6fb120a2009-05-22 14:52:59 -040015553 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
15554 if (rc != MBX_SUCCESS) {
15555 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15556 "2008 Error %d posting all rpi "
15557 "headers\n", rc);
15558 rc = -EIO;
15559 break;
15560 }
15561 }
15562
James Smart6d368e52011-05-24 11:44:12 -040015563 exit:
15564 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
15565 LPFC_RPI_RSRC_RDY);
James Smart6fb120a2009-05-22 14:52:59 -040015566 return rc;
15567}
15568
15569/**
15570 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
15571 * @phba: pointer to lpfc hba data structure.
15572 * @rpi_page: pointer to the rpi memory region.
15573 *
15574 * This routine is invoked to post a single rpi header to the
15575 * HBA consistent with the SLI-4 interface spec. This memory region
15576 * maps up to 64 rpi context regions.
15577 *
15578 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020015579 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -040015580 * -ENOMEM - No available memory
15581 * -EIO - The mailbox failed to complete successfully.
James Smart6fb120a2009-05-22 14:52:59 -040015582 **/
15583int
15584lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
15585{
15586 LPFC_MBOXQ_t *mboxq;
15587 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
15588 uint32_t rc = 0;
James Smart6fb120a2009-05-22 14:52:59 -040015589 uint32_t shdr_status, shdr_add_status;
15590 union lpfc_sli4_cfg_shdr *shdr;
15591
James Smart6d368e52011-05-24 11:44:12 -040015592 /* SLI4 ports that support extents do not require RPI headers. */
15593 if (!phba->sli4_hba.rpi_hdrs_in_use)
15594 return rc;
15595 if (phba->sli4_hba.extents_in_use)
15596 return -EIO;
15597
James Smart6fb120a2009-05-22 14:52:59 -040015598 /* The port is notified of the header region via a mailbox command. */
15599 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15600 if (!mboxq) {
15601 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15602 "2001 Unable to allocate memory for issuing "
15603 "SLI_CONFIG_SPECIAL mailbox command\n");
15604 return -ENOMEM;
15605 }
15606
15607 /* Post all rpi memory regions to the port. */
15608 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
James Smart6fb120a2009-05-22 14:52:59 -040015609 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
15610 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
15611 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
James Smartfedd3b72011-02-16 12:39:24 -050015612 sizeof(struct lpfc_sli4_cfg_mhdr),
15613 LPFC_SLI4_MBX_EMBED);
James Smart6d368e52011-05-24 11:44:12 -040015614
15615
15616 /* Post the physical rpi to the port for this rpi header. */
James Smart6fb120a2009-05-22 14:52:59 -040015617 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
15618 rpi_page->start_rpi);
James Smart6d368e52011-05-24 11:44:12 -040015619 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
15620 hdr_tmpl, rpi_page->page_count);
15621
James Smart6fb120a2009-05-22 14:52:59 -040015622 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
15623 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
James Smartf1126682009-06-10 17:22:44 -040015624 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smart6fb120a2009-05-22 14:52:59 -040015625 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
15626 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15627 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15628 if (rc != MBX_TIMEOUT)
15629 mempool_free(mboxq, phba->mbox_mem_pool);
15630 if (shdr_status || shdr_add_status || rc) {
15631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15632 "2514 POST_RPI_HDR mailbox failed with "
15633 "status x%x add_status x%x, mbx status x%x\n",
15634 shdr_status, shdr_add_status, rc);
15635 rc = -ENXIO;
15636 }
15637 return rc;
15638}
15639
15640/**
15641 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
15642 * @phba: pointer to lpfc hba data structure.
15643 *
15644 * This routine is invoked to post rpi header templates to the
15645 * HBA consistent with the SLI-4 interface spec. This routine
James Smart49198b32010-04-06 15:04:33 -040015646 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15647 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
James Smart6fb120a2009-05-22 14:52:59 -040015648 *
15649 * Returns
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020015650 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
James Smart6fb120a2009-05-22 14:52:59 -040015651 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15652 **/
15653int
15654lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
15655{
James Smart6d368e52011-05-24 11:44:12 -040015656 unsigned long rpi;
15657 uint16_t max_rpi, rpi_limit;
15658 uint16_t rpi_remaining, lrpi = 0;
James Smart6fb120a2009-05-22 14:52:59 -040015659 struct lpfc_rpi_hdr *rpi_hdr;
James Smart4902b382013-10-10 12:20:35 -040015660 unsigned long iflag;
James Smart6fb120a2009-05-22 14:52:59 -040015661
15662 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
James Smart6fb120a2009-05-22 14:52:59 -040015663 rpi_limit = phba->sli4_hba.next_rpi;
15664
15665 /*
James Smart6d368e52011-05-24 11:44:12 -040015666 * Fetch the next logical rpi. Because this index is logical,
15667 * the driver starts at 0 each time.
James Smart6fb120a2009-05-22 14:52:59 -040015668 */
James Smart4902b382013-10-10 12:20:35 -040015669 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart6d368e52011-05-24 11:44:12 -040015670 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
15671 if (rpi >= rpi_limit)
James Smart6fb120a2009-05-22 14:52:59 -040015672 rpi = LPFC_RPI_ALLOC_ERROR;
15673 else {
15674 set_bit(rpi, phba->sli4_hba.rpi_bmask);
15675 phba->sli4_hba.max_cfg_param.rpi_used++;
15676 phba->sli4_hba.rpi_count++;
15677 }
15678
15679 /*
15680 * Don't try to allocate more rpi header regions if the device limit
James Smart6d368e52011-05-24 11:44:12 -040015681 * has been exhausted.
James Smart6fb120a2009-05-22 14:52:59 -040015682 */
15683 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
15684 (phba->sli4_hba.rpi_count >= max_rpi)) {
James Smart4902b382013-10-10 12:20:35 -040015685 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart6fb120a2009-05-22 14:52:59 -040015686 return rpi;
15687 }
15688
15689 /*
James Smart6d368e52011-05-24 11:44:12 -040015690 * RPI header postings are not required for SLI4 ports capable of
15691 * extents.
15692 */
15693 if (!phba->sli4_hba.rpi_hdrs_in_use) {
James Smart4902b382013-10-10 12:20:35 -040015694 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart6d368e52011-05-24 11:44:12 -040015695 return rpi;
15696 }
15697
15698 /*
James Smart6fb120a2009-05-22 14:52:59 -040015699 * If the driver is running low on rpi resources, allocate another
15700 * page now. Note that the next_rpi value is used because
15701 * it represents how many are actually in use whereas max_rpi notes
15702 * how many are supported max by the device.
15703 */
James Smart6d368e52011-05-24 11:44:12 -040015704 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
James Smart4902b382013-10-10 12:20:35 -040015705 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart6fb120a2009-05-22 14:52:59 -040015706 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
15707 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
15708 if (!rpi_hdr) {
15709 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15710 "2002 Error Could not grow rpi "
15711 "count\n");
15712 } else {
James Smart6d368e52011-05-24 11:44:12 -040015713 lrpi = rpi_hdr->start_rpi;
15714 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
James Smart6fb120a2009-05-22 14:52:59 -040015715 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
15716 }
15717 }
15718
15719 return rpi;
15720}
15721
15722/**
15723 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15724 * @phba: pointer to lpfc hba data structure.
15725 *
15726 * This routine is invoked to release an rpi to the pool of
15727 * available rpis maintained by the driver.
15728 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040015729static void
James Smartd7c47992010-06-08 18:31:54 -040015730__lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
15731{
15732 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
15733 phba->sli4_hba.rpi_count--;
15734 phba->sli4_hba.max_cfg_param.rpi_used--;
15735 }
15736}
15737
15738/**
15739 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15740 * @phba: pointer to lpfc hba data structure.
15741 *
15742 * This routine is invoked to release an rpi to the pool of
15743 * available rpis maintained by the driver.
15744 **/
15745void
James Smart6fb120a2009-05-22 14:52:59 -040015746lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
15747{
15748 spin_lock_irq(&phba->hbalock);
James Smartd7c47992010-06-08 18:31:54 -040015749 __lpfc_sli4_free_rpi(phba, rpi);
James Smart6fb120a2009-05-22 14:52:59 -040015750 spin_unlock_irq(&phba->hbalock);
15751}
15752
15753/**
15754 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
15755 * @phba: pointer to lpfc hba data structure.
15756 *
15757 * This routine is invoked to remove the memory region that
15758 * provided rpi via a bitmask.
15759 **/
15760void
15761lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
15762{
15763 kfree(phba->sli4_hba.rpi_bmask);
James Smart6d368e52011-05-24 11:44:12 -040015764 kfree(phba->sli4_hba.rpi_ids);
15765 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
James Smart6fb120a2009-05-22 14:52:59 -040015766}
15767
15768/**
15769 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
15770 * @phba: pointer to lpfc hba data structure.
15771 *
15772 * This routine is invoked to remove the memory region that
15773 * provided rpi via a bitmask.
15774 **/
15775int
James Smart6b5151f2012-01-18 16:24:06 -050015776lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
15777 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
James Smart6fb120a2009-05-22 14:52:59 -040015778{
15779 LPFC_MBOXQ_t *mboxq;
15780 struct lpfc_hba *phba = ndlp->phba;
15781 int rc;
15782
15783 /* The port is notified of the header region via a mailbox command. */
15784 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15785 if (!mboxq)
15786 return -ENOMEM;
15787
15788 /* Post all rpi memory regions to the port. */
15789 lpfc_resume_rpi(mboxq, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -050015790 if (cmpl) {
15791 mboxq->mbox_cmpl = cmpl;
15792 mboxq->context1 = arg;
15793 mboxq->context2 = ndlp;
James Smart72859902012-01-18 16:25:38 -050015794 } else
15795 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6b5151f2012-01-18 16:24:06 -050015796 mboxq->vport = ndlp->vport;
James Smart6fb120a2009-05-22 14:52:59 -040015797 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
15798 if (rc == MBX_NOT_FINISHED) {
15799 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15800 "2010 Resume RPI Mailbox failed "
15801 "status %d, mbxStatus x%x\n", rc,
15802 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
15803 mempool_free(mboxq, phba->mbox_mem_pool);
15804 return -EIO;
15805 }
15806 return 0;
15807}
15808
15809/**
15810 * lpfc_sli4_init_vpi - Initialize a vpi with the port
James Smart76a95d72010-11-20 23:11:48 -050015811 * @vport: Pointer to the vport for which the vpi is being initialized
James Smart6fb120a2009-05-22 14:52:59 -040015812 *
James Smart76a95d72010-11-20 23:11:48 -050015813 * This routine is invoked to activate a vpi with the port.
James Smart6fb120a2009-05-22 14:52:59 -040015814 *
15815 * Returns:
15816 * 0 success
15817 * -Evalue otherwise
15818 **/
15819int
James Smart76a95d72010-11-20 23:11:48 -050015820lpfc_sli4_init_vpi(struct lpfc_vport *vport)
James Smart6fb120a2009-05-22 14:52:59 -040015821{
15822 LPFC_MBOXQ_t *mboxq;
15823 int rc = 0;
James Smart6a9c52c2009-10-02 15:16:51 -040015824 int retval = MBX_SUCCESS;
James Smart6fb120a2009-05-22 14:52:59 -040015825 uint32_t mbox_tmo;
James Smart76a95d72010-11-20 23:11:48 -050015826 struct lpfc_hba *phba = vport->phba;
James Smart6fb120a2009-05-22 14:52:59 -040015827 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15828 if (!mboxq)
15829 return -ENOMEM;
James Smart76a95d72010-11-20 23:11:48 -050015830 lpfc_init_vpi(phba, mboxq, vport->vpi);
James Smarta183a152011-10-10 21:32:43 -040015831 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart6fb120a2009-05-22 14:52:59 -040015832 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
James Smart6fb120a2009-05-22 14:52:59 -040015833 if (rc != MBX_SUCCESS) {
James Smart76a95d72010-11-20 23:11:48 -050015834 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
James Smart6fb120a2009-05-22 14:52:59 -040015835 "2022 INIT VPI Mailbox failed "
15836 "status %d, mbxStatus x%x\n", rc,
15837 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smart6a9c52c2009-10-02 15:16:51 -040015838 retval = -EIO;
James Smart6fb120a2009-05-22 14:52:59 -040015839 }
James Smart6a9c52c2009-10-02 15:16:51 -040015840 if (rc != MBX_TIMEOUT)
James Smart76a95d72010-11-20 23:11:48 -050015841 mempool_free(mboxq, vport->phba->mbox_mem_pool);
James Smart6a9c52c2009-10-02 15:16:51 -040015842
15843 return retval;
James Smart6fb120a2009-05-22 14:52:59 -040015844}
15845
15846/**
15847 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
15848 * @phba: pointer to lpfc hba data structure.
15849 * @mboxq: Pointer to mailbox object.
15850 *
15851 * This routine is invoked to manually add a single FCF record. The caller
15852 * must pass a completely initialized FCF_Record. This routine takes
15853 * care of the nonembedded mailbox operations.
15854 **/
15855static void
15856lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
15857{
15858 void *virt_addr;
15859 union lpfc_sli4_cfg_shdr *shdr;
15860 uint32_t shdr_status, shdr_add_status;
15861
15862 virt_addr = mboxq->sge_array->addr[0];
15863 /* The IOCTL status is embedded in the mailbox subheader. */
15864 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
15865 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15866 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15867
15868 if ((shdr_status || shdr_add_status) &&
15869 (shdr_status != STATUS_FCF_IN_USE))
15870 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15871 "2558 ADD_FCF_RECORD mailbox failed with "
15872 "status x%x add_status x%x\n",
15873 shdr_status, shdr_add_status);
15874
15875 lpfc_sli4_mbox_cmd_free(phba, mboxq);
15876}
15877
15878/**
15879 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
15880 * @phba: pointer to lpfc hba data structure.
15881 * @fcf_record: pointer to the initialized fcf record to add.
15882 *
15883 * This routine is invoked to manually add a single FCF record. The caller
15884 * must pass a completely initialized FCF_Record. This routine takes
15885 * care of the nonembedded mailbox operations.
15886 **/
15887int
15888lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
15889{
15890 int rc = 0;
15891 LPFC_MBOXQ_t *mboxq;
15892 uint8_t *bytep;
15893 void *virt_addr;
15894 dma_addr_t phys_addr;
15895 struct lpfc_mbx_sge sge;
15896 uint32_t alloc_len, req_len;
15897 uint32_t fcfindex;
15898
15899 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15900 if (!mboxq) {
15901 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15902 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
15903 return -ENOMEM;
15904 }
15905
15906 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
15907 sizeof(uint32_t);
15908
15909 /* Allocate DMA memory and set up the non-embedded mailbox command */
15910 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
15911 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
15912 req_len, LPFC_SLI4_MBX_NEMBED);
15913 if (alloc_len < req_len) {
15914 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15915 "2523 Allocated DMA memory size (x%x) is "
15916 "less than the requested DMA memory "
15917 "size (x%x)\n", alloc_len, req_len);
15918 lpfc_sli4_mbox_cmd_free(phba, mboxq);
15919 return -ENOMEM;
15920 }
15921
15922 /*
15923 * Get the first SGE entry from the non-embedded DMA memory. This
15924 * routine only uses a single SGE.
15925 */
15926 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
15927 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
James Smart6fb120a2009-05-22 14:52:59 -040015928 virt_addr = mboxq->sge_array->addr[0];
15929 /*
15930 * Configure the FCF record for FCFI 0. This is the driver's
15931 * hardcoded default and gets used in nonFIP mode.
15932 */
15933 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
15934 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
15935 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
15936
15937 /*
15938 * Copy the fcf_index and the FCF Record Data. The data starts after
15939 * the FCoE header plus word10. The data copy needs to be endian
15940 * correct.
15941 */
15942 bytep += sizeof(uint32_t);
15943 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
15944 mboxq->vport = phba->pport;
15945 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
15946 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
15947 if (rc == MBX_NOT_FINISHED) {
15948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15949 "2515 ADD_FCF_RECORD mailbox failed with "
15950 "status 0x%x\n", rc);
15951 lpfc_sli4_mbox_cmd_free(phba, mboxq);
15952 rc = -EIO;
15953 } else
15954 rc = 0;
15955
15956 return rc;
15957}
15958
15959/**
15960 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
15961 * @phba: pointer to lpfc hba data structure.
15962 * @fcf_record: pointer to the fcf record to write the default data.
15963 * @fcf_index: FCF table entry index.
15964 *
15965 * This routine is invoked to build the driver's default FCF record. The
15966 * values used are hardcoded. This routine handles memory initialization.
15967 *
15968 **/
15969void
15970lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
15971 struct fcf_record *fcf_record,
15972 uint16_t fcf_index)
15973{
15974 memset(fcf_record, 0, sizeof(struct fcf_record));
15975 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
15976 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
15977 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
15978 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
15979 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
15980 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
15981 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
15982 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
15983 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
15984 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
15985 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
15986 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
15987 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
James Smart0c287582009-06-10 17:22:56 -040015988 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
James Smart6fb120a2009-05-22 14:52:59 -040015989 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
15990 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
15991 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
15992 /* Set the VLAN bit map */
15993 if (phba->valid_vlan) {
15994 fcf_record->vlan_bitmap[phba->vlan_id / 8]
15995 = 1 << (phba->vlan_id % 8);
15996 }
15997}
15998
15999/**
James Smart0c9ab6f2010-02-26 14:15:57 -050016000 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
James Smart6fb120a2009-05-22 14:52:59 -040016001 * @phba: pointer to lpfc hba data structure.
16002 * @fcf_index: FCF table entry offset.
16003 *
James Smart0c9ab6f2010-02-26 14:15:57 -050016004 * This routine is invoked to scan the entire FCF table by reading FCF
16005 * record and processing it one at a time starting from the @fcf_index
16006 * for initial FCF discovery or fast FCF failover rediscovery.
16007 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030016008 * Return 0 if the mailbox command is submitted successfully, none 0
James Smart0c9ab6f2010-02-26 14:15:57 -050016009 * otherwise.
James Smart6fb120a2009-05-22 14:52:59 -040016010 **/
16011int
James Smart0c9ab6f2010-02-26 14:15:57 -050016012lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -040016013{
16014 int rc = 0, error;
16015 LPFC_MBOXQ_t *mboxq;
James Smart6fb120a2009-05-22 14:52:59 -040016016
James Smart32b97932009-07-19 10:01:21 -040016017 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
James Smart80c17842012-03-01 22:35:45 -050016018 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
James Smart6fb120a2009-05-22 14:52:59 -040016019 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16020 if (!mboxq) {
16021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16022 "2000 Failed to allocate mbox for "
16023 "READ_FCF cmd\n");
James Smart4d9ab992009-10-02 15:16:39 -040016024 error = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -050016025 goto fail_fcf_scan;
James Smart6fb120a2009-05-22 14:52:59 -040016026 }
James Smartecfd03c2010-02-12 14:41:27 -050016027 /* Construct the read FCF record mailbox command */
James Smart0c9ab6f2010-02-26 14:15:57 -050016028 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
James Smartecfd03c2010-02-12 14:41:27 -050016029 if (rc) {
16030 error = -EINVAL;
James Smart0c9ab6f2010-02-26 14:15:57 -050016031 goto fail_fcf_scan;
James Smart6fb120a2009-05-22 14:52:59 -040016032 }
James Smartecfd03c2010-02-12 14:41:27 -050016033 /* Issue the mailbox command asynchronously */
James Smart6fb120a2009-05-22 14:52:59 -040016034 mboxq->vport = phba->pport;
James Smart0c9ab6f2010-02-26 14:15:57 -050016035 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
James Smarta93ff372010-10-22 11:06:08 -040016036
16037 spin_lock_irq(&phba->hbalock);
16038 phba->hba_flag |= FCF_TS_INPROG;
16039 spin_unlock_irq(&phba->hbalock);
16040
James Smart6fb120a2009-05-22 14:52:59 -040016041 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
James Smartecfd03c2010-02-12 14:41:27 -050016042 if (rc == MBX_NOT_FINISHED)
James Smart6fb120a2009-05-22 14:52:59 -040016043 error = -EIO;
James Smartecfd03c2010-02-12 14:41:27 -050016044 else {
James Smart38b92ef2010-08-04 16:11:39 -040016045 /* Reset eligible FCF count for new scan */
16046 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
James Smart999d8132010-03-15 11:24:56 -040016047 phba->fcf.eligible_fcf_cnt = 0;
James Smart6fb120a2009-05-22 14:52:59 -040016048 error = 0;
James Smart32b97932009-07-19 10:01:21 -040016049 }
James Smart0c9ab6f2010-02-26 14:15:57 -050016050fail_fcf_scan:
James Smart4d9ab992009-10-02 15:16:39 -040016051 if (error) {
16052 if (mboxq)
16053 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smarta93ff372010-10-22 11:06:08 -040016054 /* FCF scan failed, clear FCF_TS_INPROG flag */
James Smart4d9ab992009-10-02 15:16:39 -040016055 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -040016056 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart4d9ab992009-10-02 15:16:39 -040016057 spin_unlock_irq(&phba->hbalock);
16058 }
James Smart6fb120a2009-05-22 14:52:59 -040016059 return error;
16060}
James Smarta0c87cb2009-07-19 10:01:10 -040016061
16062/**
James Smarta93ff372010-10-22 11:06:08 -040016063 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
James Smart0c9ab6f2010-02-26 14:15:57 -050016064 * @phba: pointer to lpfc hba data structure.
16065 * @fcf_index: FCF table entry offset.
16066 *
16067 * This routine is invoked to read an FCF record indicated by @fcf_index
James Smarta93ff372010-10-22 11:06:08 -040016068 * and to use it for FLOGI roundrobin FCF failover.
James Smart0c9ab6f2010-02-26 14:15:57 -050016069 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030016070 * Return 0 if the mailbox command is submitted successfully, none 0
James Smart0c9ab6f2010-02-26 14:15:57 -050016071 * otherwise.
16072 **/
16073int
16074lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
16075{
16076 int rc = 0, error;
16077 LPFC_MBOXQ_t *mboxq;
16078
16079 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16080 if (!mboxq) {
16081 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
16082 "2763 Failed to allocate mbox for "
16083 "READ_FCF cmd\n");
16084 error = -ENOMEM;
16085 goto fail_fcf_read;
16086 }
16087 /* Construct the read FCF record mailbox command */
16088 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
16089 if (rc) {
16090 error = -EINVAL;
16091 goto fail_fcf_read;
16092 }
16093 /* Issue the mailbox command asynchronously */
16094 mboxq->vport = phba->pport;
16095 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
16096 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16097 if (rc == MBX_NOT_FINISHED)
16098 error = -EIO;
16099 else
16100 error = 0;
16101
16102fail_fcf_read:
16103 if (error && mboxq)
16104 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16105 return error;
16106}
16107
16108/**
16109 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
16110 * @phba: pointer to lpfc hba data structure.
16111 * @fcf_index: FCF table entry offset.
16112 *
16113 * This routine is invoked to read an FCF record indicated by @fcf_index to
James Smarta93ff372010-10-22 11:06:08 -040016114 * determine whether it's eligible for FLOGI roundrobin failover list.
James Smart0c9ab6f2010-02-26 14:15:57 -050016115 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030016116 * Return 0 if the mailbox command is submitted successfully, none 0
James Smart0c9ab6f2010-02-26 14:15:57 -050016117 * otherwise.
16118 **/
16119int
16120lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
16121{
16122 int rc = 0, error;
16123 LPFC_MBOXQ_t *mboxq;
16124
16125 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16126 if (!mboxq) {
16127 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
16128 "2758 Failed to allocate mbox for "
16129 "READ_FCF cmd\n");
16130 error = -ENOMEM;
16131 goto fail_fcf_read;
16132 }
16133 /* Construct the read FCF record mailbox command */
16134 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
16135 if (rc) {
16136 error = -EINVAL;
16137 goto fail_fcf_read;
16138 }
16139 /* Issue the mailbox command asynchronously */
16140 mboxq->vport = phba->pport;
16141 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
16142 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16143 if (rc == MBX_NOT_FINISHED)
16144 error = -EIO;
16145 else
16146 error = 0;
16147
16148fail_fcf_read:
16149 if (error && mboxq)
16150 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16151 return error;
16152}
16153
16154/**
James Smart7d791df2011-07-22 18:37:52 -040016155 * lpfc_check_next_fcf_pri
16156 * phba pointer to the lpfc_hba struct for this port.
16157 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
16158 * routine when the rr_bmask is empty. The FCF indecies are put into the
16159 * rr_bmask based on their priority level. Starting from the highest priority
16160 * to the lowest. The most likely FCF candidate will be in the highest
16161 * priority group. When this routine is called it searches the fcf_pri list for
16162 * next lowest priority group and repopulates the rr_bmask with only those
16163 * fcf_indexes.
16164 * returns:
16165 * 1=success 0=failure
16166 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040016167static int
James Smart7d791df2011-07-22 18:37:52 -040016168lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
16169{
16170 uint16_t next_fcf_pri;
16171 uint16_t last_index;
16172 struct lpfc_fcf_pri *fcf_pri;
16173 int rc;
16174 int ret = 0;
16175
16176 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
16177 LPFC_SLI4_FCF_TBL_INDX_MAX);
16178 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
16179 "3060 Last IDX %d\n", last_index);
James Smart25626692013-03-01 16:36:54 -050016180
16181 /* Verify the priority list has 2 or more entries */
16182 spin_lock_irq(&phba->hbalock);
16183 if (list_empty(&phba->fcf.fcf_pri_list) ||
16184 list_is_singular(&phba->fcf.fcf_pri_list)) {
16185 spin_unlock_irq(&phba->hbalock);
James Smart7d791df2011-07-22 18:37:52 -040016186 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
16187 "3061 Last IDX %d\n", last_index);
16188 return 0; /* Empty rr list */
16189 }
James Smart25626692013-03-01 16:36:54 -050016190 spin_unlock_irq(&phba->hbalock);
16191
James Smart7d791df2011-07-22 18:37:52 -040016192 next_fcf_pri = 0;
16193 /*
16194 * Clear the rr_bmask and set all of the bits that are at this
16195 * priority.
16196 */
16197 memset(phba->fcf.fcf_rr_bmask, 0,
16198 sizeof(*phba->fcf.fcf_rr_bmask));
16199 spin_lock_irq(&phba->hbalock);
16200 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
16201 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
16202 continue;
16203 /*
16204 * the 1st priority that has not FLOGI failed
16205 * will be the highest.
16206 */
16207 if (!next_fcf_pri)
16208 next_fcf_pri = fcf_pri->fcf_rec.priority;
16209 spin_unlock_irq(&phba->hbalock);
16210 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
16211 rc = lpfc_sli4_fcf_rr_index_set(phba,
16212 fcf_pri->fcf_rec.fcf_index);
16213 if (rc)
16214 return 0;
16215 }
16216 spin_lock_irq(&phba->hbalock);
16217 }
16218 /*
16219 * if next_fcf_pri was not set above and the list is not empty then
16220 * we have failed flogis on all of them. So reset flogi failed
Anatol Pomozov4907cb72012-09-01 10:31:09 -070016221 * and start at the beginning.
James Smart7d791df2011-07-22 18:37:52 -040016222 */
16223 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
16224 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
16225 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
16226 /*
16227 * the 1st priority that has not FLOGI failed
16228 * will be the highest.
16229 */
16230 if (!next_fcf_pri)
16231 next_fcf_pri = fcf_pri->fcf_rec.priority;
16232 spin_unlock_irq(&phba->hbalock);
16233 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
16234 rc = lpfc_sli4_fcf_rr_index_set(phba,
16235 fcf_pri->fcf_rec.fcf_index);
16236 if (rc)
16237 return 0;
16238 }
16239 spin_lock_irq(&phba->hbalock);
16240 }
16241 } else
16242 ret = 1;
16243 spin_unlock_irq(&phba->hbalock);
16244
16245 return ret;
16246}
16247/**
James Smart0c9ab6f2010-02-26 14:15:57 -050016248 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
16249 * @phba: pointer to lpfc hba data structure.
16250 *
16251 * This routine is to get the next eligible FCF record index in a round
16252 * robin fashion. If the next eligible FCF record index equals to the
James Smarta93ff372010-10-22 11:06:08 -040016253 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
James Smart0c9ab6f2010-02-26 14:15:57 -050016254 * shall be returned, otherwise, the next eligible FCF record's index
16255 * shall be returned.
16256 **/
16257uint16_t
16258lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
16259{
16260 uint16_t next_fcf_index;
16261
James Smart421c6622013-01-03 15:44:16 -050016262initial_priority:
James Smart3804dc82010-07-14 15:31:37 -040016263 /* Search start from next bit of currently registered FCF index */
James Smart421c6622013-01-03 15:44:16 -050016264 next_fcf_index = phba->fcf.current_rec.fcf_indx;
16265
James Smart7d791df2011-07-22 18:37:52 -040016266next_priority:
James Smart421c6622013-01-03 15:44:16 -050016267 /* Determine the next fcf index to check */
16268 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
James Smart0c9ab6f2010-02-26 14:15:57 -050016269 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
16270 LPFC_SLI4_FCF_TBL_INDX_MAX,
James Smart3804dc82010-07-14 15:31:37 -040016271 next_fcf_index);
16272
James Smart0c9ab6f2010-02-26 14:15:57 -050016273 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
James Smart7d791df2011-07-22 18:37:52 -040016274 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
16275 /*
16276 * If we have wrapped then we need to clear the bits that
16277 * have been tested so that we can detect when we should
16278 * change the priority level.
16279 */
James Smart0c9ab6f2010-02-26 14:15:57 -050016280 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
16281 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
James Smart7d791df2011-07-22 18:37:52 -040016282 }
16283
James Smart0c9ab6f2010-02-26 14:15:57 -050016284
James Smart3804dc82010-07-14 15:31:37 -040016285 /* Check roundrobin failover list empty condition */
James Smart7d791df2011-07-22 18:37:52 -040016286 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
16287 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
16288 /*
16289 * If next fcf index is not found check if there are lower
16290 * Priority level fcf's in the fcf_priority list.
16291 * Set up the rr_bmask with all of the avaiable fcf bits
16292 * at that level and continue the selection process.
16293 */
16294 if (lpfc_check_next_fcf_pri_level(phba))
James Smart421c6622013-01-03 15:44:16 -050016295 goto initial_priority;
James Smart3804dc82010-07-14 15:31:37 -040016296 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
16297 "2844 No roundrobin failover FCF available\n");
James Smart7d791df2011-07-22 18:37:52 -040016298 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
16299 return LPFC_FCOE_FCF_NEXT_NONE;
16300 else {
16301 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
16302 "3063 Only FCF available idx %d, flag %x\n",
16303 next_fcf_index,
16304 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
16305 return next_fcf_index;
16306 }
James Smart3804dc82010-07-14 15:31:37 -040016307 }
16308
James Smart7d791df2011-07-22 18:37:52 -040016309 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
16310 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
16311 LPFC_FCF_FLOGI_FAILED)
16312 goto next_priority;
16313
James Smart3804dc82010-07-14 15:31:37 -040016314 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -040016315 "2845 Get next roundrobin failover FCF (x%x)\n",
16316 next_fcf_index);
16317
James Smart0c9ab6f2010-02-26 14:15:57 -050016318 return next_fcf_index;
16319}
16320
16321/**
16322 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
16323 * @phba: pointer to lpfc hba data structure.
16324 *
16325 * This routine sets the FCF record index in to the eligible bmask for
James Smarta93ff372010-10-22 11:06:08 -040016326 * roundrobin failover search. It checks to make sure that the index
James Smart0c9ab6f2010-02-26 14:15:57 -050016327 * does not go beyond the range of the driver allocated bmask dimension
16328 * before setting the bit.
16329 *
16330 * Returns 0 if the index bit successfully set, otherwise, it returns
16331 * -EINVAL.
16332 **/
16333int
16334lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
16335{
16336 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
16337 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -040016338 "2610 FCF (x%x) reached driver's book "
16339 "keeping dimension:x%x\n",
James Smart0c9ab6f2010-02-26 14:15:57 -050016340 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
16341 return -EINVAL;
16342 }
16343 /* Set the eligible FCF record index bmask */
16344 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
16345
James Smart3804dc82010-07-14 15:31:37 -040016346 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -040016347 "2790 Set FCF (x%x) to roundrobin FCF failover "
James Smart3804dc82010-07-14 15:31:37 -040016348 "bmask\n", fcf_index);
16349
James Smart0c9ab6f2010-02-26 14:15:57 -050016350 return 0;
16351}
16352
16353/**
James Smart3804dc82010-07-14 15:31:37 -040016354 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
James Smart0c9ab6f2010-02-26 14:15:57 -050016355 * @phba: pointer to lpfc hba data structure.
16356 *
16357 * This routine clears the FCF record index from the eligible bmask for
James Smarta93ff372010-10-22 11:06:08 -040016358 * roundrobin failover search. It checks to make sure that the index
James Smart0c9ab6f2010-02-26 14:15:57 -050016359 * does not go beyond the range of the driver allocated bmask dimension
16360 * before clearing the bit.
16361 **/
16362void
16363lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
16364{
James Smart9a803a72013-09-06 12:17:56 -040016365 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
James Smart0c9ab6f2010-02-26 14:15:57 -050016366 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
16367 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -040016368 "2762 FCF (x%x) reached driver's book "
16369 "keeping dimension:x%x\n",
James Smart0c9ab6f2010-02-26 14:15:57 -050016370 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
16371 return;
16372 }
16373 /* Clear the eligible FCF record index bmask */
James Smart7d791df2011-07-22 18:37:52 -040016374 spin_lock_irq(&phba->hbalock);
James Smart9a803a72013-09-06 12:17:56 -040016375 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
16376 list) {
James Smart7d791df2011-07-22 18:37:52 -040016377 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
16378 list_del_init(&fcf_pri->list);
16379 break;
16380 }
16381 }
16382 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -050016383 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
James Smart3804dc82010-07-14 15:31:37 -040016384
16385 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -040016386 "2791 Clear FCF (x%x) from roundrobin failover "
James Smart3804dc82010-07-14 15:31:37 -040016387 "bmask\n", fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -050016388}
16389
16390/**
James Smartecfd03c2010-02-12 14:41:27 -050016391 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
16392 * @phba: pointer to lpfc hba data structure.
16393 *
16394 * This routine is the completion routine for the rediscover FCF table mailbox
16395 * command. If the mailbox command returned failure, it will try to stop the
16396 * FCF rediscover wait timer.
16397 **/
Rashika Kheria5d8b8162014-09-03 12:55:04 -040016398static void
James Smartecfd03c2010-02-12 14:41:27 -050016399lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
16400{
16401 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
16402 uint32_t shdr_status, shdr_add_status;
16403
16404 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
16405
16406 shdr_status = bf_get(lpfc_mbox_hdr_status,
16407 &redisc_fcf->header.cfg_shdr.response);
16408 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
16409 &redisc_fcf->header.cfg_shdr.response);
16410 if (shdr_status || shdr_add_status) {
James Smart0c9ab6f2010-02-26 14:15:57 -050016411 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartecfd03c2010-02-12 14:41:27 -050016412 "2746 Requesting for FCF rediscovery failed "
16413 "status x%x add_status x%x\n",
16414 shdr_status, shdr_add_status);
James Smart0c9ab6f2010-02-26 14:15:57 -050016415 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
James Smartfc2b9892010-02-26 14:15:29 -050016416 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -050016417 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -050016418 spin_unlock_irq(&phba->hbalock);
16419 /*
16420 * CVL event triggered FCF rediscover request failed,
16421 * last resort to re-try current registered FCF entry.
16422 */
16423 lpfc_retry_pport_discovery(phba);
16424 } else {
16425 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -050016426 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -050016427 spin_unlock_irq(&phba->hbalock);
16428 /*
16429 * DEAD FCF event triggered FCF rediscover request
16430 * failed, last resort to fail over as a link down
16431 * to FCF registration.
16432 */
16433 lpfc_sli4_fcf_dead_failthrough(phba);
16434 }
James Smart0c9ab6f2010-02-26 14:15:57 -050016435 } else {
16436 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -040016437 "2775 Start FCF rediscover quiescent timer\n");
James Smartecfd03c2010-02-12 14:41:27 -050016438 /*
16439 * Start FCF rediscovery wait timer for pending FCF
16440 * before rescan FCF record table.
16441 */
16442 lpfc_fcf_redisc_wait_start_timer(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -050016443 }
James Smartecfd03c2010-02-12 14:41:27 -050016444
16445 mempool_free(mbox, phba->mbox_mem_pool);
16446}
16447
16448/**
James Smart3804dc82010-07-14 15:31:37 -040016449 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
James Smartecfd03c2010-02-12 14:41:27 -050016450 * @phba: pointer to lpfc hba data structure.
16451 *
16452 * This routine is invoked to request for rediscovery of the entire FCF table
16453 * by the port.
16454 **/
16455int
16456lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
16457{
16458 LPFC_MBOXQ_t *mbox;
16459 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
16460 int rc, length;
16461
James Smart0c9ab6f2010-02-26 14:15:57 -050016462 /* Cancel retry delay timers to all vports before FCF rediscover */
16463 lpfc_cancel_all_vport_retry_delay_timer(phba);
16464
James Smartecfd03c2010-02-12 14:41:27 -050016465 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16466 if (!mbox) {
16467 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16468 "2745 Failed to allocate mbox for "
16469 "requesting FCF rediscover.\n");
16470 return -ENOMEM;
16471 }
16472
16473 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
16474 sizeof(struct lpfc_sli4_cfg_mhdr));
16475 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16476 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
16477 length, LPFC_SLI4_MBX_EMBED);
16478
16479 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
16480 /* Set count to 0 for invalidating the entire FCF database */
16481 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
16482
16483 /* Issue the mailbox command asynchronously */
16484 mbox->vport = phba->pport;
16485 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
16486 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
16487
16488 if (rc == MBX_NOT_FINISHED) {
16489 mempool_free(mbox, phba->mbox_mem_pool);
16490 return -EIO;
16491 }
16492 return 0;
16493}
16494
16495/**
James Smartfc2b9892010-02-26 14:15:29 -050016496 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
16497 * @phba: pointer to lpfc hba data structure.
16498 *
16499 * This function is the failover routine as a last resort to the FCF DEAD
16500 * event when driver failed to perform fast FCF failover.
16501 **/
16502void
16503lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
16504{
16505 uint32_t link_state;
16506
16507 /*
16508 * Last resort as FCF DEAD event failover will treat this as
16509 * a link down, but save the link state because we don't want
16510 * it to be changed to Link Down unless it is already down.
16511 */
16512 link_state = phba->link_state;
16513 lpfc_linkdown(phba);
16514 phba->link_state = link_state;
16515
16516 /* Unregister FCF if no devices connected to it */
16517 lpfc_unregister_unused_fcf(phba);
16518}
16519
16520/**
James Smart026abb82011-12-13 13:20:45 -050016521 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
James Smarta0c87cb2009-07-19 10:01:10 -040016522 * @phba: pointer to lpfc hba data structure.
James Smart026abb82011-12-13 13:20:45 -050016523 * @rgn23_data: pointer to configure region 23 data.
James Smarta0c87cb2009-07-19 10:01:10 -040016524 *
James Smart026abb82011-12-13 13:20:45 -050016525 * This function gets SLI3 port configure region 23 data through memory dump
16526 * mailbox command. When it successfully retrieves data, the size of the data
16527 * will be returned, otherwise, 0 will be returned.
James Smarta0c87cb2009-07-19 10:01:10 -040016528 **/
James Smart026abb82011-12-13 13:20:45 -050016529static uint32_t
16530lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
James Smarta0c87cb2009-07-19 10:01:10 -040016531{
16532 LPFC_MBOXQ_t *pmb = NULL;
16533 MAILBOX_t *mb;
James Smart026abb82011-12-13 13:20:45 -050016534 uint32_t offset = 0;
James Smarta0c87cb2009-07-19 10:01:10 -040016535 int rc;
16536
James Smart026abb82011-12-13 13:20:45 -050016537 if (!rgn23_data)
16538 return 0;
16539
James Smarta0c87cb2009-07-19 10:01:10 -040016540 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16541 if (!pmb) {
16542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -050016543 "2600 failed to allocate mailbox memory\n");
16544 return 0;
James Smarta0c87cb2009-07-19 10:01:10 -040016545 }
16546 mb = &pmb->u.mb;
16547
James Smarta0c87cb2009-07-19 10:01:10 -040016548 do {
16549 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
16550 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
16551
16552 if (rc != MBX_SUCCESS) {
16553 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -050016554 "2601 failed to read config "
16555 "region 23, rc 0x%x Status 0x%x\n",
16556 rc, mb->mbxStatus);
James Smarta0c87cb2009-07-19 10:01:10 -040016557 mb->un.varDmp.word_cnt = 0;
16558 }
16559 /*
16560 * dump mem may return a zero when finished or we got a
16561 * mailbox error, either way we are done.
16562 */
16563 if (mb->un.varDmp.word_cnt == 0)
16564 break;
16565 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
16566 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
16567
16568 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
James Smart026abb82011-12-13 13:20:45 -050016569 rgn23_data + offset,
16570 mb->un.varDmp.word_cnt);
James Smarta0c87cb2009-07-19 10:01:10 -040016571 offset += mb->un.varDmp.word_cnt;
16572 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
16573
James Smart026abb82011-12-13 13:20:45 -050016574 mempool_free(pmb, phba->mbox_mem_pool);
16575 return offset;
16576}
16577
16578/**
16579 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
16580 * @phba: pointer to lpfc hba data structure.
16581 * @rgn23_data: pointer to configure region 23 data.
16582 *
16583 * This function gets SLI4 port configure region 23 data through memory dump
16584 * mailbox command. When it successfully retrieves data, the size of the data
16585 * will be returned, otherwise, 0 will be returned.
16586 **/
16587static uint32_t
16588lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
16589{
16590 LPFC_MBOXQ_t *mboxq = NULL;
16591 struct lpfc_dmabuf *mp = NULL;
16592 struct lpfc_mqe *mqe;
16593 uint32_t data_length = 0;
16594 int rc;
16595
16596 if (!rgn23_data)
16597 return 0;
16598
16599 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16600 if (!mboxq) {
16601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16602 "3105 failed to allocate mailbox memory\n");
16603 return 0;
16604 }
16605
16606 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
16607 goto out;
16608 mqe = &mboxq->u.mqe;
16609 mp = (struct lpfc_dmabuf *) mboxq->context1;
16610 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
16611 if (rc)
16612 goto out;
16613 data_length = mqe->un.mb_words[5];
16614 if (data_length == 0)
16615 goto out;
16616 if (data_length > DMP_RGN23_SIZE) {
16617 data_length = 0;
16618 goto out;
16619 }
16620 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
16621out:
16622 mempool_free(mboxq, phba->mbox_mem_pool);
16623 if (mp) {
16624 lpfc_mbuf_free(phba, mp->virt, mp->phys);
16625 kfree(mp);
16626 }
16627 return data_length;
16628}
16629
16630/**
16631 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
16632 * @phba: pointer to lpfc hba data structure.
16633 *
16634 * This function read region 23 and parse TLV for port status to
16635 * decide if the user disaled the port. If the TLV indicates the
16636 * port is disabled, the hba_flag is set accordingly.
16637 **/
16638void
16639lpfc_sli_read_link_ste(struct lpfc_hba *phba)
16640{
16641 uint8_t *rgn23_data = NULL;
16642 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
16643 uint32_t offset = 0;
16644
16645 /* Get adapter Region 23 data */
16646 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
16647 if (!rgn23_data)
16648 goto out;
16649
16650 if (phba->sli_rev < LPFC_SLI_REV4)
16651 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
16652 else {
16653 if_type = bf_get(lpfc_sli_intf_if_type,
16654 &phba->sli4_hba.sli_intf);
16655 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
16656 goto out;
16657 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
16658 }
James Smarta0c87cb2009-07-19 10:01:10 -040016659
16660 if (!data_size)
16661 goto out;
16662
16663 /* Check the region signature first */
16664 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
16665 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16666 "2619 Config region 23 has bad signature\n");
16667 goto out;
16668 }
16669 offset += 4;
16670
16671 /* Check the data structure version */
16672 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
16673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16674 "2620 Config region 23 has bad version\n");
16675 goto out;
16676 }
16677 offset += 4;
16678
16679 /* Parse TLV entries in the region */
16680 while (offset < data_size) {
16681 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
16682 break;
16683 /*
16684 * If the TLV is not driver specific TLV or driver id is
16685 * not linux driver id, skip the record.
16686 */
16687 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
16688 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
16689 (rgn23_data[offset + 3] != 0)) {
16690 offset += rgn23_data[offset + 1] * 4 + 4;
16691 continue;
16692 }
16693
16694 /* Driver found a driver specific TLV in the config region */
16695 sub_tlv_len = rgn23_data[offset + 1] * 4;
16696 offset += 4;
16697 tlv_offset = 0;
16698
16699 /*
16700 * Search for configured port state sub-TLV.
16701 */
16702 while ((offset < data_size) &&
16703 (tlv_offset < sub_tlv_len)) {
16704 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
16705 offset += 4;
16706 tlv_offset += 4;
16707 break;
16708 }
16709 if (rgn23_data[offset] != PORT_STE_TYPE) {
16710 offset += rgn23_data[offset + 1] * 4 + 4;
16711 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
16712 continue;
16713 }
16714
16715 /* This HBA contains PORT_STE configured */
16716 if (!rgn23_data[offset + 2])
16717 phba->hba_flag |= LINK_DISABLED;
16718
16719 goto out;
16720 }
16721 }
James Smart026abb82011-12-13 13:20:45 -050016722
James Smarta0c87cb2009-07-19 10:01:10 -040016723out:
James Smarta0c87cb2009-07-19 10:01:10 -040016724 kfree(rgn23_data);
16725 return;
16726}
James Smart695a8142010-01-26 23:08:03 -050016727
16728/**
James Smart52d52442011-05-24 11:42:45 -040016729 * lpfc_wr_object - write an object to the firmware
16730 * @phba: HBA structure that indicates port to create a queue on.
16731 * @dmabuf_list: list of dmabufs to write to the port.
16732 * @size: the total byte value of the objects to write to the port.
16733 * @offset: the current offset to be used to start the transfer.
16734 *
16735 * This routine will create a wr_object mailbox command to send to the port.
16736 * the mailbox command will be constructed using the dma buffers described in
16737 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
16738 * BDEs that the imbedded mailbox can support. The @offset variable will be
16739 * used to indicate the starting offset of the transfer and will also return
16740 * the offset after the write object mailbox has completed. @size is used to
16741 * determine the end of the object and whether the eof bit should be set.
16742 *
16743 * Return 0 is successful and offset will contain the the new offset to use
16744 * for the next write.
16745 * Return negative value for error cases.
16746 **/
16747int
16748lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
16749 uint32_t size, uint32_t *offset)
16750{
16751 struct lpfc_mbx_wr_object *wr_object;
16752 LPFC_MBOXQ_t *mbox;
16753 int rc = 0, i = 0;
16754 uint32_t shdr_status, shdr_add_status;
16755 uint32_t mbox_tmo;
16756 union lpfc_sli4_cfg_shdr *shdr;
16757 struct lpfc_dmabuf *dmabuf;
16758 uint32_t written = 0;
16759
16760 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16761 if (!mbox)
16762 return -ENOMEM;
16763
16764 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16765 LPFC_MBOX_OPCODE_WRITE_OBJECT,
16766 sizeof(struct lpfc_mbx_wr_object) -
16767 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
16768
16769 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
16770 wr_object->u.request.write_offset = *offset;
16771 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
16772 wr_object->u.request.object_name[0] =
16773 cpu_to_le32(wr_object->u.request.object_name[0]);
16774 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
16775 list_for_each_entry(dmabuf, dmabuf_list, list) {
16776 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
16777 break;
16778 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
16779 wr_object->u.request.bde[i].addrHigh =
16780 putPaddrHigh(dmabuf->phys);
16781 if (written + SLI4_PAGE_SIZE >= size) {
16782 wr_object->u.request.bde[i].tus.f.bdeSize =
16783 (size - written);
16784 written += (size - written);
16785 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
16786 } else {
16787 wr_object->u.request.bde[i].tus.f.bdeSize =
16788 SLI4_PAGE_SIZE;
16789 written += SLI4_PAGE_SIZE;
16790 }
16791 i++;
16792 }
16793 wr_object->u.request.bde_count = i;
16794 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
16795 if (!phba->sli4_hba.intr_enable)
16796 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16797 else {
James Smarta183a152011-10-10 21:32:43 -040016798 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
James Smart52d52442011-05-24 11:42:45 -040016799 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
16800 }
16801 /* The IOCTL status is embedded in the mailbox subheader. */
16802 shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
16803 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16804 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16805 if (rc != MBX_TIMEOUT)
16806 mempool_free(mbox, phba->mbox_mem_pool);
16807 if (shdr_status || shdr_add_status || rc) {
16808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16809 "3025 Write Object mailbox failed with "
16810 "status x%x add_status x%x, mbx status x%x\n",
16811 shdr_status, shdr_add_status, rc);
16812 rc = -ENXIO;
16813 } else
16814 *offset += wr_object->u.response.actual_write_length;
16815 return rc;
16816}
16817
16818/**
James Smart695a8142010-01-26 23:08:03 -050016819 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
16820 * @vport: pointer to vport data structure.
16821 *
16822 * This function iterate through the mailboxq and clean up all REG_LOGIN
16823 * and REG_VPI mailbox commands associated with the vport. This function
16824 * is called when driver want to restart discovery of the vport due to
16825 * a Clear Virtual Link event.
16826 **/
16827void
16828lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
16829{
16830 struct lpfc_hba *phba = vport->phba;
16831 LPFC_MBOXQ_t *mb, *nextmb;
16832 struct lpfc_dmabuf *mp;
James Smart78730cf2010-04-06 15:06:30 -040016833 struct lpfc_nodelist *ndlp;
James Smartd439d282010-09-29 11:18:45 -040016834 struct lpfc_nodelist *act_mbx_ndlp = NULL;
James Smart589a52d2010-07-14 15:30:54 -040016835 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartd439d282010-09-29 11:18:45 -040016836 LIST_HEAD(mbox_cmd_list);
James Smart63e801c2010-11-20 23:14:19 -050016837 uint8_t restart_loop;
James Smart695a8142010-01-26 23:08:03 -050016838
James Smartd439d282010-09-29 11:18:45 -040016839 /* Clean up internally queued mailbox commands with the vport */
James Smart695a8142010-01-26 23:08:03 -050016840 spin_lock_irq(&phba->hbalock);
16841 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
16842 if (mb->vport != vport)
16843 continue;
16844
16845 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
16846 (mb->u.mb.mbxCommand != MBX_REG_VPI))
16847 continue;
16848
James Smartd439d282010-09-29 11:18:45 -040016849 list_del(&mb->list);
16850 list_add_tail(&mb->list, &mbox_cmd_list);
16851 }
16852 /* Clean up active mailbox command with the vport */
16853 mb = phba->sli.mbox_active;
16854 if (mb && (mb->vport == vport)) {
16855 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
16856 (mb->u.mb.mbxCommand == MBX_REG_VPI))
16857 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16858 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
16859 act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
16860 /* Put reference count for delayed processing */
16861 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
16862 /* Unregister the RPI when mailbox complete */
16863 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
16864 }
16865 }
James Smart63e801c2010-11-20 23:14:19 -050016866 /* Cleanup any mailbox completions which are not yet processed */
16867 do {
16868 restart_loop = 0;
16869 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
16870 /*
16871 * If this mailox is already processed or it is
16872 * for another vport ignore it.
16873 */
16874 if ((mb->vport != vport) ||
16875 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
16876 continue;
16877
16878 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
16879 (mb->u.mb.mbxCommand != MBX_REG_VPI))
16880 continue;
16881
16882 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16883 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
16884 ndlp = (struct lpfc_nodelist *)mb->context2;
16885 /* Unregister the RPI when mailbox complete */
16886 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
16887 restart_loop = 1;
16888 spin_unlock_irq(&phba->hbalock);
16889 spin_lock(shost->host_lock);
16890 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
16891 spin_unlock(shost->host_lock);
16892 spin_lock_irq(&phba->hbalock);
16893 break;
16894 }
16895 }
16896 } while (restart_loop);
16897
James Smartd439d282010-09-29 11:18:45 -040016898 spin_unlock_irq(&phba->hbalock);
16899
16900 /* Release the cleaned-up mailbox commands */
16901 while (!list_empty(&mbox_cmd_list)) {
16902 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
James Smart695a8142010-01-26 23:08:03 -050016903 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
16904 mp = (struct lpfc_dmabuf *) (mb->context1);
16905 if (mp) {
16906 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
16907 kfree(mp);
16908 }
James Smart78730cf2010-04-06 15:06:30 -040016909 ndlp = (struct lpfc_nodelist *) mb->context2;
James Smartd439d282010-09-29 11:18:45 -040016910 mb->context2 = NULL;
James Smart78730cf2010-04-06 15:06:30 -040016911 if (ndlp) {
Dan Carpenterec21b3b2010-08-08 00:15:17 +020016912 spin_lock(shost->host_lock);
James Smart589a52d2010-07-14 15:30:54 -040016913 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
Dan Carpenterec21b3b2010-08-08 00:15:17 +020016914 spin_unlock(shost->host_lock);
James Smart78730cf2010-04-06 15:06:30 -040016915 lpfc_nlp_put(ndlp);
James Smart78730cf2010-04-06 15:06:30 -040016916 }
James Smart695a8142010-01-26 23:08:03 -050016917 }
James Smart695a8142010-01-26 23:08:03 -050016918 mempool_free(mb, phba->mbox_mem_pool);
16919 }
James Smartd439d282010-09-29 11:18:45 -040016920
16921 /* Release the ndlp with the cleaned-up active mailbox command */
16922 if (act_mbx_ndlp) {
16923 spin_lock(shost->host_lock);
16924 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
16925 spin_unlock(shost->host_lock);
16926 lpfc_nlp_put(act_mbx_ndlp);
James Smart695a8142010-01-26 23:08:03 -050016927 }
James Smart695a8142010-01-26 23:08:03 -050016928}
16929
James Smart2a9bf3d2010-06-07 15:24:45 -040016930/**
16931 * lpfc_drain_txq - Drain the txq
16932 * @phba: Pointer to HBA context object.
16933 *
16934 * This function attempt to submit IOCBs on the txq
16935 * to the adapter. For SLI4 adapters, the txq contains
16936 * ELS IOCBs that have been deferred because the there
16937 * are no SGLs. This congestion can occur with large
16938 * vport counts during node discovery.
16939 **/
16940
16941uint32_t
16942lpfc_drain_txq(struct lpfc_hba *phba)
16943{
16944 LIST_HEAD(completions);
16945 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
Daeseok Youn2e706372014-02-21 09:03:32 +090016946 struct lpfc_iocbq *piocbq = NULL;
James Smart2a9bf3d2010-06-07 15:24:45 -040016947 unsigned long iflags = 0;
16948 char *fail_msg = NULL;
16949 struct lpfc_sglq *sglq;
16950 union lpfc_wqe wqe;
James Smart0e9bb8d2013-03-01 16:35:12 -050016951 int txq_cnt = 0;
James Smart2a9bf3d2010-06-07 15:24:45 -040016952
James Smart398d81c2013-05-31 17:04:19 -040016953 spin_lock_irqsave(&pring->ring_lock, iflags);
James Smart0e9bb8d2013-03-01 16:35:12 -050016954 list_for_each_entry(piocbq, &pring->txq, list) {
16955 txq_cnt++;
16956 }
16957
16958 if (txq_cnt > pring->txq_max)
16959 pring->txq_max = txq_cnt;
James Smart2a9bf3d2010-06-07 15:24:45 -040016960
James Smart398d81c2013-05-31 17:04:19 -040016961 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smart2a9bf3d2010-06-07 15:24:45 -040016962
James Smart0e9bb8d2013-03-01 16:35:12 -050016963 while (!list_empty(&pring->txq)) {
James Smart398d81c2013-05-31 17:04:19 -040016964 spin_lock_irqsave(&pring->ring_lock, iflags);
James Smart2a9bf3d2010-06-07 15:24:45 -040016965
James Smart19ca7602010-11-20 23:11:55 -050016966 piocbq = lpfc_sli_ringtx_get(phba, pring);
James Smarta6298522012-06-12 13:54:11 -040016967 if (!piocbq) {
James Smart398d81c2013-05-31 17:04:19 -040016968 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smarta6298522012-06-12 13:54:11 -040016969 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16970 "2823 txq empty and txq_cnt is %d\n ",
James Smart0e9bb8d2013-03-01 16:35:12 -050016971 txq_cnt);
James Smarta6298522012-06-12 13:54:11 -040016972 break;
16973 }
James Smart19ca7602010-11-20 23:11:55 -050016974 sglq = __lpfc_sli_get_sglq(phba, piocbq);
James Smart2a9bf3d2010-06-07 15:24:45 -040016975 if (!sglq) {
James Smart19ca7602010-11-20 23:11:55 -050016976 __lpfc_sli_ringtx_put(phba, pring, piocbq);
James Smart398d81c2013-05-31 17:04:19 -040016977 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smart2a9bf3d2010-06-07 15:24:45 -040016978 break;
James Smart2a9bf3d2010-06-07 15:24:45 -040016979 }
James Smart0e9bb8d2013-03-01 16:35:12 -050016980 txq_cnt--;
James Smart2a9bf3d2010-06-07 15:24:45 -040016981
16982 /* The xri and iocb resources secured,
16983 * attempt to issue request
16984 */
James Smart6d368e52011-05-24 11:44:12 -040016985 piocbq->sli4_lxritag = sglq->sli4_lxritag;
James Smart2a9bf3d2010-06-07 15:24:45 -040016986 piocbq->sli4_xritag = sglq->sli4_xritag;
16987 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
16988 fail_msg = "to convert bpl to sgl";
16989 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
16990 fail_msg = "to convert iocb to wqe";
16991 else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
16992 fail_msg = " - Wq is full";
16993 else
16994 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
16995
16996 if (fail_msg) {
16997 /* Failed means we can't issue and need to cancel */
16998 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16999 "2822 IOCB failed %s iotag 0x%x "
17000 "xri 0x%x\n",
17001 fail_msg,
17002 piocbq->iotag, piocbq->sli4_xritag);
17003 list_add_tail(&piocbq->list, &completions);
17004 }
James Smart398d81c2013-05-31 17:04:19 -040017005 spin_unlock_irqrestore(&pring->ring_lock, iflags);
James Smart2a9bf3d2010-06-07 15:24:45 -040017006 }
17007
James Smart2a9bf3d2010-06-07 15:24:45 -040017008 /* Cancel all the IOCBs that cannot be issued */
17009 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
17010 IOERR_SLI_ABORTED);
17011
James Smart0e9bb8d2013-03-01 16:35:12 -050017012 return txq_cnt;
James Smart2a9bf3d2010-06-07 15:24:45 -040017013}