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