1 /* $NetBSD: ninjascsi32var.h,v 1.5 2008/04/28 20:23:50 martin Exp $ */
4 * Copyright (c) 2004, 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 typedef unsigned njsc32_model_t
;
36 #define NJSC32_MODEL_MASK 0xff
37 #define NJSC32_MODEL_INVALID 0
38 #define NJSC32_MODEL_32BI 1
39 #define NJSC32_MODEL_32UDE 2
40 #define NJSC32_FLAG_DUALEDGE 0x100 /* supports DualEdge */
43 * time parameters (25us per unit?)
45 #define NJSC32_SEL_TIMEOUT_TIME 20000 /* selection timeout (500ms) */
46 #define NJSC32_ARBITRATION_RETRY_TIME 4 /* 100us */
49 #define NJSC32_REQ_TIMEOUT 10000 /* 10ms */
50 #define NJSC32_RESET_HOLD_TIME 26 /* 25us min */
55 #ifdef NJSC32_AUTOPARAM
56 #define NJSC32_NUM_CMD 14 /* # simultaneous commands */
58 #define NJSC32_NUM_CMD 15 /* # simultaneous commands */
60 #define NJSC32_NUM_SG 17 /* # scatter/gather table entries per command */
62 struct njsc32_dma_page
{
64 * scatter/gather transfer table
66 struct njsc32_sgtable dp_sg
[NJSC32_NUM_CMD
][NJSC32_NUM_SG
];
67 #define NJSC32_SIZE_SGT \
68 (sizeof(struct njsc32_sgtable) * NJSC32_NUM_SG)
70 #ifdef NJSC32_AUTOPARAM
72 * device reads parameters from this structure (autoparam)
74 struct njsc32_autoparam dp_ap
;
80 TAILQ_ENTRY(njsc32_cmd
) c_q
;
81 struct njsc32_softc
*c_sc
;
84 struct scsipi_xfer
*c_xs
;
85 struct njsc32_target
*c_target
;
86 struct njsc32_lu
*c_lu
;
87 u_int32_t c_datacnt
; /* I/O buffer length */
91 #define NJSC32_CMD_DMA_MAPPED 0x01
92 #define NJSC32_CMD_TAGGED 0x02
93 #define NJSC32_CMD_TAGGED_HEAD 0x04
96 u_int32_t c_dp_cur
; /* current (or active) data pointer */
97 u_int32_t c_dp_saved
; /* saved data pointer */
98 u_int32_t c_dp_max
; /* max value of data pointer */
100 /* last loaded scatter/gather table */
101 unsigned c_sgoffset
; /* # skip entries */
102 u_int32_t c_sgfixcnt
; /* # skip bytes in the top entry */
104 /* command start/restart parameter */
105 u_int8_t c_msg_identify
; /* Identify message */
107 u_int32_t c_sgtdmaaddr
;
110 struct njsc32_sgtable
*c_sgt
; /* for host */
111 bus_addr_t c_sgt_dma
; /* for device */
112 #define NJSC32_CMD_DMAADDR_SGT(cmd, n) \
113 ((cmd)->c_sgt_dma + sizeof(struct njsc32_sgtable) * (n))
114 bus_dmamap_t c_dmamap_xfer
;
117 /* -1 for unaligned acccess */
118 #define NJSC32_MAX_XFER ((NJSC32_NUM_SG - 1) << PGSHIFT)
120 struct njsc32_softc
{
124 njsc32_model_t sc_model
;
126 int sc_clk
; /* one of following */
127 #define NJSC32_CLK_40M NJSC32_CLOCK_DIV_4 /* 20MB/s */
128 #define NJSC32_CLK_20M NJSC32_CLOCK_DIV_2 /* 10MB/s */
129 #define NJSC32_CLK_PCI_33M NJSC32_CLOCK_PCICLK /* 16.6MB/s */
131 /* device register */
132 bus_space_tag_t sc_regt
;
133 bus_space_handle_t sc_regh
;
136 #define NJSC32_IO_MAPPED 0x00000001
137 #define NJSC32_MEM_MAPPED 0x00000002
138 #define NJSC32_CMDPG_MAPPED 0x00000004
139 #define NJSC32_CANNOT_SUPPLY_TERMPWR 0x00000100
146 NJSC32_STAT_ARBIT
, /* initiator started arbitration */
147 NJSC32_STAT_CONNECT
, /* command is active (connection) */
148 NJSC32_STAT_RESEL
, /* a target did Reselection */
149 NJSC32_STAT_RESEL_LUN
, /* received Identify message */
150 NJSC32_STAT_RECONNECT
, /* command is active (reconnection) */
151 NJSC32_STAT_RESET
, /* resetting bus */
152 NJSC32_STAT_RESET1
, /* waiting for bus reset release */
153 NJSC32_STAT_RESET2
, /* waiting for bus reset release */
154 NJSC32_STAT_DETACH
/* detaching */
157 /* interrupt handle */
161 bus_dma_tag_t sc_dmat
;
162 struct njsc32_dma_page
*sc_cmdpg
; /* scatter/gather table page */
164 bus_addr_t sc_cmdpg_dma
;
166 bus_dma_segment_t sc_cmdpg_seg
;
167 bus_dmamap_t sc_dmamap_cmdpg
;
170 #ifdef NJSC32_AUTOPARAM
171 u_int32_t sc_ap_dma
; /* autoparam DMA address */
174 /* for monitoring bus reset */
175 struct callout sc_callout
;
178 * command control structure
180 struct njsc32_cmd sc_cmds
[NJSC32_NUM_CMD
];
181 TAILQ_HEAD(njsc32_cmd_head
, njsc32_cmd
)
182 sc_freecmd
, /* free list */
183 sc_reqcmd
; /* waiting commands */
185 struct njsc32_cmd
*sc_curcmd
; /* currently active command */
186 int sc_ncmd
; /* total # commands available */
187 int sc_nusedcmds
; /* # used commands */
190 int sc_reselid
, sc_resellun
;
192 /* message in buffer */
193 #define NJSC32_MSGIN_LEN 20
194 u_int8_t sc_msginbuf
[NJSC32_MSGIN_LEN
];
197 /* message out buffer */
198 #define NJSC32_MSGOUT_LEN 16
199 u_int8_t sc_msgout
[NJSC32_MSGOUT_LEN
];
203 /* sync timing table */
204 const struct njsc32_sync_param
{
205 u_int8_t sp_period
; /* transfer period */
206 u_int8_t sp_ackw
; /* ACK width parameter */
207 u_int8_t sp_sample
; /* sampling period */
211 /* for scsipi layer */
212 struct device
*sc_scsi
;
213 struct scsipi_adapter sc_adapter
;
214 struct scsipi_channel sc_channel
;
217 struct njsc32_target
{
219 NJSC32_TARST_DONE
, /* negotiation done */
221 NJSC32_TARST_DE
, /* negotiating DualEdge */
222 NJSC32_TARST_WDTR
, /* negotiating width */
223 NJSC32_TARST_SDTR
, /* negotiating sync */
224 NJSC32_TARST_ASYNC
/* negotiating async */
227 #define NJSC32_TARF_TAG 0x0001 /* tagged queueing is enabled */
228 #define NJSC32_TARF_SYNC 0x0002 /* negotiate for sync transfer */
229 #define NJSC32_TARF_DE 0x0004 /* negotiate for DualEdge transfer */
236 u_int8_t t_targetid
; /* initiator and target id */
239 u_int16_t t_xferctl
; /* DualEdge flag */
241 /* per logical unit */
244 * disconnected commands
246 struct njsc32_cmd
*lu_cmd
; /* untagged command */
247 struct njsc32_cmd_head lu_q
; /* tagged commands */
249 } sc_targets
[NJSC32_MAX_TARGET_ID
+ 1];
253 void njsc32_attach(struct njsc32_softc
*);
254 int njsc32_detach(struct njsc32_softc
*, int);
255 int njsc32_intr(void *);
258 #endif /* _NJSC32VAR_H_ */