Home | History | Annotate | Line # | Download | only in ic
mlxvar.h revision 1.1
      1 /*	$NetBSD: mlxvar.h,v 1.1 2001/02/04 17:05:12 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 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 /*-
     40  * Copyright (c) 1999 Michael Smith
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  * SUCH DAMAGE.
     63  *
     64  * from FreeBSD: mlxvar.h,v 1.5.2.2 2000/04/24 19:40:50 msmith Exp
     65  */
     66 
     67 #ifndef _IC_MLXVAR_H_
     68 #define	_IC_MLXVAR_H_
     69 
     70 #include "locators.h"
     71 
     72 /* Older boards allow up to 17 segments and 64kB transfers. */
     73 #define	MLX_MAX_SEGS		17
     74 #define	MLX_MAX_XFER		65536
     75 #define MLX_SGL_SIZE		(sizeof(struct mlx_sgentry) * MLX_MAX_SEGS)
     76 
     77 /* This shouldn't be ajusted lightly... */
     78 #define MLX_MAX_DRIVES		32
     79 
     80 /* Maximum queue depth, matching the older controllers. */
     81 #define	MLX_MAX_QUEUECNT	63
     82 
     83 /* Number of CCBs to reserve for `special' operations. */
     84 #define	MLX_NCCBS_RESERVE	7
     85 
     86 /* Structure describing a system drive as attached to the controller. */
     87 struct mlx_sysdrive {
     88 	u_int32_t	ms_size;
     89 	u_short		ms_state;
     90 	u_short		ms_raidlevel;
     91 	struct device	*ms_dv;
     92 };
     93 
     94 /* Optional per-CCB context. */
     95 struct mlx_ccb;
     96 struct mlx_context {
     97 	void	(*mx_handler)(struct mlx_ccb *);
     98 	void 	*mx_context;
     99 	struct	device	*mx_dv;
    100 };
    101 
    102 /* Command control block. */
    103 struct mlx_ccb {
    104 	union {
    105 		SIMPLEQ_ENTRY(mlx_ccb) simpleq;
    106 		SLIST_ENTRY(mlx_ccb) slist;
    107 		TAILQ_ENTRY(mlx_ccb) tailq;
    108 	} mc_chain;
    109 	u_int		mc_flags;
    110 	u_int		mc_status;
    111 	u_int		mc_ident;
    112 	time_t		mc_expiry;
    113 	u_int		mc_nsgent;
    114 	u_int		mc_xfer_size;
    115 	bus_addr_t	mc_xfer_phys;
    116 	bus_dmamap_t	mc_xfer_map;
    117 	struct mlx_context mc_mx;
    118 	u_int8_t	mc_mbox[16];
    119 };
    120 #define	MC_XFER_IN	MU_XFER_IN	/* Map describes inbound xfer */
    121 #define	MC_XFER_OUT	MU_XFER_OUT	/* Map describes outbound xfer */
    122 #define	MC_WAITING	0x0400		/* We have waiters */
    123 
    124 /*
    125  * Per-controller state.
    126  */
    127 struct mlx_softc {
    128 	struct device		mlx_dv;
    129 	bus_space_tag_t		mlx_iot;
    130 	bus_space_handle_t	mlx_ioh;
    131 	bus_dma_tag_t		mlx_dmat;
    132 	bus_dmamap_t		mlx_dmamap;
    133 	void			*mlx_ih;
    134 
    135 	SLIST_HEAD(, mlx_ccb)	mlx_ccb_freelist;
    136 	TAILQ_HEAD(, mlx_ccb)	mlx_ccb_worklist;
    137 	SIMPLEQ_HEAD(, mlx_ccb)	mlx_ccb_queue;
    138 	struct mlx_ccb		*mlx_ccbs;
    139 	int			mlx_nccbs;
    140 	int			mlx_nccbs_free;
    141 
    142 	caddr_t			mlx_sgls;
    143 	bus_addr_t		mlx_sgls_paddr;
    144 
    145 	int	(*mlx_submit)(struct mlx_softc *, struct mlx_ccb *);
    146 	int	(*mlx_findcomplete)(struct mlx_softc *, u_int *, u_int *);
    147 	void	(*mlx_intaction)(struct mlx_softc *, int);
    148 	int	(*mlx_fw_handshake)(struct mlx_softc *, int *, int *, int *);
    149 
    150 	int			mlx_max_queuecnt;
    151 	struct mlx_enquiry2	*mlx_enq2;
    152 	int			mlx_iftype;
    153 
    154 	time_t			mlx_lastpoll;
    155 	u_int			mlx_lastevent;
    156 	u_int			mlx_currevent;
    157 	u_int			mlx_bg;
    158 	struct mlx_rebuild_status mlx_rebuildstat;
    159 	struct mlx_pause	mlx_pause;
    160 	int			mlx_flags;
    161 
    162 	struct mlx_sysdrive	mlx_sysdrive[MLX_MAX_DRIVES];
    163 };
    164 
    165 #define MLX_BG_CHECK		1	/* we started a check */
    166 #define MLX_BG_REBUILD		2	/* we started a rebuild */
    167 #define MLX_BG_SPONTANEOUS	3	/* it just happened somehow */
    168 
    169 #define MLXF_SPINUP_REPORTED	0x0001	/* "spinning up drives" displayed */
    170 #define MLXF_EVENTLOG_BUSY	0x0002	/* currently reading event log */
    171 #define MLXF_FW_INITTED		0x0004	/* firmware init crap done */
    172 #define MLXF_PAUSEWORKS		0x0008	/* channel pause works as expected */
    173 #define MLXF_OPEN		0x0010	/* control device is open */
    174 #define	MLXF_INITOK		0x0020	/* controller initalised OK */
    175 #define	MLXF_PERIODIC_CTLR	0x0040	/* periodic check running */
    176 #define	MLXF_PERIODIC_DRIVE	0x0080	/* periodic check running */
    177 #define	MLXF_PERIODIC_REBUILD	0x0100	/* periodic check running */
    178 #define	MLXF_EISA		0x0200	/* EISA board */
    179 
    180 struct mlx_attach_args {
    181 	int		mlxa_unit;
    182 };
    183 
    184 #define	mlxacf_unit	cf_loc[MLXCF_UNIT]
    185 
    186 int	mlx_flush(struct mlx_softc *, int);
    187 void	mlx_init(struct mlx_softc *, const char *);
    188 int	mlx_intr(void *);
    189 
    190 int	mlx_ccb_alloc(struct mlx_softc *, struct mlx_ccb **, int);
    191 const char *mlx_ccb_diagnose(struct mlx_ccb *);
    192 void	mlx_ccb_enqueue(struct mlx_softc *, struct mlx_ccb *);
    193 void	mlx_ccb_free(struct mlx_softc *, struct mlx_ccb *);
    194 int	mlx_ccb_map(struct mlx_softc *, struct mlx_ccb *, void *, int, int);
    195 int	mlx_ccb_poll(struct mlx_softc *, struct mlx_ccb *, int);
    196 void	mlx_ccb_unmap(struct mlx_softc *, struct mlx_ccb *);
    197 int	mlx_ccb_wait(struct mlx_softc *, struct mlx_ccb *);
    198 
    199 static __inline__ void	mlx_make_type1(struct mlx_ccb *, u_int8_t, u_int16_t,
    200 				       u_int32_t, u_int8_t, u_int32_t,
    201 				       u_int8_t);
    202 static __inline__ void	mlx_make_type2(struct mlx_ccb *, u_int8_t, u_int8_t,
    203 				       u_int8_t, u_int8_t, u_int8_t,
    204 				       u_int8_t, u_int8_t, u_int32_t,
    205 				       u_int8_t);
    206 static __inline__ void	mlx_make_type3(struct mlx_ccb *, u_int8_t, u_int8_t,
    207 				       u_int8_t, u_int16_t, u_int8_t,
    208 				       u_int8_t, u_int32_t, u_int8_t);
    209 static __inline__ void	mlx_make_type4(struct mlx_ccb *, u_int8_t, u_int16_t,
    210 				       u_int32_t, u_int32_t, u_int8_t);
    211 static __inline__ void	mlx_make_type5(struct mlx_ccb *, u_int8_t,  u_int8_t,
    212 				       u_int8_t, u_int32_t, u_int32_t,
    213 				       u_int8_t);
    214 
    215 static __inline__ u_int8_t	mlx_inb(struct mlx_softc *, int);
    216 static __inline__ u_int16_t	mlx_inw(struct mlx_softc *, int);
    217 static __inline__ u_int32_t	mlx_inl(struct mlx_softc *, int);
    218 static __inline__ void		mlx_outb(struct mlx_softc *, int, u_int8_t);
    219 static __inline__ void		mlx_outw(struct mlx_softc *, int, u_int16_t);
    220 static __inline__ void		mlx_outl(struct mlx_softc *, int, u_int32_t);
    221 
    222 static __inline__ void
    223 mlx_make_type1(struct mlx_ccb *mc, u_int8_t code, u_int16_t f1, u_int32_t f2,
    224 	       u_int8_t f3, u_int32_t f4, u_int8_t f5)
    225 {
    226 
    227 	mc->mc_mbox[0x0] = code;
    228 	mc->mc_mbox[0x2] = f1;
    229 	mc->mc_mbox[0x3] = (((f2 >> 24) & 0x3) << 6) | ((f1 >> 8) & 0x3f);
    230 	mc->mc_mbox[0x4] = f2;
    231 	mc->mc_mbox[0x5] = (f2 >> 8);
    232 	mc->mc_mbox[0x6] = (f2 >> 16);
    233 	mc->mc_mbox[0x7] = f3;
    234 	mc->mc_mbox[0x8] = f4;
    235 	mc->mc_mbox[0x9] = (f4 >> 8);
    236 	mc->mc_mbox[0xa] = (f4 >> 16);
    237 	mc->mc_mbox[0xb] = (f4 >> 24);
    238 	mc->mc_mbox[0xc] = f5;
    239 }
    240 
    241 static __inline__ void
    242 mlx_make_type2(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
    243 	       u_int8_t f3, u_int8_t f4, u_int8_t f5, u_int8_t f6,
    244 	       u_int32_t f7, u_int8_t f8)
    245 {
    246 
    247 	mc->mc_mbox[0x0] = code;
    248 	mc->mc_mbox[0x2] = f1;
    249 	mc->mc_mbox[0x3] = f2;
    250 	mc->mc_mbox[0x4] = f3;
    251 	mc->mc_mbox[0x5] = f4;
    252 	mc->mc_mbox[0x6] = f5;
    253 	mc->mc_mbox[0x7] = f6;
    254 	mc->mc_mbox[0x8] = f7;
    255 	mc->mc_mbox[0x9] = (f7 >> 8);
    256 	mc->mc_mbox[0xa] = (f7 >> 16);
    257 	mc->mc_mbox[0xb] = (f7 >> 24);
    258 	mc->mc_mbox[0xc] = f8;
    259 }
    260 
    261 static __inline__ void
    262 mlx_make_type3(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
    263 	       u_int16_t f3, u_int8_t f4, u_int8_t f5, u_int32_t f6,
    264 	       u_int8_t f7)
    265 {
    266 
    267 	mc->mc_mbox[0x0] = code;
    268 	mc->mc_mbox[0x2] = f1;
    269 	mc->mc_mbox[0x3] = f2;
    270 	mc->mc_mbox[0x4] = f3;
    271 	mc->mc_mbox[0x5] = (f3 >> 8);
    272 	mc->mc_mbox[0x6] = f4;
    273 	mc->mc_mbox[0x7] = f5;
    274 	mc->mc_mbox[0x8] = f6;
    275 	mc->mc_mbox[0x9] = (f6 >> 8);
    276 	mc->mc_mbox[0xa] = (f6 >> 16);
    277 	mc->mc_mbox[0xb] = (f6 >> 24);
    278 	mc->mc_mbox[0xc] = f7;
    279 }
    280 
    281 static __inline__ void
    282 mlx_make_type4(struct mlx_ccb *mc, u_int8_t code,  u_int16_t f1, u_int32_t f2,
    283 	       u_int32_t f3, u_int8_t f4)
    284 {
    285 
    286 	mc->mc_mbox[0x0] = code;
    287 	mc->mc_mbox[0x2] = f1;
    288 	mc->mc_mbox[0x3] = (f1 >> 8);
    289 	mc->mc_mbox[0x4] = f2;
    290 	mc->mc_mbox[0x5] = (f2 >> 8);
    291 	mc->mc_mbox[0x6] = (f2 >> 16);
    292 	mc->mc_mbox[0x7] = (f2 >> 24);
    293 	mc->mc_mbox[0x8] = f3;
    294 	mc->mc_mbox[0x9] = (f3 >> 8);
    295 	mc->mc_mbox[0xa] = (f3 >> 16);
    296 	mc->mc_mbox[0xb] = (f3 >> 24);
    297 	mc->mc_mbox[0xc] = f4;
    298 }
    299 
    300 static __inline__ void
    301 mlx_make_type5(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
    302 	       u_int32_t f3, u_int32_t f4, u_int8_t f5)
    303 {
    304 
    305 	mc->mc_mbox[0x0] = code;
    306 	mc->mc_mbox[0x2] = f1;
    307 	mc->mc_mbox[0x3] = f2;
    308 	mc->mc_mbox[0x4] = f3;
    309 	mc->mc_mbox[0x5] = (f3 >> 8);
    310 	mc->mc_mbox[0x6] = (f3 >> 16);
    311 	mc->mc_mbox[0x7] = (f3 >> 24);
    312 	mc->mc_mbox[0x8] = f4;
    313 	mc->mc_mbox[0x9] = (f4 >> 8);
    314 	mc->mc_mbox[0xa] = (f4 >> 16);
    315 	mc->mc_mbox[0xb] = (f4 >> 24);
    316 	mc->mc_mbox[0xc] = f5;
    317 }
    318 
    319 static __inline__ u_int8_t
    320 mlx_inb(struct mlx_softc *mlx, int off)
    321 {
    322 
    323 	bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 1,
    324 	    BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
    325 	return (bus_space_read_1(mlx->mlx_iot, mlx->mlx_ioh, off));
    326 }
    327 
    328 static __inline__ u_int16_t
    329 mlx_inw(struct mlx_softc *mlx, int off)
    330 {
    331 
    332 	bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 2,
    333 	    BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
    334 	return (bus_space_read_2(mlx->mlx_iot, mlx->mlx_ioh, off));
    335 }
    336 
    337 static __inline__ u_int32_t
    338 mlx_inl(struct mlx_softc *mlx, int off)
    339 {
    340 
    341 	bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 4,
    342 	    BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
    343 	return (bus_space_read_4(mlx->mlx_iot, mlx->mlx_ioh, off));
    344 }
    345 
    346 static __inline__ void
    347 mlx_outb(struct mlx_softc *mlx, int off, u_int8_t val)
    348 {
    349 
    350 	bus_space_write_1(mlx->mlx_iot, mlx->mlx_ioh, off, val);
    351 	bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 1,
    352 	    BUS_SPACE_BARRIER_WRITE);
    353 }
    354 
    355 static __inline__ void
    356 mlx_outw(struct mlx_softc *mlx, int off, u_int16_t val)
    357 {
    358 
    359 	bus_space_write_2(mlx->mlx_iot, mlx->mlx_ioh, off, val);
    360 	bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 2,
    361 	    BUS_SPACE_BARRIER_WRITE);
    362 }
    363 
    364 static __inline__ void
    365 mlx_outl(struct mlx_softc *mlx, int off, u_int32_t val)
    366 {
    367 
    368 	bus_space_write_4(mlx->mlx_iot, mlx->mlx_ioh, off, val);
    369 	bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 4,
    370 	    BUS_SPACE_BARRIER_WRITE);
    371 }
    372 
    373 #endif	/* !_IC_MLXVAR_H_ */
    374