blob: 41f13a300ba5323e0b8fc7475b8ce7f459b6896b [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 Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 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>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_cmnd.h>
29#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040031#include <scsi/scsi_transport_fc.h>
dea31012005-04-17 16:05:31 -050032
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
35#include "lpfc_disc.h"
36#include "lpfc_scsi.h"
37#include "lpfc.h"
38#include "lpfc_crtn.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050041#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050042
43/*
44 * Define macro to log: Mailbox command x%x cannot issue Data
45 * This allows multiple uses of lpfc_msgBlk0311
46 * w/o perturbing log msg utility.
47 */
James Smart92d7f7b2007-06-17 19:56:38 -050048#define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
dea31012005-04-17 16:05:31 -050049 lpfc_printf_log(phba, \
50 KERN_INFO, \
51 LOG_MBOX | LOG_SLI, \
James Smarte8b62012007-08-02 11:10:09 -040052 "(%d):0311 Mailbox command x%x cannot " \
James Smart92d7f7b2007-06-17 19:56:38 -050053 "issue Data: x%x x%x x%x\n", \
James Smart92d7f7b2007-06-17 19:56:38 -050054 pmbox->vport ? pmbox->vport->vpi : 0, \
55 pmbox->mb.mbxCommand, \
James Smart2e0fef82007-06-17 19:56:36 -050056 phba->pport->port_state, \
dea31012005-04-17 16:05:31 -050057 psli->sli_flag, \
James Smart2e0fef82007-06-17 19:56:36 -050058 flag)
dea31012005-04-17 16:05:31 -050059
60
61/* There are only four IOCB completion types. */
62typedef enum _lpfc_iocb_type {
63 LPFC_UNKNOWN_IOCB,
64 LPFC_UNSOL_IOCB,
65 LPFC_SOL_IOCB,
66 LPFC_ABORT_IOCB
67} lpfc_iocb_type;
68
James Smart92d7f7b2007-06-17 19:56:38 -050069 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
70 * to the start of the ring, and the slot number of the
71 * desired iocb entry, calc a pointer to that entry.
72 */
James Smarted957682007-06-17 19:56:37 -050073static inline IOCB_t *
74lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
75{
76 return (IOCB_t *) (((char *) pring->cmdringaddr) +
77 pring->cmdidx * phba->iocb_cmd_size);
78}
79
80static inline IOCB_t *
81lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
82{
83 return (IOCB_t *) (((char *) pring->rspringaddr) +
84 pring->rspidx * phba->iocb_rsp_size);
85}
86
James Smart2e0fef82007-06-17 19:56:36 -050087static struct lpfc_iocbq *
88__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040089{
90 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
91 struct lpfc_iocbq * iocbq = NULL;
92
93 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
94 return iocbq;
95}
96
James Smart2e0fef82007-06-17 19:56:36 -050097struct lpfc_iocbq *
98lpfc_sli_get_iocbq(struct lpfc_hba *phba)
James Bottomley604a3e32005-10-29 10:28:33 -050099{
James Smart2e0fef82007-06-17 19:56:36 -0500100 struct lpfc_iocbq * iocbq = NULL;
101 unsigned long iflags;
102
103 spin_lock_irqsave(&phba->hbalock, iflags);
104 iocbq = __lpfc_sli_get_iocbq(phba);
105 spin_unlock_irqrestore(&phba->hbalock, iflags);
106 return iocbq;
107}
108
109void
110__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
111{
112 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
James Bottomley604a3e32005-10-29 10:28:33 -0500113
114 /*
115 * Clean all volatile data fields, preserve iotag and node struct.
116 */
117 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
118 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
119}
120
James Smart2e0fef82007-06-17 19:56:36 -0500121void
122lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
123{
124 unsigned long iflags;
125
126 /*
127 * Clean all volatile data fields, preserve iotag and node struct.
128 */
129 spin_lock_irqsave(&phba->hbalock, iflags);
130 __lpfc_sli_release_iocbq(phba, iocbq);
131 spin_unlock_irqrestore(&phba->hbalock, iflags);
132}
133
dea31012005-04-17 16:05:31 -0500134/*
135 * Translate the iocb command to an iocb command type used to decide the final
136 * disposition of each completed IOCB.
137 */
138static lpfc_iocb_type
139lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
140{
141 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
142
143 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
144 return 0;
145
146 switch (iocb_cmnd) {
147 case CMD_XMIT_SEQUENCE_CR:
148 case CMD_XMIT_SEQUENCE_CX:
149 case CMD_XMIT_BCAST_CN:
150 case CMD_XMIT_BCAST_CX:
151 case CMD_ELS_REQUEST_CR:
152 case CMD_ELS_REQUEST_CX:
153 case CMD_CREATE_XRI_CR:
154 case CMD_CREATE_XRI_CX:
155 case CMD_GET_RPI_CN:
156 case CMD_XMIT_ELS_RSP_CX:
157 case CMD_GET_RPI_CR:
158 case CMD_FCP_IWRITE_CR:
159 case CMD_FCP_IWRITE_CX:
160 case CMD_FCP_IREAD_CR:
161 case CMD_FCP_IREAD_CX:
162 case CMD_FCP_ICMND_CR:
163 case CMD_FCP_ICMND_CX:
James Smartf5603512006-12-02 13:35:43 -0500164 case CMD_FCP_TSEND_CX:
165 case CMD_FCP_TRSP_CX:
166 case CMD_FCP_TRECEIVE_CX:
167 case CMD_FCP_AUTO_TRSP_CX:
dea31012005-04-17 16:05:31 -0500168 case CMD_ADAPTER_MSG:
169 case CMD_ADAPTER_DUMP:
170 case CMD_XMIT_SEQUENCE64_CR:
171 case CMD_XMIT_SEQUENCE64_CX:
172 case CMD_XMIT_BCAST64_CN:
173 case CMD_XMIT_BCAST64_CX:
174 case CMD_ELS_REQUEST64_CR:
175 case CMD_ELS_REQUEST64_CX:
176 case CMD_FCP_IWRITE64_CR:
177 case CMD_FCP_IWRITE64_CX:
178 case CMD_FCP_IREAD64_CR:
179 case CMD_FCP_IREAD64_CX:
180 case CMD_FCP_ICMND64_CR:
181 case CMD_FCP_ICMND64_CX:
James Smartf5603512006-12-02 13:35:43 -0500182 case CMD_FCP_TSEND64_CX:
183 case CMD_FCP_TRSP64_CX:
184 case CMD_FCP_TRECEIVE64_CX:
dea31012005-04-17 16:05:31 -0500185 case CMD_GEN_REQUEST64_CR:
186 case CMD_GEN_REQUEST64_CX:
187 case CMD_XMIT_ELS_RSP64_CX:
188 type = LPFC_SOL_IOCB;
189 break;
190 case CMD_ABORT_XRI_CN:
191 case CMD_ABORT_XRI_CX:
192 case CMD_CLOSE_XRI_CN:
193 case CMD_CLOSE_XRI_CX:
194 case CMD_XRI_ABORTED_CX:
195 case CMD_ABORT_MXRI64_CN:
196 type = LPFC_ABORT_IOCB;
197 break;
198 case CMD_RCV_SEQUENCE_CX:
199 case CMD_RCV_ELS_REQ_CX:
200 case CMD_RCV_SEQUENCE64_CX:
201 case CMD_RCV_ELS_REQ64_CX:
James Smart57127f12007-10-27 13:37:05 -0400202 case CMD_ASYNC_STATUS:
James Smarted957682007-06-17 19:56:37 -0500203 case CMD_IOCB_RCV_SEQ64_CX:
204 case CMD_IOCB_RCV_ELS64_CX:
205 case CMD_IOCB_RCV_CONT64_CX:
dea31012005-04-17 16:05:31 -0500206 type = LPFC_UNSOL_IOCB;
207 break;
208 default:
209 type = LPFC_UNKNOWN_IOCB;
210 break;
211 }
212
213 return type;
214}
215
216static int
James Smarted957682007-06-17 19:56:37 -0500217lpfc_sli_ring_map(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500218{
219 struct lpfc_sli *psli = &phba->sli;
James Smarted957682007-06-17 19:56:37 -0500220 LPFC_MBOXQ_t *pmb;
221 MAILBOX_t *pmbox;
222 int i, rc, ret = 0;
dea31012005-04-17 16:05:31 -0500223
James Smarted957682007-06-17 19:56:37 -0500224 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
225 if (!pmb)
226 return -ENOMEM;
227 pmbox = &pmb->mb;
228 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500229 for (i = 0; i < psli->num_rings; i++) {
dea31012005-04-17 16:05:31 -0500230 lpfc_config_ring(phba, i, pmb);
231 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
232 if (rc != MBX_SUCCESS) {
James Smart92d7f7b2007-06-17 19:56:38 -0500233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400234 "0446 Adapter failed to init (%d), "
dea31012005-04-17 16:05:31 -0500235 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
236 "ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -0400237 rc, pmbox->mbxCommand,
238 pmbox->mbxStatus, i);
James Smart2e0fef82007-06-17 19:56:36 -0500239 phba->link_state = LPFC_HBA_ERROR;
James Smarted957682007-06-17 19:56:37 -0500240 ret = -ENXIO;
241 break;
dea31012005-04-17 16:05:31 -0500242 }
243 }
James Smarted957682007-06-17 19:56:37 -0500244 mempool_free(pmb, phba->mbox_mem_pool);
245 return ret;
dea31012005-04-17 16:05:31 -0500246}
247
248static int
James Smart2e0fef82007-06-17 19:56:36 -0500249lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
250 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -0500251{
dea31012005-04-17 16:05:31 -0500252 list_add_tail(&piocb->list, &pring->txcmplq);
253 pring->txcmplq_cnt++;
James Smart92d7f7b2007-06-17 19:56:38 -0500254 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
255 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
256 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
257 if (!piocb->vport)
258 BUG();
259 else
260 mod_timer(&piocb->vport->els_tmofunc,
261 jiffies + HZ * (phba->fc_ratov << 1));
262 }
263
dea31012005-04-17 16:05:31 -0500264
James Smart2e0fef82007-06-17 19:56:36 -0500265 return 0;
dea31012005-04-17 16:05:31 -0500266}
267
268static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500269lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500270{
dea31012005-04-17 16:05:31 -0500271 struct lpfc_iocbq *cmd_iocb;
272
James Smart858c9f62007-06-17 19:56:39 -0500273 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
274 if (cmd_iocb != NULL)
dea31012005-04-17 16:05:31 -0500275 pring->txq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -0500276 return cmd_iocb;
dea31012005-04-17 16:05:31 -0500277}
278
279static IOCB_t *
280lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
281{
James Smarted957682007-06-17 19:56:37 -0500282 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
283 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
284 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -0500285 uint32_t max_cmd_idx = pring->numCiocb;
dea31012005-04-17 16:05:31 -0500286
287 if ((pring->next_cmdidx == pring->cmdidx) &&
288 (++pring->next_cmdidx >= max_cmd_idx))
289 pring->next_cmdidx = 0;
290
291 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
292
293 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
294
295 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
296 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400297 "0315 Ring %d issue: portCmdGet %d "
dea31012005-04-17 16:05:31 -0500298 "is bigger then cmd ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -0400299 pring->ringno,
dea31012005-04-17 16:05:31 -0500300 pring->local_getidx, max_cmd_idx);
301
James Smart2e0fef82007-06-17 19:56:36 -0500302 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500303 /*
304 * All error attention handlers are posted to
305 * worker thread
306 */
307 phba->work_ha |= HA_ERATT;
308 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -0500309
310 /* hbalock should already be held */
dea31012005-04-17 16:05:31 -0500311 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -0500312 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -0500313
314 return NULL;
315 }
316
317 if (pring->local_getidx == pring->next_cmdidx)
318 return NULL;
319 }
320
James Smarted957682007-06-17 19:56:37 -0500321 return lpfc_cmd_iocb(phba, pring);
dea31012005-04-17 16:05:31 -0500322}
323
James Bottomley604a3e32005-10-29 10:28:33 -0500324uint16_t
James Smart2e0fef82007-06-17 19:56:36 -0500325lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
dea31012005-04-17 16:05:31 -0500326{
James Smart2e0fef82007-06-17 19:56:36 -0500327 struct lpfc_iocbq **new_arr;
328 struct lpfc_iocbq **old_arr;
James Bottomley604a3e32005-10-29 10:28:33 -0500329 size_t new_len;
330 struct lpfc_sli *psli = &phba->sli;
331 uint16_t iotag;
dea31012005-04-17 16:05:31 -0500332
James Smart2e0fef82007-06-17 19:56:36 -0500333 spin_lock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500334 iotag = psli->last_iotag;
335 if(++iotag < psli->iocbq_lookup_len) {
336 psli->last_iotag = iotag;
337 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -0500338 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500339 iocbq->iotag = iotag;
340 return iotag;
James Smart2e0fef82007-06-17 19:56:36 -0500341 } else if (psli->iocbq_lookup_len < (0xffff
James Bottomley604a3e32005-10-29 10:28:33 -0500342 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
343 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
James Smart2e0fef82007-06-17 19:56:36 -0500344 spin_unlock_irq(&phba->hbalock);
345 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
James Bottomley604a3e32005-10-29 10:28:33 -0500346 GFP_KERNEL);
347 if (new_arr) {
James Smart2e0fef82007-06-17 19:56:36 -0500348 spin_lock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500349 old_arr = psli->iocbq_lookup;
350 if (new_len <= psli->iocbq_lookup_len) {
351 /* highly unprobable case */
352 kfree(new_arr);
353 iotag = psli->last_iotag;
354 if(++iotag < psli->iocbq_lookup_len) {
355 psli->last_iotag = iotag;
356 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -0500357 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500358 iocbq->iotag = iotag;
359 return iotag;
360 }
James Smart2e0fef82007-06-17 19:56:36 -0500361 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500362 return 0;
363 }
364 if (psli->iocbq_lookup)
365 memcpy(new_arr, old_arr,
366 ((psli->last_iotag + 1) *
James Smart311464e2007-08-02 11:10:37 -0400367 sizeof (struct lpfc_iocbq *)));
James Bottomley604a3e32005-10-29 10:28:33 -0500368 psli->iocbq_lookup = new_arr;
369 psli->iocbq_lookup_len = new_len;
370 psli->last_iotag = iotag;
371 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -0500372 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500373 iocbq->iotag = iotag;
374 kfree(old_arr);
375 return iotag;
376 }
James Smart8f6d98d2006-08-01 07:34:00 -0400377 } else
James Smart2e0fef82007-06-17 19:56:36 -0500378 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500379
James Bottomley604a3e32005-10-29 10:28:33 -0500380 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400381 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
382 psli->last_iotag);
dea31012005-04-17 16:05:31 -0500383
James Bottomley604a3e32005-10-29 10:28:33 -0500384 return 0;
dea31012005-04-17 16:05:31 -0500385}
386
387static void
388lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
389 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
390{
391 /*
James Bottomley604a3e32005-10-29 10:28:33 -0500392 * Set up an iotag
dea31012005-04-17 16:05:31 -0500393 */
James Bottomley604a3e32005-10-29 10:28:33 -0500394 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
dea31012005-04-17 16:05:31 -0500395
James Smarta58cbd52007-08-02 11:09:43 -0400396 if (pring->ringno == LPFC_ELS_RING) {
397 lpfc_debugfs_slow_ring_trc(phba,
398 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
399 *(((uint32_t *) &nextiocb->iocb) + 4),
400 *(((uint32_t *) &nextiocb->iocb) + 6),
401 *(((uint32_t *) &nextiocb->iocb) + 7));
402 }
403
dea31012005-04-17 16:05:31 -0500404 /*
405 * Issue iocb command to adapter
406 */
James Smart92d7f7b2007-06-17 19:56:38 -0500407 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
dea31012005-04-17 16:05:31 -0500408 wmb();
409 pring->stats.iocb_cmd++;
410
411 /*
412 * If there is no completion routine to call, we can release the
413 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
414 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
415 */
416 if (nextiocb->iocb_cmpl)
417 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
James Bottomley604a3e32005-10-29 10:28:33 -0500418 else
James Smart2e0fef82007-06-17 19:56:36 -0500419 __lpfc_sli_release_iocbq(phba, nextiocb);
dea31012005-04-17 16:05:31 -0500420
421 /*
422 * Let the HBA know what IOCB slot will be the next one the
423 * driver will put a command into.
424 */
425 pring->cmdidx = pring->next_cmdidx;
James Smarted957682007-06-17 19:56:37 -0500426 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
dea31012005-04-17 16:05:31 -0500427}
428
429static void
James Smart2e0fef82007-06-17 19:56:36 -0500430lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500431{
432 int ringno = pring->ringno;
433
434 pring->flag |= LPFC_CALL_RING_AVAILABLE;
435
436 wmb();
437
438 /*
439 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
440 * The HBA will tell us when an IOCB entry is available.
441 */
442 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
443 readl(phba->CAregaddr); /* flush */
444
445 pring->stats.iocb_cmd_full++;
446}
447
448static void
James Smart2e0fef82007-06-17 19:56:36 -0500449lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500450{
451 int ringno = pring->ringno;
452
453 /*
454 * Tell the HBA that there is work to do in this ring.
455 */
456 wmb();
457 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
458 readl(phba->CAregaddr); /* flush */
459}
460
461static void
James Smart2e0fef82007-06-17 19:56:36 -0500462lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500463{
464 IOCB_t *iocb;
465 struct lpfc_iocbq *nextiocb;
466
467 /*
468 * Check to see if:
469 * (a) there is anything on the txq to send
470 * (b) link is up
471 * (c) link attention events can be processed (fcp ring only)
472 * (d) IOCB processing is not blocked by the outstanding mbox command.
473 */
474 if (pring->txq_cnt &&
James Smart2e0fef82007-06-17 19:56:36 -0500475 lpfc_is_link_up(phba) &&
dea31012005-04-17 16:05:31 -0500476 (pring->ringno != phba->sli.fcp_ring ||
477 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
478 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
479
480 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
481 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
482 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
483
484 if (iocb)
485 lpfc_sli_update_ring(phba, pring);
486 else
487 lpfc_sli_update_full_ring(phba, pring);
488 }
489
490 return;
491}
492
493/* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
494static void
James Smart2e0fef82007-06-17 19:56:36 -0500495lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
dea31012005-04-17 16:05:31 -0500496{
James Smarted957682007-06-17 19:56:37 -0500497 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
498 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
499 &phba->slim2p->mbx.us.s2.port[ringno];
James Smart2e0fef82007-06-17 19:56:36 -0500500 unsigned long iflags;
dea31012005-04-17 16:05:31 -0500501
502 /* If the ring is active, flag it */
James Smart2e0fef82007-06-17 19:56:36 -0500503 spin_lock_irqsave(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -0500504 if (phba->sli.ring[ringno].cmdringaddr) {
505 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
506 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
507 /*
508 * Force update of the local copy of cmdGetInx
509 */
510 phba->sli.ring[ringno].local_getidx
511 = le32_to_cpu(pgp->cmdGetInx);
dea31012005-04-17 16:05:31 -0500512 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
dea31012005-04-17 16:05:31 -0500513 }
514 }
James Smart2e0fef82007-06-17 19:56:36 -0500515 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -0500516}
517
James Smarted957682007-06-17 19:56:37 -0500518struct lpfc_hbq_entry *
519lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
520{
521 struct hbq_s *hbqp = &phba->hbqs[hbqno];
522
523 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
524 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
525 hbqp->next_hbqPutIdx = 0;
526
527 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500528 uint32_t raw_index = phba->hbq_get[hbqno];
James Smarted957682007-06-17 19:56:37 -0500529 uint32_t getidx = le32_to_cpu(raw_index);
530
531 hbqp->local_hbqGetIdx = getidx;
532
533 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
534 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -0500535 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400536 "1802 HBQ %d: local_hbqGetIdx "
James Smarted957682007-06-17 19:56:37 -0500537 "%u is > than hbqp->entry_count %u\n",
James Smarte8b62012007-08-02 11:10:09 -0400538 hbqno, hbqp->local_hbqGetIdx,
James Smarted957682007-06-17 19:56:37 -0500539 hbqp->entry_count);
540
541 phba->link_state = LPFC_HBA_ERROR;
542 return NULL;
543 }
544
545 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
546 return NULL;
547 }
548
James Smart51ef4c22007-08-02 11:10:31 -0400549 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
550 hbqp->hbqPutIdx;
James Smarted957682007-06-17 19:56:37 -0500551}
552
553void
554lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
555{
James Smart92d7f7b2007-06-17 19:56:38 -0500556 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
557 struct hbq_dmabuf *hbq_buf;
James Smart51ef4c22007-08-02 11:10:31 -0400558 int i, hbq_count;
James Smarted957682007-06-17 19:56:37 -0500559
James Smart51ef4c22007-08-02 11:10:31 -0400560 hbq_count = lpfc_sli_hbq_count();
James Smarted957682007-06-17 19:56:37 -0500561 /* Return all memory used by all HBQs */
James Smart51ef4c22007-08-02 11:10:31 -0400562 for (i = 0; i < hbq_count; ++i) {
563 list_for_each_entry_safe(dmabuf, next_dmabuf,
564 &phba->hbqs[i].hbq_buffer_list, list) {
565 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
566 list_del(&hbq_buf->dbuf.list);
567 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
568 }
James Smarted957682007-06-17 19:56:37 -0500569 }
James Smarted957682007-06-17 19:56:37 -0500570}
571
James Smart51ef4c22007-08-02 11:10:31 -0400572static struct lpfc_hbq_entry *
James Smarted957682007-06-17 19:56:37 -0500573lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
James Smart92d7f7b2007-06-17 19:56:38 -0500574 struct hbq_dmabuf *hbq_buf)
James Smarted957682007-06-17 19:56:37 -0500575{
576 struct lpfc_hbq_entry *hbqe;
James Smart92d7f7b2007-06-17 19:56:38 -0500577 dma_addr_t physaddr = hbq_buf->dbuf.phys;
James Smarted957682007-06-17 19:56:37 -0500578
579 /* Get next HBQ entry slot to use */
580 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
581 if (hbqe) {
582 struct hbq_s *hbqp = &phba->hbqs[hbqno];
583
James Smart92d7f7b2007-06-17 19:56:38 -0500584 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
585 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
James Smart51ef4c22007-08-02 11:10:31 -0400586 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
James Smarted957682007-06-17 19:56:37 -0500587 hbqe->bde.tus.f.bdeFlags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500588 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
589 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
590 /* Sync SLIM */
James Smarted957682007-06-17 19:56:37 -0500591 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
592 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 /* flush */
James Smarted957682007-06-17 19:56:37 -0500594 readl(phba->hbq_put + hbqno);
James Smart51ef4c22007-08-02 11:10:31 -0400595 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
James Smarted957682007-06-17 19:56:37 -0500596 }
James Smart51ef4c22007-08-02 11:10:31 -0400597 return hbqe;
James Smarted957682007-06-17 19:56:37 -0500598}
599
James Smart92d7f7b2007-06-17 19:56:38 -0500600static struct lpfc_hbq_init lpfc_els_hbq = {
601 .rn = 1,
602 .entry_count = 200,
603 .mask_count = 0,
604 .profile = 0,
James Smart51ef4c22007-08-02 11:10:31 -0400605 .ring_mask = (1 << LPFC_ELS_RING),
James Smart92d7f7b2007-06-17 19:56:38 -0500606 .buffer_count = 0,
607 .init_count = 20,
608 .add_count = 5,
609};
James Smarted957682007-06-17 19:56:37 -0500610
James Smart51ef4c22007-08-02 11:10:31 -0400611static struct lpfc_hbq_init lpfc_extra_hbq = {
612 .rn = 1,
613 .entry_count = 200,
614 .mask_count = 0,
615 .profile = 0,
616 .ring_mask = (1 << LPFC_EXTRA_RING),
617 .buffer_count = 0,
618 .init_count = 0,
619 .add_count = 5,
620};
621
James Smart78b2d852007-08-02 11:10:21 -0400622struct lpfc_hbq_init *lpfc_hbq_defs[] = {
James Smart92d7f7b2007-06-17 19:56:38 -0500623 &lpfc_els_hbq,
James Smart51ef4c22007-08-02 11:10:31 -0400624 &lpfc_extra_hbq,
James Smart92d7f7b2007-06-17 19:56:38 -0500625};
626
James Smart311464e2007-08-02 11:10:37 -0400627static int
James Smart92d7f7b2007-06-17 19:56:38 -0500628lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
629{
630 uint32_t i, start, end;
631 struct hbq_dmabuf *hbq_buffer;
632
James Smart51ef4c22007-08-02 11:10:31 -0400633 if (!phba->hbqs[hbqno].hbq_alloc_buffer) {
634 return 0;
635 }
636
James Smart92d7f7b2007-06-17 19:56:38 -0500637 start = lpfc_hbq_defs[hbqno]->buffer_count;
638 end = count + lpfc_hbq_defs[hbqno]->buffer_count;
639 if (end > lpfc_hbq_defs[hbqno]->entry_count) {
640 end = lpfc_hbq_defs[hbqno]->entry_count;
James Smarted957682007-06-17 19:56:37 -0500641 }
James Smart92d7f7b2007-06-17 19:56:38 -0500642
643 /* Populate HBQ entries */
644 for (i = start; i < end; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400645 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500646 if (!hbq_buffer)
647 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500648 hbq_buffer->tag = (i | (hbqno << 16));
James Smart51ef4c22007-08-02 11:10:31 -0400649 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
650 lpfc_hbq_defs[hbqno]->buffer_count++;
651 else
652 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
James Smart92d7f7b2007-06-17 19:56:38 -0500653 }
654 return 0;
James Smarted957682007-06-17 19:56:37 -0500655}
656
657int
James Smart92d7f7b2007-06-17 19:56:38 -0500658lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -0500659{
James Smart92d7f7b2007-06-17 19:56:38 -0500660 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
661 lpfc_hbq_defs[qno]->add_count));
James Smarted957682007-06-17 19:56:37 -0500662}
663
James Smart92d7f7b2007-06-17 19:56:38 -0500664int
665lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -0500666{
James Smart92d7f7b2007-06-17 19:56:38 -0500667 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
668 lpfc_hbq_defs[qno]->init_count));
James Smarted957682007-06-17 19:56:37 -0500669}
670
671struct hbq_dmabuf *
672lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
673{
James Smart92d7f7b2007-06-17 19:56:38 -0500674 struct lpfc_dmabuf *d_buf;
675 struct hbq_dmabuf *hbq_buf;
James Smart51ef4c22007-08-02 11:10:31 -0400676 uint32_t hbqno;
James Smarted957682007-06-17 19:56:37 -0500677
James Smart51ef4c22007-08-02 11:10:31 -0400678 hbqno = tag >> 16;
Jesper Juhla0a74e452007-08-09 20:47:15 +0200679 if (hbqno >= LPFC_MAX_HBQS)
James Smart51ef4c22007-08-02 11:10:31 -0400680 return NULL;
681
682 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
James Smart92d7f7b2007-06-17 19:56:38 -0500683 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
James Smart51ef4c22007-08-02 11:10:31 -0400684 if (hbq_buf->tag == tag) {
James Smart92d7f7b2007-06-17 19:56:38 -0500685 return hbq_buf;
James Smarted957682007-06-17 19:56:37 -0500686 }
687 }
James Smart92d7f7b2007-06-17 19:56:38 -0500688 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400689 "1803 Bad hbq tag. Data: x%x x%x\n",
690 tag, lpfc_hbq_defs[tag >> 16]->buffer_count);
James Smart92d7f7b2007-06-17 19:56:38 -0500691 return NULL;
James Smarted957682007-06-17 19:56:37 -0500692}
693
694void
James Smart51ef4c22007-08-02 11:10:31 -0400695lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
James Smarted957682007-06-17 19:56:37 -0500696{
697 uint32_t hbqno;
698
James Smart51ef4c22007-08-02 11:10:31 -0400699 if (hbq_buffer) {
700 hbqno = hbq_buffer->tag >> 16;
701 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
702 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
703 }
James Smarted957682007-06-17 19:56:37 -0500704 }
705}
706
dea31012005-04-17 16:05:31 -0500707static int
708lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
709{
710 uint8_t ret;
711
712 switch (mbxCommand) {
713 case MBX_LOAD_SM:
714 case MBX_READ_NV:
715 case MBX_WRITE_NV:
716 case MBX_RUN_BIU_DIAG:
717 case MBX_INIT_LINK:
718 case MBX_DOWN_LINK:
719 case MBX_CONFIG_LINK:
720 case MBX_CONFIG_RING:
721 case MBX_RESET_RING:
722 case MBX_READ_CONFIG:
723 case MBX_READ_RCONFIG:
724 case MBX_READ_SPARM:
725 case MBX_READ_STATUS:
726 case MBX_READ_RPI:
727 case MBX_READ_XRI:
728 case MBX_READ_REV:
729 case MBX_READ_LNK_STAT:
730 case MBX_REG_LOGIN:
731 case MBX_UNREG_LOGIN:
732 case MBX_READ_LA:
733 case MBX_CLEAR_LA:
734 case MBX_DUMP_MEMORY:
735 case MBX_DUMP_CONTEXT:
736 case MBX_RUN_DIAGS:
737 case MBX_RESTART:
738 case MBX_UPDATE_CFG:
739 case MBX_DOWN_LOAD:
740 case MBX_DEL_LD_ENTRY:
741 case MBX_RUN_PROGRAM:
742 case MBX_SET_MASK:
743 case MBX_SET_SLIM:
744 case MBX_UNREG_D_ID:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500745 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -0500746 case MBX_CONFIG_FARP:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500747 case MBX_BEACON:
dea31012005-04-17 16:05:31 -0500748 case MBX_LOAD_AREA:
749 case MBX_RUN_BIU_DIAG64:
750 case MBX_CONFIG_PORT:
751 case MBX_READ_SPARM64:
752 case MBX_READ_RPI64:
753 case MBX_REG_LOGIN64:
754 case MBX_READ_LA64:
755 case MBX_FLASH_WR_ULA:
756 case MBX_SET_DEBUG:
757 case MBX_LOAD_EXP_ROM:
James Smart57127f12007-10-27 13:37:05 -0400758 case MBX_ASYNCEVT_ENABLE:
James Smart92d7f7b2007-06-17 19:56:38 -0500759 case MBX_REG_VPI:
760 case MBX_UNREG_VPI:
James Smart858c9f62007-06-17 19:56:39 -0500761 case MBX_HEARTBEAT:
dea31012005-04-17 16:05:31 -0500762 ret = mbxCommand;
763 break;
764 default:
765 ret = MBX_SHUTDOWN;
766 break;
767 }
James Smart2e0fef82007-06-17 19:56:36 -0500768 return ret;
dea31012005-04-17 16:05:31 -0500769}
770static void
James Smart2e0fef82007-06-17 19:56:36 -0500771lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
dea31012005-04-17 16:05:31 -0500772{
773 wait_queue_head_t *pdone_q;
James Smart858c9f62007-06-17 19:56:39 -0500774 unsigned long drvr_flag;
dea31012005-04-17 16:05:31 -0500775
776 /*
777 * If pdone_q is empty, the driver thread gave up waiting and
778 * continued running.
779 */
James Smart7054a602007-04-25 09:52:34 -0400780 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
James Smart858c9f62007-06-17 19:56:39 -0500781 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -0500782 pdone_q = (wait_queue_head_t *) pmboxq->context1;
783 if (pdone_q)
784 wake_up_interruptible(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -0500785 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -0500786 return;
787}
788
789void
James Smart2e0fef82007-06-17 19:56:36 -0500790lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500791{
792 struct lpfc_dmabuf *mp;
James Smart7054a602007-04-25 09:52:34 -0400793 uint16_t rpi;
794 int rc;
795
dea31012005-04-17 16:05:31 -0500796 mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart7054a602007-04-25 09:52:34 -0400797
dea31012005-04-17 16:05:31 -0500798 if (mp) {
799 lpfc_mbuf_free(phba, mp->virt, mp->phys);
800 kfree(mp);
801 }
James Smart7054a602007-04-25 09:52:34 -0400802
803 /*
804 * If a REG_LOGIN succeeded after node is destroyed or node
805 * is in re-discovery driver need to cleanup the RPI.
806 */
James Smart2e0fef82007-06-17 19:56:36 -0500807 if (!(phba->pport->load_flag & FC_UNLOADING) &&
808 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
809 !pmb->mb.mbxStatus) {
James Smart7054a602007-04-25 09:52:34 -0400810
811 rpi = pmb->mb.un.varWords[0];
James Smart92d7f7b2007-06-17 19:56:38 -0500812 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
813 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart7054a602007-04-25 09:52:34 -0400814 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
815 if (rc != MBX_NOT_FINISHED)
816 return;
817 }
818
James Smart2e0fef82007-06-17 19:56:36 -0500819 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500820 return;
821}
822
823int
James Smart2e0fef82007-06-17 19:56:36 -0500824lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500825{
James Smart92d7f7b2007-06-17 19:56:38 -0500826 MAILBOX_t *pmbox;
dea31012005-04-17 16:05:31 -0500827 LPFC_MBOXQ_t *pmb;
James Smart92d7f7b2007-06-17 19:56:38 -0500828 int rc;
829 LIST_HEAD(cmplq);
dea31012005-04-17 16:05:31 -0500830
831 phba->sli.slistat.mbox_event++;
832
James Smart92d7f7b2007-06-17 19:56:38 -0500833 /* Get all completed mailboxe buffers into the cmplq */
834 spin_lock_irq(&phba->hbalock);
835 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
836 spin_unlock_irq(&phba->hbalock);
837
dea31012005-04-17 16:05:31 -0500838 /* Get a Mailbox buffer to setup mailbox commands for callback */
James Smart92d7f7b2007-06-17 19:56:38 -0500839 do {
840 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
841 if (pmb == NULL)
842 break;
843
dea31012005-04-17 16:05:31 -0500844 pmbox = &pmb->mb;
dea31012005-04-17 16:05:31 -0500845
James Smart858c9f62007-06-17 19:56:39 -0500846 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
847 if (pmb->vport) {
848 lpfc_debugfs_disc_trc(pmb->vport,
849 LPFC_DISC_TRC_MBOX_VPORT,
850 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
851 (uint32_t)pmbox->mbxCommand,
852 pmbox->un.varWords[0],
853 pmbox->un.varWords[1]);
854 }
855 else {
856 lpfc_debugfs_disc_trc(phba->pport,
857 LPFC_DISC_TRC_MBOX,
858 "MBOX cmpl: cmd:x%x mb:x%x x%x",
859 (uint32_t)pmbox->mbxCommand,
860 pmbox->un.varWords[0],
861 pmbox->un.varWords[1]);
862 }
863 }
864
dea31012005-04-17 16:05:31 -0500865 /*
866 * It is a fatal error if unknown mbox command completion.
867 */
868 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
869 MBX_SHUTDOWN) {
dea31012005-04-17 16:05:31 -0500870 /* Unknow mailbox command compl */
James Smart92d7f7b2007-06-17 19:56:38 -0500871 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400872 "(%d):0323 Unknown Mailbox command "
James Smart92d7f7b2007-06-17 19:56:38 -0500873 "%x Cmpl\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500874 pmb->vport ? pmb->vport->vpi : 0,
875 pmbox->mbxCommand);
James Smart2e0fef82007-06-17 19:56:36 -0500876 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500877 phba->work_hs = HS_FFER3;
878 lpfc_handle_eratt(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500879 continue;
dea31012005-04-17 16:05:31 -0500880 }
881
dea31012005-04-17 16:05:31 -0500882 if (pmbox->mbxStatus) {
883 phba->sli.slistat.mbox_stat_err++;
884 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
885 /* Mbox cmd cmpl error - RETRYing */
James Smart92d7f7b2007-06-17 19:56:38 -0500886 lpfc_printf_log(phba, KERN_INFO,
887 LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400888 "(%d):0305 Mbox cmd cmpl "
James Smart92d7f7b2007-06-17 19:56:38 -0500889 "error - RETRYing Data: x%x "
890 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500891 pmb->vport ? pmb->vport->vpi :0,
892 pmbox->mbxCommand,
893 pmbox->mbxStatus,
894 pmbox->un.varWords[0],
895 pmb->vport->port_state);
dea31012005-04-17 16:05:31 -0500896 pmbox->mbxStatus = 0;
897 pmbox->mbxOwner = OWN_HOST;
James Smart2e0fef82007-06-17 19:56:36 -0500898 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500899 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -0500900 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500901 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
902 if (rc == MBX_SUCCESS)
James Smart92d7f7b2007-06-17 19:56:38 -0500903 continue;
dea31012005-04-17 16:05:31 -0500904 }
905 }
906
907 /* Mailbox cmd <cmd> Cmpl <cmpl> */
James Smart92d7f7b2007-06-17 19:56:38 -0500908 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400909 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
dea31012005-04-17 16:05:31 -0500910 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500911 pmb->vport ? pmb->vport->vpi : 0,
dea31012005-04-17 16:05:31 -0500912 pmbox->mbxCommand,
913 pmb->mbox_cmpl,
914 *((uint32_t *) pmbox),
915 pmbox->un.varWords[0],
916 pmbox->un.varWords[1],
917 pmbox->un.varWords[2],
918 pmbox->un.varWords[3],
919 pmbox->un.varWords[4],
920 pmbox->un.varWords[5],
921 pmbox->un.varWords[6],
922 pmbox->un.varWords[7]);
923
James Smart92d7f7b2007-06-17 19:56:38 -0500924 if (pmb->mbox_cmpl)
dea31012005-04-17 16:05:31 -0500925 pmb->mbox_cmpl(phba,pmb);
James Smart92d7f7b2007-06-17 19:56:38 -0500926 } while (1);
James Smart2e0fef82007-06-17 19:56:36 -0500927 return 0;
dea31012005-04-17 16:05:31 -0500928}
James Smart92d7f7b2007-06-17 19:56:38 -0500929
930static struct lpfc_dmabuf *
931lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
932{
933 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
James Smart51ef4c22007-08-02 11:10:31 -0400934 uint32_t hbqno;
935 void *virt; /* virtual address ptr */
936 dma_addr_t phys; /* mapped address */
James Smart92d7f7b2007-06-17 19:56:38 -0500937
938 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
939 if (hbq_entry == NULL)
940 return NULL;
941 list_del(&hbq_entry->dbuf.list);
James Smart51ef4c22007-08-02 11:10:31 -0400942
943 hbqno = tag >> 16;
944 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500945 if (new_hbq_entry == NULL)
946 return &hbq_entry->dbuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500947 new_hbq_entry->tag = -1;
James Smart51ef4c22007-08-02 11:10:31 -0400948 phys = new_hbq_entry->dbuf.phys;
949 virt = new_hbq_entry->dbuf.virt;
950 new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
951 new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
952 hbq_entry->dbuf.phys = phys;
953 hbq_entry->dbuf.virt = virt;
James Smart92d7f7b2007-06-17 19:56:38 -0500954 lpfc_sli_free_hbq(phba, hbq_entry);
955 return &new_hbq_entry->dbuf;
956}
957
James Smart57127f12007-10-27 13:37:05 -0400958
dea31012005-04-17 16:05:31 -0500959static int
960lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
961 struct lpfc_iocbq *saveq)
962{
963 IOCB_t * irsp;
964 WORD5 * w5p;
965 uint32_t Rctl, Type;
966 uint32_t match, i;
967
968 match = 0;
969 irsp = &(saveq->iocb);
James Smart57127f12007-10-27 13:37:05 -0400970
971 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
972 if (pring->lpfc_sli_rcv_async_status)
973 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
974 else
975 lpfc_printf_log(phba,
976 KERN_WARNING,
977 LOG_SLI,
978 "0316 Ring %d handler: unexpected "
979 "ASYNC_STATUS iocb received evt_code "
980 "0x%x\n",
981 pring->ringno,
982 irsp->un.asyncstat.evt_code);
983 return 1;
984 }
985
dea31012005-04-17 16:05:31 -0500986 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
James Smarted957682007-06-17 19:56:37 -0500987 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
988 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
989 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
dea31012005-04-17 16:05:31 -0500990 Rctl = FC_ELS_REQ;
991 Type = FC_ELS_DATA;
992 } else {
993 w5p =
994 (WORD5 *) & (saveq->iocb.un.
995 ulpWord[5]);
996 Rctl = w5p->hcsw.Rctl;
997 Type = w5p->hcsw.Type;
998
999 /* Firmware Workaround */
1000 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001001 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
1002 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
dea31012005-04-17 16:05:31 -05001003 Rctl = FC_ELS_REQ;
1004 Type = FC_ELS_DATA;
1005 w5p->hcsw.Rctl = Rctl;
1006 w5p->hcsw.Type = Type;
1007 }
1008 }
James Smart92d7f7b2007-06-17 19:56:38 -05001009
1010 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1011 if (irsp->ulpBdeCount != 0)
1012 saveq->context2 = lpfc_sli_replace_hbqbuff(phba,
1013 irsp->un.ulpWord[3]);
1014 if (irsp->ulpBdeCount == 2)
1015 saveq->context3 = lpfc_sli_replace_hbqbuff(phba,
James Smart51ef4c22007-08-02 11:10:31 -04001016 irsp->unsli3.sli3Words[7]);
James Smart92d7f7b2007-06-17 19:56:38 -05001017 }
1018
dea31012005-04-17 16:05:31 -05001019 /* unSolicited Responses */
1020 if (pring->prt[0].profile) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001021 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1022 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1023 saveq);
dea31012005-04-17 16:05:31 -05001024 match = 1;
1025 } else {
1026 /* We must search, based on rctl / type
1027 for the right routine */
1028 for (i = 0; i < pring->num_mask;
1029 i++) {
1030 if ((pring->prt[i].rctl ==
1031 Rctl)
1032 && (pring->prt[i].
1033 type == Type)) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001034 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1035 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1036 (phba, pring, saveq);
dea31012005-04-17 16:05:31 -05001037 match = 1;
1038 break;
1039 }
1040 }
1041 }
1042 if (match == 0) {
1043 /* Unexpected Rctl / Type received */
1044 /* Ring <ringno> handler: unexpected
1045 Rctl <Rctl> Type <Type> received */
James Smart92d7f7b2007-06-17 19:56:38 -05001046 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001047 "0313 Ring %d handler: unexpected Rctl x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05001048 "Type x%x received\n",
James Smarte8b62012007-08-02 11:10:09 -04001049 pring->ringno, Rctl, Type);
dea31012005-04-17 16:05:31 -05001050 }
James Smart92d7f7b2007-06-17 19:56:38 -05001051 return 1;
dea31012005-04-17 16:05:31 -05001052}
1053
1054static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -05001055lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1056 struct lpfc_sli_ring *pring,
1057 struct lpfc_iocbq *prspiocb)
dea31012005-04-17 16:05:31 -05001058{
dea31012005-04-17 16:05:31 -05001059 struct lpfc_iocbq *cmd_iocb = NULL;
1060 uint16_t iotag;
1061
James Bottomley604a3e32005-10-29 10:28:33 -05001062 iotag = prspiocb->iocb.ulpIoTag;
dea31012005-04-17 16:05:31 -05001063
James Bottomley604a3e32005-10-29 10:28:33 -05001064 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1065 cmd_iocb = phba->sli.iocbq_lookup[iotag];
James Smart92d7f7b2007-06-17 19:56:38 -05001066 list_del_init(&cmd_iocb->list);
James Bottomley604a3e32005-10-29 10:28:33 -05001067 pring->txcmplq_cnt--;
1068 return cmd_iocb;
dea31012005-04-17 16:05:31 -05001069 }
1070
dea31012005-04-17 16:05:31 -05001071 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001072 "0317 iotag x%x is out off "
James Bottomley604a3e32005-10-29 10:28:33 -05001073 "range: max iotag x%x wd0 x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001074 iotag, phba->sli.last_iotag,
James Bottomley604a3e32005-10-29 10:28:33 -05001075 *(((uint32_t *) &prspiocb->iocb) + 7));
dea31012005-04-17 16:05:31 -05001076 return NULL;
1077}
1078
1079static int
James Smart2e0fef82007-06-17 19:56:36 -05001080lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05001081 struct lpfc_iocbq *saveq)
1082{
James Smart2e0fef82007-06-17 19:56:36 -05001083 struct lpfc_iocbq *cmdiocbp;
dea31012005-04-17 16:05:31 -05001084 int rc = 1;
1085 unsigned long iflag;
1086
1087 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
James Smart2e0fef82007-06-17 19:56:36 -05001088 spin_lock_irqsave(&phba->hbalock, iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001089 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
James Smart2e0fef82007-06-17 19:56:36 -05001090 spin_unlock_irqrestore(&phba->hbalock, iflag);
1091
dea31012005-04-17 16:05:31 -05001092 if (cmdiocbp) {
1093 if (cmdiocbp->iocb_cmpl) {
1094 /*
1095 * Post all ELS completions to the worker thread.
1096 * All other are passed to the completion callback.
1097 */
1098 if (pring->ringno == LPFC_ELS_RING) {
James Smart07951072007-04-25 09:51:38 -04001099 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1100 cmdiocbp->iocb_flag &=
1101 ~LPFC_DRIVER_ABORTED;
1102 saveq->iocb.ulpStatus =
1103 IOSTAT_LOCAL_REJECT;
1104 saveq->iocb.un.ulpWord[4] =
1105 IOERR_SLI_ABORTED;
1106 }
dea31012005-04-17 16:05:31 -05001107 }
James Smart2e0fef82007-06-17 19:56:36 -05001108 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
James Bottomley604a3e32005-10-29 10:28:33 -05001109 } else
1110 lpfc_sli_release_iocbq(phba, cmdiocbp);
dea31012005-04-17 16:05:31 -05001111 } else {
1112 /*
1113 * Unknown initiating command based on the response iotag.
1114 * This could be the case on the ELS ring because of
1115 * lpfc_els_abort().
1116 */
1117 if (pring->ringno != LPFC_ELS_RING) {
1118 /*
1119 * Ring <ringno> handler: unexpected completion IoTag
1120 * <IoTag>
1121 */
James Smarte8b62012007-08-02 11:10:09 -04001122 lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
1123 "0322 Ring %d handler: "
1124 "unexpected completion IoTag x%x "
1125 "Data: x%x x%x x%x x%x\n",
1126 pring->ringno,
1127 saveq->iocb.ulpIoTag,
1128 saveq->iocb.ulpStatus,
1129 saveq->iocb.un.ulpWord[4],
1130 saveq->iocb.ulpCommand,
1131 saveq->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05001132 }
1133 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04001134
dea31012005-04-17 16:05:31 -05001135 return rc;
1136}
1137
James Smart2e0fef82007-06-17 19:56:36 -05001138static void
1139lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001140{
James Smarted957682007-06-17 19:56:37 -05001141 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1142 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1143 &phba->slim2p->mbx.us.s2.port[pring->ringno];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001144 /*
1145 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1146 * rsp ring <portRspMax>
1147 */
1148 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001149 "0312 Ring %d handler: portRspPut %d "
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001150 "is bigger then rsp ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04001151 pring->ringno, le32_to_cpu(pgp->rspPutInx),
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001152 pring->numRiocb);
1153
James Smart2e0fef82007-06-17 19:56:36 -05001154 phba->link_state = LPFC_HBA_ERROR;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001155
1156 /*
1157 * All error attention handlers are posted to
1158 * worker thread
1159 */
1160 phba->work_ha |= HA_ERATT;
1161 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -05001162
1163 /* hbalock should already be held */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001164 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001165 lpfc_worker_wake_up(phba);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001166
1167 return;
1168}
1169
James Smart2e0fef82007-06-17 19:56:36 -05001170void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001171{
James Smart2e0fef82007-06-17 19:56:36 -05001172 struct lpfc_sli *psli = &phba->sli;
1173 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001174 IOCB_t *irsp = NULL;
1175 IOCB_t *entry = NULL;
1176 struct lpfc_iocbq *cmdiocbq = NULL;
1177 struct lpfc_iocbq rspiocbq;
1178 struct lpfc_pgp *pgp;
1179 uint32_t status;
1180 uint32_t portRspPut, portRspMax;
1181 int type;
1182 uint32_t rsp_cmpl = 0;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001183 uint32_t ha_copy;
James Smart2e0fef82007-06-17 19:56:36 -05001184 unsigned long iflags;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001185
1186 pring->stats.iocb_event++;
1187
James Smarted957682007-06-17 19:56:37 -05001188 pgp = (phba->sli_rev == 3) ?
1189 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1190 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1191
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001192
1193 /*
1194 * The next available response entry should never exceed the maximum
1195 * entries. If it does, treat it as an adapter hardware error.
1196 */
1197 portRspMax = pring->numRiocb;
1198 portRspPut = le32_to_cpu(pgp->rspPutInx);
1199 if (unlikely(portRspPut >= portRspMax)) {
1200 lpfc_sli_rsp_pointers_error(phba, pring);
1201 return;
1202 }
1203
1204 rmb();
1205 while (pring->rspidx != portRspPut) {
James Smarted957682007-06-17 19:56:37 -05001206 entry = lpfc_resp_iocb(phba, pring);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001207 if (++pring->rspidx >= portRspMax)
1208 pring->rspidx = 0;
1209
1210 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1211 (uint32_t *) &rspiocbq.iocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001212 phba->iocb_rsp_size);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001213 irsp = &rspiocbq.iocb;
1214 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1215 pring->stats.iocb_rsp++;
1216 rsp_cmpl++;
1217
1218 if (unlikely(irsp->ulpStatus)) {
1219 /* Rsp ring <ringno> error: IOCB */
1220 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001221 "0326 Rsp Ring %d error: IOCB Data: "
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001222 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001223 pring->ringno,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001224 irsp->un.ulpWord[0],
1225 irsp->un.ulpWord[1],
1226 irsp->un.ulpWord[2],
1227 irsp->un.ulpWord[3],
1228 irsp->un.ulpWord[4],
1229 irsp->un.ulpWord[5],
1230 *(((uint32_t *) irsp) + 6),
1231 *(((uint32_t *) irsp) + 7));
1232 }
1233
1234 switch (type) {
1235 case LPFC_ABORT_IOCB:
1236 case LPFC_SOL_IOCB:
1237 /*
1238 * Idle exchange closed via ABTS from port. No iocb
1239 * resources need to be recovered.
1240 */
1241 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001242 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001243 "0314 IOCB cmd 0x%x "
1244 "processed. Skipping "
1245 "completion",
James Smartdca94792006-08-01 07:34:08 -04001246 irsp->ulpCommand);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001247 break;
1248 }
1249
James Smart2e0fef82007-06-17 19:56:36 -05001250 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001251 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1252 &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001253 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001254 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1255 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1256 &rspiocbq);
1257 }
1258 break;
1259 default:
1260 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1261 char adaptermsg[LPFC_MAX_ADPTMSG];
1262 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1263 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1264 MAX_MSG_DATA);
Joe Perches898eb712007-10-18 03:06:30 -07001265 dev_warn(&((phba->pcidev)->dev),
1266 "lpfc%d: %s\n",
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001267 phba->brd_no, adaptermsg);
1268 } else {
1269 /* Unknown IOCB command */
1270 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001271 "0321 Unknown IOCB command "
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001272 "Data: x%x, x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001273 type, irsp->ulpCommand,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001274 irsp->ulpStatus,
1275 irsp->ulpIoTag,
1276 irsp->ulpContext);
1277 }
1278 break;
1279 }
1280
1281 /*
1282 * The response IOCB has been processed. Update the ring
1283 * pointer in SLIM. If the port response put pointer has not
1284 * been updated, sync the pgp->rspPutInx and fetch the new port
1285 * response put pointer.
1286 */
James Smarted957682007-06-17 19:56:37 -05001287 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001288
1289 if (pring->rspidx == portRspPut)
1290 portRspPut = le32_to_cpu(pgp->rspPutInx);
1291 }
1292
1293 ha_copy = readl(phba->HAregaddr);
1294 ha_copy >>= (LPFC_FCP_RING * 4);
1295
1296 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
James Smart2e0fef82007-06-17 19:56:36 -05001297 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001298 pring->stats.iocb_rsp_full++;
1299 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1300 writel(status, phba->CAregaddr);
1301 readl(phba->CAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001302 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001303 }
1304 if ((ha_copy & HA_R0CE_RSP) &&
1305 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001306 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001307 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1308 pring->stats.iocb_cmd_empty++;
1309
1310 /* Force update of the local copy of cmdGetInx */
1311 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1312 lpfc_sli_resume_iocb(phba, pring);
1313
1314 if ((pring->lpfc_sli_cmd_available))
1315 (pring->lpfc_sli_cmd_available) (phba, pring);
1316
James Smart2e0fef82007-06-17 19:56:36 -05001317 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001318 }
1319
1320 return;
1321}
1322
dea31012005-04-17 16:05:31 -05001323/*
1324 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1325 * to check it explicitly.
1326 */
1327static int
James Smart2e0fef82007-06-17 19:56:36 -05001328lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1329 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05001330{
James Smarted957682007-06-17 19:56:37 -05001331 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1332 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1333 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001334 IOCB_t *irsp = NULL;
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001335 IOCB_t *entry = NULL;
dea31012005-04-17 16:05:31 -05001336 struct lpfc_iocbq *cmdiocbq = NULL;
1337 struct lpfc_iocbq rspiocbq;
dea31012005-04-17 16:05:31 -05001338 uint32_t status;
1339 uint32_t portRspPut, portRspMax;
1340 int rc = 1;
1341 lpfc_iocb_type type;
1342 unsigned long iflag;
1343 uint32_t rsp_cmpl = 0;
dea31012005-04-17 16:05:31 -05001344
James Smart2e0fef82007-06-17 19:56:36 -05001345 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001346 pring->stats.iocb_event++;
1347
dea31012005-04-17 16:05:31 -05001348 /*
1349 * The next available response entry should never exceed the maximum
1350 * entries. If it does, treat it as an adapter hardware error.
1351 */
1352 portRspMax = pring->numRiocb;
1353 portRspPut = le32_to_cpu(pgp->rspPutInx);
1354 if (unlikely(portRspPut >= portRspMax)) {
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001355 lpfc_sli_rsp_pointers_error(phba, pring);
James Smart2e0fef82007-06-17 19:56:36 -05001356 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001357 return 1;
1358 }
1359
1360 rmb();
1361 while (pring->rspidx != portRspPut) {
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001362 /*
1363 * Fetch an entry off the ring and copy it into a local data
1364 * structure. The copy involves a byte-swap since the
1365 * network byte order and pci byte orders are different.
1366 */
James Smarted957682007-06-17 19:56:37 -05001367 entry = lpfc_resp_iocb(phba, pring);
James Smart858c9f62007-06-17 19:56:39 -05001368 phba->last_completion_time = jiffies;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001369
1370 if (++pring->rspidx >= portRspMax)
1371 pring->rspidx = 0;
1372
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001373 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1374 (uint32_t *) &rspiocbq.iocb,
James Smarted957682007-06-17 19:56:37 -05001375 phba->iocb_rsp_size);
James Smarta4bc3372006-12-02 13:34:16 -05001376 INIT_LIST_HEAD(&(rspiocbq.list));
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001377 irsp = &rspiocbq.iocb;
1378
dea31012005-04-17 16:05:31 -05001379 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1380 pring->stats.iocb_rsp++;
1381 rsp_cmpl++;
1382
1383 if (unlikely(irsp->ulpStatus)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001384 /*
1385 * If resource errors reported from HBA, reduce
1386 * queuedepths of the SCSI device.
1387 */
1388 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1389 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1390 spin_unlock_irqrestore(&phba->hbalock, iflag);
1391 lpfc_adjust_queue_depth(phba);
1392 spin_lock_irqsave(&phba->hbalock, iflag);
1393 }
1394
dea31012005-04-17 16:05:31 -05001395 /* Rsp ring <ringno> error: IOCB */
1396 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001397 "0336 Rsp Ring %d error: IOCB Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05001398 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001399 pring->ringno,
James Smart92d7f7b2007-06-17 19:56:38 -05001400 irsp->un.ulpWord[0],
1401 irsp->un.ulpWord[1],
1402 irsp->un.ulpWord[2],
1403 irsp->un.ulpWord[3],
1404 irsp->un.ulpWord[4],
1405 irsp->un.ulpWord[5],
1406 *(((uint32_t *) irsp) + 6),
1407 *(((uint32_t *) irsp) + 7));
dea31012005-04-17 16:05:31 -05001408 }
1409
1410 switch (type) {
1411 case LPFC_ABORT_IOCB:
1412 case LPFC_SOL_IOCB:
1413 /*
1414 * Idle exchange closed via ABTS from port. No iocb
1415 * resources need to be recovered.
1416 */
1417 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001418 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001419 "0333 IOCB cmd 0x%x"
James Smartdca94792006-08-01 07:34:08 -04001420 " processed. Skipping"
James Smart92d7f7b2007-06-17 19:56:38 -05001421 " completion\n",
James Smartdca94792006-08-01 07:34:08 -04001422 irsp->ulpCommand);
dea31012005-04-17 16:05:31 -05001423 break;
1424 }
1425
James Bottomley604a3e32005-10-29 10:28:33 -05001426 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1427 &rspiocbq);
dea31012005-04-17 16:05:31 -05001428 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001429 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1430 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1431 &rspiocbq);
1432 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001433 spin_unlock_irqrestore(&phba->hbalock,
1434 iflag);
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001435 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1436 &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001437 spin_lock_irqsave(&phba->hbalock,
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001438 iflag);
1439 }
dea31012005-04-17 16:05:31 -05001440 }
1441 break;
James Smarta4bc3372006-12-02 13:34:16 -05001442 case LPFC_UNSOL_IOCB:
James Smart2e0fef82007-06-17 19:56:36 -05001443 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05001444 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001445 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05001446 break;
dea31012005-04-17 16:05:31 -05001447 default:
1448 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1449 char adaptermsg[LPFC_MAX_ADPTMSG];
1450 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1451 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1452 MAX_MSG_DATA);
Joe Perches898eb712007-10-18 03:06:30 -07001453 dev_warn(&((phba->pcidev)->dev),
1454 "lpfc%d: %s\n",
dea31012005-04-17 16:05:31 -05001455 phba->brd_no, adaptermsg);
1456 } else {
1457 /* Unknown IOCB command */
1458 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001459 "0334 Unknown IOCB command "
James Smart92d7f7b2007-06-17 19:56:38 -05001460 "Data: x%x, x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001461 type, irsp->ulpCommand,
James Smart92d7f7b2007-06-17 19:56:38 -05001462 irsp->ulpStatus,
1463 irsp->ulpIoTag,
1464 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05001465 }
1466 break;
1467 }
1468
1469 /*
1470 * The response IOCB has been processed. Update the ring
1471 * pointer in SLIM. If the port response put pointer has not
1472 * been updated, sync the pgp->rspPutInx and fetch the new port
1473 * response put pointer.
1474 */
James Smarted957682007-06-17 19:56:37 -05001475 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05001476
1477 if (pring->rspidx == portRspPut)
1478 portRspPut = le32_to_cpu(pgp->rspPutInx);
1479 }
1480
1481 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1482 pring->stats.iocb_rsp_full++;
1483 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1484 writel(status, phba->CAregaddr);
1485 readl(phba->CAregaddr);
1486 }
1487 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1488 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1489 pring->stats.iocb_cmd_empty++;
1490
1491 /* Force update of the local copy of cmdGetInx */
1492 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1493 lpfc_sli_resume_iocb(phba, pring);
1494
1495 if ((pring->lpfc_sli_cmd_available))
1496 (pring->lpfc_sli_cmd_available) (phba, pring);
1497
1498 }
1499
James Smart2e0fef82007-06-17 19:56:36 -05001500 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001501 return rc;
1502}
1503
dea31012005-04-17 16:05:31 -05001504int
James Smart2e0fef82007-06-17 19:56:36 -05001505lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1506 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05001507{
James Smarted957682007-06-17 19:56:37 -05001508 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1509 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1510 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001511 IOCB_t *entry;
1512 IOCB_t *irsp = NULL;
1513 struct lpfc_iocbq *rspiocbp = NULL;
1514 struct lpfc_iocbq *next_iocb;
1515 struct lpfc_iocbq *cmdiocbp;
1516 struct lpfc_iocbq *saveq;
dea31012005-04-17 16:05:31 -05001517 uint8_t iocb_cmd_type;
1518 lpfc_iocb_type type;
1519 uint32_t status, free_saveq;
1520 uint32_t portRspPut, portRspMax;
1521 int rc = 1;
1522 unsigned long iflag;
dea31012005-04-17 16:05:31 -05001523
James Smart2e0fef82007-06-17 19:56:36 -05001524 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001525 pring->stats.iocb_event++;
1526
dea31012005-04-17 16:05:31 -05001527 /*
1528 * The next available response entry should never exceed the maximum
1529 * entries. If it does, treat it as an adapter hardware error.
1530 */
1531 portRspMax = pring->numRiocb;
1532 portRspPut = le32_to_cpu(pgp->rspPutInx);
1533 if (portRspPut >= portRspMax) {
1534 /*
1535 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1536 * rsp ring <portRspMax>
1537 */
James Smarted957682007-06-17 19:56:37 -05001538 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001539 "0303 Ring %d handler: portRspPut %d "
dea31012005-04-17 16:05:31 -05001540 "is bigger then rsp ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04001541 pring->ringno, portRspPut, portRspMax);
dea31012005-04-17 16:05:31 -05001542
James Smart2e0fef82007-06-17 19:56:36 -05001543 phba->link_state = LPFC_HBA_ERROR;
1544 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001545
1546 phba->work_hs = HS_FFER3;
1547 lpfc_handle_eratt(phba);
1548
1549 return 1;
1550 }
1551
1552 rmb();
dea31012005-04-17 16:05:31 -05001553 while (pring->rspidx != portRspPut) {
1554 /*
1555 * Build a completion list and call the appropriate handler.
1556 * The process is to get the next available response iocb, get
1557 * a free iocb from the list, copy the response data into the
1558 * free iocb, insert to the continuation list, and update the
1559 * next response index to slim. This process makes response
1560 * iocb's in the ring available to DMA as fast as possible but
1561 * pays a penalty for a copy operation. Since the iocb is
1562 * only 32 bytes, this penalty is considered small relative to
1563 * the PCI reads for register values and a slim write. When
1564 * the ulpLe field is set, the entire Command has been
1565 * received.
1566 */
James Smarted957682007-06-17 19:56:37 -05001567 entry = lpfc_resp_iocb(phba, pring);
1568
James Smart858c9f62007-06-17 19:56:39 -05001569 phba->last_completion_time = jiffies;
James Smart2e0fef82007-06-17 19:56:36 -05001570 rspiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001571 if (rspiocbp == NULL) {
1572 printk(KERN_ERR "%s: out of buffers! Failing "
1573 "completion.\n", __FUNCTION__);
1574 break;
1575 }
1576
James Smarted957682007-06-17 19:56:37 -05001577 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1578 phba->iocb_rsp_size);
dea31012005-04-17 16:05:31 -05001579 irsp = &rspiocbp->iocb;
1580
1581 if (++pring->rspidx >= portRspMax)
1582 pring->rspidx = 0;
1583
James Smarta58cbd52007-08-02 11:09:43 -04001584 if (pring->ringno == LPFC_ELS_RING) {
1585 lpfc_debugfs_slow_ring_trc(phba,
1586 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1587 *(((uint32_t *) irsp) + 4),
1588 *(((uint32_t *) irsp) + 6),
1589 *(((uint32_t *) irsp) + 7));
1590 }
1591
James Smarted957682007-06-17 19:56:37 -05001592 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05001593
1594 if (list_empty(&(pring->iocb_continueq))) {
1595 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1596 } else {
1597 list_add_tail(&rspiocbp->list,
1598 &(pring->iocb_continueq));
1599 }
1600
1601 pring->iocb_continueq_cnt++;
1602 if (irsp->ulpLe) {
1603 /*
1604 * By default, the driver expects to free all resources
1605 * associated with this iocb completion.
1606 */
1607 free_saveq = 1;
1608 saveq = list_get_first(&pring->iocb_continueq,
1609 struct lpfc_iocbq, list);
1610 irsp = &(saveq->iocb);
1611 list_del_init(&pring->iocb_continueq);
1612 pring->iocb_continueq_cnt = 0;
1613
1614 pring->stats.iocb_rsp++;
1615
James Smart92d7f7b2007-06-17 19:56:38 -05001616 /*
1617 * If resource errors reported from HBA, reduce
1618 * queuedepths of the SCSI device.
1619 */
1620 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1621 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1622 spin_unlock_irqrestore(&phba->hbalock, iflag);
1623 lpfc_adjust_queue_depth(phba);
1624 spin_lock_irqsave(&phba->hbalock, iflag);
1625 }
1626
dea31012005-04-17 16:05:31 -05001627 if (irsp->ulpStatus) {
1628 /* Rsp ring <ringno> error: IOCB */
James Smarted957682007-06-17 19:56:37 -05001629 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001630 "0328 Rsp Ring %d error: "
James Smarted957682007-06-17 19:56:37 -05001631 "IOCB Data: "
1632 "x%x x%x x%x x%x "
1633 "x%x x%x x%x x%x "
1634 "x%x x%x x%x x%x "
1635 "x%x x%x x%x x%x\n",
James Smarted957682007-06-17 19:56:37 -05001636 pring->ringno,
1637 irsp->un.ulpWord[0],
1638 irsp->un.ulpWord[1],
1639 irsp->un.ulpWord[2],
1640 irsp->un.ulpWord[3],
1641 irsp->un.ulpWord[4],
1642 irsp->un.ulpWord[5],
1643 *(((uint32_t *) irsp) + 6),
1644 *(((uint32_t *) irsp) + 7),
1645 *(((uint32_t *) irsp) + 8),
1646 *(((uint32_t *) irsp) + 9),
1647 *(((uint32_t *) irsp) + 10),
1648 *(((uint32_t *) irsp) + 11),
1649 *(((uint32_t *) irsp) + 12),
1650 *(((uint32_t *) irsp) + 13),
1651 *(((uint32_t *) irsp) + 14),
1652 *(((uint32_t *) irsp) + 15));
dea31012005-04-17 16:05:31 -05001653 }
1654
1655 /*
1656 * Fetch the IOCB command type and call the correct
1657 * completion routine. Solicited and Unsolicited
1658 * IOCBs on the ELS ring get freed back to the
1659 * lpfc_iocb_list by the discovery kernel thread.
1660 */
1661 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1662 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1663 if (type == LPFC_SOL_IOCB) {
James Smart2e0fef82007-06-17 19:56:36 -05001664 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05001665 iflag);
1666 rc = lpfc_sli_process_sol_iocb(phba, pring,
James Smart2e0fef82007-06-17 19:56:36 -05001667 saveq);
1668 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001669 } else if (type == LPFC_UNSOL_IOCB) {
James Smart2e0fef82007-06-17 19:56:36 -05001670 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05001671 iflag);
1672 rc = lpfc_sli_process_unsol_iocb(phba, pring,
James Smart2e0fef82007-06-17 19:56:36 -05001673 saveq);
1674 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001675 } else if (type == LPFC_ABORT_IOCB) {
1676 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1677 ((cmdiocbp =
James Bottomley604a3e32005-10-29 10:28:33 -05001678 lpfc_sli_iocbq_lookup(phba, pring,
1679 saveq)))) {
dea31012005-04-17 16:05:31 -05001680 /* Call the specified completion
1681 routine */
1682 if (cmdiocbp->iocb_cmpl) {
1683 spin_unlock_irqrestore(
James Smart2e0fef82007-06-17 19:56:36 -05001684 &phba->hbalock,
dea31012005-04-17 16:05:31 -05001685 iflag);
1686 (cmdiocbp->iocb_cmpl) (phba,
1687 cmdiocbp, saveq);
1688 spin_lock_irqsave(
James Smart2e0fef82007-06-17 19:56:36 -05001689 &phba->hbalock,
dea31012005-04-17 16:05:31 -05001690 iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001691 } else
James Smart2e0fef82007-06-17 19:56:36 -05001692 __lpfc_sli_release_iocbq(phba,
James Bottomley604a3e32005-10-29 10:28:33 -05001693 cmdiocbp);
dea31012005-04-17 16:05:31 -05001694 }
1695 } else if (type == LPFC_UNKNOWN_IOCB) {
1696 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1697
1698 char adaptermsg[LPFC_MAX_ADPTMSG];
1699
1700 memset(adaptermsg, 0,
1701 LPFC_MAX_ADPTMSG);
1702 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1703 MAX_MSG_DATA);
1704 dev_warn(&((phba->pcidev)->dev),
Joe Perches898eb712007-10-18 03:06:30 -07001705 "lpfc%d: %s\n",
dea31012005-04-17 16:05:31 -05001706 phba->brd_no, adaptermsg);
1707 } else {
1708 /* Unknown IOCB command */
James Smart92d7f7b2007-06-17 19:56:38 -05001709 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001710 "0335 Unknown IOCB "
James Smart92d7f7b2007-06-17 19:56:38 -05001711 "command Data: x%x "
1712 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001713 irsp->ulpCommand,
1714 irsp->ulpStatus,
1715 irsp->ulpIoTag,
1716 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05001717 }
1718 }
1719
1720 if (free_saveq) {
James Smart2e0fef82007-06-17 19:56:36 -05001721 list_for_each_entry_safe(rspiocbp, next_iocb,
1722 &saveq->list, list) {
1723 list_del(&rspiocbp->list);
1724 __lpfc_sli_release_iocbq(phba,
1725 rspiocbp);
dea31012005-04-17 16:05:31 -05001726 }
James Smart2e0fef82007-06-17 19:56:36 -05001727 __lpfc_sli_release_iocbq(phba, saveq);
dea31012005-04-17 16:05:31 -05001728 }
James Smart92d7f7b2007-06-17 19:56:38 -05001729 rspiocbp = NULL;
dea31012005-04-17 16:05:31 -05001730 }
1731
1732 /*
1733 * If the port response put pointer has not been updated, sync
1734 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1735 * response put pointer.
1736 */
1737 if (pring->rspidx == portRspPut) {
1738 portRspPut = le32_to_cpu(pgp->rspPutInx);
1739 }
1740 } /* while (pring->rspidx != portRspPut) */
1741
James Smart92d7f7b2007-06-17 19:56:38 -05001742 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
dea31012005-04-17 16:05:31 -05001743 /* At least one response entry has been freed */
1744 pring->stats.iocb_rsp_full++;
1745 /* SET RxRE_RSP in Chip Att register */
1746 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1747 writel(status, phba->CAregaddr);
1748 readl(phba->CAregaddr); /* flush */
1749 }
1750 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1751 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1752 pring->stats.iocb_cmd_empty++;
1753
1754 /* Force update of the local copy of cmdGetInx */
1755 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1756 lpfc_sli_resume_iocb(phba, pring);
1757
1758 if ((pring->lpfc_sli_cmd_available))
1759 (pring->lpfc_sli_cmd_available) (phba, pring);
1760
1761 }
1762
James Smart2e0fef82007-06-17 19:56:36 -05001763 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001764 return rc;
1765}
1766
James Smart2e0fef82007-06-17 19:56:36 -05001767void
dea31012005-04-17 16:05:31 -05001768lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1769{
James Smart2534ba72007-04-25 09:52:20 -04001770 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001771 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -04001772 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05001773
James Smart92d7f7b2007-06-17 19:56:38 -05001774 if (pring->ringno == LPFC_ELS_RING) {
1775 lpfc_fabric_abort_hba(phba);
1776 }
1777
dea31012005-04-17 16:05:31 -05001778 /* Error everything on txq and txcmplq
1779 * First do the txq.
1780 */
James Smart2e0fef82007-06-17 19:56:36 -05001781 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001782 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05001783 pring->txq_cnt = 0;
dea31012005-04-17 16:05:31 -05001784
1785 /* Next issue ABTS for everything on the txcmplq */
James Smart2534ba72007-04-25 09:52:20 -04001786 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1787 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1788
James Smart2e0fef82007-06-17 19:56:36 -05001789 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001790
1791 while (!list_empty(&completions)) {
1792 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
dea31012005-04-17 16:05:31 -05001793 cmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05001794 list_del_init(&iocb->list);
dea31012005-04-17 16:05:31 -05001795
James Smart2e0fef82007-06-17 19:56:36 -05001796 if (!iocb->iocb_cmpl)
1797 lpfc_sli_release_iocbq(phba, iocb);
1798 else {
dea31012005-04-17 16:05:31 -05001799 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1800 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
dea31012005-04-17 16:05:31 -05001801 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001802 }
dea31012005-04-17 16:05:31 -05001803 }
dea31012005-04-17 16:05:31 -05001804}
1805
Jamie Wellnitz41415862006-02-28 19:25:27 -05001806int
James Smart2e0fef82007-06-17 19:56:36 -05001807lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
dea31012005-04-17 16:05:31 -05001808{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001809 uint32_t status;
1810 int i = 0;
1811 int retval = 0;
dea31012005-04-17 16:05:31 -05001812
Jamie Wellnitz41415862006-02-28 19:25:27 -05001813 /* Read the HBA Host Status Register */
1814 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001815
Jamie Wellnitz41415862006-02-28 19:25:27 -05001816 /*
1817 * Check status register every 100ms for 5 retries, then every
1818 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1819 * every 2.5 sec for 4.
1820 * Break our of the loop if errors occurred during init.
1821 */
1822 while (((status & mask) != mask) &&
1823 !(status & HS_FFERM) &&
1824 i++ < 20) {
dea31012005-04-17 16:05:31 -05001825
Jamie Wellnitz41415862006-02-28 19:25:27 -05001826 if (i <= 5)
1827 msleep(10);
1828 else if (i <= 10)
1829 msleep(500);
1830 else
1831 msleep(2500);
dea31012005-04-17 16:05:31 -05001832
Jamie Wellnitz41415862006-02-28 19:25:27 -05001833 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05001834 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05001835 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001836 lpfc_sli_brdrestart(phba);
1837 }
1838 /* Read the HBA Host Status Register */
1839 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001840 }
dea31012005-04-17 16:05:31 -05001841
Jamie Wellnitz41415862006-02-28 19:25:27 -05001842 /* Check to see if any errors occurred during init */
1843 if ((status & HS_FFERM) || (i >= 20)) {
James Smart2e0fef82007-06-17 19:56:36 -05001844 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001845 retval = 1;
1846 }
dea31012005-04-17 16:05:31 -05001847
Jamie Wellnitz41415862006-02-28 19:25:27 -05001848 return retval;
dea31012005-04-17 16:05:31 -05001849}
1850
James Smart92908312006-03-07 15:04:13 -05001851#define BARRIER_TEST_PATTERN (0xdeadbeef)
1852
James Smart2e0fef82007-06-17 19:56:36 -05001853void lpfc_reset_barrier(struct lpfc_hba *phba)
James Smart92908312006-03-07 15:04:13 -05001854{
James Smart65a29c12006-07-06 15:50:50 -04001855 uint32_t __iomem *resp_buf;
1856 uint32_t __iomem *mbox_buf;
James Smart92908312006-03-07 15:04:13 -05001857 volatile uint32_t mbox;
1858 uint32_t hc_copy;
1859 int i;
1860 uint8_t hdrtype;
1861
1862 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1863 if (hdrtype != 0x80 ||
1864 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1865 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1866 return;
1867
1868 /*
1869 * Tell the other part of the chip to suspend temporarily all
1870 * its DMA activity.
1871 */
James Smart65a29c12006-07-06 15:50:50 -04001872 resp_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001873
1874 /* Disable the error attention */
1875 hc_copy = readl(phba->HCregaddr);
1876 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1877 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001878 phba->link_flag |= LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05001879
1880 if (readl(phba->HAregaddr) & HA_ERATT) {
1881 /* Clear Chip error bit */
1882 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001883 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001884 }
1885
1886 mbox = 0;
1887 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1888 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1889
1890 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
James Smart65a29c12006-07-06 15:50:50 -04001891 mbox_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001892 writel(mbox, mbox_buf);
1893
1894 for (i = 0;
1895 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1896 mdelay(1);
1897
1898 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1899 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
James Smart2e0fef82007-06-17 19:56:36 -05001900 phba->pport->stopped)
James Smart92908312006-03-07 15:04:13 -05001901 goto restore_hc;
1902 else
1903 goto clear_errat;
1904 }
1905
1906 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1907 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1908 mdelay(1);
1909
1910clear_errat:
1911
1912 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1913 mdelay(1);
1914
1915 if (readl(phba->HAregaddr) & HA_ERATT) {
1916 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001917 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001918 }
1919
1920restore_hc:
James Smart2e0fef82007-06-17 19:56:36 -05001921 phba->link_flag &= ~LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05001922 writel(hc_copy, phba->HCregaddr);
1923 readl(phba->HCregaddr); /* flush */
1924}
1925
Jamie Wellnitz41415862006-02-28 19:25:27 -05001926int
James Smart2e0fef82007-06-17 19:56:36 -05001927lpfc_sli_brdkill(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001928{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001929 struct lpfc_sli *psli;
1930 LPFC_MBOXQ_t *pmb;
1931 uint32_t status;
1932 uint32_t ha_copy;
1933 int retval;
1934 int i = 0;
1935
1936 psli = &phba->sli;
1937
1938 /* Kill HBA */
James Smarted957682007-06-17 19:56:37 -05001939 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001940 "0329 Kill HBA Data: x%x x%x\n",
1941 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001942
1943 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
James Smart92908312006-03-07 15:04:13 -05001944 GFP_KERNEL)) == 0)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001945 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001946
1947 /* Disable the error attention */
James Smart2e0fef82007-06-17 19:56:36 -05001948 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001949 status = readl(phba->HCregaddr);
1950 status &= ~HC_ERINT_ENA;
1951 writel(status, phba->HCregaddr);
1952 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001953 phba->link_flag |= LS_IGNORE_ERATT;
1954 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001955
1956 lpfc_kill_board(phba, pmb);
1957 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1958 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1959
1960 if (retval != MBX_SUCCESS) {
1961 if (retval != MBX_BUSY)
1962 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_lock_irq(&phba->hbalock);
1964 phba->link_flag &= ~LS_IGNORE_ERATT;
1965 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001966 return 1;
1967 }
1968
James Smart92908312006-03-07 15:04:13 -05001969 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1970
Jamie Wellnitz41415862006-02-28 19:25:27 -05001971 mempool_free(pmb, phba->mbox_mem_pool);
1972
1973 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1974 * attention every 100ms for 3 seconds. If we don't get ERATT after
1975 * 3 seconds we still set HBA_ERROR state because the status of the
1976 * board is now undefined.
1977 */
1978 ha_copy = readl(phba->HAregaddr);
1979
1980 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1981 mdelay(100);
1982 ha_copy = readl(phba->HAregaddr);
1983 }
1984
1985 del_timer_sync(&psli->mbox_tmo);
James Smart92908312006-03-07 15:04:13 -05001986 if (ha_copy & HA_ERATT) {
1987 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001988 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001989 }
James Smart2e0fef82007-06-17 19:56:36 -05001990 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001991 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05001992 phba->link_flag &= ~LS_IGNORE_ERATT;
1993 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001994
1995 psli->mbox_active = NULL;
1996 lpfc_hba_down_post(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001997 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001998
James Smart2e0fef82007-06-17 19:56:36 -05001999 return ha_copy & HA_ERATT ? 0 : 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002000}
2001
2002int
James Smart2e0fef82007-06-17 19:56:36 -05002003lpfc_sli_brdreset(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05002004{
2005 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002006 struct lpfc_sli_ring *pring;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002007 uint16_t cfg_value;
dea31012005-04-17 16:05:31 -05002008 int i;
dea31012005-04-17 16:05:31 -05002009
Jamie Wellnitz41415862006-02-28 19:25:27 -05002010 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002011
Jamie Wellnitz41415862006-02-28 19:25:27 -05002012 /* Reset HBA */
2013 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002014 "0325 Reset HBA Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002015 phba->pport->port_state, psli->sli_flag);
dea31012005-04-17 16:05:31 -05002016
2017 /* perform board reset */
2018 phba->fc_eventTag = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002019 phba->pport->fc_myDID = 0;
2020 phba->pport->fc_prevDID = 0;
dea31012005-04-17 16:05:31 -05002021
Jamie Wellnitz41415862006-02-28 19:25:27 -05002022 /* Turn off parity checking and serr during the physical reset */
2023 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
2024 pci_write_config_word(phba->pcidev, PCI_COMMAND,
2025 (cfg_value &
2026 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
2027
James Smart1c067a42006-08-01 07:33:52 -04002028 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002029 /* Now toggle INITFF bit in the Host Control Register */
2030 writel(HC_INITFF, phba->HCregaddr);
2031 mdelay(1);
2032 readl(phba->HCregaddr); /* flush */
2033 writel(0, phba->HCregaddr);
2034 readl(phba->HCregaddr); /* flush */
2035
2036 /* Restore PCI cmd register */
2037 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
dea31012005-04-17 16:05:31 -05002038
2039 /* Initialize relevant SLI info */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002040 for (i = 0; i < psli->num_rings; i++) {
2041 pring = &psli->ring[i];
dea31012005-04-17 16:05:31 -05002042 pring->flag = 0;
2043 pring->rspidx = 0;
2044 pring->next_cmdidx = 0;
2045 pring->local_getidx = 0;
2046 pring->cmdidx = 0;
2047 pring->missbufcnt = 0;
2048 }
dea31012005-04-17 16:05:31 -05002049
James Smart2e0fef82007-06-17 19:56:36 -05002050 phba->link_state = LPFC_WARM_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002051 return 0;
2052}
2053
2054int
James Smart2e0fef82007-06-17 19:56:36 -05002055lpfc_sli_brdrestart(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05002056{
2057 MAILBOX_t *mb;
2058 struct lpfc_sli *psli;
2059 uint16_t skip_post;
2060 volatile uint32_t word0;
2061 void __iomem *to_slim;
2062
James Smart2e0fef82007-06-17 19:56:36 -05002063 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002064
2065 psli = &phba->sli;
2066
2067 /* Restart HBA */
2068 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002069 "0337 Restart HBA Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002070 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002071
2072 word0 = 0;
2073 mb = (MAILBOX_t *) &word0;
2074 mb->mbxCommand = MBX_RESTART;
2075 mb->mbxHc = 1;
2076
James Smart92908312006-03-07 15:04:13 -05002077 lpfc_reset_barrier(phba);
2078
Jamie Wellnitz41415862006-02-28 19:25:27 -05002079 to_slim = phba->MBslimaddr;
2080 writel(*(uint32_t *) mb, to_slim);
2081 readl(to_slim); /* flush */
2082
2083 /* Only skip post after fc_ffinit is completed */
James Smart2e0fef82007-06-17 19:56:36 -05002084 if (phba->pport->port_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002085 skip_post = 1;
2086 word0 = 1; /* This is really setting up word1 */
dea31012005-04-17 16:05:31 -05002087 } else {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002088 skip_post = 0;
2089 word0 = 0; /* This is really setting up word1 */
2090 }
James Smart65a29c12006-07-06 15:50:50 -04002091 to_slim = phba->MBslimaddr + sizeof (uint32_t);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002092 writel(*(uint32_t *) mb, to_slim);
2093 readl(to_slim); /* flush */
2094
2095 lpfc_sli_brdreset(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002096 phba->pport->stopped = 0;
2097 phba->link_state = LPFC_INIT_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002098
James Smart2e0fef82007-06-17 19:56:36 -05002099 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002100
James Smart64ba8812006-08-02 15:24:34 -04002101 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2102 psli->stats_start = get_seconds();
2103
Jamie Wellnitz41415862006-02-28 19:25:27 -05002104 if (skip_post)
2105 mdelay(100);
2106 else
dea31012005-04-17 16:05:31 -05002107 mdelay(2000);
dea31012005-04-17 16:05:31 -05002108
Jamie Wellnitz41415862006-02-28 19:25:27 -05002109 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -05002110
2111 return 0;
2112}
2113
2114static int
2115lpfc_sli_chipset_init(struct lpfc_hba *phba)
2116{
2117 uint32_t status, i = 0;
2118
2119 /* Read the HBA Host Status Register */
2120 status = readl(phba->HSregaddr);
2121
2122 /* Check status register to see what current state is */
2123 i = 0;
2124 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2125
2126 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2127 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2128 * 4.
2129 */
2130 if (i++ >= 20) {
2131 /* Adapter failed to init, timeout, status reg
2132 <status> */
James Smarted957682007-06-17 19:56:37 -05002133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002134 "0436 Adapter failed to init, "
2135 "timeout, status reg x%x\n", status);
James Smart2e0fef82007-06-17 19:56:36 -05002136 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002137 return -ETIMEDOUT;
2138 }
2139
2140 /* Check to see if any errors occurred during init */
2141 if (status & HS_FFERM) {
2142 /* ERROR: During chipset initialization */
2143 /* Adapter failed to init, chipset, status reg
2144 <status> */
James Smarted957682007-06-17 19:56:37 -05002145 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002146 "0437 Adapter failed to init, "
2147 "chipset, status reg x%x\n", status);
James Smart2e0fef82007-06-17 19:56:36 -05002148 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002149 return -EIO;
2150 }
2151
2152 if (i <= 5) {
2153 msleep(10);
2154 } else if (i <= 10) {
2155 msleep(500);
2156 } else {
2157 msleep(2500);
2158 }
2159
2160 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05002161 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05002162 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002163 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05002164 }
2165 /* Read the HBA Host Status Register */
2166 status = readl(phba->HSregaddr);
2167 }
2168
2169 /* Check to see if any errors occurred during init */
2170 if (status & HS_FFERM) {
2171 /* ERROR: During chipset initialization */
2172 /* Adapter failed to init, chipset, status reg <status> */
James Smarted957682007-06-17 19:56:37 -05002173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002174 "0438 Adapter failed to init, chipset, "
2175 "status reg x%x\n", status);
James Smart2e0fef82007-06-17 19:56:36 -05002176 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002177 return -EIO;
2178 }
2179
2180 /* Clear all interrupt enable conditions */
2181 writel(0, phba->HCregaddr);
2182 readl(phba->HCregaddr); /* flush */
2183
2184 /* setup host attn register */
2185 writel(0xffffffff, phba->HAregaddr);
2186 readl(phba->HAregaddr); /* flush */
2187 return 0;
2188}
2189
James Smart78b2d852007-08-02 11:10:21 -04002190int
James Smarted957682007-06-17 19:56:37 -05002191lpfc_sli_hbq_count(void)
2192{
James Smart92d7f7b2007-06-17 19:56:38 -05002193 return ARRAY_SIZE(lpfc_hbq_defs);
James Smarted957682007-06-17 19:56:37 -05002194}
2195
2196static int
2197lpfc_sli_hbq_entry_count(void)
2198{
2199 int hbq_count = lpfc_sli_hbq_count();
2200 int count = 0;
2201 int i;
2202
2203 for (i = 0; i < hbq_count; ++i)
James Smart92d7f7b2007-06-17 19:56:38 -05002204 count += lpfc_hbq_defs[i]->entry_count;
James Smarted957682007-06-17 19:56:37 -05002205 return count;
2206}
2207
dea31012005-04-17 16:05:31 -05002208int
James Smarted957682007-06-17 19:56:37 -05002209lpfc_sli_hbq_size(void)
2210{
2211 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2212}
2213
2214static int
2215lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2216{
2217 int hbq_count = lpfc_sli_hbq_count();
2218 LPFC_MBOXQ_t *pmb;
2219 MAILBOX_t *pmbox;
2220 uint32_t hbqno;
2221 uint32_t hbq_entry_index;
James Smarted957682007-06-17 19:56:37 -05002222
James Smart92d7f7b2007-06-17 19:56:38 -05002223 /* Get a Mailbox buffer to setup mailbox
2224 * commands for HBA initialization
2225 */
James Smarted957682007-06-17 19:56:37 -05002226 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2227
2228 if (!pmb)
2229 return -ENOMEM;
2230
2231 pmbox = &pmb->mb;
2232
2233 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2234 phba->link_state = LPFC_INIT_MBX_CMDS;
2235
2236 hbq_entry_index = 0;
2237 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2238 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2239 phba->hbqs[hbqno].hbqPutIdx = 0;
2240 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2241 phba->hbqs[hbqno].entry_count =
James Smart92d7f7b2007-06-17 19:56:38 -05002242 lpfc_hbq_defs[hbqno]->entry_count;
James Smart51ef4c22007-08-02 11:10:31 -04002243 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
2244 hbq_entry_index, pmb);
James Smarted957682007-06-17 19:56:37 -05002245 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2246
2247 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2248 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2249 mbxStatus <status>, ring <num> */
2250
2251 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05002252 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002253 "1805 Adapter failed to init. "
James Smarted957682007-06-17 19:56:37 -05002254 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002255 pmbox->mbxCommand,
James Smarted957682007-06-17 19:56:37 -05002256 pmbox->mbxStatus, hbqno);
2257
2258 phba->link_state = LPFC_HBA_ERROR;
2259 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -05002260 return ENXIO;
2261 }
2262 }
2263 phba->hbq_count = hbq_count;
2264
James Smarted957682007-06-17 19:56:37 -05002265 mempool_free(pmb, phba->mbox_mem_pool);
2266
James Smart92d7f7b2007-06-17 19:56:38 -05002267 /* Initially populate or replenish the HBQs */
2268 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2269 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2270 return -ENOMEM;
2271 }
James Smarted957682007-06-17 19:56:37 -05002272 return 0;
2273}
2274
2275static int
2276lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
dea31012005-04-17 16:05:31 -05002277{
2278 LPFC_MBOXQ_t *pmb;
2279 uint32_t resetcount = 0, rc = 0, done = 0;
2280
2281 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2282 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -05002283 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002284 return -ENOMEM;
2285 }
2286
James Smarted957682007-06-17 19:56:37 -05002287 phba->sli_rev = sli_mode;
dea31012005-04-17 16:05:31 -05002288 while (resetcount < 2 && !done) {
James Smart2e0fef82007-06-17 19:56:36 -05002289 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04002290 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002291 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05002292 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002293 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05002294 msleep(2500);
2295 rc = lpfc_sli_chipset_init(phba);
2296 if (rc)
2297 break;
2298
James Smart2e0fef82007-06-17 19:56:36 -05002299 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04002300 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002301 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002302 resetcount++;
2303
James Smarted957682007-06-17 19:56:37 -05002304 /* Call pre CONFIG_PORT mailbox command initialization. A
2305 * value of 0 means the call was successful. Any other
2306 * nonzero value is a failure, but if ERESTART is returned,
2307 * the driver may reset the HBA and try again.
2308 */
dea31012005-04-17 16:05:31 -05002309 rc = lpfc_config_port_prep(phba);
2310 if (rc == -ERESTART) {
James Smarted957682007-06-17 19:56:37 -05002311 phba->link_state = LPFC_LINK_UNKNOWN;
dea31012005-04-17 16:05:31 -05002312 continue;
2313 } else if (rc) {
2314 break;
2315 }
2316
James Smart2e0fef82007-06-17 19:56:36 -05002317 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -05002318 lpfc_config_port(phba, pmb);
2319 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smarted957682007-06-17 19:56:37 -05002320 if (rc != MBX_SUCCESS) {
dea31012005-04-17 16:05:31 -05002321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002322 "0442 Adapter failed to init, mbxCmd x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05002323 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002324 pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002325 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002326 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002327 spin_unlock_irq(&phba->hbalock);
2328 rc = -ENXIO;
James Smarted957682007-06-17 19:56:37 -05002329 } else {
2330 done = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002331 phba->max_vpi = (phba->max_vpi &&
2332 pmb->mb.un.varCfgPort.gmv) != 0
2333 ? pmb->mb.un.varCfgPort.max_vpi
2334 : 0;
dea31012005-04-17 16:05:31 -05002335 }
2336 }
James Smarted957682007-06-17 19:56:37 -05002337
2338 if (!done) {
2339 rc = -EINVAL;
2340 goto do_prep_failed;
2341 }
2342
2343 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002344 (!pmb->mb.un.varCfgPort.cMA)) {
James Smarted957682007-06-17 19:56:37 -05002345 rc = -ENXIO;
2346 goto do_prep_failed;
2347 }
2348 return rc;
2349
James Smart92d7f7b2007-06-17 19:56:38 -05002350do_prep_failed:
James Smarted957682007-06-17 19:56:37 -05002351 mempool_free(pmb, phba->mbox_mem_pool);
2352 return rc;
2353}
2354
2355int
2356lpfc_sli_hba_setup(struct lpfc_hba *phba)
2357{
2358 uint32_t rc;
James Smart92d7f7b2007-06-17 19:56:38 -05002359 int mode = 3;
James Smarted957682007-06-17 19:56:37 -05002360
2361 switch (lpfc_sli_mode) {
2362 case 2:
James Smart78b2d852007-08-02 11:10:21 -04002363 if (phba->cfg_enable_npiv) {
James Smart92d7f7b2007-06-17 19:56:38 -05002364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002365 "1824 NPIV enabled: Override lpfc_sli_mode "
James Smart92d7f7b2007-06-17 19:56:38 -05002366 "parameter (%d) to auto (0).\n",
James Smarte8b62012007-08-02 11:10:09 -04002367 lpfc_sli_mode);
James Smart92d7f7b2007-06-17 19:56:38 -05002368 break;
2369 }
James Smarted957682007-06-17 19:56:37 -05002370 mode = 2;
2371 break;
2372 case 0:
2373 case 3:
2374 break;
2375 default:
James Smart92d7f7b2007-06-17 19:56:38 -05002376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002377 "1819 Unrecognized lpfc_sli_mode "
2378 "parameter: %d.\n", lpfc_sli_mode);
James Smarted957682007-06-17 19:56:37 -05002379
2380 break;
2381 }
2382
2383 rc = lpfc_do_config_port(phba, mode);
2384 if (rc && lpfc_sli_mode == 3)
James Smart92d7f7b2007-06-17 19:56:38 -05002385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002386 "1820 Unable to select SLI-3. "
2387 "Not supported by adapter.\n");
James Smarted957682007-06-17 19:56:37 -05002388 if (rc && mode != 2)
2389 rc = lpfc_do_config_port(phba, 2);
2390 if (rc)
dea31012005-04-17 16:05:31 -05002391 goto lpfc_sli_hba_setup_error;
2392
James Smarted957682007-06-17 19:56:37 -05002393 if (phba->sli_rev == 3) {
2394 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2395 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2396 phba->sli3_options |= LPFC_SLI3_ENABLED;
2397 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2398
2399 } else {
2400 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2401 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
James Smart92d7f7b2007-06-17 19:56:38 -05002402 phba->sli3_options = 0;
James Smarted957682007-06-17 19:56:37 -05002403 }
2404
2405 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002406 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2407 phba->sli_rev, phba->max_vpi);
James Smarted957682007-06-17 19:56:37 -05002408 rc = lpfc_sli_ring_map(phba);
dea31012005-04-17 16:05:31 -05002409
2410 if (rc)
2411 goto lpfc_sli_hba_setup_error;
2412
James Smart92d7f7b2007-06-17 19:56:38 -05002413 /* Init HBQs */
James Smarted957682007-06-17 19:56:37 -05002414
2415 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2416 rc = lpfc_sli_hbq_setup(phba);
2417 if (rc)
2418 goto lpfc_sli_hba_setup_error;
2419 }
2420
dea31012005-04-17 16:05:31 -05002421 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2422
2423 rc = lpfc_config_port_post(phba);
2424 if (rc)
2425 goto lpfc_sli_hba_setup_error;
2426
James Smarted957682007-06-17 19:56:37 -05002427 return rc;
2428
James Smart92d7f7b2007-06-17 19:56:38 -05002429lpfc_sli_hba_setup_error:
James Smart2e0fef82007-06-17 19:56:36 -05002430 phba->link_state = LPFC_HBA_ERROR;
James Smarted957682007-06-17 19:56:37 -05002431 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002432 "0445 Firmware initialization failed\n");
dea31012005-04-17 16:05:31 -05002433 return rc;
2434}
2435
dea31012005-04-17 16:05:31 -05002436/*! lpfc_mbox_timeout
2437 *
2438 * \pre
2439 * \post
2440 * \param hba Pointer to per struct lpfc_hba structure
2441 * \param l1 Pointer to the driver's mailbox queue.
2442 * \return
2443 * void
2444 *
2445 * \b Description:
2446 *
2447 * This routine handles mailbox timeout events at timer interrupt context.
2448 */
2449void
2450lpfc_mbox_timeout(unsigned long ptr)
2451{
James Smart92d7f7b2007-06-17 19:56:38 -05002452 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
dea31012005-04-17 16:05:31 -05002453 unsigned long iflag;
James Smart2e0fef82007-06-17 19:56:36 -05002454 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05002455
James Smart2e0fef82007-06-17 19:56:36 -05002456 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05002457 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002458 if (!tmo_posted)
2459 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2460 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2461
2462 if (!tmo_posted) {
James Smart92d7f7b2007-06-17 19:56:38 -05002463 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002464 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05002465 lpfc_worker_wake_up(phba);
2466 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002467 }
dea31012005-04-17 16:05:31 -05002468}
2469
2470void
2471lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2472{
James Smart2e0fef82007-06-17 19:56:36 -05002473 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2474 MAILBOX_t *mb = &pmbox->mb;
James Smart1dcb58e2007-04-25 09:51:30 -04002475 struct lpfc_sli *psli = &phba->sli;
2476 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002477
James Smart2e0fef82007-06-17 19:56:36 -05002478 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
dea31012005-04-17 16:05:31 -05002479 return;
2480 }
2481
dea31012005-04-17 16:05:31 -05002482 /* Mbox cmd <mbxCommand> timeout */
James Smarted957682007-06-17 19:56:37 -05002483 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002484 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002485 mb->mbxCommand,
2486 phba->pport->port_state,
2487 phba->sli.sli_flag,
2488 phba->sli.mbox_active);
dea31012005-04-17 16:05:31 -05002489
James Smart1dcb58e2007-04-25 09:51:30 -04002490 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2491 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2492 * it to fail all oustanding SCSI IO.
2493 */
James Smart2e0fef82007-06-17 19:56:36 -05002494 spin_lock_irq(&phba->pport->work_port_lock);
2495 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2496 spin_unlock_irq(&phba->pport->work_port_lock);
2497 spin_lock_irq(&phba->hbalock);
2498 phba->link_state = LPFC_LINK_UNKNOWN;
2499 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart1dcb58e2007-04-25 09:51:30 -04002500 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002501 spin_unlock_irq(&phba->hbalock);
James Smart1dcb58e2007-04-25 09:51:30 -04002502
2503 pring = &psli->ring[psli->fcp_ring];
2504 lpfc_sli_abort_iocb_ring(phba, pring);
2505
2506 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002507 "0316 Resetting board due to mailbox timeout\n");
James Smart1dcb58e2007-04-25 09:51:30 -04002508 /*
2509 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2510 * on oustanding mailbox commands.
2511 */
2512 lpfc_offline_prep(phba);
2513 lpfc_offline(phba);
2514 lpfc_sli_brdrestart(phba);
2515 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2516 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2517 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002518 return;
2519}
2520
2521int
James Smart2e0fef82007-06-17 19:56:36 -05002522lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
dea31012005-04-17 16:05:31 -05002523{
dea31012005-04-17 16:05:31 -05002524 MAILBOX_t *mb;
James Smart2e0fef82007-06-17 19:56:36 -05002525 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002526 uint32_t status, evtctr;
2527 uint32_t ha_copy;
2528 int i;
2529 unsigned long drvr_flag = 0;
2530 volatile uint32_t word0, ldata;
2531 void __iomem *to_slim;
2532
James Smarted957682007-06-17 19:56:37 -05002533 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
James Smart92d7f7b2007-06-17 19:56:38 -05002534 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
James Smarted957682007-06-17 19:56:37 -05002535 if(!pmbox->vport) {
2536 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05002537 LOG_MBOX | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002538 "1806 Mbox x%x failed. No vport\n",
James Smarted957682007-06-17 19:56:37 -05002539 pmbox->mb.mbxCommand);
2540 dump_stack();
2541 return MBXERR_ERROR;
2542 }
2543 }
2544
James Smart92d7f7b2007-06-17 19:56:38 -05002545
Linas Vepstas8d63f372007-02-14 14:28:36 -06002546 /* If the PCI channel is in offline state, do not post mbox. */
2547 if (unlikely(pci_channel_offline(phba->pcidev)))
2548 return MBX_NOT_FINISHED;
2549
James Smart2e0fef82007-06-17 19:56:36 -05002550 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002551 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002552
2553
dea31012005-04-17 16:05:31 -05002554 mb = &pmbox->mb;
2555 status = MBX_SUCCESS;
2556
James Smart2e0fef82007-06-17 19:56:36 -05002557 if (phba->link_state == LPFC_HBA_ERROR) {
2558 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002559
2560 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002561 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
James Smart2e0fef82007-06-17 19:56:36 -05002562 return MBX_NOT_FINISHED;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002563 }
2564
James Smart92908312006-03-07 15:04:13 -05002565 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2566 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
James Smart2e0fef82007-06-17 19:56:36 -05002567 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
James Smart92d7f7b2007-06-17 19:56:38 -05002568 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
James Smart2e0fef82007-06-17 19:56:36 -05002569 return MBX_NOT_FINISHED;
James Smart92908312006-03-07 15:04:13 -05002570 }
2571
dea31012005-04-17 16:05:31 -05002572 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2573 /* Polling for a mbox command when another one is already active
2574 * is not allowed in SLI. Also, the driver must have established
2575 * SLI2 mode to queue and process multiple mbox commands.
2576 */
2577
2578 if (flag & MBX_POLL) {
James Smart2e0fef82007-06-17 19:56:36 -05002579 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002580
2581 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002582 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002583 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002584 }
2585
2586 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002587 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002588 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002589 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002590 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002591 }
2592
2593 /* Handle STOP IOCB processing flag. This is only meaningful
2594 * if we are not polling for mbox completion.
2595 */
2596 if (flag & MBX_STOP_IOCB) {
2597 flag &= ~MBX_STOP_IOCB;
2598 /* Now flag each ring */
2599 for (i = 0; i < psli->num_rings; i++) {
2600 /* If the ring is active, flag it */
2601 if (psli->ring[i].cmdringaddr) {
2602 psli->ring[i].flag |=
2603 LPFC_STOP_IOCB_MBX;
2604 }
2605 }
2606 }
2607
2608 /* Another mailbox command is still being processed, queue this
2609 * command to be processed later.
2610 */
2611 lpfc_mbox_put(phba, pmbox);
2612
2613 /* Mbox cmd issue - BUSY */
James Smarted957682007-06-17 19:56:37 -05002614 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002615 "(%d):0308 Mbox cmd issue - BUSY Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05002616 "x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002617 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2618 mb->mbxCommand, phba->pport->port_state,
2619 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05002620
2621 psli->slistat.mbox_busy++;
James Smart2e0fef82007-06-17 19:56:36 -05002622 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002623
James Smart858c9f62007-06-17 19:56:39 -05002624 if (pmbox->vport) {
2625 lpfc_debugfs_disc_trc(pmbox->vport,
2626 LPFC_DISC_TRC_MBOX_VPORT,
2627 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2628 (uint32_t)mb->mbxCommand,
2629 mb->un.varWords[0], mb->un.varWords[1]);
2630 }
2631 else {
2632 lpfc_debugfs_disc_trc(phba->pport,
2633 LPFC_DISC_TRC_MBOX,
2634 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2635 (uint32_t)mb->mbxCommand,
2636 mb->un.varWords[0], mb->un.varWords[1]);
2637 }
2638
James Smart2e0fef82007-06-17 19:56:36 -05002639 return MBX_BUSY;
dea31012005-04-17 16:05:31 -05002640 }
2641
2642 /* Handle STOP IOCB processing flag. This is only meaningful
2643 * if we are not polling for mbox completion.
2644 */
2645 if (flag & MBX_STOP_IOCB) {
2646 flag &= ~MBX_STOP_IOCB;
2647 if (flag == MBX_NOWAIT) {
2648 /* Now flag each ring */
2649 for (i = 0; i < psli->num_rings; i++) {
2650 /* If the ring is active, flag it */
2651 if (psli->ring[i].cmdringaddr) {
2652 psli->ring[i].flag |=
2653 LPFC_STOP_IOCB_MBX;
2654 }
2655 }
2656 }
2657 }
2658
2659 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2660
2661 /* If we are not polling, we MUST be in SLI2 mode */
2662 if (flag != MBX_POLL) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002663 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2664 (mb->mbxCommand != MBX_KILL_BOARD)) {
dea31012005-04-17 16:05:31 -05002665 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002666 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002667 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002668 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002669 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002670 }
2671 /* timeout active mbox command */
James Smarta309a6b2006-08-01 07:33:43 -04002672 mod_timer(&psli->mbox_tmo, (jiffies +
2673 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
dea31012005-04-17 16:05:31 -05002674 }
2675
2676 /* Mailbox cmd <cmd> issue */
James Smarted957682007-06-17 19:56:37 -05002677 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002678 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05002679 "x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002680 pmbox->vport ? pmbox->vport->vpi : 0,
James Smart92d7f7b2007-06-17 19:56:38 -05002681 mb->mbxCommand, phba->pport->port_state,
2682 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05002683
James Smart858c9f62007-06-17 19:56:39 -05002684 if (mb->mbxCommand != MBX_HEARTBEAT) {
2685 if (pmbox->vport) {
2686 lpfc_debugfs_disc_trc(pmbox->vport,
2687 LPFC_DISC_TRC_MBOX_VPORT,
2688 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2689 (uint32_t)mb->mbxCommand,
2690 mb->un.varWords[0], mb->un.varWords[1]);
2691 }
2692 else {
2693 lpfc_debugfs_disc_trc(phba->pport,
2694 LPFC_DISC_TRC_MBOX,
2695 "MBOX Send: cmd:x%x mb:x%x x%x",
2696 (uint32_t)mb->mbxCommand,
2697 mb->un.varWords[0], mb->un.varWords[1]);
2698 }
2699 }
2700
dea31012005-04-17 16:05:31 -05002701 psli->slistat.mbox_cmd++;
2702 evtctr = psli->slistat.mbox_event;
2703
2704 /* next set own bit for the adapter and copy over command word */
2705 mb->mbxOwner = OWN_CHIP;
2706
2707 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002708 /* First copy command data to host SLIM area */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002709 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002710 } else {
James Smart92908312006-03-07 15:04:13 -05002711 if (mb->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05002712 /* copy command data into host mbox for cmpl */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002713 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
James Smart92d7f7b2007-06-17 19:56:38 -05002714 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002715 }
2716
2717 /* First copy mbox command data to HBA SLIM, skip past first
2718 word */
2719 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2720 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2721 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2722
2723 /* Next copy over first word, with mbxOwner set */
2724 ldata = *((volatile uint32_t *)mb);
2725 to_slim = phba->MBslimaddr;
2726 writel(ldata, to_slim);
2727 readl(to_slim); /* flush */
2728
2729 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2730 /* switch over to host mailbox */
2731 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2732 }
2733 }
2734
2735 wmb();
2736 /* interrupt board to doit right away */
2737 writel(CA_MBATT, phba->CAregaddr);
2738 readl(phba->CAregaddr); /* flush */
2739
2740 switch (flag) {
2741 case MBX_NOWAIT:
2742 /* Don't wait for it to finish, just return */
2743 psli->mbox_active = pmbox;
2744 break;
2745
2746 case MBX_POLL:
dea31012005-04-17 16:05:31 -05002747 psli->mbox_active = NULL;
2748 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2749 /* First read mbox status word */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002750 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002751 word0 = le32_to_cpu(word0);
2752 } else {
2753 /* First read mbox status word */
2754 word0 = readl(phba->MBslimaddr);
2755 }
2756
2757 /* Read the HBA Host Attention Register */
2758 ha_copy = readl(phba->HAregaddr);
2759
James Smarta309a6b2006-08-01 07:33:43 -04002760 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2761 i *= 1000; /* Convert to ms */
2762
dea31012005-04-17 16:05:31 -05002763 /* Wait for command to complete */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002764 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2765 (!(ha_copy & HA_MBATT) &&
James Smart2e0fef82007-06-17 19:56:36 -05002766 (phba->link_state > LPFC_WARM_START))) {
James Smarta309a6b2006-08-01 07:33:43 -04002767 if (i-- <= 0) {
dea31012005-04-17 16:05:31 -05002768 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002769 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05002770 drvr_flag);
James Smart2e0fef82007-06-17 19:56:36 -05002771 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002772 }
2773
2774 /* Check if we took a mbox interrupt while we were
2775 polling */
2776 if (((word0 & OWN_CHIP) != OWN_CHIP)
2777 && (evtctr != psli->slistat.mbox_event))
2778 break;
2779
James Smart2e0fef82007-06-17 19:56:36 -05002780 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05002781 drvr_flag);
2782
James Smart1dcb58e2007-04-25 09:51:30 -04002783 msleep(1);
dea31012005-04-17 16:05:31 -05002784
James Smart2e0fef82007-06-17 19:56:36 -05002785 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002786
2787 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2788 /* First copy command data */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002789 word0 = *((volatile uint32_t *)
2790 &phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002791 word0 = le32_to_cpu(word0);
2792 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2793 MAILBOX_t *slimmb;
2794 volatile uint32_t slimword0;
2795 /* Check real SLIM for any errors */
2796 slimword0 = readl(phba->MBslimaddr);
2797 slimmb = (MAILBOX_t *) & slimword0;
2798 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2799 && slimmb->mbxStatus) {
2800 psli->sli_flag &=
2801 ~LPFC_SLI2_ACTIVE;
2802 word0 = slimword0;
2803 }
2804 }
2805 } else {
2806 /* First copy command data */
2807 word0 = readl(phba->MBslimaddr);
2808 }
2809 /* Read the HBA Host Attention Register */
2810 ha_copy = readl(phba->HAregaddr);
2811 }
2812
2813 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002814 /* copy results back to user */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002815 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
James Smart92d7f7b2007-06-17 19:56:38 -05002816 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002817 } else {
2818 /* First copy command data */
2819 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2820 MAILBOX_CMD_SIZE);
2821 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2822 pmbox->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05002823 lpfc_memcpy_from_slim((void *)pmbox->context2,
dea31012005-04-17 16:05:31 -05002824 phba->MBslimaddr + DMP_RSP_OFFSET,
2825 mb->un.varDmp.word_cnt);
2826 }
2827 }
2828
2829 writel(HA_MBATT, phba->HAregaddr);
2830 readl(phba->HAregaddr); /* flush */
2831
2832 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2833 status = mb->mbxStatus;
2834 }
2835
James Smart2e0fef82007-06-17 19:56:36 -05002836 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2837 return status;
dea31012005-04-17 16:05:31 -05002838}
2839
James Smart92d7f7b2007-06-17 19:56:38 -05002840/*
2841 * Caller needs to hold lock.
2842 */
James Smart858c9f62007-06-17 19:56:39 -05002843static void
James Smart92d7f7b2007-06-17 19:56:38 -05002844__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05002845 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -05002846{
2847 /* Insert the caller's iocb in the txq tail for later processing. */
2848 list_add_tail(&piocb->list, &pring->txq);
2849 pring->txq_cnt++;
dea31012005-04-17 16:05:31 -05002850}
2851
2852static struct lpfc_iocbq *
2853lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05002854 struct lpfc_iocbq **piocb)
dea31012005-04-17 16:05:31 -05002855{
2856 struct lpfc_iocbq * nextiocb;
2857
2858 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2859 if (!nextiocb) {
2860 nextiocb = *piocb;
2861 *piocb = NULL;
2862 }
2863
2864 return nextiocb;
2865}
2866
James Smart92d7f7b2007-06-17 19:56:38 -05002867/*
2868 * Lockless version of lpfc_sli_issue_iocb.
2869 */
dea31012005-04-17 16:05:31 -05002870int
James Smart92d7f7b2007-06-17 19:56:38 -05002871__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05002872 struct lpfc_iocbq *piocb, uint32_t flag)
2873{
2874 struct lpfc_iocbq *nextiocb;
2875 IOCB_t *iocb;
2876
James Smart92d7f7b2007-06-17 19:56:38 -05002877 if (piocb->iocb_cmpl && (!piocb->vport) &&
2878 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
2879 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
2880 lpfc_printf_log(phba, KERN_ERR,
2881 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002882 "1807 IOCB x%x failed. No vport\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002883 piocb->iocb.ulpCommand);
2884 dump_stack();
2885 return IOCB_ERROR;
2886 }
2887
2888
Linas Vepstas8d63f372007-02-14 14:28:36 -06002889 /* If the PCI channel is in offline state, do not post iocbs. */
2890 if (unlikely(pci_channel_offline(phba->pcidev)))
2891 return IOCB_ERROR;
2892
dea31012005-04-17 16:05:31 -05002893 /*
2894 * We should never get an IOCB if we are in a < LINK_DOWN state
2895 */
James Smart2e0fef82007-06-17 19:56:36 -05002896 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05002897 return IOCB_ERROR;
2898
2899 /*
2900 * Check to see if we are blocking IOCB processing because of a
2901 * outstanding mbox command.
2902 */
2903 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2904 goto iocb_busy;
2905
James Smart2e0fef82007-06-17 19:56:36 -05002906 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
dea31012005-04-17 16:05:31 -05002907 /*
James Smart2680eea2007-04-25 09:52:55 -04002908 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
dea31012005-04-17 16:05:31 -05002909 * can be issued if the link is not up.
2910 */
2911 switch (piocb->iocb.ulpCommand) {
2912 case CMD_QUE_RING_BUF_CN:
2913 case CMD_QUE_RING_BUF64_CN:
dea31012005-04-17 16:05:31 -05002914 /*
2915 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2916 * completion, iocb_cmpl MUST be 0.
2917 */
2918 if (piocb->iocb_cmpl)
2919 piocb->iocb_cmpl = NULL;
2920 /*FALLTHROUGH*/
2921 case CMD_CREATE_XRI_CR:
James Smart2680eea2007-04-25 09:52:55 -04002922 case CMD_CLOSE_XRI_CN:
2923 case CMD_CLOSE_XRI_CX:
dea31012005-04-17 16:05:31 -05002924 break;
2925 default:
2926 goto iocb_busy;
2927 }
2928
2929 /*
2930 * For FCP commands, we must be in a state where we can process link
2931 * attention events.
2932 */
2933 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
James Smart92d7f7b2007-06-17 19:56:38 -05002934 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
dea31012005-04-17 16:05:31 -05002935 goto iocb_busy;
James Smart92d7f7b2007-06-17 19:56:38 -05002936 }
dea31012005-04-17 16:05:31 -05002937
dea31012005-04-17 16:05:31 -05002938 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2939 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2940 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2941
2942 if (iocb)
2943 lpfc_sli_update_ring(phba, pring);
2944 else
2945 lpfc_sli_update_full_ring(phba, pring);
2946
2947 if (!piocb)
2948 return IOCB_SUCCESS;
2949
2950 goto out_busy;
2951
2952 iocb_busy:
2953 pring->stats.iocb_cmd_delay++;
2954
2955 out_busy:
2956
2957 if (!(flag & SLI_IOCB_RET_IOCB)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002958 __lpfc_sli_ringtx_put(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05002959 return IOCB_SUCCESS;
2960 }
2961
2962 return IOCB_BUSY;
2963}
2964
James Smart92d7f7b2007-06-17 19:56:38 -05002965
2966int
2967lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2968 struct lpfc_iocbq *piocb, uint32_t flag)
2969{
2970 unsigned long iflags;
2971 int rc;
2972
2973 spin_lock_irqsave(&phba->hbalock, iflags);
2974 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
2975 spin_unlock_irqrestore(&phba->hbalock, iflags);
2976
2977 return rc;
2978}
2979
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002980static int
2981lpfc_extra_ring_setup( struct lpfc_hba *phba)
2982{
2983 struct lpfc_sli *psli;
2984 struct lpfc_sli_ring *pring;
2985
2986 psli = &phba->sli;
2987
2988 /* Adjust cmd/rsp ring iocb entries more evenly */
James Smarta4bc3372006-12-02 13:34:16 -05002989
2990 /* Take some away from the FCP ring */
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002991 pring = &psli->ring[psli->fcp_ring];
2992 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2993 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2994 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2995 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2996
James Smarta4bc3372006-12-02 13:34:16 -05002997 /* and give them to the extra ring */
2998 pring = &psli->ring[psli->extra_ring];
2999
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003000 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3001 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3002 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3003 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3004
3005 /* Setup default profile for this ring */
3006 pring->iotag_max = 4096;
3007 pring->num_mask = 1;
3008 pring->prt[0].profile = 0; /* Mask 0 */
James Smarta4bc3372006-12-02 13:34:16 -05003009 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
3010 pring->prt[0].type = phba->cfg_multi_ring_type;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003011 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
3012 return 0;
3013}
3014
James Smart57127f12007-10-27 13:37:05 -04003015void
3016lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3017 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
3018{
3019 IOCB_t *icmd;
3020 uint16_t evt_code;
3021 uint16_t temp;
3022 struct temp_event temp_event_data;
3023 struct Scsi_Host *shost;
3024
3025 icmd = &iocbq->iocb;
3026 evt_code = icmd->un.asyncstat.evt_code;
3027 temp = icmd->ulpContext;
3028
3029 if ((evt_code != ASYNC_TEMP_WARN) &&
3030 (evt_code != ASYNC_TEMP_SAFE)) {
3031 lpfc_printf_log(phba,
3032 KERN_ERR,
3033 LOG_SLI,
3034 "0327 Ring %d handler: unexpected ASYNC_STATUS"
3035 " evt_code 0x%x\n",
3036 pring->ringno,
3037 icmd->un.asyncstat.evt_code);
3038 return;
3039 }
3040 temp_event_data.data = (uint32_t)temp;
3041 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
3042 if (evt_code == ASYNC_TEMP_WARN) {
3043 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
3044 lpfc_printf_log(phba,
3045 KERN_WARNING,
3046 LOG_TEMP,
3047 "0339 Adapter is very hot, please take "
3048 "corrective action. temperature : %d Celsius\n",
3049 temp);
3050 }
3051 if (evt_code == ASYNC_TEMP_SAFE) {
3052 temp_event_data.event_code = LPFC_NORMAL_TEMP;
3053 lpfc_printf_log(phba,
3054 KERN_INFO,
3055 LOG_TEMP,
3056 "0340 Adapter temperature is OK now. "
3057 "temperature : %d Celsius\n",
3058 temp);
3059 }
3060
3061 /* Send temperature change event to applications */
3062 shost = lpfc_shost_from_vport(phba->pport);
3063 fc_host_post_vendor_event(shost, fc_get_event_number(),
3064 sizeof(temp_event_data), (char *) &temp_event_data,
3065 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
3066
3067}
3068
3069
dea31012005-04-17 16:05:31 -05003070int
3071lpfc_sli_setup(struct lpfc_hba *phba)
3072{
James Smarted957682007-06-17 19:56:37 -05003073 int i, totiocbsize = 0;
dea31012005-04-17 16:05:31 -05003074 struct lpfc_sli *psli = &phba->sli;
3075 struct lpfc_sli_ring *pring;
3076
3077 psli->num_rings = MAX_CONFIGURED_RINGS;
3078 psli->sli_flag = 0;
3079 psli->fcp_ring = LPFC_FCP_RING;
3080 psli->next_ring = LPFC_FCP_NEXT_RING;
James Smarta4bc3372006-12-02 13:34:16 -05003081 psli->extra_ring = LPFC_EXTRA_RING;
dea31012005-04-17 16:05:31 -05003082
James Bottomley604a3e32005-10-29 10:28:33 -05003083 psli->iocbq_lookup = NULL;
3084 psli->iocbq_lookup_len = 0;
3085 psli->last_iotag = 0;
3086
dea31012005-04-17 16:05:31 -05003087 for (i = 0; i < psli->num_rings; i++) {
3088 pring = &psli->ring[i];
3089 switch (i) {
3090 case LPFC_FCP_RING: /* ring 0 - FCP */
3091 /* numCiocb and numRiocb are used in config_port */
3092 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3093 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3094 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3095 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3096 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3097 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003098 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003099 SLI3_IOCB_CMD_SIZE :
3100 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003101 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003102 SLI3_IOCB_RSP_SIZE :
3103 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05003104 pring->iotag_ctr = 0;
3105 pring->iotag_max =
James Smart92d7f7b2007-06-17 19:56:38 -05003106 (phba->cfg_hba_queue_depth * 2);
dea31012005-04-17 16:05:31 -05003107 pring->fast_iotag = pring->iotag_max;
3108 pring->num_mask = 0;
3109 break;
James Smarta4bc3372006-12-02 13:34:16 -05003110 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
dea31012005-04-17 16:05:31 -05003111 /* numCiocb and numRiocb are used in config_port */
3112 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3113 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003114 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003115 SLI3_IOCB_CMD_SIZE :
3116 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003117 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003118 SLI3_IOCB_RSP_SIZE :
3119 SLI2_IOCB_RSP_SIZE;
James Smart2e0fef82007-06-17 19:56:36 -05003120 pring->iotag_max = phba->cfg_hba_queue_depth;
dea31012005-04-17 16:05:31 -05003121 pring->num_mask = 0;
3122 break;
3123 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3124 /* numCiocb and numRiocb are used in config_port */
3125 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3126 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003127 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003128 SLI3_IOCB_CMD_SIZE :
3129 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003130 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003131 SLI3_IOCB_RSP_SIZE :
3132 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05003133 pring->fast_iotag = 0;
3134 pring->iotag_ctr = 0;
3135 pring->iotag_max = 4096;
James Smart57127f12007-10-27 13:37:05 -04003136 pring->lpfc_sli_rcv_async_status =
3137 lpfc_sli_async_event_handler;
dea31012005-04-17 16:05:31 -05003138 pring->num_mask = 4;
3139 pring->prt[0].profile = 0; /* Mask 0 */
3140 pring->prt[0].rctl = FC_ELS_REQ;
3141 pring->prt[0].type = FC_ELS_DATA;
3142 pring->prt[0].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003143 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05003144 pring->prt[1].profile = 0; /* Mask 1 */
3145 pring->prt[1].rctl = FC_ELS_RSP;
3146 pring->prt[1].type = FC_ELS_DATA;
3147 pring->prt[1].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003148 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05003149 pring->prt[2].profile = 0; /* Mask 2 */
3150 /* NameServer Inquiry */
3151 pring->prt[2].rctl = FC_UNSOL_CTL;
3152 /* NameServer */
3153 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3154 pring->prt[2].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003155 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05003156 pring->prt[3].profile = 0; /* Mask 3 */
3157 /* NameServer response */
3158 pring->prt[3].rctl = FC_SOL_CTL;
3159 /* NameServer */
3160 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3161 pring->prt[3].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003162 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05003163 break;
3164 }
James Smarted957682007-06-17 19:56:37 -05003165 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
James Smart92d7f7b2007-06-17 19:56:38 -05003166 (pring->numRiocb * pring->sizeRiocb);
dea31012005-04-17 16:05:31 -05003167 }
James Smarted957682007-06-17 19:56:37 -05003168 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
dea31012005-04-17 16:05:31 -05003169 /* Too many cmd / rsp ring entries in SLI2 SLIM */
James Smarte8b62012007-08-02 11:10:09 -04003170 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
3171 "SLI2 SLIM Data: x%x x%lx\n",
3172 phba->brd_no, totiocbsize,
3173 (unsigned long) MAX_SLIM_IOCB_SIZE);
dea31012005-04-17 16:05:31 -05003174 }
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003175 if (phba->cfg_multi_ring_support == 2)
3176 lpfc_extra_ring_setup(phba);
dea31012005-04-17 16:05:31 -05003177
3178 return 0;
3179}
3180
3181int
James Smart2e0fef82007-06-17 19:56:36 -05003182lpfc_sli_queue_setup(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003183{
3184 struct lpfc_sli *psli;
3185 struct lpfc_sli_ring *pring;
James Bottomley604a3e32005-10-29 10:28:33 -05003186 int i;
dea31012005-04-17 16:05:31 -05003187
3188 psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003189 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003190 INIT_LIST_HEAD(&psli->mboxq);
James Smart92d7f7b2007-06-17 19:56:38 -05003191 INIT_LIST_HEAD(&psli->mboxq_cmpl);
dea31012005-04-17 16:05:31 -05003192 /* Initialize list headers for txq and txcmplq as double linked lists */
3193 for (i = 0; i < psli->num_rings; i++) {
3194 pring = &psli->ring[i];
3195 pring->ringno = i;
3196 pring->next_cmdidx = 0;
3197 pring->local_getidx = 0;
3198 pring->cmdidx = 0;
3199 INIT_LIST_HEAD(&pring->txq);
3200 INIT_LIST_HEAD(&pring->txcmplq);
3201 INIT_LIST_HEAD(&pring->iocb_continueq);
3202 INIT_LIST_HEAD(&pring->postbufq);
dea31012005-04-17 16:05:31 -05003203 }
James Smart2e0fef82007-06-17 19:56:36 -05003204 spin_unlock_irq(&phba->hbalock);
3205 return 1;
dea31012005-04-17 16:05:31 -05003206}
3207
3208int
James Smart92d7f7b2007-06-17 19:56:38 -05003209lpfc_sli_host_down(struct lpfc_vport *vport)
3210{
James Smart858c9f62007-06-17 19:56:39 -05003211 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05003212 struct lpfc_hba *phba = vport->phba;
3213 struct lpfc_sli *psli = &phba->sli;
3214 struct lpfc_sli_ring *pring;
3215 struct lpfc_iocbq *iocb, *next_iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003216 int i;
3217 unsigned long flags = 0;
3218 uint16_t prev_pring_flag;
3219
3220 lpfc_cleanup_discovery_resources(vport);
3221
3222 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003223 for (i = 0; i < psli->num_rings; i++) {
3224 pring = &psli->ring[i];
3225 prev_pring_flag = pring->flag;
James Smart858c9f62007-06-17 19:56:39 -05003226 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3227 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05003228 /*
3229 * Error everything on the txq since these iocbs have not been
3230 * given to the FW yet.
3231 */
James Smart92d7f7b2007-06-17 19:56:38 -05003232 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3233 if (iocb->vport != vport)
3234 continue;
James Smart858c9f62007-06-17 19:56:39 -05003235 list_move_tail(&iocb->list, &completions);
James Smart92d7f7b2007-06-17 19:56:38 -05003236 pring->txq_cnt--;
James Smart92d7f7b2007-06-17 19:56:38 -05003237 }
3238
3239 /* Next issue ABTS for everything on the txcmplq */
3240 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3241 list) {
3242 if (iocb->vport != vport)
3243 continue;
3244 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3245 }
3246
3247 pring->flag = prev_pring_flag;
3248 }
3249
3250 spin_unlock_irqrestore(&phba->hbalock, flags);
3251
James Smart858c9f62007-06-17 19:56:39 -05003252 while (!list_empty(&completions)) {
3253 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3254
3255 if (!iocb->iocb_cmpl)
3256 lpfc_sli_release_iocbq(phba, iocb);
3257 else {
3258 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3259 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3260 (iocb->iocb_cmpl) (phba, iocb, iocb);
3261 }
3262 }
James Smart92d7f7b2007-06-17 19:56:38 -05003263 return 1;
3264}
3265
3266int
James Smart2e0fef82007-06-17 19:56:36 -05003267lpfc_sli_hba_down(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003268{
James Smart2534ba72007-04-25 09:52:20 -04003269 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003270 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003271 struct lpfc_sli_ring *pring;
3272 LPFC_MBOXQ_t *pmb;
James Smart2534ba72007-04-25 09:52:20 -04003273 struct lpfc_iocbq *iocb;
3274 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003275 int i;
3276 unsigned long flags = 0;
3277
dea31012005-04-17 16:05:31 -05003278 lpfc_hba_down_prep(phba);
3279
James Smart92d7f7b2007-06-17 19:56:38 -05003280 lpfc_fabric_abort_hba(phba);
3281
James Smart2e0fef82007-06-17 19:56:36 -05003282 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003283 for (i = 0; i < psli->num_rings; i++) {
3284 pring = &psli->ring[i];
James Smart858c9f62007-06-17 19:56:39 -05003285 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3286 pring->flag |= LPFC_DEFERRED_RING_EVENT;
dea31012005-04-17 16:05:31 -05003287
3288 /*
3289 * Error everything on the txq since these iocbs have not been
3290 * given to the FW yet.
3291 */
James Smart2534ba72007-04-25 09:52:20 -04003292 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05003293 pring->txq_cnt = 0;
3294
dea31012005-04-17 16:05:31 -05003295 }
James Smart2e0fef82007-06-17 19:56:36 -05003296 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003297
James Smart2534ba72007-04-25 09:52:20 -04003298 while (!list_empty(&completions)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003299 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
James Smart2534ba72007-04-25 09:52:20 -04003300 cmd = &iocb->iocb;
James Smart2534ba72007-04-25 09:52:20 -04003301
James Smart2e0fef82007-06-17 19:56:36 -05003302 if (!iocb->iocb_cmpl)
3303 lpfc_sli_release_iocbq(phba, iocb);
3304 else {
James Smart2534ba72007-04-25 09:52:20 -04003305 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3306 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3307 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05003308 }
James Smart2534ba72007-04-25 09:52:20 -04003309 }
3310
dea31012005-04-17 16:05:31 -05003311 /* Return any active mbox cmds */
3312 del_timer_sync(&psli->mbox_tmo);
James Smarted957682007-06-17 19:56:37 -05003313 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003314
3315 spin_lock(&phba->pport->work_port_lock);
3316 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3317 spin_unlock(&phba->pport->work_port_lock);
3318
3319 if (psli->mbox_active) {
3320 list_add_tail(&psli->mbox_active->list, &completions);
James Smart2e0fef82007-06-17 19:56:36 -05003321 psli->mbox_active = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003322 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
dea31012005-04-17 16:05:31 -05003323 }
dea31012005-04-17 16:05:31 -05003324
James Smart92d7f7b2007-06-17 19:56:38 -05003325 /* Return any pending or completed mbox cmds */
3326 list_splice_init(&phba->sli.mboxq, &completions);
3327 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3328 INIT_LIST_HEAD(&psli->mboxq);
3329 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3330
3331 spin_unlock_irqrestore(&phba->hbalock, flags);
3332
3333 while (!list_empty(&completions)) {
3334 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
dea31012005-04-17 16:05:31 -05003335 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3336 if (pmb->mbox_cmpl) {
dea31012005-04-17 16:05:31 -05003337 pmb->mbox_cmpl(phba,pmb);
dea31012005-04-17 16:05:31 -05003338 }
3339 }
dea31012005-04-17 16:05:31 -05003340 return 1;
3341}
3342
3343void
3344lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3345{
3346 uint32_t *src = srcp;
3347 uint32_t *dest = destp;
3348 uint32_t ldata;
3349 int i;
3350
3351 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3352 ldata = *src;
3353 ldata = le32_to_cpu(ldata);
3354 *dest = ldata;
3355 src++;
3356 dest++;
3357 }
3358}
3359
3360int
James Smart2e0fef82007-06-17 19:56:36 -05003361lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3362 struct lpfc_dmabuf *mp)
dea31012005-04-17 16:05:31 -05003363{
3364 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3365 later */
James Smart2e0fef82007-06-17 19:56:36 -05003366 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003367 list_add_tail(&mp->list, &pring->postbufq);
dea31012005-04-17 16:05:31 -05003368 pring->postbufq_cnt++;
James Smart2e0fef82007-06-17 19:56:36 -05003369 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003370 return 0;
3371}
3372
3373
3374struct lpfc_dmabuf *
3375lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3376 dma_addr_t phys)
3377{
3378 struct lpfc_dmabuf *mp, *next_mp;
3379 struct list_head *slp = &pring->postbufq;
3380
3381 /* Search postbufq, from the begining, looking for a match on phys */
James Smart2e0fef82007-06-17 19:56:36 -05003382 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003383 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3384 if (mp->phys == phys) {
3385 list_del_init(&mp->list);
3386 pring->postbufq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05003387 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003388 return mp;
3389 }
3390 }
3391
James Smart2e0fef82007-06-17 19:56:36 -05003392 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003393 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003394 "0410 Cannot find virtual addr for mapped buf on "
dea31012005-04-17 16:05:31 -05003395 "ring %d Data x%llx x%p x%p x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003396 pring->ringno, (unsigned long long)phys,
dea31012005-04-17 16:05:31 -05003397 slp->next, slp->prev, pring->postbufq_cnt);
3398 return NULL;
3399}
3400
3401static void
James Smart2e0fef82007-06-17 19:56:36 -05003402lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3403 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003404{
James Smart2e0fef82007-06-17 19:56:36 -05003405 IOCB_t *irsp = &rspiocb->iocb;
James Smart2680eea2007-04-25 09:52:55 -04003406 uint16_t abort_iotag, abort_context;
James Smart92d7f7b2007-06-17 19:56:38 -05003407 struct lpfc_iocbq *abort_iocb;
James Smart2680eea2007-04-25 09:52:55 -04003408 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3409
3410 abort_iocb = NULL;
James Smart2680eea2007-04-25 09:52:55 -04003411
3412 if (irsp->ulpStatus) {
3413 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3414 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3415
James Smart2e0fef82007-06-17 19:56:36 -05003416 spin_lock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04003417 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3418 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3419
James Smart92d7f7b2007-06-17 19:56:38 -05003420 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003421 "0327 Cannot abort els iocb %p "
James Smart92d7f7b2007-06-17 19:56:38 -05003422 "with tag %x context %x, abort status %x, "
3423 "abort code %x\n",
James Smarte8b62012007-08-02 11:10:09 -04003424 abort_iocb, abort_iotag, abort_context,
3425 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart2680eea2007-04-25 09:52:55 -04003426
3427 /*
3428 * make sure we have the right iocbq before taking it
3429 * off the txcmplq and try to call completion routine.
3430 */
James Smart2e0fef82007-06-17 19:56:36 -05003431 if (!abort_iocb ||
3432 abort_iocb->iocb.ulpContext != abort_context ||
3433 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3434 spin_unlock_irq(&phba->hbalock);
3435 else {
James Smart92d7f7b2007-06-17 19:56:38 -05003436 list_del_init(&abort_iocb->list);
James Smart2680eea2007-04-25 09:52:55 -04003437 pring->txcmplq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05003438 spin_unlock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04003439
James Smart92d7f7b2007-06-17 19:56:38 -05003440 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3441 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3442 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3443 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
James Smart2680eea2007-04-25 09:52:55 -04003444 }
3445 }
3446
James Bottomley604a3e32005-10-29 10:28:33 -05003447 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003448 return;
3449}
3450
James Smart92d7f7b2007-06-17 19:56:38 -05003451static void
3452lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3453 struct lpfc_iocbq *rspiocb)
3454{
3455 IOCB_t *irsp = &rspiocb->iocb;
3456
3457 /* ELS cmd tag <ulpIoTag> completes */
3458 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04003459 "0133 Ignoring ELS cmd tag x%x completion Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05003460 "x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003461 irsp->ulpIoTag, irsp->ulpStatus,
James Smart92d7f7b2007-06-17 19:56:38 -05003462 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smart858c9f62007-06-17 19:56:39 -05003463 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3464 lpfc_ct_free_iocb(phba, cmdiocb);
3465 else
3466 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05003467 return;
3468}
3469
dea31012005-04-17 16:05:31 -05003470int
James Smart2e0fef82007-06-17 19:56:36 -05003471lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3472 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -05003473{
James Smart2e0fef82007-06-17 19:56:36 -05003474 struct lpfc_vport *vport = cmdiocb->vport;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003475 struct lpfc_iocbq *abtsiocbp;
dea31012005-04-17 16:05:31 -05003476 IOCB_t *icmd = NULL;
3477 IOCB_t *iabt = NULL;
James Smart07951072007-04-25 09:51:38 -04003478 int retval = IOCB_ERROR;
3479
James Smart92d7f7b2007-06-17 19:56:38 -05003480 /*
3481 * There are certain command types we don't want to abort. And we
3482 * don't want to abort commands that are already in the process of
3483 * being aborted.
James Smart07951072007-04-25 09:51:38 -04003484 */
3485 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05003486 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
James Smart92d7f7b2007-06-17 19:56:38 -05003487 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3488 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
James Smart07951072007-04-25 09:51:38 -04003489 return 0;
3490
James Smart858c9f62007-06-17 19:56:39 -05003491 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3492 * callback so that nothing happens when it finishes.
James Smart07951072007-04-25 09:51:38 -04003493 */
James Smart858c9f62007-06-17 19:56:39 -05003494 if ((vport->load_flag & FC_UNLOADING) &&
3495 (pring->ringno == LPFC_ELS_RING)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003496 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3497 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3498 else
3499 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
James Smart07951072007-04-25 09:51:38 -04003500 goto abort_iotag_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05003501 }
dea31012005-04-17 16:05:31 -05003502
3503 /* issue ABTS for this IOCB based on iotag */
James Smart92d7f7b2007-06-17 19:56:38 -05003504 abtsiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003505 if (abtsiocbp == NULL)
3506 return 0;
dea31012005-04-17 16:05:31 -05003507
James Smart07951072007-04-25 09:51:38 -04003508 /* This signals the response to set the correct status
3509 * before calling the completion handler.
3510 */
3511 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3512
dea31012005-04-17 16:05:31 -05003513 iabt = &abtsiocbp->iocb;
James Smart07951072007-04-25 09:51:38 -04003514 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3515 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3516 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05003517 iabt->ulpLe = 1;
James Smart07951072007-04-25 09:51:38 -04003518 iabt->ulpClass = icmd->ulpClass;
dea31012005-04-17 16:05:31 -05003519
James Smart2e0fef82007-06-17 19:56:36 -05003520 if (phba->link_state >= LPFC_LINK_UP)
James Smart07951072007-04-25 09:51:38 -04003521 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3522 else
3523 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3524
3525 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -04003526
James Smarte8b62012007-08-02 11:10:09 -04003527 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3528 "0339 Abort xri x%x, original iotag x%x, "
3529 "abort cmd iotag x%x\n",
3530 iabt->un.acxri.abortContextTag,
3531 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
James Smart92d7f7b2007-06-17 19:56:38 -05003532 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
James Smart07951072007-04-25 09:51:38 -04003533
3534abort_iotag_exit:
James Smart2e0fef82007-06-17 19:56:36 -05003535 /*
3536 * Caller to this routine should check for IOCB_ERROR
3537 * and handle it properly. This routine no longer removes
3538 * iocb off txcmplq and call compl in case of IOCB_ERROR.
James Smart07951072007-04-25 09:51:38 -04003539 */
James Smart2e0fef82007-06-17 19:56:36 -05003540 return retval;
dea31012005-04-17 16:05:31 -05003541}
3542
3543static int
James Smart51ef4c22007-08-02 11:10:31 -04003544lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3545 uint16_t tgt_id, uint64_t lun_id,
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003546 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05003547{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003548 struct lpfc_scsi_buf *lpfc_cmd;
3549 struct scsi_cmnd *cmnd;
dea31012005-04-17 16:05:31 -05003550 int rc = 1;
3551
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003552 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3553 return rc;
3554
James Smart51ef4c22007-08-02 11:10:31 -04003555 if (iocbq->vport != vport)
3556 return rc;
3557
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003558 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3559 cmnd = lpfc_cmd->pCmd;
3560
3561 if (cmnd == NULL)
dea31012005-04-17 16:05:31 -05003562 return rc;
3563
3564 switch (ctx_cmd) {
3565 case LPFC_CTX_LUN:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003566 if ((cmnd->device->id == tgt_id) &&
3567 (cmnd->device->lun == lun_id))
dea31012005-04-17 16:05:31 -05003568 rc = 0;
3569 break;
3570 case LPFC_CTX_TGT:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003571 if (cmnd->device->id == tgt_id)
dea31012005-04-17 16:05:31 -05003572 rc = 0;
3573 break;
dea31012005-04-17 16:05:31 -05003574 case LPFC_CTX_HOST:
3575 rc = 0;
3576 break;
3577 default:
3578 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3579 __FUNCTION__, ctx_cmd);
3580 break;
3581 }
3582
3583 return rc;
3584}
3585
3586int
James Smart51ef4c22007-08-02 11:10:31 -04003587lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3588 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05003589{
James Smart51ef4c22007-08-02 11:10:31 -04003590 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003591 struct lpfc_iocbq *iocbq;
3592 int sum, i;
dea31012005-04-17 16:05:31 -05003593
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003594 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3595 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05003596
James Smart51ef4c22007-08-02 11:10:31 -04003597 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
3598 ctx_cmd) == 0)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003599 sum++;
dea31012005-04-17 16:05:31 -05003600 }
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003601
dea31012005-04-17 16:05:31 -05003602 return sum;
3603}
3604
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003605void
James Smart2e0fef82007-06-17 19:56:36 -05003606lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3607 struct lpfc_iocbq *rspiocb)
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003608{
James Bottomley604a3e32005-10-29 10:28:33 -05003609 lpfc_sli_release_iocbq(phba, cmdiocb);
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003610 return;
3611}
3612
dea31012005-04-17 16:05:31 -05003613int
James Smart51ef4c22007-08-02 11:10:31 -04003614lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3615 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
dea31012005-04-17 16:05:31 -05003616{
James Smart51ef4c22007-08-02 11:10:31 -04003617 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003618 struct lpfc_iocbq *iocbq;
3619 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05003620 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003621 int errcnt = 0, ret_val = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003622 int i;
dea31012005-04-17 16:05:31 -05003623
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003624 for (i = 1; i <= phba->sli.last_iotag; i++) {
3625 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05003626
James Smart51ef4c22007-08-02 11:10:31 -04003627 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
James Smart2e0fef82007-06-17 19:56:36 -05003628 abort_cmd) != 0)
dea31012005-04-17 16:05:31 -05003629 continue;
3630
3631 /* issue ABTS for this IOCB based on iotag */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003632 abtsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003633 if (abtsiocb == NULL) {
3634 errcnt++;
3635 continue;
3636 }
dea31012005-04-17 16:05:31 -05003637
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003638 cmd = &iocbq->iocb;
dea31012005-04-17 16:05:31 -05003639 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3640 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3641 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3642 abtsiocb->iocb.ulpLe = 1;
3643 abtsiocb->iocb.ulpClass = cmd->ulpClass;
James Smart2e0fef82007-06-17 19:56:36 -05003644 abtsiocb->vport = phba->pport;
dea31012005-04-17 16:05:31 -05003645
James Smart2e0fef82007-06-17 19:56:36 -05003646 if (lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05003647 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3648 else
3649 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3650
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003651 /* Setup callback routine and issue the command. */
3652 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
dea31012005-04-17 16:05:31 -05003653 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3654 if (ret_val == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -05003655 lpfc_sli_release_iocbq(phba, abtsiocb);
dea31012005-04-17 16:05:31 -05003656 errcnt++;
3657 continue;
3658 }
3659 }
3660
3661 return errcnt;
3662}
3663
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003664static void
3665lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3666 struct lpfc_iocbq *cmdiocbq,
3667 struct lpfc_iocbq *rspiocbq)
dea31012005-04-17 16:05:31 -05003668{
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003669 wait_queue_head_t *pdone_q;
3670 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003671
James Smart2e0fef82007-06-17 19:56:36 -05003672 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003673 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3674 if (cmdiocbq->context2 && rspiocbq)
3675 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3676 &rspiocbq->iocb, sizeof(IOCB_t));
3677
3678 pdone_q = cmdiocbq->context_un.wait_queue;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003679 if (pdone_q)
3680 wake_up(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -05003681 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003682 return;
3683}
3684
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003685/*
3686 * Issue the caller's iocb and wait for its completion, but no longer than the
3687 * caller's timeout. Note that iocb_flags is cleared before the
3688 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3689 * definition this is a wait function.
3690 */
James Smart92d7f7b2007-06-17 19:56:38 -05003691
dea31012005-04-17 16:05:31 -05003692int
James Smart2e0fef82007-06-17 19:56:36 -05003693lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3694 struct lpfc_sli_ring *pring,
3695 struct lpfc_iocbq *piocb,
3696 struct lpfc_iocbq *prspiocbq,
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003697 uint32_t timeout)
dea31012005-04-17 16:05:31 -05003698{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003699 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003700 long timeleft, timeout_req = 0;
3701 int retval = IOCB_SUCCESS;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003702 uint32_t creg_val;
dea31012005-04-17 16:05:31 -05003703
3704 /*
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003705 * If the caller has provided a response iocbq buffer, then context2
3706 * is NULL or its an error.
dea31012005-04-17 16:05:31 -05003707 */
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003708 if (prspiocbq) {
3709 if (piocb->context2)
3710 return IOCB_ERROR;
3711 piocb->context2 = prspiocbq;
dea31012005-04-17 16:05:31 -05003712 }
3713
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003714 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3715 piocb->context_un.wait_queue = &done_q;
3716 piocb->iocb_flag &= ~LPFC_IO_WAKE;
dea31012005-04-17 16:05:31 -05003717
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003718 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3719 creg_val = readl(phba->HCregaddr);
3720 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3721 writel(creg_val, phba->HCregaddr);
3722 readl(phba->HCregaddr); /* flush */
3723 }
3724
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003725 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3726 if (retval == IOCB_SUCCESS) {
3727 timeout_req = timeout * HZ;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003728 timeleft = wait_event_timeout(done_q,
3729 piocb->iocb_flag & LPFC_IO_WAKE,
3730 timeout_req);
dea31012005-04-17 16:05:31 -05003731
James Smart7054a602007-04-25 09:52:34 -04003732 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3733 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003734 "0331 IOCB wake signaled\n");
James Smart7054a602007-04-25 09:52:34 -04003735 } else if (timeleft == 0) {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003736 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003737 "0338 IOCB wait timeout error - no "
3738 "wake response Data x%x\n", timeout);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003739 retval = IOCB_TIMEDOUT;
James Smart7054a602007-04-25 09:52:34 -04003740 } else {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003741 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003742 "0330 IOCB wake NOT set, "
3743 "Data x%x x%lx\n",
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003744 timeout, (timeleft / jiffies));
3745 retval = IOCB_TIMEDOUT;
dea31012005-04-17 16:05:31 -05003746 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003747 } else {
3748 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003749 ":0332 IOCB wait issue failed, Data x%x\n",
3750 retval);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003751 retval = IOCB_ERROR;
dea31012005-04-17 16:05:31 -05003752 }
3753
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003754 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3755 creg_val = readl(phba->HCregaddr);
3756 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3757 writel(creg_val, phba->HCregaddr);
3758 readl(phba->HCregaddr); /* flush */
3759 }
3760
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003761 if (prspiocbq)
3762 piocb->context2 = NULL;
3763
3764 piocb->context_un.wait_queue = NULL;
3765 piocb->iocb_cmpl = NULL;
dea31012005-04-17 16:05:31 -05003766 return retval;
3767}
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003768
dea31012005-04-17 16:05:31 -05003769int
James Smart2e0fef82007-06-17 19:56:36 -05003770lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
dea31012005-04-17 16:05:31 -05003771 uint32_t timeout)
3772{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003773 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
dea31012005-04-17 16:05:31 -05003774 int retval;
James Smart858c9f62007-06-17 19:56:39 -05003775 unsigned long flag;
dea31012005-04-17 16:05:31 -05003776
3777 /* The caller must leave context1 empty. */
James Smart92d7f7b2007-06-17 19:56:38 -05003778 if (pmboxq->context1 != 0)
James Smart2e0fef82007-06-17 19:56:36 -05003779 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05003780
3781 /* setup wake call as IOCB callback */
3782 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3783 /* setup context field to pass wait_queue pointer to wake function */
3784 pmboxq->context1 = &done_q;
3785
dea31012005-04-17 16:05:31 -05003786 /* now issue the command */
3787 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3788
3789 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
James Smart7054a602007-04-25 09:52:34 -04003790 wait_event_interruptible_timeout(done_q,
3791 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3792 timeout * HZ);
3793
James Smart858c9f62007-06-17 19:56:39 -05003794 spin_lock_irqsave(&phba->hbalock, flag);
dea31012005-04-17 16:05:31 -05003795 pmboxq->context1 = NULL;
James Smart7054a602007-04-25 09:52:34 -04003796 /*
3797 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3798 * else do not free the resources.
3799 */
3800 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
dea31012005-04-17 16:05:31 -05003801 retval = MBX_SUCCESS;
James Smart858c9f62007-06-17 19:56:39 -05003802 else {
James Smart7054a602007-04-25 09:52:34 -04003803 retval = MBX_TIMEOUT;
James Smart858c9f62007-06-17 19:56:39 -05003804 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3805 }
3806 spin_unlock_irqrestore(&phba->hbalock, flag);
dea31012005-04-17 16:05:31 -05003807 }
3808
dea31012005-04-17 16:05:31 -05003809 return retval;
3810}
3811
James Smartb4c02652006-07-06 15:50:43 -04003812int
3813lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3814{
James Smart2e0fef82007-06-17 19:56:36 -05003815 struct lpfc_vport *vport = phba->pport;
James Smartb4c02652006-07-06 15:50:43 -04003816 int i = 0;
James Smarted957682007-06-17 19:56:37 -05003817 uint32_t ha_copy;
James Smartb4c02652006-07-06 15:50:43 -04003818
James Smart2e0fef82007-06-17 19:56:36 -05003819 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
James Smartb4c02652006-07-06 15:50:43 -04003820 if (i++ > LPFC_MBOX_TMO * 1000)
3821 return 1;
3822
James Smarted957682007-06-17 19:56:37 -05003823 /*
3824 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3825 * did finish. This way we won't get the misleading
3826 * "Stray Mailbox Interrupt" message.
3827 */
3828 spin_lock_irq(&phba->hbalock);
3829 ha_copy = phba->work_ha;
3830 phba->work_ha &= ~HA_MBATT;
3831 spin_unlock_irq(&phba->hbalock);
3832
3833 if (ha_copy & HA_MBATT)
3834 if (lpfc_sli_handle_mb_event(phba) == 0)
3835 i = 0;
James Smartb4c02652006-07-06 15:50:43 -04003836
3837 msleep(1);
3838 }
3839
3840 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3841}
3842
dea31012005-04-17 16:05:31 -05003843irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003844lpfc_intr_handler(int irq, void *dev_id)
dea31012005-04-17 16:05:31 -05003845{
James Smart2e0fef82007-06-17 19:56:36 -05003846 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -05003847 uint32_t ha_copy;
3848 uint32_t work_ha_copy;
3849 unsigned long status;
3850 int i;
3851 uint32_t control;
3852
James Smart92d7f7b2007-06-17 19:56:38 -05003853 MAILBOX_t *mbox, *pmbox;
James Smart858c9f62007-06-17 19:56:39 -05003854 struct lpfc_vport *vport;
3855 struct lpfc_nodelist *ndlp;
3856 struct lpfc_dmabuf *mp;
James Smart92d7f7b2007-06-17 19:56:38 -05003857 LPFC_MBOXQ_t *pmb;
3858 int rc;
3859
dea31012005-04-17 16:05:31 -05003860 /*
3861 * Get the driver's phba structure from the dev_id and
3862 * assume the HBA is not interrupting.
3863 */
3864 phba = (struct lpfc_hba *) dev_id;
3865
3866 if (unlikely(!phba))
3867 return IRQ_NONE;
3868
Linas Vepstas8d63f372007-02-14 14:28:36 -06003869 /* If the pci channel is offline, ignore all the interrupts. */
3870 if (unlikely(pci_channel_offline(phba->pcidev)))
3871 return IRQ_NONE;
3872
dea31012005-04-17 16:05:31 -05003873 phba->sli.slistat.sli_intr++;
3874
3875 /*
3876 * Call the HBA to see if it is interrupting. If not, don't claim
3877 * the interrupt
3878 */
3879
3880 /* Ignore all interrupts during initialization. */
James Smart2e0fef82007-06-17 19:56:36 -05003881 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05003882 return IRQ_NONE;
3883
3884 /*
3885 * Read host attention register to determine interrupt source
3886 * Clear Attention Sources, except Error Attention (to
3887 * preserve status) and Link Attention
3888 */
James Smart2e0fef82007-06-17 19:56:36 -05003889 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003890 ha_copy = readl(phba->HAregaddr);
James Smartebdbe652007-04-25 09:53:15 -04003891 /* If somebody is waiting to handle an eratt don't process it
3892 * here. The brdkill function will do this.
3893 */
James Smart2e0fef82007-06-17 19:56:36 -05003894 if (phba->link_flag & LS_IGNORE_ERATT)
James Smartebdbe652007-04-25 09:53:15 -04003895 ha_copy &= ~HA_ERATT;
dea31012005-04-17 16:05:31 -05003896 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3897 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003898 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003899
3900 if (unlikely(!ha_copy))
3901 return IRQ_NONE;
3902
3903 work_ha_copy = ha_copy & phba->work_ha_mask;
3904
3905 if (unlikely(work_ha_copy)) {
3906 if (work_ha_copy & HA_LATT) {
3907 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3908 /*
3909 * Turn off Link Attention interrupts
3910 * until CLEAR_LA done
3911 */
James Smart2e0fef82007-06-17 19:56:36 -05003912 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003913 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3914 control = readl(phba->HCregaddr);
3915 control &= ~HC_LAINT_ENA;
3916 writel(control, phba->HCregaddr);
3917 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003918 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003919 }
3920 else
3921 work_ha_copy &= ~HA_LATT;
3922 }
3923
3924 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
James Smart858c9f62007-06-17 19:56:39 -05003925 /*
3926 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3927 * the only slow ring.
3928 */
3929 status = (work_ha_copy &
3930 (HA_RXMASK << (4*LPFC_ELS_RING)));
3931 status >>= (4*LPFC_ELS_RING);
3932 if (status & HA_RXMASK) {
3933 spin_lock(&phba->hbalock);
3934 control = readl(phba->HCregaddr);
James Smarta58cbd52007-08-02 11:09:43 -04003935
3936 lpfc_debugfs_slow_ring_trc(phba,
3937 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
3938 control, status,
3939 (uint32_t)phba->sli.slistat.sli_intr);
3940
James Smart858c9f62007-06-17 19:56:39 -05003941 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
James Smarta58cbd52007-08-02 11:09:43 -04003942 lpfc_debugfs_slow_ring_trc(phba,
3943 "ISR Disable ring:"
3944 "pwork:x%x hawork:x%x wait:x%x",
3945 phba->work_ha, work_ha_copy,
3946 (uint32_t)((unsigned long)
3947 phba->work_wait));
3948
James Smart858c9f62007-06-17 19:56:39 -05003949 control &=
3950 ~(HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -05003951 writel(control, phba->HCregaddr);
3952 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -05003953 }
James Smarta58cbd52007-08-02 11:09:43 -04003954 else {
3955 lpfc_debugfs_slow_ring_trc(phba,
3956 "ISR slow ring: pwork:"
3957 "x%x hawork:x%x wait:x%x",
3958 phba->work_ha, work_ha_copy,
3959 (uint32_t)((unsigned long)
3960 phba->work_wait));
3961 }
James Smart858c9f62007-06-17 19:56:39 -05003962 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003963 }
3964 }
3965
3966 if (work_ha_copy & HA_ERATT) {
James Smart2e0fef82007-06-17 19:56:36 -05003967 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05003968 /*
3969 * There was a link/board error. Read the
3970 * status register to retrieve the error event
3971 * and process it.
3972 */
3973 phba->sli.slistat.err_attn_event++;
3974 /* Save status info */
3975 phba->work_hs = readl(phba->HSregaddr);
3976 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3977 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3978
3979 /* Clear Chip error bit */
3980 writel(HA_ERATT, phba->HAregaddr);
3981 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003982 phba->pport->stopped = 1;
dea31012005-04-17 16:05:31 -05003983 }
3984
James Smart92d7f7b2007-06-17 19:56:38 -05003985 if ((work_ha_copy & HA_MBATT) &&
3986 (phba->sli.mbox_active)) {
3987 pmb = phba->sli.mbox_active;
3988 pmbox = &pmb->mb;
3989 mbox = &phba->slim2p->mbx;
James Smart858c9f62007-06-17 19:56:39 -05003990 vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05003991
3992 /* First check out the status word */
3993 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
3994 if (pmbox->mbxOwner != OWN_HOST) {
3995 /*
3996 * Stray Mailbox Interrupt, mbxCommand <cmd>
3997 * mbxStatus <status>
3998 */
3999 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX |
4000 LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04004001 "(%d):0304 Stray Mailbox "
James Smart92d7f7b2007-06-17 19:56:38 -05004002 "Interrupt mbxCommand x%x "
4003 "mbxStatus x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004004 (vport ? vport->vpi : 0),
James Smart92d7f7b2007-06-17 19:56:38 -05004005 pmbox->mbxCommand,
4006 pmbox->mbxStatus);
4007 }
James Smart858c9f62007-06-17 19:56:39 -05004008 phba->last_completion_time = jiffies;
James Smart92d7f7b2007-06-17 19:56:38 -05004009 del_timer_sync(&phba->sli.mbox_tmo);
4010
James Smart92d7f7b2007-06-17 19:56:38 -05004011 phba->sli.mbox_active = NULL;
4012 if (pmb->mbox_cmpl) {
4013 lpfc_sli_pcimem_bcopy(mbox, pmbox,
4014 MAILBOX_CMD_SIZE);
4015 }
James Smart858c9f62007-06-17 19:56:39 -05004016 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
4017 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
4018
4019 lpfc_debugfs_disc_trc(vport,
4020 LPFC_DISC_TRC_MBOX_VPORT,
4021 "MBOX dflt rpi: : status:x%x rpi:x%x",
4022 (uint32_t)pmbox->mbxStatus,
4023 pmbox->un.varWords[0], 0);
4024
4025 if ( !pmbox->mbxStatus) {
4026 mp = (struct lpfc_dmabuf *)
4027 (pmb->context1);
4028 ndlp = (struct lpfc_nodelist *)
4029 pmb->context2;
4030
4031 /* Reg_LOGIN of dflt RPI was successful.
4032 * new lets get rid of the RPI using the
4033 * same mbox buffer.
4034 */
4035 lpfc_unreg_login(phba, vport->vpi,
4036 pmbox->un.varWords[0], pmb);
4037 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4038 pmb->context1 = mp;
4039 pmb->context2 = ndlp;
4040 pmb->vport = vport;
4041 spin_lock(&phba->hbalock);
4042 phba->sli.sli_flag &=
4043 ~LPFC_SLI_MBOX_ACTIVE;
4044 spin_unlock(&phba->hbalock);
4045 goto send_current_mbox;
4046 }
4047 }
4048 spin_lock(&phba->pport->work_port_lock);
4049 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
4050 spin_unlock(&phba->pport->work_port_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004051 lpfc_mbox_cmpl_put(phba, pmb);
4052 }
4053 if ((work_ha_copy & HA_MBATT) &&
4054 (phba->sli.mbox_active == NULL)) {
4055send_next_mbox:
4056 spin_lock(&phba->hbalock);
4057 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4058 pmb = lpfc_mbox_get(phba);
4059 spin_unlock(&phba->hbalock);
James Smart858c9f62007-06-17 19:56:39 -05004060send_current_mbox:
James Smart92d7f7b2007-06-17 19:56:38 -05004061 /* Process next mailbox command if there is one */
4062 if (pmb != NULL) {
4063 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4064 if (rc == MBX_NOT_FINISHED) {
4065 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
4066 lpfc_mbox_cmpl_put(phba, pmb);
4067 goto send_next_mbox;
4068 }
4069 } else {
4070 /* Turn on IOCB processing */
4071 for (i = 0; i < phba->sli.num_rings; i++)
4072 lpfc_sli_turn_on_ring(phba, i);
4073 }
4074
4075 }
4076
James Smart2e0fef82007-06-17 19:56:36 -05004077 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004078 phba->work_ha |= work_ha_copy;
4079 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05004080 lpfc_worker_wake_up(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004081 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004082 }
4083
4084 ha_copy &= ~(phba->work_ha_mask);
4085
4086 /*
4087 * Process all events on FCP ring. Take the optimized path for
4088 * FCP IO. Any other IO is slow path and is handled by
4089 * the worker thread.
4090 */
4091 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4092 status >>= (4*LPFC_FCP_RING);
James Smart858c9f62007-06-17 19:56:39 -05004093 if (status & HA_RXMASK)
dea31012005-04-17 16:05:31 -05004094 lpfc_sli_handle_fast_ring_event(phba,
4095 &phba->sli.ring[LPFC_FCP_RING],
4096 status);
James Smarta4bc3372006-12-02 13:34:16 -05004097
4098 if (phba->cfg_multi_ring_support == 2) {
4099 /*
4100 * Process all events on extra ring. Take the optimized path
4101 * for extra ring IO. Any other IO is slow path and is handled
4102 * by the worker thread.
4103 */
4104 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4105 status >>= (4*LPFC_EXTRA_RING);
James Smart858c9f62007-06-17 19:56:39 -05004106 if (status & HA_RXMASK) {
James Smarta4bc3372006-12-02 13:34:16 -05004107 lpfc_sli_handle_fast_ring_event(phba,
4108 &phba->sli.ring[LPFC_EXTRA_RING],
4109 status);
4110 }
4111 }
dea31012005-04-17 16:05:31 -05004112 return IRQ_HANDLED;
4113
4114} /* lpfc_intr_handler */