Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / scsi / lpfc / lpfc_sli.c
index 8d14b28..bb69a7a 100644 (file)
@@ -1,35 +1,34 @@
 /*******************************************************************
  * This file is part of the Emulex Linux Device Driver for         *
- * Enterprise Fibre Channel Host Bus Adapters.                     *
- * Refer to the README file included with this package for         *
- * driver version and adapter support.                             *
- * Copyright (C) 2004 Emulex Corporation.                          *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2004-2006 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
  * www.emulex.com                                                  *
+ * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
  *                                                                 *
  * This program is free software; you can redistribute it and/or   *
- * modify it under the terms of the GNU General Public License     *
- * as published by the Free Software Foundation; either version 2  *
- * of the License, or (at your option) any later version.          *
- *                                                                 *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of  *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
- * GNU General Public License for more details, a copy of which    *
- * can be found in the file COPYING included with this package.    *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
  *******************************************************************/
 
-/*
- * $Id: lpfc_sli.c 1.232 2005/04/13 11:59:16EDT sf_support Exp  $
- */
-
 #include <linux/blkdev.h>
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 
+#include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_transport_fc.h>
 
 #include "lpfc_hw.h"
 #include "lpfc_sli.h"
@@ -66,6 +65,28 @@ typedef enum _lpfc_iocb_type {
        LPFC_ABORT_IOCB
 } lpfc_iocb_type;
 
+struct lpfc_iocbq *
+lpfc_sli_get_iocbq(struct lpfc_hba * phba)
+{
+       struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
+       struct lpfc_iocbq * iocbq = NULL;
+
+       list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
+       return iocbq;
+}
+
+void
+lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
+{
+       size_t start_clean = (size_t)(&((struct lpfc_iocbq *)NULL)->iocb);
+
+       /*
+        * Clean all volatile data fields, preserve iotag and node struct.
+        */
+       memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
+       list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
+}
+
 /*
  * Translate the iocb command to an iocb command type used to decide the final
  * disposition of each completed IOCB.
@@ -225,8 +246,7 @@ lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
 static IOCB_t *
 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
 {
-       MAILBOX_t *mbox = (MAILBOX_t *)phba->sli.MBhostaddr;
-       PGP *pgp = (PGP *)&mbox->us.s2.port[pring->ringno];
+       struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
        uint32_t  max_cmd_idx = pring->numCiocb;
        IOCB_t *iocb = NULL;
 
@@ -267,41 +287,69 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
        return iocb;
 }
 
-static uint32_t
-lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
+uint16_t
+lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
 {
-       uint32_t search_start;
+       struct lpfc_iocbq ** new_arr;
+       struct lpfc_iocbq ** old_arr;
+       size_t new_len;
+       struct lpfc_sli *psli = &phba->sli;
+       uint16_t iotag;
 
-       if (pring->fast_lookup == NULL) {
-               pring->iotag_ctr++;
-               if (pring->iotag_ctr >= pring->iotag_max)
-                       pring->iotag_ctr = 1;
-               return pring->iotag_ctr;
+       spin_lock_irq(phba->host->host_lock);
+       iotag = psli->last_iotag;
+       if(++iotag < psli->iocbq_lookup_len) {
+               psli->last_iotag = iotag;
+               psli->iocbq_lookup[iotag] = iocbq;
+               spin_unlock_irq(phba->host->host_lock);
+               iocbq->iotag = iotag;
+               return iotag;
+       }
+       else if (psli->iocbq_lookup_len < (0xffff
+                                          - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
+               new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
+               spin_unlock_irq(phba->host->host_lock);
+               new_arr = kmalloc(new_len * sizeof (struct lpfc_iocbq *),
+                                 GFP_KERNEL);
+               if (new_arr) {
+                       memset((char *)new_arr, 0,
+                              new_len * sizeof (struct lpfc_iocbq *));
+                       spin_lock_irq(phba->host->host_lock);
+                       old_arr = psli->iocbq_lookup;
+                       if (new_len <= psli->iocbq_lookup_len) {
+                               /* highly unprobable case */
+                               kfree(new_arr);
+                               iotag = psli->last_iotag;
+                               if(++iotag < psli->iocbq_lookup_len) {
+                                       psli->last_iotag = iotag;
+                                       psli->iocbq_lookup[iotag] = iocbq;
+                                       spin_unlock_irq(phba->host->host_lock);
+                                       iocbq->iotag = iotag;
+                                       return iotag;
+                               }
+                               spin_unlock_irq(phba->host->host_lock);
+                               return 0;
+                       }
+                       if (psli->iocbq_lookup)
+                               memcpy(new_arr, old_arr,
+                                      ((psli->last_iotag  + 1) *
+                                       sizeof (struct lpfc_iocbq *)));
+                       psli->iocbq_lookup = new_arr;
+                       psli->iocbq_lookup_len = new_len;
+                       psli->last_iotag = iotag;
+                       psli->iocbq_lookup[iotag] = iocbq;
+                       spin_unlock_irq(phba->host->host_lock);
+                       iocbq->iotag = iotag;
+                       kfree(old_arr);
+                       return iotag;
+               }
        }
 
-       search_start = pring->iotag_ctr;
-
-       do {
-               pring->iotag_ctr++;
-               if (pring->iotag_ctr >= pring->fast_iotag)
-                       pring->iotag_ctr = 1;
-
-               if (*(pring->fast_lookup + pring->iotag_ctr) == NULL)
-                       return pring->iotag_ctr;
-
-       } while (pring->iotag_ctr != search_start);
+       lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
+                       "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
+                       phba->brd_no, psli->last_iotag);
 
-       /*
-        * Outstanding I/O count for ring <ringno> is at max <fast_iotag>
-        */
-       lpfc_printf_log(phba,
-               KERN_ERR,
-               LOG_SLI,
-               "%d:0318 Outstanding I/O count for ring %d is at max x%x\n",
-               phba->brd_no,
-               pring->ringno,
-               pring->fast_iotag);
-       return (0);
+       return 0;
 }
 
 static void
