Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify it |
| 3 | * under the terms of the GNU General Public License as published by the |
| 4 | * Free Software Foundation; either version 2, or (at your option) any |
| 5 | * later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, but |
| 8 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 | * General Public License for more details. |
| 11 | * |
| 12 | * For the avoidance of doubt the "preferred form" of this code is one which |
| 13 | * is in an open non patent encumbered format. Where cryptographic key signing |
| 14 | * forms part of the process of creating an executable the information |
| 15 | * including keys needed to generate an equivalently functional executable |
| 16 | * are deemed to be part of the source code. |
| 17 | * |
| 18 | * Complications for I2O scsi |
| 19 | * |
| 20 | * o Each (bus,lun) is a logical device in I2O. We keep a map |
| 21 | * table. We spoof failed selection for unmapped units |
| 22 | * o Request sense buffers can come back for free. |
| 23 | * o Scatter gather is a bit dynamic. We have to investigate at |
| 24 | * setup time. |
| 25 | * o Some of our resources are dynamically shared. The i2o core |
| 26 | * needs a message reservation protocol to avoid swap v net |
| 27 | * deadlocking. We need to back off queue requests. |
| 28 | * |
| 29 | * In general the firmware wants to help. Where its help isn't performance |
| 30 | * useful we just ignore the aid. Its not worth the code in truth. |
| 31 | * |
| 32 | * Fixes/additions: |
| 33 | * Steve Ralston: |
| 34 | * Scatter gather now works |
| 35 | * Markus Lidel <Markus.Lidel@shadowconnect.com>: |
| 36 | * Minor fixes for 2.6. |
| 37 | * |
| 38 | * To Do: |
| 39 | * 64bit cleanups |
| 40 | * Fix the resource management problems. |
| 41 | */ |
| 42 | |
| 43 | #include <linux/module.h> |
| 44 | #include <linux/kernel.h> |
| 45 | #include <linux/types.h> |
| 46 | #include <linux/string.h> |
| 47 | #include <linux/ioport.h> |
| 48 | #include <linux/jiffies.h> |
| 49 | #include <linux/interrupt.h> |
| 50 | #include <linux/timer.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/proc_fs.h> |
| 53 | #include <linux/prefetch.h> |
| 54 | #include <linux/pci.h> |
| 55 | #include <linux/blkdev.h> |
| 56 | #include <linux/i2o.h> |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 57 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <asm/io.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 61 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | #include <scsi/scsi.h> |
| 64 | #include <scsi/scsi_host.h> |
| 65 | #include <scsi/scsi_device.h> |
| 66 | #include <scsi/scsi_cmnd.h> |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 67 | #include <scsi/sg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define OSM_NAME "scsi-osm" |
Markus Lidel | 2e1973a | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 70 | #define OSM_VERSION "1.316" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define OSM_DESCRIPTION "I2O SCSI Peripheral OSM" |
| 72 | |
| 73 | static struct i2o_driver i2o_scsi_driver; |
| 74 | |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 75 | static unsigned int i2o_scsi_max_id = 16; |
| 76 | static unsigned int i2o_scsi_max_lun = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | struct i2o_scsi_host { |
| 79 | struct Scsi_Host *scsi_host; /* pointer to the SCSI host */ |
| 80 | struct i2o_controller *iop; /* pointer to the I2O controller */ |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 81 | unsigned int lun; /* lun's used for block devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct i2o_device *channel[0]; /* channel->i2o_dev mapping table */ |
| 83 | }; |
| 84 | |
| 85 | static struct scsi_host_template i2o_scsi_host_template; |
| 86 | |
| 87 | #define I2O_SCSI_CAN_QUEUE 4 |
| 88 | |
| 89 | /* SCSI OSM class handling definition */ |
| 90 | static struct i2o_class_id i2o_scsi_class_id[] = { |
| 91 | {I2O_CLASS_SCSI_PERIPHERAL}, |
| 92 | {I2O_CLASS_END} |
| 93 | }; |
| 94 | |
| 95 | static struct i2o_scsi_host *i2o_scsi_host_alloc(struct i2o_controller *c) |
| 96 | { |
| 97 | struct i2o_scsi_host *i2o_shost; |
| 98 | struct i2o_device *i2o_dev; |
| 99 | struct Scsi_Host *scsi_host; |
| 100 | int max_channel = 0; |
| 101 | u8 type; |
| 102 | int i; |
| 103 | size_t size; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 104 | u16 body_size = 6; |
| 105 | |
| 106 | #ifdef CONFIG_I2O_EXT_ADAPTEC |
| 107 | if (c->adaptec) |
| 108 | body_size = 8; |
| 109 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | list_for_each_entry(i2o_dev, &c->devices, list) |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 112 | if (i2o_dev->lct_data.class_id == I2O_CLASS_BUS_ADAPTER) { |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 113 | if (!i2o_parm_field_get(i2o_dev, 0x0000, 0, &type, 1) |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 114 | && (type == 0x01)) /* SCSI bus */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | max_channel++; |
| 116 | } |
| 117 | |
| 118 | if (!max_channel) { |
| 119 | osm_warn("no channels found on %s\n", c->name); |
| 120 | return ERR_PTR(-EFAULT); |
| 121 | } |
| 122 | |
| 123 | size = max_channel * sizeof(struct i2o_device *) |
| 124 | + sizeof(struct i2o_scsi_host); |
| 125 | |
| 126 | scsi_host = scsi_host_alloc(&i2o_scsi_host_template, size); |
| 127 | if (!scsi_host) { |
| 128 | osm_warn("Could not allocate SCSI host\n"); |
| 129 | return ERR_PTR(-ENOMEM); |
| 130 | } |
| 131 | |
| 132 | scsi_host->max_channel = max_channel - 1; |
| 133 | scsi_host->max_id = i2o_scsi_max_id; |
| 134 | scsi_host->max_lun = i2o_scsi_max_lun; |
| 135 | scsi_host->this_id = c->unit; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 136 | scsi_host->sg_tablesize = i2o_sg_tablesize(c, body_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | i2o_shost = (struct i2o_scsi_host *)scsi_host->hostdata; |
| 139 | i2o_shost->scsi_host = scsi_host; |
| 140 | i2o_shost->iop = c; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 141 | i2o_shost->lun = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | i = 0; |
| 144 | list_for_each_entry(i2o_dev, &c->devices, list) |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 145 | if (i2o_dev->lct_data.class_id == I2O_CLASS_BUS_ADAPTER) { |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 146 | if (!i2o_parm_field_get(i2o_dev, 0x0000, 0, &type, 1) |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 147 | && (type == 0x01)) /* only SCSI bus */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | i2o_shost->channel[i++] = i2o_dev; |
| 149 | |
| 150 | if (i >= max_channel) |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | return i2o_shost; |
| 155 | }; |
| 156 | |
| 157 | /** |
| 158 | * i2o_scsi_get_host - Get an I2O SCSI host |
| 159 | * @c: I2O controller to for which to get the SCSI host |
| 160 | * |
| 161 | * If the I2O controller already exists as SCSI host, the SCSI host |
| 162 | * is returned, otherwise the I2O controller is added to the SCSI |
| 163 | * core. |
| 164 | * |
| 165 | * Returns pointer to the I2O SCSI host on success or NULL on failure. |
| 166 | */ |
| 167 | static struct i2o_scsi_host *i2o_scsi_get_host(struct i2o_controller *c) |
| 168 | { |
| 169 | return c->driver_data[i2o_scsi_driver.context]; |
| 170 | }; |
| 171 | |
| 172 | /** |
| 173 | * i2o_scsi_remove - Remove I2O device from SCSI core |
| 174 | * @dev: device which should be removed |
| 175 | * |
| 176 | * Removes the I2O device from the SCSI core again. |
| 177 | * |
| 178 | * Returns 0 on success. |
| 179 | */ |
| 180 | static int i2o_scsi_remove(struct device *dev) |
| 181 | { |
| 182 | struct i2o_device *i2o_dev = to_i2o_device(dev); |
| 183 | struct i2o_controller *c = i2o_dev->iop; |
| 184 | struct i2o_scsi_host *i2o_shost; |
| 185 | struct scsi_device *scsi_dev; |
| 186 | |
Markus Lidel | f88e119 | 2005-06-23 22:02:14 -0700 | [diff] [blame] | 187 | osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid); |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | i2o_shost = i2o_scsi_get_host(c); |
| 190 | |
| 191 | shost_for_each_device(scsi_dev, i2o_shost->scsi_host) |
| 192 | if (scsi_dev->hostdata == i2o_dev) { |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 193 | sysfs_remove_link(&i2o_dev->device.kobj, "scsi"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | scsi_remove_device(scsi_dev); |
| 195 | scsi_device_put(scsi_dev); |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | }; |
| 201 | |
| 202 | /** |
| 203 | * i2o_scsi_probe - verify if dev is a I2O SCSI device and install it |
| 204 | * @dev: device to verify if it is a I2O SCSI device |
| 205 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 206 | * Retrieve channel, id and lun for I2O device. If everything goes well |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | * register the I2O device as SCSI device on the I2O SCSI controller. |
| 208 | * |
| 209 | * Returns 0 on success or negative error code on failure. |
| 210 | */ |
| 211 | static int i2o_scsi_probe(struct device *dev) |
| 212 | { |
| 213 | struct i2o_device *i2o_dev = to_i2o_device(dev); |
| 214 | struct i2o_controller *c = i2o_dev->iop; |
| 215 | struct i2o_scsi_host *i2o_shost; |
| 216 | struct Scsi_Host *scsi_host; |
| 217 | struct i2o_device *parent; |
| 218 | struct scsi_device *scsi_dev; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 219 | u32 id = -1; |
| 220 | u64 lun = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | int channel = -1; |
Jeff Garzik | 3889b26 | 2006-12-06 20:35:31 -0800 | [diff] [blame] | 222 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | i2o_shost = i2o_scsi_get_host(c); |
| 225 | if (!i2o_shost) |
| 226 | return -EFAULT; |
| 227 | |
| 228 | scsi_host = i2o_shost->scsi_host; |
| 229 | |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 230 | switch (i2o_dev->lct_data.class_id) { |
| 231 | case I2O_CLASS_RANDOM_BLOCK_STORAGE: |
| 232 | case I2O_CLASS_EXECUTIVE: |
| 233 | #ifdef CONFIG_I2O_EXT_ADAPTEC |
| 234 | if (c->adaptec) { |
| 235 | u8 type; |
| 236 | struct i2o_device *d = i2o_shost->channel[0]; |
| 237 | |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 238 | if (!i2o_parm_field_get(d, 0x0000, 0, &type, 1) |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 239 | && (type == 0x01)) /* SCSI bus */ |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 240 | if (!i2o_parm_field_get(d, 0x0200, 4, &id, 4)) { |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 241 | channel = 0; |
| 242 | if (i2o_dev->lct_data.class_id == |
| 243 | I2O_CLASS_RANDOM_BLOCK_STORAGE) |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 244 | lun = |
| 245 | cpu_to_le64(i2o_shost-> |
| 246 | lun++); |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 247 | else |
| 248 | lun = 0; |
| 249 | } |
| 250 | } |
| 251 | #endif |
| 252 | break; |
| 253 | |
| 254 | case I2O_CLASS_SCSI_PERIPHERAL: |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 255 | if (i2o_parm_field_get(i2o_dev, 0x0000, 3, &id, 4)) |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 256 | return -EFAULT; |
| 257 | |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 258 | if (i2o_parm_field_get(i2o_dev, 0x0000, 4, &lun, 8)) |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 259 | return -EFAULT; |
| 260 | |
| 261 | parent = i2o_iop_find_device(c, i2o_dev->lct_data.parent_tid); |
| 262 | if (!parent) { |
| 263 | osm_warn("can not find parent of device %03x\n", |
| 264 | i2o_dev->lct_data.tid); |
| 265 | return -EFAULT; |
| 266 | } |
| 267 | |
| 268 | for (i = 0; i <= i2o_shost->scsi_host->max_channel; i++) |
| 269 | if (i2o_shost->channel[i] == parent) |
| 270 | channel = i; |
| 271 | break; |
| 272 | |
| 273 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return -EFAULT; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | if (channel == -1) { |
| 278 | osm_warn("can not find channel of device %03x\n", |
| 279 | i2o_dev->lct_data.tid); |
| 280 | return -EFAULT; |
| 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 283 | if (le32_to_cpu(id) >= scsi_host->max_id) { |
| 284 | osm_warn("SCSI device id (%d) >= max_id of I2O host (%d)", |
| 285 | le32_to_cpu(id), scsi_host->max_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return -EFAULT; |
| 287 | } |
| 288 | |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 289 | if (le64_to_cpu(lun) >= scsi_host->max_lun) { |
| 290 | osm_warn("SCSI device lun (%lu) >= max_lun of I2O host (%d)", |
| 291 | (long unsigned int)le64_to_cpu(lun), |
| 292 | scsi_host->max_lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | return -EFAULT; |
| 294 | } |
| 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | scsi_dev = |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 297 | __scsi_add_device(i2o_shost->scsi_host, channel, le32_to_cpu(id), |
| 298 | le64_to_cpu(lun), i2o_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 300 | if (IS_ERR(scsi_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | osm_warn("can not add SCSI device %03x\n", |
| 302 | i2o_dev->lct_data.tid); |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 303 | return PTR_ERR(scsi_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Jeff Garzik | 3889b26 | 2006-12-06 20:35:31 -0800 | [diff] [blame] | 306 | rc = sysfs_create_link(&i2o_dev->device.kobj, |
| 307 | &scsi_dev->sdev_gendev.kobj, "scsi"); |
| 308 | if (rc) |
| 309 | goto err; |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 310 | |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 311 | osm_info("device added (TID: %03x) channel: %d, id: %d, lun: %ld\n", |
Markus Lidel | 793fd15 | 2006-01-06 00:19:30 -0800 | [diff] [blame] | 312 | i2o_dev->lct_data.tid, channel, le32_to_cpu(id), |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 313 | (long unsigned int)le64_to_cpu(lun)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | return 0; |
Jeff Garzik | 3889b26 | 2006-12-06 20:35:31 -0800 | [diff] [blame] | 316 | |
| 317 | err: |
| 318 | scsi_remove_device(scsi_dev); |
| 319 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | static const char *i2o_scsi_info(struct Scsi_Host *SChost) |
| 323 | { |
| 324 | struct i2o_scsi_host *hostdata; |
| 325 | hostdata = (struct i2o_scsi_host *)SChost->hostdata; |
| 326 | return hostdata->iop->name; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * i2o_scsi_reply - SCSI OSM message reply handler |
| 331 | * @c: controller issuing the reply |
| 332 | * @m: message id for flushing |
| 333 | * @msg: the message from the controller |
| 334 | * |
| 335 | * Process reply messages (interrupts in normal scsi controller think). |
| 336 | * We can get a variety of messages to process. The normal path is |
| 337 | * scsi command completions. We must also deal with IOP failures, |
| 338 | * the reply to a bus reset and the reply to a LUN query. |
| 339 | * |
| 340 | * Returns 0 on success and if the reply should not be flushed or > 0 |
| 341 | * on success and if the reply should be flushed. Returns negative error |
| 342 | * code on failure and if the reply should be flushed. |
| 343 | */ |
| 344 | static int i2o_scsi_reply(struct i2o_controller *c, u32 m, |
| 345 | struct i2o_message *msg) |
| 346 | { |
| 347 | struct scsi_cmnd *cmd; |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 348 | u32 error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | cmd = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt)); |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 352 | if (unlikely(!cmd)) { |
| 353 | osm_err("NULL reply received!\n"); |
| 354 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Low byte is device status, next is adapter status, |
| 359 | * (then one byte reserved), then request status. |
| 360 | */ |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 361 | error = le32_to_cpu(msg->body[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 363 | osm_debug("Completed %0x%p\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 365 | cmd->result = error & 0xff; |
| 366 | /* |
| 367 | * if DeviceStatus is not SCSI_SUCCESS copy over the sense data and let |
| 368 | * the SCSI layer handle the error |
| 369 | */ |
| 370 | if (cmd->result) |
| 371 | memcpy(cmd->sense_buffer, &msg->body[3], |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 372 | min(SCSI_SENSE_BUFFERSIZE, 40)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 374 | /* only output error code if AdapterStatus is not HBA_SUCCESS */ |
| 375 | if ((error >> 8) & 0xff) |
| 376 | osm_err("SCSI error %08x\n", error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | dev = &c->pdev->dev; |
FUJITA Tomonori | 0ea7154 | 2007-06-14 00:41:06 +0900 | [diff] [blame] | 379 | |
| 380 | scsi_dma_unmap(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Markus Lidel | f88e119 | 2005-06-23 22:02:14 -0700 | [diff] [blame] | 382 | cmd->scsi_done(cmd); |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 1; |
| 385 | }; |
| 386 | |
| 387 | /** |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 388 | * i2o_scsi_notify_device_add - Retrieve notifications of added devices |
| 389 | * @i2o_dev: the I2O device which was added |
| 390 | * |
| 391 | * If a I2O device is added we catch the notification, because I2O classes |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 392 | * other than SCSI peripheral will not be received through |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 393 | * i2o_scsi_probe(). |
| 394 | */ |
| 395 | static void i2o_scsi_notify_device_add(struct i2o_device *i2o_dev) |
| 396 | { |
| 397 | switch (i2o_dev->lct_data.class_id) { |
| 398 | case I2O_CLASS_EXECUTIVE: |
| 399 | case I2O_CLASS_RANDOM_BLOCK_STORAGE: |
| 400 | i2o_scsi_probe(&i2o_dev->device); |
| 401 | break; |
| 402 | |
| 403 | default: |
| 404 | break; |
| 405 | } |
| 406 | }; |
| 407 | |
| 408 | /** |
Randy Dunlap | d9489fb | 2006-12-06 20:38:43 -0800 | [diff] [blame] | 409 | * i2o_scsi_notify_device_remove - Retrieve notifications of removed devices |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 410 | * @i2o_dev: the I2O device which was removed |
| 411 | * |
| 412 | * If a I2O device is removed, we catch the notification to remove the |
| 413 | * corresponding SCSI device. |
| 414 | */ |
| 415 | static void i2o_scsi_notify_device_remove(struct i2o_device *i2o_dev) |
| 416 | { |
| 417 | switch (i2o_dev->lct_data.class_id) { |
| 418 | case I2O_CLASS_EXECUTIVE: |
| 419 | case I2O_CLASS_RANDOM_BLOCK_STORAGE: |
| 420 | i2o_scsi_remove(&i2o_dev->device); |
| 421 | break; |
| 422 | |
| 423 | default: |
| 424 | break; |
| 425 | } |
| 426 | }; |
| 427 | |
| 428 | /** |
Randy Dunlap | d9489fb | 2006-12-06 20:38:43 -0800 | [diff] [blame] | 429 | * i2o_scsi_notify_controller_add - Retrieve notifications of added controllers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | * @c: the controller which was added |
| 431 | * |
| 432 | * If a I2O controller is added, we catch the notification to add a |
| 433 | * corresponding Scsi_Host. |
| 434 | */ |
| 435 | static void i2o_scsi_notify_controller_add(struct i2o_controller *c) |
| 436 | { |
| 437 | struct i2o_scsi_host *i2o_shost; |
| 438 | int rc; |
| 439 | |
| 440 | i2o_shost = i2o_scsi_host_alloc(c); |
| 441 | if (IS_ERR(i2o_shost)) { |
| 442 | osm_err("Could not initialize SCSI host\n"); |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | rc = scsi_add_host(i2o_shost->scsi_host, &c->device); |
| 447 | if (rc) { |
| 448 | osm_err("Could not add SCSI host\n"); |
| 449 | scsi_host_put(i2o_shost->scsi_host); |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | c->driver_data[i2o_scsi_driver.context] = i2o_shost; |
| 454 | |
| 455 | osm_debug("new I2O SCSI host added\n"); |
| 456 | }; |
| 457 | |
| 458 | /** |
Randy Dunlap | d9489fb | 2006-12-06 20:38:43 -0800 | [diff] [blame] | 459 | * i2o_scsi_notify_controller_remove - Retrieve notifications of removed controllers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | * @c: the controller which was removed |
| 461 | * |
| 462 | * If a I2O controller is removed, we catch the notification to remove the |
| 463 | * corresponding Scsi_Host. |
| 464 | */ |
| 465 | static void i2o_scsi_notify_controller_remove(struct i2o_controller *c) |
| 466 | { |
| 467 | struct i2o_scsi_host *i2o_shost; |
| 468 | i2o_shost = i2o_scsi_get_host(c); |
| 469 | if (!i2o_shost) |
| 470 | return; |
| 471 | |
| 472 | c->driver_data[i2o_scsi_driver.context] = NULL; |
| 473 | |
| 474 | scsi_remove_host(i2o_shost->scsi_host); |
| 475 | scsi_host_put(i2o_shost->scsi_host); |
Markus Lidel | f88e119 | 2005-06-23 22:02:14 -0700 | [diff] [blame] | 476 | osm_debug("I2O SCSI host removed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | }; |
| 478 | |
| 479 | /* SCSI OSM driver struct */ |
| 480 | static struct i2o_driver i2o_scsi_driver = { |
| 481 | .name = OSM_NAME, |
| 482 | .reply = i2o_scsi_reply, |
| 483 | .classes = i2o_scsi_class_id, |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 484 | .notify_device_add = i2o_scsi_notify_device_add, |
| 485 | .notify_device_remove = i2o_scsi_notify_device_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | .notify_controller_add = i2o_scsi_notify_controller_add, |
| 487 | .notify_controller_remove = i2o_scsi_notify_controller_remove, |
| 488 | .driver = { |
| 489 | .probe = i2o_scsi_probe, |
| 490 | .remove = i2o_scsi_remove, |
| 491 | }, |
| 492 | }; |
| 493 | |
| 494 | /** |
| 495 | * i2o_scsi_queuecommand - queue a SCSI command |
| 496 | * @SCpnt: scsi command pointer |
| 497 | * @done: callback for completion |
| 498 | * |
| 499 | * Issue a scsi command asynchronously. Return 0 on success or 1 if |
| 500 | * we hit an error (normally message queue congestion). The only |
| 501 | * minor complication here is that I2O deals with the device addressing |
| 502 | * so we have to map the bus/dev/lun back to an I2O handle as well |
| 503 | * as faking absent devices ourself. |
| 504 | * |
| 505 | * Locks: takes the controller lock on error path only |
| 506 | */ |
| 507 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 508 | static int i2o_scsi_queuecommand_lck(struct scsi_cmnd *SCpnt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | void (*done) (struct scsi_cmnd *)) |
| 510 | { |
| 511 | struct i2o_controller *c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | struct i2o_device *i2o_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | int tid; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 514 | struct i2o_message *msg; |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 515 | /* |
| 516 | * ENABLE_DISCONNECT |
| 517 | * SIMPLE_TAG |
| 518 | * RETURN_SENSE_DATA_IN_REPLY_MESSAGE_FRAME |
| 519 | */ |
| 520 | u32 scsi_flags = 0x20a00000; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 521 | u32 sgl_offset; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 522 | u32 *mptr; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 523 | u32 cmd = I2O_CMD_SCSI_EXEC << 24; |
| 524 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | /* |
| 527 | * Do the incoming paperwork |
| 528 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | i2o_dev = SCpnt->device->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | SCpnt->scsi_done = done; |
| 532 | |
| 533 | if (unlikely(!i2o_dev)) { |
| 534 | osm_warn("no I2O device in request\n"); |
| 535 | SCpnt->result = DID_NO_CONNECT << 16; |
| 536 | done(SCpnt); |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 537 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
Julia Lawall | d236700 | 2010-08-10 18:01:14 -0700 | [diff] [blame] | 539 | c = i2o_dev->iop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | tid = i2o_dev->lct_data.tid; |
| 541 | |
| 542 | osm_debug("qcmd: Tid = %03x\n", tid); |
| 543 | osm_debug("Real scsi messages.\n"); |
| 544 | |
| 545 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | * Put together a scsi execscb message |
| 547 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | switch (SCpnt->sc_data_direction) { |
| 549 | case PCI_DMA_NONE: |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 550 | /* DATA NO XFER */ |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 551 | sgl_offset = SGL_OFFSET_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case PCI_DMA_TODEVICE: |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 555 | /* DATA OUT (iop-->dev) */ |
| 556 | scsi_flags |= 0x80000000; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 557 | sgl_offset = SGL_OFFSET_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case PCI_DMA_FROMDEVICE: |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 561 | /* DATA IN (iop<--dev) */ |
| 562 | scsi_flags |= 0x40000000; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 563 | sgl_offset = SGL_OFFSET_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | break; |
| 565 | |
| 566 | default: |
| 567 | /* Unknown - kill the command */ |
| 568 | SCpnt->result = DID_NO_CONNECT << 16; |
| 569 | done(SCpnt); |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 570 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 573 | /* |
| 574 | * Obtain an I2O message. If there are none free then |
| 575 | * throw it back to the scsi layer |
| 576 | */ |
| 577 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 578 | msg = i2o_msg_get(c); |
| 579 | if (IS_ERR(msg)) { |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 580 | rc = SCSI_MLQUEUE_HOST_BUSY; |
| 581 | goto exit; |
| 582 | } |
| 583 | |
| 584 | mptr = &msg->body[0]; |
| 585 | |
Christoph Hellwig | beb4048 | 2006-06-10 18:01:03 +0200 | [diff] [blame] | 586 | #if 0 /* this code can't work */ |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 587 | #ifdef CONFIG_I2O_EXT_ADAPTEC |
| 588 | if (c->adaptec) { |
| 589 | u32 adpt_flags = 0; |
| 590 | |
| 591 | if (SCpnt->sc_request && SCpnt->sc_request->upper_private_data) { |
| 592 | i2o_sg_io_hdr_t __user *usr_ptr = |
| 593 | ((Sg_request *) (SCpnt->sc_request-> |
| 594 | upper_private_data))->header. |
| 595 | usr_ptr; |
| 596 | |
| 597 | if (usr_ptr) |
| 598 | get_user(adpt_flags, &usr_ptr->flags); |
| 599 | } |
| 600 | |
| 601 | switch (i2o_dev->lct_data.class_id) { |
| 602 | case I2O_CLASS_EXECUTIVE: |
| 603 | case I2O_CLASS_RANDOM_BLOCK_STORAGE: |
| 604 | /* interpret flag has to be set for executive */ |
| 605 | adpt_flags ^= I2O_DPT_SG_FLAG_INTERPRET; |
| 606 | break; |
| 607 | |
| 608 | default: |
| 609 | break; |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * for Adaptec controllers we use the PRIVATE command, because |
| 614 | * the normal SCSI EXEC doesn't support all SCSI commands on |
| 615 | * all controllers (for example READ CAPACITY). |
| 616 | */ |
| 617 | if (sgl_offset == SGL_OFFSET_10) |
| 618 | sgl_offset = SGL_OFFSET_12; |
| 619 | cmd = I2O_CMD_PRIVATE << 24; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 620 | *mptr++ = cpu_to_le32(I2O_VENDOR_DPT << 16 | I2O_CMD_SCSI_EXEC); |
| 621 | *mptr++ = cpu_to_le32(adpt_flags | tid); |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 622 | } |
| 623 | #endif |
Christoph Hellwig | beb4048 | 2006-06-10 18:01:03 +0200 | [diff] [blame] | 624 | #endif |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 625 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 626 | msg->u.head[1] = cpu_to_le32(cmd | HOST_TID << 12 | tid); |
| 627 | msg->u.s.icntxt = cpu_to_le32(i2o_scsi_driver.context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
| 629 | /* We want the SCSI control block back */ |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 630 | msg->u.s.tcntxt = cpu_to_le32(i2o_cntxt_list_add(c, SCpnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
| 632 | /* LSI_920_PCI_QUIRK |
| 633 | * |
| 634 | * Intermittant observations of msg frame word data corruption |
| 635 | * observed on msg[4] after: |
| 636 | * WRITE, READ-MODIFY-WRITE |
| 637 | * operations. 19990606 -sralston |
| 638 | * |
| 639 | * (Hence we build this word via tag. Its good practice anyway |
| 640 | * we don't want fetches over PCI needlessly) |
| 641 | */ |
| 642 | |
| 643 | /* Attach tags to the devices */ |
Markus Lidel | 9e87545 | 2005-06-23 22:02:21 -0700 | [diff] [blame] | 644 | /* FIXME: implement |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | if(SCpnt->device->tagged_supported) { |
| 646 | if(SCpnt->tag == HEAD_OF_QUEUE_TAG) |
| 647 | scsi_flags |= 0x01000000; |
| 648 | else if(SCpnt->tag == ORDERED_QUEUE_TAG) |
| 649 | scsi_flags |= 0x01800000; |
| 650 | } |
| 651 | */ |
| 652 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 653 | *mptr++ = cpu_to_le32(scsi_flags | SCpnt->cmd_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | /* Write SCSI command into the message - always 16 byte block */ |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 656 | memcpy(mptr, SCpnt->cmnd, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | mptr += 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 659 | if (sgl_offset != SGL_OFFSET_0) { |
| 660 | /* write size of data addressed by SGL */ |
FUJITA Tomonori | 0ea7154 | 2007-06-14 00:41:06 +0900 | [diff] [blame] | 661 | *mptr++ = cpu_to_le32(scsi_bufflen(SCpnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 663 | /* Now fill in the SGList and command */ |
FUJITA Tomonori | 0ea7154 | 2007-06-14 00:41:06 +0900 | [diff] [blame] | 664 | |
| 665 | if (scsi_sg_count(SCpnt)) { |
| 666 | if (!i2o_dma_map_sg(c, scsi_sglist(SCpnt), |
| 667 | scsi_sg_count(SCpnt), |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 668 | SCpnt->sc_data_direction, &mptr)) |
| 669 | goto nomem; |
Markus Lidel | f88e119 | 2005-06-23 22:02:14 -0700 | [diff] [blame] | 670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* Stick the headers on */ |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 674 | msg->u.head[0] = |
| 675 | cpu_to_le32(I2O_MESSAGE_SIZE(mptr - &msg->u.head[0]) | sgl_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
| 677 | /* Queue the message */ |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 678 | i2o_msg_post(c, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 680 | osm_debug("Issued %0x%p\n", SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | return 0; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 683 | |
| 684 | nomem: |
| 685 | rc = -ENOMEM; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 686 | i2o_msg_nop(c, msg); |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 687 | |
| 688 | exit: |
| 689 | return rc; |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static DEF_SCSI_QCMD(i2o_scsi_queuecommand) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * i2o_scsi_abort - abort a running command |
| 696 | * @SCpnt: command to abort |
| 697 | * |
| 698 | * Ask the I2O controller to abort a command. This is an asynchrnous |
| 699 | * process and our callback handler will see the command complete with an |
| 700 | * aborted message if it succeeds. |
| 701 | * |
| 702 | * Returns 0 if the command is successfully aborted or negative error code |
| 703 | * on failure. |
| 704 | */ |
| 705 | static int i2o_scsi_abort(struct scsi_cmnd *SCpnt) |
| 706 | { |
| 707 | struct i2o_device *i2o_dev; |
| 708 | struct i2o_controller *c; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 709 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | int tid; |
| 711 | int status = FAILED; |
| 712 | |
| 713 | osm_warn("Aborting command block.\n"); |
| 714 | |
| 715 | i2o_dev = SCpnt->device->hostdata; |
| 716 | c = i2o_dev->iop; |
| 717 | tid = i2o_dev->lct_data.tid; |
| 718 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 719 | msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); |
| 720 | if (IS_ERR(msg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | return SCSI_MLQUEUE_HOST_BUSY; |
| 722 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 723 | msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0); |
| 724 | msg->u.head[1] = |
| 725 | cpu_to_le32(I2O_CMD_SCSI_ABORT << 24 | HOST_TID << 12 | tid); |
| 726 | msg->body[0] = cpu_to_le32(i2o_cntxt_list_get_ptr(c, SCpnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Markus Lidel | e22bec2 | 2006-02-04 23:27:39 -0800 | [diff] [blame] | 728 | if (!i2o_msg_post_wait(c, msg, I2O_TIMEOUT_SCSI_SCB_ABORT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | status = SUCCESS; |
| 730 | |
| 731 | return status; |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * i2o_scsi_bios_param - Invent disk geometry |
| 736 | * @sdev: scsi device |
| 737 | * @dev: block layer device |
| 738 | * @capacity: size in sectors |
| 739 | * @ip: geometry array |
| 740 | * |
Randy Dunlap | d9489fb | 2006-12-06 20:38:43 -0800 | [diff] [blame] | 741 | * This is anyone's guess quite frankly. We use the same rules everyone |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | * else appears to and hope. It seems to work. |
| 743 | */ |
| 744 | |
| 745 | static int i2o_scsi_bios_param(struct scsi_device *sdev, |
| 746 | struct block_device *dev, sector_t capacity, |
| 747 | int *ip) |
| 748 | { |
| 749 | int size; |
| 750 | |
| 751 | size = capacity; |
| 752 | ip[0] = 64; /* heads */ |
| 753 | ip[1] = 32; /* sectors */ |
| 754 | if ((ip[2] = size >> 11) > 1024) { /* cylinders, test for big disk */ |
| 755 | ip[0] = 255; /* heads */ |
| 756 | ip[1] = 63; /* sectors */ |
| 757 | ip[2] = size / (255 * 63); /* cylinders */ |
| 758 | } |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static struct scsi_host_template i2o_scsi_host_template = { |
| 763 | .proc_name = OSM_NAME, |
| 764 | .name = OSM_DESCRIPTION, |
| 765 | .info = i2o_scsi_info, |
| 766 | .queuecommand = i2o_scsi_queuecommand, |
| 767 | .eh_abort_handler = i2o_scsi_abort, |
| 768 | .bios_param = i2o_scsi_bios_param, |
| 769 | .can_queue = I2O_SCSI_CAN_QUEUE, |
| 770 | .sg_tablesize = 8, |
| 771 | .cmd_per_lun = 6, |
| 772 | .use_clustering = ENABLE_CLUSTERING, |
| 773 | }; |
| 774 | |
| 775 | /** |
| 776 | * i2o_scsi_init - SCSI OSM initialization function |
| 777 | * |
| 778 | * Register SCSI OSM into I2O core. |
| 779 | * |
| 780 | * Returns 0 on success or negative error code on failure. |
| 781 | */ |
| 782 | static int __init i2o_scsi_init(void) |
| 783 | { |
| 784 | int rc; |
| 785 | |
| 786 | printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n"); |
| 787 | |
| 788 | /* Register SCSI OSM into I2O core */ |
| 789 | rc = i2o_driver_register(&i2o_scsi_driver); |
| 790 | if (rc) { |
| 791 | osm_err("Could not register SCSI driver\n"); |
| 792 | return rc; |
| 793 | } |
| 794 | |
| 795 | return 0; |
| 796 | }; |
| 797 | |
| 798 | /** |
| 799 | * i2o_scsi_exit - SCSI OSM exit function |
| 800 | * |
| 801 | * Unregisters SCSI OSM from I2O core. |
| 802 | */ |
| 803 | static void __exit i2o_scsi_exit(void) |
| 804 | { |
| 805 | /* Unregister I2O SCSI OSM from I2O core */ |
| 806 | i2o_driver_unregister(&i2o_scsi_driver); |
| 807 | }; |
| 808 | |
| 809 | MODULE_AUTHOR("Red Hat Software"); |
| 810 | MODULE_LICENSE("GPL"); |
| 811 | MODULE_DESCRIPTION(OSM_DESCRIPTION); |
| 812 | MODULE_VERSION(OSM_VERSION); |
| 813 | |
| 814 | module_init(i2o_scsi_init); |
| 815 | module_exit(i2o_scsi_exit); |