vserver 1.9.5.x5
[linux-2.6.git] / drivers / message / i2o / i2o_scsi.c
index 9be68f3..43f5875 100644 (file)
@@ -65,7 +65,9 @@
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_cmnd.h>
 
-#define VERSION_STRING        "Version 0.1.2"
+#define OSM_NAME       "scsi-osm"
+#define OSM_VERSION    "$Rev$"
+#define OSM_DESCRIPTION        "I2O SCSI Peripheral OSM"
 
 static struct i2o_driver i2o_scsi_driver;
 
@@ -106,8 +108,7 @@ static struct i2o_scsi_host *i2o_scsi_host_alloc(struct i2o_controller *c)
        }
 
        if (!max_channel) {
-               printk(KERN_WARNING "scsi-osm: no channels found on %s\n",
-                      c->name);
+               osm_warn("no channels found on %s\n", c->name);
                return ERR_PTR(-EFAULT);
        }
 
@@ -116,7 +117,7 @@ static struct i2o_scsi_host *i2o_scsi_host_alloc(struct i2o_controller *c)
 
        scsi_host = scsi_host_alloc(&i2o_scsi_host_template, size);
        if (!scsi_host) {
-               printk(KERN_WARNING "scsi-osm: Could not allocate SCSI host\n");
+               osm_warn("Could not allocate SCSI host\n");
                return ERR_PTR(-ENOMEM);
        }
 
@@ -221,24 +222,23 @@ static int i2o_scsi_probe(struct device *dev)
                return -EFAULT;
 
        if (id >= scsi_host->max_id) {
-               printk(KERN_WARNING "scsi-osm: SCSI device id (%d) >= max_id "
-                      "of I2O host (%d)", id, scsi_host->max_id);
+               osm_warn("SCSI device id (%d) >= max_id of I2O host (%d)", id,
+                        scsi_host->max_id);
                return -EFAULT;
        }
 
        if (i2o_parm_field_get(i2o_dev, 0, 4, &lun, 8) < 0)
                return -EFAULT;
        if (lun >= scsi_host->max_lun) {
-               printk(KERN_WARNING "scsi-osm: SCSI device id (%d) >= max_lun "
-                      "of I2O host (%d)", (unsigned int)lun,
-                      scsi_host->max_lun);
+               osm_warn("SCSI device id (%d) >= max_lun of I2O host (%d)",
+                        (unsigned int)lun, scsi_host->max_lun);
                return -EFAULT;
        }
 
        parent = i2o_iop_find_device(c, i2o_dev->lct_data.parent_tid);
        if (!parent) {
-               printk(KERN_WARNING "scsi-osm: can not find parent of device "
-                      "%03x\n", i2o_dev->lct_data.tid);
+               osm_warn("can not find parent of device %03x\n",
+                        i2o_dev->lct_data.tid);
                return -EFAULT;
        }
 
@@ -247,8 +247,8 @@ static int i2o_scsi_probe(struct device *dev)
                        channel = i;
 
        if (channel == -1) {
-               printk(KERN_WARNING "scsi-osm: can not find channel of device "
-                      "%03x\n", i2o_dev->lct_data.tid);
+               osm_warn("can not find channel of device %03x\n",
+                        i2o_dev->lct_data.tid);
                return -EFAULT;
        }
 
@@ -256,13 +256,13 @@ static int i2o_scsi_probe(struct device *dev)
            __scsi_add_device(i2o_shost->scsi_host, channel, id, lun, i2o_dev);
 
        if (!scsi_dev) {
-               printk(KERN_WARNING "scsi-osm: can not add SCSI device "
-                      "%03x\n", i2o_dev->lct_data.tid);
+               osm_warn("can not add SCSI device %03x\n",
+                        i2o_dev->lct_data.tid);
                return -EFAULT;
        }
 
-       pr_debug("Added new SCSI device %03x (cannel: %d, id: %d, lun: %d)\n",
-                i2o_dev->lct_data.tid, channel, id, (unsigned int)lun);
+       osm_debug("added new SCSI device %03x (cannel: %d, id: %d, lun: %d)\n",
+                 i2o_dev->lct_data.tid, channel, id, (unsigned int)lun);
 
        return 0;
 };
@@ -274,53 +274,6 @@ static const char *i2o_scsi_info(struct Scsi_Host *SChost)
        return hostdata->iop->name;
 }
 
