Home | History | Annotate | Line # | Download | only in dev
      1  1.20      chs /*	$NetBSD: ncr5380reg.h,v 1.20 2012/10/27 17:17:59 chs Exp $	*/
      2   1.1   briggs 
      3   1.1   briggs /*
      4   1.1   briggs  * Copyright (c) 1995 Leo Weppelman.
      5   1.1   briggs  * All rights reserved.
      6   1.1   briggs  *
      7   1.1   briggs  * Redistribution and use in source and binary forms, with or without
      8   1.1   briggs  * modification, are permitted provided that the following conditions
      9   1.1   briggs  * are met:
     10   1.1   briggs  * 1. Redistributions of source code must retain the above copyright
     11   1.1   briggs  *    notice, this list of conditions and the following disclaimer.
     12   1.1   briggs  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   briggs  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   briggs  *    documentation and/or other materials provided with the distribution.
     15   1.1   briggs  *
     16   1.1   briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1   briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1   briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1   briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1   briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21   1.1   briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22   1.1   briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23   1.1   briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24   1.1   briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25   1.1   briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26   1.1   briggs  */
     27   1.1   briggs 
     28   1.1   briggs #ifndef _NCR5380REG_H
     29   1.1   briggs #define _NCR5380REG_H
     30   1.1   briggs /*
     31   1.1   briggs  * NCR5380 common interface definitions.
     32   1.1   briggs  */
     33   1.1   briggs 
     34   1.1   briggs /*
     35   1.1   briggs  * Register numbers: (first argument to GET/SET_5380_REG )
     36   1.1   briggs  */
     37   1.1   briggs #define	NCR5380_DATA	0		/* Data register		*/
     38   1.1   briggs #define	NCR5380_ICOM	1		/* Initiator command register	*/
     39   1.1   briggs #define	NCR5380_MODE	2		/* Mode register		*/
     40   1.1   briggs #define	NCR5380_TCOM	3		/* Target command register	*/
     41   1.1   briggs #define	NCR5380_IDSTAT	4		/* Bus status register		*/
     42   1.1   briggs #define	NCR5380_DMSTAT	5		/* DMA status register		*/
     43   1.1   briggs #define	NCR5380_TRCV	6		/* Target receive register	*/
     44   1.1   briggs #define	NCR5380_IRCV	7		/* Initiator receive register	*/
     45   1.1   briggs 
     46   1.1   briggs /*
     47   1.1   briggs  * Definitions for Initiator command register.
     48   1.1   briggs  */
     49   1.1   briggs #define	SC_A_RST	0x80	/* RW - Assert RST			*/
     50   1.1   briggs #define	SC_TEST		0x40	/* W  - Test mode			*/
     51   1.1   briggs #define	SC_AIP		0x40	/* R  - Arbitration in progress		*/
     52   1.1   briggs #define	SC_LA		0x20	/* R  - Lost arbitration		*/
     53   1.1   briggs #define	SC_A_ACK	0x10	/* RW - Assert ACK			*/
     54   1.1   briggs #define	SC_A_BSY	0x08	/* RW - Assert BSY			*/
     55   1.1   briggs #define	SC_A_SEL	0x04	/* RW - Assert SEL			*/
     56   1.1   briggs #define	SC_A_ATN	0x02	/* RW - Assert ATN			*/
     57   1.1   briggs #define	SC_ADTB		0x01	/* RW - Assert Data To Bus		*/
     58   1.1   briggs 
     59   1.1   briggs /*
     60   1.1   briggs  * Definitions for mode register
     61   1.1   briggs  */
     62   1.1   briggs #define	SC_B_DMA	0x80	/* RW - Block mode DMA (not on TT!)	*/
     63   1.1   briggs #define	SC_T_MODE	0x40	/* RW - Target mode			*/
     64   1.1   briggs #define	SC_E_PAR	0x20	/* RW - Enable parity check		*/
     65   1.1   briggs #define	SC_E_PARI	0x10	/* RW - Enable parity interrupt		*/
     66   1.1   briggs #define	SC_E_EOPI	0x08	/* RW - Enable End Of Process Interrupt	*/
     67   1.1   briggs #define	SC_MON_BSY	0x04	/* RW - Monitor BSY			*/
     68   1.1   briggs #define	SC_M_DMA	0x02	/* RW - Set DMA mode			*/
     69   1.1   briggs #define	SC_ARBIT	0x01	/* RW - Arbitrate			*/
     70   1.1   briggs 
     71   1.1   briggs /*
     72   1.1   briggs  * Definitions for tcom register
     73   1.1   briggs  */
     74   1.1   briggs #define	SC_LBS		0x80	/* RW - Last Byte Send (not on TT!)	*/
     75   1.1   briggs #define	SC_A_REQ	0x08	/* RW - Assert REQ			*/
     76   1.1   briggs #define	SC_A_MSG	0x04	/* RW - Assert MSG			*/
     77   1.1   briggs #define	SC_A_CD		0x02	/* RW - Assert C/D			*/
     78   1.1   briggs #define	SC_A_IO		0x01	/* RW - Assert I/O			*/
     79   1.1   briggs 
     80   1.1   briggs /*
     81   1.1   briggs  * Definitions for idstat register
     82   1.1   briggs  */
     83   1.1   briggs #define	SC_S_RST	0x80	/* R  - RST is set			*/
     84   1.1   briggs #define	SC_S_BSY	0x40	/* R  - BSY is set			*/
     85   1.1   briggs #define	SC_S_REQ	0x20	/* R  - REQ is set			*/
     86   1.1   briggs #define	SC_S_MSG	0x10	/* R  - MSG is set			*/
     87   1.1   briggs #define	SC_S_CD		0x08	/* R  - C/D is set			*/
     88   1.1   briggs #define	SC_S_IO		0x04	/* R  - I/O is set			*/
     89   1.1   briggs #define	SC_S_SEL	0x02	/* R  - SEL is set			*/
     90   1.1   briggs #define	SC_S_PAR	0x01	/* R  - Parity bit			*/
     91   1.1   briggs 
     92   1.1   briggs /*
     93   1.1   briggs  * Definitions for dmastat register
     94   1.1   briggs  */
     95   1.1   briggs #define	SC_END_DMA	0x80	/* R  - End of DMA			*/
     96   1.1   briggs #define	SC_DMA_REQ	0x40	/* R  - DMA request			*/
     97   1.1   briggs #define	SC_PAR_ERR	0x20	/* R  - Parity error			*/
     98   1.1   briggs #define	SC_IRQ_SET	0x10	/* R  - IRQ is active			*/
     99   1.1   briggs #define	SC_PHS_MTCH	0x08	/* R  - Phase Match			*/
    100   1.1   briggs #define	SC_BSY_ERR	0x04	/* R  - Busy error			*/
    101   1.1   briggs #define	SC_ATN_STAT	0x02	/* R  - State of ATN line		*/
    102   1.1   briggs #define	SC_ACK_STAT	0x01	/* R  - State of ACK line		*/
    103   1.1   briggs #define	SC_S_SEND	0x00	/* W  - Start DMA output		*/
    104   1.1   briggs 
    105   1.1   briggs #define	SC_CLINT	{ 		/* Clear interrupts	*/	\
    106   1.1   briggs 			int i = GET_5380_REG(NCR5380_IRCV);		\
    107   1.1   briggs 			}
    108   1.1   briggs 
    109   1.1   briggs 
    110   1.1   briggs /*
    111   1.1   briggs  * Definition of SCSI-bus phases. The values are determined by signals
    112   1.1   briggs  * on the SCSI-bus. DO NOT CHANGE!
    113   1.1   briggs  * The values must be used to index the pointers in SCSI-PARMS.
    114   1.1   briggs  */
    115   1.1   briggs #define	NR_PHASE	8
    116   1.1   briggs #define	PH_DATAOUT	0
    117   1.1   briggs #define	PH_DATAIN	1
    118   1.1   briggs #define	PH_CMD		2
    119   1.1   briggs #define	PH_STATUS	3
    120   1.1   briggs #define	PH_RES1		4
    121   1.1   briggs #define	PH_RES2		5
    122   1.1   briggs #define	PH_MSGOUT	6
    123   1.1   briggs #define	PH_MSGIN	7
    124   1.1   briggs 
    125   1.1   briggs #define	PH_OUT(phase)	(!(phase & 1))	/* TRUE if output phase		*/
    126   1.1   briggs #define	PH_IN(phase)	(phase & 1)	/* TRUE if input phase		*/
    127   1.1   briggs 
    128   1.1   briggs /*
    129   1.1   briggs  * Id of Host-adapter
    130   1.1   briggs  */
    131   1.1   briggs #define SC_HOST_ID	0x80
    132   1.1   briggs 
    133   1.1   briggs /*
    134   1.1   briggs  * Base setting for 5380 mode register
    135   1.1   briggs  */
    136   1.1   briggs #define	IMODE_BASE	SC_E_PAR
    137   1.1   briggs 
    138   1.1   briggs /*
    139   1.1   briggs  * SCSI completion status codes, should move to sys/scsi/????
    140   1.1   briggs  */
    141   1.1   briggs #define SCSMASK		0x1e	/* status code mask			*/
    142   1.1   briggs #define SCSGOOD		0x00	/* good status				*/
    143   1.1   briggs #define SCSCHKC		0x02	/* check condition			*/
    144   1.1   briggs #define SCSBUSY		0x08	/* busy status				*/
    145   1.1   briggs #define SCSCMET		0x04	/* condition met / good			*/
    146   1.1   briggs 
    147   1.1   briggs /*
    148   1.1   briggs  * Return values of check_intr()
    149   1.1   briggs  */
    150   1.1   briggs #define	INTR_SPURIOUS	0
    151   1.1   briggs #define	INTR_RESEL	2
    152   1.1   briggs #define	INTR_DMA	3
    153   1.1   briggs 
    154   1.1   briggs struct	ncr_softc {
    155  1.20      chs 	device_t		sc_dev;
    156  1.12   bouyer 	struct	scsipi_channel	sc_channel;
    157  1.11  thorpej 	struct	scsipi_adapter	sc_adapter;
    158   1.3   briggs 
    159   1.3   briggs 	/*
    160   1.3   briggs 	 * Some (pre-SCSI2) devices don't support select with ATN.
    161   1.3   briggs 	 * If the device responds to select with ATN by going into
    162   1.3   briggs 	 * command phase (ignoring ATN), then we flag it in the
    163   1.3   briggs 	 * following bitmask.
    164   1.3   briggs 	 * We also keep track of which devices have been selected
    165   1.3   briggs 	 * before.  This allows us to not even try raising ATN if
    166   1.3   briggs 	 * the target doesn't respond to it the first time.
    167   1.3   briggs 	 */
    168   1.3   briggs 	u_int8_t	sc_noselatn;
    169   1.3   briggs 	u_int8_t	sc_selected;
    170   1.1   briggs };
    171   1.1   briggs 
    172   1.1   briggs /*
    173  1.14      wiz  * Max. number of DMA-chains per request
    174   1.1   briggs  */
    175  1.13  thorpej #define	MAXDMAIO	(MAXPHYS/PAGE_SIZE + 1)
    176   1.1   briggs 
    177   1.1   briggs /*
    178   1.1   briggs  * Some requests are not contiguous in physical memory. We need to break them
    179   1.1   briggs  * up into contiguous parts for DMA.
    180   1.1   briggs  */
    181   1.1   briggs struct dma_chain {
    182   1.1   briggs 	u_int	dm_count;
    183   1.1   briggs 	u_long	dm_addr;
    184   1.1   briggs };
    185   1.1   briggs 
    186   1.1   briggs /*
    187   1.1   briggs  * Define our issue, free and disconnect queue's.
    188   1.1   briggs  */
    189   1.1   briggs typedef struct	req_q {
    190   1.1   briggs     struct req_q	*next;	    /* next in free, issue or discon queue  */
    191   1.1   briggs     struct req_q	*link;	    /* next linked command to execute       */
    192  1.10   bouyer     struct scsipi_xfer	*xs;	    /* request from high-level driver       */
    193   1.1   briggs     u_short		dr_flag;    /* driver state			    */
    194   1.1   briggs     u_char		phase;	    /* current SCSI phase		    */
    195   1.1   briggs     u_char		msgout;	    /* message to send when requested       */
    196   1.1   briggs     u_char		targ_id;    /* target for command		    */
    197   1.1   briggs     u_char		targ_lun;   /* lun for command			    */
    198   1.1   briggs     u_char		status;	    /* returned status byte		    */
    199   1.1   briggs     u_char		message;    /* returned message byte		    */
    200   1.1   briggs     u_char		*bounceb;   /* allocated bounce buffer		    */
    201   1.1   briggs     u_char		*bouncerp;  /* bounce read-pointer		    */
    202   1.1   briggs     struct dma_chain	dm_chain[MAXDMAIO];
    203  1.14      wiz     struct dma_chain	*dm_cur;    /* current DMA-request		    */
    204  1.14      wiz     struct dma_chain	*dm_last;   /* last DMA-request			    */
    205   1.1   briggs     long		xdata_len;  /* length of transfer		    */
    206   1.2   briggs     u_char		*xdata_ptr; /* virtual address of transfer	    */
    207  1.15  thorpej     struct scsipi_generic xcmd;	    /* command to execute		    */
    208  1.15  thorpej      int                xcmd_len;   /* command length                       */
    209   1.1   briggs } SC_REQ;
    210   1.1   briggs 
    211   1.1   briggs /*
    212   1.1   briggs  * Values for dr_flag:
    213   1.1   briggs  */
    214   1.1   briggs #define	DRIVER_IN_DMA	0x01	/* Non-polled DMA activated		*/
    215   1.1   briggs #define	DRIVER_AUTOSEN	0x02	/* Doing automatic sense		*/
    216   1.1   briggs #define	DRIVER_NOINT	0x04	/* We are booting: no interrupts	*/
    217   1.1   briggs #define	DRIVER_DMAOK	0x08	/* DMA can be used on this request	*/
    218   1.1   briggs #define	DRIVER_BOUNCING	0x10	/* Using the bounce buffer		*/
    219   1.5   briggs #define DRIVER_LINKCHK	0x20	/* Doing the linked command check	*/
    220   1.1   briggs 
    221   1.1   briggs /* XXX: Should go to ncr5380var.h */
    222   1.1   briggs static SC_REQ	*issue_q   = NULL;	/* Commands waiting to be issued*/
    223   1.1   briggs static SC_REQ	*discon_q  = NULL;	/* Commands disconnected	*/
    224   1.1   briggs static SC_REQ	*connected = NULL;	/* Command currently connected	*/
    225   1.1   briggs 
    226   1.1   briggs /*
    227   1.1   briggs  * Function decls:
    228   1.1   briggs  */
    229  1.16      chs static int  transfer_pio(u_char *, u_char *, u_long *, int);
    230  1.16      chs static int  wait_req_true(void);
    231  1.16      chs static int  wait_req_false(void);
    232  1.16      chs static int  scsi_select(SC_REQ *, int);
    233  1.16      chs static int  handle_message(SC_REQ *, u_int);
    234  1.16      chs static void ack_message(void);
    235  1.16      chs static void nack_message(SC_REQ *, u_char);
    236  1.16      chs static void finish_req(SC_REQ *);
    237  1.16      chs static int  information_transfer(struct ncr_softc *);
    238  1.16      chs static void reselect(struct ncr_softc *);
    239  1.16      chs static int  check_autosense(SC_REQ *, int);
    240  1.16      chs static int  reach_msg_out(struct ncr_softc *, u_long);
    241  1.16      chs static int  check_intr(struct ncr_softc *);
    242  1.16      chs static void scsi_reset(void);
    243  1.16      chs static void scsi_reset_verbose(struct ncr_softc *, const char *);
    244  1.16      chs static void run_main(struct ncr_softc *);
    245  1.16      chs static void scsi_main(struct ncr_softc *);
    246  1.16      chs static void ncr_ctrl_intr(struct ncr_softc *);
    247  1.17      jmc static void ncr_tprint(SC_REQ *, const char *, ...);
    248  1.17      jmc static void ncr_aprint(struct ncr_softc *, const char *, ...);
    249  1.16      chs 
    250  1.16      chs static void show_data_sense(struct scsipi_xfer *);
    251  1.17      jmc static void show_request(SC_REQ *, const char *);
    252  1.16      chs /* static void show_phase(SC_REQ *, int); */
    253  1.16      chs static void show_signals(u_char, u_char);
    254   1.1   briggs 
    255   1.1   briggs #endif /* _NCR5380REG_H */
    256