xref: /netbsd-src/sys/dev/i2o/iopvar.h (revision cbab9cadce21ae72fac13910001079fff214cc29)
1*cbab9cadSchs /*	$NetBSD: iopvar.h,v 1.24 2012/10/27 17:18:17 chs Exp $	*/
2d49fd135Sad 
3d49fd135Sad /*-
49abeea58Sad  * Copyright (c) 2000, 2001, 2002, 2007 The NetBSD Foundation, Inc.
5d49fd135Sad  * All rights reserved.
6d49fd135Sad  *
7d49fd135Sad  * This code is derived from software contributed to The NetBSD Foundation
8d49fd135Sad  * by Andrew Doran.
9d49fd135Sad  *
10d49fd135Sad  * Redistribution and use in source and binary forms, with or without
11d49fd135Sad  * modification, are permitted provided that the following conditions
12d49fd135Sad  * are met:
13d49fd135Sad  * 1. Redistributions of source code must retain the above copyright
14d49fd135Sad  *    notice, this list of conditions and the following disclaimer.
15d49fd135Sad  * 2. Redistributions in binary form must reproduce the above copyright
16d49fd135Sad  *    notice, this list of conditions and the following disclaimer in the
17d49fd135Sad  *    documentation and/or other materials provided with the distribution.
18d49fd135Sad  *
19d49fd135Sad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d49fd135Sad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d49fd135Sad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d49fd135Sad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d49fd135Sad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d49fd135Sad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d49fd135Sad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d49fd135Sad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d49fd135Sad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d49fd135Sad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d49fd135Sad  * POSSIBILITY OF SUCH DAMAGE.
30d49fd135Sad  */
31d49fd135Sad 
32d49fd135Sad #ifndef _I2O_IOPVAR_H_
33d49fd135Sad #define	_I2O_IOPVAR_H_
34d49fd135Sad 
359abeea58Sad #include <sys/mutex.h>
369abeea58Sad #include <sys/condvar.h>
379abeea58Sad 
38d49fd135Sad /*
39d49fd135Sad  * Transfer descriptor.
40d49fd135Sad  */
41d49fd135Sad struct iop_xfer {
42d49fd135Sad 	bus_dmamap_t	ix_map;
43d49fd135Sad 	u_int		ix_size;
44d49fd135Sad 	u_int		ix_flags;
45d49fd135Sad };
46d49fd135Sad #define	IX_IN			0x0001	/* Data transfer from IOP */
47d49fd135Sad #define	IX_OUT			0x0002	/* Data transfer to IOP */
48d49fd135Sad 
49d49fd135Sad /*
50d49fd135Sad  * Message wrapper.
51d49fd135Sad  */
52d49fd135Sad struct iop_msg {
53ebf51109Sad 	SLIST_ENTRY(iop_msg)	im_chain;	/* Next free message */
54d49fd135Sad 	u_int			im_flags;	/* Control flags */
55d49fd135Sad 	u_int			im_tctx;	/* Transaction context */
56d49fd135Sad 	void			*im_dvcontext;	/* Un*x device context */
57ebf51109Sad 	struct i2o_reply	*im_rb;		/* Reply buffer */
58e5bca80aSad 	kcondvar_t		im_cv;		/* Notifier */
59ebf51109Sad 	u_int			im_reqstatus;	/* Status from reply */
60ee5a33f5Sad 	u_int			im_detstatus;	/* Detailed status code */
61d49fd135Sad 	struct iop_xfer		im_xfer[IOP_MAX_MSG_XFERS];
62d49fd135Sad };
63d49fd135Sad #define	IM_SYSMASK		0x00ff
64d49fd135Sad #define	IM_REPLIED		0x0001	/* Message has been replied to */
65d49fd135Sad #define	IM_ALLOCED		0x0002	/* This message wrapper is allocated */
66ebf51109Sad #define	IM_SGLOFFADJ		0x0004	/* S/G list offset adjusted */
6703e46dc8Sad #define	IM_FAIL			0x0008	/* Transaction error returned */
68d49fd135Sad 
69d49fd135Sad #define	IM_USERMASK		0xff00
70ebf51109Sad #define	IM_WAIT			0x0100	/* Wait (sleep) for completion */
71ebf51109Sad #define	IM_POLL			0x0200	/* Wait (poll) for completion */
72ebf51109Sad #define	IM_NOSTATUS		0x0400	/* Don't check status if waiting */
7399187cddSad #define	IM_POLL_INTR		0x0800	/* Do send interrupt when polling */
74d49fd135Sad 
75d49fd135Sad struct iop_initiator {
76af9d4c4fSad 	LIST_ENTRY(iop_initiator) ii_list;
77af9d4c4fSad 	LIST_ENTRY(iop_initiator) ii_hash;
78af9d4c4fSad 
79529e91fcScegger 	void	(*ii_intr)(device_t, struct iop_msg *, void *);
80529e91fcScegger 	int	(*ii_reconfig)(device_t);
81529e91fcScegger 	void	(*ii_adjqparam)(device_t, int);
82ebf51109Sad 
83*cbab9cadSchs 	device_t ii_dv;
84e5bca80aSad 	kcondvar_t ii_cv;
85d49fd135Sad 	int	ii_flags;
86af9d4c4fSad 	int	ii_ictx;		/* Initiator context */
87af9d4c4fSad 	int	ii_tid;
88d49fd135Sad };
8903e46dc8Sad #define	II_NOTCTX	0x0001	/* No transaction context */
90af9d4c4fSad #define	II_CONFIGURED	0x0002	/* Already configured */
91ebf51109Sad #define	II_UTILITY	0x0004	/* Utility initiator (not a real device) */
92d49fd135Sad 
93d49fd135Sad #define	IOP_ICTX	0
94ebf51109Sad #define	IOP_INIT_CODE	0x80
95ebf51109Sad 
96ebf51109Sad /*
97ebf51109Sad  * Parameter group op (for async parameter retrievals).
98ebf51109Sad  */
99ebf51109Sad struct iop_pgop {
100ebf51109Sad 	struct	i2o_param_op_list_header olh;
101ebf51109Sad 	struct	i2o_param_op_all_template oat;
1020de5da96Sgmcgarry } __packed;
103d49fd135Sad 
104d49fd135Sad /*
105d49fd135Sad  * Per-IOP context.
106d49fd135Sad  */
107d49fd135Sad struct iop_softc {
108*cbab9cadSchs 	device_t	sc_dev;		/* Generic device data */
10903e46dc8Sad 	bus_space_handle_t sc_ioh;	/* Bus space handle */
11003e46dc8Sad 	bus_space_tag_t	sc_iot;		/* Bus space tag */
11103e46dc8Sad 	bus_dma_tag_t	sc_dmat;	/* Bus DMA tag */
112122b0bd6Sad 	bus_space_handle_t sc_msg_ioh;	/* Message queue bus space handle */
113122b0bd6Sad 	bus_space_tag_t	sc_msg_iot;	/* Message queue bus space tag */
11403e46dc8Sad 	void	 	*sc_ih;		/* Interrupt handler cookie */
115d49fd135Sad 
11603e46dc8Sad 	struct iop_msg	*sc_ims;	/* Message wrappers */
11703e46dc8Sad 	SLIST_HEAD(, iop_msg) sc_im_freelist; /* Free wrapper list */
118e5bca80aSad 	kmutex_t	sc_intrlock;	/* Interrupt level lock */
11903e46dc8Sad 
12003e46dc8Sad 	bus_dmamap_t	sc_rep_dmamap;	/* Reply frames DMA map */
12103e46dc8Sad 	int		sc_rep_size;	/* Reply frames size */
12203e46dc8Sad 	bus_addr_t	sc_rep_phys;	/* Reply frames PA */
12353524e44Schristos 	void *		sc_rep;		/* Reply frames VA */
12403e46dc8Sad 
12503e46dc8Sad 	int		sc_maxib;	/* Max inbound (-> IOP) queue depth */
12603e46dc8Sad 	int		sc_maxob;	/* Max outbound (<- IOP) queue depth */
12703e46dc8Sad 	int		sc_curib;	/* Current inbound queue depth */
12840470684Sad 	int		sc_framesize;	/* Max msg frame size in bytes */
12903e46dc8Sad 
13003e46dc8Sad 	struct i2o_hrt	*sc_hrt;	/* Hardware resource table */
13103e46dc8Sad 	struct iop_tidmap *sc_tidmap;	/* TID map (per-LCT-entry flags) */
13203e46dc8Sad 	struct i2o_lct	*sc_lct;	/* Logical configuration table */
13303e46dc8Sad 	int		sc_nlctent;	/* Number of LCT entries */
134d49fd135Sad 	int		sc_flags;	/* IOP-wide flags */
13503e46dc8Sad 	u_int32_t	sc_chgind;	/* Configuration change indicator */
1369abeea58Sad 	kmutex_t	sc_conflock;	/* Configuration lock */
1379abeea58Sad 	kcondvar_t	sc_confcv;	/* Configuration CV */
13888ab7da9Sad 	lwp_t		*sc_reconf_thread;/* Auto reconfiguration process */
13903e46dc8Sad 	LIST_HEAD(, iop_initiator) sc_iilist;/* Initiator list */
14003e46dc8Sad 	int		sc_nii;		/* Total number of initiators */
14103e46dc8Sad 	int		sc_nuii;	/* Number of utility initiators */
14203e46dc8Sad 
143af9d4c4fSad 	struct iop_initiator sc_eventii;/* IOP event handler */
14403e46dc8Sad 	bus_dmamap_t	sc_scr_dmamap;  /* Scratch DMA map */
14503e46dc8Sad 	bus_dma_segment_t sc_scr_seg[1];/* Scratch DMA segment */
14653524e44Schristos 	void *		sc_scr;		/* Scratch memory VA */
147d49fd135Sad 
14803e46dc8Sad 	bus_space_tag_t	sc_bus_memt;	/* Parent bus memory tag */
14903e46dc8Sad 	bus_space_tag_t	sc_bus_iot;	/* Parent but I/O tag */
15003e46dc8Sad 	bus_addr_t	sc_memaddr;	/* Register window address */
15103e46dc8Sad 	bus_size_t	sc_memsize;	/* Register window size */
152fcf00dccSad 	int		sc_pcibus;	/* PCI bus number */
153fcf00dccSad 	int		sc_pcidev;	/* PCI device number */
154ebf51109Sad 
15503e46dc8Sad 	struct i2o_status sc_status;	/* Last retrieved status record */
156d49fd135Sad };
157d49fd135Sad #define	IOP_OPEN		0x01	/* Device interface open */
158af9d4c4fSad #define	IOP_HAVESTATUS		0x02	/* Successfully retrieved status */
159af9d4c4fSad #define	IOP_ONLINE		0x04	/* Can use ioctl interface */
160d49fd135Sad 
161d49fd135Sad struct iop_attach_args {
162d49fd135Sad 	int	ia_class;		/* device class */
163d49fd135Sad 	int	ia_tid;			/* target ID */
164d49fd135Sad };
165d49fd135Sad 
166af9d4c4fSad void	iop_init(struct iop_softc *, const char *);
167d49fd135Sad int	iop_intr(void *);
168af9d4c4fSad int	iop_lct_get(struct iop_softc *);
169ebf51109Sad int	iop_print_ident(struct iop_softc *, int);
170fcf00dccSad int	iop_post(struct iop_softc *, u_int32_t *);
171fcf00dccSad int	iop_reconfigure(struct iop_softc *, u_int);
172fcf00dccSad int	iop_status_get(struct iop_softc *, int);
173af9d4c4fSad int	iop_simple_cmd(struct iop_softc *, int, int, int, int, int);
174af9d4c4fSad void	iop_strvis(struct iop_softc *, const char *, int, char *, int);
175d49fd135Sad 
176ebf51109Sad void	iop_initiator_register(struct iop_softc *, struct iop_initiator *);
177d49fd135Sad void	iop_initiator_unregister(struct iop_softc *, struct iop_initiator *);
178d49fd135Sad 
17903e46dc8Sad struct	iop_msg *iop_msg_alloc(struct iop_softc *, int);
180ebf51109Sad void	iop_msg_free(struct iop_softc *, struct iop_msg *);
181ebf51109Sad int	iop_msg_map(struct iop_softc *, struct iop_msg *, u_int32_t *, void *,
18203e46dc8Sad 		    int, int, struct proc *);
183ebf51109Sad int	iop_msg_map_bio(struct iop_softc *, struct iop_msg *, u_int32_t *,
184ebf51109Sad 			void *, int, int);
185ebf51109Sad int	iop_msg_post(struct iop_softc *, struct iop_msg *, void *, int);
186d49fd135Sad void	iop_msg_unmap(struct iop_softc *, struct iop_msg *);
187d49fd135Sad 
1881d6329bbSad int	iop_field_get_all(struct iop_softc *, int, int, void *, int,
1891d6329bbSad 			  struct iop_initiator *);
1901d6329bbSad int	iop_field_set(struct iop_softc *, int, int, void *, int, int);
1911d6329bbSad int	iop_table_add_row(struct iop_softc *, int, int, void *, int, int);
1921d6329bbSad int	iop_table_clear(struct iop_softc *, int, int);
1931d6329bbSad int	iop_table_del_row(struct iop_softc *, int, int, int);
1941d6329bbSad int	iop_table_get_row(struct iop_softc *, int, int, void *, int, int);
1951d6329bbSad 
196af9d4c4fSad int	iop_util_abort(struct iop_softc *, struct iop_initiator *, int, int,
197af9d4c4fSad 		      int);
198af9d4c4fSad int	iop_util_claim(struct iop_softc *, struct iop_initiator *, int, int);
199af9d4c4fSad int	iop_util_eventreg(struct iop_softc *, struct iop_initiator *, int);
200d49fd135Sad 
201d49fd135Sad #endif	/* !_I2O_IOPVAR_H_ */
202