[SCSI] scsi_transport_fc: fix missing kernel-doc
[safe/jmp/linux-2.6] / drivers / scsi / esp_scsi.c
index 3cd5bf7..a680e18 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/irqreturn.h>
 
 #include <asm/irq.h>
 #include <asm/io.h>
@@ -218,19 +219,10 @@ static void esp_reset_esp(struct esp *esp)
        /* Now reset the ESP chip */
        scsi_esp_cmd(esp, ESP_CMD_RC);
        scsi_esp_cmd(esp, ESP_CMD_NULL | ESP_CMD_DMA);
+       if (esp->rev == FAST)
+               esp_write8(ESP_CONFIG2_FENAB, ESP_CFG2);
        scsi_esp_cmd(esp, ESP_CMD_NULL | ESP_CMD_DMA);
 
-       /* Reload the configuration registers */
-       esp_write8(esp->cfact, ESP_CFACT);
-
-       esp->prev_stp = 0;
-       esp_write8(esp->prev_stp, ESP_STP);
-
-       esp->prev_soff = 0;
-       esp_write8(esp->prev_soff, ESP_SOFF);
-
-       esp_write8(esp->neg_defp, ESP_TIMEO);
-
        /* This is the only point at which it is reliable to read
         * the ID-code for a fast ESP chip variants.
         */
@@ -315,6 +307,17 @@ static void esp_reset_esp(struct esp *esp)
                break;
        }
 
+       /* Reload the configuration registers */
+       esp_write8(esp->cfact, ESP_CFACT);
+
+       esp->prev_stp = 0;
+       esp_write8(esp->prev_stp, ESP_STP);
+
+       esp->prev_soff = 0;
+       esp_write8(esp->prev_soff, ESP_SOFF);
+
+       esp_write8(esp->neg_defp, ESP_TIMEO);
+
        /* Eat any bitrot in the chip */
        esp_read8(ESP_INTRPT);
        udelay(100);
@@ -323,17 +326,14 @@ static void esp_reset_esp(struct esp *esp)
 static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
 {
        struct esp_cmd_priv *spriv = ESP_CMD_PRIV(cmd);
-       struct scatterlist *sg = cmd->request_buffer;
+       struct scatterlist *sg = scsi_sglist(cmd);
        int dir = cmd->sc_data_direction;
        int total, i;
 
        if (dir == DMA_NONE)
                return;
 
-       BUG_ON(cmd->use_sg == 0);
-
-       spriv->u.num_sg = esp->ops->map_sg(esp, sg,
-                                          cmd->use_sg, dir);
+       spriv->u.num_sg = esp->ops->map_sg(esp, sg, scsi_sg_count(cmd), dir);
        spriv->cur_residue = sg_dma_len(sg);
        spriv->cur_sg = sg;
 
@@ -406,8 +406,7 @@ static void esp_unmap_dma(struct esp *esp, struct scsi_cmnd *cmd)
        if (dir == DMA_NONE)
                return;
 
-       esp->ops->unmap_sg(esp, cmd->request_buffer,
-                          spriv->u.num_sg, dir);
+       esp->ops->unmap_sg(esp, scsi_sglist(cmd), spriv->u.num_sg, dir);
 }
 
 static void esp_save_pointers(struct esp *esp, struct esp_cmd_entry *ent)
