PageRenderTime 69ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/scsi/in2000.c

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