[SCSI] mptfusion - bus_type, change SCSI to SPI
[firefly-linux-kernel-4.4.55.git] / drivers / message / fusion / mptbase.c
index 790a2932ded99673bae69d0ab7cd16e99e2454b9..537836068c493736d1efc7a3139974d16faeacc1 100644 (file)
@@ -47,7 +47,6 @@
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 
 #include <linux/config.h>
-#include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/errno.h>
@@ -314,13 +313,13 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
                u32      log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
                if (ioc->bus_type == FC)
                        mpt_fc_log_info(ioc, log_info);
-               else if (ioc->bus_type == SCSI)
+               else if (ioc->bus_type == SPI)
                        mpt_sp_log_info(ioc, log_info);
                else if (ioc->bus_type == SAS)
                        mpt_sas_log_info(ioc, log_info);
        }
        if (ioc_stat & MPI_IOCSTATUS_MASK) {
-               if (ioc->bus_type == SCSI &&
+               if (ioc->bus_type == SPI &&
                    cb_idx != mpt_stm_index &&
                    cb_idx != mpt_lan_index)
                        mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
@@ -1119,6 +1118,65 @@ mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
        return -1;
 }
 
+int
+mpt_alt_ioc_wait(MPT_ADAPTER *ioc)
+{
+       int loop_count = 30 * 4;  /* Wait 30 seconds */
+       int status = -1; /* -1 means failed to get board READY */
+
+       do {
+               spin_lock(&ioc->initializing_hba_lock);
+               if (ioc->initializing_hba_lock_flag == 0) {
+                       ioc->initializing_hba_lock_flag=1;
+                       spin_unlock(&ioc->initializing_hba_lock);
+                       status = 0;
+                       break;
+               }
+               spin_unlock(&ioc->initializing_hba_lock);
+               set_current_state(TASK_INTERRUPTIBLE);
+               schedule_timeout(HZ/4);
+       } while (--loop_count);
+
+       return status;
+}
+
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *     mpt_bringup_adapter - This is a wrapper function for mpt_do_ioc_recovery
+ *     @ioc: Pointer to MPT adapter structure
+ *     @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
+ *
+ *     This routine performs all the steps necessary to bring the IOC
+ *     to a OPERATIONAL state.
+ *
+ *      Special Note: This function was added with spin lock's so as to allow
+ *      the dv(domain validation) work thread to succeed on the other channel
+ *      that maybe occuring at the same time when this function is called.
+ *      Without this lock, the dv would fail when message frames were
+ *      requested during hba bringup on the alternate ioc.
+ */
+static int
+mpt_bringup_adapter(MPT_ADAPTER *ioc, int sleepFlag)
+{
+       int r;
+
+       if(ioc->alt_ioc) {
+               if((r=mpt_alt_ioc_wait(ioc->alt_ioc)!=0))
+                       return r;
+       }
+
+       r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
+           CAN_SLEEP);
+
+       if(ioc->alt_ioc) {
+               spin_lock(&ioc->alt_ioc->initializing_hba_lock);
+               ioc->alt_ioc->initializing_hba_lock_flag=0;
+               spin_unlock(&ioc->alt_ioc->initializing_hba_lock);
+       }
+
+return r;
+}
+
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /*
  *     mpt_attach - Install a PCI intelligent MPT adapter.
@@ -1187,6 +1245,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        ioc->pcidev = pdev;
        ioc->diagPending = 0;
        spin_lock_init(&ioc->diagLock);
+       spin_lock_init(&ioc->initializing_hba_lock);
 
        /* Initialize the event logging.
         */
@@ -1317,7 +1376,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        }
        else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
                ioc->prod_name = "LSI53C1030";
-               ioc->bus_type = SCSI;
+               ioc->bus_type = SPI;
                /* 1030 Chip Fix. Disable Split transactions
                 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
                 */
@@ -1330,7 +1389,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        }
        else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
                ioc->prod_name = "LSI53C1035";
-               ioc->bus_type = SCSI;
+               ioc->bus_type = SPI;
        }
        else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064) {
                ioc->prod_name = "LSISAS1064";
@@ -1409,8 +1468,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
         */
        mpt_detect_bound_ports(ioc, pdev);
 
-       if ((r = mpt_do_ioc_recovery(ioc,
-         MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0) {
+       if ((r = mpt_bringup_adapter(ioc, CAN_SLEEP)) != 0){
                printk(KERN_WARNING MYNAM
                  ": WARNING - %s did not initialize properly! (%d)\n",
                  ioc->name, r);
@@ -2984,7 +3042,7 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
        /* Clear the internal flash bad bit - autoincrementing register,
         * so must do two writes.
         */
-       if (ioc->bus_type == SCSI) {
+       if (ioc->bus_type == SPI) {
                /*
                 * 1030 and 1035 H/W errata, workaround to access
                 * the ClearFlashBadSignatureBit
@@ -3094,7 +3152,7 @@ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
        int cnt,cntdn;
 
        dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
-       if (ioc->bus_type == SCSI) {
+       if (ioc->bus_type == SPI) {
                /* Always issue a Msg Unit Reset first. This will clear some
                 * SCSI bus hang conditions.
                 */
@@ -3522,7 +3580,7 @@ initChainBuffers(MPT_ADAPTER *ioc)
        dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
                ioc->name, numSGE, num_sge, num_chain));
 
-       if (ioc->bus_type == SCSI)
+       if (ioc->bus_type == SPI)
                num_chain *= MPT_SCSI_CAN_QUEUE;
        else
                num_chain *= MPT_FC_CAN_QUEUE;
@@ -6299,6 +6357,7 @@ EXPORT_SYMBOL(mpt_read_ioc_pg_3);
 EXPORT_SYMBOL(mpt_alloc_fw_memory);
 EXPORT_SYMBOL(mpt_free_fw_memory);
 EXPORT_SYMBOL(mptbase_sas_persist_operation);
+EXPORT_SYMBOL(mpt_alt_ioc_wait);
 
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/