]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/sym53c8xx_2/sym_glue.c
[SCSI] remove use_sg_chaining
[linux-2.6-omap-h63xx.git] / drivers / scsi / sym53c8xx_2 / sym_glue.c
index 9521f0ea4129b1daf07b2cee5dbb4274642ffc01..d39107b7669bfb22e3fa1e278166dd2c2766616f 100644 (file)
@@ -39,7 +39,6 @@
  */
 #include <linux/ctype.h>
 #include <linux/init.h>
-#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/spinlock.h>
@@ -163,14 +162,6 @@ void sym_xpt_async_bus_reset(struct sym_hcb *np)
                            sym_name(np), sym_driver_setup.settle_delay);
 }
 
-/*
- *  Tell the SCSI layer about a BUS DEVICE RESET message sent.
- */
-void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
-{
-       printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
-}
-
 /*
  *  Choose the more appropriate CAM status if 
  *  the IO encountered an extended error.
@@ -216,10 +207,9 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
                        /*
                         *  Bounce back the sense data to user.
                         */
-                       memset(&cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
+                       memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
                        memcpy(cmd->sense_buffer, cp->sns_bbuf,
-                             min(sizeof(cmd->sense_buffer),
-                                 (size_t)SYM_SNS_BBUF_LEN));
+                              min(SCSI_SENSE_BUFFERSIZE, SYM_SNS_BBUF_LEN));
 #if 0
                        /*
                         *  If the device reports a UNIT ATTENTION condition 
@@ -498,14 +488,16 @@ static void sym_timer(struct sym_hcb *np)
 /*
  *  PCI BUS error handler.
  */
