blob: 54a8f4d3db1371fe0b0894574817f3ccb5ee0dc1 [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. *
Jamie Wellnitz41415862006-02-28 19:25:27 -05004 * Copyright (C) 2004-2006 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"
41
42/*
43 * Define macro to log: Mailbox command x%x cannot issue Data
44 * This allows multiple uses of lpfc_msgBlk0311
45 * w/o perturbing log msg utility.
46 */
47#define LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) \
48 lpfc_printf_log(phba, \
49 KERN_INFO, \
50 LOG_MBOX | LOG_SLI, \
51 "%d:0311 Mailbox command x%x cannot issue " \
52 "Data: x%x x%x x%x\n", \
53 phba->brd_no, \
54 mb->mbxCommand, \
55 phba->hba_state, \
56 psli->sli_flag, \
57 flag);
58
59
60/* There are only four IOCB completion types. */
61typedef enum _lpfc_iocb_type {
62 LPFC_UNKNOWN_IOCB,
63 LPFC_UNSOL_IOCB,
64 LPFC_SOL_IOCB,
65 LPFC_ABORT_IOCB
66} lpfc_iocb_type;
67
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040068struct lpfc_iocbq *
69lpfc_sli_get_iocbq(struct lpfc_hba * phba)
70{
71 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
72 struct lpfc_iocbq * iocbq = NULL;
73
74 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
75 return iocbq;
76}
77
James Bottomley604a3e32005-10-29 10:28:33 -050078void
79lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
80{
81 size_t start_clean = (size_t)(&((struct lpfc_iocbq *)NULL)->iocb);
82
83 /*
84 * Clean all volatile data fields, preserve iotag and node struct.
85 */
86 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
87 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
88}
89
dea31012005-04-17 16:05:31 -050090/*
91 * Translate the iocb command to an iocb command type used to decide the final
92 * disposition of each completed IOCB.
93 */
94static lpfc_iocb_type
95lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
96{
97 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
98
99 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
100 return 0;
101
102 switch (iocb_cmnd) {
103 case CMD_XMIT_SEQUENCE_CR:
104 case CMD_XMIT_SEQUENCE_CX:
105 case CMD_XMIT_BCAST_CN:
106 case CMD_XMIT_BCAST_CX:
107 case CMD_ELS_REQUEST_CR:
108 case CMD_ELS_REQUEST_CX:
109 case CMD_CREATE_XRI_CR:
110 case CMD_CREATE_XRI_CX:
111 case CMD_GET_RPI_CN:
112 case CMD_XMIT_ELS_RSP_CX:
113 case CMD_GET_RPI_CR:
114 case CMD_FCP_IWRITE_CR:
115 case CMD_FCP_IWRITE_CX:
116 case CMD_FCP_IREAD_CR:
117 case CMD_FCP_IREAD_CX:
118 case CMD_FCP_ICMND_CR:
119 case CMD_FCP_ICMND_CX:
James Smartf5603512006-12-02 13:35:43 -0500120 case CMD_FCP_TSEND_CX:
121 case CMD_FCP_TRSP_CX:
122 case CMD_FCP_TRECEIVE_CX:
123 case CMD_FCP_AUTO_TRSP_CX:
dea31012005-04-17 16:05:31 -0500124 case CMD_ADAPTER_MSG:
125 case CMD_ADAPTER_DUMP:
126 case CMD_XMIT_SEQUENCE64_CR:
127 case CMD_XMIT_SEQUENCE64_CX:
128 case CMD_XMIT_BCAST64_CN:
129 case CMD_XMIT_BCAST64_CX:
130 case CMD_ELS_REQUEST64_CR:
131 case CMD_ELS_REQUEST64_CX:
132 case CMD_FCP_IWRITE64_CR:
133 case CMD_FCP_IWRITE64_CX:
134 case CMD_FCP_IREAD64_CR:
135 case CMD_FCP_IREAD64_CX:
136 case CMD_FCP_ICMND64_CR:
137 case CMD_FCP_ICMND64_CX:
James Smartf5603512006-12-02 13:35:43 -0500138 case CMD_FCP_TSEND64_CX:
139 case CMD_FCP_TRSP64_CX:
140 case CMD_FCP_TRECEIVE64_CX:
dea31012005-04-17 16:05:31 -0500141 case CMD_GEN_REQUEST64_CR:
142 case CMD_GEN_REQUEST64_CX:
143 case CMD_XMIT_ELS_RSP64_CX:
144 type = LPFC_SOL_IOCB;
145 break;
146 case CMD_ABORT_XRI_CN:
147 case CMD_ABORT_XRI_CX:
148 case CMD_CLOSE_XRI_CN:
149 case CMD_CLOSE_XRI_CX:
150 case CMD_XRI_ABORTED_CX:
151 case CMD_ABORT_MXRI64_CN:
152 type = LPFC_ABORT_IOCB;
153 break;
154 case CMD_RCV_SEQUENCE_CX:
155 case CMD_RCV_ELS_REQ_CX:
156 case CMD_RCV_SEQUENCE64_CX:
157 case CMD_RCV_ELS_REQ64_CX:
158 type = LPFC_UNSOL_IOCB;
159 break;
160 default:
161 type = LPFC_UNKNOWN_IOCB;
162 break;
163 }
164
165 return type;
166}
167
168static int
169lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb)
170{
171 struct lpfc_sli *psli = &phba->sli;
172 MAILBOX_t *pmbox = &pmb->mb;
173 int i, rc;
174
175 for (i = 0; i < psli->num_rings; i++) {
176 phba->hba_state = LPFC_INIT_MBX_CMDS;
177 lpfc_config_ring(phba, i, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) {
180 lpfc_printf_log(phba,
181 KERN_ERR,
182 LOG_INIT,
183 "%d:0446 Adapter failed to init, "
184 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
185 "ring %d\n",
186 phba->brd_no,
187 pmbox->mbxCommand,
188 pmbox->mbxStatus,
189 i);
190 phba->hba_state = LPFC_HBA_ERROR;
191 return -ENXIO;
192 }
193 }
194 return 0;
195}
196
197static int
198lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
199 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
200{
dea31012005-04-17 16:05:31 -0500201 list_add_tail(&piocb->list, &pring->txcmplq);
202 pring->txcmplq_cnt++;
203 if (unlikely(pring->ringno == LPFC_ELS_RING))
204 mod_timer(&phba->els_tmofunc,
205 jiffies + HZ * (phba->fc_ratov << 1));
206
dea31012005-04-17 16:05:31 -0500207 return (0);
208}
209
210static struct lpfc_iocbq *
211lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
212{
213 struct list_head *dlp;
214 struct lpfc_iocbq *cmd_iocb;
215
216 dlp = &pring->txq;
217 cmd_iocb = NULL;
218 list_remove_head((&pring->txq), cmd_iocb,
219 struct lpfc_iocbq,
220 list);
221 if (cmd_iocb) {
222 /* If the first ptr is not equal to the list header,
223 * deque the IOCBQ_t and return it.
224 */
225 pring->txq_cnt--;
226 }
227 return (cmd_iocb);
228}
229
230static IOCB_t *
231lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
232{
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -0400233 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -0500234 uint32_t max_cmd_idx = pring->numCiocb;
235 IOCB_t *iocb = NULL;
236
237 if ((pring->next_cmdidx == pring->cmdidx) &&
238 (++pring->next_cmdidx >= max_cmd_idx))
239 pring->next_cmdidx = 0;
240
241 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
242
243 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
244
245 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
246 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
247 "%d:0315 Ring %d issue: portCmdGet %d "
248 "is bigger then cmd ring %d\n",
249 phba->brd_no, pring->ringno,
250 pring->local_getidx, max_cmd_idx);
251
252 phba->hba_state = LPFC_HBA_ERROR;
253 /*
254 * All error attention handlers are posted to
255 * worker thread
256 */
257 phba->work_ha |= HA_ERATT;
258 phba->work_hs = HS_FFER3;
259 if (phba->work_wait)
260 wake_up(phba->work_wait);
261
262 return NULL;
263 }
264
265 if (pring->local_getidx == pring->next_cmdidx)
266 return NULL;
267 }
268
269 iocb = IOCB_ENTRY(pring->cmdringaddr, pring->cmdidx);
270
271 return iocb;
272}
273
James Bottomley604a3e32005-10-29 10:28:33 -0500274uint16_t
275lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
dea31012005-04-17 16:05:31 -0500276{
James Bottomley604a3e32005-10-29 10:28:33 -0500277 struct lpfc_iocbq ** new_arr;
278 struct lpfc_iocbq ** old_arr;
279 size_t new_len;
280 struct lpfc_sli *psli = &phba->sli;
281 uint16_t iotag;
dea31012005-04-17 16:05:31 -0500282
James Bottomley604a3e32005-10-29 10:28:33 -0500283 spin_lock_irq(phba->host->host_lock);
284 iotag = psli->last_iotag;
285 if(++iotag < psli->iocbq_lookup_len) {
286 psli->last_iotag = iotag;
287 psli->iocbq_lookup[iotag] = iocbq;
288 spin_unlock_irq(phba->host->host_lock);
289 iocbq->iotag = iotag;
290 return iotag;
291 }
292 else if (psli->iocbq_lookup_len < (0xffff
293 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
294 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
295 spin_unlock_irq(phba->host->host_lock);
296 new_arr = kmalloc(new_len * sizeof (struct lpfc_iocbq *),
297 GFP_KERNEL);
298 if (new_arr) {
299 memset((char *)new_arr, 0,
300 new_len * sizeof (struct lpfc_iocbq *));
301 spin_lock_irq(phba->host->host_lock);
302 old_arr = psli->iocbq_lookup;
303 if (new_len <= psli->iocbq_lookup_len) {
304 /* highly unprobable case */
305 kfree(new_arr);
306 iotag = psli->last_iotag;
307 if(++iotag < psli->iocbq_lookup_len) {
308 psli->last_iotag = iotag;
309 psli->iocbq_lookup[iotag] = iocbq;
310 spin_unlock_irq(phba->host->host_lock);
311 iocbq->iotag = iotag;
312 return iotag;
313 }
314 spin_unlock_irq(phba->host->host_lock);
315 return 0;
316 }
317 if (psli->iocbq_lookup)
318 memcpy(new_arr, old_arr,
319 ((psli->last_iotag + 1) *
320 sizeof (struct lpfc_iocbq *)));
321 psli->iocbq_lookup = new_arr;
322 psli->iocbq_lookup_len = new_len;
323 psli->last_iotag = iotag;
324 psli->iocbq_lookup[iotag] = iocbq;
325 spin_unlock_irq(phba->host->host_lock);
326 iocbq->iotag = iotag;
327 kfree(old_arr);
328 return iotag;
329 }
James Smart8f6d98d2006-08-01 07:34:00 -0400330 } else
331 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500332
James Bottomley604a3e32005-10-29 10:28:33 -0500333 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
334 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
335 phba->brd_no, psli->last_iotag);
dea31012005-04-17 16:05:31 -0500336
James Bottomley604a3e32005-10-29 10:28:33 -0500337 return 0;
dea31012005-04-17 16:05:31 -0500338}
339
340static void
341lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
342 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
343{
344 /*
James Bottomley604a3e32005-10-29 10:28:33 -0500345 * Set up an iotag
dea31012005-04-17 16:05:31 -0500346 */
James Bottomley604a3e32005-10-29 10:28:33 -0500347 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
dea31012005-04-17 16:05:31 -0500348
349 /*
350 * Issue iocb command to adapter
351 */
352 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, sizeof (IOCB_t));
353 wmb();
354 pring->stats.iocb_cmd++;
355
356 /*
357 * If there is no completion routine to call, we can release the
358 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
359 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
360 */
361 if (nextiocb->iocb_cmpl)
362 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
James Bottomley604a3e32005-10-29 10:28:33 -0500363 else
364 lpfc_sli_release_iocbq(phba, nextiocb);
dea31012005-04-17 16:05:31 -0500365
366 /*
367 * Let the HBA know what IOCB slot will be the next one the
368 * driver will put a command into.
369 */
370 pring->cmdidx = pring->next_cmdidx;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -0400371 writel(pring->cmdidx, phba->MBslimaddr
dea31012005-04-17 16:05:31 -0500372 + (SLIMOFF + (pring->ringno * 2)) * 4);
373}
374
375static void
376lpfc_sli_update_full_ring(struct lpfc_hba * phba,
377 struct lpfc_sli_ring *pring)
378{
379 int ringno = pring->ringno;
380
381 pring->flag |= LPFC_CALL_RING_AVAILABLE;
382
383 wmb();
384
385 /*
386 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
387 * The HBA will tell us when an IOCB entry is available.
388 */
389 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
390 readl(phba->CAregaddr); /* flush */
391
392 pring->stats.iocb_cmd_full++;
393}
394
395static void
396lpfc_sli_update_ring(struct lpfc_hba * phba,
397 struct lpfc_sli_ring *pring)
398{
399 int ringno = pring->ringno;
400
401 /*
402 * Tell the HBA that there is work to do in this ring.
403 */
404 wmb();
405 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
406 readl(phba->CAregaddr); /* flush */
407}
408
409static void
410lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
411{
412 IOCB_t *iocb;
413 struct lpfc_iocbq *nextiocb;
414
415 /*
416 * Check to see if:
417 * (a) there is anything on the txq to send
418 * (b) link is up
419 * (c) link attention events can be processed (fcp ring only)
420 * (d) IOCB processing is not blocked by the outstanding mbox command.
421 */
422 if (pring->txq_cnt &&
423 (phba->hba_state > LPFC_LINK_DOWN) &&
424 (pring->ringno != phba->sli.fcp_ring ||
425 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
426 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
427
428 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
429 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
430 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
431
432 if (iocb)
433 lpfc_sli_update_ring(phba, pring);
434 else
435 lpfc_sli_update_full_ring(phba, pring);
436 }
437
438 return;
439}
440
441/* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
442static void
443lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
444{
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -0400445 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno];
dea31012005-04-17 16:05:31 -0500446
447 /* If the ring is active, flag it */
448 if (phba->sli.ring[ringno].cmdringaddr) {
449 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
450 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
451 /*
452 * Force update of the local copy of cmdGetInx
453 */
454 phba->sli.ring[ringno].local_getidx
455 = le32_to_cpu(pgp->cmdGetInx);
456 spin_lock_irq(phba->host->host_lock);
457 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
458 spin_unlock_irq(phba->host->host_lock);
459 }
460 }
461}
462
463static int
464lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
465{
466 uint8_t ret;
467
468 switch (mbxCommand) {
469 case MBX_LOAD_SM:
470 case MBX_READ_NV:
471 case MBX_WRITE_NV:
472 case MBX_RUN_BIU_DIAG:
473 case MBX_INIT_LINK:
474 case MBX_DOWN_LINK:
475 case MBX_CONFIG_LINK:
476 case MBX_CONFIG_RING:
477 case MBX_RESET_RING:
478 case MBX_READ_CONFIG:
479 case MBX_READ_RCONFIG:
480 case MBX_READ_SPARM:
481 case MBX_READ_STATUS:
482 case MBX_READ_RPI:
483 case MBX_READ_XRI:
484 case MBX_READ_REV:
485 case MBX_READ_LNK_STAT:
486 case MBX_REG_LOGIN:
487 case MBX_UNREG_LOGIN:
488 case MBX_READ_LA:
489 case MBX_CLEAR_LA:
490 case MBX_DUMP_MEMORY:
491 case MBX_DUMP_CONTEXT:
492 case MBX_RUN_DIAGS:
493 case MBX_RESTART:
494 case MBX_UPDATE_CFG:
495 case MBX_DOWN_LOAD:
496 case MBX_DEL_LD_ENTRY:
497 case MBX_RUN_PROGRAM:
498 case MBX_SET_MASK:
499 case MBX_SET_SLIM:
500 case MBX_UNREG_D_ID:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500501 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -0500502 case MBX_CONFIG_FARP:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500503 case MBX_BEACON:
dea31012005-04-17 16:05:31 -0500504 case MBX_LOAD_AREA:
505 case MBX_RUN_BIU_DIAG64:
506 case MBX_CONFIG_PORT:
507 case MBX_READ_SPARM64:
508 case MBX_READ_RPI64:
509 case MBX_REG_LOGIN64:
510 case MBX_READ_LA64:
511 case MBX_FLASH_WR_ULA:
512 case MBX_SET_DEBUG:
513 case MBX_LOAD_EXP_ROM:
514 ret = mbxCommand;
515 break;
516 default:
517 ret = MBX_SHUTDOWN;
518 break;
519 }
520 return (ret);
521}
522static void
523lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
524{
525 wait_queue_head_t *pdone_q;
526
527 /*
528 * If pdone_q is empty, the driver thread gave up waiting and
529 * continued running.
530 */
531 pdone_q = (wait_queue_head_t *) pmboxq->context1;
532 if (pdone_q)
533 wake_up_interruptible(pdone_q);
534 return;
535}
536
537void
538lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
539{
540 struct lpfc_dmabuf *mp;
541 mp = (struct lpfc_dmabuf *) (pmb->context1);
542 if (mp) {
543 lpfc_mbuf_free(phba, mp->virt, mp->phys);
544 kfree(mp);
545 }
546 mempool_free( pmb, phba->mbox_mem_pool);
547 return;
548}
549
550int
551lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
552{
553 MAILBOX_t *mbox;
554 MAILBOX_t *pmbox;
555 LPFC_MBOXQ_t *pmb;
556 struct lpfc_sli *psli;
557 int i, rc;
558 uint32_t process_next;
559
560 psli = &phba->sli;
561 /* We should only get here if we are in SLI2 mode */
562 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
563 return (1);
564 }
565
566 phba->sli.slistat.mbox_event++;
567
568 /* Get a Mailbox buffer to setup mailbox commands for callback */
569 if ((pmb = phba->sli.mbox_active)) {
570 pmbox = &pmb->mb;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -0400571 mbox = &phba->slim2p->mbx;
dea31012005-04-17 16:05:31 -0500572
573 /* First check out the status word */
574 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
575
576 /* Sanity check to ensure the host owns the mailbox */
577 if (pmbox->mbxOwner != OWN_HOST) {
578 /* Lets try for a while */
579 for (i = 0; i < 10240; i++) {
580 /* First copy command data */
581 lpfc_sli_pcimem_bcopy(mbox, pmbox,
582 sizeof (uint32_t));
583 if (pmbox->mbxOwner == OWN_HOST)
584 goto mbout;
585 }
586 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
587 <status> */
588 lpfc_printf_log(phba,
James Smartb4c02652006-07-06 15:50:43 -0400589 KERN_WARNING,
dea31012005-04-17 16:05:31 -0500590 LOG_MBOX | LOG_SLI,
591 "%d:0304 Stray Mailbox Interrupt "
592 "mbxCommand x%x mbxStatus x%x\n",
593 phba->brd_no,
594 pmbox->mbxCommand,
595 pmbox->mbxStatus);
596
597 spin_lock_irq(phba->host->host_lock);
598 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
599 spin_unlock_irq(phba->host->host_lock);
600 return (1);
601 }
602
603 mbout:
604 del_timer_sync(&phba->sli.mbox_tmo);
605 phba->work_hba_events &= ~WORKER_MBOX_TMO;
606
607 /*
608 * It is a fatal error if unknown mbox command completion.
609 */
610 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
611 MBX_SHUTDOWN) {
612
613 /* Unknow mailbox command compl */
614 lpfc_printf_log(phba,
615 KERN_ERR,
616 LOG_MBOX | LOG_SLI,
617 "%d:0323 Unknown Mailbox command %x Cmpl\n",
618 phba->brd_no,
619 pmbox->mbxCommand);
620 phba->hba_state = LPFC_HBA_ERROR;
621 phba->work_hs = HS_FFER3;
622 lpfc_handle_eratt(phba);
623 return (0);
624 }
625
626 phba->sli.mbox_active = NULL;
627 if (pmbox->mbxStatus) {
628 phba->sli.slistat.mbox_stat_err++;
629 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
630 /* Mbox cmd cmpl error - RETRYing */
631 lpfc_printf_log(phba,
632 KERN_INFO,
633 LOG_MBOX | LOG_SLI,
634 "%d:0305 Mbox cmd cmpl error - "
635 "RETRYing Data: x%x x%x x%x x%x\n",
636 phba->brd_no,
637 pmbox->mbxCommand,
638 pmbox->mbxStatus,
639 pmbox->un.varWords[0],
640 phba->hba_state);
641 pmbox->mbxStatus = 0;
642 pmbox->mbxOwner = OWN_HOST;
643 spin_lock_irq(phba->host->host_lock);
644 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
645 spin_unlock_irq(phba->host->host_lock);
646 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
647 if (rc == MBX_SUCCESS)
648 return (0);
649 }
650 }
651
652 /* Mailbox cmd <cmd> Cmpl <cmpl> */
653 lpfc_printf_log(phba,
654 KERN_INFO,
655 LOG_MBOX | LOG_SLI,
656 "%d:0307 Mailbox cmd x%x Cmpl x%p "
657 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
658 phba->brd_no,
659 pmbox->mbxCommand,
660 pmb->mbox_cmpl,
661 *((uint32_t *) pmbox),
662 pmbox->un.varWords[0],
663 pmbox->un.varWords[1],
664 pmbox->un.varWords[2],
665 pmbox->un.varWords[3],
666 pmbox->un.varWords[4],
667 pmbox->un.varWords[5],
668 pmbox->un.varWords[6],
669 pmbox->un.varWords[7]);
670
671 if (pmb->mbox_cmpl) {
672 lpfc_sli_pcimem_bcopy(mbox, pmbox, MAILBOX_CMD_SIZE);
673 pmb->mbox_cmpl(phba,pmb);
674 }
675 }
676
677
678 do {
679 process_next = 0; /* by default don't loop */
680 spin_lock_irq(phba->host->host_lock);
681 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
682
683 /* Process next mailbox command if there is one */
684 if ((pmb = lpfc_mbox_get(phba))) {
685 spin_unlock_irq(phba->host->host_lock);
686 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
687 if (rc == MBX_NOT_FINISHED) {
688 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
689 pmb->mbox_cmpl(phba,pmb);
690 process_next = 1;
691 continue; /* loop back */
692 }
693 } else {
694 spin_unlock_irq(phba->host->host_lock);
695 /* Turn on IOCB processing */
James Smart1dcb58e2007-04-25 09:51:30 -0400696 for (i = 0; i < phba->sli.num_rings; i++)
dea31012005-04-17 16:05:31 -0500697 lpfc_sli_turn_on_ring(phba, i);
dea31012005-04-17 16:05:31 -0500698 }
699
700 } while (process_next);
701
702 return (0);
703}
704static int
705lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
706 struct lpfc_iocbq *saveq)
707{
708 IOCB_t * irsp;
709 WORD5 * w5p;
710 uint32_t Rctl, Type;
711 uint32_t match, i;
712
713 match = 0;
714 irsp = &(saveq->iocb);
715 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
716 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) {
717 Rctl = FC_ELS_REQ;
718 Type = FC_ELS_DATA;
719 } else {
720 w5p =
721 (WORD5 *) & (saveq->iocb.un.
722 ulpWord[5]);
723 Rctl = w5p->hcsw.Rctl;
724 Type = w5p->hcsw.Type;
725
726 /* Firmware Workaround */
727 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
728 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) {
729 Rctl = FC_ELS_REQ;
730 Type = FC_ELS_DATA;
731 w5p->hcsw.Rctl = Rctl;
732 w5p->hcsw.Type = Type;
733 }
734 }
735 /* unSolicited Responses */
736 if (pring->prt[0].profile) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500737 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
738 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
739 saveq);
dea31012005-04-17 16:05:31 -0500740 match = 1;
741 } else {
742 /* We must search, based on rctl / type
743 for the right routine */
744 for (i = 0; i < pring->num_mask;
745 i++) {
746 if ((pring->prt[i].rctl ==
747 Rctl)
748 && (pring->prt[i].
749 type == Type)) {
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500750 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
751 (pring->prt[i].lpfc_sli_rcv_unsol_event)
752 (phba, pring, saveq);
dea31012005-04-17 16:05:31 -0500753 match = 1;
754 break;
755 }
756 }
757 }
758 if (match == 0) {
759 /* Unexpected Rctl / Type received */
760 /* Ring <ringno> handler: unexpected
761 Rctl <Rctl> Type <Type> received */
762 lpfc_printf_log(phba,
763 KERN_WARNING,
764 LOG_SLI,
765 "%d:0313 Ring %d handler: unexpected Rctl x%x "
766 "Type x%x received \n",
767 phba->brd_no,
768 pring->ringno,
769 Rctl,
770 Type);
771 }
772 return(1);
773}
774
775static struct lpfc_iocbq *
James Bottomley604a3e32005-10-29 10:28:33 -0500776lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
777 struct lpfc_sli_ring * pring,
778 struct lpfc_iocbq * prspiocb)
dea31012005-04-17 16:05:31 -0500779{
dea31012005-04-17 16:05:31 -0500780 struct lpfc_iocbq *cmd_iocb = NULL;
781 uint16_t iotag;
782
James Bottomley604a3e32005-10-29 10:28:33 -0500783 iotag = prspiocb->iocb.ulpIoTag;
dea31012005-04-17 16:05:31 -0500784
James Bottomley604a3e32005-10-29 10:28:33 -0500785 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
786 cmd_iocb = phba->sli.iocbq_lookup[iotag];
787 list_del(&cmd_iocb->list);
788 pring->txcmplq_cnt--;
789 return cmd_iocb;
dea31012005-04-17 16:05:31 -0500790 }
791
dea31012005-04-17 16:05:31 -0500792 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Bottomley604a3e32005-10-29 10:28:33 -0500793 "%d:0317 iotag x%x is out off "
794 "range: max iotag x%x wd0 x%x\n",
795 phba->brd_no, iotag,
796 phba->sli.last_iotag,
797 *(((uint32_t *) &prspiocb->iocb) + 7));
dea31012005-04-17 16:05:31 -0500798 return NULL;
799}
800
801static int
802lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
803 struct lpfc_iocbq *saveq)
804{
805 struct lpfc_iocbq * cmdiocbp;
806 int rc = 1;
807 unsigned long iflag;
808
809 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
810 spin_lock_irqsave(phba->host->host_lock, iflag);
James Bottomley604a3e32005-10-29 10:28:33 -0500811 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
dea31012005-04-17 16:05:31 -0500812 if (cmdiocbp) {
813 if (cmdiocbp->iocb_cmpl) {
814 /*
815 * Post all ELS completions to the worker thread.
816 * All other are passed to the completion callback.
817 */
818 if (pring->ringno == LPFC_ELS_RING) {
819 spin_unlock_irqrestore(phba->host->host_lock,
820 iflag);
821 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
822 spin_lock_irqsave(phba->host->host_lock, iflag);
823 }
824 else {
dea31012005-04-17 16:05:31 -0500825 spin_unlock_irqrestore(phba->host->host_lock,
826 iflag);
827 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
828 spin_lock_irqsave(phba->host->host_lock, iflag);
829 }
James Bottomley604a3e32005-10-29 10:28:33 -0500830 } else
831 lpfc_sli_release_iocbq(phba, cmdiocbp);
dea31012005-04-17 16:05:31 -0500832 } else {
833 /*
834 * Unknown initiating command based on the response iotag.
835 * This could be the case on the ELS ring because of
836 * lpfc_els_abort().
837 */
838 if (pring->ringno != LPFC_ELS_RING) {
839 /*
840 * Ring <ringno> handler: unexpected completion IoTag
841 * <IoTag>
842 */
843 lpfc_printf_log(phba,
844 KERN_WARNING,
845 LOG_SLI,
846 "%d:0322 Ring %d handler: unexpected "
847 "completion IoTag x%x Data: x%x x%x x%x x%x\n",
848 phba->brd_no,
849 pring->ringno,
850 saveq->iocb.ulpIoTag,
851 saveq->iocb.ulpStatus,
852 saveq->iocb.un.ulpWord[4],
853 saveq->iocb.ulpCommand,
854 saveq->iocb.ulpContext);
855 }
856 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -0400857
dea31012005-04-17 16:05:31 -0500858 spin_unlock_irqrestore(phba->host->host_lock, iflag);
859 return rc;
860}
861
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500862static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
863 struct lpfc_sli_ring * pring)
864{
865 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
866 /*
867 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
868 * rsp ring <portRspMax>
869 */
870 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
871 "%d:0312 Ring %d handler: portRspPut %d "
872 "is bigger then rsp ring %d\n",
873 phba->brd_no, pring->ringno,
874 le32_to_cpu(pgp->rspPutInx),
875 pring->numRiocb);
876
877 phba->hba_state = LPFC_HBA_ERROR;
878
879 /*
880 * All error attention handlers are posted to
881 * worker thread
882 */
883 phba->work_ha |= HA_ERATT;
884 phba->work_hs = HS_FFER3;
885 if (phba->work_wait)
886 wake_up(phba->work_wait);
887
888 return;
889}
890
891void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
892{
893 struct lpfc_sli * psli = &phba->sli;
894 struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING];
895 IOCB_t *irsp = NULL;
896 IOCB_t *entry = NULL;
897 struct lpfc_iocbq *cmdiocbq = NULL;
898 struct lpfc_iocbq rspiocbq;
899 struct lpfc_pgp *pgp;
900 uint32_t status;
901 uint32_t portRspPut, portRspMax;
902 int type;
903 uint32_t rsp_cmpl = 0;
904 void __iomem *to_slim;
905 uint32_t ha_copy;
906
907 pring->stats.iocb_event++;
908
909 /* The driver assumes SLI-2 mode */
910 pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
911
912 /*
913 * The next available response entry should never exceed the maximum
914 * entries. If it does, treat it as an adapter hardware error.
915 */
916 portRspMax = pring->numRiocb;
917 portRspPut = le32_to_cpu(pgp->rspPutInx);
918 if (unlikely(portRspPut >= portRspMax)) {
919 lpfc_sli_rsp_pointers_error(phba, pring);
920 return;
921 }
922
923 rmb();
924 while (pring->rspidx != portRspPut) {
925
926 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
927
928 if (++pring->rspidx >= portRspMax)
929 pring->rspidx = 0;
930
931 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
932 (uint32_t *) &rspiocbq.iocb,
933 sizeof (IOCB_t));
934 irsp = &rspiocbq.iocb;
935 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
936 pring->stats.iocb_rsp++;
937 rsp_cmpl++;
938
939 if (unlikely(irsp->ulpStatus)) {
940 /* Rsp ring <ringno> error: IOCB */
941 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
942 "%d:0326 Rsp Ring %d error: IOCB Data: "
943 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
944 phba->brd_no, pring->ringno,
945 irsp->un.ulpWord[0],
946 irsp->un.ulpWord[1],
947 irsp->un.ulpWord[2],
948 irsp->un.ulpWord[3],
949 irsp->un.ulpWord[4],
950 irsp->un.ulpWord[5],
951 *(((uint32_t *) irsp) + 6),
952 *(((uint32_t *) irsp) + 7));
953 }
954
955 switch (type) {
956 case LPFC_ABORT_IOCB:
957 case LPFC_SOL_IOCB:
958 /*
959 * Idle exchange closed via ABTS from port. No iocb
960 * resources need to be recovered.
961 */
962 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -0400963 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
964 "%d:0314 IOCB cmd 0x%x"
965 " processed. Skipping"
966 " completion", phba->brd_no,
967 irsp->ulpCommand);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500968 break;
969 }
970
971 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
972 &rspiocbq);
973 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
974 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
975 &rspiocbq);
976 }
977 break;
978 default:
979 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
980 char adaptermsg[LPFC_MAX_ADPTMSG];
981 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
982 memcpy(&adaptermsg[0], (uint8_t *) irsp,
983 MAX_MSG_DATA);
984 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
985 phba->brd_no, adaptermsg);
986 } else {
987 /* Unknown IOCB command */
988 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
989 "%d:0321 Unknown IOCB command "
990 "Data: x%x, x%x x%x x%x x%x\n",
991 phba->brd_no, type,
992 irsp->ulpCommand,
993 irsp->ulpStatus,
994 irsp->ulpIoTag,
995 irsp->ulpContext);
996 }
997 break;
998 }
999
1000 /*
1001 * The response IOCB has been processed. Update the ring
1002 * pointer in SLIM. If the port response put pointer has not
1003 * been updated, sync the pgp->rspPutInx and fetch the new port
1004 * response put pointer.
1005 */
1006 to_slim = phba->MBslimaddr +
1007 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1008 writeb(pring->rspidx, to_slim);
1009
1010 if (pring->rspidx == portRspPut)
1011 portRspPut = le32_to_cpu(pgp->rspPutInx);
1012 }
1013
1014 ha_copy = readl(phba->HAregaddr);
1015 ha_copy >>= (LPFC_FCP_RING * 4);
1016
1017 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1018 pring->stats.iocb_rsp_full++;
1019 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1020 writel(status, phba->CAregaddr);
1021 readl(phba->CAregaddr);
1022 }
1023 if ((ha_copy & HA_R0CE_RSP) &&
1024 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1025 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1026 pring->stats.iocb_cmd_empty++;
1027
1028 /* Force update of the local copy of cmdGetInx */
1029 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1030 lpfc_sli_resume_iocb(phba, pring);
1031
1032 if ((pring->lpfc_sli_cmd_available))
1033 (pring->lpfc_sli_cmd_available) (phba, pring);
1034
1035 }
1036
1037 return;
1038}
1039
dea31012005-04-17 16:05:31 -05001040/*
1041 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1042 * to check it explicitly.
1043 */
1044static int
1045lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1046 struct lpfc_sli_ring * pring, uint32_t mask)
1047{
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001048 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001049 IOCB_t *irsp = NULL;
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001050 IOCB_t *entry = NULL;
dea31012005-04-17 16:05:31 -05001051 struct lpfc_iocbq *cmdiocbq = NULL;
1052 struct lpfc_iocbq rspiocbq;
dea31012005-04-17 16:05:31 -05001053 uint32_t status;
1054 uint32_t portRspPut, portRspMax;
1055 int rc = 1;
1056 lpfc_iocb_type type;
1057 unsigned long iflag;
1058 uint32_t rsp_cmpl = 0;
1059 void __iomem *to_slim;
1060
1061 spin_lock_irqsave(phba->host->host_lock, iflag);
1062 pring->stats.iocb_event++;
1063
dea31012005-04-17 16:05:31 -05001064 /*
1065 * The next available response entry should never exceed the maximum
1066 * entries. If it does, treat it as an adapter hardware error.
1067 */
1068 portRspMax = pring->numRiocb;
1069 portRspPut = le32_to_cpu(pgp->rspPutInx);
1070 if (unlikely(portRspPut >= portRspMax)) {
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001071 lpfc_sli_rsp_pointers_error(phba, pring);
dea31012005-04-17 16:05:31 -05001072 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1073 return 1;
1074 }
1075
1076 rmb();
1077 while (pring->rspidx != portRspPut) {
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001078 /*
1079 * Fetch an entry off the ring and copy it into a local data
1080 * structure. The copy involves a byte-swap since the
1081 * network byte order and pci byte orders are different.
1082 */
James.Smart@Emulex.Com4a0dfcd2005-10-28 20:29:56 -04001083 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001084
1085 if (++pring->rspidx >= portRspMax)
1086 pring->rspidx = 0;
1087
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001088 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1089 (uint32_t *) &rspiocbq.iocb,
1090 sizeof (IOCB_t));
James Smarta4bc3372006-12-02 13:34:16 -05001091 INIT_LIST_HEAD(&(rspiocbq.list));
James.Smart@Emulex.Com87f6eaf2005-06-25 10:34:13 -04001092 irsp = &rspiocbq.iocb;
1093
dea31012005-04-17 16:05:31 -05001094 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1095 pring->stats.iocb_rsp++;
1096 rsp_cmpl++;
1097
1098 if (unlikely(irsp->ulpStatus)) {
1099 /* Rsp ring <ringno> error: IOCB */
1100 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04001101 "%d:0336 Rsp Ring %d error: IOCB Data: "
dea31012005-04-17 16:05:31 -05001102 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1103 phba->brd_no, pring->ringno,
1104 irsp->un.ulpWord[0], irsp->un.ulpWord[1],
1105 irsp->un.ulpWord[2], irsp->un.ulpWord[3],
1106 irsp->un.ulpWord[4], irsp->un.ulpWord[5],
1107 *(((uint32_t *) irsp) + 6),
1108 *(((uint32_t *) irsp) + 7));
1109 }
1110
1111 switch (type) {
1112 case LPFC_ABORT_IOCB:
1113 case LPFC_SOL_IOCB:
1114 /*
1115 * Idle exchange closed via ABTS from port. No iocb
1116 * resources need to be recovered.
1117 */
1118 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
James Smartdca94792006-08-01 07:34:08 -04001119 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1120 "%d:0333 IOCB cmd 0x%x"
1121 " processed. Skipping"
1122 " completion\n", phba->brd_no,
1123 irsp->ulpCommand);
dea31012005-04-17 16:05:31 -05001124 break;
1125 }
1126
James Bottomley604a3e32005-10-29 10:28:33 -05001127 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1128 &rspiocbq);
dea31012005-04-17 16:05:31 -05001129 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
Jamie Wellnitzb8086082006-02-28 22:33:12 -05001130 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1131 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1132 &rspiocbq);
1133 } else {
1134 spin_unlock_irqrestore(
1135 phba->host->host_lock, iflag);
1136 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1137 &rspiocbq);
1138 spin_lock_irqsave(phba->host->host_lock,
1139 iflag);
1140 }
dea31012005-04-17 16:05:31 -05001141 }
1142 break;
James Smarta4bc3372006-12-02 13:34:16 -05001143 case LPFC_UNSOL_IOCB:
1144 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1145 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1146 spin_lock_irqsave(phba->host->host_lock, iflag);
1147 break;
dea31012005-04-17 16:05:31 -05001148 default:
1149 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1150 char adaptermsg[LPFC_MAX_ADPTMSG];
1151 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1152 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1153 MAX_MSG_DATA);
1154 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1155 phba->brd_no, adaptermsg);
1156 } else {
1157 /* Unknown IOCB command */
1158 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04001159 "%d:0334 Unknown IOCB command "
dea31012005-04-17 16:05:31 -05001160 "Data: x%x, x%x x%x x%x x%x\n",
1161 phba->brd_no, type, irsp->ulpCommand,
1162 irsp->ulpStatus, irsp->ulpIoTag,
1163 irsp->ulpContext);
1164 }
1165 break;
1166 }
1167
1168 /*
1169 * The response IOCB has been processed. Update the ring
1170 * pointer in SLIM. If the port response put pointer has not
1171 * been updated, sync the pgp->rspPutInx and fetch the new port
1172 * response put pointer.
1173 */
dea31012005-04-17 16:05:31 -05001174 to_slim = phba->MBslimaddr +
1175 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001176 writel(pring->rspidx, to_slim);
dea31012005-04-17 16:05:31 -05001177
1178 if (pring->rspidx == portRspPut)
1179 portRspPut = le32_to_cpu(pgp->rspPutInx);
1180 }
1181
1182 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1183 pring->stats.iocb_rsp_full++;
1184 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1185 writel(status, phba->CAregaddr);
1186 readl(phba->CAregaddr);
1187 }
1188 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1189 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1190 pring->stats.iocb_cmd_empty++;
1191
1192 /* Force update of the local copy of cmdGetInx */
1193 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1194 lpfc_sli_resume_iocb(phba, pring);
1195
1196 if ((pring->lpfc_sli_cmd_available))
1197 (pring->lpfc_sli_cmd_available) (phba, pring);
1198
1199 }
1200
1201 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1202 return rc;
1203}
1204
1205
1206int
1207lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1208 struct lpfc_sli_ring * pring, uint32_t mask)
1209{
1210 IOCB_t *entry;
1211 IOCB_t *irsp = NULL;
1212 struct lpfc_iocbq *rspiocbp = NULL;
1213 struct lpfc_iocbq *next_iocb;
1214 struct lpfc_iocbq *cmdiocbp;
1215 struct lpfc_iocbq *saveq;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001216 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
dea31012005-04-17 16:05:31 -05001217 uint8_t iocb_cmd_type;
1218 lpfc_iocb_type type;
1219 uint32_t status, free_saveq;
1220 uint32_t portRspPut, portRspMax;
1221 int rc = 1;
1222 unsigned long iflag;
1223 void __iomem *to_slim;
1224
1225 spin_lock_irqsave(phba->host->host_lock, iflag);
1226 pring->stats.iocb_event++;
1227
dea31012005-04-17 16:05:31 -05001228 /*
1229 * The next available response entry should never exceed the maximum
1230 * entries. If it does, treat it as an adapter hardware error.
1231 */
1232 portRspMax = pring->numRiocb;
1233 portRspPut = le32_to_cpu(pgp->rspPutInx);
1234 if (portRspPut >= portRspMax) {
1235 /*
1236 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1237 * rsp ring <portRspMax>
1238 */
1239 lpfc_printf_log(phba,
1240 KERN_ERR,
1241 LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04001242 "%d:0303 Ring %d handler: portRspPut %d "
dea31012005-04-17 16:05:31 -05001243 "is bigger then rsp ring %d\n",
1244 phba->brd_no,
1245 pring->ringno, portRspPut, portRspMax);
1246
1247 phba->hba_state = LPFC_HBA_ERROR;
1248 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1249
1250 phba->work_hs = HS_FFER3;
1251 lpfc_handle_eratt(phba);
1252
1253 return 1;
1254 }
1255
1256 rmb();
dea31012005-04-17 16:05:31 -05001257 while (pring->rspidx != portRspPut) {
1258 /*
1259 * Build a completion list and call the appropriate handler.
1260 * The process is to get the next available response iocb, get
1261 * a free iocb from the list, copy the response data into the
1262 * free iocb, insert to the continuation list, and update the
1263 * next response index to slim. This process makes response
1264 * iocb's in the ring available to DMA as fast as possible but
1265 * pays a penalty for a copy operation. Since the iocb is
1266 * only 32 bytes, this penalty is considered small relative to
1267 * the PCI reads for register values and a slim write. When
1268 * the ulpLe field is set, the entire Command has been
1269 * received.
1270 */
1271 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001272 rspiocbp = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001273 if (rspiocbp == NULL) {
1274 printk(KERN_ERR "%s: out of buffers! Failing "
1275 "completion.\n", __FUNCTION__);
1276 break;
1277 }
1278
1279 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof (IOCB_t));
1280 irsp = &rspiocbp->iocb;
1281
1282 if (++pring->rspidx >= portRspMax)
1283 pring->rspidx = 0;
1284
1285 to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2)
1286 + 1) * 4;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001287 writel(pring->rspidx, to_slim);
dea31012005-04-17 16:05:31 -05001288
1289 if (list_empty(&(pring->iocb_continueq))) {
1290 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1291 } else {
1292 list_add_tail(&rspiocbp->list,
1293 &(pring->iocb_continueq));
1294 }
1295
1296 pring->iocb_continueq_cnt++;
1297 if (irsp->ulpLe) {
1298 /*
1299 * By default, the driver expects to free all resources
1300 * associated with this iocb completion.
1301 */
1302 free_saveq = 1;
1303 saveq = list_get_first(&pring->iocb_continueq,
1304 struct lpfc_iocbq, list);
1305 irsp = &(saveq->iocb);
1306 list_del_init(&pring->iocb_continueq);
1307 pring->iocb_continueq_cnt = 0;
1308
1309 pring->stats.iocb_rsp++;
1310
1311 if (irsp->ulpStatus) {
1312 /* Rsp ring <ringno> error: IOCB */
1313 lpfc_printf_log(phba,
1314 KERN_WARNING,
1315 LOG_SLI,
1316 "%d:0328 Rsp Ring %d error: IOCB Data: "
1317 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1318 phba->brd_no,
1319 pring->ringno,
1320 irsp->un.ulpWord[0],
1321 irsp->un.ulpWord[1],
1322 irsp->un.ulpWord[2],
1323 irsp->un.ulpWord[3],
1324 irsp->un.ulpWord[4],
1325 irsp->un.ulpWord[5],
1326 *(((uint32_t *) irsp) + 6),
1327 *(((uint32_t *) irsp) + 7));
1328 }
1329
1330 /*
1331 * Fetch the IOCB command type and call the correct
1332 * completion routine. Solicited and Unsolicited
1333 * IOCBs on the ELS ring get freed back to the
1334 * lpfc_iocb_list by the discovery kernel thread.
1335 */
1336 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1337 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1338 if (type == LPFC_SOL_IOCB) {
1339 spin_unlock_irqrestore(phba->host->host_lock,
1340 iflag);
1341 rc = lpfc_sli_process_sol_iocb(phba, pring,
1342 saveq);
1343 spin_lock_irqsave(phba->host->host_lock, iflag);
1344 } else if (type == LPFC_UNSOL_IOCB) {
1345 spin_unlock_irqrestore(phba->host->host_lock,
1346 iflag);
1347 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1348 saveq);
1349 spin_lock_irqsave(phba->host->host_lock, iflag);
1350 } else if (type == LPFC_ABORT_IOCB) {
1351 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1352 ((cmdiocbp =
James Bottomley604a3e32005-10-29 10:28:33 -05001353 lpfc_sli_iocbq_lookup(phba, pring,
1354 saveq)))) {
dea31012005-04-17 16:05:31 -05001355 /* Call the specified completion
1356 routine */
1357 if (cmdiocbp->iocb_cmpl) {
1358 spin_unlock_irqrestore(
1359 phba->host->host_lock,
1360 iflag);
1361 (cmdiocbp->iocb_cmpl) (phba,
1362 cmdiocbp, saveq);
1363 spin_lock_irqsave(
1364 phba->host->host_lock,
1365 iflag);
James Bottomley604a3e32005-10-29 10:28:33 -05001366 } else
1367 lpfc_sli_release_iocbq(phba,
1368 cmdiocbp);
dea31012005-04-17 16:05:31 -05001369 }
1370 } else if (type == LPFC_UNKNOWN_IOCB) {
1371 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1372
1373 char adaptermsg[LPFC_MAX_ADPTMSG];
1374
1375 memset(adaptermsg, 0,
1376 LPFC_MAX_ADPTMSG);
1377 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1378 MAX_MSG_DATA);
1379 dev_warn(&((phba->pcidev)->dev),
1380 "lpfc%d: %s",
1381 phba->brd_no, adaptermsg);
1382 } else {
1383 /* Unknown IOCB command */
1384 lpfc_printf_log(phba,
1385 KERN_ERR,
1386 LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04001387 "%d:0335 Unknown IOCB command "
dea31012005-04-17 16:05:31 -05001388 "Data: x%x x%x x%x x%x\n",
1389 phba->brd_no,
1390 irsp->ulpCommand,
1391 irsp->ulpStatus,
1392 irsp->ulpIoTag,
1393 irsp->ulpContext);
1394 }
1395 }
1396
1397 if (free_saveq) {
1398 if (!list_empty(&saveq->list)) {
1399 list_for_each_entry_safe(rspiocbp,
1400 next_iocb,
1401 &saveq->list,
1402 list) {
James Smart8f6d98d2006-08-01 07:34:00 -04001403 list_del(&rspiocbp->list);
James Bottomley604a3e32005-10-29 10:28:33 -05001404 lpfc_sli_release_iocbq(phba,
1405 rspiocbp);
dea31012005-04-17 16:05:31 -05001406 }
1407 }
James Bottomley604a3e32005-10-29 10:28:33 -05001408 lpfc_sli_release_iocbq(phba, saveq);
dea31012005-04-17 16:05:31 -05001409 }
1410 }
1411
1412 /*
1413 * If the port response put pointer has not been updated, sync
1414 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1415 * response put pointer.
1416 */
1417 if (pring->rspidx == portRspPut) {
1418 portRspPut = le32_to_cpu(pgp->rspPutInx);
1419 }
1420 } /* while (pring->rspidx != portRspPut) */
1421
1422 if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
1423 /* At least one response entry has been freed */
1424 pring->stats.iocb_rsp_full++;
1425 /* SET RxRE_RSP in Chip Att register */
1426 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1427 writel(status, phba->CAregaddr);
1428 readl(phba->CAregaddr); /* flush */
1429 }
1430 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1431 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1432 pring->stats.iocb_cmd_empty++;
1433
1434 /* Force update of the local copy of cmdGetInx */
1435 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1436 lpfc_sli_resume_iocb(phba, pring);
1437
1438 if ((pring->lpfc_sli_cmd_available))
1439 (pring->lpfc_sli_cmd_available) (phba, pring);
1440
1441 }
1442
1443 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1444 return rc;
1445}
1446
1447int
1448lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1449{
1450 struct lpfc_iocbq *iocb, *next_iocb;
1451 IOCB_t *icmd = NULL, *cmd = NULL;
1452 int errcnt;
dea31012005-04-17 16:05:31 -05001453
1454 errcnt = 0;
1455
1456 /* Error everything on txq and txcmplq
1457 * First do the txq.
1458 */
1459 spin_lock_irq(phba->host->host_lock);
1460 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1461 list_del_init(&iocb->list);
1462 if (iocb->iocb_cmpl) {
1463 icmd = &iocb->iocb;
1464 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1465 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1466 spin_unlock_irq(phba->host->host_lock);
1467 (iocb->iocb_cmpl) (phba, iocb, iocb);
1468 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001469 } else
1470 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001471 }
1472 pring->txq_cnt = 0;
1473 INIT_LIST_HEAD(&(pring->txq));
1474
1475 /* Next issue ABTS for everything on the txcmplq */
1476 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1477 cmd = &iocb->iocb;
1478
1479 /*
James Bottomley604a3e32005-10-29 10:28:33 -05001480 * Imediate abort of IOCB, deque and call compl
dea31012005-04-17 16:05:31 -05001481 */
dea31012005-04-17 16:05:31 -05001482
1483 list_del_init(&iocb->list);
1484 pring->txcmplq_cnt--;
1485
1486 if (iocb->iocb_cmpl) {
1487 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1488 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1489 spin_unlock_irq(phba->host->host_lock);
1490 (iocb->iocb_cmpl) (phba, iocb, iocb);
1491 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001492 } else
1493 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001494 }
1495
1496 INIT_LIST_HEAD(&pring->txcmplq);
1497 pring->txcmplq_cnt = 0;
1498 spin_unlock_irq(phba->host->host_lock);
1499
1500 return errcnt;
1501}
1502
Jamie Wellnitz41415862006-02-28 19:25:27 -05001503int
1504lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
dea31012005-04-17 16:05:31 -05001505{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001506 uint32_t status;
1507 int i = 0;
1508 int retval = 0;
dea31012005-04-17 16:05:31 -05001509
Jamie Wellnitz41415862006-02-28 19:25:27 -05001510 /* Read the HBA Host Status Register */
1511 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001512
Jamie Wellnitz41415862006-02-28 19:25:27 -05001513 /*
1514 * Check status register every 100ms for 5 retries, then every
1515 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1516 * every 2.5 sec for 4.
1517 * Break our of the loop if errors occurred during init.
1518 */
1519 while (((status & mask) != mask) &&
1520 !(status & HS_FFERM) &&
1521 i++ < 20) {
dea31012005-04-17 16:05:31 -05001522
Jamie Wellnitz41415862006-02-28 19:25:27 -05001523 if (i <= 5)
1524 msleep(10);
1525 else if (i <= 10)
1526 msleep(500);
1527 else
1528 msleep(2500);
dea31012005-04-17 16:05:31 -05001529
Jamie Wellnitz41415862006-02-28 19:25:27 -05001530 if (i == 15) {
1531 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1532 lpfc_sli_brdrestart(phba);
1533 }
1534 /* Read the HBA Host Status Register */
1535 status = readl(phba->HSregaddr);
dea31012005-04-17 16:05:31 -05001536 }
dea31012005-04-17 16:05:31 -05001537
Jamie Wellnitz41415862006-02-28 19:25:27 -05001538 /* Check to see if any errors occurred during init */
1539 if ((status & HS_FFERM) || (i >= 20)) {
1540 phba->hba_state = LPFC_HBA_ERROR;
1541 retval = 1;
1542 }
dea31012005-04-17 16:05:31 -05001543
Jamie Wellnitz41415862006-02-28 19:25:27 -05001544 return retval;
dea31012005-04-17 16:05:31 -05001545}
1546
James Smart92908312006-03-07 15:04:13 -05001547#define BARRIER_TEST_PATTERN (0xdeadbeef)
1548
1549void lpfc_reset_barrier(struct lpfc_hba * phba)
1550{
James Smart65a29c12006-07-06 15:50:50 -04001551 uint32_t __iomem *resp_buf;
1552 uint32_t __iomem *mbox_buf;
James Smart92908312006-03-07 15:04:13 -05001553 volatile uint32_t mbox;
1554 uint32_t hc_copy;
1555 int i;
1556 uint8_t hdrtype;
1557
1558 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1559 if (hdrtype != 0x80 ||
1560 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1561 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1562 return;
1563
1564 /*
1565 * Tell the other part of the chip to suspend temporarily all
1566 * its DMA activity.
1567 */
James Smart65a29c12006-07-06 15:50:50 -04001568 resp_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001569
1570 /* Disable the error attention */
1571 hc_copy = readl(phba->HCregaddr);
1572 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1573 readl(phba->HCregaddr); /* flush */
1574
1575 if (readl(phba->HAregaddr) & HA_ERATT) {
1576 /* Clear Chip error bit */
1577 writel(HA_ERATT, phba->HAregaddr);
1578 phba->stopped = 1;
1579 }
1580
1581 mbox = 0;
1582 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1583 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1584
1585 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
James Smart65a29c12006-07-06 15:50:50 -04001586 mbox_buf = phba->MBslimaddr;
James Smart92908312006-03-07 15:04:13 -05001587 writel(mbox, mbox_buf);
1588
1589 for (i = 0;
1590 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1591 mdelay(1);
1592
1593 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1594 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1595 phba->stopped)
1596 goto restore_hc;
1597 else
1598 goto clear_errat;
1599 }
1600
1601 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1602 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1603 mdelay(1);
1604
1605clear_errat:
1606
1607 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1608 mdelay(1);
1609
1610 if (readl(phba->HAregaddr) & HA_ERATT) {
1611 writel(HA_ERATT, phba->HAregaddr);
1612 phba->stopped = 1;
1613 }
1614
1615restore_hc:
1616 writel(hc_copy, phba->HCregaddr);
1617 readl(phba->HCregaddr); /* flush */
1618}
1619
Jamie Wellnitz41415862006-02-28 19:25:27 -05001620int
1621lpfc_sli_brdkill(struct lpfc_hba * phba)
dea31012005-04-17 16:05:31 -05001622{
Jamie Wellnitz41415862006-02-28 19:25:27 -05001623 struct lpfc_sli *psli;
1624 LPFC_MBOXQ_t *pmb;
1625 uint32_t status;
1626 uint32_t ha_copy;
1627 int retval;
1628 int i = 0;
1629
1630 psli = &phba->sli;
1631
1632 /* Kill HBA */
1633 lpfc_printf_log(phba,
1634 KERN_INFO,
1635 LOG_SLI,
1636 "%d:0329 Kill HBA Data: x%x x%x\n",
1637 phba->brd_no,
1638 phba->hba_state,
1639 psli->sli_flag);
1640
1641 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
James Smart92908312006-03-07 15:04:13 -05001642 GFP_KERNEL)) == 0)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001643 return 1;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001644
1645 /* Disable the error attention */
1646 spin_lock_irq(phba->host->host_lock);
1647 status = readl(phba->HCregaddr);
1648 status &= ~HC_ERINT_ENA;
1649 writel(status, phba->HCregaddr);
1650 readl(phba->HCregaddr); /* flush */
1651 spin_unlock_irq(phba->host->host_lock);
1652
1653 lpfc_kill_board(phba, pmb);
1654 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1655 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1656
1657 if (retval != MBX_SUCCESS) {
1658 if (retval != MBX_BUSY)
1659 mempool_free(pmb, phba->mbox_mem_pool);
1660 return 1;
1661 }
1662
James Smart92908312006-03-07 15:04:13 -05001663 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1664
Jamie Wellnitz41415862006-02-28 19:25:27 -05001665 mempool_free(pmb, phba->mbox_mem_pool);
1666
1667 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1668 * attention every 100ms for 3 seconds. If we don't get ERATT after
1669 * 3 seconds we still set HBA_ERROR state because the status of the
1670 * board is now undefined.
1671 */
1672 ha_copy = readl(phba->HAregaddr);
1673
1674 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1675 mdelay(100);
1676 ha_copy = readl(phba->HAregaddr);
1677 }
1678
1679 del_timer_sync(&psli->mbox_tmo);
James Smart92908312006-03-07 15:04:13 -05001680 if (ha_copy & HA_ERATT) {
1681 writel(HA_ERATT, phba->HAregaddr);
1682 phba->stopped = 1;
1683 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001684 spin_lock_irq(phba->host->host_lock);
1685 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1686 spin_unlock_irq(phba->host->host_lock);
1687
1688 psli->mbox_active = NULL;
1689 lpfc_hba_down_post(phba);
1690 phba->hba_state = LPFC_HBA_ERROR;
1691
1692 return (ha_copy & HA_ERATT ? 0 : 1);
1693}
1694
1695int
1696lpfc_sli_brdreset(struct lpfc_hba * phba)
1697{
1698 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001699 struct lpfc_sli_ring *pring;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001700 uint16_t cfg_value;
dea31012005-04-17 16:05:31 -05001701 int i;
dea31012005-04-17 16:05:31 -05001702
Jamie Wellnitz41415862006-02-28 19:25:27 -05001703 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001704
Jamie Wellnitz41415862006-02-28 19:25:27 -05001705 /* Reset HBA */
1706 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1707 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1708 phba->hba_state, psli->sli_flag);
dea31012005-04-17 16:05:31 -05001709
1710 /* perform board reset */
1711 phba->fc_eventTag = 0;
1712 phba->fc_myDID = 0;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001713 phba->fc_prevDID = 0;
dea31012005-04-17 16:05:31 -05001714
Jamie Wellnitz41415862006-02-28 19:25:27 -05001715 /* Turn off parity checking and serr during the physical reset */
1716 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1717 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1718 (cfg_value &
1719 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1720
James Smart1c067a42006-08-01 07:33:52 -04001721 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001722 /* Now toggle INITFF bit in the Host Control Register */
1723 writel(HC_INITFF, phba->HCregaddr);
1724 mdelay(1);
1725 readl(phba->HCregaddr); /* flush */
1726 writel(0, phba->HCregaddr);
1727 readl(phba->HCregaddr); /* flush */
1728
1729 /* Restore PCI cmd register */
1730 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
dea31012005-04-17 16:05:31 -05001731
1732 /* Initialize relevant SLI info */
Jamie Wellnitz41415862006-02-28 19:25:27 -05001733 for (i = 0; i < psli->num_rings; i++) {
1734 pring = &psli->ring[i];
dea31012005-04-17 16:05:31 -05001735 pring->flag = 0;
1736 pring->rspidx = 0;
1737 pring->next_cmdidx = 0;
1738 pring->local_getidx = 0;
1739 pring->cmdidx = 0;
1740 pring->missbufcnt = 0;
1741 }
dea31012005-04-17 16:05:31 -05001742
Jamie Wellnitz41415862006-02-28 19:25:27 -05001743 phba->hba_state = LPFC_WARM_START;
1744 return 0;
1745}
1746
1747int
1748lpfc_sli_brdrestart(struct lpfc_hba * phba)
1749{
1750 MAILBOX_t *mb;
1751 struct lpfc_sli *psli;
1752 uint16_t skip_post;
1753 volatile uint32_t word0;
1754 void __iomem *to_slim;
1755
1756 spin_lock_irq(phba->host->host_lock);
1757
1758 psli = &phba->sli;
1759
1760 /* Restart HBA */
1761 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04001762 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001763 phba->hba_state, psli->sli_flag);
1764
1765 word0 = 0;
1766 mb = (MAILBOX_t *) &word0;
1767 mb->mbxCommand = MBX_RESTART;
1768 mb->mbxHc = 1;
1769
James Smart92908312006-03-07 15:04:13 -05001770 lpfc_reset_barrier(phba);
1771
Jamie Wellnitz41415862006-02-28 19:25:27 -05001772 to_slim = phba->MBslimaddr;
1773 writel(*(uint32_t *) mb, to_slim);
1774 readl(to_slim); /* flush */
1775
1776 /* Only skip post after fc_ffinit is completed */
1777 if (phba->hba_state) {
1778 skip_post = 1;
1779 word0 = 1; /* This is really setting up word1 */
dea31012005-04-17 16:05:31 -05001780 } else {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001781 skip_post = 0;
1782 word0 = 0; /* This is really setting up word1 */
1783 }
James Smart65a29c12006-07-06 15:50:50 -04001784 to_slim = phba->MBslimaddr + sizeof (uint32_t);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001785 writel(*(uint32_t *) mb, to_slim);
1786 readl(to_slim); /* flush */
1787
1788 lpfc_sli_brdreset(phba);
James Smart92908312006-03-07 15:04:13 -05001789 phba->stopped = 0;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001790 phba->hba_state = LPFC_INIT_START;
1791
1792 spin_unlock_irq(phba->host->host_lock);
1793
James Smart64ba8812006-08-02 15:24:34 -04001794 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
1795 psli->stats_start = get_seconds();
1796
Jamie Wellnitz41415862006-02-28 19:25:27 -05001797 if (skip_post)
1798 mdelay(100);
1799 else
dea31012005-04-17 16:05:31 -05001800 mdelay(2000);
dea31012005-04-17 16:05:31 -05001801
Jamie Wellnitz41415862006-02-28 19:25:27 -05001802 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -05001803
1804 return 0;
1805}
1806
1807static int
1808lpfc_sli_chipset_init(struct lpfc_hba *phba)
1809{
1810 uint32_t status, i = 0;
1811
1812 /* Read the HBA Host Status Register */
1813 status = readl(phba->HSregaddr);
1814
1815 /* Check status register to see what current state is */
1816 i = 0;
1817 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
1818
1819 /* Check every 100ms for 5 retries, then every 500ms for 5, then
1820 * every 2.5 sec for 5, then reset board and every 2.5 sec for
1821 * 4.
1822 */
1823 if (i++ >= 20) {
1824 /* Adapter failed to init, timeout, status reg
1825 <status> */
1826 lpfc_printf_log(phba,
1827 KERN_ERR,
1828 LOG_INIT,
1829 "%d:0436 Adapter failed to init, "
1830 "timeout, status reg x%x\n",
1831 phba->brd_no,
1832 status);
1833 phba->hba_state = LPFC_HBA_ERROR;
1834 return -ETIMEDOUT;
1835 }
1836
1837 /* Check to see if any errors occurred during init */
1838 if (status & HS_FFERM) {
1839 /* ERROR: During chipset initialization */
1840 /* Adapter failed to init, chipset, status reg
1841 <status> */
1842 lpfc_printf_log(phba,
1843 KERN_ERR,
1844 LOG_INIT,
1845 "%d:0437 Adapter failed to init, "
1846 "chipset, status reg x%x\n",
1847 phba->brd_no,
1848 status);
1849 phba->hba_state = LPFC_HBA_ERROR;
1850 return -EIO;
1851 }
1852
1853 if (i <= 5) {
1854 msleep(10);
1855 } else if (i <= 10) {
1856 msleep(500);
1857 } else {
1858 msleep(2500);
1859 }
1860
1861 if (i == 15) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001862 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1863 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001864 }
1865 /* Read the HBA Host Status Register */
1866 status = readl(phba->HSregaddr);
1867 }
1868
1869 /* Check to see if any errors occurred during init */
1870 if (status & HS_FFERM) {
1871 /* ERROR: During chipset initialization */
1872 /* Adapter failed to init, chipset, status reg <status> */
1873 lpfc_printf_log(phba,
1874 KERN_ERR,
1875 LOG_INIT,
1876 "%d:0438 Adapter failed to init, chipset, "
1877 "status reg x%x\n",
1878 phba->brd_no,
1879 status);
1880 phba->hba_state = LPFC_HBA_ERROR;
1881 return -EIO;
1882 }
1883
1884 /* Clear all interrupt enable conditions */
1885 writel(0, phba->HCregaddr);
1886 readl(phba->HCregaddr); /* flush */
1887
1888 /* setup host attn register */
1889 writel(0xffffffff, phba->HAregaddr);
1890 readl(phba->HAregaddr); /* flush */
1891 return 0;
1892}
1893
1894int
1895lpfc_sli_hba_setup(struct lpfc_hba * phba)
1896{
1897 LPFC_MBOXQ_t *pmb;
1898 uint32_t resetcount = 0, rc = 0, done = 0;
1899
1900 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1901 if (!pmb) {
1902 phba->hba_state = LPFC_HBA_ERROR;
1903 return -ENOMEM;
1904 }
1905
1906 while (resetcount < 2 && !done) {
James Smart1c067a42006-08-01 07:33:52 -04001907 spin_lock_irq(phba->host->host_lock);
1908 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
1909 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001910 phba->hba_state = LPFC_STATE_UNKNOWN;
1911 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001912 msleep(2500);
1913 rc = lpfc_sli_chipset_init(phba);
1914 if (rc)
1915 break;
1916
James Smart1c067a42006-08-01 07:33:52 -04001917 spin_lock_irq(phba->host->host_lock);
1918 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1919 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001920 resetcount++;
1921
1922 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
1923 * means the call was successful. Any other nonzero value is a failure,
1924 * but if ERESTART is returned, the driver may reset the HBA and try
1925 * again.
1926 */
1927 rc = lpfc_config_port_prep(phba);
1928 if (rc == -ERESTART) {
1929 phba->hba_state = 0;
1930 continue;
1931 } else if (rc) {
1932 break;
1933 }
1934
1935 phba->hba_state = LPFC_INIT_MBX_CMDS;
1936 lpfc_config_port(phba, pmb);
1937 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1938 if (rc == MBX_SUCCESS)
1939 done = 1;
1940 else {
1941 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1942 "%d:0442 Adapter failed to init, mbxCmd x%x "
1943 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1944 phba->brd_no, pmb->mb.mbxCommand,
1945 pmb->mb.mbxStatus, 0);
1946 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1947 }
1948 }
1949 if (!done)
1950 goto lpfc_sli_hba_setup_error;
1951
1952 rc = lpfc_sli_ring_map(phba, pmb);
1953
1954 if (rc)
1955 goto lpfc_sli_hba_setup_error;
1956
1957 phba->sli.sli_flag |= LPFC_PROCESS_LA;
1958
1959 rc = lpfc_config_port_post(phba);
1960 if (rc)
1961 goto lpfc_sli_hba_setup_error;
1962
1963 goto lpfc_sli_hba_setup_exit;
1964lpfc_sli_hba_setup_error:
1965 phba->hba_state = LPFC_HBA_ERROR;
1966lpfc_sli_hba_setup_exit:
1967 mempool_free(pmb, phba->mbox_mem_pool);
1968 return rc;
1969}
1970
dea31012005-04-17 16:05:31 -05001971/*! lpfc_mbox_timeout
1972 *
1973 * \pre
1974 * \post
1975 * \param hba Pointer to per struct lpfc_hba structure
1976 * \param l1 Pointer to the driver's mailbox queue.
1977 * \return
1978 * void
1979 *
1980 * \b Description:
1981 *
1982 * This routine handles mailbox timeout events at timer interrupt context.
1983 */
1984void
1985lpfc_mbox_timeout(unsigned long ptr)
1986{
1987 struct lpfc_hba *phba;
1988 unsigned long iflag;
1989
1990 phba = (struct lpfc_hba *)ptr;
1991 spin_lock_irqsave(phba->host->host_lock, iflag);
1992 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
1993 phba->work_hba_events |= WORKER_MBOX_TMO;
1994 if (phba->work_wait)
1995 wake_up(phba->work_wait);
1996 }
1997 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1998}
1999
2000void
2001lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2002{
2003 LPFC_MBOXQ_t *pmbox;
2004 MAILBOX_t *mb;
James Smart1dcb58e2007-04-25 09:51:30 -04002005 struct lpfc_sli *psli = &phba->sli;
2006 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002007
2008 spin_lock_irq(phba->host->host_lock);
2009 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2010 spin_unlock_irq(phba->host->host_lock);
2011 return;
2012 }
2013
2014 pmbox = phba->sli.mbox_active;
2015 mb = &pmbox->mb;
2016
2017 /* Mbox cmd <mbxCommand> timeout */
2018 lpfc_printf_log(phba,
2019 KERN_ERR,
2020 LOG_MBOX | LOG_SLI,
2021 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2022 phba->brd_no,
2023 mb->mbxCommand,
2024 phba->hba_state,
2025 phba->sli.sli_flag,
2026 phba->sli.mbox_active);
2027
James Smart1dcb58e2007-04-25 09:51:30 -04002028 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2029 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2030 * it to fail all oustanding SCSI IO.
2031 */
2032 phba->hba_state = LPFC_STATE_UNKNOWN;
2033 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2034 phba->fc_flag |= FC_ESTABLISH_LINK;
2035 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
dea31012005-04-17 16:05:31 -05002036 spin_unlock_irq(phba->host->host_lock);
James Smart1dcb58e2007-04-25 09:51:30 -04002037
2038 pring = &psli->ring[psli->fcp_ring];
2039 lpfc_sli_abort_iocb_ring(phba, pring);
2040
2041 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2042 "%d:0316 Resetting board due to mailbox timeout\n",
2043 phba->brd_no);
2044 /*
2045 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2046 * on oustanding mailbox commands.
2047 */
2048 lpfc_offline_prep(phba);
2049 lpfc_offline(phba);
2050 lpfc_sli_brdrestart(phba);
2051 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2052 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2053 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002054 return;
2055}
2056
2057int
2058lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2059{
dea31012005-04-17 16:05:31 -05002060 MAILBOX_t *mb;
2061 struct lpfc_sli *psli;
2062 uint32_t status, evtctr;
2063 uint32_t ha_copy;
2064 int i;
2065 unsigned long drvr_flag = 0;
2066 volatile uint32_t word0, ldata;
2067 void __iomem *to_slim;
2068
Linas Vepstas8d63f372007-02-14 14:28:36 -06002069 /* If the PCI channel is in offline state, do not post mbox. */
2070 if (unlikely(pci_channel_offline(phba->pcidev)))
2071 return MBX_NOT_FINISHED;
2072
dea31012005-04-17 16:05:31 -05002073 psli = &phba->sli;
2074
2075 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2076
2077
2078 mb = &pmbox->mb;
2079 status = MBX_SUCCESS;
2080
Jamie Wellnitz41415862006-02-28 19:25:27 -05002081 if (phba->hba_state == LPFC_HBA_ERROR) {
2082 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2083
2084 /* Mbox command <mbxCommand> cannot issue */
2085 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2086 return (MBX_NOT_FINISHED);
2087 }
2088
James Smart92908312006-03-07 15:04:13 -05002089 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2090 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2091 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2092 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2093 return (MBX_NOT_FINISHED);
2094 }
2095
dea31012005-04-17 16:05:31 -05002096 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2097 /* Polling for a mbox command when another one is already active
2098 * is not allowed in SLI. Also, the driver must have established
2099 * SLI2 mode to queue and process multiple mbox commands.
2100 */
2101
2102 if (flag & MBX_POLL) {
2103 spin_unlock_irqrestore(phba->host->host_lock,
2104 drvr_flag);
2105
2106 /* Mbox command <mbxCommand> cannot issue */
2107 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2108 return (MBX_NOT_FINISHED);
2109 }
2110
2111 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2112 spin_unlock_irqrestore(phba->host->host_lock,
2113 drvr_flag);
2114 /* Mbox command <mbxCommand> cannot issue */
2115 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2116 return (MBX_NOT_FINISHED);
2117 }
2118
2119 /* Handle STOP IOCB processing flag. This is only meaningful
2120 * if we are not polling for mbox completion.
2121 */
2122 if (flag & MBX_STOP_IOCB) {
2123 flag &= ~MBX_STOP_IOCB;
2124 /* Now flag each ring */
2125 for (i = 0; i < psli->num_rings; i++) {
2126 /* If the ring is active, flag it */
2127 if (psli->ring[i].cmdringaddr) {
2128 psli->ring[i].flag |=
2129 LPFC_STOP_IOCB_MBX;
2130 }
2131 }
2132 }
2133
2134 /* Another mailbox command is still being processed, queue this
2135 * command to be processed later.
2136 */
2137 lpfc_mbox_put(phba, pmbox);
2138
2139 /* Mbox cmd issue - BUSY */
2140 lpfc_printf_log(phba,
2141 KERN_INFO,
2142 LOG_MBOX | LOG_SLI,
2143 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2144 phba->brd_no,
2145 mb->mbxCommand,
2146 phba->hba_state,
2147 psli->sli_flag,
2148 flag);
2149
2150 psli->slistat.mbox_busy++;
2151 spin_unlock_irqrestore(phba->host->host_lock,
2152 drvr_flag);
2153
2154 return (MBX_BUSY);
2155 }
2156
2157 /* Handle STOP IOCB processing flag. This is only meaningful
2158 * if we are not polling for mbox completion.
2159 */
2160 if (flag & MBX_STOP_IOCB) {
2161 flag &= ~MBX_STOP_IOCB;
2162 if (flag == MBX_NOWAIT) {
2163 /* Now flag each ring */
2164 for (i = 0; i < psli->num_rings; i++) {
2165 /* If the ring is active, flag it */
2166 if (psli->ring[i].cmdringaddr) {
2167 psli->ring[i].flag |=
2168 LPFC_STOP_IOCB_MBX;
2169 }
2170 }
2171 }
2172 }
2173
2174 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2175
2176 /* If we are not polling, we MUST be in SLI2 mode */
2177 if (flag != MBX_POLL) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05002178 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2179 (mb->mbxCommand != MBX_KILL_BOARD)) {
dea31012005-04-17 16:05:31 -05002180 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2181 spin_unlock_irqrestore(phba->host->host_lock,
2182 drvr_flag);
2183 /* Mbox command <mbxCommand> cannot issue */
2184 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2185 return (MBX_NOT_FINISHED);
2186 }
2187 /* timeout active mbox command */
James Smarta309a6b2006-08-01 07:33:43 -04002188 mod_timer(&psli->mbox_tmo, (jiffies +
2189 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
dea31012005-04-17 16:05:31 -05002190 }
2191
2192 /* Mailbox cmd <cmd> issue */
2193 lpfc_printf_log(phba,
2194 KERN_INFO,
2195 LOG_MBOX | LOG_SLI,
2196 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2197 phba->brd_no,
2198 mb->mbxCommand,
2199 phba->hba_state,
2200 psli->sli_flag,
2201 flag);
2202
2203 psli->slistat.mbox_cmd++;
2204 evtctr = psli->slistat.mbox_event;
2205
2206 /* next set own bit for the adapter and copy over command word */
2207 mb->mbxOwner = OWN_CHIP;
2208
2209 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002210 /* First copy command data to host SLIM area */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002211 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002212 } else {
James Smart92908312006-03-07 15:04:13 -05002213 if (mb->mbxCommand == MBX_CONFIG_PORT) {
dea31012005-04-17 16:05:31 -05002214 /* copy command data into host mbox for cmpl */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002215 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2216 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002217 }
2218
2219 /* First copy mbox command data to HBA SLIM, skip past first
2220 word */
2221 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2222 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2223 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2224
2225 /* Next copy over first word, with mbxOwner set */
2226 ldata = *((volatile uint32_t *)mb);
2227 to_slim = phba->MBslimaddr;
2228 writel(ldata, to_slim);
2229 readl(to_slim); /* flush */
2230
2231 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2232 /* switch over to host mailbox */
2233 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2234 }
2235 }
2236
2237 wmb();
2238 /* interrupt board to doit right away */
2239 writel(CA_MBATT, phba->CAregaddr);
2240 readl(phba->CAregaddr); /* flush */
2241
2242 switch (flag) {
2243 case MBX_NOWAIT:
2244 /* Don't wait for it to finish, just return */
2245 psli->mbox_active = pmbox;
2246 break;
2247
2248 case MBX_POLL:
dea31012005-04-17 16:05:31 -05002249 psli->mbox_active = NULL;
2250 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2251 /* First read mbox status word */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002252 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002253 word0 = le32_to_cpu(word0);
2254 } else {
2255 /* First read mbox status word */
2256 word0 = readl(phba->MBslimaddr);
2257 }
2258
2259 /* Read the HBA Host Attention Register */
2260 ha_copy = readl(phba->HAregaddr);
2261
James Smarta309a6b2006-08-01 07:33:43 -04002262 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2263 i *= 1000; /* Convert to ms */
2264
dea31012005-04-17 16:05:31 -05002265 /* Wait for command to complete */
Jamie Wellnitz41415862006-02-28 19:25:27 -05002266 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2267 (!(ha_copy & HA_MBATT) &&
2268 (phba->hba_state > LPFC_WARM_START))) {
James Smarta309a6b2006-08-01 07:33:43 -04002269 if (i-- <= 0) {
dea31012005-04-17 16:05:31 -05002270 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2271 spin_unlock_irqrestore(phba->host->host_lock,
2272 drvr_flag);
2273 return (MBX_NOT_FINISHED);
2274 }
2275
2276 /* Check if we took a mbox interrupt while we were
2277 polling */
2278 if (((word0 & OWN_CHIP) != OWN_CHIP)
2279 && (evtctr != psli->slistat.mbox_event))
2280 break;
2281
2282 spin_unlock_irqrestore(phba->host->host_lock,
2283 drvr_flag);
2284
James Smart1dcb58e2007-04-25 09:51:30 -04002285 msleep(1);
dea31012005-04-17 16:05:31 -05002286
2287 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2288
2289 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2290 /* First copy command data */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002291 word0 = *((volatile uint32_t *)
2292 &phba->slim2p->mbx);
dea31012005-04-17 16:05:31 -05002293 word0 = le32_to_cpu(word0);
2294 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2295 MAILBOX_t *slimmb;
2296 volatile uint32_t slimword0;
2297 /* Check real SLIM for any errors */
2298 slimword0 = readl(phba->MBslimaddr);
2299 slimmb = (MAILBOX_t *) & slimword0;
2300 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2301 && slimmb->mbxStatus) {
2302 psli->sli_flag &=
2303 ~LPFC_SLI2_ACTIVE;
2304 word0 = slimword0;
2305 }
2306 }
2307 } else {
2308 /* First copy command data */
2309 word0 = readl(phba->MBslimaddr);
2310 }
2311 /* Read the HBA Host Attention Register */
2312 ha_copy = readl(phba->HAregaddr);
2313 }
2314
2315 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
dea31012005-04-17 16:05:31 -05002316 /* copy results back to user */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04002317 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2318 MAILBOX_CMD_SIZE);
dea31012005-04-17 16:05:31 -05002319 } else {
2320 /* First copy command data */
2321 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2322 MAILBOX_CMD_SIZE);
2323 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2324 pmbox->context2) {
2325 lpfc_memcpy_from_slim((void *)pmbox->context2,
2326 phba->MBslimaddr + DMP_RSP_OFFSET,
2327 mb->un.varDmp.word_cnt);
2328 }
2329 }
2330
2331 writel(HA_MBATT, phba->HAregaddr);
2332 readl(phba->HAregaddr); /* flush */
2333
2334 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2335 status = mb->mbxStatus;
2336 }
2337
2338 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2339 return (status);
2340}
2341
2342static int
2343lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2344 struct lpfc_iocbq * piocb)
2345{
2346 /* Insert the caller's iocb in the txq tail for later processing. */
2347 list_add_tail(&piocb->list, &pring->txq);
2348 pring->txq_cnt++;
2349 return (0);
2350}
2351
2352static struct lpfc_iocbq *
2353lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2354 struct lpfc_iocbq ** piocb)
2355{
2356 struct lpfc_iocbq * nextiocb;
2357
2358 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2359 if (!nextiocb) {
2360 nextiocb = *piocb;
2361 *piocb = NULL;
2362 }
2363
2364 return nextiocb;
2365}
2366
2367int
2368lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2369 struct lpfc_iocbq *piocb, uint32_t flag)
2370{
2371 struct lpfc_iocbq *nextiocb;
2372 IOCB_t *iocb;
2373
Linas Vepstas8d63f372007-02-14 14:28:36 -06002374 /* If the PCI channel is in offline state, do not post iocbs. */
2375 if (unlikely(pci_channel_offline(phba->pcidev)))
2376 return IOCB_ERROR;
2377
dea31012005-04-17 16:05:31 -05002378 /*
2379 * We should never get an IOCB if we are in a < LINK_DOWN state
2380 */
2381 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
2382 return IOCB_ERROR;
2383
2384 /*
2385 * Check to see if we are blocking IOCB processing because of a
2386 * outstanding mbox command.
2387 */
2388 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2389 goto iocb_busy;
2390
2391 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
2392 /*
2393 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
2394 * can be issued if the link is not up.
2395 */
2396 switch (piocb->iocb.ulpCommand) {
2397 case CMD_QUE_RING_BUF_CN:
2398 case CMD_QUE_RING_BUF64_CN:
dea31012005-04-17 16:05:31 -05002399 /*
2400 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2401 * completion, iocb_cmpl MUST be 0.
2402 */
2403 if (piocb->iocb_cmpl)
2404 piocb->iocb_cmpl = NULL;
2405 /*FALLTHROUGH*/
2406 case CMD_CREATE_XRI_CR:
2407 break;
2408 default:
2409 goto iocb_busy;
2410 }
2411
2412 /*
2413 * For FCP commands, we must be in a state where we can process link
2414 * attention events.
2415 */
2416 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2417 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2418 goto iocb_busy;
2419
dea31012005-04-17 16:05:31 -05002420 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2421 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2422 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2423
2424 if (iocb)
2425 lpfc_sli_update_ring(phba, pring);
2426 else
2427 lpfc_sli_update_full_ring(phba, pring);
2428
2429 if (!piocb)
2430 return IOCB_SUCCESS;
2431
2432 goto out_busy;
2433
2434 iocb_busy:
2435 pring->stats.iocb_cmd_delay++;
2436
2437 out_busy:
2438
2439 if (!(flag & SLI_IOCB_RET_IOCB)) {
2440 lpfc_sli_ringtx_put(phba, pring, piocb);
2441 return IOCB_SUCCESS;
2442 }
2443
2444 return IOCB_BUSY;
2445}
2446
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002447static int
2448lpfc_extra_ring_setup( struct lpfc_hba *phba)
2449{
2450 struct lpfc_sli *psli;
2451 struct lpfc_sli_ring *pring;
2452
2453 psli = &phba->sli;
2454
2455 /* Adjust cmd/rsp ring iocb entries more evenly */
James Smarta4bc3372006-12-02 13:34:16 -05002456
2457 /* Take some away from the FCP ring */
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002458 pring = &psli->ring[psli->fcp_ring];
2459 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2460 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2461 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2462 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2463
James Smarta4bc3372006-12-02 13:34:16 -05002464 /* and give them to the extra ring */
2465 pring = &psli->ring[psli->extra_ring];
2466
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002467 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2468 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2469 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2470 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2471
2472 /* Setup default profile for this ring */
2473 pring->iotag_max = 4096;
2474 pring->num_mask = 1;
2475 pring->prt[0].profile = 0; /* Mask 0 */
James Smarta4bc3372006-12-02 13:34:16 -05002476 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2477 pring->prt[0].type = phba->cfg_multi_ring_type;
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002478 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2479 return 0;
2480}
2481
dea31012005-04-17 16:05:31 -05002482int
2483lpfc_sli_setup(struct lpfc_hba *phba)
2484{
2485 int i, totiocb = 0;
2486 struct lpfc_sli *psli = &phba->sli;
2487 struct lpfc_sli_ring *pring;
2488
2489 psli->num_rings = MAX_CONFIGURED_RINGS;
2490 psli->sli_flag = 0;
2491 psli->fcp_ring = LPFC_FCP_RING;
2492 psli->next_ring = LPFC_FCP_NEXT_RING;
James Smarta4bc3372006-12-02 13:34:16 -05002493 psli->extra_ring = LPFC_EXTRA_RING;
dea31012005-04-17 16:05:31 -05002494
James Bottomley604a3e32005-10-29 10:28:33 -05002495 psli->iocbq_lookup = NULL;
2496 psli->iocbq_lookup_len = 0;
2497 psli->last_iotag = 0;
2498
dea31012005-04-17 16:05:31 -05002499 for (i = 0; i < psli->num_rings; i++) {
2500 pring = &psli->ring[i];
2501 switch (i) {
2502 case LPFC_FCP_RING: /* ring 0 - FCP */
2503 /* numCiocb and numRiocb are used in config_port */
2504 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
2505 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
2506 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2507 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2508 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2509 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2510 pring->iotag_ctr = 0;
2511 pring->iotag_max =
2512 (phba->cfg_hba_queue_depth * 2);
2513 pring->fast_iotag = pring->iotag_max;
2514 pring->num_mask = 0;
2515 break;
James Smarta4bc3372006-12-02 13:34:16 -05002516 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
dea31012005-04-17 16:05:31 -05002517 /* numCiocb and numRiocb are used in config_port */
2518 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2519 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2520 pring->num_mask = 0;
2521 break;
2522 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
2523 /* numCiocb and numRiocb are used in config_port */
2524 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2525 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2526 pring->fast_iotag = 0;
2527 pring->iotag_ctr = 0;
2528 pring->iotag_max = 4096;
2529 pring->num_mask = 4;
2530 pring->prt[0].profile = 0; /* Mask 0 */
2531 pring->prt[0].rctl = FC_ELS_REQ;
2532 pring->prt[0].type = FC_ELS_DATA;
2533 pring->prt[0].lpfc_sli_rcv_unsol_event =
2534 lpfc_els_unsol_event;
2535 pring->prt[1].profile = 0; /* Mask 1 */
2536 pring->prt[1].rctl = FC_ELS_RSP;
2537 pring->prt[1].type = FC_ELS_DATA;
2538 pring->prt[1].lpfc_sli_rcv_unsol_event =
2539 lpfc_els_unsol_event;
2540 pring->prt[2].profile = 0; /* Mask 2 */
2541 /* NameServer Inquiry */
2542 pring->prt[2].rctl = FC_UNSOL_CTL;
2543 /* NameServer */
2544 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
2545 pring->prt[2].lpfc_sli_rcv_unsol_event =
2546 lpfc_ct_unsol_event;
2547 pring->prt[3].profile = 0; /* Mask 3 */
2548 /* NameServer response */
2549 pring->prt[3].rctl = FC_SOL_CTL;
2550 /* NameServer */
2551 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
2552 pring->prt[3].lpfc_sli_rcv_unsol_event =
2553 lpfc_ct_unsol_event;
2554 break;
2555 }
2556 totiocb += (pring->numCiocb + pring->numRiocb);
2557 }
2558 if (totiocb > MAX_SLI2_IOCB) {
2559 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2560 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2561 "%d:0462 Too many cmd / rsp ring entries in "
2562 "SLI2 SLIM Data: x%x x%x\n",
2563 phba->brd_no, totiocb, MAX_SLI2_IOCB);
2564 }
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002565 if (phba->cfg_multi_ring_support == 2)
2566 lpfc_extra_ring_setup(phba);
dea31012005-04-17 16:05:31 -05002567
2568 return 0;
2569}
2570
2571int
2572lpfc_sli_queue_setup(struct lpfc_hba * phba)
2573{
2574 struct lpfc_sli *psli;
2575 struct lpfc_sli_ring *pring;
James Bottomley604a3e32005-10-29 10:28:33 -05002576 int i;
dea31012005-04-17 16:05:31 -05002577
2578 psli = &phba->sli;
2579 spin_lock_irq(phba->host->host_lock);
2580 INIT_LIST_HEAD(&psli->mboxq);
2581 /* Initialize list headers for txq and txcmplq as double linked lists */
2582 for (i = 0; i < psli->num_rings; i++) {
2583 pring = &psli->ring[i];
2584 pring->ringno = i;
2585 pring->next_cmdidx = 0;
2586 pring->local_getidx = 0;
2587 pring->cmdidx = 0;
2588 INIT_LIST_HEAD(&pring->txq);
2589 INIT_LIST_HEAD(&pring->txcmplq);
2590 INIT_LIST_HEAD(&pring->iocb_continueq);
2591 INIT_LIST_HEAD(&pring->postbufq);
dea31012005-04-17 16:05:31 -05002592 }
2593 spin_unlock_irq(phba->host->host_lock);
2594 return (1);
2595}
2596
2597int
2598lpfc_sli_hba_down(struct lpfc_hba * phba)
2599{
2600 struct lpfc_sli *psli;
2601 struct lpfc_sli_ring *pring;
2602 LPFC_MBOXQ_t *pmb;
2603 struct lpfc_iocbq *iocb, *next_iocb;
2604 IOCB_t *icmd = NULL;
2605 int i;
2606 unsigned long flags = 0;
2607
2608 psli = &phba->sli;
2609 lpfc_hba_down_prep(phba);
2610
2611 spin_lock_irqsave(phba->host->host_lock, flags);
2612
2613 for (i = 0; i < psli->num_rings; i++) {
2614 pring = &psli->ring[i];
2615 pring->flag |= LPFC_DEFERRED_RING_EVENT;
2616
2617 /*
2618 * Error everything on the txq since these iocbs have not been
2619 * given to the FW yet.
2620 */
2621 pring->txq_cnt = 0;
2622
2623 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2624 list_del_init(&iocb->list);
2625 if (iocb->iocb_cmpl) {
2626 icmd = &iocb->iocb;
2627 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2628 icmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2629 spin_unlock_irqrestore(phba->host->host_lock,
2630 flags);
2631 (iocb->iocb_cmpl) (phba, iocb, iocb);
2632 spin_lock_irqsave(phba->host->host_lock, flags);
James Bottomley604a3e32005-10-29 10:28:33 -05002633 } else
2634 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002635 }
2636
2637 INIT_LIST_HEAD(&(pring->txq));
2638
dea31012005-04-17 16:05:31 -05002639 }
2640
2641 spin_unlock_irqrestore(phba->host->host_lock, flags);
2642
2643 /* Return any active mbox cmds */
2644 del_timer_sync(&psli->mbox_tmo);
2645 spin_lock_irqsave(phba->host->host_lock, flags);
2646 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2647 if (psli->mbox_active) {
2648 pmb = psli->mbox_active;
2649 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2650 if (pmb->mbox_cmpl) {
2651 spin_unlock_irqrestore(phba->host->host_lock, flags);
2652 pmb->mbox_cmpl(phba,pmb);
2653 spin_lock_irqsave(phba->host->host_lock, flags);
2654 }
2655 }
2656 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2657 psli->mbox_active = NULL;
2658
2659 /* Return any pending mbox cmds */
2660 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
2661 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2662 if (pmb->mbox_cmpl) {
2663 spin_unlock_irqrestore(phba->host->host_lock, flags);
2664 pmb->mbox_cmpl(phba,pmb);
2665 spin_lock_irqsave(phba->host->host_lock, flags);
2666 }
2667 }
2668
2669 INIT_LIST_HEAD(&psli->mboxq);
2670
2671 spin_unlock_irqrestore(phba->host->host_lock, flags);
2672
dea31012005-04-17 16:05:31 -05002673 return 1;
2674}
2675
2676void
2677lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
2678{
2679 uint32_t *src = srcp;
2680 uint32_t *dest = destp;
2681 uint32_t ldata;
2682 int i;
2683
2684 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
2685 ldata = *src;
2686 ldata = le32_to_cpu(ldata);
2687 *dest = ldata;
2688 src++;
2689 dest++;
2690 }
2691}
2692
2693int
2694lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2695 struct lpfc_dmabuf * mp)
2696{
2697 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2698 later */
2699 list_add_tail(&mp->list, &pring->postbufq);
2700
2701 pring->postbufq_cnt++;
2702 return 0;
2703}
2704
2705
2706struct lpfc_dmabuf *
2707lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2708 dma_addr_t phys)
2709{
2710 struct lpfc_dmabuf *mp, *next_mp;
2711 struct list_head *slp = &pring->postbufq;
2712
2713 /* Search postbufq, from the begining, looking for a match on phys */
2714 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
2715 if (mp->phys == phys) {
2716 list_del_init(&mp->list);
2717 pring->postbufq_cnt--;
2718 return mp;
2719 }
2720 }
2721
2722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2723 "%d:0410 Cannot find virtual addr for mapped buf on "
2724 "ring %d Data x%llx x%p x%p x%x\n",
2725 phba->brd_no, pring->ringno, (unsigned long long)phys,
2726 slp->next, slp->prev, pring->postbufq_cnt);
2727 return NULL;
2728}
2729
2730static void
2731lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2732 struct lpfc_iocbq * rspiocb)
2733{
2734 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2735 /* Free the resources associated with the ELS_REQUEST64 IOCB the driver
2736 * just aborted.
2737 * In this case, context2 = cmd, context2->next = rsp, context3 = bpl
2738 */
2739 if (cmdiocb->context2) {
2740 buf_ptr1 = (struct lpfc_dmabuf *) cmdiocb->context2;
2741
2742 /* Free the response IOCB before completing the abort
2743 command. */
2744 buf_ptr = NULL;
2745 list_remove_head((&buf_ptr1->list), buf_ptr,
2746 struct lpfc_dmabuf, list);
2747 if (buf_ptr) {
2748 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2749 kfree(buf_ptr);
2750 }
2751 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2752 kfree(buf_ptr1);
2753 }
2754
2755 if (cmdiocb->context3) {
2756 buf_ptr = (struct lpfc_dmabuf *) cmdiocb->context3;
2757 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2758 kfree(buf_ptr);
2759 }
2760
James Bottomley604a3e32005-10-29 10:28:33 -05002761 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05002762 return;
2763}
2764
2765int
2766lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
2767 struct lpfc_sli_ring * pring,
2768 struct lpfc_iocbq * cmdiocb)
2769{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002770 struct lpfc_iocbq *abtsiocbp;
dea31012005-04-17 16:05:31 -05002771 IOCB_t *icmd = NULL;
2772 IOCB_t *iabt = NULL;
2773
2774 /* issue ABTS for this IOCB based on iotag */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002775 abtsiocbp = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002776 if (abtsiocbp == NULL)
2777 return 0;
dea31012005-04-17 16:05:31 -05002778
2779 iabt = &abtsiocbp->iocb;
2780 icmd = &cmdiocb->iocb;
2781 switch (icmd->ulpCommand) {
2782 case CMD_ELS_REQUEST64_CR:
2783 /* Even though we abort the ELS command, the firmware may access
2784 * the BPL or other resources before it processes our
2785 * ABORT_MXRI64. Thus we must delay reusing the cmdiocb
2786 * resources till the actual abort request completes.
2787 */
2788 abtsiocbp->context1 = (void *)((unsigned long)icmd->ulpCommand);
2789 abtsiocbp->context2 = cmdiocb->context2;
2790 abtsiocbp->context3 = cmdiocb->context3;
2791 cmdiocb->context2 = NULL;
2792 cmdiocb->context3 = NULL;
2793 abtsiocbp->iocb_cmpl = lpfc_sli_abort_elsreq_cmpl;
2794 break;
2795 default:
James Bottomley604a3e32005-10-29 10:28:33 -05002796 lpfc_sli_release_iocbq(phba, abtsiocbp);
dea31012005-04-17 16:05:31 -05002797 return 0;
2798 }
2799
2800 iabt->un.amxri.abortType = ABORT_TYPE_ABTS;
2801 iabt->un.amxri.iotag32 = icmd->un.elsreq64.bdl.ulpIoTag32;
2802
2803 iabt->ulpLe = 1;
2804 iabt->ulpClass = CLASS3;
2805 iabt->ulpCommand = CMD_ABORT_MXRI64_CN;
2806
2807 if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -05002808 lpfc_sli_release_iocbq(phba, abtsiocbp);
dea31012005-04-17 16:05:31 -05002809 return 0;
2810 }
2811
2812 return 1;
2813}
2814
2815static int
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002816lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
2817 uint64_t lun_id, uint32_t ctx,
2818 lpfc_ctx_cmd ctx_cmd)
dea31012005-04-17 16:05:31 -05002819{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002820 struct lpfc_scsi_buf *lpfc_cmd;
2821 struct scsi_cmnd *cmnd;
dea31012005-04-17 16:05:31 -05002822 int rc = 1;
2823
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002824 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
2825 return rc;
2826
2827 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
2828 cmnd = lpfc_cmd->pCmd;
2829
2830 if (cmnd == NULL)
dea31012005-04-17 16:05:31 -05002831 return rc;
2832
2833 switch (ctx_cmd) {
2834 case LPFC_CTX_LUN:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002835 if ((cmnd->device->id == tgt_id) &&
2836 (cmnd->device->lun == lun_id))
dea31012005-04-17 16:05:31 -05002837 rc = 0;
2838 break;
2839 case LPFC_CTX_TGT:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002840 if (cmnd->device->id == tgt_id)
dea31012005-04-17 16:05:31 -05002841 rc = 0;
2842 break;
2843 case LPFC_CTX_CTX:
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002844 if (iocbq->iocb.ulpContext == ctx)
dea31012005-04-17 16:05:31 -05002845 rc = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002846 break;
dea31012005-04-17 16:05:31 -05002847 case LPFC_CTX_HOST:
2848 rc = 0;
2849 break;
2850 default:
2851 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
2852 __FUNCTION__, ctx_cmd);
2853 break;
2854 }
2855
2856 return rc;
2857}
2858
2859int
2860lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2861 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
2862{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002863 struct lpfc_iocbq *iocbq;
2864 int sum, i;
dea31012005-04-17 16:05:31 -05002865
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002866 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
2867 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05002868
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002869 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2870 0, ctx_cmd) == 0)
2871 sum++;
dea31012005-04-17 16:05:31 -05002872 }
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002873
dea31012005-04-17 16:05:31 -05002874 return sum;
2875}
2876
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04002877void
2878lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2879 struct lpfc_iocbq * rspiocb)
2880{
2881 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05002882 lpfc_sli_release_iocbq(phba, cmdiocb);
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04002883 spin_unlock_irq(phba->host->host_lock);
2884 return;
2885}
2886
dea31012005-04-17 16:05:31 -05002887int
2888lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2889 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
2890 lpfc_ctx_cmd abort_cmd)
2891{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002892 struct lpfc_iocbq *iocbq;
2893 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05002894 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05002895 int errcnt = 0, ret_val = 0;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002896 int i;
dea31012005-04-17 16:05:31 -05002897
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002898 for (i = 1; i <= phba->sli.last_iotag; i++) {
2899 iocbq = phba->sli.iocbq_lookup[i];
dea31012005-04-17 16:05:31 -05002900
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002901 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2902 0, abort_cmd) != 0)
dea31012005-04-17 16:05:31 -05002903 continue;
2904
2905 /* issue ABTS for this IOCB based on iotag */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002906 abtsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002907 if (abtsiocb == NULL) {
2908 errcnt++;
2909 continue;
2910 }
dea31012005-04-17 16:05:31 -05002911
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002912 cmd = &iocbq->iocb;
dea31012005-04-17 16:05:31 -05002913 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
2914 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
2915 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
2916 abtsiocb->iocb.ulpLe = 1;
2917 abtsiocb->iocb.ulpClass = cmd->ulpClass;
2918
2919 if (phba->hba_state >= LPFC_LINK_UP)
2920 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
2921 else
2922 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
2923
James.Smart@Emulex.Com5eb95af2005-06-25 10:34:30 -04002924 /* Setup callback routine and issue the command. */
2925 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
dea31012005-04-17 16:05:31 -05002926 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
2927 if (ret_val == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -05002928 lpfc_sli_release_iocbq(phba, abtsiocb);
dea31012005-04-17 16:05:31 -05002929 errcnt++;
2930 continue;
2931 }
2932 }
2933
2934 return errcnt;
2935}
2936
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002937static void
2938lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
2939 struct lpfc_iocbq *cmdiocbq,
2940 struct lpfc_iocbq *rspiocbq)
dea31012005-04-17 16:05:31 -05002941{
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002942 wait_queue_head_t *pdone_q;
2943 unsigned long iflags;
dea31012005-04-17 16:05:31 -05002944
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002945 spin_lock_irqsave(phba->host->host_lock, iflags);
2946 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
2947 if (cmdiocbq->context2 && rspiocbq)
2948 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
2949 &rspiocbq->iocb, sizeof(IOCB_t));
2950
2951 pdone_q = cmdiocbq->context_un.wait_queue;
2952 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2953 if (pdone_q)
2954 wake_up(pdone_q);
dea31012005-04-17 16:05:31 -05002955 return;
2956}
2957
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002958/*
2959 * Issue the caller's iocb and wait for its completion, but no longer than the
2960 * caller's timeout. Note that iocb_flags is cleared before the
2961 * lpfc_sli_issue_call since the wake routine sets a unique value and by
2962 * definition this is a wait function.
2963 */
dea31012005-04-17 16:05:31 -05002964int
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002965lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
2966 struct lpfc_sli_ring * pring,
2967 struct lpfc_iocbq * piocb,
2968 struct lpfc_iocbq * prspiocbq,
2969 uint32_t timeout)
dea31012005-04-17 16:05:31 -05002970{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08002971 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002972 long timeleft, timeout_req = 0;
2973 int retval = IOCB_SUCCESS;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002974 uint32_t creg_val;
dea31012005-04-17 16:05:31 -05002975
2976 /*
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002977 * If the caller has provided a response iocbq buffer, then context2
2978 * is NULL or its an error.
dea31012005-04-17 16:05:31 -05002979 */
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002980 if (prspiocbq) {
2981 if (piocb->context2)
2982 return IOCB_ERROR;
2983 piocb->context2 = prspiocbq;
dea31012005-04-17 16:05:31 -05002984 }
2985
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002986 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
2987 piocb->context_un.wait_queue = &done_q;
2988 piocb->iocb_flag &= ~LPFC_IO_WAKE;
dea31012005-04-17 16:05:31 -05002989
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002990 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2991 creg_val = readl(phba->HCregaddr);
2992 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2993 writel(creg_val, phba->HCregaddr);
2994 readl(phba->HCregaddr); /* flush */
2995 }
2996
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04002997 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
2998 if (retval == IOCB_SUCCESS) {
2999 timeout_req = timeout * HZ;
3000 spin_unlock_irq(phba->host->host_lock);
3001 timeleft = wait_event_timeout(done_q,
3002 piocb->iocb_flag & LPFC_IO_WAKE,
3003 timeout_req);
3004 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003005
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003006 if (timeleft == 0) {
3007 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smartdca94792006-08-01 07:34:08 -04003008 "%d:0338 IOCB wait timeout error - no "
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003009 "wake response Data x%x\n",
3010 phba->brd_no, timeout);
3011 retval = IOCB_TIMEDOUT;
3012 } else if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
3013 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3014 "%d:0330 IOCB wake NOT set, "
3015 "Data x%x x%lx\n", phba->brd_no,
3016 timeout, (timeleft / jiffies));
3017 retval = IOCB_TIMEDOUT;
3018 } else {
3019 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3020 "%d:0331 IOCB wake signaled\n",
3021 phba->brd_no);
dea31012005-04-17 16:05:31 -05003022 }
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003023 } else {
3024 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3025 "%d:0332 IOCB wait issue failed, Data x%x\n",
3026 phba->brd_no, retval);
3027 retval = IOCB_ERROR;
dea31012005-04-17 16:05:31 -05003028 }
3029
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003030 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3031 creg_val = readl(phba->HCregaddr);
3032 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3033 writel(creg_val, phba->HCregaddr);
3034 readl(phba->HCregaddr); /* flush */
3035 }
3036
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003037 if (prspiocbq)
3038 piocb->context2 = NULL;
3039
3040 piocb->context_un.wait_queue = NULL;
3041 piocb->iocb_cmpl = NULL;
dea31012005-04-17 16:05:31 -05003042 return retval;
3043}
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -04003044
dea31012005-04-17 16:05:31 -05003045int
3046lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3047 uint32_t timeout)
3048{
Peter Zijlstra7259f0d2006-10-29 22:46:36 -08003049 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
dea31012005-04-17 16:05:31 -05003050 DECLARE_WAITQUEUE(wq_entry, current);
3051 uint32_t timeleft = 0;
3052 int retval;
3053
3054 /* The caller must leave context1 empty. */
3055 if (pmboxq->context1 != 0) {
3056 return (MBX_NOT_FINISHED);
3057 }
3058
3059 /* setup wake call as IOCB callback */
3060 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3061 /* setup context field to pass wait_queue pointer to wake function */
3062 pmboxq->context1 = &done_q;
3063
3064 /* start to sleep before we wait, to avoid races */
3065 set_current_state(TASK_INTERRUPTIBLE);
3066 add_wait_queue(&done_q, &wq_entry);
3067
3068 /* now issue the command */
3069 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3070
3071 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3072 timeleft = schedule_timeout(timeout * HZ);
3073 pmboxq->context1 = NULL;
3074 /* if schedule_timeout returns 0, we timed out and were not
3075 woken up */
Jamie Wellnitz406d6042006-02-28 19:25:20 -05003076 if ((timeleft == 0) || signal_pending(current))
dea31012005-04-17 16:05:31 -05003077 retval = MBX_TIMEOUT;
Jamie Wellnitz406d6042006-02-28 19:25:20 -05003078 else
dea31012005-04-17 16:05:31 -05003079 retval = MBX_SUCCESS;
dea31012005-04-17 16:05:31 -05003080 }
3081
3082
3083 set_current_state(TASK_RUNNING);
3084 remove_wait_queue(&done_q, &wq_entry);
3085 return retval;
3086}
3087
James Smartb4c02652006-07-06 15:50:43 -04003088int
3089lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3090{
3091 int i = 0;
3092
3093 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
3094 if (i++ > LPFC_MBOX_TMO * 1000)
3095 return 1;
3096
3097 if (lpfc_sli_handle_mb_event(phba) == 0)
3098 i = 0;
3099
3100 msleep(1);
3101 }
3102
3103 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3104}
3105
dea31012005-04-17 16:05:31 -05003106irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003107lpfc_intr_handler(int irq, void *dev_id)
dea31012005-04-17 16:05:31 -05003108{
3109 struct lpfc_hba *phba;
3110 uint32_t ha_copy;
3111 uint32_t work_ha_copy;
3112 unsigned long status;
3113 int i;
3114 uint32_t control;
3115
3116 /*
3117 * Get the driver's phba structure from the dev_id and
3118 * assume the HBA is not interrupting.
3119 */
3120 phba = (struct lpfc_hba *) dev_id;
3121
3122 if (unlikely(!phba))
3123 return IRQ_NONE;
3124
Linas Vepstas8d63f372007-02-14 14:28:36 -06003125 /* If the pci channel is offline, ignore all the interrupts. */
3126 if (unlikely(pci_channel_offline(phba->pcidev)))
3127 return IRQ_NONE;
3128
dea31012005-04-17 16:05:31 -05003129 phba->sli.slistat.sli_intr++;
3130
3131 /*
3132 * Call the HBA to see if it is interrupting. If not, don't claim
3133 * the interrupt
3134 */
3135
3136 /* Ignore all interrupts during initialization. */
3137 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
3138 return IRQ_NONE;
3139
3140 /*
3141 * Read host attention register to determine interrupt source
3142 * Clear Attention Sources, except Error Attention (to
3143 * preserve status) and Link Attention
3144 */
3145 spin_lock(phba->host->host_lock);
3146 ha_copy = readl(phba->HAregaddr);
3147 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3148 readl(phba->HAregaddr); /* flush */
3149 spin_unlock(phba->host->host_lock);
3150
3151 if (unlikely(!ha_copy))
3152 return IRQ_NONE;
3153
3154 work_ha_copy = ha_copy & phba->work_ha_mask;
3155
3156 if (unlikely(work_ha_copy)) {
3157 if (work_ha_copy & HA_LATT) {
3158 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3159 /*
3160 * Turn off Link Attention interrupts
3161 * until CLEAR_LA done
3162 */
3163 spin_lock(phba->host->host_lock);
3164 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3165 control = readl(phba->HCregaddr);
3166 control &= ~HC_LAINT_ENA;
3167 writel(control, phba->HCregaddr);
3168 readl(phba->HCregaddr); /* flush */
3169 spin_unlock(phba->host->host_lock);
3170 }
3171 else
3172 work_ha_copy &= ~HA_LATT;
3173 }
3174
3175 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3176 for (i = 0; i < phba->sli.num_rings; i++) {
3177 if (work_ha_copy & (HA_RXATT << (4*i))) {
3178 /*
3179 * Turn off Slow Rings interrupts
3180 */
3181 spin_lock(phba->host->host_lock);
3182 control = readl(phba->HCregaddr);
3183 control &= ~(HC_R0INT_ENA << i);
3184 writel(control, phba->HCregaddr);
3185 readl(phba->HCregaddr); /* flush */
3186 spin_unlock(phba->host->host_lock);
3187 }
3188 }
3189 }
3190
3191 if (work_ha_copy & HA_ERATT) {
3192 phba->hba_state = LPFC_HBA_ERROR;
3193 /*
3194 * There was a link/board error. Read the
3195 * status register to retrieve the error event
3196 * and process it.
3197 */
3198 phba->sli.slistat.err_attn_event++;
3199 /* Save status info */
3200 phba->work_hs = readl(phba->HSregaddr);
3201 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3202 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3203
3204 /* Clear Chip error bit */
3205 writel(HA_ERATT, phba->HAregaddr);
3206 readl(phba->HAregaddr); /* flush */
James Smart92908312006-03-07 15:04:13 -05003207 phba->stopped = 1;
dea31012005-04-17 16:05:31 -05003208 }
3209
3210 spin_lock(phba->host->host_lock);
3211 phba->work_ha |= work_ha_copy;
3212 if (phba->work_wait)
3213 wake_up(phba->work_wait);
3214 spin_unlock(phba->host->host_lock);
3215 }
3216
3217 ha_copy &= ~(phba->work_ha_mask);
3218
3219 /*
3220 * Process all events on FCP ring. Take the optimized path for
3221 * FCP IO. Any other IO is slow path and is handled by
3222 * the worker thread.
3223 */
3224 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3225 status >>= (4*LPFC_FCP_RING);
3226 if (status & HA_RXATT)
3227 lpfc_sli_handle_fast_ring_event(phba,
3228 &phba->sli.ring[LPFC_FCP_RING],
3229 status);
James Smarta4bc3372006-12-02 13:34:16 -05003230
3231 if (phba->cfg_multi_ring_support == 2) {
3232 /*
3233 * Process all events on extra ring. Take the optimized path
3234 * for extra ring IO. Any other IO is slow path and is handled
3235 * by the worker thread.
3236 */
3237 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
3238 status >>= (4*LPFC_EXTRA_RING);
3239 if (status & HA_RXATT) {
3240 lpfc_sli_handle_fast_ring_event(phba,
3241 &phba->sli.ring[LPFC_EXTRA_RING],
3242 status);
3243 }
3244 }
dea31012005-04-17 16:05:31 -05003245 return IRQ_HANDLED;
3246
3247} /* lpfc_intr_handler */