-#if 0
-/**
- *     i2o_retry_run           -       retry on timeout
- *     @f: unused
- *
- *     Retry congested frames. This actually needs pushing down into
- *     i2o core. We should only bother the OSM with this when we can't
- *     queue and retry the frame. Or perhaps we should call the OSM
- *     and its default handler should be this in the core, and this
- *     call a 2nd "I give up" handler in the OSM ?
- */
-
-static void i2o_retry_run(unsigned long f)
-{
-       int i;
-       unsigned long flags;
-
-       spin_lock_irqsave(&retry_lock, flags);
-       for (i = 0; i < retry_ct; i++)
-               i2o_post_message(retry_ctrl[i], virt_to_bus(retry[i]));
-       retry_ct = 0;
-       spin_unlock_irqrestore(&retry_lock, flags);
-}
-
-/**
- *     flush_pending           -       empty the retry queue
- *
- *     Turn each of the pending commands into a NOP and post it back
- *     to the controller to clear it.
- */
-
-static void flush_pending(void)
-{
-       int i;
-       unsigned long flags;
-
-       spin_lock_irqsave(&retry_lock, flags);
-       for (i = 0; i < retry_ct; i++) {
-               retry[i][0] &= ~0xFFFFFF;
-               retry[i][0] |= I2O_CMD_UTIL_NOP << 24;
-               i2o_post_message(retry_ctrl[i], virt_to_bus(retry[i]));
-       }
-       retry_ct = 0;
-       spin_unlock_irqrestore(&retry_lock, flags);
-}
-#endif
-
 /**
  *     i2o_scsi_reply - SCSI OSM message reply handler
  *     @c: controller issuing the reply
@@ -343,38 +296,41 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
        struct device *dev;
        u8 as, ds, st;
 
-       cmd = i2o_cntxt_list_get(c, readl(&msg->u.s.tcntxt));
+       cmd = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt));
 
        if (msg->u.head[0] & (1 << 13)) {
-               struct i2o_message *pmsg;       /* preserved message */
+               struct i2o_message __iomem *pmsg;       /* preserved message */
                u32 pm;
+               int err = DID_ERROR;
 
-               pm = readl(&msg->body[3]);
+               pm = le32_to_cpu(msg->body[3]);
 
-               pmsg = c->in_queue.virt + pm;
+               pmsg = i2o_msg_in_to_virt(c, pm);
 
-               printk("IOP fail.\n");
-               printk("From %d To %d Cmd %d.\n",
-                      (msg->u.head[1] >> 12) & 0xFFF,
-                      msg->u.head[1] & 0xFFF, msg->u.head[1] >> 24);
-               printk("Failure Code %d.\n", msg->body[0] >> 24);
+               osm_err("IOP fail.\n");
+               osm_err("From %d To %d Cmd %d.\n",
+                       (msg->u.head[1] >> 12) & 0xFFF,
+                       msg->u.head[1] & 0xFFF, msg->u.head[1] >> 24);
+               osm_err("Failure Code %d.\n", msg->body[0] >> 24);
                if (msg->body[0] & (1 << 16))
-                       printk("Format error.\n");
+                       osm_err("Format error.\n");
                if (msg->body[0] & (1 << 17))
-                       printk("Path error.\n");
+                       osm_err("Path error.\n");
                if (msg->body[0] & (1 << 18))
-                       printk("Path State.\n");
+                       osm_err("Path State.\n");
                if (msg->body[0] & (1 << 18))
-                       printk("Congestion.\n");
+               {
+                       osm_err("Congestion.\n");
+                       err = DID_BUS_BUSY;
+               }
 
-               printk("Failing message is %p.\n", pmsg);
+               osm_debug("Failing message is %p.\n", pmsg);
 
                cmd = i2o_cntxt_list_get(c, readl(&pmsg->u.s.tcntxt));
                if (!cmd)
                        return 1;
 
-               printk("Aborted %ld\n", cmd->serial_number);
-               cmd->result = DID_ERROR << 16;
+               cmd->result = err << 16;
                cmd->scsi_done(cmd);
 
                /* Now flush the message by making it a NOP */
@@ -387,9 +343,9 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
         *      Low byte is device status, next is adapter status,
         *      (then one byte reserved), then request status.
         */
