Home | History | Annotate | Line # | Download | only in i2o
      1 /*	$NetBSD: iopvar.h,v 1.24 2012/10/27 17:18:17 chs Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000, 2001, 2002, 2007 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _I2O_IOPVAR_H_
     33 #define	_I2O_IOPVAR_H_
     34 
     35 #include <sys/mutex.h>
     36 #include <sys/condvar.h>
     37 
     38 /*
     39  * Transfer descriptor.
     40  */
     41 struct iop_xfer {
     42 	bus_dmamap_t	ix_map;
     43 	u_int		ix_size;
     44 	u_int		ix_flags;
     45 };
     46 #define	IX_IN			0x0001	/* Data transfer from IOP */
     47 #define	IX_OUT			0x0002	/* Data transfer to IOP */
     48 
     49 /*
     50  * Message wrapper.
     51  */
     52 struct iop_msg {
     53 	SLIST_ENTRY(iop_msg)	im_chain;	/* Next free message */
     54 	u_int			im_flags;	/* Control flags */
     55 	u_int			im_tctx;	/* Transaction context */
     56 	void			*im_dvcontext;	/* Un*x device context */
     57 	struct i2o_reply	*im_rb;		/* Reply buffer */
     58 	kcondvar_t		im_cv;		/* Notifier */
     59 	u_int			im_reqstatus;	/* Status from reply */
     60 	u_int			im_detstatus;	/* Detailed status code */
     61 	struct iop_xfer		im_xfer[IOP_MAX_MSG_XFERS];
     62 };
     63 #define	IM_SYSMASK		0x00ff
     64 #define	IM_REPLIED		0x0001	/* Message has been replied to */
     65 #define	IM_ALLOCED		0x0002	/* This message wrapper is allocated */
     66 #define	IM_SGLOFFADJ		0x0004	/* S/G list offset adjusted */
     67 #define	IM_FAIL			0x0008	/* Transaction error returned */
     68 
     69 #define	IM_USERMASK		0xff00
     70 #define	IM_WAIT			0x0100	/* Wait (sleep) for completion */
     71 #define	IM_POLL			0x0200	/* Wait (poll) for completion */
     72 #define	IM_NOSTATUS		0x0400	/* Don't check status if waiting */
     73 #define	IM_POLL_INTR		0x0800	/* Do send interrupt when polling */
     74 
     75 struct iop_initiator {
     76 	LIST_ENTRY(iop_initiator) ii_list;
     77 	LIST_ENTRY(iop_initiator) ii_hash;
     78 
     79 	void	(*ii_intr)(device_t, struct iop_msg *, void *);
     80 	int	(*ii_reconfig)(device_t);
     81 	void	(*ii_adjqparam)(device_t, int);
     82 
     83 	device_t ii_dv;
     84 	kcondvar_t ii_cv;
     85 	int	ii_flags;
     86 	int	ii_ictx;		/* Initiator context */
     87 	int	ii_tid;
     88 };
     89 #define	II_NOTCTX	0x0001	/* No transaction context */
     90 #define	II_CONFIGURED	0x0002	/* Already configured */
     91 #define	II_UTILITY	0x0004	/* Utility initiator (not a real device) */
     92 
     93 #define	IOP_ICTX	0
     94 #define	IOP_INIT_CODE	0x80
     95 
     96 /*
     97  * Parameter group op (for async parameter retrievals).
     98  */
     99 struct iop_pgop {
    100 	struct	i2o_param_op_list_header olh;
    101 	struct	i2o_param_op_all_template oat;
    102 } __packed;
    103 
    104 /*
    105  * Per-IOP context.
    106  */
    107 struct iop_softc {
    108 	device_t	sc_dev;		/* Generic device data */
    109 	bus_space_handle_t sc_ioh;	/* Bus space handle */
    110 	bus_space_tag_t	sc_iot;		/* Bus space tag */
    111 	bus_dma_tag_t	sc_dmat;	/* Bus DMA tag */
    112 	bus_space_handle_t sc_msg_ioh;	/* Message queue bus space handle */
    113 	bus_space_tag_t	sc_msg_iot;	/* Message queue bus space tag */
    114 	void	 	*sc_ih;		/* Interrupt handler cookie */
    115 
    116 	struct iop_msg	*sc_ims;	/* Message wrappers */
    117 	SLIST_HEAD(, iop_msg) sc_im_freelist; /* Free wrapper list */
    118 	kmutex_t	sc_intrlock;	/* Interrupt level lock */
    119 
    120 	bus_dmamap_t	sc_rep_dmamap;	/* Reply frames DMA map */
    121 	int		sc_rep_size;	/* Reply frames size */
    122 	bus_addr_t	sc_rep_phys;	/* Reply frames PA */
    123 	void *		sc_rep;		/* Reply frames VA */
    124 
    125 	int		sc_maxib;	/* Max inbound (-> IOP) queue depth */
    126 	int		sc_maxob;	/* Max outbound (<- IOP) queue depth */
    127 	int		sc_curib;	/* Current inbound queue depth */
    128 	int		sc_framesize;	/* Max msg frame size in bytes */
    129 
    130 	struct i2o_hrt	*sc_hrt;	/* Hardware resource table */
    131 	struct iop_tidmap *sc_tidmap;	/* TID map (per-LCT-entry flags) */
    132 	struct i2o_lct	*sc_lct;	/* Logical configuration table */
    133 	int		sc_nlctent;	/* Number of LCT entries */
    134 	int		sc_flags;	/* IOP-wide flags */
    135 	u_int32_t	sc_chgind;	/* Configuration change indicator */
    136 	kmutex_t	sc_conflock;	/* Configuration lock */
    137 	kcondvar_t	sc_confcv;	/* Configuration CV */
    138 	lwp_t		*sc_reconf_thread;/* Auto reconfiguration process */
    139 	LIST_HEAD(, iop_initiator) sc_iilist;/* Initiator list */
    140 	int		sc_nii;		/* Total number of initiators */
    141 	int		sc_nuii;	/* Number of utility initiators */
    142 
    143 	struct iop_initiator sc_eventii;/* IOP event handler */
    144 	bus_dmamap_t	sc_scr_dmamap;  /* Scratch DMA map */
    145 	bus_dma_segment_t sc_scr_seg[1];/* Scratch DMA segment */
    146 	void *		sc_scr;		/* Scratch memory VA */
    147 
    148 	bus_space_tag_t	sc_bus_memt;	/* Parent bus memory tag */
    149 	bus_space_tag_t	sc_bus_iot;	/* Parent but I/O tag */
    150 	bus_addr_t	sc_memaddr;	/* Register window address */
    151 	bus_size_t	sc_memsize;	/* Register window size */
    152 	int		sc_pcibus;	/* PCI bus number */
    153 	int		sc_pcidev;	/* PCI device number */
    154 
    155 	struct i2o_status sc_status;	/* Last retrieved status record */
    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 struct iop_attach_args {
    162 	int	ia_class;		/* device class */
    163 	int	ia_tid;			/* target ID */
    164 };
    165 
    166 void	iop_init(struct iop_softc *, const char *);
    167 int	iop_intr(void *);
    168 int	iop_lct_get(struct iop_softc *);
    169 int	iop_print_ident(struct iop_softc *, int);
    170 int	iop_post(struct iop_softc *, u_int32_t *);
    171 int	iop_reconfigure(struct iop_softc *, u_int);
    172 int	iop_status_get(struct iop_softc *, int);
    173 int	iop_simple_cmd(struct iop_softc *, int, int, int, int, int);
    174 void	iop_strvis(struct iop_softc *, const char *, int, char *, int);
    175 
    176 void	iop_initiator_register(struct iop_softc *, struct iop_initiator *);
    177 void	iop_initiator_unregister(struct iop_softc *, struct iop_initiator *);
    178 
    179 struct	iop_msg *iop_msg_alloc(struct iop_softc *, int);
    180 void	iop_msg_free(struct iop_softc *, struct iop_msg *);
    181 int	iop_msg_map(struct iop_softc *, struct iop_msg *, u_int32_t *, void *,
    182 		    int, int, struct proc *);
    183 int	iop_msg_map_bio(struct iop_softc *, struct iop_msg *, u_int32_t *,
    184 			void *, int, int);
    185 int	iop_msg_post(struct iop_softc *, struct iop_msg *, void *, int);
    186 void	iop_msg_unmap(struct iop_softc *, struct iop_msg *);
    187 
    188 int	iop_field_get_all(struct iop_softc *, int, int, void *, int,
    189 			  struct iop_initiator *);
    190 int	iop_field_set(struct iop_softc *, int, int, void *, int, int);
    191 int	iop_table_add_row(struct iop_softc *, int, int, void *, int, int);
    192 int	iop_table_clear(struct iop_softc *, int, int);
    193 int	iop_table_del_row(struct iop_softc *, int, int, int);
    194 int	iop_table_get_row(struct iop_softc *, int, int, void *, int, int);
    195 
    196 int	iop_util_abort(struct iop_softc *, struct iop_initiator *, int, int,
    197 		      int);
    198 int	iop_util_claim(struct iop_softc *, struct iop_initiator *, int, int);
    199 int	iop_util_eventreg(struct iop_softc *, struct iop_initiator *, int);
    200 
    201 #endif	/* !_I2O_IOPVAR_H_ */
    202