@@ -309,10 +357,9 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
 {
        /*
-        * Allocate and set up an iotag
+        * Set up an iotag
         */
-       nextiocb->iocb.ulpIoTag =
-               lpfc_sli_next_iotag(phba, &phba->sli.ring[phba->sli.fcp_ring]);
+       nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
 
        /*
         * Issue iocb command to adapter
@@ -328,16 +375,15 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
         */
        if (nextiocb->iocb_cmpl)
                lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
-       else {
-               list_add_tail(&nextiocb->list, &phba->lpfc_iocb_list);
-       }
+       else
+               lpfc_sli_release_iocbq(phba, nextiocb);
 
        /*
         * Let the HBA know what IOCB slot will be the next one the
         * driver will put a command into.
         */
        pring->cmdidx = pring->next_cmdidx;
-       writeb(pring->cmdidx, phba->MBslimaddr
+       writel(pring->cmdidx, phba->MBslimaddr
               + (SLIMOFF + (pring->ringno * 2)) * 4);
 }
 
@@ -411,9 +457,7 @@ lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
 static void
 lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
 {
-       PGP *pgp =
-               ((PGP *) &
-                (((MAILBOX_t *)phba->sli.MBhostaddr)->us.s2.port[ringno]));
+       struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno];
 
        /* If the ring is active, flag it */
        if (phba->sli.ring[ringno].cmdringaddr) {
@@ -469,7 +513,9 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
        case MBX_SET_MASK:
        case MBX_SET_SLIM:
        case MBX_UNREG_D_ID:
+       case MBX_KILL_BOARD:
        case MBX_CONFIG_FARP:
+       case MBX_BEACON:
        case MBX_LOAD_AREA:
        case MBX_RUN_BIU_DIAG64:
        case MBX_CONFIG_PORT:
@@ -537,7 +583,7 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
        /* Get a Mailbox buffer to setup mailbox commands for callback */
        if ((pmb = phba->sli.mbox_active)) {
                pmbox = &pmb->mb;
-               mbox = (MAILBOX_t *) phba->sli.MBhostaddr;
+               mbox = &phba->slim2p->mbx;
 
                /* First check out the status word */
                lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
@@ -720,7 +766,9 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
        }
        /* unSolicited Responses */
        if (pring->prt[0].profile) {
-               (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, saveq);
+               if (pring->prt[0].lpfc_sli_rcv_unsol_event)
+                       (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
+                                                                       saveq);
                match = 1;
        } else {
                /* We must search, based on rctl / type
@@ -731,8 +779,9 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                             Rctl)
                            && (pring->prt[i].
                                type == Type)) {
-                               (pring->prt[i].lpfc_sli_rcv_unsol_event)
-                                       (phba, pring, saveq);
+                               if (pring->prt[i].lpfc_sli_rcv_unsol_event)
+                                       (pring->prt[i].lpfc_sli_rcv_unsol_event)
+                                                       (phba, pring, saveq);
                                match = 1;
                                break;
                        }
@@ -756,80 +805,28 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
 }
 
 static struct lpfc_iocbq *
-lpfc_sli_txcmpl_ring_search_slow(struct lpfc_sli_ring * pring,
-                                struct lpfc_iocbq * prspiocb)
-{
-       IOCB_t *icmd = NULL;
-       IOCB_t *irsp = NULL;
-       struct lpfc_iocbq *cmd_iocb;
-       struct lpfc_iocbq *iocb, *next_iocb;
-       uint16_t iotag;
-
-       irsp = &prspiocb->iocb;
-       iotag = irsp->ulpIoTag;
-       cmd_iocb = NULL;
-
-       /* Search through txcmpl from the begining */
-       list_for_each_entry_safe(iocb, next_iocb, &(pring->txcmplq), list) {
-               icmd = &iocb->iocb;
-               if (iotag == icmd->ulpIoTag) {
-                       /* Found a match.  */
-                       cmd_iocb = iocb;
-                       list_del(&iocb->list);
-                       pring->txcmplq_cnt--;
-                       break;
-               }
-       }
-
-       return (cmd_iocb);
-}
-
-static struct lpfc_iocbq *
-lpfc_sli_txcmpl_ring_iotag_lookup(struct lpfc_hba * phba,
-                       struct lpfc_sli_ring * pring,
-                       struct lpfc_iocbq * prspiocb)
+lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
+                     struct lpfc_sli_ring * pring,
+                     struct lpfc_iocbq * prspiocb)
 {
-       IOCB_t *irsp = NULL;
        struct lpfc_iocbq *cmd_iocb = NULL;
        uint16_t iotag;
 
-       if (unlikely(pring->fast_lookup == NULL))
-               return NULL;
-
-       /* Use fast lookup based on iotag for completion */
-       irsp = &prspiocb->iocb;
-       iotag = irsp->ulpIoTag;
-       if (iotag < pring->fast_iotag) {
-               cmd_iocb = *(pring->fast_lookup + iotag);
-               *(pring->fast_lookup + iotag) = NULL;
-               if (cmd_iocb) {
-                       list_del(&cmd_iocb->list);
-                       pring->txcmplq_cnt--;
-                       return cmd_iocb;
-               } else {
-                       /*
-                        * This is clearly an error.  A ring that uses iotags
-                        * should never have a interrupt for a completion that
-                        * is not on the ring.  Return NULL and log a error.
-                        */
-                       lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
-                               "%d:0327 Rsp ring %d error -  command "
-                               "completion for iotag x%x not found\n",
-                               phba->brd_no, pring->ringno, iotag);
-                       return NULL;
-               }
+       iotag = prspiocb->iocb.ulpIoTag;
+
+       if (iotag != 0 && iotag <= phba->sli.last_iotag) {
+               cmd_iocb = phba->sli.iocbq_lookup[iotag];
+               list_del(&cmd_iocb->list);
+               pring->txcmplq_cnt--;
+               return cmd_iocb;
        }
 
-       /*
-        * Rsp ring <ringno> get: iotag <iotag> greater then
-        * configured max <fast_iotag> wd0 <irsp>.  This is an
-        * error.  Just return NULL.
-        */
        lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
-                       "%d:0317 Rsp ring %d get: iotag x%x greater then "
-                       "configured max x%x wd0 x%x\n",
-                       phba->brd_no, pring->ringno, iotag, pring->fast_iotag,
-                       *(((uint32_t *) irsp) + 7));
+                       "%d:0317 iotag x%x is out off "
+                       "range: max iotag x%x wd0 x%x\n",
+                       phba->brd_no, iotag,
+                       phba->sli.last_iotag,
+                       *(((uint32_t *) &prspiocb->iocb) + 7));
        return NULL;
 }
 
@@ -843,7 +840,7 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
 
        /* Based on the iotag field, get the cmd IOCB from the txcmplq */
        spin_lock_irqsave(phba->host->host_lock, iflag);
