seagate.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. /*
  2. * seagate.c Copyright (C) 1992, 1993 Drew Eckhardt
  3. * low level scsi driver for ST01/ST02, Future Domain TMC-885,
  4. * TMC-950 by Drew Eckhardt <drew@colorado.edu>
  5. *
  6. * Note : TMC-880 boards don't work because they have two bits in
  7. * the status register flipped, I'll fix this "RSN"
  8. * [why do I have strong feeling that above message is from 1993? :-)
  9. * pavel@ucw.cz]
  10. *
  11. * This card does all the I/O via memory mapped I/O, so there is no need
  12. * to check or allocate a region of the I/O address space.
  13. */
  14. /* 1996 - to use new read{b,w,l}, write{b,w,l}, and phys_to_virt
  15. * macros, replaced assembler routines with C. There's probably a
  16. * performance hit, but I only have a cdrom and can't tell. Define
  17. * SEAGATE_USE_ASM if you want the old assembler code -- SJT
  18. *
  19. * 1998-jul-29 - created DPRINTK macros and made it work under
  20. * linux 2.1.112, simplified some #defines etc. <pavel@ucw.cz>
  21. *
  22. * Aug 2000 - aeb - deleted seagate_st0x_biosparam(). It would try to
  23. * read the physical disk geometry, a bad mistake. Of course it doesn't
  24. * matter much what geometry one invents, but on large disks it
  25. * returned 256 (or more) heads, causing all kind of failures.
  26. * Of course this means that people might see a different geometry now,
  27. * so boot parameters may be necessary in some cases.
  28. */
  29. /*
  30. * Configuration :
  31. * To use without BIOS -DOVERRIDE=base_address -DCONTROLLER=FD or SEAGATE
  32. * -DIRQ will override the default of 5.
  33. * Note: You can now set these options from the kernel's "command line".
  34. * The syntax is:
  35. *
  36. * st0x=ADDRESS,IRQ (for a Seagate controller)
  37. * or:
  38. * tmc8xx=ADDRESS,IRQ (for a TMC-8xx or TMC-950 controller)
  39. * eg:
  40. * tmc8xx=0xC8000,15
  41. *
  42. * will configure the driver for a TMC-8xx style controller using IRQ 15
  43. * with a base address of 0xC8000.
  44. *
  45. * -DARBITRATE
  46. * Will cause the host adapter to arbitrate for the
  47. * bus for better SCSI-II compatibility, rather than just
  48. * waiting for BUS FREE and then doing its thing. Should
  49. * let us do one command per Lun when I integrate my
  50. * reorganization changes into the distribution sources.
  51. *
  52. * -DDEBUG=65535
  53. * Will activate debug code.
  54. *
  55. * -DFAST or -DFAST32
  56. * Will use blind transfers where possible
  57. *
  58. * -DPARITY
  59. * This will enable parity.
  60. *
  61. * -DSEAGATE_USE_ASM
  62. * Will use older seagate assembly code. should be (very small amount)
  63. * Faster.
  64. *
  65. * -DSLOW_RATE=50
  66. * Will allow compatibility with broken devices that don't
  67. * handshake fast enough (ie, some CD ROM's) for the Seagate
  68. * code.
  69. *
  70. * 50 is some number, It will let you specify a default
  71. * transfer rate if handshaking isn't working correctly.
  72. *
  73. * -DOLDCNTDATASCEME There is a new sceme to set the CONTROL
  74. * and DATA reigsters which complies more closely
  75. * with the SCSI2 standard. This hopefully eliminates
  76. * the need to swap the order these registers are
  77. * 'messed' with. It makes the following two options
  78. * obsolete. To reenable the old sceme define this.
  79. *
  80. * The following to options are patches from the SCSI.HOWTO
  81. *
  82. * -DSWAPSTAT This will swap the definitions for STAT_MSG and STAT_CD.
  83. *
  84. * -DSWAPCNTDATA This will swap the order that seagate.c messes with
  85. * the CONTROL an DATA registers.
  86. */
  87. #include <linux/module.h>
  88. #include <linux/interrupt.h>
  89. #include <linux/spinlock.h>
  90. #include <linux/signal.h>
  91. #include <linux/string.h>
  92. #include <linux/proc_fs.h>
  93. #include <linux/init.h>
  94. #include <linux/delay.h>
  95. #include <linux/blkdev.h>
  96. #include <linux/stat.h>
  97. #include <linux/delay.h>
  98. #include <asm/io.h>
  99. #include <asm/system.h>
  100. #include <asm/uaccess.h>
  101. #include "scsi.h"
  102. #include <scsi/scsi_dbg.h>
  103. #include <scsi/scsi_host.h>
  104. #include "seagate.h"
  105. #include <scsi/scsi_ioctl.h>
  106. #ifdef DEBUG
  107. #define DPRINTK( when, msg... ) do { if ( (DEBUG & (when)) == (when) ) printk( msg ); } while (0)
  108. #else
  109. #define DPRINTK( when, msg... ) do { } while (0)
  110. #endif
  111. #define DANY( msg... ) DPRINTK( 0xffff, msg );
  112. #ifndef IRQ
  113. #define IRQ 5
  114. #endif
  115. #ifdef FAST32
  116. #define FAST
  117. #endif
  118. #undef LINKED /* Linked commands are currently broken! */
  119. #if defined(OVERRIDE) && !defined(CONTROLLER)
  120. #error Please use -DCONTROLLER=SEAGATE or -DCONTROLLER=FD to override controller type
  121. #endif
  122. #ifndef __i386__
  123. #undef SEAGATE_USE_ASM
  124. #endif
  125. /*
  126. Thanks to Brian Antoine for the example code in his Messy-Loss ST-01
  127. driver, and Mitsugu Suzuki for information on the ST-01
  128. SCSI host.
  129. */
  130. /*
  131. CONTROL defines
  132. */
  133. #define CMD_RST 0x01
  134. #define CMD_SEL 0x02
  135. #define CMD_BSY 0x04
  136. #define CMD_ATTN 0x08
  137. #define CMD_START_ARB 0x10
  138. #define CMD_EN_PARITY 0x20
  139. #define CMD_INTR 0x40
  140. #define CMD_DRVR_ENABLE 0x80
  141. /*
  142. STATUS
  143. */
  144. #ifdef SWAPSTAT
  145. #define STAT_MSG 0x08
  146. #define STAT_CD 0x02
  147. #else
  148. #define STAT_MSG 0x02
  149. #define STAT_CD 0x08
  150. #endif
  151. #define STAT_BSY 0x01
  152. #define STAT_IO 0x04
  153. #define STAT_REQ 0x10
  154. #define STAT_SEL 0x20
  155. #define STAT_PARITY 0x40
  156. #define STAT_ARB_CMPL 0x80
  157. /*
  158. REQUESTS
  159. */
  160. #define REQ_MASK (STAT_CD | STAT_IO | STAT_MSG)
  161. #define REQ_DATAOUT 0
  162. #define REQ_DATAIN STAT_IO
  163. #define REQ_CMDOUT STAT_CD
  164. #define REQ_STATIN (STAT_CD | STAT_IO)
  165. #define REQ_MSGOUT (STAT_MSG | STAT_CD)
  166. #define REQ_MSGIN (STAT_MSG | STAT_CD | STAT_IO)
  167. extern volatile int seagate_st0x_timeout;
  168. #ifdef PARITY
  169. #define BASE_CMD CMD_EN_PARITY
  170. #else
  171. #define BASE_CMD 0
  172. #endif
  173. /*
  174. Debugging code
  175. */
  176. #define PHASE_BUS_FREE 1
  177. #define PHASE_ARBITRATION 2
  178. #define PHASE_SELECTION 4
  179. #define PHASE_DATAIN 8
  180. #define PHASE_DATAOUT 0x10
  181. #define PHASE_CMDOUT 0x20
  182. #define PHASE_MSGIN 0x40
  183. #define PHASE_MSGOUT 0x80
  184. #define PHASE_STATUSIN 0x100
  185. #define PHASE_ETC (PHASE_DATAIN | PHASE_DATAOUT | PHASE_CMDOUT | PHASE_MSGIN | PHASE_MSGOUT | PHASE_STATUSIN)
  186. #define PRINT_COMMAND 0x200
  187. #define PHASE_EXIT 0x400
  188. #define PHASE_RESELECT 0x800
  189. #define DEBUG_FAST 0x1000
  190. #define DEBUG_SG 0x2000
  191. #define DEBUG_LINKED 0x4000
  192. #define DEBUG_BORKEN 0x8000
  193. /*
  194. * Control options - these are timeouts specified in .01 seconds.
  195. */
  196. /* 30, 20 work */
  197. #define ST0X_BUS_FREE_DELAY 25
  198. #define ST0X_SELECTION_DELAY 25
  199. #define SEAGATE 1 /* these determine the type of the controller */
  200. #define FD 2
  201. #define ST0X_ID_STR "Seagate ST-01/ST-02"
  202. #define FD_ID_STR "TMC-8XX/TMC-950"
  203. static int internal_command (unsigned char target, unsigned char lun,
  204. const void *cmnd,
  205. void *buff, int bufflen, int reselect);
  206. static int incommand; /* set if arbitration has finished
  207. and we are in some command phase. */
  208. static unsigned int base_address = 0; /* Where the card ROM starts, used to
  209. calculate memory mapped register
  210. location. */
  211. static void __iomem *st0x_cr_sr; /* control register write, status
  212. register read. 256 bytes in
  213. length.
  214. Read is status of SCSI BUS, as per
  215. STAT masks. */
  216. static void __iomem *st0x_dr; /* data register, read write 256
  217. bytes in length. */
  218. static volatile int st0x_aborted = 0; /* set when we are aborted, ie by a
  219. time out, etc. */
  220. static unsigned char controller_type = 0; /* set to SEAGATE for ST0x
  221. boards or FD for TMC-8xx
  222. boards */
  223. static int irq = IRQ;
  224. module_param(base_address, uint, 0);
  225. module_param(controller_type, byte, 0);
  226. module_param(irq, int, 0);
  227. MODULE_LICENSE("GPL");
  228. #define retcode(result) (((result) << 16) | (message << 8) | status)
  229. #define STATUS ((u8) readb(st0x_cr_sr))
  230. #define DATA ((u8) readb(st0x_dr))
  231. #define WRITE_CONTROL(d) { writeb((d), st0x_cr_sr); }
  232. #define WRITE_DATA(d) { writeb((d), st0x_dr); }
  233. #ifndef OVERRIDE
  234. static unsigned int seagate_bases[] = {
  235. 0xc8000, 0xca000, 0xcc000,
  236. 0xce000, 0xdc000, 0xde000
  237. };
  238. typedef struct {
  239. const unsigned char *signature;
  240. unsigned offset;
  241. unsigned length;
  242. unsigned char type;
  243. } Signature;
  244. static Signature __initdata signatures[] = {
  245. {"ST01 v1.7 (C) Copyright 1987 Seagate", 15, 37, SEAGATE},
  246. {"SCSI BIOS 2.00 (C) Copyright 1987 Seagate", 15, 40, SEAGATE},
  247. /*
  248. * The following two lines are NOT mistakes. One detects ROM revision
  249. * 3.0.0, the other 3.2. Since seagate has only one type of SCSI adapter,
  250. * and this is not going to change, the "SEAGATE" and "SCSI" together
  251. * are probably "good enough"
  252. */
  253. {"SEAGATE SCSI BIOS ", 16, 17, SEAGATE},
  254. {"SEAGATE SCSI BIOS ", 17, 17, SEAGATE},
  255. /*
  256. * However, future domain makes several incompatible SCSI boards, so specific
  257. * signatures must be used.
  258. */
  259. {"FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89", 5, 46, FD},
  260. {"FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89", 5, 46, FD},
  261. {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90", 5, 47, FD},
  262. {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90", 5, 47, FD},
  263. {"FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90", 5, 46, FD},
  264. {"FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92", 5, 44, FD},
  265. {"IBM F1 BIOS V1.1004/30/92", 5, 25, FD},
  266. {"FUTURE DOMAIN TMC-950", 5, 21, FD},
  267. /* Added for 2.2.16 by Matthias_Heidbrink@b.maus.de */
  268. {"IBM F1 V1.2009/22/93", 5, 25, FD},
  269. };
  270. #define NUM_SIGNATURES (sizeof(signatures) / sizeof(Signature))
  271. #endif /* n OVERRIDE */
  272. /*
  273. * hostno stores the hostnumber, as told to us by the init routine.
  274. */
  275. static int hostno = -1;
  276. static void seagate_reconnect_intr (int, void *, struct pt_regs *);
  277. static irqreturn_t do_seagate_reconnect_intr (int, void *, struct pt_regs *);
  278. #ifdef FAST
  279. static int fast = 1;
  280. #else
  281. #define fast 0
  282. #endif
  283. #ifdef SLOW_RATE
  284. /*
  285. * Support for broken devices :
  286. * The Seagate board has a handshaking problem. Namely, a lack
  287. * thereof for slow devices. You can blast 600K/second through
  288. * it if you are polling for each byte, more if you do a blind
  289. * transfer. In the first case, with a fast device, REQ will
  290. * transition high-low or high-low-high before your loop restarts
  291. * and you'll have no problems. In the second case, the board
  292. * will insert wait states for up to 13.2 usecs for REQ to
  293. * transition low->high, and everything will work.
  294. *
  295. * However, there's nothing in the state machine that says
  296. * you *HAVE* to see a high-low-high set of transitions before
  297. * sending the next byte, and slow things like the Trantor CD ROMS
  298. * will break because of this.
  299. *
  300. * So, we need to slow things down, which isn't as simple as it
  301. * seems. We can't slow things down period, because then people
  302. * who don't recompile their kernels will shoot me for ruining
  303. * their performance. We need to do it on a case per case basis.
  304. *
  305. * The best for performance will be to, only for borken devices
  306. * (this is stored on a per-target basis in the scsi_devices array)
  307. *
  308. * Wait for a low->high transition before continuing with that
  309. * transfer. If we timeout, continue anyways. We don't need
  310. * a long timeout, because REQ should only be asserted until the
  311. * corresponding ACK is received and processed.
  312. *
  313. * Note that we can't use the system timer for this, because of
  314. * resolution, and we *really* can't use the timer chip since
  315. * gettimeofday() and the beeper routines use that. So,
  316. * the best thing for us to do will be to calibrate a timing
  317. * loop in the initialization code using the timer chip before
  318. * gettimeofday() can screw with it.
  319. *
  320. * FIXME: this is broken (not borken :-). Empty loop costs less than
  321. * loop with ISA access in it! -- pavel@ucw.cz
  322. */
  323. static int borken_calibration = 0;
  324. static void __init borken_init (void)
  325. {
  326. register int count = 0, start = jiffies + 1, stop = start + 25;
  327. /* FIXME: There may be a better approach, this is a straight port for
  328. now */
  329. preempt_disable();
  330. while (time_before (jiffies, start))
  331. cpu_relax();
  332. for (; time_before (jiffies, stop); ++count)
  333. cpu_relax();
  334. preempt_enable();
  335. /*
  336. * Ok, we now have a count for .25 seconds. Convert to a
  337. * count per second and divide by transfer rate in K. */
  338. borken_calibration = (count * 4) / (SLOW_RATE * 1024);
  339. if (borken_calibration < 1)
  340. borken_calibration = 1;
  341. }
  342. static inline void borken_wait (void)
  343. {
  344. register int count;
  345. for (count = borken_calibration; count && (STATUS & STAT_REQ); --count)
  346. cpu_relax();
  347. #if (DEBUG & DEBUG_BORKEN)
  348. if (count)
  349. printk ("scsi%d : borken timeout\n", hostno);
  350. #endif
  351. }
  352. #endif /* def SLOW_RATE */
  353. /* These beasts only live on ISA, and ISA means 8MHz. Each ULOOP()
  354. * contains at least one ISA access, which takes more than 0.125
  355. * usec. So if we loop 8 times time in usec, we are safe.
  356. */
  357. #define ULOOP( i ) for (clock = i*8;;)
  358. #define TIMEOUT (!(clock--))
  359. int __init seagate_st0x_detect (struct scsi_host_template * tpnt)
  360. {
  361. struct Scsi_Host *instance;
  362. int i, j;
  363. unsigned long cr, dr;
  364. tpnt->proc_name = "seagate";
  365. /*
  366. * First, we try for the manual override.
  367. */
  368. DANY ("Autodetecting ST0x / TMC-8xx\n");
  369. if (hostno != -1) {
  370. printk (KERN_ERR "seagate_st0x_detect() called twice?!\n");
  371. return 0;
  372. }
  373. /* If the user specified the controller type from the command line,
  374. controller_type will be non-zero, so don't try to detect one */
  375. if (!controller_type) {
  376. #ifdef OVERRIDE
  377. base_address = OVERRIDE;
  378. controller_type = CONTROLLER;
  379. DANY ("Base address overridden to %x, controller type is %s\n",
  380. base_address,
  381. controller_type == SEAGATE ? "SEAGATE" : "FD");
  382. #else /* OVERRIDE */
  383. /*
  384. * To detect this card, we simply look for the signature
  385. * from the BIOS version notice in all the possible locations
  386. * of the ROM's. This has a nice side effect of not trashing
  387. * any register locations that might be used by something else.
  388. *
  389. * XXX - note that we probably should be probing the address
  390. * space for the on-board RAM instead.
  391. */
  392. for (i = 0; i < (sizeof (seagate_bases) / sizeof (unsigned int)); ++i) {
  393. void __iomem *p = ioremap(seagate_bases[i], 0x2000);
  394. if (!p)
  395. continue;
  396. for (j = 0; j < NUM_SIGNATURES; ++j)
  397. if (check_signature(p + signatures[j].offset, signatures[j].signature, signatures[j].length)) {
  398. base_address = seagate_bases[i];
  399. controller_type = signatures[j].type;
  400. break;
  401. }
  402. iounmap(p);
  403. }
  404. #endif /* OVERRIDE */
  405. }
  406. /* (! controller_type) */
  407. tpnt->this_id = (controller_type == SEAGATE) ? 7 : 6;
  408. tpnt->name = (controller_type == SEAGATE) ? ST0X_ID_STR : FD_ID_STR;
  409. if (!base_address) {
  410. printk(KERN_INFO "seagate: ST0x/TMC-8xx not detected.\n");
  411. return 0;
  412. }
  413. cr = base_address + (controller_type == SEAGATE ? 0x1a00 : 0x1c00);
  414. dr = cr + 0x200;
  415. st0x_cr_sr = ioremap(cr, 0x100);
  416. st0x_dr = ioremap(dr, 0x100);
  417. DANY("%s detected. Base address = %x, cr = %x, dr = %x\n",
  418. tpnt->name, base_address, cr, dr);
  419. /*
  420. * At all times, we will use IRQ 5. Should also check for IRQ3
  421. * if we lose our first interrupt.
  422. */
  423. instance = scsi_register (tpnt, 0);
  424. if (instance == NULL)
  425. return 0;
  426. hostno = instance->host_no;
  427. if (request_irq (irq, do_seagate_reconnect_intr, SA_INTERRUPT, (controller_type == SEAGATE) ? "seagate" : "tmc-8xx", instance)) {
  428. printk(KERN_ERR "scsi%d : unable to allocate IRQ%d\n", hostno, irq);
  429. return 0;
  430. }
  431. instance->irq = irq;
  432. instance->io_port = base_address;
  433. #ifdef SLOW_RATE
  434. printk(KERN_INFO "Calibrating borken timer... ");
  435. borken_init();
  436. printk(" %d cycles per transfer\n", borken_calibration);
  437. #endif
  438. printk (KERN_INFO "This is one second... ");
  439. {
  440. int clock;
  441. ULOOP (1 * 1000 * 1000) {
  442. STATUS;
  443. if (TIMEOUT)
  444. break;
  445. }
  446. }
  447. printk ("done, %s options:"
  448. #ifdef ARBITRATE
  449. " ARBITRATE"
  450. #endif
  451. #ifdef DEBUG
  452. " DEBUG"
  453. #endif
  454. #ifdef FAST
  455. " FAST"
  456. #ifdef FAST32
  457. "32"
  458. #endif
  459. #endif
  460. #ifdef LINKED
  461. " LINKED"
  462. #endif
  463. #ifdef PARITY
  464. " PARITY"
  465. #endif
  466. #ifdef SEAGATE_USE_ASM
  467. " SEAGATE_USE_ASM"
  468. #endif
  469. #ifdef SLOW_RATE
  470. " SLOW_RATE"
  471. #endif
  472. #ifdef SWAPSTAT
  473. " SWAPSTAT"
  474. #endif
  475. #ifdef SWAPCNTDATA
  476. " SWAPCNTDATA"
  477. #endif
  478. "\n", tpnt->name);
  479. return 1;
  480. }
  481. static const char *seagate_st0x_info (struct Scsi_Host *shpnt)
  482. {
  483. static char buffer[64];
  484. snprintf(buffer, 64, "%s at irq %d, address 0x%05X",
  485. (controller_type == SEAGATE) ? ST0X_ID_STR : FD_ID_STR,
  486. irq, base_address);
  487. return buffer;
  488. }
  489. /*
  490. * These are our saved pointers for the outstanding command that is
  491. * waiting for a reconnect
  492. */
  493. static unsigned char current_target, current_lun;
  494. static unsigned char *current_cmnd, *current_data;
  495. static int current_nobuffs;
  496. static struct scatterlist *current_buffer;
  497. static int current_bufflen;
  498. #ifdef LINKED
  499. /*
  500. * linked_connected indicates whether or not we are currently connected to
  501. * linked_target, linked_lun and in an INFORMATION TRANSFER phase,
  502. * using linked commands.
  503. */
  504. static int linked_connected = 0;
  505. static unsigned char linked_target, linked_lun;
  506. #endif
  507. static void (*done_fn) (Scsi_Cmnd *) = NULL;
  508. static Scsi_Cmnd *SCint = NULL;
  509. /*
  510. * These control whether or not disconnect / reconnect will be attempted,
  511. * or are being attempted.
  512. */
  513. #define NO_RECONNECT 0
  514. #define RECONNECT_NOW 1
  515. #define CAN_RECONNECT 2
  516. /*
  517. * LINKED_RIGHT indicates that we are currently connected to the correct target
  518. * for this command, LINKED_WRONG indicates that we are connected to the wrong
  519. * target. Note that these imply CAN_RECONNECT and require defined(LINKED).
  520. */
  521. #define LINKED_RIGHT 3
  522. #define LINKED_WRONG 4
  523. /*
  524. * This determines if we are expecting to reconnect or not.
  525. */
  526. static int should_reconnect = 0;
  527. /*
  528. * The seagate_reconnect_intr routine is called when a target reselects the
  529. * host adapter. This occurs on the interrupt triggered by the target
  530. * asserting SEL.
  531. */
  532. static irqreturn_t do_seagate_reconnect_intr(int irq, void *dev_id,
  533. struct pt_regs *regs)
  534. {
  535. unsigned long flags;
  536. struct Scsi_Host *dev = dev_id;
  537. spin_lock_irqsave (dev->host_lock, flags);
  538. seagate_reconnect_intr (irq, dev_id, regs);
  539. spin_unlock_irqrestore (dev->host_lock, flags);
  540. return IRQ_HANDLED;
  541. }
  542. static void seagate_reconnect_intr (int irq, void *dev_id, struct pt_regs *regs)
  543. {
  544. int temp;
  545. Scsi_Cmnd *SCtmp;
  546. DPRINTK (PHASE_RESELECT, "scsi%d : seagate_reconnect_intr() called\n", hostno);
  547. if (!should_reconnect)
  548. printk(KERN_WARNING "scsi%d: unexpected interrupt.\n", hostno);
  549. else {
  550. should_reconnect = 0;
  551. DPRINTK (PHASE_RESELECT, "scsi%d : internal_command(%d, %08x, %08x, RECONNECT_NOW\n",
  552. hostno, current_target, current_data, current_bufflen);
  553. temp = internal_command (current_target, current_lun, current_cmnd, current_data, current_bufflen, RECONNECT_NOW);
  554. if (msg_byte(temp) != DISCONNECT) {
  555. if (done_fn) {
  556. DPRINTK(PHASE_RESELECT, "scsi%d : done_fn(%d,%08x)", hostno, hostno, temp);
  557. if (!SCint)
  558. panic ("SCint == NULL in seagate");
  559. SCtmp = SCint;
  560. SCint = NULL;
  561. SCtmp->result = temp;
  562. done_fn(SCtmp);
  563. } else
  564. printk(KERN_ERR "done_fn() not defined.\n");
  565. }
  566. }
  567. }
  568. /*
  569. * The seagate_st0x_queue_command() function provides a queued interface
  570. * to the seagate SCSI driver. Basically, it just passes control onto the
  571. * seagate_command() function, after fixing it so that the done_fn()
  572. * is set to the one passed to the function. We have to be very careful,
  573. * because there are some commands on some devices that do not disconnect,
  574. * and if we simply call the done_fn when the command is done then another
  575. * command is started and queue_command is called again... We end up
  576. * overflowing the kernel stack, and this tends not to be such a good idea.
  577. */
  578. static int recursion_depth = 0;
  579. static int seagate_st0x_queue_command (Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
  580. {
  581. int result, reconnect;
  582. Scsi_Cmnd *SCtmp;
  583. DANY ("seagate: que_command");
  584. done_fn = done;
  585. current_target = SCpnt->device->id;
  586. current_lun = SCpnt->device->lun;
  587. current_cmnd = SCpnt->cmnd;
  588. current_data = (unsigned char *) SCpnt->request_buffer;
  589. current_bufflen = SCpnt->request_bufflen;
  590. SCint = SCpnt;
  591. if (recursion_depth)
  592. return 1;
  593. recursion_depth++;
  594. do {
  595. #ifdef LINKED
  596. /*
  597. * Set linked command bit in control field of SCSI command.
  598. */
  599. current_cmnd[SCpnt->cmd_len] |= 0x01;
  600. if (linked_connected) {
  601. DPRINTK (DEBUG_LINKED, "scsi%d : using linked commands, current I_T_L nexus is ", hostno);
  602. if (linked_target == current_target && linked_lun == current_lun)
  603. {
  604. DPRINTK(DEBUG_LINKED, "correct\n");
  605. reconnect = LINKED_RIGHT;
  606. } else {
  607. DPRINTK(DEBUG_LINKED, "incorrect\n");
  608. reconnect = LINKED_WRONG;
  609. }
  610. } else
  611. #endif /* LINKED */
  612. reconnect = CAN_RECONNECT;
  613. result = internal_command(SCint->device->id, SCint->device->lun, SCint->cmnd,
  614. SCint->request_buffer, SCint->request_bufflen, reconnect);
  615. if (msg_byte(result) == DISCONNECT)
  616. break;
  617. SCtmp = SCint;
  618. SCint = NULL;
  619. SCtmp->result = result;
  620. done_fn(SCtmp);
  621. }
  622. while (SCint);
  623. recursion_depth--;
  624. return 0;
  625. }
  626. static int internal_command (unsigned char target, unsigned char lun,
  627. const void *cmnd, void *buff, int bufflen, int reselect)
  628. {
  629. unsigned char *data = NULL;
  630. struct scatterlist *buffer = NULL;
  631. int clock, temp, nobuffs = 0, done = 0, len = 0;
  632. #ifdef DEBUG
  633. int transfered = 0, phase = 0, newphase;
  634. #endif
  635. register unsigned char status_read;
  636. unsigned char tmp_data, tmp_control, status = 0, message = 0;
  637. unsigned transfersize = 0, underflow = 0;
  638. #ifdef SLOW_RATE
  639. int borken = (int) SCint->device->borken; /* Does the current target require
  640. Very Slow I/O ? */
  641. #endif
  642. incommand = 0;
  643. st0x_aborted = 0;
  644. #if (DEBUG & PRINT_COMMAND)
  645. printk("scsi%d : target = %d, command = ", hostno, target);
  646. __scsi_print_command((unsigned char *) cmnd);
  647. #endif
  648. #if (DEBUG & PHASE_RESELECT)
  649. switch (reselect) {
  650. case RECONNECT_NOW:
  651. printk("scsi%d : reconnecting\n", hostno);
  652. break;
  653. #ifdef LINKED
  654. case LINKED_RIGHT:
  655. printk("scsi%d : connected, can reconnect\n", hostno);
  656. break;
  657. case LINKED_WRONG:
  658. printk("scsi%d : connected to wrong target, can reconnect\n",
  659. hostno);
  660. break;
  661. #endif
  662. case CAN_RECONNECT:
  663. printk("scsi%d : allowed to reconnect\n", hostno);
  664. break;
  665. default:
  666. printk("scsi%d : not allowed to reconnect\n", hostno);
  667. }
  668. #endif
  669. if (target == (controller_type == SEAGATE ? 7 : 6))
  670. return DID_BAD_TARGET;
  671. /*
  672. * We work it differently depending on if this is is "the first time,"
  673. * or a reconnect. If this is a reselect phase, then SEL will
  674. * be asserted, and we must skip selection / arbitration phases.
  675. */
  676. switch (reselect) {
  677. case RECONNECT_NOW:
  678. DPRINTK (PHASE_RESELECT, "scsi%d : phase RESELECT \n", hostno);
  679. /*
  680. * At this point, we should find the logical or of our ID
  681. * and the original target's ID on the BUS, with BSY, SEL,
  682. * and I/O signals asserted.
  683. *
  684. * After ARBITRATION phase is completed, only SEL, BSY,
  685. * and the target ID are asserted. A valid initiator ID
  686. * is not on the bus until IO is asserted, so we must wait
  687. * for that.
  688. */
  689. ULOOP (100 * 1000) {
  690. temp = STATUS;
  691. if ((temp & STAT_IO) && !(temp & STAT_BSY))
  692. break;
  693. if (TIMEOUT) {
  694. DPRINTK (PHASE_RESELECT, "scsi%d : RESELECT timed out while waiting for IO .\n", hostno);
  695. return (DID_BAD_INTR << 16);
  696. }
  697. }
  698. /*
  699. * After I/O is asserted by the target, we can read our ID
  700. * and its ID off of the BUS.
  701. */
  702. if (!((temp = DATA) & (controller_type == SEAGATE ? 0x80 : 0x40))) {
  703. DPRINTK (PHASE_RESELECT, "scsi%d : detected reconnect request to different target.\n\tData bus = %d\n", hostno, temp);
  704. return (DID_BAD_INTR << 16);
  705. }
  706. if (!(temp & (1 << current_target))) {
  707. printk(KERN_WARNING "scsi%d : Unexpected reselect interrupt. Data bus = %d\n", hostno, temp);
  708. return (DID_BAD_INTR << 16);
  709. }
  710. buffer = current_buffer;
  711. cmnd = current_cmnd; /* WDE add */
  712. data = current_data; /* WDE add */
  713. len = current_bufflen; /* WDE add */
  714. nobuffs = current_nobuffs;
  715. /*
  716. * We have determined that we have been selected. At this
  717. * point, we must respond to the reselection by asserting
  718. * BSY ourselves
  719. */
  720. #if 1
  721. WRITE_CONTROL (BASE_CMD | CMD_DRVR_ENABLE | CMD_BSY);
  722. #else
  723. WRITE_CONTROL (BASE_CMD | CMD_BSY);
  724. #endif
  725. /*
  726. * The target will drop SEL, and raise BSY, at which time
  727. * we must drop BSY.
  728. */
  729. ULOOP (100 * 1000) {
  730. if (!(STATUS & STAT_SEL))
  731. break;
  732. if (TIMEOUT) {
  733. WRITE_CONTROL (BASE_CMD | CMD_INTR);
  734. DPRINTK (PHASE_RESELECT, "scsi%d : RESELECT timed out while waiting for SEL.\n", hostno);
  735. return (DID_BAD_INTR << 16);
  736. }
  737. }
  738. WRITE_CONTROL (BASE_CMD);
  739. /*
  740. * At this point, we have connected with the target
  741. * and can get on with our lives.
  742. */
  743. break;
  744. case CAN_RECONNECT:
  745. #ifdef LINKED
  746. /*
  747. * This is a bletcherous hack, just as bad as the Unix #!
  748. * interpreter stuff. If it turns out we are using the wrong
  749. * I_T_L nexus, the easiest way to deal with it is to go into
  750. * our INFORMATION TRANSFER PHASE code, send a ABORT
  751. * message on MESSAGE OUT phase, and then loop back to here.
  752. */
  753. connect_loop:
  754. #endif
  755. DPRINTK (PHASE_BUS_FREE, "scsi%d : phase = BUS FREE \n", hostno);
  756. /*
  757. * BUS FREE PHASE
  758. *
  759. * On entry, we make sure that the BUS is in a BUS FREE
  760. * phase, by insuring that both BSY and SEL are low for
  761. * at least one bus settle delay. Several reads help
  762. * eliminate wire glitch.
  763. */
  764. #ifndef ARBITRATE
  765. #error FIXME: this is broken: we may not use jiffies here - we are under cli(). It will hardlock.
  766. clock = jiffies + ST0X_BUS_FREE_DELAY;
  767. while (((STATUS | STATUS | STATUS) & (STAT_BSY | STAT_SEL)) && (!st0x_aborted) && time_before (jiffies, clock))
  768. cpu_relax();
  769. if (time_after (jiffies, clock))
  770. return retcode (DID_BUS_BUSY);
  771. else if (st0x_aborted)
  772. return retcode (st0x_aborted);
  773. #endif
  774. DPRINTK (PHASE_SELECTION, "scsi%d : phase = SELECTION\n", hostno);
  775. clock = jiffies + ST0X_SELECTION_DELAY;
  776. /*
  777. * Arbitration/selection procedure :
  778. * 1. Disable drivers
  779. * 2. Write HOST adapter address bit
  780. * 3. Set start arbitration.
  781. * 4. We get either ARBITRATION COMPLETE or SELECT at this
  782. * point.
  783. * 5. OR our ID and targets on bus.
  784. * 6. Enable SCSI drivers and asserted SEL and ATTN
  785. */
  786. #ifdef ARBITRATE
  787. /* FIXME: verify host lock is always held here */
  788. WRITE_CONTROL(0);
  789. WRITE_DATA((controller_type == SEAGATE) ? 0x80 : 0x40);
  790. WRITE_CONTROL(CMD_START_ARB);
  791. ULOOP (ST0X_SELECTION_DELAY * 10000) {
  792. status_read = STATUS;
  793. if (status_read & STAT_ARB_CMPL)
  794. break;
  795. if (st0x_aborted) /* FIXME: What? We are going to do something even after abort? */
  796. break;
  797. if (TIMEOUT || (status_read & STAT_SEL)) {
  798. printk(KERN_WARNING "scsi%d : arbitration lost or timeout.\n", hostno);
  799. WRITE_CONTROL (BASE_CMD);
  800. return retcode (DID_NO_CONNECT);
  801. }
  802. }
  803. DPRINTK (PHASE_SELECTION, "scsi%d : arbitration complete\n", hostno);
  804. #endif
  805. /*
  806. * When the SCSI device decides that we're gawking at it,
  807. * it will respond by asserting BUSY on the bus.
  808. *
  809. * Note : the Seagate ST-01/02 product manual says that we
  810. * should twiddle the DATA register before the control
  811. * register. However, this does not work reliably so we do
  812. * it the other way around.
  813. *
  814. * Probably could be a problem with arbitration too, we
  815. * really should try this with a SCSI protocol or logic
  816. * analyzer to see what is going on.
  817. */
  818. tmp_data = (unsigned char) ((1 << target) | (controller_type == SEAGATE ? 0x80 : 0x40));
  819. tmp_control = BASE_CMD | CMD_DRVR_ENABLE | CMD_SEL | (reselect ? CMD_ATTN : 0);
  820. /* FIXME: verify host lock is always held here */
  821. #ifdef OLDCNTDATASCEME
  822. #ifdef SWAPCNTDATA
  823. WRITE_CONTROL (tmp_control);
  824. WRITE_DATA (tmp_data);
  825. #else
  826. WRITE_DATA (tmp_data);
  827. WRITE_CONTROL (tmp_control);
  828. #endif
  829. #else
  830. tmp_control ^= CMD_BSY; /* This is guesswork. What used to be in driver */
  831. WRITE_CONTROL (tmp_control); /* could never work: it sent data into control */
  832. WRITE_DATA (tmp_data); /* register and control info into data. Hopefully */
  833. tmp_control ^= CMD_BSY; /* fixed, but order of first two may be wrong. */
  834. WRITE_CONTROL (tmp_control); /* -- pavel@ucw.cz */
  835. #endif
  836. ULOOP (250 * 1000) {
  837. if (st0x_aborted) {
  838. /*
  839. * If we have been aborted, and we have a
  840. * command in progress, IE the target
  841. * still has BSY asserted, then we will
  842. * reset the bus, and notify the midlevel
  843. * driver to expect sense.
  844. */
  845. WRITE_CONTROL (BASE_CMD);
  846. if (STATUS & STAT_BSY) {
  847. printk(KERN_WARNING "scsi%d : BST asserted after we've been aborted.\n", hostno);
  848. seagate_st0x_bus_reset(NULL);
  849. return retcode (DID_RESET);
  850. }
  851. return retcode (st0x_aborted);
  852. }
  853. if (STATUS & STAT_BSY)
  854. break;
  855. if (TIMEOUT) {
  856. DPRINTK (PHASE_SELECTION, "scsi%d : NO CONNECT with target %d, stat = %x \n", hostno, target, STATUS);
  857. return retcode (DID_NO_CONNECT);
  858. }
  859. }
  860. /* Establish current pointers. Take into account scatter / gather */
  861. if ((nobuffs = SCint->use_sg)) {
  862. #if (DEBUG & DEBUG_SG)
  863. {
  864. int i;
  865. printk("scsi%d : scatter gather requested, using %d buffers.\n", hostno, nobuffs);
  866. for (i = 0; i < nobuffs; ++i)
  867. printk("scsi%d : buffer %d address = %p length = %d\n",
  868. hostno, i,
  869. page_address(buffer[i].page) + buffer[i].offset,
  870. buffer[i].length);
  871. }
  872. #endif
  873. buffer = (struct scatterlist *) SCint->buffer;
  874. len = buffer->length;
  875. data = page_address(buffer->page) + buffer->offset;
  876. } else {
  877. DPRINTK (DEBUG_SG, "scsi%d : scatter gather not requested.\n", hostno);
  878. buffer = NULL;
  879. len = SCint->request_bufflen;
  880. data = (unsigned char *) SCint->request_buffer;
  881. }
  882. DPRINTK (PHASE_DATAIN | PHASE_DATAOUT, "scsi%d : len = %d\n",
  883. hostno, len);
  884. break;
  885. #ifdef LINKED
  886. case LINKED_RIGHT:
  887. break;
  888. case LINKED_WRONG:
  889. break;
  890. #endif
  891. } /* end of switch(reselect) */
  892. /*
  893. * There are several conditions under which we wish to send a message :
  894. * 1. When we are allowing disconnect / reconnect, and need to
  895. * establish the I_T_L nexus via an IDENTIFY with the DiscPriv bit
  896. * set.
  897. *
  898. * 2. When we are doing linked commands, are have the wrong I_T_L
  899. * nexus established and want to send an ABORT message.
  900. */
  901. /* GCC does not like an ifdef inside a macro, so do it the hard way. */
  902. #ifdef LINKED
  903. WRITE_CONTROL (BASE_CMD | CMD_DRVR_ENABLE | (((reselect == CAN_RECONNECT)|| (reselect == LINKED_WRONG))? CMD_ATTN : 0));
  904. #else
  905. WRITE_CONTROL (BASE_CMD | CMD_DRVR_ENABLE | (((reselect == CAN_RECONNECT))? CMD_ATTN : 0));
  906. #endif
  907. /*
  908. * INFORMATION TRANSFER PHASE
  909. *
  910. * The nasty looking read / write inline assembler loops we use for
  911. * DATAIN and DATAOUT phases are approximately 4-5 times as fast as
  912. * the 'C' versions - since we're moving 1024 bytes of data, this
  913. * really adds up.
  914. *
  915. * SJT: The nasty-looking assembler is gone, so it's slower.
  916. *
  917. */
  918. DPRINTK (PHASE_ETC, "scsi%d : phase = INFORMATION TRANSFER\n", hostno);
  919. incommand = 1;
  920. transfersize = SCint->transfersize;
  921. underflow = SCint->underflow;
  922. /*
  923. * Now, we poll the device for status information,
  924. * and handle any requests it makes. Note that since we are unsure
  925. * of how much data will be flowing across the system, etc and
  926. * cannot make reasonable timeouts, that we will instead have the
  927. * midlevel driver handle any timeouts that occur in this phase.
  928. */
  929. while (((status_read = STATUS) & STAT_BSY) && !st0x_aborted && !done) {
  930. #ifdef PARITY
  931. if (status_read & STAT_PARITY) {
  932. printk(KERN_ERR "scsi%d : got parity error\n", hostno);
  933. st0x_aborted = DID_PARITY;
  934. }
  935. #endif
  936. if (status_read & STAT_REQ) {
  937. #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
  938. if ((newphase = (status_read & REQ_MASK)) != phase) {
  939. phase = newphase;
  940. switch (phase) {
  941. case REQ_DATAOUT:
  942. printk ("scsi%d : phase = DATA OUT\n", hostno);
  943. break;
  944. case REQ_DATAIN:
  945. printk ("scsi%d : phase = DATA IN\n", hostno);
  946. break;
  947. case REQ_CMDOUT:
  948. printk
  949. ("scsi%d : phase = COMMAND OUT\n", hostno);
  950. break;
  951. case REQ_STATIN:
  952. printk ("scsi%d : phase = STATUS IN\n", hostno);
  953. break;
  954. case REQ_MSGOUT:
  955. printk
  956. ("scsi%d : phase = MESSAGE OUT\n", hostno);
  957. break;
  958. case REQ_MSGIN:
  959. printk ("scsi%d : phase = MESSAGE IN\n", hostno);
  960. break;
  961. default:
  962. printk ("scsi%d : phase = UNKNOWN\n", hostno);
  963. st0x_aborted = DID_ERROR;
  964. }
  965. }
  966. #endif
  967. switch (status_read & REQ_MASK) {
  968. case REQ_DATAOUT:
  969. /*
  970. * If we are in fast mode, then we simply splat
  971. * the data out in word-sized chunks as fast as
  972. * we can.
  973. */
  974. if (!len) {
  975. #if 0
  976. printk("scsi%d: underflow to target %d lun %d \n", hostno, target, lun);
  977. st0x_aborted = DID_ERROR;
  978. fast = 0;
  979. #endif
  980. break;
  981. }
  982. if (fast && transfersize
  983. && !(len % transfersize)
  984. && (len >= transfersize)
  985. #ifdef FAST32
  986. && !(transfersize % 4)
  987. #endif
  988. ) {
  989. DPRINTK (DEBUG_FAST,
  990. "scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
  991. " len = %d, data = %08x\n",
  992. hostno, SCint->underflow,
  993. SCint->transfersize, len,
  994. data);
  995. /* SJT: Start. Fast Write */
  996. #ifdef SEAGATE_USE_ASM
  997. __asm__ ("cld\n\t"
  998. #ifdef FAST32
  999. "shr $2, %%ecx\n\t"
  1000. "1:\t"
  1001. "lodsl\n\t"
  1002. "movl %%eax, (%%edi)\n\t"
  1003. #else
  1004. "1:\t"
  1005. "lodsb\n\t"
  1006. "movb %%al, (%%edi)\n\t"
  1007. #endif
  1008. "loop 1b;"
  1009. /* output */ :
  1010. /* input */ :"D" (st0x_dr),
  1011. "S"
  1012. (data),
  1013. "c" (SCint->transfersize)
  1014. /* clobbered */
  1015. : "eax", "ecx",
  1016. "esi");
  1017. #else /* SEAGATE_USE_ASM */
  1018. memcpy_toio(st0x_dr, data, transfersize);
  1019. #endif /* SEAGATE_USE_ASM */
  1020. /* SJT: End */
  1021. len -= transfersize;
  1022. data += transfersize;
  1023. DPRINTK (DEBUG_FAST, "scsi%d : FAST transfer complete len = %d data = %08x\n", hostno, len, data);
  1024. } else {
  1025. /*
  1026. * We loop as long as we are in a
  1027. * data out phase, there is data to
  1028. * send, and BSY is still active.
  1029. */
  1030. /* SJT: Start. Slow Write. */
  1031. #ifdef SEAGATE_USE_ASM
  1032. int __dummy_1, __dummy_2;
  1033. /*
  1034. * We loop as long as we are in a data out phase, there is data to send,
  1035. * and BSY is still active.
  1036. */
  1037. /* Local variables : len = ecx , data = esi,
  1038. st0x_cr_sr = ebx, st0x_dr = edi
  1039. */
  1040. __asm__ (
  1041. /* Test for any data here at all. */
  1042. "orl %%ecx, %%ecx\n\t"
  1043. "jz 2f\n\t" "cld\n\t"
  1044. /* "movl st0x_cr_sr, %%ebx\n\t" */
  1045. /* "movl st0x_dr, %%edi\n\t" */
  1046. "1:\t"
  1047. "movb (%%ebx), %%al\n\t"
  1048. /* Test for BSY */
  1049. "test $1, %%al\n\t"
  1050. "jz 2f\n\t"
  1051. /* Test for data out phase - STATUS & REQ_MASK should be
  1052. REQ_DATAOUT, which is 0. */
  1053. "test $0xe, %%al\n\t"
  1054. "jnz 2f\n\t"
  1055. /* Test for REQ */
  1056. "test $0x10, %%al\n\t"
  1057. "jz 1b\n\t"
  1058. "lodsb\n\t"
  1059. "movb %%al, (%%edi)\n\t"
  1060. "loop 1b\n\t" "2:\n"
  1061. /* output */ :"=S" (data), "=c" (len),
  1062. "=b"
  1063. (__dummy_1),
  1064. "=D" (__dummy_2)
  1065. /* input */
  1066. : "0" (data), "1" (len),
  1067. "2" (st0x_cr_sr),
  1068. "3" (st0x_dr)
  1069. /* clobbered */
  1070. : "eax");
  1071. #else /* SEAGATE_USE_ASM */
  1072. while (len) {
  1073. unsigned char stat;
  1074. stat = STATUS;
  1075. if (!(stat & STAT_BSY)
  1076. || ((stat & REQ_MASK) !=
  1077. REQ_DATAOUT))
  1078. break;
  1079. if (stat & STAT_REQ) {
  1080. WRITE_DATA (*data++);
  1081. --len;
  1082. }
  1083. }
  1084. #endif /* SEAGATE_USE_ASM */
  1085. /* SJT: End. */
  1086. }
  1087. if (!len && nobuffs) {
  1088. --nobuffs;
  1089. ++buffer;
  1090. len = buffer->length;
  1091. data = page_address(buffer->page) + buffer->offset;
  1092. DPRINTK (DEBUG_SG,
  1093. "scsi%d : next scatter-gather buffer len = %d address = %08x\n",
  1094. hostno, len, data);
  1095. }
  1096. break;
  1097. case REQ_DATAIN:
  1098. #ifdef SLOW_RATE
  1099. if (borken) {
  1100. #if (DEBUG & (PHASE_DATAIN))
  1101. transfered += len;
  1102. #endif
  1103. for (; len && (STATUS & (REQ_MASK | STAT_REQ)) == (REQ_DATAIN | STAT_REQ); --len) {
  1104. *data++ = DATA;
  1105. borken_wait();
  1106. }
  1107. #if (DEBUG & (PHASE_DATAIN))
  1108. transfered -= len;
  1109. #endif
  1110. } else
  1111. #endif
  1112. if (fast && transfersize
  1113. && !(len % transfersize)
  1114. && (len >= transfersize)
  1115. #ifdef FAST32
  1116. && !(transfersize % 4)
  1117. #endif
  1118. ) {
  1119. DPRINTK (DEBUG_FAST,
  1120. "scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
  1121. " len = %d, data = %08x\n",
  1122. hostno, SCint->underflow,
  1123. SCint->transfersize, len,
  1124. data);
  1125. /* SJT: Start. Fast Read */
  1126. #ifdef SEAGATE_USE_ASM
  1127. __asm__ ("cld\n\t"
  1128. #ifdef FAST32
  1129. "shr $2, %%ecx\n\t"
  1130. "1:\t"
  1131. "movl (%%esi), %%eax\n\t"
  1132. "stosl\n\t"
  1133. #else
  1134. "1:\t"
  1135. "movb (%%esi), %%al\n\t"
  1136. "stosb\n\t"
  1137. #endif
  1138. "loop 1b\n\t"
  1139. /* output */ :
  1140. /* input */ :"S" (st0x_dr),
  1141. "D"
  1142. (data),
  1143. "c" (SCint->transfersize)
  1144. /* clobbered */
  1145. : "eax", "ecx",
  1146. "edi");
  1147. #else /* SEAGATE_USE_ASM */
  1148. memcpy_fromio(data, st0x_dr, len);
  1149. #endif /* SEAGATE_USE_ASM */
  1150. /* SJT: End */
  1151. len -= transfersize;
  1152. data += transfersize;
  1153. #if (DEBUG & PHASE_DATAIN)
  1154. printk ("scsi%d: transfered += %d\n", hostno, transfersize);
  1155. transfered += transfersize;
  1156. #endif
  1157. DPRINTK (DEBUG_FAST, "scsi%d : FAST transfer complete len = %d data = %08x\n", hostno, len, data);
  1158. } else {
  1159. #if (DEBUG & PHASE_DATAIN)
  1160. printk ("scsi%d: transfered += %d\n", hostno, len);
  1161. transfered += len; /* Assume we'll transfer it all, then
  1162. subtract what we *didn't* transfer */
  1163. #endif
  1164. /*
  1165. * We loop as long as we are in a data in phase, there is room to read,
  1166. * and BSY is still active
  1167. */
  1168. /* SJT: Start. */
  1169. #ifdef SEAGATE_USE_ASM
  1170. int __dummy_3, __dummy_4;
  1171. /* Dummy clobbering variables for the new gcc-2.95 */
  1172. /*
  1173. * We loop as long as we are in a data in phase, there is room to read,
  1174. * and BSY is still active
  1175. */
  1176. /* Local variables : ecx = len, edi = data
  1177. esi = st0x_cr_sr, ebx = st0x_dr */
  1178. __asm__ (
  1179. /* Test for room to read */
  1180. "orl %%ecx, %%ecx\n\t"
  1181. "jz 2f\n\t" "cld\n\t"
  1182. /* "movl st0x_cr_sr, %%esi\n\t" */
  1183. /* "movl st0x_dr, %%ebx\n\t" */
  1184. "1:\t"
  1185. "movb (%%esi), %%al\n\t"
  1186. /* Test for BSY */
  1187. "test $1, %%al\n\t"
  1188. "jz 2f\n\t"
  1189. /* Test for data in phase - STATUS & REQ_MASK should be REQ_DATAIN,
  1190. = STAT_IO, which is 4. */
  1191. "movb $0xe, %%ah\n\t"
  1192. "andb %%al, %%ah\n\t"
  1193. "cmpb $0x04, %%ah\n\t"
  1194. "jne 2f\n\t"
  1195. /* Test for REQ */
  1196. "test $0x10, %%al\n\t"
  1197. "jz 1b\n\t"
  1198. "movb (%%ebx), %%al\n\t"
  1199. "stosb\n\t"
  1200. "loop 1b\n\t" "2:\n"
  1201. /* output */ :"=D" (data), "=c" (len),
  1202. "=S"
  1203. (__dummy_3),
  1204. "=b" (__dummy_4)
  1205. /* input */
  1206. : "0" (data), "1" (len),
  1207. "2" (st0x_cr_sr),
  1208. "3" (st0x_dr)
  1209. /* clobbered */
  1210. : "eax");
  1211. #else /* SEAGATE_USE_ASM */
  1212. while (len) {
  1213. unsigned char stat;
  1214. stat = STATUS;
  1215. if (!(stat & STAT_BSY)
  1216. || ((stat & REQ_MASK) !=
  1217. REQ_DATAIN))
  1218. break;
  1219. if (stat & STAT_REQ) {
  1220. *data++ = DATA;
  1221. --len;
  1222. }
  1223. }
  1224. #endif /* SEAGATE_USE_ASM */
  1225. /* SJT: End. */
  1226. #if (DEBUG & PHASE_DATAIN)
  1227. printk ("scsi%d: transfered -= %d\n", hostno, len);
  1228. transfered -= len; /* Since we assumed all of Len got *
  1229. transfered, correct our mistake */
  1230. #endif
  1231. }
  1232. if (!len && nobuffs) {
  1233. --nobuffs;
  1234. ++buffer;
  1235. len = buffer->length;
  1236. data = page_address(buffer->page) + buffer->offset;
  1237. DPRINTK (DEBUG_SG, "scsi%d : next scatter-gather buffer len = %d address = %08x\n", hostno, len, data);
  1238. }
  1239. break;
  1240. case REQ_CMDOUT:
  1241. while (((status_read = STATUS) & STAT_BSY) &&
  1242. ((status_read & REQ_MASK) == REQ_CMDOUT))
  1243. if (status_read & STAT_REQ) {
  1244. WRITE_DATA (*(const unsigned char *) cmnd);
  1245. cmnd = 1 + (const unsigned char *)cmnd;
  1246. #ifdef SLOW_RATE
  1247. if (borken)
  1248. borken_wait ();
  1249. #endif
  1250. }
  1251. break;
  1252. case REQ_STATIN:
  1253. status = DATA;
  1254. break;
  1255. case REQ_MSGOUT:
  1256. /*
  1257. * We can only have sent a MSG OUT if we
  1258. * requested to do this by raising ATTN.
  1259. * So, we must drop ATTN.
  1260. */
  1261. WRITE_CONTROL (BASE_CMD | CMD_DRVR_ENABLE);
  1262. /*
  1263. * If we are reconnecting, then we must
  1264. * send an IDENTIFY message in response
  1265. * to MSGOUT.
  1266. */
  1267. switch (reselect) {
  1268. case CAN_RECONNECT:
  1269. WRITE_DATA (IDENTIFY (1, lun));
  1270. DPRINTK (PHASE_RESELECT | PHASE_MSGOUT, "scsi%d : sent IDENTIFY message.\n", hostno);
  1271. break;
  1272. #ifdef LINKED
  1273. case LINKED_WRONG:
  1274. WRITE_DATA (ABORT);
  1275. linked_connected = 0;
  1276. reselect = CAN_RECONNECT;
  1277. goto connect_loop;
  1278. DPRINTK (PHASE_MSGOUT | DEBUG_LINKED, "scsi%d : sent ABORT message to cancel incorrect I_T_L nexus.\n", hostno);
  1279. #endif /* LINKED */
  1280. DPRINTK (DEBUG_LINKED, "correct\n");
  1281. default:
  1282. WRITE_DATA (NOP);
  1283. printk("scsi%d : target %d requested MSGOUT, sent NOP message.\n", hostno, target);
  1284. }
  1285. break;
  1286. case REQ_MSGIN:
  1287. switch (message = DATA) {
  1288. case DISCONNECT:
  1289. DANY("seagate: deciding to disconnect\n");
  1290. should_reconnect = 1;
  1291. current_data = data; /* WDE add */
  1292. current_buffer = buffer;
  1293. current_bufflen = len; /* WDE add */
  1294. current_nobuffs = nobuffs;
  1295. #ifdef LINKED
  1296. linked_connected = 0;
  1297. #endif
  1298. done = 1;
  1299. DPRINTK ((PHASE_RESELECT | PHASE_MSGIN), "scsi%d : disconnected.\n", hostno);
  1300. break;
  1301. #ifdef LINKED
  1302. case LINKED_CMD_COMPLETE:
  1303. case LINKED_FLG_CMD_COMPLETE:
  1304. #endif
  1305. case COMMAND_COMPLETE:
  1306. /*
  1307. * Note : we should check for underflow here.
  1308. */
  1309. DPRINTK(PHASE_MSGIN, "scsi%d : command complete.\n", hostno);
  1310. done = 1;
  1311. break;
  1312. case ABORT:
  1313. DPRINTK(PHASE_MSGIN, "scsi%d : abort message.\n", hostno);
  1314. done = 1;
  1315. break;
  1316. case SAVE_POINTERS:
  1317. current_buffer = buffer;
  1318. current_bufflen = len; /* WDE add */
  1319. current_data = data; /* WDE mod */
  1320. current_nobuffs = nobuffs;
  1321. DPRINTK (PHASE_MSGIN, "scsi%d : pointers saved.\n", hostno);
  1322. break;
  1323. case RESTORE_POINTERS:
  1324. buffer = current_buffer;
  1325. cmnd = current_cmnd;
  1326. data = current_data; /* WDE mod */
  1327. len = current_bufflen;
  1328. nobuffs = current_nobuffs;
  1329. DPRINTK(PHASE_MSGIN, "scsi%d : pointers restored.\n", hostno);
  1330. break;
  1331. default:
  1332. /*
  1333. * IDENTIFY distinguishes itself
  1334. * from the other messages by
  1335. * setting the high bit.
  1336. *
  1337. * Note : we need to handle at
  1338. * least one outstanding command
  1339. * per LUN, and need to hash the
  1340. * SCSI command for that I_T_L
  1341. * nexus based on the known ID
  1342. * (at this point) and LUN.
  1343. */
  1344. if (message & 0x80) {
  1345. DPRINTK (PHASE_MSGIN, "scsi%d : IDENTIFY message received from id %d, lun %d.\n", hostno, target, message & 7);
  1346. } else {
  1347. /*
  1348. * We should go into a
  1349. * MESSAGE OUT phase, and
  1350. * send a MESSAGE_REJECT
  1351. * if we run into a message
  1352. * that we don't like. The
  1353. * seagate driver needs
  1354. * some serious
  1355. * restructuring first
  1356. * though.
  1357. */
  1358. DPRINTK (PHASE_MSGIN, "scsi%d : unknown message %d from target %d.\n", hostno, message, target);
  1359. }
  1360. }
  1361. break;
  1362. default:
  1363. printk(KERN_ERR "scsi%d : unknown phase.\n", hostno);
  1364. st0x_aborted = DID_ERROR;
  1365. } /* end of switch (status_read & REQ_MASK) */
  1366. #ifdef SLOW_RATE
  1367. /*
  1368. * I really don't care to deal with borken devices in
  1369. * each single byte transfer case (ie, message in,
  1370. * message out, status), so I'll do the wait here if
  1371. * necessary.
  1372. */
  1373. if(borken)
  1374. borken_wait();
  1375. #endif
  1376. } /* if(status_read & STAT_REQ) ends */
  1377. } /* while(((status_read = STATUS)...) ends */
  1378. DPRINTK(PHASE_DATAIN | PHASE_DATAOUT | PHASE_EXIT, "scsi%d : Transfered %d bytes\n", hostno, transfered);
  1379. #if (DEBUG & PHASE_EXIT)
  1380. #if 0 /* Doesn't work for scatter/gather */
  1381. printk("Buffer : \n");
  1382. for(i = 0; i < 20; ++i)
  1383. printk("%02x ", ((unsigned char *) data)[i]); /* WDE mod */
  1384. printk("\n");
  1385. #endif
  1386. printk("scsi%d : status = ", hostno);
  1387. scsi_print_status(status);
  1388. printk(" message = %02x\n", message);
  1389. #endif
  1390. /* We shouldn't reach this until *after* BSY has been deasserted */
  1391. #ifdef LINKED
  1392. else
  1393. {
  1394. /*
  1395. * Fix the message byte so that unsuspecting high level drivers
  1396. * don't puke when they see a LINKED COMMAND message in place of
  1397. * the COMMAND COMPLETE they may be expecting. Shouldn't be
  1398. * necessary, but it's better to be on the safe side.
  1399. *
  1400. * A non LINKED* message byte will indicate that the command
  1401. * completed, and we are now disconnected.
  1402. */
  1403. switch (message) {
  1404. case LINKED_CMD_COMPLETE:
  1405. case LINKED_FLG_CMD_COMPLETE:
  1406. message = COMMAND_COMPLETE;
  1407. linked_target = current_target;
  1408. linked_lun = current_lun;
  1409. linked_connected = 1;
  1410. DPRINTK (DEBUG_LINKED, "scsi%d : keeping I_T_L nexus established for linked command.\n", hostno);
  1411. /* We also will need to adjust status to accommodate intermediate
  1412. conditions. */
  1413. if ((status == INTERMEDIATE_GOOD) || (status == INTERMEDIATE_C_GOOD))
  1414. status = GOOD;
  1415. break;
  1416. /*
  1417. * We should also handle what are "normal" termination
  1418. * messages here (ABORT, BUS_DEVICE_RESET?, and
  1419. * COMMAND_COMPLETE individually, and flake if things
  1420. * aren't right.
  1421. */
  1422. default:
  1423. DPRINTK (DEBUG_LINKED, "scsi%d : closing I_T_L nexus.\n", hostno);
  1424. linked_connected = 0;
  1425. }
  1426. }
  1427. #endif /* LINKED */
  1428. if (should_reconnect) {
  1429. DPRINTK (PHASE_RESELECT, "scsi%d : exiting seagate_st0x_queue_command() with reconnect enabled.\n", hostno);
  1430. WRITE_CONTROL (BASE_CMD | CMD_INTR);
  1431. } else
  1432. WRITE_CONTROL (BASE_CMD);
  1433. return retcode (st0x_aborted);
  1434. } /* end of internal_command */
  1435. static int seagate_st0x_abort (Scsi_Cmnd * SCpnt)
  1436. {
  1437. st0x_aborted = DID_ABORT;
  1438. return SUCCESS;
  1439. }
  1440. #undef ULOOP
  1441. #undef TIMEOUT
  1442. /*
  1443. * the seagate_st0x_reset function resets the SCSI bus
  1444. *
  1445. * May be called with SCpnt = NULL
  1446. */
  1447. static int seagate_st0x_bus_reset(Scsi_Cmnd * SCpnt)
  1448. {
  1449. /* No timeouts - this command is going to fail because it was reset. */
  1450. DANY ("scsi%d: Reseting bus... ", hostno);
  1451. /* assert RESET signal on SCSI bus. */
  1452. WRITE_CONTROL (BASE_CMD | CMD_RST);
  1453. mdelay (20);
  1454. WRITE_CONTROL (BASE_CMD);
  1455. st0x_aborted = DID_RESET;
  1456. DANY ("done.\n");
  1457. return SUCCESS;
  1458. }
  1459. static int seagate_st0x_release(struct Scsi_Host *shost)
  1460. {
  1461. if (shost->irq)
  1462. free_irq(shost->irq, shost);
  1463. release_region(shost->io_port, shost->n_io_port);
  1464. return 0;
  1465. }
  1466. static struct scsi_host_template driver_template = {
  1467. .detect = seagate_st0x_detect,
  1468. .release = seagate_st0x_release,
  1469. .info = seagate_st0x_info,
  1470. .queuecommand = seagate_st0x_queue_command,
  1471. .eh_abort_handler = seagate_st0x_abort,
  1472. .eh_bus_reset_handler = seagate_st0x_bus_reset,
  1473. .can_queue = 1,
  1474. .this_id = 7,
  1475. .sg_tablesize = SG_ALL,
  1476. .cmd_per_lun = 1,
  1477. .use_clustering = DISABLE_CLUSTERING,
  1478. };
  1479. #include "scsi_module.c"