aha152x.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:96k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

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