-       cmdiocbp = lpfc_sli_txcmpl_ring_search_slow(pring, saveq);
+       cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
        if (cmdiocbp) {
                if (cmdiocbp->iocb_cmpl) {
                        /*
@@ -857,17 +854,13 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
                                spin_lock_irqsave(phba->host->host_lock, iflag);
                        }
                        else {
-                               if (cmdiocbp->iocb_flag & LPFC_IO_POLL)
-                                       rc = 0;
-
                                spin_unlock_irqrestore(phba->host->host_lock,
                                                       iflag);
                                (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
                                spin_lock_irqsave(phba->host->host_lock, iflag);
                        }
-               } else {
-                       list_add_tail(&cmdiocbp->list, &phba->lpfc_iocb_list);
-               }
+               } else
+                       lpfc_sli_release_iocbq(phba, cmdiocbp);
        } else {
                /*
                 * Unknown initiating command based on the response iotag.
@@ -893,10 +886,187 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
                                saveq->iocb.ulpContext);
                }
        }
+
        spin_unlock_irqrestore(phba->host->host_lock, iflag);
        return rc;
 }
 
+static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
+                                       struct lpfc_sli_ring * pring)
+{
+       struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
+       /*
+        * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
+        * rsp ring <portRspMax>
+        */
+       lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+                       "%d:0312 Ring %d handler: portRspPut %d "
+                       "is bigger then rsp ring %d\n",
+                       phba->brd_no, pring->ringno,
+                       le32_to_cpu(pgp->rspPutInx),
+                       pring->numRiocb);
+
+       phba->hba_state = LPFC_HBA_ERROR;
+
+       /*
+        * All error attention handlers are posted to
+        * worker thread
+        */
+       phba->work_ha |= HA_ERATT;
+       phba->work_hs = HS_FFER3;
+       if (phba->work_wait)
+               wake_up(phba->work_wait);
+
+       return;
+}
+
+void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
+{
+       struct lpfc_sli      * psli   = &phba->sli;
+       struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING];
+       IOCB_t *irsp = NULL;
+       IOCB_t *entry = NULL;
+       struct lpfc_iocbq *cmdiocbq = NULL;
+       struct lpfc_iocbq rspiocbq;
+       struct lpfc_pgp *pgp;
+       uint32_t status;
+       uint32_t portRspPut, portRspMax;
+       int type;
+       uint32_t rsp_cmpl = 0;
+       void __iomem *to_slim;
+       uint32_t ha_copy;
+
+       pring->stats.iocb_event++;
+
+       /* The driver assumes SLI-2 mode */
+       pgp =  &phba->slim2p->mbx.us.s2.port[pring->ringno];
+
+       /*
+        * The next available response entry should never exceed the maximum
+        * entries.  If it does, treat it as an adapter hardware error.
+        */
+       portRspMax = pring->numRiocb;
+       portRspPut = le32_to_cpu(pgp->rspPutInx);
+       if (unlikely(portRspPut >= portRspMax)) {
+               lpfc_sli_rsp_pointers_error(phba, pring);
+               return;
+       }
+
+       rmb();
+       while (pring->rspidx != portRspPut) {
+
+               entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
+
+               if (++pring->rspidx >= portRspMax)
+                       pring->rspidx = 0;
+
+               lpfc_sli_pcimem_bcopy((uint32_t *) entry,
+                                     (uint32_t *) &rspiocbq.iocb,
+                                     sizeof (IOCB_t));
+               irsp = &rspiocbq.iocb;
+               type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
+               pring->stats.iocb_rsp++;
+               rsp_cmpl++;
+
+               if (unlikely(irsp->ulpStatus)) {
+                       /* Rsp ring <ringno> error: IOCB */
+                       lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
+                                       "%d:0326 Rsp Ring %d error: IOCB Data: "
+                                       "x%x x%x x%x x%x x%x x%x x%x x%x\n",
+                                       phba->brd_no, pring->ringno,
+                                       irsp->un.ulpWord[0],
+                                       irsp->un.ulpWord[1],
+                                       irsp->un.ulpWord[2],
+                                       irsp->un.ulpWord[3],
+                                       irsp->un.ulpWord[4],
+                                       irsp->un.ulpWord[5],
+                                       *(((uint32_t *) irsp) + 6),
+                                       *(((uint32_t *) irsp) + 7));
+               }
+
+               switch (type) {
+               case LPFC_ABORT_IOCB:
+               case LPFC_SOL_IOCB:
+                       /*
+                        * Idle exchange closed via ABTS from port.  No iocb
+                        * resources need to be recovered.
+                        */
+                       if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
+                               printk(KERN_INFO "%s: IOCB cmd 0x%x processed."
+                                      " Skipping completion\n", __FUNCTION__,
+                                      irsp->ulpCommand);
+                               break;
+                       }
+
+                       cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
+                                                        &rspiocbq);
+                       if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
+                               (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
+                                                     &rspiocbq);
+                       }
+                       break;
+               default:
+                       if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
+                               char adaptermsg[LPFC_MAX_ADPTMSG];
+                               memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
+                               memcpy(&adaptermsg[0], (uint8_t *) irsp,
+                                      MAX_MSG_DATA);
+                               dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
+                                        phba->brd_no, adaptermsg);
+                       } else {
+                               /* Unknown IOCB command */
+                               lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+                                               "%d:0321 Unknown IOCB command "
+                                               "Data: x%x, x%x x%x x%x x%x\n",
+                                               phba->brd_no, type,
+                                               irsp->ulpCommand,
+                                               irsp->ulpStatus,
+                                               irsp->ulpIoTag,
+                                               irsp->ulpContext);
+                       }
+                       break;
+               }
+
+               /*
+                * The response IOCB has been processed.  Update the ring
+                * pointer in SLIM.  If the port response put pointer has not
+                * been updated, sync the pgp->rspPutInx and fetch the new port
+                * response put pointer.
+                */
+               to_slim = phba->MBslimaddr +
+                       (SLIMOFF + (pring->ringno * 2) + 1) * 4;
+               writeb(pring->rspidx, to_slim);
+
+               if (pring->rspidx == portRspPut)
+                       portRspPut = le32_to_cpu(pgp->rspPutInx);
+       }
+
+       ha_copy = readl(phba->HAregaddr);
+       ha_copy >>= (LPFC_FCP_RING * 4);
+
+       if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
+               pring->stats.iocb_rsp_full++;
+               status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
+               writel(status, phba->CAregaddr);
+               readl(phba->CAregaddr);
+       }
+       if ((ha_copy & HA_R0CE_RSP) &&
+           (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
+               pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
+               pring->stats.iocb_cmd_empty++;
+
+               /* Force update of the local copy of cmdGetInx */
+               pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
+               lpfc_sli_resume_iocb(phba, pring);
+
+               if ((pring->lpfc_sli_cmd_available))
+                       (pring->lpfc_sli_cmd_available) (phba, pring);
+
+       }
+
+       return;
+}
+
 /*
  * This routine presumes LPFC_FCP_RING handling and doesn't bother
  * to check it explicitly.
@@ -905,10 +1075,11 @@ static int
 lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
                                struct lpfc_sli_ring * pring, uint32_t mask)
 {
+       struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
        IOCB_t *irsp = NULL;
+       IOCB_t *entry = NULL;
        struct lpfc_iocbq *cmdiocbq = NULL;
        struct lpfc_iocbq rspiocbq;
-       PGP *pgp;
        uint32_t status;
        uint32_t portRspPut, portRspMax;
        int rc = 1;
@@ -920,10 +1091,6 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
        spin_lock_irqsave(phba->host->host_lock, iflag);
        pring->stats.iocb_event++;
 
-       /* The driver assumes SLI-2 mode */
-       pgp = (PGP *) &((MAILBOX_t *) phba->sli.MBhostaddr)
-               ->us.s2.port[pring->ringno];
-
        /*
         * The next available response entry should never exceed the maximum
         * entries.  If it does, treat it as an adapter hardware error.
@@ -931,31 +1098,28 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
        portRspMax = pring->numRiocb;
        portRspPut = le32_to_cpu(pgp->rspPutInx);
        if (unlikely(portRspPut >= portRspMax)) {
-               /*
-                * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
-                * rsp ring <portRspMax>
-                */
-               lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
-                               "%d:0312 Ring %d handler: portRspPut %d "
-                               "is bigger then rsp ring %d\n",
-                               phba->brd_no, pring->ringno, portRspPut,
-                               portRspMax);
-
-               phba->hba_state = LPFC_HBA_ERROR;
-
-               /* All error attention handlers are posted to worker thread */
-               phba->work_ha |= HA_ERATT;
-               phba->work_hs = HS_FFER3;
-               if (phba->work_wait)
-                       wake_up(phba->work_wait);
-
+               lpfc_sli_rsp_pointers_error(phba, pring);
                spin_unlock_irqrestore(phba->host->host_lock, iflag);
                return 1;
        }
 
        rmb();
        while (pring->rspidx != portRspPut) {
-               irsp = (IOCB_t *) IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
+               /*
+                * Fetch an entry off the ring and copy it into a local data
+                * structure.  The copy involves a byte-swap since the
+                * network byte order and pci byte orders are different.
+                */
+               entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
+
+               if (++pring->rspidx >= portRspMax)
+                       pring->rspidx = 0;
+
+               lpfc_sli_pcimem_bcopy((uint32_t *) entry,
+                                     (uint32_t *) &rspiocbq.iocb,
+                                     sizeof (IOCB_t));
+               irsp = &rspiocbq.iocb;
+
                type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
                pring->stats.iocb_rsp++;
                rsp_cmpl++;
@@ -987,20 +1151,20 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
                                break;
                        }
 
-                       rspiocbq.iocb.un.ulpWord[4] = irsp->un.ulpWord[4];
-                       rspiocbq.iocb.ulpStatus = irsp->ulpStatus;
-                       rspiocbq.iocb.ulpContext = irsp->ulpContext;
-                       rspiocbq.iocb.ulpIoTag = irsp->ulpIoTag;
-                       cmdiocbq = lpfc_sli_txcmpl_ring_iotag_lookup(phba,
-                                                               pring,
-                                                               &rspiocbq);
+                       cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
+                                                        &rspiocbq);
                        if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
-                               spin_unlock_irqrestore(
-                                      phba->host->host_lock, iflag);
-                               (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
-                                                     &rspiocbq);
-                               spin_lock_irqsave(phba->host->host_lock,
-                                                 iflag);
+                               if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
+                                       (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
+                                                             &rspiocbq);
+                               } else {
+                                       spin_unlock_irqrestore(
+                                               phba->host->host_lock, iflag);
+                                       (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
+                                                             &rspiocbq);
+                                       spin_lock_irqsave(phba->host->host_lock,
+                                                         iflag);
+                               }
                        }
                        break;
                default:
@@ -1029,12 +1193,9 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
                 * been updated, sync the pgp->rspPutInx and fetch the new port
                 * response put pointer.
                 */
-               if (++pring->rspidx >= portRspMax)
-                       pring->rspidx = 0;
-
                to_slim = phba->MBslimaddr +
                        (SLIMOFF + (pring->ringno * 2) + 1) * 4;
-               writeb(pring->rspidx, to_slim);
+               writel(pring->rspidx, to_slim);
 
                if (pring->rspidx == portRspPut)
                        portRspPut = le32_to_cpu(pgp->rspPutInx);
@@ -1074,10 +1235,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
        struct lpfc_iocbq *next_iocb;
        struct lpfc_iocbq *cmdiocbp;
        struct lpfc_iocbq *saveq;
-       struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
-       HGP *hgp;
-       PGP *pgp;
-       MAILBOX_t *mbox;
+       struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
        uint8_t iocb_cmd_type;
        lpfc_iocb_type type;
        uint32_t status, free_saveq;
@@ -1089,11 +1247,6 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
        spin_lock_irqsave(phba->host->host_lock, iflag);
        pring->stats.iocb_event++;
 
-       /* The driver assumes SLI-2 mode */
-       mbox = (MAILBOX_t *) phba->sli.MBhostaddr;
-       pgp = (PGP *) & mbox->us.s2.port[pring->ringno];
-       hgp = (HGP *) & mbox->us.s2.host[pring->ringno];
-
        /*
         * The next available response entry should never exceed the maximum
         * entries.  If it does, treat it as an adapter hardware error.
@@ -1123,7 +1276,6 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
        }
 
        rmb();
-       lpfc_iocb_list = &phba->lpfc_iocb_list;
        while (pring->rspidx != portRspPut) {
                /*
                 * Build a completion list and call the appropriate handler.
@@ -1139,8 +1291,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                 * received.
                 */
                entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
