Home | History | Annotate | Line # | Download | only in ic
bhavar.h revision 1.16
      1  1.16    kleink /*	$NetBSD: bhavar.h,v 1.16 2000/03/26 20:42:44 kleink Exp $	*/
      2  1.10   thorpej 
      3  1.10   thorpej /*-
      4  1.14   thorpej  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
      5  1.10   thorpej  * All rights reserved.
      6  1.10   thorpej  *
      7  1.10   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11   mycroft  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
      9  1.11   mycroft  * Simulation Facility, NASA Ames Research Center.
     10  1.10   thorpej  *
     11  1.10   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.10   thorpej  * modification, are permitted provided that the following conditions
     13  1.10   thorpej  * are met:
     14  1.10   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.10   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.10   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.10   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.10   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.10   thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.10   thorpej  *    must display the following acknowledgement:
     21  1.10   thorpej  *	This product includes software developed by the NetBSD
     22  1.10   thorpej  *	Foundation, Inc. and its contributors.
     23  1.10   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.10   thorpej  *    contributors may be used to endorse or promote products derived
     25  1.10   thorpej  *    from this software without specific prior written permission.
     26  1.10   thorpej  *
     27  1.10   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.10   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.10   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.10   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.10   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.10   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.10   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.10   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.10   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.10   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.10   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38   1.2   mycroft  */
     39   1.2   mycroft 
     40   1.9   thorpej #include <sys/queue.h>
     41   1.9   thorpej 
     42  1.14   thorpej /* XXX adjust hash for large numbers of CCBs */
     43   1.1   mycroft #define	CCB_HASH_SIZE	32	/* hash table size for phystokv */
     44   1.1   mycroft #define	CCB_HASH_SHIFT	9
     45   1.1   mycroft #define CCB_HASH(x)	((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1))
     46   1.1   mycroft 
     47  1.14   thorpej /*
     48  1.14   thorpej  * A CCB allocation group.  Each group is a page size.  We can find
     49  1.14   thorpej  * the allocation group for a CCB by truncating the CCB address to
     50  1.14   thorpej  * a page boundary, and the offset from the group's DMA mapping
     51  1.14   thorpej  * by taking the offset of the CCB into the page.
     52  1.14   thorpej  */
     53  1.14   thorpej #define	BHA_CCBS_PER_GROUP	((PAGE_SIZE - sizeof(bus_dmamap_t)) /	\
     54  1.14   thorpej 				 sizeof(struct bha_ccb))
     55  1.14   thorpej struct bha_ccb_group {
     56  1.14   thorpej 	bus_dmamap_t bcg_dmamap;
     57  1.14   thorpej 	struct bha_ccb bcg_ccbs[1];	/* determined at run-time */
     58   1.1   mycroft };
     59   1.1   mycroft 
     60  1.16    kleink #define	BHA_CCB_GROUP(ccb)	(struct bha_ccb_group *)(trunc_page((vaddr_t)ccb))
     61  1.14   thorpej #define	BHA_CCB_OFFSET(ccb)	((vaddr_t)(ccb) & PAGE_MASK)
     62  1.14   thorpej 
     63  1.14   thorpej #define	BHA_CCB_SYNC(sc, ccb, ops)					\
     64  1.14   thorpej do {									\
     65  1.14   thorpej 	struct bha_ccb_group *bcg = BHA_CCB_GROUP((ccb));		\
     66  1.14   thorpej 									\
     67  1.14   thorpej 	bus_dmamap_sync((sc)->sc_dmat, bcg->bcg_dmamap,			\
     68  1.14   thorpej 	    BHA_CCB_OFFSET(ccb), sizeof(struct bha_ccb), (ops));	\
     69  1.14   thorpej } while (0)
     70  1.14   thorpej 
     71  1.14   thorpej #define	BHA_MBI_OFFSET(sc, mbi)	((u_long)(mbi) - (u_long)(sc)->sc_mbi)
     72  1.14   thorpej #define	BHA_MBO_OFFSET(sc, mbo)	((u_long)(mbo) - (u_long)(sc)->sc_mbo)
     73  1.14   thorpej 
     74  1.14   thorpej #define	BHA_MBI_SYNC(sc, mbi, ops)					\
     75  1.14   thorpej do {									\
     76  1.14   thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox,		\
     77  1.14   thorpej 	    BHA_MBI_OFFSET((sc), (mbi)), sizeof(struct bha_mbx_in), (ops)); \
     78  1.14   thorpej } while (0)
     79  1.14   thorpej 
     80  1.14   thorpej #define	BHA_MBO_SYNC(sc, mbo, ops)					\
     81  1.14   thorpej do {									\
     82  1.14   thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox,		\
     83  1.14   thorpej 	    BHA_MBO_OFFSET((sc), (mbo)), sizeof(struct bha_mbx_out), (ops)); \
     84  1.14   thorpej } while (0)
     85  1.10   thorpej 
     86   1.1   mycroft struct bha_softc {
     87   1.1   mycroft 	struct device sc_dev;
     88   1.6   mycroft 
     89   1.3   thorpej 	bus_space_tag_t sc_iot;
     90   1.3   thorpej 	bus_space_handle_t sc_ioh;
     91   1.7   thorpej 	bus_dma_tag_t sc_dmat;
     92  1.14   thorpej 	bus_dmamap_t sc_dmamap_mbox;	/* maps the mailboxes */
     93   1.7   thorpej 	int sc_dmaflags;		/* bus-specific dma map flags */
     94   1.1   mycroft 	void *sc_ih;
     95   1.1   mycroft 
     96  1.14   thorpej 	int sc_scsi_id;			/* host adapter SCSI ID */
     97  1.14   thorpej 
     98  1.14   thorpej 	int sc_flags;
     99  1.14   thorpej #define	BHAF_WIDE		0x01	/* device is wide */
    100  1.14   thorpej #define	BHAF_DIFFERENTIAL	0x02	/* device is differential */
    101  1.14   thorpej #define	BHAF_ULTRA		0x04	/* device is ultra-scsi */
    102  1.14   thorpej #define	BHAF_TAGGED_QUEUEING	0x08	/* device supports tagged queueing */
    103  1.14   thorpej #define	BHAF_WIDE_LUN		0x10	/* device supported wide lun CCBs */
    104  1.14   thorpej #define	BHAF_STRICT_ROUND_ROBIN	0x20	/* device supports strict RR mode */
    105  1.14   thorpej 
    106  1.14   thorpej 	int sc_max_dmaseg;		/* maximum number of DMA segments */
    107  1.14   thorpej 	int sc_hw_ccbs;			/* maximum number of CCBs (HW) */
    108  1.14   thorpej 	int sc_max_ccbs;		/* maximum number of CCBs (SW) */
    109  1.14   thorpej 	int sc_cur_ccbs;		/* current number of CCBs */
    110  1.14   thorpej 	int sc_mbox_count;		/* maximum number of mailboxes */
    111  1.14   thorpej 
    112  1.14   thorpej 	int sc_disc_mask;		/* mask of targets allowing discnnct */
    113  1.14   thorpej 	int sc_ultra_mask;		/* mask of targets allowing ultra */
    114  1.14   thorpej 	int sc_fast_mask;		/* mask of targets allowing fast */
    115  1.14   thorpej 	int sc_sync_mask;		/* mask of targets allowing sync */
    116  1.14   thorpej 	int sc_wide_mask;		/* mask of targets allowing wide */
    117  1.14   thorpej 	int sc_tag_mask;		/* mask of targets allowing t/q'ing */
    118  1.14   thorpej 
    119  1.14   thorpej 	/*
    120  1.14   thorpej 	 * In and Out mailboxes.
    121  1.14   thorpej 	 */
    122  1.14   thorpej 	struct bha_mbx_out *sc_mbo;
    123  1.14   thorpej 	struct bha_mbx_in *sc_mbi;
    124  1.14   thorpej 
    125  1.14   thorpej 	struct bha_mbx_out *sc_cmbo;	/* Collection Mail Box out */
    126  1.14   thorpej 	struct bha_mbx_out *sc_tmbo;	/* Target Mail Box out */
    127  1.10   thorpej 
    128  1.14   thorpej 	int sc_mbofull;			/* number of full Mail Box Out */
    129  1.14   thorpej 
    130  1.14   thorpej 	struct bha_mbx_in *sc_tmbi;	/* Target Mail Box in */
    131  1.10   thorpej 
    132   1.1   mycroft 	struct bha_ccb *sc_ccbhash[CCB_HASH_SIZE];
    133  1.14   thorpej 	TAILQ_HEAD(, bha_ccb)	sc_free_ccb,
    134  1.14   thorpej 				sc_waiting_ccb,
    135  1.14   thorpej 				sc_allocating_ccbs;
    136   1.8    bouyer 	struct scsipi_link sc_link;	/* prototype for devs */
    137  1.12   thorpej 	struct scsipi_adapter sc_adapter;
    138   1.9   thorpej 
    139  1.13   thorpej 	TAILQ_HEAD(, scsipi_xfer) sc_queue;
    140   1.6   mycroft 
    141   1.6   mycroft 	char sc_model[7],
    142   1.6   mycroft 	     sc_firmware[6];
    143   1.6   mycroft };
    144  1.10   thorpej 
    145   1.6   mycroft struct bha_probe_data {
    146   1.6   mycroft 	int sc_irq, sc_drq;
    147   1.1   mycroft };
    148   1.1   mycroft 
    149   1.3   thorpej int	bha_find __P((bus_space_tag_t, bus_space_handle_t,
    150   1.6   mycroft 	    struct bha_probe_data *));
    151   1.6   mycroft void	bha_attach __P((struct bha_softc *, struct bha_probe_data *));
    152  1.15   thorpej int	bha_info __P((struct bha_softc *));
    153   1.1   mycroft int	bha_intr __P((void *));
    154   1.4  jonathan 
    155   1.4  jonathan int	bha_disable_isacompat __P((struct bha_softc *));
    156