wd33c93.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233
  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. static int
  334. wd33c93_queuecommand_lck(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( ", cmd->device->id, cmd->cmnd[0]))
  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 "))
  412. spin_unlock_irq(&hostdata->lock);
  413. return 0;
  414. }
  415. DEF_SCSI_QCMD(wd33c93_queuecommand)
  416. /*
  417. * This routine attempts to start a scsi command. If the host_card is
  418. * already connected, we give up immediately. Otherwise, look through
  419. * the input_Q, using the first command we find that's intended
  420. * for a currently non-busy target/lun.
  421. *
  422. * wd33c93_execute() is always called with interrupts disabled or from
  423. * the wd33c93_intr itself, which means that a wd33c93 interrupt
  424. * cannot occur while we are in here.
  425. */
  426. static void
  427. wd33c93_execute(struct Scsi_Host *instance)
  428. {
  429. struct WD33C93_hostdata *hostdata =
  430. (struct WD33C93_hostdata *) instance->hostdata;
  431. const wd33c93_regs regs = hostdata->regs;
  432. struct scsi_cmnd *cmd, *prev;
  433. DB(DB_EXECUTE, printk("EX("))
  434. if (hostdata->selecting || hostdata->connected) {
  435. DB(DB_EXECUTE, printk(")EX-0 "))
  436. return;
  437. }
  438. /*
  439. * Search through the input_Q for a command destined
  440. * for an idle target/lun.
  441. */
  442. cmd = (struct scsi_cmnd *) hostdata->input_Q;
  443. prev = NULL;
  444. while (cmd) {
  445. if (!(hostdata->busy[cmd->device->id] & (1 << cmd->device->lun)))
  446. break;
  447. prev = cmd;
  448. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  449. }
  450. /* quit if queue empty or all possible targets are busy */
  451. if (!cmd) {
  452. DB(DB_EXECUTE, printk(")EX-1 "))
  453. return;
  454. }
  455. /* remove command from queue */
  456. if (prev)
  457. prev->host_scribble = cmd->host_scribble;
  458. else
  459. hostdata->input_Q = (struct scsi_cmnd *) cmd->host_scribble;
  460. #ifdef PROC_STATISTICS
  461. hostdata->cmd_cnt[cmd->device->id]++;
  462. #endif
  463. /*
  464. * Start the selection process
  465. */
  466. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  467. write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id);
  468. else
  469. write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD);
  470. /* Now we need to figure out whether or not this command is a good
  471. * candidate for disconnect/reselect. We guess to the best of our
  472. * ability, based on a set of hierarchical rules. When several
  473. * devices are operating simultaneously, disconnects are usually
  474. * an advantage. In a single device system, or if only 1 device
  475. * is being accessed, transfers usually go faster if disconnects
  476. * are not allowed:
  477. *
  478. * + Commands should NEVER disconnect if hostdata->disconnect =
  479. * DIS_NEVER (this holds for tape drives also), and ALWAYS
  480. * disconnect if hostdata->disconnect = DIS_ALWAYS.
  481. * + Tape drive commands should always be allowed to disconnect.
  482. * + Disconnect should be allowed if disconnected_Q isn't empty.
  483. * + Commands should NOT disconnect if input_Q is empty.
  484. * + Disconnect should be allowed if there are commands in input_Q
  485. * for a different target/lun. In this case, the other commands
  486. * should be made disconnect-able, if not already.
  487. *
  488. * I know, I know - this code would flunk me out of any
  489. * "C Programming 101" class ever offered. But it's easy
  490. * to change around and experiment with for now.
  491. */
  492. cmd->SCp.phase = 0; /* assume no disconnect */
  493. if (hostdata->disconnect == DIS_NEVER)
  494. goto no;
  495. if (hostdata->disconnect == DIS_ALWAYS)
  496. goto yes;
  497. if (cmd->device->type == 1) /* tape drive? */
  498. goto yes;
  499. if (hostdata->disconnected_Q) /* other commands disconnected? */
  500. goto yes;
  501. if (!(hostdata->input_Q)) /* input_Q empty? */
  502. goto no;
  503. for (prev = (struct scsi_cmnd *) hostdata->input_Q; prev;
  504. prev = (struct scsi_cmnd *) prev->host_scribble) {
  505. if ((prev->device->id != cmd->device->id) ||
  506. (prev->device->lun != cmd->device->lun)) {
  507. for (prev = (struct scsi_cmnd *) hostdata->input_Q; prev;
  508. prev = (struct scsi_cmnd *) prev->host_scribble)
  509. prev->SCp.phase = 1;
  510. goto yes;
  511. }
  512. }
  513. goto no;
  514. yes:
  515. cmd->SCp.phase = 1;
  516. #ifdef PROC_STATISTICS
  517. hostdata->disc_allowed_cnt[cmd->device->id]++;
  518. #endif
  519. no:
  520. write_wd33c93(regs, WD_SOURCE_ID, ((cmd->SCp.phase) ? SRCID_ER : 0));
  521. write_wd33c93(regs, WD_TARGET_LUN, cmd->device->lun);
  522. write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
  523. hostdata->sync_xfer[cmd->device->id]);
  524. hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
  525. if ((hostdata->level2 == L2_NONE) ||
  526. (hostdata->sync_stat[cmd->device->id] == SS_UNSET)) {
  527. /*
  528. * Do a 'Select-With-ATN' command. This will end with
  529. * one of the following interrupts:
  530. * CSR_RESEL_AM: failure - can try again later.
  531. * CSR_TIMEOUT: failure - give up.
  532. * CSR_SELECT: success - proceed.
  533. */
  534. hostdata->selecting = cmd;
  535. /* Every target has its own synchronous transfer setting, kept in the
  536. * sync_xfer array, and a corresponding status byte in sync_stat[].
  537. * Each target's sync_stat[] entry is initialized to SX_UNSET, and its
  538. * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
  539. * means that the parameters are undetermined as yet, and that we
  540. * need to send an SDTR message to this device after selection is
  541. * complete: We set SS_FIRST to tell the interrupt routine to do so.
  542. * If we've been asked not to try synchronous transfers on this
  543. * target (and _all_ luns within it), we'll still send the SDTR message
  544. * later, but at that time we'll negotiate for async by specifying a
  545. * sync fifo depth of 0.
  546. */
  547. if (hostdata->sync_stat[cmd->device->id] == SS_UNSET)
  548. hostdata->sync_stat[cmd->device->id] = SS_FIRST;
  549. hostdata->state = S_SELECTING;
  550. write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */
  551. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN);
  552. } else {
  553. /*
  554. * Do a 'Select-With-ATN-Xfer' command. This will end with
  555. * one of the following interrupts:
  556. * CSR_RESEL_AM: failure - can try again later.
  557. * CSR_TIMEOUT: failure - give up.
  558. * anything else: success - proceed.
  559. */
  560. hostdata->connected = cmd;
  561. write_wd33c93(regs, WD_COMMAND_PHASE, 0);
  562. /* copy command_descriptor_block into WD chip
  563. * (take advantage of auto-incrementing)
  564. */
  565. write_wd33c93_cdb(regs, cmd->cmd_len, cmd->cmnd);
  566. /* The wd33c93 only knows about Group 0, 1, and 5 commands when
  567. * it's doing a 'select-and-transfer'. To be safe, we write the
  568. * size of the CDB into the OWN_ID register for every case. This
  569. * way there won't be problems with vendor-unique, audio, etc.
  570. */
  571. write_wd33c93(regs, WD_OWN_ID, cmd->cmd_len);
  572. /* When doing a non-disconnect command with DMA, we can save
  573. * ourselves a DATA phase interrupt later by setting everything
  574. * up ahead of time.
  575. */
  576. if ((cmd->SCp.phase == 0) && (hostdata->no_dma == 0)) {
  577. if (hostdata->dma_setup(cmd,
  578. (cmd->sc_data_direction == DMA_TO_DEVICE) ?
  579. DATA_OUT_DIR : DATA_IN_DIR))
  580. write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */
  581. else {
  582. write_wd33c93_count(regs,
  583. cmd->SCp.this_residual);
  584. write_wd33c93(regs, WD_CONTROL,
  585. CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
  586. hostdata->dma = D_DMA_RUNNING;
  587. }
  588. } else
  589. write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */
  590. hostdata->state = S_RUNNING_LEVEL2;
  591. write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  592. }
  593. /*
  594. * Since the SCSI bus can handle only 1 connection at a time,
  595. * we get out of here now. If the selection fails, or when
  596. * the command disconnects, we'll come back to this routine
  597. * to search the input_Q again...
  598. */
  599. DB(DB_EXECUTE,
  600. printk("%s)EX-2 ", (cmd->SCp.phase) ? "d:" : ""))
  601. }
  602. static void
  603. transfer_pio(const wd33c93_regs regs, uchar * buf, int cnt,
  604. int data_in_dir, struct WD33C93_hostdata *hostdata)
  605. {
  606. uchar asr;
  607. DB(DB_TRANSFER,
  608. printk("(%p,%d,%s:", buf, cnt, data_in_dir ? "in" : "out"))
  609. write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  610. write_wd33c93_count(regs, cnt);
  611. write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO);
  612. if (data_in_dir) {
  613. do {
  614. asr = read_aux_stat(regs);
  615. if (asr & ASR_DBR)
  616. *buf++ = read_wd33c93(regs, WD_DATA);
  617. } while (!(asr & ASR_INT));
  618. } else {
  619. do {
  620. asr = read_aux_stat(regs);
  621. if (asr & ASR_DBR)
  622. write_wd33c93(regs, WD_DATA, *buf++);
  623. } while (!(asr & ASR_INT));
  624. }
  625. /* Note: we are returning with the interrupt UN-cleared.
  626. * Since (presumably) an entire I/O operation has
  627. * completed, the bus phase is probably different, and
  628. * the interrupt routine will discover this when it
  629. * responds to the uncleared int.
  630. */
  631. }
  632. static void
  633. transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
  634. int data_in_dir)
  635. {
  636. struct WD33C93_hostdata *hostdata;
  637. unsigned long length;
  638. hostdata = (struct WD33C93_hostdata *) cmd->device->host->hostdata;
  639. /* Normally, you'd expect 'this_residual' to be non-zero here.
  640. * In a series of scatter-gather transfers, however, this
  641. * routine will usually be called with 'this_residual' equal
  642. * to 0 and 'buffers_residual' non-zero. This means that a
  643. * previous transfer completed, clearing 'this_residual', and
  644. * now we need to setup the next scatter-gather buffer as the
  645. * source or destination for THIS transfer.
  646. */
  647. if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
  648. ++cmd->SCp.buffer;
  649. --cmd->SCp.buffers_residual;
  650. cmd->SCp.this_residual = cmd->SCp.buffer->length;
  651. cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
  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", cmd->cmnd[0]))
  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"))
  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"))
  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: Unknown SEL_XFER_DONE phase!!---",
  1047. asr, sr, phs);
  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"))
  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"))
  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. 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 from input_Q. ",
  1427. instance->host_no);
  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 - ",
  1449. instance->host_no);
  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 found on disconnected_Q - ",
  1504. instance->host_no);
  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 occurred 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\n", WD33C93_VERSION, WD33C93_DATE);
  1794. }
  1795. int
  1796. wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off, int len, int in)
  1797. {
  1798. #ifdef PROC_INTERFACE
  1799. char *bp;
  1800. char tbuf[128];
  1801. struct WD33C93_hostdata *hd;
  1802. struct scsi_cmnd *cmd;
  1803. int x;
  1804. static int stop = 0;
  1805. hd = (struct WD33C93_hostdata *) instance->hostdata;
  1806. /* If 'in' is TRUE we need to _read_ the proc file. We accept the following
  1807. * keywords (same format as command-line, but arguments are not optional):
  1808. * debug
  1809. * disconnect
  1810. * period
  1811. * resync
  1812. * proc
  1813. * nodma
  1814. * level2
  1815. * burst
  1816. * fast
  1817. * nosync
  1818. */
  1819. if (in) {
  1820. buf[len] = '\0';
  1821. for (bp = buf; *bp; ) {
  1822. while (',' == *bp || ' ' == *bp)
  1823. ++bp;
  1824. if (!strncmp(bp, "debug:", 6)) {
  1825. hd->args = simple_strtoul(bp+6, &bp, 0) & DB_MASK;
  1826. } else if (!strncmp(bp, "disconnect:", 11)) {
  1827. x = simple_strtoul(bp+11, &bp, 0);
  1828. if (x < DIS_NEVER || x > DIS_ALWAYS)
  1829. x = DIS_ADAPTIVE;
  1830. hd->disconnect = x;
  1831. } else if (!strncmp(bp, "period:", 7)) {
  1832. x = simple_strtoul(bp+7, &bp, 0);
  1833. hd->default_sx_per =
  1834. hd->sx_table[round_period((unsigned int) x,
  1835. hd->sx_table)].period_ns;
  1836. } else if (!strncmp(bp, "resync:", 7)) {
  1837. set_resync(hd, (int)simple_strtoul(bp+7, &bp, 0));
  1838. } else if (!strncmp(bp, "proc:", 5)) {
  1839. hd->proc = simple_strtoul(bp+5, &bp, 0);
  1840. } else if (!strncmp(bp, "nodma:", 6)) {
  1841. hd->no_dma = simple_strtoul(bp+6, &bp, 0);
  1842. } else if (!strncmp(bp, "level2:", 7)) {
  1843. hd->level2 = simple_strtoul(bp+7, &bp, 0);
  1844. } else if (!strncmp(bp, "burst:", 6)) {
  1845. hd->dma_mode =
  1846. simple_strtol(bp+6, &bp, 0) ? CTRL_BURST:CTRL_DMA;
  1847. } else if (!strncmp(bp, "fast:", 5)) {
  1848. x = !!simple_strtol(bp+5, &bp, 0);
  1849. if (x != hd->fast)
  1850. set_resync(hd, 0xff);
  1851. hd->fast = x;
  1852. } else if (!strncmp(bp, "nosync:", 7)) {
  1853. x = simple_strtoul(bp+7, &bp, 0);
  1854. set_resync(hd, x ^ hd->no_sync);
  1855. hd->no_sync = x;
  1856. } else {
  1857. break; /* unknown keyword,syntax-error,... */
  1858. }
  1859. }
  1860. return len;
  1861. }
  1862. spin_lock_irq(&hd->lock);
  1863. bp = buf;
  1864. *bp = '\0';
  1865. if (hd->proc & PR_VERSION) {
  1866. sprintf(tbuf, "\nVersion %s - %s.",
  1867. WD33C93_VERSION, WD33C93_DATE);
  1868. strcat(bp, tbuf);
  1869. }
  1870. if (hd->proc & PR_INFO) {
  1871. sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
  1872. " dma_mode=%02x fast=%d",
  1873. hd->clock_freq, hd->no_sync, hd->no_dma, hd->dma_mode, hd->fast);
  1874. strcat(bp, tbuf);
  1875. strcat(bp, "\nsync_xfer[] = ");
  1876. for (x = 0; x < 7; x++) {
  1877. sprintf(tbuf, "\t%02x", hd->sync_xfer[x]);
  1878. strcat(bp, tbuf);
  1879. }
  1880. strcat(bp, "\nsync_stat[] = ");
  1881. for (x = 0; x < 7; x++) {
  1882. sprintf(tbuf, "\t%02x", hd->sync_stat[x]);
  1883. strcat(bp, tbuf);
  1884. }
  1885. }
  1886. #ifdef PROC_STATISTICS
  1887. if (hd->proc & PR_STATISTICS) {
  1888. strcat(bp, "\ncommands issued: ");
  1889. for (x = 0; x < 7; x++) {
  1890. sprintf(tbuf, "\t%ld", hd->cmd_cnt[x]);
  1891. strcat(bp, tbuf);
  1892. }
  1893. strcat(bp, "\ndisconnects allowed:");
  1894. for (x = 0; x < 7; x++) {
  1895. sprintf(tbuf, "\t%ld", hd->disc_allowed_cnt[x]);
  1896. strcat(bp, tbuf);
  1897. }
  1898. strcat(bp, "\ndisconnects done: ");
  1899. for (x = 0; x < 7; x++) {
  1900. sprintf(tbuf, "\t%ld", hd->disc_done_cnt[x]);
  1901. strcat(bp, tbuf);
  1902. }
  1903. sprintf(tbuf,
  1904. "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
  1905. hd->int_cnt, hd->dma_cnt, hd->pio_cnt);
  1906. strcat(bp, tbuf);
  1907. }
  1908. #endif
  1909. if (hd->proc & PR_CONNECTED) {
  1910. strcat(bp, "\nconnected: ");
  1911. if (hd->connected) {
  1912. cmd = (struct scsi_cmnd *) hd->connected;
  1913. sprintf(tbuf, " %d:%d(%02x)",
  1914. cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1915. strcat(bp, tbuf);
  1916. }
  1917. }
  1918. if (hd->proc & PR_INPUTQ) {
  1919. strcat(bp, "\ninput_Q: ");
  1920. cmd = (struct scsi_cmnd *) hd->input_Q;
  1921. while (cmd) {
  1922. sprintf(tbuf, " %d:%d(%02x)",
  1923. cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1924. strcat(bp, tbuf);
  1925. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1926. }
  1927. }
  1928. if (hd->proc & PR_DISCQ) {
  1929. strcat(bp, "\ndisconnected_Q:");
  1930. cmd = (struct scsi_cmnd *) hd->disconnected_Q;
  1931. while (cmd) {
  1932. sprintf(tbuf, " %d:%d(%02x)",
  1933. cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1934. strcat(bp, tbuf);
  1935. cmd = (struct scsi_cmnd *) cmd->host_scribble;
  1936. }
  1937. }
  1938. strcat(bp, "\n");
  1939. spin_unlock_irq(&hd->lock);
  1940. *start = buf;
  1941. if (stop) {
  1942. stop = 0;
  1943. return 0;
  1944. }
  1945. if (off > 0x40000) /* ALWAYS stop after 256k bytes have been read */
  1946. stop = 1;
  1947. if (hd->proc & PR_STOP) /* stop every other time */
  1948. stop = 1;
  1949. return strlen(bp);
  1950. #else /* PROC_INTERFACE */
  1951. return 0;
  1952. #endif /* PROC_INTERFACE */
  1953. }
  1954. EXPORT_SYMBOL(wd33c93_host_reset);
  1955. EXPORT_SYMBOL(wd33c93_init);
  1956. EXPORT_SYMBOL(wd33c93_abort);
  1957. EXPORT_SYMBOL(wd33c93_queuecommand);
  1958. EXPORT_SYMBOL(wd33c93_intr);
  1959. EXPORT_SYMBOL(wd33c93_proc_info);