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