in2000.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303
  1. /*
  2. * in2000.c - Linux device driver for the
  3. * Always IN2000 ISA SCSI card.
  4. *
  5. * Copyright (c) 1996 John Shifflett, GeoLog Consulting
  6. * john@geolog.com
  7. * jshiffle@netcom.com
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * For the avoidance of doubt the "preferred form" of this code is one which
  20. * is in an open non patent encumbered format. Where cryptographic key signing
  21. * forms part of the process of creating an executable the information
  22. * including keys needed to generate an equivalently functional executable
  23. * are deemed to be part of the source code.
  24. *
  25. * Drew Eckhardt's excellent 'Generic NCR5380' sources provided
  26. * much of the inspiration and some of the code for this driver.
  27. * The Linux IN2000 driver distributed in the Linux kernels through
  28. * version 1.2.13 was an extremely valuable reference on the arcane
  29. * (and still mysterious) workings of the IN2000's fifo. It also
  30. * is where I lifted in2000_biosparam(), the gist of the card
  31. * detection scheme, and other bits of code. Many thanks to the
  32. * talented and courageous people who wrote, contributed to, and
  33. * maintained that driver (including Brad McLean, Shaun Savage,
  34. * Bill Earnest, Larry Doolittle, Roger Sunshine, John Luckey,
  35. * Matt Postiff, Peter Lu, zerucha@shell.portal.com, and Eric
  36. * Youngdale). I should also mention the driver written by
  37. * Hamish Macdonald for the (GASP!) Amiga A2091 card, included
  38. * in the Linux-m68k distribution; it gave me a good initial
  39. * understanding of the proper way to run a WD33c93 chip, and I
  40. * ended up stealing lots of code from it.
  41. *
  42. * _This_ driver is (I feel) an improvement over the old one in
  43. * several respects:
  44. * - All problems relating to the data size of a SCSI request are
  45. * gone (as far as I know). The old driver couldn't handle
  46. * swapping to partitions because that involved 4k blocks, nor
  47. * could it deal with the st.c tape driver unmodified, because
  48. * that usually involved 4k - 32k blocks. The old driver never
  49. * quite got away from a morbid dependence on 2k block sizes -
  50. * which of course is the size of the card's fifo.
  51. *
  52. * - Target Disconnection/Reconnection is now supported. Any
  53. * system with more than one device active on the SCSI bus
  54. * will benefit from this. The driver defaults to what I'm
  55. * calling 'adaptive disconnect' - meaning that each command
  56. * is evaluated individually as to whether or not it should
  57. * be run with the option to disconnect/reselect (if the
  58. * device chooses), or as a "SCSI-bus-hog".
  59. *
  60. * - Synchronous data transfers are now supported. Because there
  61. * are a few devices (and many improperly terminated systems)
  62. * that choke when doing sync, the default is sync DISABLED
  63. * for all devices. This faster protocol can (and should!)
  64. * be enabled on selected devices via the command-line.
  65. *
  66. * - Runtime operating parameters can now be specified through
  67. * either the LILO or the 'insmod' command line. For LILO do:
  68. * "in2000=blah,blah,blah"
  69. * and with insmod go like:
  70. * "insmod /usr/src/linux/modules/in2000.o setup_strings=blah,blah"
  71. * The defaults should be good for most people. See the comment
  72. * for 'setup_strings' below for more details.
  73. *
  74. * - The old driver relied exclusively on what the Western Digital
  75. * docs call "Combination Level 2 Commands", which are a great
  76. * idea in that the CPU is relieved of a lot of interrupt
  77. * overhead. However, by accepting a certain (user-settable)
  78. * amount of additional interrupts, this driver achieves
  79. * better control over the SCSI bus, and data transfers are
  80. * almost as fast while being much easier to define, track,
  81. * and debug.
  82. *
  83. * - You can force detection of a card whose BIOS has been disabled.
  84. *
  85. * - Multiple IN2000 cards might almost be supported. I've tried to
  86. * keep it in mind, but have no way to test...
  87. *
  88. *
  89. * TODO:
  90. * tagged queuing. multiple cards.
  91. *
  92. *
  93. * NOTE:
  94. * When using this or any other SCSI driver as a module, you'll
  95. * find that with the stock kernel, at most _two_ SCSI hard
  96. * drives will be linked into the device list (ie, usable).
  97. * If your IN2000 card has more than 2 disks on its bus, you
  98. * might want to change the define of 'SD_EXTRA_DEVS' in the
  99. * 'hosts.h' file from 2 to whatever is appropriate. It took
  100. * me a while to track down this surprisingly obscure and
  101. * undocumented little "feature".
  102. *
  103. *
  104. * People with bug reports, wish-lists, complaints, comments,
  105. * or improvements are asked to pah-leeez email me (John Shifflett)
  106. * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
  107. * this thing into as good a shape as possible, and I'm positive
  108. * there are lots of lurking bugs and "Stupid Places".
  109. *
  110. * Updated for Linux 2.5 by Alan Cox <alan@lxorguk.ukuu.org.uk>
  111. * - Using new_eh handler
  112. * - Hopefully got all the locking right again
  113. * See "FIXME" notes for items that could do with more work
  114. */
  115. #include <linux/module.h>
  116. #include <linux/blkdev.h>
  117. #include <linux/interrupt.h>
  118. #include <linux/string.h>
  119. #include <linux/delay.h>
  120. #include <linux/proc_fs.h>
  121. #include <linux/ioport.h>
  122. #include <linux/stat.h>
  123. #include <asm/io.h>
  124. #include "scsi.h"
  125. #include <scsi/scsi_host.h>
  126. #define IN2000_VERSION "1.33-2.5"
  127. #define IN2000_DATE "2002/11/03"
  128. #include "in2000.h"
  129. /*
  130. * 'setup_strings' is a single string used to pass operating parameters and
  131. * settings from the kernel/module command-line to the driver. 'setup_args[]'
  132. * is an array of strings that define the compile-time default values for
  133. * these settings. If Linux boots with a LILO or insmod command-line, those
  134. * settings are combined with 'setup_args[]'. Note that LILO command-lines
  135. * are prefixed with "in2000=" while insmod uses a "setup_strings=" prefix.
  136. * The driver recognizes the following keywords (lower case required) and
  137. * arguments:
  138. *
  139. * - ioport:addr -Where addr is IO address of a (usually ROM-less) card.
  140. * - noreset -No optional args. Prevents SCSI bus reset at boot time.
  141. * - nosync:x -x is a bitmask where the 1st 7 bits correspond with
  142. * the 7 possible SCSI devices (bit 0 for device #0, etc).
  143. * Set a bit to PREVENT sync negotiation on that device.
  144. * The driver default is sync DISABLED on all devices.
  145. * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
  146. * period. Default is 500; acceptable values are 250 - 1000.
  147. * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
  148. * x = 1 does 'adaptive' disconnects, which is the default
  149. * and generally the best choice.
  150. * - debug:x -If 'DEBUGGING_ON' is defined, x is a bitmask that causes
  151. * various types of debug output to printed - see the DB_xxx
  152. * defines in in2000.h
  153. * - proc:x -If 'PROC_INTERFACE' is defined, x is a bitmask that
  154. * determines how the /proc interface works and what it
  155. * does - see the PR_xxx defines in in2000.h
  156. *
  157. * Syntax Notes:
  158. * - Numeric arguments can be decimal or the '0x' form of hex notation. There
  159. * _must_ be a colon between a keyword and its numeric argument, with no
  160. * spaces.
  161. * - Keywords are separated by commas, no spaces, in the standard kernel
  162. * command-line manner.
  163. * - A keyword in the 'nth' comma-separated command-line member will overwrite
  164. * the 'nth' element of setup_args[]. A blank command-line member (in
  165. * other words, a comma with no preceding keyword) will _not_ overwrite
  166. * the corresponding setup_args[] element.
  167. *
  168. * A few LILO examples (for insmod, use 'setup_strings' instead of 'in2000'):
  169. * - in2000=ioport:0x220,noreset
  170. * - in2000=period:250,disconnect:2,nosync:0x03
  171. * - in2000=debug:0x1e
  172. * - in2000=proc:3
  173. */
  174. /* Normally, no defaults are specified... */
  175. static char *setup_args[] = { "", "", "", "", "", "", "", "", "" };
  176. /* filled in by 'insmod' */
  177. static char *setup_strings;
  178. module_param(setup_strings, charp, 0);
  179. static inline uchar read_3393(struct IN2000_hostdata *hostdata, uchar reg_num)
  180. {
  181. write1_io(reg_num, IO_WD_ADDR);
  182. return read1_io(IO_WD_DATA);
  183. }
  184. #define READ_AUX_STAT() read1_io(IO_WD_ASR)
  185. static inline void write_3393(struct IN2000_hostdata *hostdata, uchar reg_num, uchar value)
  186. {
  187. write1_io(reg_num, IO_WD_ADDR);
  188. write1_io(value, IO_WD_DATA);
  189. }
  190. static inline void write_3393_cmd(struct IN2000_hostdata *hostdata, uchar cmd)
  191. {
  192. /* while (READ_AUX_STAT() & ASR_CIP)
  193. printk("|");*/
  194. write1_io(WD_COMMAND, IO_WD_ADDR);
  195. write1_io(cmd, IO_WD_DATA);
  196. }
  197. static uchar read_1_byte(struct IN2000_hostdata *hostdata)
  198. {
  199. uchar asr, x = 0;
  200. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  201. write_3393_cmd(hostdata, WD_CMD_TRANS_INFO | 0x80);
  202. do {
  203. asr = READ_AUX_STAT();
  204. if (asr & ASR_DBR)
  205. x = read_3393(hostdata, WD_DATA);
  206. } while (!(asr & ASR_INT));
  207. return x;
  208. }
  209. static void write_3393_count(struct IN2000_hostdata *hostdata, unsigned long value)
  210. {
  211. write1_io(WD_TRANSFER_COUNT_MSB, IO_WD_ADDR);
  212. write1_io((value >> 16), IO_WD_DATA);
  213. write1_io((value >> 8), IO_WD_DATA);
  214. write1_io(value, IO_WD_DATA);
  215. }
  216. static unsigned long read_3393_count(struct IN2000_hostdata *hostdata)
  217. {
  218. unsigned long value;
  219. write1_io(WD_TRANSFER_COUNT_MSB, IO_WD_ADDR);
  220. value = read1_io(IO_WD_DATA) << 16;
  221. value |= read1_io(IO_WD_DATA) << 8;
  222. value |= read1_io(IO_WD_DATA);
  223. return value;
  224. }
  225. /* The 33c93 needs to be told which direction a command transfers its
  226. * data; we use this function to figure it out. Returns true if there
  227. * will be a DATA_OUT phase with this command, false otherwise.
  228. * (Thanks to Joerg Dorchain for the research and suggestion.)
  229. */
  230. static int is_dir_out(Scsi_Cmnd * cmd)
  231. {
  232. switch (cmd->cmnd[0]) {
  233. case WRITE_6:
  234. case WRITE_10:
  235. case WRITE_12:
  236. case WRITE_LONG:
  237. case WRITE_SAME:
  238. case WRITE_BUFFER:
  239. case WRITE_VERIFY:
  240. case WRITE_VERIFY_12:
  241. case COMPARE:
  242. case COPY:
  243. case COPY_VERIFY:
  244. case SEARCH_EQUAL:
  245. case SEARCH_HIGH:
  246. case SEARCH_LOW:
  247. case SEARCH_EQUAL_12:
  248. case SEARCH_HIGH_12:
  249. case SEARCH_LOW_12:
  250. case FORMAT_UNIT:
  251. case REASSIGN_BLOCKS:
  252. case RESERVE:
  253. case MODE_SELECT:
  254. case MODE_SELECT_10:
  255. case LOG_SELECT:
  256. case SEND_DIAGNOSTIC:
  257. case CHANGE_DEFINITION:
  258. case UPDATE_BLOCK:
  259. case SET_WINDOW:
  260. case MEDIUM_SCAN:
  261. case SEND_VOLUME_TAG:
  262. case 0xea:
  263. return 1;
  264. default:
  265. return 0;
  266. }
  267. }
  268. static struct sx_period sx_table[] = {
  269. {1, 0x20},
  270. {252, 0x20},
  271. {376, 0x30},
  272. {500, 0x40},
  273. {624, 0x50},
  274. {752, 0x60},
  275. {876, 0x70},
  276. {1000, 0x00},
  277. {0, 0}
  278. };
  279. static int round_period(unsigned int period)
  280. {
  281. int x;
  282. for (x = 1; sx_table[x].period_ns; x++) {
  283. if ((period <= sx_table[x - 0].period_ns) && (period > sx_table[x - 1].period_ns)) {
  284. return x;
  285. }
  286. }
  287. return 7;
  288. }
  289. static uchar calc_sync_xfer(unsigned int period, unsigned int offset)
  290. {
  291. uchar result;
  292. period *= 4; /* convert SDTR code to ns */
  293. result = sx_table[round_period(period)].reg_value;
  294. result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF;
  295. return result;
  296. }
  297. static void in2000_execute(struct Scsi_Host *instance);
  298. static int in2000_queuecommand_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
  299. {
  300. struct Scsi_Host *instance;
  301. struct IN2000_hostdata *hostdata;
  302. Scsi_Cmnd *tmp;
  303. instance = cmd->device->host;
  304. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  305. DB(DB_QUEUE_COMMAND, scmd_printk(KERN_DEBUG, cmd, "Q-%02x(", cmd->cmnd[0]))
  306. /* Set up a few fields in the Scsi_Cmnd structure for our own use:
  307. * - host_scribble is the pointer to the next cmd in the input queue
  308. * - scsi_done points to the routine we call when a cmd is finished
  309. * - result is what you'd expect
  310. */
  311. cmd->host_scribble = NULL;
  312. cmd->scsi_done = done;
  313. cmd->result = 0;
  314. /* We use the Scsi_Pointer structure that's included with each command
  315. * as a scratchpad (as it's intended to be used!). The handy thing about
  316. * the SCp.xxx fields is that they're always associated with a given
  317. * cmd, and are preserved across disconnect-reselect. This means we
  318. * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
  319. * if we keep all the critical pointers and counters in SCp:
  320. * - SCp.ptr is the pointer into the RAM buffer
  321. * - SCp.this_residual is the size of that buffer
  322. * - SCp.buffer points to the current scatter-gather buffer
  323. * - SCp.buffers_residual tells us how many S.G. buffers there are
  324. * - SCp.have_data_in helps keep track of >2048 byte transfers
  325. * - SCp.sent_command is not used
  326. * - SCp.phase records this command's SRCID_ER bit setting
  327. */
  328. if (scsi_bufflen(cmd)) {
  329. cmd->SCp.buffer = scsi_sglist(cmd);
  330. cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
  331. cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
  332. cmd->SCp.this_residual = cmd->SCp.buffer->length;
  333. } else {
  334. cmd->SCp.buffer = NULL;
  335. cmd->SCp.buffers_residual = 0;
  336. cmd->SCp.ptr = NULL;
  337. cmd->SCp.this_residual = 0;
  338. }
  339. cmd->SCp.have_data_in = 0;
  340. /* We don't set SCp.phase here - that's done in in2000_execute() */
  341. /* WD docs state that at the conclusion of a "LEVEL2" command, the
  342. * status byte can be retrieved from the LUN register. Apparently,
  343. * this is the case only for *uninterrupted* LEVEL2 commands! If
  344. * there are any unexpected phases entered, even if they are 100%
  345. * legal (different devices may choose to do things differently),
  346. * the LEVEL2 command sequence is exited. This often occurs prior
  347. * to receiving the status byte, in which case the driver does a
  348. * status phase interrupt and gets the status byte on its own.
  349. * While such a command can then be "resumed" (ie restarted to
  350. * finish up as a LEVEL2 command), the LUN register will NOT be
  351. * a valid status byte at the command's conclusion, and we must
  352. * use the byte obtained during the earlier interrupt. Here, we
  353. * preset SCp.Status to an illegal value (0xff) so that when
  354. * this command finally completes, we can tell where the actual
  355. * status byte is stored.
  356. */
  357. cmd->SCp.Status = ILLEGAL_STATUS_BYTE;
  358. /* We need to disable interrupts before messing with the input
  359. * queue and calling in2000_execute().
  360. */
  361. /*
  362. * Add the cmd to the end of 'input_Q'. Note that REQUEST_SENSE
  363. * commands are added to the head of the queue so that the desired
  364. * sense data is not lost before REQUEST_SENSE executes.
  365. */
  366. if (!(hostdata->input_Q) || (cmd->cmnd[0] == REQUEST_SENSE)) {
  367. cmd->host_scribble = (uchar *) hostdata->input_Q;
  368. hostdata->input_Q = cmd;
  369. } else { /* find the end of the queue */
  370. for (tmp = (Scsi_Cmnd *) hostdata->input_Q; tmp->host_scribble; tmp = (Scsi_Cmnd *) tmp->host_scribble);
  371. tmp->host_scribble = (uchar *) cmd;
  372. }
  373. /* We know that there's at least one command in 'input_Q' now.
  374. * Go see if any of them are runnable!
  375. */
  376. in2000_execute(cmd->device->host);
  377. DB(DB_QUEUE_COMMAND, printk(")Q "))
  378. return 0;
  379. }
  380. static DEF_SCSI_QCMD(in2000_queuecommand)
  381. /*
  382. * This routine attempts to start a scsi command. If the host_card is
  383. * already connected, we give up immediately. Otherwise, look through
  384. * the input_Q, using the first command we find that's intended
  385. * for a currently non-busy target/lun.
  386. * Note that this function is always called with interrupts already
  387. * disabled (either from in2000_queuecommand() or in2000_intr()).
  388. */
  389. static void in2000_execute(struct Scsi_Host *instance)
  390. {
  391. struct IN2000_hostdata *hostdata;
  392. Scsi_Cmnd *cmd, *prev;
  393. int i;
  394. unsigned short *sp;
  395. unsigned short f;
  396. unsigned short flushbuf[16];
  397. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  398. DB(DB_EXECUTE, printk("EX("))
  399. if (hostdata->selecting || hostdata->connected) {
  400. DB(DB_EXECUTE, printk(")EX-0 "))
  401. return;
  402. }
  403. /*
  404. * Search through the input_Q for a command destined
  405. * for an idle target/lun.
  406. */
  407. cmd = (Scsi_Cmnd *) hostdata->input_Q;
  408. prev = NULL;
  409. while (cmd) {
  410. if (!(hostdata->busy[cmd->device->id] & (1 << cmd->device->lun)))
  411. break;
  412. prev = cmd;
  413. cmd = (Scsi_Cmnd *) cmd->host_scribble;
  414. }
  415. /* quit if queue empty or all possible targets are busy */
  416. if (!cmd) {
  417. DB(DB_EXECUTE, printk(")EX-1 "))
  418. return;
  419. }
  420. /* remove command from queue */
  421. if (prev)
  422. prev->host_scribble = cmd->host_scribble;
  423. else
  424. hostdata->input_Q = (Scsi_Cmnd *) cmd->host_scribble;
  425. #ifdef PROC_STATISTICS
  426. hostdata->cmd_cnt[cmd->device->id]++;
  427. #endif
  428. /*
  429. * Start the selection process
  430. */
  431. if (is_dir_out(cmd))
  432. write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id);
  433. else
  434. write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD);
  435. /* Now we need to figure out whether or not this command is a good
  436. * candidate for disconnect/reselect. We guess to the best of our
  437. * ability, based on a set of hierarchical rules. When several
  438. * devices are operating simultaneously, disconnects are usually
  439. * an advantage. In a single device system, or if only 1 device
  440. * is being accessed, transfers usually go faster if disconnects
  441. * are not allowed:
  442. *
  443. * + Commands should NEVER disconnect if hostdata->disconnect =
  444. * DIS_NEVER (this holds for tape drives also), and ALWAYS
  445. * disconnect if hostdata->disconnect = DIS_ALWAYS.
  446. * + Tape drive commands should always be allowed to disconnect.
  447. * + Disconnect should be allowed if disconnected_Q isn't empty.
  448. * + Commands should NOT disconnect if input_Q is empty.
  449. * + Disconnect should be allowed if there are commands in input_Q
  450. * for a different target/lun. In this case, the other commands
  451. * should be made disconnect-able, if not already.
  452. *
  453. * I know, I know - this code would flunk me out of any
  454. * "C Programming 101" class ever offered. But it's easy
  455. * to change around and experiment with for now.
  456. */
  457. cmd->SCp.phase = 0; /* assume no disconnect */
  458. if (hostdata->disconnect == DIS_NEVER)
  459. goto no;
  460. if (hostdata->disconnect == DIS_ALWAYS)
  461. goto yes;
  462. if (cmd->device->type == 1) /* tape drive? */
  463. goto yes;
  464. if (hostdata->disconnected_Q) /* other commands disconnected? */
  465. goto yes;
  466. if (!(hostdata->input_Q)) /* input_Q empty? */
  467. goto no;
  468. for (prev = (Scsi_Cmnd *) hostdata->input_Q; prev; prev = (Scsi_Cmnd *) prev->host_scribble) {
  469. if ((prev->device->id != cmd->device->id) || (prev->device->lun != cmd->device->lun)) {
  470. for (prev = (Scsi_Cmnd *) hostdata->input_Q; prev; prev = (Scsi_Cmnd *) prev->host_scribble)
  471. prev->SCp.phase = 1;
  472. goto yes;
  473. }
  474. }
  475. goto no;
  476. yes:
  477. cmd->SCp.phase = 1;
  478. #ifdef PROC_STATISTICS
  479. hostdata->disc_allowed_cnt[cmd->device->id]++;
  480. #endif
  481. no:
  482. write_3393(hostdata, WD_SOURCE_ID, ((cmd->SCp.phase) ? SRCID_ER : 0));
  483. write_3393(hostdata, WD_TARGET_LUN, cmd->device->lun);
  484. write_3393(hostdata, WD_SYNCHRONOUS_TRANSFER, hostdata->sync_xfer[cmd->device->id]);
  485. hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
  486. if ((hostdata->level2 <= L2_NONE) || (hostdata->sync_stat[cmd->device->id] == SS_UNSET)) {
  487. /*
  488. * Do a 'Select-With-ATN' command. This will end with
  489. * one of the following interrupts:
  490. * CSR_RESEL_AM: failure - can try again later.
  491. * CSR_TIMEOUT: failure - give up.
  492. * CSR_SELECT: success - proceed.
  493. */
  494. hostdata->selecting = cmd;
  495. /* Every target has its own synchronous transfer setting, kept in
  496. * the sync_xfer array, and a corresponding status byte in sync_stat[].
  497. * Each target's sync_stat[] entry is initialized to SS_UNSET, and its
  498. * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
  499. * means that the parameters are undetermined as yet, and that we
  500. * need to send an SDTR message to this device after selection is
  501. * complete. We set SS_FIRST to tell the interrupt routine to do so,
  502. * unless we don't want to even _try_ synchronous transfers: In this
  503. * case we set SS_SET to make the defaults final.
  504. */
  505. if (hostdata->sync_stat[cmd->device->id] == SS_UNSET) {
  506. if (hostdata->sync_off & (1 << cmd->device->id))
  507. hostdata->sync_stat[cmd->device->id] = SS_SET;
  508. else
  509. hostdata->sync_stat[cmd->device->id] = SS_FIRST;
  510. }
  511. hostdata->state = S_SELECTING;
  512. write_3393_count(hostdata, 0); /* this guarantees a DATA_PHASE interrupt */
  513. write_3393_cmd(hostdata, WD_CMD_SEL_ATN);
  514. }
  515. else {
  516. /*
  517. * Do a 'Select-With-ATN-Xfer' command. This will end with
  518. * one of the following interrupts:
  519. * CSR_RESEL_AM: failure - can try again later.
  520. * CSR_TIMEOUT: failure - give up.
  521. * anything else: success - proceed.
  522. */
  523. hostdata->connected = cmd;
  524. write_3393(hostdata, WD_COMMAND_PHASE, 0);
  525. /* copy command_descriptor_block into WD chip
  526. * (take advantage of auto-incrementing)
  527. */
  528. write1_io(WD_CDB_1, IO_WD_ADDR);
  529. for (i = 0; i < cmd->cmd_len; i++)
  530. write1_io(cmd->cmnd[i], IO_WD_DATA);
  531. /* The wd33c93 only knows about Group 0, 1, and 5 commands when
  532. * it's doing a 'select-and-transfer'. To be safe, we write the
  533. * size of the CDB into the OWN_ID register for every case. This
  534. * way there won't be problems with vendor-unique, audio, etc.
  535. */
  536. write_3393(hostdata, WD_OWN_ID, cmd->cmd_len);
  537. /* When doing a non-disconnect command, we can save ourselves a DATA
  538. * phase interrupt later by setting everything up now. With writes we
  539. * need to pre-fill the fifo; if there's room for the 32 flush bytes,
  540. * put them in there too - that'll avoid a fifo interrupt. Reads are
  541. * somewhat simpler.
  542. * KLUDGE NOTE: It seems that you can't completely fill the fifo here:
  543. * This results in the IO_FIFO_COUNT register rolling over to zero,
  544. * and apparently the gate array logic sees this as empty, not full,
  545. * so the 3393 chip is never signalled to start reading from the
  546. * fifo. Or maybe it's seen as a permanent fifo interrupt condition.
  547. * Regardless, we fix this by temporarily pretending that the fifo
  548. * is 16 bytes smaller. (I see now that the old driver has a comment
  549. * about "don't fill completely" in an analogous place - must be the
  550. * same deal.) This results in CDROM, swap partitions, and tape drives
  551. * needing an extra interrupt per write command - I think we can live
  552. * with that!
  553. */
  554. if (!(cmd->SCp.phase)) {
  555. write_3393_count(hostdata, cmd->SCp.this_residual);
  556. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_BUS);
  557. write1_io(0, IO_FIFO_WRITE); /* clear fifo counter, write mode */
  558. if (is_dir_out(cmd)) {
  559. hostdata->fifo = FI_FIFO_WRITING;
  560. if ((i = cmd->SCp.this_residual) > (IN2000_FIFO_SIZE - 16))
  561. i = IN2000_FIFO_SIZE - 16;
  562. cmd->SCp.have_data_in = i; /* this much data in fifo */
  563. i >>= 1; /* Gulp. Assuming modulo 2. */
  564. sp = (unsigned short *) cmd->SCp.ptr;
  565. f = hostdata->io_base + IO_FIFO;
  566. #ifdef FAST_WRITE_IO
  567. FAST_WRITE2_IO();
  568. #else
  569. while (i--)
  570. write2_io(*sp++, IO_FIFO);
  571. #endif
  572. /* Is there room for the flush bytes? */
  573. if (cmd->SCp.have_data_in <= ((IN2000_FIFO_SIZE - 16) - 32)) {
  574. sp = flushbuf;
  575. i = 16;
  576. #ifdef FAST_WRITE_IO
  577. FAST_WRITE2_IO();
  578. #else
  579. while (i--)
  580. write2_io(0, IO_FIFO);
  581. #endif
  582. }
  583. }
  584. else {
  585. write1_io(0, IO_FIFO_READ); /* put fifo in read mode */
  586. hostdata->fifo = FI_FIFO_READING;
  587. cmd->SCp.have_data_in = 0; /* nothing transferred yet */
  588. }
  589. } else {
  590. write_3393_count(hostdata, 0); /* this guarantees a DATA_PHASE interrupt */
  591. }
  592. hostdata->state = S_RUNNING_LEVEL2;
  593. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  594. }
  595. /*
  596. * Since the SCSI bus can handle only 1 connection at a time,
  597. * we get out of here now. If the selection fails, or when
  598. * the command disconnects, we'll come back to this routine
  599. * to search the input_Q again...
  600. */
  601. DB(DB_EXECUTE, printk("%s)EX-2 ", (cmd->SCp.phase) ? "d:" : ""))
  602. }
  603. static void transfer_pio(uchar * buf, int cnt, int data_in_dir, struct IN2000_hostdata *hostdata)
  604. {
  605. uchar asr;
  606. DB(DB_TRANSFER, printk("(%p,%d,%s)", buf, cnt, data_in_dir ? "in" : "out"))
  607. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  608. write_3393_count(hostdata, cnt);
  609. write_3393_cmd(hostdata, WD_CMD_TRANS_INFO);
  610. if (data_in_dir) {
  611. do {
  612. asr = READ_AUX_STAT();
  613. if (asr & ASR_DBR)
  614. *buf++ = read_3393(hostdata, WD_DATA);
  615. } while (!(asr & ASR_INT));
  616. } else {
  617. do {
  618. asr = READ_AUX_STAT();
  619. if (asr & ASR_DBR)
  620. write_3393(hostdata, WD_DATA, *buf++);
  621. } while (!(asr & ASR_INT));
  622. }
  623. /* Note: we are returning with the interrupt UN-cleared.
  624. * Since (presumably) an entire I/O operation has
  625. * completed, the bus phase is probably different, and
  626. * the interrupt routine will discover this when it
  627. * responds to the uncleared int.
  628. */
  629. }
  630. static void transfer_bytes(Scsi_Cmnd * cmd, int data_in_dir)
  631. {
  632. struct IN2000_hostdata *hostdata;
  633. unsigned short *sp;
  634. unsigned short f;
  635. int i;
  636. hostdata = (struct IN2000_hostdata *) cmd->device->host->hostdata;
  637. /* Normally, you'd expect 'this_residual' to be non-zero here.
  638. * In a series of scatter-gather transfers, however, this
  639. * routine will usually be called with 'this_residual' equal
  640. * to 0 and 'buffers_residual' non-zero. This means that a
  641. * previous transfer completed, clearing 'this_residual', and
  642. * now we need to setup the next scatter-gather buffer as the
  643. * source or destination for THIS transfer.
  644. */
  645. if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
  646. ++cmd->SCp.buffer;
  647. --cmd->SCp.buffers_residual;
  648. cmd->SCp.this_residual = cmd->SCp.buffer->length;
  649. cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
  650. }
  651. /* Set up hardware registers */
  652. write_3393(hostdata, WD_SYNCHRONOUS_TRANSFER, hostdata->sync_xfer[cmd->device->id]);
  653. write_3393_count(hostdata, cmd->SCp.this_residual);
  654. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_BUS);
  655. write1_io(0, IO_FIFO_WRITE); /* zero counter, assume write */
  656. /* Reading is easy. Just issue the command and return - we'll
  657. * get an interrupt later when we have actual data to worry about.
  658. */
  659. if (data_in_dir) {
  660. write1_io(0, IO_FIFO_READ);
  661. if ((hostdata->level2 >= L2_DATA) || (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) {
  662. write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
  663. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  664. hostdata->state = S_RUNNING_LEVEL2;
  665. } else
  666. write_3393_cmd(hostdata, WD_CMD_TRANS_INFO);
  667. hostdata->fifo = FI_FIFO_READING;
  668. cmd->SCp.have_data_in = 0;
  669. return;
  670. }
  671. /* Writing is more involved - we'll start the WD chip and write as
  672. * much data to the fifo as we can right now. Later interrupts will
  673. * write any bytes that don't make it at this stage.
  674. */
  675. if ((hostdata->level2 >= L2_DATA) || (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) {
  676. write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
  677. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  678. hostdata->state = S_RUNNING_LEVEL2;
  679. } else
  680. write_3393_cmd(hostdata, WD_CMD_TRANS_INFO);
  681. hostdata->fifo = FI_FIFO_WRITING;
  682. sp = (unsigned short *) cmd->SCp.ptr;
  683. if ((i = cmd->SCp.this_residual) > IN2000_FIFO_SIZE)
  684. i = IN2000_FIFO_SIZE;
  685. cmd->SCp.have_data_in = i;
  686. i >>= 1; /* Gulp. We assume this_residual is modulo 2 */
  687. f = hostdata->io_base + IO_FIFO;
  688. #ifdef FAST_WRITE_IO
  689. FAST_WRITE2_IO();
  690. #else
  691. while (i--)
  692. write2_io(*sp++, IO_FIFO);
  693. #endif
  694. }
  695. /* We need to use spin_lock_irqsave() & spin_unlock_irqrestore() in this
  696. * function in order to work in an SMP environment. (I'd be surprised
  697. * if the driver is ever used by anyone on a real multi-CPU motherboard,
  698. * but it _does_ need to be able to compile and run in an SMP kernel.)
  699. */
  700. static irqreturn_t in2000_intr(int irqnum, void *dev_id)
  701. {
  702. struct Scsi_Host *instance = dev_id;
  703. struct IN2000_hostdata *hostdata;
  704. Scsi_Cmnd *patch, *cmd;
  705. uchar asr, sr, phs, id, lun, *ucp, msg;
  706. int i, j;
  707. unsigned long length;
  708. unsigned short *sp;
  709. unsigned short f;
  710. unsigned long flags;
  711. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  712. /* Get the spin_lock and disable further ints, for SMP */
  713. spin_lock_irqsave(instance->host_lock, flags);
  714. #ifdef PROC_STATISTICS
  715. hostdata->int_cnt++;
  716. #endif
  717. /* The IN2000 card has 2 interrupt sources OR'ed onto its IRQ line - the
  718. * WD3393 chip and the 2k fifo (which is actually a dual-port RAM combined
  719. * with a big logic array, so it's a little different than what you might
  720. * expect). As far as I know, there's no reason that BOTH can't be active
  721. * at the same time, but there's a problem: while we can read the 3393
  722. * to tell if _it_ wants an interrupt, I don't know of a way to ask the
  723. * fifo the same question. The best we can do is check the 3393 and if
  724. * it _isn't_ the source of the interrupt, then we can be pretty sure
  725. * that the fifo is the culprit.
  726. * UPDATE: I have it on good authority (Bill Earnest) that bit 0 of the
  727. * IO_FIFO_COUNT register mirrors the fifo interrupt state. I
  728. * assume that bit clear means interrupt active. As it turns
  729. * out, the driver really doesn't need to check for this after
  730. * all, so my remarks above about a 'problem' can safely be
  731. * ignored. The way the logic is set up, there's no advantage
  732. * (that I can see) to worrying about it.
  733. *
  734. * It seems that the fifo interrupt signal is negated when we extract
  735. * bytes during read or write bytes during write.
  736. * - fifo will interrupt when data is moving from it to the 3393, and
  737. * there are 31 (or less?) bytes left to go. This is sort of short-
  738. * sighted: what if you don't WANT to do more? In any case, our
  739. * response is to push more into the fifo - either actual data or
  740. * dummy bytes if need be. Note that we apparently have to write at
  741. * least 32 additional bytes to the fifo after an interrupt in order
  742. * to get it to release the ones it was holding on to - writing fewer
  743. * than 32 will result in another fifo int.
  744. * UPDATE: Again, info from Bill Earnest makes this more understandable:
  745. * 32 bytes = two counts of the fifo counter register. He tells
  746. * me that the fifo interrupt is a non-latching signal derived
  747. * from a straightforward boolean interpretation of the 7
  748. * highest bits of the fifo counter and the fifo-read/fifo-write
  749. * state. Who'd a thought?
  750. */
  751. write1_io(0, IO_LED_ON);
  752. asr = READ_AUX_STAT();
  753. if (!(asr & ASR_INT)) { /* no WD33c93 interrupt? */
  754. /* Ok. This is definitely a FIFO-only interrupt.
  755. *
  756. * If FI_FIFO_READING is set, there are up to 2048 bytes waiting to be read,
  757. * maybe more to come from the SCSI bus. Read as many as we can out of the
  758. * fifo and into memory at the location of SCp.ptr[SCp.have_data_in], and
  759. * update have_data_in afterwards.
  760. *
  761. * If we have FI_FIFO_WRITING, the FIFO has almost run out of bytes to move
  762. * into the WD3393 chip (I think the interrupt happens when there are 31
  763. * bytes left, but it may be fewer...). The 3393 is still waiting, so we
  764. * shove some more into the fifo, which gets things moving again. If the
  765. * original SCSI command specified more than 2048 bytes, there may still
  766. * be some of that data left: fine - use it (from SCp.ptr[SCp.have_data_in]).
  767. * Don't forget to update have_data_in. If we've already written out the
  768. * entire buffer, feed 32 dummy bytes to the fifo - they're needed to
  769. * push out the remaining real data.
  770. * (Big thanks to Bill Earnest for getting me out of the mud in here.)
  771. */
  772. cmd = (Scsi_Cmnd *) hostdata->connected; /* assume we're connected */
  773. CHECK_NULL(cmd, "fifo_int")
  774. if (hostdata->fifo == FI_FIFO_READING) {
  775. DB(DB_FIFO, printk("{R:%02x} ", read1_io(IO_FIFO_COUNT)))
  776. sp = (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
  777. i = read1_io(IO_FIFO_COUNT) & 0xfe;
  778. i <<= 2; /* # of words waiting in the fifo */
  779. f = hostdata->io_base + IO_FIFO;
  780. #ifdef FAST_READ_IO
  781. FAST_READ2_IO();
  782. #else
  783. while (i--)
  784. *sp++ = read2_io(IO_FIFO);
  785. #endif
  786. i = sp - (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
  787. i <<= 1;
  788. cmd->SCp.have_data_in += i;
  789. }
  790. else if (hostdata->fifo == FI_FIFO_WRITING) {
  791. DB(DB_FIFO, printk("{W:%02x} ", read1_io(IO_FIFO_COUNT)))
  792. /* If all bytes have been written to the fifo, flush out the stragglers.
  793. * Note that while writing 16 dummy words seems arbitrary, we don't
  794. * have another choice that I can see. What we really want is to read
  795. * the 3393 transfer count register (that would tell us how many bytes
  796. * needed flushing), but the TRANSFER_INFO command hasn't completed
  797. * yet (not enough bytes!) and that register won't be accessible. So,
  798. * we use 16 words - a number obtained through trial and error.
  799. * UPDATE: Bill says this is exactly what Always does, so there.
  800. * More thanks due him for help in this section.
  801. */
  802. if (cmd->SCp.this_residual == cmd->SCp.have_data_in) {
  803. i = 16;
  804. while (i--) /* write 32 dummy bytes */
  805. write2_io(0, IO_FIFO);
  806. }
  807. /* If there are still bytes left in the SCSI buffer, write as many as we
  808. * can out to the fifo.
  809. */
  810. else {
  811. sp = (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
  812. i = cmd->SCp.this_residual - cmd->SCp.have_data_in; /* bytes yet to go */
  813. j = read1_io(IO_FIFO_COUNT) & 0xfe;
  814. j <<= 2; /* how many words the fifo has room for */
  815. if ((j << 1) > i)
  816. j = (i >> 1);
  817. while (j--)
  818. write2_io(*sp++, IO_FIFO);
  819. i = sp - (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
  820. i <<= 1;
  821. cmd->SCp.have_data_in += i;
  822. }
  823. }
  824. else {
  825. printk("*** Spurious FIFO interrupt ***");
  826. }
  827. write1_io(0, IO_LED_OFF);
  828. /* release the SMP spin_lock and restore irq state */
  829. spin_unlock_irqrestore(instance->host_lock, flags);
  830. return IRQ_HANDLED;
  831. }
  832. /* This interrupt was triggered by the WD33c93 chip. The fifo interrupt
  833. * may also be asserted, but we don't bother to check it: we get more
  834. * detailed info from FIFO_READING and FIFO_WRITING (see below).
  835. */
  836. cmd = (Scsi_Cmnd *) hostdata->connected; /* assume we're connected */
  837. sr = read_3393(hostdata, WD_SCSI_STATUS); /* clear the interrupt */
  838. phs = read_3393(hostdata, WD_COMMAND_PHASE);
  839. if (!cmd && (sr != CSR_RESEL_AM && sr != CSR_TIMEOUT && sr != CSR_SELECT)) {
  840. printk("\nNR:wd-intr-1\n");
  841. write1_io(0, IO_LED_OFF);
  842. /* release the SMP spin_lock and restore irq state */
  843. spin_unlock_irqrestore(instance->host_lock, flags);
  844. return IRQ_HANDLED;
  845. }
  846. DB(DB_INTR, printk("{%02x:%02x-", asr, sr))
  847. /* After starting a FIFO-based transfer, the next _WD3393_ interrupt is
  848. * guaranteed to be in response to the completion of the transfer.
  849. * If we were reading, there's probably data in the fifo that needs
  850. * to be copied into RAM - do that here. Also, we have to update
  851. * 'this_residual' and 'ptr' based on the contents of the
  852. * TRANSFER_COUNT register, in case the device decided to do an
  853. * intermediate disconnect (a device may do this if it has to
  854. * do a seek, or just to be nice and let other devices have
  855. * some bus time during long transfers).
  856. * After doing whatever is necessary with the fifo, we go on and
  857. * service the WD3393 interrupt normally.
  858. */
  859. if (hostdata->fifo == FI_FIFO_READING) {
  860. /* buffer index = start-of-buffer + #-of-bytes-already-read */
  861. sp = (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
  862. /* bytes remaining in fifo = (total-wanted - #-not-got) - #-already-read */
  863. i = (cmd->SCp.this_residual - read_3393_count(hostdata)) - cmd->SCp.have_data_in;
  864. i >>= 1; /* Gulp. We assume this will always be modulo 2 */
  865. f = hostdata->io_base + IO_FIFO;
  866. #ifdef FAST_READ_IO
  867. FAST_READ2_IO();
  868. #else
  869. while (i--)
  870. *sp++ = read2_io(IO_FIFO);
  871. #endif
  872. hostdata->fifo = FI_FIFO_UNUSED;
  873. length = cmd->SCp.this_residual;
  874. cmd->SCp.this_residual = read_3393_count(hostdata);
  875. cmd->SCp.ptr += (length - cmd->SCp.this_residual);
  876. DB(DB_TRANSFER, printk("(%p,%d)", cmd->SCp.ptr, cmd->SCp.this_residual))
  877. }
  878. else if (hostdata->fifo == FI_FIFO_WRITING) {
  879. hostdata->fifo = FI_FIFO_UNUSED;
  880. length = cmd->SCp.this_residual;
  881. cmd->SCp.this_residual = read_3393_count(hostdata);
  882. cmd->SCp.ptr += (length - cmd->SCp.this_residual);
  883. DB(DB_TRANSFER, printk("(%p,%d)", cmd->SCp.ptr, cmd->SCp.this_residual))
  884. }
  885. /* Respond to the specific WD3393 interrupt - there are quite a few! */
  886. switch (sr) {
  887. case CSR_TIMEOUT:
  888. DB(DB_INTR, printk("TIMEOUT"))
  889. if (hostdata->state == S_RUNNING_LEVEL2)
  890. hostdata->connected = NULL;
  891. else {
  892. cmd = (Scsi_Cmnd *) hostdata->selecting; /* get a valid cmd */
  893. CHECK_NULL(cmd, "csr_timeout")
  894. hostdata->selecting = NULL;
  895. }
  896. cmd->result = DID_NO_CONNECT << 16;
  897. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  898. hostdata->state = S_UNCONNECTED;
  899. cmd->scsi_done(cmd);
  900. /* We are not connected to a target - check to see if there
  901. * are commands waiting to be executed.
  902. */
  903. in2000_execute(instance);
  904. break;
  905. /* Note: this interrupt should not occur in a LEVEL2 command */
  906. case CSR_SELECT:
  907. DB(DB_INTR, printk("SELECT"))
  908. hostdata->connected = cmd = (Scsi_Cmnd *) hostdata->selecting;
  909. CHECK_NULL(cmd, "csr_select")
  910. hostdata->selecting = NULL;
  911. /* construct an IDENTIFY message with correct disconnect bit */
  912. hostdata->outgoing_msg[0] = (0x80 | 0x00 | cmd->device->lun);
  913. if (cmd->SCp.phase)
  914. hostdata->outgoing_msg[0] |= 0x40;
  915. if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) {
  916. #ifdef SYNC_DEBUG
  917. printk(" sending SDTR ");
  918. #endif
  919. hostdata->sync_stat[cmd->device->id] = SS_WAITING;
  920. /* tack on a 2nd message to ask about synchronous transfers */
  921. hostdata->outgoing_msg[1] = EXTENDED_MESSAGE;
  922. hostdata->outgoing_msg[2] = 3;
  923. hostdata->outgoing_msg[3] = EXTENDED_SDTR;
  924. hostdata->outgoing_msg[4] = OPTIMUM_SX_PER / 4;
  925. hostdata->outgoing_msg[5] = OPTIMUM_SX_OFF;
  926. hostdata->outgoing_len = 6;
  927. } else
  928. hostdata->outgoing_len = 1;
  929. hostdata->state = S_CONNECTED;
  930. break;
  931. case CSR_XFER_DONE | PHS_DATA_IN:
  932. case CSR_UNEXP | PHS_DATA_IN:
  933. case CSR_SRV_REQ | PHS_DATA_IN:
  934. DB(DB_INTR, printk("IN-%d.%d", cmd->SCp.this_residual, cmd->SCp.buffers_residual))
  935. transfer_bytes(cmd, DATA_IN_DIR);
  936. if (hostdata->state != S_RUNNING_LEVEL2)
  937. hostdata->state = S_CONNECTED;
  938. break;
  939. case CSR_XFER_DONE | PHS_DATA_OUT:
  940. case CSR_UNEXP | PHS_DATA_OUT:
  941. case CSR_SRV_REQ | PHS_DATA_OUT:
  942. DB(DB_INTR, printk("OUT-%d.%d", cmd->SCp.this_residual, cmd->SCp.buffers_residual))
  943. transfer_bytes(cmd, DATA_OUT_DIR);
  944. if (hostdata->state != S_RUNNING_LEVEL2)
  945. hostdata->state = S_CONNECTED;
  946. break;
  947. /* Note: this interrupt should not occur in a LEVEL2 command */
  948. case CSR_XFER_DONE | PHS_COMMAND:
  949. case CSR_UNEXP | PHS_COMMAND:
  950. case CSR_SRV_REQ | PHS_COMMAND:
  951. DB(DB_INTR, printk("CMND-%02x", cmd->cmnd[0]))
  952. transfer_pio(cmd->cmnd, cmd->cmd_len, DATA_OUT_DIR, hostdata);
  953. hostdata->state = S_CONNECTED;
  954. break;
  955. case CSR_XFER_DONE | PHS_STATUS:
  956. case CSR_UNEXP | PHS_STATUS:
  957. case CSR_SRV_REQ | PHS_STATUS:
  958. DB(DB_INTR, printk("STATUS="))
  959. cmd->SCp.Status = read_1_byte(hostdata);
  960. DB(DB_INTR, printk("%02x", cmd->SCp.Status))
  961. if (hostdata->level2 >= L2_BASIC) {
  962. sr = read_3393(hostdata, WD_SCSI_STATUS); /* clear interrupt */
  963. hostdata->state = S_RUNNING_LEVEL2;
  964. write_3393(hostdata, WD_COMMAND_PHASE, 0x50);
  965. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  966. } else {
  967. hostdata->state = S_CONNECTED;
  968. }
  969. break;
  970. case CSR_XFER_DONE | PHS_MESS_IN:
  971. case CSR_UNEXP | PHS_MESS_IN:
  972. case CSR_SRV_REQ | PHS_MESS_IN:
  973. DB(DB_INTR, printk("MSG_IN="))
  974. msg = read_1_byte(hostdata);
  975. sr = read_3393(hostdata, WD_SCSI_STATUS); /* clear interrupt */
  976. hostdata->incoming_msg[hostdata->incoming_ptr] = msg;
  977. if (hostdata->incoming_msg[0] == EXTENDED_MESSAGE)
  978. msg = EXTENDED_MESSAGE;
  979. else
  980. hostdata->incoming_ptr = 0;
  981. cmd->SCp.Message = msg;
  982. switch (msg) {
  983. case COMMAND_COMPLETE:
  984. DB(DB_INTR, printk("CCMP"))
  985. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  986. hostdata->state = S_PRE_CMP_DISC;
  987. break;
  988. case SAVE_POINTERS:
  989. DB(DB_INTR, printk("SDP"))
  990. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  991. hostdata->state = S_CONNECTED;
  992. break;
  993. case RESTORE_POINTERS:
  994. DB(DB_INTR, printk("RDP"))
  995. if (hostdata->level2 >= L2_BASIC) {
  996. write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
  997. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  998. hostdata->state = S_RUNNING_LEVEL2;
  999. } else {
  1000. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1001. hostdata->state = S_CONNECTED;
  1002. }
  1003. break;
  1004. case DISCONNECT:
  1005. DB(DB_INTR, printk("DIS"))
  1006. cmd->device->disconnect = 1;
  1007. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1008. hostdata->state = S_PRE_TMP_DISC;
  1009. break;
  1010. case MESSAGE_REJECT:
  1011. DB(DB_INTR, printk("REJ"))
  1012. #ifdef SYNC_DEBUG
  1013. printk("-REJ-");
  1014. #endif
  1015. if (hostdata->sync_stat[cmd->device->id] == SS_WAITING)
  1016. hostdata->sync_stat[cmd->device->id] = SS_SET;
  1017. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1018. hostdata->state = S_CONNECTED;
  1019. break;
  1020. case EXTENDED_MESSAGE:
  1021. DB(DB_INTR, printk("EXT"))
  1022. ucp = hostdata->incoming_msg;
  1023. #ifdef SYNC_DEBUG
  1024. printk("%02x", ucp[hostdata->incoming_ptr]);
  1025. #endif
  1026. /* Is this the last byte of the extended message? */
  1027. if ((hostdata->incoming_ptr >= 2) && (hostdata->incoming_ptr == (ucp[1] + 1))) {
  1028. switch (ucp[2]) { /* what's the EXTENDED code? */
  1029. case EXTENDED_SDTR:
  1030. id = calc_sync_xfer(ucp[3], ucp[4]);
  1031. if (hostdata->sync_stat[cmd->device->id] != SS_WAITING) {
  1032. /* A device has sent an unsolicited SDTR message; rather than go
  1033. * through the effort of decoding it and then figuring out what
  1034. * our reply should be, we're just gonna say that we have a
  1035. * synchronous fifo depth of 0. This will result in asynchronous
  1036. * transfers - not ideal but so much easier.
  1037. * Actually, this is OK because it assures us that if we don't
  1038. * specifically ask for sync transfers, we won't do any.
  1039. */
  1040. write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  1041. hostdata->outgoing_msg[0] = EXTENDED_MESSAGE;
  1042. hostdata->outgoing_msg[1] = 3;
  1043. hostdata->outgoing_msg[2] = EXTENDED_SDTR;
  1044. hostdata->outgoing_msg[3] = hostdata->default_sx_per / 4;
  1045. hostdata->outgoing_msg[4] = 0;
  1046. hostdata->outgoing_len = 5;
  1047. hostdata->sync_xfer[cmd->device->id] = calc_sync_xfer(hostdata->default_sx_per / 4, 0);
  1048. } else {
  1049. hostdata->sync_xfer[cmd->device->id] = id;
  1050. }
  1051. #ifdef SYNC_DEBUG
  1052. printk("sync_xfer=%02x", hostdata->sync_xfer[cmd->device->id]);
  1053. #endif
  1054. hostdata->sync_stat[cmd->device->id] = SS_SET;
  1055. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1056. hostdata->state = S_CONNECTED;
  1057. break;
  1058. case EXTENDED_WDTR:
  1059. write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  1060. printk("sending WDTR ");
  1061. hostdata->outgoing_msg[0] = EXTENDED_MESSAGE;
  1062. hostdata->outgoing_msg[1] = 2;
  1063. hostdata->outgoing_msg[2] = EXTENDED_WDTR;
  1064. hostdata->outgoing_msg[3] = 0; /* 8 bit transfer width */
  1065. hostdata->outgoing_len = 4;
  1066. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1067. hostdata->state = S_CONNECTED;
  1068. break;
  1069. default:
  1070. write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  1071. printk("Rejecting Unknown Extended Message(%02x). ", ucp[2]);
  1072. hostdata->outgoing_msg[0] = MESSAGE_REJECT;
  1073. hostdata->outgoing_len = 1;
  1074. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1075. hostdata->state = S_CONNECTED;
  1076. break;
  1077. }
  1078. hostdata->incoming_ptr = 0;
  1079. }
  1080. /* We need to read more MESS_IN bytes for the extended message */
  1081. else {
  1082. hostdata->incoming_ptr++;
  1083. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1084. hostdata->state = S_CONNECTED;
  1085. }
  1086. break;
  1087. default:
  1088. printk("Rejecting Unknown Message(%02x) ", msg);
  1089. write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
  1090. hostdata->outgoing_msg[0] = MESSAGE_REJECT;
  1091. hostdata->outgoing_len = 1;
  1092. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1093. hostdata->state = S_CONNECTED;
  1094. }
  1095. break;
  1096. /* Note: this interrupt will occur only after a LEVEL2 command */
  1097. case CSR_SEL_XFER_DONE:
  1098. /* Make sure that reselection is enabled at this point - it may
  1099. * have been turned off for the command that just completed.
  1100. */
  1101. write_3393(hostdata, WD_SOURCE_ID, SRCID_ER);
  1102. if (phs == 0x60) {
  1103. DB(DB_INTR, printk("SX-DONE"))
  1104. cmd->SCp.Message = COMMAND_COMPLETE;
  1105. lun = read_3393(hostdata, WD_TARGET_LUN);
  1106. DB(DB_INTR, printk(":%d.%d", cmd->SCp.Status, lun))
  1107. hostdata->connected = NULL;
  1108. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1109. hostdata->state = S_UNCONNECTED;
  1110. if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
  1111. cmd->SCp.Status = lun;
  1112. if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
  1113. cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
  1114. else
  1115. cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1116. cmd->scsi_done(cmd);
  1117. /* We are no longer connected to a target - check to see if
  1118. * there are commands waiting to be executed.
  1119. */
  1120. in2000_execute(instance);
  1121. } else {
  1122. printk("%02x:%02x:%02x: Unknown SEL_XFER_DONE phase!!---", asr, sr, phs);
  1123. }
  1124. break;
  1125. /* Note: this interrupt will occur only after a LEVEL2 command */
  1126. case CSR_SDP:
  1127. DB(DB_INTR, printk("SDP"))
  1128. hostdata->state = S_RUNNING_LEVEL2;
  1129. write_3393(hostdata, WD_COMMAND_PHASE, 0x41);
  1130. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  1131. break;
  1132. case CSR_XFER_DONE | PHS_MESS_OUT:
  1133. case CSR_UNEXP | PHS_MESS_OUT:
  1134. case CSR_SRV_REQ | PHS_MESS_OUT:
  1135. DB(DB_INTR, printk("MSG_OUT="))
  1136. /* To get here, we've probably requested MESSAGE_OUT and have
  1137. * already put the correct bytes in outgoing_msg[] and filled
  1138. * in outgoing_len. We simply send them out to the SCSI bus.
  1139. * Sometimes we get MESSAGE_OUT phase when we're not expecting
  1140. * it - like when our SDTR message is rejected by a target. Some
  1141. * targets send the REJECT before receiving all of the extended
  1142. * message, and then seem to go back to MESSAGE_OUT for a byte
  1143. * or two. Not sure why, or if I'm doing something wrong to
  1144. * cause this to happen. Regardless, it seems that sending
  1145. * NOP messages in these situations results in no harm and
  1146. * makes everyone happy.
  1147. */
  1148. if (hostdata->outgoing_len == 0) {
  1149. hostdata->outgoing_len = 1;
  1150. hostdata->outgoing_msg[0] = NOP;
  1151. }
  1152. transfer_pio(hostdata->outgoing_msg, hostdata->outgoing_len, DATA_OUT_DIR, hostdata);
  1153. DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0]))
  1154. hostdata->outgoing_len = 0;
  1155. hostdata->state = S_CONNECTED;
  1156. break;
  1157. case CSR_UNEXP_DISC:
  1158. /* I think I've seen this after a request-sense that was in response
  1159. * to an error condition, but not sure. We certainly need to do
  1160. * something when we get this interrupt - the question is 'what?'.
  1161. * Let's think positively, and assume some command has finished
  1162. * in a legal manner (like a command that provokes a request-sense),
  1163. * so we treat it as a normal command-complete-disconnect.
  1164. */
  1165. /* Make sure that reselection is enabled at this point - it may
  1166. * have been turned off for the command that just completed.
  1167. */
  1168. write_3393(hostdata, WD_SOURCE_ID, SRCID_ER);
  1169. if (cmd == NULL) {
  1170. printk(" - Already disconnected! ");
  1171. hostdata->state = S_UNCONNECTED;
  1172. /* release the SMP spin_lock and restore irq state */
  1173. spin_unlock_irqrestore(instance->host_lock, flags);
  1174. return IRQ_HANDLED;
  1175. }
  1176. DB(DB_INTR, printk("UNEXP_DISC"))
  1177. hostdata->connected = NULL;
  1178. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1179. hostdata->state = S_UNCONNECTED;
  1180. if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
  1181. cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
  1182. else
  1183. cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1184. cmd->scsi_done(cmd);
  1185. /* We are no longer connected to a target - check to see if
  1186. * there are commands waiting to be executed.
  1187. */
  1188. in2000_execute(instance);
  1189. break;
  1190. case CSR_DISC:
  1191. /* Make sure that reselection is enabled at this point - it may
  1192. * have been turned off for the command that just completed.
  1193. */
  1194. write_3393(hostdata, WD_SOURCE_ID, SRCID_ER);
  1195. DB(DB_INTR, printk("DISC"))
  1196. if (cmd == NULL) {
  1197. printk(" - Already disconnected! ");
  1198. hostdata->state = S_UNCONNECTED;
  1199. }
  1200. switch (hostdata->state) {
  1201. case S_PRE_CMP_DISC:
  1202. hostdata->connected = NULL;
  1203. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1204. hostdata->state = S_UNCONNECTED;
  1205. DB(DB_INTR, printk(":%d", cmd->SCp.Status))
  1206. if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
  1207. cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
  1208. else
  1209. cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1210. cmd->scsi_done(cmd);
  1211. break;
  1212. case S_PRE_TMP_DISC:
  1213. case S_RUNNING_LEVEL2:
  1214. cmd->host_scribble = (uchar *) hostdata->disconnected_Q;
  1215. hostdata->disconnected_Q = cmd;
  1216. hostdata->connected = NULL;
  1217. hostdata->state = S_UNCONNECTED;
  1218. #ifdef PROC_STATISTICS
  1219. hostdata->disc_done_cnt[cmd->device->id]++;
  1220. #endif
  1221. break;
  1222. default:
  1223. printk("*** Unexpected DISCONNECT interrupt! ***");
  1224. hostdata->state = S_UNCONNECTED;
  1225. }
  1226. /* We are no longer connected to a target - check to see if
  1227. * there are commands waiting to be executed.
  1228. */
  1229. in2000_execute(instance);
  1230. break;
  1231. case CSR_RESEL_AM:
  1232. DB(DB_INTR, printk("RESEL"))
  1233. /* First we have to make sure this reselection didn't */
  1234. /* happen during Arbitration/Selection of some other device. */
  1235. /* If yes, put losing command back on top of input_Q. */
  1236. if (hostdata->level2 <= L2_NONE) {
  1237. if (hostdata->selecting) {
  1238. cmd = (Scsi_Cmnd *) hostdata->selecting;
  1239. hostdata->selecting = NULL;
  1240. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1241. cmd->host_scribble = (uchar *) hostdata->input_Q;
  1242. hostdata->input_Q = cmd;
  1243. }
  1244. }
  1245. else {
  1246. if (cmd) {
  1247. if (phs == 0x00) {
  1248. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1249. cmd->host_scribble = (uchar *) hostdata->input_Q;
  1250. hostdata->input_Q = cmd;
  1251. } else {
  1252. printk("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---", asr, sr, phs);
  1253. while (1)
  1254. printk("\r");
  1255. }
  1256. }
  1257. }
  1258. /* OK - find out which device reselected us. */
  1259. id = read_3393(hostdata, WD_SOURCE_ID);
  1260. id &= SRCID_MASK;
  1261. /* and extract the lun from the ID message. (Note that we don't
  1262. * bother to check for a valid message here - I guess this is
  1263. * not the right way to go, but....)
  1264. */
  1265. lun = read_3393(hostdata, WD_DATA);
  1266. if (hostdata->level2 < L2_RESELECT)
  1267. write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
  1268. lun &= 7;
  1269. /* Now we look for the command that's reconnecting. */
  1270. cmd = (Scsi_Cmnd *) hostdata->disconnected_Q;
  1271. patch = NULL;
  1272. while (cmd) {
  1273. if (id == cmd->device->id && lun == cmd->device->lun)
  1274. break;
  1275. patch = cmd;
  1276. cmd = (Scsi_Cmnd *) cmd->host_scribble;
  1277. }
  1278. /* Hmm. Couldn't find a valid command.... What to do? */
  1279. if (!cmd) {
  1280. printk("---TROUBLE: target %d.%d not in disconnect queue---", id, lun);
  1281. break;
  1282. }
  1283. /* Ok, found the command - now start it up again. */
  1284. if (patch)
  1285. patch->host_scribble = cmd->host_scribble;
  1286. else
  1287. hostdata->disconnected_Q = (Scsi_Cmnd *) cmd->host_scribble;
  1288. hostdata->connected = cmd;
  1289. /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
  1290. * because these things are preserved over a disconnect.
  1291. * But we DO need to fix the DPD bit so it's correct for this command.
  1292. */
  1293. if (is_dir_out(cmd))
  1294. write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id);
  1295. else
  1296. write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD);
  1297. if (hostdata->level2 >= L2_RESELECT) {
  1298. write_3393_count(hostdata, 0); /* we want a DATA_PHASE interrupt */
  1299. write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
  1300. write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
  1301. hostdata->state = S_RUNNING_LEVEL2;
  1302. } else
  1303. hostdata->state = S_CONNECTED;
  1304. break;
  1305. default:
  1306. printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr, sr, phs);
  1307. }
  1308. write1_io(0, IO_LED_OFF);
  1309. DB(DB_INTR, printk("} "))
  1310. /* release the SMP spin_lock and restore irq state */
  1311. spin_unlock_irqrestore(instance->host_lock, flags);
  1312. return IRQ_HANDLED;
  1313. }
  1314. #define RESET_CARD 0
  1315. #define RESET_CARD_AND_BUS 1
  1316. #define B_FLAG 0x80
  1317. /*
  1318. * Caller must hold instance lock!
  1319. */
  1320. static int reset_hardware(struct Scsi_Host *instance, int type)
  1321. {
  1322. struct IN2000_hostdata *hostdata;
  1323. int qt, x;
  1324. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  1325. write1_io(0, IO_LED_ON);
  1326. if (type == RESET_CARD_AND_BUS) {
  1327. write1_io(0, IO_CARD_RESET);
  1328. x = read1_io(IO_HARDWARE);
  1329. }
  1330. x = read_3393(hostdata, WD_SCSI_STATUS); /* clear any WD intrpt */
  1331. write_3393(hostdata, WD_OWN_ID, instance->this_id | OWNID_EAF | OWNID_RAF | OWNID_FS_8);
  1332. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1333. write_3393(hostdata, WD_SYNCHRONOUS_TRANSFER, calc_sync_xfer(hostdata->default_sx_per / 4, DEFAULT_SX_OFF));
  1334. write1_io(0, IO_FIFO_WRITE); /* clear fifo counter */
  1335. write1_io(0, IO_FIFO_READ); /* start fifo out in read mode */
  1336. write_3393(hostdata, WD_COMMAND, WD_CMD_RESET);
  1337. /* FIXME: timeout ?? */
  1338. while (!(READ_AUX_STAT() & ASR_INT))
  1339. cpu_relax(); /* wait for RESET to complete */
  1340. x = read_3393(hostdata, WD_SCSI_STATUS); /* clear interrupt */
  1341. write_3393(hostdata, WD_QUEUE_TAG, 0xa5); /* any random number */
  1342. qt = read_3393(hostdata, WD_QUEUE_TAG);
  1343. if (qt == 0xa5) {
  1344. x |= B_FLAG;
  1345. write_3393(hostdata, WD_QUEUE_TAG, 0);
  1346. }
  1347. write_3393(hostdata, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
  1348. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1349. write1_io(0, IO_LED_OFF);
  1350. return x;
  1351. }
  1352. static int in2000_bus_reset(Scsi_Cmnd * cmd)
  1353. {
  1354. struct Scsi_Host *instance;
  1355. struct IN2000_hostdata *hostdata;
  1356. int x;
  1357. unsigned long flags;
  1358. instance = cmd->device->host;
  1359. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  1360. printk(KERN_WARNING "scsi%d: Reset. ", instance->host_no);
  1361. spin_lock_irqsave(instance->host_lock, flags);
  1362. /* do scsi-reset here */
  1363. reset_hardware(instance, RESET_CARD_AND_BUS);
  1364. for (x = 0; x < 8; x++) {
  1365. hostdata->busy[x] = 0;
  1366. hostdata->sync_xfer[x] = calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF);
  1367. hostdata->sync_stat[x] = SS_UNSET; /* using default sync values */
  1368. }
  1369. hostdata->input_Q = NULL;
  1370. hostdata->selecting = NULL;
  1371. hostdata->connected = NULL;
  1372. hostdata->disconnected_Q = NULL;
  1373. hostdata->state = S_UNCONNECTED;
  1374. hostdata->fifo = FI_FIFO_UNUSED;
  1375. hostdata->incoming_ptr = 0;
  1376. hostdata->outgoing_len = 0;
  1377. cmd->result = DID_RESET << 16;
  1378. spin_unlock_irqrestore(instance->host_lock, flags);
  1379. return SUCCESS;
  1380. }
  1381. static int __in2000_abort(Scsi_Cmnd * cmd)
  1382. {
  1383. struct Scsi_Host *instance;
  1384. struct IN2000_hostdata *hostdata;
  1385. Scsi_Cmnd *tmp, *prev;
  1386. uchar sr, asr;
  1387. unsigned long timeout;
  1388. instance = cmd->device->host;
  1389. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  1390. printk(KERN_DEBUG "scsi%d: Abort-", instance->host_no);
  1391. printk("(asr=%02x,count=%ld,resid=%d,buf_resid=%d,have_data=%d,FC=%02x)- ", READ_AUX_STAT(), read_3393_count(hostdata), cmd->SCp.this_residual, cmd->SCp.buffers_residual, cmd->SCp.have_data_in, read1_io(IO_FIFO_COUNT));
  1392. /*
  1393. * Case 1 : If the command hasn't been issued yet, we simply remove it
  1394. * from the inout_Q.
  1395. */
  1396. tmp = (Scsi_Cmnd *) hostdata->input_Q;
  1397. prev = NULL;
  1398. while (tmp) {
  1399. if (tmp == cmd) {
  1400. if (prev)
  1401. prev->host_scribble = cmd->host_scribble;
  1402. cmd->host_scribble = NULL;
  1403. cmd->result = DID_ABORT << 16;
  1404. printk(KERN_WARNING "scsi%d: Abort - removing command from input_Q. ", instance->host_no);
  1405. cmd->scsi_done(cmd);
  1406. return SUCCESS;
  1407. }
  1408. prev = tmp;
  1409. tmp = (Scsi_Cmnd *) tmp->host_scribble;
  1410. }
  1411. /*
  1412. * Case 2 : If the command is connected, we're going to fail the abort
  1413. * and let the high level SCSI driver retry at a later time or
  1414. * issue a reset.
  1415. *
  1416. * Timeouts, and therefore aborted commands, will be highly unlikely
  1417. * and handling them cleanly in this situation would make the common
  1418. * case of noresets less efficient, and would pollute our code. So,
  1419. * we fail.
  1420. */
  1421. if (hostdata->connected == cmd) {
  1422. printk(KERN_WARNING "scsi%d: Aborting connected command - ", instance->host_no);
  1423. printk("sending wd33c93 ABORT command - ");
  1424. write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
  1425. write_3393_cmd(hostdata, WD_CMD_ABORT);
  1426. /* Now we have to attempt to flush out the FIFO... */
  1427. printk("flushing fifo - ");
  1428. timeout = 1000000;
  1429. do {
  1430. asr = READ_AUX_STAT();
  1431. if (asr & ASR_DBR)
  1432. read_3393(hostdata, WD_DATA);
  1433. } while (!(asr & ASR_INT) && timeout-- > 0);
  1434. sr = read_3393(hostdata, WD_SCSI_STATUS);
  1435. printk("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ", asr, sr, read_3393_count(hostdata), timeout);
  1436. /*
  1437. * Abort command processed.
  1438. * Still connected.
  1439. * We must disconnect.
  1440. */
  1441. printk("sending wd33c93 DISCONNECT command - ");
  1442. write_3393_cmd(hostdata, WD_CMD_DISCONNECT);
  1443. timeout = 1000000;
  1444. asr = READ_AUX_STAT();
  1445. while ((asr & ASR_CIP) && timeout-- > 0)
  1446. asr = READ_AUX_STAT();
  1447. sr = read_3393(hostdata, WD_SCSI_STATUS);
  1448. printk("asr=%02x, sr=%02x.", asr, sr);
  1449. hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
  1450. hostdata->connected = NULL;
  1451. hostdata->state = S_UNCONNECTED;
  1452. cmd->result = DID_ABORT << 16;
  1453. cmd->scsi_done(cmd);
  1454. in2000_execute(instance);
  1455. return SUCCESS;
  1456. }
  1457. /*
  1458. * Case 3: If the command is currently disconnected from the bus,
  1459. * we're not going to expend much effort here: Let's just return
  1460. * an ABORT_SNOOZE and hope for the best...
  1461. */
  1462. for (tmp = (Scsi_Cmnd *) hostdata->disconnected_Q; tmp; tmp = (Scsi_Cmnd *) tmp->host_scribble)
  1463. if (cmd == tmp) {
  1464. printk(KERN_DEBUG "scsi%d: unable to abort disconnected command.\n", instance->host_no);
  1465. return FAILED;
  1466. }
  1467. /*
  1468. * Case 4 : If we reached this point, the command was not found in any of
  1469. * the queues.
  1470. *
  1471. * We probably reached this point because of an unlikely race condition
  1472. * between the command completing successfully and the abortion code,
  1473. * so we won't panic, but we will notify the user in case something really
  1474. * broke.
  1475. */
  1476. in2000_execute(instance);
  1477. printk("scsi%d: warning : SCSI command probably completed successfully" " before abortion. ", instance->host_no);
  1478. return SUCCESS;
  1479. }
  1480. static int in2000_abort(Scsi_Cmnd * cmd)
  1481. {
  1482. int rc;
  1483. spin_lock_irq(cmd->device->host->host_lock);
  1484. rc = __in2000_abort(cmd);
  1485. spin_unlock_irq(cmd->device->host->host_lock);
  1486. return rc;
  1487. }
  1488. #define MAX_IN2000_HOSTS 3
  1489. #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
  1490. #define SETUP_BUFFER_SIZE 200
  1491. static char setup_buffer[SETUP_BUFFER_SIZE];
  1492. static char setup_used[MAX_SETUP_ARGS];
  1493. static int done_setup = 0;
  1494. static void __init in2000_setup(char *str, int *ints)
  1495. {
  1496. int i;
  1497. char *p1, *p2;
  1498. strlcpy(setup_buffer, str, SETUP_BUFFER_SIZE);
  1499. p1 = setup_buffer;
  1500. i = 0;
  1501. while (*p1 && (i < MAX_SETUP_ARGS)) {
  1502. p2 = strchr(p1, ',');
  1503. if (p2) {
  1504. *p2 = '\0';
  1505. if (p1 != p2)
  1506. setup_args[i] = p1;
  1507. p1 = p2 + 1;
  1508. i++;
  1509. } else {
  1510. setup_args[i] = p1;
  1511. break;
  1512. }
  1513. }
  1514. for (i = 0; i < MAX_SETUP_ARGS; i++)
  1515. setup_used[i] = 0;
  1516. done_setup = 1;
  1517. }
  1518. /* check_setup_args() returns index if key found, 0 if not
  1519. */
  1520. static int __init check_setup_args(char *key, int *val, char *buf)
  1521. {
  1522. int x;
  1523. char *cp;
  1524. for (x = 0; x < MAX_SETUP_ARGS; x++) {
  1525. if (setup_used[x])
  1526. continue;
  1527. if (!strncmp(setup_args[x], key, strlen(key)))
  1528. break;
  1529. }
  1530. if (x == MAX_SETUP_ARGS)
  1531. return 0;
  1532. setup_used[x] = 1;
  1533. cp = setup_args[x] + strlen(key);
  1534. *val = -1;
  1535. if (*cp != ':')
  1536. return ++x;
  1537. cp++;
  1538. if ((*cp >= '0') && (*cp <= '9')) {
  1539. *val = simple_strtoul(cp, NULL, 0);
  1540. }
  1541. return ++x;
  1542. }
  1543. /* The "correct" (ie portable) way to access memory-mapped hardware
  1544. * such as the IN2000 EPROM and dip switch is through the use of
  1545. * special macros declared in 'asm/io.h'. We use readb() and readl()
  1546. * when reading from the card's BIOS area in in2000_detect().
  1547. */
  1548. static u32 bios_tab[] in2000__INITDATA = {
  1549. 0xc8000,
  1550. 0xd0000,
  1551. 0xd8000,
  1552. 0
  1553. };
  1554. static unsigned short base_tab[] in2000__INITDATA = {
  1555. 0x220,
  1556. 0x200,
  1557. 0x110,
  1558. 0x100,
  1559. };
  1560. static int int_tab[] in2000__INITDATA = {
  1561. 15,
  1562. 14,
  1563. 11,
  1564. 10
  1565. };
  1566. static int probe_bios(u32 addr, u32 *s1, uchar *switches)
  1567. {
  1568. void __iomem *p = ioremap(addr, 0x34);
  1569. if (!p)
  1570. return 0;
  1571. *s1 = readl(p + 0x10);
  1572. if (*s1 == 0x41564f4e || readl(p + 0x30) == 0x61776c41) {
  1573. /* Read the switch image that's mapped into EPROM space */
  1574. *switches = ~readb(p + 0x20);
  1575. iounmap(p);
  1576. return 1;
  1577. }
  1578. iounmap(p);
  1579. return 0;
  1580. }
  1581. static int __init in2000_detect(struct scsi_host_template * tpnt)
  1582. {
  1583. struct Scsi_Host *instance;
  1584. struct IN2000_hostdata *hostdata;
  1585. int detect_count;
  1586. int bios;
  1587. int x;
  1588. unsigned short base;
  1589. uchar switches;
  1590. uchar hrev;
  1591. unsigned long flags;
  1592. int val;
  1593. char buf[32];
  1594. /* Thanks to help from Bill Earnest, probing for IN2000 cards is a
  1595. * pretty straightforward and fool-proof operation. There are 3
  1596. * possible locations for the IN2000 EPROM in memory space - if we
  1597. * find a BIOS signature, we can read the dip switch settings from
  1598. * the byte at BIOS+32 (shadowed in by logic on the card). From 2
  1599. * of the switch bits we get the card's address in IO space. There's
  1600. * an image of the dip switch there, also, so we have a way to back-
  1601. * check that this really is an IN2000 card. Very nifty. Use the
  1602. * 'ioport:xx' command-line parameter if your BIOS EPROM is absent
  1603. * or disabled.
  1604. */
  1605. if (!done_setup && setup_strings)
  1606. in2000_setup(setup_strings, NULL);
  1607. detect_count = 0;
  1608. for (bios = 0; bios_tab[bios]; bios++) {
  1609. u32 s1 = 0;
  1610. if (check_setup_args("ioport", &val, buf)) {
  1611. base = val;
  1612. switches = ~inb(base + IO_SWITCHES) & 0xff;
  1613. printk("Forcing IN2000 detection at IOport 0x%x ", base);
  1614. bios = 2;
  1615. }
  1616. /*
  1617. * There have been a couple of BIOS versions with different layouts
  1618. * for the obvious ID strings. We look for the 2 most common ones and
  1619. * hope that they cover all the cases...
  1620. */
  1621. else if (probe_bios(bios_tab[bios], &s1, &switches)) {
  1622. printk("Found IN2000 BIOS at 0x%x ", (unsigned int) bios_tab[bios]);
  1623. /* Find out where the IO space is */
  1624. x = switches & (SW_ADDR0 | SW_ADDR1);
  1625. base = base_tab[x];
  1626. /* Check for the IN2000 signature in IO space. */
  1627. x = ~inb(base + IO_SWITCHES) & 0xff;
  1628. if (x != switches) {
  1629. printk("Bad IO signature: %02x vs %02x.\n", x, switches);
  1630. continue;
  1631. }
  1632. } else
  1633. continue;
  1634. /* OK. We have a base address for the IO ports - run a few safety checks */
  1635. if (!(switches & SW_BIT7)) { /* I _think_ all cards do this */
  1636. printk("There is no IN-2000 SCSI card at IOport 0x%03x!\n", base);
  1637. continue;
  1638. }
  1639. /* Let's assume any hardware version will work, although the driver
  1640. * has only been tested on 0x21, 0x22, 0x25, 0x26, and 0x27. We'll
  1641. * print out the rev number for reference later, but accept them all.
  1642. */
  1643. hrev = inb(base + IO_HARDWARE);
  1644. /* Bit 2 tells us if interrupts are disabled */
  1645. if (switches & SW_DISINT) {
  1646. printk("The IN-2000 SCSI card at IOport 0x%03x ", base);
  1647. printk("is not configured for interrupt operation!\n");
  1648. printk("This driver requires an interrupt: cancelling detection.\n");
  1649. continue;
  1650. }
  1651. /* Ok. We accept that there's an IN2000 at ioaddr 'base'. Now
  1652. * initialize it.
  1653. */
  1654. tpnt->proc_name = "in2000";
  1655. instance = scsi_register(tpnt, sizeof(struct IN2000_hostdata));
  1656. if (instance == NULL)
  1657. continue;
  1658. detect_count++;
  1659. hostdata = (struct IN2000_hostdata *) instance->hostdata;
  1660. instance->io_port = hostdata->io_base = base;
  1661. hostdata->dip_switch = switches;
  1662. hostdata->hrev = hrev;
  1663. write1_io(0, IO_FIFO_WRITE); /* clear fifo counter */
  1664. write1_io(0, IO_FIFO_READ); /* start fifo out in read mode */
  1665. write1_io(0, IO_INTR_MASK); /* allow all ints */
  1666. x = int_tab[(switches & (SW_INT0 | SW_INT1)) >> SW_INT_SHIFT];
  1667. if (request_irq(x, in2000_intr, 0, "in2000", instance)) {
  1668. printk("in2000_detect: Unable to allocate IRQ.\n");
  1669. detect_count--;
  1670. continue;
  1671. }
  1672. instance->irq = x;
  1673. instance->n_io_port = 13;
  1674. request_region(base, 13, "in2000"); /* lock in this IO space for our use */
  1675. for (x = 0; x < 8; x++) {
  1676. hostdata->busy[x] = 0;
  1677. hostdata->sync_xfer[x] = calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF);
  1678. hostdata->sync_stat[x] = SS_UNSET; /* using default sync values */
  1679. #ifdef PROC_STATISTICS
  1680. hostdata->cmd_cnt[x] = 0;
  1681. hostdata->disc_allowed_cnt[x] = 0;
  1682. hostdata->disc_done_cnt[x] = 0;
  1683. #endif
  1684. }
  1685. hostdata->input_Q = NULL;
  1686. hostdata->selecting = NULL;
  1687. hostdata->connected = NULL;
  1688. hostdata->disconnected_Q = NULL;
  1689. hostdata->state = S_UNCONNECTED;
  1690. hostdata->fifo = FI_FIFO_UNUSED;
  1691. hostdata->level2 = L2_BASIC;
  1692. hostdata->disconnect = DIS_ADAPTIVE;
  1693. hostdata->args = DEBUG_DEFAULTS;
  1694. hostdata->incoming_ptr = 0;
  1695. hostdata->outgoing_len = 0;
  1696. hostdata->default_sx_per = DEFAULT_SX_PER;
  1697. /* Older BIOS's had a 'sync on/off' switch - use its setting */
  1698. if (s1 == 0x41564f4e && (switches & SW_SYNC_DOS5))
  1699. hostdata->sync_off = 0x00; /* sync defaults to on */
  1700. else
  1701. hostdata->sync_off = 0xff; /* sync defaults to off */
  1702. #ifdef PROC_INTERFACE
  1703. hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS | PR_CONNECTED | PR_INPUTQ | PR_DISCQ | PR_STOP;
  1704. #ifdef PROC_STATISTICS
  1705. hostdata->int_cnt = 0;
  1706. #endif
  1707. #endif
  1708. if (check_setup_args("nosync", &val, buf))
  1709. hostdata->sync_off = val;
  1710. if (check_setup_args("period", &val, buf))
  1711. hostdata->default_sx_per = sx_table[round_period((unsigned int) val)].period_ns;
  1712. if (check_setup_args("disconnect", &val, buf)) {
  1713. if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
  1714. hostdata->disconnect = val;
  1715. else
  1716. hostdata->disconnect = DIS_ADAPTIVE;
  1717. }
  1718. if (check_setup_args("noreset", &val, buf))
  1719. hostdata->args ^= A_NO_SCSI_RESET;
  1720. if (check_setup_args("level2", &val, buf))
  1721. hostdata->level2 = val;
  1722. if (check_setup_args("debug", &val, buf))
  1723. hostdata->args = (val & DB_MASK);
  1724. #ifdef PROC_INTERFACE
  1725. if (check_setup_args("proc", &val, buf))
  1726. hostdata->proc = val;
  1727. #endif
  1728. /* FIXME: not strictly needed I think but the called code expects
  1729. to be locked */
  1730. spin_lock_irqsave(instance->host_lock, flags);
  1731. x = reset_hardware(instance, (hostdata->args & A_NO_SCSI_RESET) ? RESET_CARD : RESET_CARD_AND_BUS);
  1732. spin_unlock_irqrestore(instance->host_lock, flags);
  1733. hostdata->microcode = read_3393(hostdata, WD_CDB_1);
  1734. if (x & 0x01) {
  1735. if (x & B_FLAG)
  1736. hostdata->chip = C_WD33C93B;
  1737. else
  1738. hostdata->chip = C_WD33C93A;
  1739. } else
  1740. hostdata->chip = C_WD33C93;
  1741. printk("dip_switch=%02x irq=%d ioport=%02x floppy=%s sync/DOS5=%s ", (switches & 0x7f), instance->irq, hostdata->io_base, (switches & SW_FLOPPY) ? "Yes" : "No", (switches & SW_SYNC_DOS5) ? "Yes" : "No");
  1742. printk("hardware_ver=%02x chip=%s microcode=%02x\n", hrev, (hostdata->chip == C_WD33C93) ? "WD33c93" : (hostdata->chip == C_WD33C93A) ? "WD33c93A" : (hostdata->chip == C_WD33C93B) ? "WD33c93B" : "unknown", hostdata->microcode);
  1743. #ifdef DEBUGGING_ON
  1744. printk("setup_args = ");
  1745. for (x = 0; x < MAX_SETUP_ARGS; x++)
  1746. printk("%s,", setup_args[x]);
  1747. printk("\n");
  1748. #endif
  1749. if (hostdata->sync_off == 0xff)
  1750. printk("Sync-transfer DISABLED on all devices: ENABLE from command-line\n");
  1751. printk("IN2000 driver version %s - %s\n", IN2000_VERSION, IN2000_DATE);
  1752. }
  1753. return detect_count;
  1754. }
  1755. static int in2000_release(struct Scsi_Host *shost)
  1756. {
  1757. if (shost->irq)
  1758. free_irq(shost->irq, shost);
  1759. if (shost->io_port && shost->n_io_port)
  1760. release_region(shost->io_port, shost->n_io_port);
  1761. return 0;
  1762. }
  1763. /* NOTE: I lifted this function straight out of the old driver,
  1764. * and have not tested it. Presumably it does what it's
  1765. * supposed to do...
  1766. */
  1767. static int in2000_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *iinfo)
  1768. {
  1769. int size;
  1770. size = capacity;
  1771. iinfo[0] = 64;
  1772. iinfo[1] = 32;
  1773. iinfo[2] = size >> 11;
  1774. /* This should approximate the large drive handling that the DOS ASPI manager
  1775. uses. Drives very near the boundaries may not be handled correctly (i.e.
  1776. near 2.0 Gb and 4.0 Gb) */
  1777. if (iinfo[2] > 1024) {
  1778. iinfo[0] = 64;
  1779. iinfo[1] = 63;
  1780. iinfo[2] = (unsigned long) capacity / (iinfo[0] * iinfo[1]);
  1781. }
  1782. if (iinfo[2] > 1024) {
  1783. iinfo[0] = 128;
  1784. iinfo[1] = 63;
  1785. iinfo[2] = (unsigned long) capacity / (iinfo[0] * iinfo[1]);
  1786. }
  1787. if (iinfo[2] > 1024) {
  1788. iinfo[0] = 255;
  1789. iinfo[1] = 63;
  1790. iinfo[2] = (unsigned long) capacity / (iinfo[0] * iinfo[1]);
  1791. }
  1792. return 0;
  1793. }
  1794. static int in2000_write_info(struct Scsi_Host *instance, char *buf, int len)
  1795. {
  1796. #ifdef PROC_INTERFACE
  1797. char *bp;
  1798. struct IN2000_hostdata *hd;
  1799. int x, i;
  1800. hd = (struct IN2000_hostdata *) instance->hostdata;
  1801. buf[len] = '\0';
  1802. bp = buf;
  1803. if (!strncmp(bp, "debug:", 6)) {
  1804. bp += 6;
  1805. hd->args = simple_strtoul(bp, NULL, 0) & DB_MASK;
  1806. } else if (!strncmp(bp, "disconnect:", 11)) {
  1807. bp += 11;
  1808. x = simple_strtoul(bp, NULL, 0);
  1809. if (x < DIS_NEVER || x > DIS_ALWAYS)
  1810. x = DIS_ADAPTIVE;
  1811. hd->disconnect = x;
  1812. } else if (!strncmp(bp, "period:", 7)) {
  1813. bp += 7;
  1814. x = simple_strtoul(bp, NULL, 0);
  1815. hd->default_sx_per = sx_table[round_period((unsigned int) x)].period_ns;
  1816. } else if (!strncmp(bp, "resync:", 7)) {
  1817. bp += 7;
  1818. x = simple_strtoul(bp, NULL, 0);
  1819. for (i = 0; i < 7; i++)
  1820. if (x & (1 << i))
  1821. hd->sync_stat[i] = SS_UNSET;
  1822. } else if (!strncmp(bp, "proc:", 5)) {
  1823. bp += 5;
  1824. hd->proc = simple_strtoul(bp, NULL, 0);
  1825. } else if (!strncmp(bp, "level2:", 7)) {
  1826. bp += 7;
  1827. hd->level2 = simple_strtoul(bp, NULL, 0);
  1828. }
  1829. #endif
  1830. return len;
  1831. }
  1832. static int in2000_show_info(struct seq_file *m, struct Scsi_Host *instance)
  1833. {
  1834. #ifdef PROC_INTERFACE
  1835. unsigned long flags;
  1836. struct IN2000_hostdata *hd;
  1837. Scsi_Cmnd *cmd;
  1838. int x;
  1839. hd = (struct IN2000_hostdata *) instance->hostdata;
  1840. spin_lock_irqsave(instance->host_lock, flags);
  1841. if (hd->proc & PR_VERSION)
  1842. seq_printf(m, "\nVersion %s - %s.", IN2000_VERSION, IN2000_DATE);
  1843. if (hd->proc & PR_INFO) {
  1844. seq_printf(m, "\ndip_switch=%02x: irq=%d io=%02x floppy=%s sync/DOS5=%s", (hd->dip_switch & 0x7f), instance->irq, hd->io_base, (hd->dip_switch & 0x40) ? "Yes" : "No", (hd->dip_switch & 0x20) ? "Yes" : "No");
  1845. seq_puts(m, "\nsync_xfer[] = ");
  1846. for (x = 0; x < 7; x++)
  1847. seq_printf(m, "\t%02x", hd->sync_xfer[x]);
  1848. seq_puts(m, "\nsync_stat[] = ");
  1849. for (x = 0; x < 7; x++)
  1850. seq_printf(m, "\t%02x", hd->sync_stat[x]);
  1851. }
  1852. #ifdef PROC_STATISTICS
  1853. if (hd->proc & PR_STATISTICS) {
  1854. seq_puts(m, "\ncommands issued: ");
  1855. for (x = 0; x < 7; x++)
  1856. seq_printf(m, "\t%ld", hd->cmd_cnt[x]);
  1857. seq_puts(m, "\ndisconnects allowed:");
  1858. for (x = 0; x < 7; x++)
  1859. seq_printf(m, "\t%ld", hd->disc_allowed_cnt[x]);
  1860. seq_puts(m, "\ndisconnects done: ");
  1861. for (x = 0; x < 7; x++)
  1862. seq_printf(m, "\t%ld", hd->disc_done_cnt[x]);
  1863. seq_printf(m, "\ninterrupts: \t%ld", hd->int_cnt);
  1864. }
  1865. #endif
  1866. if (hd->proc & PR_CONNECTED) {
  1867. seq_puts(m, "\nconnected: ");
  1868. if (hd->connected) {
  1869. cmd = (Scsi_Cmnd *) hd->connected;
  1870. seq_printf(m, " %d:%llu(%02x)", cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1871. }
  1872. }
  1873. if (hd->proc & PR_INPUTQ) {
  1874. seq_puts(m, "\ninput_Q: ");
  1875. cmd = (Scsi_Cmnd *) hd->input_Q;
  1876. while (cmd) {
  1877. seq_printf(m, " %d:%llu(%02x)", cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1878. cmd = (Scsi_Cmnd *) cmd->host_scribble;
  1879. }
  1880. }
  1881. if (hd->proc & PR_DISCQ) {
  1882. seq_puts(m, "\ndisconnected_Q:");
  1883. cmd = (Scsi_Cmnd *) hd->disconnected_Q;
  1884. while (cmd) {
  1885. seq_printf(m, " %d:%llu(%02x)", cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
  1886. cmd = (Scsi_Cmnd *) cmd->host_scribble;
  1887. }
  1888. }
  1889. if (hd->proc & PR_TEST) {
  1890. ; /* insert your own custom function here */
  1891. }
  1892. seq_putc(m, '\n');
  1893. spin_unlock_irqrestore(instance->host_lock, flags);
  1894. #endif /* PROC_INTERFACE */
  1895. return 0;
  1896. }
  1897. MODULE_LICENSE("GPL");
  1898. static struct scsi_host_template driver_template = {
  1899. .proc_name = "in2000",
  1900. .write_info = in2000_write_info,
  1901. .show_info = in2000_show_info,
  1902. .name = "Always IN2000",
  1903. .detect = in2000_detect,
  1904. .release = in2000_release,
  1905. .queuecommand = in2000_queuecommand,
  1906. .eh_abort_handler = in2000_abort,
  1907. .eh_bus_reset_handler = in2000_bus_reset,
  1908. .bios_param = in2000_biosparam,
  1909. .can_queue = IN2000_CAN_Q,
  1910. .this_id = IN2000_HOST_ID,
  1911. .sg_tablesize = IN2000_SG,
  1912. .cmd_per_lun = IN2000_CPL,
  1913. .use_clustering = DISABLE_CLUSTERING,
  1914. };
  1915. #include "scsi_module.c"