-               list_remove_head(lpfc_iocb_list, rspiocbp, struct lpfc_iocbq,
-                                list);
+               rspiocbp = lpfc_sli_get_iocbq(phba);
                if (rspiocbp == NULL) {
                        printk(KERN_ERR "%s: out of buffers! Failing "
                               "completion.\n", __FUNCTION__);
@@ -1155,7 +1306,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
 
                to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2)
                                              + 1) * 4;
-               writeb(pring->rspidx, to_slim);
+               writel(pring->rspidx, to_slim);
 
                if (list_empty(&(pring->iocb_continueq))) {
                        list_add(&rspiocbp->list, &(pring->iocb_continueq));
@@ -1221,8 +1372,8 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                        } else if (type == LPFC_ABORT_IOCB) {
                                if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
                                    ((cmdiocbp =
-                                     lpfc_sli_txcmpl_ring_search_slow(pring,
-                                               saveq)))) {
+                                     lpfc_sli_iocbq_lookup(phba, pring,
+                                                           saveq)))) {
                                        /* Call the specified completion
                                           routine */
                                        if (cmdiocbp->iocb_cmpl) {
@@ -1234,10 +1385,9 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                                                spin_lock_irqsave(
                                                          phba->host->host_lock,
                                                          iflag);
-                                       } else {
-                                               list_add_tail(&cmdiocbp->list,
-                                                               lpfc_iocb_list);
-                                       }
+                                       } else
+                                               lpfc_sli_release_iocbq(phba,
+                                                                     cmdiocbp);
                                }
                        } else if (type == LPFC_UNKNOWN_IOCB) {
                                if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
@@ -1272,12 +1422,12 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                                                                 next_iocb,
                                                                 &saveq->list,
                                                                 list) {
-                                               list_add_tail(&rspiocbp->list,
-                                                             lpfc_iocb_list);
+                                               lpfc_sli_release_iocbq(phba,
+                                                                    rspiocbp);
                                        }
                                }
 
-                               list_add_tail(&saveq->list, lpfc_iocb_list);
+                               lpfc_sli_release_iocbq(phba, saveq);
                        }
                }
 
@@ -1322,7 +1472,6 @@ lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
        struct lpfc_iocbq *iocb, *next_iocb;
        IOCB_t *icmd = NULL, *cmd = NULL;
        int errcnt;
-       uint16_t iotag;
 
        errcnt = 0;
 
@@ -1339,139 +1488,274 @@ lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
                        spin_unlock_irq(phba->host->host_lock);
                        (iocb->iocb_cmpl) (phba, iocb, iocb);
                        spin_lock_irq(phba->host->host_lock);
-               } else {
-                       list_add_tail(&iocb->list, &phba->lpfc_iocb_list);
+               } else
+                       lpfc_sli_release_iocbq(phba, iocb);
+       }
+       pring->txq_cnt = 0;
+       INIT_LIST_HEAD(&(pring->txq));
+
+       /* Next issue ABTS for everything on the txcmplq */
+       list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+               cmd = &iocb->iocb;
+
+               /*
+                * Imediate abort of IOCB, deque and call compl
+                */
+
+               list_del_init(&iocb->list);
+               pring->txcmplq_cnt--;
+
+               if (iocb->iocb_cmpl) {
+                       cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+                       cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+                       spin_unlock_irq(phba->host->host_lock);
+                       (iocb->iocb_cmpl) (phba, iocb, iocb);
+                       spin_lock_irq(phba->host->host_lock);
+               } else
+                       lpfc_sli_release_iocbq(phba, iocb);
+       }
+
+       INIT_LIST_HEAD(&pring->txcmplq);
+       pring->txcmplq_cnt = 0;
+       spin_unlock_irq(phba->host->host_lock);
+
+       return errcnt;
+}
+
+int
+lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
+{
+       uint32_t status;
+       int i = 0;
+       int retval = 0;
+
+       /* Read the HBA Host Status Register */
+       status = readl(phba->HSregaddr);
+
+       /*
+        * Check status register every 100ms for 5 retries, then every
+        * 500ms for 5, then every 2.5 sec for 5, then reset board and
+        * every 2.5 sec for 4.
+        * Break our of the loop if errors occurred during init.
+        */
+       while (((status & mask) != mask) &&
+              !(status & HS_FFERM) &&
+              i++ < 20) {
+
+               if (i <= 5)
+                       msleep(10);
+               else if (i <= 10)
+                       msleep(500);
+               else
+                       msleep(2500);
+
+               if (i == 15) {
+                       phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
+                       lpfc_sli_brdrestart(phba);
                }
+               /* Read the HBA Host Status Register */
+               status = readl(phba->HSregaddr);
+       }
+
+       /* Check to see if any errors occurred during init */
+       if ((status & HS_FFERM) || (i >= 20)) {
+               phba->hba_state = LPFC_HBA_ERROR;
+               retval = 1;
+       }
+
+       return retval;
+}
+
+#define BARRIER_TEST_PATTERN (0xdeadbeef)
+
+void lpfc_reset_barrier(struct lpfc_hba * phba)
+{
+       uint32_t * resp_buf;
+       uint32_t * mbox_buf;
+       volatile uint32_t mbox;
+       uint32_t hc_copy;
+       int  i;
+       uint8_t hdrtype;
+
+       pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
+       if (hdrtype != 0x80 ||
+           (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
+            FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
+               return;
+
+       /*
+        * Tell the other part of the chip to suspend temporarily all
+        * its DMA activity.
+        */
+       resp_buf =  (uint32_t *)phba->MBslimaddr;
+
+       /* Disable the error attention */
+       hc_copy = readl(phba->HCregaddr);
+       writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
+       readl(phba->HCregaddr); /* flush */
+
+       if (readl(phba->HAregaddr) & HA_ERATT) {
+               /* Clear Chip error bit */
+               writel(HA_ERATT, phba->HAregaddr);
+               phba->stopped = 1;
+       }
+
+       mbox = 0;
+       ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
+       ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
+
+       writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
+       mbox_buf = (uint32_t *)phba->MBslimaddr;
+       writel(mbox, mbox_buf);
+
+       for (i = 0;
+            readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
+               mdelay(1);
+
+       if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
+               if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
+                   phba->stopped)
+                       goto restore_hc;
+               else
+                       goto clear_errat;
+       }
+
+       ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
+       for (i = 0; readl(resp_buf) != mbox &&  i < 500; i++)
+               mdelay(1);
+
+clear_errat:
+
+       while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
+               mdelay(1);
+
+       if (readl(phba->HAregaddr) & HA_ERATT) {
+               writel(HA_ERATT, phba->HAregaddr);
+               phba->stopped = 1;
+       }
+
+restore_hc:
+       writel(hc_copy, phba->HCregaddr);
+       readl(phba->HCregaddr); /* flush */
+}
+
+int
+lpfc_sli_brdkill(struct lpfc_hba * phba)
+{
+       struct lpfc_sli *psli;
+       LPFC_MBOXQ_t *pmb;
+       uint32_t status;
+       uint32_t ha_copy;
+       int retval;
+       int i = 0;
+
+       psli = &phba->sli;
+
+       /* Kill HBA */
+       lpfc_printf_log(phba,
+               KERN_INFO,
+               LOG_SLI,
+               "%d:0329 Kill HBA Data: x%x x%x\n",
+               phba->brd_no,
+               phba->hba_state,
+               psli->sli_flag);
+
+       if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
+                                                 GFP_KERNEL)) == 0)
+               return 1;
+
+       /* Disable the error attention */
+       spin_lock_irq(phba->host->host_lock);
+       status = readl(phba->HCregaddr);
+       status &= ~HC_ERINT_ENA;
+       writel(status, phba->HCregaddr);
+       readl(phba->HCregaddr); /* flush */
+       spin_unlock_irq(phba->host->host_lock);
+
+       lpfc_kill_board(phba, pmb);
+       pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+       retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
+
+       if (retval != MBX_SUCCESS) {
+               if (retval != MBX_BUSY)
+                       mempool_free(pmb, phba->mbox_mem_pool);
+               return 1;
        }
-       pring->txq_cnt = 0;
-       INIT_LIST_HEAD(&(pring->txq));
 
-       /* Next issue ABTS for everything on the txcmplq */
-       list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
-               cmd = &iocb->iocb;
+       psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
 
-               /*
-                * Imediate abort of IOCB, clear fast_lookup entry,
-                * if any, deque and call compl
-                */
-               iotag = cmd->ulpIoTag;
-               if (iotag && pring->fast_lookup &&
-                   (iotag < pring->fast_iotag))
-                       pring->fast_lookup[iotag] = NULL;
+       mempool_free(pmb, phba->mbox_mem_pool);
 
