mhavar.h revision 1.5.8.2 1 1.5.8.2 bouyer /* $NetBSD: mhavar.h,v 1.5.8.2 2001/04/25 17:53:27 bouyer Exp $ */
2 1.5.8.2 bouyer
3 1.5.8.2 bouyer /*
4 1.5.8.2 bouyer * Copyright (c) 1994 Peter Galbavy. All rights reserved.
5 1.5.8.2 bouyer *
6 1.5.8.2 bouyer * Redistribution and use in source and binary forms, with or without
7 1.5.8.2 bouyer * modification, are permitted provided that the following conditions
8 1.5.8.2 bouyer * are met:
9 1.5.8.2 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.5.8.2 bouyer * notice, this list of conditions and the following disclaimer.
11 1.5.8.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.5.8.2 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.5.8.2 bouyer * documentation and/or other materials provided with the distribution.
14 1.5.8.2 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.5.8.2 bouyer * must display the following acknowledgement:
16 1.5.8.2 bouyer * This product includes software developed by Peter Galbavy.
17 1.5.8.2 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.5.8.2 bouyer * derived from this software without specific prior written permission.
19 1.5.8.2 bouyer *
20 1.5.8.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.5.8.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.5.8.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.5.8.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.5.8.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.5.8.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.5.8.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.5.8.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.5.8.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.5.8.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.5.8.2 bouyer */
31 1.5.8.2 bouyer
32 1.5.8.2 bouyer /*
33 1.5.8.2 bouyer * ACB. Holds additional information for each SCSI command Comments: We
34 1.5.8.2 bouyer * need a separate scsi command block because we may need to overwrite it
35 1.5.8.2 bouyer * with a request sense command. Basicly, we refrain from fiddling with
36 1.5.8.2 bouyer * the scsi_xfer struct (except do the expected updating of return values).
37 1.5.8.2 bouyer * We'll generally update: xs->{flags,resid,error,sense,status} and
38 1.5.8.2 bouyer * occasionally xs->retries.
39 1.5.8.2 bouyer */
40 1.5.8.2 bouyer struct acb {
41 1.5.8.2 bouyer TAILQ_ENTRY(acb) chain;
42 1.5.8.2 bouyer struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */
43 1.5.8.2 bouyer int flags; /* Status */
44 1.5.8.2 bouyer #define ACB_QNONE 0
45 1.5.8.2 bouyer #define ACB_QFREE 1
46 1.5.8.2 bouyer #define ACB_QREADY 2
47 1.5.8.2 bouyer #define ACB_QNEXUS 3
48 1.5.8.2 bouyer
49 1.5.8.2 bouyer #define ACB_QBITS 0x07
50 1.5.8.2 bouyer #define ACB_CHKSENSE 0x08
51 1.5.8.2 bouyer #define ACB_ABORTED 0x10
52 1.5.8.2 bouyer #define ACB_RESET 0x80
53 1.5.8.2 bouyer #define ACB_SETQ(e, q) do (e)->flags = ((e)->flags&~ACB_QBITS)|(q); while(0)
54 1.5.8.2 bouyer struct scsi_generic cmd; /* SCSI command block */
55 1.5.8.2 bouyer int clen;
56 1.5.8.2 bouyer char *daddr; /* Saved data pointer */
57 1.5.8.2 bouyer int dleft; /* Residue */
58 1.5.8.2 bouyer u_char stat; /* SCSI status byte */
59 1.5.8.2 bouyer
60 1.5.8.2 bouyer /* struct spc_dma_seg dma[SPC_NSEG];*/ /* Physical addresses+len */
61 1.5.8.2 bouyer };
62 1.5.8.2 bouyer
63 1.5.8.2 bouyer /*
64 1.5.8.2 bouyer * Some info about each (possible) target on the SCSI bus. This should
65 1.5.8.2 bouyer * probably have been a "per target+lunit" structure, but we'll leave it at
66 1.5.8.2 bouyer * this for now.
67 1.5.8.2 bouyer */
68 1.5.8.2 bouyer struct spc_tinfo {
69 1.5.8.2 bouyer int cmds; /* #commands processed */
70 1.5.8.2 bouyer int dconns; /* #disconnects */
71 1.5.8.2 bouyer int touts; /* #timeouts */
72 1.5.8.2 bouyer int perrs; /* #parity errors */
73 1.5.8.2 bouyer int senses; /* #request sense commands sent */
74 1.5.8.2 bouyer ushort lubusy; /* What local units/subr. are busy? */
75 1.5.8.2 bouyer u_char flags;
76 1.5.8.2 bouyer #define T_NEED_TO_RESET 0x01 /* Should send a BUS_DEV_RESET */
77 1.5.8.2 bouyer #define T_NEGOTIATE 0x02 /* (Re)Negotiate synchronous options */
78 1.5.8.2 bouyer #define T_BUSY 0x04 /* Target is busy, i.e. cmd in progress */
79 1.5.8.2 bouyer #define T_SYNCMODE 0x08 /* sync mode has been negotiated */
80 1.5.8.2 bouyer #define T_SYNCHOFF 0x10 /* .. */
81 1.5.8.2 bouyer #define T_RSELECTOFF 0x20 /* .. */
82 1.5.8.2 bouyer u_char period; /* Period suggestion */
83 1.5.8.2 bouyer u_char offset; /* Offset suggestion */
84 1.5.8.2 bouyer u_char width; /* Width suggestion */
85 1.5.8.2 bouyer } tinfo_t;
86 1.5.8.2 bouyer
87 1.5.8.2 bouyer struct mha_softc {
88 1.5.8.2 bouyer struct device sc_dev; /* us as a device */
89 1.5.8.2 bouyer volatile void *sc_iobase;
90 1.5.8.2 bouyer volatile u_char *sc_pc;
91 1.5.8.2 bouyer volatile u_short *sc_ps;
92 1.5.8.2 bouyer volatile u_char *sc_pcx;
93 1.5.8.2 bouyer
94 1.5.8.2 bouyer struct scsipi_channel sc_channel;
95 1.5.8.2 bouyer struct scsipi_adapter sc_adapter;
96 1.5.8.2 bouyer
97 1.5.8.2 bouyer TAILQ_HEAD(, acb) free_list, ready_list, nexus_list;
98 1.5.8.2 bouyer struct acb *sc_nexus; /* current command */
99 1.5.8.2 bouyer struct acb sc_acb[8]; /* one per target */
100 1.5.8.2 bouyer struct spc_tinfo sc_tinfo[8];
101 1.5.8.2 bouyer
102 1.5.8.2 bouyer /* Data about the current nexus (updated for every cmd switch) */
103 1.5.8.2 bouyer u_char *sc_dp; /* Current data pointer */
104 1.5.8.2 bouyer size_t sc_dleft; /* Data bytes left to transfer */
105 1.5.8.2 bouyer
106 1.5.8.2 bouyer u_char *sc_cp; /* Current command pointer */
107 1.5.8.2 bouyer size_t sc_cleft; /* Command bytes left to transfer */
108 1.5.8.2 bouyer
109 1.5.8.2 bouyer /* Adapter state */
110 1.5.8.2 bouyer int sc_phase; /* Copy of what bus phase we are in */
111 1.5.8.2 bouyer int sc_prevphase; /* Copy of what bus phase we were in */
112 1.5.8.2 bouyer u_char sc_state; /* State applicable to the adapter */
113 1.5.8.2 bouyer u_char sc_flags;
114 1.5.8.2 bouyer u_char sc_selid; /* Reselection ID */
115 1.5.8.2 bouyer volatile u_char sc_spcinitialized; /* */
116 1.5.8.2 bouyer
117 1.5.8.2 bouyer /* Message stuff */
118 1.5.8.2 bouyer u_char sc_msgpriq; /* Messages we want to send */
119 1.5.8.2 bouyer u_char sc_msgout; /* What message is on its way out? */
120 1.5.8.2 bouyer u_char sc_msgoutq; /* Messages sent during last MESSAGE OUT */
121 1.5.8.2 bouyer u_char sc_lastmsg; /* Message last transmitted */
122 1.5.8.2 bouyer u_char sc_currmsg; /* Message currently ready to transmit */
123 1.5.8.2 bouyer #define SPC_MAX_MSG_LEN 8
124 1.5.8.2 bouyer u_char sc_omess[SPC_MAX_MSG_LEN];
125 1.5.8.2 bouyer u_char *sc_omp; /* Outgoing message pointer */
126 1.5.8.2 bouyer u_char sc_imess[SPC_MAX_MSG_LEN];
127 1.5.8.2 bouyer u_char *sc_imp; /* Incoming message pointer */
128 1.5.8.2 bouyer size_t sc_imlen;
129 1.5.8.2 bouyer
130 1.5.8.2 bouyer /* Hardware stuff */
131 1.5.8.2 bouyer int sc_freq; /* Clock frequency in MHz */
132 1.5.8.2 bouyer int sc_id; /* our scsi id */
133 1.5.8.2 bouyer int sc_minsync; /* Minimum sync period / 4 */
134 1.5.8.2 bouyer int sc_maxsync; /* Maximum sync period / 4 */
135 1.5.8.2 bouyer
136 1.5.8.2 bouyer /* DMA buffer */
137 1.5.8.2 bouyer bus_dma_tag_t sc_dmat;
138 1.5.8.2 bouyer bus_dma_segment_t sc_dmaseg[1];
139 1.5.8.2 bouyer int sc_ndmasegs;
140 1.5.8.2 bouyer bus_dmamap_t sc_dmamap;
141 1.5.8.2 bouyer caddr_t sc_dmabuf;
142 1.5.8.2 bouyer u_char *sc_p;
143 1.5.8.2 bouyer u_int32_t sc_dmasize;
144 1.5.8.2 bouyer };
145 1.5.8.2 bouyer
146 1.5.8.2 bouyer /* values for sc_state */
147 1.5.8.2 bouyer #define SPC_INIT 0x00
148 1.5.8.2 bouyer #define SPC_IDLE 0x01 /* waiting for something to do */
149 1.5.8.2 bouyer #define ESP_TMP_UNAVAIL 0x02 /* Don't accept SCSI commands */
150 1.5.8.2 bouyer #define SPC_SELECTING 0x03 /* SCSI command is arbiting */
151 1.5.8.2 bouyer #define SPC_RESELECTED 0x04 /* Has been reselected */
152 1.5.8.2 bouyer #define SPC_HASNEXUS 0x05 /* Actively using the SCSI bus */
153 1.5.8.2 bouyer #define SPC_CLEANING 0x06
154 1.5.8.2 bouyer #define ESP_SBR 0x07 /* Expect a SCSI RST because we commanded it */
155 1.5.8.2 bouyer #define SPC_CONNECTED 0x08 /* Actively using the SCSI bus */
156 1.5.8.2 bouyer #define SPC_DISCONNECT 0x09 /* MSG_DISCONNECT received */
157 1.5.8.2 bouyer #define SPC_CMDCOMPLETE 0x0a /* MSG_CMDCOMPLETE received */
158 1.5.8.2 bouyer
159 1.5.8.2 bouyer
160 1.5.8.2 bouyer /* values for sc_flags */
161 1.5.8.2 bouyer #define SPC_DROP_MSGI 0x01 /* Discard all msgs (parity err detected) */
162 1.5.8.2 bouyer #define SPC_DOINGDMA 0x02 /* The FIFO data path is active! */
163 1.5.8.2 bouyer #define SPC_BUSFREE_OK 0x04 /* Bus free phase is OK. */
164 1.5.8.2 bouyer #define SPC_SYNCHNEGO 0x08 /* Synch negotiation in progress. */
165 1.5.8.2 bouyer #define SPC_DISCON 0x10 /* Target sent DISCONNECT msg */
166 1.5.8.2 bouyer #define SPC_ABORTING 0x20 /* Bailing out */
167 1.5.8.2 bouyer #define ESP_ICCS 0x40 /* Expect status phase results */
168 1.5.8.2 bouyer #define ESP_WAITI 0x80 /* Waiting for non-DMA data to arrive */
169 1.5.8.2 bouyer
170 1.5.8.2 bouyer
171 1.5.8.2 bouyer /* values for sc_msgout */
172 1.5.8.2 bouyer #define SEND_DEV_RESET 0x01
173 1.5.8.2 bouyer #define SEND_PARITY_ERROR 0x02
174 1.5.8.2 bouyer #define SEND_INIT_DET_ERR 0x04
175 1.5.8.2 bouyer #define SEND_REJECT 0x08
176 1.5.8.2 bouyer #define SEND_IDENTIFY 0x10
177 1.5.8.2 bouyer #define SEND_ABORT 0x20
178 1.5.8.2 bouyer #define SEND_SDTR 0x40
179 1.5.8.2 bouyer #define SEND_WDTR 0x80
180 1.5.8.2 bouyer
181 1.5.8.2 bouyer /* SCSI Status codes */
182 1.5.8.2 bouyer #define ST_GOOD 0x00
183 1.5.8.2 bouyer #define ST_CHKCOND 0x02
184 1.5.8.2 bouyer #define ST_CONDMET 0x04
185 1.5.8.2 bouyer #define ST_BUSY 0x08
186 1.5.8.2 bouyer #define ST_INTERMED 0x10
187 1.5.8.2 bouyer #define ST_INTERMED_CONDMET 0x14
188 1.5.8.2 bouyer #define ST_RESERVATION_CONFLICT 0x18
189 1.5.8.2 bouyer #define ST_CMD_TERM 0x22
190 1.5.8.2 bouyer #define ST_QUEUE_FULL 0x28
191 1.5.8.2 bouyer
192 1.5.8.2 bouyer #define ST_MASK 0x3e /* bit 0,6,7 is reserved */
193 1.5.8.2 bouyer
194 1.5.8.2 bouyer /* phase bits */
195 1.5.8.2 bouyer #define IOI 0x01
196 1.5.8.2 bouyer #define CDI 0x02
197 1.5.8.2 bouyer #define MSGI 0x04
198 1.5.8.2 bouyer
199 1.5.8.2 bouyer /* Information transfer phases */
200 1.5.8.2 bouyer #define DATA_OUT_PHASE (0)
201 1.5.8.2 bouyer #define DATA_IN_PHASE (IOI)
202 1.5.8.2 bouyer #define COMMAND_PHASE (CDI)
203 1.5.8.2 bouyer #define STATUS_PHASE (CDI|IOI)
204 1.5.8.2 bouyer #define MESSAGE_OUT_PHASE (MSGI|CDI)
205 1.5.8.2 bouyer #define MESSAGE_IN_PHASE (MSGI|CDI|IOI)
206 1.5.8.2 bouyer
207 1.5.8.2 bouyer #define PHASE_MASK (MSGI|CDI|IOI)
208 1.5.8.2 bouyer
209 1.5.8.2 bouyer /* Some pseudo phases for getphase()*/
210 1.5.8.2 bouyer #define BUSFREE_PHASE 0x100 /* Re/Selection no longer valid */
211 1.5.8.2 bouyer #define INVALID_PHASE 0x101 /* Re/Selection valid, but no REQ yet */
212 1.5.8.2 bouyer #define PSEUDO_PHASE 0x100 /* "pseudo" bit */
213