1 /*	$MirOS: src/sys/dev/i2o/iopvar.h,v 1.2 2013/10/31 20:06:51 tg Exp $ */
2 /*	$OpenBSD: iopvar.h,v 1.7 2002/03/14 01:26:53 millert Exp $	*/
3 /*	$NetBSD: iopvar.h,v 1.5 2001/03/20 13:01:49 ad Exp $	*/
4 
5 /*-
6  * Copyright © 2013
7  *	Thorsten “mirabilos” Glaser <tg@mirbsd.org>
8  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
9  * All rights reserved.
10  *
11  * This code is derived from software contributed to The NetBSD Foundation
12  * by Andrew Doran.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. All advertising materials mentioning features or use of this software
23  *    must display the following acknowledgement:
24  *        This product includes software developed by the NetBSD
25  *        Foundation, Inc. and its contributors.
26  * 4. Neither the name of The NetBSD Foundation nor the names of its
27  *    contributors may be used to endorse or promote products derived
28  *    from this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  * POSSIBILITY OF SUCH DAMAGE.
41  */
42 
43 #ifndef _I2O_IOPVAR_H_
44 #define	_I2O_IOPVAR_H_
45 
46 /*
47  * Transfer descriptor.
48  */
49 struct iop_xfer {
50 	bus_dmamap_t	ix_map;
51 	u_int		ix_size;
52 	u_int		ix_flags;
53 };
54 #define	IX_IN			0x0001	/* Data transfer from IOP */
55 #define	IX_OUT			0x0002	/* Data transfer to IOP */
56 
57 /*
58  * Message wrapper.
59  */
60 struct iop_msg {
61 	SLIST_ENTRY(iop_msg)	im_chain;	/* Next free message */
62 	u_int			im_flags;	/* Control flags */
63 	u_int			im_tctx;	/* Transaction context */
64 	void			*im_dvcontext;	/* Un*x device context */
65 	struct i2o_reply	*im_rb;		/* Reply buffer */
66 	u_int			im_reqstatus;	/* Status from reply */
67 	struct iop_xfer		im_xfer[IOP_MAX_MSG_XFERS];
68 };
69 #define	IM_SYSMASK		0x00ff
70 #define	IM_REPLIED		0x0001	/* Message has been replied to */
71 #define	IM_ALLOCED		0x0002	/* This message wrapper is allocated */
72 #define	IM_SGLOFFADJ		0x0004	/* S/G list offset adjusted */
73 #define	IM_DISCARD		0x0008	/* Discard message wrapper once sent */
74 #define	IM_FAIL			0x0010	/* Transaction error returned */
75 
76 #define	IM_USERMASK		0xff00
77 #define	IM_WAIT			0x0100	/* Wait (sleep) for completion */
78 #define	IM_POLL			0x0200	/* Wait (poll) for completion */
79 #define	IM_NOSTATUS		0x0400	/* Don't check status if waiting */
80 #define	IM_POLL_INTR		0x0800	/* Do send interrupt when polling */
81 
82 struct iop_initiator {
83 	LIST_ENTRY(iop_initiator) ii_list;
84 	LIST_ENTRY(iop_initiator) ii_hash;
85 
86 	void	(*ii_intr)(struct device *, struct iop_msg *, void *);
87 	int	(*ii_reconfig)(struct device *);
88 	void	(*ii_adjqparam)(struct device *, int);
89 
90 	struct	device *ii_dv;
91 	int	ii_flags;
92 	int	ii_ictx;		/* Initiator context */
93 	int	ii_tid;
94 };
95 #define	II_DISCARD	0x0001	/* Don't track state; discard msg wrappers */
96 #define	II_CONFIGURED	0x0002	/* Already configured */
97 #define	II_UTILITY	0x0004	/* Utility initiator (not a real device) */
98 
99 #define	IOP_ICTX	0
100 #define	IOP_INIT_CODE	0x80
101 
102 /*
103  * Parameter group op (for async parameter retrievals).
104  */
105 struct iop_pgop {
106 	struct	i2o_param_op_list_header olh;
107 	struct	i2o_param_op_all_template oat;
108 } __attribute__((__packed__));
109 
110 /*
111  * Per-IOP context.
112  */
113 struct iop_softc {
114 	struct device	sc_dv;		/* generic device data */
115 	bus_space_handle_t sc_ioh;	/* bus space handle */
116 	bus_space_tag_t	sc_iot;		/* bus space tag */
117 	bus_dma_tag_t	sc_dmat;	/* bus DMA tag */
118 	void	 	*sc_ih;		/* interrupt handler cookie */
119 	struct lock	sc_conflock;	/* autoconfiguration lock */
120 	bus_addr_t	sc_memaddr;	/* register window address */
121 	bus_size_t	sc_memsize;	/* register window size */
122 
123 	struct i2o_hrt	*sc_hrt;	/* hardware resource table */
124 	struct iop_tidmap *sc_tidmap;	/* tid map (per-lct-entry flags) */
125 	struct i2o_lct	*sc_lct;	/* logical configuration table */
126 	int		sc_nlctent;	/* number of LCT entries */
127 	int		sc_flags;	/* IOP-wide flags */
128 	int		sc_maxib;
129 	int		sc_maxob;
130 	int		sc_curib;
131 	u_int32_t	sc_chgind;	/* autoconfig vs. LCT change ind. */
132 	LIST_HEAD(, iop_initiator) sc_iilist;/* initiator list */
133 	int		sc_nii;
134 	int		sc_nuii;
135 	struct iop_initiator sc_eventii;/* IOP event handler */
136 	struct proc	*sc_reconf_proc;/* reconfiguration process */
137 	struct iop_msg	*sc_ims;
138 	SLIST_HEAD(, iop_msg) sc_im_freelist;
139 	caddr_t		sc_ptb;
140 	bus_dmamap_t	sc_scr_dmamap;	/* Scratch DMA map */
141 	bus_dma_segment_t sc_scr_seg[1];/* Scratch DMA segment */
142 	caddr_t		sc_scr;		/* Scratch memory va */
143 
144 	/*
145 	 * Reply queue.
146 	 */
147 	bus_dmamap_t	sc_rep_dmamap;
148 	int		sc_rep_size;
149 	bus_addr_t	sc_rep_phys;
150 	caddr_t		sc_rep;
151 
152 	bus_space_tag_t	sc_bus_memt;
153 	bus_space_tag_t	sc_bus_iot;
154 
155 	struct i2o_status sc_status;	/* status */
156 };
157 #define	IOP_OPEN		0x01	/* Device interface open */
158 #define	IOP_HAVESTATUS		0x02	/* Successfully retrieved status */
159 #define	IOP_ONLINE		0x04	/* Can use ioctl interface */
160 
161 #define	IOPCF_TID		0
162 #define	IOPCF_TID_DEFAULT	-1
163 
164 struct iop_attach_args {
165 	int	ia_class;		/* device class */
166 	int	ia_tid;			/* target ID */
167 };
168 #define	iopcf_tid	cf_loc[IOPCF_TID]		/* TID */
169 
170 void	iop_init(struct iop_softc *, const char *);
171 int	iop_intr(void *);
172 int	iop_lct_get(struct iop_softc *);
173 int	iop_param_op(struct iop_softc *, int, struct iop_initiator *, int,
174 	    int, void *, size_t);
175 int	iop_print_ident(struct iop_softc *, int);
176 int	iop_simple_cmd(struct iop_softc *, int, int, int, int, int);
177 void	iop_strvis(struct iop_softc *, const char *, int, char *, int);
178 
179 void	iop_initiator_register(struct iop_softc *, struct iop_initiator *);
180 void	iop_initiator_unregister(struct iop_softc *, struct iop_initiator *);
181 
182 struct	iop_msg *iop_msg_alloc(struct iop_softc *, struct iop_initiator *,
183 	    int);
184 void	iop_msg_free(struct iop_softc *, struct iop_msg *);
185 int	iop_msg_map(struct iop_softc *, struct iop_msg *, u_int32_t *, void *,
186 	    size_t, int);
187 int	iop_msg_map_bio(struct iop_softc *, struct iop_msg *, u_int32_t *,
188 	    void *, int, int);
189 int	iop_msg_post(struct iop_softc *, struct iop_msg *, void *, int);
190 void	iop_msg_unmap(struct iop_softc *, struct iop_msg *);
191 
192 int	iop_util_abort(struct iop_softc *, struct iop_initiator *, int, int,
193 	    int);
194 int	iop_util_claim(struct iop_softc *, struct iop_initiator *, int, int);
195 int	iop_util_eventreg(struct iop_softc *, struct iop_initiator *, int);
196 
197 #endif	/* !_I2O_IOPVAR_H_ */
198