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