@@ -920,7 +919,7 @@ static void esp_event_queue_full(struct esp *esp, struct esp_cmd_entry *ent)
 static int esp_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 {
        struct scsi_device *dev = cmd->device;
-       struct esp *esp = host_to_esp(dev->host);
+       struct esp *esp = shost_priv(dev->host);
        struct esp_cmd_priv *spriv;
        struct esp_cmd_entry *ent;
 
@@ -981,7 +980,7 @@ static int esp_check_spur_intr(struct esp *esp)
                         */
                        if (!esp->ops->dma_error(esp)) {
                                printk(KERN_ERR PFX "esp%d: Spurious irq, "
-                                      "sreg=%x.\n",
+                                      "sreg=%02x.\n",
                                       esp->host->unique_id, esp->sreg);
                                return -1;
                        }
@@ -1450,8 +1449,11 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
        if (offset > 15)
                goto do_reject;
 
+       if (esp->flags & ESP_FLAG_DISABLE_SYNC)
+               offset = 0;
+
        if (offset) {
-               int rounded_up, one_clock;
+               int one_clock;
 
                if (period > esp->max_period) {
                        period = offset = 0;
@@ -1461,9 +1463,7 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
                        goto do_reject;
 
                one_clock = esp->ccycle / 1000;
-               rounded_up = (period << 2);
-               rounded_up = (rounded_up + one_clock - 1) / one_clock;
-               stp = rounded_up;
+               stp = DIV_ROUND_UP(period << 2, one_clock);
                if (stp && esp->rev >= FAS236) {
                        if (stp >= 50)
                                stp--;
@@ -1700,23 +1700,28 @@ again:
                else
                        ent->flags &= ~ESP_CMD_FLAG_WRITE;
 
-               dma_len = esp_dma_length_limit(esp, dma_addr, dma_len);
+               if (esp->ops->dma_length_limit)
+                       dma_len = esp->ops->dma_length_limit(esp, dma_addr,
+                                                            dma_len);
+               else
+                       dma_len = esp_dma_length_limit(esp, dma_addr, dma_len);
+
                esp->data_dma_len = dma_len;
 
                if (!dma_len) {
                        printk(KERN_ERR PFX "esp%d: DMA length is zero!\n",
                               esp->host->unique_id);
-                       printk(KERN_ERR PFX "esp%d: cur adr[%08x] len[%08x]\n",
+                       printk(KERN_ERR PFX "esp%d: cur adr[%08llx] len[%08x]\n",
                               esp->host->unique_id,
-                              esp_cur_dma_addr(ent, cmd),
+                              (unsigned long long)esp_cur_dma_addr(ent, cmd),
                               esp_cur_dma_len(ent, cmd));
                        esp_schedule_reset(esp);
                        return 0;
                }
 
-               esp_log_datastart("ESP: start data addr[%08x] len[%u] "
+               esp_log_datastart("ESP: start data addr[%08llx] len[%u] "
                                  "write(%d)\n",
-                                 dma_addr, dma_len, write);
+                                 (unsigned long long)dma_addr, dma_len, write);
 
                esp->ops->send_dma_cmd(esp, dma_addr, dma_len, dma_len,
                                       write, ESP_CMD_DMA | ESP_CMD_TI);
@@ -1764,7 +1769,6 @@ again:
                esp_advance_dma(esp, ent, cmd, bytes_sent);
                esp_event(esp, ESP_EVENT_CHECK_PHASE);
                goto again;
-               break;
        }
 
        case ESP_EVENT_STATUS: {
@@ -2029,9 +2033,10 @@ static void esp_reset_cleanup(struct esp *esp)
                tp->flags |= ESP_TGT_CHECK_NEGO;
 
                if (tp->starget)
-                       starget_for_each_device(tp->starget, NULL,
-                                               esp_clear_hold);
+                       __starget_for_each_device(tp->starget, NULL,
+                                                 esp_clear_hold);
        }
+       esp->flags &= ~ESP_FLAG_RESETTING;
 }
 
 /* Runs under host->lock */
@@ -2140,7 +2145,7 @@ irqreturn_t scsi_esp_intr(int irq, void *dev_id)
 }
 EXPORT_SYMBOL(scsi_esp_intr);
 
-static void __devinit esp_get_revision(struct esp *esp)
+static void esp_get_revision(struct esp *esp)
 {
        u8 val;
 
@@ -2189,7 +2194,7 @@ static void __devinit esp_get_revision(struct esp *esp)
        }
 }
 
-static void __devinit esp_init_swstate(struct esp *esp)
+static void esp_init_swstate(struct esp *esp)
 {
        int i;
 
@@ -2211,7 +2216,7 @@ static void __devinit esp_init_swstate(struct esp *esp)
 }
 
 /* This places the ESP into a known state at boot time. */
-static void __devinit esp_bootup_reset(struct esp *esp)
+static void esp_bootup_reset(struct esp *esp)
 {
        u8 val;
 
@@ -2235,9 +2240,9 @@ static void __devinit esp_bootup_reset(struct esp *esp)
        esp_read8(ESP_INTRPT);
 }
 
-static void __devinit esp_set_clock_params(struct esp *esp)
+static void esp_set_clock_params(struct esp *esp)
 {
-       int fmhz;
+       int fhz;
        u8 ccf;
 
        /* This is getting messy but it has to be done correctly or else
@@ -2272,9 +2277,9 @@ static void __devinit esp_set_clock_params(struct esp *esp)
         *    This entails the smallest and largest sync period we could ever
         *    handle on this ESP.
         */
-       fmhz = esp->cfreq;
+       fhz = esp->cfreq;
 
-       ccf = ((fmhz / 1000000) + 4) / 5;
+       ccf = ((fhz / 1000000) + 4) / 5;
        if (ccf == 1)
                ccf = 2;
 
@@ -2283,16 +2288,16 @@ static void __devinit esp_set_clock_params(struct esp *esp)
         * been unable to find the clock-frequency PROM property.  All
         * other machines provide useful values it seems.
         */
-       if (fmhz <= 5000000 || ccf < 1 || ccf > 8) {
-               fmhz = 20000000;
+       if (fhz <= 5000000 || ccf < 1 || ccf > 8) {
+               fhz = 20000000;
                ccf = 4;
        }
 
        esp->cfact = (ccf == 8 ? 0 : ccf);
-       esp->cfreq = fmhz;
-       esp->ccycle = ESP_MHZ_TO_CYCLE(fmhz);
+       esp->cfreq = fhz;
+       esp->ccycle = ESP_HZ_TO_CYCLE(fhz);
        esp->ctick = ESP_TICK(ccf, esp->ccycle);
-       esp->neg_defp = ESP_NEG_DEFP(fmhz, ccf);
+       esp->neg_defp = ESP_NEG_DEFP(fhz, ccf);
        esp->sync_defp = SYNC_DEFP_SLOW;
 }
 
@@ -2308,7 +2313,7 @@ static const char *esp_chip_names[] = {
 
 static struct scsi_transport_template *esp_transport_template;
 
-int __devinit scsi_esp_register(struct esp *esp, struct device *dev)
+int scsi_esp_register(struct esp *esp, struct device *dev)
 {
        static int instance;
        int err;
@@ -2316,6 +2321,7 @@ int __devinit scsi_esp_register(struct esp *esp, struct device *dev)
        esp->host->transportt = esp_transport_template;
        esp->host->max_lun = ESP_MAX_LUN;
        esp->host->cmd_per_lun = 2;
+       esp->host->unique_id = instance;
 
        esp_set_clock_params(esp);
 
@@ -2339,7 +2345,7 @@ int __devinit scsi_esp_register(struct esp *esp, struct device *dev)
        if (err)
                return err;
 
-       esp->host->unique_id = instance++;
+       instance++;
 
        scsi_scan_host(esp->host);
 
@@ -2347,15 +2353,33 @@ int __devinit scsi_esp_register(struct esp *esp, struct device *dev)
 }
 EXPORT_SYMBOL(scsi_esp_register);
 
-void __devexit scsi_esp_unregister(struct esp *esp)
+void scsi_esp_unregister(struct esp *esp)
 {
        scsi_remove_host(esp->host);
 }
 EXPORT_SYMBOL(scsi_esp_unregister);
 
+static int esp_target_alloc(struct scsi_target *starget)
+{
+       struct esp *esp = shost_priv(dev_to_shost(&starget->dev));
+       struct esp_target_data *tp = &esp->target[starget->id];
+
+       tp->starget = starget;
+
+       return 0;
+}
+
+static void esp_target_destroy(struct scsi_target *starget)
+{
+       struct esp *esp = shost_priv(dev_to_shost(&starget->dev));
+       struct esp_target_data *tp = &esp->target[starget->id];
+
+       tp->starget = NULL;
+}
+
 static int esp_slave_alloc(struct scsi_device *dev)
 {
-       struct esp *esp = host_to_esp(dev->host);
+       struct esp *esp = shost_priv(dev->host);
        struct esp_target_data *tp = &esp->target[dev->id];
        struct esp_lun_data *lp;
 
@@ -2364,8 +2388,6 @@ static int esp_slave_alloc(struct scsi_device *dev)
                return -ENOMEM;
        dev->hostdata = lp;
 
-       tp->starget = dev->sdev_target;
-
        spi_min_period(tp->starget) = esp->min_period;
        spi_max_offset(tp->starget) = 15;
 
@@ -2379,10 +2401,16 @@ static int esp_slave_alloc(struct scsi_device *dev)
 
 static int esp_slave_configure(struct scsi_device *dev)
 {
-       struct esp *esp = host_to_esp(dev->host);
+       struct esp *esp = shost_priv(dev->host);
        struct esp_target_data *tp = &esp->target[dev->id];
        int goal_tags, queue_depth;
 
+       if (esp->flags & ESP_FLAG_DISABLE_SYNC) {
+               /* Bypass async domain validation */
+               dev->ppr  = 0;
+               dev->sdtr = 0;
+       }
+
        goal_tags = 0;
 
        if (dev->tagged_supported) {
@@ -2421,7 +2449,7 @@ static void esp_slave_destroy(struct scsi_device *dev)
 
 static int esp_eh_abort_handler(struct scsi_cmnd *cmd)
 {
-       struct esp *esp = host_to_esp(cmd->device->host);
+       struct esp *esp = shost_priv(cmd->device->host);
        struct esp_cmd_entry *ent, *tmp;
        struct completion eh_done;
        unsigned long flags;
@@ -2537,7 +2565,7 @@ out_failure:
 
 static int esp_eh_bus_reset_handler(struct scsi_cmnd *cmd)
 {
-       struct esp *esp = host_to_esp(cmd->device->host);
+       struct esp *esp = shost_priv(cmd->device->host);
        struct completion eh_reset;
        unsigned long flags;
 
@@ -2573,7 +2601,7 @@ static int esp_eh_bus_reset_handler(struct scsi_cmnd *cmd)
 /* All bets are off, reset the entire device.  */
 static int esp_eh_host_reset_handler(struct scsi_cmnd *cmd)
 {
-       struct esp *esp = host_to_esp(cmd->device->host);
+       struct esp *esp = shost_priv(cmd->device->host);
        unsigned long flags;
 
        spin_lock_irqsave(esp->host->host_lock, flags);
@@ -2596,6 +2624,8 @@ struct scsi_host_template scsi_esp_template = {
        .name                   = "esp",
        .info                   = esp_info,
        .queuecommand           = esp_queuecommand,
+       .target_alloc           = esp_target_alloc,
+       .target_destroy         = esp_target_destroy,
        .slave_alloc            = esp_slave_alloc,
        .slave_configure        = esp_slave_configure,
        .slave_destroy          = esp_slave_destroy,
@@ -2613,7 +2643,7 @@ EXPORT_SYMBOL(scsi_esp_template);
 
 static void esp_get_signalling(struct Scsi_Host *host)
 {
-       struct esp *esp = host_to_esp(host);
+       struct esp *esp = shost_priv(host);
        enum spi_signal_type type;
 
        if (esp->flags & ESP_FLAG_DIFFERENTIAL)
@@ -2627,7 +2657,7 @@ static void esp_get_signalling(struct Scsi_Host *host)
 static void esp_set_offset(struct scsi_target *target, int offset)
 {
        struct Scsi_Host *host = dev_to_shost(target->dev.parent);
-       struct esp *esp = host_to_esp(host);
+       struct esp *esp = shost_priv(host);
        struct esp_target_data *tp = &esp->target[target->id];
 
        tp->nego_goal_offset = offset;
@@ -2637,7 +2667,7 @@ static void esp_set_offset(struct scsi_target *target, int offset)
 static void esp_set_period(struct scsi_target *target, int period)
 {
        struct Scsi_Host *host = dev_to_shost(target->dev.parent);
-       struct esp *esp = host_to_esp(host);
+       struct esp *esp = shost_priv(host);
        struct esp_target_data *tp = &esp->target[target->id];
 
        tp->nego_goal_period = period;
@@ -2647,7 +2677,7 @@ static void esp_set_period(struct scsi_target *target, int period)
 static void esp_set_width(struct scsi_target *target, int width)
 {
        struct Scsi_Host *host = dev_to_shost(target->dev.parent);
-       struct esp *esp = host_to_esp(host);
+       struct esp *esp = shost_priv(host);
        struct esp_target_data *tp = &esp->target[target->id];
 
        tp->nego_goal_width = (width ? 1 : 0);