ncr5380reg.h revision 1.14 1 1.14 bouyer /* $NetBSD: ncr5380reg.h,v 1.14 2001/04/25 17:53:13 bouyer Exp $ */
2 1.1 leo
3 1.1 leo /*
4 1.1 leo * Copyright (c) 1995 Leo Weppelman.
5 1.1 leo * All rights reserved.
6 1.1 leo *
7 1.1 leo * Redistribution and use in source and binary forms, with or without
8 1.1 leo * modification, are permitted provided that the following conditions
9 1.1 leo * are met:
10 1.1 leo * 1. Redistributions of source code must retain the above copyright
11 1.1 leo * notice, this list of conditions and the following disclaimer.
12 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 leo * notice, this list of conditions and the following disclaimer in the
14 1.1 leo * documentation and/or other materials provided with the distribution.
15 1.1 leo * 3. All advertising materials mentioning features or use of this software
16 1.1 leo * must display the following acknowledgement:
17 1.1 leo * This product includes software developed by Leo Weppelman.
18 1.1 leo * 4. The name of the author may not be used to endorse or promote products
19 1.1 leo * derived from this software without specific prior written permission
20 1.1 leo *
21 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 leo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 leo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 leo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 leo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 leo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 leo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 leo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 leo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 leo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 leo */
32 1.1 leo
33 1.1 leo #ifndef _NCR5380REG_H
34 1.1 leo #define _NCR5380REG_H
35 1.1 leo /*
36 1.2 leo * NCR5380 common interface definitions.
37 1.1 leo */
38 1.1 leo
39 1.2 leo /*
40 1.2 leo * Register numbers: (first argument to GET/SET_5380_REG )
41 1.2 leo */
42 1.2 leo #define NCR5380_DATA 0 /* Data register */
43 1.2 leo #define NCR5380_ICOM 1 /* Initiator command register */
44 1.2 leo #define NCR5380_MODE 2 /* Mode register */
45 1.2 leo #define NCR5380_TCOM 3 /* Target command register */
46 1.2 leo #define NCR5380_IDSTAT 4 /* Bus status register */
47 1.2 leo #define NCR5380_DMSTAT 5 /* DMA status register */
48 1.2 leo #define NCR5380_TRCV 6 /* Target receive register */
49 1.2 leo #define NCR5380_IRCV 7 /* Initiator receive register */
50 1.1 leo
51 1.1 leo /*
52 1.1 leo * Definitions for Initiator command register.
53 1.1 leo */
54 1.1 leo #define SC_A_RST 0x80 /* RW - Assert RST */
55 1.1 leo #define SC_TEST 0x40 /* W - Test mode */
56 1.1 leo #define SC_AIP 0x40 /* R - Arbitration in progress */
57 1.1 leo #define SC_LA 0x20 /* R - Lost arbitration */
58 1.1 leo #define SC_A_ACK 0x10 /* RW - Assert ACK */
59 1.1 leo #define SC_A_BSY 0x08 /* RW - Assert BSY */
60 1.1 leo #define SC_A_SEL 0x04 /* RW - Assert SEL */
61 1.1 leo #define SC_A_ATN 0x02 /* RW - Assert ATN */
62 1.1 leo #define SC_ADTB 0x01 /* RW - Assert Data To Bus */
63 1.1 leo
64 1.1 leo /*
65 1.1 leo * Definitions for mode register
66 1.1 leo */
67 1.1 leo #define SC_B_DMA 0x80 /* RW - Block mode DMA (not on TT!) */
68 1.1 leo #define SC_T_MODE 0x40 /* RW - Target mode */
69 1.1 leo #define SC_E_PAR 0x20 /* RW - Enable parity check */
70 1.1 leo #define SC_E_PARI 0x10 /* RW - Enable parity interrupt */
71 1.1 leo #define SC_E_EOPI 0x08 /* RW - Enable End Of Process Interrupt */
72 1.1 leo #define SC_MON_BSY 0x04 /* RW - Monitor BSY */
73 1.1 leo #define SC_M_DMA 0x02 /* RW - Set DMA mode */
74 1.1 leo #define SC_ARBIT 0x01 /* RW - Arbitrate */
75 1.1 leo
76 1.1 leo /*
77 1.1 leo * Definitions for tcom register
78 1.1 leo */
79 1.1 leo #define SC_LBS 0x80 /* RW - Last Byte Send (not on TT!) */
80 1.1 leo #define SC_A_REQ 0x08 /* RW - Assert REQ */
81 1.1 leo #define SC_A_MSG 0x04 /* RW - Assert MSG */
82 1.1 leo #define SC_A_CD 0x02 /* RW - Assert C/D */
83 1.1 leo #define SC_A_IO 0x01 /* RW - Assert I/O */
84 1.1 leo
85 1.1 leo /*
86 1.1 leo * Definitions for idstat register
87 1.1 leo */
88 1.1 leo #define SC_S_RST 0x80 /* R - RST is set */
89 1.1 leo #define SC_S_BSY 0x40 /* R - BSY is set */
90 1.1 leo #define SC_S_REQ 0x20 /* R - REQ is set */
91 1.1 leo #define SC_S_MSG 0x10 /* R - MSG is set */
92 1.1 leo #define SC_S_CD 0x08 /* R - C/D is set */
93 1.1 leo #define SC_S_IO 0x04 /* R - I/O is set */
94 1.1 leo #define SC_S_SEL 0x02 /* R - SEL is set */
95 1.1 leo #define SC_S_PAR 0x01 /* R - Parity bit */
96 1.1 leo
97 1.1 leo /*
98 1.1 leo * Definitions for dmastat register
99 1.1 leo */
100 1.1 leo #define SC_END_DMA 0x80 /* R - End of DMA */
101 1.1 leo #define SC_DMA_REQ 0x40 /* R - DMA request */
102 1.1 leo #define SC_PAR_ERR 0x20 /* R - Parity error */
103 1.1 leo #define SC_IRQ_SET 0x10 /* R - IRQ is active */
104 1.1 leo #define SC_PHS_MTCH 0x08 /* R - Phase Match */
105 1.1 leo #define SC_BSY_ERR 0x04 /* R - Busy error */
106 1.1 leo #define SC_ATN_STAT 0x02 /* R - State of ATN line */
107 1.1 leo #define SC_ACK_STAT 0x01 /* R - State of ACK line */
108 1.1 leo #define SC_S_SEND 0x00 /* W - Start DMA output */
109 1.1 leo
110 1.1 leo #define SC_CLINT { /* Clear interrupts */ \
111 1.2 leo int i = GET_5380_REG(NCR5380_IRCV); \
112 1.1 leo }
113 1.1 leo
114 1.1 leo
115 1.1 leo /*
116 1.1 leo * Definition of SCSI-bus phases. The values are determined by signals
117 1.1 leo * on the SCSI-bus. DO NOT CHANGE!
118 1.1 leo * The values must be used to index the pointers in SCSI-PARMS.
119 1.1 leo */
120 1.1 leo #define NR_PHASE 8
121 1.1 leo #define PH_DATAOUT 0
122 1.1 leo #define PH_DATAIN 1
123 1.1 leo #define PH_CMD 2
124 1.1 leo #define PH_STATUS 3
125 1.1 leo #define PH_RES1 4
126 1.1 leo #define PH_RES2 5
127 1.1 leo #define PH_MSGOUT 6
128 1.1 leo #define PH_MSGIN 7
129 1.1 leo
130 1.1 leo #define PH_OUT(phase) (!(phase & 1)) /* TRUE if output phase */
131 1.1 leo #define PH_IN(phase) (phase & 1) /* TRUE if input phase */
132 1.1 leo
133 1.1 leo /*
134 1.1 leo * Id of Host-adapter
135 1.1 leo */
136 1.1 leo #define SC_HOST_ID 0x80
137 1.1 leo
138 1.1 leo /*
139 1.1 leo * Base setting for 5380 mode register
140 1.1 leo */
141 1.1 leo #define IMODE_BASE SC_E_PAR
142 1.2 leo
143 1.2 leo /*
144 1.2 leo * SCSI completion status codes, should move to sys/scsi/????
145 1.2 leo */
146 1.2 leo #define SCSMASK 0x1e /* status code mask */
147 1.2 leo #define SCSGOOD 0x00 /* good status */
148 1.2 leo #define SCSCHKC 0x02 /* check condition */
149 1.2 leo #define SCSBUSY 0x08 /* busy status */
150 1.2 leo #define SCSCMET 0x04 /* condition met / good */
151 1.2 leo
152 1.2 leo /*
153 1.2 leo * Return values of check_intr()
154 1.2 leo */
155 1.2 leo #define INTR_SPURIOUS 0
156 1.2 leo #define INTR_RESEL 2
157 1.2 leo #define INTR_DMA 3
158 1.2 leo
159 1.10 leo struct ncr_softc {
160 1.10 leo struct device sc_dev;
161 1.14 bouyer struct scsipi_channel sc_channel;
162 1.13 thorpej struct scsipi_adapter sc_adapter;
163 1.10 leo
164 1.10 leo /*
165 1.10 leo * Some (pre-SCSI2) devices don't support select with ATN.
166 1.10 leo * If the device responds to select with ATN by going into
167 1.10 leo * command phase (ignoring ATN), then we flag it in the
168 1.10 leo * following bitmask.
169 1.10 leo * We also keep track of which devices have been selected
170 1.10 leo * before. This allows us to not even try raising ATN if
171 1.10 leo * the target doesn't respond to it the first time.
172 1.10 leo */
173 1.10 leo u_int8_t sc_noselatn;
174 1.10 leo u_int8_t sc_selected;
175 1.10 leo };
176 1.10 leo
177 1.10 leo /*
178 1.10 leo * Max. number of dma-chains per request
179 1.10 leo */
180 1.10 leo #define MAXDMAIO (MAXPHYS/NBPG + 1)
181 1.10 leo
182 1.10 leo /*
183 1.10 leo * Some requests are not contiguous in physical memory. We need to break them
184 1.10 leo * up into contiguous parts for DMA.
185 1.10 leo */
186 1.10 leo struct dma_chain {
187 1.10 leo u_int dm_count;
188 1.10 leo u_long dm_addr;
189 1.10 leo };
190 1.10 leo
191 1.10 leo /*
192 1.10 leo * Define our issue, free and disconnect queue's.
193 1.10 leo */
194 1.10 leo typedef struct req_q {
195 1.10 leo struct req_q *next; /* next in free, issue or discon queue */
196 1.10 leo struct req_q *link; /* next linked command to execute */
197 1.12 bouyer struct scsipi_xfer *xs; /* request from high-level driver */
198 1.10 leo u_short dr_flag; /* driver state */
199 1.10 leo u_char phase; /* current SCSI phase */
200 1.10 leo u_char msgout; /* message to send when requested */
201 1.10 leo u_char targ_id; /* target for command */
202 1.10 leo u_char targ_lun; /* lun for command */
203 1.10 leo u_char status; /* returned status byte */
204 1.10 leo u_char message; /* returned message byte */
205 1.10 leo u_char *bounceb; /* allocated bounce buffer */
206 1.10 leo u_char *bouncerp; /* bounce read-pointer */
207 1.10 leo struct dma_chain dm_chain[MAXDMAIO];
208 1.10 leo struct dma_chain *dm_cur; /* current dma-request */
209 1.10 leo struct dma_chain *dm_last; /* last dma-request */
210 1.10 leo long xdata_len; /* length of transfer */
211 1.10 leo u_char *xdata_ptr; /* virtual address of transfer */
212 1.10 leo struct scsi_generic xcmd; /* command to execute */
213 1.10 leo } SC_REQ;
214 1.10 leo
215 1.10 leo /*
216 1.10 leo * Values for dr_flag:
217 1.10 leo */
218 1.10 leo #define DRIVER_IN_DMA 0x01 /* Non-polled DMA activated */
219 1.10 leo #define DRIVER_AUTOSEN 0x02 /* Doing automatic sense */
220 1.10 leo #define DRIVER_NOINT 0x04 /* We are booting: no interrupts */
221 1.10 leo #define DRIVER_DMAOK 0x08 /* DMA can be used on this request */
222 1.10 leo #define DRIVER_BOUNCING 0x10 /* Using the bounce buffer */
223 1.10 leo #define DRIVER_LINKCHK 0x20 /* Doing the linked command check */
224 1.10 leo
225 1.10 leo static SC_REQ *issue_q = NULL; /* Commands waiting to be issued*/
226 1.10 leo static SC_REQ *discon_q = NULL; /* Commands disconnected */
227 1.10 leo static SC_REQ *connected = NULL; /* Command currently connected */
228 1.10 leo
229 1.2 leo /*
230 1.2 leo * Function decls:
231 1.2 leo */
232 1.3 leo static void ack_message __P((void));
233 1.10 leo static int check_autosense __P((SC_REQ *, int));
234 1.10 leo static int check_intr __P((struct ncr_softc *));
235 1.10 leo static int command_size __P((u_char));
236 1.10 leo static int dma_ready __P((void));
237 1.10 leo static void finish_req __P((SC_REQ *));
238 1.10 leo static int handle_message __P((SC_REQ *, u_int));
239 1.7 leo static int information_transfer __P((struct ncr_softc *));
240 1.10 leo static void nack_message __P((SC_REQ *, u_char));
241 1.10 leo static void ncr_aprint __P((struct ncr_softc *, char *, ...));
242 1.10 leo static void ncr_ctrl_intr __P((struct ncr_softc *));
243 1.10 leo static void ncr_dma_intr __P((struct ncr_softc *));
244 1.10 leo static void ncr_tprint __P((SC_REQ *, char *, ...));
245 1.10 leo static int reach_msg_out __P((struct ncr_softc *, u_long));
246 1.2 leo static void reselect __P((struct ncr_softc *));
247 1.2 leo static void run_main __P((struct ncr_softc *));
248 1.10 leo static int scsi_dmaok __P((SC_REQ *));
249 1.2 leo static void scsi_main __P((struct ncr_softc *));
250 1.10 leo static void scsi_reset_verbose __P((struct ncr_softc *, const char *));
251 1.10 leo static int scsi_select __P((SC_REQ *, int));
252 1.12 bouyer static void show_data_sense __P((struct scsipi_xfer *));
253 1.11 leo static void show_phase __P((SC_REQ *, int));
254 1.10 leo static void show_request __P((SC_REQ *, char *));
255 1.10 leo static void show_signals __P((u_char, u_char));
256 1.10 leo static void transfer_dma __P((SC_REQ *, u_int, int));
257 1.10 leo static int transfer_pio __P((u_char *, u_char *, u_long *, int));
258 1.10 leo static int wait_req_false __P((void));
259 1.10 leo static int wait_req_true __P((void));
260 1.2 leo
261 1.10 leo /*
262 1.10 leo * You might want to call these from the debugger...
263 1.10 leo */
264 1.8 leo void scsi_show __P((void));
265 1.10 leo void scsi_reset __P((void));
266 1.1 leo
267 1.1 leo #endif /* _NCR5380REG_H */
268