Home | History | Annotate | Line # | Download | only in ic
aacvar.h revision 1.11.10.2
      1  1.11.10.2      yamt /*	$NetBSD: aacvar.h,v 1.11.10.2 2009/05/04 08:12:39 yamt Exp $	*/
      2        1.1        ad 
      3        1.1        ad /*-
      4        1.1        ad  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5        1.1        ad  * All rights reserved.
      6        1.1        ad  *
      7        1.1        ad  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1        ad  * by Andrew Doran.
      9        1.1        ad  *
     10        1.1        ad  * Redistribution and use in source and binary forms, with or without
     11        1.1        ad  * modification, are permitted provided that the following conditions
     12        1.1        ad  * are met:
     13        1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14        1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15        1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17        1.1        ad  *    documentation and/or other materials provided with the distribution.
     18        1.1        ad  *
     19        1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1        ad  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        ad  */
     31        1.1        ad 
     32        1.1        ad /*-
     33        1.1        ad  * Copyright (c) 2000 Michael Smith
     34        1.1        ad  * Copyright (c) 2000 BSDi
     35        1.1        ad  * Copyright (c) 2000 Niklas Hallqvist
     36        1.1        ad  * All rights reserved.
     37        1.1        ad  *
     38        1.1        ad  * Redistribution and use in source and binary forms, with or without
     39        1.1        ad  * modification, are permitted provided that the following conditions
     40        1.1        ad  * are met:
     41        1.1        ad  * 1. Redistributions of source code must retain the above copyright
     42        1.1        ad  *    notice, this list of conditions and the following disclaimer.
     43        1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     44        1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     45        1.1        ad  *    documentation and/or other materials provided with the distribution.
     46        1.1        ad  *
     47        1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     48        1.1        ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     49        1.1        ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     50        1.1        ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     51        1.1        ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     52        1.1        ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     53        1.1        ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     54        1.1        ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     55        1.1        ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     56        1.1        ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     57        1.1        ad  * SUCH DAMAGE.
     58        1.1        ad  *
     59        1.1        ad  *	from FreeBSD: aacvar.h,v 1.1 2000/09/13 03:20:34 msmith Exp
     60        1.1        ad  *	via OpenBSD: aacvar.h,v 1.2 2002/03/14 01:26:53 millert Exp
     61        1.1        ad  */
     62        1.1        ad 
     63        1.1        ad #ifndef _PCI_AACVAR_H_
     64        1.1        ad #define	_PCI_AACVAR_H_
     65        1.1        ad 
     66        1.1        ad /* Debugging */
     67        1.1        ad #ifdef AAC_DEBUG
     68        1.1        ad #define AAC_DPRINTF(mask, args) if ((aac_debug & (mask)) != 0) printf args
     69        1.1        ad #define AAC_D_INTR	0x01
     70        1.1        ad #define AAC_D_MISC	0x02
     71        1.1        ad #define AAC_D_CMD	0x04
     72        1.1        ad #define AAC_D_QUEUE	0x08
     73        1.1        ad #define AAC_D_IO	0x10
     74        1.1        ad extern int aac_debug;
     75        1.1        ad 
     76       1.11     perry #define AAC_PRINT_FIB(sc, fib)	aac_print_fib((sc), (fib), __func__)
     77        1.1        ad #else
     78        1.1        ad #define AAC_DPRINTF(mask, args)
     79        1.1        ad #define AAC_PRINT_FIB(sc, fib)
     80        1.1        ad #endif
     81        1.1        ad 
     82        1.1        ad struct aac_code_lookup {
     83        1.7  christos 	const char	*string;
     84        1.1        ad 	u_int32_t code;
     85        1.1        ad };
     86        1.1        ad 
     87        1.1        ad extern const struct	 aac_code_lookup aac_command_status_table[];
     88        1.1        ad extern const struct	 aac_code_lookup aac_container_types[];
     89        1.1        ad 
     90        1.1        ad struct aac_softc;
     91        1.1        ad 
     92        1.1        ad /*
     93        1.1        ad  * We allocate a small set of FIBs for the adapter to use to send us messages.
     94        1.1        ad  */
     95        1.1        ad #define AAC_ADAPTER_FIBS	8
     96        1.1        ad 
     97        1.1        ad /*
     98        1.9    briggs  * FIBs are allocated in page-size chunks and can grow up to the 512
     99        1.9    briggs  * limit imposed by the hardware.
    100       1.10    briggs  * XXX -- There should be some way to allocate these as-needed without
    101       1.10    briggs  *        allocating them at interrupt time.  For now, though, allocate
    102       1.10    briggs  *	  all that we'll ever need up-front.
    103        1.9    briggs  */
    104       1.10    briggs #define AAC_PREALLOCATE_FIBS(sc)	((sc)->sc_max_fibs)
    105        1.9    briggs 
    106        1.9    briggs /*
    107        1.1        ad  * Firmware messages are passed in the printf buffer.
    108        1.1        ad  */
    109        1.1        ad #define AAC_PRINTF_BUFSIZE	256
    110        1.1        ad 
    111        1.1        ad /*
    112        1.1        ad  * We wait this many seconds for the adapter to come ready if it is still
    113        1.1        ad  * booting.
    114        1.1        ad  */
    115        1.1        ad #define AAC_BOOT_TIMEOUT	(3 * 60)
    116        1.1        ad 
    117        1.1        ad /*
    118        1.1        ad  * Wait this long for a lost interrupt to get detected.
    119        1.1        ad  */
    120        1.1        ad #define AAC_WATCH_TIMEOUT	10000		/* 10000 * 1ms = 10s */
    121        1.1        ad 
    122        1.1        ad /*
    123        1.1        ad  * Timeout for immediate commands.
    124        1.1        ad  */
    125        1.1        ad #define AAC_IMMEDIATE_TIMEOUT	30
    126        1.1        ad 
    127        1.1        ad /*
    128        1.1        ad  * Delay 20ms after the qnotify in sync operations.  Experimentally deduced.
    129        1.1        ad  */
    130        1.1        ad #define AAC_SYNC_DELAY		20000
    131        1.1        ad 
    132        1.1        ad /*
    133        1.9    briggs  * sc->sc_max_sgs is the number of scatter-gather elements we can fit
    134        1.9    briggs  * in one block I/O request (64-bit or 32-bit, depending) FIB, or the
    135        1.9    briggs  * maximum number that the firmware will accept.  We subtract one to
    136        1.9    briggs  * deal with requests that do not start on an even page boundary.
    137        1.1        ad  */
    138        1.9    briggs #define	AAC_MAX_XFER(sc)	(((sc)->sc_max_sgs - 1) * PAGE_SIZE)
    139        1.1        ad 
    140        1.1        ad /*
    141        1.1        ad  * Fixed sector size.
    142        1.1        ad  */
    143        1.1        ad #define	AAC_SECTOR_SIZE		512
    144        1.1        ad 
    145        1.1        ad /*
    146        1.9    briggs  * Number of CCBs to reserve for control operations.
    147        1.1        ad  */
    148        1.9    briggs #define	AAC_NCCBS_RESERVE	8
    149        1.1        ad 
    150        1.1        ad /*
    151        1.1        ad  * Quirk listings.
    152        1.1        ad  */
    153        1.6    briggs #define AAC_QUIRK_PERC2QC	(1 << 0)	/* Dell PERC 2QC */
    154        1.6    briggs #define AAC_QUIRK_SG_64BIT	(1 << 4)	/* Use 64-bit S/G addresses */
    155        1.6    briggs #define AAC_QUIRK_4GB_WINDOW	(1 << 5)	/* Device can access host mem
    156        1.6    briggs 						 * in 2GB-4GB range */
    157        1.6    briggs #define AAC_QUIRK_NO4GB		(1 << 6)	/* Can't access host mem >2GB */
    158        1.6    briggs #define AAC_QUIRK_256FIBS	(1 << 7)	/* Can only handle 256 cmds */
    159        1.6    briggs #define AAC_QUIRK_BROKEN_MMAP	(1 << 8)	/* Broken HostPhysMemPages */
    160        1.9    briggs #define AAC_QUIRK_NEW_COMM	(1 << 11)	/* New comm. i/f supported */
    161        1.9    briggs #define AAC_QUIRK_RAW_IO	(1 << 12)	/* Raw I/O interface */
    162        1.9    briggs #define AAC_QUIRK_ARRAY_64BIT	(1 << 13)	/* 64-bit array size */
    163  1.11.10.2      yamt #define AAC_QUIRK_LBA_64BIT	(1 << 14)	/* 64-bit LBA support */
    164        1.6    briggs 
    165        1.1        ad 
    166        1.1        ad /*
    167        1.1        ad  * We gather a number of adapter-visible items into a single structure.
    168        1.1        ad  *
    169        1.2       wiz  * The ordering of this structure may be important; we copy the Linux driver:
    170        1.1        ad  *
    171        1.1        ad  * Adapter FIBs
    172        1.1        ad  * Init struct
    173        1.1        ad  * Queue headers (Comm Area)
    174        1.1        ad  * Printf buffer
    175        1.1        ad  *
    176        1.1        ad  * In addition, we add:
    177        1.1        ad  * Sync Fib
    178        1.1        ad  */
    179        1.1        ad struct aac_common {
    180        1.1        ad 	/* fibs for the controller to send us messages */
    181        1.1        ad 	struct aac_fib ac_fibs[AAC_ADAPTER_FIBS];
    182        1.1        ad 
    183        1.1        ad 	/* the init structure */
    184        1.1        ad 	struct aac_adapter_init	ac_init;
    185        1.1        ad 
    186        1.1        ad 	/* arena within which the queue structures are kept */
    187        1.1        ad 	u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + AAC_QUEUE_ALIGN];
    188        1.1        ad 
    189        1.1        ad 	/* buffer for text messages from the controller */
    190        1.1        ad 	char	ac_printf[AAC_PRINTF_BUFSIZE];
    191        1.5     perry 
    192        1.1        ad 	/* fib for synchronous commands */
    193        1.1        ad 	struct aac_fib ac_sync_fib;
    194        1.1        ad };
    195        1.1        ad 
    196        1.9    briggs struct aac_ccb;
    197        1.9    briggs 
    198        1.1        ad /*
    199        1.1        ad  * Interface operations
    200        1.1        ad  */
    201        1.1        ad struct aac_interface {
    202        1.1        ad 	int	(*aif_get_fwstatus)(struct aac_softc *);
    203        1.1        ad 	void	(*aif_qnotify)(struct aac_softc *, int);
    204        1.1        ad 	int	(*aif_get_istatus)(struct aac_softc *);
    205        1.1        ad 	void	(*aif_set_istatus)(struct aac_softc *, int);
    206        1.1        ad 	void	(*aif_set_mailbox)(struct aac_softc *, u_int32_t,
    207        1.1        ad 				   u_int32_t, u_int32_t, u_int32_t, u_int32_t);
    208        1.6    briggs 	uint32_t (*aif_get_mailbox)(struct aac_softc *, int);
    209        1.1        ad 	void	(*aif_set_interrupts)(struct aac_softc *, int);
    210        1.9    briggs 	int	(*aif_send_command)(struct aac_softc *, struct aac_ccb *);
    211        1.9    briggs 	int	(*aif_get_outb_queue)(struct aac_softc *);
    212        1.9    briggs 	void	(*aif_set_outb_queue)(struct aac_softc *, int);
    213        1.1        ad };
    214        1.1        ad 
    215        1.1        ad #define AAC_GET_FWSTATUS(sc)		((sc)->sc_if.aif_get_fwstatus(sc))
    216        1.1        ad #define AAC_QNOTIFY(sc, qbit) \
    217        1.1        ad 	((sc)->sc_if.aif_qnotify((sc), (qbit)))
    218        1.1        ad #define AAC_GET_ISTATUS(sc)		((sc)->sc_if.aif_get_istatus(sc))
    219        1.1        ad #define AAC_CLEAR_ISTATUS(sc, mask) \
    220        1.1        ad 	((sc)->sc_if.aif_set_istatus((sc), (mask)))
    221        1.1        ad #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \
    222        1.1        ad 	do {								\
    223        1.1        ad 		((sc)->sc_if.aif_set_mailbox((sc), (command), (arg0),	\
    224        1.1        ad 		    (arg1), (arg2), (arg3)));				\
    225        1.1        ad 	} while(0)
    226        1.6    briggs #define AAC_GET_MAILBOX(sc, mb)		((sc)->sc_if.aif_get_mailbox(sc, mb))
    227        1.6    briggs #define AAC_GET_MAILBOXSTATUS(sc)	(AAC_GET_MAILBOX(sc, 0))
    228        1.1        ad #define	AAC_MASK_INTERRUPTS(sc)	\
    229        1.1        ad 	((sc)->sc_if.aif_set_interrupts((sc), 0))
    230        1.1        ad #define AAC_UNMASK_INTERRUPTS(sc) \
    231        1.1        ad 	((sc)->sc_if.aif_set_interrupts((sc), 1))
    232        1.9    briggs #define AAC_SEND_COMMAND(sc, cm) \
    233        1.9    briggs 	((sc)->sc_if.aif_send_command((sc), cm))
    234        1.9    briggs #define AAC_GET_OUTB_QUEUE(sc) \
    235        1.9    briggs 	((sc)->sc_if.aif_get_outb_queue((sc)))
    236        1.9    briggs #define AAC_SET_OUTB_QUEUE(sc, idx) \
    237        1.9    briggs 	((sc)->sc_if.aif_set_outb_queue((sc), (idx)))
    238        1.1        ad 
    239        1.1        ad #define AAC_SETREG4(sc, reg, val) \
    240        1.1        ad 	bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (reg), (val))
    241        1.1        ad #define AAC_GETREG4(sc, reg) \
    242        1.1        ad 	bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (reg))
    243        1.1        ad #define AAC_SETREG2(sc, reg, val) \
    244        1.1        ad 	bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (reg), (val))
    245        1.1        ad #define AAC_GETREG2(sc, reg) \
    246        1.1        ad 	bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (reg))
    247        1.1        ad #define AAC_SETREG1(sc, reg, val) \
    248        1.1        ad 	bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (reg), (val))
    249        1.1        ad #define AAC_GETREG1(sc, reg) \
    250        1.1        ad 	bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (reg))
    251        1.1        ad 
    252        1.9    briggs struct aac_fibmap {
    253        1.9    briggs 	TAILQ_ENTRY(aac_fibmap)	fm_link;
    254        1.9    briggs 	struct aac_fib		*fm_fibs;
    255        1.9    briggs 	bus_dma_segment_t	fm_fibseg;
    256        1.9    briggs 	bus_dmamap_t		fm_fibmap;
    257        1.9    briggs 	struct aac_ccb		*fm_ccbs;
    258        1.9    briggs };
    259        1.1        ad 
    260        1.1        ad /*
    261        1.9    briggs  * A command control block, one for each corresponding command index
    262        1.9    briggs  * of the controller.
    263        1.1        ad  */
    264        1.1        ad struct aac_ccb {
    265        1.1        ad 	SIMPLEQ_ENTRY(aac_ccb)	ac_chain;
    266        1.1        ad 
    267        1.1        ad 	struct aac_fib		*ac_fib;
    268        1.9    briggs 	struct aac_fibmap	*ac_fibmap;
    269        1.1        ad 	bus_addr_t		ac_fibphys;
    270        1.1        ad 	bus_dmamap_t		ac_dmamap_xfer;
    271        1.1        ad 
    272        1.1        ad 	void			*ac_data;
    273        1.1        ad 	size_t			ac_datalen;
    274        1.1        ad 	u_int			ac_flags;
    275        1.1        ad 
    276        1.1        ad 	void			(*ac_intr)(struct aac_ccb *);
    277        1.1        ad 	struct device		*ac_device;
    278        1.1        ad 	void			*ac_context;
    279        1.1        ad };
    280        1.1        ad #define AAC_CCB_MAPPED	 	0x01
    281        1.1        ad #define AAC_CCB_COMPLETED 	0x02
    282        1.1        ad #define AAC_CCB_DATA_IN		0x04
    283        1.1        ad #define AAC_CCB_DATA_OUT	0x08
    284        1.1        ad 
    285        1.1        ad struct aac_drive {
    286        1.1        ad 	u_int	hd_present;
    287        1.1        ad 	u_int	hd_devtype;
    288  1.11.10.2      yamt 	u_int64_t	hd_size;
    289        1.1        ad };
    290        1.1        ad 
    291        1.1        ad /*
    292        1.1        ad  * Per-controller structure.
    293        1.1        ad  */
    294        1.1        ad struct aac_softc {
    295        1.1        ad 	struct device		sc_dv;
    296        1.1        ad 	void			*sc_ih;
    297        1.1        ad 	bus_space_tag_t		sc_memt;
    298        1.1        ad 	bus_space_handle_t	sc_memh;
    299        1.1        ad 	bus_dma_tag_t		sc_dmat;
    300        1.9    briggs 	bus_size_t		sc_regsize;
    301        1.1        ad 
    302        1.1        ad 	struct FsaRevision	sc_revision;
    303        1.1        ad 	int			sc_hwif;
    304        1.1        ad 	int			sc_quirks;
    305        1.1        ad 	struct aac_interface	sc_if;
    306        1.1        ad 
    307        1.9    briggs 	u_int32_t		sc_max_fibs;
    308        1.9    briggs 	u_int32_t		sc_max_fibs_alloc;
    309        1.9    briggs 	u_int32_t		sc_max_sectors;
    310        1.9    briggs 	u_int32_t		sc_max_fib_size;
    311        1.9    briggs 	u_int32_t		sc_max_sgs;
    312        1.9    briggs 
    313        1.9    briggs 	u_int32_t		sc_total_fibs;
    314        1.9    briggs 	TAILQ_HEAD(,aac_fibmap)	sc_fibmap_tqh;
    315        1.9    briggs 
    316        1.1        ad 	struct aac_common	*sc_common;
    317        1.1        ad 	bus_dma_segment_t	sc_common_seg;
    318        1.1        ad 	bus_dmamap_t		sc_common_dmamap;
    319        1.9    briggs 	struct aac_fib		*sc_aif_fib;
    320        1.1        ad 
    321        1.1        ad 	struct aac_ccb		*sc_ccbs;
    322        1.1        ad 	SIMPLEQ_HEAD(, aac_ccb)	sc_ccb_free;
    323        1.1        ad 	SIMPLEQ_HEAD(, aac_ccb)	sc_ccb_queue;
    324        1.1        ad 	SIMPLEQ_HEAD(, aac_ccb)	sc_ccb_complete;
    325        1.1        ad 
    326        1.1        ad 	struct aac_queue_table	*sc_queues;
    327        1.1        ad 	struct aac_queue_entry	*sc_qentries[AAC_QUEUE_COUNT];
    328        1.1        ad 	struct aac_drive	sc_hdr[AAC_MAX_CONTAINERS];
    329        1.1        ad 	int			sc_nunits;
    330        1.1        ad 	int			sc_flags;
    331        1.6    briggs 	uint32_t		sc_supported_options;
    332        1.9    briggs 
    333        1.9    briggs 	/* Set by parent */
    334        1.9    briggs 	int			(*sc_intr_set)(struct aac_softc *,
    335        1.9    briggs 						int (*)(void *), void *);
    336        1.1        ad };
    337        1.1        ad #define AAC_HWIF_I960RX		0
    338        1.1        ad #define AAC_HWIF_STRONGARM	1
    339        1.9    briggs #define AAC_HWIF_FALCON		2
    340        1.9    briggs #define AAC_HWIF_RKT		3
    341        1.9    briggs #define AAC_HWIF_UNKNOWN	-1
    342        1.1        ad 
    343        1.1        ad #define	AAC_ONLINE		2
    344        1.1        ad 
    345        1.1        ad struct aac_attach_args {
    346        1.1        ad 	int		aaca_unit;
    347        1.1        ad };
    348        1.1        ad 
    349        1.1        ad int	aac_attach(struct aac_softc *);
    350        1.1        ad void	aac_ccb_enqueue(struct aac_softc *, struct aac_ccb *);
    351        1.1        ad void	aac_ccb_free(struct aac_softc *, struct aac_ccb *);
    352        1.1        ad struct aac_ccb *aac_ccb_alloc(struct aac_softc *, int);
    353        1.1        ad int	aac_ccb_map(struct aac_softc *, struct aac_ccb *);
    354        1.1        ad int	aac_ccb_poll(struct aac_softc *, struct aac_ccb *, int);
    355        1.1        ad int	aac_ccb_submit(struct aac_softc *, struct aac_ccb *);
    356        1.1        ad void	aac_ccb_unmap(struct aac_softc *, struct aac_ccb *);
    357        1.1        ad const char	*aac_describe_code(const struct aac_code_lookup *, u_int32_t);
    358        1.1        ad int	aac_intr(void *);
    359        1.1        ad 
    360        1.1        ad #endif	/* !_PCI_AACVAR_H_ */
    361