-       ds = (u8) readl(&msg->body[0]);
-       as = (u8) (readl(&msg->body[0]) >> 8);
-       st = (u8) (readl(&msg->body[0]) >> 24);
+       ds = (u8) le32_to_cpu(msg->body[0]);
+       as = (u8) (le32_to_cpu(msg->body[0]) >> 8);
+       st = (u8) (le32_to_cpu(msg->body[0]) >> 24);
 
        /*
         *      Is this a control request coming back - eg an abort ?
@@ -397,13 +353,12 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
 
        if (!cmd) {
                if (st)
-                       printk(KERN_WARNING "SCSI abort: %08X",
-                              readl(&msg->body[0]));
-               printk(KERN_INFO "SCSI abort completed.\n");
+                       osm_warn("SCSI abort: %08X", le32_to_cpu(msg->body[0]));
+               osm_info("SCSI abort completed.\n");
                return -EFAULT;
        }
 
-       pr_debug("Completed %ld\n", cmd->serial_number);
+       osm_debug("Completed %ld\n", cmd->serial_number);
 
        if (st) {
                u32 count, error;
@@ -411,23 +366,24 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
 
                switch (st) {
                case 0x06:
-                       count = readl(&msg->body[1]);
+                       count = le32_to_cpu(msg->body[1]);
                        if (count < cmd->underflow) {
                                int i;
-                               printk(KERN_ERR "SCSI: underflow 0x%08X 0x%08X"
-                                      "\n", count, cmd->underflow);
-                               printk("Cmd: ");
+
+                               osm_err("SCSI underflow 0x%08X 0x%08X\n", count,
+                                       cmd->underflow);
+                               osm_debug("Cmd: ");
                                for (i = 0; i < 15; i++)
-                                       printk("%02X ", cmd->cmnd[i]);
-                               printk(".\n");
+                                       pr_debug("%02X ", cmd->cmnd[i]);
+                               pr_debug(".\n");
                                cmd->result = (DID_ERROR << 16);
                        }
                        break;
 
                default:
-                       error = readl(&msg->body[0]);
+                       error = le32_to_cpu(msg->body[0]);
 
-                       printk(KERN_ERR "scsi-osm: SCSI error %08x\n", error);
+                       osm_err("SCSI error %08x\n", error);
 
                        if ((error & 0xff) == 0x02 /*CHECK_CONDITION */ ) {
                                int i;
@@ -437,8 +393,8 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
                                memcpy(cmd->sense_buffer, (void *)&msg->body[3],
                                       len);
                                for (i = 0; i <= len; i++)
-                                       printk(KERN_INFO "%02x\n",
-                                              cmd->sense_buffer[i]);
+                                       osm_info("%02x\n",
+                                                cmd->sense_buffer[i]);
                                if (cmd->sense_buffer[0] == 0x70
                                    && cmd->sense_buffer[2] == DATA_PROTECT) {
                                        /* This is to handle an array failed */
@@ -503,29 +459,27 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
  *     If a I2O controller is added, we catch the notification to add a
  *     corresponding Scsi_Host.
  */
-void i2o_scsi_notify_controller_add(struct i2o_controller *c)
+static void i2o_scsi_notify_controller_add(struct i2o_controller *c)
 {
        struct i2o_scsi_host *i2o_shost;
        int rc;
 
        i2o_shost = i2o_scsi_host_alloc(c);
        if (IS_ERR(i2o_shost)) {
-               printk(KERN_ERR "scsi-osm: Could not initialize"
-                      " SCSI host\n");
+               osm_err("Could not initialize SCSI host\n");
                return;
        }
 
        rc = scsi_add_host(i2o_shost->scsi_host, &c->device);
        if (rc) {
-               printk(KERN_ERR "scsi-osm: Could not add SCSI "
-                      "host\n");
+               osm_err("Could not add SCSI host\n");
                scsi_host_put(i2o_shost->scsi_host);
                return;
        }
 
        c->driver_data[i2o_scsi_driver.context] = i2o_shost;
 
-       pr_debug("new I2O SCSI host added\n");
+       osm_debug("new I2O SCSI host added\n");
 };
 
 /**
@@ -536,7 +490,7 @@ void i2o_scsi_notify_controller_add(struct i2o_controller *c)
  *     If a I2O controller is removed, we catch the notification to remove the
  *     corresponding Scsi_Host.
  */
-void i2o_scsi_notify_controller_remove(struct i2o_controller *c)
+static void i2o_scsi_notify_controller_remove(struct i2o_controller *c)
 {
        struct i2o_scsi_host *i2o_shost;
        i2o_shost = i2o_scsi_get_host(c);
@@ -547,12 +501,12 @@ void i2o_scsi_notify_controller_remove(struct i2o_controller *c)
 
        scsi_remove_host(i2o_shost->scsi_host);
        scsi_host_put(i2o_shost->scsi_host);
-       pr_debug("I2O SCSI host removed\n");
+       pr_info("I2O SCSI host removed\n");
 };
 
 /* SCSI OSM driver struct */
 static struct i2o_driver i2o_scsi_driver = {
-       .name = "scsi-osm",
+       .name = OSM_NAME,
        .reply = i2o_scsi_reply,
        .classes = i2o_scsi_class_id,
        .notify_controller_add = i2o_scsi_notify_controller_add,
@@ -585,10 +539,11 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
        struct i2o_device *i2o_dev;
        struct device *dev;
        int tid;
-       struct i2o_message *msg;
+       struct i2o_message __iomem *msg;
        u32 m;
        u32 scsi_flags, sg_flags;
-       u32 *mptr, *lenptr;
+       u32 __iomem *mptr;
+       u32 __iomem *lenptr;
        u32 len, reqlen;
        int i;
 
@@ -604,7 +559,7 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
        SCpnt->scsi_done = done;
 
        if (unlikely(!i2o_dev)) {
-               printk(KERN_WARNING "scsi-osm: no I2O device in request\n");
+               osm_warn("no I2O device in request\n");
                SCpnt->result = DID_NO_CONNECT << 16;
                done(SCpnt);
                return 0;
@@ -612,8 +567,8 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
 
        tid = i2o_dev->lct_data.tid;
 
-       pr_debug("qcmd: Tid = %03x\n", tid);
-       pr_debug("Real scsi messages.\n");
+       osm_debug("qcmd: Tid = %03x\n", tid);
+       osm_debug("Real scsi messages.\n");
 
        /*
         *      Obtain an I2O message. If there are none free then
@@ -745,7 +700,7 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
        /* Queue the message */
        i2o_msg_post(c, m);
 
-       pr_debug("Issued %ld\n", SCpnt->serial_number);
+       osm_debug("Issued %ld\n", SCpnt->serial_number);
 
        return 0;
 };
@@ -761,16 +716,16 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
  *     Returns 0 if the command is successfully aborted or negative error code
  *     on failure.
  */
-int i2o_scsi_abort(struct scsi_cmnd *SCpnt)
+static int i2o_scsi_abort(struct scsi_cmnd *SCpnt)
 {
        struct i2o_device *i2o_dev;
        struct i2o_controller *c;
-       struct i2o_message *msg;
+       struct i2o_message __iomem *msg;
        u32 m;
        int tid;
        int status = FAILED;
 
-       printk(KERN_WARNING "i2o_scsi: Aborting command block.\n");
+       osm_warn("Aborting command block.\n");
 
        i2o_dev = SCpnt->device->hostdata;
        c = i2o_dev->iop;
@@ -820,8 +775,8 @@ static int i2o_scsi_bios_param(struct scsi_device *sdev,
 }
 
 static struct scsi_host_template i2o_scsi_host_template = {
-       .proc_name = "SCSI-OSM",
-       .name = "I2O SCSI Peripheral OSM",
+       .proc_name = OSM_NAME,
+       .name = OSM_DESCRIPTION,
        .info = i2o_scsi_info,
        .queuecommand = i2o_scsi_queuecommand,
        .eh_abort_handler = i2o_scsi_abort,
@@ -832,15 +787,6 @@ static struct scsi_host_template i2o_scsi_host_template = {
        .use_clustering = ENABLE_CLUSTERING,
 };
 
-/*
-int
-i2o_scsi_queuecommand(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
-{
-       printk(KERN_INFO "queuecommand\n");
-       return SCSI_MLQUEUE_HOST_BUSY;
-};
-*/
-
 /**
  *     i2o_scsi_init - SCSI OSM initialization function
  *
@@ -852,12 +798,12 @@ static int __init i2o_scsi_init(void)
 {
        int rc;
 
-       printk(KERN_INFO "I2O SCSI Peripheral OSM\n");
+       printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
 
        /* Register SCSI OSM into I2O core */
        rc = i2o_driver_register(&i2o_scsi_driver);
        if (rc) {
-               printk(KERN_ERR "scsi-osm: Could not register SCSI driver\n");
+               osm_err("Could not register SCSI driver\n");
                return rc;
        }
 
@@ -877,6 +823,8 @@ static void __exit i2o_scsi_exit(void)
 
 MODULE_AUTHOR("Red Hat Software");
 MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION(OSM_DESCRIPTION);
+MODULE_VERSION(OSM_VERSION);
 
 module_init(i2o_scsi_init);
 module_exit(i2o_scsi_exit);