Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / drivers / scsi / lpfc / lpfc_sli.c
index bb69a7a..70f4d5a 100644 (file)
@@ -191,35 +191,12 @@ static int
 lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
                        struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
 {
-       uint16_t iotag;
-
        list_add_tail(&piocb->list, &pring->txcmplq);
        pring->txcmplq_cnt++;
        if (unlikely(pring->ringno == LPFC_ELS_RING))
                mod_timer(&phba->els_tmofunc,
                                        jiffies + HZ * (phba->fc_ratov << 1));
 
-       if (pring->fast_lookup) {
-               /* Setup fast lookup based on iotag for completion */
-               iotag = piocb->iocb.ulpIoTag;
-               if (iotag && (iotag < pring->fast_iotag))
-                       *(pring->fast_lookup + iotag) = piocb;
-               else {
-
-                       /* Cmd ring <ringno> put: iotag <iotag> greater then
-                          configured max <fast_iotag> wd0 <icmd> */
-                       lpfc_printf_log(phba,
-                                       KERN_ERR,
-                                       LOG_SLI,
-                                       "%d:0316 Cmd ring %d put: iotag x%x "
-                                       "greater then configured max x%x "
-                                       "wd0 x%x\n",
-                                       phba->brd_no,
-                                       pring->ringno, iotag,
-                                       pring->fast_iotag,
-                                       *(((uint32_t *)(&piocb->iocb)) + 7));
-               }
-       }
        return (0);
 }
 
@@ -343,7 +320,8 @@ lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
                        kfree(old_arr);
                        return iotag;
                }
-       }
+       } else
+               spin_unlock_irq(phba->host->host_lock);
 
        lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
                        "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
@@ -601,7 +579,7 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
                        /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
                           <status> */
                        lpfc_printf_log(phba,
-                                       KERN_ERR,
+                                       KERN_WARNING,
                                        LOG_MBOX | LOG_SLI,
                                        "%d:0304 Stray Mailbox Interrupt "
                                        "mbxCommand x%x mbxStatus x%x\n",
@@ -992,9 +970,11 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
                         * 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);
+                               lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                                               "%d:0314 IOCB cmd 0x%x"
+                                               " processed. Skipping"
+                                               " completion", phba->brd_no,
+                                               irsp->ulpCommand);
                                break;
                        }
 
@@ -1127,7 +1107,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
                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: "
+                               "%d:0336 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],
@@ -1145,9 +1125,11 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
                         * 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);
+                               lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
+                                               "%d:0333 IOCB cmd 0x%x"
+                                               " processed. Skipping"
+                                               " completion\n", phba->brd_no,
+                                               irsp->ulpCommand);
                                break;
                        }
 
@@ -1178,7 +1160,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
                        } else {
                                /* Unknown IOCB command */
                                lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
-                                       "%d:0321 Unknown IOCB command "
+                                       "%d:0334 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,
@@ -1261,7 +1243,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                lpfc_printf_log(phba,
                                KERN_ERR,
                                LOG_SLI,
-                               "%d:0312 Ring %d handler: portRspPut %d "
+                               "%d:0303 Ring %d handler: portRspPut %d "
                                "is bigger then rsp ring %d\n",
                                phba->brd_no,
                                pring->ringno, portRspPut, portRspMax);
@@ -1406,7 +1388,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                                        lpfc_printf_log(phba,
                                                KERN_ERR,
                                                LOG_SLI,
-                                               "%d:0321 Unknown IOCB command "
+                                               "%d:0335 Unknown IOCB command "
                                                "Data: x%x x%x x%x x%x\n",
                                                phba->brd_no,
                                                irsp->ulpCommand,
@@ -1422,11 +1404,11 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
                                                                 next_iocb,
                                                                 &saveq->list,
                                                                 list) {
+                                               list_del(&rspiocbp->list);
                                                lpfc_sli_release_iocbq(phba,
                                                                     rspiocbp);
                                        }
                                }
-
                                lpfc_sli_release_iocbq(phba, saveq);
                        }
                }
