Home | History | Annotate | Line # | Download | only in ic
bhavar.h revision 1.21.22.1
      1  1.21.22.1    skrll /*	$NetBSD: bhavar.h,v 1.21.22.1 2004/08/25 06:57:35 skrll Exp $	*/
      2       1.10  thorpej 
      3       1.10  thorpej /*-
      4       1.20   bouyer  * 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.21.22.1    skrll #ifndef _DEV_IC_BHAVAR_H_
     41  1.21.22.1    skrll #define	_DEV_IC_BHAVAR_H_
     42  1.21.22.1    skrll 
     43        1.9  thorpej #include <sys/queue.h>
     44        1.9  thorpej 
     45       1.20   bouyer /* XXX adjust hash for large numbers of CCBs */
     46        1.1  mycroft #define	CCB_HASH_SIZE	32	/* hash table size for phystokv */
     47        1.1  mycroft #define	CCB_HASH_SHIFT	9
     48        1.1  mycroft #define CCB_HASH(x)	((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1))
     49        1.1  mycroft 
     50       1.20   bouyer /*
     51       1.20   bouyer  * A CCB allocation group.  Each group is a page size.  We can find
     52       1.20   bouyer  * the allocation group for a CCB by truncating the CCB address to
     53       1.20   bouyer  * a page boundary, and the offset from the group's DMA mapping
     54       1.20   bouyer  * by taking the offset of the CCB into the page.
     55       1.20   bouyer  */
     56       1.20   bouyer #define	BHA_CCBS_PER_GROUP	((PAGE_SIZE - sizeof(bus_dmamap_t)) /	\
     57       1.20   bouyer 				 sizeof(struct bha_ccb))
     58       1.20   bouyer struct bha_ccb_group {
     59       1.20   bouyer 	bus_dmamap_t bcg_dmamap;
     60       1.20   bouyer 	struct bha_ccb bcg_ccbs[1];	/* determined at run-time */
     61        1.1  mycroft };
     62        1.1  mycroft 
     63       1.20   bouyer #define	BHA_CCB_GROUP(ccb)						\
     64       1.20   bouyer 	(struct bha_ccb_group *)(trunc_page((vaddr_t)ccb))
     65       1.20   bouyer #define	BHA_CCB_OFFSET(ccb)	((vaddr_t)(ccb) & PAGE_MASK)
     66       1.20   bouyer 
     67       1.20   bouyer #define	BHA_CCB_SYNC(sc, ccb, ops)					\
     68       1.20   bouyer do {									\
     69       1.20   bouyer 	struct bha_ccb_group *bcg = BHA_CCB_GROUP((ccb));		\
     70       1.20   bouyer 									\
     71       1.20   bouyer 	bus_dmamap_sync((sc)->sc_dmat, bcg->bcg_dmamap,			\
     72       1.20   bouyer 	    BHA_CCB_OFFSET(ccb), sizeof(struct bha_ccb), (ops));	\
     73       1.20   bouyer } while (0)
     74       1.20   bouyer 
     75       1.20   bouyer /*
     76       1.20   bouyer  * Offset in the DMA mapping for mailboxes.
     77       1.20   bouyer  * Since all mailboxes are allocated on a single DMA'able memory
     78       1.20   bouyer  * due to the hardware limitation, an offset of any mailboxes can be
     79       1.20   bouyer  * calculated using same expression.
     80       1.20   bouyer  */
     81       1.20   bouyer #define	BHA_MBX_OFFSET(sc, mbx)	((u_long)(mbx) - (u_long)(sc)->sc_mbo)
     82       1.20   bouyer 
     83       1.20   bouyer #define	BHA_MBI_SYNC(sc, mbi, ops)					\
     84       1.20   bouyer do {									\
     85       1.20   bouyer 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox,		\
     86       1.20   bouyer 	    BHA_MBX_OFFSET((sc), (mbi)), sizeof(struct bha_mbx_in), (ops)); \
     87       1.20   bouyer } while (0)
     88       1.20   bouyer 
     89       1.20   bouyer #define	BHA_MBO_SYNC(sc, mbo, ops)					\
     90       1.20   bouyer do {									\
     91       1.20   bouyer 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox,		\
     92       1.20   bouyer 	    BHA_MBX_OFFSET((sc), (mbo)), sizeof(struct bha_mbx_out), (ops)); \
     93       1.20   bouyer } while (0)
     94       1.10  thorpej 
     95        1.1  mycroft struct bha_softc {
     96        1.1  mycroft 	struct device sc_dev;
     97        1.6  mycroft 
     98        1.3  thorpej 	bus_space_tag_t sc_iot;
     99        1.3  thorpej 	bus_space_handle_t sc_ioh;
    100        1.7  thorpej 	bus_dma_tag_t sc_dmat;
    101       1.20   bouyer 	bus_dmamap_t sc_dmamap_mbox;	/* maps the mailboxes */
    102        1.7  thorpej 	int sc_dmaflags;		/* bus-specific dma map flags */
    103        1.1  mycroft 	void *sc_ih;
    104        1.1  mycroft 
    105       1.20   bouyer 	int sc_scsi_id;			/* host adapter SCSI ID */
    106       1.20   bouyer 
    107       1.20   bouyer 	int sc_flags;
    108       1.20   bouyer #define	BHAF_WIDE		0x01	/* device is wide */
    109       1.20   bouyer #define	BHAF_DIFFERENTIAL	0x02	/* device is differential */
    110       1.20   bouyer #define	BHAF_ULTRA		0x04	/* device is ultra-scsi */
    111       1.20   bouyer #define	BHAF_TAGGED_QUEUEING	0x08	/* device supports tagged queueing */
    112       1.20   bouyer #define	BHAF_WIDE_LUN		0x10	/* device supported wide lun CCBs */
    113       1.20   bouyer #define	BHAF_STRICT_ROUND_ROBIN	0x20	/* device supports strict RR mode */
    114       1.20   bouyer 
    115       1.20   bouyer 	int sc_max_dmaseg;		/* maximum number of DMA segments */
    116       1.20   bouyer 	int sc_max_ccbs;		/* maximum number of CCBs (HW) */
    117       1.20   bouyer 	int sc_cur_ccbs;		/* current number of CCBs */
    118       1.20   bouyer 
    119       1.20   bouyer 	int sc_disc_mask;		/* mask of targets allowing discnnct */
    120       1.20   bouyer 	int sc_ultra_mask;		/* mask of targets allowing ultra */
    121       1.20   bouyer 	int sc_fast_mask;		/* mask of targets allowing fast */
    122       1.20   bouyer 	int sc_sync_mask;		/* mask of targets allowing sync */
    123       1.20   bouyer 	int sc_wide_mask;		/* mask of targets allowing wide */
    124       1.20   bouyer 	int sc_tag_mask;		/* mask of targets allowing t/q'ing */
    125       1.20   bouyer 
    126       1.20   bouyer 	/*
    127       1.20   bouyer 	 * In and Out mailboxes.
    128       1.20   bouyer 	 */
    129       1.20   bouyer 	struct bha_mbx_out *sc_mbo;
    130       1.20   bouyer 	struct bha_mbx_in *sc_mbi;
    131       1.20   bouyer 
    132       1.20   bouyer 	struct bha_mbx_out *sc_cmbo;	/* Collection Mail Box out */
    133       1.20   bouyer 	struct bha_mbx_out *sc_tmbo;	/* Target Mail Box out */
    134       1.20   bouyer 
    135       1.20   bouyer 	int sc_mbox_count;		/* number of mailboxes */
    136       1.20   bouyer 	int sc_mbofull;			/* number of full Mail Box Out */
    137       1.10  thorpej 
    138       1.20   bouyer 	struct bha_mbx_in *sc_tmbi;	/* Target Mail Box in */
    139       1.10  thorpej 
    140        1.1  mycroft 	struct bha_ccb *sc_ccbhash[CCB_HASH_SIZE];
    141       1.20   bouyer 	TAILQ_HEAD(, bha_ccb)	sc_free_ccb,
    142       1.20   bouyer 				sc_waiting_ccb,
    143       1.20   bouyer 				sc_allocating_ccbs;
    144       1.20   bouyer 
    145       1.12  thorpej 	struct scsipi_adapter sc_adapter;
    146       1.20   bouyer 	struct scsipi_channel sc_channel;
    147        1.6  mycroft 
    148        1.6  mycroft 	char sc_model[7],
    149        1.6  mycroft 	     sc_firmware[6];
    150        1.6  mycroft };
    151       1.10  thorpej 
    152        1.6  mycroft struct bha_probe_data {
    153        1.6  mycroft 	int sc_irq, sc_drq;
    154        1.1  mycroft };
    155        1.1  mycroft 
    156  1.21.22.1    skrll int	bha_find(bus_space_tag_t, bus_space_handle_t);
    157  1.21.22.1    skrll int	bha_inquire_config(bus_space_tag_t, bus_space_handle_t,
    158  1.21.22.1    skrll 	    struct bha_probe_data *);
    159  1.21.22.1    skrll void	bha_attach(struct bha_softc *);
    160  1.21.22.1    skrll int	bha_info(struct bha_softc *);
    161  1.21.22.1    skrll int	bha_intr(void *);
    162  1.21.22.1    skrll 
    163  1.21.22.1    skrll int	bha_disable_isacompat(struct bha_softc *);
    164  1.21.22.1    skrll int	bha_probe_inquiry(bus_space_tag_t, bus_space_handle_t,
    165  1.21.22.1    skrll 	    struct bha_probe_data *);
    166  1.21.22.1    skrll 
    167  1.21.22.1    skrll #endif /* _DEV_IC_BHAVAR_H_ */
    168