PageRenderTime 62ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/scsi/aha152x.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t
C | 3985 lines | 2794 code | 615 blank | 576 comment | 580 complexity | d03cc28137d1cd08fbfbd47e155f6a28 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /* aha152x.c -- Adaptec AHA-152x driver
  2. * Author: Jürgen E. Fischer, fischer@norbit.de
  3. * Copyright 1993-2004 Jürgen E. Fischer
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2, or (at your option) any
  8. * later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. *
  16. * $Id: aha152x.c,v 2.7 2004/01/24 11:42:59 fischer Exp $
  17. *
  18. * $Log: aha152x.c,v $
  19. * Revision 2.7 2004/01/24 11:42:59 fischer
  20. * - gather code that is not used by PCMCIA at the end
  21. * - move request_region for !PCMCIA case to detection
  22. * - migration to new scsi host api (remove legacy code)
  23. * - free host scribble before scsi_done
  24. * - fix error handling
  25. * - one isapnp device added to id_table
  26. *
  27. * Revision 2.6 2003/10/30 20:52:47 fischer
  28. * - interfaces changes for kernel 2.6
  29. * - aha152x_probe_one introduced for pcmcia stub
  30. * - fixed pnpdev handling
  31. * - instead of allocation a new one, reuse command for request sense after check condition and reset
  32. * - fixes race in is_complete
  33. *
  34. * Revision 2.5 2002/04/14 11:24:53 fischer
  35. * - isapnp support
  36. * - abort fixed
  37. * - 2.5 support
  38. *
  39. * Revision 2.4 2000/12/16 12:53:56 fischer
  40. * - allow REQUEST SENSE to be queued
  41. * - handle shared PCI interrupts
  42. *
  43. * Revision 2.3 2000/11/04 16:40:26 fischer
  44. * - handle data overruns
  45. * - extend timeout for data phases
  46. *
  47. * Revision 2.2 2000/08/08 19:54:53 fischer
  48. * - minor changes
  49. *
  50. * Revision 2.1 2000/05/17 16:23:17 fischer
  51. * - signature update
  52. * - fix for data out w/o scatter gather
  53. *
  54. * Revision 2.0 1999/12/25 15:07:32 fischer
  55. * - interrupt routine completly reworked
  56. * - basic support for new eh code
  57. *
  58. * Revision 1.21 1999/11/10 23:46:36 fischer
  59. * - default to synchronous operation
  60. * - synchronous negotiation fixed
  61. * - added timeout to loops
  62. * - debugging output can be controlled through procfs
  63. *
  64. * Revision 1.20 1999/11/07 18:37:31 fischer
  65. * - synchronous operation works
  66. * - resid support for sg driver
  67. *
  68. * Revision 1.19 1999/11/02 22:39:59 fischer
  69. * - moved leading comments to README.aha152x
  70. * - new additional module parameters
  71. * - updates for 2.3
  72. * - support for the Tripace TC1550 controller
  73. * - interrupt handling changed
  74. *
  75. * Revision 1.18 1996/09/07 20:10:40 fischer
  76. * - fixed can_queue handling (multiple outstanding commands working again)
  77. *
  78. * Revision 1.17 1996/08/17 16:05:14 fischer
  79. * - biosparam improved
  80. * - interrupt verification
  81. * - updated documentation
  82. * - cleanups
  83. *
  84. * Revision 1.16 1996/06/09 00:04:56 root
  85. * - added configuration symbols for insmod (aha152x/aha152x1)
  86. *
  87. * Revision 1.15 1996/04/30 14:52:06 fischer
  88. * - proc info fixed
  89. * - support for extended translation for >1GB disks
  90. *
  91. * Revision 1.14 1996/01/17 15:11:20 fischer
  92. * - fixed lockup in MESSAGE IN phase after reconnection
  93. *
  94. * Revision 1.13 1996/01/09 02:15:53 fischer
  95. * - some cleanups
  96. * - moved request_irq behind controller initialization
  97. * (to avoid spurious interrupts)
  98. *
  99. * Revision 1.12 1995/12/16 12:26:07 fischer
  100. * - barrier()s added
  101. * - configurable RESET delay added
  102. *
  103. * Revision 1.11 1995/12/06 21:18:35 fischer
  104. * - some minor updates
  105. *
  106. * Revision 1.10 1995/07/22 19:18:45 fischer
  107. * - support for 2 controllers
  108. * - started synchronous data transfers (not working yet)
  109. *
  110. * Revision 1.9 1995/03/18 09:20:24 root
  111. * - patches for PCMCIA and modules
  112. *
  113. * Revision 1.8 1995/01/21 22:07:19 root
  114. * - snarf_region => request_region
  115. * - aha152x_intr interface change
  116. *
  117. * Revision 1.7 1995/01/02 23:19:36 root
  118. * - updated COMMAND_SIZE to cmd_len
  119. * - changed sti() to restore_flags()
  120. * - fixed some #ifdef which generated warnings
  121. *
  122. * Revision 1.6 1994/11/24 20:35:27 root
  123. * - problem with odd number of bytes in fifo fixed
  124. *
  125. * Revision 1.5 1994/10/30 14:39:56 root
  126. * - abort code fixed
  127. * - debugging improved
  128. *
  129. * Revision 1.4 1994/09/12 11:33:01 root
  130. * - irqaction to request_irq
  131. * - abortion updated
  132. *
  133. * Revision 1.3 1994/08/04 13:53:05 root
  134. * - updates for mid-level-driver changes
  135. * - accept unexpected BUSFREE phase as error condition
  136. * - parity check now configurable
  137. *
  138. * Revision 1.2 1994/07/03 12:56:36 root
  139. * - cleaned up debugging code
  140. * - more tweaking on reset delays
  141. * - updated abort/reset code (pretty untested...)
  142. *
  143. * Revision 1.1 1994/05/28 21:18:49 root
  144. * - update for mid-level interface change (abort-reset)
  145. * - delays after resets adjusted for some slow devices
  146. *
  147. * Revision 1.0 1994/03/25 12:52:00 root
  148. * - Fixed "more data than expected" problem
  149. * - added new BIOS signatures
  150. *
  151. * Revision 0.102 1994/01/31 20:44:12 root
  152. * - minor changes in insw/outsw handling
  153. *
  154. * Revision 0.101 1993/12/13 01:16:27 root
  155. * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
  156. * fixes problems with CD-ROM sector size detection & media change)
  157. *
  158. * Revision 0.100 1993/12/10 16:58:47 root
  159. * - fix for unsuccessful selections in case of non-continuous id assignments
  160. * on the scsi bus.
  161. *
  162. * Revision 0.99 1993/10/24 16:19:59 root
  163. * - fixed DATA IN (rare read errors gone)
  164. *
  165. * Revision 0.98 1993/10/17 12:54:44 root
  166. * - fixed some recent fixes (shame on me)
  167. * - moved initialization of scratch area to aha152x_queue
  168. *
  169. * Revision 0.97 1993/10/09 18:53:53 root
  170. * - DATA IN fixed. Rarely left data in the fifo.
  171. *
  172. * Revision 0.96 1993/10/03 00:53:59 root
  173. * - minor changes on DATA IN
  174. *
  175. * Revision 0.95 1993/09/24 10:36:01 root
  176. * - change handling of MSGI after reselection
  177. * - fixed sti/cli
  178. * - minor changes
  179. *
  180. * Revision 0.94 1993/09/18 14:08:22 root
  181. * - fixed bug in multiple outstanding command code
  182. * - changed detection
  183. * - support for kernel command line configuration
  184. * - reset corrected
  185. * - changed message handling
  186. *
  187. * Revision 0.93 1993/09/15 20:41:19 root
  188. * - fixed bugs with multiple outstanding commands
  189. *
  190. * Revision 0.92 1993/09/13 02:46:33 root
  191. * - multiple outstanding commands work (no problems with IBM drive)
  192. *
  193. * Revision 0.91 1993/09/12 20:51:46 root
  194. * added multiple outstanding commands
  195. * (some problem with this $%&? IBM device remain)
  196. *
  197. * Revision 0.9 1993/09/12 11:11:22 root
  198. * - corrected auto-configuration
  199. * - changed the auto-configuration (added some '#define's)
  200. * - added support for dis-/reconnection
  201. *
  202. * Revision 0.8 1993/09/06 23:09:39 root
  203. * - added support for the drive activity light
  204. * - minor changes
  205. *
  206. * Revision 0.7 1993/09/05 14:30:15 root
  207. * - improved phase detection
  208. * - now using the new snarf_region code of 0.99pl13
  209. *
  210. * Revision 0.6 1993/09/02 11:01:38 root
  211. * first public release; added some signatures and biosparam()
  212. *
  213. * Revision 0.5 1993/08/30 10:23:30 root
  214. * fixed timing problems with my IBM drive
  215. *
  216. * Revision 0.4 1993/08/29 14:06:52 root
  217. * fixed some problems with timeouts due incomplete commands
  218. *
  219. * Revision 0.3 1993/08/28 15:55:03 root
  220. * writing data works too. mounted and worked on a dos partition
  221. *
  222. * Revision 0.2 1993/08/27 22:42:07 root
  223. * reading data works. Mounted a msdos partition.
  224. *
  225. * Revision 0.1 1993/08/25 13:38:30 root
  226. * first "damn thing doesn't work" version
  227. *
  228. * Revision 0.0 1993/08/14 19:54:25 root
  229. * empty function bodies; detect() works.
  230. *
  231. *
  232. **************************************************************************
  233. see Documentation/scsi/aha152x.txt for configuration details
  234. **************************************************************************/
  235. #include <linux/module.h>
  236. #include <asm/irq.h>
  237. #include <linux/io.h>
  238. #include <linux/blkdev.h>
  239. #include <asm/system.h>
  240. #include <linux/completion.h>
  241. #include <linux/errno.h>
  242. #include <linux/string.h>
  243. #include <linux/wait.h>
  244. #include <linux/ioport.h>
  245. #include <linux/delay.h>
  246. #include <linux/proc_fs.h>
  247. #include <linux/interrupt.h>
  248. #include <linux/init.h>
  249. #include <linux/kernel.h>
  250. #include <linux/isapnp.h>
  251. #include <linux/spinlock.h>
  252. #include <linux/workqueue.h>
  253. #include <linux/list.h>
  254. #include <linux/slab.h>
  255. #include <scsi/scsicam.h>
  256. #include "scsi.h"
  257. #include <scsi/scsi_dbg.h>
  258. #include <scsi/scsi_host.h>
  259. #include <scsi/scsi_transport_spi.h>
  260. #include <scsi/scsi_eh.h>
  261. #include "aha152x.h"
  262. static LIST_HEAD(aha152x_host_list);
  263. /* DEFINES */
  264. /* For PCMCIA cards, always use AUTOCONF */
  265. #if defined(PCMCIA) || defined(MODULE)
  266. #if !defined(AUTOCONF)
  267. #define AUTOCONF
  268. #endif
  269. #endif
  270. #if !defined(AUTOCONF) && !defined(SETUP0)
  271. #error define AUTOCONF or SETUP0
  272. #endif
  273. #if defined(AHA152X_DEBUG)
  274. #define DEBUG_DEFAULT debug_eh
  275. #define DPRINTK(when,msgs...) \
  276. do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0)
  277. #define DO_LOCK(flags) \
  278. do { \
  279. if(spin_is_locked(&QLOCK)) { \
  280. DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \
  281. } \
  282. DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
  283. spin_lock_irqsave(&QLOCK,flags); \
  284. DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
  285. QLOCKER=__func__; \
  286. QLOCKERL=__LINE__; \
  287. } while(0)
  288. #define DO_UNLOCK(flags) \
  289. do { \
  290. DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \
  291. spin_unlock_irqrestore(&QLOCK,flags); \
  292. DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
  293. QLOCKER="(not locked)"; \
  294. QLOCKERL=0; \
  295. } while(0)
  296. #else
  297. #define DPRINTK(when,msgs...)
  298. #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
  299. #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
  300. #endif
  301. #define LEAD "(scsi%d:%d:%d) "
  302. #define WARN_LEAD KERN_WARNING LEAD
  303. #define INFO_LEAD KERN_INFO LEAD
  304. #define NOTE_LEAD KERN_NOTICE LEAD
  305. #define ERR_LEAD KERN_ERR LEAD
  306. #define DEBUG_LEAD KERN_DEBUG LEAD
  307. #define CMDINFO(cmd) \
  308. (cmd) ? ((cmd)->device->host->host_no) : -1, \
  309. (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
  310. (cmd) ? ((cmd)->device->lun & 0x07) : -1
  311. static inline void
  312. CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
  313. {
  314. scsi_set_resid(cmd, scsi_get_resid(cmd) + inc);
  315. }
  316. #define DELAY_DEFAULT 1000
  317. #if defined(PCMCIA)
  318. #define IRQ_MIN 0
  319. #define IRQ_MAX 16
  320. #else
  321. #define IRQ_MIN 9
  322. #if defined(__PPC)
  323. #define IRQ_MAX (nr_irqs-1)
  324. #else
  325. #define IRQ_MAX 12
  326. #endif
  327. #endif
  328. enum {
  329. not_issued = 0x0001, /* command not yet issued */
  330. selecting = 0x0002, /* target is beeing selected */
  331. identified = 0x0004, /* IDENTIFY was sent */
  332. disconnected = 0x0008, /* target disconnected */
  333. completed = 0x0010, /* target sent COMMAND COMPLETE */
  334. aborted = 0x0020, /* ABORT was sent */
  335. resetted = 0x0040, /* BUS DEVICE RESET was sent */
  336. spiordy = 0x0080, /* waiting for SPIORDY to raise */
  337. syncneg = 0x0100, /* synchronous negotiation in progress */
  338. aborting = 0x0200, /* ABORT is pending */
  339. resetting = 0x0400, /* BUS DEVICE RESET is pending */
  340. check_condition = 0x0800, /* requesting sense after CHECK CONDITION */
  341. };
  342. MODULE_AUTHOR("Jürgen Fischer");
  343. MODULE_DESCRIPTION(AHA152X_REVID);
  344. MODULE_LICENSE("GPL");
  345. #if !defined(PCMCIA)
  346. #if defined(MODULE)
  347. static int io[] = {0, 0};
  348. module_param_array(io, int, NULL, 0);
  349. MODULE_PARM_DESC(io,"base io address of controller");
  350. static int irq[] = {0, 0};
  351. module_param_array(irq, int, NULL, 0);
  352. MODULE_PARM_DESC(irq,"interrupt for controller");
  353. static int scsiid[] = {7, 7};
  354. module_param_array(scsiid, int, NULL, 0);
  355. MODULE_PARM_DESC(scsiid,"scsi id of controller");
  356. static int reconnect[] = {1, 1};
  357. module_param_array(reconnect, int, NULL, 0);
  358. MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
  359. static int parity[] = {1, 1};
  360. module_param_array(parity, int, NULL, 0);
  361. MODULE_PARM_DESC(parity,"use scsi parity");
  362. static int sync[] = {1, 1};
  363. module_param_array(sync, int, NULL, 0);
  364. MODULE_PARM_DESC(sync,"use synchronous transfers");
  365. static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
  366. module_param_array(delay, int, NULL, 0);
  367. MODULE_PARM_DESC(delay,"scsi reset delay");
  368. static int exttrans[] = {0, 0};
  369. module_param_array(exttrans, int, NULL, 0);
  370. MODULE_PARM_DESC(exttrans,"use extended translation");
  371. #if !defined(AHA152X_DEBUG)
  372. static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
  373. module_param_array(aha152x, int, NULL, 0);
  374. MODULE_PARM_DESC(aha152x, "parameters for first controller");
  375. static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
  376. module_param_array(aha152x1, int, NULL, 0);
  377. MODULE_PARM_DESC(aha152x1, "parameters for second controller");
  378. #else
  379. static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT};
  380. module_param_array(debug, int, NULL, 0);
  381. MODULE_PARM_DESC(debug, "flags for driver debugging");
  382. static int aha152x[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
  383. module_param_array(aha152x, int, NULL, 0);
  384. MODULE_PARM_DESC(aha152x, "parameters for first controller");
  385. static int aha152x1[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
  386. module_param_array(aha152x1, int, NULL, 0);
  387. MODULE_PARM_DESC(aha152x1, "parameters for second controller");
  388. #endif /* !defined(AHA152X_DEBUG) */
  389. #endif /* MODULE */
  390. #ifdef __ISAPNP__
  391. static struct isapnp_device_id id_table[] __devinitdata = {
  392. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1502), 0 },
  393. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1505), 0 },
  394. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1510), 0 },
  395. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1515), 0 },
  396. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1520), 0 },
  397. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2015), 0 },
  398. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1522), 0 },
  399. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2215), 0 },
  400. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1530), 0 },
  401. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3015), 0 },
  402. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1532), 0 },
  403. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3215), 0 },
  404. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x6360), 0 },
  405. { ISAPNP_DEVICE_SINGLE_END, }
  406. };
  407. MODULE_DEVICE_TABLE(isapnp, id_table);
  408. #endif /* ISAPNP */
  409. #endif /* !PCMCIA */
  410. static struct scsi_host_template aha152x_driver_template;
  411. /*
  412. * internal states of the host
  413. *
  414. */
  415. enum aha152x_state {
  416. idle=0,
  417. unknown,
  418. seldo,
  419. seldi,
  420. selto,
  421. busfree,
  422. msgo,
  423. cmd,
  424. msgi,
  425. status,
  426. datai,
  427. datao,
  428. parerr,
  429. rsti,
  430. maxstate
  431. };
  432. /*
  433. * current state information of the host
  434. *
  435. */
  436. struct aha152x_hostdata {
  437. Scsi_Cmnd *issue_SC;
  438. /* pending commands to issue */
  439. Scsi_Cmnd *current_SC;
  440. /* current command on the bus */
  441. Scsi_Cmnd *disconnected_SC;
  442. /* commands that disconnected */
  443. Scsi_Cmnd *done_SC;
  444. /* command that was completed */
  445. spinlock_t lock;
  446. /* host lock */
  447. #if defined(AHA152X_DEBUG)
  448. const char *locker;
  449. /* which function has the lock */
  450. int lockerl; /* where did it get it */
  451. int debug; /* current debugging setting */
  452. #endif
  453. #if defined(AHA152X_STAT)
  454. int total_commands;
  455. int disconnections;
  456. int busfree_without_any_action;
  457. int busfree_without_old_command;
  458. int busfree_without_new_command;
  459. int busfree_without_done_command;
  460. int busfree_with_check_condition;
  461. int count[maxstate];
  462. int count_trans[maxstate];
  463. unsigned long time[maxstate];
  464. #endif
  465. int commands; /* current number of commands */
  466. int reconnect; /* disconnection allowed */
  467. int parity; /* parity checking enabled */
  468. int synchronous; /* synchronous transferes enabled */
  469. int delay; /* reset out delay */
  470. int ext_trans; /* extended translation enabled */
  471. int swint; /* software-interrupt was fired during detect() */
  472. int service; /* bh needs to be run */
  473. int in_intr; /* bh is running */
  474. /* current state,
  475. previous state,
  476. last state different from current state */
  477. enum aha152x_state state, prevstate, laststate;
  478. int target;
  479. /* reconnecting target */
  480. unsigned char syncrate[8];
  481. /* current synchronous transfer agreements */
  482. unsigned char syncneg[8];
  483. /* 0: no negotiation;
  484. * 1: negotiation in progress;
  485. * 2: negotiation completed
  486. */
  487. int cmd_i;
  488. /* number of sent bytes of current command */
  489. int msgi_len;
  490. /* number of received message bytes */
  491. unsigned char msgi[256];
  492. /* received message bytes */
  493. int msgo_i, msgo_len;
  494. /* number of sent bytes and length of current messages */
  495. unsigned char msgo[256];
  496. /* pending messages */
  497. int data_len;
  498. /* number of sent/received bytes in dataphase */
  499. unsigned long io_port0;
  500. unsigned long io_port1;
  501. #ifdef __ISAPNP__
  502. struct pnp_dev *pnpdev;
  503. #endif
  504. struct list_head host_list;
  505. };
  506. /*
  507. * host specific command extension
  508. *
  509. */
  510. struct aha152x_scdata {
  511. Scsi_Cmnd *next; /* next sc in queue */
  512. struct completion *done;/* semaphore to block on */
  513. struct scsi_eh_save ses;
  514. };
  515. /* access macros for hostdata */
  516. #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
  517. #define HOSTNO ((shpnt)->host_no)
  518. #define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
  519. #define DONE_SC (HOSTDATA(shpnt)->done_SC)
  520. #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
  521. #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
  522. #define QLOCK (HOSTDATA(shpnt)->lock)
  523. #define QLOCKER (HOSTDATA(shpnt)->locker)
  524. #define QLOCKERL (HOSTDATA(shpnt)->lockerl)
  525. #define STATE (HOSTDATA(shpnt)->state)
  526. #define PREVSTATE (HOSTDATA(shpnt)->prevstate)
  527. #define LASTSTATE (HOSTDATA(shpnt)->laststate)
  528. #define RECONN_TARGET (HOSTDATA(shpnt)->target)
  529. #define CMD_I (HOSTDATA(shpnt)->cmd_i)
  530. #define MSGO(i) (HOSTDATA(shpnt)->msgo[i])
  531. #define MSGO_I (HOSTDATA(shpnt)->msgo_i)
  532. #define MSGOLEN (HOSTDATA(shpnt)->msgo_len)
  533. #define ADDMSGO(x) (MSGOLEN<256 ? (void)(MSGO(MSGOLEN++)=x) : aha152x_error(shpnt,"MSGO overflow"))
  534. #define MSGI(i) (HOSTDATA(shpnt)->msgi[i])
  535. #define MSGILEN (HOSTDATA(shpnt)->msgi_len)
  536. #define ADDMSGI(x) (MSGILEN<256 ? (void)(MSGI(MSGILEN++)=x) : aha152x_error(shpnt,"MSGI overflow"))
  537. #define DATA_LEN (HOSTDATA(shpnt)->data_len)
  538. #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->device->id])
  539. #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->device->id])
  540. #define DELAY (HOSTDATA(shpnt)->delay)
  541. #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
  542. #define TC1550 (HOSTDATA(shpnt)->tc1550)
  543. #define RECONNECT (HOSTDATA(shpnt)->reconnect)
  544. #define PARITY (HOSTDATA(shpnt)->parity)
  545. #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous)
  546. #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0)
  547. #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1)
  548. #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble)
  549. #define SCNEXT(SCpnt) SCDATA(SCpnt)->next
  550. #define SCSEM(SCpnt) SCDATA(SCpnt)->done
  551. #define SG_ADDRESS(buffer) ((char *) sg_virt((buffer)))
  552. /* state handling */
  553. static void seldi_run(struct Scsi_Host *shpnt);
  554. static void seldo_run(struct Scsi_Host *shpnt);
  555. static void selto_run(struct Scsi_Host *shpnt);
  556. static void busfree_run(struct Scsi_Host *shpnt);
  557. static void msgo_init(struct Scsi_Host *shpnt);
  558. static void msgo_run(struct Scsi_Host *shpnt);
  559. static void msgo_end(struct Scsi_Host *shpnt);
  560. static void cmd_init(struct Scsi_Host *shpnt);
  561. static void cmd_run(struct Scsi_Host *shpnt);
  562. static void cmd_end(struct Scsi_Host *shpnt);
  563. static void datai_init(struct Scsi_Host *shpnt);
  564. static void datai_run(struct Scsi_Host *shpnt);
  565. static void datai_end(struct Scsi_Host *shpnt);
  566. static void datao_init(struct Scsi_Host *shpnt);
  567. static void datao_run(struct Scsi_Host *shpnt);
  568. static void datao_end(struct Scsi_Host *shpnt);
  569. static void status_run(struct Scsi_Host *shpnt);
  570. static void msgi_run(struct Scsi_Host *shpnt);
  571. static void msgi_end(struct Scsi_Host *shpnt);
  572. static void parerr_run(struct Scsi_Host *shpnt);
  573. static void rsti_run(struct Scsi_Host *shpnt);
  574. static void is_complete(struct Scsi_Host *shpnt);
  575. /*
  576. * driver states
  577. *
  578. */
  579. static struct {
  580. char *name;
  581. void (*init)(struct Scsi_Host *);
  582. void (*run)(struct Scsi_Host *);
  583. void (*end)(struct Scsi_Host *);
  584. int spio;
  585. } states[] = {
  586. { "idle", NULL, NULL, NULL, 0},
  587. { "unknown", NULL, NULL, NULL, 0},
  588. { "seldo", NULL, seldo_run, NULL, 0},
  589. { "seldi", NULL, seldi_run, NULL, 0},
  590. { "selto", NULL, selto_run, NULL, 0},
  591. { "busfree", NULL, busfree_run, NULL, 0},
  592. { "msgo", msgo_init, msgo_run, msgo_end, 1},
  593. { "cmd", cmd_init, cmd_run, cmd_end, 1},
  594. { "msgi", NULL, msgi_run, msgi_end, 1},
  595. { "status", NULL, status_run, NULL, 1},
  596. { "datai", datai_init, datai_run, datai_end, 0},
  597. { "datao", datao_init, datao_run, datao_end, 0},
  598. { "parerr", NULL, parerr_run, NULL, 0},
  599. { "rsti", NULL, rsti_run, NULL, 0},
  600. };
  601. /* setup & interrupt */
  602. static irqreturn_t intr(int irq, void *dev_id);
  603. static void reset_ports(struct Scsi_Host *shpnt);
  604. static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
  605. static void done(struct Scsi_Host *shpnt, int error);
  606. /* diagnostics */
  607. static void disp_ports(struct Scsi_Host *shpnt);
  608. static void show_command(Scsi_Cmnd * ptr);
  609. static void show_queues(struct Scsi_Host *shpnt);
  610. static void disp_enintr(struct Scsi_Host *shpnt);
  611. /*
  612. * queue services:
  613. *
  614. */
  615. static inline void append_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
  616. {
  617. Scsi_Cmnd *end;
  618. SCNEXT(new_SC) = NULL;
  619. if (!*SC)
  620. *SC = new_SC;
  621. else {
  622. for (end = *SC; SCNEXT(end); end = SCNEXT(end))
  623. ;
  624. SCNEXT(end) = new_SC;
  625. }
  626. }
  627. static inline Scsi_Cmnd *remove_first_SC(Scsi_Cmnd ** SC)
  628. {
  629. Scsi_Cmnd *ptr;
  630. ptr = *SC;
  631. if (ptr) {
  632. *SC = SCNEXT(*SC);
  633. SCNEXT(ptr)=NULL;
  634. }
  635. return ptr;
  636. }
  637. static inline Scsi_Cmnd *remove_lun_SC(Scsi_Cmnd ** SC, int target, int lun)
  638. {
  639. Scsi_Cmnd *ptr, *prev;
  640. for (ptr = *SC, prev = NULL;
  641. ptr && ((ptr->device->id != target) || (ptr->device->lun != lun));
  642. prev = ptr, ptr = SCNEXT(ptr))
  643. ;
  644. if (ptr) {
  645. if (prev)
  646. SCNEXT(prev) = SCNEXT(ptr);
  647. else
  648. *SC = SCNEXT(ptr);
  649. SCNEXT(ptr)=NULL;
  650. }
  651. return ptr;
  652. }
  653. static inline Scsi_Cmnd *remove_SC(Scsi_Cmnd **SC, Scsi_Cmnd *SCp)
  654. {
  655. Scsi_Cmnd *ptr, *prev;
  656. for (ptr = *SC, prev = NULL;
  657. ptr && SCp!=ptr;
  658. prev = ptr, ptr = SCNEXT(ptr))
  659. ;
  660. if (ptr) {
  661. if (prev)
  662. SCNEXT(prev) = SCNEXT(ptr);
  663. else
  664. *SC = SCNEXT(ptr);
  665. SCNEXT(ptr)=NULL;
  666. }
  667. return ptr;
  668. }
  669. static irqreturn_t swintr(int irqno, void *dev_id)
  670. {
  671. struct Scsi_Host *shpnt = dev_id;
  672. HOSTDATA(shpnt)->swint++;
  673. SETPORT(DMACNTRL0, INTEN);
  674. return IRQ_HANDLED;
  675. }
  676. struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup)
  677. {
  678. struct Scsi_Host *shpnt;
  679. shpnt = scsi_host_alloc(&aha152x_driver_template, sizeof(struct aha152x_hostdata));
  680. if (!shpnt) {
  681. printk(KERN_ERR "aha152x: scsi_host_alloc failed\n");
  682. return NULL;
  683. }
  684. memset(HOSTDATA(shpnt), 0, sizeof *HOSTDATA(shpnt));
  685. INIT_LIST_HEAD(&HOSTDATA(shpnt)->host_list);
  686. /* need to have host registered before triggering any interrupt */
  687. list_add_tail(&HOSTDATA(shpnt)->host_list, &aha152x_host_list);
  688. shpnt->io_port = setup->io_port;
  689. shpnt->n_io_port = IO_RANGE;
  690. shpnt->irq = setup->irq;
  691. if (!setup->tc1550) {
  692. HOSTIOPORT0 = setup->io_port;
  693. HOSTIOPORT1 = setup->io_port;
  694. } else {
  695. HOSTIOPORT0 = setup->io_port+0x10;
  696. HOSTIOPORT1 = setup->io_port-0x10;
  697. }
  698. spin_lock_init(&QLOCK);
  699. RECONNECT = setup->reconnect;
  700. SYNCHRONOUS = setup->synchronous;
  701. PARITY = setup->parity;
  702. DELAY = setup->delay;
  703. EXT_TRANS = setup->ext_trans;
  704. #if defined(AHA152X_DEBUG)
  705. HOSTDATA(shpnt)->debug = setup->debug;
  706. #endif
  707. SETPORT(SCSIID, setup->scsiid << 4);
  708. shpnt->this_id = setup->scsiid;
  709. if (setup->reconnect)
  710. shpnt->can_queue = AHA152X_MAXQUEUE;
  711. /* RESET OUT */
  712. printk("aha152x: resetting bus...\n");
  713. SETPORT(SCSISEQ, SCSIRSTO);
  714. mdelay(256);
  715. SETPORT(SCSISEQ, 0);
  716. mdelay(DELAY);
  717. reset_ports(shpnt);
  718. printk(KERN_INFO
  719. "aha152x%d%s: "
  720. "vital data: rev=%x, "
  721. "io=0x%03lx (0x%03lx/0x%03lx), "
  722. "irq=%d, "
  723. "scsiid=%d, "
  724. "reconnect=%s, "
  725. "parity=%s, "
  726. "synchronous=%s, "
  727. "delay=%d, "
  728. "extended translation=%s\n",
  729. shpnt->host_no, setup->tc1550 ? " (tc1550 mode)" : "",
  730. GETPORT(REV) & 0x7,
  731. shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1,
  732. shpnt->irq,
  733. shpnt->this_id,
  734. RECONNECT ? "enabled" : "disabled",
  735. PARITY ? "enabled" : "disabled",
  736. SYNCHRONOUS ? "enabled" : "disabled",
  737. DELAY,
  738. EXT_TRANS ? "enabled" : "disabled");
  739. /* not expecting any interrupts */
  740. SETPORT(SIMODE0, 0);
  741. SETPORT(SIMODE1, 0);
  742. if( request_irq(shpnt->irq, swintr, IRQF_DISABLED|IRQF_SHARED, "aha152x", shpnt) ) {
  743. printk(KERN_ERR "aha152x%d: irq %d busy.\n", shpnt->host_no, shpnt->irq);
  744. goto out_host_put;
  745. }
  746. HOSTDATA(shpnt)->swint = 0;
  747. printk(KERN_INFO "aha152x%d: trying software interrupt, ", shpnt->host_no);
  748. mb();
  749. SETPORT(DMACNTRL0, SWINT|INTEN);
  750. mdelay(1000);
  751. free_irq(shpnt->irq, shpnt);
  752. if (!HOSTDATA(shpnt)->swint) {
  753. if (TESTHI(DMASTAT, INTSTAT)) {
  754. printk("lost.\n");
  755. } else {
  756. printk("failed.\n");
  757. }
  758. SETPORT(DMACNTRL0, INTEN);
  759. printk(KERN_ERR "aha152x%d: irq %d possibly wrong. "
  760. "Please verify.\n", shpnt->host_no, shpnt->irq);
  761. goto out_host_put;
  762. }
  763. printk("ok.\n");
  764. /* clear interrupts */
  765. SETPORT(SSTAT0, 0x7f);
  766. SETPORT(SSTAT1, 0xef);
  767. if ( request_irq(shpnt->irq, intr, IRQF_DISABLED|IRQF_SHARED, "aha152x", shpnt) ) {
  768. printk(KERN_ERR "aha152x%d: failed to reassign irq %d.\n", shpnt->host_no, shpnt->irq);
  769. goto out_host_put;
  770. }
  771. if( scsi_add_host(shpnt, NULL) ) {
  772. free_irq(shpnt->irq, shpnt);
  773. printk(KERN_ERR "aha152x%d: failed to add host.\n", shpnt->host_no);
  774. goto out_host_put;
  775. }
  776. scsi_scan_host(shpnt);
  777. return shpnt;
  778. out_host_put:
  779. list_del(&HOSTDATA(shpnt)->host_list);
  780. scsi_host_put(shpnt);
  781. return NULL;
  782. }
  783. void aha152x_release(struct Scsi_Host *shpnt)
  784. {
  785. if (!shpnt)
  786. return;
  787. scsi_remove_host(shpnt);
  788. if (shpnt->irq)
  789. free_irq(shpnt->irq, shpnt);
  790. #if !defined(PCMCIA)
  791. if (shpnt->io_port)
  792. release_region(shpnt->io_port, IO_RANGE);
  793. #endif
  794. #ifdef __ISAPNP__
  795. if (HOSTDATA(shpnt)->pnpdev)
  796. pnp_device_detach(HOSTDATA(shpnt)->pnpdev);
  797. #endif
  798. list_del(&HOSTDATA(shpnt)->host_list);
  799. scsi_host_put(shpnt);
  800. }
  801. /*
  802. * setup controller to generate interrupts depending
  803. * on current state (lock has to be acquired)
  804. *
  805. */
  806. static int setup_expected_interrupts(struct Scsi_Host *shpnt)
  807. {
  808. if(CURRENT_SC) {
  809. CURRENT_SC->SCp.phase |= 1 << 16;
  810. if(CURRENT_SC->SCp.phase & selecting) {
  811. DPRINTK(debug_intr, DEBUG_LEAD "expecting: (seldo) (seltimo) (seldi)\n", CMDINFO(CURRENT_SC));
  812. SETPORT(SSTAT1, SELTO);
  813. SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
  814. SETPORT(SIMODE1, ENSELTIMO);
  815. } else {
  816. DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (busfree) %s\n", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.phase & spiordy ? "(spiordy)" : "");
  817. SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0);
  818. SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
  819. }
  820. } else if(STATE==seldi) {
  821. DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (identify)\n", CMDINFO(CURRENT_SC));
  822. SETPORT(SIMODE0, 0);
  823. SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
  824. } else {
  825. DPRINTK(debug_intr, DEBUG_LEAD "expecting: %s %s\n",
  826. CMDINFO(CURRENT_SC),
  827. DISCONNECTED_SC ? "(reselection)" : "",
  828. ISSUE_SC ? "(busfree)" : "");
  829. SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
  830. SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
  831. }
  832. if(!HOSTDATA(shpnt)->in_intr)
  833. SETBITS(DMACNTRL0, INTEN);
  834. return TESTHI(DMASTAT, INTSTAT);
  835. }
  836. /*
  837. * Queue a command and setup interrupts for a free bus.
  838. */
  839. static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
  840. int phase, void (*done)(Scsi_Cmnd *))
  841. {
  842. struct Scsi_Host *shpnt = SCpnt->device->host;
  843. unsigned long flags;
  844. #if defined(AHA152X_DEBUG)
  845. if (HOSTDATA(shpnt)->debug & debug_queue) {
  846. printk(INFO_LEAD "queue: %p; cmd_len=%d pieces=%d size=%u cmnd=",
  847. CMDINFO(SCpnt), SCpnt, SCpnt->cmd_len,
  848. scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
  849. __scsi_print_command(SCpnt->cmnd);
  850. }
  851. #endif
  852. SCpnt->scsi_done = done;
  853. SCpnt->SCp.phase = not_issued | phase;
  854. SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */
  855. SCpnt->SCp.Message = 0;
  856. SCpnt->SCp.have_data_in = 0;
  857. SCpnt->SCp.sent_command = 0;
  858. if(SCpnt->SCp.phase & (resetting|check_condition)) {
  859. if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
  860. printk(ERR_LEAD "cannot reuse command\n", CMDINFO(SCpnt));
  861. return FAILED;
  862. }
  863. } else {
  864. SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
  865. if(!SCpnt->host_scribble) {
  866. printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt));
  867. return FAILED;
  868. }
  869. }
  870. SCNEXT(SCpnt) = NULL;
  871. SCSEM(SCpnt) = complete;
  872. /* setup scratch area
  873. SCp.ptr : buffer pointer
  874. SCp.this_residual : buffer length
  875. SCp.buffer : next buffer
  876. SCp.buffers_residual : left buffers in list
  877. SCp.phase : current state of the command */
  878. if ((phase & resetting) || !scsi_sglist(SCpnt)) {
  879. SCpnt->SCp.ptr = NULL;
  880. SCpnt->SCp.this_residual = 0;
  881. scsi_set_resid(SCpnt, 0);
  882. SCpnt->SCp.buffer = NULL;
  883. SCpnt->SCp.buffers_residual = 0;
  884. } else {
  885. scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
  886. SCpnt->SCp.buffer = scsi_sglist(SCpnt);
  887. SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer);
  888. SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
  889. SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
  890. }
  891. DO_LOCK(flags);
  892. #if defined(AHA152X_STAT)
  893. HOSTDATA(shpnt)->total_commands++;
  894. #endif
  895. /* Turn led on, when this is the first command. */
  896. HOSTDATA(shpnt)->commands++;
  897. if (HOSTDATA(shpnt)->commands==1)
  898. SETPORT(PORTA, 1);
  899. append_SC(&ISSUE_SC, SCpnt);
  900. if(!HOSTDATA(shpnt)->in_intr)
  901. setup_expected_interrupts(shpnt);
  902. DO_UNLOCK(flags);
  903. return 0;
  904. }
  905. /*
  906. * queue a command
  907. *
  908. */
  909. static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
  910. {
  911. #if 0
  912. if(*SCpnt->cmnd == REQUEST_SENSE) {
  913. SCpnt->result = 0;
  914. done(SCpnt);
  915. return 0;
  916. }
  917. #endif
  918. return aha152x_internal_queue(SCpnt, NULL, 0, done);
  919. }
  920. static DEF_SCSI_QCMD(aha152x_queue)
  921. /*
  922. *
  923. *
  924. */
  925. static void reset_done(Scsi_Cmnd *SCpnt)
  926. {
  927. #if 0
  928. struct Scsi_Host *shpnt = SCpnt->host;
  929. DPRINTK(debug_eh, INFO_LEAD "reset_done called\n", CMDINFO(SCpnt));
  930. #endif
  931. if(SCSEM(SCpnt)) {
  932. complete(SCSEM(SCpnt));
  933. } else {
  934. printk(KERN_ERR "aha152x: reset_done w/o completion\n");
  935. }
  936. }
  937. /*
  938. * Abort a command
  939. *
  940. */
  941. static int aha152x_abort(Scsi_Cmnd *SCpnt)
  942. {
  943. struct Scsi_Host *shpnt = SCpnt->device->host;
  944. Scsi_Cmnd *ptr;
  945. unsigned long flags;
  946. #if defined(AHA152X_DEBUG)
  947. if(HOSTDATA(shpnt)->debug & debug_eh) {
  948. printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt);
  949. show_queues(shpnt);
  950. }
  951. #endif
  952. DO_LOCK(flags);
  953. ptr=remove_SC(&ISSUE_SC, SCpnt);
  954. if(ptr) {
  955. DPRINTK(debug_eh, DEBUG_LEAD "not yet issued - SUCCESS\n", CMDINFO(SCpnt));
  956. HOSTDATA(shpnt)->commands--;
  957. if (!HOSTDATA(shpnt)->commands)
  958. SETPORT(PORTA, 0);
  959. DO_UNLOCK(flags);
  960. kfree(SCpnt->host_scribble);
  961. SCpnt->host_scribble=NULL;
  962. return SUCCESS;
  963. }
  964. DO_UNLOCK(flags);
  965. /*
  966. * FIXME:
  967. * for current command: queue ABORT for message out and raise ATN
  968. * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
  969. *
  970. */
  971. printk(ERR_LEAD "cannot abort running or disconnected command\n", CMDINFO(SCpnt));
  972. return FAILED;
  973. }
  974. /*
  975. * Reset a device
  976. *
  977. */
  978. static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
  979. {
  980. struct Scsi_Host *shpnt = SCpnt->device->host;
  981. DECLARE_COMPLETION(done);
  982. int ret, issued, disconnected;
  983. unsigned char old_cmd_len = SCpnt->cmd_len;
  984. unsigned long flags;
  985. unsigned long timeleft;
  986. #if defined(AHA152X_DEBUG)
  987. if(HOSTDATA(shpnt)->debug & debug_eh) {
  988. printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt);
  989. show_queues(shpnt);
  990. }
  991. #endif
  992. if(CURRENT_SC==SCpnt) {
  993. printk(ERR_LEAD "cannot reset current device\n", CMDINFO(SCpnt));
  994. return FAILED;
  995. }
  996. DO_LOCK(flags);
  997. issued = remove_SC(&ISSUE_SC, SCpnt) == NULL;
  998. disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt);
  999. DO_UNLOCK(flags);
  1000. SCpnt->cmd_len = 0;
  1001. aha152x_internal_queue(SCpnt, &done, resetting, reset_done);
  1002. timeleft = wait_for_completion_timeout(&done, 100*HZ);
  1003. if (!timeleft) {
  1004. /* remove command from issue queue */
  1005. DO_LOCK(flags);
  1006. remove_SC(&ISSUE_SC, SCpnt);
  1007. DO_UNLOCK(flags);
  1008. }
  1009. SCpnt->cmd_len = old_cmd_len;
  1010. DO_LOCK(flags);
  1011. if(SCpnt->SCp.phase & resetted) {
  1012. HOSTDATA(shpnt)->commands--;
  1013. if (!HOSTDATA(shpnt)->commands)
  1014. SETPORT(PORTA, 0);
  1015. kfree(SCpnt->host_scribble);
  1016. SCpnt->host_scribble=NULL;
  1017. ret = SUCCESS;
  1018. } else {
  1019. /* requeue */
  1020. if(!issued) {
  1021. append_SC(&ISSUE_SC, SCpnt);
  1022. } else if(disconnected) {
  1023. append_SC(&DISCONNECTED_SC, SCpnt);
  1024. }
  1025. ret = FAILED;
  1026. }
  1027. DO_UNLOCK(flags);
  1028. return ret;
  1029. }
  1030. static void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs)
  1031. {
  1032. Scsi_Cmnd *ptr;
  1033. ptr=*SCs;
  1034. while(ptr) {
  1035. Scsi_Cmnd *next;
  1036. if(SCDATA(ptr)) {
  1037. next = SCNEXT(ptr);
  1038. } else {
  1039. printk(DEBUG_LEAD "queue corrupted at %p\n", CMDINFO(ptr), ptr);
  1040. next = NULL;
  1041. }
  1042. if (!ptr->device->soft_reset) {
  1043. DPRINTK(debug_eh, DEBUG_LEAD "disconnected command %p removed\n", CMDINFO(ptr), ptr);
  1044. remove_SC(SCs, ptr);
  1045. HOSTDATA(shpnt)->commands--;
  1046. kfree(ptr->host_scribble);
  1047. ptr->host_scribble=NULL;
  1048. }
  1049. ptr = next;
  1050. }
  1051. }
  1052. /*
  1053. * Reset the bus
  1054. *
  1055. */
  1056. static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
  1057. {
  1058. unsigned long flags;
  1059. DO_LOCK(flags);
  1060. #if defined(AHA152X_DEBUG)
  1061. if(HOSTDATA(shpnt)->debug & debug_eh) {
  1062. printk(KERN_DEBUG "scsi%d: bus reset", shpnt->host_no);
  1063. show_queues(shpnt);
  1064. }
  1065. #endif
  1066. free_hard_reset_SCs(shpnt, &ISSUE_SC);
  1067. free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
  1068. DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting bus\n", shpnt->host_no);
  1069. SETPORT(SCSISEQ, SCSIRSTO);
  1070. mdelay(256);
  1071. SETPORT(SCSISEQ, 0);
  1072. mdelay(DELAY);
  1073. DPRINTK(debug_eh, KERN_DEBUG "scsi%d: bus resetted\n", shpnt->host_no);
  1074. setup_expected_interrupts(shpnt);
  1075. if(HOSTDATA(shpnt)->commands==0)
  1076. SETPORT(PORTA, 0);
  1077. DO_UNLOCK(flags);
  1078. return SUCCESS;
  1079. }
  1080. /*
  1081. * Reset the bus
  1082. *
  1083. */
  1084. static int aha152x_bus_reset(Scsi_Cmnd *SCpnt)
  1085. {
  1086. return aha152x_bus_reset_host(SCpnt->device->host);
  1087. }
  1088. /*
  1089. * Restore default values to the AIC-6260 registers and reset the fifos
  1090. *
  1091. */
  1092. static void reset_ports(struct Scsi_Host *shpnt)
  1093. {
  1094. unsigned long flags;
  1095. /* disable interrupts */
  1096. SETPORT(DMACNTRL0, RSTFIFO);
  1097. SETPORT(SCSISEQ, 0);
  1098. SETPORT(SXFRCTL1, 0);
  1099. SETPORT(SCSISIG, 0);
  1100. SETRATE(0);
  1101. /* clear all interrupt conditions */
  1102. SETPORT(SSTAT0, 0x7f);
  1103. SETPORT(SSTAT1, 0xef);
  1104. SETPORT(SSTAT4, SYNCERR | FWERR | FRERR);
  1105. SETPORT(DMACNTRL0, 0);
  1106. SETPORT(DMACNTRL1, 0);
  1107. SETPORT(BRSTCNTRL, 0xf1);
  1108. /* clear SCSI fifos and transfer count */
  1109. SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
  1110. SETPORT(SXFRCTL0, CH1);
  1111. DO_LOCK(flags);
  1112. setup_expected_interrupts(shpnt);
  1113. DO_UNLOCK(flags);
  1114. }
  1115. /*
  1116. * Reset the host (bus and controller)
  1117. *
  1118. */
  1119. int aha152x_host_reset_host(struct Scsi_Host *shpnt)
  1120. {
  1121. DPRINTK(debug_eh, KERN_DEBUG "scsi%d: host reset\n", shpnt->host_no);
  1122. aha152x_bus_reset_host(shpnt);
  1123. DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting ports\n", shpnt->host_no);
  1124. reset_ports(shpnt);
  1125. return SUCCESS;
  1126. }
  1127. /*
  1128. * Reset the host (bus and controller)
  1129. *
  1130. */
  1131. static int aha152x_host_reset(Scsi_Cmnd *SCpnt)
  1132. {
  1133. return aha152x_host_reset_host(SCpnt->device->host);
  1134. }
  1135. /*
  1136. * Return the "logical geometry"
  1137. *
  1138. */
  1139. static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  1140. sector_t capacity, int *info_array)
  1141. {
  1142. struct Scsi_Host *shpnt = sdev->host;
  1143. /* try default translation */
  1144. info_array[0] = 64;
  1145. info_array[1] = 32;
  1146. info_array[2] = (unsigned long)capacity / (64 * 32);
  1147. /* for disks >1GB do some guessing */
  1148. if (info_array[2] >= 1024) {
  1149. int info[3];
  1150. /* try to figure out the geometry from the partition table */
  1151. if (scsicam_bios_param(bdev, capacity, info) < 0 ||
  1152. !((info[0] == 64 && info[1] == 32) || (info[0] == 255 && info[1] == 63))) {
  1153. if (EXT_TRANS) {
  1154. printk(KERN_NOTICE
  1155. "aha152x: unable to verify geometry for disk with >1GB.\n"
  1156. " using extended translation.\n");
  1157. info_array[0] = 255;
  1158. info_array[1] = 63;
  1159. info_array[2] = (unsigned long)capacity / (255 * 63);
  1160. } else {
  1161. printk(KERN_NOTICE
  1162. "aha152x: unable to verify geometry for disk with >1GB.\n"
  1163. " Using default translation. Please verify yourself.\n"
  1164. " Perhaps you need to enable extended translation in the driver.\n"
  1165. " See Documentation/scsi/aha152x.txt for details.\n");
  1166. }
  1167. } else {
  1168. info_array[0] = info[0];
  1169. info_array[1] = info[1];
  1170. info_array[2] = info[2];
  1171. if (info[0] == 255 && !EXT_TRANS) {
  1172. printk(KERN_NOTICE
  1173. "aha152x: current partition table is using extended translation.\n"
  1174. " using it also, although it's not explicitly enabled.\n");
  1175. }
  1176. }
  1177. }
  1178. return 0;
  1179. }
  1180. /*
  1181. * Internal done function
  1182. *
  1183. */
  1184. static void done(struct Scsi_Host *shpnt, int error)
  1185. {
  1186. if (CURRENT_SC) {
  1187. if(DONE_SC)
  1188. printk(ERR_LEAD "there's already a completed command %p - will cause abort\n", CMDINFO(CURRENT_SC), DONE_SC);
  1189. DONE_SC = CURRENT_SC;
  1190. CURRENT_SC = NULL;
  1191. DONE_SC->result = error;
  1192. } else
  1193. printk(KERN_ERR "aha152x: done() called outside of command\n");
  1194. }
  1195. static struct work_struct aha152x_tq;
  1196. /*
  1197. * Run service completions on the card with interrupts enabled.
  1198. *
  1199. */
  1200. static void run(struct work_struct *work)
  1201. {
  1202. struct aha152x_hostdata *hd;
  1203. list_for_each_entry(hd, &aha152x_host_list, host_list) {
  1204. struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
  1205. is_complete(shost);
  1206. }
  1207. }
  1208. /*
  1209. * Interrupt handler
  1210. *
  1211. */
  1212. static irqreturn_t intr(int irqno, void *dev_id)
  1213. {
  1214. struct Scsi_Host *shpnt = dev_id;
  1215. unsigned long flags;
  1216. unsigned char rev, dmacntrl0;
  1217. /*
  1218. * Read a couple of registers that are known to not be all 1's. If
  1219. * we read all 1's (-1), that means that either:
  1220. *
  1221. * a. The host adapter chip has gone bad, and we cannot control it,
  1222. * OR
  1223. * b. The host adapter is a PCMCIA card that has been ejected
  1224. *
  1225. * In either case, we cannot do anything with the host adapter at
  1226. * this point in time. So just ignore the interrupt and return.
  1227. * In the latter case, the interrupt might actually be meant for
  1228. * someone else sharing this IRQ, and that driver will handle it.
  1229. */
  1230. rev = GETPORT(REV);
  1231. dmacntrl0 = GETPORT(DMACNTRL0);
  1232. if ((rev == 0xFF) && (dmacntrl0 == 0xFF))
  1233. return IRQ_NONE;
  1234. if( TESTLO(DMASTAT, INTSTAT) )
  1235. return IRQ_NONE;
  1236. /* no more interrupts from the controller, while we're busy.
  1237. INTEN is restored by the BH handler */
  1238. CLRBITS(DMACNTRL0, INTEN);
  1239. DO_LOCK(flags);
  1240. if( HOSTDATA(shpnt)->service==0 ) {
  1241. HOSTDATA(shpnt)->service=1;
  1242. /* Poke the BH handler */
  1243. INIT_WORK(&aha152x_tq, run);
  1244. schedule_work(&aha152x_tq);
  1245. }
  1246. DO_UNLOCK(flags);
  1247. return IRQ_HANDLED;
  1248. }
  1249. /*
  1250. * busfree phase
  1251. * - handle completition/disconnection/error of current command
  1252. * - start selection for next command (if any)
  1253. */
  1254. static void busfree_run(struct Scsi_Host *shpnt)
  1255. {
  1256. unsigned long flags;
  1257. #if defined(AHA152X_STAT)
  1258. int action=0;
  1259. #endif
  1260. SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
  1261. SETPORT(SXFRCTL0, CH1);
  1262. SETPORT(SSTAT1, CLRBUSFREE);
  1263. if(CURRENT_SC) {
  1264. #if defined(AHA152X_STAT)
  1265. action++;
  1266. #endif
  1267. CURRENT_SC->SCp.phase &= ~syncneg;
  1268. if(CURRENT_SC->SCp.phase & completed) {
  1269. /* target sent COMMAND COMPLETE */
  1270. done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
  1271. } else if(CURRENT_SC->SCp.phase & aborted) {
  1272. DPRINTK(debug_eh, DEBUG_LEAD "ABORT sent\n", CMDINFO(CURRENT_SC));
  1273. done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16));
  1274. } else if(CURRENT_SC->SCp.phase & resetted) {
  1275. DPRINTK(debug_eh, DEBUG_LEAD "BUS DEVICE RESET sent\n", CMDINFO(CURRENT_SC));
  1276. done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16));
  1277. } else if(CURRENT_SC->SCp.phase & disconnected) {
  1278. /* target sent DISCONNECT */
  1279. DPRINTK(debug_selection, DEBUG_LEAD "target disconnected at %d/%d\n",
  1280. CMDINFO(CURRENT_SC),
  1281. scsi_get_resid(CURRENT_SC),
  1282. scsi_bufflen(CURRENT_SC));
  1283. #if defined(AHA152X_STAT)
  1284. HOSTDATA(shpnt)->disconnections++;
  1285. #endif
  1286. append_SC(&DISCONNECTED_SC, CURRENT_SC);
  1287. CURRENT_SC->SCp.phase |= 1 << 16;
  1288. CURRENT_SC = NULL;
  1289. } else {
  1290. done(shpnt, DID_ERROR << 16);
  1291. }
  1292. #if defined(AHA152X_STAT)
  1293. } else {
  1294. HOSTDATA(shpnt)->busfree_without_old_command++;
  1295. #endif
  1296. }
  1297. DO_LOCK(flags);
  1298. if(DONE_SC) {
  1299. #if defined(AHA152X_STAT)
  1300. action++;
  1301. #endif
  1302. if(DONE_SC->SCp.phase & check_condition) {
  1303. struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
  1304. struct aha152x_scdata *sc = SCDATA(cmd);
  1305. #if 0
  1306. if(HOSTDATA(shpnt)->debug & debug_eh) {
  1307. printk(ERR_LEAD "received sense: ", CMDINFO(DONE_SC));
  1308. scsi_print_sense("bh", DONE_SC);
  1309. }
  1310. #endif
  1311. scsi_eh_restore_cmnd(cmd, &sc->ses);
  1312. cmd->SCp.Status = SAM_STAT_CHECK_CONDITION;
  1313. HOSTDATA(shpnt)->commands--;
  1314. if (!HOSTDATA(shpnt)->commands)
  1315. SETPORT(PORTA, 0); /* turn led off */
  1316. } else if(DONE_SC->SCp.Status==SAM_STAT_CHECK_CONDITION) {
  1317. #if defined(AHA152X_STAT)
  1318. HOSTDATA(shpnt)->busfree_with_check_condition++;
  1319. #endif
  1320. #if 0
  1321. DPRINTK(debug_eh, ERR_LEAD "CHECK CONDITION found\n", CMDINFO(DONE_SC));
  1322. #endif
  1323. if(!(DONE_SC->SCp.phase & not_issued)) {
  1324. struct aha152x_scdata *sc;
  1325. Scsi_Cmnd *ptr = DONE_SC;
  1326. DONE_SC=NULL;
  1327. #if 0
  1328. DPRINTK(debug_eh, ERR_LEAD "requesting sense\n", CMDINFO(ptr));
  1329. #endif
  1330. sc = SCDATA(ptr);
  1331. /* It was allocated in aha152x_internal_queue? */
  1332. BUG_ON(!sc);
  1333. scsi_eh_prep_cmnd(ptr, &sc->ses, NULL, 0, ~0);
  1334. DO_UNLOCK(flags);
  1335. aha152x_internal_queue(ptr, NULL, check_condition, ptr->scsi_done);
  1336. DO_LOCK(flags);
  1337. #if 0
  1338. } else {
  1339. DPRINTK(debug_eh, ERR_LEAD "command not issued - CHECK CONDITION ignored\n", CMDINFO(DONE_SC));
  1340. #endif
  1341. }
  1342. }
  1343. if(DONE_SC && DONE_SC->scsi_done) {
  1344. #if defined(AHA152X_DEBUG)
  1345. int hostno=DONE_SC->device->host->host_no;
  1346. int id=DONE_SC->device->id & 0xf;
  1347. int lun=DONE_SC->device->lun & 0x7;
  1348. #endif
  1349. Scsi_Cmnd *ptr = DONE_SC;
  1350. DONE_SC=NULL;
  1351. /* turn led off, when no commands are in the driver */
  1352. HOSTDATA(shpnt)->commands--;
  1353. if (!HOSTDATA(shpnt)->commands)
  1354. SETPORT(PORTA, 0); /* turn led off */
  1355. if(ptr->scsi_done != reset_done) {
  1356. kfree(ptr->host_scribble);
  1357. ptr->host_scribble=NULL;
  1358. }
  1359. DO_UNLOCK(flags);
  1360. DPRINTK(debug_done, DEBUG_LEAD "calling scsi_done(%p)\n", hostno, id, lun, ptr);
  1361. ptr->scsi_done(ptr);
  1362. DPRINTK(debug_done, DEBUG_LEAD "scsi_done(%p) returned\n", hostno, id, lun, ptr);
  1363. DO_LOCK(flags);
  1364. }
  1365. DONE_SC=NULL;
  1366. #if defined(AHA152X_STAT)
  1367. } else {
  1368. HOSTDATA(shpnt)->busfree_without_done_command++;
  1369. #endif
  1370. }
  1371. if(ISSUE_SC)
  1372. CURRENT_SC = remove_first_SC(&ISSUE_SC);
  1373. DO_UNLOCK(flags);
  1374. if(CURRENT_SC) {
  1375. #if defined(AHA152X_STAT)
  1376. action++;
  1377. #endif
  1378. CURRENT_SC->SCp.phase |= selecting;
  1379. DPRINTK(debug_selection, DEBUG_LEAD "selecting target\n", CMDINFO(CURRENT_SC));
  1380. /* clear selection timeout */
  1381. SETPORT(SSTAT1, SELTO);
  1382. SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->device->id);
  1383. SETPORT(SXFRCTL1, (PARITY ? ENSPCHK : 0 ) | ENSTIMER);
  1384. SETPORT(SCSISEQ, ENSELO | ENAUTOATNO | (DISCONNECTED_SC ? ENRESELI : 0));
  1385. } else {
  1386. #if defined(AHA152X_STAT)
  1387. HOSTDATA(shpnt)->busfree_without_new_command++;
  1388. #endif
  1389. SETPORT(SCSISEQ, DISCONNECTED_SC ? ENRESELI : 0);
  1390. }
  1391. #if defined(AHA152X_STAT)
  1392. if(!action)
  1393. HOSTDATA(shpnt)->busfree_without_any_action++;
  1394. #endif
  1395. }
  1396. /*
  1397. * Selection done (OUT)
  1398. * - queue IDENTIFY message and SDTR to selected target for message out
  1399. * (ATN asserted automagically via ENAUTOATNO in busfree())
  1400. */
  1401. static void seldo_run(struct Scsi_Host *shpnt)
  1402. {
  1403. SETPORT(SCSISIG, 0);
  1404. SETPORT(SSTAT1, CLRBUSFREE);
  1405. SETPORT(SSTAT1, CLRPHASECHG);
  1406. CURRENT_SC->SCp.phase &= ~(selecting|not_issued);
  1407. SETPORT(SCSISEQ, 0);
  1408. if (TESTLO(SSTAT0, SELDO)) {
  1409. printk(ERR_LEAD "aha152x: passing bus free condition\n", CMDINFO(CURRENT_SC));
  1410. done(shpnt, DID_NO_CONNECT << 16);
  1411. return;
  1412. }
  1413. SETPORT(SSTAT0, CLRSELDO);
  1414. ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
  1415. if (CURRENT_SC->SCp.phase & aborting) {
  1416. ADDMSGO(ABORT);
  1417. } else if (CURRENT_SC->SCp.phase & resetting) {
  1418. ADDMSGO(BUS_DEVICE_RESET);
  1419. } else if (SYNCNEG==0 && SYNCHRONOUS) {
  1420. CURRENT_SC->SCp.phase |= syncneg;
  1421. MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
  1422. SYNCNEG=1; /* negotiation in progress */
  1423. }
  1424. SETRATE(SYNCRATE);
  1425. }
  1426. /*
  1427. * Selection timeout
  1428. * - return command to mid-level with failure cause
  1429. *
  1430. */
  1431. static void selto_run(struct Scsi_Host *shpnt)
  1432. {
  1433. SETPORT(SCSISEQ, 0);
  1434. SETPORT(SSTAT1, CLRSELTIMO);
  1435. DPRINTK(debug_selection, DEBUG_LEAD "selection timeout\n", CMDINFO(CURRENT_SC));
  1436. if(!CURRENT_SC) {
  1437. DPRINTK(debug_selection, DEBUG_LEAD "!CURRENT_SC\n", CMDINFO(CURRENT_SC));
  1438. return;
  1439. }
  1440. CURRENT_SC->SCp.phase &= ~selecting;
  1441. if (CURRENT_SC->SCp.phase & aborted) {
  1442. DPRINTK(debug_selection, DEBUG_LEAD "aborted\n", CMDINFO(CURRENT_SC));
  1443. done(shpnt, DID_ABORT << 16);
  1444. } else if (TESTLO(SSTAT0, SELINGO)) {
  1445. DPRINTK(debug_selection, DEBUG_LEAD "arbitration not won\n", CMDINFO(CURRENT_SC));
  1446. done(shpnt, DID_BUS_BUSY << 16);
  1447. } else {
  1448. /* ARBITRATION won, but SELECTION failed */
  1449. DPRINTK(debug_selection, DEBUG_LEAD "selection failed\n", CMDINFO(CURRENT_SC));
  1450. done(shpnt, DID_NO_CONNECT << 16);
  1451. }
  1452. }
  1453. /*
  1454. * Selection in done
  1455. * - put current command back to issue queue
  1456. * (reconnection of a disconnected nexus instead
  1457. * of successful selection out)
  1458. *
  1459. */
  1460. static void seldi_run(struct Scsi_Host *shpnt)
  1461. {
  1462. int selid;
  1463. int target;
  1464. unsigned long flags;
  1465. SETPORT(SCSISIG, 0);
  1466. SETPORT(SSTAT0, CLRSELDI);
  1467. SETPORT(SSTAT1, CLRBUSFREE);
  1468. SETPORT(SSTAT1, CLRPHASECHG);
  1469. if(CURRENT_SC) {
  1470. if(!(CURRENT_SC->SCp.phase & not_issued))
  1471. printk(ERR_LEAD "command should not have been issued yet\n", CMDINFO(CURRENT_SC));
  1472. DPRINTK(debug_selection, ERR_LEAD "command requeued - reselection\n", CMDINFO(CURRENT_SC));
  1473. DO_LOCK(flags);
  1474. append_SC(&ISSUE_SC, CURRENT_SC);
  1475. DO_UNLOCK(flags);
  1476. CURRENT_SC = NULL;
  1477. }
  1478. if(!DISCONNECTED_SC) {
  1479. DPRINTK(debug_selection, DEBUG_LEAD "unexpected SELDI ", CMDINFO(CURRENT_SC));
  1480. return;
  1481. }
  1482. RECONN_TARGET=-1;
  1483. selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
  1484. if (selid==0) {
  1485. printk("aha152x%d: target id unknown (%02x)\n", HOSTNO, selid);
  1486. return;
  1487. }
  1488. for(target=7; !(selid & (1 << target)); target--)
  1489. ;
  1490. if(selid & ~(1 << target)) {
  1491. printk("aha152x%d: multiple targets reconnected (%02x)\n",
  1492. HOSTNO, selid);
  1493. }
  1494. SETPORT(SCSIID, (shpnt->this_id << OID_) | target);
  1495. SETPORT(SCSISEQ, 0);
  1496. SETRATE(HOSTDATA(shpnt)->syncrate[target]);
  1497. RECONN_TARGET=target;
  1498. DPRINTK(debug_selection, DEBUG_LEAD "target %d reselected (%02x).\n", CMDINFO(CURRENT_SC), target, selid);
  1499. }
  1500. /*
  1501. * message in phase
  1502. * - handle initial message after reconnection to identify
  1503. * reconnecting nexus
  1504. * - queue command on DISCONNECTED_SC on DISCONNECT message
  1505. * - set completed flag on COMMAND COMPLETE
  1506. * (other completition code moved to busfree_run)
  1507. * - handle response to SDTR
  1508. * - clear synchronous transfer agreements on BUS RESET
  1509. *
  1510. * FIXME: what about SAVE POINTERS, RESTORE POINTERS?
  1511. *
  1512. */
  1513. static void msgi_run(struct Scsi_Host *shpnt)
  1514. {
  1515. for(;;) {
  1516. int sstat1 = GETPORT(SSTAT1);
  1517. if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
  1518. return;
  1519. if(TESTLO(SSTAT0,SPIORDY)) {
  1520. DPRINTK(debug_msgi, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
  1521. return;
  1522. }
  1523. ADDMSGI(GETPORT(SCSIDAT));
  1524. #if defined(AHA152X_DEBUG)
  1525. if (HOSTDATA(shpnt)->debug & debug_msgi) {
  1526. printk(INFO_LEAD "inbound message %02x ", CMDINFO(CURRENT_SC), MSGI(0));
  1527. spi_print_msg(&MSGI(0));
  1528. printk("\n");
  1529. }
  1530. #endif
  1531. if(!CURRENT_SC) {
  1532. if(LASTSTATE!=seldi) {
  1533. printk(KERN_ERR "aha152x%d: message in w/o current command not after reselection\n", HOSTNO);
  1534. }
  1535. /*
  1536. * Handle reselection
  1537. */
  1538. if(!(MSGI(0) & IDENTIFY_BASE)) {
  1539. printk(KERN_ERR "aha152x%d: target didn't identify after reselection\n", HOSTNO);
  1540. continue;
  1541. }
  1542. CURRENT_SC = remove_lun_SC(&DISCONNECTED_SC, RECONN_TARGET, MSGI(0) & 0x3f);
  1543. if (!CURRENT_SC) {
  1544. show_queues(shpnt);
  1545. printk(KERN_ERR "aha152x%d: no disconnected command for target %d/%d\n", HOSTNO, RECONN_TARGET, MSGI(0) & 0x3f);
  1546. continue;
  1547. }
  1548. DPRINTK(debug_msgi, DEBUG_LEAD "target reconnected\n", CMDINFO(CURRENT_SC));
  1549. CURRENT_SC->SCp.Message = MSGI(0);
  1550. CURRENT_SC->SCp.phase &= ~disconnected;
  1551. MSGILEN=0;
  1552. /* next message if any */
  1553. continue;
  1554. }
  1555. CURRENT_SC->SCp.Message = MSGI(0);
  1556. switch (MSGI(0)) {
  1557. case DISCONNECT:
  1558. if (!RECONNECT)
  1559. printk(WARN_LEAD "target was not allowed to disconnect\n", CMDINFO(CURRENT_SC));
  1560. CURRENT_SC->SCp.phase |= disconnected;
  1561. break;
  1562. case COMMAND_COMPLETE:
  1563. if(CURRENT_SC->SCp.phase & completed)
  1564. DPRINTK(debug_msgi, DEBUG_LEAD "again COMMAND COMPLETE\n", CMDINFO(CURRENT_SC));
  1565. CURRENT_SC->SCp.phase |= completed;
  1566. break;
  1567. case MESSAGE_REJECT:
  1568. if (SYNCNEG==1) {
  1569. printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC));
  1570. SYNCNEG=2; /* negotiation completed */
  1571. } else
  1572. printk(INFO_LEAD "inbound message (MESSAGE REJECT)\n", CMDINFO(CURRENT_SC));
  1573. break;
  1574. case SAVE_POINTERS:
  1575. break;
  1576. case RESTORE_POINTERS:
  1577. break;
  1578. case EXTENDED_MESSAGE:
  1579. if(MSGILEN<2 || MSGILEN<MSGI(1)+2) {
  1580. /* not yet completed */
  1581. continue;
  1582. }
  1583. switch (MSGI(2)) {
  1584. case EXTENDED_SDTR:
  1585. {
  1586. long ticks;
  1587. if (MSGI(1) != 3) {
  1588. printk(ERR_LEAD "SDTR message length!=3\n", CMDINFO(CURRENT_SC));
  1589. break;
  1590. }
  1591. if (!HOSTDATA(shpnt)->synchronous)
  1592. break;
  1593. printk(INFO_LEAD, CMDINFO(CURRENT_SC));
  1594. spi_print_msg(&MSGI(0));
  1595. printk("\n");
  1596. ticks = (MSGI(3) * 4 + 49) / 50;
  1597. if (syncneg) {
  1598. /* negotiation in progress */
  1599. if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
  1600. ADDMSGO(MESSAGE_REJECT);
  1601. printk(INFO_LEAD "received Synchronous Data Transfer Request invalid - rejected\n", CMDINFO(CURRENT_SC));
  1602. break;
  1603. }
  1604. SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
  1605. } else if (ticks <= 9 && MSGI(4) >= 1) {
  1606. ADDMSGO(EXTENDED_MESSAGE);
  1607. ADDMSGO(3);
  1608. ADDMSGO(EXTENDED_SDTR);
  1609. if (ticks < 4) {
  1610. ticks = 4;
  1611. ADDMSGO(50);
  1612. } else
  1613. ADDMSGO(MSGI(3));
  1614. if (MSGI(4) > 8)
  1615. MSGI(4) = 8;
  1616. ADDMSGO(MSGI(4));
  1617. SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
  1618. } else {
  1619. /* requested SDTR is too slow, do it asynchronously */
  1620. printk(INFO_LEAD "Synchronous Data Transfer Request too slow - Rejecting\n", CMDINFO(CURRENT_SC));
  1621. ADDMSGO(MESSAGE_REJECT);
  1622. }
  1623. SYNCNEG=2; /* negotiation completed */
  1624. SETRATE(SYNCRATE);
  1625. }
  1626. break;
  1627. case BUS_DEVICE_RESET:
  1628. {
  1629. int i;
  1630. for(i=0; i<8; i++) {
  1631. HOSTDATA(shpnt)->syncrate[i]=0;
  1632. HOSTDATA(shpnt)->syncneg[i]=0;
  1633. }
  1634. }
  1635. break;
  1636. case EXTENDED_MODIFY_DATA_POINTER:
  1637. case EXTENDED_EXTENDED_IDENTIFY:
  1638. case EXTENDED_WDTR:
  1639. default:
  1640. ADDMSGO(MESSAGE_REJECT);
  1641. break;
  1642. }
  1643. break;
  1644. }
  1645. MSGILEN=0;
  1646. }
  1647. }
  1648. static void msgi_end(struct Scsi_Host *shpnt)
  1649. {
  1650. if(MSGILEN>0)
  1651. printk(WARN_LEAD "target left before message completed (%d)\n", CMDINFO(CURRENT_SC), MSGILEN);
  1652. if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE)) {
  1653. DPRINTK(debug_msgi, DEBUG_LEAD "msgo pending\n", CMDINFO(CURRENT_SC));
  1654. SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
  1655. }
  1656. }
  1657. /*
  1658. * message out phase
  1659. *
  1660. */
  1661. static void msgo_init(struct Scsi_Host *shpnt)
  1662. {
  1663. if(MSGOLEN==0) {
  1664. if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) {
  1665. ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
  1666. } else {
  1667. printk(INFO_LEAD "unexpected MESSAGE OUT phase; rejecting\n", CMDINFO(CURRENT_SC));
  1668. ADDMSGO(MESSAGE_REJECT);
  1669. }
  1670. }
  1671. #if defined(AHA152X_DEBUG)
  1672. if(HOSTDATA(shpnt)->debug & debug_msgo) {
  1673. int i;
  1674. printk(DEBUG_LEAD "messages( ", CMDINFO(CURRENT_SC));
  1675. for (i=0; i<MSGOLEN; i+=spi_print_msg(&MSGO(i)), printk(" "))
  1676. ;
  1677. printk(")\n");
  1678. }
  1679. #endif
  1680. }
  1681. /*
  1682. * message out phase
  1683. *
  1684. */
  1685. static void msgo_run(struct Scsi_Host *shpnt)
  1686. {
  1687. if(MSGO_I==MSGOLEN)
  1688. DPRINTK(debug_msgo, DEBUG_LEAD "messages all sent (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN);
  1689. while(MSGO_I<MSGOLEN) {
  1690. DPRINTK(debug_msgo, DEBUG_LEAD "message byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO(MSGO_I), MSGO_I, MSGOLEN);
  1691. if(TESTLO(SSTAT0, SPIORDY)) {
  1692. DPRINTK(debug_msgo, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
  1693. return;
  1694. }
  1695. if (MSGO_I==MSGOLEN-1) {
  1696. /* Leave MESSAGE OUT after transfer */
  1697. SETPORT(SSTAT1, CLRATNO);
  1698. }
  1699. if (MSGO(MSGO_I) & IDENTIFY_BASE)
  1700. CURRENT_SC->SCp.phase |= identified;
  1701. if (MSGO(MSGO_I)==ABORT)
  1702. CURRENT_SC->SCp.phase |= aborted;
  1703. if (MSGO(MSGO_I)==BUS_DEVICE_RESET)
  1704. CURRENT_SC->SCp.phase |= resetted;
  1705. SETPORT(SCSIDAT, MSGO(MSGO_I++));
  1706. }
  1707. }
  1708. static void msgo_end(struct Scsi_Host *shpnt)
  1709. {
  1710. if(MSGO_I<MSGOLEN) {
  1711. printk(ERR_LEAD "message sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN);
  1712. if(SYNCNEG==1) {
  1713. printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC));
  1714. SYNCNEG=2;
  1715. }
  1716. }
  1717. MSGO_I = 0;
  1718. MSGOLEN = 0;
  1719. }
  1720. /*
  1721. * command phase
  1722. *
  1723. */
  1724. static void cmd_init(struct Scsi_Host *shpnt)
  1725. {
  1726. if (CURRENT_SC->SCp.sent_command) {
  1727. printk(ERR_LEAD "command already sent\n", CMDINFO(CURRENT_SC));
  1728. done(shpnt, DID_ERROR << 16);
  1729. return;
  1730. }
  1731. #if defined(AHA152X_DEBUG)
  1732. if (HOSTDATA(shpnt)->debug & debug_cmd) {
  1733. printk(DEBUG_LEAD "cmd_init: ", CMDINFO(CURRENT_SC));
  1734. __scsi_print_command(CURRENT_SC->cmnd);
  1735. }
  1736. #endif
  1737. CMD_I=0;
  1738. }
  1739. /*
  1740. * command phase
  1741. *
  1742. */
  1743. static void cmd_run(struct Scsi_Host *shpnt)
  1744. {
  1745. if(CMD_I==CURRENT_SC->cmd_len) {
  1746. DPRINTK(debug_cmd, DEBUG_LEAD "command already completely sent (%d/%d)", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len);
  1747. disp_ports(shpnt);
  1748. }
  1749. while(CMD_I<CURRENT_SC->cmd_len) {
  1750. DPRINTK(debug_cmd, DEBUG_LEAD "command byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), CURRENT_SC->cmnd[CMD_I], CMD_I, CURRENT_SC->cmd_len);
  1751. if(TESTLO(SSTAT0, SPIORDY)) {
  1752. DPRINTK(debug_cmd, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
  1753. return;
  1754. }
  1755. SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
  1756. }
  1757. }
  1758. static void cmd_end(struct Scsi_Host *shpnt)
  1759. {
  1760. if(CMD_I<CURRENT_SC->cmd_len)
  1761. printk(ERR_LEAD "command sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len);
  1762. else
  1763. CURRENT_SC->SCp.sent_command++;
  1764. }
  1765. /*
  1766. * status phase
  1767. *
  1768. */
  1769. static void status_run(struct Scsi_Host *shpnt)
  1770. {
  1771. if(TESTLO(SSTAT0,SPIORDY)) {
  1772. DPRINTK(debug_status, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
  1773. return;
  1774. }
  1775. CURRENT_SC->SCp.Status = GETPORT(SCSIDAT);
  1776. #if defined(AHA152X_DEBUG)
  1777. if (HOSTDATA(shpnt)->debug & debug_status) {
  1778. printk(DEBUG_LEAD "inbound status %02x ", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.Status);
  1779. scsi_print_status(CURRENT_SC->SCp.Status);
  1780. printk("\n");
  1781. }
  1782. #endif
  1783. }
  1784. /*
  1785. * data in phase
  1786. *
  1787. */
  1788. static void datai_init(struct Scsi_Host *shpnt)
  1789. {
  1790. SETPORT(DMACNTRL0, RSTFIFO);
  1791. SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
  1792. SETPORT(SXFRCTL0, CH1|CLRSTCNT);
  1793. SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
  1794. SETPORT(SIMODE0, 0);
  1795. SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
  1796. DATA_LEN=0;
  1797. DPRINTK(debug_datai,
  1798. DEBUG_LEAD "datai_init: request_bufflen=%d resid=%d\n",
  1799. CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
  1800. scsi_get_resid(CURRENT_SC));
  1801. }
  1802. static void datai_run(struct Scsi_Host *shpnt)
  1803. {
  1804. unsigned long the_time;
  1805. int fifodata, data_count;
  1806. /*
  1807. * loop while the phase persists or the fifos are not empty
  1808. *
  1809. */
  1810. while(TESTLO(DMASTAT, INTSTAT) || TESTLO(DMASTAT, DFIFOEMP) || TESTLO(SSTAT2, SEMPTY)) {
  1811. /* FIXME: maybe this should be done by setting up
  1812. * STCNT to trigger ENSWRAP interrupt, instead of
  1813. * polling for DFIFOFULL
  1814. */
  1815. the_time=jiffies + 100*HZ;
  1816. while(TESTLO(DMASTAT, DFIFOFULL|INTSTAT) && time_before(jiffies,the_time))
  1817. barrier();
  1818. if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
  1819. printk(ERR_LEAD "datai timeout", CMDINFO(CURRENT_SC));
  1820. disp_ports(shpnt);
  1821. break;
  1822. }
  1823. if(TESTHI(DMASTAT, DFIFOFULL)) {
  1824. fifodata = 128;
  1825. } else {
  1826. the_time=jiffies + 100*HZ;
  1827. while(TESTLO(SSTAT2, SEMPTY) && time_before(jiffies,the_time))
  1828. barrier();
  1829. if(TESTLO(SSTAT2, SEMPTY)) {
  1830. printk(ERR_LEAD "datai sempty timeout", CMDINFO(CURRENT_SC));
  1831. disp_ports(shpnt);
  1832. break;
  1833. }
  1834. fifodata = GETPORT(FIFOSTAT);
  1835. }
  1836. if(CURRENT_SC->SCp.this_residual>0) {
  1837. while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) {
  1838. data_count = fifodata>CURRENT_SC->SCp.this_residual ?
  1839. CURRENT_SC->SCp.this_residual :
  1840. fifodata;
  1841. fifodata -= data_count;
  1842. if(data_count & 1) {
  1843. DPRINTK(debug_datai, DEBUG_LEAD "8bit\n", CMDINFO(CURRENT_SC));
  1844. SETPORT(DMACNTRL0, ENDMA|_8BIT);
  1845. *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT);
  1846. CURRENT_SC->SCp.this_residual--;
  1847. DATA_LEN++;
  1848. SETPORT(DMACNTRL0, ENDMA);
  1849. }
  1850. if(data_count > 1) {
  1851. DPRINTK(debug_datai, DEBUG_LEAD "16bit(%d)\n", CMDINFO(CURRENT_SC), data_count);
  1852. data_count >>= 1;
  1853. insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
  1854. CURRENT_SC->SCp.ptr += 2 * data_count;
  1855. CURRENT_SC->SCp.this_residual -= 2 * data_count;
  1856. DATA_LEN += 2 * data_count;
  1857. }
  1858. if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
  1859. /* advance to next buffer */
  1860. CURRENT_SC->SCp.buffers_residual--;
  1861. CURRENT_SC->SCp.buffer++;
  1862. CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
  1863. CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
  1864. }
  1865. }
  1866. } else if(fifodata>0) {
  1867. printk(ERR_LEAD "no buffers left for %d(%d) bytes (data overrun!?)\n", CMDINFO(CURRENT_SC), fifodata, GETPORT(FIFOSTAT));
  1868. SETPORT(DMACNTRL0, ENDMA|_8BIT);
  1869. while(fifodata>0) {
  1870. int data;
  1871. data=GETPORT(DATAPORT);
  1872. DPRINTK(debug_datai, DEBUG_LEAD "data=%02x\n", CMDINFO(CURRENT_SC), data);
  1873. fifodata--;
  1874. DATA_LEN++;
  1875. }
  1876. SETPORT(DMACNTRL0, ENDMA|_8BIT);
  1877. }
  1878. }
  1879. if(TESTLO(DMASTAT, INTSTAT) ||
  1880. TESTLO(DMASTAT, DFIFOEMP) ||
  1881. TESTLO(SSTAT2, SEMPTY) ||
  1882. GETPORT(FIFOSTAT)>0) {
  1883. /*
  1884. * something went wrong, if there's something left in the fifos
  1885. * or the phase didn't change
  1886. */
  1887. printk(ERR_LEAD "fifos should be empty and phase should have changed\n", CMDINFO(CURRENT_SC));
  1888. disp_ports(shpnt);
  1889. }
  1890. if(DATA_LEN!=GETSTCNT()) {
  1891. printk(ERR_LEAD
  1892. "manual transfer count differs from automatic (count=%d;stcnt=%d;diff=%d;fifostat=%d)",
  1893. CMDINFO(CURRENT_SC), DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN, GETPORT(FIFOSTAT));
  1894. disp_ports(shpnt);
  1895. mdelay(10000);
  1896. }
  1897. }
  1898. static void datai_end(struct Scsi_Host *shpnt)
  1899. {
  1900. CMD_INC_RESID(CURRENT_SC, -GETSTCNT());
  1901. DPRINTK(debug_datai,
  1902. DEBUG_LEAD "datai_end: request_bufflen=%d resid=%d stcnt=%d\n",
  1903. CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
  1904. scsi_get_resid(CURRENT_SC), GETSTCNT());
  1905. SETPORT(SXFRCTL0, CH1|CLRSTCNT);
  1906. SETPORT(DMACNTRL0, 0);
  1907. }
  1908. /*
  1909. * data out phase
  1910. *
  1911. */
  1912. static void datao_init(struct Scsi_Host *shpnt)
  1913. {
  1914. SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
  1915. SETPORT(DMACNTRL0, WRITE_READ | ENDMA);
  1916. SETPORT(SXFRCTL0, CH1|CLRSTCNT);
  1917. SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
  1918. SETPORT(SIMODE0, 0);
  1919. SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
  1920. DATA_LEN = scsi_get_resid(CURRENT_SC);
  1921. DPRINTK(debug_datao,
  1922. DEBUG_LEAD "datao_init: request_bufflen=%d; resid=%d\n",
  1923. CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
  1924. scsi_get_resid(CURRENT_SC));
  1925. }
  1926. static void datao_run(struct Scsi_Host *shpnt)
  1927. {
  1928. unsigned long the_time;
  1929. int data_count;
  1930. /* until phase changes or all data sent */
  1931. while(TESTLO(DMASTAT, INTSTAT) && CURRENT_SC->SCp.this_residual>0) {
  1932. data_count = 128;
  1933. if(data_count > CURRENT_SC->SCp.this_residual)
  1934. data_count=CURRENT_SC->SCp.this_residual;
  1935. if(TESTLO(DMASTAT, DFIFOEMP)) {
  1936. printk(ERR_LEAD "datao fifo not empty (%d)", CMDINFO(CURRENT_SC), GETPORT(FIFOSTAT));
  1937. disp_ports(shpnt);
  1938. break;
  1939. }
  1940. if(data_count & 1) {
  1941. SETPORT(DMACNTRL0,WRITE_READ|ENDMA|_8BIT);
  1942. SETPORT(DATAPORT, *CURRENT_SC->SCp.ptr++);
  1943. CURRENT_SC->SCp.this_residual--;
  1944. CMD_INC_RESID(CURRENT_SC, -1);
  1945. SETPORT(DMACNTRL0,WRITE_READ|ENDMA);
  1946. }
  1947. if(data_count > 1) {
  1948. data_count >>= 1;
  1949. outsw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
  1950. CURRENT_SC->SCp.ptr += 2 * data_count;
  1951. CURRENT_SC->SCp.this_residual -= 2 * data_count;
  1952. CMD_INC_RESID(CURRENT_SC, -2 * data_count);
  1953. }
  1954. if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
  1955. /* advance to next buffer */
  1956. CURRENT_SC->SCp.buffers_residual--;
  1957. CURRENT_SC->SCp.buffer++;
  1958. CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
  1959. CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
  1960. }
  1961. the_time=jiffies + 100*HZ;
  1962. while(TESTLO(DMASTAT, DFIFOEMP|INTSTAT) && time_before(jiffies,the_time))
  1963. barrier();
  1964. if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
  1965. printk(ERR_LEAD "dataout timeout", CMDINFO(CURRENT_SC));
  1966. disp_ports(shpnt);
  1967. break;
  1968. }
  1969. }
  1970. }
  1971. static void datao_end(struct Scsi_Host *shpnt)
  1972. {
  1973. if(TESTLO(DMASTAT, DFIFOEMP)) {
  1974. int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) -
  1975. GETSTCNT();
  1976. DPRINTK(debug_datao, DEBUG_LEAD "datao: %d bytes to resend (%d written, %d transferred)\n",
  1977. CMDINFO(CURRENT_SC),
  1978. data_count,
  1979. DATA_LEN - scsi_get_resid(CURRENT_SC),
  1980. GETSTCNT());
  1981. CMD_INC_RESID(CURRENT_SC, data_count);
  1982. data_count -= CURRENT_SC->SCp.ptr -
  1983. SG_ADDRESS(CURRENT_SC->SCp.buffer);
  1984. while(data_count>0) {
  1985. CURRENT_SC->SCp.buffer--;
  1986. CURRENT_SC->SCp.buffers_residual++;
  1987. data_count -= CURRENT_SC->SCp.buffer->length;
  1988. }
  1989. CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) -
  1990. data_count;
  1991. CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length +
  1992. data_count;
  1993. }
  1994. DPRINTK(debug_datao, DEBUG_LEAD "datao_end: request_bufflen=%d; resid=%d; stcnt=%d\n",
  1995. CMDINFO(CURRENT_SC),
  1996. scsi_bufflen(CURRENT_SC),
  1997. scsi_get_resid(CURRENT_SC),
  1998. GETSTCNT());
  1999. SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
  2000. SETPORT(SXFRCTL0, CH1);
  2001. SETPORT(DMACNTRL0, 0);
  2002. }
  2003. /*
  2004. * figure out what state we're in
  2005. *
  2006. */
  2007. static int update_state(struct Scsi_Host *shpnt)
  2008. {
  2009. int dataphase=0;
  2010. unsigned int stat0 = GETPORT(SSTAT0);
  2011. unsigned int stat1 = GETPORT(SSTAT1);
  2012. PREVSTATE = STATE;
  2013. STATE=unknown;
  2014. if(stat1 & SCSIRSTI) {
  2015. STATE=rsti;
  2016. SETPORT(SCSISEQ,0);
  2017. SETPORT(SSTAT1,SCSIRSTI);
  2018. } else if(stat0 & SELDI && PREVSTATE==busfree) {
  2019. STATE=seldi;
  2020. } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) {
  2021. STATE=seldo;
  2022. } else if(stat1 & SELTO) {
  2023. STATE=selto;
  2024. } else if(stat1 & BUSFREE) {
  2025. STATE=busfree;
  2026. SETPORT(SSTAT1,BUSFREE);
  2027. } else if(stat1 & SCSIPERR) {
  2028. STATE=parerr;
  2029. SETPORT(SSTAT1,SCSIPERR);
  2030. } else if(stat1 & REQINIT) {
  2031. switch(GETPORT(SCSISIG) & P_MASK) {
  2032. case P_MSGI: STATE=msgi; break;
  2033. case P_MSGO: STATE=msgo; break;
  2034. case P_DATAO: STATE=datao; break;
  2035. case P_DATAI: STATE=datai; break;
  2036. case P_STATUS: STATE=status; break;
  2037. case P_CMD: STATE=cmd; break;
  2038. }
  2039. dataphase=1;
  2040. }
  2041. if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
  2042. printk(INFO_LEAD "reselection missed?", CMDINFO(CURRENT_SC));
  2043. disp_ports(shpnt);
  2044. }
  2045. if(STATE!=PREVSTATE) {
  2046. LASTSTATE=PREVSTATE;
  2047. }
  2048. return dataphase;
  2049. }
  2050. /*
  2051. * handle parity error
  2052. *
  2053. * FIXME: in which phase?
  2054. *
  2055. */
  2056. static void parerr_run(struct Scsi_Host *shpnt)
  2057. {
  2058. printk(ERR_LEAD "parity error\n", CMDINFO(CURRENT_SC));
  2059. done(shpnt, DID_PARITY << 16);
  2060. }
  2061. /*
  2062. * handle reset in
  2063. *
  2064. */
  2065. static void rsti_run(struct Scsi_Host *shpnt)
  2066. {
  2067. Scsi_Cmnd *ptr;
  2068. printk(KERN_NOTICE "aha152x%d: scsi reset in\n", HOSTNO);
  2069. ptr=DISCONNECTED_SC;
  2070. while(ptr) {
  2071. Scsi_Cmnd *next = SCNEXT(ptr);
  2072. if (!ptr->device->soft_reset) {
  2073. remove_SC(&DISCONNECTED_SC, ptr);
  2074. kfree(ptr->host_scribble);
  2075. ptr->host_scribble=NULL;
  2076. ptr->result = DID_RESET << 16;
  2077. ptr->scsi_done(ptr);
  2078. }
  2079. ptr = next;
  2080. }
  2081. if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
  2082. done(shpnt, DID_RESET << 16 );
  2083. }
  2084. /*
  2085. * bottom-half handler
  2086. *
  2087. */
  2088. static void is_complete(struct Scsi_Host *shpnt)
  2089. {
  2090. int dataphase;
  2091. unsigned long flags;
  2092. int pending;
  2093. if(!shpnt)
  2094. return;
  2095. DO_LOCK(flags);
  2096. if( HOSTDATA(shpnt)->service==0 ) {
  2097. DO_UNLOCK(flags);
  2098. return;
  2099. }
  2100. HOSTDATA(shpnt)->service = 0;
  2101. if(HOSTDATA(shpnt)->in_intr) {
  2102. DO_UNLOCK(flags);
  2103. /* aha152x_error never returns.. */
  2104. aha152x_error(shpnt, "bottom-half already running!?");
  2105. }
  2106. HOSTDATA(shpnt)->in_intr++;
  2107. /*
  2108. * loop while there are interrupt conditions pending
  2109. *
  2110. */
  2111. do {
  2112. unsigned long start = jiffies;
  2113. DO_UNLOCK(flags);
  2114. dataphase=update_state(shpnt);
  2115. DPRINTK(debug_phases, LEAD "start %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
  2116. /*
  2117. * end previous state
  2118. *
  2119. */
  2120. if(PREVSTATE!=STATE && states[PREVSTATE].end)
  2121. states[PREVSTATE].end(shpnt);
  2122. /*
  2123. * disable SPIO mode if previous phase used it
  2124. * and this one doesn't
  2125. *
  2126. */
  2127. if(states[PREVSTATE].spio && !states[STATE].spio) {
  2128. SETPORT(SXFRCTL0, CH1);
  2129. SETPORT(DMACNTRL0, 0);
  2130. if(CURRENT_SC)
  2131. CURRENT_SC->SCp.phase &= ~spiordy;
  2132. }
  2133. /*
  2134. * accept current dataphase phase
  2135. *
  2136. */
  2137. if(dataphase) {
  2138. SETPORT(SSTAT0, REQINIT);
  2139. SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
  2140. SETPORT(SSTAT1, PHASECHG);
  2141. }
  2142. /*
  2143. * enable SPIO mode if previous didn't use it
  2144. * and this one does
  2145. *
  2146. */
  2147. if(!states[PREVSTATE].spio && states[STATE].spio) {
  2148. SETPORT(DMACNTRL0, 0);
  2149. SETPORT(SXFRCTL0, CH1|SPIOEN);
  2150. if(CURRENT_SC)
  2151. CURRENT_SC->SCp.phase |= spiordy;
  2152. }
  2153. /*
  2154. * initialize for new state
  2155. *
  2156. */
  2157. if(PREVSTATE!=STATE && states[STATE].init)
  2158. states[STATE].init(shpnt);
  2159. /*
  2160. * handle current state
  2161. *
  2162. */
  2163. if(states[STATE].run)
  2164. states[STATE].run(shpnt);
  2165. else
  2166. printk(ERR_LEAD "unexpected state (%x)\n", CMDINFO(CURRENT_SC), STATE);
  2167. /*
  2168. * setup controller to interrupt on
  2169. * the next expected condition and
  2170. * loop if it's already there
  2171. *
  2172. */
  2173. DO_LOCK(flags);
  2174. pending=setup_expected_interrupts(shpnt);
  2175. #if defined(AHA152X_STAT)
  2176. HOSTDATA(shpnt)->count[STATE]++;
  2177. if(PREVSTATE!=STATE)
  2178. HOSTDATA(shpnt)->count_trans[STATE]++;
  2179. HOSTDATA(shpnt)->time[STATE] += jiffies-start;
  2180. #endif
  2181. DPRINTK(debug_phases, LEAD "end %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
  2182. } while(pending);
  2183. /*
  2184. * enable interrupts and leave bottom-half
  2185. *
  2186. */
  2187. HOSTDATA(shpnt)->in_intr--;
  2188. SETBITS(DMACNTRL0, INTEN);
  2189. DO_UNLOCK(flags);
  2190. }
  2191. /*
  2192. * Dump the current driver status and panic
  2193. */
  2194. static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
  2195. {
  2196. printk(KERN_EMERG "\naha152x%d: %s\n", HOSTNO, msg);
  2197. show_queues(shpnt);
  2198. panic("aha152x panic\n");
  2199. }
  2200. /*
  2201. * Display registers of AIC-6260
  2202. */
  2203. static void disp_ports(struct Scsi_Host *shpnt)
  2204. {
  2205. #if defined(AHA152X_DEBUG)
  2206. int s;
  2207. printk("\n%s: %s(%s) ",
  2208. CURRENT_SC ? "busy" : "waiting",
  2209. states[STATE].name,
  2210. states[PREVSTATE].name);
  2211. s = GETPORT(SCSISEQ);
  2212. printk("SCSISEQ( ");
  2213. if (s & TEMODEO)
  2214. printk("TARGET MODE ");
  2215. if (s & ENSELO)
  2216. printk("SELO ");
  2217. if (s & ENSELI)
  2218. printk("SELI ");
  2219. if (s & ENRESELI)
  2220. printk("RESELI ");
  2221. if (s & ENAUTOATNO)
  2222. printk("AUTOATNO ");
  2223. if (s & ENAUTOATNI)
  2224. printk("AUTOATNI ");
  2225. if (s & ENAUTOATNP)
  2226. printk("AUTOATNP ");
  2227. if (s & SCSIRSTO)
  2228. printk("SCSIRSTO ");
  2229. printk(");");
  2230. printk(" SCSISIG(");
  2231. s = GETPORT(SCSISIG);
  2232. switch (s & P_MASK) {
  2233. case P_DATAO:
  2234. printk("DATA OUT");
  2235. break;
  2236. case P_DATAI:
  2237. printk("DATA IN");
  2238. break;
  2239. case P_CMD:
  2240. printk("COMMAND");
  2241. break;
  2242. case P_STATUS:
  2243. printk("STATUS");
  2244. break;
  2245. case P_MSGO:
  2246. printk("MESSAGE OUT");
  2247. break;
  2248. case P_MSGI:
  2249. printk("MESSAGE IN");
  2250. break;
  2251. default:
  2252. printk("*invalid*");
  2253. break;
  2254. }
  2255. printk("); ");
  2256. printk("INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
  2257. printk("SSTAT( ");
  2258. s = GETPORT(SSTAT0);
  2259. if (s & TARGET)
  2260. printk("TARGET ");
  2261. if (s & SELDO)
  2262. printk("SELDO ");
  2263. if (s & SELDI)
  2264. printk("SELDI ");
  2265. if (s & SELINGO)
  2266. printk("SELINGO ");
  2267. if (s & SWRAP)
  2268. printk("SWRAP ");
  2269. if (s & SDONE)
  2270. printk("SDONE ");
  2271. if (s & SPIORDY)
  2272. printk("SPIORDY ");
  2273. if (s & DMADONE)
  2274. printk("DMADONE ");
  2275. s = GETPORT(SSTAT1);
  2276. if (s & SELTO)
  2277. printk("SELTO ");
  2278. if (s & ATNTARG)
  2279. printk("ATNTARG ");
  2280. if (s & SCSIRSTI)
  2281. printk("SCSIRSTI ");
  2282. if (s & PHASEMIS)
  2283. printk("PHASEMIS ");
  2284. if (s & BUSFREE)
  2285. printk("BUSFREE ");
  2286. if (s & SCSIPERR)
  2287. printk("SCSIPERR ");
  2288. if (s & PHASECHG)
  2289. printk("PHASECHG ");
  2290. if (s & REQINIT)
  2291. printk("REQINIT ");
  2292. printk("); ");
  2293. printk("SSTAT( ");
  2294. s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
  2295. if (s & TARGET)
  2296. printk("TARGET ");
  2297. if (s & SELDO)
  2298. printk("SELDO ");
  2299. if (s & SELDI)
  2300. printk("SELDI ");
  2301. if (s & SELINGO)
  2302. printk("SELINGO ");
  2303. if (s & SWRAP)
  2304. printk("SWRAP ");
  2305. if (s & SDONE)
  2306. printk("SDONE ");
  2307. if (s & SPIORDY)
  2308. printk("SPIORDY ");
  2309. if (s & DMADONE)
  2310. printk("DMADONE ");
  2311. s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
  2312. if (s & SELTO)
  2313. printk("SELTO ");
  2314. if (s & ATNTARG)
  2315. printk("ATNTARG ");
  2316. if (s & SCSIRSTI)
  2317. printk("SCSIRSTI ");
  2318. if (s & PHASEMIS)
  2319. printk("PHASEMIS ");
  2320. if (s & BUSFREE)
  2321. printk("BUSFREE ");
  2322. if (s & SCSIPERR)
  2323. printk("SCSIPERR ");
  2324. if (s & PHASECHG)
  2325. printk("PHASECHG ");
  2326. if (s & REQINIT)
  2327. printk("REQINIT ");
  2328. printk("); ");
  2329. printk("SXFRCTL0( ");
  2330. s = GETPORT(SXFRCTL0);
  2331. if (s & SCSIEN)
  2332. printk("SCSIEN ");
  2333. if (s & DMAEN)
  2334. printk("DMAEN ");
  2335. if (s & CH1)
  2336. printk("CH1 ");
  2337. if (s & CLRSTCNT)
  2338. printk("CLRSTCNT ");
  2339. if (s & SPIOEN)
  2340. printk("SPIOEN ");
  2341. if (s & CLRCH1)
  2342. printk("CLRCH1 ");
  2343. printk("); ");
  2344. printk("SIGNAL( ");
  2345. s = GETPORT(SCSISIG);
  2346. if (s & SIG_ATNI)
  2347. printk("ATNI ");
  2348. if (s & SIG_SELI)
  2349. printk("SELI ");
  2350. if (s & SIG_BSYI)
  2351. printk("BSYI ");
  2352. if (s & SIG_REQI)
  2353. printk("REQI ");
  2354. if (s & SIG_ACKI)
  2355. printk("ACKI ");
  2356. printk("); ");
  2357. printk("SELID (%02x), ", GETPORT(SELID));
  2358. printk("STCNT (%d), ", GETSTCNT());
  2359. printk("SSTAT2( ");
  2360. s = GETPORT(SSTAT2);
  2361. if (s & SOFFSET)
  2362. printk("SOFFSET ");
  2363. if (s & SEMPTY)
  2364. printk("SEMPTY ");
  2365. if (s & SFULL)
  2366. printk("SFULL ");
  2367. printk("); SFCNT (%d); ", s & (SFULL | SFCNT));
  2368. s = GETPORT(SSTAT3);
  2369. printk("SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
  2370. printk("SSTAT4( ");
  2371. s = GETPORT(SSTAT4);
  2372. if (s & SYNCERR)
  2373. printk("SYNCERR ");
  2374. if (s & FWERR)
  2375. printk("FWERR ");
  2376. if (s & FRERR)
  2377. printk("FRERR ");
  2378. printk("); ");
  2379. printk("DMACNTRL0( ");
  2380. s = GETPORT(DMACNTRL0);
  2381. printk("%s ", s & _8BIT ? "8BIT" : "16BIT");
  2382. printk("%s ", s & DMA ? "DMA" : "PIO");
  2383. printk("%s ", s & WRITE_READ ? "WRITE" : "READ");
  2384. if (s & ENDMA)
  2385. printk("ENDMA ");
  2386. if (s & INTEN)
  2387. printk("INTEN ");
  2388. if (s & RSTFIFO)
  2389. printk("RSTFIFO ");
  2390. if (s & SWINT)
  2391. printk("SWINT ");
  2392. printk("); ");
  2393. printk("DMASTAT( ");
  2394. s = GETPORT(DMASTAT);
  2395. if (s & ATDONE)
  2396. printk("ATDONE ");
  2397. if (s & WORDRDY)
  2398. printk("WORDRDY ");
  2399. if (s & DFIFOFULL)
  2400. printk("DFIFOFULL ");
  2401. if (s & DFIFOEMP)
  2402. printk("DFIFOEMP ");
  2403. printk(")\n");
  2404. #endif
  2405. }
  2406. /*
  2407. * display enabled interrupts
  2408. */
  2409. static void disp_enintr(struct Scsi_Host *shpnt)
  2410. {
  2411. int s;
  2412. printk(KERN_DEBUG "enabled interrupts ( ");
  2413. s = GETPORT(SIMODE0);
  2414. if (s & ENSELDO)
  2415. printk("ENSELDO ");
  2416. if (s & ENSELDI)
  2417. printk("ENSELDI ");
  2418. if (s & ENSELINGO)
  2419. printk("ENSELINGO ");
  2420. if (s & ENSWRAP)
  2421. printk("ENSWRAP ");
  2422. if (s & ENSDONE)
  2423. printk("ENSDONE ");
  2424. if (s & ENSPIORDY)
  2425. printk("ENSPIORDY ");
  2426. if (s & ENDMADONE)
  2427. printk("ENDMADONE ");
  2428. s = GETPORT(SIMODE1);
  2429. if (s & ENSELTIMO)
  2430. printk("ENSELTIMO ");
  2431. if (s & ENATNTARG)
  2432. printk("ENATNTARG ");
  2433. if (s & ENPHASEMIS)
  2434. printk("ENPHASEMIS ");
  2435. if (s & ENBUSFREE)
  2436. printk("ENBUSFREE ");
  2437. if (s & ENSCSIPERR)
  2438. printk("ENSCSIPERR ");
  2439. if (s & ENPHASECHG)
  2440. printk("ENPHASECHG ");
  2441. if (s & ENREQINIT)
  2442. printk("ENREQINIT ");
  2443. printk(")\n");
  2444. }
  2445. /*
  2446. * Show the command data of a command
  2447. */
  2448. static void show_command(Scsi_Cmnd *ptr)
  2449. {
  2450. scmd_printk(KERN_DEBUG, ptr, "%p: cmnd=(", ptr);
  2451. __scsi_print_command(ptr->cmnd);
  2452. printk(KERN_DEBUG "); request_bufflen=%d; resid=%d; phase |",
  2453. scsi_bufflen(ptr), scsi_get_resid(ptr));
  2454. if (ptr->SCp.phase & not_issued)
  2455. printk("not issued|");
  2456. if (ptr->SCp.phase & selecting)
  2457. printk("selecting|");
  2458. if (ptr->SCp.phase & identified)
  2459. printk("identified|");
  2460. if (ptr->SCp.phase & disconnected)
  2461. printk("disconnected|");
  2462. if (ptr->SCp.phase & completed)
  2463. printk("completed|");
  2464. if (ptr->SCp.phase & spiordy)
  2465. printk("spiordy|");
  2466. if (ptr->SCp.phase & syncneg)
  2467. printk("syncneg|");
  2468. if (ptr->SCp.phase & aborted)
  2469. printk("aborted|");
  2470. if (ptr->SCp.phase & resetted)
  2471. printk("resetted|");
  2472. if( SCDATA(ptr) ) {
  2473. printk("; next=0x%p\n", SCNEXT(ptr));
  2474. } else {
  2475. printk("; next=(host scribble NULL)\n");
  2476. }
  2477. }
  2478. /*
  2479. * Dump the queued data
  2480. */
  2481. static void show_queues(struct Scsi_Host *shpnt)
  2482. {
  2483. Scsi_Cmnd *ptr;
  2484. unsigned long flags;
  2485. DO_LOCK(flags);
  2486. printk(KERN_DEBUG "\nqueue status:\nissue_SC:\n");
  2487. for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
  2488. show_command(ptr);
  2489. DO_UNLOCK(flags);
  2490. printk(KERN_DEBUG "current_SC:\n");
  2491. if (CURRENT_SC)
  2492. show_command(CURRENT_SC);
  2493. else
  2494. printk(KERN_DEBUG "none\n");
  2495. printk(KERN_DEBUG "disconnected_SC:\n");
  2496. for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL)
  2497. show_command(ptr);
  2498. disp_ports(shpnt);
  2499. disp_enintr(shpnt);
  2500. }
  2501. #undef SPRINTF
  2502. #define SPRINTF(args...) pos += sprintf(pos, ## args)
  2503. static int get_command(char *pos, Scsi_Cmnd * ptr)
  2504. {
  2505. char *start = pos;
  2506. int i;
  2507. SPRINTF("0x%08x: target=%d; lun=%d; cmnd=( ",
  2508. (unsigned int) ptr, ptr->device->id, ptr->device->lun);
  2509. for (i = 0; i < COMMAND_SIZE(ptr->cmnd[0]); i++)
  2510. SPRINTF("0x%02x ", ptr->cmnd[i]);
  2511. SPRINTF("); resid=%d; residual=%d; buffers=%d; phase |",
  2512. scsi_get_resid(ptr), ptr->SCp.this_residual,
  2513. ptr->SCp.buffers_residual);
  2514. if (ptr->SCp.phase & not_issued)
  2515. SPRINTF("not issued|");
  2516. if (ptr->SCp.phase & selecting)
  2517. SPRINTF("selecting|");
  2518. if (ptr->SCp.phase & disconnected)
  2519. SPRINTF("disconnected|");
  2520. if (ptr->SCp.phase & aborted)
  2521. SPRINTF("aborted|");
  2522. if (ptr->SCp.phase & identified)
  2523. SPRINTF("identified|");
  2524. if (ptr->SCp.phase & completed)
  2525. SPRINTF("completed|");
  2526. if (ptr->SCp.phase & spiordy)
  2527. SPRINTF("spiordy|");
  2528. if (ptr->SCp.phase & syncneg)
  2529. SPRINTF("syncneg|");
  2530. SPRINTF("; next=0x%p\n", SCNEXT(ptr));
  2531. return (pos - start);
  2532. }
  2533. static int get_ports(struct Scsi_Host *shpnt, char *pos)
  2534. {
  2535. char *start = pos;
  2536. int s;
  2537. SPRINTF("\n%s: %s(%s) ", CURRENT_SC ? "on bus" : "waiting", states[STATE].name, states[PREVSTATE].name);
  2538. s = GETPORT(SCSISEQ);
  2539. SPRINTF("SCSISEQ( ");
  2540. if (s & TEMODEO)
  2541. SPRINTF("TARGET MODE ");
  2542. if (s & ENSELO)
  2543. SPRINTF("SELO ");
  2544. if (s & ENSELI)
  2545. SPRINTF("SELI ");
  2546. if (s & ENRESELI)
  2547. SPRINTF("RESELI ");
  2548. if (s & ENAUTOATNO)
  2549. SPRINTF("AUTOATNO ");
  2550. if (s & ENAUTOATNI)
  2551. SPRINTF("AUTOATNI ");
  2552. if (s & ENAUTOATNP)
  2553. SPRINTF("AUTOATNP ");
  2554. if (s & SCSIRSTO)
  2555. SPRINTF("SCSIRSTO ");
  2556. SPRINTF(");");
  2557. SPRINTF(" SCSISIG(");
  2558. s = GETPORT(SCSISIG);
  2559. switch (s & P_MASK) {
  2560. case P_DATAO:
  2561. SPRINTF("DATA OUT");
  2562. break;
  2563. case P_DATAI:
  2564. SPRINTF("DATA IN");
  2565. break;
  2566. case P_CMD:
  2567. SPRINTF("COMMAND");
  2568. break;
  2569. case P_STATUS:
  2570. SPRINTF("STATUS");
  2571. break;
  2572. case P_MSGO:
  2573. SPRINTF("MESSAGE OUT");
  2574. break;
  2575. case P_MSGI:
  2576. SPRINTF("MESSAGE IN");
  2577. break;
  2578. default:
  2579. SPRINTF("*invalid*");
  2580. break;
  2581. }
  2582. SPRINTF("); ");
  2583. SPRINTF("INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
  2584. SPRINTF("SSTAT( ");
  2585. s = GETPORT(SSTAT0);
  2586. if (s & TARGET)
  2587. SPRINTF("TARGET ");
  2588. if (s & SELDO)
  2589. SPRINTF("SELDO ");
  2590. if (s & SELDI)
  2591. SPRINTF("SELDI ");
  2592. if (s & SELINGO)
  2593. SPRINTF("SELINGO ");
  2594. if (s & SWRAP)
  2595. SPRINTF("SWRAP ");
  2596. if (s & SDONE)
  2597. SPRINTF("SDONE ");
  2598. if (s & SPIORDY)
  2599. SPRINTF("SPIORDY ");
  2600. if (s & DMADONE)
  2601. SPRINTF("DMADONE ");
  2602. s = GETPORT(SSTAT1);
  2603. if (s & SELTO)
  2604. SPRINTF("SELTO ");
  2605. if (s & ATNTARG)
  2606. SPRINTF("ATNTARG ");
  2607. if (s & SCSIRSTI)
  2608. SPRINTF("SCSIRSTI ");
  2609. if (s & PHASEMIS)
  2610. SPRINTF("PHASEMIS ");
  2611. if (s & BUSFREE)
  2612. SPRINTF("BUSFREE ");
  2613. if (s & SCSIPERR)
  2614. SPRINTF("SCSIPERR ");
  2615. if (s & PHASECHG)
  2616. SPRINTF("PHASECHG ");
  2617. if (s & REQINIT)
  2618. SPRINTF("REQINIT ");
  2619. SPRINTF("); ");
  2620. SPRINTF("SSTAT( ");
  2621. s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
  2622. if (s & TARGET)
  2623. SPRINTF("TARGET ");
  2624. if (s & SELDO)
  2625. SPRINTF("SELDO ");
  2626. if (s & SELDI)
  2627. SPRINTF("SELDI ");
  2628. if (s & SELINGO)
  2629. SPRINTF("SELINGO ");
  2630. if (s & SWRAP)
  2631. SPRINTF("SWRAP ");
  2632. if (s & SDONE)
  2633. SPRINTF("SDONE ");
  2634. if (s & SPIORDY)
  2635. SPRINTF("SPIORDY ");
  2636. if (s & DMADONE)
  2637. SPRINTF("DMADONE ");
  2638. s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
  2639. if (s & SELTO)
  2640. SPRINTF("SELTO ");
  2641. if (s & ATNTARG)
  2642. SPRINTF("ATNTARG ");
  2643. if (s & SCSIRSTI)
  2644. SPRINTF("SCSIRSTI ");
  2645. if (s & PHASEMIS)
  2646. SPRINTF("PHASEMIS ");
  2647. if (s & BUSFREE)
  2648. SPRINTF("BUSFREE ");
  2649. if (s & SCSIPERR)
  2650. SPRINTF("SCSIPERR ");
  2651. if (s & PHASECHG)
  2652. SPRINTF("PHASECHG ");
  2653. if (s & REQINIT)
  2654. SPRINTF("REQINIT ");
  2655. SPRINTF("); ");
  2656. SPRINTF("SXFRCTL0( ");
  2657. s = GETPORT(SXFRCTL0);
  2658. if (s & SCSIEN)
  2659. SPRINTF("SCSIEN ");
  2660. if (s & DMAEN)
  2661. SPRINTF("DMAEN ");
  2662. if (s & CH1)
  2663. SPRINTF("CH1 ");
  2664. if (s & CLRSTCNT)
  2665. SPRINTF("CLRSTCNT ");
  2666. if (s & SPIOEN)
  2667. SPRINTF("SPIOEN ");
  2668. if (s & CLRCH1)
  2669. SPRINTF("CLRCH1 ");
  2670. SPRINTF("); ");
  2671. SPRINTF("SIGNAL( ");
  2672. s = GETPORT(SCSISIG);
  2673. if (s & SIG_ATNI)
  2674. SPRINTF("ATNI ");
  2675. if (s & SIG_SELI)
  2676. SPRINTF("SELI ");
  2677. if (s & SIG_BSYI)
  2678. SPRINTF("BSYI ");
  2679. if (s & SIG_REQI)
  2680. SPRINTF("REQI ");
  2681. if (s & SIG_ACKI)
  2682. SPRINTF("ACKI ");
  2683. SPRINTF("); ");
  2684. SPRINTF("SELID(%02x), ", GETPORT(SELID));
  2685. SPRINTF("STCNT(%d), ", GETSTCNT());
  2686. SPRINTF("SSTAT2( ");
  2687. s = GETPORT(SSTAT2);
  2688. if (s & SOFFSET)
  2689. SPRINTF("SOFFSET ");
  2690. if (s & SEMPTY)
  2691. SPRINTF("SEMPTY ");
  2692. if (s & SFULL)
  2693. SPRINTF("SFULL ");
  2694. SPRINTF("); SFCNT (%d); ", s & (SFULL | SFCNT));
  2695. s = GETPORT(SSTAT3);
  2696. SPRINTF("SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
  2697. SPRINTF("SSTAT4( ");
  2698. s = GETPORT(SSTAT4);
  2699. if (s & SYNCERR)
  2700. SPRINTF("SYNCERR ");
  2701. if (s & FWERR)
  2702. SPRINTF("FWERR ");
  2703. if (s & FRERR)
  2704. SPRINTF("FRERR ");
  2705. SPRINTF("); ");
  2706. SPRINTF("DMACNTRL0( ");
  2707. s = GETPORT(DMACNTRL0);
  2708. SPRINTF("%s ", s & _8BIT ? "8BIT" : "16BIT");
  2709. SPRINTF("%s ", s & DMA ? "DMA" : "PIO");
  2710. SPRINTF("%s ", s & WRITE_READ ? "WRITE" : "READ");
  2711. if (s & ENDMA)
  2712. SPRINTF("ENDMA ");
  2713. if (s & INTEN)
  2714. SPRINTF("INTEN ");
  2715. if (s & RSTFIFO)
  2716. SPRINTF("RSTFIFO ");
  2717. if (s & SWINT)
  2718. SPRINTF("SWINT ");
  2719. SPRINTF("); ");
  2720. SPRINTF("DMASTAT( ");
  2721. s = GETPORT(DMASTAT);
  2722. if (s & ATDONE)
  2723. SPRINTF("ATDONE ");
  2724. if (s & WORDRDY)
  2725. SPRINTF("WORDRDY ");
  2726. if (s & DFIFOFULL)
  2727. SPRINTF("DFIFOFULL ");
  2728. if (s & DFIFOEMP)
  2729. SPRINTF("DFIFOEMP ");
  2730. SPRINTF(")\n");
  2731. SPRINTF("enabled interrupts( ");
  2732. s = GETPORT(SIMODE0);
  2733. if (s & ENSELDO)
  2734. SPRINTF("ENSELDO ");
  2735. if (s & ENSELDI)
  2736. SPRINTF("ENSELDI ");
  2737. if (s & ENSELINGO)
  2738. SPRINTF("ENSELINGO ");
  2739. if (s & ENSWRAP)
  2740. SPRINTF("ENSWRAP ");
  2741. if (s & ENSDONE)
  2742. SPRINTF("ENSDONE ");
  2743. if (s & ENSPIORDY)
  2744. SPRINTF("ENSPIORDY ");
  2745. if (s & ENDMADONE)
  2746. SPRINTF("ENDMADONE ");
  2747. s = GETPORT(SIMODE1);
  2748. if (s & ENSELTIMO)
  2749. SPRINTF("ENSELTIMO ");
  2750. if (s & ENATNTARG)
  2751. SPRINTF("ENATNTARG ");
  2752. if (s & ENPHASEMIS)
  2753. SPRINTF("ENPHASEMIS ");
  2754. if (s & ENBUSFREE)
  2755. SPRINTF("ENBUSFREE ");
  2756. if (s & ENSCSIPERR)
  2757. SPRINTF("ENSCSIPERR ");
  2758. if (s & ENPHASECHG)
  2759. SPRINTF("ENPHASECHG ");
  2760. if (s & ENREQINIT)
  2761. SPRINTF("ENREQINIT ");
  2762. SPRINTF(")\n");
  2763. return (pos - start);
  2764. }
  2765. static int aha152x_set_info(char *buffer, int length, struct Scsi_Host *shpnt)
  2766. {
  2767. if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
  2768. return -EINVAL;
  2769. #if defined(AHA152X_DEBUG)
  2770. if(length>14 && strncmp("debug ", buffer+8, 6)==0) {
  2771. int debug = HOSTDATA(shpnt)->debug;
  2772. HOSTDATA(shpnt)->debug = simple_strtoul(buffer+14, NULL, 0);
  2773. printk(KERN_INFO "aha152x%d: debugging options set to 0x%04x (were 0x%04x)\n", HOSTNO, HOSTDATA(shpnt)->debug, debug);
  2774. } else
  2775. #endif
  2776. #if defined(AHA152X_STAT)
  2777. if(length>13 && strncmp("reset", buffer+8, 5)==0) {
  2778. int i;
  2779. HOSTDATA(shpnt)->total_commands=0;
  2780. HOSTDATA(shpnt)->disconnections=0;
  2781. HOSTDATA(shpnt)->busfree_without_any_action=0;
  2782. HOSTDATA(shpnt)->busfree_without_old_command=0;
  2783. HOSTDATA(shpnt)->busfree_without_new_command=0;
  2784. HOSTDATA(shpnt)->busfree_without_done_command=0;
  2785. HOSTDATA(shpnt)->busfree_with_check_condition=0;
  2786. for (i = idle; i<maxstate; i++) {
  2787. HOSTDATA(shpnt)->count[i]=0;
  2788. HOSTDATA(shpnt)->count_trans[i]=0;
  2789. HOSTDATA(shpnt)->time[i]=0;
  2790. }
  2791. printk(KERN_INFO "aha152x%d: stats reseted.\n", HOSTNO);
  2792. } else
  2793. #endif
  2794. {
  2795. return -EINVAL;
  2796. }
  2797. return length;
  2798. }
  2799. #undef SPRINTF
  2800. #define SPRINTF(args...) \
  2801. do { if(pos < buffer + length) pos += sprintf(pos, ## args); } while(0)
  2802. static int aha152x_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start,
  2803. off_t offset, int length, int inout)
  2804. {
  2805. int i;
  2806. char *pos = buffer;
  2807. Scsi_Cmnd *ptr;
  2808. unsigned long flags;
  2809. int thislength;
  2810. DPRINTK(debug_procinfo,
  2811. KERN_DEBUG "aha152x_proc_info: buffer=%p offset=%ld length=%d hostno=%d inout=%d\n",
  2812. buffer, offset, length, shpnt->host_no, inout);
  2813. if (inout)
  2814. return aha152x_set_info(buffer, length, shpnt);
  2815. SPRINTF(AHA152X_REVID "\n");
  2816. SPRINTF("ioports 0x%04lx to 0x%04lx\n",
  2817. shpnt->io_port, shpnt->io_port + shpnt->n_io_port - 1);
  2818. SPRINTF("interrupt 0x%02x\n", shpnt->irq);
  2819. SPRINTF("disconnection/reconnection %s\n",
  2820. RECONNECT ? "enabled" : "disabled");
  2821. SPRINTF("parity checking %s\n",
  2822. PARITY ? "enabled" : "disabled");
  2823. SPRINTF("synchronous transfers %s\n",
  2824. SYNCHRONOUS ? "enabled" : "disabled");
  2825. SPRINTF("%d commands currently queued\n", HOSTDATA(shpnt)->commands);
  2826. if(SYNCHRONOUS) {
  2827. SPRINTF("synchronously operating targets (tick=50 ns):\n");
  2828. for (i = 0; i < 8; i++)
  2829. if (HOSTDATA(shpnt)->syncrate[i] & 0x7f)
  2830. SPRINTF("target %d: period %dT/%dns; req/ack offset %d\n",
  2831. i,
  2832. (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2),
  2833. (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
  2834. HOSTDATA(shpnt)->syncrate[i] & 0x0f);
  2835. }
  2836. #if defined(AHA152X_DEBUG)
  2837. #define PDEBUG(flags,txt) \
  2838. if(HOSTDATA(shpnt)->debug & flags) SPRINTF("(%s) ", txt);
  2839. SPRINTF("enabled debugging options: ");
  2840. PDEBUG(debug_procinfo, "procinfo");
  2841. PDEBUG(debug_queue, "queue");
  2842. PDEBUG(debug_intr, "interrupt");
  2843. PDEBUG(debug_selection, "selection");
  2844. PDEBUG(debug_msgo, "message out");
  2845. PDEBUG(debug_msgi, "message in");
  2846. PDEBUG(debug_status, "status");
  2847. PDEBUG(debug_cmd, "command");
  2848. PDEBUG(debug_datai, "data in");
  2849. PDEBUG(debug_datao, "data out");
  2850. PDEBUG(debug_eh, "eh");
  2851. PDEBUG(debug_locking, "locks");
  2852. PDEBUG(debug_phases, "phases");
  2853. SPRINTF("\n");
  2854. #endif
  2855. SPRINTF("\nqueue status:\n");
  2856. DO_LOCK(flags);
  2857. if (ISSUE_SC) {
  2858. SPRINTF("not yet issued commands:\n");
  2859. for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
  2860. pos += get_command(pos, ptr);
  2861. } else
  2862. SPRINTF("no not yet issued commands\n");
  2863. DO_UNLOCK(flags);
  2864. if (CURRENT_SC) {
  2865. SPRINTF("current command:\n");
  2866. pos += get_command(pos, CURRENT_SC);
  2867. } else
  2868. SPRINTF("no current command\n");
  2869. if (DISCONNECTED_SC) {
  2870. SPRINTF("disconnected commands:\n");
  2871. for (ptr = DISCONNECTED_SC; ptr; ptr = SCNEXT(ptr))
  2872. pos += get_command(pos, ptr);
  2873. } else
  2874. SPRINTF("no disconnected commands\n");
  2875. pos += get_ports(shpnt, pos);
  2876. #if defined(AHA152X_STAT)
  2877. SPRINTF("statistics:\n"
  2878. "total commands: %d\n"
  2879. "disconnections: %d\n"
  2880. "busfree with check condition: %d\n"
  2881. "busfree without old command: %d\n"
  2882. "busfree without new command: %d\n"
  2883. "busfree without done command: %d\n"
  2884. "busfree without any action: %d\n"
  2885. "state "
  2886. "transitions "
  2887. "count "
  2888. "time\n",
  2889. HOSTDATA(shpnt)->total_commands,
  2890. HOSTDATA(shpnt)->disconnections,
  2891. HOSTDATA(shpnt)->busfree_with_check_condition,
  2892. HOSTDATA(shpnt)->busfree_without_old_command,
  2893. HOSTDATA(shpnt)->busfree_without_new_command,
  2894. HOSTDATA(shpnt)->busfree_without_done_command,
  2895. HOSTDATA(shpnt)->busfree_without_any_action);
  2896. for(i=0; i<maxstate; i++) {
  2897. SPRINTF("%-10s %-12d %-12d %-12ld\n",
  2898. states[i].name,
  2899. HOSTDATA(shpnt)->count_trans[i],
  2900. HOSTDATA(shpnt)->count[i],
  2901. HOSTDATA(shpnt)->time[i]);
  2902. }
  2903. #endif
  2904. DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: pos=%p\n", pos);
  2905. thislength = pos - (buffer + offset);
  2906. DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: length=%d thislength=%d\n", length, thislength);
  2907. if(thislength<0) {
  2908. DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: output too short\n");
  2909. *start = NULL;
  2910. return 0;
  2911. }
  2912. thislength = thislength<length ? thislength : length;
  2913. DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: return %d\n", thislength);
  2914. *start = buffer + offset;
  2915. return thislength < length ? thislength : length;
  2916. }
  2917. static int aha152x_adjust_queue(struct scsi_device *device)
  2918. {
  2919. blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
  2920. return 0;
  2921. }
  2922. static struct scsi_host_template aha152x_driver_template = {
  2923. .module = THIS_MODULE,
  2924. .name = AHA152X_REVID,
  2925. .proc_name = "aha152x",
  2926. .proc_info = aha152x_proc_info,
  2927. .queuecommand = aha152x_queue,
  2928. .eh_abort_handler = aha152x_abort,
  2929. .eh_device_reset_handler = aha152x_device_reset,
  2930. .eh_bus_reset_handler = aha152x_bus_reset,
  2931. .eh_host_reset_handler = aha152x_host_reset,
  2932. .bios_param = aha152x_biosparam,
  2933. .can_queue = 1,
  2934. .this_id = 7,
  2935. .sg_tablesize = SG_ALL,
  2936. .cmd_per_lun = 1,
  2937. .use_clustering = DISABLE_CLUSTERING,
  2938. .slave_alloc = aha152x_adjust_queue,
  2939. };
  2940. #if !defined(PCMCIA)
  2941. static int setup_count;
  2942. static struct aha152x_setup setup[2];
  2943. /* possible i/o addresses for the AIC-6260; default first */
  2944. static unsigned short ports[] = { 0x340, 0x140 };
  2945. #if !defined(SKIP_BIOSTEST)
  2946. /* possible locations for the Adaptec BIOS; defaults first */
  2947. static unsigned int addresses[] =
  2948. {
  2949. 0xdc000, /* default first */
  2950. 0xc8000,
  2951. 0xcc000,
  2952. 0xd0000,
  2953. 0xd4000,
  2954. 0xd8000,
  2955. 0xe0000,
  2956. 0xeb800, /* VTech Platinum SMP */
  2957. 0xf0000,
  2958. };
  2959. /* signatures for various AIC-6[23]60 based controllers.
  2960. The point in detecting signatures is to avoid useless and maybe
  2961. harmful probes on ports. I'm not sure that all listed boards pass
  2962. auto-configuration. For those which fail the BIOS signature is
  2963. obsolete, because user intervention to supply the configuration is
  2964. needed anyway. May be an information whether or not the BIOS supports
  2965. extended translation could be also useful here. */
  2966. static struct signature {
  2967. unsigned char *signature;
  2968. int sig_offset;
  2969. int sig_length;
  2970. } signatures[] =
  2971. {
  2972. { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
  2973. /* Adaptec 152x */
  2974. { "Adaptec AHA-1520B", 0x000b, 17 },
  2975. /* Adaptec 152x rev B */
  2976. { "Adaptec AHA-1520B", 0x0026, 17 },
  2977. /* Iomega Jaz Jet ISA (AIC6370Q) */
  2978. { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
  2979. /* on-board controller */
  2980. { "Adaptec BIOS: ASW-B626", 0x000f, 22 },
  2981. /* on-board controller */
  2982. { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
  2983. /* on-board controller */
  2984. { "Adaptec BIOS:AIC-6360", 0x000c, 21 },
  2985. /* on-board controller */
  2986. { "ScsiPro SP-360 BIOS", 0x2873, 19 },
  2987. /* ScsiPro-Controller */
  2988. { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
  2989. /* Gigabyte Local-Bus-SCSI */
  2990. { "Adaptec BIOS:AVA-282X", 0x000c, 21 },
  2991. /* Adaptec 282x */
  2992. { "Adaptec IBM Dock II SCSI", 0x2edd, 24 },
  2993. /* IBM Thinkpad Dock II */
  2994. { "Adaptec BIOS:AHA-1532P", 0x001c, 22 },
  2995. /* IBM Thinkpad Dock II SCSI */
  2996. { "DTC3520A Host Adapter BIOS", 0x318a, 26 },
  2997. /* DTC 3520A ISA SCSI */
  2998. };
  2999. #endif /* !SKIP_BIOSTEST */
  3000. /*
  3001. * Test, if port_base is valid.
  3002. *
  3003. */
  3004. static int aha152x_porttest(int io_port)
  3005. {
  3006. int i;
  3007. SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
  3008. for (i = 0; i < 16; i++)
  3009. SETPORT(io_port + O_STACK, i);
  3010. SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
  3011. for (i = 0; i < 16 && GETPORT(io_port + O_STACK) == i; i++)
  3012. ;
  3013. return (i == 16);
  3014. }
  3015. static int tc1550_porttest(int io_port)
  3016. {
  3017. int i;
  3018. SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
  3019. for (i = 0; i < 16; i++)
  3020. SETPORT(io_port + O_STACK, i);
  3021. SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
  3022. for (i = 0; i < 16 && GETPORT(io_port + O_TC_STACK) == i; i++)
  3023. ;
  3024. return (i == 16);
  3025. }
  3026. static int checksetup(struct aha152x_setup *setup)
  3027. {
  3028. int i;
  3029. for (i = 0; i < ARRAY_SIZE(ports) && (setup->io_port != ports[i]); i++)
  3030. ;
  3031. if (i == ARRAY_SIZE(ports))
  3032. return 0;
  3033. if (!request_region(setup->io_port, IO_RANGE, "aha152x")) {
  3034. printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup->io_port);
  3035. return 0;
  3036. }
  3037. if( aha152x_porttest(setup->io_port) ) {
  3038. setup->tc1550=0;
  3039. } else if( tc1550_porttest(setup->io_port) ) {
  3040. setup->tc1550=1;
  3041. } else {
  3042. release_region(setup->io_port, IO_RANGE);
  3043. return 0;
  3044. }
  3045. release_region(setup->io_port, IO_RANGE);
  3046. if ((setup->irq < IRQ_MIN) || (setup->irq > IRQ_MAX))
  3047. return 0;
  3048. if ((setup->scsiid < 0) || (setup->scsiid > 7))
  3049. return 0;
  3050. if ((setup->reconnect < 0) || (setup->reconnect > 1))
  3051. return 0;
  3052. if ((setup->parity < 0) || (setup->parity > 1))
  3053. return 0;
  3054. if ((setup->synchronous < 0) || (setup->synchronous > 1))
  3055. return 0;
  3056. if ((setup->ext_trans < 0) || (setup->ext_trans > 1))
  3057. return 0;
  3058. return 1;
  3059. }
  3060. static int __init aha152x_init(void)
  3061. {
  3062. int i, j, ok;
  3063. #if defined(AUTOCONF)
  3064. aha152x_config conf;
  3065. #endif
  3066. #ifdef __ISAPNP__
  3067. struct pnp_dev *dev=NULL, *pnpdev[2] = {NULL, NULL};
  3068. #endif
  3069. if ( setup_count ) {
  3070. printk(KERN_INFO "aha152x: processing commandline: ");
  3071. for (i = 0; i<setup_count; i++) {
  3072. if (!checksetup(&setup[i])) {
  3073. printk(KERN_ERR "\naha152x: %s\n", setup[i].conf);
  3074. printk(KERN_ERR "aha152x: invalid line\n");
  3075. }
  3076. }
  3077. printk("ok\n");
  3078. }
  3079. #if defined(SETUP0)
  3080. if (setup_count < ARRAY_SIZE(setup)) {
  3081. struct aha152x_setup override = SETUP0;
  3082. if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
  3083. if (!checksetup(&override)) {
  3084. printk(KERN_ERR "\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
  3085. override.io_port,
  3086. override.irq,
  3087. override.scsiid,
  3088. override.reconnect,
  3089. override.parity,
  3090. override.synchronous,
  3091. override.delay,
  3092. override.ext_trans);
  3093. } else
  3094. setup[setup_count++] = override;
  3095. }
  3096. }
  3097. #endif
  3098. #if defined(SETUP1)
  3099. if (setup_count < ARRAY_SIZE(setup)) {
  3100. struct aha152x_setup override = SETUP1;
  3101. if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
  3102. if (!checksetup(&override)) {
  3103. printk(KERN_ERR "\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
  3104. override.io_port,
  3105. override.irq,
  3106. override.scsiid,
  3107. override.reconnect,
  3108. override.parity,
  3109. override.synchronous,
  3110. override.delay,
  3111. override.ext_trans);
  3112. } else
  3113. setup[setup_count++] = override;
  3114. }
  3115. }
  3116. #endif
  3117. #if defined(MODULE)
  3118. if (setup_count<ARRAY_SIZE(setup) && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
  3119. if(aha152x[0]!=0) {
  3120. setup[setup_count].conf = "";
  3121. setup[setup_count].io_port = aha152x[0];
  3122. setup[setup_count].irq = aha152x[1];
  3123. setup[setup_count].scsiid = aha152x[2];
  3124. setup[setup_count].reconnect = aha152x[3];
  3125. setup[setup_count].parity = aha152x[4];
  3126. setup[setup_count].synchronous = aha152x[5];
  3127. setup[setup_count].delay = aha152x[6];
  3128. setup[setup_count].ext_trans = aha152x[7];
  3129. #if defined(AHA152X_DEBUG)
  3130. setup[setup_count].debug = aha152x[8];
  3131. #endif
  3132. } else if(io[0]!=0 || irq[0]!=0) {
  3133. if(io[0]!=0) setup[setup_count].io_port = io[0];
  3134. if(irq[0]!=0) setup[setup_count].irq = irq[0];
  3135. setup[setup_count].scsiid = scsiid[0];
  3136. setup[setup_count].reconnect = reconnect[0];
  3137. setup[setup_count].parity = parity[0];
  3138. setup[setup_count].synchronous = sync[0];
  3139. setup[setup_count].delay = delay[0];
  3140. setup[setup_count].ext_trans = exttrans[0];
  3141. #if defined(AHA152X_DEBUG)
  3142. setup[setup_count].debug = debug[0];
  3143. #endif
  3144. }
  3145. if (checksetup(&setup[setup_count]))
  3146. setup_count++;
  3147. else
  3148. printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
  3149. setup[setup_count].io_port,
  3150. setup[setup_count].irq,
  3151. setup[setup_count].scsiid,
  3152. setup[setup_count].reconnect,
  3153. setup[setup_count].parity,
  3154. setup[setup_count].synchronous,
  3155. setup[setup_count].delay,
  3156. setup[setup_count].ext_trans);
  3157. }
  3158. if (setup_count<ARRAY_SIZE(setup) && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
  3159. if(aha152x1[0]!=0) {
  3160. setup[setup_count].conf = "";
  3161. setup[setup_count].io_port = aha152x1[0];
  3162. setup[setup_count].irq = aha152x1[1];
  3163. setup[setup_count].scsiid = aha152x1[2];
  3164. setup[setup_count].reconnect = aha152x1[3];
  3165. setup[setup_count].parity = aha152x1[4];
  3166. setup[setup_count].synchronous = aha152x1[5];
  3167. setup[setup_count].delay = aha152x1[6];
  3168. setup[setup_count].ext_trans = aha152x1[7];
  3169. #if defined(AHA152X_DEBUG)
  3170. setup[setup_count].debug = aha152x1[8];
  3171. #endif
  3172. } else if(io[1]!=0 || irq[1]!=0) {
  3173. if(io[1]!=0) setup[setup_count].io_port = io[1];
  3174. if(irq[1]!=0) setup[setup_count].irq = irq[1];
  3175. setup[setup_count].scsiid = scsiid[1];
  3176. setup[setup_count].reconnect = reconnect[1];
  3177. setup[setup_count].parity = parity[1];
  3178. setup[setup_count].synchronous = sync[1];
  3179. setup[setup_count].delay = delay[1];
  3180. setup[setup_count].ext_trans = exttrans[1];
  3181. #if defined(AHA152X_DEBUG)
  3182. setup[setup_count].debug = debug[1];
  3183. #endif
  3184. }
  3185. if (checksetup(&setup[setup_count]))
  3186. setup_count++;
  3187. else
  3188. printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
  3189. setup[setup_count].io_port,
  3190. setup[setup_count].irq,
  3191. setup[setup_count].scsiid,
  3192. setup[setup_count].reconnect,
  3193. setup[setup_count].parity,
  3194. setup[setup_count].synchronous,
  3195. setup[setup_count].delay,
  3196. setup[setup_count].ext_trans);
  3197. }
  3198. #endif
  3199. #ifdef __ISAPNP__
  3200. for(i=0; setup_count<ARRAY_SIZE(setup) && id_table[i].vendor; i++) {
  3201. while ( setup_count<ARRAY_SIZE(setup) &&
  3202. (dev=pnp_find_dev(NULL, id_table[i].vendor, id_table[i].function, dev)) ) {
  3203. if (pnp_device_attach(dev) < 0)
  3204. continue;
  3205. if (pnp_activate_dev(dev) < 0) {
  3206. pnp_device_detach(dev);
  3207. continue;
  3208. }
  3209. if (!pnp_port_valid(dev, 0)) {
  3210. pnp_device_detach(dev);
  3211. continue;
  3212. }
  3213. if (setup_count==1 && pnp_port_start(dev, 0)==setup[0].io_port) {
  3214. pnp_device_detach(dev);
  3215. continue;
  3216. }
  3217. setup[setup_count].io_port = pnp_port_start(dev, 0);
  3218. setup[setup_count].irq = pnp_irq(dev, 0);
  3219. setup[setup_count].scsiid = 7;
  3220. setup[setup_count].reconnect = 1;
  3221. setup[setup_count].parity = 1;
  3222. setup[setup_count].synchronous = 1;
  3223. setup[setup_count].delay = DELAY_DEFAULT;
  3224. setup[setup_count].ext_trans = 0;
  3225. #if defined(AHA152X_DEBUG)
  3226. setup[setup_count].debug = DEBUG_DEFAULT;
  3227. #endif
  3228. #if defined(__ISAPNP__)
  3229. pnpdev[setup_count] = dev;
  3230. #endif
  3231. printk (KERN_INFO
  3232. "aha152x: found ISAPnP adapter at io=0x%03x, irq=%d\n",
  3233. setup[setup_count].io_port, setup[setup_count].irq);
  3234. setup_count++;
  3235. }
  3236. }
  3237. #endif
  3238. #if defined(AUTOCONF)
  3239. if (setup_count<ARRAY_SIZE(setup)) {
  3240. #if !defined(SKIP_BIOSTEST)
  3241. ok = 0;
  3242. for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++) {
  3243. void __iomem *p = ioremap(addresses[i], 0x4000);
  3244. if (!p)
  3245. continue;
  3246. for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
  3247. ok = check_signature(p + signatures[j].sig_offset,
  3248. signatures[j].signature, signatures[j].sig_length);
  3249. iounmap(p);
  3250. }
  3251. if (!ok && setup_count == 0)
  3252. return -ENODEV;
  3253. printk(KERN_INFO "aha152x: BIOS test: passed, ");
  3254. #else
  3255. printk(KERN_INFO "aha152x: ");
  3256. #endif /* !SKIP_BIOSTEST */
  3257. ok = 0;
  3258. for (i = 0; i < ARRAY_SIZE(ports) && setup_count < 2; i++) {
  3259. if ((setup_count == 1) && (setup[0].io_port == ports[i]))
  3260. continue;
  3261. if (!request_region(ports[i], IO_RANGE, "aha152x")) {
  3262. printk(KERN_ERR "aha152x: io port 0x%x busy.\n", ports[i]);
  3263. continue;
  3264. }
  3265. if (aha152x_porttest(ports[i])) {
  3266. setup[setup_count].tc1550 = 0;
  3267. conf.cf_port =
  3268. (GETPORT(ports[i] + O_PORTA) << 8) + GETPORT(ports[i] + O_PORTB);
  3269. } else if (tc1550_porttest(ports[i])) {
  3270. setup[setup_count].tc1550 = 1;
  3271. conf.cf_port =
  3272. (GETPORT(ports[i] + O_TC_PORTA) << 8) + GETPORT(ports[i] + O_TC_PORTB);
  3273. } else {
  3274. release_region(ports[i], IO_RANGE);
  3275. continue;
  3276. }
  3277. release_region(ports[i], IO_RANGE);
  3278. ok++;
  3279. setup[setup_count].io_port = ports[i];
  3280. setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
  3281. setup[setup_count].scsiid = conf.cf_id;
  3282. setup[setup_count].reconnect = conf.cf_tardisc;
  3283. setup[setup_count].parity = !conf.cf_parity;
  3284. setup[setup_count].synchronous = conf.cf_syncneg;
  3285. setup[setup_count].delay = DELAY_DEFAULT;
  3286. setup[setup_count].ext_trans = 0;
  3287. #if defined(AHA152X_DEBUG)
  3288. setup[setup_count].debug = DEBUG_DEFAULT;
  3289. #endif
  3290. setup_count++;
  3291. }
  3292. if (ok)
  3293. printk("auto configuration: ok, ");
  3294. }
  3295. #endif
  3296. printk("%d controller(s) configured\n", setup_count);
  3297. for (i=0; i<setup_count; i++) {
  3298. if ( request_region(setup[i].io_port, IO_RANGE, "aha152x") ) {
  3299. struct Scsi_Host *shpnt = aha152x_probe_one(&setup[i]);
  3300. if( !shpnt ) {
  3301. release_region(setup[i].io_port, IO_RANGE);
  3302. #if defined(__ISAPNP__)
  3303. } else if( pnpdev[i] ) {
  3304. HOSTDATA(shpnt)->pnpdev=pnpdev[i];
  3305. pnpdev[i]=NULL;
  3306. #endif
  3307. }
  3308. } else {
  3309. printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup[i].io_port);
  3310. }
  3311. #if defined(__ISAPNP__)
  3312. if( pnpdev[i] )
  3313. pnp_device_detach(pnpdev[i]);
  3314. #endif
  3315. }
  3316. return 0;
  3317. }
  3318. static void __exit aha152x_exit(void)
  3319. {
  3320. struct aha152x_hostdata *hd, *tmp;
  3321. list_for_each_entry_safe(hd, tmp, &aha152x_host_list, host_list) {
  3322. struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
  3323. aha152x_release(shost);
  3324. }
  3325. }
  3326. module_init(aha152x_init);
  3327. module_exit(aha152x_exit);
  3328. #if !defined(MODULE)
  3329. static int __init aha152x_setup(char *str)
  3330. {
  3331. #if defined(AHA152X_DEBUG)
  3332. int ints[11];
  3333. #else
  3334. int ints[10];
  3335. #endif
  3336. get_options(str, ARRAY_SIZE(ints), ints);
  3337. if(setup_count>=ARRAY_SIZE(setup)) {
  3338. printk(KERN_ERR "aha152x: you can only configure up to two controllers\n");
  3339. return 1;
  3340. }
  3341. setup[setup_count].conf = str;
  3342. setup[setup_count].io_port = ints[0] >= 1 ? ints[1] : 0x340;
  3343. setup[setup_count].irq = ints[0] >= 2 ? ints[2] : 11;
  3344. setup[setup_count].scsiid = ints[0] >= 3 ? ints[3] : 7;
  3345. setup[setup_count].reconnect = ints[0] >= 4 ? ints[4] : 1;
  3346. setup[setup_count].parity = ints[0] >= 5 ? ints[5] : 1;
  3347. setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
  3348. setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
  3349. setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
  3350. #if defined(AHA152X_DEBUG)
  3351. setup[setup_count].debug = ints[0] >= 9 ? ints[9] : DEBUG_DEFAULT;
  3352. if (ints[0] > 9) {
  3353. printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
  3354. "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>[,<DEBUG>]]]]]]]]\n");
  3355. #else
  3356. if (ints[0] > 8) { /*}*/
  3357. printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
  3358. "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
  3359. #endif
  3360. } else {
  3361. setup_count++;
  3362. return 0;
  3363. }
  3364. return 1;
  3365. }
  3366. __setup("aha152x=", aha152x_setup);
  3367. #endif
  3368. #endif /* !PCMCIA */