@@ -1570,8 +1552,8 @@ lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
 
 void lpfc_reset_barrier(struct lpfc_hba * phba)
 {
-       uint32_t resp_buf;
-       uint32_t mbox_buf;
+       uint32_t __iomem *resp_buf;
+       uint32_t __iomem *mbox_buf;
        volatile uint32_t mbox;
        uint32_t hc_copy;
        int  i;
@@ -1587,7 +1569,7 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
         * Tell the other part of the chip to suspend temporarily all
         * its DMA activity.
         */
-       resp_buf =  (uint32_t *)phba->MBslimaddr;
+       resp_buf = phba->MBslimaddr;
 
        /* Disable the error attention */
        hc_copy = readl(phba->HCregaddr);
@@ -1605,7 +1587,7 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
        ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
 
        writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
-       mbox_buf = (uint32_t *)phba->MBslimaddr;
+       mbox_buf = phba->MBslimaddr;
        writel(mbox, mbox_buf);
 
        for (i = 0;
@@ -1734,15 +1716,13 @@ lpfc_sli_brdreset(struct lpfc_hba * phba)
        phba->fc_myDID = 0;
        phba->fc_prevDID = 0;
 
-       psli->sli_flag = 0;
-
        /* Turn off parity checking and serr during the physical reset */
        pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
        pci_write_config_word(phba->pcidev, PCI_COMMAND,
                              (cfg_value &
                               ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
 
-       psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
+       psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
        /* Now toggle INITFF bit in the Host Control Register */
        writel(HC_INITFF, phba->HCregaddr);
        mdelay(1);
@@ -1783,7 +1763,7 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
 
        /* Restart HBA */
        lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
-                       "%d:0328 Restart HBA Data: x%x x%x\n", phba->brd_no,
+                       "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
                        phba->hba_state, psli->sli_flag);
 
        word0 = 0;
@@ -1805,7 +1785,7 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
                skip_post = 0;
                word0 = 0;      /* This is really setting up word1 */
        }
-       to_slim = (uint8_t *) phba->MBslimaddr + sizeof (uint32_t);
+       to_slim = phba->MBslimaddr + sizeof (uint32_t);
        writel(*(uint32_t *) mb, to_slim);
        readl(to_slim); /* flush */
 
@@ -1815,6 +1795,9 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
 
        spin_unlock_irq(phba->host->host_lock);
 
+       memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
+       psli->stats_start = get_seconds();
+
        if (skip_post)
                mdelay(100);
        else
@@ -1925,6 +1908,9 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
        }
 
        while (resetcount < 2 && !done) {
+               spin_lock_irq(phba->host->host_lock);
+               phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
+               spin_unlock_irq(phba->host->host_lock);
                phba->hba_state = LPFC_STATE_UNKNOWN;
                lpfc_sli_brdrestart(phba);
                msleep(2500);
@@ -1932,6 +1918,9 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
                if (rc)
                        break;
 
+               spin_lock_irq(phba->host->host_lock);
+               phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+               spin_unlock_irq(phba->host->host_lock);
                resetcount++;
 
        /* Call pre CONFIG_PORT mailbox command initialization.  A value of 0
@@ -2217,7 +2206,8 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
                        return (MBX_NOT_FINISHED);
                }
                /* timeout active mbox command */
-               mod_timer(&psli->mbox_tmo, jiffies + HZ * LPFC_MBOX_TMO);
+               mod_timer(&psli->mbox_tmo, (jiffies +
+                              (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
        }
 
        /* Mailbox cmd <cmd> issue */
@@ -2277,7 +2267,6 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
                break;
 
        case MBX_POLL:
-               i = 0;
                psli->mbox_active = NULL;
                if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
                        /* First read mbox status word */
@@ -2291,11 +2280,14 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
                /* Read the HBA Host Attention Register */
                ha_copy = readl(phba->HAregaddr);
 
+               i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
+               i *= 1000; /* Convert to ms */
+
                /* Wait for command to complete */
                while (((word0 & OWN_CHIP) == OWN_CHIP) ||
                       (!(ha_copy & HA_MBATT) &&
                        (phba->hba_state > LPFC_WARM_START))) {
-                       if (i++ >= 100) {
+                       if (i-- <= 0) {
                                psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
                                spin_unlock_irqrestore(phba->host->host_lock,
                                                       drvr_flag);
@@ -2313,7 +2305,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
 
                        /* Can be in interrupt context, do not sleep */
                        /* (or might be called with interrupts disabled) */
-                       mdelay(i);
+                       mdelay(1);
 
                        spin_lock_irqsave(phba->host->host_lock, drvr_flag);
 
@@ -2659,8 +2651,6 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
 
                INIT_LIST_HEAD(&(pring->txq));
 
-               kfree(pring->fast_lookup);
-               pring->fast_lookup = NULL;
        }
 
        spin_unlock_irqrestore(phba->host->host_lock, flags);
@@ -3030,7 +3020,7 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
 
                if (timeleft == 0) {
                        lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
-                                       "%d:0329 IOCB wait timeout error - no "
+                                       "%d:0338 IOCB wait timeout error - no "
                                        "wake response Data x%x\n",
                                        phba->brd_no, timeout);
                        retval = IOCB_TIMEDOUT;
@@ -3110,6 +3100,24 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
        return retval;
 }
 
+int
+lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
+{
+       int i = 0;
+
+       while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
+               if (i++ > LPFC_MBOX_TMO * 1000)
+                       return 1;
+
+               if (lpfc_sli_handle_mb_event(phba) == 0)
+                       i = 0;
+
+               msleep(1);
+       }
+
+       return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
+}
+
 irqreturn_t
 lpfc_intr_handler(int irq, void *dev_id, struct pt_regs * regs)
 {