-void sym_log_bus_error(struct sym_hcb *np)
+void sym_log_bus_error(struct Scsi_Host *shost)
 {
-       u_short pci_sts;
-       pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
+       struct sym_data *sym_data = shost_priv(shost);
+       struct pci_dev *pdev = sym_data->pdev;
+       unsigned short pci_sts;
+       pci_read_config_word(pdev, PCI_STATUS, &pci_sts);
        if (pci_sts & 0xf900) {
-               pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
-               printf("%s: PCI STATUS = 0x%04x\n",
-                       sym_name(np), pci_sts & 0xf900);
+               pci_write_config_word(pdev, PCI_STATUS, pci_sts);
+               shost_printk(KERN_WARNING, shost,
+                       "PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
        }
 }
 
@@ -549,21 +541,23 @@ static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
  */
 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
 {
-       struct sym_hcb *np = dev_id;
+       struct Scsi_Host *shost = dev_id;
+       struct sym_data *sym_data = shost_priv(shost);
+       irqreturn_t result;
 
        /* Avoid spinloop trying to handle interrupts on frozen device */
-       if (pci_channel_offline(np->s.device))
+       if (pci_channel_offline(sym_data->pdev))
                return IRQ_NONE;
 
        if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
 
-       spin_lock(np->s.host->host_lock);
-       sym_interrupt(np);
-       spin_unlock(np->s.host->host_lock);
+       spin_lock(shost->host_lock);
+       result = sym_interrupt(shost);
+       spin_unlock(shost->host_lock);
 
        if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
 
-       return IRQ_HANDLED;
+       return result;
 }
 
 /*
@@ -594,16 +588,17 @@ static void sym53c8xx_timer(unsigned long npref)
  */
 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
 {
-       struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
        struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
-       struct Scsi_Host *host = cmd->device->host;
-       struct pci_dev *pdev = np->s.device;
+       struct Scsi_Host *shost = cmd->device->host;
+       struct sym_data *sym_data = shost_priv(shost);
+       struct pci_dev *pdev = sym_data->pdev;
+       struct sym_hcb *np = sym_data->ncb;
        SYM_QUEHEAD *qp;
        int cmd_queued = 0;
        int sts = -1;
        struct completion eh_done;
 
-       scmd_printk(KERN_WARNING, cmd, "%s operation started.\n", opname);
+       scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
 
        /* We may be in an error condition because the PCI bus
         * went down. In this case, we need to wait until the
@@ -613,31 +608,29 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
         */
 #define WAIT_FOR_PCI_RECOVERY  35
        if (pci_channel_offline(pdev)) {
-               struct host_data *hostdata = shost_priv(host);
-               struct completion *io_reset;
                int finished_reset = 0;
                init_completion(&eh_done);
-               spin_lock_irq(host->host_lock);
+               spin_lock_irq(shost->host_lock);
                /* Make sure we didn't race */
                if (pci_channel_offline(pdev)) {
-                       if (!hostdata->io_reset)
-                               hostdata->io_reset = &eh_done;
-                       io_reset = hostdata->io_reset;
+                       BUG_ON(sym_data->io_reset);
+                       sym_data->io_reset = &eh_done;
                } else {
-                       io_reset = NULL;
-               }
-
-               if (!pci_channel_offline(pdev))
                        finished_reset = 1;
-               spin_unlock_irq(host->host_lock);
+               }
+               spin_unlock_irq(shost->host_lock);
                if (!finished_reset)
-                       finished_reset = wait_for_completion_timeout(io_reset,
+                       finished_reset = wait_for_completion_timeout
+                                               (sym_data->io_reset,
                                                WAIT_FOR_PCI_RECOVERY*HZ);
+               spin_lock_irq(shost->host_lock);
+               sym_data->io_reset = NULL;
+               spin_unlock_irq(shost->host_lock);
                if (!finished_reset)
                        return SCSI_FAILED;
        }
 
-       spin_lock_irq(host->host_lock);
+       spin_lock_irq(shost->host_lock);
        /* This one is queued in some place -> to wait for completion */
        FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
                struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
@@ -662,7 +655,7 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
                break;
        case SYM_EH_HOST_RESET:
                sym_reset_scsi_bus(np, 0);
-               sym_start_up(np, 1);
+               sym_start_up(shost, 1);
                sts = 0;
                break;
        default:
@@ -676,13 +669,13 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
        if (cmd_queued) {
                init_completion(&eh_done);
                ucmd->eh_done = &eh_done;
-               spin_unlock_irq(host->host_lock);
+               spin_unlock_irq(shost->host_lock);
                if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
                        ucmd->eh_done = NULL;
                        sts = -2;
                }
        } else {
-               spin_unlock_irq(host->host_lock);
+               spin_unlock_irq(shost->host_lock);
        }
 
        dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
@@ -995,8 +988,9 @@ static int is_keyword(char *ptr, int len, char *verb)
  * Parse a control command
  */
 
-static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
+static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
 {
+       struct sym_hcb *np = sym_get_hcb(shost);
        char *ptr       = buffer;
        int len         = length;
        struct sym_usrcmd cmd, *uc = &cmd;
@@ -1123,9 +1117,9 @@ printk("sym_user_command: data=%ld\n", uc->data);
        else {
                unsigned long flags;
 
-               spin_lock_irqsave(np->s.host->host_lock, flags);
-               sym_exec_user_command (np, uc);
-               spin_unlock_irqrestore(np->s.host->host_lock, flags);
+               spin_lock_irqsave(shost->host_lock, flags);
+               sym_exec_user_command(np, uc);
+               spin_unlock_irqrestore(shost->host_lock, flags);
        }
        return length;
 }
@@ -1181,8 +1175,11 @@ static int copy_info(struct info_str *info, char *fmt, ...)
 /*
  *  Copy formatted information into the input buffer.
  */
-static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
+static int sym_host_info(struct Scsi_Host *shost, char *ptr, off_t offset, int len)
 {
+       struct sym_data *sym_data = shost_priv(shost);
+       struct pci_dev *pdev = sym_data->pdev;
+       struct sym_hcb *np = sym_data->ncb;
        struct info_str info;
 
        info.buffer     = ptr;
@@ -1192,9 +1189,9 @@ static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
 
        copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
                         "revision id 0x%x\n", np->s.chip_name,
-                        np->s.device->device, np->s.device->revision);
+                        pdev->device, pdev->revision);
        copy_info(&info, "At PCI address %s, IRQ %u\n",
-                        pci_name(np->s.device), np->s.device->irq);
+                        pci_name(pdev), pdev->irq);
        copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
                         (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
                         np->maxwide ? "Wide" : "Narrow",
@@ -1213,15 +1210,14 @@ static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
  *  - func = 0 means read  (returns adapter infos)
  *  - func = 1 means write (not yet merget from sym53c8xx)
  */
-static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
+static int sym53c8xx_proc_info(struct Scsi_Host *shost, char *buffer,
                        char **start, off_t offset, int length, int func)
 {
-       struct sym_hcb *np = sym_get_hcb(host);
        int retv;
 
        if (func) {
 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
-               retv = sym_user_command(np, buffer, length);
+               retv = sym_user_command(shost, buffer, length);
 #else
                retv = -EINVAL;
 #endif
@@ -1229,7 +1225,7 @@ static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
                if (start)
                        *start = buffer;
 #ifdef SYM_LINUX_USER_INFO_SUPPORT
-               retv = sym_host_info(np, buffer, offset, length);
+               retv = sym_host_info(shost, buffer, offset, length);
 #else
                retv = -EINVAL;
 #endif
@@ -1248,7 +1244,7 @@ static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
         *  Free O/S specific resources.
         */
        if (pdev->irq)
-               free_irq(pdev->irq, np);
+               free_irq(pdev->irq, np->s.host);
        if (np->s.ioaddr)
                pci_iounmap(pdev, np->s.ioaddr);
        if (np->s.ramaddr)
@@ -1273,9 +1269,9 @@ static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
                int unit, struct sym_device *dev)
 {
-       struct host_data *host_data;
+       struct sym_data *sym_data;
        struct sym_hcb *np = NULL;
-       struct Scsi_Host *instance = NULL;
+       struct Scsi_Host *shost;
        struct pci_dev *pdev = dev->pdev;
        unsigned long flags;
        struct sym_fw *fw;
@@ -1289,15 +1285,12 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
         */
        fw = sym_find_firmware(&dev->chip);
        if (!fw)
-               goto attach_failed;
+               return NULL;
 
-       /*
-        *      Allocate host_data structure
-        */
-       instance = scsi_host_alloc(tpnt, sizeof(*host_data));
-       if (!instance)
-               goto attach_failed;
-       host_data = (struct host_data *) instance->hostdata;
+       shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
+       if (!shost)
+               return NULL;
+       sym_data = shost_priv(shost);
 
        /*
         *  Allocate immediately the host control block, 
@@ -1308,19 +1301,18 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
        np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
        if (!np)
                goto attach_failed;
-       np->s.device = pdev;
        np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
-       host_data->ncb = np;
-       np->s.host = instance;
+       sym_data->ncb = np;
+       sym_data->pdev = pdev;
+       np->s.host = shost;
 
-       pci_set_drvdata(pdev, np);
+       pci_set_drvdata(pdev, shost);
 
        /*
         *  Copy some useful infos to the HCB.
         */
        np->hcb_ba      = vtobus(np);
        np->verbose     = sym_driver_setup.verbose;
-       np->s.device    = pdev;
        np->s.unit      = unit;
        np->features    = dev->chip.features;
        np->clock_divn  = dev->chip.nr_divisor;
@@ -1335,9 +1327,9 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
        sprintf(np->s.inst_name, "sym%d", np->s.unit);
 
        if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
-                       !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) {
+                       !pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
                set_dac(np);
-       } else if (pci_set_dma_mask(np->s.device, DMA_32BIT_MASK)) {
+       } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
                printf_warning("%s: No suitable DMA available\n", sym_name(np));
                goto attach_failed;
        }
@@ -1358,7 +1350,7 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
        if (dev->ram_base)
                np->ram_ba = (u32)dev->ram_base;
 
-       if (sym_hcb_attach(instance, fw, dev->nvram))
+       if (sym_hcb_attach(shost, fw, dev->nvram))
                goto attach_failed;
 
        /*
@@ -1366,7 +1358,8 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
         *  If we synchonize the C code with SCRIPTS on interrupt, 
         *  we do not want to share the INTR line at all.
         */
-       if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX, np)) {
+       if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
+                       shost)) {
                printf_err("%s: request irq %u failure\n",
                        sym_name(np), pdev->irq);
                goto attach_failed;
@@ -1376,14 +1369,14 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
         *  After SCSI devices have been opened, we cannot
         *  reset the bus safely, so we do it here.
         */
-       spin_lock_irqsave(instance->host_lock, flags);
+       spin_lock_irqsave(shost->host_lock, flags);
        if (sym_reset_scsi_bus(np, 0))
                goto reset_failed;
 
        /*
         *  Start the SCRIPTS.
         */
-       sym_start_up(np, 1);
+       sym_start_up(shost, 1);
 
        /*
         *  Start the timer daemon
@@ -1398,37 +1391,37 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
         *  Fill Linux host instance structure
         *  and return success.
         */
-       instance->max_channel   = 0;
-       instance->this_id       = np->myaddr;
-       instance->max_id        = np->maxwide ? 16 : 8;
-       instance->max_lun       = SYM_CONF_MAX_LUN;
-       instance->unique_id     = pci_resource_start(pdev, 0);
-       instance->cmd_per_lun   = SYM_CONF_MAX_TAG;
-       instance->can_queue     = (SYM_CONF_MAX_START-2);
-       instance->sg_tablesize  = SYM_CONF_MAX_SG;
-       instance->max_cmd_len   = 16;
+       shost->max_channel      = 0;
+       shost->this_id          = np->myaddr;
+       shost->max_id           = np->maxwide ? 16 : 8;
+       shost->max_lun          = SYM_CONF_MAX_LUN;
+       shost->unique_id        = pci_resource_start(pdev, 0);
+       shost->cmd_per_lun      = SYM_CONF_MAX_TAG;
+       shost->can_queue        = (SYM_CONF_MAX_START-2);
+       shost->sg_tablesize     = SYM_CONF_MAX_SG;
+       shost->max_cmd_len      = 16;
        BUG_ON(sym2_transport_template == NULL);
-       instance->transportt    = sym2_transport_template;
+       shost->transportt       = sym2_transport_template;
 
        /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
        if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
-               instance->dma_boundary = 0xFFFFFF;
+               shost->dma_boundary = 0xFFFFFF;
 
-       spin_unlock_irqrestore(instance->host_lock, flags);
+       spin_unlock_irqrestore(shost->host_lock, flags);
 
-       return instance;
+       return shost;
 
  reset_failed:
        printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
                   "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
-       spin_unlock_irqrestore(instance->host_lock, flags);
+       spin_unlock_irqrestore(shost->host_lock, flags);
  attach_failed:
-       if (!instance)
+       if (!shost)
                return NULL;
        printf_info("%s: giving up ...\n", sym_name(np));
        if (np)
                sym_free_resources(np, pdev);
-       scsi_host_put(instance);
+       scsi_host_put(shost);
 
        return NULL;
  }