-               list_del_init(&iocb->list);
-               pring->txcmplq_cnt--;
+       /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
+        * attention every 100ms for 3 seconds. If we don't get ERATT after
+        * 3 seconds we still set HBA_ERROR state because the status of the
+        * board is now undefined.
+        */
+       ha_copy = readl(phba->HAregaddr);
 
-               if (iocb->iocb_cmpl) {
-                       cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
-                       cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
-                       spin_unlock_irq(phba->host->host_lock);
-                       (iocb->iocb_cmpl) (phba, iocb, iocb);
-                       spin_lock_irq(phba->host->host_lock);
-               } else {
-                       list_add_tail(&iocb->list, &phba->lpfc_iocb_list);
-               }
+       while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
+               mdelay(100);
+               ha_copy = readl(phba->HAregaddr);
        }
 
-       INIT_LIST_HEAD(&pring->txcmplq);
-       pring->txcmplq_cnt = 0;
+       del_timer_sync(&psli->mbox_tmo);
+       if (ha_copy & HA_ERATT) {
+               writel(HA_ERATT, phba->HAregaddr);
+               phba->stopped = 1;
+       }
+       spin_lock_irq(phba->host->host_lock);
+       psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
        spin_unlock_irq(phba->host->host_lock);
 
-       return errcnt;
+       psli->mbox_active = NULL;
+       lpfc_hba_down_post(phba);
+       phba->hba_state = LPFC_HBA_ERROR;
+
+       return (ha_copy & HA_ERATT ? 0 : 1);
 }
 
-/******************************************************************************
-* lpfc_sli_send_reset
-*
-* Note: After returning from this function, the HBA cannot be accessed for
-* 1 ms. Since we do not wish to delay in interrupt context, it is the
-* responsibility of the caller to perform the mdelay(1) and flush via readl().
-******************************************************************************/
-static int
-lpfc_sli_send_reset(struct lpfc_hba * phba, uint16_t skip_post)
+int
+lpfc_sli_brdreset(struct lpfc_hba * phba)
 {
-       MAILBOX_t *swpmb;
-       volatile uint32_t word0;
-       void __iomem *to_slim;
-       unsigned long flags = 0;
-
-       spin_lock_irqsave(phba->host->host_lock, flags);
+       struct lpfc_sli *psli;
+       struct lpfc_sli_ring *pring;
+       uint16_t cfg_value;
+       int i;
 
-       /* A board reset must use REAL SLIM. */
-       phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
+       psli = &phba->sli;
 
-       word0 = 0;
-       swpmb = (MAILBOX_t *) & word0;
-       swpmb->mbxCommand = MBX_RESTART;
-       swpmb->mbxHc = 1;
+       /* Reset HBA */
+       lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                       "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
+                       phba->hba_state, psli->sli_flag);
 
-       to_slim = phba->MBslimaddr;
-       writel(*(uint32_t *) swpmb, to_slim);
-       readl(to_slim); /* flush */
+       /* perform board reset */
+       phba->fc_eventTag = 0;
+       phba->fc_myDID = 0;
+       phba->fc_prevDID = 0;
 
-       /* Only skip post after fc_ffinit is completed */
-       if (skip_post) {
-               word0 = 1;      /* This is really setting up word1 */
-       } else {
-               word0 = 0;      /* This is really setting up word1 */
-       }
-       to_slim = phba->MBslimaddr + sizeof (uint32_t);
-       writel(*(uint32_t *) swpmb, to_slim);
-       readl(to_slim); /* flush */
+       psli->sli_flag = 0;
 
        /* Turn off parity checking and serr during the physical reset */
-       pci_read_config_word(phba->pcidev, PCI_COMMAND, &phba->pci_cfg_value);
+       pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
        pci_write_config_word(phba->pcidev, PCI_COMMAND,
-                             (phba->pci_cfg_value &
+                             (cfg_value &
                               ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
 
+       psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
+       /* Now toggle INITFF bit in the Host Control Register */
        writel(HC_INITFF, phba->HCregaddr);
-
-       phba->hba_state = LPFC_INIT_START;
-       spin_unlock_irqrestore(phba->host->host_lock, flags);
-
-       return 0;
-}
-
-static int
-lpfc_sli_brdreset(struct lpfc_hba * phba, uint16_t skip_post)
-{
-       struct lpfc_sli_ring *pring;
-       int i;
-       struct lpfc_dmabuf *mp, *next_mp;
-       unsigned long flags = 0;
-
-       lpfc_sli_send_reset(phba, skip_post);
        mdelay(1);
-
-       spin_lock_irqsave(phba->host->host_lock, flags);
-       /* Risk the write on flush case ie no delay after the readl */
        readl(phba->HCregaddr); /* flush */
-       /* Now toggle INITFF bit set by lpfc_sli_send_reset */
        writel(0, phba->HCregaddr);
        readl(phba->HCregaddr); /* flush */
 
        /* Restore PCI cmd register */
-       pci_write_config_word(phba->pcidev, PCI_COMMAND, phba->pci_cfg_value);
-
-       /* perform board reset */
-       phba->fc_eventTag = 0;
-       phba->fc_myDID = 0;
-       phba->fc_prevDID = Mask_DID;
-
-       /* Reset HBA */
-       lpfc_printf_log(phba,
-               KERN_INFO,
-               LOG_SLI,
-               "%d:0325 Reset HBA Data: x%x x%x x%x\n",
-               phba->brd_no,
-               phba->hba_state,
-               phba->sli.sli_flag,
-               skip_post);
+       pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
 
        /* Initialize relevant SLI info */
-       for (i = 0; i < phba->sli.num_rings; i++) {
-               pring = &phba->sli.ring[i];
+       for (i = 0; i < psli->num_rings; i++) {
+               pring = &psli->ring[i];
                pring->flag = 0;
                pring->rspidx = 0;
                pring->next_cmdidx  = 0;
@@ -1479,27 +1763,64 @@ lpfc_sli_brdreset(struct lpfc_hba * phba, uint16_t skip_post)
                pring->cmdidx = 0;
                pring->missbufcnt = 0;
        }
-       spin_unlock_irqrestore(phba->host->host_lock, flags);
 
-       if (skip_post) {
-               mdelay(100);
+       phba->hba_state = LPFC_WARM_START;
+       return 0;
+}
+
+int
+lpfc_sli_brdrestart(struct lpfc_hba * phba)
+{
+       MAILBOX_t *mb;
+       struct lpfc_sli *psli;
+       uint16_t skip_post;
+       volatile uint32_t word0;
+       void __iomem *to_slim;
+
+       spin_lock_irq(phba->host->host_lock);
+
+       psli = &phba->sli;
+
+       /* Restart HBA */
+       lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                       "%d:0328 Restart HBA Data: x%x x%x\n", phba->brd_no,
+                       phba->hba_state, psli->sli_flag);
+
+       word0 = 0;
+       mb = (MAILBOX_t *) &word0;
+       mb->mbxCommand = MBX_RESTART;
+       mb->mbxHc = 1;
+
+       lpfc_reset_barrier(phba);
+
+       to_slim = phba->MBslimaddr;
+       writel(*(uint32_t *) mb, to_slim);
+       readl(to_slim); /* flush */
+
+       /* Only skip post after fc_ffinit is completed */
+       if (phba->hba_state) {
+               skip_post = 1;
+               word0 = 1;      /* This is really setting up word1 */
        } else {
-               mdelay(2000);
+               skip_post = 0;
+               word0 = 0;      /* This is really setting up word1 */
        }
+       to_slim = (uint8_t *) phba->MBslimaddr + sizeof (uint32_t);
+       writel(*(uint32_t *) mb, to_slim);
+       readl(to_slim); /* flush */
 
-       spin_lock_irqsave(phba->host->host_lock, flags);
-       /* Cleanup preposted buffers on the ELS ring */
-       pring = &phba->sli.ring[LPFC_ELS_RING];
-       list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
-               list_del(&mp->list);
-               pring->postbufq_cnt--;
-               lpfc_mbuf_free(phba, mp->virt, mp->phys);
-               kfree(mp);
-       }
-       spin_unlock_irqrestore(phba->host->host_lock, flags);
+       lpfc_sli_brdreset(phba);
+       phba->stopped = 0;
+       phba->hba_state = LPFC_INIT_START;
+
+       spin_unlock_irq(phba->host->host_lock);
+
+       if (skip_post)
+               mdelay(100);
+       else
+               mdelay(2000);
 
-       for (i = 0; i < phba->sli.num_rings; i++)
-               lpfc_sli_abort_iocb_ring(phba, &phba->sli.ring[i]);
+       lpfc_hba_down_post(phba);
 
        return 0;
 }
@@ -1559,7 +1880,8 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
                }
 
                if (i == 15) {
-                       lpfc_sli_brdreset(phba, 0);
+                       phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
+                       lpfc_sli_brdrestart(phba);
                }
                /* Read the HBA Host Status Register */
                status = readl(phba->HSregaddr);
@@ -1603,8 +1925,8 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
        }
 
        while (resetcount < 2 && !done) {
-               phba->hba_state = 0;
-               lpfc_sli_brdreset(phba, 0);
+               phba->hba_state = LPFC_STATE_UNKNOWN;
+               lpfc_sli_brdrestart(phba);
                msleep(2500);
                rc = lpfc_sli_chipset_init(phba);
                if (rc)
@@ -1738,6 +2060,8 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
                return;
        }
 
