PageRenderTime 53ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/scsi/arm/acornscsi.c

http://github.com/mirrors/linux
C | 3013 lines | 1938 code | 411 blank | 664 comment | 268 complexity | 294037fe137c2819fa624c5a905159b9 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/drivers/acorn/scsi/acornscsi.c
  4. *
  5. * Acorn SCSI 3 driver
  6. * By R.M.King.
  7. *
  8. * Abandoned using the Select and Transfer command since there were
  9. * some nasty races between our software and the target devices that
  10. * were not easy to solve, and the device errata had a lot of entries
  11. * for this command, some of them quite nasty...
  12. *
  13. * Changelog:
  14. * 26-Sep-1997 RMK Re-jigged to use the queue module.
  15. * Re-coded state machine to be based on driver
  16. * state not scsi state. Should be easier to debug.
  17. * Added acornscsi_release to clean up properly.
  18. * Updated proc/scsi reporting.
  19. * 05-Oct-1997 RMK Implemented writing to SCSI devices.
  20. * 06-Oct-1997 RMK Corrected small (non-serious) bug with the connect/
  21. * reconnect race condition causing a warning message.
  22. * 12-Oct-1997 RMK Added catch for re-entering interrupt routine.
  23. * 15-Oct-1997 RMK Improved handling of commands.
  24. * 27-Jun-1998 RMK Changed asm/delay.h to linux/delay.h.
  25. * 13-Dec-1998 RMK Better abort code and command handling. Extra state
  26. * transitions added to allow dodgy devices to work.
  27. */
  28. #define DEBUG_NO_WRITE 1
  29. #define DEBUG_QUEUES 2
  30. #define DEBUG_DMA 4
  31. #define DEBUG_ABORT 8
  32. #define DEBUG_DISCON 16
  33. #define DEBUG_CONNECT 32
  34. #define DEBUG_PHASES 64
  35. #define DEBUG_WRITE 128
  36. #define DEBUG_LINK 256
  37. #define DEBUG_MESSAGES 512
  38. #define DEBUG_RESET 1024
  39. #define DEBUG_ALL (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
  40. DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
  41. DEBUG_DMA|DEBUG_QUEUES)
  42. /* DRIVER CONFIGURATION
  43. *
  44. * SCSI-II Tagged queue support.
  45. *
  46. * I don't have any SCSI devices that support it, so it is totally untested
  47. * (except to make sure that it doesn't interfere with any non-tagging
  48. * devices). It is not fully implemented either - what happens when a
  49. * tagging device reconnects???
  50. *
  51. * You can tell if you have a device that supports tagged queueing my
  52. * cating (eg) /proc/scsi/acornscsi/0 and see if the SCSI revision is reported
  53. * as '2 TAG'.
  54. *
  55. * Also note that CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE is normally set in the config
  56. * scripts, but disabled here. Once debugged, remove the #undef, otherwise to debug,
  57. * comment out the undef.
  58. */
  59. #undef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  60. /*
  61. * SCSI-II Synchronous transfer support.
  62. *
  63. * Tried and tested...
  64. *
  65. * SDTR_SIZE - maximum number of un-acknowledged bytes (0 = off, 12 = max)
  66. * SDTR_PERIOD - period of REQ signal (min=125, max=1020)
  67. * DEFAULT_PERIOD - default REQ period.
  68. */
  69. #define SDTR_SIZE 12
  70. #define SDTR_PERIOD 125
  71. #define DEFAULT_PERIOD 500
  72. /*
  73. * Debugging information
  74. *
  75. * DEBUG - bit mask from list above
  76. * DEBUG_TARGET - is defined to the target number if you want to debug
  77. * a specific target. [only recon/write/dma].
  78. */
  79. #define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
  80. /* only allow writing to SCSI device 0 */
  81. #define NO_WRITE 0xFE
  82. /*#define DEBUG_TARGET 2*/
  83. /*
  84. * Select timeout time (in 10ms units)
  85. *
  86. * This is the timeout used between the start of selection and the WD33C93
  87. * chip deciding that the device isn't responding.
  88. */
  89. #define TIMEOUT_TIME 10
  90. /*
  91. * Define this if you want to have verbose explanation of SCSI
  92. * status/messages.
  93. */
  94. #undef CONFIG_ACORNSCSI_CONSTANTS
  95. /*
  96. * Define this if you want to use the on board DMAC [don't remove this option]
  97. * If not set, then use PIO mode (not currently supported).
  98. */
  99. #define USE_DMAC
  100. /*
  101. * ====================================================================================
  102. */
  103. #ifdef DEBUG_TARGET
  104. #define DBG(cmd,xxx...) \
  105. if (cmd->device->id == DEBUG_TARGET) { \
  106. xxx; \
  107. }
  108. #else
  109. #define DBG(cmd,xxx...) xxx
  110. #endif
  111. #include <linux/module.h>
  112. #include <linux/kernel.h>
  113. #include <linux/string.h>
  114. #include <linux/signal.h>
  115. #include <linux/errno.h>
  116. #include <linux/proc_fs.h>
  117. #include <linux/ioport.h>
  118. #include <linux/blkdev.h>
  119. #include <linux/delay.h>
  120. #include <linux/interrupt.h>
  121. #include <linux/init.h>
  122. #include <linux/bitops.h>
  123. #include <linux/stringify.h>
  124. #include <linux/io.h>
  125. #include <asm/ecard.h>
  126. #include "../scsi.h"
  127. #include <scsi/scsi_dbg.h>
  128. #include <scsi/scsi_host.h>
  129. #include <scsi/scsi_transport_spi.h>
  130. #include "acornscsi.h"
  131. #include "msgqueue.h"
  132. #include "scsi.h"
  133. #include <scsi/scsicam.h>
  134. #define VER_MAJOR 2
  135. #define VER_MINOR 0
  136. #define VER_PATCH 6
  137. #ifndef ABORT_TAG
  138. #define ABORT_TAG 0xd
  139. #else
  140. #error "Yippee! ABORT TAG is now defined! Remove this error!"
  141. #endif
  142. #ifdef USE_DMAC
  143. /*
  144. * DMAC setup parameters
  145. */
  146. #define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
  147. #define INIT_DEVCON1 (DEVCON1_BHLD)
  148. #define DMAC_READ (MODECON_READ)
  149. #define DMAC_WRITE (MODECON_WRITE)
  150. #define INIT_SBICDMA (CTRL_DMABURST)
  151. #define scsi_xferred have_data_in
  152. /*
  153. * Size of on-board DMA buffer
  154. */
  155. #define DMAC_BUFFER_SIZE 65536
  156. #endif
  157. #define STATUS_BUFFER_TO_PRINT 24
  158. unsigned int sdtr_period = SDTR_PERIOD;
  159. unsigned int sdtr_size = SDTR_SIZE;
  160. static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
  161. unsigned int result);
  162. static int acornscsi_reconnect_finish(AS_Host *host);
  163. static void acornscsi_dma_cleanup(AS_Host *host);
  164. static void acornscsi_abortcmd(AS_Host *host, unsigned char tag);
  165. /* ====================================================================================
  166. * Miscellaneous
  167. */
  168. /* Offsets from MEMC base */
  169. #define SBIC_REGIDX 0x2000
  170. #define SBIC_REGVAL 0x2004
  171. #define DMAC_OFFSET 0x3000
  172. /* Offsets from FAST IOC base */
  173. #define INT_REG 0x2000
  174. #define PAGE_REG 0x3000
  175. static inline void sbic_arm_write(AS_Host *host, unsigned int reg, unsigned int value)
  176. {
  177. writeb(reg, host->base + SBIC_REGIDX);
  178. writeb(value, host->base + SBIC_REGVAL);
  179. }
  180. static inline int sbic_arm_read(AS_Host *host, unsigned int reg)
  181. {
  182. if(reg == SBIC_ASR)
  183. return readl(host->base + SBIC_REGIDX) & 255;
  184. writeb(reg, host->base + SBIC_REGIDX);
  185. return readl(host->base + SBIC_REGVAL) & 255;
  186. }
  187. #define sbic_arm_writenext(host, val) writeb((val), (host)->base + SBIC_REGVAL)
  188. #define sbic_arm_readnext(host) readb((host)->base + SBIC_REGVAL)
  189. #ifdef USE_DMAC
  190. #define dmac_read(host,reg) \
  191. readb((host)->base + DMAC_OFFSET + ((reg) << 2))
  192. #define dmac_write(host,reg,value) \
  193. ({ writeb((value), (host)->base + DMAC_OFFSET + ((reg) << 2)); })
  194. #define dmac_clearintr(host) writeb(0, (host)->fast + INT_REG)
  195. static inline unsigned int dmac_address(AS_Host *host)
  196. {
  197. return dmac_read(host, DMAC_TXADRHI) << 16 |
  198. dmac_read(host, DMAC_TXADRMD) << 8 |
  199. dmac_read(host, DMAC_TXADRLO);
  200. }
  201. static
  202. void acornscsi_dumpdma(AS_Host *host, char *where)
  203. {
  204. unsigned int mode, addr, len;
  205. mode = dmac_read(host, DMAC_MODECON);
  206. addr = dmac_address(host);
  207. len = dmac_read(host, DMAC_TXCNTHI) << 8 |
  208. dmac_read(host, DMAC_TXCNTLO);
  209. printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
  210. host->host->host_no, where,
  211. mode, addr, (len + 1) & 0xffff,
  212. dmac_read(host, DMAC_MASKREG));
  213. printk("DMA @%06x, ", host->dma.start_addr);
  214. printk("BH @%p +%04x, ", host->scsi.SCp.ptr,
  215. host->scsi.SCp.this_residual);
  216. printk("DT @+%04x ST @+%04x", host->dma.transferred,
  217. host->scsi.SCp.scsi_xferred);
  218. printk("\n");
  219. }
  220. #endif
  221. static
  222. unsigned long acornscsi_sbic_xfcount(AS_Host *host)
  223. {
  224. unsigned long length;
  225. length = sbic_arm_read(host, SBIC_TRANSCNTH) << 16;
  226. length |= sbic_arm_readnext(host) << 8;
  227. length |= sbic_arm_readnext(host);
  228. return length;
  229. }
  230. static int
  231. acornscsi_sbic_wait(AS_Host *host, int stat_mask, int stat, int timeout, char *msg)
  232. {
  233. int asr;
  234. do {
  235. asr = sbic_arm_read(host, SBIC_ASR);
  236. if ((asr & stat_mask) == stat)
  237. return 0;
  238. udelay(1);
  239. } while (--timeout);
  240. printk("scsi%d: timeout while %s\n", host->host->host_no, msg);
  241. return -1;
  242. }
  243. static
  244. int acornscsi_sbic_issuecmd(AS_Host *host, int command)
  245. {
  246. if (acornscsi_sbic_wait(host, ASR_CIP, 0, 1000, "issuing command"))
  247. return -1;
  248. sbic_arm_write(host, SBIC_CMND, command);
  249. return 0;
  250. }
  251. static void
  252. acornscsi_csdelay(unsigned int cs)
  253. {
  254. unsigned long target_jiffies, flags;
  255. target_jiffies = jiffies + 1 + cs * HZ / 100;
  256. local_save_flags(flags);
  257. local_irq_enable();
  258. while (time_before(jiffies, target_jiffies)) barrier();
  259. local_irq_restore(flags);
  260. }
  261. static
  262. void acornscsi_resetcard(AS_Host *host)
  263. {
  264. unsigned int i, timeout;
  265. /* assert reset line */
  266. host->card.page_reg = 0x80;
  267. writeb(host->card.page_reg, host->fast + PAGE_REG);
  268. /* wait 3 cs. SCSI standard says 25ms. */
  269. acornscsi_csdelay(3);
  270. host->card.page_reg = 0;
  271. writeb(host->card.page_reg, host->fast + PAGE_REG);
  272. /*
  273. * Should get a reset from the card
  274. */
  275. timeout = 1000;
  276. do {
  277. if (readb(host->fast + INT_REG) & 8)
  278. break;
  279. udelay(1);
  280. } while (--timeout);
  281. if (timeout == 0)
  282. printk("scsi%d: timeout while resetting card\n",
  283. host->host->host_no);
  284. sbic_arm_read(host, SBIC_ASR);
  285. sbic_arm_read(host, SBIC_SSR);
  286. /* setup sbic - WD33C93A */
  287. sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
  288. sbic_arm_write(host, SBIC_CMND, CMND_RESET);
  289. /*
  290. * Command should cause a reset interrupt
  291. */
  292. timeout = 1000;
  293. do {
  294. if (readb(host->fast + INT_REG) & 8)
  295. break;
  296. udelay(1);
  297. } while (--timeout);
  298. if (timeout == 0)
  299. printk("scsi%d: timeout while resetting card\n",
  300. host->host->host_no);
  301. sbic_arm_read(host, SBIC_ASR);
  302. if (sbic_arm_read(host, SBIC_SSR) != 0x01)
  303. printk(KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
  304. host->host->host_no);
  305. sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
  306. sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
  307. sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
  308. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  309. host->card.page_reg = 0x40;
  310. writeb(host->card.page_reg, host->fast + PAGE_REG);
  311. /* setup dmac - uPC71071 */
  312. dmac_write(host, DMAC_INIT, 0);
  313. #ifdef USE_DMAC
  314. dmac_write(host, DMAC_INIT, INIT_8BIT);
  315. dmac_write(host, DMAC_CHANNEL, CHANNEL_0);
  316. dmac_write(host, DMAC_DEVCON0, INIT_DEVCON0);
  317. dmac_write(host, DMAC_DEVCON1, INIT_DEVCON1);
  318. #endif
  319. host->SCpnt = NULL;
  320. host->scsi.phase = PHASE_IDLE;
  321. host->scsi.disconnectable = 0;
  322. memset(host->busyluns, 0, sizeof(host->busyluns));
  323. for (i = 0; i < 8; i++) {
  324. host->device[i].sync_state = SYNC_NEGOCIATE;
  325. host->device[i].disconnect_ok = 1;
  326. }
  327. /* wait 25 cs. SCSI standard says 250ms. */
  328. acornscsi_csdelay(25);
  329. }
  330. /*=============================================================================================
  331. * Utility routines (eg. debug)
  332. */
  333. #ifdef CONFIG_ACORNSCSI_CONSTANTS
  334. static char *acornscsi_interrupttype[] = {
  335. "rst", "suc", "p/a", "3",
  336. "term", "5", "6", "7",
  337. "serv", "9", "a", "b",
  338. "c", "d", "e", "f"
  339. };
  340. static signed char acornscsi_map[] = {
  341. 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  342. -1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
  343. 12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
  344. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  345. 15, 16, 17, 18, 19, -1, -1, 20, 4, 5, 6, 7, 8, 9, 10, 11,
  346. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  347. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  348. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  349. 21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
  350. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  351. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  352. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  353. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  354. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  355. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  356. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  357. };
  358. static char *acornscsi_interruptcode[] = {
  359. /* 0 */
  360. "reset - normal mode", /* 00 */
  361. "reset - advanced mode", /* 01 */
  362. /* 2 */
  363. "sel", /* 11 */
  364. "sel+xfer", /* 16 */
  365. "data-out", /* 18 */
  366. "data-in", /* 19 */
  367. "cmd", /* 1A */
  368. "stat", /* 1B */
  369. "??-out", /* 1C */
  370. "??-in", /* 1D */
  371. "msg-out", /* 1E */
  372. "msg-in", /* 1F */
  373. /* 12 */
  374. "/ACK asserted", /* 20 */
  375. "save-data-ptr", /* 21 */
  376. "{re}sel", /* 22 */
  377. /* 15 */
  378. "inv cmd", /* 40 */
  379. "unexpected disconnect", /* 41 */
  380. "sel timeout", /* 42 */
  381. "P err", /* 43 */
  382. "P err+ATN", /* 44 */
  383. "bad status byte", /* 47 */
  384. /* 21 */
  385. "resel, no id", /* 80 */
  386. "resel", /* 81 */
  387. "discon", /* 85 */
  388. };
  389. static
  390. void print_scsi_status(unsigned int ssr)
  391. {
  392. if (acornscsi_map[ssr] != -1)
  393. printk("%s:%s",
  394. acornscsi_interrupttype[(ssr >> 4)],
  395. acornscsi_interruptcode[acornscsi_map[ssr]]);
  396. else
  397. printk("%X:%X", ssr >> 4, ssr & 0x0f);
  398. }
  399. #endif
  400. static
  401. void print_sbic_status(int asr, int ssr, int cmdphase)
  402. {
  403. #ifdef CONFIG_ACORNSCSI_CONSTANTS
  404. printk("sbic: %c%c%c%c%c%c ",
  405. asr & ASR_INT ? 'I' : 'i',
  406. asr & ASR_LCI ? 'L' : 'l',
  407. asr & ASR_BSY ? 'B' : 'b',
  408. asr & ASR_CIP ? 'C' : 'c',
  409. asr & ASR_PE ? 'P' : 'p',
  410. asr & ASR_DBR ? 'D' : 'd');
  411. printk("scsi: ");
  412. print_scsi_status(ssr);
  413. printk(" ph %02X\n", cmdphase);
  414. #else
  415. printk("sbic: %02X scsi: %X:%X ph: %02X\n",
  416. asr, (ssr & 0xf0)>>4, ssr & 0x0f, cmdphase);
  417. #endif
  418. }
  419. static void
  420. acornscsi_dumplogline(AS_Host *host, int target, int line)
  421. {
  422. unsigned long prev;
  423. signed int ptr;
  424. ptr = host->status_ptr[target] - STATUS_BUFFER_TO_PRINT;
  425. if (ptr < 0)
  426. ptr += STATUS_BUFFER_SIZE;
  427. printk("%c: %3s:", target == 8 ? 'H' : '0' + target,
  428. line == 0 ? "ph" : line == 1 ? "ssr" : "int");
  429. prev = host->status[target][ptr].when;
  430. for (; ptr != host->status_ptr[target]; ptr = (ptr + 1) & (STATUS_BUFFER_SIZE - 1)) {
  431. unsigned long time_diff;
  432. if (!host->status[target][ptr].when)
  433. continue;
  434. switch (line) {
  435. case 0:
  436. printk("%c%02X", host->status[target][ptr].irq ? '-' : ' ',
  437. host->status[target][ptr].ph);
  438. break;
  439. case 1:
  440. printk(" %02X", host->status[target][ptr].ssr);
  441. break;
  442. case 2:
  443. time_diff = host->status[target][ptr].when - prev;
  444. prev = host->status[target][ptr].when;
  445. if (time_diff == 0)
  446. printk("==^");
  447. else if (time_diff >= 100)
  448. printk(" ");
  449. else
  450. printk(" %02ld", time_diff);
  451. break;
  452. }
  453. }
  454. printk("\n");
  455. }
  456. static
  457. void acornscsi_dumplog(AS_Host *host, int target)
  458. {
  459. do {
  460. acornscsi_dumplogline(host, target, 0);
  461. acornscsi_dumplogline(host, target, 1);
  462. acornscsi_dumplogline(host, target, 2);
  463. if (target == 8)
  464. break;
  465. target = 8;
  466. } while (1);
  467. }
  468. static
  469. char acornscsi_target(AS_Host *host)
  470. {
  471. if (host->SCpnt)
  472. return '0' + host->SCpnt->device->id;
  473. return 'H';
  474. }
  475. /*
  476. * Prototype: cmdtype_t acornscsi_cmdtype(int command)
  477. * Purpose : differentiate READ from WRITE from other commands
  478. * Params : command - command to interpret
  479. * Returns : CMD_READ - command reads data,
  480. * CMD_WRITE - command writes data,
  481. * CMD_MISC - everything else
  482. */
  483. static inline
  484. cmdtype_t acornscsi_cmdtype(int command)
  485. {
  486. switch (command) {
  487. case WRITE_6: case WRITE_10: case WRITE_12:
  488. return CMD_WRITE;
  489. case READ_6: case READ_10: case READ_12:
  490. return CMD_READ;
  491. default:
  492. return CMD_MISC;
  493. }
  494. }
  495. /*
  496. * Prototype: int acornscsi_datadirection(int command)
  497. * Purpose : differentiate between commands that have a DATA IN phase
  498. * and a DATA OUT phase
  499. * Params : command - command to interpret
  500. * Returns : DATADIR_OUT - data out phase expected
  501. * DATADIR_IN - data in phase expected
  502. */
  503. static
  504. datadir_t acornscsi_datadirection(int command)
  505. {
  506. switch (command) {
  507. case CHANGE_DEFINITION: case COMPARE: case COPY:
  508. case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
  509. case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
  510. case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
  511. case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
  512. case WRITE_6: case WRITE_10: case WRITE_VERIFY:
  513. case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
  514. case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
  515. case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
  516. case MEDIUM_SCAN: case SEND_VOLUME_TAG: case 0xea:
  517. return DATADIR_OUT;
  518. default:
  519. return DATADIR_IN;
  520. }
  521. }
  522. /*
  523. * Purpose : provide values for synchronous transfers with 33C93.
  524. * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
  525. * Modified by Russell King for 8MHz WD33C93A
  526. */
  527. static struct sync_xfer_tbl {
  528. unsigned int period_ns;
  529. unsigned char reg_value;
  530. } sync_xfer_table[] = {
  531. { 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
  532. { 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
  533. { 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
  534. };
  535. /*
  536. * Prototype: int acornscsi_getperiod(unsigned char syncxfer)
  537. * Purpose : period for the synchronous transfer setting
  538. * Params : syncxfer SYNCXFER register value
  539. * Returns : period in ns.
  540. */
  541. static
  542. int acornscsi_getperiod(unsigned char syncxfer)
  543. {
  544. int i;
  545. syncxfer &= 0xf0;
  546. if (syncxfer == 0x10)
  547. syncxfer = 0;
  548. for (i = 1; sync_xfer_table[i].period_ns; i++)
  549. if (syncxfer == sync_xfer_table[i].reg_value)
  550. return sync_xfer_table[i].period_ns;
  551. return 0;
  552. }
  553. /*
  554. * Prototype: int round_period(unsigned int period)
  555. * Purpose : return index into above table for a required REQ period
  556. * Params : period - time (ns) for REQ
  557. * Returns : table index
  558. * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
  559. */
  560. static inline
  561. int round_period(unsigned int period)
  562. {
  563. int i;
  564. for (i = 1; sync_xfer_table[i].period_ns; i++) {
  565. if ((period <= sync_xfer_table[i].period_ns) &&
  566. (period > sync_xfer_table[i - 1].period_ns))
  567. return i;
  568. }
  569. return 7;
  570. }
  571. /*
  572. * Prototype: unsigned char calc_sync_xfer(unsigned int period, unsigned int offset)
  573. * Purpose : calculate value for 33c93s SYNC register
  574. * Params : period - time (ns) for REQ
  575. * offset - offset in bytes between REQ/ACK
  576. * Returns : value for SYNC register
  577. * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
  578. */
  579. static
  580. unsigned char __maybe_unused calc_sync_xfer(unsigned int period,
  581. unsigned int offset)
  582. {
  583. return sync_xfer_table[round_period(period)].reg_value |
  584. ((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
  585. }
  586. /* ====================================================================================
  587. * Command functions
  588. */
  589. /*
  590. * Function: acornscsi_kick(AS_Host *host)
  591. * Purpose : kick next command to interface
  592. * Params : host - host to send command to
  593. * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
  594. * Notes : interrupts are always disabled!
  595. */
  596. static
  597. intr_ret_t acornscsi_kick(AS_Host *host)
  598. {
  599. int from_queue = 0;
  600. struct scsi_cmnd *SCpnt;
  601. /* first check to see if a command is waiting to be executed */
  602. SCpnt = host->origSCpnt;
  603. host->origSCpnt = NULL;
  604. /* retrieve next command */
  605. if (!SCpnt) {
  606. SCpnt = queue_remove_exclude(&host->queues.issue, host->busyluns);
  607. if (!SCpnt)
  608. return INTR_IDLE;
  609. from_queue = 1;
  610. }
  611. if (host->scsi.disconnectable && host->SCpnt) {
  612. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  613. host->scsi.disconnectable = 0;
  614. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  615. DBG(host->SCpnt, printk("scsi%d.%c: moved command to disconnected queue\n",
  616. host->host->host_no, acornscsi_target(host)));
  617. #endif
  618. host->SCpnt = NULL;
  619. }
  620. /*
  621. * If we have an interrupt pending, then we may have been reselected.
  622. * In this case, we don't want to write to the registers
  623. */
  624. if (!(sbic_arm_read(host, SBIC_ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
  625. sbic_arm_write(host, SBIC_DESTID, SCpnt->device->id);
  626. sbic_arm_write(host, SBIC_CMND, CMND_SELWITHATN);
  627. }
  628. /*
  629. * claim host busy - all of these must happen atomically wrt
  630. * our interrupt routine. Failure means command loss.
  631. */
  632. host->scsi.phase = PHASE_CONNECTING;
  633. host->SCpnt = SCpnt;
  634. host->scsi.SCp = SCpnt->SCp;
  635. host->dma.xfer_setup = 0;
  636. host->dma.xfer_required = 0;
  637. host->dma.xfer_done = 0;
  638. #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
  639. DBG(SCpnt,printk("scsi%d.%c: starting cmd %02X\n",
  640. host->host->host_no, '0' + SCpnt->device->id,
  641. SCpnt->cmnd[0]));
  642. #endif
  643. if (from_queue) {
  644. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  645. /*
  646. * tagged queueing - allocate a new tag to this command
  647. */
  648. if (SCpnt->device->simple_tags) {
  649. SCpnt->device->current_tag += 1;
  650. if (SCpnt->device->current_tag == 0)
  651. SCpnt->device->current_tag = 1;
  652. SCpnt->tag = SCpnt->device->current_tag;
  653. } else
  654. #endif
  655. set_bit(SCpnt->device->id * 8 +
  656. (u8)(SCpnt->device->lun & 0x07), host->busyluns);
  657. host->stats.removes += 1;
  658. switch (acornscsi_cmdtype(SCpnt->cmnd[0])) {
  659. case CMD_WRITE:
  660. host->stats.writes += 1;
  661. break;
  662. case CMD_READ:
  663. host->stats.reads += 1;
  664. break;
  665. case CMD_MISC:
  666. host->stats.miscs += 1;
  667. break;
  668. }
  669. }
  670. return INTR_PROCESSING;
  671. }
  672. /*
  673. * Function: void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, unsigned int result)
  674. * Purpose : complete processing for command
  675. * Params : host - interface that completed
  676. * result - driver byte of result
  677. */
  678. static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
  679. unsigned int result)
  680. {
  681. struct scsi_cmnd *SCpnt = *SCpntp;
  682. /* clean up */
  683. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  684. host->stats.fins += 1;
  685. if (SCpnt) {
  686. *SCpntp = NULL;
  687. acornscsi_dma_cleanup(host);
  688. SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
  689. /*
  690. * In theory, this should not happen. In practice, it seems to.
  691. * Only trigger an error if the device attempts to report all happy
  692. * but with untransferred buffers... If we don't do something, then
  693. * data loss will occur. Should we check SCpnt->underflow here?
  694. * It doesn't appear to be set to something meaningful by the higher
  695. * levels all the time.
  696. */
  697. if (result == DID_OK) {
  698. int xfer_warn = 0;
  699. if (SCpnt->underflow == 0) {
  700. if (host->scsi.SCp.ptr &&
  701. acornscsi_cmdtype(SCpnt->cmnd[0]) != CMD_MISC)
  702. xfer_warn = 1;
  703. } else {
  704. if (host->scsi.SCp.scsi_xferred < SCpnt->underflow ||
  705. host->scsi.SCp.scsi_xferred != host->dma.transferred)
  706. xfer_warn = 1;
  707. }
  708. /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
  709. * Targets which break data transfers into multiple
  710. * connections shall end each successful connection
  711. * (except possibly the last) with a SAVE DATA
  712. * POINTER - DISCONNECT message sequence.
  713. *
  714. * This makes it difficult to ensure that a transfer has
  715. * completed. If we reach the end of a transfer during
  716. * the command, then we can only have finished the transfer.
  717. * therefore, if we seem to have some data remaining, this
  718. * is not a problem.
  719. */
  720. if (host->dma.xfer_done)
  721. xfer_warn = 0;
  722. if (xfer_warn) {
  723. switch (status_byte(SCpnt->result)) {
  724. case CHECK_CONDITION:
  725. case COMMAND_TERMINATED:
  726. case BUSY:
  727. case QUEUE_FULL:
  728. case RESERVATION_CONFLICT:
  729. break;
  730. default:
  731. scmd_printk(KERN_ERR, SCpnt,
  732. "incomplete data transfer detected: "
  733. "result=%08X", SCpnt->result);
  734. scsi_print_command(SCpnt);
  735. acornscsi_dumpdma(host, "done");
  736. acornscsi_dumplog(host, SCpnt->device->id);
  737. set_host_byte(SCpnt, DID_ERROR);
  738. }
  739. }
  740. }
  741. if (!SCpnt->scsi_done)
  742. panic("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
  743. clear_bit(SCpnt->device->id * 8 +
  744. (u8)(SCpnt->device->lun & 0x7), host->busyluns);
  745. SCpnt->scsi_done(SCpnt);
  746. } else
  747. printk("scsi%d: null command in acornscsi_done", host->host->host_no);
  748. host->scsi.phase = PHASE_IDLE;
  749. }
  750. /* ====================================================================================
  751. * DMA routines
  752. */
  753. /*
  754. * Purpose : update SCSI Data Pointer
  755. * Notes : this will only be one SG entry or less
  756. */
  757. static
  758. void acornscsi_data_updateptr(AS_Host *host, struct scsi_pointer *SCp, unsigned int length)
  759. {
  760. SCp->ptr += length;
  761. SCp->this_residual -= length;
  762. if (SCp->this_residual == 0 && next_SCp(SCp) == 0)
  763. host->dma.xfer_done = 1;
  764. }
  765. /*
  766. * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
  767. * unsigned int start_addr, unsigned int length)
  768. * Purpose : read data from DMA RAM
  769. * Params : host - host to transfer from
  770. * ptr - DRAM address
  771. * start_addr - host mem address
  772. * length - number of bytes to transfer
  773. * Notes : this will only be one SG entry or less
  774. */
  775. static
  776. void acornscsi_data_read(AS_Host *host, char *ptr,
  777. unsigned int start_addr, unsigned int length)
  778. {
  779. extern void __acornscsi_in(void __iomem *, char *buf, int len);
  780. unsigned int page, offset, len = length;
  781. page = (start_addr >> 12);
  782. offset = start_addr & ((1 << 12) - 1);
  783. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  784. while (len > 0) {
  785. unsigned int this_len;
  786. if (len + offset > (1 << 12))
  787. this_len = (1 << 12) - offset;
  788. else
  789. this_len = len;
  790. __acornscsi_in(host->base + (offset << 1), ptr, this_len);
  791. offset += this_len;
  792. ptr += this_len;
  793. len -= this_len;
  794. if (offset == (1 << 12)) {
  795. offset = 0;
  796. page ++;
  797. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  798. }
  799. }
  800. writeb(host->card.page_reg, host->fast + PAGE_REG);
  801. }
  802. /*
  803. * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
  804. * unsigned int start_addr, unsigned int length)
  805. * Purpose : write data to DMA RAM
  806. * Params : host - host to transfer from
  807. * ptr - DRAM address
  808. * start_addr - host mem address
  809. * length - number of bytes to transfer
  810. * Notes : this will only be one SG entry or less
  811. */
  812. static
  813. void acornscsi_data_write(AS_Host *host, char *ptr,
  814. unsigned int start_addr, unsigned int length)
  815. {
  816. extern void __acornscsi_out(void __iomem *, char *buf, int len);
  817. unsigned int page, offset, len = length;
  818. page = (start_addr >> 12);
  819. offset = start_addr & ((1 << 12) - 1);
  820. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  821. while (len > 0) {
  822. unsigned int this_len;
  823. if (len + offset > (1 << 12))
  824. this_len = (1 << 12) - offset;
  825. else
  826. this_len = len;
  827. __acornscsi_out(host->base + (offset << 1), ptr, this_len);
  828. offset += this_len;
  829. ptr += this_len;
  830. len -= this_len;
  831. if (offset == (1 << 12)) {
  832. offset = 0;
  833. page ++;
  834. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  835. }
  836. }
  837. writeb(host->card.page_reg, host->fast + PAGE_REG);
  838. }
  839. /* =========================================================================================
  840. * On-board DMA routines
  841. */
  842. #ifdef USE_DMAC
  843. /*
  844. * Prototype: void acornscsi_dmastop(AS_Host *host)
  845. * Purpose : stop all DMA
  846. * Params : host - host on which to stop DMA
  847. * Notes : This is called when leaving DATA IN/OUT phase,
  848. * or when interface is RESET
  849. */
  850. static inline
  851. void acornscsi_dma_stop(AS_Host *host)
  852. {
  853. dmac_write(host, DMAC_MASKREG, MASK_ON);
  854. dmac_clearintr(host);
  855. #if (DEBUG & DEBUG_DMA)
  856. DBG(host->SCpnt, acornscsi_dumpdma(host, "stop"));
  857. #endif
  858. }
  859. /*
  860. * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
  861. * Purpose : setup DMA controller for data transfer
  862. * Params : host - host to setup
  863. * direction - data transfer direction
  864. * Notes : This is called when entering DATA I/O phase, not
  865. * while we're in a DATA I/O phase
  866. */
  867. static
  868. void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
  869. {
  870. unsigned int address, length, mode;
  871. host->dma.direction = direction;
  872. dmac_write(host, DMAC_MASKREG, MASK_ON);
  873. if (direction == DMA_OUT) {
  874. #if (DEBUG & DEBUG_NO_WRITE)
  875. if (NO_WRITE & (1 << host->SCpnt->device->id)) {
  876. printk(KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
  877. host->host->host_no, acornscsi_target(host));
  878. return;
  879. }
  880. #endif
  881. mode = DMAC_WRITE;
  882. } else
  883. mode = DMAC_READ;
  884. /*
  885. * Allocate some buffer space, limited to half the buffer size
  886. */
  887. length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
  888. if (length) {
  889. host->dma.start_addr = address = host->dma.free_addr;
  890. host->dma.free_addr = (host->dma.free_addr + length) &
  891. (DMAC_BUFFER_SIZE - 1);
  892. /*
  893. * Transfer data to DMA memory
  894. */
  895. if (direction == DMA_OUT)
  896. acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
  897. length);
  898. length -= 1;
  899. dmac_write(host, DMAC_TXCNTLO, length);
  900. dmac_write(host, DMAC_TXCNTHI, length >> 8);
  901. dmac_write(host, DMAC_TXADRLO, address);
  902. dmac_write(host, DMAC_TXADRMD, address >> 8);
  903. dmac_write(host, DMAC_TXADRHI, 0);
  904. dmac_write(host, DMAC_MODECON, mode);
  905. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  906. #if (DEBUG & DEBUG_DMA)
  907. DBG(host->SCpnt, acornscsi_dumpdma(host, "strt"));
  908. #endif
  909. host->dma.xfer_setup = 1;
  910. }
  911. }
  912. /*
  913. * Function: void acornscsi_dma_cleanup(AS_Host *host)
  914. * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
  915. * Params : host - host to finish
  916. * Notes : This is called when a command is:
  917. * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONNECT
  918. * : This must not return until all transfers are completed.
  919. */
  920. static
  921. void acornscsi_dma_cleanup(AS_Host *host)
  922. {
  923. dmac_write(host, DMAC_MASKREG, MASK_ON);
  924. dmac_clearintr(host);
  925. /*
  926. * Check for a pending transfer
  927. */
  928. if (host->dma.xfer_required) {
  929. host->dma.xfer_required = 0;
  930. if (host->dma.direction == DMA_IN)
  931. acornscsi_data_read(host, host->dma.xfer_ptr,
  932. host->dma.xfer_start, host->dma.xfer_length);
  933. }
  934. /*
  935. * Has a transfer been setup?
  936. */
  937. if (host->dma.xfer_setup) {
  938. unsigned int transferred;
  939. host->dma.xfer_setup = 0;
  940. #if (DEBUG & DEBUG_DMA)
  941. DBG(host->SCpnt, acornscsi_dumpdma(host, "cupi"));
  942. #endif
  943. /*
  944. * Calculate number of bytes transferred from DMA.
  945. */
  946. transferred = dmac_address(host) - host->dma.start_addr;
  947. host->dma.transferred += transferred;
  948. if (host->dma.direction == DMA_IN)
  949. acornscsi_data_read(host, host->scsi.SCp.ptr,
  950. host->dma.start_addr, transferred);
  951. /*
  952. * Update SCSI pointers
  953. */
  954. acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
  955. #if (DEBUG & DEBUG_DMA)
  956. DBG(host->SCpnt, acornscsi_dumpdma(host, "cupo"));
  957. #endif
  958. }
  959. }
  960. /*
  961. * Function: void acornscsi_dmacintr(AS_Host *host)
  962. * Purpose : handle interrupts from DMAC device
  963. * Params : host - host to process
  964. * Notes : If reading, we schedule the read to main memory &
  965. * allow the transfer to continue.
  966. * : If writing, we fill the onboard DMA memory from main
  967. * memory.
  968. * : Called whenever DMAC finished it's current transfer.
  969. */
  970. static
  971. void acornscsi_dma_intr(AS_Host *host)
  972. {
  973. unsigned int address, length, transferred;
  974. #if (DEBUG & DEBUG_DMA)
  975. DBG(host->SCpnt, acornscsi_dumpdma(host, "inti"));
  976. #endif
  977. dmac_write(host, DMAC_MASKREG, MASK_ON);
  978. dmac_clearintr(host);
  979. /*
  980. * Calculate amount transferred via DMA
  981. */
  982. transferred = dmac_address(host) - host->dma.start_addr;
  983. host->dma.transferred += transferred;
  984. /*
  985. * Schedule DMA transfer off board
  986. */
  987. if (host->dma.direction == DMA_IN) {
  988. host->dma.xfer_start = host->dma.start_addr;
  989. host->dma.xfer_length = transferred;
  990. host->dma.xfer_ptr = host->scsi.SCp.ptr;
  991. host->dma.xfer_required = 1;
  992. }
  993. acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
  994. /*
  995. * Allocate some buffer space, limited to half the on-board RAM size
  996. */
  997. length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
  998. if (length) {
  999. host->dma.start_addr = address = host->dma.free_addr;
  1000. host->dma.free_addr = (host->dma.free_addr + length) &
  1001. (DMAC_BUFFER_SIZE - 1);
  1002. /*
  1003. * Transfer data to DMA memory
  1004. */
  1005. if (host->dma.direction == DMA_OUT)
  1006. acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
  1007. length);
  1008. length -= 1;
  1009. dmac_write(host, DMAC_TXCNTLO, length);
  1010. dmac_write(host, DMAC_TXCNTHI, length >> 8);
  1011. dmac_write(host, DMAC_TXADRLO, address);
  1012. dmac_write(host, DMAC_TXADRMD, address >> 8);
  1013. dmac_write(host, DMAC_TXADRHI, 0);
  1014. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  1015. #if (DEBUG & DEBUG_DMA)
  1016. DBG(host->SCpnt, acornscsi_dumpdma(host, "into"));
  1017. #endif
  1018. } else {
  1019. host->dma.xfer_setup = 0;
  1020. #if 0
  1021. /*
  1022. * If the interface still wants more, then this is an error.
  1023. * We give it another byte, but we also attempt to raise an
  1024. * attention condition. We continue giving one byte until
  1025. * the device recognises the attention.
  1026. */
  1027. if (dmac_read(host, DMAC_STATUS) & STATUS_RQ0) {
  1028. acornscsi_abortcmd(host, host->SCpnt->tag);
  1029. dmac_write(host, DMAC_TXCNTLO, 0);
  1030. dmac_write(host, DMAC_TXCNTHI, 0);
  1031. dmac_write(host, DMAC_TXADRLO, 0);
  1032. dmac_write(host, DMAC_TXADRMD, 0);
  1033. dmac_write(host, DMAC_TXADRHI, 0);
  1034. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  1035. }
  1036. #endif
  1037. }
  1038. }
  1039. /*
  1040. * Function: void acornscsi_dma_xfer(AS_Host *host)
  1041. * Purpose : transfer data between AcornSCSI and memory
  1042. * Params : host - host to process
  1043. */
  1044. static
  1045. void acornscsi_dma_xfer(AS_Host *host)
  1046. {
  1047. host->dma.xfer_required = 0;
  1048. if (host->dma.direction == DMA_IN)
  1049. acornscsi_data_read(host, host->dma.xfer_ptr,
  1050. host->dma.xfer_start, host->dma.xfer_length);
  1051. }
  1052. /*
  1053. * Function: void acornscsi_dma_adjust(AS_Host *host)
  1054. * Purpose : adjust DMA pointers & count for bytes transferred to
  1055. * SBIC but not SCSI bus.
  1056. * Params : host - host to adjust DMA count for
  1057. */
  1058. static
  1059. void acornscsi_dma_adjust(AS_Host *host)
  1060. {
  1061. if (host->dma.xfer_setup) {
  1062. signed long transferred;
  1063. #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
  1064. DBG(host->SCpnt, acornscsi_dumpdma(host, "adji"));
  1065. #endif
  1066. /*
  1067. * Calculate correct DMA address - DMA is ahead of SCSI bus while
  1068. * writing.
  1069. * host->scsi.SCp.scsi_xferred is the number of bytes
  1070. * actually transferred to/from the SCSI bus.
  1071. * host->dma.transferred is the number of bytes transferred
  1072. * over DMA since host->dma.start_addr was last set.
  1073. *
  1074. * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
  1075. * - host->dma.transferred
  1076. */
  1077. transferred = host->scsi.SCp.scsi_xferred - host->dma.transferred;
  1078. if (transferred < 0)
  1079. printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
  1080. host->host->host_no, acornscsi_target(host), transferred);
  1081. else if (transferred == 0)
  1082. host->dma.xfer_setup = 0;
  1083. else {
  1084. transferred += host->dma.start_addr;
  1085. dmac_write(host, DMAC_TXADRLO, transferred);
  1086. dmac_write(host, DMAC_TXADRMD, transferred >> 8);
  1087. dmac_write(host, DMAC_TXADRHI, transferred >> 16);
  1088. #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
  1089. DBG(host->SCpnt, acornscsi_dumpdma(host, "adjo"));
  1090. #endif
  1091. }
  1092. }
  1093. }
  1094. #endif
  1095. /* =========================================================================================
  1096. * Data I/O
  1097. */
  1098. static int
  1099. acornscsi_write_pio(AS_Host *host, char *bytes, int *ptr, int len, unsigned int max_timeout)
  1100. {
  1101. unsigned int asr, timeout = max_timeout;
  1102. int my_ptr = *ptr;
  1103. while (my_ptr < len) {
  1104. asr = sbic_arm_read(host, SBIC_ASR);
  1105. if (asr & ASR_DBR) {
  1106. timeout = max_timeout;
  1107. sbic_arm_write(host, SBIC_DATA, bytes[my_ptr++]);
  1108. } else if (asr & ASR_INT)
  1109. break;
  1110. else if (--timeout == 0)
  1111. break;
  1112. udelay(1);
  1113. }
  1114. *ptr = my_ptr;
  1115. return (timeout == 0) ? -1 : 0;
  1116. }
  1117. /*
  1118. * Function: void acornscsi_sendcommand(AS_Host *host)
  1119. * Purpose : send a command to a target
  1120. * Params : host - host which is connected to target
  1121. */
  1122. static void
  1123. acornscsi_sendcommand(AS_Host *host)
  1124. {
  1125. struct scsi_cmnd *SCpnt = host->SCpnt;
  1126. sbic_arm_write(host, SBIC_TRANSCNTH, 0);
  1127. sbic_arm_writenext(host, 0);
  1128. sbic_arm_writenext(host, SCpnt->cmd_len - host->scsi.SCp.sent_command);
  1129. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1130. if (acornscsi_write_pio(host, SCpnt->cmnd,
  1131. (int *)&host->scsi.SCp.sent_command, SCpnt->cmd_len, 1000000))
  1132. printk("scsi%d: timeout while sending command\n", host->host->host_no);
  1133. host->scsi.phase = PHASE_COMMAND;
  1134. }
  1135. static
  1136. void acornscsi_sendmessage(AS_Host *host)
  1137. {
  1138. unsigned int message_length = msgqueue_msglength(&host->scsi.msgs);
  1139. unsigned int msgnr;
  1140. struct message *msg;
  1141. #if (DEBUG & DEBUG_MESSAGES)
  1142. printk("scsi%d.%c: sending message ",
  1143. host->host->host_no, acornscsi_target(host));
  1144. #endif
  1145. switch (message_length) {
  1146. case 0:
  1147. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1148. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 1");
  1149. sbic_arm_write(host, SBIC_DATA, NOP);
  1150. host->scsi.last_message = NOP;
  1151. #if (DEBUG & DEBUG_MESSAGES)
  1152. printk("NOP");
  1153. #endif
  1154. break;
  1155. case 1:
  1156. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1157. msg = msgqueue_getmsg(&host->scsi.msgs, 0);
  1158. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 2");
  1159. sbic_arm_write(host, SBIC_DATA, msg->msg[0]);
  1160. host->scsi.last_message = msg->msg[0];
  1161. #if (DEBUG & DEBUG_MESSAGES)
  1162. spi_print_msg(msg->msg);
  1163. #endif
  1164. break;
  1165. default:
  1166. /*
  1167. * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
  1168. * 'When a target sends this (MESSAGE_REJECT) message, it
  1169. * shall change to MESSAGE IN phase and send this message
  1170. * prior to requesting additional message bytes from the
  1171. * initiator. This provides an interlock so that the
  1172. * initiator can determine which message byte is rejected.
  1173. */
  1174. sbic_arm_write(host, SBIC_TRANSCNTH, 0);
  1175. sbic_arm_writenext(host, 0);
  1176. sbic_arm_writenext(host, message_length);
  1177. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1178. msgnr = 0;
  1179. while ((msg = msgqueue_getmsg(&host->scsi.msgs, msgnr++)) != NULL) {
  1180. unsigned int i;
  1181. #if (DEBUG & DEBUG_MESSAGES)
  1182. spi_print_msg(msg);
  1183. #endif
  1184. i = 0;
  1185. if (acornscsi_write_pio(host, msg->msg, &i, msg->length, 1000000))
  1186. printk("scsi%d: timeout while sending message\n", host->host->host_no);
  1187. host->scsi.last_message = msg->msg[0];
  1188. if (msg->msg[0] == EXTENDED_MESSAGE)
  1189. host->scsi.last_message |= msg->msg[2] << 8;
  1190. if (i != msg->length)
  1191. break;
  1192. }
  1193. break;
  1194. }
  1195. #if (DEBUG & DEBUG_MESSAGES)
  1196. printk("\n");
  1197. #endif
  1198. }
  1199. /*
  1200. * Function: void acornscsi_readstatusbyte(AS_Host *host)
  1201. * Purpose : Read status byte from connected target
  1202. * Params : host - host connected to target
  1203. */
  1204. static
  1205. void acornscsi_readstatusbyte(AS_Host *host)
  1206. {
  1207. acornscsi_sbic_issuecmd(host, CMND_XFERINFO|CMND_SBT);
  1208. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "reading status byte");
  1209. host->scsi.SCp.Status = sbic_arm_read(host, SBIC_DATA);
  1210. }
  1211. /*
  1212. * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
  1213. * Purpose : Read one message byte from connected target
  1214. * Params : host - host connected to target
  1215. */
  1216. static
  1217. unsigned char acornscsi_readmessagebyte(AS_Host *host)
  1218. {
  1219. unsigned char message;
  1220. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1221. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "for message byte");
  1222. message = sbic_arm_read(host, SBIC_DATA);
  1223. /* wait for MSGIN-XFER-PAUSED */
  1224. acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after message byte");
  1225. sbic_arm_read(host, SBIC_SSR);
  1226. return message;
  1227. }
  1228. /*
  1229. * Function: void acornscsi_message(AS_Host *host)
  1230. * Purpose : Read complete message from connected target & action message
  1231. * Params : host - host connected to target
  1232. */
  1233. static
  1234. void acornscsi_message(AS_Host *host)
  1235. {
  1236. unsigned char message[16];
  1237. unsigned int msgidx = 0, msglen = 1;
  1238. do {
  1239. message[msgidx] = acornscsi_readmessagebyte(host);
  1240. switch (msgidx) {
  1241. case 0:
  1242. if (message[0] == EXTENDED_MESSAGE ||
  1243. (message[0] >= 0x20 && message[0] <= 0x2f))
  1244. msglen = 2;
  1245. break;
  1246. case 1:
  1247. if (message[0] == EXTENDED_MESSAGE)
  1248. msglen += message[msgidx];
  1249. break;
  1250. }
  1251. msgidx += 1;
  1252. if (msgidx < msglen) {
  1253. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1254. /* wait for next msg-in */
  1255. acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after negate ack");
  1256. sbic_arm_read(host, SBIC_SSR);
  1257. }
  1258. } while (msgidx < msglen);
  1259. #if (DEBUG & DEBUG_MESSAGES)
  1260. printk("scsi%d.%c: message in: ",
  1261. host->host->host_no, acornscsi_target(host));
  1262. spi_print_msg(message);
  1263. printk("\n");
  1264. #endif
  1265. if (host->scsi.phase == PHASE_RECONNECTED) {
  1266. /*
  1267. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
  1268. * 'Whenever a target reconnects to an initiator to continue
  1269. * a tagged I/O process, the SIMPLE QUEUE TAG message shall
  1270. * be sent immediately following the IDENTIFY message...'
  1271. */
  1272. if (message[0] == SIMPLE_QUEUE_TAG)
  1273. host->scsi.reconnected.tag = message[1];
  1274. if (acornscsi_reconnect_finish(host))
  1275. host->scsi.phase = PHASE_MSGIN;
  1276. }
  1277. switch (message[0]) {
  1278. case ABORT:
  1279. case ABORT_TAG:
  1280. case COMMAND_COMPLETE:
  1281. if (host->scsi.phase != PHASE_STATUSIN) {
  1282. printk(KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
  1283. host->host->host_no, acornscsi_target(host));
  1284. acornscsi_dumplog(host, host->SCpnt->device->id);
  1285. }
  1286. host->scsi.phase = PHASE_DONE;
  1287. host->scsi.SCp.Message = message[0];
  1288. break;
  1289. case SAVE_POINTERS:
  1290. /*
  1291. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
  1292. * 'The SAVE DATA POINTER message is sent from a target to
  1293. * direct the initiator to copy the active data pointer to
  1294. * the saved data pointer for the current I/O process.
  1295. */
  1296. acornscsi_dma_cleanup(host);
  1297. host->SCpnt->SCp = host->scsi.SCp;
  1298. host->SCpnt->SCp.sent_command = 0;
  1299. host->scsi.phase = PHASE_MSGIN;
  1300. break;
  1301. case RESTORE_POINTERS:
  1302. /*
  1303. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
  1304. * 'The RESTORE POINTERS message is sent from a target to
  1305. * direct the initiator to copy the most recently saved
  1306. * command, data, and status pointers for the I/O process
  1307. * to the corresponding active pointers. The command and
  1308. * status pointers shall be restored to the beginning of
  1309. * the present command and status areas.'
  1310. */
  1311. acornscsi_dma_cleanup(host);
  1312. host->scsi.SCp = host->SCpnt->SCp;
  1313. host->scsi.phase = PHASE_MSGIN;
  1314. break;
  1315. case DISCONNECT:
  1316. /*
  1317. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
  1318. * 'On those occasions when an error or exception condition occurs
  1319. * and the target elects to repeat the information transfer, the
  1320. * target may repeat the transfer either issuing a RESTORE POINTERS
  1321. * message or by disconnecting without issuing a SAVE POINTERS
  1322. * message. When reconnection is completed, the most recent
  1323. * saved pointer values are restored.'
  1324. */
  1325. acornscsi_dma_cleanup(host);
  1326. host->scsi.phase = PHASE_DISCONNECT;
  1327. break;
  1328. case MESSAGE_REJECT:
  1329. #if 0 /* this isn't needed any more */
  1330. /*
  1331. * If we were negociating sync transfer, we don't yet know if
  1332. * this REJECT is for the sync transfer or for the tagged queue/wide
  1333. * transfer. Re-initiate sync transfer negotiation now, and if
  1334. * we got a REJECT in response to SDTR, then it'll be set to DONE.
  1335. */
  1336. if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST)
  1337. host->device[host->SCpnt->device->id].sync_state = SYNC_NEGOCIATE;
  1338. #endif
  1339. /*
  1340. * If we have any messages waiting to go out, then assert ATN now
  1341. */
  1342. if (msgqueue_msglength(&host->scsi.msgs))
  1343. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1344. switch (host->scsi.last_message) {
  1345. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1346. case HEAD_OF_QUEUE_TAG:
  1347. case ORDERED_QUEUE_TAG:
  1348. case SIMPLE_QUEUE_TAG:
  1349. /*
  1350. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
  1351. * If a target does not implement tagged queuing and a queue tag
  1352. * message is received, it shall respond with a MESSAGE REJECT
  1353. * message and accept the I/O process as if it were untagged.
  1354. */
  1355. printk(KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
  1356. host->host->host_no, acornscsi_target(host));
  1357. host->SCpnt->device->simple_tags = 0;
  1358. set_bit(host->SCpnt->device->id * 8 +
  1359. (u8)(host->SCpnt->device->lun & 0x7), host->busyluns);
  1360. break;
  1361. #endif
  1362. case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
  1363. /*
  1364. * Target can't handle synchronous transfers
  1365. */
  1366. printk(KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
  1367. host->host->host_no, acornscsi_target(host));
  1368. host->device[host->SCpnt->device->id].sync_xfer = SYNCHTRANSFER_2DBA;
  1369. host->device[host->SCpnt->device->id].sync_state = SYNC_ASYNCHRONOUS;
  1370. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1371. break;
  1372. default:
  1373. break;
  1374. }
  1375. break;
  1376. case QUEUE_FULL:
  1377. /* TODO: target queue is full */
  1378. break;
  1379. case SIMPLE_QUEUE_TAG:
  1380. /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
  1381. printk("scsi%d.%c: reconnect queue tag %02X\n",
  1382. host->host->host_no, acornscsi_target(host),
  1383. message[1]);
  1384. break;
  1385. case EXTENDED_MESSAGE:
  1386. switch (message[2]) {
  1387. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  1388. case EXTENDED_SDTR:
  1389. if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST) {
  1390. /*
  1391. * We requested synchronous transfers. This isn't quite right...
  1392. * We can only say if this succeeded if we proceed on to execute the
  1393. * command from this message. If we get a MESSAGE PARITY ERROR,
  1394. * and the target retries fail, then we fallback to asynchronous mode
  1395. */
  1396. host->device[host->SCpnt->device->id].sync_state = SYNC_COMPLETED;
  1397. printk(KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
  1398. host->host->host_no, acornscsi_target(host),
  1399. message[4], message[3] * 4);
  1400. host->device[host->SCpnt->device->id].sync_xfer =
  1401. calc_sync_xfer(message[3] * 4, message[4]);
  1402. } else {
  1403. unsigned char period, length;
  1404. /*
  1405. * Target requested synchronous transfers. The agreement is only
  1406. * to be in operation AFTER the target leaves message out phase.
  1407. */
  1408. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1409. period = max_t(unsigned int, message[3], sdtr_period / 4);
  1410. length = min_t(unsigned int, message[4], sdtr_size);
  1411. msgqueue_addmsg(&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
  1412. EXTENDED_SDTR, period, length);
  1413. host->device[host->SCpnt->device->id].sync_xfer =
  1414. calc_sync_xfer(period * 4, length);
  1415. }
  1416. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1417. break;
  1418. #else
  1419. /* We do not accept synchronous transfers. Respond with a
  1420. * MESSAGE_REJECT.
  1421. */
  1422. #endif
  1423. case EXTENDED_WDTR:
  1424. /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
  1425. * to a wide data transfer request.
  1426. */
  1427. default:
  1428. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1429. msgqueue_flush(&host->scsi.msgs);
  1430. msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
  1431. break;
  1432. }
  1433. break;
  1434. default: /* reject message */
  1435. printk(KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
  1436. host->host->host_no, acornscsi_target(host),
  1437. message[0]);
  1438. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1439. msgqueue_flush(&host->scsi.msgs);
  1440. msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
  1441. host->scsi.phase = PHASE_MSGIN;
  1442. break;
  1443. }
  1444. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1445. }
  1446. /*
  1447. * Function: int acornscsi_buildmessages(AS_Host *host)
  1448. * Purpose : build the connection messages for a host
  1449. * Params : host - host to add messages to
  1450. */
  1451. static
  1452. void acornscsi_buildmessages(AS_Host *host)
  1453. {
  1454. #if 0
  1455. /* does the device need resetting? */
  1456. if (cmd_reset) {
  1457. msgqueue_addmsg(&host->scsi.msgs, 1, BUS_DEVICE_RESET);
  1458. return;
  1459. }
  1460. #endif
  1461. msgqueue_addmsg(&host->scsi.msgs, 1,
  1462. IDENTIFY(host->device[host->SCpnt->device->id].disconnect_ok,
  1463. host->SCpnt->device->lun));
  1464. #if 0
  1465. /* does the device need the current command aborted */
  1466. if (cmd_aborted) {
  1467. acornscsi_abortcmd(host->SCpnt->tag);
  1468. return;
  1469. }
  1470. #endif
  1471. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1472. if (host->SCpnt->tag) {
  1473. unsigned int tag_type;
  1474. if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
  1475. host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
  1476. host->SCpnt->cmnd[0] == INQUIRY)
  1477. tag_type = HEAD_OF_QUEUE_TAG;
  1478. else
  1479. tag_type = SIMPLE_QUEUE_TAG;
  1480. msgqueue_addmsg(&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
  1481. }
  1482. #endif
  1483. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  1484. if (host->device[host->SCpnt->device->id].sync_state == SYNC_NEGOCIATE) {
  1485. host->device[host->SCpnt->device->id].sync_state = SYNC_SENT_REQUEST;
  1486. msgqueue_addmsg(&host->scsi.msgs, 5,
  1487. EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
  1488. sdtr_period / 4, sdtr_size);
  1489. }
  1490. #endif
  1491. }
  1492. /*
  1493. * Function: int acornscsi_starttransfer(AS_Host *host)
  1494. * Purpose : transfer data to/from connected target
  1495. * Params : host - host to which target is connected
  1496. * Returns : 0 if failure
  1497. */
  1498. static
  1499. int acornscsi_starttransfer(AS_Host *host)
  1500. {
  1501. int residual;
  1502. if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
  1503. printk(KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
  1504. host->host->host_no, acornscsi_target(host));
  1505. return 0;
  1506. }
  1507. residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
  1508. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1509. sbic_arm_writenext(host, residual >> 16);
  1510. sbic_arm_writenext(host, residual >> 8);
  1511. sbic_arm_writenext(host, residual);
  1512. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1513. return 1;
  1514. }
  1515. /* =========================================================================================
  1516. * Connection & Disconnection
  1517. */
  1518. /*
  1519. * Function : acornscsi_reconnect(AS_Host *host)
  1520. * Purpose : reconnect a previously disconnected command
  1521. * Params : host - host specific data
  1522. * Remarks : SCSI spec says:
  1523. * 'The set of active pointers is restored from the set
  1524. * of saved pointers upon reconnection of the I/O process'
  1525. */
  1526. static
  1527. int acornscsi_reconnect(AS_Host *host)
  1528. {
  1529. unsigned int target, lun, ok = 0;
  1530. target = sbic_arm_read(host, SBIC_SOURCEID);
  1531. if (!(target & 8))
  1532. printk(KERN_ERR "scsi%d: invalid source id after reselection "
  1533. "- device fault?\n",
  1534. host->host->host_no);
  1535. target &= 7;
  1536. if (host->SCpnt && !host->scsi.disconnectable) {
  1537. printk(KERN_ERR "scsi%d.%d: reconnected while command in "
  1538. "progress to target %d?\n",
  1539. host->host->host_no, target, host->SCpnt->device->id);
  1540. host->SCpnt = NULL;
  1541. }
  1542. lun = sbic_arm_read(host, SBIC_DATA) & 7;
  1543. host->scsi.reconnected.target = target;
  1544. host->scsi.reconnected.lun = lun;
  1545. host->scsi.reconnected.tag = 0;
  1546. if (host->scsi.disconnectable && host->SCpnt &&
  1547. host->SCpnt->device->id == target && host->SCpnt->device->lun == lun)
  1548. ok = 1;
  1549. if (!ok && queue_probetgtlun(&host->queues.disconnected, target, lun))
  1550. ok = 1;
  1551. ADD_STATUS(target, 0x81, host->scsi.phase, 0);
  1552. if (ok) {
  1553. host->scsi.phase = PHASE_RECONNECTED;
  1554. } else {
  1555. /* this doesn't seem to work */
  1556. printk(KERN_ERR "scsi%d.%c: reselected with no command "
  1557. "to reconnect with\n",
  1558. host->host->host_no, '0' + target);
  1559. acornscsi_dumplog(host, target);
  1560. acornscsi_abortcmd(host, 0);
  1561. if (host->SCpnt) {
  1562. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  1563. host->SCpnt = NULL;
  1564. }
  1565. }
  1566. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1567. return !ok;
  1568. }
  1569. /*
  1570. * Function: int acornscsi_reconnect_finish(AS_Host *host)
  1571. * Purpose : finish reconnecting a command
  1572. * Params : host - host to complete
  1573. * Returns : 0 if failed
  1574. */
  1575. static
  1576. int acornscsi_reconnect_finish(AS_Host *host)
  1577. {
  1578. if (host->scsi.disconnectable && host->SCpnt) {
  1579. host->scsi.disconnectable = 0;
  1580. if (host->SCpnt->device->id == host->scsi.reconnected.target &&
  1581. host->SCpnt->device->lun == host->scsi.reconnected.lun &&
  1582. host->SCpnt->tag == host->scsi.reconnected.tag) {
  1583. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1584. DBG(host->SCpnt, printk("scsi%d.%c: reconnected",
  1585. host->host->host_no, acornscsi_target(host)));
  1586. #endif
  1587. } else {
  1588. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  1589. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1590. DBG(host->SCpnt, printk("scsi%d.%c: had to move command "
  1591. "to disconnected queue\n",
  1592. host->host->host_no, acornscsi_target(host)));
  1593. #endif
  1594. host->SCpnt = NULL;
  1595. }
  1596. }
  1597. if (!host->SCpnt) {
  1598. host->SCpnt = queue_remove_tgtluntag(&host->queues.disconnected,
  1599. host->scsi.reconnected.target,
  1600. host->scsi.reconnected.lun,
  1601. host->scsi.reconnected.tag);
  1602. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1603. DBG(host->SCpnt, printk("scsi%d.%c: had to get command",
  1604. host->host->host_no, acornscsi_target(host)));
  1605. #endif
  1606. }
  1607. if (!host->SCpnt)
  1608. acornscsi_abortcmd(host, host->scsi.reconnected.tag);
  1609. else {
  1610. /*
  1611. * Restore data pointer from SAVED pointers.
  1612. */
  1613. host->scsi.SCp = host->SCpnt->SCp;
  1614. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1615. printk(", data pointers: [%p, %X]",
  1616. host->scsi.SCp.ptr, host->scsi.SCp.this_residual);
  1617. #endif
  1618. }
  1619. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1620. printk("\n");
  1621. #endif
  1622. host->dma.transferred = host->scsi.SCp.scsi_xferred;
  1623. return host->SCpnt != NULL;
  1624. }
  1625. /*
  1626. * Function: void acornscsi_disconnect_unexpected(AS_Host *host)
  1627. * Purpose : handle an unexpected disconnect
  1628. * Params : host - host on which disconnect occurred
  1629. */
  1630. static
  1631. void acornscsi_disconnect_unexpected(AS_Host *host)
  1632. {
  1633. printk(KERN_ERR "scsi%d.%c: unexpected disconnect\n",
  1634. host->host->host_no, acornscsi_target(host));
  1635. #if (DEBUG & DEBUG_ABORT)
  1636. acornscsi_dumplog(host, 8);
  1637. #endif
  1638. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  1639. }
  1640. /*
  1641. * Function: void acornscsi_abortcmd(AS_host *host, unsigned char tag)
  1642. * Purpose : abort a currently executing command
  1643. * Params : host - host with connected command to abort
  1644. * tag - tag to abort
  1645. */
  1646. static
  1647. void acornscsi_abortcmd(AS_Host *host, unsigned char tag)
  1648. {
  1649. host->scsi.phase = PHASE_ABORTED;
  1650. sbic_arm_write(host, SBIC_CMND, CMND_ASSERTATN);
  1651. msgqueue_flush(&host->scsi.msgs);
  1652. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1653. if (tag)
  1654. msgqueue_addmsg(&host->scsi.msgs, 2, ABORT_TAG, tag);
  1655. else
  1656. #endif
  1657. msgqueue_addmsg(&host->scsi.msgs, 1, ABORT);
  1658. }
  1659. /* ==========================================================================================
  1660. * Interrupt routines.
  1661. */
  1662. /*
  1663. * Function: int acornscsi_sbicintr(AS_Host *host)
  1664. * Purpose : handle interrupts from SCSI device
  1665. * Params : host - host to process
  1666. * Returns : INTR_PROCESS if expecting another SBIC interrupt
  1667. * INTR_IDLE if no interrupt
  1668. * INTR_NEXT_COMMAND if we have finished processing the command
  1669. */
  1670. static
  1671. intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
  1672. {
  1673. unsigned int asr, ssr;
  1674. asr = sbic_arm_read(host, SBIC_ASR);
  1675. if (!(asr & ASR_INT))
  1676. return INTR_IDLE;
  1677. ssr = sbic_arm_read(host, SBIC_SSR);
  1678. #if (DEBUG & DEBUG_PHASES)
  1679. print_sbic_status(asr, ssr, host->scsi.phase);
  1680. #endif
  1681. ADD_STATUS(8, ssr, host->scsi.phase, in_irq);
  1682. if (host->SCpnt && !host->scsi.disconnectable)
  1683. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, in_irq);
  1684. switch (ssr) {
  1685. case 0x00: /* reset state - not advanced */
  1686. printk(KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
  1687. host->host->host_no);
  1688. /* setup sbic - WD33C93A */
  1689. sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
  1690. sbic_arm_write(host, SBIC_CMND, CMND_RESET);
  1691. return INTR_IDLE;
  1692. case 0x01: /* reset state - advanced */
  1693. sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
  1694. sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
  1695. sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
  1696. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  1697. msgqueue_flush(&host->scsi.msgs);
  1698. return INTR_IDLE;
  1699. case 0x41: /* unexpected disconnect aborted command */
  1700. acornscsi_disconnect_unexpected(host);
  1701. return INTR_NEXT_COMMAND;
  1702. }
  1703. switch (host->scsi.phase) {
  1704. case PHASE_CONNECTING: /* STATE: command removed from issue queue */
  1705. switch (ssr) {
  1706. case 0x11: /* -> PHASE_CONNECTED */
  1707. /* BUS FREE -> SELECTION */
  1708. host->scsi.phase = PHASE_CONNECTED;
  1709. msgqueue_flush(&host->scsi.msgs);
  1710. host->dma.transferred = host->scsi.SCp.scsi_xferred;
  1711. /* 33C93 gives next interrupt indicating bus phase */
  1712. asr = sbic_arm_read(host, SBIC_ASR);
  1713. if (!(asr & ASR_INT))
  1714. break;
  1715. ssr = sbic_arm_read(host, SBIC_SSR);
  1716. ADD_STATUS(8, ssr, host->scsi.phase, 1);
  1717. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, 1);
  1718. goto connected;
  1719. case 0x42: /* select timed out */
  1720. /* -> PHASE_IDLE */
  1721. acornscsi_done(host, &host->SCpnt, DID_NO_CONNECT);
  1722. return INTR_NEXT_COMMAND;
  1723. case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
  1724. /* BUS FREE -> RESELECTION */
  1725. host->origSCpnt = host->SCpnt;
  1726. host->SCpnt = NULL;
  1727. msgqueue_flush(&host->scsi.msgs);
  1728. acornscsi_reconnect(host);
  1729. break;
  1730. default:
  1731. printk(KERN_ERR "scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
  1732. host->host->host_no, acornscsi_target(host), ssr);
  1733. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1734. acornscsi_abortcmd(host, host->SCpnt->tag);
  1735. }
  1736. return INTR_PROCESSING;
  1737. connected:
  1738. case PHASE_CONNECTED: /* STATE: device selected ok */
  1739. switch (ssr) {
  1740. #ifdef NONSTANDARD
  1741. case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1742. /* SELECTION -> COMMAND */
  1743. acornscsi_sendcommand(host);
  1744. break;
  1745. case 0x8b: /* -> PHASE_STATUS */
  1746. /* SELECTION -> STATUS */
  1747. acornscsi_readstatusbyte(host);
  1748. host->scsi.phase = PHASE_STATUSIN;
  1749. break;
  1750. #endif
  1751. case 0x8e: /* -> PHASE_MSGOUT */
  1752. /* SELECTION ->MESSAGE OUT */
  1753. host->scsi.phase = PHASE_MSGOUT;
  1754. acornscsi_buildmessages(host);
  1755. acornscsi_sendmessage(host);
  1756. break;
  1757. /* these should not happen */
  1758. case 0x85: /* target disconnected */
  1759. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  1760. break;
  1761. default:
  1762. printk(KERN_ERR "scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
  1763. host->host->host_no, acornscsi_target(host), ssr);
  1764. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1765. acornscsi_abortcmd(host, host->SCpnt->tag);
  1766. }
  1767. return INTR_PROCESSING;
  1768. case PHASE_MSGOUT: /* STATE: connected & sent IDENTIFY message */
  1769. /*
  1770. * SCSI standard says that MESSAGE OUT phases can be followed by a
  1771. * DATA phase, STATUS phase, MESSAGE IN phase or COMMAND phase
  1772. */
  1773. switch (ssr) {
  1774. case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1775. case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1776. /* MESSAGE OUT -> COMMAND */
  1777. acornscsi_sendcommand(host);
  1778. break;
  1779. case 0x8b: /* -> PHASE_STATUS */
  1780. case 0x1b: /* -> PHASE_STATUS */
  1781. /* MESSAGE OUT -> STATUS */
  1782. acornscsi_readstatusbyte(host);
  1783. host->scsi.phase = PHASE_STATUSIN;
  1784. break;
  1785. case 0x8e: /* -> PHASE_MSGOUT */
  1786. /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
  1787. acornscsi_sendmessage(host);
  1788. break;
  1789. case 0x4f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1790. case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1791. /* MESSAGE OUT -> MESSAGE IN */
  1792. acornscsi_message(host);
  1793. break;
  1794. default:
  1795. printk(KERN_ERR "scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
  1796. host->host->host_no, acornscsi_target(host), ssr);
  1797. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1798. }
  1799. return INTR_PROCESSING;
  1800. case PHASE_COMMAND: /* STATE: connected & command sent */
  1801. switch (ssr) {
  1802. case 0x18: /* -> PHASE_DATAOUT */
  1803. /* COMMAND -> DATA OUT */
  1804. if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
  1805. acornscsi_abortcmd(host, host->SCpnt->tag);
  1806. acornscsi_dma_setup(host, DMA_OUT);
  1807. if (!acornscsi_starttransfer(host))
  1808. acornscsi_abortcmd(host, host->SCpnt->tag);
  1809. host->scsi.phase = PHASE_DATAOUT;
  1810. return INTR_IDLE;
  1811. case 0x19: /* -> PHASE_DATAIN */
  1812. /* COMMAND -> DATA IN */
  1813. if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
  1814. acornscsi_abortcmd(host, host->SCpnt->tag);
  1815. acornscsi_dma_setup(host, DMA_IN);
  1816. if (!acornscsi_starttransfer(host))
  1817. acornscsi_abortcmd(host, host->SCpnt->tag);
  1818. host->scsi.phase = PHASE_DATAIN;
  1819. return INTR_IDLE;
  1820. case 0x1b: /* -> PHASE_STATUS */
  1821. /* COMMAND -> STATUS */
  1822. acornscsi_readstatusbyte(host);
  1823. host->scsi.phase = PHASE_STATUSIN;
  1824. break;
  1825. case 0x1e: /* -> PHASE_MSGOUT */
  1826. /* COMMAND -> MESSAGE OUT */
  1827. acornscsi_sendmessage(host);
  1828. break;
  1829. case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1830. /* COMMAND -> MESSAGE IN */
  1831. acornscsi_message(host);
  1832. break;
  1833. default:
  1834. printk(KERN_ERR "scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
  1835. host->host->host_no, acornscsi_target(host), ssr);
  1836. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1837. }
  1838. return INTR_PROCESSING;
  1839. case PHASE_DISCONNECT: /* STATE: connected, received DISCONNECT msg */
  1840. if (ssr == 0x85) { /* -> PHASE_IDLE */
  1841. host->scsi.disconnectable = 1;
  1842. host->scsi.reconnected.tag = 0;
  1843. host->scsi.phase = PHASE_IDLE;
  1844. host->stats.disconnects += 1;
  1845. } else {
  1846. printk(KERN_ERR "scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
  1847. host->host->host_no, acornscsi_target(host), ssr);
  1848. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1849. }
  1850. return INTR_NEXT_COMMAND;
  1851. case PHASE_IDLE: /* STATE: disconnected */
  1852. if (ssr == 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
  1853. acornscsi_reconnect(host);
  1854. else {
  1855. printk(KERN_ERR "scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
  1856. host->host->host_no, acornscsi_target(host), ssr);
  1857. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1858. }
  1859. return INTR_PROCESSING;
  1860. case PHASE_RECONNECTED: /* STATE: device reconnected to initiator */
  1861. /*
  1862. * Command reconnected - if MESGIN, get message - it may be
  1863. * the tag. If not, get command out of disconnected queue
  1864. */
  1865. /*
  1866. * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
  1867. * reconnect I_T_L command
  1868. */
  1869. if (ssr != 0x8f && !acornscsi_reconnect_finish(host))
  1870. return INTR_IDLE;
  1871. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, in_irq);
  1872. switch (ssr) {
  1873. case 0x88: /* data out phase */
  1874. /* -> PHASE_DATAOUT */
  1875. /* MESSAGE IN -> DATA OUT */
  1876. acornscsi_dma_setup(host, DMA_OUT);
  1877. if (!acornscsi_starttransfer(host))
  1878. acornscsi_abortcmd(host, host->SCpnt->tag);
  1879. host->scsi.phase = PHASE_DATAOUT;
  1880. return INTR_IDLE;
  1881. case 0x89: /* data in phase */
  1882. /* -> PHASE_DATAIN */
  1883. /* MESSAGE IN -> DATA IN */
  1884. acornscsi_dma_setup(host, DMA_IN);
  1885. if (!acornscsi_starttransfer(host))
  1886. acornscsi_abortcmd(host, host->SCpnt->tag);
  1887. host->scsi.phase = PHASE_DATAIN;
  1888. return INTR_IDLE;
  1889. case 0x8a: /* command out */
  1890. /* MESSAGE IN -> COMMAND */
  1891. acornscsi_sendcommand(host);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1892. break;
  1893. case 0x8b: /* status in */
  1894. /* -> PHASE_STATUSIN */
  1895. /* MESSAGE IN -> STATUS */
  1896. acornscsi_readstatusbyte(host);
  1897. host->scsi.phase = PHASE_STATUSIN;
  1898. break;
  1899. case 0x8e: /* message out */
  1900. /* -> PHASE_MSGOUT */
  1901. /* MESSAGE IN -> MESSAGE OUT */
  1902. acornscsi_sendmessage(host);
  1903. break;
  1904. case 0x8f: /* message in */
  1905. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1906. break;
  1907. default:
  1908. printk(KERN_ERR "scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
  1909. host->host->host_no, acornscsi_target(host), ssr);
  1910. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1911. }
  1912. return INTR_PROCESSING;
  1913. case PHASE_DATAIN: /* STATE: transferred data in */
  1914. /*
  1915. * This is simple - if we disconnect then the DMA address & count is
  1916. * correct.
  1917. */
  1918. switch (ssr) {
  1919. case 0x19: /* -> PHASE_DATAIN */
  1920. case 0x89: /* -> PHASE_DATAIN */
  1921. acornscsi_abortcmd(host, host->SCpnt->tag);
  1922. return INTR_IDLE;
  1923. case 0x1b: /* -> PHASE_STATUSIN */
  1924. case 0x4b: /* -> PHASE_STATUSIN */
  1925. case 0x8b: /* -> PHASE_STATUSIN */
  1926. /* DATA IN -> STATUS */
  1927. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1928. acornscsi_sbic_xfcount(host);
  1929. acornscsi_dma_stop(host);
  1930. acornscsi_readstatusbyte(host);
  1931. host->scsi.phase = PHASE_STATUSIN;
  1932. break;
  1933. case 0x1e: /* -> PHASE_MSGOUT */
  1934. case 0x4e: /* -> PHASE_MSGOUT */
  1935. case 0x8e: /* -> PHASE_MSGOUT */
  1936. /* DATA IN -> MESSAGE OUT */
  1937. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1938. acornscsi_sbic_xfcount(host);
  1939. acornscsi_dma_stop(host);
  1940. acornscsi_sendmessage(host);
  1941. break;
  1942. case 0x1f: /* message in */
  1943. case 0x4f: /* message in */
  1944. case 0x8f: /* message in */
  1945. /* DATA IN -> MESSAGE IN */
  1946. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1947. acornscsi_sbic_xfcount(host);
  1948. acornscsi_dma_stop(host);
  1949. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1950. break;
  1951. default:
  1952. printk(KERN_ERR "scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
  1953. host->host->host_no, acornscsi_target(host), ssr);
  1954. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1955. }
  1956. return INTR_PROCESSING;
  1957. case PHASE_DATAOUT: /* STATE: transferred data out */
  1958. /*
  1959. * This is more complicated - if we disconnect, the DMA could be 12
  1960. * bytes ahead of us. We need to correct this.
  1961. */
  1962. switch (ssr) {
  1963. case 0x18: /* -> PHASE_DATAOUT */
  1964. case 0x88: /* -> PHASE_DATAOUT */
  1965. acornscsi_abortcmd(host, host->SCpnt->tag);
  1966. return INTR_IDLE;
  1967. case 0x1b: /* -> PHASE_STATUSIN */
  1968. case 0x4b: /* -> PHASE_STATUSIN */
  1969. case 0x8b: /* -> PHASE_STATUSIN */
  1970. /* DATA OUT -> STATUS */
  1971. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1972. acornscsi_sbic_xfcount(host);
  1973. acornscsi_dma_stop(host);
  1974. acornscsi_dma_adjust(host);
  1975. acornscsi_readstatusbyte(host);
  1976. host->scsi.phase = PHASE_STATUSIN;
  1977. break;
  1978. case 0x1e: /* -> PHASE_MSGOUT */
  1979. case 0x4e: /* -> PHASE_MSGOUT */
  1980. case 0x8e: /* -> PHASE_MSGOUT */
  1981. /* DATA OUT -> MESSAGE OUT */
  1982. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1983. acornscsi_sbic_xfcount(host);
  1984. acornscsi_dma_stop(host);
  1985. acornscsi_dma_adjust(host);
  1986. acornscsi_sendmessage(host);
  1987. break;
  1988. case 0x1f: /* message in */
  1989. case 0x4f: /* message in */
  1990. case 0x8f: /* message in */
  1991. /* DATA OUT -> MESSAGE IN */
  1992. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1993. acornscsi_sbic_xfcount(host);
  1994. acornscsi_dma_stop(host);
  1995. acornscsi_dma_adjust(host);
  1996. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1997. break;
  1998. default:
  1999. printk(KERN_ERR "scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
  2000. host->host->host_no, acornscsi_target(host), ssr);
  2001. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2002. }
  2003. return INTR_PROCESSING;
  2004. case PHASE_STATUSIN: /* STATE: status in complete */
  2005. switch (ssr) {
  2006. case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2007. case 0x8f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2008. /* STATUS -> MESSAGE IN */
  2009. acornscsi_message(host);
  2010. break;
  2011. case 0x1e: /* -> PHASE_MSGOUT */
  2012. case 0x8e: /* -> PHASE_MSGOUT */
  2013. /* STATUS -> MESSAGE OUT */
  2014. acornscsi_sendmessage(host);
  2015. break;
  2016. default:
  2017. printk(KERN_ERR "scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
  2018. host->host->host_no, acornscsi_target(host), ssr);
  2019. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2020. }
  2021. return INTR_PROCESSING;
  2022. case PHASE_MSGIN: /* STATE: message in */
  2023. switch (ssr) {
  2024. case 0x1e: /* -> PHASE_MSGOUT */
  2025. case 0x4e: /* -> PHASE_MSGOUT */
  2026. case 0x8e: /* -> PHASE_MSGOUT */
  2027. /* MESSAGE IN -> MESSAGE OUT */
  2028. acornscsi_sendmessage(host);
  2029. break;
  2030. case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2031. case 0x2f:
  2032. case 0x4f:
  2033. case 0x8f:
  2034. acornscsi_message(host);
  2035. break;
  2036. case 0x85:
  2037. printk("scsi%d.%c: strange message in disconnection\n",
  2038. host->host->host_no, acornscsi_target(host));
  2039. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2040. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  2041. break;
  2042. default:
  2043. printk(KERN_ERR "scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
  2044. host->host->host_no, acornscsi_target(host), ssr);
  2045. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2046. }
  2047. return INTR_PROCESSING;
  2048. case PHASE_DONE: /* STATE: received status & message */
  2049. switch (ssr) {
  2050. case 0x85: /* -> PHASE_IDLE */
  2051. acornscsi_done(host, &host->SCpnt, DID_OK);
  2052. return INTR_NEXT_COMMAND;
  2053. case 0x1e:
  2054. case 0x8e:
  2055. acornscsi_sendmessage(host);
  2056. break;
  2057. default:
  2058. printk(KERN_ERR "scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
  2059. host->host->host_no, acornscsi_target(host), ssr);
  2060. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2061. }
  2062. return INTR_PROCESSING;
  2063. case PHASE_ABORTED:
  2064. switch (ssr) {
  2065. case 0x85:
  2066. if (host->SCpnt)
  2067. acornscsi_done(host, &host->SCpnt, DID_ABORT);
  2068. else {
  2069. clear_bit(host->scsi.reconnected.target * 8 + host->scsi.reconnected.lun,
  2070. host->busyluns);
  2071. host->scsi.phase = PHASE_IDLE;
  2072. }
  2073. return INTR_NEXT_COMMAND;
  2074. case 0x1e:
  2075. case 0x2e:
  2076. case 0x4e:
  2077. case 0x8e:
  2078. acornscsi_sendmessage(host);
  2079. break;
  2080. default:
  2081. printk(KERN_ERR "scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
  2082. host->host->host_no, acornscsi_target(host), ssr);
  2083. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2084. }
  2085. return INTR_PROCESSING;
  2086. default:
  2087. printk(KERN_ERR "scsi%d.%c: unknown driver phase %d\n",
  2088. host->host->host_no, acornscsi_target(host), ssr);
  2089. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2090. }
  2091. return INTR_PROCESSING;
  2092. }
  2093. /*
  2094. * Prototype: void acornscsi_intr(int irq, void *dev_id)
  2095. * Purpose : handle interrupts from Acorn SCSI card
  2096. * Params : irq - interrupt number
  2097. * dev_id - device specific data (AS_Host structure)
  2098. */
  2099. static irqreturn_t
  2100. acornscsi_intr(int irq, void *dev_id)
  2101. {
  2102. AS_Host *host = (AS_Host *)dev_id;
  2103. intr_ret_t ret;
  2104. int iostatus;
  2105. int in_irq = 0;
  2106. do {
  2107. ret = INTR_IDLE;
  2108. iostatus = readb(host->fast + INT_REG);
  2109. if (iostatus & 2) {
  2110. acornscsi_dma_intr(host);
  2111. iostatus = readb(host->fast + INT_REG);
  2112. }
  2113. if (iostatus & 8)
  2114. ret = acornscsi_sbicintr(host, in_irq);
  2115. /*
  2116. * If we have a transfer pending, start it.
  2117. * Only start it if the interface has already started transferring
  2118. * it's data
  2119. */
  2120. if (host->dma.xfer_required)
  2121. acornscsi_dma_xfer(host);
  2122. if (ret == INTR_NEXT_COMMAND)
  2123. ret = acornscsi_kick(host);
  2124. in_irq = 1;
  2125. } while (ret != INTR_IDLE);
  2126. return IRQ_HANDLED;
  2127. }
  2128. /*=============================================================================================
  2129. * Interfaces between interrupt handler and rest of scsi code
  2130. */
  2131. /*
  2132. * Function : acornscsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  2133. * Purpose : queues a SCSI command
  2134. * Params : cmd - SCSI command
  2135. * done - function called on completion, with pointer to command descriptor
  2136. * Returns : 0, or < 0 on error.
  2137. */
  2138. static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
  2139. void (*done)(struct scsi_cmnd *))
  2140. {
  2141. AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
  2142. if (!done) {
  2143. /* there should be some way of rejecting errors like this without panicing... */
  2144. panic("scsi%d: queuecommand called with NULL done function [cmd=%p]",
  2145. host->host->host_no, SCpnt);
  2146. return -EINVAL;
  2147. }
  2148. #if (DEBUG & DEBUG_NO_WRITE)
  2149. if (acornscsi_cmdtype(SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->device->id))) {
  2150. printk(KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
  2151. host->host->host_no, '0' + SCpnt->device->id);
  2152. SCpnt->result = DID_NO_CONNECT << 16;
  2153. done(SCpnt);
  2154. return 0;
  2155. }
  2156. #endif
  2157. SCpnt->scsi_done = done;
  2158. SCpnt->host_scribble = NULL;
  2159. SCpnt->result = 0;
  2160. SCpnt->tag = 0;
  2161. SCpnt->SCp.phase = (int)acornscsi_datadirection(SCpnt->cmnd[0]);
  2162. SCpnt->SCp.sent_command = 0;
  2163. SCpnt->SCp.scsi_xferred = 0;
  2164. init_SCp(SCpnt);
  2165. host->stats.queues += 1;
  2166. {
  2167. unsigned long flags;
  2168. if (!queue_add_cmd_ordered(&host->queues.issue, SCpnt)) {
  2169. SCpnt->result = DID_ERROR << 16;
  2170. done(SCpnt);
  2171. return 0;
  2172. }
  2173. local_irq_save(flags);
  2174. if (host->scsi.phase == PHASE_IDLE)
  2175. acornscsi_kick(host);
  2176. local_irq_restore(flags);
  2177. }
  2178. return 0;
  2179. }
  2180. DEF_SCSI_QCMD(acornscsi_queuecmd)
  2181. /*
  2182. * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result)
  2183. * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
  2184. * Params : SCpntp1 - pointer to command to return
  2185. * SCpntp2 - pointer to command to check
  2186. * result - result to pass back to mid-level done function
  2187. * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
  2188. */
  2189. static inline void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1,
  2190. struct scsi_cmnd **SCpntp2,
  2191. int result)
  2192. {
  2193. struct scsi_cmnd *SCpnt = *SCpntp1;
  2194. if (SCpnt) {
  2195. *SCpntp1 = NULL;
  2196. SCpnt->result = result;
  2197. SCpnt->scsi_done(SCpnt);
  2198. }
  2199. if (SCpnt == *SCpntp2)
  2200. *SCpntp2 = NULL;
  2201. }
  2202. enum res_abort { res_not_running, res_success, res_success_clear, res_snooze };
  2203. /*
  2204. * Prototype: enum res acornscsi_do_abort(struct scsi_cmnd *SCpnt)
  2205. * Purpose : abort a command on this host
  2206. * Params : SCpnt - command to abort
  2207. * Returns : our abort status
  2208. */
  2209. static enum res_abort acornscsi_do_abort(AS_Host *host, struct scsi_cmnd *SCpnt)
  2210. {
  2211. enum res_abort res = res_not_running;
  2212. if (queue_remove_cmd(&host->queues.issue, SCpnt)) {
  2213. /*
  2214. * The command was on the issue queue, and has not been
  2215. * issued yet. We can remove the command from the queue,
  2216. * and acknowledge the abort. Neither the devices nor the
  2217. * interface know about the command.
  2218. */
  2219. //#if (DEBUG & DEBUG_ABORT)
  2220. printk("on issue queue ");
  2221. //#endif
  2222. res = res_success;
  2223. } else if (queue_remove_cmd(&host->queues.disconnected, SCpnt)) {
  2224. /*
  2225. * The command was on the disconnected queue. Simply
  2226. * acknowledge the abort condition, and when the target
  2227. * reconnects, we will give it an ABORT message. The
  2228. * target should then disconnect, and we will clear
  2229. * the busylun bit.
  2230. */
  2231. //#if (DEBUG & DEBUG_ABORT)
  2232. printk("on disconnected queue ");
  2233. //#endif
  2234. res = res_success;
  2235. } else if (host->SCpnt == SCpnt) {
  2236. unsigned long flags;
  2237. //#if (DEBUG & DEBUG_ABORT)
  2238. printk("executing ");
  2239. //#endif
  2240. local_irq_save(flags);
  2241. switch (host->scsi.phase) {
  2242. /*
  2243. * If the interface is idle, and the command is 'disconnectable',
  2244. * then it is the same as on the disconnected queue. We simply
  2245. * remove all traces of the command. When the target reconnects,
  2246. * we will give it an ABORT message since the command could not
  2247. * be found. When the target finally disconnects, we will clear
  2248. * the busylun bit.
  2249. */
  2250. case PHASE_IDLE:
  2251. if (host->scsi.disconnectable) {
  2252. host->scsi.disconnectable = 0;
  2253. host->SCpnt = NULL;
  2254. res = res_success;
  2255. }
  2256. break;
  2257. /*
  2258. * If the command has connected and done nothing further,
  2259. * simply force a disconnect. We also need to clear the
  2260. * busylun bit.
  2261. */
  2262. case PHASE_CONNECTED:
  2263. sbic_arm_write(host, SBIC_CMND, CMND_DISCONNECT);
  2264. host->SCpnt = NULL;
  2265. res = res_success_clear;
  2266. break;
  2267. default:
  2268. acornscsi_abortcmd(host, host->SCpnt->tag);
  2269. res = res_snooze;
  2270. }
  2271. local_irq_restore(flags);
  2272. } else if (host->origSCpnt == SCpnt) {
  2273. /*
  2274. * The command will be executed next, but a command
  2275. * is currently using the interface. This is similar to
  2276. * being on the issue queue, except the busylun bit has
  2277. * been set.
  2278. */
  2279. host->origSCpnt = NULL;
  2280. //#if (DEBUG & DEBUG_ABORT)
  2281. printk("waiting for execution ");
  2282. //#endif
  2283. res = res_success_clear;
  2284. } else
  2285. printk("unknown ");
  2286. return res;
  2287. }
  2288. /*
  2289. * Prototype: int acornscsi_abort(struct scsi_cmnd *SCpnt)
  2290. * Purpose : abort a command on this host
  2291. * Params : SCpnt - command to abort
  2292. * Returns : one of SCSI_ABORT_ macros
  2293. */
  2294. int acornscsi_abort(struct scsi_cmnd *SCpnt)
  2295. {
  2296. AS_Host *host = (AS_Host *) SCpnt->device->host->hostdata;
  2297. int result;
  2298. host->stats.aborts += 1;
  2299. #if (DEBUG & DEBUG_ABORT)
  2300. {
  2301. int asr, ssr;
  2302. asr = sbic_arm_read(host, SBIC_ASR);
  2303. ssr = sbic_arm_read(host, SBIC_SSR);
  2304. printk(KERN_WARNING "acornscsi_abort: ");
  2305. print_sbic_status(asr, ssr, host->scsi.phase);
  2306. acornscsi_dumplog(host, SCpnt->device->id);
  2307. }
  2308. #endif
  2309. printk("scsi%d: ", host->host->host_no);
  2310. switch (acornscsi_do_abort(host, SCpnt)) {
  2311. /*
  2312. * We managed to find the command and cleared it out.
  2313. * We do not expect the command to be executing on the
  2314. * target, but we have set the busylun bit.
  2315. */
  2316. case res_success_clear:
  2317. //#if (DEBUG & DEBUG_ABORT)
  2318. printk("clear ");
  2319. //#endif
  2320. clear_bit(SCpnt->device->id * 8 +
  2321. (u8)(SCpnt->device->lun & 0x7), host->busyluns);
  2322. /*
  2323. * We found the command, and cleared it out. Either
  2324. * the command is still known to be executing on the
  2325. * target, or the busylun bit is not set.
  2326. */
  2327. case res_success:
  2328. //#if (DEBUG & DEBUG_ABORT)
  2329. printk("success\n");
  2330. //#endif
  2331. result = SUCCESS;
  2332. break;
  2333. /*
  2334. * We did find the command, but unfortunately we couldn't
  2335. * unhook it from ourselves. Wait some more, and if it
  2336. * still doesn't complete, reset the interface.
  2337. */
  2338. case res_snooze:
  2339. //#if (DEBUG & DEBUG_ABORT)
  2340. printk("snooze\n");
  2341. //#endif
  2342. result = FAILED;
  2343. break;
  2344. /*
  2345. * The command could not be found (either because it completed,
  2346. * or it got dropped.
  2347. */
  2348. default:
  2349. case res_not_running:
  2350. acornscsi_dumplog(host, SCpnt->device->id);
  2351. result = FAILED;
  2352. //#if (DEBUG & DEBUG_ABORT)
  2353. printk("not running\n");
  2354. //#endif
  2355. break;
  2356. }
  2357. return result;
  2358. }
  2359. /*
  2360. * Prototype: int acornscsi_reset(struct scsi_cmnd *SCpnt)
  2361. * Purpose : reset a command on this host/reset this host
  2362. * Params : SCpnt - command causing reset
  2363. * Returns : one of SCSI_RESET_ macros
  2364. */
  2365. int acornscsi_host_reset(struct scsi_cmnd *SCpnt)
  2366. {
  2367. AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
  2368. struct scsi_cmnd *SCptr;
  2369. host->stats.resets += 1;
  2370. #if (DEBUG & DEBUG_RESET)
  2371. {
  2372. int asr, ssr, devidx;
  2373. asr = sbic_arm_read(host, SBIC_ASR);
  2374. ssr = sbic_arm_read(host, SBIC_SSR);
  2375. printk(KERN_WARNING "acornscsi_reset: ");
  2376. print_sbic_status(asr, ssr, host->scsi.phase);
  2377. for (devidx = 0; devidx < 9; devidx++)
  2378. acornscsi_dumplog(host, devidx);
  2379. }
  2380. #endif
  2381. acornscsi_dma_stop(host);
  2382. /*
  2383. * do hard reset. This resets all devices on this host, and so we
  2384. * must set the reset status on all commands.
  2385. */
  2386. acornscsi_resetcard(host);
  2387. while ((SCptr = queue_remove(&host->queues.disconnected)) != NULL)
  2388. ;
  2389. return SUCCESS;
  2390. }
  2391. /*==============================================================================================
  2392. * initialisation & miscellaneous support
  2393. */
  2394. /*
  2395. * Function: char *acornscsi_info(struct Scsi_Host *host)
  2396. * Purpose : return a string describing this interface
  2397. * Params : host - host to give information on
  2398. * Returns : a constant string
  2399. */
  2400. const
  2401. char *acornscsi_info(struct Scsi_Host *host)
  2402. {
  2403. static char string[100], *p;
  2404. p = string;
  2405. p += sprintf(string, "%s at port %08lX irq %d v%d.%d.%d"
  2406. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  2407. " SYNC"
  2408. #endif
  2409. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  2410. " TAG"
  2411. #endif
  2412. #if (DEBUG & DEBUG_NO_WRITE)
  2413. " NOWRITE (" __stringify(NO_WRITE) ")"
  2414. #endif
  2415. , host->hostt->name, host->io_port, host->irq,
  2416. VER_MAJOR, VER_MINOR, VER_PATCH);
  2417. return string;
  2418. }
  2419. static int acornscsi_show_info(struct seq_file *m, struct Scsi_Host *instance)
  2420. {
  2421. int devidx;
  2422. struct scsi_device *scd;
  2423. AS_Host *host;
  2424. host = (AS_Host *)instance->hostdata;
  2425. seq_printf(m, "AcornSCSI driver v%d.%d.%d"
  2426. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  2427. " SYNC"
  2428. #endif
  2429. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  2430. " TAG"
  2431. #endif
  2432. #if (DEBUG & DEBUG_NO_WRITE)
  2433. " NOWRITE (" __stringify(NO_WRITE) ")"
  2434. #endif
  2435. "\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
  2436. seq_printf(m, "SBIC: WD33C93A Address: %p IRQ : %d\n",
  2437. host->base + SBIC_REGIDX, host->scsi.irq);
  2438. #ifdef USE_DMAC
  2439. seq_printf(m, "DMAC: uPC71071 Address: %p IRQ : %d\n\n",
  2440. host->base + DMAC_OFFSET, host->scsi.irq);
  2441. #endif
  2442. seq_printf(m, "Statistics:\n"
  2443. "Queued commands: %-10u Issued commands: %-10u\n"
  2444. "Done commands : %-10u Reads : %-10u\n"
  2445. "Writes : %-10u Others : %-10u\n"
  2446. "Disconnects : %-10u Aborts : %-10u\n"
  2447. "Resets : %-10u\n\nLast phases:",
  2448. host->stats.queues, host->stats.removes,
  2449. host->stats.fins, host->stats.reads,
  2450. host->stats.writes, host->stats.miscs,
  2451. host->stats.disconnects, host->stats.aborts,
  2452. host->stats.resets);
  2453. for (devidx = 0; devidx < 9; devidx ++) {
  2454. unsigned int statptr, prev;
  2455. seq_printf(m, "\n%c:", devidx == 8 ? 'H' : ('0' + devidx));
  2456. statptr = host->status_ptr[devidx] - 10;
  2457. if ((signed int)statptr < 0)
  2458. statptr += STATUS_BUFFER_SIZE;
  2459. prev = host->status[devidx][statptr].when;
  2460. for (; statptr != host->status_ptr[devidx]; statptr = (statptr + 1) & (STATUS_BUFFER_SIZE - 1)) {
  2461. if (host->status[devidx][statptr].when) {
  2462. seq_printf(m, "%c%02X:%02X+%2ld",
  2463. host->status[devidx][statptr].irq ? '-' : ' ',
  2464. host->status[devidx][statptr].ph,
  2465. host->status[devidx][statptr].ssr,
  2466. (host->status[devidx][statptr].when - prev) < 100 ?
  2467. (host->status[devidx][statptr].when - prev) : 99);
  2468. prev = host->status[devidx][statptr].when;
  2469. }
  2470. }
  2471. }
  2472. seq_printf(m, "\nAttached devices:\n");
  2473. shost_for_each_device(scd, instance) {
  2474. seq_printf(m, "Device/Lun TaggedQ Sync\n");
  2475. seq_printf(m, " %d/%llu ", scd->id, scd->lun);
  2476. if (scd->tagged_supported)
  2477. seq_printf(m, "%3sabled(%3d) ",
  2478. scd->simple_tags ? "en" : "dis",
  2479. scd->current_tag);
  2480. else
  2481. seq_printf(m, "unsupported ");
  2482. if (host->device[scd->id].sync_xfer & 15)
  2483. seq_printf(m, "offset %d, %d ns\n",
  2484. host->device[scd->id].sync_xfer & 15,
  2485. acornscsi_getperiod(host->device[scd->id].sync_xfer));
  2486. else
  2487. seq_printf(m, "async\n");
  2488. }
  2489. return 0;
  2490. }
  2491. static struct scsi_host_template acornscsi_template = {
  2492. .module = THIS_MODULE,
  2493. .show_info = acornscsi_show_info,
  2494. .name = "AcornSCSI",
  2495. .info = acornscsi_info,
  2496. .queuecommand = acornscsi_queuecmd,
  2497. .eh_abort_handler = acornscsi_abort,
  2498. .eh_host_reset_handler = acornscsi_host_reset,
  2499. .can_queue = 16,
  2500. .this_id = 7,
  2501. .sg_tablesize = SG_ALL,
  2502. .cmd_per_lun = 2,
  2503. .dma_boundary = PAGE_SIZE - 1,
  2504. .proc_name = "acornscsi",
  2505. };
  2506. static int acornscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  2507. {
  2508. struct Scsi_Host *host;
  2509. AS_Host *ashost;
  2510. int ret;
  2511. ret = ecard_request_resources(ec);
  2512. if (ret)
  2513. goto out;
  2514. host = scsi_host_alloc(&acornscsi_template, sizeof(AS_Host));
  2515. if (!host) {
  2516. ret = -ENOMEM;
  2517. goto out_release;
  2518. }
  2519. ashost = (AS_Host *)host->hostdata;
  2520. ashost->base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
  2521. ashost->fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
  2522. if (!ashost->base || !ashost->fast)
  2523. goto out_put;
  2524. host->irq = ec->irq;
  2525. ashost->host = host;
  2526. ashost->scsi.irq = host->irq;
  2527. ec->irqaddr = ashost->fast + INT_REG;
  2528. ec->irqmask = 0x0a;
  2529. ret = request_irq(host->irq, acornscsi_intr, 0, "acornscsi", ashost);
  2530. if (ret) {
  2531. printk(KERN_CRIT "scsi%d: IRQ%d not free: %d\n",
  2532. host->host_no, ashost->scsi.irq, ret);
  2533. goto out_put;
  2534. }
  2535. memset(&ashost->stats, 0, sizeof (ashost->stats));
  2536. queue_initialise(&ashost->queues.issue);
  2537. queue_initialise(&ashost->queues.disconnected);
  2538. msgqueue_initialise(&ashost->scsi.msgs);
  2539. acornscsi_resetcard(ashost);
  2540. ret = scsi_add_host(host, &ec->dev);
  2541. if (ret)
  2542. goto out_irq;
  2543. scsi_scan_host(host);
  2544. goto out;
  2545. out_irq:
  2546. free_irq(host->irq, ashost);
  2547. msgqueue_free(&ashost->scsi.msgs);
  2548. queue_free(&ashost->queues.disconnected);
  2549. queue_free(&ashost->queues.issue);
  2550. out_put:
  2551. ecardm_iounmap(ec, ashost->fast);
  2552. ecardm_iounmap(ec, ashost->base);
  2553. scsi_host_put(host);
  2554. out_release:
  2555. ecard_release_resources(ec);
  2556. out:
  2557. return ret;
  2558. }
  2559. static void acornscsi_remove(struct expansion_card *ec)
  2560. {
  2561. struct Scsi_Host *host = ecard_get_drvdata(ec);
  2562. AS_Host *ashost = (AS_Host *)host->hostdata;
  2563. ecard_set_drvdata(ec, NULL);
  2564. scsi_remove_host(host);
  2565. /*
  2566. * Put card into RESET state
  2567. */
  2568. writeb(0x80, ashost->fast + PAGE_REG);
  2569. free_irq(host->irq, ashost);
  2570. msgqueue_free(&ashost->scsi.msgs);
  2571. queue_free(&ashost->queues.disconnected);
  2572. queue_free(&ashost->queues.issue);
  2573. ecardm_iounmap(ec, ashost->fast);
  2574. ecardm_iounmap(ec, ashost->base);
  2575. scsi_host_put(host);
  2576. ecard_release_resources(ec);
  2577. }
  2578. static const struct ecard_id acornscsi_cids[] = {
  2579. { MANU_ACORN, PROD_ACORN_SCSI },
  2580. { 0xffff, 0xffff },
  2581. };
  2582. static struct ecard_driver acornscsi_driver = {
  2583. .probe = acornscsi_probe,
  2584. .remove = acornscsi_remove,
  2585. .id_table = acornscsi_cids,
  2586. .drv = {
  2587. .name = "acornscsi",
  2588. },
  2589. };
  2590. static int __init acornscsi_init(void)
  2591. {
  2592. return ecard_register_driver(&acornscsi_driver);
  2593. }
  2594. static void __exit acornscsi_exit(void)
  2595. {
  2596. ecard_remove_driver(&acornscsi_driver);
  2597. }
  2598. module_init(acornscsi_init);
  2599. module_exit(acornscsi_exit);
  2600. MODULE_AUTHOR("Russell King");
  2601. MODULE_DESCRIPTION("AcornSCSI driver");
  2602. MODULE_LICENSE("GPL");