i2o_scsi.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:20k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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.  *  Complications for I2O scsi
  13.  *
  14.  * o Each (bus,lun) is a logical device in I2O. We keep a map
  15.  * table. We spoof failed selection for unmapped units
  16.  * o Request sense buffers can come back for free. 
  17.  * o Scatter gather is a bit dynamic. We have to investigate at
  18.  * setup time.
  19.  * o Some of our resources are dynamically shared. The i2o core
  20.  * needs a message reservation protocol to avoid swap v net
  21.  * deadlocking. We need to back off queue requests.
  22.  *
  23.  * In general the firmware wants to help. Where its help isn't performance
  24.  * useful we just ignore the aid. Its not worth the code in truth.
  25.  *
  26.  * Fixes:
  27.  * Steve Ralston : Scatter gather now works
  28.  *
  29.  * To Do
  30.  * 64bit cleanups
  31.  * Fix the resource management problems.
  32.  */
  33. #include <linux/module.h>
  34. #include <linux/kernel.h>
  35. #include <linux/types.h>
  36. #include <linux/string.h>
  37. #include <linux/ioport.h>
  38. #include <linux/sched.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/timer.h>
  41. #include <linux/delay.h>
  42. #include <linux/proc_fs.h>
  43. #include <linux/prefetch.h>
  44. #include <asm/dma.h>
  45. #include <asm/system.h>
  46. #include <asm/io.h>
  47. #include <asm/atomic.h>
  48. #include <linux/blk.h>
  49. #include <linux/version.h>
  50. #include <linux/i2o.h>
  51. #include "../../scsi/scsi.h"
  52. #include "../../scsi/hosts.h"
  53. #include "../../scsi/sd.h"
  54. #include "i2o_scsi.h"
  55. #define VERSION_STRING        "Version 0.0.1"
  56. #define dprintk(x)
  57. #define MAXHOSTS 32
  58. struct i2o_scsi_host
  59. {
  60. struct i2o_controller *controller;
  61. s16 task[16][8]; /* Allow 16 devices for now */
  62. unsigned long tagclock[16][8]; /* Tag clock for queueing */
  63. s16 bus_task; /* The adapter TID */
  64. };
  65. static int scsi_context;
  66. static int lun_done;
  67. static int i2o_scsi_hosts;
  68. static u32 *retry[32];
  69. static struct i2o_controller *retry_ctrl[32];
  70. static struct timer_list retry_timer;
  71. static int retry_ct = 0;
  72. static atomic_t queue_depth;
  73. /*
  74.  * SG Chain buffer support...
  75.  */
  76. #define SG_MAX_FRAGS 64
  77. /*
  78.  * FIXME: we should allocate one of these per bus we find as we
  79.  * locate them not in a lump at boot.
  80.  */
  81.  
  82. typedef struct _chain_buf
  83. {
  84. u32 sg_flags_cnt[SG_MAX_FRAGS];
  85. u32 sg_buf[SG_MAX_FRAGS];
  86. } chain_buf;
  87. #define SG_CHAIN_BUF_SZ sizeof(chain_buf)
  88. #define SG_MAX_BUFS (i2o_num_controllers * I2O_SCSI_CAN_QUEUE)
  89. #define SG_CHAIN_POOL_SZ (SG_MAX_BUFS * SG_CHAIN_BUF_SZ)
  90. static int max_sg_len = 0;
  91. static chain_buf *sg_chain_pool = NULL;
  92. static int sg_chain_tag = 0;
  93. static int sg_max_frags = SG_MAX_FRAGS;
  94. /*
  95.  * Retry congested frames. This actually needs pushing down into
  96.  * i2o core. We should only bother the OSM with this when we can't
  97.  * queue and retry the frame. Or perhaps we should call the OSM
  98.  * and its default handler should be this in the core, and this
  99.  * call a 2nd "I give up" handler in the OSM ?
  100.  */
  101.  
  102. static void i2o_retry_run(unsigned long f)
  103. {
  104. int i;
  105. unsigned long flags;
  106. spin_lock_irqsave(&io_request_lock, flags);
  107. for(i=0;i<retry_ct;i++)
  108. i2o_post_message(retry_ctrl[i], virt_to_bus(retry[i]));
  109. retry_ct=0;
  110. spin_unlock_irqrestore(&io_request_lock, flags);
  111. }
  112. static void flush_pending(void)
  113. {
  114. int i;
  115. unsigned long flags;
  116. spin_lock_irqsave(&io_request_lock, flags);
  117. for(i=0;i<retry_ct;i++)
  118. {
  119. retry[i][0]&=~0xFFFFFF;
  120. retry[i][0]|=I2O_CMD_UTIL_NOP<<24;
  121. i2o_post_message(retry_ctrl[i],virt_to_bus(retry[i]));
  122. }
  123. retry_ct=0;
  124. spin_unlock_irqrestore(&io_request_lock, flags);
  125. }
  126. static void i2o_scsi_reply(struct i2o_handler *h, struct i2o_controller *c, struct i2o_message *msg)
  127. {
  128. Scsi_Cmnd *current_command;
  129. u32 *m = (u32 *)msg;
  130. u8 as,ds,st;
  131. spin_lock_prefetch(&io_request_lock);
  132. if(m[0] & (1<<13))
  133. {
  134. printk("IOP fail.n");
  135. printk("From %d To %d Cmd %d.n",
  136. (m[1]>>12)&0xFFF,
  137. m[1]&0xFFF,
  138. m[1]>>24);
  139. printk("Failure Code %d.n", m[4]>>24);
  140. if(m[4]&(1<<16))
  141. printk("Format error.n");
  142. if(m[4]&(1<<17))
  143. printk("Path error.n");
  144. if(m[4]&(1<<18))
  145. printk("Path State.n");
  146. if(m[4]&(1<<18))
  147. printk("Congestion.n");
  148. m=(u32 *)bus_to_virt(m[7]);
  149. printk("Failing message is %p.n", m);
  150. if((m[4]&(1<<18)) && retry_ct < 32)
  151. {
  152. retry_ctrl[retry_ct]=c;
  153. retry[retry_ct]=m;
  154. if(!retry_ct++)
  155. {
  156. retry_timer.expires=jiffies+1;
  157. add_timer(&retry_timer);
  158. }
  159. }
  160. else
  161. {
  162. /* Create a scsi error for this */
  163. current_command = (Scsi_Cmnd *)m[3];
  164. printk("Aborted %ldn", current_command->serial_number);
  165. spin_lock_irq(&io_request_lock);
  166. current_command->result = DID_ERROR << 16;
  167. current_command->scsi_done(current_command);
  168. spin_unlock_irq(&io_request_lock);
  169. /* Now flush the message by making it a NOP */
  170. m[0]&=0x00FFFFFF;
  171. m[0]|=(I2O_CMD_UTIL_NOP)<<24;
  172. i2o_post_message(c,virt_to_bus(m));
  173. }
  174. return;
  175. }
  176. prefetchw(&queue_depth);
  177. /*
  178.  * Low byte is device status, next is adapter status,
  179.  * (then one byte reserved), then request status.
  180.  */
  181. ds=(u8)le32_to_cpu(m[4]); 
  182. as=(u8)le32_to_cpu(m[4]>>8);
  183. st=(u8)le32_to_cpu(m[4]>>24);
  184. dprintk(("i2o got a scsi reply %08X: ", m[0]));
  185. dprintk(("m[2]=%08X: ", m[2]));
  186. dprintk(("m[4]=%08Xn", m[4]));
  187. if(m[2]&0x80000000)
  188. {
  189. if(m[2]&0x40000000)
  190. {
  191. dprintk(("Event.n"));
  192. lun_done=1;
  193. return;
  194. }
  195. printk(KERN_ERR "i2o_scsi: bus reset reply.n");
  196. return;
  197. }
  198. /*
  199.    * FIXME: 64bit breakage
  200.  */
  201. current_command = (Scsi_Cmnd *)m[3];
  202. /*
  203.  * Is this a control request coming back - eg an abort ?
  204.  */
  205.  
  206. if(current_command==NULL)
  207. {
  208. if(st)
  209. dprintk(("SCSI abort: %08X", m[4]));
  210. dprintk(("SCSI abort completed.n"));
  211. return;
  212. }
  213. dprintk(("Completed %ldn", current_command->serial_number));
  214. atomic_dec(&queue_depth);
  215. if(st == 0x06)
  216. {
  217. if(le32_to_cpu(m[5]) < current_command->underflow)
  218. {
  219. int i;
  220. printk(KERN_ERR "SCSI: underflow 0x%08X 0x%08Xn",
  221. le32_to_cpu(m[5]), current_command->underflow);
  222. printk("Cmd: ");
  223. for(i=0;i<15;i++)
  224. printk("%02X ", current_command->cmnd[i]);
  225. printk(".n");
  226. }
  227. else st=0;
  228. }
  229. if(st)
  230. {
  231. /* An error has occurred */
  232. dprintk((KERN_DEBUG "SCSI error %08X", m[4]));
  233. if (as == 0x0E) 
  234. /* SCSI Reset */
  235. current_command->result = DID_RESET << 16;
  236. else if (as == 0x0F)
  237. current_command->result = DID_PARITY << 16;
  238. else
  239. current_command->result = DID_ERROR << 16;
  240. }
  241. else
  242. /*
  243.  * It worked maybe ?
  244.  */
  245. current_command->result = DID_OK << 16 | ds;
  246. spin_lock(&io_request_lock);
  247. current_command->scsi_done(current_command);
  248. spin_unlock(&io_request_lock);
  249. return;
  250. }
  251. struct i2o_handler i2o_scsi_handler=
  252. {
  253. i2o_scsi_reply,
  254. NULL,
  255. NULL,
  256. NULL,
  257. "I2O SCSI OSM",
  258. 0,
  259. I2O_CLASS_SCSI_PERIPHERAL
  260. };
  261. static int i2o_find_lun(struct i2o_controller *c, struct i2o_device *d, int *target, int *lun)
  262. {
  263. u8 reply[8];
  264. if(i2o_query_scalar(c, d->lct_data.tid, 0, 3, reply, 4)<0)
  265. return -1;
  266. *target=reply[0];
  267. if(i2o_query_scalar(c, d->lct_data.tid, 0, 4, reply, 8)<0)
  268. return -1;
  269. *lun=reply[1];
  270. dprintk(("SCSI (%d,%d)n", *target, *lun));
  271. return 0;
  272. }
  273. static void i2o_scsi_init(struct i2o_controller *c, struct i2o_device *d, struct Scsi_Host *shpnt)
  274. {
  275. struct i2o_device *unit;
  276. struct i2o_scsi_host *h =(struct i2o_scsi_host *)shpnt->hostdata;
  277. int lun;
  278. int target;
  279. h->controller=c;
  280. h->bus_task=d->lct_data.tid;
  281. for(target=0;target<16;target++)
  282. for(lun=0;lun<8;lun++)
  283. h->task[target][lun] = -1;
  284. for(unit=c->devices;unit!=NULL;unit=unit->next)
  285. {
  286. dprintk(("Class %03X, parent %d, want %d.n",
  287. unit->lct_data.class_id, unit->lct_data.parent_tid, d->lct_data.tid));
  288. /* Only look at scsi and fc devices */
  289. if (    (unit->lct_data.class_id != I2O_CLASS_SCSI_PERIPHERAL)
  290.      && (unit->lct_data.class_id != I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL)
  291.    )
  292. continue;
  293. /* On our bus ? */
  294. dprintk(("Found a disk (%d).n", unit->lct_data.tid));
  295. if ((unit->lct_data.parent_tid == d->lct_data.tid)
  296.      || (unit->lct_data.parent_tid == d->lct_data.parent_tid)
  297.    )
  298. {
  299. u16 limit;
  300. dprintk(("Its ours.n"));
  301. if(i2o_find_lun(c, unit, &target, &lun)==-1)
  302. {
  303. printk(KERN_ERR "i2o_scsi: Unable to get lun for tid %d.n", unit->lct_data.tid);
  304. continue;
  305. }
  306. dprintk(("Found disk %d %d.n", target, lun));
  307. h->task[target][lun]=unit->lct_data.tid;
  308. h->tagclock[target][lun]=jiffies;
  309. /* Get the max fragments/request */
  310. i2o_query_scalar(c, d->lct_data.tid, 0xF103, 3, &limit, 2);
  311. /* sanity */
  312. if ( limit == 0 )
  313. {
  314. printk(KERN_WARNING "i2o_scsi: Ignoring unreasonable SG limit of 0 from IOP!n");
  315. limit = 1;
  316. }
  317. shpnt->sg_tablesize = limit;
  318. dprintk(("i2o_scsi: set scatter-gather to %d.n", 
  319. shpnt->sg_tablesize));
  320. }
  321. }
  322. }
  323. static int i2o_scsi_detect(Scsi_Host_Template * tpnt)
  324. {
  325. unsigned long flags;
  326. struct Scsi_Host *shpnt = NULL;
  327. int i;
  328. int count;
  329. printk("i2o_scsi.c: %sn", VERSION_STRING);
  330. if(i2o_install_handler(&i2o_scsi_handler)<0)
  331. {
  332. printk(KERN_ERR "i2o_scsi: Unable to install OSM handler.n");
  333. return 0;
  334. }
  335. scsi_context = i2o_scsi_handler.context;
  336. if((sg_chain_pool = kmalloc(SG_CHAIN_POOL_SZ, GFP_KERNEL)) == NULL)
  337. {
  338. printk("i2o_scsi: Unable to alloc %d byte SG chain buffer pool.n", SG_CHAIN_POOL_SZ);
  339. printk("i2o_scsi: SG chaining DISABLED!n");
  340. sg_max_frags = 11;
  341. }
  342. else
  343. {
  344. printk("  chain_pool: %d bytes @ %pn", SG_CHAIN_POOL_SZ, sg_chain_pool);
  345. printk("  (%d byte buffers X %d can_queue X %d i2o controllers)n",
  346. SG_CHAIN_BUF_SZ, I2O_SCSI_CAN_QUEUE, i2o_num_controllers);
  347. sg_max_frags = SG_MAX_FRAGS;    // 64
  348. }
  349. init_timer(&retry_timer);
  350. retry_timer.data = 0UL;
  351. retry_timer.function = i2o_retry_run;
  352. // printk("SCSI OSM at %d.n", scsi_context);
  353. for (count = 0, i = 0; i < MAX_I2O_CONTROLLERS; i++)
  354. {
  355. struct i2o_controller *c=i2o_find_controller(i);
  356. struct i2o_device *d;
  357. /*
  358.  * This controller doesn't exist.
  359.  */
  360. if(c==NULL)
  361. continue;
  362. /*
  363.  * Fixme - we need some altered device locking. This
  364.  * is racing with device addition in theory. Easy to fix.
  365.  */
  366. for(d=c->devices;d!=NULL;d=d->next)
  367. {
  368. /*
  369.  * bus_adapter, SCSI (obsolete), or FibreChannel busses only
  370.  */
  371. if(    (d->lct_data.class_id!=I2O_CLASS_BUS_ADAPTER_PORT) // bus_adapter
  372. //     && (d->lct_data.class_id!=I2O_CLASS_FIBRE_CHANNEL_PORT) // FC_PORT
  373.   )
  374. continue;
  375. shpnt = scsi_register(tpnt, sizeof(struct i2o_scsi_host));
  376. if(shpnt==NULL)
  377. continue;
  378. save_flags(flags);
  379. cli();
  380. shpnt->unique_id = (u32)d;
  381. shpnt->io_port = 0;
  382. shpnt->n_io_port = 0;
  383. shpnt->irq = 0;
  384. shpnt->this_id = /* Good question */15;
  385. restore_flags(flags);
  386. i2o_scsi_init(c, d, shpnt);
  387. count++;
  388. }
  389. }
  390. i2o_scsi_hosts = count;
  391. if(count==0)
  392. {
  393. if(sg_chain_pool!=NULL)
  394. {
  395. kfree(sg_chain_pool);
  396. sg_chain_pool = NULL;
  397. }
  398. flush_pending();
  399. del_timer(&retry_timer);
  400. i2o_remove_handler(&i2o_scsi_handler);
  401. }
  402. return count;
  403. }
  404. static int i2o_scsi_release(struct Scsi_Host *host)
  405. {
  406. if(--i2o_scsi_hosts==0)
  407. {
  408. if(sg_chain_pool!=NULL)
  409. {
  410. kfree(sg_chain_pool);
  411. sg_chain_pool = NULL;
  412. }
  413. flush_pending();
  414. del_timer(&retry_timer);
  415. i2o_remove_handler(&i2o_scsi_handler);
  416. }
  417. return 0;
  418. }
  419. static const char *i2o_scsi_info(struct Scsi_Host *SChost)
  420. {
  421. struct i2o_scsi_host *hostdata;
  422. hostdata = (struct i2o_scsi_host *)SChost->hostdata;
  423. return(&hostdata->controller->name[0]);
  424. }
  425. static int i2o_scsi_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
  426. {
  427. int i;
  428. int tid;
  429. struct i2o_controller *c;
  430. Scsi_Cmnd *current_command;
  431. struct Scsi_Host *host;
  432. struct i2o_scsi_host *hostdata;
  433. u32 *msg, *mptr;
  434. u32 m;
  435. u32 *lenptr;
  436. int direction;
  437. int scsidir;
  438. u32 len;
  439. u32 reqlen;
  440. u32 tag;
  441. static int max_qd = 1;
  442. /*
  443.  * Do the incoming paperwork
  444.  */
  445.  
  446. host = SCpnt->host;
  447. hostdata = (struct i2o_scsi_host *)host->hostdata;
  448.  
  449. c = hostdata->controller;
  450. prefetch(c);
  451. prefetchw(&queue_depth);
  452. SCpnt->scsi_done = done;
  453. if(SCpnt->target > 15)
  454. {
  455. printk(KERN_ERR "i2o_scsi: Wild target %d.n", SCpnt->target);
  456. return -1;
  457. }
  458. tid = hostdata->task[SCpnt->target][SCpnt->lun];
  459. dprintk(("qcmd: Tid = %dn", tid));
  460. current_command = SCpnt; /* set current command                */
  461. current_command->scsi_done = done; /* set ptr to done function           */
  462. /* We don't have such a device. Pretend we did the command 
  463.    and that selection timed out */
  464. if(tid == -1)
  465. {
  466. SCpnt->result = DID_NO_CONNECT << 16;
  467. done(SCpnt);
  468. return 0;
  469. }
  470. dprintk(("Real scsi messages.n"));
  471. /*
  472.  * Obtain an I2O message. Right now we _have_ to obtain one
  473.  * until the scsi layer stuff is cleaned up.
  474.  */
  475.  
  476. do
  477. {
  478. mb();
  479. m = le32_to_cpu(I2O_POST_READ32(c));
  480. }
  481. while(m==0xFFFFFFFF);
  482. msg = (u32 *)(c->mem_offset + m);
  483. /*
  484.  * Put together a scsi execscb message
  485.  */
  486. len = SCpnt->request_bufflen;
  487. direction = 0x00000000; // SGL IN  (osm<--iop)
  488. if(SCpnt->sc_data_direction == SCSI_DATA_NONE)
  489. scsidir = 0x00000000; // DATA NO XFER
  490. else if(SCpnt->sc_data_direction == SCSI_DATA_WRITE)
  491. {
  492. direction=0x04000000; // SGL OUT  (osm-->iop)
  493. scsidir  =0x80000000; // DATA OUT (iop-->dev)
  494. }
  495. else if(SCpnt->sc_data_direction == SCSI_DATA_READ)
  496. {
  497. scsidir  =0x40000000; // DATA IN  (iop<--dev)
  498. }
  499. else
  500. {
  501. /* Unknown - kill the command */
  502. SCpnt->result = DID_NO_CONNECT << 16;
  503. done(SCpnt);
  504. return 0;
  505. }
  506. i2o_raw_writel(I2O_CMD_SCSI_EXEC<<24|HOST_TID<<12|tid, &msg[1]);
  507. i2o_raw_writel(scsi_context, &msg[2]); /* So the I2O layer passes to us */
  508. /* Sorry 64bit folks. FIXME */
  509. i2o_raw_writel((u32)SCpnt, &msg[3]); /* We want the SCSI control block back */
  510. /* LSI_920_PCI_QUIRK
  511.  *
  512.  * Intermittant observations of msg frame word data corruption
  513.  * observed on msg[4] after:
  514.  *   WRITE, READ-MODIFY-WRITE
  515.  * operations.  19990606 -sralston
  516.  *
  517.  * (Hence we build this word via tag. Its good practice anyway
  518.  *  we don't want fetches over PCI needlessly)
  519.  */
  520. tag=0;
  521. /*
  522.  * Attach tags to the devices
  523.  */
  524. if(SCpnt->device->tagged_supported)
  525. {
  526. /*
  527.  * Some drives are too stupid to handle fairness issues
  528.  * with tagged queueing. We throw in the odd ordered
  529.  * tag to stop them starving themselves.
  530.  */
  531. if((jiffies - hostdata->tagclock[SCpnt->target][SCpnt->lun]) > (5*HZ))
  532. {
  533. tag=0x01800000; /* ORDERED! */
  534. hostdata->tagclock[SCpnt->target][SCpnt->lun]=jiffies;
  535. }
  536. else
  537. {
  538. /* Hmmm...  I always see value of 0 here,
  539.  *  of which {HEAD_OF, ORDERED, SIMPLE} are NOT!  -sralston
  540.  */
  541. if(SCpnt->tag == HEAD_OF_QUEUE_TAG)
  542. tag=0x01000000;
  543. else if(SCpnt->tag == ORDERED_QUEUE_TAG)
  544. tag=0x01800000;
  545. }
  546. }
  547. /* Direction, disconnect ok, tag, CDBLen */
  548. i2o_raw_writel(scsidir|0x20000000|SCpnt->cmd_len|tag, &msg[4]);
  549. mptr=msg+5;
  550. /* 
  551.  * Write SCSI command into the message - always 16 byte block 
  552.  */
  553.  
  554. memcpy_toio(mptr, SCpnt->cmnd, 16);
  555. mptr+=4;
  556. lenptr=mptr++; /* Remember me - fill in when we know */
  557. reqlen = 12; // SINGLE SGE
  558. /*
  559.  * Now fill in the SGList and command 
  560.  *
  561.  * FIXME: we need to set the sglist limits according to the 
  562.  * message size of the I2O controller. We might only have room
  563.  * for 6 or so worst case
  564.  *
  565.  * FIXME: pci dma mapping
  566.  */
  567. if(SCpnt->use_sg)
  568. {
  569. struct scatterlist *sg = (struct scatterlist *)SCpnt->request_buffer;
  570. int chain = 0;
  571. len = 0;
  572. if((sg_max_frags > 11) && (SCpnt->use_sg > 11))
  573. {
  574. chain = 1;
  575. /*
  576.  * Need to chain!
  577.  */
  578. i2o_raw_writel(direction|0xB0000000|(SCpnt->use_sg*2*4), mptr++);
  579. i2o_raw_writel(virt_to_bus(sg_chain_pool + sg_chain_tag), mptr);
  580. mptr = (u32*)(sg_chain_pool + sg_chain_tag);
  581. if (SCpnt->use_sg > max_sg_len)
  582. {
  583. max_sg_len = SCpnt->use_sg;
  584. printk("i2o_scsi: Chain SG! SCpnt=%p, SG_FragCnt=%d, SG_idx=%dn",
  585. SCpnt, SCpnt->use_sg, sg_chain_tag);
  586. }
  587. if ( ++sg_chain_tag == SG_MAX_BUFS )
  588. sg_chain_tag = 0;
  589. for(i = 0 ; i < SCpnt->use_sg; i++)
  590. {
  591. *mptr++=direction|0x10000000|sg->length;
  592. len+=sg->length;
  593. *mptr++=virt_to_bus(sg->address);
  594. sg++;
  595. }
  596. mptr[-2]=direction|0xD0000000|(sg-1)->length;
  597. }
  598. else
  599. {
  600. for(i = 0 ; i < SCpnt->use_sg; i++)
  601. {
  602. i2o_raw_writel(direction|0x10000000|sg->length, mptr++);
  603. len+=sg->length;
  604. i2o_raw_writel(virt_to_bus(sg->address), mptr++);
  605. sg++;
  606. }
  607. /* Make this an end of list. Again evade the 920 bug and
  608.    unwanted PCI read traffic */
  609. i2o_raw_writel(direction|0xD0000000|(sg-1)->length, &mptr[-2]);
  610. }
  611. if(!chain)
  612. reqlen = mptr - msg;
  613. i2o_raw_writel(len, lenptr);
  614. if(len != SCpnt->underflow)
  615. printk("Cmd len %08X Cmd underflow %08Xn",
  616. len, SCpnt->underflow);
  617. }
  618. else
  619. {
  620. dprintk(("non sg for %p, %dn", SCpnt->request_buffer,
  621. SCpnt->request_bufflen));
  622. i2o_raw_writel(len = SCpnt->request_bufflen, lenptr);
  623. if(len == 0)
  624. {
  625. reqlen = 9;
  626. }
  627. else
  628. {
  629. i2o_raw_writel(0xD0000000|direction|SCpnt->request_bufflen, mptr++);
  630. i2o_raw_writel(virt_to_bus(SCpnt->request_buffer), mptr++);
  631. }
  632. }
  633. /*
  634.  * Stick the headers on 
  635.  */
  636. i2o_raw_writel(reqlen<<16 | SGL_OFFSET_10, msg);
  637. /* Queue the message */
  638. i2o_post_message(c,m);
  639. atomic_inc(&queue_depth);
  640. if(atomic_read(&queue_depth)> max_qd)
  641. {
  642. max_qd=atomic_read(&queue_depth);
  643. printk("Queue depth now %d.n", max_qd);
  644. }
  645. mb();
  646. dprintk(("Issued %ldn", current_command->serial_number));
  647. return 0;
  648. }
  649. static void internal_done(Scsi_Cmnd * SCpnt)
  650. {
  651. SCpnt->SCp.Status++;
  652. }
  653. static int i2o_scsi_command(Scsi_Cmnd * SCpnt)
  654. {
  655. i2o_scsi_queuecommand(SCpnt, internal_done);
  656. SCpnt->SCp.Status = 0;
  657. while (!SCpnt->SCp.Status)
  658. barrier();
  659. return SCpnt->result;
  660. }
  661. static int i2o_scsi_abort(Scsi_Cmnd * SCpnt)
  662. {
  663. struct i2o_controller *c;
  664. struct Scsi_Host *host;
  665. struct i2o_scsi_host *hostdata;
  666. unsigned long msg;
  667. u32 m;
  668. int tid;
  669. printk("i2o_scsi: Aborting command block.n");
  670. host = SCpnt->host;
  671. hostdata = (struct i2o_scsi_host *)host->hostdata;
  672. tid = hostdata->task[SCpnt->target][SCpnt->lun];
  673. if(tid==-1)
  674. {
  675. printk(KERN_ERR "impossible command to abort.n");
  676. return SCSI_ABORT_NOT_RUNNING;
  677. }
  678. c = hostdata->controller;
  679. /*
  680.  * Obtain an I2O message. Right now we _have_ to obtain one
  681.  * until the scsi layer stuff is cleaned up.
  682.  */
  683.  
  684. do
  685. {
  686. mb();
  687. m = le32_to_cpu(I2O_POST_READ32(c));
  688. }
  689. while(m==0xFFFFFFFF);
  690. msg = c->mem_offset + m;
  691. i2o_raw_writel(FIVE_WORD_MSG_SIZE, msg);
  692. i2o_raw_writel(I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|tid, msg+4);
  693. i2o_raw_writel(scsi_context, msg+8);
  694. i2o_raw_writel(0, msg+12); /* Not needed for an abort */
  695. i2o_raw_writel((u32)SCpnt, msg+16); /* FIXME 32bitism */
  696. wmb();
  697. i2o_post_message(c,m);
  698. wmb();
  699. return SCSI_ABORT_PENDING;
  700. }
  701. static int i2o_scsi_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
  702. {
  703. int tid;
  704. struct i2o_controller *c;
  705. struct Scsi_Host *host;
  706. struct i2o_scsi_host *hostdata;
  707. u32 m;
  708. unsigned long msg;
  709. /*
  710.  * Find the TID for the bus
  711.  */
  712. printk("i2o_scsi: Attempting to reset the bus.n");
  713. host = SCpnt->host;
  714. hostdata = (struct i2o_scsi_host *)host->hostdata;
  715. tid = hostdata->bus_task;
  716. c = hostdata->controller;
  717. /*
  718.  * Now send a SCSI reset request. Any remaining commands
  719.  * will be aborted by the IOP. We need to catch the reply
  720.  * possibly ?
  721.  */
  722.  
  723. m = le32_to_cpu(I2O_POST_READ32(c));
  724. /*
  725.  * No free messages, try again next time - no big deal
  726.  */
  727.  
  728. if(m == 0xFFFFFFFF)
  729. return SCSI_RESET_PUNT;
  730. msg = c->mem_offset + m;
  731. i2o_raw_writel(FOUR_WORD_MSG_SIZE|SGL_OFFSET_0, msg);
  732. i2o_raw_writel(I2O_CMD_SCSI_BUSRESET<<24|HOST_TID<<12|tid, msg+4);
  733. i2o_raw_writel(scsi_context|0x80000000, msg+8);
  734. /* We use the top bit to split controller and unit transactions */
  735. /* Now store unit,tid so we can tie the completion back to a specific device */
  736. i2o_raw_writel(c->unit << 16 | tid, msg+12);
  737. wmb();
  738. i2o_post_message(c,m);
  739. return SCSI_RESET_PENDING;
  740. }
  741. /*
  742.  * This is anyones guess quite frankly.
  743.  */
  744.  
  745. static int i2o_scsi_bios_param(Disk * disk, kdev_t dev, int *ip)
  746. {
  747. int size;
  748. size = disk->capacity;
  749. ip[0] = 64; /* heads                        */
  750. ip[1] = 32; /* sectors                      */
  751. if ((ip[2] = size >> 11) > 1024) { /* cylinders, test for big disk */
  752. ip[0] = 255; /* heads                        */
  753. ip[1] = 63; /* sectors                      */
  754. ip[2] = size / (255 * 63); /* cylinders                    */
  755. }
  756. return 0;
  757. }
  758. MODULE_AUTHOR("Red Hat Software");
  759. MODULE_LICENSE("GPL");
  760. static Scsi_Host_Template driver_template = I2OSCSI;
  761. #include "../../scsi/scsi_module.c"