i2o_scsi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  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. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/types.h>
  45. #include <linux/string.h>
  46. #include <linux/ioport.h>
  47. #include <linux/jiffies.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/timer.h>
  50. #include <linux/delay.h>
  51. #include <linux/proc_fs.h>
  52. #include <linux/prefetch.h>
  53. #include <linux/pci.h>
  54. #include <linux/blkdev.h>
  55. #include <linux/i2o.h>
  56. #include <linux/scatterlist.h>
  57. #include <asm/dma.h>
  58. #include <asm/io.h>
  59. #include <linux/atomic.h>
  60. #include <scsi/scsi.h>
  61. #include <scsi/scsi_host.h>
  62. #include <scsi/scsi_device.h>
  63. #include <scsi/scsi_cmnd.h>
  64. #include <scsi/sg.h>
  65. #define OSM_NAME "scsi-osm"
  66. #define OSM_VERSION "1.316"
  67. #define OSM_DESCRIPTION "I2O SCSI Peripheral OSM"
  68. static struct i2o_driver i2o_scsi_driver;
  69. static unsigned int i2o_scsi_max_id = 16;
  70. static unsigned int i2o_scsi_max_lun = 255;
  71. struct i2o_scsi_host {
  72. struct Scsi_Host *scsi_host; /* pointer to the SCSI host */
  73. struct i2o_controller *iop; /* pointer to the I2O controller */
  74. u64 lun; /* lun's used for block devices */
  75. struct i2o_device *channel[0]; /* channel->i2o_dev mapping table */
  76. };
  77. static struct scsi_host_template i2o_scsi_host_template;
  78. #define I2O_SCSI_CAN_QUEUE 4
  79. /* SCSI OSM class handling definition */
  80. static struct i2o_class_id i2o_scsi_class_id[] = {
  81. {I2O_CLASS_SCSI_PERIPHERAL},
  82. {I2O_CLASS_END}
  83. };
  84. static struct i2o_scsi_host *i2o_scsi_host_alloc(struct i2o_controller *c)
  85. {
  86. struct i2o_scsi_host *i2o_shost;
  87. struct i2o_device *i2o_dev;
  88. struct Scsi_Host *scsi_host;
  89. int max_channel = 0;
  90. u8 type;
  91. int i;
  92. size_t size;
  93. u16 body_size = 6;
  94. #ifdef CONFIG_I2O_EXT_ADAPTEC
  95. if (c->adaptec)
  96. body_size = 8;
  97. #endif
  98. list_for_each_entry(i2o_dev, &c->devices, list)
  99. if (i2o_dev->lct_data.class_id == I2O_CLASS_BUS_ADAPTER) {
  100. if (!i2o_parm_field_get(i2o_dev, 0x0000, 0, &type, 1)
  101. && (type == 0x01)) /* SCSI bus */
  102. max_channel++;
  103. }
  104. if (!max_channel) {
  105. osm_warn("no channels found on %s\n", c->name);
  106. return ERR_PTR(-EFAULT);
  107. }
  108. size = max_channel * sizeof(struct i2o_device *)
  109. + sizeof(struct i2o_scsi_host);
  110. scsi_host = scsi_host_alloc(&i2o_scsi_host_template, size);
  111. if (!scsi_host) {
  112. osm_warn("Could not allocate SCSI host\n");
  113. return ERR_PTR(-ENOMEM);
  114. }
  115. scsi_host->max_channel = max_channel - 1;
  116. scsi_host->max_id = i2o_scsi_max_id;
  117. scsi_host->max_lun = i2o_scsi_max_lun;
  118. scsi_host->this_id = c->unit;
  119. scsi_host->sg_tablesize = i2o_sg_tablesize(c, body_size);
  120. i2o_shost = (struct i2o_scsi_host *)scsi_host->hostdata;
  121. i2o_shost->scsi_host = scsi_host;
  122. i2o_shost->iop = c;
  123. i2o_shost->lun = 1;
  124. i = 0;
  125. list_for_each_entry(i2o_dev, &c->devices, list)
  126. if (i2o_dev->lct_data.class_id == I2O_CLASS_BUS_ADAPTER) {
  127. if (!i2o_parm_field_get(i2o_dev, 0x0000, 0, &type, 1)
  128. && (type == 0x01)) /* only SCSI bus */
  129. i2o_shost->channel[i++] = i2o_dev;
  130. if (i >= max_channel)
  131. break;
  132. }
  133. return i2o_shost;
  134. };
  135. /**
  136. * i2o_scsi_get_host - Get an I2O SCSI host
  137. * @c: I2O controller to for which to get the SCSI host
  138. *
  139. * If the I2O controller already exists as SCSI host, the SCSI host
  140. * is returned, otherwise the I2O controller is added to the SCSI
  141. * core.
  142. *
  143. * Returns pointer to the I2O SCSI host on success or NULL on failure.
  144. */
  145. static struct i2o_scsi_host *i2o_scsi_get_host(struct i2o_controller *c)
  146. {
  147. return c->driver_data[i2o_scsi_driver.context];
  148. };
  149. /**
  150. * i2o_scsi_remove - Remove I2O device from SCSI core
  151. * @dev: device which should be removed
  152. *
  153. * Removes the I2O device from the SCSI core again.
  154. *
  155. * Returns 0 on success.
  156. */
  157. static int i2o_scsi_remove(struct device *dev)
  158. {
  159. struct i2o_device *i2o_dev = to_i2o_device(dev);
  160. struct i2o_controller *c = i2o_dev->iop;
  161. struct i2o_scsi_host *i2o_shost;
  162. struct scsi_device *scsi_dev;
  163. osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);
  164. i2o_shost = i2o_scsi_get_host(c);
  165. shost_for_each_device(scsi_dev, i2o_shost->scsi_host)
  166. if (scsi_dev->hostdata == i2o_dev) {
  167. sysfs_remove_link(&i2o_dev->device.kobj, "scsi");
  168. scsi_remove_device(scsi_dev);
  169. scsi_device_put(scsi_dev);
  170. break;
  171. }
  172. return 0;
  173. };
  174. /**
  175. * i2o_scsi_probe - verify if dev is a I2O SCSI device and install it
  176. * @dev: device to verify if it is a I2O SCSI device
  177. *
  178. * Retrieve channel, id and lun for I2O device. If everything goes well
  179. * register the I2O device as SCSI device on the I2O SCSI controller.
  180. *
  181. * Returns 0 on success or negative error code on failure.
  182. */
  183. static int i2o_scsi_probe(struct device *dev)
  184. {
  185. struct i2o_device *i2o_dev = to_i2o_device(dev);
  186. struct i2o_controller *c = i2o_dev->iop;
  187. struct i2o_scsi_host *i2o_shost;
  188. struct Scsi_Host *scsi_host;
  189. struct i2o_device *parent;
  190. struct scsi_device *scsi_dev;
  191. u32 id = -1;
  192. u64 lun = -1;
  193. int channel = -1;
  194. int i, rc;
  195. i2o_shost = i2o_scsi_get_host(c);
  196. if (!i2o_shost)
  197. return -EFAULT;
  198. scsi_host = i2o_shost->scsi_host;
  199. switch (i2o_dev->lct_data.class_id) {
  200. case I2O_CLASS_RANDOM_BLOCK_STORAGE:
  201. case I2O_CLASS_EXECUTIVE:
  202. #ifdef CONFIG_I2O_EXT_ADAPTEC
  203. if (c->adaptec) {
  204. u8 type;
  205. struct i2o_device *d = i2o_shost->channel[0];
  206. if (!i2o_parm_field_get(d, 0x0000, 0, &type, 1)
  207. && (type == 0x01)) /* SCSI bus */
  208. if (!i2o_parm_field_get(d, 0x0200, 4, &id, 4)) {
  209. channel = 0;
  210. if (i2o_dev->lct_data.class_id ==
  211. I2O_CLASS_RANDOM_BLOCK_STORAGE)
  212. lun =
  213. cpu_to_le64(i2o_shost->
  214. lun++);
  215. else
  216. lun = 0;
  217. }
  218. }
  219. #endif
  220. break;
  221. case I2O_CLASS_SCSI_PERIPHERAL:
  222. if (i2o_parm_field_get(i2o_dev, 0x0000, 3, &id, 4))
  223. return -EFAULT;
  224. if (i2o_parm_field_get(i2o_dev, 0x0000, 4, &lun, 8))
  225. return -EFAULT;
  226. parent = i2o_iop_find_device(c, i2o_dev->lct_data.parent_tid);
  227. if (!parent) {
  228. osm_warn("can not find parent of device %03x\n",
  229. i2o_dev->lct_data.tid);
  230. return -EFAULT;
  231. }
  232. for (i = 0; i <= i2o_shost->scsi_host->max_channel; i++)
  233. if (i2o_shost->channel[i] == parent)
  234. channel = i;
  235. break;
  236. default:
  237. return -EFAULT;
  238. }
  239. if (channel == -1) {
  240. osm_warn("can not find channel of device %03x\n",
  241. i2o_dev->lct_data.tid);
  242. return -EFAULT;
  243. }
  244. if (le32_to_cpu(id) >= scsi_host->max_id) {
  245. osm_warn("SCSI device id (%d) >= max_id of I2O host (%d)",
  246. le32_to_cpu(id), scsi_host->max_id);
  247. return -EFAULT;
  248. }
  249. if (le64_to_cpu(lun) >= scsi_host->max_lun) {
  250. osm_warn("SCSI device lun (%llu) >= max_lun of I2O host (%llu)",
  251. le64_to_cpu(lun), scsi_host->max_lun);
  252. return -EFAULT;
  253. }
  254. scsi_dev =
  255. __scsi_add_device(i2o_shost->scsi_host, channel, le32_to_cpu(id),
  256. le64_to_cpu(lun), i2o_dev);
  257. if (IS_ERR(scsi_dev)) {
  258. osm_warn("can not add SCSI device %03x\n",
  259. i2o_dev->lct_data.tid);
  260. return PTR_ERR(scsi_dev);
  261. }
  262. rc = sysfs_create_link(&i2o_dev->device.kobj,
  263. &scsi_dev->sdev_gendev.kobj, "scsi");
  264. if (rc)
  265. goto err;
  266. osm_info("device added (TID: %03x) channel: %d, id: %d, lun: %llu\n",
  267. i2o_dev->lct_data.tid, channel, le32_to_cpu(id),
  268. le64_to_cpu(lun));
  269. return 0;
  270. err:
  271. scsi_remove_device(scsi_dev);
  272. return rc;
  273. };
  274. static const char *i2o_scsi_info(struct Scsi_Host *SChost)
  275. {
  276. struct i2o_scsi_host *hostdata;
  277. hostdata = (struct i2o_scsi_host *)SChost->hostdata;
  278. return hostdata->iop->name;
  279. }
  280. /**
  281. * i2o_scsi_reply - SCSI OSM message reply handler
  282. * @c: controller issuing the reply
  283. * @m: message id for flushing
  284. * @msg: the message from the controller
  285. *
  286. * Process reply messages (interrupts in normal scsi controller think).
  287. * We can get a variety of messages to process. The normal path is
  288. * scsi command completions. We must also deal with IOP failures,
  289. * the reply to a bus reset and the reply to a LUN query.
  290. *
  291. * Returns 0 on success and if the reply should not be flushed or > 0
  292. * on success and if the reply should be flushed. Returns negative error
  293. * code on failure and if the reply should be flushed.
  294. */
  295. static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
  296. struct i2o_message *msg)
  297. {
  298. struct scsi_cmnd *cmd;
  299. u32 error;
  300. struct device *dev;
  301. cmd = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt));
  302. if (unlikely(!cmd)) {
  303. osm_err("NULL reply received!\n");
  304. return -1;
  305. }
  306. /*
  307. * Low byte is device status, next is adapter status,
  308. * (then one byte reserved), then request status.
  309. */
  310. error = le32_to_cpu(msg->body[0]);
  311. osm_debug("Completed %0x%p\n", cmd);
  312. cmd->result = error & 0xff;
  313. /*
  314. * if DeviceStatus is not SCSI_SUCCESS copy over the sense data and let
  315. * the SCSI layer handle the error
  316. */
  317. if (cmd->result)
  318. memcpy(cmd->sense_buffer, &msg->body[3],
  319. min(SCSI_SENSE_BUFFERSIZE, 40));
  320. /* only output error code if AdapterStatus is not HBA_SUCCESS */
  321. if ((error >> 8) & 0xff)
  322. osm_err("SCSI error %08x\n", error);
  323. dev = &c->pdev->dev;
  324. scsi_dma_unmap(cmd);
  325. cmd->scsi_done(cmd);
  326. return 1;
  327. };
  328. /**
  329. * i2o_scsi_notify_device_add - Retrieve notifications of added devices
  330. * @i2o_dev: the I2O device which was added
  331. *
  332. * If a I2O device is added we catch the notification, because I2O classes
  333. * other than SCSI peripheral will not be received through
  334. * i2o_scsi_probe().
  335. */
  336. static void i2o_scsi_notify_device_add(struct i2o_device *i2o_dev)
  337. {
  338. switch (i2o_dev->lct_data.class_id) {
  339. case I2O_CLASS_EXECUTIVE:
  340. case I2O_CLASS_RANDOM_BLOCK_STORAGE:
  341. i2o_scsi_probe(&i2o_dev->device);
  342. break;
  343. default:
  344. break;
  345. }
  346. };
  347. /**
  348. * i2o_scsi_notify_device_remove - Retrieve notifications of removed devices
  349. * @i2o_dev: the I2O device which was removed
  350. *
  351. * If a I2O device is removed, we catch the notification to remove the
  352. * corresponding SCSI device.
  353. */
  354. static void i2o_scsi_notify_device_remove(struct i2o_device *i2o_dev)
  355. {
  356. switch (i2o_dev->lct_data.class_id) {
  357. case I2O_CLASS_EXECUTIVE:
  358. case I2O_CLASS_RANDOM_BLOCK_STORAGE:
  359. i2o_scsi_remove(&i2o_dev->device);
  360. break;
  361. default:
  362. break;
  363. }
  364. };
  365. /**
  366. * i2o_scsi_notify_controller_add - Retrieve notifications of added controllers
  367. * @c: the controller which was added
  368. *
  369. * If a I2O controller is added, we catch the notification to add a
  370. * corresponding Scsi_Host.
  371. */
  372. static void i2o_scsi_notify_controller_add(struct i2o_controller *c)
  373. {
  374. struct i2o_scsi_host *i2o_shost;
  375. int rc;
  376. i2o_shost = i2o_scsi_host_alloc(c);
  377. if (IS_ERR(i2o_shost)) {
  378. osm_err("Could not initialize SCSI host\n");
  379. return;
  380. }
  381. rc = scsi_add_host(i2o_shost->scsi_host, &c->device);
  382. if (rc) {
  383. osm_err("Could not add SCSI host\n");
  384. scsi_host_put(i2o_shost->scsi_host);
  385. return;
  386. }
  387. c->driver_data[i2o_scsi_driver.context] = i2o_shost;
  388. osm_debug("new I2O SCSI host added\n");
  389. };
  390. /**
  391. * i2o_scsi_notify_controller_remove - Retrieve notifications of removed controllers
  392. * @c: the controller which was removed
  393. *
  394. * If a I2O controller is removed, we catch the notification to remove the
  395. * corresponding Scsi_Host.
  396. */
  397. static void i2o_scsi_notify_controller_remove(struct i2o_controller *c)
  398. {
  399. struct i2o_scsi_host *i2o_shost;
  400. i2o_shost = i2o_scsi_get_host(c);
  401. if (!i2o_shost)
  402. return;
  403. c->driver_data[i2o_scsi_driver.context] = NULL;
  404. scsi_remove_host(i2o_shost->scsi_host);
  405. scsi_host_put(i2o_shost->scsi_host);
  406. osm_debug("I2O SCSI host removed\n");
  407. };
  408. /* SCSI OSM driver struct */
  409. static struct i2o_driver i2o_scsi_driver = {
  410. .name = OSM_NAME,
  411. .reply = i2o_scsi_reply,
  412. .classes = i2o_scsi_class_id,
  413. .notify_device_add = i2o_scsi_notify_device_add,
  414. .notify_device_remove = i2o_scsi_notify_device_remove,
  415. .notify_controller_add = i2o_scsi_notify_controller_add,
  416. .notify_controller_remove = i2o_scsi_notify_controller_remove,
  417. .driver = {
  418. .probe = i2o_scsi_probe,
  419. .remove = i2o_scsi_remove,
  420. },
  421. };
  422. /**
  423. * i2o_scsi_queuecommand - queue a SCSI command
  424. * @SCpnt: scsi command pointer
  425. * @done: callback for completion
  426. *
  427. * Issue a scsi command asynchronously. Return 0 on success or 1 if
  428. * we hit an error (normally message queue congestion). The only
  429. * minor complication here is that I2O deals with the device addressing
  430. * so we have to map the bus/dev/lun back to an I2O handle as well
  431. * as faking absent devices ourself.
  432. *
  433. * Locks: takes the controller lock on error path only
  434. */
  435. static int i2o_scsi_queuecommand_lck(struct scsi_cmnd *SCpnt,
  436. void (*done) (struct scsi_cmnd *))
  437. {
  438. struct i2o_controller *c;
  439. struct i2o_device *i2o_dev;
  440. int tid;
  441. struct i2o_message *msg;
  442. /*
  443. * ENABLE_DISCONNECT
  444. * SIMPLE_TAG
  445. * RETURN_SENSE_DATA_IN_REPLY_MESSAGE_FRAME
  446. */
  447. u32 scsi_flags = 0x20a00000;
  448. u32 sgl_offset;
  449. u32 *mptr;
  450. u32 cmd = I2O_CMD_SCSI_EXEC << 24;
  451. int rc = 0;
  452. /*
  453. * Do the incoming paperwork
  454. */
  455. i2o_dev = SCpnt->device->hostdata;
  456. SCpnt->scsi_done = done;
  457. if (unlikely(!i2o_dev)) {
  458. osm_warn("no I2O device in request\n");
  459. SCpnt->result = DID_NO_CONNECT << 16;
  460. done(SCpnt);
  461. goto exit;
  462. }
  463. c = i2o_dev->iop;
  464. tid = i2o_dev->lct_data.tid;
  465. osm_debug("qcmd: Tid = %03x\n", tid);
  466. osm_debug("Real scsi messages.\n");
  467. /*
  468. * Put together a scsi execscb message
  469. */
  470. switch (SCpnt->sc_data_direction) {
  471. case PCI_DMA_NONE:
  472. /* DATA NO XFER */
  473. sgl_offset = SGL_OFFSET_0;
  474. break;
  475. case PCI_DMA_TODEVICE:
  476. /* DATA OUT (iop-->dev) */
  477. scsi_flags |= 0x80000000;
  478. sgl_offset = SGL_OFFSET_10;
  479. break;
  480. case PCI_DMA_FROMDEVICE:
  481. /* DATA IN (iop<--dev) */
  482. scsi_flags |= 0x40000000;
  483. sgl_offset = SGL_OFFSET_10;
  484. break;
  485. default:
  486. /* Unknown - kill the command */
  487. SCpnt->result = DID_NO_CONNECT << 16;
  488. done(SCpnt);
  489. goto exit;
  490. }
  491. /*
  492. * Obtain an I2O message. If there are none free then
  493. * throw it back to the scsi layer
  494. */
  495. msg = i2o_msg_get(c);
  496. if (IS_ERR(msg)) {
  497. rc = SCSI_MLQUEUE_HOST_BUSY;
  498. goto exit;
  499. }
  500. mptr = &msg->body[0];
  501. #if 0 /* this code can't work */
  502. #ifdef CONFIG_I2O_EXT_ADAPTEC
  503. if (c->adaptec) {
  504. u32 adpt_flags = 0;
  505. if (SCpnt->sc_request && SCpnt->sc_request->upper_private_data) {
  506. i2o_sg_io_hdr_t __user *usr_ptr =
  507. ((Sg_request *) (SCpnt->sc_request->
  508. upper_private_data))->header.
  509. usr_ptr;
  510. if (usr_ptr)
  511. get_user(adpt_flags, &usr_ptr->flags);
  512. }
  513. switch (i2o_dev->lct_data.class_id) {
  514. case I2O_CLASS_EXECUTIVE:
  515. case I2O_CLASS_RANDOM_BLOCK_STORAGE:
  516. /* interpret flag has to be set for executive */
  517. adpt_flags ^= I2O_DPT_SG_FLAG_INTERPRET;
  518. break;
  519. default:
  520. break;
  521. }
  522. /*
  523. * for Adaptec controllers we use the PRIVATE command, because
  524. * the normal SCSI EXEC doesn't support all SCSI commands on
  525. * all controllers (for example READ CAPACITY).
  526. */
  527. if (sgl_offset == SGL_OFFSET_10)
  528. sgl_offset = SGL_OFFSET_12;
  529. cmd = I2O_CMD_PRIVATE << 24;
  530. *mptr++ = cpu_to_le32(I2O_VENDOR_DPT << 16 | I2O_CMD_SCSI_EXEC);
  531. *mptr++ = cpu_to_le32(adpt_flags | tid);
  532. }
  533. #endif
  534. #endif
  535. msg->u.head[1] = cpu_to_le32(cmd | HOST_TID << 12 | tid);
  536. msg->u.s.icntxt = cpu_to_le32(i2o_scsi_driver.context);
  537. /* We want the SCSI control block back */
  538. msg->u.s.tcntxt = cpu_to_le32(i2o_cntxt_list_add(c, SCpnt));
  539. /* LSI_920_PCI_QUIRK
  540. *
  541. * Intermittant observations of msg frame word data corruption
  542. * observed on msg[4] after:
  543. * WRITE, READ-MODIFY-WRITE
  544. * operations. 19990606 -sralston
  545. *
  546. * (Hence we build this word via tag. Its good practice anyway
  547. * we don't want fetches over PCI needlessly)
  548. */
  549. /* Attach tags to the devices */
  550. /* FIXME: implement
  551. if(SCpnt->device->tagged_supported) {
  552. if(SCpnt->tag == HEAD_OF_QUEUE_TAG)
  553. scsi_flags |= 0x01000000;
  554. else if(SCpnt->tag == ORDERED_QUEUE_TAG)
  555. scsi_flags |= 0x01800000;
  556. }
  557. */
  558. *mptr++ = cpu_to_le32(scsi_flags | SCpnt->cmd_len);
  559. /* Write SCSI command into the message - always 16 byte block */
  560. memcpy(mptr, SCpnt->cmnd, 16);
  561. mptr += 4;
  562. if (sgl_offset != SGL_OFFSET_0) {
  563. /* write size of data addressed by SGL */
  564. *mptr++ = cpu_to_le32(scsi_bufflen(SCpnt));
  565. /* Now fill in the SGList and command */
  566. if (scsi_sg_count(SCpnt)) {
  567. if (!i2o_dma_map_sg(c, scsi_sglist(SCpnt),
  568. scsi_sg_count(SCpnt),
  569. SCpnt->sc_data_direction, &mptr))
  570. goto nomem;
  571. }
  572. }
  573. /* Stick the headers on */
  574. msg->u.head[0] =
  575. cpu_to_le32(I2O_MESSAGE_SIZE(mptr - &msg->u.head[0]) | sgl_offset);
  576. /* Queue the message */
  577. i2o_msg_post(c, msg);
  578. osm_debug("Issued %0x%p\n", SCpnt);
  579. return 0;
  580. nomem:
  581. rc = -ENOMEM;
  582. i2o_msg_nop(c, msg);
  583. exit:
  584. return rc;
  585. }
  586. static DEF_SCSI_QCMD(i2o_scsi_queuecommand)
  587. /**
  588. * i2o_scsi_abort - abort a running command
  589. * @SCpnt: command to abort
  590. *
  591. * Ask the I2O controller to abort a command. This is an asynchrnous
  592. * process and our callback handler will see the command complete with an
  593. * aborted message if it succeeds.
  594. *
  595. * Returns 0 if the command is successfully aborted or negative error code
  596. * on failure.
  597. */
  598. static int i2o_scsi_abort(struct scsi_cmnd *SCpnt)
  599. {
  600. struct i2o_device *i2o_dev;
  601. struct i2o_controller *c;
  602. struct i2o_message *msg;
  603. int tid;
  604. int status = FAILED;
  605. osm_warn("Aborting command block.\n");
  606. i2o_dev = SCpnt->device->hostdata;
  607. c = i2o_dev->iop;
  608. tid = i2o_dev->lct_data.tid;
  609. msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
  610. if (IS_ERR(msg))
  611. return SCSI_MLQUEUE_HOST_BUSY;
  612. msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0);
  613. msg->u.head[1] =
  614. cpu_to_le32(I2O_CMD_SCSI_ABORT << 24 | HOST_TID << 12 | tid);
  615. msg->body[0] = cpu_to_le32(i2o_cntxt_list_get_ptr(c, SCpnt));
  616. if (!i2o_msg_post_wait(c, msg, I2O_TIMEOUT_SCSI_SCB_ABORT))
  617. status = SUCCESS;
  618. return status;
  619. }
  620. /**
  621. * i2o_scsi_bios_param - Invent disk geometry
  622. * @sdev: scsi device
  623. * @dev: block layer device
  624. * @capacity: size in sectors
  625. * @ip: geometry array
  626. *
  627. * This is anyone's guess quite frankly. We use the same rules everyone
  628. * else appears to and hope. It seems to work.
  629. */
  630. static int i2o_scsi_bios_param(struct scsi_device *sdev,
  631. struct block_device *dev, sector_t capacity,
  632. int *ip)
  633. {
  634. int size;
  635. size = capacity;
  636. ip[0] = 64; /* heads */
  637. ip[1] = 32; /* sectors */
  638. if ((ip[2] = size >> 11) > 1024) { /* cylinders, test for big disk */
  639. ip[0] = 255; /* heads */
  640. ip[1] = 63; /* sectors */
  641. ip[2] = size / (255 * 63); /* cylinders */
  642. }
  643. return 0;
  644. }
  645. static struct scsi_host_template i2o_scsi_host_template = {
  646. .proc_name = OSM_NAME,
  647. .name = OSM_DESCRIPTION,
  648. .info = i2o_scsi_info,
  649. .queuecommand = i2o_scsi_queuecommand,
  650. .eh_abort_handler = i2o_scsi_abort,
  651. .bios_param = i2o_scsi_bios_param,
  652. .can_queue = I2O_SCSI_CAN_QUEUE,
  653. .sg_tablesize = 8,
  654. .cmd_per_lun = 6,
  655. .use_clustering = ENABLE_CLUSTERING,
  656. };
  657. /**
  658. * i2o_scsi_init - SCSI OSM initialization function
  659. *
  660. * Register SCSI OSM into I2O core.
  661. *
  662. * Returns 0 on success or negative error code on failure.
  663. */
  664. static int __init i2o_scsi_init(void)
  665. {
  666. int rc;
  667. printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
  668. /* Register SCSI OSM into I2O core */
  669. rc = i2o_driver_register(&i2o_scsi_driver);
  670. if (rc) {
  671. osm_err("Could not register SCSI driver\n");
  672. return rc;
  673. }
  674. return 0;
  675. };
  676. /**
  677. * i2o_scsi_exit - SCSI OSM exit function
  678. *
  679. * Unregisters SCSI OSM from I2O core.
  680. */
  681. static void __exit i2o_scsi_exit(void)
  682. {
  683. /* Unregister I2O SCSI OSM from I2O core */
  684. i2o_driver_unregister(&i2o_scsi_driver);
  685. };
  686. MODULE_AUTHOR("Red Hat Software");
  687. MODULE_LICENSE("GPL");
  688. MODULE_DESCRIPTION(OSM_DESCRIPTION);
  689. MODULE_VERSION(OSM_VERSION);
  690. module_init(i2o_scsi_init);
  691. module_exit(i2o_scsi_exit);