Home | History | Annotate | Line # | Download | only in i2o
iopvar.h revision 1.4
      1 /*	$NetBSD: iopvar.h,v 1.4 2001/01/03 21:04:01 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      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 NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _I2O_IOPVAR_H_
     40 #define	_I2O_IOPVAR_H_
     41 
     42 /* Per-IOP statistics; not particularly useful at the moment. */
     43 struct iop_stat {
     44 	int	is_cur_swqueue;
     45 	int	is_peak_swqueue;
     46 	int	is_cur_hwqueue;
     47 	int	is_peak_hwqueue;
     48 	int64_t	is_requests;
     49 	int64_t	is_bytes;
     50 };
     51 
     52 /*
     53  * XXX The following should be adjusted if and when:
     54  *
     55  * o MAXPHYS exceeds 64kB.
     56  * o A new message or reply is defined in i2o.h.
     57  *
     58  * As it stands, these make for a message frame of 200 bytes.
     59  */
     60 #define	IOP_MAX_SGL_SIZE	132	/* Maximum S/G list size */
     61 #define	IOP_MAX_BASE_MSG_SIZE	68	/* Maximum base message size */
     62 #define	IOP_MAX_XFER		65536	/* Maximum transfer size */
     63 #define	IOP_MAX_MSG_XFERS	3	/* Maximum transfer count per msg */
     64 
     65 #define	IOP_MAX_SGL_ENTRIES	(IOP_MAX_SGL_SIZE / 8)
     66 #define	IOP_MAX_MSG_SIZE	(IOP_MAX_BASE_MSG_SIZE + IOP_MAX_SGL_SIZE)
     67 
     68 /* Linux sez that some IOPs don't like reply frame sizes other than 128. */
     69 #define	IOP_MAX_REPLY_SIZE	128
     70 
     71 #define	IOP_MAX_HW_QUEUECNT	256
     72 #define	IOP_MAX_HW_REPLYCNT	256
     73 
     74 struct iop_tidmap {
     75 	u_short	it_tid;
     76 	u_short	it_flags;
     77 	char	it_dvname[sizeof(((struct device *)NULL)->dv_xname)];
     78 };
     79 #define	IT_CONFIGURED	0x02	/* target configured */
     80 
     81 #ifdef _KERNEL
     82 
     83 #include "locators.h"
     84 
     85 /*
     86  * Transfer descriptor.
     87  */
     88 struct iop_xfer {
     89 	bus_dmamap_t	ix_map;
     90 	u_int		ix_size;
     91 	u_int		ix_flags;
     92 };
     93 #define	IX_IN			0x0001	/* Data transfer from IOP */
     94 #define	IX_OUT			0x0002	/* Data transfer to IOP */
     95 
     96 /*
     97  * Message wrapper.
     98  */
     99 struct iop_msg {
    100 	SIMPLEQ_ENTRY(iop_msg)	im_queue;	/* Next queued message */
    101 	TAILQ_ENTRY(iop_msg)	im_hash;	/* Hash chain */
    102 	u_int			im_flags;	/* Control flags */
    103 	u_int			im_tctx;	/* Transaction context */
    104 	void			*im_dvcontext;	/* Un*x device context */
    105 	u_int32_t		im_msg[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    106 	struct iop_xfer		im_xfer[IOP_MAX_MSG_XFERS];
    107 };
    108 #define	IM_SYSMASK		0x00ff
    109 #define	IM_REPLIED		0x0001	/* Message has been replied to */
    110 #define	IM_ALLOCED		0x0002	/* This message wrapper is allocated */
    111 #define	IM_SGLOFFADJ		0x0008	/* S/G list offset adjusted */
    112 #define	IM_DISCARD		0x0010	/* Discard message wrapper once sent */
    113 #define	IM_WAITING		0x0020	/* Waiting for completion */
    114 
    115 #define	IM_USERMASK		0xff00
    116 #define	IM_NOWAIT		0x0100	/* Don't sleep when processing */
    117 #define	IM_NOICTX		0x0200	/* No initiator context field */
    118 #define	IM_NOINTR		0x0400	/* Don't interrupt when complete */
    119 #define	IM_NOSTATUS		0x0800	/* Don't check status if waiting */
    120 
    121 struct iop_initiator {
    122 	LIST_ENTRY(iop_initiator) ii_list;
    123 	LIST_ENTRY(iop_initiator) ii_hash;
    124 
    125 	void	(*ii_intr)(struct device *, struct iop_msg *, void *);
    126 	int	(*ii_reconfig)(struct device *);
    127 	struct	device *ii_dv;
    128 	int	ii_flags;
    129 	int	ii_ictx;		/* Initiator context */
    130 	int	ii_stctx;		/* Static transaction context */
    131 	int	ii_tid;
    132 };
    133 #define	II_DISCARD	0x0001	/* Don't track state; discard msg wrappers */
    134 #define	II_CONFIGURED	0x0002	/* Already configured */
    135 #define	II_UTILITY	0x0004	/* Utility initiator (not a `real device') */
    136 
    137 #define	IOP_ICTX	0
    138 
    139 /*
    140  * Per-IOP context.
    141  */
    142 struct iop_softc {
    143 	struct device	sc_dv;		/* generic device data */
    144 	bus_space_handle_t sc_ioh;	/* bus space handle */
    145 	bus_space_tag_t	sc_iot;		/* bus space tag */
    146 	bus_dma_tag_t	sc_dmat;	/* bus DMA tag */
    147 	void	 	*sc_ih;		/* interrupt handler cookie */
    148 	struct lock	sc_conflock;	/* autoconfiguration lock */
    149 	bus_addr_t	sc_memaddr;	/* register window address */
    150 	bus_size_t	sc_memsize;	/* register window size */
    151 
    152 	struct i2o_hrt	*sc_hrt;	/* hardware resource table */
    153 	struct i2o_lct	*sc_lct;	/* logical configuration table */
    154 	int		sc_nlctent;	/* number of LCT entries */
    155 	struct iop_tidmap *sc_tidmap;	/* tid map (per-lct-entry flags) */
    156 	struct i2o_status sc_status;	/* status */
    157 	struct iop_stat	sc_stat;	/* counters */
    158 	int		sc_flags;	/* IOP-wide flags */
    159 	int		sc_maxreplycnt;	/* reply queue size */
    160 	u_int32_t	sc_chgindicator;/* autoconfig vs. LCT change ind. */
    161 	LIST_HEAD(, iop_initiator) sc_iilist;/* initiator list */
    162 	SIMPLEQ_HEAD(,iop_msg) sc_queue;/* software queue */
    163 	int		sc_maxqueuecnt;	/* maximum # of msgs on h/w queue */
    164 	struct iop_initiator sc_eventii;/* IOP event handler */
    165 	struct proc	*sc_reconf_proc;/* reconfiguration process */
    166 	caddr_t		sc_ptb;
    167 
    168 	/*
    169 	 * Reply queue.
    170 	 */
    171 	bus_dmamap_t	sc_rep_dmamap;
    172 	int		sc_rep_size;
    173 	bus_addr_t	sc_rep_phys;
    174 	caddr_t		sc_rep;
    175 };
    176 #define	IOP_OPEN		0x01	/* Device interface open */
    177 #define	IOP_HAVESTATUS		0x02	/* Successfully retrieved status */
    178 #define	IOP_ONLINE		0x04	/* Can use ioctl interface */
    179 
    180 struct iop_attach_args {
    181 	int	ia_class;		/* device class */
    182 	int	ia_tid;			/* target ID */
    183 };
    184 #define	iopcf_tid	cf_loc[IOPCF_TID]		/* TID */
    185 
    186 void	iop_init(struct iop_softc *, const char *);
    187 int	iop_intr(void *);
    188 int	iop_lct_get(struct iop_softc *);
    189 int	iop_param_op(struct iop_softc *, int, int, int, void *, int);
    190 int	iop_simple_cmd(struct iop_softc *, int, int, int, int, int);
    191 void	iop_strvis(struct iop_softc *, const char *, int, char *, int);
    192 
    193 int	iop_initiator_register(struct iop_softc *, struct iop_initiator *);
    194 void	iop_initiator_unregister(struct iop_softc *, struct iop_initiator *);
    195 
    196 int	iop_msg_alloc(struct iop_softc *, struct iop_initiator *,
    197 		      struct iop_msg **, int);
    198 int	iop_msg_enqueue(struct iop_softc *, struct iop_msg *, int);
    199 void	iop_msg_free(struct iop_softc *, struct iop_initiator *,
    200 		     struct iop_msg *);
    201 int	iop_msg_map(struct iop_softc *, struct iop_msg *, void *, int, int);
    202 int	iop_msg_send(struct iop_softc *, struct iop_msg *, int);
    203 void	iop_msg_unmap(struct iop_softc *, struct iop_msg *);
    204 
    205 int	iop_util_abort(struct iop_softc *, struct iop_initiator *, int, int,
    206 		      int);
    207 int	iop_util_claim(struct iop_softc *, struct iop_initiator *, int, int);
    208 int	iop_util_eventreg(struct iop_softc *, struct iop_initiator *, int);
    209 
    210 #endif	/* _KERNEL */
    211 
    212 /*
    213  * ioctl() interface.
    214  */
    215 
    216 struct ioppt_buf {
    217 	void	*ptb_data;
    218 	size_t	ptb_datalen;
    219 	int	ptb_out;
    220 };
    221 
    222 struct ioppt {
    223 	void	*pt_msg;
    224 	size_t	pt_msglen;
    225 	void	*pt_reply;
    226 	size_t	pt_replylen;
    227 	int	pt_timo;
    228 	int	pt_nbufs;
    229 	struct	ioppt_buf pt_bufs[IOP_MAX_MSG_XFERS];
    230 };
    231 
    232 #define	IOPIOCPT	_IOWR('u', 0, struct ioppt)
    233 #define	IOPIOCGLCT	_IOWR('u', 1, struct iovec)
    234 #define	IOPIOCGSTATUS	_IOWR('u', 2, struct iovec)
    235 #define	IOPIOCRECONFIG	_IO('u', 3)
    236 #define	IOPIOCGTIDMAP	_IOWR('u', 4, struct iovec)
    237 
    238 #endif	/* !_I2O_IOPVAR_H_ */
    239