Home | History | Annotate | Line # | Download | only in mscp
mscpvar.h revision 1.7
      1 /*	$NetBSD: mscpvar.h,v 1.7 1999/06/06 19:16:18 ragge Exp $	*/
      2 /*
      3  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
      4  * Copyright (c) 1988 Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Chris Torek.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the University of
     21  *	California, Berkeley and its contributors.
     22  * 4. Neither the name of the University nor the names of its contributors
     23  *    may be used to endorse or promote products derived from this software
     24  *    without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  *
     38  *	@(#)mscpvar.h	7.3 (Berkeley) 6/28/90
     39  */
     40 
     41 /*
     42  * MSCP generic driver configuration
     43  */
     44 
     45 /*
     46  * Enabling MSCP_PARANOIA makes the response code perform various checks
     47  * on the hardware.  (Right now it verifies only the buffer pointer in
     48  * mscp_cmdref.)
     49  *
     50  * Enabling AVOID_EMULEX_BUG selects an alternative method of identifying
     51  * transfers in progress, which gets around a rather peculiar bug in the
     52  * SC41/MS.  Enabling MSCP_PARANOIA instead should work, but will cause
     53  * `extra' Unibus resets.
     54  *
     55  * Either of these flags can simply be included as an `options' line in
     56  * your configuration file.
     57  */
     58 
     59 /* #define MSCP_PARANOIA */
     60 /* #define AVOID_EMULEX_BUG */
     61 
     62 /*
     63  * Ring information, per ring (one each for commands and responses).
     64  */
     65 struct mscp_ri {
     66 	int	mri_size;		/* ring size */
     67 	int	mri_next;		/* next (expected|free) */
     68 	long	*mri_desc;		/* base address of descriptors */
     69 	struct	mscp *mri_ring;		/* base address of packets */
     70 };
     71 
     72 /*
     73  * Transfer info, one per command packet.
     74  */
     75 struct mscp_xi {
     76 	bus_dmamap_t	mxi_dmam;	/* Allocated DMA map for this entry */
     77 	struct buf *	mxi_bp;		/* Buffer used in this command */
     78 	struct mscp *	mxi_mp;		/* Packet used in this command */
     79 	int		mxi_inuse;
     80 };
     81 
     82 struct	mscp_ctlr {
     83 	void	(*mc_ctlrdone)		/* controller operation complete */
     84 	    __P((struct device *));
     85 	void	(*mc_go)		/* device-specific start routine */
     86 	    __P((struct device *, struct mscp_xi *));
     87 	void	(*mc_saerror)		/* ctlr error handling */
     88 	    __P((struct device *, int));
     89 };
     90 
     91 struct mscp_softc;
     92 
     93 struct	mscp_device {
     94 	void	(*me_dgram)	/* error datagram */
     95 	    __P((struct device *, struct mscp *, struct mscp_softc *));
     96 	void	(*me_iodone)	/* normal I/O is done */
     97 	    __P((struct device *, struct buf *));
     98 	int	(*me_online)	/* drive on line */
     99 	    __P((struct device *, struct mscp *));
    100 	int	(*me_gotstatus) /* got unit status */
    101 	    __P((struct device *, struct mscp *));
    102 	void	(*me_replace)	/* replace done */
    103 	    __P((struct device *, struct mscp *));
    104 	int	(*me_ioerr)	/* read or write failed */
    105 	    __P((struct device *, struct mscp *, struct buf *));
    106 	void	(*me_bb)	/* B_BAD io done */
    107 	    __P((struct device *, struct mscp *, struct buf *));
    108 	void	(*me_fillin)	/* Fill in mscp info for this drive */
    109 	    __P((struct buf *,struct mscp *));
    110 	void	(*me_cmddone)	/* Non-data transfer operation is done */
    111 	    __P((struct device *, struct mscp *));
    112 };
    113 
    114 /*
    115  * This struct is used when attaching a mscpbus.
    116  */
    117 struct	mscp_attach_args {
    118 	struct	mscp_ctlr *ma_mc;	/* Pointer to ctlr's mscp_ctlr */
    119 	int	ma_type;		/* disk/tape bus type */
    120 	struct	mscp_pack *ma_uda;	/* comm area virtual */
    121 	struct	mscp_softc **ma_softc;	/* backpointer to bus softc */
    122 	bus_dmamap_t	   ma_dmam;	/* This comm area dma info */
    123 	bus_dma_tag_t	   ma_dmat;
    124 	bus_space_tag_t	   ma_iot;
    125 	bus_space_handle_t ma_iph;	/* initialisation and polling */
    126 	bus_space_handle_t ma_sah;	/* status & address (read part) */
    127 	bus_space_handle_t ma_swh;	/* status & address (write part) */
    128 	short	ma_ivec;		/* Interrupt vector to use */
    129 	char	ma_ctlrnr;		/* Phys ctlr nr */
    130 	char	ma_adapnr;		/* Phys adapter nr */
    131 };
    132 #define MSCPBUS_DISK	001	/* Bus is used for disk mounts */
    133 #define MSCPBUS_TAPE	002	/* Bus is used for tape mounts */
    134 #define MSCPBUS_UDA	004	/* ctlr is disk on unibus/qbus */
    135 #define MSCPBUS_KDB	010	/* ctlr is disk on BI */
    136 #define MSCPBUS_KLE	020	/* ctlr is tape on unibus/qbus */
    137 
    138 /*
    139  * Used when going for child devices.
    140  */
    141 struct	drive_attach_args {
    142 	struct	mscp *da_mp;	/* this devices response struct */
    143 	int	da_typ;		/* Parent of type */
    144 };
    145 
    146 /*
    147  * Return values from functions.
    148  * MSCP_RESTARTED is peculiar to I/O errors.
    149  */
    150 #define MSCP_DONE	0		/* all ok */
    151 #define MSCP_FAILED	1		/* no go */
    152 #define MSCP_RESTARTED	2		/* transfer restarted */
    153 
    154 /*
    155  * Per device information.
    156  *
    157  * mi_ip is a pointer to the inverting pointers (things that get `ui's
    158  * given unit numbers) FOR THIS CONTROLLER (NOT the whole set!).
    159  *
    160  * b_actf holds a queue of those transfers that were started but have
    161  * not yet finished.  Other Unibus drivers do not need this as they hand
    162  * out requests one at a time.	MSCP devices, however, take a slew of
    163  * requests and pick their own order to execute them.  This means that
    164  * we have to have a place to move transfers that were given to the
    165  * controller, so we can tell those apart from those that have not yet
    166  * been handed out; b_actf is that place.
    167  */
    168 struct mscp_softc {
    169 	struct	device mi_dev;		/* Autoconf stuff */
    170 	struct	mscp_ri mi_cmd;		/* MSCP command ring info */
    171 	struct	mscp_ri mi_rsp;		/* MSCP response ring info */
    172 	bus_dma_tag_t	mi_dmat;
    173 	bus_dmamap_t	mi_dmam;
    174 	struct	mscp_xi mi_xi[NCMD];
    175 	int	mi_mxiuse;		/* Bitfield of inuse mxi packets */
    176 	short	mi_credits;		/* transfer credits */
    177 	char	mi_wantcmd;		/* waiting for command packet */
    178 	char	mi_wantcredits;		/* waiting for transfer credits */
    179 	struct	mscp_ctlr *mi_mc;	/* Pointer to parent's mscp_ctlr */
    180 	struct	mscp_device *mi_me;	/* Pointer to child's mscp_device */
    181 	struct	device **mi_dp;		/* array of backpointers */
    182 	int	mi_driveno;		/* Max physical drive number found */
    183 	char	mi_ctlrnr;		/* Phys ctlr nr */
    184 	char	mi_adapnr;		/* Phys adapter nr */
    185 	int	mi_flags;
    186 	struct	mscp_pack *mi_uda;	/* virtual address */
    187 	int	mi_type;
    188 	short	mi_ivec;		/* Interrupt vector to use */
    189 	short	mi_ierr;		/* Init err counter */
    190 	bus_space_tag_t	   mi_iot;
    191 	bus_space_handle_t mi_iph;	/* initialisation and polling */
    192 	bus_space_handle_t mi_sah;	/* status & address (read part) */
    193 	bus_space_handle_t mi_swh;	/* status & address (write part) */
    194 	SIMPLEQ_HEAD(, buf) mi_resq;	/* While waiting for packets */
    195 };
    196 
    197 /* mi_flags */
    198 #define MSC_STARTPOLL	1
    199 #define MSC_INSTART	2
    200 #define MSC_IGNOREINTR	4
    201 #define MSC_READY	8
    202 
    203 /*
    204  * We have run out of credits when mi_credits is <= MSCP_MINCREDITS.
    205  * It is still possible to issue one command in this case, but it must
    206  * not be a data transfer.  E.g., `get command status' or `abort command'
    207  * is legal, while `read' is not.
    208  */
    209 #define MSCP_MINCREDITS 1
    210 
    211 /*
    212  * Flags for mscp_getcp().
    213  */
    214 #define MSCP_WAIT	1
    215 #define MSCP_DONTWAIT	0
    216 
    217 	/* get a command packet */
    218 
    219 /*
    220  * Unit flags
    221  */
    222 #define UNIT_ONLINE	0x01	/* drive is on line */
    223 #define UNIT_HAVESTATUS 0x02	/* got unit status */
    224 #define UNIT_REQUEUE	0x04	/* requeue after response */
    225 
    226 /*
    227  * Handle a command ring transition: wake up sleepers for command packets.
    228  * This is too simple to bother with a function call.
    229  */
    230 #define MSCP_DOCMD(mi) { \
    231 	if ((mi)->mi_wantcmd) { \
    232 		(mi)->mi_wantcmd = 0; \
    233 		wakeup((caddr_t) &(mi)->mi_wantcmd); \
    234 	} \
    235 }
    236 
    237 /* Prototypes */
    238 struct	mscp *mscp_getcp __P((struct mscp_softc *, int));
    239 void	mscp_printevent __P((struct mscp *));
    240 void	mscp_go __P((struct mscp_softc *, struct mscp *, int));
    241 void	mscp_requeue __P((struct mscp_softc *));
    242 void	mscp_dorsp __P((struct mscp_softc *));
    243 int	mscp_decodeerror __P((char *, struct mscp *, struct mscp_softc *));
    244 int	mscp_print __P((void *, const char *));
    245 void	mscp_hexdump __P((struct mscp *));
    246 void	mscp_strategy __P((struct buf *, struct device *));
    247 void	mscp_printtype __P((int, int));
    248 int	mscp_waitstep __P((struct mscp_softc *, int, int));
    249 void	mscp_dgo __P((struct mscp_softc *, struct mscp_xi *));
    250 void	mscp_intr __P((struct mscp_softc *));
    251