Home | History | Annotate | Line # | Download | only in ic
aacvar.h revision 1.2
      1 /*	$NetBSD: aacvar.h,v 1.2 2003/11/02 11:07:44 wiz Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2002 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) 2000 Michael Smith
     41  * Copyright (c) 2000 BSDi
     42  * Copyright (c) 2000 Niklas Hallqvist
     43  * All rights reserved.
     44  *
     45  * Redistribution and use in source and binary forms, with or without
     46  * modification, are permitted provided that the following conditions
     47  * are met:
     48  * 1. Redistributions of source code must retain the above copyright
     49  *    notice, this list of conditions and the following disclaimer.
     50  * 2. Redistributions in binary form must reproduce the above copyright
     51  *    notice, this list of conditions and the following disclaimer in the
     52  *    documentation and/or other materials provided with the distribution.
     53  *
     54  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  * SUCH DAMAGE.
     65  *
     66  *	from FreeBSD: aacvar.h,v 1.1 2000/09/13 03:20:34 msmith Exp
     67  *	via OpenBSD: aacvar.h,v 1.2 2002/03/14 01:26:53 millert Exp
     68  */
     69 
     70 #ifndef _PCI_AACVAR_H_
     71 #define	_PCI_AACVAR_H_
     72 
     73 /* Debugging */
     74 #ifdef AAC_DEBUG
     75 #define AAC_DPRINTF(mask, args) if ((aac_debug & (mask)) != 0) printf args
     76 #define AAC_D_INTR	0x01
     77 #define AAC_D_MISC	0x02
     78 #define AAC_D_CMD	0x04
     79 #define AAC_D_QUEUE	0x08
     80 #define AAC_D_IO	0x10
     81 extern int aac_debug;
     82 
     83 #define AAC_PRINT_FIB(sc, fib)	aac_print_fib((sc), (fib), __FUNCTION__)
     84 #else
     85 #define AAC_DPRINTF(mask, args)
     86 #define AAC_PRINT_FIB(sc, fib)
     87 #endif
     88 
     89 struct aac_code_lookup {
     90 	char	*string;
     91 	u_int32_t code;
     92 };
     93 
     94 extern const struct	 aac_code_lookup aac_command_status_table[];
     95 extern const struct	 aac_code_lookup aac_cpu_variant[];
     96 extern const struct	 aac_code_lookup aac_battery_platform[];
     97 extern const struct	 aac_code_lookup aac_container_types[];
     98 
     99 struct aac_softc;
    100 
    101 /*
    102  * We allocate a small set of FIBs for the adapter to use to send us messages.
    103  */
    104 #define AAC_ADAPTER_FIBS	8
    105 
    106 /*
    107  * Firmware messages are passed in the printf buffer.
    108  */
    109 #define AAC_PRINTF_BUFSIZE	256
    110 
    111 /*
    112  * We wait this many seconds for the adapter to come ready if it is still
    113  * booting.
    114  */
    115 #define AAC_BOOT_TIMEOUT	(3 * 60)
    116 
    117 /*
    118  * Wait this long for a lost interrupt to get detected.
    119  */
    120 #define AAC_WATCH_TIMEOUT	10000		/* 10000 * 1ms = 10s */
    121 
    122 /*
    123  * Timeout for immediate commands.
    124  */
    125 #define AAC_IMMEDIATE_TIMEOUT	30
    126 
    127 /*
    128  * Delay 20ms after the qnotify in sync operations.  Experimentally deduced.
    129  */
    130 #define AAC_SYNC_DELAY		20000
    131 
    132 /*
    133  * The firmware interface allows for a 16-bit s/g list length.  We limit
    134  * ourselves to a reasonable maximum and ensure alignment.
    135  */
    136 #define AAC_MAX_SGENTRIES	17	/* max S/G entries, limit 65535 */
    137 #define	AAC_MAX_XFER		((AAC_MAX_SGENTRIES - 1) * PAGE_SIZE)
    138 
    139 /*
    140  * Fixed sector size.
    141  */
    142 #define	AAC_SECTOR_SIZE		512
    143 
    144 /*
    145  * Number of CCBs to allocate, and to reserve for control operations.
    146  */
    147 #define	AAC_NCCBS		256
    148 #define	AAC_NCCBS_RESERVE	4
    149 
    150 /*
    151  * Quirk listings.
    152  */
    153 #define	AAC_QUIRK_PERC2QC	0x0001
    154 
    155 /*
    156  * We gather a number of adapter-visible items into a single structure.
    157  *
    158  * The ordering of this structure may be important; we copy the Linux driver:
    159  *
    160  * Adapter FIBs
    161  * Init struct
    162  * Queue headers (Comm Area)
    163  * Printf buffer
    164  *
    165  * In addition, we add:
    166  * Sync Fib
    167  */
    168 struct aac_common {
    169 	/* fibs for the controller to send us messages */
    170 	struct aac_fib ac_fibs[AAC_ADAPTER_FIBS];
    171 
    172 	/* the init structure */
    173 	struct aac_adapter_init	ac_init;
    174 
    175 	/* arena within which the queue structures are kept */
    176 	u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + AAC_QUEUE_ALIGN];
    177 
    178 	/* buffer for text messages from the controller */
    179 	char	ac_printf[AAC_PRINTF_BUFSIZE];
    180 
    181 	/* fib for synchronous commands */
    182 	struct aac_fib ac_sync_fib;
    183 };
    184 
    185 /*
    186  * Interface operations
    187  */
    188 struct aac_interface {
    189 	int	(*aif_get_fwstatus)(struct aac_softc *);
    190 	void	(*aif_qnotify)(struct aac_softc *, int);
    191 	int	(*aif_get_istatus)(struct aac_softc *);
    192 	void	(*aif_set_istatus)(struct aac_softc *, int);
    193 	void	(*aif_set_mailbox)(struct aac_softc *, u_int32_t,
    194 				   u_int32_t, u_int32_t, u_int32_t, u_int32_t);
    195 	int	(*aif_get_mailboxstatus)(struct aac_softc *);
    196 	void	(*aif_set_interrupts)(struct aac_softc *, int);
    197 };
    198 
    199 #define AAC_GET_FWSTATUS(sc)		((sc)->sc_if.aif_get_fwstatus(sc))
    200 #define AAC_QNOTIFY(sc, qbit) \
    201 	((sc)->sc_if.aif_qnotify((sc), (qbit)))
    202 #define AAC_GET_ISTATUS(sc)		((sc)->sc_if.aif_get_istatus(sc))
    203 #define AAC_CLEAR_ISTATUS(sc, mask) \
    204 	((sc)->sc_if.aif_set_istatus((sc), (mask)))
    205 #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \
    206 	do {								\
    207 		((sc)->sc_if.aif_set_mailbox((sc), (command), (arg0),	\
    208 		    (arg1), (arg2), (arg3)));				\
    209 	} while(0)
    210 #define AAC_GET_MAILBOXSTATUS(sc) \
    211 	((sc)->sc_if.aif_get_mailboxstatus(sc))
    212 #define	AAC_MASK_INTERRUPTS(sc)	\
    213 	((sc)->sc_if.aif_set_interrupts((sc), 0))
    214 #define AAC_UNMASK_INTERRUPTS(sc) \
    215 	((sc)->sc_if.aif_set_interrupts((sc), 1))
    216 
    217 #define AAC_SETREG4(sc, reg, val) \
    218 	bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (reg), (val))
    219 #define AAC_GETREG4(sc, reg) \
    220 	bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (reg))
    221 #define AAC_SETREG2(sc, reg, val) \
    222 	bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (reg), (val))
    223 #define AAC_GETREG2(sc, reg) \
    224 	bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (reg))
    225 #define AAC_SETREG1(sc, reg, val) \
    226 	bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (reg), (val))
    227 #define AAC_GETREG1(sc, reg) \
    228 	bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (reg))
    229 
    230 
    231 /*
    232  * A command contol block, one for each corresponding command index of the
    233  * controller.
    234  */
    235 struct aac_ccb {
    236 	SIMPLEQ_ENTRY(aac_ccb)	ac_chain;
    237 
    238 	struct aac_fib		*ac_fib;
    239 	bus_addr_t		ac_fibphys;
    240 	bus_dmamap_t		ac_dmamap_xfer;
    241 
    242 	void			*ac_data;
    243 	size_t			ac_datalen;
    244 	u_int			ac_flags;
    245 
    246 	void			(*ac_intr)(struct aac_ccb *);
    247 	struct device		*ac_device;
    248 	void			*ac_context;
    249 };
    250 #define AAC_CCB_MAPPED	 	0x01
    251 #define AAC_CCB_COMPLETED 	0x02
    252 #define AAC_CCB_DATA_IN		0x04
    253 #define AAC_CCB_DATA_OUT	0x08
    254 
    255 struct aac_drive {
    256 	u_int	hd_present;
    257 	u_int	hd_devtype;
    258 	u_int	hd_size;
    259 };
    260 
    261 /*
    262  * Per-controller structure.
    263  */
    264 struct aac_softc {
    265 	struct device		sc_dv;
    266 	void			*sc_ih;
    267 	bus_space_tag_t		sc_memt;
    268 	bus_space_handle_t	sc_memh;
    269 	bus_dma_tag_t		sc_dmat;
    270 
    271 	struct FsaRevision	sc_revision;
    272 	int			sc_hwif;
    273 	int			sc_quirks;
    274 	struct aac_interface	sc_if;
    275 
    276 	struct aac_common	*sc_common;
    277 	bus_dma_segment_t	sc_common_seg;
    278 	bus_dmamap_t		sc_common_dmamap;
    279 	struct aac_fib		*sc_fibs;
    280 	bus_dma_segment_t	sc_fibs_seg;
    281 	bus_dmamap_t		sc_fibs_dmamap;
    282 
    283 	struct aac_ccb		*sc_ccbs;
    284 	SIMPLEQ_HEAD(, aac_ccb)	sc_ccb_free;
    285 	SIMPLEQ_HEAD(, aac_ccb)	sc_ccb_queue;
    286 	SIMPLEQ_HEAD(, aac_ccb)	sc_ccb_complete;
    287 
    288 	struct aac_queue_table	*sc_queues;
    289 	struct aac_queue_entry	*sc_qentries[AAC_QUEUE_COUNT];
    290 	struct aac_drive	sc_hdr[AAC_MAX_CONTAINERS];
    291 	int			sc_nunits;
    292 	int			sc_flags;
    293 };
    294 #define AAC_HWIF_I960RX		0
    295 #define AAC_HWIF_STRONGARM	1
    296 
    297 #define	AAC_ONLINE		2
    298 
    299 struct aac_attach_args {
    300 	int		aaca_unit;
    301 };
    302 
    303 #define	aaccf_unit	cf_loc[AACCF_UNIT]
    304 
    305 int	aac_attach(struct aac_softc *);
    306 void	aac_ccb_enqueue(struct aac_softc *, struct aac_ccb *);
    307 void	aac_ccb_free(struct aac_softc *, struct aac_ccb *);
    308 struct aac_ccb *aac_ccb_alloc(struct aac_softc *, int);
    309 int	aac_ccb_map(struct aac_softc *, struct aac_ccb *);
    310 int	aac_ccb_poll(struct aac_softc *, struct aac_ccb *, int);
    311 int	aac_ccb_submit(struct aac_softc *, struct aac_ccb *);
    312 void	aac_ccb_unmap(struct aac_softc *, struct aac_ccb *);
    313 const char	*aac_describe_code(const struct aac_code_lookup *, u_int32_t);
    314 int	aac_intr(void *);
    315 
    316 #endif	/* !_PCI_AACVAR_H_ */
    317