Merge master.kernel.org:/pub/scm/linux/kernel/git/bart/ide-2.6
[pandora-kernel.git] / drivers / scsi / stex.c
index 0fd115c..69be132 100644 (file)
  *     Written By:
  *             Ed Lin <promise_linux@promise.com>
  *
- *     Version: 3.0.0.1
- *
  */
 
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
-#include <linux/sched.h>
 #include <linux/time.h>
 #include <linux/pci.h>
 #include <linux/blkdev.h>
@@ -37,9 +34,9 @@
 #include <scsi/scsi_tcq.h>
 
 #define DRV_NAME "stex"
-#define ST_DRIVER_VERSION "3.0.0.1"
+#define ST_DRIVER_VERSION "3.1.0.1"
 #define ST_VER_MAJOR           3
-#define ST_VER_MINOR           0
+#define ST_VER_MINOR           1
 #define ST_OEM                         0
 #define ST_BUILD_VER           1
 
@@ -76,9 +73,10 @@ enum {
        MU_STATE_STARTED                        = 4,
        MU_STATE_RESETTING                      = 5,
 
-       MU_MAX_DELAY_TIME                       = 240000,
+       MU_MAX_DELAY                            = 120,
        MU_HANDSHAKE_SIGNATURE                  = 0x55aaaa55,
        MU_HANDSHAKE_SIGNATURE_HALF             = 0x5a5a0000,
+       MU_HARD_RESET_WAIT                      = 30000,
        HMU_PARTNER_TYPE                        = 2,
 
        /* firmware returned values */
@@ -121,7 +119,8 @@ enum {
 
        st_shasta                               = 0,
        st_vsc                                  = 1,
-       st_yosemite                             = 2,
+       st_vsc1                                 = 2,
+       st_yosemite                             = 3,
 
        PASSTHRU_REQ_TYPE                       = 0x00000001,
        PASSTHRU_REQ_NO_WAKEUP                  = 0x00000100,
@@ -151,6 +150,8 @@ enum {
        MGT_CMD_SIGNATURE                       = 0xba,
 
        INQUIRY_EVPD                            = 0x01,
+
+       ST_ADDITIONAL_MEM                       = 0x200000,
 };
 
 /* SCSI inquiry data */
@@ -212,7 +213,9 @@ struct handshake_frame {
        __le32 partner_ver_minor;
        __le32 partner_ver_oem;
        __le32 partner_ver_build;
-       u32 reserved1[4];
+       __le32 extra_offset;    /* NEW */
+       __le32 extra_size;      /* NEW */
+       u32 reserved1[2];
 };
 
 struct req_msg {
@@ -303,6 +306,7 @@ struct st_hba {
        void __iomem *mmio_base;        /* iomapped PCI memory space */
        void *dma_mem;
        dma_addr_t dma_handle;
+       size_t dma_size;
 
        struct Scsi_Host *host;
        struct pci_dev *pdev;
@@ -904,23 +908,22 @@ static int stex_handshake(struct st_hba *hba)
        struct handshake_frame *h;
        dma_addr_t status_phys;
        u32 data;
-       int i;
+       unsigned long before;
 
        if (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
                writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
                readl(base + IDBL);
-               for (i = 0; readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE
-                       && i < MU_MAX_DELAY_TIME; i++) {
+               before = jiffies;
+               while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
+                       if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
+                               printk(KERN_ERR DRV_NAME
+                                       "(%s): no handshake signature\n",
+                                       pci_name(hba->pdev));
+                               return -1;
+                       }
                        rmb();
                        msleep(1);
                }
-
-               if (i == MU_MAX_DELAY_TIME) {
-                       printk(KERN_ERR DRV_NAME
-                               "(%s): no handshake signature\n",
-                               pci_name(hba->pdev));
-                       return -1;
-               }
        }
 
        udelay(10);
@@ -941,6 +944,11 @@ static int stex_handshake(struct st_hba *hba)
        h->status_cnt = cpu_to_le16(MU_STATUS_COUNT);
        stex_gettime(&h->hosttime);
        h->partner_type = HMU_PARTNER_TYPE;
+       if (hba->dma_size > STEX_BUFFER_SIZE) {
+               h->extra_offset = cpu_to_le32(STEX_BUFFER_SIZE);
+               h->extra_size = cpu_to_le32(ST_ADDITIONAL_MEM);
+       } else
+               h->extra_offset = h->extra_size = 0;
 
        status_phys = hba->dma_handle + MU_REQ_BUFFER_SIZE;
        writel(status_phys, base + IMR0);
@@ -954,19 +962,18 @@ static int stex_handshake(struct st_hba *hba)
        readl(base + IDBL); /* flush */
 
        udelay(10);
-       for (i = 0; readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE
-               && i < MU_MAX_DELAY_TIME; i++) {
+       before = jiffies;
+       while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
+               if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
+                       printk(KERN_ERR DRV_NAME
+                               "(%s): no signature after handshake frame\n",
+                               pci_name(hba->pdev));
+                       return -1;
+               }
                rmb();
                msleep(1);
        }
 
-       if (i == MU_MAX_DELAY_TIME) {
-               printk(KERN_ERR DRV_NAME
-                       "(%s): no signature after handshake frame\n",
-                       pci_name(hba->pdev));
-               return -1;
-       }
-
        writel(0, base + IMR0);
        readl(base + IMR0);
        writel(0, base + OMR0);
@@ -1048,7 +1055,7 @@ static void stex_hard_reset(struct st_hba *hba)
        pci_bctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
        pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
 
-       for (i = 0; i < MU_MAX_DELAY_TIME; i++) {
+       for (i = 0; i < MU_HARD_RESET_WAIT; i++) {
                pci_read_config_word(hba->pdev, PCI_COMMAND, &pci_cmd);
                if (pci_cmd != 0xffff && (pci_cmd & PCI_COMMAND_MASTER))
                        break;
@@ -1203,8 +1210,13 @@ stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                goto out_iounmap;
        }
 
+       hba->cardtype = (unsigned int) id->driver_data;
+       if (hba->cardtype == st_vsc && (pdev->subsystem_device & 0xf) == 0x1)
+               hba->cardtype = st_vsc1;
+       hba->dma_size = (hba->cardtype == st_vsc1) ?
+               (STEX_BUFFER_SIZE + ST_ADDITIONAL_MEM) : (STEX_BUFFER_SIZE);
        hba->dma_mem = dma_alloc_coherent(&pdev->dev,
-               STEX_BUFFER_SIZE, &hba->dma_handle, GFP_KERNEL);
+               hba->dma_size, &hba->dma_handle, GFP_KERNEL);
        if (!hba->dma_mem) {
                err = -ENOMEM;
                printk(KERN_ERR DRV_NAME "(%s): dma mem alloc failed\n",
@@ -1217,8 +1229,6 @@ stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        hba->copy_buffer = hba->dma_mem + MU_BUFFER_SIZE;
        hba->mu_status = MU_STATE_STARTING;
 
-       hba->cardtype = (unsigned int) id->driver_data;
-
        /* firmware uses id/lun pair for a logical drive, but lun would be
           always 0 if CONFIG_SCSI_MULTI_LUN not configured, so we use
           channel to map lun here */
@@ -1266,7 +1276,7 @@ stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 out_free_irq:
        free_irq(pdev->irq, hba);
 out_pci_free:
-       dma_free_coherent(&pdev->dev, STEX_BUFFER_SIZE,
+       dma_free_coherent(&pdev->dev, hba->dma_size,
                          hba->dma_mem, hba->dma_handle);
 out_iounmap:
        iounmap(hba->mmio_base);
@@ -1327,7 +1337,7 @@ static void stex_hba_free(struct st_hba *hba)
 
        pci_release_regions(hba->pdev);
 
-       dma_free_coherent(&hba->pdev->dev, STEX_BUFFER_SIZE,
+       dma_free_coherent(&hba->pdev->dev, hba->dma_size,
                          hba->dma_mem, hba->dma_handle);
 }