+       phba->work_hba_events &= ~WORKER_MBOX_TMO;
+
        pmbox = phba->sli.mbox_active;
        mb = &pmbox->mb;
 
@@ -1752,16 +2076,14 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
                phba->sli.sli_flag,
                phba->sli.mbox_active);
 
-       if (phba->sli.mbox_active == pmbox) {
-               phba->sli.mbox_active = NULL;
-               if (pmbox->mbox_cmpl) {
-                       mb->mbxStatus = MBX_NOT_FINISHED;
-                       spin_unlock_irq(phba->host->host_lock);
-                       (pmbox->mbox_cmpl) (phba, pmbox);
-                       spin_lock_irq(phba->host->host_lock);
-               }
-               phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+       phba->sli.mbox_active = NULL;
+       if (pmbox->mbox_cmpl) {
+               mb->mbxStatus = MBX_NOT_FINISHED;
+               spin_unlock_irq(phba->host->host_lock);
+               (pmbox->mbox_cmpl) (phba, pmbox);
+               spin_lock_irq(phba->host->host_lock);
        }
+       phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
 
        spin_unlock_irq(phba->host->host_lock);
        lpfc_mbox_abort(phba);
@@ -1771,7 +2093,6 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
 int
 lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
 {
-       MAILBOX_t *mbox;
        MAILBOX_t *mb;
        struct lpfc_sli *psli;
        uint32_t status, evtctr;
@@ -1789,6 +2110,21 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
        mb = &pmbox->mb;
        status = MBX_SUCCESS;
 
+       if (phba->hba_state == LPFC_HBA_ERROR) {
+               spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
+
+               /* Mbox command <mbxCommand> cannot issue */
+               LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
+               return (MBX_NOT_FINISHED);
+       }
+
+       if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
+           !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
+               spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
+               LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
+               return (MBX_NOT_FINISHED);
+       }
+
        if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
                /* Polling for a mbox command when another one is already active
                 * is not allowed in SLI. Also, the driver must have established
@@ -1871,7 +2207,8 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
 
        /* If we are not polling, we MUST be in SLI2 mode */
        if (flag != MBX_POLL) {
-               if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
+               if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
+                   (mb->mbxCommand != MBX_KILL_BOARD)) {
                        psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
                        spin_unlock_irqrestore(phba->host->host_lock,
                                               drvr_flag);
@@ -1901,15 +2238,13 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
        mb->mbxOwner = OWN_CHIP;
 
        if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
-
                /* First copy command data to host SLIM area */
-               mbox = (MAILBOX_t *) psli->MBhostaddr;
-               lpfc_sli_pcimem_bcopy(mb, mbox, MAILBOX_CMD_SIZE);
+               lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
        } else {
                if (mb->mbxCommand == MBX_CONFIG_PORT) {
                        /* copy command data into host mbox for cmpl */
-                       mbox = (MAILBOX_t *) psli->MBhostaddr;
-                       lpfc_sli_pcimem_bcopy(mb, mbox, MAILBOX_CMD_SIZE);
+                       lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
+                                       MAILBOX_CMD_SIZE);
                }
 
                /* First copy mbox command data to HBA SLIM, skip past first
@@ -1946,8 +2281,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
                psli->mbox_active = NULL;
                if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
                        /* First read mbox status word */
-                       mbox = (MAILBOX_t *) psli->MBhostaddr;
-                       word0 = *((volatile uint32_t *)mbox);
+                       word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
                        word0 = le32_to_cpu(word0);
                } else {
                        /* First read mbox status word */
@@ -1958,8 +2292,9 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
                ha_copy = readl(phba->HAregaddr);
 
                /* Wait for command to complete */
-               while (((word0 & OWN_CHIP) == OWN_CHIP)
-                      || !(ha_copy & HA_MBATT)) {
+               while (((word0 & OWN_CHIP) == OWN_CHIP) ||
+                      (!(ha_copy & HA_MBATT) &&
+                       (phba->hba_state > LPFC_WARM_START))) {
                        if (i++ >= 100) {
                                psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
                                spin_unlock_irqrestore(phba->host->host_lock,
@@ -1984,8 +2319,8 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
 
                        if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
                                /* First copy command data */
-                               mbox = (MAILBOX_t *) psli->MBhostaddr;
-                               word0 = *((volatile uint32_t *)mbox);
+                               word0 = *((volatile uint32_t *)
+                                               &phba->slim2p->mbx);
                                word0 = le32_to_cpu(word0);
                                if (mb->mbxCommand == MBX_CONFIG_PORT) {
                                        MAILBOX_t *slimmb;
@@ -2009,10 +2344,9 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
                }
 
                if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
-                       /* First copy command data */
-                       mbox = (MAILBOX_t *) psli->MBhostaddr;
                        /* copy results back to user */
-                       lpfc_sli_pcimem_bcopy(mbox, mb, MAILBOX_CMD_SIZE);
+                       lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
+                                       MAILBOX_CMD_SIZE);
                } else {
                        /* First copy command data */
                        lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
@@ -2089,8 +2423,6 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                switch (piocb->iocb.ulpCommand) {
                case CMD_QUE_RING_BUF_CN:
                case CMD_QUE_RING_BUF64_CN:
-               case CMD_CLOSE_XRI_CN:
-               case CMD_ABORT_XRI_CN:
                        /*
                         * For IOCBs, like QUE_RING_BUF, that have no rsp ring
                         * completion, iocb_cmpl MUST be 0.
@@ -2112,16 +2444,6 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                   !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
                goto iocb_busy;
 
-       /*
-        * Check to see if this is a high priority command.
-        * If so bypass tx queue processing.
-        */
-       if (unlikely((flag & SLI_IOCB_HIGH_PRIORITY) &&
-                    (iocb = lpfc_sli_next_iocb_slot(phba, pring)))) {
-               lpfc_sli_submit_iocb(phba, pring, iocb, piocb);
-               piocb = NULL;
-       }
-
        while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
               (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
                lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
@@ -2149,6 +2471,37 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
        return IOCB_BUSY;
 }
 
+static int
+lpfc_extra_ring_setup( struct lpfc_hba *phba)
+{
+       struct lpfc_sli *psli;
+       struct lpfc_sli_ring *pring;
+
+       psli = &phba->sli;
+
+       /* Adjust cmd/rsp ring iocb entries more evenly */
+       pring = &psli->ring[psli->fcp_ring];
+       pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
+       pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
+       pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
+       pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
+
+       pring = &psli->ring[1];
+       pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
+       pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
+       pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
+       pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
+
+       /* Setup default profile for this ring */
+       pring->iotag_max = 4096;
+       pring->num_mask = 1;
+       pring->prt[0].profile = 0;      /* Mask 0 */
+       pring->prt[0].rctl = FC_UNSOL_DATA;
+       pring->prt[0].type = 5;
+       pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
+       return 0;
+}
+
 int
 lpfc_sli_setup(struct lpfc_hba *phba)
 {
@@ -2162,6 +2515,10 @@ lpfc_sli_setup(struct lpfc_hba *phba)
        psli->next_ring = LPFC_FCP_NEXT_RING;
        psli->ip_ring = LPFC_IP_RING;
 
+       psli->iocbq_lookup = NULL;
+       psli->iocbq_lookup_len = 0;
+       psli->last_iotag = 0;
+
        for (i = 0; i < psli->num_rings; i++) {
                pring = &psli->ring[i];
                switch (i) {
@@ -2228,6 +2585,8 @@ lpfc_sli_setup(struct lpfc_hba *phba)
                                "SLI2 SLIM Data: x%x x%x\n",
                                phba->brd_no, totiocb, MAX_SLI2_IOCB);
        }
+       if (phba->cfg_multi_ring_support == 2)
+               lpfc_extra_ring_setup(phba);
 
        return 0;
 }
@@ -2237,7 +2596,7 @@ lpfc_sli_queue_setup(struct lpfc_hba * phba)
 {
        struct lpfc_sli *psli;
        struct lpfc_sli_ring *pring;
-       int i, cnt;
+       int i;
 
        psli = &phba->sli;
        spin_lock_irq(phba->host->host_lock);
@@ -2253,19 +2612,6 @@ lpfc_sli_queue_setup(struct lpfc_hba * phba)
                INIT_LIST_HEAD(&pring->txcmplq);
                INIT_LIST_HEAD(&pring->iocb_continueq);
                INIT_LIST_HEAD(&pring->postbufq);
-               cnt = pring->fast_iotag;
-               spin_unlock_irq(phba->host->host_lock);
-               if (cnt) {
-                       pring->fast_lookup =
-                               kmalloc(cnt * sizeof (struct lpfc_iocbq *),
-                                       GFP_KERNEL);
-                       if (pring->fast_lookup == 0) {
-                               return (0);
-                       }
-                       memset((char *)pring->fast_lookup, 0,
-                              cnt * sizeof (struct lpfc_iocbq *));
-               }
-               spin_lock_irq(phba->host->host_lock);
        }
        spin_unlock_irq(phba->host->host_lock);
        return (1);
@@ -2307,19 +2653,14 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
                                                       flags);
                                (iocb->iocb_cmpl) (phba, iocb, iocb);
                                spin_lock_irqsave(phba->host->host_lock, flags);
-                       } else {
-                               list_add_tail(&iocb->list,
-                                             &phba->lpfc_iocb_list);
-                       }
+                       } else
+                               lpfc_sli_release_iocbq(phba, iocb);
                }
 
                INIT_LIST_HEAD(&(pring->txq));
 
-               if (pring->fast_lookup) {
-                       kfree(pring->fast_lookup);
-                       pring->fast_lookup = NULL;
-               }
-
+               kfree(pring->fast_lookup);
+               pring->fast_lookup = NULL;
        }
 
        spin_unlock_irqrestore(phba->host->host_lock, flags);
