ninjascsi32var.h revision 1.6 1 1.6 joerg /* $NetBSD: ninjascsi32var.h,v 1.6 2008/07/09 19:08:44 joerg Exp $ */
2 1.1 itohy
3 1.1 itohy /*-
4 1.4 itohy * Copyright (c) 2004, 2007 The NetBSD Foundation, Inc.
5 1.1 itohy * All rights reserved.
6 1.1 itohy *
7 1.1 itohy * This code is derived from software contributed to The NetBSD Foundation
8 1.1 itohy * by ITOH Yasufumi.
9 1.1 itohy *
10 1.1 itohy * Redistribution and use in source and binary forms, with or without
11 1.1 itohy * modification, are permitted provided that the following conditions
12 1.1 itohy * are met:
13 1.1 itohy * 1. Redistributions of source code must retain the above copyright
14 1.1 itohy * notice, this list of conditions and the following disclaimer.
15 1.1 itohy * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 itohy * notice, this list of conditions and the following disclaimer in the
17 1.1 itohy * documentation and/or other materials provided with the distribution.
18 1.1 itohy *
19 1.1 itohy * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 itohy * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 itohy * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 itohy * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 itohy * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 itohy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 itohy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 itohy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 itohy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 itohy * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 itohy * POSSIBILITY OF SUCH DAMAGE.
30 1.1 itohy */
31 1.1 itohy
32 1.1 itohy #ifndef _NJSC32VAR_H_
33 1.1 itohy #define _NJSC32VAR_H_
34 1.1 itohy
35 1.1 itohy typedef unsigned njsc32_model_t;
36 1.1 itohy #define NJSC32_MODEL_MASK 0xff
37 1.1 itohy #define NJSC32_MODEL_INVALID 0
38 1.1 itohy #define NJSC32_MODEL_32BI 1
39 1.1 itohy #define NJSC32_MODEL_32UDE 2
40 1.1 itohy #define NJSC32_FLAG_DUALEDGE 0x100 /* supports DualEdge */
41 1.1 itohy
42 1.1 itohy /*
43 1.1 itohy * time parameters (25us per unit?)
44 1.1 itohy */
45 1.1 itohy #define NJSC32_SEL_TIMEOUT_TIME 20000 /* selection timeout (500ms) */
46 1.1 itohy #define NJSC32_ARBITRATION_RETRY_TIME 4 /* 100us */
47 1.1 itohy
48 1.1 itohy /* in microseconds */
49 1.1 itohy #define NJSC32_REQ_TIMEOUT 10000 /* 10ms */
50 1.4 itohy #define NJSC32_RESET_HOLD_TIME 26 /* 25us min */
51 1.1 itohy
52 1.1 itohy /*
53 1.1 itohy * DMA page
54 1.1 itohy */
55 1.1 itohy #ifdef NJSC32_AUTOPARAM
56 1.4 itohy #define NJSC32_NUM_CMD 14 /* # simultaneous commands */
57 1.4 itohy #else
58 1.1 itohy #define NJSC32_NUM_CMD 15 /* # simultaneous commands */
59 1.1 itohy #endif
60 1.4 itohy #define NJSC32_NUM_SG 17 /* # scatter/gather table entries per command */
61 1.1 itohy
62 1.1 itohy struct njsc32_dma_page {
63 1.1 itohy /*
64 1.1 itohy * scatter/gather transfer table
65 1.1 itohy */
66 1.1 itohy struct njsc32_sgtable dp_sg[NJSC32_NUM_CMD][NJSC32_NUM_SG];
67 1.1 itohy #define NJSC32_SIZE_SGT \
68 1.1 itohy (sizeof(struct njsc32_sgtable) * NJSC32_NUM_SG)
69 1.1 itohy
70 1.1 itohy #ifdef NJSC32_AUTOPARAM
71 1.1 itohy /*
72 1.1 itohy * device reads parameters from this structure (autoparam)
73 1.1 itohy */
74 1.1 itohy struct njsc32_autoparam dp_ap;
75 1.1 itohy #endif
76 1.1 itohy };
77 1.1 itohy
78 1.1 itohy /* per command */
79 1.1 itohy struct njsc32_cmd {
80 1.1 itohy TAILQ_ENTRY(njsc32_cmd) c_q;
81 1.1 itohy struct njsc32_softc *c_sc;
82 1.1 itohy
83 1.1 itohy /* on transfer */
84 1.1 itohy struct scsipi_xfer *c_xs;
85 1.1 itohy struct njsc32_target *c_target;
86 1.1 itohy struct njsc32_lu *c_lu;
87 1.1 itohy u_int32_t c_datacnt; /* I/O buffer length */
88 1.1 itohy
89 1.1 itohy /* command status */
90 1.1 itohy int c_flags;
91 1.1 itohy #define NJSC32_CMD_DMA_MAPPED 0x01
92 1.1 itohy #define NJSC32_CMD_TAGGED 0x02
93 1.1 itohy #define NJSC32_CMD_TAGGED_HEAD 0x04
94 1.1 itohy
95 1.1 itohy /* SCSI pointer */
96 1.1 itohy u_int32_t c_dp_cur; /* current (or active) data pointer */
97 1.1 itohy u_int32_t c_dp_saved; /* saved data pointer */
98 1.1 itohy u_int32_t c_dp_max; /* max value of data pointer */
99 1.1 itohy
100 1.1 itohy /* last loaded scatter/gather table */
101 1.1 itohy unsigned c_sgoffset; /* # skip entries */
102 1.1 itohy u_int32_t c_sgfixcnt; /* # skip bytes in the top entry */
103 1.1 itohy
104 1.1 itohy /* command start/restart parameter */
105 1.1 itohy u_int8_t c_msg_identify; /* Identify message */
106 1.1 itohy u_int16_t c_xferctl;
107 1.1 itohy u_int32_t c_sgtdmaaddr;
108 1.1 itohy
109 1.1 itohy /* DMA resource */
110 1.1 itohy struct njsc32_sgtable *c_sgt; /* for host */
111 1.1 itohy bus_addr_t c_sgt_dma; /* for device */
112 1.1 itohy #define NJSC32_CMD_DMAADDR_SGT(cmd, n) \
113 1.1 itohy ((cmd)->c_sgt_dma + sizeof(struct njsc32_sgtable) * (n))
114 1.1 itohy bus_dmamap_t c_dmamap_xfer;
115 1.1 itohy };
116 1.1 itohy
117 1.4 itohy /* -1 for unaligned acccess */
118 1.4 itohy #define NJSC32_MAX_XFER ((NJSC32_NUM_SG - 1) << PGSHIFT)
119 1.1 itohy
120 1.1 itohy struct njsc32_softc {
121 1.6 joerg device_t sc_dev;
122 1.1 itohy
123 1.1 itohy /* device spec */
124 1.1 itohy njsc32_model_t sc_model;
125 1.1 itohy
126 1.1 itohy int sc_clk; /* one of following */
127 1.1 itohy #define NJSC32_CLK_40M NJSC32_CLOCK_DIV_4 /* 20MB/s */
128 1.1 itohy #define NJSC32_CLK_20M NJSC32_CLOCK_DIV_2 /* 10MB/s */
129 1.1 itohy #define NJSC32_CLK_PCI_33M NJSC32_CLOCK_PCICLK /* 16.6MB/s */
130 1.1 itohy
131 1.1 itohy /* device register */
132 1.1 itohy bus_space_tag_t sc_regt;
133 1.1 itohy bus_space_handle_t sc_regh;
134 1.1 itohy
135 1.1 itohy unsigned sc_flags;
136 1.1 itohy #define NJSC32_IO_MAPPED 0x00000001
137 1.1 itohy #define NJSC32_MEM_MAPPED 0x00000002
138 1.1 itohy #define NJSC32_CMDPG_MAPPED 0x00000004
139 1.1 itohy #define NJSC32_CANNOT_SUPPLY_TERMPWR 0x00000100
140 1.1 itohy
141 1.1 itohy /*
142 1.1 itohy * controller state
143 1.1 itohy */
144 1.1 itohy enum njsc32_stat {
145 1.1 itohy NJSC32_STAT_IDLE,
146 1.1 itohy NJSC32_STAT_ARBIT, /* initiator started arbitration */
147 1.1 itohy NJSC32_STAT_CONNECT, /* command is active (connection) */
148 1.1 itohy NJSC32_STAT_RESEL, /* a target did Reselection */
149 1.1 itohy NJSC32_STAT_RESEL_LUN, /* received Identify message */
150 1.1 itohy NJSC32_STAT_RECONNECT, /* command is active (reconnection) */
151 1.4 itohy NJSC32_STAT_RESET, /* resetting bus */
152 1.4 itohy NJSC32_STAT_RESET1, /* waiting for bus reset release */
153 1.4 itohy NJSC32_STAT_RESET2, /* waiting for bus reset release */
154 1.1 itohy NJSC32_STAT_DETACH /* detaching */
155 1.1 itohy } sc_stat;
156 1.1 itohy
157 1.1 itohy /* interrupt handle */
158 1.1 itohy void *sc_ih;
159 1.1 itohy
160 1.1 itohy /* for DMA */
161 1.1 itohy bus_dma_tag_t sc_dmat;
162 1.1 itohy struct njsc32_dma_page *sc_cmdpg; /* scatter/gather table page */
163 1.1 itohy #if 0
164 1.1 itohy bus_addr_t sc_cmdpg_dma;
165 1.1 itohy #endif
166 1.1 itohy bus_dma_segment_t sc_cmdpg_seg;
167 1.1 itohy bus_dmamap_t sc_dmamap_cmdpg;
168 1.1 itohy int sc_cmdpg_nsegs;
169 1.1 itohy
170 1.1 itohy #ifdef NJSC32_AUTOPARAM
171 1.1 itohy u_int32_t sc_ap_dma; /* autoparam DMA address */
172 1.1 itohy #endif
173 1.1 itohy
174 1.4 itohy /* for monitoring bus reset */
175 1.4 itohy struct callout sc_callout;
176 1.4 itohy
177 1.1 itohy /*
178 1.1 itohy * command control structure
179 1.1 itohy */
180 1.1 itohy struct njsc32_cmd sc_cmds[NJSC32_NUM_CMD];
181 1.1 itohy TAILQ_HEAD(njsc32_cmd_head, njsc32_cmd)
182 1.1 itohy sc_freecmd, /* free list */
183 1.1 itohy sc_reqcmd; /* waiting commands */
184 1.1 itohy
185 1.1 itohy struct njsc32_cmd *sc_curcmd; /* currently active command */
186 1.1 itohy int sc_ncmd; /* total # commands available */
187 1.1 itohy int sc_nusedcmds; /* # used commands */
188 1.1 itohy
189 1.1 itohy /* reselection */
190 1.1 itohy int sc_reselid, sc_resellun;
191 1.1 itohy
192 1.1 itohy /* message in buffer */
193 1.1 itohy #define NJSC32_MSGIN_LEN 20
194 1.1 itohy u_int8_t sc_msginbuf[NJSC32_MSGIN_LEN];
195 1.1 itohy int sc_msgincnt;
196 1.1 itohy
197 1.1 itohy /* message out buffer */
198 1.1 itohy #define NJSC32_MSGOUT_LEN 16
199 1.1 itohy u_int8_t sc_msgout[NJSC32_MSGOUT_LEN];
200 1.1 itohy size_t sc_msgoutlen;
201 1.1 itohy size_t sc_msgoutidx;
202 1.1 itohy
203 1.1 itohy /* sync timing table */
204 1.1 itohy const struct njsc32_sync_param {
205 1.1 itohy u_int8_t sp_period; /* transfer period */
206 1.1 itohy u_int8_t sp_ackw; /* ACK width parameter */
207 1.1 itohy u_int8_t sp_sample; /* sampling period */
208 1.1 itohy } *sc_synct;
209 1.1 itohy int sc_sync_max;
210 1.1 itohy
211 1.1 itohy /* for scsipi layer */
212 1.1 itohy struct device *sc_scsi;
213 1.1 itohy struct scsipi_adapter sc_adapter;
214 1.1 itohy struct scsipi_channel sc_channel;
215 1.1 itohy
216 1.1 itohy /* per-target */
217 1.1 itohy struct njsc32_target {
218 1.1 itohy enum njsc32_tarst {
219 1.1 itohy NJSC32_TARST_DONE, /* negotiation done */
220 1.1 itohy NJSC32_TARST_INIT,
221 1.1 itohy NJSC32_TARST_DE, /* negotiating DualEdge */
222 1.1 itohy NJSC32_TARST_WDTR, /* negotiating width */
223 1.1 itohy NJSC32_TARST_SDTR, /* negotiating sync */
224 1.1 itohy NJSC32_TARST_ASYNC /* negotiating async */
225 1.1 itohy } t_state;
226 1.1 itohy int t_flags;
227 1.1 itohy #define NJSC32_TARF_TAG 0x0001 /* tagged queueing is enabled */
228 1.1 itohy #define NJSC32_TARF_SYNC 0x0002 /* negotiate for sync transfer */
229 1.1 itohy #define NJSC32_TARF_DE 0x0004 /* negotiate for DualEdge transfer */
230 1.1 itohy
231 1.1 itohy int t_syncperiod;
232 1.1 itohy int t_syncoffset;
233 1.1 itohy
234 1.1 itohy u_int8_t t_sync;
235 1.1 itohy u_int8_t t_ackwidth;
236 1.1 itohy u_int8_t t_targetid; /* initiator and target id */
237 1.1 itohy u_int8_t t_sample;
238 1.1 itohy
239 1.1 itohy u_int16_t t_xferctl; /* DualEdge flag */
240 1.1 itohy
241 1.1 itohy /* per logical unit */
242 1.1 itohy struct njsc32_lu {
243 1.1 itohy /*
244 1.1 itohy * disconnected commands
245 1.1 itohy */
246 1.1 itohy struct njsc32_cmd *lu_cmd; /* untagged command */
247 1.1 itohy struct njsc32_cmd_head lu_q; /* tagged commands */
248 1.1 itohy } t_lus[NJSC32_NLU];
249 1.1 itohy } sc_targets[NJSC32_MAX_TARGET_ID + 1];
250 1.1 itohy };
251 1.1 itohy
252 1.1 itohy #ifdef _KERNEL
253 1.2 thorpej void njsc32_attach(struct njsc32_softc *);
254 1.2 thorpej int njsc32_detach(struct njsc32_softc *, int);
255 1.2 thorpej int njsc32_intr(void *);
256 1.1 itohy #endif
257 1.1 itohy
258 1.1 itohy #endif /* _NJSC32VAR_H_ */
259