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