i2o_scsi.c 21 KB

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