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