blob: 14fe6b000b5923e3154294d06c640c4ea9693b60 [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 Smart92d7f7b2007-06-17 19:56:38 -050052 "%d (%d):0311 Mailbox command x%x cannot " \
53 "issue Data: x%x x%x x%x\n", \
dea31012005-04-17 16:05:31 -050054 phba->brd_no, \
James Smart92d7f7b2007-06-17 19:56:38 -050055 pmbox->vport ? pmbox->vport->vpi : 0, \
56 pmbox->mb.mbxCommand, \
James Smart2e0fef82007-06-17 19:56:36 -050057 phba->pport->port_state, \
dea31012005-04-17 16:05:31 -050058 psli->sli_flag, \
James Smart2e0fef82007-06-17 19:56:36 -050059 flag)
dea31012005-04-17 16:05:31 -050060
61
62/* There are only four IOCB completion types. */
63typedef enum _lpfc_iocb_type {
64 LPFC_UNKNOWN_IOCB,
65 LPFC_UNSOL_IOCB,
66 LPFC_SOL_IOCB,
67 LPFC_ABORT_IOCB
68} lpfc_iocb_type;
69
James Smart92d7f7b2007-06-17 19:56:38 -050070 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
71 * to the start of the ring, and the slot number of the
72 * desired iocb entry, calc a pointer to that entry.
73 */
James Smarted957682007-06-17 19:56:37 -050074static inline IOCB_t *
75lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
76{
77 return (IOCB_t *) (((char *) pring->cmdringaddr) +
78 pring->cmdidx * phba->iocb_cmd_size);
79}
80
81static inline IOCB_t *
82lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
83{
84 return (IOCB_t *) (((char *) pring->rspringaddr) +
85 pring->rspidx * phba->iocb_rsp_size);
86}
87
James Smart2e0fef82007-06-17 19:56:36 -050088static struct lpfc_iocbq *
89__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040090{
91 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
92 struct lpfc_iocbq * iocbq = NULL;
93
94 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
95 return iocbq;
96}
97
James Smart2e0fef82007-06-17 19:56:36 -050098struct lpfc_iocbq *
99lpfc_sli_get_iocbq(struct lpfc_hba *phba)
James Bottomley604a3e32005-10-29 10:28:33 -0500100{
James Smart2e0fef82007-06-17 19:56:36 -0500101 struct lpfc_iocbq * iocbq = NULL;
102 unsigned long iflags;
103
104 spin_lock_irqsave(&phba->hbalock, iflags);
105 iocbq = __lpfc_sli_get_iocbq(phba);
106 spin_unlock_irqrestore(&phba->hbalock, iflags);
107 return iocbq;
108}
109
110void
111__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
112{
113 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
James Bottomley604a3e32005-10-29 10:28:33 -0500114
115 /*
116 * Clean all volatile data fields, preserve iotag and node struct.
117 */
118 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
119 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
120}
121
James Smart2e0fef82007-06-17 19:56:36 -0500122void
123lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
124{
125 unsigned long iflags;
126
127 /*
128 * Clean all volatile data fields, preserve iotag and node struct.
129 */
130 spin_lock_irqsave(&phba->hbalock, iflags);
131 __lpfc_sli_release_iocbq(phba, iocbq);
132 spin_unlock_irqrestore(&phba->hbalock, iflags);
133}
134
dea31012005-04-17 16:05:31 -0500135/*
136 * Translate the iocb command to an iocb command type used to decide the final
137 * disposition of each completed IOCB.
138 */
139static lpfc_iocb_type
140lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
141{
142 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
143
144 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
145 return 0;
146
147 switch (iocb_cmnd) {
148 case CMD_XMIT_SEQUENCE_CR:
149 case CMD_XMIT_SEQUENCE_CX:
150 case CMD_XMIT_BCAST_CN:
151 case CMD_XMIT_BCAST_CX:
152 case CMD_ELS_REQUEST_CR:
153 case CMD_ELS_REQUEST_CX:
154 case CMD_CREATE_XRI_CR:
155 case CMD_CREATE_XRI_CX:
156 case CMD_GET_RPI_CN:
157 case CMD_XMIT_ELS_RSP_CX:
158 case CMD_GET_RPI_CR:
159 case CMD_FCP_IWRITE_CR:
160 case CMD_FCP_IWRITE_CX:
161 case CMD_FCP_IREAD_CR:
162 case CMD_FCP_IREAD_CX:
163 case CMD_FCP_ICMND_CR:
164 case CMD_FCP_ICMND_CX:
James Smartf5603512006-12-02 13:35:43 -0500165 case CMD_FCP_TSEND_CX:
166 case CMD_FCP_TRSP_CX:
167 case CMD_FCP_TRECEIVE_CX:
168 case CMD_FCP_AUTO_TRSP_CX:
dea31012005-04-17 16:05:31 -0500169 case CMD_ADAPTER_MSG:
170 case CMD_ADAPTER_DUMP:
171 case CMD_XMIT_SEQUENCE64_CR:
172 case CMD_XMIT_SEQUENCE64_CX:
173 case CMD_XMIT_BCAST64_CN:
174 case CMD_XMIT_BCAST64_CX:
175 case CMD_ELS_REQUEST64_CR:
176 case CMD_ELS_REQUEST64_CX:
177 case CMD_FCP_IWRITE64_CR:
178 case CMD_FCP_IWRITE64_CX:
179 case CMD_FCP_IREAD64_CR:
180 case CMD_FCP_IREAD64_CX:
181 case CMD_FCP_ICMND64_CR:
182 case CMD_FCP_ICMND64_CX:
James Smartf5603512006-12-02 13:35:43 -0500183 case CMD_FCP_TSEND64_CX:
184 case CMD_FCP_TRSP64_CX:
185 case CMD_FCP_TRECEIVE64_CX:
dea31012005-04-17 16:05:31 -0500186 case CMD_GEN_REQUEST64_CR:
187 case CMD_GEN_REQUEST64_CX:
188 case CMD_XMIT_ELS_RSP64_CX:
189 type = LPFC_SOL_IOCB;
190 break;
191 case CMD_ABORT_XRI_CN:
192 case CMD_ABORT_XRI_CX:
193 case CMD_CLOSE_XRI_CN:
194 case CMD_CLOSE_XRI_CX:
195 case CMD_XRI_ABORTED_CX:
196 case CMD_ABORT_MXRI64_CN:
197 type = LPFC_ABORT_IOCB;
198 break;
199 case CMD_RCV_SEQUENCE_CX:
200 case CMD_RCV_ELS_REQ_CX:
201 case CMD_RCV_SEQUENCE64_CX:
202 case CMD_RCV_ELS_REQ64_CX:
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,
234 "%d: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 Smart92d7f7b2007-06-17 19:56:38 -0500237 phba->brd_no, rc,
dea31012005-04-17 16:05:31 -0500238 pmbox->mbxCommand,
239 pmbox->mbxStatus,
240 i);
James Smart2e0fef82007-06-17 19:56:36 -0500241 phba->link_state = LPFC_HBA_ERROR;
James Smarted957682007-06-17 19:56:37 -0500242 ret = -ENXIO;
243 break;
dea31012005-04-17 16:05:31 -0500244 }
245 }
James Smarted957682007-06-17 19:56:37 -0500246 mempool_free(pmb, phba->mbox_mem_pool);
247 return ret;
dea31012005-04-17 16:05:31 -0500248}
249
250static int
James Smart2e0fef82007-06-17 19:56:36 -0500251lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
252 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -0500253{
dea31012005-04-17 16:05:31 -0500254 list_add_tail(&piocb->list, &pring->txcmplq);
255 pring->txcmplq_cnt++;
James Smart92d7f7b2007-06-17 19:56:38 -0500256 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
257 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
258 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
259 if (!piocb->vport)
260 BUG();
261 else
262 mod_timer(&piocb->vport->els_tmofunc,
263 jiffies + HZ * (phba->fc_ratov << 1));
264 }
265
dea31012005-04-17 16:05:31 -0500266
James Smart2e0fef82007-06-17 19:56:36 -0500267 return 0;
dea31012005-04-17 16:05:31 -0500268}
269
270static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500271lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500272{
dea31012005-04-17 16:05:31 -0500273 struct lpfc_iocbq *cmd_iocb;
274
James Smart858c9f62007-06-17 19:56:39 -0500275 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
276 if (cmd_iocb != NULL)
dea31012005-04-17 16:05:31 -0500277 pring->txq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -0500278 return cmd_iocb;
dea31012005-04-17 16:05:31 -0500279}
280
281static IOCB_t *
282lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
283{
James Smarted957682007-06-17 19:56:37 -0500284 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
285 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
286 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -0500287 uint32_t max_cmd_idx = pring->numCiocb;
dea31012005-04-17 16:05:31 -0500288
289 if ((pring->next_cmdidx == pring->cmdidx) &&
290 (++pring->next_cmdidx >= max_cmd_idx))
291 pring->next_cmdidx = 0;
292
293 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
294
295 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
296
297 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
298 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
299 "%d:0315 Ring %d issue: portCmdGet %d "
300 "is bigger then cmd ring %d\n",
301 phba->brd_no, pring->ringno,
302 pring->local_getidx, max_cmd_idx);
303
James Smart2e0fef82007-06-17 19:56:36 -0500304 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500305 /*
306 * All error attention handlers are posted to
307 * worker thread
308 */
309 phba->work_ha |= HA_ERATT;
310 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -0500311
312 /* hbalock should already be held */
dea31012005-04-17 16:05:31 -0500313 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -0500314 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -0500315
316 return NULL;
317 }
318
319 if (pring->local_getidx == pring->next_cmdidx)
320 return NULL;
321 }
322
James Smarted957682007-06-17 19:56:37 -0500323 return lpfc_cmd_iocb(phba, pring);
dea31012005-04-17 16:05:31 -0500324}
325
James Bottomley604a3e32005-10-29 10:28:33 -0500326uint16_t
James Smart2e0fef82007-06-17 19:56:36 -0500327lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
dea31012005-04-17 16:05:31 -0500328{
James Smart2e0fef82007-06-17 19:56:36 -0500329 struct lpfc_iocbq **new_arr;
330 struct lpfc_iocbq **old_arr;
James Bottomley604a3e32005-10-29 10:28:33 -0500331 size_t new_len;
332 struct lpfc_sli *psli = &phba->sli;
333 uint16_t iotag;
dea31012005-04-17 16:05:31 -0500334
James Smart2e0fef82007-06-17 19:56:36 -0500335 spin_lock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500336 iotag = psli->last_iotag;
337 if(++iotag < psli->iocbq_lookup_len) {
338 psli->last_iotag = iotag;
339 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -0500340 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500341 iocbq->iotag = iotag;
342 return iotag;
James Smart2e0fef82007-06-17 19:56:36 -0500343 } else if (psli->iocbq_lookup_len < (0xffff
James Bottomley604a3e32005-10-29 10:28:33 -0500344 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
345 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
James Smart2e0fef82007-06-17 19:56:36 -0500346 spin_unlock_irq(&phba->hbalock);
347 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
James Bottomley604a3e32005-10-29 10:28:33 -0500348 GFP_KERNEL);
349 if (new_arr) {
James Smart2e0fef82007-06-17 19:56:36 -0500350 spin_lock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500351 old_arr = psli->iocbq_lookup;
352 if (new_len <= psli->iocbq_lookup_len) {
353 /* highly unprobable case */
354 kfree(new_arr);
355 iotag = psli->last_iotag;
356 if(++iotag < psli->iocbq_lookup_len) {
357 psli->last_iotag = iotag;
358 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -0500359 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500360 iocbq->iotag = iotag;
361 return iotag;
362 }
James Smart2e0fef82007-06-17 19:56:36 -0500363 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500364 return 0;
365 }
366 if (psli->iocbq_lookup)
367 memcpy(new_arr, old_arr,
368 ((psli->last_iotag + 1) *
369 sizeof (struct lpfc_iocbq *)));
370 psli->iocbq_lookup = new_arr;
371 psli->iocbq_lookup_len = new_len;
372 psli->last_iotag = iotag;
373 psli->iocbq_lookup[iotag] = iocbq;
James Smart2e0fef82007-06-17 19:56:36 -0500374 spin_unlock_irq(&phba->hbalock);
James Bottomley604a3e32005-10-29 10:28:33 -0500375 iocbq->iotag = iotag;
376 kfree(old_arr);
377 return iotag;
378 }
James Smart8f6d98d2006-08-01 07:34:00 -0400379 } else
James Smart2e0fef82007-06-17 19:56:36 -0500380 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500381
James Bottomley604a3e32005-10-29 10:28:33 -0500382 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
383 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
384 phba->brd_no, psli->last_iotag);
dea31012005-04-17 16:05:31 -0500385
James Bottomley604a3e32005-10-29 10:28:33 -0500386 return 0;
dea31012005-04-17 16:05:31 -0500387}
388
389static void
390lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
391 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
392{
393 /*
James Bottomley604a3e32005-10-29 10:28:33 -0500394 * Set up an iotag
dea31012005-04-17 16:05:31 -0500395 */
James Bottomley604a3e32005-10-29 10:28:33 -0500396 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
dea31012005-04-17 16:05:31 -0500397
James Smarta58cbd52007-08-02 11:09:43 -0400398 if (pring->ringno == LPFC_ELS_RING) {
399 lpfc_debugfs_slow_ring_trc(phba,
400 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
401 *(((uint32_t *) &nextiocb->iocb) + 4),
402 *(((uint32_t *) &nextiocb->iocb) + 6),
403 *(((uint32_t *) &nextiocb->iocb) + 7));
404 }
405
dea31012005-04-17 16:05:31 -0500406 /*
407 * Issue iocb command to adapter
408 */
James Smart92d7f7b2007-06-17 19:56:38 -0500409 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
dea31012005-04-17 16:05:31 -0500410 wmb();
411 pring->stats.iocb_cmd++;
412
413 /*
414 * If there is no completion routine to call, we can release the
415 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
416 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
417 */
418 if (nextiocb->iocb_cmpl)
419 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
James Bottomley604a3e32005-10-29 10:28:33 -0500420 else
James Smart2e0fef82007-06-17 19:56:36 -0500421 __lpfc_sli_release_iocbq(phba, nextiocb);
dea31012005-04-17 16:05:31 -0500422
423 /*
424 * Let the HBA know what IOCB slot will be the next one the
425 * driver will put a command into.
426 */
427 pring->cmdidx = pring->next_cmdidx;
James Smarted957682007-06-17 19:56:37 -0500428 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
dea31012005-04-17 16:05:31 -0500429}
430
431static void
James Smart2e0fef82007-06-17 19:56:36 -0500432lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500433{
434 int ringno = pring->ringno;
435
436 pring->flag |= LPFC_CALL_RING_AVAILABLE;
437
438 wmb();
439
440 /*
441 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
442 * The HBA will tell us when an IOCB entry is available.
443 */
444 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
445 readl(phba->CAregaddr); /* flush */
446
447 pring->stats.iocb_cmd_full++;
448}
449
450static void
James Smart2e0fef82007-06-17 19:56:36 -0500451lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500452{
453 int ringno = pring->ringno;
454
455 /*
456 * Tell the HBA that there is work to do in this ring.
457 */
458 wmb();
459 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
460 readl(phba->CAregaddr); /* flush */
461}
462
463static void
James Smart2e0fef82007-06-17 19:56:36 -0500464lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
dea31012005-04-17 16:05:31 -0500465{
466 IOCB_t *iocb;
467 struct lpfc_iocbq *nextiocb;
468
469 /*
470 * Check to see if:
471 * (a) there is anything on the txq to send
472 * (b) link is up
473 * (c) link attention events can be processed (fcp ring only)
474 * (d) IOCB processing is not blocked by the outstanding mbox command.
475 */
476 if (pring->txq_cnt &&
James Smart2e0fef82007-06-17 19:56:36 -0500477 lpfc_is_link_up(phba) &&
dea31012005-04-17 16:05:31 -0500478 (pring->ringno != phba->sli.fcp_ring ||
479 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
480 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
481
482 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
483 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
484 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
485
486 if (iocb)
487 lpfc_sli_update_ring(phba, pring);
488 else
489 lpfc_sli_update_full_ring(phba, pring);
490 }
491
492 return;
493}
494
495/* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
496static void
James Smart2e0fef82007-06-17 19:56:36 -0500497lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
dea31012005-04-17 16:05:31 -0500498{
James Smarted957682007-06-17 19:56:37 -0500499 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
500 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
501 &phba->slim2p->mbx.us.s2.port[ringno];
James Smart2e0fef82007-06-17 19:56:36 -0500502 unsigned long iflags;
dea31012005-04-17 16:05:31 -0500503
504 /* If the ring is active, flag it */
James Smart2e0fef82007-06-17 19:56:36 -0500505 spin_lock_irqsave(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -0500506 if (phba->sli.ring[ringno].cmdringaddr) {
507 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
508 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
509 /*
510 * Force update of the local copy of cmdGetInx
511 */
512 phba->sli.ring[ringno].local_getidx
513 = le32_to_cpu(pgp->cmdGetInx);
dea31012005-04-17 16:05:31 -0500514 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
dea31012005-04-17 16:05:31 -0500515 }
516 }
James Smart2e0fef82007-06-17 19:56:36 -0500517 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -0500518}
519
James Smarted957682007-06-17 19:56:37 -0500520struct lpfc_hbq_entry *
521lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
522{
523 struct hbq_s *hbqp = &phba->hbqs[hbqno];
524
525 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
526 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
527 hbqp->next_hbqPutIdx = 0;
528
529 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500530 uint32_t raw_index = phba->hbq_get[hbqno];
James Smarted957682007-06-17 19:56:37 -0500531 uint32_t getidx = le32_to_cpu(raw_index);
532
533 hbqp->local_hbqGetIdx = getidx;
534
535 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
536 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -0500537 LOG_SLI | LOG_VPORT,
James Smarted957682007-06-17 19:56:37 -0500538 "%d:1802 HBQ %d: local_hbqGetIdx "
539 "%u is > than hbqp->entry_count %u\n",
540 phba->brd_no, hbqno,
541 hbqp->local_hbqGetIdx,
542 hbqp->entry_count);
543
544 phba->link_state = LPFC_HBA_ERROR;
545 return NULL;
546 }
547
548 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
549 return NULL;
550 }
551
552 return (struct lpfc_hbq_entry *) phba->hbqslimp.virt + hbqp->hbqPutIdx;
553}
554
555void
556lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
557{
James Smart92d7f7b2007-06-17 19:56:38 -0500558 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
559 struct hbq_dmabuf *hbq_buf;
James Smarted957682007-06-17 19:56:37 -0500560
James Smarted957682007-06-17 19:56:37 -0500561 /* Return all memory used by all HBQs */
James Smart92d7f7b2007-06-17 19:56:38 -0500562 list_for_each_entry_safe(dmabuf, next_dmabuf,
563 &phba->hbq_buffer_list, list) {
564 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
565 list_del(&hbq_buf->dbuf.list);
566 lpfc_hbq_free(phba, hbq_buf->dbuf.virt, hbq_buf->dbuf.phys);
567 kfree(hbq_buf);
James Smarted957682007-06-17 19:56:37 -0500568 }
James Smarted957682007-06-17 19:56:37 -0500569}
570
571static void
572lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
James Smart92d7f7b2007-06-17 19:56:38 -0500573 struct hbq_dmabuf *hbq_buf)
James Smarted957682007-06-17 19:56:37 -0500574{
575 struct lpfc_hbq_entry *hbqe;
James Smart92d7f7b2007-06-17 19:56:38 -0500576 dma_addr_t physaddr = hbq_buf->dbuf.phys;
James Smarted957682007-06-17 19:56:37 -0500577
578 /* Get next HBQ entry slot to use */
579 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
580 if (hbqe) {
581 struct hbq_s *hbqp = &phba->hbqs[hbqno];
582
James Smart92d7f7b2007-06-17 19:56:38 -0500583 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
584 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
James Smarted957682007-06-17 19:56:37 -0500585 hbqe->bde.tus.f.bdeSize = FCELSSIZE;
586 hbqe->bde.tus.f.bdeFlags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500587 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
588 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
589 /* Sync SLIM */
James Smarted957682007-06-17 19:56:37 -0500590 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
591 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
James Smart92d7f7b2007-06-17 19:56:38 -0500592 /* flush */
James Smarted957682007-06-17 19:56:37 -0500593 readl(phba->hbq_put + hbqno);
James Smart92d7f7b2007-06-17 19:56:38 -0500594 list_add_tail(&hbq_buf->dbuf.list, &phba->hbq_buffer_list);
James Smarted957682007-06-17 19:56:37 -0500595 }
596}
597
James Smart92d7f7b2007-06-17 19:56:38 -0500598static struct lpfc_hbq_init lpfc_els_hbq = {
599 .rn = 1,
600 .entry_count = 200,
601 .mask_count = 0,
602 .profile = 0,
603 .ring_mask = 1 << LPFC_ELS_RING,
604 .buffer_count = 0,
605 .init_count = 20,
606 .add_count = 5,
607};
James Smarted957682007-06-17 19:56:37 -0500608
James Smart92d7f7b2007-06-17 19:56:38 -0500609static struct lpfc_hbq_init *lpfc_hbq_defs[] = {
610 &lpfc_els_hbq,
611};
612
613int
614lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
615{
616 uint32_t i, start, end;
617 struct hbq_dmabuf *hbq_buffer;
618
619 start = lpfc_hbq_defs[hbqno]->buffer_count;
620 end = count + lpfc_hbq_defs[hbqno]->buffer_count;
621 if (end > lpfc_hbq_defs[hbqno]->entry_count) {
622 end = lpfc_hbq_defs[hbqno]->entry_count;
James Smarted957682007-06-17 19:56:37 -0500623 }
James Smart92d7f7b2007-06-17 19:56:38 -0500624
625 /* Populate HBQ entries */
626 for (i = start; i < end; i++) {
627 hbq_buffer = kmalloc(sizeof(struct hbq_dmabuf),
628 GFP_KERNEL);
629 if (!hbq_buffer)
630 return 1;
631 hbq_buffer->dbuf.virt = lpfc_hbq_alloc(phba, MEM_PRI,
632 &hbq_buffer->dbuf.phys);
633 if (hbq_buffer->dbuf.virt == NULL)
634 return 1;
635 hbq_buffer->tag = (i | (hbqno << 16));
636 lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer);
637 lpfc_hbq_defs[hbqno]->buffer_count++;
638 }
639 return 0;
James Smarted957682007-06-17 19:56:37 -0500640}
641
642int
James Smart92d7f7b2007-06-17 19:56:38 -0500643lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -0500644{
James Smart92d7f7b2007-06-17 19:56:38 -0500645 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
646 lpfc_hbq_defs[qno]->add_count));
James Smarted957682007-06-17 19:56:37 -0500647}
648
James Smart92d7f7b2007-06-17 19:56:38 -0500649int
650lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
James Smarted957682007-06-17 19:56:37 -0500651{
James Smart92d7f7b2007-06-17 19:56:38 -0500652 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
653 lpfc_hbq_defs[qno]->init_count));
James Smarted957682007-06-17 19:56:37 -0500654}
655
656struct hbq_dmabuf *
657lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
658{
James Smart92d7f7b2007-06-17 19:56:38 -0500659 struct lpfc_dmabuf *d_buf;
660 struct hbq_dmabuf *hbq_buf;
James Smarted957682007-06-17 19:56:37 -0500661
James Smart92d7f7b2007-06-17 19:56:38 -0500662 list_for_each_entry(d_buf, &phba->hbq_buffer_list, list) {
663 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
664 if ((hbq_buf->tag & 0xffff) == tag) {
665 return hbq_buf;
James Smarted957682007-06-17 19:56:37 -0500666 }
667 }
James Smart92d7f7b2007-06-17 19:56:38 -0500668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
669 "%d:1803 Bad hbq tag. Data: x%x x%x\n",
670 phba->brd_no, tag,
671 lpfc_hbq_defs[tag >> 16]->buffer_count);
672 return NULL;
James Smarted957682007-06-17 19:56:37 -0500673}
674
675void
676lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *sp)
677{
678 uint32_t hbqno;
679
680 if (sp) {
681 hbqno = sp->tag >> 16;
682 lpfc_sli_hbq_to_firmware(phba, hbqno, sp);
683 }
684}
685
dea31012005-04-17 16:05:31 -0500686static int
687lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
688{
689 uint8_t ret;
690
691 switch (mbxCommand) {
692 case MBX_LOAD_SM:
693 case MBX_READ_NV:
694 case MBX_WRITE_NV:
695 case MBX_RUN_BIU_DIAG:
696 case MBX_INIT_LINK:
697 case MBX_DOWN_LINK:
698 case MBX_CONFIG_LINK:
699 case MBX_CONFIG_RING:
700 case MBX_RESET_RING:
701 case MBX_READ_CONFIG:
702 case MBX_READ_RCONFIG:
703 case MBX_READ_SPARM:
704 case MBX_READ_STATUS:
705 case MBX_READ_RPI:
706 case MBX_READ_XRI:
707 case MBX_READ_REV:
708 case MBX_READ_LNK_STAT:
709 case MBX_REG_LOGIN:
710 case MBX_UNREG_LOGIN:
711 case MBX_READ_LA:
712 case MBX_CLEAR_LA:
713 case MBX_DUMP_MEMORY:
714 case MBX_DUMP_CONTEXT:
715 case MBX_RUN_DIAGS:
716 case MBX_RESTART:
717 case MBX_UPDATE_CFG:
718 case MBX_DOWN_LOAD:
719 case MBX_DEL_LD_ENTRY:
720 case MBX_RUN_PROGRAM:
721 case MBX_SET_MASK:
722 case MBX_SET_SLIM:
723 case MBX_UNREG_D_ID:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500724 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -0500725 case MBX_CONFIG_FARP:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500726 case MBX_BEACON:
dea31012005-04-17 16:05:31 -0500727 case MBX_LOAD_AREA:
728 case MBX_RUN_BIU_DIAG64:
729 case MBX_CONFIG_PORT:
730 case MBX_READ_SPARM64:
731 case MBX_READ_RPI64:
732 case MBX_REG_LOGIN64:
733 case MBX_READ_LA64:
734 case MBX_FLASH_WR_ULA:
735 case MBX_SET_DEBUG:
736 case MBX_LOAD_EXP_ROM:
James Smart92d7f7b2007-06-17 19:56:38 -0500737 case MBX_REG_VPI:
738 case MBX_UNREG_VPI:
James Smart858c9f62007-06-17 19:56:39 -0500739 case MBX_HEARTBEAT:
dea31012005-04-17 16:05:31 -0500740 ret = mbxCommand;
741 break;
742 default:
743 ret = MBX_SHUTDOWN;
744 break;
745 }
James Smart2e0fef82007-06-17 19:56:36 -0500746 return ret;
dea31012005-04-17 16:05:31 -0500747}
748static void
James Smart2e0fef82007-06-17 19:56:36 -0500749lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
dea31012005-04-17 16:05:31 -0500750{
751 wait_queue_head_t *pdone_q;
James Smart858c9f62007-06-17 19:56:39 -0500752 unsigned long drvr_flag;
dea31012005-04-17 16:05:31 -0500753
754 /*
755 * If pdone_q is empty, the driver thread gave up waiting and
756 * continued running.
757 */
James Smart7054a602007-04-25 09:52:34 -0400758 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
James Smart858c9f62007-06-17 19:56:39 -0500759 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -0500760 pdone_q = (wait_queue_head_t *) pmboxq->context1;
761 if (pdone_q)
762 wake_up_interruptible(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -0500763 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -0500764 return;
765}
766
767void
James Smart2e0fef82007-06-17 19:56:36 -0500768lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500769{
770 struct lpfc_dmabuf *mp;
James Smart7054a602007-04-25 09:52:34 -0400771 uint16_t rpi;
772 int rc;
773
dea31012005-04-17 16:05:31 -0500774 mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart7054a602007-04-25 09:52:34 -0400775
dea31012005-04-17 16:05:31 -0500776 if (mp) {
777 lpfc_mbuf_free(phba, mp->virt, mp->phys);
778 kfree(mp);
779 }
James Smart7054a602007-04-25 09:52:34 -0400780
781 /*
782 * If a REG_LOGIN succeeded after node is destroyed or node
783 * is in re-discovery driver need to cleanup the RPI.
784 */
James Smart2e0fef82007-06-17 19:56:36 -0500785 if (!(phba->pport->load_flag & FC_UNLOADING) &&
786 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
787 !pmb->mb.mbxStatus) {
James Smart7054a602007-04-25 09:52:34 -0400788
789 rpi = pmb->mb.un.varWords[0];
James Smart92d7f7b2007-06-17 19:56:38 -0500790 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
791 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart7054a602007-04-25 09:52:34 -0400792 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
793 if (rc != MBX_NOT_FINISHED)
794 return;
795 }
796
James Smart2e0fef82007-06-17 19:56:36 -0500797 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500798 return;
799}
800
801int
James Smart2e0fef82007-06-17 19:56:36 -0500802lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500803{
James Smart92d7f7b2007-06-17 19:56:38 -0500804 MAILBOX_t *pmbox;
dea31012005-04-17 16:05:31 -0500805 LPFC_MBOXQ_t *pmb;
James Smart92d7f7b2007-06-17 19:56:38 -0500806 int rc;
807 LIST_HEAD(cmplq);
dea31012005-04-17 16:05:31 -0500808
809 phba->sli.slistat.mbox_event++;
810
James Smart92d7f7b2007-06-17 19:56:38 -0500811 /* Get all completed mailboxe buffers into the cmplq */
812 spin_lock_irq(&phba->hbalock);
813 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
814 spin_unlock_irq(&phba->hbalock);
815
dea31012005-04-17 16:05:31 -0500816 /* Get a Mailbox buffer to setup mailbox commands for callback */
James Smart92d7f7b2007-06-17 19:56:38 -0500817 do {
818 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
819 if (pmb == NULL)
820 break;
821
dea31012005-04-17 16:05:31 -0500822 pmbox = &pmb->mb;
dea31012005-04-17 16:05:31 -0500823
James Smart858c9f62007-06-17 19:56:39 -0500824 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
825 if (pmb->vport) {
826 lpfc_debugfs_disc_trc(pmb->vport,
827 LPFC_DISC_TRC_MBOX_VPORT,
828 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
829 (uint32_t)pmbox->mbxCommand,
830 pmbox->un.varWords[0],
831 pmbox->un.varWords[1]);
832 }
833 else {
834 lpfc_debugfs_disc_trc(phba->pport,
835 LPFC_DISC_TRC_MBOX,
836 "MBOX cmpl: cmd:x%x mb:x%x x%x",
837 (uint32_t)pmbox->mbxCommand,
838 pmbox->un.varWords[0],
839 pmbox->un.varWords[1]);
840 }
841 }
842
dea31012005-04-17 16:05:31 -0500843 /*
844 * It is a fatal error if unknown mbox command completion.
845 */
846 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
847 MBX_SHUTDOWN) {
848
849 /* Unknow mailbox command compl */
James Smart92d7f7b2007-06-17 19:56:38 -0500850 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
851 "%d (%d):0323 Unknown Mailbox command "
852 "%x Cmpl\n",
853 phba->brd_no,
854 pmb->vport ? pmb->vport->vpi : 0,
855 pmbox->mbxCommand);
James Smart2e0fef82007-06-17 19:56:36 -0500856 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500857 phba->work_hs = HS_FFER3;
858 lpfc_handle_eratt(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500859 continue;
dea31012005-04-17 16:05:31 -0500860 }
861
dea31012005-04-17 16:05:31 -0500862 if (pmbox->mbxStatus) {
863 phba->sli.slistat.mbox_stat_err++;
864 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
865 /* Mbox cmd cmpl error - RETRYing */
James Smart92d7f7b2007-06-17 19:56:38 -0500866 lpfc_printf_log(phba, KERN_INFO,
867 LOG_MBOX | LOG_SLI,
868 "%d (%d):0305 Mbox cmd cmpl "
869 "error - RETRYing Data: x%x "
870 "x%x x%x x%x\n",
871 phba->brd_no,
872 pmb->vport ? pmb->vport->vpi :0,
873 pmbox->mbxCommand,
874 pmbox->mbxStatus,
875 pmbox->un.varWords[0],
876 pmb->vport->port_state);
dea31012005-04-17 16:05:31 -0500877 pmbox->mbxStatus = 0;
878 pmbox->mbxOwner = OWN_HOST;
James Smart2e0fef82007-06-17 19:56:36 -0500879 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500880 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500882 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
883 if (rc == MBX_SUCCESS)
James Smart92d7f7b2007-06-17 19:56:38 -0500884 continue;
dea31012005-04-17 16:05:31 -0500885 }
886 }
887
888 /* Mailbox cmd <cmd> Cmpl <cmpl> */
James Smart92d7f7b2007-06-17 19:56:38 -0500889 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
890 "%d (%d):0307 Mailbox cmd x%x Cmpl x%p "
dea31012005-04-17 16:05:31 -0500891 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
892 phba->brd_no,
James Smart92d7f7b2007-06-17 19:56:38 -0500893 pmb->vport ? pmb->vport->vpi : 0,
dea31012005-04-17 16:05:31 -0500894 pmbox->mbxCommand,
895 pmb->mbox_cmpl,
896 *((uint32_t *) pmbox),
897 pmbox->un.varWords[0],
898 pmbox->un.varWords[1],
899 pmbox->un.varWords[2],
900 pmbox->un.varWords[3],
901 pmbox->un.varWords[4],
902 pmbox->un.varWords[5],
903 pmbox->un.varWords[6],
904 pmbox->un.varWords[7]);
905
James Smart92d7f7b2007-06-17 19:56:38 -0500906 if (pmb->mbox_cmpl)
dea31012005-04-17 16:05:31 -0500907 pmb->mbox_cmpl(phba,pmb);
James Smart92d7f7b2007-06-17 19:56:38 -0500908 } while (1);
James Smart2e0fef82007-06-17 19:56:36 -0500909 return 0;
dea31012005-04-17 16:05:31 -0500910}
James Smart92d7f7b2007-06-17 19:56:38 -0500911
912static struct lpfc_dmabuf *
913lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
914{
915 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
916
917 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
918 if (hbq_entry == NULL)
919 return NULL;
920 list_del(&hbq_entry->dbuf.list);
921 new_hbq_entry = kmalloc(sizeof(struct hbq_dmabuf), GFP_ATOMIC);
922 if (new_hbq_entry == NULL)
923 return &hbq_entry->dbuf;
924 new_hbq_entry->dbuf = hbq_entry->dbuf;
925 new_hbq_entry->tag = -1;
926 hbq_entry->dbuf.virt = lpfc_hbq_alloc(phba, 0, &hbq_entry->dbuf.phys);
927 if (hbq_entry->dbuf.virt == NULL) {
928 kfree(new_hbq_entry);
929 return &hbq_entry->dbuf;
930 }
931 lpfc_sli_free_hbq(phba, hbq_entry);
932 return &new_hbq_entry->dbuf;
933}
934
dea31012005-04-17 16:05:31 -0500935static int
936lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
937 struct lpfc_iocbq *saveq)
938{
939 IOCB_t * irsp;
940 WORD5 * w5p;
941 uint32_t Rctl, Type;
942 uint32_t match, i;
943
944 match = 0;
945 irsp = &(saveq->iocb);
946 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
James Smarted957682007-06-17 19:56:37 -0500947 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
948 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
949 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
dea31012005-04-17 16:05:31 -0500950 Rctl = FC_ELS_REQ;
951 Type = FC_ELS_DATA;
952 } else {
953 w5p =
954 (WORD5 *) & (saveq->iocb.un.
955 ulpWord[5]);
956 Rctl = w5p->hcsw.Rctl;
957 Type = w5p->hcsw.Type;
958
959 /* Firmware Workaround */
960 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
James Smart92d7f7b2007-06-17 19:56:38 -0500961 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
962 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
dea31012005-04-17 16:05:31 -0500963 Rctl = FC_ELS_REQ;
964 Type = FC_ELS_DATA;
965 w5p->hcsw.Rctl = Rctl;
966 w5p->hcsw.Type = Type;
967 }
968 }
James Smart92d7f7b2007-06-17 19:56:38 -0500969
970 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
971 if (irsp->ulpBdeCount != 0)
972 saveq->context2 = lpfc_sli_replace_hbqbuff(phba,
973 irsp->un.ulpWord[3]);
974 if (irsp->ulpBdeCount == 2)
975 saveq->context3 = lpfc_sli_replace_hbqbuff(phba,
976 irsp->un.ulpWord[15]);
977 }
978
dea31012005-04-17 16:05:31 -0500979 /* unSolicited Responses */
980 if (pring->prt[0].profile) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500981 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
982 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
983 saveq);
dea31012005-04-17 16:05:31 -0500984 match = 1;
985 } else {
986 /* We must search, based on rctl / type
987 for the right routine */
988 for (i = 0; i < pring->num_mask;
989 i++) {
990 if ((pring->prt[i].rctl ==
991 Rctl)
992 && (pring->prt[i].
993 type == Type)) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500994 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
995 (pring->prt[i].lpfc_sli_rcv_unsol_event)
996 (phba, pring, saveq);
dea31012005-04-17 16:05:31 -0500997 match = 1;
998 break;
999 }
1000 }
1001 }
1002 if (match == 0) {
1003 /* Unexpected Rctl / Type received */
1004 /* Ring <ringno> handler: unexpected
1005 Rctl <Rctl> Type <Type> received */
James Smart92d7f7b2007-06-17 19:56:38 -05001006 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
dea31012005-04-17 16:05:31 -05001007 "%d:0313 Ring %d handler: unexpected Rctl x%x "
James Smart92d7f7b2007-06-17 19:56:38 -05001008 "Type x%x received\n",
dea31012005-04-17 16:05:31 -05001009 phba->brd_no,
1010 pring->ringno,
1011 Rctl,
1012 Type);
1013 }
James Smart92d7f7b2007-06-17 19:56:38 -05001014 return 1;
dea31012005-04-17 16:05:31 -05001015}
1016
1017static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -05001018lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1019 struct lpfc_sli_ring *pring,
1020 struct lpfc_iocbq *prspiocb)
dea31012005-04-17 16:05:31 -05001021{
dea31012005-04-17 16:05:31 -05001022 struct lpfc_iocbq *cmd_iocb = NULL;
1023 uint16_t iotag;
1024
James Bottomley604a3e32005-10-29 10:28:33 -05001025 iotag = prspiocb->iocb.ulpIoTag;
dea31012005-04-17 16:05:31 -05001026
James Bottomley604a3e32005-10-29 10:28:33 -05001027 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1028 cmd_iocb = phba->sli.iocbq_lookup[iotag];
James Smart92d7f7b2007-06-17 19:56:38 -05001029 list_del_init(&cmd_iocb->list);
James Bottomley604a3e32005-10-29 10:28:33 -05001030 pring->txcmplq_cnt--;
1031 return cmd_iocb;
dea31012005-04-17 16:05:31 -05001032 }
1033
dea31012005-04-17 16:05:31 -05001034 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Bottomley604a3e32005-10-29 10:28:33 -05001035 "%d:0317 iotag x%x is out off "
1036 "range: max iotag x%x wd0 x%x\n",
1037 phba->brd_no, iotag,
1038 phba->sli.last_iotag,
1039 *(((uint32_t *) &prspiocb->iocb) + 7));
dea31012005-04-17 16:05:31 -05001040 return NULL;
1041}
1042
1043static int
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05001045 struct lpfc_iocbq *saveq)
1046{
James Smart2e0fef82007-06-17 19:56:36 -05001047 struct lpfc_iocbq *cmdiocbp;
dea31012005-04-17 16:05:31 -05001048 int rc = 1;
1049 unsigned long iflag;
1050
1051 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
James Smart2e0fef82007-06-17 19:56:36 -05001052 spin_lock_irqsave(&phba->hbalock, iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001053 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
James Smart2e0fef82007-06-17 19:56:36 -05001054 spin_unlock_irqrestore(&phba->hbalock, iflag);
1055
dea31012005-04-17 16:05:31 -05001056 if (cmdiocbp) {
1057 if (cmdiocbp->iocb_cmpl) {
1058 /*
1059 * Post all ELS completions to the worker thread.
1060 * All other are passed to the completion callback.
1061 */
1062 if (pring->ringno == LPFC_ELS_RING) {
James Smart07951072007-04-25 09:51:38 -04001063 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1064 cmdiocbp->iocb_flag &=
1065 ~LPFC_DRIVER_ABORTED;
1066 saveq->iocb.ulpStatus =
1067 IOSTAT_LOCAL_REJECT;
1068 saveq->iocb.un.ulpWord[4] =
1069 IOERR_SLI_ABORTED;
1070 }
dea31012005-04-17 16:05:31 -05001071 }
James Smart2e0fef82007-06-17 19:56:36 -05001072 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
James Bottomley604a3e32005-10-29 10:28:33 -05001073 } else
1074 lpfc_sli_release_iocbq(phba, cmdiocbp);
dea31012005-04-17 16:05:31 -05001075 } else {
1076 /*
1077 * Unknown initiating command based on the response iotag.
1078 * This could be the case on the ELS ring because of
1079 * lpfc_els_abort().
1080 */
1081 if (pring->ringno != LPFC_ELS_RING) {
1082 /*
1083 * Ring <ringno> handler: unexpected completion IoTag
1084 * <IoTag>
1085 */
James Smart92d7f7b2007-06-17 19:56:38 -05001086 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1087 "%d (%d):0322 Ring %d handler: "
1088 "unexpected completion IoTag x%x "
1089 "Data: x%x x%x x%x x%x\n",
1090 phba->brd_no,
1091 cmdiocbp->vport->vpi,
1092 pring->ringno,
1093 saveq->iocb.ulpIoTag,
1094 saveq->iocb.ulpStatus,
1095 saveq->iocb.un.ulpWord[4],
1096 saveq->iocb.ulpCommand,
1097 saveq->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05001098 }
1099 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04001100
dea31012005-04-17 16:05:31 -05001101 return rc;
1102}
1103
James Smart2e0fef82007-06-17 19:56:36 -05001104static void
1105lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001106{
James Smarted957682007-06-17 19:56:37 -05001107 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1108 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1109 &phba->slim2p->mbx.us.s2.port[pring->ringno];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001110 /*
1111 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1112 * rsp ring <portRspMax>
1113 */
1114 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1115 "%d:0312 Ring %d handler: portRspPut %d "
1116 "is bigger then rsp ring %d\n",
1117 phba->brd_no, pring->ringno,
1118 le32_to_cpu(pgp->rspPutInx),
1119 pring->numRiocb);
1120
James Smart2e0fef82007-06-17 19:56:36 -05001121 phba->link_state = LPFC_HBA_ERROR;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001122
1123 /*
1124 * All error attention handlers are posted to
1125 * worker thread
1126 */
1127 phba->work_ha |= HA_ERATT;
1128 phba->work_hs = HS_FFER3;
James Smart92d7f7b2007-06-17 19:56:38 -05001129
1130 /* hbalock should already be held */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001131 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001132 lpfc_worker_wake_up(phba);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001133
1134 return;
1135}
1136
James Smart2e0fef82007-06-17 19:56:36 -05001137void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001138{
James Smart2e0fef82007-06-17 19:56:36 -05001139 struct lpfc_sli *psli = &phba->sli;
1140 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001141 IOCB_t *irsp = NULL;
1142 IOCB_t *entry = NULL;
1143 struct lpfc_iocbq *cmdiocbq = NULL;
1144 struct lpfc_iocbq rspiocbq;
1145 struct lpfc_pgp *pgp;
1146 uint32_t status;
1147 uint32_t portRspPut, portRspMax;
1148 int type;
1149 uint32_t rsp_cmpl = 0;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001150 uint32_t ha_copy;
James Smart2e0fef82007-06-17 19:56:36 -05001151 unsigned long iflags;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001152
1153 pring->stats.iocb_event++;
1154
James Smarted957682007-06-17 19:56:37 -05001155 pgp = (phba->sli_rev == 3) ?
1156 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1157 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1158
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001159
1160 /*
1161 * The next available response entry should never exceed the maximum
1162 * entries. If it does, treat it as an adapter hardware error.
1163 */
1164 portRspMax = pring->numRiocb;
1165 portRspPut = le32_to_cpu(pgp->rspPutInx);
1166 if (unlikely(portRspPut >= portRspMax)) {
1167 lpfc_sli_rsp_pointers_error(phba, pring);
1168 return;
1169 }
1170
1171 rmb();
1172 while (pring->rspidx != portRspPut) {
James Smarted957682007-06-17 19:56:37 -05001173 entry = lpfc_resp_iocb(phba, pring);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001174 if (++pring->rspidx >= portRspMax)
1175 pring->rspidx = 0;
1176
1177 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1178 (uint32_t *) &rspiocbq.iocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001179 phba->iocb_rsp_size);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001180 irsp = &rspiocbq.iocb;
1181 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1182 pring->stats.iocb_rsp++;
1183 rsp_cmpl++;
1184
1185 if (unlikely(irsp->ulpStatus)) {
1186 /* Rsp ring <ringno> error: IOCB */
1187 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1188 "%d:0326 Rsp Ring %d error: IOCB Data: "
1189 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1190 phba->brd_no, pring->ringno,
1191 irsp->un.ulpWord[0],
1192 irsp->un.ulpWord[1],
1193 irsp->un.ulpWord[2],
1194 irsp->un.ulpWord[3],
1195 irsp->un.ulpWord[4],
1196 irsp->un.ulpWord[5],
1197 *(((uint32_t *) irsp) + 6),
1198 *(((uint32_t *) irsp) + 7));
1199 }
1200
1201 switch (type) {
1202 case LPFC_ABORT_IOCB:
1203 case LPFC_SOL_IOCB:
1204 /*
1205 * Idle exchange closed via ABTS from port. No iocb
1206 * resources need to be recovered.
1207 */
1208 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001209 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1210 "%d:0314 IOCB cmd 0x%x"
1211 " processed. Skipping"
1212 " completion", phba->brd_no,
1213 irsp->ulpCommand);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001214 break;
1215 }
1216
James Smart2e0fef82007-06-17 19:56:36 -05001217 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001218 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1219 &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001220 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001221 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1222 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1223 &rspiocbq);
1224 }
1225 break;
1226 default:
1227 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1228 char adaptermsg[LPFC_MAX_ADPTMSG];
1229 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1230 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1231 MAX_MSG_DATA);
1232 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1233 phba->brd_no, adaptermsg);
1234 } else {
1235 /* Unknown IOCB command */
1236 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1237 "%d:0321 Unknown IOCB command "
1238 "Data: x%x, x%x x%x x%x x%x\n",
1239 phba->brd_no, type,
1240 irsp->ulpCommand,
1241 irsp->ulpStatus,
1242 irsp->ulpIoTag,
1243 irsp->ulpContext);
1244 }
1245 break;
1246 }
1247
1248 /*
1249 * The response IOCB has been processed. Update the ring
1250 * pointer in SLIM. If the port response put pointer has not
1251 * been updated, sync the pgp->rspPutInx and fetch the new port
1252 * response put pointer.
1253 */
James Smarted957682007-06-17 19:56:37 -05001254 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001255
1256 if (pring->rspidx == portRspPut)
1257 portRspPut = le32_to_cpu(pgp->rspPutInx);
1258 }
1259
1260 ha_copy = readl(phba->HAregaddr);
1261 ha_copy >>= (LPFC_FCP_RING * 4);
1262
1263 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
James Smart2e0fef82007-06-17 19:56:36 -05001264 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001265 pring->stats.iocb_rsp_full++;
1266 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1267 writel(status, phba->CAregaddr);
1268 readl(phba->CAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001269 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001270 }
1271 if ((ha_copy & HA_R0CE_RSP) &&
1272 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001273 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001274 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1275 pring->stats.iocb_cmd_empty++;
1276
1277 /* Force update of the local copy of cmdGetInx */
1278 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1279 lpfc_sli_resume_iocb(phba, pring);
1280
1281 if ((pring->lpfc_sli_cmd_available))
1282 (pring->lpfc_sli_cmd_available) (phba, pring);
1283
James Smart2e0fef82007-06-17 19:56:36 -05001284 spin_unlock_irqrestore(&phba->hbalock, iflags);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001285 }
1286
1287 return;
1288}
1289
dea31012005-04-17 16:05:31 -05001290/*
1291 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1292 * to check it explicitly.
1293 */
1294static int
James Smart2e0fef82007-06-17 19:56:36 -05001295lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1296 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05001297{
James Smarted957682007-06-17 19:56:37 -05001298 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1299 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1300 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001301 IOCB_t *irsp = NULL;
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001302 IOCB_t *entry = NULL;
dea31012005-04-17 16:05:31 -05001303 struct lpfc_iocbq *cmdiocbq = NULL;
1304 struct lpfc_iocbq rspiocbq;
dea31012005-04-17 16:05:31 -05001305 uint32_t status;
1306 uint32_t portRspPut, portRspMax;
1307 int rc = 1;
1308 lpfc_iocb_type type;
1309 unsigned long iflag;
1310 uint32_t rsp_cmpl = 0;
dea31012005-04-17 16:05:31 -05001311
James Smart2e0fef82007-06-17 19:56:36 -05001312 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001313 pring->stats.iocb_event++;
1314
dea31012005-04-17 16:05:31 -05001315 /*
1316 * The next available response entry should never exceed the maximum
1317 * entries. If it does, treat it as an adapter hardware error.
1318 */
1319 portRspMax = pring->numRiocb;
1320 portRspPut = le32_to_cpu(pgp->rspPutInx);
1321 if (unlikely(portRspPut >= portRspMax)) {
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001322 lpfc_sli_rsp_pointers_error(phba, pring);
James Smart2e0fef82007-06-17 19:56:36 -05001323 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001324 return 1;
1325 }
1326
1327 rmb();
1328 while (pring->rspidx != portRspPut) {
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001329 /*
1330 * Fetch an entry off the ring and copy it into a local data
1331 * structure. The copy involves a byte-swap since the
1332 * network byte order and pci byte orders are different.
1333 */
James Smarted957682007-06-17 19:56:37 -05001334 entry = lpfc_resp_iocb(phba, pring);
James Smart858c9f62007-06-17 19:56:39 -05001335 phba->last_completion_time = jiffies;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001336
1337 if (++pring->rspidx >= portRspMax)
1338 pring->rspidx = 0;
1339
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001340 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1341 (uint32_t *) &rspiocbq.iocb,
James Smarted957682007-06-17 19:56:37 -05001342 phba->iocb_rsp_size);
James Smarta4bc3372006-12-02 13:34:16 -05001343 INIT_LIST_HEAD(&(rspiocbq.list));
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001344 irsp = &rspiocbq.iocb;
1345
dea31012005-04-17 16:05:31 -05001346 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1347 pring->stats.iocb_rsp++;
1348 rsp_cmpl++;
1349
1350 if (unlikely(irsp->ulpStatus)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001351 /*
1352 * If resource errors reported from HBA, reduce
1353 * queuedepths of the SCSI device.
1354 */
1355 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1356 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1357 spin_unlock_irqrestore(&phba->hbalock, iflag);
1358 lpfc_adjust_queue_depth(phba);
1359 spin_lock_irqsave(&phba->hbalock, iflag);
1360 }
1361
dea31012005-04-17 16:05:31 -05001362 /* Rsp ring <ringno> error: IOCB */
1363 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05001364 "%d:0336 Rsp Ring %d error: IOCB Data: "
1365 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1366 phba->brd_no, pring->ringno,
1367 irsp->un.ulpWord[0],
1368 irsp->un.ulpWord[1],
1369 irsp->un.ulpWord[2],
1370 irsp->un.ulpWord[3],
1371 irsp->un.ulpWord[4],
1372 irsp->un.ulpWord[5],
1373 *(((uint32_t *) irsp) + 6),
1374 *(((uint32_t *) irsp) + 7));
dea31012005-04-17 16:05:31 -05001375 }
1376
1377 switch (type) {
1378 case LPFC_ABORT_IOCB:
1379 case LPFC_SOL_IOCB:
1380 /*
1381 * Idle exchange closed via ABTS from port. No iocb
1382 * resources need to be recovered.
1383 */
1384 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001385 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1386 "%d:0333 IOCB cmd 0x%x"
1387 " processed. Skipping"
James Smart92d7f7b2007-06-17 19:56:38 -05001388 " completion\n",
1389 phba->brd_no,
James Smartdca94792006-08-01 07:34:08 -04001390 irsp->ulpCommand);
dea31012005-04-17 16:05:31 -05001391 break;
1392 }
1393
James Bottomley604a3e32005-10-29 10:28:33 -05001394 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1395 &rspiocbq);
dea31012005-04-17 16:05:31 -05001396 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001397 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1398 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1399 &rspiocbq);
1400 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001401 spin_unlock_irqrestore(&phba->hbalock,
1402 iflag);
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001403 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1404 &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001405 spin_lock_irqsave(&phba->hbalock,
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001406 iflag);
1407 }
dea31012005-04-17 16:05:31 -05001408 }
1409 break;
James Smarta4bc3372006-12-02 13:34:16 -05001410 case LPFC_UNSOL_IOCB:
James Smart2e0fef82007-06-17 19:56:36 -05001411 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05001412 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
James Smart2e0fef82007-06-17 19:56:36 -05001413 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta4bc3372006-12-02 13:34:16 -05001414 break;
dea31012005-04-17 16:05:31 -05001415 default:
1416 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1417 char adaptermsg[LPFC_MAX_ADPTMSG];
1418 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1419 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1420 MAX_MSG_DATA);
1421 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1422 phba->brd_no, adaptermsg);
1423 } else {
1424 /* Unknown IOCB command */
1425 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05001426 "%d:0334 Unknown IOCB command "
1427 "Data: x%x, x%x x%x x%x x%x\n",
1428 phba->brd_no, type,
1429 irsp->ulpCommand,
1430 irsp->ulpStatus,
1431 irsp->ulpIoTag,
1432 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05001433 }
1434 break;
1435 }
1436
1437 /*
1438 * The response IOCB has been processed. Update the ring
1439 * pointer in SLIM. If the port response put pointer has not
1440 * been updated, sync the pgp->rspPutInx and fetch the new port
1441 * response put pointer.
1442 */
James Smarted957682007-06-17 19:56:37 -05001443 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05001444
1445 if (pring->rspidx == portRspPut)
1446 portRspPut = le32_to_cpu(pgp->rspPutInx);
1447 }
1448
1449 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1450 pring->stats.iocb_rsp_full++;
1451 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1452 writel(status, phba->CAregaddr);
1453 readl(phba->CAregaddr);
1454 }
1455 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1456 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1457 pring->stats.iocb_cmd_empty++;
1458
1459 /* Force update of the local copy of cmdGetInx */
1460 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1461 lpfc_sli_resume_iocb(phba, pring);
1462
1463 if ((pring->lpfc_sli_cmd_available))
1464 (pring->lpfc_sli_cmd_available) (phba, pring);
1465
1466 }
1467
James Smart2e0fef82007-06-17 19:56:36 -05001468 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001469 return rc;
1470}
1471
dea31012005-04-17 16:05:31 -05001472int
James Smart2e0fef82007-06-17 19:56:36 -05001473lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1474 struct lpfc_sli_ring *pring, uint32_t mask)
dea31012005-04-17 16:05:31 -05001475{
James Smarted957682007-06-17 19:56:37 -05001476 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1477 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1478 &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001479 IOCB_t *entry;
1480 IOCB_t *irsp = NULL;
1481 struct lpfc_iocbq *rspiocbp = NULL;
1482 struct lpfc_iocbq *next_iocb;
1483 struct lpfc_iocbq *cmdiocbp;
1484 struct lpfc_iocbq *saveq;
dea31012005-04-17 16:05:31 -05001485 uint8_t iocb_cmd_type;
1486 lpfc_iocb_type type;
1487 uint32_t status, free_saveq;
1488 uint32_t portRspPut, portRspMax;
1489 int rc = 1;
1490 unsigned long iflag;
dea31012005-04-17 16:05:31 -05001491
James Smart2e0fef82007-06-17 19:56:36 -05001492 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001493 pring->stats.iocb_event++;
1494
dea31012005-04-17 16:05:31 -05001495 /*
1496 * The next available response entry should never exceed the maximum
1497 * entries. If it does, treat it as an adapter hardware error.
1498 */
1499 portRspMax = pring->numRiocb;
1500 portRspPut = le32_to_cpu(pgp->rspPutInx);
1501 if (portRspPut >= portRspMax) {
1502 /*
1503 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1504 * rsp ring <portRspMax>
1505 */
James Smarted957682007-06-17 19:56:37 -05001506 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04001507 "%d:0303 Ring %d handler: portRspPut %d "
dea31012005-04-17 16:05:31 -05001508 "is bigger then rsp ring %d\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001509 phba->brd_no, pring->ringno, portRspPut,
1510 portRspMax);
dea31012005-04-17 16:05:31 -05001511
James Smart2e0fef82007-06-17 19:56:36 -05001512 phba->link_state = LPFC_HBA_ERROR;
1513 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001514
1515 phba->work_hs = HS_FFER3;
1516 lpfc_handle_eratt(phba);
1517
1518 return 1;
1519 }
1520
1521 rmb();
dea31012005-04-17 16:05:31 -05001522 while (pring->rspidx != portRspPut) {
1523 /*
1524 * Build a completion list and call the appropriate handler.
1525 * The process is to get the next available response iocb, get
1526 * a free iocb from the list, copy the response data into the
1527 * free iocb, insert to the continuation list, and update the
1528 * next response index to slim. This process makes response
1529 * iocb's in the ring available to DMA as fast as possible but
1530 * pays a penalty for a copy operation. Since the iocb is
1531 * only 32 bytes, this penalty is considered small relative to
1532 * the PCI reads for register values and a slim write. When
1533 * the ulpLe field is set, the entire Command has been
1534 * received.
1535 */
James Smarted957682007-06-17 19:56:37 -05001536 entry = lpfc_resp_iocb(phba, pring);
1537
James Smart858c9f62007-06-17 19:56:39 -05001538 phba->last_completion_time = jiffies;
James Smart2e0fef82007-06-17 19:56:36 -05001539 rspiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001540 if (rspiocbp == NULL) {
1541 printk(KERN_ERR "%s: out of buffers! Failing "
1542 "completion.\n", __FUNCTION__);
1543 break;
1544 }
1545
James Smarted957682007-06-17 19:56:37 -05001546 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1547 phba->iocb_rsp_size);
dea31012005-04-17 16:05:31 -05001548 irsp = &rspiocbp->iocb;
1549
1550 if (++pring->rspidx >= portRspMax)
1551 pring->rspidx = 0;
1552
James Smarta58cbd52007-08-02 11:09:43 -04001553 if (pring->ringno == LPFC_ELS_RING) {
1554 lpfc_debugfs_slow_ring_trc(phba,
1555 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1556 *(((uint32_t *) irsp) + 4),
1557 *(((uint32_t *) irsp) + 6),
1558 *(((uint32_t *) irsp) + 7));
1559 }
1560
James Smarted957682007-06-17 19:56:37 -05001561 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
dea31012005-04-17 16:05:31 -05001562
1563 if (list_empty(&(pring->iocb_continueq))) {
1564 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1565 } else {
1566 list_add_tail(&rspiocbp->list,
1567 &(pring->iocb_continueq));
1568 }
1569
1570 pring->iocb_continueq_cnt++;
1571 if (irsp->ulpLe) {
1572 /*
1573 * By default, the driver expects to free all resources
1574 * associated with this iocb completion.
1575 */
1576 free_saveq = 1;
1577 saveq = list_get_first(&pring->iocb_continueq,
1578 struct lpfc_iocbq, list);
1579 irsp = &(saveq->iocb);
1580 list_del_init(&pring->iocb_continueq);
1581 pring->iocb_continueq_cnt = 0;
1582
1583 pring->stats.iocb_rsp++;
1584
James Smart92d7f7b2007-06-17 19:56:38 -05001585 /*
1586 * If resource errors reported from HBA, reduce
1587 * queuedepths of the SCSI device.
1588 */
1589 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1590 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1591 spin_unlock_irqrestore(&phba->hbalock, iflag);
1592 lpfc_adjust_queue_depth(phba);
1593 spin_lock_irqsave(&phba->hbalock, iflag);
1594 }
1595
dea31012005-04-17 16:05:31 -05001596 if (irsp->ulpStatus) {
1597 /* Rsp ring <ringno> error: IOCB */
James Smarted957682007-06-17 19:56:37 -05001598 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1599 "%d:0328 Rsp Ring %d error: "
1600 "IOCB Data: "
1601 "x%x x%x x%x x%x "
1602 "x%x x%x x%x x%x "
1603 "x%x x%x x%x x%x "
1604 "x%x x%x x%x x%x\n",
1605 phba->brd_no,
1606 pring->ringno,
1607 irsp->un.ulpWord[0],
1608 irsp->un.ulpWord[1],
1609 irsp->un.ulpWord[2],
1610 irsp->un.ulpWord[3],
1611 irsp->un.ulpWord[4],
1612 irsp->un.ulpWord[5],
1613 *(((uint32_t *) irsp) + 6),
1614 *(((uint32_t *) irsp) + 7),
1615 *(((uint32_t *) irsp) + 8),
1616 *(((uint32_t *) irsp) + 9),
1617 *(((uint32_t *) irsp) + 10),
1618 *(((uint32_t *) irsp) + 11),
1619 *(((uint32_t *) irsp) + 12),
1620 *(((uint32_t *) irsp) + 13),
1621 *(((uint32_t *) irsp) + 14),
1622 *(((uint32_t *) irsp) + 15));
dea31012005-04-17 16:05:31 -05001623 }
1624
1625 /*
1626 * Fetch the IOCB command type and call the correct
1627 * completion routine. Solicited and Unsolicited
1628 * IOCBs on the ELS ring get freed back to the
1629 * lpfc_iocb_list by the discovery kernel thread.
1630 */
1631 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1632 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1633 if (type == LPFC_SOL_IOCB) {
James Smart2e0fef82007-06-17 19:56:36 -05001634 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05001635 iflag);
1636 rc = lpfc_sli_process_sol_iocb(phba, pring,
James Smart2e0fef82007-06-17 19:56:36 -05001637 saveq);
1638 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001639 } else if (type == LPFC_UNSOL_IOCB) {
James Smart2e0fef82007-06-17 19:56:36 -05001640 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05001641 iflag);
1642 rc = lpfc_sli_process_unsol_iocb(phba, pring,
James Smart2e0fef82007-06-17 19:56:36 -05001643 saveq);
1644 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001645 } else if (type == LPFC_ABORT_IOCB) {
1646 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1647 ((cmdiocbp =
James Bottomley604a3e32005-10-29 10:28:33 -05001648 lpfc_sli_iocbq_lookup(phba, pring,
1649 saveq)))) {
dea31012005-04-17 16:05:31 -05001650 /* Call the specified completion
1651 routine */
1652 if (cmdiocbp->iocb_cmpl) {
1653 spin_unlock_irqrestore(
James Smart2e0fef82007-06-17 19:56:36 -05001654 &phba->hbalock,
dea31012005-04-17 16:05:31 -05001655 iflag);
1656 (cmdiocbp->iocb_cmpl) (phba,
1657 cmdiocbp, saveq);
1658 spin_lock_irqsave(
James Smart2e0fef82007-06-17 19:56:36 -05001659 &phba->hbalock,
dea31012005-04-17 16:05:31 -05001660 iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001661 } else
James Smart2e0fef82007-06-17 19:56:36 -05001662 __lpfc_sli_release_iocbq(phba,
James Bottomley604a3e32005-10-29 10:28:33 -05001663 cmdiocbp);
dea31012005-04-17 16:05:31 -05001664 }
1665 } else if (type == LPFC_UNKNOWN_IOCB) {
1666 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1667
1668 char adaptermsg[LPFC_MAX_ADPTMSG];
1669
1670 memset(adaptermsg, 0,
1671 LPFC_MAX_ADPTMSG);
1672 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1673 MAX_MSG_DATA);
1674 dev_warn(&((phba->pcidev)->dev),
1675 "lpfc%d: %s",
1676 phba->brd_no, adaptermsg);
1677 } else {
1678 /* Unknown IOCB command */
James Smart92d7f7b2007-06-17 19:56:38 -05001679 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1680 "%d:0335 Unknown IOCB "
1681 "command Data: x%x "
1682 "x%x x%x x%x\n",
1683 phba->brd_no,
1684 irsp->ulpCommand,
1685 irsp->ulpStatus,
1686 irsp->ulpIoTag,
1687 irsp->ulpContext);
dea31012005-04-17 16:05:31 -05001688 }
1689 }
1690
1691 if (free_saveq) {
James Smart2e0fef82007-06-17 19:56:36 -05001692 list_for_each_entry_safe(rspiocbp, next_iocb,
1693 &saveq->list, list) {
1694 list_del(&rspiocbp->list);
1695 __lpfc_sli_release_iocbq(phba,
1696 rspiocbp);
dea31012005-04-17 16:05:31 -05001697 }
James Smart2e0fef82007-06-17 19:56:36 -05001698 __lpfc_sli_release_iocbq(phba, saveq);
dea31012005-04-17 16:05:31 -05001699 }
James Smart92d7f7b2007-06-17 19:56:38 -05001700 rspiocbp = NULL;
dea31012005-04-17 16:05:31 -05001701 }
1702
1703 /*
1704 * If the port response put pointer has not been updated, sync
1705 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1706 * response put pointer.
1707 */
1708 if (pring->rspidx == portRspPut) {
1709 portRspPut = le32_to_cpu(pgp->rspPutInx);
1710 }
1711 } /* while (pring->rspidx != portRspPut) */
1712
James Smart92d7f7b2007-06-17 19:56:38 -05001713 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
dea31012005-04-17 16:05:31 -05001714 /* At least one response entry has been freed */
1715 pring->stats.iocb_rsp_full++;
1716 /* SET RxRE_RSP in Chip Att register */
1717 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1718 writel(status, phba->CAregaddr);
1719 readl(phba->CAregaddr); /* flush */
1720 }
1721 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1722 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1723 pring->stats.iocb_cmd_empty++;
1724
1725 /* Force update of the local copy of cmdGetInx */
1726 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1727 lpfc_sli_resume_iocb(phba, pring);
1728
1729 if ((pring->lpfc_sli_cmd_available))
1730 (pring->lpfc_sli_cmd_available) (phba, pring);
1731
1732 }
1733
James Smart2e0fef82007-06-17 19:56:36 -05001734 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001735 return rc;
1736}
1737
James Smart2e0fef82007-06-17 19:56:36 -05001738void
dea31012005-04-17 16:05:31 -05001739lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1740{
James Smart2534ba72007-04-25 09:52:20 -04001741 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001742 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -04001743 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05001744
James Smart92d7f7b2007-06-17 19:56:38 -05001745 if (pring->ringno == LPFC_ELS_RING) {
1746 lpfc_fabric_abort_hba(phba);
1747 }
1748
dea31012005-04-17 16:05:31 -05001749 /* Error everything on txq and txcmplq
1750 * First do the txq.
1751 */
James Smart2e0fef82007-06-17 19:56:36 -05001752 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001753 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05001754 pring->txq_cnt = 0;
dea31012005-04-17 16:05:31 -05001755
1756 /* Next issue ABTS for everything on the txcmplq */
James Smart2534ba72007-04-25 09:52:20 -04001757 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1758 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1759
James Smart2e0fef82007-06-17 19:56:36 -05001760 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001761
1762 while (!list_empty(&completions)) {
1763 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
dea31012005-04-17 16:05:31 -05001764 cmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05001765 list_del_init(&iocb->list);
dea31012005-04-17 16:05:31 -05001766
James Smart2e0fef82007-06-17 19:56:36 -05001767 if (!iocb->iocb_cmpl)
1768 lpfc_sli_release_iocbq(phba, iocb);
1769 else {
dea31012005-04-17 16:05:31 -05001770 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1771 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
dea31012005-04-17 16:05:31 -05001772 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001773 }
dea31012005-04-17 16:05:31 -05001774 }
dea31012005-04-17 16:05:31 -05001775}
1776
Jamie Wellnitz41415862006-02-28 19:25:27 -05001777int
James Smart2e0fef82007-06-17 19:56:36 -05001778lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
dea31012005-04-17 16:05:31 -05001779{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001780 uint32_t status;
1781 int i = 0;
1782 int retval = 0;
dea31012005-04-17 16:05:31 -05001783
Jamie Wellnitz41415862006-02-28 19:25:27 -05001784 /* Read the HBA Host Status Register */
1785 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001786
Jamie Wellnitz41415862006-02-28 19:25:27 -05001787 /*
1788 * Check status register every 100ms for 5 retries, then every
1789 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1790 * every 2.5 sec for 4.
1791 * Break our of the loop if errors occurred during init.
1792 */
1793 while (((status & mask) != mask) &&
1794 !(status & HS_FFERM) &&
1795 i++ < 20) {
dea31012005-04-17 16:05:31 -05001796
Jamie Wellnitz41415862006-02-28 19:25:27 -05001797 if (i <= 5)
1798 msleep(10);
1799 else if (i <= 10)
1800 msleep(500);
1801 else
1802 msleep(2500);
dea31012005-04-17 16:05:31 -05001803
Jamie Wellnitz41415862006-02-28 19:25:27 -05001804 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05001805 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05001806 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001807 lpfc_sli_brdrestart(phba);
1808 }
1809 /* Read the HBA Host Status Register */
1810 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001811 }
dea31012005-04-17 16:05:31 -05001812
Jamie Wellnitz41415862006-02-28 19:25:27 -05001813 /* Check to see if any errors occurred during init */
1814 if ((status & HS_FFERM) || (i >= 20)) {
James Smart2e0fef82007-06-17 19:56:36 -05001815 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001816 retval = 1;
1817 }
dea31012005-04-17 16:05:31 -05001818
Jamie Wellnitz41415862006-02-28 19:25:27 -05001819 return retval;
dea31012005-04-17 16:05:31 -05001820}
1821
James Smart92908312006-03-07 15:04:13 -05001822#define BARRIER_TEST_PATTERN (0xdeadbeef)
1823
James Smart2e0fef82007-06-17 19:56:36 -05001824void lpfc_reset_barrier(struct lpfc_hba *phba)
James Smart92908312006-03-07 15:04:13 -05001825{
James Smart65a29c12006-07-06 15:50:50 -04001826 uint32_t __iomem *resp_buf;
1827 uint32_t __iomem *mbox_buf;
James Smart92908312006-03-07 15:04:13 -05001828 volatile uint32_t mbox;
1829 uint32_t hc_copy;
1830 int i;
1831 uint8_t hdrtype;
1832
1833 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1834 if (hdrtype != 0x80 ||
1835 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1836 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1837 return;
1838
1839 /*
1840 * Tell the other part of the chip to suspend temporarily all
1841 * its DMA activity.
1842 */
James Smart65a29c12006-07-06 15:50:50 -04001843 resp_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001844
1845 /* Disable the error attention */
1846 hc_copy = readl(phba->HCregaddr);
1847 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1848 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001849 phba->link_flag |= LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05001850
1851 if (readl(phba->HAregaddr) & HA_ERATT) {
1852 /* Clear Chip error bit */
1853 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001854 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001855 }
1856
1857 mbox = 0;
1858 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1859 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1860
1861 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
James Smart65a29c12006-07-06 15:50:50 -04001862 mbox_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001863 writel(mbox, mbox_buf);
1864
1865 for (i = 0;
1866 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1867 mdelay(1);
1868
1869 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1870 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
James Smart2e0fef82007-06-17 19:56:36 -05001871 phba->pport->stopped)
James Smart92908312006-03-07 15:04:13 -05001872 goto restore_hc;
1873 else
1874 goto clear_errat;
1875 }
1876
1877 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1878 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1879 mdelay(1);
1880
1881clear_errat:
1882
1883 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1884 mdelay(1);
1885
1886 if (readl(phba->HAregaddr) & HA_ERATT) {
1887 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001888 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001889 }
1890
1891restore_hc:
James Smart2e0fef82007-06-17 19:56:36 -05001892 phba->link_flag &= ~LS_IGNORE_ERATT;
James Smart92908312006-03-07 15:04:13 -05001893 writel(hc_copy, phba->HCregaddr);
1894 readl(phba->HCregaddr); /* flush */
1895}
1896
Jamie Wellnitz41415862006-02-28 19:25:27 -05001897int
James Smart2e0fef82007-06-17 19:56:36 -05001898lpfc_sli_brdkill(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001899{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001900 struct lpfc_sli *psli;
1901 LPFC_MBOXQ_t *pmb;
1902 uint32_t status;
1903 uint32_t ha_copy;
1904 int retval;
1905 int i = 0;
1906
1907 psli = &phba->sli;
1908
1909 /* Kill HBA */
James Smarted957682007-06-17 19:56:37 -05001910 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05001911 "%d:0329 Kill HBA Data: x%x x%x\n",
1912 phba->brd_no, phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001913
1914 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
James Smart92908312006-03-07 15:04:13 -05001915 GFP_KERNEL)) == 0)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001916 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001917
1918 /* Disable the error attention */
James Smart2e0fef82007-06-17 19:56:36 -05001919 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001920 status = readl(phba->HCregaddr);
1921 status &= ~HC_ERINT_ENA;
1922 writel(status, phba->HCregaddr);
1923 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001924 phba->link_flag |= LS_IGNORE_ERATT;
1925 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001926
1927 lpfc_kill_board(phba, pmb);
1928 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1929 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1930
1931 if (retval != MBX_SUCCESS) {
1932 if (retval != MBX_BUSY)
1933 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05001934 spin_lock_irq(&phba->hbalock);
1935 phba->link_flag &= ~LS_IGNORE_ERATT;
1936 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001937 return 1;
1938 }
1939
James Smart92908312006-03-07 15:04:13 -05001940 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1941
Jamie Wellnitz41415862006-02-28 19:25:27 -05001942 mempool_free(pmb, phba->mbox_mem_pool);
1943
1944 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1945 * attention every 100ms for 3 seconds. If we don't get ERATT after
1946 * 3 seconds we still set HBA_ERROR state because the status of the
1947 * board is now undefined.
1948 */
1949 ha_copy = readl(phba->HAregaddr);
1950
1951 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1952 mdelay(100);
1953 ha_copy = readl(phba->HAregaddr);
1954 }
1955
1956 del_timer_sync(&psli->mbox_tmo);
James Smart92908312006-03-07 15:04:13 -05001957 if (ha_copy & HA_ERATT) {
1958 writel(HA_ERATT, phba->HAregaddr);
James Smart2e0fef82007-06-17 19:56:36 -05001959 phba->pport->stopped = 1;
James Smart92908312006-03-07 15:04:13 -05001960 }
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001962 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05001963 phba->link_flag &= ~LS_IGNORE_ERATT;
1964 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001965
1966 psli->mbox_active = NULL;
1967 lpfc_hba_down_post(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001968 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001969
James Smart2e0fef82007-06-17 19:56:36 -05001970 return ha_copy & HA_ERATT ? 0 : 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001971}
1972
1973int
James Smart2e0fef82007-06-17 19:56:36 -05001974lpfc_sli_brdreset(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001975{
1976 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001977 struct lpfc_sli_ring *pring;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001978 uint16_t cfg_value;
dea31012005-04-17 16:05:31 -05001979 int i;
dea31012005-04-17 16:05:31 -05001980
Jamie Wellnitz41415862006-02-28 19:25:27 -05001981 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001982
Jamie Wellnitz41415862006-02-28 19:25:27 -05001983 /* Reset HBA */
1984 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1985 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05001986 phba->pport->port_state, psli->sli_flag);
dea31012005-04-17 16:05:31 -05001987
1988 /* perform board reset */
1989 phba->fc_eventTag = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001990 phba->pport->fc_myDID = 0;
1991 phba->pport->fc_prevDID = 0;
dea31012005-04-17 16:05:31 -05001992
Jamie Wellnitz41415862006-02-28 19:25:27 -05001993 /* Turn off parity checking and serr during the physical reset */
1994 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1995 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1996 (cfg_value &
1997 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1998
James Smart1c067a42006-08-01 07:33:52 -04001999 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002000 /* Now toggle INITFF bit in the Host Control Register */
2001 writel(HC_INITFF, phba->HCregaddr);
2002 mdelay(1);
2003 readl(phba->HCregaddr); /* flush */
2004 writel(0, phba->HCregaddr);
2005 readl(phba->HCregaddr); /* flush */
2006
2007 /* Restore PCI cmd register */
2008 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
dea31012005-04-17 16:05:31 -05002009
2010 /* Initialize relevant SLI info */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002011 for (i = 0; i < psli->num_rings; i++) {
2012 pring = &psli->ring[i];
dea31012005-04-17 16:05:31 -05002013 pring->flag = 0;
2014 pring->rspidx = 0;
2015 pring->next_cmdidx = 0;
2016 pring->local_getidx = 0;
2017 pring->cmdidx = 0;
2018 pring->missbufcnt = 0;
2019 }
dea31012005-04-17 16:05:31 -05002020
James Smart2e0fef82007-06-17 19:56:36 -05002021 phba->link_state = LPFC_WARM_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002022 return 0;
2023}
2024
2025int
James Smart2e0fef82007-06-17 19:56:36 -05002026lpfc_sli_brdrestart(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05002027{
2028 MAILBOX_t *mb;
2029 struct lpfc_sli *psli;
2030 uint16_t skip_post;
2031 volatile uint32_t word0;
2032 void __iomem *to_slim;
2033
James Smart2e0fef82007-06-17 19:56:36 -05002034 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002035
2036 psli = &phba->sli;
2037
2038 /* Restart HBA */
2039 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04002040 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05002041 phba->pport->port_state, psli->sli_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002042
2043 word0 = 0;
2044 mb = (MAILBOX_t *) &word0;
2045 mb->mbxCommand = MBX_RESTART;
2046 mb->mbxHc = 1;
2047
James Smart92908312006-03-07 15:04:13 -05002048 lpfc_reset_barrier(phba);
2049
Jamie Wellnitz41415862006-02-28 19:25:27 -05002050 to_slim = phba->MBslimaddr;
2051 writel(*(uint32_t *) mb, to_slim);
2052 readl(to_slim); /* flush */
2053
2054 /* Only skip post after fc_ffinit is completed */
James Smart2e0fef82007-06-17 19:56:36 -05002055 if (phba->pport->port_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002056 skip_post = 1;
2057 word0 = 1; /* This is really setting up word1 */
dea31012005-04-17 16:05:31 -05002058 } else {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002059 skip_post = 0;
2060 word0 = 0; /* This is really setting up word1 */
2061 }
James Smart65a29c12006-07-06 15:50:50 -04002062 to_slim = phba->MBslimaddr + sizeof (uint32_t);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002063 writel(*(uint32_t *) mb, to_slim);
2064 readl(to_slim); /* flush */
2065
2066 lpfc_sli_brdreset(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002067 phba->pport->stopped = 0;
2068 phba->link_state = LPFC_INIT_START;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002069
James Smart2e0fef82007-06-17 19:56:36 -05002070 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002071
James Smart64ba8812006-08-02 15:24:34 -04002072 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2073 psli->stats_start = get_seconds();
2074
Jamie Wellnitz41415862006-02-28 19:25:27 -05002075 if (skip_post)
2076 mdelay(100);
2077 else
dea31012005-04-17 16:05:31 -05002078 mdelay(2000);
dea31012005-04-17 16:05:31 -05002079
Jamie Wellnitz41415862006-02-28 19:25:27 -05002080 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -05002081
2082 return 0;
2083}
2084
2085static int
2086lpfc_sli_chipset_init(struct lpfc_hba *phba)
2087{
2088 uint32_t status, i = 0;
2089
2090 /* Read the HBA Host Status Register */
2091 status = readl(phba->HSregaddr);
2092
2093 /* Check status register to see what current state is */
2094 i = 0;
2095 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2096
2097 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2098 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2099 * 4.
2100 */
2101 if (i++ >= 20) {
2102 /* Adapter failed to init, timeout, status reg
2103 <status> */
James Smarted957682007-06-17 19:56:37 -05002104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -05002105 "%d:0436 Adapter failed to init, "
2106 "timeout, status reg x%x\n",
James Smarted957682007-06-17 19:56:37 -05002107 phba->brd_no, status);
James Smart2e0fef82007-06-17 19:56:36 -05002108 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002109 return -ETIMEDOUT;
2110 }
2111
2112 /* Check to see if any errors occurred during init */
2113 if (status & HS_FFERM) {
2114 /* ERROR: During chipset initialization */
2115 /* Adapter failed to init, chipset, status reg
2116 <status> */
James Smarted957682007-06-17 19:56:37 -05002117 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -05002118 "%d:0437 Adapter failed to init, "
2119 "chipset, status reg x%x\n",
2120 phba->brd_no,
2121 status);
James Smart2e0fef82007-06-17 19:56:36 -05002122 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002123 return -EIO;
2124 }
2125
2126 if (i <= 5) {
2127 msleep(10);
2128 } else if (i <= 10) {
2129 msleep(500);
2130 } else {
2131 msleep(2500);
2132 }
2133
2134 if (i == 15) {
James Smart2e0fef82007-06-17 19:56:36 -05002135 /* Do post */
James Smart92d7f7b2007-06-17 19:56:38 -05002136 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002137 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05002138 }
2139 /* Read the HBA Host Status Register */
2140 status = readl(phba->HSregaddr);
2141 }
2142
2143 /* Check to see if any errors occurred during init */
2144 if (status & HS_FFERM) {
2145 /* ERROR: During chipset initialization */
2146 /* Adapter failed to init, chipset, status reg <status> */
James Smarted957682007-06-17 19:56:37 -05002147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -05002148 "%d:0438 Adapter failed to init, chipset, "
2149 "status reg x%x\n",
2150 phba->brd_no,
2151 status);
James Smart2e0fef82007-06-17 19:56:36 -05002152 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002153 return -EIO;
2154 }
2155
2156 /* Clear all interrupt enable conditions */
2157 writel(0, phba->HCregaddr);
2158 readl(phba->HCregaddr); /* flush */
2159
2160 /* setup host attn register */
2161 writel(0xffffffff, phba->HAregaddr);
2162 readl(phba->HAregaddr); /* flush */
2163 return 0;
2164}
2165
James Smarted957682007-06-17 19:56:37 -05002166static int
2167lpfc_sli_hbq_count(void)
2168{
James Smart92d7f7b2007-06-17 19:56:38 -05002169 return ARRAY_SIZE(lpfc_hbq_defs);
James Smarted957682007-06-17 19:56:37 -05002170}
2171
2172static int
2173lpfc_sli_hbq_entry_count(void)
2174{
2175 int hbq_count = lpfc_sli_hbq_count();
2176 int count = 0;
2177 int i;
2178
2179 for (i = 0; i < hbq_count; ++i)
James Smart92d7f7b2007-06-17 19:56:38 -05002180 count += lpfc_hbq_defs[i]->entry_count;
James Smarted957682007-06-17 19:56:37 -05002181 return count;
2182}
2183
dea31012005-04-17 16:05:31 -05002184int
James Smarted957682007-06-17 19:56:37 -05002185lpfc_sli_hbq_size(void)
2186{
2187 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2188}
2189
2190static int
2191lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2192{
2193 int hbq_count = lpfc_sli_hbq_count();
2194 LPFC_MBOXQ_t *pmb;
2195 MAILBOX_t *pmbox;
2196 uint32_t hbqno;
2197 uint32_t hbq_entry_index;
James Smarted957682007-06-17 19:56:37 -05002198
James Smart92d7f7b2007-06-17 19:56:38 -05002199 /* Get a Mailbox buffer to setup mailbox
2200 * commands for HBA initialization
2201 */
James Smarted957682007-06-17 19:56:37 -05002202 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2203
2204 if (!pmb)
2205 return -ENOMEM;
2206
2207 pmbox = &pmb->mb;
2208
2209 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2210 phba->link_state = LPFC_INIT_MBX_CMDS;
2211
2212 hbq_entry_index = 0;
2213 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2214 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2215 phba->hbqs[hbqno].hbqPutIdx = 0;
2216 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2217 phba->hbqs[hbqno].entry_count =
James Smart92d7f7b2007-06-17 19:56:38 -05002218 lpfc_hbq_defs[hbqno]->entry_count;
2219 lpfc_config_hbq(phba, lpfc_hbq_defs[hbqno], hbq_entry_index,
2220 pmb);
James Smarted957682007-06-17 19:56:37 -05002221 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2222
2223 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2224 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2225 mbxStatus <status>, ring <num> */
2226
2227 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05002228 LOG_SLI | LOG_VPORT,
James Smarted957682007-06-17 19:56:37 -05002229 "%d:1805 Adapter failed to init. "
2230 "Data: x%x x%x x%x\n",
2231 phba->brd_no, pmbox->mbxCommand,
2232 pmbox->mbxStatus, hbqno);
2233
2234 phba->link_state = LPFC_HBA_ERROR;
2235 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -05002236 return ENXIO;
2237 }
2238 }
2239 phba->hbq_count = hbq_count;
2240
James Smarted957682007-06-17 19:56:37 -05002241 mempool_free(pmb, phba->mbox_mem_pool);
2242
James Smart92d7f7b2007-06-17 19:56:38 -05002243 /* Initially populate or replenish the HBQs */
2244 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2245 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2246 return -ENOMEM;
2247 }
James Smarted957682007-06-17 19:56:37 -05002248 return 0;
2249}
2250
2251static int
2252lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
dea31012005-04-17 16:05:31 -05002253{
2254 LPFC_MBOXQ_t *pmb;
2255 uint32_t resetcount = 0, rc = 0, done = 0;
2256
2257 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2258 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -05002259 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002260 return -ENOMEM;
2261 }
2262
James Smarted957682007-06-17 19:56:37 -05002263 phba->sli_rev = sli_mode;
dea31012005-04-17 16:05:31 -05002264 while (resetcount < 2 && !done) {
James Smart2e0fef82007-06-17 19:56:36 -05002265 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04002266 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002267 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05002268 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002269 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05002270 msleep(2500);
2271 rc = lpfc_sli_chipset_init(phba);
2272 if (rc)
2273 break;
2274
James Smart2e0fef82007-06-17 19:56:36 -05002275 spin_lock_irq(&phba->hbalock);
James Smart1c067a42006-08-01 07:33:52 -04002276 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002277 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002278 resetcount++;
2279
James Smarted957682007-06-17 19:56:37 -05002280 /* Call pre CONFIG_PORT mailbox command initialization. A
2281 * value of 0 means the call was successful. Any other
2282 * nonzero value is a failure, but if ERESTART is returned,
2283 * the driver may reset the HBA and try again.
2284 */
dea31012005-04-17 16:05:31 -05002285 rc = lpfc_config_port_prep(phba);
2286 if (rc == -ERESTART) {
James Smarted957682007-06-17 19:56:37 -05002287 phba->link_state = LPFC_LINK_UNKNOWN;
dea31012005-04-17 16:05:31 -05002288 continue;
2289 } else if (rc) {
2290 break;
2291 }
2292
James Smart2e0fef82007-06-17 19:56:36 -05002293 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -05002294 lpfc_config_port(phba, pmb);
2295 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smarted957682007-06-17 19:56:37 -05002296 if (rc != MBX_SUCCESS) {
dea31012005-04-17 16:05:31 -05002297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart92d7f7b2007-06-17 19:56:38 -05002298 "%d:0442 Adapter failed to init, mbxCmd x%x "
2299 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2300 phba->brd_no, pmb->mb.mbxCommand,
2301 pmb->mb.mbxStatus, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002302 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002303 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002304 spin_unlock_irq(&phba->hbalock);
2305 rc = -ENXIO;
James Smarted957682007-06-17 19:56:37 -05002306 } else {
2307 done = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002308 phba->max_vpi = (phba->max_vpi &&
2309 pmb->mb.un.varCfgPort.gmv) != 0
2310 ? pmb->mb.un.varCfgPort.max_vpi
2311 : 0;
dea31012005-04-17 16:05:31 -05002312 }
2313 }
James Smarted957682007-06-17 19:56:37 -05002314
2315 if (!done) {
2316 rc = -EINVAL;
2317 goto do_prep_failed;
2318 }
2319
2320 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002321 (!pmb->mb.un.varCfgPort.cMA)) {
James Smarted957682007-06-17 19:56:37 -05002322 rc = -ENXIO;
2323 goto do_prep_failed;
2324 }
2325 return rc;
2326
James Smart92d7f7b2007-06-17 19:56:38 -05002327do_prep_failed:
James Smarted957682007-06-17 19:56:37 -05002328 mempool_free(pmb, phba->mbox_mem_pool);
2329 return rc;
2330}
2331
2332int
2333lpfc_sli_hba_setup(struct lpfc_hba *phba)
2334{
2335 uint32_t rc;
James Smart92d7f7b2007-06-17 19:56:38 -05002336 int mode = 3;
James Smarted957682007-06-17 19:56:37 -05002337
2338 switch (lpfc_sli_mode) {
2339 case 2:
James Smart858c9f62007-06-17 19:56:39 -05002340 if (phba->cfg_npiv_enable) {
James Smart92d7f7b2007-06-17 19:56:38 -05002341 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2342 "%d:1824 NPIV enabled: Override lpfc_sli_mode "
2343 "parameter (%d) to auto (0).\n",
2344 phba->brd_no, lpfc_sli_mode);
2345 break;
2346 }
James Smarted957682007-06-17 19:56:37 -05002347 mode = 2;
2348 break;
2349 case 0:
2350 case 3:
2351 break;
2352 default:
James Smart92d7f7b2007-06-17 19:56:38 -05002353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarted957682007-06-17 19:56:37 -05002354 "%d:1819 Unrecognized lpfc_sli_mode "
2355 "parameter: %d.\n",
2356 phba->brd_no, lpfc_sli_mode);
2357
2358 break;
2359 }
2360
2361 rc = lpfc_do_config_port(phba, mode);
2362 if (rc && lpfc_sli_mode == 3)
James Smart92d7f7b2007-06-17 19:56:38 -05002363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
James Smarted957682007-06-17 19:56:37 -05002364 "%d:1820 Unable to select SLI-3. "
2365 "Not supported by adapter.\n",
2366 phba->brd_no);
2367 if (rc && mode != 2)
2368 rc = lpfc_do_config_port(phba, 2);
2369 if (rc)
dea31012005-04-17 16:05:31 -05002370 goto lpfc_sli_hba_setup_error;
2371
James Smarted957682007-06-17 19:56:37 -05002372 if (phba->sli_rev == 3) {
2373 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2374 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2375 phba->sli3_options |= LPFC_SLI3_ENABLED;
2376 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2377
2378 } else {
2379 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2380 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
James Smart92d7f7b2007-06-17 19:56:38 -05002381 phba->sli3_options = 0;
James Smarted957682007-06-17 19:56:37 -05002382 }
2383
2384 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart92d7f7b2007-06-17 19:56:38 -05002385 "%d:0444 Firmware in SLI %x mode. Max_vpi %d\n",
2386 phba->brd_no, phba->sli_rev, phba->max_vpi);
James Smarted957682007-06-17 19:56:37 -05002387 rc = lpfc_sli_ring_map(phba);
dea31012005-04-17 16:05:31 -05002388
2389 if (rc)
2390 goto lpfc_sli_hba_setup_error;
2391
James Smart92d7f7b2007-06-17 19:56:38 -05002392 /* Init HBQs */
James Smarted957682007-06-17 19:56:37 -05002393
2394 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2395 rc = lpfc_sli_hbq_setup(phba);
2396 if (rc)
2397 goto lpfc_sli_hba_setup_error;
2398 }
2399
dea31012005-04-17 16:05:31 -05002400 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2401
2402 rc = lpfc_config_port_post(phba);
2403 if (rc)
2404 goto lpfc_sli_hba_setup_error;
2405
James Smarted957682007-06-17 19:56:37 -05002406 return rc;
2407
James Smart92d7f7b2007-06-17 19:56:38 -05002408lpfc_sli_hba_setup_error:
James Smart2e0fef82007-06-17 19:56:36 -05002409 phba->link_state = LPFC_HBA_ERROR;
James Smarted957682007-06-17 19:56:37 -05002410 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2411 "%d:0445 Firmware initialization failed\n",
2412 phba->brd_no);
dea31012005-04-17 16:05:31 -05002413 return rc;
2414}
2415
dea31012005-04-17 16:05:31 -05002416/*! lpfc_mbox_timeout
2417 *
2418 * \pre
2419 * \post
2420 * \param hba Pointer to per struct lpfc_hba structure
2421 * \param l1 Pointer to the driver's mailbox queue.
2422 * \return
2423 * void
2424 *
2425 * \b Description:
2426 *
2427 * This routine handles mailbox timeout events at timer interrupt context.
2428 */
2429void
2430lpfc_mbox_timeout(unsigned long ptr)
2431{
James Smart92d7f7b2007-06-17 19:56:38 -05002432 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
dea31012005-04-17 16:05:31 -05002433 unsigned long iflag;
James Smart2e0fef82007-06-17 19:56:36 -05002434 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05002435
James Smart2e0fef82007-06-17 19:56:36 -05002436 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05002437 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002438 if (!tmo_posted)
2439 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2440 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2441
2442 if (!tmo_posted) {
James Smart92d7f7b2007-06-17 19:56:38 -05002443 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002444 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05002445 lpfc_worker_wake_up(phba);
2446 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05002447 }
dea31012005-04-17 16:05:31 -05002448}
2449
2450void
2451lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2452{
James Smart2e0fef82007-06-17 19:56:36 -05002453 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2454 MAILBOX_t *mb = &pmbox->mb;
James Smart1dcb58e2007-04-25 09:51:30 -04002455 struct lpfc_sli *psli = &phba->sli;
2456 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002457
James Smart2e0fef82007-06-17 19:56:36 -05002458 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
dea31012005-04-17 16:05:31 -05002459 return;
2460 }
2461
dea31012005-04-17 16:05:31 -05002462 /* Mbox cmd <mbxCommand> timeout */
James Smarted957682007-06-17 19:56:37 -05002463 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05002464 "%d:0310 Mailbox command x%x timeout Data: x%x x%x "
2465 "x%p\n",
2466 phba->brd_no,
2467 mb->mbxCommand,
2468 phba->pport->port_state,
2469 phba->sli.sli_flag,
2470 phba->sli.mbox_active);
dea31012005-04-17 16:05:31 -05002471
James Smart1dcb58e2007-04-25 09:51:30 -04002472 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2473 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2474 * it to fail all oustanding SCSI IO.
2475 */
James Smart2e0fef82007-06-17 19:56:36 -05002476 spin_lock_irq(&phba->pport->work_port_lock);
2477 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2478 spin_unlock_irq(&phba->pport->work_port_lock);
2479 spin_lock_irq(&phba->hbalock);
2480 phba->link_state = LPFC_LINK_UNKNOWN;
2481 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart1dcb58e2007-04-25 09:51:30 -04002482 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002483 spin_unlock_irq(&phba->hbalock);
James Smart1dcb58e2007-04-25 09:51:30 -04002484
2485 pring = &psli->ring[psli->fcp_ring];
2486 lpfc_sli_abort_iocb_ring(phba, pring);
2487
2488 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2489 "%d:0316 Resetting board due to mailbox timeout\n",
2490 phba->brd_no);
2491 /*
2492 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2493 * on oustanding mailbox commands.
2494 */
2495 lpfc_offline_prep(phba);
2496 lpfc_offline(phba);
2497 lpfc_sli_brdrestart(phba);
2498 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2499 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2500 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002501 return;
2502}
2503
2504int
James Smart2e0fef82007-06-17 19:56:36 -05002505lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
dea31012005-04-17 16:05:31 -05002506{
dea31012005-04-17 16:05:31 -05002507 MAILBOX_t *mb;
James Smart2e0fef82007-06-17 19:56:36 -05002508 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002509 uint32_t status, evtctr;
2510 uint32_t ha_copy;
2511 int i;
2512 unsigned long drvr_flag = 0;
2513 volatile uint32_t word0, ldata;
2514 void __iomem *to_slim;
2515
James Smarted957682007-06-17 19:56:37 -05002516 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
James Smart92d7f7b2007-06-17 19:56:38 -05002517 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
James Smarted957682007-06-17 19:56:37 -05002518 if(!pmbox->vport) {
2519 lpfc_printf_log(phba, KERN_ERR,
James Smart92d7f7b2007-06-17 19:56:38 -05002520 LOG_MBOX | LOG_VPORT,
James Smarted957682007-06-17 19:56:37 -05002521 "%d:1806 Mbox x%x failed. No vport\n",
2522 phba->brd_no,
2523 pmbox->mb.mbxCommand);
2524 dump_stack();
2525 return MBXERR_ERROR;
2526 }
2527 }
2528
James Smart92d7f7b2007-06-17 19:56:38 -05002529
Linas Vepstas8d63f372007-02-14 14:28:36 -06002530 /* If the PCI channel is in offline state, do not post mbox. */
2531 if (unlikely(pci_channel_offline(phba->pcidev)))
2532 return MBX_NOT_FINISHED;
2533
James Smart2e0fef82007-06-17 19:56:36 -05002534 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002535 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002536
2537
dea31012005-04-17 16:05:31 -05002538 mb = &pmbox->mb;
2539 status = MBX_SUCCESS;
2540
James Smart2e0fef82007-06-17 19:56:36 -05002541 if (phba->link_state == LPFC_HBA_ERROR) {
2542 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
Jamie Wellnitz41415862006-02-28 19:25:27 -05002543
2544 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002545 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
James Smart2e0fef82007-06-17 19:56:36 -05002546 return MBX_NOT_FINISHED;
Jamie Wellnitz41415862006-02-28 19:25:27 -05002547 }
2548
James Smart92908312006-03-07 15:04:13 -05002549 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2550 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
James Smart2e0fef82007-06-17 19:56:36 -05002551 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
James Smart92d7f7b2007-06-17 19:56:38 -05002552 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
James Smart2e0fef82007-06-17 19:56:36 -05002553 return MBX_NOT_FINISHED;
James Smart92908312006-03-07 15:04:13 -05002554 }
2555
dea31012005-04-17 16:05:31 -05002556 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2557 /* Polling for a mbox command when another one is already active
2558 * is not allowed in SLI. Also, the driver must have established
2559 * SLI2 mode to queue and process multiple mbox commands.
2560 */
2561
2562 if (flag & MBX_POLL) {
James Smart2e0fef82007-06-17 19:56:36 -05002563 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002564
2565 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002566 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002567 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002568 }
2569
2570 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002571 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002572 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002573 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002574 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002575 }
2576
2577 /* Handle STOP IOCB processing flag. This is only meaningful
2578 * if we are not polling for mbox completion.
2579 */
2580 if (flag & MBX_STOP_IOCB) {
2581 flag &= ~MBX_STOP_IOCB;
2582 /* Now flag each ring */
2583 for (i = 0; i < psli->num_rings; i++) {
2584 /* If the ring is active, flag it */
2585 if (psli->ring[i].cmdringaddr) {
2586 psli->ring[i].flag |=
2587 LPFC_STOP_IOCB_MBX;
2588 }
2589 }
2590 }
2591
2592 /* Another mailbox command is still being processed, queue this
2593 * command to be processed later.
2594 */
2595 lpfc_mbox_put(phba, pmbox);
2596
2597 /* Mbox cmd issue - BUSY */
James Smarted957682007-06-17 19:56:37 -05002598 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05002599 "%d (%d):0308 Mbox cmd issue - BUSY Data: "
2600 "x%x x%x x%x x%x\n",
2601 phba->brd_no,
2602 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2603 mb->mbxCommand, phba->pport->port_state,
2604 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05002605
2606 psli->slistat.mbox_busy++;
James Smart2e0fef82007-06-17 19:56:36 -05002607 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002608
James Smart858c9f62007-06-17 19:56:39 -05002609 if (pmbox->vport) {
2610 lpfc_debugfs_disc_trc(pmbox->vport,
2611 LPFC_DISC_TRC_MBOX_VPORT,
2612 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2613 (uint32_t)mb->mbxCommand,
2614 mb->un.varWords[0], mb->un.varWords[1]);
2615 }
2616 else {
2617 lpfc_debugfs_disc_trc(phba->pport,
2618 LPFC_DISC_TRC_MBOX,
2619 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2620 (uint32_t)mb->mbxCommand,
2621 mb->un.varWords[0], mb->un.varWords[1]);
2622 }
2623
James Smart2e0fef82007-06-17 19:56:36 -05002624 return MBX_BUSY;
dea31012005-04-17 16:05:31 -05002625 }
2626
2627 /* Handle STOP IOCB processing flag. This is only meaningful
2628 * if we are not polling for mbox completion.
2629 */
2630 if (flag & MBX_STOP_IOCB) {
2631 flag &= ~MBX_STOP_IOCB;
2632 if (flag == MBX_NOWAIT) {
2633 /* Now flag each ring */
2634 for (i = 0; i < psli->num_rings; i++) {
2635 /* If the ring is active, flag it */
2636 if (psli->ring[i].cmdringaddr) {
2637 psli->ring[i].flag |=
2638 LPFC_STOP_IOCB_MBX;
2639 }
2640 }
2641 }
2642 }
2643
2644 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2645
2646 /* If we are not polling, we MUST be in SLI2 mode */
2647 if (flag != MBX_POLL) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002648 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2649 (mb->mbxCommand != MBX_KILL_BOARD)) {
dea31012005-04-17 16:05:31 -05002650 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002651 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002652 /* Mbox command <mbxCommand> cannot issue */
James Smart92d7f7b2007-06-17 19:56:38 -05002653 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
James Smart2e0fef82007-06-17 19:56:36 -05002654 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002655 }
2656 /* timeout active mbox command */
James Smarta309a6b2006-08-01 07:33:43 -04002657 mod_timer(&psli->mbox_tmo, (jiffies +
2658 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
dea31012005-04-17 16:05:31 -05002659 }
2660
2661 /* Mailbox cmd <cmd> issue */
James Smarted957682007-06-17 19:56:37 -05002662 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05002663 "%d (%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2664 "x%x\n",
2665 phba->brd_no, pmbox->vport ? pmbox->vport->vpi : 0,
2666 mb->mbxCommand, phba->pport->port_state,
2667 psli->sli_flag, flag);
dea31012005-04-17 16:05:31 -05002668
James Smart858c9f62007-06-17 19:56:39 -05002669 if (mb->mbxCommand != MBX_HEARTBEAT) {
2670 if (pmbox->vport) {
2671 lpfc_debugfs_disc_trc(pmbox->vport,
2672 LPFC_DISC_TRC_MBOX_VPORT,
2673 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2674 (uint32_t)mb->mbxCommand,
2675 mb->un.varWords[0], mb->un.varWords[1]);
2676 }
2677 else {
2678 lpfc_debugfs_disc_trc(phba->pport,
2679 LPFC_DISC_TRC_MBOX,
2680 "MBOX Send: cmd:x%x mb:x%x x%x",
2681 (uint32_t)mb->mbxCommand,
2682 mb->un.varWords[0], mb->un.varWords[1]);
2683 }
2684 }
2685
dea31012005-04-17 16:05:31 -05002686 psli->slistat.mbox_cmd++;
2687 evtctr = psli->slistat.mbox_event;
2688
2689 /* next set own bit for the adapter and copy over command word */
2690 mb->mbxOwner = OWN_CHIP;
2691
2692 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002693 /* First copy command data to host SLIM area */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002694 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002695 } else {
James Smart92908312006-03-07 15:04:13 -05002696 if (mb->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05002697 /* copy command data into host mbox for cmpl */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002698 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
James Smart92d7f7b2007-06-17 19:56:38 -05002699 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002700 }
2701
2702 /* First copy mbox command data to HBA SLIM, skip past first
2703 word */
2704 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2705 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2706 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2707
2708 /* Next copy over first word, with mbxOwner set */
2709 ldata = *((volatile uint32_t *)mb);
2710 to_slim = phba->MBslimaddr;
2711 writel(ldata, to_slim);
2712 readl(to_slim); /* flush */
2713
2714 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2715 /* switch over to host mailbox */
2716 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2717 }
2718 }
2719
2720 wmb();
2721 /* interrupt board to doit right away */
2722 writel(CA_MBATT, phba->CAregaddr);
2723 readl(phba->CAregaddr); /* flush */
2724
2725 switch (flag) {
2726 case MBX_NOWAIT:
2727 /* Don't wait for it to finish, just return */
2728 psli->mbox_active = pmbox;
2729 break;
2730
2731 case MBX_POLL:
dea31012005-04-17 16:05:31 -05002732 psli->mbox_active = NULL;
2733 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2734 /* First read mbox status word */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002735 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002736 word0 = le32_to_cpu(word0);
2737 } else {
2738 /* First read mbox status word */
2739 word0 = readl(phba->MBslimaddr);
2740 }
2741
2742 /* Read the HBA Host Attention Register */
2743 ha_copy = readl(phba->HAregaddr);
2744
James Smarta309a6b2006-08-01 07:33:43 -04002745 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2746 i *= 1000; /* Convert to ms */
2747
dea31012005-04-17 16:05:31 -05002748 /* Wait for command to complete */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002749 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2750 (!(ha_copy & HA_MBATT) &&
James Smart2e0fef82007-06-17 19:56:36 -05002751 (phba->link_state > LPFC_WARM_START))) {
James Smarta309a6b2006-08-01 07:33:43 -04002752 if (i-- <= 0) {
dea31012005-04-17 16:05:31 -05002753 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05002754 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05002755 drvr_flag);
James Smart2e0fef82007-06-17 19:56:36 -05002756 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05002757 }
2758
2759 /* Check if we took a mbox interrupt while we were
2760 polling */
2761 if (((word0 & OWN_CHIP) != OWN_CHIP)
2762 && (evtctr != psli->slistat.mbox_event))
2763 break;
2764
James Smart2e0fef82007-06-17 19:56:36 -05002765 spin_unlock_irqrestore(&phba->hbalock,
dea31012005-04-17 16:05:31 -05002766 drvr_flag);
2767
James Smart1dcb58e2007-04-25 09:51:30 -04002768 msleep(1);
dea31012005-04-17 16:05:31 -05002769
James Smart2e0fef82007-06-17 19:56:36 -05002770 spin_lock_irqsave(&phba->hbalock, drvr_flag);
dea31012005-04-17 16:05:31 -05002771
2772 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2773 /* First copy command data */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002774 word0 = *((volatile uint32_t *)
2775 &phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002776 word0 = le32_to_cpu(word0);
2777 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2778 MAILBOX_t *slimmb;
2779 volatile uint32_t slimword0;
2780 /* Check real SLIM for any errors */
2781 slimword0 = readl(phba->MBslimaddr);
2782 slimmb = (MAILBOX_t *) & slimword0;
2783 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2784 && slimmb->mbxStatus) {
2785 psli->sli_flag &=
2786 ~LPFC_SLI2_ACTIVE;
2787 word0 = slimword0;
2788 }
2789 }
2790 } else {
2791 /* First copy command data */
2792 word0 = readl(phba->MBslimaddr);
2793 }
2794 /* Read the HBA Host Attention Register */
2795 ha_copy = readl(phba->HAregaddr);
2796 }
2797
2798 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002799 /* copy results back to user */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002800 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
James Smart92d7f7b2007-06-17 19:56:38 -05002801 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002802 } else {
2803 /* First copy command data */
2804 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2805 MAILBOX_CMD_SIZE);
2806 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2807 pmbox->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05002808 lpfc_memcpy_from_slim((void *)pmbox->context2,
dea31012005-04-17 16:05:31 -05002809 phba->MBslimaddr + DMP_RSP_OFFSET,
2810 mb->un.varDmp.word_cnt);
2811 }
2812 }
2813
2814 writel(HA_MBATT, phba->HAregaddr);
2815 readl(phba->HAregaddr); /* flush */
2816
2817 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2818 status = mb->mbxStatus;
2819 }
2820
James Smart2e0fef82007-06-17 19:56:36 -05002821 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2822 return status;
dea31012005-04-17 16:05:31 -05002823}
2824
James Smart92d7f7b2007-06-17 19:56:38 -05002825/*
2826 * Caller needs to hold lock.
2827 */
James Smart858c9f62007-06-17 19:56:39 -05002828static void
James Smart92d7f7b2007-06-17 19:56:38 -05002829__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05002830 struct lpfc_iocbq *piocb)
dea31012005-04-17 16:05:31 -05002831{
2832 /* Insert the caller's iocb in the txq tail for later processing. */
2833 list_add_tail(&piocb->list, &pring->txq);
2834 pring->txq_cnt++;
dea31012005-04-17 16:05:31 -05002835}
2836
2837static struct lpfc_iocbq *
2838lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05002839 struct lpfc_iocbq **piocb)
dea31012005-04-17 16:05:31 -05002840{
2841 struct lpfc_iocbq * nextiocb;
2842
2843 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2844 if (!nextiocb) {
2845 nextiocb = *piocb;
2846 *piocb = NULL;
2847 }
2848
2849 return nextiocb;
2850}
2851
James Smart92d7f7b2007-06-17 19:56:38 -05002852/*
2853 * Lockless version of lpfc_sli_issue_iocb.
2854 */
dea31012005-04-17 16:05:31 -05002855int
James Smart92d7f7b2007-06-17 19:56:38 -05002856__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
dea31012005-04-17 16:05:31 -05002857 struct lpfc_iocbq *piocb, uint32_t flag)
2858{
2859 struct lpfc_iocbq *nextiocb;
2860 IOCB_t *iocb;
2861
James Smart92d7f7b2007-06-17 19:56:38 -05002862 if (piocb->iocb_cmpl && (!piocb->vport) &&
2863 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
2864 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
2865 lpfc_printf_log(phba, KERN_ERR,
2866 LOG_SLI | LOG_VPORT,
2867 "%d:1807 IOCB x%x failed. No vport\n",
2868 phba->brd_no,
2869 piocb->iocb.ulpCommand);
2870 dump_stack();
2871 return IOCB_ERROR;
2872 }
2873
2874
Linas Vepstas8d63f372007-02-14 14:28:36 -06002875 /* If the PCI channel is in offline state, do not post iocbs. */
2876 if (unlikely(pci_channel_offline(phba->pcidev)))
2877 return IOCB_ERROR;
2878
dea31012005-04-17 16:05:31 -05002879 /*
2880 * We should never get an IOCB if we are in a < LINK_DOWN state
2881 */
James Smart2e0fef82007-06-17 19:56:36 -05002882 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05002883 return IOCB_ERROR;
2884
2885 /*
2886 * Check to see if we are blocking IOCB processing because of a
2887 * outstanding mbox command.
2888 */
2889 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2890 goto iocb_busy;
2891
James Smart2e0fef82007-06-17 19:56:36 -05002892 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
dea31012005-04-17 16:05:31 -05002893 /*
James Smart2680eea2007-04-25 09:52:55 -04002894 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
dea31012005-04-17 16:05:31 -05002895 * can be issued if the link is not up.
2896 */
2897 switch (piocb->iocb.ulpCommand) {
2898 case CMD_QUE_RING_BUF_CN:
2899 case CMD_QUE_RING_BUF64_CN:
dea31012005-04-17 16:05:31 -05002900 /*
2901 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2902 * completion, iocb_cmpl MUST be 0.
2903 */
2904 if (piocb->iocb_cmpl)
2905 piocb->iocb_cmpl = NULL;
2906 /*FALLTHROUGH*/
2907 case CMD_CREATE_XRI_CR:
James Smart2680eea2007-04-25 09:52:55 -04002908 case CMD_CLOSE_XRI_CN:
2909 case CMD_CLOSE_XRI_CX:
dea31012005-04-17 16:05:31 -05002910 break;
2911 default:
2912 goto iocb_busy;
2913 }
2914
2915 /*
2916 * For FCP commands, we must be in a state where we can process link
2917 * attention events.
2918 */
2919 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
James Smart92d7f7b2007-06-17 19:56:38 -05002920 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
dea31012005-04-17 16:05:31 -05002921 goto iocb_busy;
James Smart92d7f7b2007-06-17 19:56:38 -05002922 }
dea31012005-04-17 16:05:31 -05002923
dea31012005-04-17 16:05:31 -05002924 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2925 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2926 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2927
2928 if (iocb)
2929 lpfc_sli_update_ring(phba, pring);
2930 else
2931 lpfc_sli_update_full_ring(phba, pring);
2932
2933 if (!piocb)
2934 return IOCB_SUCCESS;
2935
2936 goto out_busy;
2937
2938 iocb_busy:
2939 pring->stats.iocb_cmd_delay++;
2940
2941 out_busy:
2942
2943 if (!(flag & SLI_IOCB_RET_IOCB)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002944 __lpfc_sli_ringtx_put(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05002945 return IOCB_SUCCESS;
2946 }
2947
2948 return IOCB_BUSY;
2949}
2950
James Smart92d7f7b2007-06-17 19:56:38 -05002951
2952int
2953lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2954 struct lpfc_iocbq *piocb, uint32_t flag)
2955{
2956 unsigned long iflags;
2957 int rc;
2958
2959 spin_lock_irqsave(&phba->hbalock, iflags);
2960 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
2961 spin_unlock_irqrestore(&phba->hbalock, iflags);
2962
2963 return rc;
2964}
2965
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002966static int
2967lpfc_extra_ring_setup( struct lpfc_hba *phba)
2968{
2969 struct lpfc_sli *psli;
2970 struct lpfc_sli_ring *pring;
2971
2972 psli = &phba->sli;
2973
2974 /* Adjust cmd/rsp ring iocb entries more evenly */
James Smarta4bc3372006-12-02 13:34:16 -05002975
2976 /* Take some away from the FCP ring */
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002977 pring = &psli->ring[psli->fcp_ring];
2978 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2979 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2980 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2981 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2982
James Smarta4bc3372006-12-02 13:34:16 -05002983 /* and give them to the extra ring */
2984 pring = &psli->ring[psli->extra_ring];
2985
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002986 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2987 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2988 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2989 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2990
2991 /* Setup default profile for this ring */
2992 pring->iotag_max = 4096;
2993 pring->num_mask = 1;
2994 pring->prt[0].profile = 0; /* Mask 0 */
James Smarta4bc3372006-12-02 13:34:16 -05002995 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2996 pring->prt[0].type = phba->cfg_multi_ring_type;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002997 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2998 return 0;
2999}
3000
dea31012005-04-17 16:05:31 -05003001int
3002lpfc_sli_setup(struct lpfc_hba *phba)
3003{
James Smarted957682007-06-17 19:56:37 -05003004 int i, totiocbsize = 0;
dea31012005-04-17 16:05:31 -05003005 struct lpfc_sli *psli = &phba->sli;
3006 struct lpfc_sli_ring *pring;
3007
3008 psli->num_rings = MAX_CONFIGURED_RINGS;
3009 psli->sli_flag = 0;
3010 psli->fcp_ring = LPFC_FCP_RING;
3011 psli->next_ring = LPFC_FCP_NEXT_RING;
James Smarta4bc3372006-12-02 13:34:16 -05003012 psli->extra_ring = LPFC_EXTRA_RING;
dea31012005-04-17 16:05:31 -05003013
James Bottomley604a3e32005-10-29 10:28:33 -05003014 psli->iocbq_lookup = NULL;
3015 psli->iocbq_lookup_len = 0;
3016 psli->last_iotag = 0;
3017
dea31012005-04-17 16:05:31 -05003018 for (i = 0; i < psli->num_rings; i++) {
3019 pring = &psli->ring[i];
3020 switch (i) {
3021 case LPFC_FCP_RING: /* ring 0 - FCP */
3022 /* numCiocb and numRiocb are used in config_port */
3023 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3024 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3025 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3026 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3027 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3028 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003029 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003030 SLI3_IOCB_CMD_SIZE :
3031 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003032 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003033 SLI3_IOCB_RSP_SIZE :
3034 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05003035 pring->iotag_ctr = 0;
3036 pring->iotag_max =
James Smart92d7f7b2007-06-17 19:56:38 -05003037 (phba->cfg_hba_queue_depth * 2);
dea31012005-04-17 16:05:31 -05003038 pring->fast_iotag = pring->iotag_max;
3039 pring->num_mask = 0;
3040 break;
James Smarta4bc3372006-12-02 13:34:16 -05003041 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
dea31012005-04-17 16:05:31 -05003042 /* numCiocb and numRiocb are used in config_port */
3043 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3044 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003045 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003046 SLI3_IOCB_CMD_SIZE :
3047 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003048 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003049 SLI3_IOCB_RSP_SIZE :
3050 SLI2_IOCB_RSP_SIZE;
James Smart2e0fef82007-06-17 19:56:36 -05003051 pring->iotag_max = phba->cfg_hba_queue_depth;
dea31012005-04-17 16:05:31 -05003052 pring->num_mask = 0;
3053 break;
3054 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3055 /* numCiocb and numRiocb are used in config_port */
3056 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3057 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
James Smarted957682007-06-17 19:56:37 -05003058 pring->sizeCiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003059 SLI3_IOCB_CMD_SIZE :
3060 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -05003061 pring->sizeRiocb = (phba->sli_rev == 3) ?
James Smart92d7f7b2007-06-17 19:56:38 -05003062 SLI3_IOCB_RSP_SIZE :
3063 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -05003064 pring->fast_iotag = 0;
3065 pring->iotag_ctr = 0;
3066 pring->iotag_max = 4096;
3067 pring->num_mask = 4;
3068 pring->prt[0].profile = 0; /* Mask 0 */
3069 pring->prt[0].rctl = FC_ELS_REQ;
3070 pring->prt[0].type = FC_ELS_DATA;
3071 pring->prt[0].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003072 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05003073 pring->prt[1].profile = 0; /* Mask 1 */
3074 pring->prt[1].rctl = FC_ELS_RSP;
3075 pring->prt[1].type = FC_ELS_DATA;
3076 pring->prt[1].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003077 lpfc_els_unsol_event;
dea31012005-04-17 16:05:31 -05003078 pring->prt[2].profile = 0; /* Mask 2 */
3079 /* NameServer Inquiry */
3080 pring->prt[2].rctl = FC_UNSOL_CTL;
3081 /* NameServer */
3082 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3083 pring->prt[2].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003084 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05003085 pring->prt[3].profile = 0; /* Mask 3 */
3086 /* NameServer response */
3087 pring->prt[3].rctl = FC_SOL_CTL;
3088 /* NameServer */
3089 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3090 pring->prt[3].lpfc_sli_rcv_unsol_event =
James Smart92d7f7b2007-06-17 19:56:38 -05003091 lpfc_ct_unsol_event;
dea31012005-04-17 16:05:31 -05003092 break;
3093 }
James Smarted957682007-06-17 19:56:37 -05003094 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
James Smart92d7f7b2007-06-17 19:56:38 -05003095 (pring->numRiocb * pring->sizeRiocb);
dea31012005-04-17 16:05:31 -05003096 }
James Smarted957682007-06-17 19:56:37 -05003097 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
dea31012005-04-17 16:05:31 -05003098 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3100 "%d:0462 Too many cmd / rsp ring entries in "
James Smarted957682007-06-17 19:56:37 -05003101 "SLI2 SLIM Data: x%x x%lx\n",
3102 phba->brd_no, totiocbsize,
3103 (unsigned long) MAX_SLIM_IOCB_SIZE);
dea31012005-04-17 16:05:31 -05003104 }
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003105 if (phba->cfg_multi_ring_support == 2)
3106 lpfc_extra_ring_setup(phba);
dea31012005-04-17 16:05:31 -05003107
3108 return 0;
3109}
3110
3111int
James Smart2e0fef82007-06-17 19:56:36 -05003112lpfc_sli_queue_setup(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003113{
3114 struct lpfc_sli *psli;
3115 struct lpfc_sli_ring *pring;
James Bottomley604a3e32005-10-29 10:28:33 -05003116 int i;
dea31012005-04-17 16:05:31 -05003117
3118 psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003119 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003120 INIT_LIST_HEAD(&psli->mboxq);
James Smart92d7f7b2007-06-17 19:56:38 -05003121 INIT_LIST_HEAD(&psli->mboxq_cmpl);
dea31012005-04-17 16:05:31 -05003122 /* Initialize list headers for txq and txcmplq as double linked lists */
3123 for (i = 0; i < psli->num_rings; i++) {
3124 pring = &psli->ring[i];
3125 pring->ringno = i;
3126 pring->next_cmdidx = 0;
3127 pring->local_getidx = 0;
3128 pring->cmdidx = 0;
3129 INIT_LIST_HEAD(&pring->txq);
3130 INIT_LIST_HEAD(&pring->txcmplq);
3131 INIT_LIST_HEAD(&pring->iocb_continueq);
3132 INIT_LIST_HEAD(&pring->postbufq);
dea31012005-04-17 16:05:31 -05003133 }
James Smart2e0fef82007-06-17 19:56:36 -05003134 spin_unlock_irq(&phba->hbalock);
3135 return 1;
dea31012005-04-17 16:05:31 -05003136}
3137
3138int
James Smart92d7f7b2007-06-17 19:56:38 -05003139lpfc_sli_host_down(struct lpfc_vport *vport)
3140{
James Smart858c9f62007-06-17 19:56:39 -05003141 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05003142 struct lpfc_hba *phba = vport->phba;
3143 struct lpfc_sli *psli = &phba->sli;
3144 struct lpfc_sli_ring *pring;
3145 struct lpfc_iocbq *iocb, *next_iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003146 int i;
3147 unsigned long flags = 0;
3148 uint16_t prev_pring_flag;
3149
3150 lpfc_cleanup_discovery_resources(vport);
3151
3152 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003153 for (i = 0; i < psli->num_rings; i++) {
3154 pring = &psli->ring[i];
3155 prev_pring_flag = pring->flag;
James Smart858c9f62007-06-17 19:56:39 -05003156 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3157 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05003158 /*
3159 * Error everything on the txq since these iocbs have not been
3160 * given to the FW yet.
3161 */
James Smart92d7f7b2007-06-17 19:56:38 -05003162 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3163 if (iocb->vport != vport)
3164 continue;
James Smart858c9f62007-06-17 19:56:39 -05003165 list_move_tail(&iocb->list, &completions);
James Smart92d7f7b2007-06-17 19:56:38 -05003166 pring->txq_cnt--;
James Smart92d7f7b2007-06-17 19:56:38 -05003167 }
3168
3169 /* Next issue ABTS for everything on the txcmplq */
3170 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3171 list) {
3172 if (iocb->vport != vport)
3173 continue;
3174 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3175 }
3176
3177 pring->flag = prev_pring_flag;
3178 }
3179
3180 spin_unlock_irqrestore(&phba->hbalock, flags);
3181
James Smart858c9f62007-06-17 19:56:39 -05003182 while (!list_empty(&completions)) {
3183 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3184
3185 if (!iocb->iocb_cmpl)
3186 lpfc_sli_release_iocbq(phba, iocb);
3187 else {
3188 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3189 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3190 (iocb->iocb_cmpl) (phba, iocb, iocb);
3191 }
3192 }
James Smart92d7f7b2007-06-17 19:56:38 -05003193 return 1;
3194}
3195
3196int
James Smart2e0fef82007-06-17 19:56:36 -05003197lpfc_sli_hba_down(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003198{
James Smart2534ba72007-04-25 09:52:20 -04003199 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003200 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003201 struct lpfc_sli_ring *pring;
3202 LPFC_MBOXQ_t *pmb;
James Smart2534ba72007-04-25 09:52:20 -04003203 struct lpfc_iocbq *iocb;
3204 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003205 int i;
3206 unsigned long flags = 0;
3207
dea31012005-04-17 16:05:31 -05003208 lpfc_hba_down_prep(phba);
3209
James Smart92d7f7b2007-06-17 19:56:38 -05003210 lpfc_fabric_abort_hba(phba);
3211
James Smart2e0fef82007-06-17 19:56:36 -05003212 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003213 for (i = 0; i < psli->num_rings; i++) {
3214 pring = &psli->ring[i];
James Smart858c9f62007-06-17 19:56:39 -05003215 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3216 pring->flag |= LPFC_DEFERRED_RING_EVENT;
dea31012005-04-17 16:05:31 -05003217
3218 /*
3219 * Error everything on the txq since these iocbs have not been
3220 * given to the FW yet.
3221 */
James Smart2534ba72007-04-25 09:52:20 -04003222 list_splice_init(&pring->txq, &completions);
dea31012005-04-17 16:05:31 -05003223 pring->txq_cnt = 0;
3224
dea31012005-04-17 16:05:31 -05003225 }
James Smart2e0fef82007-06-17 19:56:36 -05003226 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003227
James Smart2534ba72007-04-25 09:52:20 -04003228 while (!list_empty(&completions)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003229 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
James Smart2534ba72007-04-25 09:52:20 -04003230 cmd = &iocb->iocb;
James Smart2534ba72007-04-25 09:52:20 -04003231
James Smart2e0fef82007-06-17 19:56:36 -05003232 if (!iocb->iocb_cmpl)
3233 lpfc_sli_release_iocbq(phba, iocb);
3234 else {
James Smart2534ba72007-04-25 09:52:20 -04003235 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3236 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3237 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05003238 }
James Smart2534ba72007-04-25 09:52:20 -04003239 }
3240
dea31012005-04-17 16:05:31 -05003241 /* Return any active mbox cmds */
3242 del_timer_sync(&psli->mbox_tmo);
James Smarted957682007-06-17 19:56:37 -05003243 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003244
3245 spin_lock(&phba->pport->work_port_lock);
3246 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3247 spin_unlock(&phba->pport->work_port_lock);
3248
3249 if (psli->mbox_active) {
3250 list_add_tail(&psli->mbox_active->list, &completions);
James Smart2e0fef82007-06-17 19:56:36 -05003251 psli->mbox_active = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003252 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
dea31012005-04-17 16:05:31 -05003253 }
dea31012005-04-17 16:05:31 -05003254
James Smart92d7f7b2007-06-17 19:56:38 -05003255 /* Return any pending or completed mbox cmds */
3256 list_splice_init(&phba->sli.mboxq, &completions);
3257 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3258 INIT_LIST_HEAD(&psli->mboxq);
3259 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3260
3261 spin_unlock_irqrestore(&phba->hbalock, flags);
3262
3263 while (!list_empty(&completions)) {
3264 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
dea31012005-04-17 16:05:31 -05003265 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3266 if (pmb->mbox_cmpl) {
dea31012005-04-17 16:05:31 -05003267 pmb->mbox_cmpl(phba,pmb);
dea31012005-04-17 16:05:31 -05003268 }
3269 }
dea31012005-04-17 16:05:31 -05003270 return 1;
3271}
3272
3273void
3274lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3275{
3276 uint32_t *src = srcp;
3277 uint32_t *dest = destp;
3278 uint32_t ldata;
3279 int i;
3280
3281 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3282 ldata = *src;
3283 ldata = le32_to_cpu(ldata);
3284 *dest = ldata;
3285 src++;
3286 dest++;
3287 }
3288}
3289
3290int
James Smart2e0fef82007-06-17 19:56:36 -05003291lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3292 struct lpfc_dmabuf *mp)
dea31012005-04-17 16:05:31 -05003293{
3294 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3295 later */
James Smart2e0fef82007-06-17 19:56:36 -05003296 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003297 list_add_tail(&mp->list, &pring->postbufq);
dea31012005-04-17 16:05:31 -05003298 pring->postbufq_cnt++;
James Smart2e0fef82007-06-17 19:56:36 -05003299 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003300 return 0;
3301}
3302
3303
3304struct lpfc_dmabuf *
3305lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3306 dma_addr_t phys)
3307{
3308 struct lpfc_dmabuf *mp, *next_mp;
3309 struct list_head *slp = &pring->postbufq;
3310
3311 /* Search postbufq, from the begining, looking for a match on phys */
James Smart2e0fef82007-06-17 19:56:36 -05003312 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003313 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3314 if (mp->phys == phys) {
3315 list_del_init(&mp->list);
3316 pring->postbufq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05003317 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003318 return mp;
3319 }
3320 }
3321
James Smart2e0fef82007-06-17 19:56:36 -05003322 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3324 "%d:0410 Cannot find virtual addr for mapped buf on "
3325 "ring %d Data x%llx x%p x%p x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003326 phba->brd_no, pring->ringno, (unsigned long long)phys,
dea31012005-04-17 16:05:31 -05003327 slp->next, slp->prev, pring->postbufq_cnt);
3328 return NULL;
3329}
3330
3331static void
James Smart2e0fef82007-06-17 19:56:36 -05003332lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3333 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003334{
James Smart2e0fef82007-06-17 19:56:36 -05003335 IOCB_t *irsp = &rspiocb->iocb;
James Smart2680eea2007-04-25 09:52:55 -04003336 uint16_t abort_iotag, abort_context;
James Smart92d7f7b2007-06-17 19:56:38 -05003337 struct lpfc_iocbq *abort_iocb;
James Smart2680eea2007-04-25 09:52:55 -04003338 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3339
3340 abort_iocb = NULL;
James Smart2680eea2007-04-25 09:52:55 -04003341
3342 if (irsp->ulpStatus) {
3343 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3344 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3345
James Smart2e0fef82007-06-17 19:56:36 -05003346 spin_lock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04003347 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3348 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3349
James Smart92d7f7b2007-06-17 19:56:38 -05003350 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
3351 "%d:0327 Cannot abort els iocb %p "
3352 "with tag %x context %x, abort status %x, "
3353 "abort code %x\n",
3354 phba->brd_no, abort_iocb, abort_iotag,
3355 abort_context, irsp->ulpStatus,
3356 irsp->un.ulpWord[4]);
James Smart2680eea2007-04-25 09:52:55 -04003357
3358 /*
3359 * make sure we have the right iocbq before taking it
3360 * off the txcmplq and try to call completion routine.
3361 */
James Smart2e0fef82007-06-17 19:56:36 -05003362 if (!abort_iocb ||
3363 abort_iocb->iocb.ulpContext != abort_context ||
3364 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3365 spin_unlock_irq(&phba->hbalock);
3366 else {
James Smart92d7f7b2007-06-17 19:56:38 -05003367 list_del_init(&abort_iocb->list);
James Smart2680eea2007-04-25 09:52:55 -04003368 pring->txcmplq_cnt--;
James Smart2e0fef82007-06-17 19:56:36 -05003369 spin_unlock_irq(&phba->hbalock);
James Smart2680eea2007-04-25 09:52:55 -04003370
James Smart92d7f7b2007-06-17 19:56:38 -05003371 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3372 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3373 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3374 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
James Smart2680eea2007-04-25 09:52:55 -04003375 }
3376 }
3377
James Bottomley604a3e32005-10-29 10:28:33 -05003378 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003379 return;
3380}
3381
James Smart92d7f7b2007-06-17 19:56:38 -05003382static void
3383lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3384 struct lpfc_iocbq *rspiocb)
3385{
3386 IOCB_t *irsp = &rspiocb->iocb;
3387
3388 /* ELS cmd tag <ulpIoTag> completes */
3389 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3390 "%d (X):0133 Ignoring ELS cmd tag x%x completion Data: "
3391 "x%x x%x x%x\n",
3392 phba->brd_no, irsp->ulpIoTag, irsp->ulpStatus,
3393 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smart858c9f62007-06-17 19:56:39 -05003394 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3395 lpfc_ct_free_iocb(phba, cmdiocb);
3396 else
3397 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05003398 return;
3399}
3400
dea31012005-04-17 16:05:31 -05003401int
James Smart2e0fef82007-06-17 19:56:36 -05003402lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3403 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -05003404{
James Smart2e0fef82007-06-17 19:56:36 -05003405 struct lpfc_vport *vport = cmdiocb->vport;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003406 struct lpfc_iocbq *abtsiocbp;
dea31012005-04-17 16:05:31 -05003407 IOCB_t *icmd = NULL;
3408 IOCB_t *iabt = NULL;
James Smart07951072007-04-25 09:51:38 -04003409 int retval = IOCB_ERROR;
3410
James Smart92d7f7b2007-06-17 19:56:38 -05003411 /*
3412 * There are certain command types we don't want to abort. And we
3413 * don't want to abort commands that are already in the process of
3414 * being aborted.
James Smart07951072007-04-25 09:51:38 -04003415 */
3416 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05003417 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
James Smart92d7f7b2007-06-17 19:56:38 -05003418 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3419 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
James Smart07951072007-04-25 09:51:38 -04003420 return 0;
3421
James Smart858c9f62007-06-17 19:56:39 -05003422 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3423 * callback so that nothing happens when it finishes.
James Smart07951072007-04-25 09:51:38 -04003424 */
James Smart858c9f62007-06-17 19:56:39 -05003425 if ((vport->load_flag & FC_UNLOADING) &&
3426 (pring->ringno == LPFC_ELS_RING)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003427 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3428 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3429 else
3430 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
James Smart07951072007-04-25 09:51:38 -04003431 goto abort_iotag_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05003432 }
dea31012005-04-17 16:05:31 -05003433
3434 /* issue ABTS for this IOCB based on iotag */
James Smart92d7f7b2007-06-17 19:56:38 -05003435 abtsiocbp = __lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003436 if (abtsiocbp == NULL)
3437 return 0;
dea31012005-04-17 16:05:31 -05003438
James Smart07951072007-04-25 09:51:38 -04003439 /* This signals the response to set the correct status
3440 * before calling the completion handler.
3441 */
3442 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3443
dea31012005-04-17 16:05:31 -05003444 iabt = &abtsiocbp->iocb;
James Smart07951072007-04-25 09:51:38 -04003445 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3446 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3447 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05003448 iabt->ulpLe = 1;
James Smart07951072007-04-25 09:51:38 -04003449 iabt->ulpClass = icmd->ulpClass;
dea31012005-04-17 16:05:31 -05003450
James Smart2e0fef82007-06-17 19:56:36 -05003451 if (phba->link_state >= LPFC_LINK_UP)
James Smart07951072007-04-25 09:51:38 -04003452 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3453 else
3454 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3455
3456 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -04003457
3458 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart92d7f7b2007-06-17 19:56:38 -05003459 "%d (%d):0339 Abort xri x%x, original iotag x%x, "
3460 "abort cmd iotag x%x\n",
3461 phba->brd_no, vport->vpi,
3462 iabt->un.acxri.abortContextTag,
James Smart5b8bd0c2007-04-25 09:52:49 -04003463 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
James Smart92d7f7b2007-06-17 19:56:38 -05003464 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
James Smart07951072007-04-25 09:51:38 -04003465
3466abort_iotag_exit:
James Smart2e0fef82007-06-17 19:56:36 -05003467 /*
3468 * Caller to this routine should check for IOCB_ERROR
3469 * and handle it properly. This routine no longer removes
3470 * iocb off txcmplq and call compl in case of IOCB_ERROR.
James Smart07951072007-04-25 09:51:38 -04003471 */
James Smart2e0fef82007-06-17 19:56:36 -05003472 return retval;
dea31012005-04-17 16:05:31 -05003473}
3474
3475static int
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003476lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
3477 uint64_t lun_id, uint32_t ctx,
3478 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05003479{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003480 struct lpfc_scsi_buf *lpfc_cmd;
3481 struct scsi_cmnd *cmnd;
dea31012005-04-17 16:05:31 -05003482 int rc = 1;
3483
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003484 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3485 return rc;
3486
3487 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3488 cmnd = lpfc_cmd->pCmd;
3489
3490 if (cmnd == NULL)
dea31012005-04-17 16:05:31 -05003491 return rc;
3492
3493 switch (ctx_cmd) {
3494 case LPFC_CTX_LUN:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003495 if ((cmnd->device->id == tgt_id) &&
3496 (cmnd->device->lun == lun_id))
dea31012005-04-17 16:05:31 -05003497 rc = 0;
3498 break;
3499 case LPFC_CTX_TGT:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003500 if (cmnd->device->id == tgt_id)
dea31012005-04-17 16:05:31 -05003501 rc = 0;
3502 break;
3503 case LPFC_CTX_CTX:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003504 if (iocbq->iocb.ulpContext == ctx)
dea31012005-04-17 16:05:31 -05003505 rc = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003506 break;
dea31012005-04-17 16:05:31 -05003507 case LPFC_CTX_HOST:
3508 rc = 0;
3509 break;
3510 default:
3511 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3512 __FUNCTION__, ctx_cmd);
3513 break;
3514 }
3515
3516 return rc;
3517}
3518
3519int
3520lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart2e0fef82007-06-17 19:56:36 -05003521 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05003522{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003523 struct lpfc_iocbq *iocbq;
3524 int sum, i;
dea31012005-04-17 16:05:31 -05003525
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003526 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3527 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05003528
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003529 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
3530 0, ctx_cmd) == 0)
3531 sum++;
dea31012005-04-17 16:05:31 -05003532 }
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003533
dea31012005-04-17 16:05:31 -05003534 return sum;
3535}
3536
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003537void
James Smart2e0fef82007-06-17 19:56:36 -05003538lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3539 struct lpfc_iocbq *rspiocb)
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003540{
James Bottomley604a3e32005-10-29 10:28:33 -05003541 lpfc_sli_release_iocbq(phba, cmdiocb);
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003542 return;
3543}
3544
dea31012005-04-17 16:05:31 -05003545int
3546lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3547 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
3548 lpfc_ctx_cmd abort_cmd)
3549{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003550 struct lpfc_iocbq *iocbq;
3551 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05003552 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003553 int errcnt = 0, ret_val = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003554 int i;
dea31012005-04-17 16:05:31 -05003555
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003556 for (i = 1; i <= phba->sli.last_iotag; i++) {
3557 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05003558
James Smart2e0fef82007-06-17 19:56:36 -05003559 if (lpfc_sli_validate_fcp_iocb(iocbq, tgt_id, lun_id, 0,
3560 abort_cmd) != 0)
dea31012005-04-17 16:05:31 -05003561 continue;
3562
3563 /* issue ABTS for this IOCB based on iotag */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003564 abtsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05003565 if (abtsiocb == NULL) {
3566 errcnt++;
3567 continue;
3568 }
dea31012005-04-17 16:05:31 -05003569
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003570 cmd = &iocbq->iocb;
dea31012005-04-17 16:05:31 -05003571 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3572 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3573 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3574 abtsiocb->iocb.ulpLe = 1;
3575 abtsiocb->iocb.ulpClass = cmd->ulpClass;
James Smart2e0fef82007-06-17 19:56:36 -05003576 abtsiocb->vport = phba->pport;
dea31012005-04-17 16:05:31 -05003577
James Smart2e0fef82007-06-17 19:56:36 -05003578 if (lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05003579 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3580 else
3581 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3582
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04003583 /* Setup callback routine and issue the command. */
3584 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
dea31012005-04-17 16:05:31 -05003585 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3586 if (ret_val == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -05003587 lpfc_sli_release_iocbq(phba, abtsiocb);
dea31012005-04-17 16:05:31 -05003588 errcnt++;
3589 continue;
3590 }
3591 }
3592
3593 return errcnt;
3594}
3595
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003596static void
3597lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3598 struct lpfc_iocbq *cmdiocbq,
3599 struct lpfc_iocbq *rspiocbq)
dea31012005-04-17 16:05:31 -05003600{
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003601 wait_queue_head_t *pdone_q;
3602 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003603
James Smart2e0fef82007-06-17 19:56:36 -05003604 spin_lock_irqsave(&phba->hbalock, iflags);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003605 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3606 if (cmdiocbq->context2 && rspiocbq)
3607 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3608 &rspiocbq->iocb, sizeof(IOCB_t));
3609
3610 pdone_q = cmdiocbq->context_un.wait_queue;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003611 if (pdone_q)
3612 wake_up(pdone_q);
James Smart858c9f62007-06-17 19:56:39 -05003613 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003614 return;
3615}
3616
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003617/*
3618 * Issue the caller's iocb and wait for its completion, but no longer than the
3619 * caller's timeout. Note that iocb_flags is cleared before the
3620 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3621 * definition this is a wait function.
3622 */
James Smart92d7f7b2007-06-17 19:56:38 -05003623
dea31012005-04-17 16:05:31 -05003624int
James Smart2e0fef82007-06-17 19:56:36 -05003625lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3626 struct lpfc_sli_ring *pring,
3627 struct lpfc_iocbq *piocb,
3628 struct lpfc_iocbq *prspiocbq,
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003629 uint32_t timeout)
dea31012005-04-17 16:05:31 -05003630{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003631 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003632 long timeleft, timeout_req = 0;
3633 int retval = IOCB_SUCCESS;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003634 uint32_t creg_val;
dea31012005-04-17 16:05:31 -05003635
3636 /*
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003637 * If the caller has provided a response iocbq buffer, then context2
3638 * is NULL or its an error.
dea31012005-04-17 16:05:31 -05003639 */
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003640 if (prspiocbq) {
3641 if (piocb->context2)
3642 return IOCB_ERROR;
3643 piocb->context2 = prspiocbq;
dea31012005-04-17 16:05:31 -05003644 }
3645
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003646 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3647 piocb->context_un.wait_queue = &done_q;
3648 piocb->iocb_flag &= ~LPFC_IO_WAKE;
dea31012005-04-17 16:05:31 -05003649
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003650 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3651 creg_val = readl(phba->HCregaddr);
3652 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3653 writel(creg_val, phba->HCregaddr);
3654 readl(phba->HCregaddr); /* flush */
3655 }
3656
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003657 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3658 if (retval == IOCB_SUCCESS) {
3659 timeout_req = timeout * HZ;
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003660 timeleft = wait_event_timeout(done_q,
3661 piocb->iocb_flag & LPFC_IO_WAKE,
3662 timeout_req);
dea31012005-04-17 16:05:31 -05003663
James Smart7054a602007-04-25 09:52:34 -04003664 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3665 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3666 "%d:0331 IOCB wake signaled\n",
3667 phba->brd_no);
3668 } else if (timeleft == 0) {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003669 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04003670 "%d:0338 IOCB wait timeout error - no "
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003671 "wake response Data x%x\n",
3672 phba->brd_no, timeout);
3673 retval = IOCB_TIMEDOUT;
James Smart7054a602007-04-25 09:52:34 -04003674 } else {
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003675 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3676 "%d:0330 IOCB wake NOT set, "
3677 "Data x%x x%lx\n", phba->brd_no,
3678 timeout, (timeleft / jiffies));
3679 retval = IOCB_TIMEDOUT;
dea31012005-04-17 16:05:31 -05003680 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003681 } else {
3682 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3683 "%d:0332 IOCB wait issue failed, Data x%x\n",
3684 phba->brd_no, retval);
3685 retval = IOCB_ERROR;
dea31012005-04-17 16:05:31 -05003686 }
3687
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003688 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3689 creg_val = readl(phba->HCregaddr);
3690 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3691 writel(creg_val, phba->HCregaddr);
3692 readl(phba->HCregaddr); /* flush */
3693 }
3694
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003695 if (prspiocbq)
3696 piocb->context2 = NULL;
3697
3698 piocb->context_un.wait_queue = NULL;
3699 piocb->iocb_cmpl = NULL;
dea31012005-04-17 16:05:31 -05003700 return retval;
3701}
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003702
dea31012005-04-17 16:05:31 -05003703int
James Smart2e0fef82007-06-17 19:56:36 -05003704lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
dea31012005-04-17 16:05:31 -05003705 uint32_t timeout)
3706{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003707 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
dea31012005-04-17 16:05:31 -05003708 int retval;
James Smart858c9f62007-06-17 19:56:39 -05003709 unsigned long flag;
dea31012005-04-17 16:05:31 -05003710
3711 /* The caller must leave context1 empty. */
James Smart92d7f7b2007-06-17 19:56:38 -05003712 if (pmboxq->context1 != 0)
James Smart2e0fef82007-06-17 19:56:36 -05003713 return MBX_NOT_FINISHED;
dea31012005-04-17 16:05:31 -05003714
3715 /* setup wake call as IOCB callback */
3716 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3717 /* setup context field to pass wait_queue pointer to wake function */
3718 pmboxq->context1 = &done_q;
3719
dea31012005-04-17 16:05:31 -05003720 /* now issue the command */
3721 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3722
3723 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
James Smart7054a602007-04-25 09:52:34 -04003724 wait_event_interruptible_timeout(done_q,
3725 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3726 timeout * HZ);
3727
James Smart858c9f62007-06-17 19:56:39 -05003728 spin_lock_irqsave(&phba->hbalock, flag);
dea31012005-04-17 16:05:31 -05003729 pmboxq->context1 = NULL;
James Smart7054a602007-04-25 09:52:34 -04003730 /*
3731 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3732 * else do not free the resources.
3733 */
3734 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
dea31012005-04-17 16:05:31 -05003735 retval = MBX_SUCCESS;
James Smart858c9f62007-06-17 19:56:39 -05003736 else {
James Smart7054a602007-04-25 09:52:34 -04003737 retval = MBX_TIMEOUT;
James Smart858c9f62007-06-17 19:56:39 -05003738 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3739 }
3740 spin_unlock_irqrestore(&phba->hbalock, flag);
dea31012005-04-17 16:05:31 -05003741 }
3742
dea31012005-04-17 16:05:31 -05003743 return retval;
3744}
3745
James Smartb4c02652006-07-06 15:50:43 -04003746int
3747lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3748{
James Smart2e0fef82007-06-17 19:56:36 -05003749 struct lpfc_vport *vport = phba->pport;
James Smartb4c02652006-07-06 15:50:43 -04003750 int i = 0;
James Smarted957682007-06-17 19:56:37 -05003751 uint32_t ha_copy;
James Smartb4c02652006-07-06 15:50:43 -04003752
James Smart2e0fef82007-06-17 19:56:36 -05003753 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
James Smartb4c02652006-07-06 15:50:43 -04003754 if (i++ > LPFC_MBOX_TMO * 1000)
3755 return 1;
3756
James Smarted957682007-06-17 19:56:37 -05003757 /*
3758 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3759 * did finish. This way we won't get the misleading
3760 * "Stray Mailbox Interrupt" message.
3761 */
3762 spin_lock_irq(&phba->hbalock);
3763 ha_copy = phba->work_ha;
3764 phba->work_ha &= ~HA_MBATT;
3765 spin_unlock_irq(&phba->hbalock);
3766
3767 if (ha_copy & HA_MBATT)
3768 if (lpfc_sli_handle_mb_event(phba) == 0)
3769 i = 0;
James Smartb4c02652006-07-06 15:50:43 -04003770
3771 msleep(1);
3772 }
3773
3774 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3775}
3776
dea31012005-04-17 16:05:31 -05003777irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003778lpfc_intr_handler(int irq, void *dev_id)
dea31012005-04-17 16:05:31 -05003779{
James Smart2e0fef82007-06-17 19:56:36 -05003780 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -05003781 uint32_t ha_copy;
3782 uint32_t work_ha_copy;
3783 unsigned long status;
3784 int i;
3785 uint32_t control;
3786
James Smart92d7f7b2007-06-17 19:56:38 -05003787 MAILBOX_t *mbox, *pmbox;
James Smart858c9f62007-06-17 19:56:39 -05003788 struct lpfc_vport *vport;
3789 struct lpfc_nodelist *ndlp;
3790 struct lpfc_dmabuf *mp;
James Smart92d7f7b2007-06-17 19:56:38 -05003791 LPFC_MBOXQ_t *pmb;
3792 int rc;
3793
dea31012005-04-17 16:05:31 -05003794 /*
3795 * Get the driver's phba structure from the dev_id and
3796 * assume the HBA is not interrupting.
3797 */
3798 phba = (struct lpfc_hba *) dev_id;
3799
3800 if (unlikely(!phba))
3801 return IRQ_NONE;
3802
Linas Vepstas8d63f372007-02-14 14:28:36 -06003803 /* If the pci channel is offline, ignore all the interrupts. */
3804 if (unlikely(pci_channel_offline(phba->pcidev)))
3805 return IRQ_NONE;
3806
dea31012005-04-17 16:05:31 -05003807 phba->sli.slistat.sli_intr++;
3808
3809 /*
3810 * Call the HBA to see if it is interrupting. If not, don't claim
3811 * the interrupt
3812 */
3813
3814 /* Ignore all interrupts during initialization. */
James Smart2e0fef82007-06-17 19:56:36 -05003815 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
dea31012005-04-17 16:05:31 -05003816 return IRQ_NONE;
3817
3818 /*
3819 * Read host attention register to determine interrupt source
3820 * Clear Attention Sources, except Error Attention (to
3821 * preserve status) and Link Attention
3822 */
James Smart2e0fef82007-06-17 19:56:36 -05003823 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003824 ha_copy = readl(phba->HAregaddr);
James Smartebdbe652007-04-25 09:53:15 -04003825 /* If somebody is waiting to handle an eratt don't process it
3826 * here. The brdkill function will do this.
3827 */
James Smart2e0fef82007-06-17 19:56:36 -05003828 if (phba->link_flag & LS_IGNORE_ERATT)
James Smartebdbe652007-04-25 09:53:15 -04003829 ha_copy &= ~HA_ERATT;
dea31012005-04-17 16:05:31 -05003830 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3831 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003832 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003833
3834 if (unlikely(!ha_copy))
3835 return IRQ_NONE;
3836
3837 work_ha_copy = ha_copy & phba->work_ha_mask;
3838
3839 if (unlikely(work_ha_copy)) {
3840 if (work_ha_copy & HA_LATT) {
3841 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3842 /*
3843 * Turn off Link Attention interrupts
3844 * until CLEAR_LA done
3845 */
James Smart2e0fef82007-06-17 19:56:36 -05003846 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003847 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3848 control = readl(phba->HCregaddr);
3849 control &= ~HC_LAINT_ENA;
3850 writel(control, phba->HCregaddr);
3851 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003852 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003853 }
3854 else
3855 work_ha_copy &= ~HA_LATT;
3856 }
3857
3858 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
James Smart858c9f62007-06-17 19:56:39 -05003859 /*
3860 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3861 * the only slow ring.
3862 */
3863 status = (work_ha_copy &
3864 (HA_RXMASK << (4*LPFC_ELS_RING)));
3865 status >>= (4*LPFC_ELS_RING);
3866 if (status & HA_RXMASK) {
3867 spin_lock(&phba->hbalock);
3868 control = readl(phba->HCregaddr);
James Smarta58cbd52007-08-02 11:09:43 -04003869
3870 lpfc_debugfs_slow_ring_trc(phba,
3871 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
3872 control, status,
3873 (uint32_t)phba->sli.slistat.sli_intr);
3874
James Smart858c9f62007-06-17 19:56:39 -05003875 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
James Smarta58cbd52007-08-02 11:09:43 -04003876 lpfc_debugfs_slow_ring_trc(phba,
3877 "ISR Disable ring:"
3878 "pwork:x%x hawork:x%x wait:x%x",
3879 phba->work_ha, work_ha_copy,
3880 (uint32_t)((unsigned long)
3881 phba->work_wait));
3882
James Smart858c9f62007-06-17 19:56:39 -05003883 control &=
3884 ~(HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -05003885 writel(control, phba->HCregaddr);
3886 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -05003887 }
James Smarta58cbd52007-08-02 11:09:43 -04003888 else {
3889 lpfc_debugfs_slow_ring_trc(phba,
3890 "ISR slow ring: pwork:"
3891 "x%x hawork:x%x wait:x%x",
3892 phba->work_ha, work_ha_copy,
3893 (uint32_t)((unsigned long)
3894 phba->work_wait));
3895 }
James Smart858c9f62007-06-17 19:56:39 -05003896 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003897 }
3898 }
3899
3900 if (work_ha_copy & HA_ERATT) {
James Smart2e0fef82007-06-17 19:56:36 -05003901 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05003902 /*
3903 * There was a link/board error. Read the
3904 * status register to retrieve the error event
3905 * and process it.
3906 */
3907 phba->sli.slistat.err_attn_event++;
3908 /* Save status info */
3909 phba->work_hs = readl(phba->HSregaddr);
3910 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3911 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3912
3913 /* Clear Chip error bit */
3914 writel(HA_ERATT, phba->HAregaddr);
3915 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05003916 phba->pport->stopped = 1;
dea31012005-04-17 16:05:31 -05003917 }
3918
James Smart92d7f7b2007-06-17 19:56:38 -05003919 if ((work_ha_copy & HA_MBATT) &&
3920 (phba->sli.mbox_active)) {
3921 pmb = phba->sli.mbox_active;
3922 pmbox = &pmb->mb;
3923 mbox = &phba->slim2p->mbx;
James Smart858c9f62007-06-17 19:56:39 -05003924 vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05003925
3926 /* First check out the status word */
3927 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
3928 if (pmbox->mbxOwner != OWN_HOST) {
3929 /*
3930 * Stray Mailbox Interrupt, mbxCommand <cmd>
3931 * mbxStatus <status>
3932 */
3933 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX |
3934 LOG_SLI,
3935 "%d (%d):0304 Stray Mailbox "
3936 "Interrupt mbxCommand x%x "
3937 "mbxStatus x%x\n",
3938 phba->brd_no,
James Smart858c9f62007-06-17 19:56:39 -05003939 (vport
3940 ? vport->vpi : 0),
James Smart92d7f7b2007-06-17 19:56:38 -05003941 pmbox->mbxCommand,
3942 pmbox->mbxStatus);
3943 }
James Smart858c9f62007-06-17 19:56:39 -05003944 phba->last_completion_time = jiffies;
James Smart92d7f7b2007-06-17 19:56:38 -05003945 del_timer_sync(&phba->sli.mbox_tmo);
3946
James Smart92d7f7b2007-06-17 19:56:38 -05003947 phba->sli.mbox_active = NULL;
3948 if (pmb->mbox_cmpl) {
3949 lpfc_sli_pcimem_bcopy(mbox, pmbox,
3950 MAILBOX_CMD_SIZE);
3951 }
James Smart858c9f62007-06-17 19:56:39 -05003952 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
3953 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
3954
3955 lpfc_debugfs_disc_trc(vport,
3956 LPFC_DISC_TRC_MBOX_VPORT,
3957 "MBOX dflt rpi: : status:x%x rpi:x%x",
3958 (uint32_t)pmbox->mbxStatus,
3959 pmbox->un.varWords[0], 0);
3960
3961 if ( !pmbox->mbxStatus) {
3962 mp = (struct lpfc_dmabuf *)
3963 (pmb->context1);
3964 ndlp = (struct lpfc_nodelist *)
3965 pmb->context2;
3966
3967 /* Reg_LOGIN of dflt RPI was successful.
3968 * new lets get rid of the RPI using the
3969 * same mbox buffer.
3970 */
3971 lpfc_unreg_login(phba, vport->vpi,
3972 pmbox->un.varWords[0], pmb);
3973 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3974 pmb->context1 = mp;
3975 pmb->context2 = ndlp;
3976 pmb->vport = vport;
3977 spin_lock(&phba->hbalock);
3978 phba->sli.sli_flag &=
3979 ~LPFC_SLI_MBOX_ACTIVE;
3980 spin_unlock(&phba->hbalock);
3981 goto send_current_mbox;
3982 }
3983 }
3984 spin_lock(&phba->pport->work_port_lock);
3985 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3986 spin_unlock(&phba->pport->work_port_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003987 lpfc_mbox_cmpl_put(phba, pmb);
3988 }
3989 if ((work_ha_copy & HA_MBATT) &&
3990 (phba->sli.mbox_active == NULL)) {
3991send_next_mbox:
3992 spin_lock(&phba->hbalock);
3993 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3994 pmb = lpfc_mbox_get(phba);
3995 spin_unlock(&phba->hbalock);
James Smart858c9f62007-06-17 19:56:39 -05003996send_current_mbox:
James Smart92d7f7b2007-06-17 19:56:38 -05003997 /* Process next mailbox command if there is one */
3998 if (pmb != NULL) {
3999 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4000 if (rc == MBX_NOT_FINISHED) {
4001 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
4002 lpfc_mbox_cmpl_put(phba, pmb);
4003 goto send_next_mbox;
4004 }
4005 } else {
4006 /* Turn on IOCB processing */
4007 for (i = 0; i < phba->sli.num_rings; i++)
4008 lpfc_sli_turn_on_ring(phba, i);
4009 }
4010
4011 }
4012
James Smart2e0fef82007-06-17 19:56:36 -05004013 spin_lock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004014 phba->work_ha |= work_ha_copy;
4015 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05004016 lpfc_worker_wake_up(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004017 spin_unlock(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004018 }
4019
4020 ha_copy &= ~(phba->work_ha_mask);
4021
4022 /*
4023 * Process all events on FCP ring. Take the optimized path for
4024 * FCP IO. Any other IO is slow path and is handled by
4025 * the worker thread.
4026 */
4027 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4028 status >>= (4*LPFC_FCP_RING);
James Smart858c9f62007-06-17 19:56:39 -05004029 if (status & HA_RXMASK)
dea31012005-04-17 16:05:31 -05004030 lpfc_sli_handle_fast_ring_event(phba,
4031 &phba->sli.ring[LPFC_FCP_RING],
4032 status);
James Smarta4bc3372006-12-02 13:34:16 -05004033
4034 if (phba->cfg_multi_ring_support == 2) {
4035 /*
4036 * Process all events on extra ring. Take the optimized path
4037 * for extra ring IO. Any other IO is slow path and is handled
4038 * by the worker thread.
4039 */
4040 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4041 status >>= (4*LPFC_EXTRA_RING);
James Smart858c9f62007-06-17 19:56:39 -05004042 if (status & HA_RXMASK) {
James Smarta4bc3372006-12-02 13:34:16 -05004043 lpfc_sli_handle_fast_ring_event(phba,
4044 &phba->sli.ring[LPFC_EXTRA_RING],
4045 status);
4046 }
4047 }
dea31012005-04-17 16:05:31 -05004048 return IRQ_HANDLED;
4049
4050} /* lpfc_intr_handler */