Commit | Line | Data |
---|---|---|
09d5c084 | 1 | /* |
ad787160 C |
2 | * Copyright (c) 1988, 1992, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
09d5c084 CT |
4 | * |
5 | * This software was developed by the Computer Systems Engineering group | |
6 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | |
7 | * contributed to Berkeley. | |
8 | * | |
b480239a KB |
9 | * All advertising materials mentioning features or use of this software |
10 | * must display the following acknowledgement: | |
11 | * This product includes software developed by the University of | |
1869bdc0 | 12 | * California, Lawrence Berkeley Laboratory. |
b480239a | 13 | * |
ad787160 C |
14 | * Redistribution and use in source and binary forms, with or without |
15 | * modification, are permitted provided that the following conditions | |
16 | * are met: | |
17 | * 1. Redistributions of source code must retain the above copyright | |
18 | * notice, this list of conditions and the following disclaimer. | |
19 | * 2. Redistributions in binary form must reproduce the above copyright | |
20 | * notice, this list of conditions and the following disclaimer in the | |
21 | * documentation and/or other materials provided with the distribution. | |
22 | * 3. All advertising materials mentioning features or use of this software | |
23 | * must display the following acknowledgement: | |
24 | * This product includes software developed by the University of | |
25 | * California, Berkeley and its contributors. | |
26 | * 4. Neither the name of the University nor the names of its contributors | |
27 | * may be used to endorse or promote products derived from this software | |
28 | * without specific prior written permission. | |
29 | * | |
30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
40 | * SUCH DAMAGE. | |
09d5c084 | 41 | * |
ed554bc5 | 42 | * @(#)espreg.h 8.2 (Berkeley) 12/14/93 |
09d5c084 | 43 | * |
1869bdc0 | 44 | * from: $Header: espreg.h,v 1.7 92/11/26 02:28:10 torek Exp $ (LBL) |
09d5c084 CT |
45 | * |
46 | * Derived from Mary Baker's devSCSIC90.c from the Berkeley | |
47 | * Sprite project, which is: | |
48 | * | |
49 | * Copyright 1988 Regents of the University of California | |
50 | * Permission to use, copy, modify, and distribute this | |
51 | * software and its documentation for any purpose and without | |
52 | * fee is hereby granted, provided that the above copyright | |
53 | * notice appear in all copies. The University of California | |
54 | * makes no representations about the suitability of this | |
55 | * software for any purpose. It is provided "as is" without | |
56 | * express or implied warranty. | |
57 | */ | |
58 | ||
59 | /* | |
60 | * Emulex ESP100, ESP100A, and ESP200 registers, as found on the | |
61 | * Sun-4c Sbus. | |
62 | * | |
63 | * The registers are all bytes, and all on longword boundaries. | |
64 | * Grody to the max! | |
65 | */ | |
66 | struct espreg { | |
67 | u_char esp_tcl; /* transfer count low (byte 0) (rw) */ | |
68 | u_char esp_xxx0[3]; | |
69 | u_char esp_tch; /* transfer count high (byte 1) (rw) */ | |
70 | u_char esp_xxx1[3]; | |
71 | u_char esp_fifo; /* fifo data register (rw) */ | |
72 | u_char esp_xxx2[3]; | |
73 | u_char esp_cmd; /* command (rw) */ | |
74 | u_char esp_xxx3[3]; | |
75 | u_char esp_stat; /* status (ro); scsi id (wo) */ | |
76 | #define esp_id esp_stat | |
77 | u_char esp_xxx4[3]; | |
78 | u_char esp_intr; /* interrupt (ro); timeout (wo) */ | |
79 | #define esp_timeout esp_intr | |
80 | u_char esp_xxx5[3]; | |
81 | u_char esp_step; /* sequence step (ro); sync period (wo) */ | |
82 | #define esp_syncperiod esp_step | |
83 | u_char esp_xxx6[3]; | |
84 | u_char esp_fflags; /* fifo flags (ro); sync offset (wo) */ | |
85 | #define esp_syncoff esp_fflags | |
86 | u_char esp_xxx7[3]; | |
87 | u_char esp_conf1; /* configuration #1 (rw) */ | |
88 | u_char esp_xxx8[3]; | |
89 | u_char esp_ccf; /* clock conversion factor (wo) */ | |
90 | u_char esp_xxx9[3]; | |
91 | u_char esp_test; /* test (do not use) */ | |
92 | u_char esp_xxxA[3]; | |
ea183373 | 93 | u_char esp_conf2; /* configuration #2 (rw, ESP100A/2xx) */ |
09d5c084 CT |
94 | u_char esp_xxxB[3]; |
95 | u_char esp_conf3; /* configuration #3 (rw, ESP-236) */ | |
96 | u_char esp_xxxC[3]; | |
97 | }; | |
98 | ||
99 | /* THE REST OF THESE NAMES COULD STAND TO BE SHORTENED */ | |
100 | ||
101 | /* | |
102 | * Bits in esp_cmd. Note that the cmd register is two levels deep (see | |
103 | * Emulex documentation, p. 4-3); our typical usage is to set the command, | |
104 | * then set it again with DMA. | |
105 | * | |
106 | * Targets will use disconnected and target mode commands; initiators will use | |
107 | * disconnected and initiator mode commands. Bit 0x40 indicates disconnected | |
108 | * mode, 0x20 target mode, and 0x10 initiator mode. (However, everyone can | |
109 | * use the miscellaneous commands, which have none of those bits set.) | |
110 | */ | |
111 | #define ESPCMD_DMA 0x80 /* flag => do DMA */ | |
112 | ||
113 | /* miscellaneous */ | |
114 | #define ESPCMD_NOP 0x00 /* do nothing */ | |
115 | #define ESPCMD_FLUSH_FIFO 0x01 /* flush FIFO */ | |
116 | #define ESPCMD_RESET_CHIP 0x02 /* reset ESP chip */ | |
117 | #define ESPCMD_RESET_BUS 0x03 /* reset SCSI bus */ | |
ea183373 | 118 | /* NB: fifo flush takes time, may need delay or NOP to allow completion */ |
09d5c084 CT |
119 | |
120 | /* disconnected */ | |
121 | #define ESPCMD_RESEL_SEQ 0x40 /* reselect sequence */ | |
122 | #define ESPCMD_SEL_NATN 0x41 /* select without ATN sequence */ | |
123 | #define ESPCMD_SEL_ATN 0x42 /* select with ATN sequence */ | |
124 | #define ESPCMD_SEL_ATNS 0x43 /* select with ATN & stop seq */ | |
125 | #define ESPCMD_SEL_ENA 0x44 /* enable selection/reselection */ | |
126 | #define ESPCMD_SEL_DIS 0x45 /* disable selection/reselection */ | |
127 | #define ESPCMD_SEL_ATN3 0x46 /* select with ATN3 sequence */ | |
128 | ||
129 | /* target state */ | |
130 | #define ESPCMD_SEND_MSG 0x20 /* send message */ | |
131 | #define ESPCMD_SEND_STATUS 0x21 /* send status */ | |
132 | #define ESPCMD_SEND_DATA 0x22 /* send data */ | |
133 | #define ESPCMD_DIS_SEQ 0x23 /* disconnect sequence */ | |
134 | #define ESPCMD_TERM_SEQ 0x24 /* terminate sequence */ | |
135 | #define ESPCMD_TARG_COMP 0x25 /* target command complete sequence */ | |
136 | #define ESPCMD_DISCONNECT 0x27 /* disconnect */ | |
137 | #define ESPCMD_RCV_MSG 0x28 /* receive message sequence */ | |
138 | #define ESPCMD_RCV_CMD 0x29 /* receive command */ | |
139 | #define ESPCMD_RCV_DATA 0x2a /* receive data */ | |
140 | #define ESPCMD_REC_CMD_SEQ 0x2b /* receive command sequence */ | |
141 | #define ESPCMD_STOP_DMA 0x04 /* stop DMA (see p. 4-6) */ | |
142 | /* ESPCMD_TARG_ABORT 0x06 target abort sequence */ | |
143 | ||
144 | /* initiator state */ | |
145 | #define ESPCMD_XFER_INFO 0x10 /* transfer information */ | |
146 | #define ESPCMD_INIT_COMP 0x11 /* initiator command complete seq */ | |
147 | #define ESPCMD_MSG_ACCEPT 0x12 /* message accepted */ | |
148 | #define ESPCMD_XFER_PAD 0x18 /* transfer pad (use only w/ DMA) */ | |
149 | #define ESPCMD_SET_ATN 0x1a /* set ATN */ | |
150 | #define ESPCMD_RESET_ATN 0x1b /* reset ATN */ | |
151 | ||
152 | /* | |
153 | * Bits in esp_stat. | |
154 | * Bits 3 through 7 are latched until esp_intr is read; | |
155 | * bits 0 through 2 (the phase) are not normally latched. | |
156 | * The interrupt bit is set even if interrupts are disabled. | |
157 | * Hardware or software reset, or reading esp_intr, will | |
158 | * clear the interrupt and turn off ESPSTAT_INT. | |
159 | */ | |
160 | #ifdef notdef | |
161 | #define ESPSTAT_INT 0x80 /* ASC interrupting processor */ | |
162 | #else | |
163 | #define ESPSTAT_XXX 0x80 /* rumored unreliable: use dma IP */ | |
164 | #endif | |
165 | #define ESPSTAT_GE 0x40 /* gross error */ | |
166 | #define ESPSTAT_PE 0x20 /* parity error */ | |
167 | #define ESPSTAT_ERR 0x60 /* pseudo composite */ | |
168 | #define ESPSTAT_TC 0x10 /* terminal count */ | |
169 | #define ESPSTAT_VGC 0x08 /* valid group code */ | |
170 | #define ESPSTAT_MSG 0x04 /* MSG line from SCSI bus */ | |
171 | #define ESPSTAT_CD 0x02 /* CD line from SCSI bus */ | |
172 | #define ESPSTAT_IO 0x01 /* IO line from SCSI bus */ | |
173 | #define ESPSTAT_PHASE 7 /* phase mask */ | |
174 | #define ESPPHASE_DATA_OUT 0 /* data out */ | |
175 | #define ESPPHASE_DATA_IN 1 /* data in */ | |
176 | #define ESPPHASE_CMD 2 /* command */ | |
177 | #define ESPPHASE_STATUS 3 /* status */ | |
178 | #define ESPPHASE_MSG_OUT 6 /* message out (w.r.t. initiator) */ | |
179 | #define ESPPHASE_MSG_IN 7 /* message in */ | |
180 | ||
181 | #ifdef ESP_PHASE_NAMES | |
182 | /* printed as `... during %s phase' */ | |
183 | char *espphases[] = | |
184 | { "data out", "data in", "command", "status", | |
185 | "impossible(4)", "impossible(5)", "message out", "message in" }; | |
186 | #endif | |
187 | ||
188 | #define ESPSTAT_BITS "\20\10INT\7GE\6PE\5TC\4VGC\3MSG\2CD\1IO" | |
189 | ||
190 | /* | |
191 | * Bits in esp_intr. | |
192 | */ | |
193 | #define ESPINTR_SBR 0x80 /* SCSI bus reset detected */ | |
194 | #define ESPINTR_ILC 0x40 /* illegal command */ | |
195 | #define ESPINTR_DSC 0x20 /* target disconnected, or timeout */ | |
196 | #define ESPINTR_SVC 0x10 /* a device wants bus service */ | |
197 | #define ESPINTR_CMP 0x08 /* function complete */ | |
198 | #define ESPINTR_RSL 0x04 /* reselected */ | |
199 | #define ESPINTR_SAT 0x02 /* selected with ATN */ | |
200 | #define ESPINTR_SEL 0x01 /* selected (no ATN) */ | |
201 | ||
202 | #define ESPINTR_BITS "\20\10SBR\7ILC\6DSC\5SVC\4CMP\3RSL\2SAT\1SEL" | |
203 | ||
204 | /* | |
205 | * Formula for select/reselect timeout (esp_timeout). | |
206 | * TU = 7682 * CCF * TCP | |
207 | * T / TU = register value | |
208 | * CCF = clock conversion factor | |
209 | * TCP = input clock period (in same units as T) | |
210 | * TU = time unit (i.e., the esp_timeout register counts in TUs) | |
211 | * T = desired timeout | |
212 | * (i.e., we want ceil(timeout / (7682*ccf*tcp))). If timeout is in ms., | |
213 | * and tcp is in MHz, then (ccf * 7682)/tcp gives us 1000*TU, and | |
214 | * 1000*timeout/(1000*TU) gives us our result (but remember to round up). | |
215 | * | |
216 | * N.B.: The register value 0 gives a TU of 256. | |
217 | */ | |
218 | #define ESPTIMO_REGVAL(timo_ms, ccf, mhz) \ | |
219 | howmany(1000 * (timo_ms), ((ccf) * 7682) / (mhz)) | |
220 | ||
221 | /* | |
222 | * Value in esp_step. These tell us how much of a `sequence' completed, | |
223 | * and apply to the following sequenced operations: | |
224 | * [initiator] | |
225 | * select without ATN | |
226 | * select with ATN | |
227 | * select with ATN3 | |
228 | * select with ATN and stop | |
229 | * [target] | |
230 | * bus-initiated select with ATN | |
231 | * bus-initiated select | |
232 | * receive command sequence | |
233 | * command complete sequence | |
234 | * disconnect sequence | |
235 | * terminate sequence | |
236 | * The actual values are too complicated to define here, except that | |
237 | * code 4 always means `everything worked and the command went out' | |
238 | * (and is thus typical for everything except ATN-and-stop). | |
239 | */ | |
240 | #define ESPSTEP_MASK 0x07 /* only these bits are valid */ | |
241 | #define ESPSTEP_DONE 4 /* command went out */ | |
242 | ||
243 | /* | |
ea183373 | 244 | * Synchronous transfer period (esp_syncperiod, 5 bits). |
09d5c084 CT |
245 | * The minimum clocks-per-period is 5 and the max is 35; |
246 | * the default on reset is 5. Note that a period value of 4 | |
247 | * actually gives 5 clocks. | |
248 | */ | |
249 | #define ESP_CLOCKS_TO_PERIOD(nclocks) ((nclocks) & 31) | |
250 | ||
251 | /* | |
252 | * Bits in fifo flags (esp_fflags) register. The FIFO itself | |
253 | * is only 16 bytes, so the byte count fits in 5 bits. Normally | |
254 | * a copy of the sequence step register appears in the top 3 bits, | |
255 | * but in test mode the chip re-uses one of those for a synchronous | |
ea183373 CT |
256 | * offset bit; in any case, they are pretty much worthless. |
257 | * | |
258 | * Note that the fifo flags register must not be read while the | |
259 | * fifo is changing. | |
09d5c084 | 260 | */ |
ea183373 | 261 | #define ESP_NFIFO(fflags) ((fflags) & 0x1f) |
09d5c084 CT |
262 | |
263 | #define ESPFFLAGS_TM_SOFFNZ 0x20 /* nonzero sync offset (test mode) */ | |
264 | ||
265 | /* | |
266 | * Bits in esp_conf1. | |
267 | */ | |
268 | #define ESPCONF1_SLOW_CABLE 0x80 /* ``slow cable'' mode */ | |
269 | #define ESPCONF1_REPORT 0x40 /* disable reporting of interrupts | |
270 | from scsi bus reset command */ | |
271 | #define ESPCONF1_PARTST 0x20 /* parity test mode */ | |
272 | #define ESPCONF1_PARENB 0x10 /* enable parity */ | |
273 | #define ESPCONF1_TEST 0x08 /* chip test mode */ | |
274 | #define ESPCONF1_ID_MASK 0x07 /* SCSI bus ID field */ | |
275 | ||
276 | #define ESPCONF1_BITS "\20\10SLOW_CABLE\7REPORT\6PARTST\5PARENB\4TEST" | |
277 | ||
278 | /* | |
279 | * Values for clock conversion factor (esp_ccf). | |
280 | */ | |
281 | #define ESPCCF_FROMMHZ(mhz) (((mhz) + 4) / 5) | |
282 | #define ESPCCF_MIN 2 /* minimum CCF value */ | |
283 | ||
284 | /* | |
285 | * Bits in esp_test (for board testing only; can only be used in test mode). | |
286 | */ | |
287 | #define ESPTEST_MBZ 0xf8 /* reserved; must be 0 */ | |
288 | #define ESPTEST_TRISTATE 0x04 /* all output pins tristated */ | |
289 | #define ESPTEST_INITIATOR 0x02 /* operate as initiator */ | |
290 | #define ESPTEST_TARGET 0x01 /* operate as target */ | |
291 | ||
292 | /* | |
293 | * Bits in esp_conf2. | |
294 | */ | |
295 | #define ESPCONF2_RSVD 0xe0 /* reserved */ | |
296 | #define ESPCONF2_TRISTATE_DMA 0x10 /* tristate the DMA REQ pin */ | |
297 | #define ESPCONF2_SCSI2 0x08 /* enable SCSI 2 (see p. 4-18) */ | |
298 | #define ESPCONF2_TBPA 0x04 /* enable target bad parity abort */ | |
299 | #define ESPCONF2_RPE 0x02 /* register parity ena (ESP2xx only) */ | |
300 | #define ESPCONF2_DPE 0x01 /* DMA parity enable (ESP2xx only) */ |