wd33c93.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  1. /*
  2. * Copyright (c) 1996 John Shifflett, GeoLog Consulting
  3. * john@geolog.com
  4. * jshiffle@netcom.com
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. /*
  17. * Drew Eckhardt's excellent 'Generic NCR5380' sources from Linux-PC
  18. * provided much of the inspiration and some of the code for this
  19. * driver. Everything I know about Amiga DMA was gleaned from careful
  20. * reading of Hamish Mcdonald's original wd33c93 driver; in fact, I
  21. * borrowed shamelessly from all over that source. Thanks Hamish!
  22. *
  23. * _This_ driver is (I feel) an improvement over the old one in
  24. * several respects:
  25. *
  26. * - Target Disconnection/Reconnection is now supported. Any
  27. * system with more than one device active on the SCSI bus
  28. * will benefit from this. The driver defaults to what I
  29. * call 'adaptive disconnect' - meaning that each command
  30. * is evaluated individually as to whether or not it should
  31. * be run with the option to disconnect/reselect (if the
  32. * device chooses), or as a "SCSI-bus-hog".
  33. *
  34. * - Synchronous data transfers are now supported. Because of
  35. * a few devices that choke after telling the driver that
  36. * they can do sync transfers, we don't automatically use
  37. * this faster protocol - it can be enabled via the command-
  38. * line on a device-by-device basis.
  39. *
  40. * - Runtime operating parameters can now be specified through
  41. * the 'amiboot' or the 'insmod' command line. For amiboot do:
  42. * "amiboot [usual stuff] wd33c93=blah,blah,blah"
  43. * The defaults should be good for most people. See the comment
  44. * for 'setup_strings' below for more details.
  45. *
  46. * - The old driver relied exclusively on what the Western Digital
  47. * docs call "Combination Level 2 Commands", which are a great
  48. * idea in that the CPU is relieved of a lot of interrupt
  49. * overhead. However, by accepting a certain (user-settable)
  50. * amount of additional interrupts, this driver achieves
  51. * better control over the SCSI bus, and data transfers are
  52. * almost as fast while being much easier to define, track,
  53. * and debug.
  54. *
  55. *
  56. * TODO:
  57. * more speed. linked commands.
  58. *
  59. *
  60. * People with bug reports, wish-lists, complaints, comments,
  61. * or improvements are asked to pah-leeez email me (John Shifflett)
  62. * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
  63. * this thing into as good a shape as possible, and I'm positive
  64. * there are lots of lurking bugs and "Stupid Places".
  65. *
  66. * Updates:
  67. *
  68. * Added support for pre -A chips, which don't have advanced features
  69. * and will generate CSR_RESEL rather than CSR_RESEL_AM.
  70. * Richard Hirst <richard@sleepie.demon.co.uk> August 2000
  71. *
  72. * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of
  73. * default_sx_per for asynchronous data transfers. Added adjustment
  74. * of transfer periods in sx_table to the actual input-clock.
  75. * peter fuerst <post@pfrst.de> February 2007
  76. */
  77. #include <linux/module.h>
  78. #include <linux/string.h>
  79. #include <linux/delay.h>
  80. #include <linux/init.h>
  81. #include <linux/interrupt.h>
  82. #include <linux/blkdev.h>
  83. #include <scsi/scsi.h>
  84. #include <scsi/scsi_cmnd.h>
  85. #include <scsi/scsi_device.h>
  86. #include <scsi/scsi_host.h>
  87. #include <asm/irq.h>
  88. #include "wd33c93.h"
  89. #define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
  90. #define WD33C93_VERSION "1.26++"
  91. #define WD33C93_DATE "10/Feb/2007"
  92. MODULE_AUTHOR("John Shifflett");
  93. MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
  94. MODULE_LICENSE("GPL");
  95. /*
  96. * 'setup_strings' is a single string used to pass operating parameters and
  97. * settings from the kernel/module command-line to the driver. 'setup_args[]'
  98. * is an array of strings that define the compile-time default values for
  99. * these settings. If Linux boots with an amiboot or insmod command-line,
  100. * those settings are combined with 'setup_args[]'. Note that amiboot
  101. * command-lines are prefixed with "wd33c93=" while insmod uses a
  102. * "setup_strings=" prefix. The driver recognizes the following keywords
  103. * (lower case required) and arguments:
  104. *
  105. * - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with
  106. * the 7 possible SCSI devices. Set a bit to negotiate for
  107. * asynchronous transfers on that device. To maintain
  108. * backwards compatibility, a command-line such as
  109. * "wd33c93=255" will be automatically translated to
  110. * "wd33c93=nosync:0xff".
  111. * - nodma:x -x = 1 to disable DMA, x = 0 to enable it. Argument is
  112. * optional - if not present, same as "nodma:1".
  113. * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
  114. * period. Default is 500; acceptable values are 250 - 1000.
  115. * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
  116. * x = 1 does 'adaptive' disconnects, which is the default
  117. * and generally the best choice.
  118. * - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes
  119. * various types of debug output to printed - see the DB_xxx
  120. * defines in wd33c93.h
  121. * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
  122. * would be from 8 through 20. Default is 8.
  123. * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
  124. * Single Byte DMA, which is the default. Argument is
  125. * optional - if not present, same as "burst:1".
  126. * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
  127. * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
  128. * it, which is the default. Argument is optional - if not
  129. * present, same as "fast:1".
  130. * - next -No argument. Used to separate blocks of keywords when
  131. * there's more than one host adapter in the system.
  132. *
  133. * Syntax Notes:
  134. * - Numeric arguments can be decimal or the '0x' form of hex notation. There
  135. * _must_ be a colon between a keyword and its numeric argument, with no
  136. * spaces.
  137. * - Keywords are separated by commas, no spaces, in the standard kernel
  138. * command-line manner.
  139. * - A keyword in the 'nth' comma-separated command-line member will overwrite
  140. * the 'nth' element of setup_args[]. A blank command-line member (in
  141. * other words, a comma with no preceding keyword) will _not_ overwrite
  142. * the corresponding setup_args[] element.
  143. * - If a keyword is used more than once, the first one applies to the first
  144. * SCSI host found, the second to the second card, etc, unless the 'next'
  145. * keyword is used to change the order.
  146. *
  147. * Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'):
  148. * - wd33c93=nosync:255
  149. * - wd33c93=nodma
  150. * - wd33c93=nodma:1
  151. * - wd33c93=disconnect:2,nosync:0x08,period:250
  152. * - wd33c93=debug:0x1c
  153. */
  154. /* Normally, no defaults are specified */
  155. static char *setup_args[] = { "", "", "", "", "", "", "", "", "", "" };
  156. static char *setup_strings;
  157. module_param(setup_strings, charp, 0);
  158. static void wd33c93_execute(struct Scsi_Host *instance);
  159. #ifdef CONFIG_WD33C93_PIO
  160. static inline uchar
  161. read_wd33c93(const wd33c93_regs regs, uchar reg_num)
  162. {
  163. uchar data;
  164. outb(reg_num, regs.SASR);
  165. data = inb(regs.SCMD);
  166. return data;
  167. }
  168. static inline unsigned long
  169. read_wd33c93_count(const wd33c93_regs regs)
  170. {
  171. unsigned long value;
  172. outb(WD_TRANSFER_COUNT_MSB, regs.SASR);
  173. value = inb(regs.SCMD) << 16;
  174. value |= inb(regs.SCMD) << 8;
  175. value |= inb(regs.SCMD);
  176. return value;
  177. }
  178. static inline uchar
  179. read_aux_stat(const wd33c93_regs regs)
  180. {
  181. return inb(regs.SASR);
  182. }
  183. static inline void
  184. write_wd33c93(const wd33c93_regs regs, uchar reg_num, uchar value)
  185. {
  186. outb(reg_num, regs.SASR);
  187. outb(value, regs.SCMD);
  188. }
  189. static inline void
  190. write_wd33c93_count(const wd33c93_regs regs, unsigned long value)
  191. {
  192. outb(WD_TRANSFER_COUNT_MSB, regs.SASR);
  193. outb((value >> 16) & 0xff, regs.SCMD);
  194. outb((value >> 8) & 0xff, regs.SCMD);
  195. outb( value & 0xff, regs.SCMD);
  196. }
  197. #define write_wd33c93_cmd(regs, cmd) \
  198. write_wd33c93((regs), WD_COMMAND, (cmd))
  199. static inline void
  200. write_wd33c93_cdb(const wd33c93_regs regs, uint len, uchar cmnd[])
  201. {
  202. int i;
  203. outb(WD_CDB_1, regs.SASR);
  204. for (i=0; i<len; i++)
  205. outb(cmnd[i], regs.SCMD);
  206. }
  207. #else /* CONFIG_WD33C93_PIO */
  208. static inline uchar
  209. read_wd33c93(const wd33c93_regs regs, uchar reg_num)
  210. {
  211. *regs.SASR = reg_num;
  212. mb();
  213. return (*regs.SCMD);
  214. }
  215. static unsigned long
  216. read_wd33c93_count(const wd33c93_regs regs)
  217. {
  218. unsigned long value;
  219. *regs.SASR = WD_TRANSFER_COUNT_MSB;
  220. mb();
  221. value = *regs.SCMD << 16;
  222. value |= *regs.SCMD << 8;
  223. value |= *regs.SCMD;
  224. mb();
  225. return value;
  226. }
  227. static inline uchar
  228. read_aux_stat(const wd33c93_regs regs)
  229. {
  230. return *regs.SASR;
  231. }
  232. static inline void
  233. write_wd33c93(const wd33c93_regs regs, uchar reg_num, uchar value)
  234. {
  235. *regs.SASR = reg_num;
  236. mb();
  237. *regs.SCMD = value;
  238. mb();
  239. }
  240. static void
  241. write_wd33c93_count(const wd33c93_regs regs, unsigned long value)
  242. {
  243. *regs.SASR = WD_TRANSFER_COUNT_MSB;
  244. mb();
  245. *regs.SCMD = value >> 16;
  246. *regs.SCMD = value >> 8;
  247. *regs.SCMD = value;
  248. mb();
  249. }
  250. static inline void
  251. write_wd33c93_cmd(const wd33c93_regs regs, uchar cmd)
  252. {
  253. *regs.SASR = WD_COMMAND;
  254. mb();
  255. *regs.SCMD = cmd;
  256. mb();
  257. }
  258. static inline void
  259. write_wd33c93_cdb(const wd33c93_regs regs, uint len, uchar cmnd[])
  260. {
  261. int i;
  262. *regs.SASR = WD_CDB_1;
  263. for (i = 0; i < len; i++)
  264. *regs.SCMD = cmnd[i];
  265. }
  266. #endif /* CONFIG_WD33C93_PIO */
  267. static inline uchar
  268. read_1_byte(const wd33c93_regs regs)
  269. {
  270. uchar asr;
  271. uchar x = 0;
  272. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  273. write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO | 0x80);
  274. do {
  275. asr = read_aux_stat(regs);
  276. if (asr & ASR_DBR)
  277. x = read_wd33c93(regs, WD_DATA);
  278. } while (!(asr & ASR_INT));
  279. return x;
  280. }
  281. static int
  282. round_period(unsigned int period, const struct sx_period *sx_table)
  283. {
  284. int x;
  285. for (x = 1; sx_table[x].period_ns; x++) {
  286. if ((period <= sx_table[x - 0].period_ns) &&
  287. (period > sx_table[x - 1].period_ns)) {
  288. return x;
  289. }
  290. }
  291. return 7;
  292. }
  293. /*
  294. * Calculate Synchronous Transfer Register value from SDTR code.
  295. */
  296. static uchar
  297. calc_sync_xfer(unsigned int period, unsigned int offset, unsigned int fast,
  298. const struct sx_period *sx_table)
  299. {
  300. /* When doing Fast SCSI synchronous data transfers, the corresponding
  301. * value in 'sx_table' is two times the actually used transfer period.
  302. */
  303. uchar result;
  304. if (offset && fast) {
  305. fast = STR_FSS;
  306. period *= 2;
  307. } else {
  308. fast = 0;
  309. }
  310. period *= 4; /* convert SDTR code to ns */
  311. result = sx_table[round_period(period,sx_table)].reg_value;
  312. result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF;
  313. result |= fast;
  314. return result;
  315. }
  316. /*
  317. * Calculate SDTR code bytes [3],[4] from period and offset.
  318. */
  319. static inline void
  320. calc_sync_msg(unsigned int period, unsigned int offset, unsigned int fast,
  321. uchar msg[2])
  322. {
  323. /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
  324. * actually used transfer period for Fast SCSI synchronous data
  325. * transfers is half that value.
  326. */
  327. period /= 4;
  328. if (offset && fast)
  329. period /= 2;
  330. msg[0] = period;
  331. msg[1] = offset;
  332. }
  333. int
  334. wd33c93_queuecommand(struct scsi_cmnd *cmd,
  335. void (*done)(struct scsi_cmnd *))
  336. {
  337. struct WD33C93_hostdata *hostdata;
  338. struct scsi_cmnd *tmp;
  339. hostdata = (struct WD33C93_hostdata *) cmd->device->host->hostdata;
  340. DB(DB_QUEUE_COMMAND,
  341. printk("Q-%d-%02x-%ld( ", cmd->device->id, cmd->cmnd[0], cmd->serial_number))
  342. /* Set up a few fields in the scsi_cmnd structure for our own use:
  343. * - host_scribble is the pointer to the next cmd in the input queue
  344. * - scsi_done points to the routine we call when a cmd is finished
  345. * - result is what you'd expect
  346. */
  347. cmd->host_scribble = NULL;
  348. cmd->scsi_done = done;
  349. cmd->result = 0;
  350. /* We use the Scsi_Pointer structure that's included with each command
  351. * as a scratchpad (as it's intended to be used!). The handy thing about
  352. * the SCp.xxx fields is that they're always associated with a given
  353. * cmd, and are preserved across disconnect-reselect. This means we
  354. * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
  355. * if we keep all the critical pointers and counters in SCp:
  356. * - SCp.ptr is the pointer into the RAM buffer
  357. * - SCp.this_residual is the size of that buffer
  358. * - SCp.buffer points to the current scatter-gather buffer
  359. * - SCp.buffers_residual tells us how many S.G. buffers there are
  360. * - SCp.have_data_in is not used
  361. * - SCp.sent_command is not used
  362. * - SCp.phase records this command's SRCID_ER bit setting
  363. */
  364. if (scsi_bufflen(cmd)) {
  365. cmd->SCp.buffer = scsi_sglist(cmd);
  366. cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
  367. cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
  368. cmd->SCp.this_residual = cmd->SCp.buffer->length;
  369. } else {
  370. cmd->SCp.buffer = NULL;
  371. cmd->SCp.buffers_residual = 0;
  372. cmd->SCp.ptr = NULL;
  373. cmd->SCp.this_residual = 0;
  374. }
  375. /* WD docs state that at the conclusion of a "LEVEL2" command, the
  376. * status byte can be retrieved from the LUN register. Apparently,
  377. * this is the case only for *uninterrupted* LEVEL2 commands! If
  378. * there are any unexpected phases entered, even if they are 100%
  379. * legal (different devices may choose to do things differently),
  380. * the LEVEL2 command sequence is exited. This often occurs prior
  381. * to receiving the status byte, in which case the driver does a
  382. * status phase interrupt and gets the status byte on its own.
  383. * While such a command can then be "resumed" (ie restarted to
  384. * finish up as a LEVEL2 command), the LUN register will NOT be
  385. * a valid status byte at the command's conclusion, and we must
  386. * use the byte obtained during the earlier interrupt. Here, we
  387. * preset SCp.Status to an illegal value (0xff) so that when
  388. * this command finally completes, we can tell where the actual
  389. * status byte is stored.
  390. */
  391. cmd->SCp.Status = ILLEGAL_STATUS_BYTE;
  392. /*
  393. * Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE
  394. * commands are added to the head of the queue so that the desired
  395. * sense data is not lost before REQUEST_SENSE executes.
  396. */
  397. spin_lock_irq(&hostdata->lock);
  398. if (!(hostdata->input_Q) || (cmd->cmnd[0] == REQUEST_SENSE)) {
  399. cmd->host_scribble = (uchar *) hostdata->input_Q;
  400. hostdata->input_Q = cmd;
  401. } else { /* find the end of the queue */
  402. for (tmp = (struct scsi_cmnd *) hostdata->input_Q;
  403. tmp->host_scribble;
  404. tmp = (struct scsi_cmnd *) tmp->host_scribble) ;
  405. tmp->host_scribble = (uchar *) cmd;
  406. }
  407. /* We know that there's at least one command in 'input_Q' now.
  408. * Go see if any of them are runnable!
  409. */
  410. wd33c93_execute(cmd->device->host);
  411. DB(DB_QUEUE_COMMAND, printk(")Q-%ld ", cmd->serial_number))
  412. spin_unlock_irq(&hostdata->lock);
  413. return 0;
  414. }
  415. /*
  416. * This routine attempts to start a scsi command. If the host_card is
  417. * already connected, we give up immediately. Otherwise, look through
  418. * the input_Q, using the first command we find that's intended
  419. * for a currently non-busy target/lun.
  420. *
  421. * wd33c93_execute() is always called with interrupts disabled or from
  422. * the wd33c93_intr itself, which means that a wd33c93 interrupt
  423. * cannot occur while we are in here.
  424. */
  425. static void
  426. wd33c93_execute(struct Scsi_Host *instance)
  427. {
  428. struct WD33C93_hostdata *hostdata =
  429. (struct WD33C93_hostdata *) instance->hostdata;
  430. const wd33c93_regs regs = hostdata->regs;
  431. struct scsi_cmnd *cmd, *prev;
  432. DB(DB_EXECUTE, printk("EX("))
  433. if (hostdata->selecting || hostdata->connected) {
  434. DB(DB_EXECUTE, printk(")EX-0 "))
  435. return;
  436. }
  437. /*
  438. * Search through the input_Q for a command destined
  439. * for an idle target/lun.
  440. */
  441. cmd = (struct scsi_cmnd *) hostdata->input_Q;
  442. prev = NULL;
  443. while (cmd) {
  444. if (!(hostdata->busy[cmd->device->id] & (1 << cmd->device->lun)))
  445. break;
  446. prev = cmd;
  447. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  448. }
  449. /* quit if queue empty or all possible targets are busy */
  450. if (!cmd) {
  451. DB(DB_EXECUTE, printk(")EX-1 "))
  452. return;
  453. }
  454. /* remove command from queue */
  455. if (prev)
  456. prev->host_scribble = cmd->host_scribble;
  457. else
  458. hostdata->input_Q = (struct scsi_cmnd *) cmd->host_scribble;
  459. #ifdef PROC_STATISTICS
  460. hostdata->cmd_cnt[cmd->device->id]++;
  461. #endif
  462. /*
  463. * Start the selection process
  464. */
  465. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  466. write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id);
  467. else
  468. write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD);
  469. /* Now we need to figure out whether or not this command is a good
  470. * candidate for disconnect/reselect. We guess to the best of our
  471. * ability, based on a set of hierarchical rules. When several
  472. * devices are operating simultaneously, disconnects are usually
  473. * an advantage. In a single device system, or if only 1 device
  474. * is being accessed, transfers usually go faster if disconnects
  475. * are not allowed:
  476. *
  477. * + Commands should NEVER disconnect if hostdata->disconnect =
  478. * DIS_NEVER (this holds for tape drives also), and ALWAYS
  479. * disconnect if hostdata->disconnect = DIS_ALWAYS.
  480. * + Tape drive commands should always be allowed to disconnect.
  481. * + Disconnect should be allowed if disconnected_Q isn't empty.
  482. * + Commands should NOT disconnect if input_Q is empty.
  483. * + Disconnect should be allowed if there are commands in input_Q
  484. * for a different target/lun. In this case, the other commands
  485. * should be made disconnect-able, if not already.
  486. *
  487. * I know, I know - this code would flunk me out of any
  488. * "C Programming 101" class ever offered. But it's easy
  489. * to change around and experiment with for now.
  490. */
  491. cmd->SCp.phase = 0; /* assume no disconnect */
  492. if (hostdata->disconnect == DIS_NEVER)
  493. goto no;
  494. if (hostdata->disconnect == DIS_ALWAYS)
  495. goto yes;
  496. if (cmd->device->type == 1) /* tape drive? */
  497. goto yes;
  498. if (hostdata->disconnected_Q) /* other commands disconnected? */
  499. goto yes;
  500. if (!(hostdata->input_Q)) /* input_Q empty? */
  501. goto no;
  502. for (prev = (struct scsi_cmnd *) hostdata->input_Q; prev;
  503. prev = (struct scsi_cmnd *) prev->host_scribble) {
  504. if ((prev->device->id != cmd->device->id) ||
  505. (prev->device->lun != cmd->device->lun)) {
  506. for (prev = (struct scsi_cmnd *) hostdata->input_Q; prev;
  507. prev = (struct scsi_cmnd *) prev->host_scribble)
  508. prev->SCp.phase = 1;
  509. goto yes;
  510. }
  511. }
  512. goto no;
  513. yes:
  514. cmd->SCp.phase = 1;
  515. #ifdef PROC_STATISTICS
  516. hostdata->disc_allowed_cnt[cmd->device->id]++;
  517. #endif
  518. no:
  519. write_wd33c93(regs, WD_SOURCE_ID, ((cmd->SCp.phase) ? SRCID_ER : 0));
  520. write_wd33c93(regs, WD_TARGET_LUN, cmd->device->lun);
  521. write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
  522. hostdata->sync_xfer[cmd->device->id]);
  523. hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
  524. if ((hostdata->level2 == L2_NONE) ||
  525. (hostdata->sync_stat[cmd->device->id] == SS_UNSET)) {
  526. /*
  527. * Do a 'Select-With-ATN' command. This will end with
  528. * one of the following interrupts:
  529. * CSR_RESEL_AM: failure - can try again later.
  530. * CSR_TIMEOUT: failure - give up.
  531. * CSR_SELECT: success - proceed.
  532. */
  533. hostdata->selecting = cmd;
  534. /* Every target has its own synchronous transfer setting, kept in the
  535. * sync_xfer array, and a corresponding status byte in sync_stat[].
  536. * Each target's sync_stat[] entry is initialized to SX_UNSET, and its
  537. * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
  538. * means that the parameters are undetermined as yet, and that we
  539. * need to send an SDTR message to this device after selection is
  540. * complete: We set SS_FIRST to tell the interrupt routine to do so.
  541. * If we've been asked not to try synchronous transfers on this
  542. * target (and _all_ luns within it), we'll still send the SDTR message
  543. * later, but at that time we'll negotiate for async by specifying a
  544. * sync fifo depth of 0.
  545. */
  546. if (hostdata->sync_stat[cmd->device->id] == SS_UNSET)
  547. hostdata->sync_stat[cmd->device->id] = SS_FIRST;
  548. hostdata->state = S_SELECTING;
  549. write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */
  550. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN);
  551. } else {
  552. /*
  553. * Do a 'Select-With-ATN-Xfer' command. This will end with
  554. * one of the following interrupts:
  555. * CSR_RESEL_AM: failure - can try again later.
  556. * CSR_TIMEOUT: failure - give up.
  557. * anything else: success - proceed.
  558. */
  559. hostdata->connected = cmd;
  560. write_wd33c93(regs, WD_COMMAND_PHASE, 0);
  561. /* copy command_descriptor_block into WD chip
  562. * (take advantage of auto-incrementing)
  563. */
  564. write_wd33c93_cdb(regs, cmd->cmd_len, cmd->cmnd);
  565. /* The wd33c93 only knows about Group 0, 1, and 5 commands when
  566. * it's doing a 'select-and-transfer'. To be safe, we write the
  567. * size of the CDB into the OWN_ID register for every case. This
  568. * way there won't be problems with vendor-unique, audio, etc.
  569. */
  570. write_wd33c93(regs, WD_OWN_ID, cmd->cmd_len);
  571. /* When doing a non-disconnect command with DMA, we can save
  572. * ourselves a DATA phase interrupt later by setting everything
  573. * up ahead of time.
  574. */
  575. if ((cmd->SCp.phase == 0) && (hostdata->no_dma == 0)) {
  576. if (hostdata->dma_setup(cmd,
  577. (cmd->sc_data_direction == DMA_TO_DEVICE) ?
  578. DATA_OUT_DIR : DATA_IN_DIR))
  579. write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */
  580. else {
  581. write_wd33c93_count(regs,
  582. cmd->SCp.this_residual);
  583. write_wd33c93(regs, WD_CONTROL,
  584. CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
  585. hostdata->dma = D_DMA_RUNNING;
  586. }
  587. } else
  588. write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */
  589. hostdata->state = S_RUNNING_LEVEL2;
  590. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  591. }
  592. /*
  593. * Since the SCSI bus can handle only 1 connection at a time,
  594. * we get out of here now. If the selection fails, or when
  595. * the command disconnects, we'll come back to this routine
  596. * to search the input_Q again...
  597. */
  598. DB(DB_EXECUTE,
  599. printk("%s%ld)EX-2 ", (cmd->SCp.phase) ? "d:" : "", cmd->serial_number))
  600. }
  601. static void
  602. transfer_pio(const wd33c93_regs regs, uchar * buf, int cnt,
  603. int data_in_dir, struct WD33C93_hostdata *hostdata)
  604. {
  605. uchar asr;
  606. DB(DB_TRANSFER,
  607. printk("(%p,%d,%s:", buf, cnt, data_in_dir ? "in" : "out"))
  608. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  609. write_wd33c93_count(regs, cnt);
  610. write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO);
  611. if (data_in_dir) {
  612. do {
  613. asr = read_aux_stat(regs);
  614. if (asr & ASR_DBR)
  615. *buf++ = read_wd33c93(regs, WD_DATA);
  616. } while (!(asr & ASR_INT));
  617. } else {
  618. do {
  619. asr = read_aux_stat(regs);
  620. if (asr & ASR_DBR)
  621. write_wd33c93(regs, WD_DATA, *buf++);
  622. } while (!(asr & ASR_INT));
  623. }
  624. /* Note: we are returning with the interrupt UN-cleared.
  625. * Since (presumably) an entire I/O operation has
  626. * completed, the bus phase is probably different, and
  627. * the interrupt routine will discover this when it
  628. * responds to the uncleared int.
  629. */
  630. }
  631. static void
  632. transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
  633. int data_in_dir)
  634. {
  635. struct WD33C93_hostdata *hostdata;
  636. unsigned long length;
  637. hostdata = (struct WD33C93_hostdata *) cmd->device->host->hostdata;
  638. /* Normally, you'd expect 'this_residual' to be non-zero here.
  639. * In a series of scatter-gather transfers, however, this
  640. * routine will usually be called with 'this_residual' equal
  641. * to 0 and 'buffers_residual' non-zero. This means that a
  642. * previous transfer completed, clearing 'this_residual', and
  643. * now we need to setup the next scatter-gather buffer as the
  644. * source or destination for THIS transfer.
  645. */
  646. if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
  647. ++cmd->SCp.buffer;
  648. --cmd->SCp.buffers_residual;
  649. cmd->SCp.this_residual = cmd->SCp.buffer->length;
  650. cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
  651. }
  652. if (!cmd->SCp.this_residual) /* avoid bogus setups */
  653. return;
  654. write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
  655. hostdata->sync_xfer[cmd->device->id]);
  656. /* 'hostdata->no_dma' is TRUE if we don't even want to try DMA.
  657. * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns.
  658. */
  659. if (hostdata->no_dma || hostdata->dma_setup(cmd, data_in_dir)) {
  660. #ifdef PROC_STATISTICS
  661. hostdata->pio_cnt++;
  662. #endif
  663. transfer_pio(regs, (uchar *) cmd->SCp.ptr,
  664. cmd->SCp.this_residual, data_in_dir, hostdata);
  665. length = cmd->SCp.this_residual;
  666. cmd->SCp.this_residual = read_wd33c93_count(regs);
  667. cmd->SCp.ptr += (length - cmd->SCp.this_residual);
  668. }
  669. /* We are able to do DMA (in fact, the Amiga hardware is
  670. * already going!), so start up the wd33c93 in DMA mode.
  671. * We set 'hostdata->dma' = D_DMA_RUNNING so that when the
  672. * transfer completes and causes an interrupt, we're
  673. * reminded to tell the Amiga to shut down its end. We'll
  674. * postpone the updating of 'this_residual' and 'ptr'
  675. * until then.
  676. */
  677. else {
  678. #ifdef PROC_STATISTICS
  679. hostdata->dma_cnt++;
  680. #endif
  681. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
  682. write_wd33c93_count(regs, cmd->SCp.this_residual);
  683. if ((hostdata->level2 >= L2_DATA) ||
  684. (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) {
  685. write_wd33c93(regs, WD_COMMAND_PHASE, 0x45);
  686. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  687. hostdata->state = S_RUNNING_LEVEL2;
  688. } else
  689. write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO);
  690. hostdata->dma = D_DMA_RUNNING;
  691. }
  692. }
  693. void
  694. wd33c93_intr(struct Scsi_Host *instance)
  695. {
  696. struct WD33C93_hostdata *hostdata =
  697. (struct WD33C93_hostdata *) instance->hostdata;
  698. const wd33c93_regs regs = hostdata->regs;
  699. struct scsi_cmnd *patch, *cmd;
  700. uchar asr, sr, phs, id, lun, *ucp, msg;
  701. unsigned long length, flags;
  702. asr = read_aux_stat(regs);
  703. if (!(asr & ASR_INT) || (asr & ASR_BSY))
  704. return;
  705. spin_lock_irqsave(&hostdata->lock, flags);
  706. #ifdef PROC_STATISTICS
  707. hostdata->int_cnt++;
  708. #endif
  709. cmd = (struct scsi_cmnd *) hostdata->connected; /* assume we're connected */
  710. sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear the interrupt */
  711. phs = read_wd33c93(regs, WD_COMMAND_PHASE);
  712. DB(DB_INTR, printk("{%02x:%02x-", asr, sr))
  713. /* After starting a DMA transfer, the next interrupt
  714. * is guaranteed to be in response to completion of
  715. * the transfer. Since the Amiga DMA hardware runs in
  716. * in an open-ended fashion, it needs to be told when
  717. * to stop; do that here if D_DMA_RUNNING is true.
  718. * Also, we have to update 'this_residual' and 'ptr'
  719. * based on the contents of the TRANSFER_COUNT register,
  720. * in case the device decided to do an intermediate
  721. * disconnect (a device may do this if it has to do a
  722. * seek, or just to be nice and let other devices have
  723. * some bus time during long transfers). After doing
  724. * whatever is needed, we go on and service the WD3393
  725. * interrupt normally.
  726. */
  727. if (hostdata->dma == D_DMA_RUNNING) {
  728. DB(DB_TRANSFER,
  729. printk("[%p/%d:", cmd->SCp.ptr, cmd->SCp.this_residual))
  730. hostdata->dma_stop(cmd->device->host, cmd, 1);
  731. hostdata->dma = D_DMA_OFF;
  732. length = cmd->SCp.this_residual;
  733. cmd->SCp.this_residual = read_wd33c93_count(regs);
  734. cmd->SCp.ptr += (length - cmd->SCp.this_residual);
  735. DB(DB_TRANSFER,
  736. printk("%p/%d]", cmd->SCp.ptr, cmd->SCp.this_residual))
  737. }
  738. /* Respond to the specific WD3393 interrupt - there are quite a few! */
  739. switch (sr) {
  740. case CSR_TIMEOUT:
  741. DB(DB_INTR, printk("TIMEOUT"))
  742. if (hostdata->state == S_RUNNING_LEVEL2)
  743. hostdata->connected = NULL;
  744. else {
  745. cmd = (struct scsi_cmnd *) hostdata->selecting; /* get a valid cmd */
  746. hostdata->selecting = NULL;
  747. }
  748. cmd->result = DID_NO_CONNECT << 16;
  749. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  750. hostdata->state = S_UNCONNECTED;
  751. cmd->scsi_done(cmd);
  752. /* From esp.c:
  753. * There is a window of time within the scsi_done() path
  754. * of execution where interrupts are turned back on full
  755. * blast and left that way. During that time we could
  756. * reconnect to a disconnected command, then we'd bomb
  757. * out below. We could also end up executing two commands
  758. * at _once_. ...just so you know why the restore_flags()
  759. * is here...
  760. */
  761. spin_unlock_irqrestore(&hostdata->lock, flags);
  762. /* We are not connected to a target - check to see if there
  763. * are commands waiting to be executed.
  764. */
  765. wd33c93_execute(instance);
  766. break;
  767. /* Note: this interrupt should not occur in a LEVEL2 command */
  768. case CSR_SELECT:
  769. DB(DB_INTR, printk("SELECT"))
  770. hostdata->connected = cmd =
  771. (struct scsi_cmnd *) hostdata->selecting;
  772. hostdata->selecting = NULL;
  773. /* construct an IDENTIFY message with correct disconnect bit */
  774. hostdata->outgoing_msg[0] = (0x80 | 0x00 | cmd->device->lun);
  775. if (cmd->SCp.phase)
  776. hostdata->outgoing_msg[0] |= 0x40;
  777. if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) {
  778. hostdata->sync_stat[cmd->device->id] = SS_WAITING;
  779. /* Tack on a 2nd message to ask about synchronous transfers. If we've
  780. * been asked to do only asynchronous transfers on this device, we
  781. * request a fifo depth of 0, which is equivalent to async - should
  782. * solve the problems some people have had with GVP's Guru ROM.
  783. */
  784. hostdata->outgoing_msg[1] = EXTENDED_MESSAGE;
  785. hostdata->outgoing_msg[2] = 3;
  786. hostdata->outgoing_msg[3] = EXTENDED_SDTR;
  787. if (hostdata->no_sync & (1 << cmd->device->id)) {
  788. calc_sync_msg(hostdata->default_sx_per, 0,
  789. 0, hostdata->outgoing_msg + 4);
  790. } else {
  791. calc_sync_msg(optimum_sx_per(hostdata),
  792. OPTIMUM_SX_OFF,
  793. hostdata->fast,
  794. hostdata->outgoing_msg + 4);
  795. }
  796. hostdata->outgoing_len = 6;
  797. #ifdef SYNC_DEBUG
  798. ucp = hostdata->outgoing_msg + 1;
  799. printk(" sending SDTR %02x03%02x%02x%02x ",
  800. ucp[0], ucp[2], ucp[3], ucp[4]);
  801. #endif
  802. } else
  803. hostdata->outgoing_len = 1;
  804. hostdata->state = S_CONNECTED;
  805. spin_unlock_irqrestore(&hostdata->lock, flags);
  806. break;
  807. case CSR_XFER_DONE | PHS_DATA_IN:
  808. case CSR_UNEXP | PHS_DATA_IN:
  809. case CSR_SRV_REQ | PHS_DATA_IN:
  810. DB(DB_INTR,
  811. printk("IN-%d.%d", cmd->SCp.this_residual,
  812. cmd->SCp.buffers_residual))
  813. transfer_bytes(regs, cmd, DATA_IN_DIR);
  814. if (hostdata->state != S_RUNNING_LEVEL2)
  815. hostdata->state = S_CONNECTED;
  816. spin_unlock_irqrestore(&hostdata->lock, flags);
  817. break;
  818. case CSR_XFER_DONE | PHS_DATA_OUT:
  819. case CSR_UNEXP | PHS_DATA_OUT:
  820. case CSR_SRV_REQ | PHS_DATA_OUT:
  821. DB(DB_INTR,
  822. printk("OUT-%d.%d", cmd->SCp.this_residual,
  823. cmd->SCp.buffers_residual))
  824. transfer_bytes(regs, cmd, DATA_OUT_DIR);
  825. if (hostdata->state != S_RUNNING_LEVEL2)
  826. hostdata->state = S_CONNECTED;
  827. spin_unlock_irqrestore(&hostdata->lock, flags);
  828. break;
  829. /* Note: this interrupt should not occur in a LEVEL2 command */
  830. case CSR_XFER_DONE | PHS_COMMAND:
  831. case CSR_UNEXP | PHS_COMMAND:
  832. case CSR_SRV_REQ | PHS_COMMAND:
  833. DB(DB_INTR, printk("CMND-%02x,%ld", cmd->cmnd[0], cmd->serial_number))
  834. transfer_pio(regs, cmd->cmnd, cmd->cmd_len, DATA_OUT_DIR,
  835. hostdata);
  836. hostdata->state = S_CONNECTED;
  837. spin_unlock_irqrestore(&hostdata->lock, flags);
  838. break;
  839. case CSR_XFER_DONE | PHS_STATUS:
  840. case CSR_UNEXP | PHS_STATUS:
  841. case CSR_SRV_REQ | PHS_STATUS:
  842. DB(DB_INTR, printk("STATUS="))
  843. cmd->SCp.Status = read_1_byte(regs);
  844. DB(DB_INTR, printk("%02x", cmd->SCp.Status))
  845. if (hostdata->level2 >= L2_BASIC) {
  846. sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear interrupt */
  847. udelay(7);
  848. hostdata->state = S_RUNNING_LEVEL2;
  849. write_wd33c93(regs, WD_COMMAND_PHASE, 0x50);
  850. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  851. } else {
  852. hostdata->state = S_CONNECTED;
  853. }
  854. spin_unlock_irqrestore(&hostdata->lock, flags);
  855. break;
  856. case CSR_XFER_DONE | PHS_MESS_IN:
  857. case CSR_UNEXP | PHS_MESS_IN:
  858. case CSR_SRV_REQ | PHS_MESS_IN:
  859. DB(DB_INTR, printk("MSG_IN="))
  860. msg = read_1_byte(regs);
  861. sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear interrupt */
  862. udelay(7);
  863. hostdata->incoming_msg[hostdata->incoming_ptr] = msg;
  864. if (hostdata->incoming_msg[0] == EXTENDED_MESSAGE)
  865. msg = EXTENDED_MESSAGE;
  866. else
  867. hostdata->incoming_ptr = 0;
  868. cmd->SCp.Message = msg;
  869. switch (msg) {
  870. case COMMAND_COMPLETE:
  871. DB(DB_INTR, printk("CCMP-%ld", cmd->serial_number))
  872. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  873. hostdata->state = S_PRE_CMP_DISC;
  874. break;
  875. case SAVE_POINTERS:
  876. DB(DB_INTR, printk("SDP"))
  877. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  878. hostdata->state = S_CONNECTED;
  879. break;
  880. case RESTORE_POINTERS:
  881. DB(DB_INTR, printk("RDP"))
  882. if (hostdata->level2 >= L2_BASIC) {
  883. write_wd33c93(regs, WD_COMMAND_PHASE, 0x45);
  884. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  885. hostdata->state = S_RUNNING_LEVEL2;
  886. } else {
  887. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  888. hostdata->state = S_CONNECTED;
  889. }
  890. break;
  891. case DISCONNECT:
  892. DB(DB_INTR, printk("DIS"))
  893. cmd->device->disconnect = 1;
  894. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  895. hostdata->state = S_PRE_TMP_DISC;
  896. break;
  897. case MESSAGE_REJECT:
  898. DB(DB_INTR, printk("REJ"))
  899. #ifdef SYNC_DEBUG
  900. printk("-REJ-");
  901. #endif
  902. if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) {
  903. hostdata->sync_stat[cmd->device->id] = SS_SET;
  904. /* we want default_sx_per, not DEFAULT_SX_PER */
  905. hostdata->sync_xfer[cmd->device->id] =
  906. calc_sync_xfer(hostdata->default_sx_per
  907. / 4, 0, 0, hostdata->sx_table);
  908. }
  909. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  910. hostdata->state = S_CONNECTED;
  911. break;
  912. case EXTENDED_MESSAGE:
  913. DB(DB_INTR, printk("EXT"))
  914. ucp = hostdata->incoming_msg;
  915. #ifdef SYNC_DEBUG
  916. printk("%02x", ucp[hostdata->incoming_ptr]);
  917. #endif
  918. /* Is this the last byte of the extended message? */
  919. if ((hostdata->incoming_ptr >= 2) &&
  920. (hostdata->incoming_ptr == (ucp[1] + 1))) {
  921. switch (ucp[2]) { /* what's the EXTENDED code? */
  922. case EXTENDED_SDTR:
  923. /* default to default async period */
  924. id = calc_sync_xfer(hostdata->
  925. default_sx_per / 4, 0,
  926. 0, hostdata->sx_table);
  927. if (hostdata->sync_stat[cmd->device->id] !=
  928. SS_WAITING) {
  929. /* A device has sent an unsolicited SDTR message; rather than go
  930. * through the effort of decoding it and then figuring out what
  931. * our reply should be, we're just gonna say that we have a
  932. * synchronous fifo depth of 0. This will result in asynchronous
  933. * transfers - not ideal but so much easier.
  934. * Actually, this is OK because it assures us that if we don't
  935. * specifically ask for sync transfers, we won't do any.
  936. */
  937. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  938. hostdata->outgoing_msg[0] =
  939. EXTENDED_MESSAGE;
  940. hostdata->outgoing_msg[1] = 3;
  941. hostdata->outgoing_msg[2] =
  942. EXTENDED_SDTR;
  943. calc_sync_msg(hostdata->
  944. default_sx_per, 0,
  945. 0, hostdata->outgoing_msg + 3);
  946. hostdata->outgoing_len = 5;
  947. } else {
  948. if (ucp[4]) /* well, sync transfer */
  949. id = calc_sync_xfer(ucp[3], ucp[4],
  950. hostdata->fast,
  951. hostdata->sx_table);
  952. else if (ucp[3]) /* very unlikely... */
  953. id = calc_sync_xfer(ucp[3], ucp[4],
  954. 0, hostdata->sx_table);
  955. }
  956. hostdata->sync_xfer[cmd->device->id] = id;
  957. #ifdef SYNC_DEBUG
  958. printk(" sync_xfer=%02x\n",
  959. hostdata->sync_xfer[cmd->device->id]);
  960. #endif
  961. hostdata->sync_stat[cmd->device->id] =
  962. SS_SET;
  963. write_wd33c93_cmd(regs,
  964. WD_CMD_NEGATE_ACK);
  965. hostdata->state = S_CONNECTED;
  966. break;
  967. case EXTENDED_WDTR:
  968. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  969. printk("sending WDTR ");
  970. hostdata->outgoing_msg[0] =
  971. EXTENDED_MESSAGE;
  972. hostdata->outgoing_msg[1] = 2;
  973. hostdata->outgoing_msg[2] =
  974. EXTENDED_WDTR;
  975. hostdata->outgoing_msg[3] = 0; /* 8 bit transfer width */
  976. hostdata->outgoing_len = 4;
  977. write_wd33c93_cmd(regs,
  978. WD_CMD_NEGATE_ACK);
  979. hostdata->state = S_CONNECTED;
  980. break;
  981. default:
  982. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  983. printk
  984. ("Rejecting Unknown Extended Message(%02x). ",
  985. ucp[2]);
  986. hostdata->outgoing_msg[0] =
  987. MESSAGE_REJECT;
  988. hostdata->outgoing_len = 1;
  989. write_wd33c93_cmd(regs,
  990. WD_CMD_NEGATE_ACK);
  991. hostdata->state = S_CONNECTED;
  992. break;
  993. }
  994. hostdata->incoming_ptr = 0;
  995. }
  996. /* We need to read more MESS_IN bytes for the extended message */
  997. else {
  998. hostdata->incoming_ptr++;
  999. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  1000. hostdata->state = S_CONNECTED;
  1001. }
  1002. break;
  1003. default:
  1004. printk("Rejecting Unknown Message(%02x) ", msg);
  1005. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  1006. hostdata->outgoing_msg[0] = MESSAGE_REJECT;
  1007. hostdata->outgoing_len = 1;
  1008. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  1009. hostdata->state = S_CONNECTED;
  1010. }
  1011. spin_unlock_irqrestore(&hostdata->lock, flags);
  1012. break;
  1013. /* Note: this interrupt will occur only after a LEVEL2 command */
  1014. case CSR_SEL_XFER_DONE:
  1015. /* Make sure that reselection is enabled at this point - it may
  1016. * have been turned off for the command that just completed.
  1017. */
  1018. write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1019. if (phs == 0x60) {
  1020. DB(DB_INTR, printk("SX-DONE-%ld", cmd->serial_number))
  1021. cmd->SCp.Message = COMMAND_COMPLETE;
  1022. lun = read_wd33c93(regs, WD_TARGET_LUN);
  1023. DB(DB_INTR, printk(":%d.%d", cmd->SCp.Status, lun))
  1024. hostdata->connected = NULL;
  1025. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1026. hostdata->state = S_UNCONNECTED;
  1027. if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
  1028. cmd->SCp.Status = lun;
  1029. if (cmd->cmnd[0] == REQUEST_SENSE
  1030. && cmd->SCp.Status != GOOD)
  1031. cmd->result =
  1032. (cmd->
  1033. result & 0x00ffff) | (DID_ERROR << 16);
  1034. else
  1035. cmd->result =
  1036. cmd->SCp.Status | (cmd->SCp.Message << 8);
  1037. cmd->scsi_done(cmd);
  1038. /* We are no longer connected to a target - check to see if
  1039. * there are commands waiting to be executed.
  1040. */
  1041. spin_unlock_irqrestore(&hostdata->lock, flags);
  1042. wd33c93_execute(instance);
  1043. } else {
  1044. printk
  1045. ("%02x:%02x:%02x-%ld: Unknown SEL_XFER_DONE phase!!---",
  1046. asr, sr, phs, cmd->serial_number);
  1047. spin_unlock_irqrestore(&hostdata->lock, flags);
  1048. }
  1049. break;
  1050. /* Note: this interrupt will occur only after a LEVEL2 command */
  1051. case CSR_SDP:
  1052. DB(DB_INTR, printk("SDP"))
  1053. hostdata->state = S_RUNNING_LEVEL2;
  1054. write_wd33c93(regs, WD_COMMAND_PHASE, 0x41);
  1055. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  1056. spin_unlock_irqrestore(&hostdata->lock, flags);
  1057. break;
  1058. case CSR_XFER_DONE | PHS_MESS_OUT:
  1059. case CSR_UNEXP | PHS_MESS_OUT:
  1060. case CSR_SRV_REQ | PHS_MESS_OUT:
  1061. DB(DB_INTR, printk("MSG_OUT="))
  1062. /* To get here, we've probably requested MESSAGE_OUT and have
  1063. * already put the correct bytes in outgoing_msg[] and filled
  1064. * in outgoing_len. We simply send them out to the SCSI bus.
  1065. * Sometimes we get MESSAGE_OUT phase when we're not expecting
  1066. * it - like when our SDTR message is rejected by a target. Some
  1067. * targets send the REJECT before receiving all of the extended
  1068. * message, and then seem to go back to MESSAGE_OUT for a byte
  1069. * or two. Not sure why, or if I'm doing something wrong to
  1070. * cause this to happen. Regardless, it seems that sending
  1071. * NOP messages in these situations results in no harm and
  1072. * makes everyone happy.
  1073. */
  1074. if (hostdata->outgoing_len == 0) {
  1075. hostdata->outgoing_len = 1;
  1076. hostdata->outgoing_msg[0] = NOP;
  1077. }
  1078. transfer_pio(regs, hostdata->outgoing_msg,
  1079. hostdata->outgoing_len, DATA_OUT_DIR, hostdata);
  1080. DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0]))
  1081. hostdata->outgoing_len = 0;
  1082. hostdata->state = S_CONNECTED;
  1083. spin_unlock_irqrestore(&hostdata->lock, flags);
  1084. break;
  1085. case CSR_UNEXP_DISC:
  1086. /* I think I've seen this after a request-sense that was in response
  1087. * to an error condition, but not sure. We certainly need to do
  1088. * something when we get this interrupt - the question is 'what?'.
  1089. * Let's think positively, and assume some command has finished
  1090. * in a legal manner (like a command that provokes a request-sense),
  1091. * so we treat it as a normal command-complete-disconnect.
  1092. */
  1093. /* Make sure that reselection is enabled at this point - it may
  1094. * have been turned off for the command that just completed.
  1095. */
  1096. write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1097. if (cmd == NULL) {
  1098. printk(" - Already disconnected! ");
  1099. hostdata->state = S_UNCONNECTED;
  1100. spin_unlock_irqrestore(&hostdata->lock, flags);
  1101. return;
  1102. }
  1103. DB(DB_INTR, printk("UNEXP_DISC-%ld", cmd->serial_number))
  1104. hostdata->connected = NULL;
  1105. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1106. hostdata->state = S_UNCONNECTED;
  1107. if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
  1108. cmd->result =
  1109. (cmd->result & 0x00ffff) | (DID_ERROR << 16);
  1110. else
  1111. cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1112. cmd->scsi_done(cmd);
  1113. /* We are no longer connected to a target - check to see if
  1114. * there are commands waiting to be executed.
  1115. */
  1116. /* look above for comments on scsi_done() */
  1117. spin_unlock_irqrestore(&hostdata->lock, flags);
  1118. wd33c93_execute(instance);
  1119. break;
  1120. case CSR_DISC:
  1121. /* Make sure that reselection is enabled at this point - it may
  1122. * have been turned off for the command that just completed.
  1123. */
  1124. write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1125. DB(DB_INTR, printk("DISC-%ld", cmd->serial_number))
  1126. if (cmd == NULL) {
  1127. printk(" - Already disconnected! ");
  1128. hostdata->state = S_UNCONNECTED;
  1129. }
  1130. switch (hostdata->state) {
  1131. case S_PRE_CMP_DISC:
  1132. hostdata->connected = NULL;
  1133. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1134. hostdata->state = S_UNCONNECTED;
  1135. DB(DB_INTR, printk(":%d", cmd->SCp.Status))
  1136. if (cmd->cmnd[0] == REQUEST_SENSE
  1137. && cmd->SCp.Status != GOOD)
  1138. cmd->result =
  1139. (cmd->
  1140. result & 0x00ffff) | (DID_ERROR << 16);
  1141. else
  1142. cmd->result =
  1143. cmd->SCp.Status | (cmd->SCp.Message << 8);
  1144. cmd->scsi_done(cmd);
  1145. break;
  1146. case S_PRE_TMP_DISC:
  1147. case S_RUNNING_LEVEL2:
  1148. cmd->host_scribble = (uchar *) hostdata->disconnected_Q;
  1149. hostdata->disconnected_Q = cmd;
  1150. hostdata->connected = NULL;
  1151. hostdata->state = S_UNCONNECTED;
  1152. #ifdef PROC_STATISTICS
  1153. hostdata->disc_done_cnt[cmd->device->id]++;
  1154. #endif
  1155. break;
  1156. default:
  1157. printk("*** Unexpected DISCONNECT interrupt! ***");
  1158. hostdata->state = S_UNCONNECTED;
  1159. }
  1160. /* We are no longer connected to a target - check to see if
  1161. * there are commands waiting to be executed.
  1162. */
  1163. spin_unlock_irqrestore(&hostdata->lock, flags);
  1164. wd33c93_execute(instance);
  1165. break;
  1166. case CSR_RESEL_AM:
  1167. case CSR_RESEL:
  1168. DB(DB_INTR, printk("RESEL%s", sr == CSR_RESEL_AM ? "_AM" : ""))
  1169. /* Old chips (pre -A ???) don't have advanced features and will
  1170. * generate CSR_RESEL. In that case we have to extract the LUN the
  1171. * hard way (see below).
  1172. * First we have to make sure this reselection didn't
  1173. * happen during Arbitration/Selection of some other device.
  1174. * If yes, put losing command back on top of input_Q.
  1175. */
  1176. if (hostdata->level2 <= L2_NONE) {
  1177. if (hostdata->selecting) {
  1178. cmd = (struct scsi_cmnd *) hostdata->selecting;
  1179. hostdata->selecting = NULL;
  1180. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1181. cmd->host_scribble =
  1182. (uchar *) hostdata->input_Q;
  1183. hostdata->input_Q = cmd;
  1184. }
  1185. }
  1186. else {
  1187. if (cmd) {
  1188. if (phs == 0x00) {
  1189. hostdata->busy[cmd->device->id] &=
  1190. ~(1 << cmd->device->lun);
  1191. cmd->host_scribble =
  1192. (uchar *) hostdata->input_Q;
  1193. hostdata->input_Q = cmd;
  1194. } else {
  1195. printk
  1196. ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",
  1197. asr, sr, phs);
  1198. while (1)
  1199. printk("\r");
  1200. }
  1201. }
  1202. }
  1203. /* OK - find out which device reselected us. */
  1204. id = read_wd33c93(regs, WD_SOURCE_ID);
  1205. id &= SRCID_MASK;
  1206. /* and extract the lun from the ID message. (Note that we don't
  1207. * bother to check for a valid message here - I guess this is
  1208. * not the right way to go, but...)
  1209. */
  1210. if (sr == CSR_RESEL_AM) {
  1211. lun = read_wd33c93(regs, WD_DATA);
  1212. if (hostdata->level2 < L2_RESELECT)
  1213. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  1214. lun &= 7;
  1215. } else {
  1216. /* Old chip; wait for msgin phase to pick up the LUN. */
  1217. for (lun = 255; lun; lun--) {
  1218. if ((asr = read_aux_stat(regs)) & ASR_INT)
  1219. break;
  1220. udelay(10);
  1221. }
  1222. if (!(asr & ASR_INT)) {
  1223. printk
  1224. ("wd33c93: Reselected without IDENTIFY\n");
  1225. lun = 0;
  1226. } else {
  1227. /* Verify this is a change to MSG_IN and read the message */
  1228. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1229. udelay(7);
  1230. if (sr == (CSR_ABORT | PHS_MESS_IN) ||
  1231. sr == (CSR_UNEXP | PHS_MESS_IN) ||
  1232. sr == (CSR_SRV_REQ | PHS_MESS_IN)) {
  1233. /* Got MSG_IN, grab target LUN */
  1234. lun = read_1_byte(regs);
  1235. /* Now we expect a 'paused with ACK asserted' int.. */
  1236. asr = read_aux_stat(regs);
  1237. if (!(asr & ASR_INT)) {
  1238. udelay(10);
  1239. asr = read_aux_stat(regs);
  1240. if (!(asr & ASR_INT))
  1241. printk
  1242. ("wd33c93: No int after LUN on RESEL (%02x)\n",
  1243. asr);
  1244. }
  1245. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1246. udelay(7);
  1247. if (sr != CSR_MSGIN)
  1248. printk
  1249. ("wd33c93: Not paused with ACK on RESEL (%02x)\n",
  1250. sr);
  1251. lun &= 7;
  1252. write_wd33c93_cmd(regs,
  1253. WD_CMD_NEGATE_ACK);
  1254. } else {
  1255. printk
  1256. ("wd33c93: Not MSG_IN on reselect (%02x)\n",
  1257. sr);
  1258. lun = 0;
  1259. }
  1260. }
  1261. }
  1262. /* Now we look for the command that's reconnecting. */
  1263. cmd = (struct scsi_cmnd *) hostdata->disconnected_Q;
  1264. patch = NULL;
  1265. while (cmd) {
  1266. if (id == cmd->device->id && lun == cmd->device->lun)
  1267. break;
  1268. patch = cmd;
  1269. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1270. }
  1271. /* Hmm. Couldn't find a valid command.... What to do? */
  1272. if (!cmd) {
  1273. printk
  1274. ("---TROUBLE: target %d.%d not in disconnect queue---",
  1275. id, lun);
  1276. spin_unlock_irqrestore(&hostdata->lock, flags);
  1277. return;
  1278. }
  1279. /* Ok, found the command - now start it up again. */
  1280. if (patch)
  1281. patch->host_scribble = cmd->host_scribble;
  1282. else
  1283. hostdata->disconnected_Q =
  1284. (struct scsi_cmnd *) cmd->host_scribble;
  1285. hostdata->connected = cmd;
  1286. /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
  1287. * because these things are preserved over a disconnect.
  1288. * But we DO need to fix the DPD bit so it's correct for this command.
  1289. */
  1290. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  1291. write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id);
  1292. else
  1293. write_wd33c93(regs, WD_DESTINATION_ID,
  1294. cmd->device->id | DSTID_DPD);
  1295. if (hostdata->level2 >= L2_RESELECT) {
  1296. write_wd33c93_count(regs, 0); /* we want a DATA_PHASE interrupt */
  1297. write_wd33c93(regs, WD_COMMAND_PHASE, 0x45);
  1298. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  1299. hostdata->state = S_RUNNING_LEVEL2;
  1300. } else
  1301. hostdata->state = S_CONNECTED;
  1302. DB(DB_INTR, printk("-%ld", cmd->serial_number))
  1303. spin_unlock_irqrestore(&hostdata->lock, flags);
  1304. break;
  1305. default:
  1306. printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr, sr, phs);
  1307. spin_unlock_irqrestore(&hostdata->lock, flags);
  1308. }
  1309. DB(DB_INTR, printk("} "))
  1310. }
  1311. static void
  1312. reset_wd33c93(struct Scsi_Host *instance)
  1313. {
  1314. struct WD33C93_hostdata *hostdata =
  1315. (struct WD33C93_hostdata *) instance->hostdata;
  1316. const wd33c93_regs regs = hostdata->regs;
  1317. uchar sr;
  1318. #ifdef CONFIG_SGI_IP22
  1319. {
  1320. int busycount = 0;
  1321. extern void sgiwd93_reset(unsigned long);
  1322. /* wait 'til the chip gets some time for us */
  1323. while ((read_aux_stat(regs) & ASR_BSY) && busycount++ < 100)
  1324. udelay (10);
  1325. /*
  1326. * there are scsi devices out there, which manage to lock up
  1327. * the wd33c93 in a busy condition. In this state it won't
  1328. * accept the reset command. The only way to solve this is to
  1329. * give the chip a hardware reset (if possible). The code below
  1330. * does this for the SGI Indy, where this is possible
  1331. */
  1332. /* still busy ? */
  1333. if (read_aux_stat(regs) & ASR_BSY)
  1334. sgiwd93_reset(instance->base); /* yeah, give it the hard one */
  1335. }
  1336. #endif
  1337. write_wd33c93(regs, WD_OWN_ID, OWNID_EAF | OWNID_RAF |
  1338. instance->this_id | hostdata->clock_freq);
  1339. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1340. write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
  1341. calc_sync_xfer(hostdata->default_sx_per / 4,
  1342. DEFAULT_SX_OFF, 0, hostdata->sx_table));
  1343. write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET);
  1344. #ifdef CONFIG_MVME147_SCSI
  1345. udelay(25); /* The old wd33c93 on MVME147 needs this, at least */
  1346. #endif
  1347. while (!(read_aux_stat(regs) & ASR_INT))
  1348. ;
  1349. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1350. hostdata->microcode = read_wd33c93(regs, WD_CDB_1);
  1351. if (sr == 0x00)
  1352. hostdata->chip = C_WD33C93;
  1353. else if (sr == 0x01) {
  1354. write_wd33c93(regs, WD_QUEUE_TAG, 0xa5); /* any random number */
  1355. sr = read_wd33c93(regs, WD_QUEUE_TAG);
  1356. if (sr == 0xa5) {
  1357. hostdata->chip = C_WD33C93B;
  1358. write_wd33c93(regs, WD_QUEUE_TAG, 0);
  1359. } else
  1360. hostdata->chip = C_WD33C93A;
  1361. } else
  1362. hostdata->chip = C_UNKNOWN_CHIP;
  1363. if (hostdata->chip != C_WD33C93B) /* Fast SCSI unavailable */
  1364. hostdata->fast = 0;
  1365. write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
  1366. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1367. }
  1368. int
  1369. wd33c93_host_reset(struct scsi_cmnd * SCpnt)
  1370. {
  1371. struct Scsi_Host *instance;
  1372. struct WD33C93_hostdata *hostdata;
  1373. int i;
  1374. instance = SCpnt->device->host;
  1375. hostdata = (struct WD33C93_hostdata *) instance->hostdata;
  1376. printk("scsi%d: reset. ", instance->host_no);
  1377. disable_irq(instance->irq);
  1378. hostdata->dma_stop(instance, NULL, 0);
  1379. for (i = 0; i < 8; i++) {
  1380. hostdata->busy[i] = 0;
  1381. hostdata->sync_xfer[i] =
  1382. calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
  1383. 0, hostdata->sx_table);
  1384. hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
  1385. }
  1386. hostdata->input_Q = NULL;
  1387. hostdata->selecting = NULL;
  1388. hostdata->connected = NULL;
  1389. hostdata->disconnected_Q = NULL;
  1390. hostdata->state = S_UNCONNECTED;
  1391. hostdata->dma = D_DMA_OFF;
  1392. hostdata->incoming_ptr = 0;
  1393. hostdata->outgoing_len = 0;
  1394. reset_wd33c93(instance);
  1395. SCpnt->result = DID_RESET << 16;
  1396. enable_irq(instance->irq);
  1397. return SUCCESS;
  1398. }
  1399. int
  1400. wd33c93_abort(struct scsi_cmnd * cmd)
  1401. {
  1402. struct Scsi_Host *instance;
  1403. struct WD33C93_hostdata *hostdata;
  1404. wd33c93_regs regs;
  1405. struct scsi_cmnd *tmp, *prev;
  1406. disable_irq(cmd->device->host->irq);
  1407. instance = cmd->device->host;
  1408. hostdata = (struct WD33C93_hostdata *) instance->hostdata;
  1409. regs = hostdata->regs;
  1410. /*
  1411. * Case 1 : If the command hasn't been issued yet, we simply remove it
  1412. * from the input_Q.
  1413. */
  1414. tmp = (struct scsi_cmnd *) hostdata->input_Q;
  1415. prev = NULL;
  1416. while (tmp) {
  1417. if (tmp == cmd) {
  1418. if (prev)
  1419. prev->host_scribble = cmd->host_scribble;
  1420. else
  1421. hostdata->input_Q =
  1422. (struct scsi_cmnd *) cmd->host_scribble;
  1423. cmd->host_scribble = NULL;
  1424. cmd->result = DID_ABORT << 16;
  1425. printk
  1426. ("scsi%d: Abort - removing command %ld from input_Q. ",
  1427. instance->host_no, cmd->serial_number);
  1428. enable_irq(cmd->device->host->irq);
  1429. cmd->scsi_done(cmd);
  1430. return SUCCESS;
  1431. }
  1432. prev = tmp;
  1433. tmp = (struct scsi_cmnd *) tmp->host_scribble;
  1434. }
  1435. /*
  1436. * Case 2 : If the command is connected, we're going to fail the abort
  1437. * and let the high level SCSI driver retry at a later time or
  1438. * issue a reset.
  1439. *
  1440. * Timeouts, and therefore aborted commands, will be highly unlikely
  1441. * and handling them cleanly in this situation would make the common
  1442. * case of noresets less efficient, and would pollute our code. So,
  1443. * we fail.
  1444. */
  1445. if (hostdata->connected == cmd) {
  1446. uchar sr, asr;
  1447. unsigned long timeout;
  1448. printk("scsi%d: Aborting connected command %ld - ",
  1449. instance->host_no, cmd->serial_number);
  1450. printk("stopping DMA - ");
  1451. if (hostdata->dma == D_DMA_RUNNING) {
  1452. hostdata->dma_stop(instance, cmd, 0);
  1453. hostdata->dma = D_DMA_OFF;
  1454. }
  1455. printk("sending wd33c93 ABORT command - ");
  1456. write_wd33c93(regs, WD_CONTROL,
  1457. CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1458. write_wd33c93_cmd(regs, WD_CMD_ABORT);
  1459. /* Now we have to attempt to flush out the FIFO... */
  1460. printk("flushing fifo - ");
  1461. timeout = 1000000;
  1462. do {
  1463. asr = read_aux_stat(regs);
  1464. if (asr & ASR_DBR)
  1465. read_wd33c93(regs, WD_DATA);
  1466. } while (!(asr & ASR_INT) && timeout-- > 0);
  1467. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1468. printk
  1469. ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
  1470. asr, sr, read_wd33c93_count(regs), timeout);
  1471. /*
  1472. * Abort command processed.
  1473. * Still connected.
  1474. * We must disconnect.
  1475. */
  1476. printk("sending wd33c93 DISCONNECT command - ");
  1477. write_wd33c93_cmd(regs, WD_CMD_DISCONNECT);
  1478. timeout = 1000000;
  1479. asr = read_aux_stat(regs);
  1480. while ((asr & ASR_CIP) && timeout-- > 0)
  1481. asr = read_aux_stat(regs);
  1482. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1483. printk("asr=%02x, sr=%02x.", asr, sr);
  1484. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1485. hostdata->connected = NULL;
  1486. hostdata->state = S_UNCONNECTED;
  1487. cmd->result = DID_ABORT << 16;
  1488. /* sti();*/
  1489. wd33c93_execute(instance);
  1490. enable_irq(cmd->device->host->irq);
  1491. cmd->scsi_done(cmd);
  1492. return SUCCESS;
  1493. }
  1494. /*
  1495. * Case 3: If the command is currently disconnected from the bus,
  1496. * we're not going to expend much effort here: Let's just return
  1497. * an ABORT_SNOOZE and hope for the best...
  1498. */
  1499. tmp = (struct scsi_cmnd *) hostdata->disconnected_Q;
  1500. while (tmp) {
  1501. if (tmp == cmd) {
  1502. printk
  1503. ("scsi%d: Abort - command %ld found on disconnected_Q - ",
  1504. instance->host_no, cmd->serial_number);
  1505. printk("Abort SNOOZE. ");
  1506. enable_irq(cmd->device->host->irq);
  1507. return FAILED;
  1508. }
  1509. tmp = (struct scsi_cmnd *) tmp->host_scribble;
  1510. }
  1511. /*
  1512. * Case 4 : If we reached this point, the command was not found in any of
  1513. * the queues.
  1514. *
  1515. * We probably reached this point because of an unlikely race condition
  1516. * between the command completing successfully and the abortion code,
  1517. * so we won't panic, but we will notify the user in case something really
  1518. * broke.
  1519. */
  1520. /* sti();*/
  1521. wd33c93_execute(instance);
  1522. enable_irq(cmd->device->host->irq);
  1523. printk("scsi%d: warning : SCSI command probably completed successfully"
  1524. " before abortion. ", instance->host_no);
  1525. return FAILED;
  1526. }
  1527. #define MAX_WD33C93_HOSTS 4
  1528. #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
  1529. #define SETUP_BUFFER_SIZE 200
  1530. static char setup_buffer[SETUP_BUFFER_SIZE];
  1531. static char setup_used[MAX_SETUP_ARGS];
  1532. static int done_setup = 0;
  1533. static int
  1534. wd33c93_setup(char *str)
  1535. {
  1536. int i;
  1537. char *p1, *p2;
  1538. /* The kernel does some processing of the command-line before calling
  1539. * this function: If it begins with any decimal or hex number arguments,
  1540. * ints[0] = how many numbers found and ints[1] through [n] are the values
  1541. * themselves. str points to where the non-numeric arguments (if any)
  1542. * start: We do our own parsing of those. We construct synthetic 'nosync'
  1543. * keywords out of numeric args (to maintain compatibility with older
  1544. * versions) and then add the rest of the arguments.
  1545. */
  1546. p1 = setup_buffer;
  1547. *p1 = '\0';
  1548. if (str)
  1549. strncpy(p1, str, SETUP_BUFFER_SIZE - strlen(setup_buffer));
  1550. setup_buffer[SETUP_BUFFER_SIZE - 1] = '\0';
  1551. p1 = setup_buffer;
  1552. i = 0;
  1553. while (*p1 && (i < MAX_SETUP_ARGS)) {
  1554. p2 = strchr(p1, ',');
  1555. if (p2) {
  1556. *p2 = '\0';
  1557. if (p1 != p2)
  1558. setup_args[i] = p1;
  1559. p1 = p2 + 1;
  1560. i++;
  1561. } else {
  1562. setup_args[i] = p1;
  1563. break;
  1564. }
  1565. }
  1566. for (i = 0; i < MAX_SETUP_ARGS; i++)
  1567. setup_used[i] = 0;
  1568. done_setup = 1;
  1569. return 1;
  1570. }
  1571. __setup("wd33c93=", wd33c93_setup);
  1572. /* check_setup_args() returns index if key found, 0 if not
  1573. */
  1574. static int
  1575. check_setup_args(char *key, int *flags, int *val, char *buf)
  1576. {
  1577. int x;
  1578. char *cp;
  1579. for (x = 0; x < MAX_SETUP_ARGS; x++) {
  1580. if (setup_used[x])
  1581. continue;
  1582. if (!strncmp(setup_args[x], key, strlen(key)))
  1583. break;
  1584. if (!strncmp(setup_args[x], "next", strlen("next")))
  1585. return 0;
  1586. }
  1587. if (x == MAX_SETUP_ARGS)
  1588. return 0;
  1589. setup_used[x] = 1;
  1590. cp = setup_args[x] + strlen(key);
  1591. *val = -1;
  1592. if (*cp != ':')
  1593. return ++x;
  1594. cp++;
  1595. if ((*cp >= '0') && (*cp <= '9')) {
  1596. *val = simple_strtoul(cp, NULL, 0);
  1597. }
  1598. return ++x;
  1599. }
  1600. /*
  1601. * Calculate internal data-transfer-clock cycle from input-clock
  1602. * frequency (/MHz) and fill 'sx_table'.
  1603. *
  1604. * The original driver used to rely on a fixed sx_table, containing periods
  1605. * for (only) the lower limits of the respective input-clock-frequency ranges
  1606. * (8-10/12-15/16-20 MHz). Although it seems, that no problems ocurred with
  1607. * this setting so far, it might be desirable to adjust the transfer periods
  1608. * closer to the really attached, possibly 25% higher, input-clock, since
  1609. * - the wd33c93 may really use a significant shorter period, than it has
  1610. * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
  1611. * instead).
  1612. * - the wd33c93 may ask the target for a lower transfer rate, than the target
  1613. * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
  1614. * possible 200ns, which indeed shows up in tests as an approx. 10% lower
  1615. * transfer rate).
  1616. */
  1617. static inline unsigned int
  1618. round_4(unsigned int x)
  1619. {
  1620. switch (x & 3) {
  1621. case 1: --x;
  1622. break;
  1623. case 2: ++x;
  1624. case 3: ++x;
  1625. }
  1626. return x;
  1627. }
  1628. static void
  1629. calc_sx_table(unsigned int mhz, struct sx_period sx_table[9])
  1630. {
  1631. unsigned int d, i;
  1632. if (mhz < 11)
  1633. d = 2; /* divisor for 8-10 MHz input-clock */
  1634. else if (mhz < 16)
  1635. d = 3; /* divisor for 12-15 MHz input-clock */
  1636. else
  1637. d = 4; /* divisor for 16-20 MHz input-clock */
  1638. d = (100000 * d) / 2 / mhz; /* 100 x DTCC / nanosec */
  1639. sx_table[0].period_ns = 1;
  1640. sx_table[0].reg_value = 0x20;
  1641. for (i = 1; i < 8; i++) {
  1642. sx_table[i].period_ns = round_4((i+1)*d / 100);
  1643. sx_table[i].reg_value = (i+1)*0x10;
  1644. }
  1645. sx_table[7].reg_value = 0;
  1646. sx_table[8].period_ns = 0;
  1647. sx_table[8].reg_value = 0;
  1648. }
  1649. /*
  1650. * check and, maybe, map an init- or "clock:"- argument.
  1651. */
  1652. static uchar
  1653. set_clk_freq(int freq, int *mhz)
  1654. {
  1655. int x = freq;
  1656. if (WD33C93_FS_8_10 == freq)
  1657. freq = 8;
  1658. else if (WD33C93_FS_12_15 == freq)
  1659. freq = 12;
  1660. else if (WD33C93_FS_16_20 == freq)
  1661. freq = 16;
  1662. else if (freq > 7 && freq < 11)
  1663. x = WD33C93_FS_8_10;
  1664. else if (freq > 11 && freq < 16)
  1665. x = WD33C93_FS_12_15;
  1666. else if (freq > 15 && freq < 21)
  1667. x = WD33C93_FS_16_20;
  1668. else {
  1669. /* Hmm, wouldn't it be safer to assume highest freq here? */
  1670. x = WD33C93_FS_8_10;
  1671. freq = 8;
  1672. }
  1673. *mhz = freq;
  1674. return x;
  1675. }
  1676. /*
  1677. * to be used with the resync: fast: ... options
  1678. */
  1679. static inline void set_resync ( struct WD33C93_hostdata *hd, int mask )
  1680. {
  1681. int i;
  1682. for (i = 0; i < 8; i++)
  1683. if (mask & (1 << i))
  1684. hd->sync_stat[i] = SS_UNSET;
  1685. }
  1686. void
  1687. wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
  1688. dma_setup_t setup, dma_stop_t stop, int clock_freq)
  1689. {
  1690. struct WD33C93_hostdata *hostdata;
  1691. int i;
  1692. int flags;
  1693. int val;
  1694. char buf[32];
  1695. if (!done_setup && setup_strings)
  1696. wd33c93_setup(setup_strings);
  1697. hostdata = (struct WD33C93_hostdata *) instance->hostdata;
  1698. hostdata->regs = regs;
  1699. hostdata->clock_freq = set_clk_freq(clock_freq, &i);
  1700. calc_sx_table(i, hostdata->sx_table);
  1701. hostdata->dma_setup = setup;
  1702. hostdata->dma_stop = stop;
  1703. hostdata->dma_bounce_buffer = NULL;
  1704. hostdata->dma_bounce_len = 0;
  1705. for (i = 0; i < 8; i++) {
  1706. hostdata->busy[i] = 0;
  1707. hostdata->sync_xfer[i] =
  1708. calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
  1709. 0, hostdata->sx_table);
  1710. hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
  1711. #ifdef PROC_STATISTICS
  1712. hostdata->cmd_cnt[i] = 0;
  1713. hostdata->disc_allowed_cnt[i] = 0;
  1714. hostdata->disc_done_cnt[i] = 0;
  1715. #endif
  1716. }
  1717. hostdata->input_Q = NULL;
  1718. hostdata->selecting = NULL;
  1719. hostdata->connected = NULL;
  1720. hostdata->disconnected_Q = NULL;
  1721. hostdata->state = S_UNCONNECTED;
  1722. hostdata->dma = D_DMA_OFF;
  1723. hostdata->level2 = L2_BASIC;
  1724. hostdata->disconnect = DIS_ADAPTIVE;
  1725. hostdata->args = DEBUG_DEFAULTS;
  1726. hostdata->incoming_ptr = 0;
  1727. hostdata->outgoing_len = 0;
  1728. hostdata->default_sx_per = DEFAULT_SX_PER;
  1729. hostdata->no_dma = 0; /* default is DMA enabled */
  1730. #ifdef PROC_INTERFACE
  1731. hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS |
  1732. PR_CONNECTED | PR_INPUTQ | PR_DISCQ | PR_STOP;
  1733. #ifdef PROC_STATISTICS
  1734. hostdata->dma_cnt = 0;
  1735. hostdata->pio_cnt = 0;
  1736. hostdata->int_cnt = 0;
  1737. #endif
  1738. #endif
  1739. if (check_setup_args("clock", &flags, &val, buf)) {
  1740. hostdata->clock_freq = set_clk_freq(val, &val);
  1741. calc_sx_table(val, hostdata->sx_table);
  1742. }
  1743. if (check_setup_args("nosync", &flags, &val, buf))
  1744. hostdata->no_sync = val;
  1745. if (check_setup_args("nodma", &flags, &val, buf))
  1746. hostdata->no_dma = (val == -1) ? 1 : val;
  1747. if (check_setup_args("period", &flags, &val, buf))
  1748. hostdata->default_sx_per =
  1749. hostdata->sx_table[round_period((unsigned int) val,
  1750. hostdata->sx_table)].period_ns;
  1751. if (check_setup_args("disconnect", &flags, &val, buf)) {
  1752. if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
  1753. hostdata->disconnect = val;
  1754. else
  1755. hostdata->disconnect = DIS_ADAPTIVE;
  1756. }
  1757. if (check_setup_args("level2", &flags, &val, buf))
  1758. hostdata->level2 = val;
  1759. if (check_setup_args("debug", &flags, &val, buf))
  1760. hostdata->args = val & DB_MASK;
  1761. if (check_setup_args("burst", &flags, &val, buf))
  1762. hostdata->dma_mode = val ? CTRL_BURST:CTRL_DMA;
  1763. if (WD33C93_FS_16_20 == hostdata->clock_freq /* divisor 4 */
  1764. && check_setup_args("fast", &flags, &val, buf))
  1765. hostdata->fast = !!val;
  1766. if ((i = check_setup_args("next", &flags, &val, buf))) {
  1767. while (i)
  1768. setup_used[--i] = 1;
  1769. }
  1770. #ifdef PROC_INTERFACE
  1771. if (check_setup_args("proc", &flags, &val, buf))
  1772. hostdata->proc = val;
  1773. #endif
  1774. spin_lock_irq(&hostdata->lock);
  1775. reset_wd33c93(instance);
  1776. spin_unlock_irq(&hostdata->lock);
  1777. printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d",
  1778. instance->host_no,
  1779. (hostdata->chip == C_WD33C93) ? "WD33c93" : (hostdata->chip ==
  1780. C_WD33C93A) ?
  1781. "WD33c93A" : (hostdata->chip ==
  1782. C_WD33C93B) ? "WD33c93B" : "unknown",
  1783. hostdata->microcode, hostdata->no_sync, hostdata->no_dma);
  1784. #ifdef DEBUGGING_ON
  1785. printk(" debug_flags=0x%02x\n", hostdata->args);
  1786. #else
  1787. printk(" debugging=OFF\n");
  1788. #endif
  1789. printk(" setup_args=");
  1790. for (i = 0; i < MAX_SETUP_ARGS; i++)
  1791. printk("%s,", setup_args[i]);
  1792. printk("\n");
  1793. printk(" Version %s - %s, Compiled %s at %s\n",
  1794. WD33C93_VERSION, WD33C93_DATE, __DATE__, __TIME__);
  1795. }
  1796. int
  1797. wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off, int len, int in)
  1798. {
  1799. #ifdef PROC_INTERFACE
  1800. char *bp;
  1801. char tbuf[128];
  1802. struct WD33C93_hostdata *hd;
  1803. struct scsi_cmnd *cmd;
  1804. int x;
  1805. static int stop = 0;
  1806. hd = (struct WD33C93_hostdata *) instance->hostdata;
  1807. /* If 'in' is TRUE we need to _read_ the proc file. We accept the following
  1808. * keywords (same format as command-line, but arguments are not optional):
  1809. * debug
  1810. * disconnect
  1811. * period
  1812. * resync
  1813. * proc
  1814. * nodma
  1815. * level2
  1816. * burst
  1817. * fast
  1818. * nosync
  1819. */
  1820. if (in) {
  1821. buf[len] = '\0';
  1822. for (bp = buf; *bp; ) {
  1823. while (',' == *bp || ' ' == *bp)
  1824. ++bp;
  1825. if (!strncmp(bp, "debug:", 6)) {
  1826. hd->args = simple_strtoul(bp+6, &bp, 0) & DB_MASK;
  1827. } else if (!strncmp(bp, "disconnect:", 11)) {
  1828. x = simple_strtoul(bp+11, &bp, 0);
  1829. if (x < DIS_NEVER || x > DIS_ALWAYS)
  1830. x = DIS_ADAPTIVE;
  1831. hd->disconnect = x;
  1832. } else if (!strncmp(bp, "period:", 7)) {
  1833. x = simple_strtoul(bp+7, &bp, 0);
  1834. hd->default_sx_per =
  1835. hd->sx_table[round_period((unsigned int) x,
  1836. hd->sx_table)].period_ns;
  1837. } else if (!strncmp(bp, "resync:", 7)) {
  1838. set_resync(hd, (int)simple_strtoul(bp+7, &bp, 0));
  1839. } else if (!strncmp(bp, "proc:", 5)) {
  1840. hd->proc = simple_strtoul(bp+5, &bp, 0);
  1841. } else if (!strncmp(bp, "nodma:", 6)) {
  1842. hd->no_dma = simple_strtoul(bp+6, &bp, 0);
  1843. } else if (!strncmp(bp, "level2:", 7)) {
  1844. hd->level2 = simple_strtoul(bp+7, &bp, 0);
  1845. } else if (!strncmp(bp, "burst:", 6)) {
  1846. hd->dma_mode =
  1847. simple_strtol(bp+6, &bp, 0) ? CTRL_BURST:CTRL_DMA;
  1848. } else if (!strncmp(bp, "fast:", 5)) {
  1849. x = !!simple_strtol(bp+5, &bp, 0);
  1850. if (x != hd->fast)
  1851. set_resync(hd, 0xff);
  1852. hd->fast = x;
  1853. } else if (!strncmp(bp, "nosync:", 7)) {
  1854. x = simple_strtoul(bp+7, &bp, 0);
  1855. set_resync(hd, x ^ hd->no_sync);
  1856. hd->no_sync = x;
  1857. } else {
  1858. break; /* unknown keyword,syntax-error,... */
  1859. }
  1860. }
  1861. return len;
  1862. }
  1863. spin_lock_irq(&hd->lock);
  1864. bp = buf;
  1865. *bp = '\0';
  1866. if (hd->proc & PR_VERSION) {
  1867. sprintf(tbuf, "\nVersion %s - %s. Compiled %s %s",
  1868. WD33C93_VERSION, WD33C93_DATE, __DATE__, __TIME__);
  1869. strcat(bp, tbuf);
  1870. }
  1871. if (hd->proc & PR_INFO) {
  1872. sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
  1873. " dma_mode=%02x fast=%d",
  1874. hd->clock_freq, hd->no_sync, hd->no_dma, hd->dma_mode, hd->fast);
  1875. strcat(bp, tbuf);
  1876. strcat(bp, "\nsync_xfer[] = ");
  1877. for (x = 0; x < 7; x++) {
  1878. sprintf(tbuf, "\t%02x", hd->sync_xfer[x]);
  1879. strcat(bp, tbuf);
  1880. }
  1881. strcat(bp, "\nsync_stat[] = ");
  1882. for (x = 0; x < 7; x++) {
  1883. sprintf(tbuf, "\t%02x", hd->sync_stat[x]);
  1884. strcat(bp, tbuf);
  1885. }
  1886. }
  1887. #ifdef PROC_STATISTICS
  1888. if (hd->proc & PR_STATISTICS) {
  1889. strcat(bp, "\ncommands issued: ");
  1890. for (x = 0; x < 7; x++) {
  1891. sprintf(tbuf, "\t%ld", hd->cmd_cnt[x]);
  1892. strcat(bp, tbuf);
  1893. }
  1894. strcat(bp, "\ndisconnects allowed:");
  1895. for (x = 0; x < 7; x++) {
  1896. sprintf(tbuf, "\t%ld", hd->disc_allowed_cnt[x]);
  1897. strcat(bp, tbuf);
  1898. }
  1899. strcat(bp, "\ndisconnects done: ");
  1900. for (x = 0; x < 7; x++) {
  1901. sprintf(tbuf, "\t%ld", hd->disc_done_cnt[x]);
  1902. strcat(bp, tbuf);
  1903. }
  1904. sprintf(tbuf,
  1905. "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
  1906. hd->int_cnt, hd->dma_cnt, hd->pio_cnt);
  1907. strcat(bp, tbuf);
  1908. }
  1909. #endif
  1910. if (hd->proc & PR_CONNECTED) {
  1911. strcat(bp, "\nconnected: ");
  1912. if (hd->connected) {
  1913. cmd = (struct scsi_cmnd *) hd->connected;
  1914. sprintf(tbuf, " %ld-%d:%d(%02x)",
  1915. cmd->serial_number, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1916. strcat(bp, tbuf);
  1917. }
  1918. }
  1919. if (hd->proc & PR_INPUTQ) {
  1920. strcat(bp, "\ninput_Q: ");
  1921. cmd = (struct scsi_cmnd *) hd->input_Q;
  1922. while (cmd) {
  1923. sprintf(tbuf, " %ld-%d:%d(%02x)",
  1924. cmd->serial_number, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1925. strcat(bp, tbuf);
  1926. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1927. }
  1928. }
  1929. if (hd->proc & PR_DISCQ) {
  1930. strcat(bp, "\ndisconnected_Q:");
  1931. cmd = (struct scsi_cmnd *) hd->disconnected_Q;
  1932. while (cmd) {
  1933. sprintf(tbuf, " %ld-%d:%d(%02x)",
  1934. cmd->serial_number, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1935. strcat(bp, tbuf);
  1936. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1937. }
  1938. }
  1939. strcat(bp, "\n");
  1940. spin_unlock_irq(&hd->lock);
  1941. *start = buf;
  1942. if (stop) {
  1943. stop = 0;
  1944. return 0;
  1945. }
  1946. if (off > 0x40000) /* ALWAYS stop after 256k bytes have been read */
  1947. stop = 1;
  1948. if (hd->proc & PR_STOP) /* stop every other time */
  1949. stop = 1;
  1950. return strlen(bp);
  1951. #else /* PROC_INTERFACE */
  1952. return 0;
  1953. #endif /* PROC_INTERFACE */
  1954. }
  1955. void
  1956. wd33c93_release(void)
  1957. {
  1958. }
  1959. EXPORT_SYMBOL(wd33c93_host_reset);
  1960. EXPORT_SYMBOL(wd33c93_init);
  1961. EXPORT_SYMBOL(wd33c93_release);
  1962. EXPORT_SYMBOL(wd33c93_abort);
  1963. EXPORT_SYMBOL(wd33c93_queuecommand);
  1964. EXPORT_SYMBOL(wd33c93_intr);
  1965. EXPORT_SYMBOL(wd33c93_proc_info);