@@ -2354,15 +2695,6 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
 
        spin_unlock_irqrestore(phba->host->host_lock, flags);
 
-       /*
-        * Provided the hba is not in an error state, reset it.  It is not
-        * capable of IO anymore.
-        */
-       if (phba->hba_state != LPFC_HBA_ERROR) {
-               phba->hba_state = LPFC_INIT_START;
-               lpfc_sli_brdreset(phba, 1);
-       }
-
        return 1;
 }
 
@@ -2451,7 +2783,7 @@ lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
                kfree(buf_ptr);
        }
 
-       list_add_tail(&cmdiocb->list, &phba->lpfc_iocb_list);
+       lpfc_sli_release_iocbq(phba, cmdiocb);
        return;
 }
 
@@ -2460,16 +2792,14 @@ lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
                             struct lpfc_sli_ring * pring,
                             struct lpfc_iocbq * cmdiocb)
 {
-       struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
-       struct lpfc_iocbq *abtsiocbp = NULL;
+       struct lpfc_iocbq *abtsiocbp;
        IOCB_t *icmd = NULL;
        IOCB_t *iabt = NULL;
 
        /* issue ABTS for this IOCB based on iotag */
-       list_remove_head(lpfc_iocb_list, abtsiocbp, struct lpfc_iocbq, list);
+       abtsiocbp = lpfc_sli_get_iocbq(phba);
        if (abtsiocbp == NULL)
                return 0;
-       memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
 
        iabt = &abtsiocbp->iocb;
        icmd = &cmdiocb->iocb;
@@ -2488,7 +2818,7 @@ lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
                abtsiocbp->iocb_cmpl = lpfc_sli_abort_elsreq_cmpl;
                break;
        default:
-               list_add_tail(&abtsiocbp->list, lpfc_iocb_list);
+               lpfc_sli_release_iocbq(phba, abtsiocbp);
                return 0;
        }
 
@@ -2500,7 +2830,7 @@ lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
        iabt->ulpCommand = CMD_ABORT_MXRI64_CN;
 
        if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) == IOCB_ERROR) {
-               list_add_tail(&abtsiocbp->list, lpfc_iocb_list);
+               lpfc_sli_release_iocbq(phba, abtsiocbp);
                return 0;
        }
 
@@ -2508,28 +2838,37 @@ lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
 }
 
 static int
-lpfc_sli_validate_iocb_cmd(struct lpfc_scsi_buf *lpfc_cmd, uint16_t tgt_id,
-                            uint64_t lun_id, struct lpfc_iocbq *iocb,
-                            uint32_t ctx, lpfc_ctx_cmd ctx_cmd)
+lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
+                          uint64_t lun_id, uint32_t ctx,
+                          lpfc_ctx_cmd ctx_cmd)
 {
+       struct lpfc_scsi_buf *lpfc_cmd;
+       struct scsi_cmnd *cmnd;
        int rc = 1;
 
-       if (lpfc_cmd == NULL)
+       if (!(iocbq->iocb_flag &  LPFC_IO_FCP))
+               return rc;
+
+       lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
+       cmnd = lpfc_cmd->pCmd;
+
+       if (cmnd == NULL)
                return rc;
 
        switch (ctx_cmd) {
        case LPFC_CTX_LUN:
-               if ((lpfc_cmd->pCmd->device->id == tgt_id) &&
-                   (lpfc_cmd->pCmd->device->lun == lun_id))
+               if ((cmnd->device->id == tgt_id) &&
+                   (cmnd->device->lun == lun_id))
                        rc = 0;
                break;
        case LPFC_CTX_TGT:
-               if (lpfc_cmd->pCmd->device->id == tgt_id)
+               if (cmnd->device->id == tgt_id)
                        rc = 0;
                break;
        case LPFC_CTX_CTX:
-               if (iocb->iocb.ulpContext == ctx)
+               if (iocbq->iocb.ulpContext == ctx)
                        rc = 0;
+               break;
        case LPFC_CTX_HOST:
                rc = 0;
                break;
@@ -2546,71 +2885,56 @@ int
 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
 {
-       struct lpfc_iocbq *iocb, *next_iocb;
-       IOCB_t *cmd = NULL;
-       struct lpfc_scsi_buf *lpfc_cmd;
-       int sum = 0, ret_val = 0;
-
-       /* Next check the txcmplq */
-       list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
-               cmd = &iocb->iocb;
+       struct lpfc_iocbq *iocbq;
+       int sum, i;
 
-               /* Must be a FCP command */
-               if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
-                   (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
-                   (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
-                       continue;
-               }
+       for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
+               iocbq = phba->sli.iocbq_lookup[i];
 
-               /* context1 MUST be a struct lpfc_scsi_buf */
-               lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
-               ret_val = lpfc_sli_validate_iocb_cmd(lpfc_cmd, tgt_id, lun_id,
-                                                    NULL, 0, ctx_cmd);
-               if (ret_val != 0)
-                       continue;
-               sum++;
+               if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
+                                               0, ctx_cmd) == 0)
+                       sum++;
        }
+
        return sum;
 }
 
+void
+lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+                          struct lpfc_iocbq * rspiocb)
+{
+       spin_lock_irq(phba->host->host_lock);
+       lpfc_sli_release_iocbq(phba, cmdiocb);
+       spin_unlock_irq(phba->host->host_lock);
+       return;
+}
+
 int
 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                    uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
                    lpfc_ctx_cmd abort_cmd)
 {
-       struct lpfc_iocbq *iocb, *next_iocb;
-       struct lpfc_iocbq *abtsiocb = NULL;
-       struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
+       struct lpfc_iocbq *iocbq;
+       struct lpfc_iocbq *abtsiocb;
        IOCB_t *cmd = NULL;
-       struct lpfc_scsi_buf *lpfc_cmd;
        int errcnt = 0, ret_val = 0;
+       int i;
 
-       list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
-               cmd = &iocb->iocb;
-
-               /* Must be a FCP command */
-               if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
-                   (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
-                   (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
-                       continue;
-               }
+       for (i = 1; i <= phba->sli.last_iotag; i++) {
+               iocbq = phba->sli.iocbq_lookup[i];
 
-               /* context1 MUST be a struct lpfc_scsi_buf */
-               lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
-               ret_val = lpfc_sli_validate_iocb_cmd(lpfc_cmd, tgt_id, lun_id,
-                                                    iocb, ctx, abort_cmd);
-               if (ret_val != 0)
+               if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
+                                               0, abort_cmd) != 0)
                        continue;
 
                /* issue ABTS for this IOCB based on iotag */
-               list_remove_head(lpfc_iocb_list, abtsiocb, struct lpfc_iocbq,
-                                list);
+               abtsiocb = lpfc_sli_get_iocbq(phba);
                if (abtsiocb == NULL) {
                        errcnt++;
                        continue;
                }
-               memset(abtsiocb, 0, sizeof (struct lpfc_iocbq));
 
+               cmd = &iocbq->iocb;
                abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
                abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
                abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
@@ -2622,9 +2946,11 @@ lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
                else
                        abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
 
+               /* Setup callback routine and issue the command. */
+               abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
                ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
                if (ret_val == IOCB_ERROR) {
-                       list_add_tail(&abtsiocb->list, lpfc_iocb_list);
+                       lpfc_sli_release_iocbq(phba, abtsiocb);
                        errcnt++;
                        continue;
                }
@@ -2633,83 +2959,114 @@ lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
        return errcnt;
 }
 
