wd33c93.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241
  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 "wd33c93.h"
  88. #define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
  89. #define WD33C93_VERSION "1.26++"
  90. #define WD33C93_DATE "10/Feb/2007"
  91. MODULE_AUTHOR("John Shifflett");
  92. MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
  93. MODULE_LICENSE("GPL");
  94. /*
  95. * 'setup_strings' is a single string used to pass operating parameters and
  96. * settings from the kernel/module command-line to the driver. 'setup_args[]'
  97. * is an array of strings that define the compile-time default values for
  98. * these settings. If Linux boots with an amiboot or insmod command-line,
  99. * those settings are combined with 'setup_args[]'. Note that amiboot
  100. * command-lines are prefixed with "wd33c93=" while insmod uses a
  101. * "setup_strings=" prefix. The driver recognizes the following keywords
  102. * (lower case required) and arguments:
  103. *
  104. * - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with
  105. * the 7 possible SCSI devices. Set a bit to negotiate for
  106. * asynchronous transfers on that device. To maintain
  107. * backwards compatibility, a command-line such as
  108. * "wd33c93=255" will be automatically translated to
  109. * "wd33c93=nosync:0xff".
  110. * - nodma:x -x = 1 to disable DMA, x = 0 to enable it. Argument is
  111. * optional - if not present, same as "nodma:1".
  112. * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
  113. * period. Default is 500; acceptable values are 250 - 1000.
  114. * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
  115. * x = 1 does 'adaptive' disconnects, which is the default
  116. * and generally the best choice.
  117. * - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes
  118. * various types of debug output to printed - see the DB_xxx
  119. * defines in wd33c93.h
  120. * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
  121. * would be from 8 through 20. Default is 8.
  122. * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
  123. * Single Byte DMA, which is the default. Argument is
  124. * optional - if not present, same as "burst:1".
  125. * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
  126. * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
  127. * it, which is the default. Argument is optional - if not
  128. * present, same as "fast:1".
  129. * - next -No argument. Used to separate blocks of keywords when
  130. * there's more than one host adapter in the system.
  131. *
  132. * Syntax Notes:
  133. * - Numeric arguments can be decimal or the '0x' form of hex notation. There
  134. * _must_ be a colon between a keyword and its numeric argument, with no
  135. * spaces.
  136. * - Keywords are separated by commas, no spaces, in the standard kernel
  137. * command-line manner.
  138. * - A keyword in the 'nth' comma-separated command-line member will overwrite
  139. * the 'nth' element of setup_args[]. A blank command-line member (in
  140. * other words, a comma with no preceding keyword) will _not_ overwrite
  141. * the corresponding setup_args[] element.
  142. * - If a keyword is used more than once, the first one applies to the first
  143. * SCSI host found, the second to the second card, etc, unless the 'next'
  144. * keyword is used to change the order.
  145. *
  146. * Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'):
  147. * - wd33c93=nosync:255
  148. * - wd33c93=nodma
  149. * - wd33c93=nodma:1
  150. * - wd33c93=disconnect:2,nosync:0x08,period:250
  151. * - wd33c93=debug:0x1c
  152. */
  153. /* Normally, no defaults are specified */
  154. static char *setup_args[] = { "", "", "", "", "", "", "", "", "", "" };
  155. static char *setup_strings;
  156. module_param(setup_strings, charp, 0);
  157. static void wd33c93_execute(struct Scsi_Host *instance);
  158. #ifdef CONFIG_WD33C93_PIO
  159. static inline uchar
  160. read_wd33c93(const wd33c93_regs regs, uchar reg_num)
  161. {
  162. uchar data;
  163. outb(reg_num, regs.SASR);
  164. data = inb(regs.SCMD);
  165. return data;
  166. }
  167. static inline unsigned long
  168. read_wd33c93_count(const wd33c93_regs regs)
  169. {
  170. unsigned long value;
  171. outb(WD_TRANSFER_COUNT_MSB, regs.SASR);
  172. value = inb(regs.SCMD) << 16;
  173. value |= inb(regs.SCMD) << 8;
  174. value |= inb(regs.SCMD);
  175. return value;
  176. }
  177. static inline uchar
  178. read_aux_stat(const wd33c93_regs regs)
  179. {
  180. return inb(regs.SASR);
  181. }
  182. static inline void
  183. write_wd33c93(const wd33c93_regs regs, uchar reg_num, uchar value)
  184. {
  185. outb(reg_num, regs.SASR);
  186. outb(value, regs.SCMD);
  187. }
  188. static inline void
  189. write_wd33c93_count(const wd33c93_regs regs, unsigned long value)
  190. {
  191. outb(WD_TRANSFER_COUNT_MSB, regs.SASR);
  192. outb((value >> 16) & 0xff, regs.SCMD);
  193. outb((value >> 8) & 0xff, regs.SCMD);
  194. outb( value & 0xff, regs.SCMD);
  195. }
  196. #define write_wd33c93_cmd(regs, cmd) \
  197. write_wd33c93((regs), WD_COMMAND, (cmd))
  198. static inline void
  199. write_wd33c93_cdb(const wd33c93_regs regs, uint len, uchar cmnd[])
  200. {
  201. int i;
  202. outb(WD_CDB_1, regs.SASR);
  203. for (i=0; i<len; i++)
  204. outb(cmnd[i], regs.SCMD);
  205. }
  206. #else /* CONFIG_WD33C93_PIO */
  207. static inline uchar
  208. read_wd33c93(const wd33c93_regs regs, uchar reg_num)
  209. {
  210. *regs.SASR = reg_num;
  211. mb();
  212. return (*regs.SCMD);
  213. }
  214. static unsigned long
  215. read_wd33c93_count(const wd33c93_regs regs)
  216. {
  217. unsigned long value;
  218. *regs.SASR = WD_TRANSFER_COUNT_MSB;
  219. mb();
  220. value = *regs.SCMD << 16;
  221. value |= *regs.SCMD << 8;
  222. value |= *regs.SCMD;
  223. mb();
  224. return value;
  225. }
  226. static inline uchar
  227. read_aux_stat(const wd33c93_regs regs)
  228. {
  229. return *regs.SASR;
  230. }
  231. static inline void
  232. write_wd33c93(const wd33c93_regs regs, uchar reg_num, uchar value)
  233. {
  234. *regs.SASR = reg_num;
  235. mb();
  236. *regs.SCMD = value;
  237. mb();
  238. }
  239. static void
  240. write_wd33c93_count(const wd33c93_regs regs, unsigned long value)
  241. {
  242. *regs.SASR = WD_TRANSFER_COUNT_MSB;
  243. mb();
  244. *regs.SCMD = value >> 16;
  245. *regs.SCMD = value >> 8;
  246. *regs.SCMD = value;
  247. mb();
  248. }
  249. static inline void
  250. write_wd33c93_cmd(const wd33c93_regs regs, uchar cmd)
  251. {
  252. *regs.SASR = WD_COMMAND;
  253. mb();
  254. *regs.SCMD = cmd;
  255. mb();
  256. }
  257. static inline void
  258. write_wd33c93_cdb(const wd33c93_regs regs, uint len, uchar cmnd[])
  259. {
  260. int i;
  261. *regs.SASR = WD_CDB_1;
  262. for (i = 0; i < len; i++)
  263. *regs.SCMD = cmnd[i];
  264. }
  265. #endif /* CONFIG_WD33C93_PIO */
  266. static inline uchar
  267. read_1_byte(const wd33c93_regs regs)
  268. {
  269. uchar asr;
  270. uchar x = 0;
  271. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  272. write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO | 0x80);
  273. do {
  274. asr = read_aux_stat(regs);
  275. if (asr & ASR_DBR)
  276. x = read_wd33c93(regs, WD_DATA);
  277. } while (!(asr & ASR_INT));
  278. return x;
  279. }
  280. static int
  281. round_period(unsigned int period, const struct sx_period *sx_table)
  282. {
  283. int x;
  284. for (x = 1; sx_table[x].period_ns; x++) {
  285. if ((period <= sx_table[x - 0].period_ns) &&
  286. (period > sx_table[x - 1].period_ns)) {
  287. return x;
  288. }
  289. }
  290. return 7;
  291. }
  292. /*
  293. * Calculate Synchronous Transfer Register value from SDTR code.
  294. */
  295. static uchar
  296. calc_sync_xfer(unsigned int period, unsigned int offset, unsigned int fast,
  297. const struct sx_period *sx_table)
  298. {
  299. /* When doing Fast SCSI synchronous data transfers, the corresponding
  300. * value in 'sx_table' is two times the actually used transfer period.
  301. */
  302. uchar result;
  303. if (offset && fast) {
  304. fast = STR_FSS;
  305. period *= 2;
  306. } else {
  307. fast = 0;
  308. }
  309. period *= 4; /* convert SDTR code to ns */
  310. result = sx_table[round_period(period,sx_table)].reg_value;
  311. result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF;
  312. result |= fast;
  313. return result;
  314. }
  315. /*
  316. * Calculate SDTR code bytes [3],[4] from period and offset.
  317. */
  318. static inline void
  319. calc_sync_msg(unsigned int period, unsigned int offset, unsigned int fast,
  320. uchar msg[2])
  321. {
  322. /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
  323. * actually used transfer period for Fast SCSI synchronous data
  324. * transfers is half that value.
  325. */
  326. period /= 4;
  327. if (offset && fast)
  328. period /= 2;
  329. msg[0] = period;
  330. msg[1] = offset;
  331. }
  332. int
  333. wd33c93_queuecommand(struct scsi_cmnd *cmd,
  334. void (*done)(struct scsi_cmnd *))
  335. {
  336. struct WD33C93_hostdata *hostdata;
  337. struct scsi_cmnd *tmp;
  338. hostdata = (struct WD33C93_hostdata *) cmd->device->host->hostdata;
  339. DB(DB_QUEUE_COMMAND,
  340. printk("Q-%d-%02x-%ld( ", cmd->device->id, cmd->cmnd[0], cmd->pid))
  341. /* Set up a few fields in the scsi_cmnd structure for our own use:
  342. * - host_scribble is the pointer to the next cmd in the input queue
  343. * - scsi_done points to the routine we call when a cmd is finished
  344. * - result is what you'd expect
  345. */
  346. cmd->host_scribble = NULL;
  347. cmd->scsi_done = done;
  348. cmd->result = 0;
  349. /* We use the Scsi_Pointer structure that's included with each command
  350. * as a scratchpad (as it's intended to be used!). The handy thing about
  351. * the SCp.xxx fields is that they're always associated with a given
  352. * cmd, and are preserved across disconnect-reselect. This means we
  353. * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
  354. * if we keep all the critical pointers and counters in SCp:
  355. * - SCp.ptr is the pointer into the RAM buffer
  356. * - SCp.this_residual is the size of that buffer
  357. * - SCp.buffer points to the current scatter-gather buffer
  358. * - SCp.buffers_residual tells us how many S.G. buffers there are
  359. * - SCp.have_data_in is not used
  360. * - SCp.sent_command is not used
  361. * - SCp.phase records this command's SRCID_ER bit setting
  362. */
  363. if (cmd->use_sg) {
  364. cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
  365. cmd->SCp.buffers_residual = cmd->use_sg - 1;
  366. cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
  367. cmd->SCp.buffer->offset;
  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 = (char *) cmd->request_buffer;
  373. cmd->SCp.this_residual = cmd->request_bufflen;
  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->pid))
  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->pid))
  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 = page_address(cmd->SCp.buffer->page) +
  651. cmd->SCp.buffer->offset;
  652. }
  653. if (!cmd->SCp.this_residual) /* avoid bogus setups */
  654. return;
  655. write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
  656. hostdata->sync_xfer[cmd->device->id]);
  657. /* 'hostdata->no_dma' is TRUE if we don't even want to try DMA.
  658. * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns.
  659. */
  660. if (hostdata->no_dma || hostdata->dma_setup(cmd, data_in_dir)) {
  661. #ifdef PROC_STATISTICS
  662. hostdata->pio_cnt++;
  663. #endif
  664. transfer_pio(regs, (uchar *) cmd->SCp.ptr,
  665. cmd->SCp.this_residual, data_in_dir, hostdata);
  666. length = cmd->SCp.this_residual;
  667. cmd->SCp.this_residual = read_wd33c93_count(regs);
  668. cmd->SCp.ptr += (length - cmd->SCp.this_residual);
  669. }
  670. /* We are able to do DMA (in fact, the Amiga hardware is
  671. * already going!), so start up the wd33c93 in DMA mode.
  672. * We set 'hostdata->dma' = D_DMA_RUNNING so that when the
  673. * transfer completes and causes an interrupt, we're
  674. * reminded to tell the Amiga to shut down its end. We'll
  675. * postpone the updating of 'this_residual' and 'ptr'
  676. * until then.
  677. */
  678. else {
  679. #ifdef PROC_STATISTICS
  680. hostdata->dma_cnt++;
  681. #endif
  682. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
  683. write_wd33c93_count(regs, cmd->SCp.this_residual);
  684. if ((hostdata->level2 >= L2_DATA) ||
  685. (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) {
  686. write_wd33c93(regs, WD_COMMAND_PHASE, 0x45);
  687. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  688. hostdata->state = S_RUNNING_LEVEL2;
  689. } else
  690. write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO);
  691. hostdata->dma = D_DMA_RUNNING;
  692. }
  693. }
  694. void
  695. wd33c93_intr(struct Scsi_Host *instance)
  696. {
  697. struct WD33C93_hostdata *hostdata =
  698. (struct WD33C93_hostdata *) instance->hostdata;
  699. const wd33c93_regs regs = hostdata->regs;
  700. struct scsi_cmnd *patch, *cmd;
  701. uchar asr, sr, phs, id, lun, *ucp, msg;
  702. unsigned long length, flags;
  703. asr = read_aux_stat(regs);
  704. if (!(asr & ASR_INT) || (asr & ASR_BSY))
  705. return;
  706. spin_lock_irqsave(&hostdata->lock, flags);
  707. #ifdef PROC_STATISTICS
  708. hostdata->int_cnt++;
  709. #endif
  710. cmd = (struct scsi_cmnd *) hostdata->connected; /* assume we're connected */
  711. sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear the interrupt */
  712. phs = read_wd33c93(regs, WD_COMMAND_PHASE);
  713. DB(DB_INTR, printk("{%02x:%02x-", asr, sr))
  714. /* After starting a DMA transfer, the next interrupt
  715. * is guaranteed to be in response to completion of
  716. * the transfer. Since the Amiga DMA hardware runs in
  717. * in an open-ended fashion, it needs to be told when
  718. * to stop; do that here if D_DMA_RUNNING is true.
  719. * Also, we have to update 'this_residual' and 'ptr'
  720. * based on the contents of the TRANSFER_COUNT register,
  721. * in case the device decided to do an intermediate
  722. * disconnect (a device may do this if it has to do a
  723. * seek, or just to be nice and let other devices have
  724. * some bus time during long transfers). After doing
  725. * whatever is needed, we go on and service the WD3393
  726. * interrupt normally.
  727. */
  728. if (hostdata->dma == D_DMA_RUNNING) {
  729. DB(DB_TRANSFER,
  730. printk("[%p/%d:", cmd->SCp.ptr, cmd->SCp.this_residual))
  731. hostdata->dma_stop(cmd->device->host, cmd, 1);
  732. hostdata->dma = D_DMA_OFF;
  733. length = cmd->SCp.this_residual;
  734. cmd->SCp.this_residual = read_wd33c93_count(regs);
  735. cmd->SCp.ptr += (length - cmd->SCp.this_residual);
  736. DB(DB_TRANSFER,
  737. printk("%p/%d]", cmd->SCp.ptr, cmd->SCp.this_residual))
  738. }
  739. /* Respond to the specific WD3393 interrupt - there are quite a few! */
  740. switch (sr) {
  741. case CSR_TIMEOUT:
  742. DB(DB_INTR, printk("TIMEOUT"))
  743. if (hostdata->state == S_RUNNING_LEVEL2)
  744. hostdata->connected = NULL;
  745. else {
  746. cmd = (struct scsi_cmnd *) hostdata->selecting; /* get a valid cmd */
  747. hostdata->selecting = NULL;
  748. }
  749. cmd->result = DID_NO_CONNECT << 16;
  750. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  751. hostdata->state = S_UNCONNECTED;
  752. cmd->scsi_done(cmd);
  753. /* From esp.c:
  754. * There is a window of time within the scsi_done() path
  755. * of execution where interrupts are turned back on full
  756. * blast and left that way. During that time we could
  757. * reconnect to a disconnected command, then we'd bomb
  758. * out below. We could also end up executing two commands
  759. * at _once_. ...just so you know why the restore_flags()
  760. * is here...
  761. */
  762. spin_unlock_irqrestore(&hostdata->lock, flags);
  763. /* We are not connected to a target - check to see if there
  764. * are commands waiting to be executed.
  765. */
  766. wd33c93_execute(instance);
  767. break;
  768. /* Note: this interrupt should not occur in a LEVEL2 command */
  769. case CSR_SELECT:
  770. DB(DB_INTR, printk("SELECT"))
  771. hostdata->connected = cmd =
  772. (struct scsi_cmnd *) hostdata->selecting;
  773. hostdata->selecting = NULL;
  774. /* construct an IDENTIFY message with correct disconnect bit */
  775. hostdata->outgoing_msg[0] = (0x80 | 0x00 | cmd->device->lun);
  776. if (cmd->SCp.phase)
  777. hostdata->outgoing_msg[0] |= 0x40;
  778. if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) {
  779. hostdata->sync_stat[cmd->device->id] = SS_WAITING;
  780. /* Tack on a 2nd message to ask about synchronous transfers. If we've
  781. * been asked to do only asynchronous transfers on this device, we
  782. * request a fifo depth of 0, which is equivalent to async - should
  783. * solve the problems some people have had with GVP's Guru ROM.
  784. */
  785. hostdata->outgoing_msg[1] = EXTENDED_MESSAGE;
  786. hostdata->outgoing_msg[2] = 3;
  787. hostdata->outgoing_msg[3] = EXTENDED_SDTR;
  788. if (hostdata->no_sync & (1 << cmd->device->id)) {
  789. calc_sync_msg(hostdata->default_sx_per, 0,
  790. 0, hostdata->outgoing_msg + 4);
  791. } else {
  792. calc_sync_msg(optimum_sx_per(hostdata),
  793. OPTIMUM_SX_OFF,
  794. hostdata->fast,
  795. hostdata->outgoing_msg + 4);
  796. }
  797. hostdata->outgoing_len = 6;
  798. #ifdef SYNC_DEBUG
  799. ucp = hostdata->outgoing_msg + 1;
  800. printk(" sending SDTR %02x03%02x%02x%02x ",
  801. ucp[0], ucp[2], ucp[3], ucp[4]);
  802. #endif
  803. } else
  804. hostdata->outgoing_len = 1;
  805. hostdata->state = S_CONNECTED;
  806. spin_unlock_irqrestore(&hostdata->lock, flags);
  807. break;
  808. case CSR_XFER_DONE | PHS_DATA_IN:
  809. case CSR_UNEXP | PHS_DATA_IN:
  810. case CSR_SRV_REQ | PHS_DATA_IN:
  811. DB(DB_INTR,
  812. printk("IN-%d.%d", cmd->SCp.this_residual,
  813. cmd->SCp.buffers_residual))
  814. transfer_bytes(regs, cmd, DATA_IN_DIR);
  815. if (hostdata->state != S_RUNNING_LEVEL2)
  816. hostdata->state = S_CONNECTED;
  817. spin_unlock_irqrestore(&hostdata->lock, flags);
  818. break;
  819. case CSR_XFER_DONE | PHS_DATA_OUT:
  820. case CSR_UNEXP | PHS_DATA_OUT:
  821. case CSR_SRV_REQ | PHS_DATA_OUT:
  822. DB(DB_INTR,
  823. printk("OUT-%d.%d", cmd->SCp.this_residual,
  824. cmd->SCp.buffers_residual))
  825. transfer_bytes(regs, cmd, DATA_OUT_DIR);
  826. if (hostdata->state != S_RUNNING_LEVEL2)
  827. hostdata->state = S_CONNECTED;
  828. spin_unlock_irqrestore(&hostdata->lock, flags);
  829. break;
  830. /* Note: this interrupt should not occur in a LEVEL2 command */
  831. case CSR_XFER_DONE | PHS_COMMAND:
  832. case CSR_UNEXP | PHS_COMMAND:
  833. case CSR_SRV_REQ | PHS_COMMAND:
  834. DB(DB_INTR, printk("CMND-%02x,%ld", cmd->cmnd[0], cmd->pid))
  835. transfer_pio(regs, cmd->cmnd, cmd->cmd_len, DATA_OUT_DIR,
  836. hostdata);
  837. hostdata->state = S_CONNECTED;
  838. spin_unlock_irqrestore(&hostdata->lock, flags);
  839. break;
  840. case CSR_XFER_DONE | PHS_STATUS:
  841. case CSR_UNEXP | PHS_STATUS:
  842. case CSR_SRV_REQ | PHS_STATUS:
  843. DB(DB_INTR, printk("STATUS="))
  844. cmd->SCp.Status = read_1_byte(regs);
  845. DB(DB_INTR, printk("%02x", cmd->SCp.Status))
  846. if (hostdata->level2 >= L2_BASIC) {
  847. sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear interrupt */
  848. udelay(7);
  849. hostdata->state = S_RUNNING_LEVEL2;
  850. write_wd33c93(regs, WD_COMMAND_PHASE, 0x50);
  851. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  852. } else {
  853. hostdata->state = S_CONNECTED;
  854. }
  855. spin_unlock_irqrestore(&hostdata->lock, flags);
  856. break;
  857. case CSR_XFER_DONE | PHS_MESS_IN:
  858. case CSR_UNEXP | PHS_MESS_IN:
  859. case CSR_SRV_REQ | PHS_MESS_IN:
  860. DB(DB_INTR, printk("MSG_IN="))
  861. msg = read_1_byte(regs);
  862. sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear interrupt */
  863. udelay(7);
  864. hostdata->incoming_msg[hostdata->incoming_ptr] = msg;
  865. if (hostdata->incoming_msg[0] == EXTENDED_MESSAGE)
  866. msg = EXTENDED_MESSAGE;
  867. else
  868. hostdata->incoming_ptr = 0;
  869. cmd->SCp.Message = msg;
  870. switch (msg) {
  871. case COMMAND_COMPLETE:
  872. DB(DB_INTR, printk("CCMP-%ld", cmd->pid))
  873. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  874. hostdata->state = S_PRE_CMP_DISC;
  875. break;
  876. case SAVE_POINTERS:
  877. DB(DB_INTR, printk("SDP"))
  878. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  879. hostdata->state = S_CONNECTED;
  880. break;
  881. case RESTORE_POINTERS:
  882. DB(DB_INTR, printk("RDP"))
  883. if (hostdata->level2 >= L2_BASIC) {
  884. write_wd33c93(regs, WD_COMMAND_PHASE, 0x45);
  885. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  886. hostdata->state = S_RUNNING_LEVEL2;
  887. } else {
  888. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  889. hostdata->state = S_CONNECTED;
  890. }
  891. break;
  892. case DISCONNECT:
  893. DB(DB_INTR, printk("DIS"))
  894. cmd->device->disconnect = 1;
  895. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  896. hostdata->state = S_PRE_TMP_DISC;
  897. break;
  898. case MESSAGE_REJECT:
  899. DB(DB_INTR, printk("REJ"))
  900. #ifdef SYNC_DEBUG
  901. printk("-REJ-");
  902. #endif
  903. if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) {
  904. hostdata->sync_stat[cmd->device->id] = SS_SET;
  905. /* we want default_sx_per, not DEFAULT_SX_PER */
  906. hostdata->sync_xfer[cmd->device->id] =
  907. calc_sync_xfer(hostdata->default_sx_per
  908. / 4, 0, 0, hostdata->sx_table);
  909. }
  910. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  911. hostdata->state = S_CONNECTED;
  912. break;
  913. case EXTENDED_MESSAGE:
  914. DB(DB_INTR, printk("EXT"))
  915. ucp = hostdata->incoming_msg;
  916. #ifdef SYNC_DEBUG
  917. printk("%02x", ucp[hostdata->incoming_ptr]);
  918. #endif
  919. /* Is this the last byte of the extended message? */
  920. if ((hostdata->incoming_ptr >= 2) &&
  921. (hostdata->incoming_ptr == (ucp[1] + 1))) {
  922. switch (ucp[2]) { /* what's the EXTENDED code? */
  923. case EXTENDED_SDTR:
  924. /* default to default async period */
  925. id = calc_sync_xfer(hostdata->
  926. default_sx_per / 4, 0,
  927. 0, hostdata->sx_table);
  928. if (hostdata->sync_stat[cmd->device->id] !=
  929. SS_WAITING) {
  930. /* A device has sent an unsolicited SDTR message; rather than go
  931. * through the effort of decoding it and then figuring out what
  932. * our reply should be, we're just gonna say that we have a
  933. * synchronous fifo depth of 0. This will result in asynchronous
  934. * transfers - not ideal but so much easier.
  935. * Actually, this is OK because it assures us that if we don't
  936. * specifically ask for sync transfers, we won't do any.
  937. */
  938. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  939. hostdata->outgoing_msg[0] =
  940. EXTENDED_MESSAGE;
  941. hostdata->outgoing_msg[1] = 3;
  942. hostdata->outgoing_msg[2] =
  943. EXTENDED_SDTR;
  944. calc_sync_msg(hostdata->
  945. default_sx_per, 0,
  946. 0, hostdata->outgoing_msg + 3);
  947. hostdata->outgoing_len = 5;
  948. } else {
  949. if (ucp[4]) /* well, sync transfer */
  950. id = calc_sync_xfer(ucp[3], ucp[4],
  951. hostdata->fast,
  952. hostdata->sx_table);
  953. else if (ucp[3]) /* very unlikely... */
  954. id = calc_sync_xfer(ucp[3], ucp[4],
  955. 0, hostdata->sx_table);
  956. }
  957. hostdata->sync_xfer[cmd->device->id] = id;
  958. #ifdef SYNC_DEBUG
  959. printk(" sync_xfer=%02x\n",
  960. hostdata->sync_xfer[cmd->device->id]);
  961. #endif
  962. hostdata->sync_stat[cmd->device->id] =
  963. SS_SET;
  964. write_wd33c93_cmd(regs,
  965. WD_CMD_NEGATE_ACK);
  966. hostdata->state = S_CONNECTED;
  967. break;
  968. case EXTENDED_WDTR:
  969. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  970. printk("sending WDTR ");
  971. hostdata->outgoing_msg[0] =
  972. EXTENDED_MESSAGE;
  973. hostdata->outgoing_msg[1] = 2;
  974. hostdata->outgoing_msg[2] =
  975. EXTENDED_WDTR;
  976. hostdata->outgoing_msg[3] = 0; /* 8 bit transfer width */
  977. hostdata->outgoing_len = 4;
  978. write_wd33c93_cmd(regs,
  979. WD_CMD_NEGATE_ACK);
  980. hostdata->state = S_CONNECTED;
  981. break;
  982. default:
  983. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  984. printk
  985. ("Rejecting Unknown Extended Message(%02x). ",
  986. ucp[2]);
  987. hostdata->outgoing_msg[0] =
  988. MESSAGE_REJECT;
  989. hostdata->outgoing_len = 1;
  990. write_wd33c93_cmd(regs,
  991. WD_CMD_NEGATE_ACK);
  992. hostdata->state = S_CONNECTED;
  993. break;
  994. }
  995. hostdata->incoming_ptr = 0;
  996. }
  997. /* We need to read more MESS_IN bytes for the extended message */
  998. else {
  999. hostdata->incoming_ptr++;
  1000. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  1001. hostdata->state = S_CONNECTED;
  1002. }
  1003. break;
  1004. default:
  1005. printk("Rejecting Unknown Message(%02x) ", msg);
  1006. write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  1007. hostdata->outgoing_msg[0] = MESSAGE_REJECT;
  1008. hostdata->outgoing_len = 1;
  1009. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  1010. hostdata->state = S_CONNECTED;
  1011. }
  1012. spin_unlock_irqrestore(&hostdata->lock, flags);
  1013. break;
  1014. /* Note: this interrupt will occur only after a LEVEL2 command */
  1015. case CSR_SEL_XFER_DONE:
  1016. /* Make sure that reselection is enabled at this point - it may
  1017. * have been turned off for the command that just completed.
  1018. */
  1019. write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1020. if (phs == 0x60) {
  1021. DB(DB_INTR, printk("SX-DONE-%ld", cmd->pid))
  1022. cmd->SCp.Message = COMMAND_COMPLETE;
  1023. lun = read_wd33c93(regs, WD_TARGET_LUN);
  1024. DB(DB_INTR, printk(":%d.%d", cmd->SCp.Status, lun))
  1025. hostdata->connected = NULL;
  1026. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1027. hostdata->state = S_UNCONNECTED;
  1028. if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
  1029. cmd->SCp.Status = lun;
  1030. if (cmd->cmnd[0] == REQUEST_SENSE
  1031. && cmd->SCp.Status != GOOD)
  1032. cmd->result =
  1033. (cmd->
  1034. result & 0x00ffff) | (DID_ERROR << 16);
  1035. else
  1036. cmd->result =
  1037. cmd->SCp.Status | (cmd->SCp.Message << 8);
  1038. cmd->scsi_done(cmd);
  1039. /* We are no longer connected to a target - check to see if
  1040. * there are commands waiting to be executed.
  1041. */
  1042. spin_unlock_irqrestore(&hostdata->lock, flags);
  1043. wd33c93_execute(instance);
  1044. } else {
  1045. printk
  1046. ("%02x:%02x:%02x-%ld: Unknown SEL_XFER_DONE phase!!---",
  1047. asr, sr, phs, cmd->pid);
  1048. spin_unlock_irqrestore(&hostdata->lock, flags);
  1049. }
  1050. break;
  1051. /* Note: this interrupt will occur only after a LEVEL2 command */
  1052. case CSR_SDP:
  1053. DB(DB_INTR, printk("SDP"))
  1054. hostdata->state = S_RUNNING_LEVEL2;
  1055. write_wd33c93(regs, WD_COMMAND_PHASE, 0x41);
  1056. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  1057. spin_unlock_irqrestore(&hostdata->lock, flags);
  1058. break;
  1059. case CSR_XFER_DONE | PHS_MESS_OUT:
  1060. case CSR_UNEXP | PHS_MESS_OUT:
  1061. case CSR_SRV_REQ | PHS_MESS_OUT:
  1062. DB(DB_INTR, printk("MSG_OUT="))
  1063. /* To get here, we've probably requested MESSAGE_OUT and have
  1064. * already put the correct bytes in outgoing_msg[] and filled
  1065. * in outgoing_len. We simply send them out to the SCSI bus.
  1066. * Sometimes we get MESSAGE_OUT phase when we're not expecting
  1067. * it - like when our SDTR message is rejected by a target. Some
  1068. * targets send the REJECT before receiving all of the extended
  1069. * message, and then seem to go back to MESSAGE_OUT for a byte
  1070. * or two. Not sure why, or if I'm doing something wrong to
  1071. * cause this to happen. Regardless, it seems that sending
  1072. * NOP messages in these situations results in no harm and
  1073. * makes everyone happy.
  1074. */
  1075. if (hostdata->outgoing_len == 0) {
  1076. hostdata->outgoing_len = 1;
  1077. hostdata->outgoing_msg[0] = NOP;
  1078. }
  1079. transfer_pio(regs, hostdata->outgoing_msg,
  1080. hostdata->outgoing_len, DATA_OUT_DIR, hostdata);
  1081. DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0]))
  1082. hostdata->outgoing_len = 0;
  1083. hostdata->state = S_CONNECTED;
  1084. spin_unlock_irqrestore(&hostdata->lock, flags);
  1085. break;
  1086. case CSR_UNEXP_DISC:
  1087. /* I think I've seen this after a request-sense that was in response
  1088. * to an error condition, but not sure. We certainly need to do
  1089. * something when we get this interrupt - the question is 'what?'.
  1090. * Let's think positively, and assume some command has finished
  1091. * in a legal manner (like a command that provokes a request-sense),
  1092. * so we treat it as a normal command-complete-disconnect.
  1093. */
  1094. /* Make sure that reselection is enabled at this point - it may
  1095. * have been turned off for the command that just completed.
  1096. */
  1097. write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1098. if (cmd == NULL) {
  1099. printk(" - Already disconnected! ");
  1100. hostdata->state = S_UNCONNECTED;
  1101. spin_unlock_irqrestore(&hostdata->lock, flags);
  1102. return;
  1103. }
  1104. DB(DB_INTR, printk("UNEXP_DISC-%ld", cmd->pid))
  1105. hostdata->connected = NULL;
  1106. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1107. hostdata->state = S_UNCONNECTED;
  1108. if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
  1109. cmd->result =
  1110. (cmd->result & 0x00ffff) | (DID_ERROR << 16);
  1111. else
  1112. cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1113. cmd->scsi_done(cmd);
  1114. /* We are no longer connected to a target - check to see if
  1115. * there are commands waiting to be executed.
  1116. */
  1117. /* look above for comments on scsi_done() */
  1118. spin_unlock_irqrestore(&hostdata->lock, flags);
  1119. wd33c93_execute(instance);
  1120. break;
  1121. case CSR_DISC:
  1122. /* Make sure that reselection is enabled at this point - it may
  1123. * have been turned off for the command that just completed.
  1124. */
  1125. write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1126. DB(DB_INTR, printk("DISC-%ld", cmd->pid))
  1127. if (cmd == NULL) {
  1128. printk(" - Already disconnected! ");
  1129. hostdata->state = S_UNCONNECTED;
  1130. }
  1131. switch (hostdata->state) {
  1132. case S_PRE_CMP_DISC:
  1133. hostdata->connected = NULL;
  1134. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1135. hostdata->state = S_UNCONNECTED;
  1136. DB(DB_INTR, printk(":%d", cmd->SCp.Status))
  1137. if (cmd->cmnd[0] == REQUEST_SENSE
  1138. && cmd->SCp.Status != GOOD)
  1139. cmd->result =
  1140. (cmd->
  1141. result & 0x00ffff) | (DID_ERROR << 16);
  1142. else
  1143. cmd->result =
  1144. cmd->SCp.Status | (cmd->SCp.Message << 8);
  1145. cmd->scsi_done(cmd);
  1146. break;
  1147. case S_PRE_TMP_DISC:
  1148. case S_RUNNING_LEVEL2:
  1149. cmd->host_scribble = (uchar *) hostdata->disconnected_Q;
  1150. hostdata->disconnected_Q = cmd;
  1151. hostdata->connected = NULL;
  1152. hostdata->state = S_UNCONNECTED;
  1153. #ifdef PROC_STATISTICS
  1154. hostdata->disc_done_cnt[cmd->device->id]++;
  1155. #endif
  1156. break;
  1157. default:
  1158. printk("*** Unexpected DISCONNECT interrupt! ***");
  1159. hostdata->state = S_UNCONNECTED;
  1160. }
  1161. /* We are no longer connected to a target - check to see if
  1162. * there are commands waiting to be executed.
  1163. */
  1164. spin_unlock_irqrestore(&hostdata->lock, flags);
  1165. wd33c93_execute(instance);
  1166. break;
  1167. case CSR_RESEL_AM:
  1168. case CSR_RESEL:
  1169. DB(DB_INTR, printk("RESEL%s", sr == CSR_RESEL_AM ? "_AM" : ""))
  1170. /* Old chips (pre -A ???) don't have advanced features and will
  1171. * generate CSR_RESEL. In that case we have to extract the LUN the
  1172. * hard way (see below).
  1173. * First we have to make sure this reselection didn't
  1174. * happen during Arbitration/Selection of some other device.
  1175. * If yes, put losing command back on top of input_Q.
  1176. */
  1177. if (hostdata->level2 <= L2_NONE) {
  1178. if (hostdata->selecting) {
  1179. cmd = (struct scsi_cmnd *) hostdata->selecting;
  1180. hostdata->selecting = NULL;
  1181. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1182. cmd->host_scribble =
  1183. (uchar *) hostdata->input_Q;
  1184. hostdata->input_Q = cmd;
  1185. }
  1186. }
  1187. else {
  1188. if (cmd) {
  1189. if (phs == 0x00) {
  1190. hostdata->busy[cmd->device->id] &=
  1191. ~(1 << cmd->device->lun);
  1192. cmd->host_scribble =
  1193. (uchar *) hostdata->input_Q;
  1194. hostdata->input_Q = cmd;
  1195. } else {
  1196. printk
  1197. ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",
  1198. asr, sr, phs);
  1199. while (1)
  1200. printk("\r");
  1201. }
  1202. }
  1203. }
  1204. /* OK - find out which device reselected us. */
  1205. id = read_wd33c93(regs, WD_SOURCE_ID);
  1206. id &= SRCID_MASK;
  1207. /* and extract the lun from the ID message. (Note that we don't
  1208. * bother to check for a valid message here - I guess this is
  1209. * not the right way to go, but...)
  1210. */
  1211. if (sr == CSR_RESEL_AM) {
  1212. lun = read_wd33c93(regs, WD_DATA);
  1213. if (hostdata->level2 < L2_RESELECT)
  1214. write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
  1215. lun &= 7;
  1216. } else {
  1217. /* Old chip; wait for msgin phase to pick up the LUN. */
  1218. for (lun = 255; lun; lun--) {
  1219. if ((asr = read_aux_stat(regs)) & ASR_INT)
  1220. break;
  1221. udelay(10);
  1222. }
  1223. if (!(asr & ASR_INT)) {
  1224. printk
  1225. ("wd33c93: Reselected without IDENTIFY\n");
  1226. lun = 0;
  1227. } else {
  1228. /* Verify this is a change to MSG_IN and read the message */
  1229. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1230. udelay(7);
  1231. if (sr == (CSR_ABORT | PHS_MESS_IN) ||
  1232. sr == (CSR_UNEXP | PHS_MESS_IN) ||
  1233. sr == (CSR_SRV_REQ | PHS_MESS_IN)) {
  1234. /* Got MSG_IN, grab target LUN */
  1235. lun = read_1_byte(regs);
  1236. /* Now we expect a 'paused with ACK asserted' int.. */
  1237. asr = read_aux_stat(regs);
  1238. if (!(asr & ASR_INT)) {
  1239. udelay(10);
  1240. asr = read_aux_stat(regs);
  1241. if (!(asr & ASR_INT))
  1242. printk
  1243. ("wd33c93: No int after LUN on RESEL (%02x)\n",
  1244. asr);
  1245. }
  1246. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1247. udelay(7);
  1248. if (sr != CSR_MSGIN)
  1249. printk
  1250. ("wd33c93: Not paused with ACK on RESEL (%02x)\n",
  1251. sr);
  1252. lun &= 7;
  1253. write_wd33c93_cmd(regs,
  1254. WD_CMD_NEGATE_ACK);
  1255. } else {
  1256. printk
  1257. ("wd33c93: Not MSG_IN on reselect (%02x)\n",
  1258. sr);
  1259. lun = 0;
  1260. }
  1261. }
  1262. }
  1263. /* Now we look for the command that's reconnecting. */
  1264. cmd = (struct scsi_cmnd *) hostdata->disconnected_Q;
  1265. patch = NULL;
  1266. while (cmd) {
  1267. if (id == cmd->device->id && lun == cmd->device->lun)
  1268. break;
  1269. patch = cmd;
  1270. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1271. }
  1272. /* Hmm. Couldn't find a valid command.... What to do? */
  1273. if (!cmd) {
  1274. printk
  1275. ("---TROUBLE: target %d.%d not in disconnect queue---",
  1276. id, lun);
  1277. spin_unlock_irqrestore(&hostdata->lock, flags);
  1278. return;
  1279. }
  1280. /* Ok, found the command - now start it up again. */
  1281. if (patch)
  1282. patch->host_scribble = cmd->host_scribble;
  1283. else
  1284. hostdata->disconnected_Q =
  1285. (struct scsi_cmnd *) cmd->host_scribble;
  1286. hostdata->connected = cmd;
  1287. /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
  1288. * because these things are preserved over a disconnect.
  1289. * But we DO need to fix the DPD bit so it's correct for this command.
  1290. */
  1291. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  1292. write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id);
  1293. else
  1294. write_wd33c93(regs, WD_DESTINATION_ID,
  1295. cmd->device->id | DSTID_DPD);
  1296. if (hostdata->level2 >= L2_RESELECT) {
  1297. write_wd33c93_count(regs, 0); /* we want a DATA_PHASE interrupt */
  1298. write_wd33c93(regs, WD_COMMAND_PHASE, 0x45);
  1299. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  1300. hostdata->state = S_RUNNING_LEVEL2;
  1301. } else
  1302. hostdata->state = S_CONNECTED;
  1303. DB(DB_INTR, printk("-%ld", cmd->pid))
  1304. spin_unlock_irqrestore(&hostdata->lock, flags);
  1305. break;
  1306. default:
  1307. printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr, sr, phs);
  1308. spin_unlock_irqrestore(&hostdata->lock, flags);
  1309. }
  1310. DB(DB_INTR, printk("} "))
  1311. }
  1312. static void
  1313. reset_wd33c93(struct Scsi_Host *instance)
  1314. {
  1315. struct WD33C93_hostdata *hostdata =
  1316. (struct WD33C93_hostdata *) instance->hostdata;
  1317. const wd33c93_regs regs = hostdata->regs;
  1318. uchar sr;
  1319. #ifdef CONFIG_SGI_IP22
  1320. {
  1321. int busycount = 0;
  1322. extern void sgiwd93_reset(unsigned long);
  1323. /* wait 'til the chip gets some time for us */
  1324. while ((read_aux_stat(regs) & ASR_BSY) && busycount++ < 100)
  1325. udelay (10);
  1326. /*
  1327. * there are scsi devices out there, which manage to lock up
  1328. * the wd33c93 in a busy condition. In this state it won't
  1329. * accept the reset command. The only way to solve this is to
  1330. * give the chip a hardware reset (if possible). The code below
  1331. * does this for the SGI Indy, where this is possible
  1332. */
  1333. /* still busy ? */
  1334. if (read_aux_stat(regs) & ASR_BSY)
  1335. sgiwd93_reset(instance->base); /* yeah, give it the hard one */
  1336. }
  1337. #endif
  1338. write_wd33c93(regs, WD_OWN_ID, OWNID_EAF | OWNID_RAF |
  1339. instance->this_id | hostdata->clock_freq);
  1340. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1341. write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
  1342. calc_sync_xfer(hostdata->default_sx_per / 4,
  1343. DEFAULT_SX_OFF, 0, hostdata->sx_table));
  1344. write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET);
  1345. #ifdef CONFIG_MVME147_SCSI
  1346. udelay(25); /* The old wd33c93 on MVME147 needs this, at least */
  1347. #endif
  1348. while (!(read_aux_stat(regs) & ASR_INT))
  1349. ;
  1350. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1351. hostdata->microcode = read_wd33c93(regs, WD_CDB_1);
  1352. if (sr == 0x00)
  1353. hostdata->chip = C_WD33C93;
  1354. else if (sr == 0x01) {
  1355. write_wd33c93(regs, WD_QUEUE_TAG, 0xa5); /* any random number */
  1356. sr = read_wd33c93(regs, WD_QUEUE_TAG);
  1357. if (sr == 0xa5) {
  1358. hostdata->chip = C_WD33C93B;
  1359. write_wd33c93(regs, WD_QUEUE_TAG, 0);
  1360. } else
  1361. hostdata->chip = C_WD33C93A;
  1362. } else
  1363. hostdata->chip = C_UNKNOWN_CHIP;
  1364. if (hostdata->chip != C_WD33C93B) /* Fast SCSI unavailable */
  1365. hostdata->fast = 0;
  1366. write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
  1367. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1368. }
  1369. int
  1370. wd33c93_host_reset(struct scsi_cmnd * SCpnt)
  1371. {
  1372. struct Scsi_Host *instance;
  1373. struct WD33C93_hostdata *hostdata;
  1374. int i;
  1375. instance = SCpnt->device->host;
  1376. hostdata = (struct WD33C93_hostdata *) instance->hostdata;
  1377. printk("scsi%d: reset. ", instance->host_no);
  1378. disable_irq(instance->irq);
  1379. hostdata->dma_stop(instance, NULL, 0);
  1380. for (i = 0; i < 8; i++) {
  1381. hostdata->busy[i] = 0;
  1382. hostdata->sync_xfer[i] =
  1383. calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
  1384. 0, hostdata->sx_table);
  1385. hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
  1386. }
  1387. hostdata->input_Q = NULL;
  1388. hostdata->selecting = NULL;
  1389. hostdata->connected = NULL;
  1390. hostdata->disconnected_Q = NULL;
  1391. hostdata->state = S_UNCONNECTED;
  1392. hostdata->dma = D_DMA_OFF;
  1393. hostdata->incoming_ptr = 0;
  1394. hostdata->outgoing_len = 0;
  1395. reset_wd33c93(instance);
  1396. SCpnt->result = DID_RESET << 16;
  1397. enable_irq(instance->irq);
  1398. return SUCCESS;
  1399. }
  1400. int
  1401. wd33c93_abort(struct scsi_cmnd * cmd)
  1402. {
  1403. struct Scsi_Host *instance;
  1404. struct WD33C93_hostdata *hostdata;
  1405. wd33c93_regs regs;
  1406. struct scsi_cmnd *tmp, *prev;
  1407. disable_irq(cmd->device->host->irq);
  1408. instance = cmd->device->host;
  1409. hostdata = (struct WD33C93_hostdata *) instance->hostdata;
  1410. regs = hostdata->regs;
  1411. /*
  1412. * Case 1 : If the command hasn't been issued yet, we simply remove it
  1413. * from the input_Q.
  1414. */
  1415. tmp = (struct scsi_cmnd *) hostdata->input_Q;
  1416. prev = NULL;
  1417. while (tmp) {
  1418. if (tmp == cmd) {
  1419. if (prev)
  1420. prev->host_scribble = cmd->host_scribble;
  1421. else
  1422. hostdata->input_Q =
  1423. (struct scsi_cmnd *) cmd->host_scribble;
  1424. cmd->host_scribble = NULL;
  1425. cmd->result = DID_ABORT << 16;
  1426. printk
  1427. ("scsi%d: Abort - removing command %ld from input_Q. ",
  1428. instance->host_no, cmd->pid);
  1429. enable_irq(cmd->device->host->irq);
  1430. cmd->scsi_done(cmd);
  1431. return SUCCESS;
  1432. }
  1433. prev = tmp;
  1434. tmp = (struct scsi_cmnd *) tmp->host_scribble;
  1435. }
  1436. /*
  1437. * Case 2 : If the command is connected, we're going to fail the abort
  1438. * and let the high level SCSI driver retry at a later time or
  1439. * issue a reset.
  1440. *
  1441. * Timeouts, and therefore aborted commands, will be highly unlikely
  1442. * and handling them cleanly in this situation would make the common
  1443. * case of noresets less efficient, and would pollute our code. So,
  1444. * we fail.
  1445. */
  1446. if (hostdata->connected == cmd) {
  1447. uchar sr, asr;
  1448. unsigned long timeout;
  1449. printk("scsi%d: Aborting connected command %ld - ",
  1450. instance->host_no, cmd->pid);
  1451. printk("stopping DMA - ");
  1452. if (hostdata->dma == D_DMA_RUNNING) {
  1453. hostdata->dma_stop(instance, cmd, 0);
  1454. hostdata->dma = D_DMA_OFF;
  1455. }
  1456. printk("sending wd33c93 ABORT command - ");
  1457. write_wd33c93(regs, WD_CONTROL,
  1458. CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1459. write_wd33c93_cmd(regs, WD_CMD_ABORT);
  1460. /* Now we have to attempt to flush out the FIFO... */
  1461. printk("flushing fifo - ");
  1462. timeout = 1000000;
  1463. do {
  1464. asr = read_aux_stat(regs);
  1465. if (asr & ASR_DBR)
  1466. read_wd33c93(regs, WD_DATA);
  1467. } while (!(asr & ASR_INT) && timeout-- > 0);
  1468. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1469. printk
  1470. ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
  1471. asr, sr, read_wd33c93_count(regs), timeout);
  1472. /*
  1473. * Abort command processed.
  1474. * Still connected.
  1475. * We must disconnect.
  1476. */
  1477. printk("sending wd33c93 DISCONNECT command - ");
  1478. write_wd33c93_cmd(regs, WD_CMD_DISCONNECT);
  1479. timeout = 1000000;
  1480. asr = read_aux_stat(regs);
  1481. while ((asr & ASR_CIP) && timeout-- > 0)
  1482. asr = read_aux_stat(regs);
  1483. sr = read_wd33c93(regs, WD_SCSI_STATUS);
  1484. printk("asr=%02x, sr=%02x.", asr, sr);
  1485. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1486. hostdata->connected = NULL;
  1487. hostdata->state = S_UNCONNECTED;
  1488. cmd->result = DID_ABORT << 16;
  1489. /* sti();*/
  1490. wd33c93_execute(instance);
  1491. enable_irq(cmd->device->host->irq);
  1492. cmd->scsi_done(cmd);
  1493. return SUCCESS;
  1494. }
  1495. /*
  1496. * Case 3: If the command is currently disconnected from the bus,
  1497. * we're not going to expend much effort here: Let's just return
  1498. * an ABORT_SNOOZE and hope for the best...
  1499. */
  1500. tmp = (struct scsi_cmnd *) hostdata->disconnected_Q;
  1501. while (tmp) {
  1502. if (tmp == cmd) {
  1503. printk
  1504. ("scsi%d: Abort - command %ld found on disconnected_Q - ",
  1505. instance->host_no, cmd->pid);
  1506. printk("Abort SNOOZE. ");
  1507. enable_irq(cmd->device->host->irq);
  1508. return FAILED;
  1509. }
  1510. tmp = (struct scsi_cmnd *) tmp->host_scribble;
  1511. }
  1512. /*
  1513. * Case 4 : If we reached this point, the command was not found in any of
  1514. * the queues.
  1515. *
  1516. * We probably reached this point because of an unlikely race condition
  1517. * between the command completing successfully and the abortion code,
  1518. * so we won't panic, but we will notify the user in case something really
  1519. * broke.
  1520. */
  1521. /* sti();*/
  1522. wd33c93_execute(instance);
  1523. enable_irq(cmd->device->host->irq);
  1524. printk("scsi%d: warning : SCSI command probably completed successfully"
  1525. " before abortion. ", instance->host_no);
  1526. return FAILED;
  1527. }
  1528. #define MAX_WD33C93_HOSTS 4
  1529. #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
  1530. #define SETUP_BUFFER_SIZE 200
  1531. static char setup_buffer[SETUP_BUFFER_SIZE];
  1532. static char setup_used[MAX_SETUP_ARGS];
  1533. static int done_setup = 0;
  1534. int
  1535. wd33c93_setup(char *str)
  1536. {
  1537. int i;
  1538. char *p1, *p2;
  1539. /* The kernel does some processing of the command-line before calling
  1540. * this function: If it begins with any decimal or hex number arguments,
  1541. * ints[0] = how many numbers found and ints[1] through [n] are the values
  1542. * themselves. str points to where the non-numeric arguments (if any)
  1543. * start: We do our own parsing of those. We construct synthetic 'nosync'
  1544. * keywords out of numeric args (to maintain compatibility with older
  1545. * versions) and then add the rest of the arguments.
  1546. */
  1547. p1 = setup_buffer;
  1548. *p1 = '\0';
  1549. if (str)
  1550. strncpy(p1, str, SETUP_BUFFER_SIZE - strlen(setup_buffer));
  1551. setup_buffer[SETUP_BUFFER_SIZE - 1] = '\0';
  1552. p1 = setup_buffer;
  1553. i = 0;
  1554. while (*p1 && (i < MAX_SETUP_ARGS)) {
  1555. p2 = strchr(p1, ',');
  1556. if (p2) {
  1557. *p2 = '\0';
  1558. if (p1 != p2)
  1559. setup_args[i] = p1;
  1560. p1 = p2 + 1;
  1561. i++;
  1562. } else {
  1563. setup_args[i] = p1;
  1564. break;
  1565. }
  1566. }
  1567. for (i = 0; i < MAX_SETUP_ARGS; i++)
  1568. setup_used[i] = 0;
  1569. done_setup = 1;
  1570. return 1;
  1571. }
  1572. __setup("wd33c93=", wd33c93_setup);
  1573. /* check_setup_args() returns index if key found, 0 if not
  1574. */
  1575. static int
  1576. check_setup_args(char *key, int *flags, int *val, char *buf)
  1577. {
  1578. int x;
  1579. char *cp;
  1580. for (x = 0; x < MAX_SETUP_ARGS; x++) {
  1581. if (setup_used[x])
  1582. continue;
  1583. if (!strncmp(setup_args[x], key, strlen(key)))
  1584. break;
  1585. if (!strncmp(setup_args[x], "next", strlen("next")))
  1586. return 0;
  1587. }
  1588. if (x == MAX_SETUP_ARGS)
  1589. return 0;
  1590. setup_used[x] = 1;
  1591. cp = setup_args[x] + strlen(key);
  1592. *val = -1;
  1593. if (*cp != ':')
  1594. return ++x;
  1595. cp++;
  1596. if ((*cp >= '0') && (*cp <= '9')) {
  1597. *val = simple_strtoul(cp, NULL, 0);
  1598. }
  1599. return ++x;
  1600. }
  1601. /*
  1602. * Calculate internal data-transfer-clock cycle from input-clock
  1603. * frequency (/MHz) and fill 'sx_table'.
  1604. *
  1605. * The original driver used to rely on a fixed sx_table, containing periods
  1606. * for (only) the lower limits of the respective input-clock-frequency ranges
  1607. * (8-10/12-15/16-20 MHz). Although it seems, that no problems ocurred with
  1608. * this setting so far, it might be desirable to adjust the transfer periods
  1609. * closer to the really attached, possibly 25% higher, input-clock, since
  1610. * - the wd33c93 may really use a significant shorter period, than it has
  1611. * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
  1612. * instead).
  1613. * - the wd33c93 may ask the target for a lower transfer rate, than the target
  1614. * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
  1615. * possible 200ns, which indeed shows up in tests as an approx. 10% lower
  1616. * transfer rate).
  1617. */
  1618. static inline unsigned int
  1619. round_4(unsigned int x)
  1620. {
  1621. switch (x & 3) {
  1622. case 1: --x;
  1623. break;
  1624. case 2: ++x;
  1625. case 3: ++x;
  1626. }
  1627. return x;
  1628. }
  1629. static void
  1630. calc_sx_table(unsigned int mhz, struct sx_period sx_table[9])
  1631. {
  1632. unsigned int d, i;
  1633. if (mhz < 11)
  1634. d = 2; /* divisor for 8-10 MHz input-clock */
  1635. else if (mhz < 16)
  1636. d = 3; /* divisor for 12-15 MHz input-clock */
  1637. else
  1638. d = 4; /* divisor for 16-20 MHz input-clock */
  1639. d = (100000 * d) / 2 / mhz; /* 100 x DTCC / nanosec */
  1640. sx_table[0].period_ns = 1;
  1641. sx_table[0].reg_value = 0x20;
  1642. for (i = 1; i < 8; i++) {
  1643. sx_table[i].period_ns = round_4((i+1)*d / 100);
  1644. sx_table[i].reg_value = (i+1)*0x10;
  1645. }
  1646. sx_table[7].reg_value = 0;
  1647. sx_table[8].period_ns = 0;
  1648. sx_table[8].reg_value = 0;
  1649. }
  1650. /*
  1651. * check and, maybe, map an init- or "clock:"- argument.
  1652. */
  1653. static uchar
  1654. set_clk_freq(int freq, int *mhz)
  1655. {
  1656. int x = freq;
  1657. if (WD33C93_FS_8_10 == freq)
  1658. freq = 8;
  1659. else if (WD33C93_FS_12_15 == freq)
  1660. freq = 12;
  1661. else if (WD33C93_FS_16_20 == freq)
  1662. freq = 16;
  1663. else if (freq > 7 && freq < 11)
  1664. x = WD33C93_FS_8_10;
  1665. else if (freq > 11 && freq < 16)
  1666. x = WD33C93_FS_12_15;
  1667. else if (freq > 15 && freq < 21)
  1668. x = WD33C93_FS_16_20;
  1669. else {
  1670. /* Hmm, wouldn't it be safer to assume highest freq here? */
  1671. x = WD33C93_FS_8_10;
  1672. freq = 8;
  1673. }
  1674. *mhz = freq;
  1675. return x;
  1676. }
  1677. /*
  1678. * to be used with the resync: fast: ... options
  1679. */
  1680. static inline void set_resync ( struct WD33C93_hostdata *hd, int mask )
  1681. {
  1682. int i;
  1683. for (i = 0; i < 8; i++)
  1684. if (mask & (1 << i))
  1685. hd->sync_stat[i] = SS_UNSET;
  1686. }
  1687. void
  1688. wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
  1689. dma_setup_t setup, dma_stop_t stop, int clock_freq)
  1690. {
  1691. struct WD33C93_hostdata *hostdata;
  1692. int i;
  1693. int flags;
  1694. int val;
  1695. char buf[32];
  1696. if (!done_setup && setup_strings)
  1697. wd33c93_setup(setup_strings);
  1698. hostdata = (struct WD33C93_hostdata *) instance->hostdata;
  1699. hostdata->regs = regs;
  1700. hostdata->clock_freq = set_clk_freq(clock_freq, &i);
  1701. calc_sx_table(i, hostdata->sx_table);
  1702. hostdata->dma_setup = setup;
  1703. hostdata->dma_stop = stop;
  1704. hostdata->dma_bounce_buffer = NULL;
  1705. hostdata->dma_bounce_len = 0;
  1706. for (i = 0; i < 8; i++) {
  1707. hostdata->busy[i] = 0;
  1708. hostdata->sync_xfer[i] =
  1709. calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
  1710. 0, hostdata->sx_table);
  1711. hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
  1712. #ifdef PROC_STATISTICS
  1713. hostdata->cmd_cnt[i] = 0;
  1714. hostdata->disc_allowed_cnt[i] = 0;
  1715. hostdata->disc_done_cnt[i] = 0;
  1716. #endif
  1717. }
  1718. hostdata->input_Q = NULL;
  1719. hostdata->selecting = NULL;
  1720. hostdata->connected = NULL;
  1721. hostdata->disconnected_Q = NULL;
  1722. hostdata->state = S_UNCONNECTED;
  1723. hostdata->dma = D_DMA_OFF;
  1724. hostdata->level2 = L2_BASIC;
  1725. hostdata->disconnect = DIS_ADAPTIVE;
  1726. hostdata->args = DEBUG_DEFAULTS;
  1727. hostdata->incoming_ptr = 0;
  1728. hostdata->outgoing_len = 0;
  1729. hostdata->default_sx_per = DEFAULT_SX_PER;
  1730. hostdata->no_sync = 0xff; /* sync defaults to off */
  1731. hostdata->no_dma = 0; /* default is DMA enabled */
  1732. hostdata->fast = 0; /* default is Fast SCSI transfers disabled */
  1733. hostdata->dma_mode = CTRL_DMA; /* default is Single Byte DMA */
  1734. #ifdef PROC_INTERFACE
  1735. hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS |
  1736. PR_CONNECTED | PR_INPUTQ | PR_DISCQ | PR_STOP;
  1737. #ifdef PROC_STATISTICS
  1738. hostdata->dma_cnt = 0;
  1739. hostdata->pio_cnt = 0;
  1740. hostdata->int_cnt = 0;
  1741. #endif
  1742. #endif
  1743. if (check_setup_args("clock", &flags, &val, buf)) {
  1744. hostdata->clock_freq = set_clk_freq(val, &val);
  1745. calc_sx_table(val, hostdata->sx_table);
  1746. }
  1747. if (check_setup_args("nosync", &flags, &val, buf))
  1748. hostdata->no_sync = val;
  1749. if (check_setup_args("nodma", &flags, &val, buf))
  1750. hostdata->no_dma = (val == -1) ? 1 : val;
  1751. if (check_setup_args("period", &flags, &val, buf))
  1752. hostdata->default_sx_per =
  1753. hostdata->sx_table[round_period((unsigned int) val,
  1754. hostdata->sx_table)].period_ns;
  1755. if (check_setup_args("disconnect", &flags, &val, buf)) {
  1756. if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
  1757. hostdata->disconnect = val;
  1758. else
  1759. hostdata->disconnect = DIS_ADAPTIVE;
  1760. }
  1761. if (check_setup_args("level2", &flags, &val, buf))
  1762. hostdata->level2 = val;
  1763. if (check_setup_args("debug", &flags, &val, buf))
  1764. hostdata->args = val & DB_MASK;
  1765. if (check_setup_args("burst", &flags, &val, buf))
  1766. hostdata->dma_mode = val ? CTRL_BURST:CTRL_DMA;
  1767. if (WD33C93_FS_16_20 == hostdata->clock_freq /* divisor 4 */
  1768. && check_setup_args("fast", &flags, &val, buf))
  1769. hostdata->fast = !!val;
  1770. if ((i = check_setup_args("next", &flags, &val, buf))) {
  1771. while (i)
  1772. setup_used[--i] = 1;
  1773. }
  1774. #ifdef PROC_INTERFACE
  1775. if (check_setup_args("proc", &flags, &val, buf))
  1776. hostdata->proc = val;
  1777. #endif
  1778. spin_lock_irq(&hostdata->lock);
  1779. reset_wd33c93(instance);
  1780. spin_unlock_irq(&hostdata->lock);
  1781. printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d",
  1782. instance->host_no,
  1783. (hostdata->chip == C_WD33C93) ? "WD33c93" : (hostdata->chip ==
  1784. C_WD33C93A) ?
  1785. "WD33c93A" : (hostdata->chip ==
  1786. C_WD33C93B) ? "WD33c93B" : "unknown",
  1787. hostdata->microcode, hostdata->no_sync, hostdata->no_dma);
  1788. #ifdef DEBUGGING_ON
  1789. printk(" debug_flags=0x%02x\n", hostdata->args);
  1790. #else
  1791. printk(" debugging=OFF\n");
  1792. #endif
  1793. printk(" setup_args=");
  1794. for (i = 0; i < MAX_SETUP_ARGS; i++)
  1795. printk("%s,", setup_args[i]);
  1796. printk("\n");
  1797. printk(" Version %s - %s, Compiled %s at %s\n",
  1798. WD33C93_VERSION, WD33C93_DATE, __DATE__, __TIME__);
  1799. }
  1800. int
  1801. wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off, int len, int in)
  1802. {
  1803. #ifdef PROC_INTERFACE
  1804. char *bp;
  1805. char tbuf[128];
  1806. struct WD33C93_hostdata *hd;
  1807. struct scsi_cmnd *cmd;
  1808. int x;
  1809. static int stop = 0;
  1810. hd = (struct WD33C93_hostdata *) instance->hostdata;
  1811. /* If 'in' is TRUE we need to _read_ the proc file. We accept the following
  1812. * keywords (same format as command-line, but arguments are not optional):
  1813. * debug
  1814. * disconnect
  1815. * period
  1816. * resync
  1817. * proc
  1818. * nodma
  1819. * level2
  1820. * burst
  1821. * fast
  1822. * nosync
  1823. */
  1824. if (in) {
  1825. buf[len] = '\0';
  1826. for (bp = buf; *bp; ) {
  1827. while (',' == *bp || ' ' == *bp)
  1828. ++bp;
  1829. if (!strncmp(bp, "debug:", 6)) {
  1830. hd->args = simple_strtoul(bp+6, &bp, 0) & DB_MASK;
  1831. } else if (!strncmp(bp, "disconnect:", 11)) {
  1832. x = simple_strtoul(bp+11, &bp, 0);
  1833. if (x < DIS_NEVER || x > DIS_ALWAYS)
  1834. x = DIS_ADAPTIVE;
  1835. hd->disconnect = x;
  1836. } else if (!strncmp(bp, "period:", 7)) {
  1837. x = simple_strtoul(bp+7, &bp, 0);
  1838. hd->default_sx_per =
  1839. hd->sx_table[round_period((unsigned int) x,
  1840. hd->sx_table)].period_ns;
  1841. } else if (!strncmp(bp, "resync:", 7)) {
  1842. set_resync(hd, (int)simple_strtoul(bp+7, &bp, 0));
  1843. } else if (!strncmp(bp, "proc:", 5)) {
  1844. hd->proc = simple_strtoul(bp+5, &bp, 0);
  1845. } else if (!strncmp(bp, "nodma:", 6)) {
  1846. hd->no_dma = simple_strtoul(bp+6, &bp, 0);
  1847. } else if (!strncmp(bp, "level2:", 7)) {
  1848. hd->level2 = simple_strtoul(bp+7, &bp, 0);
  1849. } else if (!strncmp(bp, "burst:", 6)) {
  1850. hd->dma_mode =
  1851. simple_strtol(bp+6, &bp, 0) ? CTRL_BURST:CTRL_DMA;
  1852. } else if (!strncmp(bp, "fast:", 5)) {
  1853. x = !!simple_strtol(bp+5, &bp, 0);
  1854. if (x != hd->fast)
  1855. set_resync(hd, 0xff);
  1856. hd->fast = x;
  1857. } else if (!strncmp(bp, "nosync:", 7)) {
  1858. x = simple_strtoul(bp+7, &bp, 0);
  1859. set_resync(hd, x ^ hd->no_sync);
  1860. hd->no_sync = x;
  1861. } else {
  1862. break; /* unknown keyword,syntax-error,... */
  1863. }
  1864. }
  1865. return len;
  1866. }
  1867. spin_lock_irq(&hd->lock);
  1868. bp = buf;
  1869. *bp = '\0';
  1870. if (hd->proc & PR_VERSION) {
  1871. sprintf(tbuf, "\nVersion %s - %s. Compiled %s %s",
  1872. WD33C93_VERSION, WD33C93_DATE, __DATE__, __TIME__);
  1873. strcat(bp, tbuf);
  1874. }
  1875. if (hd->proc & PR_INFO) {
  1876. sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
  1877. " dma_mode=%02x fast=%d",
  1878. hd->clock_freq, hd->no_sync, hd->no_dma, hd->dma_mode, hd->fast);
  1879. strcat(bp, tbuf);
  1880. strcat(bp, "\nsync_xfer[] = ");
  1881. for (x = 0; x < 7; x++) {
  1882. sprintf(tbuf, "\t%02x", hd->sync_xfer[x]);
  1883. strcat(bp, tbuf);
  1884. }
  1885. strcat(bp, "\nsync_stat[] = ");
  1886. for (x = 0; x < 7; x++) {
  1887. sprintf(tbuf, "\t%02x", hd->sync_stat[x]);
  1888. strcat(bp, tbuf);
  1889. }
  1890. }
  1891. #ifdef PROC_STATISTICS
  1892. if (hd->proc & PR_STATISTICS) {
  1893. strcat(bp, "\ncommands issued: ");
  1894. for (x = 0; x < 7; x++) {
  1895. sprintf(tbuf, "\t%ld", hd->cmd_cnt[x]);
  1896. strcat(bp, tbuf);
  1897. }
  1898. strcat(bp, "\ndisconnects allowed:");
  1899. for (x = 0; x < 7; x++) {
  1900. sprintf(tbuf, "\t%ld", hd->disc_allowed_cnt[x]);
  1901. strcat(bp, tbuf);
  1902. }
  1903. strcat(bp, "\ndisconnects done: ");
  1904. for (x = 0; x < 7; x++) {
  1905. sprintf(tbuf, "\t%ld", hd->disc_done_cnt[x]);
  1906. strcat(bp, tbuf);
  1907. }
  1908. sprintf(tbuf,
  1909. "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
  1910. hd->int_cnt, hd->dma_cnt, hd->pio_cnt);
  1911. strcat(bp, tbuf);
  1912. }
  1913. #endif
  1914. if (hd->proc & PR_CONNECTED) {
  1915. strcat(bp, "\nconnected: ");
  1916. if (hd->connected) {
  1917. cmd = (struct scsi_cmnd *) hd->connected;
  1918. sprintf(tbuf, " %ld-%d:%d(%02x)",
  1919. cmd->pid, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1920. strcat(bp, tbuf);
  1921. }
  1922. }
  1923. if (hd->proc & PR_INPUTQ) {
  1924. strcat(bp, "\ninput_Q: ");
  1925. cmd = (struct scsi_cmnd *) hd->input_Q;
  1926. while (cmd) {
  1927. sprintf(tbuf, " %ld-%d:%d(%02x)",
  1928. cmd->pid, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1929. strcat(bp, tbuf);
  1930. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1931. }
  1932. }
  1933. if (hd->proc & PR_DISCQ) {
  1934. strcat(bp, "\ndisconnected_Q:");
  1935. cmd = (struct scsi_cmnd *) hd->disconnected_Q;
  1936. while (cmd) {
  1937. sprintf(tbuf, " %ld-%d:%d(%02x)",
  1938. cmd->pid, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1939. strcat(bp, tbuf);
  1940. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1941. }
  1942. }
  1943. strcat(bp, "\n");
  1944. spin_unlock_irq(&hd->lock);
  1945. *start = buf;
  1946. if (stop) {
  1947. stop = 0;
  1948. return 0;
  1949. }
  1950. if (off > 0x40000) /* ALWAYS stop after 256k bytes have been read */
  1951. stop = 1;
  1952. if (hd->proc & PR_STOP) /* stop every other time */
  1953. stop = 1;
  1954. return strlen(bp);
  1955. #else /* PROC_INTERFACE */
  1956. return 0;
  1957. #endif /* PROC_INTERFACE */
  1958. }
  1959. void
  1960. wd33c93_release(void)
  1961. {
  1962. }
  1963. EXPORT_SYMBOL(wd33c93_host_reset);
  1964. EXPORT_SYMBOL(wd33c93_init);
  1965. EXPORT_SYMBOL(wd33c93_release);
  1966. EXPORT_SYMBOL(wd33c93_abort);
  1967. EXPORT_SYMBOL(wd33c93_queuecommand);
  1968. EXPORT_SYMBOL(wd33c93_intr);
  1969. EXPORT_SYMBOL(wd33c93_proc_info);