@@ -1648,8 +1641,9 @@ static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
  *  Detach the host.
  *  We have to free resources and halt the NCR chip.
  */
-static int sym_detach(struct sym_hcb *np, struct pci_dev *pdev)
+static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
 {
+       struct sym_hcb *np = sym_get_hcb(shost);
        printk("%s: detaching ...\n", sym_name(np));
 
        del_timer_sync(&np->s.timer);
@@ -1687,7 +1681,6 @@ static struct scsi_host_template sym2_template = {
        .eh_host_reset_handler  = sym53c8xx_eh_host_reset_handler,
        .this_id                = 7,
        .use_clustering         = ENABLE_CLUSTERING,
-       .use_sg_chaining        = ENABLE_SG_CHAINING,
        .max_sectors            = 0xFFFF,
 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
        .proc_info              = sym53c8xx_proc_info,
@@ -1702,7 +1695,7 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
 {
        struct sym_device sym_dev;
        struct sym_nvram nvram;
-       struct Scsi_Host *instance;
+       struct Scsi_Host *shost;
 
        memset(&sym_dev, 0, sizeof(sym_dev));
        memset(&nvram, 0, sizeof(nvram));
@@ -1729,13 +1722,13 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
 
        sym_get_nvram(&sym_dev, &nvram);
 
-       instance = sym_attach(&sym2_template, attach_count, &sym_dev);
-       if (!instance)
+       shost = sym_attach(&sym2_template, attach_count, &sym_dev);
+       if (!shost)
                goto free;
 
-       if (scsi_add_host(instance, &pdev->dev))
+       if (scsi_add_host(shost, &pdev->dev))
                goto detach;
-       scsi_scan_host(instance);
+       scsi_scan_host(shost);
 
        attach_count++;
 
@@ -1751,16 +1744,13 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
        return -ENODEV;
 }
 
-static void __devexit sym2_remove(struct pci_dev *pdev)
+static void sym2_remove(struct pci_dev *pdev)
 {
-       struct sym_hcb *np = pci_get_drvdata(pdev);
-       struct Scsi_Host *host = np->s.host;
-
-       scsi_remove_host(host);
-       scsi_host_put(host);
-
-       sym_detach(np, pdev);
+       struct Scsi_Host *shost = pci_get_drvdata(pdev);
 
+       scsi_remove_host(shost);
+       scsi_host_put(shost);
+       sym_detach(shost, pdev);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
 
@@ -1794,9 +1784,9 @@ static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
  */
 static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
 {
-       struct sym_hcb *np = pci_get_drvdata(pdev);
+       struct Scsi_Host *shost = pci_get_drvdata(pdev);
 
-       sym_dump_registers(np);
+       sym_dump_registers(shost);
 
        /* Request a slot reset. */
        return PCI_ERS_RESULT_NEED_RESET;
@@ -1836,7 +1826,8 @@ static void sym2_reset_workarounds(struct pci_dev *pdev)
  */
 static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
 {
-       struct sym_hcb *np = pci_get_drvdata(pdev);
+       struct Scsi_Host *shost = pci_get_drvdata(pdev);
+       struct sym_hcb *np = sym_get_hcb(shost);
 
        printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
                  sym_name(np));
@@ -1866,7 +1857,7 @@ static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
                                sym_name(np));
                        return PCI_ERS_RESULT_DISCONNECT;
                }
-               sym_start_up(np, 1);
+               sym_start_up(shost, 1);
        }
 
        return PCI_ERS_RESULT_RECOVERED;
@@ -1882,14 +1873,12 @@ static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
  */
 static void sym2_io_resume(struct pci_dev *pdev)
 {
-       struct sym_hcb *np = pci_get_drvdata(pdev);
-       struct Scsi_Host *shost = np->s.host;
-       struct host_data *hostdata = shost_priv(shost);
+       struct Scsi_Host *shost = pci_get_drvdata(pdev);
+       struct sym_data *sym_data = shost_priv(shost);
 
        spin_lock_irq(shost->host_lock);
-       if (hostdata->io_reset)
-               complete_all(hostdata->io_reset);
-       hostdata->io_reset = NULL;
+       if (sym_data->io_reset)
+               complete_all(sym_data->io_reset);
        spin_unlock_irq(shost->host_lock);
 }
 
@@ -2066,7 +2055,7 @@ static struct pci_driver sym2_driver = {
        .name           = NAME53C8XX,
        .id_table       = sym2_id_table,
        .probe          = sym2_probe,
-       .remove         = __devexit_p(sym2_remove),
+       .remove         = sym2_remove,
        .err_handler    = &sym2_err_handler,
 };