-void
-lpfc_sli_wake_iocb_high_priority(struct lpfc_hba * phba,
-                                struct lpfc_iocbq * queue1,
-                                struct lpfc_iocbq * queue2)
+static void
+lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
+                       struct lpfc_iocbq *cmdiocbq,
+                       struct lpfc_iocbq *rspiocbq)
 {
-       if (queue1->context2 && queue2)
-               memcpy(queue1->context2, queue2, sizeof (struct lpfc_iocbq));
+       wait_queue_head_t *pdone_q;
+       unsigned long iflags;
 
-       /* The waiter is looking for LPFC_IO_HIPRI bit to be set
-          as a signal to wake up */
-       queue1->iocb_flag |= LPFC_IO_HIPRI;
+       spin_lock_irqsave(phba->host->host_lock, iflags);
+       cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
+       if (cmdiocbq->context2 && rspiocbq)
+               memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
+                      &rspiocbq->iocb, sizeof(IOCB_t));
+
+       pdone_q = cmdiocbq->context_un.wait_queue;
+       spin_unlock_irqrestore(phba->host->host_lock, iflags);
+       if (pdone_q)
+               wake_up(pdone_q);
        return;
 }
 
+/*
+ * Issue the caller's iocb and wait for its completion, but no longer than the
+ * caller's timeout.  Note that iocb_flags is cleared before the
+ * lpfc_sli_issue_call since the wake routine sets a unique value and by
+ * definition this is a wait function.
+ */
 int
-lpfc_sli_issue_iocb_wait_high_priority(struct lpfc_hba * phba,
-                                      struct lpfc_sli_ring * pring,
-                                      struct lpfc_iocbq * piocb,
-                                      uint32_t flag,
-                                      struct lpfc_iocbq * prspiocbq,
-                                      uint32_t timeout)
+lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
+                        struct lpfc_sli_ring * pring,
+                        struct lpfc_iocbq * piocb,
+                        struct lpfc_iocbq * prspiocbq,
+                        uint32_t timeout)
 {
-       int j, delay_time,  retval = IOCB_ERROR;
-
-       /* The caller must left context1 empty.  */
-       if (piocb->context_un.hipri_wait_queue != 0) {
-               return IOCB_ERROR;
-       }
+       DECLARE_WAIT_QUEUE_HEAD(done_q);
+       long timeleft, timeout_req = 0;
+       int retval = IOCB_SUCCESS;
+       uint32_t creg_val;
 
        /*
-        * If the caller has provided a response iocbq buffer, context2 must
-        * be NULL or its an error.
+        * If the caller has provided a response iocbq buffer, then context2
+        * is NULL or its an error.
         */
-       if (prspiocbq && piocb->context2) {
-               return IOCB_ERROR;
+       if (prspiocbq) {
+               if (piocb->context2)
+                       return IOCB_ERROR;
+               piocb->context2 = prspiocbq;
        }
 
-       piocb->context2 = prspiocbq;
+       piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
+       piocb->context_un.wait_queue = &done_q;
+       piocb->iocb_flag &= ~LPFC_IO_WAKE;
 
-       /* Setup callback routine and issue the command. */
-       piocb->iocb_cmpl = lpfc_sli_wake_iocb_high_priority;
-       retval = lpfc_sli_issue_iocb(phba, pring, piocb,
-                                       flag | SLI_IOCB_HIGH_PRIORITY);
-       if (retval != IOCB_SUCCESS) {
-               piocb->context2 = NULL;
-               return IOCB_ERROR;
+       if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
+               creg_val = readl(phba->HCregaddr);
+               creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
+               writel(creg_val, phba->HCregaddr);
+               readl(phba->HCregaddr); /* flush */
        }
 
-       /*
-        * This high-priority iocb was sent out-of-band.  Poll for its
-        * completion rather than wait for a signal.  Note that the host_lock
-        * is held by the midlayer and must be released here to allow the
-        * interrupt handlers to complete the IO and signal this routine via
-        * the iocb_flag.
-        * Also, the delay_time is computed to be one second longer than
-        * the scsi command timeout to give the FW time to abort on
-        * timeout rather than the driver just giving up.  Typically,
-        * the midlayer does not specify a time for this command so the
-        * driver is free to enforce its own timeout.
-        */
+       retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
+       if (retval == IOCB_SUCCESS) {
+               timeout_req = timeout * HZ;
+               spin_unlock_irq(phba->host->host_lock);
+               timeleft = wait_event_timeout(done_q,
+                               piocb->iocb_flag & LPFC_IO_WAKE,
+                               timeout_req);
+               spin_lock_irq(phba->host->host_lock);
 
-       delay_time = ((timeout + 1) * 1000) >> 6;
-       retval = IOCB_ERROR;
-       spin_unlock_irq(phba->host->host_lock);
-       for (j = 0; j < 64; j++) {
-               msleep(delay_time);
-               if (piocb->iocb_flag & LPFC_IO_HIPRI) {
-                       piocb->iocb_flag &= ~LPFC_IO_HIPRI;
-                       retval = IOCB_SUCCESS;
-                       break;
+               if (timeleft == 0) {
+                       lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+                                       "%d:0329 IOCB wait timeout error - no "
+                                       "wake response Data x%x\n",
+                                       phba->brd_no, timeout);
+                       retval = IOCB_TIMEDOUT;
+               } else if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
+                       lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+                                       "%d:0330 IOCB wake NOT set, "
+                                       "Data x%x x%lx\n", phba->brd_no,
+                                       timeout, (timeleft / jiffies));
+                       retval = IOCB_TIMEDOUT;
+               } else {
+                       lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                                       "%d:0331 IOCB wake signaled\n",
+                                       phba->brd_no);
                }
+       } else {
+               lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                               "%d:0332 IOCB wait issue failed, Data x%x\n",
+                               phba->brd_no, retval);
+               retval = IOCB_ERROR;
        }
 
-       spin_lock_irq(phba->host->host_lock);
-       piocb->context2 = NULL;
+       if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
+               creg_val = readl(phba->HCregaddr);
+               creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
+               writel(creg_val, phba->HCregaddr);
+               readl(phba->HCregaddr); /* flush */
+       }
+
+       if (prspiocbq)
+               piocb->context2 = NULL;
+
+       piocb->context_un.wait_queue = NULL;
+       piocb->iocb_cmpl = NULL;
        return retval;
 }
+
 int
 lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
                         uint32_t timeout)
@@ -2741,11 +3098,10 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
                pmboxq->context1 = NULL;
                /* if schedule_timeout returns 0, we timed out and were not
                   woken up */
-               if (timeleft == 0) {
+               if ((timeleft == 0) || signal_pending(current))
                        retval = MBX_TIMEOUT;
-               } else {
+               else
                        retval = MBX_SUCCESS;
-               }
        }
 
 
@@ -2851,13 +3207,7 @@ lpfc_intr_handler(int irq, void *dev_id, struct pt_regs * regs)
                        /* Clear Chip error bit */
                        writel(HA_ERATT, phba->HAregaddr);
                        readl(phba->HAregaddr); /* flush */
-
-                       /*
-                        * Reseting the HBA is the only reliable way
-                        * to shutdown interrupt when there is a
-                        * ERROR.
-                        */
-                       lpfc_sli_send_reset(phba, phba->hba_state);
+                       phba->stopped = 1;
                }
 
                spin_lock(phba->host->host_lock);