Home | History | Annotate | Line # | Download | only in ic
ncr5380var.h revision 1.6
      1 /*	$NetBSD: ncr5380var.h,v 1.6 1996/05/10 18:04:06 gwr Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 David Jones, Gordon W. Ross
      5  * Copyright (c) 1994 Jarle Greipsland
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. The name of the authors may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission.
     18  * 4. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed by
     21  *      David Jones and Gordon Ross
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * This file defines the interface between the machine-dependent
     37  * module and the machine-indepenedent ncr5380sbc.c module.
     38  */
     39 
     40 #define SCI_CLR_INTR(sc)	(*(sc)->sci_iack)
     41 #define	SCI_BUSY(sc)		(*sc->sci_bus_csr & SCI_BUS_BSY)
     42 
     43 /* These are NOT artibtrary, but map to bits in sci_tcmd */
     44 #define PHASE_DATA_OUT	0x0
     45 #define PHASE_DATA_IN	0x1
     46 #define PHASE_COMMAND	0x2
     47 #define PHASE_STATUS	0x3
     48 #define PHASE_UNSPEC1	0x4
     49 #define PHASE_UNSPEC2	0x5
     50 #define PHASE_MSG_OUT	0x6
     51 #define PHASE_MSG_IN	0x7
     52 
     53 /*
     54  * This illegal phase is used to prevent the 5380 from having
     55  * a phase-match condition when we don't want one, such as
     56  * when setting up the DMA engine or whatever...
     57  */
     58 #define PHASE_INVALID	PHASE_UNSPEC1
     59 
     60 
     61 /* Per-request state.  This is required in order to support reselection. */
     62 struct sci_req {
     63 	struct		scsi_xfer *sr_xs;	/* Pointer to xfer struct, NULL=unused */
     64 	int		sr_target, sr_lun;	/* For fast access */
     65 	void		*sr_dma_hand;		/* Current DMA hnadle */
     66 	u_char		*sr_dataptr;		/* Saved data pointer */
     67 	int		sr_datalen;
     68 	int		sr_flags;		/* Internal error code */
     69 #define	SR_IMMED			1	/* Immediate command */
     70 #define	SR_SENSE			2	/* We are getting sense */
     71 #define	SR_OVERDUE			4	/* Timeout while not current */
     72 #define	SR_ERROR			8	/* Error occurred */
     73 	int		sr_status;		/* Status code from last cmd */
     74 };
     75 #define	SCI_OPENINGS	16		/* How many commands we can enqueue. */
     76 
     77 
     78 struct ncr5380_softc {
     79 	struct device	sc_dev;
     80 	struct		scsi_link sc_link;
     81 
     82 	/* Pointers to 5380 registers.  See ncr5380reg.h */
     83 	volatile u_char *sci_r0;
     84 	volatile u_char *sci_r1;
     85 	volatile u_char *sci_r2;
     86 	volatile u_char *sci_r3;
     87 	volatile u_char *sci_r4;
     88 	volatile u_char *sci_r5;
     89 	volatile u_char *sci_r6;
     90 	volatile u_char *sci_r7;
     91 
     92 	/* Functions set from MD code */
     93 	int		(*sc_pio_out) __P((struct ncr5380_softc *,
     94 					   int, int, u_char *));
     95 	int		(*sc_pio_in) __P((struct ncr5380_softc *,
     96 					  int, int, u_char *));
     97 	void		(*sc_dma_alloc) __P((struct ncr5380_softc *));
     98 	void		(*sc_dma_free) __P((struct ncr5380_softc *));
     99 
    100 	void		(*sc_dma_setup) __P((struct ncr5380_softc *));
    101 	void		(*sc_dma_start) __P((struct ncr5380_softc *));
    102 	void		(*sc_dma_poll) __P((struct ncr5380_softc *));
    103 	void		(*sc_dma_eop) __P((struct ncr5380_softc *));
    104 	void		(*sc_dma_stop) __P((struct ncr5380_softc *));
    105 
    106 	void		(*sc_intr_on) __P((struct ncr5380_softc *));
    107 	void		(*sc_intr_off) __P((struct ncr5380_softc *));
    108 
    109 	int		sc_flags;	/* Misc. flags and capabilities */
    110 #define	NCR5380_PERMIT_RESELECT		1  /* Allow disconnect/reselect */
    111 #define	NCR5380_FORCE_POLLING		2  /* Do not use interrupts. */
    112 
    113 	/* Set bits in this to disable parity for some target. */
    114 	int		sc_parity_disable;
    115 
    116 	int 	sc_min_dma_len;	/* Smaller than this is done with PIO */
    117 
    118 	/* Begin MI shared data */
    119 
    120 	int		sc_state;
    121 #define	NCR_IDLE		   0	/* Ready for new work. */
    122 #define NCR_WORKING 	0x01	/* Some command is in progress. */
    123 #define	NCR_ABORTING	0x02	/* Bailing out */
    124 #define NCR_DOINGDMA	0x04	/* The FIFO data path is active! */
    125 #define NCR_DROP_MSGIN	0x10	/* Discard all msgs (parity err detected) */
    126 
    127 	/* The request that has the bus now. */
    128 	struct		sci_req *sc_current;
    129 
    130 	/* Active data pointer for current SCSI command. */
    131 	u_char		*sc_dataptr;
    132 	int		sc_datalen;
    133 
    134 	/* Begin MI private data */
    135 
    136 	/* The number of operations in progress on the bus */
    137 	volatile int	sc_ncmds;
    138 
    139 	/* Ring buffer of pending/active requests */
    140 	struct		sci_req sc_ring[SCI_OPENINGS];
    141 	int		sc_rr;		/* Round-robin scan pointer */
    142 
    143 	/* Active requests, by target/LUN */
    144 	struct		sci_req *sc_matrix[8][8];
    145 
    146 	/* Message stuff */
    147 	int	sc_prevphase;
    148 
    149 	u_int	sc_msgpriq;	/* Messages we want to send */
    150 	u_int	sc_msgoutq;	/* Messages sent during last MESSAGE OUT */
    151 	u_int	sc_msgout;	/* Message last transmitted */
    152 #define SEND_DEV_RESET		0x01
    153 #define SEND_PARITY_ERROR	0x02
    154 #define SEND_ABORT		0x04
    155 #define SEND_REJECT		0x08
    156 #define SEND_INIT_DET_ERR	0x10
    157 #define SEND_IDENTIFY  		0x20
    158 #define SEND_SDTR		0x40
    159 #define	SEND_WDTR		0x80
    160 #define NCR_MAX_MSG_LEN 8
    161 	u_char  sc_omess[NCR_MAX_MSG_LEN];
    162 	u_char	*sc_omp;		/* Outgoing message pointer */
    163 	u_char	sc_imess[NCR_MAX_MSG_LEN];
    164 	u_char	*sc_imp;		/* Incoming message pointer */
    165 
    166 };
    167 
    168 void	ncr5380_init __P((struct ncr5380_softc *));
    169 void	ncr5380_reset_scsibus __P((struct ncr5380_softc *));
    170 int 	ncr5380_intr __P((struct ncr5380_softc *));
    171 int 	ncr5380_scsi_cmd __P((struct scsi_xfer *));
    172 int 	ncr5380_pio_in __P((struct ncr5380_softc *, int, int, u_char *));
    173 int 	ncr5380_pio_out __P((struct ncr5380_softc *, int, int, u_char *));
    174 
    175 #ifdef	NCR5380_DEBUG
    176 struct ncr5380_softc *ncr5380_debug_sc;
    177 void ncr5380_trace __P((char *msg, long val));
    178 #define	NCR_TRACE(msg, val) ncr5380_trace(msg, val)
    179 #else	/* NCR5380_DEBUG */
    180 #define	NCR_TRACE(msg, val)	/* nada */
    181 #endif	/* NCR5380_DEBUG */
    182