blob: 5a2cb484e1373492d6bca671dea1d13bd291077e [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
Adrian Bunka6ababd2007-11-05 18:07:33 +0100109static void
James Smart2e0fef82007-06-17 19:56:36 -0500110__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 ||
James Smart0b727fe2007-10-27 13:37:25 -0400477 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
dea31012005-04-17 16:05:31 -0500478
479 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
480 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
481 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
482
483 if (iocb)
484 lpfc_sli_update_ring(phba, pring);
485 else
486 lpfc_sli_update_full_ring(phba, pring);
487 }
488
489 return;
490}
491
Adrian Bunka6ababd2007-11-05 18:07:33 +0100492static struct lpfc_hbq_entry *
James Smarted957682007-06-17 19:56:37 -0500493lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
494{
495 struct hbq_s *hbqp = &phba->hbqs[hbqno];
496
497 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
498 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
499 hbqp->next_hbqPutIdx = 0;
500
501 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500502 uint32_t raw_index = phba->hbq_get[hbqno];
James Smarted957682007-06-17 19:56:37 -0500503 uint32_t getidx = le32_to_cpu(raw_index);
504
505 hbqp->local_hbqGetIdx = getidx;
506
507 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
508 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -0500509 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400510 "1802 HBQ %d: local_hbqGetIdx "
James Smarted957682007-06-17 19:56:37 -0500511 "%u is > than hbqp->entry_count %u\n",
James Smarte8b62012007-08-02 11:10:09 -0400512 hbqno, hbqp->local_hbqGetIdx,
James Smarted957682007-06-17 19:56:37 -0500513 hbqp->entry_count);
514
515 phba->link_state = LPFC_HBA_ERROR;
516 return NULL;
517 }
518
519 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
520 return NULL;
521 }
522
James Smart51ef4c22007-08-02 11:10:31 -0400523 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
524 hbqp->hbqPutIdx;
James Smarted957682007-06-17 19:56:37 -0500525}
526
527void
528lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
529{
James Smart92d7f7b2007-06-17 19:56:38 -0500530 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
531 struct hbq_dmabuf *hbq_buf;
James Smart51ef4c22007-08-02 11:10:31 -0400532 int i, hbq_count;
James Smarted957682007-06-17 19:56:37 -0500533
James Smart51ef4c22007-08-02 11:10:31 -0400534 hbq_count = lpfc_sli_hbq_count();
James Smarted957682007-06-17 19:56:37 -0500535 /* Return all memory used by all HBQs */
James Smart51ef4c22007-08-02 11:10:31 -0400536 for (i = 0; i < hbq_count; ++i) {
537 list_for_each_entry_safe(dmabuf, next_dmabuf,
538 &phba->hbqs[i].hbq_buffer_list, list) {
539 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
540 list_del(&hbq_buf->dbuf.list);
541 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
542 }
James Smarta8adb832007-10-27 13:37:53 -0400543 phba->hbqs[i].buffer_count = 0;
James Smarted957682007-06-17 19:56:37 -0500544 }
James Smarted957682007-06-17 19:56:37 -0500545}
546
James Smart51ef4c22007-08-02 11:10:31 -0400547static struct lpfc_hbq_entry *
James Smarted957682007-06-17 19:56:37 -0500548lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
James Smart92d7f7b2007-06-17 19:56:38 -0500549 struct hbq_dmabuf *hbq_buf)
James Smarted957682007-06-17 19:56:37 -0500550{
551 struct lpfc_hbq_entry *hbqe;
James Smart92d7f7b2007-06-17 19:56:38 -0500552 dma_addr_t physaddr = hbq_buf->dbuf.phys;
James Smarted957682007-06-17 19:56:37 -0500553
554 /* Get next HBQ entry slot to use */
555 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
556 if (hbqe) {
557 struct hbq_s *hbqp = &phba->hbqs[hbqno];
558
James Smart92d7f7b2007-06-17 19:56:38 -0500559 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
560 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
James Smart51ef4c22007-08-02 11:10:31 -0400561 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
James Smarted957682007-06-17 19:56:37 -0500562 hbqe->bde.tus.f.bdeFlags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500563 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
564 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
565 /* Sync SLIM */
James Smarted957682007-06-17 19:56:37 -0500566 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
567 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
James Smart92d7f7b2007-06-17 19:56:38 -0500568 /* flush */
James Smarted957682007-06-17 19:56:37 -0500569 readl(phba->hbq_put + hbqno);
James Smart51ef4c22007-08-02 11:10:31 -0400570 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
James Smarted957682007-06-17 19:56:37 -0500571 }
James Smart51ef4c22007-08-02 11:10:31 -0400572 return hbqe;
James Smarted957682007-06-17 19:56:37 -0500573}
574
James Smart92d7f7b2007-06-17 19:56:38 -0500575static struct lpfc_hbq_init lpfc_els_hbq = {
576 .rn = 1,
577 .entry_count = 200,
578 .mask_count = 0,
579 .profile = 0,
James Smart51ef4c22007-08-02 11:10:31 -0400580 .ring_mask = (1 << LPFC_ELS_RING),
James Smart92d7f7b2007-06-17 19:56:38 -0500581 .buffer_count = 0,
582 .init_count = 20,
583 .add_count = 5,
584};
James Smarted957682007-06-17 19:56:37 -0500585
James Smart51ef4c22007-08-02 11:10:31 -0400586static struct lpfc_hbq_init lpfc_extra_hbq = {
587 .rn = 1,
588 .entry_count = 200,
589 .mask_count = 0,
590 .profile = 0,
591 .ring_mask = (1 << LPFC_EXTRA_RING),
592 .buffer_count = 0,
593 .init_count = 0,
594 .add_count = 5,
595};
596
James Smart78b2d852007-08-02 11:10:21 -0400597struct lpfc_hbq_init *lpfc_hbq_defs[] = {
James Smart92d7f7b2007-06-17 19:56:38 -0500598 &lpfc_els_hbq,
James Smart51ef4c22007-08-02 11:10:31 -0400599 &lpfc_extra_hbq,
James Smart92d7f7b2007-06-17 19:56:38 -0500600};
601
James Smart311464e2007-08-02 11:10:37 -0400602static int
James Smart92d7f7b2007-06-17 19:56:38 -0500603lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
604{
605 uint32_t i, start, end;
606 struct hbq_dmabuf *hbq_buffer;
607
James Smart51ef4c22007-08-02 11:10:31 -0400608 if (!phba->hbqs[hbqno].hbq_alloc_buffer) {
609 return 0;
610 }
611
James Smarta8adb832007-10-27 13:37:53 -0400612 start = phba->hbqs[hbqno].buffer_count;
613 end = count + start;
James Smart92d7f7b2007-06-17 19:56:38 -0500614 if (end > lpfc_hbq_defs[hbqno]->entry_count) {
615 end = lpfc_hbq_defs[hbqno]->entry_count;
James Smarted957682007-06-17 19:56:37 -0500616 }
James Smart92d7f7b2007-06-17 19:56:38 -0500617
618 /* Populate HBQ entries */
619 for (i = start; i < end; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400620 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500621 if (!hbq_buffer)
622 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500623 hbq_buffer->tag = (i | (hbqno << 16));
James Smart51ef4c22007-08-02 11:10:31 -0400624 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
James Smarta8adb832007-10-27 13:37:53 -0400625 phba->hbqs[hbqno].buffer_count++;
James Smart51ef4c22007-08-02 11:10:31 -0400626 else
627 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
James Smart92d7f7b2007-06-17 19:56:38 -0500628 }
629 return 0;
James Smarted957682007-06-17 19:56:37 -0500630}
631
632int
James Smart92d7f7b2007-06-17 19:56:38 -0500633lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -0500634{
James Smart92d7f7b2007-06-17 19:56:38 -0500635 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
636 lpfc_hbq_defs[qno]->add_count));
James Smarted957682007-06-17 19:56:37 -0500637}
638
Adrian Bunka6ababd2007-11-05 18:07:33 +0100639static int
James Smart92d7f7b2007-06-17 19:56:38 -0500640lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -0500641{
James Smart92d7f7b2007-06-17 19:56:38 -0500642 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
643 lpfc_hbq_defs[qno]->init_count));
James Smarted957682007-06-17 19:56:37 -0500644}
645
Adrian Bunka6ababd2007-11-05 18:07:33 +0100646static struct hbq_dmabuf *
James Smarted957682007-06-17 19:56:37 -0500647lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
648{
James Smart92d7f7b2007-06-17 19:56:38 -0500649 struct lpfc_dmabuf *d_buf;
650 struct hbq_dmabuf *hbq_buf;
James Smart51ef4c22007-08-02 11:10:31 -0400651 uint32_t hbqno;
James Smarted957682007-06-17 19:56:37 -0500652
James Smart51ef4c22007-08-02 11:10:31 -0400653 hbqno = tag >> 16;
Jesper Juhla0a74e452007-08-09 20:47:15 +0200654 if (hbqno >= LPFC_MAX_HBQS)
James Smart51ef4c22007-08-02 11:10:31 -0400655 return NULL;
656
657 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
James Smart92d7f7b2007-06-17 19:56:38 -0500658 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
James Smart51ef4c22007-08-02 11:10:31 -0400659 if (hbq_buf->tag == tag) {
James Smart92d7f7b2007-06-17 19:56:38 -0500660 return hbq_buf;
James Smarted957682007-06-17 19:56:37 -0500661 }
662 }
James Smart92d7f7b2007-06-17 19:56:38 -0500663 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400664 "1803 Bad hbq tag. Data: x%x x%x\n",
James Smarta8adb832007-10-27 13:37:53 -0400665 tag, phba->hbqs[tag >> 16].buffer_count);
James Smart92d7f7b2007-06-17 19:56:38 -0500666 return NULL;
James Smarted957682007-06-17 19:56:37 -0500667}
668
669void
James Smart51ef4c22007-08-02 11:10:31 -0400670lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
James Smarted957682007-06-17 19:56:37 -0500671{
672 uint32_t hbqno;
673
James Smart51ef4c22007-08-02 11:10:31 -0400674 if (hbq_buffer) {
675 hbqno = hbq_buffer->tag >> 16;
676 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
677 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
678 }
James Smarted957682007-06-17 19:56:37 -0500679 }
680}
681
dea31012005-04-17 16:05:31 -0500682static int
683lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
684{
685 uint8_t ret;
686
687 switch (mbxCommand) {
688 case MBX_LOAD_SM:
689 case MBX_READ_NV:
690 case MBX_WRITE_NV:
James Smarta8adb832007-10-27 13:37:53 -0400691 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -0500692 case MBX_RUN_BIU_DIAG:
693 case MBX_INIT_LINK:
694 case MBX_DOWN_LINK:
695 case MBX_CONFIG_LINK:
696 case MBX_CONFIG_RING:
697 case MBX_RESET_RING:
698 case MBX_READ_CONFIG:
699 case MBX_READ_RCONFIG:
700 case MBX_READ_SPARM:
701 case MBX_READ_STATUS:
702 case MBX_READ_RPI:
703 case MBX_READ_XRI:
704 case MBX_READ_REV:
705 case MBX_READ_LNK_STAT:
706 case MBX_REG_LOGIN:
707 case MBX_UNREG_LOGIN:
708 case MBX_READ_LA:
709 case MBX_CLEAR_LA:
710 case MBX_DUMP_MEMORY:
711 case MBX_DUMP_CONTEXT:
712 case MBX_RUN_DIAGS:
713 case MBX_RESTART:
714 case MBX_UPDATE_CFG:
715 case MBX_DOWN_LOAD:
716 case MBX_DEL_LD_ENTRY:
717 case MBX_RUN_PROGRAM:
718 case MBX_SET_MASK:
James Smart09372822008-01-11 01:52:54 -0500719 case MBX_SET_VARIABLE:
dea31012005-04-17 16:05:31 -0500720 case MBX_UNREG_D_ID:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500721 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -0500722 case MBX_CONFIG_FARP:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500723 case MBX_BEACON:
dea31012005-04-17 16:05:31 -0500724 case MBX_LOAD_AREA:
725 case MBX_RUN_BIU_DIAG64:
726 case MBX_CONFIG_PORT:
727 case MBX_READ_SPARM64:
728 case MBX_READ_RPI64:
729 case MBX_REG_LOGIN64:
730 case MBX_READ_LA64:
James Smart09372822008-01-11 01:52:54 -0500731 case MBX_WRITE_WWN:
dea31012005-04-17 16:05:31 -0500732 case MBX_SET_DEBUG:
733 case MBX_LOAD_EXP_ROM:
James Smart57127f12007-10-27 13:37:05 -0400734 case MBX_ASYNCEVT_ENABLE:
James Smart92d7f7b2007-06-17 19:56:38 -0500735 case MBX_REG_VPI:
736 case MBX_UNREG_VPI:
James Smart858c9f62007-06-17 19:56:39 -0500737 case MBX_HEARTBEAT:
dea31012005-04-17 16:05:31 -0500738 ret = mbxCommand;
739 break;
740 default:
741 ret = MBX_SHUTDOWN;
742 break;
743 }
James Smart2e0fef82007-06-17 19:56:36 -0500744 return ret;
dea31012005-04-17 16:05:31 -0500745}
746static void
James Smart2e0fef82007-06-17 19:56:36 -0500747lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
dea31012005-04-17 16:05:31 -0500748{
749 wait_queue_head_t *pdone_q;
James Smart858c9f62007-06-17 19:56:39 -0500750 unsigned long drvr_flag;
dea31012005-04-17 16:05:31 -0500751
752 /*
753 * If pdone_q is empty, the driver thread gave up waiting and
754 * continued running.
755 */
James Smart7054a602007-04-25 09:52:34 -0400756 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
James Smart858c9f62007-06-17 19:56:39 -0500757 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -0500758 pdone_q = (wait_queue_head_t *) pmboxq->context1;
759 if (pdone_q)
760 wake_up_interruptible(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -0500761 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -0500762 return;
763}
764
765void
James Smart2e0fef82007-06-17 19:56:36 -0500766lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500767{
768 struct lpfc_dmabuf *mp;
James Smart7054a602007-04-25 09:52:34 -0400769 uint16_t rpi;
770 int rc;
771
dea31012005-04-17 16:05:31 -0500772 mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart7054a602007-04-25 09:52:34 -0400773
dea31012005-04-17 16:05:31 -0500774 if (mp) {
775 lpfc_mbuf_free(phba, mp->virt, mp->phys);
776 kfree(mp);
777 }
James Smart7054a602007-04-25 09:52:34 -0400778
779 /*
780 * If a REG_LOGIN succeeded after node is destroyed or node
781 * is in re-discovery driver need to cleanup the RPI.
782 */
James Smart2e0fef82007-06-17 19:56:36 -0500783 if (!(phba->pport->load_flag & FC_UNLOADING) &&
784 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
785 !pmb->mb.mbxStatus) {
James Smart7054a602007-04-25 09:52:34 -0400786
787 rpi = pmb->mb.un.varWords[0];
James Smart92d7f7b2007-06-17 19:56:38 -0500788 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
789 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart7054a602007-04-25 09:52:34 -0400790 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
791 if (rc != MBX_NOT_FINISHED)
792 return;
793 }
794
James Smart2e0fef82007-06-17 19:56:36 -0500795 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500796 return;
797}
798
799int
James Smart2e0fef82007-06-17 19:56:36 -0500800lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500801{
James Smart92d7f7b2007-06-17 19:56:38 -0500802 MAILBOX_t *pmbox;
dea31012005-04-17 16:05:31 -0500803 LPFC_MBOXQ_t *pmb;
James Smart92d7f7b2007-06-17 19:56:38 -0500804 int rc;
805 LIST_HEAD(cmplq);
dea31012005-04-17 16:05:31 -0500806
807 phba->sli.slistat.mbox_event++;
808
James Smart92d7f7b2007-06-17 19:56:38 -0500809 /* Get all completed mailboxe buffers into the cmplq */
810 spin_lock_irq(&phba->hbalock);
811 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
812 spin_unlock_irq(&phba->hbalock);
813
dea31012005-04-17 16:05:31 -0500814 /* Get a Mailbox buffer to setup mailbox commands for callback */
James Smart92d7f7b2007-06-17 19:56:38 -0500815 do {
816 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
817 if (pmb == NULL)
818 break;
819
dea31012005-04-17 16:05:31 -0500820 pmbox = &pmb->mb;
dea31012005-04-17 16:05:31 -0500821
James Smart858c9f62007-06-17 19:56:39 -0500822 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
823 if (pmb->vport) {
824 lpfc_debugfs_disc_trc(pmb->vport,
825 LPFC_DISC_TRC_MBOX_VPORT,
826 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
827 (uint32_t)pmbox->mbxCommand,
828 pmbox->un.varWords[0],
829 pmbox->un.varWords[1]);
830 }
831 else {
832 lpfc_debugfs_disc_trc(phba->pport,
833 LPFC_DISC_TRC_MBOX,
834 "MBOX cmpl: cmd:x%x mb:x%x x%x",
835 (uint32_t)pmbox->mbxCommand,
836 pmbox->un.varWords[0],
837 pmbox->un.varWords[1]);
838 }
839 }
840
dea31012005-04-17 16:05:31 -0500841 /*
842 * It is a fatal error if unknown mbox command completion.
843 */
844 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
845 MBX_SHUTDOWN) {
dea31012005-04-17 16:05:31 -0500846 /* Unknow mailbox command compl */
James Smart92d7f7b2007-06-17 19:56:38 -0500847 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400848 "(%d):0323 Unknown Mailbox command "
James Smart92d7f7b2007-06-17 19:56:38 -0500849 "%x Cmpl\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500850 pmb->vport ? pmb->vport->vpi : 0,
851 pmbox->mbxCommand);
James Smart2e0fef82007-06-17 19:56:36 -0500852 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500853 phba->work_hs = HS_FFER3;
854 lpfc_handle_eratt(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500855 continue;
dea31012005-04-17 16:05:31 -0500856 }
857
dea31012005-04-17 16:05:31 -0500858 if (pmbox->mbxStatus) {
859 phba->sli.slistat.mbox_stat_err++;
860 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
861 /* Mbox cmd cmpl error - RETRYing */
James Smart92d7f7b2007-06-17 19:56:38 -0500862 lpfc_printf_log(phba, KERN_INFO,
863 LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400864 "(%d):0305 Mbox cmd cmpl "
James Smart92d7f7b2007-06-17 19:56:38 -0500865 "error - RETRYing Data: x%x "
866 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500867 pmb->vport ? pmb->vport->vpi :0,
868 pmbox->mbxCommand,
869 pmbox->mbxStatus,
870 pmbox->un.varWords[0],
871 pmb->vport->port_state);
dea31012005-04-17 16:05:31 -0500872 pmbox->mbxStatus = 0;
873 pmbox->mbxOwner = OWN_HOST;
James Smart2e0fef82007-06-17 19:56:36 -0500874 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500875 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -0500876 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500877 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
878 if (rc == MBX_SUCCESS)
James Smart92d7f7b2007-06-17 19:56:38 -0500879 continue;
dea31012005-04-17 16:05:31 -0500880 }
881 }
882
883 /* Mailbox cmd <cmd> Cmpl <cmpl> */
James Smart92d7f7b2007-06-17 19:56:38 -0500884 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -0400885 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
dea31012005-04-17 16:05:31 -0500886 "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 -0500887 pmb->vport ? pmb->vport->vpi : 0,
dea31012005-04-17 16:05:31 -0500888 pmbox->mbxCommand,
889 pmb->mbox_cmpl,
890 *((uint32_t *) pmbox),
891 pmbox->un.varWords[0],
892 pmbox->un.varWords[1],
893 pmbox->un.varWords[2],
894 pmbox->un.varWords[3],
895 pmbox->un.varWords[4],
896 pmbox->un.varWords[5],
897 pmbox->un.varWords[6],
898 pmbox->un.varWords[7]);
899
James Smart92d7f7b2007-06-17 19:56:38 -0500900 if (pmb->mbox_cmpl)
dea31012005-04-17 16:05:31 -0500901 pmb->mbox_cmpl(phba,pmb);
James Smart92d7f7b2007-06-17 19:56:38 -0500902 } while (1);
James Smart2e0fef82007-06-17 19:56:36 -0500903 return 0;
dea31012005-04-17 16:05:31 -0500904}
James Smart92d7f7b2007-06-17 19:56:38 -0500905
906static struct lpfc_dmabuf *
907lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
908{
909 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
James Smart51ef4c22007-08-02 11:10:31 -0400910 uint32_t hbqno;
911 void *virt; /* virtual address ptr */
912 dma_addr_t phys; /* mapped address */
James Smart92d7f7b2007-06-17 19:56:38 -0500913
914 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
915 if (hbq_entry == NULL)
916 return NULL;
917 list_del(&hbq_entry->dbuf.list);
James Smart51ef4c22007-08-02 11:10:31 -0400918
919 hbqno = tag >> 16;
920 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500921 if (new_hbq_entry == NULL)
922 return &hbq_entry->dbuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500923 new_hbq_entry->tag = -1;
James Smart51ef4c22007-08-02 11:10:31 -0400924 phys = new_hbq_entry->dbuf.phys;
925 virt = new_hbq_entry->dbuf.virt;
926 new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
927 new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
928 hbq_entry->dbuf.phys = phys;
929 hbq_entry->dbuf.virt = virt;
James Smart92d7f7b2007-06-17 19:56:38 -0500930 lpfc_sli_free_hbq(phba, hbq_entry);
931 return &new_hbq_entry->dbuf;
932}
933
James Smart76bb24e2007-10-27 13:38:00 -0400934static struct lpfc_dmabuf *
935lpfc_sli_get_buff(struct lpfc_hba *phba,
936 struct lpfc_sli_ring *pring,
937 uint32_t tag)
938{
939 if (tag & QUE_BUFTAG_BIT)
940 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
941 else
942 return lpfc_sli_replace_hbqbuff(phba, tag);
943}
James Smart57127f12007-10-27 13:37:05 -0400944
dea31012005-04-17 16:05:31 -0500945static int
946lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
947 struct lpfc_iocbq *saveq)
948{
949 IOCB_t * irsp;
950 WORD5 * w5p;
951 uint32_t Rctl, Type;
952 uint32_t match, i;
James Smart76bb24e2007-10-27 13:38:00 -0400953 struct lpfc_iocbq *iocbq;
dea31012005-04-17 16:05:31 -0500954
955 match = 0;
956 irsp = &(saveq->iocb);
James Smart57127f12007-10-27 13:37:05 -0400957
958 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
959 if (pring->lpfc_sli_rcv_async_status)
960 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
961 else
962 lpfc_printf_log(phba,
963 KERN_WARNING,
964 LOG_SLI,
965 "0316 Ring %d handler: unexpected "
966 "ASYNC_STATUS iocb received evt_code "
967 "0x%x\n",
968 pring->ringno,
969 irsp->un.asyncstat.evt_code);
970 return 1;
971 }
972
dea31012005-04-17 16:05:31 -0500973 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
James Smarted957682007-06-17 19:56:37 -0500974 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
975 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
976 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
dea31012005-04-17 16:05:31 -0500977 Rctl = FC_ELS_REQ;
978 Type = FC_ELS_DATA;
979 } else {
980 w5p =
981 (WORD5 *) & (saveq->iocb.un.
982 ulpWord[5]);
983 Rctl = w5p->hcsw.Rctl;
984 Type = w5p->hcsw.Type;
985
986 /* Firmware Workaround */
987 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
James Smart92d7f7b2007-06-17 19:56:38 -0500988 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
989 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
dea31012005-04-17 16:05:31 -0500990 Rctl = FC_ELS_REQ;
991 Type = FC_ELS_DATA;
992 w5p->hcsw.Rctl = Rctl;
993 w5p->hcsw.Type = Type;
994 }
995 }
James Smart92d7f7b2007-06-17 19:56:38 -0500996
997 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart76bb24e2007-10-27 13:38:00 -0400998 struct lpfc_hbq_entry *hbqe_1, *hbqe_2;
999 hbqe_1 = (struct lpfc_hbq_entry *) &saveq->iocb.un.ulpWord[0];
1000 hbqe_2 = (struct lpfc_hbq_entry *) &saveq->iocb.
1001 unsli3.sli3Words[4];
1002
1003 if (irsp->ulpBdeCount != 0) {
1004 saveq->context2 = lpfc_sli_get_buff(phba, pring,
James Smart92d7f7b2007-06-17 19:56:38 -05001005 irsp->un.ulpWord[3]);
James Smart76bb24e2007-10-27 13:38:00 -04001006 if (!saveq->context2)
1007 lpfc_printf_log(phba,
1008 KERN_ERR,
1009 LOG_SLI,
1010 "0341 Ring %d Cannot find buffer for "
1011 "an unsolicited iocb. tag 0x%x\n",
1012 pring->ringno,
1013 irsp->un.ulpWord[3]);
1014
1015 }
1016 if (irsp->ulpBdeCount == 2) {
1017 saveq->context3 = lpfc_sli_get_buff(phba, pring,
James Smart51ef4c22007-08-02 11:10:31 -04001018 irsp->unsli3.sli3Words[7]);
James Smart76bb24e2007-10-27 13:38:00 -04001019 if (!saveq->context3)
1020 lpfc_printf_log(phba,
1021 KERN_ERR,
1022 LOG_SLI,
1023 "0342 Ring %d Cannot find buffer for an"
1024 " unsolicited iocb. tag 0x%x\n",
1025 pring->ringno,
1026 irsp->unsli3.sli3Words[7]);
1027 }
1028 list_for_each_entry(iocbq, &saveq->list, list) {
1029 hbqe_1 = (struct lpfc_hbq_entry *) &iocbq->iocb.
1030 un.ulpWord[0];
1031 hbqe_2 = (struct lpfc_hbq_entry *) &iocbq->iocb.
1032 unsli3.sli3Words[4];
1033 irsp = &(iocbq->iocb);
1034
1035 if (irsp->ulpBdeCount != 0) {
1036 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
1037 irsp->un.ulpWord[3]);
1038 if (!saveq->context2)
1039 lpfc_printf_log(phba,
1040 KERN_ERR,
1041 LOG_SLI,
1042 "0343 Ring %d Cannot find "
1043 "buffer for an unsolicited iocb"
1044 ". tag 0x%x\n", pring->ringno,
1045 irsp->un.ulpWord[3]);
1046 }
1047 if (irsp->ulpBdeCount == 2) {
1048 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
1049 irsp->unsli3.sli3Words[7]);
1050 if (!saveq->context3)
1051 lpfc_printf_log(phba,
1052 KERN_ERR,
1053 LOG_SLI,
1054 "0344 Ring %d Cannot find "
1055 "buffer for an unsolicited "
1056 "iocb. tag 0x%x\n",
1057 pring->ringno,
1058 irsp->unsli3.sli3Words[7]);
1059 }
1060 }
James Smart92d7f7b2007-06-17 19:56:38 -05001061 }
1062
dea31012005-04-17 16:05:31 -05001063 /* unSolicited Responses */
1064 if (pring->prt[0].profile) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001065 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1066 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1067 saveq);
dea31012005-04-17 16:05:31 -05001068 match = 1;
1069 } else {
1070 /* We must search, based on rctl / type
1071 for the right routine */
1072 for (i = 0; i < pring->num_mask;
1073 i++) {
1074 if ((pring->prt[i].rctl ==
1075 Rctl)
1076 && (pring->prt[i].
1077 type == Type)) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001078 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1079 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1080 (phba, pring, saveq);
dea31012005-04-17 16:05:31 -05001081 match = 1;
1082 break;
1083 }
1084 }
1085 }
1086 if (match == 0) {
1087 /* Unexpected Rctl / Type received */
1088 /* Ring <ringno> handler: unexpected
1089 Rctl <Rctl> Type <Type> received */
James Smart92d7f7b2007-06-17 19:56:38 -05001090 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001091 "0313 Ring %d handler: unexpected Rctl x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05001092 "Type x%x received\n",
James Smarte8b62012007-08-02 11:10:09 -04001093 pring->ringno, Rctl, Type);
dea31012005-04-17 16:05:31 -05001094 }
James Smart92d7f7b2007-06-17 19:56:38 -05001095 return 1;
dea31012005-04-17 16:05:31 -05001096}
1097
1098static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -05001099lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1100 struct lpfc_sli_ring *pring,
1101 struct lpfc_iocbq *prspiocb)
dea31012005-04-17 16:05:31 -05001102{
dea31012005-04-17 16:05:31 -05001103 struct lpfc_iocbq *cmd_iocb = NULL;
1104 uint16_t iotag;
1105
James Bottomley604a3e32005-10-29 10:28:33 -05001106 iotag = prspiocb->iocb.ulpIoTag;
dea31012005-04-17 16:05:31 -05001107
James Bottomley604a3e32005-10-29 10:28:33 -05001108 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1109 cmd_iocb = phba->sli.iocbq_lookup[iotag];
James Smart92d7f7b2007-06-17 19:56:38 -05001110 list_del_init(&cmd_iocb->list);
James Bottomley604a3e32005-10-29 10:28:33 -05001111 pring->txcmplq_cnt--;
1112 return cmd_iocb;
dea31012005-04-17 16:05:31 -05001113 }
1114
dea31012005-04-17 16:05:31 -05001115 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001116 "0317 iotag x%x is out off "
James Bottomley604a3e32005-10-29 10:28:33 -05001117 "range: max iotag x%x wd0 x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001118 iotag, phba->sli.last_iotag,
James Bottomley604a3e32005-10-29 10:28:33 -05001119 *(((uint32_t *) &prspiocb->iocb) + 7));
dea31012005-04-17 16:05:31 -05001120 return NULL;
1121}
1122
1123static int
James Smart2e0fef82007-06-17 19:56:36 -05001124lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05001125 struct lpfc_iocbq *saveq)
1126{
James Smart2e0fef82007-06-17 19:56:36 -05001127 struct lpfc_iocbq *cmdiocbp;
dea31012005-04-17 16:05:31 -05001128 int rc = 1;
1129 unsigned long iflag;
1130
1131 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
James Smart2e0fef82007-06-17 19:56:36 -05001132 spin_lock_irqsave(&phba->hbalock, iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001133 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
James Smart2e0fef82007-06-17 19:56:36 -05001134 spin_unlock_irqrestore(&phba->hbalock, iflag);
1135
dea31012005-04-17 16:05:31 -05001136 if (cmdiocbp) {
1137 if (cmdiocbp->iocb_cmpl) {
1138 /*
1139 * Post all ELS completions to the worker thread.
1140 * All other are passed to the completion callback.
1141 */
1142 if (pring->ringno == LPFC_ELS_RING) {
James Smart07951072007-04-25 09:51:38 -04001143 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1144 cmdiocbp->iocb_flag &=
1145 ~LPFC_DRIVER_ABORTED;
1146 saveq->iocb.ulpStatus =
1147 IOSTAT_LOCAL_REJECT;
1148 saveq->iocb.un.ulpWord[4] =
1149 IOERR_SLI_ABORTED;
James Smart0ff10d42008-01-11 01:52:36 -05001150
1151 /* Firmware could still be in progress
1152 * of DMAing payload, so don't free data
1153 * buffer till after a hbeat.
1154 */
1155 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
James Smart07951072007-04-25 09:51:38 -04001156 }
dea31012005-04-17 16:05:31 -05001157 }
James Smart2e0fef82007-06-17 19:56:36 -05001158 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
James Bottomley604a3e32005-10-29 10:28:33 -05001159 } else
1160 lpfc_sli_release_iocbq(phba, cmdiocbp);
dea31012005-04-17 16:05:31 -05001161 } else {
1162 /*
1163 * Unknown initiating command based on the response iotag.
1164 * This could be the case on the ELS ring because of
1165 * lpfc_els_abort().
1166 */
1167 if (pring->ringno != LPFC_ELS_RING) {
1168 /*
1169 * Ring <ringno> handler: unexpected completion IoTag
1170 * <IoTag>
1171 */
James Smarte8b62012007-08-02 11:10:09 -04001172 lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
1173 "0322 Ring %d handler: "
1174 "unexpected completion IoTag x%x "
1175 "Data: x%x x%x x%x x%x\n",
1176 pring->ringno,
1177 saveq->iocb.ulpIoTag,
1178 saveq->iocb.ulpStatus,
1179 saveq->iocb.un.ulpWord[4],
1180 saveq->iocb.ulpCommand,
1181 saveq->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05001182 }
1183 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04001184
dea31012005-04-17 16:05:31 -05001185 return rc;
1186}
1187
James Smart2e0fef82007-06-17 19:56:36 -05001188static void
1189lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001190{
James Smarted957682007-06-17 19:56:37 -05001191 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1192 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1193 &phba->slim2p->mbx.us.s2.port[pring->ringno];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001194 /*
1195 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1196 * rsp ring <portRspMax>
1197 */
1198 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001199 "0312 Ring %d handler: portRspPut %d "
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001200 "is bigger then rsp ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04001201 pring->ringno, le32_to_cpu(pgp->rspPutInx),
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001202 pring->numRiocb);
1203
James Smart2e0fef82007-06-17 19:56:36 -05001204 phba->link_state = LPFC_HBA_ERROR;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001205
1206 /*
1207 * All error attention handlers are posted to
1208 * worker thread
1209 */
1210 phba->work_ha |= HA_ERATT;
1211 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -05001212
1213 /* hbalock should already be held */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001214 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001215 lpfc_worker_wake_up(phba);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001216
1217 return;
1218}
1219
James Smart2e0fef82007-06-17 19:56:36 -05001220void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001221{
James Smart2e0fef82007-06-17 19:56:36 -05001222 struct lpfc_sli *psli = &phba->sli;
1223 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001224 IOCB_t *irsp = NULL;
1225 IOCB_t *entry = NULL;
1226 struct lpfc_iocbq *cmdiocbq = NULL;
1227 struct lpfc_iocbq rspiocbq;
1228 struct lpfc_pgp *pgp;
1229 uint32_t status;
1230 uint32_t portRspPut, portRspMax;
1231 int type;
1232 uint32_t rsp_cmpl = 0;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001233 uint32_t ha_copy;
James Smart2e0fef82007-06-17 19:56:36 -05001234 unsigned long iflags;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001235
1236 pring->stats.iocb_event++;
1237
James Smarted957682007-06-17 19:56:37 -05001238 pgp = (phba->sli_rev == 3) ?
1239 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1240 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1241
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001242
1243 /*
1244 * The next available response entry should never exceed the maximum
1245 * entries. If it does, treat it as an adapter hardware error.
1246 */
1247 portRspMax = pring->numRiocb;
1248 portRspPut = le32_to_cpu(pgp->rspPutInx);
1249 if (unlikely(portRspPut >= portRspMax)) {
1250 lpfc_sli_rsp_pointers_error(phba, pring);
1251 return;
1252 }
1253
1254 rmb();
1255 while (pring->rspidx != portRspPut) {
James Smarted957682007-06-17 19:56:37 -05001256 entry = lpfc_resp_iocb(phba, pring);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001257 if (++pring->rspidx >= portRspMax)
1258 pring->rspidx = 0;
1259
1260 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1261 (uint32_t *) &rspiocbq.iocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001262 phba->iocb_rsp_size);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001263 irsp = &rspiocbq.iocb;
1264 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1265 pring->stats.iocb_rsp++;
1266 rsp_cmpl++;
1267
1268 if (unlikely(irsp->ulpStatus)) {
1269 /* Rsp ring <ringno> error: IOCB */
1270 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001271 "0326 Rsp Ring %d error: IOCB Data: "
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001272 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001273 pring->ringno,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001274 irsp->un.ulpWord[0],
1275 irsp->un.ulpWord[1],
1276 irsp->un.ulpWord[2],
1277 irsp->un.ulpWord[3],
1278 irsp->un.ulpWord[4],
1279 irsp->un.ulpWord[5],
1280 *(((uint32_t *) irsp) + 6),
1281 *(((uint32_t *) irsp) + 7));
1282 }
1283
1284 switch (type) {
1285 case LPFC_ABORT_IOCB:
1286 case LPFC_SOL_IOCB:
1287 /*
1288 * Idle exchange closed via ABTS from port. No iocb
1289 * resources need to be recovered.
1290 */
1291 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001292 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001293 "0314 IOCB cmd 0x%x "
1294 "processed. Skipping "
1295 "completion",
James Smartdca94792006-08-01 07:34:08 -04001296 irsp->ulpCommand);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001297 break;
1298 }
1299
James Smart2e0fef82007-06-17 19:56:36 -05001300 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001301 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1302 &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001303 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001304 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1305 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1306 &rspiocbq);
1307 }
1308 break;
1309 default:
1310 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1311 char adaptermsg[LPFC_MAX_ADPTMSG];
1312 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1313 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1314 MAX_MSG_DATA);
Joe Perches898eb712007-10-18 03:06:30 -07001315 dev_warn(&((phba->pcidev)->dev),
1316 "lpfc%d: %s\n",
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001317 phba->brd_no, adaptermsg);
1318 } else {
1319 /* Unknown IOCB command */
1320 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001321 "0321 Unknown IOCB command "
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001322 "Data: x%x, x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001323 type, irsp->ulpCommand,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001324 irsp->ulpStatus,
1325 irsp->ulpIoTag,
1326 irsp->ulpContext);
1327 }
1328 break;
1329 }
1330
1331 /*
1332 * The response IOCB has been processed. Update the ring
1333 * pointer in SLIM. If the port response put pointer has not
1334 * been updated, sync the pgp->rspPutInx and fetch the new port
1335 * response put pointer.
1336 */
James Smarted957682007-06-17 19:56:37 -05001337 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001338
1339 if (pring->rspidx == portRspPut)
1340 portRspPut = le32_to_cpu(pgp->rspPutInx);
1341 }
1342
1343 ha_copy = readl(phba->HAregaddr);
1344 ha_copy >>= (LPFC_FCP_RING * 4);
1345
1346 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
James Smart2e0fef82007-06-17 19:56:36 -05001347 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001348 pring->stats.iocb_rsp_full++;
1349 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1350 writel(status, phba->CAregaddr);
1351 readl(phba->CAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001352 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001353 }
1354 if ((ha_copy & HA_R0CE_RSP) &&
1355 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001356 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001357 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1358 pring->stats.iocb_cmd_empty++;
1359
1360 /* Force update of the local copy of cmdGetInx */
1361 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1362 lpfc_sli_resume_iocb(phba, pring);
1363
1364 if ((pring->lpfc_sli_cmd_available))
1365 (pring->lpfc_sli_cmd_available) (phba, pring);
1366
James Smart2e0fef82007-06-17 19:56:36 -05001367 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001368 }
1369
1370 return;
1371}
1372
dea31012005-04-17 16:05:31 -05001373/*
1374 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1375 * to check it explicitly.
1376 */
1377static int
James Smart2e0fef82007-06-17 19:56:36 -05001378lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1379 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05001380{
James Smarted957682007-06-17 19:56:37 -05001381 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1382 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1383 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001384 IOCB_t *irsp = NULL;
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001385 IOCB_t *entry = NULL;
dea31012005-04-17 16:05:31 -05001386 struct lpfc_iocbq *cmdiocbq = NULL;
1387 struct lpfc_iocbq rspiocbq;
dea31012005-04-17 16:05:31 -05001388 uint32_t status;
1389 uint32_t portRspPut, portRspMax;
1390 int rc = 1;
1391 lpfc_iocb_type type;
1392 unsigned long iflag;
1393 uint32_t rsp_cmpl = 0;
dea31012005-04-17 16:05:31 -05001394
James Smart2e0fef82007-06-17 19:56:36 -05001395 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001396 pring->stats.iocb_event++;
1397
dea31012005-04-17 16:05:31 -05001398 /*
1399 * The next available response entry should never exceed the maximum
1400 * entries. If it does, treat it as an adapter hardware error.
1401 */
1402 portRspMax = pring->numRiocb;
1403 portRspPut = le32_to_cpu(pgp->rspPutInx);
1404 if (unlikely(portRspPut >= portRspMax)) {
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001405 lpfc_sli_rsp_pointers_error(phba, pring);
James Smart2e0fef82007-06-17 19:56:36 -05001406 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001407 return 1;
1408 }
1409
1410 rmb();
1411 while (pring->rspidx != portRspPut) {
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001412 /*
1413 * Fetch an entry off the ring and copy it into a local data
1414 * structure. The copy involves a byte-swap since the
1415 * network byte order and pci byte orders are different.
1416 */
James Smarted957682007-06-17 19:56:37 -05001417 entry = lpfc_resp_iocb(phba, pring);
James Smart858c9f62007-06-17 19:56:39 -05001418 phba->last_completion_time = jiffies;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001419
1420 if (++pring->rspidx >= portRspMax)
1421 pring->rspidx = 0;
1422
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001423 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1424 (uint32_t *) &rspiocbq.iocb,
James Smarted957682007-06-17 19:56:37 -05001425 phba->iocb_rsp_size);
James Smarta4bc3372006-12-02 13:34:16 -05001426 INIT_LIST_HEAD(&(rspiocbq.list));
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001427 irsp = &rspiocbq.iocb;
1428
dea31012005-04-17 16:05:31 -05001429 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1430 pring->stats.iocb_rsp++;
1431 rsp_cmpl++;
1432
1433 if (unlikely(irsp->ulpStatus)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001434 /*
1435 * If resource errors reported from HBA, reduce
1436 * queuedepths of the SCSI device.
1437 */
1438 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1439 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1440 spin_unlock_irqrestore(&phba->hbalock, iflag);
1441 lpfc_adjust_queue_depth(phba);
1442 spin_lock_irqsave(&phba->hbalock, iflag);
1443 }
1444
dea31012005-04-17 16:05:31 -05001445 /* Rsp ring <ringno> error: IOCB */
1446 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001447 "0336 Rsp Ring %d error: IOCB Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05001448 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001449 pring->ringno,
James Smart92d7f7b2007-06-17 19:56:38 -05001450 irsp->un.ulpWord[0],
1451 irsp->un.ulpWord[1],
1452 irsp->un.ulpWord[2],
1453 irsp->un.ulpWord[3],
1454 irsp->un.ulpWord[4],
1455 irsp->un.ulpWord[5],
1456 *(((uint32_t *) irsp) + 6),
1457 *(((uint32_t *) irsp) + 7));
dea31012005-04-17 16:05:31 -05001458 }
1459
1460 switch (type) {
1461 case LPFC_ABORT_IOCB:
1462 case LPFC_SOL_IOCB:
1463 /*
1464 * Idle exchange closed via ABTS from port. No iocb
1465 * resources need to be recovered.
1466 */
1467 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001468 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001469 "0333 IOCB cmd 0x%x"
James Smartdca94792006-08-01 07:34:08 -04001470 " processed. Skipping"
James Smart92d7f7b2007-06-17 19:56:38 -05001471 " completion\n",
James Smartdca94792006-08-01 07:34:08 -04001472 irsp->ulpCommand);
dea31012005-04-17 16:05:31 -05001473 break;
1474 }
1475
James Bottomley604a3e32005-10-29 10:28:33 -05001476 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1477 &rspiocbq);
dea31012005-04-17 16:05:31 -05001478 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001479 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1480 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1481 &rspiocbq);
1482 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001483 spin_unlock_irqrestore(&phba->hbalock,
1484 iflag);
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001485 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1486 &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001487 spin_lock_irqsave(&phba->hbalock,
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001488 iflag);
1489 }
dea31012005-04-17 16:05:31 -05001490 }
1491 break;
James Smarta4bc3372006-12-02 13:34:16 -05001492 case LPFC_UNSOL_IOCB:
James Smart2e0fef82007-06-17 19:56:36 -05001493 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05001494 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001495 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05001496 break;
dea31012005-04-17 16:05:31 -05001497 default:
1498 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1499 char adaptermsg[LPFC_MAX_ADPTMSG];
1500 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1501 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1502 MAX_MSG_DATA);
Joe Perches898eb712007-10-18 03:06:30 -07001503 dev_warn(&((phba->pcidev)->dev),
1504 "lpfc%d: %s\n",
dea31012005-04-17 16:05:31 -05001505 phba->brd_no, adaptermsg);
1506 } else {
1507 /* Unknown IOCB command */
1508 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001509 "0334 Unknown IOCB command "
James Smart92d7f7b2007-06-17 19:56:38 -05001510 "Data: x%x, x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001511 type, irsp->ulpCommand,
James Smart92d7f7b2007-06-17 19:56:38 -05001512 irsp->ulpStatus,
1513 irsp->ulpIoTag,
1514 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05001515 }
1516 break;
1517 }
1518
1519 /*
1520 * The response IOCB has been processed. Update the ring
1521 * pointer in SLIM. If the port response put pointer has not
1522 * been updated, sync the pgp->rspPutInx and fetch the new port
1523 * response put pointer.
1524 */
James Smarted957682007-06-17 19:56:37 -05001525 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05001526
1527 if (pring->rspidx == portRspPut)
1528 portRspPut = le32_to_cpu(pgp->rspPutInx);
1529 }
1530
1531 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1532 pring->stats.iocb_rsp_full++;
1533 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1534 writel(status, phba->CAregaddr);
1535 readl(phba->CAregaddr);
1536 }
1537 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1538 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1539 pring->stats.iocb_cmd_empty++;
1540
1541 /* Force update of the local copy of cmdGetInx */
1542 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1543 lpfc_sli_resume_iocb(phba, pring);
1544
1545 if ((pring->lpfc_sli_cmd_available))
1546 (pring->lpfc_sli_cmd_available) (phba, pring);
1547
1548 }
1549
James Smart2e0fef82007-06-17 19:56:36 -05001550 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001551 return rc;
1552}
1553
dea31012005-04-17 16:05:31 -05001554int
James Smart2e0fef82007-06-17 19:56:36 -05001555lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1556 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05001557{
James Smarted957682007-06-17 19:56:37 -05001558 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1559 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1560 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001561 IOCB_t *entry;
1562 IOCB_t *irsp = NULL;
1563 struct lpfc_iocbq *rspiocbp = NULL;
1564 struct lpfc_iocbq *next_iocb;
1565 struct lpfc_iocbq *cmdiocbp;
1566 struct lpfc_iocbq *saveq;
dea31012005-04-17 16:05:31 -05001567 uint8_t iocb_cmd_type;
1568 lpfc_iocb_type type;
1569 uint32_t status, free_saveq;
1570 uint32_t portRspPut, portRspMax;
1571 int rc = 1;
1572 unsigned long iflag;
dea31012005-04-17 16:05:31 -05001573
James Smart2e0fef82007-06-17 19:56:36 -05001574 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001575 pring->stats.iocb_event++;
1576
dea31012005-04-17 16:05:31 -05001577 /*
1578 * The next available response entry should never exceed the maximum
1579 * entries. If it does, treat it as an adapter hardware error.
1580 */
1581 portRspMax = pring->numRiocb;
1582 portRspPut = le32_to_cpu(pgp->rspPutInx);
1583 if (portRspPut >= portRspMax) {
1584 /*
1585 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1586 * rsp ring <portRspMax>
1587 */
James Smarted957682007-06-17 19:56:37 -05001588 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001589 "0303 Ring %d handler: portRspPut %d "
dea31012005-04-17 16:05:31 -05001590 "is bigger then rsp ring %d\n",
James Smarte8b62012007-08-02 11:10:09 -04001591 pring->ringno, portRspPut, portRspMax);
dea31012005-04-17 16:05:31 -05001592
James Smart2e0fef82007-06-17 19:56:36 -05001593 phba->link_state = LPFC_HBA_ERROR;
1594 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001595
1596 phba->work_hs = HS_FFER3;
1597 lpfc_handle_eratt(phba);
1598
1599 return 1;
1600 }
1601
1602 rmb();
dea31012005-04-17 16:05:31 -05001603 while (pring->rspidx != portRspPut) {
1604 /*
1605 * Build a completion list and call the appropriate handler.
1606 * The process is to get the next available response iocb, get
1607 * a free iocb from the list, copy the response data into the
1608 * free iocb, insert to the continuation list, and update the
1609 * next response index to slim. This process makes response
1610 * iocb's in the ring available to DMA as fast as possible but
1611 * pays a penalty for a copy operation. Since the iocb is
1612 * only 32 bytes, this penalty is considered small relative to
1613 * the PCI reads for register values and a slim write. When
1614 * the ulpLe field is set, the entire Command has been
1615 * received.
1616 */
James Smarted957682007-06-17 19:56:37 -05001617 entry = lpfc_resp_iocb(phba, pring);
1618
James Smart858c9f62007-06-17 19:56:39 -05001619 phba->last_completion_time = jiffies;
James Smart2e0fef82007-06-17 19:56:36 -05001620 rspiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001621 if (rspiocbp == NULL) {
1622 printk(KERN_ERR "%s: out of buffers! Failing "
1623 "completion.\n", __FUNCTION__);
1624 break;
1625 }
1626
James Smarted957682007-06-17 19:56:37 -05001627 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1628 phba->iocb_rsp_size);
dea31012005-04-17 16:05:31 -05001629 irsp = &rspiocbp->iocb;
1630
1631 if (++pring->rspidx >= portRspMax)
1632 pring->rspidx = 0;
1633
James Smarta58cbd52007-08-02 11:09:43 -04001634 if (pring->ringno == LPFC_ELS_RING) {
1635 lpfc_debugfs_slow_ring_trc(phba,
1636 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1637 *(((uint32_t *) irsp) + 4),
1638 *(((uint32_t *) irsp) + 6),
1639 *(((uint32_t *) irsp) + 7));
1640 }
1641
James Smarted957682007-06-17 19:56:37 -05001642 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05001643
1644 if (list_empty(&(pring->iocb_continueq))) {
1645 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1646 } else {
1647 list_add_tail(&rspiocbp->list,
1648 &(pring->iocb_continueq));
1649 }
1650
1651 pring->iocb_continueq_cnt++;
1652 if (irsp->ulpLe) {
1653 /*
1654 * By default, the driver expects to free all resources
1655 * associated with this iocb completion.
1656 */
1657 free_saveq = 1;
1658 saveq = list_get_first(&pring->iocb_continueq,
1659 struct lpfc_iocbq, list);
1660 irsp = &(saveq->iocb);
1661 list_del_init(&pring->iocb_continueq);
1662 pring->iocb_continueq_cnt = 0;
1663
1664 pring->stats.iocb_rsp++;
1665
James Smart92d7f7b2007-06-17 19:56:38 -05001666 /*
1667 * If resource errors reported from HBA, reduce
1668 * queuedepths of the SCSI device.
1669 */
1670 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1671 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1672 spin_unlock_irqrestore(&phba->hbalock, iflag);
1673 lpfc_adjust_queue_depth(phba);
1674 spin_lock_irqsave(&phba->hbalock, iflag);
1675 }
1676
dea31012005-04-17 16:05:31 -05001677 if (irsp->ulpStatus) {
1678 /* Rsp ring <ringno> error: IOCB */
James Smarted957682007-06-17 19:56:37 -05001679 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001680 "0328 Rsp Ring %d error: "
James Smarted957682007-06-17 19:56:37 -05001681 "IOCB Data: "
1682 "x%x x%x x%x x%x "
1683 "x%x x%x x%x x%x "
1684 "x%x x%x x%x x%x "
1685 "x%x x%x x%x x%x\n",
James Smarted957682007-06-17 19:56:37 -05001686 pring->ringno,
1687 irsp->un.ulpWord[0],
1688 irsp->un.ulpWord[1],
1689 irsp->un.ulpWord[2],
1690 irsp->un.ulpWord[3],
1691 irsp->un.ulpWord[4],
1692 irsp->un.ulpWord[5],
1693 *(((uint32_t *) irsp) + 6),
1694 *(((uint32_t *) irsp) + 7),
1695 *(((uint32_t *) irsp) + 8),
1696 *(((uint32_t *) irsp) + 9),
1697 *(((uint32_t *) irsp) + 10),
1698 *(((uint32_t *) irsp) + 11),
1699 *(((uint32_t *) irsp) + 12),
1700 *(((uint32_t *) irsp) + 13),
1701 *(((uint32_t *) irsp) + 14),
1702 *(((uint32_t *) irsp) + 15));
dea31012005-04-17 16:05:31 -05001703 }
1704
1705 /*
1706 * Fetch the IOCB command type and call the correct
1707 * completion routine. Solicited and Unsolicited
1708 * IOCBs on the ELS ring get freed back to the
1709 * lpfc_iocb_list by the discovery kernel thread.
1710 */
1711 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1712 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1713 if (type == LPFC_SOL_IOCB) {
James Smart2e0fef82007-06-17 19:56:36 -05001714 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05001715 iflag);
1716 rc = lpfc_sli_process_sol_iocb(phba, pring,
James Smart2e0fef82007-06-17 19:56:36 -05001717 saveq);
1718 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001719 } else if (type == LPFC_UNSOL_IOCB) {
James Smart2e0fef82007-06-17 19:56:36 -05001720 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05001721 iflag);
1722 rc = lpfc_sli_process_unsol_iocb(phba, pring,
James Smart2e0fef82007-06-17 19:56:36 -05001723 saveq);
1724 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001725 } else if (type == LPFC_ABORT_IOCB) {
1726 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1727 ((cmdiocbp =
James Bottomley604a3e32005-10-29 10:28:33 -05001728 lpfc_sli_iocbq_lookup(phba, pring,
1729 saveq)))) {
dea31012005-04-17 16:05:31 -05001730 /* Call the specified completion
1731 routine */
1732 if (cmdiocbp->iocb_cmpl) {
1733 spin_unlock_irqrestore(
James Smart2e0fef82007-06-17 19:56:36 -05001734 &phba->hbalock,
dea31012005-04-17 16:05:31 -05001735 iflag);
1736 (cmdiocbp->iocb_cmpl) (phba,
1737 cmdiocbp, saveq);
1738 spin_lock_irqsave(
James Smart2e0fef82007-06-17 19:56:36 -05001739 &phba->hbalock,
dea31012005-04-17 16:05:31 -05001740 iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001741 } else
James Smart2e0fef82007-06-17 19:56:36 -05001742 __lpfc_sli_release_iocbq(phba,
James Bottomley604a3e32005-10-29 10:28:33 -05001743 cmdiocbp);
dea31012005-04-17 16:05:31 -05001744 }
1745 } else if (type == LPFC_UNKNOWN_IOCB) {
1746 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1747
1748 char adaptermsg[LPFC_MAX_ADPTMSG];
1749
1750 memset(adaptermsg, 0,
1751 LPFC_MAX_ADPTMSG);
1752 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1753 MAX_MSG_DATA);
1754 dev_warn(&((phba->pcidev)->dev),
Joe Perches898eb712007-10-18 03:06:30 -07001755 "lpfc%d: %s\n",
dea31012005-04-17 16:05:31 -05001756 phba->brd_no, adaptermsg);
1757 } else {
1758 /* Unknown IOCB command */
James Smart92d7f7b2007-06-17 19:56:38 -05001759 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001760 "0335 Unknown IOCB "
James Smart92d7f7b2007-06-17 19:56:38 -05001761 "command Data: x%x "
1762 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001763 irsp->ulpCommand,
1764 irsp->ulpStatus,
1765 irsp->ulpIoTag,
1766 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05001767 }
1768 }
1769
1770 if (free_saveq) {
James Smart2e0fef82007-06-17 19:56:36 -05001771 list_for_each_entry_safe(rspiocbp, next_iocb,
1772 &saveq->list, list) {
1773 list_del(&rspiocbp->list);
1774 __lpfc_sli_release_iocbq(phba,
1775 rspiocbp);
dea31012005-04-17 16:05:31 -05001776 }
James Smart2e0fef82007-06-17 19:56:36 -05001777 __lpfc_sli_release_iocbq(phba, saveq);
dea31012005-04-17 16:05:31 -05001778 }
James Smart92d7f7b2007-06-17 19:56:38 -05001779 rspiocbp = NULL;
dea31012005-04-17 16:05:31 -05001780 }
1781
1782 /*
1783 * If the port response put pointer has not been updated, sync
1784 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1785 * response put pointer.
1786 */
1787 if (pring->rspidx == portRspPut) {
1788 portRspPut = le32_to_cpu(pgp->rspPutInx);
1789 }
1790 } /* while (pring->rspidx != portRspPut) */
1791
James Smart92d7f7b2007-06-17 19:56:38 -05001792 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
dea31012005-04-17 16:05:31 -05001793 /* At least one response entry has been freed */
1794 pring->stats.iocb_rsp_full++;
1795 /* SET RxRE_RSP in Chip Att register */
1796 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1797 writel(status, phba->CAregaddr);
1798 readl(phba->CAregaddr); /* flush */
1799 }
1800 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1801 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1802 pring->stats.iocb_cmd_empty++;
1803
1804 /* Force update of the local copy of cmdGetInx */
1805 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1806 lpfc_sli_resume_iocb(phba, pring);
1807
1808 if ((pring->lpfc_sli_cmd_available))
1809 (pring->lpfc_sli_cmd_available) (phba, pring);
1810
1811 }
1812
James Smart2e0fef82007-06-17 19:56:36 -05001813 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001814 return rc;
1815}
1816
James Smart2e0fef82007-06-17 19:56:36 -05001817void
dea31012005-04-17 16:05:31 -05001818lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1819{
James Smart2534ba72007-04-25 09:52:20 -04001820 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001821 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -04001822 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05001823
James Smart92d7f7b2007-06-17 19:56:38 -05001824 if (pring->ringno == LPFC_ELS_RING) {
1825 lpfc_fabric_abort_hba(phba);
1826 }
1827
dea31012005-04-17 16:05:31 -05001828 /* Error everything on txq and txcmplq
1829 * First do the txq.
1830 */
James Smart2e0fef82007-06-17 19:56:36 -05001831 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001832 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05001833 pring->txq_cnt = 0;
dea31012005-04-17 16:05:31 -05001834
1835 /* Next issue ABTS for everything on the txcmplq */
James Smart2534ba72007-04-25 09:52:20 -04001836 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1837 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1838
James Smart2e0fef82007-06-17 19:56:36 -05001839 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001840
1841 while (!list_empty(&completions)) {
1842 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
dea31012005-04-17 16:05:31 -05001843 cmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05001844 list_del_init(&iocb->list);
dea31012005-04-17 16:05:31 -05001845
James Smart2e0fef82007-06-17 19:56:36 -05001846 if (!iocb->iocb_cmpl)
1847 lpfc_sli_release_iocbq(phba, iocb);
1848 else {
dea31012005-04-17 16:05:31 -05001849 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1850 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
dea31012005-04-17 16:05:31 -05001851 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001852 }
dea31012005-04-17 16:05:31 -05001853 }
dea31012005-04-17 16:05:31 -05001854}
1855
Jamie Wellnitz41415862006-02-28 19:25:27 -05001856int
James Smart2e0fef82007-06-17 19:56:36 -05001857lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
dea31012005-04-17 16:05:31 -05001858{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001859 uint32_t status;
1860 int i = 0;
1861 int retval = 0;
dea31012005-04-17 16:05:31 -05001862
Jamie Wellnitz41415862006-02-28 19:25:27 -05001863 /* Read the HBA Host Status Register */
1864 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001865
Jamie Wellnitz41415862006-02-28 19:25:27 -05001866 /*
1867 * Check status register every 100ms for 5 retries, then every
1868 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1869 * every 2.5 sec for 4.
1870 * Break our of the loop if errors occurred during init.
1871 */
1872 while (((status & mask) != mask) &&
1873 !(status & HS_FFERM) &&
1874 i++ < 20) {
dea31012005-04-17 16:05:31 -05001875
Jamie Wellnitz41415862006-02-28 19:25:27 -05001876 if (i <= 5)
1877 msleep(10);
1878 else if (i <= 10)
1879 msleep(500);
1880 else
1881 msleep(2500);
dea31012005-04-17 16:05:31 -05001882
Jamie Wellnitz41415862006-02-28 19:25:27 -05001883 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05001884 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05001885 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001886 lpfc_sli_brdrestart(phba);
1887 }
1888 /* Read the HBA Host Status Register */
1889 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001890 }
dea31012005-04-17 16:05:31 -05001891
Jamie Wellnitz41415862006-02-28 19:25:27 -05001892 /* Check to see if any errors occurred during init */
1893 if ((status & HS_FFERM) || (i >= 20)) {
James Smart2e0fef82007-06-17 19:56:36 -05001894 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001895 retval = 1;
1896 }
dea31012005-04-17 16:05:31 -05001897
Jamie Wellnitz41415862006-02-28 19:25:27 -05001898 return retval;
dea31012005-04-17 16:05:31 -05001899}
1900
James Smart92908312006-03-07 15:04:13 -05001901#define BARRIER_TEST_PATTERN (0xdeadbeef)
1902
James Smart2e0fef82007-06-17 19:56:36 -05001903void lpfc_reset_barrier(struct lpfc_hba *phba)
James Smart92908312006-03-07 15:04:13 -05001904{
James Smart65a29c12006-07-06 15:50:50 -04001905 uint32_t __iomem *resp_buf;
1906 uint32_t __iomem *mbox_buf;
James Smart92908312006-03-07 15:04:13 -05001907 volatile uint32_t mbox;
1908 uint32_t hc_copy;
1909 int i;
1910 uint8_t hdrtype;
1911
1912 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1913 if (hdrtype != 0x80 ||
1914 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1915 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1916 return;
1917
1918 /*
1919 * Tell the other part of the chip to suspend temporarily all
1920 * its DMA activity.
1921 */
James Smart65a29c12006-07-06 15:50:50 -04001922 resp_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001923
1924 /* Disable the error attention */
1925 hc_copy = readl(phba->HCregaddr);
1926 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1927 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001928 phba->link_flag |= LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05001929
1930 if (readl(phba->HAregaddr) & HA_ERATT) {
1931 /* Clear Chip error bit */
1932 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001933 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001934 }
1935
1936 mbox = 0;
1937 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1938 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1939
1940 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
James Smart65a29c12006-07-06 15:50:50 -04001941 mbox_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001942 writel(mbox, mbox_buf);
1943
1944 for (i = 0;
1945 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1946 mdelay(1);
1947
1948 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1949 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
James Smart2e0fef82007-06-17 19:56:36 -05001950 phba->pport->stopped)
James Smart92908312006-03-07 15:04:13 -05001951 goto restore_hc;
1952 else
1953 goto clear_errat;
1954 }
1955
1956 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1957 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1958 mdelay(1);
1959
1960clear_errat:
1961
1962 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1963 mdelay(1);
1964
1965 if (readl(phba->HAregaddr) & HA_ERATT) {
1966 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001967 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001968 }
1969
1970restore_hc:
James Smart2e0fef82007-06-17 19:56:36 -05001971 phba->link_flag &= ~LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05001972 writel(hc_copy, phba->HCregaddr);
1973 readl(phba->HCregaddr); /* flush */
1974}
1975
Jamie Wellnitz41415862006-02-28 19:25:27 -05001976int
James Smart2e0fef82007-06-17 19:56:36 -05001977lpfc_sli_brdkill(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001978{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001979 struct lpfc_sli *psli;
1980 LPFC_MBOXQ_t *pmb;
1981 uint32_t status;
1982 uint32_t ha_copy;
1983 int retval;
1984 int i = 0;
1985
1986 psli = &phba->sli;
1987
1988 /* Kill HBA */
James Smarted957682007-06-17 19:56:37 -05001989 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04001990 "0329 Kill HBA Data: x%x x%x\n",
1991 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001992
James Smart98c9ea52007-10-27 13:37:33 -04001993 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1994 if (!pmb)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001995 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001996
1997 /* Disable the error attention */
James Smart2e0fef82007-06-17 19:56:36 -05001998 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001999 status = readl(phba->HCregaddr);
2000 status &= ~HC_ERINT_ENA;
2001 writel(status, phba->HCregaddr);
2002 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002003 phba->link_flag |= LS_IGNORE_ERATT;
2004 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002005
2006 lpfc_kill_board(phba, pmb);
2007 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2008 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2009
2010 if (retval != MBX_SUCCESS) {
2011 if (retval != MBX_BUSY)
2012 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05002013 spin_lock_irq(&phba->hbalock);
2014 phba->link_flag &= ~LS_IGNORE_ERATT;
2015 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002016 return 1;
2017 }
2018
James Smart92908312006-03-07 15:04:13 -05002019 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2020
Jamie Wellnitz41415862006-02-28 19:25:27 -05002021 mempool_free(pmb, phba->mbox_mem_pool);
2022
2023 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
2024 * attention every 100ms for 3 seconds. If we don't get ERATT after
2025 * 3 seconds we still set HBA_ERROR state because the status of the
2026 * board is now undefined.
2027 */
2028 ha_copy = readl(phba->HAregaddr);
2029
2030 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
2031 mdelay(100);
2032 ha_copy = readl(phba->HAregaddr);
2033 }
2034
2035 del_timer_sync(&psli->mbox_tmo);
James Smart92908312006-03-07 15:04:13 -05002036 if (ha_copy & HA_ERATT) {
2037 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05002038 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05002039 }
James Smart2e0fef82007-06-17 19:56:36 -05002040 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002041 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002042 phba->link_flag &= ~LS_IGNORE_ERATT;
2043 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002044
2045 psli->mbox_active = NULL;
2046 lpfc_hba_down_post(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002047 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002048
James Smart2e0fef82007-06-17 19:56:36 -05002049 return ha_copy & HA_ERATT ? 0 : 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002050}
2051
2052int
James Smart2e0fef82007-06-17 19:56:36 -05002053lpfc_sli_brdreset(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05002054{
2055 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002056 struct lpfc_sli_ring *pring;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002057 uint16_t cfg_value;
dea31012005-04-17 16:05:31 -05002058 int i;
dea31012005-04-17 16:05:31 -05002059
Jamie Wellnitz41415862006-02-28 19:25:27 -05002060 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002061
Jamie Wellnitz41415862006-02-28 19:25:27 -05002062 /* Reset HBA */
2063 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002064 "0325 Reset HBA Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002065 phba->pport->port_state, psli->sli_flag);
dea31012005-04-17 16:05:31 -05002066
2067 /* perform board reset */
2068 phba->fc_eventTag = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002069 phba->pport->fc_myDID = 0;
2070 phba->pport->fc_prevDID = 0;
dea31012005-04-17 16:05:31 -05002071
Jamie Wellnitz41415862006-02-28 19:25:27 -05002072 /* Turn off parity checking and serr during the physical reset */
2073 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
2074 pci_write_config_word(phba->pcidev, PCI_COMMAND,
2075 (cfg_value &
2076 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
2077
James Smart1c067a42006-08-01 07:33:52 -04002078 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002079 /* Now toggle INITFF bit in the Host Control Register */
2080 writel(HC_INITFF, phba->HCregaddr);
2081 mdelay(1);
2082 readl(phba->HCregaddr); /* flush */
2083 writel(0, phba->HCregaddr);
2084 readl(phba->HCregaddr); /* flush */
2085
2086 /* Restore PCI cmd register */
2087 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
dea31012005-04-17 16:05:31 -05002088
2089 /* Initialize relevant SLI info */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002090 for (i = 0; i < psli->num_rings; i++) {
2091 pring = &psli->ring[i];
dea31012005-04-17 16:05:31 -05002092 pring->flag = 0;
2093 pring->rspidx = 0;
2094 pring->next_cmdidx = 0;
2095 pring->local_getidx = 0;
2096 pring->cmdidx = 0;
2097 pring->missbufcnt = 0;
2098 }
dea31012005-04-17 16:05:31 -05002099
James Smart2e0fef82007-06-17 19:56:36 -05002100 phba->link_state = LPFC_WARM_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002101 return 0;
2102}
2103
2104int
James Smart2e0fef82007-06-17 19:56:36 -05002105lpfc_sli_brdrestart(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05002106{
2107 MAILBOX_t *mb;
2108 struct lpfc_sli *psli;
2109 uint16_t skip_post;
2110 volatile uint32_t word0;
2111 void __iomem *to_slim;
2112
James Smart2e0fef82007-06-17 19:56:36 -05002113 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002114
2115 psli = &phba->sli;
2116
2117 /* Restart HBA */
2118 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002119 "0337 Restart HBA Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002120 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002121
2122 word0 = 0;
2123 mb = (MAILBOX_t *) &word0;
2124 mb->mbxCommand = MBX_RESTART;
2125 mb->mbxHc = 1;
2126
James Smart92908312006-03-07 15:04:13 -05002127 lpfc_reset_barrier(phba);
2128
Jamie Wellnitz41415862006-02-28 19:25:27 -05002129 to_slim = phba->MBslimaddr;
2130 writel(*(uint32_t *) mb, to_slim);
2131 readl(to_slim); /* flush */
2132
2133 /* Only skip post after fc_ffinit is completed */
James Smart2e0fef82007-06-17 19:56:36 -05002134 if (phba->pport->port_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002135 skip_post = 1;
2136 word0 = 1; /* This is really setting up word1 */
dea31012005-04-17 16:05:31 -05002137 } else {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002138 skip_post = 0;
2139 word0 = 0; /* This is really setting up word1 */
2140 }
James Smart65a29c12006-07-06 15:50:50 -04002141 to_slim = phba->MBslimaddr + sizeof (uint32_t);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002142 writel(*(uint32_t *) mb, to_slim);
2143 readl(to_slim); /* flush */
2144
2145 lpfc_sli_brdreset(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002146 phba->pport->stopped = 0;
2147 phba->link_state = LPFC_INIT_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002148
James Smart2e0fef82007-06-17 19:56:36 -05002149 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002150
James Smart64ba8812006-08-02 15:24:34 -04002151 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2152 psli->stats_start = get_seconds();
2153
Jamie Wellnitz41415862006-02-28 19:25:27 -05002154 if (skip_post)
2155 mdelay(100);
2156 else
dea31012005-04-17 16:05:31 -05002157 mdelay(2000);
dea31012005-04-17 16:05:31 -05002158
Jamie Wellnitz41415862006-02-28 19:25:27 -05002159 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -05002160
2161 return 0;
2162}
2163
2164static int
2165lpfc_sli_chipset_init(struct lpfc_hba *phba)
2166{
2167 uint32_t status, i = 0;
2168
2169 /* Read the HBA Host Status Register */
2170 status = readl(phba->HSregaddr);
2171
2172 /* Check status register to see what current state is */
2173 i = 0;
2174 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2175
2176 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2177 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2178 * 4.
2179 */
2180 if (i++ >= 20) {
2181 /* Adapter failed to init, timeout, status reg
2182 <status> */
James Smarted957682007-06-17 19:56:37 -05002183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002184 "0436 Adapter failed to init, "
James Smart09372822008-01-11 01:52:54 -05002185 "timeout, status reg x%x, "
2186 "FW Data: A8 x%x AC x%x\n", status,
2187 readl(phba->MBslimaddr + 0xa8),
2188 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05002189 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002190 return -ETIMEDOUT;
2191 }
2192
2193 /* Check to see if any errors occurred during init */
2194 if (status & HS_FFERM) {
2195 /* ERROR: During chipset initialization */
2196 /* Adapter failed to init, chipset, status reg
2197 <status> */
James Smarted957682007-06-17 19:56:37 -05002198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002199 "0437 Adapter failed to init, "
James Smart09372822008-01-11 01:52:54 -05002200 "chipset, status reg x%x, "
2201 "FW Data: A8 x%x AC x%x\n", status,
2202 readl(phba->MBslimaddr + 0xa8),
2203 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05002204 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002205 return -EIO;
2206 }
2207
2208 if (i <= 5) {
2209 msleep(10);
2210 } else if (i <= 10) {
2211 msleep(500);
2212 } else {
2213 msleep(2500);
2214 }
2215
2216 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05002217 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05002218 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002219 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05002220 }
2221 /* Read the HBA Host Status Register */
2222 status = readl(phba->HSregaddr);
2223 }
2224
2225 /* Check to see if any errors occurred during init */
2226 if (status & HS_FFERM) {
2227 /* ERROR: During chipset initialization */
2228 /* Adapter failed to init, chipset, status reg <status> */
James Smarted957682007-06-17 19:56:37 -05002229 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002230 "0438 Adapter failed to init, chipset, "
James Smart09372822008-01-11 01:52:54 -05002231 "status reg x%x, "
2232 "FW Data: A8 x%x AC x%x\n", status,
2233 readl(phba->MBslimaddr + 0xa8),
2234 readl(phba->MBslimaddr + 0xac));
James Smart2e0fef82007-06-17 19:56:36 -05002235 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002236 return -EIO;
2237 }
2238
2239 /* Clear all interrupt enable conditions */
2240 writel(0, phba->HCregaddr);
2241 readl(phba->HCregaddr); /* flush */
2242
2243 /* setup host attn register */
2244 writel(0xffffffff, phba->HAregaddr);
2245 readl(phba->HAregaddr); /* flush */
2246 return 0;
2247}
2248
James Smart78b2d852007-08-02 11:10:21 -04002249int
James Smarted957682007-06-17 19:56:37 -05002250lpfc_sli_hbq_count(void)
2251{
James Smart92d7f7b2007-06-17 19:56:38 -05002252 return ARRAY_SIZE(lpfc_hbq_defs);
James Smarted957682007-06-17 19:56:37 -05002253}
2254
2255static int
2256lpfc_sli_hbq_entry_count(void)
2257{
2258 int hbq_count = lpfc_sli_hbq_count();
2259 int count = 0;
2260 int i;
2261
2262 for (i = 0; i < hbq_count; ++i)
James Smart92d7f7b2007-06-17 19:56:38 -05002263 count += lpfc_hbq_defs[i]->entry_count;
James Smarted957682007-06-17 19:56:37 -05002264 return count;
2265}
2266
dea31012005-04-17 16:05:31 -05002267int
James Smarted957682007-06-17 19:56:37 -05002268lpfc_sli_hbq_size(void)
2269{
2270 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2271}
2272
2273static int
2274lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2275{
2276 int hbq_count = lpfc_sli_hbq_count();
2277 LPFC_MBOXQ_t *pmb;
2278 MAILBOX_t *pmbox;
2279 uint32_t hbqno;
2280 uint32_t hbq_entry_index;
James Smarted957682007-06-17 19:56:37 -05002281
James Smart92d7f7b2007-06-17 19:56:38 -05002282 /* Get a Mailbox buffer to setup mailbox
2283 * commands for HBA initialization
2284 */
James Smarted957682007-06-17 19:56:37 -05002285 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2286
2287 if (!pmb)
2288 return -ENOMEM;
2289
2290 pmbox = &pmb->mb;
2291
2292 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2293 phba->link_state = LPFC_INIT_MBX_CMDS;
2294
2295 hbq_entry_index = 0;
2296 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2297 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2298 phba->hbqs[hbqno].hbqPutIdx = 0;
2299 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2300 phba->hbqs[hbqno].entry_count =
James Smart92d7f7b2007-06-17 19:56:38 -05002301 lpfc_hbq_defs[hbqno]->entry_count;
James Smart51ef4c22007-08-02 11:10:31 -04002302 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
2303 hbq_entry_index, pmb);
James Smarted957682007-06-17 19:56:37 -05002304 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2305
2306 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2307 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2308 mbxStatus <status>, ring <num> */
2309
2310 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05002311 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002312 "1805 Adapter failed to init. "
James Smarted957682007-06-17 19:56:37 -05002313 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002314 pmbox->mbxCommand,
James Smarted957682007-06-17 19:56:37 -05002315 pmbox->mbxStatus, hbqno);
2316
2317 phba->link_state = LPFC_HBA_ERROR;
2318 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -05002319 return ENXIO;
2320 }
2321 }
2322 phba->hbq_count = hbq_count;
2323
James Smarted957682007-06-17 19:56:37 -05002324 mempool_free(pmb, phba->mbox_mem_pool);
2325
James Smart92d7f7b2007-06-17 19:56:38 -05002326 /* Initially populate or replenish the HBQs */
2327 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2328 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2329 return -ENOMEM;
2330 }
James Smarted957682007-06-17 19:56:37 -05002331 return 0;
2332}
2333
2334static int
2335lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
dea31012005-04-17 16:05:31 -05002336{
2337 LPFC_MBOXQ_t *pmb;
2338 uint32_t resetcount = 0, rc = 0, done = 0;
2339
2340 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2341 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -05002342 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002343 return -ENOMEM;
2344 }
2345
James Smarted957682007-06-17 19:56:37 -05002346 phba->sli_rev = sli_mode;
dea31012005-04-17 16:05:31 -05002347 while (resetcount < 2 && !done) {
James Smart2e0fef82007-06-17 19:56:36 -05002348 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04002349 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002350 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05002351 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002352 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05002353 msleep(2500);
2354 rc = lpfc_sli_chipset_init(phba);
2355 if (rc)
2356 break;
2357
James Smart2e0fef82007-06-17 19:56:36 -05002358 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04002359 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002360 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002361 resetcount++;
2362
James Smarted957682007-06-17 19:56:37 -05002363 /* Call pre CONFIG_PORT mailbox command initialization. A
2364 * value of 0 means the call was successful. Any other
2365 * nonzero value is a failure, but if ERESTART is returned,
2366 * the driver may reset the HBA and try again.
2367 */
dea31012005-04-17 16:05:31 -05002368 rc = lpfc_config_port_prep(phba);
2369 if (rc == -ERESTART) {
James Smarted957682007-06-17 19:56:37 -05002370 phba->link_state = LPFC_LINK_UNKNOWN;
dea31012005-04-17 16:05:31 -05002371 continue;
2372 } else if (rc) {
2373 break;
2374 }
2375
James Smart2e0fef82007-06-17 19:56:36 -05002376 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -05002377 lpfc_config_port(phba, pmb);
2378 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smarted957682007-06-17 19:56:37 -05002379 if (rc != MBX_SUCCESS) {
dea31012005-04-17 16:05:31 -05002380 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002381 "0442 Adapter failed to init, mbxCmd x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05002382 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002383 pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002384 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002385 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002386 spin_unlock_irq(&phba->hbalock);
2387 rc = -ENXIO;
James Smarted957682007-06-17 19:56:37 -05002388 } else {
2389 done = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002390 phba->max_vpi = (phba->max_vpi &&
2391 pmb->mb.un.varCfgPort.gmv) != 0
2392 ? pmb->mb.un.varCfgPort.max_vpi
2393 : 0;
dea31012005-04-17 16:05:31 -05002394 }
2395 }
James Smarted957682007-06-17 19:56:37 -05002396
2397 if (!done) {
2398 rc = -EINVAL;
2399 goto do_prep_failed;
2400 }
2401
2402 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002403 (!pmb->mb.un.varCfgPort.cMA)) {
James Smarted957682007-06-17 19:56:37 -05002404 rc = -ENXIO;
2405 goto do_prep_failed;
2406 }
2407 return rc;
2408
James Smart92d7f7b2007-06-17 19:56:38 -05002409do_prep_failed:
James Smarted957682007-06-17 19:56:37 -05002410 mempool_free(pmb, phba->mbox_mem_pool);
2411 return rc;
2412}
2413
2414int
2415lpfc_sli_hba_setup(struct lpfc_hba *phba)
2416{
2417 uint32_t rc;
James Smart92d7f7b2007-06-17 19:56:38 -05002418 int mode = 3;
James Smarted957682007-06-17 19:56:37 -05002419
2420 switch (lpfc_sli_mode) {
2421 case 2:
James Smart78b2d852007-08-02 11:10:21 -04002422 if (phba->cfg_enable_npiv) {
James Smart92d7f7b2007-06-17 19:56:38 -05002423 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002424 "1824 NPIV enabled: Override lpfc_sli_mode "
James Smart92d7f7b2007-06-17 19:56:38 -05002425 "parameter (%d) to auto (0).\n",
James Smarte8b62012007-08-02 11:10:09 -04002426 lpfc_sli_mode);
James Smart92d7f7b2007-06-17 19:56:38 -05002427 break;
2428 }
James Smarted957682007-06-17 19:56:37 -05002429 mode = 2;
2430 break;
2431 case 0:
2432 case 3:
2433 break;
2434 default:
James Smart92d7f7b2007-06-17 19:56:38 -05002435 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002436 "1819 Unrecognized lpfc_sli_mode "
2437 "parameter: %d.\n", lpfc_sli_mode);
James Smarted957682007-06-17 19:56:37 -05002438
2439 break;
2440 }
2441
2442 rc = lpfc_do_config_port(phba, mode);
2443 if (rc && lpfc_sli_mode == 3)
James Smart92d7f7b2007-06-17 19:56:38 -05002444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002445 "1820 Unable to select SLI-3. "
2446 "Not supported by adapter.\n");
James Smarted957682007-06-17 19:56:37 -05002447 if (rc && mode != 2)
2448 rc = lpfc_do_config_port(phba, 2);
2449 if (rc)
dea31012005-04-17 16:05:31 -05002450 goto lpfc_sli_hba_setup_error;
2451
James Smarted957682007-06-17 19:56:37 -05002452 if (phba->sli_rev == 3) {
2453 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2454 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2455 phba->sli3_options |= LPFC_SLI3_ENABLED;
2456 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2457
2458 } else {
2459 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2460 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
James Smart92d7f7b2007-06-17 19:56:38 -05002461 phba->sli3_options = 0;
James Smarted957682007-06-17 19:56:37 -05002462 }
2463
2464 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002465 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2466 phba->sli_rev, phba->max_vpi);
James Smarted957682007-06-17 19:56:37 -05002467 rc = lpfc_sli_ring_map(phba);
dea31012005-04-17 16:05:31 -05002468
2469 if (rc)
2470 goto lpfc_sli_hba_setup_error;
2471
James Smart92d7f7b2007-06-17 19:56:38 -05002472 /* Init HBQs */
James Smarted957682007-06-17 19:56:37 -05002473
2474 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2475 rc = lpfc_sli_hbq_setup(phba);
2476 if (rc)
2477 goto lpfc_sli_hba_setup_error;
2478 }
2479
dea31012005-04-17 16:05:31 -05002480 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2481
2482 rc = lpfc_config_port_post(phba);
2483 if (rc)
2484 goto lpfc_sli_hba_setup_error;
2485
James Smarted957682007-06-17 19:56:37 -05002486 return rc;
2487
James Smart92d7f7b2007-06-17 19:56:38 -05002488lpfc_sli_hba_setup_error:
James Smart2e0fef82007-06-17 19:56:36 -05002489 phba->link_state = LPFC_HBA_ERROR;
James Smarted957682007-06-17 19:56:37 -05002490 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002491 "0445 Firmware initialization failed\n");
dea31012005-04-17 16:05:31 -05002492 return rc;
2493}
2494
dea31012005-04-17 16:05:31 -05002495/*! lpfc_mbox_timeout
2496 *
2497 * \pre
2498 * \post
2499 * \param hba Pointer to per struct lpfc_hba structure
2500 * \param l1 Pointer to the driver's mailbox queue.
2501 * \return
2502 * void
2503 *
2504 * \b Description:
2505 *
2506 * This routine handles mailbox timeout events at timer interrupt context.
2507 */
2508void
2509lpfc_mbox_timeout(unsigned long ptr)
2510{
James Smart92d7f7b2007-06-17 19:56:38 -05002511 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
dea31012005-04-17 16:05:31 -05002512 unsigned long iflag;
James Smart2e0fef82007-06-17 19:56:36 -05002513 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05002514
James Smart2e0fef82007-06-17 19:56:36 -05002515 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05002516 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002517 if (!tmo_posted)
2518 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2519 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2520
2521 if (!tmo_posted) {
James Smart92d7f7b2007-06-17 19:56:38 -05002522 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002523 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05002524 lpfc_worker_wake_up(phba);
2525 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002526 }
dea31012005-04-17 16:05:31 -05002527}
2528
2529void
2530lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2531{
James Smart2e0fef82007-06-17 19:56:36 -05002532 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2533 MAILBOX_t *mb = &pmbox->mb;
James Smart1dcb58e2007-04-25 09:51:30 -04002534 struct lpfc_sli *psli = &phba->sli;
2535 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002536
James Smart2e0fef82007-06-17 19:56:36 -05002537 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
dea31012005-04-17 16:05:31 -05002538 return;
2539 }
2540
dea31012005-04-17 16:05:31 -05002541 /* Mbox cmd <mbxCommand> timeout */
James Smarted957682007-06-17 19:56:37 -05002542 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002543 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002544 mb->mbxCommand,
2545 phba->pport->port_state,
2546 phba->sli.sli_flag,
2547 phba->sli.mbox_active);
dea31012005-04-17 16:05:31 -05002548
James Smart1dcb58e2007-04-25 09:51:30 -04002549 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2550 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2551 * it to fail all oustanding SCSI IO.
2552 */
James Smart2e0fef82007-06-17 19:56:36 -05002553 spin_lock_irq(&phba->pport->work_port_lock);
2554 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2555 spin_unlock_irq(&phba->pport->work_port_lock);
2556 spin_lock_irq(&phba->hbalock);
2557 phba->link_state = LPFC_LINK_UNKNOWN;
2558 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart1dcb58e2007-04-25 09:51:30 -04002559 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002560 spin_unlock_irq(&phba->hbalock);
James Smart1dcb58e2007-04-25 09:51:30 -04002561
2562 pring = &psli->ring[psli->fcp_ring];
2563 lpfc_sli_abort_iocb_ring(phba, pring);
2564
2565 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smart76bb24e2007-10-27 13:38:00 -04002566 "0345 Resetting board due to mailbox timeout\n");
James Smart1dcb58e2007-04-25 09:51:30 -04002567 /*
2568 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2569 * on oustanding mailbox commands.
2570 */
James Smart13815c82008-01-11 01:52:48 -05002571 /* If resets are disabled then set error state and return. */
2572 if (!phba->cfg_enable_hba_reset) {
2573 phba->link_state = LPFC_HBA_ERROR;
2574 return;
2575 }
James Smart1dcb58e2007-04-25 09:51:30 -04002576 lpfc_offline_prep(phba);
2577 lpfc_offline(phba);
2578 lpfc_sli_brdrestart(phba);
2579 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2580 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2581 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002582 return;
2583}
2584
2585int
James Smart2e0fef82007-06-17 19:56:36 -05002586lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
dea31012005-04-17 16:05:31 -05002587{
dea31012005-04-17 16:05:31 -05002588 MAILBOX_t *mb;
James Smart2e0fef82007-06-17 19:56:36 -05002589 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002590 uint32_t status, evtctr;
2591 uint32_t ha_copy;
2592 int i;
James Smart09372822008-01-11 01:52:54 -05002593 unsigned long timeout;
dea31012005-04-17 16:05:31 -05002594 unsigned long drvr_flag = 0;
2595 volatile uint32_t word0, ldata;
2596 void __iomem *to_slim;
2597
James Smarted957682007-06-17 19:56:37 -05002598 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
James Smart92d7f7b2007-06-17 19:56:38 -05002599 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
James Smarted957682007-06-17 19:56:37 -05002600 if(!pmbox->vport) {
2601 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05002602 LOG_MBOX | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002603 "1806 Mbox x%x failed. No vport\n",
James Smarted957682007-06-17 19:56:37 -05002604 pmbox->mb.mbxCommand);
2605 dump_stack();
2606 return MBXERR_ERROR;
2607 }
2608 }
2609
James Smart92d7f7b2007-06-17 19:56:38 -05002610
Linas Vepstas8d63f372007-02-14 14:28:36 -06002611 /* If the PCI channel is in offline state, do not post mbox. */
2612 if (unlikely(pci_channel_offline(phba->pcidev)))
2613 return MBX_NOT_FINISHED;
2614
James Smart2e0fef82007-06-17 19:56:36 -05002615 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002616 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002617
2618
dea31012005-04-17 16:05:31 -05002619 mb = &pmbox->mb;
2620 status = MBX_SUCCESS;
2621
James Smart2e0fef82007-06-17 19:56:36 -05002622 if (phba->link_state == LPFC_HBA_ERROR) {
2623 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002624
2625 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002626 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
James Smart2e0fef82007-06-17 19:56:36 -05002627 return MBX_NOT_FINISHED;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002628 }
2629
James Smart92908312006-03-07 15:04:13 -05002630 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2631 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
James Smart2e0fef82007-06-17 19:56:36 -05002632 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
James Smart92d7f7b2007-06-17 19:56:38 -05002633 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
James Smart2e0fef82007-06-17 19:56:36 -05002634 return MBX_NOT_FINISHED;
James Smart92908312006-03-07 15:04:13 -05002635 }
2636
dea31012005-04-17 16:05:31 -05002637 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2638 /* Polling for a mbox command when another one is already active
2639 * is not allowed in SLI. Also, the driver must have established
2640 * SLI2 mode to queue and process multiple mbox commands.
2641 */
2642
2643 if (flag & MBX_POLL) {
James Smart2e0fef82007-06-17 19:56:36 -05002644 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002645
2646 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002647 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002648 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002649 }
2650
2651 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002652 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002653 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002654 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002655 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002656 }
2657
dea31012005-04-17 16:05:31 -05002658 /* Another mailbox command is still being processed, queue this
2659 * command to be processed later.
2660 */
2661 lpfc_mbox_put(phba, pmbox);
2662
2663 /* Mbox cmd issue - BUSY */
James Smarted957682007-06-17 19:56:37 -05002664 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002665 "(%d):0308 Mbox cmd issue - BUSY Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05002666 "x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002667 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2668 mb->mbxCommand, phba->pport->port_state,
2669 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05002670
2671 psli->slistat.mbox_busy++;
James Smart2e0fef82007-06-17 19:56:36 -05002672 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002673
James Smart858c9f62007-06-17 19:56:39 -05002674 if (pmbox->vport) {
2675 lpfc_debugfs_disc_trc(pmbox->vport,
2676 LPFC_DISC_TRC_MBOX_VPORT,
2677 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2678 (uint32_t)mb->mbxCommand,
2679 mb->un.varWords[0], mb->un.varWords[1]);
2680 }
2681 else {
2682 lpfc_debugfs_disc_trc(phba->pport,
2683 LPFC_DISC_TRC_MBOX,
2684 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2685 (uint32_t)mb->mbxCommand,
2686 mb->un.varWords[0], mb->un.varWords[1]);
2687 }
2688
James Smart2e0fef82007-06-17 19:56:36 -05002689 return MBX_BUSY;
dea31012005-04-17 16:05:31 -05002690 }
2691
dea31012005-04-17 16:05:31 -05002692 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2693
2694 /* If we are not polling, we MUST be in SLI2 mode */
2695 if (flag != MBX_POLL) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002696 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2697 (mb->mbxCommand != MBX_KILL_BOARD)) {
dea31012005-04-17 16:05:31 -05002698 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002699 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002700 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002701 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002702 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002703 }
2704 /* timeout active mbox command */
James Smarta309a6b2006-08-01 07:33:43 -04002705 mod_timer(&psli->mbox_tmo, (jiffies +
2706 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
dea31012005-04-17 16:05:31 -05002707 }
2708
2709 /* Mailbox cmd <cmd> issue */
James Smarted957682007-06-17 19:56:37 -05002710 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04002711 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05002712 "x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002713 pmbox->vport ? pmbox->vport->vpi : 0,
James Smart92d7f7b2007-06-17 19:56:38 -05002714 mb->mbxCommand, phba->pport->port_state,
2715 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05002716
James Smart858c9f62007-06-17 19:56:39 -05002717 if (mb->mbxCommand != MBX_HEARTBEAT) {
2718 if (pmbox->vport) {
2719 lpfc_debugfs_disc_trc(pmbox->vport,
2720 LPFC_DISC_TRC_MBOX_VPORT,
2721 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2722 (uint32_t)mb->mbxCommand,
2723 mb->un.varWords[0], mb->un.varWords[1]);
2724 }
2725 else {
2726 lpfc_debugfs_disc_trc(phba->pport,
2727 LPFC_DISC_TRC_MBOX,
2728 "MBOX Send: cmd:x%x mb:x%x x%x",
2729 (uint32_t)mb->mbxCommand,
2730 mb->un.varWords[0], mb->un.varWords[1]);
2731 }
2732 }
2733
dea31012005-04-17 16:05:31 -05002734 psli->slistat.mbox_cmd++;
2735 evtctr = psli->slistat.mbox_event;
2736
2737 /* next set own bit for the adapter and copy over command word */
2738 mb->mbxOwner = OWN_CHIP;
2739
2740 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002741 /* First copy command data to host SLIM area */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002742 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002743 } else {
James Smart92908312006-03-07 15:04:13 -05002744 if (mb->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05002745 /* copy command data into host mbox for cmpl */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002746 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
James Smart92d7f7b2007-06-17 19:56:38 -05002747 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002748 }
2749
2750 /* First copy mbox command data to HBA SLIM, skip past first
2751 word */
2752 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2753 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2754 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2755
2756 /* Next copy over first word, with mbxOwner set */
2757 ldata = *((volatile uint32_t *)mb);
2758 to_slim = phba->MBslimaddr;
2759 writel(ldata, to_slim);
2760 readl(to_slim); /* flush */
2761
2762 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2763 /* switch over to host mailbox */
2764 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2765 }
2766 }
2767
2768 wmb();
dea31012005-04-17 16:05:31 -05002769
2770 switch (flag) {
2771 case MBX_NOWAIT:
James Smart09372822008-01-11 01:52:54 -05002772 /* Set up reference to mailbox command */
dea31012005-04-17 16:05:31 -05002773 psli->mbox_active = pmbox;
James Smart09372822008-01-11 01:52:54 -05002774 /* Interrupt board to do it */
2775 writel(CA_MBATT, phba->CAregaddr);
2776 readl(phba->CAregaddr); /* flush */
2777 /* Don't wait for it to finish, just return */
dea31012005-04-17 16:05:31 -05002778 break;
2779
2780 case MBX_POLL:
James Smart09372822008-01-11 01:52:54 -05002781 /* Set up null reference to mailbox command */
dea31012005-04-17 16:05:31 -05002782 psli->mbox_active = NULL;
James Smart09372822008-01-11 01:52:54 -05002783 /* Interrupt board to do it */
2784 writel(CA_MBATT, phba->CAregaddr);
2785 readl(phba->CAregaddr); /* flush */
2786
dea31012005-04-17 16:05:31 -05002787 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2788 /* First read mbox status word */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002789 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002790 word0 = le32_to_cpu(word0);
2791 } else {
2792 /* First read mbox status word */
2793 word0 = readl(phba->MBslimaddr);
2794 }
2795
2796 /* Read the HBA Host Attention Register */
2797 ha_copy = readl(phba->HAregaddr);
James Smart09372822008-01-11 01:52:54 -05002798 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2799 mb->mbxCommand) *
2800 1000) + jiffies;
2801 i = 0;
dea31012005-04-17 16:05:31 -05002802 /* Wait for command to complete */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002803 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2804 (!(ha_copy & HA_MBATT) &&
James Smart2e0fef82007-06-17 19:56:36 -05002805 (phba->link_state > LPFC_WARM_START))) {
James Smart09372822008-01-11 01:52:54 -05002806 if (time_after(jiffies, timeout)) {
dea31012005-04-17 16:05:31 -05002807 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002808 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05002809 drvr_flag);
James Smart2e0fef82007-06-17 19:56:36 -05002810 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002811 }
2812
2813 /* Check if we took a mbox interrupt while we were
2814 polling */
2815 if (((word0 & OWN_CHIP) != OWN_CHIP)
2816 && (evtctr != psli->slistat.mbox_event))
2817 break;
2818
James Smart09372822008-01-11 01:52:54 -05002819 if (i++ > 10) {
2820 spin_unlock_irqrestore(&phba->hbalock,
2821 drvr_flag);
2822 msleep(1);
2823 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2824 }
dea31012005-04-17 16:05:31 -05002825
2826 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2827 /* First copy command data */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002828 word0 = *((volatile uint32_t *)
2829 &phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002830 word0 = le32_to_cpu(word0);
2831 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2832 MAILBOX_t *slimmb;
2833 volatile uint32_t slimword0;
2834 /* Check real SLIM for any errors */
2835 slimword0 = readl(phba->MBslimaddr);
2836 slimmb = (MAILBOX_t *) & slimword0;
2837 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2838 && slimmb->mbxStatus) {
2839 psli->sli_flag &=
2840 ~LPFC_SLI2_ACTIVE;
2841 word0 = slimword0;
2842 }
2843 }
2844 } else {
2845 /* First copy command data */
2846 word0 = readl(phba->MBslimaddr);
2847 }
2848 /* Read the HBA Host Attention Register */
2849 ha_copy = readl(phba->HAregaddr);
2850 }
2851
2852 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002853 /* copy results back to user */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002854 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
James Smart92d7f7b2007-06-17 19:56:38 -05002855 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002856 } else {
2857 /* First copy command data */
2858 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2859 MAILBOX_CMD_SIZE);
2860 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2861 pmbox->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05002862 lpfc_memcpy_from_slim((void *)pmbox->context2,
dea31012005-04-17 16:05:31 -05002863 phba->MBslimaddr + DMP_RSP_OFFSET,
2864 mb->un.varDmp.word_cnt);
2865 }
2866 }
2867
2868 writel(HA_MBATT, phba->HAregaddr);
2869 readl(phba->HAregaddr); /* flush */
2870
2871 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2872 status = mb->mbxStatus;
2873 }
2874
James Smart2e0fef82007-06-17 19:56:36 -05002875 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2876 return status;
dea31012005-04-17 16:05:31 -05002877}
2878
James Smart92d7f7b2007-06-17 19:56:38 -05002879/*
2880 * Caller needs to hold lock.
2881 */
James Smart858c9f62007-06-17 19:56:39 -05002882static void
James Smart92d7f7b2007-06-17 19:56:38 -05002883__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05002884 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -05002885{
2886 /* Insert the caller's iocb in the txq tail for later processing. */
2887 list_add_tail(&piocb->list, &pring->txq);
2888 pring->txq_cnt++;
dea31012005-04-17 16:05:31 -05002889}
2890
2891static struct lpfc_iocbq *
2892lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05002893 struct lpfc_iocbq **piocb)
dea31012005-04-17 16:05:31 -05002894{
2895 struct lpfc_iocbq * nextiocb;
2896
2897 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2898 if (!nextiocb) {
2899 nextiocb = *piocb;
2900 *piocb = NULL;
2901 }
2902
2903 return nextiocb;
2904}
2905
James Smart92d7f7b2007-06-17 19:56:38 -05002906/*
2907 * Lockless version of lpfc_sli_issue_iocb.
2908 */
James Smart98c9ea52007-10-27 13:37:33 -04002909static int
James Smart92d7f7b2007-06-17 19:56:38 -05002910__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05002911 struct lpfc_iocbq *piocb, uint32_t flag)
2912{
2913 struct lpfc_iocbq *nextiocb;
2914 IOCB_t *iocb;
2915
James Smart92d7f7b2007-06-17 19:56:38 -05002916 if (piocb->iocb_cmpl && (!piocb->vport) &&
2917 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
2918 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
2919 lpfc_printf_log(phba, KERN_ERR,
2920 LOG_SLI | LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -04002921 "1807 IOCB x%x failed. No vport\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002922 piocb->iocb.ulpCommand);
2923 dump_stack();
2924 return IOCB_ERROR;
2925 }
2926
2927
Linas Vepstas8d63f372007-02-14 14:28:36 -06002928 /* If the PCI channel is in offline state, do not post iocbs. */
2929 if (unlikely(pci_channel_offline(phba->pcidev)))
2930 return IOCB_ERROR;
2931
dea31012005-04-17 16:05:31 -05002932 /*
2933 * We should never get an IOCB if we are in a < LINK_DOWN state
2934 */
James Smart2e0fef82007-06-17 19:56:36 -05002935 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05002936 return IOCB_ERROR;
2937
2938 /*
2939 * Check to see if we are blocking IOCB processing because of a
James Smart0b727fe2007-10-27 13:37:25 -04002940 * outstanding event.
dea31012005-04-17 16:05:31 -05002941 */
James Smart0b727fe2007-10-27 13:37:25 -04002942 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
dea31012005-04-17 16:05:31 -05002943 goto iocb_busy;
2944
James Smart2e0fef82007-06-17 19:56:36 -05002945 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
dea31012005-04-17 16:05:31 -05002946 /*
James Smart2680eea2007-04-25 09:52:55 -04002947 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
dea31012005-04-17 16:05:31 -05002948 * can be issued if the link is not up.
2949 */
2950 switch (piocb->iocb.ulpCommand) {
2951 case CMD_QUE_RING_BUF_CN:
2952 case CMD_QUE_RING_BUF64_CN:
dea31012005-04-17 16:05:31 -05002953 /*
2954 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2955 * completion, iocb_cmpl MUST be 0.
2956 */
2957 if (piocb->iocb_cmpl)
2958 piocb->iocb_cmpl = NULL;
2959 /*FALLTHROUGH*/
2960 case CMD_CREATE_XRI_CR:
James Smart2680eea2007-04-25 09:52:55 -04002961 case CMD_CLOSE_XRI_CN:
2962 case CMD_CLOSE_XRI_CX:
dea31012005-04-17 16:05:31 -05002963 break;
2964 default:
2965 goto iocb_busy;
2966 }
2967
2968 /*
2969 * For FCP commands, we must be in a state where we can process link
2970 * attention events.
2971 */
2972 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
James Smart92d7f7b2007-06-17 19:56:38 -05002973 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
dea31012005-04-17 16:05:31 -05002974 goto iocb_busy;
James Smart92d7f7b2007-06-17 19:56:38 -05002975 }
dea31012005-04-17 16:05:31 -05002976
dea31012005-04-17 16:05:31 -05002977 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2978 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2979 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2980
2981 if (iocb)
2982 lpfc_sli_update_ring(phba, pring);
2983 else
2984 lpfc_sli_update_full_ring(phba, pring);
2985
2986 if (!piocb)
2987 return IOCB_SUCCESS;
2988
2989 goto out_busy;
2990
2991 iocb_busy:
2992 pring->stats.iocb_cmd_delay++;
2993
2994 out_busy:
2995
2996 if (!(flag & SLI_IOCB_RET_IOCB)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002997 __lpfc_sli_ringtx_put(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05002998 return IOCB_SUCCESS;
2999 }
3000
3001 return IOCB_BUSY;
3002}
3003
James Smart92d7f7b2007-06-17 19:56:38 -05003004
3005int
3006lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3007 struct lpfc_iocbq *piocb, uint32_t flag)
3008{
3009 unsigned long iflags;
3010 int rc;
3011
3012 spin_lock_irqsave(&phba->hbalock, iflags);
3013 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
3014 spin_unlock_irqrestore(&phba->hbalock, iflags);
3015
3016 return rc;
3017}
3018
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003019static int
3020lpfc_extra_ring_setup( struct lpfc_hba *phba)
3021{
3022 struct lpfc_sli *psli;
3023 struct lpfc_sli_ring *pring;
3024
3025 psli = &phba->sli;
3026
3027 /* Adjust cmd/rsp ring iocb entries more evenly */
James Smarta4bc3372006-12-02 13:34:16 -05003028
3029 /* Take some away from the FCP ring */
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003030 pring = &psli->ring[psli->fcp_ring];
3031 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3032 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3033 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3034 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3035
James Smarta4bc3372006-12-02 13:34:16 -05003036 /* and give them to the extra ring */
3037 pring = &psli->ring[psli->extra_ring];
3038
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003039 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3040 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3041 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3042 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3043
3044 /* Setup default profile for this ring */
3045 pring->iotag_max = 4096;
3046 pring->num_mask = 1;
3047 pring->prt[0].profile = 0; /* Mask 0 */
James Smarta4bc3372006-12-02 13:34:16 -05003048 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
3049 pring->prt[0].type = phba->cfg_multi_ring_type;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003050 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
3051 return 0;
3052}
3053
James Smart98c9ea52007-10-27 13:37:33 -04003054static void
James Smart57127f12007-10-27 13:37:05 -04003055lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3056 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
3057{
3058 IOCB_t *icmd;
3059 uint16_t evt_code;
3060 uint16_t temp;
3061 struct temp_event temp_event_data;
3062 struct Scsi_Host *shost;
3063
3064 icmd = &iocbq->iocb;
3065 evt_code = icmd->un.asyncstat.evt_code;
3066 temp = icmd->ulpContext;
3067
3068 if ((evt_code != ASYNC_TEMP_WARN) &&
3069 (evt_code != ASYNC_TEMP_SAFE)) {
3070 lpfc_printf_log(phba,
3071 KERN_ERR,
3072 LOG_SLI,
James Smart76bb24e2007-10-27 13:38:00 -04003073 "0346 Ring %d handler: unexpected ASYNC_STATUS"
James Smart57127f12007-10-27 13:37:05 -04003074 " evt_code 0x%x\n",
3075 pring->ringno,
3076 icmd->un.asyncstat.evt_code);
3077 return;
3078 }
3079 temp_event_data.data = (uint32_t)temp;
3080 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
3081 if (evt_code == ASYNC_TEMP_WARN) {
3082 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
3083 lpfc_printf_log(phba,
James Smart09372822008-01-11 01:52:54 -05003084 KERN_ERR,
James Smart57127f12007-10-27 13:37:05 -04003085 LOG_TEMP,
James Smart76bb24e2007-10-27 13:38:00 -04003086 "0347 Adapter is very hot, please take "
James Smart57127f12007-10-27 13:37:05 -04003087 "corrective action. temperature : %d Celsius\n",
3088 temp);
3089 }
3090 if (evt_code == ASYNC_TEMP_SAFE) {
3091 temp_event_data.event_code = LPFC_NORMAL_TEMP;
3092 lpfc_printf_log(phba,
James Smart09372822008-01-11 01:52:54 -05003093 KERN_ERR,
James Smart57127f12007-10-27 13:37:05 -04003094 LOG_TEMP,
3095 "0340 Adapter temperature is OK now. "
3096 "temperature : %d Celsius\n",
3097 temp);
3098 }
3099
3100 /* Send temperature change event to applications */
3101 shost = lpfc_shost_from_vport(phba->pport);
3102 fc_host_post_vendor_event(shost, fc_get_event_number(),
3103 sizeof(temp_event_data), (char *) &temp_event_data,
3104 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
3105
3106}
3107
3108
dea31012005-04-17 16:05:31 -05003109int
3110lpfc_sli_setup(struct lpfc_hba *phba)
3111{
James Smarted957682007-06-17 19:56:37 -05003112 int i, totiocbsize = 0;
dea31012005-04-17 16:05:31 -05003113 struct lpfc_sli *psli = &phba->sli;
3114 struct lpfc_sli_ring *pring;
3115
3116 psli->num_rings = MAX_CONFIGURED_RINGS;
3117 psli->sli_flag = 0;
3118 psli->fcp_ring = LPFC_FCP_RING;
3119 psli->next_ring = LPFC_FCP_NEXT_RING;
James Smarta4bc3372006-12-02 13:34:16 -05003120 psli->extra_ring = LPFC_EXTRA_RING;
dea31012005-04-17 16:05:31 -05003121
James Bottomley604a3e32005-10-29 10:28:33 -05003122 psli->iocbq_lookup = NULL;
3123 psli->iocbq_lookup_len = 0;
3124 psli->last_iotag = 0;
3125
dea31012005-04-17 16:05:31 -05003126 for (i = 0; i < psli->num_rings; i++) {
3127 pring = &psli->ring[i];
3128 switch (i) {
3129 case LPFC_FCP_RING: /* ring 0 - FCP */
3130 /* numCiocb and numRiocb are used in config_port */
3131 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3132 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3133 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3134 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3135 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3136 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003137 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003138 SLI3_IOCB_CMD_SIZE :
3139 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003140 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003141 SLI3_IOCB_RSP_SIZE :
3142 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05003143 pring->iotag_ctr = 0;
3144 pring->iotag_max =
James Smart92d7f7b2007-06-17 19:56:38 -05003145 (phba->cfg_hba_queue_depth * 2);
dea31012005-04-17 16:05:31 -05003146 pring->fast_iotag = pring->iotag_max;
3147 pring->num_mask = 0;
3148 break;
James Smarta4bc3372006-12-02 13:34:16 -05003149 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
dea31012005-04-17 16:05:31 -05003150 /* numCiocb and numRiocb are used in config_port */
3151 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3152 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003153 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003154 SLI3_IOCB_CMD_SIZE :
3155 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003156 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003157 SLI3_IOCB_RSP_SIZE :
3158 SLI2_IOCB_RSP_SIZE;
James Smart2e0fef82007-06-17 19:56:36 -05003159 pring->iotag_max = phba->cfg_hba_queue_depth;
dea31012005-04-17 16:05:31 -05003160 pring->num_mask = 0;
3161 break;
3162 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3163 /* numCiocb and numRiocb are used in config_port */
3164 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3165 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003166 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003167 SLI3_IOCB_CMD_SIZE :
3168 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003169 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003170 SLI3_IOCB_RSP_SIZE :
3171 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05003172 pring->fast_iotag = 0;
3173 pring->iotag_ctr = 0;
3174 pring->iotag_max = 4096;
James Smart57127f12007-10-27 13:37:05 -04003175 pring->lpfc_sli_rcv_async_status =
3176 lpfc_sli_async_event_handler;
dea31012005-04-17 16:05:31 -05003177 pring->num_mask = 4;
3178 pring->prt[0].profile = 0; /* Mask 0 */
3179 pring->prt[0].rctl = FC_ELS_REQ;
3180 pring->prt[0].type = FC_ELS_DATA;
3181 pring->prt[0].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003182 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05003183 pring->prt[1].profile = 0; /* Mask 1 */
3184 pring->prt[1].rctl = FC_ELS_RSP;
3185 pring->prt[1].type = FC_ELS_DATA;
3186 pring->prt[1].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003187 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05003188 pring->prt[2].profile = 0; /* Mask 2 */
3189 /* NameServer Inquiry */
3190 pring->prt[2].rctl = FC_UNSOL_CTL;
3191 /* NameServer */
3192 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3193 pring->prt[2].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003194 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05003195 pring->prt[3].profile = 0; /* Mask 3 */
3196 /* NameServer response */
3197 pring->prt[3].rctl = FC_SOL_CTL;
3198 /* NameServer */
3199 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3200 pring->prt[3].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003201 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05003202 break;
3203 }
James Smarted957682007-06-17 19:56:37 -05003204 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
James Smart92d7f7b2007-06-17 19:56:38 -05003205 (pring->numRiocb * pring->sizeRiocb);
dea31012005-04-17 16:05:31 -05003206 }
James Smarted957682007-06-17 19:56:37 -05003207 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
dea31012005-04-17 16:05:31 -05003208 /* Too many cmd / rsp ring entries in SLI2 SLIM */
James Smarte8b62012007-08-02 11:10:09 -04003209 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
3210 "SLI2 SLIM Data: x%x x%lx\n",
3211 phba->brd_no, totiocbsize,
3212 (unsigned long) MAX_SLIM_IOCB_SIZE);
dea31012005-04-17 16:05:31 -05003213 }
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003214 if (phba->cfg_multi_ring_support == 2)
3215 lpfc_extra_ring_setup(phba);
dea31012005-04-17 16:05:31 -05003216
3217 return 0;
3218}
3219
3220int
James Smart2e0fef82007-06-17 19:56:36 -05003221lpfc_sli_queue_setup(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003222{
3223 struct lpfc_sli *psli;
3224 struct lpfc_sli_ring *pring;
James Bottomley604a3e32005-10-29 10:28:33 -05003225 int i;
dea31012005-04-17 16:05:31 -05003226
3227 psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003228 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003229 INIT_LIST_HEAD(&psli->mboxq);
James Smart92d7f7b2007-06-17 19:56:38 -05003230 INIT_LIST_HEAD(&psli->mboxq_cmpl);
dea31012005-04-17 16:05:31 -05003231 /* Initialize list headers for txq and txcmplq as double linked lists */
3232 for (i = 0; i < psli->num_rings; i++) {
3233 pring = &psli->ring[i];
3234 pring->ringno = i;
3235 pring->next_cmdidx = 0;
3236 pring->local_getidx = 0;
3237 pring->cmdidx = 0;
3238 INIT_LIST_HEAD(&pring->txq);
3239 INIT_LIST_HEAD(&pring->txcmplq);
3240 INIT_LIST_HEAD(&pring->iocb_continueq);
3241 INIT_LIST_HEAD(&pring->postbufq);
dea31012005-04-17 16:05:31 -05003242 }
James Smart2e0fef82007-06-17 19:56:36 -05003243 spin_unlock_irq(&phba->hbalock);
3244 return 1;
dea31012005-04-17 16:05:31 -05003245}
3246
3247int
James Smart92d7f7b2007-06-17 19:56:38 -05003248lpfc_sli_host_down(struct lpfc_vport *vport)
3249{
James Smart858c9f62007-06-17 19:56:39 -05003250 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05003251 struct lpfc_hba *phba = vport->phba;
3252 struct lpfc_sli *psli = &phba->sli;
3253 struct lpfc_sli_ring *pring;
3254 struct lpfc_iocbq *iocb, *next_iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003255 int i;
3256 unsigned long flags = 0;
3257 uint16_t prev_pring_flag;
3258
3259 lpfc_cleanup_discovery_resources(vport);
3260
3261 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003262 for (i = 0; i < psli->num_rings; i++) {
3263 pring = &psli->ring[i];
3264 prev_pring_flag = pring->flag;
James Smart858c9f62007-06-17 19:56:39 -05003265 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3266 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05003267 /*
3268 * Error everything on the txq since these iocbs have not been
3269 * given to the FW yet.
3270 */
James Smart92d7f7b2007-06-17 19:56:38 -05003271 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3272 if (iocb->vport != vport)
3273 continue;
James Smart858c9f62007-06-17 19:56:39 -05003274 list_move_tail(&iocb->list, &completions);
James Smart92d7f7b2007-06-17 19:56:38 -05003275 pring->txq_cnt--;
James Smart92d7f7b2007-06-17 19:56:38 -05003276 }
3277
3278 /* Next issue ABTS for everything on the txcmplq */
3279 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3280 list) {
3281 if (iocb->vport != vport)
3282 continue;
3283 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3284 }
3285
3286 pring->flag = prev_pring_flag;
3287 }
3288
3289 spin_unlock_irqrestore(&phba->hbalock, flags);
3290
James Smart858c9f62007-06-17 19:56:39 -05003291 while (!list_empty(&completions)) {
3292 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3293
3294 if (!iocb->iocb_cmpl)
3295 lpfc_sli_release_iocbq(phba, iocb);
3296 else {
3297 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3298 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3299 (iocb->iocb_cmpl) (phba, iocb, iocb);
3300 }
3301 }
James Smart92d7f7b2007-06-17 19:56:38 -05003302 return 1;
3303}
3304
3305int
James Smart2e0fef82007-06-17 19:56:36 -05003306lpfc_sli_hba_down(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003307{
James Smart2534ba72007-04-25 09:52:20 -04003308 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003309 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003310 struct lpfc_sli_ring *pring;
James Smart0ff10d42008-01-11 01:52:36 -05003311 struct lpfc_dmabuf *buf_ptr;
dea31012005-04-17 16:05:31 -05003312 LPFC_MBOXQ_t *pmb;
James Smart2534ba72007-04-25 09:52:20 -04003313 struct lpfc_iocbq *iocb;
3314 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003315 int i;
3316 unsigned long flags = 0;
3317
dea31012005-04-17 16:05:31 -05003318 lpfc_hba_down_prep(phba);
3319
James Smart92d7f7b2007-06-17 19:56:38 -05003320 lpfc_fabric_abort_hba(phba);
3321
James Smart2e0fef82007-06-17 19:56:36 -05003322 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003323 for (i = 0; i < psli->num_rings; i++) {
3324 pring = &psli->ring[i];
James Smart858c9f62007-06-17 19:56:39 -05003325 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3326 pring->flag |= LPFC_DEFERRED_RING_EVENT;
dea31012005-04-17 16:05:31 -05003327
3328 /*
3329 * Error everything on the txq since these iocbs have not been
3330 * given to the FW yet.
3331 */
James Smart2534ba72007-04-25 09:52:20 -04003332 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05003333 pring->txq_cnt = 0;
3334
dea31012005-04-17 16:05:31 -05003335 }
James Smart2e0fef82007-06-17 19:56:36 -05003336 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003337
James Smart2534ba72007-04-25 09:52:20 -04003338 while (!list_empty(&completions)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003339 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
James Smart2534ba72007-04-25 09:52:20 -04003340 cmd = &iocb->iocb;
James Smart2534ba72007-04-25 09:52:20 -04003341
James Smart2e0fef82007-06-17 19:56:36 -05003342 if (!iocb->iocb_cmpl)
3343 lpfc_sli_release_iocbq(phba, iocb);
3344 else {
James Smart2534ba72007-04-25 09:52:20 -04003345 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3346 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3347 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05003348 }
James Smart2534ba72007-04-25 09:52:20 -04003349 }
3350
James Smart0ff10d42008-01-11 01:52:36 -05003351 spin_lock_irqsave(&phba->hbalock, flags);
3352 list_splice_init(&phba->elsbuf, &completions);
3353 phba->elsbuf_cnt = 0;
3354 phba->elsbuf_prev_cnt = 0;
3355 spin_unlock_irqrestore(&phba->hbalock, flags);
3356
3357 while (!list_empty(&completions)) {
3358 list_remove_head(&completions, buf_ptr,
3359 struct lpfc_dmabuf, list);
3360 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3361 kfree(buf_ptr);
3362 }
3363
dea31012005-04-17 16:05:31 -05003364 /* Return any active mbox cmds */
3365 del_timer_sync(&psli->mbox_tmo);
James Smarted957682007-06-17 19:56:37 -05003366 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003367
3368 spin_lock(&phba->pport->work_port_lock);
3369 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3370 spin_unlock(&phba->pport->work_port_lock);
3371
3372 if (psli->mbox_active) {
3373 list_add_tail(&psli->mbox_active->list, &completions);
James Smart2e0fef82007-06-17 19:56:36 -05003374 psli->mbox_active = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003375 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
dea31012005-04-17 16:05:31 -05003376 }
dea31012005-04-17 16:05:31 -05003377
James Smart92d7f7b2007-06-17 19:56:38 -05003378 /* Return any pending or completed mbox cmds */
3379 list_splice_init(&phba->sli.mboxq, &completions);
3380 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3381 INIT_LIST_HEAD(&psli->mboxq);
3382 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3383
3384 spin_unlock_irqrestore(&phba->hbalock, flags);
3385
3386 while (!list_empty(&completions)) {
3387 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
dea31012005-04-17 16:05:31 -05003388 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3389 if (pmb->mbox_cmpl) {
dea31012005-04-17 16:05:31 -05003390 pmb->mbox_cmpl(phba,pmb);
dea31012005-04-17 16:05:31 -05003391 }
3392 }
dea31012005-04-17 16:05:31 -05003393 return 1;
3394}
3395
3396void
3397lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3398{
3399 uint32_t *src = srcp;
3400 uint32_t *dest = destp;
3401 uint32_t ldata;
3402 int i;
3403
3404 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3405 ldata = *src;
3406 ldata = le32_to_cpu(ldata);
3407 *dest = ldata;
3408 src++;
3409 dest++;
3410 }
3411}
3412
3413int
James Smart2e0fef82007-06-17 19:56:36 -05003414lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3415 struct lpfc_dmabuf *mp)
dea31012005-04-17 16:05:31 -05003416{
3417 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3418 later */
James Smart2e0fef82007-06-17 19:56:36 -05003419 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003420 list_add_tail(&mp->list, &pring->postbufq);
dea31012005-04-17 16:05:31 -05003421 pring->postbufq_cnt++;
James Smart2e0fef82007-06-17 19:56:36 -05003422 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003423 return 0;
3424}
3425
James Smart76bb24e2007-10-27 13:38:00 -04003426uint32_t
3427lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
3428{
3429 spin_lock_irq(&phba->hbalock);
3430 phba->buffer_tag_count++;
3431 /*
3432 * Always set the QUE_BUFTAG_BIT to distiguish between
3433 * a tag assigned by HBQ.
3434 */
3435 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
3436 spin_unlock_irq(&phba->hbalock);
3437 return phba->buffer_tag_count;
3438}
3439
3440struct lpfc_dmabuf *
3441lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3442 uint32_t tag)
3443{
3444 struct lpfc_dmabuf *mp, *next_mp;
3445 struct list_head *slp = &pring->postbufq;
3446
3447 /* Search postbufq, from the begining, looking for a match on tag */
3448 spin_lock_irq(&phba->hbalock);
3449 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3450 if (mp->buffer_tag == tag) {
3451 list_del_init(&mp->list);
3452 pring->postbufq_cnt--;
3453 spin_unlock_irq(&phba->hbalock);
3454 return mp;
3455 }
3456 }
3457
3458 spin_unlock_irq(&phba->hbalock);
3459 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3460 "0410 Cannot find virtual addr for buffer tag on "
3461 "ring %d Data x%lx x%p x%p x%x\n",
3462 pring->ringno, (unsigned long) tag,
3463 slp->next, slp->prev, pring->postbufq_cnt);
3464
3465 return NULL;
3466}
dea31012005-04-17 16:05:31 -05003467
3468struct lpfc_dmabuf *
3469lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3470 dma_addr_t phys)
3471{
3472 struct lpfc_dmabuf *mp, *next_mp;
3473 struct list_head *slp = &pring->postbufq;
3474
3475 /* Search postbufq, from the begining, looking for a match on phys */
James Smart2e0fef82007-06-17 19:56:36 -05003476 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003477 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3478 if (mp->phys == phys) {
3479 list_del_init(&mp->list);
3480 pring->postbufq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05003481 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003482 return mp;
3483 }
3484 }
3485
James Smart2e0fef82007-06-17 19:56:36 -05003486 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003487 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003488 "0410 Cannot find virtual addr for mapped buf on "
dea31012005-04-17 16:05:31 -05003489 "ring %d Data x%llx x%p x%p x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003490 pring->ringno, (unsigned long long)phys,
dea31012005-04-17 16:05:31 -05003491 slp->next, slp->prev, pring->postbufq_cnt);
3492 return NULL;
3493}
3494
3495static void
James Smart2e0fef82007-06-17 19:56:36 -05003496lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3497 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003498{
James Smart2e0fef82007-06-17 19:56:36 -05003499 IOCB_t *irsp = &rspiocb->iocb;
James Smart2680eea2007-04-25 09:52:55 -04003500 uint16_t abort_iotag, abort_context;
James Smart92d7f7b2007-06-17 19:56:38 -05003501 struct lpfc_iocbq *abort_iocb;
James Smart2680eea2007-04-25 09:52:55 -04003502 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3503
3504 abort_iocb = NULL;
James Smart2680eea2007-04-25 09:52:55 -04003505
3506 if (irsp->ulpStatus) {
3507 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3508 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3509
James Smart2e0fef82007-06-17 19:56:36 -05003510 spin_lock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04003511 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3512 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3513
James Smart92d7f7b2007-06-17 19:56:38 -05003514 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003515 "0327 Cannot abort els iocb %p "
James Smart92d7f7b2007-06-17 19:56:38 -05003516 "with tag %x context %x, abort status %x, "
3517 "abort code %x\n",
James Smarte8b62012007-08-02 11:10:09 -04003518 abort_iocb, abort_iotag, abort_context,
3519 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart2680eea2007-04-25 09:52:55 -04003520
3521 /*
3522 * make sure we have the right iocbq before taking it
3523 * off the txcmplq and try to call completion routine.
3524 */
James Smart2e0fef82007-06-17 19:56:36 -05003525 if (!abort_iocb ||
3526 abort_iocb->iocb.ulpContext != abort_context ||
3527 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3528 spin_unlock_irq(&phba->hbalock);
3529 else {
James Smart92d7f7b2007-06-17 19:56:38 -05003530 list_del_init(&abort_iocb->list);
James Smart2680eea2007-04-25 09:52:55 -04003531 pring->txcmplq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05003532 spin_unlock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04003533
James Smart0ff10d42008-01-11 01:52:36 -05003534 /* Firmware could still be in progress of DMAing
3535 * payload, so don't free data buffer till after
3536 * a hbeat.
3537 */
3538 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
3539
James Smart92d7f7b2007-06-17 19:56:38 -05003540 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3541 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3542 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3543 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
James Smart2680eea2007-04-25 09:52:55 -04003544 }
3545 }
3546
James Bottomley604a3e32005-10-29 10:28:33 -05003547 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003548 return;
3549}
3550
James Smart92d7f7b2007-06-17 19:56:38 -05003551static void
3552lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3553 struct lpfc_iocbq *rspiocb)
3554{
3555 IOCB_t *irsp = &rspiocb->iocb;
3556
3557 /* ELS cmd tag <ulpIoTag> completes */
3558 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04003559 "0133 Ignoring ELS cmd tag x%x completion Data: "
James Smart92d7f7b2007-06-17 19:56:38 -05003560 "x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003561 irsp->ulpIoTag, irsp->ulpStatus,
James Smart92d7f7b2007-06-17 19:56:38 -05003562 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smart858c9f62007-06-17 19:56:39 -05003563 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3564 lpfc_ct_free_iocb(phba, cmdiocb);
3565 else
3566 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05003567 return;
3568}
3569
dea31012005-04-17 16:05:31 -05003570int
James Smart2e0fef82007-06-17 19:56:36 -05003571lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3572 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -05003573{
James Smart2e0fef82007-06-17 19:56:36 -05003574 struct lpfc_vport *vport = cmdiocb->vport;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003575 struct lpfc_iocbq *abtsiocbp;
dea31012005-04-17 16:05:31 -05003576 IOCB_t *icmd = NULL;
3577 IOCB_t *iabt = NULL;
James Smart07951072007-04-25 09:51:38 -04003578 int retval = IOCB_ERROR;
3579
James Smart92d7f7b2007-06-17 19:56:38 -05003580 /*
3581 * There are certain command types we don't want to abort. And we
3582 * don't want to abort commands that are already in the process of
3583 * being aborted.
James Smart07951072007-04-25 09:51:38 -04003584 */
3585 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05003586 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
James Smart92d7f7b2007-06-17 19:56:38 -05003587 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3588 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
James Smart07951072007-04-25 09:51:38 -04003589 return 0;
3590
James Smart858c9f62007-06-17 19:56:39 -05003591 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3592 * callback so that nothing happens when it finishes.
James Smart07951072007-04-25 09:51:38 -04003593 */
James Smart858c9f62007-06-17 19:56:39 -05003594 if ((vport->load_flag & FC_UNLOADING) &&
3595 (pring->ringno == LPFC_ELS_RING)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003596 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3597 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3598 else
3599 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
James Smart07951072007-04-25 09:51:38 -04003600 goto abort_iotag_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05003601 }
dea31012005-04-17 16:05:31 -05003602
3603 /* issue ABTS for this IOCB based on iotag */
James Smart92d7f7b2007-06-17 19:56:38 -05003604 abtsiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003605 if (abtsiocbp == NULL)
3606 return 0;
dea31012005-04-17 16:05:31 -05003607
James Smart07951072007-04-25 09:51:38 -04003608 /* This signals the response to set the correct status
3609 * before calling the completion handler.
3610 */
3611 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3612
dea31012005-04-17 16:05:31 -05003613 iabt = &abtsiocbp->iocb;
James Smart07951072007-04-25 09:51:38 -04003614 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3615 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3616 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05003617 iabt->ulpLe = 1;
James Smart07951072007-04-25 09:51:38 -04003618 iabt->ulpClass = icmd->ulpClass;
dea31012005-04-17 16:05:31 -05003619
James Smart2e0fef82007-06-17 19:56:36 -05003620 if (phba->link_state >= LPFC_LINK_UP)
James Smart07951072007-04-25 09:51:38 -04003621 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3622 else
3623 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3624
3625 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -04003626
James Smarte8b62012007-08-02 11:10:09 -04003627 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3628 "0339 Abort xri x%x, original iotag x%x, "
3629 "abort cmd iotag x%x\n",
3630 iabt->un.acxri.abortContextTag,
3631 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
James Smart92d7f7b2007-06-17 19:56:38 -05003632 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
James Smart07951072007-04-25 09:51:38 -04003633
3634abort_iotag_exit:
James Smart2e0fef82007-06-17 19:56:36 -05003635 /*
3636 * Caller to this routine should check for IOCB_ERROR
3637 * and handle it properly. This routine no longer removes
3638 * iocb off txcmplq and call compl in case of IOCB_ERROR.
James Smart07951072007-04-25 09:51:38 -04003639 */
James Smart2e0fef82007-06-17 19:56:36 -05003640 return retval;
dea31012005-04-17 16:05:31 -05003641}
3642
3643static int
James Smart51ef4c22007-08-02 11:10:31 -04003644lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3645 uint16_t tgt_id, uint64_t lun_id,
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003646 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05003647{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003648 struct lpfc_scsi_buf *lpfc_cmd;
3649 struct scsi_cmnd *cmnd;
dea31012005-04-17 16:05:31 -05003650 int rc = 1;
3651
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003652 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3653 return rc;
3654
James Smart51ef4c22007-08-02 11:10:31 -04003655 if (iocbq->vport != vport)
3656 return rc;
3657
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003658 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3659 cmnd = lpfc_cmd->pCmd;
3660
3661 if (cmnd == NULL)
dea31012005-04-17 16:05:31 -05003662 return rc;
3663
3664 switch (ctx_cmd) {
3665 case LPFC_CTX_LUN:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003666 if ((cmnd->device->id == tgt_id) &&
3667 (cmnd->device->lun == lun_id))
dea31012005-04-17 16:05:31 -05003668 rc = 0;
3669 break;
3670 case LPFC_CTX_TGT:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003671 if (cmnd->device->id == tgt_id)
dea31012005-04-17 16:05:31 -05003672 rc = 0;
3673 break;
dea31012005-04-17 16:05:31 -05003674 case LPFC_CTX_HOST:
3675 rc = 0;
3676 break;
3677 default:
3678 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3679 __FUNCTION__, ctx_cmd);
3680 break;
3681 }
3682
3683 return rc;
3684}
3685
3686int
James Smart51ef4c22007-08-02 11:10:31 -04003687lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3688 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05003689{
James Smart51ef4c22007-08-02 11:10:31 -04003690 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003691 struct lpfc_iocbq *iocbq;
3692 int sum, i;
dea31012005-04-17 16:05:31 -05003693
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003694 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3695 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05003696
James Smart51ef4c22007-08-02 11:10:31 -04003697 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
3698 ctx_cmd) == 0)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003699 sum++;
dea31012005-04-17 16:05:31 -05003700 }
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003701
dea31012005-04-17 16:05:31 -05003702 return sum;
3703}
3704
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003705void
James Smart2e0fef82007-06-17 19:56:36 -05003706lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3707 struct lpfc_iocbq *rspiocb)
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003708{
James Bottomley604a3e32005-10-29 10:28:33 -05003709 lpfc_sli_release_iocbq(phba, cmdiocb);
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003710 return;
3711}
3712
dea31012005-04-17 16:05:31 -05003713int
James Smart51ef4c22007-08-02 11:10:31 -04003714lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3715 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
dea31012005-04-17 16:05:31 -05003716{
James Smart51ef4c22007-08-02 11:10:31 -04003717 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003718 struct lpfc_iocbq *iocbq;
3719 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05003720 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003721 int errcnt = 0, ret_val = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003722 int i;
dea31012005-04-17 16:05:31 -05003723
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003724 for (i = 1; i <= phba->sli.last_iotag; i++) {
3725 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05003726
James Smart51ef4c22007-08-02 11:10:31 -04003727 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
James Smart2e0fef82007-06-17 19:56:36 -05003728 abort_cmd) != 0)
dea31012005-04-17 16:05:31 -05003729 continue;
3730
3731 /* issue ABTS for this IOCB based on iotag */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003732 abtsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003733 if (abtsiocb == NULL) {
3734 errcnt++;
3735 continue;
3736 }
dea31012005-04-17 16:05:31 -05003737
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003738 cmd = &iocbq->iocb;
dea31012005-04-17 16:05:31 -05003739 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3740 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3741 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3742 abtsiocb->iocb.ulpLe = 1;
3743 abtsiocb->iocb.ulpClass = cmd->ulpClass;
James Smart2e0fef82007-06-17 19:56:36 -05003744 abtsiocb->vport = phba->pport;
dea31012005-04-17 16:05:31 -05003745
James Smart2e0fef82007-06-17 19:56:36 -05003746 if (lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05003747 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3748 else
3749 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3750
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003751 /* Setup callback routine and issue the command. */
3752 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
dea31012005-04-17 16:05:31 -05003753 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3754 if (ret_val == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -05003755 lpfc_sli_release_iocbq(phba, abtsiocb);
dea31012005-04-17 16:05:31 -05003756 errcnt++;
3757 continue;
3758 }
3759 }
3760
3761 return errcnt;
3762}
3763
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003764static void
3765lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3766 struct lpfc_iocbq *cmdiocbq,
3767 struct lpfc_iocbq *rspiocbq)
dea31012005-04-17 16:05:31 -05003768{
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003769 wait_queue_head_t *pdone_q;
3770 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003771
James Smart2e0fef82007-06-17 19:56:36 -05003772 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003773 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3774 if (cmdiocbq->context2 && rspiocbq)
3775 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3776 &rspiocbq->iocb, sizeof(IOCB_t));
3777
3778 pdone_q = cmdiocbq->context_un.wait_queue;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003779 if (pdone_q)
3780 wake_up(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -05003781 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003782 return;
3783}
3784
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003785/*
3786 * Issue the caller's iocb and wait for its completion, but no longer than the
3787 * caller's timeout. Note that iocb_flags is cleared before the
3788 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3789 * definition this is a wait function.
3790 */
James Smart92d7f7b2007-06-17 19:56:38 -05003791
dea31012005-04-17 16:05:31 -05003792int
James Smart2e0fef82007-06-17 19:56:36 -05003793lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3794 struct lpfc_sli_ring *pring,
3795 struct lpfc_iocbq *piocb,
3796 struct lpfc_iocbq *prspiocbq,
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003797 uint32_t timeout)
dea31012005-04-17 16:05:31 -05003798{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003799 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003800 long timeleft, timeout_req = 0;
3801 int retval = IOCB_SUCCESS;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003802 uint32_t creg_val;
dea31012005-04-17 16:05:31 -05003803
3804 /*
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003805 * If the caller has provided a response iocbq buffer, then context2
3806 * is NULL or its an error.
dea31012005-04-17 16:05:31 -05003807 */
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003808 if (prspiocbq) {
3809 if (piocb->context2)
3810 return IOCB_ERROR;
3811 piocb->context2 = prspiocbq;
dea31012005-04-17 16:05:31 -05003812 }
3813
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003814 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3815 piocb->context_un.wait_queue = &done_q;
3816 piocb->iocb_flag &= ~LPFC_IO_WAKE;
dea31012005-04-17 16:05:31 -05003817
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003818 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3819 creg_val = readl(phba->HCregaddr);
3820 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3821 writel(creg_val, phba->HCregaddr);
3822 readl(phba->HCregaddr); /* flush */
3823 }
3824
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003825 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3826 if (retval == IOCB_SUCCESS) {
3827 timeout_req = timeout * HZ;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003828 timeleft = wait_event_timeout(done_q,
3829 piocb->iocb_flag & LPFC_IO_WAKE,
3830 timeout_req);
dea31012005-04-17 16:05:31 -05003831
James Smart7054a602007-04-25 09:52:34 -04003832 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3833 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003834 "0331 IOCB wake signaled\n");
James Smart7054a602007-04-25 09:52:34 -04003835 } else if (timeleft == 0) {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003836 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003837 "0338 IOCB wait timeout error - no "
3838 "wake response Data x%x\n", timeout);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003839 retval = IOCB_TIMEDOUT;
James Smart7054a602007-04-25 09:52:34 -04003840 } else {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003841 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003842 "0330 IOCB wake NOT set, "
3843 "Data x%x x%lx\n",
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003844 timeout, (timeleft / jiffies));
3845 retval = IOCB_TIMEDOUT;
dea31012005-04-17 16:05:31 -05003846 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003847 } else {
3848 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04003849 ":0332 IOCB wait issue failed, Data x%x\n",
3850 retval);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003851 retval = IOCB_ERROR;
dea31012005-04-17 16:05:31 -05003852 }
3853
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003854 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3855 creg_val = readl(phba->HCregaddr);
3856 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3857 writel(creg_val, phba->HCregaddr);
3858 readl(phba->HCregaddr); /* flush */
3859 }
3860
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003861 if (prspiocbq)
3862 piocb->context2 = NULL;
3863
3864 piocb->context_un.wait_queue = NULL;
3865 piocb->iocb_cmpl = NULL;
dea31012005-04-17 16:05:31 -05003866 return retval;
3867}
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003868
dea31012005-04-17 16:05:31 -05003869int
James Smart2e0fef82007-06-17 19:56:36 -05003870lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
dea31012005-04-17 16:05:31 -05003871 uint32_t timeout)
3872{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003873 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
dea31012005-04-17 16:05:31 -05003874 int retval;
James Smart858c9f62007-06-17 19:56:39 -05003875 unsigned long flag;
dea31012005-04-17 16:05:31 -05003876
3877 /* The caller must leave context1 empty. */
James Smart98c9ea52007-10-27 13:37:33 -04003878 if (pmboxq->context1)
James Smart2e0fef82007-06-17 19:56:36 -05003879 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05003880
3881 /* setup wake call as IOCB callback */
3882 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3883 /* setup context field to pass wait_queue pointer to wake function */
3884 pmboxq->context1 = &done_q;
3885
dea31012005-04-17 16:05:31 -05003886 /* now issue the command */
3887 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3888
3889 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
James Smart7054a602007-04-25 09:52:34 -04003890 wait_event_interruptible_timeout(done_q,
3891 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3892 timeout * HZ);
3893
James Smart858c9f62007-06-17 19:56:39 -05003894 spin_lock_irqsave(&phba->hbalock, flag);
dea31012005-04-17 16:05:31 -05003895 pmboxq->context1 = NULL;
James Smart7054a602007-04-25 09:52:34 -04003896 /*
3897 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3898 * else do not free the resources.
3899 */
3900 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
dea31012005-04-17 16:05:31 -05003901 retval = MBX_SUCCESS;
James Smart858c9f62007-06-17 19:56:39 -05003902 else {
James Smart7054a602007-04-25 09:52:34 -04003903 retval = MBX_TIMEOUT;
James Smart858c9f62007-06-17 19:56:39 -05003904 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3905 }
3906 spin_unlock_irqrestore(&phba->hbalock, flag);
dea31012005-04-17 16:05:31 -05003907 }
3908
dea31012005-04-17 16:05:31 -05003909 return retval;
3910}
3911
James Smartb4c02652006-07-06 15:50:43 -04003912int
3913lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3914{
James Smart2e0fef82007-06-17 19:56:36 -05003915 struct lpfc_vport *vport = phba->pport;
James Smartb4c02652006-07-06 15:50:43 -04003916 int i = 0;
James Smarted957682007-06-17 19:56:37 -05003917 uint32_t ha_copy;
James Smartb4c02652006-07-06 15:50:43 -04003918
James Smart2e0fef82007-06-17 19:56:36 -05003919 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
James Smartb4c02652006-07-06 15:50:43 -04003920 if (i++ > LPFC_MBOX_TMO * 1000)
3921 return 1;
3922
James Smarted957682007-06-17 19:56:37 -05003923 /*
3924 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3925 * did finish. This way we won't get the misleading
3926 * "Stray Mailbox Interrupt" message.
3927 */
3928 spin_lock_irq(&phba->hbalock);
3929 ha_copy = phba->work_ha;
3930 phba->work_ha &= ~HA_MBATT;
3931 spin_unlock_irq(&phba->hbalock);
3932
3933 if (ha_copy & HA_MBATT)
3934 if (lpfc_sli_handle_mb_event(phba) == 0)
3935 i = 0;
James Smartb4c02652006-07-06 15:50:43 -04003936
3937 msleep(1);
3938 }
3939
3940 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3941}
3942
dea31012005-04-17 16:05:31 -05003943irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003944lpfc_intr_handler(int irq, void *dev_id)
dea31012005-04-17 16:05:31 -05003945{
James Smart2e0fef82007-06-17 19:56:36 -05003946 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -05003947 uint32_t ha_copy;
3948 uint32_t work_ha_copy;
3949 unsigned long status;
dea31012005-04-17 16:05:31 -05003950 uint32_t control;
3951
James Smart92d7f7b2007-06-17 19:56:38 -05003952 MAILBOX_t *mbox, *pmbox;
James Smart858c9f62007-06-17 19:56:39 -05003953 struct lpfc_vport *vport;
3954 struct lpfc_nodelist *ndlp;
3955 struct lpfc_dmabuf *mp;
James Smart92d7f7b2007-06-17 19:56:38 -05003956 LPFC_MBOXQ_t *pmb;
3957 int rc;
3958
dea31012005-04-17 16:05:31 -05003959 /*
3960 * Get the driver's phba structure from the dev_id and
3961 * assume the HBA is not interrupting.
3962 */
3963 phba = (struct lpfc_hba *) dev_id;
3964
3965 if (unlikely(!phba))
3966 return IRQ_NONE;
3967
Linas Vepstas8d63f372007-02-14 14:28:36 -06003968 /* If the pci channel is offline, ignore all the interrupts. */
3969 if (unlikely(pci_channel_offline(phba->pcidev)))
3970 return IRQ_NONE;
3971
dea31012005-04-17 16:05:31 -05003972 phba->sli.slistat.sli_intr++;
3973
3974 /*
3975 * Call the HBA to see if it is interrupting. If not, don't claim
3976 * the interrupt
3977 */
3978
3979 /* Ignore all interrupts during initialization. */
James Smart2e0fef82007-06-17 19:56:36 -05003980 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05003981 return IRQ_NONE;
3982
3983 /*
3984 * Read host attention register to determine interrupt source
3985 * Clear Attention Sources, except Error Attention (to
3986 * preserve status) and Link Attention
3987 */
James Smart2e0fef82007-06-17 19:56:36 -05003988 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003989 ha_copy = readl(phba->HAregaddr);
James Smartebdbe652007-04-25 09:53:15 -04003990 /* If somebody is waiting to handle an eratt don't process it
3991 * here. The brdkill function will do this.
3992 */
James Smart2e0fef82007-06-17 19:56:36 -05003993 if (phba->link_flag & LS_IGNORE_ERATT)
James Smartebdbe652007-04-25 09:53:15 -04003994 ha_copy &= ~HA_ERATT;
dea31012005-04-17 16:05:31 -05003995 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3996 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003997 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003998
3999 if (unlikely(!ha_copy))
4000 return IRQ_NONE;
4001
4002 work_ha_copy = ha_copy & phba->work_ha_mask;
4003
4004 if (unlikely(work_ha_copy)) {
4005 if (work_ha_copy & HA_LATT) {
4006 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
4007 /*
4008 * Turn off Link Attention interrupts
4009 * until CLEAR_LA done
4010 */
James Smart2e0fef82007-06-17 19:56:36 -05004011 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004012 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
4013 control = readl(phba->HCregaddr);
4014 control &= ~HC_LAINT_ENA;
4015 writel(control, phba->HCregaddr);
4016 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05004017 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004018 }
4019 else
4020 work_ha_copy &= ~HA_LATT;
4021 }
4022
4023 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
James Smart858c9f62007-06-17 19:56:39 -05004024 /*
4025 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
4026 * the only slow ring.
4027 */
4028 status = (work_ha_copy &
4029 (HA_RXMASK << (4*LPFC_ELS_RING)));
4030 status >>= (4*LPFC_ELS_RING);
4031 if (status & HA_RXMASK) {
4032 spin_lock(&phba->hbalock);
4033 control = readl(phba->HCregaddr);
James Smarta58cbd52007-08-02 11:09:43 -04004034
4035 lpfc_debugfs_slow_ring_trc(phba,
4036 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
4037 control, status,
4038 (uint32_t)phba->sli.slistat.sli_intr);
4039
James Smart858c9f62007-06-17 19:56:39 -05004040 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
James Smarta58cbd52007-08-02 11:09:43 -04004041 lpfc_debugfs_slow_ring_trc(phba,
4042 "ISR Disable ring:"
4043 "pwork:x%x hawork:x%x wait:x%x",
4044 phba->work_ha, work_ha_copy,
4045 (uint32_t)((unsigned long)
4046 phba->work_wait));
4047
James Smart858c9f62007-06-17 19:56:39 -05004048 control &=
4049 ~(HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -05004050 writel(control, phba->HCregaddr);
4051 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -05004052 }
James Smarta58cbd52007-08-02 11:09:43 -04004053 else {
4054 lpfc_debugfs_slow_ring_trc(phba,
4055 "ISR slow ring: pwork:"
4056 "x%x hawork:x%x wait:x%x",
4057 phba->work_ha, work_ha_copy,
4058 (uint32_t)((unsigned long)
4059 phba->work_wait));
4060 }
James Smart858c9f62007-06-17 19:56:39 -05004061 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004062 }
4063 }
4064
4065 if (work_ha_copy & HA_ERATT) {
dea31012005-04-17 16:05:31 -05004066 /*
4067 * There was a link/board error. Read the
4068 * status register to retrieve the error event
4069 * and process it.
4070 */
4071 phba->sli.slistat.err_attn_event++;
4072 /* Save status info */
4073 phba->work_hs = readl(phba->HSregaddr);
4074 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
4075 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
4076
4077 /* Clear Chip error bit */
4078 writel(HA_ERATT, phba->HAregaddr);
4079 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05004080 phba->pport->stopped = 1;
dea31012005-04-17 16:05:31 -05004081 }
4082
James Smart92d7f7b2007-06-17 19:56:38 -05004083 if ((work_ha_copy & HA_MBATT) &&
4084 (phba->sli.mbox_active)) {
4085 pmb = phba->sli.mbox_active;
4086 pmbox = &pmb->mb;
4087 mbox = &phba->slim2p->mbx;
James Smart858c9f62007-06-17 19:56:39 -05004088 vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05004089
4090 /* First check out the status word */
4091 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
4092 if (pmbox->mbxOwner != OWN_HOST) {
4093 /*
4094 * Stray Mailbox Interrupt, mbxCommand <cmd>
4095 * mbxStatus <status>
4096 */
James Smart09372822008-01-11 01:52:54 -05004097 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
James Smart92d7f7b2007-06-17 19:56:38 -05004098 LOG_SLI,
James Smarte8b62012007-08-02 11:10:09 -04004099 "(%d):0304 Stray Mailbox "
James Smart92d7f7b2007-06-17 19:56:38 -05004100 "Interrupt mbxCommand x%x "
4101 "mbxStatus x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004102 (vport ? vport->vpi : 0),
James Smart92d7f7b2007-06-17 19:56:38 -05004103 pmbox->mbxCommand,
4104 pmbox->mbxStatus);
James Smart09372822008-01-11 01:52:54 -05004105 /* clear mailbox attention bit */
4106 work_ha_copy &= ~HA_MBATT;
4107 } else {
4108 phba->last_completion_time = jiffies;
4109 del_timer(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05004110
James Smart09372822008-01-11 01:52:54 -05004111 phba->sli.mbox_active = NULL;
4112 if (pmb->mbox_cmpl) {
4113 lpfc_sli_pcimem_bcopy(mbox, pmbox,
4114 MAILBOX_CMD_SIZE);
James Smart858c9f62007-06-17 19:56:39 -05004115 }
James Smart09372822008-01-11 01:52:54 -05004116 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
4117 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
4118
4119 lpfc_debugfs_disc_trc(vport,
4120 LPFC_DISC_TRC_MBOX_VPORT,
4121 "MBOX dflt rpi: : "
4122 "status:x%x rpi:x%x",
4123 (uint32_t)pmbox->mbxStatus,
4124 pmbox->un.varWords[0], 0);
4125
4126 if (!pmbox->mbxStatus) {
4127 mp = (struct lpfc_dmabuf *)
4128 (pmb->context1);
4129 ndlp = (struct lpfc_nodelist *)
4130 pmb->context2;
4131
4132 /* Reg_LOGIN of dflt RPI was
4133 * successful. new lets get
4134 * rid of the RPI using the
4135 * same mbox buffer.
4136 */
4137 lpfc_unreg_login(phba,
4138 vport->vpi,
4139 pmbox->un.varWords[0],
4140 pmb);
4141 pmb->mbox_cmpl =
4142 lpfc_mbx_cmpl_dflt_rpi;
4143 pmb->context1 = mp;
4144 pmb->context2 = ndlp;
4145 pmb->vport = vport;
4146 spin_lock(&phba->hbalock);
4147 phba->sli.sli_flag &=
4148 ~LPFC_SLI_MBOX_ACTIVE;
4149 spin_unlock(&phba->hbalock);
4150 goto send_current_mbox;
4151 }
4152 }
4153 spin_lock(&phba->pport->work_port_lock);
4154 phba->pport->work_port_events &=
4155 ~WORKER_MBOX_TMO;
4156 spin_unlock(&phba->pport->work_port_lock);
4157 lpfc_mbox_cmpl_put(phba, pmb);
James Smart858c9f62007-06-17 19:56:39 -05004158 }
James Smart92d7f7b2007-06-17 19:56:38 -05004159 }
4160 if ((work_ha_copy & HA_MBATT) &&
4161 (phba->sli.mbox_active == NULL)) {
4162send_next_mbox:
4163 spin_lock(&phba->hbalock);
4164 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4165 pmb = lpfc_mbox_get(phba);
4166 spin_unlock(&phba->hbalock);
James Smart858c9f62007-06-17 19:56:39 -05004167send_current_mbox:
James Smart92d7f7b2007-06-17 19:56:38 -05004168 /* Process next mailbox command if there is one */
4169 if (pmb != NULL) {
4170 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4171 if (rc == MBX_NOT_FINISHED) {
4172 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
4173 lpfc_mbox_cmpl_put(phba, pmb);
4174 goto send_next_mbox;
4175 }
James Smart92d7f7b2007-06-17 19:56:38 -05004176 }
4177
4178 }
4179
James Smart2e0fef82007-06-17 19:56:36 -05004180 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004181 phba->work_ha |= work_ha_copy;
4182 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05004183 lpfc_worker_wake_up(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004184 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004185 }
4186
4187 ha_copy &= ~(phba->work_ha_mask);
4188
4189 /*
4190 * Process all events on FCP ring. Take the optimized path for
4191 * FCP IO. Any other IO is slow path and is handled by
4192 * the worker thread.
4193 */
4194 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4195 status >>= (4*LPFC_FCP_RING);
James Smart858c9f62007-06-17 19:56:39 -05004196 if (status & HA_RXMASK)
dea31012005-04-17 16:05:31 -05004197 lpfc_sli_handle_fast_ring_event(phba,
4198 &phba->sli.ring[LPFC_FCP_RING],
4199 status);
James Smarta4bc3372006-12-02 13:34:16 -05004200
4201 if (phba->cfg_multi_ring_support == 2) {
4202 /*
4203 * Process all events on extra ring. Take the optimized path
4204 * for extra ring IO. Any other IO is slow path and is handled
4205 * by the worker thread.
4206 */
4207 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4208 status >>= (4*LPFC_EXTRA_RING);
James Smart858c9f62007-06-17 19:56:39 -05004209 if (status & HA_RXMASK) {
James Smarta4bc3372006-12-02 13:34:16 -05004210 lpfc_sli_handle_fast_ring_event(phba,
4211 &phba->sli.ring[LPFC_EXTRA_RING],
4212 status);
4213 }
4214 }
dea31012005-04-17 16:05:31 -05004215 return IRQ_HANDLED;
4216
4217} /* lpfc_intr_handler */